- Get the sighash — Compute the signature hash for an input
- Append the signature — Add the signed result to the PCZT
Two Approaches
External Signing
Use
get_sighash + append_signature when:- Using a hardware wallet
- Key is in an HSM
- Signing on a separate system
Convenience Method
Use
sign_transparent_input when:- Key is available in memory
- Testing/development
- Simple use cases
External Signing Flow
Step 1: Get Sighash
- TypeScript
- Go
- Kotlin
Step 2: Sign Externally
Sign the sighash with ECDSA secp256k1. The signature must be DER-encoded with the sighash type byte appended.Step 3: Append Signature
- TypeScript
- Go
- Kotlin
Convenience Method
For simple cases where the private key is available:- TypeScript
- Go
- Kotlin
Signing Multiple Inputs
Each input must be signed individually:Signature Format
The signature appended to the PCZT must be:| Component | Size | Description |
|---|---|---|
| DER signature | 70-72 bytes | Standard DER-encoded ECDSA |
| Sighash type | 1 byte | 0x01 for SIGHASH_ALL |
Example DER Signature
Hardware Wallet Integration
The external signing flow is designed for hardware wallets:Verifying Signatures
After signing, useinspect_pczt to verify:
Common Errors
Invalid signature
Invalid signature
The signature doesn’t validate for the sighash. Check:
- Correct private key for the input
- Proper DER encoding
- Sighash type byte (0x01) appended
Invalid pubkey
Invalid pubkey
The public key doesn’t match the input’s scriptPubkey. Ensure you’re using the correct key for each input.
Invalid input index
Invalid input index
The input index is out of bounds. Check
inputs.length from inspect_pczt.
