From dc09bade561290b0155656b63cfef28412741164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren?= Date: Thu, 21 Nov 2024 18:39:49 -0600 Subject: [PATCH] Fix generation of HTLC funding and redeeming transactions for Albatross Co-authored-by: mar-v-in --- src/lib/LedgerSwapProxy.ts | 16 +--------------- src/views/SetupSwapSuccess.vue | 21 +++++++-------------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/lib/LedgerSwapProxy.ts b/src/lib/LedgerSwapProxy.ts index 0e94adee..ded9115e 100644 --- a/src/lib/LedgerSwapProxy.ts +++ b/src/lib/LedgerSwapProxy.ts @@ -290,7 +290,7 @@ export default class LedgerSwapProxy { }: LedgerApiTransactionInfoNimiq): Promise { // Always create an ExtendedTransaction because all transactions that will typically be signed by the proxy will // be ExtendedTransactions because they include extraData or have sender- or recipientType HTLC. - let transaction = new Nimiq.Transaction( + const transaction = new Nimiq.Transaction( sender, senderType, new Uint8Array(0), @@ -303,20 +303,6 @@ export default class LedgerSwapProxy { validityStartHeight, Config.nimiqNetworkId, ); - if ( - transaction.recipientType === Nimiq.AccountType.HTLC - && transaction.flags === 1 /* Nimiq.Transaction.Flag.CONTRACT_CREATION */ - ) { - // Calculate the contract address of the HTLC that gets created and recreate the transaction - // with that address as the recipient: - const contractAddress = new Nimiq.Address(Nimiq.BufferUtils.fromHex(transaction.hash())); - transaction = new Nimiq.Transaction( - transaction.sender, transaction.senderType, transaction.senderData, - contractAddress, transaction.recipientType, transaction.data, - transaction.value, transaction.fee, - transaction.flags, transaction.validityStartHeight, transaction.networkId, - ); - } if (this._localSignerPrivateKey) { const signature = Nimiq.Signature.create( diff --git a/src/views/SetupSwapSuccess.vue b/src/views/SetupSwapSuccess.vue index b608e939..346e6b37 100644 --- a/src/views/SetupSwapSuccess.vue +++ b/src/views/SetupSwapSuccess.vue @@ -500,18 +500,20 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView { const dummyPreImage = '0000000000000000000000000000000000000000000000000000000000000000'; const dummyHashRoot = '66687aadf862bd776c8fc18b8e9f8e20089714856ee233b3902a591d0d5f2925'; // sha256 - const proof = new Nimiq.SerialBuffer(3 + 2 * 32 + nimiqTransaction.proof.length); + const proof = new Nimiq.SerialBuffer(4 + 2 * 32 + nimiqTransaction.proof.length); proof.writeUint8(0 /* Nimiq.HashedTimeLockedContract.ProofType.REGULAR_TRANSFER */); + proof.writeUint8(1); // hashCount must be 1 for our swaps proof.writeUint8({ - blake2b: 0, - sha256: 1, - sha512: 2, + blake2b: 1, + sha256: 3, + sha512: 4, }[nimiqHtlcHashAlgorithm]); - proof.writeUint8(1); // hashCount must be 1 for our swaps proof.write(Nimiq.BufferUtils.fromHex(dummyHashRoot)); + proof.writeUint8(32); // PreImage size proof.write(Nimiq.BufferUtils.fromHex(dummyPreImage)); proof.write(new Nimiq.SerialBuffer(nimiqTransaction.proof)); // Current proof is regular SignatureProof nimiqTransaction.proof = proof; + console.log(Nimiq.BufferUtils.toHex(proof)); } // Validate that transaction is valid @@ -596,15 +598,6 @@ export default class SetupSwapSuccess extends BitcoinSyncBaseView { signerPubKey: nimiqSignatureResult.publicKey, signature: nimiqSignatureResult.signature, }); - // Calculate the contract address of the HTLC that gets created and recreate the transaction - // with that address as the recipient: - const contractAddress = new Nimiq.Address(Nimiq.BufferUtils.fromHex(nimiqTransaction.hash())); - nimiqTransaction = new Nimiq.Transaction( - nimiqTransaction.sender, nimiqTransaction.senderType, nimiqTransaction.senderData, - contractAddress, nimiqTransaction.recipientType, nimiqTransaction.data, - nimiqTransaction.value, nimiqTransaction.fee, - nimiqTransaction.flags, nimiqTransaction.validityStartHeight, nimiqTransaction.networkId, - ); } else if (this.request.redeem.type === SwapAsset.NIM && htlcInfo.redeem.type === SwapAsset.NIM && nimiqSignatureResult) { nimiqTransaction = this.nimiqNetwork.createTx({