From 4e1ff7450c129ee2d0686ca7ca8ae419bdc0567d Mon Sep 17 00:00:00 2001 From: issam2021 Date: Sun, 19 Apr 2026 01:17:26 +0200 Subject: [PATCH] refactor: extract buildTransferMessage helper function - Resolves TODO in transferWithWinternitz - Improves code reusability and readability - Adds JSDoc documentation for the new function --- src/index.ts | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index d7babbb..9e8d134 100644 --- a/src/index.ts +++ b/src/index.ts @@ -118,7 +118,34 @@ export class QuipSigner { return this.wots.sign(key.privateKey, key.publicKey.publicSeed, message); } } - +/** + * buildTransferMessage constructs the packed message data used for + * transfer signature verification in the QuipWallet contract. + * + * @param currentPqOwner - The current post-quantum owner key pair + * @param nextPublicKey - The next post-quantum public key + * @param to - The recipient address + * @param value - The transfer amount in wei + * @returns The ABI-packed message bytes + */ +function buildTransferMessage( + currentPqOwner: { publicSeed: string; publicKeyHash: string }, + nextPublicKey: WinternitzPublicKey, + to: ethers.AddressLike, + value: bigint +): string { + return ethers.solidityPacked( + ["bytes32", "bytes32", "bytes32", "bytes32", "address", "uint256"], + [ + currentPqOwner.publicSeed, + currentPqOwner.publicKeyHash, + nextPublicKey.publicSeed, + nextPublicKey.publicKeyHash, + to, + value, + ] + ); +} export class QuipWalletClient { private wallet: QuipWallet; private quipSigner: QuipSigner; @@ -156,18 +183,12 @@ export class QuipWalletClient { const publicSeed = ethers.getBytes(currentPqOwner.publicSeed); const transferFee = await this.getTransferFee(); - // TODO: Make a function that does this? - const packedMessageData = ethers.solidityPacked( - ["bytes32", "bytes32", "bytes32", "bytes32", "address", "uint256"], - [ - currentPqOwner.publicSeed, - currentPqOwner.publicKeyHash, - nextPqOwner.publicKey.publicSeed, - nextPqOwner.publicKey.publicKeyHash, - to, - value, - ] - ); + const packedMessageData = buildTransferMessage( + currentPqOwner, + nextPqOwner.publicKey, + to, + value +); // FIXME: these are stupid in hindsight. const message = {