utxo-lib 1.0.9 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. package/README.md +19 -16
  2. package/dist/src/address.d.ts.map +1 -1
  3. package/dist/src/address.js +11 -1
  4. package/dist/src/addressFormat.d.ts +1 -1
  5. package/dist/src/addressFormat.d.ts.map +1 -1
  6. package/dist/src/addressFormat.js +1 -1
  7. package/dist/src/bitgo/Musig2.d.ts +115 -17
  8. package/dist/src/bitgo/Musig2.d.ts.map +1 -1
  9. package/dist/src/bitgo/Musig2.js +283 -100
  10. package/dist/src/bitgo/PsbtUtil.d.ts +59 -0
  11. package/dist/src/bitgo/PsbtUtil.d.ts.map +1 -0
  12. package/dist/src/bitgo/PsbtUtil.js +92 -0
  13. package/dist/src/bitgo/UtxoPsbt.d.ts +180 -47
  14. package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -1
  15. package/dist/src/bitgo/UtxoPsbt.js +673 -113
  16. package/dist/src/bitgo/UtxoTransaction.js +2 -2
  17. package/dist/src/bitgo/bitcoincash/address.js +2 -2
  18. package/dist/src/bitgo/index.d.ts +11 -0
  19. package/dist/src/bitgo/index.d.ts.map +1 -1
  20. package/dist/src/bitgo/index.js +6 -2
  21. package/dist/src/bitgo/legacysafe/index.d.ts +15 -0
  22. package/dist/src/bitgo/legacysafe/index.d.ts.map +1 -0
  23. package/dist/src/bitgo/legacysafe/index.js +61 -0
  24. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts +10 -0
  25. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts.map +1 -0
  26. package/dist/src/bitgo/litecoin/LitecoinPsbt.js +17 -0
  27. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts +16 -0
  28. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts.map +1 -0
  29. package/dist/src/bitgo/litecoin/LitecoinTransaction.js +46 -0
  30. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts +10 -0
  31. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts.map +1 -0
  32. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.js +15 -0
  33. package/dist/src/bitgo/litecoin/index.d.ts +4 -0
  34. package/dist/src/bitgo/litecoin/index.d.ts.map +1 -0
  35. package/dist/src/bitgo/litecoin/index.js +16 -0
  36. package/dist/src/bitgo/outputScripts.d.ts +3 -1
  37. package/dist/src/bitgo/outputScripts.d.ts.map +1 -1
  38. package/dist/src/bitgo/outputScripts.js +20 -12
  39. package/dist/src/bitgo/parseInput.d.ts +49 -20
  40. package/dist/src/bitgo/parseInput.d.ts.map +1 -1
  41. package/dist/src/bitgo/parseInput.js +110 -26
  42. package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -1
  43. package/dist/src/bitgo/psbt/fromHalfSigned.js +9 -6
  44. package/dist/src/bitgo/psbt/scriptTypes.js +3 -3
  45. package/dist/src/bitgo/signature.d.ts +3 -3
  46. package/dist/src/bitgo/signature.d.ts.map +1 -1
  47. package/dist/src/bitgo/signature.js +48 -16
  48. package/dist/src/bitgo/transaction.d.ts +18 -3
  49. package/dist/src/bitgo/transaction.d.ts.map +1 -1
  50. package/dist/src/bitgo/transaction.js +28 -15
  51. package/dist/src/bitgo/types.d.ts +2 -0
  52. package/dist/src/bitgo/types.d.ts.map +1 -1
  53. package/dist/src/bitgo/types.js +1 -1
  54. package/dist/src/bitgo/wallet/Psbt.d.ts +104 -12
  55. package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -1
  56. package/dist/src/bitgo/wallet/Psbt.js +288 -70
  57. package/dist/src/bitgo/wallet/Unspent.d.ts +28 -0
  58. package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -1
  59. package/dist/src/bitgo/wallet/Unspent.js +173 -68
  60. package/dist/src/bitgo/wallet/WalletOutput.d.ts +17 -1
  61. package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -1
  62. package/dist/src/bitgo/wallet/WalletOutput.js +64 -23
  63. package/dist/src/bitgo/wallet/chains.d.ts +2 -2
  64. package/dist/src/bitgo/wallet/chains.d.ts.map +1 -1
  65. package/dist/src/bitgo/wallet/chains.js +1 -1
  66. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +0 -1
  67. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -1
  68. package/dist/src/bitgo/zcash/ZcashPsbt.js +8 -15
  69. package/dist/src/bitgo/zcash/ZcashTransaction.js +2 -2
  70. package/dist/src/musig.d.ts +0 -1
  71. package/dist/src/musig.d.ts.map +1 -1
  72. package/dist/src/musig.js +15 -29
  73. package/dist/src/networks.d.ts +1 -2
  74. package/dist/src/networks.d.ts.map +1 -1
  75. package/dist/src/networks.js +22 -29
  76. package/dist/src/noble_ecc.d.ts +1 -1
  77. package/dist/src/noble_ecc.d.ts.map +1 -1
  78. package/dist/src/noble_ecc.js +9 -5
  79. package/dist/src/payments/p2tr.d.ts.map +1 -1
  80. package/dist/src/payments/p2tr.js +25 -15
  81. package/dist/src/payments/p2tr_ns.js +3 -2
  82. package/dist/src/taproot.d.ts +16 -0
  83. package/dist/src/taproot.d.ts.map +1 -1
  84. package/dist/src/taproot.js +46 -3
  85. package/dist/src/testutil/index.d.ts +2 -0
  86. package/dist/src/testutil/index.d.ts.map +1 -1
  87. package/dist/src/testutil/index.js +3 -1
  88. package/dist/src/testutil/keys.d.ts +3 -0
  89. package/dist/src/testutil/keys.d.ts.map +1 -1
  90. package/dist/src/testutil/keys.js +17 -2
  91. package/dist/src/testutil/mock.d.ts +1 -1
  92. package/dist/src/testutil/mock.d.ts.map +1 -1
  93. package/dist/src/testutil/mock.js +12 -4
  94. package/dist/src/testutil/psbt.d.ts +89 -0
  95. package/dist/src/testutil/psbt.d.ts.map +1 -0
  96. package/dist/src/testutil/psbt.js +150 -0
  97. package/dist/src/testutil/transaction.d.ts +70 -0
  98. package/dist/src/testutil/transaction.d.ts.map +1 -0
  99. package/dist/src/testutil/transaction.js +107 -0
  100. package/dist/src/transaction_builder.js +2 -2
  101. package/package.json +7 -6
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parsePsbtInput = exports.signWalletPsbt = exports.toWalletPsbt = void 0;
3
+ exports.deleteWitnessUtxoForNonSegwitInputs = exports.clonePsbtWithoutNonWitnessUtxo = exports.extractP2msOnlyHalfSignedTx = exports.getSignatureValidationArrayPsbt = exports.addXpubsToPsbt = exports.isTransactionWithKeyPathSpendInput = exports.isTxInputArray = exports.isPsbtInputArray = exports.getStrictSignatureCounts = exports.getStrictSignatureCount = exports.parsePsbtInput = exports.getPsbtInputScriptType = exports.signWalletPsbt = exports.toWalletPsbt = void 0;
4
+ const assert = require("assert");
5
+ const utils_1 = require("bip174/src/lib/utils");
6
+ const bs58check = require("bs58check");
7
+ const UtxoPsbt_1 = require("../UtxoPsbt");
8
+ const UtxoTransaction_1 = require("../UtxoTransaction");
4
9
  const outputScripts_1 = require("../outputScripts");
