did-jwt
Version:
Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients
2 lines โข 126 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,c=e.charAt(0),a=Math.log(s)/Math.log(256),f=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]===c;)n++,r++;for(var i=(e.length-r)*a+1>>>0,f=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*f[d]>>>0,f[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===f[l];)l++;for(var p=new Uint8Array(n+(i-l)),y=n;l!==i;)p[y++]=f[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 a=(i-o)*f+1>>>0,u=new Uint8Array(a);o!==i;){for(var h=t[o],d=0,l=a-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=a-n;p!==a&&0===u[p];)p++;for(var y=c.repeat(r);p<a;++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])}`),"")}}`}},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)}}},579:(e,t,r)=>{const n=r(84),o=r(633),{rfc4648:i}=r(417),{decodeText:s,encodeText:c}=r(703),a=[["identity","\0",()=>({encode:s,decode:c}),""],["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-_="]],f=a.reduce(((e,t)=>(e[t[0]]=new o(t[0],t[1],t[2],t[3]),e)),{}),u=a.reduce(((e,t)=>(e[t[1]]=f[t[0]],e)),{});e.exports={names:f,codes:u}},466:(e,t,r)=>{const n=r(579),{encodeText:o,decodeText:i,concat:s}=r(703);function c(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}=c(e);return function(e,t){c(e).decode(i(t))}(r,t),s([n,t],n.length+t.length)}).encode=function(e,t){const r=c(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()),c(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 c(e[0]).name}catch(e){return!1}},t.encoding=c,t.encodingFromData=function(e){return e instanceof Uint8Array&&(e=i(e)),c(e[0])};const a=Object.freeze(n.names),f=Object.freeze(n.codes);t.names=a,t.codes=f},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,c=0;for(let n=0;n<e.length;++n)for(c=c<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&c>>s];if(s&&(i+=t[o&c<<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,c=0,a=0;for(let t=0;t<o;++t){const o=n[e[t]];if(void 0===o)throw new SyntaxError("Invalid character "+e[t]);c=c<<r|o,s+=r,s>=8&&(s-=8,i[a++]=255&c>>s)}if(s>=r||255&c<<8-s)throw new SyntaxError("Unexpected end of data");return i})(r,t,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.d(n,{xG:()=>as,wB:()=>ls,Eq:()=>hs,fD:()=>us,hV:()=>As,lA:()=>ds,fJ:()=>fs,rk:()=>Ni,Kp:()=>Ri,Tl:()=>Ki,L6:()=>Oi,My:()=>Wi,n0:()=>_i,So:()=>fc,vz:()=>cc,qU:()=>cs,Hk:()=>gc,DM:()=>pc,Pg:()=>yc,jS:()=>lc,cu:()=>hc,Pt:()=>rc,PM:()=>js,WJ:()=>Ds,p0:()=>Cs,Xo:()=>uc,PC:()=>ac,Cg:()=>sc,Cq:()=>Ms,Ks:()=>tc,NS:()=>$i,V:()=>es,aT:()=>Hi,fr:()=>Vi,uV:()=>dc,k:()=>Di,bm:()=>os,K:()=>Gs,RO:()=>Ls,Vd:()=>xc,fG:()=>mc,K3:()=>Bc,sg:()=>Ec,hc:()=>ic,b3:()=>oc});var o={};r.r(o),r.d(o,{identity:()=>O});var i={};r.r(i),r.d(i,{base2:()=>R});var s={};r.r(s),r.d(s,{base8:()=>N});var c={};r.r(c),r.d(c,{base10:()=>K});var a={};r.r(a),r.d(a,{base16:()=>L,base16upper:()=>C});var f={};r.r(f),r.d(f,{base32:()=>D,base32hex:()=>V,base32hexpad:()=>J,base32hexpadupper:()=>z,base32hexupper:()=>H,base32pad:()=>$,base32padupper:()=>_,base32upper:()=>j,base32z:()=>W});var u={};r.r(u),r.d(u,{base36:()=>F,base36upper:()=>M});var h={};r.r(h),r.d(h,{base58btc:()=>q,base58flickr:()=>G});var d={};r.r(d),r.d(d,{base64:()=>Z,base64pad:()=>X,base64url:()=>Y,base64urlpad:()=>Q});var l={};r.r(l),r.d(l,{base256emoji:()=>ne});var p={};r.r(p),r.d(p,{sha256:()=>ke,sha512:()=>Pe});var y={};r.r(y),r.d(y,{identity:()=>Te});var g={};r.r(g),r.d(g,{code:()=>Re,decode:()=>Ke,encode:()=>Ne,name:()=>Oe});var w={};function b(e){return null!=globalThis.Buffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e}function m(e=0){return null!=globalThis.Buffer&&null!=globalThis.Buffer.allocUnsafe?b(globalThis.Buffer.allocUnsafe(e)):new Uint8Array(e)}function v(e,t){t||(t=e.reduce(((e,t)=>e+t.length),0));const r=m(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return b(r)}r.r(w),r.d(w,{code:()=>je,decode:()=>_e,encode:()=>$e,name:()=>De});const E=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 c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);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]===a;)n++,t++;for(var i=(e.length-t)*f+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+=c*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,f=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*f[l]>>>0,f[l]=h%c>>>0,h=h/c>>>0;if(0!==h)throw new Error("Non-zero carry");n=d,o++}for(var p=s-n;p!==s&&0===f[p];)p++;for(var y=a.repeat(r);p<s;++p)y+=e.charAt(f[p]);return y},decodeUnsafe:h,decode:function(e){var r=h(e);if(r)return r;throw new Error(`Non-${t} character`)}}},x=(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 A{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 B{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 I(this,e)}}class S{constructor(e){this.decoders=e}or(e){return I(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 I=(e,t)=>new S({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}});class k{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new A(e,t,r),this.decoder=new B(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const P=({name:e,prefix:t,encode:r,decode:n})=>new k(e,t,r,n),U=({prefix:e,name:t,alphabet:r})=>{const{encode:n,decode:o}=E(r,t);return P({prefix:e,name:t,encode:n,decode:e=>x(o(e))})},T=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>P({prefix:t,name:e,encode:e=>((e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,c=0;for(let n=0;n<e.length;++n)for(c=c<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&c>>s];if(s&&(i+=t[o&c<<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 c=0,a=0,f=0;for(let t=0;t<i;++t){const i=o[e[t]];if(void 0===i)throw new SyntaxError(`Non-${n} character`);a=a<<r|i,c+=r,c>=8&&(c-=8,s[f++]=255&a>>c)}if(c>=r||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return s})(t,n,r,e)}),O=P({prefix:"\0",name:"identity",encode:e=>{return t=e,(new TextDecoder).decode(t);var t},decode:e=>(e=>(new TextEncoder).encode(e))(e)}),R=T({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1}),N=T({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3}),K=U({prefix:"9",name:"base10",alphabet:"0123456789"}),L=T({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),C=T({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4}),D=T({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),j=T({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$=T({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_=T({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),V=T({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),H=T({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),J=T({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),z=T({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),W=T({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),F=U({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),M=U({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"}),q=U({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),G=U({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Z=T({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),X=T({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Y=T({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Q=T({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),ee=Array.from("๐๐ชโ๐ฐ๐๐๐๐๐๐๐๐๐๐๐๐๐โ๐ป๐ฅ๐พ๐ฟ๐โค๐๐คฃ๐๐๐๐ญ๐๐๐
๐๐๐ฅ๐ฅฐ๐๐๐๐ข๐ค๐๐๐ช๐โบ๐๐ค๐๐๐๐๐น๐คฆ๐๐โโจ๐คท๐ฑ๐๐ธ๐๐๐๐๐๐๐๐๐คฉ๐๐๐ค๐๐ฏ๐๐๐ถ๐๐คญโฃ๐๐๐๐ช๐๐ฅ๐๐๐ฉ๐ก๐คช๐๐ฅณ๐ฅ๐คค๐๐๐ณโ๐๐๐ด๐๐ฌ๐๐๐ท๐ป๐โญโ
๐ฅบ๐๐๐ค๐ฆโ๐ฃ๐๐โน๐๐๐ โ๐๐บ๐๐ป๐๐๐๐๐น๐ฃ๐ซ๐๐๐ต๐ค๐๐ด๐ค๐ผ๐ซโฝ๐คโ๐๐คซ๐๐ฎ๐๐ป๐๐ถ๐๐ฒ๐ฟ๐งก๐โก๐๐โโ๐๐ฐ๐คจ๐ถ๐ค๐ถ๐ฐ๐๐ข๐ค๐๐จ๐จ๐คฌโ๐๐บ๐ค๐๐๐ฑ๐๐ถ๐ฅดโถโกโ๐๐ธโฌ๐จ๐๐ฆ๐ท๐บโ ๐
๐๐ต๐๐คฒ๐ค ๐คง๐๐ต๐
๐ง๐พ๐๐๐ค๐๐คฏ๐ทโ๐ง๐ฏ๐๐๐ค๐๐โ๐ด๐ฃ๐ธ๐๐๐ฅ๐คข๐
๐ก๐ฉ๐๐ธ๐ป๐ค๐คฎ๐ผ๐ฅต๐ฉ๐๐๐ผ๐๐ฃ๐ฅ"),te=ee.reduce(((e,t,r)=>(e[r]=t,e)),[]),re=ee.reduce(((e,t,r)=>(e[t.codePointAt(0)]=r,e)),[]),ne=P({prefix:"๐",name:"base256emoji",encode:function(e){return e.reduce(((e,t)=>e+te[t]),"")},decode:function(e){const t=[];for(const r of e){const e=re[r.codePointAt(0)];if(void 0===e)throw new Error(`Non-base256emoji character: ${r}`);t.push(e)}return new Uint8Array(t)}});var oe=128,ie=-128,se=Math.pow(2,31),ce=128,ae=127,fe=Math.pow(2,7),ue=Math.pow(2,14),he=Math.pow(2,21),de=Math.pow(2,28),le=Math.pow(2,35),pe=Math.pow(2,42),ye=Math.pow(2,49),ge=Math.pow(2,56),we=Math.pow(2,63);const be={encode:function e(t,r,n){r=r||[];for(var o=n=n||0;t>=se;)r[n++]=255&t|oe,t/=128;for(;t&ie;)r[n++]=255&t|oe,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,c=t.length;do{if(s>=c)throw e.bytes=0,new RangeError("Could not decode varint");n=t[s++],o+=i<28?(n&ae)<<i:(n&ae)*Math.pow(2,i),i+=7}while(n>=ce);return e.bytes=s-r,o},encodingLength:function(e){return e<fe?1:e<ue?2:e<he?3:e<de?4:e<le?5:e<pe?6:e<ye?7:e<ge?8:e<we?9:10}},me=(e,t=0)=>[be.decode(e,t),be.decode.bytes],ve=(e,t,r=0)=>(be.encode(e,t,r),t),Ee=e=>be.encodingLength(e),xe=(e,t)=>{const r=t.byteLength,n=Ee(e),o=n+Ee(r),i=new Uint8Array(o+r);return ve(e,i,0),ve(r,i,n),i.set(t,o),new Ae(e,r,t,i)};class Ae{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}const Be=({name:e,code:t,encode:r})=>new Se(e,t,r);class Se{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?xe(this.code,t):t.then((e=>xe(this.code,e)))}throw Error("Unknown type, must be binary type")}}const Ie=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),ke=Be({name:"sha2-256",code:18,encode:Ie("SHA-256")}),Pe=Be({name:"sha2-512",code:19,encode:Ie("SHA-512")}),Ue=x,Te={code:0,name:"identity",encode:Ue,digest:e=>xe(0,Ue(e))},Oe="raw",Re=85,Ne=e=>x(e),Ke=e=>x(e),Le=new TextEncoder,Ce=new TextDecoder,De="json",je=512,$e=e=>Le.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 Ve={...o,...i,...s,...c,...a,...f,...u,...h,...d,...l};function He(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}const Je=He("utf8","u",(e=>"u"+new TextDecoder("utf8").decode(e)),(e=>(new TextEncoder).encode(e.substring(1)))),ze=He("ascii","a",(e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t}),(e=>{const t=m((e=e.substring(1)).length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t})),We={utf8:Je,"utf-8":Je,hex:Ve.base16,latin1:ze,ascii:ze,binary:ze,...Ve};function Fe(e,t="utf8"){const r=We[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}`):b(globalThis.Buffer.from(e,"utf-8"))}function Me(e,t="utf8"){const r=We[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 qe="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0;function Ge(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Ze(e,...t){if(!((r=e)instanceof Uint8Array||ArrayBuffer.isView(r)&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Xe(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 Ye(e,t){Ze(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Qe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function et(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function tt(e,t){return e<<32-t|e>>>t}function rt(e,t){return e<<t|e>>>32-t>>>0}const nt=(()=>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};function ot(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)),Ze(e),e}class it{}function st(e){const t=t=>e().update(ot(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ct(e=32){if(qe&&"function"==typeof qe.getRandomValues)return qe.getRandomValues(new Uint8Array(e));if(qe&&"function"==typeof qe.randomBytes)return Uint8Array.from(qe.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function at(e,t,r){return e&t^e&r^t&r}class ft extends it{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=et(this.buffer)}update(e){Xe(this),Ze(e=ot(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=et(e);for(;n<=o-i;i+=n)this.process(t,i)}}return this.length+=e.length,this.roundClean(),this}digestInto(e){Xe(this),Ye(e,this),this.finished=!0;const{buffer:t,view:r,blockLen:n,isLE:o}=this;let{pos:i}=this;t[i++]=128,Qe(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),c=Number(r&i),a=n?4:0,f=n?0:4;e.setUint32(t+a,s,n),e.setUint32(t+f,c,n)}(r,n-8,BigInt(8*this.length),o),this.process(r,0);const s=et(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const a=c/4,f=this.get();if(a>f.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<a;e++)s.setUint32(4*e,f[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 ut=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ht=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),lt=BigInt(2**32-1),pt=BigInt(32);function yt(e,t=!1){return t?{h:Number(e<),l:Number(e>>pt<)}:{h:0|Number(e>>pt<),l:0|Number(e<)}}function gt(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}=yt(e[i],t);[n[i],o[i]]=[r,s]}return[n,o]}const wt=(e,t,r)=>e>>>r,bt=(e,t,r)=>e<<32-r|t>>>r,mt=(e,t,r)=>e>>>r|t<<32-r,vt=(e,t,r)=>e<<32-r|t>>>r,Et=(e,t,r)=>e<<64-r|t>>>r-32,xt=(e,t,r)=>e>>>r-32|t<<64-r;function At(e,t,r,n){const o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:0|o}}const Bt=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),St=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,It=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),kt=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Pt=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ut=(e,t,r,n,o,i)=>t+r+n+o+i+(e/2**32|0)|0,Tt=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]),Ot=new Uint32Array(64);class Rt extends ft{constructor(e=32){super(64,e,8,!1),this.A=0|ut[0],this.B=0|ut[1],this.C=0|ut[2],this.D=0|ut[3],this.E=0|ut[4],this.F=0|ut[5],this.G=0|ut[6],this.H=0|ut[7]}get(){const{A:e,B:t,C:r,D:n,E:o,F:i,G:s,H:c}=this;return[e,t,r,n,o,i,s,c]}set(e,t,r,n,o,i,s,c){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|c}process(e,t){for(let r=0;r<16;r++,t+=4)Ot[r]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Ot[e-15],r=Ot[e-2],n=tt(t,7)^tt(t,18)^t>>>3,o=tt(r,17)^tt(r,19)^r>>>10;Ot[e]=o+Ot[e-7]+n+Ot[e-16]|0}let{A:r,B:n,C:o,D:i,E:s,F:c,G:a,H:f}=this;for(let e=0;e<64;e++){const t=f+(tt(s,6)^tt(s,11)^tt(s,25))+((u=s)&c^~u&a)+Tt[e]+Ot[e]|0,h=(tt(r,2)^tt(r,13)^tt(r,22))+at(r,n,o)|0;f=a,a=c,c=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,c=c+this.F|0,a=a+this.G|0,f=f+this.H|0,this.set(r,n,o,i,s,c,a,f)}roundClean(){Qe(Ot)}destroy(){this.set(0,0,0,0,0,0,0,0),Qe(this.buffer)}}const Nt=(()=>gt(["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)))))(),Kt=(()=>Nt[0])(),Lt=(()=>Nt[1])(),Ct=new Uint32Array(80),Dt=new Uint32Array(80);class jt extends ft{constructor(e=64){super(128,e,16,!1),this.Ah=0|dt[0],this.Al=0|dt[1],this.Bh=0|dt[2],this.Bl=0|dt[3],this.Ch=0|dt[4],this.Cl=0|dt[5],this.Dh=0|dt[6],this.Dl=0|dt[7],this.Eh=0|dt[8],this.El=0|dt[9],this.Fh=0|dt[10],this.Fl=0|dt[11],this.Gh=0|dt[12],this.Gl=0|dt[13],this.Hh=0|dt[14],this.Hl=0|dt[15]}get(){const{Ah:e,Al:t,Bh:r,Bl:n,Ch:o,Cl:i,Dh:s,Dl:c,Eh:a,El:f,Fh:u,Fl:h,Gh:d,Gl:l,Hh:p,Hl:y}=this;return[e,t,r,n,o,i,s,c,a,f,u,h,d,l,p,y]}set(e,t,r,n,o,i,s,c,a,f,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|c,this.Eh=0|a,this.El=0|f,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)Ct[r]=e.getUint32(t),Dt[r]=e.getUint32(t+=4);for(let e=16;e<80;e++){const t=0|Ct[e-15],r=0|Dt[e-15],n=mt(t,r,1)^mt(t,r,8)^wt(t,0,7),o=vt(t,r,1)^vt(t,r,8)^bt(t,r,7),i=0|Ct[e-2],s=0|Dt[e-2],c=mt(i,s,19)^Et(i,s,61)^wt(i,0,6),a=vt(i,s,19)^xt(i,s,61)^bt(i,s,6),f=It(o,a,Dt[e-7],Dt[e-16]),u=kt(f,n,c,Ct[e-7],Ct[e-16]);Ct[e]=0|u,Dt[e]=0|f}let{Ah:r,Al:n,Bh:o,Bl:i,Ch:s,Cl:c,Dh:a,Dl:f,Eh:u,El:h,Fh:d,Fl:l,Gh:p,Gl:y,Hh:g,Hl:w}=this;for(let e=0;e<80;e++){const t=mt(u,h,14)^mt(u,h,18)^Et(u,h,41),b=vt(u,h,14)^vt(u,h,18)^xt(u,h,41),m=u&d^~u&p,v=Pt(w,b,h&l^~h&y,Lt[e],Dt[e]),E=Ut(v,g,t,m,Kt[e],Ct[e]),x=0|v,A=mt(r,n,28)^Et(r,n,34)^Et(r,n,39),B=vt(r,n,28)^xt(r,n,34)^xt(r,n,39),S=r&o^r&s^o&s,I=n&i^n&c^i&c;g=0|p,w=0|y,p=0|d,y=0|l,d=0|u,l=0|h,({h:u,l:h}=At(0|a,0|f,0|E,0|x)),a=0|s,f=0|c,s=0|o,c=0|i,o=0|r,i=0|n;const k=Bt(x,B,I);r=St(k,E,A,S),n=0|k}({h:r,l:n}=At(0|this.Ah,0|this.Al,0|r,0|n)),({h:o,l:i}=At(0|this.Bh,0|this.Bl,0|o,0|i)),({h:s,l:c}=At(0|this.Ch,0|this.Cl,0|s,0|c)),({h:a,l:f}=At(0|this.Dh,0|this.Dl,0|a,0|f)),({h:u,l:h}=At(0|this.Eh,0|this.El,0|u,0|h)),({h:d,l}=At(0|this.Fh,0|this.Fl,0|d,0|l)),({h:p,l:y}=At(0|this.Gh,0|this.Gl,0|p,0|y)),({h:g,l:w}=At(0|this.Hh,0|this.Hl,0|g,0|w)),this.set(r,n,o,i,s,c,a,f,u,h,d,l,p,y,g,w)}roundClean(){Qe(Ct,Dt)}destroy(){Qe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class $t extends jt{constructor(){super(48),this.Ah=0|ht[0],this.Al=0|ht[1],this.Bh=0|ht[2],this.Bl=0|ht[3],this.Ch=0|ht[4],this.Cl=0|ht[5],this.Dh=0|ht[6],this.Dl=0|ht[7],this.Eh=0|ht[8],this.El=0|ht[9],this.Fh=0|ht[10],this.Fl=0|ht[11],this.Gh=0|ht[12],this.Gl=0|ht[13],this.Hh=0|ht[14],this.Hl=0|ht[15]}}const _t=st((()=>new Rt)),Vt=st((()=>new jt)),Ht=st((()=>new $t)),Jt=BigInt(0),zt=BigInt(1);function Wt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Ft(e){if(!Wt(e))throw new Error("Uint8Array expected")}function Mt(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function qt(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function Gt(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?Jt:BigInt("0x"+e)}const Zt="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,Xt=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function Yt(e){if(Ft(e),Zt)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Xt[e[r]];return t}function Qt(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function er(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Zt)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=Qt(e.charCodeAt(o)),i=Qt(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 tr(e){return Gt(Yt(e))}function rr(e){return Ft(e),Gt(Yt(Uint8Array.from(e).reverse()))}function nr(e,t){return er(e.toString(16).padStart(2*t,"0"))}function or(e,t){return nr(e,t).reverse()}function ir(e,t,r){let n;if("string"==typeof t)try{n=er(t)}catch(t){throw new Error(e+" must be hex string or Uint8Array, cause: "+t)}else{if(!Wt(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}function sr(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Ft(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}const cr=e=>"bigint"==typeof e&&Jt<=e;function ar(e,t,r){return cr(e)&&cr(t)&&cr(r)&&t<=e&&e<r}function fr(e,t,r,n){if(!ar(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}const ur=e=>(zt<<BigInt(e))-zt,hr=e=>new Uint8Array(e),dr=e=>Uint8Array.from(e),lr={bigint:e=>"bigint"==typeof e,function:e=>"function"==typeof e,boolean:e=>"boolean"==typeof e,string:e=>"string"==typeof e,stringOrUint8Array:e=>"string"==typeof e||Wt(e),isSafeInteger:e=>Number.isSafeInteger(e),array:e=>Array.isArray(e),field:(e,t)=>t.Fp.isValid(e),hash:e=>"function"==typeof e&&Number.isSafeInteger(e.outputLen)};function pr(e,t,r={}){const n=(t,r,n)=>{const o=lr[r];if("function"!=typeof o)throw new Error("invalid validator function");const i=e[t];if(!(n&&void 0===i||o(i,e)))throw new Error("param "+String(t)+" is invalid. Expected "+r+", got "+i)};for(const[e,r]of Object.entries(t))n(e,r,!1);for(const[e,t]of Object.entries(r))n(e,t,!0);return e}function yr(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 gr=BigInt(0),wr=BigInt(1),br=BigInt(2),mr=BigInt(3),vr=BigInt(4),Er=BigInt(5),xr=BigInt(8);function Ar(e,t){const r=e%t;return r>=gr?r:t+r}function Br(e,t,r){let n=e;for(;t-- >gr;)n*=n,n%=r;return n}function Sr(e,t){if(e===gr)throw new Error("invert: expected non-zero number");if(t<=gr)throw new Error("invert: expected positive modulus, got "+t);let r=Ar(e,t),n=t,o=gr,i=wr,s=wr,c=gr;for(;r!==gr;){const e=n/r,t=n%r,a=o-s*e,f=i-c*e;n=r,r=t,o=s,i=c,s=a,c=f}if(n!==wr)throw new Error("invert: does not exist");return Ar(o,t)}const Ir=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function kr(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 Pr(e,t){const r=function(e,t){const r=(e.ORDER-wr)/br,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("Cannot find square root: probably non-prime P");return o?1:i?0:-1}(e,t);return 0===r||1===r}function Ur(e,t){void 0!==t&&Ge(t);const r=void 0!==t?t:e.toString(2).length;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}function Tr(e,t,r=!1,n={}){if(e<=gr)throw new Error("invalid field: expected ORDER > 0, got "+e);const{nBitLength:o,nByteLength:i}=Ur(e,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let s;const c=Object.freeze({ORDER:e,isLE:r,BITS:o,BYTES:i,MASK:ur(o),ZERO:gr,ONE:wr,create:t=>Ar(t,e),isValid:t=>{if("bigint"!=typeof t)throw new Error("invalid field element: expected bigint, got "+typeof t);return gr<=t&&t<e},is0:e=>e===gr,isOdd:e=>(e&wr)===wr,neg:t=>Ar(-t,e),eql:(e,t)=>e===t,sqr:t=>Ar(t*t,e),add:(t,r)=>Ar(t+r,e),sub:(t,r)=>Ar(t-r,e),mul:(t,r)=>Ar(t*r,e),pow:(e,t)=>function(e,t,r){if(r<gr)throw new Error("invalid exponent, negatives unsupported");if(r===gr)return e.ONE;if(r===wr)return t;let n=e.ONE,o=t;for(;r>gr;)r&wr&&(n=e.mul(n,o)),o=e.sqr(o),r>>=wr;return n}(c,e,t),div:(t,r)=>Ar(t*Sr(r,e),e),sqrN:e=>e*e,addN:(e,t)=>e+t,subN:(e,t)=>e-t,mulN:(e,t)=>e*t,inv:t=>Sr(t,e),sqrt:n.sqrt||(t=>{return s||(s=(r=e)%vr===mr?function(e,t){const n=(r+wr)/vr,o=e.pow(t,n);if(!e.eql(e.sqr(o),t))throw new Error("Cannot find square root");return o}:r%xr===Er?function(e,t){const n=e.mul(t,br),o=(r-Er)/xr,i=e.pow(n,o),s=e.mul(t,i),c=e.mul(e.mul(s,br),i),a=e.mul(s,e.sub(c,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}:function(e){let t=e-wr,r=0;for(;t%br===gr;)t/=br,r++;let n=br;const o=Tr(e);for(;n<e&&Pr(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(1===r){const t=(e+wr)/vr;return function(e,r){const n=e.pow(r,t);if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root");return n}}const i=(t+wr)/br;return function(e,o){if(!Pr(e,o))throw new Error("Cannot find square root");let s=r,c=e.pow(e.mul(e.ONE,n),t),a=e.pow(o,i),f=e.pow(o,t);for(;!e.eql(f,e.ONE);){if(e.eql(f,e.ZERO))return e.ZERO;let t=1;for(let r=e.sqr(f);t<s&&!e.eql(r,e.ONE);t++)r=e.sqr(r);const r=e.pow(c,wr<<BigInt(s-t-1));c=e.sqr(r),a=e.mul(a,r),f=e.mul(f,c),s=t}return a}}(r)),s(c,t);var r}),toBytes:e=>r?or(e,i):nr(e,i),fromBytes:e=>{if(e.length!==i)throw new Error("Field.fromBytes: expected "+i+" bytes, got "+e.length);return r?rr(e):tr(e)},invertBatch:e=>kr(c,e),cmov:(e,t,r)=>r?t:e});return Object.freeze(c)}function Or(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 Rr(e){const t=Or(e);return t+Math.ceil(t/2)}const Nr=BigInt(0),Kr=BigInt(1);function Lr(e,t){const r=t.negate();return e?r:t}function Cr(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Dr(e,t){Cr(e,t);const r=2**e;return{windows:Math.ceil(t/e)+1,windowSize:2**(e-1),mask:ur(e),maxNumber:r,shiftBy:BigInt(e)}}function jr(e,t,r){const{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r;let c=Number(e&o),a=e>>s;c>n&&(c-=i,a+=Kr);const f=t*n;return{nextN:a,offset:f+Math.abs(c)-1,isZero:0===c,isNeg:c<0,isNegF:t%2!=0,offsetF:f}}const $r=new WeakMap,_r=new WeakMap;function Vr(e){return _r.get(e)||1}function Hr(e,t){return{constTimeNegate:Lr,hasPrecomputes:e=>1!==Vr(e),unsafeLadder(t,r,n=e.ZERO){let o=t;for(;r>Nr;)r&Kr&&(n=n.add(o)),o=o.double(),r>>=Kr;return n},precomputeWindow(e,r){const{windows:n,windowSize:o}=Dr(r,t),i=[];let s=e,c=s;for(let e=0;e<n;e++){c=s,i.push(c);for(let e=1;e<o;e++)c=c.add(s),i.push(c);s=c.double()}return i},wNAF(r,n,o){let i=e.ZERO,s=e.BASE;const c=Dr(r,t);for(let e=0;e<c.windows;e++){const{nextN:t,offset:r,isZero:a,isNeg:f,isNegF:u,offsetF:h}=jr(o,e,c);o=t,a?s=s.add(Lr(u,n[h])):i=i.add(Lr(f,n[r]))}return{p:i,f:s}},wNAFUnsafe(r,n,o,i=e.ZERO){const s=Dr(r,t);for(let e=0;e<s.windows&&o!==Nr;e++){const{nextN:t,offset:r,isZero:c,isNeg:a}=jr(o,e,s);if(o=t,!c){const e=n[r];i=i.add(a?e.negate():e)}}return i},getPrecomputes(e,t,r){let n=$r.get(t);return n||(n=this.precomputeWindow(t,e),1!==e&&$r.set(t,r(n))),n},wNAFCached(e,t,r){const n=Vr(e);return this.wNAF(n,this.getPrecomputes(n,e,r),t)},wNAFCachedUnsafe(e,t,r,n){const o=Vr(e);return 1===o?this.unsafeLadder(e,t,n):this.wNAFUnsafe(o,this.getPrecomputes(o,e,r),t,n)},setWindowSize(e,r){Cr(r,t),_r.set(e,r),$r.delete(e)}}}function Jr(e,t,r,n){if(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),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const o=e.ZERO,i=function(e){let t;for(t=0;e>Jt;e>>=zt,t+=1);return t}(BigInt(r.length)),s=i>12?i-3:i>4?i-2:i?2:1,c=ur(s),a=new Array(Number(c)+1).fill(o);let f=o;for(let e=Math.floor((t.BITS-1)/s)*s;e>=0;e-=s){a.fill(o);for(let t=0;t<n.length;t++){const o=n[t],i=Number(o>>BigInt(e)&c);a[i]=a[i].add(r[t])}let t=o;for(let e=a.length-1,r=o;e>0;e--)r=r.add(a[e]),t=t.add(r);if(f=f.add(t),0!==e)for(let e=0;e<s;e++)f=f.double()}return f}function zr(e){return pr(e.Fp,Ir.reduce(((e,t)=>(e[t]="function",e)),{ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"})),pr(e,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Ur(e.n,e.nBitLength),...e,p:e.Fp.ORDER})}const Wr=BigInt(0),Fr=BigInt(1),Mr=BigInt(2),qr=BigInt(8),Gr={zip215:!0};const Zr=BigInt(0),Xr=BigInt(1);const Yr=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Qr=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),en=(BigInt(0),BigInt(1)),tn=BigInt(2),rn=BigInt(3),nn=BigInt(5),on=BigInt(8);function sn(e){const t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),i=Yr,s=e*e%i*e%i,c=Br(s,tn,i)*s%i,a=Br(c,en,i)*e%i,f=Br(a,nn,i)*a%i,u=Br(f,t,i)*f%i,h=Br(u,r,i)*u%i,d=Br(h,n,i)*h%i,l=Br(d,o,i)*d%i,p=Br(l,o,i)*d%i,y=Br(p,t,i)*f%i;return{pow_p_5_8:Br(y,tn,i)*e%i,b2:s}}function cn(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}function an(e,t){const r=Yr,n=Ar(t*t*t,r),o=Ar(n*n*t,r);let i=Ar(e*n*sn(e*o).pow_p_5_8,r);const s=Ar(t*i*i,r),c=i,a=Ar(i*Qr,r),f=s===e,u=s===Ar(-e,r),h=s===Ar(-e*Qr,r);return f&&(i=c),(u||h)&&(i=a),(Ar(i,r)&wr)===wr&&(i=Ar(-i,r)),{isValid:f||u,value:i}}const fn=(()=>Tr(Yr,void 0,!0))(),un=(()=>({a:fn.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:fn,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:on,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Vt,randomBytes:ct,adjustScalarBytes:cn,uvRatio:an}))(),hn=(()=>function(e){const t=function(e){const t=zr(e);return pr(e,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}(e),{Fp:r,n,prehash:o,hash:i,randomBytes:s,nByteLength:c,h:a}=t,f=Mr<<BigInt(8*c)-Fr,u=r.create,h=Tr(t.n,t.nBitLength),d=t.uvRatio||((e,t)=>{try{return{isValid:!0,value:r.sqrt(e*r.inv(t))}}catch(e){return{isValid:!1,value:Wr}}}),l=t.adjustScalarBytes||(e=>e),p=t.domain||((e,t,r)=>{if(Mt("phflag",r),t.length||r)throw new Error("Contexts/pre-hash are not supported");return e});function y(e,t,r=!1){fr("coordinate "+e,t,r?Fr:Wr,f)}function g(e){if(!(e instanceof m))throw new Error("ExtendedPoint expected")}const w=yr(((e,t)=>{const{ex:n,ey:o,ez:i}=e,s=e.is0();null==t&&(t=s?qr:r.inv(i));const c=u(n*t),a=u(o*t),f=u(i*t);if(s)return{x:Wr,y:Fr};if(f!==Fr)throw new Error("invZ was invalid");return{x:c,y:a}})),b=yr((e=>{const{a:r,d:n}=t;if(e.is0())throw new Error("bad point: ZERO");const{ex:o,ey:i,ez:s,et:c}=e,a=u(o*o),f=u(i*i),h=u(s*s),d=u(h*h),l=u(a*r);if(u(h*u(l+f))!==u(d+u(n*u(a*f))))throw new Error("bad point: equation left != right (1)");if(u(o*i)!==u(s*c))throw new Error("bad point: equation left != right (2)");return!0}));class m{constructor(e,t,r,n){y("x",e),y("y",t),y("z",r,!0),y("t",n),this.ex=e,this.ey=t,this.ez=r,this.et=n,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(e){if(e instanceof m)throw new Error("extended point not allowed");const{x:t,y:r}=e||{};return y("x",t),y("y",r),new m(t,r,Fr,u(t*r))}static normalizeZ(e){const t=kr(r,e.map((e=>e.ez)));return e.map(((e,r)=>e.toAffine(t[r]))).map(m.fromAffine)}static msm(e,t){return Jr(m,h,e,t)}_setWindowSize(e){x.setWindowSize(this,e)}assertValidity(){b(this)}equals(e){g(e);const{ex:t,ey:r,ez:n}=this,{ex:o,ey:i,ez:s}=e,c=u(t*s),a=u(o*n),f=u(r*s),h=u(i*n);return c===a&&f===h}is0(){return this.equals(m.ZERO)}negate(){return new m(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){const{a:e}=t,{ex:r,ey:n,ez:o}=this,i=u(r*r),s=u(n*n),c=u(Mr*u(o*o)),a=u(e*i),f=r+n,h=u(u(f*f)-i-s),d=a+s,l=d-c,p=a-s,y=u(h*l),g=u(d*p),w=u(h*p),b=u(l*d);return new m(y,g,b,w)}add(e){g(e);const{a:r,d:n}=t,{ex:o,ey:i,ez:s,et:c}=this,{ex:a,ey:f,ez:h,et:d}=e,l=u(o*a),p=u(i*f),y=u(c*n*d),w=u(s*h),b=u((o+i)*(a+f)-l-p),v=w-y,E=w+y,x=u(p-r*l),A=u(b*v),B=u(E*x),S=u(b*x),I=u(v*E);return new m(A,B,I,S)}subtract(e){return this.add(e.negate())}wNAF(e){return x.wNAFCached(this,e,m.normalizeZ)}multiply(e){const t=e;fr("scalar",t,Fr,n);const{p:r,f:o}=this.wNAF(t);return m.normalizeZ([r,o])[0]}multiplyUnsafe(e,t=m.ZERO){const r=e;return fr("scalar",r,Wr,n),r===Wr?E:this.is0()||r===Fr?this:x.wNAFCachedUnsafe(this,r,m.normalizeZ,t)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return x.unsafeLadder(this,n).is0()}toAffine(e){return w(this,e)}clearCofactor(){const{h:e}=t;return e===Fr?this:this.multiplyUnsafe(e)}static fromHex(e,n=!1){const{d:o,a:i}=t,s=r.BYTES;e=ir("pointHex",e,s),Mt("zip215",n);const c=e.slice(),a=e[s-1];c[s-1]=-129&a;const h=rr(c),l=n?f:r.ORDER;fr("pointHex.y",h,Wr,l);const p=u(h*h),y=u(p-Fr),g=u(o*p-i);let{isValid:w,value:b}=d(y,g);if(!w)throw new Error("Point.fromHex: invalid y coordinate");const v=(b&Fr)===Fr,E=!!(128&a);if(!n&&b===Wr&&E)throw new Error("Point.fromHex: x=0 and x_0=1");return E!==v&&(b=u(-b)),m.fromAffine({x:b,y:h})}static fromPrivateKey(e){const{scalar:t}=S(e);return v.multiply(t)}toRawBytes(){const{x:e,y:t}=this.toAffine(),n=or(t,r.BYTES);return n[n.length-1]|=e&Fr?128:0,n}toHex(){return Yt(this.toRawBytes())}}m.BASE=new m(t.Gx,t.Gy,Fr,u(t.Gx*t.Gy)),m.ZERO=new m(Wr,Fr,Fr,Wr);const{BASE:v,ZERO:E}=m,x=Hr(m,8*c);function A(e){return Ar(e,n)}function B(e){return A(rr(e))}function S(e){const t=r.BYTES;e=ir("private key",e,t);const n=ir("hashed private key",i(e),2*t),o=l(n.slice(0,t));return{head:o,prefix:n.slice(t,2*t),scalar:B(o)}}function I(e){const{head:t,prefix:r,scalar:n}=S(e),o=v.multiply(n),i=o.toRawBytes();return{head:t,prefix:r,scalar:n,point:o,pointBytes:i}}function k(e=Uint8Array.of(),...t){const r=sr(...t);return B(i(p(r,ir("context",e),!!o)))}const P=Gr;return v._setWindowSize(8),{CURVE:t,getPublicKey:function(e){return I(e).pointBytes},sign:function(e,t,i={}){e=ir("message",e),o&&(e=o(e));const{prefix:s,scalar:c,pointBytes:a}=I(t),f=k(i.context,s,e),u=v.multiply(f).toRawBytes(),h=A(f+k(i.context,u,a,e)*c);return fr("signature.s",h,Wr,n),ir("result",sr(u,or(h,r.BYTES)),2*r.BYTES)},verify:function(e,t,n,i=P){const{context:s,zip215:c}=i,a=r.BYTES;e=ir("signature",e,2*a),t=ir("message",t),n=ir("publicKey",n,a),void 0!==c&&Mt("zip215",c),o&&(t=o(t));const f=rr(e.slice(a,2*a));let u,h,d;try{u=m.fromHex(n,c),h=m.fromHex(e.slice(0,a),c),d=v.multiplyUnsafe(f)}catch(e){return!1}if(!c&&u.isSmallOrder())return!1;const l=k(s,h.toRawBytes(),u.toRawBytes(),t);return h.add(u.multiplyUnsafe(l)).subtract(d).clearCofactor().equals(m.ZERO)},ExtendedPoint:m,utils:{getExtendedPublicKey:I,randomPrivateKey:()=>s(r.BYTES),precompute:(e=8,t=m.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)}}}(un))(),dn=(()=>function(e){const t=(pr(r=e,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...r}));var r;const{P:n}=t,o=Tr(n),i=e=>Ar(e,n),s=t.montgomeryBits,c=Math.ceil(s/8),a=t.nByteLength,f=t.adjustScalarBytes||(e=>e),u=t.powPminus2||(e=>o.pow(e,n-BigInt(2)));function h(e,t,r){const n=i(e*(t-r));return[t=i(t-n),r=i(r+n)]}const d=(t.a-BigInt(2))/BigInt(4);function l(e){return or(i(e),c)}function p(e,t){const r=function(e){const t=ir("u coordinate",e,c);return 32===a&&(t[31]&=127),rr(t)}(t),o=function(e,t){fr("u",e,Zr,n),fr("scalar",t,Zr,n);const r=t,o=e;let c,a=Xr,f=Zr,l=e,p=Xr,y=Zr;for(let e=BigInt(s-1);e>=Zr;e--){const t=r>>e&Xr;y^=t,c=h(y,a,l),a=c[0],l=c[1],c=h(y,f,p),f=c[0],p=c[1],y=t;const n=a+f,s=i(n*n),u=a-f,g=i(u*u),w=s-g,b=l+p,m=i((l-p)*n),v=i(b*u),E=m+v,x=m-v;l=i(E*E),p=i(o*i(x*x)),a=i(s*g),f=i(w*(s+i(d*w)))}c=h(y,a,l),a=c[0],l=c[1],c=h(y,f,p),f=c[0],p=c[1];const g=u(f);return i(a*g)}(r,function(e){const t=ir("scalar",e),r=t.length;if(r!==c&&r!==a)throw new Error("invalid scalar, expected "+c+" or "+a+" bytes, got "+r);return rr(f(t))}(e));if(o===Zr)throw new Error("invalid private or public key received");return l(o)}const y=l(t.Gu);function g(e){return p(e,y)}return{scalarMult:p,scalarMultBase:g,getSharedSecret:(e,t)=>p(e,t),getPublicKey:e=>g(e),utils:{randomPrivateKey:()=>t.randomBytes(t.nByteLength)},GuBytes:y}}({P:Yr,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:e=>{const t=Yr,{pow_p_5_8:r,b2:n}=sn(e);return Ar(Br(r,rn,t)*n,t)},adjustScalarBytes:cn,randomBytes:ct}))();var ln=r(466);class pn extends it{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");Ge(e.outputLen),Ge(e.blockLen)}(e);const r=ot(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),Qe(o)}update(e){return Xe(this),this.iHash.update(e),this}digestInto(e){Xe(this),Ze(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 yn=(e,t,r)=>new pn(e,t).update(r).digest();function gn(e){void 0!==e.lowS&&Mt("lowS",e.lowS),void 0!==e.prehash&&Mt("prehash",e.prehash)}yn.create=(e,t)=>new pn(e,t);class wn extends Error{constructor(e=""){super(e)}}const bn={Err:wn,_tlv:{encode:(e,t)=>{const{Err:r}=bn;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=qt(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");const i=n>127?qt(o.length/2|128):"";return qt(e)+i+o+t},decode(e,t){const{Err:r}=bn;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}=bn;if(e<mn)throw new t("integer: negative integers are not allowed");let r=qt(e);if(8&Number.parseInt(r[0],16)&&(r="00"+r),1&r.length)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){const{Err:t}=bn;if(128&e[0])throw new t("invalid signature integer: negative");if(0===e[0]&&!(128&e[1]))throw new t("invalid signature integer: unnecessary leading zero");return tr(e)}},toSig(e){const{Err:t,_int:r,_tlv:n}=bn,o=ir("signature",e),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");const{v:c,l:a}=n.decode(2,i),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){const{_tlv:t,_int:r}=bn,n=t.encode(2,r.encode(e.r))+t.encode(2,r.encode(e.s));return t.encode(48,n)}},mn=BigInt(0),vn=BigInt(1),En=(BigInt(2),BigInt(3));function xn(e){const t=function(e){const t=zr(e);return pr(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}(e),{Fp:r,n}=t,o=r.BYTES+1,i=2*r.BYTES+1;function s(e){return Ar(e,n)}function c(e){return Sr(e,n)}const{ProjectivePoint:a,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:h}=function(e){const t=function(e){const t=zr(e);pr(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:o}=t;if(r){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if("object"!=typeof r||"bigint"!=typeof r.beta||"function"!=typeof r.splitScalar)throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}(e),{Fp:r}=t,n=Tr(t.n,t.nBitLength),o=t.toBytes||((e,t,n)=>{const o=t.toAffine();return sr(Uint8Array.from([4]),r.toBytes(o.x),r.toBytes(o.y))}),i=t.fromBytes||(e=>{const t=e.subarray(1);return{x:r.fromBytes(t.subarray(0,r.BYTES)),y:r.fromBytes(t.subarray(r.BYTES,2*r.BYTES))}});function s(e){const{a:n,b:o}=t,i=r.sqr(e),s=r.mul(i,e);return r.add(r.add(s,r.mul(e,n)),o)}if(!r.eql(r.sqr(t.Gy),s(t.Gx)))throw new Error("bad generator point: equation left != right");function c(e){const{allowedPrivateKeyLengths:r,nByteLength:n,wrapPrivateKey:o,n:i}=t;if(r&&"bigint"!=typeof e){if(Wt(e)&&(e=Yt(e)),"string"!=typeof e||!r.includes(e.length))throw new Error("invalid private key");e=e.padStart(2*n,"0")}let s;try{s="bigint"==typeof e?e:tr(ir("private key",e,n))}catch(t){throw new Error("invalid private key, expected hex or "+n+" bytes, got "+typeof e)}return o&&(s=Ar(s,i)),fr("private key",s,vn,i),s}function a(e){if(!(e instanceof h))throw new Error("ProjectivePoint expected")}const f=yr(((e,t)=>{const{px:n,py:o,pz:i}=e;if(r.eql(i,r.ONE))return{x:n,y:o};const s=e.is0();null==t&&(t=s?r.ONE:r.inv(i));const c=r.mul(n,t),a=r.mul(o,t),f=r.mul(i,t);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(f,r.ONE))throw new Error("invZ was invalid");return{x:c,y:a}})),u=yr((e=>{if(e.is0()){if(t.allowInfinityPoint&&!r.is0(e.py))return;throw new Error("bad point: ZERO")}const{x:n,y:o}=e.toAffine();if(!r.isValid(n)||!r.isValid(o))throw new Error("bad point: x or y not FE");const i=r.sqr(o),c=s(n);if(!r.eql(i,c))throw new Error("bad point: equation left != right");if(!e.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0}));class h{constructor(e,t,n){if(null==e||!r.isValid(e))throw new Error("x required");if(null==t||!r.isValid(t)||r.is0(t))throw new Error("y required");if(null==n||!r.isValid(n))throw new Error("z required");this.px=e,this.py=t,this.pz=n,Object.freeze(this)}static fromAffine(e){const{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw new Error("invalid affine point");if(e instanceof h)throw new Error("projective point not allowed");const o=e=>r.eql(e,r.ZERO);return o(t)&&o(n)?h.ZERO:new h(t,n,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(e){const t=kr(r,e.map((e=>e.pz)));return e.map(((e,r)=>e.toAffine(t[r]))).map(h.fromAffine)}static fromHex(e){const t=h.fromAffine(i(ir("pointHex",e)));return t.assertValidity(),t}static fromPrivateKey(e){return h.BASE.multiply(c(e))}static msm(e,t){return Jr(h,n,e,t)}_setWindowSize(e){l.setWindowSize(this,e)}assertValidity(){u(this)}hasEvenY(){const{y:e}=this.toAffine();if(r.isOdd)return!r.isOdd(e);throw new Error("Field doesn't support isOdd")}equals(e){a(e);const{px:t,py:n,pz:o}=this,{px:i,py:s,pz:c}=e,f=r.eql(r.mul(t,c),r.mul(i,o)),u=r.eql(r.mul(n,c),r.mul(s,o));return f&&u}negate(){return new h(this.px,r.neg(this.py),this.pz)}double(){const{a:e,b:n}=t,o=r.mul(n,En),{px:i,py:s,pz:c}=this;let a=r.ZERO,f=r.ZERO,u=r.ZERO,d=r.mul(i,i),l=r.mul(s,s),p=r.mul(c,c),y=r.mul(i,s);return y=r.add(y,y),u=r.mul(i,c),u=r.add(u,u),a=r.mul(e,u),f=r.mul(o,p),f=r.add(a,f),a=r.sub(l,f),f=r.add(l,f),f=r.mul(a,f),a=r.mul(y,a),u=r.mul(o,u),p=r.mul(e,p),y=r.sub(d,p),y=r.mul(e,y),y=r.add(y,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,y),f=r.add(f,d),p=r.mul(s,c),p=r.add(p,p),d=r.mul(p,y),a=r.sub(a,d),u=r.mul(p,l),u=r.add(u,u),u=r.add(u,u),new h(a,f,u)}add(e){a(e);const{px:n,py:o,pz:i}=this,{px:s,py:c,pz:f}=e;let u=r.ZERO,d=r.ZERO,l=r.ZERO;const p=t.a,y=r.mul(t.b,En);let g=r.mul(n,s),w=r.mul(o,c),b=r.mul(i,f),m=r.add(n,o),v=r.add(s,c);m=r.mul(m,v),v=r.add(g,w),m=r.sub(m,v),v=r.add(n,i);let E=r.add(s,f);return v=r.mul(v,E),E=r.add(g,b),v=r.sub(v,E),E=r.add(o,i),u=r.add(c,f),E=r.mul(E,u),u=r.add(w,b),E=r.sub(E,u),l=r.mul(p,v),u=r.mul(y,b),l=r.add(u,l),u=r.sub(w,l),l=r.add(w,l),d=r.mul(u,l),w=r.add(g,g),w=r.add(w,g),b=r.mul(p,b),v=r.mul(y,v),w=r.add(w,b),b=r.sub(g,b),b=r.mul(p,b),v=r.add(v,b),g=r.mul(w,v),d=r.add(d,g),g=r.mul(E,v),u=r.mul(m,u),u=r.sub(u,g),g=r.mul(m,w),l=r.mul(E,l),l=r.add(l,g),new h(u,d,l)}subtract(e){return this.add(e.negate())}is0(){return this.equals(h.ZERO)}wNAF(e){return l.wNAFCached(this,e,h.normalizeZ)}multiplyUnsafe(e){const{endo:n,n:o}=t;fr("scalar",e,mn,o);const i=h.ZERO;if(e===mn)return i;if(this.is0()||e===vn)return this;if(!n||l.hasPrecomputes(this))return l.wNAFCachedUnsafe(this,e,h.normalizeZ);let{k1neg:s,k1:c,k2neg:a,k2:f}=n.splitScalar(e),u=i,d=i,p=this;for(;c>mn||f>mn;)c&vn&&(u=u.add(p)),f&vn&&(d=d.add(p)),p=p.double(),c>>=vn,f>>=vn;return s&&(u=u.negate()),a&&(d=d.negate()),d=new h(r.mul(d.px,n.beta),d.py,d.pz),u.add(d)}multiply(e){const{endo:n,n:o}=t;let i,s;if(fr("scalar",e,vn,o),n){const{k1neg:t,k1:o,k2neg:c,k2:a}=n.splitScalar(e);let{p:f,f:u}=this.wNAF(o),{p:d,f:p}=this.wNAF(a);f=l.constTimeNegate(t,f),d=l.constTimeNegate(c,d),d=new h(r.mul(d.px,n.beta),d.py,d.pz),i=f.add(d),s=u.add(p)}else{const{p:t,f:r}=this.wNAF(e);i=t,s=r}return h.normalizeZ([i,s])[0]}multiplyAndAddUnsafe(e,t,r){const n=h.BASE,o=(e,t)=>t!==mn&&t!==vn&&e.equals(n)?e.multiply(t):e.multiplyUnsafe(t),i=o(this,t).add(o(e,r));return i.is0()?void 0:i}toAffine(e){return f(this,e)}isTorsionFree(){const{h:e,isTorsionFree:r}=t;if(e===vn)return!0;if(r)return r(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:e,clearCofactor:r}=t;return e===vn?this:r?r(h,this):this.multiplyUnsafe(t.h)}toRawBytes(e=!0){return Mt("isCompressed",e),this.assertValidity(),o(h,this,e)}toHex(e=!0){return Mt("isCompressed",e),Yt(this.toRawBytes(e))}}h.BASE=new h(t.Gx,t.Gy,r.ONE),h.ZERO=new h(r.ZERO,r.ONE,r.ZERO);const d=t.nBitLength,l=Hr(h,t.endo?Math.ceil(d/2):d);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:function(e){return ar(e,vn,t.n)}}}({...t,toBytes(e,t,n){const o=t.toAffine(),i=r.toBytes(o.x),s=sr;return Mt("isCompressed",n),n?s(Uint8Array.from([t.hasEvenY()?2:3]),i):s(Uint8Array.from([4]),i,r.toBytes(o.y))},fromBytes(e){const t=e.length,n=e[0],s=e.subarray(1);if(t!==o||2!==n&&3!==n){if(t===i&&4===n)return{x:r.fromBytes(s.subarray(0,r.BYTES)),y:r.fromBytes(s.subarray(r.BYTES,2*r.BYTES))};throw new Error("invalid Point, expected length of "+o+", or uncompressed "+i+", got "+t)}{const e=tr(s);if(!ar(e,vn,r.ORDER))throw new Error("Point is not on curve");const t=u(e);let o;try{o=r.sqrt(t)}catch(e){const t=e instanceof Error?": "+e.message:"";throw new Error("Point is not on curve"+t)}return!(1&~n)!=((o&vn)===vn)&&(o=r.neg(o)),{x:e,y:o}}}}),d=e=>Yt(nr(e,t.nByteLength));function l(e){return e>n>>vn}const p=(e,t,r)=>tr(e.slice(t,r));class y{constructor(e,t,r){fr("r",e,vn,n),fr("s",t,vn,n),this.r=e,this.s=t,null!=r&&(this.recovery=r),Object.freeze(this)}static fromCompact(e){const r=t.nByteLength;return e=ir("compactSignature",e,2*r),new y(p(e,0,r),p(e,r,2*r))}static fromDER(e){const{r:t,s:r}=bn.toSig(ir("DER",e));return new y(t,r)}assertValidity(){}addRecoveryBit(e){return new y(this.r,this.s,e)}recoverPublicKey(e){const{r:n,s:o,recovery:i}=this,f=m(ir("msgHash",e));if(null==i||![0,1,2,3].includes(i))throw new Error("recovery id invalid");const u=2===i||3===i?n+t.n:n;if(u>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const h=1&i?"03":"02",l=a.fromHex(h+d(u)),p=c(u),y=s(-f*p),g=s(o*p),w=a.BASE.multiplyAndAddUnsafe(l,y,g);if(!w)throw new Error("point at infinify");return w.assertValidity(),w}hasHighS(){return l(this.s)}normalizeS(){return this.hasHighS()?new y(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return er(this.toDERHex())}toDERHex(){return bn.hexFromSig(this)}toCompactRawBytes(){return er(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const g={isValidPrivateKey(e){try{return f(e),!0}catch(e){return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const e=Rr(t.n);return function(e,t,r=!1){const n=e.length,o=Or(t),i=Rr(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);const s=Ar(r?rr(e):tr(e),t-wr)+wr;return r?or(s,o):nr(s,o)}(t.randomBytes(e),t.n)},precompute:(e=8,t=a.BASE)=>(t._setWindowSize(e),t.multiply(BigInt(3)),t)};function w(e){const t=Wt(e),r="string"==typeof e,n=(t||r)&&e.length;return t?n===o||n===i:r?n===2*o||n===2*i:e instanceof a}const b=t.bits2int||function(e){if(e.length>8192)throw new Error("input is too large");const r=tr(e),n=8*e.length-t.nBitLength;return n>0?r>>BigInt(n):r},m=t.bits2int_modN||function(e){return s(b(e))},v=ur(t.nBitLength);function E(e){return fr("num < 2^"+t.nBitLength,e,mn,v),nr(e,t.nByteLength)}const x={lowS:t.lowS,prehash:!1},A={lowS:t.lowS,prehash:!1};return a.BASE._setWindowSize(8),{CURVE:t,getPublicKey:function(e,t=!0){return a.fromPrivateKey(e).toRawBytes(t)},getSharedSecret:function(e,t,r=!0){if(w(e))throw new Error("first arg must be private key");if(!w(t))throw new Error("second arg must be public key");return a.fromHex(t).multiply(f(e)).toRawBytes(r)},sign:function(e,n,o=x){const{seed:i,k2sig:u}=function(e,n,o=x){if(["recovered","canonical"].some((e=>e in o)))throw new Error("sign() legacy options not supported");const{hash:i,randomBytes:u}=t;let{lowS:d,prehash:p,extraEntropy:g}=o;null==d&&(d=!0),e=ir("msgHash",e),gn(o),p&&(e=ir("prehashed msgHash",i(e)));const w=m(e),v=f(n),A=[E(v),E(w)];if(null!=g&&!1!==g){const e=!0===g?u(r.BYTES):g;A.push(ir("extraEntropy",e))}const B=sr(...A),S=w;return{seed:B,k2sig:function(e){const t=b(e);if(!h(t))return;const r=c(t),n=a.BASE.multiply(t).toAffine(),o=s(n.x);if(o===mn)return;const i=s(r*s(S+o*v));if(i===mn)return;let f=(n.x===o?0:2)|Number(n.y&vn),u=i;return d&&l(i)&&(u=function(e){return l(e)?s(-e):e}(i),f^=1),new y(o,u,f)}}}(e,n,o),d=t,p=function(e,t,r){if("number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");if("function"!=typeof r)throw new Error("hmacFn must be a function");let n=hr(e),o=hr(e),i=0;const s=()=>{n.fill(1),o.fill(0),i=0},c=(...e)=>r(o,n,...e),a=(e=hr(0))=>{o=c(dr([0]),e),n=c(),0!==e.length&&(o=c(dr([1]),e),n=c())},f=()=>{if(i++>=1e3)throw new Error("drbg: tried 1000 values");let e=0;const r=[];for(;e<t;){n=c();const t=n.slice();r.push(t),e+=n.length}return sr(...r)};return(e,t)=>{let r;for(s(),a(e);!(r=t(f()));)a();return s(),r}}(d.hash.outputLen,d.nByteLength,d.hmac);return p(i,u)},verify:function(e,r,n,o=A){const i=e;r=ir("msgHash",r),n=ir("publicKey",n);const{lowS:f,prehash:u,format:h}=o;if(gn(o),"strict"in o)throw new Error("options.strict was renamed to lowS");if(void 0!==h&&"compact"!==h&&"der"!==h)throw new Error("format must be compact or der");const d="string"==typeof i||Wt(i),l=!d&&!h&&"object"==typeof i&&null!==i&&"bigint"==typeof i.r&&"bigint"==typeof i.s;if(!d&&!l)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let p,g;try{if(l&&(p=new y(i.r,i.s)),d){try{"compact"!==h&&(p=y.fromDER(i))}catch(e){if(!(e instanceof bn.Err))throw e}p||"der"===h||(p=y.fromCompact(i))}g=a.fromHex(n)}catch(e){return!1}if(!p)return!1;if(f&&p.hasHighS())return!1;u&&(r=t.hash(r));const{r:w,s:b}=p,v=m(r),E=c(b),x=s(v*E),B=s(w*E),S=a.BASE.multiplyAndAddUnsafe(g,x,B)?.toAffine();return!!S&&s(S.x)===w},ProjectivePoint:a,Signature:y,utils:g}}function An(e){return{hash:e,hmac:(t,...r)=>yn(e,t,function(...e){let t=0;for(let r=0;r<e.length;r++){const n=e[r];Ze(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}(...r)),randomBytes:ct}}function Bn(e,t){const r=t=>xn({...e,...An(t)});return{...r(t),create:r}}BigInt(4);const Sn=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),In=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),kn=BigInt(1),Pn=BigInt(2),Un=(e,t)=>(e+t/Pn)/t;const Tn=Tr(Sn,void 0,void 0,{sqrt:function(e){const t=Sn,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,u=f*f*e%t,h=Br(u,r,t)*u%t,d=Br(h,r,t)*u%t,l=Br(d,Pn,t)*f%t,p=Br(l,o,t)*l%t,y=Br(p,i,t)*p%t,g=Br(y,c,t)*y%t,w=Br(g,a,t)*g%t,b=Br(w,c,t)*y%t,m=Br(b,r,t)*u%t,v=Br(m,s,t)*p%t,E=Br(v,n,t)*f%t,x=Br(E,Pn,t);if(!Tn.eql(Tn.sqr(x),e))throw new Error("Cannot find square root");return x}}),On=Bn({a:BigInt(0),b:BigInt(7),Fp:Tn,n:In,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:e=>{const t=In,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-kn*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=r,s=BigInt("0x100000000000000000000000000000000"),c=Un(i*e,t),a=Un(-n*e,t);let f=Ar(e-c*r-a*o,t),u=Ar(-c*n-a*i,t);const h=f>s,d=u>s;if(h&&(f=t-f),d&&(u=t-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+e);return{k1neg:h,k1:f,k2neg:d,k2:u}}}},_t);BigInt(0),On.ProjectivePoint;const Rn=Tr(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),Nn=Bn({a:Rn.create(BigInt("-3")),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Fp:Rn,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},_t),Kn=Tr(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),Ln=(Bn({a:Kn.create(BigInt("-3")),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Fp:Kn,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},Ht),Tr(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))),Cn=(Bn({a:Ln.create(BigInt("-3")),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Fp:Ln,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},Vt),Nn),Dn=_t,jn=Uint8Array.from([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),$n=(()=>Uint8Array.from(new Array(16).fill(0).map(((e,t)=>t))))(),_n=(()=>$n.map((e=>(9*e+5)%16)))(),Vn=(()=>{const e=[[$n],[_n]];for(let t=0;t<4;t++)for(let r of e)r.push(r[t].map((e=>jn[e])));return e})(),Hn=(()=>Vn[0])(),Jn=(()=>Vn[1])(),zn=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((e=>Uint8Array.from(e))),Wn=Hn.map(((e,t)=>e.map((e=>zn[t][e])))),Fn=Jn.map(((e,t)=>e.map((e=>zn[t][e])))),Mn=Uint32Array.from([0,1518500249,1859775393,2400959708,2840853838]),qn=Uint32Array.from([1352829926,1548603684,1836072691,2053994217,0]);function Gn(e,t,r,n){return 0===e?t^r^n:1===e?t&r|~t&n:2===e?(t|~r)^n:3===e?t&n|r&~n:t^(r|~n)}const Zn=new Uint32Array(16);class Xn extends ft{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:e,h1:t,h2:r,h3:n,h4:o}=this;return[e,t,r,n,o]}set(e,t,r,n,o){this.h0=0|e,this.h1=0|t,this.h2=0|r,this.h3=0|n,this.h4=0|o}process(e,t){for(let r=0;r<16;r++,t+=4)Zn[r]=e.getUint32(t,!0);let r=0|this.h0,n=r,o=0|this.h1,i=o,s=0|this.h2,c=s,a=0|this.h3,f=a,u=0|this.h4,h=u;for(let e=0;e<5;e++){const t=4-e,d=Mn[e],l=qn[e],p=Hn[e],y=Jn[e],g=Wn[e],w=Fn[e];for(let t=0;t<16;t++){const n=rt(r+Gn(e,o,s,a)+Zn[p[t]]+d,g[t])+u|0;r=u,u=a,a=0|rt(s,10),s=o,o=n}for(let e=0;e<16;e++){const r=rt(n+Gn(t,i,c,f)+Zn[y[e]]+l,w[e])+h|0;n=h,h=f,f=0|rt(c,10),c=i,i=r}}this.set(this.h1+s+f|0,this.h2+a+h|0,this.h3+u+n|0,this.h4+r+i|0,this.h0+o+c|0)}roundClean(){Qe(Zn)}destroy(){this.destroyed=!0,Qe(this.buffer),this.set(0,0,0,0,0)}}const Yn=st((()=>new Xn)),Qn=BigInt(0),eo=BigInt(1),to=BigInt(2),ro=BigInt(7),no=BigInt(256),oo=BigInt(113),io=[],so=[],co=[];for(let e=0,t=eo,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],io.push(2*(5*n+r)),so.push((e+1)*(e+2)/2%64);let o=Qn;for(let e=0;e<7;e++)t=(t<<eo^(t>>ro)*oo)%no,t&to&&(o^=eo<<(eo<<BigInt(e))-eo);co.push(o)}const ao=gt(co,!0),fo=ao[0],uo=ao[1],ho=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),lo=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class po extends it{constructor(e,t,r,n=!1,o=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=o,Ge(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){nt(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,o=(t+2)%10,i=r[o],s=r[o+1],c=ho(i,s,1)^r[n],a=lo(i,s,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=c,e[t+r+1]^=a}let t=e[2],o=e[3];for(let r=0;r<24;r++){const n=so[r],i=ho(t,o,n),s=lo(t,o,n),c=io[r];t=e[c],o=e[c+1],e[c]=i,e[c+1]=s}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=fo[n],e[1]^=uo[n]}Qe(r)}(this.state32,this.rounds),nt(this.state32),this.posOut=0,this.pos=0}update(e){Xe(this),Ze(e=ot(e));const{blockLen:t,state:r}=this,n=e.length;for(let o=0;o<n;){const i=Math.min(t-this.pos,n-o);for(let t=0;t<i;t++)r[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,128&t&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){Xe(this,!1),Ze(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,o=e.length;n<o;){this.posOut>=r&&this.keccak();const i=Math.min(r-this.posOut,o-n);e.set(t.subarray(this.posOut,this.posOut+i),n),this.posOut+=i,n+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Ge(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ye(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,Qe(this.state)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:o,enableXOF:i}=this;return e||(e=new po(t,r,n,i,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=n,e.enableXOF=i,e.destroyed=this.destroyed,e}}const yo=(()=>{return e=1,t=136,r=32,st((()=>new po(t,e,r)));var e,t,r})();var go=r(341);const wo="(?:[a-zA-Z0-9._-]|(?:%[0-9a-fA-F]{2}))",bo="[a-zA-Z0-9_.:%-]",mo=new RegExp(`^did:([a-z0-9]+):((?:${wo}*:)*(${wo}+))((;${bo}+=${bo}*)*)(/[^#?]*)?([?][^#]*)?(#.*)?$`);function vo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Eo(e,...t){if(!vo(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 xo(e,t){return!!Array.isArray(t)&&(0===t.length||(e?t.every((e=>"string"==typeof e)):t.every((e=>Number.isSafeInteger(e)))))}function Ao(e){if("function"!=typeof e)throw new Error("function expected");return!0}function Bo(e,t){if("string"!=typeof t)throw new Error(`${e}: string expected`);return!0}function So(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Io(e){if(!Array.isArray(e))throw new Error("array expected")}function ko(e,t){if(!xo(!0,t))throw new Error(`${e}: array of strings expected`)}function Po(e,t){if(!xo(!1,t))throw new Error(`${e}: array of numbers expected`)}function Uo(...e){const t=e=>e,r=(e,t)=>r=>e(t(r));return{encode:e.map((e=>e.encode)).reduceRight(r,t),decode:e.map((e=>e.decode)).reduce(r,t)}}function To(e){const t="string"==typeof e?e.split(""):e,r=t.length;ko("alphabet",t);const n=new Map(t.map(((e,t)=>[e,t])));return{encode:n=>(Io(n),n.map((n=>{if(!Number.isSafeInteger(n)||n<0||n>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${n}". Allowed: ${e}`);return t[n]}))),decode:t=>(Io(t),t.map((t=>{Bo("alphabet.decode",t);const r=n.get(t);if(void 0===r)throw new Error(`Unknown letter: "${t}". Allowed: ${e}`);return r})))}}function Oo(e=""){return Bo("join",e),{encode:t=>(ko("join.decode",t),t.join(e)),decode:t=>(Bo("join.decode",t),t.split(e))}}function Ro(e,t="="){return So(e),Bo("padding",t),{encode(r){for(ko("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){ko("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8==0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}function No(e){return Ao(e),{encode:e=>e,decode:t=>e(t)}}function Ko(e,t,r){if(t<2)throw new Error(`convertRadix: invalid from=${t}, base cannot be less than 2`);if(r<2)throw new Error(`convertRadix: invalid to=${r}, base cannot be less than 2`);if(Io(e),!e.length)return[];let n=0;const o=[],i=Array.from(e,(e=>{if(So(e),e<0||e>=t)throw new Error(`invalid integer: ${e}`);return e})),s=i.length;for(;;){let e=0,c=!0;for(let o=n;o<s;o++){const s=i[o],a=t*e,f=a+s;if(!Number.isSafeInteger(f)||a/t!==e||f-s!==a)throw new Error("convertRadix: carry overflow");const u=f/r;e=f%r;const h=Math.floor(u);if(i[o]=h,!Number.isSafeInteger(h)||h*r+e!==f)throw new Error("convertRadix: carry overflow");c&&(h?c=!1:n=o)}if(o.push(e),c)break}for(let t=0;t<e.length-1&&0===e[t];t++)o.push(0);return o.reverse()}const Lo=(e,t)=>0===t?e:Lo(t,e%t),Co=(e,t)=>e+(t-Lo(e,t)),Do=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function jo(e,t,r,n){if(Io(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Co(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${Co(t,r)}`);let o=0,i=0;const s=Do[t],c=Do[r]-1,a=[];for(const n of e){if(So(n),n>=s)throw new Error(`convertRadix2: invalid data word=${n} from=${t}`);if(o=o<<t|n,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=r;i-=r)a.push((o>>i-r&c)>>>0);const e=Do[i];if(void 0===e)throw new Error("invalid carry");o&=e-1}if(o=o<<r-i&c,!n&&i>=t)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&a.push(o>>>0),a}function $o(e,t=!1){if(So(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Co(8,e)>32||Co(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!vo(r))throw new Error("radix2.encode input should be Uint8Array");return jo(Array.from(r),8,e,!t)},decode:r=>(Po("radix2.decode",r),Uint8Array.from(jo(r,e,8,t)))}}function _o(e){return Ao(e),function(...t){try{return e.apply(null,t)}catch(e){}}}Uo($o(4),To("0123456789ABCDEF"),Oo("")),Uo($o(5),To("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Ro(5),Oo(""));const Vo=(Uo($o(5),To("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Oo("")),Uo($o(5),To("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Ro(5),Oo("")),Uo($o(5),To("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Oo("")),Uo($o(5),To("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),Oo(""),No((e=>e.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")))),(()=>"function"==typeof Uint8Array.from([]).toBase64&&"function"==typeof Uint8Array.fromBase64)()),Ho=(Vo||Uo($o(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Ro(6),Oo("")),Uo($o(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Oo("")),Vo||Uo($o(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Ro(6),Oo("")),Uo($o(6),To("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Oo("")),e=>{return Uo((So(t=58),{encode:e=>{if(!vo(e))throw new Error("radix.encode input should be Uint8Array");return Ko(Array.from(e),256,t)},decode:e=>(Po("radix.decode",e),Uint8Array.from(Ko(e,t,256)))}),To(e),Oo(""));var t}),Jo=(Ho("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),Ho("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),Ho("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"),Uo(To("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Oo(""))),zo=[996825010,642813549,513874426,1027748829,705979059];function Wo(e){const t=e>>25;let r=(33554431&e)<<5;for(let e=0;e<zo.length;e++)1==(t>>e&1)&&(r^=zo[e]);return r}function Fo(e,t,r=1){const n=e.length;let o=1;for(let t=0;t<n;t++){const r=e.charCodeAt(t);if(r<33||r>126)throw new Error(`Invalid prefix (${e})`);o=Wo(o)^r>>5}o=Wo(o);for(let t=0;t<n;t++)o=Wo(o)^31&e.charCodeAt(t);for(let e of t)o=Wo(o)^e;for(let e=0;e<6;e++)o=Wo(o);return o^=r,Jo.encode(jo([o%Do[30]],30,5,!1))}function Mo(e){const t="bech32"===e?1:734539939,r=$o(5),n=r.decode,o=r.encode,i=_o(n);function s(e,r,n=90){Bo("bech32.encode prefix",e),vo(r)&&(r=Array.from(r)),Po("bech32.encode",r);const o=e.length;if(0===o)throw new TypeError(`Invalid prefix length ${o}`);const i=o+7+r.length;if(!1!==n&&i>n)throw new TypeError(`Length ${i} exceeds limit ${n}`);const s=e.toLowerCase(),c=Fo(s,r,t);return`${s}1${Jo.encode(r)}${c}`}function c(e,r=90){Bo("bech32.decode input",e);const n=e.length;if(n<8||!1!==r&&n>r)throw new TypeError(`invalid string length: ${n} (${e}). Expected (8..${r})`);const o=e.toLowerCase();if(e!==o&&e!==e.toUpperCase())throw new Error("String must be lowercase or uppercase");const i=o.lastIndexOf("1");if(0===i||-1===i)throw new Error('Letter "1" must be present between prefix and data only');const s=o.slice(0,i),c=o.slice(i+1);if(c.length<6)throw new Error("Data must be at least 6 characters long");const a=Jo.decode(c).slice(0,-6),f=Fo(s,a,t);if(!c.endsWith(f))throw new Error(`Invalid checksum in ${e}: expected "${f}"`);return{prefix:s,words:a}}return{encode:s,decode:c,encodeFromBytes:function(e,t){return s(e,o(t))},decodeToBytes:function(e){const{prefix:t,words:r}=c(e,!1);return{prefix:t,words:r,bytes:n(r)}},decodeUnsafe:_o(c),fromWords:n,fromWordsUnsafe:i,toWords:o}}const qo=Mo("bech32");Mo("bech32m");function Go(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function Zo(e){if("boolean"!=typeof e)throw new Error(`boolean expected, not ${e}`)}function Xo(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Yo(e,...t){if(!Go(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 Qo(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 ei(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function ti(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)()||Uo($o(4),To("0123456789abcdef"),Oo(""),No((e=>{if("string"!=typeof e||e.length%2!=0)throw new TypeError(`hex.decode: expected string, got ${typeof e} with length ${e.length}`);return e.toLowerCase()})));const ri=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])();function ni(e){if("string"==typeof e)e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e);else{if(!Go(e))throw new Error("Uint8Array expected, got "+typeof e);e=ci(e)}return e}const oi=(e,t)=>{function r(r,...n){if(Yo(r),!ri)throw new Error("Non little-endian hardware is not yet supported");if(void 0!==e.nonceLength){const t=n[0];if(!t)throw new Error("nonce / iv required");e.varSizeNonce?Yo(t):Yo(t,e.nonceLength)}const o=e.tagLength;o&&void 0!==n[1]&&Yo(n[1]);const i=t(r,...n),s=(e,t)=>{if(void 0!==t){if(2!==e)throw new Error("cipher output not supported");Yo(t)}};let c=!1;return{encrypt(e,t){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Yo(e),s(i.encrypt.length,t),i.encrypt(e,t)},decrypt(e,t){if(Yo(e),o&&e.length<o)throw new Error("invalid ciphertext length: smaller than tagLength="+o);return s(i.decrypt.length,t),i.decrypt(e,t)}}}return Object.assign(r,e),r};function ii(e,t,r=!0){if(void 0===t)return new Uint8Array(e);if(t.length!==e)throw new Error("invalid output length, expected "+e+", got: "+t.length);if(r&&t.byteOffset%4!=0)throw new Error("invalid output, must be aligned");return t}function si(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),c=Number(r&i),a=n?4:0,f=n?0:4;e.setUint32(t+a,s,n),e.setUint32(t+f,c,n)}function ci(e){return Uint8Array.from(e)}const ai=e=>Uint8Array.from(e.split("").map((e=>e.charCodeAt(0)))),fi=ai("expand 16-byte k"),ui=ai("expand 32-byte k"),hi=ei(fi),di=ei(ui);function li(e,t){return e<<t|e>>>32-t}function pi(e){return e.byteOffset%4==0}const yi=2**32-1,gi=new Uint32Array;function wi(e,t){const{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=function(e,t){if(null==t||"object"!=typeof t)throw new Error("options must be defined");return Object.assign({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t)}(0,t);if("function"!=typeof e)throw new Error("core must be a function");return Xo(o),Xo(s),Zo(i),Zo(r),(t,c,a,f,u=0)=>{Yo(t),Yo(c),Yo(a);const h=a.length;if(void 0===f&&(f=new Uint8Array(h)),Yo(f),Xo(u),u<0||u>=yi)throw new Error("arx: counter overflow");if(f.length<h)throw new Error(`arx: output (${f.length}) is shorter than data (${h})`);const d=[];let l,p,y=t.length;if(32===y)d.push(l=ci(t)),p=di;else{if(16!==y||!r)throw new Error(`arx: invalid 32-byte key, got length=${y}`);l=new Uint8Array(32),l.set(t),l.set(t,16),p=hi,d.push(l)}pi(c)||d.push(c=ci(c));const g=ei(l);if(n){if(24!==c.length)throw new Error("arx: extended nonce must be 24 bytes");n(p,g,ei(c.subarray(0,16)),g),c=c.subarray(16)}const w=16-o;if(w!==c.length)throw new Error(`arx: nonce must be ${w} or 16 bytes`);if(12!==w){const e=new Uint8Array(12);e.set(c,i?0:12-c.length),c=e,d.push(c)}const b=ei(c);return function(e,t,r,n,o,i,s,c){const a=o.length,f=new Uint8Array(64),u=ei(f),h=pi(o)&&pi(i),d=h?ei(o):gi,l=h?ei(i):gi;for(let p=0;p<a;s++){if(e(t,r,n,u,s,c),s>=yi)throw new Error("arx: counter overflow");const y=Math.min(64,a-p);if(h&&64===y){const e=p/4;if(p%4!=0)throw new Error("arx: invalid block position");for(let t,r=0;r<16;r++)t=e+r,l[t]=d[t]^u[r];p+=64}else{for(let e,t=0;t<y;t++)e=p+t,i[e]=o[e]^f[t];p+=y}}}(e,p,g,b,a,f,u,s),ti(...d),f}}const bi=(e,t)=>255&e[t++]|(255&e[t++])<<8;class mi{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,Yo(e=ni(e),32);const t=bi(e,0),r=bi(e,2),n=bi(e,4),o=bi(e,6),i=bi(e,8),s=bi(e,10),c=bi(e,12),a=bi(e,14);this.r[0]=8191&t,this.r[1]=8191&(t>>>13|r<<3),this.r[2]=7939&(r>>>10|n<<6),this.r[3]=8191&(n>>>7|o<<9),this.r[4]=255&(o>>>4|i<<12),this.r[5]=i>>>1&8190,this.r[6]=8191&(i>>>14|s<<2),this.r[7]=8065&(s>>>11|c<<5),this.r[8]=8191&(c>>>8|a<<8),this.r[9]=a>>>5&127;for(let t=0;t<8;t++)this.pad[t]=bi(e,16+2*t)}process(e,t,r=!1){const n=r?0:2048,{h:o,r:i}=this,s=i[0],c=i[1],a=i[2],f=i[3],u=i[4],h=i[5],d=i[6],l=i[7],p=i[8],y=i[9],g=bi(e,t+0),w=bi(e,t+2),b=bi(e,t+4),m=bi(e,t+6),v=bi(e,t+8),E=bi(e,t+10),x=bi(e,t+12),A=bi(e,t+14);let B=o[0]+(8191&g),S=o[1]+(8191&(g>>>13|w<<3)),I=o[2]+(8191&(w>>>10|b<<6)),k=o[3]+(8191&(b>>>7|m<<9)),P=o[4]+(8191&(m>>>4|v<<12)),U=o[5]+(v>>>1&8191),T=o[6]+(8191&(v>>>14|E<<2)),O=o[7]+(8191&(E>>>11|x<<5)),R=o[8]+(8191&(x>>>8|A<<8)),N=o[9]+(A>>>5|n),K=0,L=K+B*s+S*(5*y)+I*(5*p)+k*(5*l)+P*(5*d);K=L>>>13,L&=8191,L+=U*(5*h)+T*(5*u)+O*(5*f)+R*(5*a)+N*(5*c),K+=L>>>13,L&=8191;let C=K+B*c+S*s+I*(5*y)+k*(5*p)+P*(5*l);K=C>>>13,C&=8191,C+=U*(5*d)+T*(5*h)+O*(5*u)+R*(5*f)+N*(5*a),K+=C>>>13,C&=8191;let D=K+B*a+S*c+I*s+k*(5*y)+P*(5*p);K=D>>>13,D&=8191,D+=U*(5*l)+T*(5*d)+O*(5*h)+R*(5*u)+N*(5*f),K+=D>>>13,D&=8191;let j=K+B*f+S*a+I*c+k*s+P*(5*y);K=j>>>13,j&=8191,j+=U*(5*p)+T*(5*l)+O*(5*d)+R*(5*h)+N*(5*u),K+=j>>>13,j&=8191;let $=K+B*u+S*f+I*a+k*c+P*s;K=$>>>13,$&=8191,$+=U*(5*y)+T*(5*p)+O*(5*l)+R*(5*d)+N*(5*h),K+=$>>>13,$&=8191;let _=K+B*h+S*u+I*f+k*a+P*c;K=_>>>13,_&=8191,_+=U*s+T*(5*y)+O*(5*p)+R*(5*l)+N*(5*d),K+=_>>>13,_&=8191;let V=K+B*d+S*h+I*u+k*f+P*a;K=V>>>13,V&=8191,V+=U*c+T*s+O*(5*y)+R*(5*p)+N*(5*l),K+=V>>>13,V&=8191;let H=K+B*l+S*d+I*h+k*u+P*f;K=H>>>13,H&=8191,H+=U*a+T*c+O*s+R*(5*y)+N*(5*p),K+=H>>>13,H&=8191;let J=K+B*p+S*l+I*d+k*h+P*u;K=J>>>13,J&=8191,J+=U*f+T*a+O*c+R*s+N*(5*y),K+=J>>>13,J&=8191;let z=K+B*y+S*p+I*l+k*d+P*h;K=z>>>13,z&=8191,z+=U*u+T*f+O*a+R*c+N*s,K+=z>>>13,z&=8191,K=(K<<2)+K|0,K=K+L|0,L=8191&K,K>>>=13,C+=K,o[0]=L,o[1]=C,o[2]=D,o[3]=j,o[4]=$,o[5]=_,o[6]=V,o[7]=H,o[8]=J,o[9]=z}finalize(){const{h:e,pad:t}=this,r=new Uint16Array(10);let n=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=n,n=e[t]>>>13,e[t]&=8191;e[0]+=5*n,n=e[0]>>>13,e[0]&=8191,e[1]+=n,n=e[1]>>>13,e[1]&=8191,e[2]+=n,r[0]=e[0]+5,n=r[0]>>>13,r[0]&=8191;for(let t=1;t<10;t++)r[t]=e[t]+n,n=r[t]>>>13,r[t]&=8191;r[9]-=8192;let o=(1^n)-1;for(let e=0;e<10;e++)r[e]&=o;o=~o;for(let t=0;t<10;t++)e[t]=e[t]&o|r[t];e[0]=65535&(e[0]|e[1]<<13),e[1]=65535&(e[1]>>>3|e[2]<<10),e[2]=65535&(e[2]>>>6|e[3]<<7),e[3]=65535&(e[3]>>>9|e[4]<<4),e[4]=65535&(e[4]>>>12|e[5]<<1|e[6]<<14),e[5]=65535&(e[6]>>>2|e[7]<<11),e[6]=65535&(e[7]>>>5|e[8]<<8),e[7]=65535&(e[8]>>>8|e[9]<<5);let i=e[0]+t[0];e[0]=65535&i;for(let r=1;r<8;r++)i=(e[r]+t[r]|0)+(i>>>16)|0,e[r]=65535&i;ti(r)}update(e){Qo(this),Yo(e=ni(e));const{buffer:t,blockLen:r}=this,n=e.length;for(let o=0;o<n;){const i=Math.min(r-this.pos,n-o);if(i!==r)t.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0,!1),this.pos=0);else for(;r<=n-o;o+=r)this.process(e,o)}return this}destroy(){ti(this.h,this.r,this.buffer,this.pad)}digestInto(e){Qo(this),function(e,t){Yo(e);const r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}(e,this),this.finished=!0;const{buffer:t,h:r}=this;let{pos:n}=this;if(n){for(t[n++]=1;n<16;n++)t[n]=0;this.process(t,0,!0)}this.finalize();let o=0;for(let t=0;t<8;t++)e[o++]=r[t]>>>0,e[o++]=r[t]>>>8;return e}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const r=e.slice(0,t);return this.destroy(),r}}const vi=function(e){const t=(t,r)=>e(r).update(ni(t)).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=t=>e(t),t}((e=>new mi(e)));function Ei(e,t,r,n,o,i=20){let s=e[0],c=e[1],a=e[2],f=e[3],u=t[0],h=t[1],d=t[2],l=t[3],p=t[4],y=t[5],g=t[6],w=t[7],b=o,m=r[0],v=r[1],E=r[2],x=s,A=c,B=a,S=f,I=u,k=h,P=d,U=l,T=p,O=y,R=g,N=w,K=b,L=m,C=v,D=E;for(let e=0;e<i;e+=2)x=x+I|0,K=li(K^x,16),T=T+K|0,I=li(I^T,12),x=x+I|0,K=li(K^x,8),T=T+K|0,I=li(I^T,7),A=A+k|0,L=li(L^A,16),O=O+L|0,k=li(k^O,12),A=A+k|0,L=li(L^A,8),O=O+L|0,k=li(k^O,7),B=B+P|0,C=li(C^B,16),R=R+C|0,P=li(P^R,12),B=B+P|0,C=li(C^B,8),R=R+C|0,P=li(P^R,7),S=S+U|0,D=li(D^S,16),N=N+D|0,U=li(U^N,12),S=S+U|0,D=li(D^S,8),N=N+D|0,U=li(U^N,7),x=x+k|0,D=li(D^x,16),R=R+D|0,k=li(k^R,12),x=x+k|0,D=li(D^x,8),R=R+D|0,k=li(k^R,7),A=A+P|0,K=li(K^A,16),N=N+K|0,P=li(P^N,12),A=A+P|0,K=li(K^A,8),N=N+K|0,P=li(P^N,7),B=B+U|0,L=li(L^B,16),T=T+L|0,U=li(U^T,12),B=B+U|0,L=li(L^B,8),T=T+L|0,U=li(U^T,7),S=S+I|0,C=li(C^S,16),O=O+C|0,I=li(I^O,12),S=S+I|0,C=li(C^S,8),O=O+C|0,I=li(I^O,7);let j=0;n[j++]=s+x|0,n[j++]=c+A|0,n[j++]=a+B|0,n[j++]=f+S|0,n[j++]=u+I|0,n[j++]=h+k|0,n[j++]=d+P|0,n[j++]=l+U|0,n[j++]=p+T|0,n[j++]=y+O|0,n[j++]=g+R|0,n[j++]=w+N|0,n[j++]=b+K|0,n[j++]=m+L|0,n[j++]=v+C|0,n[j++]=E+D|0}const xi=wi(Ei,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Ai=wi(Ei,{counterRight:!1,counterLength:8,extendNonceFn:function(e,t,r,n){let o=e[0],i=e[1],s=e[2],c=e[3],a=t[0],f=t[1],u=t[2],h=t[3],d=t[4],l=t[5],p=t[6],y=t[7],g=r[0],w=r[1],b=r[2],m=r[3];for(let e=0;e<20;e+=2)o=o+a|0,g=li(g^o,16),d=d+g|0,a=li(a^d,12),o=o+a|0,g=li(g^o,8),d=d+g|0,a=li(a^d,7),i=i+f|0,w=li(w^i,16),l=l+w|0,f=li(f^l,12),i=i+f|0,w=li(w^i,8),l=l+w|0,f=li(f^l,7),s=s+u|0,b=li(b^s,16),p=p+b|0,u=li(u^p,12),s=s+u|0,b=li(b^s,8),p=p+b|0,u=li(u^p,7),c=c+h|0,m=li(m^c,16),y=y+m|0,h=li(h^y,12),c=c+h|0,m=li(m^c,8),y=y+m|0,h=li(h^y,7),o=o+f|0,m=li(m^o,16),p=p+m|0,f=li(f^p,12),o=o+f|0,m=li(m^o,8),p=p+m|0,f=li(f^p,7),i=i+u|0,g=li(g^i,16),y=y+g|0,u=li(u^y,12),i=i+u|0,g=li(g^i,8),y=y+g|0,u=li(u^y,7),s=s+h|0,w=li(w^s,16),d=d+w|0,h=li(h^d,12),s=s+h|0,w=li(w^s,8),d=d+w|0,h=li(h^d,7),c=c+a|0,b=li(b^c,16),l=l+b|0,a=li(a^l,12),c=c+a|0,b=li(b^c,8),l=l+b|0,a=li(a^l,7);let v=0;n[v++]=o,n[v++]=i,n[v++]=s,n[v++]=c,n[v++]=g,n[v++]=w,n[v++]=b,n[v++]=m},allowShortKeys:!1}),Bi=new Uint8Array(16),Si=(e,t)=>{e.update(t);const r=t.length%16;r&&e.update(Bi.subarray(r))},Ii=new Uint8Array(32);function ki(e,t,r,n,o){const i=e(t,r,Ii),s=vi.create(i);o&&Si(s,o),Si(s,n);const c=function(e,t,r){Zo(r);const n=new Uint8Array(16),o=(i=n,new DataView(i.buffer,i.byteOffset,i.byteLength));var i;return si(o,0,BigInt(t),r),si(o,8,BigInt(e),r),n}(n.length,o?o.length:0,!0);s.update(c);const a=s.digest();return ti(i,c),a}const Pi=e=>(t,r,n)=>({encrypt(o,i){const s=o.length;(i=ii(s+16,i,!1)).set(o);const c=i.subarray(0,-16);e(t,r,c,c,1);const a=ki(e,t,r,c,n);return i.set(a,s),ti(a),i},decrypt(o,i){i=ii(o.length-16,i,!1);const s=o.subarray(0,-16),c=o.subarray(-16),a=ki(e,t,r,s,n);if(!function(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return 0===r}(c,a))throw new Error("invalid tag");return i.set(o.subarray(0,-16)),e(t,r,i,i,1),ti(a),i}}),Ui=(Pi(xi),oi({blockSize:64,nonceLength:24,tagLength:16},Pi(Ai))),Ti={toString:Me,fromString:Fe,concat:v};function Oi(e){return Ti.toString(e,"base64url")}function Ri(e){const t=e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"");return Ti.fromString(t,"base64url")}function Ni(e){return Ti.fromString(e,"base58btc")}function Ki(e){return Ti.toString(e,"base58btc")}const Li={ES256:["JsonWebKey2020","Multikey","EcdsaSecp256r1VerificationKey2019"],ES256K:["EcdsaSecp256k1VerificationKey2019","EcdsaSecp256k1RecoveryMethod2020","Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1","JsonWebKey2020","Multikey"],"ES256K-R":["EcdsaSecp256k1VerificationKey2019","EcdsaSecp256k1RecoveryMethod2020","Secp256k1VerificationKey2018","Secp256k1SignatureVerificationKey2018","EcdsaPublicKeySecp256k1","ConditionalProof2022","JsonWebKey2020","Multikey"],Ed25519:["ED25519SignatureVerification","Ed25519VerificationKey2018","Ed25519VerificationKey2020","JsonWebKey2020","Multikey"],EdDSA:["ED25519SignatureVerification","Ed25519VerificationKey2018","Ed25519VerificationKey2020","JsonWebKey2020","Multikey"]},Ci={Secp256k1SignatureVerificationKey2018:"Secp256k1",Secp256k1VerificationKey2018:"Secp256k1",EcdsaSecp256k1VerificationKey2019:"Secp256k1",EcdsaPublicKeySecp256k1:"Secp256k1",EcdsaSecp256k1RecoveryMethod2020:"Secp256k1",EcdsaSecp256r1VerificationKey2019:"P-256",Ed25519VerificationKey2018:"Ed25519",Ed25519VerificationKey2020:"Ed25519",ED25519SignatureVerification:"Ed25519",X25519KeyAgreementKey2019:"X25519",X25519KeyAgreementKey2020:"X25519",ConditionalProof2022:void 0,JsonWebKey2020:void 0,Multikey:void 0},Di={"ed25519-pub":237,"x25519-pub":236,"secp256k1-pub":231,"bls12_381-g1-pub":234,"bls12_381-g2-pub":235,"p256-pub":4608},ji={"bls12_381-g1-pub":"Bls12381G1","bls12_381-g2-pub":"Bls12381G2","ed25519-pub":"Ed25519","p256-pub":"P-256","secp256k1-pub":"Secp256k1","x25519-pub":"X25519"};function $i(e){if(e.publicKeyBase58)return{keyBytes:Ni(e.publicKeyBase58),keyType:Ci[e.type]};if(e.publicKeyBase64)return{keyBytes:Ri(e.publicKeyBase64),keyType:Ci[e.type]};if(e.publicKeyHex)return{keyBytes:Hi(e.publicKeyHex),keyType:Ci[e.type]};if(e.publicKeyJwk&&"secp256k1"===e.publicKeyJwk.crv&&e.publicKeyJwk.x&&e.publicKeyJwk.y)return{keyBytes:On.ProjectivePoint.fromAffine({x:Fi(Ri(e.publicKeyJwk.x)),y:Fi(Ri(e.publicKeyJwk.y))}).toRawBytes(!1),keyType:"Secp256k1"};if(e.publicKeyJwk&&"P-256"===e.publicKeyJwk.crv&&e.publicKeyJwk.x&&e.publicKeyJwk.y)return{keyBytes:Cn.ProjectivePoint.fromAffine({x:Fi(Ri(e.publicKeyJwk.x)),y:Fi(Ri(e.publicKeyJwk.y))}).toRawBytes(!1),keyType:"P-256"};if(e.publicKeyJwk&&"OKP"===e.publicKeyJwk.kty&&["Ed25519","X25519"].includes(e.publicKeyJwk.crv??"")&&e.publicKeyJwk.x)return{keyBytes:Ri(e.publicKeyJwk.x),keyType:e.publicKeyJwk.crv};if(e.publicKeyMultibase){const{keyBytes:t,keyType:r}=Vi(e.publicKeyMultibase);return{keyBytes:t,keyType:r??Ci[e.type]}}return{keyBytes:new Uint8Array}}function _i(e,t="base58btc",r){if(r){const n="string"==typeof r?Di[r]:r,o=Ee(n),i=new Uint8Array(o+e.length);return ve(n,i),i.set(e,o),Ti.toString((0,ln.encode)(t,i),"utf-8")}return Ti.toString((0,ln.encode)(t,e),"utf-8")}function Vi(e){const t=(0,ln.decode)(e);if([32,33,48,64,65,96].includes(t.length))return{keyBytes:t};try{const[e,r]=me(t),n=Object.entries(Di).filter((([,t])=>t===e))?.[0][0]??"";return{keyBytes:t.slice(r),keyType:ji[n]}}catch(e){return{keyBytes:t}}}function Hi(e,t){let r=e.startsWith("0x")?e.substring(2):e;if(r.length%2!=0&&(r=`0${r}`),t){const e=Math.max(r.length,2*t);r=r.padStart(e,"00")}return Ti.fromString(r.toLowerCase(),"base16")}function Ji(e){return Oi(Ti.fromString(e))}function zi(e){return Ti.toString(Ri(e))}function Wi(e){return Ti.toString(e,"base16")}function Fi(e){return BigInt("0x"+Ti.toString(e,"base16"))}function Mi(e){return Ti.fromString(e,"utf-8")}function qi({r:e,s:t,recoveryParam:r},n){const o=new Uint8Array(n?65:64);if(o.set(Ti.fromString(e,"base16"),0),o.set(Ti.fromString(t,"base16"),32),n){if(void 0===r)throw new Error("Signer did not return a recoveryParam");o[64]=r}return Oi(o)}function Gi(e){const t=Ri(e);if(t.length<64||t.length>65)throw new TypeError(`Wrong size for signature. Expected 64 or 65 bytes, but got ${t.length}`);return{r:Wi(t.slice(0,32)),s:Wi(t.slice(32,64)),recoveryParam:65===t.length?t[64]:void 0}}function Zi(e,t){return Ti.concat([Ri(e),t?Ri(t):new Uint8Array(0)])}function Xi(e,t=64){return e.length===t?e:"0".repeat(t-e.length)+e}function Yi(){const e=dn.utils.randomPrivateKey();return{secretKey:e,publicKey:dn.getPublicKey(e)}}function Qi(e){if(32!==e.length)throw new Error("x25519: seed must be 32 bytes");return{publicKey:dn.getPublicKey(e),secretKey:e}}function es(){const e=Yi();return{publicKeyJWK:{kty:"OKP",crv:"X25519",x:Oi(e.publicKey)},secretKey:e.secretKey}}function ts(e){return null!=e}function rs(e){const t="string"==typeof e?Fe(e):e;return Dn(t)}const ns=yo;function os(e){const t=Fe(e.slice(2),"base16");return`0x${Me(ns(t).slice(-20),"base16")}`}function is(e,t=new Uint8Array(4)){const r=Fe(e.toString(),"base10");return t.set(r,4-r.length),t}const ss=e=>v([is(e.length),e]);function cs(e,t,r,n,o){if(256!==t)throw new Error(`Unsupported key length: ${t}`);const i=v([ss(Fe(r)),ss(void 0===n?new Uint8Array(0):n),ss(void 0===o?new Uint8Array(0):o),is(t)]);return rs(v([is(1),e,i]))}function as(e,t=!1){const r=e;if(32!==r.length)throw new Error(`bad_key: Invalid private key format. Expecting 32 bytes, but got ${r.length}`);return function(e){try{const n=On.sign(rs(e),r);return Promise.resolve(qi({r:Xi(n.r.toString(16)),s:Xi(n.s.toString(16)),recoveryParam:n.recovery},t))}catch(e){return Promise.reject(e)}}}function fs(e){const t=as(Hi(e),!0);return function(e){try{return Promise.resolve(t(e)).then(Gi)}catch(e){return Promise.reject(e)}}}function us(e){return as(Hi(e))}function hs(e){const t=e;if(![32,64].includes(t.length))throw new Error(`bad_key: Invalid private key format. Expecting 32 or 64 bytes, but got ${t.length}`);return function(e){try{const r="string"==typeof e?Mi(e):e,n=hn.sign(r,t.slice(0,32));return Promise.resolve(Oi(n))}catch(e){return Promise.reject(e)}}}function ds(e){return hs(Ri(e))}function ls(e){if(32!==e.length)throw new Error(`bad_key: Invalid private key format. Expecting 32 bytes, but got ${e.length}`);return function(t){try{const r=Cn.sign(rs(t),e);return Promise.resolve(qi({r:Xi(r.r.toString(16)),s:Xi(r.s.toString(16))}))}catch(e){return Promise.reject(e)}}}function ps(e){return"object"==typeof e&&"r"in e&&"s"in e}function ys(e){return function(t,r){try{return Promise.resolve(r(t)).then((function(t){if(ps(t))return qi(t,e);if(e&&void 0===Gi(t).recoveryParam)throw new Error("not_supported: ES256K-R not supported when signer doesn't provide a recovery param");return t}))}catch(e){return Promise.reject(e)}}}function gs(){return function(e,t){try{return Promise.resolve(t(e)).then((function(e){if(ps(e))throw new Error("invalid_config: expected a signer function that returns a string instead of signature object");return e}))}catch(e){return Promise.reject(e)}}}const ws={ES256:function(e,t){try{return Promise.resolve(t(e)).then((function(e){return ps(e)?qi(e):e}))}catch(e){return Promise.reject(e)}},ES256K:ys(),"ES256K-R":ys(!0),Ed25519:gs(),EdDSA:gs()};function bs(e,t=!1){const r=Ri(e);if(r.length!==(t?65:64))throw new Error("wrong signature length");return{compact:r.slice(0,64),recovery:r[64]}}function ms(e,t,r){const n=[];if(t.length>86)n.push(bs(t,!0));else{const e=bs(t,!1);n.push({...e,recovery:0}),n.push({...e,recovery:1})}const o=rs(e),i=e=>{const t=On.Signature.fromCompact(e.compact).addRecoveryBit(e.recovery||0).recoverPublicKey(o),n=os(t.toHex(!1)).toLowerCase(),i=t.toHex(!1),s=t.toHex(!0);return r.find((e=>{const{keyBytes:t}=$i(e),r=Wi(t);return r===i||r===s||e.ethereumAddress?.toLowerCase()===n||e.blockchainAccountId?.split("@eip155")?.[0].toLowerCase()===n||function(e,t){if(t){const r=t.split(":");switch(r[0]){case"bip122":r[r.length-1]=function(e,t){const r=Wi(Ni(t).slice(0,1)),n=Hi(e),o=r+Wi(Yn(rs(n))),i=rs(Hi(o));return Ki(Hi(o+Wi(rs(i)).substring(0,8)))}(e,r[r.length-1]);break;case"cosmos":r[r.length-1]=function(e,t){const r=On.ProjectivePoint.fromHex(e).toRawBytes(),n=Yn(rs(r)),o=qo.toWords(n);return qo.encode(t,o).replace(t,"")}(e,r[1]);break;case"eip155":r[r.length-1]=os(e);break;default:return!1}return r.join(":").toLowerCase()===t.toLowerCase()}return!1}(i,e.blockchainAccountId)}))};for(const e of n){const t=i(e);if(t)return t}throw new Error("invalid_signature: Signature invalid for JWT")}function vs(e,t,r){const n=Mi(e),o=Ri(t),i=r.find((e=>{const{keyBytes:t,keyType:r}=$i(e);return"Ed25519"===r&&hn.verify(o,n,t)}));if(!i)throw new Error("invalid_signature: Signature invalid for JWT");return i}const Es={ES256:function(e,t,r){const n=rs(e),o=Cn.Signature.fromCompact(bs(t).compact),i=r.filter((e=>!e.ethereumAddress&&!e.blockchainAccountId)).find((e=>{try{const{keyBytes:t}=$i(e);return Cn.verify(o,n,t)}catch(e){return!1}}));if(!i)throw new Error("invalid_signature: Signature invalid for JWT");return i},ES256K:function(e,t,r){const n=rs(e),o=On.Signature.fromCompact(Ri(t)).normalizeS(),i=r.filter((e=>!e.ethereumAddress&&!e.blockchainAccountId)),s=r.filter((e=>e.ethereumAddress||e.blockchainAccountId));let c=i.find((e=>{try{const{keyBytes:t}=$i(e);return On.verify(o,n,t)}catch(e){return!1}}));if(!c&&s.length>0&&(c=ms(e,t,s)),!c)throw new Error("invalid_signature: Signature invalid for JWT");return c},"ES256K-R":ms,Ed25519:vs,EdDSA:vs};function xs(e){const t=Es[e];if(!t)throw new Error(`not_supported: Unsupported algorithm ${e}`);return t}xs.toSignatureObject=function(e,t=!1){const r=Ri(e);if(r.length!==(t?65:64))throw new Error("wrong signature length");const n={r:Wi(r.slice(0,32)),s:Wi(r.slice(32,64))};return t&&(n.recoveryParam=r[64]),n};const As={INVALID_JWT:"invalid_jwt",INVALID_AUDIENCE:"invalid_config",INVALID_SIGNATURE:"invalid_signature",NO_SUITABLE_KEYS:"no_suitable_keys",NOT_SUPPORTED:"not_supported",RESOLVER_ERROR:"resolver_error"},Bs="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Ss(e,t,r){if(!e.s){if(r instanceof Is){if(!r.s)return void(r.o=Ss.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Ss.bind(null,e,t),Ss.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const Is=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,o=this.s;if(o){const e=1&o?t:r;if(e){try{Ss(n,1,e(this.v))}catch(e){Ss(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?Ss(n,1,t?t(o):o):r?Ss(n,1,r(o)):Ss(n,2,o)}catch(e){Ss(n,2,e)}},n},e}();function ks(e){return e instanceof Is&&1&e.s}const Ps=function(e,{header:t,payload:r,data:n,signature:o},i,s){try{let c;function a(e){if(c)return e;throw new Error(`${As.INVALID_SIGNATURE}: condition for authenticator ${i.id} is not met.`)}if(!i.conditionWeightedThreshold||!i.threshold)throw new Error("Expected conditionWeightedThreshold and threshold");const f=[],u=i.threshold;let h=0;const d=function(e,t,r){if("function"==typeof e[Bs]){var n,o,i,s=e[Bs]();function u(e){try{for(;!((n=s.next()).done||r&&r());)if((e=t(n.value))&&e.then){if(!ks(e))return void e.then(u,i||(i=Ss.bind(null,o=new Is,2)));e=e.v}o?Ss(o,1,e):o=e}catch(e){Ss(o||(o=new Is),2,e)}}if(u(),s.return){var c=function(e){try{n.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(c,(function(e){throw c(e)}));c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],f=0;f<e.length;f++)a.push(e[f]);return function(e,t,r){var n,o,i=-1;return function s(c){try{for(;++i<e.length&&(!r||!r());)if((c=t(i))&&c.then){if(!ks(c))return void c.then(s,o||(o=Ss.bind(null,n=new Is,2)));c=c.v}n?Ss(n,1,c):n=c}catch(e){Ss(n||(n=new Is),2,e)}}(),n}(a,(function(e){return t(a[e])}),r)}(i.conditionWeightedThreshold,(function(a){function d(e){return c?e:p&&!f.includes(p.id)&&(f.push(p.id),h+=a.weight,h>=u)?(c=1,i):void 0}const l=a.condition;let p;const y=function(i,c){try{var a=function(){if(l.type===Ts){if(!s.didAuthenticator)throw new Error("Expected didAuthenticator");const t={...s,didAuthenticator:{didResolutionResult:s.didAuthenticator?.didResolutionResult,authenticators:[l],issuer:l.id}};return Promise.resolve(Ls(e,t)).then((function({verified:e}){e&&(p=l)}))}return Promise.resolve(qs({header:t,payload:r,data:n,signature:o},l)).then((function(e){p=e}))}()}catch(e){return c(e)}return a&&a.then?a.then(void 0,c):a}(0,(function(e){if(!e.message.startsWith(As.INVALID_SIGNATURE))throw e}));return y&&y.then?y.then(d):d(y)}),(function(){return c}));return Promise.resolve(d&&d.then?d.then(a):a(d))}catch(l){return Promise.reject(l)}},Us=function(e,{header:t,payload:r,signature:n,data:o},i,s){try{return i.type===Ts?function(e,{header:t,payload:r,signature:n,data:o},i,s){try{if(i.conditionWeightedThreshold)return Ps(e,{header:t,payload:r,data:o,signature:n},i,s);if(i.conditionDelegated)return function(e,{header:t,payload:r,data:n,signature:o},i,s){try{if(!i.conditionDelegated)throw new Error("Expected conditionDelegated");if(!s.resolver)throw new Error("Expected resolver");let c;const a=i.conditionDelegated;return Promise.resolve(Ks(s.resolver,t.alg,a,s.proofPurpose)).then((function(f){function u(e){if(c)return i;throw new Error(`${As.INVALID_SIGNATURE}: condition for authenticator ${i.id} is not met.`)}const h=f.didResolutionResult;if(!h?.didDocument)throw new Error(`${As.RESOLVER_ERROR}: Could not resolve delegated DID ${a}.`);const d=f.authenticators.find((e=>e.id===a));if(!d)throw new Error(`${As.NO_SUITABLE_KEYS}: Could not find delegated authenticator ${a} in it's DID Document`);const l=function(){if(d.type===Ts)return Promise.resolve(Ls(e,{...s,didAuthenticator:{didResolutionResult:h,authenticators:[d],issuer:d.id}})).then((function({verified:e}){e&&(c=d)}));try{c=qs({header:t,payload:r,data:n,signature:o},d)}catch(e){if(!e.message.startsWith("invalid_signature:"))throw e}}();return l&&l.then?l.then(u):u()}))}catch(e){return Promise.reject(e)}}(e,{header:t,payload:r,data:o,signature:n},i,s);throw new Error(`${As.INVALID_JWT}: conditional proof type did not find condition for authenticator ${i.id}.`)}catch(e){return Promise.reject(e)}}(e,{payload:r,header:t,signature:n,data:o},i,s):Promise.resolve(qs({header:t,payload:r,data:o,signature:n},[i]))}catch(e){return Promise.reject(e)}},Ts="ConditionalProof2022";function Os(e,t,r){if(!e.s){if(r instanceof Rs){if(!r.s)return void(r.o=Os.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Os.bind(null,e,t),Os.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const Rs=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,o=this.s;if(o){const e=1&o?t:r;if(e){try{Os(n,1,e(this.v))}catch(e){Os(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?Os(n,1,t?t(o):o):r?Os(n,1,r(o)):Os(n,2,o)}catch(e){Os(n,2,e)}},n},e}();function Ns(e){return e instanceof Rs&&1&e.s}const Ks=function(e,t,r,n){try{const o=Li[t];if(!o||0===o.length)throw new Error(`${As.NOT_SUPPORTED}: No supported signature types for algorithm ${t}`);let i;return Promise.resolve(e.resolve(r,{accept:Js})).then((function(e){if(i=-1===Object.getOwnPropertyNames(e).indexOf("didDocument")?{didDocument:e,didDocumentMetadata:{},didResolutionMetadata:{contentType:Js}}:e,i.didResolutionMetadata?.error||null==i.didDocument){const{error:e,message:t}=i.didResolutionMetadata;throw new Error(`${As.RESOLVER_ERROR}: Unable to resolve DID document for ${r}: ${e}, ${t||""}`)}const s=(e,t)=>{const r=e.filter((({id:e})=>t===e));return r.length>0?r[0]:null};let c=[...i?.didDocument?.verificationMethod||[],...i?.didDocument?.publicKey||[]];"string"==typeof n&&(n.startsWith("assertion")&&!Object.getOwnPropertyNames(i?.didDocument).includes("assertionMethod")&&(i.didDocument={...i.didDocument},i.didDocument.assertionMethod=[...c.map((e=>e.id))]),c=(i.didDocument[n]||[]).map((e=>"string"==typeof e?s(c,e):"string"==typeof e.publicKey?s(c,e.publicKey):e)).filter((e=>null!=e)));const a=c.filter((({type:e})=>o.find((t=>t===e))));if("string"==typeof n&&(!a||0===a.length))throw new Error(`${As.NO_SUITABLE_KEYS}: DID document for ${r} does not have public keys suitable for ${t} with ${n} purpose`);if(!a||0===a.length)throw new Error(`${As.NO_SUITABLE_KEYS}: DID document for ${r} does not have public keys for ${t}`);return{authenticators:a,issuer:r,didResolutionResult:i}}))}catch(e){return Promise.reject(e)}},Ls=function(e,t={resolver:void 0,auth:void 0,audience:void 0,callbackUrl:void 0,skewTime:void 0,proofPurpose:void 0,policies:{},didAuthenticator:void 0}){try{function r(){function r(r){if(d){const r="number"==typeof t.policies?.now?t.policies.now:Math.floor(Date.now()/1e3),o=void 0!==t.skewTime&&t.skewTime>=0?t.skewTime:Ws,i=r+o;if(!1!==t.policies?.nbf&&n.nbf){if(n.nbf>i)throw new Error(`${As.INVALID_JWT}: JWT not valid before nbf: ${n.nbf}`)}else if(!1!==t.policies?.iat&&n.iat&&n.iat>i)throw new Error(`${As.INVALID_JWT}: JWT not valid yet (issued in the future) iat: ${n.iat}`);if(!1!==t.policies?.exp&&n.exp&&n.exp<=r-o)throw new Error(`${As.INVALID_JWT}: JWT has expired: exp: ${n.exp} < now: ${r}`);if(!1!==t.policies?.aud&&n.aud){if(!t.audience&&!t.callbackUrl)throw new Error(`${As.INVALID_AUDIENCE}: JWT audience is required but your app address has not been configured`);if(void 0===(Array.isArray(n.aud)?n.aud:[n.aud]).find((e=>t.audience===e||t.callbackUrl===e)))throw new Error(`${As.INVALID_AUDIENCE}: JWT audience does not match your DID or callback url`)}return{verified:!0,payload:n,didResolutionResult:h,issuer:u,signer:d,jwt:e,policies:t.policies}}throw new Error(`${As.INVALID_SIGNATURE}: JWT not valid. issuer DID document does not contain a verificationMethod that matches the signature.`)}const{did:c}=function(e){if(""===e||!e)return null;const t=e.match(mo);if(t){const r={did:`did:${t[1]}:${t[2]}`,method:t[1],id:t[2],didUrl:e};if(t[4]){const e=t[4].slice(1).split(";");r.params={};for(const t of e){const e=t.split("=");r.params[e[0]]=e[1]}}return t[6]&&(r.path=t[6]),t[7]&&(r.query=t[7].slice(1)),t[8]&&(r.fragment=t[8].slice(1)),r}return null}(a);let d=null;const l=function(){if(c!==a){const r=f.find((e=>e.id===a));if(!r)throw new Error(`${As.INVALID_JWT}: No authenticator found for did URL ${a}`);return Promise.resolve(Us(e,{payload:n,header:o,signature:i,data:s},r,t)).then((function(e){d=e}))}{let r=0;return function(e,t,r){for(var n;;){var o=e();if(Ns(o)&&(o=o.v),!o)return s;if(o.then){n=0;break}var i,s=r();if(s&&s.then){if(!Ns(s)){n=1;break}s=s.s}}var c=new Rs,a=Os.bind(null,c,2);return(0===n?o.then(u):1===n?s.then(f):i.then(h)).then(void 0,a),c;function f(t){s=t;do{if(!(o=e())||Ns(o)&&!o.v)return void Os(c,1,s);if(o.then)return void o.then(u).then(void 0,a);Ns(s=r())&&(s=s.v)}while(!s||!s.then);s.then(f).then(void 0,a)}function u(e){e?(s=r())&&s.then?s.then(f).then(void 0,a):f(s):Os(c,1,s)}function h(){(o=e())?o.then?o.then(u).then(void 0,a):u(o):Os(c,1,s)}}((function(){return!d&&r<f.length}),0,(function(){function c(e){r++}const a=f[r],u=function(r,c){try{var f=Promise.resolve(Us(e,{payload:n,header:o,signature:i,data:s},a,t)).then((function(e){d=e}))}catch(e){return c(e)}return f&&f.then?f.then(void 0,c):f}(0,(function(e){if(!e.message.includes(As.INVALID_SIGNATURE)||r===f.length-1)throw e}));return u&&u.then?u.then(c):c()}))}}();return l&&l.then?l.then(r):r()}if(!t.resolver)throw new Error("missing_resolver: No DID resolver has been configured");const{payload:n,header:o,signature:i,data:s}=Ms(e,!1),c=Object.prototype.hasOwnProperty.call(t,"auth")?t.auth?"authentication":void 0:t.proofPurpose;let a,f,u,h;if(!n.iss&&!n.client_id)throw new Error(`${As.INVALID_JWT}: JWT iss or client_id are required`);if(t.didAuthenticator)a=t.didAuthenticator.issuer;else if(n.iss===$s||n.iss===_s){if(!n.sub)throw new Error(`${As.INVALID_JWT}: JWT sub is required`);a=void 0===n.sub_jwk?n.sub:(o.kid||"").split("#")[0]}else if(n.iss===Vs){if(!n.did)throw new Error(`${As.INVALID_JWT}: JWT did is required`);a=n.did}else if(!n.iss&&"openid"===n.scope&&n.redirect_uri){if(!n.client_id)throw new Error(`${As.INVALID_JWT}: JWT client_id is required`);a=n.client_id}else a=n.iss;if(!a)throw new Error(`${As.INVALID_JWT}: No DID has been found in the JWT`);const d=function(){if(!t.didAuthenticator)return Promise.resolve(Ks(t.resolver,o.alg,a,c)).then((function(e){({didResolutionResult:h,authenticators:f,issuer:u}=e),t.didAuthenticator={didResolutionResult:h,authenticators:f,issuer:u}}));({didResolutionResult:h,authenticators:f,issuer:u}=t.didAuthenticator)}();return Promise.resolve(d&&d.then?d.then(r):r())}catch(l){return Promise.reject(l)}},Cs=function(e,{expiresIn:t,canonicalize:r},n){try{if(0===n.length)throw new Error("invalid_argument: must provide one or more issuers");let f=e,u="";const h=(o=n,i=function(e){const o=n[e],i={typ:"JWT",alg:o.alg};return 0!==e&&(i.cty="JWT"),Promise.resolve(Ds(f,{...o,canonicalize:r,expiresIn:t},i)).then((function(e){u=e,f={jwt:u}}))},a=-1,function e(t){try{for(;++a<o.length;)if((t=i(a))&&t.then){if(!Ns(t))return void t.then(e,c||(c=Os.bind(null,s=new Rs,2)));t=t.v}s?Os(s,1,t):s=t}catch(e){Os(s||(s=new Rs),2,e)}}(),s);return Promise.resolve(h&&h.then?h.then((function(){return u})):u)}catch(e){return Promise.reject(e)}var o,i,s,c,a},Ds=function(e,{issuer:t,signer:r,alg:n,expiresIn:o,canonicalize:i},s={}){try{if(!r)throw new Error("missing_signer: No Signer functionality has been configured");if(!t)throw new Error("missing_issuer: No issuing DID has been configured");s.typ||(s.typ="JWT"),s.alg||(s.alg=n);const c={iat:Math.floor(Date.now()/1e3),exp:void 0};if(o){if("number"!=typeof o)throw new Error("invalid_argument: JWT expiresIn is not a number");c.exp=(e.nbf||c.iat)+Math.floor(o)}const a={...c,...e,iss:t};return js(a,r,s,{canonicalize:i})}catch(e){return Promise.reject(e)}},js=function(e,t,r={},n={}){try{r.alg||(r.alg=Hs);const o="string"==typeof e?e:zs(e,n.canonicalize),i=[zs(r,n.canonicalize),o].join("."),s=function(e){const t=ws[e];if(!t)throw new Error(`not_supported: Unsupported algorithm ${e}`);return t}(r.alg);return Promise.resolve(s(i,t)).then((function(e){return[i,e].join(".")}))}catch(e){return Promise.reject(e)}},$s="https://self-issued.me/v2",_s="https://self-issued.me/v2/openid-vc",Vs="https://self-issued.me",Hs="ES256K",Js="application/did+json";function zs(e,t=!1){return Ji(t?go(e):JSON.stringify(e))}const Ws=300;function Fs(e){const t=e.match(/^([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)\.([a-zA-Z0-9_-]+)$/);if(t)return{header:JSON.parse(zi(t[1])),payload:t[2],signature:t[3],data:`${t[1]}.${t[2]}`};throw new Error("invalid_argument: Incorrect format JWS")}function Ms(e,t=!0){if(!e)throw new Error("invalid_argument: no JWT passed into decodeJWT");try{const r=Fs(e),n=Object.assign(r,{payload:JSON.parse(zi(r.payload))}),o=n.payload.iss;if("JWT"===n.header.cty&&t){const e=Ms(n.payload.jwt);if(e.payload.iss!==o)throw new Error(`${As.INVALID_JWT}: multiple issuers`);return e}return n}catch(e){throw new Error(`invalid_argument: ${As.INVALID_JWT}: ${e}`)}}function qs({header:e,payload:t,data:r,signature:n},o){Array.isArray(o)||(o=[o]);const i=t.iss;let s=!0;do{if(i!==t.iss)throw new Error(`${As.INVALID_JWT}: multiple issuers`);try{return xs(e.alg)(r,n,o)}catch(e){if(!e.message.startsWith(As.INVALID_SIGNATURE))throw e}"JWT"!==e.cty?s=!1:({payload:t,header:e,signature:n,data:r}=Ms(t.jwt,!1))}while(s);throw new Error(`${As.INVALID_SIGNATURE}: no matching public key found`)}function Gs(e,t){return function({header:e,data:t,signature:r},n){return Array.isArray(n)||(n=[n]),xs(e.alg)(t,r,n)}(Fs(e),t)}const Zs="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function Xs(e,t,r){if(!e.s){if(r instanceof Ys){if(!r.s)return void(r.o=Xs.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(Xs.bind(null,e,t),Xs.bind(null,e,2));e.s=t,e.v=r;const n=e.o;n&&n(e)}}const Ys=function(){function e(){}return e.prototype.then=function(t,r){const n=new e,o=this.s;if(o){const e=1&o?t:r;if(e){try{Xs(n,1,e(this.v))}catch(e){Xs(n,2,e)}return n}return this}return this.o=function(e){try{const o=e.v;1&e.s?Xs(n,1,t?t(o):o):r?Xs(n,1,r(o)):Xs(n,2,o)}catch(e){Xs(n,2,e)}},n},e}();function Qs(e){return e instanceof Ys&&1&e.s}function ec({ciphertext:e,tag:t,iv:r,protectedHeader:n,recipient:o},i){const s={protected:n,iv:Oi(r??new Uint8Array(0)),ciphertext:Oi(e),tag:Oi(t??new Uint8Array(0))};return i&&(s.aad=Oi(i)),o&&(s.recipients=[o]),s}const tc=function(e,t){try{function r(e){if(null===s)throw new Error("failure: Failed to decrypt");return s}!function(e){if(!(e.protected&&e.iv&&e.ciphertext&&e.tag))throw new Error("bad_jwe: missing properties");e.recipients&&e.recipients.map((e=>{if(!e.header||!e.encrypted_key)throw new Error("bad_jwe: malformed recipients")}))}(e);const n=JSON.parse(zi(e.protected));if(n.enc!==t.enc)throw new Error(`not_supported: Decrypter does not supported: '${n.enc}'`);const o=Zi(e.ciphertext,e.tag),i=Mi(e.aad?`${e.protected}.${e.aad}`:e.protected);let s=null;const c="dir"===n.alg&&"dir"===t.alg?Promise.resolve(t.decrypt(o,Ri(e.iv),i)).then((function(e){s=e})):function(){if(e.recipients&&0!==e.recipients.length){let r=0;return function(e,t,r){for(var n;;){var o=e();if(Qs(o)&&(o=o.v),!o)return i;if(o.then){n=0;break}var i=r();if(i&&i.then){if(!Qs(i)){n=1;break}i=i.s}if(t){var s=t();if(s&&s.then&&!Qs(s)){n=2;break}}}var c=new Ys,a=Xs.bind(null,c,2);return(0===n?o.then(u):1===n?i.then(f):s.then(h)).then(void 0,a),c;function f(n){i=n;do{if(t&&(s=t())&&s.then&&!Qs(s))return void s.then(h).then(void 0,a);if(!(o=e())||Qs(o)&&!o.v)return void Xs(c,1,i);if(o.then)return void o.then(u).then(void 0,a);Qs(i=r())&&(i=i.v)}while(!i||!i.then);i.then(f).then(void 0,a)}function u(e){e?(i=r())&&i.then?i.then(f).then(void 0,a):f(i):Xs(c,1,i)}function h(){(o=e())?o.then?o.then(u).then(void 0,a):u(o):Xs(c,1,i)}}((function(){return!s&&r<e.recipients.length}),(function(){return r++}),(function(){const c=e.recipients[r];Object.assign(c.header,n);const a=function(){if(c.header.alg===t.alg)return Promise.resolve(t.decrypt(o,Ri(e.iv),i,c)).then((function(e){s=e}))}();if(a&&a.then)return a.then((function(){}))}))}throw new Error("bad_jwe: missing recipients")}();return Promise.resolve(c&&c.then?c.then(r):r())}catch(a){return Promise.reject(a)}},rc=function(e,t,r={},n,o=!1){try{if("dir"===t[0].alg){if(t.length>1)throw new Error('not_supported: Can only do "dir" encryption to one key.');return Promise.resolve(t[0].encrypt(e,r,n)).then((function(e){return ec(e,n)}))}{const i=t[0].enc;if(!t.reduce(((e,t)=>e&&t.enc===i),!0))throw new Error("invalid_argument: Incompatible encrypters passed");let s,c,a;if(o){a=t[0].genEpk?.();const e=t[0].alg;r={...r,alg:e,epk:a?.publicKeyJWK}}const f=function(e,t,r){if("function"==typeof e[Zs]){var n,o,i,s=e[Zs]();function u(e){try{for(;!((n=s.next()).done||r&&r());)if((e=t(n.value))&&e.then){if(!Qs(e))return void e.then(u,i||(i=Xs.bind(null,o=new Ys,2)));e=e.v}o?Xs(o,1,e):o=e}catch(e){Xs(o||(o=new Ys),2,e)}}if(u(),s.return){var c=function(e){try{n.done||s.return()}catch(e){}return e};if(o&&o.then)return o.then(c,(function(e){throw c(e)}));c()}return o}if(!("length"in e))throw new TypeError("Object is not iterable");for(var a=[],f=0;f<e.length;f++)a.push(e[f]);return function(e,t,r){var n,o,i=-1;return function s(c){try{for(;++i<e.length&&(!r||!r());)if((c=t(i))&&c.then){if(!Qs(c))return void c.then(s,o||(o=Xs.bind(null,n=new Ys,2)));c=c.v}n?Xs(n,1,c):n=c}catch(e){Xs(n||(n=new Ys),2,e)}}(),n}(a,(function(e){return t(a[e])}),r)}(t,(function(t){const o=s?Promise.resolve(t.encryptCek?.(s,a)).then((function(e){e&&c?.recipients?.push(e)})):Promise.resolve(t.encrypt(e,r,n,a)).then((function(e){s=e.cek,c=ec(e,n)}));if(o&&o.then)return o.then((function(){}))}));return Promise.resolve(f&&f.then?f.then((function(){return c})):c)}}catch(e){return Promise.reject(e)}};function nc(e){return(t,r)=>{const n=ct(24),o=Ui(e,n,r).encrypt(t);return{ciphertext:o.subarray(0,o.length-16),tag:o.subarray(o.length-16),iv:n}}}function oc(e){const t=nc(e),r="XC20P";return{alg:"dir",enc:r,encrypt:function(e,n={},o){try{const i=Ji(JSON.stringify(Object.assign({alg:"dir"},n,{enc:r}))),s=Mi(o?`${i}.${Oi(o)}`:i);return Promise.resolve({...t(e,s),protectedHeader:i})}catch(e){return Promise.reject(e)}}}}function ic(e){return{alg:"dir",enc:"XC20P",decrypt:function(t,r,n){try{try{return Promise.resolve(Ui(e,r,n).decrypt(t))}catch(e){return Promise.resolve(null)}}catch(e){return Promise.reject(e)}}}}const sc=function(e,t,r,n,o,i){try{const t="X25519",n=256,s=i?Qi(i.secretKey):Yi(),c={kty:"OKP",crv:t,x:Oi(s.publicKey)},a=cs(dn.getSharedSecret(s.secretKey,e),n,r,void 0,Ri(o??""));return Promise.resolve({epk:c,kek:a})}catch(e){return Promise.reject(e)}},cc=function(e,t,r){try{function n(){let t,n;return e.header.apu&&(t=Ri(e.header.apu)),e.header.apv&&(n=Ri(e.header.apv)),cs(a,i,r,t,n)}const o="X25519",i=256,s=e.header;if(s.epk?.crv!==o||void 0===s.epk.x)return Promise.resolve(null);const c=Ri(s.epk.x);let a;const f=function(){if(!(t instanceof Uint8Array))return Promise.resolve(t(c)).then((function(e){a=e}));a=dn.getSharedSecret(t,c)}();return Promise.resolve(f&&f.then?f.then(n):n())}catch(u){return Promise.reject(u)}},ac=function(e,t,r,n,o,i){try{function s(){const e=new Uint8Array(h.length+d.length);e.set(h),e.set(d,h.length);let t=new Uint8Array(0),i=new Uint8Array(0);n&&(t=Ri(n)),o&&(i=Ri(o));const s=cs(e,a,r,t,i);return{epk:u,kek:s}}const c="X25519",a=256,f=i?Qi(i.secretKey):Yi(),u={kty:"OKP",crv:c,x:Oi(f.publicKey)},h=dn.getSharedSecret(f.secretKey,e);let d;const l=function(){if(!(t instanceof Uint8Array))return Promise.resolve(t(e)).then((function(e){d=e}));d=dn.getSharedSecret(t,e)}();return Promise.resolve(l&&l.then?l.then(s):s())}catch(p){return Promise.reject(p)}},fc=function(e,t,r,n){try{function o(){const t=new Uint8Array(f.length+u.length);let r,o;return t.set(f),t.set(u,f.length),e.header.apu&&(r=Ri(e.header.apu)),e.header.apv&&(o=Ri(e.header.apv)),cs(t,s,n,r,o)}const i="X25519",s=256,c=e.header;if(c.epk?.crv!==i||void 0===c.epk.x)return Promise.resolve(null);const a=Ri(c.epk.x);let f,u;const h=function(){if(!(t instanceof Uint8Array))return Promise.resolve(t(a)).then((function(e){return f=e,Promise.resolve(t(r)).then((function(e){u=e}))}));f=dn.getSharedSecret(t,a),u=dn.getSharedSecret(t,r)}();return Promise.resolve(h&&h.then?h.then(o):o())}catch(d){return Promise.reject(d)}};function uc(e){if(32!==e.length)throw new Error("invalid_argument: incorrect secret key length for X25519");return function(t){try{if(32!==t.length)throw new Error("invalid_argument: incorrect publicKey key length for X25519");return Promise.resolve(dn.getSharedSecret(e,t))}catch(e){return Promise.reject(e)}}}function hc(e,t,r={},n,o,i){const s=function(i,s){try{return Promise.resolve(n.createKek(e,t,`${n.alg}+${o.alg}`,r.apu,r.apv,s)).then((function({epk:e,kek:t}){return Promise.resolve(o.from(t).wrap(i)).then((function(t){const i={encrypted_key:Oi(t.ciphertext),header:{}};return t.iv&&(i.header.iv=Oi(t.iv)),t.tag&&(i.header.tag=Oi(t.tag)),r.kid&&(i.header.kid=r.kid),r.apu&&(i.header.apu=r.apu),r.apv&&(i.header.apv=r.apv),s||(i.header.alg=`${n.alg}+${o.alg}`,i.header.epk=e),i}))}))}catch(e){return Promise.reject(e)}};return{alg:o.alg,enc:i.enc,encrypt:function(e,t={},r,c){try{Object.assign(t,{alg:void 0});const a=ct(32);return Promise.resolve(s(a,c)).then((function(s){return c&&(t.alg=`${n.alg}+${o.alg}`,t.epk=c.publicKeyJWK),Promise.resolve(i.from(a).encrypt(e,t,r)).then((function(e){return{...e,recipient:s,cek:a}}))}))}catch(e){return Promise.reject(e)}},encryptCek:s,genEpk:es}}const dc=function(e,t){try{const r=function(e,n=[]){try{return Promise.resolve(t.resolve(e)).then((function({didResolutionMetadata:t,didDocument:o}){function i(){const t=o.keyAgreement?.map((e=>"string"==typeof e?[...o.publicKey||[],...o.verificationMethod||[]].find((t=>t.id===e)):e))?.filter((e=>void 0!==e)),r=t?.filter((e=>["X25519KeyAgreementKey2019","X25519KeyAgreementKey2020","JsonWebKey2020","Multikey"].includes(e.type)))??[];if(!r.length&&!s.length)throw new Error(`no_suitable_keys: Could not find X25519 key for ${e}`);return r.map((e=>{const{keyBytes:t,keyType:r}=$i(e);return"X25519"===r?mc(t,e.id):null})).filter(ts).concat(...s)}if(n.push(e),t?.error||null==o)throw new Error(`resolver_error: Could not resolve ${e}: ${t.error}, ${t.message}`);let s=[];if(!o.controller&&!o.keyAgreement)throw new Error(`no_suitable_keys: Could not find x25519 key for ${e}`);const c=function(){if(o.controller){let e=Array.isArray(o.controller)?o.controller:[o.controller];e=e.filter((e=>!n.includes(e)));const t=e.map((e=>r(e,n).catch((()=>[]))));return Promise.resolve(Promise.all(t)).then((function(e){s=[].concat(...e)}))}}();return c&&c.then?c.then(i):i()}))}catch(e){return Promise.reject(e)}},n=e.map((e=>r(e)));return Promise.resolve(Promise.all(n)).then((function(e){return[].concat(...e)}))}catch(e){return Promise.reject(e)}};function lc(e,t,r={}){return Ec(e,t,r)}function pc(e,t={}){return vc(e,t)}function yc(e,t){return Bc(e,t)}function gc(e){return Ac(e)}function wc(e){if(!(e&&e.epk&&e.iv&&e.tag))throw new Error("bad_jwe: malformed header");return e}const bc={from:e=>({wrap:function(t){try{return Promise.resolve(nc(e)(t))}catch(e){return Promise.reject(e)}}}),alg:"XC20PKW"};function mc(e,t,r){return vc(e,{kid:t,apv:r})}function vc(e,t={}){return hc(e,void 0,t,{createKek:sc,alg:"ECDH-ES"},bc,{from:e=>oc(e),enc:"XC20P"})}function Ec(e,t,r={}){return hc(e,t,r,{createKek:ac,alg:"ECDH-1PU"},bc,{from:e=>oc(e),enc:"XC20P"})}function xc(e){return Ac(e)}function Ac(e){const t="ECDH-ES+XC20PKW";return{alg:t,enc:"XC20P",decrypt:function(r,n,o,i){try{const s=wc(i.header);return Promise.resolve(cc(i,e,t)).then((function(e){if(!e)return null;const t=Zi(i.encrypted_key,s.tag);return Promise.resolve(ic(e).decrypt(t,Ri(s.iv))).then((function(e){return null===e?null:ic(e).decrypt(r,n,o)}))}))}catch(e){return Promise.reject(e)}}}}function Bc(e,t){const r="ECDH-1PU+XC20PKW";return{alg:r,enc:"XC20P",decrypt:function(n,o,i,s){try{const c=wc(s.header);return Promise.resolve(fc(s,e,t,r)).then((function(e){if(!e)return null;const t=Zi(s.encrypted_key,c.tag);return Promise.resolve(ic(e).decrypt(t,Ri(c.iv))).then((function(e){return null===e?null:ic(e).decrypt(n,o,i)}))}))}catch(e){return Promise.reject(e)}}}}var Sc=n.xG,Ic=n.wB,kc=n.Eq,Pc=n.fD,Uc=n.hV,Tc=n.lA,Oc=n.fJ,Rc=n.rk,Nc=n.Kp,Kc=n.Tl,Lc=n.L6,Cc=n.My,Dc=n.n0,jc=n.So,$c=n.vz,_c=n.qU,Vc=n.Hk,Hc=n.DM,Jc=n.Pg,zc=n.jS,Wc=n.cu,Fc=n.Pt,Mc=n.PM,qc=n.WJ,Gc=n.p0,Zc=n.Xo,Xc=n.PC,Yc=n.Cg,Qc=n.Cq,ea=n.Ks,ta=n.NS,ra=n.V,na=n.aT,oa=n.fr,ia=n.uV,sa=n.k,ca=n.bm,aa=n.K,fa=n.RO,ua=n.Vd,ha=n.fG,da=n.K3,la=n.sg,pa=n.hc,ya=n.b3;export{Sc as ES256KSigner,Ic as ES256Signer,kc as EdDSASigner,Pc as EllipticSigner,Uc as JWT_ERROR,Tc as NaclSigner,Oc as SimpleSigner,Rc as base58ToBytes,Nc as base64ToBytes,Kc as bytesToBase58,Lc as bytesToBase64url,Cc as bytesToHex,Dc as bytesToMultibase,jc as computeX25519Ecdh1PUv3Kek,$c as computeX25519EcdhEsKek,_c as concatKDF,Vc as createAnonDecrypter,Hc as createAnonEncrypter,Jc as createAuthDecrypter,zc as createAuthEncrypter,Wc as createFullEncrypter,Fc as createJWE,Mc as createJWS,qc as createJWT,Gc as createMultisignatureJWT,Zc as createX25519ECDH,Xc as createX25519Ecdh1PUv3Kek,Yc as createX25519EcdhEsKek,Qc as decodeJWT,ea as decryptJWE,ta as extractPublicKeyBytes,ra as genX25519EphemeralKeyPair,na as hexToBytes,oa as multibaseToBytes,ia as resolveX25519Encrypters,sa as supportedCodecs,ca as toEthereumAddress,aa as verifyJWS,fa as verifyJWT,ua as x25519Decrypter,ha as x25519Encrypter,da as xc20pAuthDecrypterEcdh1PuV3x25519WithXc20PkwV2,la as xc20pAuthEncrypterEcdh1PuV3x25519WithXc20PkwV2,pa as xc20pDirDecrypter,ya as xc20pDirEncrypter};