Tranfr — Programmable Recovery for CKB

This is indeed a missing part of the original cheque lock design, and I think it would be possible to add support for additional transfer methods using a fork lock from cheque.

Looking forward to your thoughts on this!

1 Like

Thanks, a fork of the cheque lock sounds right. My proposal: (1) the recipient’s claim no longer forces capacity back to the sender, so plain CKB reaches the recipient; (2) the hardcoded 6-epoch delay becomes a per-cell deadline in the args, with the recipient’s claim valid only once an absolute since reaches it; (3) the owner path is always valid, and a heartbeat is the owner recreating the cell with a later deadline (90 days by default in the frontend, any duration allowed). The rest stays as in Cheque. I already have a working version with tests and a full testnet lifecycle in the repo, which I can rebase onto the Cheque source if you prefer. Does this match what you had in mind?

I have many CKB wallets, but there is one CKB wallet that I own and cannot find the passphrase.This would be very helpful. Great work.

3 Likes

I am particularly concerned about the flow of cell capacity. In your current design, the args field might contain a significant amount of cell deadline data, which increases the minimum capacity required for a cell. However, for transactions involving only UDTs, the recipient could potentially claim the entire capacity without any restrictions.

I would suggest reconsidering this aspect of the design. Especially for scenarios where the operator intends to transfer only UDTs, without any plan to transfer CKB.

Thank you, I appreciate it. :folded_hands:

Good point on capacity. Right now the recipient takes the whole cell, so someone sending only UDTs would hand over the CKB deposit too. I see two fixes: (1) if the cell holds a UDT, the deposit returns to the owner when the recipient claims, like Cheque, and plain CKB cells let the recipient take it all; or (2) a switch in the cell chosen at creation. I can also make the cell info smaller to lower the deposit. Which do you prefer?

In my view, both approaches are viable. The former may offer an advantage in terms of CKB occupation.

1 Like

Sounds good. I take “the former” to mean option 1 (branch on type script, no extra args), so I’ll proceed with that and also look at trimming the args. Please let me know if you meant otherwise.

Update: capacity rule built, tested, and run on testnet

@Hanssen thanks for the capacity feedback. I went with option 1 (branch on type script), with no new args.

What changed

  • On a recipient claim, if a Tranfr input carries a type script (e.g. a UDT), the owner-locked outputs must return at least that input’s capacity. Plain CKB cells are unchanged: the recipient takes everything. The owner path is untouched.
  • The lock args stay at 72 bytes (full 32-byte hashes), so the minimum cell capacity is 113 CKB. I kept the full-length hashes for the larger collision margin. If you’d prefer 20-byte hashes to lower the occupation, say so and I’ll switch.

Verification

  • The Rust tests cover typed claims with no refund, an underpaid refund, a full refund, plain claims, and mixed inputs. The full output is in docs/cargo-test-output.txt (56 tests).
  • Testnet: full lifecycle for plain cells (create, extend, owner reclaim, early claim rejected by the node, recipient claim, owner reclaim) and a UDT claim that refunds the owner’s capacity and delivers the tokens to the recipient. Transaction hashes are in docs/testnet-evidence.md.
  • As you suggested, I tested the Time Lock + Cheque composition under ckb-testtool. For plain CKB, Cheque rule 1.b.ii (error 8) blocks the recipient’s claim, so the lock is a purpose-built one. The test and findings are in tests/src/composition.rs and docs/composition-evaluation.md.

This is testnet-only and unaudited. Feedback is welcome, and if you think I’ve missed an edge case in the refund rule, please tell me.

Tranfr: Project Completion Report

Programmable recovery for CKB self-custody

Report date: 9 November 2026 | Applicant: SalmanDev | Status: testnet deployment

1. Summary

Tranfr is a CKB lock script, a TypeScript SDK and a testnet web demo that give a self-custodied cell a recovery path. The owner keeps full control at all times. A designated recovery recipient can claim the cell only after an on-chain deadline has passed. The owner extends the deadline by renewing the cell, an ordinary owner spend that recreates it with a later deadline. Nothing depends on a custodian, oracle or off-chain service.

The design follows the program reviewer’s feedback on the original proposal: the hard-freeze model and the custom state machine were dropped, the owner can always spend, the recipient can claim once the deadline is reached, the heartbeat is an off-chain agreement with a 90-day default set in the frontend, and the SDK and frontend are treated as first-class deliverables.

