@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.
- package/lib/__tests__/families/bitcoin/logic.d.ts +2 -0
- package/lib/__tests__/families/bitcoin/logic.d.ts.map +1 -0
- package/lib/__tests__/families/bitcoin/logic.js +39 -0
- package/lib/__tests__/families/bitcoin/logic.js.map +1 -0
- package/lib/__tests__/test-helpers/mockDevice.d.ts.map +1 -1
- package/lib/__tests__/test-helpers/mockDevice.js +0 -1
- package/lib/__tests__/test-helpers/mockDevice.js.map +1 -1
- package/lib/account/addAccounts.d.ts.map +1 -1
- package/lib/account/addAccounts.js +2 -1
- package/lib/account/addAccounts.js.map +1 -1
- package/lib/account/support.d.ts.map +1 -1
- package/lib/account/support.js +24 -1
- package/lib/account/support.js.map +1 -1
- package/lib/api/explorerConfig/index.js +15 -15
- package/lib/bridge/jsHelpers.d.ts +6 -1
- package/lib/bridge/jsHelpers.d.ts.map +1 -1
- package/lib/bridge/jsHelpers.js +11 -3
- package/lib/bridge/jsHelpers.js.map +1 -1
- package/lib/families/bitcoin/account.d.ts.map +1 -1
- package/lib/families/bitcoin/account.js +3 -2
- package/lib/families/bitcoin/account.js.map +1 -1
- package/lib/families/bitcoin/bridge/js.d.ts +8 -0
- package/lib/families/bitcoin/bridge/js.d.ts.map +1 -0
- package/lib/families/bitcoin/bridge/js.js +149 -0
- package/lib/families/bitcoin/bridge/js.js.map +1 -0
- package/lib/families/bitcoin/cache.d.ts +28 -0
- package/lib/families/bitcoin/cache.d.ts.map +1 -0
- package/lib/families/bitcoin/cache.js +109 -0
- package/lib/families/bitcoin/cache.js.map +1 -0
- package/lib/families/bitcoin/datasets/bitcoin.js +6 -6
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/datasets/litecoin.js +3 -3
- package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts +6 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.js +124 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts +2 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.test.d.ts.map +1 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js +71 -0
- package/lib/families/bitcoin/getAccountNetworkInfo.test.js.map +1 -0
- package/lib/families/bitcoin/js-broadcast.d.ts +11 -0
- package/lib/families/bitcoin/js-broadcast.d.ts.map +1 -0
- package/lib/families/bitcoin/js-broadcast.js +80 -0
- package/lib/families/bitcoin/js-broadcast.js.map +1 -0
- package/lib/families/bitcoin/js-buildTransaction.d.ts +5 -0
- package/lib/families/bitcoin/js-buildTransaction.d.ts.map +1 -0
- package/lib/families/bitcoin/js-buildTransaction.js +106 -0
- package/lib/families/bitcoin/js-buildTransaction.js.map +1 -0
- package/lib/families/bitcoin/js-createTransaction.d.ts +9 -0
- package/lib/families/bitcoin/js-createTransaction.d.ts.map +1 -0
- package/lib/families/bitcoin/js-createTransaction.js +27 -0
- package/lib/families/bitcoin/js-createTransaction.js.map +1 -0
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts +15 -0
- package/lib/families/bitcoin/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/families/bitcoin/js-estimateMaxSpendable.js +95 -0
- package/lib/families/bitcoin/js-estimateMaxSpendable.js.map +1 -0
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts +26 -0
- package/lib/families/bitcoin/js-getFeesForTransaction.d.ts.map +1 -0
- package/lib/families/bitcoin/js-getFeesForTransaction.js +100 -0
- package/lib/families/bitcoin/js-getFeesForTransaction.js.map +1 -0
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts +5 -0
- package/lib/families/bitcoin/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/families/bitcoin/js-getTransactionStatus.js +131 -0
- package/lib/families/bitcoin/js-getTransactionStatus.js.map +1 -0
- package/lib/families/bitcoin/js-prepareTransaction.d.ts +5 -0
- package/lib/families/bitcoin/js-prepareTransaction.d.ts.map +1 -0
- package/lib/families/bitcoin/js-prepareTransaction.js +80 -0
- package/lib/families/bitcoin/js-prepareTransaction.js.map +1 -0
- package/lib/families/bitcoin/js-signOperation.d.ts +10 -0
- package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -0
- package/lib/families/bitcoin/js-signOperation.js +212 -0
- package/lib/families/bitcoin/js-signOperation.js.map +1 -0
- package/lib/families/bitcoin/js-synchronisation.d.ts +10 -0
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -0
- package/lib/families/bitcoin/js-synchronisation.js +411 -0
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -0
- package/lib/families/bitcoin/logic.d.ts +34 -0
- package/lib/families/bitcoin/logic.d.ts.map +1 -0
- package/lib/families/bitcoin/logic.js +290 -0
- package/lib/families/bitcoin/logic.js.map +1 -0
- package/lib/families/bitcoin/networks.d.ts +3 -0
- package/lib/families/bitcoin/networks.d.ts.map +1 -0
- package/lib/families/bitcoin/networks.js +379 -0
- package/lib/families/bitcoin/networks.js.map +1 -0
- package/lib/families/bitcoin/serialization.d.ts +2 -2
- package/lib/families/bitcoin/serialization.d.ts.map +1 -1
- package/lib/families/bitcoin/serialization.js +8 -4
- package/lib/families/bitcoin/serialization.js.map +1 -1
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +8 -5
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/speculos-deviceActions.js +2 -2
- package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
- package/lib/families/bitcoin/test-dataset.js +1 -1
- package/lib/families/bitcoin/test-dataset.js.map +1 -1
- package/lib/families/bitcoin/transaction.d.ts +3 -3
- package/lib/families/bitcoin/transaction.d.ts.map +1 -1
- package/lib/families/bitcoin/transaction.js +64 -61
- package/lib/families/bitcoin/transaction.js.map +1 -1
- package/lib/families/bitcoin/types.d.ts +66 -36
- package/lib/families/bitcoin/types.d.ts.map +1 -1
- package/lib/families/bitcoin/types.js +16 -1
- package/lib/families/bitcoin/types.js.map +1 -1
- package/lib/families/bitcoin/wallet.d.ts +6 -0
- package/lib/families/bitcoin/wallet.d.ts.map +1 -0
- package/lib/families/bitcoin/wallet.js +66 -0
- package/lib/families/bitcoin/wallet.js.map +1 -0
- package/lib/generated/bridge/js.d.ts +4 -0
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +20 -18
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/migrations/accounts-dataset.d.ts.map +1 -1
- package/lib/migrations/accounts-dataset.js +4 -2
- package/lib/migrations/accounts-dataset.js.map +1 -1
- package/lib/migrations/accounts.d.ts.map +1 -1
- package/lib/migrations/accounts.js +17 -0
- package/lib/migrations/accounts.js.map +1 -1
- package/lib/mock/account.d.ts.map +1 -1
- package/lib/mock/account.js +2 -1
- package/lib/mock/account.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -125
- package/src/__tests__/families/bitcoin/logic.ts +40 -0
- package/src/__tests__/test-helpers/mockDevice.ts +0 -1
- package/src/account/addAccounts.ts +2 -1
- package/src/account/support.ts +24 -1
- package/src/api/explorerConfig/index.ts +15 -15
- package/src/bridge/jsHelpers.ts +22 -2
- package/src/families/bitcoin/account.ts +2 -1
- package/src/families/bitcoin/bridge/js.ts +76 -0
- package/src/families/bitcoin/cache.ts +76 -0
- package/src/families/bitcoin/datasets/bitcoin.ts +6 -6
- package/src/families/bitcoin/datasets/litecoin.ts +6 -6
- package/src/families/bitcoin/getAccountNetworkInfo.test.ts +27 -0
- package/src/families/bitcoin/getAccountNetworkInfo.ts +61 -0
- package/src/families/bitcoin/js-broadcast.ts +30 -0
- package/src/families/bitcoin/js-buildTransaction.ts +57 -0
- package/src/families/bitcoin/js-createTransaction.ts +27 -0
- package/src/families/bitcoin/js-estimateMaxSpendable.ts +36 -0
- package/src/families/bitcoin/js-getFeesForTransaction.ts +59 -0
- package/src/families/bitcoin/js-getTransactionStatus.ts +118 -0
- package/src/families/bitcoin/js-prepareTransaction.ts +35 -0
- package/src/families/bitcoin/js-signOperation.ts +164 -0
- package/src/families/bitcoin/js-synchronisation.ts +362 -0
- package/src/families/bitcoin/logic.ts +255 -0
- package/src/families/bitcoin/networks.ts +360 -0
- package/src/families/bitcoin/serialization.ts +6 -0
- package/src/families/bitcoin/specs.ts +5 -2
- package/src/families/bitcoin/speculos-deviceActions.ts +1 -1
- package/src/families/bitcoin/test-dataset.ts +1 -1
- package/src/families/bitcoin/transaction.ts +98 -93
- package/src/families/bitcoin/types.ts +95 -37
- package/src/families/bitcoin/wallet.ts +21 -0
- package/src/families/ethereum/modules/__snapshots__/compound.resilience.test.ts.snap +50 -9
- package/src/generated/bridge/js.ts +3 -0
- package/src/migrations/accounts-dataset.ts +3 -0
- package/src/migrations/accounts.ts +18 -0
- package/src/mock/account.ts +2 -0
|
@@ -25,6 +25,102 @@ import { formatCurrencyUnit } from "../../currencies";
|
|
|
25
25
|
import type { CryptoCurrencyIds } from "../../types";
|
|
26
26
|
import { libcoreAmountToBigNumber } from "../../libcore/buildBigNumber";
|
|
27
27
|
|
|
28
|
+
const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
|
|
29
|
+
items: fir.items.map((fi) => ({
|
|
30
|
+
key: fi.key,
|
|
31
|
+
speed: fi.speed,
|
|
32
|
+
feePerByte: new BigNumber(fi.feePerByte),
|
|
33
|
+
})),
|
|
34
|
+
defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
|
|
38
|
+
items: fir.items.map((fi) => ({
|
|
39
|
+
key: fi.key,
|
|
40
|
+
speed: fi.speed,
|
|
41
|
+
feePerByte: fi.feePerByte.toString(),
|
|
42
|
+
})),
|
|
43
|
+
defaultFeePerByte: fir.defaultFeePerByte.toString(),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
47
|
+
const common = fromTransactionCommonRaw(tr);
|
|
48
|
+
return {
|
|
49
|
+
...common,
|
|
50
|
+
rbf: tr.rbf,
|
|
51
|
+
utxoStrategy: tr.utxoStrategy,
|
|
52
|
+
family: tr.family,
|
|
53
|
+
feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
|
|
54
|
+
networkInfo: tr.networkInfo && {
|
|
55
|
+
family: tr.networkInfo.family,
|
|
56
|
+
feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
|
|
57
|
+
},
|
|
58
|
+
feesStrategy: tr.feesStrategy,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
62
|
+
const common = toTransactionCommonRaw(t);
|
|
63
|
+
return {
|
|
64
|
+
...common,
|
|
65
|
+
rbf: t.rbf,
|
|
66
|
+
utxoStrategy: t.utxoStrategy,
|
|
67
|
+
family: t.family,
|
|
68
|
+
feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
|
|
69
|
+
networkInfo: t.networkInfo && {
|
|
70
|
+
family: t.networkInfo.family,
|
|
71
|
+
feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
|
|
72
|
+
},
|
|
73
|
+
feesStrategy: t.feesStrategy,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const formatNetworkInfo = (
|
|
78
|
+
networkInfo:
|
|
79
|
+
| {
|
|
80
|
+
feeItems: FeeItems;
|
|
81
|
+
}
|
|
82
|
+
| null
|
|
83
|
+
| undefined
|
|
84
|
+
) => {
|
|
85
|
+
if (!networkInfo) return "network info not loaded";
|
|
86
|
+
return `network fees: ${networkInfo.feeItems.items
|
|
87
|
+
.map((i) => i.key + "=" + i.feePerByte.toString())
|
|
88
|
+
.join(", ")}`;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const formatTransaction = (t: Transaction, account: Account): string => {
|
|
92
|
+
const n = getEnv("DEBUG_UTXO_DISPLAY");
|
|
93
|
+
const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
|
|
94
|
+
const displayAll = excludeUTXOs.length <= n;
|
|
95
|
+
return `
|
|
96
|
+
SEND ${
|
|
97
|
+
t.useAllAmount
|
|
98
|
+
? "MAX"
|
|
99
|
+
: formatCurrencyUnit(getAccountUnit(account), t.amount, {
|
|
100
|
+
showCode: true,
|
|
101
|
+
disableRounding: true,
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
TO ${t.recipient}
|
|
105
|
+
with feePerByte=${
|
|
106
|
+
t.feePerByte ? t.feePerByte.toString() : "?"
|
|
107
|
+
} (${formatNetworkInfo(t.networkInfo)})
|
|
108
|
+
${[
|
|
109
|
+
Object.keys(bitcoinPickingStrategy).find(
|
|
110
|
+
(k) => bitcoinPickingStrategy[k] === strategy
|
|
111
|
+
),
|
|
112
|
+
pickUnconfirmedRBF && "pick-unconfirmed",
|
|
113
|
+
t.rbf && "RBF-enabled",
|
|
114
|
+
]
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join(" ")}${excludeUTXOs
|
|
117
|
+
.slice(0, displayAll ? excludeUTXOs.length : n)
|
|
118
|
+
.map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
|
|
119
|
+
.join("")}`;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// TODO vvvvv DEPRECATED, TO BE REMOVED vvvvv
|
|
123
|
+
|
|
28
124
|
function bchExplicit(str: string): string {
|
|
29
125
|
const explicit = str.includes(":") ? str : "bitcoincash:" + str;
|
|
30
126
|
|
|
@@ -158,6 +254,7 @@ export async function parseBitcoinOutput(
|
|
|
158
254
|
outputIndex,
|
|
159
255
|
blockHeight,
|
|
160
256
|
address,
|
|
257
|
+
isChange: false,
|
|
161
258
|
path,
|
|
162
259
|
value,
|
|
163
260
|
rbf,
|
|
@@ -201,100 +298,8 @@ export function isChangeOutput(output: BitcoinOutput): boolean {
|
|
|
201
298
|
const p = output.path.split("/");
|
|
202
299
|
return p[p.length - 2] === "1";
|
|
203
300
|
}
|
|
301
|
+
// ==============================================================================
|
|
204
302
|
|
|
205
|
-
const fromFeeItemsRaw = (fir: FeeItemsRaw): FeeItems => ({
|
|
206
|
-
items: fir.items.map((fi) => ({
|
|
207
|
-
key: fi.key,
|
|
208
|
-
speed: fi.speed,
|
|
209
|
-
feePerByte: new BigNumber(fi.feePerByte),
|
|
210
|
-
})),
|
|
211
|
-
defaultFeePerByte: new BigNumber(fir.defaultFeePerByte),
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
const toFeeItemsRaw = (fir: FeeItems): FeeItemsRaw => ({
|
|
215
|
-
items: fir.items.map((fi) => ({
|
|
216
|
-
key: fi.key,
|
|
217
|
-
speed: fi.speed,
|
|
218
|
-
feePerByte: fi.feePerByte.toString(),
|
|
219
|
-
})),
|
|
220
|
-
defaultFeePerByte: fir.defaultFeePerByte.toString(),
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
224
|
-
const common = fromTransactionCommonRaw(tr);
|
|
225
|
-
return {
|
|
226
|
-
...common,
|
|
227
|
-
rbf: tr.rbf,
|
|
228
|
-
utxoStrategy: tr.utxoStrategy,
|
|
229
|
-
family: tr.family,
|
|
230
|
-
feePerByte: tr.feePerByte ? new BigNumber(tr.feePerByte) : null,
|
|
231
|
-
networkInfo: tr.networkInfo && {
|
|
232
|
-
family: tr.networkInfo.family,
|
|
233
|
-
feeItems: fromFeeItemsRaw(tr.networkInfo.feeItems),
|
|
234
|
-
},
|
|
235
|
-
feesStrategy: tr.feesStrategy,
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
239
|
-
const common = toTransactionCommonRaw(t);
|
|
240
|
-
return {
|
|
241
|
-
...common,
|
|
242
|
-
rbf: t.rbf,
|
|
243
|
-
utxoStrategy: t.utxoStrategy,
|
|
244
|
-
family: t.family,
|
|
245
|
-
feePerByte: t.feePerByte ? t.feePerByte.toString() : null,
|
|
246
|
-
networkInfo: t.networkInfo && {
|
|
247
|
-
family: t.networkInfo.family,
|
|
248
|
-
feeItems: toFeeItemsRaw(t.networkInfo.feeItems),
|
|
249
|
-
},
|
|
250
|
-
feesStrategy: t.feesStrategy,
|
|
251
|
-
};
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const formatNetworkInfo = (
|
|
255
|
-
networkInfo:
|
|
256
|
-
| {
|
|
257
|
-
feeItems: FeeItems;
|
|
258
|
-
}
|
|
259
|
-
| null
|
|
260
|
-
| undefined
|
|
261
|
-
) => {
|
|
262
|
-
if (!networkInfo) return "network info not loaded";
|
|
263
|
-
return `network fees: ${networkInfo.feeItems.items
|
|
264
|
-
.map((i) => i.key + "=" + i.feePerByte.toString())
|
|
265
|
-
.join(", ")}`;
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export const formatTransaction = (t: Transaction, account: Account): string => {
|
|
269
|
-
const n = getEnv("DEBUG_UTXO_DISPLAY");
|
|
270
|
-
const { excludeUTXOs, strategy, pickUnconfirmedRBF } = t.utxoStrategy;
|
|
271
|
-
const displayAll = excludeUTXOs.length <= n;
|
|
272
|
-
return `
|
|
273
|
-
SEND ${
|
|
274
|
-
t.useAllAmount
|
|
275
|
-
? "MAX"
|
|
276
|
-
: formatCurrencyUnit(getAccountUnit(account), t.amount, {
|
|
277
|
-
showCode: true,
|
|
278
|
-
disableRounding: true,
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
TO ${t.recipient}
|
|
282
|
-
with feePerByte=${
|
|
283
|
-
t.feePerByte ? t.feePerByte.toString() : "?"
|
|
284
|
-
} (${formatNetworkInfo(t.networkInfo)})
|
|
285
|
-
${[
|
|
286
|
-
Object.keys(bitcoinPickingStrategy).find(
|
|
287
|
-
(k) => bitcoinPickingStrategy[k] === strategy
|
|
288
|
-
),
|
|
289
|
-
pickUnconfirmedRBF && "pick-unconfirmed",
|
|
290
|
-
t.rbf && "RBF-enabled",
|
|
291
|
-
]
|
|
292
|
-
.filter(Boolean)
|
|
293
|
-
.join(" ")}${excludeUTXOs
|
|
294
|
-
.slice(0, displayAll ? excludeUTXOs.length : n)
|
|
295
|
-
.map((utxo) => `\nexclude ${utxo.hash} @${utxo.outputIndex}`)
|
|
296
|
-
.join("")}`;
|
|
297
|
-
};
|
|
298
303
|
export default {
|
|
299
304
|
fromTransactionRaw,
|
|
300
305
|
toTransactionRaw,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { SerializedAccount as WalletSerializedAccount } from "@ledgerhq/wallet-btc";
|
|
3
|
+
|
|
2
4
|
import type {
|
|
3
5
|
TransactionCommon,
|
|
4
6
|
TransactionCommonRaw,
|
|
@@ -9,43 +11,8 @@ import type {
|
|
|
9
11
|
CoreDerivationPath,
|
|
10
12
|
Spec,
|
|
11
13
|
} from "../../libcore/types";
|
|
12
|
-
export type BitcoinInput = {
|
|
13
|
-
address: string | null | undefined;
|
|
14
|
-
value: BigNumber | null | undefined;
|
|
15
|
-
previousTxHash: string | null | undefined;
|
|
16
|
-
previousOutputIndex: number;
|
|
17
|
-
};
|
|
18
|
-
export type BitcoinInputRaw = [
|
|
19
|
-
string | null | undefined,
|
|
20
|
-
string | null | undefined,
|
|
21
|
-
string | null | undefined,
|
|
22
|
-
number
|
|
23
|
-
];
|
|
24
|
-
export type BitcoinOutput = {
|
|
25
|
-
hash: string;
|
|
26
|
-
outputIndex: number;
|
|
27
|
-
blockHeight: number | null | undefined;
|
|
28
|
-
address: string | null | undefined;
|
|
29
|
-
path: string | null | undefined;
|
|
30
|
-
value: BigNumber;
|
|
31
|
-
rbf: boolean;
|
|
32
|
-
};
|
|
33
|
-
export type BitcoinOutputRaw = [
|
|
34
|
-
string,
|
|
35
|
-
number,
|
|
36
|
-
number | null | undefined,
|
|
37
|
-
string | null | undefined,
|
|
38
|
-
string | null | undefined,
|
|
39
|
-
string,
|
|
40
|
-
number // rbf 0/1 for compression
|
|
41
|
-
];
|
|
42
|
-
export type BitcoinResources = {
|
|
43
|
-
utxos: BitcoinOutput[];
|
|
44
|
-
};
|
|
45
|
-
export type BitcoinResourcesRaw = {
|
|
46
|
-
utxos: BitcoinOutputRaw[];
|
|
47
|
-
};
|
|
48
14
|
|
|
15
|
+
//* TODO REPLACE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
49
16
|
declare class CoreBitcoinLikeInput {
|
|
50
17
|
getPreviousTransaction(): Promise<string>;
|
|
51
18
|
getPreviousTxHash(): Promise<string | null | undefined>;
|
|
@@ -130,6 +97,93 @@ export type CoreOperationSpecifics = {
|
|
|
130
97
|
export type CoreCurrencySpecifics = {
|
|
131
98
|
getBitcoinLikeNetworkParameters(): Promise<CoreBitcoinLikeNetworkParameters>;
|
|
132
99
|
};
|
|
100
|
+
/*/ WITH >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
101
|
+
export type CoreStatics = Record<string, never>;
|
|
102
|
+
export type CoreAccountSpecifics = Record<string, never>;
|
|
103
|
+
export type CoreOperationSpecifics = Record<string, never>;
|
|
104
|
+
export type CoreCurrencySpecifics = Record<string, never>;
|
|
105
|
+
//*/ // ====================================================
|
|
106
|
+
|
|
107
|
+
export type BitcoinInput = {
|
|
108
|
+
address: string | null | undefined;
|
|
109
|
+
value: BigNumber | null | undefined;
|
|
110
|
+
previousTxHash: string | null | undefined;
|
|
111
|
+
previousOutputIndex: number;
|
|
112
|
+
};
|
|
113
|
+
export type BitcoinInputRaw = [
|
|
114
|
+
string | null | undefined,
|
|
115
|
+
string | null | undefined,
|
|
116
|
+
string | null | undefined,
|
|
117
|
+
number
|
|
118
|
+
];
|
|
119
|
+
export type BitcoinOutput = {
|
|
120
|
+
hash: string;
|
|
121
|
+
outputIndex: number;
|
|
122
|
+
blockHeight: number | null | undefined;
|
|
123
|
+
address: string | null | undefined;
|
|
124
|
+
isChange: boolean;
|
|
125
|
+
path: string | null | undefined; // TODO DEPRECATED, TO BE REMOVED
|
|
126
|
+
value: BigNumber;
|
|
127
|
+
rbf: boolean;
|
|
128
|
+
};
|
|
129
|
+
export type BitcoinOutputRaw = [
|
|
130
|
+
string,
|
|
131
|
+
number,
|
|
132
|
+
number | null | undefined,
|
|
133
|
+
string | null | undefined,
|
|
134
|
+
number,
|
|
135
|
+
string | null | undefined, // TODO DEPRECATED, TO BE REMOVED
|
|
136
|
+
string,
|
|
137
|
+
number // rbf 0/1 for compression
|
|
138
|
+
];
|
|
139
|
+
export type BitcoinResources = {
|
|
140
|
+
utxos: BitcoinOutput[];
|
|
141
|
+
serializedData?: WalletSerializedAccount; // TODO '?' TO BE REMOVED
|
|
142
|
+
};
|
|
143
|
+
export type BitcoinResourcesRaw = {
|
|
144
|
+
utxos: BitcoinOutputRaw[];
|
|
145
|
+
serializedData?: WalletSerializedAccount; // TODO '?' TO BE REMOVED
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const BitcoinLikeFeePolicy = Object.freeze({
|
|
149
|
+
PER_BYTE: "PER_BYTE",
|
|
150
|
+
PER_KBYTE: "PER_KBYTE",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export const BitcoinLikeSigHashType = Object.freeze({
|
|
154
|
+
SIGHASH_ALL: 0x01,
|
|
155
|
+
SIGHASH_NONE: 0x02,
|
|
156
|
+
SIGHASH_SINGLE: 0x03,
|
|
157
|
+
SIGHASH_FORKID: 0x40,
|
|
158
|
+
SIGHASH_ANYONECANPAY: 0x80,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// TODO maybe not all fields are useful
|
|
162
|
+
export type BitcoinLikeNetworkParameters = {
|
|
163
|
+
// Name of the network.
|
|
164
|
+
identifier: string;
|
|
165
|
+
// Version of the Pay To Public Hash standard.
|
|
166
|
+
P2PKHVersion: Buffer;
|
|
167
|
+
// Version of the Pay To Script Hash standard.
|
|
168
|
+
P2SHVersion: Buffer;
|
|
169
|
+
// Version of the Extended Public Key standard.
|
|
170
|
+
xpubVersion: Buffer;
|
|
171
|
+
// Policy to use when expressing fee amount, values in BitcoinLikeFeePolicy
|
|
172
|
+
feePolicy: string;
|
|
173
|
+
// Minimal amount a UTXO should have before being considered BTC dust.
|
|
174
|
+
dustAmount: BigNumber;
|
|
175
|
+
// Constant prefix to prepend all signature messages.
|
|
176
|
+
messagePrefix: string;
|
|
177
|
+
// Are transactions encoded with timestamp?
|
|
178
|
+
usesTimestampedTransaction: boolean;
|
|
179
|
+
// Delay applied to all timestamps. Used to debounce transactions.
|
|
180
|
+
timestampDelay: BigNumber;
|
|
181
|
+
// Bitcoin signature flag indicating what part of a transaction a signature signs, values in BitcoinLikeSigHashType
|
|
182
|
+
sigHash: number;
|
|
183
|
+
// Addition BIPs enabled for this network.
|
|
184
|
+
additionalBIPs: string[];
|
|
185
|
+
};
|
|
186
|
+
|
|
133
187
|
export type FeeItem = {
|
|
134
188
|
key: string;
|
|
135
189
|
speed: string;
|
|
@@ -163,7 +217,6 @@ export const bitcoinPickingStrategy = {
|
|
|
163
217
|
};
|
|
164
218
|
export type BitcoinPickingStrategy =
|
|
165
219
|
typeof bitcoinPickingStrategy[keyof typeof bitcoinPickingStrategy];
|
|
166
|
-
// FIXME the UtxoStrategy level should be flattened back in Transaction
|
|
167
220
|
export type UtxoStrategy = {
|
|
168
221
|
strategy: BitcoinPickingStrategy;
|
|
169
222
|
pickUnconfirmedRBF: boolean;
|
|
@@ -186,6 +239,8 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
186
239
|
feePerByte: string | null | undefined;
|
|
187
240
|
networkInfo: NetworkInfoRaw | null | undefined;
|
|
188
241
|
};
|
|
242
|
+
|
|
243
|
+
//* TODO REPLACE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
|
189
244
|
export const reflect = (
|
|
190
245
|
declare: (arg0: string, arg1: Spec) => void
|
|
191
246
|
): {
|
|
@@ -315,3 +370,6 @@ export const reflect = (
|
|
|
315
370
|
},
|
|
316
371
|
};
|
|
317
372
|
};
|
|
373
|
+
/*/ WITH >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
374
|
+
export const reflect = (_declare: any): void => {};
|
|
375
|
+
//*/ // ====================================================
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { WalletLedger } from "@ledgerhq/wallet-btc";
|
|
2
|
+
import type { Account } from "./../../types";
|
|
3
|
+
let wallet: WalletLedger | null = null;
|
|
4
|
+
export const getWalletAccount = async (account: Account) => {
|
|
5
|
+
const walletData = account.bitcoinResources?.serializedData;
|
|
6
|
+
if (!walletData) {
|
|
7
|
+
throw new Error("bitcoin wallet account expected");
|
|
8
|
+
}
|
|
9
|
+
const walletInstance = getWallet();
|
|
10
|
+
return await walletInstance.importFromSerializedAccount(walletData);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getWallet = () => {
|
|
14
|
+
if (!wallet) {
|
|
15
|
+
wallet = new WalletLedger();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return wallet;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default getWallet();
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`if API is down, an account still sync fine 1`] = `
|
|
4
4
|
Object {
|
|
5
|
-
"balance": "
|
|
5
|
+
"balance": "0",
|
|
6
6
|
"blockHeight": 0,
|
|
7
7
|
"creationDate": "",
|
|
8
8
|
"currencyId": "ethereum",
|
|
@@ -15,6 +15,47 @@ Object {
|
|
|
15
15
|
"lastSyncDate": "",
|
|
16
16
|
"name": "Ethereum legacy xpub6Bem...JyAdpYZy",
|
|
17
17
|
"operations": Array [
|
|
18
|
+
Object {
|
|
19
|
+
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
20
|
+
"blockHash": "0x3d995e1931a059b0acb13a1595d4c6668b4c5ca384de8823c4a72c828507e984",
|
|
21
|
+
"blockHeight": 0,
|
|
22
|
+
"date": "",
|
|
23
|
+
"extra": Object {},
|
|
24
|
+
"fee": "2110500000000000",
|
|
25
|
+
"hasFailed": false,
|
|
26
|
+
"hash": "0x12bcdadf67b905eb6955b4c435f78b8c4eb4fb3a8c8bc16305331474b2897174",
|
|
27
|
+
"id": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:-0x12bcdadf67b905eb6955b4c435f78b8c4eb4fb3a8c8bc16305331474b2897174-OUT",
|
|
28
|
+
"internalOperations": Array [],
|
|
29
|
+
"recipients": Array [
|
|
30
|
+
"0x17733CAb76d9A2112576443F21735789733B1ca3",
|
|
31
|
+
],
|
|
32
|
+
"senders": Array [
|
|
33
|
+
"0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5",
|
|
34
|
+
],
|
|
35
|
+
"transactionSequenceNumber": 225,
|
|
36
|
+
"type": "OUT",
|
|
37
|
+
"value": "102193757957260253",
|
|
38
|
+
},
|
|
39
|
+
Object {
|
|
40
|
+
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
41
|
+
"blockHash": "0x912d8feccc2c943daa396ec2a20f6149d2bfeef3828fc9f47ee98b3151b5d4f9",
|
|
42
|
+
"blockHeight": 0,
|
|
43
|
+
"date": "",
|
|
44
|
+
"extra": Object {},
|
|
45
|
+
"fee": "1903135989909000",
|
|
46
|
+
"hash": "0xa54eb928a2f7e522517133f22ebdc2b599d130e86f0118658a7884a7df9265cc",
|
|
47
|
+
"id": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:-0xa54eb928a2f7e522517133f22ebdc2b599d130e86f0118658a7884a7df9265cc-IN",
|
|
48
|
+
"internalOperations": Array [],
|
|
49
|
+
"recipients": Array [
|
|
50
|
+
"0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5",
|
|
51
|
+
],
|
|
52
|
+
"senders": Array [
|
|
53
|
+
"0x86D3E894b5CDb6a80affFd35eD348868fb98DD3f",
|
|
54
|
+
],
|
|
55
|
+
"transactionSequenceNumber": 67292,
|
|
56
|
+
"type": "IN",
|
|
57
|
+
"value": "100101099334000000",
|
|
58
|
+
},
|
|
18
59
|
Object {
|
|
19
60
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
20
61
|
"blockHash": "0x2f43388babd05ea277497a0afd03d61324ad4b2b5d1e603470d29951e987e279",
|
|
@@ -157,7 +198,7 @@ Object {
|
|
|
157
198
|
],
|
|
158
199
|
"transactionSequenceNumber": 221,
|
|
159
200
|
"type": "FEES",
|
|
160
|
-
"value": "
|
|
201
|
+
"value": "72825000000000",
|
|
161
202
|
},
|
|
162
203
|
Object {
|
|
163
204
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -797,7 +838,7 @@ Object {
|
|
|
797
838
|
],
|
|
798
839
|
"transactionSequenceNumber": 201,
|
|
799
840
|
"type": "FEES",
|
|
800
|
-
"value": "
|
|
841
|
+
"value": "359040000000000",
|
|
801
842
|
},
|
|
802
843
|
Object {
|
|
803
844
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -1399,7 +1440,7 @@ Object {
|
|
|
1399
1440
|
],
|
|
1400
1441
|
"transactionSequenceNumber": 179,
|
|
1401
1442
|
"type": "FEES",
|
|
1402
|
-
"value": "
|
|
1443
|
+
"value": "79359000000000",
|
|
1403
1444
|
},
|
|
1404
1445
|
Object {
|
|
1405
1446
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -2720,7 +2761,7 @@ Object {
|
|
|
2720
2761
|
],
|
|
2721
2762
|
"transactionSequenceNumber": 138,
|
|
2722
2763
|
"type": "FEES",
|
|
2723
|
-
"value": "
|
|
2764
|
+
"value": "239390000000000",
|
|
2724
2765
|
},
|
|
2725
2766
|
Object {
|
|
2726
2767
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -5741,7 +5782,7 @@ Object {
|
|
|
5741
5782
|
],
|
|
5742
5783
|
"transactionSequenceNumber": 57,
|
|
5743
5784
|
"type": "FEES",
|
|
5744
|
-
"value": "
|
|
5785
|
+
"value": "679610000000000",
|
|
5745
5786
|
},
|
|
5746
5787
|
Object {
|
|
5747
5788
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -6937,7 +6978,7 @@ Object {
|
|
|
6937
6978
|
],
|
|
6938
6979
|
"transactionSequenceNumber": 21,
|
|
6939
6980
|
"type": "FEES",
|
|
6940
|
-
"value": "
|
|
6981
|
+
"value": "758734820000000",
|
|
6941
6982
|
},
|
|
6942
6983
|
Object {
|
|
6943
6984
|
"accountId": "js:2:ethereum:0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5:",
|
|
@@ -7601,10 +7642,10 @@ Object {
|
|
|
7601
7642
|
"value": "331419644025820000",
|
|
7602
7643
|
},
|
|
7603
7644
|
],
|
|
7604
|
-
"operationsCount":
|
|
7645
|
+
"operationsCount": 367,
|
|
7605
7646
|
"pendingOperations": Array [],
|
|
7606
7647
|
"seedIdentifier": "0x0E3F0bb9516F01f2C34c25E0957518b8aC9414c5",
|
|
7607
|
-
"spendableBalance": "
|
|
7648
|
+
"spendableBalance": "0",
|
|
7608
7649
|
"starred": false,
|
|
7609
7650
|
"subAccounts": Array [
|
|
7610
7651
|
Object {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import bitcoin from "../../families/bitcoin/bridge/js";
|
|
2
|
+
|
|
1
3
|
import crypto_org from "../../families/crypto_org/bridge/js";
|
|
2
4
|
|
|
3
5
|
import elrond from "../../families/elrond/bridge/js";
|
|
@@ -18,6 +20,7 @@ import tron from "../../families/tron/bridge/js";
|
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
export default {
|
|
23
|
+
bitcoin,
|
|
21
24
|
crypto_org,
|
|
22
25
|
elrond,
|
|
23
26
|
ethereum,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SerializedAccount as WalletSerializedAccount } from "@ledgerhq/wallet-btc";
|
|
1
2
|
import { fromAccountRaw } from "../account";
|
|
2
3
|
import type { Account, AccountRaw } from "../types";
|
|
3
4
|
|
|
@@ -26,6 +27,7 @@ const accounts: Account[] = [
|
|
|
26
27
|
xpub: "xpub6DACJs4ZgE67HEu53j2osRtw51wfJybJ88ccVQnHpmjqr9XJfMYXn6Fxt3u772FonuWfqYUrb9Z9wxe2S9pTzxGDiQZDk1cMPiDH2S5HjYa",
|
|
27
28
|
bitcoinResources: {
|
|
28
29
|
utxos: [],
|
|
30
|
+
serializedData: {} as WalletSerializedAccount,
|
|
29
31
|
},
|
|
30
32
|
swapHistory: [
|
|
31
33
|
{
|
|
@@ -88,6 +90,7 @@ const accounts: Account[] = [
|
|
|
88
90
|
xpub: "Ltub2Zx1tbqWB7AbC4fb7aWgsuyXBm2qt97gzG5av4PHAjdAhvdZQFHS7nmcScgtAvpgcGAkVQQvR9BXwu54ny6Yqwst4KQAnyD1Yx6VezNf1S8",
|
|
89
91
|
bitcoinResources: {
|
|
90
92
|
utxos: [],
|
|
93
|
+
serializedData: {} as WalletSerializedAccount,
|
|
91
94
|
},
|
|
92
95
|
swapHistory: [
|
|
93
96
|
{
|
|
@@ -16,6 +16,24 @@ function sameSwap(a: SwapOperation, b: SwapOperation) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const implicitMigration = (accounts: Account[]): Account[] => {
|
|
19
|
+
// TODO Need this for BTC-JS?
|
|
20
|
+
/*
|
|
21
|
+
// this infer the next account id following ongoing libcore->js migration
|
|
22
|
+
function targetBitcoinJSaccountId(a: AccountLike) {
|
|
23
|
+
if (a.type === "Account") {
|
|
24
|
+
const decoded = decodeAccountId(a.id);
|
|
25
|
+
if (decoded.type !== "libcore") {
|
|
26
|
+
return a.id;
|
|
27
|
+
}
|
|
28
|
+
if (decoded.currencyId !== "bitcoin") {
|
|
29
|
+
return a.id;
|
|
30
|
+
}
|
|
31
|
+
return `js:2:${decoded.currencyId}:${a.freshAddress}:${decoded.derivationMode}`;
|
|
32
|
+
}
|
|
33
|
+
return a.id;
|
|
34
|
+
}
|
|
35
|
+
*/
|
|
36
|
+
|
|
19
37
|
// this infer the next account id following ongoing libcore->js migration
|
|
20
38
|
function targetEthereumJSaccountId(a: AccountLike) {
|
|
21
39
|
if (a.type === "Account") {
|
package/src/mock/account.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Prando from "prando";
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import type { SerializedAccount as WalletSerializedAccount } from "@ledgerhq/wallet-btc";
|
|
3
4
|
import {
|
|
4
5
|
listCryptoCurrencies,
|
|
5
6
|
listTokensForCryptoCurrency,
|
|
@@ -412,6 +413,7 @@ export function genAccount(
|
|
|
412
413
|
if (currency.family === "bitcoin") {
|
|
413
414
|
account.bitcoinResources = {
|
|
414
415
|
utxos: [],
|
|
416
|
+
serializedData: {} as WalletSerializedAccount,
|
|
415
417
|
};
|
|
416
418
|
}
|
|
417
419
|
|