@chainvue/verus-sdk 0.10.0 → 0.11.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.
- package/README.md +5 -0
- package/dist/VerusSDK.d.ts +28 -0
- package/dist/VerusSDK.d.ts.map +1 -1
- package/dist/VerusSDK.js +47 -0
- package/dist/VerusSDK.js.map +1 -1
- package/dist/bundle.js +552 -43
- package/dist/fork/boundary.d.ts +1 -1
- package/dist/fork/boundary.d.ts.map +1 -1
- package/dist/fork/boundary.js +6 -1
- package/dist/fork/boundary.js.map +1 -1
- package/dist/identity/index.d.ts +10 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +31 -0
- package/dist/identity/index.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/offers/identity.d.ts +193 -0
- package/dist/offers/identity.d.ts.map +1 -0
- package/dist/offers/identity.js +314 -0
- package/dist/offers/identity.js.map +1 -0
- package/dist/offers/maker.d.ts +67 -0
- package/dist/offers/maker.d.ts.map +1 -0
- package/dist/offers/maker.js +132 -0
- package/dist/offers/maker.js.map +1 -0
- package/dist/offers/public.d.ts +30 -0
- package/dist/offers/public.d.ts.map +1 -0
- package/dist/offers/public.js +42 -0
- package/dist/offers/public.js.map +1 -0
- package/dist/offers/sign.d.ts +42 -0
- package/dist/offers/sign.d.ts.map +1 -0
- package/dist/offers/sign.js +98 -0
- package/dist/offers/sign.js.map +1 -0
- package/dist/offers/taker.d.ts +33 -0
- package/dist/offers/taker.d.ts.map +1 -0
- package/dist/offers/taker.js +113 -0
- package/dist/offers/taker.js.map +1 -0
- package/dist/utxo/index.d.ts +7 -0
- package/dist/utxo/index.d.ts.map +1 -1
- package/dist/utxo/index.js +1 -0
- package/dist/utxo/index.js.map +1 -1
- 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
|
|
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 =
|
|
9963
|
-
|
|
9964
|
-
|
|
9965
|
-
|
|
9966
|
-
|
|
9967
|
-
|
|
9968
|
-
|
|
9969
|
-
|
|
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
|
|
20229
|
+
var SmartTransactionSignature2 = (
|
|
20230
20230
|
/** @class */
|
|
20231
20231
|
(function() {
|
|
20232
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
20300
|
+
return SmartTransactionSignature3;
|
|
20301
20301
|
})()
|
|
20302
20302
|
);
|
|
20303
|
-
module2.exports =
|
|
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
|
|
20315
|
-
var
|
|
20314
|
+
var SmartTransactionSignature2 = require_smart_transaction_signature();
|
|
20315
|
+
var SmartTransactionSignatures2 = (
|
|
20316
20316
|
/** @class */
|
|
20317
20317
|
(function() {
|
|
20318
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20339
|
-
var checkSigs = new
|
|
20338
|
+
SmartTransactionSignatures3.prototype.minLength = function() {
|
|
20339
|
+
var checkSigs = new SmartTransactionSignatures3();
|
|
20340
20340
|
return checkSigs.__byteLength();
|
|
20341
20341
|
};
|
|
20342
|
-
|
|
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
|
-
|
|
20365
|
-
var sigs = new
|
|
20364
|
+
SmartTransactionSignatures3.fromChunk = function(chunk) {
|
|
20365
|
+
var sigs = new SmartTransactionSignatures3();
|
|
20366
20366
|
sigs.fromBuffer(chunk);
|
|
20367
20367
|
return sigs;
|
|
20368
20368
|
};
|
|
20369
|
-
|
|
20369
|
+
SmartTransactionSignatures3.prototype.toChunk = function() {
|
|
20370
20370
|
return this.toBuffer();
|
|
20371
20371
|
};
|
|
20372
|
-
|
|
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
|
|
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
|
|
20413
|
+
return SmartTransactionSignatures3;
|
|
20414
20414
|
})()
|
|
20415
20415
|
);
|
|
20416
|
-
module2.exports =
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
30154
|
-
var
|
|
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 =
|
|
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
|
|
30826
|
-
new
|
|
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 =
|
|
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: () =>
|
|
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,451 @@ 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
|
+
buildSellIdentityOffer: () => buildSellIdentityOffer,
|
|
34374
|
+
buildSwapIdentityOffer: () => buildSwapIdentityOffer,
|
|
34375
|
+
completeBuyIdentityOffer: () => completeBuyIdentityOffer,
|
|
34376
|
+
completeOffer: () => completeOffer,
|
|
34377
|
+
completeSellIdentityOffer: () => completeSellIdentityOffer,
|
|
34378
|
+
completeSwapIdentityOffer: () => completeSwapIdentityOffer
|
|
34379
|
+
});
|
|
34380
|
+
|
|
34381
|
+
// src/offers/sign.ts
|
|
34382
|
+
var SIGHASH_SINGLE = 3;
|
|
34383
|
+
var SIGHASH_ANYONECANPAY = 128;
|
|
34384
|
+
var SIGHASH_OFFER = SIGHASH_SINGLE | SIGHASH_ANYONECANPAY;
|
|
34385
|
+
function signOfferInput(unsignedHex, inputIndex, prevOutScript, prevOutValue, wif, network) {
|
|
34386
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34387
|
+
const tx = import_utxo_lib.Transaction.fromHex(unsignedHex, verusNetwork);
|
|
34388
|
+
const input = tx.ins[inputIndex];
|
|
34389
|
+
if (!input) {
|
|
34390
|
+
throw new TransactionBuildError(`signOfferInput: no input at index ${inputIndex}`);
|
|
34391
|
+
}
|
|
34392
|
+
const keyPair = import_utxo_lib.ECPair.fromWIF(wif, verusNetwork);
|
|
34393
|
+
const sighash = tx.hashForSignatureByNetwork(
|
|
34394
|
+
inputIndex,
|
|
34395
|
+
prevOutScript,
|
|
34396
|
+
toSafeNumber(prevOutValue),
|
|
34397
|
+
SIGHASH_OFFER,
|
|
34398
|
+
false
|
|
34399
|
+
);
|
|
34400
|
+
const signature = keyPair.sign(sighash);
|
|
34401
|
+
const fulfillment = new import_utxo_lib.SmartTransactionSignatures(1, SIGHASH_OFFER, [
|
|
34402
|
+
new import_utxo_lib.SmartTransactionSignature(1, 1, keyPair.getPublicKeyBuffer(), signature.toCompact().slice(1))
|
|
34403
|
+
]).toChunk();
|
|
34404
|
+
input.script = import_utxo_lib.script.compile([fulfillment]);
|
|
34405
|
+
return { signedTx: tx.toHex(), txid: tx.getId() };
|
|
34406
|
+
}
|
|
34407
|
+
function signTakerInputs(txHex, takerInputs, wif, network) {
|
|
34408
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34409
|
+
const tx = import_utxo_lib.Transaction.fromHex(txHex, verusNetwork);
|
|
34410
|
+
const keyPair = import_utxo_lib.ECPair.fromWIF(wif, verusNetwork);
|
|
34411
|
+
for (const { index, prevOutScript, value } of takerInputs) {
|
|
34412
|
+
const input = tx.ins[index];
|
|
34413
|
+
if (!input) {
|
|
34414
|
+
throw new TransactionBuildError(`signTakerInputs: no input at index ${index}`);
|
|
34415
|
+
}
|
|
34416
|
+
const sighash = tx.hashForSignatureByNetwork(
|
|
34417
|
+
index,
|
|
34418
|
+
prevOutScript,
|
|
34419
|
+
toSafeNumber(value),
|
|
34420
|
+
import_utxo_lib.Transaction.SIGHASH_ALL,
|
|
34421
|
+
false
|
|
34422
|
+
);
|
|
34423
|
+
const signature = keyPair.sign(sighash);
|
|
34424
|
+
input.script = isSmartTransactionScript(prevOutScript) ? import_utxo_lib.script.compile([
|
|
34425
|
+
new import_utxo_lib.SmartTransactionSignatures(1, import_utxo_lib.Transaction.SIGHASH_ALL, [
|
|
34426
|
+
new import_utxo_lib.SmartTransactionSignature(1, 1, keyPair.getPublicKeyBuffer(), signature.toCompact().slice(1))
|
|
34427
|
+
]).toChunk()
|
|
34428
|
+
]) : import_utxo_lib.script.compile([signature.toScriptSignature(import_utxo_lib.Transaction.SIGHASH_ALL), keyPair.getPublicKeyBuffer()]);
|
|
34429
|
+
}
|
|
34430
|
+
return { signedTx: tx.toHex(), txid: tx.getId() };
|
|
34431
|
+
}
|
|
34432
|
+
|
|
34433
|
+
// src/offers/maker.ts
|
|
34434
|
+
function buildOfferFunding(params, network) {
|
|
34435
|
+
if (params.offered.amount <= 0n) {
|
|
34436
|
+
throw new TransactionBuildError("offered.amount must be positive");
|
|
34437
|
+
}
|
|
34438
|
+
const makerAddress = parseRAddress(params.makerAddress, "makerAddress");
|
|
34439
|
+
const systemId = NETWORK_CONFIG[network].chainId;
|
|
34440
|
+
const offeringNative = params.offered.currency === systemId;
|
|
34441
|
+
const commitmentScript = offeringNative ? buildCommitmentScript(Buffer.alloc(32, 0), makerAddress) : buildTokenCommitmentScript(params.offered.currency, params.offered.amount, makerAddress);
|
|
34442
|
+
const commitmentOutput = offeringNative ? { script: commitmentScript, nativeSat: params.offered.amount } : {
|
|
34443
|
+
script: commitmentScript,
|
|
34444
|
+
nativeSat: 0n,
|
|
34445
|
+
carries: /* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
|
|
34446
|
+
};
|
|
34447
|
+
const assembled = assembleAndSign({
|
|
34448
|
+
network,
|
|
34449
|
+
wif: params.wif,
|
|
34450
|
+
expiryHeight: params.expiryHeight ?? 0,
|
|
34451
|
+
funding: params.utxos,
|
|
34452
|
+
outputs: [commitmentOutput],
|
|
34453
|
+
changeAddress: params.changeAddress,
|
|
34454
|
+
fee: { policy: "estimate" },
|
|
34455
|
+
label: "offer funding"
|
|
34456
|
+
});
|
|
34457
|
+
return {
|
|
34458
|
+
fundingTx: assembled.signedTx,
|
|
34459
|
+
txid: assembled.txid,
|
|
34460
|
+
fee: assembled.fee,
|
|
34461
|
+
commitment: {
|
|
34462
|
+
txid: assembled.txid,
|
|
34463
|
+
vout: 0,
|
|
34464
|
+
// Native satoshis on the commitment output — 0 for a token offer. This is
|
|
34465
|
+
// the amount the offer input signs over (SIGHASH_SINGLE|ANYONECANPAY).
|
|
34466
|
+
value: offeringNative ? params.offered.amount : 0n,
|
|
34467
|
+
script: commitmentScript.toString("hex")
|
|
34468
|
+
}
|
|
34469
|
+
};
|
|
34470
|
+
}
|
|
34471
|
+
function buildOffer(params, network) {
|
|
34472
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34473
|
+
const systemId = NETWORK_CONFIG[network].chainId;
|
|
34474
|
+
if (params.want.amount <= 0n) {
|
|
34475
|
+
throw new TransactionBuildError("want.amount must be positive");
|
|
34476
|
+
}
|
|
34477
|
+
if (params.expiryHeight === void 0 || !Number.isInteger(params.expiryHeight) || params.expiryHeight <= 0) {
|
|
34478
|
+
throw new TransactionBuildError(
|
|
34479
|
+
"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)."
|
|
34480
|
+
);
|
|
34481
|
+
}
|
|
34482
|
+
let wantedScript;
|
|
34483
|
+
let wantedNative;
|
|
34484
|
+
if (params.want.currency === systemId) {
|
|
34485
|
+
wantedScript = params.want.address.startsWith("i") ? identityPaymentScript(parseIAddress(params.want.address, "want.address")) : addressToScriptPubKey(params.want.address);
|
|
34486
|
+
wantedNative = params.want.amount;
|
|
34487
|
+
} else {
|
|
34488
|
+
wantedScript = buildTokenChangeOutput(
|
|
34489
|
+
parseAddress(params.want.address, "want.address"),
|
|
34490
|
+
/* @__PURE__ */ new Map([[params.want.currency, params.want.amount]])
|
|
34491
|
+
).script;
|
|
34492
|
+
wantedNative = 0n;
|
|
34493
|
+
}
|
|
34494
|
+
const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
|
|
34495
|
+
txb.setVersion(4);
|
|
34496
|
+
txb.setExpiryHeight(resolveExpiryHeight(params.expiryHeight));
|
|
34497
|
+
txb.setVersionGroupId(VERSION_GROUP_ID);
|
|
34498
|
+
txb.addInput(
|
|
34499
|
+
Buffer.from(params.commitment.txid, "hex").reverse(),
|
|
34500
|
+
params.commitment.vout,
|
|
34501
|
+
4294967295,
|
|
34502
|
+
Buffer.from(params.commitment.script, "hex")
|
|
34503
|
+
);
|
|
34504
|
+
txb.addOutput(wantedScript, toSafeNumber(wantedNative));
|
|
34505
|
+
const unsignedHex = txb.buildIncomplete().toHex();
|
|
34506
|
+
const { signedTx, txid } = signOfferInput(
|
|
34507
|
+
unsignedHex,
|
|
34508
|
+
0,
|
|
34509
|
+
Buffer.from(params.commitment.script, "hex"),
|
|
34510
|
+
params.commitment.value,
|
|
34511
|
+
params.wif,
|
|
34512
|
+
network
|
|
34513
|
+
);
|
|
34514
|
+
return { offerTx: signedTx, txid };
|
|
34515
|
+
}
|
|
34516
|
+
|
|
34517
|
+
// src/offers/taker.ts
|
|
34518
|
+
function nativePaymentScript(address2) {
|
|
34519
|
+
return address2.startsWith("i") ? identityPaymentScript(parseIAddress(address2, "address")) : addressToScriptPubKey(address2);
|
|
34520
|
+
}
|
|
34521
|
+
function completeOffer(params, network) {
|
|
34522
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34523
|
+
const systemId = NETWORK_CONFIG[network].chainId;
|
|
34524
|
+
const offeringNative = params.offered.currency === systemId;
|
|
34525
|
+
const wantingNative = params.want.currency === systemId;
|
|
34526
|
+
if (params.offered.amount <= 0n || params.want.amount <= 0n) {
|
|
34527
|
+
throw new TransactionBuildError("completeOffer: offered.amount and want.amount must be positive");
|
|
34528
|
+
}
|
|
34529
|
+
const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
34530
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
34531
|
+
throw new TransactionBuildError("completeOffer: expected a maker offer partial (1 input, 1 output)");
|
|
34532
|
+
}
|
|
34533
|
+
const commitmentNative = offeringNative ? params.offered.amount : 0n;
|
|
34534
|
+
if (offeringNative) {
|
|
34535
|
+
tx.addOutput(nativePaymentScript(params.takerAddress), toSafeNumber(params.offered.amount));
|
|
34536
|
+
} else {
|
|
34537
|
+
const offeredOut = buildTokenChangeOutput(
|
|
34538
|
+
parseAddress(params.takerAddress, "takerAddress"),
|
|
34539
|
+
/* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
|
|
34540
|
+
);
|
|
34541
|
+
tx.addOutput(offeredOut.script, 0);
|
|
34542
|
+
}
|
|
34543
|
+
const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
|
|
34544
|
+
const requiredNative = wantingNative ? params.want.amount : 0n;
|
|
34545
|
+
const selection = selectUtxos(
|
|
34546
|
+
params.takerUtxos,
|
|
34547
|
+
requiredNative,
|
|
34548
|
+
wantedTokenReq,
|
|
34549
|
+
3,
|
|
34550
|
+
systemId,
|
|
34551
|
+
void 0,
|
|
34552
|
+
true,
|
|
34553
|
+
150
|
|
34554
|
+
);
|
|
34555
|
+
const takerInputs = [];
|
|
34556
|
+
for (const u of selection.selected) {
|
|
34557
|
+
const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
|
|
34558
|
+
takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
|
|
34559
|
+
}
|
|
34560
|
+
const hasTokenChange = selection.currencyChanges.size > 0;
|
|
34561
|
+
if (hasTokenChange || selection.nativeChange > 0n) {
|
|
34562
|
+
if (hasTokenChange) {
|
|
34563
|
+
const change = buildTokenChangeOutput(parseAddress(params.changeAddress, "changeAddress"), selection.currencyChanges);
|
|
34564
|
+
tx.addOutput(change.script, toSafeNumber(selection.nativeChange));
|
|
34565
|
+
} else {
|
|
34566
|
+
tx.addOutput(nativePaymentScript(params.changeAddress), toSafeNumber(selection.nativeChange));
|
|
34567
|
+
}
|
|
34568
|
+
}
|
|
34569
|
+
assertTokenConservation(
|
|
34570
|
+
selection.selected,
|
|
34571
|
+
wantedTokenReq,
|
|
34572
|
+
selection.currencyChanges,
|
|
34573
|
+
systemId,
|
|
34574
|
+
"takeOffer"
|
|
34575
|
+
);
|
|
34576
|
+
const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
|
|
34577
|
+
const allInputsNative = commitmentNative + takerNativeIn;
|
|
34578
|
+
assertNativeConservation([{ satoshis: allInputsNative }], tx.outs, selection.fee, "takeOffer");
|
|
34579
|
+
const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
|
|
34580
|
+
return { swapTx: signedTx, txid };
|
|
34581
|
+
}
|
|
34582
|
+
|
|
34583
|
+
// src/offers/identity.ts
|
|
34584
|
+
function nativePaymentScript2(address2) {
|
|
34585
|
+
return address2.startsWith("i") ? identityPaymentScript(parseIAddress(address2, "address")) : addressToScriptPubKey(address2);
|
|
34586
|
+
}
|
|
34587
|
+
function buildTransferredIdentity(identityJson, newPrimaryAddresses) {
|
|
34588
|
+
const identity = boundary_exports.Identity.fromJson(identityJson);
|
|
34589
|
+
identity.setPrimaryAddresses(newPrimaryAddresses);
|
|
34590
|
+
return buildIdentityScript(identity);
|
|
34591
|
+
}
|
|
34592
|
+
function assertExpiryHeight(expiryHeight) {
|
|
34593
|
+
if (!Number.isInteger(expiryHeight) || expiryHeight <= 0) {
|
|
34594
|
+
throw new TransactionBuildError(
|
|
34595
|
+
"expiryHeight (a positive future block height) is required for an offer; the daemon rejects a 0/never-expiring offer as expired."
|
|
34596
|
+
);
|
|
34597
|
+
}
|
|
34598
|
+
}
|
|
34599
|
+
function fundFeeAndSignIdentityTaker(args) {
|
|
34600
|
+
const systemId = NETWORK_CONFIG[args.network].chainId;
|
|
34601
|
+
const verusNetwork = getNetwork(args.network === "testnet");
|
|
34602
|
+
const selection = selectUtxos(args.takerUtxos, 0n, /* @__PURE__ */ new Map(), 3, systemId, void 0, true, args.extraOutputBytes);
|
|
34603
|
+
if (selection.currencyChanges.size > 0) {
|
|
34604
|
+
throw new TransactionBuildError(
|
|
34605
|
+
`${args.label}: the fee UTXOs must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost.`
|
|
34606
|
+
);
|
|
34607
|
+
}
|
|
34608
|
+
const expectedScript = addressToScriptPubKey(
|
|
34609
|
+
import_utxo_lib.ECPair.fromWIF(args.wif, verusNetwork).getAddress()
|
|
34610
|
+
).toString("hex");
|
|
34611
|
+
const takerInputs = [...args.priorInputs];
|
|
34612
|
+
for (const u of selection.selected) {
|
|
34613
|
+
if (!isSmartTransactionScript(Buffer.from(u.script, "hex")) && u.script !== expectedScript) {
|
|
34614
|
+
throw new TransactionBuildError(
|
|
34615
|
+
`${args.label}: fee UTXO ${u.txid}:${u.outputIndex} is not controlled by the provided wif (its scriptPubKey does not match the wif's address).`
|
|
34616
|
+
);
|
|
34617
|
+
}
|
|
34618
|
+
const idx = args.tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
|
|
34619
|
+
takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
|
|
34620
|
+
}
|
|
34621
|
+
if (selection.nativeChange > 0n) {
|
|
34622
|
+
args.tx.addOutput(nativePaymentScript2(args.changeAddress), toSafeNumber(selection.nativeChange));
|
|
34623
|
+
}
|
|
34624
|
+
const feeNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
|
|
34625
|
+
assertNativeConservation(
|
|
34626
|
+
[{ satoshis: args.extraInputNative + feeNativeIn }],
|
|
34627
|
+
args.tx.outs,
|
|
34628
|
+
selection.fee,
|
|
34629
|
+
args.label
|
|
34630
|
+
);
|
|
34631
|
+
const { signedTx, txid } = signTakerInputs(args.tx.toHex(), takerInputs, args.wif, args.network);
|
|
34632
|
+
return { swapTx: signedTx, txid };
|
|
34633
|
+
}
|
|
34634
|
+
function buildSellIdentityOffer(params, network) {
|
|
34635
|
+
const commitment = {
|
|
34636
|
+
txid: params.identityOutput.txid,
|
|
34637
|
+
vout: params.identityOutput.vout,
|
|
34638
|
+
value: 0n,
|
|
34639
|
+
// an identity primary output carries 0 native
|
|
34640
|
+
script: params.identityOutput.script
|
|
34641
|
+
};
|
|
34642
|
+
return buildOffer({ wif: params.wif, commitment, want: params.want, expiryHeight: params.expiryHeight }, network);
|
|
34643
|
+
}
|
|
34644
|
+
function completeSellIdentityOffer(params, network) {
|
|
34645
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34646
|
+
const systemId = NETWORK_CONFIG[network].chainId;
|
|
34647
|
+
const wantingNative = params.want.currency === systemId;
|
|
34648
|
+
if (params.want.amount <= 0n) {
|
|
34649
|
+
throw new TransactionBuildError("completeSellIdentityOffer: want.amount must be positive");
|
|
34650
|
+
}
|
|
34651
|
+
if (params.newPrimaryAddresses.length === 0) {
|
|
34652
|
+
throw new TransactionBuildError("completeSellIdentityOffer: newPrimaryAddresses must not be empty");
|
|
34653
|
+
}
|
|
34654
|
+
const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
34655
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
34656
|
+
throw new TransactionBuildError("completeSellIdentityOffer: expected a maker offer partial (1 input, 1 output)");
|
|
34657
|
+
}
|
|
34658
|
+
tx.addOutput(buildTransferredIdentity(params.identityJson, params.newPrimaryAddresses), 0);
|
|
34659
|
+
const wantedTokenReq = wantingNative ? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map([[params.want.currency, params.want.amount]]);
|
|
34660
|
+
const requiredNative = wantingNative ? params.want.amount : 0n;
|
|
34661
|
+
const selection = selectUtxos(
|
|
34662
|
+
params.takerUtxos,
|
|
34663
|
+
requiredNative,
|
|
34664
|
+
wantedTokenReq,
|
|
34665
|
+
3,
|
|
34666
|
+
systemId,
|
|
34667
|
+
void 0,
|
|
34668
|
+
true,
|
|
34669
|
+
150
|
|
34670
|
+
);
|
|
34671
|
+
const takerInputs = [];
|
|
34672
|
+
for (const u of selection.selected) {
|
|
34673
|
+
const idx = tx.addInput(Buffer.from(u.txid, "hex").reverse(), u.outputIndex, 4294967295);
|
|
34674
|
+
takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, "hex"), value: u.satoshis });
|
|
34675
|
+
}
|
|
34676
|
+
const hasTokenChange = selection.currencyChanges.size > 0;
|
|
34677
|
+
if (hasTokenChange || selection.nativeChange > 0n) {
|
|
34678
|
+
if (hasTokenChange) {
|
|
34679
|
+
const change = buildTokenChangeOutput(parseAddress(params.changeAddress, "changeAddress"), selection.currencyChanges);
|
|
34680
|
+
tx.addOutput(change.script, toSafeNumber(selection.nativeChange));
|
|
34681
|
+
} else {
|
|
34682
|
+
tx.addOutput(nativePaymentScript2(params.changeAddress), toSafeNumber(selection.nativeChange));
|
|
34683
|
+
}
|
|
34684
|
+
}
|
|
34685
|
+
assertTokenConservation(selection.selected, wantedTokenReq, selection.currencyChanges, systemId, "takeSellIdentityOffer");
|
|
34686
|
+
const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
|
|
34687
|
+
assertNativeConservation([{ satoshis: takerNativeIn }], tx.outs, selection.fee, "takeSellIdentityOffer");
|
|
34688
|
+
const { signedTx, txid } = signTakerInputs(tx.toHex(), takerInputs, params.wif, network);
|
|
34689
|
+
return { swapTx: signedTx, txid };
|
|
34690
|
+
}
|
|
34691
|
+
function buildBuyIdentityOffer(params, network) {
|
|
34692
|
+
assertExpiryHeight(params.expiryHeight);
|
|
34693
|
+
if (params.buyerPrimaryAddresses.length === 0) {
|
|
34694
|
+
throw new TransactionBuildError("buildBuyIdentityOffer: buyerPrimaryAddresses must not be empty");
|
|
34695
|
+
}
|
|
34696
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34697
|
+
const wantedScript = buildTransferredIdentity(params.identityJson, params.buyerPrimaryAddresses);
|
|
34698
|
+
const txb = new import_utxo_lib.TransactionBuilder(verusNetwork);
|
|
34699
|
+
txb.setVersion(4);
|
|
34700
|
+
txb.setExpiryHeight(resolveExpiryHeight(params.expiryHeight));
|
|
34701
|
+
txb.setVersionGroupId(VERSION_GROUP_ID);
|
|
34702
|
+
txb.addInput(
|
|
34703
|
+
Buffer.from(params.commitment.txid, "hex").reverse(),
|
|
34704
|
+
params.commitment.vout,
|
|
34705
|
+
4294967295,
|
|
34706
|
+
Buffer.from(params.commitment.script, "hex")
|
|
34707
|
+
);
|
|
34708
|
+
txb.addOutput(wantedScript, 0);
|
|
34709
|
+
const { signedTx, txid } = signOfferInput(
|
|
34710
|
+
txb.buildIncomplete().toHex(),
|
|
34711
|
+
0,
|
|
34712
|
+
Buffer.from(params.commitment.script, "hex"),
|
|
34713
|
+
params.commitment.value,
|
|
34714
|
+
params.wif,
|
|
34715
|
+
network
|
|
34716
|
+
);
|
|
34717
|
+
return { offerTx: signedTx, txid };
|
|
34718
|
+
}
|
|
34719
|
+
function completeBuyIdentityOffer(params, network) {
|
|
34720
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34721
|
+
const systemId = NETWORK_CONFIG[network].chainId;
|
|
34722
|
+
const offeringNative = params.offered.currency === systemId;
|
|
34723
|
+
if (params.offered.amount <= 0n) {
|
|
34724
|
+
throw new TransactionBuildError("completeBuyIdentityOffer: offered.amount must be positive");
|
|
34725
|
+
}
|
|
34726
|
+
const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
34727
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
34728
|
+
throw new TransactionBuildError("completeBuyIdentityOffer: expected a maker offer partial (1 input, 1 output)");
|
|
34729
|
+
}
|
|
34730
|
+
const commitmentNative = offeringNative ? params.offered.amount : 0n;
|
|
34731
|
+
const idIdx = tx.addInput(
|
|
34732
|
+
Buffer.from(params.identityOutput.txid, "hex").reverse(),
|
|
34733
|
+
params.identityOutput.vout,
|
|
34734
|
+
4294967295
|
|
34735
|
+
);
|
|
34736
|
+
const takerInputs = [
|
|
34737
|
+
{ index: idIdx, prevOutScript: Buffer.from(params.identityOutput.script, "hex"), value: 0n }
|
|
34738
|
+
];
|
|
34739
|
+
if (offeringNative) {
|
|
34740
|
+
tx.addOutput(nativePaymentScript2(params.sellerReceiveAddress), toSafeNumber(params.offered.amount));
|
|
34741
|
+
} else {
|
|
34742
|
+
const out = buildTokenChangeOutput(
|
|
34743
|
+
parseAddress(params.sellerReceiveAddress, "sellerReceiveAddress"),
|
|
34744
|
+
/* @__PURE__ */ new Map([[params.offered.currency, params.offered.amount]])
|
|
34745
|
+
);
|
|
34746
|
+
tx.addOutput(out.script, 0);
|
|
34747
|
+
}
|
|
34748
|
+
return fundFeeAndSignIdentityTaker({
|
|
34749
|
+
tx,
|
|
34750
|
+
priorInputs: takerInputs,
|
|
34751
|
+
extraInputNative: commitmentNative,
|
|
34752
|
+
takerUtxos: params.takerUtxos,
|
|
34753
|
+
changeAddress: params.changeAddress,
|
|
34754
|
+
wif: params.wif,
|
|
34755
|
+
network,
|
|
34756
|
+
label: "takeBuyIdentityOffer",
|
|
34757
|
+
extraOutputBytes: 300
|
|
34758
|
+
});
|
|
34759
|
+
}
|
|
34760
|
+
function buildSwapIdentityOffer(params, network) {
|
|
34761
|
+
if (params.makerPrimaryAddresses.length === 0) {
|
|
34762
|
+
throw new TransactionBuildError("buildSwapIdentityOffer: makerPrimaryAddresses must not be empty");
|
|
34763
|
+
}
|
|
34764
|
+
return buildBuyIdentityOffer(
|
|
34765
|
+
{
|
|
34766
|
+
wif: params.wif,
|
|
34767
|
+
commitment: {
|
|
34768
|
+
txid: params.offeredIdentityOutput.txid,
|
|
34769
|
+
vout: params.offeredIdentityOutput.vout,
|
|
34770
|
+
value: 0n,
|
|
34771
|
+
// an identity primary output carries 0 native
|
|
34772
|
+
script: params.offeredIdentityOutput.script
|
|
34773
|
+
},
|
|
34774
|
+
identityJson: params.wantedIdentityJson,
|
|
34775
|
+
buyerPrimaryAddresses: params.makerPrimaryAddresses,
|
|
34776
|
+
expiryHeight: params.expiryHeight
|
|
34777
|
+
},
|
|
34778
|
+
network
|
|
34779
|
+
);
|
|
34780
|
+
}
|
|
34781
|
+
function completeSwapIdentityOffer(params, network) {
|
|
34782
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
34783
|
+
if (params.takerPrimaryAddresses.length === 0) {
|
|
34784
|
+
throw new TransactionBuildError("completeSwapIdentityOffer: takerPrimaryAddresses must not be empty");
|
|
34785
|
+
}
|
|
34786
|
+
const tx = import_utxo_lib.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
34787
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
34788
|
+
throw new TransactionBuildError("completeSwapIdentityOffer: expected a maker offer partial (1 input, 1 output)");
|
|
34789
|
+
}
|
|
34790
|
+
tx.addOutput(buildTransferredIdentity(params.offeredIdentityJson, params.takerPrimaryAddresses), 0);
|
|
34791
|
+
const idIdx = tx.addInput(
|
|
34792
|
+
Buffer.from(params.wantedIdentityOutput.txid, "hex").reverse(),
|
|
34793
|
+
params.wantedIdentityOutput.vout,
|
|
34794
|
+
4294967295
|
|
34795
|
+
);
|
|
34796
|
+
const takerInputs = [
|
|
34797
|
+
{ index: idIdx, prevOutScript: Buffer.from(params.wantedIdentityOutput.script, "hex"), value: 0n }
|
|
34798
|
+
];
|
|
34799
|
+
return fundFeeAndSignIdentityTaker({
|
|
34800
|
+
tx,
|
|
34801
|
+
priorInputs: takerInputs,
|
|
34802
|
+
extraInputNative: 0n,
|
|
34803
|
+
takerUtxos: params.takerUtxos,
|
|
34804
|
+
changeAddress: params.changeAddress,
|
|
34805
|
+
wif: params.wif,
|
|
34806
|
+
network,
|
|
34807
|
+
label: "takeSwapIdentityOffer",
|
|
34808
|
+
extraOutputBytes: 500
|
|
34809
|
+
});
|
|
34810
|
+
}
|
|
34811
|
+
|
|
34350
34812
|
// src/VerusSDK.ts
|
|
34351
34813
|
var VerusSDK = class {
|
|
34352
34814
|
constructor(config) {
|
|
@@ -34468,6 +34930,52 @@ var VerusSDK = class {
|
|
|
34468
34930
|
verifyMessage(params) {
|
|
34469
34931
|
return verifyMessage(params, this.network);
|
|
34470
34932
|
}
|
|
34933
|
+
// ─── Marketplace Offers (atomic swaps) ─────────────
|
|
34934
|
+
/**
|
|
34935
|
+
* Maker step 1 (currency offers only): fund the OFFERED asset into a commitment
|
|
34936
|
+
* output. Broadcast the returned tx, then pass `commitment` to `buildOffer`.
|
|
34937
|
+
*/
|
|
34938
|
+
buildOfferFunding(params) {
|
|
34939
|
+
return buildOfferFunding(params, this.network);
|
|
34940
|
+
}
|
|
34941
|
+
/**
|
|
34942
|
+
* Maker step 2 (currency offers): build the half-signed offer — spend the funded
|
|
34943
|
+
* commitment with 0x83, committing to the single WANTED output paid to the maker.
|
|
34944
|
+
*/
|
|
34945
|
+
buildOffer(params) {
|
|
34946
|
+
return buildOffer(params, this.network);
|
|
34947
|
+
}
|
|
34948
|
+
/**
|
|
34949
|
+
* Taker (currency offers): complete the maker's offer — pay the wanted asset,
|
|
34950
|
+
* receive the offered asset, and sign the taker's side into an atomic swap.
|
|
34951
|
+
*/
|
|
34952
|
+
completeOffer(params) {
|
|
34953
|
+
return completeOffer(params, this.network);
|
|
34954
|
+
}
|
|
34955
|
+
/** Maker: offer a VerusID for a currency (spends the identity's on-chain output). */
|
|
34956
|
+
buildSellIdentityOffer(params) {
|
|
34957
|
+
return buildSellIdentityOffer(params, this.network);
|
|
34958
|
+
}
|
|
34959
|
+
/** Taker: complete a sell-identity offer — pay the currency, receive the identity. */
|
|
34960
|
+
completeSellIdentityOffer(params) {
|
|
34961
|
+
return completeSellIdentityOffer(params, this.network);
|
|
34962
|
+
}
|
|
34963
|
+
/** Maker: offer a currency for a VerusID (funds the currency into a commitment). */
|
|
34964
|
+
buildBuyIdentityOffer(params) {
|
|
34965
|
+
return buildBuyIdentityOffer(params, this.network);
|
|
34966
|
+
}
|
|
34967
|
+
/** Taker (identity owner): complete a buy-identity offer — give up the identity, take the currency. */
|
|
34968
|
+
completeBuyIdentityOffer(params) {
|
|
34969
|
+
return completeBuyIdentityOffer(params, this.network);
|
|
34970
|
+
}
|
|
34971
|
+
/** Maker: offer a VerusID for another VerusID (no currency moves). */
|
|
34972
|
+
buildSwapIdentityOffer(params) {
|
|
34973
|
+
return buildSwapIdentityOffer(params, this.network);
|
|
34974
|
+
}
|
|
34975
|
+
/** Taker (owns the wanted identity): complete an identity swap — funds only the miner fee. */
|
|
34976
|
+
completeSwapIdentityOffer(params) {
|
|
34977
|
+
return completeSwapIdentityOffer(params, this.network);
|
|
34978
|
+
}
|
|
34471
34979
|
// ─── Static Utilities ─────────────────────────────
|
|
34472
34980
|
/** Derive R-address from WIF private key */
|
|
34473
34981
|
static async deriveAddress(wif) {
|
|
@@ -34516,8 +35024,8 @@ function isIdentityName(input) {
|
|
|
34516
35024
|
}
|
|
34517
35025
|
|
|
34518
35026
|
// src/identity/public.ts
|
|
34519
|
-
var
|
|
34520
|
-
__export(
|
|
35027
|
+
var public_exports2 = {};
|
|
35028
|
+
__export(public_exports2, {
|
|
34521
35029
|
buildAndSignCommitment: () => buildAndSignCommitment,
|
|
34522
35030
|
buildAndSignIdentityUpdate: () => buildAndSignIdentityUpdate,
|
|
34523
35031
|
buildAndSignRegistration: () => buildAndSignRegistration,
|
|
@@ -34568,6 +35076,7 @@ __export(public_exports, {
|
|
|
34568
35076
|
isVerusAddress,
|
|
34569
35077
|
keys,
|
|
34570
35078
|
message,
|
|
35079
|
+
offers,
|
|
34571
35080
|
parseSats,
|
|
34572
35081
|
signing,
|
|
34573
35082
|
toCoins,
|