LiçõesO que a CKB aprendeu
Começa aqui · Glossário · Testa-te · Feed
As lições estão escritas em inglês, por isso pesquise em inglês.
“Witnesses and signatures” ✕
48 lições encontradas. Todas as lições
AnteriorPágina 3 de 4Seguinte
When a lock script commits to output 0's exact bytes (capacity included), the capacity must be decided before proving and must equal what the transaction ships. In CCC, tx.completeFeeBy(signer) pays the fee by pulling in the signer's cells and adding a change output, so output 0 keeps its capacity and the fee is then paid from extra inputs, which breaks the binding if the proof assumed inputCapacity minus fee. Instead compute the fee from tx.toBytes().length with the witness already at its final length, build output 0 at inputCapacity minus that fee, and check before sending that the fee recomputed on the real transaction equals the planned one.
#Transaction building and fees #Witnesses and signatures #Capacity and cell size · Fontes (1) · 2026-11-04
A transaction witness in ckb_types is a molecule packed::Bytes, so as_slice() returns the 4 byte length header followed by the content, while raw_data() returns only the content (here a serialized WitnessArgs). A check that compares a witness to the secp256k1 sighash placeholder WitnessArgs (lock of 65 zero bytes) must use witness.raw_data() (or unpack()), otherwise it is silently never true. Fiber's funding witness merge never recognized placeholders until it switched to raw_data(), so a peer's placeholder could be kept in place of a real signature.
#Data encoding (molecule, hex, bigints) #Witnesses and signatures · Fontes (2) · 2026-10-29
When one key controls several lock groups in a CCC transaction, call transaction.prepareSighashAllWitness(script, len, client) for each group with the final witness lock length of that lock, then getSignHashInfo and sign that group's own digest. In KeyWay's case the length is 65 bytes for secp256k1 and 85 bytes for an Omnilock owner witness holding one 65-byte signature; write the bare signature for secp256k1 and wrap it in the OmniLockWitnessLock molecule for Omnilock. A custom lock with its own witness layout needs its own length the same way.
#Witnesses and signatures #Transaction building and fees · Fontes (2) · 2026-10-23
For an Omnilock cell spent in owner (secp256k1) mode, the WitnessArgs.lock is an 85 byte OmniLockWitnessLock (a 20 byte molecule header 0x5500000010000000550000005500000041000000 plus the 65 byte signature), so the sighash digest must be computed with an 85 byte zeroed placeholder (e.g. CCC prepareSighashAllWitness(lock, 85, client)). A digest taken over the usual 65 byte secp256k1 placeholder does not verify, which the test confirms against a real testnet spend.
#Witnesses and signatures #Data encoding (molecule, hex, bigints) · Fontes (2) · 2026-10-23
To drive CCC's real EIP-6963 connector and EVM/Omnilock signing in headless Playwright, inject a minimal EIP-1193 provider with page.addInitScript passed as a string, because transpiled function sources carry helpers such as __name that the page lacks. The provider answers eth_requestAccounts, eth_accounts and personal_sign, stubs on and removeListener, and announces itself on eip6963:announceProvider, also whenever eip6963:requestProvider fires. Signing runs in Node through page.exposeFunction so the key never enters the page, and personal_sign must return r‖s‖v with v = 27 + recovery id; noble-curves 2.x sign with format "recovered" yields recovery‖r‖s, so reorder it with hexFrom(bytesConcat(recovered.slice(1, 65), [recovered[0] + 27])) and check it against ccc.verifyMessageEvmPersonal.
#Testing and devnet #Witnesses and signatures · Fontes (1) · 2026-10-22
When the funding wallet uses the JoyID lock, its WitnessArgs outputType may carry a subkey unlock proof, so do not put your own type script data in that witness's outputType. Place the type script action in another witness index and align the related output index with it. Size the fee estimate's signature placeholder for JoyID's larger witness (openswap uses 1000 bytes) instead of the 65 byte secp256k1 size.
#Witnesses and signatures #Transaction building and fees · Fontes (1) · 2026-10-22
When a custom lock's spend rebuilds an output from an input cell that may carry a type script (a UDT held in custody, say), copy cell.cellOutput.type and cell.outputData into the output and change only the lock; writing outputsData "0x" with no type burns or strands the token. Add the type script's cell deps to the transaction before signing, because the signature covers the cell deps and callers cannot append them afterwards, and refuse to build the spend if a typed cell comes without them. If the lock also constrains who gets the capacity (as Tranfr's recipient claim does today), follow that rule instead of a plain copy.
#Transaction building and fees #Cell deps and script lookup #Witnesses and signatures · Fontes (1) · 2026-10-21
When a test signer for the secp256k1 sighash_all lock fills the first witness of a script group, it should parse the existing WitnessArgs (for example one with data in output_type) and replace only the lock field: zeroed to 65 bytes while hashing, then set to the signature. Building a fresh WitnessArgs drops output_type or input_type data that a type script reads, and sighash_all hashes the whole first witness with only the lock zeroed, so those fields must already be in place when hashing.
#Witnesses and signatures #Testing and devnet · Fontes (1) · 2026-10-20
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.
#Witnesses and signatures #Testing and devnet · Fontes (1) · 2026-10-14
To expose a remote secp256k1 key as a CCC signer, extend ccc.SignerCkbPublicKey(client, publicKey) and override signOnlyTransaction and signMessageRaw to call the backend. The address and lock come from the public key, and signMessageRaw must sign in the "Nervos Message:" format so signMessage and verifyMessage keep working. SignerCkbPublicKey also reports anyone-can-pay addresses of the key, whose cells a backend that only signs the secp256k1 lock cannot spend, so override getAddressObjs to return only the lock you can sign (ckb-keyway had to do this later).
#Witnesses and signatures · Fontes (1) · 2026-10-12
With CCC, a simple CKB transfer is built as ccc.Transaction.from({ outputs: [{ lock, capacity }] }), then transaction.completeInputsByCapacity(signer) and transaction.completeFeeBy(signer) are called before signer.sendTransaction(transaction). The recipient lock comes from ccc.Address.fromString(address, signer.client), and its .script is used as the output lock.
#Transaction building and fees #Witnesses and signatures · Fontes (1) · 2026-10-12
A JoyID passkey from a second device is a sub key, so deriving the JoyID lock from the signer's public key does not find the account. Given the account's address, call JoyID's CoTA aggregator method generate_subkey_unlock_smt with alg_index 1 (the passkey algorithm), pubkey_hash set to the first 20 bytes of ckbHash(pubkey) for the same pubkey bytes JoyID signs with, and lock_script set to the serialized lock; a non-empty result.unlock_entry means the key belongs to that account. The aggregator is trusted and its SMT proof is not checked against the chain, and the positive case was not run against a real sub key here.
#Witnesses and signatures #Login and authorization · Fontes (1) · 2026-10-12
AnteriorPágina 3 de 4Seguinte
Texto sob CC BY 4.0: dá crédito à LusoCryptoLabs, CKB lessons, com uma ligação para a lição. JSON · Queres que uma lição seja mudada ou retirada? Abre um issue.