Signatory

Built on

Try the guided payment demo

Check a post-quantum signature on Aevum in one call.

An ML-DSA-65 verifier is live on QDay Aevum testnet. Signatory accounts use it to guard tUSD8, and your contracts and scripts can call it the same way. Try it here: no install, no wallet, no gas.

The call5,293 bytes, read-only, to the verifier at 0x3066…9919 (opens the Aevum explorer)
  1. public key1,952 bytes
  2. signature3,309 bytes
  3. message32 bytes

Drawn to scale: the signature is about 51 times the size of an elliptic-curve one. Nothing is asked until you press the button.

Your browser makes the key and signs; the contract on Aevum answers. The key lives in this page’s memory and is gone when you leave. The same three steps as code are the first example below.

Quickstart

Node 22 and pnpm. The first example only reads from Aevum, so it needs no key and no gas.

Terminal
git clone https://github.com/a252937166/signatory signatory && cd signatory
pnpm install
pnpm example:verify
It prints
the signed message: true
another message:    false

That is all of scripts/src/examples/verify.ts: a key, a signature, one call.

verify.ts
import { bytesToHex, concat, createPublicClient, http, keccak256, toHex, type Hex } from "viem";
import { aevumTestnet, deployment, newMnemonic, pqKeyFromMnemonic, pqSign } from "@signatory/core";

const client = createPublicClient({ chain: aevumTestnet, transport: http() });

// 1. An ML-DSA-65 key, derived from a mnemonic the way QDay's PQC SDK derives it.
const key = pqKeyFromMnemonic(newMnemonic());

// 2. Sign a 32-byte message with it.
const message = keccak256(toHex("hello, Aevum"));
const signature = pqSign(message, key.secretKey);

// 3. Ask the verifier contract: public key ‖ signature ‖ message. It answers 1 or 0.
async function accepted(what: Hex): Promise<boolean> {
  const call = concat([bytesToHex(key.publicKey), signature, what]);
  const { data } = await client.call({ to: deployment.verifier, data: call });
  return data !== undefined && BigInt(data) === 1n;
}

console.log("the signed message:", await accepted(message));
console.log("another message:   ", await accepted(keccak256(toHex("hello, Aevum!"))));

