diff --git a/packages/extension/package.json b/packages/extension/package.json index aa24fc716..b442306d8 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -30,6 +30,7 @@ "@enkryptcom/utils": "workspace:^", "@ethereumjs/common": "^4.2.0", "@ethereumjs/tx": "^5.2.1", + "@ethereumjs/util": "^9.0.2", "@ledgerhq/hw-transport-webusb": "^6.28.4", "@metamask/eth-sig-util": "^7.0.1", "@rollup/plugin-replace": "^5.0.5", @@ -47,8 +48,8 @@ "concurrently": "^8.2.2", "core-js": "^3.36.0", "echarts": "^5.5.0", + "ethereum-cryptography": "^2.1.3", "ethereumjs-abi": "^0.6.8", - "ethereumjs-util": "^7.1.5", "ethereumjs-wallet": "^1.0.2", "eventemitter3": "^5.0.1", "lodash": "^4.17.21", diff --git a/packages/extension/src/providers/bitcoin/libs/bip322-message-sign.ts b/packages/extension/src/providers/bitcoin/libs/bip322-message-sign.ts index f8deb7431..c9d1dc783 100644 --- a/packages/extension/src/providers/bitcoin/libs/bip322-message-sign.ts +++ b/packages/extension/src/providers/bitcoin/libs/bip322-message-sign.ts @@ -5,8 +5,9 @@ import { BitcoinNetwork, PaymentType } from "../types/bitcoin-network"; import { address as BTCAddress, Transaction, Psbt } from "bitcoinjs-lib"; -import { sha256 } from "ethereumjs-util"; +import { sha256 } from "ethereum-cryptography/sha256"; import { PSBTSigner } from "../ui/libs/signer"; +import { bufferToHex } from "@enkryptcom/utils"; const bip0322_hash = (message: string) => { const tag = "BIP0322-signed-message"; @@ -14,7 +15,7 @@ const bip0322_hash = (message: string) => { const result = sha256( Buffer.concat([tagHash, tagHash, Buffer.from(message)]) ); - return result.toString("hex"); + return bufferToHex(result, true); }; const MAX_SAFE_INTEGER = 9007199254740991; diff --git a/packages/extension/src/providers/bitcoin/libs/sign-message-utils.ts b/packages/extension/src/providers/bitcoin/libs/sign-message-utils.ts index 1f2a86ee4..465a40a39 100644 --- a/packages/extension/src/providers/bitcoin/libs/sign-message-utils.ts +++ b/packages/extension/src/providers/bitcoin/libs/sign-message-utils.ts @@ -1,4 +1,4 @@ -import { sha256 } from "ethereumjs-util"; +import { sha256 } from "ethereum-cryptography/sha256"; const MAGIC_BYTES = Buffer.from("Bitcoin Signed Message:\n"); @@ -28,7 +28,7 @@ export const magicHash = (messageBuffer: Buffer) => { const prefix1 = varintBufNum(MAGIC_BYTES.length); const prefix2 = varintBufNum(messageBuffer.length); const buf = Buffer.concat([prefix1, MAGIC_BYTES, prefix2, messageBuffer]); - return sha256(sha256(buf)); + return Buffer.from(sha256(sha256(buf))); }; export const toCompact = ( diff --git a/packages/extension/src/providers/bitcoin/ui/btc-verify-transaction.vue b/packages/extension/src/providers/bitcoin/ui/btc-verify-transaction.vue index e06e5e0d6..5ea9e0382 100644 --- a/packages/extension/src/providers/bitcoin/ui/btc-verify-transaction.vue +++ b/packages/extension/src/providers/bitcoin/ui/btc-verify-transaction.vue @@ -126,7 +126,7 @@ import { getError } from "@/libs/error"; import { ErrorCodes } from "@/providers/ethereum/types"; import { WindowPromiseHandler } from "@/libs/window-promise"; import { DEFAULT_BTC_NETWORK, getNetworkByName } from "@/libs/utils/networks"; -import { fromBase, hexToBuffer } from "@enkryptcom/utils"; +import { fromBase, hexToBuffer, bufferToHex } from "@enkryptcom/utils"; import { ProviderRequestOptions } from "@/types/provider"; import { GasFeeType } from "./types"; import MarketData from "@/libs/market-data"; @@ -141,7 +141,6 @@ import { toBN } from "web3-utils"; import { Psbt } from "bitcoinjs-lib"; import BigNumber from "bignumber.js"; import { JsonTreeView } from "@/libs/json-tree-view"; -import { bufferToHex } from "ethereumjs-util"; const isProcessing = ref(false); const isPreLoading = ref(true); diff --git a/packages/extension/src/providers/bitcoin/ui/libs/signer.ts b/packages/extension/src/providers/bitcoin/ui/libs/signer.ts index bd64c3511..161fdc71d 100644 --- a/packages/extension/src/providers/bitcoin/ui/libs/signer.ts +++ b/packages/extension/src/providers/bitcoin/ui/libs/signer.ts @@ -1,8 +1,7 @@ import { InternalMethods, InternalOnMessageResponse } from "@/types/messenger"; import { SignerTransactionOptions, SignerMessageOptions } from "../types"; -import { bufferToHex } from "ethereumjs-util"; import sendUsingInternalMessengers from "@/libs/messenger/internal-messenger"; -import { hexToBuffer } from "@enkryptcom/utils"; +import { hexToBuffer, bufferToHex } from "@enkryptcom/utils"; import { Psbt } from "bitcoinjs-lib"; import { BitcoinNetwork, PaymentType } from "../../types/bitcoin-network"; import { EnkryptAccount } from "@enkryptcom/types"; diff --git a/packages/extension/src/providers/common/types/index.ts b/packages/extension/src/providers/common/types/index.ts index 328d26d53..591d6a8a9 100644 --- a/packages/extension/src/providers/common/types/index.ts +++ b/packages/extension/src/providers/common/types/index.ts @@ -1,3 +1,5 @@ +import type { toBN } from "web3-utils"; + export interface GasFeeInfo { nativeValue: string; fiatValue: string; @@ -16,3 +18,5 @@ export interface GasFeeType { [GasPriceTypes.FAST]: GasFeeInfo; [GasPriceTypes.FASTEST]: GasFeeInfo; } + +export type BNType = ReturnType; diff --git a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts index 9326670eb..edc8c7510 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/gas-utils.ts @@ -1,7 +1,6 @@ import BigNumber from "bignumber.js"; -import { BN } from "ethereumjs-util"; import { toBN, toWei } from "web3-utils"; -import { GasPriceTypes } from "@/providers/common/types"; +import { BNType, GasPriceTypes } from "@/providers/common/types"; import { FeeHistoryResult } from "web3-eth"; import { FormattedFeeHistory } from "./types"; @@ -14,10 +13,10 @@ const FASTEST_MULTIPLIER = 1.21828571429; const LIMITER = 25000000000; const GAS_PERCENTILES = [25, 50, 75, 90]; -const getEconomy = (gasPrice: string): BN => { +const getEconomy = (gasPrice: string): BNType => { return toBN(gasPrice); }; -const getRegular = (gasPrice: string): BN => { +const getRegular = (gasPrice: string): BNType => { const gpBN = toBN(gasPrice); if (gpBN.gt(toBN(LIMITER))) { let initialValue = new BigNumber(gasPrice).times(MED_MULTIPLIER); @@ -26,7 +25,7 @@ const getRegular = (gasPrice: string): BN => { } return toBN(new BigNumber(gasPrice).times(1.25).toFixed(0)); }; -const getFast = (gasPrice: string): BN => { +const getFast = (gasPrice: string): BNType => { const gpBN = toBN(gasPrice); if (gpBN.gt(toBN(LIMITER))) { let initialValue = new BigNumber(gasPrice).times(FAST_MULTIPLIER); @@ -35,7 +34,7 @@ const getFast = (gasPrice: string): BN => { } return toBN(new BigNumber(gasPrice).times(1.5).toFixed(0)); }; -const getFastest = (gasPrice: string): BN => { +const getFastest = (gasPrice: string): BNType => { const gpBN = toBN(gasPrice); if (gpBN.gt(toBN(LIMITER))) { let initialValue = new BigNumber(gasPrice).times(FASTEST_MULTIPLIER); @@ -48,7 +47,7 @@ const getFastest = (gasPrice: string): BN => { const getGasBasedOnType = ( gasPrice: string, gasPriceType: GasPriceTypes -): BN => { +): BNType => { switch (gasPriceType) { case GasPriceTypes.ECONOMY: return getEconomy(gasPrice); @@ -62,10 +61,10 @@ const getGasBasedOnType = ( return getEconomy(gasPrice); } }; -const getMinPriorityFee = (): BN => { +const getMinPriorityFee = (): BNType => { return toBN(toWei("0.1", "gwei")); }; -const getPriorityFeeAvg = (arr: BN[]): BN => { +const getPriorityFeeAvg = (arr: BNType[]): BNType => { const sum = arr.reduce((a, v) => a.add(v)); const fee = sum.divn(arr.length); if (fee.eqn(0)) return getMinPriorityFee(); @@ -75,7 +74,7 @@ const getPriorityFeeAvg = (arr: BN[]): BN => { const getPriorityFeeBasedOnType = ( gasFeeHistory: FormattedFeeHistory, gasPriceType: GasPriceTypes -): BN => { +): BNType => { if (gasFeeHistory.blocks.length === 0) return getMinPriorityFee(); switch (gasPriceType) { case GasPriceTypes.ECONOMY: @@ -141,7 +140,7 @@ const formatFeeHistory = ( const getBaseFeeBasedOnType = ( baseFee: string, gasPriceType: GasPriceTypes -): BN => { +): BNType => { const baseFeeBN = toBN(baseFee); switch (gasPriceType) { case GasPriceTypes.ECONOMY: diff --git a/packages/extension/src/providers/ethereum/libs/transaction/types.ts b/packages/extension/src/providers/ethereum/libs/transaction/types.ts index b911706dd..4cf00b52d 100644 --- a/packages/extension/src/providers/ethereum/libs/transaction/types.ts +++ b/packages/extension/src/providers/ethereum/libs/transaction/types.ts @@ -1,5 +1,5 @@ import { GasPriceTypes } from "@/providers/common/types"; -import { BN } from "ethereumjs-util"; +import { BNType as BN } from "@/providers/common/types"; export interface AccessList { address: `0x${string}`; diff --git a/packages/extension/src/providers/ethereum/methods/personal_ecRecover.ts b/packages/extension/src/providers/ethereum/methods/personal_ecRecover.ts index a6efce8a4..f582869f9 100644 --- a/packages/extension/src/providers/ethereum/methods/personal_ecRecover.ts +++ b/packages/extension/src/providers/ethereum/methods/personal_ecRecover.ts @@ -1,12 +1,12 @@ import { getCustomError } from "@/libs/error"; import { MiddlewareFunction } from "@enkryptcom/types"; -import { hexToBuffer } from "@enkryptcom/utils"; +import { bufferToHex, hexToBuffer } from "@enkryptcom/utils"; import { ecrecover, fromRpcSig, hashPersonalMessage, publicToAddress, -} from "ethereumjs-util"; +} from "@ethereumjs/util"; import EthereumProvider from ".."; const method: MiddlewareFunction = function ( this: EthereumProvider, @@ -23,7 +23,7 @@ const method: MiddlewareFunction = function ( const hashedMessage = hashPersonalMessage(hexToBuffer(payload.params[0])); const { v, r, s } = fromRpcSig(payload.params[1]); const recoveredPubKey = ecrecover(hashedMessage, v, r, s); - return res(null, "0x" + publicToAddress(recoveredPubKey).toString("hex")); + return res(null, bufferToHex(publicToAddress(recoveredPubKey))); } catch (e) { return res(getCustomError((e as Error).message)); } diff --git a/packages/extension/src/providers/ethereum/methods/wallet_watchAsset.ts b/packages/extension/src/providers/ethereum/methods/wallet_watchAsset.ts index 598082db4..74577f588 100644 --- a/packages/extension/src/providers/ethereum/methods/wallet_watchAsset.ts +++ b/packages/extension/src/providers/ethereum/methods/wallet_watchAsset.ts @@ -4,7 +4,7 @@ import MarketData from "@/libs/market-data"; import { CustomErc20Token, TokenType } from "@/libs/tokens-state/types"; import { WindowPromise } from "@/libs/window-promise"; import { MiddlewareFunction } from "@enkryptcom/types"; -import { isValidAddress } from "ethereumjs-util"; +import { isValidAddress } from "@ethereumjs/util"; import EthereumProvider from ".."; import API from "../libs/api"; import { Erc20Token } from "../types/erc20-token"; diff --git a/packages/extension/src/providers/ethereum/networks/rsk.ts b/packages/extension/src/providers/ethereum/networks/rsk.ts index 3661eea3f..36f3e662a 100644 --- a/packages/extension/src/providers/ethereum/networks/rsk.ts +++ b/packages/extension/src/providers/ethereum/networks/rsk.ts @@ -6,7 +6,7 @@ import { toChecksumAddress, isValidChecksumAddress, isValidAddress, -} from "ethereumjs-util"; +} from "@ethereumjs/util"; import assetsInfoHandler from "@/providers/ethereum/libs/assets-handlers/assetinfo-mew"; const rootstockOptions: EvmNetworkOptions = { diff --git a/packages/extension/src/providers/ethereum/tests/ethereum.data.decode.mocha.ts b/packages/extension/src/providers/ethereum/tests/ethereum.data.decode.mocha.ts index 55eef6449..ba1629bbb 100644 --- a/packages/extension/src/providers/ethereum/tests/ethereum.data.decode.mocha.ts +++ b/packages/extension/src/providers/ethereum/tests/ethereum.data.decode.mocha.ts @@ -1,6 +1,6 @@ import DataDecode from "../libs/transaction/data-decoder"; import { expect } from "chai"; -import { BN } from "ethereumjs-util"; +import { toBN } from "web3-utils"; import { numberToHex } from "web3-utils"; describe("Test Ethereum data decoding", () => { it("should decode correct token transfer info", async () => { @@ -15,7 +15,7 @@ describe("Test Ethereum data decoding", () => { "0x92eefc435008af9dfc428e9f84c2a6c0fd385e8f" ); expect(dataDecoder.decode().values[1]).to.eq( - numberToHex(new BN("390343345")) + numberToHex(toBN("390343345")) ); }); it("should not decode unknown data", async () => { diff --git a/packages/extension/src/providers/ethereum/types/erc20-token.ts b/packages/extension/src/providers/ethereum/types/erc20-token.ts index 2c9d03e5e..36cb0718d 100644 --- a/packages/extension/src/providers/ethereum/types/erc20-token.ts +++ b/packages/extension/src/providers/ethereum/types/erc20-token.ts @@ -1,9 +1,9 @@ import { BaseToken, BaseTokenOptions } from "@/types/base-token"; -import { BN } from "ethereumjs-util"; import { numberToHex } from "web3-utils"; import erc20 from "../libs/abi/erc20"; import EvmAPI from "../libs/api"; import { NATIVE_TOKEN_ADDRESS } from "../libs/common"; +import { BNType } from "@/providers/common/types"; export interface Erc20TokenOptions extends BaseTokenOptions { contract: string; @@ -27,7 +27,7 @@ export class Erc20Token extends BaseToken { return contract.methods .balanceOf(address) .call() - .then((val: BN) => { + .then((val: BNType) => { const balance = numberToHex(val); this.balance = balance; return balance; diff --git a/packages/extension/src/providers/ethereum/types/evm-network.ts b/packages/extension/src/providers/ethereum/types/evm-network.ts index 2f461e5e5..5c7030acd 100644 --- a/packages/extension/src/providers/ethereum/types/evm-network.ts +++ b/packages/extension/src/providers/ethereum/types/evm-network.ts @@ -14,12 +14,13 @@ import { NFTCollection } from "@/types/nft"; import { AssetsType, ProviderName } from "@/types/provider"; import { CoingeckoPlatform, NetworkNames, SignerType } from "@enkryptcom/types"; import BigNumber from "bignumber.js"; -import { BNLike, toChecksumAddress } from "ethereumjs-util"; +import { toChecksumAddress } from "@ethereumjs/util"; import { isAddress } from "web3-utils"; import API from "../libs/api"; import createIcon from "../libs/blockies"; import { NATIVE_TOKEN_ADDRESS } from "../libs/common"; import { Erc20Token, Erc20TokenOptions } from "./erc20-token"; +import { BNType } from "@/providers/common/types"; export interface EvmNetworkOptions { name: NetworkNames; @@ -49,8 +50,8 @@ export interface EvmNetworkOptions { address: string ) => Promise; customTokens?: boolean; - displayAddress?: (address: string, chainId?: BNLike) => string; - isAddress?: (address: string, chainId?: BNLike) => boolean; + displayAddress?: (address: string, chainId?: BNType) => string; + isAddress?: (address: string, chainId?: BNType) => boolean; } export class EvmNetwork extends BaseNetwork { @@ -73,7 +74,7 @@ export class EvmNetwork extends BaseNetwork { public assets: Erc20Token[] = []; - public isAddress: (address: string, chainId?: BNLike) => boolean; + public isAddress: (address: string, chainId?: BNType) => boolean; constructor(options: EvmNetworkOptions) { const api = async () => { diff --git a/packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue b/packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue index c1ffb9ddb..932853585 100644 --- a/packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue +++ b/packages/extension/src/providers/ethereum/ui/eth-verify-transaction.vue @@ -150,9 +150,9 @@ import { defaultGasCostVals } from "@/providers/common/libs/default-vals"; import { EnkryptAccount } from "@enkryptcom/types"; import { TransactionSigner } from "./libs/signer"; import { Activity, ActivityStatus, ActivityType } from "@/types/activity"; -import { generateAddress } from "ethereumjs-util"; +import { generateAddress, bigIntToBytes } from "@ethereumjs/util"; import ActivityState from "@/libs/activity-state"; -import { bigIntToBuffer, bigIntToHex, fromBase } from "@enkryptcom/utils"; +import { bigIntToHex, fromBase, bufferToHex } from "@enkryptcom/utils"; import broadcastTx from "../libs/tx-broadcaster"; import TokenSigs from "../libs/transaction/lists/tokenSigs"; import AlertIcon from "@action/icons/send/alert-icon.vue"; @@ -303,10 +303,12 @@ const approve = async () => { from: account.value.address, to: tx.to ? tx.to.toString() - : `0x${generateAddress( - tx.getSenderAddress().toBuffer(), - bigIntToBuffer(tx.nonce) - ).toString("hex")}`, + : bufferToHex( + generateAddress( + tx.getSenderAddress().toBytes(), + bigIntToBytes(tx.nonce) + ) + ), isIncoming: tx.getSenderAddress().toString() === tx.to?.toString(), network: network.value.name, status: ActivityStatus.pending, @@ -345,11 +347,11 @@ const approve = async () => { }); }); }; - broadcastTx("0x" + tx.serialize().toString("hex"), network.value.name) + broadcastTx(bufferToHex(tx.serialize()), network.value.name) .then(onHash) .catch(() => { web3 - .sendSignedTransaction("0x" + tx.serialize().toString("hex")) + .sendSignedTransaction(bufferToHex(tx.serialize())) .on("transactionHash", onHash) .on("error", (error) => { txActivity.status = ActivityStatus.failed; diff --git a/packages/extension/src/providers/ethereum/ui/libs/signer.ts b/packages/extension/src/providers/ethereum/ui/libs/signer.ts index ab3ff2ec6..75ebd2e15 100644 --- a/packages/extension/src/providers/ethereum/ui/libs/signer.ts +++ b/packages/extension/src/providers/ethereum/ui/libs/signer.ts @@ -3,7 +3,7 @@ import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; import { SignerTransactionOptions, SignerMessageOptions } from "../types"; import HWwallet from "@enkryptcom/hw-wallets"; import { HWwalletType } from "@enkryptcom/types"; -import { fromRpcSig, hashPersonalMessage } from "ethereumjs-util"; +import { fromRpcSig, hashPersonalMessage } from "@ethereumjs/util"; import { getCustomError } from "@/libs/error"; import { bufferToHex } from "@enkryptcom/utils"; import sendUsingInternalMessengers from "@/libs/messenger/internal-messenger"; @@ -50,7 +50,7 @@ const TransactionSigner = ( } else { const rpcSig = fromRpcSig(JSON.parse(res.result as string) || "0x"); const signedTx = (payload as FeeMarketEIP1559Transaction).addSignature( - BigInt(rpcSig.v), + rpcSig.v, rpcSig.r, rpcSig.s, true diff --git a/packages/extension/src/providers/polkadot/networks/acala/libs/assetinfo-orml.ts b/packages/extension/src/providers/polkadot/networks/acala/libs/assetinfo-orml.ts index 489a6ef69..5cf194be6 100644 --- a/packages/extension/src/providers/polkadot/networks/acala/libs/assetinfo-orml.ts +++ b/packages/extension/src/providers/polkadot/networks/acala/libs/assetinfo-orml.ts @@ -10,7 +10,7 @@ import { import { toBN } from "web3-utils"; import { KnownTokenDisplay } from "@/providers/polkadot/types"; import { SubstrateNativeToken } from "@/providers/polkadot/types/substrate-native-token"; -import { BN } from "ethereumjs-util"; +import { BNType } from "@/providers/common/types"; type AssetMetadata = { name: `0x${string}`; @@ -105,7 +105,7 @@ export default async ( const ormlOptions: AcalaOrmlAssetOptions = { name: hexToString(asset!.name), symbol: hexToString(asset!.symbol), - existentialDeposit: asset!.minimalBalance as BN, + existentialDeposit: asset!.minimalBalance as BNType, assetType: asset!.assetLookupId, lookupValue: asset!.assetLookupValue, icon: network.icon, diff --git a/packages/extension/src/providers/polkadot/networks/bifrost/libs/assetinfo-orml.ts b/packages/extension/src/providers/polkadot/networks/bifrost/libs/assetinfo-orml.ts index b157e875e..56f2af7b7 100644 --- a/packages/extension/src/providers/polkadot/networks/bifrost/libs/assetinfo-orml.ts +++ b/packages/extension/src/providers/polkadot/networks/bifrost/libs/assetinfo-orml.ts @@ -10,7 +10,7 @@ import { OrmlTokensAccountData } from "../../acala/types/acala-orml-asset"; import { toBN } from "web3-utils"; import { KnownTokenDisplay } from "@/providers/polkadot/types"; import { SubstrateNativeToken } from "@/providers/polkadot/types/substrate-native-token"; -import { BN } from "ethereumjs-util"; +import { BNType } from "@/providers/common/types"; type AssetMetadata = { name: `0x${string}`; @@ -105,7 +105,7 @@ export default async ( const ormlOptions: BifrostOrmlAssetOptions = { name: hexToString(asset!.name), symbol: hexToString(asset!.symbol), - existentialDeposit: asset!.minimalBalance as BN, + existentialDeposit: asset!.minimalBalance as BNType, assetType: asset!.assetLookupId, lookupValue: asset!.assetLookupValue, icon: network.icon, diff --git a/packages/extension/src/providers/polkadot/types/substrate-network.ts b/packages/extension/src/providers/polkadot/types/substrate-network.ts index c597163b3..f728f9252 100644 --- a/packages/extension/src/providers/polkadot/types/substrate-network.ts +++ b/packages/extension/src/providers/polkadot/types/substrate-network.ts @@ -17,7 +17,7 @@ import { SubstrateNativeToken } from "./substrate-native-token"; import { Activity } from "@/types/activity"; import { getApi, addNewApi } from "../libs/api-promises"; import { KnownTokenDisplay } from "."; -import { BN } from "ethereumjs-util"; +import { BNType } from "@/providers/common/types"; export interface SubstrateNetworkOptions { name: NetworkNames; @@ -36,7 +36,7 @@ export interface SubstrateNetworkOptions { coingeckoPlatform?: CoingeckoPlatform; genesisHash: string; knownTokens?: KnownTokenDisplay[]; - existentialDeposit?: BN; + existentialDeposit?: BNType; activityHandler: ( network: BaseNetwork, address: string @@ -52,7 +52,7 @@ export class SubstrateNetwork extends BaseNetwork { public prefix: number; public assets: BaseToken[] = []; public genesisHash: string; - public existentialDeposit?: BN; + public existentialDeposit?: BNType; private knownTokens?: KnownTokenDisplay[]; private activityHandler: ( diff --git a/packages/extension/src/providers/polkadot/ui/libs/signer.ts b/packages/extension/src/providers/polkadot/ui/libs/signer.ts index 5bf61f06a..161f58004 100644 --- a/packages/extension/src/providers/polkadot/ui/libs/signer.ts +++ b/packages/extension/src/providers/polkadot/ui/libs/signer.ts @@ -11,7 +11,7 @@ import { u8aUnwrapBytes, u8aWrapBytes, } from "@polkadot/util"; -import { bufferToHex } from "ethereumjs-util"; +import { bufferToHex } from "@enkryptcom/utils"; const TransactionSigner = ( options: SignerTransactionOptions diff --git a/packages/extension/src/scripts/chrome/hot-reload.ts b/packages/extension/src/scripts/chrome/hot-reload.ts index 8fa5d188a..43fd1febe 100644 --- a/packages/extension/src/scripts/chrome/hot-reload.ts +++ b/packages/extension/src/scripts/chrome/hot-reload.ts @@ -1,5 +1,6 @@ import browser from "webextension-polyfill"; -import { keccakFromString } from "ethereumjs-util"; +import { keccak256 } from "ethereum-cryptography/keccak"; +import { bufferToHex } from "@enkryptcom/utils"; const filesToMonitor = { content: { path: "scripts/contentscript.js", @@ -33,7 +34,7 @@ const checkFilesChanged = async () => { await fetch(exturl) .then((res) => res.text()) .then((content) => { - const hash = keccakFromString(content).toString("hex"); + const hash = bufferToHex(keccak256(Buffer.from(content))); if (value.hash !== hash) { filesChanged = true; value.hash = hash; diff --git a/packages/extension/src/types/base-network.ts b/packages/extension/src/types/base-network.ts index dbfd51fd5..aef61ef72 100644 --- a/packages/extension/src/types/base-network.ts +++ b/packages/extension/src/types/base-network.ts @@ -5,7 +5,7 @@ import { AssetsType, ProviderName } from "@/types/provider"; import { CoingeckoPlatform, SignerType, NetworkNames } from "@enkryptcom/types"; import { Activity } from "./activity"; import { BaseToken } from "./base-token"; -import { BNLike } from "ethereumjs-util"; +import { BNType } from "@/providers/common/types"; export interface BaseNetworkOptions { name: NetworkNames; @@ -20,7 +20,7 @@ export interface BaseNetworkOptions { decimals: number; signer: SignerType[]; node: string; - displayAddress: (address: string, chainId?: BNLike) => string; + displayAddress: (address: string, chainId?: BNType) => string; provider: ProviderName; coingeckoID?: string; coingeckoPlatform?: CoingeckoPlatform; @@ -42,7 +42,7 @@ export abstract class BaseNetwork { public icon: string; public signer: SignerType[]; public node: string; - public displayAddress: (address: string, chainId?: BNLike) => string; + public displayAddress: (address: string, chainId?: BNType) => string; public provider: ProviderName; public coingeckoID: string | undefined; public coingeckoPlatform: CoingeckoPlatform | undefined; diff --git a/packages/extension/src/types/base-token.ts b/packages/extension/src/types/base-token.ts index 791c58e56..00a76a944 100644 --- a/packages/extension/src/types/base-token.ts +++ b/packages/extension/src/types/base-token.ts @@ -2,7 +2,7 @@ import EvmAPI from "@/providers/ethereum/libs/api"; import MarketData from "@/libs/market-data"; import { ApiPromise } from "@polkadot/api"; import BitcoinAPI from "@/providers/bitcoin/libs/api"; -import { BN } from "ethereumjs-util"; +import { BNType } from "@/providers/common/types"; export type TransferType = "keepAlive" | "all" | "allKeepAlive" | "transfer"; @@ -16,7 +16,7 @@ export interface BaseTokenOptions { decimals: number; icon: string; coingeckoID?: string; - existentialDeposit?: BN; + existentialDeposit?: BNType; balance?: string; price?: string; } @@ -27,7 +27,7 @@ export abstract class BaseToken { public decimals: number; public icon: string; public coingeckoID: string | undefined; - public existentialDeposit: BN | undefined; + public existentialDeposit: BNType | undefined; public balance?: string; public price?: string; diff --git a/packages/extension/src/ui/action/views/swap/types.ts b/packages/extension/src/ui/action/views/swap/types.ts index ad142cf5c..fd914d0da 100644 --- a/packages/extension/src/ui/action/views/swap/types.ts +++ b/packages/extension/src/ui/action/views/swap/types.ts @@ -1,4 +1,4 @@ -import { GasPriceTypes } from "@/providers/common/types"; +import { BNType, GasPriceTypes } from "@/providers/common/types"; import { BaseNetwork } from "@/types/base-network"; import { EVMTransaction, @@ -10,7 +10,6 @@ import { StatusOptionsResponse, } from "@enkryptcom/swap"; import { EnkryptAccount } from "@enkryptcom/types"; -import { BN } from "ethereumjs-util"; export enum SWAP_LOADING { LOADING = "loading", LOOKING_FOR_OFFERS = "looking", @@ -21,9 +20,9 @@ export interface SwapData { fromToken: TokenType; toToken: TokenTypeTo; priceDifference: string; - nativeBalance: BN; + nativeBalance: BNType; nativePrice: number; - existentialDeposit: BN; + existentialDeposit: BNType; fromAddress: string; toAddress: string; } diff --git a/packages/hw-wallets/package.json b/packages/hw-wallets/package.json index 403ae0735..f22002632 100644 --- a/packages/hw-wallets/package.json +++ b/packages/hw-wallets/package.json @@ -47,7 +47,9 @@ "dependencies": { "@enkryptcom/types": "workspace:^", "@enkryptcom/utils": "workspace:^", + "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/tx": "^5.2.1", + "@ethereumjs/util": "^9.0.2", "@ledgerhq/hw-app-eth": "^6.35.6", "@ledgerhq/hw-transport": "^6.30.4", "@ledgerhq/hw-transport-webusb": "^6.28.4", @@ -56,7 +58,6 @@ "@polkadot/util": "^12.6.2", "@trezor/connect-web": "^9.1.12", "@zondax/ledger-substrate": "^0.41.3", - "ethereumjs-util": "^7.1.5", "hdkey": "^2.1.0", "webextension-polyfill": "^0.10.0" } diff --git a/packages/hw-wallets/src/ledger/ethereum/index.ts b/packages/hw-wallets/src/ledger/ethereum/index.ts index 41b787073..85ec45ab9 100644 --- a/packages/hw-wallets/src/ledger/ethereum/index.ts +++ b/packages/hw-wallets/src/ledger/ethereum/index.ts @@ -3,10 +3,11 @@ import webUsbTransport from "@ledgerhq/hw-transport-webusb"; import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger"; import { HWwalletCapabilities, NetworkNames } from "@enkryptcom/types"; import EthApp from "@ledgerhq/hw-app-eth"; -import { toRpcSig, publicToAddress, rlp } from "ethereumjs-util"; +import { toRpcSig, publicToAddress } from "@ethereumjs/util"; import { LegacyTransaction, FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; import HDKey from "hdkey"; -import { bigIntToHex, bufferToHex, hexToBuffer } from "@enkryptcom/utils"; +import { bufferToHex, hexToBuffer } from "@enkryptcom/utils"; +import { RLP } from "@ethereumjs/rlp"; import { AddressResponse, getAddressRequest, @@ -108,7 +109,7 @@ class LedgerEthereum implements HWWalletProvider { let msgToSign: string; if ((options.transaction as LegacyTransaction).gasPrice) { tx = options.transaction as LegacyTransaction; - msgToSign = rlp.encode(tx.getMessageToSign()).toString("hex"); + msgToSign = bufferToHex(RLP.encode(tx.getMessageToSign()), true); } else { tx = options.transaction as FeeMarketEIP1559Transaction; msgToSign = bufferToHex(tx.getMessageToSign(), true); @@ -129,13 +130,13 @@ class LedgerEthereum implements HWWalletProvider { const rv = BigInt(parseInt(result.v, 16)); const cv = tx.common.chainId() * 2n + 35n; return toRpcSig( - bigIntToHex(rv - cv), + rv - cv, hexToBuffer(result.r), hexToBuffer(result.s) ); } return toRpcSig( - `0x${result.v}`, + BigInt(`0x${result.v}`), hexToBuffer(result.r), hexToBuffer(result.s) ); diff --git a/packages/hw-wallets/src/trezor/index.ts b/packages/hw-wallets/src/trezor/index.ts index b1626335b..77fb3e0c5 100644 --- a/packages/hw-wallets/src/trezor/index.ts +++ b/packages/hw-wallets/src/trezor/index.ts @@ -2,7 +2,7 @@ import TrezorConnect from "@trezor/connect-web"; import { HWwalletCapabilities, NetworkNames } from "@enkryptcom/types"; import HDKey from "hdkey"; import { bigIntToHex, bufferToHex, hexToBuffer } from "@enkryptcom/utils"; -import { publicToAddress, toRpcSig } from "ethereumjs-util"; +import { publicToAddress, toRpcSig } from "@ethereumjs/util"; import { FeeMarketEIP1559Transaction, LegacyTransaction } from "@ethereumjs/tx"; import { AddressResponse, @@ -113,7 +113,7 @@ class TrezorEthereum implements HWWalletProvider { const rv = BigInt(parseInt(result.payload.v, 16)); const cv = tx.common.chainId() * 2n + 35n; return toRpcSig( - bigIntToHex(rv - cv), + rv - cv, hexToBuffer(result.payload.r), hexToBuffer(result.payload.s) ); @@ -132,7 +132,7 @@ class TrezorEthereum implements HWWalletProvider { if (!result.success) throw new Error((result.payload as any).error as string); return toRpcSig( - result.payload.v, + BigInt(result.payload.v), hexToBuffer(result.payload.r), hexToBuffer(result.payload.s) ); diff --git a/packages/signers/ethereum/package.json b/packages/signers/ethereum/package.json index 1de1d97a5..7ee4e8fb5 100644 --- a/packages/signers/ethereum/package.json +++ b/packages/signers/ethereum/package.json @@ -18,9 +18,9 @@ }, "dependencies": { "@enkryptcom/utils": "workspace:^", + "@ethereumjs/util": "^9.0.2", "bip39": "^3.1.0", "chai": "^4.4.1", - "ethereumjs-util": "^7.1.5", "hdkey": "^2.1.0", "tweetnacl": "^1.0.3", "tweetnacl-util": "^0.15.1" diff --git a/packages/signers/ethereum/src/index.ts b/packages/signers/ethereum/src/index.ts index 45b727de2..5a30c95dc 100644 --- a/packages/signers/ethereum/src/index.ts +++ b/packages/signers/ethereum/src/index.ts @@ -1,11 +1,11 @@ import { + privateToPublic, ecsign, ecrecover, fromRpcSig, toRpcSig, - privateToPublic, privateToAddress, -} from "ethereumjs-util"; +} from "@ethereumjs/util"; import { mnemonicToSeed } from "bip39"; import { Errors, SignerInterface, KeyPair } from "@enkryptcom/types"; import { hexToBuffer, bufferToHex } from "@enkryptcom/utils"; diff --git a/packages/signers/ethereum/tests/encrypt.test.ts b/packages/signers/ethereum/tests/encrypt.test.ts index 05bbf1158..81158a965 100644 --- a/packages/signers/ethereum/tests/encrypt.test.ts +++ b/packages/signers/ethereum/tests/encrypt.test.ts @@ -1,6 +1,7 @@ import { bufferToHex, hexToBuffer } from "@enkryptcom/utils"; import { expect } from "chai"; import { privateToPublic } from "ethereumjs-util"; +import { privateToPublic } from "@ethereumjs/util"; import Signer from "../src"; // https://github.com/MetaMask/eth-sig-util/blob/main/src/encryption.test.ts diff --git a/packages/signers/ethereum/tests/sign.test.ts b/packages/signers/ethereum/tests/sign.test.ts index 02815abc8..6c5761a76 100644 --- a/packages/signers/ethereum/tests/sign.test.ts +++ b/packages/signers/ethereum/tests/sign.test.ts @@ -1,6 +1,6 @@ import { bufferToHex, hexToBuffer } from "@enkryptcom/utils"; import { expect } from "chai"; -import { privateToPublic } from "ethereumjs-util"; +import { privateToPublic } from "@ethereumjs/util"; import Signer from "../src"; describe("Ethreum signing", () => { diff --git a/yarn.lock b/yarn.lock index b2acefd7a..fc8cebb75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2360,6 +2360,7 @@ __metadata: "@enkryptcom/utils": "workspace:^" "@ethereumjs/common": ^4.2.0 "@ethereumjs/tx": ^5.2.1 + "@ethereumjs/util": ^9.0.2 "@ledgerhq/hw-transport-webusb": ^6.28.4 "@metamask/eth-sig-util": ^7.0.1 "@polkadot/api": ^10.11.3 @@ -2410,8 +2411,8 @@ __metadata: eslint-config-prettier: ^8.10.0 eslint-plugin-prettier: ^4.2.1 eslint-plugin-vue: ^8.7.1 + ethereum-cryptography: ^2.1.3 ethereumjs-abi: ^0.6.8 - ethereumjs-util: ^7.1.5 ethereumjs-wallet: ^1.0.2 eventemitter3: ^5.0.1 https-browserify: ^1.0.0 @@ -2459,7 +2460,9 @@ __metadata: dependencies: "@enkryptcom/types": "workspace:^" "@enkryptcom/utils": "workspace:^" + "@ethereumjs/rlp": ^5.0.2 "@ethereumjs/tx": ^5.2.1 + "@ethereumjs/util": ^9.0.2 "@ledgerhq/hw-app-eth": ^6.35.6 "@ledgerhq/hw-transport": ^6.30.4 "@ledgerhq/hw-transport-webusb": ^6.28.4 @@ -2480,7 +2483,6 @@ __metadata: eslint-import-resolver-alias: ^1.1.2 eslint-plugin-import: ^2.29.1 eslint-plugin-module-resolver: ^1.5.0 - ethereumjs-util: ^7.1.5 hdkey: ^2.1.0 mocha: ^10.3.0 prettier: ^2.8.8 @@ -2637,6 +2639,7 @@ __metadata: dependencies: "@enkryptcom/types": "workspace:^" "@enkryptcom/utils": "workspace:^" + "@ethereumjs/util": ^9.0.2 "@types/chai": ^4.3.12 "@types/hdkey": ^2.0.3 "@types/mocha": ^10.0.6 @@ -2651,7 +2654,6 @@ __metadata: eslint-import-resolver-alias: ^1.1.2 eslint-plugin-import: ^2.29.1 eslint-plugin-module-resolver: ^1.5.0 - ethereumjs-util: ^7.1.5 hdkey: ^2.1.0 mocha: ^10.3.0 prettier: ^2.8.8