utxo-lib 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) 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 +91 -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 +651 -107
  16. package/dist/src/bitgo/bitcoincash/address.js +2 -2
  17. package/dist/src/bitgo/index.d.ts +11 -0
  18. package/dist/src/bitgo/index.d.ts.map +1 -1
  19. package/dist/src/bitgo/index.js +6 -2
  20. package/dist/src/bitgo/legacysafe/index.d.ts +15 -0
  21. package/dist/src/bitgo/legacysafe/index.d.ts.map +1 -0
  22. package/dist/src/bitgo/legacysafe/index.js +61 -0
  23. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts +10 -0
  24. package/dist/src/bitgo/litecoin/LitecoinPsbt.d.ts.map +1 -0
  25. package/dist/src/bitgo/litecoin/LitecoinPsbt.js +17 -0
  26. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts +16 -0
  27. package/dist/src/bitgo/litecoin/LitecoinTransaction.d.ts.map +1 -0
  28. package/dist/src/bitgo/litecoin/LitecoinTransaction.js +46 -0
  29. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts +10 -0
  30. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.d.ts.map +1 -0
  31. package/dist/src/bitgo/litecoin/LitecoinTransactionBuilder.js +15 -0
  32. package/dist/src/bitgo/litecoin/index.d.ts +4 -0
  33. package/dist/src/bitgo/litecoin/index.d.ts.map +1 -0
  34. package/dist/src/bitgo/litecoin/index.js +16 -0
  35. package/dist/src/bitgo/outputScripts.d.ts +3 -1
  36. package/dist/src/bitgo/outputScripts.d.ts.map +1 -1
  37. package/dist/src/bitgo/outputScripts.js +18 -10
  38. package/dist/src/bitgo/parseInput.d.ts +49 -20
  39. package/dist/src/bitgo/parseInput.d.ts.map +1 -1
  40. package/dist/src/bitgo/parseInput.js +109 -25
  41. package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -1
  42. package/dist/src/bitgo/psbt/fromHalfSigned.js +9 -6
  43. package/dist/src/bitgo/signature.d.ts +3 -3
  44. package/dist/src/bitgo/signature.d.ts.map +1 -1
  45. package/dist/src/bitgo/signature.js +48 -16
  46. package/dist/src/bitgo/transaction.d.ts +18 -3
  47. package/dist/src/bitgo/transaction.d.ts.map +1 -1
  48. package/dist/src/bitgo/transaction.js +28 -15
  49. package/dist/src/bitgo/types.d.ts +2 -0
  50. package/dist/src/bitgo/types.d.ts.map +1 -1
  51. package/dist/src/bitgo/types.js +1 -1
  52. package/dist/src/bitgo/wallet/Psbt.d.ts +104 -12
  53. package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -1
  54. package/dist/src/bitgo/wallet/Psbt.js +285 -70
  55. package/dist/src/bitgo/wallet/Unspent.d.ts +28 -0
  56. package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -1
  57. package/dist/src/bitgo/wallet/Unspent.js +172 -68
  58. package/dist/src/bitgo/wallet/WalletOutput.d.ts +17 -1
  59. package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -1
  60. package/dist/src/bitgo/wallet/WalletOutput.js +64 -23
  61. package/dist/src/bitgo/wallet/chains.d.ts +2 -2
  62. package/dist/src/bitgo/wallet/chains.d.ts.map +1 -1
  63. package/dist/src/bitgo/wallet/chains.js +1 -1
  64. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +0 -1
  65. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -1
  66. package/dist/src/bitgo/zcash/ZcashPsbt.js +6 -14
  67. package/dist/src/musig.d.ts +0 -1
  68. package/dist/src/musig.d.ts.map +1 -1
  69. package/dist/src/musig.js +15 -29
  70. package/dist/src/networks.d.ts +1 -2
  71. package/dist/src/networks.d.ts.map +1 -1
  72. package/dist/src/networks.js +22 -29
  73. package/dist/src/noble_ecc.d.ts.map +1 -1
  74. package/dist/src/noble_ecc.js +7 -3
  75. package/dist/src/payments/p2tr.d.ts.map +1 -1
  76. package/dist/src/payments/p2tr.js +15 -9
  77. package/dist/src/taproot.d.ts +16 -0
  78. package/dist/src/taproot.d.ts.map +1 -1
  79. package/dist/src/taproot.js +44 -2
  80. package/dist/src/testutil/index.d.ts +2 -0
  81. package/dist/src/testutil/index.d.ts.map +1 -1
  82. package/dist/src/testutil/index.js +3 -1
  83. package/dist/src/testutil/keys.d.ts +3 -0
  84. package/dist/src/testutil/keys.d.ts.map +1 -1
  85. package/dist/src/testutil/keys.js +17 -2
  86. package/dist/src/testutil/mock.d.ts +1 -1
  87. package/dist/src/testutil/mock.d.ts.map +1 -1
  88. package/dist/src/testutil/mock.js +12 -4
  89. package/dist/src/testutil/psbt.d.ts +89 -0
  90. package/dist/src/testutil/psbt.d.ts.map +1 -0
  91. package/dist/src/testutil/psbt.js +150 -0
  92. package/dist/src/testutil/transaction.d.ts +70 -0
  93. package/dist/src/testutil/transaction.d.ts.map +1 -0
  94. package/dist/src/testutil/transaction.js +107 -0
  95. package/package.json +6 -6
