nexa-wallet-sdk 0.5.1 → 0.5.2

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.
package/dist/index.cjs CHANGED
@@ -149,7 +149,7 @@ $parcel$export(module.exports, "SighashType", () => $l50U0$libnexats.SighashType
149
149
  $parcel$export(module.exports, "AccountKeysUtils", () => $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6);
150
150
  // @ts-ignore
151
151
  var $2dd241e44b9dc3c2$exports = {};
152
- $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.5.1\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\",\"docs:serve\":\"typedoc && npx serve docs -l 8080\",\"docs:mkdocs\":\"typedoc && mkdocs serve\",\"docs:build\":\"typedoc && mkdocs build\",\"docs:setup\":\"./scripts/setup-docs.sh\",\"wallet-cli\":\"node examples/wallet-cli.cjs\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^1.0.5\",\"lodash-es\":\"^4.17.21\",\"prompt-sync\":\"^4.2.0\",\"wallet-comms-sdk\":\"^0.6.1\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
152
+ $2dd241e44b9dc3c2$exports = JSON.parse("{\"name\":\"nexa-wallet-sdk\",\"version\":\"0.5.2\",\"type\":\"module\",\"source\":\"src/index.ts\",\"types\":\"dist/index.d.ts\",\"main\":\"dist/index.cjs\",\"module\":\"dist/index.mjs\",\"browser\":\"dist/index.web.mjs\",\"exports\":{\"types\":\"./dist/index.d.ts\",\"node\":{\"import\":\"./dist/index.mjs\",\"require\":\"./dist/index.cjs\"},\"browser\":\"./dist/index.web.mjs\",\"default\":\"./dist/index.mjs\"},\"scripts\":{\"build\":\"parcel build\",\"lint\":\"eslint .\",\"fix-lint\":\"eslint --fix .\",\"dev\":\"parcel watch\",\"test\":\"vitest run\",\"clean\":\"rm -rf dist .parcel-cache\",\"docs\":\"typedoc\",\"docs:serve\":\"typedoc && npx serve docs -l 8080\",\"docs:mkdocs\":\"typedoc && mkdocs serve\",\"docs:build\":\"typedoc && mkdocs build\",\"docs:setup\":\"./scripts/setup-docs.sh\",\"wallet-cli\":\"node examples/wallet-cli.cjs\"},\"repository\":{\"type\":\"git\",\"url\":\"git+ssh://git@gitlab.com/nexa/wallet-sdk-ts.git\"},\"keywords\":[\"nexa\",\"wallet\",\"web3\",\"crypto\",\"dapp\",\"walletcomms\",\"walletsdk\"],\"contributors\":[{\"name\":\"Dolaned\"},{\"name\":\"Griffith\"},{\"name\":\"Vgrunner\"},{\"name\":\"myendy\"}],\"author\":\"Dolaned\",\"license\":\"MIT\",\"bugs\":{\"url\":\"https://gitlab.com/nexa/wallet-sdk-ts/issues\"},\"homepage\":\"https://gitlab.com/nexa/wallet-sdk-ts#readme\",\"description\":\"Wallet SDK for the Nexa blockchain\",\"devDependencies\":{\"@parcel/packager-ts\":\"^2.15.4\",\"@parcel/transformer-typescript-types\":\"^2.15.4\",\"@types/lodash-es\":\"^4.17.12\",\"@types/node\":\"^22.13.1\",\"eslint\":\"^9.20.1\",\"parcel\":\"^2.15.4\",\"typedoc\":\"^0.28.7\",\"typedoc-plugin-markdown\":\"^4.7.0\",\"typedoc-plugin-rename-defaults\":\"^0.7.3\",\"typescript\":\"^5.8.3\",\"typescript-eslint\":\"^8.24.1\",\"vitest\":\"^3.0.8\"},\"targets\":{\"main\":{\"context\":\"node\",\"outputFormat\":\"commonjs\",\"distDir\":\"dist\",\"isLibrary\":true,\"includeNodeModules\":[\"lodash-es\"]},\"module\":{\"context\":\"node\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true},\"browser\":{\"context\":\"browser\",\"outputFormat\":\"esmodule\",\"distDir\":\"dist\",\"isLibrary\":true}},\"dependencies\":{\"@vgrunner/electrum-cash\":\"^2.0.12\",\"bip39\":\"^3.1.0\",\"js-big-decimal\":\"^2.2.0\",\"libnexa-ts\":\"^1.0.5\",\"lodash-es\":\"^4.17.21\",\"prompt-sync\":\"^4.2.0\",\"wallet-comms-sdk\":\"^0.6.1\"},\"files\":[\"dist\"],\"directories\":{\"test\":\"tests\"},\"@parcel/resolver-default\":{\"packageExports\":true}}");
153
153
 
154
154
 
155
155
 
@@ -375,6 +375,7 @@ class $f8a48da5c0b6346a$export$c54c8796e94a37a0 {
375
375
  }
376
376
  constructor(_bip44Account){
377
377
  this._tokenBalances = {};
378
+ this._tokenAuthorities = {};
378
379
  this._transactions = new Map();
379
380
  this._bip44Account = _bip44Account;
380
381
  this._balance = {
@@ -382,6 +383,7 @@ class $f8a48da5c0b6346a$export$c54c8796e94a37a0 {
382
383
  unconfirmed: 0
383
384
  };
384
385
  this._tokenBalances = {};
386
+ this._tokenAuthorities = {};
385
387
  }
386
388
  get balance() {
387
389
  return this._balance;
@@ -395,6 +397,12 @@ class $f8a48da5c0b6346a$export$c54c8796e94a37a0 {
395
397
  set tokenBalances(value) {
396
398
  this._tokenBalances = value;
397
399
  }
400
+ get tokenAuthorities() {
401
+ return this._tokenAuthorities;
402
+ }
403
+ set tokenAuthorities(value) {
404
+ this._tokenAuthorities = value;
405
+ }
398
406
  async fetchAndClassifyTransactions(transactionAddress, fromHeight) {
399
407
  const transactions = await (0, $0d59d2bcffd646c5$export$a2ed4b531376a5a4)([
400
408
  transactionAddress
@@ -444,7 +452,7 @@ class $cf960f437fe63027$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$exp
444
452
  };
445
453
  }
446
454
  async loadBalances() {
447
- let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([
455
+ const { balances: balances, authorities: authorities } = await (0, $0d59d2bcffd646c5$export$e4fb0bc90aacba9e)([
448
456
  this._accountKey
449
457
  ]);
450
458
  let tokenBalances = [
@@ -452,6 +460,7 @@ class $cf960f437fe63027$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$exp
452
460
  ].map((k)=>k.tokensBalance);
453
461
  super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
454
462
  super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
463
+ super.tokenAuthorities = authorities;
455
464
  }
456
465
  getKeyFromAddress(address) {
457
466
  if (address !== this._accountKey.address) throw new Error(`Address ${address} does not belong to this account`);
@@ -505,10 +514,11 @@ class $1c49a4fffc97409b$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$exp
505
514
  return this._accountKeys;
506
515
  }
507
516
  async loadBalances() {
508
- let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)(this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys));
517
+ const { balances: balances, authorities: authorities } = await (0, $0d59d2bcffd646c5$export$e4fb0bc90aacba9e)(this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys));
509
518
  let tokenBalances = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys).map((k)=>k.tokensBalance);
510
519
  super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
511
520
  super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
521
+ super.tokenAuthorities = authorities;
512
522
  }
513
523
  getKeyFromAddress(address) {
514
524
  const allKeys = this._accountKeys.receiveKeys.concat(this._accountKeys.changeKeys);
@@ -595,7 +605,7 @@ class $0b557605c0e99621$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$exp
595
605
  };
596
606
  }
597
607
  async loadBalances() {
598
- let balances = await (0, $0d59d2bcffd646c5$export$9e38d26dbd7c33f4)([
608
+ const { balances: balances, authorities: authorities } = await (0, $0d59d2bcffd646c5$export$e4fb0bc90aacba9e)([
599
609
  this._accountKey
600
610
  ]);
601
611
  let tokenBalances = [
@@ -603,6 +613,7 @@ class $0b557605c0e99621$export$2e2bcd8739ae039 extends (0, $f8a48da5c0b6346a$exp
603
613
  ].map((k)=>k.tokensBalance);
604
614
  super.balance = (0, $0d59d2bcffd646c5$export$a26005fb5b8d1e4a)(balances);
605
615
  super.tokenBalances = (0, $0d59d2bcffd646c5$export$dec515296f176dbe)(tokenBalances);
616
+ super.tokenAuthorities = authorities;
606
617
  }
607
618
  getKeyFromAddress(address) {
608
619
  if (address !== this._accountKey.address) throw new Error(`Address ${address} does not belong to this account`);
@@ -658,6 +669,70 @@ function $bc5ca2c06b1affa3$export$f12d707d2b261fb6(txIdem, outputIndex) {
658
669
  }
659
670
 
660
671
 
672
+
673
+ function $22e282633cad8f97$export$7f7cffd29bf2d96d(authFlags, permission) {
674
+ if (authFlags > 0) return false;
675
+ let flags = BigInt.asUintN(64, BigInt(authFlags));
676
+ switch(permission){
677
+ case 'authorise':
678
+ return (0, $l50U0$libnexats.GroupToken).allowsRenew(flags);
679
+ case 'mint':
680
+ return (0, $l50U0$libnexats.GroupToken).allowsMint(flags);
681
+ case 'melt':
682
+ return (0, $l50U0$libnexats.GroupToken).allowsMelt(flags);
683
+ case 'rescript':
684
+ return (0, $l50U0$libnexats.GroupToken).allowsRescript(flags);
685
+ case 'subgroup':
686
+ return (0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags);
687
+ default:
688
+ return false;
689
+ }
690
+ }
691
+ function $22e282633cad8f97$export$636fb0b03b94ac81(authFlags, withSubgroup = true) {
692
+ if (authFlags > 0) return 0n;
693
+ let flags = BigInt.asUintN(64, BigInt(authFlags));
694
+ let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
695
+ if ((0, $l50U0$libnexats.GroupToken).allowsRenew(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
696
+ if ((0, $l50U0$libnexats.GroupToken).allowsMint(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
697
+ if ((0, $l50U0$libnexats.GroupToken).allowsMelt(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
698
+ if ((0, $l50U0$libnexats.GroupToken).allowsRescript(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
699
+ if ((0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags) && withSubgroup) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
700
+ return newFlags;
701
+ }
702
+ function $22e282633cad8f97$export$e240c810a53c3a0c(perms) {
703
+ let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
704
+ for (let perm of perms)switch(perm){
705
+ case 'authorise':
706
+ newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
707
+ break;
708
+ case 'mint':
709
+ newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
710
+ break;
711
+ case 'melt':
712
+ newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
713
+ break;
714
+ case 'rescript':
715
+ newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
716
+ break;
717
+ case 'subgroup':
718
+ newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
719
+ break;
720
+ }
721
+ return newFlags;
722
+ }
723
+ function $22e282633cad8f97$export$c949c84578b9e236(authFlags) {
724
+ if (authFlags > 0) return [];
725
+ const permissions = [];
726
+ const flags = BigInt.asUintN(64, BigInt(authFlags));
727
+ if ((0, $l50U0$libnexats.GroupToken).allowsRenew(flags)) permissions.push('authorise');
728
+ if ((0, $l50U0$libnexats.GroupToken).allowsMint(flags)) permissions.push('mint');
729
+ if ((0, $l50U0$libnexats.GroupToken).allowsMelt(flags)) permissions.push('melt');
730
+ if ((0, $l50U0$libnexats.GroupToken).allowsRescript(flags)) permissions.push('rescript');
731
+ if ((0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags)) permissions.push('subgroup');
732
+ return permissions;
733
+ }
734
+
735
+
661
736
  var $0d59d2bcffd646c5$export$dcc1fb6ad5308e56 = /*#__PURE__*/ function(TxTokenType) {
662
737
  TxTokenType[TxTokenType["NO_GROUP"] = 0] = "NO_GROUP";
663
738
  TxTokenType[TxTokenType["CREATE"] = 1] = "CREATE";
@@ -860,35 +935,81 @@ async function $0d59d2bcffd646c5$var$isAddressUsed(address) {
860
935
  throw e;
861
936
  }
862
937
  }
863
- async function $0d59d2bcffd646c5$var$getKeyTokenBalance(key) {
864
- let tokensBalance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokensBalance(key.address);
865
- let balance = {};
866
- for(const cToken in tokensBalance.confirmed)if (tokensBalance.confirmed[cToken] != 0) balance[cToken] = {
867
- confirmed: BigInt(tokensBalance.confirmed[cToken]).toString(),
868
- unconfirmed: "0"
869
- };
870
- for(const uToken in tokensBalance.unconfirmed)if (tokensBalance.unconfirmed[uToken] != 0) {
871
- if (balance[uToken]) balance[uToken].unconfirmed = BigInt(tokensBalance.unconfirmed[uToken]).toString();
872
- else balance[uToken] = {
873
- confirmed: "0",
874
- unconfirmed: BigInt(tokensBalance.unconfirmed[uToken]).toString()
938
+ async function $0d59d2bcffd646c5$var$getKeyTokenBalanceAndAuthorities(address) {
939
+ const tokensBalance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokensBalance(address);
940
+ const balance = {};
941
+ const authorities = {};
942
+ // Get all unique token IDs from both confirmed and unconfirmed
943
+ const allTokenIds = new Set([
944
+ ...Object.keys(tokensBalance.confirmed),
945
+ ...Object.keys(tokensBalance.unconfirmed)
946
+ ]);
947
+ // Process each token to get both balance and check for authorities
948
+ for (const tokenId of allTokenIds){
949
+ const confirmedAmount = tokensBalance.confirmed[tokenId] || 0;
950
+ const unconfirmedAmount = tokensBalance.unconfirmed[tokenId] || 0;
951
+ // Add to balance if non-zero
952
+ if (confirmedAmount !== 0 || unconfirmedAmount !== 0) balance[tokenId] = {
953
+ confirmed: BigInt(confirmedAmount).toString(),
954
+ unconfirmed: BigInt(unconfirmedAmount).toString()
875
955
  };
956
+ // Check for authorities by getting token UTXOs
957
+ try {
958
+ const tokenUtxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(address, tokenId);
959
+ if (tokenUtxos && tokenUtxos.length > 0) {
960
+ // Look for authorities (negative amounts)
961
+ const authUtxos = tokenUtxos.filter((utxo)=>{
962
+ const amount = parseInt(String(utxo.token_amount || '0'));
963
+ return amount < 0;
964
+ });
965
+ // Add permissions and address to each authority UTXO and organize by token ID
966
+ if (authUtxos.length > 0) {
967
+ const authoritiesWithPermissions = authUtxos.map((utxo)=>({
968
+ ...utxo,
969
+ permissions: (0, $22e282633cad8f97$export$c949c84578b9e236)(parseInt(String(utxo.token_amount || '0'))),
970
+ address: address
971
+ }));
972
+ authorities[tokenId] = authoritiesWithPermissions;
973
+ }
974
+ }
975
+ } catch (error) {
976
+ console.warn(`Error checking authorities for token ${tokenId} on address ${address}:`, error);
977
+ }
876
978
  }
877
- return balance;
979
+ return {
980
+ balance: balance,
981
+ authorities: authorities
982
+ };
878
983
  }
879
984
  async function $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key) {
880
985
  let balance = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getBalance(key.address);
881
986
  key.balance = (BigInt(balance.confirmed) + BigInt(balance.unconfirmed)).toString();
882
- key.tokensBalance = await $0d59d2bcffd646c5$var$getKeyTokenBalance(key);
883
- return balance;
987
+ const { balance: tokenBalance, authorities: authorities } = await $0d59d2bcffd646c5$var$getKeyTokenBalanceAndAuthorities(key.address);
988
+ key.tokensBalance = tokenBalance;
989
+ return {
990
+ balance: balance,
991
+ authorities: authorities
992
+ };
884
993
  }
885
- async function $0d59d2bcffd646c5$export$9e38d26dbd7c33f4(keys) {
994
+ async function $0d59d2bcffd646c5$export$e4fb0bc90aacba9e(keys) {
886
995
  let promises = [];
887
996
  keys.forEach((key)=>{
888
- let b = $0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key);
889
- promises.push(b);
997
+ promises.push($0d59d2bcffd646c5$var$getAndUpdateAddressKeyBalance(key));
890
998
  });
891
- return await Promise.all(promises);
999
+ const results = await Promise.all(promises);
1000
+ const balances = results.map((r)=>r.balance);
1001
+ // Combine authorities from all addresses, merging by token ID
1002
+ const combinedAuthorities = {};
1003
+ results.forEach((result)=>{
1004
+ Object.keys(result.authorities).forEach((tokenId)=>{
1005
+ if (combinedAuthorities[tokenId]) combinedAuthorities[tokenId] = combinedAuthorities[tokenId].concat(result.authorities[tokenId]);
1006
+ else combinedAuthorities[tokenId] = result.authorities[tokenId];
1007
+ });
1008
+ });
1009
+ return {
1010
+ balances: balances,
1011
+ authorities: combinedAuthorities
1012
+ };
892
1013
  }
893
1014
  function $0d59d2bcffd646c5$export$a26005fb5b8d1e4a(balances) {
894
1015
  let confirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0), unconfirmed = new (0, ($parcel$interopDefault($l50U0$jsbigdecimal)))(0);
@@ -1309,58 +1430,6 @@ class $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6 {
1309
1430
 
1310
1431
 
1311
1432
 
1312
- function $22e282633cad8f97$export$7f7cffd29bf2d96d(authFlags, permission) {
1313
- if (authFlags > 0) return false;
1314
- let flags = BigInt.asUintN(64, BigInt(authFlags));
1315
- switch(permission){
1316
- case 'authorise':
1317
- return (0, $l50U0$libnexats.GroupToken).allowsRenew(flags);
1318
- case 'mint':
1319
- return (0, $l50U0$libnexats.GroupToken).allowsMint(flags);
1320
- case 'melt':
1321
- return (0, $l50U0$libnexats.GroupToken).allowsMelt(flags);
1322
- case 'rescript':
1323
- return (0, $l50U0$libnexats.GroupToken).allowsRescript(flags);
1324
- case 'subgroup':
1325
- return (0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags);
1326
- default:
1327
- return false;
1328
- }
1329
- }
1330
- function $22e282633cad8f97$export$636fb0b03b94ac81(authFlags, withSubgroup = true) {
1331
- if (authFlags > 0) return 0n;
1332
- let flags = BigInt.asUintN(64, BigInt(authFlags));
1333
- let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
1334
- if ((0, $l50U0$libnexats.GroupToken).allowsRenew(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
1335
- if ((0, $l50U0$libnexats.GroupToken).allowsMint(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
1336
- if ((0, $l50U0$libnexats.GroupToken).allowsMelt(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
1337
- if ((0, $l50U0$libnexats.GroupToken).allowsRescript(flags)) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
1338
- if ((0, $l50U0$libnexats.GroupToken).allowsSubgroup(flags) && withSubgroup) newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
1339
- return newFlags;
1340
- }
1341
- function $22e282633cad8f97$export$e240c810a53c3a0c(perms) {
1342
- let newFlags = (0, $l50U0$libnexats.GroupToken).authFlags.AUTHORITY;
1343
- for (let perm of perms)switch(perm){
1344
- case 'authorise':
1345
- newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.BATON;
1346
- break;
1347
- case 'mint':
1348
- newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MINT;
1349
- break;
1350
- case 'melt':
1351
- newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.MELT;
1352
- break;
1353
- case 'rescript':
1354
- newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.RESCRIPT;
1355
- break;
1356
- case 'subgroup':
1357
- newFlags |= (0, $l50U0$libnexats.GroupToken).authFlags.SUBGROUP;
1358
- break;
1359
- }
1360
- return newFlags;
1361
- }
1362
-
1363
-
1364
1433
  /** Maximum number of inputs/outputs allowed in a single transaction */ const $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS = 250;
1365
1434
  async function $b4a043612f1c4089$export$afd979971a55acfc(txBuilder, keys, totalTxValue, options, spentOutpoints) {
1366
1435
  let rKeys = keys.receiveKeys.filter((k)=>BigInt(k.balance) > 0n);
@@ -1372,7 +1441,6 @@ async function $b4a043612f1c4089$export$afd979971a55acfc(txBuilder, keys, totalT
1372
1441
  for (let key of allKeys){
1373
1442
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(key.address);
1374
1443
  for (let utxo of utxos){
1375
- // Skip if this outpoint is already spent
1376
1444
  if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1377
1445
  let input = {
1378
1446
  outpoint: utxo.outpoint_hash,
@@ -1381,7 +1449,6 @@ async function $b4a043612f1c4089$export$afd979971a55acfc(txBuilder, keys, totalT
1381
1449
  templateData: options.templateData
1382
1450
  };
1383
1451
  txBuilder.from(input);
1384
- // Add to spent outpoints set
1385
1452
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1386
1453
  if (!usedKeys.has(key.address)) usedKeys.set(key.address, key.key.privateKey);
1387
1454
  if (options.isConsolidate) {
@@ -1427,10 +1494,7 @@ async function $b4a043612f1c4089$export$afd979971a55acfc(txBuilder, keys, totalT
1427
1494
  throw new Error(JSON.stringify(err));
1428
1495
  }
1429
1496
  async function $b4a043612f1c4089$export$931e37acdaa22dcf(txBuilder, keys, token, outTokenAmount, spentOutpoints) {
1430
- let tokenHex = (0, $bc5ca2c06b1affa3$export$254a5c7330bbfd41)(token);
1431
- let rKeys = keys.receiveKeys.filter((k)=>Object.keys(k.tokensBalance).includes(tokenHex));
1432
- let cKeys = keys.changeKeys.filter((k)=>Object.keys(k.tokensBalance).includes(tokenHex));
1433
- let allKeys = rKeys.concat(cKeys);
1497
+ let allKeys = keys.receiveKeys.concat(keys.changeKeys);
1434
1498
  if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(allKeys)) throw new Error("Not enough token balance.");
1435
1499
  let usedKeys = new Map();
1436
1500
  let inTokenAmount = 0n;
@@ -1438,7 +1502,6 @@ async function $b4a043612f1c4089$export$931e37acdaa22dcf(txBuilder, keys, token,
1438
1502
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
1439
1503
  for (let utxo of utxos){
1440
1504
  if (utxo.token_amount < 0) continue;
1441
- // Skip if this outpoint is already spent
1442
1505
  if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1443
1506
  txBuilder.from({
1444
1507
  outpoint: utxo.outpoint_hash,
@@ -1447,7 +1510,6 @@ async function $b4a043612f1c4089$export$931e37acdaa22dcf(txBuilder, keys, token,
1447
1510
  groupId: utxo.group,
1448
1511
  groupAmount: BigInt(utxo.token_amount)
1449
1512
  });
1450
- // Add to spent outpoints set
1451
1513
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1452
1514
  inTokenAmount = inTokenAmount + BigInt(utxo.token_amount);
1453
1515
  if (!usedKeys.has(key.address)) usedKeys.set(key.address, key.key.privateKey);
@@ -1455,7 +1517,6 @@ async function $b4a043612f1c4089$export$931e37acdaa22dcf(txBuilder, keys, token,
1455
1517
  if (txBuilder.transaction.inputs.length > $b4a043612f1c4089$var$MAX_INPUTS_OUTPUTS) throw new Error("Too many inputs. Consider consolidating transactions or reduce the send amount.");
1456
1518
  if (inTokenAmount == outTokenAmount) return Array.from(usedKeys.values());
1457
1519
  if (inTokenAmount > outTokenAmount) {
1458
- // change
1459
1520
  const tokenChangeAddress = keys.changeKeys.length > 0 ? keys.changeKeys[keys.changeKeys.length - 1].address : keys.receiveKeys[keys.receiveKeys.length - 1].address;
1460
1521
  txBuilder.to(tokenChangeAddress, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, inTokenAmount - outTokenAmount);
1461
1522
  return Array.from(usedKeys.values());
@@ -1473,14 +1534,12 @@ async function $b4a043612f1c4089$export$d7f2b844e1d59768(txBuilder, keys, opRetu
1473
1534
  for (let key of allKeys){
1474
1535
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getNexaUtxos(key.address);
1475
1536
  for (let utxo of utxos){
1476
- // Skip if this outpoint is already spent
1477
1537
  if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1478
1538
  txBuilder.from({
1479
1539
  outpoint: utxo.outpoint_hash,
1480
1540
  address: key.address,
1481
1541
  satoshis: utxo.value
1482
1542
  });
1483
- // Add to spent outpoints set
1484
1543
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1485
1544
  if ((0, $bc5ca2c06b1affa3$export$c8733ae29fb53302)(outpoint)) {
1486
1545
  outpoint = utxo.outpoint_hash;
@@ -1516,14 +1575,12 @@ async function $b4a043612f1c4089$export$1dfa5d829fc95097(txBuilder, keys, token,
1516
1575
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
1517
1576
  for (let utxo of utxos){
1518
1577
  if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) continue;
1519
- // Skip if this outpoint is already spent
1520
1578
  if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1521
1579
  txBuilder.from({
1522
1580
  outpoint: utxo.outpoint_hash,
1523
1581
  address: key.address,
1524
1582
  satoshis: utxo.value
1525
1583
  });
1526
- // Add to spent outpoints set
1527
1584
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1528
1585
  if (perm === 'subgroup') {
1529
1586
  const subgroupQuantity = quantity ?? (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount, false);
@@ -1541,6 +1598,108 @@ async function $b4a043612f1c4089$export$1dfa5d829fc95097(txBuilder, keys, token,
1541
1598
  }
1542
1599
  throw new Error("The requested authority not found");
1543
1600
  }
1601
+ async function $b4a043612f1c4089$export$fc6e64edb1452fc7(txBuilder, keys, token, amount, parentToken, spentOutpoints) {
1602
+ const privateKeys = [];
1603
+ const allKeys = (0, $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6).getAllKeys(keys);
1604
+ // Determine which token to look for authority
1605
+ const authTokenId = parentToken || token;
1606
+ const isSubgroupMint = !!parentToken;
1607
+ // Find and add mint authority
1608
+ let mintAuthorityFound = false;
1609
+ for (let key of allKeys){
1610
+ if (mintAuthorityFound) break;
1611
+ let authUtxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, authTokenId);
1612
+ for (let utxo of authUtxos){
1613
+ if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, 'mint')) continue;
1614
+ // Skip if already spent
1615
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1616
+ // Add mint authority as input
1617
+ txBuilder.from({
1618
+ outpoint: utxo.outpoint_hash,
1619
+ address: key.address,
1620
+ satoshis: utxo.value
1621
+ });
1622
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1623
+ // Create the minted tokens output
1624
+ const mintAddress = keys.receiveKeys[keys.receiveKeys.length - 1].address;
1625
+ txBuilder.to(mintAddress, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, amount);
1626
+ // Preserve the mint authority for future use
1627
+ if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) {
1628
+ const authChangeAddress = keys.changeKeys.length > 0 ? keys.changeKeys[keys.changeKeys.length - 1].address : keys.receiveKeys[keys.receiveKeys.length - 1].address;
1629
+ txBuilder.to(authChangeAddress, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, authTokenId, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
1630
+ }
1631
+ privateKeys.push(key.key.privateKey);
1632
+ mintAuthorityFound = true;
1633
+ break;
1634
+ }
1635
+ }
1636
+ if (!mintAuthorityFound) throw new Error(`Mint authority not found for token ${authTokenId}`);
1637
+ return privateKeys;
1638
+ }
1639
+ async function $b4a043612f1c4089$export$661377a8795b235c(txBuilder, keys, token, amount, parentToken, spentOutpoints) {
1640
+ const privateKeys = [];
1641
+ const allKeys = (0, $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6).getAllKeys(keys);
1642
+ const authTokenId = parentToken || token;
1643
+ // First, find and add melt authority
1644
+ let meltAuthorityFound = false;
1645
+ for (let key of allKeys){
1646
+ if (meltAuthorityFound) break;
1647
+ let authUtxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, authTokenId);
1648
+ for (let utxo of authUtxos){
1649
+ if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, 'melt')) continue;
1650
+ // Skip if already spent
1651
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1652
+ // Add melt authority as input
1653
+ txBuilder.from({
1654
+ outpoint: utxo.outpoint_hash,
1655
+ address: key.address,
1656
+ satoshis: utxo.value
1657
+ });
1658
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1659
+ // Preserve the melt authority for future use
1660
+ if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) {
1661
+ const authChangeAddress = keys.changeKeys.length > 0 ? keys.changeKeys[keys.changeKeys.length - 1].address : keys.receiveKeys[keys.receiveKeys.length - 1].address;
1662
+ txBuilder.to(authChangeAddress, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
1663
+ }
1664
+ privateKeys.push(key.key.privateKey);
1665
+ meltAuthorityFound = true;
1666
+ break;
1667
+ }
1668
+ }
1669
+ if (!meltAuthorityFound) throw new Error("Melt authority not found for token");
1670
+ // Now find and add token UTXOs to melt
1671
+ let inTokenAmount = 0n;
1672
+ for (let key of allKeys){
1673
+ let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
1674
+ for (let utxo of utxos){
1675
+ // Skip authorities (negative amounts)
1676
+ if (utxo.token_amount < 0) continue;
1677
+ // Skip if already spent
1678
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1679
+ // Add token UTXO as input
1680
+ txBuilder.from({
1681
+ outpoint: utxo.outpoint_hash,
1682
+ address: key.address,
1683
+ satoshis: utxo.value,
1684
+ groupId: utxo.group,
1685
+ groupAmount: BigInt(utxo.token_amount)
1686
+ });
1687
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1688
+ inTokenAmount += BigInt(utxo.token_amount);
1689
+ if (!privateKeys.includes(key.key.privateKey)) privateKeys.push(key.key.privateKey);
1690
+ // Check if we have enough tokens to melt
1691
+ if (inTokenAmount >= amount) {
1692
+ // Create change output if melting less than full amount
1693
+ if (inTokenAmount > amount) {
1694
+ const changeAddress = keys.changeKeys.length > 0 ? keys.changeKeys[keys.changeKeys.length - 1].address : keys.receiveKeys[keys.receiveKeys.length - 1].address;
1695
+ txBuilder.to(changeAddress, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, inTokenAmount - amount);
1696
+ }
1697
+ return privateKeys;
1698
+ }
1699
+ }
1700
+ }
1701
+ throw new Error(`Not enough token balance to melt. Required: ${amount}, Available: ${inTokenAmount}`);
1702
+ }
1544
1703
  async function $b4a043612f1c4089$export$28a843ca046a6b3f(txBuilder, keys, token, perms, toAddr, spentOutpoints) {
1545
1704
  let allKeys = (0, $4d68f29c39c1a3e4$export$94f569bf4eb0f6f6).getAllKeys(keys);
1546
1705
  let usedKeys = [];
@@ -1550,7 +1709,6 @@ async function $b4a043612f1c4089$export$28a843ca046a6b3f(txBuilder, keys, token,
1550
1709
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(key.address, token);
1551
1710
  for (let utxo of utxos){
1552
1711
  if (utxo.token_amount > 0) continue;
1553
- // Skip if this outpoint is already spent
1554
1712
  if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
1555
1713
  let found = false;
1556
1714
  for (let perm of reqiredPerms)if ((0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, perm)) {
@@ -1564,7 +1722,6 @@ async function $b4a043612f1c4089$export$28a843ca046a6b3f(txBuilder, keys, token,
1564
1722
  satoshis: utxo.value
1565
1723
  });
1566
1724
  usedKeys.push(key.key.privateKey);
1567
- // Add to spent outpoints set
1568
1725
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
1569
1726
  // duplicate
1570
1727
  const duplicateAddress = toAddr != null ? toAddr : keys.changeKeys.length > 0 ? keys.changeKeys[keys.changeKeys.length - 1].address : keys.receiveKeys[keys.receiveKeys.length - 1].address;
@@ -1574,6 +1731,34 @@ async function $b4a043612f1c4089$export$28a843ca046a6b3f(txBuilder, keys, token,
1574
1731
  }
1575
1732
  throw new Error("The required authorities not found");
1576
1733
  }
1734
+ function $b4a043612f1c4089$export$eabd1dee7adcf71(txHex, network) {
1735
+ const tokenOutputs = [];
1736
+ try {
1737
+ const transaction = new (0, $l50U0$libnexats.Transaction)(txHex);
1738
+ for (const output of transaction.outputs)if (output.type !== 0 && output.scriptPubKey.chunks[0]?.opcodenum >= 32) {
1739
+ const tokenIdHex = output.scriptPubKey.chunks[0].buf?.toString('hex');
1740
+ if (tokenIdHex && output.scriptPubKey.chunks[1]?.buf) {
1741
+ const tokenAddress = (0, $l50U0$libnexats.Address).fromObject({
1742
+ data: tokenIdHex,
1743
+ network: network.toString(),
1744
+ type: (0, $l50U0$libnexats.AddressType).GroupIdAddress
1745
+ });
1746
+ if (tokenAddress !== null) {
1747
+ const tokenAddressStr = tokenAddress.toString();
1748
+ // Extract token amount
1749
+ const tokenAmount = (0, $l50U0$libnexats.BNExtended).fromScriptNumBuffer(output.scriptPubKey.chunks[1].buf, false, 8).toBigInt();
1750
+ tokenOutputs.push({
1751
+ tokenId: tokenAddressStr,
1752
+ amount: tokenAmount.toString()
1753
+ });
1754
+ }
1755
+ }
1756
+ }
1757
+ } catch (error) {
1758
+ console.warn('Failed to extract token data from transaction:', error);
1759
+ }
1760
+ return tokenOutputs;
1761
+ }
1577
1762
 
1578
1763
 
1579
1764
 
@@ -1849,9 +2034,10 @@ class $57b0117fe8233fef$export$bba690fb5c12ba04 {
1849
2034
  * @param amount Amount to send
1850
2035
  * @param token Token ID
1851
2036
  * @param action Action type (mint, melt, send, etc.)
2037
+ * @param parent Optional parent token ID (for NFT/SFT minting)
1852
2038
  * @throws Error if validation fails
1853
- */ tokenAction(toAddr, amount, token, action) {
1854
- // Validate destination address
2039
+ */ tokenAction(toAddr, amount, token, action, parent) {
2040
+ // Validate destokenActiontination address
1855
2041
  if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network) && !(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(toAddr, this.network, (0, $l50U0$libnexats.AddressType).PayToPublicKeyHash)) throw new Error('Invalid Address.');
1856
2042
  // Validate amount ranges
1857
2043
  if (token && BigInt(amount) < 1n || !token && (0, $ed110f8656071ee4$export$2e2bcd8739ae039)(amount) < (0, $l50U0$libnexats.Transaction).DUST_AMOUNT) throw new Error("The amount is too low.");
@@ -1860,11 +2046,13 @@ class $57b0117fe8233fef$export$bba690fb5c12ba04 {
1860
2046
  if (!(0, $0d59d2bcffd646c5$export$8d986bd2866fe6ab)(token, this.network, (0, $l50U0$libnexats.AddressType).GroupIdAddress)) throw new Error('Invalid Token ID');
1861
2047
  // Ensure tokens are sent to script template addresses
1862
2048
  if ((0, $l50U0$libnexats.Address).getOutputType(toAddr) === 0) throw new Error('Token must be sent to script template address');
1863
- // Add output to transaction
2049
+ // For mint and melt operations, don't add output here - specialized functions will handle it
2050
+ if (action !== 'mint' && action !== 'melt') // Add output to transaction for regular token operations (send, etc.)
1864
2051
  this.transactionBuilder.to(toAddr, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, BigInt(amount));
1865
2052
  // Record the token action
1866
2053
  this.tokens.add({
1867
2054
  token: token,
2055
+ parentToken: parent,
1868
2056
  amount: BigInt(amount),
1869
2057
  action: action
1870
2058
  });
@@ -2188,17 +2376,17 @@ class $e1896e59040fa3c5$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$exp
2188
2376
  if (this._keysToSign.length == 0) this._keysToSign.push(this._account.getPrimaryAddressKey().key.privateKey);
2189
2377
  return this;
2190
2378
  }
2191
- mint(token, amount) {
2379
+ mint(token, amount, parent) {
2192
2380
  this.builder.push(async ()=>{
2193
2381
  let toAddr = this._account.accountKeys.receiveKeys.at(-1).address;
2194
- this.tokenAction(toAddr, amount, token, 'mint');
2382
+ this.tokenAction(toAddr, amount, token, 'mint', parent);
2195
2383
  });
2196
2384
  return this;
2197
2385
  }
2198
- melt(token, amount) {
2386
+ melt(token, amount, parent) {
2199
2387
  this.builder.push(async ()=>{
2200
2388
  let toAddr = this._account.accountKeys.receiveKeys.at(-1).address;
2201
- this.tokenAction(toAddr, amount, token, 'melt');
2389
+ this.tokenAction(toAddr, amount, token, 'melt', parent);
2202
2390
  });
2203
2391
  return this;
2204
2392
  }
@@ -2208,7 +2396,8 @@ class $e1896e59040fa3c5$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$exp
2208
2396
  let tK = [];
2209
2397
  let nK = [];
2210
2398
  if (this.tokens.size > 0) for (const tokenAction of this.tokens){
2211
- if (tokenAction.action == 'mint' || tokenAction.action == 'melt') tK = tK.concat(await (0, $b4a043612f1c4089$export$1dfa5d829fc95097)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.action, undefined, undefined, undefined, this.spentOutpoints));
2399
+ if (tokenAction.action == 'mint') tK = tK.concat(await (0, $b4a043612f1c4089$export$fc6e64edb1452fc7)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.amount, tokenAction.parentToken, this.spentOutpoints));
2400
+ else if (tokenAction.action == 'melt') tK = tK.concat(await (0, $b4a043612f1c4089$export$661377a8795b235c)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.amount, tokenAction.parentToken, this.spentOutpoints));
2212
2401
  else if (tokenAction.action == 'group') tK = tK.concat(await (0, $b4a043612f1c4089$export$d7f2b844e1d59768)(this.transactionBuilder, this._account.accountKeys, tokenAction.extraData?.opReturnData, this.network, this.spentOutpoints));
2213
2402
  else if (tokenAction.action == 'subgroup') tK = tK.concat(await (0, $b4a043612f1c4089$export$1dfa5d829fc95097)(this.transactionBuilder, this._account.accountKeys, tokenAction.parentToken, 'subgroup', tokenAction.token, this._account.accountKeys.receiveKeys.at(-1).address, tokenAction.extraData?.quantity, this.spentOutpoints));
2214
2403
  else if (tokenAction.action == 'renew') tK = tK.concat(await (0, $b4a043612f1c4089$export$28a843ca046a6b3f)(this.transactionBuilder, this._account.accountKeys, tokenAction.token, tokenAction.extraData.perms, tokenAction.extraData.address, this.spentOutpoints));
@@ -3290,7 +3479,7 @@ async function $52632971edbdb934$export$1eb54f2f084fd3c6(txBuilder, addresses, o
3290
3479
  addrKey.address
3291
3480
  ];
3292
3481
  }
3293
- async function $52632971edbdb934$export$d7c9c386067a6463(txBuilder, addresses, token, perm, subgroup = '', quantity, spentOutpoints) {
3482
+ async function $52632971edbdb934$export$d7c9c386067a6463(txBuilder, addresses, token, perm, subgroup = '', subgroupAddr = '', quantity, spentOutpoints) {
3294
3483
  for (let item of addresses){
3295
3484
  let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, token);
3296
3485
  for (let utxo of utxos){
@@ -3306,7 +3495,7 @@ async function $52632971edbdb934$export$d7c9c386067a6463(txBuilder, addresses, t
3306
3495
  if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
3307
3496
  if (perm === 'subgroup') {
3308
3497
  const subgroupQuantity = quantity ?? (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount, false);
3309
- txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, subgroup, subgroupQuantity);
3498
+ txBuilder.to(subgroupAddr, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, subgroup, subgroupQuantity);
3310
3499
  }
3311
3500
  // if renew flag included, we don't want to burn it
3312
3501
  if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
@@ -3317,6 +3506,94 @@ async function $52632971edbdb934$export$d7c9c386067a6463(txBuilder, addresses, t
3317
3506
  }
3318
3507
  throw new Error("The requested authority not found");
3319
3508
  }
3509
+ async function $52632971edbdb934$export$91f9f23df90683cc(txBuilder, addresses, token, amount, parentToken, spentOutpoints) {
3510
+ const usedAddresses = [];
3511
+ // Determine which token to look for authority
3512
+ const authTokenId = parentToken || token;
3513
+ // Find and add mint authority
3514
+ let mintAuthorityFound = false;
3515
+ for (let item of addresses){
3516
+ if (mintAuthorityFound) break;
3517
+ let authUtxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, authTokenId);
3518
+ for (let utxo of authUtxos){
3519
+ if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, 'mint')) continue;
3520
+ // Skip if already spent
3521
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
3522
+ // Add mint authority as input
3523
+ txBuilder.from({
3524
+ outpoint: utxo.outpoint_hash,
3525
+ address: item.address,
3526
+ satoshis: utxo.value
3527
+ });
3528
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
3529
+ // Create the minted tokens output
3530
+ txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, amount);
3531
+ // Preserve the mint authority for future use if renewable
3532
+ if ((0, $l50U0$libnexats.GroupToken).allowsRenew(BigInt.asUintN(64, BigInt(utxo.token_amount)))) txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, authTokenId, (0, $22e282633cad8f97$export$636fb0b03b94ac81)(utxo.token_amount));
3533
+ usedAddresses.push(item.address);
3534
+ mintAuthorityFound = true;
3535
+ break;
3536
+ }
3537
+ }
3538
+ if (!mintAuthorityFound) throw new Error(`Mint authority not found for token ${authTokenId}`);
3539
+ return usedAddresses;
3540
+ }
3541
+ async function $52632971edbdb934$export$cfda880a425a2203(txBuilder, addresses, token, amount, parentToken, spentOutpoints) {
3542
+ const usedAddresses = [];
3543
+ // Determine which token to look for melt authority
3544
+ const authTokenId = parentToken || token;
3545
+ // Find and add melt authority first
3546
+ let meltAuthorityFound = false;
3547
+ for (let item of addresses){
3548
+ if (meltAuthorityFound) break;
3549
+ let authUtxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, authTokenId);
3550
+ for (let utxo of authUtxos){
3551
+ if (!(0, $22e282633cad8f97$export$7f7cffd29bf2d96d)(utxo.token_amount, 'melt')) continue;
3552
+ // Skip if already spent
3553
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
3554
+ // Add melt authority as input
3555
+ txBuilder.from({
3556
+ outpoint: utxo.outpoint_hash,
3557
+ address: item.address,
3558
+ satoshis: utxo.value
3559
+ });
3560
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
3561
+ usedAddresses.push(item.address);
3562
+ meltAuthorityFound = true;
3563
+ break;
3564
+ }
3565
+ }
3566
+ if (!meltAuthorityFound) throw new Error("Melt authority not found for token");
3567
+ // Now find and add token UTXOs to melt
3568
+ let inTokenAmount = 0n;
3569
+ for (let item of addresses){
3570
+ let utxos = await (0, $b5bfd17fdf06d231$export$eaa49f0478d81b9d).getTokenUtxos(item.address, token);
3571
+ for (let utxo of utxos){
3572
+ // Skip authorities (negative amounts)
3573
+ if (utxo.token_amount < 0) continue;
3574
+ // Skip if already spent
3575
+ if (spentOutpoints && spentOutpoints.has(utxo.outpoint_hash)) continue;
3576
+ // Add token UTXO as input
3577
+ txBuilder.from({
3578
+ outpoint: utxo.outpoint_hash,
3579
+ address: item.address,
3580
+ satoshis: utxo.value,
3581
+ groupId: utxo.group,
3582
+ groupAmount: BigInt(utxo.token_amount)
3583
+ });
3584
+ if (spentOutpoints) spentOutpoints.add(utxo.outpoint_hash);
3585
+ inTokenAmount += BigInt(utxo.token_amount);
3586
+ if (!usedAddresses.includes(item.address)) usedAddresses.push(item.address);
3587
+ // Check if we have enough tokens to melt
3588
+ if (inTokenAmount >= amount) {
3589
+ // Create change output if melting less than full amount
3590
+ if (inTokenAmount > amount) txBuilder.to(item.address, (0, $l50U0$libnexats.Transaction).DUST_AMOUNT, token, inTokenAmount - amount);
3591
+ return usedAddresses;
3592
+ }
3593
+ }
3594
+ }
3595
+ throw new Error(`Not enough token balance to melt. Required: ${amount}, Available: ${inTokenAmount}`);
3596
+ }
3320
3597
  async function $52632971edbdb934$export$5c44e04d8c04c292(txBuilder, addresses, token, perms, toAddr, spentOutpoints) {
3321
3598
  let usedAddresses = [];
3322
3599
  let reqiredPerms = new Set(perms);
@@ -3390,10 +3667,11 @@ class $2ce5b75d10954bb1$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$exp
3390
3667
  * @param token Token ID to mint
3391
3668
  * @param amount Amount to mint
3392
3669
  * @param toAddr Destination address for minted tokens
3670
+ * @param parent Optional parent token ID (for NFT/SFT minting)
3393
3671
  * @returns This instance for chaining
3394
- */ mint(token, amount, toAddr) {
3672
+ */ mint(token, amount, toAddr, parent) {
3395
3673
  this.builder.push(async ()=>{
3396
- this.tokenAction(toAddr, amount, token, 'mint');
3674
+ this.tokenAction(toAddr, amount, token, 'mint', parent);
3397
3675
  });
3398
3676
  return this;
3399
3677
  }
@@ -3402,10 +3680,11 @@ class $2ce5b75d10954bb1$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$exp
3402
3680
  * @param token Token ID to melt
3403
3681
  * @param amount Amount to melt
3404
3682
  * @param toAddr Destination address for melted tokens
3683
+ * @param parent Optional parent token ID (for NFT/SFT melting)
3405
3684
  * @returns This instance for chaining
3406
- */ melt(token, amount, toAddr) {
3685
+ */ melt(token, amount, toAddr, parent) {
3407
3686
  this.builder.push(async ()=>{
3408
- this.tokenAction(toAddr, amount, token, 'melt');
3687
+ this.tokenAction(toAddr, amount, token, 'melt', parent);
3409
3688
  });
3410
3689
  return this;
3411
3690
  }
@@ -3420,12 +3699,14 @@ class $2ce5b75d10954bb1$export$2e2bcd8739ae039 extends (0, $57b0117fe8233fef$exp
3420
3699
  let nexaAddresses = [];
3421
3700
  // Process token operations if any are configured
3422
3701
  if (this.tokens.size > 0) for (const tokenAction of this.tokens){
3423
- if (tokenAction.action == 'mint' || tokenAction.action == 'melt') // Handle token minting/melting - requires authority
3424
- tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$d7c9c386067a6463)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.action, undefined, undefined, this.spentOutpoints));
3702
+ if (tokenAction.action == 'mint') // Use specialized mint function for groups and subgroups
3703
+ tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$91f9f23df90683cc)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.amount, tokenAction.parentToken, this.spentOutpoints));
3704
+ else if (tokenAction.action == 'melt') // Use specialized melt function for groups and subgroups
3705
+ tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$cfda880a425a2203)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.amount, tokenAction.parentToken, this.spentOutpoints));
3425
3706
  else if (tokenAction.action == 'group') // Handle group token creation
3426
3707
  tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$74e83de914f372c5)(this.transactionBuilder, this._availableAddresses, tokenAction.extraData?.opReturnData, this.network, this.spentOutpoints));
3427
3708
  else if (tokenAction.action == 'subgroup') // Handle subgroup token creation
3428
- tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$d7c9c386067a6463)(this.transactionBuilder, this._availableAddresses, tokenAction.parentToken, tokenAction.action, tokenAction.token, tokenAction.extraData?.quantity, this.spentOutpoints));
3709
+ tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$d7c9c386067a6463)(this.transactionBuilder, this._availableAddresses, tokenAction.parentToken, tokenAction.action, tokenAction.token, this._availableAddresses[0]?.address, tokenAction.extraData?.quantity, this.spentOutpoints));
3429
3710
  else if (tokenAction.action == 'renew') // Handle authority renewal
3430
3711
  tokenAddresses = tokenAddresses.concat(await (0, $52632971edbdb934$export$5c44e04d8c04c292)(this.transactionBuilder, this._availableAddresses, tokenAction.token, tokenAction.extraData.perms, tokenAction.extraData?.address, this.spentOutpoints));
3431
3712
  else if (tokenAction.action == 'delete') // Handle authority deletion