/** * Legacy (P2PKH) transaction construction and signing on top of the bitcoinjs-lib v6 API. * * WHY THIS EXISTS, AND WHY IT IS NOT `Psbt` * ----------------------------------------- * This replaces `TransactionBuilder` from the vendored `bitgo-utxo-lib` fork, which was removed * from bitcoinjs-lib in v6 in favour of `Psbt`. `Psbt` cannot be used here: signing a legacy P2PKH * input requires `nonWitnessUtxo`, i.e. the *full previous transaction*. Our unsigned transaction * format carries only `txId`, `vout`, `value`, `address` and `derivationPath`, and it crosses the * air gap as a QR code, so the previous transactions are simply not available to the signer. * (Segwit can use `witnessUtxo` instead because the segwit sighash commits to the input value; * the legacy sighash does not, which is exactly why `nonWitnessUtxo` is mandatory there.) * * So we do what `TransactionBuilder` did internally for P2PKH, explicitly: * * 1. build the transaction with empty input scripts, * 2. compute the legacy sighash per input over the input's P2PKH scriptPubKey, * 3. sign it, DER-encode the signature with the hash type appended, * 4. set the scriptSig to ` `. * * Output is byte-identical to the previous `TransactionBuilder` implementation; the golden-vector * snapshots in `test/v1/golden-vectors.json` pin that and will fail loudly if it ever stops being * true. * * SAFETY NOTES FOR REVIEWERS * -------------------------- * - Only SIGHASH_ALL is produced, matching the previous behaviour. Any other hash type would * change what the signature commits to. * - `txId` is reversed into internal byte order, as the wire format requires. * - Signatures are *not* low-R ground. `TransactionBuilder` did not grind either, and grinding * would change the bytes (and therefore the txid) without changing validity. * - The signer is only ever handed the sighash; no key material is logged or returned. */ /// export interface LegacyInput { /** Transaction id of the output being spent, in display (big-endian) order. */ txId: string; vout: number; } export interface LegacyOutput { recipient: string; /** Value in the smallest unit, as a decimal string. */ value: string; } /** Minimal signer surface — satisfied by a bip32 node. */ export interface LegacySigner { publicKey: Uint8Array; sign(hash: Buffer): Uint8Array; } /** Wraps a raw 32-byte secret key in the minimal signer shape used for legacy signing. */ export declare function ecPairSigner(secretKey: Buffer, network: any): LegacySigner; /** * The subset of the bitcoinjs-lib v6 API this module needs. Both `bitcoinjs-lib` and * `groestlcoinjs-lib` satisfy it; the latter transparently swaps in the groestl hash, which is the * whole reason Groestlcoin needs a different library rather than a different parameter. */ export interface BitcoinJSLib { Transaction: any; payments: any; address: any; script: any; } /** * Builds and signs a legacy P2PKH transaction. * * `signerForInput` is called once per input, in order, and must return the key that owns that * input — the caller is responsible for the derivation. */ export declare function buildAndSignLegacyTransaction(lib: BitcoinJSLib, network: any, inputs: LegacyInput[], outputs: LegacyOutput[], signerForInput: (index: number) => LegacySigner): string;