From 0dc31ea04c315e41b485b7e1ffeac47e1b04f498 Mon Sep 17 00:00:00 2001 From: "ollie.j" Date: Mon, 11 Sep 2023 16:28:25 +0900 Subject: [PATCH] jscore: Import only minimum ethers subpackages --- js-ext-core/package.json | 6 +++--- js-ext-core/src/core/klaytn_tx.ts | 8 ++++---- js-ext-core/src/core/util.ts | 16 ++++++---------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/js-ext-core/package.json b/js-ext-core/package.json index f9528541f..d71b2b35f 100644 --- a/js-ext-core/package.json +++ b/js-ext-core/package.json @@ -16,9 +16,6 @@ "prepublishOnly": "npm run build" }, "license": "MIT", - "peerDependencies": { - "ethers": "^5.7.2" - }, "devDependencies": { "@types/chai": "^4.3.4", "@types/chai-as-promised": "^7.1.5", @@ -34,6 +31,9 @@ "typescript": "^5.0.4" }, "dependencies": { + "@ethersproject/address": "^5.7.0", + "@ethersproject/bignumber": "^5.7.0", + "@ethersproject/transactions": "^5.7.0", "@klaytn/web3rpc": "^0.9.0", "lodash": "^4.17.21" } diff --git a/js-ext-core/src/core/klaytn_tx.ts b/js-ext-core/src/core/klaytn_tx.ts index 496085bbb..8dd44fdd1 100644 --- a/js-ext-core/src/core/klaytn_tx.ts +++ b/js-ext-core/src/core/klaytn_tx.ts @@ -1,6 +1,6 @@ -import { TransactionRequest } from "@ethersproject/abstract-provider"; -import { BigNumber } from "ethers"; -import { hexValue, parseTransaction } from "ethers/lib/utils"; +import { BigNumber } from "@ethersproject/bignumber"; +import { hexValue } from "@ethersproject/bytes"; +import { parse as parseTransaction } from "@ethersproject/transactions"; import _ from "lodash"; import { FieldSet, FieldSetFactory } from "./field"; @@ -108,7 +108,7 @@ export function objectFromRLP(value: string): any { return tx; } -export function encodeTxForRPC(allowedKeys:string[], tx: TransactionRequest): any { +export function encodeTxForRPC(allowedKeys:string[], tx: any): any { // TODO: refactoring like below // https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/json-rpc-provider.ts#L701 // return { diff --git a/js-ext-core/src/core/util.ts b/js-ext-core/src/core/util.ts index cc4b38a09..51109bac9 100644 --- a/js-ext-core/src/core/util.ts +++ b/js-ext-core/src/core/util.ts @@ -1,8 +1,8 @@ -import { BigNumber, BigNumberish } from "@ethersproject/bignumber"; +import { BigNumber, BigNumberish, FixedNumber } from "@ethersproject/bignumber"; +import { getAddress } from "@ethersproject/address"; import * as bytes from "@ethersproject/bytes"; import * as rlp from "@ethersproject/rlp"; -import { FixedNumber, ethers } from "ethers"; -import { computeAddress } from "ethers/lib/utils"; +import { computeAddress } from "@ethersproject/transactions"; export const RLP = { encode: rlp.encode, @@ -26,20 +26,16 @@ export const HexStr = { return bytes.isHexString(value, length); }, isSameAddress(a:string, b:string): boolean { - const A = ethers.utils.getAddress(a); - const B = ethers.utils.getAddress(b); - return A == B; + return getAddress(a) == getAddress(b); }, isSamePrivKey(a:string, b:string): boolean { - const A = computeAddress(a); - const B = computeAddress(b); - return this.isSameAddress(A, B); + return computeAddress(a) == computeAddress(b); }, stripZeros(value: any): string { return bytes.hexlify(bytes.stripZeros(value)); }, zeroPad(value:string, length:number): string { - return ethers.utils.hexZeroPad(value, length); + return bytes.hexZeroPad(value, length); } };