From ba719ff7b4d93ad2896735421744f5fe4a5ecf27 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 10 Apr 2024 10:05:14 +0100 Subject: [PATCH 01/10] Cleanup scripts/typos --- .eslintrc.json => .eslintrc | 0 examples/send-eth.ts | 2 +- examples/weth/wrap.ts | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename .eslintrc.json => .eslintrc (100%) diff --git a/.eslintrc.json b/.eslintrc similarity index 100% rename from .eslintrc.json rename to .eslintrc diff --git a/examples/send-eth.ts b/examples/send-eth.ts index 62d53a0..6b990da 100644 --- a/examples/send-eth.ts +++ b/examples/send-eth.ts @@ -6,7 +6,7 @@ const run = async (): Promise => { const evm = await setupNearEthAdapter(); await evm.signAndSendTransaction({ to: "0xdeADBeeF0000000000000000000000000b00B1e5", - // THIS IS ONE WAY! + // THIS IS ONE WEI! value: 1n, }); }; diff --git a/examples/weth/wrap.ts b/examples/weth/wrap.ts index 85e7db0..604155c 100644 --- a/examples/weth/wrap.ts +++ b/examples/weth/wrap.ts @@ -4,12 +4,12 @@ import { setupNearEthAdapter } from "../setup"; const run = async (): Promise => { const neareth = await setupNearEthAdapter(); const sepoliaWETH = "0xfff9976782d46cc05630d1f6ebab18b2324d6b14"; - const ethAmount = 0.01; + const ethAmount = parseEther("0.01"); const deposit = "0xd0e30db0"; await neareth.signAndSendTransaction({ to: sepoliaWETH, - value: parseEther(ethAmount.toString()), + value: ethAmount, data: deposit, }); }; From 9c21b5049f692313f656539c32763787df1aec04 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 11 Apr 2024 22:07:35 +0200 Subject: [PATCH 02/10] close attempt to remove ethereumjs --- package.json | 2 +- src/chains/ethereum.ts | 86 ++++++++++++++---------------- src/types.ts | 11 ++-- src/utils/transaction.ts | 110 +++++++++++++++++++++++++++++++++++++++ tests/e2e.test.ts | 5 ++ tests/ethereum.test.ts | 35 +++++++++++-- tests/utils.kdf.test.ts | 34 ++++++++++++ 7 files changed, 225 insertions(+), 58 deletions(-) create mode 100644 src/utils/transaction.ts create mode 100644 tests/e2e.test.ts diff --git a/package.json b/package.json index 2a6b78d..58d9524 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "rm -rf ./dist && tsc", "lint": "eslint . --ext .ts,.tsx", - "test": "jest", + "test": "jest --testTimeout 10000", "fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}'" }, "devDependencies": { diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 7254320..60b1a47 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -1,5 +1,3 @@ -import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; -import { bytesToHex } from "@ethereumjs/util"; import { Address, Hex, @@ -7,6 +5,8 @@ import { createPublicClient, http, Hash, + serializeTransaction, + parseTransaction, } from "viem"; import { BaseTx, @@ -15,9 +15,14 @@ import { TxPayload, TransactionWithSignature, } from "../types"; -import { queryGasPrice } from "../utils/gasPrice"; import { MultichainContract } from "../mpcContract"; import BN from "bn.js"; +import { queryGasPrice } from "../utils/gasPrice"; +import { + // addSignature, + buildTxPayload, + ethersJsAddSignature, +} from "../utils/transaction"; export class NearEthAdapter { private ethClient: PublicClient; @@ -109,7 +114,7 @@ export class NearEthAdapter { txData: BaseTx, nearGas?: BN ): Promise<{ - transaction: FeeMarketEIP1559Transaction; + transaction: Hex; requestPayload: NearContractFunctionPayload; }> { console.log("Creating Payload for sender:", this.sender); @@ -132,6 +137,8 @@ export class NearEthAdapter { */ async relayTransaction(tx: TransactionWithSignature): Promise { const signedTx = await this.reconstructSignature(tx); + console.log(parseTransaction(signedTx)); + throw new Error("DONT BOTHER"); return this.relaySignedTransaction(signedTx); } @@ -140,25 +147,21 @@ export class NearEthAdapter { * and payload bytes in preparation to be relayed to Near MPC contract. * * @param {BaseTx} tx - Minimal transaction data to be signed by Near MPC and executed on EVM. + * @param {number?} nonce - Optional transaction nonce. * @returns Transaction and its bytes (the payload to be signed on Near). */ async createTxPayload(tx: BaseTx, nonce?: number): Promise { const transaction = await this.buildTransaction(tx, nonce); - console.log("Built (unsigned) Transaction", transaction.toJSON()); - const payload = Array.from( - new Uint8Array(transaction.getHashedMessageToSign().slice().reverse()) - ); - const signArgs = { payload, path: this.derivationPath, key_version: 0 }; + console.log("Built (unsigned) Transaction", transaction); + const signArgs = { + payload: await buildTxPayload(transaction), + path: this.derivationPath, + key_version: 0, + }; return { transaction, signArgs }; } - async buildTransaction( - tx: BaseTx, - nonce?: number - ): Promise { - const { maxFeePerGas, maxPriorityFeePerGas } = await queryGasPrice( - this.gasStationUrl - ); + async buildTransaction(tx: BaseTx, nonce?: number): Promise { const transactionData = { nonce: nonce || @@ -167,52 +170,43 @@ export class NearEthAdapter { })), account: this.sender, to: tx.to, - value: tx.value || 0n, - data: tx.data || "0x", + value: tx.value ?? 0n, + data: tx.data ?? "0x", }; - const estimatedGas = await this.ethClient.estimateGas(transactionData); + const [estimatedGas, { maxFeePerGas, maxPriorityFeePerGas }, chainId] = + await Promise.all([ + this.ethClient.estimateGas(transactionData), + queryGasPrice(this.gasStationUrl), + this.ethClient.getChainId(), + ]); const transactionDataWithGasLimit = { ...transactionData, gasLimit: BigInt(estimatedGas.toString()), maxFeePerGas, maxPriorityFeePerGas, - chainId: await this.ethClient.getChainId(), + chainId, }; - return FeeMarketEIP1559Transaction.fromTxData(transactionDataWithGasLimit); + console.log("Gas Estimation:", estimatedGas); + console.log("Transaction Request", transactionDataWithGasLimit); + return serializeTransaction(transactionDataWithGasLimit); } - reconstructSignature( - tx: TransactionWithSignature - ): FeeMarketEIP1559Transaction { - const { transaction, signature: sig } = tx; - const r = Buffer.from(sig.big_r.substring(2), "hex"); - const s = Buffer.from(sig.big_s, "hex"); - - const candidates = [0n, 1n].map((v) => transaction.addSignature(v, r, s)); - const signature = candidates.find( - (c) => - c.getSenderAddress().toString().toLowerCase() === - this.sender.toLowerCase() - ); - - if (!signature) { - throw new Error("Signature is not valid"); - } - - return signature; + reconstructSignature(tx: TransactionWithSignature): Hex { + // TODO - replace with viemAddSignature + return ethersJsAddSignature(tx, this.sender); } /** - * Relays signed transaction to Etherem mempool for execution. - * @param signedTx - Signed Ethereum transaction. + * Relays signed transaction to Ethereum mem-pool for execution. + * @param serializedTransaction - Signed Ethereum transaction. * @returns Transaction Hash of relayed transaction. */ - async relaySignedTransaction( - signedTx: FeeMarketEIP1559Transaction + private async relaySignedTransaction( + serializedTransaction: Hex ): Promise { - const serializedTx = bytesToHex(signedTx.serialize()) as Hex; + // const serializedTransaction = serializeTransaction(signedTx); const txHash = await this.ethClient.sendRawTransaction({ - serializedTransaction: serializedTx, + serializedTransaction, }); console.log(`Transaction Confirmed: ${this.scanUrl}/tx/${txHash}`); return txHash; diff --git a/src/types.ts b/src/types.ts index fa89bac..28f2b8d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,16 +1,15 @@ -import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; -import { Address, Hex } from "viem"; import { MultichainContract } from "./mpcContract"; import { FunctionCallAction } from "@near-wallet-selector/core"; import BN from "bn.js"; +import { Hex } from "viem"; export interface BaseTx { /// Recipient of the transaction - to: Address; + to: `0x${string}`; /// ETH value of transaction value?: bigint; /// Call Data of the transaction - data?: Hex; + data?: `0x${string}`; } export interface NearEthAdapterParams { @@ -66,7 +65,7 @@ export interface SignArgs { export interface TxPayload { /// Deserialized Ethereum Transaction. - transaction: FeeMarketEIP1559Transaction; + transaction: Hex; /// Arguments required by Near MPC Contract signature request. signArgs: SignArgs; } @@ -94,7 +93,7 @@ export interface MPCSignature { */ export interface TransactionWithSignature { /// Unsigned Ethereum transaction data. - transaction: FeeMarketEIP1559Transaction; + transaction: Hex; /// Representation of the transaction's signature. signature: MPCSignature; } diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts new file mode 100644 index 0000000..48c1258 --- /dev/null +++ b/src/utils/transaction.ts @@ -0,0 +1,110 @@ +import { + Address, + Hex, + bytesToHex, + hexToNumber, + keccak256, + parseTransaction, + recoverPublicKey, + serializeTransaction, + signatureToHex, +} from "viem"; +import { TransactionWithSignature } from "../types"; +import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; + +export function hexStringToUint8Array(hexString: string): Uint8Array { + // Remove the "0x" prefix if it's present + hexString = hexString.replace(/^0x/, ""); + + // Ensure the hex string has an even length + if (hexString.length % 2 !== 0) { + console.error( + "Hex string has an odd length, which is not valid for byte representation." + ); + return new Uint8Array(); + } + + // Create a Uint8Array with the length of half the hex string length + const byteArray = new Uint8Array(hexString.length / 2); + + // Convert each hex byte (two hex characters) to a decimal value and fill the Uint8Array + for (let i = 0, j = 0; i < hexString.length; i += 2, j++) { + byteArray[j] = parseInt(hexString.substring(i, i + 2), 16); + } + + return byteArray; +} + +export function ethersJsAddSignature( + tx: TransactionWithSignature, + sender: Address +): Hex { + const { transaction: unsignedTxHash, signature: sig } = tx; + const transaction = FeeMarketEIP1559Transaction.fromSerializedTx( + hexStringToUint8Array(unsignedTxHash) + ); + const r = Buffer.from(sig.big_r.substring(2), "hex"); + const s = Buffer.from(sig.big_s, "hex"); + + const candidates = [0n, 1n].map((v) => transaction.addSignature(v, r, s)); + const signature = candidates.find( + (c) => + c.getSenderAddress().toString().toLowerCase() === + sender.toString().toLowerCase() + ); + + if (!signature) { + throw new Error("Signature is not valid"); + } + return bytesToHex(signature.serialize()); +} + +export async function viemAddSig( + { transaction, signature: sig }: TransactionWithSignature, + sender: Address +): Promise { + const txData = parseTransaction(transaction); + const candidates = [0, 1].map((v) => { + return { + yParity: v, + r: `0x${sig.big_r.substring(2)}` as Hex, + s: `0x${sig.big_s}` as Hex, + ...txData, + }; + }); + const signature = candidates.find(async (tx) => { + const signature = signatureToHex({ + r: tx.r!, + s: tx.s!, + // v: tx.v!, + yParity: tx.yParity!, + }); + const pk = await recoverPublicKey({ + hash: serializeTransaction(tx), + signature, + }); + const v = hexToNumber(`0x${signature.slice(130)}`); + console.log("V Value:", v); + return pk.toString().toLowerCase() === sender.toLowerCase(); + }); + if (!signature) { + throw new Error("Signature is not valid"); + } + + return serializeTransaction(signature); +} + +export async function addSignature( + tx: TransactionWithSignature, + sender: Address +): Promise { + return viemAddSig(tx, sender); +} + +export async function buildTxPayload( + unsignedTxHash: `0x${string}` +): Promise { + // Compute the Transaction Message Hash. + const messageHash = await keccak256(unsignedTxHash); + return Array.from(hexStringToUint8Array(messageHash).slice().reverse()); +} diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts new file mode 100644 index 0000000..de3d946 --- /dev/null +++ b/tests/e2e.test.ts @@ -0,0 +1,5 @@ +describe("End To End", () => { + it.skip("Runs the Send ETH Tx", () => { + expect(1).toEqual(0); + }); +}); diff --git a/tests/ethereum.test.ts b/tests/ethereum.test.ts index 25ef1b8..a0fc12c 100644 --- a/tests/ethereum.test.ts +++ b/tests/ethereum.test.ts @@ -1,12 +1,16 @@ import { setupNearEthAdapter } from "../examples/setup"; +import { NearEthAdapter, TransactionWithSignature } from "../src"; const ONE_ADDRESS = "0x1111111111111111111111111111111111111111"; describe("Near Eth Adapter", () => { - it.skip("Create Tx Payload", async () => { - const evm = await setupNearEthAdapter(); + let adapter: NearEthAdapter; - const { signArgs } = await evm.createTxPayload( + beforeAll(async () => { + adapter = await setupNearEthAdapter(); + }); + it.skip("Create Tx Payload", async () => { + const { signArgs } = await adapter.createTxPayload( { to: ONE_ADDRESS, value: 1n, @@ -14,9 +18,11 @@ describe("Near Eth Adapter", () => { }, 1 ); + console.log(signArgs.payload); expect(signArgs.payload).toEqual([ - 110, 28, 45, 165, 219, 192, 26, 112, 63, 28, 205, 2, 103, 60, 51, 230, - 196, 252, 2, 98, 253, 73, 252, 4, 16, 81, 69, 33, 208, 188, 153, 216, + 205, 122, 162, 139, 210, 184, 225, 242, 45, 225, 52, 204, 240, 116, 140, + 27, 73, 166, 251, 122, 197, 60, 24, 147, 125, 132, 132, 195, 131, 39, 57, + 189, ]); // const { big_r, big_s } = await evm.mpcContract.requestSignature(signArgs); // const s = evm.reconstructSignature({ @@ -24,4 +30,23 @@ describe("Near Eth Adapter", () => { // signature: { big_r, big_s }, // }); }); + + it.skip("Reconstructs Signature", async () => { + const testTx: TransactionWithSignature = { + transaction: + "0x02e883aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0", + signature: { + big_r: + "02EF532579E267C932B959A1ADB9E455AC3C5397D0473471C4C3DD5D62FD4D7EDE", + big_s: + "7C195E658C713D601D245311A259115BB91EC87C86ACB07C03BD9C1936A6A9E8", + }, + }; + // This shit should not be async. Reason: VEIM. + const signedTx = await adapter.reconstructSignature(testTx); + console.log(signedTx); + // expect(serializeTransaction(signedTx)).toEqual( + // "0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c001a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8" + // ); + }); }); diff --git a/tests/utils.kdf.test.ts b/tests/utils.kdf.test.ts index d1e6ccf..16a2e3e 100644 --- a/tests/utils.kdf.test.ts +++ b/tests/utils.kdf.test.ts @@ -1,8 +1,14 @@ +import { TransactionWithSignature } from "../src"; import { najPublicKeyStrToUncompressedHexPoint, deriveChildPublicKey, uncompressedHexPointToEvmAddress, } from "../src/utils/kdf"; +import { + addSignature, + buildTxPayload, + ethersJsAddSignature, +} from "../src/utils/transaction"; const ROOT_PK = "ecp256k1:4HFcTSodRLVCGNVcGc4Mf2fwBBBxv9jxkGdiW2S2CA1y6UpVVRWKj6RX7d7TDt65k2Bj3w9FU4BGtt43ZvuhCnNt"; @@ -33,4 +39,32 @@ describe("Crypto Functions", () => { expect(result).toMatch(/^0x[0-9a-fA-F]{40}$/); expect(result).toMatch("0x8958e9780a209b57aa639330196f2baba27d760b"); }); + + it.only("addSignature", async () => { + const testTx: TransactionWithSignature = { + transaction: + "0x02e883aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0", + signature: { + big_r: + "02EF532579E267C932B959A1ADB9E455AC3C5397D0473471C4C3DD5D62FD4D7EDE", + big_s: + "7C195E658C713D601D245311A259115BB91EC87C86ACB07C03BD9C1936A6A9E8", + }, + }; + const sender = "0xa61d98854f7ab25402e3d12548a2e93a080c1f97"; + const signature = await addSignature(testTx, sender); + console.log(ethersJsAddSignature(testTx, sender)); + expect(signature).toEqual( + "0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c001a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8" + ); + }); + it("buildTxPayload", async () => { + const txHash = + "0x02e783aa36a7808309e8bb84773f7cbb8094deadbeef0000000000000000000000000b00b1e50180c0"; + const payload = await buildTxPayload(txHash); + expect(payload).toEqual([ + 178, 243, 90, 239, 203, 210, 59, 212, 215, 225, 70, 217, 13, 214, 94, 37, + 36, 9, 101, 199, 230, 132, 140, 98, 211, 7, 68, 130, 233, 88, 145, 179, + ]); + }); }); From 3514d88429d3227920ac7b166d9ec57166e329d2 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 11 Apr 2024 22:34:40 +0200 Subject: [PATCH 03/10] fix some tests --- package.json | 2 +- src/chains/ethereum.ts | 14 ++++------- src/utils/transaction.ts | 31 +++--------------------- tests/e2e.test.ts | 13 +++++++--- tests/ethereum.test.ts | 42 ++++++++------------------------- tests/utils.kdf.test.ts | 34 -------------------------- tests/utils.transaction.test.ts | 35 +++++++++++++++++++++++++++ 7 files changed, 63 insertions(+), 108 deletions(-) create mode 100644 tests/utils.transaction.test.ts diff --git a/package.json b/package.json index 58d9524..1e0f7a8 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "rm -rf ./dist && tsc", "lint": "eslint . --ext .ts,.tsx", - "test": "jest --testTimeout 10000", + "test": "jest --testTimeout 30000", "fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}'" }, "devDependencies": { diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 60b1a47..7e3855b 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -6,7 +6,6 @@ import { http, Hash, serializeTransaction, - parseTransaction, } from "viem"; import { BaseTx, @@ -18,11 +17,7 @@ import { import { MultichainContract } from "../mpcContract"; import BN from "bn.js"; import { queryGasPrice } from "../utils/gasPrice"; -import { - // addSignature, - buildTxPayload, - ethersJsAddSignature, -} from "../utils/transaction"; +import { buildTxPayload, ethersJsAddSignature } from "../utils/transaction"; export class NearEthAdapter { private ethClient: PublicClient; @@ -137,8 +132,6 @@ export class NearEthAdapter { */ async relayTransaction(tx: TransactionWithSignature): Promise { const signedTx = await this.reconstructSignature(tx); - console.log(parseTransaction(signedTx)); - throw new Error("DONT BOTHER"); return this.relaySignedTransaction(signedTx); } @@ -181,7 +174,7 @@ export class NearEthAdapter { ]); const transactionDataWithGasLimit = { ...transactionData, - gasLimit: BigInt(estimatedGas.toString()), + gas: BigInt(estimatedGas.toString()), maxFeePerGas, maxPriorityFeePerGas, chainId, @@ -192,7 +185,8 @@ export class NearEthAdapter { } reconstructSignature(tx: TransactionWithSignature): Hex { - // TODO - replace with viemAddSignature + // TODO - replace with viemAddSignature! + // Its off by a single byte. return ethersJsAddSignature(tx, this.sender); } diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 48c1258..32b667d 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -2,7 +2,7 @@ import { Address, Hex, bytesToHex, - hexToNumber, + hexToBytes, keccak256, parseTransaction, recoverPublicKey, @@ -12,36 +12,13 @@ import { import { TransactionWithSignature } from "../types"; import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; -export function hexStringToUint8Array(hexString: string): Uint8Array { - // Remove the "0x" prefix if it's present - hexString = hexString.replace(/^0x/, ""); - - // Ensure the hex string has an even length - if (hexString.length % 2 !== 0) { - console.error( - "Hex string has an odd length, which is not valid for byte representation." - ); - return new Uint8Array(); - } - - // Create a Uint8Array with the length of half the hex string length - const byteArray = new Uint8Array(hexString.length / 2); - - // Convert each hex byte (two hex characters) to a decimal value and fill the Uint8Array - for (let i = 0, j = 0; i < hexString.length; i += 2, j++) { - byteArray[j] = parseInt(hexString.substring(i, i + 2), 16); - } - - return byteArray; -} - export function ethersJsAddSignature( tx: TransactionWithSignature, sender: Address ): Hex { const { transaction: unsignedTxHash, signature: sig } = tx; const transaction = FeeMarketEIP1559Transaction.fromSerializedTx( - hexStringToUint8Array(unsignedTxHash) + hexToBytes(unsignedTxHash) ); const r = Buffer.from(sig.big_r.substring(2), "hex"); const s = Buffer.from(sig.big_s, "hex"); @@ -83,8 +60,6 @@ export async function viemAddSig( hash: serializeTransaction(tx), signature, }); - const v = hexToNumber(`0x${signature.slice(130)}`); - console.log("V Value:", v); return pk.toString().toLowerCase() === sender.toLowerCase(); }); if (!signature) { @@ -106,5 +81,5 @@ export async function buildTxPayload( ): Promise { // Compute the Transaction Message Hash. const messageHash = await keccak256(unsignedTxHash); - return Array.from(hexStringToUint8Array(messageHash).slice().reverse()); + return Array.from(hexToBytes(messageHash).slice().reverse()); } diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index de3d946..ae00b70 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,5 +1,12 @@ -describe("End To End", () => { - it.skip("Runs the Send ETH Tx", () => { - expect(1).toEqual(0); +import { setupNearEthAdapter } from "../examples/setup"; + +describe.skip("End To End", () => { + it("Runs the Send ETH Tx", async () => { + const evm = await setupNearEthAdapter(); + await evm.signAndSendTransaction({ + to: "0xdeADBeeF0000000000000000000000000b00B1e5", + // THIS IS ONE WEI! + value: 1n, + }); }); }); diff --git a/tests/ethereum.test.ts b/tests/ethereum.test.ts index a0fc12c..b2b4c81 100644 --- a/tests/ethereum.test.ts +++ b/tests/ethereum.test.ts @@ -1,15 +1,15 @@ import { setupNearEthAdapter } from "../examples/setup"; -import { NearEthAdapter, TransactionWithSignature } from "../src"; +import { NearEthAdapter } from "../src"; const ONE_ADDRESS = "0x1111111111111111111111111111111111111111"; -describe("Near Eth Adapter", () => { +describe.skip("Near Eth Adapter", () => { let adapter: NearEthAdapter; beforeAll(async () => { adapter = await setupNearEthAdapter(); }); - it.skip("Create Tx Payload", async () => { + it("createTxPayload", async () => { const { signArgs } = await adapter.createTxPayload( { to: ONE_ADDRESS, @@ -19,34 +19,12 @@ describe("Near Eth Adapter", () => { 1 ); console.log(signArgs.payload); - expect(signArgs.payload).toEqual([ - 205, 122, 162, 139, 210, 184, 225, 242, 45, 225, 52, 204, 240, 116, 140, - 27, 73, 166, 251, 122, 197, 60, 24, 147, 125, 132, 132, 195, 131, 39, 57, - 189, - ]); - // const { big_r, big_s } = await evm.mpcContract.requestSignature(signArgs); - // const s = evm.reconstructSignature({ - // transaction, - // signature: { big_r, big_s }, - // }); - }); - - it.skip("Reconstructs Signature", async () => { - const testTx: TransactionWithSignature = { - transaction: - "0x02e883aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0", - signature: { - big_r: - "02EF532579E267C932B959A1ADB9E455AC3C5397D0473471C4C3DD5D62FD4D7EDE", - big_s: - "7C195E658C713D601D245311A259115BB91EC87C86ACB07C03BD9C1936A6A9E8", - }, - }; - // This shit should not be async. Reason: VEIM. - const signedTx = await adapter.reconstructSignature(testTx); - console.log(signedTx); - // expect(serializeTransaction(signedTx)).toEqual( - // "0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c001a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8" - // ); + expect(signArgs).toEqual({ + payload: [ + 205, 122, 162, 139, 210, 184, 225, 242, 45, 225, 52, 204, 240, 116, 140, + 27, 73, 166, 251, 122, 197, 60, 24, 147, 125, 132, 132, 195, 131, 39, + 57, 189, + ], + }); }); }); diff --git a/tests/utils.kdf.test.ts b/tests/utils.kdf.test.ts index 16a2e3e..d1e6ccf 100644 --- a/tests/utils.kdf.test.ts +++ b/tests/utils.kdf.test.ts @@ -1,14 +1,8 @@ -import { TransactionWithSignature } from "../src"; import { najPublicKeyStrToUncompressedHexPoint, deriveChildPublicKey, uncompressedHexPointToEvmAddress, } from "../src/utils/kdf"; -import { - addSignature, - buildTxPayload, - ethersJsAddSignature, -} from "../src/utils/transaction"; const ROOT_PK = "ecp256k1:4HFcTSodRLVCGNVcGc4Mf2fwBBBxv9jxkGdiW2S2CA1y6UpVVRWKj6RX7d7TDt65k2Bj3w9FU4BGtt43ZvuhCnNt"; @@ -39,32 +33,4 @@ describe("Crypto Functions", () => { expect(result).toMatch(/^0x[0-9a-fA-F]{40}$/); expect(result).toMatch("0x8958e9780a209b57aa639330196f2baba27d760b"); }); - - it.only("addSignature", async () => { - const testTx: TransactionWithSignature = { - transaction: - "0x02e883aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0", - signature: { - big_r: - "02EF532579E267C932B959A1ADB9E455AC3C5397D0473471C4C3DD5D62FD4D7EDE", - big_s: - "7C195E658C713D601D245311A259115BB91EC87C86ACB07C03BD9C1936A6A9E8", - }, - }; - const sender = "0xa61d98854f7ab25402e3d12548a2e93a080c1f97"; - const signature = await addSignature(testTx, sender); - console.log(ethersJsAddSignature(testTx, sender)); - expect(signature).toEqual( - "0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c001a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8" - ); - }); - it("buildTxPayload", async () => { - const txHash = - "0x02e783aa36a7808309e8bb84773f7cbb8094deadbeef0000000000000000000000000b00b1e50180c0"; - const payload = await buildTxPayload(txHash); - expect(payload).toEqual([ - 178, 243, 90, 239, 203, 210, 59, 212, 215, 225, 70, 217, 13, 214, 94, 37, - 36, 9, 101, 199, 230, 132, 140, 98, 211, 7, 68, 130, 233, 88, 145, 179, - ]); - }); }); diff --git a/tests/utils.transaction.test.ts b/tests/utils.transaction.test.ts new file mode 100644 index 0000000..ad09679 --- /dev/null +++ b/tests/utils.transaction.test.ts @@ -0,0 +1,35 @@ +import { TransactionWithSignature } from "../src"; +import { addSignature, buildTxPayload } from "../src/utils/transaction"; + +describe("Transaction Builder Functions", () => { + it("addSignature", async () => { + const testTx: TransactionWithSignature = { + transaction: + "0x02e883aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0", + signature: { + big_r: + "02EF532579E267C932B959A1ADB9E455AC3C5397D0473471C4C3DD5D62FD4D7EDE", + big_s: + "7C195E658C713D601D245311A259115BB91EC87C86ACB07C03BD9C1936A6A9E8", + }, + }; + const sender = "0xa61d98854f7ab25402e3d12548a2e93a080c1f97"; + const signature = await addSignature(testTx, sender); + // This does not agree with: + // try ethersJsAddSignature(testTx, sender)! + // which says that vByte should be "01"!!! + const vByte = "80"; + expect(signature).toEqual( + `0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0${vByte}a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8` + ); + }); + it("buildTxPayload", async () => { + const txHash = + "0x02e783aa36a7808309e8bb84773f7cbb8094deadbeef0000000000000000000000000b00b1e50180c0"; + const payload = await buildTxPayload(txHash); + expect(payload).toEqual([ + 178, 243, 90, 239, 203, 210, 59, 212, 215, 225, 70, 217, 13, 214, 94, 37, + 36, 9, 101, 199, 230, 132, 140, 98, 211, 7, 68, 130, 233, 88, 145, 179, + ]); + }); +}); From 1bc83dfa518a040fb55675778d2a9a9af6ead02e Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 11 Apr 2024 22:38:17 +0200 Subject: [PATCH 04/10] remove unused dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index 1e0f7a8..4c3ef7d 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,7 @@ "typescript": "^5.4.2" }, "dependencies": { - "@ethereumjs/common": "^4.3.0", "@ethereumjs/tx": "^5.3.0", - "@ethereumjs/util": "^9.0.3", "@near-js/accounts": "^1.0.4", "@near-js/crypto": "^1.2.1", "@near-js/keystores": "^0.0.9", From a0664cf6c8433786f2b00b78f2a217b53e000897 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Thu, 11 Apr 2024 22:47:55 +0200 Subject: [PATCH 05/10] add 1WEI e2e test --- .github/workflows/ci.yaml | 14 +++++++++++--- tests/e2e.test.ts | 2 +- tests/ethereum.test.ts | 30 ------------------------------ 3 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 tests/ethereum.test.ts diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ef82005..b683e3f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,9 +2,9 @@ name: Node.js CI on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: types: @@ -15,7 +15,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: "20" - name: Install & Build run: yarn && yarn build @@ -24,3 +24,11 @@ jobs: run: | yarn lint yarn test + env: + NODE_URL: https://rpc2.sepolia.org + SCAN_URL: https://sepolia.etherscan.io + GAS_STATION_URL: https://sepolia.beaconcha.in/api/v1/execution/gasnow + + NEAR_MULTICHAIN_CONTRACT: multichain-testnet-2.testnet + NEAR_ACCOUNT_ID: ${{secrets.NEAR_ACCOUNT_ID}} + NEAR_ACCOUNT_PRIVATE_KEY: ${{secrets.NEAR_PK}} diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index ae00b70..994b4e7 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,6 +1,6 @@ import { setupNearEthAdapter } from "../examples/setup"; -describe.skip("End To End", () => { +describe("End To End", () => { it("Runs the Send ETH Tx", async () => { const evm = await setupNearEthAdapter(); await evm.signAndSendTransaction({ diff --git a/tests/ethereum.test.ts b/tests/ethereum.test.ts deleted file mode 100644 index b2b4c81..0000000 --- a/tests/ethereum.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { setupNearEthAdapter } from "../examples/setup"; -import { NearEthAdapter } from "../src"; - -const ONE_ADDRESS = "0x1111111111111111111111111111111111111111"; - -describe.skip("Near Eth Adapter", () => { - let adapter: NearEthAdapter; - - beforeAll(async () => { - adapter = await setupNearEthAdapter(); - }); - it("createTxPayload", async () => { - const { signArgs } = await adapter.createTxPayload( - { - to: ONE_ADDRESS, - value: 1n, - data: "0x", - }, - 1 - ); - console.log(signArgs.payload); - expect(signArgs).toEqual({ - payload: [ - 205, 122, 162, 139, 210, 184, 225, 242, 45, 225, 52, 204, 240, 116, 140, - 27, 73, 166, 251, 122, 197, 60, 24, 147, 125, 132, 132, 195, 131, 39, - 57, 189, - ], - }); - }); -}); From 8589503e030ef09b9b24174a2efd7d7f91ae8fa8 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Fri, 12 Apr 2024 11:04:00 +0200 Subject: [PATCH 06/10] remove unnecessary async --- src/chains/ethereum.ts | 2 +- src/utils/transaction.ts | 67 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 7e3855b..cd070b3 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -147,7 +147,7 @@ export class NearEthAdapter { const transaction = await this.buildTransaction(tx, nonce); console.log("Built (unsigned) Transaction", transaction); const signArgs = { - payload: await buildTxPayload(transaction), + payload: buildTxPayload(transaction), path: this.derivationPath, key_version: 0, }; diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 32b667d..f4a4ba2 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -1,16 +1,21 @@ import { Address, Hex, + RecoverPublicKeyParameters, + RecoverPublicKeyReturnType, bytesToHex, hexToBytes, + hexToNumber, + isHex, keccak256, parseTransaction, - recoverPublicKey, serializeTransaction, signatureToHex, + toHex, } from "viem"; import { TransactionWithSignature } from "../types"; import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; +import { secp256k1 } from "@noble/curves/secp256k1"; export function ethersJsAddSignature( tx: TransactionWithSignature, @@ -56,7 +61,7 @@ export async function viemAddSig( // v: tx.v!, yParity: tx.yParity!, }); - const pk = await recoverPublicKey({ + const pk = recoverPublicKey({ hash: serializeTransaction(tx), signature, }); @@ -76,10 +81,60 @@ export async function addSignature( return viemAddSig(tx, sender); } -export async function buildTxPayload( - unsignedTxHash: `0x${string}` -): Promise { +export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] { // Compute the Transaction Message Hash. - const messageHash = await keccak256(unsignedTxHash); + const messageHash = keccak256(unsignedTxHash); return Array.from(hexToBytes(messageHash).slice().reverse()); } + +// This method is +export function recoverPublicKey({ + hash, + signature, +}: RecoverPublicKeyParameters): RecoverPublicKeyReturnType { + const signatureHex = isHex(signature) ? signature : toHex(signature); + const hashHex = isHex(hash) ? hash : toHex(hash); + + // Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message) + // The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1]. + let v = hexToNumber(`0x${signatureHex.slice(130)}`); + if (v === 0 || v === 1) v += 27; + + const publicKey = secp256k1.Signature.fromCompact( + signatureHex.substring(2, 130) + ) + .addRecoveryBit(v - 27) + .recoverPublicKey(hashHex.substring(2)) + .toHex(false); + return `0x${publicKey}`; +} + +// export function getSenderPublicKey(tx: LegacyTxInterface): Uint8Array { +// if (tx.cache.senderPubKey !== undefined) { +// return tx.cache.senderPubKey +// } + +// const msgHash = tx.getMessageToVerifySignature() + +// const { v, r, s } = tx + +// validateHighS(tx) + +// try { +// const ecrecoverFunction = tx.common.customCrypto.ecrecover ?? ecrecover +// const sender = ecrecoverFunction( +// msgHash, +// v!, +// bigIntToUnpaddedBytes(r!), +// bigIntToUnpaddedBytes(s!), +// tx.supports(Capability.EIP155ReplayProtection) ? tx.common.chainId() : undefined +// ) +// if (Object.isFrozen(tx)) { +// tx.cache.senderPubKey = sender +// } +// return sender +// } catch (e: any) { +// const msg = errorMsg(tx, 'Invalid Signature') +// throw new Error(msg) +// } +// } From 700d1c418278d4dccee6d79ace4c5171948d5afd Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Fri, 12 Apr 2024 16:47:04 +0200 Subject: [PATCH 07/10] isolating error --- src/utils/transaction.ts | 116 +++++++++++--------------------- tests/e2e.test.ts | 2 +- tests/utils.transaction.test.ts | 35 +++++----- 3 files changed, 61 insertions(+), 92 deletions(-) diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index f4a4ba2..62d44cb 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -1,39 +1,46 @@ import { Address, Hex, - RecoverPublicKeyParameters, - RecoverPublicKeyReturnType, bytesToHex, hexToBytes, hexToNumber, - isHex, keccak256, parseTransaction, serializeTransaction, signatureToHex, - toHex, + hexToBigInt, } from "viem"; import { TransactionWithSignature } from "../types"; -import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; import { secp256k1 } from "@noble/curves/secp256k1"; +import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; + +export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] { + // Compute the Transaction Message Hash. + const messageHash = keccak256(unsignedTxHash); + return Array.from(hexToBytes(messageHash).slice().reverse()); +} export function ethersJsAddSignature( tx: TransactionWithSignature, sender: Address ): Hex { - const { transaction: unsignedTxHash, signature: sig } = tx; + const { + transaction: unsignedTxHash, + signature: { big_r, big_s }, + } = tx; const transaction = FeeMarketEIP1559Transaction.fromSerializedTx( hexToBytes(unsignedTxHash) ); - const r = Buffer.from(sig.big_r.substring(2), "hex"); - const s = Buffer.from(sig.big_s, "hex"); + const r = hexToBigInt(`0x${big_r.substring(2)}`); + const s = hexToBigInt(`0x${big_s}`); const candidates = [0n, 1n].map((v) => transaction.addSignature(v, r, s)); - const signature = candidates.find( - (c) => + const signature = candidates.find((c) => { + return ( c.getSenderAddress().toString().toLowerCase() === sender.toString().toLowerCase() - ); + ); + }); if (!signature) { throw new Error("Signature is not valid"); @@ -41,16 +48,19 @@ export function ethersJsAddSignature( return bytesToHex(signature.serialize()); } -export async function viemAddSig( - { transaction, signature: sig }: TransactionWithSignature, +export function viemAddSig( + { transaction, signature: { big_r, big_s } }: TransactionWithSignature, sender: Address -): Promise { +): Hex { const txData = parseTransaction(transaction); + const r = `0x${big_r.substring(2)}` as Hex; + const s = `0x${big_s}` as Hex; + const candidates = [0, 1].map((v) => { return { yParity: v, - r: `0x${sig.big_r.substring(2)}` as Hex, - s: `0x${sig.big_s}` as Hex, + r, + s, ...txData, }; }); @@ -58,13 +68,9 @@ export async function viemAddSig( const signature = signatureToHex({ r: tx.r!, s: tx.s!, - // v: tx.v!, yParity: tx.yParity!, }); - const pk = recoverPublicKey({ - hash: serializeTransaction(tx), - signature, - }); + const pk = recoverPublicKey(transaction, signature); return pk.toString().toLowerCase() === sender.toLowerCase(); }); if (!signature) { @@ -74,67 +80,25 @@ export async function viemAddSig( return serializeTransaction(signature); } -export async function addSignature( - tx: TransactionWithSignature, - sender: Address -): Promise { - return viemAddSig(tx, sender); -} - -export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] { - // Compute the Transaction Message Hash. - const messageHash = keccak256(unsignedTxHash); - return Array.from(hexToBytes(messageHash).slice().reverse()); -} - -// This method is -export function recoverPublicKey({ - hash, - signature, -}: RecoverPublicKeyParameters): RecoverPublicKeyReturnType { - const signatureHex = isHex(signature) ? signature : toHex(signature); - const hashHex = isHex(hash) ? hash : toHex(hash); +// export function addSignature( +// tx: TransactionWithSignature, +// sender: Address +// ): Hex { +// return viemAddSig(tx, sender); +// } +// This method is mostly pasted from viem since they use an unnecessary async import. +// import { secp256k1 } from "@noble/curves/secp256k1"; +// Somehow this method also seems to return the wrong parity... +export function recoverPublicKey(hash: Hex, signature: Hex): Hex { // Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message) // The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1]. - let v = hexToNumber(`0x${signatureHex.slice(130)}`); + let v = hexToNumber(`0x${signature.slice(130)}`); if (v === 0 || v === 1) v += 27; - const publicKey = secp256k1.Signature.fromCompact( - signatureHex.substring(2, 130) - ) + const publicKey = secp256k1.Signature.fromCompact(signature.substring(2, 130)) .addRecoveryBit(v - 27) - .recoverPublicKey(hashHex.substring(2)) + .recoverPublicKey(hash.substring(2)) .toHex(false); return `0x${publicKey}`; } - -// export function getSenderPublicKey(tx: LegacyTxInterface): Uint8Array { -// if (tx.cache.senderPubKey !== undefined) { -// return tx.cache.senderPubKey -// } - -// const msgHash = tx.getMessageToVerifySignature() - -// const { v, r, s } = tx - -// validateHighS(tx) - -// try { -// const ecrecoverFunction = tx.common.customCrypto.ecrecover ?? ecrecover -// const sender = ecrecoverFunction( -// msgHash, -// v!, -// bigIntToUnpaddedBytes(r!), -// bigIntToUnpaddedBytes(s!), -// tx.supports(Capability.EIP155ReplayProtection) ? tx.common.chainId() : undefined -// ) -// if (Object.isFrozen(tx)) { -// tx.cache.senderPubKey = sender -// } -// return sender -// } catch (e: any) { -// const msg = errorMsg(tx, 'Invalid Signature') -// throw new Error(msg) -// } -// } diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 994b4e7..ae00b70 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,6 +1,6 @@ import { setupNearEthAdapter } from "../examples/setup"; -describe("End To End", () => { +describe.skip("End To End", () => { it("Runs the Send ETH Tx", async () => { const evm = await setupNearEthAdapter(); await evm.signAndSendTransaction({ diff --git a/tests/utils.transaction.test.ts b/tests/utils.transaction.test.ts index ad09679..ad43256 100644 --- a/tests/utils.transaction.test.ts +++ b/tests/utils.transaction.test.ts @@ -1,7 +1,20 @@ import { TransactionWithSignature } from "../src"; -import { addSignature, buildTxPayload } from "../src/utils/transaction"; +import { + ethersJsAddSignature, + viemAddSig, + buildTxPayload, +} from "../src/utils/transaction"; describe("Transaction Builder Functions", () => { + it("buildTxPayload", async () => { + const txHash = + "0x02e783aa36a7808309e8bb84773f7cbb8094deadbeef0000000000000000000000000b00b1e50180c0"; + const payload = await buildTxPayload(txHash); + expect(payload).toEqual([ + 178, 243, 90, 239, 203, 210, 59, 212, 215, 225, 70, 217, 13, 214, 94, 37, + 36, 9, 101, 199, 230, 132, 140, 98, 211, 7, 68, 130, 233, 88, 145, 179, + ]); + }); it("addSignature", async () => { const testTx: TransactionWithSignature = { transaction: @@ -14,22 +27,14 @@ describe("Transaction Builder Functions", () => { }, }; const sender = "0xa61d98854f7ab25402e3d12548a2e93a080c1f97"; - const signature = await addSignature(testTx, sender); // This does not agree with: // try ethersJsAddSignature(testTx, sender)! // which says that vByte should be "01"!!! - const vByte = "80"; - expect(signature).toEqual( - `0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0${vByte}a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8` - ); - }); - it("buildTxPayload", async () => { - const txHash = - "0x02e783aa36a7808309e8bb84773f7cbb8094deadbeef0000000000000000000000000b00b1e50180c0"; - const payload = await buildTxPayload(txHash); - expect(payload).toEqual([ - 178, 243, 90, 239, 203, 210, 59, 212, 215, 225, 70, 217, 13, 214, 94, 37, - 36, 9, 101, 199, 230, 132, 140, 98, 211, 7, 68, 130, 233, 88, 145, 179, - ]); + expect(viemAddSig(testTx, sender)).toEqual(expectedSig("80")); + expect(ethersJsAddSignature(testTx, sender)).toEqual(expectedSig("01")); }); }); + +function expectedSig(vByte: string): `0x${string}` { + return `0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0${vByte}a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8`; +} From 27578154051f753187993a4389f71a7f2107141f Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 15 Apr 2024 12:24:08 +0200 Subject: [PATCH 08/10] finally fixed signing! --- package.json | 1 - src/chains/ethereum.ts | 6 ++-- src/utils/transaction.ts | 64 ++++++++------------------------- tests/utils.transaction.test.ts | 18 +++------- yarn.lock | 32 +---------------- 5 files changed, 22 insertions(+), 99 deletions(-) diff --git a/package.json b/package.json index 4c3ef7d..f02abef 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,6 @@ "typescript": "^5.4.2" }, "dependencies": { - "@ethereumjs/tx": "^5.3.0", "@near-js/accounts": "^1.0.4", "@near-js/crypto": "^1.2.1", "@near-js/keystores": "^0.0.9", diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index cd070b3..18a711d 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -17,7 +17,7 @@ import { import { MultichainContract } from "../mpcContract"; import BN from "bn.js"; import { queryGasPrice } from "../utils/gasPrice"; -import { buildTxPayload, ethersJsAddSignature } from "../utils/transaction"; +import { buildTxPayload, addSignature } from "../utils/transaction"; export class NearEthAdapter { private ethClient: PublicClient; @@ -185,9 +185,7 @@ export class NearEthAdapter { } reconstructSignature(tx: TransactionWithSignature): Hex { - // TODO - replace with viemAddSignature! - // Its off by a single byte. - return ethersJsAddSignature(tx, this.sender); + return addSignature(tx, this.sender); } /** diff --git a/src/utils/transaction.ts b/src/utils/transaction.ts index 62d44cb..5fc5502 100644 --- a/src/utils/transaction.ts +++ b/src/utils/transaction.ts @@ -1,18 +1,17 @@ import { Address, Hex, - bytesToHex, hexToBytes, hexToNumber, keccak256, parseTransaction, serializeTransaction, signatureToHex, - hexToBigInt, } from "viem"; import { TransactionWithSignature } from "../types"; import { secp256k1 } from "@noble/curves/secp256k1"; -import { FeeMarketEIP1559Transaction } from "@ethereumjs/tx"; + +import { publicKeyToAddress } from "viem/utils"; export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] { // Compute the Transaction Message Hash. @@ -20,35 +19,7 @@ export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] { return Array.from(hexToBytes(messageHash).slice().reverse()); } -export function ethersJsAddSignature( - tx: TransactionWithSignature, - sender: Address -): Hex { - const { - transaction: unsignedTxHash, - signature: { big_r, big_s }, - } = tx; - const transaction = FeeMarketEIP1559Transaction.fromSerializedTx( - hexToBytes(unsignedTxHash) - ); - const r = hexToBigInt(`0x${big_r.substring(2)}`); - const s = hexToBigInt(`0x${big_s}`); - - const candidates = [0n, 1n].map((v) => transaction.addSignature(v, r, s)); - const signature = candidates.find((c) => { - return ( - c.getSenderAddress().toString().toLowerCase() === - sender.toString().toLowerCase() - ); - }); - - if (!signature) { - throw new Error("Signature is not valid"); - } - return bytesToHex(signature.serialize()); -} - -export function viemAddSig( +export function addSignature( { transaction, signature: { big_r, big_s } }: TransactionWithSignature, sender: Address ): Hex { @@ -56,40 +27,35 @@ export function viemAddSig( const r = `0x${big_r.substring(2)}` as Hex; const s = `0x${big_s}` as Hex; - const candidates = [0, 1].map((v) => { + const candidates = [27n, 28n].map((v) => { return { - yParity: v, + v, r, s, ...txData, }; }); - const signature = candidates.find(async (tx) => { + + const signedTx = candidates.find((tx) => { const signature = signatureToHex({ r: tx.r!, s: tx.s!, - yParity: tx.yParity!, + v: tx.v!, }); - const pk = recoverPublicKey(transaction, signature); - return pk.toString().toLowerCase() === sender.toLowerCase(); + const pk = publicKeyToAddress( + recoverPublicKey(keccak256(transaction), signature) + ); + return pk.toLowerCase() === sender.toLowerCase(); }); - if (!signature) { + if (!signedTx) { throw new Error("Signature is not valid"); } - - return serializeTransaction(signature); + return serializeTransaction(signedTx); } -// export function addSignature( -// tx: TransactionWithSignature, -// sender: Address -// ): Hex { -// return viemAddSig(tx, sender); -// } - // This method is mostly pasted from viem since they use an unnecessary async import. // import { secp256k1 } from "@noble/curves/secp256k1"; -// Somehow this method also seems to return the wrong parity... +// TODO - fix their async import! export function recoverPublicKey(hash: Hex, signature: Hex): Hex { // Derive v = recoveryId + 27 from end of the signature (27 is added when signing the message) // The recoveryId represents the y-coordinate on the secp256k1 elliptic curve and can have a value [0, 1]. diff --git a/tests/utils.transaction.test.ts b/tests/utils.transaction.test.ts index ad43256..a79bde7 100644 --- a/tests/utils.transaction.test.ts +++ b/tests/utils.transaction.test.ts @@ -1,9 +1,5 @@ import { TransactionWithSignature } from "../src"; -import { - ethersJsAddSignature, - viemAddSig, - buildTxPayload, -} from "../src/utils/transaction"; +import { buildTxPayload, addSignature } from "../src/utils/transaction"; describe("Transaction Builder Functions", () => { it("buildTxPayload", async () => { @@ -27,14 +23,8 @@ describe("Transaction Builder Functions", () => { }, }; const sender = "0xa61d98854f7ab25402e3d12548a2e93a080c1f97"; - // This does not agree with: - // try ethersJsAddSignature(testTx, sender)! - // which says that vByte should be "01"!!! - expect(viemAddSig(testTx, sender)).toEqual(expectedSig("80")); - expect(ethersJsAddSignature(testTx, sender)).toEqual(expectedSig("01")); + expect(addSignature(testTx, sender)).toEqual( + "0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c001a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8" + ); }); }); - -function expectedSig(vByte: string): `0x${string}` { - return `0x02f86b83aa36a780845974e6f084d0aa7af08094deadbeef0000000000000000000000000b00b1e50180c0${vByte}a0ef532579e267c932b959a1adb9e455ac3c5397d0473471c4c3dd5d62fd4d7edea07c195e658c713d601d245311a259115bb91ec87c86acb07c03bd9c1936a6a9e8`; -} diff --git a/yarn.lock b/yarn.lock index 1e426d1..2e17452 100644 --- a/yarn.lock +++ b/yarn.lock @@ -352,33 +352,11 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.57.0.tgz#a5417ae8427873f1dd08b70b3574b453e67b5f7f" integrity sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g== -"@ethereumjs/common@^4.3.0": - version "4.3.0" - resolved "https://registry.yarnpkg.com/@ethereumjs/common/-/common-4.3.0.tgz#5b45eec7dcf521fa4ddaf0b383072fbcf9913553" - integrity sha512-shBNJ0ewcPNTUfZduHiczPmqkfJDn0Dh/9BR5fq7xUFTuIq7Fu1Vx00XDwQVIrpVL70oycZocOhBM6nDO+4FEQ== - dependencies: - "@ethereumjs/util" "^9.0.3" - "@ethereumjs/rlp@^4.0.1": version "4.0.1" resolved "https://registry.yarnpkg.com/@ethereumjs/rlp/-/rlp-4.0.1.tgz#626fabfd9081baab3d0a3074b0c7ecaf674aaa41" integrity sha512-tqsQiBQDQdmPWE1xkkBq4rlSW5QZpLOUJ5RJh2/9fug+q9tnUhuZoVLk7s0scUIKTOzEtR72DFBXI4WiZcMpvw== -"@ethereumjs/rlp@^5.0.2": - version "5.0.2" - resolved "https://registry.yarnpkg.com/@ethereumjs/rlp/-/rlp-5.0.2.tgz#c89bd82f2f3bec248ab2d517ae25f5bbc4aac842" - integrity sha512-DziebCdg4JpGlEqEdGgXmjqcFoJi+JGulUXwEjsZGAscAQ7MyD/7LE/GVCP29vEQxKc7AAwjT3A2ywHp2xfoCA== - -"@ethereumjs/tx@^5.3.0": - version "5.3.0" - resolved "https://registry.yarnpkg.com/@ethereumjs/tx/-/tx-5.3.0.tgz#473f351729ef4e30eaa3a3fb5aaccd4405a7ee41" - integrity sha512-uv++XYuIfuqYbvymL3/o14hHuC6zX0nRQ1nI2FHsbkkorLZ2ChEIDqVeeVk7Xc9/jQNU/22sk9qZZkRlsveXxw== - dependencies: - "@ethereumjs/common" "^4.3.0" - "@ethereumjs/rlp" "^5.0.2" - "@ethereumjs/util" "^9.0.3" - ethereum-cryptography "^2.1.3" - "@ethereumjs/util@^8.1.0": version "8.1.0" resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-8.1.0.tgz#299df97fb6b034e0577ce9f94c7d9d1004409ed4" @@ -388,14 +366,6 @@ ethereum-cryptography "^2.0.0" micro-ftch "^0.3.1" -"@ethereumjs/util@^9.0.3": - version "9.0.3" - resolved "https://registry.yarnpkg.com/@ethereumjs/util/-/util-9.0.3.tgz#c2709e6127a85bbe23a71937ac78358ac93e7241" - integrity sha512-PmwzWDflky+7jlZIFqiGsBPap12tk9zK5SVH9YW2OEnDN7OEhCjUOMzbOqwuClrbkSIkM2ERivd7sXZ48Rh/vg== - dependencies: - "@ethereumjs/rlp" "^5.0.2" - ethereum-cryptography "^2.1.3" - "@humanwhocodes/config-array@^0.11.14": version "0.11.14" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.14.tgz#d78e481a039f7566ecc9660b4ea7fe6b1fec442b" @@ -1864,7 +1834,7 @@ ethereum-bloom-filters@^1.0.6: dependencies: js-sha3 "^0.8.0" -ethereum-cryptography@^2.0.0, ethereum-cryptography@^2.1.2, ethereum-cryptography@^2.1.3: +ethereum-cryptography@^2.0.0, ethereum-cryptography@^2.1.2: version "2.1.3" resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-2.1.3.tgz#1352270ed3b339fe25af5ceeadcf1b9c8e30768a" integrity sha512-BlwbIL7/P45W8FGW2r7LGuvoEZ+7PWsniMvQ4p5s2xCyw9tmaDlpfsN9HjAucbF+t/qpVHwZUisgfK24TCW8aA== From f8a2a13eaf0450113351f9655a1b4de5f6bb7d8f Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 15 Apr 2024 12:29:47 +0200 Subject: [PATCH 09/10] update lock file --- tests/e2e.test.ts | 2 +- yarn.lock | 444 ++++++++++++++++++++++++++++++---------------- 2 files changed, 289 insertions(+), 157 deletions(-) diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index ae00b70..994b4e7 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,6 +1,6 @@ import { setupNearEthAdapter } from "../examples/setup"; -describe.skip("End To End", () => { +describe("End To End", () => { it("Runs the Send ETH Tx", async () => { const evm = await setupNearEthAdapter(); await evm.signAndSendTransaction({ diff --git a/yarn.lock b/yarn.lock index 2e17452..b305817 100644 --- a/yarn.lock +++ b/yarn.lock @@ -34,22 +34,22 @@ picocolors "^1.0.0" "@babel/compat-data@^7.23.5": - version "7.24.1" - resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.24.1.tgz#31c1f66435f2a9c329bb5716a6d6186c516c3742" - integrity sha512-Pc65opHDliVpRHuKfzI+gSA4zcgr65O4cl64fFJIWEEh8JoHIHh0Oez1Eo8Arz8zq/JhgKodQaxEwUPRtZylVA== + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.24.4.tgz#6f102372e9094f25d908ca0d34fc74c74606059a" + integrity sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ== "@babel/core@^7.11.6", "@babel/core@^7.12.3", "@babel/core@^7.23.9": - version "7.24.3" - resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.24.3.tgz#568864247ea10fbd4eff04dda1e05f9e2ea985c3" - integrity sha512-5FcvN1JHw2sHJChotgx8Ek0lyuh4kCKelgMTTqhYJJtloNvUfpAFMeNQUtdlIaktwrSV9LtCdqwk48wL2wBacQ== + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.24.4.tgz#1f758428e88e0d8c563874741bc4ffc4f71a4717" + integrity sha512-MBVlMXP+kkl5394RBLSxxk/iLTeVGuXTV3cIDXavPpMMqnSnt6apKgan/U8O3USWZCWZT/TbgfEpKa4uMgN4Dg== dependencies: "@ampproject/remapping" "^2.2.0" "@babel/code-frame" "^7.24.2" - "@babel/generator" "^7.24.1" + "@babel/generator" "^7.24.4" "@babel/helper-compilation-targets" "^7.23.6" "@babel/helper-module-transforms" "^7.23.3" - "@babel/helpers" "^7.24.1" - "@babel/parser" "^7.24.1" + "@babel/helpers" "^7.24.4" + "@babel/parser" "^7.24.4" "@babel/template" "^7.24.0" "@babel/traverse" "^7.24.1" "@babel/types" "^7.24.0" @@ -59,10 +59,10 @@ json5 "^2.2.3" semver "^6.3.1" -"@babel/generator@^7.24.1", "@babel/generator@^7.7.2": - version "7.24.1" - resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.24.1.tgz#e67e06f68568a4ebf194d1c6014235344f0476d0" - integrity sha512-DfCRfZsBcrPEHUfuBMgbJ1Ut01Y/itOs+hY2nFLgqsqXd52/iSiVq5TITtUasIUgm+IIKdY2/1I7auiQOEeC9A== +"@babel/generator@^7.24.1", "@babel/generator@^7.24.4", "@babel/generator@^7.7.2": + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.24.4.tgz#1fc55532b88adf952025d5d2d1e71f946cb1c498" + integrity sha512-Xd6+v6SnjWVx/nus+y0l1sxMOTOMBkyL4+BIdbALyatQnAe/SRVjANeDPSCYaX+i1iJmuGSKf3Z+E+V/va1Hvw== dependencies: "@babel/types" "^7.24.0" "@jridgewell/gen-mapping" "^0.3.5" @@ -152,10 +152,10 @@ resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz#907a3fbd4523426285365d1206c423c4c5520307" integrity sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw== -"@babel/helpers@^7.24.1": - version "7.24.1" - resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.24.1.tgz#183e44714b9eba36c3038e442516587b1e0a1a94" - integrity sha512-BpU09QqEe6ZCHuIHFphEFgvNSrubve1FtyMton26ekZ85gRGi6LrTF7zArARp2YvyFxloeiRmtSCq5sjh1WqIg== +"@babel/helpers@^7.24.4": + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.24.4.tgz#dc00907fd0d95da74563c142ef4cd21f2cb856b6" + integrity sha512-FewdlZbSiwaVGlgT1DPANDuCHaDMiOo+D/IDYRFYjHOuv66xMSJ7fQwwODwRNAPkADIO/z1EoF/l2BCWlWABDw== dependencies: "@babel/template" "^7.24.0" "@babel/traverse" "^7.24.1" @@ -171,10 +171,10 @@ js-tokens "^4.0.0" picocolors "^1.0.0" -"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.24.0", "@babel/parser@^7.24.1": - version "7.24.1" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.24.1.tgz#1e416d3627393fab1cb5b0f2f1796a100ae9133a" - integrity sha512-Zo9c7N3xdOIQrNip7Lc9wvRPzlRtovHVE4lkz8WEDr7uYh/GMQhSiIgFxGIArRHYdJE5kxtZjAf8rT0xhdLCzg== +"@babel/parser@^7.1.0", "@babel/parser@^7.14.7", "@babel/parser@^7.20.7", "@babel/parser@^7.23.9", "@babel/parser@^7.24.0", "@babel/parser@^7.24.1", "@babel/parser@^7.24.4": + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.24.4.tgz#234487a110d89ad5a3ed4a8a566c36b9453e8c88" + integrity sha512-zTvEBcghmeBma9QIGunWevvBAp4/Qu9Bdq+2k0Ot4fVMD6v3dsC9WOcRSKk7tRRyBM/53yKMJko9xOatGQAwSg== "@babel/plugin-syntax-async-generators@^7.8.4": version "7.8.4" @@ -327,7 +327,7 @@ dependencies: eslint-visitor-keys "^3.3.0" -"@eslint-community/regexpp@^4.5.1", "@eslint-community/regexpp@^4.6.1": +"@eslint-community/regexpp@^4.10.0", "@eslint-community/regexpp@^4.6.1": version "4.10.0" resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.10.0.tgz#548f6de556857c8bb73bbee70c35dc82a2e74d63" integrity sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA== @@ -381,9 +381,9 @@ integrity sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA== "@humanwhocodes/object-schema@^2.0.2": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.2.tgz#d9fae00a2d5cb40f92cfe64b47ad749fbc38f917" - integrity sha512-6EwiSjwWYP7pTckG6I5eyFANjPhmPjUX9JRLUSfNPC7FX7zK9gyZAfUEaECL6ALTpGX5AjnBq3C9XmVWPitNpw== + version "2.0.3" + resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz#4a2868d75d6d6963e423bcf90b7fd1be343409d3" + integrity sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA== "@istanbuljs/load-nyc-config@^1.0.0": version "1.1.0" @@ -633,7 +633,7 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@near-js/accounts@1.0.4", "@near-js/accounts@^1.0.4": +"@near-js/accounts@1.0.4": version "1.0.4" resolved "https://registry.yarnpkg.com/@near-js/accounts/-/accounts-1.0.4.tgz#b699dc1c63ffccc1598481b4260dfaf2507f0a69" integrity sha512-6zgSwq/rQ9ggPOIkGUx9RoEurbJiojqA/axeh6o1G+46GqUBI7SUcDooyVvZjeiOvUPObnTQptDYpbV+XZji8g== @@ -652,7 +652,24 @@ lru_map "0.4.1" near-abi "0.1.1" -"@near-js/crypto@1.2.1", "@near-js/crypto@^1.2.1": +"@near-js/accounts@^1.0.4": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@near-js/accounts/-/accounts-1.1.0.tgz#9adfa02c57aa5a5e0d9df5388321e725b94c18aa" + integrity sha512-YYudGgVepuWsLfusslj423IqH31A1YNS10ETgrg5zT8HEYUPpkevsdCAKslaihjQUAV6TVZ6bb3BjT7skoDMOg== + dependencies: + "@near-js/crypto" "1.2.2" + "@near-js/providers" "0.2.0" + "@near-js/signers" "0.1.2" + "@near-js/transactions" "1.2.0" + "@near-js/types" "0.1.0" + "@near-js/utils" "0.2.0" + borsh "1.0.0" + depd "2.0.0" + is-my-json-valid "^2.20.6" + lru_map "0.4.1" + near-abi "0.1.1" + +"@near-js/crypto@1.2.1": version "1.2.1" resolved "https://registry.yarnpkg.com/@near-js/crypto/-/crypto-1.2.1.tgz#aa18bed171e68653dae9f82114636eba34ece32a" integrity sha512-iJOHaGKvdudYfR8nEtRhGlgcTEHeVmxMoT0JVXmuP3peG96v/sSnA03CE6MZBeCC8txKAQOffagxE7oU6hJp9g== @@ -664,6 +681,17 @@ borsh "1.0.0" randombytes "2.1.0" +"@near-js/crypto@1.2.2", "@near-js/crypto@^1.2.1": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@near-js/crypto/-/crypto-1.2.2.tgz#1e36e624151ad7f546f9870c9953abfb848a1f37" + integrity sha512-a/1SICBPg6zo+VGOy+HT448+uHXmlYnP4vwNUdJnmn0yMksi30G1N8BSU5tnP1SX904EASu1pdqSMWslERrCQw== + dependencies: + "@near-js/types" "0.1.0" + "@near-js/utils" "0.2.0" + "@noble/curves" "1.2.0" + borsh "1.0.0" + randombytes "2.1.0" + "@near-js/keystores-browser@0.0.9": version "0.0.9" resolved "https://registry.yarnpkg.com/@near-js/keystores-browser/-/keystores-browser-0.0.9.tgz#4d6211ad617613124aeee78ede5771b153e3bcdd" @@ -680,6 +708,14 @@ "@near-js/crypto" "1.2.1" "@near-js/keystores" "0.0.9" +"@near-js/keystores@0.0.10": + version "0.0.10" + resolved "https://registry.yarnpkg.com/@near-js/keystores/-/keystores-0.0.10.tgz#6e18b917c3ab7c660e42e2b15eb835ca91aa7dcd" + integrity sha512-rzGMkqY7EcIbUPrcSjK1RJi3dTXusfmZcxg2Jcc9u7VVjEjP/HVnvVaazsYC1la7812VSrDPxqHsZRzWSFxtMA== + dependencies: + "@near-js/crypto" "1.2.2" + "@near-js/types" "0.1.0" + "@near-js/keystores@0.0.9", "@near-js/keystores@^0.0.9": version "0.0.9" resolved "https://registry.yarnpkg.com/@near-js/keystores/-/keystores-0.0.9.tgz#768aaaab1beb7f797432513cb1bbf9430e305a85" @@ -702,6 +738,19 @@ optionalDependencies: node-fetch "2.6.7" +"@near-js/providers@0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@near-js/providers/-/providers-0.2.0.tgz#31408576cb0d5d8499e780a987bc0a90a1a6855c" + integrity sha512-K7RJTkVbn6SD68p/8TkxFjp6jhxNQrkjZ+etQxrBRAMS6kupLTobV+9AfAc1OaORO47X873p4BRhbm9KhCdmZg== + dependencies: + "@near-js/transactions" "1.2.0" + "@near-js/types" "0.1.0" + "@near-js/utils" "0.2.0" + borsh "1.0.0" + http-errors "1.7.2" + optionalDependencies: + node-fetch "2.6.7" + "@near-js/signers@0.1.1": version "0.1.1" resolved "https://registry.yarnpkg.com/@near-js/signers/-/signers-0.1.1.tgz#6d32b262eac9b03fab5fc1ee93d2c4055c86980f" @@ -711,6 +760,15 @@ "@near-js/keystores" "0.0.9" "@noble/hashes" "1.3.3" +"@near-js/signers@0.1.2": + version "0.1.2" + resolved "https://registry.yarnpkg.com/@near-js/signers/-/signers-0.1.2.tgz#766ce770c5c76eb95519daaf0d887101d4349eb1" + integrity sha512-Echz+ldAFUDGntiBcnCZN4scHBIccz6xVC0Zt9cZu9I4SGKrWga0vNfAwXGVGep8YCEu8MwI9lE2B5n2ouc6kg== + dependencies: + "@near-js/crypto" "1.2.2" + "@near-js/keystores" "0.0.10" + "@noble/hashes" "1.3.3" + "@near-js/transactions@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@near-js/transactions/-/transactions-1.1.2.tgz#7dec18b463cd336e325ee61b1e1c39a6192d9e81" @@ -724,6 +782,18 @@ bn.js "5.2.1" borsh "1.0.0" +"@near-js/transactions@1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@near-js/transactions/-/transactions-1.2.0.tgz#781512d76cb54d1289954e64e1e6344073ac7fc3" + integrity sha512-I9UVVPg0HHQUpL17tb9L1HgTMG5+KREI2mNQlvJhF5uE6DrI2tC/O4rQf3HZOUVWpUhOiXSKRfSXpgZq5TbXaw== + dependencies: + "@near-js/crypto" "1.2.2" + "@near-js/signers" "0.1.2" + "@near-js/types" "0.1.0" + "@near-js/utils" "0.2.0" + "@noble/hashes" "1.3.3" + borsh "1.0.0" + "@near-js/types@0.0.4": version "0.0.4" resolved "https://registry.yarnpkg.com/@near-js/types/-/types-0.0.4.tgz#d941689df41c850aeeeaeb9d498418acec515404" @@ -731,6 +801,11 @@ dependencies: bn.js "5.2.1" +"@near-js/types@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@near-js/types/-/types-0.1.0.tgz#d8cb35763571f6794af6c9eb2eee158003930c35" + integrity sha512-uQTB3G7251cKCFhM4poAgypTODb83jrqD5A5B0Nr89TAGbsYM2ozXJyffJpsWedbYhK527Jx/BFgs+Jzf3oO5g== + "@near-js/utils@0.1.0": version "0.1.0" resolved "https://registry.yarnpkg.com/@near-js/utils/-/utils-0.1.0.tgz#1368f59008c39df1e903bd3e0f308eedcdf25c1d" @@ -742,6 +817,16 @@ depd "2.0.0" mustache "4.0.0" +"@near-js/utils@0.2.0": + version "0.2.0" + resolved "https://registry.yarnpkg.com/@near-js/utils/-/utils-0.2.0.tgz#32d22ed64ae3b0740c2475e3a28dfce3a3f1236f" + integrity sha512-Ul0NoOiV/vW6hnkYVMwRNbP18hB7mCRkqgSe1a2Qoe+3xFOMnjLVVod3Y1l/QXgp4yNDrLOd6r4PDPI72eKUww== + dependencies: + "@near-js/types" "0.1.0" + bs58 "4.0.0" + depd "2.0.0" + mustache "4.0.0" + "@near-js/wallet-account@1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@near-js/wallet-account/-/wallet-account-1.1.1.tgz#e66e8d10fb51f71f7cb722bdff63fb98e2b0d486" @@ -758,9 +843,9 @@ borsh "1.0.0" "@near-wallet-selector/core@^8.9.5": - version "8.9.5" - resolved "https://registry.yarnpkg.com/@near-wallet-selector/core/-/core-8.9.5.tgz#15e49f17252ee4e54a1c9719b8c2b98fd71aae74" - integrity sha512-wJiCL8M7z6tkNMY5H4n63/SZCmlW0Z15H6R1biWgpRuMDlVjhQOzxrmQggb1jbK4nYkzXyARNKyPh2gcRUuS+w== + version "8.9.7" + resolved "https://registry.yarnpkg.com/@near-wallet-selector/core/-/core-8.9.7.tgz#d55cb97b8d4932f1bd786805c3365205cd084b61" + integrity sha512-WFAtNrA/w7gnobKmHGEqV4r/RtDM1QTf33TF0Kaf/1nK5jBNNyoYldyAPnbP08t1S+IbbVJ9NcWW3P7hdXe4Lg== dependencies: borsh "0.7.0" events "3.3.0" @@ -791,7 +876,7 @@ resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699" integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA== -"@noble/hashes@^1.2.0": +"@noble/hashes@^1.2.0", "@noble/hashes@^1.4.0": version "1.4.0" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.4.0.tgz#45814aa329f30e4fe0ba49426f49dfccdd066426" integrity sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg== @@ -817,10 +902,10 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@opensea/seaport-js@^3.0.0": - version "3.0.2" - resolved "https://registry.yarnpkg.com/@opensea/seaport-js/-/seaport-js-3.0.2.tgz#d1d4ccb0db6c67c4150e4213d768f7df9b096dc0" - integrity sha512-XtPzNZSOyF7cA1WdAvmSPyFR1d3bIhp6hdCc7i7djFvuNYN/xCTtHeN2jljm0jDNR0bcNCls989ZvZRbf1vRgA== +"@opensea/seaport-js@^4.0.0": + version "4.0.0" + resolved "https://registry.yarnpkg.com/@opensea/seaport-js/-/seaport-js-4.0.0.tgz#e519785e4441aa6b6870c4353721f0c9fbe25aa8" + integrity sha512-xL0kv4CDdtuuJd7w2zI+cWR0e33T10Y9Sor+R1e1DfBHfc8w0POcgCqG0LsyAM0ZuopuYw4gwYY1eVyoqLJfVg== dependencies: ethers "^6.9.0" merkletreejs "^0.3.11" @@ -884,9 +969,9 @@ "@sinonjs/commons" "^3.0.0" "@tsconfig/node10@^1.0.7": - version "1.0.9" - resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2" - integrity sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA== + version "1.0.11" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.11.tgz#6ee46400685f130e278128c7b38b7e031ff5b2f2" + integrity sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw== "@tsconfig/node12@^1.0.7": version "1.0.11" @@ -944,11 +1029,11 @@ "@types/node" "*" "@types/bun@latest": - version "1.0.10" - resolved "https://registry.yarnpkg.com/@types/bun/-/bun-1.0.10.tgz#a24287dab84a5f64de826c88c50b53bf522f3025" - integrity sha512-Jaz6YYAdm1u3NVlgSyEK+qGmrlLQ20sbWeEoXD64b9w6z/YKYNWlfaphu+xF2Kiy5Tpykm5Q9jIquLegwXx4ng== + version "1.0.12" + resolved "https://registry.yarnpkg.com/@types/bun/-/bun-1.0.12.tgz#75ef1728ffe069891271d1a7f5ef5daa95b6d365" + integrity sha512-qPb5FcygbpSS1NDBjWyQCWeI9kKXwSYSR1Enu7yb+gMXgFwGMhlyOvgV/7FGrdvAjlSXWRY6IDepos7k8WzAtQ== dependencies: - bun-types "1.0.33" + bun-types "1.0.36" "@types/elliptic@^6.4.18": version "6.4.18" @@ -991,7 +1076,7 @@ expect "^29.0.0" pretty-format "^29.0.0" -"@types/json-schema@^7.0.11", "@types/json-schema@^7.0.12": +"@types/json-schema@^7.0.11", "@types/json-schema@^7.0.15": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA== @@ -1003,10 +1088,10 @@ dependencies: "@types/node" "*" -"@types/node@*", "@types/node@^20.11.30", "@types/node@~20.11.3": - version "20.11.30" - resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.30.tgz#9c33467fc23167a347e73834f788f4b9f399d66f" - integrity sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw== +"@types/node@*", "@types/node@^20.11.30": + version "20.12.7" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.12.7.tgz#04080362fa3dd6c5822061aa3124f5c152cff384" + integrity sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg== dependencies: undici-types "~5.26.4" @@ -1015,7 +1100,14 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.13.tgz#f64277c341150c979e42b00e4ac289290c9df469" integrity sha512-N+0kuo9KgrUQ1Sn/ifDXsvg0TTleP7rIy4zOBGECxAljqvqfqpTfzx0Q1NUedOixRMBfe2Whhb056a42cWs26Q== -"@types/semver@^7.5.0": +"@types/node@~20.11.3": + version "20.11.30" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.30.tgz#9c33467fc23167a347e73834f788f4b9f399d66f" + integrity sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw== + dependencies: + undici-types "~5.26.4" + +"@types/semver@^7.5.8": version "7.5.8" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e" integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ== @@ -1045,90 +1137,90 @@ "@types/yargs-parser" "*" "@typescript-eslint/eslint-plugin@^7.2.0": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.3.1.tgz#0d8f38a6c8a1802139e62184ee7a68ed024f30a1" - integrity sha512-STEDMVQGww5lhCuNXVSQfbfuNII5E08QWkvAw5Qwf+bj2WT+JkG1uc+5/vXA3AOYMDHVOSpL+9rcbEUiHIm2dw== - dependencies: - "@eslint-community/regexpp" "^4.5.1" - "@typescript-eslint/scope-manager" "7.3.1" - "@typescript-eslint/type-utils" "7.3.1" - "@typescript-eslint/utils" "7.3.1" - "@typescript-eslint/visitor-keys" "7.3.1" + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.6.0.tgz#1f5df5cda490a0bcb6fbdd3382e19f1241024242" + integrity sha512-gKmTNwZnblUdnTIJu3e9kmeRRzV2j1a/LUO27KNNAnIC5zjy1aSvXSRp4rVNlmAoHlQ7HzX42NbKpcSr4jF80A== + dependencies: + "@eslint-community/regexpp" "^4.10.0" + "@typescript-eslint/scope-manager" "7.6.0" + "@typescript-eslint/type-utils" "7.6.0" + "@typescript-eslint/utils" "7.6.0" + "@typescript-eslint/visitor-keys" "7.6.0" debug "^4.3.4" graphemer "^1.4.0" - ignore "^5.2.4" + ignore "^5.3.1" natural-compare "^1.4.0" - semver "^7.5.4" - ts-api-utils "^1.0.1" + semver "^7.6.0" + ts-api-utils "^1.3.0" "@typescript-eslint/parser@^7.2.0": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.3.1.tgz#c4ba7dc2744318a5e4506596cbc3a0086255c526" - integrity sha512-Rq49+pq7viTRCH48XAbTA+wdLRrB/3sRq4Lpk0oGDm0VmnjBrAOVXH/Laalmwsv2VpekiEfVFwJYVk6/e8uvQw== - dependencies: - "@typescript-eslint/scope-manager" "7.3.1" - "@typescript-eslint/types" "7.3.1" - "@typescript-eslint/typescript-estree" "7.3.1" - "@typescript-eslint/visitor-keys" "7.3.1" + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.6.0.tgz#0aca5de3045d68b36e88903d15addaf13d040a95" + integrity sha512-usPMPHcwX3ZoPWnBnhhorc14NJw9J4HpSXQX4urF2TPKG0au0XhJoZyX62fmvdHONUkmyUe74Hzm1//XA+BoYg== + dependencies: + "@typescript-eslint/scope-manager" "7.6.0" + "@typescript-eslint/types" "7.6.0" + "@typescript-eslint/typescript-estree" "7.6.0" + "@typescript-eslint/visitor-keys" "7.6.0" debug "^4.3.4" -"@typescript-eslint/scope-manager@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.3.1.tgz#73fd0cb4211a7be23e49e5b6efec8820caa6ec36" - integrity sha512-fVS6fPxldsKY2nFvyT7IP78UO1/I2huG+AYu5AMjCT9wtl6JFiDnsv4uad4jQ0GTFzcUV5HShVeN96/17bTBag== +"@typescript-eslint/scope-manager@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.6.0.tgz#1e9972f654210bd7500b31feadb61a233f5b5e9d" + integrity sha512-ngttyfExA5PsHSx0rdFgnADMYQi+Zkeiv4/ZxGYUWd0nLs63Ha0ksmp8VMxAIC0wtCFxMos7Lt3PszJssG/E6w== dependencies: - "@typescript-eslint/types" "7.3.1" - "@typescript-eslint/visitor-keys" "7.3.1" + "@typescript-eslint/types" "7.6.0" + "@typescript-eslint/visitor-keys" "7.6.0" -"@typescript-eslint/type-utils@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.3.1.tgz#cbf90d3d7e788466aa8a5c0ab3f46103f098aa0d" - integrity sha512-iFhaysxFsMDQlzJn+vr3OrxN8NmdQkHks4WaqD4QBnt5hsq234wcYdyQ9uquzJJIDAj5W4wQne3yEsYA6OmXGw== +"@typescript-eslint/type-utils@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.6.0.tgz#644f75075f379827d25fe0713e252ccd4e4a428c" + integrity sha512-NxAfqAPNLG6LTmy7uZgpK8KcuiS2NZD/HlThPXQRGwz6u7MDBWRVliEEl1Gj6U7++kVJTpehkhZzCJLMK66Scw== dependencies: - "@typescript-eslint/typescript-estree" "7.3.1" - "@typescript-eslint/utils" "7.3.1" + "@typescript-eslint/typescript-estree" "7.6.0" + "@typescript-eslint/utils" "7.6.0" debug "^4.3.4" - ts-api-utils "^1.0.1" + ts-api-utils "^1.3.0" -"@typescript-eslint/types@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.3.1.tgz#ae104de8efa4227a462c0874d856602c5994413c" - integrity sha512-2tUf3uWggBDl4S4183nivWQ2HqceOZh1U4hhu4p1tPiIJoRRXrab7Y+Y0p+dozYwZVvLPRI6r5wKe9kToF9FIw== +"@typescript-eslint/types@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.6.0.tgz#53dba7c30c87e5f10a731054266dd905f1fbae38" + integrity sha512-h02rYQn8J+MureCvHVVzhl69/GAfQGPQZmOMjG1KfCl7o3HtMSlPaPUAPu6lLctXI5ySRGIYk94clD/AUMCUgQ== -"@typescript-eslint/typescript-estree@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.3.1.tgz#598848195fad34c7aa73f548bd00a4d4e5f5e2bb" - integrity sha512-tLpuqM46LVkduWP7JO7yVoWshpJuJzxDOPYIVWUUZbW+4dBpgGeUdl/fQkhuV0A8eGnphYw3pp8d2EnvPOfxmQ== +"@typescript-eslint/typescript-estree@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.6.0.tgz#112a3775563799fd3f011890ac8322f80830ac17" + integrity sha512-+7Y/GP9VuYibecrCQWSKgl3GvUM5cILRttpWtnAu8GNL9j11e4tbuGZmZjJ8ejnKYyBRb2ddGQ3rEFCq3QjMJw== dependencies: - "@typescript-eslint/types" "7.3.1" - "@typescript-eslint/visitor-keys" "7.3.1" + "@typescript-eslint/types" "7.6.0" + "@typescript-eslint/visitor-keys" "7.6.0" debug "^4.3.4" globby "^11.1.0" is-glob "^4.0.3" - minimatch "9.0.3" - semver "^7.5.4" - ts-api-utils "^1.0.1" + minimatch "^9.0.4" + semver "^7.6.0" + ts-api-utils "^1.3.0" -"@typescript-eslint/utils@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.3.1.tgz#fc28fd508ccf89495012561b7c02a6fdad162460" - integrity sha512-jIERm/6bYQ9HkynYlNZvXpzmXWZGhMbrOvq3jJzOSOlKXsVjrrolzWBjDW6/TvT5Q3WqaN4EkmcfdQwi9tDjBQ== +"@typescript-eslint/utils@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.6.0.tgz#e400d782280b6f724c8a1204269d984c79202282" + integrity sha512-x54gaSsRRI+Nwz59TXpCsr6harB98qjXYzsRxGqvA5Ue3kQH+FxS7FYU81g/omn22ML2pZJkisy6Q+ElK8pBCA== dependencies: "@eslint-community/eslint-utils" "^4.4.0" - "@types/json-schema" "^7.0.12" - "@types/semver" "^7.5.0" - "@typescript-eslint/scope-manager" "7.3.1" - "@typescript-eslint/types" "7.3.1" - "@typescript-eslint/typescript-estree" "7.3.1" - semver "^7.5.4" - -"@typescript-eslint/visitor-keys@7.3.1": - version "7.3.1" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.3.1.tgz#6ddef14a3ce2a79690f01176f5305c34d7b93d8c" - integrity sha512-9RMXwQF8knsZvfv9tdi+4D/j7dMG28X/wMJ8Jj6eOHyHWwDW4ngQJcqEczSsqIKKjFiLFr40Mnr7a5ulDD3vmw== + "@types/json-schema" "^7.0.15" + "@types/semver" "^7.5.8" + "@typescript-eslint/scope-manager" "7.6.0" + "@typescript-eslint/types" "7.6.0" + "@typescript-eslint/typescript-estree" "7.6.0" + semver "^7.6.0" + +"@typescript-eslint/visitor-keys@7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.6.0.tgz#d1ce13145844379021e1f9bd102c1d78946f4e76" + integrity sha512-4eLB7t+LlNUmXzfOu1VAIAdkjbu5xNSerURS9X/S5TUKWFRpXRQZbmtPqgKmYx8bj3J0irtQXSiWAOY82v+cgw== dependencies: - "@typescript-eslint/types" "7.3.1" - eslint-visitor-keys "^3.4.1" + "@typescript-eslint/types" "7.6.0" + eslint-visitor-keys "^3.4.3" "@ungap/structured-clone@^1.2.0": version "1.2.0" @@ -1466,10 +1558,10 @@ buffer-reverse@^1.0.1: resolved "https://registry.yarnpkg.com/buffer-reverse/-/buffer-reverse-1.0.1.tgz#49283c8efa6f901bc01fa3304d06027971ae2f60" integrity sha512-M87YIUBsZ6N924W57vDwT/aOu8hw7ZgdByz6ijksLjmHJELBASmYTTlNHRgjE+pTsT9oJXGaDSgqqwfdHotDUg== -bun-types@1.0.33: - version "1.0.33" - resolved "https://registry.yarnpkg.com/bun-types/-/bun-types-1.0.33.tgz#b0cd5453c514058d78d5402775c0771b4cb7a489" - integrity sha512-L5tBIf9g6rBBkvshqysi5NoLQ9NnhSPU1pfJ9FzqoSfofYdyac3WLUnOIuQ+M5za/sooVUOP2ko+E6Tco0OLIA== +bun-types@1.0.36: + version "1.0.36" + resolved "https://registry.yarnpkg.com/bun-types/-/bun-types-1.0.36.tgz#42c06f60b9abb858239d3a4ffd937ba768bfc825" + integrity sha512-gaIb1SyhB0JZfIEg73/kSFhqolUqJXC68peguhXGwqr27HuvI8nkD0LTIHp/1DY4cNadfXHYgYrZIWX7oEoXlg== dependencies: "@types/node" "~20.11.3" "@types/ws" "~8.5.10" @@ -1490,9 +1582,9 @@ camelcase@^6.2.0: integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== caniuse-lite@^1.0.30001587: - version "1.0.30001599" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001599.tgz#571cf4f3f1506df9bf41fcbb6d10d5d017817bce" - integrity sha512-LRAQHZ4yT1+f9LemSMeqdMpMxZcc4RMWdj4tiFe3G8tNkWK+E58g+/tzotb5cU6TbcVJLr4fySiAW7XmxQvZQA== + version "1.0.30001610" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001610.tgz#2f44ed6e21d359e914271ae35b68903632628ccf" + integrity sha512-QFutAY4NgaelojVMjY63o6XlZyORPaLfyMnsl3HgnWdJUcX6K0oaJymHjH8PT5Gk7sTm8rvC/c5COUQKXqmOMA== chalk@^2.4.2: version "2.4.2" @@ -1619,9 +1711,9 @@ debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4: ms "2.1.2" dedent@^1.0.0: - version "1.5.1" - resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.5.1.tgz#4f3fc94c8b711e9bb2800d185cd6ad20f2a90aff" - integrity sha512-+LxW+KLWxu3HW3M2w2ympwtqPrqYRzU8fqi6Fhd18fBALe15blJPI/I4+UHveMVG6lJqB4JNd4UG0S5cnVHwIg== + version "1.5.3" + resolved "https://registry.yarnpkg.com/dedent/-/dedent-1.5.3.tgz#99aee19eb9bae55a67327717b6e848d0bf777e5a" + integrity sha512-NHQtfOOW68WD8lgypbLA5oT+Bt0xXJhiYvoR6SmmNXZfpzOGXwdKWmcwG8N7PwVVWV3eF/68nmD9BaJSsTBhyQ== deep-is@^0.1.3: version "0.1.4" @@ -1678,9 +1770,9 @@ dotenv@^16.4.5: integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== electron-to-chromium@^1.4.668: - version "1.4.712" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.712.tgz#2117ea2f4f95e8e0ec96c33dd345134ac00e57ed" - integrity sha512-ncfPC8UnGIyGFrPE03J5Xn6yTZ6R+clkcZbuG1PJbjAaZBFS4Kn3UKfzu8eilzru6SfC8TPsHuwv0p0eYVu+ww== + version "1.4.736" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.736.tgz#ecb4348f4d5c70fb1e31c347e5bad6b751066416" + integrity sha512-Rer6wc3ynLelKNM4lOCg7/zPQj8tPOCB2hzD32PX9wd3hgRRi9MxEbmkFCokzcEhRVMiOVLjnL9ig9cefJ+6+Q== elliptic@^6.5.5: version "6.5.5" @@ -1828,11 +1920,11 @@ esutils@^2.0.2: integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== ethereum-bloom-filters@^1.0.6: - version "1.0.10" - resolved "https://registry.yarnpkg.com/ethereum-bloom-filters/-/ethereum-bloom-filters-1.0.10.tgz#3ca07f4aed698e75bd134584850260246a5fed8a" - integrity sha512-rxJ5OFN3RwjQxDcFP2Z5+Q9ho4eIdEmSc2ht0fCu8Se9nbXjZ7/031uXoUYJ87KHCOdVeiUuwSnoS7hmYAGVHA== + version "1.1.0" + resolved "https://registry.yarnpkg.com/ethereum-bloom-filters/-/ethereum-bloom-filters-1.1.0.tgz#b3fc1eb789509ee30db0bf99a2988ccacb8d0397" + integrity sha512-J1gDRkLpuGNvWYzWslBQR9cDV4nd4kfvVTE/Wy4Kkm4yb3EYRSlyi0eB/inTsSTTVyA0+HyzHgbr95Fn/Z1fSw== dependencies: - js-sha3 "^0.8.0" + "@noble/hashes" "^1.4.0" ethereum-cryptography@^2.0.0, ethereum-cryptography@^2.1.2: version "2.1.3" @@ -2000,6 +2092,20 @@ function-bind@^1.1.2: resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c" integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA== +generate-function@^2.0.0: + version "2.3.1" + resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.3.1.tgz#f069617690c10c868e73b8465746764f97c3479f" + integrity sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ== + dependencies: + is-property "^1.0.2" + +generate-object-property@^1.1.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/generate-object-property/-/generate-object-property-1.2.0.tgz#9c0e1c40308ce804f4783618b937fa88f99d50d0" + integrity sha512-TuOwZWgJ2VAMEGJvAyPWvpqxSANF0LDpmyHauMjFYzaACvn+QTT/AZomvPCzVBV7yDN3OmwHQ5OvHaeLKre3JQ== + dependencies: + is-property "^1.0.0" + gensync@^1.0.0-beta.2: version "1.0.0-beta.2" resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" @@ -2135,7 +2241,7 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== -ignore@^5.2.0, ignore@^5.2.4: +ignore@^5.2.0, ignore@^5.3.1: version "5.3.1" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.3.1.tgz#5073e554cd42c5b33b394375f538b8593e34d4ef" integrity sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw== @@ -2218,6 +2324,22 @@ is-hex-prefixed@1.0.0: resolved "https://registry.yarnpkg.com/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz#7d8d37e6ad77e5d127148913c573e082d777f554" integrity sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA== +is-my-ip-valid@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-my-ip-valid/-/is-my-ip-valid-1.0.1.tgz#f7220d1146257c98672e6fba097a9f3f2d348442" + integrity sha512-jxc8cBcOWbNK2i2aTkCZP6i7wkHF1bqKFrwEHuN5Jtg5BSaZHUZQ/JTOJwoV41YvHnOaRyWWh72T/KvfNz9DJg== + +is-my-json-valid@^2.20.6: + version "2.20.6" + resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.20.6.tgz#a9d89e56a36493c77bda1440d69ae0dc46a08387" + integrity sha512-1JQwulVNjx8UqkPE/bqDaxtH4PXCe/2VRh/y3p99heOV87HG4Id5/VfDswd+YiAfHcRTfDlWgISycnHuhZq1aw== + dependencies: + generate-function "^2.0.0" + generate-object-property "^1.1.0" + is-my-ip-valid "^1.0.0" + jsonpointer "^5.0.0" + xtend "^4.0.0" + is-number@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/is-number/-/is-number-7.0.0.tgz#7535345b896734d5f80c4d06c50955527a14f12b" @@ -2228,6 +2350,11 @@ is-path-inside@^3.0.3: resolved "https://registry.yarnpkg.com/is-path-inside/-/is-path-inside-3.0.3.tgz#d231362e53a07ff2b0e0ea7fed049161ffd16283" integrity sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ== +is-property@^1.0.0, is-property@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-property/-/is-property-1.0.2.tgz#57fe1c4e48474edd65b09911f26b1cd4095dda84" + integrity sha512-Ks/IoX00TtClbGQr4TWXemAnktAQvYB7HzcCxDGqEZU6oCmb2INHuOoKxbtR+HFkmYWBKv/dOZtGRiAjDhj92g== + is-stream@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077" @@ -2659,11 +2786,6 @@ js-sha256@0.9.0: resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966" integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA== -js-sha3@^0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840" - integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q== - js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -2719,6 +2841,11 @@ json5@^2.2.3: resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== +jsonpointer@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-5.0.1.tgz#2110e0af0900fd37467b5907ecd13a7884a1b559" + integrity sha512-p/nXbhSEcu3pZRdkW1OfJhpsVtW1gd4Wa1fnQc9YLiTfAjn0312eMKimbdIQzuZl9aa9xUGaRlP9T/CJE/ditQ== + keccak@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/keccak/-/keccak-3.0.4.tgz#edc09b89e633c0549da444432ecf062ffadee86d" @@ -2869,13 +2996,6 @@ minimalistic-crypto-utils@^1.0.1: resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" integrity sha512-JIYlbt6g8i5jKfJ3xz7rF0LXmv2TkDxBLUkiBeZ7bAx4GnnNMr8xFpGnOxn6GhTEHx3SjRrZEoU+j04prX1ktg== -minimatch@9.0.3: - version "9.0.3" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825" - integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg== - dependencies: - brace-expansion "^2.0.1" - minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" @@ -2883,6 +3003,13 @@ minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" +minimatch@^9.0.4: + version "9.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.4.tgz#8e49c731d1749cbec05050ee5145147b32496a51" + integrity sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw== + dependencies: + brace-expansion "^2.0.1" + ms@2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" @@ -2993,11 +3120,11 @@ onetime@^5.1.2: mimic-fn "^2.1.0" opensea-js@^7.0.9: - version "7.0.9" - resolved "https://registry.yarnpkg.com/opensea-js/-/opensea-js-7.0.9.tgz#fcdcce08388f12fa90fda6c2762b1d7815e101b8" - integrity sha512-3ptQxuucyrvBvExOCTU+cH/zqv+2Sk7tWbWK66RXNqZ4S9vhdzf7sfCnYJ7+KMKDbEU9Bx7PIMvIC60GNTpVAQ== + version "7.1.5" + resolved "https://registry.yarnpkg.com/opensea-js/-/opensea-js-7.1.5.tgz#af66b380635a6c1cf9b50f2736d4cdc5e90ca9af" + integrity sha512-nR5AAqT+sK2CiG9iuvqbVuUlbrs4wMRG32514wtRL/mFlSUr9hkteIitG23R4zGrjjyTJbI6wIaEclnccbI76Q== dependencies: - "@opensea/seaport-js" "^3.0.0" + "@opensea/seaport-js" "^4.0.0" ethers "^6.9.0" optionator@^0.9.3: @@ -3142,9 +3269,9 @@ punycode@^2.1.0: integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg== pure-rand@^6.0.0: - version "6.0.4" - resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.0.4.tgz#50b737f6a925468679bff00ad20eade53f37d5c7" - integrity sha512-LA0Y9kxMYv47GIPJy6MI84fqTd2HmYZI83W/kM/SkKfDlajnZYfmXFTxkbY+xSBPkLJxltMa9hIkmdc29eguMA== + version "6.1.0" + resolved "https://registry.yarnpkg.com/pure-rand/-/pure-rand-6.1.0.tgz#d173cf23258231976ccbdb05247c9787957604f2" + integrity sha512-bVWawvoZoBYpp6yIoQtQXHZjmz35RSVHnUOTefl8Vcjr8snTPY1wnpSPMWekcFwbxI6gtmT7rSYPFvz71ldiOA== queue-microtask@^1.2.2: version "1.2.3" @@ -3249,7 +3376,7 @@ semver@^6.3.0, semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.5.3, semver@^7.5.4: +semver@^7.5.3, semver@^7.5.4, semver@^7.6.0: version "7.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" integrity sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg== @@ -3448,7 +3575,7 @@ treeify@^1.1.0: resolved "https://registry.yarnpkg.com/treeify/-/treeify-1.1.0.tgz#4e31c6a463accd0943879f30667c4fdaff411bb8" integrity sha512-1m4RA7xVAJrSGrrXGs0L3YTwyvBs2S8PbRHaLZAkFw7JR8oIFwYtysxlBZhYIa7xSyiYJKZ3iGrrk55cGA3i9A== -ts-api-utils@^1.0.1: +ts-api-utils@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.3.0.tgz#4b490e27129f1e8e686b45cc4ab63714dc60eea1" integrity sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ== @@ -3519,9 +3646,9 @@ type-fest@^0.21.3: integrity sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w== typescript@^5.4.2: - version "5.4.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" - integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== + version "5.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" + integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== undici-types@~5.26.4: version "5.26.5" @@ -3568,9 +3695,9 @@ v8-to-istanbul@^9.0.1: convert-source-map "^2.0.0" viem@^2.8.14: - version "2.8.16" - resolved "https://registry.yarnpkg.com/viem/-/viem-2.8.16.tgz#30370390a6f109657b57c1a01b2793c4056b4e95" - integrity sha512-J8tu1aP7TfI2HT/IEmyJ+n+WInrA/cuMuJtfgvYhYgHBobxhYGc2SojHm5lZBWcWgErN1Ld7VcKUwTmPh4ToQA== + version "2.9.17" + resolved "https://registry.yarnpkg.com/viem/-/viem-2.9.17.tgz#4a74b5302fe5b3d6ac8db4769418a0466867befa" + integrity sha512-xMQ4JhgR1fPXQYagEeSsq9lmKXXooHP2gcnowb0eJRq3NTheyzpVBtMuH8DZnnWT4aeFepZktqSXlFul+Ou5Xg== dependencies: "@adraffy/ens-normalize" "1.10.0" "@noble/curves" "1.2.0" @@ -3654,6 +3781,11 @@ ws@8.5.0: resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f" integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg== +xtend@^4.0.0: + version "4.0.2" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" + integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== + y18n@^5.0.5: version "5.0.8" resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" From 97387d0960304a936e5eb669b3a8e6c8618df7e3 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 15 Apr 2024 15:20:23 +0200 Subject: [PATCH 10/10] e2e test assertion --- src/chains/ethereum.ts | 3 +-- tests/e2e.test.ts | 30 +++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/chains/ethereum.ts b/src/chains/ethereum.ts index 18a711d..13f2fc7 100644 --- a/src/chains/ethereum.ts +++ b/src/chains/ethereum.ts @@ -20,7 +20,7 @@ import { queryGasPrice } from "../utils/gasPrice"; import { buildTxPayload, addSignature } from "../utils/transaction"; export class NearEthAdapter { - private ethClient: PublicClient; + ethClient: PublicClient; private scanUrl: string; private gasStationUrl: string; @@ -196,7 +196,6 @@ export class NearEthAdapter { private async relaySignedTransaction( serializedTransaction: Hex ): Promise { - // const serializedTransaction = serializeTransaction(signedTx); const txHash = await this.ethClient.sendRawTransaction({ serializedTransaction, }); diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index 994b4e7..deb0ce1 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -1,12 +1,32 @@ import { setupNearEthAdapter } from "../examples/setup"; +import { NearEthAdapter } from "../src"; +import { getBalance } from "viem/actions"; describe("End To End", () => { + let evm: NearEthAdapter; + const to = "0xdeADBeeF0000000000000000000000000b00B1e5"; + const ONE_WEI = 1n; + + beforeAll(async () => { + evm = await setupNearEthAdapter(); + }); + + afterAll(async () => { + clearTimeout(); + }); + it("Runs the Send ETH Tx", async () => { - const evm = await setupNearEthAdapter(); - await evm.signAndSendTransaction({ - to: "0xdeADBeeF0000000000000000000000000b00B1e5", - // THIS IS ONE WEI! - value: 1n, + await expect( + evm.signAndSendTransaction({ to, value: ONE_WEI }) + ).resolves.not.toThrow(); + }); + + it("Fails Invalid Send ETH Tx", async () => { + const senderBalance = await getBalance(evm.ethClient, { + address: evm.ethPublicKey(), }); + await expect( + evm.signAndSendTransaction({ to, value: senderBalance + ONE_WEI }) + ).rejects.toThrow(); }); });