ckb-ward
v0.8.0
Published
Ward, lock proof for CKB: prove control of any CKB lock by running the lock on a transaction that can never land
Maintainers
Readme
Ward
Lock proof for CKB. A lock-agnostic way for any CKB wallet to prove it controls a lock, with a single signature. Nothing is sent and nothing is spent. It is the CKB counterpart of Ethereum's EIP-1271 and Bitcoin's BIP-322.
What it is
On CKB a lock is a program, not a signature scheme. "Prove this wallet is mine" has no single answer: a secp256k1 key, a JoyID passkey, a multisig, Omnilock in one of its modes and a smart-account lock each prove control a different way.
Ward gives them one answer. The wallet signs a transaction that can never be committed. The verifier rebuilds that transaction itself, reads the lock's cell deps from the chain, and runs the lock in CKB-VM. Exit 0 means the wallet controls the lock. One verifier handles every lock that signs the transaction hash, and any wallet that can sign an ordinary transaction can sign the proof, with no new code on either side.
The full standard, with byte-exact templates, the rules a platform must follow, and test vectors, is in docs/SPEC.md.
Why it matters
Linking a wallet to an account is the first step of almost everything a CKB site wants to do: sign in, gate a community, check an airdrop, prove reserves, or count a holder's weight in a vote. Today a site checks a signed message, which proves a key, not the lock that holds the coins. Some accept one signature type: Metaforo binds only Neuron-style signatures (secp256k1 signed messages), so a holder whose Nervos DAO deposit sits under JoyID, a multisig, Omnilock or a smart-account lock cannot take part there. Others accept the six types CCC verifies, which still leaves out a multisig, the quantum-resistant lock and smart-account locks. Checking each scheme separately does not scale: every new lock needs new verifier code and new wallet code.
Running the lock itself needs neither, so Ward works with wallets that do not exist yet, as long as they can sign a transaction. That is what lets a voting platform count any wallet's deposit, not only the ones it was written to understand.
Try it
The playground runs each use case on its own, on testnet, with any CKB wallet. Nothing there is real.
- Prove a wallet is yours, What a wallet shows, What you sign: the building block, and what your wallet does with it.
- Sign in with a wallet: enter a site with no password and no account.
- Members only: open a community, content, or a mint to wallets that hold enough.
- Airdrop claim: see if a wallet qualified at a past snapshot, its score in CKB-days, and on testnet claim its share of a test token pool, sent to any address.
- Proof of reserves: prove several addresses and add up the CKB you can prove.
- DAO voting: count any wallet's Nervos DAO deposit in a community vote.
The DAO voting example is a full reference platform for the rules of section 9 of the spec: it binds a lock from any wallet CCC connects, freezes sign-up while a vote is open, and counts each wallet's Nervos DAO deposit at one snapshot block. Its server lives in playground/; the standalone ward-demo now opens it.
How it works
- The only input points at an out point that cannot exist:
tx_hash = ckbhash("CKB lock proof v1\n" || lock hash || message),index = 0xffffffff. The verifier resolves it to{ capacity u64::MAX, the claimed lock }, so a key that may only move part of an account cannot prove it. One output under the claimed lock carries the message, so a wallet reads from the transaction which of its locks is asked to sign. - The message names the platform, the account, the lock hash, the chain's genesis hash, the time and a single-use nonce.
- After the lock accepts, the verifier runs it twice more, with an empty witness and with the same witness on another message. A lock that opens either way is open to anyone, and the proof is refused.
- An Omnilock in administrator mode is refused: any key on its admin list opens it, the owner's lock included.
Nodes refuse the proof as Unknown(OutPoint). So a node cannot verify a proof either; the verifier needs a VM.
There are two forms of the proof, and the verifier accepts both. Form 1 names an out point that cannot exist. Form 2 (proofTemplate(lock, message, { version: 2 })) names output 0 of a synthetic previous transaction (proofPrevious), for signers that check every input against the transaction its hash names. The lock sees the same input cell in both. SPEC section 4 has the details; tests/vectors-v2/ has 12 signed form 2 proofs.
Install
npm install ckb-wardThree entries:
ckb-ward: everything, the verifier included. Node only: the runners spawn ckb-debugger or ward-vm.ckb-ward/browser: the verifier without the runners that start a process. No Node built-ins: a page can verify a proof itself, running the lock withckbVmJs(below).ckb-ward/wallet:message,parseMessage,proofTemplate,readProofand the constants. No Node built-ins, so it bundles for a browser. This is what a wallet or a site needs.
A Rust backend can use the crate in rust/: the same message, template, verifier and snapshot rules, with the lock run in process by ckb-script, the node's own crate. Not on crates.io yet; it installs from git.
Use
import { ccc } from "@ckb-ccc/core";
import { ckbDebugger, message, proofTemplate, verify } from "ckb-ward";
const CHAIN = "0x10639e0895502b5688a6be8cf69460d76541bfa4821629d86d62ba0aae3f9606"; // testnet genesis, from config
// Platform: write the message, and store it under its nonce.
const text = message({ domain: "dao.example", account: "user-42", lock, chain: CHAIN, issuedAt: new Date(), nonce });
// Wallet: sign the template like any transaction (any CCC signer).
let tx = proofTemplate(lock, text);
tx = await signer.prepareTransaction(tx);
tx = await signer.signOnlyTransaction(tx);
// Platform: verify against what it stored. Every field of expect is required.
const result = await verify(
{ lock, message: text, tx },
{
rpcUrl: "https://testnet.ckb.dev/rpc",
runLock: ckbDebugger(),
expect: { message: stored.message, domain: "dao.example", account: "user-42", nonce, chain: CHAIN, maxAgeSeconds: 600 },
claimNonce: () => markUsedIfUnused(nonce), // compare-and-set, before any chain read
},
);
// { ok: true, fields, cycles, cellDeps } or { ok: false, reason, run? }verify refuses when expect is missing, when the message is not the one issued, when the lock is an Omnilock in administrator mode, when the transaction is not exactly the template the verifier builds, when it breaks a limit (cell deps, dep group members, size), when a cell dep is not live on the chain, when the lock exits non-zero, or when the lock also opens without the owner. It throws only when the node cannot be reached or the runner cannot start. cellDeps lists the cells the proof ran with; a binding stays valid while they are live.
Verifying is the easy half. A platform that counts weight from bindings also needs the rules of section 9 of the spec: one active binding per lock, bindings frozen while a vote is open, weight read at one snapshot block from Nervos DAO deposits only, and a binding counted only while the cells its proof ran with were live at that block:
import { daoWeightAt, depsLiveAt } from "ckb-ward";
const at = await depsLiveAt(rpcUrl, binding.cellDeps, snapshotBlock); // cellDeps as verify() returned them
if (!at.live) skip(binding); // at.deps says which cell, and when it was created or spent
const { weight } = await daoWeightAt(rpcUrl, binding.lock, snapshotBlock); // shannons in DAO depositsdaoWeightAt counts only the Nervos DAO deposits under exactly that lock that were live at the snapshot block. A cell in phase 1 of a withdrawal keeps the DAO type but is not counted (it comes back in withdrawing), and a lock whose args merely start the same way weighs nothing. It throws rather than give a weight it could not read in full.
Wallets can call readProof(tx, lock) (from ckb-ward/wallet) to recognise a proof request and show its domain next to the site's origin, instead of a transfer.
Wallets that sign it
- Cellula wallet (testnet, since 2026-11-05). A site asks through the wallet link (
cellula-sdkCellulaWalletSigner,signTransaction(proofTemplate(lock, message))). The wallet shows the request as a proof: who asks, the account, the address, and that nothing leaves. It refuses a proof for another site, another network or an address that is not its own, and any request from a site on another device. Tested through its screen with a starter and a guarded account, and with a real phone passkey (section 13 of the spec). - JoyID signs the template in its app (vector V2), but shows it as a transaction.
Through CCC, the playground also signs with MetaMask, UniSat, OKX and UTXO Global (Omnilock in Ethereum and Bitcoin modes), among others.
Lock runner
runLock is pluggable: it receives a ckb-debugger mock transaction and returns { code, cycles, output }. ckbDebugger() runs ckb-debugger (tested with 1.1.1) and reads only the debugger's own final lines and exit status, never text the lock printed:
ckbDebugger(); // `ckb-debugger` on PATH
ckbDebugger({ command: "/root/.cargo/bin/ckb-debugger", wsl: { distro: "Ubuntu" } }); // Windows, through WSL
ckbDebugger({ maxCycles: 70_000_000, tmpDir: "/tmp" }); // defaults shown for maxCyclesckb-debugger is a development tool: its VM version does not follow the chain, and it adds syscalls no node has. For production, wardVm() runs ward-vm (in vm/): the node's own ckb-script, from the release mainnet and testnet run (0.210.0), under the chain's consensus at the tip's epoch, with only the node's syscalls (section 11 of the spec).
cd vm && cargo build --release # target/release/ward-vmimport { tipEpoch, wardVm } from "ckb-ward";
const rpcUrl = "https://mainnet.ckb.dev/rpc";
wardVm({ command: "vm/target/release/ward-vm", chain: "mainnet", epoch: () => tipEpoch(rpcUrl) });In a browser, or anywhere without a process to start, ckbVmJs() runs the lock with ckb-vm-js: CKB's own transaction verifier and CKB-VM compiled to WebAssembly. Ward does not depend on it; create its verifier and pass it in. The chain's consensus and tip header are read from rpcUrl.
import { ckbVmJs, verify } from "ckb-ward/browser";
import { createVerifier } from "ckb-vm-js";
const runLock = ckbVmJs({ verifier: await createVerifier(), rpcUrl });
const result = await verify(proof, { rpcUrl, runLock, expect });In Node, ckb-vm-js cannot fetch its .wasm from a file URL; read it and pass the bytes: createVerifier({ wasm: await readFile(new URL(import.meta.resolve("ckb-vm-js/wasm"))) }).
Measured on 2026-11-17 with ckb-vm-js 0.2.0 from npm (npm i [email protected]): every saved vector gives the same exit code as ward-vm, accepted and with one signature bit flipped, and the same cycles when accepted. Bundled with Vite and run in Chromium 149, verify() accepted the secp256k1, JoyID and Cellula smart-account proofs and refused each with one bit flipped, reading only the testnet RPC. Set CKB_VM_JS to an installed ckb-vm-js package directory to run tests/ckbvmjs.test.ts against it.
A bind server
examples/bind-server is a small service a voting platform can run next to its current binding: it issues a proof request, verifies the signed proof, and reads the DAO weight of the bound address at a snapshot block.
Tests
npm install
npm run typecheck
npm testtests/vectors/ holds real signed proofs: from mainnet secp256k1, the JoyID app, PW-lock and the quantum-resistant lock, replayed against mainnet's cell deps, and from testnet secp256k1, the JoyID app with its main key and with a sub key, the Cellula smart-account lock (starter and guarded), a 2-of-3 multisig, anyone-can-pay, Omnilock in Dogecoin, Ethereum and Bitcoin modes (the last two are the locks CCC gives MetaMask, UniSat and OKX), the Nostr lock, PW-lock (Portal Wallet) and the quantum-resistant lock (Quantum Purse). Each is replayed with controls that must be refused: another message, one flipped signature bit, a wrong key, a missing or forged settings cell dep, one multisig signature where two are needed, anyone-can-pay with no signature, an empty witness, and test_tx_pool_accept on the node. Other tests cover a smart account with capped keys, an Omnilock whose administrator signs for the owner, locks anyone can open, a lock that prints a fake result, and the verifier's limits, each next to a control that passes.
Without configuration, tests that run a lock are skipped. Set CKB_DEBUGGER (the executable) and, on Windows, CKB_DEBUGGER_WSL (the WSL distro that has it), or WARD_VM and WARD_VM_WSL for ward-vm. With both set, tests/vm.test.ts runs every vector under both and checks that they agree. Set CKB_WARD_OFFLINE=1 to skip everything that needs the testnet RPC (CKB_RPC_URL overrides it).
CKB_DEBUGGER=ckb-debugger npm test
# Windows, Git Bash (stop it rewriting the Linux path):
MSYS_NO_PATHCONV=1 CKB_DEBUGGER_WSL=Ubuntu CKB_DEBUGGER=/root/.cargo/bin/ckb-debugger npm testThe vectors depend on testnet cell deps staying live.
Status
Prototype, on npm as ckb-ward. Vectors are from testnet, and two from mainnet. The spec is a v1 draft and may change.
A proof can carry a since and header deps for the locks that need them, so a matured absolute time lock or a header-reading lock can be proven. Known gaps are in section 12 of the spec: relative or not-yet-matured time conditions, and locks whose signature does not cover the transaction hash.
License
MIT, see LICENSE. Author: LusoCryptoLabs.