10
+ const WalletKeys_1 = require("./WalletKeys");
5
11
  const Unspent_1 = require("../Unspent");
6
12
  const transaction_1 = require("../transaction");
7
13
  const Unspent_2 = require("./Unspent");
8
- const utils_1 = require("bip174/src/lib/utils");
9
14
  const parseInput_1 = require("../parseInput");
15
+ const Musig2_1 = require("../Musig2");
16
+ const types_1 = require("../types");
17
+ const taproot_1 = require("../../taproot");
18
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
19
+ const index_1 = require("../../index");
20
+ const PsbtUtil_1 = require("../PsbtUtil");
10
21
  function getTaprootSigners(script, walletKeys) {
11
- const parsedPublicKeys = parseInput_1.parsePubScript(script, 'p2tr').publicKeys;
22
+ const parsedPublicKeys = parseInput_1.parsePubScript2Of3(script, 'taprootScriptPathSpend').publicKeys;
12
23
  const walletSigners = parsedPublicKeys.map((publicKey) => {
13
24
  const index = walletKeys.publicKeys.findIndex((walletPublicKey) => outputScripts_1.toXOnlyPublicKey(walletPublicKey).equals(publicKey));
14
25
  if (index >= 0) {
@@ -19,14 +30,14 @@ function getTaprootSigners(script, walletKeys) {
19
30
  return [walletSigners[0], walletSigners[1]];
20
31
  }
21
32
  function updatePsbtInput(psbt, inputIndex, unspent, rootWalletKeys) {
22
- const signatureCount = psbt.getSignatureCount(inputIndex);
33
+ const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
34
+ const signatureCount = PsbtUtil_1.getPsbtInputSignatureCount(input);
23
35
  const scriptType = outputScripts_1.scriptTypeForChain(unspent.chain);
24
36
  if (signatureCount === 0 && scriptType === 'p2tr') {
25
37
  return;
26
38
  }
27
39
  const walletKeys = rootWalletKeys.deriveForChainAndIndex(unspent.chain, unspent.index);
28
40
  if (scriptType === 'p2tr') {
29
- const input = psbt.data.inputs[inputIndex];
30
41
  if (!Array.isArray(input.tapLeafScript) || input.tapLeafScript.length === 0) {
31
42
  throw new Error('Invalid PSBT state. Missing required fields.');
32
43
  }
@@ -75,7 +86,10 @@ function updatePsbtInput(psbt, inputIndex, unspent, rootWalletKeys) {
75
86
  * Signed PSBT for other input with witnessUtxo/nonWitnessUtxo, redeemScript/witnessScript, bip32Derivation, partialSig
76
87
  */
77
88
  function toWalletPsbt(tx, unspents, rootWalletKeys) {
78
- const prevOutputs = unspents.map((u) => Unspent_1.toPrevOutputWithPrevTx(u, tx.network));
89
+ const prevOutputs = unspents.map((u) => {
90
+ assert.notStrictEqual(outputScripts_1.scriptTypeForChain(u.chain), 'p2trMusig2');
91
+ return Unspent_1.toPrevOutputWithPrevTx(u, tx.network);
92
+ });
79
93
  const psbt = transaction_1.createPsbtFromTransaction(tx, prevOutputs);
80
94
  unspents.forEach((u, i) => {
81
95
  if (Unspent_2.isWalletUnspent(u) && u.index !== undefined) {
@@ -93,7 +107,8 @@ exports.toWalletPsbt = toWalletPsbt;
93
107
  * @return signed PSBT with signer's key for unspent
94
108
  */
95
109
  function signWalletPsbt(psbt, inputIndex, signer, unspent) {
96
- if (outputScripts_1.scriptTypeForChain(unspent.chain) === 'p2tr') {
110
+ const scriptType = outputScripts_1.scriptTypeForChain(unspent.chain);
111
+ if (scriptType === 'p2tr' || scriptType === 'p2trMusig2') {
97
112
  psbt.signTaprootInputHD(inputIndex, signer);
98
113
  }
99
114
  else {
@@ -101,132 +116,335 @@ function signWalletPsbt(psbt, inputIndex, signer, unspent) {
101
116
  }
102
117
  }
103
118
  exports.signWalletPsbt = signWalletPsbt;
104
- function classifyScriptType(input) {
119
+ /**
120
+ * @returns script type of the input
121
+ */
122
+ function getPsbtInputScriptType(input) {
123
+ const isP2pk = (script) => {
124
+ try {
125
+ const chunks = bitcoinjs_lib_1.script.decompile(script);
126
+ return ((chunks === null || chunks === void 0 ? void 0 : chunks.length) === 2 &&
127
+ Buffer.isBuffer(chunks[0]) &&
128
+ bitcoinjs_lib_1.script.isCanonicalPubKey(chunks[0]) &&
129
+ chunks[1] === index_1.opcodes.OP_CHECKSIG);
130
+ }
131
+ catch (e) {
132
+ return false;
133
+ }
134
+ };
105
135
  let scriptType;
106
136
  if (Buffer.isBuffer(input.redeemScript) && Buffer.isBuffer(input.witnessScript)) {
107
137
  scriptType = 'p2shP2wsh';
108
138
  }
109
139
  else if (Buffer.isBuffer(input.redeemScript)) {
110
- scriptType = 'p2sh';
140
+ scriptType = isP2pk(input.redeemScript) ? 'p2shP2pk' : 'p2sh';
111
141
  }
112
142
  else if (Buffer.isBuffer(input.witnessScript)) {
113
143
  scriptType = 'p2wsh';
114
144
  }
115
145
  if (Array.isArray(input.tapLeafScript) && input.tapLeafScript.length > 0) {
116
146
  if (scriptType) {
117
- throw new Error(`Found both ${scriptType} and p2tr PSBT metadata.`);
147
+ throw new Error(`Found both ${scriptType} and taprootScriptPath PSBT metadata.`);
118
148
  }
119
149
  if (input.tapLeafScript.length > 1) {
120
150
  throw new Error('Bitgo only supports a single tap leaf script per input.');
121
151
  }
122
- scriptType = 'p2tr';
152
+ scriptType = 'taprootScriptPathSpend';
123
153
  }
124
- return scriptType;
125
- }
126
- function parseSignatures(input, scriptType) {
127
- const validate = (sig) => {
128
- if (Buffer.isBuffer(sig)) {
129
- return sig;
130
- }
131
- throw new Error('Invalid signature type');
132
- };
133
- if (scriptType === 'p2tr') {
134
- if (input.partialSig && input.partialSig.length > 0) {
135
- throw new Error('Invalid PSBT signature state');
136
- }
137
- if (!input.tapScriptSig || input.tapScriptSig.length === 0) {
138
- return undefined;
139
- }
140
- if (input.tapScriptSig.length > 2) {
141
- throw new Error('unexpected signature count');
154
+ if (input.tapInternalKey) {
155
+ if (scriptType) {
156
+ throw new Error(`Found both ${scriptType} and taprootKeyPath PSBT metadata.`);
142
157
  }
143
- return input.tapScriptSig.length === 1
144
- ? [validate(input.tapScriptSig[0].signature)]
145
- : [validate(input.tapScriptSig[0].signature), validate(input.tapScriptSig[1].signature)];
158
+ scriptType = 'taprootKeyPathSpend';
159
+ }
160
+ if (scriptType) {
161
+ return scriptType;
146
162
  }
147
- if (input.tapScriptSig && input.tapScriptSig.length > 0) {
148
- throw new Error('Invalid PSBT signature state');
163
+ throw new Error('could not parse input');
164
+ }
165
+ exports.getPsbtInputScriptType = getPsbtInputScriptType;
166
+ function parseTaprootKeyPathSignatures(input) {
167
+ const partialSigs = Musig2_1.parsePsbtMusig2PartialSigs(input);
168
+ if (!partialSigs) {
169
+ return { signatures: undefined, participantPublicKeys: undefined };
149
170
  }
150
- if (!input.partialSig || input.partialSig.length === 0) {
151
- return undefined;
171
+ const signatures = partialSigs.map((pSig) => pSig.partialSig);
172
+ const participantPublicKeys = partialSigs.map((pSig) => pSig.participantPubKey);
173
+ return types_1.isTuple(signatures) && types_1.isTuple(participantPublicKeys)
174
+ ? { signatures, participantPublicKeys }
175
+ : { signatures: [signatures[0]], participantPublicKeys: [participantPublicKeys[0]] };
176
+ }
177
+ function parsePartialOrTapScriptSignatures(sig) {
178
+ if (!(sig === null || sig === void 0 ? void 0 : sig.length)) {
179
+ return { signatures: undefined };
152
180
  }
153
- if (input.partialSig.length > 2) {
181
+ if (sig.length > 2) {
154
182
  throw new Error('unexpected signature count');
155
183
  }
156
- return input.partialSig.length === 1
157
- ? [validate(input.partialSig[0].signature)]
158
- : [validate(input.partialSig[0].signature), validate(input.partialSig[1].signature)];
184
+ const signatures = sig.map((tSig) => tSig.signature);
185
+ return types_1.isTuple(signatures) ? { signatures } : { signatures: [signatures[0]] };
186
+ }
187
+ function parseSignatures(input, scriptType) {
188
+ return scriptType === 'taprootKeyPathSpend'
189
+ ? parseTaprootKeyPathSignatures(input)
190
+ : scriptType === 'taprootScriptPathSpend'
191
+ ? parsePartialOrTapScriptSignatures(input.tapScriptSig)
192
+ : parsePartialOrTapScriptSignatures(input.partialSig);
159
193
  }
160
194
  function parseScript(input, scriptType) {
195
+ var _a;
161
196
  let pubScript;
162
- if (scriptType === 'p2sh') {
197
+ if (scriptType === 'p2sh' || scriptType === 'p2shP2pk') {
163
198
  pubScript = input.redeemScript;
164
199
  }
165
200
  else if (scriptType === 'p2wsh' || scriptType === 'p2shP2wsh') {
166
201
  pubScript = input.witnessScript;
167
202
  }
168
- else {
203
+ else if (scriptType === 'taprootScriptPathSpend') {
169
204
  pubScript = input.tapLeafScript ? input.tapLeafScript[0].script : undefined;
170
205
  }
206
+ else if (scriptType === 'taprootKeyPathSpend') {
207
+ if ((_a = input.witnessUtxo) === null || _a === void 0 ? void 0 : _a.script) {
208
+ pubScript = input.witnessUtxo.script;
209
+ }
210
+ else if (input.tapInternalKey && input.tapMerkleRoot) {
211
+ pubScript = taproot_1.createTaprootOutputScript({ internalPubKey: input.tapInternalKey, taptreeRoot: input.tapMerkleRoot });
212
+ }
213
+ }
171
214
  if (!pubScript) {
172
215
  throw new Error(`Invalid PSBT state for ${scriptType}. Missing required fields.`);
173
216
  }
174
217
  return parseInput_1.parsePubScript(pubScript, scriptType);
175
218
  }
176
- function parseInputMetadata(input, scriptType) {
219
+ /**
220
+ * @return psbt metadata are parsed as per below conditions.
221
+ * redeemScript/witnessScript/tapLeafScript matches BitGo.
222
+ * signature and public key count matches BitGo.
223
+ * P2SH-P2PK => scriptType, redeemScript, public key, signature.
224
+ * P2SH => scriptType, redeemScript, public keys, signatures.
225
+ * PW2SH => scriptType, witnessScript, public keys, signatures.
226
+ * P2SH-PW2SH => scriptType, redeemScript, witnessScript, public keys, signatures.
227
+ * P2TR and P2TR MUSIG2 script path => scriptType (taprootScriptPathSpend), pubScript (leaf script), controlBlock,
228
+ * scriptPathLevel, leafVersion, public keys, signatures.
229
+ * P2TR MUSIG2 kep path => scriptType (taprootKeyPathSpend), pubScript (scriptPubKey), participant pub keys (signer),
230
+ * public key (tapOutputkey), signatures (partial signer sigs).
231
+ */
232
+ function parsePsbtInput(input) {
233
+ if (PsbtUtil_1.isPsbtInputFinalized(input)) {
234
+ throw new Error('Finalized PSBT parsing is not supported');
235
+ }
236
+ const scriptType = getPsbtInputScriptType(input);
177
237
  const parsedPubScript = parseScript(input, scriptType);
178
238
  const signatures = parseSignatures(input, scriptType);
179
- if (parsedPubScript.scriptType === 'p2tr') {
239
+ if (parsedPubScript.scriptType === 'taprootKeyPathSpend' && 'participantPublicKeys' in signatures) {
240
+ return {
241
+ ...parsedPubScript,
242
+ ...signatures,
243
+ };
244
+ }
245
+ if (parsedPubScript.scriptType === 'taprootScriptPathSpend') {
180
246
  if (!input.tapLeafScript) {
181
- throw new Error('Invalid PSBT state for p2tr. Missing required fields.');
247
+ throw new Error('Invalid PSBT state for taprootScriptPathSpend. Missing required fields.');
182
248
  }
183
249
  const controlBlock = input.tapLeafScript[0].controlBlock;
184
250
  if (!parseInput_1.isValidControlBock(controlBlock)) {
185
- throw new Error('Invalid PSBT p2tr script path controlBlock.');
251
+ throw new Error('Invalid PSBT taprootScriptPathSpend controlBlock.');
186
252
  }
187
253
  const scriptPathLevel = parseInput_1.calculateScriptPathLevel(controlBlock);
188
- const leafVersion = parseInput_1.getScriptPathLevel(controlBlock);
254
+ const leafVersion = parseInput_1.getLeafVersion(controlBlock);
189
255
  return {
190
256
  ...parsedPubScript,
191
- signatures,
257
+ ...signatures,
192
258
  controlBlock,
193
259
  scriptPathLevel,
194
260
  leafVersion,
195
261
  };
196
262
  }
197
- else {
263
+ if (parsedPubScript.scriptType === 'p2sh' ||
264
+ parsedPubScript.scriptType === 'p2wsh' ||
265
+ parsedPubScript.scriptType === 'p2shP2wsh') {
198
266
  if (parsedPubScript.scriptType === 'p2shP2wsh') {
199
267
  parsedPubScript.redeemScript = input.redeemScript;
200
268
  }
201
269
  return {
202
270
  ...parsedPubScript,
203
- signatures,
271
+ ...signatures,
272
+ };
273
+ }
274
+ if (parsedPubScript.scriptType === 'p2shP2pk' && (!signatures.signatures || !types_1.isTuple(signatures.signatures))) {
275
+ return {
276
+ ...parsedPubScript,
277
+ signatures: signatures.signatures,
204
278
  };
205
279
  }
280
+ throw new Error('invalid pub script');
206
281
  }
282
+ exports.parsePsbtInput = parsePsbtInput;
207
283
  /**
208
- * @return psbt metadata are parsed as per below conditions.
209
- * redeemScript/witnessScript/tapLeafScript matches BitGo.
210
- * signature and public key count matches BitGo.
211
- * P2SH => scriptType, redeemScript, public keys, signatures.
212
- * PW2SH => scriptType, witnessScript, public keys, signatures.
213
- * P2SH-PW2SH => scriptType, redeemScript, witnessScript, public keys, signatures.
214
- * P2TR => scriptType, pubScript (witnessScript), controlBlock, scriptPathLevel, leafVersion, public keys, signatures.
215
- * Any unsigned PSBT and without required metadata is returned with undefined.
284
+ * @returns strictly parse the input and get signature count.
285
+ * unsigned(0), half-signed(1) or fully-signed(2)
216
286
  */
217
- function parsePsbtInput(psbt, inputIndex) {
218
- const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
219
- if (psbt.isInputFinalized(inputIndex)) {
220
- throw new Error('Finalized PSBT parsing is not supported');
287
+ function getStrictSignatureCount(input) {
288
+ var _a, _b;
289
+ const calculateSignatureCount = (signatures) => {
290
+ const count = signatures ? signatures.filter((s) => !parseInput_1.isPlaceholderSignature(s)).length : 0;
291
+ if (count === 0 || count === 1 || count === 2) {
292
+ return count;
293
+ }
294
+ throw new Error('invalid signature count');
295
+ };
296
+ if ('hash' in input) {
297
+ if (((_a = input.script) === null || _a === void 0 ? void 0 : _a.length) || ((_b = input.witness) === null || _b === void 0 ? void 0 : _b.length)) {
298
+ const parsedInput = parseInput_1.parseSignatureScript(input);
299
+ return parsedInput.scriptType === 'taprootKeyPathSpend' ? 2 : calculateSignatureCount(parsedInput.signatures);
300
+ }
301
+ return 0;
302
+ }
303
+ else {
304
+ return calculateSignatureCount(parsePsbtInput(input).signatures);
221
305
  }
222
- const scriptType = classifyScriptType(input);
223
- if (!scriptType) {
224
- if (psbt.getSignatureCount(inputIndex) > 0) {
225
- throw new Error('Invalid PSBT state. Signatures found without scripts.');
306
+ }
307
+ exports.getStrictSignatureCount = getStrictSignatureCount;
308
+ /**
309
+ * @returns strictly parse input and get signature count for all inputs.
310
+ * 0=unsigned, 1=half-signed or 2=fully-signed
311
+ */
312
+ function getStrictSignatureCounts(tx) {
313
+ const inputs = tx instanceof UtxoPsbt_1.UtxoPsbt ? tx.data.inputs : tx instanceof UtxoTransaction_1.UtxoTransaction ? tx.ins : tx;
314
+ return inputs.map((input, _) => getStrictSignatureCount(input));
315
+ }
316
+ exports.getStrictSignatureCounts = getStrictSignatureCounts;
317
+ /**
318
+ * @return true iff inputs array is of PsbtInputType type
319
+ * */
320
+ function isPsbtInputArray(inputs) {
321
+ return !isTxInputArray(inputs);
322
+ }
323
+ exports.isPsbtInputArray = isPsbtInputArray;
324
+ /**
325
+ * @return true iff inputs array is of TxInput type
326
+ * */
327
+ function isTxInputArray(inputs) {
328
+ assert(!!inputs.length, 'empty inputs array');
329
+ return 'hash' in inputs[0];
330
+ }
331
+ exports.isTxInputArray = isTxInputArray;
332
+ /**
333
+ * @returns true iff given psbt/transaction/tx-input-array/psbt-input-array contains at least one taproot key path spend input
334
+ */
335
+ function isTransactionWithKeyPathSpendInput(data) {
336
+ const inputs = data instanceof UtxoPsbt_1.UtxoPsbt ? data.data.inputs : data instanceof UtxoTransaction_1.UtxoTransaction ? data.ins : data;
337
+ if (!inputs.length) {
338
+ return false;
339
+ }
340
+ if (isPsbtInputArray(inputs)) {
341
+ return inputs.some((input, _) => getPsbtInputScriptType(input) === 'taprootKeyPathSpend');
342
+ }
343
+ return inputs.some((input, _) => {
344
+ // If the input is not signed, it cannot be a taprootKeyPathSpend input because you can only
345
+ // extract a fully signed psbt into a transaction with taprootKeyPathSpend inputs.
346
+ if (getStrictSignatureCount(input) === 0) {
347
+ return false;
226
348
  }
227
- return undefined;
349
+ return parseInput_1.parseSignatureScript(input).scriptType === 'taprootKeyPathSpend';
350
+ });
351
+ }
352
+ exports.isTransactionWithKeyPathSpendInput = isTransactionWithKeyPathSpendInput;
353
+ /**
354
+ * Set the RootWalletKeys as the globalXpubs on the psbt
355
+ *
356
+ * We do all the matching of the (tap)bip32Derivations masterFingerprint to the fingerprint of the
357
+ * extendedPubkey.
358
+ */
359
+ function addXpubsToPsbt(psbt, rootWalletKeys) {
360
+ const safeRootWalletKeys = new WalletKeys_1.RootWalletKeys(rootWalletKeys.triple.map((bip32) => bip32.neutered()), rootWalletKeys.derivationPrefixes);
361
+ const xPubs = safeRootWalletKeys.triple.map((bip32) => ({
362
+ extendedPubkey: bs58check.decode(bip32.toBase58()),
363
+ masterFingerprint: bip32.fingerprint,
364
+ // TODO: BG-73797 - bip174 currently requires m prefix for this to be a valid globalXpub
365
+ path: 'm',
366
+ }));
367
+ psbt.updateGlobal({ globalXpub: xPubs });
368
+ }
369
+ exports.addXpubsToPsbt = addXpubsToPsbt;
370
+ /**
371
+ * validates signatures for each 2 of 3 input against user, backup, bitgo keys derived from rootWalletKeys.
372
+ * @returns array of input index and its [is valid user sig exist, is valid backup sig exist, is valid user bitgo exist]
373
+ * For p2shP2pk input, [false, false, false] is returned since it is not a 2 of 3 sig input.
374
+ */
375
+ function getSignatureValidationArrayPsbt(psbt, rootWalletKeys) {
376
+ return psbt.data.inputs.map((input, i) => {
377
+ const sigValArrayForInput = getPsbtInputScriptType(input) === 'p2shP2pk'
378
+ ? [false, false, false]
379
+ : psbt.getSignatureValidationArray(i, { rootNodes: rootWalletKeys.triple });
380
+ return [i, sigValArrayForInput];
381
+ });
382
+ }
383
+ exports.getSignatureValidationArrayPsbt = getSignatureValidationArrayPsbt;
384
+ /**
385
+ * Extracts the half signed transaction from the psbt for p2ms based script types - p2sh, p2wsh, and p2shP2wsh.
386
+ * The purpose is to provide backward compatibility to keyternal (KRS) that only supports network transaction and p2ms script types.
387
+ */
388
+ function extractP2msOnlyHalfSignedTx(psbt) {
389
+ assert(!!(psbt.data.inputs.length && psbt.data.outputs.length), 'empty inputs or outputs');
390
+ const tx = psbt.getUnsignedTx();
391
+ function isP2msParsedPsbtInput(parsed) {
392
+ return ['p2sh', 'p2shP2wsh', 'p2wsh'].includes(parsed.scriptType);
228
393
  }
229
- return parseInputMetadata(input, scriptType);
394
+ psbt.data.inputs.forEach((input, i) => {
395
+ var _a, _b;
396
+ const parsed = parsePsbtInput(input);
397
+ assert(isP2msParsedPsbtInput(parsed), `unsupported script type ${parsed.scriptType}`);
398
+ assert(((_a = input.partialSig) === null || _a === void 0 ? void 0 : _a.length) === 1, `unexpected signature count ${(_b = input.partialSig) === null || _b === void 0 ? void 0 : _b.length}`);
399
+ const [partialSig] = input.partialSig;
400
+ assert(input.sighashType !== undefined && input.sighashType === bitcoinjs_lib_1.script.signature.decode(partialSig.signature).hashType, 'signature sighash does not match input sighash type');
401
+ // type casting is to address the invalid type checking in payments.p2ms
402
+ const signatures = parsed.publicKeys.map((pk) => partialSig.pubkey.equals(pk) ? partialSig.signature : bitcoinjs_lib_1.opcodes.OP_0);
403
+ const isP2SH = !!parsed.redeemScript;
404
+ const isP2WSH = !!parsed.witnessScript;
405
+ const payment = index_1.payments.p2ms({ output: parsed.pubScript, signatures }, { validate: false, allowIncomplete: true });
406
+ const p2wsh = isP2WSH ? index_1.payments.p2wsh({ redeem: payment }) : undefined;
407
+ const p2sh = isP2SH ? index_1.payments.p2sh({ redeem: p2wsh || payment }) : undefined;
408
+ if (p2sh === null || p2sh === void 0 ? void 0 : p2sh.input) {
409
+ tx.setInputScript(i, p2sh.input);
410
+ }
411
+ if (p2wsh === null || p2wsh === void 0 ? void 0 : p2wsh.witness) {
412
+ tx.setWitness(i, p2wsh.witness);
413
+ }
414
+ });
415
+ return tx;
230
416
  }
231
- exports.parsePsbtInput = parsePsbtInput;
232
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUHNidC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvUHNidC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSxvREFNMEI7QUFFMUIsd0NBQW9EO0FBQ3BELGdEQUEyRDtBQUUzRCx1Q0FBMkQ7QUFDM0QsZ0RBQXFEO0FBRXJELDhDQU91QjtBQXFCdkIsU0FBUyxpQkFBaUIsQ0FBQyxNQUFjLEVBQUUsVUFBNkI7SUFDdEUsTUFBTSxnQkFBZ0IsR0FBRywyQkFBYyxDQUFDLE1BQU0sRUFBRSxNQUFNLENBQUMsQ0FBQyxVQUFVLENBQUM7SUFDbkUsTUFBTSxhQUFhLEdBQUcsZ0JBQWdCLENBQUMsR0FBRyxDQUFDLENBQUMsU0FBUyxFQUFFLEVBQUU7UUFDdkQsTUFBTSxLQUFLLEdBQUcsVUFBVSxDQUFDLFVBQVUsQ0FBQyxTQUFTLENBQUMsQ0FBQyxlQUFlLEVBQUUsRUFBRSxDQUNoRSxnQ0FBZ0IsQ0FBQyxlQUFlLENBQUMsQ0FBQyxNQUFNLENBQUMsU0FBUyxDQUFDLENBQ3BELENBQUM7UUFDRixJQUFJLEtBQUssSUFBSSxDQUFDLEVBQUU7WUFDZCxPQUFPLEVBQUUsU0FBUyxFQUFFLFVBQVUsQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsT0FBTyxFQUFFLFVBQVUsQ0FBQyxNQUFNLENBQUMsTUFBTSxDQ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uLCBwdWJsaWMga2V5cywgc2lnbmF0dXJlcy5cbiAqIEFueSB1bnNpZ25lZCBQU0JUIGFuZCB3aXRob3V0IHJlcXVpcmVkIG1ldGFkYXRhIGlzIHJldHVybmVkIHdpdGggdW5kZWZpbmVkLlxuICovXG5leHBvcnQgZnVuY3Rpb24gcGFyc2VQc2J0SW5wdXQocHNidDogVXR4b1BzYnQsIGlucHV0SW5kZXg6IG51bWJlcik6IFBhcnNlZFBzYnQyT2YzIHwgUGFyc2VkUHNidFAyVFIgfCB1bmRlZmluZWQge1xuICBjb25zdCBpbnB1dCA9IGNoZWNrRm9ySW5wdXQocHNidC5kYXRhLmlucHV0cywgaW5wdXRJbmRleCk7XG4gIGlmIChwc2J0LmlzSW5wdXRGaW5hbGl6ZWQoaW5wdXRJbmRleCkpIHtcbiAgICB0aHJvdyBuZXcgRXJyb3IoJ0ZpbmFsaXplZCBQU0JUIHBhcnNpbmcgaXMgbm90IHN1cHBvcnRlZCcpO1xuICB9XG4gIGNvbnN0IHNjcmlwdFR5cGUgPSBjbGFzc2lmeVNjcmlwdFR5cGUoaW5wdXQpO1xuICBpZiAoIXNjcmlwdFR5cGUpIHtcbiAgICBpZiAocHNidC5nZXRTaWduYXR1cmVDb3VudChpbnB1dEluZGV4KSA+IDApIHtcbiAgICAgIHRocm93IG5ldyBFcnJvcignSW52YWxpZCBQU0JUIHN0YXRlLiBTaWduYXR1cmVzIGZvdW5kIHdpdGhvdXQgc2NyaXB0cy4nKTtcbiAgICB9XG4gICAgcmV0dXJuIHVuZGVmaW5lZDtcbiAgfVxuICByZXR1cm4gcGFyc2VJbnB1dE1ldGFkYXRhKGlucHV0LCBzY3JpcHRUeXBlKTtcbn1cbiJdfQ==
417
+ exports.extractP2msOnlyHalfSignedTx = extractP2msOnlyHalfSignedTx;
418
+ /**
419
+ * Clones the psbt without nonWitnessUtxo for non-segwit inputs and witnessUtxo is added instead.
420
+ * It is not BIP-174 compliant, so use it carefully.
421
+ */
422
+ function clonePsbtWithoutNonWitnessUtxo(psbt) {
423
+ const newPsbt = psbt.clone();
424
+ const txInputs = psbt.txInputs;
425
+ psbt.data.inputs.forEach((input, i) => {
426
+ if (input.nonWitnessUtxo && !input.witnessUtxo) {
427
+ const tx = UtxoTransaction_1.UtxoTransaction.fromBuffer(input.nonWitnessUtxo, false, 'bigint', psbt.network);
428
+ if (!txInputs[i].hash.equals(tx.getHash())) {
429
+ throw new Error(`Non-witness UTXO hash for input #${i} doesn't match the hash specified in the prevout`);
430
+ }
431
+ newPsbt.data.inputs[i].witnessUtxo = tx.outs[txInputs[i].index];
432
+ }
433
+ delete newPsbt.data.inputs[i].nonWitnessUtxo;
434
+ });
435
+ return newPsbt;
436
+ }
437
+ exports.clonePsbtWithoutNonWitnessUtxo = clonePsbtWithoutNonWitnessUtxo;
438
+ /**
439
+ * Deletes witnessUtxo for non-segwit inputs to make the PSBT BIP-174 compliant.
440
+ */
441
+ function deleteWitnessUtxoForNonSegwitInputs(psbt) {
442
+ psbt.data.inputs.forEach((input, i) => {
443
+ const scriptType = getPsbtInputScriptType(input);
444
+ if (scriptType === 'p2sh' || scriptType === 'p2shP2pk') {
445
+ delete input.witnessUtxo;
446
+ }
447
+ });
448
+ }
449
+ exports.deleteWitnessUtxoForNonSegwitInputs = deleteWitnessUtxoForNonSegwitInputs;
450
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUHNidC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvUHNidC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxpQ0FBaUM7QUFHakMsZ0RBQXFEO0FBRXJELHVDQUF1QztBQUN2QywwQ0FBdUM7QUFDdkMsd0RBQXFEO0FBQ3JELG9EQUE2RztBQUM3Ryw2Q0FBaUU7QUFDakUsd0NBQW9EO0FBQ3BELGdEQUEyRDtBQUMzRCx1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