Skip to main content
Adds a DER-encoded ECDSA signature to a transparent input in the PCZT.

Signature

  • TypeScript
  • Go
  • Kotlin
function append_signature(
  pczt: WasmPczt,
  input_index: number,
  pubkey: string,
  signature: string
): WasmPczt

Parameters

pczt
Pczt
required
The PCZT to add the signature to
input_index
number
required
Index of the transparent input (0-based)
pubkey
string
required
33-byte compressed public key (hex)
signature
string
required
DER-encoded ECDSA signature with sighash type byte appended (hex)

Returns

Updated PCZT with the signature added.

Signature Format

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