@chainvue/verus-sdk 0.10.0 → 0.12.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 (47) hide show
  1. package/README.md +6 -0
  2. package/dist/VerusSDK.d.ts +34 -0
  3. package/dist/VerusSDK.d.ts.map +1 -1
  4. package/dist/VerusSDK.js +55 -0
  5. package/dist/VerusSDK.js.map +1 -1
  6. package/dist/bundle.js +645 -43
  7. package/dist/fork/boundary.d.ts +1 -1
  8. package/dist/fork/boundary.d.ts.map +1 -1
  9. package/dist/fork/boundary.js +6 -1
  10. package/dist/fork/boundary.js.map +1 -1
  11. package/dist/identity/index.d.ts +10 -0
  12. package/dist/identity/index.d.ts.map +1 -1
  13. package/dist/identity/index.js +31 -0
  14. package/dist/identity/index.js.map +1 -1
  15. package/dist/index.d.ts +2 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +3 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/offers/identity.d.ts +193 -0
  20. package/dist/offers/identity.d.ts.map +1 -0
  21. package/dist/offers/identity.js +317 -0
  22. package/dist/offers/identity.js.map +1 -0
  23. package/dist/offers/maker.d.ts +67 -0
  24. package/dist/offers/maker.d.ts.map +1 -0
  25. package/dist/offers/maker.js +132 -0
  26. package/dist/offers/maker.js.map +1 -0
  27. package/dist/offers/public.d.ts +32 -0
  28. package/dist/offers/public.d.ts.map +1 -0
  29. package/dist/offers/public.js +45 -0
  30. package/dist/offers/public.js.map +1 -0
  31. package/dist/offers/reclaim.d.ts +39 -0
  32. package/dist/offers/reclaim.d.ts.map +1 -0
  33. package/dist/offers/reclaim.js +112 -0
  34. package/dist/offers/reclaim.js.map +1 -0
  35. package/dist/offers/sign.d.ts +42 -0
  36. package/dist/offers/sign.d.ts.map +1 -0
  37. package/dist/offers/sign.js +98 -0
  38. package/dist/offers/sign.js.map +1 -0
  39. package/dist/offers/taker.d.ts +33 -0
  40. package/dist/offers/taker.d.ts.map +1 -0
  41. package/dist/offers/taker.js +113 -0
  42. package/dist/offers/taker.js.map +1 -0
  43. package/dist/utxo/index.d.ts +7 -0
  44. package/dist/utxo/index.d.ts.map +1 -1
  45. package/dist/utxo/index.js +1 -0
  46. package/dist/utxo/index.js.map +1 -1
  47. 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 Identity3 = class _Identity extends Principal_1.Principal {
9595
+ var Identity4 = 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 = Identity3;
9963
- Identity3.VERSION_INVALID = new bn_js_1.BN(0);
9964
- Identity3.VERSION_VERUSID = new bn_js_1.BN(1);
9965
- Identity3.VERSION_VAULT = new bn_js_1.BN(2);
9966
- Identity3.VERSION_PBAAS = new bn_js_1.BN(3);
9967
- Identity3.VERSION_CURRENT = Identity3.VERSION_PBAAS;
9968
- Identity3.VERSION_FIRSTVALID = new bn_js_1.BN(1);
9969
- Identity3.VERSION_LASTVALID = new bn_js_1.BN(3);
9962
+ exports2.Identity = Identity4;
9963
+ Identity4.VERSION_INVALID = new bn_js_1.BN(0);
9964
+ Identity4.VERSION_VERUSID = new bn_js_1.BN(1);
9965
+ Identity4.VERSION_VAULT = new bn_js_1.BN(2);
9966
+ Identity4.VERSION_PBAAS = new bn_js_1.BN(3);
9967
+ Identity4.VERSION_CURRENT = Identity4.VERSION_PBAAS;
9968
+ Identity4.VERSION_FIRSTVALID = new bn_js_1.BN(1);
9969
+ Identity4.VERSION_LASTVALID = new bn_js_1.BN(3);
9970
9970
  }
9971
9971
  });
9972
9972
 
