@ledgerhq/live-common 21.4.0 → 21.4.1-btcjs.6

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 (159) hide show
  1. package/lib/__tests__/families/bitcoin/logic.d.ts +2 -0
  2. package/lib/__tests__/families/bitcoin/logic.d.ts.map +1 -0
  3. package/lib/__tests__/families/bitcoin/logic.js +39 -0
  4. package/lib/__tests__/families/bitcoin/logic.js.map +1 -0
  5. package/lib/__tests__/test-helpers/mockDevice.d.ts.map +1 -1
  6. package/lib/__tests__/test-helpers/mockDevice.js +0 -1
  7. package/lib/__tests__/test-helpers/mockDevice.js.map +1 -1
  8. package/lib/account/addAccounts.d.ts.map +1 -1
  9. package/lib/account/addAccounts.js +2 -1
  10. package/lib/account/addAccounts.js.map +1 -1
  11. package/lib/account/support.d.ts.map +1 -1
  12. package/lib/account/support.js +24 -1
  13. package/lib/account/support.js.map +1 -1
  14. package/lib/api/explorerConfig/index.js +15 -15
  15. package/lib/bridge/jsHelpers.d.ts +6 -1
  16. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  17. package/lib/bridge/jsHelpers.js +11 -3
  18. package/lib/bridge/jsHelpers.js.map +1 -1
  19. package/lib/families/bitcoin/account.d.ts.map +1 -1
  20. package/lib/families/bitcoin/account.js +3 -2
  21. package/lib/families/bitcoin/account.js.map +1 -1
  22. package/lib/families/bitcoin/bridge/js.d.ts +8 -0
  23. package/lib/families/bitcoin/bridge/js.d.ts.map +1 -0
  24. package/lib/families/bitcoin/bridge/js.js +149 -0
  25. package/lib/families/bitcoin/bridge/js.js.map +1 -0
  26. package/lib/families/bitcoin/cache.d.ts +28 -0
  27. package/lib/families/bitcoin/cache.d.ts.map +1 -0
  28. package/lib/families/bitcoin/cache.js +109 -0
  29. package/lib/families/bitcoin/cache.js.map +1 -0
  30. package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
  31. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  32. package/lib/families/bitcoin/datasets/litecoin.js +3 -3
  33. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  34. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +6 -0
  35. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -0
  36. package/lib/families/bitcoin/getAccountNetworkInfo.js +124 -0
  37. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -0
  38. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +2 -0
  39. package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +1 -0
  40. package/lib/families/bitcoin/getAccountNetworkInfo.test.js +71 -0
  41. package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +1 -0
  42. package/lib/families/bitcoin/js-broadcast.d.ts +11 -0
  43. package/lib/families/bitcoin/js-broadcast.d.ts.map +1 -0
  44. package/lib/families/bitcoin/js-broadcast.js +80 -0
  45. package/lib/families/bitcoin/js-broadcast.js.map +1 -0
  46. package/lib/families/bitcoin/js-buildTransaction.d.ts +5 -0
  47. package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -0
  48. package/lib/families/bitcoin/js-buildTransaction.js +106 -0
  49. package/lib/families/bitcoin/js-buildTransaction.js.map +1 -0
  50. package/lib/families/bitcoin/js-createTransaction.d.ts +9 -0
  51. package/lib/families/bitcoin/js-createTransaction.d.ts.map +1 -0
  52. package/lib/families/bitcoin/js-createTransaction.js +27 -0
  53. package/lib/families/bitcoin/js-createTransaction.js.map +1 -0
  54. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +15 -0
  55. package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -0
  56. package/lib/families/bitcoin/js-estimateMaxSpendable.js +95 -0
  57. package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -0
  58. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +26 -0
  59. package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +1 -0
  60. package/lib/families/bitcoin/js-getFeesForTransaction.js +100 -0
  61. package/lib/families/bitcoin/js-getFeesForTransaction.js.map +1 -0
  62. package/lib/families/bitcoin/js-getTransactionStatus.d.ts +5 -0
  63. package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +1 -0
  64. package/lib/families/bitcoin/js-getTransactionStatus.js +131 -0
  65. package/lib/families/bitcoin/js-getTransactionStatus.js.map +1 -0
  66. package/lib/families/bitcoin/js-prepareTransaction.d.ts +5 -0
  67. package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +1 -0
  68. package/lib/families/bitcoin/js-prepareTransaction.js +80 -0
  69. package/lib/families/bitcoin/js-prepareTransaction.js.map +1 -0
  70. package/lib/families/bitcoin/js-signOperation.d.ts +10 -0
  71. package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -0
  72. package/lib/families/bitcoin/js-signOperation.js +212 -0
  73. package/lib/families/bitcoin/js-signOperation.js.map +1 -0
  74. package/lib/families/bitcoin/js-synchronisation.d.ts +10 -0
  75. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -0
  76. package/lib/families/bitcoin/js-synchronisation.js +411 -0
  77. package/lib/families/bitcoin/js-synchronisation.js.map +1 -0
  78. package/lib/families/bitcoin/logic.d.ts +34 -0
  79. package/lib/families/bitcoin/logic.d.ts.map +1 -0
  80. package/lib/families/bitcoin/logic.js +290 -0
  81. package/lib/families/bitcoin/logic.js.map +1 -0
  82. package/lib/families/bitcoin/networks.d.ts +3 -0
  83. package/lib/families/bitcoin/networks.d.ts.map +1 -0
  84. package/lib/families/bitcoin/networks.js +379 -0
  85. package/lib/families/bitcoin/networks.js.map +1 -0
  86. package/lib/families/bitcoin/serialization.d.ts +2 -2
  87. package/lib/families/bitcoin/serialization.d.ts.map +1 -1
  88. package/lib/families/bitcoin/serialization.js +8 -4
  89. package/lib/families/bitcoin/serialization.js.map +1 -1
  90. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  91. package/lib/families/bitcoin/specs.js +8 -5
  92. package/lib/families/bitcoin/specs.js.map +1 -1
  93. package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
  94. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  95. package/lib/families/bitcoin/test-dataset.js +1 -1
  96. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  97. package/lib/families/bitcoin/transaction.d.ts +3 -3
  98. package/lib/families/bitcoin/transaction.d.ts.map +1 -1
  99. package/lib/families/bitcoin/transaction.js +64 -61
  100. package/lib/families/bitcoin/transaction.js.map +1 -1
  101. package/lib/families/bitcoin/types.d.ts +66 -36
  102. package/lib/families/bitcoin/types.d.ts.map +1 -1
  103. package/lib/families/bitcoin/types.js +16 -1
  104. package/lib/families/bitcoin/types.js.map +1 -1
  105. package/lib/families/bitcoin/wallet.d.ts +6 -0
  106. package/lib/families/bitcoin/wallet.d.ts.map +1 -0
  107. package/lib/families/bitcoin/wallet.js +66 -0
  108. package/lib/families/bitcoin/wallet.js.map +1 -0
  109. package/lib/generated/bridge/js.d.ts +4 -0
  110. package/lib/generated/bridge/js.d.ts.map +1 -1
  111. package/lib/generated/bridge/js.js +20 -18
  112. package/lib/generated/bridge/js.js.map +1 -1
  113. package/lib/migrations/accounts-dataset.d.ts.map +1 -1
  114. package/lib/migrations/accounts-dataset.js +4 -2
  115. package/lib/migrations/accounts-dataset.js.map +1 -1
  116. package/lib/migrations/accounts.d.ts.map +1 -1
  117. package/lib/migrations/accounts.js +17 -0
  118. package/lib/migrations/accounts.js.map +1 -1
  119. package/lib/mock/account.d.ts.map +1 -1
  120. package/lib/mock/account.js +2 -1
  121. package/lib/mock/account.js.map +1 -1
  122. package/package.json +6 -6
  123. package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -125
  124. package/src/__tests__/families/bitcoin/logic.ts +40 -0
  125. package/src/__tests__/test-helpers/mockDevice.ts +0 -1
  126. package/src/account/addAccounts.ts +2 -1
  127. package/src/account/support.ts +24 -1
  128. package/src/api/explorerConfig/index.ts +15 -15
  129. package/src/bridge/jsHelpers.ts +22 -2
  130. package/src/families/bitcoin/account.ts +2 -1
  131. package/src/families/bitcoin/bridge/js.ts +76 -0
  132. package/src/families/bitcoin/cache.ts +76 -0
  133. package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
  134. package/src/families/bitcoin/datasets/litecoin.ts +6 -6
  135. package/src/families/bitcoin/getAccountNetworkInfo.test.ts +27 -0
  136. package/src/families/bitcoin/getAccountNetworkInfo.ts +61 -0
  137. package/src/families/bitcoin/js-broadcast.ts +30 -0
  138. package/src/families/bitcoin/js-buildTransaction.ts +57 -0
  139. package/src/families/bitcoin/js-createTransaction.ts +27 -0
  140. package/src/families/bitcoin/js-estimateMaxSpendable.ts +36 -0
  141. package/src/families/bitcoin/js-getFeesForTransaction.ts +59 -0
  142. package/src/families/bitcoin/js-getTransactionStatus.ts +118 -0
  143. package/src/families/bitcoin/js-prepareTransaction.ts +35 -0
  144. package/src/families/bitcoin/js-signOperation.ts +164 -0
  145. package/src/families/bitcoin/js-synchronisation.ts +362 -0
  146. package/src/families/bitcoin/logic.ts +255 -0
  147. package/src/families/bitcoin/networks.ts +360 -0
  148. package/src/families/bitcoin/serialization.ts +6 -0
  149. package/src/families/bitcoin/specs.ts +5 -2
  150. package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
  151. package/src/families/bitcoin/test-dataset.ts +1 -1
  152. package/src/families/bitcoin/transaction.ts +98 -93
  153. package/src/families/bitcoin/types.ts +95 -37
  154. package/src/families/bitcoin/wallet.ts +21 -0
  155. package/src/families/ethereum/modules/__snapshots__/compound.resilience.test.ts.snap +50 -9
  156. package/src/generated/bridge/js.ts +3 -0
  157. package/src/migrations/accounts-dataset.ts +3 -0
  158. package/src/migrations/accounts.ts +18 -0
  159. package/src/mock/account.ts +2 -0
