utxo-lib 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/src/address.d.ts +11 -0
  4. package/dist/src/address.d.ts.map +1 -0
  5. package/dist/src/address.js +37 -0
  6. package/dist/src/addressFormat.d.ts +53 -0
  7. package/dist/src/addressFormat.d.ts.map +1 -0
  8. package/dist/src/addressFormat.js +110 -0
  9. package/dist/src/bitgo/Musig2.d.ts +51 -0
  10. package/dist/src/bitgo/Musig2.d.ts.map +1 -0
  11. package/dist/src/bitgo/Musig2.js +175 -0
  12. package/dist/src/bitgo/Unspent.d.ts +95 -0
  13. package/dist/src/bitgo/Unspent.d.ts.map +1 -0
  14. package/dist/src/bitgo/Unspent.js +138 -0
  15. package/dist/src/bitgo/UtxoPsbt.d.ts +132 -0
  16. package/dist/src/bitgo/UtxoPsbt.d.ts.map +1 -0
  17. package/dist/src/bitgo/UtxoPsbt.js +469 -0
  18. package/dist/src/bitgo/UtxoTransaction.d.ts +22 -0
  19. package/dist/src/bitgo/UtxoTransaction.d.ts.map +1 -0
  20. package/dist/src/bitgo/UtxoTransaction.js +97 -0
  21. package/dist/src/bitgo/UtxoTransactionBuilder.d.ts +26 -0
  22. package/dist/src/bitgo/UtxoTransactionBuilder.d.ts.map +1 -0
  23. package/dist/src/bitgo/UtxoTransactionBuilder.js +67 -0
  24. package/dist/src/bitgo/bbc/DashPsbt.d.ts +12 -0
  25. package/dist/src/bitgo/bbc/DashPsbt.d.ts.map +1 -0
  26. package/dist/src/bitgo/bbc/DashPsbt.js +27 -0
  27. package/dist/src/bitgo/bbc/DashTransaction.d.ts +39 -0
  28. package/dist/src/bitgo/bbc/DashTransaction.d.ts.map +1 -0
  29. package/dist/src/bitgo/bbc/DashTransaction.js +109 -0
  30. package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts +14 -0
  31. package/dist/src/bitgo/bbc/DashTransactionBuilder.d.ts.map +1 -0
  32. package/dist/src/bitgo/bbc/DashTransactionBuilder.js +28 -0
  33. package/dist/src/bitgo/bbc/index.d.ts +4 -0
  34. package/dist/src/bitgo/bbc/index.d.ts.map +1 -0
  35. package/dist/src/bitgo/bbc/index.js +16 -0
  36. package/dist/src/bitgo/bitcoincash/address.d.ts +35 -0
  37. package/dist/src/bitgo/bitcoincash/address.d.ts.map +1 -0
  38. package/dist/src/bitgo/bitcoincash/address.js +151 -0
  39. package/dist/src/bitgo/bitcoincash/index.d.ts +2 -0
  40. package/dist/src/bitgo/bitcoincash/index.d.ts.map +1 -0
  41. package/dist/src/bitgo/bitcoincash/index.js +14 -0
  42. package/dist/src/bitgo/dash/DashPsbt.d.ts +12 -0
  43. package/dist/src/bitgo/dash/DashPsbt.d.ts.map +1 -0
  44. package/dist/src/bitgo/dash/DashPsbt.js +27 -0
  45. package/dist/src/bitgo/dash/DashTransaction.d.ts +39 -0
  46. package/dist/src/bitgo/dash/DashTransaction.d.ts.map +1 -0
  47. package/dist/src/bitgo/dash/DashTransaction.js +109 -0
  48. package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts +14 -0
  49. package/dist/src/bitgo/dash/DashTransactionBuilder.d.ts.map +1 -0
  50. package/dist/src/bitgo/dash/DashTransactionBuilder.js +28 -0
  51. package/dist/src/bitgo/dash/index.d.ts +4 -0
  52. package/dist/src/bitgo/dash/index.d.ts.map +1 -0
  53. package/dist/src/bitgo/dash/index.js +16 -0
  54. package/dist/src/bitgo/index.d.ts +17 -0
  55. package/dist/src/bitgo/index.d.ts.map +1 -0
  56. package/dist/src/bitgo/index.js +30 -0
  57. package/dist/src/bitgo/keyutil.d.ts +17 -0
  58. package/dist/src/bitgo/keyutil.d.ts.map +1 -0
  59. package/dist/src/bitgo/keyutil.js +37 -0
  60. package/dist/src/bitgo/nonStandardHalfSigned.d.ts +7 -0
  61. package/dist/src/bitgo/nonStandardHalfSigned.d.ts.map +1 -0
  62. package/dist/src/bitgo/nonStandardHalfSigned.js +56 -0
  63. package/dist/src/bitgo/outputScripts.d.ts +84 -0
  64. package/dist/src/bitgo/outputScripts.d.ts.map +1 -0
  65. package/dist/src/bitgo/outputScripts.js +297 -0
  66. package/dist/src/bitgo/parseInput.d.ts +92 -0
  67. package/dist/src/bitgo/parseInput.d.ts.map +1 -0
  68. package/dist/src/bitgo/parseInput.js +344 -0
  69. package/dist/src/bitgo/psbt/fromHalfSigned.d.ts +24 -0
  70. package/dist/src/bitgo/psbt/fromHalfSigned.d.ts.map +1 -0
  71. package/dist/src/bitgo/psbt/fromHalfSigned.js +91 -0
  72. package/dist/src/bitgo/psbt/scriptTypes.d.ts +6 -0
  73. package/dist/src/bitgo/psbt/scriptTypes.d.ts.map +1 -0
  74. package/dist/src/bitgo/psbt/scriptTypes.js +23 -0
  75. package/dist/src/bitgo/signature.d.ts +84 -0
  76. package/dist/src/bitgo/signature.d.ts.map +1 -0
  77. package/dist/src/bitgo/signature.js +222 -0
  78. package/dist/src/bitgo/tnumber.d.ts +9 -0
  79. package/dist/src/bitgo/tnumber.d.ts.map +1 -0
  80. package/dist/src/bitgo/tnumber.js +31 -0
  81. package/dist/src/bitgo/transaction.d.ts +29 -0
  82. package/dist/src/bitgo/transaction.d.ts.map +1 -0
  83. package/dist/src/bitgo/transaction.js +247 -0
  84. package/dist/src/bitgo/types.d.ts +5 -0
  85. package/dist/src/bitgo/types.d.ts.map +1 -0
  86. package/dist/src/bitgo/types.js +12 -0
  87. package/dist/src/bitgo/wallet/Psbt.d.ts +47 -0
  88. package/dist/src/bitgo/wallet/Psbt.d.ts.map +1 -0
  89. package/dist/src/bitgo/wallet/Psbt.js +232 -0
  90. package/dist/src/bitgo/wallet/Unspent.d.ts +47 -0
  91. package/dist/src/bitgo/wallet/Unspent.d.ts.map +1 -0
  92. package/dist/src/bitgo/wallet/Unspent.js +154 -0
  93. package/dist/src/bitgo/wallet/WalletKeys.d.ts +72 -0
  94. package/dist/src/bitgo/wallet/WalletKeys.d.ts.map +1 -0
  95. package/dist/src/bitgo/wallet/WalletKeys.js +104 -0
  96. package/dist/src/bitgo/wallet/WalletOutput.d.ts +18 -0
  97. package/dist/src/bitgo/wallet/WalletOutput.d.ts.map +1 -0
  98. package/dist/src/bitgo/wallet/WalletOutput.js +69 -0
  99. package/dist/src/bitgo/wallet/WalletScripts.d.ts +7 -0
  100. package/dist/src/bitgo/wallet/WalletScripts.d.ts.map +1 -0
  101. package/dist/src/bitgo/wallet/WalletScripts.js +15 -0
  102. package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts +19 -0
  103. package/dist/src/bitgo/wallet/WalletUnspentSigner.d.ts.map +1 -0
  104. package/dist/src/bitgo/wallet/WalletUnspentSigner.js +47 -0
  105. package/dist/src/bitgo/wallet/chains.d.ts +57 -0
  106. package/dist/src/bitgo/wallet/chains.d.ts.map +1 -0
  107. package/dist/src/bitgo/wallet/chains.js +106 -0
  108. package/dist/src/bitgo/wallet/index.d.ts +8 -0
  109. package/dist/src/bitgo/wallet/index.d.ts.map +1 -0
  110. package/dist/src/bitgo/wallet/index.js +20 -0
  111. package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts +26 -0
  112. package/dist/src/bitgo/zcash/ZcashBufferutils.d.ts.map +1 -0
  113. package/dist/src/bitgo/zcash/ZcashBufferutils.js +157 -0
  114. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts +36 -0
  115. package/dist/src/bitgo/zcash/ZcashPsbt.d.ts.map +1 -0
  116. package/dist/src/bitgo/zcash/ZcashPsbt.js +146 -0
  117. package/dist/src/bitgo/zcash/ZcashTransaction.d.ts +61 -0
  118. package/dist/src/bitgo/zcash/ZcashTransaction.d.ts.map +1 -0
  119. package/dist/src/bitgo/zcash/ZcashTransaction.js +341 -0
  120. package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts +21 -0
  121. package/dist/src/bitgo/zcash/ZcashTransactionBuilder.d.ts.map +1 -0
  122. package/dist/src/bitgo/zcash/ZcashTransactionBuilder.js +105 -0
  123. package/dist/src/bitgo/zcash/address.d.ts +8 -0
  124. package/dist/src/bitgo/zcash/address.d.ts.map +1 -0
  125. package/dist/src/bitgo/zcash/address.js +57 -0
  126. package/dist/src/bitgo/zcash/hashZip0244.d.ts +27 -0
  127. package/dist/src/bitgo/zcash/hashZip0244.d.ts.map +1 -0
  128. package/dist/src/bitgo/zcash/hashZip0244.js +184 -0
  129. package/dist/src/bitgo/zcash/index.d.ts +4 -0
  130. package/dist/src/bitgo/zcash/index.d.ts.map +1 -0
  131. package/dist/src/bitgo/zcash/index.js +16 -0
  132. package/dist/src/classify.d.ts +19 -0
  133. package/dist/src/classify.d.ts.map +1 -0
  134. package/dist/src/classify.js +89 -0
  135. package/dist/src/index.d.ts +13 -0
  136. package/dist/src/index.d.ts.map +1 -0
  137. package/dist/src/index.js +36 -0
  138. package/dist/src/networks.d.ts +119 -0
  139. package/dist/src/networks.d.ts.map +1 -0
  140. package/dist/src/networks.js +477 -0
  141. package/dist/src/noble_ecc.d.ts +28 -0
  142. package/dist/src/noble_ecc.d.ts.map +1 -0
  143. package/dist/src/noble_ecc.js +168 -0
  144. package/dist/src/payments/index.d.ts +4 -0
  145. package/dist/src/payments/index.d.ts.map +1 -0
  146. package/dist/src/payments/index.js +8 -0
  147. package/dist/src/payments/p2tr.d.ts +3 -0
  148. package/dist/src/payments/p2tr.d.ts.map +1 -0
  149. package/dist/src/payments/p2tr.js +348 -0
  150. package/dist/src/payments/p2tr_ns.d.ts +3 -0
  151. package/dist/src/payments/p2tr_ns.d.ts.map +1 -0
  152. package/dist/src/payments/p2tr_ns.js +134 -0
  153. package/dist/src/taproot.d.ts +141 -0
  154. package/dist/src/taproot.d.ts.map +1 -0
  155. package/dist/src/taproot.js +384 -0
  156. package/dist/src/templates/multisig/index.d.ts +4 -0
  157. package/dist/src/templates/multisig/index.d.ts.map +1 -0
  158. package/dist/src/templates/multisig/index.js +8 -0
  159. package/dist/src/templates/multisig/input.d.ts +7 -0
  160. package/dist/src/templates/multisig/input.d.ts.map +1 -0
  161. package/dist/src/templates/multisig/input.js +25 -0
  162. package/dist/src/templates/multisig/output.d.ts +7 -0
  163. package/dist/src/templates/multisig/output.d.ts.map +1 -0
  164. package/dist/src/templates/multisig/output.js +38 -0
  165. package/dist/src/templates/nulldata.d.ts +10 -0
  166. package/dist/src/templates/nulldata.d.ts.map +1 -0
  167. package/dist/src/templates/nulldata.js +17 -0
  168. package/dist/src/templates/pubkey/index.d.ts +4 -0
  169. package/dist/src/templates/pubkey/index.d.ts.map +1 -0
  170. package/dist/src/templates/pubkey/index.js +8 -0
  171. package/dist/src/templates/pubkey/input.d.ts +7 -0
  172. package/dist/src/templates/pubkey/input.d.ts.map +1 -0
  173. package/dist/src/templates/pubkey/input.js +14 -0
  174. package/dist/src/templates/pubkey/output.d.ts +7 -0
  175. package/dist/src/templates/pubkey/output.d.ts.map +1 -0
  176. package/dist/src/templates/pubkey/output.js +15 -0
  177. package/dist/src/templates/pubkeyhash/index.d.ts +4 -0
  178. package/dist/src/templates/pubkeyhash/index.d.ts.map +1 -0
  179. package/dist/src/templates/pubkeyhash/index.js +8 -0
  180. package/dist/src/templates/pubkeyhash/input.d.ts +7 -0
  181. package/dist/src/templates/pubkeyhash/input.d.ts.map +1 -0
  182. package/dist/src/templates/pubkeyhash/input.js +16 -0
  183. package/dist/src/templates/pubkeyhash/output.d.ts +6 -0
  184. package/dist/src/templates/pubkeyhash/output.d.ts.map +1 -0
  185. package/dist/src/templates/pubkeyhash/output.js +20 -0
  186. package/dist/src/templates/scripthash/index.d.ts +4 -0
  187. package/dist/src/templates/scripthash/index.d.ts.map +1 -0
  188. package/dist/src/templates/scripthash/index.js +8 -0
  189. package/dist/src/templates/scripthash/input.d.ts +6 -0
  190. package/dist/src/templates/scripthash/input.d.ts.map +1 -0
  191. package/dist/src/templates/scripthash/input.js +43 -0
  192. package/dist/src/templates/scripthash/output.d.ts +6 -0
  193. package/dist/src/templates/scripthash/output.d.ts.map +1 -0
  194. package/dist/src/templates/scripthash/output.js +15 -0
  195. package/dist/src/templates/taproot/index.d.ts +4 -0
  196. package/dist/src/templates/taproot/index.d.ts.map +1 -0
  197. package/dist/src/templates/taproot/index.js +8 -0
  198. package/dist/src/templates/taproot/input.d.ts +6 -0
  199. package/dist/src/templates/taproot/input.d.ts.map +1 -0
  200. package/dist/src/templates/taproot/input.js +23 -0
  201. package/dist/src/templates/taproot/output.d.ts +6 -0
  202. package/dist/src/templates/taproot/output.d.ts.map +1 -0
  203. package/dist/src/templates/taproot/output.js +15 -0
  204. package/dist/src/templates/taprootnofn/index.d.ts +4 -0
  205. package/dist/src/templates/taprootnofn/index.d.ts.map +1 -0
  206. package/dist/src/templates/taprootnofn/index.js +8 -0
  207. package/dist/src/templates/taprootnofn/input.d.ts +7 -0
  208. package/dist/src/templates/taprootnofn/input.d.ts.map +1 -0
  209. package/dist/src/templates/taprootnofn/input.js +24 -0
  210. package/dist/src/templates/taprootnofn/output.d.ts +7 -0
  211. package/dist/src/templates/taprootnofn/output.d.ts.map +1 -0
  212. package/dist/src/templates/taprootnofn/output.js +28 -0
  213. package/dist/src/templates/witnesscommitment/index.d.ts +3 -0
  214. package/dist/src/templates/witnesscommitment/index.d.ts.map +1 -0
  215. package/dist/src/templates/witnesscommitment/index.js +6 -0
  216. package/dist/src/templates/witnesscommitment/output.d.ts +8 -0
  217. package/dist/src/templates/witnesscommitment/output.d.ts.map +1 -0
  218. package/dist/src/templates/witnesscommitment/output.js +31 -0
  219. package/dist/src/templates/witnesspubkeyhash/index.d.ts +4 -0
  220. package/dist/src/templates/witnesspubkeyhash/index.d.ts.map +1 -0
  221. package/dist/src/templates/witnesspubkeyhash/index.js +8 -0
  222. package/dist/src/templates/witnesspubkeyhash/input.d.ts +7 -0
  223. package/dist/src/templates/witnesspubkeyhash/input.d.ts.map +1 -0
  224. package/dist/src/templates/witnesspubkeyhash/input.js +19 -0
  225. package/dist/src/templates/witnesspubkeyhash/output.d.ts +6 -0
  226. package/dist/src/templates/witnesspubkeyhash/output.d.ts.map +1 -0
  227. package/dist/src/templates/witnesspubkeyhash/output.js +15 -0
  228. package/dist/src/templates/witnessscripthash/index.d.ts +4 -0
  229. package/dist/src/templates/witnessscripthash/index.d.ts.map +1 -0
  230. package/dist/src/templates/witnessscripthash/index.js +8 -0
  231. package/dist/src/templates/witnessscripthash/input.d.ts +6 -0
  232. package/dist/src/templates/witnessscripthash/input.d.ts.map +1 -0
  233. package/dist/src/templates/witnessscripthash/input.js +35 -0
  234. package/dist/src/templates/witnessscripthash/output.d.ts +6 -0
  235. package/dist/src/templates/witnessscripthash/output.d.ts.map +1 -0
  236. package/dist/src/templates/witnessscripthash/output.js +15 -0
  237. package/dist/src/testutil/index.d.ts +3 -0
  238. package/dist/src/testutil/index.d.ts.map +1 -0
  239. package/dist/src/testutil/index.js +15 -0
  240. package/dist/src/testutil/keys.d.ts +10 -0
  241. package/dist/src/testutil/keys.d.ts.map +1 -0
  242. package/dist/src/testutil/keys.js +40 -0
  243. package/dist/src/testutil/mock.d.ts +21 -0
  244. package/dist/src/testutil/mock.d.ts.map +1 -0
  245. package/dist/src/testutil/mock.js +86 -0
  246. package/dist/src/transaction_builder.d.ts +47 -0
  247. package/dist/src/transaction_builder.d.ts.map +1 -0
  248. package/dist/src/transaction_builder.js +1084 -0
  249. package/package.json +87 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2017 bitcoinjs-lib contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # BitGo UTXO library
