'use strict'; import { KeyStore } from './keystore'; import { KeyPair } from '../utils/key_pair'; /** * Simple in-memory keystore for testing purposes. */ export class InMemoryKeyStore extends KeyStore { private keys: { [key: string]: string }; constructor() { super(); this.keys = {}; } async setKey(networkId: string, accountId: string, keyPair: KeyPair): Promise { this.keys[`${accountId}:${networkId}`] = keyPair.toString(); } async getKey(networkId: string, accountId: string): Promise { const value = this.keys[`${accountId}:${networkId}`]; if (!value) { return null; } return KeyPair.fromString(value); } async removeKey(networkId: string, accountId: string): Promise { delete this.keys[`${accountId}:${networkId}`]; } async clear(): Promise { this.keys = {}; } async getNetworks(): Promise { const result = new Set(); Object.keys(this.keys).forEach((key) => { const parts = key.split(':'); result.add(parts[1]); }); return Array.from(result.values()); } async getAccounts(networkId: string): Promise { const result = new Array(); Object.keys(this.keys).forEach((key) => { const parts = key.split(':'); if (parts[parts.length - 1] === networkId) { result.push(parts.slice(0, parts.length - 1).join(':')); } }); return result; } }