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