Skip to content

Commit 8ca34c0

Browse files
committed
refactor: simplify addOutput() checks
1 parent 58258a7 commit 8ca34c0

File tree

8 files changed

+45
-109
lines changed

8 files changed

+45
-109
lines changed

src/psbt.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference types="node" />
22
import { Psbt as PsbtBase } from 'bip174';
3-
import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate, TapInternalKey, TapTree } from 'bip174/src/lib/interfaces';
3+
import { KeyValue, PsbtGlobalUpdate, PsbtInput, PsbtInputUpdate, PsbtOutput, PsbtOutputUpdate } from 'bip174/src/lib/interfaces';
44
import { Network } from './networks';
55
import { Transaction } from './transaction';
66
export interface TransactionInput {
@@ -125,7 +125,7 @@ interface PsbtOptsOptional {
125125
}
126126
interface PsbtInputExtended extends PsbtInput, TransactionInput {
127127
}
128-
declare type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript | PsbtOutputExtendedTaproot;
128+
declare type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
129129
interface PsbtOutputExtendedAddress extends PsbtOutput {
130130
address: string;
131131
value: number;
@@ -134,12 +134,6 @@ interface PsbtOutputExtendedScript extends PsbtOutput {
134134
script: Buffer;
135135
value: number;
136136
}
137-
interface PsbtOutputExtendedTaproot extends PsbtOutput {
138-
tapInternalKey: TapInternalKey;
139-
tapTree?: TapTree;
140-
script?: Buffer;
141-
value: number;
142-
}
143137
interface HDSignerBase {
144138
/**
145139
* DER format compressed publicKey buffer

src/psbt.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,11 @@ class Psbt {
226226
arguments.length > 1 ||
227227
!outputData ||
228228
outputData.value === undefined ||
229-
(outputData.address === undefined &&
230-
outputData.script === undefined &&
231-
outputData.tapInternalKey === undefined)
229+
(outputData.address === undefined && outputData.script === undefined)
232230
) {
233231
throw new Error(
234232
`Invalid arguments for Psbt.addOutput. ` +
235-
`Requires single object with at least [script, address or tapInternalKey] and [value]`,
233+
`Requires single object with at least [script or address] and [value]`,
236234
);
237235
}
238236
checkInputsForPartialSig(this.data.inputs, 'addOutput');
@@ -242,20 +240,7 @@ class Psbt {
242240
const script = (0, address_1.toOutputScript)(address, network);
243241
outputData = Object.assign(outputData, { script });
244242
}
245-
if ((0, bip371_1.isTaprootOutput)(outputData)) {
246-
(0, bip371_1.checkTaprootOutputFields)(
247-
outputData,
248-
outputData,
249-
'addOutput',
250-
);
251-
const scriptAndAddress = (0, bip371_1.getNewTaprootScriptAndAddress)(
252-
outputData,
253-
outputData,
254-
this.opts.network,
255-
);
256-
if (scriptAndAddress)
257-
outputData = Object.assign(outputData, scriptAndAddress);
258-
}
243+
(0, bip371_1.checkTaprootOutputFields)(outputData, outputData, 'addOutput');
259244
const c = this.__CACHE;
260245
this.data.addOutput(outputData);
261246
c.__FEE = undefined;
@@ -899,6 +884,8 @@ class Psbt {
899884
return this;
900885
}
901886
updateOutput(outputIndex, updateData) {
887+
// const outputData = this.data.outputs[outputIndex];
888+
// checkTaprootOutputFields(outputData, updateData, 'updateOutput');
902889
this.data.updateOutput(outputIndex, updateData);
903890
return this;
904891
}

src/psbt/bip371.d.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference types="node" />
22
import { Taptree } from '../types';
33
import { PsbtInput, PsbtOutput, TapLeaf } from 'bip174/src/lib/interfaces';
4-
import { Network } from '../networks';
54
export declare const toXOnly: (pubKey: Buffer) => Buffer;
65
/**
76
* Default tapscript finalizer. It searches for the `tapLeafHashToFinalize` if provided.
@@ -20,10 +19,6 @@ export declare function isTaprootInput(input: PsbtInput): boolean;
2019
export declare function isTaprootOutput(output: PsbtOutput, script?: Buffer): boolean;
2120
export declare function checkTaprootInputFields(inputData: PsbtInput, newInputData: PsbtInput, action: string): void;
2221
export declare function checkTaprootOutputFields(outputData: PsbtOutput, newOutputData: PsbtOutput, action: string): void;
23-
export declare function getNewTaprootScriptAndAddress(outputData: PsbtOutput, newOutputData: PsbtOutput, network?: Network): {
24-
script: Buffer;
25-
address: string;
26-
} | undefined;
2722
export declare function tweakInternalPubKey(inputIndex: number, input: PsbtInput): Buffer;
2823
/**
2924
* Convert a binary tree to a BIP371 type list. Each element of the list is (according to BIP371):

src/psbt/bip371.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
Object.defineProperty(exports, '__esModule', { value: true });
3-
exports.tapTreeFromList = exports.tapTreeToList = exports.tweakInternalPubKey = exports.getNewTaprootScriptAndAddress = exports.checkTaprootOutputFields = exports.checkTaprootInputFields = exports.isTaprootOutput = exports.isTaprootInput = exports.serializeTaprootSignature = exports.tapScriptFinalizer = exports.toXOnly = void 0;
3+
exports.tapTreeFromList = exports.tapTreeToList = exports.tweakInternalPubKey = exports.checkTaprootOutputFields = exports.checkTaprootInputFields = exports.isTaprootOutput = exports.isTaprootInput = exports.serializeTaprootSignature = exports.tapScriptFinalizer = exports.toXOnly = void 0;
44
const types_1 = require('../types');
55
const psbtutils_1 = require('./psbtutils');
66
const taprootutils_1 = require('../payments/taprootutils');
@@ -72,34 +72,28 @@ function checkTaprootInputFields(inputData, newInputData, action) {
7272
exports.checkTaprootInputFields = checkTaprootInputFields;
7373
function checkTaprootOutputFields(outputData, newOutputData, action) {
7474
checkMixedTaprootAndNonTaprootOutputFields(outputData, newOutputData, action);
75+
checkTaprootScriptPubkey(outputData, newOutputData);
7576
}
7677
exports.checkTaprootOutputFields = checkTaprootOutputFields;
77-
function getNewTaprootScriptAndAddress(outputData, newOutputData, network) {
78+
function checkTaprootScriptPubkey(outputData, newOutputData) {
7879
if (!newOutputData.tapTree && !newOutputData.tapInternalKey) return;
7980
const tapInternalKey =
8081
newOutputData.tapInternalKey || outputData.tapInternalKey;
8182
const tapTree = newOutputData.tapTree || outputData.tapTree;
8283
if (tapInternalKey) {
83-
const { script, address } = getTaprootScriptAndAddress(
84-
tapInternalKey,
85-
tapTree,
86-
network,
87-
);
88-
const { script: newScript } = newOutputData;
89-
if (newScript && !newScript.equals(script))
84+
const { script: scriptPubkey } = outputData;
85+
const script = getTaprootScripPubkey(tapInternalKey, tapTree);
86+
if (scriptPubkey && !scriptPubkey.equals(script))
9087
throw new Error('Error adding output. Script or address missmatch.');
91-
return { script, address };
9288
}
9389
}
94-
exports.getNewTaprootScriptAndAddress = getNewTaprootScriptAndAddress;
95-
function getTaprootScriptAndAddress(tapInternalKey, tapTree, network) {
90+
function getTaprootScripPubkey(tapInternalKey, tapTree) {
9691
const scriptTree = tapTree && tapTreeFromList(tapTree.leaves);
97-
const { output, address } = (0, payments_1.p2tr)({
92+
const { output } = (0, payments_1.p2tr)({
9893
internalPubkey: tapInternalKey,
9994
scriptTree,
100-
network,
10195
});
102-
return { script: output, address: address };
96+
return output;
10397
}
10498
function tweakInternalPubKey(inputIndex, input) {
10599
const tapInternalKey = input.tapInternalKey;

test/fixtures/psbt.json

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@
506506
"outputData": {
507507
"value": 1000
508508
},
509-
"exception": "Invalid arguments for Psbt\\.addOutput. Requires single object with at least \\[script, address or tapInternalKey\\] and \\[value\\]"
509+
"exception": "Invalid arguments for Psbt\\.addOutput. Requires single object with at least \\[script or address\\] and \\[value\\]"
510510
},
511511
{
512512
"description": "Adds output normally",
@@ -516,20 +516,12 @@
516516
}
517517
},
518518
{
519-
"description": "Adds taproot output with internal key only (address derived)",
520-
"isTaproot": true,
521-
"psbt": "cHNidP8BAFwCAAAAAo6LlrlIROHUfunj2OPeOpJlw/sG4cG99LrNl88u7rcrAAAAAAD/////LR6UXz/GymI8bcsv2b+NIzWKT/d9cEUPwWHREjtSapcAAAAAAP////8AAAAAAAABASugaAYAAAAAACJRIAkRWDXSsncord4FtaUxPSWLua73cQbIN0uq2qyWztP3ARcgAqgH8rOX0SzoemaM+YlCy9DYeU1w9CrcR7Vm5/PPlxYAAQDAAgAAAAG67fXBoOPSqNrW6dbIkadKg+T6+tnU2pqoCSiOxyVdhQAAAABrSDBFAiEA9sK/dshQbR7W58jOzsH069Ms5C7Q4b0CDiDB//7BccECICDpjneIIw2Wgr9fq7VvqZfOgghSlXjiMaVr1Qqkb4qUASEC/r+CrU8sH0Jy0FIrGL6XQ8p0tDVOfnVpl6M6NKkwqZT/////AaBoBgAAAAAAGXapFLuFzFEeVsEgi+khfH7+Tc7+AvKBiKwAAAAAAAA=",
522-
"outputData": {
523-
"tapInternalKey": "Buffer.from('1a954a44837e47815f7285eae2dc3716f98eafb41a1155e999bfa66853b2cc47', 'hex')",
524-
"value": 410000
525-
},
526-
"result": "cHNidP8BAIcCAAAAAo6LlrlIROHUfunj2OPeOpJlw/sG4cG99LrNl88u7rcrAAAAAAD/////LR6UXz/GymI8bcsv2b+NIzWKT/d9cEUPwWHREjtSapcAAAAAAP////8BkEEGAAAAAAAiUSCTYMKBNf5sZR1VO8dJdu2z5lO0vHqjXMjmOYotibmHLwAAAAAAAQEroGgGAAAAAAAiUSAJEVg10rJ3KK3eBbWlMT0li7mu93EGyDdLqtqsls7T9wEXIAKoB/Kzl9Es6HpmjPmJQsvQ2HlNcPQq3Ee1Zufzz5cWAAEAwAIAAAABuu31waDj0qja1unWyJGnSoPk+vrZ1NqaqAkojsclXYUAAAAAa0gwRQIhAPbCv3bIUG0e1ufIzs7B9OvTLOQu0OG9Ag4gwf/+wXHBAiAg6Y53iCMNloK/X6u1b6mXzoIIUpV44jGla9UKpG+KlAEhAv6/gq1PLB9CctBSKxi+l0PKdLQ1Tn51aZejOjSpMKmU/////wGgaAYAAAAAABl2qRS7hcxRHlbBIIvpIXx+/k3O/gLygYisAAAAAAABBSAalUpEg35HgV9yheri3DcW+Y6vtBoRVemZv6ZoU7LMRwA="
527-
},
528-
{
529-
"description": "Adds taproot output with internal key and tap tree (address derived)",
519+
"description": "Adds taproot output with internal key and tap tree",
530520
"isTaproot": true,
531521
"psbt": "cHNidP8BADMCAAAAAcbgSGx76du9GXsr4c6Yk7DFglfHi7M2jdCNUXwc+Q+EAAAAAAD/////AAAAAAAAAQEroGgGAAAAAAAiUSClLxmVQ6aZXLEwkYA/WGZuIE91BHT7xP7DIEAvz/NITaIVwd2NnolThxX+QCpgFksj8u93bzuZy6olaHxJNHaArwK1tCTeoJ+EC5MqADc83NvSVlC4w6z+VKn0pkGihnIbjSbax5V2a72h6uqkXlv6CpUP3V9MSq2lsfMILtyWibn9Cu4oo7gsSuy+vTeBJ9yI3Rnh6pPtunont1ThyIHTCIdKesRIlUS3uEDQRVmeyUFa5xzLCQwsRlwFyfoF9Bx6BtUjIFX368Cp2d6uXSbyrn23vC4KMjRRlEssuTTh7ThM6bXQrMAAAA==",
532522
"outputData": {
523+
"address": "bc1px4ssshedlz4jc56ses3lftz462a06jwy8my4pwpx6twx30vvv6nsgwcpu3",
524+
"value": 410000,
533525
"tapInternalKey": "Buffer.from('f6d4ce132444de7f0e3a1d2be9b38ceec798cf9a76eeeac585869445830eb167', 'hex')",
534526
"tapTree": {
535527
"leaves": [
@@ -569,8 +561,7 @@
569561
"script": "Buffer.from('2055f7ebc0a9d9deae5d26f2ae7db7bc2e0a323451944b2cb934e1ed384ce9b5d0ac', 'hex')"
570562
}
571563
]
572-
},
573-
"value": 410000
564+
}
574565
},
575566
"result": "cHNidP8BAF4CAAAAAcbgSGx76du9GXsr4c6Yk7DFglfHi7M2jdCNUXwc+Q+EAAAAAAD/////AZBBBgAAAAAAIlEgNWEIXy34qyxTUMwj9KxV0rr9ScQ+yVC4JtLcaL2MZqcAAAAAAAEBK6BoBgAAAAAAIlEgpS8ZlUOmmVyxMJGAP1hmbiBPdQR0+8T+wyBAL8/zSE2iFcHdjZ6JU4cV/kAqYBZLI/Lvd287mcuqJWh8STR2gK8CtbQk3qCfhAuTKgA3PNzb0lZQuMOs/lSp9KZBooZyG40m2seVdmu9oerqpF5b+gqVD91fTEqtpbHzCC7clom5/QruKKO4LErsvr03gSfciN0Z4eqT7bp6J7dU4ciB0wiHSnrESJVEt7hA0EVZnslBWuccywkMLEZcBcn6BfQcegbVIyBV9+vAqdnerl0m8q59t7wuCjI0UZRLLLk04e04TOm10KzAAAEFIPbUzhMkRN5/DjodK+mzjO7HmM+adu7qxYWGlEWDDrFnAQb9AwECwCIgUJKbdMGgSVS3i0tgNel6XgeKWg8o7JbVR7/ums6AOsCsA8AiIFCSm3TBoElUt4tLYDXpel4HiloPKOyW1Ue/7prOgDrBrAPAIiAiWLHDFgvghkpUGFTuyRZKVy8JT3ViYoKBqAc7uJFzp6wCwCIgUJKbdMGgSVS3i0tgNel6XgeKWg8o7JbVR7/ums6AOsKsA8AiIFCSm3TBoElUt4tLYDXpel4HiloPKOyW1Ue/7prOgDrDrATAIiBQkpt0waBJVLeLS2A16XpeB4paDyjsltVHv+6azoA6xKwEwCIgVffrwKnZ3q5dJvKufbe8LgoyNFGUSyy5NOHtOEzptdCsAA=="
576567
},
@@ -601,9 +592,10 @@
601592
"isTaproot": true,
602593
"psbt": "cHNidP8BAFwCAAAAAk9Ve2845C8v//JR71uKzf70FjeNfx7SvB4l3A+Q44UKAAAAAAD/////FIp10hu+RPgTSFGPmjwb01Tf/a5UkcPFUpOw/X6UEPYAAAAAAP////8AAAAAAAABASugaAYAAAAAACJRINqadqaDhePTT29qdKQScUmyJxEeDw12HLjkMYMVSlnkARcgDN4bJzix3HdE8+FUM6UgA1lEKpgpIImVUePmAGYh7yYAAQDAAgAAAAFbIoaAJqDd/f4mZppgYV4UR9bgU8lT9pTH4/aDJdFUWgAAAABrSDBFAiEA6JS0xMdSQhG+9gAPSxGs6HazyauyNUBMwrmF386IAxwCIGiyH9QHCzKOBTtg+VsISF4nUi9NfAtJAtC02J03+I07ASEDu1tkEI8W1bd6qrPZ3uLaHvE90BDUvRCwvTTzPYPXzwf/////AaBoBgAAAAAAGXapFL5QEf51k4TA7Mp5d18IM2ddq79oiKwAAAAAAAA=",
603594
"outputData": {
595+
"address": "bc1px4ssshedlz4jc56ses3lftz462a06jwy8my4pwpx6twx30vvv6nsgwcpu3",
596+
"value": 410000,
604597
"tapInternalKey": "Buffer.from('884d969439deced21d1ab71ecd9ef9a6a8795215588ce7eff4ad5efc903e40ec', 'hex')",
605-
"redeemScript": "Buffer.from('5221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae', 'hex')",
606-
"value": 410000
598+
"redeemScript": "Buffer.from('5221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae', 'hex')"
607599
},
608600
"exception": "Invalid arguments for Psbt.addOutput. Cannot use both taproot and non-taproot fields."
609601
}

test/integration/taproot.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
9393

9494
psbt.addOutput({
9595
value: sendAmount,
96+
address: sendAddress!,
9697
tapInternalKey: sendPubKey,
9798
});
9899

@@ -271,6 +272,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
271272

272273
psbt.addOutput({
273274
value: sendAmount,
275+
address: sendAddress!,
274276
tapInternalKey: sendPubKey,
275277
tapTree: { leaves: tapTreeToList(scriptTree) },
276278
});

ts_src/psbt.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import {
1313
TransactionFromBuffer,
1414
TapKeySig,
1515
TapScriptSig,
16-
TapInternalKey,
17-
TapTree,
1816
} from 'bip174/src/lib/interfaces';
1917
import { checkForInput, checkForOutput } from 'bip174/src/lib/utils';
2018
import { fromOutputScript, toOutputScript } from './address';
@@ -29,11 +27,9 @@ import {
2927
tapScriptFinalizer,
3028
serializeTaprootSignature,
3129
isTaprootInput,
32-
isTaprootOutput,
3330
checkTaprootInputFields,
3431
checkTaprootOutputFields,
3532
tweakInternalPubKey,
36-
getNewTaprootScriptAndAddress,
3733
} from './psbt/bip371';
3834
import {
3935
witnessStackToScriptWitness,
@@ -316,12 +312,11 @@ export class Psbt {
316312
!outputData ||
317313
outputData.value === undefined ||
318314
((outputData as any).address === undefined &&
319-
(outputData as any).script === undefined &&
320-
(outputData as any).tapInternalKey === undefined)
315+
(outputData as any).script === undefined)
321316
) {
322317
throw new Error(
323318
`Invalid arguments for Psbt.addOutput. ` +
324-
`Requires single object with at least [script, address or tapInternalKey] and [value]`,
319+
`Requires single object with at least [script or address] and [value]`,
325320
);
326321
}
327322
checkInputsForPartialSig(this.data.inputs, 'addOutput');
@@ -331,17 +326,7 @@ export class Psbt {
331326
const script = toOutputScript(address, network);
332327
outputData = Object.assign(outputData, { script });
333328
}
334-
335-
if (isTaprootOutput(outputData)) {
336-
checkTaprootOutputFields(outputData, outputData, 'addOutput');
337-
const scriptAndAddress = getNewTaprootScriptAndAddress(
338-
outputData,
339-
outputData,
340-
this.opts.network,
341-
);
342-
if (scriptAndAddress)
343-
outputData = Object.assign(outputData, scriptAndAddress);
344-
}
329+
checkTaprootOutputFields(outputData, outputData, 'addOutput');
345330

346331
const c = this.__CACHE;
347332
this.data.addOutput(outputData);
@@ -1117,6 +1102,9 @@ export class Psbt {
11171102
}
11181103

11191104
updateOutput(outputIndex: number, updateData: PsbtOutputUpdate): this {
1105+
// const outputData = this.data.outputs[outputIndex];
1106+
// checkTaprootOutputFields(outputData, updateData, 'updateOutput');
1107+
11201108
this.data.updateOutput(outputIndex, updateData);
11211109
return this;
11221110
}
@@ -1165,10 +1153,7 @@ interface PsbtOpts {
11651153

11661154
interface PsbtInputExtended extends PsbtInput, TransactionInput {}
11671155

1168-
type PsbtOutputExtended =
1169-
| PsbtOutputExtendedAddress
1170-
| PsbtOutputExtendedScript
1171-
| PsbtOutputExtendedTaproot;
1156+
type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
11721157

11731158
interface PsbtOutputExtendedAddress extends PsbtOutput {
11741159
address: string;
@@ -1180,13 +1165,6 @@ interface PsbtOutputExtendedScript extends PsbtOutput {
11801165
value: number;
11811166
}
11821167

1183-
interface PsbtOutputExtendedTaproot extends PsbtOutput {
1184-
tapInternalKey: TapInternalKey;
1185-
tapTree?: TapTree;
1186-
script?: Buffer;
1187-
value: number;
1188-
}
1189-
11901168
interface HDSignerBase {
11911169
/**
11921170
* DER format compressed publicKey buffer

ts_src/psbt/bip371.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
MAX_TAPTREE_DEPTH,
2323
} from '../payments/taprootutils';
2424
import { p2tr } from '../payments';
25-
import { Network } from '../networks';
2625

2726
export const toXOnly = (pubKey: Buffer) =>
2827
pubKey.length === 32 ? pubKey : pubKey.slice(1, 33);
@@ -109,42 +108,37 @@ export function checkTaprootOutputFields(
109108
action: string,
110109
): void {
111110
checkMixedTaprootAndNonTaprootOutputFields(outputData, newOutputData, action);
111+
checkTaprootScriptPubkey(outputData, newOutputData);
112112
}
113113

114-
export function getNewTaprootScriptAndAddress(
114+
function checkTaprootScriptPubkey(
115115
outputData: PsbtOutput,
116116
newOutputData: PsbtOutput,
117-
network?: Network,
118-
): { script: Buffer; address: string } | undefined {
117+
): void {
119118
if (!newOutputData.tapTree && !newOutputData.tapInternalKey) return;
119+
120120
const tapInternalKey =
121121
newOutputData.tapInternalKey || outputData.tapInternalKey;
122122
const tapTree = newOutputData.tapTree || outputData.tapTree;
123+
123124
if (tapInternalKey) {
124-
const { script, address } = getTaprootScriptAndAddress(
125-
tapInternalKey,
126-
tapTree,
127-
network,
128-
);
129-
const { script: newScript } = newOutputData as any;
130-
if (newScript && !newScript.equals(script))
125+
const { script: scriptPubkey } = outputData as any;
126+
const script = getTaprootScripPubkey(tapInternalKey, tapTree);
127+
if (scriptPubkey && !scriptPubkey.equals(script))
131128
throw new Error('Error adding output. Script or address missmatch.');
132-
return { script, address };
133129
}
134130
}
135131

136-
function getTaprootScriptAndAddress(
132+
function getTaprootScripPubkey(
137133
tapInternalKey: TapInternalKey,
138134
tapTree?: TapTree,
139-
network?: Network,
140-
): { script: Buffer; address: string } {
135+
): Buffer {
141136
const scriptTree = tapTree && tapTreeFromList(tapTree.leaves);
142-
const { output, address } = p2tr({
137+
const { output } = p2tr({
143138
internalPubkey: tapInternalKey,
144139
scriptTree,
145-
network,
146140
});
147-
return { script: output!, address: address! };
141+
return output!;
148142
}
149143

150144
export function tweakInternalPubKey(

0 commit comments

Comments
 (0)