Quick start · ERC-8441 scheme 3
Post-quantum stealth addresses
Scheme 3 combines ML-KEM-768 and secp256k1, so an observer who records announcements today cannot link them to a receiver later. It is announced under ERC-5564 schemeId 3. The code is the erc8441-ts reference and passes its official vectors. The meta-address is 1250 bytes, so the registry commitment (ERC-8441 section 4) stores its hash instead of the bytes.
1. Recipient: generate a meta-address
From fresh randomness, from a 32-byte master you store, or from a wallet signature. trackingKey and masterKey are secrets.
import { generatePqKeys } from "@ephmoney/stealth-receive/pq";
const keys = generatePqKeys(); // fresh randomness; or generatePqKeys({ master, index: 0 })
// keys.metaAddress 0x + 2500 hex (1250 bytes), public
// keys.commitment keccak256(metaAddress), what commitKeys stores
// keys.trackingKey 96 bytes, secret (may go to a scanning service)
// keys.masterKey spending key, secret
2. Recipient: commit it with commitKeys
Stores keccak256(metaAddress) in one slot and puts the bytes in the event log. Use buildCommitHashTx to store only the hash and publish the bytes elsewhere (ENS, IPFS, your site).
import { buildCommitKeysTx, COMMITMENTS_SEPOLIA } from "@ephmoney/stealth-receive";
const registry = COMMITMENTS_SEPOLIA; // Sepolia sketch contract, pass your own elsewhere
const tx = buildCommitKeysTx({ registry, meta: keys.metaAddress });
// await wallet.sendTransaction(tx); // about 159k gas, bytes go to the event log
// or hash only: buildCommitHashTx({ registry, meta: keys.metaAddress }) // about 128k gas
3. Sender: look it up, verify it, pay it
Reads commitmentOf, takes the bytes from the log, and accepts them only if their hash matches and they pass the ERC-8441 section 2.2 checks. This example reads the public Sepolia demo recipient, so it runs as is.
import { httpRpc, COMMITMENTS_SEPOLIA } from "@ephmoney/stealth-receive";
import { resolveCommittedMetaAddress, preparePqPayment } from "@ephmoney/stealth-receive/pq";
const registry = COMMITMENTS_SEPOLIA;
const rpc = httpRpc("https://ethereum-sepolia-rpc.publicnode.com");
const registrant = "0xdF8500032a476Dd0feA06A5a70F9287295EAC2dA"; // public Sepolia demo recipient
const resolved = await resolveCommittedMetaAddress(rpc, { registry, registrant, fromBlock: 12_270_000 });
// null: nothing committed. Throws if bytes are missing or do not hash to the commitment.
const pay = preparePqPayment({ metaAddress: resolved.metaAddress, amountWei: 10n ** 14n }); // 0.0001 ETH
// await wallet.sendTransaction(pay.sendTx); // ETH to pay.stealthAddress
// await wallet.sendTransaction(pay.announceTx); // Announcer, schemeId 3
The view tag is checked first, then ML-KEM decapsulation, then the derived address. Anything else is skipped. For several batches build the scanner once with createPqScanner.
import { pqAnnouncementLogFilter, scanPqLogs } from "@ephmoney/stealth-receive/pq";
const logs = await provider.request({
method: "eth_getLogs",
params: [pqAnnouncementLogFilter({ fromBlock: 24_000_000 })],
});
const { trackingKey, metaAddress, masterKey } = keys;
const payments = scanPqLogs(logs, { trackingKey, metaAddress, masterKey });
// payments[i].stealthAddress, .amountWei, .stealthPrivateKey (only with masterKey)