@ledgerhq/live-common 22.0.3 → 22.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.d.ts +2 -0
  2. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.d.ts.map +1 -0
  3. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.js +147 -0
  4. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.js.map +1 -0
  5. package/lib/api/Ripple.d.ts +17 -21
  6. package/lib/api/Ripple.d.ts.map +1 -1
  7. package/lib/api/Ripple.js +117 -176
  8. package/lib/api/Ripple.js.map +1 -1
  9. package/lib/api/index.d.ts.map +1 -1
  10. package/lib/api/index.js +1 -5
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/env.d.ts +6 -6
  13. package/lib/env.d.ts.map +1 -1
  14. package/lib/env.js +3 -3
  15. package/lib/env.js.map +1 -1
  16. package/lib/env.react.d.ts +1 -1
  17. package/lib/env.react.d.ts.map +1 -1
  18. package/lib/errors.d.ts +3 -0
  19. package/lib/errors.d.ts.map +1 -1
  20. package/lib/errors.js +2 -1
  21. package/lib/errors.js.map +1 -1
  22. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -1
  23. package/lib/families/bitcoin/getAccountNetworkInfo.js +4 -2
  24. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -1
  25. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  26. package/lib/families/bitcoin/specs.js +5 -2
  27. package/lib/families/bitcoin/specs.js.map +1 -1
  28. package/lib/families/bitcoin/wallet-btc/utils.d.ts +2 -0
  29. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  30. package/lib/families/bitcoin/wallet-btc/utils.js +9 -1
  31. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  32. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  33. package/lib/families/bitcoin/wallet-btc/wallet.js +11 -11
  34. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  35. package/lib/families/cosmos/js-prepareTransaction.d.ts.map +1 -1
  36. package/lib/families/cosmos/js-prepareTransaction.js +29 -5
  37. package/lib/families/cosmos/js-prepareTransaction.js.map +1 -1
  38. package/lib/families/cosmos/js-signOperation.d.ts.map +1 -1
  39. package/lib/families/cosmos/js-signOperation.js +76 -39
  40. package/lib/families/cosmos/js-signOperation.js.map +1 -1
  41. package/lib/families/cosmos/validators.js +1 -1
  42. package/lib/families/ripple/bridge/js.d.ts +2 -1
  43. package/lib/families/ripple/bridge/js.d.ts.map +1 -1
  44. package/lib/families/ripple/bridge/js.js +96 -466
  45. package/lib/families/ripple/bridge/js.js.map +1 -1
  46. package/lib/families/ripple/bridge.test.js +0 -48
  47. package/lib/families/ripple/bridge.test.js.map +1 -1
  48. package/lib/families/ripple/js-synchronization.d.ts +10 -0
  49. package/lib/families/ripple/js-synchronization.d.ts.map +1 -0
  50. package/lib/families/ripple/js-synchronization.js +156 -0
  51. package/lib/families/ripple/js-synchronization.js.map +1 -0
  52. package/lib/families/ripple/test-dataset.d.ts.map +1 -1
  53. package/lib/families/ripple/test-dataset.js +1 -1
  54. package/lib/families/ripple/test-dataset.js.map +1 -1
  55. package/lib/families/ripple/types.api.d.ts +24 -0
  56. package/lib/families/ripple/types.api.d.ts.map +1 -0
  57. package/lib/families/ripple/types.api.js +3 -0
  58. package/lib/families/ripple/types.api.js.map +1 -0
  59. package/lib/families/solana/api/chain/instruction/token/types.d.ts +3 -3
  60. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  61. package/lib/featureFlags/defaultFeatures.js +46 -0
  62. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  63. package/lib/featureFlags/types.d.ts +2 -1
  64. package/lib/featureFlags/types.d.ts.map +1 -1
  65. package/lib/platform/providers/GlobalCatalogProvider/api/mock.json +0 -26
  66. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -63
  67. package/lib/types/nft.d.ts +1 -1
  68. package/lib/types/nft.d.ts.map +1 -1
  69. package/package.json +7 -7
  70. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.ts +96 -0
  71. package/src/api/Ripple.ts +95 -160
  72. package/src/api/index.ts +0 -2
  73. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +47 -3
  74. package/src/env.ts +3 -3
  75. package/src/errors.ts +4 -0
  76. package/src/families/bitcoin/getAccountNetworkInfo.ts +4 -2
  77. package/src/families/bitcoin/specs.ts +4 -5
  78. package/src/families/bitcoin/wallet-btc/utils.ts +8 -0
  79. package/src/families/bitcoin/wallet-btc/wallet.ts +24 -12
  80. package/src/families/cosmos/__snapshots__/bridge.test.ts.snap +128 -7
  81. package/src/families/cosmos/js-prepareTransaction.ts +7 -5
  82. package/src/families/cosmos/js-signOperation.ts +54 -36
  83. package/src/families/cosmos/validators.ts +1 -1
  84. package/src/families/ripple/bridge/js.ts +89 -494
  85. package/src/families/ripple/bridge.test.ts +0 -6
  86. package/src/families/ripple/js-synchronization.ts +153 -0
  87. package/src/families/ripple/test-dataset.ts +2 -0
  88. package/src/families/ripple/types.api.ts +23 -0
  89. package/src/featureFlags/defaultFeatures.ts +47 -0
  90. package/src/featureFlags/types.ts +7 -1
  91. package/src/platform/providers/GlobalCatalogProvider/api/mock.json +0 -26
  92. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -63
  93. package/src/types/nft.ts +1 -1
  94. package/src/.DS_Store +0 -0
  95. package/src/__tests__/.DS_Store +0 -0
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "type": "git",
9
9
  "url": "https://github.com/LedgerHQ/ledger-live-common"
