CKB Pulse

Todas as lições · CCC (TypeScript SDK) · Começa aqui · Glossário

Locate the signing witness slot instead of hardcoding its indexPráticoDe uma correção

De uma correção · Verificação: em parte certa · Verificada em 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.

Porque importa: 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.

Reproduzida por um teste

Um teste público corre o que esta lição diz em @ckb-ccc/core 1.23.1, sem nó. Qualquer pessoa o pode correr. Cobre uma parte da lição: where CCC puts the witness, not the advice for wallets and mocks.

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

Conceitos
Witnesses and signatures
Evidência
De uma correção: de um projeto, verificada contra o commit
Vista pela primeira vez
2026-11-05
Última mudança
2026-11-05
Última verificação
2026-11-19
Verificação contra o commit
em parte certa: um núcleo verdadeiro, com uma parte solta ou demasiado larga

Fontes (1)

Mais sobre CCC (TypeScript SDK)

Ver as 33 deste tema

Manténs um projeto de onde esta lição veio? Confirma ou corrige

Citar esta lição
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.

Tiradas de commits públicos e verificadas contra o commit de onde cada uma veio e o código de hoje do projeto. Lê a fonte antes de confiar numa. Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. Queres que uma lição seja mudada ou retirada? Abre um issue.