Register keys
Every account in PQ-402 has two post-quantum keys on chain. Both come from the account’s phrase, and both are read by the account’s address, so the chain binds them to one identity.
| Key | Used for | Where others read it |
|---|---|---|
| ML-DSA-87 | signing payments, receipts and escrow withdrawals | the pqcKeyStatus precompile (0x…0a02) |
| ML-KEM-1024 | receiving sealed requests or answers | the KEM key registry, REST /qorechain/pqc/v1/kem/{address} |
The account helper
Section titled “The account helper”The guides share this helper. It derives the keys and sends native transactions:
/** * A QoreChain testnet account from a BIP-39 phrase: its EVM address, its * ML-DSA-87 key, its ML-KEM-1024 sealing keys, and a helper that sends native * (Cosmos) transactions, which key registration and EVM windows need. */import { StargateClient } from "@cosmjs/stargate";import type { Hex } from "@pq402/core";import { deriveSealKeys } from "@qorechain/qoreseal";import { EthNativeSigner, deriveUnifiedAccount, getNetwork } from "@qorechain/sdk";import { mnemonicToAccount } from "viem/accounts";
export const testnet = getNetwork("testnet");
export async function accountFromMnemonic(mnemonic: string) { const unified = await deriveUnifiedAccount(mnemonic, 0); return { /** `0x` address: the payer or the gateway in PQ-402 messages. */ address: mnemonicToAccount(mnemonic).address as Hex, /** The same account in bech32 form, for native transactions. */ qor: unified.cosmos, /** ML-DSA-87 key pair: signs payments and receipts. */ mldsa: unified.pqc, /** ML-KEM-1024 key pair: opens what is sealed to this account. */ seal: deriveSealKeys({ mnemonic }), /** Signs EVM transactions (deposits, settlements). */ evm: mnemonicToAccount(mnemonic), unified, };}
export type Account = Awaited<ReturnType<typeof accountFromMnemonic>>;
type Messages = Parameters<EthNativeSigner["sign"]>[0]["messages"];
/** Sends a native transaction; `hybrid` adds the account's ML-DSA-87 signature. */export async function sendNative(account: Account, mode: "hybrid" | "classical", messages: Messages) { const res = await fetch(`${testnet.endpoints.rest}/cosmos/auth/v1beta1/accounts/${account.qor}`); if (res.status === 404) throw new Error(`${account.qor} has no QOR yet: use the faucet first`); const body = (await res.json()) as { account?: Record<string, unknown> }; const info = (body.account?.base_account ?? body.account ?? {}) as Record<string, string>; const signer = new EthNativeSigner(account.unified, { signMode: mode, rest: testnet.endpoints.rest }); const rpc = await StargateClient.connect(testnet.endpoints.rpc); try { const out = await signer.signAndBroadcast(rpc, { chainId: testnet.chainId, accountNumber: BigInt(info.account_number ?? "0"), sequence: BigInt(info.sequence ?? "0"), fee: { amount: [{ denom: "uqor", amount: "100000" }], gas: "800000" }, messages, }); return out.transactionHash; } finally { rpc.disconnect(); }}
export function env(name: string): string { const value = process.env[name]?.trim(); if (!value) throw new Error(`set ${name} (see the testnet quickstart)`); return value;}Register both keys
Section titled “Register both keys”/** * Registers an account's two post-quantum keys on the QoreChain testnet: * 1. its ML-DSA-87 key, with proof of possession (signs payments), * 2. its ML-KEM-1024 key in the KEM key registry (receives sealed bodies). * * QORE_MNEMONIC="..." npx tsx register-keys.ts */import { qorechainTestnet } from "@pq402/scheme-qorechain";import { fetchMlkemPublicKey } from "@qorechain/qoreseal/network";import { buildRegisterPqcKeyMsg, fetchPqcStatus, msg, signProofOfPossession } from "@qorechain/sdk";import { accountFromMnemonic, env, sendNative, testnet } from "./account.js";
const account = await accountFromMnemonic(env("QORE_MNEMONIC"));const rest = qorechainTestnet.rest;
// 1. ML-DSA-87. The proof of possession shows the chain you hold the secret key.const status = await fetchPqcStatus({ rest, address: account.qor });if (status.registered) { console.log("ML-DSA-87 key already registered");} else { const proofOfPossession = signProofOfPossession({ chainId: testnet.chainId, account: account.qor, keypair: account.mldsa, }); const register = buildRegisterPqcKeyMsg(account.qor, { pqcKeypair: account.mldsa, proofOfPossession }); // The first registration is classically signed: the chain has no ML-DSA key to check yet. console.log(`ML-DSA-87 key registered: ${await sendNative(account, "classical", [register])}`);}
// 2. ML-KEM-1024, algorithm 2. Hybrid-signed, so the registered ML-DSA-87 key vouches for it.const registerKem = msg.pqc.registerKemKey({ sender: account.qor, algorithmId: 2, publicKey: account.seal.mlkemPublicKey,});console.log(`ML-KEM-1024 key registered: ${await sendNative(account, "hybrid", [registerKem])}`);
// Check: the registry now returns this account's key.const onChain = await fetchMlkemPublicKey({ rest, address: account.qor });console.log(`registry matches: ${Buffer.from(onChain).equals(Buffer.from(account.seal.mlkemPublicKey))}`);QORE_MNEMONIC="..." npx tsx register-keys.tsML-DSA-87 key registered: <transaction hash>ML-KEM-1024 key registered: <transaction hash>registry matches: trueThe account needs some QOR first, from the faucet.
Why the order matters
Section titled “Why the order matters”The ML-DSA-87 registration carries a proof of possession, and the chain marks the key possessionProven. PQ-402
accepts only keys with that flag. The ML-KEM-1024 registration then goes in a hybrid-signed transaction, so the chain
checks the account’s registered ML-DSA-87 key before it accepts the KEM key. The account in the recorded runs did this in
D4E53C1B0164FC76656D07CB76611134E7EE0C8300CC6110961EAAB096DAD5EC, whose transaction carries a 4,627-byte ML-DSA-87
signature.