10
10
  },
11
- "version": "22.0.3",
11
+ "version": "22.1.0",
12
12
  "main": "lib/index.js",
13
13
  "types": "lib/index.d.ts",
14
14
  "license": "Apache-2.0",
@@ -44,21 +44,21 @@
44
44
  "@celo/contractkit": "^1.5.2",
45
45
  "@celo/wallet-base": "^1.5.2",
46
46
  "@celo/wallet-ledger": "^1.5.2",
47
+ "@cosmjs/amino": "^0.28.4",
47
48
  "@cosmjs/crypto": "^0.26.5",
48
- "@cosmjs/ledger-amino": "^0.26.5",
49
49
  "@cosmjs/proto-signing": "^0.26.5",
50
50
  "@cosmjs/stargate": "^0.26.5",
51
51
  "@crypto-com/chain-jslib": "0.0.19",
52
52
  "@ethereumjs/common": "^2.6.2",
53
53
  "@ethereumjs/tx": "^3.5.0",
54
54
  "@ledgerhq/compressjs": "1.3.2",
55
- "@ledgerhq/cryptoassets": "6.28.1",
55
+ "@ledgerhq/cryptoassets": "6.28.2",
56
56
  "@ledgerhq/devices": "6.27.1",
57
57
  "@ledgerhq/errors": "6.10.0",
58
58
  "@ledgerhq/hw-app-algorand": "6.27.1",
59
59
  "@ledgerhq/hw-app-btc": "6.27.1",
60
60
  "@ledgerhq/hw-app-cosmos": "6.27.1",
61
- "@ledgerhq/hw-app-eth": "6.28.1",
61
+ "@ledgerhq/hw-app-eth": "6.28.2",
62
62
  "@ledgerhq/hw-app-polkadot": "6.27.1",
63
63
  "@ledgerhq/hw-app-solana": "^6.27.1",
64
64
  "@ledgerhq/hw-app-str": "6.27.1",
@@ -71,8 +71,8 @@
71
71
  "@ledgerhq/json-bignumber": "^1.1.0",
72
72
  "@ledgerhq/live-app-sdk": "^0.6.1",
73
73
  "@ledgerhq/logs": "6.10.0",
74
- "@polkadot/types": "7.8.1",
75
- "@polkadot/types-known": "7.8.1",
74
+ "@polkadot/types": "8.1.1",
75
+ "@polkadot/types-known": "8.1.1",
76
76
  "@solana/spl-token": "^0.1.8",
77
77
  "@solana/web3.js": "^1.32.0",
78
78
  "@taquito/ledger-signer": "stablelib",
@@ -123,7 +123,6 @@
123
123
  "ripemd160": "^2.0.2",
124
124
  "ripple-binary-codec": "^1.3.0",
125
125
  "ripple-bs58check": "^2.0.2",
126
- "ripple-lib": "1.10.0",
127
126
  "rlp": "^3.0.0",
128
127
  "rxjs": "6",
129
128
  "rxjs-compat": "^6.6.7",
@@ -133,6 +132,7 @@
133
132
  "stellar-sdk": "^10.0.1",
134
133
  "superstruct": "^0.14.2",
135
134
  "triple-beam": "^1.3.0",
135
+ "varuint-bitcoin": "1.1.2",
136
136
  "winston": "^3.4.0",
137
137
  "xstate": "^4.28.1"
138
138
  },
