@ledgerhq/coin-evm 0.2.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.
Files changed (53) hide show
  1. package/.eslintrc.js +57 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/CHANGELOG.md +18 -0
  4. package/jest.config.js +6 -0
  5. package/package.json +102 -0
  6. package/src/__tests__/adapters.unit.test.ts +527 -0
  7. package/src/__tests__/broadcast.unit.test.ts +181 -0
  8. package/src/__tests__/buildOptimisticOperation.unit.test.ts +182 -0
  9. package/src/__tests__/createTransaction.unit.test.ts +52 -0
  10. package/src/__tests__/deviceTransactionConfig.unit.test.ts +245 -0
  11. package/src/__tests__/estimateMaxSpendable.unit.test.ts +123 -0
  12. package/src/__tests__/getTransactionStatus.unit.test.ts +355 -0
  13. package/src/__tests__/hw-getAddress.unit.test.ts +24 -0
  14. package/src/__tests__/logic.unit.test.ts +406 -0
  15. package/src/__tests__/preload.unit.test.ts +139 -0
  16. package/src/__tests__/prepareTransaction.unit.test.ts +394 -0
  17. package/src/__tests__/rpc.unit.test.ts +532 -0
  18. package/src/__tests__/signOperation.unit.test.ts +157 -0
  19. package/src/__tests__/synchronization.unit.test.ts +832 -0
  20. package/src/__tests__/transaction.unit.test.ts +196 -0
  21. package/src/abis/erc20.abi.json +230 -0
  22. package/src/abis/optimismGasPriceOracle.abi.json +252 -0
  23. package/src/adapters.ts +148 -0
  24. package/src/api/etherscan.ts +124 -0
  25. package/src/api/rpc.common.ts +354 -0
  26. package/src/api/rpc.native.ts +5 -0
  27. package/src/api/rpc.ts +2 -0
  28. package/src/bridge/js.ts +77 -0
  29. package/src/bridge.integration.test.ts +93 -0
  30. package/src/broadcast.ts +40 -0
  31. package/src/buildOptimisticOperation.ts +113 -0
  32. package/src/cli-transaction.ts +11 -0
  33. package/src/createTransaction.ts +25 -0
  34. package/src/datasets/ethereum.scanAccounts.1.ts +48 -0
  35. package/src/datasets/ethereum1.ts +20 -0
  36. package/src/datasets/ethereum2.ts +20 -0
  37. package/src/datasets/ethereum_classic.ts +68 -0
  38. package/src/deviceTransactionConfig.ts +64 -0
  39. package/src/errors.ts +5 -0
  40. package/src/estimateMaxSpendable.ts +19 -0
  41. package/src/getTransactionStatus.ts +186 -0
  42. package/src/hw-getAddress.ts +24 -0
  43. package/src/logic.ts +149 -0
  44. package/src/preload.ts +54 -0
  45. package/src/prepareTransaction.ts +176 -0
  46. package/src/signOperation.ts +127 -0
  47. package/src/specs.ts +344 -0
  48. package/src/speculos-deviceActions.ts +83 -0
  49. package/src/synchronization.ts +317 -0
  50. package/src/testUtils.ts +153 -0
  51. package/src/transaction.ts +193 -0
  52. package/src/types.ts +132 -0
  53. package/tsconfig.json +12 -0