Following that feedback, the Time Lock + Cheque composition was built and tested. It cannot pay native CKB to a recipient, so the delivered lock is a single purpose-built script that implements the same rules. This is documented with a runnable test suite (section 5).

The reviewer also raised a capacity concern for typed cells such as UDTs. The lock now includes a typed-cell refund rule (section 3).


2. Scope and design decisions

Requirement from feedback
Outcome
No hard freeze, no custom state machine
Done. There are two unlock paths and no stored state transitions.
Owner can always take the assets, even after the deadline
Done. The owner path is unconditional.
Recipient can take the assets once the deadline is reached
Done. The recipient path is gated by an absolute epoch since on every input in the script group.
Heartbeat is off-chain, 90 days by default, longer allowed
Done. Renewal is an owner spend that recreates the cell with a later deadline. The default is 540 epochs (about 90 days) and any longer period is allowed.
SDK and frontend are first-class
Done. A standalone TypeScript SDK and a web demo are in the repo.
Combine Time Lock with Cheque
Evaluated and not viable for native CKB. See section 5.
Capacity concern for typed assets
Addressed with a type-script branch in the recipient path. See section 3.

3. What was built

3.1 Tranfr lock script

  • Owner path. Valid at any time, before or after the deadline. Authorized by the owner’s signature.

  • Recipient path. Valid only when every input in the script group carries an absolute epoch since at or after the deadline stored in the cell’s args, and the recipient has signed.

  • Typed-cell refund rule. On a recipient claim, the capacity of any input that carries a type script (for example a UDT cell) must be returned to the owner, meaning the owner-locked outputs must total at least that capacity. Plain CKB cells carry no type script and the recipient takes them in full. Mixed transactions only need to refund the typed part. Sums use u128 so many capacities cannot overflow.

  • Args layout. Fixed width, 72 bytes, with full-length hashes. The minimum capacity of a Tranfr cell is therefore 113 CKB. Full-length hashes were kept for the larger collision margin.

  • Deployment. The testnet deployment is described in docs/deployment.md. It uses a Type ID, so the deployer can upgrade the binary.

What the lock does not do: it does not check the token output of a typed claim (amount, type or destination). Delivering the tokens to the recipient is the transaction builder’s job. The lock enforces only the owner’s capacity refund.

3.2 TypeScript SDK

A standalone package that builds to sdk/dist, with no imports outside its own directory. It covers creating a Tranfr, inspecting its policy and status, renewing, owner reclaim, and recipient claim.

  • Owner and recipient locks are validated as standard secp256k1 sighash locks, so funds cannot be locked behind an unusable lock type.

  • Renewal keeps the cell’s own inactivity period, with a minimum of 90 days, and refuses an earlier deadline unless the caller allows it explicitly. A heartbeat therefore cannot silently shorten a longer period.

  • Builders preserve type scripts on typed cells and require the type script’s cell deps. For typed claims, buildRecoveryClaim adds the owner refund output.

3.3 Web demo

A web application for the full lifecycle: create, renew, claim, reclaim, with the cell’s state and transaction status shown at each stage. It was redesigned in the final phase and is exercised by Playwright end-to-end specs.

Wallet view: Tranfr — recovery policy (CKB Testnet)

The standalone version is still https://tranfr-jet.vercel.app if you want to see the full flow including the recipient claim.

3.4 Documentation

The repo contains docs/spec.md, docs/security-model.md, docs/deployment.md, docs/implementation-plan.md, docs/testnet-evidence.md, docs/composition-evaluation.md and docs/cargo-test-output.txt. The README describes the delivered design.

4. Verification

4.1 Automated tests

  • Rust: 56 tests, all passing (saved output in docs/cargo-test-output.txt): 11 since-comparison tests, 34 integration tests (26 lock tests plus 8 composition tests) and 11 lock unit tests.

  • Lock coverage: both unlock paths, deadline boundaries, relative and other since metrics, every-input-in-group checks, the mode byte, malformed args and witnesses, signature tampering, and replay. New refund-rule cases: typed claim with no refund fails, typed claim with an underpaid refund fails, typed claim with a full refund passes, plain claim is unchanged, and mixed inputs refund only the typed part.

  • TypeScript: 47 SDK tests, all passing. Typecheck and build are clean.

4.2 Testnet lifecycle

The full run is recorded with explorer links in docs/testnet-evidence.md. Highlights:

  • Plain cells. Create, extend (owner renew), owner reclaim before the deadline, recipient claim after the deadline (199.99999236 CKB paid to the recipient, transaction 0x024f847f…1c35), and owner reclaim after the deadline (199.99999644 CKB paid to the owner, transaction 0x1f405df1…2ee8).

  • Early claim rejected. The SDK refuses to build an early claim. With the SDK check bypassed, the node itself rejects it as immature because of the since requirement.

  • Typed cell (UDT). A 200 CKB cell carrying 1,000,000 xUDT was claimed by the recipient after the deadline (transaction 0x5d0ae5b6…4343). The cell’s 200 CKB capacity was refunded to the owner as a plain cell, and the xUDT went to the recipient’s own token cell.

5. Time Lock + Cheque evaluation

The suggested composition was tested under ckb-testtool using the vendored testnet binaries, whose data hashes are asserted in the tests. Both role assignments were tried.

  1. The recipient’s claim cannot pay the recipient. With the recipient on the Cheque receiver path, RFC 0039 rule 1.b.ii requires the Cheque’s capacity to be returned to the sender. Paying the recipient fails with Cheque error 8 (SenderCapacityNotSame).

  2. Swapping the roles blocks the owner. The same rule then forces the owner’s own reclaim to send the capacity to the sender, so the owner cannot take their funds back as plain CKB.

  3. The owner is locked out for six epochs after every spend. The Cheque sender path accepts only a relative since of six epochs (about 24 hours), so each create or renew would freeze the owner for a day. Before the window it fails with Cheque error 11.

No role assignment delivers both “the recipient claims the CKB after the deadline” and “the owner can reclaim the CKB at any time.” Cheque is built for token transfers, where returning the capacity to the sender is the right behavior. The Tranfr lock keeps that behavior only where it is wanted, for typed cells.

The tests are in tests/src/composition.rs. A correction was also made during this work: an earlier draft of docs/implementation-plan.md wrongly said the Time Lock does not exist. It does, under ckb-devrel/ckb-proxy-locks, and it is listed on docs.nervos.org with mainnet and testnet deployments. The plan is corrected and the evaluation document records this.

6. Security model and known limitations

  • Unaudited, testnet only. No production audit has been done. Do not use this with real funds.

  • Owner race after the deadline. Because the owner path never freezes, the owner and recipient can race after the deadline. This is intended and documented in the security model.

  • Typed assets. The lock enforces only the capacity refund. Preserving the tokens in the recipient’s output is the builder’s responsibility, and typed cells need the type script’s cell deps.

  • Standard lock types only. Owner and recipient must use the standard secp256k1 sighash lock. The SDK rejects anything else.

  • Upgradeable deployment. The testnet deployment uses a Type ID, so the deployer controls the binary.

  • Minimum capacity. 113 CKB per cell. Shrinking the args to 20-byte hashes would lower this to 89 CKB but was not done, and would require redeploying and repeating the testnet evidence.

  • Testnet test conditions. The recorded lifecycles used short deadlines (one epoch), not the 540-epoch default, and the demo was driven with an injected test wallet, not a production wallet such as JoyID or MetaMask.

  • Out of scope: multiple recipients, social or threshold recovery, notifications, production wallet integration, Fiber channel funds, and a security audit.

7. How to verify

  1. Run the Rust tests: cargo test and the composition suite with cargo test --manifest-path tests/Cargo.toml composition.

  2. Run the SDK checks: npm ci, then npx tsc --noEmit, npx tsc -p tsconfig.build.json and npx tsx --test sdk/tests/*.test.ts.

  3. Open the transaction links in docs/testnet-evidence.md and compare each against its description.

  4. Read docs/spec.md and docs/security-model.md against contracts/tranfr-lock/.

8. Next steps

  • A third-party security audit before any mainnet use.

  • Decide whether to shrink the args to 20-byte hashes to lower the minimum capacity.

  • Run the full 540-epoch lifecycle on testnet and test with production wallets.

  • Integration examples for wallets and apps, including node-side runners that could host the lock.

  • A proposal for further funding, covering the audit, wallet integration and mainnet deployment.

Repository:GitHub - salmansarwarr/Tranfr: Tranfr | Programmable Asset Continuity for web3 Non-custodial inactivity recovery for self-custody. If the owner stops checking in, a designated recipient can claim, enforced on-chain. · GitHub
Wallet view: Tranfr — recovery policy (CKB Testnet)

The standalone version: https://tranfr-jet.vercel.app

@xingtianchunyan requesting remaining milestone payment. Thank you.

1 Like