@bsv/sdk
Version:
BSV Blockchain Software Development Kit
1 lines • 422 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.bsv=t():e.bsv=t()}(this,()=>(()=>{"use strict";let e,t,r,i,n;var a,s,o,c,l,h,u,d,f={};f.d=(e,t)=>{for(var r in t)f.o(t,r)&&!f.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},f.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),f.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var p={};f.r(p),f.d(p,{walletErrors:()=>u,HTTPWalletWire:()=>iR,BEEF_V1:()=>rG,BEEF_V2:()=>rX,SignedMessage:()=>m,StorageUtils:()=>k,TopicBroadcaster:()=>nz,KeyShares:()=>tZ,BlockHeadersService:()=>r7,MerklePath:()=>rz,RPuzzle:()=>rC,PrivateKey:()=>tQ,StorageDownloader:()=>nQ,CompletedProtoWallet:()=>nx,isBroadcastResponse:()=>r0,XDM:()=>iA,binaryHttpClient:()=>r4,LookupResolver:()=>nM,LivePolicy:()=>rD,HD:()=>ih,KeyDeriver:()=>ik,defaultBroadcaster:()=>rq,LocalKVStore:()=>n9,ProtoWallet:()=>iE,verifyNonce:()=>nP,AuthFetch:()=>nB,FetchHttpClient:()=>rF,Secp256r1:()=>rw,UnlockingScript:()=>rE,ECIES:()=>im,Random:()=>tX,TOTP:()=>iv,ARC:()=>rH,Curve:()=>tD,SHIPCast:()=>nz,ECDSA:()=>y,DEFAULT_SLAP_TRACKERS:()=>nK,GlobalKVStore:()=>aa,MasterCertificate:()=>nk,VerifiableCertificate:()=>nS,WERR_INVALID_PARAMETER:()=>iU,SessionManager:()=>nE,SHIPBroadcaster:()=>nz,StorageUploader:()=>nZ,SymmetricKey:()=>rc,WERR_REVIEW_ACTIONS:()=>iV,WalletErrors:()=>iO,WhatsOnChain:()=>rM,WindowCWISubstrate:()=>iP,defaultChainTracker:()=>r$,fromUtxo:()=>iw,validateCertificates:()=>nA,EncryptedMessage:()=>w,Spend:()=>r_,DEFAULT_TESTNET_SLAP_TRACKERS:()=>nH,Hash:()=>g,OverlayAdminTokenTemplate:()=>nV,Mnemonic:()=>id,NodejsHttpClient:()=>rU,Schnorr:()=>ru,HTTPWalletJSON:()=>iL,LockingScript:()=>rx,PushDrop:()=>rB,Script:()=>rS,ScriptEvaluationError:()=>rP,WERR_INSUFFICIENT_FUNDS:()=>iF,DEFAULT_IDENTITY_CLIENT_OPTIONS:()=>n1,HTTPSOverlayLookupFacilitator:()=>nq,BigNumber:()=>P,Beef:()=>rY,PublicKey:()=>tW,RegistryClient:()=>n5,Transaction:()=>rQ,WalletWireProcessor:()=>nI,BeefTx:()=>rW,TransactionSignature:()=>rh,Certificate:()=>i_,WalletWireTransceiver:()=>iC,createNonce:()=>nN,KNOWN_IDENTITY_TYPES:()=>n2,TX_DATA_FORMAT:()=>l,defaultIdentity:()=>n0,getVerifiableCertificates:()=>nO,HTTPSOverlayBroadcastFacilitator:()=>n$,Peer:()=>nT,ReactNativeWebView:()=>iK,Signature:()=>tU,PointInFiniteField:()=>tJ,Teranode:()=>r5,WhatsOnChainBroadcaster:()=>r8,CachedKeyDeriver:()=>iS,defaultHttpClient:()=>rL,withDoubleSpendRetry:()=>nW,SimplifiedFetchTransport:()=>nR,Polynomial:()=>tY,OP:()=>rI,P2PKH:()=>rT,WalletError:()=>iN,deserializeWalletProtocol:()=>n7,isBroadcastFailure:()=>r1,BeefParty:()=>r2,SecurityLevels:()=>h,Point:()=>tV,BSM:()=>v,ATOMIC_BEEF:()=>rJ,SatoshisPerKilobyte:()=>rV,WalletClient:()=>nv,Validation:()=>I,IdentityClient:()=>n4,Utils:()=>b});var g={};f.r(g),f.d(g,{RIPEMD160:()=>J,SHA1:()=>Z,SHA1HMAC:()=>et,SHA256:()=>Y,SHA256HMAC:()=>ee,SHA512:()=>Q,SHA512HMAC:()=>er,hash160:()=>ec,hash256:()=>eo,htonl:()=>F,pbkdf2:()=>eQ,realHtonl:()=>e2,ripemd160:()=>ei,sha1:()=>en,sha256:()=>ea,sha256hmac:()=>el,sha512:()=>es,sha512hmac:()=>eh,swapBytes32:()=>e0,toArray:()=>U});var b={};f.r(b),f.d(b,{Reader:()=>td,Writer:()=>tu,base64ToArray:()=>tr,constantTimeEquals:()=>ty,encode:()=>tn,fromBase58:()=>to,fromBase58Check:()=>th,minimallyEncode:()=>tf,toArray:()=>e9,toBase58:()=>tc,toBase58Check:()=>tl,toBase64:()=>ta,toHex:()=>e7,toUTF8:()=>ti,verifyNotNull:()=>tb,zero2:()=>e6});var y={};f.r(y),f.d(y,{sign:()=>t$,verify:()=>tz});var m={};f.r(m),f.d(m,{sign:()=>ie,verify:()=>it});var w={};f.r(w),f.d(w,{decrypt:()=>ia,encrypt:()=>ii});var v={};f.r(v),f.d(v,{magicHash:()=>io,sign:()=>ic,verify:()=>il});var I={};f.r(I),f.d(I,{isHexString:()=>i8,parseWalletOutpoint:()=>iH,specOpThrowReviewActions:()=>nw,validateAbortActionArgs:()=>ne,validateAcquireDirectCertificateArgs:()=>nf,validateAcquireIssuanceCertificateArgs:()=>nd,validateBase64String:()=>i0,validateBasketInsertion:()=>nr,validateCreateActionArgs:()=>i5,validateCreateActionInput:()=>i3,validateCreateActionOptions:()=>i4,validateCreateActionOutput:()=>i6,validateDiscoverByAttributesArgs:()=>nb,validateDiscoverByIdentityKeyArgs:()=>ng,validateInteger:()=>iW,validateInternalizeActionArgs:()=>na,validateInternalizeOutput:()=>ni,validateListActionsArgs:()=>nm,validateListCertificatesArgs:()=>nh,validateListOutputsArgs:()=>ny,validateOptionalInteger:()=>iz,validateOptionalOutpointString:()=>ns,validateOriginator:()=>nn,validateOutpointString:()=>no,validatePositiveIntegerOrZero:()=>ij,validateProveCertificateArgs:()=>np,validateRelinquishCertificateArgs:()=>nl,validateRelinquishOutputArgs:()=>nc,validateSatoshis:()=>i$,validateSignActionArgs:()=>i9,validateSignActionOptions:()=>i7,validateStringLength:()=>iG,validateWalletPayment:()=>nt});var k={};f.r(k),f.d(k,{getHashFromURL:()=>nJ,getURLForFile:()=>nX,getURLForHash:()=>nG,isValidURL:()=>nY,normalizeURL:()=>nj});let S="undefined"!=typeof globalThis?globalThis.Buffer:void 0,x=null!=S&&"function"==typeof S.from,E=new Int8Array(256).fill(-1);for(let e=0;e<10;e++)E[48+e]=e;for(let e=0;e<6;e++)E[65+e]=10+e,E[97+e]=10+e;class P{static zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];static groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];static groupBases=[0,0,0x2000000,0x290d741,0x1000000,0x2e90edd,0x39aa400,0x267bf47,0x1000000,0x290d741,1e7,0x12959c3,0x222c000,0x3bd7765,7529536,0xadcea1,0x1000000,0x1704f61,0x206fc40,0x2cddcf9,64e6,4084101,5153632,6436343,7962624,9765625,0xb54ba0,0xdaf26b,0x1069c00,0x138f9ad,243e5,0x1b4d89f,0x2000000,0x25528a1,0x2b54a20,0x3216b93,0x39aa400];static wordSize=26;static WORD_SIZE_BIGINT=BigInt(P.wordSize);static WORD_MASK=(1n<<P.WORD_SIZE_BIGINT)-1n;static MAX_SAFE_INTEGER_BIGINT=BigInt(Number.MAX_SAFE_INTEGER);static MIN_SAFE_INTEGER_BIGINT=BigInt(Number.MIN_SAFE_INTEGER);static MAX_IMULN_ARG=0x3ffffff;static MAX_NUMBER_CONSTRUCTOR_MAG_BIGINT=(1n<<53n)-1n;_magnitude;_sign;_nominalWordLength;red;get negative(){return this._sign}set negative(e){this.assert(0===e||1===e,"Negative property must be 0 or 1"),0n===this._magnitude?this._sign=0:this._sign=+(1===e)}get _computedWordsArray(){if(0n===this._magnitude)return[0];let e=[],t=this._magnitude;for(;t>0n;)e.push(Number(t&P.WORD_MASK)),t>>=P.WORD_SIZE_BIGINT;return e.length>0?e:[0]}get words(){let e=this._computedWordsArray;if(this._nominalWordLength<=e.length)return e;let t=Array(this._nominalWordLength).fill(0);for(let r=0;r<e.length;r++)t[r]=e[r];return t}set words(e){let t=this._sign,r=0n,i=e.length>0?e.length:1;for(let t=i-1;t>=0;t--){let i=void 0===e[t]?0:e[t];r=r<<P.WORD_SIZE_BIGINT|BigInt(i&Number(P.WORD_MASK))}this._magnitude=r,this._sign=t,this._nominalWordLength=i,this.normSign()}get length(){return Math.max(1,this._nominalWordLength)}static isBN(e){return e instanceof P||null!==e&&"object"==typeof e&&e.constructor?.wordSize===P.wordSize&&Array.isArray(e.words)}static max(e,t){return e.cmp(t)>0?e:t}static min(e,t){return 0>e.cmp(t)?e:t}constructor(e=0,t=10,r="be"){if(this._magnitude=0n,this._sign=0,this._nominalWordLength=1,this.red=null,void 0===e&&(e=0),null===e)return void this._initializeState(0n,0);if("bigint"==typeof e){this._initializeState(e<0n?-e:e,+(e<0n)),this.normSign();return}let i=t,n=r;if(("le"===t||"be"===t)&&(n=t,i=10),"number"==typeof e)return void this.initNumber(e,n);if(Array.isArray(e))return void this.initArray(e,n);if("string"==typeof e){"hex"===i&&(i=16),this.assert("number"==typeof i&&i===(0|i)&&i>=2&&i<=36,"Base must be an integer between 2 and 36");const t=e.toString().replace(/\s+/g,"");let r=0,a=0;t.startsWith("-")?(r++,a=1):t.startsWith("+")&&r++;const s=t.substring(r);if(0===s.length){this._initializeState(0n,1===a&&t.startsWith("-")?1:0),this.normSign();return}if(16===i){let e;if("le"===n){const e=[];let t=s;t.length%2!=0&&(t="0"+t);for(let r=0;r<t.length;r+=2){const i=parseInt(t.substring(r,r+2),16);if(isNaN(i))throw Error("Invalid character in "+t);e.push(i)}this.initArray(e,"le"),this._sign=a,this.normSign();return}try{e=BigInt("0x"+s)}catch(e){throw Error("Invalid character in "+s)}this._initializeState(e,a),this.normSign()}else try{if(this._parseBaseString(s,i),this._sign=a,this.normSign(),"le"===n){const e=this._sign;this.initArray(this.toArray("be"),"le"),this._sign=e,this.normSign()}}catch(e){if(e.message.includes("Invalid character in string")||e.message.includes("Invalid digit for base")||e.message.startsWith("Invalid character:"))throw Error("Invalid character");throw e}}else 0!==e?this.assert(!1,"Unsupported input type for BigNumber constructor"):this._initializeState(0n,0)}_bigIntToStringInBase(e,t){if(0n===e)return"0";if(t<2||t>36)throw Error("Base must be between 2 and 36");let r="",i=e>0n?e:-e,n=BigInt(t);for(;i>0n;)r="0123456789abcdefghijklmnopqrstuvwxyz"[Number(i%n)]+r,i/=n;return r}_parseBaseString(e,t){if(0===e.length){this._magnitude=0n,this._finishInitialization();return}this._magnitude=0n;let r=BigInt(t),i=P.groupSizes[t],n=BigInt(P.groupBases[t]);(0===i||0n===n)&&(0===(i=Math.floor(Math.log(0x3ffffff)/Math.log(t)))&&(i=1),n=r**BigInt(i));let a=0,s=e.length,o=s%i;if(0===o&&s>0&&(o=i),o>0){let r=e.substring(a,a+o);this._magnitude=BigInt(this._parseBaseWord(r,t)),a+=o}for(;a<s;){let r=e.substring(a,a+i),s=BigInt(this._parseBaseWord(r,t));this._magnitude=this._magnitude*n+s,a+=i}this._finishInitialization()}_parseBaseWord(e,t){let r=0;for(let i=0;i<e.length;i++){let n,a=e.charCodeAt(i);if(a>=48&&a<=57)n=a-48;else if(a>=65&&a<=90)n=a-65+10;else if(a>=97&&a<=122)n=a-97+10;else throw Error("Invalid character: "+e[i]);if(n>=t)throw Error("Invalid character");r=r*t+n}return r}_initializeState(e,t){this._magnitude=e,this._sign=0n===e?0:t,this._finishInitialization()}_finishInitialization(){if(0n===this._magnitude)this._nominalWordLength=1,this._sign=0;else{let e=this._magnitude.toString(2).length;this._nominalWordLength=Math.max(1,Math.ceil(e/P.wordSize))}}assert(e,t="Assertion failed"){if(!e)throw Error(t)}initNumber(e,t="be"){if(this.assert(BigInt(Math.abs(e))<=P.MAX_NUMBER_CONSTRUCTOR_MAG_BIGINT,"The number is larger than 2 ^ 53 (unsafe)"),this.assert(e%1==0,"Number must be an integer for BigNumber conversion"),this._initializeState(BigInt(Math.abs(e)),+(e<0)),"le"===t){let e=this._sign,t=this.toArray("be");this.initArray(t,"le"),this._sign=e,this.normSign()}return this}initArray(e,t){if(0===e.length)return this._initializeState(0n,0),this;let r=0n;if("be"===t)for(let t=0;t<e.length;t++)r=r<<8n|BigInt(255&e[t]);else for(let t=e.length-1;t>=0;t--)r=r<<8n|BigInt(255&e[t]);return this._initializeState(r,0),this}copy(e){e._magnitude=this._magnitude,e._sign=this._sign,e._nominalWordLength=this._nominalWordLength,e.red=this.red}static move(e,t){e._magnitude=t._magnitude,e._sign=t._sign,e._nominalWordLength=t._nominalWordLength,e.red=t.red}clone(){let e=new P(0n);return this.copy(e),e}expand(e){return this.assert(e>=0,"Expand size must be non-negative"),this._nominalWordLength=Math.max(this._nominalWordLength,e,1),this}strip(){return this._finishInitialization(),this.normSign()}normSign(){return 0n===this._magnitude&&(this._sign=0),this}inspect(){return(null!==this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}_getMinimalHex(){return 0n===this._magnitude?"0":this._magnitude.toString(16)}toString(e=10,t=1){if(16===e||"hex"===e){let e=this._getMinimalHex();if(t>1)for("0"!==e&&e.length%2!=0&&(e="0"+e);e.length%t!=0;)e="0"+e;return(this.isNeg()?"-":"")+e}if("number"!=typeof e||e<2||e>36||e%1!=0)throw Error("Base should be an integer between 2 and 36");return this.toBaseString(e,t)}toBaseString(e,t){if(0n===this._magnitude){let e="0";if(t>1)for(;e.length<t;)e="0"+e;return e}let r=P.groupSizes[e],i=BigInt(P.groupBases[e]);(0===r||0n===i)&&(0===(r=Math.floor(Math.log(Number.MAX_SAFE_INTEGER)/Math.log(e)))&&(r=1),i=BigInt(e)**BigInt(r));let n="",a=this._magnitude;for(;a>0n;){let t=a%i;a/=i;let s=this._bigIntToStringInBase(t,e);if(a>0n){let e=r-s.length;n=e>0&&e<P.zeros.length?P.zeros[e]+s+n:e>0?"0".repeat(e)+s+n:s+n}else n=s+n}if(t>0)for(;n.length<t;)n="0"+n;return(1===this._sign?"-":"")+n}toNumber(){let e=this._getSignedValue();if(e>P.MAX_SAFE_INTEGER_BIGINT||e<P.MIN_SAFE_INTEGER_BIGINT)throw Error("Number can only safely store up to 53 bits");return Number(e)}toBigInt(){return this._getSignedValue()}toJSON(){let e=this._getMinimalHex();return(this.isNeg()?"-":"")+e}toArrayLikeGeneric(e,t){let r=this._magnitude,i=t?0:e.length-1,n=t?1:-1;for(let t=0;t<e.length;++t){if(0n===r&&i>=0&&i<e.length)e[i]=0;else if(i>=0&&i<e.length)e[i]=Number(255n&r);else break;r>>=8n,i+=n}}toArray(e="be",t){this.strip();let r=this.byteLength(),i=t??Math.max(1,r);this.assert(r<=i,"byte array longer than desired length"),this.assert(i>0,"Requested array length <= 0");let n=Array(i).fill(0);return 0n===this._magnitude&&i>0?n:0n===this._magnitude&&0===i?[]:(this.toArrayLikeGeneric(n,"le"===e),n)}bitLength(){return 0n===this._magnitude?0:this._magnitude.toString(2).length}static toBitArray(e){let t=e.bitLength();if(0===t)return[];let r=Array(t),i=e._magnitude;for(let e=0;e<t;e++)r[e]=+((i>>BigInt(e)&1n)!==0n);return r}toBitArray(){return P.toBitArray(this)}zeroBits(){if(0n===this._magnitude)return 0;let e=0,t=this._magnitude;for(;(1n&t)===0n&&0n!==t;)e++,t>>=1n;return e}byteLength(){return 0n===this._magnitude?0:Math.ceil(this.bitLength()/8)}_getSignedValue(){return 1===this._sign?-this._magnitude:this._magnitude}_setValueFromSigned(e){e<0n?(this._magnitude=-e,this._sign=1):(this._magnitude=e,this._sign=0),this._finishInitialization(),this.normSign()}toTwos(e){this.assert(e>=0);let t=BigInt(e),r=this._getSignedValue();1===this._sign&&0n!==this._magnitude&&(r=(1n<<t)+r),r&=(1n<<t)-1n;let i=new P(0n);return i._initializeState(r,0),i}fromTwos(e){this.assert(e>=0);let t=BigInt(e),r=this._magnitude;if(e>0&&(r>>t-1n&1n)!==0n&&0===this._sign){let e=new P(0n);return e._setValueFromSigned(r-(1n<<t)),e}return this.clone()}isNeg(){return 1===this._sign&&0n!==this._magnitude}neg(){return this.clone().ineg()}ineg(){return 0n!==this._magnitude&&(this._sign=+(1!==this._sign)),this}_iuop(e,t){let r=t(this._magnitude,e._magnitude),i=t===((e,t)=>e^t),n=this._nominalWordLength;return i&&(n=Math.max(this.length,e.length)),this._magnitude=r,this._finishInitialization(),i&&(this._nominalWordLength=Math.max(this._nominalWordLength,n)),this.strip()}iuor(e){return this._iuop(e,(e,t)=>e|t)}iuand(e){return this._iuop(e,(e,t)=>e&t)}iuxor(e){return this._iuop(e,(e,t)=>e^t)}_iop(e,t){return this.assert(0===this._sign&&0===e._sign),this._iuop(e,t)}ior(e){return this._iop(e,(e,t)=>e|t)}iand(e){return this._iop(e,(e,t)=>e&t)}ixor(e){return this._iop(e,(e,t)=>e^t)}_uop_new(e,t){return this.length>=e.length?this.clone()[t](e):e.clone()[t](this)}or(e){return this.assert(0===this._sign&&0===e._sign),this._uop_new(e,"iuor")}uor(e){return this._uop_new(e,"iuor")}and(e){return this.assert(0===this._sign&&0===e._sign),this._uop_new(e,"iuand")}uand(e){return this._uop_new(e,"iuand")}xor(e){return this.assert(0===this._sign&&0===e._sign),this._uop_new(e,"iuxor")}uxor(e){return this._uop_new(e,"iuxor")}inotn(e){this.assert("number"==typeof e&&e>=0);let t=BigInt(e);this._magnitude=~this._magnitude&(1n<<t)-1n;let r=0===e?1:Math.ceil(e/P.wordSize);return this._nominalWordLength=Math.max(1,r),this.strip(),this._nominalWordLength=Math.max(this._nominalWordLength,Math.max(1,r)),this}notn(e){return this.clone().inotn(e)}setn(e,t){this.assert("number"==typeof e&&e>=0);let r=BigInt(e);1===t||!0===t?this._magnitude|=1n<<r:this._magnitude&=~(1n<<r);let i=Math.floor(e/P.wordSize)+1;return this._nominalWordLength=Math.max(this._nominalWordLength,i),this._finishInitialization(),this.strip()}iadd(e){return this._setValueFromSigned(this._getSignedValue()+e._getSignedValue()),this}add(e){let t=new P(0n);return t._setValueFromSigned(this._getSignedValue()+e._getSignedValue()),t}isub(e){return this._setValueFromSigned(this._getSignedValue()-e._getSignedValue()),this}sub(e){let t=new P(0n);return t._setValueFromSigned(this._getSignedValue()-e._getSignedValue()),t}mul(e){let t=new P(0n);return t._magnitude=this._magnitude*e._magnitude,t._sign=0n===t._magnitude?0:this._sign^e._sign,t._nominalWordLength=this.length+e.length,t.red=null,t.normSign()}imul(e){return this._magnitude*=e._magnitude,this._sign=0n===this._magnitude?0:this._sign^e._sign,this._nominalWordLength=this.length+e.length,this.red=null,this.normSign()}imuln(e){return this.assert("number"==typeof e,"Assertion failed"),this.assert(Math.abs(e)<=P.MAX_IMULN_ARG,"Assertion failed"),this._setValueFromSigned(this._getSignedValue()*BigInt(e)),this}muln(e){return this.clone().imuln(e)}sqr(){let e=new P(0n);return e._magnitude=this._magnitude*this._magnitude,e._sign=0,e._nominalWordLength=2*this.length,e.red=null,e}isqr(){return this._magnitude*=this._magnitude,this._sign=0,this._nominalWordLength=2*this.length,this.red=null,this}pow(e){if(this.assert(0===e._sign,"Exponent for pow must be non-negative"),e.isZero())return new P(1n);let t=new P(1n),r=this.clone(),i=e.clone(),n=r.isNeg(),a=i.isOdd();for(n&&r.ineg();!i.isZero();)i.isOdd()&&t.imul(r),r.isqr(),i.iushrn(1);return n&&a&&t.ineg(),t}static normalizeNonNegativeBigInt(e,t){if("number"==typeof e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<0)throw Error(`${t} must be a non-negative integer`);return BigInt(e)}if(e<0n)throw Error(`${t} must be a non-negative integer`);return e}iushln(e){let t=P.normalizeNonNegativeBigInt(e,"Shift bits");return 0n===t?this:(this._magnitude<<=t,this._finishInitialization(),this.strip())}ishln(e){return this.assert(0===this._sign,"ishln requires positive number"),this.iushln(e)}iushrn(e,t,r){let i=P.normalizeNonNegativeBigInt(e,"Shift bits");if(0n===i)return null!=r&&r._initializeState(0n,0),this;if(null!=r){let e=this._magnitude&(1n<<i)-1n;r._initializeState(e,0)}return this._magnitude>>=i,this._finishInitialization(),this.strip()}ishrn(e,t,r){return this.assert(0===this._sign,"ishrn requires positive number"),this.iushrn(e,t,r)}shln(e){return this.clone().ishln(e)}ushln(e){return this.clone().iushln(e)}shrn(e){return this.clone().ishrn(e)}ushrn(e){return this.clone().iushrn(e)}testn(e){return this.assert("number"==typeof e&&e>=0),(this._magnitude>>BigInt(e)&1n)!==0n}imaskn(e){this.assert("number"==typeof e&&e>=0),this.assert(0===this._sign,"imaskn works only with positive numbers");let t=BigInt(e);this._magnitude&=0n===t?0n:(1n<<t)-1n;let r=0===e?1:Math.max(1,Math.ceil(e/P.wordSize));return this._nominalWordLength=r,this._finishInitialization(),this._nominalWordLength=Math.max(this._nominalWordLength,r),this.strip()}maskn(e){return this.clone().imaskn(e)}iaddn(e){return this.assert("number"==typeof e),this.assert(Math.abs(e)<=P.MAX_IMULN_ARG,"num is too large"),this._setValueFromSigned(this._getSignedValue()+BigInt(e)),this}_iaddn(e){return this.iaddn(e)}isubn(e){return this.assert("number"==typeof e),this.assert(Math.abs(e)<=P.MAX_IMULN_ARG,"Assertion failed"),this._setValueFromSigned(this._getSignedValue()-BigInt(e)),this}addn(e){return this.clone().iaddn(e)}subn(e){return this.clone().isubn(e)}iabs(){return this._sign=0,this}abs(){return this.clone().iabs()}divmod(e,t,r){if(this.assert(!e.isZero(),"Division by zero"),this.isZero()){let e=new P(0n);return{div:"mod"!==t?e:null,mod:"div"!==t?e:null}}let i=this._getSignedValue(),n=e._getSignedValue(),a=null,s=null;"mod"!==t&&(a=i/n),"div"!==t&&(s=i%n,!0===r&&s<0n&&(s+=n<0n?-n:n));let o=null!==a?new P(0n):null;null!==o&&null!==a&&o._setValueFromSigned(a);let c=null!==s?new P(0n):null;return null!==c&&null!==s&&c._setValueFromSigned(s),{div:o,mod:c}}div(e){return this.divmod(e,"div",!1).div}mod(e){return this.divmod(e,"mod",!1).mod}umod(e){return this.divmod(e,"mod",!0).mod}divRound(e){this.assert(!e.isZero());let t=this._getSignedValue(),r=e._getSignedValue(),i=t/r,n=t%r;if(0n===n){let e=new P(0n);return e._setValueFromSigned(i),e}2n*(n<0n?-n:n)>=(r<0n?-r:r)&&(t>0n&&r>0n||t<0n&&r<0n?i+=1n:i-=1n);let a=new P(0n);return a._setValueFromSigned(i),a}modrn(e){this.assert(0!==e,"Division by zero in modrn");let t=BigInt(Math.abs(e));if(0n===t)throw Error("Division by zero in modrn");let r=this._magnitude%t;return e<0?Number(-r):Number(r)}idivn(e){return this.assert(0!==e),this.assert(Math.abs(e)<=P.MAX_IMULN_ARG,"num is too large"),this._setValueFromSigned(this._getSignedValue()/BigInt(e)),this}divn(e){return this.clone().idivn(e)}egcd(e){this.assert(0===e._sign,"p must not be negative"),this.assert(!e.isZero(),"p must not be zero");let t=this._getSignedValue(),r=e._magnitude,i=1n,n=0n,a=0n,s=1n;for(;0n!==r;){let e=t/r,o=r;r=t%r,t=o,o=n,n=i-e*n,i=o,o=s,s=a-e*s,a=o}let o=new P(0n);o._setValueFromSigned(i);let c=new P(0n);c._setValueFromSigned(a);let l=new P(0n);return l._initializeState(t<0n?-t:t,0),{a:o,b:c,gcd:l}}gcd(e){let t=this._magnitude,r=e._magnitude;if(0n===t){let e=new P(0n);return e._setValueFromSigned(r),e.iabs()}if(0n===r){let e=new P(0n);return e._setValueFromSigned(t),e.iabs()}for(;0n!==r;){let e=t%r;t=r,r=e}let i=new P(0n);return i._initializeState(t,0),i}invm(e){this.assert(!e.isZero()&&0===e._sign,"Modulus for invm must be positive and non-zero");let t=this.egcd(e);if(!t.gcd.eqn(1))throw Error("Inverse does not exist (numbers are not coprime).");return t.a.umod(e)}isEven(){return this._magnitude%2n===0n}isOdd(){return this._magnitude%2n===1n}andln(e){return this.assert(e>=0),Number(this._magnitude&BigInt(e))}bincn(e){this.assert("number"==typeof e&&e>=0);let t=1n<<BigInt(e);return this._setValueFromSigned(this._getSignedValue()+t),this}isZero(){return 0n===this._magnitude}cmpn(e){this.assert(Math.abs(e)<=P.MAX_IMULN_ARG,"Number is too big");let t=this._getSignedValue(),r=BigInt(e);return t<r?-1:+(t>r)}cmp(e){let t=this._getSignedValue(),r=e._getSignedValue();return t<r?-1:+(t>r)}ucmp(e){return this._magnitude<e._magnitude?-1:+(this._magnitude>e._magnitude)}gtn(e){return 1===this.cmpn(e)}gt(e){return 1===this.cmp(e)}gten(e){return this.cmpn(e)>=0}gte(e){return this.cmp(e)>=0}ltn(e){return -1===this.cmpn(e)}lt(e){return -1===this.cmp(e)}lten(e){return 0>=this.cmpn(e)}lte(e){return 0>=this.cmp(e)}eqn(e){return 0===this.cmpn(e)}eq(e){return 0===this.cmp(e)}toRed(e){return this.assert(null==this.red,"Already a number in reduction context"),this.assert(0===this._sign,"toRed works only with positives"),e.convertTo(this).forceRed(e)}fromRed(){return this.assert(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)}forceRed(e){return this.red=e,this}redAdd(e){return this.assert(this.red,"redAdd works only with red numbers"),this.red.add(this,e)}redIAdd(e){return this.assert(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)}redSub(e){return this.assert(this.red,"redSub works only with red numbers"),this.red.sub(this,e)}redISub(e){return this.assert(this.red,"redISub works only with red numbers"),this.red.isub(this,e)}redShl(e){return this.assert(this.red,"redShl works only with red numbers"),this.red.shl(this,e)}redMul(e){return this.assert(this.red,"redMul works only with red numbers"),this.red.verify2(this,e),this.red.mul(this,e)}redIMul(e){return this.assert(this.red,"redIMul works only with red numbers"),this.red.verify2(this,e),this.red.imul(this,e)}redSqr(){return this.assert(this.red,"redSqr works only with red numbers"),this.red.verify1(this),this.red.sqr(this)}redISqr(){return this.assert(this.red,"redISqr works only with red numbers"),this.red.verify1(this),this.red.isqr(this)}redSqrt(){return this.assert(this.red,"redSqrt works only with red numbers"),this.red.verify1(this),this.red.sqrt(this)}redInvm(){return this.assert(this.red,"redInvm works only with red numbers"),this.red.verify1(this),this.red.invm(this)}redNeg(){return this.assert(this.red,"redNeg works only with red numbers"),this.red.verify1(this),this.red.neg(this)}redPow(e){return this.assert(null!=this.red&&null==e.red,"redPow(normalNum)"),this.red.verify1(this),this.red.pow(this,e)}static fromHex(e,t){let r="be";return("little"===t||"le"===t)&&(r="le"),new P(e,16,r)}toHex(e=0){if(this.isZero()&&0===e)return"";let t=this._getMinimalHex();"0"!==t&&t.length%2!=0&&(t="0"+t);let r=2*e;for(;t.length<r;)t="0"+t;return(this.isNeg()?"-":"")+t}static fromJSON(e){return new P(e,16)}static fromNumber(e){return new P(e)}static fromString(e,t){return new P(e,t)}static fromSm(e,t="big"){if(0===e.length)return new P(0n);let r=e.slice();"little"===t&&r.reverse();let i=0;r.length>0&&(128&r[0])!=0&&(i=1,r[0]&=127);let n=0n;if(x){let e=S.from(r).toString("hex");n=0===e.length?0n:BigInt("0x"+e)}else{let e="";for(let t of r)e+=t<16?"0"+t.toString(16):t.toString(16);n=0===e.length?0n:BigInt("0x"+e)}let a=new P(0n);return a._initializeState(n,i),a}toSm(e="big"){let t;if(0n===this._magnitude)return 1===this._sign?[128]:[];let r=this._getMinimalHex();r.length%2!=0&&(r="0"+r);let i=Array(r.length/2);for(let e=0,t=0;e<r.length;e+=2){let n=E[r.charCodeAt(e)],a=E[r.charCodeAt(e+1)];i[t++]=(15&n)<<4|15&a}return 1===this._sign?(128&i[0])!=0?t=[128,...i]:(t=i.slice(),t[0]|=128):t=(128&i[0])!=0?[0,...i]:i.slice(),"little"===e?t.reverse():t}static fromBits(e,t=!1){let r=e>>>24,i=8388607&e,n=(8388608&e)!=0;if(t&&n)throw Error("negative bit set");if(0===r&&0===i){if(n&&t)throw Error("negative bit set for zero value");return new P(0n)}let a=new P(i);return r<=3?a.iushrn((3-r)*8):a.iushln((r-3)*8),n&&a.ineg(),a}toBits(){let e;if(this.strip(),this.isZero()&&!this.isNeg())return 0;let t=this.isNeg(),r=this.abs(),i=r.toArray("be"),n=0;for(;n<i.length-1&&0===i[n];)n++;let a=(i=i.slice(n)).length;if(0!==a||r.isZero()||(i=[0],a=1),r.isZero()&&(a=0,i=[]),0===a)e=0;else if(a<=3){e=0;for(let t=0;t<a;t++)e=e<<8|i[t]}else e=i[0]<<16|i[1]<<8|i[2];(8388608&e)!=0&&a<=255&&(e>>>=8,a++);let s=a<<24|e;return t&&(s|=8388608),s>>>0}static fromScriptNum(e,t=!1,r){if(void 0!==r&&e.length>r)throw Error("script number overflow");if(0===e.length)return new P(0n);if(t&&(127&e[e.length-1])==0&&(e.length<=1||(128&e[e.length-2])==0))throw Error("non-minimally encoded script number");return P.fromSm(e,"little")}toScriptNum(){return this.toSm("little")}_invmp(e){let t;this.assert(0===e._sign,"p must not be negative for _invmp"),this.assert(!e.isZero(),"p must not be zero for _invmp");let r=this.umod(e)._magnitude,i=e._magnitude,n=1n,a=0n,s=e._magnitude;for(;r>1n&&i>1n;){let e=0;for(;(r>>BigInt(e)&1n)===0n;)e++;if(e>0){r>>=BigInt(e);for(let t=0;t<e;++t)(1n&n)!==0n&&(n+=s),n>>=1n}let t=0;for(;(i>>BigInt(t)&1n)===0n;)t++;if(t>0){i>>=BigInt(t);for(let e=0;e<t;++e)(1n&a)!==0n&&(a+=s),a>>=1n}r>=i?(r-=i,n-=a):(i-=r,a-=n)}if(1n===r)t=n;else if(1n===i)t=a;else if(0n===r&&1n===i)t=a;else if(0n===i&&1n===r)t=n;else throw Error("_invmp: GCD is not 1, inverse does not exist. aVal="+r+", bVal="+i);(t%=s)<0n&&(t+=s);let o=new P(0n);return o._initializeState(t,0),o}mulTo(e,t){return t._magnitude=this._magnitude*e._magnitude,t._sign=0n===t._magnitude?0:this._sign^e._sign,t._nominalWordLength=this.length+e.length,t.red=null,t.normSign(),t}}class N{name;p;k;n;tmp;constructor(e,t){this.name=e,this.p=new P(t,16),this.n=this.p.bitLength(),this.k=new P(BigInt(1)).iushln(this.n).isub(this.p),this.tmp=this._tmp()}_tmp(){let e=new P(BigInt(0)),t=Math.ceil(this.n/P.wordSize);return e.expand(Math.max(1,t)),e}ireduce(e){let t;do this.split(e,this.tmp),this.imulK(e),e.iadd(this.tmp),t=e.bitLength();while(t>this.n);let r=t<this.n?-1:e.ucmp(this.p);return 0===r?e.words=[0]:r>0&&e.isub(this.p),e.strip(),e}split(e,t){e.iushrn(this.n,0,t)}imulK(e){return e.imul(this.k)}}class O extends N{constructor(){super("k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}split(e,t){let r=e.words,i=e.length,n=Math.min(i,9),a=Array(n+ +(i>9)).fill(0);for(let e=0;e<n;e++)a[e]=r[e];let s=n;if(i<=9){let r=Array(s);for(let e=0;e<s;++e)r[e]=a[e];t.words=r,e.words=[0];return}let o=r[9];a[s++]=4194303&o;let c=Array(s);for(let e=0;e<s;++e)c[e]=a[e];t.words=c;let l=Array(Math.max(1,i-9)).fill(0),h=0;for(let e=10;e<i;e++){let t=0|r[e];h<l.length&&(l[h++]=(4194303&t)<<4|o>>>22),o=t}o>>>=22,h<l.length?l[h++]=o:0!==o&&l.length;let u=Array(h);for(let e=0;e<h;++e)u[e]=l[e];e.words=u}imulK(e){let t=e.words,r=e.length,i=r+2,n=Array(i).fill(0);for(let e=0;e<r;e++)n[e]=t[e];let a=0;for(let e=0;e<i;e++){let t=0|n[e];a+=977*t,n[e]=0x3ffffff&a,a=64*t+(a/0x4000000|0)}return e.words=n,e}}class A{prime;m;constructor(e){if("k256"===e){const e=new O;this.m=e.p,this.prime=e}else this.assert(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}assert(e,t="Assertion failed"){if(!e)throw Error(t)}verify1(e){this.assert(0===e.negative,"red works only with positives"),this.assert(e.red,"red works only with red numbers")}verify2(e,t){this.assert((e.negative|t.negative)==0,"red works only with positives"),this.assert(null!=e.red&&e.red===t.red,"red works only with red numbers")}imod(e){return null!=this.prime?this.prime.ireduce(e).forceRed(this):(P.move(e,e.umod(this.m).forceRed(this)),e)}neg(e){return e.isZero()?e.clone():this.m.sub(e).forceRed(this)}add(e,t){this.verify2(e,t);let r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r.forceRed(this)}iadd(e,t){this.verify2(e,t);let r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r}sub(e,t){this.verify2(e,t);let r=e.sub(t);return 0>r.cmpn(0)&&r.iadd(this.m),r.forceRed(this)}isub(e,t){this.verify2(e,t);let r=e.isub(t);return 0>r.cmpn(0)&&r.iadd(this.m),r}shl(e,t){return this.verify1(e),this.imod(e.ushln(t))}imul(e,t){return this.verify2(e,t),this.imod(e.imul(t))}mul(e,t){return this.verify2(e,t),this.imod(e.mul(t))}isqr(e){return this.imul(e,e.clone())}sqr(e){return this.mul(e,e)}sqrt(e){if(e.isZero())return e.clone();let t=this.m.andln(3);if(this.assert(t%2==1),3===t){let t=this.m.add(new P(1)).iushrn(2);return this.pow(e,t)}let r=this.m.subn(1),i=0;for(;!r.isZero()&&0===r.andln(1);)i++,r.iushrn(1);this.assert(!r.isZero());let n=new P(1).toRed(this),a=n.redNeg(),s=this.m.subn(1).iushrn(1),o=this.m.bitLength(),c=new P(2*o*o).toRed(this);for(;0!==this.pow(c,s).cmp(a);)c.redIAdd(a);let l=this.pow(c,r),h=this.pow(e,r.addn(1).iushrn(1)),u=this.pow(e,r),d=i;for(;0!==u.cmp(n);){let e=u,t=0;for(;0!==e.cmp(n);t++)e=e.redSqr();this.assert(t<d);let r=this.pow(l,new P(1).iushln(d-t-1));h=h.redMul(r),l=r.redSqr(),u=u.redMul(l),d=t}return h}invm(e){let t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)}pow(e,t){if(t.isZero())return new P(1).toRed(this);if(0===t.cmpn(1))return e.clone();let r=Array(16);r[0]=new P(1).toRed(this),r[1]=e;let i=2;for(;i<r.length;i++)r[i]=this.mul(r[i-1],e);let n=r[0],a=0,s=0,o=t.bitLength()%26;for(0===o&&(o=26),i=t.length-1;i>=0;i--){let e=t.words[i];for(let t=o-1;t>=0;t--){let o=e>>t&1;if(n!==r[0]&&(n=this.sqr(n)),0===o&&0===a){s=0;continue}a<<=1,a|=o,(4==++s||0===i&&0===t)&&(n=this.mul(n,r[a]),s=0,a=0)}o=26}return n}convertTo(e){let t=e.umod(this.m);return t===e?t.clone():t}convertFrom(e){let t=e.clone();return t.red=null,t}}class _ extends A{shift;r;r2;rinv;minv;constructor(e){super(e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new P(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}convertTo(e){return this.imod(e.ushln(this.shift))}convertFrom(e){let t=this.imod(e.mul(this.rinv));return t.red=null,t}imul(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;let r=e.imul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),a=n;return n.cmp(this.m)>=0?a=n.isub(this.m):0>n.cmpn(0)&&(a=n.iadd(this.m)),a.forceRed(this)}mul(e,t){if(e.isZero()||t.isZero())return new P(0).forceRed(this);let r=e.mul(t),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).iushrn(this.shift),a=n;return n.cmp(this.m)>=0?a=n.isub(this.m):0>n.cmpn(0)&&(a=n.iadd(this.m)),a.forceRed(this)}invm(e){return this.imod(e._invmp(this.m).mul(this.r2)).forceRed(this)}}class T{curve;type;precomputed;constructor(e){this.curve=new tD,this.type=e,this.precomputed=null}}class C extends T{x;y;z;zOne;constructor(e,t,r){super("jacobian"),null===e&&null===t&&null===r?(this.x=this.curve.one,this.y=this.curve.one,this.z=new P(0)):(P.isBN(e)||(e=new P(e,16)),this.x=e,P.isBN(t)||(t=new P(t,16)),this.y=t,P.isBN(r)||(r=new P(r,16)),this.z=r),null==this.x.red&&(this.x=this.x.toRed(this.curve.red)),null==this.y.red&&(this.y=this.y.toRed(this.curve.red)),null==this.z.red&&(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.isInfinity()&&(this.x=this.curve.one,this.y=this.curve.one,this.z=new P(0).toRed(this.curve.red),this.zOne=!1)}toP(){if(this.isInfinity())return new tV(null,null);let e=this.z.redInvm(),t=e.redSqr();return new tV(this.x.redMul(t),this.y.redMul(t).redMul(e))}neg(){return new C(this.x,this.y.redNeg(),this.z)}add(e){if(this.isInfinity())return e;if(e.isInfinity())return this;let t=e.z.redSqr(),r=this.z.redSqr(),i=this.x.redMul(t),n=e.x.redMul(r),a=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),o=i.redSub(n),c=a.redSub(s);if(0===o.cmpn(0))if(0!==c.cmpn(0))return new C(null,null,null);else return this.dbl();let l=o.redSqr(),h=l.redMul(o),u=i.redMul(l),d=c.redSqr().redIAdd(h).redISub(u).redISub(u),f=c.redMul(u.redISub(d)).redISub(a.redMul(h));return new C(d,f,this.z.redMul(e.z).redMul(o))}mixedAdd(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;if(null===e.x||null===e.y)throw Error("Point coordinates cannot be null");let t=this.z.redSqr(),r=this.x,i=e.x.redMul(t),n=this.y,a=e.y.redMul(t).redMul(this.z),s=r.redSub(i),o=n.redSub(a);if(0===s.cmpn(0))if(0!==o.cmpn(0))return new C(null,null,null);else return this.dbl();let c=s.redSqr(),l=c.redMul(s),h=r.redMul(c),u=o.redSqr().redIAdd(l).redISub(h).redISub(h),d=o.redMul(h.redISub(u)).redISub(n.redMul(l));return new C(u,d,this.z.redMul(s))}dblp(e){if(0===e||this.isInfinity())return this;if(void 0===e)return this.dbl();let t=this;for(let r=0;r<e;r++)t=t.dbl();return t}dbl(){let e,t,r;if(this.isInfinity())return this;if(this.zOne){let i=this.x.redSqr(),n=this.y.redSqr(),a=n.redSqr(),s=this.x.redAdd(n).redSqr().redISub(i).redISub(a);s=s.redIAdd(s);let o=i.redAdd(i).redIAdd(i),c=o.redSqr().redISub(s).redISub(s),l=a.redIAdd(a);l=(l=l.redIAdd(l)).redIAdd(l),e=c,t=o.redMul(s.redISub(c)).redISub(l),r=this.y.redAdd(this.y)}else{let i=this.x.redSqr(),n=this.y.redSqr(),a=n.redSqr(),s=this.x.redAdd(n).redSqr().redISub(i).redISub(a);s=s.redIAdd(s);let o=i.redAdd(i).redIAdd(i),c=o.redSqr(),l=a.redIAdd(a);l=(l=l.redIAdd(l)).redIAdd(l),e=c.redISub(s).redISub(s),t=o.redMul(s.redISub(e)).redISub(l),r=(r=this.y.redMul(this.z)).redIAdd(r)}return new C(e,t,r)}eq(e){if("affine"===e.type)return this.eq(e.toJ());if(this===e||this.isInfinity()&&e.isInfinity())return!0;if(this.isInfinity()!==e.isInfinity())return!1;let t=this.z.redSqr(),r=e.z.redSqr();if(0!==this.x.redMul(r).redISub(e.x.redMul(t)).cmpn(0))return!1;let i=t.redMul(this.z),n=r.redMul(e.z);return 0===this.y.redMul(n).redISub(e.y.redMul(i)).cmpn(0)}eqXToP(e){let t=this.z.redSqr(),r=e.toRed(this.curve?.red).redMul(t);if(0===this.x.cmp(r))return!0;let i=e.clone();if(null===this.curve||null==this.curve.redN)throw Error("Curve or redN is not initialized.");let n=this.curve.redN.redMul(t);for(;0>i.cmp(this.curve.p)&&(i.iadd(this.curve.n),!(i.cmp(this.curve.p)>=0));)if(r.redIAdd(n),0===this.x.cmp(r))return!0;return!1}inspect(){return this.isInfinity()?"<EC JPoint Infinity>":"<EC JPoint x: "+this.x.toString(16,2)+" y: "+this.y.toString(16,2)+" z: "+this.z.toString(16,2)+">"}isInfinity(){return 0===this.z.cmpn(0)}}let R=/^[0-9a-fA-F]*$/;function B(e){if("string"!=typeof e)throw TypeError("Invalid hex string");if(0!==e.length&&!R.test(e))throw Error("Invalid hex string")}let V=(e,t="Hash assertion failed")=>{if(!e)throw Error(t)};class D{pending;pendingTotal;blockSize;outSize;endian;_delta8;_delta32;padLength;hmacStrength;constructor(e,t,r,i){this.pending=null,this.pendingTotal=0,this.blockSize=e,this.outSize=t,this.hmacStrength=r,this.padLength=i/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}_update(e,t){throw Error("Not implemented")}_digest(){throw Error("Not implemented")}_digestHex(){throw Error("Not implemented")}update(e,t){if(e=U(e,t),null==this.pending?this.pending=e:this.pending=this.pending.concat(e),this.pendingTotal+=e.length,this.pending.length>=this._delta8){let t=(e=this.pending).length%this._delta8;this.pending=e.slice(e.length-t,e.length),0===this.pending.length&&(this.pending=null),e=function(e,t,r,i){let n=r-0;V(n%4==0);let a=Array(n/4);for(let t=0,r=0;t<a.length;t++,r+=4){let n;n="big"===i?e[r]<<24|e[r+1]<<16|e[r+2]<<8|e[r+3]:e[r+3]<<24|e[r+2]<<16|e[r+1]<<8|e[r],a[t]=n>>>0}return a}(e,0,e.length-t,this.endian);for(let t=0;t<e.length;t+=this._delta32)this._update(e,t)}return this}digest(){return this.update(this._pad()),V(null===this.pending),this._digest()}digestHex(){return this.update(this._pad()),V(null===this.pending),this._digestHex()}_pad(){let e,t=this.pendingTotal;if(!Number.isSafeInteger(t)||t<0)throw Error("Message too long for this hash function");let r=this._delta8,i=r-(t+this.padLength)%r,n=Array(i+this.padLength);for(e=1,n[0]=128;e<i;e++)n[e]=0;let a=this.padLength,s=1n<<BigInt(8*a),o=8n*BigInt(t);if(o>=s)throw Error("Message too long for this hash function");if("big"===this.endian){let t=Array(a);for(let e=a-1;e>=0;e--)t[e]=Number(255n&o),o>>=8n;for(let r=0;r<a;r++)n[e++]=t[r]}else for(let t=0;t<a;t++)n[e++]=Number(255n&o),o>>=8n;return n}}function U(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];let r=[];if("string"==typeof e)if("hex"!==t){let t=0;for(let a=0;a<e.length;a++){let s=e.charCodeAt(a);if(s<128)r[t++]=s;else if(s<2048)r[t++]=s>>6|192,r[t++]=63&s|128;else{var i,n;(i=e,n=a,(64512&i.charCodeAt(n))!=55296||n<0||n+1>=i.length?1:(64512&i.charCodeAt(n+1))!=56320)?r[t++]=s>>12|224:(s=65536+((1023&s)<<10)+(1023&e.charCodeAt(++a)),r[t++]=s>>18|240,r[t++]=s>>12&63|128),r[t++]=s>>6&63|128,r[t++]=63&s|128}}}else{B(e),e=function(e){if(B(e),0===e.length)return"";let t=e.toLowerCase();return t.length%2!=0&&(t="0"+t),t}(e);for(let t=0;t<e.length;t+=2)r.push(parseInt(e[t]+e[t+1],16))}else for(let t=0;t<e.length;t++)r[t]=0|e[t];return r}function F(e){return e0(e)}function L(e,t){let r="";for(let i=0;i<e.length;i++){let n=e[i];"little"===t&&(n=e0(n)),r+=function(e){if(7===e.length)return"0"+e;if(6===e.length)return"00"+e;if(5===e.length)return"000"+e;if(4===e.length)return"0000"+e;if(3===e.length)return"00000"+e;else if(2===e.length)return"000000"+e;else if(1===e.length)return"0000000"+e;else return e}(n.toString(16))}return r}function K(e){let t="";for(let r of e)t+=r.toString(16).padStart(2,"0");return t}function H(e,t){let r=Array(4*e.length);for(let i=0,n=0;i<e.length;i++,n+=4){let a=e[i];"big"===t?(r[n]=a>>>24,r[n+1]=a>>>16&255,r[n+2]=a>>>8&255,r[n+3]=255&a):(r[n+3]=a>>>24,r[n+2]=a>>>16&255,r[n+1]=a>>>8&255,r[n]=255&a)}return r}function q(e,t){return e>>>t|e<<32-t}function M(e,t){return e<<t|e>>>32-t}function $(e,t){return e+t>>>0}let z=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],W=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],j=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],G=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];function X(e,t,r,i){return e<=15?t^r^i:e<=31?t&r|~t&i:e<=47?(t|~r)^i:e<=63?t&i|r&~i:t^(r|~i)}class J extends D{h;constructor(){super(512,160,192,64),this.endian="little",this.h=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],this.endian="little"}_update(e,t){var r,i,n,a,s,o;let c,l=this.h[0],h=this.h[1],u=this.h[2],d=this.h[3],f=this.h[4],p=l,g=h,b=u,y=d,m=f;for(let w=0;w<80;w++){c=$(M((r=l,i=X(w,h,u,d),r+i+e[z[w]+t]+((s=w)<=15?0:s<=31?0x5a827999:s<=47?0x6ed9eba1:s<=63?0x8f1bbcdc:0xa953fd4e)>>>0),j[w]),f),l=f,f=d,d=M(u,10),u=h,h=c,c=$(M((n=p,a=X(79-w,g,b,y),n+a+e[W[w]+t]+((o=w)<=15?0x50a28be6:o<=31?0x5c4dd124:o<=47?0x6d703ef3:0x7a6d76e9*!!(o<=63))>>>0),G[w]),m),p=m,m=y,y=M(b,10),b=g,g=c}c=this.h[1]+u+y>>>0,this.h[1]=this.h[2]+d+m>>>0,this.h[2]=this.h[3]+f+p>>>0,this.h[3]=this.h[4]+l+g>>>0,this.h[4]=this.h[0]+h+b>>>0,this.h[0]=c}_digest(){return H(this.h,"little")}_digestHex(){return L(this.h,"little")}}class Y{h;constructor(){this.h=new eH}update(e,t){let r=e instanceof Uint8Array?e:Uint8Array.from(U(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return K(this.h.digest())}}class Z extends D{h;W;k;constructor(){super(512,160,80,64),this.k=[0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6],this.h=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],this.W=Array(80)}_update(e,t){let r,i=this.W;for(void 0===t&&(t=0),r=0;r<16;r++)i[r]=e[t+r];for(;r<i.length;r++)i[r]=M(i[r-3]^i[r-8]^i[r-14]^i[r-16],1);let n=this.h[0],a=this.h[1],s=this.h[2],o=this.h[3],c=this.h[4];for(r=0;r<i.length;r++){var l,h,u,d,f,p,g,b,y;let e=~~(r/20),t=(d=M(n,5),l=a,h=s,u=o,f=0===e?(p=l)&h^~p&u:1===e||3===e?l^h^u:2===e?(g=l)&(b=h)^g&(y=u)^b&y:0,d+f+c+i[r]+this.k[e]>>>0);c=o,o=s,s=M(a,30),a=n,n=t}this.h[0]=$(this.h[0],n),this.h[1]=$(this.h[1],a),this.h[2]=$(this.h[2],s),this.h[3]=$(this.h[3],o),this.h[4]=$(this.h[4],c)}_digest(){return H(this.h,"big")}_digestHex(){return L(this.h,"big")}}class Q{h;constructor(){this.h=new eX}update(e,t){let r=Uint8Array.from(U(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return K(this.h.digest())}}class ee{h;blockSize=64;outSize=32;constructor(e){const t=e instanceof Uint8Array?e:Uint8Array.from(U(e,"string"==typeof e?"hex":void 0));this.h=new eY(eq,t)}update(e,t){let r=e instanceof Uint8Array?e:Uint8Array.from(U(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return K(this.h.digest())}}class et{inner;outer;blockSize=64;constructor(e){let t;for((e=U(e,"hex")).length>this.blockSize&&(e=new Z().update(e).digest()),t=e.length;t<this.blockSize;t++)e.push(0);for(t=0;t<e.length;t++)e[t]^=54;for(t=0,this.inner=new Z().update(e);t<e.length;t++)e[t]^=106;this.outer=new Z().update(e)}update(e,t){return this.inner.update(e,t),this}digest(){return this.outer.update(this.inner.digest()),this.outer.digest()}digestHex(){return this.outer.update(this.inner.digest()),this.outer.digestHex()}}class er{h;blockSize=128;outSize=32;constructor(e){const t=e instanceof Uint8Array?e:Uint8Array.from(U(e,"string"==typeof e?"hex":void 0));this.h=new eY(eJ,t)}update(e,t){let r=e instanceof Uint8Array?e:Uint8Array.from(U(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return K(this.h.digest())}}let ei=(e,t)=>new J().update(e,t).digest(),en=(e,t)=>new Z().update(e,t).digest(),ea=(e,t)=>new Y().update(e,t).digest(),es=(e,t)=>new Q().update(e,t).digest(),eo=(e,t)=>{let r=new Y().update(e,t).digest();return new Y().update(r).digest()},ec=(e,t)=>{let r=new Y().update(e,t).digest();return new J().update(r).digest()},el=(e,t,r)=>new ee(e).update(t,r).digest(),eh=(e,t,r)=>new er(e).update(t,r).digest();function eu(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got ${e}`)}function ed(e,...t){if(!(e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name))throw Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length)){let r=t.join(",");throw Error(`Uint8Array expected of length ${r}, got length=${e.length}`)}}function ef(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.createHasher");eu(e.outputLen),eu(e.blockLen)}function ep(e,t=!0){if(!0===e.destroyed)throw Error("Hash instance has been destroyed");if(t&&!0===e.finished)throw Error("Hash#digest() has already been called")}function eg(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function eb(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ey(e){return"string"==typeof e&&(e=em(e)),ed(e),e}function em(e){if("string"!=typeof e)throw Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ew(e){return"string"==typeof e&&(e=em(e)),ed(e),e}class ev{}function eI(e){let t=t=>e().update(ey(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}let ek=BigInt(0x100000000-1),eS=BigInt(32),ex=(e,t,r)=>e>>>r,eE=(e,t,r)=>e<<32-r|t>>>r,eP=(e,t,r)=>e>>>r|t<<32-r,eN=(e,t,r)=>e<<32-r|t>>>r,eO=(e,t,r)=>e<<64-r|t>>>r-32,eA=(e,t,r)=>e>>>r-32|t<<64-r;function e_(e,t,r,i){let n=(t>>>0)+(i>>>0);return{h:e+r+(n/0x100000000|0)|0,l:0|n}}let eT=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),eC=(e,t,r,i)=>t+r+i+(e/0x100000000|0)|0,eR=(e,t,r,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(i>>>0),eB=(e,t,r,i,n)=>t+r+i+n+(e/0x100000000|0)|0,eV=(e,t,r,i,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(i>>>0)+(n>>>0),eD=(e,t,r,i,n,a)=>t+r+i+n+a+(e/0x100000000|0)|0;class eU extends ev{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,r,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=eb(this.buffer)}update(e){ep(this),ed(e=ey(e));let{view:t,buffer:r,blockLen:i}=this,n=e.length;for(let a=0;a<n;){let s=Math.min(i-this.pos,n-a);if(s===i){let t=eb(e);for(;i<=n-a;a+=i)this.process(t,a);continue}r.set(e.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ep(this);ed(e);let t=this.outputLen;if(e.length<t)throw Error(`digestInto() expects output buffer of length at least ${t}`);this.finished=!0;let{buffer:r,view:i,blockLen:n,isLE:a}=this,{pos:s}=this;r[s++]=128,eg(this.buffer.subarray(s)),this.padOffset>n-s&&(this.process(i,0),s=0);for(let e=s;e<n;e++)r[e]=0;(function(e,t,r,i){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,i);let n=BigInt(32),a=BigInt(0xffffffff),s=Number(r>>n&a),o=Number(r&a),c=4*!!i,l=4*!i;e.setUint32(t+c,s,i),e.setUint32(t+l,o,i)})(i,n-8,BigInt(8*this.length),a),this.process(i,0);let o=eb(e),c=this.outputLen;if(c%4!=0)throw Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,h=this.get();if(l>h.length)throw Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)o.setUint32(4*e,h[e],a)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){(e||=new this.constructor).set(...this.get());let{blockLen:t,buffer:r,length:i,finished:n,destroyed:a,pos:s}=this;return e.destroyed=a,e.finished=n,e.length=i,e.pos=s,i%t!=0&&e.buffer.set(r),e}clone(){return this._cloneInto()}}let eF=Uint32Array.from([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),eL=Uint32Array.from([0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174,0xe49b69c1,0xefbe4786,0xfc19dc6,0x240ca1cc,0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da,0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7,0xc6e00bf3,0xd5a79147,0x6ca6351,0x14292967,0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13,0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85,0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3,0xd192e819,0xd6990624,0xf40e3585,0x106aa070,0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5,0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3,0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208,0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2]),eK=new Uint32Array(64);class eH extends eU{A=0|eF[0];B=0|eF[1];C=0|eF[2];D=0|eF[3];E=0|eF[4];F=0|eF[5];G=0|eF[6];H=0|eF[7];constructor(e=32){super(64,e,8,!1)}get(){let{A:e,B:t,C:r,D:i,E:n,F:a,G:s,H:o}=this;return[e,t,r,i,n,a,s,o]}set(e,t,r,i,n,a,s,o){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|i,this.E=0|n,this.F=0|a,this.G=0|s,this.H=0|o}process(e,t){var r,i,n,a,s,o,c,l,h;for(let r=0;r<16;r++,t+=4)eK[r]=e.getUint32(t);for(let e=16;e<64;e++){let t=eK[e-15],r=eK[e-2],i=q(t,7)^q(t,18)^t>>>3,n=q(r,17)^q(r,19)^r>>>10;eK[e]=$($(i,eK[e-7]),$(n,eK[e-16]))}let{A:u,B:d,C:f,D:p,E:g,F:b,G:y,H:m}=this;for(let e=0;e<64;e++){let t=(n=m,a=q(r=g,6)^q(r,11)^q(r,25),s=(i=g)&b^~i&y,n+a+s+eL[e]+eK[e]>>>0),w=$(q(o=u,2)^q(o,13)^q(o,22),(c=u)&(l=d)^c&(h=f)^l&h);m=y,y=b,b=g,g=$(p,t),p=f,f=d,d=u,u=$(t,w)}this.A=$(this.A,u),this.B=$(this.B,d),this.C=$(this.C,f),this.D=$(this.D,p),this.E=$(this.E,g),this.F=$(this.F,b),this.G=$(this.G,y),this.H=$(this.H,m)}roundClean(){eg(eK)}destroy(){eg(this.buffer),this.set(0,0,0,0,0,0,0,0)}}let eq=eI(()=>new eH),eM=Uint32Array.from([0x6a09e667,0xf3bcc908,0xbb67ae85,0x84caa73b,0x3c6ef372,0xfe94f82b,0xa54ff53a,0x5f1d36f1,0x510e527f,0xade682d1,0x9b05688c,0x2b3e6c1f,0x1f83d9ab,0xfb41bd6b,0x5be0cd19,0x137e2179]),e$=function(e,t=!1){let r=e.length,i=new Uint32Array(r),n=new Uint32Array(r);for(let a=0;a<r;a++){let{h:r,l:s}=function(e,t=!1){return t?{h:Number(e&ek),l:Number(e>>eS&ek)}:{h:0|Number(e>>eS&ek),l:0|Number(e&ek)}}(e[a],t);i[a]=r,n[a]=s}return[i,n]}(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0f