From b9e36702f246649f035cc263eab413ac8aef384e Mon Sep 17 00:00:00 2001 From: rileystephens28 Date: Mon, 17 Jun 2024 13:50:09 -0500 Subject: [PATCH 1/3] Fallback to wallet address when populating tx in `signTransaction` --- src/wallet/base-wallet.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/wallet/base-wallet.ts b/src/wallet/base-wallet.ts index e19a3df5..376ebdfd 100644 --- a/src/wallet/base-wallet.ts +++ b/src/wallet/base-wallet.ts @@ -89,27 +89,26 @@ export class BaseWallet extends AbstractSigner { from: tx.from ? resolveAddress(tx.from) : undefined, }); - if (to != null) { + if (to !== undefined) { validateAddress(to); tx.to = to; } - if (from != null) { - validateAddress(from); - tx.from = from; - } - if (tx.from != null) { + if (from !== undefined) { assertArgument( - getAddress(tx.from) === this.#address, + getAddress(from) === this.#address, 'transaction from address mismatch', 'tx.from', - tx.from, + from, ); + } else { + // No `from` specified, use the wallet's address + tx.from = this.#address; } const btx = QuaiTransaction.from(tx); - const digest= keccak256(btx.unsignedSerialized) - btx.signature = this.signingKey.sign(digest) + const digest = keccak256(btx.unsignedSerialized); + btx.signature = this.signingKey.sign(digest); return btx.serialized; } From 6fa895433ce78884f346f83f02d1972a8b01c63b Mon Sep 17 00:00:00 2001 From: rileystephens28 Date: Mon, 17 Jun 2024 13:56:52 -0500 Subject: [PATCH 2/3] Remove Qi logic --- src/signers/abstract-signer.ts | 41 ++++++---------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/src/signers/abstract-signer.ts b/src/signers/abstract-signer.ts index ec547a8f..a849508b 100644 --- a/src/signers/abstract-signer.ts +++ b/src/signers/abstract-signer.ts @@ -3,13 +3,8 @@ * sufficent for most developers, but this is provided to fascilitate more complex Signers. */ import { AddressLike, resolveAddress, validateAddress } from '../address/index.js'; -import { defineProperties, getBigInt, resolveProperties, assert, assertArgument, isQiAddress } from '../utils/index.js'; -import { - addressFromTransactionRequest, - copyRequest, - QiTransactionRequest, - QuaiTransactionRequest, -} from '../providers/provider.js'; +import { defineProperties, getBigInt, resolveProperties, assert, assertArgument } from '../utils/index.js'; +import { addressFromTransactionRequest, copyRequest, QuaiTransactionRequest } from '../providers/provider.js'; import type { TypedDataDomain, TypedDataField } from '../hash/index.js'; import type { TransactionLike } from '../transaction/index.js'; @@ -17,7 +12,7 @@ import type { TransactionLike } from '../transaction/index.js'; import type { BlockTag, Provider, TransactionRequest, TransactionResponse } from '../providers/provider.js'; import type { Signer } from './signer.js'; import { getTxType } from '../utils/index.js'; -import { QiTransaction, QiTransactionLike, QuaiTransaction, QuaiTransactionLike } from '../transaction/index.js'; +import { QuaiTransaction, QuaiTransactionLike } from '../transaction/index.js'; import { toZone, Zone } from '../constants/index.js'; function checkProvider(signer: AbstractSigner, operation: string): Provider { @@ -155,19 +150,6 @@ export abstract class AbstractSigner

{ - const pop = { - inputsUTXO: tx.inputs, - outputsUTXO: tx.outputs, - chainId: tx.chainId, - type: 2, - }; - - //@TOOD: Don't await all over the place; save them up for - // the end for better batching - return await resolveProperties(pop); - } - async estimateGas(tx: TransactionRequest): Promise { return checkProvider(this, 'estimateGas').estimateGas(await this.populateCall(tx)); } @@ -178,22 +160,13 @@ export abstract class AbstractSigner

{ const provider = checkProvider(this, 'sendTransaction'); - const sender = await this.getAddress(); const zone = await this.zoneFromAddress(addressFromTransactionRequest(tx)); + const pop = await this.populateQuaiTransaction(tx as QuaiTransactionRequest); + const txObj = QuaiTransaction.from(pop); - let pop; - let txObj; - if (isQiAddress(sender)) { - pop = await this.populateQiTransaction(tx); - txObj = QiTransaction.from(pop); - } else { - pop = await this.populateQuaiTransaction(tx as QuaiTransactionRequest); - txObj = QuaiTransaction.from(pop); - } - + const sender = await this.getAddress(); const signedTx = await this.signTransaction(txObj); - - return await provider.broadcastTransaction(zone, signedTx, 'from' in tx ? tx.from : undefined); + return await provider.broadcastTransaction(zone, signedTx, sender); } abstract signTransaction(tx: TransactionRequest): Promise; From e85970127d64c1894247c0826807e5951e05fca9 Mon Sep 17 00:00:00 2001 From: rileystephens28 Date: Mon, 17 Jun 2024 13:57:07 -0500 Subject: [PATCH 3/3] Better from address validation --- src/transaction/quai-transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction/quai-transaction.ts b/src/transaction/quai-transaction.ts index 777abab7..5e3536d6 100644 --- a/src/transaction/quai-transaction.ts +++ b/src/transaction/quai-transaction.ts @@ -443,7 +443,7 @@ export class QuaiTransaction extends AbstractTransaction implements Q } if (tx.from != null) { - validateAddress(tx.from); + assertArgument(!isQiAddress(tx.from), 'from address must be a Quai address', 'tx.from', tx.from); assertArgument( (result.from || '').toLowerCase() === (tx.from || '').toLowerCase(), 'from mismatch',