From a9c296c44ba3a226c00d520d2d8bd210abf2473a Mon Sep 17 00:00:00 2001 From: natsoni Date: Wed, 8 Jul 2026 11:18:17 +0200 Subject: [PATCH] Export isWitnessProgram function and add PSBT_GLOBAL --- frontend/src/app/shared/transaction.utils.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/shared/transaction.utils.ts b/frontend/src/app/shared/transaction.utils.ts index 8bb4fcbc4..1b27476ce 100644 --- a/frontend/src/app/shared/transaction.utils.ts +++ b/frontend/src/app/shared/transaction.utils.ts @@ -713,7 +713,7 @@ function isNonStandardLegacySigops(tx: Transaction, height?: number, network?: s // A witness program is any valid scriptpubkey that consists of a 1-byte push opcode // followed by a data push between 2 and 40 bytes. // https://github.com/bitcoin/bitcoin/blob/2c79abc7ad4850e9e3ba32a04c530155cda7f980/src/script/script.cpp#L224-L240 -function isWitnessProgram(scriptpubkey: string): false | { version: number, program: string } { +export function isWitnessProgram(scriptpubkey: string): false | { version: number, program: string } { if (scriptpubkey.length < 8 || scriptpubkey.length > 84) { return false; } @@ -1456,6 +1456,11 @@ function fromBuffer(buffer: Uint8Array, network: string, inputs?: PsbtKeyValueMa export type PsbtKeyValue = { keyData: Uint8Array; value: Uint8Array; }; export type PsbtKeyValueMap = Map; +export const PSBT_GLOBAL = { + UNSIGNED_TX: 0x00, + GENERIC_SIGNED_MESSAGE: 0x09, +}; + export const PSBT_IN = { NON_WITNESS_UTXO: 0x00, WITNESS_UTXO: 0x01, @@ -1601,9 +1606,10 @@ function decodePsbt(psbtBuffer: Uint8Array): { rawTx: Uint8Array; inputs: PsbtKe * @param rawTx - The unsigned transaction as Uint8Array * @param inputs - Array of input maps containing key-value pairs for each input * @param outputs - Array of output maps containing key-value pairs for each output + * @param globals - Global key-value pairs for the PSBT * @returns PSBT buffer as Uint8Array */ -export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs: PsbtKeyValueMap[]): Uint8Array { +export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs: PsbtKeyValueMap[], globals: PsbtKeyValueMap = new Map()): Uint8Array { const result: number[] = []; // Magic bytes: "psbt" in ASCII @@ -1633,7 +1639,12 @@ export function encodePsbt(rawTx: Uint8Array, inputs: PsbtKeyValueMap[], outputs // GLOBAL MAP // Add unsigned transaction (key type 0x00) - writeKeyValue(0x00, new Uint8Array(), rawTx); + writeKeyValue(PSBT_GLOBAL.UNSIGNED_TX, new Uint8Array(), rawTx); + for (const [keyType, items] of globals) { + for (const record of items) { + writeKeyValue(keyType, record.keyData, record.value); + } + } // End global map result.push(0x00);