Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Fix signTransactionAsFeePayer #494

Merged
merged 1 commit into from
Aug 16, 2023
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
24 changes: 20 additions & 4 deletions ethers-ext/src/ethers/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,35 @@ export class Wallet extends EthersWallet {
}

async signTransactionAsFeePayer(transaction: Deferrable<TransactionRequest>): Promise<string> {
const tx: TransactionRequest = await resolveProperties(transaction);
let tx = transaction;
if (typeof transaction === "string") {
if (HexStr.isHex(transaction)) {
tx = this.decodeTxFromRLP(transaction);
// @ts-ignore : we have to add feePayer property
tx.chainId = Math.floor((tx.txSignatures[0][0] - 35) / 2);
} else {
throw new Error("Input parameter has to be RLP encoded Hex string.");
}
}

const ttx = KlaytnTxFactory.fromObject(tx);
const rtx: TransactionRequest = await resolveProperties(tx);
// @ts-ignore : we have to add feePayer property
if (!rtx.feePayer) {
// @ts-ignore : we have to add feePayer property
rtx.feePayer = await this.getAddress();
}

const ttx = KlaytnTxFactory.fromObject(rtx);
if (!ttx.hasFeePayer()) {
throw new Error("This transaction can not be signed as FeePayer");
}

const sigFeePayerHash = keccak256(ttx.sigFeePayerRLP());
const sig = this._signingKey().signDigest(sigFeePayerHash);

// @ts-ignore : we have to add feePayer property
if (tx.chainId) { // EIP-155
// @ts-ignore : we have to add feePayer property
sig.v = sig.recoveryParam + tx.chainId * 2 + 35;
}
ttx.addFeePayerSig(sig);
Expand Down Expand Up @@ -245,8 +263,6 @@ export class Wallet extends EthersWallet {
ptx = await this.populateTransaction(transaction);
}

// @ts-ignore : we have to add feePayer property
ptx.feePayer = await this.getAddress();
const signedTx = await this.signTransactionAsFeePayer(ptx);

if (this.provider instanceof EthersJsonRpcProvider) {
Expand Down