@chainvue/verus-sdk 0.15.0 → 0.16.0

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.
Files changed (51) hide show
  1. package/README.md +9 -0
  2. package/dist/assemble/assembler.d.ts +2 -8
  3. package/dist/assemble/assembler.d.ts.map +1 -1
  4. package/dist/assemble/assembler.js +30 -20
  5. package/dist/assemble/assembler.js.map +1 -1
  6. package/dist/assemble/fundedIdentityUpdate.d.ts +0 -3
  7. package/dist/assemble/fundedIdentityUpdate.d.ts.map +1 -1
  8. package/dist/assemble/fundedIdentityUpdate.js +22 -14
  9. package/dist/assemble/fundedIdentityUpdate.js.map +1 -1
  10. package/dist/bundle.js +173 -159
  11. package/dist/constants/index.d.ts +8 -2
  12. package/dist/constants/index.d.ts.map +1 -1
  13. package/dist/constants/index.js +9 -3
  14. package/dist/constants/index.js.map +1 -1
  15. package/dist/currency/index.d.ts.map +1 -1
  16. package/dist/currency/index.js +0 -3
  17. package/dist/currency/index.js.map +1 -1
  18. package/dist/currency/launch.d.ts.map +1 -1
  19. package/dist/currency/launch.js +0 -2
  20. package/dist/currency/launch.js.map +1 -1
  21. package/dist/fee/index.d.ts +116 -0
  22. package/dist/fee/index.d.ts.map +1 -0
  23. package/dist/fee/index.js +228 -0
  24. package/dist/fee/index.js.map +1 -0
  25. package/dist/identity/index.d.ts.map +1 -1
  26. package/dist/identity/index.js +2 -16
  27. package/dist/identity/index.js.map +1 -1
  28. package/dist/identity/multisig.d.ts.map +1 -1
  29. package/dist/identity/multisig.js +23 -18
  30. package/dist/identity/multisig.js.map +1 -1
  31. package/dist/index.d.ts +3 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +41 -33
  34. package/dist/index.js.map +1 -1
  35. package/dist/offers/identity.d.ts.map +1 -1
  36. package/dist/offers/identity.js +40 -32
  37. package/dist/offers/identity.js.map +1 -1
  38. package/dist/offers/reclaim.d.ts.map +1 -1
  39. package/dist/offers/reclaim.js +29 -21
  40. package/dist/offers/reclaim.js.map +1 -1
  41. package/dist/offers/taker.d.ts.map +1 -1
  42. package/dist/offers/taker.js +22 -17
  43. package/dist/offers/taker.js.map +1 -1
  44. package/dist/transfer/index.d.ts.map +1 -1
  45. package/dist/transfer/index.js +0 -2
  46. package/dist/transfer/index.js.map +1 -1
  47. package/dist/utxo/index.d.ts +11 -8
  48. package/dist/utxo/index.d.ts.map +1 -1
  49. package/dist/utxo/index.js +20 -37
  50. package/dist/utxo/index.js.map +1 -1
  51. package/package.json +1 -1
