CKB Pulse

All lessons · CCC (TypeScript SDK) · Start here · Glossary

Locate the signing witness slot instead of hardcoding its indexWorkingFrom one fix

From one fix · Check: partly right · Checked 2026-11-19

The signing witness of a lock group sits at the index of the first input that uses that lock, so it differs between transaction shapes (in QuotaCell, 1 for payments and most owner actions, 0 for a deposit). In CCC, take the position from tx.getSignHashInfo(lock, client).position and assert it matches the position you set, instead of hardcoding 1. A wallet or test mock that has no lock available can look for the placeholder witness, but a bare "first non-empty witness" search is only safe when no other input carries a witness.

Why it matters: A hardcoded index such as 1 makes the mock wallet sign the wrong witness when an owner transaction puts the signer's input elsewhere, so that signature fails verification.

Reproduced by a test

A public test runs what this lesson says on @ckb-ccc/core 1.23.1, with no node. Anyone can run it. It covers a part of the lesson: where CCC puts the witness, not the advice for wallets and mocks.

tests/ccc/signing-witness-position.test.mjs

Concepts
Witnesses and signatures
Evidence
From one fix: from one project, checked against its commit
First seen
2026-11-05
Last changed
2026-11-05
Last checked
2026-11-19
Check against the commit
partly right: a true core, with a part that is loose or too wide

Sources (1)

More about CCC (TypeScript SDK)

All 33 in this topic

Do you maintain a project this lesson came from? Confirm or correct it

Cite this lesson
LusoCryptoLabs, "Locate the signing witness slot instead of hardcoding its index", CKB lessons, https://pulse.lusocryptolabs.com/learned/ccc/locate-the-signing-witness-slot-instead-of-hardcoding-its-in, CC BY 4.0, last changed 2026-11-05.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.