From 5ef4e697a96b83dd318db484bda570c2453a3f6f Mon Sep 17 00:00:00 2001 From: Nohyun Nehemiah Kwak Date: Wed, 16 Aug 2023 13:29:15 +0900 Subject: [PATCH] Update signer.ts --- ethers-ext/src/ethers/signer.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ethers-ext/src/ethers/signer.ts b/ethers-ext/src/ethers/signer.ts index e04704755..35fa8bf31 100644 --- a/ethers-ext/src/ethers/signer.ts +++ b/ethers-ext/src/ethers/signer.ts @@ -194,9 +194,25 @@ export class Wallet extends EthersWallet { } async signTransactionAsFeePayer(transaction: Deferrable): Promise { - 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"); } @@ -204,7 +220,9 @@ export class Wallet extends EthersWallet { 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); @@ -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) {