Skip to content

Commit

Permalink
feat(@ethereumjs): update eth libs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Nov 11, 2023
1 parent de5c922 commit e063fb5
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 39 deletions.
4 changes: 1 addition & 3 deletions packages/suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"test-unit:watch": "jest -o --watch"
},
"dependencies": {
"@ethereumjs/common": "^3.1.2",
"@ethereumjs/tx": "^4.1.2",
"@ethereumjs/util": "^9.0.1",
"@formatjs/intl": "2.9.6",
"@hookform/resolvers": "3.1.0",
"@reduxjs/toolkit": "1.9.5",
Expand Down Expand Up @@ -71,7 +70,6 @@
"bs58check": "^3.0.1",
"date-fns": "^2.30.0",
"dropbox": "^10.34.0",
"ethereumjs-util": "^7.1.5",
"file-saver": "^2.0.5",
"framer-motion": "^10.16.4",
"history": "^4.10.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useState } from 'react';
import styled from 'styled-components';
import { isValidChecksumAddress, toChecksumAddress } from 'ethereumjs-util';
import { isValidChecksumAddress, toChecksumAddress } from '@ethereumjs/util';
import { capitalizeFirstLetter } from '@trezor/utils';
import { Input, useTheme, Icon, Button, Tooltip } from '@trezor/components';
import { AddressLabeling, Translation, MetadataLabeling } from 'src/components/suite';
Expand Down
8 changes: 4 additions & 4 deletions suite-common/wallet-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"test-unit:watch": "jest -o --watch"
},
"dependencies": {
"@ethereumjs/common": "^3.1.2",
"@ethereumjs/tx": "^4.1.2",
"@ethereumjs/common": "^4.1.0",
"@ethereumjs/tx": "^5.1.0",
"@ethereumjs/util": "^9.0.1",
"@suite-common/fiat-services": "workspace:*",
"@suite-common/metadata-types": "workspace:*",
"@suite-common/suite-config": "workspace:*",
Expand All @@ -29,7 +30,6 @@
"@trezor/utils": "workspace:*",
"bignumber.js": "^9.1.1",
"date-fns": "^2.30.0",
"ethereumjs-util": "^7.1.5",
"pdfmake": "^0.2.7",
"react": "18.2.0",
"react-hook-form": "^7.48.2",
Expand All @@ -38,7 +38,7 @@
},
"devDependencies": {
"@types/pdfmake": "^0.2.8",
"jest": "^26.6.3",
"jest": "29.5.0",
"typescript": "4.9.5"
}
}
6 changes: 3 additions & 3 deletions suite-common/wallet-utils/src/__tests__/sendFormUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Transaction } from '@ethereumjs/tx';
import { TransactionFactory } from '@ethereumjs/tx';
import { sha3 } from 'web3-utils';

