@ledgerhq/coin-evm 0.7.0-next.0 → 0.7.0-next.2

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.
@@ -12,34 +12,770 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const eip55_1 = __importDefault(require("eip55"));
15
16
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
16
17
  const cryptoassets_1 = require("@ledgerhq/cryptoassets");
17
18
  const common_fixtures_1 = require("../fixtures/common.fixtures");
18
19
  const deviceTransactionConfig_1 = __importDefault(require("../../deviceTransactionConfig"));
19
20
  const getTransactionStatus_1 = __importDefault(require("../../getTransactionStatus"));
21
+ const nftId_1 = require("@ledgerhq/coin-framework/nft/nftId");
22
+ var NFT_CONTRACTS;
23
+ (function (NFT_CONTRACTS) {
24
+ NFT_CONTRACTS["ERC721"] = "0x60F80121C31A0d46B5279700f9DF786054aa5eE5";
25
+ NFT_CONTRACTS["ERC1155"] = "0xd07dc4262BCDbf85190C01c996b4C06a461d2430";
26
+ })(NFT_CONTRACTS || (NFT_CONTRACTS = {}));
20
27
  const currency = (0, cryptoassets_1.getCryptoCurrencyById)("ethereum");
21
28
  const tokenCurrency = (0, cryptoassets_1.getTokenById)("ethereum/erc20/usd__coin");
22
29
  const tokenAccount = (0, common_fixtures_1.makeTokenAccount)("0xkvn", tokenCurrency);
23
30
  const account = (0, common_fixtures_1.makeAccount)("0xkvn", currency, [tokenAccount]);