package/src/types.ts ADDED
@@ -0,0 +1,132 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ TransactionCommon,
4
+ TransactionCommonRaw,
5
+ TransactionStatusCommon,
6
+ TransactionStatusCommonRaw,
7
+ } from "@ledgerhq/types-live";
8
+
9
+ export type EvmTransactionMode = "send";
10
+
11
+ export type EvmTransactionBase = TransactionCommon & {
12
+ family: "evm";
13
+ mode: EvmTransactionMode;
14
+ // transaction number, relative to the account. used to sequence transactions
15
+ nonce: number;
16
+ // maximum of gas (as unit of computation) used by the transaction
17
+ gasLimit: BigNumber;
18
+ // id of the blockchain to use (used at the signature level for EIP-155)
19
+ chainId: number;
20
+ // buffer of the calldata that will be used by the smart contract
21
+ data?: Buffer | null;
22
+ // type of the transaction (will determine if transaction is a legacy transaction or an EIP-1559 one)
23
+ type?: number;
24
+ // additional fees can be expected on some Layer 2 chains.
25
+ // It's an additional cost to take into account while estimating the cost of the tx.
26
+ additionalFees?: BigNumber;
27
+ };
28
+
29
+ export type EvmTransactionLegacy = EvmTransactionBase & {
30
+ type?: 0 | 1;
31
+ gasPrice: BigNumber;
32
+ maxPriorityFeePerGas?: never;
33
+ maxFeePerGas?: never;
34
+ };
35
+
36
+ export type EvmTransactionEIP1559 = EvmTransactionBase & {
37
+ type: 2;
38
+ gasPrice?: never;
39
+ maxPriorityFeePerGas: BigNumber;
40
+ maxFeePerGas: BigNumber;
41
+ };
42
+
43
+ export type Transaction = EvmTransactionLegacy | EvmTransactionEIP1559;
44
+
45
+ export type EvmTransactionBaseRaw = TransactionCommonRaw & {
46
+ family: "evm";
47
+ mode: EvmTransactionMode;
48
+ nonce: number;
49
+ gasLimit: string;
50
+ chainId: number;
51
+ data?: string | null;
52
+ type?: number;
53
+ additionalFees?: string;
54
+ };
55
+
56
+ export type EvmTransactionLegacyRaw = EvmTransactionBaseRaw & {
57
+ type?: 0 | 1;
58
+ gasPrice: string;
59
+ maxPriorityFeePerGas?: never;
60
+ maxFeePerGas?: never;
61
+ };
62
+
63
+ export type EvmTransactionEIP1559Raw = EvmTransactionBaseRaw & {
64
+ type: 2;
65
+ gasPrice?: never;
66
+ maxPriorityFeePerGas: string;
67
+ maxFeePerGas: string;
68
+ };
69
+
70
+ export type TransactionRaw = EvmTransactionLegacyRaw | EvmTransactionEIP1559Raw;
71
+
72
+ export type EtherscanOperation = {
73
+ blockNumber: string;
74
+ timeStamp: string;
75
+ hash: string;
76
+ nonce: string;
77
+ blockHash: string;
78
+ transactionIndex: string;
79
+ from: string;
80
+ to: string;
81
+ value: string;
82
+ gas: string;
83
+ gasPrice: string;
84
+ isError: string;
85
+ txreceipt_status: string;
86
+ input: string;
87
+ contractAddress: string;
88
+ cumulativeGasUsed: string;
89
+ gasUsed: string;
90
+ confirmations: string;
91
+ methodId: string;
92
+ functionName: string;
93
+ };
94
+
95
+ export type EtherscanERC20Event = {
96
+ blockNumber: string;
97
+ timeStamp: string;
98
+ hash: string;
99
+ nonce: string;
100
+ blockHash: string;
101
+ from: string;
102
+ contractAddress: string;
103
+ to: string;
104
+ value: string;
105
+ tokenName: string;
106
+ tokenSymbol: string;
107
+ tokenDecimal: string;
108
+ transactionIndex: string;
109
+ gas: string;
110
+ gasPrice: string;
111
+ gasUsed: string;
112
+ cumulativeGasUsed: string;
113
+ input: string;
114
+ confirmations: string;
115
+ };
116
+
117
+ export type TransactionStatus = TransactionStatusCommon;
118
+
119
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
120
+
121
+ export type FeeHistory = {
122
+ baseFeePerGas: string[];
123
+ gasUsedRatio: number[];
124
+ oldestBlock: string;
125
+ reward: string[][];
126
+ };
127
+
128
+ export type FeeData = {
129
+ maxFeePerGas: null | BigNumber;
130
+ maxPriorityFeePerGas: null | BigNumber;
131
+ gasPrice: null | BigNumber;
132
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "module": "commonjs",
7
+ "downlevelIteration": true,
8
+ "lib": ["es2020", "dom"],
9
+ "outDir": "lib"
10
+ },
11
+ "include": ["src/**/*"]
12
+ }