@ledgerhq/hw-app-btc 6.24.2-monorepo.0 → 6.24.2-monorepo.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (283) hide show
  1. package/.turbo/turbo-build.log +5 -1
  2. package/CHANGELOG.md +9 -0
  3. package/lib/Btc.d.ts +149 -0
  4. package/lib/Btc.d.ts.map +1 -0
  5. package/lib/Btc.js +357 -0
  6. package/lib/Btc.js.map +1 -0
  7. package/lib/BtcNew.d.ts +122 -0
  8. package/lib/BtcNew.d.ts.map +1 -0
  9. package/lib/BtcNew.js +451 -0
  10. package/lib/BtcNew.js.map +1 -0
  11. package/lib/BtcOld.d.ts +120 -0
  12. package/lib/BtcOld.d.ts.map +1 -0
  13. package/lib/BtcOld.js +263 -0
  14. package/lib/BtcOld.js.map +1 -0
  15. package/lib/bip32.d.ts +13 -0
  16. package/lib/bip32.d.ts.map +1 -0
  17. package/lib/bip32.js +57 -0
  18. package/lib/bip32.js.map +1 -0
  19. package/lib/buffertools.d.ts +30 -0
  20. package/lib/buffertools.d.ts.map +1 -0
  21. package/lib/buffertools.js +132 -0
  22. package/lib/buffertools.js.map +1 -0
  23. package/lib/compressPublicKey.d.ts +3 -0
  24. package/lib/compressPublicKey.d.ts.map +1 -0
  25. package/lib/compressPublicKey.js +11 -0
  26. package/lib/compressPublicKey.js.map +1 -0
  27. package/lib/constants.d.ts +13 -0
  28. package/lib/constants.d.ts.map +1 -0
  29. package/lib/constants.js +17 -0
  30. package/lib/constants.js.map +1 -0
  31. package/lib/createTransaction.d.ts +35 -0
  32. package/lib/createTransaction.d.ts.map +1 -0
  33. package/lib/createTransaction.js +411 -0
  34. package/lib/createTransaction.js.map +1 -0
  35. package/lib/debug.d.ts +4 -0
  36. package/lib/debug.d.ts.map +1 -0
  37. package/lib/debug.js +45 -0
  38. package/lib/debug.js.map +1 -0
  39. package/lib/finalizeInput.d.ts +5 -0
  40. package/lib/finalizeInput.d.ts.map +1 -0
  41. package/lib/finalizeInput.js +81 -0
  42. package/lib/finalizeInput.js.map +1 -0
  43. package/lib/getAppAndVersion.d.ts +9 -0
  44. package/lib/getAppAndVersion.d.ts.map +1 -0
  45. package/lib/getAppAndVersion.js +69 -0
  46. package/lib/getAppAndVersion.js.map +1 -0
  47. package/lib/getTrustedInput.d.ts +6 -0
  48. package/lib/getTrustedInput.d.ts.map +1 -0
  49. package/lib/getTrustedInput.js +275 -0
  50. package/lib/getTrustedInput.js.map +1 -0
  51. package/lib/getTrustedInputBIP143.d.ts +4 -0
  52. package/lib/getTrustedInputBIP143.d.ts.map +1 -0
  53. package/lib/getTrustedInputBIP143.js +34 -0
  54. package/lib/getTrustedInputBIP143.js.map +1 -0
  55. package/lib/getWalletPublicKey.d.ts +15 -0
  56. package/lib/getWalletPublicKey.d.ts.map +1 -0
  57. package/lib/getWalletPublicKey.js +93 -0
  58. package/lib/getWalletPublicKey.js.map +1 -0
  59. package/lib/hashPublicKey.d.ts +3 -0
  60. package/lib/hashPublicKey.d.ts.map +1 -0
  61. package/lib/hashPublicKey.js +13 -0
  62. package/lib/hashPublicKey.js.map +1 -0
  63. package/lib/index.d.ts +3 -0
  64. package/lib/index.d.ts.map +1 -0
  65. package/lib/index.js +8 -0
  66. package/lib/index.js.map +1 -0
  67. package/lib/newops/accounttype.d.ts +110 -0
  68. package/lib/newops/accounttype.d.ts.map +1 -0
  69. package/lib/newops/accounttype.js +236 -0
  70. package/lib/newops/accounttype.js.map +1 -0
  71. package/lib/newops/appClient.d.ts +18 -0
  72. package/lib/newops/appClient.d.ts.map +1 -0
  73. package/lib/newops/appClient.js +243 -0
  74. package/lib/newops/appClient.js.map +1 -0
  75. package/lib/newops/clientCommands.d.ts +77 -0
  76. package/lib/newops/clientCommands.d.ts.map +1 -0
  77. package/lib/newops/clientCommands.js +353 -0
  78. package/lib/newops/clientCommands.js.map +1 -0
  79. package/lib/newops/merkelizedPsbt.d.ts +26 -0
  80. package/lib/newops/merkelizedPsbt.d.ts.map +1 -0
  81. package/lib/newops/merkelizedPsbt.js +102 -0
  82. package/lib/newops/merkelizedPsbt.js.map +1 -0
  83. package/lib/newops/merkle.d.ts +34 -0
  84. package/lib/newops/merkle.d.ts.map +1 -0
  85. package/lib/newops/merkle.js +138 -0
  86. package/lib/newops/merkle.js.map +1 -0
  87. package/lib/newops/merkleMap.d.ts +25 -0
  88. package/lib/newops/merkleMap.d.ts.map +1 -0
  89. package/lib/newops/merkleMap.js +47 -0
  90. package/lib/newops/merkleMap.js.map +1 -0
  91. package/lib/newops/policy.d.ts +22 -0
  92. package/lib/newops/policy.d.ts.map +1 -0
  93. package/lib/newops/policy.js +48 -0
  94. package/lib/newops/policy.js.map +1 -0
  95. package/lib/newops/psbtExtractor.d.ts +10 -0
  96. package/lib/newops/psbtExtractor.d.ts.map +1 -0
  97. package/lib/newops/psbtExtractor.js +42 -0
  98. package/lib/newops/psbtExtractor.js.map +1 -0
  99. package/lib/newops/psbtFinalizer.d.ts +17 -0
  100. package/lib/newops/psbtFinalizer.d.ts.map +1 -0
  101. package/lib/newops/psbtFinalizer.js +135 -0
  102. package/lib/newops/psbtFinalizer.js.map +1 -0
  103. package/lib/newops/psbtv2.d.ts +149 -0
  104. package/lib/newops/psbtv2.d.ts.map +1 -0
  105. package/lib/newops/psbtv2.js +506 -0
  106. package/lib/newops/psbtv2.js.map +1 -0
  107. package/lib/serializeTransaction.d.ts +10 -0
  108. package/lib/serializeTransaction.d.ts.map +1 -0
  109. package/lib/serializeTransaction.js +72 -0
  110. package/lib/serializeTransaction.js.map +1 -0
  111. package/lib/shouldUseTrustedInputForSegwit.d.ts +5 -0
  112. package/lib/shouldUseTrustedInputForSegwit.d.ts.map +1 -0
  113. package/lib/shouldUseTrustedInputForSegwit.js +17 -0
  114. package/lib/shouldUseTrustedInputForSegwit.js.map +1 -0
  115. package/lib/signMessage.d.ts +10 -0
  116. package/lib/signMessage.d.ts.map +1 -0
  117. package/lib/signMessage.js +118 -0
  118. package/lib/signMessage.js.map +1 -0
  119. package/lib/signP2SHTransaction.d.ts +21 -0
  120. package/lib/signP2SHTransaction.d.ts.map +1 -0
  121. package/lib/signP2SHTransaction.js +208 -0
  122. package/lib/signP2SHTransaction.js.map +1 -0
  123. package/lib/signTransaction.d.ts +4 -0
  124. package/lib/signTransaction.d.ts.map +1 -0
  125. package/lib/signTransaction.js +36 -0
  126. package/lib/signTransaction.js.map +1 -0
  127. package/lib/splitTransaction.d.ts +3 -0
  128. package/lib/splitTransaction.d.ts.map +1 -0
  129. package/lib/splitTransaction.js +142 -0
  130. package/lib/splitTransaction.js.map +1 -0
  131. package/lib/startUntrustedHashTransactionInput.d.ts +9 -0
  132. package/lib/startUntrustedHashTransactionInput.d.ts.map +1 -0
  133. package/lib/startUntrustedHashTransactionInput.js +197 -0
  134. package/lib/startUntrustedHashTransactionInput.js.map +1 -0
  135. package/lib/types.d.ts +34 -0
  136. package/lib/types.d.ts.map +1 -0
  137. package/lib/types.js +3 -0
  138. package/lib/types.js.map +1 -0
  139. package/lib/varint.d.ts +4 -0
  140. package/lib/varint.d.ts.map +1 -0
  141. package/lib/varint.js +45 -0
  142. package/lib/varint.js.map +1 -0
  143. package/lib-es/Btc.d.ts +149 -0
  144. package/lib-es/Btc.d.ts.map +1 -0
  145. package/lib-es/Btc.js +329 -0
  146. package/lib-es/Btc.js.map +1 -0
  147. package/lib-es/BtcNew.d.ts +122 -0
  148. package/lib-es/BtcNew.d.ts.map +1 -0
  149. package/lib-es/BtcNew.js +444 -0
  150. package/lib-es/BtcNew.js.map +1 -0
  151. package/lib-es/BtcOld.d.ts +120 -0
  152. package/lib-es/BtcOld.d.ts.map +1 -0
  153. package/lib-es/BtcOld.js +258 -0
  154. package/lib-es/BtcOld.js.map +1 -0
  155. package/lib-es/bip32.d.ts +13 -0
  156. package/lib-es/bip32.d.ts.map +1 -0
  157. package/lib-es/bip32.js +44 -0
  158. package/lib-es/bip32.js.map +1 -0
  159. package/lib-es/buffertools.d.ts +30 -0
  160. package/lib-es/buffertools.d.ts.map +1 -0
  161. package/lib-es/buffertools.js +124 -0
  162. package/lib-es/buffertools.js.map +1 -0
  163. package/lib-es/compressPublicKey.d.ts +3 -0
  164. package/lib-es/compressPublicKey.d.ts.map +1 -0
  165. package/lib-es/compressPublicKey.js +7 -0
  166. package/lib-es/compressPublicKey.js.map +1 -0
  167. package/lib-es/constants.d.ts +13 -0
  168. package/lib-es/constants.d.ts.map +1 -0
  169. package/lib-es/constants.js +14 -0
  170. package/lib-es/constants.js.map +1 -0
  171. package/lib-es/createTransaction.d.ts +35 -0
  172. package/lib-es/createTransaction.d.ts.map +1 -0
  173. package/lib-es/createTransaction.js +407 -0
  174. package/lib-es/createTransaction.js.map +1 -0
  175. package/lib-es/debug.d.ts +4 -0
  176. package/lib-es/debug.d.ts.map +1 -0
  177. package/lib-es/debug.js +40 -0
  178. package/lib-es/debug.js.map +1 -0
  179. package/lib-es/finalizeInput.d.ts +5 -0
  180. package/lib-es/finalizeInput.d.ts.map +1 -0
  181. package/lib-es/finalizeInput.js +76 -0
  182. package/lib-es/finalizeInput.js.map +1 -0
  183. package/lib-es/getAppAndVersion.d.ts +9 -0
  184. package/lib-es/getAppAndVersion.d.ts.map +1 -0
  185. package/lib-es/getAppAndVersion.js +62 -0
  186. package/lib-es/getAppAndVersion.js.map +1 -0
  187. package/lib-es/getTrustedInput.d.ts +6 -0
  188. package/lib-es/getTrustedInput.d.ts.map +1 -0
  189. package/lib-es/getTrustedInput.js +267 -0
  190. package/lib-es/getTrustedInput.js.map +1 -0
  191. package/lib-es/getTrustedInputBIP143.d.ts +4 -0
  192. package/lib-es/getTrustedInputBIP143.d.ts.map +1 -0
  193. package/lib-es/getTrustedInputBIP143.js +27 -0
  194. package/lib-es/getTrustedInputBIP143.js.map +1 -0
  195. package/lib-es/getWalletPublicKey.d.ts +15 -0
  196. package/lib-es/getWalletPublicKey.d.ts.map +1 -0
  197. package/lib-es/getWalletPublicKey.js +89 -0
  198. package/lib-es/getWalletPublicKey.js.map +1 -0
  199. package/lib-es/hashPublicKey.d.ts +3 -0
  200. package/lib-es/hashPublicKey.d.ts.map +1 -0
  201. package/lib-es/hashPublicKey.js +6 -0
  202. package/lib-es/hashPublicKey.js.map +1 -0
  203. package/lib-es/index.d.ts +3 -0
  204. package/lib-es/index.d.ts.map +1 -0
  205. package/lib-es/index.js +3 -0
  206. package/lib-es/index.js.map +1 -0
  207. package/lib-es/newops/accounttype.d.ts +110 -0
  208. package/lib-es/newops/accounttype.d.ts.map +1 -0
  209. package/lib-es/newops/accounttype.js +233 -0
  210. package/lib-es/newops/accounttype.js.map +1 -0
  211. package/lib-es/newops/appClient.d.ts +18 -0
  212. package/lib-es/newops/appClient.d.ts.map +1 -0
  213. package/lib-es/newops/appClient.js +240 -0
  214. package/lib-es/newops/appClient.js.map +1 -0
  215. package/lib-es/newops/clientCommands.d.ts +77 -0
  216. package/lib-es/newops/clientCommands.d.ts.map +1 -0
  217. package/lib-es/newops/clientCommands.js +350 -0
  218. package/lib-es/newops/clientCommands.js.map +1 -0
  219. package/lib-es/newops/merkelizedPsbt.d.ts +26 -0
  220. package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -0
  221. package/lib-es/newops/merkelizedPsbt.js +99 -0
  222. package/lib-es/newops/merkelizedPsbt.js.map +1 -0
  223. package/lib-es/newops/merkle.d.ts +34 -0
  224. package/lib-es/newops/merkle.d.ts.map +1 -0
  225. package/lib-es/newops/merkle.js +134 -0
  226. package/lib-es/newops/merkle.js.map +1 -0
  227. package/lib-es/newops/merkleMap.d.ts +25 -0
  228. package/lib-es/newops/merkleMap.d.ts.map +1 -0
  229. package/lib-es/newops/merkleMap.js +44 -0
  230. package/lib-es/newops/merkleMap.js.map +1 -0
  231. package/lib-es/newops/policy.d.ts +22 -0
  232. package/lib-es/newops/policy.d.ts.map +1 -0
  233. package/lib-es/newops/policy.js +44 -0
  234. package/lib-es/newops/policy.js.map +1 -0
  235. package/lib-es/newops/psbtExtractor.d.ts +10 -0
  236. package/lib-es/newops/psbtExtractor.d.ts.map +1 -0
  237. package/lib-es/newops/psbtExtractor.js +38 -0
  238. package/lib-es/newops/psbtExtractor.js.map +1 -0
  239. package/lib-es/newops/psbtFinalizer.d.ts +17 -0
  240. package/lib-es/newops/psbtFinalizer.d.ts.map +1 -0
  241. package/lib-es/newops/psbtFinalizer.js +131 -0
  242. package/lib-es/newops/psbtFinalizer.js.map +1 -0
  243. package/lib-es/newops/psbtv2.d.ts +149 -0
  244. package/lib-es/newops/psbtv2.d.ts.map +1 -0
  245. package/lib-es/newops/psbtv2.js +503 -0
  246. package/lib-es/newops/psbtv2.js.map +1 -0
  247. package/lib-es/serializeTransaction.d.ts +10 -0
  248. package/lib-es/serializeTransaction.d.ts.map +1 -0
  249. package/lib-es/serializeTransaction.js +67 -0
  250. package/lib-es/serializeTransaction.js.map +1 -0
  251. package/lib-es/shouldUseTrustedInputForSegwit.d.ts +5 -0
  252. package/lib-es/shouldUseTrustedInputForSegwit.d.ts.map +1 -0
  253. package/lib-es/shouldUseTrustedInputForSegwit.js +10 -0
  254. package/lib-es/shouldUseTrustedInputForSegwit.js.map +1 -0
  255. package/lib-es/signMessage.d.ts +10 -0
  256. package/lib-es/signMessage.d.ts.map +1 -0
  257. package/lib-es/signMessage.js +111 -0
  258. package/lib-es/signMessage.js.map +1 -0
  259. package/lib-es/signP2SHTransaction.d.ts +21 -0
  260. package/lib-es/signP2SHTransaction.d.ts.map +1 -0
  261. package/lib-es/signP2SHTransaction.js +204 -0
  262. package/lib-es/signP2SHTransaction.js.map +1 -0
  263. package/lib-es/signTransaction.d.ts +4 -0
  264. package/lib-es/signTransaction.d.ts.map +1 -0
  265. package/lib-es/signTransaction.js +32 -0
  266. package/lib-es/signTransaction.js.map +1 -0
  267. package/lib-es/splitTransaction.d.ts +3 -0
  268. package/lib-es/splitTransaction.d.ts.map +1 -0
  269. package/lib-es/splitTransaction.js +138 -0
  270. package/lib-es/splitTransaction.js.map +1 -0
  271. package/lib-es/startUntrustedHashTransactionInput.d.ts +9 -0
  272. package/lib-es/startUntrustedHashTransactionInput.d.ts.map +1 -0
  273. package/lib-es/startUntrustedHashTransactionInput.js +192 -0
  274. package/lib-es/startUntrustedHashTransactionInput.js.map +1 -0
  275. package/lib-es/types.d.ts +34 -0
  276. package/lib-es/types.d.ts.map +1 -0
  277. package/lib-es/types.js +2 -0
  278. package/lib-es/types.js.map +1 -0
  279. package/lib-es/varint.d.ts +4 -0
  280. package/lib-es/varint.d.ts.map +1 -0
  281. package/lib-es/varint.js +40 -0
  282. package/lib-es/varint.js.map +1 -0
  283. package/package.json +5 -5
