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,55 +1,112 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setMusig2Nonces = exports.createTapOutputKey = exports.createTapInternalKey = exports.decodePsbtMusig2ParticipantsKeyValData = exports.encodePsbtMusig2PubNonceKeyValData = exports.encodePsbtMusig2ParticipantsKeyValData = void 0;
4
- const UtxoPsbt_1 = require("./UtxoPsbt");
3
+ exports.musig2DeterministicSign = exports.createMusig2DeterministicNonce = exports.getSigHashTypeFromSigs = exports.assertPsbtMusig2Nonces = exports.assertPsbtMusig2Participants = exports.parsePsbtMusig2PartialSigs = exports.parsePsbtMusig2Nonces = exports.parsePsbtMusig2Participants = exports.createMusig2SigningSession = exports.musig2AggregateSigs = exports.musig2PartialSigVerify = exports.musig2PartialSign = exports.createTapTweak = exports.createAggregateNonce = exports.createTapOutputKey = exports.createTapInternalKey = exports.decodePsbtMusig2PartialSig = exports.decodePsbtMusig2Nonce = exports.decodePsbtMusig2Participants = exports.encodePsbtMusig2PartialSig = exports.encodePsbtMusig2PubNonce = exports.encodePsbtMusig2Participants = exports.Musig2NonceStore = void 0;
5
4
  const outputScripts_1 = require("./outputScripts");
6
5
  const noble_ecc_1 = require("../noble_ecc");
7
6
  const taproot_1 = require("../taproot");
8
- const utils_1 = require("bip174/src/lib/utils");
7
+ const index_1 = require("../index");
8
+ const PsbtUtil_1 = require("./PsbtUtil");
9
+ /**
10
+ * Because musig uses reference-equal buffers to cache nonces, we wrap it here to allow using
11
+ * nonces that are byte-equal but not reference-equal.
12
+ */
13
+ class Musig2NonceStore {
14
+ constructor() {
15
+ this.nonces = [];
16
+ }
17
+ /**
18
+ * Get original Buffer instance for nonce (which may be a copy).
19
+ * @return byte-equal buffer that is reference-equal to what was stored earlier in createMusig2Nonce
20
+ */
21
+ getRef(nonce) {
22
+ for (const b of this.nonces) {
23
+ if (Buffer.from(b).equals(nonce)) {
24
+ return b;
25
+ }
26
+ }
27
+ throw new Error(`unknown nonce`);
28
+ }
29
+ /**
30
+ * Creates musig2 nonce and stores buffer reference.
31
+ * tapInternalkey, tapMerkleRoot, tapBip32Derivation for rootWalletKey are required per p2trMusig2 key path input.
32
+ * Also participant keys are required from psbt proprietary key values.
33
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
34
+ * @param privateKey - signer private key
35
+ * @param publicKey - signer xy public key
36
+ * @param xOnlyPublicKey - tweaked aggregated key (tapOutputKey)
37
+ * @param sessionId Additional entropy. If provided it must either be a counter unique to this secret key,
38
+ * (converted to an array of 32 bytes), or 32 uniformly random bytes.
39
+ */
40
+ createMusig2Nonce(privateKey, publicKey, xOnlyPublicKey, txHash, sessionId) {
41
+ if (txHash.length != 32) {
42
+ throw new Error(`Invalid txHash size ${txHash}`);
43
+ }
44
+ const buf = noble_ecc_1.musig.nonceGen({ secretKey: privateKey, publicKey, xOnlyPublicKey, msg: txHash, sessionId });
45
+ this.nonces.push(buf);
46
+ return buf;
47
+ }
48
+ }
49
+ exports.Musig2NonceStore = Musig2NonceStore;
9
50
  /**
10
51
  * Psbt proprietary key val util function for participants pub keys. SubType is 0x01
11
52
  * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
12
53
  * @return x-only tapOutputKey||tapInternalKey as sub keydata, plain sigining participant keys as valuedata
13
54
  */