package/dist/bundle.js CHANGED
@@ -9592,7 +9592,7 @@ var require_Identity = __commonJS({
9592
9592
  exports2.IDENTITY_MAX_UNLOCK_DELAY = new bn_js_1.BN(60).mul(new bn_js_1.BN(24)).mul(new bn_js_1.BN(22)).mul(new bn_js_1.BN(365));
9593
9593
  exports2.IDENTITY_MAX_NAME_LEN = new bn_js_1.BN(64);
9594
9594
  var { BufferReader, BufferWriter } = bufferutils_1.default;
9595
- var Identity7 = class _Identity extends Principal_1.Principal {
9595
+ var Identity8 = class _Identity extends Principal_1.Principal {
9596
9596
  constructor(data) {
9597
9597
  super(data);
9598
9598
  if (data === null || data === void 0 ? void 0 : data.version)
@@ -9959,14 +9959,14 @@ var require_Identity = __commonJS({
9959
9959
  return _Identity.internalFromJson(json, _Identity);
9960
9960
  }
9961
9961
  };
9962
- exports2.Identity = Identity7;
9963
- Identity7.VERSION_INVALID = new bn_js_1.BN(0);
9964
- Identity7.VERSION_VERUSID = new bn_js_1.BN(1);
9965
- Identity7.VERSION_VAULT = new bn_js_1.BN(2);
9966
- Identity7.VERSION_PBAAS = new bn_js_1.BN(3);
9967
- Identity7.VERSION_CURRENT = Identity7.VERSION_PBAAS;
9968
- Identity7.VERSION_FIRSTVALID = new bn_js_1.BN(1);
9969
- Identity7.VERSION_LASTVALID = new bn_js_1.BN(3);
9962
+ exports2.Identity = Identity8;
9963
+ Identity8.VERSION_INVALID = new bn_js_1.BN(0);
9964
+ Identity8.VERSION_VERUSID = new bn_js_1.BN(1);
9965
+ Identity8.VERSION_VAULT = new bn_js_1.BN(2);
9966
+ Identity8.VERSION_PBAAS = new bn_js_1.BN(3);
9967
+ Identity8.VERSION_CURRENT = Identity8.VERSION_PBAAS;
9968
+ Identity8.VERSION_FIRSTVALID = new bn_js_1.BN(1);
9969
+ Identity8.VERSION_LASTVALID = new bn_js_1.BN(3);
9970
9970
  }
9971
9971
  });
9972
9972
 
@@ -11091,7 +11091,7 @@ var require_IdentityScript = __commonJS({
11091
11091
  var IdentityID_1 = require_IdentityID();
11092
11092
  var cccustom_1 = require_cccustom();
11093
11093
  var KeyID_1 = require_KeyID();
11094
- var IdentityScript3 = class _IdentityScript extends SmartTransactionScript_1.SmartTransactionScript {
11094
+ var IdentityScript4 = class _IdentityScript extends SmartTransactionScript_1.SmartTransactionScript {
11095
11095
  constructor(master, params) {
11096
11096
  super(master, params);
11097
11097
  }
@@ -11171,7 +11171,7 @@ var require_IdentityScript = __commonJS({
11171
11171
  return identity;
11172
11172
  }
11173
11173
  };
11174
- exports2.IdentityScript = IdentityScript3;
11174
+ exports2.IdentityScript = IdentityScript4;
11175
11175
  }
11176
11176
  });
11177
11177
 
@@ -20877,7 +20877,7 @@ var require_optccparams = __commonJS({
20877
20877
  "node_modules/.pnpm/@bitgo+utxo-lib@https+++codeload.github.com+VerusCoin+BitGoJS+tar.gz+9701df63b479984f27_7b6d2dd0c6d9d9555ac626a4a148d56a/node_modules/@bitgo/utxo-lib/dist/src/optccparams.js"(exports2, module2) {
20878
20878
  "use strict";
20879
20879
  var bscript = require_script2();
20880
- var EVALS2 = require_evals2();
20880
+ var EVALS3 = require_evals2();
20881
20881
  var varuint = require_varuint_bitcoin();
20882
20882
  var TxDestination3 = require_tx_destination();
20883
20883
  var bufferutils = require_bufferutils2();
@@ -20917,27 +20917,27 @@ var require_optccparams = __commonJS({
20917
20917
  }
20918
20918
  OptCCParams4.prototype.getParamObject = function() {
20919
20919
  switch (this.evalCode) {
20920
- case EVALS2.EVAL_NONE: {
20920
+ case EVALS3.EVAL_NONE: {
20921
20921
  return null;
20922
20922
  }
20923
- case EVALS2.EVAL_STAKEGUARD:
20924
- case EVALS2.EVAL_CURRENCY_DEFINITION:
20925
- case EVALS2.EVAL_NOTARY_EVIDENCE:
20926
- case EVALS2.EVAL_EARNEDNOTARIZATION:
20927
- case EVALS2.EVAL_ACCEPTEDNOTARIZATION:
20928
- case EVALS2.EVAL_FINALIZE_NOTARIZATION:
20929
- case EVALS2.EVAL_CURRENCYSTATE:
20930
- case EVALS2.EVAL_RESERVE_TRANSFER:
20931
- case EVALS2.EVAL_RESERVE_OUTPUT:
20932
- case EVALS2.EVAL_RESERVE_DEPOSIT:
20933
- case EVALS2.EVAL_CROSSCHAIN_EXPORT:
20934
- case EVALS2.EVAL_CROSSCHAIN_IMPORT:
20935
- case EVALS2.EVAL_IDENTITY_PRIMARY:
20936
- case EVALS2.EVAL_IDENTITY_COMMITMENT:
20937
- case EVALS2.EVAL_IDENTITY_RESERVATION:
20938
- case EVALS2.EVAL_FINALIZE_EXPORT:
20939
- case EVALS2.EVAL_FEE_POOL:
20940
- case EVALS2.EVAL_NOTARY_SIGNATURE: {
20923
+ case EVALS3.EVAL_STAKEGUARD:
20924
+ case EVALS3.EVAL_CURRENCY_DEFINITION:
20925
+ case EVALS3.EVAL_NOTARY_EVIDENCE:
20926
+ case EVALS3.EVAL_EARNEDNOTARIZATION:
20927
+ case EVALS3.EVAL_ACCEPTEDNOTARIZATION:
20928
+ case EVALS3.EVAL_FINALIZE_NOTARIZATION:
20929
+ case EVALS3.EVAL_CURRENCYSTATE:
20930
+ case EVALS3.EVAL_RESERVE_TRANSFER:
20931
+ case EVALS3.EVAL_RESERVE_OUTPUT:
20932
+ case EVALS3.EVAL_RESERVE_DEPOSIT:
20933
+ case EVALS3.EVAL_CROSSCHAIN_EXPORT:
20934
+ case EVALS3.EVAL_CROSSCHAIN_IMPORT:
20935
+ case EVALS3.EVAL_IDENTITY_PRIMARY:
20936
+ case EVALS3.EVAL_IDENTITY_COMMITMENT:
20937
+ case EVALS3.EVAL_IDENTITY_RESERVATION:
20938
+ case EVALS3.EVAL_FINALIZE_EXPORT:
20939
+ case EVALS3.EVAL_FEE_POOL:
20940
+ case EVALS3.EVAL_NOTARY_SIGNATURE: {
20941
20941
  if (this.vData.length) {
20942
20942
  return this.vData[0];
20943
20943
  } else {
@@ -20952,28 +20952,28 @@ var require_optccparams = __commonJS({
20952
20952
  OptCCParams4.prototype.isValid = function() {
20953
20953
  var validEval = false;
20954
20954
  switch (this.evalCode) {
20955
- case EVALS2.EVAL_NONE: {
20955
+ case EVALS3.EVAL_NONE: {
20956
20956
  validEval = true;
20957
20957
  break;
20958
20958
  }
20959
- case EVALS2.EVAL_STAKEGUARD:
20960
- case EVALS2.EVAL_CURRENCY_DEFINITION:
20961
- case EVALS2.EVAL_NOTARY_EVIDENCE:
20962
- case EVALS2.EVAL_EARNEDNOTARIZATION:
20963
- case EVALS2.EVAL_ACCEPTEDNOTARIZATION:
20964
- case EVALS2.EVAL_FINALIZE_NOTARIZATION:
20965
- case EVALS2.EVAL_CURRENCYSTATE:
20966
- case EVALS2.EVAL_RESERVE_TRANSFER:
20967
- case EVALS2.EVAL_RESERVE_OUTPUT:
20968
- case EVALS2.EVAL_RESERVE_DEPOSIT:
20969
- case EVALS2.EVAL_CROSSCHAIN_EXPORT:
20970
- case EVALS2.EVAL_CROSSCHAIN_IMPORT:
20971
- case EVALS2.EVAL_IDENTITY_PRIMARY:
20972
- case EVALS2.EVAL_IDENTITY_COMMITMENT:
20973
- case EVALS2.EVAL_IDENTITY_RESERVATION:
20974
- case EVALS2.EVAL_FINALIZE_EXPORT:
20975
- case EVALS2.EVAL_FEE_POOL:
20976
- case EVALS2.EVAL_NOTARY_SIGNATURE: {
20959
+ case EVALS3.EVAL_STAKEGUARD:
20960
+ case EVALS3.EVAL_CURRENCY_DEFINITION:
20961
+ case EVALS3.EVAL_NOTARY_EVIDENCE:
20962
+ case EVALS3.EVAL_EARNEDNOTARIZATION:
20963
+ case EVALS3.EVAL_ACCEPTEDNOTARIZATION:
20964
+ case EVALS3.EVAL_FINALIZE_NOTARIZATION:
20965
+ case EVALS3.EVAL_CURRENCYSTATE:
20966
+ case EVALS3.EVAL_RESERVE_TRANSFER:
20967
+ case EVALS3.EVAL_RESERVE_OUTPUT:
20968
+ case EVALS3.EVAL_RESERVE_DEPOSIT:
20969
+ case EVALS3.EVAL_CROSSCHAIN_EXPORT:
20970
+ case EVALS3.EVAL_CROSSCHAIN_IMPORT:
20971
+ case EVALS3.EVAL_IDENTITY_PRIMARY:
20972
+ case EVALS3.EVAL_IDENTITY_COMMITMENT:
20973
+ case EVALS3.EVAL_IDENTITY_RESERVATION:
20974
+ case EVALS3.EVAL_FINALIZE_EXPORT:
20975
+ case EVALS3.EVAL_FEE_POOL:
20976
+ case EVALS3.EVAL_NOTARY_SIGNATURE: {
20977
20977
  validEval = this.vData && this.vData.length > 0;
20978
20978
  }
20979
20979
  }
@@ -32216,9 +32216,9 @@ __export(src_exports, {
32216
32216
  CURRENCY_OPTION: () => CURRENCY_OPTION,
32217
32217
  CURRENCY_TYPE_ORDER: () => CURRENCY_TYPE_ORDER,
32218
32218
  DEFAULT_EXPIRY_DELTA: () => DEFAULT_EXPIRY_DELTA,
32219
- DEFAULT_FEE_PER_KB: () => DEFAULT_FEE_PER_KB,
32220
32219
  DEFAULT_REFERRAL_LEVELS: () => DEFAULT_REFERRAL_LEVELS,
32221
32220
  DEFAULT_REGISTRATION_FEE: () => DEFAULT_REGISTRATION_FEE,
32221
+ DEFAULT_TRANSACTION_FEE: () => DEFAULT_TRANSACTION_FEE,
32222
32222
  DUST_THRESHOLD: () => DUST_THRESHOLD,
32223
32223
  HASH_SHA256: () => HASH_SHA256,
32224
32224
  IDENTITY_FLAG_ACTIVECURRENCY: () => IDENTITY_FLAG_ACTIVECURRENCY,
@@ -32230,6 +32230,7 @@ __export(src_exports, {
32230
32230
  InvalidNameError: () => InvalidNameError,
32231
32231
  InvalidSeedError: () => InvalidSeedError,
32232
32232
  InvalidWifError: () => InvalidWifError,
32233
+ LARGE_SCRIPT_FEE_THRESHOLD: () => LARGE_SCRIPT_FEE_THRESHOLD,
32233
32234
  NETWORK_CONFIG: () => NETWORK_CONFIG,
32234
32235
  NOTARIZATION_PROTOCOL: () => NOTARIZATION_PROTOCOL,
32235
32236
  PROOF_PROTOCOL: () => PROOF_PROTOCOL,
@@ -32244,12 +32245,16 @@ __export(src_exports, {
32244
32245
  VerusSDK: () => VerusSDK,
32245
32246
  WIF_PREFIX: () => WIF_PREFIX,
32246
32247
  address: () => address_exports,
32248
+ assertFeeMeetsRelayMinimum: () => assertFeeMeetsRelayMinimum,
32247
32249
  buildCurrencyDefinitionScript: () => buildCurrencyDefinitionScript,
32248
32250
  buildCurrencyLaunchOutputs: () => buildCurrencyLaunchOutputs,
32249
32251
  buildCurrencyLaunchTransaction: () => buildCurrencyLaunchTransaction,
32250
32252
  buildReserveTransferOutput: () => buildReserveTransferOutput,
32251
32253
  classifyCurrency: () => classifyCurrency,
32254
+ computeIdentityFeeFactor: () => computeIdentityFeeFactor,
32252
32255
  currency: () => currency_exports,
32256
+ estimateMinerFee: () => estimateMinerFee,
32257
+ fee: () => fee_exports,
32253
32258
  identity: () => public_exports2,
32254
32259
  identityMultisig: () => multisig_exports,
32255
32260
  isIAddress: () => isIAddress2,
@@ -32260,6 +32265,7 @@ __export(src_exports, {
32260
32265
  message: () => message_exports,
32261
32266
  offers: () => public_exports,
32262
32267
  parseSats: () => parseSats,
32268
+ relayMinimumFee: () => relayMinimumFee,
32263
32269
  serializeCurrencyDefinition: () => serializeCurrencyDefinition,
32264
32270
  signing: () => signing_exports,
32265
32271
  toCoins: () => toCoins,
@@ -32321,7 +32327,7 @@ var NETWORK_CONFIG = {
32321
32327
  var CONSENSUS_BRANCH_ID = 1991772603;
32322
32328
  var VERSION_GROUP_ID = 2301567109;
32323
32329
  var TX_VERSION = 4;
32324
- var DEFAULT_FEE_PER_KB = 10000n;
32330
+ var DEFAULT_TRANSACTION_FEE = 10000n;
32325
32331
  var DUST_THRESHOLD = 546n;
32326
32332
  var DEFAULT_REGISTRATION_FEE = 10000000000n;
32327
32333
  var DEFAULT_REFERRAL_LEVELS = 3;
@@ -32667,16 +32673,10 @@ var utxo_exports = {};
32667
32673
  __export(utxo_exports, {
32668
32674
  assertTokenConservation: () => assertTokenConservation,
32669
32675
  decodeUtxo: () => decodeUtxo,
32670
- estimateFee: () => estimateFee,
32671
32676
  isSmartTransactionScript: () => isSmartTransactionScript,
32672
32677
  selectUtxos: () => selectUtxos
32673
32678
  });
32674
32679
  var { unpackOutput } = import_utxo_lib.smarttxs;
32675
- var INPUT_SIZE = 180;
32676
- var P2PKH_OUTPUT_SIZE = 34;
32677
- var SMART_OUTPUT_SIZE = 200;
32678
- var TX_OVERHEAD = 60;
32679
- var MIN_FEE = 10000n;
32680
32680
  function isSmartTransactionScript(script2) {
32681
32681
  try {
32682
32682
  const chunks = import_utxo_lib.script.decompile(script2);
@@ -32735,13 +32735,12 @@ function assertTokenConservation(selected, spentToOutputs, currencyChanges, syst
32735
32735
  }
32736
32736
  }
32737
32737
  }
32738
- function estimateFee(numInputs, numOutputs, feePerKb = DEFAULT_FEE_PER_KB, hasSmartOutputs = false, extraBytes = 0) {
32739
- const outputSize = hasSmartOutputs ? SMART_OUTPUT_SIZE : P2PKH_OUTPUT_SIZE;
32740
- const txSize = TX_OVERHEAD + numInputs * INPUT_SIZE + numOutputs * outputSize + extraBytes;
32741
- const fee = (BigInt(txSize) * feePerKb + 999n) / 1000n;
32742
- return fee > MIN_FEE ? fee : MIN_FEE;
32743
- }
32744
- function selectUtxos(utxos, requiredNative, requiredCurrencies = /* @__PURE__ */ new Map(), numOutputs = 2, systemId = NETWORK_CONFIG.mainnet.chainId, feePerKb = DEFAULT_FEE_PER_KB, hasSmartOutputs = false, extraOutputBytes = 0) {
32738
+ function selectUtxos(utxos, requiredNative, requiredCurrencies, fee, systemId = NETWORK_CONFIG.mainnet.chainId) {
32739
+ if (typeof fee !== "bigint" || fee < DEFAULT_TRANSACTION_FEE) {
32740
+ throw new TransactionBuildError(
32741
+ `selectUtxos: fee must be a bigint of at least ${DEFAULT_TRANSACTION_FEE} satoshis (compute it with estimateMinerFee), got ${String(fee)}`
32742
+ );
32743
+ }
32745
32744
  const seenOutpoints = /* @__PURE__ */ new Set();
32746
32745
  for (const u of utxos) {
32747
32746
  const outpoint = `${u.txid}:${u.outputIndex}`;
@@ -32807,21 +32806,6 @@ function selectUtxos(utxos, requiredNative, requiredCurrencies = /* @__PURE__ */
32807
32806
  if (at !== bt) return at - bt;
32808
32807
  return b.satoshis > a.satoshis ? 1 : b.satoshis < a.satoshis ? -1 : 0;
32809
32808
  });
32810
- const countCurrencyChanges = () => {
32811
- let n = 0;
32812
- for (const [currency, needed] of remaining) {
32813
- if (currency !== systemId && needed < 0n) n++;
32814
- }
32815
- return n;
32816
- };
32817
- let changeOutputCount = countCurrencyChanges();
32818
- let fee = estimateFee(
32819
- selected.length + 1,
32820
- numOutputs + 1 + changeOutputCount,
32821
- feePerKb,
32822
- hasSmartOutputs,
32823
- extraOutputBytes
32824
- );
32825
32809
  while (remainingNative + fee > 0n) {
32826
32810
  const next = nativeOnly.shift();
32827
32811
  if (!next) {
@@ -32838,14 +32822,6 @@ function selectUtxos(utxos, requiredNative, requiredCurrencies = /* @__PURE__ */
32838
32822
  if (currency === systemId || amount <= 0n) continue;
32839
32823
  remaining.set(currency, (remaining.get(currency) || 0n) - amount);
32840
32824
  }
32841
- changeOutputCount = countCurrencyChanges();
32842
- fee = estimateFee(
32843
- selected.length,
32844
- numOutputs + 1 + changeOutputCount,
32845
- feePerKb,
32846
- hasSmartOutputs,
32847
- extraOutputBytes
32848
- );
32849
32825
  }
32850
32826
  const totalNativeIn = selected.reduce((sum, u) => sum + u.satoshis, 0n);
32851
32827
  const actualNativeChange = totalNativeIn - requiredNative - fee;
@@ -32865,6 +32841,78 @@ function selectUtxos(utxos, requiredNative, requiredCurrencies = /* @__PURE__ */
32865
32841
  };
32866
32842
  }
32867
32843
 
32844
+ // src/fee/index.ts
32845
+ var fee_exports = {};
32846
+ __export(fee_exports, {
32847
+ LARGE_SCRIPT_FEE_THRESHOLD: () => LARGE_SCRIPT_FEE_THRESHOLD,
32848
+ assertFeeMeetsRelayMinimum: () => assertFeeMeetsRelayMinimum,
32849
+ computeIdentityFeeFactor: () => computeIdentityFeeFactor,
32850
+ estimateMinerFee: () => estimateMinerFee,
32851
+ relayMinimumFee: () => relayMinimumFee
32852
+ });
32853
+ var LARGE_SCRIPT_FEE_THRESHOLD = 2e3;
32854
+ var ID_EXTRA_LIMIT = 0;
32855
+ function largeScriptSurcharge(scriptLength) {
32856
+ if (scriptLength > 2 * LARGE_SCRIPT_FEE_THRESHOLD) return 2n * DEFAULT_TRANSACTION_FEE;
32857
+ if (scriptLength > LARGE_SCRIPT_FEE_THRESHOLD) return DEFAULT_TRANSACTION_FEE;
32858
+ return 0n;
32859
+ }
32860
+ function parseIdentityOutput(script2) {
32861
+ try {
32862
+ const parsed = new boundary_exports.IdentityScript();
32863
+ parsed.fromBuffer(script2);
32864
+ if (parsed.paramsOptCC.eval_code.toNumber() !== boundary_exports.EVALS.EVAL_IDENTITY_PRIMARY) return null;
32865
+ return parsed.getIdentity();
32866
+ } catch {
32867
+ return null;
32868
+ }
32869
+ }
32870
+ function computeIdentityFeeFactor(outputScripts) {
32871
+ let factor = 0;
32872
+ for (const script2 of outputScripts) {
32873
+ const identity = parseIdentityOutput(script2);
32874
+ if (identity === null) continue;
32875
+ factor += identity.content_map?.size ?? 0;
32876
+ factor += Math.max((identity.primary_addresses?.length ?? 0) - 1, 0);
32877
+ factor += Math.max((identity.private_addresses?.length ?? 0) - 1, 0);
32878
+ if ((identity.content_multimap?.kv_content?.size ?? 0) > 0) {
32879
+ const withContent = identity.getByteLength();
32880
+ identity.clearContentMultiMap();
32881
+ const serSize = withContent - identity.getByteLength();
32882
+ factor += Math.ceil(serSize / 128);
32883
+ }
32884
+ }
32885
+ return factor;
32886
+ }
32887
+ function estimateMinerFee(outputScripts) {
32888
+ const factor = BigInt(computeIdentityFeeFactor(outputScripts));
32889
+ const count = outputScripts.length;
32890
+ let fee = factor > 0n ? factor * DEFAULT_TRANSACTION_FEE : DEFAULT_TRANSACTION_FEE;
32891
+ fee += BigInt(Math.max(count - (1 + ID_EXTRA_LIMIT), 0)) * DEFAULT_TRANSACTION_FEE;
32892
+ if (!(factor > 0n && count <= 1 + ID_EXTRA_LIMIT)) {
32893
+ for (const script2 of outputScripts) fee += largeScriptSurcharge(script2.length);
32894
+ }
32895
+ return fee;
32896
+ }
32897
+ function relayMinimumFee(outputScripts) {
32898
+ const factor = BigInt(computeIdentityFeeFactor(outputScripts));
32899
+ const count = outputScripts.length;
32900
+ let fee = factor > 0n ? factor * DEFAULT_TRANSACTION_FEE : DEFAULT_TRANSACTION_FEE;
32901
+ fee += BigInt(Math.max(count - (3 + ID_EXTRA_LIMIT), 0)) * DEFAULT_TRANSACTION_FEE;
32902
+ if (!(factor > 0n && count <= 3 + ID_EXTRA_LIMIT)) {
32903
+ for (const script2 of outputScripts) fee += largeScriptSurcharge(script2.length);
32904
+ }
32905
+ return fee;
32906
+ }
32907
+ function assertFeeMeetsRelayMinimum(fee, outputScripts, label) {
32908
+ const minimum = relayMinimumFee(outputScripts);
32909
+ if (fee < minimum) {
32910
+ throw new TransactionBuildError(
32911
+ `${label}: miner fee ${fee} is below the daemon's relay minimum ${minimum} for this transaction's ${outputScripts.length} output(s); it would not reliably relay.`
32912
+ );
32913
+ }
32914
+ }
32915
+
32868
32916
  // src/identity/index.ts
32869
32917
  var import_crypto2 = require("crypto");
32870
32918
  var import_bn = __toESM(require("bn.js"));
@@ -32924,16 +32972,8 @@ function assembleFundedIdentityUpdate(intent) {
32924
32972
  const verusNetwork = getNetwork(intent.network === "testnet");
32925
32973
  const systemId = NETWORK_CONFIG[intent.network].chainId;
32926
32974
  const requiredNative = intent.outputs.reduce((sum, o) => sum + o.nativeSat, 0n);
32927
- const selection = selectUtxos(
32928
- intent.funding,
32929
- requiredNative,
32930
- /* @__PURE__ */ new Map(),
32931
- intent.outputs.length,
32932
- systemId,
32933
- void 0,
32934
- true,
32935
- intent.extraOutputBytes
32936
- );
32975
+ const minerFee = estimateMinerFee(intent.outputs.map((o) => o.script));
32976
+ const selection = selectUtxos(intent.funding, requiredNative, /* @__PURE__ */ new Map(), minerFee, systemId);
32937
32977
  assertTokenConservation(selection.selected, /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), systemId, intent.label);
32938
32978
  const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
32939
32979
  txb.setVersion(4);
@@ -32990,12 +33030,9 @@ function assembleFundedIdentityUpdate(intent) {
32990
33030
  }
32991
33031
  );
32992
33032
  const allUtxos = [...selection.selected, idUtxo];
32993
- assertNativeConservation(
32994
- allUtxos,
32995
- import_utxo_lib.Transaction.fromHex(completedHex, verusNetwork).outs,
32996
- selection.fee,
32997
- intent.label
32998
- );
33033
+ const completedOuts = import_utxo_lib.Transaction.fromHex(completedHex, verusNetwork).outs;
33034
+ assertNativeConservation(allUtxos, completedOuts, selection.fee, intent.label);
33035
+ assertFeeMeetsRelayMinimum(selection.fee, completedOuts.map((o) => o.script), intent.label);
32999
33036
  const { signedTx, txid } = signTransactionSmart(completedHex, intent.wif, allUtxos, verusNetwork);
33000
33037
  return {
33001
33038
  signedTx,
@@ -33610,9 +33647,6 @@ function _buildVrscRegistration(params, identityScript, reservationScript, ident
33610
33647
  { script: reservationScript, nativeSat: 0n }
33611
33648
  ],
33612
33649
  changeAddress: params.changeAddress,
33613
- // Legacy fee estimate: identity + referrals + reservation, plus the one extra
33614
- // change slot the original path counted on top of selectUtxos' own reserve.
33615
- feeOutputCount: 2 + referralOutputs.length + 1,
33616
33650
  fee: {
33617
33651
  policy: "declared",
33618
33652
  burnSat: registrationOutlay - totalReferralPayments,
@@ -33676,10 +33710,6 @@ function _buildSubIdRegistration(params, identityScript, reservationScript, iden
33676
33710
  { script: reservationScript, nativeSat: 0n }
33677
33711
  ],
33678
33712
  changeAddress: params.changeAddress,
33679
- // Legacy fee estimate: identity + fee + reservation, plus the one extra change
33680
- // slot the original path counted on top of selectUtxos' own reserve.
33681
- feeOutputCount: 4,
33682
- extraOutputBytes: identityScript.length + reservationScript.length + feeOutput.script.length,
33683
33713
  fee: {
33684
33714
  policy: "declared",
33685
33715
  burnSat: nativeImportFee,
@@ -33854,10 +33884,6 @@ function buildAndSignIdentityUpdate(params, network, operation = "update", lockU
33854
33884
  identityUtxo: params.identityUtxo,
33855
33885
  outputs: unfundedTx.outs.map((o) => ({ script: o.script, nativeSat: BigInt(o.value) })),
33856
33886
  changeAddress: params.changeAddress,
33857
- // The identity output embeds the full serialized identity (a large
33858
- // contentMultimap can make it multi-KB); size the fee from the unfunded tx's
33859
- // real bytes so a big update isn't fee-estimated below the relay minimum.
33860
- extraOutputBytes: unfundedHex.length / 2,
33861
33887
  label: `identity ${operation}`
33862
33888
  });
33863
33889
  return {
@@ -33904,15 +33930,13 @@ function assembleAndSign(intent) {
33904
33930
  for (const [c, v] of o.carries) requiredCurrencies.set(c, (requiredCurrencies.get(c) ?? 0n) + v);
33905
33931
  }
33906
33932
  }
33933
+ const minerFee = estimateMinerFee(intent.outputs.map((o) => o.script));
33907
33934
  const selection = selectUtxos(
33908
33935
  intent.funding,
33909
33936
  requiredNative,
33910
33937
  requiredCurrencies,
33911
- intent.feeOutputCount ?? intent.outputs.length,
33912
- systemId,
33913
- void 0,
33914
- intent.hasSmartOutputs ?? true,
33915
- intent.extraOutputBytes ?? 0
33938
+ minerFee,
33939
+ systemId
33916
33940
  );
33917
33941
  const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
33918
33942
  txb.setVersion(4);
@@ -33958,6 +33982,7 @@ function assembleAndSign(intent) {
33958
33982
  const leadingNative = leading.reduce((sum, u) => sum + u.satoshis, 0n);
33959
33983
  const expectedFee = selection.fee + burnSat + leadingNative;
33960
33984
  assertNativeConservation(allUtxos, unsignedTx.outs, expectedFee, intent.label);
33985
+ assertFeeMeetsRelayMinimum(selection.fee, unsignedTx.outs.map((o) => o.script), intent.label);
33961
33986
  const maxFeeSats = intent.fee.policy === "declared" ? expectedFee : void 0;
33962
33987
  const { signedTx, txid } = signTransactionSmart(unsignedTx.toHex(), intent.wif, allUtxos, verusNetwork, maxFeeSats);
33963
33988
  return {
@@ -34095,9 +34120,6 @@ function sendCurrency(params, network) {
34095
34120
  expiryHeight
34096
34121
  );
34097
34122
  const unfundedTx = import_utxo_lib.Transaction.fromHex(unfundedTxHex, verusNetwork);
34098
- const hasSmartOutputs = params.outputs.some(
34099
- (o) => o.convertTo || o.exportTo || o.via || o.mintnew || o.burn || o.burnweight || o.currency !== systemId
34100
- );
34101
34123
  const requiredCurrencies = /* @__PURE__ */ new Map();
34102
34124
  for (const out of params.outputs) {
34103
34125
  if (out.currency !== systemId && !out.mintnew) {
@@ -34120,7 +34142,6 @@ function sendCurrency(params, network) {
34120
34142
  funding: params.utxos,
34121
34143
  outputs: unfundedTx.outs.map((o) => ({ script: o.script, nativeSat: BigInt(o.value) })),
34122
34144
  changeAddress: params.changeAddress,
34123
- hasSmartOutputs,
34124
34145
  requiredCurrencies,
34125
34146
  changeStrategy: "separate",
34126
34147
  fee: { policy: "estimate" },
@@ -35123,7 +35144,6 @@ function buildCurrencyLaunchTransaction(params, network) {
35123
35144
  script: Buffer.from(o.script, "hex"),
35124
35145
  nativeSat: o.value
35125
35146
  }));
35126
- const extraOutputBytes = consensusOutputs.reduce((sum, o) => sum + o.script.length, 0);
35127
35147
  const assembled = assembleFundedIdentityUpdate({
35128
35148
  network,
35129
35149
  wif: params.wif,
@@ -35135,7 +35155,6 @@ function buildCurrencyLaunchTransaction(params, network) {
35135
35155
  identityUtxo: params.identityUtxo,
35136
35156
  outputs: consensusOutputs,
35137
35157
  changeAddress: params.changeAddress ?? identityAddress,
35138
- extraOutputBytes,
35139
35158
  label: "currency launch"
35140
35159
  });
35141
35160
  return {
@@ -35242,9 +35261,6 @@ function defineCurrency(params, network) {
35242
35261
  { script: currencyDefScript, nativeSat: currencyDefValue }
35243
35262
  ],
35244
35263
  changeAddress: params.changeAddress,
35245
- // The identity + currency-definition outputs can be large; size the fee from
35246
- // their real byte length so the tx isn't estimated below the relay minimum.
35247
- extraOutputBytes: identityOutputScript.length + currencyDefScript.length,
35248
35264
  label: "currency definition"
35249
35265
  });
35250
35266
  return {
@@ -35436,16 +35452,8 @@ function completeOffer(params, network) {
35436
35452
  }
35437
35453
  const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
35438
35454
  const requiredNative = wantingNative ? params.want.amount : 0n;
35439
- const selection = selectUtxos(
35440
- params.takerUtxos,
35441
- requiredNative,
35442
- wantedTokenReq,
35443
- 3,
35444
- systemId,
35445
- void 0,
35446
- true,
35447
- 150
35448
- );
35455
+ const minerFee = estimateMinerFee(tx.outs.map((o) => o.script));
35456
+ const selection = selectUtxos(params.takerUtxos, requiredNative, wantedTokenReq, minerFee, systemId);
35449
35457
  const takerInputs = [];
35450
35458
  for (const u of selection.selected) {
35451
35459
  const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
@@ -35470,6 +35478,7 @@ function completeOffer(params, network) {
35470
35478
  const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
35471
35479
  const allInputsNative = commitmentNative + takerNativeIn;
35472
35480
  assertNativeConservation([{ satoshis: allInputsNative }], tx.outs, selection.fee, "takeOffer");
35481
+ assertFeeMeetsRelayMinimum(selection.fee, tx.outs.map((o) => o.script), "takeOffer");
35473
35482
  const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
35474
35483
  return { swapTx: signedTx, txid };
35475
35484
  }
@@ -35500,19 +35509,21 @@ function buildReclaimOffer(params, network) {
35500
35509
  commitmentScript
35501
35510
  );
35502
35511
  if (offeringNative) {
35503
- const fee = estimateFee(1, 1, DEFAULT_FEE_PER_KB, false, 100);
35512
+ const payScript = nativePaymentScript2(params.makerAddress);
35513
+ const fee = estimateMinerFee([payScript]);
35504
35514
  const outAmount = params.offered.amount - fee;
35505
35515
  if (outAmount <= DUST_THRESHOLD) {
35506
35516
  throw new TransactionBuildError(
35507
35517
  `buildReclaimOffer: reclaimed native value ${params.offered.amount} is too small to cover the fee ${fee} above dust`
35508
35518
  );
35509
35519
  }
35510
- txb.addOutput(nativePaymentScript2(params.makerAddress), toSafeNumber(outAmount));
35520
+ txb.addOutput(payScript, toSafeNumber(outAmount));
35511
35521
  const tx2 = import_utxo_lib.Transaction.fromHex(txb.buildIncomplete().toHex(), verusNetwork);
35512
35522
  const takerInputs2 = [
35513
35523
  { index: 0, prevOutScript: commitmentScript, value: params.commitment.value }
35514
35524
  ];
35515
35525
  assertNativeConservation([{ satoshis: params.commitment.value }], tx2.outs, fee, "reclaimOffer");
35526
+ assertFeeMeetsRelayMinimum(fee, tx2.outs.map((o) => o.script), "reclaimOffer");
35516
35527
  const { signedTx: signedTx2, txid: txid2 } = signTakerInputs(tx2.toHex(), takerInputs2, params.wif, network);
35517
35528
  return { reclaimTx: signedTx2, txid: txid2 };
35518
35529
  }
@@ -35531,7 +35542,8 @@ function buildReclaimOffer(params, network) {
35531
35542
  const takerInputs = [
35532
35543
  { index: 0, prevOutScript: commitmentScript, value: 0n }
35533
35544
  ];
35534
- const selection = selectUtxos(feeUtxos, 0n, /* @__PURE__ */ new Map(), 2, systemId, void 0, true, 200);
35545
+ const minerFee = estimateMinerFee([tokenOut.script]);
35546
+ const selection = selectUtxos(feeUtxos, 0n, /* @__PURE__ */ new Map(), minerFee, systemId);
35535
35547
  if (selection.currencyChanges.size > 0) {
35536
35548
  throw new TransactionBuildError(
35537
35549
  "buildReclaimOffer: feeUtxos must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost."
@@ -35554,6 +35566,7 @@ function buildReclaimOffer(params, network) {
35554
35566
  }
35555
35567
  const feeNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
35556
35568
  assertNativeConservation([{ satoshis: feeNativeIn }], tx.outs, selection.fee, "reclaimOffer");
35569
+ assertFeeMeetsRelayMinimum(selection.fee, tx.outs.map((o) => o.script), "reclaimOffer");
35557
35570
  const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
35558
35571
  return { reclaimTx: signedTx, txid };
35559
35572
  }
@@ -35577,7 +35590,8 @@ function assertExpiryHeight(expiryHeight) {
35577
35590
  function fundFeeAndSignIdentityTaker(args) {
35578
35591
  const systemId = NETWORK_CONFIG[args.network].chainId;
35579
35592
  const verusNetwork = getNetwork(args.network === "testnet");
35580
- const selection = selectUtxos(args.takerUtxos, 0n, /* @__PURE__ */ new Map(), 3, systemId, void 0, true, args.extraOutputBytes);
35593
+ const minerFee = estimateMinerFee(args.tx.outs.map((o) => o.script));
35594
+ const selection = selectUtxos(args.takerUtxos, 0n, /* @__PURE__ */ new Map(), minerFee, systemId);
35581
35595
  if (selection.currencyChanges.size > 0) {
35582
35596
  throw new TransactionBuildError(
35583
35597
  `${args.label}: the fee UTXOs must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost.`
@@ -35606,6 +35620,7 @@ function fundFeeAndSignIdentityTaker(args) {
35606
35620
  selection.fee,
35607
35621
  args.label
35608
35622
  );
35623
+ assertFeeMeetsRelayMinimum(selection.fee, args.tx.outs.map((o) => o.script), args.label);
35609
35624
  const { signedTx, txid } = signTakerInputs(args.tx.toHex(), takerInputs, args.wif, args.network);
35610
35625
  return { swapTx: signedTx, txid };
35611
35626
  }
@@ -35636,16 +35651,8 @@ function completeSellIdentityOffer(params, network) {
35636
35651
  tx.addOutput(buildTransferredIdentity(params.identityJson, params.newPrimaryAddresses), 0);
35637
35652
  const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
35638
35653
  const requiredNative = wantingNative ? params.want.amount : 0n;
35639
- const selection = selectUtxos(
35640
- params.takerUtxos,
35641
- requiredNative,
35642
- wantedTokenReq,
35643
- 3,
35644
- systemId,
35645
- void 0,
35646
- true,
35647
- 150
35648
- );
35654
+ const minerFee = estimateMinerFee(tx.outs.map((o) => o.script));
35655
+ const selection = selectUtxos(params.takerUtxos, requiredNative, wantedTokenReq, minerFee, systemId);
35649
35656
  const takerInputs = [];
35650
35657
  for (const u of selection.selected) {
35651
35658
  const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
@@ -35663,6 +35670,7 @@ function completeSellIdentityOffer(params, network) {
35663
35670
  assertTokenConservation(selection.selected, wantedTokenReq, selection.currencyChanges, systemId, "takeSellIdentityOffer");
35664
35671
  const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
35665
35672
  assertNativeConservation([{ satoshis: takerNativeIn }], tx.outs, selection.fee, "takeSellIdentityOffer");
35673
+ assertFeeMeetsRelayMinimum(selection.fee, tx.outs.map((o) => o.script), "takeSellIdentityOffer");
35666
35674
  const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
35667
35675
  return { swapTx: signedTx, txid };
35668
35676
  }
@@ -35731,8 +35739,7 @@ function completeBuyIdentityOffer(params, network) {
35731
35739
  changeAddress: params.changeAddress,
35732
35740
  wif: params.wif,
35733
35741
  network,
35734
- label: "takeBuyIdentityOffer",
35735
- extraOutputBytes: 300
35742
+ label: "takeBuyIdentityOffer"
35736
35743
  });
35737
35744
  }
35738
35745
  function buildSwapIdentityOffer(params, network) {
@@ -35782,8 +35789,7 @@ function completeSwapIdentityOffer(params, network) {
35782
35789
  changeAddress: params.changeAddress,
35783
35790
  wif: params.wif,
35784
35791
  network,
35785
- label: "takeSwapIdentityOffer",
35786
- extraOutputBytes: 500
35792
+ label: "takeSwapIdentityOffer"
35787
35793
  });
35788
35794
  }
35789
35795
 
@@ -35819,7 +35825,8 @@ function buildMultisigIdentityUpdate(params, network) {
35819
35825
  throw new TransactionBuildError("buildMultisigIdentityUpdate: funding must include native UTXOs for the fee");
35820
35826
  }
35821
35827
  const newIdScript = buildIdentityScript(boundary_exports.Identity.fromJson(params.newIdentity));
35822
- const selection = selectUtxos(params.funding, 0n, /* @__PURE__ */ new Map(), 2, systemId, void 0, true, newIdScript.length + 100);
35828
+ const minerFee = estimateMinerFee([newIdScript]);
35829
+ const selection = selectUtxos(params.funding, 0n, /* @__PURE__ */ new Map(), minerFee, systemId);
35823
35830
  if (selection.currencyChanges.size > 0) {
35824
35831
  throw new TransactionBuildError(
35825
35832
  "buildMultisigIdentityUpdate: funding must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost."
@@ -35857,6 +35864,7 @@ function buildMultisigIdentityUpdate(params, network) {
35857
35864
  const tx = import_utxo_lib.Transaction.fromHex(completedHex, verusNetwork);
35858
35865
  const funderNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
35859
35866
  assertNativeConservation([{ satoshis: funderNativeIn }], tx.outs, selection.fee, "multisigIdentityUpdate");
35867
+ assertFeeMeetsRelayMinimum(selection.fee, tx.outs.map((o) => o.script), "multisigIdentityUpdate");
35860
35868
  const funderKey = import_utxo_lib.ECPair.fromWIF(params.funderWif, verusNetwork);
35861
35869
  for (let i = 0; i < selection.selected.length; i++) {
35862
35870
  const u = selection.selected[i];
@@ -36225,9 +36233,9 @@ __export(public_exports2, {
36225
36233
  CURRENCY_OPTION,
36226
36234
  CURRENCY_TYPE_ORDER,
36227
36235
  DEFAULT_EXPIRY_DELTA,
36228
- DEFAULT_FEE_PER_KB,
36229
36236
  DEFAULT_REFERRAL_LEVELS,
36230
36237
  DEFAULT_REGISTRATION_FEE,
36238
+ DEFAULT_TRANSACTION_FEE,
36231
36239
  DUST_THRESHOLD,
36232
36240
  HASH_SHA256,
36233
36241
  IDENTITY_FLAG_ACTIVECURRENCY,
@@ -36239,6 +36247,7 @@ __export(public_exports2, {
36239
36247
  InvalidNameError,
36240
36248
  InvalidSeedError,
36241
36249
  InvalidWifError,
36250
+ LARGE_SCRIPT_FEE_THRESHOLD,
36242
36251
  NETWORK_CONFIG,
36243
36252
  NOTARIZATION_PROTOCOL,
36244
36253
  PROOF_PROTOCOL,
@@ -36253,12 +36262,16 @@ __export(public_exports2, {
36253
36262
  VerusSDK,
36254
36263
  WIF_PREFIX,
36255
36264
  address,
36265
+ assertFeeMeetsRelayMinimum,
36256
36266
  buildCurrencyDefinitionScript,
36257
36267
  buildCurrencyLaunchOutputs,
36258
36268
  buildCurrencyLaunchTransaction,
36259
36269
  buildReserveTransferOutput,
36260
36270
  classifyCurrency,
36271
+ computeIdentityFeeFactor,
36261
36272
  currency,
36273
+ estimateMinerFee,
36274
+ fee,
36262
36275
  identity,
36263
36276
  identityMultisig,
36264
36277
  isIAddress,
@@ -36269,6 +36282,7 @@ __export(public_exports2, {
36269
36282
  message,
36270
36283
  offers,
36271
36284
  parseSats,
36285
+ relayMinimumFee,
36272
36286
  serializeCurrencyDefinition,
36273
36287
  signing,
36274
36288
  toCoins,