keyring.getPair throws
This commit is contained in:
@@ -22,7 +22,7 @@ module.exports = function keyring (): KeyringInstance {
|
||||
pairs.add(decrypt(encrypted, passphrase)),
|
||||
encrypt: (publicKey: Uint8Array, passphrase: Uint8Array | string): ?Uint8Array =>
|
||||
encrypt(pairs.get(publicKey), passphrase),
|
||||
getPair: (publicKey: Uint8Array): ?KeyringPair =>
|
||||
getPair: (publicKey: Uint8Array): KeyringPair =>
|
||||
pairs.get(publicKey),
|
||||
getPairs: pairs.all,
|
||||
getPublicKeys: (): Array<Uint8Array> =>
|
||||
|
||||
@@ -9,6 +9,9 @@ type KeyringPairMap = {
|
||||
[Uint8Array]: KeyringPair
|
||||
};
|
||||
|
||||
const assert = require('@polkadot/util/assert');
|
||||
const u8aToHex = require('@polkadot/util/u8a/toHex');
|
||||
|
||||
module.exports = function pairs (): KeyringPairs {
|
||||
const self: KeyringPairMap = {};
|
||||
|
||||
@@ -21,7 +24,12 @@ module.exports = function pairs (): KeyringPairs {
|
||||
all: (): Array<KeyringPair> =>
|
||||
// flowlint-next-line unclear-type:off
|
||||
((Object.values(self): any): Array<KeyringPair>),
|
||||
get: (publicKey: Uint8Array): ?KeyringPair =>
|
||||
self[publicKey]
|
||||
get: (publicKey: Uint8Array): KeyringPair => {
|
||||
const pair = self[publicKey];
|
||||
|
||||
assert(pair, `Unable to retrieve keypair for publicKey '${u8aToHex(publicKey)}'`);
|
||||
|
||||
return pair;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,7 +28,7 @@ export type KeyringInstance = {
|
||||
addFromSeed (seed: Uint8Array): KeyringPair,
|
||||
decrypt (encrypted: Uint8Array, secret: Uint8Array | string): KeyringPair,
|
||||
encrypt (publicKey: Uint8Array, secret: Uint8Array | string): ?Uint8Array,
|
||||
getPair (publicKey: Uint8Array): ?KeyringPair,
|
||||
getPair (publicKey: Uint8Array): KeyringPair,
|
||||
getPairs (): Array<KeyringPair>,
|
||||
getPublicKeys (): Array<Uint8Array>
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user