import { networksCompatibility as NETWORKS } from '@suite-common/wallet-config';
Expand Down Expand Up @@ -35,8 +35,8 @@ describe('sendForm utils', () => {
// verify hash using 2 different tools
if (f.tx.chainId !== 61) {
// ETC is not supported
const tx = Transaction.fromTxData(f.tx);
const hash1 = tx.hash().toString('hex');
const tx = TransactionFactory.fromTxData(f.tx);
const hash1 = Buffer.from(tx.hash()).toString('hex');
expect(`0x${hash1}`).toEqual(f.result);
}
const serialized = serializeEthereumTx(f.tx);
Expand Down
6 changes: 3 additions & 3 deletions suite-common/wallet-utils/src/ethUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as EthereumjsUtil from 'ethereumjs-util';
import { isValidChecksumAddress, isValidAddress } from '@ethereumjs/util';
import BigNumber from 'bignumber.js';

import { hasUppercaseLetter } from '@trezor/utils';
Expand Down Expand Up @@ -29,10 +29,10 @@ export const validateAddress = (address: string): string | null => {
if (address.length < 1) {
return 'Address is not set';
}
if (!EthereumjsUtil.isValidAddress(address)) {
if (!isValidAddress(address)) {
return 'Address is not valid';
}
if (hasUppercaseLetter(address) && !EthereumjsUtil.isValidChecksumAddress(address)) {
if (hasUppercaseLetter(address) && !isValidChecksumAddress(address)) {
return 'Address is not a valid checksum';
}
return null;
Expand Down
9 changes: 5 additions & 4 deletions suite-common/wallet-utils/src/sendFormUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {

import BigNumber from 'bignumber.js';
import { Common, Chain, Hardfork } from '@ethereumjs/common';
import { Transaction, TxData } from '@ethereumjs/tx';
import { LegacyTxData, TransactionFactory } from '@ethereumjs/tx';
import { fromWei, padLeft, toHex, toWei } from 'web3-utils';

import { fiatCurrencies } from '@suite-common/suite-config';
Expand Down Expand Up @@ -148,7 +148,7 @@ export const prepareEthereumTransaction = (txInfo: EthTransactionData) => {
return result;
};

export const serializeEthereumTx = (tx: TxData & EthereumTransaction) => {
export const serializeEthereumTx = (tx: LegacyTxData & EthereumTransaction) => {
// @ethereumjs/tx doesn't support ETC (chain 61) by default
// and it needs to be declared as custom chain
// see: https://github.com/ethereumjs/ethereumjs-tx/blob/master/examples/custom-chain-tx.ts
Expand All @@ -168,8 +168,9 @@ export const serializeEthereumTx = (tx: TxData & EthereumTransaction) => {
chain: tx.chainId,
};

const ethTx = new Transaction(tx, options);
return `0x${ethTx.serialize().toString('hex')}`;
const ethTx = TransactionFactory.fromTxData(tx, options);
const hexEthTx = Buffer.from(ethTx.serialize()).toString('hex');
return `0x${hexEthTx}`;
};

export const getFeeLevels = (networkType: Network['networkType'], feeInfo: FeeInfo) => {
Expand Down
103 changes: 82 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.1.6, @babel/traverse@npm:^7.16.0, @babel/traverse@npm:^7.20.0, @babel/traverse@npm:^7.22.8, @babel/traverse@npm:^7.23.2, @babel/traverse@npm:^7.4.5":
"@babel/traverse@npm:^7.1.0, @babel/traverse@npm:^7.1.6, @babel/traverse@npm:^7.16.0, @babel/traverse@npm:^7.20.0, @babel/traverse@npm:^7.22.8, @babel/traverse@npm:^7.23.2, @babel/traverse@npm:^7.4.5, @babel/traverse@npm:^7.7.2":
version: 7.23.2
resolution: "@babel/traverse@npm:7.23.2"
dependencies:
Expand Down Expand Up @@ -2557,7 +2557,7 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/common@npm:^3.1.2, @ethereumjs/common@npm:^3.2.0":
"@ethereumjs/common@npm:^3.2.0":
version: 3.2.0
resolution: "@ethereumjs/common@npm:3.2.0"
dependencies:
Expand All @@ -2567,6 +2567,16 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/common@npm:^4.1.0":
version: 4.1.0
resolution: "@ethereumjs/common@npm:4.1.0"
dependencies:
"@ethereumjs/util": ^9.0.1
crc: ^4.3.2
checksum: 8494e6d179fe3949d8d8285badfb7be9ade71864e477da5dbf432ecc8046a58a0db73e99b5543c807fdc1b3f5959ed9c85ba99536b2f4753e08eaeb096af4beb
languageName: node
linkType: hard

"@ethereumjs/rlp@npm:^4.0.1":
version: 4.0.1
resolution: "@ethereumjs/rlp@npm:4.0.1"
Expand All @@ -2576,7 +2586,16 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/tx@npm:^4.1.2, @ethereumjs/tx@npm:^4.2.0":
"@ethereumjs/rlp@npm:^5.0.1":
version: 5.0.1
resolution: "@ethereumjs/rlp@npm:5.0.1"
bin:
rlp: bin/rlp.cjs
checksum: eddff08718c3b8312007ef51a951dff6b2c1152f9f9ea6fb9eec65d50caf3fa53f5894d79d6d450eef70a5ef3b0688be044912096aa8d263345a0d9debb4d477
languageName: node
linkType: hard

"@ethereumjs/tx@npm:^4.2.0":
version: 4.2.0
resolution: "@ethereumjs/tx@npm:4.2.0"
dependencies:
Expand All @@ -2588,6 +2607,23 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/tx@npm:^5.1.0":
version: 5.1.0
resolution: "@ethereumjs/tx@npm:5.1.0"
dependencies:
"@ethereumjs/common": ^4.1.0
"@ethereumjs/rlp": ^5.0.1
"@ethereumjs/util": ^9.0.1
ethereum-cryptography: ^2.1.2
peerDependencies:
c-kzg: ^2.1.2
peerDependenciesMeta:
c-kzg:
optional: true
checksum: fd17b337f7a64a6a29b1d279c52ac5bfb9655cda06858b198b85a306cc978d25b871acc4ec57e0c29bab50a7c9600d934837fb62052cbde7dc88223be7ebc740
languageName: node
linkType: hard

"@ethereumjs/util@npm:^8.1.0":
version: 8.1.0
resolution: "@ethereumjs/util@npm:8.1.0"
Expand All @@ -2599,6 +2635,21 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/util@npm:^9.0.1":
version: 9.0.1
resolution: "@ethereumjs/util@npm:9.0.1"
dependencies:
"@ethereumjs/rlp": ^5.0.1
ethereum-cryptography: ^2.1.2
peerDependencies:
c-kzg: ^2.1.2
peerDependenciesMeta:
c-kzg:
optional: true
checksum: 3569dcc0106f5e962e62811be66b5f49529c9d1a29671908568528b2b45d6cae03cb497fc755a1ae4144170f749133308494be42255ac98b61c930d143ed26f4
languageName: node
linkType: hard

"@expo/bunyan@npm:4.0.0, @expo/bunyan@npm:^4.0.0":
version: 4.0.0
resolution: "@expo/bunyan@npm:4.0.0"
Expand Down Expand Up @@ -4042,7 +4093,7 @@ __metadata:
languageName: node
linkType: hard

"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.18, @jridgewell/trace-mapping@npm:^0.3.9":
"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.15, @jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.18, @jridgewell/trace-mapping@npm:^0.3.9":
version: 0.3.20
resolution: "@jridgewell/trace-mapping@npm:0.3.20"
dependencies:
Expand Down Expand Up @@ -7128,7 +7179,7 @@ __metadata:
"@trezor/utils": "workspace:*"
dropbox: ^10.34.0
fake-indexeddb: ^4.0.2
jest: 29.5.0
jest: ^26.6.3
redux: ^4.2.1
redux-thunk: ^2.4.2
typescript: 4.9.5
Expand Down Expand Up @@ -7230,8 +7281,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@suite-common/wallet-utils@workspace:suite-common/wallet-utils"
dependencies:
"@ethereumjs/common": ^3.1.2
"@ethereumjs/tx": ^4.1.2
"@ethereumjs/common": ^4.1.0
"@ethereumjs/tx": ^5.1.0
"@ethereumjs/util": ^9.0.1
"@suite-common/fiat-services": "workspace:*"
"@suite-common/metadata-types": "workspace:*"
"@suite-common/suite-config": "workspace:*"
Expand All @@ -7248,8 +7300,7 @@ __metadata:
"@types/pdfmake": ^0.2.8
bignumber.js: ^9.1.1
date-fns: ^2.30.0
ethereumjs-util: ^7.1.5
jest: ^26.6.3
jest: 29.5.0
pdfmake: ^0.2.7
react: 18.2.0
react-hook-form: ^7.48.2
Expand Down Expand Up @@ -9454,8 +9505,7 @@ __metadata:
resolution: "@trezor/suite@workspace:packages/suite"
dependencies:
"@crowdin/cli": ^3.15.0
"@ethereumjs/common": ^3.1.2
"@ethereumjs/tx": ^4.1.2
"@ethereumjs/util": ^9.0.1
"@formatjs/cli": ^6.2.1
"@formatjs/intl": 2.9.6
"@hookform/resolvers": 3.1.0
Expand Down Expand Up @@ -9527,7 +9577,6 @@ __metadata:
bs58check: ^3.0.1
date-fns: ^2.30.0
dropbox: ^10.34.0
ethereumjs-util: ^7.1.5
file-saver: ^2.0.5
framer-motion: ^10.16.4
history: ^4.10.1
Expand Down Expand Up @@ -10712,7 +10761,7 @@ __metadata:
languageName: node
linkType: hard

"@types/prettier@npm:^2.0.0, @types/prettier@npm:^2.6.1":
"@types/prettier@npm:^2.0.0, @types/prettier@npm:^2.1.5, @types/prettier@npm:^2.6.1":
version: 2.7.3
resolution: "@types/prettier@npm:2.7.3"
checksum: 705384209cea6d1433ff6c187c80dcc0b95d99d5c5ce21a46a9a58060c527973506822e428789d842761e0280d25e3359300f017fbe77b9755bc772ab3dc2f83
Expand Down Expand Up @@ -15117,6 +15166,18 @@ __metadata:
languageName: node
linkType: hard

"crc@npm:^4.3.2":
version: 4.3.2
resolution: "crc@npm:4.3.2"
peerDependencies:
buffer: ">=6.0.3"
peerDependenciesMeta:
buffer:
optional: true
checksum: 8231cc25331727083ffd22da3575110fc49b4dc8725de973bd43261d4426aba134ed3a75cc247f7c5e97a6e171f87dffc3325b82890e86d032de2e6bcef09c32
languageName: node
linkType: hard

"create-ecdh@npm:^4.0.0":
version: 4.0.4
resolution: "create-ecdh@npm:4.0.4"
Expand Down Expand Up @@ -18045,7 +18106,7 @@ __metadata:
languageName: node
linkType: hard

"ethereumjs-util@npm:^7.1.0, ethereumjs-util@npm:^7.1.5":
"ethereumjs-util@npm:^7.1.0":
version: 7.1.5
resolution: "ethereumjs-util@npm:7.1.5"
dependencies:
Expand Down Expand Up @@ -21980,7 +22041,7 @@ __metadata:
languageName: node
linkType: hard

"istanbul-lib-instrument@npm:^5.0.4":
"istanbul-lib-instrument@npm:^5.0.4, istanbul-lib-instrument@npm:^5.1.0":
version: 5.2.1
resolution: "istanbul-lib-instrument@npm:5.2.1"
dependencies:
Expand Down Expand Up @@ -22272,7 +22333,7 @@ __metadata:
languageName: node
linkType: hard

"jest-diff@npm:^29.4.1, jest-diff@npm:^29.7.0":
"jest-diff@npm:^29.4.1, jest-diff@npm:^29.5.0, jest-diff@npm:^29.7.0":
version: 29.7.0
resolution: "jest-diff@npm:29.7.0"
dependencies:
Expand Down Expand Up @@ -22441,7 +22502,7 @@ __metadata:
languageName: node
linkType: hard

"jest-get-type@npm:^29.6.3":
"jest-get-type@npm:^29.4.3, jest-get-type@npm:^29.6.3":
version: 29.6.3
resolution: "jest-get-type@npm:29.6.3"
checksum: 88ac9102d4679d768accae29f1e75f592b760b44277df288ad76ce5bf038c3f5ce3719dea8aa0f035dac30e9eb034b848ce716b9183ad7cc222d029f03e92205
Expand Down Expand Up @@ -22573,7 +22634,7 @@ __metadata:
languageName: node
linkType: hard

"jest-matcher-utils@npm:^29.7.0":
"jest-matcher-utils@npm:^29.5.0, jest-matcher-utils@npm:^29.7.0":
version: 29.7.0
resolution: "jest-matcher-utils@npm:29.7.0"
dependencies:
Expand Down Expand Up @@ -22619,7 +22680,7 @@ __metadata:
languageName: node
linkType: hard

"jest-message-util@npm:^29.7.0":
"jest-message-util@npm:^29.5.0, jest-message-util@npm:^29.6.2, jest-message-util@npm:^29.7.0":
version: 29.7.0
resolution: "jest-message-util@npm:29.7.0"
dependencies:
Expand Down Expand Up @@ -22971,7 +23032,7 @@ __metadata:
languageName: node
linkType: hard

"jest-util@npm:^29.0.0, jest-util@npm:^29.6.2, jest-util@npm:^29.7.0":
"jest-util@npm:^29.0.0, jest-util@npm:^29.5.0, jest-util@npm:^29.6.2, jest-util@npm:^29.7.0":
version: 29.7.0
resolution: "jest-util@npm:29.7.0"
dependencies:
Expand Down Expand Up @@ -28367,7 +28428,7 @@ __metadata:
languageName: node
linkType: hard

"pretty-format@npm:^29.0.0, pretty-format@npm:^29.0.3, pretty-format@npm:^29.7.0":
"pretty-format@npm:^29.0.0, pretty-format@npm:^29.0.3, pretty-format@npm:^29.5.0, pretty-format@npm:^29.7.0":
version: 29.7.0
resolution: "pretty-format@npm:29.7.0"
dependencies:
Expand Down

0 comments on commit e063fb5

Please sign in to comment.