31
+ const accountWithNfts = Object.freeze(Object.assign(Object.assign({}, account), { nfts: [
32
+ {
33
+ amount: new bignumber_js_1.default(1),
34
+ contract: NFT_CONTRACTS.ERC721,
35
+ currencyId: currency.id,
36
+ standard: "ERC721",
37
+ tokenId: "1",
38
+ id: (0, nftId_1.encodeNftId)(account.id, NFT_CONTRACTS.ERC721, "1", currency.id),
39
+ metadata: { tokenName: "Collection ERC721" },
40
+ },
41
+ {
42
+ amount: new bignumber_js_1.default(10),
43
+ contract: NFT_CONTRACTS.ERC1155,
44
+ currencyId: currency.id,
45
+ standard: "ERC721",
46
+ tokenId: "1",
47
+ id: (0, nftId_1.encodeNftId)(account.id, NFT_CONTRACTS.ERC1155, "1", currency.id),
48
+ metadata: { tokenName: "Collection ERC1155" },
49
+ },
50
+ ] }));
51
+ const baseTransaction = {
52
+ amount: new bignumber_js_1.default(0),
53
+ useAllAmount: false,
54
+ subAccountId: "id",
55
+ recipient: "",
56
+ feesStrategy: "custom",
57
+ family: "evm",
58
+ mode: "send",
59
+ gasPrice: new bignumber_js_1.default(0),
60
+ gasLimit: new bignumber_js_1.default(21000),
61
+ nonce: 0,
62
+ chainId: 1,
63
+ };
64
+ const status = {
65
+ errors: {},
66
+ warnings: {},
67
+ estimatedFees: new bignumber_js_1.default(0),
68
+ amount: new bignumber_js_1.default(0),
69
+ totalSpent: new bignumber_js_1.default(0),
70
+ };
24
71
  describe("EVM Family", () => {
25
72
  describe("deviceTransactionConfig.ts", () => {
26
73
  describe("getDeviceTransactionConfig", () => {
74
+ describe("From Live", () => {
75
+ describe("Coin", () => {
76
+ it("should return the fields for a normal transaction without domain", () => {
77
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), recipient: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" });
78
+ expect((0, deviceTransactionConfig_1.default)({
79
+ account: account,
80
+ parentAccount: undefined,
81
+ transaction,
82
+ status,
83
+ })).toEqual([
84
+ {
85
+ type: "amount",
86
+ label: "Amount",
87
+ },
88
+ {
89
+ type: "address",
90
+ label: "Address",
91
+ address: transaction.recipient,
92
+ },
93
+ { type: "text", label: "Network", value: "Ethereum" },
94
+ { type: "fees", label: "Max fees" },
95
+ ]);
96
+ });
97
+ it("should return the fields for a normal transaction with domain", () => {
98
+ var _a;
99
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), recipient: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", recipientDomain: {
100
+ registry: "ens",
101
+ domain: "vitalik.eth",
102
+ address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
103
+ type: "forward",
104
+ } });
105
+ expect((0, deviceTransactionConfig_1.default)({
106
+ account: account,
107
+ parentAccount: undefined,
108
+ transaction,
109
+ status,
110
+ })).toEqual([
111
+ {
112
+ type: "amount",
113
+ label: "Amount",
114
+ },
115
+ {
116
+ type: "text",
117
+ label: "Domain",
118
+ value: (_a = transaction.recipientDomain) === null || _a === void 0 ? void 0 : _a.domain,
119
+ },
120
+ { type: "text", label: "Network", value: "Ethereum" },
121
+ { type: "fees", label: "Max fees" },
122
+ ]);
123
+ });
124
+ });
125
+ describe("Tokens", () => {
126
+ it("should return the fields for a token transfer transaction without domain", () => {
127
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), recipient: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" });
128
+ expect((0, deviceTransactionConfig_1.default)({
129
+ account: tokenAccount,
130
+ parentAccount: account,
131
+ transaction,
132
+ status,
133
+ })).toEqual([
134
+ {
135
+ type: "amount",
136
+ label: "Amount",
137
+ },
138
+ {
139
+ type: "address",
140
+ label: "Address",
141
+ address: transaction.recipient,
142
+ },
143
+ { type: "text", label: "Network", value: "Ethereum" },
144
+ { type: "fees", label: "Max fees" },
145
+ ]);
146
+ });
147
+ it("should return the fields for a token transfer transaction with domain", () => {
148
+ var _a;
149
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), recipient: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", recipientDomain: {
150
+ registry: "ens",
151
+ domain: "vitalik.eth",
152
+ address: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
153
+ type: "forward",
154
+ } });
155
+ expect((0, deviceTransactionConfig_1.default)({
156
+ account: account,
157
+ parentAccount: undefined,
158
+ transaction,
159
+ status,
160
+ })).toEqual([
161
+ {
162
+ type: "amount",
163
+ label: "Amount",
164
+ },
165
+ {
166
+ type: "text",
167
+ label: "Domain",
168
+ value: (_a = transaction.recipientDomain) === null || _a === void 0 ? void 0 : _a.domain,
169
+ },
170
+ { type: "text", label: "Network", value: "Ethereum" },
171
+ { type: "fees", label: "Max fees" },
172
+ ]);
173
+ });
174
+ });
175
+ describe("NFTs", () => {
176
+ it("should return the right fields for an NFT transfer with mode 'erc721'", () => __awaiter(void 0, void 0, void 0, function* () {
177
+ const nftTransaction = Object.assign(Object.assign({}, baseTransaction), { mode: "erc721", recipient: "0x8E9eDe486d8208705C67095dd0b4839dEB127132", nft: {
178
+ contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
179
+ tokenId: "1",
180
+ quantity: new bignumber_js_1.default(1),
181
+ collectionName: "BAYC",
182
+ } });
183
+ const status = yield (0, getTransactionStatus_1.default)(account, nftTransaction);
184
+ expect((0, deviceTransactionConfig_1.default)({
185
+ account: tokenAccount,
186
+ parentAccount: account,
187
+ transaction: nftTransaction,
188
+ status,
189
+ })).toEqual([
190
+ {
191
+ type: "text",
192
+ label: "Type",
193
+ value: `NFT Transfer`,
194
+ },
195
+ {
196
+ type: "text",
197
+ label: "To",
198
+ value: nftTransaction.recipient,
199
+ },
200
+ {
201
+ type: "text",
202
+ label: "Collection Name",
203
+ value: nftTransaction.nft.collectionName,
204
+ },
205
+ {
206
+ type: "address",
207
+ label: "NFT Address",
208
+ address: nftTransaction.nft.contract,
209
+ },
210
+ {
211
+ type: "text",
212
+ label: "NFT ID",
213
+ value: nftTransaction.nft.tokenId,
214
+ },
215
+ { type: "text", label: "Network", value: "Ethereum" },
216
+ { type: "fees", label: "Max fees" },
217
+ ]);
218
+ }));
219
+ it("should return the right fields for an NFT transfer with mode 'erc1155'", () => __awaiter(void 0, void 0, void 0, function* () {
220
+ const nftTransaction = Object.assign(Object.assign({}, baseTransaction), { mode: "erc1155", recipient: "0x8E9eDe486d8208705C67095dd0b4839dEB127132", nft: {
221
+ contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
222
+ tokenId: "1",
223
+ quantity: new bignumber_js_1.default(10),
224
+ collectionName: "BAYC",
225
+ } });
226
+ const status = yield (0, getTransactionStatus_1.default)(account, nftTransaction);
227
+ expect((0, deviceTransactionConfig_1.default)({
228
+ account: tokenAccount,
229
+ parentAccount: account,
230
+ transaction: nftTransaction,
231
+ status,
232
+ })).toEqual([
233
+ {
234
+ type: "text",
235
+ label: "Type",
236
+ value: `NFT Transfer`,
237
+ },
238
+ {
239
+ type: "text",
240
+ label: "To",
241
+ value: nftTransaction.recipient,
242
+ },
243
+ {
244
+ type: "text",
245
+ label: "Collection Name",
246
+ value: nftTransaction.nft.collectionName,
247
+ },
248
+ {
249
+ type: "text",
250
+ label: "Quantity",
251
+ value: nftTransaction.nft.quantity.toFixed(),
252
+ },
253
+ {
254
+ type: "address",
255
+ label: "NFT Address",
256
+ address: nftTransaction.nft.contract,
257
+ },
258
+ {
259
+ type: "text",
260
+ label: "NFT ID",
261
+ value: nftTransaction.nft.tokenId,
262
+ },
263
+ { type: "text", label: "Network", value: "Ethereum" },
264
+ { type: "fees", label: "Max fees" },
265
+ ]);
266
+ }));
267
+ });
268
+ });
269
+ describe("From Wallet API", () => {
270
+ describe("Coin", () => {
271
+ it("should return the fields for a normal transaction", () => {
272
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), recipient: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045" });
273
+ expect((0, deviceTransactionConfig_1.default)({
274
+ account: account,
275
+ parentAccount: undefined,
276
+ transaction,
277
+ status,
278
+ })).toEqual([
279
+ {
280
+ type: "amount",
281
+ label: "Amount",
282
+ },
283
+ {
284
+ type: "address",
285
+ label: "Address",
286
+ address: transaction.recipient,
287
+ },
288
+ { type: "text", label: "Network", value: "Ethereum" },
289
+ { type: "fees", label: "Max fees" },
290
+ ]);
291
+ });
292
+ });
293
+ describe("Tokens", () => {
294
+ it("should return the fields for a token transfer transaction", () => {
295
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", data: Buffer.from("a9059cbb0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
296
+ expect((0, deviceTransactionConfig_1.default)({
297
+ account: account,
298
+ parentAccount: undefined,
299
+ transaction,
300
+ status,
301
+ })).toEqual([
302
+ {
303
+ type: "text",
304
+ label: "Amount",
305
+ value: `USDC 0.000001`,
306
+ },
307
+ {
308
+ type: "address",
309
+ label: "Address",
310
+ address: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
311
+ },
312
+ { type: "text", label: "Network", value: "Ethereum" },
313
+ { type: "fees", label: "Max fees" },
314
+ ]);
315
+ });
316
+ it("should return the fields for a token allowance transaction", () => {
317
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", data: Buffer.from("095ea7b30000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
318
+ expect((0, deviceTransactionConfig_1.default)({
319
+ account: account,
320
+ parentAccount: undefined,
321
+ transaction,
322
+ status,
323
+ })).toEqual([
324
+ { type: "text", label: "Type", value: "Approve" },
325
+ {
326
+ type: "text",
327
+ label: "Amount",
328
+ value: `USDC 0.000001`,
329
+ },
330
+ {
331
+ type: "address",
332
+ label: "Address",
333
+ address: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
334
+ },
335
+ { type: "text", label: "Network", value: "Ethereum" },
336
+ { type: "fees", label: "Max fees" },
337
+ ]);
338
+ });
339
+ it("should return the fields for an unlimited token allowance transaction", () => {
340
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", data: Buffer.from("095ea7b30000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "hex") });
341
+ expect((0, deviceTransactionConfig_1.default)({
342
+ account: account,
343
+ parentAccount: undefined,
344
+ transaction,
345
+ status,
346
+ })).toEqual([
347
+ { type: "text", label: "Type", value: "Approve" },
348
+ {
349
+ type: "text",
350
+ label: "Amount",
351
+ value: `Unlimited USDC`,
352
+ },
353
+ {
354
+ type: "address",
355
+ label: "Address",
356
+ address: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
357
+ },
358
+ { type: "text", label: "Network", value: "Ethereum" },
359
+ { type: "fees", label: "Max fees" },
360
+ ]);
361
+ });
362
+ });
363
+ describe("NFTs", () => {
364
+ describe("ERC721", () => {
365
+ it("should return the fields for an ERC721 transferFrom transaction", () => {
366
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("23b872dd0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
367
+ expect((0, deviceTransactionConfig_1.default)({
368
+ account: accountWithNfts,
369
+ parentAccount: undefined,
370
+ transaction,
371
+ status,
372
+ })).toEqual([
373
+ {
374
+ type: "text",
375
+ label: "NFT",
376
+ value: "Transfer",
377
+ },
378
+ {
379
+ type: "text",
380
+ label: "To",
381
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
382
+ },
383
+ {
384
+ type: "text",
385
+ label: "Collection Name",
386
+ value: "Collection ERC721",
387
+ },
388
+ {
389
+ type: "address",
390
+ label: "NFT Address",
391
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
392
+ },
393
+ {
394
+ type: "text",
395
+ label: "NFT ID",
396
+ value: "1",
397
+ },
398
+ { type: "text", label: "Network", value: "Ethereum" },
399
+ { type: "fees", label: "Max fees" },
400
+ ]);
401
+ });
402
+ it("should return the fields for an ERC721 safeTransferFrom transaction", () => {
403
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("42842e0e0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
404
+ expect((0, deviceTransactionConfig_1.default)({
405
+ account: accountWithNfts,
406
+ parentAccount: undefined,
407
+ transaction,
408
+ status,
409
+ })).toEqual([
410
+ {
411
+ type: "text",
412
+ label: "NFT",
413
+ value: "Transfer",
414
+ },
415
+ {
416
+ type: "text",
417
+ label: "To",
418
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
419
+ },
420
+ {
421
+ type: "text",
422
+ label: "Collection Name",
423
+ value: "Collection ERC721",
424
+ },
425
+ {
426
+ type: "address",
427
+ label: "NFT Address",
428
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
429
+ },
430
+ {
431
+ type: "text",
432
+ label: "NFT ID",
433
+ value: "1",
434
+ },
435
+ { type: "text", label: "Network", value: "Ethereum" },
436
+ { type: "fees", label: "Max fees" },
437
+ ]);
438
+ });
439
+ it("should return the fields for an ERC721 safeTransferFromWithData transaction", () => {
440
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("b88d4fde0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000", "hex") });
441
+ expect((0, deviceTransactionConfig_1.default)({
442
+ account: accountWithNfts,
443
+ parentAccount: undefined,
444
+ transaction,
445
+ status,
446
+ })).toEqual([
447
+ {
448
+ type: "text",
449
+ label: "NFT",
450
+ value: "Transfer",
451
+ },
452
+ {
453
+ type: "text",
454
+ label: "To",
455
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
456
+ },
457
+ {
458
+ type: "text",
459
+ label: "Collection Name",
460
+ value: "Collection ERC721",
461
+ },
462
+ {
463
+ type: "address",
464
+ label: "NFT Address",
465
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
466
+ },
467
+ {
468
+ type: "text",
469
+ label: "NFT ID",
470
+ value: "1",
471
+ },
472
+ { type: "text", label: "Network", value: "Ethereum" },
473
+ { type: "fees", label: "Max fees" },
474
+ ]);
475
+ });
476
+ it("should return the fields for an ERC721 approve transaction", () => {
477
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("095ea7b30000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
478
+ expect((0, deviceTransactionConfig_1.default)({
479
+ account: accountWithNfts,
480
+ parentAccount: undefined,
481
+ transaction,
482
+ status,
483
+ })).toEqual([
484
+ {
485
+ type: "text",
486
+ label: "NFT",
487
+ value: "Allowance",
488
+ },
489
+ {
490
+ type: "text",
491
+ label: "Allow",
492
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
493
+ },
494
+ {
495
+ type: "text",
496
+ label: "To Manage Your",
497
+ value: "Collection ERC721",
498
+ },
499
+ {
500
+ type: "address",
501
+ label: "NFT Address",
502
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
503
+ },
504
+ {
505
+ type: "text",
506
+ label: "NFT ID",
507
+ value: "1",
508
+ },
509
+ { type: "text", label: "Network", value: "Ethereum" },
510
+ { type: "fees", label: "Max fees" },
511
+ ]);
512
+ });
513
+ it("should return the fields for an ERC721 setApprovalForAll true transaction", () => {
514
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("a22cb4650000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
515
+ expect((0, deviceTransactionConfig_1.default)({
516
+ account: accountWithNfts,
517
+ parentAccount: undefined,
518
+ transaction,
519
+ status,
520
+ })).toEqual([
521
+ {
522
+ type: "text",
523
+ label: "NFT",
524
+ value: "Allowance",
525
+ },
526
+ {
527
+ type: "text",
528
+ label: "Allow",
529
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
530
+ },
531
+ {
532
+ type: "text",
533
+ label: "To Manage ALL",
534
+ value: "Collection ERC721",
535
+ },
536
+ {
537
+ type: "address",
538
+ label: "NFT Address",
539
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
540
+ },
541
+ { type: "text", label: "Network", value: "Ethereum" },
542
+ { type: "fees", label: "Max fees" },
543
+ ]);
544
+ });
545
+ it("should return the fields for an ERC721 setApprovalForAll false transaction", () => {
546
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC721, data: Buffer.from("a22cb4650000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000000", "hex") });
547
+ expect((0, deviceTransactionConfig_1.default)({
548
+ account: accountWithNfts,
549
+ parentAccount: undefined,
550
+ transaction,
551
+ status,
552
+ })).toEqual([
553
+ {
554
+ type: "text",
555
+ label: "NFT",
556
+ value: "Allowance",
557
+ },
558
+ {
559
+ type: "text",
560
+ label: "Revoke",
561
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
562
+ },
563
+ {
564
+ type: "text",
565
+ label: "To Manage ALL",
566
+ value: "Collection ERC721",
567
+ },
568
+ {
569
+ type: "address",
570
+ label: "NFT Address",
571
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC721),
572
+ },
573
+ { type: "text", label: "Network", value: "Ethereum" },
574
+ { type: "fees", label: "Max fees" },
575
+ ]);
576
+ });
577
+ });
578
+ describe("ERC1155", () => {
579
+ it("should return the fields for an ERC1155 safeTransferFrom transaction", () => {
580
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC1155, data: Buffer.from("f242432a0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000", "hex") });
581
+ expect((0, deviceTransactionConfig_1.default)({
582
+ account: accountWithNfts,
583
+ parentAccount: undefined,
584
+ transaction,
585
+ status,
586
+ })).toEqual([
587
+ {
588
+ type: "text",
589
+ label: "NFT",
590
+ value: "Transfer",
591
+ },
592
+ {
593
+ type: "text",
594
+ label: "To",
595
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
596
+ },
597
+ {
598
+ type: "text",
599
+ label: "Collection Name",
600
+ value: "Collection ERC1155",
601
+ },
602
+ {
603
+ type: "address",
604
+ label: "NFT Address",
605
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC1155),
606
+ },
607
+ {
608
+ type: "text",
609
+ label: "NFT ID",
610
+ value: "1",
611
+ },
612
+ {
613
+ type: "text",
614
+ label: "Quantity",
615
+ value: "5",
616
+ },
617
+ { type: "text", label: "Network", value: "Ethereum" },
618
+ { type: "fees", label: "Max fees" },
619
+ ]);
620
+ });
621
+ it("should return the fields for an ERC1155 safeBatchTransferFrom transaction", () => {
622
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC1155, data: Buffer.from("2eb2c2d60000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000", "hex") });
623
+ expect((0, deviceTransactionConfig_1.default)({
624
+ account: accountWithNfts,
625
+ parentAccount: undefined,
626
+ transaction,
627
+ status,
628
+ })).toEqual([
629
+ {
630
+ type: "text",
631
+ label: "NFT",
632
+ value: "Batch Transfer",
633
+ },
634
+ {
635
+ type: "text",
636
+ label: "To",
637
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
638
+ },
639
+ {
640
+ type: "text",
641
+ label: "Collection Name",
642
+ value: "Collection ERC1155",
643
+ },
644
+ {
645
+ type: "address",
646
+ label: "NFT Address",
647
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC1155),
648
+ },
649
+ {
650
+ type: "text",
651
+ label: "Total Quantity",
652
+ value: "15 from 2 NFT IDs",
653
+ },
654
+ { type: "text", label: "Network", value: "Ethereum" },
655
+ { type: "fees", label: "Max fees" },
656
+ ]);
657
+ });
658
+ it("should return the fields for an ERC1155 setApprovalForAll true transaction", () => {
659
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC1155, data: Buffer.from("a22cb4650000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000001", "hex") });
660
+ expect((0, deviceTransactionConfig_1.default)({
661
+ account: accountWithNfts,
662
+ parentAccount: undefined,
663
+ transaction,
664
+ status,
665
+ })).toEqual([
666
+ {
667
+ type: "text",
668
+ label: "NFT",
669
+ value: "Allowance",
670
+ },
671
+ {
672
+ type: "text",
673
+ label: "Allow",
674
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
675
+ },
676
+ {
677
+ type: "text",
678
+ label: "To Manage ALL",
679
+ value: "Collection ERC1155",
680
+ },
681
+ {
682
+ type: "address",
683
+ label: "NFT Address",
684
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC1155),
685
+ },
686
+ { type: "text", label: "Network", value: "Ethereum" },
687
+ { type: "fees", label: "Max fees" },
688
+ ]);
689
+ });
690
+ it("should return the fields for an ERC1155 setApprovalForAll false transaction", () => {
691
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: NFT_CONTRACTS.ERC1155, data: Buffer.from("a22cb4650000000000000000000000006cbcd73cd8e8a42844662f0a0e76d7f79afd933d0000000000000000000000000000000000000000000000000000000000000000", "hex") });
692
+ expect((0, deviceTransactionConfig_1.default)({
693
+ account: accountWithNfts,
694
+ parentAccount: undefined,
695
+ transaction,
696
+ status,
697
+ })).toEqual([
698
+ {
699
+ type: "text",
700
+ label: "NFT",
701
+ value: "Allowance",
702
+ },
703
+ {
704
+ type: "text",
705
+ label: "Revoke",
706
+ value: eip55_1.default.encode(`0x6cbcd73cd8e8a42844662f0a0e76d7f79afd933d`),
707
+ },
708
+ {
709
+ type: "text",
710
+ label: "To Manage ALL",
711
+ value: "Collection ERC1155",
712
+ },
713
+ {
714
+ type: "address",
715
+ label: "NFT Address",
716
+ address: eip55_1.default.encode(NFT_CONTRACTS.ERC1155),
717
+ },
718
+ { type: "text", label: "Network", value: "Ethereum" },
719
+ { type: "fees", label: "Max fees" },
720
+ ]);
721
+ });
722
+ });
723
+ });
724
+ it("should fallback on other cases without amount", () => {
725
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(0), recipient: "0x000000000000000000000000000000000000dead", data: Buffer.from("00", "hex") });
726
+ expect((0, deviceTransactionConfig_1.default)({
727
+ account: account,
728
+ parentAccount: undefined,
729
+ transaction,
730
+ status,
731
+ })).toEqual([
732
+ {
733
+ type: "text",
734
+ label: "Data",
735
+ value: "Present",
736
+ },
737
+ {
738
+ type: "amount",
739
+ label: "Amount",
740
+ },
741
+ {
742
+ type: "text",
743
+ label: "Address",
744
+ value: "0x000000000000000000000000000000000000dead",
745
+ },
746
+ { type: "text", label: "Network", value: "Ethereum" },
747
+ { type: "fees", label: "Max fees" },
748
+ ]);
749
+ });
750
+ it("should fallback on other cases with amount", () => {
751
+ const transaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(1), recipient: "0x000000000000000000000000000000000000dead", data: Buffer.from("00", "hex") });
752
+ expect((0, deviceTransactionConfig_1.default)({
753
+ account: account,
754
+ parentAccount: undefined,
755
+ transaction,
756
+ status,
757
+ })).toEqual([
758
+ {
759
+ type: "text",
760
+ label: "Data",
761
+ value: "Present",
762
+ },
763
+ {
764
+ type: "amount",
765
+ label: "Amount",
766
+ },
767
+ {
768
+ type: "text",
769
+ label: "Address",
770
+ value: "0x000000000000000000000000000000000000dead",
771
+ },
772
+ { type: "text", label: "Network", value: "Ethereum" },
773
+ { type: "fees", label: "Max fees" },
774
+ ]);
775
+ });
776
+ });
27
777
  it("should return the right fields and infos for a coin transaction without mode'", () => __awaiter(void 0, void 0, void 0, function* () {
28
- const coinTransaction = {
29
- amount: new bignumber_js_1.default(100),
30
- useAllAmount: false,
31
- subAccountId: "id",
32
- recipient: "0x997e135e96114c0E84FFc58754552368E4abf329",
33
- feesStrategy: "custom",
34
- family: "evm",
35
- mode: "unknown mode",
36
- nonce: 0,
37
- gasLimit: new bignumber_js_1.default(21000),
38
- chainId: 1,
39
- maxFeePerGas: new bignumber_js_1.default(100),
40
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
41
- type: 2,
42
- };
778
+ const coinTransaction = Object.assign(Object.assign({}, baseTransaction), { amount: new bignumber_js_1.default(100), mode: "unknown mode" });
43
779
  const status = yield (0, getTransactionStatus_1.default)(account, coinTransaction);
44
780
  expect((0, deviceTransactionConfig_1.default)({
45
781
  account,
@@ -61,287 +797,6 @@ describe("EVM Family", () => {
61
797
  { type: "fees", label: "Max fees" },
62
798
  ]);
63
799
  }));
64
- it("should return the right fields and infos for a coin transaction mode 'send'", () => __awaiter(void 0, void 0, void 0, function* () {
65
- const coinTransaction = {
66
- amount: new bignumber_js_1.default(100),
67
- useAllAmount: false,
68
- subAccountId: "id",
69
- recipient: "0x997e135e96114c0E84FFc58754552368E4abf329",
70
- feesStrategy: "custom",
71
- family: "evm",
72
- mode: "send",
73
- nonce: 0,
74
- gasLimit: new bignumber_js_1.default(21000),
75
- chainId: 1,
76
- maxFeePerGas: new bignumber_js_1.default(100),
77
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
78
- type: 2,
79
- };
80
- const status = yield (0, getTransactionStatus_1.default)(account, coinTransaction);
81
- expect((0, deviceTransactionConfig_1.default)({
82
- account,
83
- parentAccount: undefined,
84
- transaction: coinTransaction,
85
- status,
86
- })).toEqual([
87
- { type: "amount", label: "Amount" },
88
- {
89
- type: "address",
90
- label: "Address",
91
- address: coinTransaction.recipient,
92
- },
93
- {
94
- type: "text",
95
- label: "Network",
96
- value: currency.name.replace("Lite", "").trim(),
97
- },
98
- { type: "fees", label: "Max fees" },
99
- ]);
100
- }));
101
- it("should return the right fields and infos for a coin transaction mode 'send' with domain", () => __awaiter(void 0, void 0, void 0, function* () {
102
- var _a;
103
- const coinTransaction = {
104
- amount: new bignumber_js_1.default(100),
105
- useAllAmount: false,
106
- subAccountId: "id",
107
- recipient: "0x997e135e96114c0E84FFc58754552368E4abf329",
108
- feesStrategy: "custom",
109
- family: "evm",
110
- mode: "send",
111
- nonce: 0,
112
- gasLimit: new bignumber_js_1.default(21000),
113
- chainId: 1,
114
- maxFeePerGas: new bignumber_js_1.default(100),
115
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
116
- type: 2,
117
- recipientDomain: {
118
- address: "0x123",
119
- domain: "vitalik.eth",
120
- registry: "ens",
121
- type: "forward",
122
- },
123
- };
124
- const status = yield (0, getTransactionStatus_1.default)(account, coinTransaction);
125
- expect((0, deviceTransactionConfig_1.default)({
126
- account,
127
- parentAccount: undefined,
128
- transaction: coinTransaction,
129
- status,
130
- })).toEqual([
131
- { type: "amount", label: "Amount" },
132
- {
133
- type: "text",
134
- label: "Domain",
135
- value: (_a = coinTransaction.recipientDomain) === null || _a === void 0 ? void 0 : _a.domain,
136
- },
137
- {
138
- type: "text",
139
- label: "Network",
140
- value: currency.name.replace("Lite", "").trim(),
141
- },
142
- { type: "fees", label: "Max fees" },
143
- ]);
144
- }));
145
- it("should return the right fields and infos for a token transaction mode 'send'", () => __awaiter(void 0, void 0, void 0, function* () {
146
- const tokenTransaction = {
147
- amount: new bignumber_js_1.default(100),
148
- useAllAmount: false,
149
- subAccountId: tokenAccount.id,
150
- recipient: "0x997e135e96114c0E84FFc58754552368E4abf329",
151
- data: Buffer.from("a9059cbb00000000000000000000000059569e96d0e3d9728dc07bf5c1443809e6f237fd0000000000000000000000000000000000000000000000000c06701668d322ac", "hex"),
152
- feesStrategy: "custom",
153
- family: "evm",
154
- mode: "send",
155
- nonce: 0,
156
- gasLimit: new bignumber_js_1.default(21000),
157
- chainId: 1,
158
- maxFeePerGas: new bignumber_js_1.default(100),
159
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
160
- type: 2,
161
- };
162
- const status = yield (0, getTransactionStatus_1.default)(account, tokenTransaction);
163
- expect((0, deviceTransactionConfig_1.default)({
164
- account: tokenAccount,
165
- parentAccount: account,
166
- transaction: tokenTransaction,
167
- status,
168
- })).toEqual([
169
- { type: "amount", label: "Amount" },
170
- {
171
- type: "address",
172
- label: "Address",
173
- address: tokenTransaction.recipient,
174
- },
175
- {
176
- type: "text",
177
- label: "Network",
178
- value: currency.name.replace("Lite", "").trim(),
179
- },
180
- { type: "fees", label: "Max fees" },
181
- ]);
182
- }));
183
- it("should return the right fields and infos for a token transaction mode 'send' with domain", () => __awaiter(void 0, void 0, void 0, function* () {
184
- var _b;
185
- const tokenTransaction = {
186
- amount: new bignumber_js_1.default(100),
187
- useAllAmount: false,
188
- subAccountId: tokenAccount.id,
189
- recipient: "0x997e135e96114c0E84FFc58754552368E4abf329",
190
- data: Buffer.from("a9059cbb00000000000000000000000059569e96d0e3d9728dc07bf5c1443809e6f237fd0000000000000000000000000000000000000000000000000c06701668d322ac", "hex"),
191
- feesStrategy: "custom",
192
- family: "evm",
193
- mode: "send",
194
- nonce: 0,
195
- gasLimit: new bignumber_js_1.default(21000),
196
- chainId: 1,
197
- maxFeePerGas: new bignumber_js_1.default(100),
198
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
199
- type: 2,
200
- recipientDomain: {
201
- address: "0x123",
202
- domain: "vitalik.eth",
203
- registry: "ens",
204
- type: "forward",
205
- },
206
- };
207
- const status = yield (0, getTransactionStatus_1.default)(account, tokenTransaction);
208
- expect((0, deviceTransactionConfig_1.default)({
209
- account: tokenAccount,
210
- parentAccount: account,
211
- transaction: tokenTransaction,
212
- status,
213
- })).toEqual([
214
- { type: "amount", label: "Amount" },
215
- {
216
- type: "text",
217
- label: "Domain",
218
- value: (_b = tokenTransaction.recipientDomain) === null || _b === void 0 ? void 0 : _b.domain,
219
- },
220
- {
221
- type: "text",
222
- label: "Network",
223
- value: currency.name.replace("Lite", "").trim(),
224
- },
225
- { type: "fees", label: "Max fees" },
226
- ]);
227
- }));
228
- it("should return the right fields and infos for an NFT transaction mode 'erc721'", () => __awaiter(void 0, void 0, void 0, function* () {
229
- const nftTransaction = {
230
- family: "evm",
231
- mode: "erc721",
232
- amount: new bignumber_js_1.default(0),
233
- useAllAmount: false,
234
- recipient: "0x8E9eDe486d8208705C67095dd0b4839dEB127132",
235
- feesStrategy: "custom",
236
- nonce: 0,
237
- gasLimit: new bignumber_js_1.default(21000),
238
- chainId: 1,
239
- nft: {
240
- contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
241
- tokenId: "1",
242
- quantity: new bignumber_js_1.default(1),
243
- collectionName: "BAYC",
244
- },
245
- maxFeePerGas: new bignumber_js_1.default(100),
246
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
247
- type: 2,
248
- };
249
- const status = yield (0, getTransactionStatus_1.default)(account, nftTransaction);
250
- expect((0, deviceTransactionConfig_1.default)({
251
- account: tokenAccount,
252
- parentAccount: account,
253
- transaction: nftTransaction,
254
- status,
255
- })).toEqual([
256
- {
257
- type: "text",
258
- label: "Type",
259
- value: `NFT Transfer`,
260
- },
261
- {
262
- type: "text",
263
- label: "To",
264
- value: nftTransaction.recipient,
265
- },
266
- {
267
- type: "text",
268
- label: "Collection Name",
269
- value: nftTransaction.nft.collectionName,
270
- },
271
- {
272
- type: "address",
273
- label: "NFT Address",
274
- address: nftTransaction.nft.contract,
275
- },
276
- {
277
- type: "text",
278
- label: "NFT ID",
279
- value: nftTransaction.nft.tokenId,
280
- },
281
- { type: "fees", label: "Max fees" },
282
- ]);
283
- }));
284
- it("should return the right fields and infos for an NFT transaction mode 'erc1155'", () => __awaiter(void 0, void 0, void 0, function* () {
285
- const nftTransaction = {
286
- family: "evm",
287
- mode: "erc1155",
288
- amount: new bignumber_js_1.default(0),
289
- useAllAmount: false,
290
- recipient: "0x8E9eDe486d8208705C67095dd0b4839dEB127132",
291
- feesStrategy: "custom",
292
- nonce: 0,
293
- gasLimit: new bignumber_js_1.default(21000),
294
- chainId: 1,
295
- nft: {
296
- contract: "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
297
- tokenId: "1",
298
- quantity: new bignumber_js_1.default(10),
299
- collectionName: "BAYC",
300
- },
301
- maxFeePerGas: new bignumber_js_1.default(100),
302
- maxPriorityFeePerGas: new bignumber_js_1.default(100),
303
- type: 2,
304
- };
305
- const status = yield (0, getTransactionStatus_1.default)(account, nftTransaction);
306
- expect((0, deviceTransactionConfig_1.default)({
307
- account: tokenAccount,
308
- parentAccount: account,
309
- transaction: nftTransaction,
310
- status,
311
- })).toEqual([
312
- {
313
- type: "text",
314
- label: "Type",
315
- value: `NFT Transfer`,
316
- },
317
- {
318
- type: "text",
319
- label: "To",
320
- value: nftTransaction.recipient,
321
- },
322
- {
323
- type: "text",
324
- label: "Collection Name",
325
- value: nftTransaction.nft.collectionName,
326
- },
327
- {
328
- type: "text",
329
- label: "Quantity",
330
- value: nftTransaction.nft.quantity.toFixed(),
331
- },
332
- {
333
- type: "address",
334
- label: "NFT Address",
335
- address: nftTransaction.nft.contract,
336
- },
337
- {
338
- type: "text",
339
- label: "NFT ID",
340
- value: nftTransaction.nft.tokenId,
341
- },
342
- { type: "fees", label: "Max fees" },
343
- ]);
344
- }));
345
800
  });
346
801
  });
347
802
  });