diff --git a/src/_tests/unit/wallet.unit.test.ts b/src/_tests/unit/wallet.unit.test.ts index ac3d8a8f..8449ae88 100644 --- a/src/_tests/unit/wallet.unit.test.ts +++ b/src/_tests/unit/wallet.unit.test.ts @@ -4,13 +4,7 @@ import { loadTests } from '../utils.js'; import type { TestCaseAccount, TestCaseTypedData, TestCaseTransaction } from '../types.js'; -import { - // hexlify, - // randomBytes, - Wallet, -} from '../../index.js'; - -// import type { QuaiHDWallet } from "../index.js"; +import { Wallet } from '../../index.js'; describe('Test Private Key Wallet', function () { const tests = loadTests('accounts'); @@ -39,10 +33,6 @@ describe('Test Transaction Signing', function () { gasLimit: 0, }); const signed = await wallet.signTransaction(txData); - // let parsed = Transaction.from(signed); - // // console.log('txData: ', JSON.stringify(parsed)) - // // console.log('EXPECTED: ', test.signedEip155) - // // console.log("ACTUAL: ", signed) assert.equal(signed, test.signed, 'signed'); }); } diff --git a/src/wallet/qi-hdwallet.ts b/src/wallet/qi-hdwallet.ts index 762847cc..a031d2a8 100644 --- a/src/wallet/qi-hdwallet.ts +++ b/src/wallet/qi-hdwallet.ts @@ -697,23 +697,10 @@ export class QiHDWallet extends AbstractHDWallet { const sendAddressesInfo = this.getUnusedBIP44Addresses(1, 0, 'BIP44:external', zone); const sendAddresses = sendAddressesInfo.map((addressInfo) => addressInfo.address); const changeAddresses: string[] = []; - const inputPubKeys = selection.inputs.map((input) => { - const addressInfo = this.locateAddressInfo(input.address); - if (!addressInfo) { - throw new Error(`Could not locate address info for address: ${input.address}`); - } - return addressInfo.pubKey; - }); // Proceed with creating and signing the transaction const chainId = (await this.provider.getNetwork()).chainId; - const tx = await this.prepareTransaction( - selection, - inputPubKeys, - sendAddresses, - changeAddresses, - Number(chainId), - ); + const tx = await this.prepareTransaction(selection, sendAddresses, changeAddresses, Number(chainId)); // Sign the transaction const signedTx = await this.signTransaction(tx); @@ -845,13 +832,7 @@ export class QiHDWallet extends AbstractHDWallet { // Proceed with creating and signing the transaction const chainId = (await this.provider.getNetwork()).chainId; - const tx = await this.prepareTransaction( - selection, - inputPubKeys.map((pubkey) => pubkey!), - sendAddresses, - changeAddresses, - Number(chainId), - ); + const tx = await this.prepareTransaction(selection, sendAddresses, changeAddresses, Number(chainId)); // Sign the transaction const signedTx = await this.signTransaction(tx); @@ -872,17 +853,40 @@ export class QiHDWallet extends AbstractHDWallet { */ private async prepareTransaction( selection: SelectedCoinsResult, - inputPubKeys: string[], sendAddresses: string[], changeAddresses: string[], chainId: number, ): Promise { const tx = new QiTransaction(); - tx.txInputs = selection.inputs.map((input, index) => ({ - txhash: input.txhash!, - index: input.index!, - pubkey: inputPubKeys[index], + + interface InputWithPubKey { + utxo: UTXO; + pubKey: string; + } + + const inputsWithPubKeys: InputWithPubKey[] = selection.inputs.map((input) => { + const addressInfo = this.locateAddressInfo(input.address); + if (!addressInfo?.pubKey) { + throw new Error(`Missing public key for input address: ${input.address}`); + } + return { + utxo: input, + pubKey: addressInfo.pubKey, + }; + }); + + tx.txInputs = inputsWithPubKeys.map((input) => ({ + txhash: input.utxo.txhash!, + index: input.utxo.index!, + pubkey: input.pubKey, })); + + // // 5.1 Create the "sender" inputs + // tx.txInputs = selection.inputs.map((input, index) => ({ + // txhash: input.txhash!, + // index: input.index!, + // pubkey: inputPubKeys[index], + // })); // 5.3 Create the "sender" outputs const senderOutputs = selection.spendOutputs.map((output, index) => ({ address: sendAddresses[index], diff --git a/testcases/qi-wallet-scan-and-convert-to-quai.json.gz b/testcases/qi-wallet-scan-and-convert-to-quai.json.gz index c6522c65..1cabdcf8 100644 Binary files a/testcases/qi-wallet-scan-and-convert-to-quai.json.gz and b/testcases/qi-wallet-scan-and-convert-to-quai.json.gz differ diff --git a/testcases/qi-wallet-scan-and-send.json.gz b/testcases/qi-wallet-scan-and-send.json.gz index 3d8bd555..20359f6a 100644 Binary files a/testcases/qi-wallet-scan-and-send.json.gz and b/testcases/qi-wallet-scan-and-send.json.gz differ diff --git a/testcases/quai-transaction.json.gz b/testcases/quai-transaction.json.gz index 5d322160..f453c156 100644 Binary files a/testcases/quai-transaction.json.gz and b/testcases/quai-transaction.json.gz differ diff --git a/testcases/transactions.json.gz b/testcases/transactions.json.gz index 92bd5216..237b81a4 100644 Binary files a/testcases/transactions.json.gz and b/testcases/transactions.json.gz differ