UNPKG

o1js

Version:

TypeScript framework for zk-SNARKs and zkApps

22 lines (19 loc) 728 B
import { PrivateKey, PublicKey } from 'o1js'; export { randomAccounts }; /** * Predefined accounts keys, labeled by the input strings. Useful for testing/debugging with consistent keys. */ function randomAccounts<K extends string>( ...names: [K, ...K[]] ): { keys: Record<K, PrivateKey>; addresses: Record<K, PublicKey> } { let base58Keys = Array(names.length) .fill('') .map(() => PrivateKey.random().toBase58()); let keys = Object.fromEntries( names.map((name, idx) => [name, PrivateKey.fromBase58(base58Keys[idx])]) ) as Record<K, PrivateKey>; let addresses = Object.fromEntries( names.map((name) => [name, keys[name].toPublicKey()]) ) as Record<K, PublicKey>; return { keys, addresses }; }