@chainvue/verus-sdk 0.13.0 → 0.14.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 +21 -8
- package/dist/VerusSDK.d.ts +34 -1
- package/dist/VerusSDK.d.ts.map +1 -1
- package/dist/VerusSDK.js +38 -1
- package/dist/VerusSDK.js.map +1 -1
- package/dist/bundle.js +1009 -122
- package/dist/currency/definition.d.ts +181 -0
- package/dist/currency/definition.d.ts.map +1 -0
- package/dist/currency/definition.js +396 -0
- package/dist/currency/definition.js.map +1 -0
- package/dist/currency/index.d.ts +17 -7
- package/dist/currency/index.d.ts.map +1 -1
- package/dist/currency/index.js +32 -9
- package/dist/currency/index.js.map +1 -1
- package/dist/currency/launch.d.ts +43 -0
- package/dist/currency/launch.d.ts.map +1 -0
- package/dist/currency/launch.js +96 -0
- package/dist/currency/launch.js.map +1 -0
- package/dist/currency/outputs.d.ts +40 -0
- package/dist/currency/outputs.d.ts.map +1 -0
- package/dist/currency/outputs.js +296 -0
- package/dist/currency/outputs.js.map +1 -0
- package/dist/currency/reserveTransfer.d.ts +36 -0
- package/dist/currency/reserveTransfer.d.ts.map +1 -0
- package/dist/currency/reserveTransfer.js +104 -0
- package/dist/currency/reserveTransfer.js.map +1 -0
- package/dist/currency/wire.d.ts +76 -0
- package/dist/currency/wire.d.ts.map +1 -0
- package/dist/currency/wire.js +252 -0
- package/dist/currency/wire.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/transfer/index.d.ts.map +1 -1
- package/dist/transfer/index.js +38 -14
- package/dist/transfer/index.js.map +1 -1
- package/dist/types/index.d.ts +27 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
package/dist/bundle.js
CHANGED
|
@@ -6562,7 +6562,7 @@ var require_TransferDestination = __commonJS({
|
|
|
6562
6562
|
exports2.FLAG_DEST_AUX = new bn_js_1.BN(64, 10);
|
|
6563
6563
|
exports2.FLAG_DEST_GATEWAY = new bn_js_1.BN(128, 10);
|
|
6564
6564
|
exports2.FLAG_MASK = exports2.FLAG_DEST_AUX.add(exports2.FLAG_DEST_GATEWAY);
|
|
6565
|
-
var
|
|
6565
|
+
var TransferDestination4 = class _TransferDestination {
|
|
6566
6566
|
constructor(data) {
|
|
6567
6567
|
this.type = exports2.DEST_INVALID;
|
|
6568
6568
|
this.destination_bytes = Buffer.alloc(0);
|
|
@@ -6764,7 +6764,7 @@ var require_TransferDestination = __commonJS({
|
|
|
6764
6764
|
return retVal;
|
|
6765
6765
|
}
|
|
6766
6766
|
};
|
|
6767
|
-
exports2.TransferDestination =
|
|
6767
|
+
exports2.TransferDestination = TransferDestination4;
|
|
6768
6768
|
}
|
|
6769
6769
|
});
|
|
6770
6770
|
|
|
@@ -6955,7 +6955,7 @@ var require_CurrencyValueMap = __commonJS({
|
|
|
6955
6955
|
var vdxf_1 = require_vdxf();
|
|
6956
6956
|
var { BufferReader, BufferWriter } = bufferutils_1.default;
|
|
6957
6957
|
var numberConversion_1 = require_numberConversion();
|
|
6958
|
-
var
|
|
6958
|
+
var CurrencyValueMap3 = class _CurrencyValueMap {
|
|
6959
6959
|
constructor(data = {}) {
|
|
6960
6960
|
this.value_map = new Map(data.value_map || []);
|
|
6961
6961
|
this.multivalue = !!data.multivalue;
|
|
@@ -7044,7 +7044,7 @@ var require_CurrencyValueMap = __commonJS({
|
|
|
7044
7044
|
return new _CurrencyValueMap({ value_map, multivalue });
|
|
7045
7045
|
}
|
|
7046
7046
|
};
|
|
7047
|
-
exports2.CurrencyValueMap =
|
|
7047
|
+
exports2.CurrencyValueMap = CurrencyValueMap3;
|
|
7048
7048
|
}
|
|
7049
7049
|
});
|
|
7050
7050
|
|
|
@@ -7056,7 +7056,7 @@ var require_KeyID = __commonJS({
|
|
|
7056
7056
|
exports2.KeyID = void 0;
|
|
7057
7057
|
var vdxf_1 = require_vdxf();
|
|
7058
7058
|
var Hash160_1 = require_Hash160();
|
|
7059
|
-
var
|
|
7059
|
+
var KeyID3 = class _KeyID extends Hash160_1.Hash160SerEnt {
|
|
7060
7060
|
constructor(hash = Buffer.alloc(0)) {
|
|
7061
7061
|
super(hash, vdxf_1.R_ADDR_VERSION, false);
|
|
7062
7062
|
}
|
|
@@ -7069,7 +7069,7 @@ var require_KeyID = __commonJS({
|
|
|
7069
7069
|
return new _KeyID(Hash160_1.Hash160SerEnt.fromAddress(address2, false).hash);
|
|
7070
7070
|
}
|
|
7071
7071
|
};
|
|
7072
|
-
exports2.KeyID =
|
|
7072
|
+
exports2.KeyID = KeyID3;
|
|
7073
7073
|
}
|
|
7074
7074
|
});
|
|
7075
7075
|
|
|
@@ -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 Identity7 = 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 = 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);
|
|
9970
9970
|
}
|
|
9971
9971
|
});
|
|
9972
9972
|
|
|
@@ -10072,7 +10072,7 @@ var require_ReserveTransfer = __commonJS({
|
|
|
10072
10072
|
type: TransferDestination_1.DEST_PKH,
|
|
10073
10073
|
destination_bytes: (0, address_1.fromBase58Check)("RTqQe58LSj2yr5CrwYFwcsAQ1edQwmrkUU").hash
|
|
10074
10074
|
});
|
|
10075
|
-
var
|
|
10075
|
+
var ReserveTransfer3 = class extends TokenOutput_1.TokenOutput {
|
|
10076
10076
|
constructor(data) {
|
|
10077
10077
|
super(data);
|
|
10078
10078
|
this.flags = exports2.RESERVE_TRANSFER_INVALID;
|
|
@@ -10194,7 +10194,7 @@ var require_ReserveTransfer = __commonJS({
|
|
|
10194
10194
|
return reader.offset;
|
|
10195
10195
|
}
|
|
10196
10196
|
};
|
|
10197
|
-
exports2.ReserveTransfer =
|
|
10197
|
+
exports2.ReserveTransfer = ReserveTransfer3;
|
|
10198
10198
|
}
|
|
10199
10199
|
});
|
|
10200
10200
|
|
|
@@ -10594,7 +10594,7 @@ var require_PubKey = __commonJS({
|
|
|
10594
10594
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
10595
10595
|
exports2.PubKey = void 0;
|
|
10596
10596
|
var bufferutils_1 = require_bufferutils();
|
|
10597
|
-
var
|
|
10597
|
+
var PubKey2 = class _PubKey {
|
|
10598
10598
|
constructor(bytes = Buffer.alloc(0), compressed = true) {
|
|
10599
10599
|
this.bytes = bytes;
|
|
10600
10600
|
this.compressed = compressed;
|
|
@@ -10616,9 +10616,9 @@ var require_PubKey = __commonJS({
|
|
|
10616
10616
|
return writer.buffer;
|
|
10617
10617
|
}
|
|
10618
10618
|
};
|
|
10619
|
-
exports2.PubKey =
|
|
10620
|
-
|
|
10621
|
-
|
|
10619
|
+
exports2.PubKey = PubKey2;
|
|
10620
|
+
PubKey2.PUBLIC_KEY_SIZE = 65;
|
|
10621
|
+
PubKey2.COMPRESSED_PUBLIC_KEY_SIZE = 33;
|
|
10622
10622
|
}
|
|
10623
10623
|
});
|
|
10624
10624
|
|
|
@@ -10667,7 +10667,7 @@ var require_TxDestination = __commonJS({
|
|
|
10667
10667
|
var PubKey_1 = require_PubKey();
|
|
10668
10668
|
var UnknownID_1 = require_UnknownID();
|
|
10669
10669
|
var { BufferReader, BufferWriter } = bufferutils_1.default;
|
|
10670
|
-
var
|
|
10670
|
+
var TxDestination3 = class _TxDestination {
|
|
10671
10671
|
constructor(data = new NoDestination_1.NoDestination(), type) {
|
|
10672
10672
|
this.data = data;
|
|
10673
10673
|
if (!type) {
|
|
@@ -10752,15 +10752,15 @@ var require_TxDestination = __commonJS({
|
|
|
10752
10752
|
return Buffer.from(this.toBuffer().subarray(varuint_1.default.encodingLength(this.data.toBuffer().length)));
|
|
10753
10753
|
}
|
|
10754
10754
|
};
|
|
10755
|
-
exports2.TxDestination =
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10755
|
+
exports2.TxDestination = TxDestination3;
|
|
10756
|
+
TxDestination3.TYPE_INVALID = new bn_js_1.BN(0, 10);
|
|
10757
|
+
TxDestination3.TYPE_PK = new bn_js_1.BN(1, 10);
|
|
10758
|
+
TxDestination3.TYPE_PKH = new bn_js_1.BN(2, 10);
|
|
10759
|
+
TxDestination3.TYPE_SH = new bn_js_1.BN(3, 10);
|
|
10760
|
+
TxDestination3.TYPE_ID = new bn_js_1.BN(4, 10);
|
|
10761
|
+
TxDestination3.TYPE_INDEX = new bn_js_1.BN(5, 10);
|
|
10762
|
+
TxDestination3.TYPE_QUANTUM = new bn_js_1.BN(6, 10);
|
|
10763
|
+
TxDestination3.TYPE_LAST = new bn_js_1.BN(6, 10);
|
|
10764
10764
|
}
|
|
10765
10765
|
});
|
|
10766
10766
|
|
|
@@ -10776,7 +10776,7 @@ var require_OptCCParams = __commonJS({
|
|
|
10776
10776
|
var TxDestination_1 = require_TxDestination();
|
|
10777
10777
|
var bn_js_1 = require("bn.js");
|
|
10778
10778
|
var bufferutils_1 = require_bufferutils();
|
|
10779
|
-
var
|
|
10779
|
+
var OptCCParams3 = class _OptCCParams {
|
|
10780
10780
|
constructor(data) {
|
|
10781
10781
|
if (data === null || data === void 0 ? void 0 : data.version)
|
|
10782
10782
|
this.version = data.version;
|
|
@@ -10952,7 +10952,7 @@ var require_OptCCParams = __commonJS({
|
|
|
10952
10952
|
return this.internalToBuffer(false);
|
|
10953
10953
|
}
|
|
10954
10954
|
};
|
|
10955
|
-
exports2.OptCCParams =
|
|
10955
|
+
exports2.OptCCParams = OptCCParams3;
|
|
10956
10956
|
}
|
|
10957
10957
|
});
|
|
10958
10958
|
|
|
@@ -20501,10 +20501,10 @@ var require_tx_destination = __commonJS({
|
|
|
20501
20501
|
"node_modules/.pnpm/@bitgo+utxo-lib@https+++codeload.github.com+VerusCoin+BitGoJS+tar.gz+9701df63b479984f27_7b6d2dd0c6d9d9555ac626a4a148d56a/node_modules/@bitgo/utxo-lib/dist/src/tx_destination.js"(exports2, module2) {
|
|
20502
20502
|
"use strict";
|
|
20503
20503
|
var varuint = require_varuint_bitcoin();
|
|
20504
|
-
var
|
|
20504
|
+
var TxDestination3 = (
|
|
20505
20505
|
/** @class */
|
|
20506
20506
|
(function() {
|
|
20507
|
-
function
|
|
20507
|
+
function TxDestination4(destType, destinationBytes) {
|
|
20508
20508
|
if (destType === void 0) {
|
|
20509
20509
|
destType = this.typePKH;
|
|
20510
20510
|
}
|
|
@@ -20514,115 +20514,115 @@ var require_tx_destination = __commonJS({
|
|
|
20514
20514
|
this.destType = destType;
|
|
20515
20515
|
this.destinationBytes = destinationBytes;
|
|
20516
20516
|
}
|
|
20517
|
-
Object.defineProperty(
|
|
20517
|
+
Object.defineProperty(TxDestination4.prototype, "typeInvalid", {
|
|
20518
20518
|
get: function() {
|
|
20519
|
-
return
|
|
20519
|
+
return TxDestination4.TYPE_INVALID;
|
|
20520
20520
|
},
|
|
20521
20521
|
enumerable: false,
|
|
20522
20522
|
configurable: true
|
|
20523
20523
|
});
|
|
20524
|
-
Object.defineProperty(
|
|
20524
|
+
Object.defineProperty(TxDestination4.prototype, "typePK", {
|
|
20525
20525
|
get: function() {
|
|
20526
|
-
return
|
|
20526
|
+
return TxDestination4.TYPE_PK;
|
|
20527
20527
|
},
|
|
20528
20528
|
enumerable: false,
|
|
20529
20529
|
configurable: true
|
|
20530
20530
|
});
|
|
20531
|
-
Object.defineProperty(
|
|
20531
|
+
Object.defineProperty(TxDestination4.prototype, "isPK", {
|
|
20532
20532
|
get: function() {
|
|
20533
20533
|
return this.destType === this.typePK;
|
|
20534
20534
|
},
|
|
20535
20535
|
enumerable: false,
|
|
20536
20536
|
configurable: true
|
|
20537
20537
|
});
|
|
20538
|
-
Object.defineProperty(
|
|
20538
|
+
Object.defineProperty(TxDestination4.prototype, "typePKH", {
|
|
20539
20539
|
get: function() {
|
|
20540
|
-
return
|
|
20540
|
+
return TxDestination4.TYPE_PKH;
|
|
20541
20541
|
},
|
|
20542
20542
|
enumerable: false,
|
|
20543
20543
|
configurable: true
|
|
20544
20544
|
});
|
|
20545
|
-
Object.defineProperty(
|
|
20545
|
+
Object.defineProperty(TxDestination4.prototype, "isPKH", {
|
|
20546
20546
|
get: function() {
|
|
20547
20547
|
return this.destType === this.typePKH;
|
|
20548
20548
|
},
|
|
20549
20549
|
enumerable: false,
|
|
20550
20550
|
configurable: true
|
|
20551
20551
|
});
|
|
20552
|
-
Object.defineProperty(
|
|
20552
|
+
Object.defineProperty(TxDestination4.prototype, "typeSH", {
|
|
20553
20553
|
get: function() {
|
|
20554
|
-
return
|
|
20554
|
+
return TxDestination4.TYPE_SH;
|
|
20555
20555
|
},
|
|
20556
20556
|
enumerable: false,
|
|
20557
20557
|
configurable: true
|
|
20558
20558
|
});
|
|
20559
|
-
Object.defineProperty(
|
|
20559
|
+
Object.defineProperty(TxDestination4.prototype, "isSH", {
|
|
20560
20560
|
get: function() {
|
|
20561
20561
|
return this.destType === this.typeSH;
|
|
20562
20562
|
},
|
|
20563
20563
|
enumerable: false,
|
|
20564
20564
|
configurable: true
|
|
20565
20565
|
});
|
|
20566
|
-
Object.defineProperty(
|
|
20566
|
+
Object.defineProperty(TxDestination4.prototype, "typeID", {
|
|
20567
20567
|
get: function() {
|
|
20568
|
-
return
|
|
20568
|
+
return TxDestination4.TYPE_ID;
|
|
20569
20569
|
},
|
|
20570
20570
|
enumerable: false,
|
|
20571
20571
|
configurable: true
|
|
20572
20572
|
});
|
|
20573
|
-
Object.defineProperty(
|
|
20573
|
+
Object.defineProperty(TxDestination4.prototype, "isID", {
|
|
20574
20574
|
get: function() {
|
|
20575
20575
|
return this.destType === this.typeID;
|
|
20576
20576
|
},
|
|
20577
20577
|
enumerable: false,
|
|
20578
20578
|
configurable: true
|
|
20579
20579
|
});
|
|
20580
|
-
Object.defineProperty(
|
|
20580
|
+
Object.defineProperty(TxDestination4.prototype, "typeIndex", {
|
|
20581
20581
|
get: function() {
|
|
20582
|
-
return
|
|
20582
|
+
return TxDestination4.TYPE_INDEX;
|
|
20583
20583
|
},
|
|
20584
20584
|
enumerable: false,
|
|
20585
20585
|
configurable: true
|
|
20586
20586
|
});
|
|
20587
|
-
Object.defineProperty(
|
|
20587
|
+
Object.defineProperty(TxDestination4.prototype, "isIndex", {
|
|
20588
20588
|
get: function() {
|
|
20589
20589
|
return this.destType === this.typeIndex;
|
|
20590
20590
|
},
|
|
20591
20591
|
enumerable: false,
|
|
20592
20592
|
configurable: true
|
|
20593
20593
|
});
|
|
20594
|
-
Object.defineProperty(
|
|
20594
|
+
Object.defineProperty(TxDestination4.prototype, "typeQuantum", {
|
|
20595
20595
|
get: function() {
|
|
20596
|
-
return
|
|
20596
|
+
return TxDestination4.TYPE_QUANTUM;
|
|
20597
20597
|
},
|
|
20598
20598
|
enumerable: false,
|
|
20599
20599
|
configurable: true
|
|
20600
20600
|
});
|
|
20601
|
-
Object.defineProperty(
|
|
20601
|
+
Object.defineProperty(TxDestination4.prototype, "isQuantum", {
|
|
20602
20602
|
get: function() {
|
|
20603
20603
|
return this.destType === this.typeQuantum;
|
|
20604
20604
|
},
|
|
20605
20605
|
enumerable: false,
|
|
20606
20606
|
configurable: true
|
|
20607
20607
|
});
|
|
20608
|
-
Object.defineProperty(
|
|
20608
|
+
Object.defineProperty(TxDestination4.prototype, "typeLast", {
|
|
20609
20609
|
get: function() {
|
|
20610
|
-
return
|
|
20610
|
+
return TxDestination4.TYPE_QUANTUM;
|
|
20611
20611
|
},
|
|
20612
20612
|
enumerable: false,
|
|
20613
20613
|
configurable: true
|
|
20614
20614
|
});
|
|
20615
|
-
|
|
20615
|
+
TxDestination4.prototype.isValid = function() {
|
|
20616
20616
|
return this.destType > this.typeInvalid && this.destType <= this.typeLast && this.destinationBytes && this.destinationBytes.length;
|
|
20617
20617
|
};
|
|
20618
|
-
|
|
20618
|
+
TxDestination4.fromChunk = function(chunk) {
|
|
20619
20619
|
var prefix = Buffer.alloc(1);
|
|
20620
20620
|
prefix.writeUInt8(chunk.length, 0);
|
|
20621
|
-
var dest = new
|
|
20621
|
+
var dest = new TxDestination4();
|
|
20622
20622
|
dest.fromBuffer(Buffer.concat([prefix, chunk]));
|
|
20623
20623
|
return dest;
|
|
20624
20624
|
};
|
|
20625
|
-
|
|
20625
|
+
TxDestination4.prototype.fromBuffer = function(buffer, initialOffset) {
|
|
20626
20626
|
if (initialOffset === void 0) {
|
|
20627
20627
|
initialOffset = 0;
|
|
20628
20628
|
}
|
|
@@ -20652,7 +20652,7 @@ var require_tx_destination = __commonJS({
|
|
|
20652
20652
|
}
|
|
20653
20653
|
return offset;
|
|
20654
20654
|
};
|
|
20655
|
-
|
|
20655
|
+
TxDestination4.prototype.__byteLength = function() {
|
|
20656
20656
|
if (this.destType === this.typePKH) {
|
|
20657
20657
|
return 21;
|
|
20658
20658
|
} else if (this.destType === this.typePK) {
|
|
@@ -20661,10 +20661,10 @@ var require_tx_destination = __commonJS({
|
|
|
20661
20661
|
return varuint.encodingLength(this.destinationBytes.length + 1) + this.destinationBytes.length + 1;
|
|
20662
20662
|
}
|
|
20663
20663
|
};
|
|
20664
|
-
|
|
20664
|
+
TxDestination4.prototype.toChunk = function() {
|
|
20665
20665
|
return this.toBuffer().slice(1);
|
|
20666
20666
|
};
|
|
20667
|
-
|
|
20667
|
+
TxDestination4.prototype.toBuffer = function(buffer, initialOffset) {
|
|
20668
20668
|
if (!buffer)
|
|
20669
20669
|
buffer = Buffer.allocUnsafe(this.__byteLength());
|
|
20670
20670
|
var offset = initialOffset || 0;
|
|
@@ -20701,17 +20701,17 @@ var require_tx_destination = __commonJS({
|
|
|
20701
20701
|
return buffer.slice(initialOffset, offset);
|
|
20702
20702
|
return buffer.slice(0, offset);
|
|
20703
20703
|
};
|
|
20704
|
-
|
|
20705
|
-
|
|
20706
|
-
|
|
20707
|
-
|
|
20708
|
-
|
|
20709
|
-
|
|
20710
|
-
|
|
20711
|
-
return
|
|
20704
|
+
TxDestination4.TYPE_INVALID = 0;
|
|
20705
|
+
TxDestination4.TYPE_PK = 1;
|
|
20706
|
+
TxDestination4.TYPE_PKH = 2;
|
|
20707
|
+
TxDestination4.TYPE_SH = 3;
|
|
20708
|
+
TxDestination4.TYPE_ID = 4;
|
|
20709
|
+
TxDestination4.TYPE_INDEX = 5;
|
|
20710
|
+
TxDestination4.TYPE_QUANTUM = 6;
|
|
20711
|
+
return TxDestination4;
|
|
20712
20712
|
})()
|
|
20713
20713
|
);
|
|
20714
|
-
module2.exports =
|
|
20714
|
+
module2.exports = TxDestination3;
|
|
20715
20715
|
}
|
|
20716
20716
|
});
|
|
20717
20717
|
|
|
@@ -20879,16 +20879,16 @@ var require_optccparams = __commonJS({
|
|
|
20879
20879
|
var bscript = require_script2();
|
|
20880
20880
|
var EVALS2 = require_evals2();
|
|
20881
20881
|
var varuint = require_varuint_bitcoin();
|
|
20882
|
-
var
|
|
20882
|
+
var TxDestination3 = require_tx_destination();
|
|
20883
20883
|
var bufferutils = require_bufferutils2();
|
|
20884
20884
|
function varSliceSize(varSlice) {
|
|
20885
20885
|
var length = varSlice.length;
|
|
20886
20886
|
return varuint.encodingLength(length) + length;
|
|
20887
20887
|
}
|
|
20888
|
-
var
|
|
20888
|
+
var OptCCParams3 = (
|
|
20889
20889
|
/** @class */
|
|
20890
20890
|
(function() {
|
|
20891
|
-
function
|
|
20891
|
+
function OptCCParams4(version, evalCode, m, n, destinations, serializedObjects) {
|
|
20892
20892
|
if (version === void 0) {
|
|
20893
20893
|
version = 3;
|
|
20894
20894
|
}
|
|
@@ -20915,7 +20915,7 @@ var require_optccparams = __commonJS({
|
|
|
20915
20915
|
this.vData = serializedObjects;
|
|
20916
20916
|
this.error = null;
|
|
20917
20917
|
}
|
|
20918
|
-
|
|
20918
|
+
OptCCParams4.prototype.getParamObject = function() {
|
|
20919
20919
|
switch (this.evalCode) {
|
|
20920
20920
|
case EVALS2.EVAL_NONE: {
|
|
20921
20921
|
return null;
|
|
@@ -20949,7 +20949,7 @@ var require_optccparams = __commonJS({
|
|
|
20949
20949
|
}
|
|
20950
20950
|
}
|
|
20951
20951
|
};
|
|
20952
|
-
|
|
20952
|
+
OptCCParams4.prototype.isValid = function() {
|
|
20953
20953
|
var validEval = false;
|
|
20954
20954
|
switch (this.evalCode) {
|
|
20955
20955
|
case EVALS2.EVAL_NONE: {
|
|
@@ -20979,17 +20979,17 @@ var require_optccparams = __commonJS({
|
|
|
20979
20979
|
}
|
|
20980
20980
|
return validEval && this.version > 0 && this.version < 4 && (this.version < 3 && this.evalCode < 2 || this.evalCode <= 26 && this.m <= this.n);
|
|
20981
20981
|
};
|
|
20982
|
-
|
|
20982
|
+
OptCCParams4.fromChunk = function(chunk) {
|
|
20983
20983
|
var writer = new bufferutils.BufferWriter(Buffer.alloc(varuint.encodingLength(chunk.length)), 0);
|
|
20984
20984
|
writer.writeVarInt(chunk.length);
|
|
20985
|
-
var params = new
|
|
20985
|
+
var params = new OptCCParams4();
|
|
20986
20986
|
params.fromBuffer(Buffer.concat([writer.buffer, chunk]));
|
|
20987
20987
|
return params;
|
|
20988
20988
|
};
|
|
20989
|
-
|
|
20989
|
+
OptCCParams4.prototype.toChunk = function() {
|
|
20990
20990
|
return this.toBuffer(void 0, void 0, true);
|
|
20991
20991
|
};
|
|
20992
|
-
|
|
20992
|
+
OptCCParams4.prototype.fromBuffer = function(buffer, initialOffset) {
|
|
20993
20993
|
if (initialOffset === void 0) {
|
|
20994
20994
|
initialOffset = 0;
|
|
20995
20995
|
}
|
|
@@ -21027,7 +21027,7 @@ var require_optccparams = __commonJS({
|
|
|
21027
21027
|
this.destinations = [];
|
|
21028
21028
|
var loop;
|
|
21029
21029
|
for (loop = 1; this.version && loop < limit; loop++) {
|
|
21030
|
-
var oneDest =
|
|
21030
|
+
var oneDest = TxDestination3.fromChunk(chunks[loop]);
|
|
21031
21031
|
if (oneDest.isValid()) {
|
|
21032
21032
|
this.destinations.push(oneDest);
|
|
21033
21033
|
} else {
|
|
@@ -21041,7 +21041,7 @@ var require_optccparams = __commonJS({
|
|
|
21041
21041
|
}
|
|
21042
21042
|
return offset;
|
|
21043
21043
|
};
|
|
21044
|
-
|
|
21044
|
+
OptCCParams4.prototype.__byteLength = function() {
|
|
21045
21045
|
var chunks = [Buffer.allocUnsafe(4)];
|
|
21046
21046
|
chunks[0][0] = this.version;
|
|
21047
21047
|
chunks[0][1] = this.evalCode;
|
|
@@ -21056,7 +21056,7 @@ var require_optccparams = __commonJS({
|
|
|
21056
21056
|
});
|
|
21057
21057
|
return varSliceSize(bscript.compile(chunks));
|
|
21058
21058
|
};
|
|
21059
|
-
|
|
21059
|
+
OptCCParams4.prototype.toBuffer = function(buffer, initialOffset, asChunk) {
|
|
21060
21060
|
if (asChunk === void 0) {
|
|
21061
21061
|
asChunk = false;
|
|
21062
21062
|
}
|
|
@@ -21095,10 +21095,10 @@ var require_optccparams = __commonJS({
|
|
|
21095
21095
|
return buffer.slice(initialOffset, offset);
|
|
21096
21096
|
return buffer.slice(0, offset);
|
|
21097
21097
|
};
|
|
21098
|
-
return
|
|
21098
|
+
return OptCCParams4;
|
|
21099
21099
|
})()
|
|
21100
21100
|
);
|
|
21101
|
-
module2.exports =
|
|
21101
|
+
module2.exports = OptCCParams3;
|
|
21102
21102
|
}
|
|
21103
21103
|
});
|
|
21104
21104
|
|
|
@@ -21110,15 +21110,15 @@ var require_output8 = __commonJS({
|
|
|
21110
21110
|
var types = require_types2();
|
|
21111
21111
|
var typeforce = require_typeforce();
|
|
21112
21112
|
var OPS = require_bitcoin_ops();
|
|
21113
|
-
var
|
|
21113
|
+
var OptCCParams3 = require_optccparams();
|
|
21114
21114
|
var OP_INT_BASE = OPS.OP_RESERVED;
|
|
21115
21115
|
function check(script2) {
|
|
21116
21116
|
var chunks = bscript.decompile(script2);
|
|
21117
21117
|
if (chunks.length < 4 || !(chunks[chunks.length - 1] === OPS.OP_DROP && chunks[1] === OPS.OP_CHECKCRYPTOCONDITION)) {
|
|
21118
21118
|
return false;
|
|
21119
21119
|
}
|
|
21120
|
-
var params =
|
|
21121
|
-
var master =
|
|
21120
|
+
var params = OptCCParams3.fromChunk(chunks[2]);
|
|
21121
|
+
var master = OptCCParams3.fromChunk(chunks[0]);
|
|
21122
21122
|
if (!params.isValid() || !master.isValid()) {
|
|
21123
21123
|
return false;
|
|
21124
21124
|
}
|
|
@@ -31622,10 +31622,10 @@ var require_smart_transactions = __commonJS({
|
|
|
31622
31622
|
var bn_js_1 = require("bn.js");
|
|
31623
31623
|
var Transaction2 = require_transaction();
|
|
31624
31624
|
var TransactionBuilder2 = require_transaction_builder();
|
|
31625
|
-
var
|
|
31625
|
+
var TxDestination3 = require_tx_destination();
|
|
31626
31626
|
var script2 = require_script2();
|
|
31627
31627
|
var opcodes2 = require_bitcoin_ops();
|
|
31628
|
-
var
|
|
31628
|
+
var OptCCParams3 = require_optccparams();
|
|
31629
31629
|
var templates = require_templates();
|
|
31630
31630
|
var BNClass = new bn_js_1.BN(0);
|
|
31631
31631
|
var unpackOutput2 = function(output, systemId, isInput, allowNonTransferEvals) {
|
|
@@ -31655,9 +31655,9 @@ var require_smart_transactions = __commonJS({
|
|
|
31655
31655
|
var decompiledScript = script2.decompile(outputScript);
|
|
31656
31656
|
for (var i = 0; i < decompiledScript.length; i += 2) {
|
|
31657
31657
|
if (i === 0)
|
|
31658
|
-
masterOptCC =
|
|
31658
|
+
masterOptCC = OptCCParams3.fromChunk(decompiledScript[i]);
|
|
31659
31659
|
else
|
|
31660
|
-
paramsOptCC.push(
|
|
31660
|
+
paramsOptCC.push(OptCCParams3.fromChunk(decompiledScript[i]));
|
|
31661
31661
|
}
|
|
31662
31662
|
if (paramsOptCC.length > 1)
|
|
31663
31663
|
throw new Error(">1 OptCCParam objects not currently supported for smart transaction params.");
|
|
@@ -32060,8 +32060,8 @@ var require_smart_transactions = __commonJS({
|
|
|
32060
32060
|
var outMaster = void 0;
|
|
32061
32061
|
var outParams = void 0;
|
|
32062
32062
|
if (isReserveTransfer) {
|
|
32063
|
-
var destination = new
|
|
32064
|
-
outMaster = new
|
|
32063
|
+
var destination = new TxDestination3(TxDestination3.TYPE_PKH, verus_typescript_primitives_1.RESERVE_TRANSFER_DESTINATION.destination_bytes);
|
|
32064
|
+
outMaster = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_NONE, 1, 1, [destination]);
|
|
32065
32065
|
var flags = new bn_js_1.BN(1);
|
|
32066
32066
|
var version_1 = new bn_js_1.BN(1, 10);
|
|
32067
32067
|
var isConversion = params.convertto != null && params.convertto !== params.currency;
|
|
@@ -32096,22 +32096,22 @@ var require_smart_transactions = __commonJS({
|
|
|
32096
32096
|
second_reserve_id: params.convertto,
|
|
32097
32097
|
dest_system_id: params.exportto
|
|
32098
32098
|
});
|
|
32099
|
-
outParams = new
|
|
32099
|
+
outParams = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_RESERVE_TRANSFER, 1, 1, [destination], [resTransfer.toBuffer()]);
|
|
32100
32100
|
} else {
|
|
32101
32101
|
values.value_map.delete(systemId);
|
|
32102
32102
|
if (values.value_map.size == 0) {
|
|
32103
|
-
var destination = new
|
|
32104
|
-
outMaster = new
|
|
32105
|
-
outParams = new
|
|
32103
|
+
var destination = new TxDestination3(params.address.type.toNumber(), params.address.destination_bytes);
|
|
32104
|
+
outMaster = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_NONE, 0, 0, []);
|
|
32105
|
+
outParams = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_NONE, 1, 1, [destination], []);
|
|
32106
32106
|
} else {
|
|
32107
|
-
var destination = new
|
|
32108
|
-
outMaster = new
|
|
32107
|
+
var destination = new TxDestination3(params.address.type.toNumber(), params.address.destination_bytes);
|
|
32108
|
+
outMaster = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_NONE, 1, 1, [destination]);
|
|
32109
32109
|
var version_2 = new bn_js_1.BN(1, 10);
|
|
32110
32110
|
var tokenOutput = new verus_typescript_primitives_1.TokenOutput({
|
|
32111
32111
|
values,
|
|
32112
32112
|
version: version_2
|
|
32113
32113
|
});
|
|
32114
|
-
outParams = new
|
|
32114
|
+
outParams = new OptCCParams3(3, verus_typescript_primitives_1.EVALS.EVAL_RESERVE_OUTPUT, 1, 1, [destination], [tokenOutput.toBuffer()]);
|
|
32115
32115
|
}
|
|
32116
32116
|
}
|
|
32117
32117
|
var outputScript = script2.compile([
|
|
@@ -32213,6 +32213,7 @@ __export(src_exports, {
|
|
|
32213
32213
|
AMOUNT_DECIMALS: () => AMOUNT_DECIMALS,
|
|
32214
32214
|
BASE58_RE: () => BASE58_RE,
|
|
32215
32215
|
CONSENSUS_BRANCH_ID: () => CONSENSUS_BRANCH_ID,
|
|
32216
|
+
CURRENCY_OPTION: () => CURRENCY_OPTION,
|
|
32216
32217
|
CURRENCY_TYPE_ORDER: () => CURRENCY_TYPE_ORDER,
|
|
32217
32218
|
DEFAULT_EXPIRY_DELTA: () => DEFAULT_EXPIRY_DELTA,
|
|
32218
32219
|
DEFAULT_FEE_PER_KB: () => DEFAULT_FEE_PER_KB,
|
|
@@ -32229,6 +32230,8 @@ __export(src_exports, {
|
|
|
32229
32230
|
InvalidNameError: () => InvalidNameError,
|
|
32230
32231
|
InvalidWifError: () => InvalidWifError,
|
|
32231
32232
|
NETWORK_CONFIG: () => NETWORK_CONFIG,
|
|
32233
|
+
NOTARIZATION_PROTOCOL: () => NOTARIZATION_PROTOCOL,
|
|
32234
|
+
PROOF_PROTOCOL: () => PROOF_PROTOCOL,
|
|
32232
32235
|
PUBKEY_HASH_PREFIX: () => PUBKEY_HASH_PREFIX,
|
|
32233
32236
|
RESERVE_TRANSFER_FEE: () => RESERVE_TRANSFER_FEE,
|
|
32234
32237
|
SATS_PER_COIN: () => SATS_PER_COIN,
|
|
@@ -32240,6 +32243,10 @@ __export(src_exports, {
|
|
|
32240
32243
|
VerusSDK: () => VerusSDK,
|
|
32241
32244
|
WIF_PREFIX: () => WIF_PREFIX,
|
|
32242
32245
|
address: () => address_exports,
|
|
32246
|
+
buildCurrencyDefinitionScript: () => buildCurrencyDefinitionScript,
|
|
32247
|
+
buildCurrencyLaunchOutputs: () => buildCurrencyLaunchOutputs,
|
|
32248
|
+
buildCurrencyLaunchTransaction: () => buildCurrencyLaunchTransaction,
|
|
32249
|
+
buildReserveTransferOutput: () => buildReserveTransferOutput,
|
|
32243
32250
|
classifyCurrency: () => classifyCurrency,
|
|
32244
32251
|
currency: () => currency_exports,
|
|
32245
32252
|
identity: () => public_exports2,
|
|
@@ -32252,6 +32259,7 @@ __export(src_exports, {
|
|
|
32252
32259
|
message: () => message_exports,
|
|
32253
32260
|
offers: () => public_exports,
|
|
32254
32261
|
parseSats: () => parseSats,
|
|
32262
|
+
serializeCurrencyDefinition: () => serializeCurrencyDefinition,
|
|
32255
32263
|
signing: () => signing_exports,
|
|
32256
32264
|
toCoins: () => toCoins,
|
|
32257
32265
|
toSafeNumber: () => toSafeNumber,
|
|
@@ -34006,18 +34014,30 @@ function sendCurrency(params, network) {
|
|
|
34006
34014
|
const verusNetwork = getNetwork(network === "testnet");
|
|
34007
34015
|
const systemId = networkConfig.chainId;
|
|
34008
34016
|
const expiryHeight = resolveExpiryHeight(params.expiryHeight);
|
|
34009
|
-
const
|
|
34010
|
-
|
|
34011
|
-
|
|
34012
|
-
|
|
34013
|
-
|
|
34014
|
-
|
|
34015
|
-
|
|
34016
|
-
|
|
34017
|
-
|
|
34018
|
-
|
|
34019
|
-
|
|
34020
|
-
|
|
34017
|
+
for (const out of params.outputs) {
|
|
34018
|
+
if (out.mintnew && (out.convertTo !== void 0 || out.preconvert || out.burn || out.burnweight)) {
|
|
34019
|
+
throw new TransactionBuildError("mintnew cannot be combined with convertTo, preconvert, or burn");
|
|
34020
|
+
}
|
|
34021
|
+
}
|
|
34022
|
+
const txOutputs = params.outputs.map((out) => {
|
|
34023
|
+
const forcesReserveTransfer = out.mintnew || out.burn || out.burnweight;
|
|
34024
|
+
const feecurrency = out.feeCurrency ?? (forcesReserveTransfer ? systemId : void 0);
|
|
34025
|
+
return {
|
|
34026
|
+
currency: out.currency,
|
|
34027
|
+
satoshis: out.satoshis.toString(10),
|
|
34028
|
+
address: parseAddress2(out.address, out.addressType || "PKH"),
|
|
34029
|
+
...out.convertTo !== void 0 ? { convertto: out.convertTo } : {},
|
|
34030
|
+
...out.exportTo !== void 0 ? { exportto: out.exportTo } : {},
|
|
34031
|
+
...out.via !== void 0 ? { via: out.via } : {},
|
|
34032
|
+
...out.bridgeId !== void 0 ? { bridgeid: out.bridgeId } : {},
|
|
34033
|
+
...feecurrency !== void 0 ? { feecurrency } : {},
|
|
34034
|
+
...out.feeSatoshis !== void 0 ? { feesatoshis: out.feeSatoshis.toString(10) } : {},
|
|
34035
|
+
...out.preconvert !== void 0 ? { preconvert: out.preconvert } : {},
|
|
34036
|
+
...out.mintnew !== void 0 ? { mintnew: out.mintnew } : {},
|
|
34037
|
+
...out.burn !== void 0 ? { burn: out.burn } : {},
|
|
34038
|
+
...out.burnweight !== void 0 ? { burnweight: out.burnweight } : {}
|
|
34039
|
+
};
|
|
34040
|
+
});
|
|
34021
34041
|
const unfundedTxHex = createUnfundedCurrencyTransfer(
|
|
34022
34042
|
systemId,
|
|
34023
34043
|
txOutputs,
|
|
@@ -34026,11 +34046,11 @@ function sendCurrency(params, network) {
|
|
|
34026
34046
|
);
|
|
34027
34047
|
const unfundedTx = import_utxo_lib.Transaction.fromHex(unfundedTxHex, verusNetwork);
|
|
34028
34048
|
const hasSmartOutputs = params.outputs.some(
|
|
34029
|
-
(o) => o.convertTo || o.exportTo || o.via || o.currency !== systemId
|
|
34049
|
+
(o) => o.convertTo || o.exportTo || o.via || o.mintnew || o.burn || o.burnweight || o.currency !== systemId
|
|
34030
34050
|
);
|
|
34031
34051
|
const requiredCurrencies = /* @__PURE__ */ new Map();
|
|
34032
34052
|
for (const out of params.outputs) {
|
|
34033
|
-
if (out.currency !== systemId) {
|
|
34053
|
+
if (out.currency !== systemId && !out.mintnew) {
|
|
34034
34054
|
requiredCurrencies.set(
|
|
34035
34055
|
out.currency,
|
|
34036
34056
|
(requiredCurrencies.get(out.currency) || 0n) + out.satoshis
|
|
@@ -34287,9 +34307,18 @@ function verifyMessage(params, network) {
|
|
|
34287
34307
|
// src/currency/index.ts
|
|
34288
34308
|
var currency_exports = {};
|
|
34289
34309
|
__export(currency_exports, {
|
|
34310
|
+
CURRENCY_DEFINITION_VERSION: () => CURRENCY_DEFINITION_VERSION,
|
|
34311
|
+
CURRENCY_OPTION: () => CURRENCY_OPTION,
|
|
34290
34312
|
CURRENCY_TYPE_ORDER: () => CURRENCY_TYPE_ORDER,
|
|
34313
|
+
NOTARIZATION_PROTOCOL: () => NOTARIZATION_PROTOCOL,
|
|
34314
|
+
PROOF_PROTOCOL: () => PROOF_PROTOCOL,
|
|
34315
|
+
buildCurrencyDefinitionScript: () => buildCurrencyDefinitionScript,
|
|
34316
|
+
buildCurrencyLaunchOutputs: () => buildCurrencyLaunchOutputs,
|
|
34317
|
+
buildCurrencyLaunchTransaction: () => buildCurrencyLaunchTransaction,
|
|
34318
|
+
buildReserveTransferOutput: () => buildReserveTransferOutput,
|
|
34291
34319
|
classifyCurrency: () => classifyCurrency,
|
|
34292
|
-
defineCurrency: () => defineCurrency
|
|
34320
|
+
defineCurrency: () => defineCurrency,
|
|
34321
|
+
serializeCurrencyDefinition: () => serializeCurrencyDefinition
|
|
34293
34322
|
});
|
|
34294
34323
|
|
|
34295
34324
|
// src/currency/classify.ts
|
|
@@ -34311,8 +34340,820 @@ function classifyCurrency(currencyInfo) {
|
|
|
34311
34340
|
return "token";
|
|
34312
34341
|
}
|
|
34313
34342
|
|
|
34314
|
-
// src/currency/
|
|
34343
|
+
// src/currency/wire.ts
|
|
34315
34344
|
var import_bn3 = __toESM(require("bn.js"));
|
|
34345
|
+
var SATOSHIDEN = 100000000n;
|
|
34346
|
+
var INT32_MIN = -2147483648;
|
|
34347
|
+
var INT32_MAX = 2147483647;
|
|
34348
|
+
var ZEROS_32 = Buffer.alloc(32);
|
|
34349
|
+
function requireInt32Range(value, label) {
|
|
34350
|
+
if (value < 0n || value > BigInt(INT32_MAX)) {
|
|
34351
|
+
throw new TransactionBuildError(`${label} must be in [0, ${INT32_MAX}], got ${value}`);
|
|
34352
|
+
}
|
|
34353
|
+
return value;
|
|
34354
|
+
}
|
|
34355
|
+
var INT64_MAX = 2n ** 63n - 1n;
|
|
34356
|
+
function requireInt64Range(value, label) {
|
|
34357
|
+
if (value < 0n || value > INT64_MAX) {
|
|
34358
|
+
throw new TransactionBuildError(`${label} must be in [0, 2^63-1], got ${value}`);
|
|
34359
|
+
}
|
|
34360
|
+
return value;
|
|
34361
|
+
}
|
|
34362
|
+
function uint16LE(value, label) {
|
|
34363
|
+
if (!Number.isInteger(value) || value < 0 || value > 65535) {
|
|
34364
|
+
throw new TransactionBuildError(`${label} must be a uint16, got ${value}`);
|
|
34365
|
+
}
|
|
34366
|
+
const buf = Buffer.alloc(2);
|
|
34367
|
+
buf.writeUInt16LE(value, 0);
|
|
34368
|
+
return buf;
|
|
34369
|
+
}
|
|
34370
|
+
function int32LE(value, label) {
|
|
34371
|
+
if (!Number.isInteger(value) || value < INT32_MIN || value > INT32_MAX) {
|
|
34372
|
+
throw new TransactionBuildError(`${label} must be an int32, got ${value}`);
|
|
34373
|
+
}
|
|
34374
|
+
const buf = Buffer.alloc(4);
|
|
34375
|
+
buf.writeInt32LE(value, 0);
|
|
34376
|
+
return buf;
|
|
34377
|
+
}
|
|
34378
|
+
function uint32LE(value, label) {
|
|
34379
|
+
if (!Number.isInteger(value) || value < 0 || value > 4294967295) {
|
|
34380
|
+
throw new TransactionBuildError(`${label} must be a uint32, got ${value}`);
|
|
34381
|
+
}
|
|
34382
|
+
const buf = Buffer.alloc(4);
|
|
34383
|
+
buf.writeUInt32LE(value, 0);
|
|
34384
|
+
return buf;
|
|
34385
|
+
}
|
|
34386
|
+
function int64LE(value, label) {
|
|
34387
|
+
const buf = Buffer.alloc(8);
|
|
34388
|
+
try {
|
|
34389
|
+
buf.writeBigInt64LE(value, 0);
|
|
34390
|
+
} catch {
|
|
34391
|
+
throw new TransactionBuildError(`${label} does not fit in an int64: ${value}`);
|
|
34392
|
+
}
|
|
34393
|
+
return buf;
|
|
34394
|
+
}
|
|
34395
|
+
function varInt(value, label) {
|
|
34396
|
+
if (value < 0n) {
|
|
34397
|
+
throw new TransactionBuildError(`${label} must be non-negative for VARINT, got ${value}`);
|
|
34398
|
+
}
|
|
34399
|
+
let n = value;
|
|
34400
|
+
const out = [];
|
|
34401
|
+
let len = 0;
|
|
34402
|
+
for (; ; ) {
|
|
34403
|
+
out.push(Number(n & 0x7fn) | (len > 0 ? 128 : 0));
|
|
34404
|
+
if (n <= 0x7fn) break;
|
|
34405
|
+
n = (n >> 7n) - 1n;
|
|
34406
|
+
len++;
|
|
34407
|
+
}
|
|
34408
|
+
return Buffer.from(out.reverse());
|
|
34409
|
+
}
|
|
34410
|
+
function limitedString(value, maxLen, label) {
|
|
34411
|
+
const bytes = Buffer.from(value, "utf8");
|
|
34412
|
+
if (bytes.length > maxLen) {
|
|
34413
|
+
throw new TransactionBuildError(`${label} exceeds ${maxLen} bytes`);
|
|
34414
|
+
}
|
|
34415
|
+
return Buffer.concat([writeCompactSize(bytes.length), bytes]);
|
|
34416
|
+
}
|
|
34417
|
+
function uint160(iAddress, label) {
|
|
34418
|
+
const hash = iAddressToHash(parseIAddress(iAddress, label));
|
|
34419
|
+
if (hash.length !== 20) {
|
|
34420
|
+
throw new TransactionBuildError(`${label} must be a 20-byte i-address hash`);
|
|
34421
|
+
}
|
|
34422
|
+
return hash;
|
|
34423
|
+
}
|
|
34424
|
+
function uint160Raw(hash, label) {
|
|
34425
|
+
if (hash.length !== 20) {
|
|
34426
|
+
throw new TransactionBuildError(`${label} must be a 20-byte hash, got ${hash.length}`);
|
|
34427
|
+
}
|
|
34428
|
+
return Buffer.from(hash);
|
|
34429
|
+
}
|
|
34430
|
+
function uint256Raw(hash, label) {
|
|
34431
|
+
if (hash.length !== 32) {
|
|
34432
|
+
throw new TransactionBuildError(`${label} must be a 32-byte hash, got ${hash.length}`);
|
|
34433
|
+
}
|
|
34434
|
+
return Buffer.from(hash);
|
|
34435
|
+
}
|
|
34436
|
+
function vectorU160(addresses, label) {
|
|
34437
|
+
return Buffer.concat([
|
|
34438
|
+
writeCompactSize(addresses.length),
|
|
34439
|
+
...addresses.map((a, i) => uint160(a, `${label}[${i}]`))
|
|
34440
|
+
]);
|
|
34441
|
+
}
|
|
34442
|
+
function vectorI64(values, label) {
|
|
34443
|
+
return Buffer.concat([
|
|
34444
|
+
writeCompactSize(values.length),
|
|
34445
|
+
...values.map((v, i) => int64LE(v, `${label}[${i}]`))
|
|
34446
|
+
]);
|
|
34447
|
+
}
|
|
34448
|
+
function vectorI32(values, label) {
|
|
34449
|
+
return Buffer.concat([
|
|
34450
|
+
writeCompactSize(values.length),
|
|
34451
|
+
...values.map((v, i) => int32LE(Number(v), `${label}[${i}]`))
|
|
34452
|
+
]);
|
|
34453
|
+
}
|
|
34454
|
+
function currencyValueMap(entries, label) {
|
|
34455
|
+
return Buffer.concat([
|
|
34456
|
+
writeCompactSize(entries.length),
|
|
34457
|
+
...entries.flatMap((e, i) => [uint160Raw(e.hash, `${label}[${i}].id`), int64LE(e.amount, `${label}[${i}].amount`)])
|
|
34458
|
+
]);
|
|
34459
|
+
}
|
|
34460
|
+
function normalizeWeights(raw) {
|
|
34461
|
+
let total = 0n;
|
|
34462
|
+
for (const w of raw) {
|
|
34463
|
+
if (w <= 0n) {
|
|
34464
|
+
throw new TransactionBuildError(`each reserve weight must be > 0, got ${w}`);
|
|
34465
|
+
}
|
|
34466
|
+
requireInt32Range(w, "weight");
|
|
34467
|
+
total += w;
|
|
34468
|
+
}
|
|
34469
|
+
const out = [];
|
|
34470
|
+
let reserveLeft = SATOSHIDEN;
|
|
34471
|
+
raw.forEach((w, i) => {
|
|
34472
|
+
let amount = SATOSHIDEN * w / total;
|
|
34473
|
+
if (reserveLeft <= amount || i + 1 === raw.length) {
|
|
34474
|
+
amount = reserveLeft;
|
|
34475
|
+
}
|
|
34476
|
+
reserveLeft -= amount;
|
|
34477
|
+
out.push(amount);
|
|
34478
|
+
});
|
|
34479
|
+
return out;
|
|
34480
|
+
}
|
|
34481
|
+
function toTxDestination(dest) {
|
|
34482
|
+
return dest.kind === "pubkey" ? new boundary_exports.TxDestination(new boundary_exports.PubKey(dest.pubkey, true)) : new boundary_exports.TxDestination(new boundary_exports.KeyID(uint160Raw(dest.hash, "cc destination hash")));
|
|
34483
|
+
}
|
|
34484
|
+
function wrapCcOutput(evalCode, vdata, dest) {
|
|
34485
|
+
const destination = () => toTxDestination(dest);
|
|
34486
|
+
const master = new boundary_exports.OptCCParams({
|
|
34487
|
+
version: new import_bn3.default(3),
|
|
34488
|
+
eval_code: new import_bn3.default(0),
|
|
34489
|
+
m: new import_bn3.default(1),
|
|
34490
|
+
n: new import_bn3.default(1),
|
|
34491
|
+
destinations: [destination()],
|
|
34492
|
+
vdata: []
|
|
34493
|
+
});
|
|
34494
|
+
const params = new boundary_exports.OptCCParams({
|
|
34495
|
+
version: new import_bn3.default(3),
|
|
34496
|
+
eval_code: new import_bn3.default(evalCode),
|
|
34497
|
+
m: new import_bn3.default(1),
|
|
34498
|
+
n: new import_bn3.default(1),
|
|
34499
|
+
destinations: [destination()],
|
|
34500
|
+
vdata
|
|
34501
|
+
});
|
|
34502
|
+
return import_utxo_lib.script.compile([
|
|
34503
|
+
master.toChunk(),
|
|
34504
|
+
import_utxo_lib.opcodes.OP_CHECKCRYPTOCONDITION,
|
|
34505
|
+
params.toChunk(),
|
|
34506
|
+
import_utxo_lib.opcodes.OP_DROP
|
|
34507
|
+
]);
|
|
34508
|
+
}
|
|
34509
|
+
|
|
34510
|
+
// src/currency/definition.ts
|
|
34511
|
+
var CURRENCY_DEFINITION_VERSION = 1;
|
|
34512
|
+
var CURRENCY_OPTION = {
|
|
34513
|
+
FRACTIONAL: 1,
|
|
34514
|
+
ID_RESTRICTED: 2,
|
|
34515
|
+
ID_STAKING: 4,
|
|
34516
|
+
ID_REFERRALS: 8,
|
|
34517
|
+
ID_REFERRALREQUIRED: 16,
|
|
34518
|
+
TOKEN: 32,
|
|
34519
|
+
SINGLECURRENCY: 64,
|
|
34520
|
+
GATEWAY: 128,
|
|
34521
|
+
PBAAS: 256,
|
|
34522
|
+
GATEWAY_CONVERTER: 512,
|
|
34523
|
+
GATEWAY_NAMECONTROLLER: 1024,
|
|
34524
|
+
NFT_TOKEN: 2048,
|
|
34525
|
+
NO_IDS: 4096
|
|
34526
|
+
};
|
|
34527
|
+
var NOTARIZATION_PROTOCOL = { AUTO: 1, NOTARY_CONFIRM: 2, NOTARY_CHAINID: 3 };
|
|
34528
|
+
var PROOF_PROTOCOL = { PBAASMMR: 1, CHAINID: 2, ETHNOTARIZATION: 3 };
|
|
34529
|
+
var CURRENCY_DEFINITION_PUBKEY = Buffer.from(
|
|
34530
|
+
"02a0de91740d3d5a3a4a7990ae22315133d02f33716b339ebce88662d012224ef5",
|
|
34531
|
+
"hex"
|
|
34532
|
+
);
|
|
34533
|
+
var DEFAULT_ID_REGISTRATION_FEE = 10000000000n;
|
|
34534
|
+
var DEFAULT_ID_IMPORT_FEE = 2000000n;
|
|
34535
|
+
var DEFAULT_ID_REFERRAL_LEVELS = 3;
|
|
34536
|
+
var MIN_RESERVE_RATIO = 5000000n;
|
|
34537
|
+
var MAX_RESERVE_CURRENCIES = 10;
|
|
34538
|
+
var MAX_ID_REFERRAL_LEVELS = 5;
|
|
34539
|
+
var MIN_CURRENCY_LIFE = 480;
|
|
34540
|
+
var BLOCK_MAX = 2147483647;
|
|
34541
|
+
function normalizeCurrencyDefinition(input) {
|
|
34542
|
+
if (!input.name || input.name.includes("@")) {
|
|
34543
|
+
throw new TransactionBuildError('name must be a bare currency name without "@"');
|
|
34544
|
+
}
|
|
34545
|
+
if (!Number.isInteger(input.options)) {
|
|
34546
|
+
throw new TransactionBuildError("options is required (must include the TOKEN bit)");
|
|
34547
|
+
}
|
|
34548
|
+
if (!(input.options & CURRENCY_OPTION.TOKEN)) {
|
|
34549
|
+
throw new TransactionBuildError("options must include the TOKEN bit (0x20); native currencies are out of scope");
|
|
34550
|
+
}
|
|
34551
|
+
if (input.options & (CURRENCY_OPTION.GATEWAY | CURRENCY_OPTION.PBAAS | CURRENCY_OPTION.GATEWAY_CONVERTER)) {
|
|
34552
|
+
throw new TransactionBuildError("GATEWAY and PBAAS currencies are out of scope for the offline builder");
|
|
34553
|
+
}
|
|
34554
|
+
if (input.options < 0 || input.options > CURRENCY_OPTION.NO_IDS * 2 - 1) {
|
|
34555
|
+
throw new TransactionBuildError(`options has bits outside the known mask: ${input.options}`);
|
|
34556
|
+
}
|
|
34557
|
+
const legacy = input;
|
|
34558
|
+
if (legacy.conversions !== void 0) {
|
|
34559
|
+
throw new TransactionBuildError(
|
|
34560
|
+
"conversions are not supported: a fractional definition always carries a zero conversion vector (the daemon derives launch prices); omit the field"
|
|
34561
|
+
);
|
|
34562
|
+
}
|
|
34563
|
+
if (legacy.initialContributions !== void 0) {
|
|
34564
|
+
throw new TransactionBuildError(
|
|
34565
|
+
"initialContributions are out of scope: they seed reserves the identity must hold and require reserve-deposit inputs the offline builder cannot assemble; contribute via a preconvert reserve-transfer instead"
|
|
34566
|
+
);
|
|
34567
|
+
}
|
|
34568
|
+
const isFractional = Boolean(input.options & CURRENCY_OPTION.FRACTIONAL);
|
|
34569
|
+
const isNFT = Boolean(input.options & CURRENCY_OPTION.NFT_TOKEN);
|
|
34570
|
+
const currencies = input.currencies ?? [];
|
|
34571
|
+
const systemId = input.systemId ?? input.parent;
|
|
34572
|
+
const launchSystemId = input.launchSystemId ?? systemId;
|
|
34573
|
+
if (isNFT) {
|
|
34574
|
+
if (isFractional) {
|
|
34575
|
+
throw new TransactionBuildError("an NFT (NFT_TOKEN) cannot also be FRACTIONAL");
|
|
34576
|
+
}
|
|
34577
|
+
if (currencies.length || input.weights?.length) {
|
|
34578
|
+
throw new TransactionBuildError("do not set currencies/weights for an NFT \u2014 the system currency is added automatically");
|
|
34579
|
+
}
|
|
34580
|
+
if (input.minPreconversion || input.maxPreconversion) {
|
|
34581
|
+
throw new TransactionBuildError("do not set min/maxPreconversion for an NFT \u2014 they are fixed (maxPreconversion=[0])");
|
|
34582
|
+
}
|
|
34583
|
+
if ((input.initialSupply ?? 0n) !== 0n || (input.preLaunchDiscount ?? 0n) !== 0n) {
|
|
34584
|
+
throw new TransactionBuildError("an NFT takes no initialSupply or preLaunchDiscount \u2014 its supply is the single 1-satoshi token");
|
|
34585
|
+
}
|
|
34586
|
+
if ((input.preLaunchCarveOut ?? 0) !== 0) {
|
|
34587
|
+
throw new TransactionBuildError("an NFT takes no preLaunchCarveOut");
|
|
34588
|
+
}
|
|
34589
|
+
const proofProtocol = input.proofProtocol ?? PROOF_PROTOCOL.PBAASMMR;
|
|
34590
|
+
if (proofProtocol === PROOF_PROTOCOL.CHAINID) {
|
|
34591
|
+
throw new TransactionBuildError("an NFT may not use a centralized proof protocol (CHAINID/2); use PBAASMMR (1)");
|
|
34592
|
+
}
|
|
34593
|
+
const preAllocations = input.preAllocations ?? [];
|
|
34594
|
+
const preallocTotal = preAllocations.reduce((sum, p) => sum + p.amount, 0n);
|
|
34595
|
+
if (preallocTotal !== 1n) {
|
|
34596
|
+
throw new TransactionBuildError("an NFT must pre-allocate exactly 1 satoshi \u2014 the single indivisible token");
|
|
34597
|
+
}
|
|
34598
|
+
return {
|
|
34599
|
+
version: CURRENCY_DEFINITION_VERSION,
|
|
34600
|
+
options: input.options,
|
|
34601
|
+
parent: input.parent,
|
|
34602
|
+
name: input.name,
|
|
34603
|
+
launchSystemId,
|
|
34604
|
+
systemId,
|
|
34605
|
+
notarizationProtocol: input.notarizationProtocol ?? NOTARIZATION_PROTOCOL.AUTO,
|
|
34606
|
+
proofProtocol,
|
|
34607
|
+
startBlock: input.startBlock ?? 0,
|
|
34608
|
+
endBlock: input.endBlock ?? 0,
|
|
34609
|
+
initialFractionalSupply: 0n,
|
|
34610
|
+
preAllocations,
|
|
34611
|
+
gatewayConverterIssuance: 0n,
|
|
34612
|
+
// The daemon maps the NFT to the native/system currency with a zeroed
|
|
34613
|
+
// conversion and maxPreconvert=[0]; weights stay empty (not fractional).
|
|
34614
|
+
currencies: [systemId],
|
|
34615
|
+
weights: [],
|
|
34616
|
+
conversions: [0n],
|
|
34617
|
+
minPreconversion: [],
|
|
34618
|
+
maxPreconversion: [0n],
|
|
34619
|
+
initialContributions: [0n],
|
|
34620
|
+
preconverted: [0n],
|
|
34621
|
+
preLaunchDiscount: 0n,
|
|
34622
|
+
preLaunchCarveOut: 0,
|
|
34623
|
+
notaries: [],
|
|
34624
|
+
minNotariesConfirm: 0,
|
|
34625
|
+
idRegistrationFees: input.idRegistrationFees ?? DEFAULT_ID_REGISTRATION_FEE,
|
|
34626
|
+
idReferralLevels: input.idReferralLevels ?? DEFAULT_ID_REFERRAL_LEVELS,
|
|
34627
|
+
idImportFees: input.idImportFees ?? DEFAULT_ID_IMPORT_FEE
|
|
34628
|
+
};
|
|
34629
|
+
}
|
|
34630
|
+
if (isFractional && currencies.length === 0) {
|
|
34631
|
+
throw new TransactionBuildError("a fractional currency requires at least one reserve currency");
|
|
34632
|
+
}
|
|
34633
|
+
if (!isFractional && currencies.length > 0) {
|
|
34634
|
+
throw new TransactionBuildError("reserve currencies require the FRACTIONAL bit (0x01)");
|
|
34635
|
+
}
|
|
34636
|
+
let fractionalWeights = [];
|
|
34637
|
+
if (isFractional) {
|
|
34638
|
+
if (input.weights === void 0 || input.weights.length !== currencies.length) {
|
|
34639
|
+
throw new TransactionBuildError(`a fractional currency requires one weight per reserve currency (${currencies.length})`);
|
|
34640
|
+
}
|
|
34641
|
+
if ((input.initialSupply ?? 0n) <= 0n) {
|
|
34642
|
+
throw new TransactionBuildError("a fractional currency requires a positive initialSupply (the daemon rejects zero)");
|
|
34643
|
+
}
|
|
34644
|
+
if (currencies.length > MAX_RESERVE_CURRENCIES) {
|
|
34645
|
+
throw new TransactionBuildError(`a fractional currency may have at most ${MAX_RESERVE_CURRENCIES} reserve currencies, got ${currencies.length}`);
|
|
34646
|
+
}
|
|
34647
|
+
if (!currencies.includes(systemId)) {
|
|
34648
|
+
throw new TransactionBuildError(`a fractional currency must include the chain's native currency (${systemId}) among its reserves`);
|
|
34649
|
+
}
|
|
34650
|
+
fractionalWeights = normalizeWeights(input.weights);
|
|
34651
|
+
fractionalWeights.forEach((w, i) => {
|
|
34652
|
+
if (w < MIN_RESERVE_RATIO) {
|
|
34653
|
+
throw new TransactionBuildError(`reserve weight[${i}] normalizes to ${w}, below the 5% minimum (${MIN_RESERVE_RATIO}); a fractional reserve may not go below 5%`);
|
|
34654
|
+
}
|
|
34655
|
+
});
|
|
34656
|
+
} else {
|
|
34657
|
+
if (input.initialSupply !== void 0 && input.initialSupply !== 0n) {
|
|
34658
|
+
throw new TransactionBuildError("initialSupply applies only to a FRACTIONAL currency");
|
|
34659
|
+
}
|
|
34660
|
+
if (input.preLaunchDiscount !== void 0 && input.preLaunchDiscount !== 0n) {
|
|
34661
|
+
throw new TransactionBuildError("preLaunchDiscount applies only to a FRACTIONAL currency");
|
|
34662
|
+
}
|
|
34663
|
+
}
|
|
34664
|
+
const requireBlock = (v, label) => {
|
|
34665
|
+
if (!Number.isInteger(v) || v < 0 || v > BLOCK_MAX) {
|
|
34666
|
+
throw new TransactionBuildError(`${label} must be an integer block height in [0, ${BLOCK_MAX}], got ${v}`);
|
|
34667
|
+
}
|
|
34668
|
+
};
|
|
34669
|
+
const startBlock = input.startBlock ?? 0;
|
|
34670
|
+
const endBlock = input.endBlock ?? 0;
|
|
34671
|
+
requireBlock(startBlock, "startBlock");
|
|
34672
|
+
requireBlock(endBlock, "endBlock");
|
|
34673
|
+
if (endBlock !== 0 && endBlock < startBlock + MIN_CURRENCY_LIFE) {
|
|
34674
|
+
throw new TransactionBuildError(`endBlock (${endBlock}) must be 0 or \u2265 startBlock + ${MIN_CURRENCY_LIFE} (${startBlock + MIN_CURRENCY_LIFE})`);
|
|
34675
|
+
}
|
|
34676
|
+
if ((input.idReferralLevels ?? DEFAULT_ID_REFERRAL_LEVELS) > MAX_ID_REFERRAL_LEVELS) {
|
|
34677
|
+
throw new TransactionBuildError(`idReferralLevels must be \u2264 ${MAX_ID_REFERRAL_LEVELS}`);
|
|
34678
|
+
}
|
|
34679
|
+
if ((input.preLaunchCarveOut ?? 0) < 0) {
|
|
34680
|
+
throw new TransactionBuildError("preLaunchCarveOut must be non-negative");
|
|
34681
|
+
}
|
|
34682
|
+
(input.preAllocations ?? []).forEach((p, i) => {
|
|
34683
|
+
if (p.amount <= 0n) {
|
|
34684
|
+
throw new TransactionBuildError(`preAllocations[${i}].amount must be positive, got ${p.amount}`);
|
|
34685
|
+
}
|
|
34686
|
+
});
|
|
34687
|
+
const checkVec = (arr, label) => {
|
|
34688
|
+
if (arr.length !== currencies.length) {
|
|
34689
|
+
throw new TransactionBuildError(`${label} must have one entry per reserve currency (${currencies.length}), got ${arr.length}`);
|
|
34690
|
+
}
|
|
34691
|
+
arr.forEach((v, i) => {
|
|
34692
|
+
if (v < 0n) throw new TransactionBuildError(`${label}[${i}] must be non-negative, got ${v}`);
|
|
34693
|
+
});
|
|
34694
|
+
return arr;
|
|
34695
|
+
};
|
|
34696
|
+
const emptyOr = (arr, label) => arr === void 0 ? [] : checkVec(arr, label);
|
|
34697
|
+
const zeros = () => new Array(currencies.length).fill(0n);
|
|
34698
|
+
const minPreconversion = emptyOr(input.minPreconversion, "minPreconversion");
|
|
34699
|
+
const maxPreconversion = emptyOr(input.maxPreconversion, "maxPreconversion");
|
|
34700
|
+
if (minPreconversion.length && maxPreconversion.length) {
|
|
34701
|
+
for (let i = 0; i < currencies.length; i++) {
|
|
34702
|
+
const min = minPreconversion[i];
|
|
34703
|
+
const max = maxPreconversion[i];
|
|
34704
|
+
if (min !== void 0 && max !== void 0 && max < min) {
|
|
34705
|
+
throw new TransactionBuildError(
|
|
34706
|
+
`maxPreconversion[${i}] (${max}) must be \u2265 minPreconversion[${i}] (${min})`
|
|
34707
|
+
);
|
|
34708
|
+
}
|
|
34709
|
+
}
|
|
34710
|
+
}
|
|
34711
|
+
return {
|
|
34712
|
+
version: CURRENCY_DEFINITION_VERSION,
|
|
34713
|
+
options: input.options,
|
|
34714
|
+
parent: input.parent,
|
|
34715
|
+
name: input.name,
|
|
34716
|
+
launchSystemId,
|
|
34717
|
+
systemId,
|
|
34718
|
+
notarizationProtocol: input.notarizationProtocol ?? NOTARIZATION_PROTOCOL.AUTO,
|
|
34719
|
+
proofProtocol: input.proofProtocol ?? PROOF_PROTOCOL.CHAINID,
|
|
34720
|
+
startBlock: input.startBlock ?? 0,
|
|
34721
|
+
endBlock: input.endBlock ?? 0,
|
|
34722
|
+
initialFractionalSupply: input.initialSupply ?? 0n,
|
|
34723
|
+
preAllocations: input.preAllocations ?? [],
|
|
34724
|
+
gatewayConverterIssuance: 0n,
|
|
34725
|
+
currencies,
|
|
34726
|
+
// Normalized to sum to 1e8 (computed and range-checked above).
|
|
34727
|
+
weights: fractionalWeights,
|
|
34728
|
+
// A fractional definition always carries a zero conversion vector (the daemon
|
|
34729
|
+
// ignores any explicit `conversions` and derives launch prices); a
|
|
34730
|
+
// non-fractional token has no reserves, hence an empty vector.
|
|
34731
|
+
conversions: zeros(),
|
|
34732
|
+
minPreconversion,
|
|
34733
|
+
maxPreconversion,
|
|
34734
|
+
// `initialContributions` and `preconverted` are internal to a fresh
|
|
34735
|
+
// definition: both carry a zero per reserve currency (empty for a
|
|
34736
|
+
// non-fractional token). Matches on-chain definitions.
|
|
34737
|
+
initialContributions: zeros(),
|
|
34738
|
+
preconverted: zeros(),
|
|
34739
|
+
preLaunchDiscount: requireInt32Range(input.preLaunchDiscount ?? 0n, "preLaunchDiscount"),
|
|
34740
|
+
preLaunchCarveOut: input.preLaunchCarveOut ?? 0,
|
|
34741
|
+
notaries: [],
|
|
34742
|
+
minNotariesConfirm: 0,
|
|
34743
|
+
idRegistrationFees: requireInt64Range(input.idRegistrationFees ?? DEFAULT_ID_REGISTRATION_FEE, "idRegistrationFees"),
|
|
34744
|
+
idReferralLevels: input.idReferralLevels ?? DEFAULT_ID_REFERRAL_LEVELS,
|
|
34745
|
+
idImportFees: requireInt64Range(input.idImportFees ?? DEFAULT_ID_IMPORT_FEE, "idImportFees")
|
|
34746
|
+
};
|
|
34747
|
+
}
|
|
34748
|
+
var MAX_NAME_LEN = 64;
|
|
34749
|
+
function serializeNormalizedDefinition(def) {
|
|
34750
|
+
const parts = [
|
|
34751
|
+
uint32LE(def.version, "version"),
|
|
34752
|
+
uint32LE(def.options, "options"),
|
|
34753
|
+
uint160(def.parent, "parent"),
|
|
34754
|
+
limitedString(def.name, MAX_NAME_LEN, "name"),
|
|
34755
|
+
uint160(def.launchSystemId, "launchSystemId"),
|
|
34756
|
+
uint160(def.systemId, "systemId"),
|
|
34757
|
+
int32LE(def.notarizationProtocol, "notarizationProtocol"),
|
|
34758
|
+
int32LE(def.proofProtocol, "proofProtocol"),
|
|
34759
|
+
// nativeCurrencyID: a null CTransferDestination (type 0, empty destination) → `0000`.
|
|
34760
|
+
Buffer.from([0, 0]),
|
|
34761
|
+
// gatewayID: null uint160 for a non-gateway currency → 20 zero bytes.
|
|
34762
|
+
Buffer.alloc(20),
|
|
34763
|
+
varInt(BigInt(def.startBlock), "startBlock"),
|
|
34764
|
+
varInt(BigInt(def.endBlock), "endBlock"),
|
|
34765
|
+
int64LE(def.initialFractionalSupply, "initialSupply"),
|
|
34766
|
+
// preAllocation: CompactSize count, then (uint160 recipient, int64 amount) pairs.
|
|
34767
|
+
writeCompactSize(def.preAllocations.length),
|
|
34768
|
+
...def.preAllocations.flatMap((p, i) => [
|
|
34769
|
+
uint160(p.address, `preAllocations[${i}].address`),
|
|
34770
|
+
int64LE(p.amount, `preAllocations[${i}].amount`)
|
|
34771
|
+
]),
|
|
34772
|
+
int64LE(def.gatewayConverterIssuance, "gatewayConverterIssuance"),
|
|
34773
|
+
vectorU160(def.currencies, "currencies"),
|
|
34774
|
+
vectorI32(def.weights, "weights"),
|
|
34775
|
+
vectorI64(def.conversions, "conversions"),
|
|
34776
|
+
vectorI64(def.minPreconversion, "minPreconversion"),
|
|
34777
|
+
vectorI64(def.maxPreconversion, "maxPreconversion"),
|
|
34778
|
+
vectorI64(def.initialContributions, "initialContributions"),
|
|
34779
|
+
vectorI64(def.preconverted, "preconverted"),
|
|
34780
|
+
varInt(def.preLaunchDiscount, "preLaunchDiscount"),
|
|
34781
|
+
int32LE(def.preLaunchCarveOut, "preLaunchCarveOut"),
|
|
34782
|
+
vectorU160(def.notaries, "notaries"),
|
|
34783
|
+
varInt(BigInt(def.minNotariesConfirm), "minNotariesConfirm"),
|
|
34784
|
+
varInt(def.idRegistrationFees, "idRegistrationFees"),
|
|
34785
|
+
varInt(BigInt(def.idReferralLevels), "idReferralLevels"),
|
|
34786
|
+
varInt(def.idImportFees, "idImportFees")
|
|
34787
|
+
];
|
|
34788
|
+
return Buffer.concat(parts);
|
|
34789
|
+
}
|
|
34790
|
+
var EVAL_CURRENCY_DEFINITION = 2;
|
|
34791
|
+
function serializeCurrencyDefinition(input) {
|
|
34792
|
+
return serializeNormalizedDefinition(normalizeCurrencyDefinition(input));
|
|
34793
|
+
}
|
|
34794
|
+
function buildCurrencyDefinitionScript(input) {
|
|
34795
|
+
const defBytes = serializeNormalizedDefinition(normalizeCurrencyDefinition(input));
|
|
34796
|
+
return wrapCcOutput(EVAL_CURRENCY_DEFINITION, [defBytes], {
|
|
34797
|
+
kind: "pubkey",
|
|
34798
|
+
pubkey: CURRENCY_DEFINITION_PUBKEY
|
|
34799
|
+
}).toString("hex");
|
|
34800
|
+
}
|
|
34801
|
+
|
|
34802
|
+
// src/currency/outputs.ts
|
|
34803
|
+
var import_bn4 = __toESM(require("bn.js"));
|
|
34804
|
+
var EVAL_CROSSCHAIN_IMPORT = 13;
|
|
34805
|
+
var EVAL_ACCEPTEDNOTARIZATION = 5;
|
|
34806
|
+
var EVAL_CROSSCHAIN_EXPORT = 12;
|
|
34807
|
+
var EVAL_RESERVE_DEPOSIT = 11;
|
|
34808
|
+
var CC_PUBKEY = {
|
|
34809
|
+
[EVAL_ACCEPTEDNOTARIZATION]: "02d85f078815b7a52faa92639c3691d2a640e26c4e06de54dd1490f0e93bcc11c3",
|
|
34810
|
+
[EVAL_CROSSCHAIN_EXPORT]: "02cbfe54fb371cfc89d35b46cafcad6ac3b7dc9b40546b0f30b2b29a4865ed3b4a",
|
|
34811
|
+
[EVAL_RESERVE_DEPOSIT]: "03b99d7cb946c5b1f8a54cde49b8d7e0a2a15a22639feb798009f82b519526c050"
|
|
34812
|
+
};
|
|
34813
|
+
var CC_IMPORT_KEYHASH = Buffer.from("6e4ae35cca122eb65e73abd4c956940ef25a3eab", "hex");
|
|
34814
|
+
var IDENTITY_FLAG_ACTIVECURRENCY2 = 1;
|
|
34815
|
+
var IDENTITY_FLAG_TOKENIZED_ID_CONTROL = 4;
|
|
34816
|
+
function pubkeyDest(evalCode) {
|
|
34817
|
+
return { kind: "pubkey", pubkey: Buffer.from(CC_PUBKEY[evalCode], "hex") };
|
|
34818
|
+
}
|
|
34819
|
+
function buildIdentityUpdateOutput(identityJson, options) {
|
|
34820
|
+
const identity = boundary_exports.Identity.fromJson(identityJson);
|
|
34821
|
+
if (identity.flags.and(new import_bn4.default(IDENTITY_FLAG_ACTIVECURRENCY2)).gtn(0)) {
|
|
34822
|
+
throw new TransactionBuildError("identity already has an active currency (FLAG_ACTIVECURRENCY set); a currency can be defined only once per identity");
|
|
34823
|
+
}
|
|
34824
|
+
identity.flags = identity.flags.or(new import_bn4.default(IDENTITY_FLAG_ACTIVECURRENCY2));
|
|
34825
|
+
if (options & CURRENCY_OPTION.NFT_TOKEN) {
|
|
34826
|
+
identity.flags = identity.flags.or(new import_bn4.default(IDENTITY_FLAG_TOKENIZED_ID_CONTROL));
|
|
34827
|
+
}
|
|
34828
|
+
return { script: buildIdentityScript(identity).toString("hex"), value: 0n };
|
|
34829
|
+
}
|
|
34830
|
+
function serializeImport(systemHash, currencyHash, exportTxOutNum, height) {
|
|
34831
|
+
return Buffer.concat([
|
|
34832
|
+
uint16LE(1, "import.version"),
|
|
34833
|
+
uint16LE(9, "import.flags"),
|
|
34834
|
+
// DEFINITION_IMPORT(1) | SAME_CHAIN(8)
|
|
34835
|
+
uint160Raw(systemHash, "import.sourceSystemID"),
|
|
34836
|
+
uint32LE(height, "import.sourceSystemHeight"),
|
|
34837
|
+
uint160Raw(currencyHash, "import.importCurrencyID"),
|
|
34838
|
+
currencyValueMap([], "import.importValue"),
|
|
34839
|
+
currencyValueMap([], "import.totalReserveOutMap"),
|
|
34840
|
+
int32LE(0, "import.numOutputs"),
|
|
34841
|
+
uint256Raw(ZEROS_32, "import.hashReserveTransfers"),
|
|
34842
|
+
uint256Raw(ZEROS_32, "import.exportTxId"),
|
|
34843
|
+
int32LE(exportTxOutNum, "import.exportTxOutNum")
|
|
34844
|
+
]);
|
|
34845
|
+
}
|
|
34846
|
+
function serializeCoinbaseCurrencyState(currencyHash, reserveHashes, normalizedWeights, isFractional, initialFractionalSupply, tokenSupply) {
|
|
34847
|
+
const n = reserveHashes.length;
|
|
34848
|
+
const zeroVec = () => Buffer.concat([writeCompactSize(n), ...Array.from({ length: n }, () => int64LE(0n, "state.zero"))]);
|
|
34849
|
+
const supply = isFractional ? initialFractionalSupply : tokenSupply;
|
|
34850
|
+
const stateWeights = normalizedWeights.length === n ? normalizedWeights : new Array(n).fill(0n);
|
|
34851
|
+
const parts = [
|
|
34852
|
+
uint16LE(1, "state.version"),
|
|
34853
|
+
uint16LE(isFractional ? 3 : 2, "state.flags"),
|
|
34854
|
+
// PRELAUNCH(2) [| FRACTIONAL(1)]
|
|
34855
|
+
uint160Raw(currencyHash, "state.currencyID"),
|
|
34856
|
+
writeCompactSize(n),
|
|
34857
|
+
...reserveHashes.map((h, i) => uint160Raw(h, `state.currencies[${i}]`)),
|
|
34858
|
+
writeCompactSize(n),
|
|
34859
|
+
...stateWeights.map((w, i) => int32LE(Number(w), `state.weights[${i}]`)),
|
|
34860
|
+
zeroVec(),
|
|
34861
|
+
// reserves — zero at definition (no preconversions yet)
|
|
34862
|
+
varInt(isFractional ? initialFractionalSupply : 0n, "state.initialSupply"),
|
|
34863
|
+
varInt(0n, "state.emitted"),
|
|
34864
|
+
varInt(supply, "state.supply"),
|
|
34865
|
+
// CCoinbaseCurrencyState extension — all-zero at definition.
|
|
34866
|
+
int64LE(0n, "state.primaryCurrencyOut"),
|
|
34867
|
+
int64LE(0n, "state.preConvertedOut"),
|
|
34868
|
+
int64LE(0n, "state.primaryCurrencyFees"),
|
|
34869
|
+
int64LE(0n, "state.primaryCurrencyConversionFees"),
|
|
34870
|
+
zeroVec(),
|
|
34871
|
+
// reserveIn
|
|
34872
|
+
zeroVec(),
|
|
34873
|
+
// primaryCurrencyIn
|
|
34874
|
+
zeroVec(),
|
|
34875
|
+
// reserveOut
|
|
34876
|
+
// conversionPrice (Bancor, reserves→SATOSHIDEN substitution)
|
|
34877
|
+
writeCompactSize(n),
|
|
34878
|
+
...stateWeights.map((w, i) => {
|
|
34879
|
+
const price = isFractional && initialFractionalSupply > 0n && w > 0n ? SATOSHIDEN * SATOSHIDEN * SATOSHIDEN / (initialFractionalSupply * w) : 0n;
|
|
34880
|
+
return int64LE(price, `state.conversionPrice[${i}]`);
|
|
34881
|
+
}),
|
|
34882
|
+
zeroVec(),
|
|
34883
|
+
// viaConversionPrice
|
|
34884
|
+
zeroVec(),
|
|
34885
|
+
// fees
|
|
34886
|
+
// priorWeights — zero at definition (int32 vector, one per reserve).
|
|
34887
|
+
writeCompactSize(n),
|
|
34888
|
+
...stateWeights.map((_, i) => int32LE(0, `state.priorWeights[${i}]`)),
|
|
34889
|
+
zeroVec()
|
|
34890
|
+
// conversionFees
|
|
34891
|
+
];
|
|
34892
|
+
return Buffer.concat(parts);
|
|
34893
|
+
}
|
|
34894
|
+
function serializeNotarization(currencyHash, currencyState, height) {
|
|
34895
|
+
return Buffer.concat([
|
|
34896
|
+
varInt(2n, "notarization.version"),
|
|
34897
|
+
// CPBaaSNotarization::VERSION_CURRENT on VRSC/VRSCTEST
|
|
34898
|
+
varInt(0x83n, "notarization.flags"),
|
|
34899
|
+
// DEF_NOTARIZATION(1) | PRE_LAUNCH(2) | SAME_CHAIN(0x80)
|
|
34900
|
+
Buffer.from([0, 0]),
|
|
34901
|
+
// proposer: empty CTransferDestination
|
|
34902
|
+
uint160Raw(currencyHash, "notarization.currencyID"),
|
|
34903
|
+
currencyState,
|
|
34904
|
+
uint32LE(height, "notarization.notarizationHeight"),
|
|
34905
|
+
uint256Raw(ZEROS_32, "notarization.prevNotarization.hash"),
|
|
34906
|
+
uint32LE(4294967295, "notarization.prevNotarization.n"),
|
|
34907
|
+
uint256Raw(ZEROS_32, "notarization.hashPrevCrossNotarization"),
|
|
34908
|
+
uint32LE(0, "notarization.prevHeight"),
|
|
34909
|
+
writeCompactSize(0),
|
|
34910
|
+
// currencyStates map (empty) — version ≥ 2
|
|
34911
|
+
writeCompactSize(0),
|
|
34912
|
+
// proofRoots map (empty) — version ≥ 2
|
|
34913
|
+
writeCompactSize(0)
|
|
34914
|
+
// nodes vector (empty)
|
|
34915
|
+
]);
|
|
34916
|
+
}
|
|
34917
|
+
function serializeExport(systemHash, currencyHash, height, fee) {
|
|
34918
|
+
return Buffer.concat([
|
|
34919
|
+
uint16LE(1, "export.version"),
|
|
34920
|
+
uint16LE(65, "export.flags"),
|
|
34921
|
+
// DEFINITION_EXPORT(0x40) | PRELAUNCH(1)
|
|
34922
|
+
uint160Raw(systemHash, "export.sourceSystemID"),
|
|
34923
|
+
uint256Raw(ZEROS_32, "export.hashReserveTransfers"),
|
|
34924
|
+
uint160Raw(systemHash, "export.destSystemID"),
|
|
34925
|
+
// same chain
|
|
34926
|
+
uint160Raw(currencyHash, "export.destCurrencyID"),
|
|
34927
|
+
Buffer.from([0, 0]),
|
|
34928
|
+
// exporter: empty CTransferDestination
|
|
34929
|
+
int32LE(-1, "export.firstInput"),
|
|
34930
|
+
int32LE(0, "export.numInputs"),
|
|
34931
|
+
varInt(0n, "export.sourceHeightStart"),
|
|
34932
|
+
varInt(BigInt(height), "export.sourceHeightEnd"),
|
|
34933
|
+
currencyValueMap(fee, "export.totalFees"),
|
|
34934
|
+
currencyValueMap(fee, "export.totalAmounts"),
|
|
34935
|
+
currencyValueMap([], "export.totalBurned"),
|
|
34936
|
+
writeCompactSize(0)
|
|
34937
|
+
// reserveTransfers (empty)
|
|
34938
|
+
]);
|
|
34939
|
+
}
|
|
34940
|
+
function serializeReserveDeposit(systemHash, controllingHash, amount) {
|
|
34941
|
+
return Buffer.concat([
|
|
34942
|
+
varInt(1n, "reserveDeposit.version"),
|
|
34943
|
+
uint160Raw(systemHash, "reserveDeposit.currencyID"),
|
|
34944
|
+
varInt(amount, "reserveDeposit.amount"),
|
|
34945
|
+
uint160Raw(controllingHash, "reserveDeposit.controllingCurrencyID")
|
|
34946
|
+
]);
|
|
34947
|
+
}
|
|
34948
|
+
function buildIdentityChangeScript(identityHash) {
|
|
34949
|
+
const master = Buffer.from([4, 3, 0, 0, 0]);
|
|
34950
|
+
const idDest = Buffer.concat([Buffer.from([21, 4]), identityHash]);
|
|
34951
|
+
const params = Buffer.concat([Buffer.from([4, 3, 0, 1, 1]), idDest]);
|
|
34952
|
+
return Buffer.concat([
|
|
34953
|
+
Buffer.from([master.length]),
|
|
34954
|
+
master,
|
|
34955
|
+
Buffer.from([204]),
|
|
34956
|
+
// OP_CHECKCRYPTOCONDITION
|
|
34957
|
+
Buffer.from([params.length]),
|
|
34958
|
+
params,
|
|
34959
|
+
Buffer.from([117])
|
|
34960
|
+
// OP_DROP
|
|
34961
|
+
]);
|
|
34962
|
+
}
|
|
34963
|
+
function buildCurrencyLaunchOutputs(input, context) {
|
|
34964
|
+
const def = normalizeCurrencyDefinition(input);
|
|
34965
|
+
const identityAddress = context.identity.identityaddress;
|
|
34966
|
+
if (typeof identityAddress !== "string" || !identityAddress) {
|
|
34967
|
+
throw new TransactionBuildError("context.identity.identityaddress is required");
|
|
34968
|
+
}
|
|
34969
|
+
const derivedId = deriveIdentityAddress(def.name, def.parent);
|
|
34970
|
+
if (derivedId !== identityAddress) {
|
|
34971
|
+
throw new TransactionBuildError(
|
|
34972
|
+
`identity mismatch: currency "${def.name}" under ${def.parent} derives ${derivedId}, but context.identity.identityaddress is ${identityAddress}`
|
|
34973
|
+
);
|
|
34974
|
+
}
|
|
34975
|
+
if (!Number.isInteger(context.height) || context.height < 0) {
|
|
34976
|
+
throw new TransactionBuildError(`context.height must be a non-negative block height, got ${context.height}`);
|
|
34977
|
+
}
|
|
34978
|
+
if (def.startBlock <= context.height) {
|
|
34979
|
+
throw new TransactionBuildError(`startBlock (${def.startBlock}) must be greater than the current height (${context.height})`);
|
|
34980
|
+
}
|
|
34981
|
+
if (typeof context.identity.systemid === "string" && def.systemId !== context.identity.systemid) {
|
|
34982
|
+
throw new TransactionBuildError(`currency systemId (${def.systemId}) must equal the chain system id (${String(context.identity.systemid)})`);
|
|
34983
|
+
}
|
|
34984
|
+
if (context.launchFeeSats <= 0n) {
|
|
34985
|
+
throw new TransactionBuildError("context.launchFeeSats must be positive");
|
|
34986
|
+
}
|
|
34987
|
+
const systemHash = iAddressToHash(def.systemId);
|
|
34988
|
+
const currencyHash = iAddressToHash(identityAddress);
|
|
34989
|
+
const reserveHashes = def.currencies.map((c) => iAddressToHash(c));
|
|
34990
|
+
const isFractional = Boolean(def.options & CURRENCY_OPTION.FRACTIONAL);
|
|
34991
|
+
const importFee = context.launchFeeSats - context.launchFeeSats / 2n;
|
|
34992
|
+
const tokenSupply = def.preAllocations.reduce((sum, p) => sum + p.amount, 0n);
|
|
34993
|
+
const feeEntry = [{ hash: systemHash, amount: importFee }];
|
|
34994
|
+
const identityUpdate = buildIdentityUpdateOutput(context.identity, def.options);
|
|
34995
|
+
const currencyDefinition = {
|
|
34996
|
+
script: buildCurrencyDefinitionScript(input),
|
|
34997
|
+
value: 0n
|
|
34998
|
+
};
|
|
34999
|
+
const importOutput = {
|
|
35000
|
+
// exportTxOutNum = 4 points at the export output (same tx).
|
|
35001
|
+
script: wrapCcOutput(EVAL_CROSSCHAIN_IMPORT, [serializeImport(systemHash, currencyHash, 4, context.height)], {
|
|
35002
|
+
kind: "keyid",
|
|
35003
|
+
hash: CC_IMPORT_KEYHASH
|
|
35004
|
+
}).toString("hex"),
|
|
35005
|
+
value: 0n
|
|
35006
|
+
};
|
|
35007
|
+
const currencyState = serializeCoinbaseCurrencyState(
|
|
35008
|
+
currencyHash,
|
|
35009
|
+
reserveHashes,
|
|
35010
|
+
def.weights,
|
|
35011
|
+
isFractional,
|
|
35012
|
+
def.initialFractionalSupply,
|
|
35013
|
+
tokenSupply
|
|
35014
|
+
);
|
|
35015
|
+
const notarization = {
|
|
35016
|
+
script: wrapCcOutput(
|
|
35017
|
+
EVAL_ACCEPTEDNOTARIZATION,
|
|
35018
|
+
[serializeNotarization(currencyHash, currencyState, context.height)],
|
|
35019
|
+
pubkeyDest(EVAL_ACCEPTEDNOTARIZATION)
|
|
35020
|
+
).toString("hex"),
|
|
35021
|
+
value: 0n
|
|
35022
|
+
};
|
|
35023
|
+
const exportOutput = {
|
|
35024
|
+
script: wrapCcOutput(
|
|
35025
|
+
EVAL_CROSSCHAIN_EXPORT,
|
|
35026
|
+
[serializeExport(systemHash, currencyHash, context.height, feeEntry)],
|
|
35027
|
+
pubkeyDest(EVAL_CROSSCHAIN_EXPORT)
|
|
35028
|
+
).toString("hex"),
|
|
35029
|
+
value: 0n
|
|
35030
|
+
};
|
|
35031
|
+
const reserveDeposit = {
|
|
35032
|
+
script: wrapCcOutput(
|
|
35033
|
+
EVAL_RESERVE_DEPOSIT,
|
|
35034
|
+
[serializeReserveDeposit(systemHash, currencyHash, importFee)],
|
|
35035
|
+
pubkeyDest(EVAL_RESERVE_DEPOSIT)
|
|
35036
|
+
).toString("hex"),
|
|
35037
|
+
value: importFee
|
|
35038
|
+
};
|
|
35039
|
+
const change = {
|
|
35040
|
+
script: buildIdentityChangeScript(currencyHash).toString("hex"),
|
|
35041
|
+
value: 0n
|
|
35042
|
+
};
|
|
35043
|
+
const ordered = [identityUpdate, currencyDefinition, importOutput, notarization, exportOutput, reserveDeposit, change];
|
|
35044
|
+
return { identityUpdate, currencyDefinition, import: importOutput, notarization, export: exportOutput, reserveDeposit, change, ordered };
|
|
35045
|
+
}
|
|
35046
|
+
|
|
35047
|
+
// src/currency/launch.ts
|
|
35048
|
+
function buildCurrencyLaunchTransaction(params, network) {
|
|
35049
|
+
const wifCheck = validateWif(params.wif);
|
|
35050
|
+
if (!wifCheck.valid) {
|
|
35051
|
+
throw new InvalidWifError(wifCheck.error);
|
|
35052
|
+
}
|
|
35053
|
+
if (!params.fundingUtxos || params.fundingUtxos.length === 0) {
|
|
35054
|
+
throw new TransactionBuildError("at least one funding UTXO is required");
|
|
35055
|
+
}
|
|
35056
|
+
const identityAddress = params.identity.identityaddress;
|
|
35057
|
+
if (typeof identityAddress !== "string" || !identityAddress) {
|
|
35058
|
+
throw new TransactionBuildError("identity.identityaddress is required");
|
|
35059
|
+
}
|
|
35060
|
+
const chainId = NETWORK_CONFIG[network].chainId;
|
|
35061
|
+
const systemId = params.definition.systemId ?? params.definition.parent;
|
|
35062
|
+
if (systemId !== chainId) {
|
|
35063
|
+
throw new TransactionBuildError(`currency systemId/parent (${systemId}) must be the chain id (${chainId}) \u2014 this SDK launches same-chain currencies only`);
|
|
35064
|
+
}
|
|
35065
|
+
const verusNetwork = getNetwork(network === "testnet");
|
|
35066
|
+
assertWifIsPrimary(params.wif, boundary_exports.Identity.fromJson(params.identity), verusNetwork);
|
|
35067
|
+
const outputs = buildCurrencyLaunchOutputs(params.definition, {
|
|
35068
|
+
identity: params.identity,
|
|
35069
|
+
height: params.height,
|
|
35070
|
+
launchFeeSats: params.launchFeeSats
|
|
35071
|
+
});
|
|
35072
|
+
const consensusOutputs = outputs.ordered.slice(0, 6).map((o) => ({
|
|
35073
|
+
script: Buffer.from(o.script, "hex"),
|
|
35074
|
+
nativeSat: o.value
|
|
35075
|
+
}));
|
|
35076
|
+
const extraOutputBytes = consensusOutputs.reduce((sum, o) => sum + o.script.length, 0);
|
|
35077
|
+
const assembled = assembleFundedIdentityUpdate({
|
|
35078
|
+
network,
|
|
35079
|
+
wif: params.wif,
|
|
35080
|
+
// Default to a bounded expiry above the tip (matching the doc), NOT 0, which
|
|
35081
|
+
// would silently make the transaction never expire. Pass expiryHeight: 0
|
|
35082
|
+
// explicitly to opt into a never-expiring transaction.
|
|
35083
|
+
expiryHeight: params.expiryHeight ?? params.height + DEFAULT_EXPIRY_DELTA,
|
|
35084
|
+
funding: params.fundingUtxos,
|
|
35085
|
+
identityUtxo: params.identityUtxo,
|
|
35086
|
+
outputs: consensusOutputs,
|
|
35087
|
+
changeAddress: params.changeAddress ?? identityAddress,
|
|
35088
|
+
extraOutputBytes,
|
|
35089
|
+
label: "currency launch"
|
|
35090
|
+
});
|
|
35091
|
+
return {
|
|
35092
|
+
signedTx: assembled.signedTx,
|
|
35093
|
+
txid: assembled.txid,
|
|
35094
|
+
fee: assembled.fee,
|
|
35095
|
+
nativeChange: assembled.nativeChange,
|
|
35096
|
+
inputsUsed: assembled.inputsUsed,
|
|
35097
|
+
currencyAddress: identityAddress
|
|
35098
|
+
};
|
|
35099
|
+
}
|
|
35100
|
+
|
|
35101
|
+
// src/currency/reserveTransfer.ts
|
|
35102
|
+
var import_bn5 = __toESM(require("bn.js"));
|
|
35103
|
+
var EVAL_RESERVE_TRANSFER = 8;
|
|
35104
|
+
var RESERVE_TRANSFER_KEYHASH = Buffer.from("cb8a0f7f651b484a81e2312c3438deb601e27368", "hex");
|
|
35105
|
+
var MIN_TRANSFER_FEE = 20000n;
|
|
35106
|
+
var RT_VALID = 1;
|
|
35107
|
+
var RT_CONVERT = 2;
|
|
35108
|
+
var RT_PRECONVERT = 4;
|
|
35109
|
+
var DEST_ID3 = 4;
|
|
35110
|
+
var FLAG_DEST_AUX = 64;
|
|
35111
|
+
function buildReserveTransferOutput(params) {
|
|
35112
|
+
if (params.amount <= 0n) {
|
|
35113
|
+
throw new TransactionBuildError("amount must be positive");
|
|
35114
|
+
}
|
|
35115
|
+
if (params.feeAmount < MIN_TRANSFER_FEE) {
|
|
35116
|
+
throw new TransactionBuildError(`feeAmount must be at least ${MIN_TRANSFER_FEE} (the daemon's minimum transfer fee), got ${params.feeAmount}`);
|
|
35117
|
+
}
|
|
35118
|
+
parseIAddress(params.sourceCurrency, "sourceCurrency");
|
|
35119
|
+
parseIAddress(params.destCurrency, "destCurrency");
|
|
35120
|
+
parseIAddress(params.recipient, "recipient");
|
|
35121
|
+
if (params.refundAddress !== void 0) {
|
|
35122
|
+
parseIAddress(params.refundAddress, "refundAddress");
|
|
35123
|
+
}
|
|
35124
|
+
const feeCurrency = params.feeCurrency ?? params.sourceCurrency;
|
|
35125
|
+
parseIAddress(feeCurrency, "feeCurrency");
|
|
35126
|
+
if (feeCurrency !== params.sourceCurrency) {
|
|
35127
|
+
throw new TransactionBuildError("feeCurrency must equal sourceCurrency (this builder handles native-reserve transfers only)");
|
|
35128
|
+
}
|
|
35129
|
+
const flags = RT_VALID | RT_CONVERT | (params.preconvert ? RT_PRECONVERT : 0);
|
|
35130
|
+
const transfer2 = new boundary_exports.ReserveTransfer({
|
|
35131
|
+
// Single-value mode (multivalue:false) — the daemon's encoding for a
|
|
35132
|
+
// single-currency transfer: currency id + VARINT amount, no count prefix.
|
|
35133
|
+
values: new boundary_exports.CurrencyValueMap({
|
|
35134
|
+
value_map: /* @__PURE__ */ new Map([[params.sourceCurrency, new import_bn5.default(params.amount.toString())]]),
|
|
35135
|
+
multivalue: false
|
|
35136
|
+
}),
|
|
35137
|
+
version: new import_bn5.default(1),
|
|
35138
|
+
flags: new import_bn5.default(flags),
|
|
35139
|
+
fee_currency_id: feeCurrency,
|
|
35140
|
+
fee_amount: new import_bn5.default(params.feeAmount.toString()),
|
|
35141
|
+
transfer_destination: boundary_exports.TransferDestination.fromJson({
|
|
35142
|
+
type: DEST_ID3 | FLAG_DEST_AUX,
|
|
35143
|
+
address: params.recipient,
|
|
35144
|
+
auxdests: [{ type: DEST_ID3, address: params.refundAddress ?? params.recipient }]
|
|
35145
|
+
}),
|
|
35146
|
+
dest_currency_id: params.destCurrency
|
|
35147
|
+
});
|
|
35148
|
+
const script2 = wrapCcOutput(EVAL_RESERVE_TRANSFER, [transfer2.toBuffer()], {
|
|
35149
|
+
kind: "keyid",
|
|
35150
|
+
hash: RESERVE_TRANSFER_KEYHASH
|
|
35151
|
+
}).toString("hex");
|
|
35152
|
+
return { script: script2, value: params.amount + params.feeAmount };
|
|
35153
|
+
}
|
|
35154
|
+
|
|
35155
|
+
// src/currency/index.ts
|
|
35156
|
+
var import_bn6 = __toESM(require("bn.js"));
|
|
34316
35157
|
function defineCurrency(params, network) {
|
|
34317
35158
|
const wifCheck = validateWif(params.wif);
|
|
34318
35159
|
if (!wifCheck.valid) {
|
|
@@ -34327,6 +35168,7 @@ function defineCurrency(params, network) {
|
|
|
34327
35168
|
if (!params.currencyDefScript) {
|
|
34328
35169
|
throw new TransactionBuildError("currencyDefScript is required");
|
|
34329
35170
|
}
|
|
35171
|
+
const currencyDefScriptHex = params.currencyDefScript;
|
|
34330
35172
|
const verusNetwork = getNetwork(network === "testnet");
|
|
34331
35173
|
const currencyDefValue = params.currencyDefValue || 0n;
|
|
34332
35174
|
const identity = new boundary_exports.Identity();
|
|
@@ -34334,11 +35176,11 @@ function defineCurrency(params, network) {
|
|
|
34334
35176
|
assertWifIsPrimary(params.wif, identity, verusNetwork);
|
|
34335
35177
|
if (!identity.hasActiveCurrency()) {
|
|
34336
35178
|
const currentFlags = identity.flags.toNumber();
|
|
34337
|
-
identity.flags = new
|
|
35179
|
+
identity.flags = new import_bn6.default(currentFlags | IDENTITY_FLAG_ACTIVECURRENCY);
|
|
34338
35180
|
}
|
|
34339
35181
|
const identityScript = boundary_exports.IdentityScript.fromIdentity(identity);
|
|
34340
35182
|
const identityOutputScript = identityScript.toBuffer();
|
|
34341
|
-
const currencyDefScript = Buffer.from(
|
|
35183
|
+
const currencyDefScript = Buffer.from(currencyDefScriptHex, "hex");
|
|
34342
35184
|
const assembled = assembleFundedIdentityUpdate({
|
|
34343
35185
|
network,
|
|
34344
35186
|
wif: params.wif,
|
|
@@ -35151,10 +35993,47 @@ var VerusSDK = class {
|
|
|
35151
35993
|
);
|
|
35152
35994
|
}
|
|
35153
35995
|
// ─── Currency ──────────────────────────────────────
|
|
35154
|
-
/**
|
|
35996
|
+
/**
|
|
35997
|
+
* Assemble the identity-spend + currency-definition output for a currency.
|
|
35998
|
+
*
|
|
35999
|
+
* A partial helper — NOT a full launch. For a complete, broadcastable launch
|
|
36000
|
+
* built entirely offline (all seven outputs), use
|
|
36001
|
+
* {@link VerusSDK.buildCurrencyLaunchTransaction}. To build only the definition
|
|
36002
|
+
* output script, use {@link VerusSDK.buildCurrencyDefinitionScript}.
|
|
36003
|
+
*/
|
|
35155
36004
|
defineCurrency(params) {
|
|
35156
36005
|
return defineCurrency(params, this.network);
|
|
35157
36006
|
}
|
|
36007
|
+
/**
|
|
36008
|
+
* Serialize a currency definition (token or fractional basket) to its
|
|
36009
|
+
* EVAL_CURRENCY_DEFINITION output script — offline, byte-equivalent to the
|
|
36010
|
+
* daemon's `definecurrency`. For building/inspecting/verifying the definition
|
|
36011
|
+
* script; a full on-chain launch is a daemon operation (see `defineCurrency`).
|
|
36012
|
+
*/
|
|
36013
|
+
buildCurrencyDefinitionScript(input) {
|
|
36014
|
+
return buildCurrencyDefinitionScript(input);
|
|
36015
|
+
}
|
|
36016
|
+
/**
|
|
36017
|
+
* Build all seven output scripts of a currency-definition transaction offline,
|
|
36018
|
+
* byte-equivalent to `definecurrency` — identity update, currency definition,
|
|
36019
|
+
* import, notarization (with currency state), export, reserve deposit, and
|
|
36020
|
+
* change. Needs the defining identity (from a lite node's `getidentity`), the
|
|
36021
|
+
* current chain tip height, and the chain's currency launch fee. Produces the
|
|
36022
|
+
* output scripts; funding, the identity input, and signing are assembled
|
|
36023
|
+
* separately (see `CurrencyLaunchContext`).
|
|
36024
|
+
*/
|
|
36025
|
+
buildCurrencyLaunchOutputs(input, context) {
|
|
36026
|
+
return buildCurrencyLaunchOutputs(input, context);
|
|
36027
|
+
}
|
|
36028
|
+
/**
|
|
36029
|
+
* Build and sign a full, broadcastable currency-definition transaction offline:
|
|
36030
|
+
* the seven byte-locked outputs, funded from the supplied UTXOs, with the
|
|
36031
|
+
* defining identity spent under primary authority. Hand the signed hex to any
|
|
36032
|
+
* node to launch the currency. See `CurrencyLaunchTxParams`.
|
|
36033
|
+
*/
|
|
36034
|
+
buildCurrencyLaunchTransaction(params) {
|
|
36035
|
+
return buildCurrencyLaunchTransaction(params, this.network);
|
|
36036
|
+
}
|
|
35158
36037
|
// ─── Message Signing ───────────────────────────────
|
|
35159
36038
|
/** Sign a message with a VerusID identity signature */
|
|
35160
36039
|
signMessage(params) {
|
|
@@ -35282,6 +36161,7 @@ __export(public_exports2, {
|
|
|
35282
36161
|
AMOUNT_DECIMALS,
|
|
35283
36162
|
BASE58_RE,
|
|
35284
36163
|
CONSENSUS_BRANCH_ID,
|
|
36164
|
+
CURRENCY_OPTION,
|
|
35285
36165
|
CURRENCY_TYPE_ORDER,
|
|
35286
36166
|
DEFAULT_EXPIRY_DELTA,
|
|
35287
36167
|
DEFAULT_FEE_PER_KB,
|
|
@@ -35298,6 +36178,8 @@ __export(public_exports2, {
|
|
|
35298
36178
|
InvalidNameError,
|
|
35299
36179
|
InvalidWifError,
|
|
35300
36180
|
NETWORK_CONFIG,
|
|
36181
|
+
NOTARIZATION_PROTOCOL,
|
|
36182
|
+
PROOF_PROTOCOL,
|
|
35301
36183
|
PUBKEY_HASH_PREFIX,
|
|
35302
36184
|
RESERVE_TRANSFER_FEE,
|
|
35303
36185
|
SATS_PER_COIN,
|
|
@@ -35309,6 +36191,10 @@ __export(public_exports2, {
|
|
|
35309
36191
|
VerusSDK,
|
|
35310
36192
|
WIF_PREFIX,
|
|
35311
36193
|
address,
|
|
36194
|
+
buildCurrencyDefinitionScript,
|
|
36195
|
+
buildCurrencyLaunchOutputs,
|
|
36196
|
+
buildCurrencyLaunchTransaction,
|
|
36197
|
+
buildReserveTransferOutput,
|
|
35312
36198
|
classifyCurrency,
|
|
35313
36199
|
currency,
|
|
35314
36200
|
identity,
|
|
@@ -35321,6 +36207,7 @@ __export(public_exports2, {
|
|
|
35321
36207
|
message,
|
|
35322
36208
|
offers,
|
|
35323
36209
|
parseSats,
|
|
36210
|
+
serializeCurrencyDefinition,
|
|
35324
36211
|
signing,
|
|
35325
36212
|
toCoins,
|
|
35326
36213
|
toSafeNumber,
|