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

Commit

Permalink
Merge pull request #494 from nohkwak/202308-signer-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
blukat29 authored Aug 16, 2023
2 parents cde7476 + 5ef4e69 commit b98db6a
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit b98db6a

Please sign in to comment.