@libp2p/crypto
Version:
Crypto primitives for libp2p
2 lines • 108 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PCrypto = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PCrypto=(()=>{var tn=Object.defineProperty;var zi=Object.getOwnPropertyDescriptor;var Fi=Object.getOwnPropertyNames;var ji=Object.prototype.hasOwnProperty;var et=(e,t)=>{for(var r in t)tn(e,r,{get:t[r],enumerable:!0})},Gi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Fi(t))!ji.call(e,o)&&o!==r&&tn(e,o,{get:()=>t[o],enumerable:!(n=zi(t,o))||n.enumerable});return e};var Zi=e=>Gi(tn({},"__esModule",{value:!0}),e);var Of={};et(Of,{hmac:()=>mr,keys:()=>Ao,pbkdf2:()=>So,randomBytes:()=>ao});var mr={};et(mr,{create:()=>en});var He=class extends Error{constructor(t="An error occurred while signing a message"){super(t),this.name="SigningError"}},Oe=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Bo={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new pr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var F=Bo;var vo={SHA1:20,SHA256:32,SHA512:64};var $i={SHA1:"SHA-1",SHA256:"SHA-256",SHA512:"SHA-512"},Yi=async(e,t)=>{let r=await F.get().subtle.sign({name:"HMAC"},e,t);return new Uint8Array(r,0,r.byteLength)};async function en(e,t){let r=$i[e],n=await F.get().subtle.importKey("raw",t,{name:"HMAC",hash:{name:r}},!1,["sign"]);return{async digest(o){return Yi(n,o)},length:vo[e]}}var Ao={};et(Ao,{generateEphemeralKeyPair:()=>Ri,generateKeyPair:()=>vf,generateKeyPairFromSeed:()=>If,keyStretcher:()=>ki,privateKeyFromCryptoKeyPair:()=>Nf,privateKeyFromProtobuf:()=>Tf,privateKeyFromRaw:()=>Uf,privateKeyToCryptoKeyPair:()=>Rf,privateKeyToProtobuf:()=>Cf,publicKeyFromMultihash:()=>Lf,publicKeyFromProtobuf:()=>_f,publicKeyFromRaw:()=>Kf,publicKeyToProtobuf:()=>Wt});var N=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},he=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}},Me=class extends Error{static name="InvalidPrivateKeyError";constructor(t="Invalid private key"){super(t),this.name="InvalidPrivateKeyError"}};var Nt=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var an={};et(an,{base58btc:()=>W,base58flickr:()=>ra});var Wf=new Uint8Array(0);function Io(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function _o(e){return new TextEncoder().encode(e)}function Ko(e){return new TextDecoder().decode(e)}function Wi(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var E=0,y=0,S=0,I=g.length;S!==I&&g[S]===0;)S++,E++;for(var B=(I-S)*f+1>>>0,C=new Uint8Array(B);S!==I;){for(var p=g[S],U=0,T=B-1;(p!==0||U<y)&&T!==-1;T--,U++)p+=256*C[T]>>>0,C[T]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");y=U,S++}for(var _=B-y;_!==B&&C[_]===0;)_++;for(var l=c.repeat(E);_<B;++_)l+=e.charAt(C[_]);return l}function m(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var E=0;if(g[E]!==" "){for(var y=0,S=0;g[E]===c;)y++,E++;for(var I=(g.length-E)*h+1>>>0,B=new Uint8Array(I);g[E];){var C=r[g.charCodeAt(E)];if(C===255)return;for(var p=0,U=I-1;(C!==0||p<S)&&U!==-1;U--,p++)C+=a*B[U]>>>0,B[U]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");S=p,E++}if(g[E]!==" "){for(var T=I-S;T!==I&&B[T]===0;)T++;for(var _=new Uint8Array(y+(I-T)),l=y;T!==I;)_[l++]=B[T++];return _}}}function b(g){var E=m(g);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:m,decode:b}}var Xi=Wi,Ji=Xi,To=Ji;var rn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},nn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Uo(this,t)}},on=class{decoders;constructor(t){this.decoders=t}or(t){return Uo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Uo(e,t){return new on({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var sn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new rn(t,r,n),this.decoder=new nn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function le({name:e,prefix:t,encode:r,decode:n}){return new sn(e,t,r,n)}function kt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=To(r,e);return le({prefix:t,name:e,encode:n,decode:s=>Kt(o(s))})}function Qi(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let h=0;h<o;++h){let f=t[e[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ta(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ea(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function G({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ea(n);return le({prefix:t,name:e,encode(s){return ta(s,n,r)},decode(s){return Qi(s,o,r,e)}})}var W=kt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ra=kt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var cn={};et(cn,{base32:()=>de,base32hex:()=>ia,base32hexpad:()=>ca,base32hexpadupper:()=>fa,base32hexupper:()=>aa,base32pad:()=>oa,base32padupper:()=>sa,base32upper:()=>na,base32z:()=>ua});var de=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),na=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oa=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sa=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ia=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),aa=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ca=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),fa=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ua=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fn={};et(fn,{base36:()=>qe,base36upper:()=>ha});var qe=kt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ha=kt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var la=Po,Co=128,da=127,pa=~da,ma=Math.pow(2,31);function Po(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ma;)t[r++]=e&255|Co,e/=128;for(;e&pa;)t[r++]=e&255|Co,e>>>=7;return t[r]=e|0,Po.bytes=r-n+1,t}var ya=un,ba=128,Do=127;function un(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw un.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Do)<<o:(i&Do)*Math.pow(2,o),o+=7}while(i>=ba);return un.bytes=s-n,r}var xa=Math.pow(2,7),wa=Math.pow(2,14),ga=Math.pow(2,21),Ea=Math.pow(2,28),Aa=Math.pow(2,35),Sa=Math.pow(2,42),Ba=Math.pow(2,49),va=Math.pow(2,56),Ia=Math.pow(2,63),_a=function(e){return e<xa?1:e<wa?2:e<ga?3:e<Ea?4:e<Aa?5:e<Sa?6:e<Ba?7:e<va?8:e<Ia?9:10},Ka={encode:la,decode:ya,encodingLength:_a},La=Ka,Ve=La;function ze(e,t=0){return[Ve.decode(e,t),Ve.decode.bytes]}function pe(e,t,r=0){return Ve.encode(e,t,r),t}function me(e){return Ve.encodingLength(e)}function bt(e,t){let r=t.byteLength,n=me(e),o=n+me(r),s=new Uint8Array(o+r);return pe(e,s,0),pe(r,s,n),s.set(t,o),new ye(e,r,t,s)}function Ro(e){let t=Kt(e),[r,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ye(r,o,i,t)}function No(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Io(e.bytes,r.bytes)}}var ye=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ko(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Ua(r,hn(e),t??W.encoder);default:return Ca(r,hn(e),t??de.encoder)}}var Ho=new WeakMap;function hn(e){let t=Ho.get(e);if(t==null){let r=new Map;return Ho.set(e,r),r}return t}var yt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==je)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Da)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=bt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&No(t.multihash,n.multihash)}toString(t){return ko(this,t)}toJSON(){return{"/":ko(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Oo(n,o,s.bytes))}else if(r[Pa]===!0){let{version:n,multihash:o,code:s}=r,i=Ro(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==je)throw new Error(`Version 0 CID must use dag-pb (code: ${je}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Oo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,je,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Kt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new ye(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,m]=ze(t.subarray(r));return r+=m,u},o=n(),s=je;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),h=r+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,o]=Ta(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return hn(s).set(n,t),s}};function Ta(e,t){switch(e[0]){case"Q":{let r=t??W;return[W.prefix,r.decode(`${W.prefix}${e}`)]}case W.prefix:{let r=t??W;return[W.prefix,r.decode(e)]}case de.prefix:{let r=t??de;return[de.prefix,r.decode(e)]}case qe.prefix:{let r=t??qe;return[qe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Ua(e,t,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ca(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var je=112,Da=18;function Oo(e,t,r){let n=me(e),o=n+me(t),s=new Uint8Array(o+r.byteLength);return pe(e,s,0),pe(t,s,n),s.set(r,o),s}var Pa=Symbol.for("@ipld/js-cid/CID");var ln={};et(ln,{identity:()=>$t});var Mo=0,Ra="identity",qo=Kt;function Na(e){return bt(Mo,qo(e))}var $t={code:Mo,name:Ra,encode:qo,digest:Na};function rt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Lt(e=0){return new Uint8Array(e)}function ht(e=0){return new Uint8Array(e)}function St(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ht(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var zo=Symbol.for("@achingbrain/uint8arraylist");function Vo(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function br(e){return!!e?.[zo]}var st=class e{bufs;length;[zo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(br(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(br(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Vo(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Vo(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(br(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return St(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:St(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!br(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let m=h;m>=0;m--){let b=this.get(u+m);if(n[m]!==b){f=Math.max(1,m-a[b]);break}}if(f===0)return u}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Lt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Lt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Lt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!rt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var dn={};et(dn,{base10:()=>ka});var ka=kt({prefix:"9",name:"base10",alphabet:"0123456789"});var pn={};et(pn,{base16:()=>Ha,base16upper:()=>Oa});var Ha=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Oa=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mn={};et(mn,{base2:()=>Ma});var Ma=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yn={};et(yn,{base256emoji:()=>ja});var Fo=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),qa=Fo.reduce((e,t,r)=>(e[r]=t,e),[]),Va=Fo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function za(e){return e.reduce((t,r)=>(t+=qa[r],t),"")}function Fa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Va[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ja=le({prefix:"\u{1F680}",name:"base256emoji",encode:za,decode:Fa});var xn={};et(xn,{base64:()=>bn,base64pad:()=>Ga,base64url:()=>Za,base64urlpad:()=>$a});var bn=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ga=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Za=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$a=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wn={};et(wn,{base8:()=>Ya});var Ya=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gn={};et(gn,{identity:()=>Wa});var Wa=le({prefix:"\0",name:"identity",encode:e=>Ko(e),decode:e=>_o(e)});var Du=new TextEncoder,Pu=new TextDecoder;var Sn={};et(Sn,{sha256:()=>xr,sha512:()=>Qa});function An({name:e,code:t,encode:r}){return new En(e,t,r)}var En=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?bt(this.code,r):r.then(n=>bt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Go(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var xr=An({name:"sha2-256",code:18,encode:Go("SHA-256")}),Qa=An({name:"sha2-512",code:19,encode:Go("SHA-512")});var Bn={...gn,...mn,...wn,...dn,...pn,...cn,...fn,...an,...xn,...yn},Gu={...Sn,...ln};function $o(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Zo=$o("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),vn=$o("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ht(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),tc={utf8:Zo,"utf-8":Zo,hex:Bn.base16,latin1:vn,ascii:vn,binary:vn,...Bn},wr=tc;function q(e,t="utf8"){let r=wr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function k(e,t="utf8"){let r=wr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var ec=parseInt("11111",2),In=parseInt("10000000",2),rc=parseInt("01111111",2),Yo={0:Ge,1:Ge,2:nc,3:ic,4:ac,5:sc,6:oc,16:Ge,22:Ge,48:Ge};function lt(e,t={offset:0}){let r=e[t.offset]&ec;if(t.offset++,Yo[r]!=null)return Yo[r](e,t);throw new Error("No decoder for tag "+r)}function Ze(e,t){let r=0;if((e[t.offset]&In)===In){let n=e[t.offset]&rc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ge(e,t){Ze(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=lt(e,t);if(n===null)break;r.push(n)}return r}function nc(e,t){let r=Ze(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function oc(e,t){let r=Ze(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function sc(e,t){return t.offset++,null}function ic(e,t){let r=Ze(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ac(e,t){let r=Ze(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function cc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new st;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function gr(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=cc(e.byteLength);return new st(Uint8Array.from([t.byteLength|In]),t)}function it(e){let t=new st,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new st(Uint8Array.from([2]),gr(t),t)}function $e(e){let t=Uint8Array.from([0]),r=new st(t,e);return new st(Uint8Array.from([3]),gr(r),r)}function Wo(e){return new st(Uint8Array.from([4]),gr(e),e)}function xt(e,t=48){let r=new st;for(let n of e)r.append(n);return new st(Uint8Array.from([t]),gr(r),r)}var _n="1.2.840.10045.3.1.7",Kn="1.3.132.0.34",Ln="1.3.132.0.35";async function Xo(e="P-256"){let t=await crypto.subtle.generateKey({name:"ECDSA",namedCurve:e},!0,["sign","verify"]);return{publicKey:await crypto.subtle.exportKey("jwk",t.publicKey),privateKey:await crypto.subtle.exportKey("jwk",t.privateKey)}}async function Jo(e,t,r){let n=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["sign"]);r?.signal?.throwIfAborted();let o=await crypto.subtle.sign({name:"ECDSA",hash:{name:"SHA-256"}},n,t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Qo(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var fc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),uc=Uint8Array.from([6,5,43,129,4,0,34]),hc=Uint8Array.from([6,5,43,129,4,0,35]),ts={ext:!0,kty:"EC",crv:"P-256"},es={ext:!0,kty:"EC",crv:"P-384"},rs={ext:!0,kty:"EC",crv:"P-521"},be=32,xe=48,we=66;function ns(e){let t=lt(e);return Tn(t)}function Tn(e){let t=e[1],r=k(t,"base64url"),n=e[2][1][0],o=1,s,i;if(t.byteLength===be)return s=k(n.subarray(o,o+be),"base64url"),i=k(n.subarray(o+be),"base64url"),new Tt({...ts,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===xe)return s=k(n.subarray(o,o+xe),"base64url"),i=k(n.subarray(o+xe),"base64url"),new Tt({...es,key_ops:["sign"],d:r,x:s,y:i});if(t.byteLength===we)return s=k(n.subarray(o,o+we),"base64url"),i=k(n.subarray(o+we),"base64url"),new Tt({...rs,key_ops:["sign"],d:r,x:s,y:i});throw new N(`Private key length was wrong length, got ${t.byteLength}, expected 32, 48 or 66`)}function Un(e){let t=lt(e);return Cn(t)}function Cn(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===be*2+1)return n=k(t.subarray(r,r+be),"base64url"),o=k(t.subarray(r+be),"base64url"),new Yt({...ts,key_ops:["verify"],x:n,y:o});if(t.byteLength===xe*2+1)return n=k(t.subarray(r,r+xe),"base64url"),o=k(t.subarray(r+xe),"base64url"),new Yt({...es,key_ops:["verify"],x:n,y:o});if(t.byteLength===we*2+1)return n=k(t.subarray(r,r+we),"base64url"),o=k(t.subarray(r+we),"base64url"),new Yt({...rs,key_ops:["verify"],x:n,y:o});throw new N(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function os(e){return xt([it(Uint8Array.from([1])),Wo(q(e.d??"","base64url")),xt([is(e.crv)],160),xt([$e(new st(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function ss(e){return xt([it(Uint8Array.from([1])),xt([is(e.crv)],160),xt([$e(new st(Uint8Array.from([4]),q(e.x??"","base64url"),q(e.y??"","base64url")))],161)]).subarray()}function is(e){if(e==="P-256")return fc;if(e==="P-384")return uc;if(e==="P-521")return hc;throw new N(`Invalid curve ${e}`)}async function as(e="P-256"){let t=await Xo(e);return new Tt(t.privateKey)}var Yt=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=ss(this.jwk)),this._raw}toMultihash(){return $t.digest(Wt(this))}toCID(){return yt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async verify(t,r,n){return Qo(this.jwk,r,t,n)}},Tt=class{type="ECDSA";jwk;publicKey;_raw;constructor(t){this.jwk=t,this.publicKey=new Yt({crv:t.crv,ext:t.ext,key_ops:["verify"],kty:"EC",x:t.x,y:t.y})}get raw(){return this._raw==null&&(this._raw=os(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:rt(this.raw,t.raw)}async sign(t,r){return Jo(this.jwk,t,r)}};var Xt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ee(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ct(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function J(e,...t){if(!Ee(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Er(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ct(e.outputLen),Ct(e.blockLen)}function Ae(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function fs(e,t){J(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function ut(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Se(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function Ar(e,t){return e<<t|e>>>32-t>>>0}var us=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",lc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Bt(e){if(J(e),us)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=lc[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function cs(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function Be(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(us)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=cs(e.charCodeAt(s)),a=cs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Dn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Ye(e){return typeof e=="string"&&(e=Dn(e)),J(e),e}function Pn(e){return typeof e=="string"&&(e=Dn(e)),J(e),e}function dt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];J(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function hs(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var ge=class{};function We(e){let t=n=>e().update(Ye(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function Jt(e=32){if(Xt&&typeof Xt.getRandomValues=="function")return Xt.getRandomValues(new Uint8Array(e));if(Xt&&typeof Xt.randomBytes=="function")return Uint8Array.from(Xt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function dc(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,h=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+h,a,n)}function Sr(e,t,r){return e&t^~e&r}function Br(e,t,r){return e&t^e&r^t&r}var Qt=class extends ge{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Se(this.buffer)}update(t){Ae(this),t=Ye(t),J(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Se(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ae(this),fs(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ut(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)r[u]=0;dc(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Se(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,f[u],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Dt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var vr=BigInt(4294967295),ls=BigInt(32);function pc(e,t=!1){return t?{h:Number(e&vr),l:Number(e>>ls&vr)}:{h:Number(e>>ls&vr)|0,l:Number(e&vr)|0}}function ds(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=pc(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Rn=(e,t,r)=>e>>>r,Nn=(e,t,r)=>e<<32-r|t>>>r,te=(e,t,r)=>e>>>r|t<<32-r,ee=(e,t,r)=>e<<32-r|t>>>r,Xe=(e,t,r)=>e<<64-r|t>>>r-32,Je=(e,t,r)=>e>>>r-32|t<<64-r;function vt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ps=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ms=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ys=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),bs=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,xs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ws=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var yc=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ht=new Uint32Array(64),Ir=class extends Qt{constructor(t=32){super(64,t,8,!1),this.A=Dt[0]|0,this.B=Dt[1]|0,this.C=Dt[2]|0,this.D=Dt[3]|0,this.E=Dt[4]|0,this.F=Dt[5]|0,this.G=Dt[6]|0,this.H=Dt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)Ht[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let m=Ht[u-15],b=Ht[u-2],g=wt(m,7)^wt(m,18)^m>>>3,E=wt(b,17)^wt(b,19)^b>>>10;Ht[u]=E+Ht[u-7]+g+Ht[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:h,H:f}=this;for(let u=0;u<64;u++){let m=wt(a,6)^wt(a,11)^wt(a,25),b=f+m+Sr(a,c,h)+yc[u]+Ht[u]|0,E=(wt(n,2)^wt(n,13)^wt(n,22))+Br(n,o,s)|0;f=h,h=c,c=a,a=i+b|0,i=s,s=o,o=n,n=b+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,h,f)}roundClean(){ut(Ht)}destroy(){this.set(0,0,0,0,0,0,0,0),ut(this.buffer)}};var gs=ds(["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))),bc=gs[0],xc=gs[1],Ot=new Uint32Array(80),Mt=new Uint32Array(80),_r=class extends Qt{constructor(t=64){super(128,t,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:u,Fl:m,Gh:b,Gl:g,Hh:E,Hl:y}=this;return[t,r,n,o,s,i,a,c,h,f,u,m,b,g,E,y]}set(t,r,n,o,s,i,a,c,h,f,u,m,b,g,E,y){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=u|0,this.Fl=m|0,this.Gh=b|0,this.Gl=g|0,this.Hh=E|0,this.Hl=y|0}process(t,r){for(let B=0;B<16;B++,r+=4)Ot[B]=t.getUint32(r),Mt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let C=Ot[B-15]|0,p=Mt[B-15]|0,U=te(C,p,1)^te(C,p,8)^Rn(C,p,7),T=ee(C,p,1)^ee(C,p,8)^Nn(C,p,7),_=Ot[B-2]|0,l=Mt[B-2]|0,w=te(_,l,19)^Xe(_,l,61)^Rn(_,l,6),d=ee(_,l,19)^Je(_,l,61)^Nn(_,l,6),x=ys(T,d,Mt[B-7],Mt[B-16]),A=bs(x,U,w,Ot[B-7],Ot[B-16]);Ot[B]=A|0,Mt[B]=x|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:u,El:m,Fh:b,Fl:g,Gh:E,Gl:y,Hh:S,Hl:I}=this;for(let B=0;B<80;B++){let C=te(u,m,14)^te(u,m,18)^Xe(u,m,41),p=ee(u,m,14)^ee(u,m,18)^Je(u,m,41),U=u&b^~u&E,T=m&g^~m&y,_=xs(I,p,T,xc[B],Mt[B]),l=ws(_,S,C,U,bc[B],Ot[B]),w=_|0,d=te(n,o,28)^Xe(n,o,34)^Xe(n,o,39),x=ee(n,o,28)^Je(n,o,34)^Je(n,o,39),A=n&s^n&a^s&a,K=o&i^o&c^i&c;S=E|0,I=y|0,E=b|0,y=g|0,b=u|0,g=m|0,{h:u,l:m}=vt(h|0,f|0,l|0,w|0),h=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=ps(w,x,K);n=ms(v,l,d,A),o=v|0}({h:n,l:o}=vt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=vt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=vt(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=vt(this.Dh|0,this.Dl|0,h|0,f|0),{h:u,l:m}=vt(this.Eh|0,this.El|0,u|0,m|0),{h:b,l:g}=vt(this.Fh|0,this.Fl|0,b|0,g|0),{h:E,l:y}=vt(this.Gh|0,this.Gl|0,E|0,y|0),{h:S,l:I}=vt(this.Hh|0,this.Hl|0,S|0,I|0),this.set(n,o,s,i,a,c,h,f,u,m,b,g,E,y,S,I)}roundClean(){ut(Ot,Mt)}destroy(){ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Kr=We(()=>new Ir);var Lr=We(()=>new _r);var On=BigInt(0),Hn=BigInt(1);function Pt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function Qe(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Es(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?On:BigInt("0x"+e)}function ve(e){return Es(Bt(e))}function re(e){return J(e),Es(Bt(Uint8Array.from(e).reverse()))}function Tr(e,t){return Be(e.toString(16).padStart(t*2,"0"))}function Ie(e,t){return Tr(e,t).reverse()}function V(e,t,r){let n;if(typeof t=="string")try{n=Be(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Ee(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var kn=e=>typeof e=="bigint"&&On<=e;function As(e,t,r){return kn(e)&&kn(t)&&kn(r)&&t<=e&&e<r}function qt(e,t,r,n){if(!As(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ss(e){let t;for(t=0;e>On;e>>=Hn,t+=1);return t}var ne=e=>(Hn<<BigInt(e))-Hn;function Bs(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},h=(...b)=>r(i,s,...b),f=(b=n(0))=>{i=h(o(0),b),s=h(),b.length!==0&&(i=h(o(1),b),s=h())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,g=[];for(;b<t;){s=h();let E=s.slice();g.push(E),b+=s.length}return dt(...g)};return(b,g)=>{c(),f(b);let E;for(;!(E=g(u()));)f();return c(),E}}function Vt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function _e(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var at=BigInt(0),X=BigInt(1),oe=BigInt(2),wc=BigInt(3),_s=BigInt(4),Ks=BigInt(5),Ls=BigInt(8);function j(e,t){let r=e%t;return r>=at?r:t+r}function z(e,t,r){let n=e;for(;t-- >at;)n*=n,n%=r;return n}function vs(e,t){if(e===at)throw new Error("invert: expected non-zero number");if(t<=at)throw new Error("invert: expected positive modulus, got "+t);let r=j(e,t),n=t,o=at,s=X,i=X,a=at;for(;r!==at;){let h=n/r,f=n%r,u=o-i*h,m=s-a*h;n=r,r=f,o=i,s=a,i=u,a=m}if(n!==X)throw new Error("invert: does not exist");return j(o,t)}function Ts(e,t){let r=(e.ORDER+X)/_s,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function gc(e,t){let r=(e.ORDER-Ks)/Ls,n=e.mul(t,oe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,oe),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Ec(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%oe===at;)t/=oe,r++;let n=oe,o=gt(e);for(;Is(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ts;let s=o.pow(n,t),i=(t+X)/oe;return function(c,h){if(c.is0(h))return h;if(Is(c,h)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,s),m=c.pow(h,t),b=c.pow(h,i);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let g=1,E=c.sqr(m);for(;!c.eql(E,c.ONE);)if(g++,E=c.sqr(E),g===f)throw new Error("Cannot find square root");let y=X<<BigInt(f-g-1),S=c.pow(u,y);f=g,u=c.sqr(S),m=c.mul(m,u),b=c.mul(b,S)}return b}}function Ac(e){return e%_s===wc?Ts:e%Ls===Ks?gc:Ec(e)}var Us=(e,t)=>(j(e,t)&X)===X,Sc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Mn(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Sc.reduce((n,o)=>(n[o]="function",n),t);return Vt(e,r),e}function Bc(e,t,r){if(r<at)throw new Error("invalid exponent, negatives unsupported");if(r===at)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>at;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function tr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Is(e,t){let r=(e.ORDER-X)/oe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Cs(e,t){t!==void 0&&Ct(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function gt(e,t,r=!1,n={}){if(e<=at)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Cs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,h=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:ne(i),ZERO:at,ONE:X,create:f=>j(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return at<=f&&f<e},is0:f=>f===at,isValidNot0:f=>!h.is0(f)&&h.isValid(f),isOdd:f=>(f&X)===X,neg:f=>j(-f,e),eql:(f,u)=>f===u,sqr:f=>j(f*f,e),add:(f,u)=>j(f+u,e),sub:(f,u)=>j(f-u,e),mul:(f,u)=>j(f*u,e),pow:(f,u)=>Bc(h,f,u),div:(f,u)=>j(f*vs(u,e),e),sqrN:f=>f*f,addN:(f,u)=>f+u,subN:(f,u)=>f-u,mulN:(f,u)=>f*u,inv:f=>vs(f,e),sqrt:s||(f=>(c||(c=Ac(e)),c(h,f))),toBytes:f=>r?Ie(f,a):Tr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?re(f):ve(f)},invertBatch:f=>tr(h,f),cmov:(f,u,m)=>m?u:f});return Object.freeze(h)}function Ds(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function qn(e){let t=Ds(e);return t+Math.ceil(t/2)}function Ps(e,t,r=!1){let n=e.length,o=Ds(t),s=qn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?re(e):ve(e),a=j(i,t-X)+X;return r?Ie(a,o):Tr(a,o)}var Le=BigInt(0),se=BigInt(1);function Ke(e,t){let r=t.negate();return e?r:t}function Ur(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=tr(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function Hs(e,t){if(!Number.isSafeInteger(e)||