Skip to content

Commit

Permalink
Replace ethers with @ethersproject/...
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Sep 14, 2023
1 parent cabb652 commit a7d390e
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 36 deletions.
3 changes: 3 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@
"typescript": "^4.6.2"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/keccak256": "^5.7.0",
"@ethersproject/networks": "npm:boa-networks@^5.7.2",
"@ethersproject/providers": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/client-common/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ContextParams, ContextState } from "./interfaces/context";
import { JsonRpcProvider, Networkish } from "@ethersproject/providers";

import { ContextParams, ContextState } from "./interfaces/context";
import { UnsupportedProtocolError } from "del-sdk-common";
import { activeContractsList } from "del-osx-lib";

Expand Down
9 changes: 5 additions & 4 deletions packages/client/src/client-common/modules/web3.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Context } from "../context";
import { Wallet } from "@ethersproject/wallet";
import { JsonRpcProvider } from "@ethersproject/providers";
import { Contract, ContractInterface } from "@ethersproject/contracts";
import { Signer } from "@ethersproject/abstract-signer";
import { Contract, ContractInterface } from "@ethersproject/contracts";
import { JsonRpcProvider } from "@ethersproject/providers";
import { Wallet } from "@ethersproject/wallet";

import { Context } from "../context";
import { IClientWeb3Core } from "../interfaces/core";
import { NoLinkCollection } from "del-sdk-common";
import { GenericRecord, IHttpConfig } from "../interfaces/common";
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Client } from "./client";
export * from "./client-common";
export { AddRequestValue, IdParams, ToAddressParams, ToEmailParams, NonceOfParams } from "./interfaces";
export { AddRequestValue } from "./interfaces";
export * from "./utils/ContractUtils";
export * from "./utils/Amount";
19 changes: 2 additions & 17 deletions packages/client/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumber } from "@ethersproject/bignumber";

import { IClientCore } from "./client-common/interfaces/core";
import { BigNumber } from "ethers";

/** Defines the shape of the general purpose Client class */
export interface IClientMethods extends IClientCore {
Expand All @@ -18,22 +19,6 @@ export interface IClient {
methods: IClientMethods;
}

export type IdParams = {
id: string;
};

export type ToAddressParams = {
email: string;
};

export type ToEmailParams = {
wallet: string;
};

export type NonceOfParams = {
wallet: string;
};

export type ValidatorInfoValue = {
address: string;
index: number;
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/internal/client/methods.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Contract } from "@ethersproject/contracts";
import { BigNumber } from "@ethersproject/bignumber";

import { LinkCollection__factory } from "del-osx-lib";
import { NoProviderError, NoSignerError } from "del-sdk-common";

Expand All @@ -12,8 +15,6 @@ import {

import { ClientCore, Context, IHttpConfig } from "../../client-common";
import { ContractUtils } from "../../utils/ContractUtils";
import { BigNumber } from "ethers";
import { Contract } from "@ethersproject/contracts";
import {
AlreadyRegisteredAddress,
AlreadyRegisteredEmail,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/utils/Amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* MIT License. See LICENSE for details.
*/

import { BigNumber } from "ethers";
import { BigNumber } from "@ethersproject/bignumber";

/**
* The class that defines the Amount
Expand Down
18 changes: 11 additions & 7 deletions packages/client/src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
* License:
* MIT License. See LICENSE for details.
*/
import { defaultAbiCoder } from "@ethersproject/abi";
import { Signer } from "@ethersproject/abstract-signer";
import { BigNumberish } from "@ethersproject/bignumber";
import { arrayify } from "@ethersproject/bytes";
import { keccak256 } from "@ethersproject/keccak256";
import { verifyMessage } from "@ethersproject/wallet";

import * as crypto from "crypto";
import { BigNumberish, ethers, Signer } from "ethers";
import { arrayify } from "ethers/lib/utils";

export class ContractUtils {
/**
Expand Down Expand Up @@ -61,19 +65,19 @@ export class ContractUtils {
}

public static getRequestId(emailHash: string, address: string, nonce: BigNumberish): string {
const encodedResult = ethers.utils.defaultAbiCoder.encode(
const encodedResult = defaultAbiCoder.encode(
["bytes32", "address", "uint256", "bytes32"],
[emailHash, address, nonce, crypto.randomBytes(32)]
);
return ethers.utils.keccak256(encodedResult);
return keccak256(encodedResult);
}

public static getRequestHash(email: string, address: string, nonce: BigNumberish): Uint8Array {
const encodedResult = ethers.utils.defaultAbiCoder.encode(
const encodedResult = defaultAbiCoder.encode(
["bytes32", "address", "uint256"],
[ContractUtils.sha256String(email), address, nonce]
);
return arrayify(ethers.utils.keccak256(encodedResult));
return arrayify(keccak256(encodedResult));
}

public static async signRequestData(signer: Signer, email: string, nonce: BigNumberish): Promise<string> {
Expand All @@ -85,7 +89,7 @@ export class ContractUtils {
const message = ContractUtils.getRequestHash(email, address, nonce);
let res: string;
try {
res = ethers.utils.verifyMessage(message, signature);
res = verifyMessage(message, signature);
} catch (error) {
return false;
}
Expand Down
1 change: 1 addition & 0 deletions packages/client/test/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { JsonRpcProvider } from "@ethersproject/providers";
import { Wallet } from "@ethersproject/wallet";

import { Client, Context } from "../src";
import { contextParamsMainnet, web3endpoints } from "./helper/constants";

Expand Down
4 changes: 2 additions & 2 deletions packages/client/test/helper/GanacheServer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ganache, { Server } from "ganache";
import * as dotenv from "dotenv";
import { Wallet } from "ethers";
import { JsonRpcProvider } from "@ethersproject/providers";
import { contextParamsLocalChain } from "./constants";
import { LIVE_CONTRACTS } from "../../src";
import { Signer } from "@ethersproject/abstract-signer";
import { JsonRpcProvider } from "@ethersproject/providers";
import { Wallet } from "@ethersproject/wallet";

dotenv.config({ path: "env/.env" });

Expand Down
1 change: 1 addition & 0 deletions packages/client/test/helper/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Wallet } from "@ethersproject/wallet";

import { ContextParams } from "../../src";

export const web3endpoints = {
Expand Down
3 changes: 2 additions & 1 deletion packages/client/test/methods.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BigNumber } from "@ethersproject/bignumber";

import { Server } from "ganache";
import { GanacheServer } from "./helper/GanacheServer";
import { contextParamsLocalChain } from "./helper/constants";
import { FakerValidator } from "./helper/FakerValidator";
import { Client, Context, ContractUtils } from "../src";
import { AddRequestSteps } from "../src/interfaces";
import { BigNumber } from "ethers";
import { ContractDeployer, Deployment } from "./helper/ContractDeployer";
import { RegisterSteps } from "../src/interfaces";

Expand Down

0 comments on commit a7d390e

Please sign in to comment.