UNPKG

@dashevo/dashcore-lib

Version:

A pure and powerful JavaScript Dash library.

1 lines 1.65 MB
!function(A,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.dashcore=t():A.dashcore=t()}(self,(()=>(()=>{var A={6010:(A,t,e)=>{"use strict";var r=e(8764).Buffer;const{configure:i}=e(8065);var n=A.exports;n.version="v"+e(4147).i8,n.versionGuard=function(A){if(void 0!==A){console.warn("More than one instance of dashcore-lib found. Please make sure that you are not mixing instances of classes of the different versions of dashcore.")}},n.versionGuard(e.g._dashcore),e.g._dashcore=n.version,n.crypto={},n.crypto.BN=e(5441),n.crypto.BLS=e(2138),n.crypto.ECDSA=e(6836),n.crypto.Hash=e(1018),n.crypto.Random=e(8199),n.crypto.Point=e(287),n.crypto.Signature=e(6146),n.Signer=e(6239),n.encoding={},n.encoding.Base58=e(9853),n.encoding.Base58Check=e(96),n.encoding.BufferReader=e(6907),n.encoding.BufferWriter=e(6133),n.encoding.Varint=e(6057),n.util={},n.util.buffer=e(4102),n.util.js=e(3336),n.util.preconditions=e(5099),n.util.hashUtil=e(8055),n.util.merkleTree=e(7656),n.errors=e(6485),n.Address=e(6577),n.Block=e(7534),n.MerkleBlock=e(5146),n.QuorumEntry=e(8715),n.SimplifiedMNList=e(6489),n.SimplifiedMNListDiff=e(425),n.SimplifiedMNListEntry=e(2724),n.BlockHeader=e(6088),n.HDPrivateKey=e(2676),n.HDPublicKey=e(6648),n.Networks=e(4205),n.Opcode=e(1524),n.PrivateKey=e(1812),n.PublicKey=e(5882),n.Script=e(2727),n.Transaction=e(4437),n.GovObject=e(3712),n.URI=e(4681),n.Unit=e(6525),n.Message=e(6695),n.Mnemonic=e(1359),n.BloomFilter=e(4830),n.ChainLock=e(253),n.InstantLock=e(8795),n.ZmqMessages={ChainLockSigMessage:e(1786)},n.deps={},n.deps.bnjs=e(3550),n.deps.bs58=e(7191),n.deps.Buffer=r,n.deps.elliptic=e(6266),n.deps._=e(6486),n.Transaction.sighash=e(6459),n.configure=i},6577:(A,t,e)=>{"use strict";var r=e(8764).Buffer,i=e(6486),n=e(5099),o=e(6485),g=e(96),a=e(4205),s=e(1018),I=e(3336),B=e(5882);function u(A,t,e){if(!(this instanceof u))return new u(A,t,e);if(i.isArray(A)&&i.isNumber(t))return u.createMultisig(A,t,e);if(A instanceof u)return A;if(n.checkArgument(A,"First argument is required, please include address data.","guide/address.html"),t&&!a.get(t))throw new TypeError('Second argument must be "livenet" or "testnet".');if(e&&e!==u.PayToPublicKeyHash&&e!==u.PayToScriptHash)throw new TypeError('Third argument must be "pubkeyhash" or "scripthash".');var r=this._classifyArguments(A,t,e);return r.network=r.network||a.get(t)||a.defaultNetwork,r.type=r.type||e||u.PayToPublicKeyHash,I.defineImmutable(this,{hashBuffer:r.hashBuffer,network:r.network,type:r.type}),this}u.prototype._classifyArguments=function(A,t,n){if(E=e(4240),(A instanceof r||A instanceof Uint8Array)&&20===A.length)return u._transformHash(A);if((A instanceof r||A instanceof Uint8Array)&&21===A.length)return u._transformBuffer(A,t,n);if(A instanceof B)return u._transformPublicKey(A);if(A instanceof E)return u._transformScript(A,t);if("string"==typeof A)return u._transformString(A,t,n);if(i.isObject(A))return u._transformObject(A);throw new TypeError("First argument is an unrecognized data format.")},u.PayToPublicKeyHash="pubkeyhash",u.PayToScriptHash="scripthash",u._transformHash=function(A){var t={};if(!(A instanceof r||A instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(20!==A.length)throw new TypeError("Address hashbuffers must be exactly 20 bytes.");return t.hashBuffer=A,t},u._transformObject=function(A){return n.checkArgument(A.hash||A.hashBuffer,"Must provide a `hash` or `hashBuffer` property"),n.checkArgument(A.type,"Must provide a `type` property"),{hashBuffer:A.hash?r.from(A.hash,"hex"):A.hashBuffer,network:a.get(A.network)||a.defaultNetwork,type:A.type}},u._classifyFromVersion=function(A){var t={},e=a.get(A[0],"pubkeyhash"),r=a.get(A[0],"scripthash");return e?(t.network=e,t.type=u.PayToPublicKeyHash):r&&(t.network=r,t.type=u.PayToScriptHash),t},u._transformBuffer=function(A,t,e){var i={};if(!(A instanceof r||A instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(21!==A.length)throw new TypeError("Address buffers must be exactly 21 bytes.");t=a.get(t);var n=u._classifyFromVersion(A);if(!n.network||t&&t!==n.network)throw new TypeError("Address has mismatched network type.");if(!n.type||e&&e!==n.type)throw new TypeError("Address has mismatched type.");return i.hashBuffer=A.slice(1),i.network=n.network,i.type=n.type,i},u._transformPublicKey=function(A){var t={};if(!(A instanceof B))throw new TypeError("Address must be an instance of PublicKey.");return t.hashBuffer=s.sha256ripemd160(A.toBuffer()),t.type=u.PayToPublicKeyHash,t},u._transformScript=function(A,t){n.checkArgument(A instanceof E,"script must be a Script instance");var e=A.getAddressInfo(t);if(!e)throw new o.Script.CantDeriveAddress(A);return e},u.createMultisig=function(A,t,e){return e=e||A[0].network||a.defaultNetwork,u.payingTo(E.buildMultisigOut(A,t),e)},u._transformString=function(A,t,e){if("string"!=typeof A)throw new TypeError("data parameter supplied is not a string.");A=A.trim();var r=g.decode(A);return u._transformBuffer(r,t,e)},u.fromPublicKey=function(A,t){var e=u._transformPublicKey(A);return t=t||a.defaultNetwork,new u(e.hashBuffer,t,e.type)},u.fromPublicKeyHash=function(A,t){var e=u._transformHash(A);return new u(e.hashBuffer,t,u.PayToPublicKeyHash)},u.fromScriptHash=function(A,t){n.checkArgument(A,"hash parameter is required");var e=u._transformHash(A);return new u(e.hashBuffer,t,u.PayToScriptHash)},u.payingTo=function(A,t){return n.checkArgument(A,"script is required"),n.checkArgument(A instanceof E,"script must be instance of Script"),u.fromScriptHash(s.sha256ripemd160(A.toBuffer()),t)},u.fromScript=function(A,t){n.checkArgument(A instanceof E,"script must be a Script instance");var e=u._transformScript(A,t);return new u(e.hashBuffer,t,e.type)},u.fromBuffer=function(A,t,e){var r=u._transformBuffer(A,t,e);return new u(r.hashBuffer,r.network,r.type)},u.fromString=function(A,t,e){var r=u._transformString(A,t,e);return new u(r.hashBuffer,r.network,r.type)},u.fromObject=function(A){return n.checkState(I.isHexa(A.hash),'Unexpected hash property, "'+A.hash+'", expected to be hex.'),new u(r.from(A.hash,"hex"),A.network,A.type)},u.getValidationError=function(A,t,e){var r;try{new u(A,t,e)}catch(A){r=A}return r},u.isValid=function(A,t,e){return!u.getValidationError(A,t,e)},u.prototype.isPayToPublicKeyHash=function(){return this.type===u.PayToPublicKeyHash},u.prototype.isPayToScriptHash=function(){return this.type===u.PayToScriptHash},u.prototype.toBuffer=function(){var A=r.from([this.network[this.type]]);return r.concat([A,this.hashBuffer])},u.prototype.toObject=u.prototype.toJSON=function(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}},u.prototype.toString=function(){return g.encode(this.toBuffer())},u.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"},A.exports=u;var E=e(2727)},9116:(A,t,e)=>{var r=e(8764).Buffer;const i=e(3218),n=e(6907),o=e(6133),g=e(4102),a=e(3336).isHexa,s=e(2087),I=e(7656),B=e(93),{convertBitArrayToUInt8Array:u}=B;function E(A){if(A){if(A instanceof E)return A.copy();if(g.isBuffer(A))return E.fromBuffer(A);if(a(A))return E.fromHexString(A);if(!i(A))throw new Error("Invalid argument passed to PartialMerkleTree - expected hex string, object or buffer");{const t=I.calculateTreeHeight(A.transactionHashes.length),e=I.traverseAndBuildPartialTree(t,0,A.transactionHashes,A.filterMatches);this.totalTransactions=A.transactionHashes.length,this.merkleFlags=u(e.flags,!0),this.merkleHashes=e.merkleHashes}}}E.fromBufferReader=function(A){const t=new E;t.totalTransactions=A.readUInt32LE();const e=A.readVarintNum();t.merkleHashes=[];for(let r=0;r<e;r+=1)t.merkleHashes.push(A.read(s.SHA256_HASH_SIZE).reverse().toString("hex"));const r=A.readVarintNum();t.merkleFlags=[];for(let e=0;e<r;e+=1)t.merkleFlags.push(A.readUInt8());return t},E.fromBuffer=function(A){return E.fromBufferReader(new n(A))},E.fromHexString=function(A){return E.fromBuffer(r.from(A,"hex"))},E.prototype.toBuffer=function(){const A=new o;return A.writeUInt32LE(this.totalTransactions),A.writeVarintNum(this.merkleHashes.length),this.merkleHashes.forEach((t=>{A.write(r.from(t,"hex").reverse())})),A.writeVarintNum(this.merkleFlags.length),this.merkleFlags.forEach((t=>{A.writeUInt8(t)})),A.toBuffer()},E.prototype.copy=function(){return E.fromBuffer(this.toBuffer())},E.prototype.toString=function(){return this.toBuffer().toString("hex")},A.exports=E},1281:(A,t,e)=>{var r=e(8764).Buffer;const i=e(6486),n=e(6088),o=e(5441),g=e(4102),a=e(6907),s=e(6133),I=e(1018),B=e(4437),u=e(5099);function E(A){return this instanceof E?(i.extend(this,E._from(A)),this):new E(A)}E.MAX_BLOCK_SIZE=1e6,E._from=function(A){let t={};if(g.isBuffer(A))t=E._fromBufferReader(a(A));else{if(!i.isObject(A))throw new TypeError("Unrecognized argument for Block");t=E._fromObject(A)}return t},E._fromObject=function(A){const t=[];A.transactions.forEach((A=>{A instanceof B?t.push(A):t.push(B().fromObject(A))}));return{header:n.fromObject(A.header),transactions:t}},E.fromObject=function(A){const t=E._fromObject(A);return new E(t)},E._fromBufferReader=function(A){const t={};u.checkState(!A.finished(),"No block data received"),t.header=n.fromBufferReader(A);const e=A.readVarintNum();t.transactions=[];for(let r=0;r<e;r+=1)t.transactions.push(B().fromBufferReader(A));return t},E.fromBufferReader=function(A){u.checkArgument(A,"br is required");const t=E._fromBufferReader(A);return new E(t)},E.fromBuffer=function(A){return E.fromBufferReader(new a(A))},E.fromString=function(A){const t=r.from(A,"hex");return E.fromBuffer(t)},E.fromRawBlock=function(A){let t=A;g.isBuffer(A)||(t=r.from(A,"binary"));const e=a(t);e.pos=E.Values.START_OF_BLOCK;const i=E._fromBufferReader(e);return new E(i)},E.prototype.toJSON=function(){const A=[];return this.transactions.forEach((t=>{A.push(t.toObject())})),{header:this.header.toObject(),transactions:A}},E.prototype.toObject=E.prototype.toJSON,E.prototype.toBuffer=function(){return this.toBufferWriter().toBuffer()},E.prototype.toString=function(){return this.toBuffer().toString("hex")},E.prototype.toBufferWriter=function(A){const t=A||new s;t.write(this.header.toBuffer()),t.writeVarintNum(this.transactions.length);for(let A=0;A<this.transactions.length;A+=1)this.transactions[A].toBufferWriter(t);return t},E.prototype.getTransactionHashes=function(){const A=[];if(0===this.transactions.length)return[E.Values.NULL_HASH];for(let t=0;t<this.transactions.length;t+=1)A.push(this.transactions[t]._getHash());return A},E.prototype.getMerkleTree=function(){const A=this.getTransactionHashes();let t=0;for(let e=this.transactions.length;e>1;e=Math.floor((e+1)/2)){for(let i=0;i<e;i+=2){const n=Math.min(i+1,e-1),o=r.concat([A[t+i],A[t+n]]);A.push(I.sha256sha256(o))}t+=e}return A},E.prototype.getMerkleRoot=function(){const A=this.getMerkleTree();return A[A.length-1]},E.prototype.validMerkleRoot=function(){const A=new o(this.header.merkleRoot.toString("hex"),"hex"),t=new o(this.getMerkleRoot().toString("hex"),"hex");return 0===A.cmp(t)},E.prototype._getHash=function(){return this.header._getHash()};const C={configurable:!1,enumerable:!0,get(){return this._id||(this._id=this.header.id),this._id},set:i.noop};Object.defineProperty(E.prototype,"id",C),Object.defineProperty(E.prototype,"hash",C),E.prototype.inspect=function(){return`<Block ${this.id}>`},E.Values={START_OF_BLOCK:8,NULL_HASH:r.from("0000000000000000000000000000000000000000000000000000000000000000","hex")},A.exports=E},6088:(A,t,e)=>{var r=e(8764).Buffer;const i=e(6486),n=e(5441),{isBuffer:o,reverse:g}=e(4102),a=e(6907),s=e(6133),I=e(1018),B=e(5099),u=function A(t){if(!(this instanceof A))return new A(t);const e=A._from(t);return this.version=e.version,this.prevHash=e.prevHash,this.merkleRoot=e.merkleRoot,this.time=e.time,this.timestamp=e.time,this.bits=e.bits,this.nonce=e.nonce,e.hash&&B.checkState(this.hash===e.hash,"Argument object hash property does not match block hash."),this};u._from=function(A){let t={};if(o(A))t=u._fromBufferReader(a(A));else{if(!i.isObject(A))throw new TypeError("Unrecognized argument for BlockHeader");t=u._fromObject(A)}return t},u._fromObject=function(A){B.checkArgument(A,"data is required");let{prevHash:t,merkleRoot:e}=A;i.isString(A.prevHash)&&(t=g(r.from(A.prevHash,"hex"))),i.isString(A.merkleRoot)&&(e=g(r.from(A.merkleRoot,"hex")));return{hash:A.hash,version:A.version,prevHash:t,merkleRoot:e,time:A.time,timestamp:A.time,bits:A.bits,nonce:A.nonce}},u.fromObject=function(A){const t=u._fromObject(A);return new u(t)},u.fromRawBlock=function(A){let t=A;o(t)||(t=r.from(t,"binary"));const e=a(t);e.pos=u.Constants.START_OF_HEADER;const i=u._fromBufferReader(e);return new u(i)},u.fromBuffer=function(A){const t=u._fromBufferReader(a(A));return new u(t)},u.fromString=function(A){const t=r.from(A,"hex");return u.fromBuffer(t)},u._fromBufferReader=function(A){const t={};return t.version=A.readInt32LE(),t.prevHash=A.read(32),t.merkleRoot=A.read(32),t.time=A.readUInt32LE(),t.bits=A.readUInt32LE(),t.nonce=A.readUInt32LE(),t},u.fromBufferReader=function(A){const t=u._fromBufferReader(A);return new u(t)},u.prototype.toJSON=function(){return{hash:this.hash,version:this.version,prevHash:g(this.prevHash).toString("hex"),merkleRoot:g(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}},u.prototype.toObject=u.prototype.toJSON,u.prototype.toBuffer=function(){return this.toBufferWriter().toBuffer()},u.prototype.toString=function(){return this.toBuffer().toString("hex")},u.prototype.toBufferWriter=function(A){const t=A||new s;return t.writeInt32LE(this.version),t.write(this.prevHash),t.write(this.merkleRoot),t.writeUInt32LE(this.time),t.writeUInt32LE(this.bits),t.writeUInt32LE(this.nonce),t},u.prototype.getTargetDifficulty=function(A){const t=A||this.bits;let e=new n(16777215&t),r=8*((t>>>24)-3);for(;r-- >0;)e=e.mul(new n(2));return e},u.prototype.getDifficulty=function(){const A=this.getTargetDifficulty(486604799).mul(new n(10**8)),t=this.getTargetDifficulty();let e=A.div(t).toString(10);const r=e.length-8;return e=`${e.slice(0,r)}.${e.slice(r)}`,parseFloat(e)},u.prototype._getHash=function(){const A=this.toBuffer();return I.x11(A)};const E={configurable:!1,enumerable:!0,get(){return this._id||(this._id=a(this._getHash()).readReverse().toString("hex")),this._id},set:i.noop};Object.defineProperty(u.prototype,"id",E),Object.defineProperty(u.prototype,"hash",E),u.prototype.validTimestamp=function(){const A=Math.round((new Date).getTime()/1e3);return!(this.time>A+u.Constants.MAX_TIME_OFFSET)},u.prototype.validProofOfWork=function(){const A=new n(this.id,"hex"),t=this.getTargetDifficulty();return!(A.cmp(t)>0)},u.prototype.inspect=function(){return`<BlockHeader ${this.id}>`},u.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:7200,LARGEST_HASH:new n("10000000000000000000000000000000000000000000000000000000000000000","hex")},A.exports=u},7534:(A,t,e)=>{A.exports=e(1281),A.exports.BlockHeader=e(6088),A.exports.MerkleBlock=e(5146)},5146:(A,t,e)=>{var r=e(8764).Buffer;const i=e(6486),n=e(6088),o=e(4102),g=e(6907),a=e(6133),s=e(1018),I=e(4437),B=e(9116),u=e(5099);function E(A){if(!(this instanceof E))return new E(A);let t={};if(o.isBuffer(A))t=E._fromBufferReader(g(A));else{if(!i.isObject(A))throw new TypeError("Unrecognized argument for MerkleBlock");{let e;e=A.header instanceof n?A.header:n.fromObject(A.header),t={header:e,numTransactions:A.numTransactions,hashes:A.hashes,flags:A.flags}}}return i.extend(this,t),this._flagBitsUsed=0,this._hashesUsed=0,this}E.build=function(A,t,e){const r=new B({transactionHashes:t,filterMatches:e});return new E({header:A,numTransactions:r.totalTransactions,hashes:r.merkleHashes,flags:r.merkleFlags})},E.fromBuffer=function(A){return E.fromBufferReader(g(A))},E.fromBufferReader=function(A){return new E(E._fromBufferReader(A))},E.prototype.toBuffer=function(){return this.toBufferWriter().toBuffer()},E.prototype.toBufferWriter=function(A){const t=A||new a;t.write(this.header.toBuffer()),t.writeUInt32LE(this.numTransactions),t.writeVarintNum(this.hashes.length);for(let A=0;A<this.hashes.length;A+=1)t.write(r.from(this.hashes[A],"hex"));t.writeVarintNum(this.flags.length);for(let A=0;A<this.flags.length;A+=1)t.writeUInt8(this.flags[A]);return t},E.prototype.toJSON=function(){return{header:this.header.toObject(),numTransactions:this.numTransactions,hashes:this.hashes,flags:this.flags}},E.prototype.toObject=E.prototype.toJSON,E.prototype.validMerkleTree=function(){if(u.checkState(i.isArray(this.flags),"MerkleBlock flags is not an array"),u.checkState(i.isArray(this.hashes),"MerkleBlock hashes is not an array"),this.hashes.length>this.numTransactions)return!1;if(8*this.flags.length<this.hashes.length)return!1;const A=this._calcTreeHeight(),t={hashesUsed:0,flagBitsUsed:0},e=this._traverseMerkleTree(A,0,t);return t.hashesUsed===this.hashes.length&&o.equals(e,this.header.merkleRoot)},E.prototype._traverseMerkleTree=function(A,t,e){const i=e||{};if(i.txs=e.txs||[],i.flagBitsUsed=e.flagBitsUsed||0,i.hashesUsed=e.hashesUsed||0,i.flagBitsUsed>8*this.flags.length)return null;const n=this.flags[i.flagBitsUsed>>3]>>>(7&i.flagBitsUsed++)&1;if(0===A||!n){if(i.hashesUsed>=this.hashes.length)return null;const t=this.hashes[i.hashesUsed++];return 0===A&&n&&i.txs.push(t),r.from(t,"hex")}const o=this._traverseMerkleTree(A-1,2*t,i);let g=o;return 2*t+1<this._calcTreeWidth(A-1)&&(g=this._traverseMerkleTree(A-1,2*t+1,i)),s.sha256sha256(r.concat([o,g]))},E.prototype._calcTreeWidth=function(A){return this.numTransactions+(1<<A)-1>>A},E.prototype._calcTreeHeight=function(){let A=0;for(;this._calcTreeWidth(A)>1;)A+=1;return A},E.prototype.getMatchedTransactionHashes=function(){const A=[],t=this._calcTreeHeight();return this._traverseMerkleTree(t,0,{txs:A}),A},E.prototype.hasTransaction=function(A){u.checkArgument(!i.isUndefined(A),"tx cannot be undefined"),u.checkArgument(A instanceof I||"string"==typeof A,'Invalid tx given, tx must be a "string" or "Transaction"');let t=A;A instanceof I&&(t=o.reverse(r.from(A.id,"hex")).toString("hex"));return-1!==this.getMatchedTransactionHashes().indexOf(t)},E._fromBufferReader=function(A){u.checkState(!A.finished(),"No merkleblock data received");const t={};t.header=n.fromBufferReader(A),t.numTransactions=A.readUInt32LE();const e=A.readVarintNum();t.hashes=[];for(let r=0;r<e;r+=1)t.hashes.push(A.read(32).toString("hex"));const r=A.readVarintNum();t.flags=[];for(let e=0;e<r;e+=1)t.flags.push(A.readUInt8());return t},E.fromObject=function(A){return new E(A)},A.exports=E},4830:(A,t,e)=>{"use strict";var r=e(2573),i=e(6907),n=e(6133);r.fromBuffer=function(A){var t={},e=new i(A),n=e.readVarintNum();t.vData=[];for(var o=0;o<n;o++)t.vData.push(e.readUInt8());return t.nHashFuncs=e.readUInt32LE(),t.nTweak=e.readUInt32LE(),t.nFlags=e.readUInt8(),new r(t)},r.prototype.toBuffer=function(){var A=new n;A.writeVarintNum(this.vData.length);for(var t=0;t<this.vData.length;t++)A.writeUInt8(this.vData[t]);return A.writeUInt32LE(this.nHashFuncs),A.writeUInt32LE(this.nTweak),A.writeUInt8(this.nFlags),A.concat()},A.exports=r},253:(A,t,e)=>{var r=e(8764).Buffer;const{isObject:i,isString:n}=e(6486),o=e(6907),g=e(6133),a=e(4102),s=e(5099),I=e(2087),B=e(1018).sha256sha256,{isHexaString:u,isUnsignedInteger:E,isHexStringOfSize:C}=e(3336),{SHA256_HASH_SIZE:c,BLS_SIGNATURE_SIZE:h}=I,Q=e(2138);class f{constructor(A){if(A instanceof f)return A.copy();const t=f._from(A);return this.height=t.height,this.blockHash=t.blockHash,this.signature=t.signature,this}static get CLSIG_REQUESTID_PREFIX(){return"clsig"}static _from(A){let t={};if(a.isBuffer(A))t=f._fromBufferReader(o(A));else if(i(A))t=f._fromObject(A);else{if(!u(A))throw new TypeError("Unrecognized argument for ChainLock");t=f.fromHex(A)}return t}static _fromObject(A){s.checkArgument(A,"data is required");let t=A.blockHash||A.blockhash,{signature:e}=A;return n(t)&&(t=r.from(t,"hex")),n(A.signature)&&(e=r.from(A.signature,"hex")),{height:A.height,blockHash:t,signature:e}}static _fromBufferReader(A){const t={};return t.height=A.readInt32LE(),t.blockHash=A.readReverse(c),t.signature=A.read(h),t}static fromBufferReader(A){s.checkArgument(A,"br is required");const t=f._fromBufferReader(A);return new f(t)}static fromString(A){return f.fromBuffer(r.from(A,"hex"))}static fromHex(A){return f.fromString(A)}static fromBuffer(A){return f.fromBufferReader(new o(A))}static fromObject(A){const t=f._fromObject(A);return new f(t)}async verifySignatureAgainstQuorum(A,t){return Q.verifySignature(this.signature.toString("hex"),this.getSignHashForQuorumEntry(A,t),A.quorumPublicKey)}async verifySignatureWithQuorumOffset(A,t,e){const r=this.selectSignatoryQuorum(A,t,e);let i=!1;return null!==r&&(i=await this.verifySignatureAgainstQuorum(r,t)),i||e!==I.LLMQ_SIGN_HEIGHT_OFFSET?i||0!==e||(i=await this.verifySignatureWithQuorumOffset(A,t,2*I.LLMQ_SIGN_HEIGHT_OFFSET)):i=await this.verifySignatureWithQuorumOffset(A,t,0),i}async verify(A){const t=this.getRequestId();return this.verifySignatureWithQuorumOffset(A,t,I.LLMQ_SIGN_HEIGHT_OFFSET)}validate(){s.checkArgument(E(this.height),"Expect height to be an unsigned integer"),s.checkArgument(C(this.blockHash.toString("hex"),2*c),`Expected blockhash to be a hex string of size ${c}`),s.checkArgument(C(this.signature.toString("hex"),2*h),"Expected signature to be a bls signature")}getHash(){return B(this.toBuffer())}getRequestId(){const A=new g,t=f.CLSIG_REQUESTID_PREFIX,e=t.length;return A.writeVarintNum(e),A.write(r.from(t,"utf-8")),A.writeUInt32LE(this.height),B(A.toBuffer()).reverse()}selectSignatoryQuorum(A,t,e){const i=A.getSMLbyHeight(this.height-e),n=i.calculateSignatoryQuorumScores(i.getChainlockLLMQType(),t);return 0===n.length?null:(n.sort(((A,t)=>r.compare(A.score,t.score))),n[0].quorum)}getSignHashForQuorumEntry(A,t){const{llmqType:e,quorumHash:i}=A,{blockHash:n}=this,o=new g;return o.writeUInt8(e),o.writeReverse(r.from(i,"hex")),o.writeReverse(t),o.writeReverse(n),B(o.toBuffer())}toObject(){return{height:this.height,blockHash:this.blockHash.toString("hex"),signature:this.signature.toString("hex")}}toJSON(){return this.toObject()}toString(){return this.toBuffer().toString("hex")}toBuffer(){return this.toBufferWriter().toBuffer()}toBufferWriter(A){const t=A||new g;return t.writeInt32LE(this.height),t.write(r.from(this.blockHash).reverse()),t.write(this.signature),t}copy(){return f.fromBuffer(this.toBuffer())}inspect(){return`<ChainLock: ${this.blockHash.toString("hex")}, height: ${this.height}>`}}A.exports=f},8065:(A,t,e)=>{const r={x11hash:e(3868),crypto:e(5835)};A.exports={configuration:r,configure:A=>{Object.assign(r,{...A})}}},2087:A=>{A.exports={PUBKEY_ID_SIZE:20,COMPACT_SIGNATURE_SIZE:65,SHA256_HASH_SIZE:32,BLS_PUBLIC_KEY_SIZE:48,BLS_SIGNATURE_SIZE:96,PLATFORM_NODE_ID_SIZE:20,MASTERNODE_TYPE_BASIC:0,MASTERNODE_TYPE_HP:1,registeredTransactionTypes:{TRANSACTION_NORMAL:0,TRANSACTION_PROVIDER_REGISTER:1,TRANSACTION_PROVIDER_UPDATE_SERVICE:2,TRANSACTION_PROVIDER_UPDATE_REGISTRAR:3,TRANSACTION_PROVIDER_UPDATE_REVOKE:4,TRANSACTION_COINBASE:5,TRANSACTION_QUORUM_COMMITMENT:6,TRANSACTION_MASTERNODE_HARD_FORK_SIGNAL:7,TRANSACTION_ASSET_LOCK:8,TRANSACTION_ASSET_UNLOCK:9},EMPTY_SIGNATURE_SIZE:0,primitives:{BOOLEAN:1},ipAddresses:{IPV4MAPPEDHOST:16,PORT:2},IP_ADDRESS_SIZE:16,CURRENT_PROTOCOL_VERSION:70211,SML_ENTRY_VERSION_1_SIZE:151,SML_ENTRY_TYPE_2_ADDITION_SIZE:22,NULL_HASH:"0000000000000000000000000000000000000000000000000000000000000000",INSTANTSEND_FEE_PER_INPUT:1e4,LLMQ_TYPES:{LLMQ_TYPE_50_60:1,LLMQ_TYPE_400_60:2,LLMQ_TYPE_400_85:3,LLMQ_TYPE_100_67:4,LLMQ_TYPE_60_75:5,LLMQ_TYPE_25_67:6,LLMQ_TYPE_LLMQ_TEST:100,LLMQ_TYPE_LLMQ_DEVNET:101,LLMQ_TYPE_TEST_V17:102,LLMQ_TYPE_TEST_DIP0024:103,LLMQ_TYPE_TEST_INSTANTSEND:104,LLMQ_DEVNET_DIP0024:105,LLMQ_TEST_PLATFORM:106,LLMQ_DEVNET_PLATFORM:107,LLMQ_SINGLE_NODE:111},LLMQ_SIGN_HEIGHT_OFFSET:8,SMLSTORE_MAX_DIFFS:720,HASH_QUORUM_INDEX_REQUIRED_VERSION:2,BASIC_BLS_SCHEME_VERSION:3,BASIC_BLS_SCHEME_HASH_QUORUM_INDEX_REQUIRED_VERSION:4}},2138:(A,t,e)=>{var r=e(8764).Buffer;const i=e(7187),n=e(9943),o="LOADED",g=new i;let a=!1,s=null;const I={getInstance:()=>new Promise((A=>{s?A(s):a?g.once(o,(()=>{A(s)})):(a=!0,n().then((A=>{s=A,a=!1,g.emit(o)}))).then((()=>{A(s)}))})),async verifySignature(A,t,e){const i=await this.getInstance();let n,o,g=!1;const{G2Element:a,G1Element:s,BasicSchemeMPL:I}=i;try{n=a.fromBytes(Uint8Array.from(r.from(A,"hex"))),o=s.fromBytes(Uint8Array.from(r.from(e,"hex"))),g=I.verify(o,t,n)}catch(A){return g}finally{n&&n.delete(),o&&o.delete()}return g},async verifyAggregatedSignature(A,t,e,i){const n=await this.getInstance();let o,g=!1;const a=[];let s=0;const{G1Element:I,G2Element:B,BasicSchemeMPL:u}=n;e.forEach((A=>{i[s]&&a.push(I.fromBytes(Uint8Array.from(r.from(A,"hex")))),s+=1}));try{o=B.fromBytes(Uint8Array.from(r.from(A,"hex"))),g=u.verifySecure(a,o,t)}catch(A){return g}finally{o&&o.delete(),a&&a.forEach((A=>{A.delete()}))}return g}};A.exports=I},5441:(A,t,e)=>{"use strict";var r=e(8764).Buffer,i=e(3550),n=e(5099),o=e(6486),g=function(A){for(var t=r.alloc(A.length),e=0;e<A.length;e++)t[e]=A[A.length-1-e];return t};i.Zero=new i(0),i.One=new i(1),i.Minus1=new i(-1),i.fromNumber=function(A){return n.checkArgument(o.isNumber(A)),new i(A)},i.fromString=function(A,t){return n.checkArgument(o.isString(A)),new i(A,t)},i.fromBuffer=function(A,t){void 0!==t&&"little"===t.endian&&(A=g(A));var e=A.toString("hex");return new i(e,16)},i.fromSM=function(A,t){var e;if(0===A.length)return i.fromBuffer(r.from([0]));var n="big";return t&&(n=t.endian),"little"===n&&(A=g(A)),128&A[0]?(A[0]=127&A[0],(e=i.fromBuffer(A)).neg().copy(e)):e=i.fromBuffer(A),e},i.prototype.toNumber=function(){return parseInt(this.toString(10),10)},i.prototype.toBuffer=function(A){var t,e;if(A&&A.size){var n=(e=this.toString(16,2)).length/2;t=r.from(e,"hex"),n===A.size||(n>A.size?t=i.trim(t,n):n<A.size&&(t=i.pad(t,n,A.size)))}else e=this.toString(16,2),t=r.from(e,"hex");return void 0!==A&&"little"===A.endian&&(t=g(t)),t},i.prototype.toSMBigEndian=function(){var A;return-1===this.cmp(i.Zero)?128&(A=this.neg().toBuffer())[0]?A=r.concat([r.from([128]),A]):A[0]=128|A[0]:128&(A=this.toBuffer())[0]&&(A=r.concat([r.from([0]),A])),1===A.length&0===A[0]&&(A=r.from([])),A},i.prototype.toSM=function(A){var t=A?A.endian:"big",e=this.toSMBigEndian();return"little"===t&&(e=g(e)),e},i.fromScriptNumBuffer=function(A,t,e){var r=e||4;if(n.checkArgument(A.length<=r,new Error("script number overflow")),t&&A.length>0&&0==(127&A[A.length-1])&&(A.length<=1||0==(128&A[A.length-2])))throw new Error("non-minimally encoded script number");return i.fromSM(A,{endian:"little"})},i.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})},i.prototype.gt=function(A){return this.cmp(A)>0},i.prototype.gte=function(A){return this.cmp(A)>=0},i.prototype.lt=function(A){return this.cmp(A)<0},i.trim=function(A,t){return A.slice(t-A.length,A.length)},i.pad=function(A,t,e){for(var i=r.alloc(e),n=0;n<A.length;n++)i[i.length-1-n]=A[A.length-1-n];for(n=0;n<e-t;n++)i[n]=0;return i},A.exports=i},6836:(A,t,e)=>{"use strict";var r=e(8764).Buffer,i=e(5441),n=e(287),o=e(6146),g=e(5882),a=e(8199),s=e(1018),I=e(4102),B=e(6486),u=e(5099),E=function A(t){if(!(this instanceof A))return new A(t);t&&this.set(t)};E.prototype.set=function(A){return this.hashbuf=A.hashbuf||this.hashbuf,this.endian=A.endian||this.endian,this.privkey=A.privkey||this.privkey,this.pubkey=A.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey),this.sig=A.sig||this.sig,this.k=A.k||this.k,this.verified=A.verified||this.verified,this},E.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()},E.prototype.calci=function(){for(var A=0;A<4;A++){var t;this.sig.i=A;try{t=this.toPublicKey()}catch(A){console.error(A);continue}if(t.point.eq(this.pubkey.point))return this.sig.compressed=this.pubkey.compressed,this}throw this.sig.i=void 0,new Error("Unable to find valid recovery factor")},E.fromString=function(A){var t=JSON.parse(A);return new E(t)},E.prototype.randomK=function(){var A,t=n.getN();do{A=i.fromBuffer(a.getRandomBuffer(32))}while(!A.lt(t)||!A.gt(i.Zero));return this.k=A,this},E.prototype.deterministicK=function(A){B.isUndefined(A)&&(A=0);var t=r.alloc(32);t.fill(1);var e=r.alloc(32);e.fill(0);var o=this.privkey.bn.toBuffer({size:32}),g="little"===this.endian?I.reverse(this.hashbuf):this.hashbuf;e=s.sha256hmac(r.concat([t,r.from([0]),o,g]),e),t=s.sha256hmac(t,e),e=s.sha256hmac(r.concat([t,r.from([1]),o,g]),e),t=s.sha256hmac(t,e),t=s.sha256hmac(t,e);for(var a=i.fromBuffer(t),u=n.getN(),E=0;E<A||!a.lt(u)||!a.gt(i.Zero);E++)e=s.sha256hmac(r.concat([t,r.from([0])]),e),t=s.sha256hmac(t,e),t=s.sha256hmac(t,e),a=i.fromBuffer(t);return this.k=a,this},E.prototype.toPublicKey=function(){var A=this.sig.i;u.checkArgument(0===A||1===A||2===A||3===A,new Error("i must be equal to 0, 1, 2, or 3"));var t=i.fromBuffer(this.hashbuf),e=this.sig.r,r=this.sig.s,o=1&A,a=A>>1,s=n.getN(),I=n.getG(),B=a?e.add(s):e,E=n.fromX(o,B);if(!E.mul(s).isInfinity())throw new Error("nR is not a valid curve point");var C=t.neg().umod(s),c=e.invm(s),h=E.mul(r).add(I.mul(C)).mul(c);return g.fromPoint(h,this.sig.compressed)},E.prototype.sigError=function(){if(!I.isBuffer(this.hashbuf)||32!==this.hashbuf.length)return"hashbuf must be a 32 byte buffer";var A=this.sig.r,t=this.sig.s;if(!(A.gt(i.Zero)&&A.lt(n.getN())&&t.gt(i.Zero)&&t.lt(n.getN())))return"r and s not in range";var e=i.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:void 0),r=n.getN(),o=t.invm(r),g=o.mul(e).umod(r),a=o.mul(A).umod(r),s=n.getG().mulAdd(g,this.pubkey.point,a);return s.isInfinity()?"p is infinity":0!==s.getX().mod(r).cmp(A)&&"Invalid signature"},E.toLowS=function(A){return A.gt(i.fromBuffer(r.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(A=n.getN().sub(A)),A},E.prototype._findSignature=function(A,t){var e,r,o,g=n.getN(),a=n.getG(),s=0;do{(!this.k||s>0)&&this.deterministicK(s),s++,e=this.k,r=a.mul(e).x.umod(g),o=e.invm(g).mul(t.add(A.mul(r))).umod(g)}while(r.cmp(i.Zero)<=0||o.cmp(i.Zero)<=0);return{s:o=E.toLowS(o),r}},E.prototype.sign=function(){var A=this.hashbuf,t=this.privkey,e=t.bn;u.checkState(A&&t&&e,new Error("invalid parameters")),u.checkState(I.isBuffer(A)&&32===A.length,new Error("hashbuf must be a 32 byte buffer"));var r=i.fromBuffer(A,this.endian?{endian:this.endian}:void 0),n=this._findSignature(e,r);return n.compressed=this.pubkey.compressed,this.sig=new o(n),this},E.prototype.signRandomK=function(){return this.randomK(),this.sign()},E.prototype.toString=function(){var A={};return this.hashbuf&&(A.hashbuf=this.hashbuf.toString("hex")),this.privkey&&(A.privkey=this.privkey.toString()),this.pubkey&&(A.pubkey=this.pubkey.toString()),this.sig&&(A.sig=this.sig.toString()),this.k&&(A.k=this.k.toString()),JSON.stringify(A)},E.prototype.verify=function(){return this.sigError()?this.verified=!1:this.verified=!0,this},E.sign=function(A,t,e){return E().set({hashbuf:A,endian:e,privkey:t}).sign().sig},E.verify=function(A,t,e,r){return E().set({hashbuf:A,endian:r,sig:t,pubkey:e}).verify().verified},A.exports=E},1018:(A,t,e)=>{"use strict";var r=e(8764).Buffer;const{configuration:i}=e(8065);var n=e(4102),o=e(5099),g=e(9785),a=A.exports;a.sha1=function(A){return o.checkArgument(n.isBuffer(A)),i.crypto.createHash("sha1").update(A).digest()},a.sha1.blocksize=512,a.sha256=function(A){return o.checkArgument(n.isBuffer(A)),i.crypto.createHash("sha256").update(A).digest()},a.sha256.blocksize=512,a.sha256sha256=function(A){return o.checkArgument(n.isBuffer(A)),a.sha256(a.sha256(A))},a.x11=function(A){o.checkArgument(n.isBuffer(A));const t=i.x11hash.digest(A,1,1);return r.from(t)},a.ripemd160=function(A){return o.checkArgument(n.isBuffer(A)),(new g).update(A).digest()},a.sha256ripemd160=function(A){return o.checkArgument(n.isBuffer(A)),a.ripemd160(a.sha256(A))},a.sha512=function(A){return o.checkArgument(n.isBuffer(A)),i.crypto.createHash("sha512").update(A).digest()},a.sha512.blocksize=1024,a.hmac=function(A,t,e){o.checkArgument(n.isBuffer(t)),o.checkArgument(n.isBuffer(e)),o.checkArgument(A.blocksize);var i=A.blocksize/8;if(e.length>i)e=A(e);else if(e<i){var g=r.alloc(i);g.fill(0),e.copy(g),e=g}var a=r.alloc(i);a.fill(92);var s=r.alloc(i);s.fill(54);for(var I=r.alloc(i),B=r.alloc(i),u=0;u<i;u++)I[u]=a[u]^e[u],B[u]=s[u]^e[u];return A(r.concat([I,A(r.concat([B,t]))]))},a.sha256hmac=function(A,t){return a.hmac(a.sha256,A,t)},a.sha512hmac=function(A,t){return a.hmac(a.sha512,A,t)}},287:(A,t,e)=>{"use strict";var r=e(8764).Buffer,i=e(5441),n=e(4102),o=new(0,e(6266).ec)("secp256k1"),g=o.curve.point.bind(o.curve),a=o.curve.pointFromX.bind(o.curve),s=function(A,t,e){try{var r=g(A,t,e)}catch(A){throw new Error("Invalid Point")}return r.validate(),r};s.prototype=Object.getPrototypeOf(o.curve.point()),s.fromX=function(A,t){try{var e=a(t,A)}catch(A){throw new Error("Invalid X")}return e.validate(),e},s.getG=function(){return o.curve.g},s.getN=function(){return new i(o.curve.n.toArray())},s.prototype._getX||(s.prototype._getX=s.prototype.getX),s.prototype.getX=function(){return new i(this._getX().toArray())},s.prototype._getY||(s.prototype._getY=s.prototype.getY),s.prototype.getY=function(){return new i(this._getY().toArray())},s.prototype.validate=function(){if(this.isInfinity())throw new Error("Point cannot be equal to Infinity");var A;try{A=a(this.getX(),this.getY().isOdd())}catch(A){throw new Error("Point does not lie on the curve")}if(0!==A.y.cmp(this.y))throw new Error("Invalid y value for curve.");if(!this.mul(s.getN()).isInfinity())throw new Error("Point times N must be infinity");return this},s.pointToCompressed=function(A){var t,e=A.getX().toBuffer({size:32}),i=A.getY().toBuffer({size:32});return t=i[i.length-1]%2?r.from([3]):r.from([2]),n.concat([t,e])},A.exports=s},8199:(A,t,e)=>{"use strict";var r=e(4155),i=e(8764).Buffer;function n(){}n.getRandomBuffer=function(A){return r.browser?n.getRandomBufferBrowser(A):n.getRandomBufferNode(A)},n.getRandomBufferNode=function(A){return e(5835).randomBytes(A)},n.getRandomBufferBrowser=function(A){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)var t=window.crypto;else{if(!window.msCrypto||!window.msCrypto.getRandomValues)throw new Error("window.crypto.getRandomValues not available");t=window.msCrypto}var e=new Uint8Array(A);return t.getRandomValues(e),i.from(e)},n.getPseudoRandomBuffer=function(A){for(var t,e=i.alloc(A),r=0;r<=A;r++){0===r-4*Math.floor(r/4)?(t=4294967296*Math.random(),e[r]=255&t):e[r]=255&(t>>>=8)}return e},A.exports=n},6146:(A,t,e)=>{"use strict";var r=e(8764).Buffer,i=e(5441),n=e(6486),o=e(5099),g=e(4102),a=e(3336),s=function A(t,e){if(!(this instanceof A))return new A(t,e);if(t instanceof i)this.set({r:t,s:e});else if(t){var r=t;this.set(r)}};s.prototype.set=function(A){return this.r=A.r||this.r||void 0,this.s=A.s||this.s||void 0,this.i=void 0!==A.i?A.i:this.i,this.compressed=void 0!==A.compressed?A.compressed:this.compressed,this.nhashtype=A.nhashtype||this.nhashtype||void 0,this},s.fromCompact=function(A){o.checkArgument(g.isBuffer(A),"Argument is expected to be a Buffer");var t=new s,e=!0,r=A.slice(0,1)[0]-27-4;r<0&&(e=!1,r+=4);var n=A.slice(1,33),a=A.slice(33,65);return o.checkArgument(0===r||1===r||2===r||3===r,new Error("i must be 0, 1, 2, or 3")),o.checkArgument(32===n.length,new Error("r must be 32 bytes")),o.checkArgument(32===a.length,new Error("s must be 32 bytes")),t.compressed=e,t.i=r,t.r=i.fromBuffer(n),t.s=i.fromBuffer(a),t},s.fromDER=s.fromBuffer=function(A,t){var e=s.parseDER(A,t),r=new s;return r.r=e.r,r.s=e.s,r},s.fromTxFormat=function(A){var t=A.readUInt8(A.length-1),e=A.slice(0,A.length-1),r=new s.fromDER(e,!1);return r.nhashtype=t,r},s.fromString=function(A){var t=r.from(A,"hex");return s.fromDER(t)},s.parseDER=function(A,t){o.checkArgument(g.isBuffer(A),new Error("DER formatted signature should be a buffer")),n.isUndefined(t)&&(t=!0);var e=A[0];o.checkArgument(48===e,new Error("Header byte should be 0x30"));var r=A[1],a=A.slice(2).length;o.checkArgument(!t||r===a,new Error("Length byte should length of what follows")),r=r<a?r:a;var s=A[2];o.checkArgument(2===s,new Error("Integer byte for r should be 0x02"));var I=A[3],B=A.slice(4,4+I),u=i.fromBuffer(B),E=0===A[4];o.checkArgument(I===B.length,new Error("Length of r incorrect"));var C=A[4+I+0];o.checkArgument(2===C,new Error("Integer byte for s should be 0x02"));var c=A[4+I+1],h=A.slice(4+I+2,4+I+2+c),Q=i.fromBuffer(h),f=0===A[4+I+2+2];o.checkArgument(c===h.length,new Error("Length of s incorrect"));var l=4+I+2+c;return o.checkArgument(r===l-2,new Error("Length of signature incorrect")),{header:e,length:r,rheader:s,rlength:I,rneg:E,rbuf:B,r:u,sheader:C,slength:c,sneg:f,sbuf:h,s:Q}},s.prototype.toCompact=function(A,t){if(A="number"==typeof A?A:this.i,t="boolean"==typeof t?t:this.compressed,0!==A&&1!==A&&2!==A&&3!==A)throw new Error("i must be equal to 0, 1, 2, or 3");var e=A+27+4;!1===t&&(e-=4);var i=r.from([e]),n=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return r.concat([i,n,o])},s.prototype.toBuffer=s.prototype.toDER=function(){var A=this.r.toBuffer(),t=this.s.toBuffer(),e=!!(128&A[0]),i=!!(128&t[0]),n=e?r.concat([r.from([0]),A]):A,o=i?r.concat([r.from([0]),t]):t,g=n.length,a=o.length,s=2+g+2+a;return r.concat([r.from([48,s,2,g]),n,r.from([2,a]),o])},s.prototype.toString=function(){return this.toDER().toString("hex")},s.isTxDER=function(A){if(A.length<9)return!1;if(A.length>73)return!1;if(48!==A[0])return!1;if(A[1]!==A.length-3)return!1;var t=A[3];if(5+t>=A.length)return!1;var e=A[5+t];if(t+e+7!==A.length)return!1;var r=A.slice(4);if(2!==A[2])return!1;if(0===t)return!1;if(128&r[0])return!1;if(t>1&&0===r[0]&&!(128&r[1]))return!1;var i=A.slice(6+t);return 2===A[6+t-2]&&(0!==e&&(!(128&i[0])&&!(e>1&&0===i[0]&&!(128&i[1]))))},s.prototype.hasLowS=function(){return!this.s.lt(new i(1))&&!this.s.gt(new i("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))},s.prototype.hasDefinedHashtype=function(){if(!a.isNaturalNumber(this.nhashtype))return!1;var A=this.nhashtype&~s.SIGHASH_ANYONECANPAY;return!(A<s.SIGHASH_ALL||A>s.SIGHASH_SINGLE)},s.prototype.toTxFormat=function(){var A=this.toDER(),t=r.alloc(1);return t.writeUInt8(this.nhashtype,0),r.concat([A,t])},s.SIGHASH_ALL=1,s.SIGHASH_NONE=2,s.SIGHASH_SINGLE=3,s.SIGHASH_ANYONECANPAY=128,A.exports=s},6239:(A,t,e)=>{var r=e(8764).Buffer,i=e(6146),n=e(6836),o=e(1812),g=e(1018).sha256sha256;function a(A,t){"string"==typeof t&&(t=new o(t));var e=new n;return e.hashbuf=A,e.privkey=t,e.pubkey=t.toPublicKey(),e.signRandomK(),e.calci(),e.sig.toCompact()}var s={sign:function(A,t){return a(g(A),t)},verifySignature:function(A,t,e){var r=g(A),o=i.fromCompact(t);return n.verify(r,o,e)},signHash:a,verifyHashSignature:function(A,t,e){var o=i.fromCompact(t),g=new n({hashbuf:A,sig:o}).toPublicKey()._getID(),a=r.from(e,"hex");return g.equals(a)}};A.exports=s},8715:(A,t,e)=>{var r=e(8764).Buffer;const i=e(6486),n=e(5099),o=e(93),g=e(6907),a=e(6133),s=e(4102),I=e(2087),B=e(1018),u=e(2138),E=e(3336),C=e(6367),{isHexStringOfSize:c,isUnsignedInteger:h,isSha256HexString:Q,isHexaString:f}=E,{BLS_PUBLIC_KEY_SIZE:l,BLS_SIGNATURE_SIZE:d,SHA256_HASH_SIZE:p}=I;function y(A){if(A){if(A instanceof y)return A.copy();if(s.isBuffer(A))return y.fromBuffer(A);if(i.isObject(A))return y.fromObject(A);if(A instanceof y)return A.copy();if(f(A))return y.fromHexString(A);throw new TypeError("Unrecognized argument for QuorumEntry")}}y.fromBuffer=function(A){const t=new g(A),e=new y;if(e.isVerified=!1,A.length<100)return e.isOutdatedRPC=!0,e.version=t.readUInt16LE(),e.llmqType=t.readUInt8(),e.quorumHash=t.read(I.SHA256_HASH_SIZE).reverse().toString("hex"),C(this.version)?e.quorumIndex=A.readInt16LE():e.quorumIndex=0,e.signersCount=t.readVarintNum(),e.validMembersCount=t.readVarintNum(),e.quorumPublicKey=t.read(l).toString("hex"),e;e.isOutdatedRPC=!1,e.version=t.readUInt16LE(),e.llmqType=t.readUInt8(),e.quorumHash=t.read(I.SHA256_HASH_SIZE).reverse().toString("hex"),C(e.version)?e.quorumIndex=t.readInt16LE():e.quorumIndex=0,e.signersCount=t.readVarintNum();const r=Math.floor((e.getParams().size+7)/8)||1;e.signers=t.read(r).toString("hex"),e.validMembersCount=t.readVarintNum();const i=Math.floor((e.getParams().size+7)/8)||1;return e.validMembers=t.read(i).toString("hex"),e.quorumPublicKey=t.read(l).toString("hex"),e.quorumVvecHash=t.read(p).reverse().toString("hex"),e.quorumSig=t.read(d).toString("hex"),e.membersSig=t.read(d).toString("hex"),e},y.fromHexString=function(A){return y.fromBuffer(r.from(A,"hex"))},y.prototype.toBuffer=function(){this.validate();const A=new a;return A.writeUInt16LE(this.version),A.writeUInt8(this.llmqType),A.write(r.from(this.quorumHash,"hex").reverse()),C(this.version)&&A.writeInt16LE(this.quorumIndex),A.writeVarintNum(this.signersCount),this.isOutdatedRPC?(A.writeVarintNum(this.validMembersCount),A.write(r.from(this.quorumPublicKey,"hex")),A.toBuffer()):(A.write(r.from(this.signers,"hex")),A.writeVarintNum(this.validMembersCount),A.write(r.from(this.validMembers,"hex")),A.write(r.from(this.quorumPublicKey,"hex")),A.write(r.from(this.quorumVvecHash,"hex").reverse()),A.write(r.from(this.quorumSig,"hex")),A.write(r.from(this.membersSig,"hex")),A.toBuffer())},y.prototype.toBufferForHashing=function(){this.validate();const A=new a,t=this.getParams().size;return A.writeUInt16LE(this.version),A.writeUInt8(this.llmqType),A.write(r.from(this.quorumHash,"hex").reverse()),C(this.version)&&A.writeInt16LE(this.quorumIndex),A.writeVarintNum(t),A.write(r.from(this.signers,"hex")),A.writeVarintNum(t),A.write(r.from(this.validMembers,"hex")),A.write(r.from(this.quorumPublicKey,"hex")),A.write(r.from(this.quorumVvecHash,"hex").reverse()),A.write(r.from(this.quorumSig,"hex")),A.write(r.from(this.membersSig,"hex")),A.toBuffer()},y.fromObject=function(A){const t=new y;return t.isVerified=!1,t.isOutdatedRPC=!1,t.version=A.version,t.llmqType=A.llmqType,t.quorumHash=A.quorumHash,t.quorumIndex=A.quorumIndex,t.signersCount=A.signersCount,t.signers=A.signers,t.validMembersCount=A.validMembersCount,t.validMembers=A.validMembers,t.quorumPublicKey=A.quorumPublicKey,t.quorumVvecHash=A.quorumVvecHash,t.quorumSig=A.quorumSig,t.membersSig=A.membersSig,void 0===t.signers&&(t.isOutdatedRPC=!0),t.validate(),t},y.prototype.validate=function(){n.checkArgument(E.isUnsignedInteger(this.version),"Expect version to be an unsigned integer"),n.checkArgument(E.isUnsignedInteger(this.llmqType),"Expect llmqType to be an unsigned integer"),n.checkArgument(Q(this.quorumHash),"Expected quorumHash to be a sha256 hex string"),C(this.version)&&n.checkArgument(Number.isInteger(this.quorumIndex),"Expected quorumIndex to be an integer"),n.checkArgument(h(this.signersCount),"Expect signersCount to be an unsigned integer"),n.checkArgument(h(this.validMembersCount),"Expect validMembersCount to be an unsigned integer"),n.checkArgument(c(this.quorumPublicKey,2*l),"Expected quorumPublicKey to be a bls pubkey"),this.isOutdatedRPC||(n.checkArgument(E.isHexaString(this.signers),"Expect signers to be a hex string"),n.checkArgument(E.isHexaString(this.validMembers),"Expect validMembers to be a hex string"),n.checkArgument(c(this.quorumVvecHash,2*p),`Expected quorumVvecHash to be a hex string of size ${p}`),n.checkArgument(c(this.quorumSig,2*d),"Expected quorumSig to be a bls signature"),n.checkArgument(c(this.membersSig,2*d),"Expected membersSig to be a bls signature"))},y.prototype.toObject=function(){const A={version:this.version,llmqType:this.llmqType,quorumHash:this.quorumHash,signersCount:this.signersCount,signers:this.signers,validMembersCount:this.validMembersCount,validMembers:this.validMembers,quorumPublicKey:this.quorumPublicKey,quorumVvecHash:this.quorumVvecHash,quorumSig:this.quorumSig,membersSig:this.membersSig};return A.quorumIndex=this.quorumIndex,A},y.getParams=function(A){const t={};switch(A){case I.LLMQ_TYPES.LLMQ_TYPE_50_60:return t.size=50,t.threshold=30,t.maximumActiveQuorumsCount=24,t;case I.LLMQ_TYPES.LLMQ_TYPE_60_75:return t.size=60,t.threshold=45,t.maximumActiveQuorumsCount=32,t;case I.LLMQ_TYPES.LLMQ_TYPE_400_60:return t.size=400,t.threshold=240,t.maximumActiveQuorumsCount=4,t;case I.LLMQ_TYPES.LLMQ_TYPE_400_85:return t.size=400,t.threshold=340,t.maximumActiveQuorumsCount=4,t;case I.LLMQ_TYPES.LLMQ_TYPE_100_67:return t.size=100,t.threshold=67,t.maximumActiveQuorumsCount=24,t;case I.LLMQ_TYPES.LLMQ_TYPE_25_67:return t.size=25,t.threshold=67,t.maximumActiveQuorumsCount=24,t;case I.LLMQ_TYPES.LLMQ_TYPE_LLMQ_TEST:return t.size=3,t.threshold=2,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_TYPE_LLMQ_DEVNET:return t.size=12,t.threshold=6,t.maximumActiveQuorumsCount=4,t;case I.LLMQ_TYPES.LLMQ_TYPE_TEST_V17:return t.size=3,t.threshold=2,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_TYPE_TEST_DIP0024:return t.size=4,t.threshold=2,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_TYPE_TEST_INSTANTSEND:return t.size=3,t.threshold=2,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_DEVNET_DIP0024:return t.size=8,t.threshold=4,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_TEST_PLATFORM:return t.size=3,t.threshold=2,t.maximumActiveQuorumsCount=2,t;case I.LLMQ_TYPES.LLMQ_DEVNET_PLATFORM:return t.size=12,t.threshold=8,t.maximumActiveQuorumsCount=4,t;case I.LLMQ_TYPES.LLMQ_SINGLE_NODE:return t.size=1,t.threshold=1,t.maximumActiveQuorumsCount=2,t;default:throw new Error(`Invalid llmq type ${A}`)}},y.prototype.getParams=function(){return y.getParams(this.llmqType)},y.prototype.getCommitmentHash=function(){const A=new a;return A.writeUInt8(this.llmqType),A.write(r.from(this.quorumHash,"hex").reverse()),A.writeVarintNum(this.getParams().size),A.write(r.from(this.validMembers,"hex")),A.write(r.from(this.quorumPublicKey,"hex")),A.write(r.from(this.quorumVvecHash,"hex").reverse()),B.sha256sha256(A.toBuffer())},y.prototype.isValidQuorumSig=async function(){if(this.isOutdatedRPC)throw new Error("Quorum cannot be verified: node running on outdated DashCore version (< 0.16)");return u.verifySignature(this.quorumSig,Uint8Array.from(this.getCommitmentHash()),this.quorumPublicKey)},y.prototype.isValidMemberSig=async function(A){if(A.blockHash!==this.quorumHash)throw new Error(`Wrong Masternode List for quorum: blockHash\n ${A.blockHash} doesn't correspond with quorumHash ${this.quorumHash}`);if(this.isOutdatedRPC)throw new Error("Quorum cannot be verified: node running on outdated DashCore version (< 0.16)");const t=this.getAllQuorumMembers(A).map((A=>A.pubKeyOperator)),e=o.uint8ArrayToBitArray(Uint8Array.from(r.from(this.signers,"hex")));return u.verifyAggregatedSignature(this.membersSig,Uint8Array.from(this.getCommitmentHash()),t,e)},y.prototype.verify=function(A){return new Promise(((t,e)=>A.blockHash!==this.quorumHash?e(new Error(`Wrong Masternode List for quorum: blockHash\n ${A.blockHash} doesn't correspond with quorumHash ${this.quorumHash}`)):this.isOutdatedRPC?e(new Error("Quorum cannot be verified: node running on outdated DashCore version (< 0.16)")):this.isVerified?t(!0):this.isValidMemberSig(A).then((A=>!!A&&this.isValidQuorumSig())).then((A=>{this.isVerified=A,t(A)}))))},y.prototype.getAllQuorumMembers=function(A){if(A.blockHash!==this.quorumHash)throw new Error(`Wrong Masternode List for quorum: blockHash\n ${A.blockHash} doesn't correspond with quorumHash ${this.quorumHash}`);const t=this.llmqType===A.getPlatformLLMQType();return A.calculateQuorum(this.getSelectionModifier(),this.getParams().size,t)},y.prototype.getSelectionModifier=function(){const A=new a;return A.writeUInt8(this.llmqType),A.write(r.from(this.quorumHash,"hex").reverse()),B.sha256sha256(A.toBuffer()).reverse()},y.prototype.getOrderingHashForRequestId=function(A){const t=r.concat([r.from(this.llmqType),r.from(this.quorumHash,"hex"),r.from(A,"hex")]);return B.sha256sha256(t).reverse()},y.prototype.calculateHash=function(){return B.sha256sha256(this.toBufferForHashing()).reverse()},y.prototype.copy=function(){return y.fromBuffer(this.toBuffer())},A.exports=y},6489:(A,t,e)=>{var r=e(8764).Buffer;const i=e(7739),n=e(6133),o=e(1018),{getMerkleTree:g,getMerkleRoot:a}=e(7656),s=e(425),I=e(8715),B=e(2724),u=e(9116),E=e(2087),C=e(4205),c=e(4437),{MASTERNODE_TYPE_HP:h}=e(2087);function Q(A){this.baseBlockHash=E.NULL_HASH,this.blockHash=E.NULL_HASH,this.mnList=[],this.quorumList=[],this.validMNs=[],this.merkleRootMNList=E.NULL_HASH,this.lastDiffMerkleRootMNList=E.NULL_HASH,this.lastDiffMerkleRootQuorums=E.NULL_HASH,this.quorumsActive=!1,this.cbTx=null,this.cbTxMerkleTree=null,A&&this.applyDiff(A)}Q.prototype.applyDiff=function(A){const t=new s(A,this.network);if(this.network||(this.network=t.network),this.baseBlockHash===E.NULL_HASH&&(this.baseBlockHash=t.baseBlockHash),this.blockHash=t.blockHash,this.lastBlockHash&&this.lastBlockHash!==t.baseBlockHash)throw new Error("Cannot apply diff: previous blockHash needs to equal the new diff's baseBlockHash");if(this.deleteMNs(t.deletedMNs),this.addOrUpdateMNs(t.mnList),this.lastDiffMerkleRootMNList=t.merkleRootMNList||E.NULL_HASH,this.merkleRootMNList=this.calculateMerkleRoot(),this.lastDiffMerkleRootMNList!==this.merkleRootMNList)throw new Error("Merkle root from the diff doesn't match calculated merkle root after diff is applied");if(this.cbTx=new c(t.cbTx),this.cbTxMerkleTree=t.cbTxMerkleTree.copy(),this.validMNs=this.mnList.filter((A=>A.isValid)),this.quorumsActive=this.cbTx.version>=2,this.nVersion=t.nVersion,this.quorumsActive&&(this.deleteQuorums(t.deletedQuorums),this.addAndMaybeRemoveQuorums(t.newQuorums),this.lastDiffMerkleRootQuorums=t.merkleRootQuorums||E.NULL_HASH,this.quorumList.length>0)){if(this.quorumList[0].isOutdatedRPC)return void(this.merkleRootQuorums=t.merkleRootQuorums);if(this.quorumList=this.sortQuorums(this.qu