keyring.getPair throws

This commit is contained in:
Jaco Greeff
2018-04-27 16:48:23 +02:00
parent 39fbcd8b0a
commit 7fd0ee4eea
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -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> =>
+10 -2
View File
@@ -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;
}
};
};
+1 -1
View File
@@ -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>
};