UNPKG

@polkadot/keyring

Version:
29 lines (28 loc) 983 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Pairs = void 0; const util_1 = require("@polkadot/util"); const util_crypto_1 = require("@polkadot/util-crypto"); class Pairs { __internal__map = {}; add(pair) { this.__internal__map[(0, util_crypto_1.decodeAddress)(pair.address).toString()] = pair; return pair; } all() { return Object.values(this.__internal__map); } get(address) { const pair = this.__internal__map[(0, util_crypto_1.decodeAddress)(address).toString()]; if (!pair) { throw new Error(`Unable to retrieve keypair '${(0, util_1.isU8a)(address) || (0, util_1.isHex)(address) ? (0, util_1.u8aToHex)((0, util_1.u8aToU8a)(address)) : address}'`); } return pair; } remove(address) { delete this.__internal__map[(0, util_crypto_1.decodeAddress)(address).toString()]; } } exports.Pairs = Pairs;