Three more sit in the same folder. Each is one file, and each has been run against Aevum.

  1. Find a key’s account

    It only reads. An account’s address follows from its key, so it is known before the account exists; this prints its balance and every run it has approved, from the chain alone.

    pnpm example:account

    Read account.ts
    account.ts
    import { createPublicClient, formatUnits, http, zeroHash } from "viem";
    import { mnemonicToAccount } from "viem/accounts";
    import { aevumTestnet, deployment, newMnemonic, walletFromMnemonic } from "@signatory/core";
    import { predictAccount, readAccount, readRuns, refText } from "@signatory/core";
    
    const client = createPublicClient({ chain: aevumTestnet, transport: http() });
    const mnemonic = process.env.MNEMONIC ?? newMnemonic();
    
    // One mnemonic gives the ML-DSA-65 key, and an ordinary key to act as the account's brake.
    const wallet = walletFromMnemonic(mnemonic);
    const brake = mnemonicToAccount(mnemonic, { addressIndex: 1 }).address;
    
    // The address follows from the key, the brake and a salt, so it is known before the account exists.
    const account = await predictAccount(client, deployment.factory, wallet.keyHash, brake, zeroHash);
    const state = await readAccount(client, account, deployment.token);
    const held = `${formatUnits(state.balance, 6)} tUSD8${state.frozen ? ", frozen" : ""}`;
    console.log(`account ${account}`);
    console.log(state.deployed ? `open, holds ${held}` : "not opened yet");
    
    // Every run it has approved, rebuilt from the chain alone.
    for (const run of state.deployed ? await readRuns(client, account) : []) {
      const lines = run.lines.map((line) => `${refText(line.ref)} ${line.status}`);
      console.log(`run ${refText(run.memo) ?? run.root.slice(0, 10)}: ${lines.join(", ")}`);
    }
  2. Pay once

    It sends one transaction, to the token itself. The signature travels with the payment, and tUSD8 has it checked before it moves anything.

    MNEMONIC="…" GAS_KEY=0x… pnpm example:pay

    Mined when we ran it3,889,765 gas0x65d25a60…eb6e56 (opens the Aevum explorer)

    Read pay.ts
    pay.ts
    import { createPublicClient, createWalletClient, http, zeroHash } from "viem";
    import type { Address, Hex } from "viem";
    import { mnemonicToAccount, privateKeyToAccount } from "viem/accounts";
    import { aevumTestnet, deployment, predictAccount, readTokenDomain } from "@signatory/core";
    import { authorizeDigest, directLine, inlinePaymentTx, lineDigest } from "@signatory/core";
    import { pqSign, walletFromMnemonic } from "@signatory/core";
    
    function need(name: string): string {
      const value = process.env[name];
      if (!value) throw new Error(`Set ${name}. See the top of this file.`);
      return value;
    }
    
    const client = createPublicClient({ chain: aevumTestnet, transport: http() });
    const wallet = walletFromMnemonic(need("MNEMONIC"));
    const brake = mnemonicToAccount(need("MNEMONIC"), { addressIndex: 1 }).address;
    const account = await predictAccount(client, deployment.factory, wallet.keyHash, brake, zeroHash);
    const payee = (process.env.PAYEE ?? deployment.merchant) as Address;
    
    // 1. The payment: an EIP-3009 authorization drawn on the account, good for the next hour.
    const now = (await client.getBlock()).timestamp;
    const hour = { validAfter: 0n, validBefore: now + 3_600n };
    const line = directLine(payee, 1_000n, `EXAMPLE-${now}`, hour);
    
    // 2. tUSD8's own digest for it, wrapped for this account and signed with the ML-DSA-65 key.
    const token = await readTokenDomain(client, deployment.token);
    const digest = authorizeDigest(aevumTestnet.id, account, lineDigest(token, account, line));
    const signature = pqSign(digest, wallet.pq.secretKey);
    
    // 3. Anyone may submit it. tUSD8 asks the account, and the account asks the verifier.
    const sender = privateKeyToAccount(need("GAS_KEY") as Hex);
    const submitter = createWalletClient({ account: sender, chain: aevumTestnet, transport: http() });
    const tx = { ...inlinePaymentTx(deployment.token, account, line, signature), gas: 6_000_000n };
    // Simulate first: a refusal then costs nothing.
    await client.call({ account: sender.address, ...tx });
    const hash = await submitter.sendTransaction({ ...tx, type: "legacy" });
    const receipt = await client.waitForTransactionReceipt({ hash });
    
    console.log(`${receipt.status}: 0.001 tUSD8 from ${account} to ${payee}`);
    console.log(`${receipt.gasUsed} gas, https://explorer-test.qday.info/tx/${hash}`);
  3. Approve a run, settle a line

    It sends two transactions. One signature approves a list of bills, and the 3.7 million gas of checking it is paid once. Each bill then settles on its own, with a Merkle proof and no key at all.

    MNEMONIC="…" GAS_KEY=0x… pnpm example:run

    Approved3,956,635 gas0xa4281abb…f8ef9b (opens the Aevum explorer)

    Settled103,050 gas0x9e09d00b…1d63c4 (opens the Aevum explorer)

    Read run.ts
    run.ts
    import { createPublicClient, createWalletClient, http, zeroHash } from "viem";
    import type { Address, Hex } from "viem";
    import { mnemonicToAccount, privateKeyToAccount } from "viem/accounts";
    import { aevumTestnet, deployment, predictAccount, readTokenDomain } from "@signatory/core";
    import { approveRunTx, directLine, merkleProof, planRun, refOf } from "@signatory/core";
    import { pqSign, runDigest, settleDirectTx, walletFromMnemonic, type Tx } from "@signatory/core";
    
    function need(name: string): string {
      const value = process.env[name];
      if (!value) throw new Error(`Set ${name}. See the top of this file.`);
      return value;
    }
    
    const client = createPublicClient({ chain: aevumTestnet, transport: http() });
    const sender = privateKeyToAccount(need("GAS_KEY") as Hex);
    const submitter = createWalletClient({ account: sender, chain: aevumTestnet, transport: http() });
    
    async function submit(label: string, tx: Tx, gas?: bigint) {
      // Simulate first: a refusal then costs nothing.
      await client.call({ account: sender.address, ...tx, gas });
      const hash = await submitter.sendTransaction({ ...tx, gas, type: "legacy" });
      const receipt = await client.waitForTransactionReceipt({ hash });
      console.log(`${label}: ${receipt.status}, ${receipt.gasUsed} gas`);
      console.log(`  https://explorer-test.qday.info/tx/${hash}`);
    }
    
    const wallet = walletFromMnemonic(need("MNEMONIC"));
    const brake = mnemonicToAccount(need("MNEMONIC"), { addressIndex: 1 }).address;
    const account = await predictAccount(client, deployment.factory, wallet.keyHash, brake, zeroHash);
    const payee = (process.env.PAYEE ?? deployment.merchant) as Address;
    
    // 1. The bills. Each line is an EIP-3009 authorization: a payee, an amount, dates, a reference.
    const now = (await client.getBlock()).timestamp;
    const hour = { validAfter: 0n, validBefore: now + 3_600n };
    const lines = [
      directLine(payee, 1_000n, `RUN-${now}-1`, hour),
      directLine(payee, 2_000n, `RUN-${now}-2`, hour),
    ];
    
    // 2. One signature over the Merkle root of the lines, their total, their references, the expiry.
    const token = await readTokenDomain(client, deployment.token);
    const terms = { notAfter: hour.validBefore, memo: refOf("example run") };
    const run = planRun(token, account, lines, terms);
    const signature = pqSign(runDigest(aevumTestnet.id, account, run), wallet.pq.secretKey);
    await submit("approve the run", approveRunTx(account, run, signature), 6_000_000n);
    
    // 3. Settle the first line. No key is involved: a Merkle proof shows the line belongs to the run.
    const proof = merkleProof(run.digests, 0);
    const settle = settleDirectTx(deployment.token, account, lines[0]!, run.root, proof);
    await submit("settle line 1", settle);