2
+
3
+ This library is a wrapper around [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) adding altcoin support.
4
+
5
+ ## Features
6
+ - Multicoin support: Configurable behaviour based on [network](https://github.com/BitGo/bitgo-utxo-lib/blob/master/src/networks.js) objects.
7
+ - Backed by [BitGo](https://www.bitgo.com/info/)
8
+
9
+ ## Installation
10
+
11
+ ``` bash
12
+ # using npm
13
+ npm install @bitgo/utxo-lib
14
+
15
+ # using yarn
16
+ yarn add @bitgo/utxo-lib
17
+ ```
18
+
19
+ ## Setup
20
+
21
+ JavaScript (ESM)
22
+ ``` javascript
23
+ import * as utxolib from '@bitgo/utxo-lib'
24
+ ```
25
+
26
+ NodeJS (CJS)
27
+ ``` javascript
28
+ const utxolib = require('@bitgo/utxo-lib')
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Support for parsing and building altcoin transactions is provided by the following methods
34
+
35
+ ``` typescript
36
+ utxolib.bitgo.createTransactionFromBuffer(buffer, network): UtxoTransaction
37
+ // (similarly `createTransactionFromHex(string, network)`)
38
+
39
+ utxolib.bitgo.createTransactionBuilderForNetwork(network): UtxoTransactionBuilder
40
+
41
+ utxolib.bitgo.createTransactionBuilderFromTransaction(tx): UtxoTransactionBuilder
42
+ ```
43
+
44
+ The `UtxoTransaction(Builder)` classes have the same interface as the `Transaction` type in `bitcoinjs-lib` .
45
+
46
+ ## Supported coins
47
+
48
+ |Network|Mainnet|Testnet|
49
+ |---|---|---|
50
+ |Bitcoin|`utxolib.networks.bitcoin`|`utxolib.networks.testnet`|
51
+ |Bitcoin Cash|`utxolib.networks.bitcoincash`|`utxolib.networks.bitcoincashTestnet`|
52
+ |Bitcoin Gold|`utxolib.networks.bitcoingold`|`utxolib.networks.bitcoingoldTestnet`|
53
+ |Bitcoin SV (Satoshi Vision)|`utxolib.networks.bitcoinsv`|`utxolib.networks.bitcoinsvTestnet`|
54
+ |Dash|`utxolib.networks.dash`|`utxolib.networks.dash`|
55
+ |eCash|`utxolib.networks.ecash`|`utxolib.networks.ecashTestnet`|
56
+ |Litecoin|`utxolib.networks.litecoin`|`utxolib.networks.litecoinTest`|
57
+ |Zcash|`utxolib.networks.zcash`|`utxolib.networks.zcashTest`|
58
+
59
+ > [Bitcoin SV](https://blog.bitgo.com/bsv-deprecation-6b3fff4df34c) no longer supports sending funds to BitGo wallets. Existing customers with Bitcoin SV in BitGo wallets will still be able to access and sweep funds to an external Bitcoin SV wallet.
@@ -0,0 +1,11 @@
1
+ /// <reference types="node" />
2
+ import * as bitcoinjs from 'bitcoinjs-lib';
3
+ import { Base58CheckResult, Bech32Result } from 'bitcoinjs-lib/src/address';
4
+ import { Network } from './networks';
5
+ export declare function fromOutputScript(outputScript: Buffer, network: Network): string;
6
+ export declare function toOutputScript(address: string, network: Network): Buffer;
7
+ export declare function toBase58Check(hash: Buffer, version: number, network: Network): string;
8
+ export declare function fromBase58Check(address: string, network: Network): Base58CheckResult;
9
+ export declare const fromBech32: typeof bitcoinjs.address.fromBech32, toBech32: typeof bitcoinjs.address.toBech32;
10
+ export { Base58CheckResult, Bech32Result };
11
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG5E,OAAO,EAA2B,OAAO,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAK/E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKxE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAKrF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,iBAAiB,CAKpF;AAED,eAAO,MAAQ,UAAU,uCAAE,QAAQ,mCAAsB,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.toBech32 = exports.fromBech32 = exports.fromBase58Check = exports.toBase58Check = exports.toOutputScript = exports.fromOutputScript = void 0;
5
+ const bitcoinjs = require("bitcoinjs-lib");
6
+ const zcashAddress = require("../src/bitgo/zcash/address");
7
+ const networks_1 = require("./networks");
8
+ function fromOutputScript(outputScript, network) {
9
+ if (networks_1.isValidNetwork(network) && networks_1.isZcash(network)) {
10
+ return zcashAddress.fromOutputScript(outputScript, network);
11
+ }
12
+ return bitcoinjs.address.fromOutputScript(outputScript, network);
13
+ }
14
+ exports.fromOutputScript = fromOutputScript;
15
+ function toOutputScript(address, network) {
16
+ if (networks_1.isValidNetwork(network) && networks_1.isZcash(network)) {
17
+ return zcashAddress.toOutputScript(address, network);
18
+ }
19
+ return bitcoinjs.address.toOutputScript(address, network);
20
+ }
21
+ exports.toOutputScript = toOutputScript;
22
+ function toBase58Check(hash, version, network) {
23
+ if (networks_1.isValidNetwork(network) && networks_1.isZcash(network)) {
24
+ return zcashAddress.toBase58Check(hash, version);
25
+ }
26
+ return bitcoinjs.address.toBase58Check(hash, version);
27
+ }
28
+ exports.toBase58Check = toBase58Check;
29
+ function fromBase58Check(address, network) {
30
+ if (networks_1.isValidNetwork(network) && networks_1.isZcash(network)) {
31
+ return zcashAddress.fromBase58Check(address);
32
+ }
33
+ return bitcoinjs.address.fromBase58Check(address);
34
+ }
35
+ exports.fromBase58Check = fromBase58Check;
36
+ _a = bitcoinjs.address, exports.fromBech32 = _a.fromBech32, exports.toBech32 = _a.toBech32;
37
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hZGRyZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7QUFBQSwyQ0FBMkM7QUFHM0MsMkRBQTJEO0FBQzNELHlDQUE4RDtBQUU5RCxTQUFnQixnQkFBZ0IsQ0FBQyxZQUFvQixFQUFFLE9BQWdCO0lBQ3JFLElBQUkseUJBQWMsQ0FBQyxPQUFPLENBQUMsSUFBSSxrQkFBTyxDQUFDLE9BQU8sQ0FBQyxFQUFFO1FBQy9DLE9BQU8sWUFBWSxDQUFDLGdCQUFnQixDQUFDLFlBQVksRUFBRSxPQUFPLENBQUMsQ0FBQztLQUM3RDtJQUNELE9BQU8sU0FBUyxDQUFDLE9BQU8sQ0FBQyxnQkFBZ0IsQ0FBQyxZQUFZLEVBQUUsT0FBNEIsQ0FBQyxDQUFDO0FBQ3hGLENBQUM7QUFMRCw0Q0FLQztBQUVELFNBQWdCLGNBQWMsQ0FBQyxPQUFlLEVBQUUsT0FBZ0I7SUFDOUQsSUFBSSx5QkFBYyxDQUFDLE9BQU8sQ0FBQyxJQUFJLGtCQUFPLENBQUMsT0FBTyxDQUFDLEVBQUU7UUFDL0MsT0FBTyxZQUFZLENBQUMsY0FBYyxDQUFDLE9BQU8sRUF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ZyB7XG4gIGlmIChpc1ZhbGlkTmV0d29yayhuZXR3b3JrKSAmJiBpc1pjYXNoKG5ldHdvcmspKSB7XG4gICAgcmV0dXJuIHpjYXNoQWRkcmVzcy50b0Jhc2U1OENoZWNrKGhhc2gsIHZlcnNpb24pO1xuICB9XG4gIHJldHVybiBiaXRjb2luanMuYWRkcmVzcy50b0Jhc2U1OENoZWNrKGhhc2gsIHZlcnNpb24pO1xufVxuXG5leHBvcnQgZnVuY3Rpb24gZnJvbUJhc2U1OENoZWNrKGFkZHJlc3M6IHN0cmluZywgbmV0d29yazogTmV0d29yayk6IEJhc2U1OENoZWNrUmVzdWx0IHtcbiAgaWYgKGlzVmFsaWROZXR3b3JrKG5ldHdvcmspICYmIGlzWmNhc2gobmV0d29yaykpIHtcbiAgICByZXR1cm4gemNhc2hBZGRyZXNzLmZyb21CYXNlNThDaGVjayhhZGRyZXNzKTtcbiAgfVxuICByZXR1cm4gYml0Y29pbmpzLmFkZHJlc3MuZnJvbUJhc2U1OENoZWNrKGFkZHJlc3MpO1xufVxuXG5leHBvcnQgY29uc3QgeyBmcm9tQmVjaDMyLCB0b0JlY2gzMiB9ID0gYml0Y29pbmpzLmFkZHJlc3M7XG5cbmV4cG9ydCB7IEJhc2U1OENoZWNrUmVzdWx0LCBCZWNoMzJSZXN1bHQgfTtcbiJdfQ==
@@ -0,0 +1,53 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Implements methods for nonstandard (non-canonical) address formats.
4
+ *
5
+ * Use `toOutputScriptTryFormats()` instead of `toOutputScript()` to parse addresses in
6
+ * non-canonical formats
7
+ */
8
+ import { Network } from './networks';
9
+ export declare const addressFormats: readonly ["default", "cashaddr"];
10
+ export declare type AddressFormat = typeof addressFormats[number];
11
+ /**
12
+ * @param format
13
+ * @param network
14
+ * @return true iff format is supported for network
15
+ */
16
+ export declare function isSupportedAddressFormat(format: AddressFormat, network: Network): boolean;
17
+ /**
18
+ * @param outputScript
19
+ * @param format
20
+ * @param network
21
+ * @return address formatted using provided AddressFormat
22
+ */
23
+ export declare function fromOutputScriptWithFormat(outputScript: Buffer, format: AddressFormat, network: Network): string;
24
+ /**
25
+ * @param address
26
+ * @param format
27
+ * @param network
28
+ * @return output script parsed with provided AddressFormat
29
+ */
30
+ export declare function toOutputScriptWithFormat(address: string, format: AddressFormat, network: Network): Buffer;
31
+ /**
32
+ * Attempts to parse address with different address formats, returns first hit.
33
+ * @param address
34
+ * @param network
35
+ * @param formats - defaults to all supported address formats for network
36
+ * @return tuple with [AddressFormat, Buffer] containing format and parsed output script
37
+ */
38
+ export declare function toOutputScriptAndFormat(address: string, network: Network, formats?: AddressFormat[]): [AddressFormat, Buffer];
39
+ /**
40
+ * Same as `toOutputScriptAndFormat`, only returning script
41
+ * @param address - {@see toOutputScriptAndFormat}
42
+ * @param network - {@see toOutputScriptAndFormat}
43
+ * @param formats - {@see toOutputScriptAndFormat}
44
+ * @return parsed output script
45
+ */
46
+ export declare function toOutputScriptTryFormats(address: string, network: Network, formats?: AddressFormat[]): Buffer;
47
+ /**
48
+ * @param address
49
+ * @param network
50
+ * @return address in canonical format
51
+ */
52
+ export declare function toCanonicalFormat(address: string, network: Network): string;
53
+ //# sourceMappingURL=addressFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addressFormat.d.ts","sourceRoot":"","sources":["../../src/addressFormat.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,OAAO,EAA8B,OAAO,EAAY,MAAM,YAAY,CAAC;AAK3E,eAAO,MAAM,cAAc,kCAAmC,CAAC;AAE/D,oBAAY,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAQzF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAYhH;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAYzG;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,aAAa,EAAE,GACxB,CAAC,aAAa,EAAE,MAAM,CAAC,CAczB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,CAG7G;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAE3E"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toCanonicalFormat = exports.toOutputScriptTryFormats = exports.toOutputScriptAndFormat = exports.toOutputScriptWithFormat = exports.fromOutputScriptWithFormat = exports.isSupportedAddressFormat = exports.addressFormats = void 0;
4
+ /**
5
+ * Implements methods for nonstandard (non-canonical) address formats.
6
+ *
7
+ * Use `toOutputScriptTryFormats()` instead of `toOutputScript()` to parse addresses in
8
+ * non-canonical formats
9
+ */
10
+ const networks_1 = require("./networks");
11
+ const address_1 = require("./address");
12
+ const bitgo_1 = require("./bitgo");
13
+ exports.addressFormats = ['default', 'cashaddr'];
14
+ /**
15
+ * @param format
16
+ * @param network
17
+ * @return true iff format is supported for network
18
+ */
19
+ function isSupportedAddressFormat(format, network) {
20
+ switch (format) {
21
+ case 'default':
22
+ return true;
23
+ case 'cashaddr':
24
+ return [networks_1.networks.bitcoincash, networks_1.networks.ecash].includes(networks_1.getMainnet(network));
25
+ }
26
+ throw new Error(`unknown address format ${format}`);
27
+ }
28
+ exports.isSupportedAddressFormat = isSupportedAddressFormat;
29
+ /**
30
+ * @param outputScript
31
+ * @param format
32
+ * @param network
33
+ * @return address formatted using provided AddressFormat
34
+ */
35
+ function fromOutputScriptWithFormat(outputScript, format, network) {
36
+ if (!isSupportedAddressFormat(format, network)) {
37
+ throw new Error(`unsupported address format ${format} for network ${networks_1.getNetworkName(network)}`);
38
+ }
39
+ switch (networks_1.getMainnet(network)) {
40
+ case networks_1.networks.bitcoincash:
41
+ case networks_1.networks.ecash:
42
+ return bitgo_1.bcashAddress.fromOutputScriptWithFormat(outputScript, format, network);
43
+ default:
44
+ return address_1.fromOutputScript(outputScript, network);
45
+ }
46
+ }
47
+ exports.fromOutputScriptWithFormat = fromOutputScriptWithFormat;
48
+ /**
49
+ * @param address
50
+ * @param format
51
+ * @param network
52
+ * @return output script parsed with provided AddressFormat
53
+ */
54
+ function toOutputScriptWithFormat(address, format, network) {
55
+ if (!isSupportedAddressFormat(format, network)) {
56
+ throw new Error(`unsupported address format ${format} for network ${networks_1.getNetworkName(network)}`);
57
+ }
58
+ switch (networks_1.getMainnet(network)) {
59
+ case networks_1.networks.bitcoincash:
60
+ case networks_1.networks.ecash:
61
+ return bitgo_1.bcashAddress.toOutputScriptWithFormat(address, format, network);
62
+ default:
63
+ return address_1.toOutputScript(address, network);
64
+ }
65
+ }
66
+ exports.toOutputScriptWithFormat = toOutputScriptWithFormat;
67
+ /**
68
+ * Attempts to parse address with different address formats, returns first hit.
69
+ * @param address
70
+ * @param network
71
+ * @param formats - defaults to all supported address formats for network
72
+ * @return tuple with [AddressFormat, Buffer] containing format and parsed output script
73
+ */
74
+ function toOutputScriptAndFormat(address, network, formats) {
75
+ if (!formats) {
76
+ formats = exports.addressFormats.filter((f) => isSupportedAddressFormat(f, network));
77
+ }
78
+ for (const format of formats) {
79
+ try {
80
+ return [format, toOutputScriptWithFormat(address, format, network)];
81
+ }
82
+ catch (e) {
83
+ // try next
84
+ }
85
+ }
86
+ throw new Error(`could not parse outputScript [formats=${formats}]`);
87
+ }
88
+ exports.toOutputScriptAndFormat = toOutputScriptAndFormat;
89
+ /**
90
+ * Same as `toOutputScriptAndFormat`, only returning script
91
+ * @param address - {@see toOutputScriptAndFormat}
92
+ * @param network - {@see toOutputScriptAndFormat}
93
+ * @param formats - {@see toOutputScriptAndFormat}
94
+ * @return parsed output script
95
+ */
96
+ function toOutputScriptTryFormats(address, network, formats) {
97
+ const [, outputScript] = toOutputScriptAndFormat(address, network, formats);
98
+ return outputScript;
99
+ }
100
+ exports.toOutputScriptTryFormats = toOutputScriptTryFormats;
101
+ /**
102
+ * @param address
103
+ * @param network
104
+ * @return address in canonical format
105
+ */
106
+ function toCanonicalFormat(address, network) {
107
+ return address_1.fromOutputScript(toOutputScriptTryFormats(address, network), network);
108
+ }
109
+ exports.toCanonicalFormat = toCanonicalFormat;
110
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWRkcmVzc0Zvcm1hdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9hZGRyZXNzRm9ybWF0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBOzs7OztHQUtHO0FBQ0gseUNBQTJFO0FBQzNFLHVDQUE2RDtBQUU3RCxtQ0FBdUM7QUFFMUIsUUFBQSxjQUFjLEdBQUcsQ0FBQyxTQUFTLEVBQUUsVUFBVSxDQUFVLENBQUM7QUFJL0Q7Ozs7R0FJRztBQUNILFNBQWdCLHdCQUF3QixDQUFDLE1BQXFCLEVBQUUsT0FBZ0I7SUFDOUUsUUFBUSxNQUFNLEVBQUU7UUFDZCxLQUFLLFNBQVM7WUFDWixPQUFPLElBQUksQ0FBQztRQUNkLEtBQUssVUFBVTtZQUNiLE9BQU8sQ0FBQyxtQkFBUSxDQUFDLFdBQVcsRUFBRSxtQkFBUSxDQUFDLEtBQUssQ0FBQyxDQUFDLFFBQVEsQ0FBQyxxQkFB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2NyaXB0VHJ5Rm9ybWF0cyhhZGRyZXNzLCBuZXR3b3JrKSwgbmV0d29yayk7XG59XG4iXX0=
@@ -0,0 +1,51 @@
1
+ /// <reference types="node" />
2
+ import { ProprietaryKeyValueData, UtxoPsbt } from './UtxoPsbt';
3
+ import { BIP32Interface } from 'bip32';
4
+ import { Tuple } from './types';
5
+ /**
6
+ * Participant key value object.
7
+ */
8
+ export interface PsbtMusig2ParticipantsKeyValueData {
9
+ tapOutputKey: Buffer;
10
+ tapInternalKey: Buffer;
11
+ participantPubKeys: Tuple<Buffer>;
12
+ }
13
+ /**
14
+ * Nonce key value object.
15
+ */
16
+ export interface PsbtMusig2NoncesKeyValueData {
17
+ participantPubKey: Buffer;
18
+ tapOutputKey: Buffer;
19
+ pubNonces: Buffer;
20
+ }
21
+ /**
22
+ * Psbt proprietary key val util function for participants pub keys. SubType is 0x01
23
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
24
+ * @return x-only tapOutputKey||tapInternalKey as sub keydata, plain sigining participant keys as valuedata
25
+ */
26
+ export declare function encodePsbtMusig2ParticipantsKeyValData(participantsKeyValData: PsbtMusig2ParticipantsKeyValueData): ProprietaryKeyValueData;
27
+ /**
28
+ * Psbt proprietary key val util function for pub nonce. SubType is 0x02
29
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
30
+ * @return plain-participantPubKey||x-only-tapOutputKey as sub keydata, 66 bytes of 2 pub nonces as valuedata
31
+ */
32
+ export declare function encodePsbtMusig2PubNonceKeyValData(noncesKeyValueData: PsbtMusig2NoncesKeyValueData): ProprietaryKeyValueData;
33
+ /**
34
+ * Decodes proprietary key value data for participant pub keys
35
+ * @param kv
36
+ */
37
+ export declare function decodePsbtMusig2ParticipantsKeyValData(kv: ProprietaryKeyValueData): PsbtMusig2ParticipantsKeyValueData;
38
+ export declare function createTapInternalKey(plainPubKeys: Buffer[]): Buffer;
39
+ export declare function createTapOutputKey(internalPubKey: Buffer, tapTreeRoot: Buffer): Buffer;
40
+ /**
41
+ * Generates and sets Musig2 nonces to p2trMusig2 key path spending inputs.
42
+ * tapInternalkey, tapMerkleRoot, tapBip32Derivation for rootWalletKey are required per p2trMusig2 key path input.
43
+ * Also participant keys are required from psbt proprietary key values.
44
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
45
+ * @param psbt
46
+ * @param rootWalletKey
47
+ * @param sessionId If provided it must either be a counter unique to this secret key,
48
+ * (converted to an array of 32 bytes), or 32 uniformly random bytes.
49
+ */
50
+ export declare function setMusig2Nonces(psbt: UtxoPsbt, rootWalletKey: BIP32Interface, sessionId?: Buffer): void;
51
+ //# sourceMappingURL=Musig2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Musig2.d.ts","sourceRoot":"","sources":["../../../src/bitgo/Musig2.ts"],"names":[],"mappings":";AAAA,OAAO,EAA+B,uBAAuB,EAAE,QAAQ,EAAyB,MAAM,YAAY,CAAC;AAEnH,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAKhC;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,sCAAsC,CACpD,sBAAsB,EAAE,kCAAkC,GACzD,uBAAuB,CAWzB;AAED;;;;GAIG;AACH,wBAAgB,kCAAkC,CAChD,kBAAkB,EAAE,4BAA4B,GAC/C,uBAAuB,CAczB;AAED;;;GAGG;AACH,wBAAgB,sCAAsC,CACpD,EAAE,EAAE,uBAAuB,GAC1B,kCAAkC,CAuBpC;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,MAAM,CAGnE;AAED,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAKtF;AA6FD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,cAAc,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAavG"}
@@ -0,0 +1,175 @@
1
+ "use strict";
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");
5
+ const outputScripts_1 = require("./outputScripts");
6
+ const noble_ecc_1 = require("../noble_ecc");
7
+ const taproot_1 = require("../taproot");
8
+ const utils_1 = require("bip174/src/lib/utils");
9
+ /**
10
+ * Psbt proprietary key val util function for participants pub keys. SubType is 0x01
11
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
12
+ * @return x-only tapOutputKey||tapInternalKey as sub keydata, plain sigining participant keys as valuedata
13
+ */
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));
17
+ const key = {
18
+ identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
19
+ subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
20
+ keydata: Buffer.concat(keydata),
21
+ };
22
+ return { key, value: Buffer.concat(value) };
23
+ }
24
+ exports.encodePsbtMusig2ParticipantsKeyValData = encodePsbtMusig2ParticipantsKeyValData;
25
+ /**
26
+ * Psbt proprietary key val util function for pub nonce. SubType is 0x02
27
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
28
+ * @return plain-participantPubKey||x-only-tapOutputKey as sub keydata, 66 bytes of 2 pub nonces as valuedata
29
+ */
30
+ function encodePsbtMusig2PubNonceKeyValData(noncesKeyValueData) {
31
+ if (noncesKeyValueData.pubNonces.length !== 66) {
32
+ throw new Error(`Invalid pubNonces length ${noncesKeyValueData.pubNonces.length}`);
33
+ }
34
+ const keydata = Buffer.concat([
35
+ outputScripts_1.checkPlainPublicKey(noncesKeyValueData.participantPubKey),
36
+ outputScripts_1.checkXOnlyPublicKey(noncesKeyValueData.tapOutputKey),
37
+ ]);
38
+ const key = {
39
+ identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
40
+ subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PUB_NONCE,
41
+ keydata,
42
+ };
43
+ return { key, value: noncesKeyValueData.pubNonces };
44
+ }
45
+ exports.encodePsbtMusig2PubNonceKeyValData = encodePsbtMusig2PubNonceKeyValData;
46
+ /**
47
+ * Decodes proprietary key value data for participant pub keys
48
+ * @param kv
49
+ */
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) {
53
+ throw new Error(`Invalid identifier ${kv.key.identifier} or subtype ${kv.key.subtype} for participants pub keys`);
54
+ }
55
+ const key = kv.key.keydata;
56
+ if (key.length !== 64) {
57
+ throw new Error(`Invalid keydata size ${key.length} for participant pub keys`);
58
+ }
59
+ const value = kv.value;
60
+ if (value.length !== 66) {
61
+ throw new Error(`Invalid valuedata size ${value.length} for participant pub keys`);
62
+ }
63
+ const participantPubKeys = [value.subarray(0, 33), value.subarray(33)];
64
+ if (participantPubKeys[0].equals(participantPubKeys[1])) {
65
+ throw new Error(`Duplicate participant pub keys found`);
66
+ }
67
+ return { tapOutputKey: key.subarray(0, 32), tapInternalKey: key.subarray(32), participantPubKeys };
68
+ }
69
+ exports.decodePsbtMusig2ParticipantsKeyValData = decodePsbtMusig2ParticipantsKeyValData;
70
+ 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))));
73
+ }
74
+ exports.createTapInternalKey = createTapInternalKey;
75
+ 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);
80
+ }
81
+ exports.createTapOutputKey = createTapOutputKey;
82
+ function deriveWalletPubKey(tapBip32Derivations, rootWalletKey) {
83
+ const myDerivations = tapBip32Derivations.filter((bipDv) => {
84
+ return bipDv.masterFingerprint.equals(rootWalletKey.fingerprint);
85
+ });
86
+ if (!myDerivations.length) {
87
+ throw new Error('Need one tapBip32Derivation masterFingerprint to match the rootWalletKey fingerprint');
88
+ }
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');
95
+ }
96
+ return rootWalletKey.derivePath(myDerivation[0].path).publicKey;
97
+ }
98
+ function getMusig2NonceKeyValueData(psbt, inputIndex, rootWalletKey, sessionId) {
99
+ var _a;
100
+ const input = utils_1.checkForInput(psbt.data.inputs, inputIndex);
101
+ if (!input.tapInternalKey) {
102
+ return;
103
+ }
104
+ if (!input.tapMerkleRoot) {
105
+ throw new Error('tapMerkleRoot is required to generate nonce');
106
+ }
107
+ if (!((_a = input.tapBip32Derivation) === null || _a === void 0 ? void 0 : _a.length)) {
108
+ throw new Error('tapBip32Derivation is required to generate nonce');
109
+ }
110
+ const participantsKeyVals = psbt.getProprietaryKeyVals(inputIndex, {
111
+ identifier: UtxoPsbt_1.PSBT_PROPRIETARY_IDENTIFIER,
112
+ subtype: UtxoPsbt_1.ProprietaryKeySubtype.MUSIG2_PARTICIPANT_PUB_KEYS,
113
+ });
114
+ if (participantsKeyVals.length !== 1) {
115
+ throw new Error(`Found ${participantsKeyVals.length} matching participant key value instead of 1`);
116
+ }
117
+ const participantKeyValData = decodePsbtMusig2ParticipantsKeyValData(participantsKeyVals[0]);
118
+ const participantPubKeys = participantKeyValData.participantPubKeys;
119
+ const tapInternalKey = createTapInternalKey(participantPubKeys);
120
+ if (!tapInternalKey.equals(participantKeyValData.tapInternalKey)) {
121
+ throw new Error('Invalid participants keyata tapInternalKey');
122
+ }
123
+ const tapOutputKey = createTapOutputKey(tapInternalKey, input.tapMerkleRoot);
124
+ if (!tapOutputKey.equals(participantKeyValData.tapOutputKey)) {
125
+ throw new Error('Invalid participants keyata tapOutputKey');
126
+ }
127
+ if (!tapInternalKey.equals(input.tapInternalKey)) {
128
+ throw new Error('tapInternalKey and aggregated participant pub keys does not match');
129
+ }
130
+ const derivedPubKey = deriveWalletPubKey(input.tapBip32Derivation, rootWalletKey);
131
+ const participantPubKey = participantPubKeys.find((pubKey) => pubKey.equals(derivedPubKey));
132
+ if (!Buffer.isBuffer(participantPubKey)) {
133
+ throw new Error('participant plain pub key should match one tapBip32Derivation plain pub key');
134
+ }
135
+ const { hash } = psbt.getTaprootHashForSigChecked(inputIndex);
136
+ const nonceGenArgs = {
137
+ sessionId,
138
+ publicKey: participantPubKey,
139
+ xOnlyPublicKey: tapOutputKey,
140
+ msg: hash,
141
+ secretKey: rootWalletKey.privateKey,
142
+ };
143
+ const pubNonces = Buffer.from(noble_ecc_1.musig.nonceGen(nonceGenArgs));
144
+ return encodePsbtMusig2PubNonceKeyValData({
145
+ participantPubKey,
146
+ tapOutputKey,
147
+ pubNonces,
148
+ });
149
+ }
150
+ /**
151
+ * Generates and sets Musig2 nonces to p2trMusig2 key path spending inputs.
152
+ * tapInternalkey, tapMerkleRoot, tapBip32Derivation for rootWalletKey are required per p2trMusig2 key path input.
153
+ * Also participant keys are required from psbt proprietary key values.
154
+ * Ref: https://gist.github.com/sanket1729/4b525c6049f4d9e034d27368c49f28a6
155
+ * @param psbt
156
+ * @param rootWalletKey
157
+ * @param sessionId If provided it must either be a counter unique to this secret key,
158
+ * (converted to an array of 32 bytes), or 32 uniformly random bytes.
159
+ */
160
+ function setMusig2Nonces(psbt, rootWalletKey, sessionId) {
161
+ if (rootWalletKey.isNeutered()) {
162
+ throw new Error('private key is required to generate nonce');
163
+ }
164
+ if (Buffer.isBuffer(sessionId) && sessionId.length !== 32) {
165
+ throw new Error(`Invalid sessionId size ${sessionId.length}`);
166
+ }
167
+ psbt.data.inputs.forEach((input, inputIndex) => {
168
+ const noncesKeyValueData = getMusig2NonceKeyValueData(psbt, inputIndex, rootWalletKey, sessionId);
169
+ if (noncesKeyValueData) {
170
+ psbt.addProprietaryKeyValToInput(inputIndex, noncesKeyValueData);
171
+ }
172
+ });
173
+ }
174
+ exports.setMusig2Nonces = setMusig2Nonces;
175
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTXVzaWcyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2JpdGdvL011c2lnMi50cyJdLCJuYW1lcyI6W10sIm1hcH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