Build on CRT
CRT gives your application public keys to encrypt to and, later, the private keys — released on chain when the deadline passes without a cancel. What you encrypt, where you keep it and who gets it is yours. The reference application is dead-man-switch.
The contract
- Plaintext never leaves the browser. You generate a content key
Kand encrypt locally. - CRT splits
Kfor you.splitKeywith an access tree,wrapKeyto the runners’ public keys; you get back sealed envelopes to store next to your ciphertext. CRT never seesK. - The recovery file is yours to extend.
generateKitproduces one self-contained HTML file; your payload rides inside it and your hook runs onceKis recovered. - Cancel is one transaction (
buildCancel), with no fee. Make it as visible as create.
The flow in code
import { loadDeployment, listRunners, selectRunners, buildCreate, readSwitch,
verifyNodes, buildDescriptor, buildArm, wrapKey, generateKit, buildCancel } from '@crt/client';
const dep = await loadDeployment('testnet');
const plan = selectRunners(await listRunners(dep), { n: 8 }); // staked, attested, diverse
const deadline = Math.floor(Date.now() / 1000) + 180 * 86400;
const { tx, T } = await buildCreate({ signer, deployment: dep, deadline, runners: plan,
heartbeatBlocks: 8000n, termBlocks: 180n * 8000n });
await signer.sendTransaction(tx); // one transaction
let sw; do { sw = await readSwitch(dep, T); } // wait for 8 commits
while (sw.nodeCells.filter(c => c.state === 1).length < 8);
await verifyNodes(dep, T, plan); // hard fail, no override
const descriptor = await buildDescriptor(dep, T, plan,
{ kind: 'threshold', t: 5, n: 8, leaves: plan.map((_, i) => ({ node: i })) });
await signer.sendTransaction(await buildArm({ signer, deployment: dep, T,
descriptorHash: descriptor.descriptor_hash }));
const K = crypto.getRandomValues(new Uint8Array(32));
const ciphertext = await yourEncrypt(K, plaintext); // your format
const envelopes = await wrapKey(K, descriptor);
download('kit.html', generateKit({ descriptor, envelopes,
application: { name: 'your-app', version: '1', payload: { ciphertext } } }));
// later, if the user changes their mind:
await signer.sendTransaction(await buildCancel({ signer, deployment: dep, T }));
verifyNodes checks every Node Cell against the deployment and the CSR registry and throws on any mismatch. There is no flag, option or environment variable that skips it; a test in the repository makes sure none appears.
Extending the recovery file
The kit exposes window.CRT_KIT.application with your payload and calls window.crtApplication.onKey(K) after recovery. Your script is appended to the file; it must be as self-contained as the kit itself — no network, no CDN — so that it still opens in 2040. The file is byte-for-byte reproducible from the descriptor, the envelopes and your payload.
What to tell your users
- The duration risk and the two margins (threshold and mandatory), separately.
- That a runner dishonest from day one is not defended against — hence thresholds and diversity.
- The cost split: tips are spent, cells come back.
- That released keys are public on chain: after the deadline, whoever has the recovery file can decrypt. The file is the secret-bearing artefact of your application; CRT’s data is all public.
The pieces
contracts/crt-core, a sharedno_stdlibrary, andcrt-node-lock, the one CKB script.service/- The program CSR runs; the state machine of a run fits on one screen.
client/- Access trees, envelopes, descriptor, kit, transaction builders, recovery, a CLI.
scripts/devnet-e2e.sh- A devnet with three runners and the full scenario, in one command.
Developer guide: docs/developers.md. Protocol: SPEC.md.