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

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 +36 -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
@@ -1 +1,5 @@
1
- @ledgerhq/hw-app-btc:build: cache hit, replaying output e581e0d2100315c4
1
+ @ledgerhq/hw-app-btc:build: cache hit, replaying output 35b2dc24fb93f7bd
2
+ @ledgerhq/hw-app-btc:build:
3
+ @ledgerhq/hw-app-btc:build: > @ledgerhq/hw-app-btc@6.24.2-monorepo.4 build /home/runner/work/ledger-live/ledger-live/libs/ledgerjs/packages/hw-app-btc
4
+ @ledgerhq/hw-app-btc:build: > bash ../../script/build.sh
5
+ @ledgerhq/hw-app-btc:build:
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @ledgerhq/hw-app-btc
2
2
 
3
+ ## 6.24.2-monorepo.4
4
+
5
+ ### Patch Changes
6
+
7
+ - f6cb87454: test prerelease
8
+ - Updated dependencies [f6cb87454]
9
+ - @ledgerhq/hw-transport@6.24.2-monorepo.4
10
+ - @ledgerhq/logs@6.10.1-monorepo.4
11
+
12
+ ## 6.24.2-monorepo.3
13
+
14
+ ### Patch Changes
15
+
16
+ - 7f4a91716: clean pnpm-lock file
17
+ - Updated dependencies [7f4a91716]
18
+ - @ledgerhq/hw-transport@6.24.2-monorepo.3
19
+ - @ledgerhq/logs@6.10.1-monorepo.3
20
+
21
+ ## 6.24.2-monorepo.2
22
+
23
+ ### Patch Changes
24
+
25
+ - a439963a7: test prerelease
26
+ - Updated dependencies [a439963a7]
27
+ - @ledgerhq/hw-transport@6.24.2-monorepo.2
28
+ - @ledgerhq/logs@6.10.1-monorepo.2
29
+
30
+ ## 6.24.2-monorepo.1
31
+
32
+ ### Patch Changes
33
+
34
+ - 1b6fec9db: monorepo prelease 2
35
+ - Updated dependencies [1b6fec9db]
36
+ - @ledgerhq/hw-transport@6.24.2-monorepo.1
37
+ - @ledgerhq/logs@6.10.1-monorepo.1
38
+
3
39
  ## 6.24.2-monorepo.0
4
40
 
5
41
  ### Patch Changes
