did-jwt
Version:
Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients
2 lines โข 128 kB
JavaScript
/*! For license information please see did-jwt.js.LICENSE.txt */
var e={84:e=>{e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var o=e.charAt(n),i=o.charCodeAt(0);if(255!==t[i])throw new TypeError(o+" is ambiguous");t[i]=n}var s=e.length,f=e.charAt(0),c=Math.log(s)/Math.log(256),a=Math.log(256)/Math.log(s);function u(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var r=0;if(" "!==e[r]){for(var n=0,o=0;e[r]===f;)n++,r++;for(var i=(e.length-r)*c+1>>>0,a=new Uint8Array(i);e[r];){var u=t[e.charCodeAt(r)];if(255===u)return;for(var h=0,d=i-1;(0!==u||h<o)&&-1!==d;d--,h++)u+=s*a[d]>>>0,a[d]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");o=h,r++}if(" "!==e[r]){for(var l=i-o;l!==i&&0===a[l];)l++;for(var p=new Uint8Array(n+(i-l)),y=n;l!==i;)p[y++]=a[l++];return p}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var c=(i-o)*a+1>>>0,u=new Uint8Array(c);o!==i;){for(var h=t[o],d=0,l=c-1;(0!==h||d<n)&&-1!==l;l--,d++)h+=256*u[l]>>>0,u[l]=h%s>>>0,h=h/s>>>0;if(0!==h)throw new Error("Non-zero carry");n=d,o++}for(var p=c-n;p!==c&&0===u[p];)p++;for(var y=f.repeat(r);p<c;++p)y+=e.charAt(u[p]);return y},decodeUnsafe:u,decode:function(e){var t=u(e);if(t)return t;throw new Error("Non-base"+s+" character")}}}},341:e=>{e.exports=function e(t){if("number"==typeof t&&isNaN(t))throw new Error("NaN is not allowed");if("number"==typeof t&&!isFinite(t))throw new Error("Infinity is not allowed");return null===t||"object"!=typeof t?JSON.stringify(t):t.toJSON instanceof Function?e(t.toJSON()):Array.isArray(t)?`[${t.reduce(((t,r,n)=>`${t}${0===n?"":","}${e(void 0===r||"symbol"==typeof r?null:r)}`),"")}]`:`{${Object.keys(t).sort().reduce(((r,n)=>void 0===t[n]||"symbol"==typeof t[n]?r:`${r}${0===r.length?"":","}${e(n)}:${e(t[n])}`),"")}}`}},417:e=>{e.exports={rfc4648:e=>t=>({encode:r=>((e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,f=0;for(let n=0;n<e.length;++n)for(f=f<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&f>>s];if(s&&(i+=t[o&f<<r-s]),n)for(;i.length*r&7;)i+="=";return i})(r,t,e),decode:r=>((e,t,r)=>{const n={};for(let e=0;e<t.length;++e)n[t[e]]=e;let o=e.length;for(;"="===e[o-1];)--o;const i=new Uint8Array(o*r/8|0);let s=0,f=0,c=0;for(let t=0;t<o;++t){const o=n[e[t]];if(void 0===o)throw new SyntaxError("Invalid character "+e[t]);f=f<<r|o,s+=r,s>=8&&(s-=8,i[c++]=255&f>>s)}if(s>=r||255&f<<8-s)throw new SyntaxError("Unexpected end of data");return i})(r,t,e)})}},466:(e,t,r)=>{const n=r(579),{encodeText:o,decodeText:i,concat:s}=r(703);function f(e){if(Object.prototype.hasOwnProperty.call(n.names,e))return n.names[e];if(Object.prototype.hasOwnProperty.call(n.codes,e))return n.codes[e];throw new Error(`Unsupported encoding: ${e}`)}(t=e.exports=function(e,t){if(!t)throw new Error("requires an encoded Uint8Array");const{name:r,codeBuf:n}=f(e);return function(e,t){f(e).decode(i(t))}(r,t),s([n,t],n.length+t.length)}).encode=function(e,t){const r=f(e),n=o(r.encode(t));return s([r.codeBuf,n],r.codeBuf.length+n.length)},t.decode=function(e){e instanceof Uint8Array&&(e=i(e));const t=e[0];return["f","F","v","V","t","T","b","B","c","C","h","k","K"].includes(t)&&(e=e.toLowerCase()),f(e[0]).decode(e.substring(1))},t.isEncoded=function(e){if(e instanceof Uint8Array&&(e=i(e)),"[object String]"!==Object.prototype.toString.call(e))return!1;try{return f(e[0]).name}catch(e){return!1}},t.encoding=f,t.encodingFromData=function(e){return e instanceof Uint8Array&&(e=i(e)),f(e[0])};const c=Object.freeze(n.names),a=Object.freeze(n.codes);t.names=c,t.codes=a},579:(e,t,r)=>{const n=r(84),o=r(633),{rfc4648:i}=r(417),{decodeText:s,encodeText:f}=r(703),c=[["identity","\0",()=>({encode:s,decode:f}),""],["base2","0",i(1),"01"],["base8","7",i(3),"01234567"],["base10","9",n,"0123456789"],["base16","f",i(4),"0123456789abcdef"],["base16upper","F",i(4),"0123456789ABCDEF"],["base32hex","v",i(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",i(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",i(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",i(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",i(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",i(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",i(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",i(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",i(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",n,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",n,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",n,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",n,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",i(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",i(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",i(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",i(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],a=c.reduce(((e,t)=>(e[t[0]]=new o(t[0],t[1],t[2],t[3]),e)),{}),u=c.reduce(((e,t)=>(e[t[1]]=a[t[0]],e)),{});e.exports={names:a,codes:u}},633:(e,t,r)=>{const{encodeText:n}=r(703);e.exports=class{constructor(e,t,r,o){this.name=e,this.code=t,this.codeBuf=n(this.code),this.alphabet=o,this.codec=r(o)}encode(e){return this.codec.encode(e)}decode(e){for(const t of e)if(this.alphabet&&this.alphabet.indexOf(t)<0)throw new Error(`invalid character '${t}' in '${e}'`);return this.codec.decode(e)}}},703:e=>{const t=new TextDecoder,r=new TextEncoder;e.exports={decodeText:e=>t.decode(e),encodeText:e=>r.encode(e),concat:function(e,t){const r=new Uint8Array(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r}}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};r.r(n),r.d(n,{identity:()=>O});var o={};r.r(o),r.d(o,{base2:()=>R});var i={};r.r(i),r.d(i,{base8:()=>T});var s={};r.r(s),r.d(s,{base10:()=>N});var f={};r.r(f),r.d(f,{base16:()=>C,base16upper:()=>K});var c={};r.r(c),r.d(c,{base32:()=>L,base32hex:()=>_,base32hexpad:()=>F,base32hexpadupper:()=>H,base32hexupper:()=>V,base32pad:()=>$,base32padupper:()=>j,base32upper:()=>D,base32z:()=>z});var a={};r.r(a),r.d(a,{base36:()=>J,base36upper:()=>M});var u={};r.r(u),r.d(u,{base58btc:()=>W,base58flickr:()=>q});var h={};r.r(h),r.d(h,{base64:()=>G,base64pad:()=>Z,base64url:()=>X,base64urlpad:()=>Y});var d={};r.r(d),r.d(d,{base256emoji:()=>re});var l={};r.r(l),r.d(l,{sha256:()=>Se,sha512:()=>Ie});var p={};r.r(p),r.d(p,{identity:()=>Ue});var y={};r.r(y),r.d(y,{code:()=>Oe,decode:()=>Te,encode:()=>Re,name:()=>Pe});var w={};function g(e){return null!=globalThis.Buffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e}function b(e=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?g(globalThis.Buffer.allocUnsafe(e)):new Uint8Array(e)}function m(e,t){t||(t=e.reduce(((e,t)=>e+t.length),0));const r=b(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return g(r)}r.r(w),r.d(w,{code:()=>Le,decode:()=>$e,encode:()=>De,name:()=>Ke});const v=function(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 i=e.charAt(o),s=i.charCodeAt(0);if(255!==r[s])throw new TypeError(i+" is ambiguous");r[s]=o}var f=e.length,c=e.charAt(0),a=Math.log(f)/Math.log(256),u=Math.log(256)/Math.log(f);function h(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===c;)n++,t++;for(var i=(e.length-t)*a+1>>>0,s=new Uint8Array(i);e[t];){var u=r[e.charCodeAt(t)];if(255===u)return;for(var h=0,d=i-1;(0!==u||h<o)&&-1!==d;d--,h++)u+=f*s[d]>>>0,s[d]=u%256>>>0,u=u/256>>>0;if(0!==u)throw new Error("Non-zero carry");o=h,t++}if(" "!==e[t]){for(var l=i-o;l!==i&&0===s[l];)l++;for(var p=new Uint8Array(n+(i-l)),y=n;l!==i;)p[y++]=s[l++];return p}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var s=(i-o)*u+1>>>0,a=new Uint8Array(s);o!==i;){for(var h=t[o],d=0,l=s-1;(0!==h||d<n)&&-1!==l;l--,d++)h+=256*a[l]>>>0,a[l]=h%f>>>0,h=h/f>>>0;if(0!==h)throw new Error("Non-zero carry");n=d,o++}for(var p=s-n;p!==s&&0===a[p];)p++;for(var y=c.repeat(r);p<s;++p)y+=e.charAt(a[p]);return y},decodeUnsafe:h,decode:function(e){var r=h(e);if(r)return r;throw new Error(`Non-${t} character`)}}},E=(new Uint8Array(0),e=>{if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)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")});class x{constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class A{constructor(e,t,r){if(this.name=e,this.prefix=t,void 0===t.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if("string"==typeof e){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(e){return S(this,e)}}class B{constructor(e){this.decoders=e}or(e){return S(this,e)}decode(e){const t=e[0],r=this.decoders[t];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const S=(e,t)=>new B({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}});class I{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new x(e,t,r),this.decoder=new A(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const k=({name:e,prefix:t,encode:r,decode:n})=>new I(e,t,r,n),U=({prefix:e,name:t,alphabet:r})=>{const{encode:n,decode:o}=v(r,t);return k({prefix:e,name:t,encode:n,decode:e=>E(o(e))})},P=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>k({prefix:t,name:e,encode:e=>((e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,f=0;for(let n=0;n<e.length;++n)for(f=f<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&f>>s];if(s&&(i+=t[o&f<<r-s]),n)for(;i.length*r&7;)i+="=";return i})(e,n,r),decode:t=>((e,t,r,n)=>{const o={};for(let e=0;e<t.length;++e)o[t[e]]=e;let i=e.length;for(;"="===e[i-1];)--i;const s=new Uint8Array(i*r/8|0);let f=0,c=0,a=0;for(let t=0;t<i;++t){const i=o[e[t]];if(void 0===i)throw new SyntaxError(`Non-${n} character`);c=c<<r|i,f+=r,f>=8&&(f-=8,s[a++]=255&c>>f)}if(f>=r||255&c<<8-f)throw new SyntaxError("Unexpected end of data");return s})(t,n,r,e)}),O=k({prefix:"\0",name:"identity",encode:e=>{return t=e,(new TextDecoder).decode(t);var t},decode:e=>(e=>(new TextEncoder).encode(e))(e)}),R=P({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),T=P({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),N=U({prefix:"9",name:"base10",alphabet:"0123456789"}),C=P({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),K=P({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),L=P({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),D=P({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$=P({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),j=P({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_=P({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),V=P({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),F=P({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),H=P({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),z=P({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),J=U({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),M=U({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),W=U({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),q=U({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),G=P({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Z=P({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),X=P({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Y=P({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),Q=Array.from("๐๐ชโ๐ฐ๐๐๐๐๐๐๐๐๐๐๐๐๐โ๐ป๐ฅ๐พ๐ฟ๐โค๐๐คฃ๐๐๐๐ญ๐๐๐
๐๐๐ฅ๐ฅฐ๐๐๐๐ข๐ค๐๐๐ช๐โบ๐๐ค๐๐๐๐๐น๐คฆ๐๐โโจ๐คท๐ฑ๐๐ธ๐๐๐๐๐๐๐๐๐คฉ๐๐๐ค๐๐ฏ๐๐๐ถ๐๐คญโฃ๐๐๐๐ช๐๐ฅ๐๐๐ฉ๐ก๐คช๐๐ฅณ๐ฅ๐คค๐๐๐ณโ๐๐๐ด๐๐ฌ๐๐๐ท๐ป๐โญโ
๐ฅบ๐๐๐ค๐ฆโ๐ฃ๐๐โน๐๐๐ โ๐๐บ๐๐ป๐๐๐๐๐น๐ฃ๐ซ๐๐๐ต๐ค๐๐ด๐ค๐ผ๐ซโฝ๐คโ๐๐คซ๐๐ฎ๐๐ป๐๐ถ๐๐ฒ๐ฟ๐งก๐โก๐๐โโ๐๐ฐ๐คจ๐ถ๐ค๐ถ๐ฐ๐๐ข๐ค๐๐จ๐จ๐คฌโ๐๐บ๐ค๐๐๐ฑ๐๐ถ๐ฅดโถโกโ๐๐ธโฌ๐จ๐๐ฆ๐ท๐บโ ๐
๐๐ต๐๐คฒ๐ค ๐คง๐๐ต๐
๐ง๐พ๐๐๐ค๐๐คฏ๐ทโ๐ง๐ฏ๐๐๐ค๐๐โ๐ด๐ฃ๐ธ๐๐๐ฅ๐คข๐
๐ก๐ฉ๐๐ธ๐ป๐ค๐คฎ๐ผ๐ฅต๐ฉ๐๐๐ผ๐๐ฃ๐ฅ"),ee=Q.reduce(((e,t,r)=>(e[r]=t,e)),[]),te=Q.reduce(((e,t,r)=>(e[t.codePointAt(0)]=r,e)),[]),re=k({prefix:"๐",name:"base256emoji",encode:function(e){return e.reduce(((e,t)=>e+ee[t]),"")},decode:function(e){const t=[];for(const r of e){const e=te[r.codePointAt(0)];if(void 0===e)throw new Error(`Non-base256emoji character: ${r}`);t.push(e)}return new Uint8Array(t)}});var ne=128,oe=-128,ie=Math.pow(2,31),se=128,fe=127,ce=Math.pow(2,7),ae=Math.pow(2,14),ue=Math.pow(2,21),he=Math.pow(2,28),de=Math.pow(2,35),le=Math.pow(2,42),pe=Math.pow(2,49),ye=Math.pow(2,56),we=Math.pow(2,63);const ge={encode:function e(t,r,n){r=r||[];for(var o=n=n||0;t>=ie;)r[n++]=255&t|ne,t/=128;for(;t&oe;)r[n++]=255&t|ne,t>>>=7;return r[n]=0|t,e.bytes=n-o+1,r},decode:function e(t,r){var n,o=0,i=0,s=r=r||0,f=t.length;do{if(s>=f)throw e.bytes=0,new RangeError("Could not decode varint");n=t[s++],o+=i<28?(n&fe)<<i:(n&fe)*Math.pow(2,i),i+=7}while(n>=se);return e.bytes=s-r,o},encodingLength:function(e){return e<ce?1:e<ae?2:e<ue?3:e<he?4:e<de?5:e<le?6:e<pe?7:e<ye?8:e<we?9:10}},be=(e,t,r=0)=>(ge.encode(e,t,r),t),me=e=>ge.encodingLength(e),ve=(e,t)=>{const r=t.byteLength,n=me(e),o=n+me(r),i=new Uint8Array(o+r);return be(e,i,0),be(r,i,n),i.set(t,o),new Ee(e,r,t,i)};class Ee{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}const xe=({name:e,code:t,encode:r})=>new Ae(e,t,r);class Ae{constructor(e,t,r){this.name=e,this.code=t,this.encode=r}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?ve(this.code,t):t.then((e=>ve(this.code,e)))}throw Error("Unknown type, must be binary type")}}const Be=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),Se=xe({name:"sha2-256",code:18,encode:Be("SHA-256")}),Ie=xe({name:"sha2-512",code:19,encode:Be("SHA-512")}),ke=E,Ue={code:0,name:"identity",encode:ke,digest:e=>ve(0,ke(e))},Pe="raw",Oe=85,Re=e=>E(e),Te=e=>E(e),Ne=new TextEncoder,Ce=new TextDecoder,Ke="json",Le=512,De=e=>Ne.encode(JSON.stringify(e)),$e=e=>JSON.parse(Ce.decode(e));Symbol.toStringTag,Symbol.for("nodejs.util.inspect.custom"),Symbol.for("@ipld/js-cid/CID");const je={...n,...o,...i,...s,...f,...c,...a,...u,...h,...d};function _e(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}const Ve=_e("utf8","u",(e=>"u"+new TextDecoder("utf8").decode(e)),(e=>(new TextEncoder).encode(e.substring(1)))),Fe=_e("ascii","a",(e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t}),(e=>{const t=b((e=e.substring(1)).length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t})),He={utf8:Ve,"utf-8":Ve,hex:je.base16,latin1:Fe,ascii:Fe,binary:Fe,...je};function ze(e,t="utf8"){const r=He[t];if(!r)throw new Error(`Unsupported encoding "${t}"`);return"utf8"!==t&&"utf-8"!==t||null==globalThis.Buffer||null==globalThis.Buffer.from?r.decoder.decode(`${r.prefix}${e}`):g(globalThis.Buffer.from(e,"utf-8"))}function Je(e,t="utf8"){const r=He[t];if(!r)throw new Error(`Unsupported encoding "${t}"`);return"utf8"!==t&&"utf-8"!==t||null==globalThis.Buffer||null==globalThis.Buffer.from?r.encoder.encode(e).substring(1):globalThis.Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8")}const Me="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function We(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function qe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Ge(e,...t){if(!We(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 Ze(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 Xe(e,t){Ge(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ye(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Qe(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function et(e,t){return e<<32-t|e>>>t}function tt(e,t){return e<<t|e>>>32-t>>>0}const rt=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t;return e},nt=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),ot=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function it(e){if(Ge(e),nt)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=ot[e[r]];return t}function st(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function ft(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(nt)return Uint8Array.fromHex(e);const t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const n=new Uint8Array(r);for(let t=0,o=0;t<r;t++,o+=2){const r=st(e.charCodeAt(o)),i=st(e.charCodeAt(o+1));if(void 0===r||void 0===i){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}n[t]=16*r+i}return n}function ct(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),Ge(e),e}function at(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Ge(n),t+=n.length}const r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const o=e[t];r.set(o,n),n+=o.length}return r}class ut{}function ht(e){const t=t=>e().update(ct(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function dt(e=32){if(Me&&"function"==typeof Me.getRandomValues)return Me.getRandomValues(new Uint8Array(e));if(Me&&"function"==typeof Me.randomBytes)return Uint8Array.from(Me.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function lt(e,t,r){return e&t^e&r^t&r}class pt extends ut{constructor(e,t,r,n){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=r,this.isLE=n,this.buffer=new Uint8Array(e),this.view=Qe(this.buffer)}update(e){Ze(this),Ge(e=ct(e));const{view:t,buffer:r,blockLen:n}=this,o=e.length;for(let i=0;i<o;){const s=Math.min(n-this.pos,o-i);if(s!==n)r.set(e.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(t,0),this.pos=0);else{const t=Qe(e);for(;n<=o-i;i+=n)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ze(this),Xe(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:i}=this;t[i++]=128,Ye(this.buffer.subarray(i)),this.padOffset>n-i&&(this.process(r,0),i=0);for(let e=i;e<n;e++)t[e]=0;!function(e,t,r,n){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,r,n);const o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),f=Number(r&i),c=n?4:0,a=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+a,f,n)}(r,n-8,BigInt(8*this.length),o),this.process(r,0);const s=Qe(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=f/4,a=this.get();if(c>a.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)s.setUint32(4*e,a[e],o)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,n%t&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const yt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),wt=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),gt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),bt=BigInt(2**32-1),mt=BigInt(32);function vt(e,t=!1){return t?{h:Number(e&bt),l:Number(e>>mt&bt)}:{h:0|Number(e>>mt&bt),l:0|Number(e&bt)}}function Et(e,t=!1){const r=e.length;let n=new Uint32Array(r),o=new Uint32Array(r);for(let i=0;i<r;i++){const{h:r,l:s}=vt(e[i],t);[n[i],o[i]]=[r,s]}return[n,o]}const xt=(e,t,r)=>e>>>r,At=(e,t,r)=>e<<32-r|t>>>r,Bt=(e,t,r)=>e>>>r|t<<32-r,St=(e,t,r)=>e<<32-r|t>>>r,It=(e,t,r)=>e<<64-r|t>>>r-32,kt=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){const o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:0|o}}const Pt=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ot=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Rt=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Tt=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Nt=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ct=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0,Kt=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]),Lt=new Uint32Array(64);class Dt extends pt{constructor(e=32){super(64,e,8,!1),this.A=0|yt[0],this.B=0|yt[1],this.C=0|yt[2],this.D=0|yt[3],this.E=0|yt[4],this.F=0|yt[5],this.G=0|yt[6],this.H=0|yt[7]}get(){const{A:e,B:t,C:r,D:n,E:o,F:i,G:s,H:f}=this;return[e,t,r,n,o,i,s,f]}set(e,t,r,n,o,i,s,f){this.A=0|e,this.B=0|t,this.C=0|r,this.D=0|n,this.E=0|o,this.F=0|i,this.G=0|s,this.H=0|f}process(e,t){for(let r=0;r<16;r++,t+=4)Lt[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Lt[e-15],r=Lt[e-2],n=et(t,7)^et(t,18)^t>>>3,o=et(r,17)^et(r,19)^r>>>10;Lt[e]=o+Lt[e-7]+n+Lt[e-16]|0}let{A:r,B:n,C:o,D:i,E:s,F:f,G:c,H:a}=this;for(let e=0;e<64;e++){const t=a+(et(s,6)^et(s,11)^et(s,25))+((u=s)&f^~u&c)+Kt[e]+Lt[e]|0,h=(et(r,2)^et(r,13)^et(r,22))+lt(r,n,o)|0;a=c,c=f,f=s,s=i+t|0,i=o,o=n,n=r,r=t+h|0}var u;r=r+this.A|0,n=n+this.B|0,o=o+this.C|0,i=i+this.D|0,s=s+this.E|0,f=f+this.F|0,c=c+this.G|0,a=a+this.H|0,this.set(r,n,o,i,s,f,c,a)}roundClean(){Ye(Lt)}destroy(){this.set(0,0,0,0,0,0,0,0),Ye(this.buffer)}}const $t=(()=>Et(["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)))))(),jt=(()=>$t[0])(),_t=(()=>$t[1])(),Vt=new Uint32Array(80),Ft=new Uint32Array(80);class Ht extends pt{constructor(e=64){super(128,e,16,!1),this.Ah=0|gt[0],this.Al=0|gt[1],this.Bh=0|gt[2],this.Bl=0|gt[3],this.Ch=0|gt[4],this.Cl=0|gt[5],this.Dh=0|gt[6],this.Dl=0|gt[7],this.Eh=0|gt[8],this.El=0|gt[9],this.Fh=0|gt[10],this.Fl=0|gt[11],this.Gh=0|gt[12],this.Gl=0|gt[13],this.Hh=0|gt[14],this.Hl=0|gt[15]}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:o,Cl:i,Dh:s,Dl:f,Eh:c,El:a,Fh:u,Fl:h,Gh:d,Gl:l,Hh:p,Hl:y}=this;return[e,t,r,n,o,i,s,f,c,a,u,h,d,l,p,y]}set(e,t,r,n,o,i,s,f,c,a,u,h,d,l,p,y){this.Ah=0|e,this.Al=0|t,this.Bh=0|r,this.Bl=0|n,this.Ch=0|o,this.Cl=0|i,this.Dh=0|s,this.Dl=0|f,this.Eh=0|c,this.El=0|a,this.Fh=0|u,this.Fl=0|h,this.Gh=0|d,this.Gl=0|l,this.Hh=0|p,this.Hl=0|y}process(e,t){for(let r=0;r<16;r++,t+=4)Vt[r]=e.getUint32(t),Ft[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Vt[e-15],r=0|Ft[e-15],n=Bt(t,r,1)^Bt(t,r,8)^xt(t,0,7),o=St(t,r,1)^St(t,r,8)^At(t,r,7),i=0|Vt[e-2],s=0|Ft[e-2],f=Bt(i,s,19)^It(i,s,61)^xt(i,0,6),c=St(i,s,19)^kt(i,s,61)^At(i,s,6),a=Rt(o,c,Ft[e-7],Ft[e-16]),u=Tt(a,n,f,Vt[e-7],Vt[e-16]);Vt[e]=0|u,Ft[e]=0|a}let{Ah:r,Al:n,Bh:o,Bl:i,Ch:s,Cl:f,Dh:c,Dl:a,Eh:u,El:h,Fh:d,Fl:l,Gh:p,Gl:y,Hh:w,Hl:g}=this;for(let e=0;e<80;e++){const t=Bt(u,h,14)^Bt(u,h,18)^It(u,h,41),b=St(u,h,14)^St(u,h,18)^kt(u,h,41),m=u&d^~u&p,v=Nt(g,b,h&l^~h&y,_t[e],Ft[e]),E=Ct(v,w,t,m,jt[e],Vt[e]),x=0|v,A=Bt(r,n,28)^It(r,n,34)^It(r,n,39),B=St(r,n,28)^kt(r,n,34)^kt(r,n,39),S=r&o^r&s^o&s,I=n&i^n&f^i&f;w=0|p,g=0|y,p=0|d,y=0|l,d=0|u,l=0|h,({h:u,l:h}=Ut(0|c,0|a,0|E,0|x)),c=0|s,a=0|f,s=0|o,f=0|i,o=0|r,i=0|n;const k=Pt(x,B,I);r=Ot(k,E,A,S),n=0|k}({h:r,l:n}=Ut(0|this.Ah,0|this.Al,0|r,0|n)),({h:o,l:i}=Ut(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:f}=Ut(0|this.Ch,0|this.Cl,0|s,0|f)),({h:c,l:a}=Ut(0|this.Dh,0|this.Dl,0|c,0|a)),({h:u,l:h}=Ut(0|this.Eh,0|this.El,0|u,0|h)),({h:d,l}=Ut(0|this.Fh,0|this.Fl,0|d,0|l)),({h:p,l:y}=Ut(0|this.Gh,0|this.Gl,0|p,0|y)),({h:w,l:g}=Ut(0|this.Hh,0|this.Hl,0|w,0|g)),this.set(r,n,o,i,s,f,c,a,u,h,d,l,p,y,w,g)}roundClean(){Ye(Vt,Ft)}destroy(){Ye(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class zt extends Ht{constructor(){super(48),this.Ah=0|wt[0],this.Al=0|wt[1],this.Bh=0|wt[2],this.Bl=0|wt[3],this.Ch=0|wt[4],this.Cl=0|wt[5],this.Dh=0|wt[6],this.Dl=0|wt[7],this.Eh=0|wt[8],this.El=0|wt[9],this.Fh=0|wt[10],this.Fl=0|wt[11],this.Gh=0|wt[12],this.Gl=0|wt[13],this.Hh=0|wt[14],this.Hl=0|wt[15]}}const Jt=ht((()=>new Dt)),Mt=ht((()=>new Ht)),Wt=ht((()=>new zt)),qt=BigInt(0),Gt=BigInt(1);function Zt(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function Xt(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function Yt(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?qt:BigInt("0x"+e)}function Qt(e){return Yt(it(e))}function er(e){return Ge(e),Yt(it(Uint8Array.from(e).reverse()))}function tr(e,t){return ft(e.toString(16).padStart(2*t,"0"))}function rr(e,t){return tr(e,t).reverse()}function nr(e,t,r){let n;if("string"==typeof t)try{n=ft(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!We(t))throw new Error(e+" must be hex string or Uint8Array");n=Uint8Array.from(t)}const o=n.length;if("number"==typeof r&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}const or=e=>"bigint"==typeof e&&qt<=e;function ir(e,t,r,n){if(!function(e,t,r){return or(e)&&or(t)&&or(r)&&t<=e&&e<r}(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}const sr=e=>(Gt<<BigInt(e))-Gt;function fr(e,t,r={}){if(!e||"object"!=typeof e)throw new Error("expected valid options object");function n(t,r,n){const o=e[t];if(n&&void 0===o)return;const i=typeof o;if(i!==r||null===o)throw new Error(`param "${t}" is invalid: expected ${r}, got ${i}`)}Object.entries(t).forEach((([e,t])=>n(e,t,!1))),Object.entries(r).forEach((([e,t])=>n(e,t,!0)))}function cr(e){const t=new WeakMap;return(r,...n)=>{const o=t.get(r);if(void 0!==o)return o;const i=e(r,...n);return t.set(r,i),i}}const ar=BigInt(0),ur=BigInt(1),hr=BigInt(2),dr=BigInt(3),lr=BigInt(4),pr=BigInt(5),yr=BigInt(8);function wr(e,t){const r=e%t;return r>=ar?r:t+r}function gr(e,t,r){let n=e;for(;t-- >ar;)n*=n,n%=r;return n}function br(e,t){if(e===ar)throw new Error("invert: expected non-zero number");if(t<=ar)throw new Error("invert: expected positive modulus, got "+t);let r=wr(e,t),n=t,o=ar,i=ur,s=ur,f=ar;for(;r!==ar;){const e=n/r,t=n%r,c=o-s*e,a=i-f*e;n=r,r=t,o=s,i=f,s=c,f=a}if(n!==ur)throw new Error("invert: does not exist");return wr(o,t)}function mr(e,t){const r=(e.ORDER+ur)/lr,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function vr(e,t){const r=(e.ORDER-pr)/yr,n=e.mul(t,hr),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,hr),o),f=e.mul(i,e.sub(s,e.ONE));if(!e.eql(e.sqr(f),t))throw new Error("Cannot find square root");return f}const Er=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xr(e,t,r=!1){const n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce(((t,r,o)=>e.is0(r)?t:(n[o]=t,e.mul(t,r))),e.ONE),i=e.inv(o);return t.reduceRight(((t,r,o)=>e.is0(r)?t:(n[o]=e.mul(t,n[o]),e.mul(t,r))),i),n}function Ar(e,t){const r=(e.ORDER-ur)/hr,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Br(e,t,r=!1,n={}){if(e<=ar)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i;if("object"==typeof t&&null!=t){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");const e=t;e.BITS&&(o=e.BITS),e.sqrt&&(i=e.sqrt),"boolean"==typeof e.isLE&&(r=e.isLE)}else"number"==typeof t&&(o=t),n.sqrt&&(i=n.sqrt);const{nBitLength:s,nByteLength:f}=function(e,t){void 0!==t&&qe(t);const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c;const a=Object.freeze({ORDER:e,isLE:r,BITS:s,BYTES:f,MASK:sr(s),ZERO:ar,ONE:ur,create:t=>wr(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return ar<=t&&t<e},is0:e=>e===ar,isValidNot0:e=>!a.is0(e)&&a.isValid(e),isOdd:e=>(e&ur)===ur,neg:t=>wr(-t,e),eql:(e,t)=>e===t,sqr:t=>wr(t*t,e),add:(t,r)=>wr(t+r,e),sub:(t,r)=>wr(t-r,e),mul:(t,r)=>wr(t*r,e),pow:(e,t)=>function(e,t,r){if(r<ar)throw new Error("invalid exponent, negatives unsupported");if(r===ar)return e.ONE;if(r===ur)return t;let n=e.ONE,o=t;for(;r>ar;)r&ur&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ur;return n}(a,e,t),div:(t,r)=>wr(t*br(r,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>br(t,e),sqrt:i||(t=>{return c||(c=(r=e)%lr===dr?mr:r%yr===pr?vr:function(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-ur,r=0;for(;t%hr===ar;)t/=hr,r++;let n=hr;const o=Br(e);for(;1===Ar(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===r)return mr;let i=o.pow(n,t);const s=(t+ur)/hr;return function(e,n){if(e.is0(n))return n;if(1!==Ar(e,n))throw new Error("Cannot find square root");let o=r,f=e.mul(e.ONE,i),c=e.pow(n,t),a=e.pow(n,s);for(;!e.eql(c,e.ONE);){if(e.is0(c))return e.ZERO;let t=1,r=e.sqr(c);for(;!e.eql(r,e.ONE);)if(t++,r=e.sqr(r),t===o)throw new Error("Cannot find square root");const n=ur<<BigInt(o-t-1),i=e.pow(f,n);o=t,f=e.sqr(i),c=e.mul(c,f),a=e.mul(a,i)}return a}}(r)),c(a,t);var r}),toBytes:e=>r?rr(e,f):tr(e,f),fromBytes:e=>{if(e.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+e.length);return r?er(e):Qt(e)},invertBatch:e=>xr(a,e),cmov:(e,t,r)=>r?t:e});return Object.freeze(a)}function Sr(e){if("bigint"!=typeof e)throw new Error("field order must be bigint");const t=e.toString(2).length;return Math.ceil(t/8)}function Ir(e){const t=Sr(e);return t+Math.ceil(t/2)}const kr=BigInt(0),Ur=BigInt(1);function Pr(e,t){const r=t.negate();return e?r:t}function Or(e,t,r){const n="pz"===t?e=>e.pz:e=>e.ez,o=xr(e.Fp,r.map(n));return r.map(((e,t)=>e.toAffine(o[t]))).map(e.fromAffine)}function Rr(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Tr(e,t){Rr(e,t);const r=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:sr(e),maxNumber:r,shiftBy:BigInt(e)}}function Nr(e,t,r){const{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r;let f=Number(e&o),c=e>>s;f>n&&(f-=i,c+=Ur);const a=t*n;return{nextN:c,offset:a+Math.abs(f)-1,isZero:0===f,isNeg:f<0,isNegF:t%2!=0,offsetF:a}}const Cr=new WeakMap,Kr=new WeakMap;function Lr(e){return Kr.get(e)||1}function Dr(e){if(e!==kr)throw new Error("invalid wNAF")}function $r(e,t){return{constTimeNegate:Pr,hasPrecomputes:e=>1!==Lr(e),unsafeLadder(t,r,n=e.ZERO){let o=t;for(;r>kr;)r&Ur&&(n=n.add(o)),o=o.double(),r>>=Ur;return n},precomputeWindow(e,r){const{windows:n,windowSize:o}=Tr(r,t),i=[];let s=e,f=s;for(let e=0;e<n;e++){f=s,i.push(f);for(let e=1;e<o;e++)f=f.add(s),i.push(f);s=f.double()}return i},wNAF(r,n,o){let i=e.ZERO,s=e.BASE;const f=Tr(r,t);for(let e=0;e<f.windows;e++){const{nextN:t,offset:r,isZero:c,isNeg:a,isNegF:u,offsetF:h}=Nr(o,e,f);o=t,c?s=s.add(Pr(u,n[h])):i=i.add(Pr(a,n[r]))}return Dr(o),{p:i,f:s}},wNAFUnsafe(r,n,o,i=e.ZERO){const s=Tr(r,t);for(let e=0;e<s.windows&&o!==kr;e++){const{nextN:t,offset:r,isZero:f,isNeg:c}=Nr(o,e,s);if(o=t,!f){const e=n[r];i=i.add(c?e.negate():e)}}return Dr(o),i},getPrecomputes(e,t,r){let n=Cr.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&("function"==typeof r&&(n=r(n)),Cr.set(t,n))),n},wNAFCached(e,t,r){const n=Lr(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)},wNAFCachedUnsafe(e,t,r,n){const o=Lr(e);return 1===o?this.unsafeLadder(e,t,n):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,n)},setWindowSize(e,r){Rr(r,t),Kr.set(e,r),Cr.delete(e)}}}function jr(e,t,r,n){(function(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach(((e,r)=>{if(!(e instanceof t))throw new Error("invalid point at index "+r)}))})(r,e),function(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach(((e,r)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+r)}))}(n,t);const o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");const s=e.ZERO,f=function(e){let t;for(t=0;e>qt;e>>=Gt,t+=1);return t}(BigInt(o));let c=1;f>12?c=f-3:f>4?c=f-2:f>0&&(c=2);const a=sr(c),u=new Array(Number(a)+1).fill(s);let h=s;for(let e=Math.floor((t.BITS-1)/c)*c;e>=0;e-=c){u.fill(s);for(let t=0;t<i;t++){const o=n[t],i=Number(o>>BigInt(e)&a);u[i]=u[i].add(r[t])}let t=s;for(let e=u.length-1,r=s;e>0;e--)r=r.add(u[e]),t=t.add(r);if(h=h.add(t),0!==e)for(let e=0;e<c;e++)h=h.double()}return h}function _r(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return function(e){fr(e,Er.reduce(((e,t)=>(e[t]="function",e)),{ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"}))}(t),t}return Br(e)}function Vr(e,t,r={}){if(!t||"object"!=typeof t)throw new Error(`expected valid ${e} CURVE object`);for(const e of["p","n","h"]){const r=t[e];if(!("bigint"==typeof r&&r>kr))throw new Error(`CURVE.${e} must be positive bigint`)}const n=_r(t.p,r.Fp),o=_r(t.n,r.Fn),i=["Gx","Gy","a","weierstrass"===e?"b":"d"];for(const e of i)if(!n.isValid(t[e]))throw new Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}const Fr=BigInt(0),Hr=BigInt(1),zr=BigInt(2),Jr=BigInt(8),Mr={zip215:!0};function Wr(e){const{CURVE:t,curveOpts:r,eddsaOpts:n}=function(e){const t={a:e.a,d:e.d,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy};return{CURVE:t,curveOpts:{Fp:e.Fp,Fn:Br(t.n,e.nBitLength,!0),uvRatio:e.uvRatio},eddsaOpts:{hash:e.hash,randomBytes:e.randomBytes,adjustScalarBytes:e.adjustScalarBytes,domain:e.domain,prehash:e.prehash,mapToCurve:e.mapToCurve}}}(e),o=function(e,t={}){const{Fp:r,Fn:n}=Vr("edwards",e,t),{h:o,n:i}=e;fr(t,{},{uvRatio:"function"});const s=zr<<BigInt(8*n.BYTES)-Hr,f=e=>r.create(e),c=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:r.sqrt(r.div(e,t))}}catch(e){return{isValid:!1,value:Fr}}});if(!function(e,t,r,n){const o=e.sqr(r),i=e.sqr(n),s=e.add(e.mul(t.a,o),i),f=e.add(e.ONE,e.mul(t.d,e.mul(o,i)));return e.eql(s,f)}(r,e,e.Gx,e.Gy))throw new Error("bad curve params: generator point");function a(e,t,r=!1){return ir("coordinate "+e,t,r?Hr:Fr,s),t}function u(e){if(!(e instanceof l))throw new Error("ExtendedPoint expected")}const h=cr(((e,t)=>{const{ex:n,ey:o,ez:i}=e,s=e.is0();null==t&&(t=s?Jr:r.inv(i));const c=f(n*t),a=f(o*t),u=f(i*t);if(s)return{x:Fr,y:Hr};if(u!==Hr)throw new Error("invZ was invalid");return{x:c,y:a}})),d=cr((t=>{const{a:r,d:n}=e;if(t.is0())throw new Error("bad point: ZERO");const{ex:o,ey:i,ez:s,et:c}=t,a=f(o*o),u=f(i*i),h=f(s*s),d=f(h*h),l=f(a*r);if(f(h*f(l+u))!==f(d+f(n*f(a*u))))throw new Error("bad point: equation left != right (1)");if(f(o*i)!==f(s*c))throw new Error("bad point: equation left != right (2)");return!0}));class l{constructor(e,t,r,n){this.ex=a("x",e),this.ey=a("y",t),this.ez=a("z",r,!0),this.et=a("t",n),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(e){if(e instanceof l)throw new Error("extended point not allowed");const{x:t,y:r}=e||{};return a("x",t),a("y",r),new l(t,r,Hr,f(t*r))}static normalizeZ(e){return Or(l,"ez",e)}static msm(e,t){return jr(l,n,e,t)}_setWindowSize(e){this.precompute(e)}precompute(e=8,t=!0){return p.setWindowSize(this,e),t||this.multiply(zr),this}assertValidity(){d(this)}equals(e){u(e);const{ex:t,ey:r,ez:n}=this,{ex:o,ey:i,ez:s}=e,c=f(t*s),a=f(o*n),h=f(r*s),d=f(i*n);return c===a&&h===d}is0(){return this.equals(l.ZERO)}negate(){return new l(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){const{a:t}=e,{ex:r,ey:n,ez:o}=this,i=f(r*r),s=f(n*n),c=f(zr*f(o*o)),a=f(t*i),u=r+n,h=f(f(u*u)-i-s),d=a+s,p=d-c,y=a-s,w=f(h*p),g=f(d*y),b=f(h*y),m=f(p*d);return new l(w,g,m,b)}add(t){u(t);const{a:r,d:n}=e,{ex:o,ey:i,ez:s,et:c}=this,{ex:a,ey:h,ez:d,et:p}=t,y=f(o*a),w=f(i*h),g=f(c*n*p),b=f(s*d),m=f((o+i)*(a+h)-y-w),v=b-g,E=b+g,x=f(w-r*y),A=f(m*v),B=f(E*x),S=f(m*x),I=f(v*E);return new l(A,B,I,S)}subtract(e){return this.add(e.negate())}multiply(e){const t=e;ir("scalar",t,Hr,i);const{p:r,f:n}=p.wNAFCached(this,t,l.normalizeZ);return l.normalizeZ([r,n])[0]}multiplyUnsafe(e,t=l.ZERO){const r=e;return ir("scalar",r,Fr,i),r===Fr?l.ZERO:this.is0()||r===Hr?this:p.wNAFCachedUnsafe(this,r,l.normalizeZ,t)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}isTorsionFree(){return p.wNAFCachedUnsafe(this,i).is0()}toAffine(e){return h(this,e)}clearCofactor(){return o===Hr?this:this.multiplyUnsafe(o)}static fromBytes(e,t=!1){return Ge(e),this.fromHex(e,t)}static fromHex(t,n=!1){const{d:o,a:i}=e,a=r.BYTES;t=nr("pointHex",t,a),Zt("zip215",n);const u=t.slice(),h=t[a-1];u[a-1]=-129&h;const d=er(u),p=n?s:r.ORDER;ir("pointHex.y",d,Fr,p);const y=f(d*d),w=f(y-Hr),g=f(o*y-i);let{isValid:b,value:m}=c(w,g);if(!b)throw new Error("Point.fromHex: invalid y coordinate");const v=(m&Hr)===Hr,E=!!(128&h);if(!n&&m===Fr&&E)throw new Error("Point.fromHex: x=0 and x_0=1");return E!==v&&(m=f(-m)),l.fromAffine({x:m,y:d})}static fromPrivateScalar(e){return l.BASE.multiply(e)}toBytes(){const{x:e,y:t}=this.toAffine(),n=rr(t,r.BYTES);return n[n.length-1]|=e&Hr?128:0,n}toRawBytes(){return this.toBytes()}toHex(){return it(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}l.BASE=new l(e.Gx,e.Gy,Hr,f(e.Gx*e.Gy)),l.ZERO=new l(Fr,Hr,Hr,Fr),l.Fp=r,l.Fn=n;const p=$r(l,8*n.BYTES);return l}(t,r);return function(e,t){return Object.assign({},t,{ExtendedPoint:t.Point,CURVE:e})}(e,function(e,t){fr(t,{hash:"function"},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});const{prehash:r,hash:n}=t,{BASE:o,Fp:i,Fn:s}=e,f=s.ORDER,c=t.randomBytes||dt,a=t.adjustScalarBytes||(e=>e),u=t.domain||((e,t,r)=>{if(Zt("phflag",r),t.length||r)throw new Error("Contexts/pre-hash are not supported");return e});function h(e){return s.create(e)}function d(e){return h(er(e))}function l(e){const{head:t,prefix:r,scalar:s}=function(e){const t=i.BYTES;e=nr("private key",e,t);const r=nr("hashed private key",n(e),2*t),o=a(r.slice(0,t));return{head:o,prefix:r.slice(t,2*t),scalar:d(o)}}(e),f=o.multiply(s),c=f.toBytes();return{head:t,prefix:r,scalar:s,point:f,pointBytes:c}}function p(e=Uint8Array.of(),...t){const o=at(...t);return d(n(u(o,nr("context",e),!!r)))}const y=Mr;return o.precompute(8),{getPublicKey:function(e){return l(e).pointBytes},sign:function(e,t,n={}){e=nr("message",e),r&&(e=r(e));const{prefix:s,scalar:c,pointBytes:a}=l(t),u=p(n.context,s,e),d=o.multiply(u).toBytes(),y=h(u+p(n.context,d,a,e)*c);ir("signature.s",y,Fr,f);const w=i.BYTES;return nr("result",at(d,rr(y,w)),2*w)},verify:function(t,n,s,f=y){const{context:c,zip215:a}=f,u=i.BYTES;t=nr("signature",t,2*u),n=nr("message",n),s=nr("publicKey",s,u),void 0!==a&&Zt("zip215",a),r&&(n=r(n));const h=er(t.slice(u,2*u));let d,l,w;try{d=e.fromHex(s,a),l=e.fromHex(t.slice(0,u),a),w=o.multiplyUnsafe(h)}catch(e){return!1}if(!a&&d.isSmallOrder())return!1;const g=p(c,l.toBytes(),d.toBytes(),n);return l.add(d.multiplyUnsafe(g)).subtract(w).clearCofactor().is0()},utils:{getExtendedPublicKey:l,randomPrivateKey:()=>c(i.BYTES),precompute:(t=8,r=e.BASE)=>r.precompute(t,!1)},Point:e}}(o,n))}const qr=BigInt(0),Gr=BigInt(1),Zr=BigInt(2);BigInt(0);const Xr=BigInt(1),Yr=BigInt(2),Qr=BigInt(3),en=BigInt(5),tn=BigInt(8),rn={p:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:tn,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nn(e){const t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=rn.p,s=e*e%i*e%i,f=gr(s,Yr,i)*s%i,c=gr(f,Xr,i)*e%i,a=gr(c,en,i)*c%i,u=gr(a,t,i)*a%i,h=gr(u,r,i)*u%i,d=gr(h,n,i)*h%i,l=gr(d,o,i)*d%i,p=gr(l,o,i)*d%i,y=gr(p,t,i)*a%i;return{pow_p_5_8:gr(y,Yr,i)*e%i,b2:s}}function on(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}const sn=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function fn(e,t){const r=rn.p,n=wr(t*t*t,r),o=wr(n*n*t,r);let i=wr(e*n*nn(e*o).pow_p_5_8,r);const s=wr(t*i*i,r),f=i,c=wr(i*sn,r),a=s===e,u=s===wr(-e,r),h=s===wr(-e*sn,r);return a&&(i=f),(u||h)&&(i=c),(wr(i,r)&ur)===ur&&(i=wr(-i,r)),{isValid:a||u,value:i}}const cn=(()=>Br(rn.p,void 0,!0))(),an=(()=>({...rn,Fp:cn,hash:Mt,adjustScalarBytes:on,uvRatio:fn}))(),un=(()=>Wr(an))(),hn=(()=>{const e=rn.p;return function(e){const t=(fr(r=e,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...r}));var r;const{P:n,type:o,adjustScalarBytes:i,powPminus2:s,randomBytes:f}=t,c="x25519"===o;if(!c&&"x448"!==o)throw new Error("invalid type");const a=f||dt,u=c?255:448,h=c?32:56,d=c?BigInt(9):BigInt(5),l=c?BigInt(121665):BigInt(39081),p=c?Zr**BigInt(254):Zr**BigInt(447),y=c?BigInt(8)*Zr**BigInt(251)-Gr:BigInt(4)*Zr**BigInt(445)-Gr,w=p+y+Gr,g=e=>wr(e,n),b=m(d);function m(e){return rr(g(e),h)}function v(e,t){const r=function(e,t){ir("u",e,qr,n),ir("scalar",t,p,w);const r=t,o=e;let i=Gr,f=qr,c=e,a=Gr,h=qr;for(let e=BigInt(u-1);e>=qr;e--){const t=r>>e&Gr;h^=t,({x_2:i,x_3:c}=x(h,i,c)),({x_2:f,x_3:a}=x(h,f,a)),h=t;const n=i+f,s=g(n*n),u=i-f,d=g(u*u),p=s-d,y=c+a,w=g((c-a)*n),b=g(y*u),m=w+b,v=w-b;c=g(m*m),a=g(o*g(v*v)),i=g(s*d),f=g(p*(s+g(l*p)))}({x_2:i,x_3:c}=x(h,i,c)),({x_2:f,x_3:a}=x(h,f,a));const d=s(f);return g(i*d)}(function(e){const t=nr("u coordinate",e,h);return c&&(t[31]&=127),g(er(t))}(t),function(e){return er(i(nr("scalar",e,h)))}(e));if(r===qr)throw new Error("invalid private or public key received");return m(r)}function E(e){return v(e,b)}function x(e,t,r){const n=g(e*(t-r));return{x_2:t=g(t-n),x_3:r=g(r+n)}}return{scalarMult:v,scalarMultBase:E,getSharedSecret:(e,t)=>v(e,t),getPublicKey:e=>E(e),utils:{randomPrivateKey:()=>a(h)},GuBytes:b.slice()}}({P:e,type:"x25519",powPminus2:t=>{const{pow_p_5_8:r,b2:n}=nn(t);return wr(gr(r,Qr,e)*n,e)},adjustScalarBytes:on})})();var dn=r(466);class ln extends ut{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");qe(e.outputLen),qe(e.blockLen)}(e);const r=ct(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let e=0;e<o.length;e++)o[e]^=54;this.iHash.update(o),this.oHash=e.create();for(let e=0;e<o.length;e++)o[e]^=106;this.oHash.update(o),Ye(o)}update(e){return Ze(this),this.iHash.update(e),this}digestInto(e){Ze(this),Ge(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:r,finished:n,destroyed:o,blockLen:i,outputLen:s}=this;return e.finished=n,e.destroyed=o,e.blockLen=i,e.outputLen=s,e.oHash=t._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const pn=(e,t,r)=>new ln(e,t).update(r).digest();function yn(e){void 0!==e.lowS&&Zt("lowS",e.lowS),void 0!==e.prehash&&Zt("prehash",e.prehash)}pn.create=(e,t)=>new ln(e,t);class wn extends Error{constructor(e=""){super(e)}}const gn={Err:wn,_tlv:{encode:(e,t)=>{const{Err:r}=gn;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(1&t.length)throw new r("tlv.encode: unpadded data");const n=t.length/2,o=Xt(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");const i=n>127?Xt(o.length/2|128):"";return Xt(e)+i+o+t},decode(e,t){const{Err:r}=gn;let n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");const o=t[n++];let i=0;if(128&o){const e=127&o;if(!e)throw new r("tlv.decode(long): indefinite length not supported");if(e>4)throw new r("tlv.decode(long): byte length is too big");const s=t.subarray(n,n+e);if(s.length!==e)throw new r("tlv.decode: length bytes not complete");if(0===s[0])throw new r("tlv.decode(long): zero leftmost byte");for(const e of s)i=i<<8|e;if(n+=e,i<128)throw new r("tlv.decode(long): not minimal encoding")}else i=o;const s=t.subarray(n,n+i);if(s.length!==i)throw new r("tlv.decode: wrong value length");return{v:s,l:t.subarray(n+i)}}},_int:{encode(e){const{Err:t}=gn;if(e<bn)throw new t("integer: