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

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 (290) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +10 -0
  3. package/README.md +4 -4
  4. package/jest.config.ts +6 -0
  5. package/package.json +15 -6
  6. package/src/bip32.ts +5 -3
  7. package/src/getTrustedInput.ts +2 -8
  8. package/src/newops/appClient.ts +8 -4
  9. package/src/newops/psbtv2.ts +13 -9
  10. package/LICENSE +0 -202
  11. package/lib/Btc.d.ts +0 -149
  12. package/lib/Btc.d.ts.map +0 -1
  13. package/lib/Btc.js +0 -353
  14. package/lib/Btc.js.map +0 -1
  15. package/lib/BtcNew.d.ts +0 -122
  16. package/lib/BtcNew.d.ts.map +0 -1
  17. package/lib/BtcNew.js +0 -451
  18. package/lib/BtcNew.js.map +0 -1
  19. package/lib/BtcOld.d.ts +0 -120
  20. package/lib/BtcOld.d.ts.map +0 -1
  21. package/lib/BtcOld.js +0 -263
  22. package/lib/BtcOld.js.map +0 -1
  23. package/lib/bip32.d.ts +0 -13
  24. package/lib/bip32.d.ts.map +0 -1
  25. package/lib/bip32.js +0 -57
  26. package/lib/bip32.js.map +0 -1
  27. package/lib/buffertools.d.ts +0 -30
  28. package/lib/buffertools.d.ts.map +0 -1
  29. package/lib/buffertools.js +0 -132
  30. package/lib/buffertools.js.map +0 -1
  31. package/lib/compressPublicKey.d.ts +0 -3
  32. package/lib/compressPublicKey.d.ts.map +0 -1
  33. package/lib/compressPublicKey.js +0 -11
  34. package/lib/compressPublicKey.js.map +0 -1
  35. package/lib/constants.d.ts +0 -13
  36. package/lib/constants.d.ts.map +0 -1
  37. package/lib/constants.js +0 -17
  38. package/lib/constants.js.map +0 -1
  39. package/lib/createTransaction.d.ts +0 -35
  40. package/lib/createTransaction.d.ts.map +0 -1
  41. package/lib/createTransaction.js +0 -411
  42. package/lib/createTransaction.js.map +0 -1
  43. package/lib/debug.d.ts +0 -4
  44. package/lib/debug.d.ts.map +0 -1
  45. package/lib/debug.js +0 -45
  46. package/lib/debug.js.map +0 -1
  47. package/lib/finalizeInput.d.ts +0 -5
  48. package/lib/finalizeInput.d.ts.map +0 -1
  49. package/lib/finalizeInput.js +0 -81
  50. package/lib/finalizeInput.js.map +0 -1
  51. package/lib/getAppAndVersion.d.ts +0 -9
  52. package/lib/getAppAndVersion.d.ts.map +0 -1
  53. package/lib/getAppAndVersion.js +0 -69
  54. package/lib/getAppAndVersion.js.map +0 -1
  55. package/lib/getTrustedInput.d.ts +0 -6
  56. package/lib/getTrustedInput.d.ts.map +0 -1
  57. package/lib/getTrustedInput.js +0 -275
  58. package/lib/getTrustedInput.js.map +0 -1
  59. package/lib/getTrustedInputBIP143.d.ts +0 -4
  60. package/lib/getTrustedInputBIP143.d.ts.map +0 -1
  61. package/lib/getTrustedInputBIP143.js +0 -34
  62. package/lib/getTrustedInputBIP143.js.map +0 -1
  63. package/lib/getWalletPublicKey.d.ts +0 -15
  64. package/lib/getWalletPublicKey.d.ts.map +0 -1
  65. package/lib/getWalletPublicKey.js +0 -93
  66. package/lib/getWalletPublicKey.js.map +0 -1
  67. package/lib/hashPublicKey.d.ts +0 -3
  68. package/lib/hashPublicKey.d.ts.map +0 -1
  69. package/lib/hashPublicKey.js +0 -13
  70. package/lib/hashPublicKey.js.map +0 -1
  71. package/lib/index.d.ts +0 -3
  72. package/lib/index.d.ts.map +0 -1
  73. package/lib/index.js +0 -8
  74. package/lib/index.js.map +0 -1
  75. package/lib/newops/accounttype.d.ts +0 -110
  76. package/lib/newops/accounttype.d.ts.map +0 -1
  77. package/lib/newops/accounttype.js +0 -236
  78. package/lib/newops/accounttype.js.map +0 -1
  79. package/lib/newops/appClient.d.ts +0 -18
  80. package/lib/newops/appClient.d.ts.map +0 -1
  81. package/lib/newops/appClient.js +0 -246
  82. package/lib/newops/appClient.js.map +0 -1
  83. package/lib/newops/clientCommands.d.ts +0 -77
  84. package/lib/newops/clientCommands.d.ts.map +0 -1
  85. package/lib/newops/clientCommands.js +0 -353
  86. package/lib/newops/clientCommands.js.map +0 -1
  87. package/lib/newops/merkelizedPsbt.d.ts +0 -26
  88. package/lib/newops/merkelizedPsbt.d.ts.map +0 -1
  89. package/lib/newops/merkelizedPsbt.js +0 -102
  90. package/lib/newops/merkelizedPsbt.js.map +0 -1
  91. package/lib/newops/merkle.d.ts +0 -34
  92. package/lib/newops/merkle.d.ts.map +0 -1
  93. package/lib/newops/merkle.js +0 -138
  94. package/lib/newops/merkle.js.map +0 -1
  95. package/lib/newops/merkleMap.d.ts +0 -25
  96. package/lib/newops/merkleMap.d.ts.map +0 -1
  97. package/lib/newops/merkleMap.js +0 -47
  98. package/lib/newops/merkleMap.js.map +0 -1
  99. package/lib/newops/policy.d.ts +0 -22
  100. package/lib/newops/policy.d.ts.map +0 -1
  101. package/lib/newops/policy.js +0 -48
  102. package/lib/newops/policy.js.map +0 -1
  103. package/lib/newops/psbtExtractor.d.ts +0 -10
  104. package/lib/newops/psbtExtractor.d.ts.map +0 -1
  105. package/lib/newops/psbtExtractor.js +0 -42
  106. package/lib/newops/psbtExtractor.js.map +0 -1
  107. package/lib/newops/psbtFinalizer.d.ts +0 -17
  108. package/lib/newops/psbtFinalizer.d.ts.map +0 -1
  109. package/lib/newops/psbtFinalizer.js +0 -135
  110. package/lib/newops/psbtFinalizer.js.map +0 -1
  111. package/lib/newops/psbtv2.d.ts +0 -149
  112. package/lib/newops/psbtv2.d.ts.map +0 -1
  113. package/lib/newops/psbtv2.js +0 -506
  114. package/lib/newops/psbtv2.js.map +0 -1
  115. package/lib/serializeTransaction.d.ts +0 -10
  116. package/lib/serializeTransaction.d.ts.map +0 -1
  117. package/lib/serializeTransaction.js +0 -72
  118. package/lib/serializeTransaction.js.map +0 -1
  119. package/lib/shouldUseTrustedInputForSegwit.d.ts +0 -5
  120. package/lib/shouldUseTrustedInputForSegwit.d.ts.map +0 -1
  121. package/lib/shouldUseTrustedInputForSegwit.js +0 -17
  122. package/lib/shouldUseTrustedInputForSegwit.js.map +0 -1
  123. package/lib/signMessage.d.ts +0 -10
  124. package/lib/signMessage.d.ts.map +0 -1
  125. package/lib/signMessage.js +0 -118
  126. package/lib/signMessage.js.map +0 -1
  127. package/lib/signP2SHTransaction.d.ts +0 -21
  128. package/lib/signP2SHTransaction.d.ts.map +0 -1
  129. package/lib/signP2SHTransaction.js +0 -208
  130. package/lib/signP2SHTransaction.js.map +0 -1
  131. package/lib/signTransaction.d.ts +0 -4
  132. package/lib/signTransaction.d.ts.map +0 -1
  133. package/lib/signTransaction.js +0 -36
  134. package/lib/signTransaction.js.map +0 -1
  135. package/lib/splitTransaction.d.ts +0 -3
  136. package/lib/splitTransaction.d.ts.map +0 -1
  137. package/lib/splitTransaction.js +0 -142
  138. package/lib/splitTransaction.js.map +0 -1
  139. package/lib/startUntrustedHashTransactionInput.d.ts +0 -9
  140. package/lib/startUntrustedHashTransactionInput.d.ts.map +0 -1
  141. package/lib/startUntrustedHashTransactionInput.js +0 -197
  142. package/lib/startUntrustedHashTransactionInput.js.map +0 -1
  143. package/lib/types.d.ts +0 -34
  144. package/lib/types.d.ts.map +0 -1
  145. package/lib/types.js +0 -3
  146. package/lib/types.js.map +0 -1
  147. package/lib/varint.d.ts +0 -4
  148. package/lib/varint.d.ts.map +0 -1
  149. package/lib/varint.js +0 -45
  150. package/lib/varint.js.map +0 -1
  151. package/lib-es/Btc.d.ts +0 -149
  152. package/lib-es/Btc.d.ts.map +0 -1
  153. package/lib-es/Btc.js +0 -329
  154. package/lib-es/Btc.js.map +0 -1
  155. package/lib-es/BtcNew.d.ts +0 -122
  156. package/lib-es/BtcNew.d.ts.map +0 -1
  157. package/lib-es/BtcNew.js +0 -444
  158. package/lib-es/BtcNew.js.map +0 -1
  159. package/lib-es/BtcOld.d.ts +0 -120
  160. package/lib-es/BtcOld.d.ts.map +0 -1
  161. package/lib-es/BtcOld.js +0 -258
  162. package/lib-es/BtcOld.js.map +0 -1
  163. package/lib-es/bip32.d.ts +0 -13
  164. package/lib-es/bip32.d.ts.map +0 -1
  165. package/lib-es/bip32.js +0 -44
  166. package/lib-es/bip32.js.map +0 -1
  167. package/lib-es/buffertools.d.ts +0 -30
  168. package/lib-es/buffertools.d.ts.map +0 -1
  169. package/lib-es/buffertools.js +0 -124
  170. package/lib-es/buffertools.js.map +0 -1
  171. package/lib-es/compressPublicKey.d.ts +0 -3
  172. package/lib-es/compressPublicKey.d.ts.map +0 -1
  173. package/lib-es/compressPublicKey.js +0 -7
  174. package/lib-es/compressPublicKey.js.map +0 -1
  175. package/lib-es/constants.d.ts +0 -13
  176. package/lib-es/constants.d.ts.map +0 -1
  177. package/lib-es/constants.js +0 -14
  178. package/lib-es/constants.js.map +0 -1
  179. package/lib-es/createTransaction.d.ts +0 -35
  180. package/lib-es/createTransaction.d.ts.map +0 -1
  181. package/lib-es/createTransaction.js +0 -407
  182. package/lib-es/createTransaction.js.map +0 -1
  183. package/lib-es/debug.d.ts +0 -4
  184. package/lib-es/debug.d.ts.map +0 -1
  185. package/lib-es/debug.js +0 -40
  186. package/lib-es/debug.js.map +0 -1
  187. package/lib-es/finalizeInput.d.ts +0 -5
  188. package/lib-es/finalizeInput.d.ts.map +0 -1
  189. package/lib-es/finalizeInput.js +0 -76
  190. package/lib-es/finalizeInput.js.map +0 -1
  191. package/lib-es/getAppAndVersion.d.ts +0 -9
  192. package/lib-es/getAppAndVersion.d.ts.map +0 -1
  193. package/lib-es/getAppAndVersion.js +0 -62
  194. package/lib-es/getAppAndVersion.js.map +0 -1
  195. package/lib-es/getTrustedInput.d.ts +0 -6
  196. package/lib-es/getTrustedInput.d.ts.map +0 -1
  197. package/lib-es/getTrustedInput.js +0 -267
  198. package/lib-es/getTrustedInput.js.map +0 -1
  199. package/lib-es/getTrustedInputBIP143.d.ts +0 -4
  200. package/lib-es/getTrustedInputBIP143.d.ts.map +0 -1
  201. package/lib-es/getTrustedInputBIP143.js +0 -27
  202. package/lib-es/getTrustedInputBIP143.js.map +0 -1
  203. package/lib-es/getWalletPublicKey.d.ts +0 -15
  204. package/lib-es/getWalletPublicKey.d.ts.map +0 -1
  205. package/lib-es/getWalletPublicKey.js +0 -89
  206. package/lib-es/getWalletPublicKey.js.map +0 -1
  207. package/lib-es/hashPublicKey.d.ts +0 -3
  208. package/lib-es/hashPublicKey.d.ts.map +0 -1
  209. package/lib-es/hashPublicKey.js +0 -6
  210. package/lib-es/hashPublicKey.js.map +0 -1
  211. package/lib-es/index.d.ts +0 -3
  212. package/lib-es/index.d.ts.map +0 -1
  213. package/lib-es/index.js +0 -3
  214. package/lib-es/index.js.map +0 -1
  215. package/lib-es/newops/accounttype.d.ts +0 -110
  216. package/lib-es/newops/accounttype.d.ts.map +0 -1
  217. package/lib-es/newops/accounttype.js +0 -233
  218. package/lib-es/newops/accounttype.js.map +0 -1
  219. package/lib-es/newops/appClient.d.ts +0 -18
  220. package/lib-es/newops/appClient.d.ts.map +0 -1
  221. package/lib-es/newops/appClient.js +0 -243
  222. package/lib-es/newops/appClient.js.map +0 -1
  223. package/lib-es/newops/clientCommands.d.ts +0 -77
  224. package/lib-es/newops/clientCommands.d.ts.map +0 -1
  225. package/lib-es/newops/clientCommands.js +0 -350
  226. package/lib-es/newops/clientCommands.js.map +0 -1
  227. package/lib-es/newops/merkelizedPsbt.d.ts +0 -26
  228. package/lib-es/newops/merkelizedPsbt.d.ts.map +0 -1
  229. package/lib-es/newops/merkelizedPsbt.js +0 -99
  230. package/lib-es/newops/merkelizedPsbt.js.map +0 -1
  231. package/lib-es/newops/merkle.d.ts +0 -34
  232. package/lib-es/newops/merkle.d.ts.map +0 -1
  233. package/lib-es/newops/merkle.js +0 -134
  234. package/lib-es/newops/merkle.js.map +0 -1
  235. package/lib-es/newops/merkleMap.d.ts +0 -25
  236. package/lib-es/newops/merkleMap.d.ts.map +0 -1
  237. package/lib-es/newops/merkleMap.js +0 -44
  238. package/lib-es/newops/merkleMap.js.map +0 -1
  239. package/lib-es/newops/policy.d.ts +0 -22
  240. package/lib-es/newops/policy.d.ts.map +0 -1
  241. package/lib-es/newops/policy.js +0 -44
  242. package/lib-es/newops/policy.js.map +0 -1
  243. package/lib-es/newops/psbtExtractor.d.ts +0 -10
  244. package/lib-es/newops/psbtExtractor.d.ts.map +0 -1
  245. package/lib-es/newops/psbtExtractor.js +0 -38
  246. package/lib-es/newops/psbtExtractor.js.map +0 -1
  247. package/lib-es/newops/psbtFinalizer.d.ts +0 -17
  248. package/lib-es/newops/psbtFinalizer.d.ts.map +0 -1
  249. package/lib-es/newops/psbtFinalizer.js +0 -131
  250. package/lib-es/newops/psbtFinalizer.js.map +0 -1
  251. package/lib-es/newops/psbtv2.d.ts +0 -149
  252. package/lib-es/newops/psbtv2.d.ts.map +0 -1
  253. package/lib-es/newops/psbtv2.js +0 -503
  254. package/lib-es/newops/psbtv2.js.map +0 -1
  255. package/lib-es/serializeTransaction.d.ts +0 -10
  256. package/lib-es/serializeTransaction.d.ts.map +0 -1
  257. package/lib-es/serializeTransaction.js +0 -67
  258. package/lib-es/serializeTransaction.js.map +0 -1
  259. package/lib-es/shouldUseTrustedInputForSegwit.d.ts +0 -5
  260. package/lib-es/shouldUseTrustedInputForSegwit.d.ts.map +0 -1
  261. package/lib-es/shouldUseTrustedInputForSegwit.js +0 -10
  262. package/lib-es/shouldUseTrustedInputForSegwit.js.map +0 -1
  263. package/lib-es/signMessage.d.ts +0 -10
  264. package/lib-es/signMessage.d.ts.map +0 -1
  265. package/lib-es/signMessage.js +0 -111
  266. package/lib-es/signMessage.js.map +0 -1
  267. package/lib-es/signP2SHTransaction.d.ts +0 -21
  268. package/lib-es/signP2SHTransaction.d.ts.map +0 -1
  269. package/lib-es/signP2SHTransaction.js +0 -204
  270. package/lib-es/signP2SHTransaction.js.map +0 -1
  271. package/lib-es/signTransaction.d.ts +0 -4
  272. package/lib-es/signTransaction.d.ts.map +0 -1
  273. package/lib-es/signTransaction.js +0 -32
  274. package/lib-es/signTransaction.js.map +0 -1
  275. package/lib-es/splitTransaction.d.ts +0 -3
  276. package/lib-es/splitTransaction.d.ts.map +0 -1
  277. package/lib-es/splitTransaction.js +0 -138
  278. package/lib-es/splitTransaction.js.map +0 -1
  279. package/lib-es/startUntrustedHashTransactionInput.d.ts +0 -9
  280. package/lib-es/startUntrustedHashTransactionInput.d.ts.map +0 -1
  281. package/lib-es/startUntrustedHashTransactionInput.js +0 -192
  282. package/lib-es/startUntrustedHashTransactionInput.js.map +0 -1
  283. package/lib-es/types.d.ts +0 -34
  284. package/lib-es/types.d.ts.map +0 -1
  285. package/lib-es/types.js +0 -2
  286. package/lib-es/types.js.map +0 -1
  287. package/lib-es/varint.d.ts +0 -4
  288. package/lib-es/varint.d.ts.map +0 -1
  289. package/lib-es/varint.js +0 -40
  290. package/lib-es/varint.js.map +0 -1
