@ledgerhq/coin-framework 0.9.0 → 0.10.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE.txt +21 -0
- package/lib/account/helpers.d.ts.map +1 -1
- package/lib/account/helpers.js +4 -0
- package/lib/account/helpers.js.map +1 -1
- package/lib/account/serialization.d.ts.map +1 -1
- package/lib/account/serialization.js +28 -0
- package/lib/account/serialization.js.map +1 -1
- package/lib/bot/specs.d.ts.map +1 -1
- package/lib/bot/specs.js +1 -7
- package/lib/bot/specs.js.map +1 -1
- package/lib/derivation.d.ts +3 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +13 -15
- package/lib/derivation.js.map +1 -1
- package/lib/derivation.test.js +83 -24
- package/lib/derivation.test.js.map +1 -1
- package/lib-es/account/helpers.d.ts.map +1 -1
- package/lib-es/account/helpers.js +4 -0
- package/lib-es/account/helpers.js.map +1 -1
- package/lib-es/account/serialization.d.ts.map +1 -1
- package/lib-es/account/serialization.js +28 -0
- package/lib-es/account/serialization.js.map +1 -1
- package/lib-es/bot/specs.d.ts.map +1 -1
- package/lib-es/bot/specs.js +1 -7
- package/lib-es/bot/specs.js.map +1 -1
- package/lib-es/derivation.d.ts +3 -0
- package/lib-es/derivation.d.ts.map +1 -1
- package/lib-es/derivation.js +13 -15
- package/lib-es/derivation.js.map +1 -1
- package/lib-es/derivation.test.js +84 -25
- package/lib-es/derivation.test.js.map +1 -1
- package/package.json +11 -11
- package/src/__snapshots__/account.test.ts.snap +455 -455
- package/src/account/helpers.ts +4 -0
- package/src/account/serialization.ts +29 -0
- package/src/bot/specs.ts +1 -7
- package/src/currencies/__snapshots__/formatCurrencyUnit.test.ts.snap +44 -44
- package/src/derivation.test.ts +103 -25
- package/src/derivation.ts +15 -19
package/src/account/helpers.ts
CHANGED
|
@@ -107,6 +107,10 @@ export const getAccountSpendableBalance = (account: AccountLike): BigNumber => {
|
|
|
107
107
|
|
|
108
108
|
export const isAccountEmpty = (a: AccountLike): boolean => {
|
|
109
109
|
// FIXME LIVE-5966 why do we need this? also this shouldn't be implemented here / this part must be removed back to the coin specifics
|
|
110
|
+
if (a.type == "Account" && a.currency.family == "vechain") {
|
|
111
|
+
const checkSubAccounts = a.subAccounts && !a.subAccounts[0].balance.isZero();
|
|
112
|
+
return a.operationsCount === 0 && a.balance.isZero() && !checkSubAccounts;
|
|
113
|
+
}
|
|
110
114
|
if (a.type === "Account" && a.currency.family === "tron") {
|
|
111
115
|
return (a as any).tronResources && (a as any).tronResources.bandwidth.freeLimit.eq(0);
|
|
112
116
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { log } from "@ledgerhq/logs";
|
|
1
2
|
import { BigNumber } from "bignumber.js";
|
|
2
3
|
import type { Operation, OperationRaw, SubAccount } from "@ledgerhq/types-live";
|
|
3
4
|
|
|
@@ -30,6 +31,34 @@ export const toOperationRaw = (
|
|
|
30
31
|
}: Operation,
|
|
31
32
|
preserveSubOperation?: boolean,
|
|
32
33
|
): OperationRaw => {
|
|
34
|
+
// -- THIS CAN BE REMOVED ONCE THE DATE ERROR HAS BEEN FIGURED OUT
|
|
35
|
+
if (date instanceof Date && !isNaN(date as unknown as number)) {
|
|
36
|
+
log("Ethereum Date Error", "Date is invalid while serializing", {
|
|
37
|
+
date,
|
|
38
|
+
value,
|
|
39
|
+
fee,
|
|
40
|
+
subOperations,
|
|
41
|
+
internalOperations,
|
|
42
|
+
nftOperations,
|
|
43
|
+
id,
|
|
44
|
+
hash,
|
|
45
|
+
type,
|
|
46
|
+
senders,
|
|
47
|
+
recipients,
|
|
48
|
+
blockHeight,
|
|
49
|
+
blockHash,
|
|
50
|
+
transactionSequenceNumber,
|
|
51
|
+
accountId,
|
|
52
|
+
hasFailed,
|
|
53
|
+
contract,
|
|
54
|
+
operator,
|
|
55
|
+
standard,
|
|
56
|
+
tokenId,
|
|
57
|
+
transactionRaw,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// -- THIS CAN BE REMOVED ONCE THE DATE ERROR HAS BEEN FIGURED OUT
|
|
61
|
+
|
|
33
62
|
const copy: OperationRaw = {
|
|
34
63
|
id,
|
|
35
64
|
hash,
|
package/src/bot/specs.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// helpers for spec
|
|
2
|
-
import { DeviceModelId } from "@ledgerhq/devices";
|
|
3
1
|
import { log } from "@ledgerhq/logs";
|
|
4
2
|
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
3
|
import { Account, TransactionCommon } from "@ledgerhq/types-live";
|
|
@@ -84,11 +82,7 @@ export function deviceActionFlow<T extends TransactionCommon>(
|
|
|
84
82
|
expect({
|
|
85
83
|
[stepTitle]: stepValueTransform(stepValue),
|
|
86
84
|
}).toMatchObject({
|
|
87
|
-
|
|
88
|
-
// Issue on speculos repository : https://github.com/LedgerHQ/speculos/issues/204
|
|
89
|
-
[stepTitle]: expectedValue(arg, acc)
|
|
90
|
-
.replace(/S/g, arg.appCandidate.model === DeviceModelId.nanoS ? "S" : "")
|
|
91
|
-
.trim(),
|
|
85
|
+
[stepTitle]: expectedValue(arg, acc).trim(),
|
|
92
86
|
});
|
|
93
87
|
});
|
|
94
88
|
}
|
|
@@ -62,11 +62,11 @@ exports[`formatCurrencyUnit with custom options with locale de-DE should correct
|
|
|
62
62
|
|
|
63
63
|
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Cosmos unit (Atom) 1`] = `"12.345.678.900,000000- -ATOM"`;
|
|
64
64
|
|
|
65
|
-
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Cronos unit (
|
|
65
|
+
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123.456.789,00000000- -tcro"`;
|
|
66
66
|
|
|
67
|
-
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format
|
|
67
|
+
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Cronos POS Chain unit (CRO) 1`] = `"123.456.789,00000000- -CRO"`;
|
|
68
68
|
|
|
69
|
-
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format
|
|
69
|
+
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
70
70
|
|
|
71
71
|
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format DEXON unit (dexon) 1`] = `"12.345.678.900,000000- -DXN"`;
|
|
72
72
|
|
|
@@ -294,7 +294,7 @@ exports[`formatCurrencyUnit with custom options with locale de-DE should correct
|
|
|
294
294
|
|
|
295
295
|
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Umee unit (Umee) 1`] = `"12.345.678.900,000000- -UMEE"`;
|
|
296
296
|
|
|
297
|
-
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format
|
|
297
|
+
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
298
298
|
|
|
299
299
|
exports[`formatCurrencyUnit with custom options with locale de-DE should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
300
300
|
|
|
@@ -384,11 +384,11 @@ exports[`formatCurrencyUnit with custom options with locale en-US should correct
|
|
|
384
384
|
|
|
385
385
|
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Cosmos unit (Atom) 1`] = `"12,345,678,900.000000- -ATOM"`;
|
|
386
386
|
|
|
387
|
-
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Cronos unit (
|
|
387
|
+
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123,456,789.00000000- -tcro"`;
|
|
388
388
|
|
|
389
|
-
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format
|
|
389
|
+
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Cronos POS Chain unit (CRO) 1`] = `"123,456,789.00000000- -CRO"`;
|
|
390
390
|
|
|
391
|
-
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format
|
|
391
|
+
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Cronos unit (CRO) 1`] = `"0.012345678900000000- -CRO"`;
|
|
392
392
|
|
|
393
393
|
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format DEXON unit (dexon) 1`] = `"12,345,678,900.000000- -DXN"`;
|
|
394
394
|
|
|
@@ -616,7 +616,7 @@ exports[`formatCurrencyUnit with custom options with locale en-US should correct
|
|
|
616
616
|
|
|
617
617
|
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Umee unit (Umee) 1`] = `"12,345,678,900.000000- -UMEE"`;
|
|
618
618
|
|
|
619
|
-
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format
|
|
619
|
+
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Vechain unit (VET) 1`] = `"0.012345678900000000- -VET"`;
|
|
620
620
|
|
|
621
621
|
exports[`formatCurrencyUnit with custom options with locale en-US should correctly format Velas EVM unit (VLX) 1`] = `"0.012345678900000000- -VLX"`;
|
|
622
622
|
|
|
@@ -706,11 +706,11 @@ exports[`formatCurrencyUnit with custom options with locale es-ES should correct
|
|
|
706
706
|
|
|
707
707
|
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Cosmos unit (Atom) 1`] = `"12.345.678.900,000000- -ATOM"`;
|
|
708
708
|
|
|
709
|
-
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Cronos unit (
|
|
709
|
+
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123.456.789,00000000- -tcro"`;
|
|
710
710
|
|
|
711
|
-
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format
|
|
711
|
+
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Cronos POS Chain unit (CRO) 1`] = `"123.456.789,00000000- -CRO"`;
|
|
712
712
|
|
|
713
|
-
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format
|
|
713
|
+
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
714
714
|
|
|
715
715
|
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format DEXON unit (dexon) 1`] = `"12.345.678.900,000000- -DXN"`;
|
|
716
716
|
|
|
@@ -938,7 +938,7 @@ exports[`formatCurrencyUnit with custom options with locale es-ES should correct
|
|
|
938
938
|
|
|
939
939
|
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Umee unit (Umee) 1`] = `"12.345.678.900,000000- -UMEE"`;
|
|
940
940
|
|
|
941
|
-
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format
|
|
941
|
+
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
942
942
|
|
|
943
943
|
exports[`formatCurrencyUnit with custom options with locale es-ES should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
944
944
|
|
|
@@ -1028,11 +1028,11 @@ exports[`formatCurrencyUnit with custom options with locale fr-FR should correct
|
|
|
1028
1028
|
|
|
1029
1029
|
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Cosmos unit (Atom) 1`] = `"12 345 678 900,000000- -ATOM"`;
|
|
1030
1030
|
|
|
1031
|
-
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Cronos unit (
|
|
1031
|
+
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123 456 789,00000000- -tcro"`;
|
|
1032
1032
|
|
|
1033
|
-
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format
|
|
1033
|
+
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Cronos POS Chain unit (CRO) 1`] = `"123 456 789,00000000- -CRO"`;
|
|
1034
1034
|
|
|
1035
|
-
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format
|
|
1035
|
+
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
1036
1036
|
|
|
1037
1037
|
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format DEXON unit (dexon) 1`] = `"12 345 678 900,000000- -DXN"`;
|
|
1038
1038
|
|
|
@@ -1260,7 +1260,7 @@ exports[`formatCurrencyUnit with custom options with locale fr-FR should correct
|
|
|
1260
1260
|
|
|
1261
1261
|
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Umee unit (Umee) 1`] = `"12 345 678 900,000000- -UMEE"`;
|
|
1262
1262
|
|
|
1263
|
-
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format
|
|
1263
|
+
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
1264
1264
|
|
|
1265
1265
|
exports[`formatCurrencyUnit with custom options with locale fr-FR should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
1266
1266
|
|
|
@@ -1350,11 +1350,11 @@ exports[`formatCurrencyUnit with custom options with locale ja-JP should correct
|
|
|
1350
1350
|
|
|
1351
1351
|
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Cosmos unit (Atom) 1`] = `"12,345,678,900.000000- -ATOM"`;
|
|
1352
1352
|
|
|
1353
|
-
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Cronos unit (
|
|
1353
|
+
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123,456,789.00000000- -tcro"`;
|
|
1354
1354
|
|
|
1355
|
-
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format
|
|
1355
|
+
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Cronos POS Chain unit (CRO) 1`] = `"123,456,789.00000000- -CRO"`;
|
|
1356
1356
|
|
|
1357
|
-
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format
|
|
1357
|
+
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Cronos unit (CRO) 1`] = `"0.012345678900000000- -CRO"`;
|
|
1358
1358
|
|
|
1359
1359
|
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format DEXON unit (dexon) 1`] = `"12,345,678,900.000000- -DXN"`;
|
|
1360
1360
|
|
|
@@ -1582,7 +1582,7 @@ exports[`formatCurrencyUnit with custom options with locale ja-JP should correct
|
|
|
1582
1582
|
|
|
1583
1583
|
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Umee unit (Umee) 1`] = `"12,345,678,900.000000- -UMEE"`;
|
|
1584
1584
|
|
|
1585
|
-
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format
|
|
1585
|
+
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Vechain unit (VET) 1`] = `"0.012345678900000000- -VET"`;
|
|
1586
1586
|
|
|
1587
1587
|
exports[`formatCurrencyUnit with custom options with locale ja-JP should correctly format Velas EVM unit (VLX) 1`] = `"0.012345678900000000- -VLX"`;
|
|
1588
1588
|
|
|
@@ -1672,11 +1672,11 @@ exports[`formatCurrencyUnit with custom options with locale ko-KR should correct
|
|
|
1672
1672
|
|
|
1673
1673
|
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Cosmos unit (Atom) 1`] = `"12,345,678,900.000000- -ATOM"`;
|
|
1674
1674
|
|
|
1675
|
-
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Cronos unit (
|
|
1675
|
+
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123,456,789.00000000- -tcro"`;
|
|
1676
1676
|
|
|
1677
|
-
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format
|
|
1677
|
+
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Cronos POS Chain unit (CRO) 1`] = `"123,456,789.00000000- -CRO"`;
|
|
1678
1678
|
|
|
1679
|
-
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format
|
|
1679
|
+
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Cronos unit (CRO) 1`] = `"0.012345678900000000- -CRO"`;
|
|
1680
1680
|
|
|
1681
1681
|
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format DEXON unit (dexon) 1`] = `"12,345,678,900.000000- -DXN"`;
|
|
1682
1682
|
|
|
@@ -1904,7 +1904,7 @@ exports[`formatCurrencyUnit with custom options with locale ko-KR should correct
|
|
|
1904
1904
|
|
|
1905
1905
|
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Umee unit (Umee) 1`] = `"12,345,678,900.000000- -UMEE"`;
|
|
1906
1906
|
|
|
1907
|
-
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format
|
|
1907
|
+
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Vechain unit (VET) 1`] = `"0.012345678900000000- -VET"`;
|
|
1908
1908
|
|
|
1909
1909
|
exports[`formatCurrencyUnit with custom options with locale ko-KR should correctly format Velas EVM unit (VLX) 1`] = `"0.012345678900000000- -VLX"`;
|
|
1910
1910
|
|
|
@@ -1994,11 +1994,11 @@ exports[`formatCurrencyUnit with custom options with locale pt-BR should correct
|
|
|
1994
1994
|
|
|
1995
1995
|
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Cosmos unit (Atom) 1`] = `"12.345.678.900,000000- -ATOM"`;
|
|
1996
1996
|
|
|
1997
|
-
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Cronos unit (
|
|
1997
|
+
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123.456.789,00000000- -tcro"`;
|
|
1998
1998
|
|
|
1999
|
-
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format
|
|
1999
|
+
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Cronos POS Chain unit (CRO) 1`] = `"123.456.789,00000000- -CRO"`;
|
|
2000
2000
|
|
|
2001
|
-
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format
|
|
2001
|
+
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
2002
2002
|
|
|
2003
2003
|
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format DEXON unit (dexon) 1`] = `"12.345.678.900,000000- -DXN"`;
|
|
2004
2004
|
|
|
@@ -2226,7 +2226,7 @@ exports[`formatCurrencyUnit with custom options with locale pt-BR should correct
|
|
|
2226
2226
|
|
|
2227
2227
|
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Umee unit (Umee) 1`] = `"12.345.678.900,000000- -UMEE"`;
|
|
2228
2228
|
|
|
2229
|
-
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format
|
|
2229
|
+
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
2230
2230
|
|
|
2231
2231
|
exports[`formatCurrencyUnit with custom options with locale pt-BR should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
2232
2232
|
|
|
@@ -2316,11 +2316,11 @@ exports[`formatCurrencyUnit with custom options with locale ru-RU should correct
|
|
|
2316
2316
|
|
|
2317
2317
|
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Cosmos unit (Atom) 1`] = `"12 345 678 900,000000- -ATOM"`;
|
|
2318
2318
|
|
|
2319
|
-
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Cronos unit (
|
|
2319
|
+
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123 456 789,00000000- -tcro"`;
|
|
2320
2320
|
|
|
2321
|
-
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format
|
|
2321
|
+
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Cronos POS Chain unit (CRO) 1`] = `"123 456 789,00000000- -CRO"`;
|
|
2322
2322
|
|
|
2323
|
-
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format
|
|
2323
|
+
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
2324
2324
|
|
|
2325
2325
|
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format DEXON unit (dexon) 1`] = `"12 345 678 900,000000- -DXN"`;
|
|
2326
2326
|
|
|
@@ -2548,7 +2548,7 @@ exports[`formatCurrencyUnit with custom options with locale ru-RU should correct
|
|
|
2548
2548
|
|
|
2549
2549
|
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Umee unit (Umee) 1`] = `"12 345 678 900,000000- -UMEE"`;
|
|
2550
2550
|
|
|
2551
|
-
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format
|
|
2551
|
+
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
2552
2552
|
|
|
2553
2553
|
exports[`formatCurrencyUnit with custom options with locale ru-RU should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
2554
2554
|
|
|
@@ -2638,11 +2638,11 @@ exports[`formatCurrencyUnit with custom options with locale tr-TR should correct
|
|
|
2638
2638
|
|
|
2639
2639
|
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Cosmos unit (Atom) 1`] = `"12.345.678.900,000000- -ATOM"`;
|
|
2640
2640
|
|
|
2641
|
-
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Cronos unit (
|
|
2641
|
+
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123.456.789,00000000- -tcro"`;
|
|
2642
2642
|
|
|
2643
|
-
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format
|
|
2643
|
+
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Cronos POS Chain unit (CRO) 1`] = `"123.456.789,00000000- -CRO"`;
|
|
2644
2644
|
|
|
2645
|
-
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format
|
|
2645
|
+
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Cronos unit (CRO) 1`] = `"0,012345678900000000- -CRO"`;
|
|
2646
2646
|
|
|
2647
2647
|
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format DEXON unit (dexon) 1`] = `"12.345.678.900,000000- -DXN"`;
|
|
2648
2648
|
|
|
@@ -2870,7 +2870,7 @@ exports[`formatCurrencyUnit with custom options with locale tr-TR should correct
|
|
|
2870
2870
|
|
|
2871
2871
|
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Umee unit (Umee) 1`] = `"12.345.678.900,000000- -UMEE"`;
|
|
2872
2872
|
|
|
2873
|
-
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format
|
|
2873
|
+
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Vechain unit (VET) 1`] = `"0,012345678900000000- -VET"`;
|
|
2874
2874
|
|
|
2875
2875
|
exports[`formatCurrencyUnit with custom options with locale tr-TR should correctly format Velas EVM unit (VLX) 1`] = `"0,012345678900000000- -VLX"`;
|
|
2876
2876
|
|
|
@@ -2960,11 +2960,11 @@ exports[`formatCurrencyUnit with custom options with locale zh-CN should correct
|
|
|
2960
2960
|
|
|
2961
2961
|
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Cosmos unit (Atom) 1`] = `"12,345,678,900.000000- -ATOM"`;
|
|
2962
2962
|
|
|
2963
|
-
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Cronos unit (
|
|
2963
|
+
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123,456,789.00000000- -tcro"`;
|
|
2964
2964
|
|
|
2965
|
-
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format
|
|
2965
|
+
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Cronos POS Chain unit (CRO) 1`] = `"123,456,789.00000000- -CRO"`;
|
|
2966
2966
|
|
|
2967
|
-
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format
|
|
2967
|
+
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Cronos unit (CRO) 1`] = `"0.012345678900000000- -CRO"`;
|
|
2968
2968
|
|
|
2969
2969
|
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format DEXON unit (dexon) 1`] = `"12,345,678,900.000000- -DXN"`;
|
|
2970
2970
|
|
|
@@ -3192,7 +3192,7 @@ exports[`formatCurrencyUnit with custom options with locale zh-CN should correct
|
|
|
3192
3192
|
|
|
3193
3193
|
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Umee unit (Umee) 1`] = `"12,345,678,900.000000- -UMEE"`;
|
|
3194
3194
|
|
|
3195
|
-
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format
|
|
3195
|
+
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Vechain unit (VET) 1`] = `"0.012345678900000000- -VET"`;
|
|
3196
3196
|
|
|
3197
3197
|
exports[`formatCurrencyUnit with custom options with locale zh-CN should correctly format Velas EVM unit (VLX) 1`] = `"0.012345678900000000- -VLX"`;
|
|
3198
3198
|
|
|
@@ -3282,11 +3282,11 @@ exports[`formatCurrencyUnit with default options should correctly format Cosmos
|
|
|
3282
3282
|
|
|
3283
3283
|
exports[`formatCurrencyUnit with default options should correctly format Cosmos unit (Atom) 1`] = `"12,345,678,900"`;
|
|
3284
3284
|
|
|
3285
|
-
exports[`formatCurrencyUnit with default options should correctly format Cronos unit (
|
|
3285
|
+
exports[`formatCurrencyUnit with default options should correctly format Cronos POS Chain Croeseid unit (TCRO) 1`] = `"123,456,789"`;
|
|
3286
3286
|
|
|
3287
|
-
exports[`formatCurrencyUnit with default options should correctly format
|
|
3287
|
+
exports[`formatCurrencyUnit with default options should correctly format Cronos POS Chain unit (CRO) 1`] = `"123,456,789"`;
|
|
3288
3288
|
|
|
3289
|
-
exports[`formatCurrencyUnit with default options should correctly format
|
|
3289
|
+
exports[`formatCurrencyUnit with default options should correctly format Cronos unit (CRO) 1`] = `"0.0123456"`;
|
|
3290
3290
|
|
|
3291
3291
|
exports[`formatCurrencyUnit with default options should correctly format DEXON unit (dexon) 1`] = `"12,345,678,900"`;
|
|
3292
3292
|
|
|
@@ -3514,7 +3514,7 @@ exports[`formatCurrencyUnit with default options should correctly format Ubiq un
|
|
|
3514
3514
|
|
|
3515
3515
|
exports[`formatCurrencyUnit with default options should correctly format Umee unit (Umee) 1`] = `"12,345,678,900"`;
|
|
3516
3516
|
|
|
3517
|
-
exports[`formatCurrencyUnit with default options should correctly format
|
|
3517
|
+
exports[`formatCurrencyUnit with default options should correctly format Vechain unit (VET) 1`] = `"0.0123456"`;
|
|
3518
3518
|
|
|
3519
3519
|
exports[`formatCurrencyUnit with default options should correctly format Velas EVM unit (VLX) 1`] = `"0.0123456"`;
|
|
3520
3520
|
|
package/src/derivation.test.ts
CHANGED
|
@@ -1,32 +1,110 @@
|
|
|
1
|
+
import { getEnv, setEnv } from "@ledgerhq/live-env";
|
|
1
2
|
import { getCryptoCurrencyById } from "./currencies";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
import {
|
|
4
|
+
getPreferredNewAccountScheme,
|
|
5
|
+
getDefaultPreferredNewAccountScheme,
|
|
6
|
+
getDerivationModesForCurrency,
|
|
7
|
+
isInvalidDerivationMode,
|
|
8
|
+
DerivationMode,
|
|
9
|
+
} from "./derivation";
|
|
10
|
+
|
|
11
|
+
describe("derivation.ts", () => {
|
|
12
|
+
describe("getPreferredNewAccountScheme", () => {
|
|
13
|
+
it("should return a list of schemes for a given currency", () => {
|
|
14
|
+
const testData: [string, string[] | null][] = [
|
|
15
|
+
["bitcoin", ["native_segwit", "taproot", "segwit", ""]],
|
|
16
|
+
["ethereum", null],
|
|
17
|
+
["cosmos", null],
|
|
18
|
+
["litecoin", ["native_segwit", "segwit", ""]],
|
|
19
|
+
["qtum", ["segwit", ""]],
|
|
20
|
+
];
|
|
21
|
+
testData.forEach(([currencyId, derivationModes]) => {
|
|
22
|
+
if (!currencyId) return;
|
|
23
|
+
const currency = getCryptoCurrencyById(currencyId);
|
|
24
|
+
const p = getPreferredNewAccountScheme(currency);
|
|
25
|
+
expect(p).toEqual(derivationModes);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("getDefaultPreferredNewAccountScheme", () => {
|
|
31
|
+
it("should return a default scheme for a given currency", () => {
|
|
32
|
+
const testData = [
|
|
33
|
+
["bitcoin", "native_segwit"],
|
|
34
|
+
["ethereum", null],
|
|
35
|
+
["cosmos", null],
|
|
36
|
+
["litecoin", "native_segwit"],
|
|
37
|
+
["qtum", "segwit"],
|
|
38
|
+
];
|
|
39
|
+
testData.forEach(([currencyId, derivationMode]) => {
|
|
40
|
+
if (!currencyId) return;
|
|
41
|
+
const currency = getCryptoCurrencyById(currencyId);
|
|
42
|
+
const defaultP = getDefaultPreferredNewAccountScheme(currency);
|
|
43
|
+
expect(defaultP).toEqual(derivationMode);
|
|
44
|
+
});
|
|
16
45
|
});
|
|
17
46
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
["ethereum",
|
|
22
|
-
["
|
|
23
|
-
["
|
|
24
|
-
[
|
|
47
|
+
|
|
48
|
+
describe("getDerivationModesForCurrency", () => {
|
|
49
|
+
const expectations: [string, DerivationMode[]][] = [
|
|
50
|
+
["ethereum", ["ethM", "ethMM", ""]], // test for fixing missing legacy derivation
|
|
51
|
+
["ethereum_classic", ["ethM", "ethMM", "etcM", ""]], // test for fixing missing legacy derivation
|
|
52
|
+
["polygon", [""]], // test absence of impact on other EVMs
|
|
53
|
+
[
|
|
54
|
+
"bitcoin",
|
|
55
|
+
[
|
|
56
|
+
"legacy_on_bch",
|
|
57
|
+
"segwit_on_legacy",
|
|
58
|
+
"legacy_on_segwit",
|
|
59
|
+
"legacy_on_native_segwit",
|
|
60
|
+
"native_segwit",
|
|
61
|
+
"taproot",
|
|
62
|
+
"segwit",
|
|
63
|
+
"",
|
|
64
|
+
],
|
|
65
|
+
], // supportsSegwit + supportsNativeSegwit + taproot + segwit
|
|
66
|
+
["bitcoin_cash", ["unsplit", ""]], // forkedFrom
|
|
67
|
+
[
|
|
68
|
+
"bitcoin_gold",
|
|
69
|
+
[
|
|
70
|
+
"unsplit",
|
|
71
|
+
"segwit_unsplit",
|
|
72
|
+
"segwit_on_legacy",
|
|
73
|
+
"legacy_on_segwit",
|
|
74
|
+
"legacy_on_native_segwit",
|
|
75
|
+
"segwit",
|
|
76
|
+
"",
|
|
77
|
+
],
|
|
78
|
+
], // forkedFrom + supportsSegwit
|
|
79
|
+
["tezos", ["galleonL", "tezboxL", "tezosbip44h", "tezbox"]], // disableBIP44
|
|
80
|
+
["solana", ["solanaMain", "solanaSub"]], // backward compatible change in getDerivationModesForCurrency
|
|
25
81
|
];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
82
|
+
|
|
83
|
+
let envBackup: boolean;
|
|
84
|
+
beforeAll(() => {
|
|
85
|
+
envBackup = getEnv("SCAN_FOR_INVALID_PATHS");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
setEnv("SCAN_FOR_INVALID_PATHS", envBackup);
|
|
30
90
|
});
|
|
91
|
+
|
|
92
|
+
it.each(expectations)(
|
|
93
|
+
"should return the expected derivation paths for %s with SCAN_FOR_INVALID_PATHS false",
|
|
94
|
+
(currency, paths) => {
|
|
95
|
+
setEnv("SCAN_FOR_INVALID_PATHS", false);
|
|
96
|
+
expect(getDerivationModesForCurrency(getCryptoCurrencyById(currency))).toEqual(
|
|
97
|
+
paths.filter(path => !isInvalidDerivationMode(path)),
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
it.each(expectations)(
|
|
103
|
+
"should return the expected derivation paths for %s with SCAN_FOR_INVALID_PATHS true",
|
|
104
|
+
(currency, paths) => {
|
|
105
|
+
setEnv("SCAN_FOR_INVALID_PATHS", true);
|
|
106
|
+
expect(getDerivationModesForCurrency(getCryptoCurrencyById(currency))).toEqual(paths);
|
|
107
|
+
},
|
|
108
|
+
);
|
|
31
109
|
});
|
|
32
110
|
});
|
package/src/derivation.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { TransportStatusError, UserRefusedAddress } from "@ledgerhq/errors";
|
|
|
6
6
|
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
7
7
|
import { getCryptoCurrencyById } from "./currencies";
|
|
8
8
|
import { getEnv } from "@ledgerhq/live-env";
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
export type ModeSpec = {
|
|
11
11
|
mandatoryEmptyAccountSkip?: number;
|
|
12
12
|
isNonIterable?: boolean;
|
|
@@ -198,6 +198,9 @@ const modes = Object.freeze({
|
|
|
198
198
|
overridesDerivation: "44'/397'/0'/0'/<account>'",
|
|
199
199
|
mandatoryEmptyAccountSkip: 1,
|
|
200
200
|
},
|
|
201
|
+
vechain: {
|
|
202
|
+
overridesDerivation: "44'/818'/0'/0/<account>",
|
|
203
|
+
},
|
|
201
204
|
internet_computer: {
|
|
202
205
|
overridesDerivation: "44'/223'/0'/0/<account>",
|
|
203
206
|
},
|
|
@@ -209,14 +212,11 @@ const modes = Object.freeze({
|
|
|
209
212
|
});
|
|
210
213
|
modes as Record<DerivationMode, ModeSpec>; // eslint-disable-line
|
|
211
214
|
|
|
212
|
-
|
|
213
|
-
// previous types: Partial<CryptoCurrencyConfig<DerivationMode[]>>
|
|
214
|
-
const legacyDerivations: Record<CryptoCurrencyIds, DerivationMode[]> = {
|
|
215
|
+
const legacyDerivations: Partial<Record<CryptoCurrency["id"], DerivationMode[]>> = {
|
|
215
216
|
aeternity: ["aeternity"],
|
|
216
217
|
bitcoin_cash: [],
|
|
217
218
|
bitcoin: ["legacy_on_bch"],
|
|
218
219
|
vertcoin: ["vertcoin_128", "vertcoin_128_segwit"],
|
|
219
|
-
ethereum_classic: ["etcM"],
|
|
220
220
|
tezos: ["galleonL", "tezboxL", "tezosbip44h", "tezbox"],
|
|
221
221
|
stellar: ["sep5"],
|
|
222
222
|
polkadot: ["polkadotbip44"],
|
|
@@ -227,11 +227,13 @@ const legacyDerivations: Record<CryptoCurrencyIds, DerivationMode[]> = {
|
|
|
227
227
|
cardano: ["cardano"],
|
|
228
228
|
cardano_testnet: ["cardano"],
|
|
229
229
|
near: ["nearbip44h"],
|
|
230
|
+
vechain: ["vechain"],
|
|
230
231
|
stacks: ["stacks_wallet"],
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
const legacyDerivationsPerFamily: Record<string, DerivationMode[]> = {
|
|
234
232
|
ethereum: ["ethM", "ethMM"],
|
|
233
|
+
ethereum_classic: ["ethM", "ethMM", "etcM"],
|
|
234
|
+
solana: ["solanaMain", "solanaSub"],
|
|
235
|
+
solana_devnet: ["solanaMain", "solanaSub"],
|
|
236
|
+
solana_testnet: ["solanaMain", "solanaSub"],
|
|
235
237
|
};
|
|
236
238
|
|
|
237
239
|
export const asDerivationMode = (derivationMode: string): DerivationMode => {
|
|
@@ -364,6 +366,7 @@ const disableBIP44: Record<string, boolean> = {
|
|
|
364
366
|
cardano: true,
|
|
365
367
|
cardano_testnet: true,
|
|
366
368
|
near: true,
|
|
369
|
+
vechain: true,
|
|
367
370
|
internet_computer: true,
|
|
368
371
|
casper: true,
|
|
369
372
|
};
|
|
@@ -383,6 +386,7 @@ const seedIdentifierPath: Record<string, SeedPathFn> = {
|
|
|
383
386
|
cardano_testnet: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
|
|
384
387
|
internet_computer: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
|
|
385
388
|
near: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0'/0'`,
|
|
389
|
+
vechain: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'/0/0`,
|
|
386
390
|
_: ({ purpose, coinType }) => `${purpose}'/${coinType}'/0'`,
|
|
387
391
|
};
|
|
388
392
|
export const getSeedIdentifierDerivation = (
|
|
@@ -401,11 +405,8 @@ export const getSeedIdentifierDerivation = (
|
|
|
401
405
|
// return an array of ways to derivate, by convention the latest is the standard one.
|
|
402
406
|
export const getDerivationModesForCurrency = (currency: CryptoCurrency): DerivationMode[] => {
|
|
403
407
|
let all: DerivationMode[] = [];
|
|
404
|
-
if (currency.family in legacyDerivationsPerFamily) {
|
|
405
|
-
all = all.concat(legacyDerivationsPerFamily[currency.family]);
|
|
406
|
-
}
|
|
407
408
|
if (currency.id in legacyDerivations) {
|
|
408
|
-
all = all.concat(legacyDerivations[currency.id]);
|
|
409
|
+
all = all.concat(legacyDerivations[currency.id] || []);
|
|
409
410
|
}
|
|
410
411
|
if (currency.forkedFrom) {
|
|
411
412
|
all.push("unsplit");
|
|
@@ -416,9 +417,7 @@ export const getDerivationModesForCurrency = (currency: CryptoCurrency): Derivat
|
|
|
416
417
|
}
|
|
417
418
|
|
|
418
419
|
if (currency.supportsSegwit) {
|
|
419
|
-
all.push("segwit_on_legacy");
|
|
420
|
-
all.push("legacy_on_segwit");
|
|
421
|
-
all.push("legacy_on_native_segwit");
|
|
420
|
+
all.push("segwit_on_legacy", "legacy_on_segwit", "legacy_on_native_segwit");
|
|
422
421
|
}
|
|
423
422
|
|
|
424
423
|
if (currency.supportsNativeSegwit) {
|
|
@@ -432,6 +431,7 @@ export const getDerivationModesForCurrency = (currency: CryptoCurrency): Derivat
|
|
|
432
431
|
}
|
|
433
432
|
}
|
|
434
433
|
|
|
434
|
+
// Can't this be concatenated with the first `supportsSegwit` condition ?
|
|
435
435
|
if (currency.supportsSegwit) {
|
|
436
436
|
all.push("segwit");
|
|
437
437
|
}
|
|
@@ -440,10 +440,6 @@ export const getDerivationModesForCurrency = (currency: CryptoCurrency): Derivat
|
|
|
440
440
|
all.push("");
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
if (currency.family === "solana") {
|
|
444
|
-
all.push("solanaMain", "solanaSub");
|
|
445
|
-
}
|
|
446
|
-
|
|
447
443
|
if (!getEnv("SCAN_FOR_INVALID_PATHS")) {
|
|
448
444
|
return all.filter(a => !isInvalidDerivationMode(a));
|
|
449
445
|
}
|