@@ -0,0 +1,122 @@
1
+ import type { CreateTransactionArg } from "./createTransaction";
2
+ import { AppAndVersion } from "./getAppAndVersion";
3
+ import type { AddressFormat } from "./getWalletPublicKey";
4
+ import { AppClient as Client } from "./newops/appClient";
5
+ export declare function canSupportApp(appAndVersion: AppAndVersion): boolean;
6
+ /**
7
+ * This class implements the same interface as BtcOld (formerly
8
+ * named Btc), but interacts with Bitcoin hardware app version 2+
9
+ * which uses a totally new APDU protocol. This new
10
+ * protocol is documented at
11
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
12
+ *
13
+ * Since the interface must remain compatible with BtcOld, the methods
14
+ * of this class are quite clunky, because it needs to adapt legacy
15
+ * input data into the PSBT process. In the future, a new interface should
16
+ * be developed that exposes PSBT to the outer world, which would render
17
+ * a much cleaner implementation.
18
+ */
19
+ export default class BtcNew {
20
+ private client;
21
+ constructor(client: Client);
22
+ /**
23
+ * This is a new method that allow users to get an xpub at a standard path.
24
+ * Standard paths are described at
25
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
26
+ *
27
+ * This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
28
+ * M/44'/N'/x'/**
29
+ * M/48'/N'/x'/y'/**
30
+ * M/49'/N'/x'/**
31
+ * M/84'/N'/x'/**
32
+ * M/86'/N'/x'/**
33
+ *
34
+ * The method was added because of added security in the hardware app v2+. The
35
+ * new hardware app will allow export of any xpub up to and including the
36
+ * deepest hardened key of standard derivation paths, whereas the old app
37
+ * would allow export of any key.
38
+ *
39
+ * This caused an issue for callers of this class, who only had
40
+ * getWalletPublicKey() to call which means they have to constuct xpub
41
+ * themselves:
42
+ *
43
+ * Suppose a user of this class wants to create an account xpub on a standard
44
+ * path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
45
+ * by requesting the parent key M/44'/0'. The new app won't allow that, because
46
+ * it only allows exporting deepest level hardened path. So the options are to
47
+ * allow requesting M/44'/0' from the app, or to add a new function
48
+ * "getWalletXpub".
49
+ *
50
+ * We opted for adding a new function, which can greatly simplify client code.
51
+ */
52
+ getWalletXpub({ path, xpubVersion, }: {
53
+ path: string;
54
+ xpubVersion: number;
55
+ }): Promise<string>;
56
+ /**
57
+ * This method returns a public key, a bitcoin address, and and a chaincode
58
+ * for a specific derivation path.
59
+ *
60
+ * Limitation: If the path is not a leaf node of a standard path, the address
61
+ * will be the empty string "", see this.getWalletAddress() for details.
62
+ */
63
+ getWalletPublicKey(path: string, opts?: {
64
+ verify?: boolean;
65
+ format?: AddressFormat;
66
+ }): Promise<{
67
+ publicKey: string;
68
+ bitcoinAddress: string;
69
+ chainCode: string;
70
+ }>;
71
+ /**
72
+ * Get an address for the specified path.
73
+ *
74
+ * If display is true, we must get the address from the device, which would require
75
+ * us to determine WalletPolicy. This requires two *extra* queries to the device, one
76
+ * for the account xpub and one for master key fingerprint.
77
+ *
78
+ * If display is false we *could* generate the address ourselves, but chose to
79
+ * get it from the device to save development time. However, it shouldn't take
80
+ * too much time to implement local address generation.
81
+ *
82
+ * Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
83
+ * way to get the address from the device. In this case we have to create it
84
+ * ourselves, but we don't at this time, and instead return an empty ("") address.
85
+ */
86
+ private getWalletAddress;
87
+ /**
88
+ * Build and sign a transaction. See Btc.createPaymentTransactionNew for
89
+ * details on how to use this method.
90
+ *
91
+ * This method will convert the legacy arguments, CreateTransactionArg, into
92
+ * a psbt which is finally signed and finalized, and the extracted fully signed
93
+ * transaction is returned.
94
+ */
95
+ createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
96
+ /**
97
+ * Calculates an output script along with public key and possible redeemScript
98
+ * from a path and accountType. The accountPath must be a prefix of path.
99
+ *
100
+ * @returns an object with output script (property "script"), redeemScript (if
101
+ * wrapped p2wpkh), and pubkey at provided path. The values of these three
102
+ * properties depend on the accountType used.
103
+ */
104
+ private outputScriptAt;
105
+ /**
106
+ * Adds relevant data about an input to the psbt. This includes sequence,
107
+ * previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
108
+ * public key and its derivation path.
109
+ */
110
+ private setInput;
111
+ /**
112
+ * This implements the "Signer" role of the BIP370 transaction signing
113
+ * process.
114
+ *
115
+ * It ssks the hardware device to sign the a psbt using the specified wallet
116
+ * policy. This method assumes BIP32 derived keys are used for all inputs, see
117
+ * comment in-line. The signatures returned from the hardware device is added
118
+ * to the appropriate input fields of the PSBT.
119
+ */
120
+ private signPsbt;
121
+ }
122
+ //# sourceMappingURL=BtcNew.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAczD,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAKnE;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,aAAa,CAAC,EAClB,IAAI,EACJ,WAAW,GACZ,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,CAAC;IAYnB;;;;;;OAMG;IACG,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,MAAM,CAAC,EAAE,aAAa,CAAC;KACxB,GACA,OAAO,CAAC;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IAsBF;;;;;;;;;;;;;;OAcG;YACW,gBAAgB;IAyB9B;;;;;;;OAOG;IACG,2BAA2B,CAC/B,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC,MAAM,CAAC;IAiHlB;;;;;;;OAOG;YACW,cAAc;IAsB5B;;;;OAIG;YACW,QAAQ;IAmDtB;;;;;;;;OAQG;YACW,QAAQ;CA6BvB"}
package/lib/BtcNew.js ADDED
@@ -0,0 +1,451 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ exports.__esModule = true;
42
+ exports.canSupportApp = void 0;
43
+ var bitcoinjs_lib_1 = require("bitcoinjs-lib");
44
+ var semver_1 = __importDefault(require("semver"));
45
+ var tiny_secp256k1_1 = require("tiny-secp256k1");
46
+ var bip32_1 = require("./bip32");
47
+ var buffertools_1 = require("./buffertools");
48
+ var accounttype_1 = require("./newops/accounttype");
49
+ var policy_1 = require("./newops/policy");
50
+ var psbtExtractor_1 = require("./newops/psbtExtractor");
51
+ var psbtFinalizer_1 = require("./newops/psbtFinalizer");
52
+ var psbtv2_1 = require("./newops/psbtv2");
53
+ var serializeTransaction_1 = require("./serializeTransaction");
54
+ var newSupportedApps = ["Bitcoin", "Bitcoin Test"];
55
+ function canSupportApp(appAndVersion) {
56
+ return (newSupportedApps.includes(appAndVersion.name) &&
57
+ semver_1["default"].major(appAndVersion.version) >= 2);
58
+ }
59
+ exports.canSupportApp = canSupportApp;
60
+ /**
61
+ * This class implements the same interface as BtcOld (formerly
62
+ * named Btc), but interacts with Bitcoin hardware app version 2+
63
+ * which uses a totally new APDU protocol. This new
64
+ * protocol is documented at
65
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
66
+ *
67
+ * Since the interface must remain compatible with BtcOld, the methods
68
+ * of this class are quite clunky, because it needs to adapt legacy
69
+ * input data into the PSBT process. In the future, a new interface should
70
+ * be developed that exposes PSBT to the outer world, which would render
71
+ * a much cleaner implementation.
72
+ */
73
+ var BtcNew = /** @class */ (function () {
74
+ function BtcNew(client) {
75
+ this.client = client;
76
+ }
77
+ /**
78
+ * This is a new method that allow users to get an xpub at a standard path.
79
+ * Standard paths are described at
80
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
81
+ *
82
+ * This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
83
+ * M/44'/N'/x'/**
84
+ * M/48'/N'/x'/y'/**
85
+ * M/49'/N'/x'/**
86
+ * M/84'/N'/x'/**
87
+ * M/86'/N'/x'/**
88
+ *
89
+ * The method was added because of added security in the hardware app v2+. The
90
+ * new hardware app will allow export of any xpub up to and including the
91
+ * deepest hardened key of standard derivation paths, whereas the old app
92
+ * would allow export of any key.
93
+ *
94
+ * This caused an issue for callers of this class, who only had
95
+ * getWalletPublicKey() to call which means they have to constuct xpub
96
+ * themselves:
97
+ *
98
+ * Suppose a user of this class wants to create an account xpub on a standard
99
+ * path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
100
+ * by requesting the parent key M/44'/0'. The new app won't allow that, because
101
+ * it only allows exporting deepest level hardened path. So the options are to
102
+ * allow requesting M/44'/0' from the app, or to add a new function
103
+ * "getWalletXpub".
104
+ *
105
+ * We opted for adding a new function, which can greatly simplify client code.
106
+ */
107
+ BtcNew.prototype.getWalletXpub = function (_a) {
108
+ var path = _a.path, xpubVersion = _a.xpubVersion;
109
+ return __awaiter(this, void 0, void 0, function () {
110
+ var pathElements, xpub, xpubComponents;
111
+ return __generator(this, function (_b) {
112
+ switch (_b.label) {
113
+ case 0:
114
+ pathElements = (0, bip32_1.pathStringToArray)(path);
115
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
116
+ case 1:
117
+ xpub = _b.sent();
118
+ xpubComponents = (0, bip32_1.getXpubComponents)(xpub);
119
+ if (xpubComponents.version != xpubVersion) {
120
+ throw new Error("Expected xpub version ".concat(xpubVersion, " doesn't match the xpub version from the device ").concat(xpubComponents.version));
121
+ }
122
+ return [2 /*return*/, xpub];
123
+ }
124
+ });
125
+ });
126
+ };
127
+ /**
128
+ * This method returns a public key, a bitcoin address, and and a chaincode
129
+ * for a specific derivation path.
130
+ *
131
+ * Limitation: If the path is not a leaf node of a standard path, the address
132
+ * will be the empty string "", see this.getWalletAddress() for details.
133
+ */
134
+ BtcNew.prototype.getWalletPublicKey = function (path, opts) {
135
+ var _a, _b;
136
+ return __awaiter(this, void 0, void 0, function () {
137
+ var pathElements, xpub, display, address, components, uncompressedPubkey;
138
+ return __generator(this, function (_c) {
139
+ switch (_c.label) {
140
+ case 0:
141
+ pathElements = (0, bip32_1.pathStringToArray)(path);
142
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
143
+ case 1:
144
+ xpub = _c.sent();
145
+ display = (_a = opts === null || opts === void 0 ? void 0 : opts.verify) !== null && _a !== void 0 ? _a : false;
146
+ return [4 /*yield*/, this.getWalletAddress(pathElements, descrTemplFrom((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : "legacy"), display)];
147
+ case 2:
148
+ address = _c.sent();
149
+ components = (0, bip32_1.getXpubComponents)(xpub);
150
+ uncompressedPubkey = Buffer.from((0, tiny_secp256k1_1.pointCompress)(components.pubkey, false));
151
+ return [2 /*return*/, {
152
+ publicKey: uncompressedPubkey.toString("hex"),
153
+ bitcoinAddress: address,
154
+ chainCode: components.chaincode.toString("hex")
155
+ }];
156
+ }
157
+ });
158
+ });
159
+ };
160
+ /**
161
+ * Get an address for the specified path.
162
+ *
163
+ * If display is true, we must get the address from the device, which would require
164
+ * us to determine WalletPolicy. This requires two *extra* queries to the device, one
165
+ * for the account xpub and one for master key fingerprint.
166
+ *
167
+ * If display is false we *could* generate the address ourselves, but chose to
168
+ * get it from the device to save development time. However, it shouldn't take
169
+ * too much time to implement local address generation.
170
+ *
171
+ * Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
172
+ * way to get the address from the device. In this case we have to create it
173
+ * ourselves, but we don't at this time, and instead return an empty ("") address.
174
+ */
175
+ BtcNew.prototype.getWalletAddress = function (pathElements, descrTempl, display) {
176
+ return __awaiter(this, void 0, void 0, function () {
177
+ var accountPath, accountXpub, masterFingerprint, policy, changeAndIndex;
178
+ return __generator(this, function (_a) {
179
+ switch (_a.label) {
180
+ case 0:
181
+ accountPath = (0, bip32_1.hardenedPathOf)(pathElements);
182
+ if (accountPath.length + 2 != pathElements.length) {
183
+ return [2 /*return*/, ""];
184
+ }
185
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
186
+ case 1:
187
+ accountXpub = _a.sent();
188
+ return [4 /*yield*/, this.client.getMasterFingerprint()];
189
+ case 2:
190
+ masterFingerprint = _a.sent();
191
+ policy = new policy_1.WalletPolicy(descrTempl, (0, policy_1.createKey)(masterFingerprint, accountPath, accountXpub));
192
+ changeAndIndex = pathElements.slice(-2, pathElements.length);
193
+ return [2 /*return*/, this.client.getWalletAddress(policy, Buffer.alloc(32, 0), changeAndIndex[0], changeAndIndex[1], display)];
194
+ }
195
+ });
196
+ });
197
+ };
198
+ /**
199
+ * Build and sign a transaction. See Btc.createPaymentTransactionNew for
200
+ * details on how to use this method.
201
+ *
202
+ * This method will convert the legacy arguments, CreateTransactionArg, into
203
+ * a psbt which is finally signed and finalized, and the extracted fully signed
204
+ * transaction is returned.
205
+ */
206
+ BtcNew.prototype.createPaymentTransactionNew = function (arg) {
207
+ return __awaiter(this, void 0, void 0, function () {
208
+ var inputCount, psbt, masterFp, accountType, notifyCount, progress, accountXpub, accountPath, i, pathElems, outputsConcat, outputsBufferReader, outputCount, changeData, changeFound, i, amount, outputScript, isChange, changePath, pubkey, key, p, firstSigned, progressCallback, serializedTx;
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0:
212
+ inputCount = arg.inputs.length;
213
+ if (inputCount == 0) {
214
+ throw Error("No inputs");
215
+ }
216
+ psbt = new psbtv2_1.PsbtV2();
217
+ return [4 /*yield*/, this.client.getMasterFingerprint()];
218
+ case 1:
219
+ masterFp = _a.sent();
220
+ accountType = accountTypeFromArg(arg, psbt, masterFp);
221
+ if (arg.lockTime != undefined) {
222
+ // The signer will assume locktime 0 if unset
223
+ psbt.setGlobalFallbackLocktime(arg.lockTime);
224
+ }
225
+ psbt.setGlobalInputCount(inputCount);
226
+ psbt.setGlobalPsbtVersion(2);
227
+ psbt.setGlobalTxVersion(2);
228
+ notifyCount = 0;
229
+ progress = function () {
230
+ if (!arg.onDeviceStreaming)
231
+ return;
232
+ arg.onDeviceStreaming({
233
+ total: 2 * inputCount,
234
+ index: notifyCount,
235
+ progress: ++notifyCount / (2 * inputCount)
236
+ });
237
+ };
238
+ accountXpub = "";
239
+ accountPath = [];
240
+ i = 0;
241
+ _a.label = 2;
242
+ case 2:
243
+ if (!(i < inputCount)) return [3 /*break*/, 7];
244
+ progress();
245
+ pathElems = (0, bip32_1.pathStringToArray)(arg.associatedKeysets[i]);
246
+ if (!(accountXpub == "")) return [3 /*break*/, 4];
247
+ // We assume all inputs belong to the same account so we set
248
+ // the account xpub and path based on the first input.
249
+ accountPath = pathElems.slice(0, -2);
250
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
251
+ case 3:
252
+ accountXpub = _a.sent();
253
+ _a.label = 4;
254
+ case 4: return [4 /*yield*/, this.setInput(psbt, i, arg.inputs[i], pathElems, accountType, masterFp, arg.sigHashType)];
255
+ case 5:
256
+ _a.sent();
257
+ _a.label = 6;
258
+ case 6:
259
+ i++;
260
+ return [3 /*break*/, 2];
261
+ case 7:
262
+ outputsConcat = Buffer.from(arg.outputScriptHex, "hex");
263
+ outputsBufferReader = new buffertools_1.BufferReader(outputsConcat);
264
+ outputCount = outputsBufferReader.readVarInt();
265
+ psbt.setGlobalOutputCount(outputCount);
266
+ return [4 /*yield*/, this.outputScriptAt(accountPath, accountType, arg.changePath)];
267
+ case 8:
268
+ changeData = _a.sent();
269
+ changeFound = !changeData;
270
+ for (i = 0; i < outputCount; i++) {
271
+ amount = Number(outputsBufferReader.readUInt64());
272
+ outputScript = outputsBufferReader.readVarSlice();
273
+ psbt.setOutputAmount(i, amount);
274
+ psbt.setOutputScript(i, outputScript);
275
+ isChange = changeData && outputScript.equals(changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey);
276
+ if (isChange) {
277
+ changeFound = true;
278
+ changePath = (0, bip32_1.pathStringToArray)(arg.changePath);
279
+ pubkey = changeData.pubkey;
280
+ accountType.setOwnOutput(i, changeData.cond, [pubkey], [changePath]);
281
+ }
282
+ }
283
+ if (!changeFound) {
284
+ throw new Error("Change script not found among outputs! " +
285
+ (changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey.toString("hex")));
286
+ }
287
+ key = (0, policy_1.createKey)(masterFp, accountPath, accountXpub);
288
+ p = new policy_1.WalletPolicy(accountType.getDescriptorTemplate(), key);
289
+ // This is cheating, because it's not actually requested on the
290
+ // device yet, but it will be, soonish.
291
+ if (arg.onDeviceSignatureRequested)
292
+ arg.onDeviceSignatureRequested();
293
+ firstSigned = false;
294
+ progressCallback = function () {
295
+ if (!firstSigned) {
296
+ firstSigned = true;
297
+ arg.onDeviceSignatureGranted && arg.onDeviceSignatureGranted();
298
+ }
299
+ progress();
300
+ };
301
+ return [4 /*yield*/, this.signPsbt(psbt, p, progressCallback)];
302
+ case 9:
303
+ _a.sent();
304
+ (0, psbtFinalizer_1.finalize)(psbt);
305
+ serializedTx = (0, psbtExtractor_1.extract)(psbt);
306
+ return [2 /*return*/, serializedTx.toString("hex")];
307
+ }
308
+ });
309
+ });
310
+ };
311
+ /**
312
+ * Calculates an output script along with public key and possible redeemScript
313
+ * from a path and accountType. The accountPath must be a prefix of path.
314
+ *
315
+ * @returns an object with output script (property "script"), redeemScript (if
316
+ * wrapped p2wpkh), and pubkey at provided path. The values of these three
317
+ * properties depend on the accountType used.
318
+ */
319
+ BtcNew.prototype.outputScriptAt = function (accountPath, accountType, path) {
320
+ return __awaiter(this, void 0, void 0, function () {
321
+ var pathElems, i, xpub, pubkey, cond;
322
+ return __generator(this, function (_a) {
323
+ switch (_a.label) {
324
+ case 0:
325
+ if (!path)
326
+ return [2 /*return*/, undefined];
327
+ pathElems = (0, bip32_1.pathStringToArray)(path);
328
+ // Make sure path is in our account, otherwise something fishy is probably
329
+ // going on.
330
+ for (i = 0; i < accountPath.length; i++) {
331
+ if (accountPath[i] != pathElems[i]) {
332
+ throw new Error("Path ".concat(path, " not in account ").concat((0, bip32_1.pathArrayToString)(accountPath)));
333
+ }
334
+ }
335
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElems)];
336
+ case 1:
337
+ xpub = _a.sent();
338
+ pubkey = (0, bip32_1.pubkeyFromXpub)(xpub);
339
+ cond = accountType.spendingCondition([pubkey]);
340
+ return [2 /*return*/, { cond: cond, pubkey: pubkey }];
341
+ }
342
+ });
343
+ });
344
+ };
345
+ /**
346
+ * Adds relevant data about an input to the psbt. This includes sequence,
347
+ * previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
348
+ * public key and its derivation path.
349
+ */
350
+ BtcNew.prototype.setInput = function (psbt, i, input, pathElements, accountType, masterFP, sigHashType) {
351
+ return __awaiter(this, void 0, void 0, function () {
352
+ var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey, spentTxOutput, spendCondition, spentOutput;
353
+ return __generator(this, function (_a) {
354
+ switch (_a.label) {
355
+ case 0:
356
+ inputTx = input[0];
357
+ spentOutputIndex = input[1];
358
+ redeemScript = input[2] ? Buffer.from(input[2], "hex") : undefined;
359
+ sequence = input[3];
360
+ if (sequence != undefined) {
361
+ psbt.setInputSequence(i, sequence);
362
+ }
363
+ if (sigHashType != undefined) {
364
+ psbt.setInputSighashType(i, sigHashType);
365
+ }
366
+ inputTxBuffer = (0, serializeTransaction_1.serializeTransaction)(inputTx, true);
367
+ inputTxid = bitcoinjs_lib_1.crypto.hash256(inputTxBuffer);
368
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
369
+ case 1:
370
+ xpubBase58 = _a.sent();
371
+ pubkey = (0, bip32_1.pubkeyFromXpub)(xpubBase58);
372
+ if (!inputTx.outputs)
373
+ throw Error("Missing outputs array in transaction to sign");
374
+ spentTxOutput = inputTx.outputs[spentOutputIndex];
375
+ spendCondition = {
376
+ scriptPubKey: spentTxOutput.script,
377
+ redeemScript: redeemScript
378
+ };
379
+ spentOutput = { cond: spendCondition, amount: spentTxOutput.amount };
380
+ accountType.setInput(i, inputTxBuffer, spentOutput, [pubkey], [pathElements]);
381
+ psbt.setInputPreviousTxId(i, inputTxid);
382
+ psbt.setInputOutputIndex(i, spentOutputIndex);
383
+ return [2 /*return*/];
384
+ }
385
+ });
386
+ });
387
+ };
388
+ /**
389
+ * This implements the "Signer" role of the BIP370 transaction signing
390
+ * process.
391
+ *
392
+ * It ssks the hardware device to sign the a psbt using the specified wallet
393
+ * policy. This method assumes BIP32 derived keys are used for all inputs, see
394
+ * comment in-line. The signatures returned from the hardware device is added
395
+ * to the appropriate input fields of the PSBT.
396
+ */
397
+ BtcNew.prototype.signPsbt = function (psbt, walletPolicy, progressCallback) {
398
+ return __awaiter(this, void 0, void 0, function () {
399
+ var sigs;
400
+ return __generator(this, function (_a) {
401
+ switch (_a.label) {
402
+ case 0: return [4 /*yield*/, this.client.signPsbt(psbt, walletPolicy, Buffer.alloc(32, 0), progressCallback)];
403
+ case 1:
404
+ sigs = _a.sent();
405
+ sigs.forEach(function (v, k) {
406
+ // Note: Looking at BIP32 derivation does not work in the generic case,
407
+ // since some inputs might not have a BIP32-derived pubkey.
408
+ var pubkeys = psbt.getInputKeyDatas(k, psbtv2_1.psbtIn.BIP32_DERIVATION);
409
+ var pubkey;
410
+ if (pubkeys.length != 1) {
411
+ // No legacy BIP32_DERIVATION, assume we're using taproot.
412
+ pubkey = psbt.getInputKeyDatas(k, psbtv2_1.psbtIn.TAP_BIP32_DERIVATION);
413
+ if (pubkey.length == 0) {
414
+ throw Error("Missing pubkey derivation for input ".concat(k));
415
+ }
416
+ psbt.setInputTapKeySig(k, v);
417
+ }
418
+ else {
419
+ pubkey = pubkeys[0];
420
+ psbt.setInputPartialSig(k, pubkey, v);
421
+ }
422
+ });
423
+ return [2 /*return*/];
424
+ }
425
+ });
426
+ });
427
+ };
428
+ return BtcNew;
429
+ }());
430
+ exports["default"] = BtcNew;
431
+ function descrTemplFrom(addressFormat) {
432
+ if (addressFormat == "legacy")
433
+ return "pkh(@0)";
434
+ if (addressFormat == "p2sh")
435
+ return "sh(wpkh(@0))";
436
+ if (addressFormat == "bech32")
437
+ return "wpkh(@0)";
438
+ if (addressFormat == "bech32m")
439
+ return "tr(@0)";
440
+ throw new Error("Unsupported address format " + addressFormat);
441
+ }
442
+ function accountTypeFromArg(arg, psbt, masterFp) {
443
+ if (arg.additionals.includes("bech32m"))
444
+ return new accounttype_1.p2tr(psbt, masterFp);
445
+ if (arg.additionals.includes("bech32"))
446
+ return new accounttype_1.p2wpkh(psbt, masterFp);
447
+ if (arg.segwit)
448
+ return new accounttype_1.p2wpkhWrapped(psbt, masterFp);
449
+ return new accounttype_1.p2pkh(psbt, masterFp);
450
+ }
451
+ //# sourceMappingURL=BtcNew.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BtcNew.js","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuC;AACvC,kDAA4B;AAC5B,iDAA+C;AAC/C,iCAMiB;AACjB,6CAA6C;AAI7C,oDAO8B;AAE9B,0CAIyB;AACzB,wDAAiD;AACjD,wDAAkD;AAClD,0CAAiD;AACjD,+DAA8D;AAG9D,IAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAErD,SAAgB,aAAa,CAAC,aAA4B;IACxD,OAAO,CACL,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC;QAC7C,mBAAM,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CACzC,CAAC;AACJ,CAAC;AALD,sCAKC;AAED;;;;;;;;;;;;GAYG;AACH;IACE,gBAAoB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;IAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,8BAAa,GAAnB,UAAoB,EAMnB;YALC,IAAI,UAAA,EACJ,WAAW,iBAAA;;;;;;wBAKL,YAAY,GAAa,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;wBAC1C,qBAAM,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,EAAA;;wBAA/D,IAAI,GAAG,SAAwD;wBAC/D,cAAc,GAAG,IAAA,yBAAiB,EAAC,IAAI,CAAC,CAAC;wBAC/C,IAAI,cAAc,CAAC,OAAO,IAAI,WAAW,EAAE;4BACzC,MAAM,IAAI,KAAK,CACb,gCAAyB,W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