CKB Pulse

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

Re-zero the witness lock before recomputing the sign message with getSignHashInfoPráticoReproduzida

Reproduzida · Verificação: em parte certa · Verificada em 2026-11-19

CCC's Transaction.getSignHashInfo hashes whatever is currently in the witness, so after a signature is filled in it no longer gives the signed message. To verify a signature (for example with ccc.recoverMessageSecp256k1), clone the tx and reset witness 0's lock to the zero placeholder of the same length that was used at signing time.

Porque importa: If you recompute the sign hash on the signed transaction, the hash covers the signature itself, so recovery returns the wrong public key and a valid signature looks invalid.

Padrão

Preferir
verifyTx.setWitnessArgs(0, { lock: ccc.hexFrom(new Uint8Array(WITNESS_LOCK_LEN)) });

Tirado do commit, encurtado.

Um teste mudou no mesmo commit

Está ao lado da correcção. Nós não o corremos.

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.

tests/ccc/rezero-witness-before-verifying.test.mjs

Conceitos
Witnesses and signatures, Testing and devnet
Evidência
Reproduzida: reproduzida por um teste público
Vista pela primeira vez
2026-10-14
Última mudança
2026-10-14
Ú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, "Re-zero the witness lock before recomputing the sign message with getSignHashInfo", CKB lessons, https://pulse.lusocryptolabs.com/learned/ccc/re-zero-the-witness-lock-before-recomputing-the-sign-message, CC BY 4.0, last changed 2026-10-14.

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.