Adds a DER-encoded ECDSA signature to a transparent input in the PCZT.
Signature
function append_signature(
pczt: WasmPczt,
input_index: number,
pubkey: string,
signature: string
): WasmPczt
Parameters
The PCZT to add the signature to
Index of the transparent input (0-based)
33-byte compressed public key (hex)
DER-encoded ECDSA signature with sighash type byte appended (hex)
Returns
Updated PCZT with the signature added.
The signature must be DER-encoded with SIGHASH_ALL (0x01) appended:
[DER signature (70-72 bytes)] + [0x01]
Example
import { secp256k1 } from '@noble/curves/secp256k1';
// Get sighash
const sighash = t2z.get_sighash(pczt, 0);
// Sign
const sig = secp256k1.sign(hexToBytes(sighash), privateKey);
const derSig = sig.toDERRawBytes();
// Append sighash type
const sigWithType = new Uint8Array([...derSig, 0x01]);
// Add to PCZT
pczt = t2z.append_signature(pczt, 0, pubkeyHex, bytesToHex(sigWithType));
See Also