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

Implement wcRespond #89

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions src/chains/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TypedDataDefinition,
parseTransaction,
keccak256,
Signature,
} from "viem";
import {
BaseTx,
Expand All @@ -20,6 +21,7 @@ import {
TransactionWithSignature,
NearEthTxData,
SignArgs,
RecoveryData,
} from "../types";
import { MpcContract } from "../mpcContract";
import {
Expand Down Expand Up @@ -268,4 +270,19 @@ export class NearEthAdapter {
recoveryData,
};
}

async wcRespond(
recoveryData: RecoveryData,
signature: Signature
): Promise<Hex> {
if (recoveryData.type === "eth_sendTransaction") {
const signedTx = addSignature({
transaction: recoveryData.data as Hex,
signature,
});
// Returns relayed transaction hash (without waiting for confirmation).
return this.relaySignedTransaction(signedTx, false);
}
return serializeSignature(signature);
}
}
4 changes: 2 additions & 2 deletions src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function toPayload(msgHash: Hex | Uint8Array): number[] {
return Array.from(bytes);
}

export function buildTxPayload(unsignedTxHash: `0x${string}`): number[] {
return toPayload(keccak256(unsignedTxHash));
export function buildTxPayload(serializedTx: `0x${string}`): number[] {
return toPayload(keccak256(serializedTx));
}

export async function populateTx(
Expand Down