Expose address decoding/encoding on keyring (#248)
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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';
|
||||
|
||||
Vendored
+6
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user