package/lib/Btc.d.ts ADDED
@@ -0,0 +1,149 @@
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
@@ -0,0 +1 @@
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,CAChB,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE;QACL,MAAM,CAAC,EA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AG,IAAI,MAAM;CAGxB"}
package/lib/Btc.js ADDED
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ exports.__esModule = true;
65
+ var bip32_1 = require("./bip32");
66
+ var BtcNew_1 = __importStar(require("./BtcNew"));
67
+ var BtcOld_1 = __importDefault(require("./BtcOld"));
68
+ var getAppAndVersion_1 = require("./getAppAndVersion");
69
+ var getTrustedInput_1 = require("./getTrustedInput");
70
+ var getTrustedInputBIP143_1 = require("./getTrustedInputBIP143");
71
+ var appClient_1 = require("./newops/appClient");
72
+ var serializeTransaction_1 = require("./serializeTransaction");
73
+ var splitTransaction_1 = require("./splitTransaction");
74
+ /**
75
+ * Bitcoin API.
76
+ *
77
+ * @example
78
+ * import Btc from "@ledgerhq/hw-app-btc";
79
+ * const btc = new Btc(transport)
80
+ */
81
+ var Btc = /** @class */ (function () {
82
+ function Btc(transport, scrambleKey) {
83
+ if (scrambleKey === void 0) { scrambleKey = "BTC"; }
84
+ // cache the underlying implementation (only once)
85
+ this._lazyImpl = null;
86
+ this.transport = transport;
87
+ transport.decorateAppAPIMethods(this, [
88
+ "getWalletXpub",
89
+ "getWalletPublicKey",
90
+ "signP2SHTransaction",
91
+ "signMessageNew",
92
+ "createPaymentTransactionNew",
93
+ "getTrustedInput",
94
+ "getTrustedInputBIP143",
95
+ ], scrambleKey);
96
+ }
97
+ /**
98
+ * Get an XPUB with a ledger device
99
+ * @param arg derivation parameter
100
+ * - path: a BIP 32 path of the account level. e.g. `84'/0'/0'`
101
+ * - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
102
+ * @returns XPUB of the account
103
+ */
104
+ Btc.prototype.getWalletXpub = function (arg) {
105
+ return this.getCorrectImpl().then(function (impl) { return impl.getWalletXpub(arg); });
106
+ };
107
+ /**
108
+ * @param path a BIP 32 path
109
+ * @param options an object with optional these fields:
110
+ *
111
+ * - verify (boolean) will ask user to confirm the address on the device
112
+ *
113
+ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.
114
+ *
115
+ * NB The normal usage is to use:
116
+ *
117
+ * - legacy format with 44' paths
118
+ *
119
+ * - p2sh format with 49' paths
120
+ *
121
+ * - bech32 format with 84' paths
122
+ *
123
+ * - cashaddr in case of Bitcoin Cash
124
+ *
125
+ * @example
126
+ * btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
127
+ * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
128
+ */
129
+ Btc.prototype.getWalletPublicKey = function (path, opts) {
130
+ var _this = this;
131
+ var options;
132
+ if (arguments.length > 2 || typeof opts === "boolean") {
133
+ console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
134
+ options = {
135
+ verify: !!opts,
136
+ // eslint-disable-next-line prefer-rest-params
137
+ format: arguments[2] ? "p2sh" : "legacy"
138
+ };
139
+ }
140
+ else {
141
+ options = opts || {};
142
+ }
143
+ return this.getCorrectImpl().then(function (impl) {
144
+ /**
145
+ * Definition: A "normal path" is a prefix of a standard path where all
146
+ * the hardened steps of the standard path are included. For example, the
147
+ * paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
148
+ * is not. m/'199/1'/17'/0/1 is not a normal path either.
149
+ *
150
+ * There's a compatiblity issue between old and new app: When exporting
151
+ * the key of a non-normal path with verify=false, the new app would
152
+ * return an error, whereas the old app would return the key.
153
+ *
154
+ * See
155
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey
156
+ *
157
+ * If format bech32m is used, we'll not use old, because it doesn't
158
+ * support it.
159
+ *
160
+ * When to use new (given the app supports it)
161
+ * * format is bech32m or
162
+ * * path is normal or
163
+ * * verify is true
164
+ *
165
+ * Otherwise use old.
166
+ */
167
+ if (impl instanceof BtcNew_1["default"] &&
168
+ options.format != "bech32m" &&
169
+ (!options.verify || options.verify == false) &&
170
+ !isPathNormal(path)) {
171
+ 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.");
172
+ return _this.old().getWalletPublicKey(path, options);
173
+ }
174
+ else {
175
+ return impl.getWalletPublicKey(path, options);
176
+ }
177
+ });
178
+ };
179
+ /**
180
+ * 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.
181
+ * @example
182
+ btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
183
+ var v = result['v'] + 27 + 4;
184
+ var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
185
+ console.log("Signature : " + signature);
186
+ }).catch(function(ex) {console.log(ex);});
187
+ */
188
+ Btc.prototype.signMessageNew = function (path, messageHex) {
189
+ return this.old().signMessageNew(path, messageHex);
190
+ };
191
+ /**
192
+ * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
193
+ * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
194
+ *
195
+ * * transaction is the previously computed transaction object for this UTXO
196
+ * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
197
+ * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
198
+ * * sequence is the sequence number to use for this input (when using RBF), or non present
199
+ * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
200
+ * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
201
+ * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
202
+ * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
203
+ * @param sigHashType is the hash type of the transaction to sign, or default (all)
204
+ * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
205
+ * @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)
206
+ * @param additionals list of additionnal options
207
+ *
208
+ * - "bech32" for spending native segwit outputs
209
+ * - "bech32m" for spending segwit v1+ outputs
210
+ * - "abc" for bch
211
+ * - "gold" for btg
212
+ * - "bipxxx" for using BIPxxx
213
+ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
214
+ * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
215
+ * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
216
+ * @return the signed transaction ready to be broadcast
217
+ * @example
218
+ btc.createTransaction({
219
+ inputs: [ [tx1, 1] ],
220
+ associatedKeysets: ["0'/0/0"],
221
+ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
222
+ }).then(res => ...);
223
+ */
224
+ Btc.prototype.createPaymentTransactionNew = function (arg) {
225
+ if (arguments.length > 1) {
226
+ console.warn("@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.");
227
+ }
228
+ return this.getCorrectImpl().then(function (impl) {
229
+ return impl.createPaymentTransactionNew(arg);
230
+ });
231
+ };
232
+ /**
233
+ * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
234
+ * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
235
+ * * transaction is the previously computed transaction object for this UTXO
236
+ * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
237
+ * * redeem script is the mandatory redeem script associated to the current P2SH input
238
+ * * sequence is the sequence number to use for this input (when using RBF), or non present
239
+ * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
240
+ * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
241
+ * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
242
+ * @param sigHashType is the hash type of the transaction to sign, or default (all)
243
+ * @return the signed transaction ready to be broadcast
244
+ * @example
245
+ btc.signP2SHTransaction({
246
+ inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
247
+ associatedKeysets: ["0'/0/0"],
248
+ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
249
+ }).then(result => ...);
250
+ */
251
+ Btc.prototype.signP2SHTransaction = function (arg) {
252
+ return this.old().signP2SHTransaction(arg);
253
+ };
254
+ /**
255
+ * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.
256
+ * @example
257
+ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
258
+ */
259
+ Btc.prototype.splitTransaction = function (transactionHex, isSegwitSupported, hasTimestamp, hasExtraData, additionals) {
260
+ if (isSegwitSupported === void 0) { isSegwitSupported = false; }
261
+ if (hasTimestamp === void 0) { hasTimestamp = false; }
262
+ if (hasExtraData === void 0) { hasExtraData = false; }
263
+ if (additionals === void 0) { additionals = []; }
264
+ return (0, splitTransaction_1.splitTransaction)(transactionHex, isSegwitSupported, hasTimestamp, hasExtraData, additionals);
265
+ };
266
+ /**
267
+ @example
268
+ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");
269
+ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
270
+ */
271
+ Btc.prototype.serializeTransactionOutputs = function (t) {
272
+ return (0, serializeTransaction_1.serializeTransactionOutputs)(t);
273
+ };
274
+ Btc.prototype.getTrustedInput = function (indexLookup, transaction, additionals) {
275
+ if (additionals === void 0) { additionals = []; }
276
+ return (0, getTrustedInput_1.getTrustedInput)(this.transport, indexLookup, transaction, additionals);
277
+ };
278
+ Btc.prototype.getTrustedInputBIP143 = function (indexLookup, transaction, additionals) {
279
+ if (additionals === void 0) { additionals = []; }
280
+ return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(this.transport, indexLookup, transaction, additionals);
281
+ };
282
+ Btc.prototype.getCorrectImpl = function () {
283
+ return __awaiter(this, void 0, void 0, function () {
284
+ var _lazyImpl, impl;
285
+ return __generator(this, function (_a) {
286
+ switch (_a.label) {
287
+ case 0:
288
+ _lazyImpl = this._lazyImpl;
289
+ if (_lazyImpl)
290
+ return [2 /*return*/, _lazyImpl];
291
+ return [4 /*yield*/, this.inferCorrectImpl()];
292
+ case 1:
293
+ impl = _a.sent();
294
+ this._lazyImpl = impl;
295
+ return [2 /*return*/, impl];
296
+ }
297
+ });
298
+ });
299
+ };
300
+ Btc.prototype.inferCorrectImpl = function () {
301
+ return __awaiter(this, void 0, void 0, function () {
302
+ var appAndVersion, canUseNewImplementation;
303
+ return __generator(this, function (_a) {
304
+ switch (_a.label) {
305
+ case 0: return [4 /*yield*/, (0, getAppAndVersion_1.getAppAndVersion)(this.transport)];
306
+ case 1:
307
+ appAndVersion = _a.sent();
308
+ canUseNewImplementation = (0, BtcNew_1.canSupportApp)(appAndVersion);
309
+ if (!canUseNewImplementation) {
310
+ return [2 /*return*/, this.old()];
311
+ }
312
+ else {
313
+ return [2 /*return*/, this["new"]()];
314
+ }
315
+ return [2 /*return*/];
316
+ }
317
+ });
318
+ });
319
+ };
320
+ Btc.prototype.old = function () {
321
+ return new BtcOld_1["default"](this.transport);
322
+ };
323
+ Btc.prototype["new"] = function () {
324
+ return new BtcNew_1["default"](new appClient_1.AppClient(this.transport));
325
+ };
326
+ return Btc;
327
+ }());
328
+ exports["default"] = Btc;
329
+ function isPathNormal(path) {
330
+ //path is not deepest hardened node of a standard path or deeper, use BtcOld
331
+ var h = 0x80000000;
332
+ var pathElems = (0, bip32_1.pathStringToArray)(path);
333
+ var hard = function (n) { return n >= h; };
334
+ var soft = function (n) { return !n || n < h; };
335
+ var change = function (n) { return !n || n == 0 || n == 1; };
336
+ if (pathElems.length >= 3 &&
337
+ pathElems.length <= 5 &&
338
+ [44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
339
+ [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
340
+ hard(pathElems[2]) &&
341
+ change(pathElems[3]) &&
342
+ soft(pathElems[4])) {
343
+ return true;
344
+ }
345
+ if (pathElems.length >= 4 &&
346
+ pathElems.length <= 6 &&
347
+ 48 + h == pathElems[0] &&
348
+ [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
349
+ hard(pathElems[2]) &&
350
+ hard(pathElems[3]) &&
351
+ change(pathElems[4]) &&
352
+ soft(pathElems[5])) {
353
+ return true;
354
+ }
355
+ return false;
356
+ }
357
+ //# sourceMappingURL=Btc.js.map
package/lib/Btc.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;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