Restore compact with optional meta (#315)

* Restore compact with optional meta

* Expose .pairs & .publicKeys (getters)
This commit is contained in:
Jaco Greeff
2019-02-16 10:17:54 +01:00
committed by GitHub
parent 3555b6fc96
commit 9864646b65
3 changed files with 23 additions and 7 deletions
+17 -3
View File
@@ -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);
+1 -1
View File
@@ -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) {
+5 -3
View File
@@ -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>;