Restore compact with optional meta (#315)
* Restore compact with optional meta * Expose .pairs & .publicKeys (getters)
This commit is contained in:
@@ -44,6 +44,20 @@ export default class Keyring implements KeyringInstance {
|
||||
encodeAddress = encodeAddress;
|
||||
setAddressPrefix = setAddressPrefix;
|
||||
|
||||
/**
|
||||
* @description retrieve the pairs (alias for getPairs)
|
||||
*/
|
||||
get pairs (): Array<KeyringPair> {
|
||||
return this.getPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description retrieve the publicKeys (alias for getPiblicKeys)
|
||||
*/
|
||||
get publicKeys (): Array<Uint8Array> {
|
||||
return this.getPublicKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the type of the keyring, either ed25519 of sr25519
|
||||
*/
|
||||
@@ -67,7 +81,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* of an account backup), and then generates a keyring pair from them that it passes to
|
||||
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
||||
*/
|
||||
addFromAddress (address: string | Uint8Array, meta: KeyringPair$Meta, encoded: Uint8Array | null, type: KeyringPairType = this.type): KeyringPair {
|
||||
addFromAddress (address: string | Uint8Array, meta: KeyringPair$Meta = {}, encoded: Uint8Array | null = null, type: KeyringPairType = this.type): KeyringPair {
|
||||
return this.addPair(createPair(type, { publicKey: this.decodeAddress(address) }, meta, encoded));
|
||||
}
|
||||
|
||||
@@ -93,7 +107,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* of an account backup), and then generates a keyring pair from it that it passes to
|
||||
* `addPair` to stores in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
||||
*/
|
||||
addFromMnemonic (mnemonic: string, meta: KeyringPair$Meta, type: KeyringPairType = this.type): KeyringPair {
|
||||
addFromMnemonic (mnemonic: string, meta: KeyringPair$Meta = {}, type: KeyringPairType = this.type): KeyringPair {
|
||||
return this.addFromSeed(mnemonicToSeed(mnemonic), meta, type);
|
||||
}
|
||||
|
||||
@@ -104,7 +118,7 @@ export default class Keyring implements KeyringInstance {
|
||||
* Allows user to provide the account seed as an argument, and then generates a keyring pair from it that it passes to
|
||||
* `addPair` to store in a keyring pair dictionary the public key of the generated pair as a key and the pair as the associated value.
|
||||
*/
|
||||
addFromSeed (seed: Uint8Array, meta: KeyringPair$Meta, type: KeyringPairType = this.type): KeyringPair {
|
||||
addFromSeed (seed: Uint8Array, meta: KeyringPair$Meta = {}, type: KeyringPairType = this.type): KeyringPair {
|
||||
const keypair = type === 'sr25519'
|
||||
? schnorrkelFromSeed(seed)
|
||||
: naclFromSeed(seed);
|
||||
|
||||
@@ -59,7 +59,7 @@ const verify = (type: KeyringPairType, message: Uint8Array, signature: Uint8Arra
|
||||
* an `encoded` property that is assigned with the encoded public key in hex format, and an `encoding`
|
||||
* property that indicates whether the public key value of the `encoded` property is encoded or not.
|
||||
*/
|
||||
export default function createPair (type: KeyringPairType, { publicKey, seed }: PairInfo, meta: KeyringPair$Meta = {}, encoded: Uint8Array | null): KeyringPair {
|
||||
export default function createPair (type: KeyringPairType, { publicKey, seed }: PairInfo, meta: KeyringPair$Meta = {}, encoded: Uint8Array | null = null): KeyringPair {
|
||||
let secretKey: Uint8Array | undefined;
|
||||
|
||||
if (seed) {
|
||||
|
||||
@@ -55,6 +55,8 @@ export interface KeyringPairs {
|
||||
}
|
||||
|
||||
export interface KeyringInstance {
|
||||
readonly pairs: Array<KeyringPair>;
|
||||
readonly publicKeys: Array<Uint8Array>;
|
||||
readonly type: KeyringPairType;
|
||||
|
||||
decodeAddress (encoded: string | Uint8Array): Uint8Array;
|
||||
@@ -62,9 +64,9 @@ export interface KeyringInstance {
|
||||
setAddressPrefix (prefix: Prefix): void;
|
||||
|
||||
addPair (pair: KeyringPair): KeyringPair;
|
||||
addFromAddress (address: string | Uint8Array, meta: KeyringPair$Meta, encoded: Uint8Array | null, type?: KeyringPairType): KeyringPair;
|
||||
addFromMnemonic (mnemonic: string, meta: KeyringPair$Meta, type?: KeyringPairType): KeyringPair;
|
||||
addFromSeed (seed: Uint8Array, meta: KeyringPair$Meta, type?: KeyringPairType): KeyringPair;
|
||||
addFromAddress (address: string | Uint8Array, meta?: KeyringPair$Meta, encoded?: Uint8Array | null, type?: KeyringPairType): KeyringPair;
|
||||
addFromMnemonic (mnemonic: string, meta?: KeyringPair$Meta, type?: KeyringPairType): KeyringPair;
|
||||
addFromSeed (seed: Uint8Array, meta?: KeyringPair$Meta, type?: KeyringPairType): KeyringPair;
|
||||
addFromJson (pair: KeyringPair$Json): KeyringPair;
|
||||
getPair (address: string | Uint8Array): KeyringPair;
|
||||
getPairs (): Array<KeyringPair>;
|
||||
|
||||
Reference in New Issue
Block a user