14
- function encodePsbtMusig2ParticipantsKeyValData(participantsKeyValData) {
15
- const keydata = [participantsKeyValData.tapOutputKey, participantsKeyValData.tapInternalKey].map((pubkey) => outputScripts_1.checkXOnlyPublicKey(pubkey));
16
- const value = participantsKeyValData.participantPubKeys.map((pubkey) => outputScripts_1.checkPlainPublicKey(pubkey));
55
+ function encodePsbtMusig2Participants(participants) {
56
+ const keydata = [participants.tapOutputKey, participants.tapInternalKey].map((pubkey) => outputScripts_1.checkXOnlyPublicKey(pubkey));
57
+ const value = participants.participantPubKeys.map((pubkey) => outputScripts_1.checkPlainPublicKey(pubkey));
17
58
  const key = {
18
- identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
19
- subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
59
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
60
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
20
61
  keydata: Buffer.concat(keydata),
21
62
  };
22
63
  return { key, value: Buffer.concat(value) };
23
64
  }
24
- exports.encodePsbtMusig2ParticipantsKeyValData = encodePsbtMusig2ParticipantsKeyValData;
65
+ exports.encodePsbtMusig2Participants = encodePsbtMusig2Participants;
25
66
  /**
26
67
  * Psbt proprietary key val util function for pub nonce. SubType is 0x02
27
68
  * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
28
69
  * @return plain-participantPubKey||x-only-tapOutputKey as sub keydata, 66 bytes of 2 pub nonces as valuedata
29
70
  */
30
- function encodePsbtMusig2PubNonceKeyValData(noncesKeyValueData) {
31
- if (noncesKeyValueData.pubNonces.length !== 66) {
32
- throw new Error(`Invalid pubNonces length ${noncesKeyValueData.pubNonces.length}`);
71
+ function encodePsbtMusig2PubNonce(nonce) {
72
+ if (nonce.pubNonce.length !== 66) {
73
+ throw new Error(`Invalid pubNonces length ${nonce.pubNonce.length}`);
74
+ }
75
+ const keydata = Buffer.concat([
76
+ outputScripts_1.checkPlainPublicKey(nonce.participantPubKey),
77
+ outputScripts_1.checkXOnlyPublicKey(nonce.tapOutputKey),
78
+ ]);
79
+ const key = {
80
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
81
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PUB_NONCE,
82
+ keydata,
83
+ };
84
+ return { key, value: nonce.pubNonce };
85
+ }
86
+ exports.encodePsbtMusig2PubNonce = encodePsbtMusig2PubNonce;
87
+ function encodePsbtMusig2PartialSig(partialSig) {
88
+ if (partialSig.partialSig.length !== 32 && partialSig.partialSig.length !== 33) {
89
+ throw new Error(`Invalid partialSig length ${partialSig.partialSig.length}`);
33
90
  }
34
91
  const keydata = Buffer.concat([
35
- outputScripts_1.checkPlainPublicKey(noncesKeyValueData.participantPubKey),
36
- outputScripts_1.checkXOnlyPublicKey(noncesKeyValueData.tapOutputKey),
92
+ outputScripts_1.checkPlainPublicKey(partialSig.participantPubKey),
93
+ outputScripts_1.checkXOnlyPublicKey(partialSig.tapOutputKey),
37
94
  ]);
38
95
  const key = {
39
- identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
40
- subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PUB_NONCE,
96
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
97
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTIAL_SIG,
41
98
  keydata,
42
99
  };
43
- return { key, value: noncesKeyValueData.pubNonces };
100
+ return { key, value: partialSig.partialSig };
44
101
  }
45
- exports.encodePsbtMusig2PubNonceKeyValData = encodePsbtMusig2PubNonceKeyValData;
102
+ exports.encodePsbtMusig2PartialSig = encodePsbtMusig2PartialSig;
46
103
  /**
47
104
  * Decodes proprietary key value data for participant pub keys
48
105
  * @param kv
49
106
  */
50
- function decodePsbtMusig2ParticipantsKeyValData(kv) {
51
- if (kv.key.identifier !== UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER ||
52
- kv.key.subtype !== UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS) {
107
+ function decodePsbtMusig2Participants(kv) {
108
+ if (kv.key.identifier !== PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER ||
109
+ kv.key.subtype !== PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS) {
53
110
  throw new Error(`Invalid identifier ${kv.key.identifier} or subtype ${kv.key.subtype} for participants pub keys`);
54
111
  }
55
112
  const key = kv.key.keydata;
@@ -66,109 +123,235 @@ function decodePsbtMusig2ParticipantsKeyValData(kv) {
66
123
  }
67
124
  return { tapOutputKey: key.subarray(0, 32), tapInternalKey: key.subarray(32), participantPubKeys };
68
125
  }
69
- exports.decodePsbtMusig2ParticipantsKeyValData = decodePsbtMusig2ParticipantsKeyValData;
126
+ exports.decodePsbtMusig2Participants = decodePsbtMusig2Participants;
127
+ /**
128
+ * Decodes proprietary key value data for musig2 nonce
129
+ * @param kv
130
+ */
131
+ function decodePsbtMusig2Nonce(kv) {
132
+ if (kv.key.identifier !== PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER || kv.key.subtype !== PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PUB_NONCE) {
133
+ throw new Error(`Invalid identifier ${kv.key.identifier} or subtype ${kv.key.subtype} for nonce`);
134
+ }
135
+ const key = kv.key.keydata;
136
+ if (key.length !== 65) {
137
+ throw new Error(`Invalid keydata size ${key.length} for nonce`);
138
+ }
139
+ const value = kv.value;
140
+ if (value.length !== 66) {
141
+ throw new Error(`Invalid valuedata size ${value.length} for nonce`);
142
+ }
143
+ return { participantPubKey: key.subarray(0, 33), tapOutputKey: key.subarray(33), pubNonce: value };
144
+ }
145
+ exports.decodePsbtMusig2Nonce = decodePsbtMusig2Nonce;
146
+ /**
147
+ * Decodes proprietary key value data for musig2 partial sig
148
+ * @param kv
149
+ */
150
+ function decodePsbtMusig2PartialSig(kv) {
151
+ if (kv.key.identifier !== PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER ||
152
+ kv.key.subtype !== PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTIAL_SIG) {
153
+ throw new Error(`Invalid identifier ${kv.key.identifier} or subtype ${kv.key.subtype} for partial sig`);
154
+ }
155
+ const key = kv.key.keydata;
156
+ if (key.length !== 65) {
157
+ throw new Error(`Invalid keydata size ${key.length} for partial sig`);
158
+ }
159
+ const value = kv.value;
160
+ if (value.length !== 32 && value.length !== 33) {
161
+ throw new Error(`Invalid valuedata size ${value.length} for partial sig`);
162
+ }
163
+ return { participantPubKey: key.subarray(0, 33), tapOutputKey: key.subarray(33), partialSig: value };
164
+ }
165
+ exports.decodePsbtMusig2PartialSig = decodePsbtMusig2PartialSig;
70
166
  function createTapInternalKey(plainPubKeys) {
71
- plainPubKeys.forEach((pubKey) => outputScripts_1.checkPlainPublicKey(pubKey));
72
- return Buffer.from(noble_ecc_1.musig.getXOnlyPubkey(noble_ecc_1.musig.keyAgg(noble_ecc_1.musig.keySort(plainPubKeys))));
167
+ return Buffer.from(noble_ecc_1.musig.getXOnlyPubkey(noble_ecc_1.musig.keyAgg(plainPubKeys)));
73
168
  }
74
169
  exports.createTapInternalKey = createTapInternalKey;
75
170
  function createTapOutputKey(internalPubKey, tapTreeRoot) {
76
- if (tapTreeRoot.length !== 32) {
77
- throw new Error(`Invalid tapTreeRoot size ${tapTreeRoot.length}`);
78
- }
79
- return Buffer.from(taproot_1.tapTweakPubkey(noble_ecc_1.ecc, outputScripts_1.toXOnlyPublicKey(internalPubKey), tapTreeRoot).xOnlyPubkey);
171
+ return Buffer.from(taproot_1.tapTweakPubkey(noble_ecc_1.ecc, outputScripts_1.toXOnlyPublicKey(internalPubKey), outputScripts_1.checkTapMerkleRoot(tapTreeRoot)).xOnlyPubkey);
80
172
  }
81
173
  exports.createTapOutputKey = createTapOutputKey;
82
- function deriveWalletPubKey(tapBip32Derivations, rootWalletKey) {
83
- const myDerivations = tapBip32Derivations.filter((bipDv) => {
84
- return bipDv.masterFingerprint.equals(rootWalletKey.fingerprint);
174
+ function createAggregateNonce(pubNonces) {
175
+ return Buffer.from(noble_ecc_1.musig.nonceAgg(pubNonces));
176
+ }
177
+ exports.createAggregateNonce = createAggregateNonce;
178
+ function createTapTweak(tapInternalKey, tapMerkleRoot) {
179
+ return Buffer.from(taproot_1.calculateTapTweak(outputScripts_1.checkXOnlyPublicKey(tapInternalKey), outputScripts_1.checkTapMerkleRoot(tapMerkleRoot)));
180
+ }
181
+ exports.createTapTweak = createTapTweak;
182
+ function startMusig2SigningSession(aggNonce, hash, publicKeys, tweak) {
183
+ return noble_ecc_1.musig.startSigningSession(aggNonce, hash, publicKeys, { tweak, xOnly: true });
184
+ }
185
+ function musig2PartialSign(privateKey, publicNonce, sessionKey, nonceStore) {
186
+ outputScripts_1.checkTxHash(Buffer.from(sessionKey.msg));
187
+ return Buffer.from(noble_ecc_1.musig.partialSign({
188
+ secretKey: privateKey,
189
+ publicNonce: nonceStore.getRef(publicNonce),
190
+ sessionKey,
191
+ }));
192
+ }
193
+ exports.musig2PartialSign = musig2PartialSign;
194
+ function musig2PartialSigVerify(sig, publicKey, publicNonce, sessionKey) {
195
+ outputScripts_1.checkTxHash(Buffer.from(sessionKey.msg));
196
+ return noble_ecc_1.musig.partialVerify({ sig, publicKey, publicNonce, sessionKey });
197
+ }
198
+ exports.musig2PartialSigVerify = musig2PartialSigVerify;
199
+ function musig2AggregateSigs(sigs, sessionKey) {
200
+ return Buffer.from(noble_ecc_1.musig.signAgg(sigs, sessionKey));
201
+ }
202
+ exports.musig2AggregateSigs = musig2AggregateSigs;
203
+ /** @return session key that can be used to reference the session later */
204
+ function createMusig2SigningSession(sessionArgs) {
205
+ outputScripts_1.checkTxHash(sessionArgs.txHash);
206
+ const aggNonce = createAggregateNonce(sessionArgs.pubNonces);
207
+ const tweak = createTapTweak(sessionArgs.internalPubKey, sessionArgs.tapTreeRoot);
208
+ return startMusig2SigningSession(aggNonce, sessionArgs.txHash, sessionArgs.pubKeys, tweak);
209
+ }
210
+ exports.createMusig2SigningSession = createMusig2SigningSession;
211
+ /**
212
+ * @returns psbt proprietary key for musig2 participant key value data
213
+ * If no key value exists, undefined is returned.
214
+ */
215
+ function parsePsbtMusig2Participants(input) {
216
+ const participantsKeyVals = PsbtUtil_1.getPsbtInputProprietaryKeyVals(input, {
217
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
218
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
85
219
  });
86
- if (!myDerivations.length) {
87
- throw new Error('Need one tapBip32Derivation masterFingerprint to match the rootWalletKey fingerprint');
220
+ if (!participantsKeyVals.length) {
221
+ return undefined;
88
222
  }
89
- const myDerivation = myDerivations.filter((bipDv) => {
90
- const publicKey = rootWalletKey.derivePath(bipDv.path).publicKey;
91
- return bipDv.pubkey.equals(outputScripts_1.toXOnlyPublicKey(publicKey));
92
- });
93
- if (myDerivation.length !== 1) {
94
- throw new Error('root wallet key should derive one tapBip32Derivation');
223
+ if (participantsKeyVals.length > 1) {
224
+ throw new Error(`Found ${participantsKeyVals.length} matching participant key value instead of 1`);
95
225
  }
96
- return rootWalletKey.derivePath(myDerivation[0].path).publicKey;
226
+ return decodePsbtMusig2Participants(participantsKeyVals[0]);
97
227
  }
98
- function getMusig2NonceKeyValueData(psbt, inputIndex, rootWalletKey, sessionId) {
99
- const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
100
- if (!input.tapInternalKey) {
101
- return;
102
- }
103
- if (!input.tapMerkleRoot) {
104
- throw new Error('tapMerkleRoot is required to generate nonce');
228
+ exports.parsePsbtMusig2Participants = parsePsbtMusig2Participants;
229
+ /**
230
+ * @returns psbt proprietary key for musig2 public nonce key value data
231
+ * If no key value exists, undefined is returned.
232
+ */
233
+ function parsePsbtMusig2Nonces(input) {
234
+ const nonceKeyVals = PsbtUtil_1.getPsbtInputProprietaryKeyVals(input, {
235
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
236
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PUB_NONCE,
237
+ });
238
+ if (!nonceKeyVals.length) {
239
+ return undefined;
105
240
  }
106
- if (!input.tapBip32Derivation?.length) {
107
- throw new Error('tapBip32Derivation is required to generate nonce');
241
+ if (nonceKeyVals.length > 2) {
242
+ throw new Error(`Found ${nonceKeyVals.length} matching nonce key value instead of 1 or 2`);
108
243
  }
109
- const participantsKeyVals = psbt.getProprietaryKeyVals(inputIndex, {
110
- identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
111
- subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
244
+ return nonceKeyVals.map((kv) => decodePsbtMusig2Nonce(kv));
245
+ }
246
+ exports.parsePsbtMusig2Nonces = parsePsbtMusig2Nonces;
247
+ /**
248
+ * @returns psbt proprietary key for musig2 partial sig key value data
249
+ * If no key value exists, undefined is returned.
250
+ */
251
+ function parsePsbtMusig2PartialSigs(input) {
252
+ const sigKeyVals = PsbtUtil_1.getPsbtInputProprietaryKeyVals(input, {
253
+ identifier: PsbtUtil_1.PSBT_PROPRIETARY_IDENTIFIER,
254
+ subtype: PsbtUtil_1.ProprietaryKeySubtype.MUSIG2_PARTIAL_SIG,
112
255
  });
113
- if (participantsKeyVals.length !== 1) {
114
- throw new Error(`Found ${participantsKeyVals.length} matching participant key value instead of 1`);
256
+ if (!sigKeyVals.length) {
257
+ return undefined;
115
258
  }
116
- const participantKeyValData = decodePsbtMusig2ParticipantsKeyValData(participantsKeyVals[0]);
259
+ if (sigKeyVals.length > 2) {
260
+ throw new Error(`Found ${sigKeyVals.length} matching partial signature key value instead of 1 or 2`);
261
+ }
262
+ return sigKeyVals.map((kv) => decodePsbtMusig2PartialSig(kv));
263
+ }
264
+ exports.parsePsbtMusig2PartialSigs = parsePsbtMusig2PartialSigs;
265
+ /**
266
+ * Assert musig2 participant key value data with tapInternalKey and tapMerkleRoot.
267
+ * <tapOutputKey><tapInputKey> => <participantKey1><participantKey2>
268
+ * Using tapMerkleRoot and 2 participant keys, the tapInputKey is validated and using tapMerkleRoot and tapInputKey,
269
+ * the tapOutputKey is validated.
270
+ */
271
+ function assertPsbtMusig2Participants(participantKeyValData, tapInternalKey, tapMerkleRoot) {
272
+ outputScripts_1.checkXOnlyPublicKey(tapInternalKey);
273
+ outputScripts_1.checkTapMerkleRoot(tapMerkleRoot);
117
274
  const participantPubKeys = participantKeyValData.participantPubKeys;
118
- const tapInternalKey = createTapInternalKey(participantPubKeys);
119
- if (!tapInternalKey.equals(participantKeyValData.tapInternalKey)) {
120
- throw new Error('Invalid participants keyata tapInternalKey');
275
+ const internalKey = createTapInternalKey(participantPubKeys);
276
+ if (!internalKey.equals(participantKeyValData.tapInternalKey)) {
277
+ throw new Error('Invalid participants keydata tapInternalKey');
121
278
  }
122
- const tapOutputKey = createTapOutputKey(tapInternalKey, input.tapMerkleRoot);
123
- if (!tapOutputKey.equals(participantKeyValData.tapOutputKey)) {
124
- throw new Error('Invalid participants keyata tapOutputKey');
279
+ const outputKey = createTapOutputKey(internalKey, tapMerkleRoot);
280
+ if (!outputKey.equals(participantKeyValData.tapOutputKey)) {
281
+ throw new Error('Invalid participants keydata tapOutputKey');
125
282
  }
126
- if (!tapInternalKey.equals(input.tapInternalKey)) {
283
+ if (!internalKey.equals(tapInternalKey)) {
127
284
  throw new Error('tapInternalKey and aggregated participant pub keys does not match');
128
285
  }
129
- const derivedPubKey = deriveWalletPubKey(input.tapBip32Derivation, rootWalletKey);
130
- const participantPubKey = participantPubKeys.find((pubKey) => pubKey.equals(derivedPubKey));
131
- if (!Buffer.isBuffer(participantPubKey)) {
132
- throw new Error('participant plain pub key should match one tapBip32Derivation plain pub key');
133
- }
134
- const { hash } = psbt.getTaprootHashForSigChecked(inputIndex);
135
- const nonceGenArgs = {
136
- sessionId,
137
- publicKey: participantPubKey,
138
- xOnlyPublicKey: tapOutputKey,
139
- msg: hash,
140
- secretKey: rootWalletKey.privateKey,
141
- };
142
- const pubNonces = Buffer.from(noble_ecc_1.musig.nonceGen(nonceGenArgs));
143
- return encodePsbtMusig2PubNonceKeyValData({
144
- participantPubKey,
145
- tapOutputKey,
146
- pubNonces,
147
- });
148
286
  }
287
+ exports.assertPsbtMusig2Participants = assertPsbtMusig2Participants;
149
288
  /**
150
- * Generates and sets Musig2 nonces to p2trMusig2 key path spending inputs.
151
- * tapInternalkey, tapMerkleRoot, tapBip32Derivation for rootWalletKey are required per p2trMusig2 key path input.
152
- * Also participant keys are required from psbt proprietary key values.
153
- * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
154
- * @param psbt
155
- * @param rootWalletKey
156
- * @param sessionId If provided it must either be a counter unique to this secret key,
157
- * (converted to an array of 32 bytes), or 32 uniformly random bytes.
289
+ * Assert musig2 public nonce key value data with participant key value data
290
+ * (refer assertPsbtMusig2ParticipantsKeyValData).
291
+ * <participantKey1><tapOutputKey> => <pubNonce1>
292
+ * <participantKey2><tapOutputKey> => <pubNonce2>
293
+ * Checks against participant keys and tapOutputKey
158
294
  */
159
- function setMusig2Nonces(psbt, rootWalletKey, sessionId) {
160
- if (rootWalletKey.isNeutered()) {
161
- throw new Error('private key is required to generate nonce');
295
+ function assertPsbtMusig2Nonces(noncesKeyValData, participantKeyValData) {
296
+ outputScripts_1.checkXOnlyPublicKey(participantKeyValData.tapOutputKey);
297
+ participantKeyValData.participantPubKeys.forEach((kv) => outputScripts_1.checkPlainPublicKey(kv));
298
+ if (participantKeyValData.participantPubKeys[0].equals(participantKeyValData.participantPubKeys[1])) {
299
+ throw new Error(`Duplicate participant pub keys found`);
162
300
  }
163
- if (Buffer.isBuffer(sessionId) && sessionId.length !== 32) {
164
- throw new Error(`Invalid sessionId size ${sessionId.length}`);
301
+ if (noncesKeyValData.length > 2) {
302
+ throw new Error(`Invalid nonce key value count ${noncesKeyValData.length}`);
165
303
  }
166
- psbt.data.inputs.forEach((input, inputIndex) => {
167
- const noncesKeyValueData = getMusig2NonceKeyValueData(psbt, inputIndex, rootWalletKey, sessionId);
168
- if (noncesKeyValueData) {
169
- psbt.addProprietaryKeyValToInput(inputIndex, noncesKeyValueData);
304
+ noncesKeyValData.forEach((nonceKv) => {
305
+ const index = participantKeyValData.participantPubKeys.findIndex((pubKey) => nonceKv.participantPubKey.equals(pubKey));
306
+ if (index < 0) {
307
+ throw new Error('Invalid nonce keydata participant pub key');
308
+ }
309
+ if (!nonceKv.tapOutputKey.equals(participantKeyValData.tapOutputKey)) {
310
+ throw new Error('Invalid nonce keydata tapOutputKey');
170
311
  }
171
312
  });
172
313
  }
173
- exports.setMusig2Nonces = setMusig2Nonces;
174
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTXVzaWcyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JpdGdvL011c2lnMi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSx5Q0FBbUg7QUFDbkgsbURBQTZGO0FBRTdGLDRDQUEwQztBQUUxQyx3Q0FBNEM7QUFFNUMsZ0RBQXFEO0FBb0JyRDs7OztHQUlHO0FBQ0gsU0FBZ0Isc0NBQXNDLENBQ3BELHNCQUEwRDtJQUUxRCxNQUFNLE9BQU8sR0FBRyxDQUFDLHNCQUFzQixDQUFDLFlBQVksRUFBRSxzQkFBc0IsQ0FBQyxjQUFjLENBQUMsQ0FBQyxHQUFHLENBQUMsQ0FBQyxNQUFNLEVBQUUsRUFBRSxDQUMxRyxtQ0FBbUIsQ0FBQyxNQUFNLENBQUMsQ0FDNUIsQ0FBQztJQUNGLE1BQU0sS0FBSyxHQUFHLHNCQUFzQixDQUFDLGtCQUFrQixDQUFDLEdBQUcsQ0FBQyxDQUFDLE1BQU0sRUFBRSxFQUFFLENBQUMsbUNBQW1CLENBQUMsTUFBTSxDQUFDLENBQUMsQ0FBQztJQUNyRyxNQUFNLEdBQUcsR0FBRztRQUNWLFVBQVUsRUFBRSxzQ0FBMkI7UUFDdkMsT0FBTyxFQUFFLGdDQUFxQixDQUFDLDJCQUEyQjtRQUMxRCxPQUFPLEVBQUUsTUFBTSxDQUFDLE1BQU0sQ0FBQyxPQUFPLENBQUM7S0FDaEMsQ0FBQztJQUNGLE9BQU8sRUFBRSxHQUFHLEVBQUUsS0FBSyxFQUFFLE1BQU0sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFDLEVBQUUsQ0FBQ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VxuICBwc2J0LmRhdGEuaW5wdXRzLmZvckVhY2goKGlucHV0LCBpbnB1dEluZGV4KSA9PiB7XG4gICAgY29uc3Qgbm9uY2VzS2V5VmFsdWVEYXRhID0gZ2V0TXVzaWcyTm9uY2VLZXlWYWx1ZURhdGEocHNidCwgaW5wdXRJbmRleCwgcm9vdFdhbGxldEtleSwgc2Vzc2lvbklkKTtcbiAgICBpZiAobm9uY2VzS2V5VmFsdWVEYXRhKSB7XG4gICAgICBwc2J0LmFkZFByb3ByaWV0YXJ5S2V5VmFsVG9JbnB1dChpbnB1dEluZGV4LCBub25jZXNLZXlWYWx1ZURhdGEpO1xuICAgIH1cbiAgfSk7XG59XG4iXX0=
314
+ exports.assertPsbtMusig2Nonces = assertPsbtMusig2Nonces;
315
+ /**
316
+ * @returns Input object but sig hash type data is taken out from partialSig field.
317
+ * If sig hash type is not common for all sigs, error out, otherwise returns the modified object and single hash type.
318
+ */
319
+ function getSigHashTypeFromSigs(partialSigs) {
320
+ if (!partialSigs.length) {
321
+ throw new Error('partialSigs array can not be empty');
322
+ }
323
+ const pSigsWithHashType = partialSigs.map((kv) => {
324
+ const { partialSig, participantPubKey, tapOutputKey } = kv;
325
+ return partialSig.length === 33
326
+ ? { pSig: { partialSig: partialSig.slice(0, 32), participantPubKey, tapOutputKey }, sigHashType: partialSig[32] }
327
+ : { pSig: { partialSig, participantPubKey, tapOutputKey }, sigHashType: index_1.Transaction.SIGHASH_DEFAULT };
328
+ });
329
+ const sigHashType = pSigsWithHashType[0].sigHashType;
330
+ if (!pSigsWithHashType.every((pSig) => pSig.sigHashType === sigHashType)) {
331
+ throw new Error('signatures must use same sig hash type');
332
+ }
333
+ return { partialSigs: pSigsWithHashType.map(({ pSig }) => pSig), sigHashType };
334
+ }
335
+ exports.getSigHashTypeFromSigs = getSigHashTypeFromSigs;
336
+ function createMusig2DeterministicNonce(params) {
337
+ return Buffer.from(noble_ecc_1.musig.deterministicNonceGen({
338
+ secretKey: params.privateKey,
339
+ aggOtherNonce: noble_ecc_1.musig.nonceAgg([params.otherNonce]),
340
+ publicKeys: params.publicKeys,
341
+ tweaks: [{ tweak: createTapTweak(params.internalPubKey, params.tapTreeRoot), xOnly: true }],
342
+ msg: params.hash,
343
+ }).publicNonce);
344
+ }
345
+ exports.createMusig2DeterministicNonce = createMusig2DeterministicNonce;
346
+ function musig2DeterministicSign(params) {
347
+ const { sig, sessionKey, publicNonce } = noble_ecc_1.musig.deterministicSign({
348
+ secretKey: params.privateKey,
349
+ aggOtherNonce: noble_ecc_1.musig.nonceAgg([params.otherNonce]),
350
+ publicKeys: params.publicKeys,
351
+ tweaks: [{ tweak: createTapTweak(params.internalPubKey, params.tapTreeRoot), xOnly: true }],
352
+ msg: params.hash,
353
+ });
354
+ return { sig: Buffer.from(sig), sessionKey, publicNonce: Buffer.from(publicNonce) };
355
+ }
356
+ exports.musig2DeterministicSign = musig2DeterministicSign;
357
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTXVzaWcyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JpdGdvL011c2lnMi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFQSxtREFNeUI7QUFDekIsNENBQTBDO0FBRTFDLHdDQUErRDtBQUMvRCxvQ0FBdUM7QUFFdkMseUNBS29CO0FBc0NwQjs7O0dBR0c7QUFDSCxNQUFhLGdCQUFnQjtJQUE3QjtRQUNVLFdBQU0sR0FBaUIsRUFBRSxDQUFDO0lBd0NwQyxDQUFDO0lBdENDOzs7T0FHRztJQUNILE1BQU0sQ0FBQyxLQUFpQjtRQUN0QixLQUFLLE1BQU0sQ0FBQyxJQUFJLElBQUksQ0FBQyxNQUFNLEVBQUU7WUFDM0IsSUFBSSxNQUFNLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRTtnQkF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VybmFsUHViS2V5LCBwYXJhbXMudGFwVHJlZVJvb3QpLCB4T25seTogdHJ1ZSB9XSxcbiAgICBtc2c6IHBhcmFtcy5oYXNoLFxuICB9KTtcbiAgcmV0dXJuIHsgc2lnOiBCdWZmZXIuZnJvbShzaWcpLCBzZXNzaW9uS2V5LCBwdWJsaWNOb25jZTogQnVmZmVyLmZyb20ocHVibGljTm9uY2UpIH07XG59XG4iXX0=
@@ -0,0 +1,59 @@
1
+ /// <reference types="node" />
2
+ import { ProprietaryKey } from 'bip174/src/lib/proprietaryKeyVal';
3
+ import { PsbtInput } from 'bip174/src/lib/interfaces';
4
+ import { Psbt } from 'bitcoinjs-lib/src/psbt';
5
+ /**
6
+ * bitgo proprietary key identifier
7
+ */
8
+ export declare const PSBT_PROPRIETARY_IDENTIFIER = "BITGO";
9
+ /**
10
+ * subtype for proprietary keys that bitgo uses
11
+ */
12
+ export declare enum ProprietaryKeySubtype {
13
+ ZEC_CONSENSUS_BRANCH_ID = 0,
14
+ MUSIG2_PARTICIPANT_PUB_KEYS = 1,
15
+ MUSIG2_PUB_NONCE = 2,
16
+ MUSIG2_PARTIAL_SIG = 3
17
+ }
18
+ /**
19
+ * Psbt proprietary keydata object.
20
+ * <compact size uint identifier length> <bytes identifier> <compact size uint subtype> <bytes subkeydata>
21
+ * => <bytes valuedata>
22
+ */
23
+ export interface ProprietaryKeyValue {
24
+ key: ProprietaryKey;
25
+ value: Buffer;
26
+ }
27
+ /**
28
+ * Psbt proprietary keydata object search fields.
29
+ * <compact size uint identifier length> <bytes identifier> <compact size uint subtype> <bytes subkeydata>
30
+ */
31
+ export interface ProprietaryKeySearch {
32
+ identifier: string;
33
+ subtype?: number;
34
+ keydata?: Buffer;
35
+ identifierEncoding?: BufferEncoding;
36
+ }
37
+ /**
38
+ * Search any data from psbt proprietary key value against keydata.
39
+ * Default identifierEncoding is utf-8 for identifier.
40
+ */
41
+ export declare function getPsbtInputProprietaryKeyVals(input: PsbtInput, keySearch?: ProprietaryKeySearch): ProprietaryKeyValue[];
42
+ /**
43
+ * @return partialSig/tapScriptSig/MUSIG2_PARTIAL_SIG count iff input is not finalized
44
+ */
45
+ export declare function getPsbtInputSignatureCount(input: PsbtInput): number;
46
+ /**
47
+ * @return true iff PSBT input is finalized
48
+ */
49
+ export declare function isPsbtInputFinalized(input: PsbtInput): boolean;
50
+ /**
51
+ * @return true iff data starts with magic PSBT byte sequence
52
+ * @param data byte array or hex string
53
+ * */
54
+ export declare function isPsbt(data: Buffer | string): boolean;
55
+ /**
56
+ * This function allows signing or validating a psbt with non-segwit inputs those do not contain nonWitnessUtxo.
57
+ */
58
+ export declare function withUnsafeNonSegwit<T>(psbt: Psbt, fn: () => T, unsafe?: boolean): T;
59
+ //# sourceMappingURL=PsbtUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PsbtUtil.d.ts","sourceRoot":"","sources":["../../../src/bitgo/PsbtUtil.ts"],"names":[],"mappings":";AAAA,OAAO,EAAwB,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAE9C;;GAEG;AACH,eAAO,MAAM,2BAA2B,UAAU,CAAC;AAEnD;;GAEG;AACH,oBAAY,qBAAqB;IAC/B,uBAAuB,IAAO;IAC9B,2BAA2B,IAAO;IAClC,gBAAgB,IAAO;IACvB,kBAAkB,IAAO;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,cAAc,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,cAAc,CAAC;CACrC;AAED;;;GAGG;AACH,w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