1 | import { isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
|
2 | import { decodeAddress } from '@polkadot/util-crypto';
|
3 | export class Pairs {
|
4 | __internal__map = {};
|
5 | add(pair) {
|
6 | this.__internal__map[decodeAddress(pair.address).toString()] = pair;
|
7 | return pair;
|
8 | }
|
9 | all() {
|
10 | return Object.values(this.__internal__map);
|
11 | }
|
12 | get(address) {
|
13 | const pair = this.__internal__map[decodeAddress(address).toString()];
|
14 | if (!pair) {
|
15 | throw new Error(`Unable to retrieve keypair '${isU8a(address) || isHex(address)
|
16 | ? u8aToHex(u8aToU8a(address))
|
17 | : address}'`);
|
18 | }
|
19 | return pair;
|
20 | }
|
21 | remove(address) {
|
22 | delete this.__internal__map[decodeAddress(address).toString()];
|
23 | }
|
24 | }
|