mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-10-20 18:56:18 +00:00
The header rule takes the current year as the end of the range, as upstream's does; 581 sources still ended at 2025, which failed lint. Lint never ran to completion here, so this went unseen. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/keyring authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { KeyringPair, KeyringPairs } from './types.js';
|
|
|
|
import { isHex, isU8a, u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
|
import { decodeAddress } from '@pezkuwi/util-crypto';
|
|
|
|
type KeyringPairMap = Record<string, KeyringPair>;
|
|
|
|
export class Pairs implements KeyringPairs {
|
|
readonly #map: KeyringPairMap = {};
|
|
|
|
public add (pair: KeyringPair): KeyringPair {
|
|
this.#map[decodeAddress(pair.address).toString()] = pair;
|
|
|
|
return pair;
|
|
}
|
|
|
|
public all (): KeyringPair[] {
|
|
return Object.values(this.#map);
|
|
}
|
|
|
|
public get (address: string | Uint8Array): KeyringPair {
|
|
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;
|
|
}
|
|
|
|
public remove (address: string | Uint8Array): void {
|
|
delete this.#map[decodeAddress(address).toString()];
|
|
}
|
|
}
|