@@ -0,0 +1,255 @@
1
+ import cashaddr from "cashaddrjs";
2
+ import bchaddr from "bchaddrjs";
3
+ import { Currency, isValidAddress } from "@ledgerhq/wallet-btc";
4
+ import {
5
+ RecipientRequired,
6
+ InvalidAddress,
7
+ CurrencyNotSupported,
8
+ } from "@ledgerhq/errors";
9
+ import type { Account, CryptoCurrency, CryptoCurrencyIds } from "./../../types";
10
+ import type {
11
+ BitcoinOutput,
12
+ BitcoinResources,
13
+ Transaction,
14
+ NetworkInfo,
15
+ UtxoStrategy,
16
+ CoreBitcoinLikeOutput,
17
+ CoreBitcoinLikeInput,
18
+ BitcoinInput,
19
+ } from "./types";
20
+ import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
21
+
22
+ // correspond ~ to min relay fees but determined empirically for a tx to be accepted by network
23
+ const minFees = {
24
+ bitcoin: 1000,
25
+ bitcoin_gold: 1000,
26
+ pivx: 2000,
27
+ stakenet: 1000,
28
+ stealthcoin: 2000,
29
+ qtum: 4000,
30
+ stratis: 2000,
31
+ vertcoin: 2000,
32
+ viacoin: 2000,
33
+ peercoin: 2000,
34
+ };
35
+ export const getMinRelayFee = (currency: CryptoCurrency): number =>
36
+ minFees[currency.id] || 0;
37
+ export const inferFeePerByte = (t: Transaction, networkInfo: NetworkInfo) => {
38
+ if (t.feesStrategy) {
39
+ const speed = networkInfo.feeItems.items.find(
40
+ (item) => t.feesStrategy === item.speed
41
+ );
42
+
43
+ if (!speed) {
44
+ return networkInfo.feeItems.defaultFeePerByte;
45
+ }
46
+
47
+ return speed.feePerByte;
48
+ }
49
+
50
+ return t.feePerByte || networkInfo.feeItems.defaultFeePerByte;
51
+ };
52
+ export const isValidRecipient = async (params: {
53
+ currency: CryptoCurrency;
54
+ recipient: string;
55
+ }): Promise<Error | null | undefined> => {
56
+ if (!params.recipient) {
57
+ return Promise.reject(new RecipientRequired(""));
58
+ }
59
+
60
+ let valid: boolean;
61
+ try {
62
+ // Optimistically assume params.currency.id is an actual Currency
63
+ valid = isValidAddress(params.recipient, <Currency>params.currency.id);
64
+ } catch (e: any) {
65
+ // isValidAddress() will throw Error if c is not an actual Currency
66
+ return Promise.reject(new InvalidAddress(e.message));
67
+ }
68
+ if (!valid) {
69
+ return Promise.reject(
70
+ new InvalidAddress("Invalid address for currency " + params.currency.name)
71
+ );
72
+ }
73
+ return Promise.resolve(null);
74
+ };
75
+ export function isChangeOutput(output: BitcoinOutput): boolean {
76
+ if (!output.path) return false;
77
+ const p = output.path.split("/");
78
+ return p[p.length - 2] === "1";
79
+ }
80
+
81
+ type UTXOStatus =
82
+ | {
83
+ excluded: true;
84
+ reason: "pickUnconfirmedRBF" | "userExclusion";
85
+ }
86
+ | {
87
+ excluded: false;
88
+ };
89
+ export const getUTXOStatus = (
90
+ utxo: BitcoinOutput,
91
+ utxoStrategy: UtxoStrategy
92
+ ): UTXOStatus => {
93
+ if (!utxoStrategy.pickUnconfirmedRBF && utxo.rbf && !utxo.blockHeight) {
94
+ return {
95
+ excluded: true,
96
+ reason: "pickUnconfirmedRBF",
97
+ };
98
+ }
99
+
100
+ if (
101
+ utxoStrategy.excludeUTXOs.some(
102
+ (u) => u.hash === utxo.hash && u.outputIndex === utxo.outputIndex
103
+ )
104
+ ) {
105
+ return {
106
+ excluded: true,
107
+ reason: "userExclusion",
108
+ };
109
+ }
110
+
111
+ return {
112
+ excluded: false,
113
+ };
114
+ };
115
+
116
+ const bchExplicit = (str: string): string => {
117
+ const explicit = str.includes(":") ? str : "bitcoincash:" + str;
118
+
119
+ try {
120
+ const { type } = cashaddr.decode(explicit);
121
+ if (type === "P2PKH") return explicit;
122
+ } catch (e) {
123
+ // ignore errors
124
+ }
125
+
126
+ return str;
127
+ };
128
+
129
+ type CoinLogic = {
130
+ hasExtraData?: boolean;
131
+ hasExpiryHeight?: boolean;
132
+ getAdditionals?: (arg0: { transaction: Transaction }) => string[];
133
+ asExplicitTransactionRecipient?: (arg0: string) => string;
134
+ onScreenTransactionRecipient?: (arg0: string) => string;
135
+ postBuildBitcoinResources?: (
136
+ arg0: Account,
137
+ arg1?: BitcoinResources
138
+ ) => BitcoinResources;
139
+ syncReplaceAddress?: (addr: string) => string;
140
+ injectGetAddressParams?: (arg0: Account) => any;
141
+ };
142
+
143
+ const bchToCashaddrAddressWithoutPrefix = (recipient) =>
144
+ recipient ? bchaddr.toCashAddress(recipient).split(":")[1] : recipient;
145
+
146
+ export const perCoinLogic: Record<
147
+ CryptoCurrencyIds,
148
+ CoinLogic | null | undefined
149
+ > = {
150
+ zencash: {
151
+ hasExtraData: true, // FIXME (legacy) investigate why we need this here and drop
152
+ },
153
+ zcash: {
154
+ hasExtraData: true,
155
+ hasExpiryHeight: true,
156
+ getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
157
+ },
158
+ komodo: {
159
+ hasExtraData: true,
160
+ hasExpiryHeight: true,
161
+ getAdditionals: () => ["sapling"], // FIXME (legacy) drop in ledgerjs. we always use sapling now for zcash & kmd
162
+ },
163
+ decred: {
164
+ hasExpiryHeight: true,
165
+ },
166
+ bitcoin_gold: {
167
+ getAdditionals: () => ["bip143"],
168
+ },
169
+ bitcoin_cash: {
170
+ getAdditionals: ({ transaction }) => {
171
+ const additionals = ["bip143"];
172
+
173
+ if (bchExplicit(transaction.recipient).startsWith("bitcoincash:")) {
174
+ additionals.push("cashaddr");
175
+ }
176
+
177
+ return additionals;
178
+ },
179
+ // Due to minimal support, we need to return the explicit format of bitcoincash:.. if it's a P2PKH
180
+ asExplicitTransactionRecipient: bchExplicit,
181
+ // to represent what happens on the device, which do not display the bitcoincash: prefix
182
+ onScreenTransactionRecipient: (str: string): string => {
183
+ const prefix = "bitcoincash:";
184
+ return str.startsWith(prefix) ? str.slice(prefix.length) : str;
185
+ },
186
+ syncReplaceAddress: (addr) => bchToCashaddrAddressWithoutPrefix(addr),
187
+ injectGetAddressParams: () => ({
188
+ forceFormat: "cashaddr",
189
+ }),
190
+ },
191
+ };
192
+
193
+ // TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
194
+
195
+ export async function parseBitcoinInput(
196
+ input: CoreBitcoinLikeInput
197
+ ): Promise<BitcoinInput> {
198
+ const address = await input.getAddress();
199
+ const rawValue = await input.getValue();
200
+ const value = rawValue ? await libcoreAmountToBigNumber(rawValue) : null;
201
+ const previousTxHash = await input.getPreviousTxHash();
202
+ const previousOutputIndex = await input.getPreviousOutputIndex();
203
+ return {
204
+ address,
205
+ value,
206
+ previousTxHash,
207
+ previousOutputIndex,
208
+ };
209
+ }
210
+
211
+ export async function parseBitcoinOutput(
212
+ output: CoreBitcoinLikeOutput
213
+ ): Promise<BitcoinOutput> {
214
+ let blockHeight = await output.getBlockHeight();
215
+
216
+ if (!blockHeight || blockHeight < 0) {
217
+ blockHeight = undefined;
218
+ }
219
+
220
+ const hash = await output.getTransactionHash();
221
+ const outputIndex = await output.getOutputIndex();
222
+ const address = await output.getAddress();
223
+ const derivationPath = await output.getDerivationPath();
224
+ let path;
225
+
226
+ if (derivationPath) {
227
+ const isDerivationPathNull = await derivationPath.isNull();
228
+
229
+ if (!isDerivationPathNull) {
230
+ path = await derivationPath.toString();
231
+ }
232
+ }
233
+
234
+ const value = await libcoreAmountToBigNumber(await output.getValue());
235
+ const rbf = false; // this is unsafe to generically call this at the moment. libcore segfault.
236
+
237
+ return {
238
+ hash,
239
+ outputIndex,
240
+ blockHeight,
241
+ address,
242
+ isChange: false,
243
+ path,
244
+ value,
245
+ rbf,
246
+ };
247
+ }
248
+
249
+ export async function parseBitcoinUTXO(
250
+ output: CoreBitcoinLikeOutput
251
+ ): Promise<BitcoinOutput> {
252
+ const utxo = await parseBitcoinOutput(output);
253
+ utxo.rbf = await output.isReplaceable();
254
+ return utxo;
255
+ }
@@ -0,0 +1,360 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import type { BitcoinLikeNetworkParameters } from "./types";
3
+ import { BitcoinLikeFeePolicy, BitcoinLikeSigHashType } from "./types";
4
+
5
+ // TODO Custom parameters from libcore -- not used yet
6
+ /*
7
+ const BIP115_PARAMETERS = {
8
+ blockHash: "9ec9845acb02fab24e1c0368b3b517c1a4488fba97f0e3459ac053ea01000000",
9
+ blockHeight: {0xC0,0x1F,0x02};
10
+ };
11
+ //Zcash overwinter
12
+ const ZIP143_PARAMETERS = {
13
+ 3,
14
+ {0x80},
15
+ {0x03, 0xC4, 0x82, 0x70},
16
+ 347500
17
+ };
18
+ //Zcash Sapling (starting from block 419200)
19
+ const ZIP_SAPLING_PARAMETERS = {
20
+ 4,
21
+ {0x80},
22
+ {0x89, 0x2F, 0x20, 0x85},
23
+ 419200
24
+ };
25
+ */
26
+
27
+ export const getNetworkParameters = (
28
+ networkName: string
29
+ ): BitcoinLikeNetworkParameters => {
30
+ if (networkName === "bitcoin") {
31
+ return {
32
+ identifier: "btc",
33
+ P2PKHVersion: Buffer.from([0x00]),
34
+ P2SHVersion: Buffer.from([0x05]),
35
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
36
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
37
+ dustAmount: new BigNumber(546),
38
+ messagePrefix: "Bitcoin signed message:\n",
39
+ usesTimestampedTransaction: false,
40
+ timestampDelay: new BigNumber(0),
41
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
42
+ additionalBIPs: [],
43
+ };
44
+ } else if (networkName === "bitcoin_testnet") {
45
+ return {
46
+ identifier: "btc_testnet",
47
+ P2PKHVersion: Buffer.from([0x6f]),
48
+ P2SHVersion: Buffer.from([0xc4]),
49
+ xpubVersion: Buffer.from([0x04, 0x35, 0x87, 0xcf]),
50
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
51
+ dustAmount: new BigNumber(546),
52
+ messagePrefix: "Bitcoin signed Message:\n",
53
+ usesTimestampedTransaction: false,
54
+ timestampDelay: new BigNumber(0),
55
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
56
+ additionalBIPs: [],
57
+ };
58
+ } else if (networkName === "bitcoin_cash") {
59
+ return {
60
+ identifier: "abc",
61
+ P2PKHVersion: Buffer.from([0x00]),
62
+ P2SHVersion: Buffer.from([0x05]),
63
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
64
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
65
+ dustAmount: new BigNumber(5430),
66
+ messagePrefix: "Bitcoin signed Message:\n",
67
+ usesTimestampedTransaction: false,
68
+ timestampDelay: new BigNumber(0),
69
+ sigHash:
70
+ BitcoinLikeSigHashType.SIGHASH_ALL |
71
+ BitcoinLikeSigHashType.SIGHASH_FORKID,
72
+ additionalBIPs: [],
73
+ };
74
+ } else if (networkName === "bitcoin_gold") {
75
+ return {
76
+ identifier: "btg",
77
+ P2PKHVersion: Buffer.from([0x26]),
78
+ P2SHVersion: Buffer.from([0x17]),
79
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
80
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
81
+ dustAmount: new BigNumber(5430),
82
+ messagePrefix: "Bitcoin gold signed Message:\n",
83
+ usesTimestampedTransaction: false,
84
+ timestampDelay: new BigNumber(0),
85
+ sigHash:
86
+ BitcoinLikeSigHashType.SIGHASH_ALL |
87
+ BitcoinLikeSigHashType.SIGHASH_FORKID,
88
+ additionalBIPs: [],
89
+ };
90
+ } else if (networkName === "zcash") {
91
+ return {
92
+ identifier: "zec",
93
+ P2PKHVersion: Buffer.from([0x1c, 0xb8]),
94
+ P2SHVersion: Buffer.from([0x1c, 0xbd]),
95
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
96
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
97
+ dustAmount: new BigNumber(10000),
98
+ messagePrefix: "Zcash Signed Message:\n",
99
+ usesTimestampedTransaction: false,
100
+ timestampDelay: new BigNumber(0),
101
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
102
+ additionalBIPs: ["ZIP"],
103
+ };
104
+ } else if (networkName === "zencash") {
105
+ return {
106
+ identifier: "zen",
107
+ P2PKHVersion: Buffer.from([0x20, 0x89]),
108
+ P2SHVersion: Buffer.from([0x20, 0x96]),
109
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
110
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
111
+ dustAmount: new BigNumber(10000),
112
+ messagePrefix: "Zencash Signed Message:\n",
113
+ usesTimestampedTransaction: false,
114
+ timestampDelay: new BigNumber(0),
115
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
116
+ additionalBIPs: ["BIP115"],
117
+ };
118
+ } else if (networkName === "litecoin") {
119
+ return {
120
+ identifier: "ltc",
121
+ P2PKHVersion: Buffer.from([0x30]),
122
+ P2SHVersion: Buffer.from([0x32]),
123
+ xpubVersion: Buffer.from([0x01, 0x9d, 0xa4, 0x62]),
124
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
125
+ dustAmount: new BigNumber(10000),
126
+ messagePrefix: "Litecoin Signed Message:\n",
127
+ usesTimestampedTransaction: false,
128
+ timestampDelay: new BigNumber(0),
129
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
130
+ additionalBIPs: [],
131
+ };
132
+ } else if (networkName === "peercoin") {
133
+ return {
134
+ identifier: "ppc",
135
+ P2PKHVersion: Buffer.from([0x37]),
136
+ P2SHVersion: Buffer.from([0x75]),
137
+ xpubVersion: Buffer.from([0xe6, 0xe8, 0xe9, 0xe5]),
138
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
139
+ dustAmount: new BigNumber(10000),
140
+ messagePrefix: "PPCoin Signed Message:\n",
141
+ usesTimestampedTransaction: true,
142
+ timestampDelay: new BigNumber(0),
143
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
144
+ additionalBIPs: [],
145
+ };
146
+ } else if (networkName === "digibyte") {
147
+ return {
148
+ identifier: "dgb",
149
+ P2PKHVersion: Buffer.from([0x1e]),
150
+ P2SHVersion: Buffer.from([0x3f]),
151
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
152
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
153
+ dustAmount: new BigNumber(10000),
154
+ messagePrefix: "DigiByte Signed Message:\n",
155
+ usesTimestampedTransaction: false,
156
+ timestampDelay: new BigNumber(0),
157
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
158
+ additionalBIPs: [],
159
+ };
160
+ } else if (networkName === "hcash") {
161
+ return {
162
+ identifier: "hsr",
163
+ P2PKHVersion: Buffer.from([0x28]),
164
+ P2SHVersion: Buffer.from([0x78]),
165
+ xpubVersion: Buffer.from([0x04, 0x88, 0xc2, 0x1e]),
166
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
167
+ dustAmount: new BigNumber(10000),
168
+ messagePrefix: "HShare Signed Message:\n",
169
+ usesTimestampedTransaction: true,
170
+ timestampDelay: new BigNumber(0),
171
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
172
+ additionalBIPs: [],
173
+ };
174
+ } else if (networkName === "qtum") {
175
+ return {
176
+ identifier: "qtum",
177
+ P2PKHVersion: Buffer.from([0x3a]),
178
+ P2SHVersion: Buffer.from([0x32]),
179
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
180
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
181
+ dustAmount: new BigNumber(10000),
182
+ messagePrefix: "Qtum Signed Message:\n",
183
+ usesTimestampedTransaction: false,
184
+ timestampDelay: new BigNumber(0),
185
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
186
+ additionalBIPs: [],
187
+ };
188
+ } else if (networkName === "stealthcoin") {
189
+ return {
190
+ identifier: "xst",
191
+ P2PKHVersion: Buffer.from([0x3e]),
192
+ P2SHVersion: Buffer.from([0x55]),
193
+ xpubVersion: Buffer.from([0x8f, 0x62, 0x4b, 0x66]),
194
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
195
+ dustAmount: new BigNumber(10000),
196
+ messagePrefix: "StealthCoin Signed Message:\n",
197
+ usesTimestampedTransaction: false,
198
+ // Used to depend on "version", cf. https://github.com/LedgerHQ/lib-ledger-core/blob/fc9d762b83fc2b269d072b662065747a64ab2816/core/src/wallet/bitcoin/networks.cpp#L250
199
+ timestampDelay: new BigNumber(15),
200
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
201
+ additionalBIPs: [],
202
+ };
203
+ } else if (networkName === "vertcoin") {
204
+ return {
205
+ identifier: "vtc",
206
+ P2PKHVersion: Buffer.from([0x47]),
207
+ P2SHVersion: Buffer.from([0x05]),
208
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
209
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
210
+ dustAmount: new BigNumber(10000),
211
+ messagePrefix: "VertCoin Signed Message:\n",
212
+ usesTimestampedTransaction: false,
213
+ timestampDelay: new BigNumber(0),
214
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
215
+ additionalBIPs: [],
216
+ };
217
+ } else if (networkName === "viacoin") {
218
+ return {
219
+ identifier: "via",
220
+ P2PKHVersion: Buffer.from([0x47]),
221
+ P2SHVersion: Buffer.from([0x21]),
222
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
223
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
224
+ dustAmount: new BigNumber(10000),
225
+ messagePrefix: "ViaCoin Signed Message:\n",
226
+ usesTimestampedTransaction: false,
227
+ timestampDelay: new BigNumber(0),
228
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
229
+ additionalBIPs: [],
230
+ };
231
+ } else if (networkName === "dash") {
232
+ return {
233
+ identifier: "dash",
234
+ P2PKHVersion: Buffer.from([0x4c]),
235
+ P2SHVersion: Buffer.from([0x01]),
236
+ xpubVersion: Buffer.from([0x02, 0xfe, 0x52, 0xf8]),
237
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
238
+ dustAmount: new BigNumber(10000),
239
+ messagePrefix: "DarkCoin Signed Message:\n",
240
+ usesTimestampedTransaction: false,
241
+ timestampDelay: new BigNumber(0),
242
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
243
+ additionalBIPs: [],
244
+ };
245
+ } else if (networkName === "dogecoin") {
246
+ return {
247
+ identifier: "doge",
248
+ P2PKHVersion: Buffer.from([0x1e]),
249
+ P2SHVersion: Buffer.from([0x16]),
250
+ xpubVersion: Buffer.from([0x02, 0xfa, 0xca, 0xfd]),
251
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
252
+ dustAmount: new BigNumber(10000),
253
+ messagePrefix: "DogeCoin Signed Message:\n",
254
+ usesTimestampedTransaction: false,
255
+ timestampDelay: new BigNumber(0),
256
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
257
+ additionalBIPs: [],
258
+ };
259
+ } else if (networkName === "stratis") {
260
+ return {
261
+ identifier: "strat",
262
+ P2PKHVersion: Buffer.from([0x3f]),
263
+ P2SHVersion: Buffer.from([0x7d]),
264
+ xpubVersion: Buffer.from([0x04, 0x88, 0xc2, 0x1e]),
265
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
266
+ dustAmount: new BigNumber(10000),
267
+ messagePrefix: "Stratis Signed Message:\n",
268
+ usesTimestampedTransaction: true,
269
+ timestampDelay: new BigNumber(15),
270
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
271
+ additionalBIPs: [],
272
+ };
273
+ } else if (networkName === "komodo") {
274
+ return {
275
+ identifier: "kmd",
276
+ P2PKHVersion: Buffer.from([0x3c]),
277
+ P2SHVersion: Buffer.from([0x55]),
278
+ xpubVersion: Buffer.from([0xf9, 0xee, 0xe4, 0x8d]),
279
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
280
+ dustAmount: new BigNumber(10000),
281
+ messagePrefix: "Komodo Signed Message:\n",
282
+ usesTimestampedTransaction: false,
283
+ timestampDelay: new BigNumber(0),
284
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
285
+ additionalBIPs: [],
286
+ };
287
+ } else if (networkName === "poswallet") {
288
+ return {
289
+ identifier: "posw",
290
+ P2PKHVersion: Buffer.from([0x37]),
291
+ P2SHVersion: Buffer.from([0x55]),
292
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
293
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
294
+ dustAmount: new BigNumber(10000),
295
+ messagePrefix: "PosWallet Signed Message:\n",
296
+ usesTimestampedTransaction: true,
297
+ timestampDelay: new BigNumber(0),
298
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
299
+ additionalBIPs: [],
300
+ };
301
+ } else if (networkName === "pivx") {
302
+ return {
303
+ identifier: "pivx",
304
+ P2PKHVersion: Buffer.from([0x1e]),
305
+ P2SHVersion: Buffer.from([0x0d]),
306
+ xpubVersion: Buffer.from([0x02, 0x2d, 0x25, 0x33]),
307
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
308
+ dustAmount: new BigNumber(10000),
309
+ messagePrefix: "DarkNet Signed Message:\n",
310
+ usesTimestampedTransaction: false,
311
+ timestampDelay: new BigNumber(0),
312
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
313
+ additionalBIPs: [],
314
+ };
315
+ } else if (networkName === "clubcoin") {
316
+ return {
317
+ identifier: "club",
318
+ P2PKHVersion: Buffer.from([0x1c]),
319
+ P2SHVersion: Buffer.from([0x55]),
320
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
321
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
322
+ dustAmount: new BigNumber(10000),
323
+ messagePrefix: "Clubcoin Signed Message:\n",
324
+ usesTimestampedTransaction: true,
325
+ timestampDelay: new BigNumber(0),
326
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
327
+ additionalBIPs: [],
328
+ };
329
+ } else if (networkName === "decred") {
330
+ return {
331
+ identifier: "dcr",
332
+ P2PKHVersion: Buffer.from([0x07, 0x3f]),
333
+ P2SHVersion: Buffer.from([0x07, 0x1a]),
334
+ xpubVersion: Buffer.from([0x02, 0xfd, 0xa9, 0x26]),
335
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
336
+ dustAmount: new BigNumber(10000),
337
+ messagePrefix: "Decred Signed Message:\n",
338
+ usesTimestampedTransaction: false,
339
+ timestampDelay: new BigNumber(0),
340
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
341
+ additionalBIPs: [],
342
+ };
343
+ } else if (networkName === "stakenet") {
344
+ return {
345
+ identifier: "xsn",
346
+ P2PKHVersion: Buffer.from([0x4c]),
347
+ P2SHVersion: Buffer.from([0x10]),
348
+ xpubVersion: Buffer.from([0x04, 0x88, 0xb2, 0x1e]),
349
+ feePolicy: BitcoinLikeFeePolicy.PER_BYTE,
350
+ dustAmount: new BigNumber(10000),
351
+ messagePrefix: "Stakenet Signed Message:\n",
352
+ usesTimestampedTransaction: false,
353
+ timestampDelay: new BigNumber(0),
354
+ sigHash: BitcoinLikeSigHashType.SIGHASH_ALL,
355
+ additionalBIPs: [],
356
+ };
357
+ }
358
+
359
+ throw new Error("No network parameters set for " + networkName);
360
+ };
@@ -38,6 +38,7 @@ export function toBitcoinOutputRaw({
38
38
  outputIndex,
39
39
  blockHeight,
40
40
  address,
41
+ isChange,
41
42
  path,
42
43
  value,
43
44
  rbf,
@@ -47,6 +48,7 @@ export function toBitcoinOutputRaw({
47
48
  outputIndex,
48
49
  blockHeight,
49
50
  address,
51
+ isChange ? 1 : 0,
50
52
  path,
51
53
  value.toString(),
52
54
  rbf ? 1 : 0,
@@ -57,6 +59,7 @@ export function fromBitcoinOutputRaw([
57
59
  outputIndex,
58
60
  blockHeight,
59
61
  address,
62
+ isChange,
60
63
  path,
61
64
  value,
62
65
  rbf,
@@ -66,6 +69,7 @@ export function fromBitcoinOutputRaw([
66
69
  outputIndex,
67
70
  blockHeight: blockHeight || undefined,
68
71
  address: address || undefined,
72
+ isChange: !!isChange,
69
73
  path: path || undefined,
70
74
  value: new BigNumber(value),
71
75
  rbf: !!rbf,
@@ -76,6 +80,7 @@ export function toBitcoinResourcesRaw(
76
80
  ): BitcoinResourcesRaw {
77
81
  return {
78
82
  utxos: r.utxos.map(toBitcoinOutputRaw),
83
+ serializedData: r.serializedData,
79
84
  };
80
85
  }
81
86
  export function fromBitcoinResourcesRaw(
@@ -83,5 +88,6 @@ export function fromBitcoinResourcesRaw(
83
88
  ): BitcoinResources {
84
89
  return {
85
90
  utxos: r.utxos.map(fromBitcoinOutputRaw),
91
+ serializedData: r.serializedData,
86
92
  };
87
93
  }
@@ -10,8 +10,7 @@ import { pickSiblings } from "../../bot/specs";
10
10
  import { bitcoinPickingStrategy } from "./types";
11
11
  import type { MutationSpec, AppSpec } from "../../bot/types";
12
12
  import { LowerThanMinimumRelayFee } from "../../errors";
13
- import { getMinRelayFee } from "./fees";
14
- import { isChangeOutput, getUTXOStatus } from "./transaction";
13
+ import { getMinRelayFee, getUTXOStatus, isChangeOutput } from "./logic";
15
14
  import { DeviceModelId } from "@ledgerhq/devices";
16
15
  type Arg = Partial<{
17
16
  minimalAmount: BigNumber;
@@ -81,7 +80,11 @@ const genericTest = ({
81
80
  ? operation.senders
82
81
  : txInputs.map((t) => t.address).filter(Boolean),
83
82
  recipients: txOutputs
83
+ // TODO REPLACE >>>>>>>>>>>>>>>>>>
84
84
  .filter((o) => !isChangeOutput(o))
85
+ /*/ WITH <<<<<<<<<<<<<<<<<<<<<<<<<
86
+ .filter((o) => !o.isChange)
87
+ //*/
85
88
  .map((t) => t.address)
86
89
  .filter(Boolean),
87
90
  })
@@ -2,7 +2,7 @@ import type { DeviceAction } from "../../bot/types";
2
2
  import type { Transaction } from "./types";
3
3
  import { formatCurrencyUnit } from "../../currencies";
4
4
  import { deviceActionFlow } from "../../bot/specs";
5
- import { perCoinLogic } from "./transaction";
5
+ import { perCoinLogic } from "./logic";
6
6
  const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
7
7
  steps: [
8
8
  {
@@ -19,7 +19,7 @@ import vertcoin from "./datasets/vertcoin";
19
19
  import viacoin from "./datasets/viacoin";
20
20
  import zcash from "./datasets/zcash";
21
21
  const dataset: DatasetTest<Transaction> = {
22
- implementations: ["libcore", "mock"],
22
+ implementations: ["js", "mock"],
23
23
  currencies: {
24
24
  bitcoin_cash,
25
25
  bitcoin_gold,