UNPKG

@bsv/sdk

Version:

BSV Blockchain Software Development Kit

1 lines 366 kB
!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;var t,r,i,a,n={};n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var s={};n.r(s),n.d(s,{Signature:()=>tu,SHIPCast:()=>iv,BEEF_V1:()=>ru,BEEF_V2:()=>rf,BeefParty:()=>rw,Polynomial:()=>tN,SHIPBroadcaster:()=>iv,KNOWN_IDENTITY_TYPES:()=>iT,Utils:()=>c,KeyDeriver:()=>rj,SignedMessage:()=>h,SymmetricKey:()=>tz,LocalKVStore:()=>iH,WhatsOnChain:()=>ro,IdentityClient:()=>iU,ScriptEvaluationError:()=>tQ,defaultHttpClient:()=>ri,defaultIdentity:()=>i_,RPuzzle:()=>t6,WalletClient:()=>r7,verifyNonce:()=>ia,SatoshisPerKilobyte:()=>t9,PrivateKey:()=>tO,walletErrors:()=>i,KeyShares:()=>tP,XDM:()=>rQ,HTTPSOverlayBroadcastFacilitator:()=>iI,Certificate:()=>r0,HD:()=>rD,CompletedProtoWallet:()=>ir,AuthFetch:()=>iu,NodejsHttpClient:()=>rt,ProtoWallet:()=>rX,StorageUtils:()=>f,CachedKeyDeriver:()=>rG,ECIES:()=>rM,HTTPWalletWire:()=>r8,PointInFiniteField:()=>tE,ARC:()=>rn,Curve:()=>td,DRBG:()=>tf,ECDSA:()=>l,MasterCertificate:()=>ie,Random:()=>tx,TOTP:()=>rz,VerifiableCertificate:()=>it,WindowCWISubstrate:()=>rY,defaultChainTracker:()=>rc,DEFAULT_SLAP_TRACKERS:()=>ig,ReactNativeWebView:()=>r5,DEFAULT_IDENTITY_CLIENT_OPTIONS:()=>iA,WalletErrors:()=>rZ,WalletError:()=>rJ,StorageUploader:()=>iP,BlockHeadersService:()=>rE,Spend:()=>t2,Hash:()=>o,validateCertificates:()=>ic,Schnorr:()=>tj,Script:()=>tY,TX_DATA_FORMAT:()=>t,WalletWireTransceiver:()=>r2,EncryptedMessage:()=>d,TransactionSignature:()=>tW,fromUtxo:()=>r$,Beef:()=>rb,HTTPWalletJSON:()=>r4,OverlayAdminTokenTemplate:()=>ip,SimplifiedFetchTransport:()=>id,TopicBroadcaster:()=>iv,BeefTx:()=>rh,MerklePath:()=>rl,WhatsOnChainBroadcaster:()=>rI,defaultBroadcaster:()=>rs,getVerifiableCertificates:()=>io,LockingScript:()=>tJ,HTTPSOverlayLookupFacilitator:()=>iy,FetchHttpClient:()=>rr,Peer:()=>il,LookupResolver:()=>iw,PublicKey:()=>tv,binaryHttpClient:()=>rS,StorageDownloader:()=>iO,BigNumber:()=>p,SessionManager:()=>ii,SecurityLevels:()=>r,WalletWireProcessor:()=>r9,createNonce:()=>is,isBroadcastResponse:()=>rm,OP:()=>tX,P2PKH:()=>t3,WERR_REVIEW_ACTIONS:()=>r6,Teranode:()=>rx,UnlockingScript:()=>tZ,LivePolicy:()=>re,deserializeWalletProtocol:()=>iB,RegistryClient:()=>iD,Point:()=>th,BSM:()=>u,Mnemonic:()=>rH,isBroadcastFailure:()=>ry,Transaction:()=>rg,PushDrop:()=>t7,ATOMIC_BEEF:()=>rp,DEFAULT_TESTNET_SLAP_TRACKERS:()=>im});var o={};n.r(o),n.d(o,{RIPEMD160:()=>U,SHA1:()=>B,SHA1HMAC:()=>K,SHA256:()=>D,SHA256HMAC:()=>L,SHA512:()=>H,SHA512HMAC:()=>F,hash160:()=>j,hash256:()=>W,pbkdf2:()=>eH,ripemd160:()=>q,sha1:()=>M,sha256:()=>$,sha256hmac:()=>G,sha512:()=>z,sha512hmac:()=>X,toArray:()=>S});var c={};n.r(c),n.d(c,{Reader:()=>eQ,Writer:()=>eZ,encode:()=>ez,fromBase58:()=>eG,fromBase58Check:()=>eJ,minimallyEncode:()=>e0,toArray:()=>eF,toBase58:()=>eX,toBase58Check:()=>eY,toBase64:()=>eW,toHex:()=>eK,toUTF8:()=>e$,zero2:()=>eL});var l={};n.r(l),n.d(l,{sign:()=>tw,verify:()=>tI});var h={};n.r(h),n.d(h,{sign:()=>rP,verify:()=>rO});var d={};n.r(d),n.d(d,{decrypt:()=>rT,encrypt:()=>rA});var u={};n.r(u),n.d(u,{magicHash:()=>rR,sign:()=>rV,verify:()=>rU});var f={};n.r(f),n.d(f,{getHashFromURL:()=>iE,getURLForFile:()=>ix,getURLForHash:()=>iS,isValidURL:()=>iN,normalizeURL:()=>ik});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,a=r;if(("le"===t||"be"===t)&&(a=t,i=10),"number"==typeof e)return void this.initNumber(e,a);if(Array.isArray(e))return void this.initArray(e,a);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");let t=e.toString().replace(/\s+/g,""),r=0,n=0;t.startsWith("-")?(r++,n=1):t.startsWith("+")&&r++;let s=t.substring(r);if(0===s.length){this._initializeState(0n,1===n&&t.startsWith("-")?1:0),this.normSign();return}if(16===i){let e;if("le"===a){let e=[],t=s;t.length%2!=0&&(t="0"+t);for(let r=0;r<t.length;r+=2){let 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=n,this.normSign();return}try{e=BigInt("0x"+s)}catch(e){throw Error("Invalid character in "+s)}this._initializeState(e,n),this.normSign()}else try{if(this._parseBaseString(s,i),this._sign=n,this.normSign(),"le"===a){let 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,a=BigInt(t);for(;i>0n;)r="0123456789abcdefghijklmnopqrstuvwxyz"[Number(i%a)]+r,i/=a;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],a=BigInt(p.groupBases[t]);(0===i||0n===a)&&(0===(i=Math.floor(Math.log(0x3ffffff)/Math.log(t)))&&(i=1),a=r**BigInt(i));let n=0,s=e.length,o=s%i;if(0===o&&s>0&&(o=i),o>0){let r=e.substring(n,n+o);this._magnitude=BigInt(this._parseBaseWord(r,t)),n+=o}for(;n<s;){let r=e.substring(n,n+i),s=BigInt(this._parseBaseWord(r,t));this._magnitude=this._magnitude*a+s,n+=i}this._finishInitialization()}_parseBaseWord(e,t){let r=0;for(let i=0;i<e.length;i++){let a,n=e.charCodeAt(i);if(n>=48&&n<=57)a=n-48;else if(n>=65&&n<=90)a=n-65+10;else if(n>=97&&n<=122)a=n-97+10;else throw Error("Invalid character: "+e[i]);if(a>=t)throw Error("Invalid character");r=r*t+a}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 a="",n=this._magnitude;for(;n>0n;){let t=n%i;n/=i;let s=this._bigIntToStringInBase(t,e);if(n>0n){let e=r-s.length;a=e>0&&e<p.zeros.length?p.zeros[e]+s+a:e>0?"0".repeat(e)+s+a:s+a}else a=s+a}if(t>0)for(;a.length<t;)a="0"+a;return(1===this._sign?"-":"")+a}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)}toJSON(){let e=this._getMinimalHex();return(this.isNeg()?"-":"")+e}toArrayLikeGeneric(e,t){let r=this._magnitude,i=t?0:e.length-1,a=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+=a}}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 a=Array(i).fill(0);return 0n===this._magnitude&&i>0?a:0n===this._magnitude&&0===i?[]:(this.toArrayLikeGeneric(a,"le"===e),a)}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),a=this._nominalWordLength;return i&&(a=Math.max(this.length,e.length)),this._magnitude=r,this._finishInitialization(),i&&(this._nominalWordLength=Math.max(this._nominalWordLength,a)),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(),a=r.isNeg(),n=i.isOdd();for(a&&r.ineg();!i.isZero();)i.isOdd()&&t.imul(r),r.isqr(),i.iushrn(1);return a&&n&&t.ineg(),t}iushln(e){return(this.assert("number"==typeof e&&e>=0),0===e)?this:(this._magnitude<<=BigInt(e),this._finishInitialization(),this.strip())}ishln(e){return this.assert(0===this._sign,"ishln requires positive number"),this.iushln(e)}iushrn(e,t,r){if(this.assert("number"==typeof e&&e>=0),0===e)return null!=r&&r._initializeState(0n,0),this;if(null!=r){let t=(1n<<BigInt(e))-1n,i=this._magnitude&t;r._initializeState(i,0)}return this._magnitude>>=BigInt(e),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(),a=e._getSignedValue(),n=null,s=null;"mod"!==t&&(n=i/a),"div"!==t&&(s=i%a,!0===r&&s<0n&&(s+=a<0n?-a:a));let o=null!==n?new p(0n):null;null!==o&&null!==n&&o._setValueFromSigned(n);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,a=t%r;if(0n===a){let e=new p(0n);return e._setValueFromSigned(i),e}2n*(a<0n?-a:a)>=(r<0n?-r:r)&&(t>0n&&r>0n||t<0n&&r<0n?i+=1n:i-=1n);let n=new p(0n);return n._setValueFromSigned(i),n}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,a=0n,n=0n,s=1n;for(;0n!==r;){let e=t/r,o=r;r=t%r,t=o,o=a,a=i-e*a,i=o,o=s,s=n-e*s,n=o}let o=new p(0n);o._setValueFromSigned(i);let c=new p(0n);c._setValueFromSigned(n);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=0,i="";if("little"===t){let t=e.length-1,a=e[t];(128&a)!=0&&(r=1,a&=127),i+=(a<16?"0":"")+a.toString(16);for(let r=t-1;r>=0;r--){let t=e[r];i+=(t<16?"0":"")+t.toString(16)}}else{let t=e[0];(128&t)!=0&&(r=1,t&=127),i+=(t<16?"0":"")+t.toString(16);for(let t=1;t<e.length;t++){let r=e[t];i+=(r<16?"0":"")+r.toString(16)}}let a=""===i?0n:BigInt("0x"+i),n=new p(0n);return n._initializeState(a,r),n}toSm(e="big"){if(0n===this._magnitude)return 1===this._sign?[128]:[];let t=this._getMinimalHex();t.length%2!=0&&(t="0"+t);let r=Array(t.length/2);for(let e=0,i=0;e<t.length;e+=2)r[i++]=parseInt(t.slice(e,e+2),16);return 1===this._sign?(128&r[0])!=0?r.unshift(128):r[0]|=128:(128&r[0])!=0&&r.unshift(0),"little"===e?r.reverse():r}static fromBits(e,t=!1){let r=e>>>24,i=8388607&e,a=(8388608&e)!=0;if(t&&a)throw Error("negative bit set");if(0===r&&0===i){if(a&&t)throw Error("negative bit set for zero value");return new p(0n)}let n=new p(i);return r<=3?n.iushrn((3-r)*8):n.iushln((r-3)*8),a&&n.ineg(),n}toBits(){let e;if(this.strip(),this.isZero()&&!this.isNeg())return 0;let t=this.isNeg(),r=this.abs(),i=r.toArray("be"),a=0;for(;a<i.length-1&&0===i[a];)a++;let n=(i=i.slice(a)).length;if(0!==n||r.isZero()||(i=[0],n=1),r.isZero()&&(n=0,i=[]),0===n)e=0;else if(n<=3){e=0;for(let t=0;t<n;t++)e=e<<8|i[t]}else e=i[0]<<16|i[1]<<8|i[2];(8388608&e)!=0&&n<=255&&(e>>>=8,n++);let s=n<<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,a=1n,n=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&a)!==0n&&(a+=s),a>>=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&n)!==0n&&(n+=s),n>>=1n}r>=i?(r-=i,a-=n):(i-=r,n-=a)}if(1n===r)t=a;else if(1n===i)t=n;else if(0n===r&&1n===i)t=n;else if(0n===i&&1n===r)t=a;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 b{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 g extends b{constructor(){super("k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}split(e,t){let r=e.words,i=e.length,a=Math.min(i,9),n=Array(a+ +(i>9)).fill(0);for(let e=0;e<a;e++)n[e]=r[e];let s=a;if(i<=9){let r=Array(s);for(let e=0;e<s;++e)r[e]=n[e];t.words=r,e.words=[0];return}let o=r[9];n[s++]=4194303&o;let c=Array(s);for(let e=0;e<s;++e)c[e]=n[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 d=Array(h);for(let e=0;e<h;++e)d[e]=l[e];e.words=d}imulK(e){let t=e.words,r=e.length,i=r+2,a=Array(i).fill(0);for(let e=0;e<r;e++)a[e]=t[e];let n=0;for(let e=0;e<i;e++){let t=0|a[e];n+=977*t,a[e]=0x3ffffff&n,n=64*t+(n/0x4000000|0)}return e.words=a,e}}class m{prime;m;constructor(e){if("k256"===e){let e=new g;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 a=new p(1).toRed(this),n=a.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(n);)c.redIAdd(n);let l=this.pow(c,r),h=this.pow(e,r.addn(1).iushrn(1)),d=this.pow(e,r),u=i;for(;0!==d.cmp(a);){let e=d,t=0;for(;0!==e.cmp(a);t++)e=e.redSqr();this.assert(t<u);let r=this.pow(l,new p(1).iushln(u-t-1));h=h.redMul(r),l=r.redSqr(),d=d.redMul(l),u=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 a=r[0],n=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(a!==r[0]&&(a=this.sqr(a)),0===o&&0===n){s=0;continue}n<<=1,n|=o,(4==++s||0===i&&0===t)&&(a=this.mul(a,r[n]),s=0,n=0)}o=26}return a}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 y extends m{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),a=r.isub(i).iushrn(this.shift),n=a;return a.cmp(this.m)>=0?n=a.isub(this.m):0>a.cmpn(0)&&(n=a.iadd(this.m)),n.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),a=r.isub(i).iushrn(this.shift),n=a;return a.cmp(this.m)>=0?n=a.isub(this.m):0>a.cmpn(0)&&(n=a.iadd(this.m)),n.forceRed(this)}invm(e){return this.imod(e._invmp(this.m).mul(this.r2)).forceRed(this)}}class w{curve;type;precomputed;constructor(e){this.curve=new td,this.type=e,this.precomputed=null}}class I extends w{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}toP(){if(this.isInfinity())return new th(null,null);let e=this.z.redInvm(),t=e.redSqr();return new th(this.x.redMul(t),this.y.redMul(t).redMul(e))}neg(){return new I(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),a=e.x.redMul(r),n=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),o=i.redSub(a),c=n.redSub(s);if(0===o.cmpn(0))if(0!==c.cmpn(0))return new I(null,null,null);else return this.dbl();let l=o.redSqr(),h=l.redMul(o),d=i.redMul(l),u=c.redSqr().redIAdd(h).redISub(d).redISub(d),f=c.redMul(d.redISub(u)).redISub(n.redMul(h));return new I(u,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),a=this.y,n=e.y.redMul(t).redMul(this.z),s=r.redSub(i),o=a.redSub(n);if(0===s.cmpn(0))if(0!==o.cmpn(0))return new I(null,null,null);else return this.dbl();let c=s.redSqr(),l=c.redMul(s),h=r.redMul(c),d=o.redSqr().redIAdd(l).redISub(h).redISub(h),u=o.redMul(h.redISub(d)).redISub(a.redMul(l));return new I(d,u,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(),a=this.y.redSqr(),n=a.redSqr(),s=this.x.redAdd(a).redSqr().redISub(i).redISub(n);s=s.redIAdd(s);let o=i.redAdd(i).redIAdd(i),c=o.redSqr().redISub(s).redISub(s),l=n.redIAdd(n);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(),a=this.y.redSqr(),n=a.redSqr(),s=this.x.redAdd(a).redSqr().redISub(i).redISub(n);s=s.redIAdd(s);let o=i.redAdd(i).redIAdd(i),c=o.redSqr(),l=n.redIAdd(n);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 I(e,t,r)}eq(e){if("affine"===e.type)return this.eq(e.toJ());if(this===e)return!0;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),a=r.redMul(e.z);return 0===this.y.redMul(a).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 a=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(a),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 v=(e,t="Hash assertion failed")=>{if(!e)throw Error(t)};class k{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=S(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 a=r-0;v(a%4==0);let n=Array(a/4);for(let r=0,a=t;r<n.length;r++,a+=4){let t;t="big"===i?e[a]<<24|e[a+1]<<16|e[a+2]<<8|e[a+3]:e[a+3]<<24|e[a+2]<<16|e[a+1]<<8|e[a],n[r]=t>>>0}return n}(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,r=this.pendingTotal,i=this._delta8,a=i-(r+this.padLength)%i,n=Array(a+this.padLength);for(e=1,n[0]=128;e<a;e++)n[e]=0;if(r<<=3,"big"===this.endian){for(t=8;t<this.padLength;t++)n[e++]=0;n[e++]=0,n[e++]=0,n[e++]=0,n[e++]=0,n[e++]=r>>>24&255,n[e++]=r>>>16&255,n[e++]=r>>>8&255,n[e++]=255&r}else for(t=8,n[e++]=255&r,n[e++]=r>>>8&255,n[e++]=r>>>16&255,n[e++]=r>>>24&255,n[e++]=0,n[e++]=0,n[e++]=0,n[e++]=0;t<this.padLength;t++)n[e++]=0;return n}}function S(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 n=0;n<e.length;n++){let s=e.charCodeAt(n);if(s<128)r[t++]=s;else if(s<2048)r[t++]=s>>6|192,r[t++]=63&s|128;else{var i,a;(i=e,a=n,(64512&i.charCodeAt(a))!=55296||a<0||a+1>=i.length?1:(64512&i.charCodeAt(a+1))!=56320)?r[t++]=s>>12|224:(s=65536+((1023&s)<<10)+(1023&e.charCodeAt(++n)),r[t++]=s>>18|240,r[t++]=s>>12&63|128),r[t++]=s>>6&63|128,r[t++]=63&s|128}}}else{(e=e.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(e="0"+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 x(e,t){let r="";for(let a=0;a<e.length;a++){var i;let n=e[a];"little"===t&&(n=((i=n)>>>24|i>>>8&65280|i<<8&0xff0000|(255&i)<<24)>>>0),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 E(e){let t="";for(let r of e)t+=r.toString(16).padStart(2,"0");return t}function N(e,t){let r=Array(4*e.length);for(let i=0,a=0;i<e.length;i++,a+=4){let n=e[i];"big"===t?(r[a]=n>>>24,r[a+1]=n>>>16&255,r[a+2]=n>>>8&255,r[a+3]=255&n):(r[a+3]=n>>>24,r[a+2]=n>>>16&255,r[a+1]=n>>>8&255,r[a]=255&n)}return r}function P(e,t){return e>>>t|e<<32-t}function O(e,t){return e<<t|e>>>32-t}function _(e,t){return e+t>>>0}let A=[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],T=[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],C=[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],R=[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 V(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 U extends k{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,a,n,s,o;let c,l=this.h[0],h=this.h[1],d=this.h[2],u=this.h[3],f=this.h[4],p=l,b=h,g=d,m=u,y=f;for(let w=0;w<80;w++){c=_(O((r=l,i=V(w,h,d,u),r+i+e[A[w]+t]+((s=w)<=15?0:s<=31?0x5a827999:s<=47?0x6ed9eba1:s<=63?0x8f1bbcdc:0xa953fd4e)>>>0),C[w]),f),l=f,f=u,u=O(d,10),d=h,h=c,c=_(O((a=p,n=V(79-w,b,g,m),a+n+e[T[w]+t]+((o=w)<=15?0x50a28be6:o<=31?0x5c4dd124:o<=47?0x6d703ef3:0x7a6d76e9*!!(o<=63))>>>0),R[w]),y),p=y,y=m,m=O(g,10),g=b,b=c}c=this.h[1]+d+m>>>0,this.h[1]=this.h[2]+u+y>>>0,this.h[2]=this.h[3]+f+p>>>0,this.h[3]=this.h[4]+l+b>>>0,this.h[4]=this.h[0]+h+g>>>0,this.h[0]=c}_digest(){return N(this.h,"little")}_digestHex(){return x(this.h,"little")}}class D{h;constructor(){this.h=new eN}update(e,t){let r=Uint8Array.from(S(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return E(this.h.digest())}}class B extends k{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]=O(i[r-3]^i[r-8]^i[r-14]^i[r-16],1);let a=this.h[0],n=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,d,u,f,p,b,g,m;let e=~~(r/20),t=(u=O(a,5),l=n,h=s,d=o,f=0===e?(p=l)&h^~p&d:1===e||3===e?l^h^d:2===e?(b=l)&(g=h)^b&(m=d)^g&m:0,u+f+c+i[r]+this.k[e]>>>0);c=o,o=s,s=O(n,30),n=a,a=t}this.h[0]=_(this.h[0],a),this.h[1]=_(this.h[1],n),this.h[2]=_(this.h[2],s),this.h[3]=_(this.h[3],o),this.h[4]=_(this.h[4],c)}_digest(){return N(this.h,"big")}_digestHex(){return x(this.h,"big")}}class H{h;constructor(){this.h=new eV}update(e,t){let r=Uint8Array.from(S(e,t));return this.h.update(r),this}digest(){return Array.from(this.h.digest())}digestHex(){return E(this.h.digest())}}class L{h;blockSize=64;outSize=32;constructor(e){let t=Uint8Array.from(S(e,"hex"));this.h=new eD(eP,t)}update(e,t){return this.h.update(Uint8Array.from(S(e,t))),this}digest(){return Array.from(this.h.digest())}digestHex(){return E(this.h.digest())}}class K{inner;outer;blockSize=64;constructor(e){let t;for((e=S(e,"hex")).length>this.blockSize&&(e=new B().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 B().update(e);t<e.length;t++)e[t]^=106;this.outer=new B().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 F{h;blockSize=128;outSize=32;constructor(e){let t=Uint8Array.from(S(e,"hex"));this.h=new eD(eU,t)}update(e,t){return this.h.update(Uint8Array.from(S(e,t))),this}digest(){return Array.from(this.h.digest())}digestHex(){return E(this.h.digest())}}let q=(e,t)=>new U().update(e,t).digest(),M=(e,t)=>new B().update(e,t).digest(),$=(e,t)=>new D().update(e,t).digest(),z=(e,t)=>new H().update(e,t).digest(),W=(e,t)=>{let r=new D().update(e,t).digest();return new D().update(r).digest()},j=(e,t)=>{let r=new D().update(e,t).digest();return new U().update(r).digest()},G=(e,t,r)=>new L(e).update(t,r).digest(),X=(e,t,r)=>new F(e).update(t,r).digest();function Y(e){if(!Number.isSafeInteger(e)||e<0)throw Error(`positive integer expected, got ${e}`)}function J(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 Z(e){if("function"!=typeof e||"function"!=typeof e.create)throw Error("Hash should be wrapped by utils.createHasher");Y(e.outputLen),Y(e.blockLen)}function Q(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 ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function et(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function er(e){return"string"==typeof e&&(e=ei(e)),J(e),e}function ei(e){if("string"!=typeof e)throw Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function ea(e){return"string"==typeof e&&(e=ei(e)),J(e),e}class en{}function es(e){let t=t=>e().update(er(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}let eo=BigInt(0x100000000-1),ec=BigInt(32),el=(e,t,r)=>e>>>r,eh=(e,t,r)=>e<<32-r|t>>>r,ed=(e,t,r)=>e>>>r|t<<32-r,eu=(e,t,r)=>e<<32-r|t>>>r,ef=(e,t,r)=>e<<64-r|t>>>r-32,ep=(e,t,r)=>e>>>r-32|t<<64-r;function eb(e,t,r,i){let a=(t>>>0)+(i>>>0);return{h:e+r+(a/0x100000000|0)|0,l:0|a}}let eg=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),em=(e,t,r,i)=>t+r+i+(e/0x100000000|0)|0,ey=(e,t,r,i)=>(e>>>0)+(t>>>0)+(r>>>0)+(i>>>0),ew=(e,t,r,i,a)=>t+r+i+a+(e/0x100000000|0)|0,eI=(e,t,r,i,a)=>(e>>>0)+(t>>>0)+(r>>>0)+(i>>>0)+(a>>>0),ev=(e,t,r,i,a,n)=>t+r+i+a+n+(e/0x100000000|0)|0;class ek extends en{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=et(this.buffer)}update(e){Q(this),J(e=er(e));let{view:t,buffer:r,blockLen:i}=this,a=e.length;for(let n=0;n<a;){let s=Math.min(i-this.pos,a-n);if(s===i){let t=et(e);for(;i<=a-n;n+=i)this.process(t,n);continue}r.set(e.subarray(n,n+s),this.pos),this.pos+=s,n+=s,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Q(this);J(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:a,isLE:n}=this,{pos:s}=this;r[s++]=128,ee(this.buffer.subarray(s)),this.padOffset>a-s&&(this.process(i,0),s=0);for(let e=s;e<a;e++)r[e]=0;(function(e,t,r,i){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,i);let a=BigInt(32),n=BigInt(0xffffffff),s=Number(r>>a&n),o=Number(r&n),c=4*!!i,l=4*!i;e.setUint32(t+c,s,i),e.setUint32(t+l,o,i)})(i,a-8,BigInt(8*this.length),n),this.process(i,0);let o=et(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],n)}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:a,destroyed:n,pos:s}=this;return e.destroyed=n,e.finished=a,e.length=i,e.pos=s,i%t!=0&&e.buffer.set(r),e}clone(){return this._cloneInto()}}let eS=Uint32Array.from([0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19]),ex=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]),eE=new Uint32Array(64);class eN extends ek{A=0|eS[0];B=0|eS[1];C=0|eS[2];D=0|eS[3];E=0|eS[4];F=0|eS[5];G=0|eS[6];H=0|eS[7];constructor(e=32){super(64,e,8,!1)}get(){let{A:e,B:t,C:r,D:i,E:a,F:n,G:s,H:o}=this;return[e,t,r,i,a,n,s,o]}set(e,t,r,i,a,n,s,o){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|i,this.E=0|a,this.F=0|n,this.G=0|s,this.H=0|o}process(e,t){var r,i,a,n,s,o,c,l,h;for(let r=0;r<16;r++,t+=4)eE[r]=e.getUint32(t);for(let e=16;e<64;e++){let t=eE[e-15],r=eE[e-2],i=P(t,7)^P(t,18)^t>>>3,a=P(r,17)^P(r,19)^r>>>10;eE[e]=_(_(i,eE[e-7]),_(a,eE[e-16]))}let{A:d,B:u,C:f,D:p,E:b,F:g,G:m,H:y}=this;for(let e=0;e<64;e++){let t=(a=y,n=P(r=b,6)^P(r,11)^P(r,25),s=(i=b)&g^~i&m,a+n+s+ex[e]+eE[e]>>>0),w=_(P(o=d,2)^P(o,13)^P(o,22),(c=d)&(l=u)^c&(h=f)^l&h);y=m,m=g,g=b,b=_(p,t),p=f,f=u,u=d,d=_(t,w)}this.A=_(this.A,d),this.B=_(this.B,u),this.C=_(this.C,f),this.D=_(this.D,p),this.E=_(this.E,b),this.F=_(this.F,g),this.G=_(this.G,m),this.H=_(this.H,y)}roundClean(){ee(eE)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0)}}let eP=es(()=>new eN),eO=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),a=new Uint32Array(r);for(let n=0;n<r;n++){let{h:r,l:s}=function(e,t=!1){return t?{h:Number(e&eo),l:Number(e>>ec&eo)}:{h:0|Number(e>>ec&eo),l:0|Number(e&eo)}}(e[n],t);i[n]=r,a[n]=s}return[i,a]}(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),eA=e_[0],eT=e_[1],eC=new Uint32Array(80),eR=new Uint32Array(80);class eV extends ek{Ah=0|eO[0];Al=0|eO[1];Bh=0|eO[2];Bl=0|eO[3];Ch=0|eO[4];Cl=0|eO[5];Dh=0|eO[6];Dl=0|eO[7];Eh=0|eO[8];El=0|eO[9];Fh=0|eO[10];Fl=0|eO[11];Gh=0|eO[12];Gl=0|eO[13];Hh=0|eO[14];Hl=0|eO[15];constructor(e=64){super(128,e,16,!1)}get(){let{Ah:e,Al:t,Bh:r,Bl:i,Ch:a,Cl:n,Dh:s,Dl:o,Eh:c,El:l,Fh:h,Fl:d,Gh:u,Gl:f,Hh:p,Hl:b}=this;return[e,t,r,i,a,n,s,o,c,l,h,d,u,f,p,b]}set(e,t,r,i,a,n,s,o,c,l,h,d,u,f,p,b){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|i,this.Ch=0|a,this.Cl=0|n,this.Dh=0|s,this.Dl=0|o,this.Eh=0|c,this.El=0|l,this.Fh=0|h,this.Fl=0|d,this.Gh=0|u,this.Gl=0|f,this.Hh=0|p,this.Hl=0|b}process(e,t){for(let r=0;r<16;r++,t+=4)eC[r]=e.getUint32(t),eR[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=0|eC[e-15],r=0|eR[e-15],i=ed(t,r,1)^ed(t,r,8)^el(t,r,7),a=eu(t,r,1)^eu(t,r,8)^eh(t,r,7),n=0|eC[e-2],s=0|eR[e-2],o=ed(n,s,19)^ef(n