@@ -0,0 +1,96 @@
1
+ import coininfo from "coininfo";
2
+ import BigNumber from "bignumber.js";
3
+ import { DerivationModes } from "../../../../families/bitcoin/wallet-btc/types";
4
+ import Xpub from "../../../../families/bitcoin/wallet-btc/xpub";
5
+ import Doge from "../../../../families/bitcoin/wallet-btc/crypto/doge";
6
+ import BitcoinLikeExplorer from "../../../../families/bitcoin/wallet-btc/explorer";
7
+ import BitcoinLikeStorage from "../../../../families/bitcoin/wallet-btc/storage";
8
+ import { Merge } from "../../../../families/bitcoin/wallet-btc/pickingstrategies/Merge";
9
+ import BitcoinLikeWallet from "../../../../families/bitcoin/wallet-btc/wallet";
10
+ import MockBtc from "../../../../mock/Btc";
11
+
12
+ describe("testing dogecoin transactions", () => {
13
+ const wallet = new BitcoinLikeWallet();
14
+ const explorer = new BitcoinLikeExplorer({
15
+ explorerURI: "https://explorers.api.vault.ledger.com/blockchain/v3/doge",
16
+ explorerVersion: "v3",
17
+ disableBatchSize: true,
18
+ });
19
+
20
+ const network = coininfo.dogecoin.main.toBitcoinJS();
21
+ const crypto = new Doge({ network });
22
+
23
+ const storage = new BitcoinLikeStorage();
24
+ const xpub = new Xpub({
25
+ storage,
26
+ explorer,
27
+ crypto,
28
+ xpub: "dgub8rBf7BYsf5YoMezYuPaEhc2tsr7sQA2v2xNCj4mt1czF1m4hRiBdjYeAq5xDVQhN5HqYQnxv2DwyfmDvp1QEfmi44b8uynPL45KXQJrsoi8",
29
+ derivationMode: DerivationModes.LEGACY,
30
+ });
31
+ it("testing dogecoin transactions with huge amount", async () => {
32
+ const utxoPickingStrategy = new Merge(xpub.crypto, xpub.derivationMode, []);
33
+ const changeAddress = await xpub.getNewAddress(1, 0);
34
+ xpub.storage.appendTxs([
35
+ {
36
+ id: "c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
37
+ inputs: [],
38
+ outputs: [
39
+ {
40
+ output_index: 0,
41
+ value: "500000000000000000", // huge utxo
42
+ address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
43
+ output_hash:
44
+ "c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
45
+ block_height: 1,
46
+ rbf: false,
47
+ },
48
+ {
49
+ output_index: 1,
50
+ value: "0",
51
+ address: "<unknown>",
52
+ output_hash:
53
+ "c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
54
+ block_height: 1,
55
+ rbf: false,
56
+ },
57
+ ],
58
+ block: {
59
+ hash: "73c565a6f226978df23480e440b27eb02f307855f50aa3bc72ebb586938f23e0",
60
+ height: 1,
61
+ time: "2021-07-28T13:34:17Z",
62
+ },
63
+ account: 0,
64
+ index: 0,
65
+ address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
66
+ received_at: "2021-07-28T13:34:17Z",
67
+ },
68
+ ]);
69
+
70
+ const txInfo = await xpub.buildTx({
71
+ destAddress: "D9fSjc6zAyjdRgSfbfMLv5z5FpuacvguUi",
72
+ amount: new BigNumber(200000000000000000),
73
+ feePerByte: 100,
74
+ changeAddress,
75
+ utxoPickingStrategy,
76
+ sequence: 0,
77
+ });
78
+ const account = await wallet.generateAccount({
79
+ xpub: xpub.xpub,
80
+ path: "44'/0'",
81
+ index: 0,
82
+ currency: "dogecoin",
83
+ network: "mainnet",
84
+ derivationMode: DerivationModes.LEGACY,
85
+ explorer: "ledgerv3",
86
+ explorerURI: "https://explorers.api.vault.ledger.com/blockchain/v3/doge",
87
+ storage: "mock",
88
+ storageParams: [],
89
+ });
90
+ await wallet.signAccountTx({
91
+ btc: new MockBtc(),
92
+ fromAccount: account,
93
+ txInfo,
94
+ });
95
+ }, 100000);
96
+ });
package/src/api/Ripple.ts CHANGED
@@ -1,185 +1,120 @@
1
1
  import { BigNumber } from "bignumber.js";
2
- import {
3
- parseCurrencyUnit,
4
- getCryptoCurrencyById,
5
- formatCurrencyUnit,
6
- } from "../currencies";
7
2
  import { getEnv } from "../env";
