Skip to content

Commit

Permalink
Fix generation of HTLC funding and redeeming transactions for Albatross
Browse files Browse the repository at this point in the history
Co-authored-by: mar-v-in <[email protected]>
  • Loading branch information
sisou and mar-v-in committed Nov 22, 2024
1 parent fcd41c7 commit dc09bad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
16 changes: 1 addition & 15 deletions src/lib/LedgerSwapProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default class LedgerSwapProxy {
}: LedgerApiTransactionInfoNimiq<typeof Config.ledgerApiNimiqVersion>): Promise<Nimiq.Transaction> {
// 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),
Expand All @@ -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(
Expand Down
21 changes: 7 additions & 14 deletions src/views/SetupSwapSuccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit dc09bad

Please sign in to comment.