utxo-lib 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +19 -16
- package/dist/src/address.d.ts.map +1 -1
- package/dist/src/address.js +11 -1
- package/dist/src/addressFormat.d.ts +1 -1
- package/dist/src/addressFormat.d.ts.map +1 -1
- package/dist/src/addressFormat.js +1 -1
- package/dist/src/base_crypto.d.ts +14 -0
- package/dist/src/base_crypto.d.ts.map +1 -0
- package/dist/src/base_crypto.js +215 -0
- package/dist/src/bitgo/Musig2.d.ts +115 -17
- package/dist/src/bitgo/Musig2.d.ts.map +1 -1
- package/dist/src/bitgo/Musig2.js +283 -101
- package/dist/src/bitgo/PsbtUtil.d.ts +59 -0
- package/dist/src/bitgo/PsbtUtil.d.ts.map +1 -0
- package/dist/src/bitgo/PsbtUtil.js +91 -0
- package/dist/src/bitgo/UtxoPsbt.d.ts +180 -47
- package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -1
- package/dist/src/bitgo/UtxoPsbt.js +657 -121
- package/dist/src/bitgo/UtxoTransaction.js +2 -2
- package/dist/src/bitgo/bitcoincash/address.js +2 -2
- package/dist/src/bitgo/index.d.ts +11 -0
- package/dist/src/bitgo/index.d.ts.map +1 -1
- package/dist/src/bitgo/index.js +6 -2
- package/dist/src/bitgo/legacysafe/index.d.ts +15 -0
- package/dist/src/bitgo/legacysafe/index.d.ts.map +1 -0
- package/dist/src/bitgo/legacysafe/index.js +61 -0
- package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts +10 -0
- package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts.map +1 -0
- package/dist/src/bitgo/litecoin/LitecoinPsbt.js +17 -0
- package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts +16 -0
- package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts.map +1 -0
- package/dist/src/bitgo/litecoin/LitecoinTransaction.js +46 -0
- package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts +10 -0
- package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts.map +1 -0
- package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.js +15 -0
- package/dist/src/bitgo/litecoin/index.d.ts +4 -0
- package/dist/src/bitgo/litecoin/index.d.ts.map +1 -0
- package/dist/src/bitgo/litecoin/index.js +16 -0
- package/dist/src/bitgo/outputScripts.d.ts +3 -1
- package/dist/src/bitgo/outputScripts.d.ts.map +1 -1
- package/dist/src/bitgo/outputScripts.js +20 -12
- package/dist/src/bitgo/parseInput.d.ts +49 -20
- package/dist/src/bitgo/parseInput.d.ts.map +1 -1
- package/dist/src/bitgo/parseInput.js +110 -26
- package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -1
- package/dist/src/bitgo/psbt/fromHalfSigned.js +9 -6
- package/dist/src/bitgo/psbt/scriptTypes.js +3 -3
- package/dist/src/bitgo/signature.d.ts +3 -3
- package/dist/src/bitgo/signature.d.ts.map +1 -1
- package/dist/src/bitgo/signature.js +48 -16
- package/dist/src/bitgo/transaction.d.ts +18 -3
- package/dist/src/bitgo/transaction.d.ts.map +1 -1
- package/dist/src/bitgo/transaction.js +28 -15
- package/dist/src/bitgo/types.d.ts +2 -0
- package/dist/src/bitgo/types.d.ts.map +1 -1
- package/dist/src/bitgo/types.js +1 -1
- package/dist/src/bitgo/wallet/Psbt.d.ts +104 -12
- package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -1
- package/dist/src/bitgo/wallet/Psbt.js +285 -70
- package/dist/src/bitgo/wallet/Unspent.d.ts +28 -0
- package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -1
- package/dist/src/bitgo/wallet/Unspent.js +172 -68
- package/dist/src/bitgo/wallet/WalletOutput.d.ts +17 -1
- package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -1
- package/dist/src/bitgo/wallet/WalletOutput.js +64 -23
- package/dist/src/bitgo/wallet/chains.d.ts +2 -2
- package/dist/src/bitgo/wallet/chains.d.ts.map +1 -1
- package/dist/src/bitgo/wallet/chains.js +1 -1
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +0 -1
- package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -1
- package/dist/src/bitgo/zcash/ZcashPsbt.js +7 -16
- package/dist/src/bitgo/zcash/ZcashTransaction.js +2 -2
- package/dist/src/musig.d.ts +390 -0
- package/dist/src/musig.d.ts.map +1 -0
- package/dist/src/musig.js +447 -0
- package/dist/src/networks.d.ts +1 -2
- package/dist/src/networks.d.ts.map +1 -1
- package/dist/src/networks.js +22 -29
- package/dist/src/noble_ecc.d.ts +1 -1
- package/dist/src/noble_ecc.d.ts.map +1 -1
- package/dist/src/noble_ecc.js +11 -7
- package/dist/src/payments/p2tr.d.ts.map +1 -1
- package/dist/src/payments/p2tr.js +21 -19
- package/dist/src/payments/p2tr_ns.js +2 -3
- package/dist/src/taproot.d.ts +16 -0
- package/dist/src/taproot.d.ts.map +1 -1
- package/dist/src/taproot.js +45 -4
- package/dist/src/testutil/index.d.ts +2 -0
- package/dist/src/testutil/index.d.ts.map +1 -1
- package/dist/src/testutil/index.js +3 -1
- package/dist/src/testutil/keys.d.ts +3 -0
- package/dist/src/testutil/keys.d.ts.map +1 -1
- package/dist/src/testutil/keys.js +17 -2
- package/dist/src/testutil/mock.d.ts +1 -1
- package/dist/src/testutil/mock.d.ts.map +1 -1
- package/dist/src/testutil/mock.js +12 -4
- package/dist/src/testutil/psbt.d.ts +89 -0
- package/dist/src/testutil/psbt.d.ts.map +1 -0
- package/dist/src/testutil/psbt.js +150 -0
- package/dist/src/testutil/transaction.d.ts +70 -0
- package/dist/src/testutil/transaction.d.ts.map +1 -0
- package/dist/src/testutil/transaction.js +107 -0
- package/dist/src/transaction_builder.js +2 -2
- package/package.json +6 -7
@@ -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.
|
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
|
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) =>
|
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
|
-
|
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,332 @@ function signWalletPsbt(psbt, inputIndex, signer, unspent) {
|
|
101
116
|
}
|
102
117
|
}
|
103
118
|
exports.signWalletPsbt = signWalletPsbt;
|
104
|
-
|
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?.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
|
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 = '
|
152
|
+
scriptType = 'taprootScriptPathSpend';
|
123
153
|
}
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
158
|
+
scriptType = 'taprootKeyPathSpend';
|
159
|
+
}
|
160
|
+
if (scriptType) {
|
161
|
+
return scriptType;
|
146
162
|
}
|
147
|
-
|
148
|
-
|
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
|
-
|
151
|
-
|
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?.length) {
|
179
|
+
return { signatures: undefined };
|
152
180
|
}
|
153
|
-
if (
|
181
|
+
if (sig.length > 2) {
|
154
182
|
throw new Error('unexpected signature count');
|
155
183
|
}
|
156
|
-
|
157
|
-
|
158
|
-
|
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) {
|
161
195
|
let pubScript;
|
162
|
-
if (scriptType === 'p2sh') {
|
196
|
+
if (scriptType === 'p2sh' || scriptType === 'p2shP2pk') {
|
163
197
|
pubScript = input.redeemScript;
|
164
198
|
}
|
165
199
|
else if (scriptType === 'p2wsh' || scriptType === 'p2shP2wsh') {
|
166
200
|
pubScript = input.witnessScript;
|
167
201
|
}
|
168
|
-
else {
|
202
|
+
else if (scriptType === 'taprootScriptPathSpend') {
|
169
203
|
pubScript = input.tapLeafScript ? input.tapLeafScript[0].script : undefined;
|
170
204
|
}
|
205
|
+
else if (scriptType === 'taprootKeyPathSpend') {
|
206
|
+
if (input.witnessUtxo?.script) {
|
207
|
+
pubScript = input.witnessUtxo.script;
|
208
|
+
}
|
209
|
+
else if (input.tapInternalKey && input.tapMerkleRoot) {
|
210
|
+
pubScript = taproot_1.createTaprootOutputScript({ internalPubKey: input.tapInternalKey, taptreeRoot: input.tapMerkleRoot });
|
211
|
+
}
|
212
|
+
}
|
171
213
|
if (!pubScript) {
|
172
214
|
throw new Error(`Invalid PSBT state for ${scriptType}. Missing required fields.`);
|
173
215
|
}
|
174
216
|
return parseInput_1.parsePubScript(pubScript, scriptType);
|
175
217
|
}
|
176
|
-
|
218
|
+
/**
|
219
|
+
* @return psbt metadata are parsed as per below conditions.
|
220
|
+
* redeemScript/witnessScript/tapLeafScript matches BitGo.
|
221
|
+
* signature and public key count matches BitGo.
|
222
|
+
* P2SH-P2PK => scriptType, redeemScript, public key, signature.
|
223
|
+
* P2SH => scriptType, redeemScript, public keys, signatures.
|
224
|
+
* PW2SH => scriptType, witnessScript, public keys, signatures.
|
225
|
+
* P2SH-PW2SH => scriptType, redeemScript, witnessScript, public keys, signatures.
|
226
|
+
* P2TR and P2TR MUSIG2 script path => scriptType (taprootScriptPathSpend), pubScript (leaf script), controlBlock,
|
227
|
+
* scriptPathLevel, leafVersion, public keys, signatures.
|
228
|
+
* P2TR MUSIG2 kep path => scriptType (taprootKeyPathSpend), pubScript (scriptPubKey), participant pub keys (signer),
|
229
|
+
* public key (tapOutputkey), signatures (partial signer sigs).
|
230
|
+
*/
|
231
|
+
function parsePsbtInput(input) {
|
232
|
+
if (PsbtUtil_1.isPsbtInputFinalized(input)) {
|
233
|
+
throw new Error('Finalized PSBT parsing is not supported');
|
234
|
+
}
|
235
|
+
const scriptType = getPsbtInputScriptType(input);
|
177
236
|
const parsedPubScript = parseScript(input, scriptType);
|
178
237
|
const signatures = parseSignatures(input, scriptType);
|
179
|
-
if (parsedPubScript.scriptType === '
|
238
|
+
if (parsedPubScript.scriptType === 'taprootKeyPathSpend' && 'participantPublicKeys' in signatures) {
|
239
|
+
return {
|
240
|
+
...parsedPubScript,
|
241
|
+
...signatures,
|
242
|
+
};
|
243
|
+
}
|
244
|
+
if (parsedPubScript.scriptType === 'taprootScriptPathSpend') {
|
180
245
|
if (!input.tapLeafScript) {
|
181
|
-
throw new Error('Invalid PSBT state for
|
246
|
+
throw new Error('Invalid PSBT state for taprootScriptPathSpend. Missing required fields.');
|
182
247
|
}
|
183
248
|
const controlBlock = input.tapLeafScript[0].controlBlock;
|
184
249
|
if (!parseInput_1.isValidControlBock(controlBlock)) {
|
185
|
-
throw new Error('Invalid PSBT
|
250
|
+
throw new Error('Invalid PSBT taprootScriptPathSpend controlBlock.');
|
186
251
|
}
|
187
252
|
const scriptPathLevel = parseInput_1.calculateScriptPathLevel(controlBlock);
|
188
|
-
const leafVersion = parseInput_1.
|
253
|
+
const leafVersion = parseInput_1.getLeafVersion(controlBlock);
|
189
254
|
return {
|
190
255
|
...parsedPubScript,
|
191
|
-
signatures,
|
256
|
+
...signatures,
|
192
257
|
controlBlock,
|
193
258
|
scriptPathLevel,
|
194
259
|
leafVersion,
|
195
260
|
};
|
196
261
|
}
|
197
|
-
|
262
|
+
if (parsedPubScript.scriptType === 'p2sh' ||
|
263
|
+
parsedPubScript.scriptType === 'p2wsh' ||
|
264
|
+
parsedPubScript.scriptType === 'p2shP2wsh') {
|
198
265
|
if (parsedPubScript.scriptType === 'p2shP2wsh') {
|
199
266
|
parsedPubScript.redeemScript = input.redeemScript;
|
200
267
|
}
|
201
268
|
return {
|
202
269
|
...parsedPubScript,
|
203
|
-
signatures,
|
270
|
+
...signatures,
|
271
|
+
};
|
272
|
+
}
|
273
|
+
if (parsedPubScript.scriptType === 'p2shP2pk' && (!signatures.signatures || !types_1.isTuple(signatures.signatures))) {
|
274
|
+
return {
|
275
|
+
...parsedPubScript,
|
276
|
+
signatures: signatures.signatures,
|
204
277
|
};
|
205
278
|
}
|
279
|
+
throw new Error('invalid pub script');
|
206
280
|
}
|
281
|
+
exports.parsePsbtInput = parsePsbtInput;
|
207
282
|
/**
|
208
|
-
* @
|
209
|
-
*
|
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.
|
283
|
+
* @returns strictly parse the input and get signature count.
|
284
|
+
* unsigned(0), half-signed(1) or fully-signed(2)
|
216
285
|
*/
|
217
|
-
function
|
218
|
-
const
|
219
|
-
|
220
|
-
|
286
|
+
function getStrictSignatureCount(input) {
|
287
|
+
const calculateSignatureCount = (signatures) => {
|
288
|
+
const count = signatures ? signatures.filter((s) => !parseInput_1.isPlaceholderSignature(s)).length : 0;
|
289
|
+
if (count === 0 || count === 1 || count === 2) {
|
290
|
+
return count;
|
291
|
+
}
|
292
|
+
throw new Error('invalid signature count');
|
293
|
+
};
|
294
|
+
if ('hash' in input) {
|
295
|
+
if (input.script?.length || input.witness?.length) {
|
296
|
+
const parsedInput = parseInput_1.parseSignatureScript(input);
|
297
|
+
return parsedInput.scriptType === 'taprootKeyPathSpend' ? 2 : calculateSignatureCount(parsedInput.signatures);
|
298
|
+
}
|
299
|
+
return 0;
|
300
|
+
}
|
301
|
+
else {
|
302
|
+
return calculateSignatureCount(parsePsbtInput(input).signatures);
|
221
303
|
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
304
|
+
}
|
305
|
+
exports.getStrictSignatureCount = getStrictSignatureCount;
|
306
|
+
/**
|
307
|
+
* @returns strictly parse input and get signature count for all inputs.
|
308
|
+
* 0=unsigned, 1=half-signed or 2=fully-signed
|
309
|
+
*/
|
310
|
+
function getStrictSignatureCounts(tx) {
|
311
|
+
const inputs = tx instanceof UtxoPsbt_1.UtxoPsbt ? tx.data.inputs : tx instanceof UtxoTransaction_1.UtxoTransaction ? tx.ins : tx;
|
312
|
+
return inputs.map((input, _) => getStrictSignatureCount(input));
|
313
|
+
}
|
314
|
+
exports.getStrictSignatureCounts = getStrictSignatureCounts;
|
315
|
+
/**
|
316
|
+
* @return true iff inputs array is of PsbtInputType type
|
317
|
+
* */
|
318
|
+
function isPsbtInputArray(inputs) {
|
319
|
+
return !isTxInputArray(inputs);
|
320
|
+
}
|
321
|
+
exports.isPsbtInputArray = isPsbtInputArray;
|
322
|
+
/**
|
323
|
+
* @return true iff inputs array is of TxInput type
|
324
|
+
* */
|
325
|
+
function isTxInputArray(inputs) {
|
326
|
+
assert(!!inputs.length, 'empty inputs array');
|
327
|
+
return 'hash' in inputs[0];
|
328
|
+
}
|
329
|
+
exports.isTxInputArray = isTxInputArray;
|
330
|
+
/**
|
331
|
+
* @returns true iff given psbt/transaction/tx-input-array/psbt-input-array contains at least one taproot key path spend input
|
332
|
+
*/
|
333
|
+
function isTransactionWithKeyPathSpendInput(data) {
|
334
|
+
const inputs = data instanceof UtxoPsbt_1.UtxoPsbt ? data.data.inputs : data instanceof UtxoTransaction_1.UtxoTransaction ? data.ins : data;
|
335
|
+
if (!inputs.length) {
|
336
|
+
return false;
|
337
|
+
}
|
338
|
+
if (isPsbtInputArray(inputs)) {
|
339
|
+
return inputs.some((input, _) => getPsbtInputScriptType(input) === 'taprootKeyPathSpend');
|
340
|
+
}
|
341
|
+
return inputs.some((input, _) => {
|
342
|
+
// If the input is not signed, it cannot be a taprootKeyPathSpend input because you can only
|
343
|
+
// extract a fully signed psbt into a transaction with taprootKeyPathSpend inputs.
|
344
|
+
if (getStrictSignatureCount(input) === 0) {
|
345
|
+
return false;
|
226
346
|
}
|
227
|
-
return
|
347
|
+
return parseInput_1.parseSignatureScript(input).scriptType === 'taprootKeyPathSpend';
|
348
|
+
});
|
349
|
+
}
|
350
|
+
exports.isTransactionWithKeyPathSpendInput = isTransactionWithKeyPathSpendInput;
|
351
|
+
/**
|
352
|
+
* Set the RootWalletKeys as the globalXpubs on the psbt
|
353
|
+
*
|
354
|
+
* We do all the matching of the (tap)bip32Derivations masterFingerprint to the fingerprint of the
|
355
|
+
* extendedPubkey.
|
356
|
+
*/
|
357
|
+
function addXpubsToPsbt(psbt, rootWalletKeys) {
|
358
|
+
const safeRootWalletKeys = new WalletKeys_1.RootWalletKeys(rootWalletKeys.triple.map((bip32) => bip32.neutered()), rootWalletKeys.derivationPrefixes);
|
359
|
+
const xPubs = safeRootWalletKeys.triple.map((bip32) => ({
|
360
|
+
extendedPubkey: bs58check.decode(bip32.toBase58()),
|
361
|
+
masterFingerprint: bip32.fingerprint,
|
362
|
+
// TODO: BG-73797 - bip174 currently requires m prefix for this to be a valid globalXpub
|
363
|
+
path: 'm',
|
364
|
+
}));
|
365
|
+
psbt.updateGlobal({ globalXpub: xPubs });
|
366
|
+
}
|
367
|
+
exports.addXpubsToPsbt = addXpubsToPsbt;
|
368
|
+
/**
|
369
|
+
* validates signatures for each 2 of 3 input against user, backup, bitgo keys derived from rootWalletKeys.
|
370
|
+
* @returns array of input index and its [is valid user sig exist, is valid backup sig exist, is valid user bitgo exist]
|
371
|
+
* For p2shP2pk input, [false, false, false] is returned since it is not a 2 of 3 sig input.
|
372
|
+
*/
|
373
|
+
function getSignatureValidationArrayPsbt(psbt, rootWalletKeys) {
|
374
|
+
return psbt.data.inputs.map((input, i) => {
|
375
|
+
const sigValArrayForInput = getPsbtInputScriptType(input) === 'p2shP2pk'
|
376
|
+
? [false, false, false]
|
377
|
+
: psbt.getSignatureValidationArray(i, { rootNodes: rootWalletKeys.triple });
|
378
|
+
return [i, sigValArrayForInput];
|
379
|
+
});
|
380
|
+
}
|
381
|
+
exports.getSignatureValidationArrayPsbt = getSignatureValidationArrayPsbt;
|
382
|
+
/**
|
383
|
+
* Extracts the half signed transaction from the psbt for p2ms based script types - p2sh, p2wsh, and p2shP2wsh.
|
384
|
+
* The purpose is to provide backward compatibility to keyternal (KRS) that only supports network transaction and p2ms script types.
|
385
|
+
*/
|
386
|
+
function extractP2msOnlyHalfSignedTx(psbt) {
|
387
|
+
assert(!!(psbt.data.inputs.length && psbt.data.outputs.length), 'empty inputs or outputs');
|
388
|
+
const tx = psbt.getUnsignedTx();
|
389
|
+
function isP2msParsedPsbtInput(parsed) {
|
390
|
+
return ['p2sh', 'p2shP2wsh', 'p2wsh'].includes(parsed.scriptType);
|
228
391
|
}
|
229
|
-
|
392
|
+
psbt.data.inputs.forEach((input, i) => {
|
393
|
+
const parsed = parsePsbtInput(input);
|
394
|
+
assert(isP2msParsedPsbtInput(parsed), `unsupported script type ${parsed.scriptType}`);
|
395
|
+
assert(input.partialSig?.length === 1, `unexpected signature count ${input.partialSig?.length}`);
|
396
|
+
const [partialSig] = input.partialSig;
|
397
|
+
assert(input.sighashType !== undefined && input.sighashType === bitcoinjs_lib_1.script.signature.decode(partialSig.signature).hashType, 'signature sighash does not match input sighash type');
|
398
|
+
// type casting is to address the invalid type checking in payments.p2ms
|
399
|
+
const signatures = parsed.publicKeys.map((pk) => partialSig.pubkey.equals(pk) ? partialSig.signature : bitcoinjs_lib_1.opcodes.OP_0);
|
400
|
+
const isP2SH = !!parsed.redeemScript;
|
401
|
+
const isP2WSH = !!parsed.witnessScript;
|
402
|
+
const payment = index_1.payments.p2ms({ output: parsed.pubScript, signatures }, { validate: false, allowIncomplete: true });
|
403
|
+
const p2wsh = isP2WSH ? index_1.payments.p2wsh({ redeem: payment }) : undefined;
|
404
|
+
const p2sh = isP2SH ? index_1.payments.p2sh({ redeem: p2wsh || payment }) : undefined;
|
405
|
+
if (p2sh?.input) {
|
406
|
+
tx.setInputScript(i, p2sh.input);
|
407
|
+
}
|
408
|
+
if (p2wsh?.witness) {
|
409
|
+
tx.setWitness(i, p2wsh.witness);
|
410
|
+
}
|
411
|
+
});
|
412
|
+
return tx;
|
230
413
|
}
|
231
|
-
exports.
|
232
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUHNidC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvUHNidC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSxvREFNMEI7QUFFMUIsd0NBQW9EO0FBQ3BELGdEQUEyRDtBQUUzRCx1Q0FBMkQ7QUFDM0QsZ0RBQXFEO0FBRXJELDhDQU91QjtBQXFCdkIsU0FB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QU0JUIHBhcnNpbmcgaXMgbm90IHN1cHBvcnRlZCcpO1xuICB9XG4gIGNvbnN0IHNjcmlwdFR5cGUgPSBjbGFzc2lmeVNjcmlwdFR5cGUoaW5wdXQpO1xuICBpZiAoIXNjcmlwdFR5cGUpIHtcbiAgICBpZiAocHNidC5nZXRTaWduYXR1cmVDb3VudChpbnB1dEluZGV4KSA+IDApIHtcbiAgICAgIHRocm93IG5ldyBFcnJvcignSW52YWxpZCBQU0JUIHN0YXRlLiBTaWduYXR1cmVzIGZvdW5kIHdpdGhvdXQgc2NyaXB0cy4nKTtcbiAgICB9XG4gICAgcmV0dXJuIHVuZGVmaW5lZDtcbiAgfVxuICByZXR1cm4gcGFyc2VJbnB1dE1ldGFkYXRhKGlucHV0LCBzY3JpcHRUeXBlKTtcbn1cbiJdfQ==
|
414
|
+
exports.extractP2msOnlyHalfSignedTx = extractP2msOnlyHalfSignedTx;
|
415
|
+
/**
|
416
|
+
* Clones the psbt without nonWitnessUtxo for non-segwit inputs and witnessUtxo is added instead.
|
417
|
+
* It is not BIP-174 compliant, so use it carefully.
|
418
|
+
*/
|
419
|
+
function clonePsbtWithoutNonWitnessUtxo(psbt) {
|
420
|
+
const newPsbt = psbt.clone();
|
421
|
+
const txInputs = psbt.txInputs;
|
422
|
+
psbt.data.inputs.forEach((input, i) => {
|
423
|
+
if (input.nonWitnessUtxo && !input.witnessUtxo) {
|
424
|
+
const tx = UtxoTransaction_1.UtxoTransaction.fromBuffer(input.nonWitnessUtxo, false, 'bigint', psbt.network);
|
425
|
+
if (!txInputs[i].hash.equals(tx.getHash())) {
|
426
|
+
throw new Error(`Non-witness UTXO hash for input #${i} doesn't match the hash specified in the prevout`);
|
427
|
+
}
|
428
|
+
newPsbt.data.inputs[i].witnessUtxo = tx.outs[txInputs[i].index];
|
429
|
+
}
|
430
|
+
delete newPsbt.data.inputs[i].nonWitnessUtxo;
|
431
|
+
});
|
432
|
+
return newPsbt;
|
433
|
+
}
|
434
|
+
exports.clonePsbtWithoutNonWitnessUtxo = clonePsbtWithoutNonWitnessUtxo;
|
435
|
+
/**
|
436
|
+
* Deletes witnessUtxo for non-segwit inputs to make the PSBT BIP-174 compliant.
|
437
|
+
*/
|
438
|
+
function deleteWitnessUtxoForNonSegwitInputs(psbt) {
|
439
|
+
psbt.data.inputs.forEach((input, i) => {
|
440
|
+
const scriptType = getPsbtInputScriptType(input);
|
441
|
+
if (scriptType === 'p2sh' || scriptType === 'p2shP2pk') {
|
442
|
+
delete input.witnessUtxo;
|
443
|
+
}
|
444
|
+
});
|
445
|
+
}
|
446
|
+
exports.deleteWitnessUtxoForNonSegwitInputs = deleteWitnessUtxoForNonSegwitInputs;
|
447
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUHNidC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy9iaXRnby93YWxsZXQvUHNidC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxpQ0FBaUM7QUFHakMsZ0RBQXFEO0FBRXJELHVDQUF1QztBQUN2QywwQ0FBdUM7QUFDdkMsd0RBQXFEO0FBQ3JELG9EQUE2RztBQUM3Ryw2Q0FBaUU7QUFDakUsd0NBQW9EO0FBQ3BELGdEQUEyRDtBQUMzRCx1Q0FBMkQ7QUFFM0QsOENBY3VCO0FBQ3ZCLHNDQUF1RDtBQUN2RCxvQ0FBMkM7QUFDM0MsMkNBQTBEO0FBQzFELGlEQUEyRTtBQUMzRSx1Q0FBZ0Q7QUFDaEQsMENBQStFO0FBcUUvRSxTQUFTLGlCQUFpQixDQUFDLE1BQWMsRUFBRSxVQUE2QjtJQUN0RSxNQUFNLGdCQUFnQixHQUFHLCtCQUFrQixDQUFDLE1BQU0sRUFBRSx3QkFBd0IsQ0FBQyxDQUFDLFVBQVUsQ0FBQztJQUN6RixNQUFNLGFBQWEsR0FBRyxnQkFBZ0IsQ0FBQ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