Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Type TransactionWithSignature #17

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions src/chains/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NearEthAdapterParams,
NearContractFunctionPayload,
TxPayload,
TransactionWithSignature,
} from "../types";
import { queryGasPrice } from "../utils/gasPrice";
import { MultichainContract } from "../mpcContract";
Expand Down Expand Up @@ -93,7 +94,7 @@ export class NearEthAdapter {
nearGas
);

return this.relayTransaction(transaction, big_r, big_s);
return this.relayTransaction({ transaction, signature: { big_r, big_s } });
}

/**
Expand Down Expand Up @@ -125,16 +126,13 @@ export class NearEthAdapter {
}

/**
* Relays signed transaction to Etherem mempool for execution.
* @param signedTx - Signed Ethereum transaction.
* @returns Transaction Hash of relayed transaction.
* Relays valid representation of signed transaction to Etherem mempool for execution.
*
* @param {TransactionWithSignature} tx - Signed Ethereum transaction.
* @returns Hash of relayed transaction.
*/
async relayTransaction(
transaction: FeeMarketEIP1559Transaction,
big_r: string,
big_s: string
): Promise<Hash> {
const signedTx = await this.reconstructSignature(transaction, big_r, big_s);
async relayTransaction(tx: TransactionWithSignature): Promise<Hash> {
const signedTx = await this.reconstructSignature(tx);
return this.relaySignedTransaction(signedTx);
}

Expand All @@ -143,7 +141,7 @@ 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.
* @returns transacion and its bytes (the payload to be signed on Near)
* @returns Transaction and its bytes (the payload to be signed on Near).
*/
async createTxPayload(tx: BaseTx): Promise<TxPayload> {
const transaction = await this.buildTransaction(tx);
Expand Down Expand Up @@ -183,12 +181,11 @@ export class NearEthAdapter {
}

private reconstructSignature = (
transaction: FeeMarketEIP1559Transaction,
big_r: string,
big_s: string
tx: TransactionWithSignature
): FeeMarketEIP1559Transaction => {
const r = Buffer.from(big_r.substring(2), "hex");
const s = Buffer.from(big_s, "hex");
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(
Expand Down