Skip to content

Commit

Permalink
remove all direct usage of BN
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed May 8, 2024
1 parent c16a778 commit 89ee79f
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 263 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}'"
},
"devDependencies": {
"@types/bn.js": "^5.1.5",
"@types/elliptic": "^6.4.18",
"@types/jest": "^29.5.12",
"@types/keccak": "^3.0.4",
Expand All @@ -33,7 +32,6 @@
"@near-js/crypto": "^1.2.1",
"@near-js/keystores": "^0.0.9",
"@near-wallet-selector/core": "^8.9.5",
"bn.js": "^5.2.1",
"elliptic": "^6.5.5",
"keccak": "^3.0.4",
"near-api-js": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/chains/near.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { keyStores, KeyPair, connect, Account } from "near-api-js";
import { Wallet } from "@near-wallet-selector/core";

export const TGAS = "1000000000000";
export const TGAS = 1000000000000n;
export const NO_DEPOSIT = "0";

export interface NearConfig {
Expand Down
17 changes: 8 additions & 9 deletions src/mpcContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
uncompressedHexPointToEvmAddress,
} from "./utils/kdf";
import { NO_DEPOSIT, nearAccountFromEnv, TGAS } from "./chains/near";
import BN from "bn.js";
import {
MPCSignature,
NearContractFunctionPayload,
Expand All @@ -18,9 +17,9 @@ export interface ChangeMethodArgs<T> {
/// Change method function agruments.
args: T;
/// GasLimit on transaction execution.
gas: BN;
gas: string;
/// Deposit (i.e. payable amount) to attach to transaction.
attachedDeposit: BN;
attachedDeposit: string;
}

interface MultichainContractInterface extends Contract {
Expand Down Expand Up @@ -72,8 +71,8 @@ export class MultichainContract {
): Promise<MPCSignature> => {
const [big_r, big_s] = await this.contract.sign({
args: signArgs,
gas: gasBNOrDefault(gas),
attachedDeposit: new BN(NO_DEPOSIT),
gas: gasOrDefault(gas),
attachedDeposit: NO_DEPOSIT,
});
return { big_r, big_s };
};
Expand All @@ -91,7 +90,7 @@ export class MultichainContract {
params: {
methodName: "sign",
args: signArgs,
gas: gasBNOrDefault(gas).toString(),
gas: gasOrDefault(gas),
deposit: NO_DEPOSIT,
},
},
Expand All @@ -100,10 +99,10 @@ export class MultichainContract {
}
}

function gasBNOrDefault(gas?: bigint): BN {
function gasOrDefault(gas?: bigint): string {
if (gas !== undefined) {
return new BN(gas.toString());
return gas.toString();
}
// Default of 200 TGAS
return new BN(TGAS).muln(200);
return (TGAS * 200n).toString();
}
Loading

0 comments on commit 89ee79f

Please sign in to comment.