8
- import { RippleAPI } from "ripple-lib";
9
- import { Payment } from "ripple-lib/dist/npm/transaction/payment";
10
- import { TransactionsOptions } from "ripple-lib/dist/npm/ledger/transactions";
3
+ import network from "../network";
4
+ import { parseCurrencyUnit, getCryptoCurrencyById } from "../currencies";
11
5
 
12
- type AsyncApiFunction = (api: RippleAPI) => Promise<any>;
13
-
14
- type XRPInstruction = {
15
- fee: string;
16
- maxLedgerVersionOffset: number;
17
- };
18
-
19
- const rippleUnit = getCryptoCurrencyById("ripple").units[0];
20
-
21
- const defaultEndpoint = () => getEnv("API_RIPPLE_WS");
6
+ const defaultEndpoint = () => getEnv("API_RIPPLE_RPC");
22
7
 
23
8
  export const connectionTimeout = 30 * 1000; // default connectionTimeout is 2s and make the specs bot failed
24
9
 
25
- const WEBSOCKET_DEBOUNCE_DELAY = 30000;
26
- let api;
27
- let pendingQueries: Promise<any>[] = [];
28
- let apiDisconnectTimeout;
29
-
30
- /**
31
- * Connects to Substrate Node, executes calls then disconnects
32
- *
33
- * @param {*} execute - the calls to execute on api
34
- */
35
- async function withApi(
36
- execute: AsyncApiFunction,
37
- endpointConfig: string | null | undefined = null
38
- ): Promise<any> {
39
- const server = endpointConfig || defaultEndpoint();
40
-
41
- // If client is instanciated already, ensure it is connected & ready
42
- if (api) {
43
- try {
44
- if (!(await api.isConnected)) {
45
- throw new Error("XRP WS is not connected");
46
- }
47
- } catch (err) {
48
- // definitely not connected...
49
- api = null;
50
- pendingQueries = [];
51
- }
52
- }
53
-
54
- if (!api) {
55
- api = new RippleAPI({
56
- server,
57
- });
58
- // https://github.com/ripple/ripple-lib/issues/1196#issuecomment-583156895
59
- // We can't add connectionTimeout to the constructor
60
- // We need to add this config to allow the bot to not timeout on github action
61
- // but it will throw a 'additionalProperty "connectionTimeout" exists'
62
- // during the preparePayment
63
- api.connection._config.connectionTimeout = connectionTimeout;
64
- api.on("error", (errorCode, errorMessage) => {
65
- console.warn(`Ripple API error: ${errorCode}: ${errorMessage}`);
66
- });
67
- await api.connect();
68
- }
69
-
70
- cancelDebouncedDisconnect();
71
-
72
- try {
73
- const query = execute(api);
74
- pendingQueries.push(query.catch((err) => err));
75
- const res = await query;
76
- return res;
77
- } finally {
78
- debouncedDisconnect();
79
- }
80
- }
81
-
82
- /**
83
- * Disconnects Websocket API client after all pending queries are flushed.
84
- */
85
- export const disconnect = async (): Promise<void> => {
86
- cancelDebouncedDisconnect();
87
-
88
- if (api) {
89
- const disconnecting = api;
90
- const pending = pendingQueries;
91
- api = undefined;
92
- pendingQueries = [];
93
- await Promise.all(pending);
94
- await disconnecting.disconnect();
95
- }
96
- };
97
-
98
- const cancelDebouncedDisconnect = () => {
99
- if (apiDisconnectTimeout) {
100
- clearTimeout(apiDisconnectTimeout);
101
- apiDisconnectTimeout = null;
102
- }
103
- };
104
-
105
- /**
106
- * Disconnects Websocket client after a delay.
107
- */
108
- const debouncedDisconnect = () => {
109
- cancelDebouncedDisconnect();
110
- apiDisconnectTimeout = setTimeout(disconnect, WEBSOCKET_DEBOUNCE_DELAY);
111
- };
10
+ const rippleUnit = getCryptoCurrencyById("ripple").units[0];
112
11
 
113
12
  export const parseAPIValue = (value: string): BigNumber =>
114
13
  parseCurrencyUnit(rippleUnit, value);
115
14
 