MNEMONIC is an account’s key: the app shows a demo account’s under “Show the mnemonic”. GAS_KEY is any Aevum testnet key holding a little tQDAY, which QDay’s faucet gives out. Whoever submits a payment pays its gas, and that need not be the payer.

Take payments from an account

tUSD8 is Circle’s FiatToken v2.2. When the payer is a contract, its EIP-3009 functions ask that contract whether the signature is good, and a Signatory account answers by checking ML-DSA-65. A contract that takes tUSD8 through EIP-3009 can already be paid by one. The token is not modified, and neither is yours.

Your function passes the signature on as bytes

Nothing to change. The bytes are longer than an elliptic-curve signature: 3,310 for a single payment, a few hundred for a line of an approved run.

Solidity
// Your contract. Nothing in it knows about ML-DSA, or about Signatory.
function pay(
    address from, uint256 value, uint256 validAfter, uint256 validBefore,
    bytes32 nonce, bytes calldata signature
) external {
    // tUSD8 sees that `from` is a contract and asks it: isValidSignature(digest, signature)?
    tUSD8.receiveWithAuthorization(
        from, address(this), value, validAfter, validBefore, nonce, signature
    );
}

Your function takes v, r and s

So does Checkout from the organizers’ starter kit, and it is paid here as it is. The payer approves the bill as a line of a run. Anyone may then call pin on the account, which records that this exact payment belongs to the run. From then on the account says yes to any 65 bytes for that payment and for no other, so Checkout is called with v, r and s all zero.

TypeScript
import { deployment, merkleProof, settleCheckoutTx } from "@signatory/core";

// `run` is the approved run and `index` the bill's place in it.
const line = run.lines[index];
const proof = merkleProof(run.digests, index);

// Pin the line, then let Checkout pull the payment: two calls anyone may make, sent as one.
const tx = settleCheckoutTx(deployment.checkout, account, line, run.digests[index], run.root, proof);

