Expose address decoding/encoding on keyring (#248)

This commit is contained in:
Jaco Greeff
2018-11-13 12:35:31 +01:00
committed by GitHub
parent 57938d22d8
commit 18982b0c2d
3 changed files with 13 additions and 3 deletions
+6 -2
View File
@@ -36,6 +36,10 @@ export default class Keyring implements KeyringInstance {
this._pairs = new Pairs();
}
decodeAddress = decodeAddress;
encodeAddress = encodeAddress;
setAddressPrefix = setAddressPrefix;
/**
* @name addPair
* @signature addPair (pair: KeyringPair): KeyringPair
@@ -56,7 +60,7 @@ export default class Keyring implements KeyringInstance {
*/
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, defaultEncoded?: Uint8Array): KeyringPair {
// @ts-ignore no secretKey - cannot unlock
return this.addPair(createPair({ publicKey: decodeAddress(address) }, meta, defaultEncoded));
return this.addPair(createPair({ publicKey: this.decodeAddress(address) }, meta, defaultEncoded));
}
/**
@@ -224,4 +228,4 @@ export default class Keyring implements KeyringInstance {
}
}
export { Keyring, decodeAddress, encodeAddress, setAddressPrefix };
export { Keyring };
+1 -1
View File
@@ -8,7 +8,7 @@ import { PairState } from './types';
import { naclSign, naclVerify } from '@polkadot/util-crypto/index';
import encodeAddress from '../address/encode';
import { encodeAddress } from '../address';
import decode from './decode';
import encode from './encode';
import getMeta from './getMeta';
+6
View File
@@ -2,6 +2,8 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { Prefix } from './address/types';
export type KeyringPair$Meta = {
[index: string]: any
}
@@ -39,6 +41,10 @@ export interface KeyringPairs {
}
export interface KeyringInstance {
decodeAddress (encoded: string | Uint8Array): Uint8Array,
encodeAddress (key: Uint8Array | string): string,
setAddressPrefix (prefix: Prefix): void,
addPair (pair: KeyringPair): KeyringPair,
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta): KeyringPair,
addFromMnemonic (mnemonic: string, meta?: KeyringPair$Meta): KeyringPair,