@@ -11,6 +11,8 @@ import { UtxoPsbt } from '../UtxoPsbt';
11
11
  export interface WalletUnspent<TNumber extends number | bigint = number> extends Unspent<TNumber> {
12
12
  chain: ChainCode;
13
13
  index: number;
14
+ witnessScript?: string;
15
+ valueString?: string;
14
16
  }
15
17
  export interface NonWitnessWalletUnspent<TNumber extends number | bigint = number> extends UnspentWithPrevTx<TNumber>, WalletUnspent<TNumber> {
16
18
  }
@@ -34,11 +36,37 @@ export interface WalletUnspentLegacy<TNumber extends number | bigint = number> e
34
36
  /** @deprecated - obviated by verifyWithUnspent */
35
37
  witnessScript?: string;
36
38
  }
39
+ /**
40
+ * @param psbt
41
+ * @param inputIndex
42
+ * @param id Unspent ID
43
+ * @returns true iff the unspent ID on the unspent and psbt input match
44
+ */
45
+ export declare function psbtIncludesUnspentAtIndex(psbt: UtxoPsbt, inputIndex: number, id: string): boolean;
46
+ /**
47
+ * Update the psbt input at the given index
48
+ * @param psbt
49
+ * @param inputIndex
50
+ * @param u
51
+ * @param redeemScript Only overrides if there is no redeemScript in the input currently
52
+ */
53
+ export declare function updateReplayProtectionUnspentToPsbt(psbt: UtxoPsbt, inputIndex: number, u: Unspent<bigint>, redeemScript?: Buffer): void;
37
54
  export declare function addReplayProtectionUnspentToPsbt(psbt: UtxoPsbt, u: Unspent<bigint>, redeemScript: Buffer,
38
55
  /**
39
56
  * @deprecated
40
57
  */
41
58
  network?: Network): void;
