/** * The wallet seed: 32 bytes that derive the reserve key and every coin key. * Whoever holds it can withdraw and sweep the whole reserve, so store it like * a private key, in a secret manager, never in the repo or a log. */ import { randomBytes } from "node:crypto"; import { SEED_LEN } from "px402"; import { hex, unhex } from "./bytes.js"; /** A new seed, as the hex you store. Run once per agent. */ export function newSeedHex(): string { return hex(new Uint8Array(randomBytes(SEED_LEN))); } /** The seed from an environment variable holding 64 hex characters. */ export function seedFromEnv(name: string): Uint8Array { const value = process.env[name]; if (value === undefined || !/^(0x)?[0-9a-fA-F]{64}$/.test(value)) { throw new Error(`${name} must hold the 32-byte wallet seed as 64 hex characters`); } return unhex(value); } // node seed.js prints a new seed. if (process.argv[1]?.endsWith("seed.js") === true) { console.log(newSeedHex()); }