@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
@@ -0,0 +1,196 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { ethers } from "ethers";
3
+ import { transactionToEthersTransaction } from "../adapters";
4
+ import * as rpcAPI from "../api/rpc.common";
5
+ import {
6
+ fromTransactionRaw,
7
+ getSerializedTransaction,
8
+ toTransactionRaw,
9
+ } from "../transaction";
10
+ import {
11
+ Transaction as EvmTransaction,
12
+ EvmTransactionEIP1559,
13
+ EvmTransactionEIP1559Raw,
14
+ EvmTransactionLegacy,
15
+ EvmTransactionLegacyRaw,
16
+ } from "../types";
17
+
18
+ const testData = Buffer.from("testBufferString").toString("hex");
19
+ const rawEip1559Tx: EvmTransactionEIP1559Raw = {
20
+ amount: "100",
21
+ useAllAmount: false,
22
+ subAccountId: "id",
23
+ recipient: "0xkvn",
24
+ feesStrategy: "custom",
25
+ family: "evm",
26
+ mode: "send",
27
+ nonce: 0,
28
+ gasLimit: "21000",
29
+ chainId: 1,
30
+ data: testData,
31
+ maxFeePerGas: "10000",
32
+ maxPriorityFeePerGas: "10000",
33
+ additionalFees: "420",
34
+ type: 2,
35
+ };
36
+ const eip1559Tx: EvmTransactionEIP1559 = {
37
+ amount: new BigNumber(100),
38
+ useAllAmount: false,
39
+ subAccountId: "id",
40
+ recipient: "0xkvn",
41
+ feesStrategy: "custom",
42
+ family: "evm",
43
+ mode: "send",
44
+ nonce: 0,
45
+ gasLimit: new BigNumber(21000),
46
+ chainId: 1,
47
+ data: Buffer.from(testData, "hex"),
48
+ maxFeePerGas: new BigNumber(10000),
49
+ maxPriorityFeePerGas: new BigNumber(10000),
50
+ additionalFees: new BigNumber(420),
51
+ type: 2,
52
+ };
53
+ const rawLegacyTx: EvmTransactionLegacyRaw = {
54
+ amount: "100",
55
+ useAllAmount: false,
56
+ subAccountId: "id",
57
+ recipient: "0xkvn",
58
+ feesStrategy: "custom",
59
+ family: "evm",
60
+ mode: "send",
61
+ nonce: 0,
62
+ gasLimit: "21000",
63
+ chainId: 1,
64
+ data: testData,
65
+ gasPrice: "10000",
66
+ additionalFees: "420",
67
+ type: 0,
68
+ };
69
+ const legacyTx: EvmTransactionLegacy = {
70
+ amount: new BigNumber(100),
71
+ useAllAmount: false,
72
+ subAccountId: "id",
73
+ recipient: "0xkvn",
74
+ feesStrategy: "custom",
75
+ family: "evm",
76
+ mode: "send",
77
+ nonce: 0,
78
+ gasLimit: new BigNumber(21000),
79
+ chainId: 1,
80
+ data: Buffer.from(testData, "hex"),
81
+ gasPrice: new BigNumber(10000),
82
+ additionalFees: new BigNumber(420),
83
+ type: 0,
84
+ };
85
+
86
+ describe("EVM Family", () => {
87
+ describe("transaction.ts", () => {
88
+ describe("fromTransactionRaw", () => {
89
+ it("should deserialize a raw EIP1559 transaction into a ledger live transaction", () => {
90
+ expect(fromTransactionRaw(rawEip1559Tx)).toEqual(eip1559Tx);
91
+ });
92
+
93
+ it("should deserialize a raw legacy transaction into a ledger live transaction", () => {
94
+ expect(fromTransactionRaw(rawLegacyTx)).toEqual(legacyTx);
95
+ });
96
+ });
97
+
98
+ describe("toTransaction", () => {
99
+ it("should serialize a ledger live EIP1559 transaction into a raw transaction", () => {
100
+ expect(toTransactionRaw(eip1559Tx)).toEqual(rawEip1559Tx);
101
+ });
102
+
103
+ it("should serialize a ledger live legacy transaction into a raw transaction", () => {
104
+ expect(toTransactionRaw(legacyTx)).toEqual(rawLegacyTx);
105
+ });
106
+ });
107
+
108
+ describe("transactionToEthersTransaction", () => {
109
+ it("should build convert an EIP1559 ledger live transaction to an ethers transaction", () => {
110
+ const ethers1559Tx: ethers.Transaction = {
111
+ to: "0xkvn",
112
+ nonce: 0,
113
+ gasLimit: ethers.BigNumber.from(21000),
114
+ data: "0x" + testData,
115
+ value: ethers.BigNumber.from(100),
116
+ chainId: 1,
117
+ type: 2,
118
+ maxFeePerGas: ethers.BigNumber.from(10000),
119
+ maxPriorityFeePerGas: ethers.BigNumber.from(10000),
120
+ };
121
+
122
+ expect(transactionToEthersTransaction(eip1559Tx)).toEqual(ethers1559Tx);
123
+ });
124
+
125
+ it("should build convert an legacy ledger live transaction to an ethers transaction", () => {
126
+ const legacyEthersTx: ethers.Transaction = {
127
+ to: "0xkvn",
128
+ nonce: 0,
129
+ gasLimit: ethers.BigNumber.from(21000),
130
+ data: "0x" + testData,
131
+ value: ethers.BigNumber.from(100),
132
+ chainId: 1,
133
+ type: 0,
134
+ gasPrice: ethers.BigNumber.from(10000),
135
+ };
136
+
137
+ expect(transactionToEthersTransaction(legacyTx)).toEqual(
138
+ legacyEthersTx
139
+ );
140
+ });
141
+ });
142
+
143
+ describe("getSerializedTransaction", () => {
144
+ beforeAll(() => {
145
+ jest
146
+ .spyOn(rpcAPI, "getTransactionCount")
147
+ .mockImplementation(() => Promise.resolve(0));
148
+ });
149
+
150
+ it("should serialize a type 0 transaction", async () => {
151
+ const transactionLegacy: EvmTransaction = {
152
+ amount: new BigNumber(100),
153
+ useAllAmount: false,
154
+ subAccountId: "id",
155
+ recipient: "0x6775e49108cb77cda06Fc3BEF51bcD497602aD88", // obama.eth
156
+ feesStrategy: "custom",
157
+ family: "evm",
158
+ mode: "send",
159
+ nonce: 0,
160
+ gasLimit: new BigNumber(21000),
161
+ chainId: 1,
162
+ gasPrice: new BigNumber(100),
163
+ type: 0,
164
+ };
165
+ const serializedTx = await getSerializedTransaction(transactionLegacy);
166
+
167
+ expect(serializedTx).toBe(
168
+ "0xdf8064825208946775e49108cb77cda06fc3bef51bcd497602ad886480018080"
169
+ );
170
+ });
171
+
172
+ it("should serialize a type 2 transaction", async () => {
173
+ const transactionEIP1559: EvmTransaction = {
174
+ amount: new BigNumber(100),
175
+ useAllAmount: false,
176
+ subAccountId: "id",
177
+ recipient: "0x6775e49108cb77cda06Fc3BEF51bcD497602aD88", // obama.eth
178
+ feesStrategy: "custom",
179
+ family: "evm",
180
+ mode: "send",
181
+ nonce: 0,
182
+ gasLimit: new BigNumber(21000),
183
+ chainId: 1,
184
+ maxFeePerGas: new BigNumber(100),
185
+ maxPriorityFeePerGas: new BigNumber(100),
186
+ type: 2,
187
+ };
188
+ const serializedTx = await getSerializedTransaction(transactionEIP1559);
189
+
190
+ expect(serializedTx).toBe(
191
+ "0x02df01806464825208946775e49108cb77cda06fc3bef51bcd497602ad886480c0"
192
+ );
193
+ });
194
+ });
195
+ });
196
+ });
@@ -0,0 +1,230 @@
1
+ [
2
+ {
3
+ "constant": true,
4
+ "inputs": [
5
+
6
+ ],
7
+ "name": "name",
8
+ "outputs": [
9
+ {
10
+ "name": "",
11
+ "type": "string"
12
+ }
13
+ ],
14
+ "payable": false,
15
+ "stateMutability": "view",
16
+ "type": "function"
17
+ },
18
+ {
19
+ "constant": false,
20
+ "inputs": [
21
+ {
22
+ "name": "_spender",
23
+ "type": "address"
24
+ },
25
+ {
26
+ "name": "_value",
27
+ "type": "uint256"
28
+ }
29
+ ],
30
+ "name": "approve",
31
+ "outputs": [
32
+ {
33
+ "name": "",
34
+ "type": "bool"
35
+ }
36
+ ],
37
+ "payable": false,
38
+ "stateMutability": "nonpayable",
39
+ "type": "function"
40
+ },
41
+ {
42
+ "constant": true,
43
+ "inputs": [
44
+
45
+ ],
46
+ "name": "totalSupply",
47
+ "outputs": [
48
+ {
49
+ "name": "",
50
+ "type": "uint256"
51
+ }
52
+ ],
53
+ "payable": false,
54
+ "stateMutability": "view",
55
+ "type": "function"
56
+ },
57
+ {
58
+ "constant": false,
59
+ "inputs": [
60
+ {
61
+ "name": "_from",
62
+ "type": "address"
63
+ },
64
+ {
65
+ "name": "_to",
66
+ "type": "address"
67
+ },
68
+ {
69
+ "name": "_value",
70
+ "type": "uint256"
71
+ }
72
+ ],
73
+ "name": "transferFrom",
74
+ "outputs": [
75
+ {
76
+ "name": "",
77
+ "type": "bool"
78
+ }
79
+ ],
80
+ "payable": false,
81
+ "stateMutability": "nonpayable",
82
+ "type": "function"
83
+ },
84
+ {
85
+ "constant": true,
86
+ "inputs": [
87
+
88
+ ],
89
+ "name": "decimals",
90
+ "outputs": [
91
+ {
92
+ "name": "",
93
+ "type": "uint8"
94
+ }
95
+ ],
96
+ "payable": false,
97
+ "stateMutability": "view",
98
+ "type": "function"
99
+ },
100
+ {
101
+ "constant": true,
102
+ "inputs": [
103
+ {
104
+ "name": "_owner",
105
+ "type": "address"
106
+ }
107
+ ],
108
+ "name": "balanceOf",
109
+ "outputs": [
110
+ {
111
+ "name": "balance",
112
+ "type": "uint256"
113
+ }
114
+ ],
115
+ "payable": false,
116
+ "stateMutability": "view",
117
+ "type": "function"
118
+ },
119
+ {
120
+ "constant": true,
121
+ "inputs": [
122
+
123
+ ],
124
+ "name": "symbol",
125
+ "outputs": [
126
+ {
127
+ "name": "",
128
+ "type": "string"
129
+ }
130
+ ],
131
+ "payable": false,
132
+ "stateMutability": "view",
133
+ "type": "function"
134
+ },
135
+ {
136
+ "constant": false,
137
+ "inputs": [
138
+ {
139
+ "name": "_to",
140
+ "type": "address"
141
+ },
142
+ {
143
+ "name": "_value",
144
+ "type": "uint256"
145
+ }
146
+ ],
147
+ "name": "transfer",
148
+ "outputs": [
149
+ {
150
+ "name": "",
151
+ "type": "bool"
152
+ }
153
+ ],
154
+ "payable": false,
155
+ "stateMutability": "nonpayable",
156
+ "type": "function"
157
+ },
158
+ {
159
+ "constant": true,
160
+ "inputs": [
161
+ {
162
+ "name": "_owner",
163
+ "type": "address"
164
+ },
165
+ {
166
+ "name": "_spender",
167
+ "type": "address"
168
+ }
169
+ ],
170
+ "name": "allowance",
171
+ "outputs": [
172
+ {
173
+ "name": "",
174
+ "type": "uint256"
175
+ }
176
+ ],
177
+ "payable": false,
178
+ "stateMutability": "view",
179
+ "type": "function"
180
+ },
181
+ {
182
+ "payable": true,
183
+ "stateMutability": "payable",
184
+ "type": "fallback"
185
+ },
186
+ {
187
+ "anonymous": false,
188
+ "inputs": [
189
+ {
190
+ "indexed": true,
191
+ "name": "owner",
192
+ "type": "address"
193
+ },
194
+ {
195
+ "indexed": true,
196
+ "name": "spender",
197
+ "type": "address"
198
+ },
199
+ {
200
+ "indexed": false,
201
+ "name": "value",
202
+ "type": "uint256"
203
+ }
204
+ ],
205
+ "name": "Approval",
206
+ "type": "event"
207
+ },
208
+ {
209
+ "anonymous": false,
210
+ "inputs": [
211
+ {
212
+ "indexed": true,
213
+ "name": "from",
214
+ "type": "address"
215
+ },
216
+ {
217
+ "indexed": true,
218
+ "name": "to",
219
+ "type": "address"
220
+ },
221
+ {
222
+ "indexed": false,
223
+ "name": "value",
224
+ "type": "uint256"
225
+ }
226
+ ],
227
+ "name": "Transfer",
228
+ "type": "event"
229
+ }
230
+ ]
@@ -0,0 +1,252 @@
1
+ [{
2
+ "inputs": [{
3
+ "internalType": "address",
4
+ "name": "_owner",
5
+ "type": "address"
6
+ }],
7
+ "stateMutability": "nonpayable",
8
+ "type": "constructor"
9
+ },
10
+ {
11
+ "anonymous": false,
12
+ "inputs": [{
13
+ "indexed": false,
14
+ "internalType": "uint256",
15
+ "name": "",
16
+ "type": "uint256"
17
+ }],
18
+ "name": "DecimalsUpdated",
19
+ "type": "event"
20
+ },
21
+ {
22
+ "anonymous": false,
23
+ "inputs": [{
24
+ "indexed": false,
25
+ "internalType": "uint256",
26
+ "name": "",
27
+ "type": "uint256"
28
+ }],
29
+ "name": "GasPriceUpdated",
30
+ "type": "event"
31
+ },
32
+ {
33
+ "anonymous": false,
34
+ "inputs": [{
35
+ "indexed": false,
36
+ "internalType": "uint256",
37
+ "name": "",
38
+ "type": "uint256"
39
+ }],
40
+ "name": "L1BaseFeeUpdated",
41
+ "type": "event"
42
+ },
43
+ {
44
+ "anonymous": false,
45
+ "inputs": [{
46
+ "indexed": false,
47
+ "internalType": "uint256",
48
+ "name": "",
49
+ "type": "uint256"
50
+ }],
51
+ "name": "OverheadUpdated",
52
+ "type": "event"
53
+ },
54
+ {
55
+ "anonymous": false,
56
+ "inputs": [{
57
+ "indexed": true,
58
+ "internalType": "address",
59
+ "name": "previousOwner",
60
+ "type": "address"
61
+ },
62
+ {
63
+ "indexed": true,
64
+ "internalType": "address",
65
+ "name": "newOwner",
66
+ "type": "address"
67
+ }
68
+ ],
69
+ "name": "OwnershipTransferred",
70
+ "type": "event"
71
+ },
72
+ {
73
+ "anonymous": false,
74
+ "inputs": [{
75
+ "indexed": false,
76
+ "internalType": "uint256",
77
+ "name": "",
78
+ "type": "uint256"
79
+ }],
80
+ "name": "ScalarUpdated",
81
+ "type": "event"
82
+ },
83
+ {
84
+ "inputs": [],
85
+ "name": "decimals",
86
+ "outputs": [{
87
+ "internalType": "uint256",
88
+ "name": "",
89
+ "type": "uint256"
90
+ }],
91
+ "stateMutability": "view",
92
+ "type": "function"
93
+ },
94
+ {
95
+ "inputs": [],
96
+ "name": "gasPrice",
97
+ "outputs": [{
98
+ "internalType": "uint256",
99
+ "name": "",
100
+ "type": "uint256"
101
+ }],
102
+ "stateMutability": "view",
103
+ "type": "function"
104
+ },
105
+ {
106
+ "inputs": [{
107
+ "internalType": "bytes",
108
+ "name": "_data",
109
+ "type": "bytes"
110
+ }],
111
+ "name": "getL1Fee",
112
+ "outputs": [{
113
+ "internalType": "uint256",
114
+ "name": "",
115
+ "type": "uint256"
116
+ }],
117
+ "stateMutability": "view",
118
+ "type": "function"
119
+ },
120
+ {
121
+ "inputs": [{
122
+ "internalType": "bytes",
123
+ "name": "_data",
124
+ "type": "bytes"
125
+ }],
126
+ "name": "getL1GasUsed",
127
+ "outputs": [{
128
+ "internalType": "uint256",
129
+ "name": "",
130
+ "type": "uint256"
131
+ }],
132
+ "stateMutability": "view",
133
+ "type": "function"
134
+ },
135
+ {
136
+ "inputs": [],
137
+ "name": "l1BaseFee",
138
+ "outputs": [{
139
+ "internalType": "uint256",
140
+ "name": "",
141
+ "type": "uint256"
142
+ }],
143
+ "stateMutability": "view",
144
+ "type": "function"
145
+ },
146
+ {
147
+ "inputs": [],
148
+ "name": "overhead",
149
+ "outputs": [{
150
+ "internalType": "uint256",
151
+ "name": "",
152
+ "type": "uint256"
153
+ }],
154
+ "stateMutability": "view",
155
+ "type": "function"
156
+ },
157
+ {
158
+ "inputs": [],
159
+ "name": "owner",
160
+ "outputs": [{
161
+ "internalType": "address",
162
+ "name": "",
163
+ "type": "address"
164
+ }],
165
+ "stateMutability": "view",
166
+ "type": "function"
167
+ },
168
+ {
169
+ "inputs": [],
170
+ "name": "renounceOwnership",
171
+ "outputs": [],
172
+ "stateMutability": "nonpayable",
173
+ "type": "function"
174
+ },
175
+ {
176
+ "inputs": [],
177
+ "name": "scalar",
178
+ "outputs": [{
179
+ "internalType": "uint256",
180
+ "name": "",
181
+ "type": "uint256"
182
+ }],
183
+ "stateMutability": "view",
184
+ "type": "function"
185
+ },
186
+ {
187
+ "inputs": [{
188
+ "internalType": "uint256",
189
+ "name": "_decimals",
190
+ "type": "uint256"
191
+ }],
192
+ "name": "setDecimals",
193
+ "outputs": [],
194
+ "stateMutability": "nonpayable",
195
+ "type": "function"
196
+ },
197
+ {
198
+ "inputs": [{
199
+ "internalType": "uint256",
200
+ "name": "_gasPrice",
201
+ "type": "uint256"
202
+ }],
203
+ "name": "setGasPrice",
204
+ "outputs": [],
205
+ "stateMutability": "nonpayable",
206
+ "type": "function"
207
+ },
208
+ {
209
+ "inputs": [{
210
+ "internalType": "uint256",
211
+ "name": "_baseFee",
212
+ "type": "uint256"
213
+ }],
214
+ "name": "setL1BaseFee",
215
+ "outputs": [],
216
+ "stateMutability": "nonpayable",
217
+ "type": "function"
218
+ },
219
+ {
220
+ "inputs": [{
221
+ "internalType": "uint256",
222
+ "name": "_overhead",
223
+ "type": "uint256"
224
+ }],
225
+ "name": "setOverhead",
226
+ "outputs": [],
227
+ "stateMutability": "nonpayable",
228
+ "type": "function"
229
+ },
230
+ {
231
+ "inputs": [{
232
+ "internalType": "uint256",
233
+ "name": "_scalar",
234
+ "type": "uint256"
235
+ }],
236
+ "name": "setScalar",
237
+ "outputs": [],
238
+ "stateMutability": "nonpayable",
239
+ "type": "function"
240
+ },
241
+ {
242
+ "inputs": [{
243
+ "internalType": "address",
244
+ "name": "newOwner",
245
+ "type": "address"
246
+ }],
247
+ "name": "transferOwnership",
248
+ "outputs": [],
249
+ "stateMutability": "nonpayable",
250
+ "type": "function"
251
+ }
252
+ ]