@arkade-os/sdk 0.4.3 → 0.4.4

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.
@@ -888,9 +888,13 @@ class Wallet extends ReadonlyWallet {
888
888
  }
889
889
  }
890
890
  let outputAssets;
891
- let assetOutputIndex; // where to send the assets
891
+ const destinationScript = address_1.ArkAddress.decode(await this.getAddress()).pkScript;
892
+ const assetOutputIndex = (0, delegator_1.findDestinationOutputIndex)(outputs, destinationScript);
892
893
  if (assetInputs.size > 0) {
893
- // collect all input assets and assign them to the first offchain output
894
+ if (assetOutputIndex === -1) {
895
+ throw new Error("Cannot assign assets: no output matches the destination address");
896
+ }
897
+ // collect all input assets and assign them to the destination output
894
898
  const allAssets = new Map();
895
899
  for (const [, assets] of assetInputs) {
896
900
  for (const asset of assets) {
@@ -902,11 +906,6 @@ class Wallet extends ReadonlyWallet {
902
906
  for (const [assetId, amount] of allAssets) {
903
907
  outputAssets.push({ assetId, amount: Number(amount) });
904
908
  }
905
- const firstOffchainIndex = params.outputs.findIndex((_, i) => !onchainOutputIndexes.includes(i));
906
- if (firstOffchainIndex === -1) {
907
- throw new Error("Cannot settle assets without an offchain output");
908
- }
909
- assetOutputIndex = firstOffchainIndex;
910
909
  }
911
910
  const recipients = params.outputs.map((output, i) => ({
912
911
  address: output.address,
@@ -27,7 +27,7 @@ import { buildTransactionHistory } from '../utils/transactionHistory.js';
27
27
  import { AssetManager, ReadonlyAssetManager } from './asset-manager.js';
28
28
  import { Extension } from '../extension/index.js';
29
29
  import { DelegateVtxo } from '../script/delegate.js';
30
- import { DelegatorManagerImpl } from './delegator.js';
30
+ import { DelegatorManagerImpl, findDestinationOutputIndex, } from './delegator.js';
31
31
  import { IndexedDBContractRepository, IndexedDBWalletRepository, } from '../repositories/index.js';
32
32
  import { ContractManager } from '../contracts/contractManager.js';
33
33
  import { contractHandlers } from '../contracts/handlers/index.js';
@@ -882,9 +882,13 @@ export class Wallet extends ReadonlyWallet {
882
882
  }
883
883
  }
884
884
  let outputAssets;
885
- let assetOutputIndex; // where to send the assets
885
+ const destinationScript = ArkAddress.decode(await this.getAddress()).pkScript;
886
+ const assetOutputIndex = findDestinationOutputIndex(outputs, destinationScript);
886
887
  if (assetInputs.size > 0) {
887
- // collect all input assets and assign them to the first offchain output
888
+ if (assetOutputIndex === -1) {
889
+ throw new Error("Cannot assign assets: no output matches the destination address");
890
+ }
891
+ // collect all input assets and assign them to the destination output
888
892
  const allAssets = new Map();
889
893
  for (const [, assets] of assetInputs) {
890
894
  for (const asset of assets) {
@@ -896,11 +900,6 @@ export class Wallet extends ReadonlyWallet {
896
900
  for (const [assetId, amount] of allAssets) {
897
901
  outputAssets.push({ assetId, amount: Number(amount) });
898
902
  }
899
- const firstOffchainIndex = params.outputs.findIndex((_, i) => !onchainOutputIndexes.includes(i));
900
- if (firstOffchainIndex === -1) {
901
- throw new Error("Cannot settle assets without an offchain output");
902
- }
903
- assetOutputIndex = firstOffchainIndex;
904
903
  }
905
904
  const recipients = params.outputs.map((output, i) => ({
906
905
  address: output.address,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/sdk",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Bitcoin wallet SDK with Taproot and Ark integration",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",