59
+ /**
60
+ * Update the PSBT with the unspent data for the input at the given index if the data is not there already.
61
+ *
62
+ * @param psbt
63
+ * @param inputIndex
64
+ * @param u
65
+ * @param rootWalletKeys
66
+ * @param signer
67
+ * @param cosigner
68
+ */
69
+ export declare function updateWalletUnspentForPsbt(psbt: UtxoPsbt, inputIndex: number, u: WalletUnspent<bigint>, rootWalletKeys: RootWalletKeys, signer: KeyName, cosigner: KeyName): void;
42
70
  export declare function addWalletUnspentToPsbt(psbt: UtxoPsbt, u: WalletUnspent<bigint>, rootWalletKeys: RootWalletKeys, signer: KeyName, cosigner: KeyName,
43
71
  /**
44
72
  * @deprecated
@@ -1 +1 @@
1
- {"version":3,"file":"Unspent.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/Unspent.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,OAAO,EAAY,MAAM,OAAO,CAAC;AACtD,OAAO,E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AAE,SAAQ,aAAa,CAAC,OAAO,CAAC;IAC3G,gDAAgD;IAChD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAMlG;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,MAAM,EAClB,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAClB,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,CAuBN;AAUD,wBAAgB,gCAAgC,CAC9C,IAAI,EAAE,QAAQ,EACd,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAClB,YAAY,EAAE,MAAM;AACpB;;GAEG;AACH,OAAO,GAAE,OAAsB,GAC9B,IAAI,CAMN;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,MAAM,EAClB,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO,GAChB,IAAI,CA0HN;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,QAAQ,EACd,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,EACxB,cAAc,EAAE,cAAc,EAC9B,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,OAAO;AACjB;;GAEG;AACH,OAAO,GAAE,OAAsB,GAC9B,IAAI,CAMN"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addWalletUnspentToPsbt = exports.addReplayProtectionUnspentToPsbt = exports.verifySignatureWithUnspent = exports.signInputWithUnspent = exports.isWalletUnspent = void 0;
3
+ exports.addWalletUnspentToPsbt = exports.updateWalletUnspentForPsbt = exports.addReplayProtectionUnspentToPsbt = exports.updateReplayProtectionUnspentToPsbt = exports.psbtIncludesUnspentAtIndex = exports.verifySignatureWithUnspent = exports.signInputWithUnspent = exports.isWalletUnspent = void 0;
4
4
  const __1 = require("../..");
5
5
  const outputScripts_1 = require("../outputScripts");
6
6
  const address_1 = require("../../address");
@@ -8,6 +8,10 @@ const signature_1 = require("../signature");
8
8
  const Unspent_1 = require("../Unspent");
9
9
  const chains_1 = require("./chains");
10
10
  const Musig2_1 = require("../Musig2");
11
+ const transaction_1 = require("../transaction");
12
+ const parseInput_1 = require("../parseInput");
13
+ const utils_1 = require("bip174/src/lib/utils");
14
+ const PsbtUtil_1 = require("../PsbtUtil");
11
15
  function isWalletUnspent(u) {
12
16
  return u.chain !== undefined;
13
17
  }
@@ -34,121 +38,221 @@ function verifySignatureWithUnspent(tx, inputIndex, unspents, walletKeys) {
34
38
  if (tx.ins.length !== unspents.length) {
35
39
  throw new Error(`input length must match unspents length`);
36
40
  }
41
+ const input = tx.ins[inputIndex];
42
+ /* istanbul ignore next */
43
+ if (!input) {
44
+ throw new Error(`no input at index ${inputIndex}`);
45
+ }
37
46
  const unspent = unspents[inputIndex];
38
- if (!isWalletUnspent(unspent)) {
47
+ if (!isWalletUnspent(unspent) || (!input.script?.length && !input.witness?.length)) {
39
48
  return [false, false, false];
40
49
  }
41
- return signature_1.verifySignatureWithPublicKeys(tx, inputIndex, unspents.map((u) => Unspent_1.toOutput(u, tx.network)), walletKeys.deriveForChainAndIndex(unspent.chain, unspent.index).publicKeys);
50
+ const parsedInput = parseInput_1.parseSignatureScript(input);
51
+ const prevOutputs = unspents.map((u) => Unspent_1.toOutput(u, tx.network));
52
+ // If it is a taproot keyPathSpend input, the only valid signature combinations is user-bitgo. We can
53
+ // only verify that the aggregated signature is valid, not that the individual partial-signature is valid.
54
+ // Therefore, we can only say that either all partial signatures are valid, or none are.
55
+ if (parsedInput.scriptType === 'taprootKeyPathSpend') {
56
+ const result = signature_1.getSignatureVerifications(tx, inputIndex, unspent.value, undefined, prevOutputs);
57
+ return result.length === 1 && result[0].signature ? [true, false, true] : [false, false, false];
58
+ }
59
+ return signature_1.verifySignatureWithPublicKeys(tx, inputIndex, prevOutputs, walletKeys.deriveForChainAndIndex(unspent.chain, unspent.index).publicKeys);
42
60
  }
43
61
  exports.verifySignatureWithUnspent = verifySignatureWithUnspent;
44
- function addReplayProtectionUnspentToPsbt(psbt, u, redeemScript,
45
62
  /**
46
- * @deprecated
63
+ * @param psbt
64
+ * @param inputIndex
65
+ * @param id Unspent ID
66
+ * @returns true iff the unspent ID on the unspent and psbt input match
47
67
  */
48
- network = psbt.network) {
49
- if (network !== psbt.network) {
50
- throw new Error(`network parameter does not match psbt.network`);
68
+ function psbtIncludesUnspentAtIndex(psbt, inputIndex, id) {
69
+ utils_1.checkForInput(psbt.data.inputs, inputIndex);
70
+ const { txid, vout } = Unspent_1.parseOutputId(id);
71
+ const psbtOutPoint = Unspent_1.getOutputIdForInput(psbt.txInputs[inputIndex]);
72
+ return psbtOutPoint.txid === txid && psbtOutPoint.vout === vout;
73
+ }
74
+ exports.psbtIncludesUnspentAtIndex = psbtIncludesUnspentAtIndex;
75
+ /**
76
+ * Update the psbt input at the given index
77
+ * @param psbt
78
+ * @param inputIndex
79
+ * @param u
80
+ * @param redeemScript Only overrides if there is no redeemScript in the input currently
81
+ */
82
+ function updateReplayProtectionUnspentToPsbt(psbt, inputIndex, u, redeemScript) {
83
+ if (!psbtIncludesUnspentAtIndex(psbt, inputIndex, u.id)) {
84
+ throw new Error(`unspent does not correspond to psbt input`);
85
+ }
86
+ const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
87
+ if (redeemScript && !input.redeemScript) {
88
+ psbt.updateInput(inputIndex, { redeemScript });
51
89
  }
52
- const { txid, vout } = Unspent_1.toPrevOutput(u, psbt.network);
53
- const isZcash = __1.getMainnet(psbt.network) !== __1.networks.zcash;
54
90
  // Because Zcash directly hashes the value for non-segwit transactions, we do not need to check indirectly
55
91
  // with the previous transaction. Therefore, we can treat Zcash non-segwit transactions as Bitcoin
56
92
  // segwit transactions
93
+ const isZcash = __1.getMainnet(psbt.network) === __1.networks.zcash;
57
94
  if (!Unspent_1.isUnspentWithPrevTx(u) && !isZcash) {
58
95
  throw new Error('Error, require previous tx to add to PSBT');
59
96
  }
97
+ if (isZcash && !input.witnessUtxo) {
98
+ const { script, value } = Unspent_1.toPrevOutput(u, psbt.network);
99
+ psbt.updateInput(inputIndex, { witnessUtxo: { script, value } });
100
+ }
101
+ else if (!isZcash && !input.nonWitnessUtxo) {
102
+ psbt.updateInput(inputIndex, { nonWitnessUtxo: u.prevTx });
103
+ }
104
+ }
105
+ exports.updateReplayProtectionUnspentToPsbt = updateReplayProtectionUnspentToPsbt;
106
+ function addUnspentToPsbt(psbt, id) {
107
+ const { txid, vout } = Unspent_1.parseOutputId(id);
60
108
  psbt.addInput({
61
109
  hash: txid,
62
110
  index: vout,
63
- redeemScript,
64
111
  });
65
- if (!isZcash) {
66
- psbt.updateInput(vout, { nonWitnessUtxo: u.prevTx });
67
- }
68
112
  }
69
- exports.addReplayProtectionUnspentToPsbt = addReplayProtectionUnspentToPsbt;
70
- function addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signer, cosigner,
113
+ function addReplayProtectionUnspentToPsbt(psbt, u, redeemScript,
71
114
  /**
72
115
  * @deprecated
73
116
  */
74
117
  network = psbt.network) {
75
- if (network !== psbt.network) {
76
- throw new Error(`network parameter does not match psbt.network`);
118
+ if (psbt.network !== network) {
119
+ throw new Error('psbt network does not match network');
77
120
  }
78
- const { txid, vout, script, value } = Unspent_1.toPrevOutput(u, psbt.network);
79
- const walletKeys = rootWalletKeys.deriveForChainAndIndex(u.chain, u.index);
80
- const scriptType = outputScripts_1.scriptTypeForChain(u.chain);
81
- psbt.addInput({
82
- hash: txid,
83
- index: vout,
84
- witnessUtxo: {
85
- script,
86
- value,
87
- },
88
- });
89
- const inputIndex = psbt.inputCount - 1;
121
+ addUnspentToPsbt(psbt, u.id);
122
+ updateReplayProtectionUnspentToPsbt(psbt, psbt.inputCount - 1, u, redeemScript);
123
+ }
124
+ exports.addReplayProtectionUnspentToPsbt = addReplayProtectionUnspentToPsbt;
125
+ /**
126
+ * Update the PSBT with the unspent data for the input at the given index if the data is not there already.
127
+ *
128
+ * @param psbt
129
+ * @param inputIndex
130
+ * @param u
131
+ * @param rootWalletKeys
132
+ * @param signer
133
+ * @param cosigner
134
+ */
135
+ function updateWalletUnspentForPsbt(psbt, inputIndex, u, rootWalletKeys, signer, cosigner) {
136
+ if (!psbtIncludesUnspentAtIndex(psbt, inputIndex, u.id)) {
137
+ throw new Error(`unspent does not correspond to psbt input`);
138
+ }
139
+ const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
90
140
  // Because Zcash directly hashes the value for non-segwit transactions, we do not need to check indirectly
91
141
  // with the previous transaction. Therefore, we can treat Zcash non-segwit transactions as Bitcoin
92
142
  // segwit transactions
93
- if (!chains_1.isSegwit(u.chain) && __1.getMainnet(psbt.network) !== __1.networks.zcash) {
143
+ const isZcashOrSegwit = chains_1.isSegwit(u.chain) || __1.getMainnet(psbt.network) === __1.networks.zcash;
144
+ if (isZcashOrSegwit && !input.witnessUtxo) {
145
+ const { script, value } = Unspent_1.toPrevOutput(u, psbt.network);
146
+ psbt.updateInput(inputIndex, { witnessUtxo: { script, value } });
147
+ }
148
+ else if (!isZcashOrSegwit) {
94
149
  if (!Unspent_1.isUnspentWithPrevTx(u)) {
95
150
  throw new Error('Error, require previous tx to add to PSBT');
96
151
  }
97
- psbt.updateInput(inputIndex, { nonWitnessUtxo: u.prevTx });
152
+ if (!input.witnessUtxo && !input.nonWitnessUtxo) {
153
+ // Force the litecoin transaction to have no MWEB advanced transaction flag
154
+ if (__1.getMainnet(psbt.network) === __1.networks.litecoin) {
155
+ u.prevTx = transaction_1.createTransactionFromBuffer(u.prevTx, psbt.network, { amountType: 'bigint' }).toBuffer();
156
+ }
157
+ psbt.updateInput(inputIndex, { nonWitnessUtxo: u.prevTx });
158
+ }
159
+ }
160
+ const walletKeys = rootWalletKeys.deriveForChainAndIndex(u.chain, u.index);
161
+ const scriptType = outputScripts_1.scriptTypeForChain(u.chain);
162
+ const sighashType = signature_1.getDefaultSigHash(psbt.network, scriptType);
163
+ if (psbt.data.inputs[inputIndex].sighashType === undefined) {
164
+ psbt.updateInput(inputIndex, { sighashType });
98
165
  }
99
166
  const isBackupFlow = signer === 'backup' || cosigner === 'backup';
100
167
  if (scriptType === 'p2tr' || (scriptType === 'p2trMusig2' && isBackupFlow)) {
168
+ if (input.tapLeafScript && input.tapBip32Derivation) {
169
+ return;
170
+ }
101
171
  const createSpendScriptP2trFn = scriptType === 'p2tr' ? outputScripts_1.createSpendScriptP2tr : outputScripts_1.createSpendScriptP2trMusig2;
102
172
  const { controlBlock, witnessScript, leafVersion, leafHash } = createSpendScriptP2trFn(walletKeys.publicKeys, [
103
173
  walletKeys[signer].publicKey,
104
174
  walletKeys[cosigner].publicKey,
105
175
  ]);
106
- psbt.updateInput(inputIndex, {
107
- tapLeafScript: [{ controlBlock, script: witnessScript, leafVersion }],
108
- tapBip32Derivation: [signer, cosigner].map((key) => ({
109
- leafHashes: [leafHash],
110
- pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
111
- path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
112
- masterFingerprint: rootWalletKeys[key].fingerprint,
113
- })),
114
- });
176
+ if (!input.tapLeafScript) {
177
+ psbt.updateInput(inputIndex, {
178
+ tapLeafScript: [{ controlBlock, script: witnessScript, leafVersion }],
179
+ });
180
+ }
181
+ if (!input.tapBip32Derivation) {
182
+ psbt.updateInput(inputIndex, {
183
+ tapBip32Derivation: [signer, cosigner].map((key) => ({
184
+ leafHashes: [leafHash],
185
+ pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
186
+ path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
187
+ masterFingerprint: rootWalletKeys[key].fingerprint,
188
+ })),
189
+ });
190
+ }
115
191
  }
116
192
  else if (scriptType === 'p2trMusig2') {
117
193
  const { internalPubkey: tapInternalKey, outputPubkey: tapOutputKey, taptreeRoot, } = outputScripts_1.createKeyPathP2trMusig2(walletKeys.publicKeys);
118
- const participantPubKeys = [walletKeys.user.publicKey, walletKeys.bitgo.publicKey];
119
- const participantsKeyValData = Musig2_1.encodePsbtMusig2ParticipantsKeyValData({
120
- tapOutputKey,
121
- tapInternalKey,
122
- participantPubKeys,
123
- });
124
- psbt.addProprietaryKeyValToInput(inputIndex, participantsKeyValData);
125
- psbt.updateInput(inputIndex, {
126
- tapInternalKey: tapInternalKey,
127
- tapMerkleRoot: taptreeRoot,
128
- tapBip32Derivation: [signer, cosigner].map((key) => ({
129
- leafHashes: [],
130
- pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
131
- path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
132
- masterFingerprint: rootWalletKeys[key].fingerprint,
133
- })),
134
- });
194
+ if (psbt.getProprietaryKeyVals(inputIndex, {
195
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
196
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
197
+ }).length === 0) {
198
+ const participantsKeyValData = Musig2_1.encodePsbtMusig2Participants({
199
+ tapOutputKey,
200
+ tapInternalKey,
201
+ participantPubKeys: [walletKeys.user.publicKey, walletKeys.bitgo.publicKey],
202
+ });
203
+ psbt.addProprietaryKeyValToInput(inputIndex, participantsKeyValData);
204
+ }
205
+ if (!input.tapInternalKey) {
206
+ psbt.updateInput(inputIndex, {
207
+ tapInternalKey: tapInternalKey,
208
+ });
209
+ }
210
+ if (!input.tapMerkleRoot) {
211
+ psbt.updateInput(inputIndex, {
212
+ tapMerkleRoot: taptreeRoot,
213
+ });
214
+ }
215
+ if (!input.tapBip32Derivation) {
216
+ psbt.updateInput(inputIndex, {
217
+ tapBip32Derivation: [signer, cosigner].map((key) => ({
218
+ leafHashes: [],
219
+ pubkey: outputScripts_1.toXOnlyPublicKey(walletKeys[key].publicKey),
220
+ path: rootWalletKeys.getDerivationPath(rootWalletKeys[key], u.chain, u.index),
221
+ masterFingerprint: rootWalletKeys[key].fingerprint,
222
+ })),
223
+ });
224
+ }
135
225
  }
136
226
  else {
227
+ if (!input.bip32Derivation) {
228
+ psbt.updateInput(inputIndex, {
229
+ bip32Derivation: [0, 1, 2].map((idx) => ({
230
+ pubkey: walletKeys.triple[idx].publicKey,
231
+ path: walletKeys.paths[idx],
232
+ masterFingerprint: rootWalletKeys.triple[idx].fingerprint,
233
+ })),
234
+ });
235
+ }
137
236
  const { witnessScript, redeemScript } = outputScripts_1.createOutputScript2of3(walletKeys.publicKeys, scriptType);
138
- psbt.updateInput(inputIndex, {
139
- bip32Derivation: [0, 1, 2].map((idx) => ({
140
- pubkey: walletKeys.triple[idx].publicKey,
141
- path: walletKeys.paths[idx],
142
- masterFingerprint: rootWalletKeys.triple[idx].fingerprint,
143
- })),
144
- });
145
- if (witnessScript) {
237
+ if (witnessScript && !input.witnessScript) {
146
238
  psbt.updateInput(inputIndex, { witnessScript });
147
239
  }
148
- if (redeemScript) {
240
+ if (redeemScript && !input.redeemScript) {
149
241
  psbt.updateInput(inputIndex, { redeemScript });
150
242
  }
151
243
  }
152
244
  }
245
+ exports.updateWalletUnspentForPsbt = updateWalletUnspentForPsbt;
246
+ function addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signer, cosigner,
247
+ /**
248
+ * @deprecated
249
+ */
250
+ network = psbt.network) {
251
+ if (psbt.network !== network) {
252
+ throw new Error('psbt network does not match network');
253
+ }
254
+ addUnspentToPsbt(psbt, u.id);
255
+ updateWalletUnspentForPsbt(psbt, psbt.inputCount - 1, u, rootWalletKeys, signer, cosigner);
256
+ }
153
257
  exports.addWallet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nRpY2lwYW50c0tleVZhbERhdGEpO1xuICAgIH1cblxuICAgIGlmICghaW5wdXQudGFwSW50ZXJuYWxLZXkpIHtcbiAgICAgIHBzYnQudXBkYXRlSW5wdXQoaW5wdXRJbmRleCwge1xuICAgICAgICB0YXBJbnRlcm5hbEtleTogdGFwSW50ZXJuYWxLZXksXG4gICAgICB9KTtcbiAgICB9XG5cbiAgICBpZiAoIWlucHV0LnRhcE1lcmtsZVJvb3QpIHtcbiAgICAgIHBzYnQudXBkYXRlSW5wdXQoaW5wdXRJbmRleCwge1xuICAgICAgICB0YXBNZXJrbGVSb290OiB0YXB0cmVlUm9vdCxcbiAgICAgIH0pO1xuICAgIH1cblxuICAgIGlmICghaW5wdXQudGFwQmlwMzJEZXJpdmF0aW9uKSB7XG4gICAgICBwc2J0LnVwZGF0ZUlucHV0KGlucHV0SW5kZXgsIHtcbiAgICAgICAgdGFwQmlwMzJEZXJpdmF0aW9uOiBbc2lnbmVyLCBjb3NpZ25lcl0ubWFwKChrZXkpID0+ICh7XG4gICAgICAgICAgbGVhZkhhc2hlczogW10sXG4gICAgICAgICAgcHVia2V5OiB0b1hPbmx5UHVibGljS2V5KHdhbGxldEtleXNba2V5XS5wdWJsaWNLZXkpLFxuICAgICAgICAgIHBhdGg6IHJvb3RXYWxsZXRLZXlzLmdldERlcml2YXRpb25QYXRoKHJvb3RXYWxsZXRLZXlzW2tleV0sIHUuY2hhaW4sIHUuaW5kZXgpLFxuICAgICAgICAgIG1hc3RlckZpbmdlcnByaW50OiByb290V2FsbGV0S2V5c1trZXldLmZpbmdlcnByaW50LFxuICAgICAgICB9KSksXG4gICAgICB9KTtcbiAgICB9XG4gIH0gZWxzZSB7XG4gICAgaWYgKCFpbnB1dC5iaXAzMkRlcml2YXRpb24pIHtcbiAgICAgIHBzYnQudXBkYXRlSW5wdXQoaW5wdXRJbmRleCwge1xuICAgICAgICBiaXAzMkRlcml2YXRpb246IFswLCAxLCAyXS5tYXAoKGlkeCkgPT4gKHtcb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XJyb3IoJ3BzYnQgbmV0d29yayBkb2VzIG5vdCBtYXRjaCBuZXR3b3JrJyk7XG4gIH1cbiAgYWRkVW5zcGVudFRvUHNidChwc2J0LCB1LmlkKTtcbiAgdXBkYXRlV2FsbGV0VW5zcGVudEZvclBzYnQocHNidCwgcHNidC5pbnB1dENvdW50IC0gMSwgdSwgcm9vdFdhbGxldEtleXMsIHNpZ25lciwgY29zaWduZXIpO1xufVxuIl19
@@ -4,7 +4,7 @@ import { ChainCode } from './chains';
4
4
  /**
5
5
  * Add a verifiable wallet output to the PSBT. The output and all data
6
6
  * needed to verify it from public keys only are added to the PSBT.
7
- * Typically these are change outputs
7
+ * Typically these are change outputs.
8
8
  *
9
9
  * @param psbt the PSBT to add change output to
10
10
  * @param rootWalletKeys keys that will be able to spend the output
@@ -15,4 +15,20 @@ import { ChainCode } from './chains';
15
15
  * @param value value of the change output
16
16
  */
17
17
  export declare function addWalletOutputToPsbt(psbt: UtxoPsbt, rootWalletKeys: RootWalletKeys, chain: ChainCode, index: number, value: bigint): void;
18
+ /**
19
+ * Update the wallet output with the required information when necessary. If the
20
+ * information is there already, it will skip over it.
21
+ *
22
+ * This function assumes that the output script and value have already been set.
23
+ *
24
+ * @param psbt the PSBT to update change output at
25
+ * @param rootWalletKeys keys that will be able to spend the output
26
+ * @param outputIndex output index where to update the output
27
+ * @param chain chain code to use for deriving scripts (and to determine script
28
+ * type) chain is an API parameter in the BitGo API, and may be
29
+ * any valid ChainCode
30
+ * @param index derivation index for the change address
31
+ * @param value value of the change output
32
+ */
33
+ export declare function updateWalletOutputForPsbt(psbt: UtxoPsbt, rootWalletKeys: RootWalletKeys, outputIndex: number, chain: ChainCode, index: number): void;
18
34
  //# sourceMappingURL=WalletOutput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WalletOutput.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,EACd,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAgDN"}
1
+ {"version":3,"file":"WalletOutput.d.ts","sourceRoot":"","sources":["../../../../src/bitgo/wallet/WalletOutput.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAsB,MAAM,UAAU,CAAC;AAGzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,QAAQ,EACd,cAAc,EAAE,cAAc,EAC9B,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,IAAI,CAYN;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,QAAQ,EACd,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,MAAM,GACZ,IAAI,CAgEN"}