In the recorded run: pinned in 0x96bc053d…ef5b0b (opens the Aevum explorer) for 61,295 gas, then pulled by Checkout in 0x26626548…9a1d5a (opens the Aevum explorer) for 156,232.

What an account accepts

tUSD8 hands the account its own digest for the payment and the signature bytes it was given. The account reads them as one of three things.

The bytesStand forThe account checks
0x01 ‖ signatureone payment, signed by the account key over Authorize(digest)the ML-DSA-65 signature, in that transaction: about 3.7M gas
0x02 ‖ abi.encode(root, proof, release)a line of a run the key approved earliera Merkle proof against the stored root; no signature is checked again
any 65 bytesa line that was pinned beforehandthat the digest is pinned to a run that is still live

Every digest the key signs is EIP-712, bound to the chain and to the account: domain Signatory Account, version 1. Authorize wraps the token’s digest for one payment. PaymentRun commits to the token, the Merkle root of the lines, the hash of their invoice references, their total and count, an expiry, and an optional key that must release each line. The functions that build them are in packages/core.

Keys come from QDay’s PQC SDK. A key is derived from a BIP-39 mnemonic exactly as the SDK derives it, so the Go SDK, the command-line signer in signer/ and this site’s browser signer make the same key from the same words, and each accepts the others’ signatures. make compat checks that, on-chain included.

Network and addresses

Chain ID
44005QDay Aevum testnet
RPC
https://rpc-test.qday.infoHTTPS only, legacy transactions, 1 gwei
ML-DSA-65 verifier
0x3066c6fff86d50FcEC743A6CD9f363e710919919 (opens the Aevum explorer)eth-act/ml-dsa-fv v3, unmodified. Call it with public key ‖ signature ‖ message.
SignatoryFactory
0x4210100f72628a3b0499c13dd6Ba7f0DeED54eD5 (opens the Aevum explorer)createAccount(publicKey, brake, salt) and predict(keyHash, brake, salt)
Account implementation
0xfeddb5aF80f450C1C896bB4Afbee52a3de8284C3 (opens the Aevum explorer)every account is a small proxy to it
tUSD8
0x456569838f1d43009A91ebA4263147Afd7233483 (opens the Aevum explorer)the organizers’ token: 6 decimals, EIP-712 domain tUSD8 / 2
Checkout
0x0433E5A3043DD88892daA697712A5Dc8ef3bd9a8 (opens the Aevum explorer)from the organizers’ starter kit, unmodified

Ours were deployed through the standard CREATE2 deployer with salt 0, so each address follows from its bytecode. The record links the deployments, and make verify rebuilds them from source.

What it costs

Gas used by mined transactions on Aevum testnet, where gas is 1 gwei of test tQDAY. A lattice signature is expensive to check, which is why a run checks one for many bills.

ActionGas
One ML-DSA-65 signature checkabout 3,710,000
One payment, its signature checked in the same transaction3,870,986
Approve a run of 3 lines3,970,627
Approve a run of 96 lines4,852,039
Settle a line directly, with its Merkle proof103,050
Settle a line through Checkout, pinned and pulled in one transaction198,409
Stop a line with the brake56,469
Open an account, storing its 1,952-byte public key625,593

Paying 96 bills one signature at a time would cost about 375 million gas. As one run it costs about 24 million.

The repository

The contracts are built with Foundry, the command-line signer is Go on QDay’s SDK, and everything else is TypeScript. MIT licensed.

Terminal
make install      # Solidity libraries and JavaScript packages
make test         # 40 contract tests, signed with real ML-DSA-65 keys
make test-fork    # 6 tests against the real tUSD8 code on a fork of Aevum
make compat       # QDay's Go SDK and the browser signer: same key, same signatures
make verify       # rebuild, then show the contracts on Aevum came from this source
make dev          # this site on http://localhost:3000
contracts/
SignatoryAccount, SignatoryFactory and their tests; the verifier and Checkout, both unmodified
packages/core/
digests, Merkle tree, key derivation, chain reads and transaction builders, used by every example here
signer/
new-mnemonic, public-key, sign and verify on the command line, on QDay’s PQC SDK
docs/
how it works, the threat model, and the record of every transaction