package/lib/Btc.d.ts DELETED
@@ -1,149 +0,0 @@
1
- /// <reference types="node" />
2
- import type Transport from "@ledgerhq/hw-transport";
3
- import BtcNew from "./BtcNew";
4
- import BtcOld from "./BtcOld";
5
- import type { CreateTransactionArg } from "./createTransaction";
6
- import type { AddressFormat } from "./getWalletPublicKey";
7
- import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
8
- import type { Transaction } from "./types";
9
- export type { AddressFormat };
10
- /**
11
- * Bitcoin API.
12
- *
13
- * @example
14
- * import Btc from "@ledgerhq/hw-app-btc";
15
- * const btc = new Btc(transport)
16
- */
17
- export default class Btc {
18
- transport: Transport;
19
- constructor(transport: Transport, scrambleKey?: string);
20
- /**
21
- * Get an XPUB with a ledger device
22
- * @param arg derivation parameter
23
- * - path: a BIP 32 path of the account level. e.g. `84'/0'/0'`
24
- * - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
25
- * @returns XPUB of the account
26
- */
27
- getWalletXpub(arg: {
28
- path: string;
29
- xpubVersion: number;
30
- }): Promise<string>;
31
- /**
32
- * @param path a BIP 32 path
33
- * @param options an object with optional these fields:
34
- *
35
- * - verify (boolean) will ask user to confirm the address on the device
36
- *
37
- * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.
38
- *
39
- * NB The normal usage is to use:
40
- *
41
- * - legacy format with 44' paths
42
- *
43
- * - p2sh format with 49' paths
44
- *
45
- * - bech32 format with 84' paths
46
- *
47
- * - cashaddr in case of Bitcoin Cash
48
- *
49
- * @example
50
- * btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
51
- * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
52
- */
53
- getWalletPublicKey(path: string, opts?: {
54
- verify?: boolean;
55
- format?: AddressFormat;
56
- }): Promise<{
57
- publicKey: string;
58
- bitcoinAddress: string;
59
- chainCode: string;
60
- }>;
61
- /**
62
- * You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
63
- * @example
64
- btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
65
- var v = result['v'] + 27 + 4;
66
- var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
67
- console.log("Signature : " + signature);
68
- }).catch(function(ex) {console.log(ex);});
69
- */
70
- signMessageNew(path: string, messageHex: string): Promise<{
71
- v: number;
72
- r: string;
73
- s: string;
74
- }>;
75
- /**
76
- * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
77
- * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
78
- *
79
- * * transaction is the previously computed transaction object for this UTXO
80
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
81
- * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
82
- * * sequence is the sequence number to use for this input (when using RBF), or non present
83
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
84
- * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
85
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
86
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
87
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
88
- * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
89
- * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
90
- * @param additionals list of additionnal options
91
- *
92
- * - "bech32" for spending native segwit outputs
93
- * - "bech32m" for spending segwit v1+ outputs
94
- * - "abc" for bch
95
- * - "gold" for btg
96
- * - "bipxxx" for using BIPxxx
97
- * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
98
- * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
99
- * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
100
- * @return the signed transaction ready to be broadcast
101
- * @example
102
- btc.createTransaction({
103
- inputs: [ [tx1, 1] ],
104
- associatedKeysets: ["0'/0/0"],
105
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
106
- }).then(res => ...);
107
- */
108
- createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
109
- /**
110
- * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
111
- * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
112
- * * transaction is the previously computed transaction object for this UTXO
113
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
114
- * * redeem script is the mandatory redeem script associated to the current P2SH input
115
- * * sequence is the sequence number to use for this input (when using RBF), or non present
116
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
117
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
118
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
119
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
120
- * @return the signed transaction ready to be broadcast
121
- * @example
122
- btc.signP2SHTransaction({
123
- inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
124
- associatedKeysets: ["0'/0/0"],
125
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
126
- }).then(result => ...);
127
- */
128
- signP2SHTransaction(arg: SignP2SHTransactionArg): Promise<string[]>;
129
- /**
130
- * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
131
- * @example
132
- const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
133
- */
134
- splitTransaction(transactionHex: string, isSegwitSupported?: boolean | null | undefined, hasTimestamp?: boolean, hasExtraData?: boolean, additionals?: Array<string>): Transaction;
135
- /**
136
- @example
137
- const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
138
- const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
139
- */
140
- serializeTransactionOutputs(t: Transaction): Buffer;
141
- getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>;
142
- getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string;
143
- private _lazyImpl;
144
- private getCorrectImpl;
145
- private inferCorrectImpl;
146
- protected old(): BtcOld;
147
- protected new(): BtcNew;
148
- }
149
- //# sourceMappingURL=Btc.d.ts.map
package/lib/Btc.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Btc.d.ts","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAEpD,OAAO,MAAyB,MAAM,UAAU,CAAC;AACjD,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,CAAC;AAC9B;;;;;;GAMG;AAEH,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS,EAAE,WAAW,SAAQ;IAiBrD;;;;;;OAMG;IACH,aAAa,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAI1E;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,kBAAkB,CA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AAgB;IAU9B,SAAS,CAAC,GAAG,IAAI,MAAM;IAIvB,SAAS,CAAC,GAAG,IAAI,MAAM;CAGxB"}
package/lib/Btc.js DELETED
@@ -1,353 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- 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;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- var __importDefault = (this && this.__importDefault) || function (mod) {
58
- return (mod && mod.__esModule) ? mod : { "default": mod };
59
- };
60
- exports.__esModule = true;
61
- var bip32_1 = require("./bip32");
62
- var BtcNew_1 = __importStar(require("./BtcNew"));
63
- var BtcOld_1 = __importDefault(require("./BtcOld"));
64
- var getAppAndVersion_1 = require("./getAppAndVersion");
65
- var getTrustedInput_1 = require("./getTrustedInput");
66
- var getTrustedInputBIP143_1 = require("./getTrustedInputBIP143");
67
- var appClient_1 = require("./newops/appClient");
68
- var serializeTransaction_1 = require("./serializeTransaction");
69
- var splitTransaction_1 = require("./splitTransaction");
70
- /**
71
- * Bitcoin API.
72
- *
73
- * @example
74
- * import Btc from "@ledgerhq/hw-app-btc";
75
- * const btc = new Btc(transport)
76
- */
77
- var Btc = /** @class */ (function () {
78
- function Btc(transport, scrambleKey) {
79
- if (scrambleKey === void 0) { scrambleKey = "BTC"; }
80
- // cache the underlying implementation (only once)
81
- this._lazyImpl = null;
82
- this.transport = transport;
83
- transport.decorateAppAPIMethods(this, [
84
- "getWalletXpub",
85
- "getWalletPublicKey",
86
- "signP2SHTransaction",
87
- "signMessageNew",
88
- "createPaymentTransactionNew",
89
- "getTrustedInput",
90
- "getTrustedInputBIP143",
91
- ], scrambleKey);
92
- }
93
- /**
94
- * Get an XPUB with a ledger device
95
- * @param arg derivation parameter
96
- * - path: a BIP 32 path of the account level. e.g. `84'/0'/0'`
97
- * - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
98
- * @returns XPUB of the account
99
- */
100
- Btc.prototype.getWalletXpub = function (arg) {
101
- return this.getCorrectImpl().then(function (impl) { return impl.getWalletXpub(arg); });
102
- };
103
- /**
104
- * @param path a BIP 32 path
105
- * @param options an object with optional these fields:
106
- *
107
- * - verify (boolean) will ask user to confirm the address on the device
108
- *
109
- * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.
110
- *
111
- * NB The normal usage is to use:
112
- *
113
- * - legacy format with 44' paths
114
- *
115
- * - p2sh format with 49' paths
116
- *
117
- * - bech32 format with 84' paths
118
- *
119
- * - cashaddr in case of Bitcoin Cash
120
- *
121
- * @example
122
- * btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
123
- * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
124
- */
125
- Btc.prototype.getWalletPublicKey = function (path, opts) {
126
- var _this = this;
127
- var options;
128
- if (arguments.length > 2 || typeof opts === "boolean") {
129
- console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
130
- options = {
131
- verify: !!opts,
132
- // eslint-disable-next-line prefer-rest-params
133
- format: arguments[2] ? "p2sh" : "legacy"
134
- };
135
- }
136
- else {
137
- options = opts || {};
138
- }
139
- return this.getCorrectImpl().then(function (impl) {
140
- /**
141
- * Definition: A "normal path" is a prefix of a standard path where all
142
- * the hardened steps of the standard path are included. For example, the
143
- * paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
144
- * is not. m/'199/1'/17'/0/1 is not a normal path either.
145
- *
146
- * There's a compatiblity issue between old and new app: When exporting
147
- * the key of a non-normal path with verify=false, the new app would
148
- * return an error, whereas the old app would return the key.
149
- *
150
- * See
151
- * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey
152
- *
153
- * If format bech32m is used, we'll not use old, because it doesn't
154
- * support it.
155
- *
156
- * When to use new (given the app supports it)
157
- * * format is bech32m or
158
- * * path is normal or
159
- * * verify is true
160
- *
161
- * Otherwise use old.
162
- */
163
- if (impl instanceof BtcNew_1["default"] &&
164
- options.format != "bech32m" &&
165
- (!options.verify || options.verify == false) &&
166
- !isPathNormal(path)) {
167
- console.warn("WARNING: Using deprecated device protocol to get the public key because\n \n * a non-standard path is requested, and\n * verify flag is false\n \n The new protocol only allows export of non-standard paths if the \n verify flag is true. Standard paths are (currently):\n\n M/44'/(1|0)'/X'\n M/49'/(1|0)'/X'\n M/84'/(1|0)'/X'\n M/86'/(1|0)'/X'\n M/48'/(1|0)'/X'/Y'\n\n followed by \"\", \"(0|1)\", or \"(0|1)/b\", where a and b are \n non-hardened. For example, the following paths are standard\n \n M/48'/1'/99'/7'\n M/86'/1'/99'/0\n M/48'/0'/99'/7'/1/17\n\n The following paths are non-standard\n\n M/48'/0'/99' // Not deepest hardened path\n M/48'/0'/99'/7'/1/17/2 // Too many non-hardened derivation steps\n M/199'/0'/1'/0/88 // Not a known purpose 199\n M/86'/1'/99'/2 // Change path item must be 0 or 1\n\n This compatibility safeguard will be removed in the future.\n Please consider calling Btc.getWalletXpub() instead.");
168
- return _this.old().getWalletPublicKey(path, options);
169
- }
170
- else {
171
- return impl.getWalletPublicKey(path, options);
172
- }
173
- });
174
- };
175
- /**
176
- * You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
177
- * @example
178
- btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
179
- var v = result['v'] + 27 + 4;
180
- var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
181
- console.log("Signature : " + signature);
182
- }).catch(function(ex) {console.log(ex);});
183
- */
184
- Btc.prototype.signMessageNew = function (path, messageHex) {
185
- return this.old().signMessageNew(path, messageHex);
186
- };
187
- /**
188
- * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
189
- * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
190
- *
191
- * * transaction is the previously computed transaction object for this UTXO
192
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
193
- * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
194
- * * sequence is the sequence number to use for this input (when using RBF), or non present
195
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
196
- * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
197
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
198
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
199
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
200
- * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
201
- * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
202
- * @param additionals list of additionnal options
203
- *
204
- * - "bech32" for spending native segwit outputs
205
- * - "bech32m" for spending segwit v1+ outputs
206
- * - "abc" for bch
207
- * - "gold" for btg
208
- * - "bipxxx" for using BIPxxx
209
- * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
210
- * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
211
- * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
212
- * @return the signed transaction ready to be broadcast
213
- * @example
214
- btc.createTransaction({
215
- inputs: [ [tx1, 1] ],
216
- associatedKeysets: ["0'/0/0"],
217
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
218
- }).then(res => ...);
219
- */
220
- Btc.prototype.createPaymentTransactionNew = function (arg) {
221
- if (arguments.length > 1) {
222
- console.warn("@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.");
223
- }
224
- return this.getCorrectImpl().then(function (impl) {
225
- return impl.createPaymentTransactionNew(arg);
226
- });
227
- };
228
- /**
229
- * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
230
- * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
231
- * * transaction is the previously computed transaction object for this UTXO
232
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
233
- * * redeem script is the mandatory redeem script associated to the current P2SH input
234
- * * sequence is the sequence number to use for this input (when using RBF), or non present
235
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
236
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
237
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
238
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
239
- * @return the signed transaction ready to be broadcast
240
- * @example
241
- btc.signP2SHTransaction({
242
- inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
243
- associatedKeysets: ["0'/0/0"],
244
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
245
- }).then(result => ...);
246
- */
247
- Btc.prototype.signP2SHTransaction = function (arg) {
248
- return this.old().signP2SHTransaction(arg);
249
- };
250
- /**
251
- * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
252
- * @example
253
- const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
254
- */
255
- Btc.prototype.splitTransaction = function (transactionHex, isSegwitSupported, hasTimestamp, hasExtraData, additionals) {
256
- if (isSegwitSupported === void 0) { isSegwitSupported = false; }
257
- if (hasTimestamp === void 0) { hasTimestamp = false; }
258
- if (hasExtraData === void 0) { hasExtraData = false; }
259
- if (additionals === void 0) { additionals = []; }
260
- return (0, splitTransaction_1.splitTransaction)(transactionHex, isSegwitSupported, hasTimestamp, hasExtraData, additionals);
261
- };
262
- /**
263
- @example
264
- const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
265
- const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
266
- */
267
- Btc.prototype.serializeTransactionOutputs = function (t) {
268
- return (0, serializeTransaction_1.serializeTransactionOutputs)(t);
269
- };
270
- Btc.prototype.getTrustedInput = function (indexLookup, transaction, additionals) {
271
- if (additionals === void 0) { additionals = []; }
272
- return (0, getTrustedInput_1.getTrustedInput)(this.transport, indexLookup, transaction, additionals);
273
- };
274
- Btc.prototype.getTrustedInputBIP143 = function (indexLookup, transaction, additionals) {
275
- if (additionals === void 0) { additionals = []; }
276
- return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(this.transport, indexLookup, transaction, additionals);
277
- };
278
- Btc.prototype.getCorrectImpl = function () {
279
- return __awaiter(this, void 0, void 0, function () {
280
- var _lazyImpl, impl;
281
- return __generator(this, function (_a) {
282
- switch (_a.label) {
283
- case 0:
284
- _lazyImpl = this._lazyImpl;
285
- if (_lazyImpl)
286
- return [2 /*return*/, _lazyImpl];
287
- return [4 /*yield*/, this.inferCorrectImpl()];
288
- case 1:
289
- impl = _a.sent();
290
- this._lazyImpl = impl;
291
- return [2 /*return*/, impl];
292
- }
293
- });
294
- });
295
- };
296
- Btc.prototype.inferCorrectImpl = function () {
297
- return __awaiter(this, void 0, void 0, function () {
298
- var appAndVersion, canUseNewImplementation;
299
- return __generator(this, function (_a) {
300
- switch (_a.label) {
301
- case 0: return [4 /*yield*/, (0, getAppAndVersion_1.getAppAndVersion)(this.transport)];
302
- case 1:
303
- appAndVersion = _a.sent();
304
- canUseNewImplementation = (0, BtcNew_1.canSupportApp)(appAndVersion);
305
- if (!canUseNewImplementation) {
306
- return [2 /*return*/, this.old()];
307
- }
308
- else {
309
- return [2 /*return*/, this["new"]()];
310
- }
311
- return [2 /*return*/];
312
- }
313
- });
314
- });
315
- };
316
- Btc.prototype.old = function () {
317
- return new BtcOld_1["default"](this.transport);
318
- };
319
- Btc.prototype["new"] = function () {
320
- return new BtcNew_1["default"](new appClient_1.AppClient(this.transport));
321
- };
322
- return Btc;
323
- }());
324
- exports["default"] = Btc;
325
- function isPathNormal(path) {
326
- //path is not deepest hardened node of a standard path or deeper, use BtcOld
327
- var h = 0x80000000;
328
- var pathElems = (0, bip32_1.pathStringToArray)(path);
329
- var hard = function (n) { return n >= h; };
330
- var soft = function (n) { return !n || n < h; };
331
- var change = function (n) { return !n || n == 0 || n == 1; };
332
- if (pathElems.length >= 3 &&
333
- pathElems.length <= 5 &&
334
- [44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
335
- [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
336
- hard(pathElems[2]) &&
337
- change(pathElems[3]) &&
338
- soft(pathElems[4])) {
339
- return true;
340
- }
341
- if (pathElems.length >= 4 &&
342
- pathElems.length <= 6 &&
343
- 48 + h == pathElems[0] &&
344
- [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
345
- hard(pathElems[2]) &&
346
- hard(pathElems[3]) &&
347
- change(pathElems[4]) &&
348
- soft(pathElems[5])) {
349
- return true;
350
- }
351
- return false;
352
- }
353
- //# sourceMappingURL=Btc.js.map
package/lib/Btc.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAA4C;AAC5C,iDAAiD;AACjD,oDAA8B;AAE9B,uDAAsD;AACtD,qDAAoD;AACpD,iEAAgE;AAEhE,gDAA+C;AAC/C,+DAAqE;AAErE,uDAAsD;AAGtD;;;;;;GAMG;AAEH;IAGE,aAAY,SAAoB,EAAE,WAAmB;QAAnB,4BAAA,EAAA,mBAAmB;QA4RrD,kDAAkD;QAC1C,cAAS,GAA2B,IAAI,CAAC;QA5R/C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,SAAS,CAAC,qBAAqB,CAC7B,IAAI,EACJ;YACE,eAAe;YACf,oBAAoB;YACpB,qBAAqB;YACrB,g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AC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/lib/BtcNew.d.ts DELETED
@@ -1,122 +0,0 @@
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
@@ -1 +0,0 @@
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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