@arkade-os/boltz-swap 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@ import {
2
2
  defineExpoSwapBackgroundTask,
3
3
  registerExpoSwapBackgroundTask,
4
4
  unregisterExpoSwapBackgroundTask
5
- } from "./chunk-3XJR3RIH.js";
6
- import "./chunk-NUR5GPRK.js";
5
+ } from "./chunk-QGPE6POI.js";
6
+ import "./chunk-NTTONVRX.js";
7
7
  import "./chunk-3RG5ZIWI.js";
8
8
  export {
9
9
  defineExpoSwapBackgroundTask,
@@ -3439,21 +3439,6 @@ var ArkadeSwaps = class _ArkadeSwaps {
3439
3439
  const preimageHash = pendingSwap.request.invoice ? getInvoicePaymentHash(pendingSwap.request.invoice) : pendingSwap.preimageHash;
3440
3440
  if (!preimageHash)
3441
3441
  throw new Error("Preimage hash is required to refund VHTLC");
3442
- const vhtlcPkScript = ArkAddress2.decode(
3443
- pendingSwap.response.address
3444
- ).pkScript;
3445
- const { vtxos } = await this.indexerProvider.getVtxos({
3446
- scripts: [hex8.encode(vhtlcPkScript)]
3447
- });
3448
- if (vtxos.length === 0) {
3449
- throw new Error(
3450
- `VHTLC not found for address ${pendingSwap.response.address}`
3451
- );
3452
- }
3453
- const vtxo = vtxos[0];
3454
- if (vtxo.isSpent) {
3455
- throw new Error("VHTLC is already spent");
3456
- }
3457
3442
  const arkInfo = await this.arkProvider.getInfo();
3458
3443
  const address = await this.wallet.getAddress();
3459
3444
  if (!address) throw new Error("Failed to get ark address from wallet");
@@ -3472,7 +3457,7 @@ var ArkadeSwaps = class _ArkadeSwaps {
3472
3457
  "boltz",
3473
3458
  pendingSwap.id
3474
3459
  );
3475
- const { vhtlcScript } = this.createVHTLCScript({
3460
+ const { vhtlcScript, vhtlcAddress } = this.createVHTLCScript({
3476
3461
  network: arkInfo.network,
3477
3462
  preimageHash: hex8.decode(preimageHash),
3478
3463
  receiverPubkey: hex8.encode(boltzXOnlyPublicKey),
@@ -3482,31 +3467,63 @@ var ArkadeSwaps = class _ArkadeSwaps {
3482
3467
  });
3483
3468
  if (!vhtlcScript.claimScript)
3484
3469
  throw new Error("Failed to create VHTLC script for submarine swap");
3485
- const isRecoverableVtxo = isRecoverable(vtxo);
3486
- const input = {
3487
- ...vtxo,
3488
- tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3489
- tapTree: vhtlcScript.encode()
3490
- };
3491
- const output = {
3492
- amount: BigInt(vtxo.value),
3493
- script: ArkAddress2.decode(address).pkScript
3494
- };
3495
- if (isRecoverableVtxo) {
3496
- await this.joinBatch(this.wallet.identity, input, output, arkInfo);
3497
- } else {
3498
- await refundVHTLCwithOffchainTx(
3499
- pendingSwap.id,
3500
- this.wallet.identity,
3501
- this.arkProvider,
3502
- boltzXOnlyPublicKey,
3503
- ourXOnlyPublicKey,
3504
- serverXOnlyPublicKey,
3505
- input,
3506
- output,
3507
- arkInfo,
3508
- this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
3470
+ if (vhtlcAddress !== pendingSwap.response.address)
3471
+ throw new Error(
3472
+ `VHTLC address mismatch for swap ${pendingSwap.id}: expected ${pendingSwap.response.address}, got ${vhtlcAddress}`
3509
3473
  );
3474
+ const vhtlcPkScriptHex = hex8.encode(vhtlcScript.pkScript);
3475
+ const { vtxos: spendableVtxos } = await this.indexerProvider.getVtxos({
3476
+ scripts: [vhtlcPkScriptHex],
3477
+ spendableOnly: true
3478
+ });
3479
+ if (spendableVtxos.length === 0) {
3480
+ const { vtxos: allVtxos } = await this.indexerProvider.getVtxos({
3481
+ scripts: [vhtlcPkScriptHex]
3482
+ });
3483
+ throw new Error(
3484
+ allVtxos.length > 0 ? "VHTLC is already spent" : `VHTLC not found for address ${pendingSwap.response.address}`
3485
+ );
3486
+ }
3487
+ const outputScript = ArkAddress2.decode(address).pkScript;
3488
+ let boltzCallCount = 0;
3489
+ for (const vtxo of spendableVtxos) {
3490
+ const isRecoverableVtxo = isRecoverable(vtxo);
3491
+ const input = {
3492
+ ...vtxo,
3493
+ tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3494
+ tapTree: vhtlcScript.encode()
3495
+ };
3496
+ const output = {
3497
+ amount: BigInt(vtxo.value),
3498
+ script: outputScript
3499
+ };
3500
+ if (isRecoverableVtxo) {
3501
+ await this.joinBatch(
3502
+ this.wallet.identity,
3503
+ input,
3504
+ output,
3505
+ arkInfo
3506
+ );
3507
+ } else {
3508
+ if (boltzCallCount > 0) {
3509
+ await new Promise((r) => setTimeout(r, 2e3));
3510
+ }
3511
+ await refundVHTLCwithOffchainTx(
3512
+ pendingSwap.id,
3513
+ this.wallet.identity,
3514
+ this.arkProvider,
3515
+ boltzXOnlyPublicKey,
3516
+ ourXOnlyPublicKey,
3517
+ serverXOnlyPublicKey,
3518
+ input,
3519
+ output,
3520
+ arkInfo,
3521
+ this.swapProvider.refundSubmarineSwap.bind(
3522
+ this.swapProvider
3523
+ )
3524
+ );
3525
+ boltzCallCount++;
3526
+ }
3510
3527
  }
3511
3528
  await updateSubmarineSwapStatus(
3512
3529
  pendingSwap,
@@ -8,7 +8,7 @@ import {
8
8
  isSubmarineFinalStatus,
9
9
  isSubmarineSwapRefundable,
10
10
  logger
11
- } from "./chunk-NUR5GPRK.js";
11
+ } from "./chunk-NTTONVRX.js";
12
12
  import {
13
13
  __require
14
14
  } from "./chunk-3RG5ZIWI.js";
@@ -3444,21 +3444,6 @@ var init_arkade_swaps = __esm({
3444
3444
  const preimageHash = pendingSwap.request.invoice ? getInvoicePaymentHash(pendingSwap.request.invoice) : pendingSwap.preimageHash;
3445
3445
  if (!preimageHash)
3446
3446
  throw new Error("Preimage hash is required to refund VHTLC");
3447
- const vhtlcPkScript = import_sdk8.ArkAddress.decode(
3448
- pendingSwap.response.address
3449
- ).pkScript;
3450
- const { vtxos } = await this.indexerProvider.getVtxos({
3451
- scripts: [import_base9.hex.encode(vhtlcPkScript)]
3452
- });
3453
- if (vtxos.length === 0) {
3454
- throw new Error(
3455
- `VHTLC not found for address ${pendingSwap.response.address}`
3456
- );
3457
- }
3458
- const vtxo = vtxos[0];
3459
- if (vtxo.isSpent) {
3460
- throw new Error("VHTLC is already spent");
3461
- }
3462
3447
  const arkInfo = await this.arkProvider.getInfo();
3463
3448
  const address = await this.wallet.getAddress();
3464
3449
  if (!address) throw new Error("Failed to get ark address from wallet");
@@ -3477,7 +3462,7 @@ var init_arkade_swaps = __esm({
3477
3462
  "boltz",
3478
3463
  pendingSwap.id
3479
3464
  );
3480
- const { vhtlcScript } = this.createVHTLCScript({
3465
+ const { vhtlcScript, vhtlcAddress } = this.createVHTLCScript({
3481
3466
  network: arkInfo.network,
3482
3467
  preimageHash: import_base9.hex.decode(preimageHash),
3483
3468
  receiverPubkey: import_base9.hex.encode(boltzXOnlyPublicKey),
@@ -3487,31 +3472,63 @@ var init_arkade_swaps = __esm({
3487
3472
  });
3488
3473
  if (!vhtlcScript.claimScript)
3489
3474
  throw new Error("Failed to create VHTLC script for submarine swap");
3490
- const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
3491
- const input = {
3492
- ...vtxo,
3493
- tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3494
- tapTree: vhtlcScript.encode()
3495
- };
3496
- const output = {
3497
- amount: BigInt(vtxo.value),
3498
- script: import_sdk8.ArkAddress.decode(address).pkScript
3499
- };
3500
- if (isRecoverableVtxo) {
3501
- await this.joinBatch(this.wallet.identity, input, output, arkInfo);
3502
- } else {
3503
- await refundVHTLCwithOffchainTx(
3504
- pendingSwap.id,
3505
- this.wallet.identity,
3506
- this.arkProvider,
3507
- boltzXOnlyPublicKey,
3508
- ourXOnlyPublicKey,
3509
- serverXOnlyPublicKey,
3510
- input,
3511
- output,
3512
- arkInfo,
3513
- this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
3475
+ if (vhtlcAddress !== pendingSwap.response.address)
3476
+ throw new Error(
3477
+ `VHTLC address mismatch for swap ${pendingSwap.id}: expected ${pendingSwap.response.address}, got ${vhtlcAddress}`
3514
3478
  );
3479
+ const vhtlcPkScriptHex = import_base9.hex.encode(vhtlcScript.pkScript);
3480
+ const { vtxos: spendableVtxos } = await this.indexerProvider.getVtxos({
3481
+ scripts: [vhtlcPkScriptHex],
3482
+ spendableOnly: true
3483
+ });
3484
+ if (spendableVtxos.length === 0) {
3485
+ const { vtxos: allVtxos } = await this.indexerProvider.getVtxos({
3486
+ scripts: [vhtlcPkScriptHex]
3487
+ });
3488
+ throw new Error(
3489
+ allVtxos.length > 0 ? "VHTLC is already spent" : `VHTLC not found for address ${pendingSwap.response.address}`
3490
+ );
3491
+ }
3492
+ const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
3493
+ let boltzCallCount = 0;
3494
+ for (const vtxo of spendableVtxos) {
3495
+ const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
3496
+ const input = {
3497
+ ...vtxo,
3498
+ tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3499
+ tapTree: vhtlcScript.encode()
3500
+ };
3501
+ const output = {
3502
+ amount: BigInt(vtxo.value),
3503
+ script: outputScript
3504
+ };
3505
+ if (isRecoverableVtxo) {
3506
+ await this.joinBatch(
3507
+ this.wallet.identity,
3508
+ input,
3509
+ output,
3510
+ arkInfo
3511
+ );
3512
+ } else {
3513
+ if (boltzCallCount > 0) {
3514
+ await new Promise((r) => setTimeout(r, 2e3));
3515
+ }
3516
+ await refundVHTLCwithOffchainTx(
3517
+ pendingSwap.id,
3518
+ this.wallet.identity,
3519
+ this.arkProvider,
3520
+ boltzXOnlyPublicKey,
3521
+ ourXOnlyPublicKey,
3522
+ serverXOnlyPublicKey,
3523
+ input,
3524
+ output,
3525
+ arkInfo,
3526
+ this.swapProvider.refundSubmarineSwap.bind(
3527
+ this.swapProvider
3528
+ )
3529
+ );
3530
+ boltzCallCount++;
3531
+ }
3515
3532
  }
3516
3533
  await updateSubmarineSwapStatus(
3517
3534
  pendingSwap,
@@ -4,10 +4,10 @@ import {
4
4
  registerExpoSwapBackgroundTask,
5
5
  swapsPollProcessor,
6
6
  unregisterExpoSwapBackgroundTask
7
- } from "../chunk-3XJR3RIH.js";
7
+ } from "../chunk-QGPE6POI.js";
8
8
  import {
9
9
  ArkadeSwaps
10
- } from "../chunk-NUR5GPRK.js";
10
+ } from "../chunk-NTTONVRX.js";
11
11
  import "../chunk-3RG5ZIWI.js";
12
12
 
13
13
  // src/expo/arkade-lightning.ts
@@ -56,7 +56,7 @@ var ExpoArkadeSwaps = class _ExpoArkadeSwaps {
56
56
  await instance.seedSwapPollTask();
57
57
  if (config.background.minimumBackgroundInterval) {
58
58
  try {
59
- const { registerExpoSwapBackgroundTask: registerExpoSwapBackgroundTask2 } = await import("../background-VM6FN7TU.js");
59
+ const { registerExpoSwapBackgroundTask: registerExpoSwapBackgroundTask2 } = await import("../background-SASNQHX4.js");
60
60
  await registerExpoSwapBackgroundTask2(
61
61
  config.background.taskName,
62
62
  {
@@ -129,7 +129,7 @@ var ExpoArkadeSwaps = class _ExpoArkadeSwaps {
129
129
  }
130
130
  await this.inner.dispose();
131
131
  try {
132
- const { unregisterExpoSwapBackgroundTask: unregisterExpoSwapBackgroundTask2 } = await import("../background-VM6FN7TU.js");
132
+ const { unregisterExpoSwapBackgroundTask: unregisterExpoSwapBackgroundTask2 } = await import("../background-SASNQHX4.js");
133
133
  await unregisterExpoSwapBackgroundTask2(this.taskName);
134
134
  } catch (err) {
135
135
  const message = err instanceof Error ? err.message : String(err);
package/dist/index.cjs CHANGED
@@ -3498,21 +3498,6 @@ var ArkadeSwaps = class _ArkadeSwaps {
3498
3498
  const preimageHash = pendingSwap.request.invoice ? getInvoicePaymentHash(pendingSwap.request.invoice) : pendingSwap.preimageHash;
3499
3499
  if (!preimageHash)
3500
3500
  throw new Error("Preimage hash is required to refund VHTLC");
3501
- const vhtlcPkScript = import_sdk8.ArkAddress.decode(
3502
- pendingSwap.response.address
3503
- ).pkScript;
3504
- const { vtxos } = await this.indexerProvider.getVtxos({
3505
- scripts: [import_base9.hex.encode(vhtlcPkScript)]
3506
- });
3507
- if (vtxos.length === 0) {
3508
- throw new Error(
3509
- `VHTLC not found for address ${pendingSwap.response.address}`
3510
- );
3511
- }
3512
- const vtxo = vtxos[0];
3513
- if (vtxo.isSpent) {
3514
- throw new Error("VHTLC is already spent");
3515
- }
3516
3501
  const arkInfo = await this.arkProvider.getInfo();
3517
3502
  const address = await this.wallet.getAddress();
3518
3503
  if (!address) throw new Error("Failed to get ark address from wallet");
@@ -3531,7 +3516,7 @@ var ArkadeSwaps = class _ArkadeSwaps {
3531
3516
  "boltz",
3532
3517
  pendingSwap.id
3533
3518
  );
3534
- const { vhtlcScript } = this.createVHTLCScript({
3519
+ const { vhtlcScript, vhtlcAddress } = this.createVHTLCScript({
3535
3520
  network: arkInfo.network,
3536
3521
  preimageHash: import_base9.hex.decode(preimageHash),
3537
3522
  receiverPubkey: import_base9.hex.encode(boltzXOnlyPublicKey),
@@ -3541,31 +3526,63 @@ var ArkadeSwaps = class _ArkadeSwaps {
3541
3526
  });
3542
3527
  if (!vhtlcScript.claimScript)
3543
3528
  throw new Error("Failed to create VHTLC script for submarine swap");
3544
- const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
3545
- const input = {
3546
- ...vtxo,
3547
- tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3548
- tapTree: vhtlcScript.encode()
3549
- };
3550
- const output = {
3551
- amount: BigInt(vtxo.value),
3552
- script: import_sdk8.ArkAddress.decode(address).pkScript
3553
- };
3554
- if (isRecoverableVtxo) {
3555
- await this.joinBatch(this.wallet.identity, input, output, arkInfo);
3556
- } else {
3557
- await refundVHTLCwithOffchainTx(
3558
- pendingSwap.id,
3559
- this.wallet.identity,
3560
- this.arkProvider,
3561
- boltzXOnlyPublicKey,
3562
- ourXOnlyPublicKey,
3563
- serverXOnlyPublicKey,
3564
- input,
3565
- output,
3566
- arkInfo,
3567
- this.swapProvider.refundSubmarineSwap.bind(this.swapProvider)
3529
+ if (vhtlcAddress !== pendingSwap.response.address)
3530
+ throw new Error(
3531
+ `VHTLC address mismatch for swap ${pendingSwap.id}: expected ${pendingSwap.response.address}, got ${vhtlcAddress}`
3568
3532
  );
3533
+ const vhtlcPkScriptHex = import_base9.hex.encode(vhtlcScript.pkScript);
3534
+ const { vtxos: spendableVtxos } = await this.indexerProvider.getVtxos({
3535
+ scripts: [vhtlcPkScriptHex],
3536
+ spendableOnly: true
3537
+ });
3538
+ if (spendableVtxos.length === 0) {
3539
+ const { vtxos: allVtxos } = await this.indexerProvider.getVtxos({
3540
+ scripts: [vhtlcPkScriptHex]
3541
+ });
3542
+ throw new Error(
3543
+ allVtxos.length > 0 ? "VHTLC is already spent" : `VHTLC not found for address ${pendingSwap.response.address}`
3544
+ );
3545
+ }
3546
+ const outputScript = import_sdk8.ArkAddress.decode(address).pkScript;
3547
+ let boltzCallCount = 0;
3548
+ for (const vtxo of spendableVtxos) {
3549
+ const isRecoverableVtxo = (0, import_sdk8.isRecoverable)(vtxo);
3550
+ const input = {
3551
+ ...vtxo,
3552
+ tapLeafScript: isRecoverableVtxo ? vhtlcScript.refundWithoutReceiver() : vhtlcScript.refund(),
3553
+ tapTree: vhtlcScript.encode()
3554
+ };
3555
+ const output = {
3556
+ amount: BigInt(vtxo.value),
3557
+ script: outputScript
3558
+ };
3559
+ if (isRecoverableVtxo) {
3560
+ await this.joinBatch(
3561
+ this.wallet.identity,
3562
+ input,
3563
+ output,
3564
+ arkInfo
3565
+ );
3566
+ } else {
3567
+ if (boltzCallCount > 0) {
3568
+ await new Promise((r) => setTimeout(r, 2e3));
3569
+ }
3570
+ await refundVHTLCwithOffchainTx(
3571
+ pendingSwap.id,
3572
+ this.wallet.identity,
3573
+ this.arkProvider,
3574
+ boltzXOnlyPublicKey,
3575
+ ourXOnlyPublicKey,
3576
+ serverXOnlyPublicKey,
3577
+ input,
3578
+ output,
3579
+ arkInfo,
3580
+ this.swapProvider.refundSubmarineSwap.bind(
3581
+ this.swapProvider
3582
+ )
3583
+ );
3584
+ boltzCallCount++;
3585
+ }
3569
3586
  }
3570
3587
  await updateSubmarineSwapStatus(
3571
3588
  pendingSwap,
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ import {
49
49
  updateReverseSwapStatus,
50
50
  updateSubmarineSwapStatus,
51
51
  verifySignatures
52
- } from "./chunk-NUR5GPRK.js";
52
+ } from "./chunk-NTTONVRX.js";
53
53
  import "./chunk-3RG5ZIWI.js";
54
54
 
55
55
  // src/serviceWorker/arkade-swaps-message-handler.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/boltz-swap",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "type": "module",
5
5
  "description": "A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.",
6
6
  "main": "./dist/index.js",