116
- export const parseAPICurrencyObject = ({
117
- currency,
118
- value,
119
- }: {
120
- currency: string;
121
- value: string;
122
- }): BigNumber => {
123
- if (currency !== "XRP") {
124
- console.warn(`RippleJS: attempt to parse unknown currency ${currency}`);
125
- return new BigNumber(0);
126
- }
127
-
128
- return parseAPIValue(value);
15
+ export const submit = async (signature: string): Promise<any> => {
16
+ const res = await network({
17
+ method: "POST",
18
+ url: `${defaultEndpoint()}`,
19
+ data: {
20
+ method: "submit",
21
+ params: [
22
+ {
23
+ tx_blob: signature,
24
+ },
25
+ ],
26
+ },
27
+ });
28
+ return res.data.result;
129
29
  };
130
30
 
131
- export const formatAPICurrencyXRP = (
132
- amount: BigNumber
133
- ): { currency: "XRP"; value: string } => {
134
- const value = formatCurrencyUnit(rippleUnit, amount, {
135
- showAllDigits: true,
136
- disableRounding: true,
137
- useGrouping: false,
138
- });
139
- return {
140
- currency: "XRP",
141
- value,
31
+ type AccountInfo = {
32
+ account_data: {
33
+ Account: string;
34
+ Balance: string;
35
+ Flags: number;
36
+ LedgerEntryType: string;
37
+ OwnerCount: number;
38
+ PreviousTxnID: string;
39
+ PreviousTxnLgrSeq: number;
40
+ Sequence: number;
41
+ index: string;
142
42
  };
43
+ error: string;
143
44
  };
144
45
 
145
- export const preparePayment = async (
146
- address: string,
147
- payment: Payment,
148
- instruction: XRPInstruction
149
- ): Promise<any> =>
150
- withApi(async (api: RippleAPI) => {
151
- return api.preparePayment(address, payment, instruction);
152
- });
153
-
154
- export const submit = async (signature: string): Promise<any> =>
155
- withApi(async (api: RippleAPI) => {
156
- return api.request("submit", {
157
- tx_blob: signature,
158
- });
159
- });
160
- // endpointConfig does not seem to be undestood by linter
161
-
162
46
  export const getAccountInfo = async (
163
47
  recipient: string,
164
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
165
- endpointConfig?: string | null | undefined
166
- ): Promise<any> =>
167
- withApi(async (api: RippleAPI) => {
168
- return api.getAccountInfo(recipient);
48
+ current?: boolean
49
+ ): Promise<AccountInfo> => {
50
+ const res = await network({
51
+ method: "POST",
52
+ url: `${defaultEndpoint()}`,
53
+ data: {
54
+ method: "account_info",
55
+ params: [
56
+ {
57
+ account: recipient,
58
+ ledger_index: current ? "current" : "validated",
59
+ },
60
+ ],
61
+ },
169
62
  });
63
+ return res.data.result;
64
+ };
65
+
170
66
  export const getServerInfo = async (
171
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
172
67
  endpointConfig?: string | null | undefined
173
- ): Promise<any> =>
174
- withApi(async (api: RippleAPI) => {
175
- return api.getServerInfo();
68
+ ): Promise<any> => {
69
+ const res = await network({
70
+ method: "POST",
71
+ url: endpointConfig ?? `${defaultEndpoint()}`,
72
+ data: {
73
+ method: "server_info",
74
+ params: [
75
+ {
76
+ ledger_index: "validated",
77
+ },
78
+ ],
79
+ },
176
80
  });
177
81
 
178
- /* eslint-enable no-unused-vars */
82
+ return res.data.result;
83
+ };
84
+
179
85
  export const getTransactions = async (
180
86
  address: string,
181
- options: TransactionsOptions | undefined
182
- ): Promise<any> =>
183
- withApi(async (api: RippleAPI) => {
184
- return api.getTransactions(address, options);
87
+ options: any | undefined
88
+ ): Promise<any> => {
89
+ const res = await network({
90
+ method: "POST",
91
+ url: `${defaultEndpoint()}`,
92
+ data: {
93
+ method: "account_tx",
94
+ params: [
95
+ {
96
+ account: address,
97
+ ledger_index: "validated",
98
+ ...options,
99
+ },
100
+ ],
101
+ },
185
102
  });
103
+ return res.data.result.transactions;
104
+ };
105
+
106
+ export default async function getLedgerIndex(): Promise<number> {
107
+ const ledgerResponse = await network({
108
+ method: "POST",
109
+ url: `${defaultEndpoint()}`,
110
+ data: {
111
+ method: "ledger",
112
+ params: [
113
+ {
114
+ ledger_index: "validated",
115
+ },
116
+ ],
117
+ },
118
+ });
119
+ return ledgerResponse.data.result.ledger_index;
120
+ }
package/src/api/index.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { disconnect as rippleApiDisconnect } from "./Ripple";
2
1
  import { disconnect as polkadotApiDisconnect } from "../families/polkadot/api";
3
2
 
4
3
  export async function disconnectAll(): Promise<void> {
5
- await rippleApiDisconnect();
6
4
  await polkadotApiDisconnect();
7
5
  }