UNPKG

alterdot-lib

Version:

A pure and powerful JavaScript Alterdot library.

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