@@ -20226,10 +20226,10 @@ var require_smart_transaction_signature = __commonJS({
20226
20226
  "use strict";
20227
20227
  var Buffer2 = require_safe_buffer().Buffer;
20228
20228
  var varuint = require_varuint_bitcoin();
20229
- var SmartTransactionSignature = (
20229
+ var SmartTransactionSignature2 = (
20230
20230
  /** @class */
20231
20231
  (function() {
20232
- function SmartTransactionSignature2(version, sigType, pubKeyData, oneSignature) {
20232
+ function SmartTransactionSignature3(version, sigType, pubKeyData, oneSignature) {
20233
20233
  if (version === void 0) {
20234
20234
  version = 1;
20235
20235
  }
@@ -20244,7 +20244,7 @@ var require_smart_transaction_signature = __commonJS({
20244
20244
  this.oneSignature = new Buffer2(0);
20245
20245
  }
20246
20246
  }
20247
- SmartTransactionSignature2.prototype.fromBuffer = function(buffer, initialOffset) {
20247
+ SmartTransactionSignature3.prototype.fromBuffer = function(buffer, initialOffset) {
20248
20248
  var offset = initialOffset || 0;
20249
20249
  function readSlice(n) {
20250
20250
  offset += n;
@@ -20268,10 +20268,10 @@ var require_smart_transaction_signature = __commonJS({
20268
20268
  this.oneSignature = readVarSlice();
20269
20269
  return offset;
20270
20270
  };
20271
- SmartTransactionSignature2.prototype.__byteLength = function() {
20271
+ SmartTransactionSignature3.prototype.__byteLength = function() {
20272
20272
  return 1 + varuint.encodingLength(this.pubKeyData.length) + this.pubKeyData.length + varuint.encodingLength(this.oneSignature.length) + this.oneSignature.length;
20273
20273
  };
20274
- SmartTransactionSignature2.prototype.toBuffer = function(buffer, initialOffset) {
20274
+ SmartTransactionSignature3.prototype.toBuffer = function(buffer, initialOffset) {
20275
20275
  var noBuffer = !buffer;
20276
20276
  if (noBuffer)
20277
20277
  buffer = Buffer2.allocUnsafe(this.__byteLength());
@@ -20297,10 +20297,10 @@ var require_smart_transaction_signature = __commonJS({
20297
20297
  return noBuffer ? buffer.slice(initialOffset, offset) : offset;
20298
20298
  return noBuffer ? buffer.slice(0, offset) : offset;
20299
20299
  };
20300
- return SmartTransactionSignature2;
20300
+ return SmartTransactionSignature3;
20301
20301
  })()
20302
20302
  );
20303
- module2.exports = SmartTransactionSignature;
20303
+ module2.exports = SmartTransactionSignature2;
20304
20304
  }
20305
20305
  });
20306
20306
 
@@ -20311,11 +20311,11 @@ var require_smart_transaction_signatures = __commonJS({
20311
20311
  var Buffer2 = require_safe_buffer().Buffer;
20312
20312
  var bscript = require_script2();
20313
20313
  var varuint = require_varuint_bitcoin();
20314
- var SmartTransactionSignature = require_smart_transaction_signature();
20315
- var SmartTransactionSignatures = (
20314
+ var SmartTransactionSignature2 = require_smart_transaction_signature();
20315
+ var SmartTransactionSignatures2 = (
20316
20316
  /** @class */
20317
20317
  (function() {
20318
- function SmartTransactionSignatures2(version, sigHashType, signatures) {
20318
+ function SmartTransactionSignatures3(version, sigHashType, signatures) {
20319
20319
  if (version === void 0) {
20320
20320
  version = 1;
20321
20321
  }
@@ -20327,19 +20327,19 @@ var require_smart_transaction_signatures = __commonJS({
20327
20327
  this.signatures = signatures || [];
20328
20328
  this.error = null;
20329
20329
  }
20330
- SmartTransactionSignatures2.prototype.isValid = function() {
20330
+ SmartTransactionSignatures3.prototype.isValid = function() {
20331
20331
  return this.version > 0 && this.version < 2 && bscript.isDefinedHashType(this.sigHashType) && this.signatures.length > 0;
20332
20332
  };
20333
- SmartTransactionSignatures2.prototype.__byteLength = function() {
20333
+ SmartTransactionSignatures3.prototype.__byteLength = function() {
20334
20334
  return this.signatures.reduce(function(a, x) {
20335
20335
  return a + x.__byteLength();
20336
20336
  }, 2 + varuint.encodingLength(this.signatures.length));
20337
20337
  };
20338
- SmartTransactionSignatures2.prototype.minLength = function() {
20339
- var checkSigs = new SmartTransactionSignatures2();
20338
+ SmartTransactionSignatures3.prototype.minLength = function() {
20339
+ var checkSigs = new SmartTransactionSignatures3();
20340
20340
  return checkSigs.__byteLength();
20341
20341
  };
20342
- SmartTransactionSignatures2.prototype.toBuffer = function(buffer, initialOffset) {
20342
+ SmartTransactionSignatures3.prototype.toBuffer = function(buffer, initialOffset) {
20343
20343
  var noBuffer = !buffer;
20344
20344
  if (noBuffer)
20345
20345
  buffer = Buffer2.allocUnsafe(this.__byteLength());
@@ -20361,15 +20361,15 @@ var require_smart_transaction_signatures = __commonJS({
20361
20361
  return noBuffer ? buffer.slice(initialOffset, offset) : offset;
20362
20362
  return noBuffer ? buffer.slice(0, offset) : offset;
20363
20363
  };
20364
- SmartTransactionSignatures2.fromChunk = function(chunk) {
20365
- var sigs = new SmartTransactionSignatures2();
20364
+ SmartTransactionSignatures3.fromChunk = function(chunk) {
20365
+ var sigs = new SmartTransactionSignatures3();
20366
20366
  sigs.fromBuffer(chunk);
20367
20367
  return sigs;
20368
20368
  };
20369
- SmartTransactionSignatures2.prototype.toChunk = function() {
20369
+ SmartTransactionSignatures3.prototype.toChunk = function() {
20370
20370
  return this.toBuffer();
20371
20371
  };
20372
- SmartTransactionSignatures2.prototype.fromBuffer = function(buffer, initialOffset) {
20372
+ SmartTransactionSignatures3.prototype.fromBuffer = function(buffer, initialOffset) {
20373
20373
  if (initialOffset === void 0) {
20374
20374
  initialOffset = 0;
20375
20375
  }
@@ -20385,7 +20385,7 @@ var require_smart_transaction_signatures = __commonJS({
20385
20385
  return vi;
20386
20386
  }
20387
20387
  function readOneSig() {
20388
- var oneSig = new SmartTransactionSignature();
20388
+ var oneSig = new SmartTransactionSignature2();
20389
20389
  offset = oneSig.fromBuffer(buffer, offset);
20390
20390
  return oneSig;
20391
20391
  }
@@ -20410,10 +20410,10 @@ var require_smart_transaction_signatures = __commonJS({
20410
20410
  }
20411
20411
  return offset;
20412
20412
  };
20413
- return SmartTransactionSignatures2;
20413
+ return SmartTransactionSignatures3;
20414
20414
  })()
20415
20415
  );
20416
- module2.exports = SmartTransactionSignatures;
20416
+ module2.exports = SmartTransactionSignatures2;
20417
20417
  }
20418
20418
  });
20419
20419
 
@@ -20424,7 +20424,7 @@ var require_input7 = __commonJS({
20424
20424
  var bscript = require_script2();
20425
20425
  var typeforce = require_typeforce();
20426
20426
  var OPS = require_bitcoin_ops();
20427
- var SmartTransactionSignatures = require_smart_transaction_signatures();
20427
+ var SmartTransactionSignatures2 = require_smart_transaction_signatures();
20428
20428
  function partialSignature(value) {
20429
20429
  return value === OPS.OP_0 || bscript.isCanonicalSignature(value);
20430
20430
  }
@@ -20432,13 +20432,13 @@ var require_input7 = __commonJS({
20432
20432
  var chunks = bscript.decompile(script2);
20433
20433
  if (chunks.length !== 1)
20434
20434
  return false;
20435
- return SmartTransactionSignatures.fromChunk(chunks[0]).isValid();
20435
+ return SmartTransactionSignatures2.fromChunk(chunks[0]).isValid();
20436
20436
  }
20437
20437
  check.toJSON = function() {
20438
20438
  return "smart transaction input";
20439
20439
  };
20440
20440
  function encodeStack(signature) {
20441
- var smartTxSigs = SmartTransactionSignatures.fromChunk(signature);
20441
+ var smartTxSigs = SmartTransactionSignatures2.fromChunk(signature);
20442
20442
  if (smartTxSigs.error == null)
20443
20443
  return [signature];
20444
20444
  else
@@ -30150,8 +30150,8 @@ var require_transaction_builder = __commonJS({
30150
30150
  var ECPair2 = require_ecpair();
30151
30151
  var ECSignature = require_ecsignature();
30152
30152
  var Transaction2 = require_transaction();
30153
- var SmartTransactionSignatures = require_smart_transaction_signatures();
30154
- var SmartTransactionSignature = require_smart_transaction_signature();
30153
+ var SmartTransactionSignatures2 = require_smart_transaction_signatures();
30154
+ var SmartTransactionSignature2 = require_smart_transaction_signature();
30155
30155
  var getMainnet = require_coins().getMainnet;
30156
30156
  var debug = require_src()("bitgo:utxolib:txbuilder");
30157
30157
  function supportedType(type) {
@@ -30594,7 +30594,7 @@ var require_transaction_builder = __commonJS({
30594
30594
  if (input.prevOutType === scriptTypes.SMART_TRANSACTION) {
30595
30595
  if (input.signatures === void 0 || input.signatures.length === 0)
30596
30596
  return true;
30597
- var smartTxSigs = SmartTransactionSignatures.fromChunk(bscript.decompile(input.signatures)[0]);
30597
+ var smartTxSigs = SmartTransactionSignatures2.fromChunk(bscript.decompile(input.signatures)[0]);
30598
30598
  if (smartTxSigs.error != null || smartTxSigs.signatures.length === 0 || smartTxSigs.signatures.every(function(sig) {
30599
30599
  return sig.oneSignature.length === 0;
30600
30600
  })) {
@@ -30822,8 +30822,8 @@ var require_transaction_builder = __commonJS({
30822
30822
  signature = ECSignature.fromRSBuffer(signature);
30823
30823
  debug("Produced signature (r: %s, s: %s)", signature.r, signature.s);
30824
30824
  if (input.signType === scriptTypes.SMART_TRANSACTION) {
30825
- input.signatures[i] = new SmartTransactionSignatures(1, 1, [
30826
- new SmartTransactionSignature(1, 1, pubKey, signature.toCompact().slice(1))
30825
+ input.signatures[i] = new SmartTransactionSignatures2(1, 1, [
30826
+ new SmartTransactionSignature2(1, 1, pubKey, signature.toCompact().slice(1))
30827
30827
  ]).toChunk();
30828
30828
  } else
30829
30829
  input.signatures[i] = signature.toScriptSignature(hashType);
@@ -30854,7 +30854,7 @@ var require_transaction_builder = __commonJS({
30854
30854
  if (input.signatures === void 0)
30855
30855
  return true;
30856
30856
  if (input.signType === scriptTypes.SMART_TRANSACTION) {
30857
- var smartTxSigs = SmartTransactionSignatures.fromChunk(bscript.decompile(input.signatures)[0]);
30857
+ var smartTxSigs = SmartTransactionSignatures2.fromChunk(bscript.decompile(input.signatures)[0]);
30858
30858
  if (smartTxSigs.error != null || smartTxSigs.signatures.length === 0 || smartTxSigs.signatures.every(function(sig) {
30859
30859
  return sig.oneSignature.length === 0;
30860
30860
  })) {
@@ -32242,13 +32242,14 @@ __export(src_exports, {
32242
32242
  address: () => address_exports,
32243
32243
  classifyCurrency: () => classifyCurrency,
32244
32244
  currency: () => currency_exports,
32245
- identity: () => public_exports,
32245
+ identity: () => public_exports2,
32246
32246
  isIAddress: () => isIAddress2,
32247
32247
  isIdentityName: () => isIdentityName,
32248
32248
  isRAddress: () => isRAddress2,
32249
32249
  isVerusAddress: () => isVerusAddress,
32250
32250
  keys: () => keys_exports,
32251
32251
  message: () => message_exports,
32252
+ offers: () => public_exports,
32252
32253
  parseSats: () => parseSats,
32253
32254
  signing: () => signing_exports,
32254
32255
  toCoins: () => toCoins,
@@ -32275,6 +32276,8 @@ var boundary_exports = {};
32275
32276
  __export(boundary_exports, {
32276
32277
  ECPair: () => import_utxo_lib.ECPair,
32277
32278
  IdentitySignature: () => import_utxo_lib.IdentitySignature,
32279
+ SmartTransactionSignature: () => import_utxo_lib.SmartTransactionSignature,
32280
+ SmartTransactionSignatures: () => import_utxo_lib.SmartTransactionSignatures,
32278
32281
  Transaction: () => import_utxo_lib.Transaction,
32279
32282
  TransactionBuilder: () => import_utxo_lib.TransactionBuilder,
32280
32283
  address: () => import_utxo_lib.address,
@@ -32649,6 +32652,7 @@ __export(utxo_exports, {
32649
32652
  assertTokenConservation: () => assertTokenConservation,
32650
32653
  decodeUtxo: () => decodeUtxo,
32651
32654
  estimateFee: () => estimateFee,
32655
+ isSmartTransactionScript: () => isSmartTransactionScript,
32652
32656
  selectUtxos: () => selectUtxos
32653
32657
  });
32654
32658
  var { unpackOutput } = import_utxo_lib.smarttxs;
@@ -33184,6 +33188,19 @@ function buildCommitmentScript(commitmentHashBuf, controlAddress) {
33184
33188
  const script2 = new boundary_exports.SmartTransactionScript(master, params);
33185
33189
  return script2.toBuffer();
33186
33190
  }
33191
+ var OFFER_TOKEN_COMMITMENT_MARKER = Buffer.concat([
33192
+ Buffer.from("2767181a4f6abe2090a7dca2c689477d163900f6", "hex"),
33193
+ Buffer.alloc(12, 0)
33194
+ ]);
33195
+ function buildTokenCommitmentScript(offeredCurrency, amountSat, controlAddress) {
33196
+ const values = new boundary_exports.CurrencyValueMap({
33197
+ value_map: /* @__PURE__ */ new Map([[offeredCurrency, new import_bn.default(amountSat.toString(10))]]),
33198
+ multivalue: false
33199
+ });
33200
+ const tokenOutput = new boundary_exports.TokenOutput({ version: new import_bn.default(1), values });
33201
+ const vdata = Buffer.concat([OFFER_TOKEN_COMMITMENT_MARKER, tokenOutput.toBuffer()]);
33202
+ return buildCommitmentScript(vdata, controlAddress);
33203
+ }
33187
33204
  function buildReservationScript(newIdentityIAddress, serializedReservation, isAdvanced = false) {
33188
33205
  const identityDest = new boundary_exports.TxDestination(boundary_exports.IdentityID.fromAddress(newIdentityIAddress));
33189
33206
  const evalCode = isAdvanced ? EVAL_IDENTITY_ADVANCEDRESERVATION : boundary_exports.EVALS.EVAL_IDENTITY_RESERVATION;
@@ -34347,6 +34364,536 @@ function defineCurrency(params, network) {
34347
34364
  };
34348
34365
  }
34349
34366
 
34367
+ // src/offers/public.ts
34368
+ var public_exports = {};
34369
+ __export(public_exports, {
34370
+ buildBuyIdentityOffer: () => buildBuyIdentityOffer,
34371
+ buildOffer: () => buildOffer,
34372
+ buildOfferFunding: () => buildOfferFunding,
34373
+ buildReclaimOffer: () => buildReclaimOffer,
34374
+ buildSellIdentityOffer: () => buildSellIdentityOffer,
34375
+ buildSwapIdentityOffer: () => buildSwapIdentityOffer,
34376
+ completeBuyIdentityOffer: () => completeBuyIdentityOffer,
34377
+ completeOffer: () => completeOffer,
34378
+ completeSellIdentityOffer: () => completeSellIdentityOffer,
34379
+ completeSwapIdentityOffer: () => completeSwapIdentityOffer
34380
+ });
34381
+
34382
+ // src/offers/sign.ts
34383
+ var SIGHASH_SINGLE = 3;
34384
+ var SIGHASH_ANYONECANPAY = 128;
34385
+ var SIGHASH_OFFER = SIGHASH_SINGLE | SIGHASH_ANYONECANPAY;
34386
+ function signOfferInput(unsignedHex, inputIndex, prevOutScript, prevOutValue, wif, network) {
34387
+ const verusNetwork = getNetwork(network === "testnet");
34388
+ const tx = import_utxo_lib.Transaction.fromHex(unsignedHex, verusNetwork);
34389
+ const input = tx.ins[inputIndex];
34390
+ if (!input) {
34391
+ throw new TransactionBuildError(`signOfferInput: no input at index ${inputIndex}`);
34392
+ }
34393
+ const keyPair = import_utxo_lib.ECPair.fromWIF(wif, verusNetwork);
34394
+ const sighash = tx.hashForSignatureByNetwork(
34395
+ inputIndex,
34396
+ prevOutScript,
34397
+ toSafeNumber(prevOutValue),
34398
+ SIGHASH_OFFER,
34399
+ false
34400
+ );
34401
+ const signature = keyPair.sign(sighash);
34402
+ const fulfillment = new import_utxo_lib.SmartTransactionSignatures(1, SIGHASH_OFFER, [
34403
+ new import_utxo_lib.SmartTransactionSignature(1, 1, keyPair.getPublicKeyBuffer(), signature.toCompact().slice(1))
34404
+ ]).toChunk();
34405
+ input.script = import_utxo_lib.script.compile([fulfillment]);
34406
+ return { signedTx: tx.toHex(), txid: tx.getId() };
34407
+ }
34408
+ function signTakerInputs(txHex, takerInputs, wif, network) {
34409
+ const verusNetwork = getNetwork(network === "testnet");
34410
+ const tx = import_utxo_lib.Transaction.fromHex(txHex, verusNetwork);
34411
+ const keyPair = import_utxo_lib.ECPair.fromWIF(wif, verusNetwork);
34412
+ for (const { index, prevOutScript, value } of takerInputs) {
34413
+ const input = tx.ins[index];
34414
+ if (!input) {
34415
+ throw new TransactionBuildError(`signTakerInputs: no input at index ${index}`);
34416
+ }
34417
+ const sighash = tx.hashForSignatureByNetwork(
34418
+ index,
34419
+ prevOutScript,
34420
+ toSafeNumber(value),
34421
+ import_utxo_lib.Transaction.SIGHASH_ALL,
34422
+ false
34423
+ );
34424
+ const signature = keyPair.sign(sighash);
34425
+ input.script = isSmartTransactionScript(prevOutScript) ? import_utxo_lib.script.compile([
34426
+ new import_utxo_lib.SmartTransactionSignatures(1, import_utxo_lib.Transaction.SIGHASH_ALL, [
34427
+ new import_utxo_lib.SmartTransactionSignature(1, 1, keyPair.getPublicKeyBuffer(), signature.toCompact().slice(1))
34428
+ ]).toChunk()
34429
+ ]) : import_utxo_lib.script.compile([signature.toScriptSignature(import_utxo_lib.Transaction.SIGHASH_ALL), keyPair.getPublicKeyBuffer()]);
34430
+ }
34431
+ return { signedTx: tx.toHex(), txid: tx.getId() };
34432
+ }
34433
+
34434
+ // src/offers/maker.ts
34435
+ function buildOfferFunding(params, network) {
34436
+ if (params.offered.amount <= 0n) {
34437
+ throw new TransactionBuildError("offered.amount must be positive");
34438
+ }
34439
+ const makerAddress = parseRAddress(params.makerAddress, "makerAddress");
34440
+ const systemId = NETWORK_CONFIG[network].chainId;
34441
+ const offeringNative = params.offered.currency === systemId;
34442
+ const commitmentScript = offeringNative ? buildCommitmentScript(Buffer.alloc(32, 0), makerAddress) : buildTokenCommitmentScript(params.offered.currency, params.offered.amount, makerAddress);
34443
+ const commitmentOutput = offeringNative ? { script: commitmentScript, nativeSat: params.offered.amount } : {
34444
+ script: commitmentScript,
34445
+ nativeSat: 0n,
34446
+ carries: /* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
34447
+ };
34448
+ const assembled = assembleAndSign({
34449
+ network,
34450
+ wif: params.wif,
34451
+ expiryHeight: params.expiryHeight ?? 0,
34452
+ funding: params.utxos,
34453
+ outputs: [commitmentOutput],
34454
+ changeAddress: params.changeAddress,
34455
+ fee: { policy: "estimate" },
34456
+ label: "offer funding"
34457
+ });
34458
+ return {
34459
+ fundingTx: assembled.signedTx,
34460
+ txid: assembled.txid,
34461
+ fee: assembled.fee,
34462
+ commitment: {
34463
+ txid: assembled.txid,
34464
+ vout: 0,
34465
+ // Native satoshis on the commitment output — 0 for a token offer. This is
34466
+ // the amount the offer input signs over (SIGHASH_SINGLE|ANYONECANPAY).
34467
+ value: offeringNative ? params.offered.amount : 0n,
34468
+ script: commitmentScript.toString("hex")
34469
+ }
34470
+ };
34471
+ }
34472
+ function buildOffer(params, network) {
34473
+ const verusNetwork = getNetwork(network === "testnet");
34474
+ const systemId = NETWORK_CONFIG[network].chainId;
34475
+ if (params.want.amount <= 0n) {
34476
+ throw new TransactionBuildError("want.amount must be positive");
34477
+ }
34478
+ if (params.expiryHeight === void 0 || !Number.isInteger(params.expiryHeight) || params.expiryHeight <= 0) {
34479
+ throw new TransactionBuildError(
34480
+ "expiryHeight (a positive future block height) is required for an offer; the daemon rejects a 0/never-expiring offer as expired. Use currentBlockHeight + a margin (e.g. +200)."
34481
+ );
34482
+ }
34483
+ let wantedScript;
34484
+ let wantedNative;
34485
+ if (params.want.currency === systemId) {
34486
+ wantedScript = params.want.address.startsWith("i") ? identityPaymentScript(parseIAddress(params.want.address, "want.address")) : addressToScriptPubKey(params.want.address);
34487
+ wantedNative = params.want.amount;
34488
+ } else {
34489
+ wantedScript = buildTokenChangeOutput(
34490
+ parseAddress(params.want.address, "want.address"),
34491
+ /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]])
34492
+ ).script;
34493
+ wantedNative = 0n;
34494
+ }
34495
+ const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
34496
+ txb.setVersion(4);
34497
+ txb.setExpiryHeight(resolveExpiryHeight(params.expiryHeight));
34498
+ txb.setVersionGroupId(VERSION_GROUP_ID);
34499
+ txb.addInput(
34500
+ Buffer.from(params.commitment.txid, "hex").reverse(),
34501
+ params.commitment.vout,
34502
+ 4294967295,
34503
+ Buffer.from(params.commitment.script, "hex")
34504
+ );
34505
+ txb.addOutput(wantedScript, toSafeNumber(wantedNative));
34506
+ const unsignedHex = txb.buildIncomplete().toHex();
34507
+ const { signedTx, txid } = signOfferInput(
34508
+ unsignedHex,
34509
+ 0,
34510
+ Buffer.from(params.commitment.script, "hex"),
34511
+ params.commitment.value,
34512
+ params.wif,
34513
+ network
34514
+ );
34515
+ return { offerTx: signedTx, txid };
34516
+ }
34517
+
34518
+ // src/offers/taker.ts
34519
+ function nativePaymentScript(address2) {
34520
+ return address2.startsWith("i") ? identityPaymentScript(parseIAddress(address2, "address")) : addressToScriptPubKey(address2);
34521
+ }
34522
+ function completeOffer(params, network) {
34523
+ const verusNetwork = getNetwork(network === "testnet");
34524
+ const systemId = NETWORK_CONFIG[network].chainId;
34525
+ const offeringNative = params.offered.currency === systemId;
34526
+ const wantingNative = params.want.currency === systemId;
34527
+ if (params.offered.amount <= 0n || params.want.amount <= 0n) {
34528
+ throw new TransactionBuildError("completeOffer: offered.amount and want.amount must be positive");
34529
+ }
34530
+ const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
34531
+ if (tx.ins.length !== 1 || tx.outs.length !== 1) {
34532
+ throw new TransactionBuildError("completeOffer: expected a maker offer partial (1 input, 1 output)");
34533
+ }
34534
+ const commitmentNative = offeringNative ? params.offered.amount : 0n;
34535
+ if (offeringNative) {
34536
+ tx.addOutput(nativePaymentScript(params.takerAddress), toSafeNumber(params.offered.amount));
34537
+ } else {
34538
+ const offeredOut = buildTokenChangeOutput(
34539
+ parseAddress(params.takerAddress, "takerAddress"),
34540
+ /* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
34541
+ );
34542
+ tx.addOutput(offeredOut.script, 0);
34543
+ }
34544
+ const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
34545
+ const requiredNative = wantingNative ? params.want.amount : 0n;
34546
+ const selection = selectUtxos(
34547
+ params.takerUtxos,
34548
+ requiredNative,
34549
+ wantedTokenReq,
34550
+ 3,
34551
+ systemId,
34552
+ void 0,
34553
+ true,
34554
+ 150
34555
+ );
34556
+ const takerInputs = [];
34557
+ for (const u of selection.selected) {
34558
+ const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
34559
+ takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
34560
+ }
34561
+ const hasTokenChange = selection.currencyChanges.size > 0;
34562
+ if (hasTokenChange || selection.nativeChange > 0n) {
34563
+ if (hasTokenChange) {
34564
+ const change = buildTokenChangeOutput(parseAddress(params.changeAddress, "changeAddress"), selection.currencyChanges);
34565
+ tx.addOutput(change.script, toSafeNumber(selection.nativeChange));
34566
+ } else {
34567
+ tx.addOutput(nativePaymentScript(params.changeAddress), toSafeNumber(selection.nativeChange));
34568
+ }
34569
+ }
34570
+ assertTokenConservation(
34571
+ selection.selected,
34572
+ wantedTokenReq,
34573
+ selection.currencyChanges,
34574
+ systemId,
34575
+ "takeOffer"
34576
+ );
34577
+ const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
34578
+ const allInputsNative = commitmentNative + takerNativeIn;
34579
+ assertNativeConservation([{ satoshis: allInputsNative }], tx.outs, selection.fee, "takeOffer");
34580
+ const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
34581
+ return { swapTx: signedTx, txid };
34582
+ }
34583
+
34584
+ // src/offers/reclaim.ts
34585
+ function nativePaymentScript2(address2) {
34586
+ return address2.startsWith("i") ? identityPaymentScript(parseIAddress(address2, "address")) : addressToScriptPubKey(address2);
34587
+ }
34588
+ function buildReclaimOffer(params, network) {
34589
+ const verusNetwork = getNetwork(network === "testnet");
34590
+ const systemId = NETWORK_CONFIG[network].chainId;
34591
+ const offeringNative = params.offered.currency === systemId;
34592
+ if (params.offered.amount <= 0n) {
34593
+ throw new TransactionBuildError("buildReclaimOffer: offered.amount must be positive");
34594
+ }
34595
+ if (!Number.isInteger(params.expiryHeight) || params.expiryHeight <= 0) {
34596
+ throw new TransactionBuildError("buildReclaimOffer: expiryHeight must be a positive block height");
34597
+ }
34598
+ const commitmentScript = Buffer.from(params.commitment.script, "hex");
34599
+ const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
34600
+ txb.setVersion(4);
34601
+ txb.setExpiryHeight(resolveExpiryHeight(params.expiryHeight));
34602
+ txb.setVersionGroupId(VERSION_GROUP_ID);
34603
+ txb.addInput(
34604
+ Buffer.from(params.commitment.txid, "hex").reverse(),
34605
+ params.commitment.vout,
34606
+ 4294967295,
34607
+ commitmentScript
34608
+ );
34609
+ if (offeringNative) {
34610
+ const fee = estimateFee(1, 1, DEFAULT_FEE_PER_KB, false, 100);
34611
+ const outAmount = params.offered.amount - fee;
34612
+ if (outAmount <= DUST_THRESHOLD) {
34613
+ throw new TransactionBuildError(
34614
+ `buildReclaimOffer: reclaimed native value ${params.offered.amount} is too small to cover the fee ${fee} above dust`
34615
+ );
34616
+ }
34617
+ txb.addOutput(nativePaymentScript2(params.makerAddress), toSafeNumber(outAmount));
34618
+ const tx2 = import_utxo_lib.Transaction.fromHex(txb.buildIncomplete().toHex(), verusNetwork);
34619
+ const takerInputs2 = [
34620
+ { index: 0, prevOutScript: commitmentScript, value: params.commitment.value }
34621
+ ];
34622
+ assertNativeConservation([{ satoshis: params.commitment.value }], tx2.outs, fee, "reclaimOffer");
34623
+ const { signedTx: signedTx2, txid: txid2 } = signTakerInputs(tx2.toHex(), takerInputs2, params.wif, network);
34624
+ return { reclaimTx: signedTx2, txid: txid2 };
34625
+ }
34626
+ const feeUtxos = params.feeUtxos ?? [];
34627
+ if (feeUtxos.length === 0) {
34628
+ throw new TransactionBuildError(
34629
+ "buildReclaimOffer: reclaiming a token requires feeUtxos (native UTXOs) \u2014 the token commitment carries no native coin for the fee"
34630
+ );
34631
+ }
34632
+ const tokenOut = buildTokenChangeOutput(
34633
+ parseAddress(params.makerAddress, "makerAddress"),
34634
+ /* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
34635
+ );
34636
+ txb.addOutput(tokenOut.script, 0);
34637
+ const tx = import_utxo_lib.Transaction.fromHex(txb.buildIncomplete().toHex(), verusNetwork);
34638
+ const takerInputs = [
34639
+ { index: 0, prevOutScript: commitmentScript, value: 0n }
34640
+ ];
34641
+ const selection = selectUtxos(feeUtxos, 0n, /* @__PURE__ */ new Map(), 2, systemId, void 0, true, 200);
34642
+ if (selection.currencyChanges.size > 0) {
34643
+ throw new TransactionBuildError(
34644
+ "buildReclaimOffer: feeUtxos must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost."
34645
+ );
34646
+ }
34647
+ const expectedFeeScript = addressToScriptPubKey(
34648
+ import_utxo_lib.ECPair.fromWIF(params.wif, verusNetwork).getAddress()
34649
+ ).toString("hex");
34650
+ for (const u of selection.selected) {
34651
+ if (u.script !== expectedFeeScript) {
34652
+ throw new TransactionBuildError(
34653
+ `buildReclaimOffer: fee UTXO ${u.txid}:${u.outputIndex} must be a native P2PKH output controlled by the provided wif.`
34654
+ );
34655
+ }
34656
+ const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
34657
+ takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
34658
+ }
34659
+ if (selection.nativeChange > 0n) {
34660
+ tx.addOutput(nativePaymentScript2(params.changeAddress ?? params.makerAddress), toSafeNumber(selection.nativeChange));
34661
+ }
34662
+ const feeNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
34663
+ assertNativeConservation([{ satoshis: feeNativeIn }], tx.outs, selection.fee, "reclaimOffer");
34664
+ const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
34665
+ return { reclaimTx: signedTx, txid };
34666
+ }
34667
+
34668
+ // src/offers/identity.ts
34669
+ function nativePaymentScript3(address2) {
34670
+ return address2.startsWith("i") ? identityPaymentScript(parseIAddress(address2, "address")) : addressToScriptPubKey(address2);
34671
+ }
34672
+ function buildTransferredIdentity(identityJson, newPrimaryAddresses) {
34673
+ const identity = boundary_exports.Identity.fromJson(identityJson);
34674
+ identity.setPrimaryAddresses(newPrimaryAddresses);
34675
+ return buildIdentityScript(identity);
34676
+ }
34677
+ function assertExpiryHeight(expiryHeight) {
34678
+ if (!Number.isInteger(expiryHeight) || expiryHeight <= 0) {
34679
+ throw new TransactionBuildError(
34680
+ "expiryHeight (a positive future block height) is required for an offer; the daemon rejects a 0/never-expiring offer as expired."
34681
+ );
34682
+ }
34683
+ }
34684
+ function fundFeeAndSignIdentityTaker(args) {
34685
+ const systemId = NETWORK_CONFIG[args.network].chainId;
34686
+ const verusNetwork = getNetwork(args.network === "testnet");
34687
+ const selection = selectUtxos(args.takerUtxos, 0n, /* @__PURE__ */ new Map(), 3, systemId, void 0, true, args.extraOutputBytes);
34688
+ if (selection.currencyChanges.size > 0) {
34689
+ throw new TransactionBuildError(
34690
+ `${args.label}: the fee UTXOs must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost.`
34691
+ );
34692
+ }
34693
+ const expectedScript = addressToScriptPubKey(
34694
+ import_utxo_lib.ECPair.fromWIF(args.wif, verusNetwork).getAddress()
34695
+ ).toString("hex");
34696
+ const takerInputs = [...args.priorInputs];
34697
+ for (const u of selection.selected) {
34698
+ if (u.script !== expectedScript) {
34699
+ throw new TransactionBuildError(
34700
+ `${args.label}: fee UTXO ${u.txid}:${u.outputIndex} must be a native P2PKH output controlled by the provided wif.`
34701
+ );
34702
+ }
34703
+ const idx = args.tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
34704
+ takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
34705
+ }
34706
+ if (selection.nativeChange > 0n) {
34707
+ args.tx.addOutput(nativePaymentScript3(args.changeAddress), toSafeNumber(selection.nativeChange));
34708
+ }
34709
+ const feeNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
34710
+ assertNativeConservation(
34711
+ [{ satoshis: args.extraInputNative + feeNativeIn }],
34712
+ args.tx.outs,
34713
+ selection.fee,
34714
+ args.label
34715
+ );
34716
+ const { signedTx, txid } = signTakerInputs(args.tx.toHex(), takerInputs, args.wif, args.network);
34717
+ return { swapTx: signedTx, txid };
34718
+ }
34719
+ function buildSellIdentityOffer(params, network) {
34720
+ const commitment = {
34721
+ txid: params.identityOutput.txid,
34722
+ vout: params.identityOutput.vout,
34723
+ value: 0n,
34724
+ // an identity primary output carries 0 native
34725
+ script: params.identityOutput.script
34726
+ };
34727
+ return buildOffer({ wif: params.wif, commitment, want: params.want, expiryHeight: params.expiryHeight }, network);
34728
+ }
34729
+ function completeSellIdentityOffer(params, network) {
34730
+ const verusNetwork = getNetwork(network === "testnet");
34731
+ const systemId = NETWORK_CONFIG[network].chainId;
34732
+ const wantingNative = params.want.currency === systemId;
34733
+ if (params.want.amount <= 0n) {
34734
+ throw new TransactionBuildError("completeSellIdentityOffer: want.amount must be positive");
34735
+ }
34736
+ if (params.newPrimaryAddresses.length === 0) {
34737
+ throw new TransactionBuildError("completeSellIdentityOffer: newPrimaryAddresses must not be empty");
34738
+ }
34739
+ const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
34740
+ if (tx.ins.length !== 1 || tx.outs.length !== 1) {
34741
+ throw new TransactionBuildError("completeSellIdentityOffer: expected a maker offer partial (1 input, 1 output)");
34742
+ }
34743
+ tx.addOutput(buildTransferredIdentity(params.identityJson, params.newPrimaryAddresses), 0);
34744
+ const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
34745
+ const requiredNative = wantingNative ? params.want.amount : 0n;
34746
+ const selection = selectUtxos(
34747
+ params.takerUtxos,
34748
+ requiredNative,
34749
+ wantedTokenReq,
34750
+ 3,
34751
+ systemId,
34752
+ void 0,
34753
+ true,
34754
+ 150
34755
+ );
34756
+ const takerInputs = [];
34757
+ for (const u of selection.selected) {
34758
+ const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
34759
+ takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
34760
+ }
34761
+ const hasTokenChange = selection.currencyChanges.size > 0;
34762
+ if (hasTokenChange || selection.nativeChange > 0n) {
34763
+ if (hasTokenChange) {
34764
+ const change = buildTokenChangeOutput(parseAddress(params.changeAddress, "changeAddress"), selection.currencyChanges);
34765
+ tx.addOutput(change.script, toSafeNumber(selection.nativeChange));
34766
+ } else {
34767
+ tx.addOutput(nativePaymentScript3(params.changeAddress), toSafeNumber(selection.nativeChange));
34768
+ }
34769
+ }
34770
+ assertTokenConservation(selection.selected, wantedTokenReq, selection.currencyChanges, systemId, "takeSellIdentityOffer");
34771
+ const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
34772
+ assertNativeConservation([{ satoshis: takerNativeIn }], tx.outs, selection.fee, "takeSellIdentityOffer");
34773
+ const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
34774
+ return { swapTx: signedTx, txid };
34775
+ }
34776
+ function buildBuyIdentityOffer(params, network) {
34777
+ assertExpiryHeight(params.expiryHeight);
34778
+ if (params.buyerPrimaryAddresses.length === 0) {
34779
+ throw new TransactionBuildError("buildBuyIdentityOffer: buyerPrimaryAddresses must not be empty");
34780
+ }
34781
+ const verusNetwork = getNetwork(network === "testnet");
34782
+ const wantedScript = buildTransferredIdentity(params.identityJson, params.buyerPrimaryAddresses);
34783
+ const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
34784
+ txb.setVersion(4);
34785
+ txb.setExpiryHeight(resolveExpiryHeight(params.expiryHeight));
34786
+ txb.setVersionGroupId(VERSION_GROUP_ID);
34787
+ txb.addInput(
34788
+ Buffer.from(params.commitment.txid, "hex").reverse(),
34789
+ params.commitment.vout,
34790
+ 4294967295,
34791
+ Buffer.from(params.commitment.script, "hex")
34792
+ );
34793
+ txb.addOutput(wantedScript, 0);
34794
+ const { signedTx, txid } = signOfferInput(
34795
+ txb.buildIncomplete().toHex(),
34796
+ 0,
34797
+ Buffer.from(params.commitment.script, "hex"),
34798
+ params.commitment.value,
34799
+ params.wif,
34800
+ network
34801
+ );
34802
+ return { offerTx: signedTx, txid };
34803
+ }
34804
+ function completeBuyIdentityOffer(params, network) {
34805
+ const verusNetwork = getNetwork(network === "testnet");
34806
+ const systemId = NETWORK_CONFIG[network].chainId;
34807
+ const offeringNative = params.offered.currency === systemId;
34808
+ if (params.offered.amount <= 0n) {
34809
+ throw new TransactionBuildError("completeBuyIdentityOffer: offered.amount must be positive");
34810
+ }
34811
+ const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
34812
+ if (tx.ins.length !== 1 || tx.outs.length !== 1) {
34813
+ throw new TransactionBuildError("completeBuyIdentityOffer: expected a maker offer partial (1 input, 1 output)");
34814
+ }
34815
+ const commitmentNative = offeringNative ? params.offered.amount : 0n;
34816
+ const idIdx = tx.addInput(
34817
+ Buffer.from(params.identityOutput.txid, "hex").reverse(),
34818
+ params.identityOutput.vout,
34819
+ 4294967295
34820
+ );
34821
+ const takerInputs = [
34822
+ { index: idIdx, prevOutScript: Buffer.from(params.identityOutput.script, "hex"), value: 0n }
34823
+ ];
34824
+ if (offeringNative) {
34825
+ tx.addOutput(nativePaymentScript3(params.sellerReceiveAddress), toSafeNumber(params.offered.amount));
34826
+ } else {
34827
+ const out = buildTokenChangeOutput(
34828
+ parseAddress(params.sellerReceiveAddress, "sellerReceiveAddress"),
34829
+ /* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
34830
+ );
34831
+ tx.addOutput(out.script, 0);
34832
+ }
34833
+ return fundFeeAndSignIdentityTaker({
34834
+ tx,
34835
+ priorInputs: takerInputs,
34836
+ extraInputNative: commitmentNative,
34837
+ takerUtxos: params.takerUtxos,
34838
+ changeAddress: params.changeAddress,
34839
+ wif: params.wif,
34840
+ network,
34841
+ label: "takeBuyIdentityOffer",
34842
+ extraOutputBytes: 300
34843
+ });
34844
+ }
34845
+ function buildSwapIdentityOffer(params, network) {
34846
+ if (params.makerPrimaryAddresses.length === 0) {
34847
+ throw new TransactionBuildError("buildSwapIdentityOffer: makerPrimaryAddresses must not be empty");
34848
+ }
34849
+ return buildBuyIdentityOffer(
34850
+ {
34851
+ wif: params.wif,
34852
+ commitment: {
34853
+ txid: params.offeredIdentityOutput.txid,
34854
+ vout: params.offeredIdentityOutput.vout,
34855
+ value: 0n,
34856
+ // an identity primary output carries 0 native
34857
+ script: params.offeredIdentityOutput.script
34858
+ },
34859
+ identityJson: params.wantedIdentityJson,
34860
+ buyerPrimaryAddresses: params.makerPrimaryAddresses,
34861
+ expiryHeight: params.expiryHeight
34862
+ },
34863
+ network
34864
+ );
34865
+ }
34866
+ function completeSwapIdentityOffer(params, network) {
34867
+ const verusNetwork = getNetwork(network === "testnet");
34868
+ if (params.takerPrimaryAddresses.length === 0) {
34869
+ throw new TransactionBuildError("completeSwapIdentityOffer: takerPrimaryAddresses must not be empty");
34870
+ }
34871
+ const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
34872
+ if (tx.ins.length !== 1 || tx.outs.length !== 1) {
34873
+ throw new TransactionBuildError("completeSwapIdentityOffer: expected a maker offer partial (1 input, 1 output)");
34874
+ }
34875
+ tx.addOutput(buildTransferredIdentity(params.offeredIdentityJson, params.takerPrimaryAddresses), 0);
34876
+ const idIdx = tx.addInput(
34877
+ Buffer.from(params.wantedIdentityOutput.txid, "hex").reverse(),
34878
+ params.wantedIdentityOutput.vout,
34879
+ 4294967295
34880
+ );
34881
+ const takerInputs = [
34882
+ { index: idIdx, prevOutScript: Buffer.from(params.wantedIdentityOutput.script, "hex"), value: 0n }
34883
+ ];
34884
+ return fundFeeAndSignIdentityTaker({
34885
+ tx,
34886
+ priorInputs: takerInputs,
34887
+ extraInputNative: 0n,
34888
+ takerUtxos: params.takerUtxos,
34889
+ changeAddress: params.changeAddress,
34890
+ wif: params.wif,
34891
+ network,
34892
+ label: "takeSwapIdentityOffer",
34893
+ extraOutputBytes: 500
34894
+ });
34895
+ }
34896
+
34350
34897
  // src/VerusSDK.ts
34351
34898
  var VerusSDK = class {
34352
34899
  constructor(config) {
@@ -34468,6 +35015,60 @@ var VerusSDK = class {
34468
35015
  verifyMessage(params) {
34469
35016
  return verifyMessage(params, this.network);
34470
35017
  }
35018
+ // ─── Marketplace Offers (atomic swaps) ─────────────
35019
+ /**
35020
+ * Maker step 1 (currency offers only): fund the OFFERED asset into a commitment
35021
+ * output. Broadcast the returned tx, then pass `commitment` to `buildOffer`.
35022
+ */
35023
+ buildOfferFunding(params) {
35024
+ return buildOfferFunding(params, this.network);
35025
+ }
35026
+ /**
35027
+ * Maker step 2 (currency offers): build the half-signed offer — spend the funded
35028
+ * commitment with 0x83, committing to the single WANTED output paid to the maker.
35029
+ */
35030
+ buildOffer(params) {
35031
+ return buildOffer(params, this.network);
35032
+ }
35033
+ /**
35034
+ * Taker (currency offers): complete the maker's offer — pay the wanted asset,
35035
+ * receive the offered asset, and sign the taker's side into an atomic swap.
35036
+ */
35037
+ completeOffer(params) {
35038
+ return completeOffer(params, this.network);
35039
+ }
35040
+ /**
35041
+ * Maker: cancel an unaccepted offer — spend the funding commitment back to the
35042
+ * maker (SIGHASH_ALL). Native: the fee comes out of the reclaimed value; token:
35043
+ * pass native `feeUtxos` controlled by the same key.
35044
+ */
35045
+ buildReclaimOffer(params) {
35046
+ return buildReclaimOffer(params, this.network);
35047
+ }
35048
+ /** Maker: offer a VerusID for a currency (spends the identity's on-chain output). */
35049
+ buildSellIdentityOffer(params) {
35050
+ return buildSellIdentityOffer(params, this.network);
35051
+ }
35052
+ /** Taker: complete a sell-identity offer — pay the currency, receive the identity. */
35053
+ completeSellIdentityOffer(params) {
35054
+ return completeSellIdentityOffer(params, this.network);
35055
+ }
35056
+ /** Maker: offer a currency for a VerusID (funds the currency into a commitment). */
35057
+ buildBuyIdentityOffer(params) {
35058
+ return buildBuyIdentityOffer(params, this.network);
35059
+ }
35060
+ /** Taker (identity owner): complete a buy-identity offer — give up the identity, take the currency. */
35061
+ completeBuyIdentityOffer(params) {
35062
+ return completeBuyIdentityOffer(params, this.network);
35063
+ }
35064
+ /** Maker: offer a VerusID for another VerusID (no currency moves). */
35065
+ buildSwapIdentityOffer(params) {
35066
+ return buildSwapIdentityOffer(params, this.network);
35067
+ }
35068
+ /** Taker (owns the wanted identity): complete an identity swap — funds only the miner fee. */
35069
+ completeSwapIdentityOffer(params) {
35070
+ return completeSwapIdentityOffer(params, this.network);
35071
+ }
34471
35072
  // ─── Static Utilities ─────────────────────────────
34472
35073
  /** Derive R-address from WIF private key */
34473
35074
  static async deriveAddress(wif) {
@@ -34516,8 +35117,8 @@ function isIdentityName(input) {
34516
35117
  }
34517
35118
 
34518
35119
  // src/identity/public.ts
34519
- var public_exports = {};
34520
- __export(public_exports, {
35120
+ var public_exports2 = {};
35121
+ __export(public_exports2, {
34521
35122
  buildAndSignCommitment: () => buildAndSignCommitment,
34522
35123
  buildAndSignIdentityUpdate: () => buildAndSignIdentityUpdate,
34523
35124
  buildAndSignRegistration: () => buildAndSignRegistration,
@@ -34568,6 +35169,7 @@ __export(public_exports, {
34568
35169
  isVerusAddress,
34569
35170
  keys,
34570
35171
  message,
35172
+ offers,
34571
35173
  parseSats,
34572
35174
  signing,
34573
35175
  toCoins,