mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-21 23:48:05 +00:00
25 lines
728 B
JavaScript
25 lines
728 B
JavaScript
import { isHex, isU8a, u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
|
import { decodeAddress } from '@pezkuwi/util-crypto';
|
|
export class Pairs {
|
|
#map = {};
|
|
add(pair) {
|
|
this.#map[decodeAddress(pair.address).toString()] = pair;
|
|
return pair;
|
|
}
|
|
all() {
|
|
return Object.values(this.#map);
|
|
}
|
|
get(address) {
|
|
const pair = this.#map[decodeAddress(address).toString()];
|
|
if (!pair) {
|
|
throw new Error(`Unable to retrieve keypair '${isU8a(address) || isHex(address)
|
|
? u8aToHex(u8aToU8a(address))
|
|
: address}'`);
|
|
}
|
|
return pair;
|
|
}
|
|
remove(address) {
|
|
delete this.#map[decodeAddress(address).toString()];
|
|
}
|
|
}
|