@enbox/api 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +2 -2
- package/dist/browser.mjs.map +3 -3
- package/package.json +3 -3
package/dist/browser.mjs
CHANGED
|
@@ -7,7 +7,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
7
7
|
|| ${s} === "boolean" || ${i} === null`).assign(o,(0,kt._)`[${i}]`)}}}function UX({gen:t,parentData:e,parentDataProperty:r},n){t.if((0,kt._)`${e} !== undefined`,()=>t.assign((0,kt._)`${e}[${r}]`,n))}function Ck(t,e,r,n=jh.Correct){let i=n===jh.Correct?kt.operators.EQ:kt.operators.NEQ,a;switch(t){case"null":return(0,kt._)`${e} ${i} null`;case"array":a=(0,kt._)`Array.isArray(${e})`;break;case"object":a=(0,kt._)`${e} && typeof ${e} == "object" && !Array.isArray(${e})`;break;case"integer":a=s((0,kt._)`!(${e} % 1) && !isNaN(${e})`);break;case"number":a=s();break;default:return(0,kt._)`typeof ${e} ${i} ${t}`}return n===jh.Correct?a:(0,kt.not)(a);function s(o=kt.nil){return(0,kt.and)((0,kt._)`typeof ${e} == "number"`,o,r?(0,kt._)`isFinite(${e})`:kt.nil)}}to.checkDataType=Ck;function $k(t,e,r,n){if(t.length===1)return Ck(t[0],e,r,n);let i,a=(0,oM.toHash)(t);if(a.array&&a.object){let s=(0,kt._)`typeof ${e} != "object"`;i=a.null?s:(0,kt._)`!${e} || ${s}`,delete a.null,delete a.array,delete a.object}else i=kt.nil;a.number&&delete a.integer;for(let s in a)i=(0,kt.and)(i,Ck(s,e,r,n));return i}to.checkDataTypes=$k;var KX={message:({schema:t})=>`must be ${t}`,params:({schema:t,schemaValue:e})=>typeof t=="string"?(0,kt._)`{type: ${t}}`:(0,kt._)`{type: ${e}}`};function Ok(t){let e=qX(t);(0,OX.reportError)(e,KX)}to.reportTypeError=Ok;function qX(t){let{gen:e,data:r,schema:n}=t,i=(0,oM.schemaRefOrVal)(t,n,"type");return{gen:e,keyword:"type",data:r,schema:n.type,schemaCode:i,schemaValue:i,parentSchema:n,params:{},it:t}}});var dM=_e(c1=>{"use strict";y();Object.defineProperty(c1,"__esModule",{value:!0});c1.assignDefaults=void 0;var Mh=St(),LX=Ut();function zX(t,e){let{properties:r,items:n}=t.schema;if(e==="object"&&r)for(let i in r)cM(t,i,r[i].default);else e==="array"&&Array.isArray(n)&&n.forEach((i,a)=>cM(t,a,i.default))}c1.assignDefaults=zX;function cM(t,e,r){let{gen:n,compositeRule:i,data:a,opts:s}=t;if(r===void 0)return;let o=(0,Mh._)`${a}${(0,Mh.getProperty)(e)}`;if(i){(0,LX.checkStrictMode)(t,`default is ignored for: ${o}`);return}let d=(0,Mh._)`${o} === undefined`;s.useDefaults==="empty"&&(d=(0,Mh._)`${d} || ${o} === null || ${o} === ""`),n.if(d,(0,Mh._)`${o} = ${(0,Mh.stringify)(r)}`)}});var Ks=_e(kr=>{"use strict";y();Object.defineProperty(kr,"__esModule",{value:!0});kr.validateUnion=kr.validateArray=kr.usePattern=kr.callValidateCode=kr.schemaProperties=kr.allSchemaProperties=kr.noPropertyInData=kr.propertyInData=kr.isOwnProperty=kr.hasPropFunc=kr.reportMissingProp=kr.checkMissingProp=kr.checkReportMissingProp=void 0;var Wr=St(),Bk=Ut(),Au=Us(),FX=Ut();function GX(t,e){let{gen:r,data:n,it:i}=t;r.if(Mk(r,n,e,i.opts.ownProperties),()=>{t.setParams({missingProperty:(0,Wr._)`${e}`},!0),t.error()})}kr.checkReportMissingProp=GX;function WX({gen:t,data:e,it:{opts:r}},n,i){return(0,Wr.or)(...n.map(a=>(0,Wr.and)(Mk(t,e,a,r.ownProperties),(0,Wr._)`${i} = ${a}`)))}kr.checkMissingProp=WX;function HX(t,e){t.setParams({missingProperty:e},!0),t.error()}kr.reportMissingProp=HX;function uM(t){return t.scopeValue("func",{ref:Object.prototype.hasOwnProperty,code:(0,Wr._)`Object.prototype.hasOwnProperty`})}kr.hasPropFunc=uM;function jk(t,e,r){return(0,Wr._)`${uM(t)}.call(${e}, ${r})`}kr.isOwnProperty=jk;function VX(t,e,r,n){let i=(0,Wr._)`${e}${(0,Wr.getProperty)(r)} !== undefined`;return n?(0,Wr._)`${i} && ${jk(t,e,r)}`:i}kr.propertyInData=VX;function Mk(t,e,r,n){let i=(0,Wr._)`${e}${(0,Wr.getProperty)(r)} === undefined`;return n?(0,Wr.or)(i,(0,Wr.not)(jk(t,e,r))):i}kr.noPropertyInData=Mk;function lM(t){return t?Object.keys(t).filter(e=>e!=="__proto__"):[]}kr.allSchemaProperties=lM;function JX(t,e){return lM(e).filter(r=>!(0,Bk.alwaysValidSchema)(t,e[r]))}kr.schemaProperties=JX;function ZX({schemaCode:t,data:e,it:{gen:r,topSchemaRef:n,schemaPath:i,errorPath:a},it:s},o,d,u){let c=u?(0,Wr._)`${t}, ${e}, ${n}${i}`:e,l=[[Au.default.instancePath,(0,Wr.strConcat)(Au.default.instancePath,a)],[Au.default.parentData,s.parentData],[Au.default.parentDataProperty,s.parentDataProperty],[Au.default.rootData,Au.default.rootData]];s.opts.dynamicRef&&l.push([Au.default.dynamicAnchors,Au.default.dynamicAnchors]);let f=(0,Wr._)`${c}, ${r.object(...l)}`;return d!==Wr.nil?(0,Wr._)`${o}.call(${d}, ${f})`:(0,Wr._)`${o}(${f})`}kr.callValidateCode=ZX;var YX=(0,Wr._)`new RegExp`;function QX({gen:t,it:{opts:e}},r){let n=e.unicodeRegExp?"u":"",{regExp:i}=e.code,a=i(r,n);return t.scopeValue("pattern",{key:a.toString(),ref:a,code:(0,Wr._)`${i.code==="new RegExp"?YX:(0,FX.useFunc)(t,i)}(${r}, ${n})`})}kr.usePattern=QX;function XX(t){let{gen:e,data:r,keyword:n,it:i}=t,a=e.name("valid");if(i.allErrors){let o=e.let("valid",!0);return s(()=>e.assign(o,!1)),o}return e.var(a,!0),s(()=>e.break()),a;function s(o){let d=e.const("len",(0,Wr._)`${r}.length`);e.forRange("i",0,d,u=>{t.subschema({keyword:n,dataProp:u,dataPropType:Bk.Type.Num},a),e.if((0,Wr.not)(a),o)})}}kr.validateArray=XX;function eee(t){let{gen:e,schema:r,keyword:n,it:i}=t;if(!Array.isArray(r))throw new Error("ajv implementation error");if(r.some(d=>(0,Bk.alwaysValidSchema)(i,d))&&!i.opts.unevaluated)return;let s=e.let("valid",!1),o=e.name("_valid");e.block(()=>r.forEach((d,u)=>{let c=t.subschema({keyword:n,schemaProp:u,compositeRule:!0},o);e.assign(s,(0,Wr._)`${s} || ${o}`),t.mergeValidEvaluated(c,o)||e.if((0,Wr.not)(s))})),t.result(s,()=>t.reset(),()=>t.error(!0))}kr.validateUnion=eee});var hM=_e(gc=>{"use strict";y();Object.defineProperty(gc,"__esModule",{value:!0});gc.validateKeywordUsage=gc.validSchemaType=gc.funcKeywordCode=gc.macroKeywordCode=void 0;var Eo=St(),gf=Us(),tee=Ks(),ree=Hg();function nee(t,e){let{gen:r,keyword:n,schema:i,parentSchema:a,it:s}=t,o=e.macro.call(s.self,i,a,s),d=pM(r,n,o);s.opts.validateSchema!==!1&&s.self.validateSchema(o,!0);let u=r.name("valid");t.subschema({schema:o,schemaPath:Eo.nil,errSchemaPath:`${s.errSchemaPath}/${n}`,topSchemaRef:d,compositeRule:!0},u),t.pass(u,()=>t.error(!0))}gc.macroKeywordCode=nee;function iee(t,e){var r;let{gen:n,keyword:i,schema:a,parentSchema:s,$data:o,it:d}=t;see(d,e);let u=!o&&e.compile?e.compile.call(d.self,a,s,d):e.validate,c=pM(n,i,u),l=n.let("valid");t.block$data(l,f),t.ok((r=e.valid)!==null&&r!==void 0?r:l);function f(){if(e.errors===!1)m(),e.modifying&&fM(t),g(()=>t.error());else{let _=e.async?h():p();e.modifying&&fM(t),g(()=>oee(t,_))}}function h(){let _=n.let("ruleErrs",null);return n.try(()=>m((0,Eo._)`await `),v=>n.assign(l,!1).if((0,Eo._)`${v} instanceof ${d.ValidationError}`,()=>n.assign(_,(0,Eo._)`${v}.errors`),()=>n.throw(v))),_}function p(){let _=(0,Eo._)`${c}.errors`;return n.assign(_,null),m(Eo.nil),_}function m(_=e.async?(0,Eo._)`await `:Eo.nil){let v=d.opts.passContext?gf.default.this:gf.default.self,E=!("compile"in e&&!o||e.schema===!1);n.assign(l,(0,Eo._)`${_}${(0,tee.callValidateCode)(t,c,v,E)}`,e.modifying)}function g(_){var v;n.if((0,Eo.not)((v=e.valid)!==null&&v!==void 0?v:l),_)}}gc.funcKeywordCode=iee;function fM(t){let{gen:e,data:r,it:n}=t;e.if(n.parentData,()=>e.assign(r,(0,Eo._)`${n.parentData}[${n.parentDataProperty}]`))}function oee(t,e){let{gen:r}=t;r.if((0,Eo._)`Array.isArray(${e})`,()=>{r.assign(gf.default.vErrors,(0,Eo._)`${gf.default.vErrors} === null ? ${e} : ${gf.default.vErrors}.concat(${e})`).assign(gf.default.errors,(0,Eo._)`${gf.default.vErrors}.length`),(0,ree.extendErrors)(t)},()=>t.error())}function see({schemaEnv:t},e){if(e.async&&!t.$async)throw new Error("async keyword in sync schema")}function pM(t,e,r){if(r===void 0)throw new Error(`keyword "${e}" failed to compile`);return t.scopeValue("keyword",typeof r=="function"?{ref:r}:{ref:r,code:(0,Eo.stringify)(r)})}function aee(t,e,r=!1){return!e.length||e.some(n=>n==="array"?Array.isArray(t):n==="object"?t&&typeof t=="object"&&!Array.isArray(t):typeof t==n||r&&typeof t>"u")}gc.validSchemaType=aee;function cee({schema:t,opts:e,self:r,errSchemaPath:n},i,a){if(Array.isArray(i.keyword)?!i.keyword.includes(a):i.keyword!==a)throw new Error("ajv implementation error");let s=i.dependencies;if(s?.some(o=>!Object.prototype.hasOwnProperty.call(t,o)))throw new Error(`parent schema must have dependencies of ${a}: ${s.join(",")}`);if(i.validateSchema&&!i.validateSchema(t[a])){let d=`keyword "${a}" value is invalid at path "${n}": `+r.errorsText(i.validateSchema.errors);if(e.validateSchema==="log")r.logger.error(d);else throw new Error(d)}}gc.validateKeywordUsage=cee});var yM=_e(Du=>{"use strict";y();Object.defineProperty(Du,"__esModule",{value:!0});Du.extendSubschemaMode=Du.extendSubschemaData=Du.getSubschema=void 0;var wc=St(),mM=Ut();function dee(t,{keyword:e,schemaProp:r,schema:n,schemaPath:i,errSchemaPath:a,topSchemaRef:s}){if(e!==void 0&&n!==void 0)throw new Error('both "keyword" and "schema" passed, only one allowed');if(e!==void 0){let o=t.schema[e];return r===void 0?{schema:o,schemaPath:(0,wc._)`${t.schemaPath}${(0,wc.getProperty)(e)}`,errSchemaPath:`${t.errSchemaPath}/${e}`}:{schema:o[r],schemaPath:(0,wc._)`${t.schemaPath}${(0,wc.getProperty)(e)}${(0,wc.getProperty)(r)}`,errSchemaPath:`${t.errSchemaPath}/${e}/${(0,mM.escapeFragment)(r)}`}}if(n!==void 0){if(i===void 0||a===void 0||s===void 0)throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');return{schema:n,schemaPath:i,topSchemaRef:s,errSchemaPath:a}}throw new Error('either "keyword" or "schema" must be passed')}Du.getSubschema=dee;function uee(t,e,{dataProp:r,dataPropType:n,data:i,dataTypes:a,propertyName:s}){if(i!==void 0&&r!==void 0)throw new Error('both "data" and "dataProp" passed, only one allowed');let{gen:o}=e;if(r!==void 0){let{errorPath:u,dataPathArr:c,opts:l}=e,f=o.let("data",(0,wc._)`${e.data}${(0,wc.getProperty)(r)}`,!0);d(f),t.errorPath=(0,wc.str)`${u}${(0,mM.getErrorPath)(r,n,l.jsPropertySyntax)}`,t.parentDataProperty=(0,wc._)`${r}`,t.dataPathArr=[...c,t.parentDataProperty]}if(i!==void 0){let u=i instanceof wc.Name?i:o.let("data",i,!0);d(u),s!==void 0&&(t.propertyName=s)}a&&(t.dataTypes=a);function d(u){t.data=u,t.dataLevel=e.dataLevel+1,t.dataTypes=[],e.definedProperties=new Set,t.parentData=e.data,t.dataNames=[...e.dataNames,u]}}Du.extendSubschemaData=uee;function lee(t,{jtdDiscriminator:e,jtdMetadata:r,compositeRule:n,createErrors:i,allErrors:a}){n!==void 0&&(t.compositeRule=n),i!==void 0&&(t.createErrors=i),a!==void 0&&(t.allErrors=a),t.jtdDiscriminator=e,t.jtdMetadata=r}Du.extendSubschemaMode=lee});var Nk=_e((N5e,gM)=>{"use strict";y();gM.exports=function t(e,r){if(e===r)return!0;if(e&&r&&typeof e=="object"&&typeof r=="object"){if(e.constructor!==r.constructor)return!1;var n,i,a;if(Array.isArray(e)){if(n=e.length,n!=r.length)return!1;for(i=n;i--!==0;)if(!t(e[i],r[i]))return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===r.toString();if(a=Object.keys(e),n=a.length,n!==Object.keys(r).length)return!1;for(i=n;i--!==0;)if(!Object.prototype.hasOwnProperty.call(r,a[i]))return!1;for(i=n;i--!==0;){var s=a[i];if(!t(e[s],r[s]))return!1}return!0}return e!==e&&r!==r}});var vM=_e((K5e,wM)=>{"use strict";y();var Iu=wM.exports=function(t,e,r){typeof e=="function"&&(r=e,e={}),r=e.cb||r;var n=typeof r=="function"?r:r.pre||function(){},i=r.post||function(){};d1(e,n,i,t,"",t)};Iu.keywords={additionalItems:!0,items:!0,contains:!0,additionalProperties:!0,propertyNames:!0,not:!0,if:!0,then:!0,else:!0};Iu.arrayKeywords={items:!0,allOf:!0,anyOf:!0,oneOf:!0};Iu.propsKeywords={$defs:!0,definitions:!0,properties:!0,patternProperties:!0,dependencies:!0};Iu.skipKeywords={default:!0,enum:!0,const:!0,required:!0,maximum:!0,minimum:!0,exclusiveMaximum:!0,exclusiveMinimum:!0,multipleOf:!0,maxLength:!0,minLength:!0,pattern:!0,format:!0,maxItems:!0,minItems:!0,uniqueItems:!0,maxProperties:!0,minProperties:!0};function d1(t,e,r,n,i,a,s,o,d,u){if(n&&typeof n=="object"&&!Array.isArray(n)){e(n,i,a,s,o,d,u);for(var c in n){var l=n[c];if(Array.isArray(l)){if(c in Iu.arrayKeywords)for(var f=0;f<l.length;f++)d1(t,e,r,l[f],i+"/"+c+"/"+f,a,i,c,n,f)}else if(c in Iu.propsKeywords){if(l&&typeof l=="object")for(var h in l)d1(t,e,r,l[h],i+"/"+c+"/"+fee(h),a,i,c,n,h)}else(c in Iu.keywords||t.allKeys&&!(c in Iu.skipKeywords))&&d1(t,e,r,l,i+"/"+c,a,i,c,n)}r(n,i,a,s,o,d,u)}}function fee(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}});var Jg=_e(Uo=>{"use strict";y();Object.defineProperty(Uo,"__esModule",{value:!0});Uo.getSchemaRefs=Uo.resolveUrl=Uo.normalizeId=Uo._getFullPath=Uo.getFullPath=Uo.inlineRef=void 0;var pee=Ut(),hee=Nk(),mee=vM(),yee=new Set(["type","format","pattern","maxLength","minLength","maxProperties","minProperties","maxItems","minItems","maximum","minimum","uniqueItems","multipleOf","required","enum","const"]);function gee(t,e=!0){return typeof t=="boolean"?!0:e===!0?!Uk(t):e?bM(t)<=e:!1}Uo.inlineRef=gee;var wee=new Set(["$ref","$recursiveRef","$recursiveAnchor","$dynamicRef","$dynamicAnchor"]);function Uk(t){for(let e in t){if(wee.has(e))return!0;let r=t[e];if(Array.isArray(r)&&r.some(Uk)||typeof r=="object"&&Uk(r))return!0}return!1}function bM(t){let e=0;for(let r in t){if(r==="$ref")return 1/0;if(e++,!yee.has(r)&&(typeof t[r]=="object"&&(0,pee.eachItem)(t[r],n=>e+=bM(n)),e===1/0))return 1/0}return e}function xM(t,e="",r){r!==!1&&(e=Nh(e));let n=t.parse(e);return PM(t,n)}Uo.getFullPath=xM;function PM(t,e){return t.serialize(e).split("#")[0]+"#"}Uo._getFullPath=PM;var vee=/#\/?$/;function Nh(t){return t?t.replace(vee,""):""}Uo.normalizeId=Nh;function bee(t,e,r){return r=Nh(r),t.resolve(e,r)}Uo.resolveUrl=bee;var xee=/^[a-z_][-a-z0-9._]*$/i;function Pee(t,e){if(typeof t=="boolean")return{};let{schemaId:r,uriResolver:n}=this.opts,i=Nh(t[r]||e),a={"":i},s=xM(n,i,!1),o={},d=new Set;return mee(t,{allKeys:!0},(l,f,h,p)=>{if(p===void 0)return;let m=s+f,g=a[p];typeof l[r]=="string"&&(g=_.call(this,l[r])),v.call(this,l.$anchor),v.call(this,l.$dynamicAnchor),a[f]=g;function _(E){let T=this.opts.uriResolver.resolve;if(E=Nh(g?T(g,E):E),d.has(E))throw c(E);d.add(E);let D=this.refs[E];return typeof D=="string"&&(D=this.refs[D]),typeof D=="object"?u(l,D.schema,E):E!==Nh(m)&&(E[0]==="#"?(u(l,o[E],E),o[E]=l):this.refs[E]=m),E}function v(E){if(typeof E=="string"){if(!xee.test(E))throw new Error(`invalid anchor "${E}"`);_.call(this,`#${E}`)}}}),o;function u(l,f,h){if(f!==void 0&&!hee(l,f))throw c(h)}function c(l){return new Error(`reference "${l}" resolves to more than one schema`)}}Uo.getSchemaRefs=Pee});var Qg=_e(Ru=>{"use strict";y();Object.defineProperty(Ru,"__esModule",{value:!0});Ru.getData=Ru.KeywordCxt=Ru.validateFunctionCode=void 0;var kM=rM(),_M=Vg(),qk=Rk(),u1=Vg(),_ee=dM(),Yg=hM(),Kk=yM(),Ze=St(),gt=Us(),Eee=Jg(),wd=Ut(),Zg=Hg();function See(t){if(IM(t)&&(RM(t),DM(t))){Aee(t);return}AM(t,()=>(0,kM.topBoolOrEmptySchema)(t))}Ru.validateFunctionCode=See;function AM({gen:t,validateName:e,schema:r,schemaEnv:n,opts:i},a){i.code.es5?t.func(e,(0,Ze._)`${gt.default.data}, ${gt.default.valCxt}`,n.$async,()=>{t.code((0,Ze._)`"use strict"; ${EM(r,i)}`),kee(t,i),t.code(a)}):t.func(e,(0,Ze._)`${gt.default.data}, ${Tee(i)}`,n.$async,()=>t.code(EM(r,i)).code(a))}function Tee(t){return(0,Ze._)`{${gt.default.instancePath}="", ${gt.default.parentData}, ${gt.default.parentDataProperty}, ${gt.default.rootData}=${gt.default.data}${t.dynamicRef?(0,Ze._)`, ${gt.default.dynamicAnchors}={}`:Ze.nil}}={}`}function kee(t,e){t.if(gt.default.valCxt,()=>{t.var(gt.default.instancePath,(0,Ze._)`${gt.default.valCxt}.${gt.default.instancePath}`),t.var(gt.default.parentData,(0,Ze._)`${gt.default.valCxt}.${gt.default.parentData}`),t.var(gt.default.parentDataProperty,(0,Ze._)`${gt.default.valCxt}.${gt.default.parentDataProperty}`),t.var(gt.default.rootData,(0,Ze._)`${gt.default.valCxt}.${gt.default.rootData}`),e.dynamicRef&&t.var(gt.default.dynamicAnchors,(0,Ze._)`${gt.default.valCxt}.${gt.default.dynamicAnchors}`)},()=>{t.var(gt.default.instancePath,(0,Ze._)`""`),t.var(gt.default.parentData,(0,Ze._)`undefined`),t.var(gt.default.parentDataProperty,(0,Ze._)`undefined`),t.var(gt.default.rootData,gt.default.data),e.dynamicRef&&t.var(gt.default.dynamicAnchors,(0,Ze._)`{}`)})}function Aee(t){let{schema:e,opts:r,gen:n}=t;AM(t,()=>{r.$comment&&e.$comment&&$M(t),$ee(t),n.let(gt.default.vErrors,null),n.let(gt.default.errors,0),r.unevaluated&&Dee(t),CM(t),jee(t)})}function Dee(t){let{gen:e,validateName:r}=t;t.evaluated=e.const("evaluated",(0,Ze._)`${r}.evaluated`),e.if((0,Ze._)`${t.evaluated}.dynamicProps`,()=>e.assign((0,Ze._)`${t.evaluated}.props`,(0,Ze._)`undefined`)),e.if((0,Ze._)`${t.evaluated}.dynamicItems`,()=>e.assign((0,Ze._)`${t.evaluated}.items`,(0,Ze._)`undefined`))}function EM(t,e){let r=typeof t=="object"&&t[e.schemaId];return r&&(e.code.source||e.code.process)?(0,Ze._)`/*# sourceURL=${r} */`:Ze.nil}function Iee(t,e){if(IM(t)&&(RM(t),DM(t))){Ree(t,e);return}(0,kM.boolOrEmptySchema)(t,e)}function DM({schema:t,self:e}){if(typeof t=="boolean")return!t;for(let r in t)if(e.RULES.all[r])return!0;return!1}function IM(t){return typeof t.schema!="boolean"}function Ree(t,e){let{schema:r,gen:n,opts:i}=t;i.$comment&&r.$comment&&$M(t),Oee(t),Bee(t);let a=n.const("_errs",gt.default.errors);CM(t,a),n.var(e,(0,Ze._)`${a} === ${gt.default.errors}`)}function RM(t){(0,wd.checkUnknownRules)(t),Cee(t)}function CM(t,e){if(t.opts.jtd)return SM(t,[],!1,e);let r=(0,_M.getSchemaTypes)(t.schema),n=(0,_M.coerceAndCheckDataType)(t,r);SM(t,r,!n,e)}function Cee(t){let{schema:e,errSchemaPath:r,opts:n,self:i}=t;e.$ref&&n.ignoreKeywordsWithRef&&(0,wd.schemaHasRulesButRef)(e,i.RULES)&&i.logger.warn(`$ref: keywords ignored in schema at path "${r}"`)}function $ee(t){let{schema:e,opts:r}=t;e.default!==void 0&&r.useDefaults&&r.strictSchema&&(0,wd.checkStrictMode)(t,"default is ignored in the schema root")}function Oee(t){let e=t.schema[t.opts.schemaId];e&&(t.baseId=(0,Eee.resolveUrl)(t.opts.uriResolver,t.baseId,e))}function Bee(t){if(t.schema.$async&&!t.schemaEnv.$async)throw new Error("async schema in sync schema")}function $M({gen:t,schemaEnv:e,schema:r,errSchemaPath:n,opts:i}){let a=r.$comment;if(i.$comment===!0)t.code((0,Ze._)`${gt.default.self}.logger.log(${a})`);else if(typeof i.$comment=="function"){let s=(0,Ze.str)`${n}/$comment`,o=t.scopeValue("root",{ref:e.root});t.code((0,Ze._)`${gt.default.self}.opts.$comment(${a}, ${s}, ${o}.schema)`)}}function jee(t){let{gen:e,schemaEnv:r,validateName:n,ValidationError:i,opts:a}=t;r.$async?e.if((0,Ze._)`${gt.default.errors} === 0`,()=>e.return(gt.default.data),()=>e.throw((0,Ze._)`new ${i}(${gt.default.vErrors})`)):(e.assign((0,Ze._)`${n}.errors`,gt.default.vErrors),a.unevaluated&&Mee(t),e.return((0,Ze._)`${gt.default.errors} === 0`))}function Mee({gen:t,evaluated:e,props:r,items:n}){r instanceof Ze.Name&&t.assign((0,Ze._)`${e}.props`,r),n instanceof Ze.Name&&t.assign((0,Ze._)`${e}.items`,n)}function SM(t,e,r,n){let{gen:i,schema:a,data:s,allErrors:o,opts:d,self:u}=t,{RULES:c}=u;if(a.$ref&&(d.ignoreKeywordsWithRef||!(0,wd.schemaHasRulesButRef)(a,c))){i.block(()=>BM(t,"$ref",c.all.$ref.definition));return}d.jtd||Nee(t,e),i.block(()=>{for(let f of c.rules)l(f);l(c.post)});function l(f){(0,qk.shouldUseGroup)(a,f)&&(f.type?(i.if((0,u1.checkDataType)(f.type,s,d.strictNumbers)),TM(t,f),e.length===1&&e[0]===f.type&&r&&(i.else(),(0,u1.reportTypeError)(t)),i.endIf()):TM(t,f),o||i.if((0,Ze._)`${gt.default.errors} === ${n||0}`))}}function TM(t,e){let{gen:r,schema:n,opts:{useDefaults:i}}=t;i&&(0,_ee.assignDefaults)(t,e.type),r.block(()=>{for(let a of e.rules)(0,qk.shouldUseRule)(n,a)&&BM(t,a.keyword,a.definition,e.type)})}function Nee(t,e){t.schemaEnv.meta||!t.opts.strictTypes||(Uee(t,e),t.opts.allowUnionTypes||Kee(t,e),qee(t,t.dataTypes))}function Uee(t,e){if(e.length){if(!t.dataTypes.length){t.dataTypes=e;return}e.forEach(r=>{OM(t.dataTypes,r)||Lk(t,`type "${r}" not allowed by context "${t.dataTypes.join(",")}"`)}),zee(t,e)}}function Kee(t,e){e.length>1&&!(e.length===2&&e.includes("null"))&&Lk(t,"use allowUnionTypes to allow union type keyword")}function qee(t,e){let r=t.self.RULES.all;for(let n in r){let i=r[n];if(typeof i=="object"&&(0,qk.shouldUseRule)(t.schema,i)){let{type:a}=i.definition;a.length&&!a.some(s=>Lee(e,s))&&Lk(t,`missing type "${a.join(",")}" for keyword "${n}"`)}}}function Lee(t,e){return t.includes(e)||e==="number"&&t.includes("integer")}function OM(t,e){return t.includes(e)||e==="integer"&&t.includes("number")}function zee(t,e){let r=[];for(let n of t.dataTypes)OM(e,n)?r.push(n):e.includes("integer")&&n==="number"&&r.push("integer");t.dataTypes=r}function Lk(t,e){let r=t.schemaEnv.baseId+t.errSchemaPath;e+=` at "${r}" (strictTypes)`,(0,wd.checkStrictMode)(t,e,t.opts.strictTypes)}var l1=class{constructor(e,r,n){if((0,Yg.validateKeywordUsage)(e,r,n),this.gen=e.gen,this.allErrors=e.allErrors,this.keyword=n,this.data=e.data,this.schema=e.schema[n],this.$data=r.$data&&e.opts.$data&&this.schema&&this.schema.$data,this.schemaValue=(0,wd.schemaRefOrVal)(e,this.schema,n,this.$data),this.schemaType=r.schemaType,this.parentSchema=e.schema,this.params={},this.it=e,this.def=r,this.$data)this.schemaCode=e.gen.const("vSchema",jM(this.$data,e));else if(this.schemaCode=this.schemaValue,!(0,Yg.validSchemaType)(this.schema,r.schemaType,r.allowUndefined))throw new Error(`${n} value must be ${JSON.stringify(r.schemaType)}`);("code"in r?r.trackErrors:r.errors!==!1)&&(this.errsCount=e.gen.const("_errs",gt.default.errors))}result(e,r,n){this.failResult((0,Ze.not)(e),r,n)}failResult(e,r,n){this.gen.if(e),n?n():this.error(),r?(this.gen.else(),r(),this.allErrors&&this.gen.endIf()):this.allErrors?this.gen.endIf():this.gen.else()}pass(e,r){this.failResult((0,Ze.not)(e),void 0,r)}fail(e){if(e===void 0){this.error(),this.allErrors||this.gen.if(!1);return}this.gen.if(e),this.error(),this.allErrors?this.gen.endIf():this.gen.else()}fail$data(e){if(!this.$data)return this.fail(e);let{schemaCode:r}=this;this.fail((0,Ze._)`${r} !== undefined && (${(0,Ze.or)(this.invalid$data(),e)})`)}error(e,r,n){if(r){this.setParams(r),this._error(e,n),this.setParams({});return}this._error(e,n)}_error(e,r){(e?Zg.reportExtraError:Zg.reportError)(this,this.def.error,r)}$dataError(){(0,Zg.reportError)(this,this.def.$dataError||Zg.keyword$DataError)}reset(){if(this.errsCount===void 0)throw new Error('add "trackErrors" to keyword definition');(0,Zg.resetErrorsCount)(this.gen,this.errsCount)}ok(e){this.allErrors||this.gen.if(e)}setParams(e,r){r?Object.assign(this.params,e):this.params=e}block$data(e,r,n=Ze.nil){this.gen.block(()=>{this.check$data(e,n),r()})}check$data(e=Ze.nil,r=Ze.nil){if(!this.$data)return;let{gen:n,schemaCode:i,schemaType:a,def:s}=this;n.if((0,Ze.or)((0,Ze._)`${i} === undefined`,r)),e!==Ze.nil&&n.assign(e,!0),(a.length||s.validateSchema)&&(n.elseIf(this.invalid$data()),this.$dataError(),e!==Ze.nil&&n.assign(e,!1)),n.else()}invalid$data(){let{gen:e,schemaCode:r,schemaType:n,def:i,it:a}=this;return(0,Ze.or)(s(),o());function s(){if(n.length){if(!(r instanceof Ze.Name))throw new Error("ajv implementation error");let d=Array.isArray(n)?n:[n];return(0,Ze._)`${(0,u1.checkDataTypes)(d,r,a.opts.strictNumbers,u1.DataType.Wrong)}`}return Ze.nil}function o(){if(i.validateSchema){let d=e.scopeValue("validate$data",{ref:i.validateSchema});return(0,Ze._)`!${d}(${r})`}return Ze.nil}}subschema(e,r){let n=(0,Kk.getSubschema)(this.it,e);(0,Kk.extendSubschemaData)(n,this.it,e),(0,Kk.extendSubschemaMode)(n,e);let i={...this.it,...n,items:void 0,props:void 0};return Iee(i,r),i}mergeEvaluated(e,r){let{it:n,gen:i}=this;n.opts.unevaluated&&(n.props!==!0&&e.props!==void 0&&(n.props=wd.mergeEvaluated.props(i,e.props,n.props,r)),n.items!==!0&&e.items!==void 0&&(n.items=wd.mergeEvaluated.items(i,e.items,n.items,r)))}mergeValidEvaluated(e,r){let{it:n,gen:i}=this;if(n.opts.unevaluated&&(n.props!==!0||n.items!==!0))return i.if(r,()=>this.mergeEvaluated(e,Ze.Name)),!0}};Ru.KeywordCxt=l1;function BM(t,e,r,n){let i=new l1(t,r,e);"code"in r?r.code(i,n):i.$data&&r.validate?(0,Yg.funcKeywordCode)(i,r):"macro"in r?(0,Yg.macroKeywordCode)(i,r):(r.compile||r.validate)&&(0,Yg.funcKeywordCode)(i,r)}var Fee=/^\/(?:[^~]|~0|~1)*$/,Gee=/^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;function jM(t,{dataLevel:e,dataNames:r,dataPathArr:n}){let i,a;if(t==="")return gt.default.rootData;if(t[0]==="/"){if(!Fee.test(t))throw new Error(`Invalid JSON-pointer: ${t}`);i=t,a=gt.default.rootData}else{let u=Gee.exec(t);if(!u)throw new Error(`Invalid JSON-pointer: ${t}`);let c=+u[1];if(i=u[2],i==="#"){if(c>=e)throw new Error(d("property/index",c));return n[e-c]}if(c>e)throw new Error(d("data",c));if(a=r[e-c],!i)return a}let s=a,o=i.split("/");for(let u of o)u&&(a=(0,Ze._)`${a}${(0,Ze.getProperty)((0,wd.unescapeJsonPointer)(u))}`,s=(0,Ze._)`${s} && ${a}`);return s;function d(u,c){return`Cannot access ${u} ${c} levels up, current level is ${e}`}}Ru.getData=jM});var f1=_e(Fk=>{"use strict";y();Object.defineProperty(Fk,"__esModule",{value:!0});var zk=class extends Error{constructor(e){super("validation failed"),this.errors=e,this.ajv=this.validation=!0}};Fk.default=zk});var Xg=_e(Hk=>{"use strict";y();Object.defineProperty(Hk,"__esModule",{value:!0});var Gk=Jg(),Wk=class extends Error{constructor(e,r,n,i){super(i||`can't resolve reference ${n} from id ${r}`),this.missingRef=(0,Gk.resolveUrl)(e,r,n),this.missingSchema=(0,Gk.normalizeId)((0,Gk.getFullPath)(e,this.missingRef))}};Hk.default=Wk});var ew=_e(qs=>{"use strict";y();Object.defineProperty(qs,"__esModule",{value:!0});qs.resolveSchema=qs.getCompilingSchema=qs.resolveRef=qs.compileSchema=qs.SchemaEnv=void 0;var Oa=St(),Wee=f1(),wf=Us(),Ba=Jg(),MM=Ut(),Hee=Qg(),Uh=class{constructor(e){var r;this.refs={},this.dynamicAnchors={};let n;typeof e.schema=="object"&&(n=e.schema),this.schema=e.schema,this.schemaId=e.schemaId,this.root=e.root||this,this.baseId=(r=e.baseId)!==null&&r!==void 0?r:(0,Ba.normalizeId)(n?.[e.schemaId||"$id"]),this.schemaPath=e.schemaPath,this.localRefs=e.localRefs,this.meta=e.meta,this.$async=n?.$async,this.refs={}}};qs.SchemaEnv=Uh;function Jk(t){let e=NM.call(this,t);if(e)return e;let r=(0,Ba.getFullPath)(this.opts.uriResolver,t.root.baseId),{es5:n,lines:i}=this.opts.code,{ownProperties:a}=this.opts,s=new Oa.CodeGen(this.scope,{es5:n,lines:i,ownProperties:a}),o;t.$async&&(o=s.scopeValue("Error",{ref:Wee.default,code:(0,Oa._)`require("ajv/dist/runtime/validation_error").default`}));let d=s.scopeName("validate");t.validateName=d;let u={gen:s,allErrors:this.opts.allErrors,data:wf.default.data,parentData:wf.default.parentData,parentDataProperty:wf.default.parentDataProperty,dataNames:[wf.default.data],dataPathArr:[Oa.nil],dataLevel:0,dataTypes:[],definedProperties:new Set,topSchemaRef:s.scopeValue("schema",this.opts.code.source===!0?{ref:t.schema,code:(0,Oa.stringify)(t.schema)}:{ref:t.schema}),validateName:d,ValidationError:o,schema:t.schema,schemaEnv:t,rootId:r,baseId:t.baseId||r,schemaPath:Oa.nil,errSchemaPath:t.schemaPath||(this.opts.jtd?"":"#"),errorPath:(0,Oa._)`""`,opts:this.opts,self:this},c;try{this._compilations.add(t),(0,Hee.validateFunctionCode)(u),s.optimize(this.opts.code.optimize);let l=s.toString();c=`${s.scopeRefs(wf.default.scope)}return ${l}`,this.opts.code.process&&(c=this.opts.code.process(c,t));let h=new Function(`${wf.default.self}`,`${wf.default.scope}`,c)(this,this.scope.get());if(this.scope.value(d,{ref:h}),h.errors=null,h.schema=t.schema,h.schemaEnv=t,t.$async&&(h.$async=!0),this.opts.code.source===!0&&(h.source={validateName:d,validateCode:l,scopeValues:s._values}),this.opts.unevaluated){let{props:p,items:m}=u;h.evaluated={props:p instanceof Oa.Name?void 0:p,items:m instanceof Oa.Name?void 0:m,dynamicProps:p instanceof Oa.Name,dynamicItems:m instanceof Oa.Name},h.source&&(h.source.evaluated=(0,Oa.stringify)(h.evaluated))}return t.validate=h,t}catch(l){throw delete t.validate,delete t.validateName,c&&this.logger.error("Error compiling schema, function code:",c),l}finally{this._compilations.delete(t)}}qs.compileSchema=Jk;function Vee(t,e,r){var n;r=(0,Ba.resolveUrl)(this.opts.uriResolver,e,r);let i=t.refs[r];if(i)return i;let a=Yee.call(this,t,r);if(a===void 0){let s=(n=t.localRefs)===null||n===void 0?void 0:n[r],{schemaId:o}=this.opts;s&&(a=new Uh({schema:s,schemaId:o,root:t,baseId:e}))}if(a!==void 0)return t.refs[r]=Jee.call(this,a)}qs.resolveRef=Vee;function Jee(t){return(0,Ba.inlineRef)(t.schema,this.opts.inlineRefs)?t.schema:t.validate?t:Jk.call(this,t)}function NM(t){for(let e of this._compilations)if(Zee(e,t))return e}qs.getCompilingSchema=NM;function Zee(t,e){return t.schema===e.schema&&t.root===e.root&&t.baseId===e.baseId}function Yee(t,e){let r;for(;typeof(r=this.refs[e])=="string";)e=r;return r||this.schemas[e]||p1.call(this,t,e)}function p1(t,e){let r=this.opts.uriResolver.parse(e),n=(0,Ba._getFullPath)(this.opts.uriResolver,r),i=(0,Ba.getFullPath)(this.opts.uriResolver,t.baseId,void 0);if(Object.keys(t.schema).length>0&&n===i)return Vk.call(this,r,t);let a=(0,Ba.normalizeId)(n),s=this.refs[a]||this.schemas[a];if(typeof s=="string"){let o=p1.call(this,t,s);return typeof o?.schema!="object"?void 0:Vk.call(this,r,o)}if(typeof s?.schema=="object"){if(s.validate||Jk.call(this,s),a===(0,Ba.normalizeId)(e)){let{schema:o}=s,{schemaId:d}=this.opts,u=o[d];return u&&(i=(0,Ba.resolveUrl)(this.opts.uriResolver,i,u)),new Uh({schema:o,schemaId:d,root:t,baseId:i})}return Vk.call(this,r,s)}}qs.resolveSchema=p1;var Qee=new Set(["properties","patternProperties","enum","dependencies","definitions"]);function Vk(t,{baseId:e,schema:r,root:n}){var i;if(((i=t.fragment)===null||i===void 0?void 0:i[0])!=="/")return;for(let o of t.fragment.slice(1).split("/")){if(typeof r=="boolean")return;let d=r[(0,MM.unescapeFragment)(o)];if(d===void 0)return;r=d;let u=typeof r=="object"&&r[this.opts.schemaId];!Qee.has(o)&&u&&(e=(0,Ba.resolveUrl)(this.opts.uriResolver,e,u))}let a;if(typeof r!="boolean"&&r.$ref&&!(0,MM.schemaHasRulesButRef)(r,this.RULES)){let o=(0,Ba.resolveUrl)(this.opts.uriResolver,e,r.$ref);a=p1.call(this,n,o)}let{schemaId:s}=this.opts;if(a=a||new Uh({schema:r,schemaId:s,root:n,baseId:e}),a.schema!==a.root.schema)return a}});var UM=_e((Q5e,Xee)=>{Xee.exports={$id:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",description:"Meta-schema for $data reference (JSON AnySchema extension proposal)",type:"object",required:["$data"],properties:{$data:{type:"string",anyOf:[{format:"relative-json-pointer"},{format:"json-pointer"}]}},additionalProperties:!1}});var Yk=_e((X5e,zM)=>{"use strict";y();var ete=RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu),qM=RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);function Zk(t){let e="",r=0,n=0;for(n=0;n<t.length;n++)if(r=t[n].charCodeAt(0),r!==48){if(!(r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102))return"";e+=t[n];break}for(n+=1;n<t.length;n++){if(r=t[n].charCodeAt(0),!(r>=48&&r<=57||r>=65&&r<=70||r>=97&&r<=102))return"";e+=t[n]}return e}var tte=RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);function KM(t){return t.length=0,!0}function rte(t,e,r){if(t.length){let n=Zk(t);if(n!=="")e.push(n);else return r.error=!0,!1;t.length=0}return!0}function nte(t){let e=0,r={error:!1,address:"",zone:""},n=[],i=[],a=!1,s=!1,o=rte;for(let d=0;d<t.length;d++){let u=t[d];if(!(u==="["||u==="]"))if(u===":"){if(a===!0&&(s=!0),!o(i,n,r))break;if(++e>7){r.error=!0;break}d>0&&t[d-1]===":"&&(a=!0),n.push(":");continue}else if(u==="%"){if(!o(i,n,r))break;o=KM}else{i.push(u);continue}}return i.length&&(o===KM?r.zone=i.join(""):s?n.push(i.join("")):n.push(Zk(i))),r.address=n.join(""),r}function LM(t){if(ite(t,":")<2)return{host:t,isIPV6:!1};let e=nte(t);if(e.error)return{host:t,isIPV6:!1};{let r=e.address,n=e.address;return e.zone&&(r+="%"+e.zone,n+="%25"+e.zone),{host:r,isIPV6:!0,escapedHost:n}}}function ite(t,e){let r=0;for(let n=0;n<t.length;n++)t[n]===e&&r++;return r}function ote(t){let e=t,r=[],n=-1,i=0;for(;i=e.length;){if(i===1){if(e===".")break;if(e==="/"){r.push("/");break}else{r.push(e);break}}else if(i===2){if(e[0]==="."){if(e[1]===".")break;if(e[1]==="/"){e=e.slice(2);continue}}else if(e[0]==="/"&&(e[1]==="."||e[1]==="/")){r.push("/");break}}else if(i===3&&e==="/.."){r.length!==0&&r.pop(),r.push("/");break}if(e[0]==="."){if(e[1]==="."){if(e[2]==="/"){e=e.slice(3);continue}}else if(e[1]==="/"){e=e.slice(2);continue}}else if(e[0]==="/"&&e[1]==="."){if(e[2]==="/"){e=e.slice(2);continue}else if(e[2]==="."&&e[3]==="/"){e=e.slice(3),r.length!==0&&r.pop();continue}}if((n=e.indexOf("/",1))===-1){r.push(e);break}else r.push(e.slice(0,n)),e=e.slice(n)}return r.join("")}function ste(t,e){let r=e!==!0?escape:unescape;return t.scheme!==void 0&&(t.scheme=r(t.scheme)),t.userinfo!==void 0&&(t.userinfo=r(t.userinfo)),t.host!==void 0&&(t.host=r(t.host)),t.path!==void 0&&(t.path=r(t.path)),t.query!==void 0&&(t.query=r(t.query)),t.fragment!==void 0&&(t.fragment=r(t.fragment)),t}function ate(t){let e=[];if(t.userinfo!==void 0&&(e.push(t.userinfo),e.push("@")),t.host!==void 0){let r=unescape(t.host);if(!qM(r)){let n=LM(r);n.isIPV6===!0?r=`[${n.escapedHost}]`:r=t.host}e.push(r)}return(typeof t.port=="number"||typeof t.port=="string")&&(e.push(":"),e.push(String(t.port))),e.length?e.join(""):void 0}zM.exports={nonSimpleDomain:tte,recomposeAuthority:ate,normalizeComponentEncoding:ste,removeDotSegments:ote,isIPv4:qM,isUUID:ete,normalizeIPv6:LM,stringArrayToHexStripped:Zk}});var VM=_e((tCe,HM)=>{"use strict";y();var{isUUID:cte}=Yk(),dte=/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu,ute=["http","https","ws","wss","urn","urn:uuid"];function lte(t){return ute.indexOf(t)!==-1}function Qk(t){return t.secure===!0?!0:t.secure===!1?!1:t.scheme?t.scheme.length===3&&(t.scheme[0]==="w"||t.scheme[0]==="W")&&(t.scheme[1]==="s"||t.scheme[1]==="S")&&(t.scheme[2]==="s"||t.scheme[2]==="S"):!1}function FM(t){return t.host||(t.error=t.error||"HTTP URIs must have a host."),t}function GM(t){let e=String(t.scheme).toLowerCase()==="https";return(t.port===(e?443:80)||t.port==="")&&(t.port=void 0),t.path||(t.path="/"),t}function fte(t){return t.secure=Qk(t),t.resourceName=(t.path||"/")+(t.query?"?"+t.query:""),t.path=void 0,t.query=void 0,t}function pte(t){if((t.port===(Qk(t)?443:80)||t.port==="")&&(t.port=void 0),typeof t.secure=="boolean"&&(t.scheme=t.secure?"wss":"ws",t.secure=void 0),t.resourceName){let[e,r]=t.resourceName.split("?");t.path=e&&e!=="/"?e:void 0,t.query=r,t.resourceName=void 0}return t.fragment=void 0,t}function hte(t,e){if(!t.path)return t.error="URN can not be parsed",t;let r=t.path.match(dte);if(r){let n=e.scheme||t.scheme||"urn";t.nid=r[1].toLowerCase(),t.nss=r[2];let i=`${n}:${e.nid||t.nid}`,a=Xk(i);t.path=void 0,a&&(t=a.parse(t,e))}else t.error=t.error||"URN can not be parsed.";return t}function mte(t,e){if(t.nid===void 0)throw new Error("URN without nid cannot be serialized");let r=e.scheme||t.scheme||"urn",n=t.nid.toLowerCase(),i=`${r}:${e.nid||n}`,a=Xk(i);a&&(t=a.serialize(t,e));let s=t,o=t.nss;return s.path=`${n||e.nid}:${o}`,e.skipEscape=!0,s}function yte(t,e){let r=t;return r.uuid=r.nss,r.nss=void 0,!e.tolerant&&(!r.uuid||!cte(r.uuid))&&(r.error=r.error||"UUID is not valid."),r}function gte(t){let e=t;return e.nss=(t.uuid||"").toLowerCase(),e}var WM={scheme:"http",domainHost:!0,parse:FM,serialize:GM},wte={scheme:"https",domainHost:WM.domainHost,parse:FM,serialize:GM},h1={scheme:"ws",domainHost:!0,parse:fte,serialize:pte},vte={scheme:"wss",domainHost:h1.domainHost,parse:h1.parse,serialize:h1.serialize},bte={scheme:"urn",parse:hte,serialize:mte,skipNormalize:!0},xte={scheme:"urn:uuid",parse:yte,serialize:gte,skipNormalize:!0},m1={http:WM,https:wte,ws:h1,wss:vte,urn:bte,"urn:uuid":xte};Object.setPrototypeOf(m1,null);function Xk(t){return t&&(m1[t]||m1[t.toLowerCase()])||void 0}HM.exports={wsIsSecure:Qk,SCHEMES:m1,isValidSchemeName:lte,getSchemeHandler:Xk}});var YM=_e((nCe,g1)=>{"use strict";y();var{normalizeIPv6:Pte,removeDotSegments:tw,recomposeAuthority:_te,normalizeComponentEncoding:y1,isIPv4:Ete,nonSimpleDomain:Ste}=Yk(),{SCHEMES:Tte,getSchemeHandler:JM}=VM();function kte(t,e){return typeof t=="string"?t=vc(vd(t,e),e):typeof t=="object"&&(t=vd(vc(t,e),e)),t}function Ate(t,e,r){let n=r?Object.assign({scheme:"null"},r):{scheme:"null"},i=ZM(vd(t,n),vd(e,n),n,!0);return n.skipEscape=!0,vc(i,n)}function ZM(t,e,r,n){let i={};return n||(t=vd(vc(t,r),r),e=vd(vc(e,r),r)),r=r||{},!r.tolerant&&e.scheme?(i.scheme=e.scheme,i.userinfo=e.userinfo,i.host=e.host,i.port=e.port,i.path=tw(e.path||""),i.query=e.query):(e.userinfo!==void 0||e.host!==void 0||e.port!==void 0?(i.userinfo=e.userinfo,i.host=e.host,i.port=e.port,i.path=tw(e.path||""),i.query=e.query):(e.path?(e.path[0]==="/"?i.path=tw(e.path):((t.userinfo!==void 0||t.host!==void 0||t.port!==void 0)&&!t.path?i.path="/"+e.path:t.path?i.path=t.path.slice(0,t.path.lastIndexOf("/")+1)+e.path:i.path=e.path,i.path=tw(i.path)),i.query=e.query):(i.path=t.path,e.query!==void 0?i.query=e.query:i.query=t.query),i.userinfo=t.userinfo,i.host=t.host,i.port=t.port),i.scheme=t.scheme),i.fragment=e.fragment,i}function Dte(t,e,r){return typeof t=="string"?(t=unescape(t),t=vc(y1(vd(t,r),!0),{...r,skipEscape:!0})):typeof t=="object"&&(t=vc(y1(t,!0),{...r,skipEscape:!0})),typeof e=="string"?(e=unescape(e),e=vc(y1(vd(e,r),!0),{...r,skipEscape:!0})):typeof e=="object"&&(e=vc(y1(e,!0),{...r,skipEscape:!0})),t.toLowerCase()===e.toLowerCase()}function vc(t,e){let r={host:t.host,scheme:t.scheme,userinfo:t.userinfo,port:t.port,path:t.path,query:t.query,nid:t.nid,nss:t.nss,uuid:t.uuid,fragment:t.fragment,reference:t.reference,resourceName:t.resourceName,secure:t.secure,error:""},n=Object.assign({},e),i=[],a=JM(n.scheme||r.scheme);a&&a.serialize&&a.serialize(r,n),r.path!==void 0&&(n.skipEscape?r.path=unescape(r.path):(r.path=escape(r.path),r.scheme!==void 0&&(r.path=r.path.split("%3A").join(":")))),n.reference!=="suffix"&&r.scheme&&i.push(r.scheme,":");let s=_te(r);if(s!==void 0&&(n.reference!=="suffix"&&i.push("//"),i.push(s),r.path&&r.path[0]!=="/"&&i.push("/")),r.path!==void 0){let o=r.path;!n.absolutePath&&(!a||!a.absolutePath)&&(o=tw(o)),s===void 0&&o[0]==="/"&&o[1]==="/"&&(o="/%2F"+o.slice(2)),i.push(o)}return r.query!==void 0&&i.push("?",r.query),r.fragment!==void 0&&i.push("#",r.fragment),i.join("")}var Ite=/^(?:([^#/:?]+):)?(?:\/\/((?:([^#/?@]*)@)?(\[[^#/?\]]+\]|[^#/:?]*)(?::(\d*))?))?([^#?]*)(?:\?([^#]*))?(?:#((?:.|[\n\r])*))?/u;function vd(t,e){let r=Object.assign({},e),n={scheme:void 0,userinfo:void 0,host:"",port:void 0,path:"",query:void 0,fragment:void 0},i=!1;r.reference==="suffix"&&(r.scheme?t=r.scheme+":"+t:t="//"+t);let a=t.match(Ite);if(a){if(n.scheme=a[1],n.userinfo=a[3],n.host=a[4],n.port=parseInt(a[5],10),n.path=a[6]||"",n.query=a[7],n.fragment=a[8],isNaN(n.port)&&(n.port=a[5]),n.host)if(Ete(n.host)===!1){let d=Pte(n.host);n.host=d.host.toLowerCase(),i=d.isIPV6}else i=!0;n.scheme===void 0&&n.userinfo===void 0&&n.host===void 0&&n.port===void 0&&n.query===void 0&&!n.path?n.reference="same-document":n.scheme===void 0?n.reference="relative":n.fragment===void 0?n.reference="absolute":n.reference="uri",r.reference&&r.reference!=="suffix"&&r.reference!==n.reference&&(n.error=n.error||"URI is not a "+r.reference+" reference.");let s=JM(r.scheme||n.scheme);if(!r.unicodeSupport&&(!s||!s.unicodeSupport)&&n.host&&(r.domainHost||s&&s.domainHost)&&i===!1&&Ste(n.host))try{n.host=URL.domainToASCII(n.host.toLowerCase())}catch(o){n.error=n.error||"Host's domain name can not be converted to ASCII: "+o}(!s||s&&!s.skipNormalize)&&(t.indexOf("%")!==-1&&(n.scheme!==void 0&&(n.scheme=unescape(n.scheme)),n.host!==void 0&&(n.host=unescape(n.host))),n.path&&(n.path=escape(unescape(n.path))),n.fragment&&(n.fragment=encodeURI(decodeURIComponent(n.fragment)))),s&&s.parse&&s.parse(n,r)}else n.error=n.error||"URI can not be parsed.";return n}var eA={SCHEMES:Tte,normalize:kte,resolve:Ate,resolveComponent:ZM,equal:Dte,serialize:vc,parse:vd};g1.exports=eA;g1.exports.default=eA;g1.exports.fastUri=eA});var XM=_e(tA=>{"use strict";y();Object.defineProperty(tA,"__esModule",{value:!0});var QM=YM();QM.code='require("ajv/dist/runtime/uri").default';tA.default=QM});var aN=_e(Ii=>{"use strict";y();Object.defineProperty(Ii,"__esModule",{value:!0});Ii.CodeGen=Ii.Name=Ii.nil=Ii.stringify=Ii.str=Ii._=Ii.KeywordCxt=void 0;var Rte=Qg();Object.defineProperty(Ii,"KeywordCxt",{enumerable:!0,get:function(){return Rte.KeywordCxt}});var Kh=St();Object.defineProperty(Ii,"_",{enumerable:!0,get:function(){return Kh._}});Object.defineProperty(Ii,"str",{enumerable:!0,get:function(){return Kh.str}});Object.defineProperty(Ii,"stringify",{enumerable:!0,get:function(){return Kh.stringify}});Object.defineProperty(Ii,"nil",{enumerable:!0,get:function(){return Kh.nil}});Object.defineProperty(Ii,"Name",{enumerable:!0,get:function(){return Kh.Name}});Object.defineProperty(Ii,"CodeGen",{enumerable:!0,get:function(){return Kh.CodeGen}});var Cte=f1(),iN=Xg(),$te=Ik(),rw=ew(),Ote=St(),nw=Jg(),w1=Vg(),nA=Ut(),eN=UM(),Bte=XM(),oN=(t,e)=>new RegExp(t,e);oN.code="new RegExp";var jte=["removeAdditional","useDefaults","coerceTypes"],Mte=new Set(["validate","serialize","parse","wrapper","root","schema","keyword","pattern","formats","validate$data","func","obj","Error"]),Nte={errorDataPath:"",format:"`validateFormats: false` can be used instead.",nullable:'"nullable" keyword is supported by default.',jsonPointers:"Deprecated jsPropertySyntax can be used instead.",extendRefs:"Deprecated ignoreKeywordsWithRef can be used instead.",missingRefs:"Pass empty schema with $id that should be ignored to ajv.addSchema.",processCode:"Use option `code: {process: (code, schemaEnv: object) => string}`",sourceCode:"Use option `code: {source: true}`",strictDefaults:"It is default now, see option `strict`.",strictKeywords:"It is default now, see option `strict`.",uniqueItems:'"uniqueItems" keyword is always validated.',unknownFormats:"Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",cache:"Map is used as cache, schema object as key.",serialize:"Map is used as cache, schema object as key.",ajvErrors:"It is default now."},Ute={ignoreKeywordsWithRef:"",jsPropertySyntax:"",unicode:'"minLength"/"maxLength" account for unicode characters by default.'},tN=200;function Kte(t){var e,r,n,i,a,s,o,d,u,c,l,f,h,p,m,g,_,v,E,T,D,R,N,B,G;let z=t.strict,U=(e=t.code)===null||e===void 0?void 0:e.optimize,H=U===!0||U===void 0?1:U||0,ee=(n=(r=t.code)===null||r===void 0?void 0:r.regExp)!==null&&n!==void 0?n:oN,I=(i=t.uriResolver)!==null&&i!==void 0?i:Bte.default;return{strictSchema:(s=(a=t.strictSchema)!==null&&a!==void 0?a:z)!==null&&s!==void 0?s:!0,strictNumbers:(d=(o=t.strictNumbers)!==null&&o!==void 0?o:z)!==null&&d!==void 0?d:!0,strictTypes:(c=(u=t.strictTypes)!==null&&u!==void 0?u:z)!==null&&c!==void 0?c:"log",strictTuples:(f=(l=t.strictTuples)!==null&&l!==void 0?l:z)!==null&&f!==void 0?f:"log",strictRequired:(p=(h=t.strictRequired)!==null&&h!==void 0?h:z)!==null&&p!==void 0?p:!1,code:t.code?{...t.code,optimize:H,regExp:ee}:{optimize:H,regExp:ee},loopRequired:(m=t.loopRequired)!==null&&m!==void 0?m:tN,loopEnum:(g=t.loopEnum)!==null&&g!==void 0?g:tN,meta:(_=t.meta)!==null&&_!==void 0?_:!0,messages:(v=t.messages)!==null&&v!==void 0?v:!0,inlineRefs:(E=t.inlineRefs)!==null&&E!==void 0?E:!0,schemaId:(T=t.schemaId)!==null&&T!==void 0?T:"$id",addUsedSchema:(D=t.addUsedSchema)!==null&&D!==void 0?D:!0,validateSchema:(R=t.validateSchema)!==null&&R!==void 0?R:!0,validateFormats:(N=t.validateFormats)!==null&&N!==void 0?N:!0,unicodeRegExp:(B=t.unicodeRegExp)!==null&&B!==void 0?B:!0,int32range:(G=t.int32range)!==null&&G!==void 0?G:!0,uriResolver:I}}var iw=class{constructor(e={}){this.schemas={},this.refs={},this.formats={},this._compilations=new Set,this._loading={},this._cache=new Map,e=this.opts={...e,...Kte(e)};let{es5:r,lines:n}=this.opts.code;this.scope=new Ote.ValueScope({scope:{},prefixes:Mte,es5:r,lines:n}),this.logger=Wte(e.logger);let i=e.validateFormats;e.validateFormats=!1,this.RULES=(0,$te.getRules)(),rN.call(this,Nte,e,"NOT SUPPORTED"),rN.call(this,Ute,e,"DEPRECATED","warn"),this._metaOpts=Fte.call(this),e.formats&&Lte.call(this),this._addVocabularies(),this._addDefaultMetaSchema(),e.keywords&&zte.call(this,e.keywords),typeof e.meta=="object"&&this.addMetaSchema(e.meta),qte.call(this),e.validateFormats=i}_addVocabularies(){this.addKeyword("$async")}_addDefaultMetaSchema(){let{$data:e,meta:r,schemaId:n}=this.opts,i=eN;n==="id"&&(i={...eN},i.id=i.$id,delete i.$id),r&&e&&this.addMetaSchema(i,i[n],!1)}defaultMeta(){let{meta:e,schemaId:r}=this.opts;return this.opts.defaultMeta=typeof e=="object"?e[r]||e:void 0}validate(e,r){let n;if(typeof e=="string"){if(n=this.getSchema(e),!n)throw new Error(`no schema with key or ref "${e}"`)}else n=this.compile(e);let i=n(r);return"$async"in n||(this.errors=n.errors),i}compile(e,r){let n=this._addSchema(e,r);return n.validate||this._compileSchemaEnv(n)}compileAsync(e,r){if(typeof this.opts.loadSchema!="function")throw new Error("options.loadSchema should be a function");let{loadSchema:n}=this.opts;return i.call(this,e,r);async function i(c,l){await a.call(this,c.$schema);let f=this._addSchema(c,l);return f.validate||s.call(this,f)}async function a(c){c&&!this.getSchema(c)&&await i.call(this,{$ref:c},!0)}async function s(c){try{return this._compileSchemaEnv(c)}catch(l){if(!(l instanceof iN.default))throw l;return o.call(this,l),await d.call(this,l.missingSchema),s.call(this,c)}}function o({missingSchema:c,missingRef:l}){if(this.refs[c])throw new Error(`AnySchema ${c} is loaded but ${l} cannot be resolved`)}async function d(c){let l=await u.call(this,c);this.refs[c]||await a.call(this,l.$schema),this.refs[c]||this.addSchema(l,c,r)}async function u(c){let l=this._loading[c];if(l)return l;try{return await(this._loading[c]=n(c))}finally{delete this._loading[c]}}}addSchema(e,r,n,i=this.opts.validateSchema){if(Array.isArray(e)){for(let s of e)this.addSchema(s,void 0,n,i);return this}let a;if(typeof e=="object"){let{schemaId:s}=this.opts;if(a=e[s],a!==void 0&&typeof a!="string")throw new Error(`schema ${s} must be string`)}return r=(0,nw.normalizeId)(r||a),this._checkUnique(r),this.schemas[r]=this._addSchema(e,n,r,i,!0),this}addMetaSchema(e,r,n=this.opts.validateSchema){return this.addSchema(e,r,!0,n),this}validateSchema(e,r){if(typeof e=="boolean")return!0;let n;if(n=e.$schema,n!==void 0&&typeof n!="string")throw new Error("$schema must be a string");if(n=n||this.opts.defaultMeta||this.defaultMeta(),!n)return this.logger.warn("meta-schema not available"),this.errors=null,!0;let i=this.validate(n,e);if(!i&&r){let a="schema is invalid: "+this.errorsText();if(this.opts.validateSchema==="log")this.logger.error(a);else throw new Error(a)}return i}getSchema(e){let r;for(;typeof(r=nN.call(this,e))=="string";)e=r;if(r===void 0){let{schemaId:n}=this.opts,i=new rw.SchemaEnv({schema:{},schemaId:n});if(r=rw.resolveSchema.call(this,i,e),!r)return;this.refs[e]=r}return r.validate||this._compileSchemaEnv(r)}removeSchema(e){if(e instanceof RegExp)return this._removeAllSchemas(this.schemas,e),this._removeAllSchemas(this.refs,e),this;switch(typeof e){case"undefined":return this._removeAllSchemas(this.schemas),this._removeAllSchemas(this.refs),this._cache.clear(),this;case"string":{let r=nN.call(this,e);return typeof r=="object"&&this._cache.delete(r.schema),delete this.schemas[e],delete this.refs[e],this}case"object":{let r=e;this._cache.delete(r);let n=e[this.opts.schemaId];return n&&(n=(0,nw.normalizeId)(n),delete this.schemas[n],delete this.refs[n]),this}default:throw new Error("ajv.removeSchema: invalid parameter")}}addVocabulary(e){for(let r of e)this.addKeyword(r);return this}addKeyword(e,r){let n;if(typeof e=="string")n=e,typeof r=="object"&&(this.logger.warn("these parameters are deprecated, see docs for addKeyword"),r.keyword=n);else if(typeof e=="object"&&r===void 0){if(r=e,n=r.keyword,Array.isArray(n)&&!n.length)throw new Error("addKeywords: keyword must be string or non-empty array")}else throw new Error("invalid addKeywords parameters");if(Vte.call(this,n,r),!r)return(0,nA.eachItem)(n,a=>rA.call(this,a)),this;Zte.call(this,r);let i={...r,type:(0,w1.getJSONTypes)(r.type),schemaType:(0,w1.getJSONTypes)(r.schemaType)};return(0,nA.eachItem)(n,i.type.length===0?a=>rA.call(this,a,i):a=>i.type.forEach(s=>rA.call(this,a,i,s))),this}getKeyword(e){let r=this.RULES.all[e];return typeof r=="object"?r.definition:!!r}removeKeyword(e){let{RULES:r}=this;delete r.keywords[e],delete r.all[e];for(let n of r.rules){let i=n.rules.findIndex(a=>a.keyword===e);i>=0&&n.rules.splice(i,1)}return this}addFormat(e,r){return typeof r=="string"&&(r=new RegExp(r)),this.formats[e]=r,this}errorsText(e=this.errors,{separator:r=", ",dataVar:n="data"}={}){return!e||e.length===0?"No errors":e.map(i=>`${n}${i.instancePath} ${i.message}`).reduce((i,a)=>i+r+a)}$dataMetaSchema(e,r){let n=this.RULES.all;e=JSON.parse(JSON.stringify(e));for(let i of r){let a=i.split("/").slice(1),s=e;for(let o of a)s=s[o];for(let o in n){let d=n[o];if(typeof d!="object")continue;let{$data:u}=d.definition,c=s[o];u&&c&&(s[o]=sN(c))}}return e}_removeAllSchemas(e,r){for(let n in e){let i=e[n];(!r||r.test(n))&&(typeof i=="string"?delete e[n]:i&&!i.meta&&(this._cache.delete(i.schema),delete e[n]))}}_addSchema(e,r,n,i=this.opts.validateSchema,a=this.opts.addUsedSchema){let s,{schemaId:o}=this.opts;if(typeof e=="object")s=e[o];else{if(this.opts.jtd)throw new Error("schema must be object");if(typeof e!="boolean")throw new Error("schema must be object or boolean")}let d=this._cache.get(e);if(d!==void 0)return d;n=(0,nw.normalizeId)(s||n);let u=nw.getSchemaRefs.call(this,e,n);return d=new rw.SchemaEnv({schema:e,schemaId:o,meta:r,baseId:n,localRefs:u}),this._cache.set(d.schema,d),a&&!n.startsWith("#")&&(n&&this._checkUnique(n),this.refs[n]=d),i&&this.validateSchema(e,!0),d}_checkUnique(e){if(this.schemas[e]||this.refs[e])throw new Error(`schema with key or id "${e}" already exists`)}_compileSchemaEnv(e){if(e.meta?this._compileMetaSchema(e):rw.compileSchema.call(this,e),!e.validate)throw new Error("ajv implementation error");return e.validate}_compileMetaSchema(e){let r=this.opts;this.opts=this._metaOpts;try{rw.compileSchema.call(this,e)}finally{this.opts=r}}};iw.ValidationError=Cte.default;iw.MissingRefError=iN.default;Ii.default=iw;function rN(t,e,r,n="error"){for(let i in t){let a=i;a in e&&this.logger[n](`${r}: option ${i}. ${t[a]}`)}}function nN(t){return t=(0,nw.normalizeId)(t),this.schemas[t]||this.refs[t]}function qte(){let t=this.opts.schemas;if(t)if(Array.isArray(t))this.addSchema(t);else for(let e in t)this.addSchema(t[e],e)}function Lte(){for(let t in this.opts.formats){let e=this.opts.formats[t];e&&this.addFormat(t,e)}}function zte(t){if(Array.isArray(t)){this.addVocabulary(t);return}this.logger.warn("keywords option as map is deprecated, pass array");for(let e in t){let r=t[e];r.keyword||(r.keyword=e),this.addKeyword(r)}}function Fte(){let t={...this.opts};for(let e of jte)delete t[e];return t}var Gte={log(){},warn(){},error(){}};function Wte(t){if(t===!1)return Gte;if(t===void 0)return console;if(t.log&&t.warn&&t.error)return t;throw new Error("logger must implement log, warn and error methods")}var Hte=/^[a-z_$][a-z0-9_$:-]*$/i;function Vte(t,e){let{RULES:r}=this;if((0,nA.eachItem)(t,n=>{if(r.keywords[n])throw new Error(`Keyword ${n} is already defined`);if(!Hte.test(n))throw new Error(`Keyword ${n} has invalid name`)}),!!e&&e.$data&&!("code"in e||"validate"in e))throw new Error('$data keyword must have "code" or "validate" function')}function rA(t,e,r){var n;let i=e?.post;if(r&&i)throw new Error('keyword with "post" flag cannot have "type"');let{RULES:a}=this,s=i?a.post:a.rules.find(({type:d})=>d===r);if(s||(s={type:r,rules:[]},a.rules.push(s)),a.keywords[t]=!0,!e)return;let o={keyword:t,definition:{...e,type:(0,w1.getJSONTypes)(e.type),schemaType:(0,w1.getJSONTypes)(e.schemaType)}};e.before?Jte.call(this,s,o,e.before):s.rules.push(o),a.all[t]=o,(n=e.implements)===null||n===void 0||n.forEach(d=>this.addKeyword(d))}function Jte(t,e,r){let n=t.rules.findIndex(i=>i.keyword===r);n>=0?t.rules.splice(n,0,e):(t.rules.push(e),this.logger.warn(`rule ${r} is not defined`))}function Zte(t){let{metaSchema:e}=t;e!==void 0&&(t.$data&&this.opts.$data&&(e=sN(e)),t.validateSchema=this.compile(e,!0))}var Yte={$ref:"https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#"};function sN(t){return{anyOf:[t,Yte]}}});var cN=_e(iA=>{"use strict";y();Object.defineProperty(iA,"__esModule",{value:!0});var Qte={keyword:"id",code(){throw new Error('NOT SUPPORTED: keyword "id", use "$id" for schema ID')}};iA.default=Qte});var x1=_e(vf=>{"use strict";y();Object.defineProperty(vf,"__esModule",{value:!0});vf.callRef=vf.getValidate=void 0;var Xte=Xg(),dN=Ks(),Ko=St(),qh=Us(),uN=ew(),v1=Ut(),ere={keyword:"$ref",schemaType:"string",code(t){let{gen:e,schema:r,it:n}=t,{baseId:i,schemaEnv:a,validateName:s,opts:o,self:d}=n,{root:u}=a;if((r==="#"||r==="#/")&&i===u.baseId)return l();let c=uN.resolveRef.call(d,u,i,r);if(c===void 0)throw new Xte.default(n.opts.uriResolver,i,r);if(c instanceof uN.SchemaEnv)return f(c);return h(c);function l(){if(a===u)return b1(t,s,a,a.$async);let p=e.scopeValue("root",{ref:u});return b1(t,(0,Ko._)`${p}.validate`,u,u.$async)}function f(p){let m=lN(t,p);b1(t,m,p,p.$async)}function h(p){let m=e.scopeValue("schema",o.code.source===!0?{ref:p,code:(0,Ko.stringify)(p)}:{ref:p}),g=e.name("valid"),_=t.subschema({schema:p,dataTypes:[],schemaPath:Ko.nil,topSchemaRef:m,errSchemaPath:r},g);t.mergeEvaluated(_),t.ok(g)}}};function lN(t,e){let{gen:r}=t;return e.validate?r.scopeValue("validate",{ref:e.validate}):(0,Ko._)`${r.scopeValue("wrapper",{ref:e})}.validate`}vf.getValidate=lN;function b1(t,e,r,n){let{gen:i,it:a}=t,{allErrors:s,schemaEnv:o,opts:d}=a,u=d.passContext?qh.default.this:Ko.nil;n?c():l();function c(){if(!o.$async)throw new Error("async schema referenced by sync schema");let p=i.let("valid");i.try(()=>{i.code((0,Ko._)`await ${(0,dN.callValidateCode)(t,e,u)}`),h(e),s||i.assign(p,!0)},m=>{i.if((0,Ko._)`!(${m} instanceof ${a.ValidationError})`,()=>i.throw(m)),f(m),s||i.assign(p,!1)}),t.ok(p)}function l(){t.result((0,dN.callValidateCode)(t,e,u),()=>h(e),()=>f(e))}function f(p){let m=(0,Ko._)`${p}.errors`;i.assign(qh.default.vErrors,(0,Ko._)`${qh.default.vErrors} === null ? ${m} : ${qh.default.vErrors}.concat(${m})`),i.assign(qh.default.errors,(0,Ko._)`${qh.default.vErrors}.length`)}function h(p){var m;if(!a.opts.unevaluated)return;let g=(m=r?.validate)===null||m===void 0?void 0:m.evaluated;if(a.props!==!0)if(g&&!g.dynamicProps)g.props!==void 0&&(a.props=v1.mergeEvaluated.props(i,g.props,a.props));else{let _=i.var("props",(0,Ko._)`${p}.evaluated.props`);a.props=v1.mergeEvaluated.props(i,_,a.props,Ko.Name)}if(a.items!==!0)if(g&&!g.dynamicItems)g.items!==void 0&&(a.items=v1.mergeEvaluated.items(i,g.items,a.items));else{let _=i.var("items",(0,Ko._)`${p}.evaluated.items`);a.items=v1.mergeEvaluated.items(i,_,a.items,Ko.Name)}}}vf.callRef=b1;vf.default=ere});var fN=_e(oA=>{"use strict";y();Object.defineProperty(oA,"__esModule",{value:!0});var tre=cN(),rre=x1(),nre=["$schema","$id","$defs","$vocabulary",{keyword:"$comment"},"definitions",tre.default,rre.default];oA.default=nre});var pN=_e(sA=>{"use strict";y();Object.defineProperty(sA,"__esModule",{value:!0});var P1=St(),Cu=P1.operators,_1={maximum:{okStr:"<=",ok:Cu.LTE,fail:Cu.GT},minimum:{okStr:">=",ok:Cu.GTE,fail:Cu.LT},exclusiveMaximum:{okStr:"<",ok:Cu.LT,fail:Cu.GTE},exclusiveMinimum:{okStr:">",ok:Cu.GT,fail:Cu.LTE}},ire={message:({keyword:t,schemaCode:e})=>(0,P1.str)`must be ${_1[t].okStr} ${e}`,params:({keyword:t,schemaCode:e})=>(0,P1._)`{comparison: ${_1[t].okStr}, limit: ${e}}`},ore={keyword:Object.keys(_1),type:"number",schemaType:"number",$data:!0,error:ire,code(t){let{keyword:e,data:r,schemaCode:n}=t;t.fail$data((0,P1._)`${r} ${_1[e].fail} ${n} || isNaN(${r})`)}};sA.default=ore});var hN=_e(aA=>{"use strict";y();Object.defineProperty(aA,"__esModule",{value:!0});var ow=St(),sre={message:({schemaCode:t})=>(0,ow.str)`must be multiple of ${t}`,params:({schemaCode:t})=>(0,ow._)`{multipleOf: ${t}}`},are={keyword:"multipleOf",type:"number",schemaType:"number",$data:!0,error:sre,code(t){let{gen:e,data:r,schemaCode:n,it:i}=t,a=i.opts.multipleOfPrecision,s=e.let("res"),o=a?(0,ow._)`Math.abs(Math.round(${s}) - ${s}) > 1e-${a}`:(0,ow._)`${s} !== parseInt(${s})`;t.fail$data((0,ow._)`(${n} === 0 || (${s} = ${r}/${n}, ${o}))`)}};aA.default=are});var mN=_e(cA=>{"use strict";y();Object.defineProperty(cA,"__esModule",{value:!0});var bf=St(),cre=Ut(),dre=r_(),ure={message({keyword:t,schemaCode:e}){let r=t==="maxLength"?"more":"fewer";return(0,bf.str)`must NOT have ${r} than ${e} characters`},params:({schemaCode:t})=>(0,bf._)`{limit: ${t}}`},lre={keyword:["maxLength","minLength"],type:"string",schemaType:"number",$data:!0,error:ure,code(t){let{keyword:e,data:r,schemaCode:n,it:i}=t,a=e==="maxLength"?bf.operators.GT:bf.operators.LT,s=i.opts.unicode===!1?(0,bf._)`${r}.length`:(0,bf._)`${(0,cre.useFunc)(t.gen,dre.default)}(${r})`;t.fail$data((0,bf._)`${s} ${a} ${n}`)}};cA.default=lre});var yN=_e(dA=>{"use strict";y();Object.defineProperty(dA,"__esModule",{value:!0});var fre=Ks(),pre=Ut(),Lh=St(),hre={message:({schemaCode:t})=>(0,Lh.str)`must match pattern "${t}"`,params:({schemaCode:t})=>(0,Lh._)`{pattern: ${t}}`},mre={keyword:"pattern",type:"string",schemaType:"string",$data:!0,error:hre,code(t){let{gen:e,data:r,$data:n,schema:i,schemaCode:a,it:s}=t,o=s.opts.unicodeRegExp?"u":"";if(n){let{regExp:d}=s.opts.code,u=d.code==="new RegExp"?(0,Lh._)`new RegExp`:(0,pre.useFunc)(e,d),c=e.let("valid");e.try(()=>e.assign(c,(0,Lh._)`${u}(${a}, ${o}).test(${r})`),()=>e.assign(c,!1)),t.fail$data((0,Lh._)`!${c}`)}else{let d=(0,fre.usePattern)(t,i);t.fail$data((0,Lh._)`!${d}.test(${r})`)}}};dA.default=mre});var gN=_e(uA=>{"use strict";y();Object.defineProperty(uA,"__esModule",{value:!0});var sw=St(),yre={message({keyword:t,schemaCode:e}){let r=t==="maxProperties"?"more":"fewer";return(0,sw.str)`must NOT have ${r} than ${e} properties`},params:({schemaCode:t})=>(0,sw._)`{limit: ${t}}`},gre={keyword:["maxProperties","minProperties"],type:"object",schemaType:"number",$data:!0,error:yre,code(t){let{keyword:e,data:r,schemaCode:n}=t,i=e==="maxProperties"?sw.operators.GT:sw.operators.LT;t.fail$data((0,sw._)`Object.keys(${r}).length ${i} ${n}`)}};uA.default=gre});var wN=_e(lA=>{"use strict";y();Object.defineProperty(lA,"__esModule",{value:!0});var aw=Ks(),cw=St(),wre=Ut(),vre={message:({params:{missingProperty:t}})=>(0,cw.str)`must have required property '${t}'`,params:({params:{missingProperty:t}})=>(0,cw._)`{missingProperty: ${t}}`},bre={keyword:"required",type:"object",schemaType:"array",$data:!0,error:vre,code(t){let{gen:e,schema:r,schemaCode:n,data:i,$data:a,it:s}=t,{opts:o}=s;if(!a&&r.length===0)return;let d=r.length>=o.loopRequired;if(s.allErrors?u():c(),o.strictRequired){let h=t.parentSchema.properties,{definedProperties:p}=t.it;for(let m of r)if(h?.[m]===void 0&&!p.has(m)){let g=s.schemaEnv.baseId+s.errSchemaPath,_=`required property "${m}" is not defined at "${g}" (strictRequired)`;(0,wre.checkStrictMode)(s,_,s.opts.strictRequired)}}function u(){if(d||a)t.block$data(cw.nil,l);else for(let h of r)(0,aw.checkReportMissingProp)(t,h)}function c(){let h=e.let("missing");if(d||a){let p=e.let("valid",!0);t.block$data(p,()=>f(h,p)),t.ok(p)}else e.if((0,aw.checkMissingProp)(t,r,h)),(0,aw.reportMissingProp)(t,h),e.else()}function l(){e.forOf("prop",n,h=>{t.setParams({missingProperty:h}),e.if((0,aw.noPropertyInData)(e,i,h,o.ownProperties),()=>t.error())})}function f(h,p){t.setParams({missingProperty:h}),e.forOf(h,n,()=>{e.assign(p,(0,aw.propertyInData)(e,i,h,o.ownProperties)),e.if((0,cw.not)(p),()=>{t.error(),e.break()})},cw.nil)}}};lA.default=bre});var vN=_e(fA=>{"use strict";y();Object.defineProperty(fA,"__esModule",{value:!0});var dw=St(),xre={message({keyword:t,schemaCode:e}){let r=t==="maxItems"?"more":"fewer";return(0,dw.str)`must NOT have ${r} than ${e} items`},params:({schemaCode:t})=>(0,dw._)`{limit: ${t}}`},Pre={keyword:["maxItems","minItems"],type:"array",schemaType:"number",$data:!0,error:xre,code(t){let{keyword:e,data:r,schemaCode:n}=t,i=e==="maxItems"?dw.operators.GT:dw.operators.LT;t.fail$data((0,dw._)`${r}.length ${i} ${n}`)}};fA.default=Pre});var E1=_e(pA=>{"use strict";y();Object.defineProperty(pA,"__esModule",{value:!0});var bN=Nk();bN.code='require("ajv/dist/runtime/equal").default';pA.default=bN});var xN=_e(mA=>{"use strict";y();Object.defineProperty(mA,"__esModule",{value:!0});var hA=Vg(),Ri=St(),_re=Ut(),Ere=E1(),Sre={message:({params:{i:t,j:e}})=>(0,Ri.str)`must NOT have duplicate items (items ## ${e} and ${t} are identical)`,params:({params:{i:t,j:e}})=>(0,Ri._)`{i: ${t}, j: ${e}}`},Tre={keyword:"uniqueItems",type:"array",schemaType:"boolean",$data:!0,error:Sre,code(t){let{gen:e,data:r,$data:n,schema:i,parentSchema:a,schemaCode:s,it:o}=t;if(!n&&!i)return;let d=e.let("valid"),u=a.items?(0,hA.getSchemaTypes)(a.items):[];t.block$data(d,c,(0,Ri._)`${s} === false`),t.ok(d);function c(){let p=e.let("i",(0,Ri._)`${r}.length`),m=e.let("j");t.setParams({i:p,j:m}),e.assign(d,!0),e.if((0,Ri._)`${p} > 1`,()=>(l()?f:h)(p,m))}function l(){return u.length>0&&!u.some(p=>p==="object"||p==="array")}function f(p,m){let g=e.name("item"),_=(0,hA.checkDataTypes)(u,g,o.opts.strictNumbers,hA.DataType.Wrong),v=e.const("indices",(0,Ri._)`{}`);e.for((0,Ri._)`;${p}--;`,()=>{e.let(g,(0,Ri._)`${r}[${p}]`),e.if(_,(0,Ri._)`continue`),u.length>1&&e.if((0,Ri._)`typeof ${g} == "string"`,(0,Ri._)`${g} += "_"`),e.if((0,Ri._)`typeof ${v}[${g}] == "number"`,()=>{e.assign(m,(0,Ri._)`${v}[${g}]`),t.error(),e.assign(d,!1).break()}).code((0,Ri._)`${v}[${g}] = ${p}`)})}function h(p,m){let g=(0,_re.useFunc)(e,Ere.default),_=e.name("outer");e.label(_).for((0,Ri._)`;${p}--;`,()=>e.for((0,Ri._)`${m} = ${p}; ${m}--;`,()=>e.if((0,Ri._)`${g}(${r}[${p}], ${r}[${m}])`,()=>{t.error(),e.assign(d,!1).break(_)})))}}};mA.default=Tre});var PN=_e(gA=>{"use strict";y();Object.defineProperty(gA,"__esModule",{value:!0});var yA=St(),kre=Ut(),Are=E1(),Dre={message:"must be equal to constant",params:({schemaCode:t})=>(0,yA._)`{allowedValue: ${t}}`},Ire={keyword:"const",$data:!0,error:Dre,code(t){let{gen:e,data:r,$data:n,schemaCode:i,schema:a}=t;n||a&&typeof a=="object"?t.fail$data((0,yA._)`!${(0,kre.useFunc)(e,Are.default)}(${r}, ${i})`):t.fail((0,yA._)`${a} !== ${r}`)}};gA.default=Ire});var _N=_e(wA=>{"use strict";y();Object.defineProperty(wA,"__esModule",{value:!0});var uw=St(),Rre=Ut(),Cre=E1(),$re={message:"must be equal to one of the allowed values",params:({schemaCode:t})=>(0,uw._)`{allowedValues: ${t}}`},Ore={keyword:"enum",schemaType:"array",$data:!0,error:$re,code(t){let{gen:e,data:r,$data:n,schema:i,schemaCode:a,it:s}=t;if(!n&&i.length===0)throw new Error("enum must have non-empty array");let o=i.length>=s.opts.loopEnum,d,u=()=>d??(d=(0,Rre.useFunc)(e,Cre.default)),c;if(o||n)c=e.let("valid"),t.block$data(c,l);else{if(!Array.isArray(i))throw new Error("ajv implementation error");let h=e.const("vSchema",a);c=(0,uw.or)(...i.map((p,m)=>f(h,m)))}t.pass(c);function l(){e.assign(c,!1),e.forOf("v",a,h=>e.if((0,uw._)`${u()}(${r}, ${h})`,()=>e.assign(c,!0).break()))}function f(h,p){let m=i[p];return typeof m=="object"&&m!==null?(0,uw._)`${u()}(${r}, ${h}[${p}])`:(0,uw._)`${r} === ${m}`}}};wA.default=Ore});var EN=_e(vA=>{"use strict";y();Object.defineProperty(vA,"__esModule",{value:!0});var Bre=pN(),jre=hN(),Mre=mN(),Nre=yN(),Ure=gN(),Kre=wN(),qre=vN(),Lre=xN(),zre=PN(),Fre=_N(),Gre=[Bre.default,jre.default,Mre.default,Nre.default,Ure.default,Kre.default,qre.default,Lre.default,{keyword:"type",schemaType:["string","array"]},{keyword:"nullable",schemaType:"boolean"},zre.default,Fre.default];vA.default=Gre});var xA=_e(lw=>{"use strict";y();Object.defineProperty(lw,"__esModule",{value:!0});lw.validateAdditionalItems=void 0;var xf=St(),bA=Ut(),Wre={message:({params:{len:t}})=>(0,xf.str)`must NOT have more than ${t} items`,params:({params:{len:t}})=>(0,xf._)`{limit: ${t}}`},Hre={keyword:"additionalItems",type:"array",schemaType:["boolean","object"],before:"uniqueItems",error:Wre,code(t){let{parentSchema:e,it:r}=t,{items:n}=e;if(!Array.isArray(n)){(0,bA.checkStrictMode)(r,'"additionalItems" is ignored when "items" is not an array of schemas');return}SN(t,n)}};function SN(t,e){let{gen:r,schema:n,data:i,keyword:a,it:s}=t;s.items=!0;let o=r.const("len",(0,xf._)`${i}.length`);if(n===!1)t.setParams({len:e.length}),t.pass((0,xf._)`${o} <= ${e.length}`);else if(typeof n=="object"&&!(0,bA.alwaysValidSchema)(s,n)){let u=r.var("valid",(0,xf._)`${o} <= ${e.length}`);r.if((0,xf.not)(u),()=>d(u)),t.ok(u)}function d(u){r.forRange("i",e.length,o,c=>{t.subschema({keyword:a,dataProp:c,dataPropType:bA.Type.Num},u),s.allErrors||r.if((0,xf.not)(u),()=>r.break())})}}lw.validateAdditionalItems=SN;lw.default=Hre});var PA=_e(fw=>{"use strict";y();Object.defineProperty(fw,"__esModule",{value:!0});fw.validateTuple=void 0;var TN=St(),S1=Ut(),Vre=Ks(),Jre={keyword:"items",type:"array",schemaType:["object","array","boolean"],before:"uniqueItems",code(t){let{schema:e,it:r}=t;if(Array.isArray(e))return kN(t,"additionalItems",e);r.items=!0,!(0,S1.alwaysValidSchema)(r,e)&&t.ok((0,Vre.validateArray)(t))}};function kN(t,e,r=t.schema){let{gen:n,parentSchema:i,data:a,keyword:s,it:o}=t;c(i),o.opts.unevaluated&&r.length&&o.items!==!0&&(o.items=S1.mergeEvaluated.items(n,r.length,o.items));let d=n.name("valid"),u=n.const("len",(0,TN._)`${a}.length`);r.forEach((l,f)=>{(0,S1.alwaysValidSchema)(o,l)||(n.if((0,TN._)`${u} > ${f}`,()=>t.subschema({keyword:s,schemaProp:f,dataProp:f},d)),t.ok(d))});function c(l){let{opts:f,errSchemaPath:h}=o,p=r.length,m=p===l.minItems&&(p===l.maxItems||l[e]===!1);if(f.strictTuples&&!m){let g=`"${s}" is ${p}-tuple, but minItems or maxItems/${e} are not specified or different at path "${h}"`;(0,S1.checkStrictMode)(o,g,f.strictTuples)}}}fw.validateTuple=kN;fw.default=Jre});var AN=_e(_A=>{"use strict";y();Object.defineProperty(_A,"__esModule",{value:!0});var Zre=PA(),Yre={keyword:"prefixItems",type:"array",schemaType:["array"],before:"uniqueItems",code:t=>(0,Zre.validateTuple)(t,"items")};_A.default=Yre});var IN=_e(EA=>{"use strict";y();Object.defineProperty(EA,"__esModule",{value:!0});var DN=St(),Qre=Ut(),Xre=Ks(),ene=xA(),tne={message:({params:{len:t}})=>(0,DN.str)`must NOT have more than ${t} items`,params:({params:{len:t}})=>(0,DN._)`{limit: ${t}}`},rne={keyword:"items",type:"array",schemaType:["object","boolean"],before:"uniqueItems",error:tne,code(t){let{schema:e,parentSchema:r,it:n}=t,{prefixItems:i}=r;n.items=!0,!(0,Qre.alwaysValidSchema)(n,e)&&(i?(0,ene.validateAdditionalItems)(t,i):t.ok((0,Xre.validateArray)(t)))}};EA.default=rne});var RN=_e(SA=>{"use strict";y();Object.defineProperty(SA,"__esModule",{value:!0});var Ls=St(),T1=Ut(),nne={message:({params:{min:t,max:e}})=>e===void 0?(0,Ls.str)`must contain at least ${t} valid item(s)`:(0,Ls.str)`must contain at least ${t} and no more than ${e} valid item(s)`,params:({params:{min:t,max:e}})=>e===void 0?(0,Ls._)`{minContains: ${t}}`:(0,Ls._)`{minContains: ${t}, maxContains: ${e}}`},ine={keyword:"contains",type:"array",schemaType:["object","boolean"],before:"uniqueItems",trackErrors:!0,error:nne,code(t){let{gen:e,schema:r,parentSchema:n,data:i,it:a}=t,s,o,{minContains:d,maxContains:u}=n;a.opts.next?(s=d===void 0?1:d,o=u):s=1;let c=e.const("len",(0,Ls._)`${i}.length`);if(t.setParams({min:s,max:o}),o===void 0&&s===0){(0,T1.checkStrictMode)(a,'"minContains" == 0 without "maxContains": "contains" keyword ignored');return}if(o!==void 0&&s>o){(0,T1.checkStrictMode)(a,'"minContains" > "maxContains" is always invalid'),t.fail();return}if((0,T1.alwaysValidSchema)(a,r)){let m=(0,Ls._)`${c} >= ${s}`;o!==void 0&&(m=(0,Ls._)`${m} && ${c} <= ${o}`),t.pass(m);return}a.items=!0;let l=e.name("valid");o===void 0&&s===1?h(l,()=>e.if(l,()=>e.break())):s===0?(e.let(l,!0),o!==void 0&&e.if((0,Ls._)`${i}.length > 0`,f)):(e.let(l,!1),f()),t.result(l,()=>t.reset());function f(){let m=e.name("_valid"),g=e.let("count",0);h(m,()=>e.if(m,()=>p(g)))}function h(m,g){e.forRange("i",0,c,_=>{t.subschema({keyword:"contains",dataProp:_,dataPropType:T1.Type.Num,compositeRule:!0},m),g()})}function p(m){e.code((0,Ls._)`${m}++`),o===void 0?e.if((0,Ls._)`${m} >= ${s}`,()=>e.assign(l,!0).break()):(e.if((0,Ls._)`${m} > ${o}`,()=>e.assign(l,!1).break()),s===1?e.assign(l,!0):e.if((0,Ls._)`${m} >= ${s}`,()=>e.assign(l,!0)))}}};SA.default=ine});var k1=_e(bc=>{"use strict";y();Object.defineProperty(bc,"__esModule",{value:!0});bc.validateSchemaDeps=bc.validatePropertyDeps=bc.error=void 0;var TA=St(),one=Ut(),pw=Ks();bc.error={message:({params:{property:t,depsCount:e,deps:r}})=>{let n=e===1?"property":"properties";return(0,TA.str)`must have ${n} ${r} when property ${t} is present`},params:({params:{property:t,depsCount:e,deps:r,missingProperty:n}})=>(0,TA._)`{property: ${t},
|
|
8
8
|
missingProperty: ${n},
|
|
9
9
|
depsCount: ${e},
|
|
10
|
-
deps: ${r}}`};var sne={keyword:"dependencies",type:"object",schemaType:"object",error:bc.error,code(t){let[e,r]=ane(t);CN(t,e),$N(t,r)}};function ane({schema:t}){let e={},r={};for(let n in t){if(n==="__proto__")continue;let i=Array.isArray(t[n])?e:r;i[n]=t[n]}return[e,r]}function CN(t,e=t.schema){let{gen:r,data:n,it:i}=t;if(Object.keys(e).length===0)return;let a=r.let("missing");for(let s in e){let o=e[s];if(o.length===0)continue;let d=(0,pw.propertyInData)(r,n,s,i.opts.ownProperties);t.setParams({property:s,depsCount:o.length,deps:o.join(", ")}),i.allErrors?r.if(d,()=>{for(let u of o)(0,pw.checkReportMissingProp)(t,u)}):(r.if((0,TA._)`${d} && (${(0,pw.checkMissingProp)(t,o,a)})`),(0,pw.reportMissingProp)(t,a),r.else())}}bc.validatePropertyDeps=CN;function $N(t,e=t.schema){let{gen:r,data:n,keyword:i,it:a}=t,s=r.name("valid");for(let o in e)(0,one.alwaysValidSchema)(a,e[o])||(r.if((0,pw.propertyInData)(r,n,o,a.opts.ownProperties),()=>{let d=t.subschema({keyword:i,schemaProp:o},s);t.mergeValidEvaluated(d,s)},()=>r.var(s,!0)),t.ok(s))}bc.validateSchemaDeps=$N;bc.default=sne});var BN=_e(kA=>{"use strict";y();Object.defineProperty(kA,"__esModule",{value:!0});var ON=St(),cne=Ut(),dne={message:"property name must be valid",params:({params:t})=>(0,ON._)`{propertyName: ${t.propertyName}}`},une={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:dne,code(t){let{gen:e,schema:r,data:n,it:i}=t;if((0,cne.alwaysValidSchema)(i,r))return;let a=e.name("valid");e.forIn("key",n,s=>{t.setParams({propertyName:s}),t.subschema({keyword:"propertyNames",data:s,dataTypes:["string"],propertyName:s,compositeRule:!0},a),e.if((0,ON.not)(a),()=>{t.error(!0),i.allErrors||e.break()})}),t.ok(a)}};kA.default=une});var DA=_e(AA=>{"use strict";y();Object.defineProperty(AA,"__esModule",{value:!0});var A1=Ks(),ja=St(),lne=Us(),D1=Ut(),fne={message:"must NOT have additional properties",params:({params:t})=>(0,ja._)`{additionalProperty: ${t.additionalProperty}}`},pne={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:fne,code(t){let{gen:e,schema:r,parentSchema:n,data:i,errsCount:a,it:s}=t;if(!a)throw new Error("ajv implementation error");let{allErrors:o,opts:d}=s;if(s.props=!0,d.removeAdditional!=="all"&&(0,D1.alwaysValidSchema)(s,r))return;let u=(0,A1.allSchemaProperties)(n.properties),c=(0,A1.allSchemaProperties)(n.patternProperties);l(),t.ok((0,ja._)`${a} === ${lne.default.errors}`);function l(){e.forIn("key",i,g=>{!u.length&&!c.length?p(g):e.if(f(g),()=>p(g))})}function f(g){let _;if(u.length>8){let v=(0,D1.schemaRefOrVal)(s,n.properties,"properties");_=(0,A1.isOwnProperty)(e,v,g)}else u.length?_=(0,ja.or)(...u.map(v=>(0,ja._)`${g} === ${v}`)):_=ja.nil;return c.length&&(_=(0,ja.or)(_,...c.map(v=>(0,ja._)`${(0,A1.usePattern)(t,v)}.test(${g})`))),(0,ja.not)(_)}function h(g){e.code((0,ja._)`delete ${i}[${g}]`)}function p(g){if(d.removeAdditional==="all"||d.removeAdditional&&r===!1){h(g);return}if(r===!1){t.setParams({additionalProperty:g}),t.error(),o||e.break();return}if(typeof r=="object"&&!(0,D1.alwaysValidSchema)(s,r)){let _=e.name("valid");d.removeAdditional==="failing"?(m(g,_,!1),e.if((0,ja.not)(_),()=>{t.reset(),h(g)})):(m(g,_),o||e.if((0,ja.not)(_),()=>e.break()))}}function m(g,_,v){let E={keyword:"additionalProperties",dataProp:g,dataPropType:D1.Type.Str};v===!1&&Object.assign(E,{compositeRule:!0,createErrors:!1,allErrors:!1}),t.subschema(E,_)}}};AA.default=pne});var NN=_e(RA=>{"use strict";y();Object.defineProperty(RA,"__esModule",{value:!0});var hne=Qg(),jN=Ks(),IA=Ut(),MN=DA(),mne={keyword:"properties",type:"object",schemaType:"object",code(t){let{gen:e,schema:r,parentSchema:n,data:i,it:a}=t;a.opts.removeAdditional==="all"&&n.additionalProperties===void 0&&MN.default.code(new hne.KeywordCxt(a,MN.default,"additionalProperties"));let s=(0,jN.allSchemaProperties)(r);for(let l of s)a.definedProperties.add(l);a.opts.unevaluated&&s.length&&a.props!==!0&&(a.props=IA.mergeEvaluated.props(e,(0,IA.toHash)(s),a.props));let o=s.filter(l=>!(0,IA.alwaysValidSchema)(a,r[l]));if(o.length===0)return;let d=e.name("valid");for(let l of o)u(l)?c(l):(e.if((0,jN.propertyInData)(e,i,l,a.opts.ownProperties)),c(l),a.allErrors||e.else().var(d,!0),e.endIf()),t.it.definedProperties.add(l),t.ok(d);function u(l){return a.opts.useDefaults&&!a.compositeRule&&r[l].default!==void 0}function c(l){t.subschema({keyword:"properties",schemaProp:l,dataProp:l},d)}}};RA.default=mne});var LN=_e(CA=>{"use strict";y();Object.defineProperty(CA,"__esModule",{value:!0});var UN=Ks(),I1=St(),KN=Ut(),qN=Ut(),yne={keyword:"patternProperties",type:"object",schemaType:"object",code(t){let{gen:e,schema:r,data:n,parentSchema:i,it:a}=t,{opts:s}=a,o=(0,UN.allSchemaProperties)(r),d=o.filter(m=>(0,KN.alwaysValidSchema)(a,r[m]));if(o.length===0||d.length===o.length&&(!a.opts.unevaluated||a.props===!0))return;let u=s.strictSchema&&!s.allowMatchingProperties&&i.properties,c=e.name("valid");a.props!==!0&&!(a.props instanceof I1.Name)&&(a.props=(0,qN.evaluatedPropsToName)(e,a.props));let{props:l}=a;f();function f(){for(let m of o)u&&h(m),a.allErrors?p(m):(e.var(c,!0),p(m),e.if(c))}function h(m){for(let g in u)new RegExp(m).test(g)&&(0,KN.checkStrictMode)(a,`property ${g} matches pattern ${m} (use allowMatchingProperties)`)}function p(m){e.forIn("key",n,g=>{e.if((0,I1._)`${(0,UN.usePattern)(t,m)}.test(${g})`,()=>{let _=d.includes(m);_||t.subschema({keyword:"patternProperties",schemaProp:m,dataProp:g,dataPropType:qN.Type.Str},c),a.opts.unevaluated&&l!==!0?e.assign((0,I1._)`${l}[${g}]`,!0):!_&&!a.allErrors&&e.if((0,I1.not)(c),()=>e.break())})})}}};CA.default=yne});var zN=_e($A=>{"use strict";y();Object.defineProperty($A,"__esModule",{value:!0});var gne=Ut(),wne={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(t){let{gen:e,schema:r,it:n}=t;if((0,gne.alwaysValidSchema)(n,r)){t.fail();return}let i=e.name("valid");t.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},i),t.failResult(i,()=>t.reset(),()=>t.error())},error:{message:"must NOT be valid"}};$A.default=wne});var FN=_e(OA=>{"use strict";y();Object.defineProperty(OA,"__esModule",{value:!0});var vne=Ks(),bne={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:vne.validateUnion,error:{message:"must match a schema in anyOf"}};OA.default=bne});var GN=_e(BA=>{"use strict";y();Object.defineProperty(BA,"__esModule",{value:!0});var R1=St(),xne=Ut(),Pne={message:"must match exactly one schema in oneOf",params:({params:t})=>(0,R1._)`{passingSchemas: ${t.passing}}`},_ne={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:Pne,code(t){let{gen:e,schema:r,parentSchema:n,it:i}=t;if(!Array.isArray(r))throw new Error("ajv implementation error");if(i.opts.discriminator&&n.discriminator)return;let a=r,s=e.let("valid",!1),o=e.let("passing",null),d=e.name("_valid");t.setParams({passing:o}),e.block(u),t.result(s,()=>t.reset(),()=>t.error(!0));function u(){a.forEach((c,l)=>{let f;(0,xne.alwaysValidSchema)(i,c)?e.var(d,!0):f=t.subschema({keyword:"oneOf",schemaProp:l,compositeRule:!0},d),l>0&&e.if((0,R1._)`${d} && ${s}`).assign(s,!1).assign(o,(0,R1._)`[${o}, ${l}]`).else(),e.if(d,()=>{e.assign(s,!0),e.assign(o,l),f&&t.mergeEvaluated(f,R1.Name)})})}}};BA.default=_ne});var WN=_e(jA=>{"use strict";y();Object.defineProperty(jA,"__esModule",{value:!0});var Ene=Ut(),Sne={keyword:"allOf",schemaType:"array",code(t){let{gen:e,schema:r,it:n}=t;if(!Array.isArray(r))throw new Error("ajv implementation error");let i=e.name("valid");r.forEach((a,s)=>{if((0,Ene.alwaysValidSchema)(n,a))return;let o=t.subschema({keyword:"allOf",schemaProp:s},i);t.ok(i),t.mergeEvaluated(o)})}};jA.default=Sne});var JN=_e(MA=>{"use strict";y();Object.defineProperty(MA,"__esModule",{value:!0});var C1=St(),VN=Ut(),Tne={message:({params:t})=>(0,C1.str)`must match "${t.ifClause}" schema`,params:({params:t})=>(0,C1._)`{failingKeyword: ${t.ifClause}}`},kne={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:Tne,code(t){let{gen:e,parentSchema:r,it:n}=t;r.then===void 0&&r.else===void 0&&(0,VN.checkStrictMode)(n,'"if" without "then" and "else" is ignored');let i=HN(n,"then"),a=HN(n,"else");if(!i&&!a)return;let s=e.let("valid",!0),o=e.name("_valid");if(d(),t.reset(),i&&a){let c=e.let("ifClause");t.setParams({ifClause:c}),e.if(o,u("then",c),u("else",c))}else i?e.if(o,u("then")):e.if((0,C1.not)(o),u("else"));t.pass(s,()=>t.error(!0));function d(){let c=t.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},o);t.mergeEvaluated(c)}function u(c,l){return()=>{let f=t.subschema({keyword:c},o);e.assign(s,o),t.mergeValidEvaluated(f,s),l?e.assign(l,(0,C1._)`${c}`):t.setParams({ifClause:c})}}}};function HN(t,e){let r=t.schema[e];return r!==void 0&&!(0,VN.alwaysValidSchema)(t,r)}MA.default=kne});var ZN=_e(NA=>{"use strict";y();Object.defineProperty(NA,"__esModule",{value:!0});var Ane=Ut(),Dne={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:t,parentSchema:e,it:r}){e.if===void 0&&(0,Ane.checkStrictMode)(r,`"${t}" without "if" is ignored`)}};NA.default=Dne});var YN=_e(UA=>{"use strict";y();Object.defineProperty(UA,"__esModule",{value:!0});var Ine=xA(),Rne=AN(),Cne=PA(),$ne=IN(),One=RN(),Bne=k1(),jne=BN(),Mne=DA(),Nne=NN(),Une=LN(),Kne=zN(),qne=FN(),Lne=GN(),zne=WN(),Fne=JN(),Gne=ZN();function Wne(t=!1){let e=[Kne.default,qne.default,Lne.default,zne.default,Fne.default,Gne.default,jne.default,Mne.default,Bne.default,Nne.default,Une.default];return t?e.push(Rne.default,$ne.default):e.push(Ine.default,Cne.default),e.push(One.default),e}UA.default=Wne});var qA=_e(hw=>{"use strict";y();Object.defineProperty(hw,"__esModule",{value:!0});hw.dynamicAnchor=void 0;var KA=St(),Hne=Us(),QN=ew(),Vne=x1(),Jne={keyword:"$dynamicAnchor",schemaType:"string",code:t=>XN(t,t.schema)};function XN(t,e){let{gen:r,it:n}=t;n.schemaEnv.root.dynamicAnchors[e]=!0;let i=(0,KA._)`${Hne.default.dynamicAnchors}${(0,KA.getProperty)(e)}`,a=n.errSchemaPath==="#"?n.validateName:Zne(t);r.if((0,KA._)`!${i}`,()=>r.assign(i,a))}hw.dynamicAnchor=XN;function Zne(t){let{schemaEnv:e,schema:r,self:n}=t.it,{root:i,baseId:a,localRefs:s,meta:o}=e.root,{schemaId:d}=n.opts,u=new QN.SchemaEnv({schema:r,schemaId:d,root:i,baseId:a,localRefs:s,meta:o});return QN.compileSchema.call(n,u),(0,Vne.getValidate)(t,u)}hw.default=Jne});var LA=_e(mw=>{"use strict";y();Object.defineProperty(mw,"__esModule",{value:!0});mw.dynamicRef=void 0;var eU=St(),Yne=Us(),tU=x1(),Qne={keyword:"$dynamicRef",schemaType:"string",code:t=>rU(t,t.schema)};function rU(t,e){let{gen:r,keyword:n,it:i}=t;if(e[0]!=="#")throw new Error(`"${n}" only supports hash fragment reference`);let a=e.slice(1);if(i.allErrors)s();else{let d=r.let("valid",!1);s(d),t.ok(d)}function s(d){if(i.schemaEnv.root.dynamicAnchors[a]){let u=r.let("_v",(0,eU._)`${Yne.default.dynamicAnchors}${(0,eU.getProperty)(a)}`);r.if(u,o(u,d),o(i.validateName,d))}else o(i.validateName,d)()}function o(d,u){return u?()=>r.block(()=>{(0,tU.callRef)(t,d),r.let(u,!0)}):()=>(0,tU.callRef)(t,d)}}mw.dynamicRef=rU;mw.default=Qne});var nU=_e(zA=>{"use strict";y();Object.defineProperty(zA,"__esModule",{value:!0});var Xne=qA(),eie=Ut(),tie={keyword:"$recursiveAnchor",schemaType:"boolean",code(t){t.schema?(0,Xne.dynamicAnchor)(t,""):(0,eie.checkStrictMode)(t.it,"$recursiveAnchor: false is ignored")}};zA.default=tie});var iU=_e(FA=>{"use strict";y();Object.defineProperty(FA,"__esModule",{value:!0});var rie=LA(),nie={keyword:"$recursiveRef",schemaType:"string",code:t=>(0,rie.dynamicRef)(t,t.schema)};FA.default=nie});var oU=_e(GA=>{"use strict";y();Object.defineProperty(GA,"__esModule",{value:!0});var iie=qA(),oie=LA(),sie=nU(),aie=iU(),cie=[iie.default,oie.default,sie.default,aie.default];GA.default=cie});var aU=_e(WA=>{"use strict";y();Object.defineProperty(WA,"__esModule",{value:!0});var sU=k1(),die={keyword:"dependentRequired",type:"object",schemaType:"object",error:sU.error,code:t=>(0,sU.validatePropertyDeps)(t)};WA.default=die});var cU=_e(HA=>{"use strict";y();Object.defineProperty(HA,"__esModule",{value:!0});var uie=k1(),lie={keyword:"dependentSchemas",type:"object",schemaType:"object",code:t=>(0,uie.validateSchemaDeps)(t)};HA.default=lie});var dU=_e(VA=>{"use strict";y();Object.defineProperty(VA,"__esModule",{value:!0});var fie=Ut(),pie={keyword:["maxContains","minContains"],type:"array",schemaType:"number",code({keyword:t,parentSchema:e,it:r}){e.contains===void 0&&(0,fie.checkStrictMode)(r,`"${t}" without "contains" is ignored`)}};VA.default=pie});var uU=_e(JA=>{"use strict";y();Object.defineProperty(JA,"__esModule",{value:!0});var hie=aU(),mie=cU(),yie=dU(),gie=[hie.default,mie.default,yie.default];JA.default=gie});var fU=_e(ZA=>{"use strict";y();Object.defineProperty(ZA,"__esModule",{value:!0});var $u=St(),lU=Ut(),wie=Us(),vie={message:"must NOT have unevaluated properties",params:({params:t})=>(0,$u._)`{unevaluatedProperty: ${t.unevaluatedProperty}}`},bie={keyword:"unevaluatedProperties",type:"object",schemaType:["boolean","object"],trackErrors:!0,error:vie,code(t){let{gen:e,schema:r,data:n,errsCount:i,it:a}=t;if(!i)throw new Error("ajv implementation error");let{allErrors:s,props:o}=a;o instanceof $u.Name?e.if((0,$u._)`${o} !== true`,()=>e.forIn("key",n,l=>e.if(u(o,l),()=>d(l)))):o!==!0&&e.forIn("key",n,l=>o===void 0?d(l):e.if(c(o,l),()=>d(l))),a.props=!0,t.ok((0,$u._)`${i} === ${wie.default.errors}`);function d(l){if(r===!1){t.setParams({unevaluatedProperty:l}),t.error(),s||e.break();return}if(!(0,lU.alwaysValidSchema)(a,r)){let f=e.name("valid");t.subschema({keyword:"unevaluatedProperties",dataProp:l,dataPropType:lU.Type.Str},f),s||e.if((0,$u.not)(f),()=>e.break())}}function u(l,f){return(0,$u._)`!${l} || !${l}[${f}]`}function c(l,f){let h=[];for(let p in l)l[p]===!0&&h.push((0,$u._)`${f} !== ${p}`);return(0,$u.and)(...h)}}};ZA.default=bie});var hU=_e(YA=>{"use strict";y();Object.defineProperty(YA,"__esModule",{value:!0});var Pf=St(),pU=Ut(),xie={message:({params:{len:t}})=>(0,Pf.str)`must NOT have more than ${t} items`,params:({params:{len:t}})=>(0,Pf._)`{limit: ${t}}`},Pie={keyword:"unevaluatedItems",type:"array",schemaType:["boolean","object"],error:xie,code(t){let{gen:e,schema:r,data:n,it:i}=t,a=i.items||0;if(a===!0)return;let s=e.const("len",(0,Pf._)`${n}.length`);if(r===!1)t.setParams({len:a}),t.fail((0,Pf._)`${s} > ${a}`);else if(typeof r=="object"&&!(0,pU.alwaysValidSchema)(i,r)){let d=e.var("valid",(0,Pf._)`${s} <= ${a}`);e.if((0,Pf.not)(d),()=>o(d,a)),t.ok(d)}i.items=!0;function o(d,u){e.forRange("i",u,s,c=>{t.subschema({keyword:"unevaluatedItems",dataProp:c,dataPropType:pU.Type.Num},d),i.allErrors||e.if((0,Pf.not)(d),()=>e.break())})}}};YA.default=Pie});var mU=_e(QA=>{"use strict";y();Object.defineProperty(QA,"__esModule",{value:!0});var _ie=fU(),Eie=hU(),Sie=[_ie.default,Eie.default];QA.default=Sie});var yU=_e(XA=>{"use strict";y();Object.defineProperty(XA,"__esModule",{value:!0});var kn=St(),Tie={message:({schemaCode:t})=>(0,kn.str)`must match format "${t}"`,params:({schemaCode:t})=>(0,kn._)`{format: ${t}}`},kie={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:Tie,code(t,e){let{gen:r,data:n,$data:i,schema:a,schemaCode:s,it:o}=t,{opts:d,errSchemaPath:u,schemaEnv:c,self:l}=o;if(!d.validateFormats)return;i?f():h();function f(){let p=r.scopeValue("formats",{ref:l.formats,code:d.code.formats}),m=r.const("fDef",(0,kn._)`${p}[${s}]`),g=r.let("fType"),_=r.let("format");r.if((0,kn._)`typeof ${m} == "object" && !(${m} instanceof RegExp)`,()=>r.assign(g,(0,kn._)`${m}.type || "string"`).assign(_,(0,kn._)`${m}.validate`),()=>r.assign(g,(0,kn._)`"string"`).assign(_,m)),t.fail$data((0,kn.or)(v(),E()));function v(){return d.strictSchema===!1?kn.nil:(0,kn._)`${s} && !${_}`}function E(){let T=c.$async?(0,kn._)`(${m}.async ? await ${_}(${n}) : ${_}(${n}))`:(0,kn._)`${_}(${n})`,D=(0,kn._)`(typeof ${_} == "function" ? ${T} : ${_}.test(${n}))`;return(0,kn._)`${_} && ${_} !== true && ${g} === ${e} && !${D}`}}function h(){let p=l.formats[a];if(!p){v();return}if(p===!0)return;let[m,g,_]=E(p);m===e&&t.pass(T());function v(){if(d.strictSchema===!1){l.logger.warn(D());return}throw new Error(D());function D(){return`unknown format "${a}" ignored in schema at path "${u}"`}}function E(D){let R=D instanceof RegExp?(0,kn.regexpCode)(D):d.code.formats?(0,kn._)`${d.code.formats}${(0,kn.getProperty)(a)}`:void 0,N=r.scopeValue("formats",{key:a,ref:D,code:R});return typeof D=="object"&&!(D instanceof RegExp)?[D.type||"string",D.validate,(0,kn._)`${N}.validate`]:["string",D,N]}function T(){if(typeof p=="object"&&!(p instanceof RegExp)&&p.async){if(!c.$async)throw new Error("async format in sync schema");return(0,kn._)`await ${_}(${n})`}return typeof g=="function"?(0,kn._)`${_}(${n})`:(0,kn._)`${_}.test(${n})`}}}};XA.default=kie});var gU=_e(eD=>{"use strict";y();Object.defineProperty(eD,"__esModule",{value:!0});var Aie=yU(),Die=[Aie.default];eD.default=Die});var wU=_e(zh=>{"use strict";y();Object.defineProperty(zh,"__esModule",{value:!0});zh.contentVocabulary=zh.metadataVocabulary=void 0;zh.metadataVocabulary=["title","description","default","deprecated","readOnly","writeOnly","examples"];zh.contentVocabulary=["contentMediaType","contentEncoding","contentSchema"]});var bU=_e(tD=>{"use strict";y();Object.defineProperty(tD,"__esModule",{value:!0});var Iie=fN(),Rie=EN(),Cie=YN(),$ie=oU(),Oie=uU(),Bie=mU(),jie=gU(),vU=wU(),Mie=[$ie.default,Iie.default,Rie.default,(0,Cie.default)(!0),jie.default,vU.metadataVocabulary,vU.contentVocabulary,Oie.default,Bie.default];tD.default=Mie});var PU=_e($1=>{"use strict";y();Object.defineProperty($1,"__esModule",{value:!0});$1.DiscrError=void 0;var xU;(function(t){t.Tag="tag",t.Mapping="mapping"})(xU||($1.DiscrError=xU={}))});var EU=_e(nD=>{"use strict";y();Object.defineProperty(nD,"__esModule",{value:!0});var Fh=St(),rD=PU(),_U=ew(),Nie=Xg(),Uie=Ut(),Kie={message:({params:{discrError:t,tagName:e}})=>t===rD.DiscrError.Tag?`tag "${e}" must be string`:`value of tag "${e}" must be in oneOf`,params:({params:{discrError:t,tag:e,tagName:r}})=>(0,Fh._)`{error: ${t}, tag: ${r}, tagValue: ${e}}`},qie={keyword:"discriminator",type:"object",schemaType:"object",error:Kie,code(t){let{gen:e,data:r,schema:n,parentSchema:i,it:a}=t,{oneOf:s}=i;if(!a.opts.discriminator)throw new Error("discriminator: requires discriminator option");let o=n.propertyName;if(typeof o!="string")throw new Error("discriminator: requires propertyName");if(n.mapping)throw new Error("discriminator: mapping is not supported");if(!s)throw new Error("discriminator: requires oneOf keyword");let d=e.let("valid",!1),u=e.const("tag",(0,Fh._)`${r}${(0,Fh.getProperty)(o)}`);e.if((0,Fh._)`typeof ${u} == "string"`,()=>c(),()=>t.error(!1,{discrError:rD.DiscrError.Tag,tag:u,tagName:o})),t.ok(d);function c(){let h=f();e.if(!1);for(let p in h)e.elseIf((0,Fh._)`${u} === ${p}`),e.assign(d,l(h[p]));e.else(),t.error(!1,{discrError:rD.DiscrError.Mapping,tag:u,tagName:o}),e.endIf()}function l(h){let p=e.name("valid"),m=t.subschema({keyword:"oneOf",schemaProp:h},p);return t.mergeEvaluated(m,Fh.Name),p}function f(){var h;let p={},m=_(i),g=!0;for(let T=0;T<s.length;T++){let D=s[T];if(D?.$ref&&!(0,Uie.schemaHasRulesButRef)(D,a.self.RULES)){let N=D.$ref;if(D=_U.resolveRef.call(a.self,a.schemaEnv.root,a.baseId,N),D instanceof _U.SchemaEnv&&(D=D.schema),D===void 0)throw new Nie.default(a.opts.uriResolver,a.baseId,N)}let R=(h=D?.properties)===null||h===void 0?void 0:h[o];if(typeof R!="object")throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${o}"`);g=g&&(m||_(D)),v(R,T)}if(!g)throw new Error(`discriminator: "${o}" must be required`);return p;function _({required:T}){return Array.isArray(T)&&T.includes(o)}function v(T,D){if(T.const)E(T.const,D);else if(T.enum)for(let R of T.enum)E(R,D);else throw new Error(`discriminator: "properties/${o}" must have "const" or "enum"`)}function E(T,D){if(typeof T!="string"||T in p)throw new Error(`discriminator: "${o}" values must be unique strings`);p[T]=D}}}};nD.default=qie});var SU=_e((t8e,Lie)=>{Lie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/schema",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0,"https://json-schema.org/draft/2020-12/vocab/applicator":!0,"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0,"https://json-schema.org/draft/2020-12/vocab/validation":!0,"https://json-schema.org/draft/2020-12/vocab/meta-data":!0,"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0,"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Core and Validation specifications meta-schema",allOf:[{$ref:"meta/core"},{$ref:"meta/applicator"},{$ref:"meta/unevaluated"},{$ref:"meta/validation"},{$ref:"meta/meta-data"},{$ref:"meta/format-annotation"},{$ref:"meta/content"}],type:["object","boolean"],$comment:"This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",properties:{definitions:{$comment:'"definitions" has been replaced by "$defs".',type:"object",additionalProperties:{$dynamicRef:"#meta"},deprecated:!0,default:{}},dependencies:{$comment:'"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',type:"object",additionalProperties:{anyOf:[{$dynamicRef:"#meta"},{$ref:"meta/validation#/$defs/stringArray"}]},deprecated:!0,default:{}},$recursiveAnchor:{$comment:'"$recursiveAnchor" has been replaced by "$dynamicAnchor".',$ref:"meta/core#/$defs/anchorString",deprecated:!0},$recursiveRef:{$comment:'"$recursiveRef" has been replaced by "$dynamicRef".',$ref:"meta/core#/$defs/uriReferenceString",deprecated:!0}}}});var TU=_e((r8e,zie)=>{zie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/applicator",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/applicator":!0},$dynamicAnchor:"meta",title:"Applicator vocabulary meta-schema",type:["object","boolean"],properties:{prefixItems:{$ref:"#/$defs/schemaArray"},items:{$dynamicRef:"#meta"},contains:{$dynamicRef:"#meta"},additionalProperties:{$dynamicRef:"#meta"},properties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},patternProperties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},propertyNames:{format:"regex"},default:{}},dependentSchemas:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},propertyNames:{$dynamicRef:"#meta"},if:{$dynamicRef:"#meta"},then:{$dynamicRef:"#meta"},else:{$dynamicRef:"#meta"},allOf:{$ref:"#/$defs/schemaArray"},anyOf:{$ref:"#/$defs/schemaArray"},oneOf:{$ref:"#/$defs/schemaArray"},not:{$dynamicRef:"#meta"}},$defs:{schemaArray:{type:"array",minItems:1,items:{$dynamicRef:"#meta"}}}}});var kU=_e((n8e,Fie)=>{Fie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/unevaluated",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0},$dynamicAnchor:"meta",title:"Unevaluated applicator vocabulary meta-schema",type:["object","boolean"],properties:{unevaluatedItems:{$dynamicRef:"#meta"},unevaluatedProperties:{$dynamicRef:"#meta"}}}});var AU=_e((i8e,Gie)=>{Gie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/content",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Content vocabulary meta-schema",type:["object","boolean"],properties:{contentEncoding:{type:"string"},contentMediaType:{type:"string"},contentSchema:{$dynamicRef:"#meta"}}}});var DU=_e((o8e,Wie)=>{Wie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/core",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0},$dynamicAnchor:"meta",title:"Core vocabulary meta-schema",type:["object","boolean"],properties:{$id:{$ref:"#/$defs/uriReferenceString",$comment:"Non-empty fragments not allowed.",pattern:"^[^#]*#?$"},$schema:{$ref:"#/$defs/uriString"},$ref:{$ref:"#/$defs/uriReferenceString"},$anchor:{$ref:"#/$defs/anchorString"},$dynamicRef:{$ref:"#/$defs/uriReferenceString"},$dynamicAnchor:{$ref:"#/$defs/anchorString"},$vocabulary:{type:"object",propertyNames:{$ref:"#/$defs/uriString"},additionalProperties:{type:"boolean"}},$comment:{type:"string"},$defs:{type:"object",additionalProperties:{$dynamicRef:"#meta"}}},$defs:{anchorString:{type:"string",pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},uriString:{type:"string",format:"uri"},uriReferenceString:{type:"string",format:"uri-reference"}}}});var IU=_e((s8e,Hie)=>{Hie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/format-annotation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0},$dynamicAnchor:"meta",title:"Format vocabulary meta-schema for annotation results",type:["object","boolean"],properties:{format:{type:"string"}}}});var RU=_e((a8e,Vie)=>{Vie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/meta-data",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/meta-data":!0},$dynamicAnchor:"meta",title:"Meta-data vocabulary meta-schema",type:["object","boolean"],properties:{title:{type:"string"},description:{type:"string"},default:!0,deprecated:{type:"boolean",default:!1},readOnly:{type:"boolean",default:!1},writeOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0}}}});var CU=_e((c8e,Jie)=>{Jie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/validation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/validation":!0},$dynamicAnchor:"meta",title:"Validation vocabulary meta-schema",type:["object","boolean"],properties:{type:{anyOf:[{$ref:"#/$defs/simpleTypes"},{type:"array",items:{$ref:"#/$defs/simpleTypes"},minItems:1,uniqueItems:!0}]},const:!0,enum:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/$defs/nonNegativeInteger"},minLength:{$ref:"#/$defs/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},maxItems:{$ref:"#/$defs/nonNegativeInteger"},minItems:{$ref:"#/$defs/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxContains:{$ref:"#/$defs/nonNegativeInteger"},minContains:{$ref:"#/$defs/nonNegativeInteger",default:1},maxProperties:{$ref:"#/$defs/nonNegativeInteger"},minProperties:{$ref:"#/$defs/nonNegativeIntegerDefault0"},required:{$ref:"#/$defs/stringArray"},dependentRequired:{type:"object",additionalProperties:{$ref:"#/$defs/stringArray"}}},$defs:{nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{$ref:"#/$defs/nonNegativeInteger",default:0},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}}}});var $U=_e(iD=>{"use strict";y();Object.defineProperty(iD,"__esModule",{value:!0});var Zie=SU(),Yie=TU(),Qie=kU(),Xie=AU(),eoe=DU(),toe=IU(),roe=RU(),noe=CU(),ioe=["/properties"];function ooe(t){return[Zie,Yie,Qie,Xie,eoe,e(this,toe),roe,e(this,noe)].forEach(r=>this.addMetaSchema(r,void 0,!1)),this;function e(r,n){return t?r.$dataMetaSchema(n,ioe):n}}iD.default=ooe});var OU=_e((Hr,sD)=>{"use strict";y();Object.defineProperty(Hr,"__esModule",{value:!0});Hr.MissingRefError=Hr.ValidationError=Hr.CodeGen=Hr.Name=Hr.nil=Hr.stringify=Hr.str=Hr._=Hr.KeywordCxt=Hr.Ajv2020=void 0;var soe=aN(),aoe=bU(),coe=EU(),doe=$U(),oD="https://json-schema.org/draft/2020-12/schema",Gh=class extends soe.default{constructor(e={}){super({...e,dynamicRef:!0,next:!0,unevaluated:!0})}_addVocabularies(){super._addVocabularies(),aoe.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(coe.default)}_addDefaultMetaSchema(){super._addDefaultMetaSchema();let{$data:e,meta:r}=this.opts;r&&(doe.default.call(this,e),this.refs["http://json-schema.org/schema"]=oD)}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(oD)?oD:void 0)}};Hr.Ajv2020=Gh;sD.exports=Hr=Gh;sD.exports.Ajv2020=Gh;Object.defineProperty(Hr,"__esModule",{value:!0});Hr.default=Gh;var uoe=Qg();Object.defineProperty(Hr,"KeywordCxt",{enumerable:!0,get:function(){return uoe.KeywordCxt}});var Wh=St();Object.defineProperty(Hr,"_",{enumerable:!0,get:function(){return Wh._}});Object.defineProperty(Hr,"str",{enumerable:!0,get:function(){return Wh.str}});Object.defineProperty(Hr,"stringify",{enumerable:!0,get:function(){return Wh.stringify}});Object.defineProperty(Hr,"nil",{enumerable:!0,get:function(){return Wh.nil}});Object.defineProperty(Hr,"Name",{enumerable:!0,get:function(){return Wh.Name}});Object.defineProperty(Hr,"CodeGen",{enumerable:!0,get:function(){return Wh.CodeGen}});var loe=f1();Object.defineProperty(Hr,"ValidationError",{enumerable:!0,get:function(){return loe.default}});var foe=Xg();Object.defineProperty(Hr,"MissingRefError",{enumerable:!0,get:function(){return foe.default}})});var _f,O1=F(()=>{"use strict";y();db();mt();_f=class t{static async authorizeConfigure(e){let{protocolsConfigureMessage:r,expectedGrantor:n,expectedGrantee:i,permissionGrant:a,messageStore:s}=e;await Ea.performBaseValidation({incomingMessage:r,expectedGrantor:n,expectedGrantee:i,permissionGrant:a,messageStore:s}),t.verifyScope(r,a.scope)}static async authorizeQuery(e){let{expectedGrantee:r,expectedGrantor:n,incomingMessage:i,permissionGrant:a,messageStore:s}=e;await Ea.performBaseValidation({incomingMessage:i,expectedGrantor:n,expectedGrantee:r,permissionGrant:a,messageStore:s});let d=a.scope.protocol,u=i.descriptor.filter?.protocol;if(d!==void 0&&u!==d)throw new le(ue.ProtocolsGrantAuthorizationQueryProtocolScopeMismatch,`Grant protocol scope ${d} does not match protocol in message ${u}`)}static verifyScope(e,r){if(r.protocol!==void 0&&r.protocol!==e.descriptor.definition.protocol)throw new le(ue.ProtocolsGrantAuthorizationScopeProtocolMismatch,"Grant scope specifies different protocol than what appears in the configure message.")}}});function Ef(t){let e=t.indexOf(":");if(e===-1)return;let r=t.substring(0,e),n=t.substring(e+1);return{alias:r,protocolPath:n}}function yw(t){return t.includes(":")}var Sf=F(()=>{"use strict";y();rn();oh()});var BU,Tf,B1=F(()=>{"use strict";y();Da();BU=wn(OU(),1);or();va();O1();Qi();mt();Yt();Sf();Bs();Mm();Tf=class t extends gn{static async parse(e){return Se.validateJsonSchema(e),t.validateProtocolDefinition(e.descriptor.definition),await Se.validateSignatureStructure(e.authorization.signature,e.descriptor),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Protocols,method:ze.Configure,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),definition:t.normalizeDefinition(e.definition),...e.permissionGrantId!==void 0&&{permissionGrantId:e.permissionGrantId}},n=await Se.createAuthorization({descriptor:r,signer:e.signer,delegatedGrant:e.delegatedGrant,permissionGrantId:e.permissionGrantId}),i={descriptor:r,authorization:n};return Se.validateJsonSchema(i),t.validateProtocolDefinition(i.descriptor.definition),new t(i)}async authorizeAuthorDelegate(e){let r=dr.parse(this.message.authorization.authorDelegatedGrant);await _f.authorizeConfigure({protocolsConfigureMessage:this.message,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:r,messageStore:e})}static validateProtocolDefinition(e){let{protocol:r,types:n,uses:i}=e;qn(r);for(let a in n){let s=n[a].schema;s!==void 0&&ic(s)}i!==void 0&&t.validateUses(i,r),t.validateStructure(e)}static validateUses(e,r){let n=/^[a-zA-Z][a-zA-Z0-9_-]*$/;for(let i in e){if(!n.test(i))throw new le(ue.ProtocolsConfigureInvalidUsesAlias,`invalid 'uses' alias '${i}': must match pattern ${n.toString()}.`);try{qn(e[i])}catch{throw new le(ue.ProtocolsConfigureInvalidUsesProtocolUrl,`invalid 'uses' protocol URL for alias '${i}': '${e[i]}' is not a valid normalized protocol URL.`)}if(e[i]===r)throw new le(ue.ProtocolsConfigureInvalidUsesSelfReference,`'uses' alias '${i}' references the protocol's own URI '${r}'. a protocol cannot compose itself.`)}}static validateStructure(e){let{uses:r}=e,n=Object.keys(e.types),i=t.fetchAllRolePathsRecursively("",e.structure,[]);t.validateRuleSetRecursively({ruleSet:e.structure,ruleSetProtocolPath:"",recordTypes:n,roles:i,uses:r,types:e.types})}static fetchAllRolePathsRecursively(e,r,n){if(e.split("/").length>10)throw new le(ue.ProtocolsConfigureRecordNestingDepthExceeded,"Record nesting depth exceeded 10 levels.");for(let i in r){if(i.startsWith("$"))continue;let a=r[i],s;e===""?s=i:s=`${e}/${i}`,a.$role?n.push(s):t.fetchAllRolePathsRecursively(s,a,n)}return n}static validateRuleSetRecursively(e){let{ruleSet:r,ruleSetProtocolPath:n,recordTypes:i,roles:a,uses:s,types:o}=e;if(r.$ref!==void 0){if(n.includes("/"))throw new le(ue.ProtocolsConfigureInvalidRefNotAtRoot,`'$ref' at protocol path '${n}' is not allowed: '$ref' nodes are only supported at the root level of the structure.`);t.validateRefNode(r,n,s)}if(r.$size!==void 0){let{min:u=0,max:c}=r.$size;if(c!==void 0&&c<u)throw new le(ue.ProtocolsConfigureInvalidSize,`Invalid size range found: max limit ${c} less than min limit ${u} at protocol path '${n}'`)}if(r.$recordLimit!==void 0){let{max:u,strategy:c}=r.$recordLimit;if(!Number.isInteger(u)||u<1)throw new le(ue.ProtocolsConfigureInvalidRecordLimit,`Invalid $recordLimit.max value ${u} at protocol path '${n}': must be an integer >= 1.`);let l=Object.values(pp);if(!l.includes(c))throw new le(ue.ProtocolsConfigureInvalidRecordLimit,`Invalid $recordLimit.strategy '${c}' at protocol path '${n}': must be one of ${l.join(", ")}.`)}if(r.$tags){let u=new BU.default.default,{$allowUndefinedTags:c,$requiredTags:l,...f}=r.$tags;for(let h in f){let p=f[h];if(!u.validateSchema(p)){let m=u.errorsText(u.errors,{dataVar:`${n}/$tags/${h}`});throw new le(ue.ProtocolsConfigureInvalidTagSchema,`tags schema validation error: ${m}`)}}}let d=r.$actions??[];for(let u=0;u<d.length;u++){let c=d[u];if(c.role!==void 0){if(yw(c.role))t.validateCrossProtocolAlias(c.role,s,n,"role");else if(!a.includes(c.role))throw new le(ue.ProtocolsConfigureRoleDoesNotExistAtGivenPath,`Role in action ${JSON.stringify(c)} for rule set ${n} does not exist.`)}if(c.who==="anyone"&&c.of)throw new le(ue.ProtocolsConfigureInvalidActionOfNotAllowed,`'of' is not allowed at rule set protocol path (${n})`);if(c.who===cl.Recipient&&c.of===void 0&&c.can.some(f=>![qi.CoUpdate,qi.CoDelete,qi.CoPrune].includes(f)))throw new le(ue.ProtocolsConfigureInvalidRecipientOfAction,"Rules for `recipient` without `of` property must have `can` containing only `co-update`, `co-delete`, and `co-prune`.");if(c.who===cl.Author&&!c.of)throw new le(ue.ProtocolsConfigureInvalidActionMissingOf,"'of' is required when 'author' is specified as 'who'");if(c.of!==void 0&&n!==""){if(yw(c.of))t.validateCrossProtocolAlias(c.of,s,n,"of");else if(!(n===c.of||n.startsWith(c.of+"/")))throw new le(ue.ProtocolsConfigureInvalidActionOfNotAnAncestor,`'of' value '${c.of}' is not an ancestor of protocol path '${n}' in action rule ${JSON.stringify(c)}.`)}if(c.can!==void 0){if(c.can.includes(qi.Update)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionUpdateWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'update' action but missing the required 'create' action.`);if(c.can.includes(qi.Delete)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionDeleteWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'delete' action but missing the required 'create' action.`);if(c.can.includes(qi.Prune)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionPruneWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'prune' action but missing the required 'create' action.`)}for(let l=u+1;l<d.length;l++){let f=d[l];if(c.who!==void 0){if(c.who===f.who&&c.of===f.of)throw new le(ue.ProtocolsConfigureDuplicateActorInRuleSet,`More than one action rule per actor ${c.who} of ${c.of} not allowed within a rule set: ${JSON.stringify(c)}`)}else if(c.role===f.role)throw new le(ue.ProtocolsConfigureDuplicateRoleInRuleSet,`More than one action rule per role ${c.role} not allowed within a rule set: ${JSON.stringify(c)}`)}}if(n!==""){let u=n.split("/").pop();o[u]?.encryptionRequired===!0&&d.some(f=>f.who===cl.Anyone&&f.can.includes(qi.Read))&&console.warn(`ProtocolsConfigure: type '${u}' at path '${n}' has encryptionRequired: true but allows { who: 'anyone', can: ['read'] }. Anyone can read the record but no one outside the key holders can decrypt it.`)}r.$delivery!==void 0&&(r.$actions===void 0||r.$actions.length===0)&&console.warn(`ProtocolsConfigure: protocol path '${n}' has $delivery: '${r.$delivery}' but no $actions rules. The server uses $actions to determine delivery targets \u2014 without $actions, no participants can be resolved for delivery.`),r.$immutable===!0&&d.length>0&&d.some(c=>c.can.includes(qi.Update)||c.can.includes(qi.CoUpdate))&&console.warn(`ProtocolsConfigure: protocol path '${n}' has $immutable: true but $actions include 'update' or 'co-update'. The $immutable directive takes precedence \u2014 updates will always be rejected regardless of action rules.`);for(let u in r){if(u.startsWith("$"))continue;let c=r[u];if(c.$ref===void 0&&!i.includes(u))throw new le(ue.ProtocolsConfigureInvalidRuleSetRecordType,`Rule set ${u} is not declared as an allowed type in the protocol definition.`);let l;n===""?l=u:l=`${n}/${u}`,t.validateRuleSetRecursively({ruleSet:c,ruleSetProtocolPath:l,recordTypes:i,roles:a,uses:s,types:o})}}static validateRefNode(e,r,n){let i=e.$ref,a=Ef(i);if(a===void 0)throw new le(ue.ProtocolsConfigureInvalidRefAlias,`'$ref' value '${i}' at protocol path '${r}' must be in 'alias:typePath' format.`);if(n===void 0||n[a.alias]===void 0)throw new le(ue.ProtocolsConfigureInvalidRefAlias,`'$ref' alias '${a.alias}' at protocol path '${r}' does not exist in the 'uses' map.`);let s=["$actions","$role","$size","$tags","$encryption","$recordLimit","$immutable","$delivery","$squash"];for(let o of s)if(e[o]!==void 0)throw new le(ue.ProtocolsConfigureInvalidRefNodeHasDirectives,`'$ref' node at protocol path '${r}' must not have '${o}'. $ref nodes are pure attachment points \u2014 directives belong on child rule sets.`)}static validateCrossProtocolAlias(e,r,n,i){let a=Ef(e);if(a===void 0){let s=i==="role"?ue.ProtocolsConfigureInvalidCrossProtocolRole:ue.ProtocolsConfigureInvalidCrossProtocolOf;throw new le(s,`cross-protocol '${i}' reference '${e}' at protocol path '${n}' could not be parsed as a valid 'alias:path' format.`)}if(r===void 0||r[a.alias]===void 0){let s=i==="role"?ue.ProtocolsConfigureInvalidCrossProtocolRole:ue.ProtocolsConfigureInvalidCrossProtocolOf;throw new le(s,`cross-protocol '${i}' alias '${a.alias}' in '${e}' at protocol path '${n}' does not exist in the 'uses' map.`)}}static normalizeDefinition(e){let r={};for(let i in e.types)r[i]={...e.types[i]};for(let i in r){let a=r[i].schema;a!==void 0&&(r[i].schema=Fl(a))}let n;if(e.uses!==void 0){n={};for(let i in e.uses)try{n[i]=$o(e.uses[i])}catch{n[i]=e.uses[i]}}return{...e,protocol:$o(e.protocol),types:r,...n!==void 0&&{uses:n}}}}});var jU=F(()=>{"use strict";y();fs();or();ps();hs();B1();O1();mt();Yt();Sf()});var bd,j1=F(()=>{"use strict";y();Da();or();hs();O1();yi();Qi();mt();Yt();Bs();bd=class t extends gn{static async parse(e){return e.authorization!==void 0&&await Se.validateSignatureStructure(e.authorization.signature,e.descriptor),e.descriptor.filter!==void 0&&qn(e.descriptor.filter.protocol),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Protocols,method:ze.Query,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),filter:e.filter?t.normalizeFilter(e.filter):void 0,permissionGrantId:e.permissionGrantId};_r(r);let n;e.signer!==void 0&&(n=await Se.createAuthorization({descriptor:r,signer:e.signer,permissionGrantId:e.permissionGrantId}));let i={descriptor:r,authorization:n};return Se.validateJsonSchema(i),new t(i)}static normalizeFilter(e){return{...e,protocol:$o(e.protocol)}}async authorize(e,r){if(this.author!==e)if(this.author!==void 0&&this.signaturePayload.permissionGrantId){let n=await zt.fetchGrant(e,r,this.signaturePayload.permissionGrantId);await _f.authorizeQuery({expectedGrantor:e,expectedGrantee:this.author,incomingMessage:this.message,permissionGrant:n,messageStore:r})}else throw new le(ue.ProtocolsQueryUnauthorized,"The ProtocolsQuery failed authorization")}}});var MU=F(()=>{"use strict";y();fs();mt();ps();j1();yi();Yt()});var NU=F(()=>{"use strict";y();_a();Po();mt();Yt();Sf();Mm()});var UU=F(()=>{"use strict";y();Po();mt();Yt()});var KU=F(()=>{"use strict";y();Mm();_a();Bn();mt();Yt();Sf()});var kf=F(()=>{"use strict";y();Sf();nc();mt();Yt();NU();UU();KU()});var qU=F(()=>{"use strict";y();fs();or();ps();kf();Bn();Vb();Yt()});var Ou,ww=F(()=>{"use strict";y();Da();or();va();Bn();oc();yi();Qi();Yt();Ou=class t extends gn{static async parse(e){let r;return e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r=e.recordId,n=Et.getCurrentTimestamp(),i={interface:Ge.Records,method:ze.Delete,messageTimestamp:e.messageTimestamp??n,recordId:r,prune:e.prune??!1},a=await Se.createAuthorization({descriptor:i,signer:e.signer,protocolRole:e.protocolRole,permissionGrantId:e.permissionGrantId,delegatedGrant:e.delegatedGrant}),s={descriptor:i,authorization:a};return Se.validateJsonSchema(s),new t(s)}constructIndexes(e){let n={...this.message.descriptor},{protocol:i,protocolPath:a,recipient:s,schema:o,parentId:d,dateCreated:u}=e.descriptor,c={isLatestBaseState:!0,protocol:i,protocolPath:a,recipient:s,schema:o,parentId:d,dateCreated:u,contextId:e.contextId,author:this.author,...n};return _r(c),c}async authorizeDelegate(e,r){let n=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeDelete({recordsDeleteMessage:this.message,recordsWriteToDelete:e,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:n,messageStore:r})}}});var M1,N1=F(()=>{"use strict";y();(function(t){t.RecordsDelete="RecordsDelete",t.RecordsSquash="RecordsSquash"})(M1||(M1={}))});var LU=F(()=>{"use strict";y();fs();Yt();or();ps();hs();kf();Bn();ww();oc();Po();N1()});var zU=F(()=>{"use strict";y();fs();Ul();or();ps();kf();Bn();Jb();Po();nc();Yt()});var Bu,cD=F(()=>{"use strict";y();Da();Ul();or();va();Bn();oc();yi();Qi();mt();Yt();Bu=class t extends gn{static async parse(e){if(e.descriptor.filter.published===!1&&(e.descriptor.dateSort===Ar.PublishedAscending||e.descriptor.dateSort===Ar.PublishedDescending))throw new le(ue.RecordsReadParseFilterPublishedSortInvalid,`reads must not filter for \`published:false\` and sort by ${e.descriptor.dateSort}`);let r;return e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let{filter:r,signer:n,permissionGrantId:i,protocolRole:a,dateSort:s}=e,o=Et.getCurrentTimestamp();if(e.filter.published===!1&&(s===Ar.PublishedAscending||s===Ar.PublishedDescending))throw new le(ue.RecordsReadCreateFilterPublishedSortInvalid,`reads must not filter for \`published:false\` and sort by ${s}`);let d={interface:Ge.Records,method:ze.Read,filter:qt.normalizeFilter(r),messageTimestamp:e.messageTimestamp??o,permissionGrantId:i,dateSort:s};_r(d);let u;n!==void 0&&(u=await Se.createAuthorization({descriptor:d,signer:n,permissionGrantId:i,protocolRole:a,delegatedGrant:e.delegatedGrant}));let c={descriptor:d,authorization:u};return Se.validateJsonSchema(c),new t(c)}async authorizeDelegate(e,r){let n=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeRead({recordsReadMessage:this.message,recordsWriteMessageToBeRead:e,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:n,messageStore:r})}}});var FU=F(()=>{"use strict";y();fs();eu();un();or();ps();hs();kf();Bn();oc();cD();Po();mt();Yt()});var xd,U1=F(()=>{"use strict";y();Da();or();va();Bn();oc();yi();Qi();mt();Yt();Bs();xd=class t extends gn{static async parse(e){let r;if(e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),r?.protocolRole!==void 0&&e.descriptor.filter.protocolPath===void 0)throw new le(ue.RecordsSubscribeFilterMissingRequiredProperties,"Role-authorized subscriptions must include `protocolPath` in the filter");return e.descriptor.filter.protocol!==void 0&&qn(e.descriptor.filter.protocol),e.descriptor.filter.schema!==void 0&&ic(e.descriptor.filter.schema),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Records,method:ze.Subscribe,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),filter:qt.normalizeFilter(e.filter),dateSort:e.dateSort,pagination:e.pagination,cursor:e.cursor};_r(r);let n=e.signer,i;n&&(i=await Se.createAuthorization({descriptor:r,signer:n,protocolRole:e.protocolRole,delegatedGrant:e.delegatedGrant}));let a={descriptor:r,authorization:i};return Se.validateJsonSchema(a),new t(a)}async authorizeDelegate(e){let r=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeQueryOrSubscribe({incomingMessage:this.message,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:r,messageStore:e})}}});var GU=F(()=>{"use strict";y();fs();Ul();or();ps();kf();Bn();U1();Po();nc();mt();Yt()});var dD=F(()=>{"use strict";y();jg();_a();or();Bn();ww();Po();Yt()});var WU=F(()=>{"use strict";y();fs();ed();eu();jg();un();_a();or();ps();hs();kf();Bn();oc();Po();N1();nc();dD();mt();Yt()});function zoe(t,e){if(t.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 i=0;i<t.length;i++){var a=t.charAt(i),s=a.charCodeAt(0);if(r[s]!==255)throw new TypeError(a+" is ambiguous");r[s]=i}var o=t.length,d=t.charAt(0),u=Math.log(o)/Math.log(256),c=Math.log(256)/Math.log(o);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var m=0,g=0,_=0,v=p.length;_!==v&&p[_]===0;)_++,m++;for(var E=(v-_)*c+1>>>0,T=new Uint8Array(E);_!==v;){for(var D=p[_],R=0,N=E-1;(D!==0||R<g)&&N!==-1;N--,R++)D+=256*T[N]>>>0,T[N]=D%o>>>0,D=D/o>>>0;if(D!==0)throw new Error("Non-zero carry");g=R,_++}for(var B=E-g;B!==E&&T[B]===0;)B++;for(var G=d.repeat(m);B<E;++B)G+=t.charAt(T[B]);return G}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var m=0;if(p[m]!==" "){for(var g=0,_=0;p[m]===d;)g++,m++;for(var v=(p.length-m)*u+1>>>0,E=new Uint8Array(v);p[m];){var T=r[p.charCodeAt(m)];if(T===255)return;for(var D=0,R=v-1;(T!==0||D<_)&&R!==-1;R--,D++)T+=o*E[R]>>>0,E[R]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");_=D,m++}if(p[m]!==" "){for(var N=v-_;N!==v&&E[N]===0;)N++;for(var B=new Uint8Array(g+(v-N)),G=g;N!==v;)B[G++]=E[N++];return B}}}function h(p){var m=f(p);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:f,decode:h}}function ese(t){return t.byteOffset!==0||t.byteLength!==t.buffer.byteLength}function tse(t){return typeof t!="object"||t===null?!1:typeof t[Symbol.asyncIterator]=="function"}function bD(t){let e=Object.prototype.toString.call(t).match(/\s([a-zA-Z0-9]+)/),[r,n]=e;return n}function Tq(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ase;)e[r++]=t&255|ZU,t/=128;for(;t&sse;)e[r++]=t&255|ZU,t>>>=7;return e[r]=t|0,Tq.bytes=r-n+1,e}function xD(t,n){var r=0,n=n||0,i=0,a=n,s,o=t.length;do{if(a>=o)throw xD.bytes=0,new RangeError("Could not decode varint");s=t[a++],r+=i<28?(s&YU)<<i:(s&YU)*Math.pow(2,i),i+=7}while(s>=dse);return xD.bytes=a-n,r}function kq(t){Object.keys(t).forEach(e=>{t[e]===void 0?delete t[e]:typeof t[e]=="object"&&kq(t[e])})}function Dc(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Uf(t){if(!Dc(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=Cse[t[r]];return e}function Iq(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function HD(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function tK(t){if(t>=_d._0&&t<=_d._9)return t-_d._0;if(t>=_d._A&&t<=_d._F)return t-(_d._A-10);if(t>=_d._a&&t<=_d._f)return t-(_d._a-10)}function om(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,a=0;i<r;i++,a+=2){let s=tK(t.charCodeAt(a)),o=tK(t.charCodeAt(a+1));if(s===void 0||o===void 0){let d=t[a]+t[a+1];throw new Error('hex string expected, got non-hex character "'+d+'" at index '+a)}n[i]=s*16+o}return n}function jf(t){return HD(Uf(t))}function Yu(t){if(!Dc(t))throw new Error("Uint8Array expected");return HD(Uf(Uint8Array.from(t).reverse()))}function Ic(t,e){return om(t.toString(16).padStart(e*2,"0"))}function sm(t,e){return Ic(t,e).reverse()}function $se(t){return om(Iq(t))}function In(t,e,r){let n;if(typeof e=="string")try{n=om(e)}catch(a){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${a}`)}else if(Dc(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function Kf(...t){let e=0;for(let i=0;i<t.length;i++){let a=t[i];if(!Dc(a))throw new Error("Uint8Array expected");e+=a.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let a=t[i];r.set(a,n),n+=a.length}return r}function Ose(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Bse(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function jse(t){let e;for(e=0;t>Dq;t>>=Dx,e+=1);return e}function Mse(t,e){return t>>BigInt(e)&Dx}function Rq(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=uD(t),i=uD(t),a=0,s=()=>{n.fill(1),i.fill(0),a=0},o=(...c)=>r(i,n,...c),d=(c=uD())=>{i=o(rK([0]),c),n=o(),c.length!==0&&(i=o(rK([1]),c),n=o())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let c=0,l=[];for(;c<e;){n=o();let f=n.slice();l.push(f),c+=n.length}return Kf(...l)};return(c,l)=>{s(),d(c);let f;for(;!(f=l(u()));)d();return s(),f}}function zf(t,e,r={}){let n=(i,a,s)=>{let o=Use[a];if(typeof o!="function")throw new Error(`Invalid validator "${a}", expected function`);let d=t[i];if(!(s&&d===void 0)&&!o(d,t))throw new Error(`Invalid param ${String(i)}=${d} (${typeof d}), expected ${a}`)};for(let[i,a]of Object.entries(e))n(i,a,!1);for(let[i,a]of Object.entries(r))n(i,a,!0);return t}function nK(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Kse(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Cq(t,...e){if(!Kse(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function qse(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");nK(t.outputLen),nK(t.blockLen)}function yx(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Lse(t,e){Cq(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}function $q(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Oq(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function JD(t){if(typeof t=="string"&&(t=Oq(t)),!$q(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Bq(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!$q(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let a=t[n];r.set(a,i),i+=a.length}return r}function Mq(t){let e=n=>t().update(JD(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function ZD(t=32){if(lD&&typeof lD.getRandomValues=="function")return lD.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Fse(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),a=BigInt(4294967295),s=Number(r>>i&a),o=Number(r&a),d=n?4:0,u=n?0:4;t.setUint32(e+d,s,n),t.setUint32(e+u,o,n)}function Nr(t,e){let r=t%e;return r>=Hn?r:e+r}function Kq(t,e,r){if(r<=Hn||e<Hn)throw new Error("Expected power/modulo > 0");if(r===Xr)return Hn;let n=Xr;for(;e>Hn;)e&Xr&&(n=n*t%r),t=t*t%r,e>>=Xr;return n}function sn(t,e,r){let n=t;for(;e-- >Hn;)n*=n,n%=r;return n}function ED(t,e){if(t===Hn||e<=Hn)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Nr(t,e),n=e,i=Hn,a=Xr,s=Xr,o=Hn;for(;r!==Hn;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}if(n!==Xr)throw new Error("invert: does not exist");return Nr(i,e)}function Yse(t){let e=(t-Xr)/Rf,r,n,i;for(r=t-Xr,n=0;r%Rf===Hn;r/=Rf,n++);for(i=Rf;i<t&&Kq(i,e,t)!==t-Xr;i++);if(n===1){let s=(t+Xr)/_D;return function(o,d){let u=o.pow(d,s);if(!o.eql(o.sqr(u),d))throw new Error("Cannot find square root");return u}}let a=(r+Xr)/Rf;return function(s,o){if(s.pow(o,e)===s.neg(s.ONE))throw new Error("Cannot find square root");let d=n,u=s.pow(s.mul(s.ONE,i),r),c=s.pow(o,a),l=s.pow(o,r);for(;!s.eql(l,s.ONE);){if(s.eql(l,s.ZERO))return s.ZERO;let f=1;for(let p=s.sqr(l);f<d&&!s.eql(p,s.ONE);f++)p=s.sqr(p);let h=s.pow(u,Xr<<BigInt(d-f-1));u=s.sqr(h),c=s.mul(c,h),l=s.mul(l,u),d=f}return c}}function Qse(t){if(t%_D===Jse){let e=(t+Xr)/_D;return function(r,n){let i=r.pow(n,e);if(!r.eql(r.sqr(i),n))throw new Error("Cannot find square root");return i}}if(t%oK===iK){let e=(t-iK)/oK;return function(r,n){let i=r.mul(n,Rf),a=r.pow(i,e),s=r.mul(n,a),o=r.mul(r.mul(s,Rf),a),d=r.mul(s,r.sub(o,r.ONE));if(!r.eql(r.sqr(d),n))throw new Error("Cannot find square root");return d}}return t%Zse,Yse(t)}function tae(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=eae.reduce((n,i)=>(n[i]="function",n),e);return zf(t,r)}function rae(t,e,r){if(r<Hn)throw new Error("Expected power > 0");if(r===Hn)return t.ONE;if(r===Xr)return e;let n=t.ONE,i=e;for(;r>Hn;)r&Xr&&(n=t.mul(n,i)),i=t.sqr(i),r>>=Xr;return n}function nae(t,e){let r=new Array(e.length),n=e.reduce((a,s,o)=>t.is0(s)?a:(r[o]=a,t.mul(a,s)),t.ONE),i=t.inv(n);return e.reduceRight((a,s,o)=>t.is0(s)?a:(r[o]=t.mul(a,r[o]),t.mul(a,s)),i),r}function qq(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function YD(t,e,r=!1,n={}){if(t<=Hn)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:a}=qq(t,e);if(a>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Qse(t),o=Object.freeze({ORDER:t,BITS:i,BYTES:a,MASK:VD(i),ZERO:Hn,ONE:Xr,create:d=>Nr(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof d}`);return Hn<=d&&d<t},is0:d=>d===Hn,isOdd:d=>(d&Xr)===Xr,neg:d=>Nr(-d,t),eql:(d,u)=>d===u,sqr:d=>Nr(d*d,t),add:(d,u)=>Nr(d+u,t),sub:(d,u)=>Nr(d-u,t),mul:(d,u)=>Nr(d*u,t),pow:(d,u)=>rae(o,d,u),div:(d,u)=>Nr(d*ED(u,t),t),sqrN:d=>d*d,addN:(d,u)=>d+u,subN:(d,u)=>d-u,mulN:(d,u)=>d*u,inv:d=>ED(d,t),sqrt:n.sqrt||(d=>s(o,d)),invertBatch:d=>nae(o,d),cmov:(d,u,c)=>c?u:d,toBytes:d=>r?sm(d,a):Ic(d,a),fromBytes:d=>{if(d.length!==a)throw new Error(`Fp.fromBytes: expected ${a}, got ${d.length}`);return r?Yu(d):jf(d)}});return Object.freeze(o)}function iae(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function Lq(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function zq(t){let e=Lq(t);return e+Math.ceil(e/2)}function oae(t,e,r=!1){let n=t.length,i=Lq(e),a=zq(e);if(n<16||n<a||n>1024)throw new Error(`expected ${a}-1024 bytes of input, got ${n}`);let s=r?jf(t):Yu(t),o=Nr(s,e-Xr)+Xr;return r?sm(o,i):Ic(o,i)}function Fq(t,e){let r=(i,a)=>{let s=a.negate();return i?s:a},n=i=>{let a=Math.ceil(e/i)+1,s=2**(i-1);return{windows:a,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,a){let s=t.ZERO,o=i;for(;a>sae;)a&pD&&(s=s.add(o)),o=o.double(),a>>=pD;return s},precomputeWindow(i,a){let{windows:s,windowSize:o}=n(a),d=[],u=i,c=u;for(let l=0;l<s;l++){c=u,d.push(c);for(let f=1;f<o;f++)c=c.add(u),d.push(c);u=c.double()}return d},wNAF(i,a,s){let{windows:o,windowSize:d}=n(i),u=t.ZERO,c=t.BASE,l=BigInt(2**i-1),f=2**i,h=BigInt(i);for(let p=0;p<o;p++){let m=p*d,g=Number(s&l);s>>=h,g>d&&(g-=f,s+=pD);let _=m,v=m+Math.abs(g)-1,E=p%2!==0,T=g<0;g===0?c=c.add(r(E,a[_])):u=u.add(r(T,a[v]))}return{p:u,f:c}},wNAFCached(i,a,s,o){let d=i._WINDOW_SIZE||1,u=a.get(i);return u||(u=this.precomputeWindow(i,d),d!==1&&a.set(i,o(u))),this.wNAF(d,u,s)}}}function QD(t){return tae(t.Fp),zf(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...qq(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function aae(t){let e=QD(t);zf(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}function uae(t){let e=aae(t),{Fp:r}=e,n=e.toBytes||((p,m,g)=>{let _=m.toAffine();return Kf(Uint8Array.from([4]),r.toBytes(_.x),r.toBytes(_.y))}),i=e.fromBytes||(p=>{let m=p.subarray(1),g=r.fromBytes(m.subarray(0,r.BYTES)),_=r.fromBytes(m.subarray(r.BYTES,2*r.BYTES));return{x:g,y:_}});function a(p){let{a:m,b:g}=e,_=r.sqr(p),v=r.mul(_,p);return r.add(r.add(v,r.mul(p,m)),g)}if(!r.eql(r.sqr(e.Gy),a(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Dd<p&&p<e.n}function o(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function d(p){let{allowedPrivateKeyLengths:m,nByteLength:g,wrapPrivateKey:_,n:v}=e;if(m&&typeof p!="bigint"){if(Dc(p)&&(p=Uf(p)),typeof p!="string"||!m.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let E;try{E=typeof p=="bigint"?p:jf(In("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return _&&(E=Nr(E,v)),o(E),E}let u=new Map;function c(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(m,g,_){if(this.px=m,this.py=g,this.pz=_,m==null||!r.isValid(m))throw new Error("x required");if(g==null||!r.isValid(g))throw new Error("y required");if(_==null||!r.isValid(_))throw new Error("z required")}static fromAffine(m){let{x:g,y:_}=m||{};if(!m||!r.isValid(g)||!r.isValid(_))throw new Error("invalid affine point");if(m instanceof l)throw new Error("projective point not allowed");let v=E=>r.eql(E,r.ZERO);return v(g)&&v(_)?l.ZERO:new l(g,_,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let g=r.invertBatch(m.map(_=>_.pz));return m.map((_,v)=>_.toAffine(g[v])).map(l.fromAffine)}static fromHex(m){let g=l.fromAffine(i(In("pointHex",m)));return g.assertValidity(),g}static fromPrivateKey(m){return l.BASE.multiply(d(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y:g}=this.toAffine();if(!r.isValid(m)||!r.isValid(g))throw new Error("bad point: x or y not FE");let _=r.sqr(g),v=a(m);if(!r.eql(_,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(r.isOdd)return!r.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){c(m);let{px:g,py:_,pz:v}=this,{px:E,py:T,pz:D}=m,R=r.eql(r.mul(g,D),r.mul(E,v)),N=r.eql(r.mul(_,D),r.mul(T,v));return R&&N}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:m,b:g}=e,_=r.mul(g,sK),{px:v,py:E,pz:T}=this,D=r.ZERO,R=r.ZERO,N=r.ZERO,B=r.mul(v,v),G=r.mul(E,E),z=r.mul(T,T),U=r.mul(v,E);return U=r.add(U,U),N=r.mul(v,T),N=r.add(N,N),D=r.mul(m,N),R=r.mul(_,z),R=r.add(D,R),D=r.sub(G,R),R=r.add(G,R),R=r.mul(D,R),D=r.mul(U,D),N=r.mul(_,N),z=r.mul(m,z),U=r.sub(B,z),U=r.mul(m,U),U=r.add(U,N),N=r.add(B,B),B=r.add(N,B),B=r.add(B,z),B=r.mul(B,U),R=r.add(R,B),z=r.mul(E,T),z=r.add(z,z),B=r.mul(z,U),D=r.sub(D,B),N=r.mul(z,G),N=r.add(N,N),N=r.add(N,N),new l(D,R,N)}add(m){c(m);let{px:g,py:_,pz:v}=this,{px:E,py:T,pz:D}=m,R=r.ZERO,N=r.ZERO,B=r.ZERO,G=e.a,z=r.mul(e.b,sK),U=r.mul(g,E),H=r.mul(_,T),ee=r.mul(v,D),I=r.add(g,_),O=r.add(E,T);I=r.mul(I,O),O=r.add(U,H),I=r.sub(I,O),O=r.add(g,v);let b=r.add(E,D);return O=r.mul(O,b),b=r.add(U,ee),O=r.sub(O,b),b=r.add(_,v),R=r.add(T,D),b=r.mul(b,R),R=r.add(H,ee),b=r.sub(b,R),B=r.mul(G,O),R=r.mul(z,ee),B=r.add(R,B),R=r.sub(H,B),B=r.add(H,B),N=r.mul(R,B),H=r.add(U,U),H=r.add(H,U),ee=r.mul(G,ee),O=r.mul(z,O),H=r.add(H,ee),ee=r.sub(U,ee),ee=r.mul(G,ee),O=r.add(O,ee),U=r.mul(H,O),N=r.add(N,U),U=r.mul(b,O),R=r.mul(I,R),R=r.sub(R,U),U=r.mul(I,H),B=r.mul(b,B),B=r.add(B,U),new l(R,N,B)}subtract(m){return this.add(m.negate())}is0(){return this.equals(l.ZERO)}wNAF(m){return h.wNAFCached(this,u,m,g=>{let _=r.invertBatch(g.map(v=>v.pz));return g.map((v,E)=>v.toAffine(_[E])).map(l.fromAffine)})}multiplyUnsafe(m){let g=l.ZERO;if(m===Dd)return g;if(o(m),m===Vs)return this;let{endo:_}=e;if(!_)return h.unsafeLadder(this,m);let{k1neg:v,k1:E,k2neg:T,k2:D}=_.splitScalar(m),R=g,N=g,B=this;for(;E>Dd||D>Dd;)E&Vs&&(R=R.add(B)),D&Vs&&(N=N.add(B)),B=B.double(),E>>=Vs,D>>=Vs;return v&&(R=R.negate()),T&&(N=N.negate()),N=new l(r.mul(N.px,_.beta),N.py,N.pz),R.add(N)}multiply(m){o(m);let g=m,_,v,{endo:E}=e;if(E){let{k1neg:T,k1:D,k2neg:R,k2:N}=E.splitScalar(g),{p:B,f:G}=this.wNAF(D),{p:z,f:U}=this.wNAF(N);B=h.constTimeNegate(T,B),z=h.constTimeNegate(R,z),z=new l(r.mul(z.px,E.beta),z.py,z.pz),_=B.add(z),v=G.add(U)}else{let{p:T,f:D}=this.wNAF(g);_=T,v=D}return l.normalizeZ([_,v])[0]}multiplyAndAddUnsafe(m,g,_){let v=l.BASE,E=(D,R)=>R===Dd||R===Vs||!D.equals(v)?D.multiplyUnsafe(R):D.multiply(R),T=E(this,g).add(E(m,_));return T.is0()?void 0:T}toAffine(m){let{px:g,py:_,pz:v}=this,E=this.is0();m==null&&(m=E?r.ONE:r.inv(v));let T=r.mul(g,m),D=r.mul(_,m),R=r.mul(v,m);if(E)return{x:r.ZERO,y:r.ZERO};if(!r.eql(R,r.ONE))throw new Error("invZ was invalid");return{x:T,y:D}}isTorsionFree(){let{h:m,isTorsionFree:g}=e;if(m===Vs)return!0;if(g)return g(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:g}=e;return m===Vs?this:g?g(l,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(l,this,m)}toHex(m=!0){return Uf(this.toRawBytes(m))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let f=e.nBitLength,h=Fq(l,e.endo?Math.ceil(f/2):f);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:d,weierstrassEquation:a,isWithinCurveOrder:s}}function lae(t){let e=QD(t);return zf(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function fae(t){let e=lae(t),{Fp:r,n}=e,i=r.BYTES+1,a=2*r.BYTES+1;function s(O){return Dd<O&&O<r.ORDER}function o(O){return Nr(O,n)}function d(O){return ED(O,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:l,isWithinCurveOrder:f}=uae({...e,toBytes(O,b,P){let x=b.toAffine(),S=r.toBytes(x.x),A=Kf;return P?A(Uint8Array.from([b.hasEvenY()?2:3]),S):A(Uint8Array.from([4]),S,r.toBytes(x.y))},fromBytes(O){let b=O.length,P=O[0],x=O.subarray(1);if(b===i&&(P===2||P===3)){let S=jf(x);if(!s(S))throw new Error("Point is not on curve");let A=l(S),M=r.sqrt(A),L=(M&Vs)===Vs;return(P&1)===1!==L&&(M=r.neg(M)),{x:S,y:M}}else if(b===a&&P===4){let S=r.fromBytes(x.subarray(0,r.BYTES)),A=r.fromBytes(x.subarray(r.BYTES,2*r.BYTES));return{x:S,y:A}}else throw new Error(`Point of length ${b} was invalid. Expected ${i} compressed bytes or ${a} uncompressed bytes`)}}),h=O=>Uf(Ic(O,e.nByteLength));function p(O){let b=n>>Vs;return O>b}function m(O){return p(O)?o(-O):O}let g=(O,b,P)=>jf(O.slice(b,P));class _{constructor(b,P,x){this.r=b,this.s=P,this.recovery=x,this.assertValidity()}static fromCompact(b){let P=e.nByteLength;return b=In("compactSignature",b,P*2),new _(g(b,0,P),g(b,P,2*P))}static fromDER(b){let{r:P,s:x}=Of.toSig(In("DER",b));return new _(P,x)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new _(this.r,this.s,b)}recoverPublicKey(b){let{r:P,s:x,recovery:S}=this,A=N(In("msgHash",b));if(S==null||![0,1,2,3].includes(S))throw new Error("recovery id invalid");let M=S===2||S===3?P+e.n:P;if(M>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=S&1?"03":"02",W=u.fromHex(L+h(M)),V=d(M),J=o(-A*V),Q=o(x*V),q=u.BASE.multiplyAndAddUnsafe(W,J,Q);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return om(this.toDERHex())}toDERHex(){return Of.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return om(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let v={isValidPrivateKey(O){try{return c(O),!0}catch{return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{let O=zq(e.n);return oae(e.randomBytes(O),e.n)},precompute(O=8,b=u.BASE){return b._setWindowSize(O),b.multiply(BigInt(3)),b}};function E(O,b=!0){return u.fromPrivateKey(O).toRawBytes(b)}function T(O){let b=Dc(O),P=typeof O=="string",x=(b||P)&&O.length;return b?x===i||x===a:P?x===2*i||x===2*a:O instanceof u}function D(O,b,P=!0){if(T(O))throw new Error("first arg must be private key");if(!T(b))throw new Error("second arg must be public key");return u.fromHex(b).multiply(c(O)).toRawBytes(P)}let R=e.bits2int||function(O){let b=jf(O),P=O.length*8-e.nBitLength;return P>0?b>>BigInt(P):b},N=e.bits2int_modN||function(O){return o(R(O))},B=VD(e.nBitLength);function G(O){if(typeof O!="bigint")throw new Error("bigint expected");if(!(Dd<=O&&O<B))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ic(O,e.nByteLength)}function z(O,b,P=U){if(["recovered","canonical"].some(ne=>ne in P))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:S}=e,{lowS:A,prehash:M,extraEntropy:L}=P;A==null&&(A=!0),O=In("msgHash",O),M&&(O=In("prehashed msgHash",x(O)));let W=N(O),V=c(b),J=[G(V),G(W)];if(L!=null){let ne=L===!0?S(r.BYTES):L;J.push(In("extraEntropy",ne))}let Q=Kf(...J),q=W;function X(ne){let re=R(ne);if(!f(re))return;let Y=d(re),ce=u.BASE.multiply(re).toAffine(),de=o(ce.x);if(de===Dd)return;let pe=o(Y*o(q+de*V));if(pe===Dd)return;let we=(ce.x===de?0:2)|Number(ce.y&Vs),ae=pe;return A&&p(pe)&&(ae=m(pe),we^=1),new _(de,ae,we)}return{seed:Q,k2sig:X}}let U={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function ee(O,b,P=U){let{seed:x,k2sig:S}=z(O,b,P),A=e;return Rq(A.hash.outputLen,A.nByteLength,A.hmac)(x,S)}u.BASE._setWindowSize(8);function I(O,b,P,x=H){let S=O;if(b=In("msgHash",b),P=In("publicKey",P),"strict"in x)throw new Error("options.strict was renamed to lowS");let{lowS:A,prehash:M}=x,L,W;try{if(typeof S=="string"||Dc(S))try{L=_.fromDER(S)}catch(Y){if(!(Y instanceof Of.Err))throw Y;L=_.fromCompact(S)}else if(typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint"){let{r:Y,s:ce}=S;L=new _(Y,ce)}else throw new Error("PARSE");W=u.fromHex(P)}catch(Y){if(Y.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&L.hasHighS())return!1;M&&(b=e.hash(b));let{r:V,s:J}=L,Q=N(b),q=d(J),X=o(Q*q),ne=o(V*q),re=u.BASE.multiplyAndAddUnsafe(W,X,ne)?.toAffine();return re?o(re.x)===V:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:D,sign:ee,verify:I,ProjectivePoint:u,Signature:_,utils:v}}function pae(t){return{hash:t,hmac:(e,...r)=>Wq(t,e,Bq(...r)),randomBytes:ZD}}function Hq(t,e){let r=n=>fae({...t,...pae(n)});return Object.freeze({...r(e),create:r})}function mae(t){let e=Vq,r=BigInt(3),n=BigInt(6),i=BigInt(11),a=BigInt(22),s=BigInt(23),o=BigInt(44),d=BigInt(88),u=t*t*t%e,c=u*u*t%e,l=sn(c,r,e)*c%e,f=sn(l,r,e)*c%e,h=sn(f,SD,e)*u%e,p=sn(h,i,e)*h%e,m=sn(p,a,e)*p%e,g=sn(m,o,e)*m%e,_=sn(g,d,e)*g%e,v=sn(_,o,e)*m%e,E=sn(v,r,e)*c%e,T=sn(E,s,e)*p%e,D=sn(T,n,e)*u%e,R=sn(D,SD,e);if(!TD.eql(TD.sqr(R),t))throw new Error("Cannot find square root");return R}function yae(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Jq(t,...e){if(!yae(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function dK(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function gae(t,e){Jq(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}function wae(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Zq(t){return typeof t=="string"&&(t=wae(t)),Jq(t),t}function bae(t){let e=n=>t().update(Zq(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function xae(t=32){if(J1&&typeof J1.getRandomValues=="function")return J1.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Pae(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),a=BigInt(4294967295),s=Number(r>>i&a),o=Number(r&a),d=n?4:0,u=n?0:4;t.setUint32(e+d,s,n),t.setUint32(e+u,o,n)}function Aae(t){let e=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),a={};for(let s of i)a[s]=e(n[s]);return a}return n},r=e(t);return JSON.stringify(r)}function lr(t){return Iae(this,arguments,void 0,function*({jwk:e}){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);kq(n);let i=Aae(n),a=tt.string(i).toUint8Array(),s=yield Yq.digest({data:a});return tt.uint8Array(s).toBase64Url()})}function Mf(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="EC"||typeof t.d!="string"||typeof t.x!="string")}function XD(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t)||"d"in t||t.kty!=="EC"||typeof t.x!="string")}function Cd(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="OKP"||typeof t.d!="string"||typeof t.x!="string")}function eI(t){return!(!t||typeof t!="object"||"d"in t||!("kty"in t&&"crv"in t&&"x"in t)||t.kty!=="OKP"||typeof t.x!="string")}function Rae(t){if(!t||typeof t!="object")return!1;switch(t.kty){case"EC":case"OKP":case"RSA":return"d"in t;case"oct":return"k"in t;default:return!1}}function Xq(t,e=!1){return e?{h:Number(t&q1),l:Number(t>>kD&q1)}:{h:Number(t>>kD&q1)|0,l:Number(t&q1)|0}}function Mae(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:a,l:s}=Xq(t[i],e);[r[i],n[i]]=[a,s]}return[r,n]}function Yae(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}function uce(t){let e=QD(t);return zf(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function tI(t){let e=uce(t),{Fp:r,n,prehash:i,hash:a,randomBytes:s,nByteLength:o,h:d}=e,u=L1<<BigInt(o*8)-ms,c=r.create,l=e.uvRatio||((P,x)=>{try{return{isValid:!0,value:r.sqrt(P*r.inv(x))}}catch{return{isValid:!1,value:Ma}}}),f=e.adjustScalarBytes||(P=>P),h=e.domain||((P,x,S)=>{if(x.length||S)throw new Error("Contexts/pre-hash are not supported");return P}),p=P=>typeof P=="bigint"&&Ma<P,m=(P,x)=>p(P)&&p(x)&&P<x,g=P=>P===Ma||m(P,u);function _(P,x){if(m(P,x))return P;throw new Error(`Expected valid scalar < ${x}, got ${typeof P} ${P}`)}function v(P){return P===Ma?P:_(P,n)}let E=new Map;function T(P){if(!(P instanceof D))throw new Error("ExtendedPoint expected")}class D{constructor(x,S,A,M){if(this.ex=x,this.ey=S,this.ez=A,this.et=M,!g(x))throw new Error("x required");if(!g(S))throw new Error("y required");if(!g(A))throw new Error("z required");if(!g(M))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(x){if(x instanceof D)throw new Error("extended point not allowed");let{x:S,y:A}=x||{};if(!g(S)||!g(A))throw new Error("invalid affine point");return new D(S,A,ms,c(S*A))}static normalizeZ(x){let S=r.invertBatch(x.map(A=>A.ez));return x.map((A,M)=>A.toAffine(S[M])).map(D.fromAffine)}_setWindowSize(x){this._WINDOW_SIZE=x,E.delete(this)}assertValidity(){let{a:x,d:S}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:A,ey:M,ez:L,et:W}=this,V=c(A*A),J=c(M*M),Q=c(L*L),q=c(Q*Q),X=c(V*x),ne=c(Q*c(X+J)),re=c(q+c(S*c(V*J)));if(ne!==re)throw new Error("bad point: equation left != right (1)");let Y=c(A*M),ce=c(L*W);if(Y!==ce)throw new Error("bad point: equation left != right (2)")}equals(x){T(x);let{ex:S,ey:A,ez:M}=this,{ex:L,ey:W,ez:V}=x,J=c(S*V),Q=c(L*M),q=c(A*V),X=c(W*M);return J===Q&&q===X}is0(){return this.equals(D.ZERO)}negate(){return new D(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:x}=e,{ex:S,ey:A,ez:M}=this,L=c(S*S),W=c(A*A),V=c(L1*c(M*M)),J=c(x*L),Q=S+A,q=c(c(Q*Q)-L-W),X=J+W,ne=X-V,re=J-W,Y=c(q*ne),ce=c(X*re),de=c(q*re),pe=c(ne*X);return new D(Y,ce,pe,de)}add(x){T(x);let{a:S,d:A}=e,{ex:M,ey:L,ez:W,et:V}=this,{ex:J,ey:Q,ez:q,et:X}=x;if(S===BigInt(-1)){let Pt=c((L-M)*(Q+J)),Pe=c((L+M)*(Q-J)),nt=c(Pe-Pt);if(nt===Ma)return this.double();let wt=c(W*L1*X),xt=c(V*L1*q),Ot=xt+wt,k=Pe+Pt,j=xt-wt,K=c(Ot*nt),te=c(k*j),se=c(Ot*j),he=c(nt*k);return new D(K,te,he,se)}let ne=c(M*J),re=c(L*Q),Y=c(V*A*X),ce=c(W*q),de=c((M+L)*(J+Q)-ne-re),pe=ce-Y,we=ce+Y,ae=c(re-S*ne),ge=c(de*pe),Be=c(we*ae),qe=c(de*ae),We=c(pe*we);return new D(ge,Be,We,qe)}subtract(x){return this.add(x.negate())}wNAF(x){return B.wNAFCached(this,E,x,D.normalizeZ)}multiply(x){let{p:S,f:A}=this.wNAF(_(x,n));return D.normalizeZ([S,A])[0]}multiplyUnsafe(x){let S=v(x);return S===Ma?N:this.equals(N)||S===ms?this:this.equals(R)?this.wNAF(S).p:B.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(d).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(x){let{ex:S,ey:A,ez:M}=this,L=this.is0();x==null&&(x=L?cce:r.inv(M));let W=c(S*x),V=c(A*x),J=c(M*x);if(L)return{x:Ma,y:ms};if(J!==ms)throw new Error("invZ was invalid");return{x:W,y:V}}clearCofactor(){let{h:x}=e;return x===ms?this:this.multiplyUnsafe(x)}static fromHex(x,S=!1){let{d:A,a:M}=e,L=r.BYTES;x=In("pointHex",x,L);let W=x.slice(),V=x[L-1];W[L-1]=V&-129;let J=Yu(W);J===Ma||(S?_(J,u):_(J,r.ORDER));let Q=c(J*J),q=c(Q-ms),X=c(A*Q-M),{isValid:ne,value:re}=l(q,X);if(!ne)throw new Error("Point.fromHex: invalid y coordinate");let Y=(re&ms)===ms,ce=(V&128)!==0;if(!S&&re===Ma&&ce)throw new Error("Point.fromHex: x=0 and x_0=1");return ce!==Y&&(re=c(-re)),D.fromAffine({x:re,y:J})}static fromPrivateKey(x){return U(x).point}toRawBytes(){let{x,y:S}=this.toAffine(),A=sm(S,r.BYTES);return A[A.length-1]|=x&ms?128:0,A}toHex(){return Uf(this.toRawBytes())}}D.BASE=new D(e.Gx,e.Gy,ms,c(e.Gx*e.Gy)),D.ZERO=new D(Ma,ms,ms,Ma);let{BASE:R,ZERO:N}=D,B=Fq(D,o*8);function G(P){return Nr(P,n)}function z(P){return G(Yu(P))}function U(P){let x=o;P=In("private key",P,x);let S=In("hashed private key",a(P),2*x),A=f(S.slice(0,x)),M=S.slice(x,2*x),L=z(A),W=R.multiply(L),V=W.toRawBytes();return{head:A,prefix:M,scalar:L,point:W,pointBytes:V}}function H(P){return U(P).pointBytes}function ee(P=new Uint8Array,...x){let S=Kf(...x);return z(a(h(S,In("context",P),!!i)))}function I(P,x,S={}){P=In("message",P),i&&(P=i(P));let{prefix:A,scalar:M,pointBytes:L}=U(x),W=ee(S.context,A,P),V=R.multiply(W).toRawBytes(),J=ee(S.context,V,L,P),Q=G(W+J*M);v(Q);let q=Kf(V,sm(Q,r.BYTES));return In("result",q,o*2)}let O=dce;function b(P,x,S,A=O){let{context:M,zip215:L}=A,W=r.BYTES;P=In("signature",P,2*W),x=In("message",x),i&&(x=i(x));let V=Yu(P.slice(W,2*W)),J,Q,q;try{J=D.fromHex(S,L),Q=D.fromHex(P.slice(0,W),L),q=R.multiplyUnsafe(V)}catch{return!1}if(!L&&J.isSmallOrder())return!1;let X=ee(M,Q.toRawBytes(),J.toRawBytes(),x);return Q.add(J.multiplyUnsafe(X)).subtract(q).clearCofactor().equals(D.ZERO)}return R._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:I,verify:b,ExtendedPoint:D,utils:{getExtendedPublicKey:U,randomPrivateKey:()=>s(r.BYTES),precompute(P=8,x=D.BASE){return x._setWindowSize(P),x.multiply(BigInt(3)),x}}}}function lce(t){return zf(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function fce(t){let e=lce(t),{P:r}=e,n=E=>Nr(E,r),i=e.montgomeryBits,a=Math.ceil(i/8),s=e.nByteLength,o=e.adjustScalarBytes||(E=>E),d=e.powPminus2||(E=>Kq(E,r-BigInt(2),r));function u(E,T,D){let R=n(E*(T-D));return T=n(T-R),D=n(D+R),[T,D]}function c(E){if(typeof E=="bigint"&&xw<=E&&E<r)return E;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function f(E,T){let D=c(E),R=c(T),N=D,B=mD,G=xw,z=D,U=mD,H=xw,ee;for(let O=BigInt(i-1);O>=xw;O--){let b=R>>O&mD;H^=b,ee=u(H,B,z),B=ee[0],z=ee[1],ee=u(H,G,U),G=ee[0],U=ee[1],H=b;let P=B+G,x=n(P*P),S=B-G,A=n(S*S),M=x-A,L=z+U,W=z-U,V=n(W*P),J=n(L*S),Q=V+J,q=V-J;z=n(Q*Q),U=n(N*n(q*q)),B=n(x*A),G=n(M*(x+n(l*M)))}ee=u(H,B,z),B=ee[0],z=ee[1],ee=u(H,G,U),G=ee[0],U=ee[1];let I=d(G);return n(B*I)}function h(E){return sm(n(E),a)}function p(E){let T=In("u coordinate",E,a);return s===32&&(T[31]&=127),Yu(T)}function m(E){let T=In("scalar",E),D=T.length;if(D!==a&&D!==s)throw new Error(`Expected ${a} or ${s} bytes, got ${D}`);return Yu(o(T))}function g(E,T){let D=p(T),R=m(E),N=f(D,R);if(N===xw)throw new Error("Invalid private or public key received");return h(N)}let _=h(e.Gu);function v(E){return g(E,_)}return{scalarMult:g,scalarMultBase:v,getSharedSecret:(E,T)=>g(E,T),getPublicKey:E=>v(E),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:_}}function tL(t){let e=Ww,r=t*t%e*t%e,n=sn(r,AD,e)*r%e,i=sn(n,pce,e)*t%e,a=sn(i,hce,e)*i%e,s=sn(a,pK,e)*a%e,o=sn(s,mce,e)*s%e,d=sn(o,yce,e)*o%e,u=sn(d,hK,e)*d%e,c=sn(u,hK,e)*d%e,l=sn(c,pK,e)*a%e;return{pow_p_5_8:sn(l,AD,e)*t%e,b2:r}}function rL(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function gce(t,e){let r=Ww,n=Nr(e*e*e,r),i=Nr(n*n*e,r),a=tL(t*i).pow_p_5_8,s=Nr(t*n*a,r),o=Nr(e*s*s,r),d=s,u=Nr(s*fK,r),c=o===t,l=o===Nr(-t,r),f=o===Nr(-t*fK,r);return c&&(s=d),(l||f)&&(s=u),Xse(s,r)&&(s=Nr(-s,r)),{isValid:c||l,value:s}}function nL(t,e,r){if(e.length>255)throw new Error("Context is too big");return Bq(Oq("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}function wce(t){let{y:e}=Df.ExtendedPoint.fromHex(t),r=BigInt(1);return Qs.toBytes(Qs.create((r+e)*Qs.inv(r-e)))}function vce(t){let e=Hw.hash(t.subarray(0,32));return Hw.adjustScalarBytes(e).subarray(0,32)}function Dce(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;return e==="string"||e==="number"||e==="bigint"||e==="symbol"?e:e==="function"?"Function":Array.isArray(t)?"Array":t instanceof Uint8Array?"Uint8Array":t.constructor===Object?"Object":Ice(t)||"Object"}function Ice(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ace.includes(e))return e}function gx(t){return Xw&&globalThis.Buffer.isBuffer(t)}function iL(t){return t instanceof Uint8Array?gx(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}function oL(t,e){if(gx(t)&&gx(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function mK(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}function lm(t,e,r){if(t.length-e<r)throw new Error(`${an} not enough data for type`)}function Ff(t,e,r){lm(t,e,1);let n=t[e];if(r.strict===!0&&n<Ni[0])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Gf(t,e,r){lm(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<Ni[1])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Wf(t,e,r){lm(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<Ni[2])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Hf(t,e,r){lm(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],a=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&a<Ni[3])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);if(a<=Number.MAX_SAFE_INTEGER)return Number(a);if(r.allowBigInt===!0)return a;throw new Error(`${an} integers outside of the safe integer range are not supported`)}function Kce(t,e,r,n){return new Qe(be.uint,Ff(t,e+1,n),2)}function qce(t,e,r,n){return new Qe(be.uint,Gf(t,e+1,n),3)}function Lce(t,e,r,n){return new Qe(be.uint,Wf(t,e+1,n),5)}function zce(t,e,r,n){return new Qe(be.uint,Hf(t,e+1,n),9)}function Vf(t,e){return ta(t,0,e.value)}function ta(t,e,r){if(r<Ni[0]){let n=Number(r);t.push([e|n])}else if(r<Ni[1]){let n=Number(r);t.push([e|24,n])}else if(r<Ni[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<Ni[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<Ni[4]){let i=[e|27,0,0,0,0,0,0,0],a=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=a&255,a=a>>8,i[7]=a&255,a=a>>8,i[6]=a&255,a=a>>8,i[5]=a&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${an} encountered BigInt larger than allowable range`)}}function Fce(t,e,r,n){return new Qe(be.negint,-1-Ff(t,e+1,n),2)}function Gce(t,e,r,n){return new Qe(be.negint,-1-Gf(t,e+1,n),3)}function Wce(t,e,r,n){return new Qe(be.negint,-1-Wf(t,e+1,n),5)}function Hce(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i!="bigint"){let a=-1-i;if(a>=Number.MIN_SAFE_INTEGER)return new Qe(be.negint,a,9)}if(n.allowBigInt!==!0)throw new Error(`${an} integers outside of the safe integer range are not supported`);return new Qe(be.negint,rI-BigInt(i),9)}function nI(t,e){let r=e.value,n=typeof r=="bigint"?r*rI-cL:r*-1-1;ta(t,e.type.majorEncoded,n)}function t0(t,e,r,n){lm(t,e,r+n);let i=t.slice(e+r,e+r+n);return new Qe(be.bytes,i,r+n)}function Vce(t,e,r,n){return t0(t,e,1,r)}function Jce(t,e,r,n){return t0(t,e,2,Ff(t,e+1,n))}function Zce(t,e,r,n){return t0(t,e,3,Gf(t,e+1,n))}function Yce(t,e,r,n){return t0(t,e,5,Wf(t,e+1,n))}function Qce(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer bytes lengths not supported`);return t0(t,e,9,i)}function wx(t){return t.encodedBytes===void 0&&(t.encodedBytes=be.equals(t.type,be.string)?Oce(t.value):t.value),t.encodedBytes}function Ix(t,e){let r=wx(e);ta(t,e.type.majorEncoded,r.length),t.push(r)}function Xce(t,e){return t.length<e.length?-1:t.length>e.length?1:oL(t,e)}function tde(t,e,r){if(r-e<ede){let n="";for(let i=e;i<r;i++){let a=t[i];if(a&128)return yK.decode(t.subarray(e,r));n+=String.fromCharCode(a)}return n}return yK.decode(t.subarray(e,r))}function r0(t,e,r,n,i){let a=r+n;lm(t,e,a);let s=new Qe(be.string,tde(t,e+r,e+a),a);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+a)),s}function rde(t,e,r,n){return r0(t,e,1,r,n)}function nde(t,e,r,n){return r0(t,e,2,Ff(t,e+1,n),n)}function ide(t,e,r,n){return r0(t,e,3,Gf(t,e+1,n),n)}function ode(t,e,r,n){return r0(t,e,5,Wf(t,e+1,n),n)}function sde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer string lengths not supported`);return r0(t,e,9,i,n)}function fm(t,e,r,n){return new Qe(be.array,n,r)}function cde(t,e,r,n){return fm(t,e,1,r)}function dde(t,e,r,n){return fm(t,e,2,Ff(t,e+1,n))}function ude(t,e,r,n){return fm(t,e,3,Gf(t,e+1,n))}function lde(t,e,r,n){return fm(t,e,5,Wf(t,e+1,n))}function fde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer array lengths not supported`);return fm(t,e,9,i)}function pde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return fm(t,e,1,1/0)}function iI(t,e){ta(t,be.array.majorEncoded,e.value)}function pm(t,e,r,n){return new Qe(be.map,n,r)}function hde(t,e,r,n){return pm(t,e,1,r)}function mde(t,e,r,n){return pm(t,e,2,Ff(t,e+1,n))}function yde(t,e,r,n){return pm(t,e,3,Gf(t,e+1,n))}function gde(t,e,r,n){return pm(t,e,5,Wf(t,e+1,n))}function wde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer map lengths not supported`);return pm(t,e,9,i)}function vde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return pm(t,e,1,1/0)}function oI(t,e){ta(t,be.map.majorEncoded,e.value)}function bde(t,e,r,n){return new Qe(be.tag,r,1)}function xde(t,e,r,n){return new Qe(be.tag,Ff(t,e+1,n),2)}function Pde(t,e,r,n){return new Qe(be.tag,Gf(t,e+1,n),3)}function _de(t,e,r,n){return new Qe(be.tag,Wf(t,e+1,n),5)}function Ede(t,e,r,n){return new Qe(be.tag,Hf(t,e+1,n),9)}function sI(t,e){ta(t,be.tag.majorEncoded,e.value)}function Sde(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${an} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new Qe(be.null,null,1):new Qe(be.undefined,void 0,1)}function Tde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return new Qe(be.break,void 0,1)}function aI(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${an} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${an} Infinity values are not supported`)}return new Qe(be.float,t,e)}function kde(t,e,r,n){return aI(dI(t,e+1),3,n)}function Ade(t,e,r,n){return aI(uI(t,e+1),5,n)}function Dde(t,e,r,n){return aI(yL(t,e+1),9,n)}function cI(t,e,r){let n=e.value;if(n===!1)t.push([be.float.majorEncoded|dL]);else if(n===!0)t.push([be.float.majorEncoded|uL]);else if(n===null)t.push([be.float.majorEncoded|lL]);else if(n===void 0)t.push([be.float.majorEncoded|fL]);else{let i,a=!1;(!r||r.float64!==!0)&&(hL(n),i=dI(Na,1),n===i||Number.isNaN(n)?(Na[0]=249,t.push(Na.slice(0,3)),a=!0):(mL(n),i=uI(Na,1),n===i&&(Na[0]=250,t.push(Na.slice(0,5)),a=!0))),a||(Ide(n),i=yL(Na,1),Na[0]=251,t.push(Na.slice(0,9)))}}function hL(t){if(t===1/0)Ws.setUint16(0,31744,!1);else if(t===-1/0)Ws.setUint16(0,64512,!1);else if(Number.isNaN(t))Ws.setUint16(0,32256,!1);else{Ws.setFloat32(0,t);let e=Ws.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Ws.setUint16(0,31744,!1);else if(r===0)Ws.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Ws.setUint16(0,0):i<-14?Ws.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Ws.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function dI(t,e){if(t.length-e<2)throw new Error(`${an} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,a;return n===0?a=i*2**-24:n!==31?a=(i+1024)*2**(n-25):a=i===0?1/0:NaN,r&32768?-a:a}function mL(t){Ws.setFloat32(0,t,!1)}function uI(t,e){if(t.length-e<4)throw new Error(`${an} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ide(t){Ws.setFloat64(0,t,!1)}function yL(t,e){if(t.length-e<8)throw new Error(`${an} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function rr(t,e,r){throw new Error(`${an} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Rx(t){return()=>{throw new Error(`${an} ${t}`)}}function Rde(t){switch(t.type){case be.false:return kd([244]);case be.true:return kd([245]);case be.null:return kd([246]);case be.bytes:return t.value.length?void 0:kd([64]);case be.string:return t.value===""?kd([96]):void 0;case be.array:return t.value===0?kd([128]):void 0;case be.map:return t.value===0?kd([160]):void 0;case be.uint:return t.value<24?kd([Number(t.value)]):void 0;case be.negint:if(t.value>=-24)return kd([31-Number(t.value)])}}function $de(){let t=[];return t[be.uint.major]=Vf,t[be.negint.major]=nI,t[be.bytes.major]=Ix,t[be.string.major]=ade,t[be.array.major]=iI,t[be.map.major]=oI,t[be.tag.major]=sI,t[be.float.major]=cI,t}function Z1(t,e={},r){let n=Dce(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||Xu[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let a=Xu[n];if(!a)throw new Error(`${aL} unsupported type: ${n}`);return a(t,n,e,r)}function jde(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Mde(t,e){if(t[0]instanceof Qe&&e[0]instanceof Qe){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=wK(r.value)),n._keyBytes||(n._keyBytes=wK(n.value)),oL(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wK(t){return Nde(t,Ode,Cde)}function wL(t,e,r,n){if(Array.isArray(e))for(let i of e)wL(t,i,r,n);else r[e.type.major](t,e,n)}function Nde(t,e,r,n){let i=n instanceof Uint8Array,a=i?new Uce(n):Bde,s=Z1(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let o=r.quickEncodeToken(s);if(o)return i?(a.push(o),a.toBytes()):o;let d=e[s.type.major];if(d.encodedSize){let u=d.encodedSize(s,r);if(i||(a=new sL(u)),d(a,s,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?a.toBytes():iL(a.chunks[0])}}return a.reset(),wL(a,s,e,r),a.toBytes(!0)}function To(t){if(typeof t=="string"&&t.length!==0)return t.split("#").pop()}function Ude({didDocument:t,id:e,type:r}){return t?.service?.filter(n=>!(e&&n.id!==e||r&&n.type!==r))??[]}async function Kde({didDocument:t,publicKeyJwk:e,publicKeyMultibase:r}){let n=Cx({didDocument:t});for(let i of n)if(e&&i.publicKeyJwk){if(await lr({jwk:e})===await lr({jwk:i.publicKeyJwk}))return i}else if(r&&i.publicKeyMultibase&&r===i.publicKeyMultibase)return i;return null}function Cx({didDocument:t}){if(!t)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...t.verificationMethod?.filter(vx)??[]),Object.keys(kx).forEach(r=>{e.push(...t[r]?.filter(vx)??[])}),e}function vL({didDocument:t}){let e=Cx({didDocument:t}).map(r=>r.type);return[...new Set(e)]}function bL({didDocument:t,methodId:e}){let r=[];return Object.keys(kx).forEach(n=>{if(Array.isArray(t[n])){let i=t[n],a=To(e);i.some(s=>{let o=To(s)===a,d=vx(s)&&To(s.id)===a;return o||d})&&r.push(n)}}),r}function xL(t){return!t||typeof t!="object"||t===null?!1:"id"in t&&"type"in t&&"serviceEndpoint"in t}function qde(t){return!(!xL(t)||t.type!=="DecentralizedWebNode")}function vx(t){return!(!t||typeof t!="object"||t===null||!("id"in t&&"type"in t&&"controller"in t)||typeof t.id!="string"||typeof t.type!="string"||typeof t.controller!="string")}function $x(t){return!(!t||typeof t!="object"||t===null)&&"uri"in t&&"document"in t&&"metadata"in t&&(!("keyManager"in t)||t.keyManager===void 0)}function PL({keyBytes:t,multicodecCode:e,multicodecName:r}){let n=Xs.addPrefix({code:e,data:t,name:r}),i=tt.uint8Array(n).toBase58Btc();return tt.base58Btc(i).toMultibase()}function _L({multibaseKeyId:t}){try{let e=tt.multibase(t).toBase58Btc(),r=tt.base58Btc(e).toUint8Array(),{code:n,data:i,name:a}=Xs.removePrefix({prefixedData:r});return{keyBytes:i,multicodecCode:n,multicodecName:a}}catch{throw new Xe("invalidDid",`Invalid multibase identifier: ${t}`)}}function i0(t){let e=t<0?1:0;return t=Math.abs(Number(t||1)),Math.floor(Math.log10(t))+1+e}function DL(t){return ArrayBuffer.isView(t)?"arraybufferview":Array.isArray(t)?"array":t instanceof Number?"number":t instanceof Boolean?"boolean":t instanceof Set?"set":t instanceof Map?"map":t instanceof String?"string":t instanceof ArrayBuffer?"arraybuffer":typeof t}function sr(t,e,r){let n=[],i=null;return sr._encode(n,t),i=zde(n),sr.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,r),e):i}function CL(t,e,r){let n=0,i=1;for(let a=e;a<r;a++){let s=t[a];if(s<58&&s>=48){n=n*10+(s-48);continue}if(!(a===e&&s===43)){if(a===e&&s===45){i=-1;continue}if(s===46)break;throw new Error("not a number: buffer["+a+"] = "+s)}}return n*i}function pt(t,e,r,n){return t==null||t.length===0?null:(typeof e!="number"&&n==null&&(n=e,e=void 0),typeof r!="number"&&n==null&&(n=r,r=void 0),pt.position=0,pt.encoding=n||null,pt.data=ArrayBuffer.isView(t)?new Uint8Array(t.slice(e,r)):$d(t),pt.bytes=pt.data.length,pt.next())}function Xde(t){let e=2;for(let r of t)e+=Bx(r);return e}function eue(t){let e=2;for(let[r,n]of t){let i=$d(r).byteLength;e+=i0(i)+1+i,e+=Bx(n)}return e}function tue(t){let e=2,r=Object.keys(t);for(let n=0;n<r.length;n++){let i=$d(r[n]).byteLength;e+=i0(i)+1+i,e+=Bx(t[r[n]])}return e}function rue(t){let e=$d(t).byteLength;return i0(e)+1+e}function nue(t){let e=t.byteLength-t.byteOffset;return i0(e)+1+e}function Bx(t){if(t==null)return 0;let e=DL(t);switch(e){case"arraybufferview":return nue(t);case"string":return rue(t);case"array":case"set":return Xde(t);case"number":return 1+i0(Math.floor(t))+1;case"bigint":return 1+t.toString().length+1;case"object":return tue(t);case"map":return eue(t);default:throw new TypeError(`Unsupported value of type "${e}"`)}}function BL(t){if(Ac.isFormat(t))return Ac.size;if(Qu.isFormat(t))return Qu.size;throw Error(`Invalid ip address: ${t}`)}function aue(t){return BL(t)===Ac.size?1:2}function cue(t,e,r){r=~~r;let n=BL(t);return typeof e=="function"&&(e=e(r+n)),n===Ac.size?Ac.encode(t,e,r):Qu.encode(t,e,r)}function due(t,e,r){if(e=~~e,r=r||t.length-e,r===Ac.size)return Ac.decode(t,e,r);if(r===Qu.size)return Qu.decode(t,e,r);throw Error(`Invalid buffer size needs to be ${Ac.size} for v4 or ${Qu.size} for v6.`)}function jx(t){switch(t){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+t}function Vw(t){switch(t.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return t.toUpperCase().startsWith("UNKNOWN_")?parseInt(t.slice(8)):0}function uue(t){switch(t){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+t}function lue(t){switch(t){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+t}function jL(t){switch(t){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+t}function ML(t){switch(t.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}function fue(t){switch(t){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return t<0?null:`OPTION_${t}`}function RK(t){if(typeof t=="number")return t;if(!t)return-1;switch(t.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=t.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}function NL(t){let e=0,r=t.length;for(let n=0;n<r;n+=1){let i=t.charCodeAt(n);if(i<=127)e+=1;else if(i<=2047)e+=2;else if((i&63488)!==55296)e+=3;else{let a=n+1;a===r||i>=56320||(t.charCodeAt(a)&64512)!==56320?e+=3:(n=a,e+=4)}}return e}function Jw(t,e,r){let n=t.length;r==null&&(r=0),e===void 0&&(e=new Uint8Array(NL(t)+r));let i=r;for(let a=0;a<n;a+=1){let s=t.charCodeAt(a);if(s<=127)e[i++]=s;else if(s<=2047)e[i++]=192|(s&1984)>>6,e[i++]=128|s&63;else if((s&63488)!==55296)e[i++]=224|(s&61440)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63;else{let o=a+1;if(o===n||s>=56320)e[i++]=239,e[i++]=191,e[i++]=189;else{let d=t.charCodeAt(o);(d&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(a=o,s=65536|(s&1023)<<10|d&1023,e[i++]=240|(s&1835008)>>18,e[i++]=128|(s&258048)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63)}}}return Jw.bytes=i-r,e}function o0(t,e,r){let n="";e==null&&(e=0),r==null&&(r=t.length);for(let i=e;i<r;){let a=t[i++],s;if(a<=128)s=a;else if(a>191&&a<224)s=(a&31)<<6|t[i++]&63;else if(a>239&&a<365){s=((a&7)<<18|(t[i++]&63)<<12|(t[i++]&63)<<6|t[i++]&63)-65536;let o=55296|s>>10&1023;n+=String.fromCharCode(o),s=56320|s&1023}else s=(a&15)<<12|(t[i++]&63)<<6|t[i++]&63;n+=String.fromCharCode(s)}return o0.bytes=r-e,n}function el(t){return typeof t=="string"?NL(t):t.byteLength}function hI(t){return t instanceof Uint8Array?t:Array.isArray(t)?new Uint8Array(t):Jw(t)}function mI(t,e,r){if(typeof e!="string")throw new Error("unknown input type");return Jw(e,t,r),Jw.bytes}function pue(t,e,r){let n="";for(let i=e;i<r;){let a=t[i++];n+=UL[a]}return n}function CK(t){return t.length>>>1}function hue(t,e,r,n){let i=0;for(;r<n;){let a=e.substr(i,2),s=Dw[a];if(s===void 0)return;t[r++]=s,i+=2}return t}function bs(t,e,r,n,i){return r<0&&(n-=r,r=0),n<0&&(n=0),i<0?new Uint8Array(0):r>=e.length||n>=i?0:wue(t,e,r,n,i)}function wue(t,e,r,n,i){i-n>e.length-r&&(i=n+e.length-r);let a=i-n,s=t.length-n;return a>s&&(a=s),(n!==0||i<t.length)&&(t=new Uint8Array(t.buffer,t.byteOffset+n,a)),e.set(t,r),a}function Cr({bytes:t=0,encode:e,decode:r,encodingLength:n}){return e.bytes=t,r.bytes=t,{encode:e,decode:r,encodingLength:n||(()=>t)}}function RD(t){if(t===1)return 20;if(t===2)return 32;throw new Error(`Invalid hashType=${t}, supported=1,2`)}function gD(t){switch(t.toUpperCase()){case"A":return qL;case"PTR":return rm;case"CNAME":return rm;case"DNAME":return rm;case"TXT":return ex;case"NULL":return tx;case"AAAA":return ox;case"SRV":return nx;case"HINFO":return rx;case"CAA":return Ju;case"NS":return Q1;case"SOA":return X1;case"MX":return ix;case"OPT":return Zu;case"DNSKEY":return kc;case"RRSIG":return Iw;case"RP":return Rw;case"NSEC":return Cw;case"NSEC3":return $w;case"SSHFP":return Xh;case"DS":return Ow}return Y1}function bx(t,e){if(t.questions)throw new Error("Only one .question object expected instead of a .questions array!");let r=Object.assign({type:e},t);return r.question&&(r.questions=[r.question],delete r.question),r}function LL(t){let e=_x(t),r=new Uint8Array(2+e.byteLength);return rt(r,e.byteLength),bs(e,r,2,0,e.length),LL.bytes=r.byteLength,r}function zL(t){let e=It(t,0);if(t.byteLength<e+2)return null;let r=CD(t.slice(2));return zL.bytes=CD.bytes,r}function em(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function Bw(t,e,r,n){for(let i=0;i<t.length;i++)e.encode(t[i],r,n),n+=e.encode.bytes;return n}function z1(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e.decode(r,n),n+=e.decode.bytes;return n}function FL(t,e){let r=tt.uint8Array(t).toBase32Z();return new URL(r,e).href}async function Eue({gatewayUri:t,publicKeyBytes:e}){let r=tt.uint8Array(e).toBase32Z(),n=FL(e,t),i;try{if(i=await fetch(n,{method:"GET",signal:AbortSignal.timeout(3e4)}),!i.ok)throw new Xe("notFound",`Pkarr record not found for: ${r}`)}catch(s){throw s instanceof Xe?s:new Xe("internalError",`Failed to fetch Pkarr record: ${s.message}`)}let a=await i.arrayBuffer();if(!a)throw new Xe("notFound",`Pkarr record not found for: ${r}`);if(a.byteLength<72)throw new Xe("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${a.byteLength}`);if(a.byteLength>1072)throw new Xe("invalidDidDocumentLength",`Pkarr response exceeds 1000 byte limit: ${a.byteLength}`);return{k:e,seq:Number(new DataView(a).getBigUint64(64)),sig:new Uint8Array(a,0,64),v:new Uint8Array(a,72)}}async function Sue({gatewayUri:t,bep44Message:e}){let r=tt.uint8Array(e.k).toBase32Z(),n=FL(e.k,t),i=new Uint8Array(e.v.length+72);i.set(e.sig,0),new DataView(i.buffer).setBigUint64(e.sig.length,BigInt(e.seq)),i.set(e.v,e.sig.length+8);let a;try{a=await fetch(n,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:i,signal:AbortSignal.timeout(3e4)})}catch(s){throw new Xe("internalError",`Failed to put Pkarr record for identifier ${r}: ${s.message}`)}return a.ok}async function Tue({dnsPacket:t,publicKeyBytes:e,signer:r}){let n=Math.ceil(Date.now()/1e3),i=_x(t),a=OL.encode({seq:n,v:i}).subarray(1,-1);if(a.length>1e3)throw new Xe("invalidDidDocumentLength",`DNS packet exceeds the 1000 byte maximum size: ${a.length} bytes`);let s=await r.sign({data:new Uint8Array(a)});return{k:e,seq:n,sig:s,v:i}}async function kue({bep44Message:t}){let e=await Mi.bytesToPublicKey({publicKeyBytes:t.k}),r=OL.encode({seq:t.seq,v:t.v}).subarray(1,-1);if(!await Mi.verify({key:e,signature:t.sig,data:new Uint8Array(r)}))throw new Xe("invalidSignature","Invalid signature for DHT BEP44 message");return CD(t.v)}async function WL({didUri:t}){let e=yI({didUri:t});return await Mi.bytesToPublicKey({publicKeyBytes:e})}function yI({didUri:t}){let e=Vn.parse(t);if(!e)throw new Xe("invalidDid",`Invalid DID URI: ${t}`);if(e.method!==GL)throw new Xe("methodNotSupported",`Method not supported: ${e.method}`);let r;try{r=tt.base32Z(e.id).toUint8Array()}catch{throw new Xe("invalidPublicKey","Failed to decode method-specific identifier")}if(r.length!==32)throw new Xe("invalidPublicKeyLength",`Invalid public key length: ${r.length}`);return r}async function Aue({identityKey:t}){let e=await Mi.publicKeyToBytes({publicKey:t}),r=tt.uint8Array(e).toBase32Z();return`did:${GL}:${r}`}function gI(t){let e={Ed25519:Mi,"P-256":{publicKeyToBytes:async({publicKey:r})=>{let n=await no.publicKeyToBytes({publicKey:r});return await no.compressPublicKey({publicKeyBytes:n})},bytesToPublicKey:no.bytesToPublicKey,privateKeyToBytes:no.privateKeyToBytes,bytesToPrivateKey:no.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:r})=>{let n=await ji.publicKeyToBytes({publicKey:r});return await ji.compressPublicKey({publicKeyBytes:n})},bytesToPublicKey:ji.bytesToPublicKey,privateKeyToBytes:ji.privateKeyToBytes,bytesToPrivateKey:ji.bytesToPrivateKey},X25519:Vh}[t];if(!e)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${t}`);return e}async function HL({newDid:t,previousDidProof:e}){let r=await WL({didUri:e.previousDid}),n=yI({didUri:t}),i=tt.base64Url(e.signature).toUint8Array();if(!await Mi.verify({key:r,data:n,signature:i}))throw new Xe("invalidPreviousDidProof","The previous DID proof is invalid.")}function Zw(t){if(typeof t=="string")return t;if(t instanceof Uint8Array)return tt.uint8Array(t).toString();if(Array.isArray(t))return t.map(e=>Zw(e)).join("");throw new Xe("internalError","Pkarr returned DNS TXT record with invalid data type")}function jw(t){return Zw(t).split(sx).reduce((e,r)=>{let[n,i]=r.split("=");return e[n]=i,e},{})}function ZL(t){if(t.length<=255)return t;let e=[];for(let r=0;r<t.length;r+=255)e.push(t.slice(r,r+255));return e}async function Iue({didUri:t,dnsPacket:e}){let r={id:t},n={published:!0},i=new Map;for(let a of e?.answers??[]){if(a.type!=="TXT")continue;let s=a.name.split(".")[0].substring(1);switch(!0){case s.startsWith("aka"):{let o=Zw(a.data);r.alsoKnownAs=o.split(So);break}case s.startsWith("cnt"):{let o=Zw(a.data);r.controller=o.includes(So)?o.split(So):o;break}case s.startsWith("k"):{let{id:o,t:d,k:u,c,a:l}=jw(a.data),f=tt.base64Url(u).toUint8Array(),h=fI[Number(d)],p=await gI(h).bytesToPublicKey({publicKeyBytes:f});p.alg=l||JL[Number(d)];let m=s==="k0"?"0":o!==void 0?o:await lr({jwk:p});r.verificationMethod??=[];let g=`${t}#${m}`;r.verificationMethod.push({id:g,type:"JsonWebKey",controller:c??t,publicKeyJwk:p}),i.set(s,g);break}case s.startsWith("s"):{let{id:o,t:d,se:u,...c}=jw(a.data),l=u.includes(So)?u.split(So):[u],f=Object.fromEntries(Object.entries(c).map(([h,p])=>[h,p.includes(So)?p.split(So):p]));r.service??=[],r.service.push({...f,id:`${t}#${o}`,type:d,serviceEndpoint:l});break}case s.startsWith("typ"):{let{id:o}=jw(a.data);n.types=o.split(So).map(d=>Number(d));break}case s.startsWith("did"):{let o=h=>h.split(So).map(p=>i.get(p)).filter(p=>typeof p=="string"),{auth:d,asm:u,del:c,inv:l,agm:f}=jw(a.data);d&&(r.authentication=o(d)),u&&(r.assertionMethod=o(u)),c&&(r.capabilityDelegation=o(c)),l&&(r.capabilityInvocation=o(l)),f&&(r.keyAgreement=o(f));break}}}return{didDocument:r,didDocumentMetadata:n,didResolutionMetadata:{}}}async function Rue({didDocument:t,didMetadata:e,authoritativeGatewayUris:r,previousDidProof:n}){let i=[],a=[],s=new Map,o=[],d=[];if(n!==void 0){let{signature:c,previousDid:l}=n;await HL({newDid:t.id,previousDidProof:n}),i.push({type:"TXT",name:"_prv._did.",ttl:Gu,data:`id=${l};s=${c}`})}if(t.alsoKnownAs&&i.push({type:"TXT",name:"_aka._did.",ttl:Gu,data:t.alsoKnownAs.join(So)}),t.controller){let c=Array.isArray(t.controller)?t.controller.join(So):t.controller;i.push({type:"TXT",name:"_cnt._did.",ttl:Gu,data:c})}for(let[c,l]of t.verificationMethod?.entries()??[]){let f=`k${c}`;d.push(f);let h=l.id.split("#").pop();s.set(h,f);let p=l.publicKeyJwk;if(!(p?.crv&&p.crv in VL))throw new Xe("invalidPublicKeyType",`Verification method '${l.id}' contains an unsupported key type: ${p?.crv??"undefined"}`);let m=fI[p.crv],g=await gI(p.crv).publicKeyToBytes({publicKey:p}),_=tt.uint8Array(g).toBase64Url(),v=[`t=${m}`,`k=${_}`];h!=="0"&&await lr({jwk:p})!==h&&v.unshift(`id=${h}`),p.alg!==JL[m]&&v.push(`a=${p.alg}`),l.controller!==t.id&&v.push(`c=${l.controller}`),i.push({type:"TXT",name:`_${f}._did.`,ttl:Gu,data:v.join(sx)})}t.service?.forEach((c,l)=>{let f=`s${l}`;o.push(f);let{id:h,type:p,serviceEndpoint:m,...g}=c;h=To(h),m=Array.isArray(m)?m.join(","):m;let _=Object.entries({id:h,t:p,se:m,...g}).map(([E,T])=>`${E}=${T}`).join(sx),v=ZL(_);i.push({type:"TXT",name:`_${f}._did.`,ttl:Gu,data:v})});let u=[`v=${Due}`];if(d.length&&u.push(`vm=${d.join(So)}`),Object.keys(kx).forEach(c=>{let l=t[c]?.map(f=>s.get(f.split("#").pop()));if(l){let f=TL[c];u.push(`${f}=${l.join(So)}`)}}),o.length&&u.push(`svc=${o.join(So)}`),e.types?.length){let c=e.types.map(l=>typeof l=="string"?SL[l]:l);i.push({type:"TXT",name:"_typ._did.",ttl:Gu,data:`id=${c.join(So)}`})}i.push({type:"TXT",name:"_did."+BK(t.id)+".",ttl:Gu,data:u.join(sx)});for(let c of r||[])a.push({type:"NS",name:"_did."+BK(t.id)+".",ttl:Gu,data:c+"."});return{id:0,type:"response",flags:Pue,answers:[...i,...a]}}function BK(t){return t.split(":")[2]}function XL(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Gue;)e[r++]=t&255|UK,t/=128;for(;t&Fue;)e[r++]=t&255|UK,t>>>=7;return e[r]=t|0,XL.bytes=r-n+1,e}function jD(t,n){var r=0,n=n||0,i=0,a=n,s,o=t.length;do{if(a>=o)throw jD.bytes=0,new RangeError("Could not decode varint");s=t[a++],r+=i<28?(s&KK)<<i:(s&KK)*Math.pow(2,i),i+=7}while(s>=Hue);return jD.bytes=a-n,r}function vle(t){t=EI(t);let e=im+8;(t.length<e||t.length>1024)&&ui("expected proper params");let r=Ye(Kx(t),_I-1n)+1n;return TI(r)}function Dle(t){let e=t.toLowerCase();if(e==="localhost"||e==="localhost.")return!0;let r=e.split(".");if(r.length===4){let i=r.map(Number);if(i.every(a=>!Number.isNaN(a)&&a>=0&&a<=255)){let[a,s]=i;if(a===10||a===172&&s>=16&&s<=31||a===192&&s===168||a===127||a===169&&s===254||a===0)return!0}}let n=e;return n.startsWith("[")&&n.endsWith("]")&&(n=n.slice(1,-1)),!!(n.includes(":")&&(n==="::1"||n==="::"||n==="::0"||n.startsWith("fe80:")||n.startsWith("fe80%")||n.startsWith("fc")||n.startsWith("fd")))}var hoe,qD,moe,yoe,goe,woe,Ft,LD,voe,Lf,boe,xoe,Rc,Poe,_oe,zD,uq,lq,fq,Eoe,Soe,Toe,koe,Tx,FD,Bf,Aoe,Doe,pq,Ioe,Roe,hq,Coe,$oe,Ooe,HU,mq,Boe,yq,gq,joe,Moe,Noe,wq,Uoe,Koe,vq,kx,li,Oi,Vn,Xe,qoe,Ys,zo,Loe,Foe,Goe,Woe,gje,Hoe,GD,Voe,Joe,Zoe,_q,Yoe,Eq,Sq,Qoe,Xoe,xs,V1,wje,vje,bje,xje,Pje,_je,Eje,VU,Js,Sje,Tje,kje,Pd,Aje,vw,JU,K1,Af,tt,qw,rse,nse,Tw,ise,ZU,ose,sse,ase,cse,dse,YU,use,lse,fse,pse,hse,mse,yse,gse,wse,vse,bse,xse,hx,mx,zw,Fw,Pse,_se,Ese,WD,QU,XU,PD,Dje,Sse,Tse,kse,bw,Ase,eK,Dse,Xs,Ije,ju,Ise,Ax,Aq,Dq,Dx,Rse,Cse,_d,Nse,VD,uD,rK,Use,lD,fD,xc,zse,jq,Rje,Nq,Gse,Wse,Hse,Mu,Nu,Vse,Uq,Hn,Xr,Rf,Jse,_D,iK,oK,Cje,Zse,Xse,eae,sae,pD,cae,dae,Of,Dd,Vs,$je,sK,Oje,Gq,Wq,Vq,aK,hae,SD,cK,TD,gs,Bje,jje,J1,hD,Pc,Mje,vae,Nje,_ae,Eae,Sae,Tae,Uu,Ku,kae,Gw,Dae,Yq,Iae,uK,Ci,Cae,ji,Qq,$ae,Oae,Bae,zs,$i,jae,no,Ed,lK,q1,kD,Nae,Uae,Kae,qae,Lae,zae,Fae,Gae,Wae,Hae,Vae,Jae,Zae,Qae,Xae,ece,tce,rce,nce,ice,Dt,oce,sce,qu,Lu,ace,eL,Ma,ms,L1,cce,dce,xw,mD,Ww,fK,Uje,pce,AD,hce,pK,mce,yce,hK,Qs,Hw,Df,Kje,qje,kw,bce,Lje,zje,Fje,Gje,Wje,Hje,Vje,Jje,Zje,Yje,Fs,xce,Mi,Sd,Pce,_ce,Ece,zu,Sce,Vh,Pw,Tce,Td,yD,Ka,kce,Ace,be,Qe,Xw,Rce,Cce,$ce,Oce,kd,Bce,jce,Mce,Nce,sL,Uce,an,aL,e0,Ni,rI,cL,yK,ede,ade,dL,uL,lL,fL,pL,Ws,Na,Ce,Od,Cde,Ode,Bde,gK,Fu,Xu,Qje,Xje,e4e,t4e,r4e,n4e,i4e,o4e,s4e,a4e,c4e,d4e,u4e,vK,io,Zs,bK,xK,l4e,f4e,p4e,h4e,PK,_K,EK,SK,lI,ea,n0,SL,fI,TL,TK,kL,kK,Lde,zde,AK,Fde,_w,Gde,AL,Wde,$d,DK,IK,m4e,Ox,IL,RL,Hde,Vde,Jde,Zde,Yde,pI,Qde,$L,iue,OL,oue,sue,Ac,Qu,qf,Dw,UL,mue,yue,gue,Id,It,Rd,rt,vue,$K,ID,bue,KL,xue,He,Wn,Jh,Y1,Q1,X1,ex,tx,rx,rm,nx,Ju,ix,qL,ox,OK,Ad,Zu,kc,Iw,Rw,vs,Cw,$w,Ow,Xh,Hs,nm,Pue,Ui,xx,Px,_x,CD,_ue,GL,Due,Gu,sx,So,VL,JL,jK,YL,tl,MK,tm,An,Dn,y4e,Cue,$ue,Oue,Bue,QL,jue,Mue,Nue,Uue,Mx,g4e,w4e,NK,v4e,am,Kue,OD,Tc,ys,wI,Ua,que,Yw,Lue,UK,zue,Fue,Gue,Wue,Hue,KK,Vue,Jue,Zue,Yue,Que,Xue,ele,tle,rle,nle,ile,ole,Ex,qK,LK,zK,FK,sle,e9,t9,ale,r9,GK,b4e,Ew,ws,MD,F1,ND,Hh,G1,n9,WK,cle,Bi,cx,UD,KD,W1,Lo,o9,vI,cm,dle,st,HK,VK,dm,Sx,dx,s9,bI,xI,ule,lle,JK,a9,_c,fle,ZK,ple,wD,YK,hle,Cf,mle,yle,PI,Nf,_I,c9,d9,u9,im,QK,ui,Nx,l9,vD,f9,p9,Qw,EI,Ye,XK,eq,um,Lw,ux,h9,SI,Ux,Kx,tq,TI,rq,nq,m9,gle,wle,iq,lx,ble,$f,xle,Ple,oq,sq,Sw,_le,Ele,aq,Sle,y9,Jf,Tle,fx,H1,kle,cq,g9,qx,Ale,w9,kI,x4e,P4e,Ile,Lx,Rle,s0,Fo=F(()=>{"use strict";y();hoe=Object.create,qD=Object.defineProperty,moe=Object.getOwnPropertyDescriptor,yoe=Object.getOwnPropertyNames,goe=Object.getPrototypeOf,woe=Object.prototype.hasOwnProperty,Ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),LD=(t,e)=>{for(var r in e)qD(t,r,{get:e[r],enumerable:!0})},voe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yoe(e))!woe.call(t,i)&&i!==r&&qD(t,i,{get:()=>e[i],enumerable:!(n=moe(e,i))||n.enumerable});return t},Lf=(t,e,r)=>(r=t!=null?hoe(goe(t)):{},voe(e||!t||!t.__esModule?qD(r,"default",{value:t,enumerable:!0}):r,t)),boe=Ft((t,e)=>{var r=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,n=()=>r.now(),i=o=>o&&o===Math.floor(o)&&o>0&&isFinite(o),a=o=>o===1/0||i(o),s=class dq{constructor({max:d=1/0,ttl:u,updateAgeOnGet:c=!1,checkAgeOnGet:l=!1,noUpdateTTL:f=!1,dispose:h,noDisposeOnSet:p=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,u!==void 0&&!a(u))throw new TypeError("ttl must be positive integer or Infinity if set");if(!a(d))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=u,this.max=d,this.updateAgeOnGet=!!c,this.checkAgeOnGet=!!l,this.noUpdateTTL=!!f,this.noDisposeOnSet=!!p,h!==void 0){if(typeof h!="function")throw new TypeError("dispose must be function if set");this.dispose=h}this.timer=void 0,this.timerExpiration=void 0}setTimer(d,u){if(this.timerExpiration<d)return;this.timer&&clearTimeout(this.timer);let c=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let l in this.expirations){this.setTimer(l,l-n());break}},u);c.unref&&c.unref(),this.timerExpiration=d,this.timer=c}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let d=this.dispose!==dq.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[u,c]of d)this.dispose(c,u,"delete")}setTTL(d,u=this.ttl){let c=this.expirationMap.get(d);if(c!==void 0){let l=this.expirations[c];!l||l.length<=1?delete this.expirations[c]:this.expirations[c]=l.filter(f=>f!==d)}if(u!==1/0){let l=Math.floor(n()+u);this.expirationMap.set(d,l),this.expirations[l]||(this.expirations[l]=[],this.setTimer(l,u)),this.expirations[l].push(d)}else this.expirationMap.set(d,1/0)}set(d,u,{ttl:c=this.ttl,noUpdateTTL:l=this.noUpdateTTL,noDisposeOnSet:f=this.noDisposeOnSet}={}){if(!a(c))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(d)){l||this.setTTL(d,c);let h=this.data.get(d);h!==u&&(this.data.set(d,u),f||this.dispose(h,d,"set"))}else this.setTTL(d,c),this.data.set(d,u);for(;this.size>this.max;)this.purgeToCapacity();return this}has(d){return this.data.has(d)}getRemainingTTL(d){let u=this.expirationMap.get(d);return u===1/0?u:u!==void 0?Math.max(0,Math.ceil(u-n())):0}get(d,{updateAgeOnGet:u=this.updateAgeOnGet,ttl:c=this.ttl,checkAgeOnGet:l=this.checkAgeOnGet}={}){let f=this.data.get(d);if(l&&this.getRemainingTTL(d)===0){this.delete(d);return}return u&&this.setTTL(d,c),f}dispose(d,u){}delete(d){let u=this.expirationMap.get(d);if(u!==void 0){let c=this.data.get(d);this.data.delete(d),this.expirationMap.delete(d);let l=this.expirations[u];return l&&(l.length<=1?delete this.expirations[u]:this.expirations[u]=l.filter(f=>f!==d)),this.dispose(c,d,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let d in this.expirations){let u=this.expirations[d];if(this.size-u.length>=this.max){delete this.expirations[d];let c=[];for(let l of u)c.push([l,this.data.get(l)]),this.data.delete(l),this.expirationMap.delete(l);for(let[l,f]of c)this.dispose(f,l,"evict")}else{let c=this.size-this.max,l=[];for(let f of u.splice(0,c))l.push([f,this.data.get(f)]),this.data.delete(f),this.expirationMap.delete(f);for(let[f,h]of l)this.dispose(h,f,"evict");return}}}get size(){return this.data.size}purgeStale(){let d=Math.ceil(n());for(let u in this.expirations){if(u==="Infinity"||u>d)return;let c=[...this.expirations[u]||[]],l=[];delete this.expirations[u];for(let f of c)l.push([f,this.data.get(f)]),this.data.delete(f),this.expirationMap.delete(f);for(let[f,h]of l)this.dispose(h,f,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let d in this.expirations)for(let u of this.expirations[d])yield[u,this.data.get(u)]}*keys(){for(let d in this.expirations)for(let u of this.expirations[d])yield u}*values(){for(let d in this.expirations)for(let u of this.expirations[d])yield this.data.get(u)}[Symbol.iterator](){return this.entries()}};e.exports=s}),xoe=Ft(t=>{"use strict";t.supports=function(...e){let r=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(r,{snapshots:r.snapshots||!1,permanence:r.permanence||!1,seek:r.seek||!1,clear:r.clear||!1,getMany:r.getMany||!1,keyIterator:r.keyIterator||!1,valueIterator:r.valueIterator||!1,iteratorNextv:r.iteratorNextv||!1,iteratorAll:r.iteratorAll||!1,status:r.status||!1,createIfMissing:r.createIfMissing||!1,errorIfExists:r.errorIfExists||!1,deferredOpen:r.deferredOpen||!1,promises:r.promises||!1,streams:r.streams||!1,encodings:Object.assign({},r.encodings),events:Object.assign({},r.events),additionalMethods:Object.assign({},r.additionalMethods)})}}),Rc=Ft((t,e)=>{"use strict";e.exports=class extends Error{constructor(r,n){super(r||""),typeof n=="object"&&n!==null&&(n.code&&(this.code=String(n.code)),n.expected&&(this.expected=!0),n.transient&&(this.transient=!0),n.cause&&(this.cause=n.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}}),Poe=Ft(t=>{"use strict";t.byteLength=d,t.toByteArray=c,t.fromByteArray=h;var e=[],r=[],n=typeof Uint8Array<"u"?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(a=0,s=i.length;a<s;++a)e[a]=i[a],r[i.charCodeAt(a)]=a;var a,s;r[45]=62,r[95]=63;function o(p){var m=p.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var g=p.indexOf("=");g===-1&&(g=m);var _=g===m?0:4-g%4;return[g,_]}function d(p){var m=o(p),g=m[0],_=m[1];return(g+_)*3/4-_}function u(p,m,g){return(m+g)*3/4-g}function c(p){var m,g=o(p),_=g[0],v=g[1],E=new n(u(p,_,v)),T=0,D=v>0?_-4:_,R;for(R=0;R<D;R+=4)m=r[p.charCodeAt(R)]<<18|r[p.charCodeAt(R+1)]<<12|r[p.charCodeAt(R+2)]<<6|r[p.charCodeAt(R+3)],E[T++]=m>>16&255,E[T++]=m>>8&255,E[T++]=m&255;return v===2&&(m=r[p.charCodeAt(R)]<<2|r[p.charCodeAt(R+1)]>>4,E[T++]=m&255),v===1&&(m=r[p.charCodeAt(R)]<<10|r[p.charCodeAt(R+1)]<<4|r[p.charCodeAt(R+2)]>>2,E[T++]=m>>8&255,E[T++]=m&255),E}function l(p){return e[p>>18&63]+e[p>>12&63]+e[p>>6&63]+e[p&63]}function f(p,m,g){for(var _,v=[],E=m;E<g;E+=3)_=(p[E]<<16&16711680)+(p[E+1]<<8&65280)+(p[E+2]&255),v.push(l(_));return v.join("")}function h(p){for(var m,g=p.length,_=g%3,v=[],E=16383,T=0,D=g-_;T<D;T+=E)v.push(f(p,T,T+E>D?D:T+E));return _===1?(m=p[g-1],v.push(e[m>>2]+e[m<<4&63]+"==")):_===2&&(m=(p[g-2]<<8)+p[g-1],v.push(e[m>>10]+e[m>>4&63]+e[m<<2&63]+"=")),v.join("")}}),_oe=Ft(t=>{t.read=function(e,r,n,i,a){var s,o,d=a*8-i-1,u=(1<<d)-1,c=u>>1,l=-7,f=n?a-1:0,h=n?-1:1,p=e[r+f];for(f+=h,s=p&(1<<-l)-1,p>>=-l,l+=d;l>0;s=s*256+e[r+f],f+=h,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=i;l>0;o=o*256+e[r+f],f+=h,l-=8);if(s===0)s=1-c;else{if(s===u)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,i),s=s-c}return(p?-1:1)*o*Math.pow(2,s-i)},t.write=function(e,r,n,i,a,s){var o,d,u,c=s*8-a-1,l=(1<<c)-1,f=l>>1,h=a===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:s-1,m=i?1:-1,g=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(d=isNaN(r)?1:0,o=l):(o=Math.floor(Math.log(r)/Math.LN2),r*(u=Math.pow(2,-o))<1&&(o--,u*=2),o+f>=1?r+=h/u:r+=h*Math.pow(2,1-f),r*u>=2&&(o++,u/=2),o+f>=l?(d=0,o=l):o+f>=1?(d=(r*u-1)*Math.pow(2,a),o=o+f):(d=r*Math.pow(2,f-1)*Math.pow(2,a),o=0));a>=8;e[n+p]=d&255,p+=m,d/=256,a-=8);for(o=o<<a|d,c+=a;c>0;e[n+p]=o&255,p+=m,o/=256,c-=8);e[n+p-m]|=g*128}}),zD=Ft(t=>{"use strict";var e=Poe(),r=_oe(),n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=v,t.INSPECT_MAX_BYTES=50;var i=2147483647;t.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=a(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function a(){try{let k=new Uint8Array(1),j={foo:function(){return 42}};return Object.setPrototypeOf(j,Uint8Array.prototype),Object.setPrototypeOf(k,j),k.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function s(k){if(k>i)throw new RangeError('The value "'+k+'" is invalid for option "size"');let j=new Uint8Array(k);return Object.setPrototypeOf(j,o.prototype),j}function o(k,j,K){if(typeof k=="number"){if(typeof j=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(k)}return d(k,j,K)}o.poolSize=8192;function d(k,j,K){if(typeof k=="string")return f(k,j);if(ArrayBuffer.isView(k))return p(k);if(k==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k);if(Pe(k,ArrayBuffer)||k&&Pe(k.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Pe(k,SharedArrayBuffer)||k&&Pe(k.buffer,SharedArrayBuffer)))return m(k,j,K);if(typeof k=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let te=k.valueOf&&k.valueOf();if(te!=null&&te!==k)return o.from(te,j,K);let se=g(k);if(se)return se;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof k[Symbol.toPrimitive]=="function")return o.from(k[Symbol.toPrimitive]("string"),j,K);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k)}o.from=function(k,j,K){return d(k,j,K)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function u(k){if(typeof k!="number")throw new TypeError('"size" argument must be of type number');if(k<0)throw new RangeError('The value "'+k+'" is invalid for option "size"')}function c(k,j,K){return u(k),k<=0?s(k):j!==void 0?typeof K=="string"?s(k).fill(j,K):s(k).fill(j):s(k)}o.alloc=function(k,j,K){return c(k,j,K)};function l(k){return u(k),s(k<0?0:_(k)|0)}o.allocUnsafe=function(k){return l(k)},o.allocUnsafeSlow=function(k){return l(k)};function f(k,j){if((typeof j!="string"||j==="")&&(j="utf8"),!o.isEncoding(j))throw new TypeError("Unknown encoding: "+j);let K=E(k,j)|0,te=s(K),se=te.write(k,j);return se!==K&&(te=te.slice(0,se)),te}function h(k){let j=k.length<0?0:_(k.length)|0,K=s(j);for(let te=0;te<j;te+=1)K[te]=k[te]&255;return K}function p(k){if(Pe(k,Uint8Array)){let j=new Uint8Array(k);return m(j.buffer,j.byteOffset,j.byteLength)}return h(k)}function m(k,j,K){if(j<0||k.byteLength<j)throw new RangeError('"offset" is outside of buffer bounds');if(k.byteLength<j+(K||0))throw new RangeError('"length" is outside of buffer bounds');let te;return j===void 0&&K===void 0?te=new Uint8Array(k):K===void 0?te=new Uint8Array(k,j):te=new Uint8Array(k,j,K),Object.setPrototypeOf(te,o.prototype),te}function g(k){if(o.isBuffer(k)){let j=_(k.length)|0,K=s(j);return K.length===0||k.copy(K,0,0,j),K}if(k.length!==void 0)return typeof k.length!="number"||nt(k.length)?s(0):h(k);if(k.type==="Buffer"&&Array.isArray(k.data))return h(k.data)}function _(k){if(k>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return k|0}function v(k){return+k!=k&&(k=0),o.alloc(+k)}o.isBuffer=function(k){return k!=null&&k._isBuffer===!0&&k!==o.prototype},o.compare=function(k,j){if(Pe(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),Pe(j,Uint8Array)&&(j=o.from(j,j.offset,j.byteLength)),!o.isBuffer(k)||!o.isBuffer(j))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(k===j)return 0;let K=k.length,te=j.length;for(let se=0,he=Math.min(K,te);se<he;++se)if(k[se]!==j[se]){K=k[se],te=j[se];break}return K<te?-1:te<K?1:0},o.isEncoding=function(k){switch(String(k).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(k,j){if(!Array.isArray(k))throw new TypeError('"list" argument must be an Array of Buffers');if(k.length===0)return o.alloc(0);let K;if(j===void 0)for(j=0,K=0;K<k.length;++K)j+=k[K].length;let te=o.allocUnsafe(j),se=0;for(K=0;K<k.length;++K){let he=k[K];if(Pe(he,Uint8Array))se+he.length>te.length?(o.isBuffer(he)||(he=o.from(he)),he.copy(te,se)):Uint8Array.prototype.set.call(te,he,se);else if(o.isBuffer(he))he.copy(te,se);else throw new TypeError('"list" argument must be an Array of Buffers');se+=he.length}return te};function E(k,j){if(o.isBuffer(k))return k.length;if(ArrayBuffer.isView(k)||Pe(k,ArrayBuffer))return k.byteLength;if(typeof k!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof k);let K=k.length,te=arguments.length>2&&arguments[2]===!0;if(!te&&K===0)return 0;let se=!1;for(;;)switch(j){case"ascii":case"latin1":case"binary":return K;case"utf8":case"utf-8":return ge(k).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return K*2;case"hex":return K>>>1;case"base64":return We(k).length;default:if(se)return te?-1:ge(k).length;j=(""+j).toLowerCase(),se=!0}}o.byteLength=E;function T(k,j,K){let te=!1;if((j===void 0||j<0)&&(j=0),j>this.length||((K===void 0||K>this.length)&&(K=this.length),K<=0)||(K>>>=0,j>>>=0,K<=j))return"";for(k||(k="utf8");;)switch(k){case"hex":return S(this,j,K);case"utf8":case"utf-8":return I(this,j,K);case"ascii":return P(this,j,K);case"latin1":case"binary":return x(this,j,K);case"base64":return ee(this,j,K);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,j,K);default:if(te)throw new TypeError("Unknown encoding: "+k);k=(k+"").toLowerCase(),te=!0}}o.prototype._isBuffer=!0;function D(k,j,K){let te=k[j];k[j]=k[K],k[K]=te}o.prototype.swap16=function(){let k=this.length;if(k%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let j=0;j<k;j+=2)D(this,j,j+1);return this},o.prototype.swap32=function(){let k=this.length;if(k%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let j=0;j<k;j+=4)D(this,j,j+3),D(this,j+1,j+2);return this},o.prototype.swap64=function(){let k=this.length;if(k%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let j=0;j<k;j+=8)D(this,j,j+7),D(this,j+1,j+6),D(this,j+2,j+5),D(this,j+3,j+4);return this},o.prototype.toString=function(){let k=this.length;return k===0?"":arguments.length===0?I(this,0,k):T.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(k){if(!o.isBuffer(k))throw new TypeError("Argument must be a Buffer");return this===k?!0:o.compare(this,k)===0},o.prototype.inspect=function(){let k="",j=t.INSPECT_MAX_BYTES;return k=this.toString("hex",0,j).replace(/(.{2})/g,"$1 ").trim(),this.length>j&&(k+=" ... "),"<Buffer "+k+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(k,j,K,te,se){if(Pe(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),!o.isBuffer(k))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof k);if(j===void 0&&(j=0),K===void 0&&(K=k?k.length:0),te===void 0&&(te=0),se===void 0&&(se=this.length),j<0||K>k.length||te<0||se>this.length)throw new RangeError("out of range index");if(te>=se&&j>=K)return 0;if(te>=se)return-1;if(j>=K)return 1;if(j>>>=0,K>>>=0,te>>>=0,se>>>=0,this===k)return 0;let he=se-te,xe=K-j,Bt=Math.min(he,xe),Mn=this.slice(te,se),$r=k.slice(j,K);for(let fr=0;fr<Bt;++fr)if(Mn[fr]!==$r[fr]){he=Mn[fr],xe=$r[fr];break}return he<xe?-1:xe<he?1:0};function R(k,j,K,te,se){if(k.length===0)return-1;if(typeof K=="string"?(te=K,K=0):K>2147483647?K=2147483647:K<-2147483648&&(K=-2147483648),K=+K,nt(K)&&(K=se?0:k.length-1),K<0&&(K=k.length+K),K>=k.length){if(se)return-1;K=k.length-1}else if(K<0)if(se)K=0;else return-1;if(typeof j=="string"&&(j=o.from(j,te)),o.isBuffer(j))return j.length===0?-1:N(k,j,K,te,se);if(typeof j=="number")return j=j&255,typeof Uint8Array.prototype.indexOf=="function"?se?Uint8Array.prototype.indexOf.call(k,j,K):Uint8Array.prototype.lastIndexOf.call(k,j,K):N(k,[j],K,te,se);throw new TypeError("val must be string, number or Buffer")}function N(k,j,K,te,se){let he=1,xe=k.length,Bt=j.length;if(te!==void 0&&(te=String(te).toLowerCase(),te==="ucs2"||te==="ucs-2"||te==="utf16le"||te==="utf-16le")){if(k.length<2||j.length<2)return-1;he=2,xe/=2,Bt/=2,K/=2}function Mn(fr,nr){return he===1?fr[nr]:fr.readUInt16BE(nr*he)}let $r;if(se){let fr=-1;for($r=K;$r<xe;$r++)if(Mn(k,$r)===Mn(j,fr===-1?0:$r-fr)){if(fr===-1&&(fr=$r),$r-fr+1===Bt)return fr*he}else fr!==-1&&($r-=$r-fr),fr=-1}else for(K+Bt>xe&&(K=xe-Bt),$r=K;$r>=0;$r--){let fr=!0;for(let nr=0;nr<Bt;nr++)if(Mn(k,$r+nr)!==Mn(j,nr)){fr=!1;break}if(fr)return $r}return-1}o.prototype.includes=function(k,j,K){return this.indexOf(k,j,K)!==-1},o.prototype.indexOf=function(k,j,K){return R(this,k,j,K,!0)},o.prototype.lastIndexOf=function(k,j,K){return R(this,k,j,K,!1)};function B(k,j,K,te){K=Number(K)||0;let se=k.length-K;te?(te=Number(te),te>se&&(te=se)):te=se;let he=j.length;te>he/2&&(te=he/2);let xe;for(xe=0;xe<te;++xe){let Bt=parseInt(j.substr(xe*2,2),16);if(nt(Bt))return xe;k[K+xe]=Bt}return xe}function G(k,j,K,te){return Pt(ge(j,k.length-K),k,K,te)}function z(k,j,K,te){return Pt(Be(j),k,K,te)}function U(k,j,K,te){return Pt(We(j),k,K,te)}function H(k,j,K,te){return Pt(qe(j,k.length-K),k,K,te)}o.prototype.write=function(k,j,K,te){if(j===void 0)te="utf8",K=this.length,j=0;else if(K===void 0&&typeof j=="string")te=j,K=this.length,j=0;else if(isFinite(j))j=j>>>0,isFinite(K)?(K=K>>>0,te===void 0&&(te="utf8")):(te=K,K=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let se=this.length-j;if((K===void 0||K>se)&&(K=se),k.length>0&&(K<0||j<0)||j>this.length)throw new RangeError("Attempt to write outside buffer bounds");te||(te="utf8");let he=!1;for(;;)switch(te){case"hex":return B(this,k,j,K);case"utf8":case"utf-8":return G(this,k,j,K);case"ascii":case"latin1":case"binary":return z(this,k,j,K);case"base64":return U(this,k,j,K);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,k,j,K);default:if(he)throw new TypeError("Unknown encoding: "+te);te=(""+te).toLowerCase(),he=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ee(k,j,K){return j===0&&K===k.length?e.fromByteArray(k):e.fromByteArray(k.slice(j,K))}function I(k,j,K){K=Math.min(k.length,K);let te=[],se=j;for(;se<K;){let he=k[se],xe=null,Bt=he>239?4:he>223?3:he>191?2:1;if(se+Bt<=K){let Mn,$r,fr,nr;switch(Bt){case 1:he<128&&(xe=he);break;case 2:Mn=k[se+1],(Mn&192)===128&&(nr=(he&31)<<6|Mn&63,nr>127&&(xe=nr));break;case 3:Mn=k[se+1],$r=k[se+2],(Mn&192)===128&&($r&192)===128&&(nr=(he&15)<<12|(Mn&63)<<6|$r&63,nr>2047&&(nr<55296||nr>57343)&&(xe=nr));break;case 4:Mn=k[se+1],$r=k[se+2],fr=k[se+3],(Mn&192)===128&&($r&192)===128&&(fr&192)===128&&(nr=(he&15)<<18|(Mn&63)<<12|($r&63)<<6|fr&63,nr>65535&&nr<1114112&&(xe=nr))}}xe===null?(xe=65533,Bt=1):xe>65535&&(xe-=65536,te.push(xe>>>10&1023|55296),xe=56320|xe&1023),te.push(xe),se+=Bt}return b(te)}var O=4096;function b(k){let j=k.length;if(j<=O)return String.fromCharCode.apply(String,k);let K="",te=0;for(;te<j;)K+=String.fromCharCode.apply(String,k.slice(te,te+=O));return K}function P(k,j,K){let te="";K=Math.min(k.length,K);for(let se=j;se<K;++se)te+=String.fromCharCode(k[se]&127);return te}function x(k,j,K){let te="";K=Math.min(k.length,K);for(let se=j;se<K;++se)te+=String.fromCharCode(k[se]);return te}function S(k,j,K){let te=k.length;(!j||j<0)&&(j=0),(!K||K<0||K>te)&&(K=te);let se="";for(let he=j;he<K;++he)se+=wt[k[he]];return se}function A(k,j,K){let te=k.slice(j,K),se="";for(let he=0;he<te.length-1;he+=2)se+=String.fromCharCode(te[he]+te[he+1]*256);return se}o.prototype.slice=function(k,j){let K=this.length;k=~~k,j=j===void 0?K:~~j,k<0?(k+=K,k<0&&(k=0)):k>K&&(k=K),j<0?(j+=K,j<0&&(j=0)):j>K&&(j=K),j<k&&(j=k);let te=this.subarray(k,j);return Object.setPrototypeOf(te,o.prototype),te};function M(k,j,K){if(k%1!==0||k<0)throw new RangeError("offset is not uint");if(k+j>K)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k],se=1,he=0;for(;++he<j&&(se*=256);)te+=this[k+he]*se;return te},o.prototype.readUintBE=o.prototype.readUIntBE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k+--j],se=1;for(;j>0&&(se*=256);)te+=this[k+--j]*se;return te},o.prototype.readUint8=o.prototype.readUInt8=function(k,j){return k=k>>>0,j||M(k,1,this.length),this[k]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(k,j){return k=k>>>0,j||M(k,2,this.length),this[k]|this[k+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(k,j){return k=k>>>0,j||M(k,2,this.length),this[k]<<8|this[k+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(k,j){return k=k>>>0,j||M(k,4,this.length),(this[k]|this[k+1]<<8|this[k+2]<<16)+this[k+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]*16777216+(this[k+1]<<16|this[k+2]<<8|this[k+3])},o.prototype.readBigUInt64LE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=j+this[++k]*2**8+this[++k]*2**16+this[++k]*2**24,se=this[++k]+this[++k]*2**8+this[++k]*2**16+K*2**24;return BigInt(te)+(BigInt(se)<<BigInt(32))}),o.prototype.readBigUInt64BE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=j*2**24+this[++k]*2**16+this[++k]*2**8+this[++k],se=this[++k]*2**24+this[++k]*2**16+this[++k]*2**8+K;return(BigInt(te)<<BigInt(32))+BigInt(se)}),o.prototype.readIntLE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k],se=1,he=0;for(;++he<j&&(se*=256);)te+=this[k+he]*se;return se*=128,te>=se&&(te-=Math.pow(2,8*j)),te},o.prototype.readIntBE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=j,se=1,he=this[k+--te];for(;te>0&&(se*=256);)he+=this[k+--te]*se;return se*=128,he>=se&&(he-=Math.pow(2,8*j)),he},o.prototype.readInt8=function(k,j){return k=k>>>0,j||M(k,1,this.length),this[k]&128?(255-this[k]+1)*-1:this[k]},o.prototype.readInt16LE=function(k,j){k=k>>>0,j||M(k,2,this.length);let K=this[k]|this[k+1]<<8;return K&32768?K|4294901760:K},o.prototype.readInt16BE=function(k,j){k=k>>>0,j||M(k,2,this.length);let K=this[k+1]|this[k]<<8;return K&32768?K|4294901760:K},o.prototype.readInt32LE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]|this[k+1]<<8|this[k+2]<<16|this[k+3]<<24},o.prototype.readInt32BE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]<<24|this[k+1]<<16|this[k+2]<<8|this[k+3]},o.prototype.readBigInt64LE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=this[k+4]+this[k+5]*2**8+this[k+6]*2**16+(K<<24);return(BigInt(te)<<BigInt(32))+BigInt(j+this[++k]*2**8+this[++k]*2**16+this[++k]*2**24)}),o.prototype.readBigInt64BE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=(j<<24)+this[++k]*2**16+this[++k]*2**8+this[++k];return(BigInt(te)<<BigInt(32))+BigInt(this[++k]*2**24+this[++k]*2**16+this[++k]*2**8+K)}),o.prototype.readFloatLE=function(k,j){return k=k>>>0,j||M(k,4,this.length),r.read(this,k,!0,23,4)},o.prototype.readFloatBE=function(k,j){return k=k>>>0,j||M(k,4,this.length),r.read(this,k,!1,23,4)},o.prototype.readDoubleLE=function(k,j){return k=k>>>0,j||M(k,8,this.length),r.read(this,k,!0,52,8)},o.prototype.readDoubleBE=function(k,j){return k=k>>>0,j||M(k,8,this.length),r.read(this,k,!1,52,8)};function L(k,j,K,te,se,he){if(!o.isBuffer(k))throw new TypeError('"buffer" argument must be a Buffer instance');if(j>se||j<he)throw new RangeError('"value" argument is out of bounds');if(K+te>k.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(k,j,K,te){if(k=+k,j=j>>>0,K=K>>>0,!te){let xe=Math.pow(2,8*K)-1;L(this,k,j,K,xe,0)}let se=1,he=0;for(this[j]=k&255;++he<K&&(se*=256);)this[j+he]=k/se&255;return j+K},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(k,j,K,te){if(k=+k,j=j>>>0,K=K>>>0,!te){let xe=Math.pow(2,8*K)-1;L(this,k,j,K,xe,0)}let se=K-1,he=1;for(this[j+se]=k&255;--se>=0&&(he*=256);)this[j+se]=k/he&255;return j+K},o.prototype.writeUint8=o.prototype.writeUInt8=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,1,255,0),this[j]=k&255,j+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,65535,0),this[j]=k&255,this[j+1]=k>>>8,j+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,65535,0),this[j]=k>>>8,this[j+1]=k&255,j+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,4294967295,0),this[j+3]=k>>>24,this[j+2]=k>>>16,this[j+1]=k>>>8,this[j]=k&255,j+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,4294967295,0),this[j]=k>>>24,this[j+1]=k>>>16,this[j+2]=k>>>8,this[j+3]=k&255,j+4};function W(k,j,K,te,se){ce(j,te,se,k,K,7);let he=Number(j&BigInt(4294967295));k[K++]=he,he=he>>8,k[K++]=he,he=he>>8,k[K++]=he,he=he>>8,k[K++]=he;let xe=Number(j>>BigInt(32)&BigInt(4294967295));return k[K++]=xe,xe=xe>>8,k[K++]=xe,xe=xe>>8,k[K++]=xe,xe=xe>>8,k[K++]=xe,K}function V(k,j,K,te,se){ce(j,te,se,k,K,7);let he=Number(j&BigInt(4294967295));k[K+7]=he,he=he>>8,k[K+6]=he,he=he>>8,k[K+5]=he,he=he>>8,k[K+4]=he;let xe=Number(j>>BigInt(32)&BigInt(4294967295));return k[K+3]=xe,xe=xe>>8,k[K+2]=xe,xe=xe>>8,k[K+1]=xe,xe=xe>>8,k[K]=xe,K+8}o.prototype.writeBigUInt64LE=xt(function(k,j=0){return W(this,k,j,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=xt(function(k,j=0){return V(this,k,j,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(k,j,K,te){if(k=+k,j=j>>>0,!te){let Bt=Math.pow(2,8*K-1);L(this,k,j,K,Bt-1,-Bt)}let se=0,he=1,xe=0;for(this[j]=k&255;++se<K&&(he*=256);)k<0&&xe===0&&this[j+se-1]!==0&&(xe=1),this[j+se]=(k/he>>0)-xe&255;return j+K},o.prototype.writeIntBE=function(k,j,K,te){if(k=+k,j=j>>>0,!te){let Bt=Math.pow(2,8*K-1);L(this,k,j,K,Bt-1,-Bt)}let se=K-1,he=1,xe=0;for(this[j+se]=k&255;--se>=0&&(he*=256);)k<0&&xe===0&&this[j+se+1]!==0&&(xe=1),this[j+se]=(k/he>>0)-xe&255;return j+K},o.prototype.writeInt8=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,1,127,-128),k<0&&(k=255+k+1),this[j]=k&255,j+1},o.prototype.writeInt16LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,32767,-32768),this[j]=k&255,this[j+1]=k>>>8,j+2},o.prototype.writeInt16BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,32767,-32768),this[j]=k>>>8,this[j+1]=k&255,j+2},o.prototype.writeInt32LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,2147483647,-2147483648),this[j]=k&255,this[j+1]=k>>>8,this[j+2]=k>>>16,this[j+3]=k>>>24,j+4},o.prototype.writeInt32BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,2147483647,-2147483648),k<0&&(k=4294967295+k+1),this[j]=k>>>24,this[j+1]=k>>>16,this[j+2]=k>>>8,this[j+3]=k&255,j+4},o.prototype.writeBigInt64LE=xt(function(k,j=0){return W(this,k,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=xt(function(k,j=0){return V(this,k,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function J(k,j,K,te,se,he){if(K+te>k.length)throw new RangeError("Index out of range");if(K<0)throw new RangeError("Index out of range")}function Q(k,j,K,te,se){return j=+j,K=K>>>0,se||J(k,j,K,4,34028234663852886e22,-34028234663852886e22),r.write(k,j,K,te,23,4),K+4}o.prototype.writeFloatLE=function(k,j,K){return Q(this,k,j,!0,K)},o.prototype.writeFloatBE=function(k,j,K){return Q(this,k,j,!1,K)};function q(k,j,K,te,se){return j=+j,K=K>>>0,se||J(k,j,K,8,17976931348623157e292,-17976931348623157e292),r.write(k,j,K,te,52,8),K+8}o.prototype.writeDoubleLE=function(k,j,K){return q(this,k,j,!0,K)},o.prototype.writeDoubleBE=function(k,j,K){return q(this,k,j,!1,K)},o.prototype.copy=function(k,j,K,te){if(!o.isBuffer(k))throw new TypeError("argument should be a Buffer");if(K||(K=0),!te&&te!==0&&(te=this.length),j>=k.length&&(j=k.length),j||(j=0),te>0&&te<K&&(te=K),te===K||k.length===0||this.length===0)return 0;if(j<0)throw new RangeError("targetStart out of bounds");if(K<0||K>=this.length)throw new RangeError("Index out of range");if(te<0)throw new RangeError("sourceEnd out of bounds");te>this.length&&(te=this.length),k.length-j<te-K&&(te=k.length-j+K);let se=te-K;return this===k&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(j,K,te):Uint8Array.prototype.set.call(k,this.subarray(K,te),j),se},o.prototype.fill=function(k,j,K,te){if(typeof k=="string"){if(typeof j=="string"?(te=j,j=0,K=this.length):typeof K=="string"&&(te=K,K=this.length),te!==void 0&&typeof te!="string")throw new TypeError("encoding must be a string");if(typeof te=="string"&&!o.isEncoding(te))throw new TypeError("Unknown encoding: "+te);if(k.length===1){let he=k.charCodeAt(0);(te==="utf8"&&he<128||te==="latin1")&&(k=he)}}else typeof k=="number"?k=k&255:typeof k=="boolean"&&(k=Number(k));if(j<0||this.length<j||this.length<K)throw new RangeError("Out of range index");if(K<=j)return this;j=j>>>0,K=K===void 0?this.length:K>>>0,k||(k=0);let se;if(typeof k=="number")for(se=j;se<K;++se)this[se]=k;else{let he=o.isBuffer(k)?k:o.from(k,te),xe=he.length;if(xe===0)throw new TypeError('The value "'+k+'" is invalid for argument "value"');for(se=0;se<K-j;++se)this[se+j]=he[se%xe]}return this};var X={};function ne(k,j,K){X[k]=class extends K{constructor(){super(),Object.defineProperty(this,"message",{value:j.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${k}]`,this.stack,delete this.name}get code(){return k}set code(te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:te,writable:!0})}toString(){return`${this.name} [${k}]: ${this.message}`}}}ne("ERR_BUFFER_OUT_OF_BOUNDS",function(k){return k?`${k} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ne("ERR_INVALID_ARG_TYPE",function(k,j){return`The "${k}" argument must be of type number. Received type ${typeof j}`},TypeError),ne("ERR_OUT_OF_RANGE",function(k,j,K){let te=`The value of "${k}" is out of range.`,se=K;return Number.isInteger(K)&&Math.abs(K)>2**32?se=re(String(K)):typeof K=="bigint"&&(se=String(K),(K>BigInt(2)**BigInt(32)||K<-(BigInt(2)**BigInt(32)))&&(se=re(se)),se+="n"),te+=` It must be ${j}. Received ${se}`,te},RangeError);function re(k){let j="",K=k.length,te=k[0]==="-"?1:0;for(;K>=te+4;K-=3)j=`_${k.slice(K-3,K)}${j}`;return`${k.slice(0,K)}${j}`}function Y(k,j,K){de(j,"offset"),(k[j]===void 0||k[j+K]===void 0)&&pe(j,k.length-(K+1))}function ce(k,j,K,te,se,he){if(k>K||k<j){let xe=typeof j=="bigint"?"n":"",Bt;throw he>3?j===0||j===BigInt(0)?Bt=`>= 0${xe} and < 2${xe} ** ${(he+1)*8}${xe}`:Bt=`>= -(2${xe} ** ${(he+1)*8-1}${xe}) and < 2 ** ${(he+1)*8-1}${xe}`:Bt=`>= ${j}${xe} and <= ${K}${xe}`,new X.ERR_OUT_OF_RANGE("value",Bt,k)}Y(te,se,he)}function de(k,j){if(typeof k!="number")throw new X.ERR_INVALID_ARG_TYPE(j,"number",k)}function pe(k,j,K){throw Math.floor(k)!==k?(de(k,K),new X.ERR_OUT_OF_RANGE(K||"offset","an integer",k)):j<0?new X.ERR_BUFFER_OUT_OF_BOUNDS:new X.ERR_OUT_OF_RANGE(K||"offset",`>= ${K?1:0} and <= ${j}`,k)}var we=/[^+/0-9A-Za-z-_]/g;function ae(k){if(k=k.split("=")[0],k=k.trim().replace(we,""),k.length<2)return"";for(;k.length%4!==0;)k=k+"=";return k}function ge(k,j){j=j||1/0;let K,te=k.length,se=null,he=[];for(let xe=0;xe<te;++xe){if(K=k.charCodeAt(xe),K>55295&&K<57344){if(!se){if(K>56319){(j-=3)>-1&&he.push(239,191,189);continue}else if(xe+1===te){(j-=3)>-1&&he.push(239,191,189);continue}se=K;continue}if(K<56320){(j-=3)>-1&&he.push(239,191,189),se=K;continue}K=(se-55296<<10|K-56320)+65536}else se&&(j-=3)>-1&&he.push(239,191,189);if(se=null,K<128){if((j-=1)<0)break;he.push(K)}else if(K<2048){if((j-=2)<0)break;he.push(K>>6|192,K&63|128)}else if(K<65536){if((j-=3)<0)break;he.push(K>>12|224,K>>6&63|128,K&63|128)}else if(K<1114112){if((j-=4)<0)break;he.push(K>>18|240,K>>12&63|128,K>>6&63|128,K&63|128)}else throw new Error("Invalid code point")}return he}function Be(k){let j=[];for(let K=0;K<k.length;++K)j.push(k.charCodeAt(K)&255);return j}function qe(k,j){let K,te,se,he=[];for(let xe=0;xe<k.length&&!((j-=2)<0);++xe)K=k.charCodeAt(xe),te=K>>8,se=K%256,he.push(se),he.push(te);return he}function We(k){return e.toByteArray(ae(k))}function Pt(k,j,K,te){let se;for(se=0;se<te&&!(se+K>=j.length||se>=k.length);++se)j[se+K]=k[se];return se}function Pe(k,j){return k instanceof j||k!=null&&k.constructor!=null&&k.constructor.name!=null&&k.constructor.name===j.name}function nt(k){return k!==k}var wt=function(){let k="0123456789abcdef",j=new Array(256);for(let K=0;K<16;++K){let te=K*16;for(let se=0;se<16;++se)j[te+se]=k[K]+k[se]}return j}();function xt(k){return typeof BigInt>"u"?Ot:k}function Ot(){throw new Error("BigInt not supported")}}),uq=Ft((t,e)=>{"use strict";var r=null;e.exports=function(){return r===null&&(r={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),r}}),lq=Ft(t=>{"use strict";var e=Rc(),r=new Set(["buffer","view","utf8"]),n=class{constructor(i){if(this.encode=i.encode||this.encode,this.decode=i.decode||this.decode,this.name=i.name||this.name,this.format=i.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!r.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");i.createViewTranscoder&&(this.createViewTranscoder=i.createViewTranscoder),i.createBufferTranscoder&&(this.createBufferTranscoder=i.createBufferTranscoder),i.createUTF8Transcoder&&(this.createUTF8Transcoder=i.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};t.Encoding=n}),fq=Ft(t=>{"use strict";var{Buffer:e}=zD()||{},{Encoding:r}=lq(),n=uq(),i=class extends r{constructor(o){super({...o,format:"buffer"})}createViewTranscoder(){return new a({encode:this.encode,decode:o=>this.decode(e.from(o.buffer,o.byteOffset,o.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},a=class extends r{constructor(o){super({...o,format:"view"})}createBufferTranscoder(){return new i({encode:o=>{let d=this.encode(o);return e.from(d.buffer,d.byteOffset,d.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},s=class extends r{constructor(o){super({...o,format:"utf8"})}createBufferTranscoder(){return new i({encode:o=>e.from(this.encode(o),"utf8"),decode:o=>this.decode(o.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:o,textDecoder:d}=n();return new a({encode:u=>o.encode(this.encode(u)),decode:u=>this.decode(d.decode(u)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};t.BufferFormat=i,t.ViewFormat=a,t.UTF8Format=s}),Eoe=Ft(t=>{"use strict";var{Buffer:e}=zD()||{Buffer:{isBuffer:()=>!1}},{textEncoder:r,textDecoder:n}=uq()(),{BufferFormat:i,ViewFormat:a,UTF8Format:s}=fq(),o=d=>d;t.utf8=new s({encode:function(d){return e.isBuffer(d)?d.toString("utf8"):ArrayBuffer.isView(d)?n.decode(d):String(d)},decode:o,name:"utf8",createViewTranscoder(){return new a({encode:function(d){return ArrayBuffer.isView(d)?d:r.encode(d)},decode:function(d){return n.decode(d)},name:`${this.name}+view`})},createBufferTranscoder(){return new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:function(d){return d.toString("utf8")},name:`${this.name}+buffer`})}}),t.json=new s({encode:JSON.stringify,decode:JSON.parse,name:"json"}),t.buffer=new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:o,name:"buffer",createViewTranscoder(){return new a({encode:function(d){return ArrayBuffer.isView(d)?d:e.from(String(d),"utf8")},decode:function(d){return e.from(d.buffer,d.byteOffset,d.byteLength)},name:`${this.name}+view`})}}),t.view=new a({encode:function(d){return ArrayBuffer.isView(d)?d:r.encode(d)},decode:o,name:"view",createBufferTranscoder(){return new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:o,name:`${this.name}+buffer`})}}),t.hex=new i({encode:function(d){return e.isBuffer(d)?d:e.from(String(d),"hex")},decode:function(d){return d.toString("hex")},name:"hex"}),t.base64=new i({encode:function(d){return e.isBuffer(d)?d:e.from(String(d),"base64")},decode:function(d){return d.toString("base64")},name:"base64"})}),Soe=Ft(t=>{"use strict";var e=Rc(),r=Eoe(),{Encoding:n}=lq(),{BufferFormat:i,ViewFormat:a,UTF8Format:s}=fq(),o=Symbol("formats"),d=Symbol("encodings"),u=new Set(["buffer","view","utf8"]),c=class{constructor(g){if(Array.isArray(g)){if(!g.every(_=>u.has(_)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[d]=new Map,this[o]=new Set(g);for(let _ in r)try{this.encoding(_)}catch(v){if(v.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw v}}encodings(){return Array.from(new Set(this[d].values()))}encoding(g){let _=this[d].get(g);if(_===void 0){if(typeof g=="string"&&g!==""){if(_=p[g],!_)throw new e(`Encoding '${g}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof g!="object"||g===null)throw new TypeError("First argument 'encoding' must be a string or object");_=l(g)}let{name:v,format:E}=_;if(!this[o].has(E))if(this[o].has("view"))_=_.createViewTranscoder();else if(this[o].has("buffer"))_=_.createBufferTranscoder();else if(this[o].has("utf8"))_=_.createUTF8Transcoder();else throw new e(`Encoding '${v}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let T of[g,v,_.name,_.commonName])this[d].set(T,_)}return _}};t.Transcoder=c;function l(g){if(g instanceof n)return g;let _="type"in g&&typeof g.type=="string"?g.type:void 0,v=g.name||_||`anonymous-${m++}`;switch(f(g)){case"view":return new a({...g,name:v});case"utf8":return new s({...g,name:v});case"buffer":return new i({...g,name:v});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function f(g){return"format"in g&&g.format!==void 0?g.format:"buffer"in g&&typeof g.buffer=="boolean"?g.buffer?"buffer":"utf8":"code"in g&&Number.isInteger(g.code)?"view":"buffer"}var h={binary:r.buffer,"utf-8":r.utf8},p={...r,...h},m=0}),Toe=Ft((t,e)=>{"use strict";var r=Object.prototype.hasOwnProperty,n="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(n=!1));function a(u,c,l){this.fn=u,this.context=c,this.once=l||!1}function s(u,c,l,f,h){if(typeof l!="function")throw new TypeError("The listener must be a function");var p=new a(l,f||u,h),m=n?n+c:c;return u._events[m]?u._events[m].fn?u._events[m]=[u._events[m],p]:u._events[m].push(p):(u._events[m]=p,u._eventsCount++),u}function o(u,c){--u._eventsCount===0?u._events=new i:delete u._events[c]}function d(){this._events=new i,this._eventsCount=0}d.prototype.eventNames=function(){var u=[],c,l;if(this._eventsCount===0)return u;for(l in c=this._events)r.call(c,l)&&u.push(n?l.slice(1):l);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(c)):u},d.prototype.listeners=function(u){var c=n?n+u:u,l=this._events[c];if(!l)return[];if(l.fn)return[l.fn];for(var f=0,h=l.length,p=new Array(h);f<h;f++)p[f]=l[f].fn;return p},d.prototype.listenerCount=function(u){var c=n?n+u:u,l=this._events[c];return l?l.fn?1:l.length:0},d.prototype.emit=function(u,c,l,f,h,p){var m=n?n+u:u;if(!this._events[m])return!1;var g=this._events[m],_=arguments.length,v,E;if(g.fn){switch(g.once&&this.removeListener(u,g.fn,void 0,!0),_){case 1:return g.fn.call(g.context),!0;case 2:return g.fn.call(g.context,c),!0;case 3:return g.fn.call(g.context,c,l),!0;case 4:return g.fn.call(g.context,c,l,f),!0;case 5:return g.fn.call(g.context,c,l,f,h),!0;case 6:return g.fn.call(g.context,c,l,f,h,p),!0}for(E=1,v=new Array(_-1);E<_;E++)v[E-1]=arguments[E];g.fn.apply(g.context,v)}else{var T=g.length,D;for(E=0;E<T;E++)switch(g[E].once&&this.removeListener(u,g[E].fn,void 0,!0),_){case 1:g[E].fn.call(g[E].context);break;case 2:g[E].fn.call(g[E].context,c);break;case 3:g[E].fn.call(g[E].context,c,l);break;case 4:g[E].fn.call(g[E].context,c,l,f);break;default:if(!v)for(D=1,v=new Array(_-1);D<_;D++)v[D-1]=arguments[D];g[E].fn.apply(g[E].context,v)}}return!0},d.prototype.on=function(u,c,l){return s(this,u,c,l,!1)},d.prototype.once=function(u,c,l){return s(this,u,c,l,!0)},d.prototype.removeListener=function(u,c,l,f){var h=n?n+u:u;if(!this._events[h])return this;if(!c)return o(this,h),this;var p=this._events[h];if(p.fn)p.fn===c&&(!f||p.once)&&(!l||p.context===l)&&o(this,h);else{for(var m=0,g=[],_=p.length;m<_;m++)(p[m].fn!==c||f&&!p[m].once||l&&p[m].context!==l)&&g.push(p[m]);g.length?this._events[h]=g.length===1?g[0]:g:o(this,h)}return this},d.prototype.removeAllListeners=function(u){var c;return u?(c=n?n+u:u,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},d.prototype.off=d.prototype.removeListener,d.prototype.addListener=d.prototype.on,d.prefixed=n,d.EventEmitter=d,typeof e<"u"&&(e.exports=d)}),koe=Ft((t,e)=>{e.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)}),Tx=Ft(t=>{"use strict";var e=koe();t.fromCallback=function(r,n){if(r===void 0){var i=new Promise(function(a,s){r=function(o,d){o?s(o):a(d)}});r[n!==void 0?n:"promise"]=i}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r},t.fromPromise=function(r,n){if(n===void 0)return r;r.then(function(i){e(()=>n(null,i))}).catch(function(i){e(()=>n(i))})}}),FD=Ft(t=>{"use strict";t.getCallback=function(e,r){return typeof e=="function"?e:r},t.getOptions=function(e,r){return typeof e=="object"&&e!==null?e:r!==void 0?r:{}}}),Bf=Ft(t=>{"use strict";var{fromCallback:e}=Tx(),r=Rc(),{getOptions:n,getCallback:i}=FD(),a=Symbol("promise"),s=Symbol("callback"),o=Symbol("working"),d=Symbol("handleOne"),u=Symbol("handleMany"),c=Symbol("autoClose"),l=Symbol("finishWork"),f=Symbol("returnMany"),h=Symbol("closing"),p=Symbol("handleClose"),m=Symbol("closed"),g=Symbol("closeCallbacks"),_=Symbol("keyEncoding"),v=Symbol("valueEncoding"),E=Symbol("abortOnClose"),T=Symbol("legacy"),D=Symbol("keys"),R=Symbol("values"),N=Symbol("limit"),B=Symbol("count"),G=Object.freeze({}),z=()=>{},U=!1,H=class{constructor(P,x,S){if(typeof P!="object"||P===null){let A=P===null?"null":typeof P;throw new TypeError(`The first argument must be an abstract-level database, received ${A}`)}if(typeof x!="object"||x===null)throw new TypeError("The second argument must be an options object");this[m]=!1,this[g]=[],this[o]=!1,this[h]=!1,this[c]=!1,this[s]=null,this[d]=this[d].bind(this),this[u]=this[u].bind(this),this[p]=this[p].bind(this),this[_]=x[_],this[v]=x[v],this[T]=S,this[N]=Number.isInteger(x.limit)&&x.limit>=0?x.limit:1/0,this[B]=0,this[E]=!!x.abortOnClose,this.db=P,this.db.attachResource(this),this.nextTick=P.nextTick}get count(){return this[B]}get limit(){return this[N]}next(P){let x;if(P===void 0)x=new Promise((S,A)=>{P=(M,L,W)=>{M?A(M):this[T]?L===void 0&&W===void 0?S():S([L,W]):S(L)}});else if(typeof P!="function")throw new TypeError("Callback must be a function");return this[h]?this.nextTick(P,new r("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(P,new r("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[o]=!0,this[s]=P,this[B]>=this[N]?this.nextTick(this[d],null):this._next(this[d])),x}_next(P){this.nextTick(P)}nextv(P,x,S){return S=i(x,S),S=e(S,a),x=n(x,G),Number.isInteger(P)?(this[h]?this.nextTick(S,new r("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(S,new r("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(P<1&&(P=1),this[N]<1/0&&(P=Math.min(P,this[N]-this[B])),this[o]=!0,this[s]=S,P<=0?this.nextTick(this[u],null,[]):this._nextv(P,x,this[u])),S[a]):(this.nextTick(S,new TypeError("The first argument 'size' must be an integer")),S[a])}_nextv(P,x,S){let A=[],M=(L,W,V)=>{if(L)return S(L);if(this[T]?W===void 0&&V===void 0:W===void 0)return S(null,A);A.push(this[T]?[W,V]:W),A.length===P?S(null,A):this._next(M)};this._next(M)}all(P,x){return x=i(P,x),x=e(x,a),P=n(P,G),this[h]?this.nextTick(x,new r("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(x,new r("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[o]=!0,this[s]=x,this[c]=!0,this[B]>=this[N]?this.nextTick(this[u],null,[]):this._all(P,this[u])),x[a]}_all(P,x){let S=this[B],A=[],M=()=>{let W=this[N]<1/0?Math.min(1e3,this[N]-S):1e3;W<=0?this.nextTick(x,null,A):this._nextv(W,G,L)},L=(W,V)=>{W?x(W):V.length===0?x(null,A):(A.push.apply(A,V),S+=V.length,M())};M()}[l](){let P=this[s];return this[E]&&P===null?z:(this[o]=!1,this[s]=null,this[h]&&this._close(this[p]),P)}[f](P,x,S){this[c]?this.close(P.bind(null,x,S)):P(x,S)}seek(P,x){if(x=n(x,G),!this[h]){if(this[o])throw new r("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let S=this.db.keyEncoding(x.keyEncoding||this[_]),A=S.format;x.keyEncoding!==A&&(x={...x,keyEncoding:A});let M=this.db.prefixKey(S.encode(P),A);this._seek(M,x)}}}_seek(P,x){throw new r("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(P){return P=e(P,a),this[m]?this.nextTick(P):this[h]?this[g].push(P):(this[h]=!0,this[g].push(P),this[o]?this[E]&&this[l]()(new r("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[p])),P[a]}_close(P){this.nextTick(P)}[p](){this[m]=!0,this.db.detachResource(this);let P=this[g];this[g]=[];for(let x of P)x()}async*[Symbol.asyncIterator](){try{let P;for(;(P=await this.next())!==void 0;)yield P}finally{this[m]||await this.close()}}},ee=class extends H{constructor(P,x){super(P,x,!0),this[D]=x.keys!==!1,this[R]=x.values!==!1}[d](P,x,S){let A=this[l]();if(P)return A(P);try{x=this[D]&&x!==void 0?this[_].decode(x):void 0,S=this[R]&&S!==void 0?this[v].decode(S):void 0}catch(M){return A(new b("entry",M))}x===void 0&&S===void 0||this[B]++,A(null,x,S)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A of x){let M=A[0],L=A[1];A[0]=this[D]&&M!==void 0?this[_].decode(M):void 0,A[1]=this[R]&&L!==void 0?this[v].decode(L):void 0}}catch(A){return this[f](S,new b("entries",A))}this[B]+=x.length,this[f](S,null,x)}end(P){return!U&&typeof console<"u"&&(U=!0,console.warn(new r("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(P)}},I=class extends H{constructor(P,x){super(P,x,!1)}[d](P,x){let S=this[l]();if(P)return S(P);try{x=x!==void 0?this[_].decode(x):void 0}catch(A){return S(new b("key",A))}x!==void 0&&this[B]++,S(null,x)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A=0;A<x.length;A++){let M=x[A];x[A]=M!==void 0?this[_].decode(M):void 0}}catch(A){return this[f](S,new b("keys",A))}this[B]+=x.length,this[f](S,null,x)}},O=class extends H{constructor(P,x){super(P,x,!1)}[d](P,x){let S=this[l]();if(P)return S(P);try{x=x!==void 0?this[v].decode(x):void 0}catch(A){return S(new b("value",A))}x!==void 0&&this[B]++,S(null,x)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A=0;A<x.length;A++){let M=x[A];x[A]=M!==void 0?this[v].decode(M):void 0}}catch(A){return this[f](S,new b("values",A))}this[B]+=x.length,this[f](S,null,x)}},b=class extends r{constructor(P,x){super(`Iterator could not decode ${P}`,{code:"LEVEL_DECODE_ERROR",cause:x})}};for(let P of["_ended property","_nexting property","_end method"])Object.defineProperty(ee.prototype,P.split(" ")[0],{get(){throw new r(`The ${P} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new r(`The ${P} has been removed`,{code:"LEVEL_LEGACY"})}});ee.keyEncoding=_,ee.valueEncoding=v,t.AbstractIterator=ee,t.AbstractKeyIterator=I,t.AbstractValueIterator=O}),Aoe=Ft(t=>{"use strict";var{AbstractKeyIterator:e,AbstractValueIterator:r}=Bf(),n=Symbol("iterator"),i=Symbol("callback"),a=Symbol("handleOne"),s=Symbol("handleMany"),o=class extends e{constructor(u,c){super(u,c),this[n]=u.iterator({...c,keys:!0,values:!1}),this[a]=this[a].bind(this),this[s]=this[s].bind(this)}},d=class extends r{constructor(u,c){super(u,c),this[n]=u.iterator({...c,keys:!1,values:!0}),this[a]=this[a].bind(this),this[s]=this[s].bind(this)}};for(let u of[o,d]){let c=u===o,l=c?f=>f[0]:f=>f[1];u.prototype._next=function(f){this[i]=f,this[n].next(this[a])},u.prototype[a]=function(f,h,p){let m=this[i];f?m(f):m(null,c?h:p)},u.prototype._nextv=function(f,h,p){this[i]=p,this[n].nextv(f,h,this[s])},u.prototype._all=function(f,h){this[i]=h,this[n].all(f,this[s])},u.prototype[s]=function(f,h){let p=this[i];f?p(f):p(null,h.map(l))},u.prototype._seek=function(f,h){this[n].seek(f,h)},u.prototype._close=function(f){this[n].close(f)}}t.DefaultKeyIterator=o,t.DefaultValueIterator=d}),Doe=Ft(t=>{"use strict";var{AbstractIterator:e,AbstractKeyIterator:r,AbstractValueIterator:n}=Bf(),i=Rc(),a=Symbol("nut"),s=Symbol("undefer"),o=Symbol("factory"),d=class extends e{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.iterator(f),this.db.defer(()=>this[s]())}},u=class extends r{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.keys(f),this.db.defer(()=>this[s]())}},c=class extends n{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.values(f),this.db.defer(()=>this[s]())}};for(let l of[d,u,c])l.prototype[s]=function(){this.db.status==="open"&&(this[a]=this[o]())},l.prototype._next=function(f){this[a]!==null?this[a].next(f):this.db.status==="opening"?this.db.defer(()=>this._next(f)):this.nextTick(f,new i("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._nextv=function(f,h,p){this[a]!==null?this[a].nextv(f,h,p):this.db.status==="opening"?this.db.defer(()=>this._nextv(f,h,p)):this.nextTick(p,new i("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._all=function(f,h){this[a]!==null?this[a].all(h):this.db.status==="opening"?this.db.defer(()=>this._all(f,h)):this.nextTick(h,new i("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._seek=function(f,h){this[a]!==null?this[a]._seek(f,h):this.db.status==="opening"&&this.db.defer(()=>this._seek(f,h))},l.prototype._close=function(f){this[a]!==null?this[a].close(f):this.db.status==="opening"?this.db.defer(()=>this._close(f)):this.nextTick(f)};t.DeferredIterator=d,t.DeferredKeyIterator=u,t.DeferredValueIterator=c}),pq=Ft(t=>{"use strict";var{fromCallback:e}=Tx(),r=Rc(),{getCallback:n,getOptions:i}=FD(),a=Symbol("promise"),s=Symbol("status"),o=Symbol("operations"),d=Symbol("finishClose"),u=Symbol("closeCallbacks"),c=class{constructor(l){if(typeof l!="object"||l===null){let f=l===null?"null":typeof l;throw new TypeError(`The first argument must be an abstract-level database, received ${f}`)}this[o]=[],this[u]=[],this[s]="open",this[d]=this[d].bind(this),this.db=l,this.db.attachResource(this),this.nextTick=l.nextTick}get length(){return this[o].length}put(l,f,h){if(this[s]!=="open")throw new r("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let p=this.db._checkKey(l)||this.db._checkValue(f);if(p)throw p;let m=h&&h.sublevel!=null?h.sublevel:this.db,g=h,_=m.keyEncoding(h&&h.keyEncoding),v=m.valueEncoding(h&&h.valueEncoding),E=_.format;h={...h,keyEncoding:E,valueEncoding:v.format},m!==this.db&&(h.sublevel=null);let T=m.prefixKey(_.encode(l),E),D=v.encode(f);return this._put(T,D,h),this[o].push({...g,type:"put",key:l,value:f}),this}_put(l,f,h){}del(l,f){if(this[s]!=="open")throw new r("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let h=this.db._checkKey(l);if(h)throw h;let p=f&&f.sublevel!=null?f.sublevel:this.db,m=f,g=p.keyEncoding(f&&f.keyEncoding),_=g.format;return f={...f,keyEncoding:_},p!==this.db&&(f.sublevel=null),this._del(p.prefixKey(g.encode(l),_),f),this[o].push({...m,type:"del",key:l}),this}_del(l,f){}clear(){if(this[s]!=="open")throw new r("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[o]=[],this}_clear(){}write(l,f){return f=n(l,f),f=e(f,a),l=i(l),this[s]!=="open"?this.nextTick(f,new r("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(f):(this[s]="writing",this._write(l,h=>{this[s]="closing",this[u].push(()=>f(h)),h||this.db.emit("batch",this[o]),this._close(this[d])})),f[a]}_write(l,f){}close(l){return l=e(l,a),this[s]==="closing"?this[u].push(l):this[s]==="closed"?this.nextTick(l):(this[u].push(l),this[s]!=="writing"&&(this[s]="closing",this._close(this[d]))),l[a]}_close(l){this.nextTick(l)}[d](){this[s]="closed",this.db.detachResource(this);let l=this[u];this[u]=[];for(let f of l)f()}};t.AbstractChainedBatch=c}),Ioe=Ft(t=>{"use strict";var{AbstractChainedBatch:e}=pq(),r=Rc(),n=Symbol("encoded"),i=class extends e{constructor(a){super(a),this[n]=[]}_put(a,s,o){this[n].push({...o,type:"put",key:a,value:s})}_del(a,s){this[n].push({...s,type:"del",key:a})}_clear(){this[n]=[]}_write(a,s){this.db.status==="opening"?this.db.defer(()=>this._write(a,s)):this.db.status==="open"?this[n].length===0?this.nextTick(s):this.db._batch(this[n],a,s):this.nextTick(s,new r("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};t.DefaultChainedBatch=i}),Roe=Ft((t,e)=>{"use strict";var r=Rc(),n=Object.prototype.hasOwnProperty,i=new Set(["lt","lte","gt","gte"]);e.exports=function(a,s){let o={};for(let d in a)if(n.call(a,d)&&!(d==="keyEncoding"||d==="valueEncoding")){if(d==="start"||d==="end")throw new r(`The legacy range option '${d}' has been removed`,{code:"LEVEL_LEGACY"});if(d==="encoding")throw new r("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});i.has(d)?o[d]=s.encode(a[d]):o[d]=a[d]}return o.reverse=!!o.reverse,o.limit=Number.isInteger(o.limit)&&o.limit>=0?o.limit:-1,o}}),hq=Ft((t,e)=>{var r;e.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):n=>(r||(r=Promise.resolve())).then(n).catch(i=>setTimeout(()=>{throw i},0))}),Coe=Ft((t,e)=>{"use strict";var r=hq();e.exports=function(n,...i){i.length===0?r(n):r(()=>n(...i))}}),$oe=Ft(t=>{"use strict";var{AbstractIterator:e,AbstractKeyIterator:r,AbstractValueIterator:n}=Bf(),i=Symbol("unfix"),a=Symbol("iterator"),s=Symbol("handleOne"),o=Symbol("handleMany"),d=Symbol("callback"),u=class extends e{constructor(f,h,p,m){super(f,h),this[a]=p,this[i]=m,this[s]=this[s].bind(this),this[o]=this[o].bind(this),this[d]=null}[s](f,h,p){let m=this[d];if(f)return m(f);h!==void 0&&(h=this[i](h)),m(f,h,p)}[o](f,h){let p=this[d];if(f)return p(f);for(let m of h){let g=m[0];g!==void 0&&(m[0]=this[i](g))}p(f,h)}},c=class extends r{constructor(f,h,p,m){super(f,h),this[a]=p,this[i]=m,this[s]=this[s].bind(this),this[o]=this[o].bind(this),this[d]=null}[s](f,h){let p=this[d];if(f)return p(f);h!==void 0&&(h=this[i](h)),p(f,h)}[o](f,h){let p=this[d];if(f)return p(f);for(let m=0;m<h.length;m++){let g=h[m];g!==void 0&&(h[m]=this[i](g))}p(f,h)}},l=class extends n{constructor(f,h,p){super(f,h),this[a]=p}};for(let f of[u,c])f.prototype._next=function(h){this[d]=h,this[a].next(this[s])},f.prototype._nextv=function(h,p,m){this[d]=m,this[a].nextv(h,p,this[o])},f.prototype._all=function(h,p){this[d]=p,this[a].all(h,this[o])};for(let f of[l])f.prototype._next=function(h){this[a].next(h)},f.prototype._nextv=function(h,p,m){this[a].nextv(h,p,m)},f.prototype._all=function(h,p){this[a].all(h,p)};for(let f of[u,c,l])f.prototype._seek=function(h,p){this[a].seek(h,p)},f.prototype._close=function(h){this[a].close(h)};t.AbstractSublevelIterator=u,t.AbstractSublevelKeyIterator=c,t.AbstractSublevelValueIterator=l}),Ooe=Ft((t,e)=>{"use strict";var r=Rc(),{Buffer:n}=zD()||{},{AbstractSublevelIterator:i,AbstractSublevelKeyIterator:a,AbstractSublevelValueIterator:s}=$oe(),o=Symbol("prefix"),d=Symbol("upperBound"),u=Symbol("prefixRange"),c=Symbol("parent"),l=Symbol("unfix"),f=new TextEncoder,h={separator:"!"};e.exports=function({AbstractLevel:E}){class T extends E{static defaults(R){if(typeof R=="string")throw new r("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(R&&R.open)throw new r("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return R==null?h:R.separator?R:{...R,separator:"!"}}constructor(R,N,B){let{separator:G,manifest:z,...U}=T.defaults(B);N=v(N,G);let H=G.charCodeAt(0)+1,ee=R[c]||R;if(!f.encode(N).every(b=>b>H&&b<127))throw new r(`Prefix must use bytes > ${H} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(p(ee,z),U);let I=(R.prefix||"")+G+N+G,O=I.slice(0,-1)+String.fromCharCode(H);this[c]=ee,this[o]=new g(I),this[d]=new g(O),this[l]=new _,this.nextTick=ee.nextTick}prefixKey(R,N){if(N==="utf8")return this[o].utf8+R;if(R.byteLength===0)return this[o][N];if(N==="view"){let B=this[o].view,G=new Uint8Array(B.byteLength+R.byteLength);return G.set(B,0),G.set(R,B.byteLength),G}else{let B=this[o].buffer;return n.concat([B,R],B.byteLength+R.byteLength)}}[u](R,N){R.gte!==void 0?R.gte=this.prefixKey(R.gte,N):R.gt!==void 0?R.gt=this.prefixKey(R.gt,N):R.gte=this[o][N],R.lte!==void 0?R.lte=this.prefixKey(R.lte,N):R.lt!==void 0?R.lt=this.prefixKey(R.lt,N):R.lte=this[d][N]}get prefix(){return this[o].utf8}get db(){return this[c]}_open(R,N){this[c].open({passive:!0},N)}_put(R,N,B,G){this[c].put(R,N,B,G)}_get(R,N,B){this[c].get(R,N,B)}_getMany(R,N,B){this[c].getMany(R,N,B)}_del(R,N,B){this[c].del(R,N,B)}_batch(R,N,B){this[c].batch(R,N,B)}_clear(R,N){this[u](R,R.keyEncoding),this[c].clear(R,N)}_iterator(R){this[u](R,R.keyEncoding);let N=this[c].iterator(R),B=this[l].get(this[o].utf8.length,R.keyEncoding);return new i(this,R,N,B)}_keys(R){this[u](R,R.keyEncoding);let N=this[c].keys(R),B=this[l].get(this[o].utf8.length,R.keyEncoding);return new a(this,R,N,B)}_values(R){this[u](R,R.keyEncoding);let N=this[c].values(R);return new s(this,R,N)}}return{AbstractSublevel:T}};var p=function(E,T){return{...E.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...T,encodings:{utf8:m(E,"utf8"),buffer:m(E,"buffer"),view:m(E,"view")}}},m=function(E,T){return E.supports.encodings[T]?E.keyEncoding(T).name===T:!1},g=class{constructor(E){this.utf8=E,this.view=f.encode(E),this.buffer=n?n.from(this.view.buffer,0,this.view.byteLength):{}}},_=class{constructor(){this.cache=new Map}get(E,T){let D=this.cache.get(T);return D===void 0&&(T==="view"?D=(function(R,N){return N.subarray(R)}).bind(null,E):D=(function(R,N){return N.slice(R)}).bind(null,E),this.cache.set(T,D)),D}},v=function(E,T){let D=0,R=E.length;for(;D<R&&E[D]===T;)D++;for(;R>D&&E[R-1]===T;)R--;return E.slice(D,R)}}),HU=Ft(t=>{"use strict";var{supports:e}=xoe(),{Transcoder:r}=Soe(),{EventEmitter:n}=Toe(),{fromCallback:i}=Tx(),a=Rc(),{AbstractIterator:s}=Bf(),{DefaultKeyIterator:o,DefaultValueIterator:d}=Aoe(),{DeferredIterator:u,DeferredKeyIterator:c,DeferredValueIterator:l}=Doe(),{DefaultChainedBatch:f}=Ioe(),{getCallback:h,getOptions:p}=FD(),m=Roe(),g=Symbol("promise"),_=Symbol("landed"),v=Symbol("resources"),E=Symbol("closeResources"),T=Symbol("operations"),D=Symbol("undefer"),R=Symbol("deferOpen"),N=Symbol("options"),B=Symbol("status"),G=Symbol("defaultOptions"),z=Symbol("transcoder"),U=Symbol("keyEncoding"),H=Symbol("valueEncoding"),ee=()=>{},I=class extends n{constructor(x,S){if(super(),typeof x!="object"||x===null)throw new TypeError("The first argument 'manifest' must be an object");S=p(S);let{keyEncoding:A,valueEncoding:M,passive:L,...W}=S;this[v]=new Set,this[T]=[],this[R]=!0,this[N]=W,this[B]="opening",this.supports=e(x,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:x.snapshots!==!1,permanence:x.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:x.encodings||{},events:Object.assign({},x.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[z]=new r(P(this)),this[U]=this[z].encoding(A||"utf8"),this[H]=this[z].encoding(M||"utf8");for(let V of this[z].encodings())this.supports.encodings[V.commonName]||(this.supports.encodings[V.commonName]=!0);this[G]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[U].commonName,valueEncoding:this[H].commonName}),key:Object.freeze({keyEncoding:this[U].commonName})},this.nextTick(()=>{this[R]&&this.open({passive:!1},ee)})}get status(){return this[B]}keyEncoding(x){return this[z].encoding(x??this[U])}valueEncoding(x){return this[z].encoding(x??this[H])}open(x,S){S=h(x,S),S=i(S,g),x={...this[N],...p(x)},x.createIfMissing=x.createIfMissing!==!1,x.errorIfExists=!!x.errorIfExists;let A=M=>{this[B]==="closing"||this[B]==="opening"?this.once(_,M?()=>A(M):A):this[B]!=="open"?S(new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:M})):S()};return x.passive?this[B]==="opening"?this.once(_,A):this.nextTick(A):this[B]==="closed"||this[R]?(this[R]=!1,this[B]="opening",this.emit("opening"),this._open(x,M=>{if(M){this[B]="closed",this[E](()=>{this.emit(_),A(M)}),this[D]();return}this[B]="open",this[D](),this.emit(_),this[B]==="open"&&this.emit("open"),this[B]==="open"&&this.emit("ready"),A()})):this[B]==="open"?this.nextTick(A):this.once(_,()=>this.open(x,S)),S[g]}_open(x,S){this.nextTick(S)}close(x){x=i(x,g);let S=A=>{this[B]==="opening"||this[B]==="closing"?this.once(_,A?S(A):S):this[B]!=="closed"?x(new a("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:A})):x()};if(this[B]==="open"){this[B]="closing",this.emit("closing");let A=M=>{this[B]="open",this[D](),this.emit(_),S(M)};this[E](()=>{this._close(M=>{if(M)return A(M);this[B]="closed",this[D](),this.emit(_),this[B]==="closed"&&this.emit("closed"),S()})})}else this[B]==="closed"?this.nextTick(S):this.once(_,()=>this.close(x));return x[g]}[E](x){if(this[v].size===0)return this.nextTick(x);let S=this[v].size,A=!0,M=()=>{--S===0&&(A?this.nextTick(x):x())};for(let L of this[v])L.close(M);A=!1,this[v].clear()}_close(x){this.nextTick(x)}get(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].entry),this[B]==="opening")return this.defer(()=>this.get(x,S,A)),A[g];if(b(this,A))return A[g];let M=this._checkKey(x);if(M)return this.nextTick(A,M),A[g];let L=this.keyEncoding(S.keyEncoding),W=this.valueEncoding(S.valueEncoding),V=L.format,J=W.format;return(S.keyEncoding!==V||S.valueEncoding!==J)&&(S=Object.assign({},S,{keyEncoding:V,valueEncoding:J})),this._get(this.prefixKey(L.encode(x),V),S,(Q,q)=>{if(Q)return(Q.code==="LEVEL_NOT_FOUND"||Q.notFound||/NotFound/i.test(Q))&&(Q.code||(Q.code="LEVEL_NOT_FOUND"),Q.notFound||(Q.notFound=!0),Q.status||(Q.status=404)),A(Q);try{q=W.decode(q)}catch(X){return A(new a("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:X}))}A(null,q)}),A[g]}_get(x,S,A){this.nextTick(A,new Error("NotFound"))}getMany(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].entry),this[B]==="opening")return this.defer(()=>this.getMany(x,S,A)),A[g];if(b(this,A))return A[g];if(!Array.isArray(x))return this.nextTick(A,new TypeError("The first argument 'keys' must be an array")),A[g];if(x.length===0)return this.nextTick(A,null,[]),A[g];let M=this.keyEncoding(S.keyEncoding),L=this.valueEncoding(S.valueEncoding),W=M.format,V=L.format;(S.keyEncoding!==W||S.valueEncoding!==V)&&(S=Object.assign({},S,{keyEncoding:W,valueEncoding:V}));let J=new Array(x.length);for(let Q=0;Q<x.length;Q++){let q=x[Q],X=this._checkKey(q);if(X)return this.nextTick(A,X),A[g];J[Q]=this.prefixKey(M.encode(q),W)}return this._getMany(J,S,(Q,q)=>{if(Q)return A(Q);try{for(let X=0;X<q.length;X++)q[X]!==void 0&&(q[X]=L.decode(q[X]))}catch(X){return A(new a(`Could not decode one or more of ${q.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:X}))}A(null,q)}),A[g]}_getMany(x,S,A){this.nextTick(A,null,new Array(x.length).fill(void 0))}put(x,S,A,M){if(M=h(A,M),M=i(M,g),A=p(A,this[G].entry),this[B]==="opening")return this.defer(()=>this.put(x,S,A,M)),M[g];if(b(this,M))return M[g];let L=this._checkKey(x)||this._checkValue(S);if(L)return this.nextTick(M,L),M[g];let W=this.keyEncoding(A.keyEncoding),V=this.valueEncoding(A.valueEncoding),J=W.format,Q=V.format;(A.keyEncoding!==J||A.valueEncoding!==Q)&&(A=Object.assign({},A,{keyEncoding:J,valueEncoding:Q}));let q=this.prefixKey(W.encode(x),J),X=V.encode(S);return this._put(q,X,A,ne=>{if(ne)return M(ne);this.emit("put",x,S),M()}),M[g]}_put(x,S,A,M){this.nextTick(M)}del(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].key),this[B]==="opening")return this.defer(()=>this.del(x,S,A)),A[g];if(b(this,A))return A[g];let M=this._checkKey(x);if(M)return this.nextTick(A,M),A[g];let L=this.keyEncoding(S.keyEncoding),W=L.format;return S.keyEncoding!==W&&(S=Object.assign({},S,{keyEncoding:W})),this._del(this.prefixKey(L.encode(x),W),S,V=>{if(V)return A(V);this.emit("del",x),A()}),A[g]}_del(x,S,A){this.nextTick(A)}batch(x,S,A){if(!arguments.length){if(this[B]==="opening")return new f(this);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof x=="function"?A=x:A=h(S,A),A=i(A,g),S=p(S,this[G].empty),this[B]==="opening")return this.defer(()=>this.batch(x,S,A)),A[g];if(b(this,A))return A[g];if(!Array.isArray(x))return this.nextTick(A,new TypeError("The first argument 'operations' must be an array")),A[g];if(x.length===0)return this.nextTick(A),A[g];let M=new Array(x.length),{keyEncoding:L,valueEncoding:W,...V}=S;for(let J=0;J<x.length;J++){if(typeof x[J]!="object"||x[J]===null)return this.nextTick(A,new TypeError("A batch operation must be an object")),A[g];let Q=Object.assign({},x[J]);if(Q.type!=="put"&&Q.type!=="del")return this.nextTick(A,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),A[g];let q=this._checkKey(Q.key);if(q)return this.nextTick(A,q),A[g];let X=Q.sublevel!=null?Q.sublevel:this,ne=X.keyEncoding(Q.keyEncoding||L),re=ne.format;if(Q.key=X.prefixKey(ne.encode(Q.key),re),Q.keyEncoding=re,Q.type==="put"){let Y=this._checkValue(Q.value);if(Y)return this.nextTick(A,Y),A[g];let ce=X.valueEncoding(Q.valueEncoding||W);Q.value=ce.encode(Q.value),Q.valueEncoding=ce.format}X!==this&&(Q.sublevel=null),M[J]=Q}return this._batch(M,V,J=>{if(J)return A(J);this.emit("batch",x),A()}),A[g]}_batch(x,S,A){this.nextTick(A)}sublevel(x,S){return this._sublevel(x,O.defaults(S))}_sublevel(x,S){return new O(this,x,S)}prefixKey(x,S){return x}clear(x,S){if(S=h(x,S),S=i(S,g),x=p(x,this[G].empty),this[B]==="opening")return this.defer(()=>this.clear(x,S)),S[g];if(b(this,S))return S[g];let A=x,M=this.keyEncoding(x.keyEncoding);return x=m(x,M),x.keyEncoding=M.format,x.limit===0?this.nextTick(S):this._clear(x,L=>{if(L)return S(L);this.emit("clear",A),S()}),S[g]}_clear(x,S){this.nextTick(S)}iterator(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x.keys=x.keys!==!1,x.values=x.values!==!1,x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new u(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(x)}_iterator(x){return new s(this,x)}keys(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new c(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(x)}_keys(x){return new o(this,x)}values(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new l(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(x)}_values(x){return new d(this,x)}defer(x){if(typeof x!="function")throw new TypeError("The first argument must be a function");this[T].push(x)}[D](){if(this[T].length===0)return;let x=this[T];this[T]=[];for(let S of x)S()}attachResource(x){if(typeof x!="object"||x===null||typeof x.close!="function")throw new TypeError("The first argument must be a resource object");this[v].add(x)}detachResource(x){this[v].delete(x)}_chainedBatch(){return new f(this)}_checkKey(x){if(x==null)return new a("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(x){if(x==null)return new a("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};I.prototype.nextTick=Coe();var{AbstractSublevel:O}=Ooe()({AbstractLevel:I});t.AbstractLevel=I,t.AbstractSublevel=O;var b=function(x,S){return x[B]!=="open"?(x.nextTick(S,new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},P=function(x){return Object.keys(x.supports.encodings).filter(S=>!!x.supports.encodings[S])}}),mq=Ft(t=>{"use strict";t.AbstractLevel=HU().AbstractLevel,t.AbstractSublevel=HU().AbstractSublevel,t.AbstractIterator=Bf().AbstractIterator,t.AbstractKeyIterator=Bf().AbstractKeyIterator,t.AbstractValueIterator=Bf().AbstractValueIterator,t.AbstractChainedBatch=pq().AbstractChainedBatch}),Boe=Ft((t,e)=>{e.exports=n;var r=hq();function n(i,a,s){if(typeof a!="number")throw new Error("second argument must be a Number");let o,d,u,c,l,f=!0,h;Array.isArray(i)?(o=[],u=d=i.length):(c=Object.keys(i),o={},u=d=c.length);function p(g){function _(){s&&s(g,o),s=null}f?r(_):_()}function m(g,_,v){if(o[g]=v,_&&(l=!0),--u===0||_)p(_);else if(!l&&h<d){let E;c?(E=c[h],h+=1,i[E](function(T,D){m(E,T,D)})):(E=h,h+=1,i[E](function(T,D){m(E,T,D)}))}}h=a,u?c?c.some(function(g,_){return i[g](function(v,E){m(g,v,E)}),_===a-1}):i.some(function(g,_){return g(function(v,E){m(_,v,E)}),_===a-1}):p(null),f=!1}}),yq=Ft((t,e)=>{"use strict";e.exports=function(r){let n=r.gte!==void 0?r.gte:r.gt!==void 0?r.gt:void 0,i=r.lte!==void 0?r.lte:r.lt!==void 0?r.lt:void 0,a=r.gte===void 0,s=r.lte===void 0;return n!==void 0&&i!==void 0?IDBKeyRange.bound(n,i,a,s):n!==void 0?IDBKeyRange.lowerBound(n,a):i!==void 0?IDBKeyRange.upperBound(i,s):null}}),gq=Ft((t,e)=>{"use strict";var r=new TextEncoder;e.exports=function(n){return n instanceof Uint8Array?n:n instanceof ArrayBuffer?new Uint8Array(n):r.encode(n)}}),joe=Ft(t=>{"use strict";var{AbstractIterator:e}=mq(),r=yq(),n=gq(),i=Symbol("cache"),a=Symbol("finished"),s=Symbol("options"),o=Symbol("currentOptions"),d=Symbol("position"),u=Symbol("location"),c=Symbol("first"),l={},f=class extends e{constructor(p,m,g){super(p,g),this[i]=[],this[a]=this.limit===0,this[s]=g,this[o]={...g},this[d]=void 0,this[u]=m,this[c]=!0}_nextv(p,m,g){if(this[c]=!1,this[a])return this.nextTick(g,null,[]);if(this[i].length>0)return p=Math.min(p,this[i].length),this.nextTick(g,null,this[i].splice(0,p));this[d]!==void 0&&(this[s].reverse?(this[o].lt=this[d],this[o].lte=void 0):(this[o].gt=this[d],this[o].gte=void 0));let _;try{_=r(this[o])}catch{return this[a]=!0,this.nextTick(g,null,[])}let v=this.db.db.transaction([this[u]],"readonly"),E=v.objectStore(this[u]),T=[];if(this[s].reverse){let D=!this[s].values&&E.openKeyCursor?"openKeyCursor":"openCursor";E[D](_,"prev").onsuccess=R=>{let N=R.target.result;if(N){let{key:B,value:G}=N;this[d]=B,T.push([this[s].keys&&B!==void 0?n(B):void 0,this[s].values&&G!==void 0?n(G):void 0]),T.length<p?N.continue():h(v)}else this[a]=!0}}else{let D,R,N=()=>{if(D===void 0||R===void 0)return;let B=Math.max(D.length,R.length);B===0||p===1/0?this[a]=!0:this[d]=D[B-1],T.length=B;for(let G=0;G<B;G++){let z=D[G],U=R[G];T[G]=[this[s].keys&&z!==void 0?n(z):void 0,this[s].values&&U!==void 0?n(U):void 0]}h(v)};this[s].keys||p<1/0?E.getAllKeys(_,p<1/0?p:void 0).onsuccess=B=>{D=B.target.result,N()}:(D=[],this.nextTick(N)),this[s].values?E.getAll(_,p<1/0?p:void 0).onsuccess=B=>{R=B.target.result,N()}:(R=[],this.nextTick(N))}v.onabort=()=>{g(v.error||new Error("aborted by user")),g=null},v.oncomplete=()=>{g(null,T),g=null}}_next(p){if(this[i].length>0){let[m,g]=this[i].shift();this.nextTick(p,null,m,g)}else if(this[a])this.nextTick(p);else{let m=Math.min(100,this.limit-this.count);this[c]&&(this[c]=!1,m=1),this._nextv(m,l,(g,_)=>{if(g)return p(g);this[i]=_,this._next(p)})}}_all(p,m){this[c]=!1;let g=this[i].splice(0,this[i].length),_=this.limit-this.count-g.length;if(_<=0)return this.nextTick(m,null,g);this._nextv(_,l,(v,E)=>{if(v)return m(v);g.length>0&&(E=g.concat(E)),m(null,E)})}_seek(p,m){this[c]=!0,this[i]=[],this[a]=!1,this[d]=void 0,this[o]={...this[s]};let g;try{g=r(this[s])}catch{this[a]=!0;return}g!==null&&!g.includes(p)?this[a]=!0:this[s].reverse?this[o].lte=p:this[o].gte=p}};t.Iterator=f;function h(p){typeof p.commit=="function"&&p.commit()}}),Moe=Ft((t,e)=>{"use strict";e.exports=function(r,n,i,a,s){if(a.limit===0)return r.nextTick(s);let o=r.db.transaction([n],"readwrite"),d=o.objectStore(n),u=0;o.oncomplete=function(){s()},o.onabort=function(){s(o.error||new Error("aborted by user"))};let c=d.openKeyCursor?"openKeyCursor":"openCursor",l=a.reverse?"prev":"next";d[c](i,l).onsuccess=function(f){let h=f.target.result;h&&(d.delete(h.key).onsuccess=function(){(a.limit<=0||++u<a.limit)&&h.continue()})}}}),Noe=Ft(t=>{"use strict";var{AbstractLevel:e}=mq(),r=Rc(),n=Boe(),{fromCallback:i}=Tx(),{Iterator:a}=joe(),s=gq(),o=Moe(),d=yq(),u="level-js-",c=Symbol("idb"),l=Symbol("namePrefix"),f=Symbol("location"),h=Symbol("version"),p=Symbol("store"),m=Symbol("onComplete"),g=Symbol("promise"),_=class extends e{constructor(v,E,T){if(typeof E=="function"||typeof T=="function")throw new r("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:D,version:R,...N}=E||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},N),typeof v!="string")throw new Error("constructor requires a location string argument");this[f]=v,this[l]=D??u,this[h]=parseInt(R||1,10),this[c]=null}get location(){return this[f]}get namePrefix(){return this[l]}get version(){return this[h]}get db(){return this[c]}get type(){return"browser-level"}_open(v,E){let T=indexedDB.open(this[l]+this[f],this[h]);T.onerror=function(){E(T.error||new Error("unknown error"))},T.onsuccess=()=>{this[c]=T.result,E()},T.onupgradeneeded=D=>{let R=D.target.result;R.objectStoreNames.contains(this[f])||R.createObjectStore(this[f])}}[p](v){return this[c].transaction([this[f]],v).objectStore(this[f])}[m](v,E){let T=v.transaction;T.onabort=function(){E(T.error||new Error("aborted by user"))},T.oncomplete=function(){E(null,v.result)}}_get(v,E,T){let D=this[p]("readonly"),R;try{R=D.get(v)}catch(N){return this.nextTick(T,N)}this[m](R,function(N,B){if(N)return T(N);if(B===void 0)return T(new r("Entry not found",{code:"LEVEL_NOT_FOUND"}));T(null,s(B))})}_getMany(v,E,T){let D=this[p]("readonly"),R=v.map(N=>B=>{let G;try{G=D.get(N)}catch(z){return B(z)}G.onsuccess=()=>{let z=G.result;B(null,z===void 0?z:s(z))},G.onerror=z=>{z.stopPropagation(),B(G.error)}});n(R,16,T)}_del(v,E,T){let D=this[p]("readwrite"),R;try{R=D.delete(v)}catch(N){return this.nextTick(T,N)}this[m](R,T)}_put(v,E,T,D){let R=this[p]("readwrite"),N;try{N=R.put(E,v)}catch(B){return this.nextTick(D,B)}this[m](N,D)}_iterator(v){return new a(this,this[f],v)}_batch(v,E,T){let D=this[p]("readwrite"),R=D.transaction,N=0,B;R.onabort=function(){T(B||R.error||new Error("aborted by user"))},R.oncomplete=function(){T()};function G(){let z=v[N++],U=z.key,H;try{H=z.type==="del"?D.delete(U):D.put(z.value,U)}catch(ee){B=ee,R.abort();return}N<v.length?H.onsuccess=G:typeof R.commit=="function"&&R.commit()}G()}_clear(v,E){let T,D;try{T=d(v)}catch{return this.nextTick(E)}if(v.limit>=0)return o(this,this[f],T,v,E);try{let R=this[p]("readwrite");D=T?R.delete(T):R.clear()}catch(R){return this.nextTick(E,R)}this[m](D,E)}_close(v){this[c].close(),this.nextTick(v)}};_.destroy=function(v,E,T){typeof E=="function"&&(T=E,E=u),T=i(T,g);let D=indexedDB.deleteDatabase(E+v);return D.onsuccess=function(){T()},D.onerror=function(R){T(R)},T[g]},t.BrowserLevel=_}),wq=Ft(t=>{t.Level=Noe().BrowserLevel}),Uoe=Ft((t,e)=>{(function(r,n){typeof t=="object"&&typeof e<"u"?n(t):typeof define=="function"&&define.amd?define(["exports"],n):n(r.URI=r.URI||{})})(t,function(r){"use strict";function n(){for(var Z=arguments.length,ie=Array(Z),oe=0;oe<Z;oe++)ie[oe]=arguments[oe];if(ie.length>1){ie[0]=ie[0].slice(0,-1);for(var ye=ie.length-1,ve=1;ve<ye;++ve)ie[ve]=ie[ve].slice(1,-1);return ie[ye]=ie[ye].slice(1),ie.join("")}else return ie[0]}function i(Z){return"(?:"+Z+")"}function a(Z){return Z===void 0?"undefined":Z===null?"null":Object.prototype.toString.call(Z).split(" ").pop().split("]").shift().toLowerCase()}function s(Z){return Z.toUpperCase()}function o(Z){return Z!=null?Z instanceof Array?Z:typeof Z.length!="number"||Z.split||Z.setInterval||Z.call?[Z]:Array.prototype.slice.call(Z):[]}function d(Z,ie){var oe=Z;if(ie)for(var ye in ie)oe[ye]=ie[ye];return oe}function u(Z){var ie="[A-Za-z]",oe="[\\x0D]",ye="[0-9]",ve="[\\x22]",Fe=n(ye,"[A-Fa-f]"),At="[\\x0A]",ar="[\\x20]",Ur=i(i("%[EFef]"+Fe+"%"+Fe+Fe+"%"+Fe+Fe)+"|"+i("%[89A-Fa-f]"+Fe+"%"+Fe+Fe)+"|"+i("%"+Fe+Fe)),Kr="[\\:\\/\\?\\#\\[\\]\\@]",Xt="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",dn=n(Kr,Xt),Cn=Z?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",en=Z?"[\\uE000-\\uF8FF]":"[]",gr=n(ie,ye,"[\\-\\.\\_\\~]",Cn),pr=i(ie+n(ie,ye,"[\\+\\-\\.]")+"*"),Ki=i(i(Ur+"|"+n(gr,Xt,"[\\:]"))+"*"),Cm=i(i("25[0-5]")+"|"+i("2[0-4]"+ye)+"|"+i("1"+ye+ye)+"|"+i("[1-9]"+ye)+"|"+ye),Ao=i(i("25[0-5]")+"|"+i("2[0-4]"+ye)+"|"+i("1"+ye+ye)+"|"+i("0?[1-9]"+ye)+"|0?0?"+ye),na=i(Ao+"\\."+Ao+"\\."+Ao+"\\."+Ao),wr=i(Fe+"{1,4}"),Ho=i(i(wr+"\\:"+wr)+"|"+na),Es=i(i(wr+"\\:")+"{6}"+Ho),Oc=i("\\:\\:"+i(wr+"\\:")+"{5}"+Ho),sl=i(i(wr)+"?\\:\\:"+i(wr+"\\:")+"{4}"+Ho),La=i(i(i(wr+"\\:")+"{0,1}"+wr)+"?\\:\\:"+i(wr+"\\:")+"{3}"+Ho),T0=i(i(i(wr+"\\:")+"{0,2}"+wr)+"?\\:\\:"+i(wr+"\\:")+"{2}"+Ho),k0=i(i(i(wr+"\\:")+"{0,3}"+wr)+"?\\:\\:"+wr+"\\:"+Ho),op=i(i(i(wr+"\\:")+"{0,4}"+wr)+"?\\:\\:"+Ho),sp=i(i(i(wr+"\\:")+"{0,5}"+wr)+"?\\:\\:"+wr),ap=i(i(i(wr+"\\:")+"{0,6}"+wr)+"?\\:\\:"),al=i([Es,Oc,sl,La,T0,k0,op,sp,ap].join("|")),cp=i(i(gr+"|"+Ur)+"+"),dp=i(al+"\\%25"+cp),I7=i(al+i("\\%25|\\%(?!"+Fe+"{2})")+cp),R7=i("[vV]"+Fe+"+\\."+n(gr,Xt,"[\\:]")+"+"),C7=i("\\["+i(I7+"|"+al+"|"+R7)+"\\]"),uR=i(i(Ur+"|"+n(gr,Xt))+"*"),$m=i(C7+"|"+na+"(?!"+uR+")|"+uR),Om=i(ye+"*"),lR=i(i(Ki+"@")+"?"+$m+i("\\:"+Om)+"?"),Bm=i(Ur+"|"+n(gr,Xt,"[\\:\\@]")),$7=i(Bm+"*"),fR=i(Bm+"+"),O7=i(i(Ur+"|"+n(gr,Xt,"[\\@]"))+"+"),Bc=i(i("\\/"+$7)+"*"),up=i("\\/"+i(fR+Bc)+"?"),IP=i(O7+Bc),A0=i(fR+Bc),lp="(?!"+Bm+")",Ape=i(Bc+"|"+up+"|"+IP+"|"+A0+"|"+lp),fp=i(i(Bm+"|"+n("[\\/\\?]",en))+"*"),jm=i(i(Bm+"|[\\/\\?]")+"*"),pR=i(i("\\/\\/"+lR+Bc)+"|"+up+"|"+A0+"|"+lp),B7=i(pr+"\\:"+pR+i("\\?"+fp)+"?"+i("\\#"+jm)+"?"),j7=i(i("\\/\\/"+lR+Bc)+"|"+up+"|"+IP+"|"+lp),M7=i(j7+i("\\?"+fp)+"?"+i("\\#"+jm)+"?"),Dpe=i(B7+"|"+M7),Ipe=i(pr+"\\:"+pR+i("\\?"+fp)+"?"),Rpe="^("+pr+")\\:"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+A0+"|"+lp+")")+i("\\?("+fp+")")+"?"+i("\\#("+jm+")")+"?$",Cpe="^(){0}"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+IP+"|"+lp+")")+i("\\?("+fp+")")+"?"+i("\\#("+jm+")")+"?$",$pe="^("+pr+")\\:"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+A0+"|"+lp+")")+i("\\?("+fp+")")+"?$",Ope="^"+i("\\#("+jm+")")+"?$",Bpe="^"+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?$";return{NOT_SCHEME:new RegExp(n("[^]",ie,ye,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(n("[^\\%\\:]",gr,Xt),"g"),NOT_HOST:new RegExp(n("[^\\%\\[\\]\\:]",gr,Xt),"g"),NOT_PATH:new RegExp(n("[^\\%\\/\\:\\@]",gr,Xt),"g"),NOT_PATH_NOSCHEME:new RegExp(n("[^\\%\\/\\@]",gr,Xt),"g"),NOT_QUERY:new RegExp(n("[^\\%]",gr,Xt,"[\\:\\@\\/\\?]",en),"g"),NOT_FRAGMENT:new RegExp(n("[^\\%]",gr,Xt,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(n("[^]",gr,Xt),"g"),UNRESERVED:new RegExp(gr,"g"),OTHER_CHARS:new RegExp(n("[^\\%]",gr,dn),"g"),PCT_ENCODED:new RegExp(Ur,"g"),IPV4ADDRESS:new RegExp("^("+na+")$"),IPV6ADDRESS:new RegExp("^\\[?("+al+")"+i(i("\\%25|\\%(?!"+Fe+"{2})")+"("+cp+")")+"?\\]?$")}}var c=u(!1),l=u(!0),f=function(){function Z(ie,oe){var ye=[],ve=!0,Fe=!1,At=void 0;try{for(var ar=ie[Symbol.iterator](),Ur;!(ve=(Ur=ar.next()).done)&&(ye.push(Ur.value),!(oe&&ye.length===oe));ve=!0);}catch(Kr){Fe=!0,At=Kr}finally{try{!ve&&ar.return&&ar.return()}finally{if(Fe)throw At}}return ye}return function(ie,oe){if(Array.isArray(ie))return ie;if(Symbol.iterator in Object(ie))return Z(ie,oe);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=function(Z){if(Array.isArray(Z)){for(var ie=0,oe=Array(Z.length);ie<Z.length;ie++)oe[ie]=Z[ie];return oe}else return Array.from(Z)},p=2147483647,m=36,g=1,_=26,v=38,E=700,T=72,D=128,R="-",N=/^xn--/,B=/[^\0-\x7E]/,G=/[\x2E\u3002\uFF0E\uFF61]/g,z={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},U=m-g,H=Math.floor,ee=String.fromCharCode;function I(Z){throw new RangeError(z[Z])}function O(Z,ie){for(var oe=[],ye=Z.length;ye--;)oe[ye]=ie(Z[ye]);return oe}function b(Z,ie){var oe=Z.split("@"),ye="";oe.length>1&&(ye=oe[0]+"@",Z=oe[1]),Z=Z.replace(G,".");var ve=Z.split("."),Fe=O(ve,ie).join(".");return ye+Fe}function P(Z){for(var ie=[],oe=0,ye=Z.length;oe<ye;){var ve=Z.charCodeAt(oe++);if(ve>=55296&&ve<=56319&&oe<ye){var Fe=Z.charCodeAt(oe++);(Fe&64512)==56320?ie.push(((ve&1023)<<10)+(Fe&1023)+65536):(ie.push(ve),oe--)}else ie.push(ve)}return ie}var x=function(Z){return String.fromCodePoint.apply(String,h(Z))},S=function(Z){return Z-48<10?Z-22:Z-65<26?Z-65:Z-97<26?Z-97:m},A=function(Z,ie){return Z+22+75*(Z<26)-((ie!=0)<<5)},M=function(Z,ie,oe){var ye=0;for(Z=oe?H(Z/E):Z>>1,Z+=H(Z/ie);Z>U*_>>1;ye+=m)Z=H(Z/U);return H(ye+(U+1)*Z/(Z+v))},L=function(Z){var ie=[],oe=Z.length,ye=0,ve=D,Fe=T,At=Z.lastIndexOf(R);At<0&&(At=0);for(var ar=0;ar<At;++ar)Z.charCodeAt(ar)>=128&&I("not-basic"),ie.push(Z.charCodeAt(ar));for(var Ur=At>0?At+1:0;Ur<oe;){for(var Kr=ye,Xt=1,dn=m;;dn+=m){Ur>=oe&&I("invalid-input");var Cn=S(Z.charCodeAt(Ur++));(Cn>=m||Cn>H((p-ye)/Xt))&&I("overflow"),ye+=Cn*Xt;var en=dn<=Fe?g:dn>=Fe+_?_:dn-Fe;if(Cn<en)break;var gr=m-en;Xt>H(p/gr)&&I("overflow"),Xt*=gr}var pr=ie.length+1;Fe=M(ye-Kr,pr,Kr==0),H(ye/pr)>p-ve&&I("overflow"),ve+=H(ye/pr),ye%=pr,ie.splice(ye++,0,ve)}return String.fromCodePoint.apply(String,ie)},W=function(Z){var ie=[];Z=P(Z);var oe=Z.length,ye=D,ve=0,Fe=T,At=!0,ar=!1,Ur=void 0;try{for(var Kr=Z[Symbol.iterator](),Xt;!(At=(Xt=Kr.next()).done);At=!0){var dn=Xt.value;dn<128&&ie.push(ee(dn))}}catch(dp){ar=!0,Ur=dp}finally{try{!At&&Kr.return&&Kr.return()}finally{if(ar)throw Ur}}var Cn=ie.length,en=Cn;for(Cn&&ie.push(R);en<oe;){var gr=p,pr=!0,Ki=!1,Cm=void 0;try{for(var Ao=Z[Symbol.iterator](),na;!(pr=(na=Ao.next()).done);pr=!0){var wr=na.value;wr>=ye&&wr<gr&&(gr=wr)}}catch(dp){Ki=!0,Cm=dp}finally{try{!pr&&Ao.return&&Ao.return()}finally{if(Ki)throw Cm}}var Ho=en+1;gr-ye>H((p-ve)/Ho)&&I("overflow"),ve+=(gr-ye)*Ho,ye=gr;var Es=!0,Oc=!1,sl=void 0;try{for(var La=Z[Symbol.iterator](),T0;!(Es=(T0=La.next()).done);Es=!0){var k0=T0.value;if(k0<ye&&++ve>p&&I("overflow"),k0==ye){for(var op=ve,sp=m;;sp+=m){var ap=sp<=Fe?g:sp>=Fe+_?_:sp-Fe;if(op<ap)break;var al=op-ap,cp=m-ap;ie.push(ee(A(ap+al%cp,0))),op=H(al/cp)}ie.push(ee(A(op,0))),Fe=M(ve,Ho,en==Cn),ve=0,++en}}}catch(dp){Oc=!0,sl=dp}finally{try{!Es&&La.return&&La.return()}finally{if(Oc)throw sl}}++ve,++ye}return ie.join("")},V=function(Z){return b(Z,function(ie){return N.test(ie)?L(ie.slice(4).toLowerCase()):ie})},J=function(Z){return b(Z,function(ie){return B.test(ie)?"xn--"+W(ie):ie})},Q={version:"2.1.0",ucs2:{decode:P,encode:x},decode:L,encode:W,toASCII:J,toUnicode:V},q={};function X(Z){var ie=Z.charCodeAt(0),oe=void 0;return ie<16?oe="%0"+ie.toString(16).toUpperCase():ie<128?oe="%"+ie.toString(16).toUpperCase():ie<2048?oe="%"+(ie>>6|192).toString(16).toUpperCase()+"%"+(ie&63|128).toString(16).toUpperCase():oe="%"+(ie>>12|224).toString(16).toUpperCase()+"%"+(ie>>6&63|128).toString(16).toUpperCase()+"%"+(ie&63|128).toString(16).toUpperCase(),oe}function ne(Z){for(var ie="",oe=0,ye=Z.length;oe<ye;){var ve=parseInt(Z.substr(oe+1,2),16);if(ve<128)ie+=String.fromCharCode(ve),oe+=3;else if(ve>=194&&ve<224){if(ye-oe>=6){var Fe=parseInt(Z.substr(oe+4,2),16);ie+=String.fromCharCode((ve&31)<<6|Fe&63)}else ie+=Z.substr(oe,6);oe+=6}else if(ve>=224){if(ye-oe>=9){var At=parseInt(Z.substr(oe+4,2),16),ar=parseInt(Z.substr(oe+7,2),16);ie+=String.fromCharCode((ve&15)<<12|(At&63)<<6|ar&63)}else ie+=Z.substr(oe,9);oe+=9}else ie+=Z.substr(oe,3),oe+=3}return ie}function re(Z,ie){function oe(ye){var ve=ne(ye);return ve.match(ie.UNRESERVED)?ve:ye}return Z.scheme&&(Z.scheme=String(Z.scheme).replace(ie.PCT_ENCODED,oe).toLowerCase().replace(ie.NOT_SCHEME,"")),Z.userinfo!==void 0&&(Z.userinfo=String(Z.userinfo).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_USERINFO,X).replace(ie.PCT_ENCODED,s)),Z.host!==void 0&&(Z.host=String(Z.host).replace(ie.PCT_ENCODED,oe).toLowerCase().replace(ie.NOT_HOST,X).replace(ie.PCT_ENCODED,s)),Z.path!==void 0&&(Z.path=String(Z.path).replace(ie.PCT_ENCODED,oe).replace(Z.scheme?ie.NOT_PATH:ie.NOT_PATH_NOSCHEME,X).replace(ie.PCT_ENCODED,s)),Z.query!==void 0&&(Z.query=String(Z.query).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_QUERY,X).replace(ie.PCT_ENCODED,s)),Z.fragment!==void 0&&(Z.fragment=String(Z.fragment).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_FRAGMENT,X).replace(ie.PCT_ENCODED,s)),Z}function Y(Z){return Z.replace(/^0*(.*)/,"$1")||"0"}function ce(Z,ie){var oe=Z.match(ie.IPV4ADDRESS)||[],ye=f(oe,2),ve=ye[1];return ve?ve.split(".").map(Y).join("."):Z}function de(Z,ie){var oe=Z.match(ie.IPV6ADDRESS)||[],ye=f(oe,3),ve=ye[1],Fe=ye[2];if(ve){for(var At=ve.toLowerCase().split("::").reverse(),ar=f(At,2),Ur=ar[0],Kr=ar[1],Xt=Kr?Kr.split(":").map(Y):[],dn=Ur.split(":").map(Y),Cn=ie.IPV4ADDRESS.test(dn[dn.length-1]),en=Cn?7:8,gr=dn.length-en,pr=Array(en),Ki=0;Ki<en;++Ki)pr[Ki]=Xt[Ki]||dn[gr+Ki]||"";Cn&&(pr[en-1]=ce(pr[en-1],ie));var Cm=pr.reduce(function(Es,Oc,sl){if(!Oc||Oc==="0"){var La=Es[Es.length-1];La&&La.index+La.length===sl?La.length++:Es.push({index:sl,length:1})}return Es},[]),Ao=Cm.sort(function(Es,Oc){return Oc.length-Es.length})[0],na=void 0;if(Ao&&Ao.length>1){var wr=pr.slice(0,Ao.index),Ho=pr.slice(Ao.index+Ao.length);na=wr.join(":")+"::"+Ho.join(":")}else na=pr.join(":");return Fe&&(na+="%"+Fe),na}else return Z}var pe=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,we="".match(/(){0}/)[1]===void 0;function ae(Z){var ie=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},oe={},ye=ie.iri!==!1?l:c;ie.reference==="suffix"&&(Z=(ie.scheme?ie.scheme+":":"")+"//"+Z);var ve=Z.match(pe);if(ve){we?(oe.scheme=ve[1],oe.userinfo=ve[3],oe.host=ve[4],oe.port=parseInt(ve[5],10),oe.path=ve[6]||"",oe.query=ve[7],oe.fragment=ve[8],isNaN(oe.port)&&(oe.port=ve[5])):(oe.scheme=ve[1]||void 0,oe.userinfo=Z.indexOf("@")!==-1?ve[3]:void 0,oe.host=Z.indexOf("//")!==-1?ve[4]:void 0,oe.port=parseInt(ve[5],10),oe.path=ve[6]||"",oe.query=Z.indexOf("?")!==-1?ve[7]:void 0,oe.fragment=Z.indexOf("#")!==-1?ve[8]:void 0,isNaN(oe.port)&&(oe.port=Z.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?ve[4]:void 0)),oe.host&&(oe.host=de(ce(oe.host,ye),ye)),oe.scheme===void 0&&oe.userinfo===void 0&&oe.host===void 0&&oe.port===void 0&&!oe.path&&oe.query===void 0?oe.reference="same-document":oe.scheme===void 0?oe.reference="relative":oe.fragment===void 0?oe.reference="absolute":oe.reference="uri",ie.reference&&ie.reference!=="suffix"&&ie.reference!==oe.reference&&(oe.error=oe.error||"URI is not a "+ie.reference+" reference.");var Fe=q[(ie.scheme||oe.scheme||"").toLowerCase()];if(!ie.unicodeSupport&&(!Fe||!Fe.unicodeSupport)){if(oe.host&&(ie.domainHost||Fe&&Fe.domainHost))try{oe.host=Q.toASCII(oe.host.replace(ye.PCT_ENCODED,ne).toLowerCase())}catch(At){oe.error=oe.error||"Host's domain name can not be converted to ASCII via punycode: "+At}re(oe,c)}else re(oe,ye);Fe&&Fe.parse&&Fe.parse(oe,ie)}else oe.error=oe.error||"URI can not be parsed.";return oe}function ge(Z,ie){var oe=ie.iri!==!1?l:c,ye=[];return Z.userinfo!==void 0&&(ye.push(Z.userinfo),ye.push("@")),Z.host!==void 0&&ye.push(de(ce(String(Z.host),oe),oe).replace(oe.IPV6ADDRESS,function(ve,Fe,At){return"["+Fe+(At?"%25"+At:"")+"]"})),(typeof Z.port=="number"||typeof Z.port=="string")&&(ye.push(":"),ye.push(String(Z.port))),ye.length?ye.join(""):void 0}var Be=/^\.\.?\//,qe=/^\/\.(\/|$)/,We=/^\/\.\.(\/|$)/,Pt=/^\/?(?:.|\n)*?(?=\/|$)/;function Pe(Z){for(var ie=[];Z.length;)if(Z.match(Be))Z=Z.replace(Be,"");else if(Z.match(qe))Z=Z.replace(qe,"/");else if(Z.match(We))Z=Z.replace(We,"/"),ie.pop();else if(Z==="."||Z==="..")Z="";else{var oe=Z.match(Pt);if(oe){var ye=oe[0];Z=Z.slice(ye.length),ie.push(ye)}else throw new Error("Unexpected dot segment condition")}return ie.join("")}function nt(Z){var ie=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},oe=ie.iri?l:c,ye=[],ve=q[(ie.scheme||Z.scheme||"").toLowerCase()];if(ve&&ve.serialize&&ve.serialize(Z,ie),Z.host&&!oe.IPV6ADDRESS.test(Z.host)&&(ie.domainHost||ve&&ve.domainHost))try{Z.host=ie.iri?Q.toUnicode(Z.host):Q.toASCII(Z.host.replace(oe.PCT_ENCODED,ne).toLowerCase())}catch(ar){Z.error=Z.error||"Host's domain name can not be converted to "+(ie.iri?"Unicode":"ASCII")+" via punycode: "+ar}re(Z,oe),ie.reference!=="suffix"&&Z.scheme&&(ye.push(Z.scheme),ye.push(":"));var Fe=ge(Z,ie);if(Fe!==void 0&&(ie.reference!=="suffix"&&ye.push("//"),ye.push(Fe),Z.path&&Z.path.charAt(0)!=="/"&&ye.push("/")),Z.path!==void 0){var At=Z.path;!ie.absolutePath&&(!ve||!ve.absolutePath)&&(At=Pe(At)),Fe===void 0&&(At=At.replace(/^\/\//,"/%2F")),ye.push(At)}return Z.query!==void 0&&(ye.push("?"),ye.push(Z.query)),Z.fragment!==void 0&&(ye.push("#"),ye.push(Z.fragment)),ye.join("")}function wt(Z,ie){var oe=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ye=arguments[3],ve={};return ye||(Z=ae(nt(Z,oe),oe),ie=ae(nt(ie,oe),oe)),oe=oe||{},!oe.tolerant&&ie.scheme?(ve.scheme=ie.scheme,ve.userinfo=ie.userinfo,ve.host=ie.host,ve.port=ie.port,ve.path=Pe(ie.path||""),ve.query=ie.query):(ie.userinfo!==void 0||ie.host!==void 0||ie.port!==void 0?(ve.userinfo=ie.userinfo,ve.host=ie.host,ve.port=ie.port,ve.path=Pe(ie.path||""),ve.query=ie.query):(ie.path?(ie.path.charAt(0)==="/"?ve.path=Pe(ie.path):((Z.userinfo!==void 0||Z.host!==void 0||Z.port!==void 0)&&!Z.path?ve.path="/"+ie.path:Z.path?ve.path=Z.path.slice(0,Z.path.lastIndexOf("/")+1)+ie.path:ve.path=ie.path,ve.path=Pe(ve.path)),ve.query=ie.query):(ve.path=Z.path,ie.query!==void 0?ve.query=ie.query:ve.query=Z.query),ve.userinfo=Z.userinfo,ve.host=Z.host,ve.port=Z.port),ve.scheme=Z.scheme),ve.fragment=ie.fragment,ve}function xt(Z,ie,oe){var ye=d({scheme:"null"},oe);return nt(wt(ae(Z,ye),ae(ie,ye),ye,!0),ye)}function Ot(Z,ie){return typeof Z=="string"?Z=nt(ae(Z,ie),ie):a(Z)==="object"&&(Z=ae(nt(Z,ie),ie)),Z}function k(Z,ie,oe){return typeof Z=="string"?Z=nt(ae(Z,oe),oe):a(Z)==="object"&&(Z=nt(Z,oe)),typeof ie=="string"?ie=nt(ae(ie,oe),oe):a(ie)==="object"&&(ie=nt(ie,oe)),Z===ie}function j(Z,ie){return Z&&Z.toString().replace(!ie||!ie.iri?c.ESCAPE:l.ESCAPE,X)}function K(Z,ie){return Z&&Z.toString().replace(!ie||!ie.iri?c.PCT_ENCODED:l.PCT_ENCODED,ne)}var te={scheme:"http",domainHost:!0,parse:function(Z,ie){return Z.host||(Z.error=Z.error||"HTTP URIs must have a host."),Z},serialize:function(Z,ie){var oe=String(Z.scheme).toLowerCase()==="https";return(Z.port===(oe?443:80)||Z.port==="")&&(Z.port=void 0),Z.path||(Z.path="/"),Z}},se={scheme:"https",domainHost:te.domainHost,parse:te.parse,serialize:te.serialize};function he(Z){return typeof Z.secure=="boolean"?Z.secure:String(Z.scheme).toLowerCase()==="wss"}var xe={scheme:"ws",domainHost:!0,parse:function(Z,ie){var oe=Z;return oe.secure=he(oe),oe.resourceName=(oe.path||"/")+(oe.query?"?"+oe.query:""),oe.path=void 0,oe.query=void 0,oe},serialize:function(Z,ie){if((Z.port===(he(Z)?443:80)||Z.port==="")&&(Z.port=void 0),typeof Z.secure=="boolean"&&(Z.scheme=Z.secure?"wss":"ws",Z.secure=void 0),Z.resourceName){var oe=Z.resourceName.split("?"),ye=f(oe,2),ve=ye[0],Fe=ye[1];Z.path=ve&&ve!=="/"?ve:void 0,Z.query=Fe,Z.resourceName=void 0}return Z.fragment=void 0,Z}},Bt={scheme:"wss",domainHost:xe.domainHost,parse:xe.parse,serialize:xe.serialize},Mn={},$r=!0,fr="[A-Za-z0-9\\-\\.\\_\\~"+($r?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",nr="[0-9A-Fa-f]",b7=i(i("%[EFef]"+nr+"%"+nr+nr+"%"+nr+nr)+"|"+i("%[89A-Fa-f]"+nr+"%"+nr+nr)+"|"+i("%"+nr+nr)),x7="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",P7="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_7=n(P7,'[\\"\\\\]'),E7="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",S7=new RegExp(fr,"g"),ip=new RegExp(b7,"g"),T7=new RegExp(n("[^]",x7,"[\\.]",'[\\"]',_7),"g"),sR=new RegExp(n("[^]",fr,E7),"g"),k7=sR;function DP(Z){var ie=ne(Z);return ie.match(S7)?ie:Z}var aR={scheme:"mailto",parse:function(Z,ie){var oe=Z,ye=oe.to=oe.path?oe.path.split(","):[];if(oe.path=void 0,oe.query){for(var ve=!1,Fe={},At=oe.query.split("&"),ar=0,Ur=At.length;ar<Ur;++ar){var Kr=At[ar].split("=");switch(Kr[0]){case"to":for(var Xt=Kr[1].split(","),dn=0,Cn=Xt.length;dn<Cn;++dn)ye.push(Xt[dn]);break;case"subject":oe.subject=K(Kr[1],ie);break;case"body":oe.body=K(Kr[1],ie);break;default:ve=!0,Fe[K(Kr[0],ie)]=K(Kr[1],ie);break}}ve&&(oe.headers=Fe)}oe.query=void 0;for(var en=0,gr=ye.length;en<gr;++en){var pr=ye[en].split("@");if(pr[0]=K(pr[0]),ie.unicodeSupport)pr[1]=K(pr[1],ie).toLowerCase();else try{pr[1]=Q.toASCII(K(pr[1],ie).toLowerCase())}catch(Ki){oe.error=oe.error||"Email address's domain name can not be converted to ASCII via punycode: "+Ki}ye[en]=pr.join("@")}return oe},serialize:function(Z,ie){var oe=Z,ye=o(Z.to);if(ye){for(var ve=0,Fe=ye.length;ve<Fe;++ve){var At=String(ye[ve]),ar=At.lastIndexOf("@"),Ur=At.slice(0,ar).replace(ip,DP).replace(ip,s).replace(T7,X),Kr=At.slice(ar+1);try{Kr=ie.iri?Q.toUnicode(Kr):Q.toASCII(K(Kr,ie).toLowerCase())}catch(en){oe.error=oe.error||"Email address's domain name can not be converted to "+(ie.iri?"Unicode":"ASCII")+" via punycode: "+en}ye[ve]=Ur+"@"+Kr}oe.path=ye.join(",")}var Xt=Z.headers=Z.headers||{};Z.subject&&(Xt.subject=Z.subject),Z.body&&(Xt.body=Z.body);var dn=[];for(var Cn in Xt)Xt[Cn]!==Mn[Cn]&&dn.push(Cn.replace(ip,DP).replace(ip,s).replace(sR,X)+"="+Xt[Cn].replace(ip,DP).replace(ip,s).replace(k7,X));return dn.length&&(oe.query=dn.join("&")),oe}},A7=/^([^\:]+)\:(.*)/,cR={scheme:"urn",parse:function(Z,ie){var oe=Z.path&&Z.path.match(A7),ye=Z;if(oe){var ve=ie.scheme||ye.scheme||"urn",Fe=oe[1].toLowerCase(),At=oe[2],ar=ve+":"+(ie.nid||Fe),Ur=q[ar];ye.nid=Fe,ye.nss=At,ye.path=void 0,Ur&&(ye=Ur.parse(ye,ie))}else ye.error=ye.error||"URN can not be parsed.";return ye},serialize:function(Z,ie){var oe=ie.scheme||Z.scheme||"urn",ye=Z.nid,ve=oe+":"+(ie.nid||ye),Fe=q[ve];Fe&&(Z=Fe.serialize(Z,ie));var At=Z,ar=Z.nss;return At.path=(ye||ie.nid)+":"+ar,At}},D7=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,dR={scheme:"urn:uuid",parse:function(Z,ie){var oe=Z;return oe.uuid=oe.nss,oe.nss=void 0,!ie.tolerant&&(!oe.uuid||!oe.uuid.match(D7))&&(oe.error=oe.error||"UUID is not valid."),oe},serialize:function(Z,ie){var oe=Z;return oe.nss=(Z.uuid||"").toLowerCase(),oe}};q[te.scheme]=te,q[se.scheme]=se,q[xe.scheme]=xe,q[Bt.scheme]=Bt,q[aR.scheme]=aR,q[cR.scheme]=cR,q[dR.scheme]=dR,r.SCHEMES=q,r.pctEncChar=X,r.pctDecChars=ne,r.parse=ae,r.removeDotSegments=Pe,r.serialize=nt,r.resolveComponents=wt,r.resolve=xt,r.normalize=Ot,r.equal=k,r.escapeComponent=j,r.unescapeComponent=K,Object.defineProperty(r,"__esModule",{value:!0})})}),Koe=Ft((t,e)=>{"use strict";e.exports=function r(n){if(typeof n=="number"&&isNaN(n))throw new Error("NaN is not allowed");if(typeof n=="number"&&!isFinite(n))throw new Error("Infinity is not allowed");return n===null||typeof n!="object"?JSON.stringify(n):n.toJSON instanceof Function?r(n.toJSON()):Array.isArray(n)?`[${n.reduce((i,a,s)=>`${i}${s===0?"":","}${r(a===void 0||typeof a=="symbol"?null:a)}`,"")}]`:`{${Object.keys(n).sort().reduce((i,a)=>{if(n[a]===void 0||typeof n[a]=="symbol")return i;let s=i.length===0?"":",";return`${i}${s}${r(a)}:${r(n[a])}`},"")}}`}}),vq=Ft((t,e)=>{var r=1e3,n=r*60,i=n*60,a=i*24,s=a*7,o=a*365.25;e.exports=function(f,h){h=h||{};var p=typeof f;if(p==="string"&&f.length>0)return d(f);if(p==="number"&&isFinite(f))return h.long?c(f):u(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))};function d(f){if(f=String(f),!(f.length>100)){var h=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(h){var p=parseFloat(h[1]),m=(h[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return p*o;case"weeks":case"week":case"w":return p*s;case"days":case"day":case"d":return p*a;case"hours":case"hour":case"hrs":case"hr":case"h":return p*i;case"minutes":case"minute":case"mins":case"min":case"m":return p*n;case"seconds":case"second":case"secs":case"sec":case"s":return p*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return p;default:return}}}}function u(f){var h=Math.abs(f);return h>=a?Math.round(f/a)+"d":h>=i?Math.round(f/i)+"h":h>=n?Math.round(f/n)+"m":h>=r?Math.round(f/r)+"s":f+"ms"}function c(f){var h=Math.abs(f);return h>=a?l(f,h,a,"day"):h>=i?l(f,h,i,"hour"):h>=n?l(f,h,n,"minute"):h>=r?l(f,h,r,"second"):f+" ms"}function l(f,h,p,m){var g=h>=p*1.5;return Math.round(f/p)+" "+m+(g?"s":"")}}),kx=(t=>(t.authentication="authentication",t.assertionMethod="assertionMethod",t.keyAgreement="keyAgreement",t.capabilityInvocation="capabilityInvocation",t.capabilityDelegation="capabilityDelegation",t))(kx||{}),li={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}},Oi=class bq{constructor({method:e,id:r,path:n,query:i,fragment:a,params:s}){this.uri=`did:${e}:${r}`,this.method=e,this.id=r,this.path=n,this.query=i,this.fragment=a,this.params=s}static parse(e){if(!e||e.length>2048)return null;let r=bq.DID_URI_PATTERN.exec(e);if(!r||!r.groups)return null;let{method:n,id:i,path:a,query:s,fragment:o}=r.groups,d={uri:`did:${n}:${i}`,method:n,id:i};if(a&&(d.path=a),s&&(d.query=s.slice(1)),o&&(d.fragment=o.slice(1)),s){let u={},c=s.slice(1).split("&");for(let l of c){let[f,h]=l.split("=");u[f]=h}d.params=u}return d}};Oi.METHOD_PATTERN="([a-z0-9]+)",Oi.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})",Oi.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${Oi.PCT_ENCODED_PATTERN})`,Oi.METHOD_ID_PATTERN=`((?:${Oi.ID_CHAR_PATTERN}*:)*(${Oi.ID_CHAR_PATTERN}+))`,Oi.PATH_PATTERN="(/[^#?]*)?",Oi.QUERY_PATTERN="([?][^#]*)?",Oi.FRAGMENT_PATTERN="(#.*)?",Oi.DID_URI_PATTERN=new RegExp("^did:(?<method>"+Oi.METHOD_PATTERN+"):(?<id>"+Oi.METHOD_ID_PATTERN+")(?<path>"+Oi.PATH_PATTERN+")(?<query>"+Oi.QUERY_PATTERN+")(?<fragment>"+Oi.FRAGMENT_PATTERN+")$");Vn=Oi,Xe=class xq extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,xq)}},qoe=(t=>(t.InvalidDid="invalidDid",t.MethodNotSupported="methodNotSupported",t.InternalError="internalError",t.InvalidDidDocument="invalidDidDocument",t.InvalidDidDocumentLength="invalidDidDocumentLength",t.InvalidDidUrl="invalidDidUrl",t.InvalidPreviousDidProof="invalidPreviousDidProof",t.InvalidPublicKey="invalidPublicKey",t.InvalidPublicKeyLength="invalidPublicKeyLength",t.InvalidPublicKeyType="invalidPublicKeyType",t.InvalidSignature="invalidSignature",t.NotFound="notFound",t.RepresentationNotSupported="representationNotSupported",t.UnsupportedPublicKeyType="unsupportedPublicKeyType",t))(qoe||{}),Ys=class Pq extends Error{constructor(e,r){super(r),this.code=e,this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,Pq)}};(function(t){t.AlgorithmNotSupported="algorithmNotSupported",t.EncodingError="encodingError",t.InvalidCoseSign1="invalidCoseSign1",t.InvalidEat="invalidEat",t.InvalidJwe="invalidJwe",t.InvalidJwk="invalidJwk",t.OperationNotSupported="operationNotSupported"})(zo||(zo={}));Loe=Lf(boe(),1);Foe=zoe,Goe=Foe,Woe=Goe,gje=new Uint8Array(0),Hoe=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},GD=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},Voe=class{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Joe=class{constructor(t,e,r){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return _q(this,t)}},Zoe=class{constructor(t){this.decoders=t}or(t){return _q(this,t)}decode(t){let e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},_q=(t,e)=>new Zoe({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Yoe=class{constructor(t,e,r,n){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=n,this.encoder=new Voe(t,e,r),this.decoder=new Joe(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Eq=({name:t,prefix:e,encode:r,decode:n})=>new Yoe(t,e,r,n),Sq=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:i}=Woe(r,e);return Eq({prefix:t,name:e,encode:n,decode:a=>GD(i(a))})},Qoe=(t,e,r,n)=>{let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let a=t.length;for(;t[a-1]==="=";)--a;let s=new Uint8Array(a*r/8|0),o=0,d=0,u=0;for(let c=0;c<a;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|l,o+=r,o>=8&&(o-=8,s[u++]=255&d>>o)}if(o>=r||255&d<<8-o)throw new SyntaxError("Unexpected end of data");return s},Xoe=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,a="",s=0,o=0;for(let d=0;d<t.length;++d)for(o=o<<8|t[d],s+=8;s>r;)s-=r,a+=e[i&o>>s];if(s&&(a+=e[i&o<<r-s]),n)for(;a.length*r&7;)a+="=";return a},xs=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Eq({prefix:e,name:t,encode(i){return Xoe(i,n,r)},decode(i){return Qoe(i,n,r,t)}}),V1=xs({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wje=xs({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vje=xs({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bje=xs({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xje=xs({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pje=xs({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_je=xs({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Eje=xs({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),VU=xs({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),Js=Sq({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sje=Sq({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Tje=xs({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kje=xs({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pd=xs({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Aje=xs({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});vw=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},JU=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(a){r[a]=t[a]&&function(s){return new Promise(function(o,d){s=t[a](s),i(o,d,s.done,s.value)})}}function i(a,s,o,d){Promise.resolve(d).then(function(u){a({value:u,done:o})},s)}},K1=new TextEncoder,Af=new TextDecoder,tt=class qo{constructor(e,r){this.data=e,this.format=r}static arrayBuffer(e){return new qo(e,"ArrayBuffer")}static asyncIterable(e){if(!tse(e))throw new TypeError("Input must be of type AsyncIterable.");return new qo(e,"AsyncIterable")}static base32Z(e){return new qo(e,"Base32Z")}static base58Btc(e){return new qo(e,"Base58Btc")}static base64Url(e){return new qo(e,"Base64Url")}static bufferSource(e){return new qo(e,"BufferSource")}static hex(e){if(typeof e!="string")throw new TypeError("Hex input must be a string.");if(e.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new qo(e,"Hex")}static multibase(e){return new qo(e,"Multibase")}static object(e){return new qo(e,"Object")}static string(e){return new qo(e,"String")}static uint8Array(e){return new qo(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return Js.baseDecode(this.data).buffer;case"Base64Url":return Pd.baseDecode(this.data).buffer;case"BufferSource":{if(bD(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return ese(this.data)?this.data.buffer.slice(this.data.byteOffset,this.data.byteOffset+this.data.byteLength):this.data.buffer;throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":return this.toUint8Array().buffer;case"String":return this.toUint8Array().buffer;case"Uint8Array":return this.data.buffer;default:throw new TypeError(`Conversion from ${this.format} to ArrayBuffer is not supported.`)}}toArrayBufferAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":return yield(yield this.toBlobAsync()).arrayBuffer();default:throw new TypeError(`Asynchronous conversion from ${this.format} to ArrayBuffer is not supported.`)}})}toBase32Z(){switch(this.format){case"Uint8Array":return VU.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Js.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return Js.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Pd.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return Pd.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),r=K1.encode(e);return Pd.baseEncode(r)}case"String":{let e=K1.encode(this.data);return Pd.baseEncode(e)}case"Uint8Array":return Pd.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return vw(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let d=[];try{for(var a=!0,s=JU(this.data),o;o=yield s.next(),e=o.done,!e;a=!0){i=o.value,a=!1;let u=i;d.push(u)}}catch(u){r={error:u}}finally{try{!a&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return new Blob(d)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(r,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let r=this.toUint8Array();return qo.uint8Array(r).toHex()}case"Base64Url":{let r=this.toUint8Array();return qo.uint8Array(r).toHex()}case"Uint8Array":{let r="";for(let n=0;n<this.data.length;n++)r+=e[this.data[n]];return r}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let e=Pd.baseDecode(this.data),r=Af.decode(e);return JSON.parse(r)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Af.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toStringAsync();return JSON.parse(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return Af.decode(this.data);case"Base64Url":{let e=Pd.baseDecode(this.data);return Af.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Af.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return vw(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let d="";try{for(var a=!0,s=JU(this.data),o;o=yield s.next(),e=o.done,!e;a=!0){i=o.value,a=!1;let u=i;typeof u=="string"?d+=u:d+=Af.decode(u,{stream:!0})}}catch(u){r={error:u}}finally{try{!a&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return d+=Af.decode(void 0,{stream:!1}),d}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return VU.baseDecode(this.data);case"Base58Btc":return Js.baseDecode(this.data);case"Base64Url":return Pd.baseDecode(this.data);case"BufferSource":{let e=bD(this.data);if(e==="Uint8Array")return this.data;if(e==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let e=new Uint8Array(this.data.length/2);for(let r=0;r<this.data.length;r+=2){let n=parseInt(this.data.substring(r,r+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[r/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return K1.encode(e)}case"String":return K1.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toArrayBufferAsync();return new Uint8Array(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};(function(t){t.Debug="debug",t.Silent="silent"})(qw||(qw={}));rse=class{constructor(){this.logLevel=qw.Silent}setLogLevel(t){this.logLevel=t}log(t){this.info(t)}info(t){this.logLevel!==qw.Silent&&console.info(t)}error(t){this.logLevel!==qw.Silent&&console.error(t)}},nse=new rse;typeof window<"u"&&(window.enboxLogger=nse);Tw={};LD(Tw,{decode:()=>mx,encodeTo:()=>zw,encodingLength:()=>Fw});ise=Tq,ZU=128,ose=127,sse=~ose,ase=Math.pow(2,31);cse=xD,dse=128,YU=127;use=Math.pow(2,7),lse=Math.pow(2,14),fse=Math.pow(2,21),pse=Math.pow(2,28),hse=Math.pow(2,35),mse=Math.pow(2,42),yse=Math.pow(2,49),gse=Math.pow(2,56),wse=Math.pow(2,63),vse=function(t){return t<use?1:t<lse?2:t<fse?3:t<pse?4:t<hse?5:t<mse?6:t<yse?7:t<gse?8:t<wse?9:10},bse={encode:ise,decode:cse,encodingLength:vse},xse=bse,hx=xse,mx=(t,e=0)=>[hx.decode(t,e),hx.decode.bytes],zw=(t,e,r=0)=>(hx.encode(t,e,r),e),Fw=t=>hx.encodingLength(t),Pse=(t,e)=>{let r=e.byteLength,n=Fw(t),i=n+Fw(r),a=new Uint8Array(i+r);return zw(t,a,0),zw(r,a,n),a.set(e,i),new WD(t,r,e,a)},_se=t=>{let e=GD(t),[r,n]=mx(e),[i,a]=mx(e.subarray(n)),s=e.subarray(n+a);if(s.byteLength!==i)throw new Error("Incorrect length");return new WD(r,i,s,e)},Ese=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Hoe(t.bytes,r.bytes)}},WD=class{constructor(t,e,r,n){this.code=t,this.size=e,this.digest=r,this.bytes=n}},QU=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Tse(r,PD(t),e||Js.encoder);default:return kse(r,PD(t),e||V1.encoder)}},XU=new WeakMap,PD=t=>{let e=XU.get(t);if(e==null){let r=new Map;return XU.set(t,r),r}return e},Dje=class ro{constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==bw)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ase)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return ro.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Pse(e,r);return ro.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return ro.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Ese(e.multihash,n.multihash)}toString(e){return QU(this,e)}toJSON(){return{"/":QU(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof ro)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:a,bytes:s}=r;return new ro(n,i,a,s||eK(n,i,a.bytes))}else if(r[Dse]===!0){let{version:n,multihash:i,code:a}=r,s=_se(i);return ro.create(n,a,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==bw)throw new Error(`Version 0 CID must use dag-pb (code: ${bw}) block encoding`);return new ro(e,r,n,n.bytes)}case 1:{let i=eK(e,r,n.bytes);return new ro(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return ro.create(0,bw,e)}static createV1(e,r){return ro.create(1,e,r)}static decode(e){let[r,n]=ro.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=ro.inspectBytes(e),n=r.size-r.multihashSize,i=GD(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let a=i.subarray(r.multihashSize-r.digestSize),s=new WD(r.multihashCode,r.digestSize,a,i);return[r.version===0?ro.createV0(s):ro.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,f]=mx(e.subarray(r));return r+=f,l},i=n(),a=bw;if(i===18?(i=0,r=0):a=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,o=n(),d=n(),u=r+d,c=u-s;return{version:i,codec:a,multihashCode:o,digestSize:d,multihashSize:c,size:u}}static parse(e,r){let[n,i]=Sse(e,r),a=ro.decode(i);if(a.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return PD(a).set(n,e),a}},Sse=(t,e)=>{switch(t[0]){case"Q":{let r=e||Js;return[Js.prefix,r.decode(`${Js.prefix}${t}`)]}case Js.prefix:{let r=e||Js;return[Js.prefix,r.decode(t)]}case V1.prefix:{let r=e||V1;return[V1.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},Tse=(t,e,r)=>{let{prefix:n}=r;if(n!==Js.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let a=r.encode(t).slice(1);return e.set(n,a),a}else return i},kse=(t,e,r)=>{let{prefix:n}=r,i=e.get(n);if(i==null){let a=r.encode(t);return e.set(n,a),a}else return i},bw=112,Ase=18,eK=(t,e,r)=>{let n=Fw(t),i=n+Fw(e),a=new Uint8Array(i+r.byteLength);return zw(t,a,0),zw(e,a,n),a.set(r,i),a},Dse=Symbol.for("@ipld/js-cid/CID"),Xs=class Wu{static addPrefix(e){var r;let{code:n,data:i,name:a}=e;if(!(a?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=Wu.codeToName.has(n)?n:Wu.nameToCode.get(a),n===void 0)throw new Error(`Unsupported multicodec: ${(r=e.name)!==null&&r!==void 0?r:e.code}`);let s=Tw.encodingLength(n),o=new Uint8Array(s+i.byteLength);return o.set(i,s),Tw.encodeTo(n,o),o}static getCodeFromData(e){let{prefixedData:r}=e,[n,i]=Tw.decode(r);return n}static getCodeFromName(e){let{name:r}=e,n=Wu.nameToCode.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static getNameFromCode(e){let{code:r}=e,n=Wu.codeToName.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static registerCodec(e){Wu.codeToName.set(e.code,e.name),Wu.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:r}=e,[n,i]=Tw.decode(r),a=Wu.codeToName.get(n);if(a===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:r.slice(i),name:a}}};Xs.codeToName=new Map;Xs.nameToCode=new Map;Xs.registerCodec({code:237,name:"ed25519-pub"});Xs.registerCodec({code:4864,name:"ed25519-priv"});Xs.registerCodec({code:236,name:"x25519-pub"});Xs.registerCodec({code:4866,name:"x25519-priv"});Xs.registerCodec({code:231,name:"secp256k1-pub"});Xs.registerCodec({code:4865,name:"secp256k1-priv"});Ije=Lf(wq(),1),ju=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Ise=class{constructor(){this.store=new Map}clear(){return ju(this,void 0,void 0,function*(){this.store.clear()})}open(){return ju(this,void 0,void 0,function*(){})}close(){return ju(this,void 0,void 0,function*(){})}delete(t){return ju(this,void 0,void 0,function*(){return this.store.delete(t)})}get(t){return ju(this,void 0,void 0,function*(){return this.store.get(t)})}has(t){return ju(this,void 0,void 0,function*(){return this.store.has(t)})}list(){return ju(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(t,e){return ju(this,void 0,void 0,function*(){this.store.set(t,e)})}},Ax=class{},Aq={};LD(Aq,{bitGet:()=>Mse,bitLen:()=>jse,bitMask:()=>VD,bitSet:()=>Nse,bytesToHex:()=>Uf,bytesToNumberBE:()=>jf,bytesToNumberLE:()=>Yu,concatBytes:()=>Kf,createHmacDrbg:()=>Rq,ensureBytes:()=>In,equalBytes:()=>Ose,hexToBytes:()=>om,hexToNumber:()=>HD,isBytes:()=>Dc,numberToBytesBE:()=>Ic,numberToBytesLE:()=>sm,numberToHexUnpadded:()=>Iq,numberToVarBytesBE:()=>$se,utf8ToBytes:()=>Bse,validateObject:()=>zf});Dq=BigInt(0),Dx=BigInt(1),Rse=BigInt(2);Cse=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));_d={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};Nse=(t,e,r)=>t|(r?Dx:Dq)<<BigInt(e),VD=t=>(Rse<<BigInt(t-1))-Dx,uD=t=>new Uint8Array(t),rK=t=>Uint8Array.from(t);Use={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Dc(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};lD=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;fD=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),xc=(t,e)=>t<<32-e|t>>>e,zse=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!zse)throw new Error("Non little-endian hardware is not supported");jq=class{clone(){return this._cloneInto()}},Rje={}.toString;Nq=class extends jq{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=fD(this.buffer)}update(t){yx(this);let{view:e,buffer:r,blockLen:n}=this;t=JD(t);let i=t.length;for(let a=0;a<i;){let s=Math.min(n-this.pos,i-a);if(s===n){let o=fD(t);for(;n<=i-a;a+=n)this.process(o,a);continue}r.set(t.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===n&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){yx(this),Lse(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:n,isLE:i}=this,{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>n-a&&(this.process(r,0),a=0);for(let c=a;c<n;c++)e[c]=0;Fse(r,n-8,BigInt(this.length*8),i),this.process(r,0);let s=fD(t),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=o/4,u=this.get();if(d>u.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<d;c++)s.setUint32(4*c,u[c],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:r,length:n,finished:i,destroyed:a,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=a,n%e&&t.buffer.set(r),t}},Gse=(t,e,r)=>t&e^~t&r,Wse=(t,e,r)=>t&e^t&r^e&r,Hse=new Uint32Array([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]),Mu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Nu=new Uint32Array(64),Vse=class extends Nq{constructor(){super(64,32,8,!1),this.A=Mu[0]|0,this.B=Mu[1]|0,this.C=Mu[2]|0,this.D=Mu[3]|0,this.E=Mu[4]|0,this.F=Mu[5]|0,this.G=Mu[6]|0,this.H=Mu[7]|0}get(){let{A:t,B:e,C:r,D:n,E:i,F:a,G:s,H:o}=this;return[t,e,r,n,i,a,s,o]}set(t,e,r,n,i,a,s,o){this.A=t|0,this.B=e|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=a|0,this.G=s|0,this.H=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)Nu[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let l=Nu[c-15],f=Nu[c-2],h=xc(l,7)^xc(l,18)^l>>>3,p=xc(f,17)^xc(f,19)^f>>>10;Nu[c]=p+Nu[c-7]+h+Nu[c-16]|0}let{A:r,B:n,C:i,D:a,E:s,F:o,G:d,H:u}=this;for(let c=0;c<64;c++){let l=xc(s,6)^xc(s,11)^xc(s,25),f=u+l+Gse(s,o,d)+Hse[c]+Nu[c]|0,h=(xc(r,2)^xc(r,13)^xc(r,22))+Wse(r,n,i)|0;u=d,d=o,o=s,s=a+f|0,a=i,i=n,n=r,r=f+h|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,o=o+this.F|0,d=d+this.G|0,u=u+this.H|0,this.set(r,n,i,a,s,o,d,u)}roundClean(){Nu.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Uq=Mq(()=>new Vse),Hn=BigInt(0),Xr=BigInt(1),Rf=BigInt(2),Jse=BigInt(3),_D=BigInt(4),iK=BigInt(5),oK=BigInt(8),Cje=BigInt(9),Zse=BigInt(16);Xse=(t,e)=>(Nr(t,e)&Xr)===Xr,eae=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];sae=BigInt(0),pD=BigInt(1);({bytesToNumberBE:cae,hexToBytes:dae}=Aq),Of={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){let{Err:e}=Of;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");let r=t[1],n=t.subarray(2,r+2);if(!r||n.length!==r)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:cae(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=Of,r=typeof t=="string"?dae(t):t;if(!Dc(r))throw new Error("ui8a expected");let n=r.length;if(n<2||r[0]!=48)throw new e("Invalid signature tag");if(r[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:a}=Of._parseInt(r.subarray(2)),{d:s,l:o}=Of._parseInt(a);if(o.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,r=u=>{let c=u.toString(16);return c.length&1?`0${c}`:c},n=e(r(t.s)),i=e(r(t.r)),a=n.length/2,s=i.length/2,o=r(a),d=r(s);return`30${r(s+a+4)}02${d}${i}02${o}${n}`}},Dd=BigInt(0),Vs=BigInt(1),$je=BigInt(2),sK=BigInt(3),Oje=BigInt(4);Gq=class extends jq{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,qse(t);let r=JD(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?t.create().update(r).digest():r);for(let a=0;a<i.length;a++)i[a]^=54;this.iHash.update(i),this.oHash=t.create();for(let a=0;a<i.length;a++)i[a]^=106;this.oHash.update(i),i.fill(0)}update(t){return yx(this),this.iHash.update(t),this}digestInto(t){yx(this),Cq(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:r,finished:n,destroyed:i,blockLen:a,outputLen:s}=this;return t=t,t.finished=n,t.destroyed=i,t.blockLen=a,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Wq=(t,e,r)=>new Gq(t,e).update(r).digest();Wq.create=(t,e)=>new Gq(t,e);Vq=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),aK=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),hae=BigInt(1),SD=BigInt(2),cK=(t,e)=>(t+e/SD)/e;TD=YD(Vq,void 0,void 0,{sqrt:mae}),gs=Hq({a:BigInt(0),b:BigInt(7),Fp:TD,n:aK,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=aK,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-hae*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),a=r,s=BigInt("0x100000000000000000000000000000000"),o=cK(a*t,e),d=cK(-n*t,e),u=Nr(t-o*r-d*i,e),c=Nr(-o*n-d*a,e),l=u>s,f=c>s;if(l&&(u=e-u),f&&(c=e-c),u>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:u,k2neg:f,k2:c}}}},Uq),Bje=BigInt(0),jje=gs.ProjectivePoint;J1=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,hD=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Pc=(t,e)=>t<<32-e|t>>>e,Mje=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;vae=class{clone(){return this._cloneInto()}},Nje={}.toString;_ae=(t,e,r)=>t&e^~t&r,Eae=(t,e,r)=>t&e^t&r^e&r,Sae=class extends vae{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=hD(this.buffer)}update(t){dK(this);let{view:e,buffer:r,blockLen:n}=this;t=Zq(t);let i=t.length;for(let a=0;a<i;){let s=Math.min(n-this.pos,i-a);if(s===n){let o=hD(t);for(;n<=i-a;a+=n)this.process(o,a);continue}r.set(t.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===n&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){dK(this),gae(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:n,isLE:i}=this,{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>n-a&&(this.process(r,0),a=0);for(let c=a;c<n;c++)e[c]=0;Pae(r,n-8,BigInt(this.length*8),i),this.process(r,0);let s=hD(t),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=o/4,u=this.get();if(d>u.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<d;c++)s.setUint32(4*c,u[c],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:r,length:n,finished:i,destroyed:a,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=a,n%e&&t.buffer.set(r),t}},Tae=new Uint32Array([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]),Uu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ku=new Uint32Array(64),kae=class extends Sae{constructor(){super(64,32,8,!1),this.A=Uu[0]|0,this.B=Uu[1]|0,this.C=Uu[2]|0,this.D=Uu[3]|0,this.E=Uu[4]|0,this.F=Uu[5]|0,this.G=Uu[6]|0,this.H=Uu[7]|0}get(){let{A:t,B:e,C:r,D:n,E:i,F:a,G:s,H:o}=this;return[t,e,r,n,i,a,s,o]}set(t,e,r,n,i,a,s,o){this.A=t|0,this.B=e|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=a|0,this.G=s|0,this.H=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)Ku[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let l=Ku[c-15],f=Ku[c-2],h=Pc(l,7)^Pc(l,18)^l>>>3,p=Pc(f,17)^Pc(f,19)^f>>>10;Ku[c]=p+Ku[c-7]+h+Ku[c-16]|0}let{A:r,B:n,C:i,D:a,E:s,F:o,G:d,H:u}=this;for(let c=0;c<64;c++){let l=Pc(s,6)^Pc(s,11)^Pc(s,25),f=u+l+_ae(s,o,d)+Tae[c]+Ku[c]|0,h=(Pc(r,2)^Pc(r,13)^Pc(r,22))+Eae(r,n,i)|0;u=d,d=o,o=s,s=a+f|0,a=i,i=n,n=r,r=f+h|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,o=o+this.F|0,d=d+this.G|0,u=u+this.H|0,this.set(r,n,i,a,s,o,d,u)}roundClean(){Ku.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Gw=bae(()=>new kae);Dae=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Yq=class{static digest(t){return Dae(this,arguments,void 0,function*({data:e}){return Gw(e)})}},Iae=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},uK="urn:jwk:";Ci=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Cae=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},ji=class Ec{static adjustSignatureToLowS(e){return Ci(this,arguments,void 0,function*({signature:r}){let n=gs.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return Ci(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield Ec.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield Ec.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static compressPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){return gs.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return Ci(this,arguments,void 0,function*({key:r}){let n=yield Ec.privateKeyToBytes({privateKey:r}),i=yield Ec.getCurvePoint({keyBytes:n}),a={kty:"EC",crv:"secp256k1",x:tt.uint8Array(i.x).toBase64Url(),y:tt.uint8Array(i.y).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertDerToCompactSignature(e){return Ci(this,arguments,void 0,function*({derSignature:r}){return gs.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){return gs.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return Ci(this,void 0,void 0,function*(){let e=gs.utils.randomPrivateKey(),r=yield Ec.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return Ci(this,arguments,void 0,function*({key:r}){var n;if(!(Mf(r)&&r.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=r,a=Cae(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return Ci(this,arguments,void 0,function*({privateKey:r}){if(!Mf(r))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Ci(this,arguments,void 0,function*({publicKey:r}){if(!(XD(r)&&r.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=tt.base64Url(r.x).toUint8Array(),a=tt.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...a])})}static sharedSecret(e){return Ci(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Ec.privateKeyToBytes({privateKey:r}),a=yield Ec.publicKeyToBytes({publicKey:n});return gs.getSharedSecret(i,a,!0).slice(1)})}static sign(e){return Ci(this,arguments,void 0,function*({data:r,key:n}){let i=yield Ec.privateKeyToBytes({privateKey:n}),a=Gw(r);return gs.sign(a,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ci(this,arguments,void 0,function*({privateKeyBytes:r}){return gs.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){try{gs.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Ci(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Ec.publicKeyToBytes({publicKey:r}),s=Gw(i);return gs.verify(n,s,a,{lowS:!1})})}static getCurvePoint(e){return Ci(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=gs.getPublicKey(r));let n=gs.ProjectivePoint.fromHex(r),i=Ic(n.x,32),a=Ic(n.y,32);return{x:i,y:a}})}},Qq=YD(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),$ae=Qq.create(BigInt("-3")),Oae=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Bae=Hq({a:$ae,b:Oae,Fp:Qq,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Uq),zs=Bae,$i=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},jae=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},no=class Sc{static adjustSignatureToLowS(e){return $i(this,arguments,void 0,function*({signature:r}){let n=zs.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return $i(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield Sc.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield Sc.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static compressPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){return zs.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return $i(this,arguments,void 0,function*({key:r}){let n=yield Sc.privateKeyToBytes({privateKey:r}),i=yield Sc.getCurvePoint({keyBytes:n}),a={kty:"EC",crv:"P-256",x:tt.uint8Array(i.x).toBase64Url(),y:tt.uint8Array(i.y).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertDerToCompactSignature(e){return $i(this,arguments,void 0,function*({derSignature:r}){return zs.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){return zs.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return $i(this,void 0,void 0,function*(){let e=zs.utils.randomPrivateKey(),r=yield Sc.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return $i(this,arguments,void 0,function*({key:r}){var n;if(!(Mf(r)&&r.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=r,a=jae(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return $i(this,arguments,void 0,function*({privateKey:r}){if(!Mf(r))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return $i(this,arguments,void 0,function*({publicKey:r}){if(!(XD(r)&&r.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=tt.base64Url(r.x).toUint8Array(),a=tt.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...a])})}static sharedSecret(e){return $i(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Sc.privateKeyToBytes({privateKey:r}),a=yield Sc.publicKeyToBytes({publicKey:n});return zs.getSharedSecret(i,a,!0).slice(1)})}static sign(e){return $i(this,arguments,void 0,function*({data:r,key:n}){let i=yield Sc.privateKeyToBytes({privateKey:n}),a=Gw(r);return zs.sign(a,i).toCompactRawBytes()})}static validatePrivateKey(e){return $i(this,arguments,void 0,function*({privateKeyBytes:r}){return zs.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){try{zs.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return $i(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Sc.publicKeyToBytes({publicKey:r}),s=Gw(i);return zs.verify(n,s,a,{lowS:!1})})}static getCurvePoint(e){return $i(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=zs.getPublicKey(r));let n=zs.ProjectivePoint.fromHex(r),i=Ic(n.x,32),a=Ic(n.y,32);return{x:i,y:a}})}},Ed=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},lK=class extends Ax{bytesToPrivateKey(t){return Ed(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"ES256K":case"secp256k1":{let n=yield ji.bytesToPrivateKey({privateKeyBytes:r});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield no.bytesToPrivateKey({privateKeyBytes:r});return n.alg="ES256",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}bytesToPublicKey(t){return Ed(this,arguments,void 0,function*({algorithm:e,publicKeyBytes:r}){switch(e){case"ES256K":case"secp256k1":{let n=yield ji.bytesToPublicKey({publicKeyBytes:r});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield no.bytesToPublicKey({publicKeyBytes:r});return n.alg="ES256",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Ed(this,arguments,void 0,function*({key:e}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let r=yield ji.computePublicKey({key:e});return r.alg="ES256K",r}case"P-256":{let r=yield no.computePublicKey({key:e});return r.alg="ES256",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Ed(this,arguments,void 0,function*({algorithm:e}){switch(e){case"ES256K":case"secp256k1":{let r=yield ji.generateKey();return r.alg="ES256K",r}case"ES256":case"secp256r1":{let r=yield no.generateKey();return r.alg="ES256",r}}})}getPublicKey(t){return Ed(this,arguments,void 0,function*({key:e}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let r=yield ji.getPublicKey({key:e});return r.alg="ES256K",r}case"P-256":{let r=yield no.getPublicKey({key:e});return r.alg="ES256",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}sign(t){return Ed(this,arguments,void 0,function*({key:e,data:r}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":return yield ji.sign({key:e,data:r});case"P-256":return yield no.sign({key:e,data:r});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}verify(t){return Ed(this,arguments,void 0,function*({key:e,signature:r,data:n}){if(!XD(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(e.crv){case"secp256k1":return yield ji.verify({key:e,signature:r,data:n});case"P-256":return yield no.verify({key:e,signature:r,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Ed(this,arguments,void 0,function*({privateKey:e}){switch(e.crv){case"secp256k1":return yield ji.privateKeyToBytes({privateKey:e});case"P-256":return yield no.privateKeyToBytes({privateKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}publicKeyToBytes(t){return Ed(this,arguments,void 0,function*({publicKey:e}){switch(e.crv){case"secp256k1":return yield ji.publicKeyToBytes({publicKey:e});case"P-256":return yield no.publicKeyToBytes({publicKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}},q1=BigInt(4294967295),kD=BigInt(32);Nae=(t,e)=>BigInt(t>>>0)<<kD|BigInt(e>>>0),Uae=(t,e,r)=>t>>>r,Kae=(t,e,r)=>t<<32-r|e>>>r,qae=(t,e,r)=>t>>>r|e<<32-r,Lae=(t,e,r)=>t<<32-r|e>>>r,zae=(t,e,r)=>t<<64-r|e>>>r-32,Fae=(t,e,r)=>t>>>r-32|e<<64-r,Gae=(t,e)=>e,Wae=(t,e)=>t,Hae=(t,e,r)=>t<<r|e>>>32-r,Vae=(t,e,r)=>e<<r|t>>>32-r,Jae=(t,e,r)=>e<<r-32|t>>>64-r,Zae=(t,e,r)=>t<<r-32|e>>>64-r;Qae=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Xae=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ece=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),tce=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,rce=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),nce=(t,e,r,n,i,a)=>e+r+n+i+a+(t/2**32|0)|0,ice={fromBig:Xq,split:Mae,toBig:Nae,shrSH:Uae,shrSL:Kae,rotrSH:qae,rotrSL:Lae,rotrBH:zae,rotrBL:Fae,rotr32H:Gae,rotr32L:Wae,rotlSH:Hae,rotlSL:Vae,rotlBH:Jae,rotlBL:Zae,add:Yae,add3L:Qae,add3H:Xae,add4L:ece,add4H:tce,add5H:nce,add5L:rce},Dt=ice,[oce,sce]=Dt.split(["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(t=>BigInt(t))),qu=new Uint32Array(80),Lu=new Uint32Array(80),ace=class extends Nq{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:r,Bl:n,Ch:i,Cl:a,Dh:s,Dl:o,Eh:d,El:u,Fh:c,Fl:l,Gh:f,Gl:h,Hh:p,Hl:m}=this;return[t,e,r,n,i,a,s,o,d,u,c,l,f,h,p,m]}set(t,e,r,n,i,a,s,o,d,u,c,l,f,h,p,m){this.Ah=t|0,this.Al=e|0,this.Bh=r|0,this.Bl=n|0,this.Ch=i|0,this.Cl=a|0,this.Dh=s|0,this.Dl=o|0,this.Eh=d|0,this.El=u|0,this.Fh=c|0,this.Fl=l|0,this.Gh=f|0,this.Gl=h|0,this.Hh=p|0,this.Hl=m|0}process(t,e){for(let v=0;v<16;v++,e+=4)qu[v]=t.getUint32(e),Lu[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let E=qu[v-15]|0,T=Lu[v-15]|0,D=Dt.rotrSH(E,T,1)^Dt.rotrSH(E,T,8)^Dt.shrSH(E,T,7),R=Dt.rotrSL(E,T,1)^Dt.rotrSL(E,T,8)^Dt.shrSL(E,T,7),N=qu[v-2]|0,B=Lu[v-2]|0,G=Dt.rotrSH(N,B,19)^Dt.rotrBH(N,B,61)^Dt.shrSH(N,B,6),z=Dt.rotrSL(N,B,19)^Dt.rotrBL(N,B,61)^Dt.shrSL(N,B,6),U=Dt.add4L(R,z,Lu[v-7],Lu[v-16]),H=Dt.add4H(U,D,G,qu[v-7],qu[v-16]);qu[v]=H|0,Lu[v]=U|0}let{Ah:r,Al:n,Bh:i,Bl:a,Ch:s,Cl:o,Dh:d,Dl:u,Eh:c,El:l,Fh:f,Fl:h,Gh:p,Gl:m,Hh:g,Hl:_}=this;for(let v=0;v<80;v++){let E=Dt.rotrSH(c,l,14)^Dt.rotrSH(c,l,18)^Dt.rotrBH(c,l,41),T=Dt.rotrSL(c,l,14)^Dt.rotrSL(c,l,18)^Dt.rotrBL(c,l,41),D=c&f^~c&p,R=l&h^~l&m,N=Dt.add5L(_,T,R,sce[v],Lu[v]),B=Dt.add5H(N,g,E,D,oce[v],qu[v]),G=N|0,z=Dt.rotrSH(r,n,28)^Dt.rotrBH(r,n,34)^Dt.rotrBH(r,n,39),U=Dt.rotrSL(r,n,28)^Dt.rotrBL(r,n,34)^Dt.rotrBL(r,n,39),H=r&i^r&s^i&s,ee=n&a^n&o^a&o;g=p|0,_=m|0,p=f|0,m=h|0,f=c|0,h=l|0,{h:c,l}=Dt.add(d|0,u|0,B|0,G|0),d=s|0,u=o|0,s=i|0,o=a|0,i=r|0,a=n|0;let I=Dt.add3L(G,U,ee);r=Dt.add3H(I,B,z,H),n=I|0}({h:r,l:n}=Dt.add(this.Ah|0,this.Al|0,r|0,n|0)),{h:i,l:a}=Dt.add(this.Bh|0,this.Bl|0,i|0,a|0),{h:s,l:o}=Dt.add(this.Ch|0,this.Cl|0,s|0,o|0),{h:d,l:u}=Dt.add(this.Dh|0,this.Dl|0,d|0,u|0),{h:c,l}=Dt.add(this.Eh|0,this.El|0,c|0,l|0),{h:f,l:h}=Dt.add(this.Fh|0,this.Fl|0,f|0,h|0),{h:p,l:m}=Dt.add(this.Gh|0,this.Gl|0,p|0,m|0),{h:g,l:_}=Dt.add(this.Hh|0,this.Hl|0,g|0,_|0),this.set(r,n,i,a,s,o,d,u,c,l,f,h,p,m,g,_)}roundClean(){qu.fill(0),Lu.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},eL=Mq(()=>new ace),Ma=BigInt(0),ms=BigInt(1),L1=BigInt(2),cce=BigInt(8),dce={zip215:!0};xw=BigInt(0),mD=BigInt(1);Ww=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fK=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Uje=BigInt(0),pce=BigInt(1),AD=BigInt(2),hce=BigInt(5),pK=BigInt(10),mce=BigInt(20),yce=BigInt(40),hK=BigInt(80);Qs=YD(Ww,void 0,!0),Hw={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Qs,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:eL,randomBytes:ZD,adjustScalarBytes:rL,uvRatio:gce},Df=tI(Hw);Kje=tI({...Hw,domain:nL}),qje=tI({...Hw,domain:nL,prehash:eL}),kw=fce({P:Ww,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=Ww,{pow_p_5_8:r,b2:n}=tL(t);return Nr(sn(r,BigInt(3),e)*n,e)},adjustScalarBytes:rL,randomBytes:ZD});bce=(Qs.ORDER+BigInt(3))/BigInt(8),Lje=Qs.pow(AD,bce),zje=Qs.sqrt(Qs.neg(Qs.ONE)),Fje=(Qs.ORDER-BigInt(5))/BigInt(8),Gje=BigInt(486662),Wje=iae(Qs,Qs.neg(BigInt(486664))),Hje=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Vje=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Jje=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Zje=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Yje=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fs=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},xce=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Mi=class Hu{static bytesToPrivateKey(e){return Fs(this,arguments,void 0,function*({privateKeyBytes:r}){let n=Df.getPublicKey(r),i={crv:"Ed25519",d:tt.uint8Array(r).toBase64Url(),kty:"OKP",x:tt.uint8Array(n).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return Fs(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"Ed25519",x:tt.uint8Array(r).toBase64Url()};return n.kid=yield lr({jwk:n}),n})}static computePublicKey(e){return Fs(this,arguments,void 0,function*({key:r}){let n=yield Hu.privateKeyToBytes({privateKey:r}),i=Df.getPublicKey(n),a={kty:"OKP",crv:"Ed25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertPrivateKeyToX25519(e){return Fs(this,arguments,void 0,function*({privateKey:r}){let n=yield Hu.privateKeyToBytes({privateKey:r}),i=vce(n),a=kw.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:tt.uint8Array(i).toBase64Url(),x:tt.uint8Array(a).toBase64Url()};return s.kid=yield lr({jwk:s}),s})}static convertPublicKeyToX25519(e){return Fs(this,arguments,void 0,function*({publicKey:r}){let n=yield Hu.publicKeyToBytes({publicKey:r});if(!(yield Hu.validatePublicKey({publicKeyBytes:n})))throw new Error("Ed25519: Invalid public key.");let i=wce(n),a={kty:"OKP",crv:"X25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static generateKey(){return Fs(this,void 0,void 0,function*(){let e=Df.utils.randomPrivateKey(),r=yield Hu.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return Fs(this,arguments,void 0,function*({key:r}){var n;if(!(Cd(r)&&r.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=r,a=xce(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return Fs(this,arguments,void 0,function*({privateKey:r}){if(!Cd(r))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Fs(this,arguments,void 0,function*({publicKey:r}){if(!eI(r))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return tt.base64Url(r.x).toUint8Array()})}static sign(e){return Fs(this,arguments,void 0,function*({key:r,data:n}){let i=yield Hu.privateKeyToBytes({privateKey:r});return Df.sign(n,i)})}static validatePublicKey(e){return Fs(this,arguments,void 0,function*({publicKeyBytes:r}){try{Df.ExtendedPoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Fs(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Hu.publicKeyToBytes({publicKey:r});return Df.verify(n,i,a)})}},Sd=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Pce=class extends Ax{bytesToPrivateKey(t){return Sd(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"Ed25519":{let n=yield Mi.bytesToPrivateKey({privateKeyBytes:r});return n.alg="EdDSA",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}bytesToPublicKey(t){return Sd(this,arguments,void 0,function*({algorithm:e,publicKeyBytes:r}){switch(e){case"Ed25519":{let n=yield Mi.bytesToPublicKey({publicKeyBytes:r});return n.alg="EdDSA",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Sd(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let r=yield Mi.computePublicKey({key:e});return r.alg="EdDSA",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Sd(this,arguments,void 0,function*({algorithm:e}){switch(e){case"Ed25519":{let r=yield Mi.generateKey();return r.alg="EdDSA",r}}})}getPublicKey(t){return Sd(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let r=yield Mi.getPublicKey({key:e});return r.alg="EdDSA",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}sign(t){return Sd(this,arguments,void 0,function*({key:e,data:r}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":return yield Mi.sign({key:e,data:r});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}verify(t){return Sd(this,arguments,void 0,function*({key:e,signature:r,data:n}){if(!eI(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(e.crv){case"Ed25519":return yield Mi.verify({key:e,signature:r,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Sd(this,arguments,void 0,function*({privateKey:e}){switch(e.crv){case"Ed25519":return yield Mi.privateKeyToBytes({privateKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}publicKeyToBytes(t){return Sd(this,arguments,void 0,function*({publicKey:e}){switch(e.crv){case"Ed25519":return yield Mi.publicKeyToBytes({publicKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}},_ce=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Ece=class extends Ax{digest(t){return _ce(this,arguments,void 0,function*({algorithm:e,data:r}){switch(e){case"SHA-256":return yield Yq.digest({data:r})}})}},zu=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Sce=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Vh=class Aw{static bytesToPrivateKey(e){return zu(this,arguments,void 0,function*({privateKeyBytes:r}){let n=kw.getPublicKey(r),i={kty:"OKP",crv:"X25519",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return zu(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"X25519",x:tt.uint8Array(r).toBase64Url()};return n.kid=yield lr({jwk:n}),n})}static computePublicKey(e){return zu(this,arguments,void 0,function*({key:r}){let n=yield Aw.privateKeyToBytes({privateKey:r}),i=kw.getPublicKey(n),a={kty:"OKP",crv:"X25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static generateKey(){return zu(this,void 0,void 0,function*(){let e=kw.utils.randomPrivateKey(),r=yield Aw.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return zu(this,arguments,void 0,function*({key:r}){var n;if(!(Cd(r)&&r.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=r,a=Sce(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return zu(this,arguments,void 0,function*({privateKey:r}){if(!Cd(r))throw new Error("X25519: The provided key is not a valid OKP private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return zu(this,arguments,void 0,function*({publicKey:r}){if(!eI(r))throw new Error("X25519: The provided key is not a valid OKP public key.");return tt.base64Url(r.x).toUint8Array()})}static sharedSecret(e){return zu(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Aw.privateKeyToBytes({privateKey:r}),a=yield Aw.publicKeyToBytes({publicKey:n});return kw.getSharedSecret(i,a)})}},Pw=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Tce=class extends Ax{bytesToPrivateKey(t){return Pw(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"X25519":return Vh.bytesToPrivateKey({privateKeyBytes:r});default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Pw(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return Vh.computePublicKey({key:e});default:throw new Ys(zo.AlgorithmNotSupported,`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Pw(this,arguments,void 0,function*({algorithm:e}){switch(e){case"X25519":return Vh.generateKey();default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}getPublicKey(t){return Pw(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return Vh.getPublicKey({key:e});default:throw new Ys(zo.AlgorithmNotSupported,`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Pw(this,arguments,void 0,function*({privateKey:e}){return Vh.privateKeyToBytes({privateKey:e})})}},Td=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},yD={Ed25519:{implementation:Pce,names:["Ed25519"]},secp256k1:{implementation:lK,names:["ES256K","secp256k1"]},secp256r1:{implementation:lK,names:["ES256","secp256r1"]},"SHA-256":{implementation:Ece,names:["SHA-256"]},X25519:{implementation:Tce,names:["X25519"]}},Ka=class{constructor(t){var e;this._algorithmInstances=new Map,this._keyStore=(e=t?.keyStore)!==null&&e!==void 0?e:new Ise}digest(t){return Td(this,arguments,void 0,function*({algorithm:e,data:r}){return yield this.getAlgorithm({algorithm:e}).digest({algorithm:e,data:r})})}exportKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){return yield this.getPrivateKey({keyUri:e})})}generateKey(t){return Td(this,arguments,void 0,function*({algorithm:e}){let r=yield this.getAlgorithm({algorithm:e}).generateKey({algorithm:e});if(r?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let n=`${uK}${r.kid}`;return yield this._keyStore.set(n,r),n})}getKeyUri(t){return Td(this,arguments,void 0,function*({key:e}){let r=yield lr({jwk:e});return`${uK}${r}`})}getPublicKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){let r=yield this.getPrivateKey({keyUri:e}),n=this.getAlgorithmName({key:r});return yield this.getAlgorithm({algorithm:n}).getPublicKey({key:r})})}importKey(t){return Td(this,arguments,void 0,function*({key:e}){var r;if(!Rae(e))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let n=structuredClone(e);(r=n.kid)!==null&&r!==void 0||(n.kid=yield lr({jwk:n}));let i=yield this.getKeyUri({key:n});return yield this._keyStore.set(i,n),i})}sign(t){return Td(this,arguments,void 0,function*({keyUri:e,data:r}){let n=yield this.getPrivateKey({keyUri:e}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:r,key:n})})}verify(t){return Td(this,arguments,void 0,function*({key:e,signature:r,data:n}){let i=this.getAlgorithmName({key:e});return this.getAlgorithm({algorithm:i}).verify({key:e,signature:r,data:n})})}getAlgorithm({algorithm:t}){var e;let r=(e=yD[t])===null||e===void 0?void 0:e.implementation;if(!r)throw new Error(`Algorithm not supported: ${t}`);return this._algorithmInstances.has(r)||this._algorithmInstances.set(r,new r),this._algorithmInstances.get(r)}getAlgorithmName({key:t}){let e=t.alg,r=t.crv;for(let n in yD){let i=yD[n];if(e&&i.names.includes(e)||r&&i.names.includes(r))return n}throw new Error(`Unable to determine algorithm based on provided input: alg=${e}, crv=${r}`)}getPrivateKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){let r=yield this._keyStore.get(e);if(!r)throw new Error(`Key not found: ${e}`);return r})}},kce=class DD{static getJoseSignatureAlgorithmFromPublicKey(e){let r={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(r).includes(e.alg))return e.alg;if(e.crv&&Object.keys(r).includes(e.crv))return r[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(r).join(", ")}. Supported 'crv' values: ${Object.keys(r).join(", ")}.`)}static randomBytes(e){return xae(e)}static randomUuid(){return J1.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let r=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let a=DD.randomBytes(Math.ceil(e/2));n=new DataView(a.buffer).getUint16(0,!1)%i}while(n>r)}else{let i=Math.pow(10,10);do{let a=DD.randomBytes(4);n=new DataView(a.buffer).getUint32(0,!1)%i}while(n>r)}return n.toString().padStart(e,"0")}},Ace=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];be=class{constructor(t,e,r){this.major=t,this.majorEncoded=t<<5,this.name=e,this.terminal=r}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,e){return t===e||t.major===e.major&&t.name===e.name}};be.uint=new be(0,"uint",!0);be.negint=new be(1,"negint",!0);be.bytes=new be(2,"bytes",!0);be.string=new be(3,"string",!0);be.array=new be(4,"array",!1);be.map=new be(5,"map",!1);be.tag=new be(6,"tag",!1);be.float=new be(7,"float",!0);be.false=new be(7,"false",!0);be.true=new be(7,"true",!0);be.null=new be(7,"null",!0);be.undefined=new be(7,"undefined",!0);be.break=new be(7,"break",!0);Qe=class{constructor(t,e,r){this.type=t,this.value=e,this.encodedLength=r,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}},Xw=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Rce=new TextEncoder;Cce=24,$ce=200,Oce=Xw?t=>t.length>=Cce?globalThis.Buffer.from(t):mK(t):t=>t.length>=$ce?Rce.encode(t):mK(t),kd=t=>Uint8Array.from(t),Bce=Xw?(t,e,r)=>gx(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),jce=Xw?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),iL(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},Mce=Xw?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);Nce=256,sL=class{constructor(t=Nce){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let e=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let r=e.length-(this.maxCursor-this.cursor)-1;e.set(t,r)}else{if(e){let r=e.length-(this.maxCursor-this.cursor)-1;r<e.length&&(this.chunks[this.chunks.length-1]=e.subarray(0,r),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(e=Mce(this.chunkSize),this.chunks.push(e),this.maxCursor+=e.length,this._initReuseChunk===null&&(this._initReuseChunk=e),e.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let e;if(this.chunks.length===1){let r=this.chunks[0];t&&this.cursor>r.length/2?(e=this.cursor===r.length?r:r.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):e=Bce(r,0,this.cursor)}else e=jce(this.chunks,this.cursor);return t&&this.reset(),e}},Uce=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let e=this.dest.subarray(0,this.cursor);return t&&this.reset(),e}},an="CBOR decode error:",aL="CBOR encode error:",e0=[];e0[23]=1;e0[24]=2;e0[25]=3;e0[26]=5;e0[27]=9;Ni=[24,256,65536,4294967296,BigInt("18446744073709551616")];Vf.encodedSize=function(t){return ta.encodedSize(t.value)};ta.encodedSize=function(t){return t<Ni[0]?1:t<Ni[1]?2:t<Ni[2]?3:t<Ni[3]?5:9};Vf.compareTokens=function(t,e){return t.value<e.value?-1:t.value>e.value?1:0};rI=BigInt(-1),cL=BigInt(1);nI.encodedSize=function(t){let e=t.value,r=typeof e=="bigint"?e*rI-cL:e*-1-1;return r<Ni[0]?1:r<Ni[1]?2:r<Ni[2]?3:r<Ni[3]?5:9};nI.compareTokens=function(t,e){return t.value<e.value?1:t.value>e.value?-1:0};Ix.encodedSize=function(t){let e=wx(t);return ta.encodedSize(e.length)+e.length};Ix.compareTokens=function(t,e){return Xce(wx(t),wx(e))};yK=new TextDecoder,ede=32;ade=Ix;iI.compareTokens=Vf.compareTokens;iI.encodedSize=function(t){return ta.encodedSize(t.value)};oI.compareTokens=Vf.compareTokens;oI.encodedSize=function(t){return ta.encodedSize(t.value)};sI.compareTokens=Vf.compareTokens;sI.encodedSize=function(t){return ta.encodedSize(t.value)};dL=20,uL=21,lL=22,fL=23;cI.encodedSize=function(t,e){let r=t.value;if(r===!1||r===!0||r===null||r===void 0)return 1;if(!e||e.float64!==!0){hL(r);let n=dI(Na,1);if(r===n||Number.isNaN(r))return 3;if(mL(r),n=uI(Na,1),r===n)return 5}return 9};pL=new ArrayBuffer(9),Ws=new DataView(pL,1),Na=new Uint8Array(pL,0);cI.compareTokens=Vf.compareTokens;Ce=[];for(let t=0;t<=23;t++)Ce[t]=rr;Ce[24]=Kce;Ce[25]=qce;Ce[26]=Lce;Ce[27]=zce;Ce[28]=rr;Ce[29]=rr;Ce[30]=rr;Ce[31]=rr;for(let t=32;t<=55;t++)Ce[t]=rr;Ce[56]=Fce;Ce[57]=Gce;Ce[58]=Wce;Ce[59]=Hce;Ce[60]=rr;Ce[61]=rr;Ce[62]=rr;Ce[63]=rr;for(let t=64;t<=87;t++)Ce[t]=Vce;Ce[88]=Jce;Ce[89]=Zce;Ce[90]=Yce;Ce[91]=Qce;Ce[92]=rr;Ce[93]=rr;Ce[94]=rr;Ce[95]=Rx("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)Ce[t]=rde;Ce[120]=nde;Ce[121]=ide;Ce[122]=ode;Ce[123]=sde;Ce[124]=rr;Ce[125]=rr;Ce[126]=rr;Ce[127]=Rx("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)Ce[t]=cde;Ce[152]=dde;Ce[153]=ude;Ce[154]=lde;Ce[155]=fde;Ce[156]=rr;Ce[157]=rr;Ce[158]=rr;Ce[159]=pde;for(let t=160;t<=183;t++)Ce[t]=hde;Ce[184]=mde;Ce[185]=yde;Ce[186]=gde;Ce[187]=wde;Ce[188]=rr;Ce[189]=rr;Ce[190]=rr;Ce[191]=vde;for(let t=192;t<=215;t++)Ce[t]=bde;Ce[216]=xde;Ce[217]=Pde;Ce[218]=_de;Ce[219]=Ede;Ce[220]=rr;Ce[221]=rr;Ce[222]=rr;Ce[223]=rr;for(let t=224;t<=243;t++)Ce[t]=Rx("simple values are not supported");Ce[244]=rr;Ce[245]=rr;Ce[246]=rr;Ce[247]=Sde;Ce[248]=Rx("simple values are not supported");Ce[249]=kde;Ce[250]=Ade;Ce[251]=Dde;Ce[252]=rr;Ce[253]=rr;Ce[254]=rr;Ce[255]=Tde;Od=[];for(let t=0;t<24;t++)Od[t]=new Qe(be.uint,t,1);for(let t=-1;t>=-24;t--)Od[31-t]=new Qe(be.negint,t,1);Od[64]=new Qe(be.bytes,new Uint8Array(0),1);Od[96]=new Qe(be.string,"",1);Od[128]=new Qe(be.array,0,1);Od[160]=new Qe(be.map,0,1);Od[244]=new Qe(be.false,!1,1);Od[245]=new Qe(be.true,!0,1);Od[246]=new Qe(be.null,null,1);Cde=Object.freeze({float64:!0,mapSorter:Mde,quickEncodeToken:Rde});Ode=$de(),Bde=new sL,gK=class gL{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${aL} object contains circular references`);return new gL(r,e)}},Fu={null:new Qe(be.null,null),undefined:new Qe(be.undefined,void 0),true:new Qe(be.true,!0),false:new Qe(be.false,!1),emptyArray:new Qe(be.array,0),emptyMap:new Qe(be.map,0)},Xu={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new Qe(be.float,t):t>=0?new Qe(be.uint,t):new Qe(be.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new Qe(be.uint,t):new Qe(be.negint,t)},Uint8Array(t,e,r,n){return new Qe(be.bytes,t)},string(t,e,r,n){return new Qe(be.string,t)},boolean(t,e,r,n){return t?Fu.true:Fu.false},null(t,e,r,n){return Fu.null},undefined(t,e,r,n){return Fu.undefined},ArrayBuffer(t,e,r,n){return new Qe(be.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new Qe(be.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Fu.emptyArray,new Qe(be.break)]:Fu.emptyArray;n=gK.createCheck(n,t);let i=[],a=0;for(let s of t)i[a++]=Z1(s,r,n);return r.addBreakTokens?[new Qe(be.array,t.length),i,new Qe(be.break)]:[new Qe(be.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",a=i?t.keys():Object.keys(t),s=i?t.size:a.length,o;if(s){o=new Array(s),n=gK.createCheck(n,t);let d=!i&&r.ignoreUndefinedProperties,u=0;for(let c of a){let l=i?t.get(c):t[c];d&&l===void 0||(o[u++]=[Z1(c,r,n),Z1(l,r,n)])}u<s&&(o.length=u)}return o?.length?(jde(o,r),r.addBreakTokens?[new Qe(be.map,o.length),o,new Qe(be.break)]:[new Qe(be.map,o.length),o]):r.addBreakTokens===!0?[Fu.emptyMap,new Qe(be.break)]:Fu.emptyMap}};Xu.Map=Xu.Object;Xu.Buffer=Xu.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Xu[`${t}Array`]=Xu.DataView;Qje=be.uint.majorEncoded,Xje=be.negint.majorEncoded,e4e=be.bytes.majorEncoded,t4e=be.string.majorEncoded,r4e=be.array.majorEncoded,n4e=be.float.majorEncoded|dL,i4e=be.float.majorEncoded|uL,o4e=be.float.majorEncoded|lL,s4e=be.float.majorEncoded|fL,a4e=BigInt(-1),c4e=BigInt(1);d4e=Symbol.for("DONE"),u4e=Symbol.for("BREAK");(function(t){t[t.OKP=1]="OKP",t[t.EC2=2]="EC2",t[t.Symmetric=4]="Symmetric"})(vK||(vK={}));(function(t){t[t.P256=1]="P256",t[t.P384=2]="P384",t[t.P521=3]="P521",t[t.X25519=4]="X25519",t[t.X448=5]="X448",t[t.Ed25519=6]="Ed25519",t[t.Ed448=7]="Ed448",t[t.Secp256k1=8]="Secp256k1"})(io||(io={}));(function(t){t[t.EdDSA=-8]="EdDSA",t[t.ES256=-7]="ES256",t[t.ES384=-35]="ES384",t[t.ES512=-36]="ES512",t[t.ES256K=-47]="ES256K"})(Zs||(Zs={}));(function(t){t[t.Kty=1]="Kty",t[t.Kid=2]="Kid",t[t.Alg=3]="Alg",t[t.KeyOps=4]="KeyOps",t[t.BaseIv=5]="BaseIv"})(bK||(bK={}));(function(t){t[t.Crv=-1]="Crv",t[t.X=-2]="X",t[t.Y=-3]="Y",t[t.D=-4]="D"})(xK||(xK={}));l4e={"P-256":io.P256,"P-384":io.P384,"P-521":io.P521,X25519:io.X25519,Ed25519:io.Ed25519,Ed448:io.Ed448,secp256k1:io.Secp256k1},f4e={[io.P256]:"P-256",[io.P384]:"P-384",[io.P521]:"P-521",[io.X25519]:"X25519",[io.Ed25519]:"Ed25519",[io.Ed448]:"Ed448",[io.Secp256k1]:"secp256k1"},p4e={EdDSA:Zs.EdDSA,ES256:Zs.ES256,ES384:Zs.ES384,ES512:Zs.ES512,ES256K:Zs.ES256K},h4e={[Zs.EdDSA]:"EdDSA",[Zs.ES256]:"ES256",[Zs.ES384]:"ES384",[Zs.ES512]:"ES512",[Zs.ES256K]:"ES256K"};(function(t){t[t.Alg=1]="Alg",t[t.Crit=2]="Crit",t[t.ContentType=3]="ContentType",t[t.Kid=4]="Kid"})(PK||(PK={}));(function(t){t[t.Iss=1]="Iss",t[t.Sub=2]="Sub",t[t.Aud=3]="Aud",t[t.Exp=4]="Exp",t[t.Nbf=5]="Nbf",t[t.Iat=6]="Iat",t[t.Cti=7]="Cti",t[t.Nonce=10]="Nonce",t[t.Ueid=256]="Ueid",t[t.Sueids=257]="Sueids",t[t.Oemid=258]="Oemid",t[t.Hwmodel=259]="Hwmodel",t[t.Hwversion=260]="Hwversion",t[t.Secboot=262]="Secboot",t[t.Dbgstat=263]="Dbgstat",t[t.Location=264]="Location",t[t.Profile=265]="Profile",t[t.Submods=266]="Submods",t[t.Measres=272]="Measres",t[t.Intuse=268]="Intuse"})(_K||(_K={}));(function(t){t[t.Enabled=0]="Enabled",t[t.Disabled=1]="Disabled",t[t.DisabledSinceBoot=2]="DisabledSinceBoot",t[t.DisabledPermanently=3]="DisabledPermanently",t[t.DisabledFullyAndPermanently=4]="DisabledFullyAndPermanently"})(EK||(EK={}));(function(t){t[t.Unrestricted=1]="Unrestricted",t[t.Restricted=2]="Restricted",t[t.SecureRestricted=3]="SecureRestricted",t[t.Hardware=4]="Hardware"})(SK||(SK={}));lI={};LD(lI,{extractDidFragment:()=>To,getServices:()=>Ude,getVerificationMethodByKey:()=>Kde,getVerificationMethodTypes:()=>vL,getVerificationMethods:()=>Cx,getVerificationRelationshipsById:()=>bL,isDidService:()=>xL,isDidVerificationMethod:()=>vx,isDwnDidService:()=>qde,isPortableDid:()=>$x,keyBytesToMultibaseId:()=>PL,multibaseIdToKeyBytes:()=>_L});ea=class EL{constructor({uri:e,document:r,metadata:n,keyManager:i}){this.uri=e,this.document=r,this.metadata=n,this.keyManager=i}async export(){if(!(Array.isArray(this.document.verificationMethod)&&this.document.verificationMethod.length>0))throw new Error(`DID document for '${this.uri}' is missing verification methods`);let e=JSON.parse(JSON.stringify({uri:this.uri,document:this.document,metadata:this.metadata}));if("exportKey"in this.keyManager&&typeof this.keyManager.exportKey=="function"){let r=[];for(let n of this.document.verificationMethod){if(!n.publicKeyJwk)throw new Error(`Verification method '${n.id}' does not contain a public key in JWK format`);let i=await this.keyManager.getKeyUri({key:n.publicKeyJwk}),a=await this.keyManager.exportKey({keyUri:i});r.push({...a})}e.privateKeys=r}return e}async getSigner(e){let r=this.document.verificationMethod?.find(s=>To(s.id)===(To(e?.methodId)??To(this.document.assertionMethod?.[0])));if(!(r&&r.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");let n=await this.keyManager.getKeyUri({key:r.publicKeyJwk}),i=await this.keyManager.getPublicKey({keyUri:n}),a=this.keyManager;return{algorithm:kce.getJoseSignatureAlgorithmFromPublicKey(i),keyId:r.id,async sign({data:s}){return await a.sign({data:s,keyUri:n})},async verify({data:s,signature:o}){return await a.verify({data:s,key:i,signature:o})}}}static async import({portableDid:e,keyManager:r=new Ka}){let n=Cx({didDocument:e.document});if(n.length===0)throw new Xe("invalidDidDocument","At least one verification method is required but 0 were given");for(let i of e.privateKeys??[]){let a=await r.getKeyUri({key:i});await r.getPublicKey({keyUri:a}).then(()=>!0).catch(()=>!1)||await r.importKey({key:i})}for(let i of n){if(!i.publicKeyJwk)throw new Error(`Verification method '${i.id}' does not contain a public key in JWK format`);let a=await r.getKeyUri({key:i.publicKeyJwk});await r.getPublicKey({keyUri:a})}return new EL({uri:e.uri,document:e.document,metadata:e.metadata,keyManager:r})}},n0=class{static async getSigningMethod(t){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")}static async resolve(t,e){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")}},SL=(t=>(t[t.Discoverable=0]="Discoverable",t[t.Organization=1]="Organization",t[t.Government=2]="Government",t[t.Corporation=3]="Corporation",t[t.LocalBusiness=4]="LocalBusiness",t[t.SoftwarePackage=5]="SoftwarePackage",t[t.WebApp=6]="WebApp",t[t.FinancialInstitution=7]="FinancialInstitution",t))(SL||{}),fI=(t=>(t[t.Ed25519=0]="Ed25519",t[t.secp256k1=1]="secp256k1",t[t.secp256r1=2]="secp256r1",t[t.X25519=3]="X25519",t))(fI||{}),TL=(t=>(t.authentication="auth",t.assertionMethod="asm",t.capabilityDelegation="del",t.capabilityInvocation="inv",t.keyAgreement="agm",t))(TL||{}),TK="0123456789abcdef",kL=[],kK=[];for(let t=0;t<256;t++)kL[t]=TK[t>>4&15]+TK[t&15],t<16&&(t<10?kK[48+t]=t:kK[87+t]=t);Lde=t=>{let e=t.length,r="",n=0;for(;n<e;)r+=kL[t[n++]];return r},zde=(t,e=0)=>{let r=t.length||0;if(!e){let s=r;for(;s--;)e+=t[s].length}let n=new Uint8Array(e),i=e,a=r;for(;a--;)i-=t[a].length,n.set(t[a],i);return n},AK="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Fde=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(_w=0;_w<AK.length;_w++)Fde[AK.charCodeAt(_w)]=_w;Gde=new TextDecoder,AL=(t,e)=>e?new TextDecoder(e).decode(t):Gde.decode(t),Wde=new TextEncoder,$d=t=>Wde.encode(t),DK=typeof window<"u"?window:self,IK=DK.crypto||DK.msCrypto||{},m4e=IK.subtle||IK.webkitSubtle;sr.bytes=-1;sr._floatConversionDetected=!1;sr._encode=function(t,e){if(e!=null)switch(DL(e)){case"object":sr.dict(t,e);break;case"map":sr.dictMap(t,e);break;case"array":sr.list(t,e);break;case"set":sr.listSet(t,e);break;case"string":sr.string(t,e);break;case"number":sr.number(t,e);break;case"boolean":sr.number(t,e);break;case"arraybufferview":sr.buffer(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":sr.buffer(t,new Uint8Array(e));break}};Ox=new Uint8Array([101]),IL=new Uint8Array([100]),RL=new Uint8Array([108]);sr.buffer=function(t,e){t.push($d(e.length+":"),e)};sr.string=function(t,e){t.push($d($d(e).byteLength+":"+e))};sr.number=function(t,e){if(Number.isInteger(e))return t.push($d("i"+BigInt(e)+"e"));let r=2147483648,n=e/r<<0,i=e%r<<0,a=n*r+i;t.push($d("i"+a+"e")),a!==e&&!sr._floatConversionDetected&&(sr._floatConversionDetected=!0,console.warn('WARNING: Possible data corruption detected with value "'+e+'":','Bencoding only defines support for integers, value was converted to "'+a+'"'),console.trace())};sr.dict=function(t,e){t.push(IL);let r=0,n,i=Object.keys(e).sort(),a=i.length;for(;r<a;r++)n=i[r],e[n]!=null&&(sr.string(t,n),sr._encode(t,e[n]));t.push(Ox)};sr.dictMap=function(t,e){t.push(IL);let r=Array.from(e.keys()).sort();for(let n of r)e.get(n)!=null&&(ArrayBuffer.isView(n)?sr._encode(t,n):sr.string(t,String(n)),sr._encode(t,e.get(n)));t.push(Ox)};sr.list=function(t,e){let r=0,n=e.length;for(t.push(RL);r<n;r++)e[r]!=null&&sr._encode(t,e[r]);t.push(Ox)};sr.listSet=function(t,e){t.push(RL);for(let r of e)r!=null&&sr._encode(t,r);t.push(Ox)};Hde=sr,Vde=105,Jde=58,Zde=100,Yde=108,pI=101;pt.bytes=0;pt.position=0;pt.data=null;pt.encoding=null;pt.next=function(){switch(pt.data[pt.position]){case Zde:return pt.dictionary();case Yde:return pt.list();case Vde:return pt.integer();default:return pt.buffer()}};pt.find=function(t){let e=pt.position,r=pt.data.length,n=pt.data;for(;e<r;){if(n[e]===t)return e;e++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(t)+'" [0x'+t.toString(16)+"]")};pt.dictionary=function(){pt.position++;let t={};for(;pt.data[pt.position]!==pI;){let e=pt.buffer(),r=AL(e);r.includes("\uFFFD")&&(r=Lde(e)),t[r]=pt.next()}return pt.position++,t};pt.list=function(){pt.position++;let t=[];for(;pt.data[pt.position]!==pI;)t.push(pt.next());return pt.position++,t};pt.integer=function(){let t=pt.find(pI),e=CL(pt.data,pt.position+1,t);return pt.position+=t+1-pt.position,e};pt.buffer=function(){let t=pt.find(Jde),e=CL(pt.data,pt.position,t),r=++t+e;return pt.position=r,pt.encoding?AL(pt.data.slice(t,r)):pt.data.slice(t,r)};Qde=pt;$L=Bx,iue=$L,OL={encode:Hde,decode:Qde,byteLength:$L,encodingLength:iue},oue=/^(\d{1,3}\.){3,3}\d{1,3}$/,sue=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,Ac={name:"v4",size:4,isFormat:t=>oue.test(t),encode(t,e,r){r=~~r,e=e||new Uint8Array(r+4);let n=t.length,i=0;for(let a=0;a<n;){let s=t.charCodeAt(a++);s===46?(e[r++]=i,i=0):i=i*10+(s-48)}return e[r]=i,e},decode(t,e){return e=~~e,`${t[e++]}.${t[e++]}.${t[e++]}.${t[e]}`}},Qu={name:"v6",size:16,isFormat:t=>t.length>0&&sue.test(t),encode(t,e,r){r=~~r;let n=r+16,i=-1,a=0,s=0,o=!0,d=!1;e=e||new Uint8Array(r+16);for(let u=0;u<t.length;u++){let c=t.charCodeAt(u);c===58?(o?i!==-1?(r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2):r<n&&(i=r):(d===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=a>>8),r<n-1&&(e[r+1]=a&255),r+=2),a=0,s=0),o=!0,d=!1):c===46?(r<n&&(e[r]=s),r++,s=0,a=0,o=!1,d=!0):(o=!1,c>=97?c-=87:c>=65?c-=55:(c-=48,s=s*10+c),a=(a<<4)+c)}if(o===!1)d===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=a>>8),r<n-1&&(e[r+1]=a&255),r+=2);else if(i===0)r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2;else if(i!==-1){r+=2;for(let u=Math.min(r-1,n-1);u>=i+2;u--)e[u]=e[u-2];e[i]=0,e[i+1]=0,i=r}if(i!==r&&i!==-1)for(r>n-2&&(r=n-2);n>i;)e[--n]=r<n&&r>i?e[--r]:0;else for(;r<n;)e[r++]=0;return e},decode(t,e){e=~~e;let r="";for(let n=0;n<16;n+=2)n!==0&&(r+=":"),r+=(t[e+n]<<8|t[e+n+1]).toString(16);return r.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};Jw.bytes=0;o0.bytes=0;qf=t=>t instanceof Uint8Array;Dw={},UL=new Array(255);for(let t=0;t<=15;t+=1){let e=t.toString(16),r=e.toUpperCase();for(let n=0;n<=15;n+=1){let i=n.toString(16),a=i.toUpperCase(),s=t<<4|n,o=`${e}${i}`;UL[s]=o,Dw[o]=s,Dw[`${r}${i}`]=s,Dw[`${e}${a}`]=s,Dw[`${r}${a}`]=s}}mue=Math.pow(2,24),yue=Math.pow(2,16),gue=Math.pow(2,8),Id=(t,e)=>t[e]*mue+t[e+1]*yue+t[e+2]*gue+t[e+3],It=(t,e)=>t[e]<<8|t[e+1],Rd=(t,e,r)=>(e=+e,t[r+3]=e,e=e>>>8,t[r+2]=e,e=e>>>8,t[r+1]=e,e=e>>>8,t[r]=e,r+4),rt=(t,e,r)=>(t[r]=e>>8,t[r+1]=e&255,r+2);vue=0,$K=32768,ID=32768,bue=~ID,KL=32768,xue=~KL;He=Cr({encode(t,e,r){e||(e=new Uint8Array(He.encodingLength(t))),r||(r=0);let n=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let a=i.split(".");for(let s=0;s<a.length;s++){let o=mI(e,a[s],r+1);e[r]=o,r+=o+1}}return e[r++]=0,He.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=[],n=e,i=0,a=0,s=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let o=t[e++];if(a+=s?0:1,o===0)break;if(o&192)if((o&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let d=It(t,e-1)-49152;if(d>=n)throw new Error("Cannot decode name (bad pointer)");e=d,n=d,a+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+o>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=o+1,i>254)throw new Error("Cannot decode name (name too long)");r.push(o0(t,e,e+o)),e+=o,a+=s?0:o}}return He.decode.bytes=a,r.length===0?".":r.join(".")},encodingLength(t){return t==="."||t===".."?1:el(t.replace(/^\.|\.$/gm,""))+2}}),Wn=Cr({encode(t,e,r){e||(e=new Uint8Array(Wn.encodingLength(t))),r||(r=0);let n=mI(e,t,r+1);return e[r]=n,Wn.encode.bytes=n+1,e},decode(t,e){e||(e=0);let r=t[e],n=o0(t,e+1,e+1+r);return Wn.decode.bytes=r+1,n},encodingLength(t){return el(t)+1}}),Jh=Cr({bytes:12,encode(t,e,r){e||(e=new Uint8Array(Jh.encodingLength(t))),r||(r=0);let n=(t.flags||0)&32767,i=t.type==="response"?$K:vue;return rt(e,t.id||0,r),rt(e,n|i,r+2),rt(e,t.questions.length,r+4),rt(e,t.answers.length,r+6),rt(e,t.authorities.length,r+8),rt(e,t.additionals.length,r+10),e},decode(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=It(t,e+2);return{id:It(t,e),type:r&$K?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:lue(r>>11&15),flag_aa:(r>>10&1)===1,flag_tc:(r>>9&1)===1,flag_rd:(r>>8&1)===1,flag_ra:(r>>7&1)===1,flag_z:(r>>6&1)===1,flag_ad:(r>>5&1)===1,flag_cd:(r>>4&1)===1,rcode:uue(r&15),questions:new Array(It(t,e+4)),answers:new Array(It(t,e+6)),authorities:new Array(It(t,e+8)),additionals:new Array(It(t,e+10))}},encodingLength(){return 12}}),Y1=Cr({encode(t,e,r){e||(e=new Uint8Array(Y1.encodingLength(t))),r||(r=0);let n=t.length;return rt(e,n,r),bs(t,e,r+2,0,n),Y1.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=It(t,e),n=t.slice(e+2,e+2+r);return Y1.decode.bytes=r+2,n},encodingLength(t){return t.length+2}}),Q1=Cr({encode(t,e,r){return e||(e=new Uint8Array(Q1.encodingLength(t))),r||(r=0),He.encode(t,e,r+2),rt(e,He.encode.bytes,r),Q1.encode.bytes=He.encode.bytes+2,e},decode(t,e){e||(e=0);let r=It(t,e),n=He.decode(t,e+2);return Q1.decode.bytes=r+2,n},encodingLength(t){return He.encodingLength(t)+2}}),X1=Cr({encode(t,e,r){e||(e=new Uint8Array(X1.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.mname,e,r),r+=He.encode.bytes,He.encode(t.rname,e,r),r+=He.encode.bytes,Rd(e,t.serial||0,r),r+=4,Rd(e,t.refresh||0,r),r+=4,Rd(e,t.retry||0,r),r+=4,Rd(e,t.expire||0,r),r+=4,Rd(e,t.minimum||0,r),r+=4,rt(e,r-n-2,n),X1.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=He.decode(t,e),e+=He.decode.bytes,n.rname=He.decode(t,e),e+=He.decode.bytes,n.serial=Id(t,e),e+=4,n.refresh=Id(t,e),e+=4,n.retry=Id(t,e),e+=4,n.expire=Id(t,e),e+=4,n.minimum=Id(t,e),e+=4,X1.decode.bytes=e-r,n},encodingLength(t){return 22+He.encodingLength(t.mname)+He.encodingLength(t.rname)}}),ex=Cr({encode(t,e,r){Array.isArray(t)||(t=[t]);for(let i=0;i<t.length;i++)if(typeof t[i]=="string"&&(t[i]=hI(t[i])),!qf(t[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(ex.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(i){e[r++]=i.length,bs(i,e,r,0,i.length),r+=i.length}),rt(e,r-n-2,n),ex.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=It(t,e);e+=2;let i=[];for(;n>0;){let a=t[e++];if(--n,n<a)throw new Error("Buffer overflow");i.push(t.slice(e,e+a)),e+=a,n-=a}return ex.decode.bytes=e-r,i},encodingLength(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=el(r)+1:e+=r.length+1}),e}}),tx=Cr({encode(t,e,r){e||(e=new Uint8Array(tx.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=hI(t)),t||(t=new Uint8Array(0));let n=r;r+=2;let i=t.length;return bs(t,e,r,0,i),r+=i,rt(e,r-n-2,n),tx.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=It(t,e);e+=2;let i=t.slice(e,e+n);return e+=n,tx.decode.bytes=e-r,i},encodingLength(t){return t?(qf(t)?t.length:el(t))+2:2}}),rx=Cr({encode(t,e,r){e||(e=new Uint8Array(rx.encodingLength(t))),r||(r=0);let n=r;return r+=2,Wn.encode(t.cpu,e,r),r+=Wn.encode.bytes,Wn.encode(t.os,e,r),r+=Wn.encode.bytes,rt(e,r-n-2,n),rx.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=Wn.decode(t,e),e+=Wn.decode.bytes,n.os=Wn.decode(t,e),e+=Wn.decode.bytes,rx.decode.bytes=e-r,n},encodingLength(t){return Wn.encodingLength(t.cpu)+Wn.encodingLength(t.os)+2}}),rm=Cr({encode(t,e,r){return e||(e=new Uint8Array(rm.encodingLength(t))),r||(r=0),He.encode(t,e,r+2),rt(e,He.encode.bytes,r),rm.encode.bytes=He.encode.bytes+2,e},decode(t,e){e||(e=0);let r=He.decode(t,e+2);return rm.decode.bytes=He.decode.bytes+2,r},encodingLength(t){return He.encodingLength(t)+2}}),nx=Cr({encode(t,e,r){e||(e=new Uint8Array(nx.encodingLength(t))),r||(r=0),rt(e,t.priority||0,r+2),rt(e,t.weight||0,r+4),rt(e,t.port||0,r+6),He.encode(t.target,e,r+8);let n=He.encode.bytes+6;return rt(e,n,r),nx.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=It(t,e),n={};return n.priority=It(t,e+2),n.weight=It(t,e+4),n.port=It(t,e+6),n.target=He.decode(t,e+8),nx.decode.bytes=r+2,n},encodingLength(t){return 8+He.encodingLength(t.target)}}),Ju=Cr({encode(t,e,r){let n=Ju.encodingLength(t);return e||(e=new Uint8Array(Ju.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=Ju.ISSUER_CRITICAL),rt(e,n-2,r),r+=2,e[r]=t.flags||0,r+=1,Wn.encode(t.tag,e,r),r+=Wn.encode.bytes,mI(e,t.value,r),r+=el(t.value),Ju.encode.bytes=n,e},decode(t,e){e||(e=0);let r=It(t,e);e+=2;let n=e,i={};return i.flags=t[e],e+=1,i.tag=Wn.decode(t,e),e+=Wn.decode.bytes,i.value=o0(t,e,n+r),i.issuerCritical=!!(i.flags&Ju.ISSUER_CRITICAL),Ju.decode.bytes=r+2,i},encodingLength(t){return Wn.encodingLength(t.tag)+Wn.encodingLength(t.value)+2}});Ju.ISSUER_CRITICAL=128;ix=Cr({encode(t,e,r){e||(e=new Uint8Array(ix.encodingLength(t))),r||(r=0);let n=r;return r+=2,rt(e,t.preference||0,r),r+=2,He.encode(t.exchange,e,r),r+=He.encode.bytes,rt(e,r-n-2,n),ix.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=It(t,e),e+=2,n.exchange=He.decode(t,e),e+=He.decode.bytes,ix.decode.bytes=e-r,n},encodingLength(t){return 4+He.encodingLength(t.exchange)}}),qL=Cr({encode(t,e,r){return e||(e=new Uint8Array(qL.encodingLength(t))),r||(r=0),rt(e,4,r),r+=2,Ac.encode(t,e,r),e},decode(t,e){return e||(e=0),e+=2,Ac.decode(t,e)},bytes:6}),ox=Cr({encode(t,e,r){return e||(e=new Uint8Array(ox.encodingLength(t))),r||(r=0),rt(e,16,r),r+=2,Qu.encode(t,e,r),ox.encode.bytes=18,e},decode(t,e){e||(e=0),e+=2;let r=Qu.decode(t,e);return ox.decode.bytes=18,r},bytes:18}),OK=t=>new Uint8Array(t),Ad=Cr({encode(t,e,r){e||(e=new Uint8Array(Ad.encodingLength(t))),r||(r=0);let n=r,i=RK(t.code);if(rt(e,i,r),r+=2,t.data)rt(e,t.data.length,r),r+=2,bs(t.data,e,r),r+=t.data.length;else switch(i){case 8:{let a=t.sourcePrefixLength||0,s=t.family||aue(t.ip,OK),o=cue(t.ip,OK),d=Math.ceil(a/8);rt(e,d+4,r),r+=2,rt(e,s,r),r+=2,e[r++]=a,e[r++]=t.scopePrefixLength||0,bs(o,e,r,0,d),r+=d}break;case 11:t.timeout?(rt(e,2,r),r+=2,rt(e,t.timeout,r),r+=2):(rt(e,0,r),r+=2);break;case 12:{let a=t.length||0;rt(e,a,r),r+=2,e.fill(0,r,r+a),r+=a}break;case 14:{let a=t.tags.length*2;rt(e,a,r),r+=2;for(let s of t.tags)rt(e,s,r),r+=2}break;default:throw new Error(`Unknown roption code: ${t.code}`)}return Ad.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={};r.code=It(t,e),r.type=fue(r.code),e+=2;let n=It(t,e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=It(t,e),e+=2,r.sourcePrefixLength=t[e++],r.scopePrefixLength=t[e++];{let i=new Uint8Array(r.family===1?4:16);bs(t,i,0,e,e+n-4),r.ip=due(i)}break;case 11:n>0&&(r.timeout=It(t,e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(It(t,e)),e+=2}return Ad.decode.bytes=n+4,r},encodingLength(t){if(t.data)return t.data.length+4;switch(RK(t.code)){case 8:{let e=t.sourcePrefixLength||0;return Math.ceil(e/8)+8}case 11:return typeof t.timeout=="number"?6:4;case 12:return t.length+4;case 14:return 4+t.tags.length*2}throw new Error(`Unknown roption code: ${t.code}`)}}),Zu=Cr({encode(t,e,r){e||(e=new Uint8Array(Zu.encodingLength(t))),r||(r=0);let n=r,i=em(t,Ad);return rt(e,i,r),r=Bw(t,Ad,e,r+2),Zu.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=[],i=It(t,e);e+=2;let a=0;for(;i>0;)n[a++]=Ad.decode(t,e),e+=Ad.decode.bytes,i-=Ad.decode.bytes;return Zu.decode.bytes=e-r,n},encodingLength(t){return 2+em(t||[],Ad)}}),kc=Cr({encode(t,e,r){e||(e=new Uint8Array(kc.encodingLength(t))),r||(r=0);let n=r,i=t.key;if(!qf(i))throw new Error("Key must be a Buffer");return r+=2,rt(e,t.flags,r),r+=2,e[r]=kc.PROTOCOL_DNSSEC,r+=1,e[r]=t.algorithm,r+=1,bs(i,e,r,0,i.length),r+=i.length,kc.encode.bytes=r-n,rt(e,kc.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=It(t,e);if(e+=2,n.flags=It(t,e),e+=2,t[e]!==kc.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t[e],e+=1,n.key=t.slice(e,r+i+2),e+=n.key.length,kc.decode.bytes=e-r,n},encodingLength(t){return 6+el(t.key)}});kc.PROTOCOL_DNSSEC=3;kc.ZONE_KEY=128;kc.SECURE_ENTRYPOINT=32768;Iw=Cr({encode(t,e,r){e||(e=new Uint8Array(Iw.encodingLength(t))),r||(r=0);let n=r,i=t.signature;if(!qf(i))throw new Error("Signature must be a Buffer");return r+=2,rt(e,Vw(t.typeCovered),r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.labels,r+=1,Rd(e,t.originalTTL,r),r+=4,Rd(e,t.expiration,r),r+=4,Rd(e,t.inception,r),r+=4,rt(e,t.keyTag,r),r+=2,He.encode(t.signersName,e,r),r+=He.encode.bytes,bs(i,e,r,0,i.length),r+=i.length,Iw.encode.bytes=r-n,rt(e,Iw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=It(t,e);return e+=2,n.typeCovered=jx(It(t,e)),e+=2,n.algorithm=t[e],e+=1,n.labels=t[e],e+=1,n.originalTTL=Id(t,e),e+=4,n.expiration=Id(t,e),e+=4,n.inception=Id(t,e),e+=4,n.keyTag=It(t,e),e+=2,n.signersName=He.decode(t,e),e+=He.decode.bytes,n.signature=t.slice(e,r+i+2),e+=n.signature.length,Iw.decode.bytes=e-r,n},encodingLength(t){return 20+He.encodingLength(t.signersName)+el(t.signature)}}),Rw=Cr({encode(t,e,r){e||(e=new Uint8Array(Rw.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.mbox||".",e,r),r+=He.encode.bytes,He.encode(t.txt||".",e,r),r+=He.encode.bytes,Rw.encode.bytes=r-n,rt(e,Rw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=He.decode(t,e)||".",e+=He.decode.bytes,n.txt=He.decode(t,e)||".",e+=He.decode.bytes,Rw.decode.bytes=e-r,n},encodingLength(t){return 2+He.encodingLength(t.mbox||".")+He.encodingLength(t.txt||".")}}),vs=Cr({encode(t,e,r){e||(e=new Uint8Array(vs.encodingLength(t))),r||(r=0);let n=r,i=[];for(let a=0;a<t.length;a++){let s=Vw(t[a]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(let a=0;a<i.length;a++)if(i[a]!==void 0){let s=hI(i[a]);e[r]=a,r+=1,e[r]=s.length,r+=1,bs(s,e,r,0,s.length),r+=s.length}return vs.encode.bytes=r-n,e},decode(t,e,r){e||(e=0);let n=e,i=[];for(;e-n<r;){let a=t[e];e+=1;let s=t[e];e+=1;for(let o=0;o<s;o++){let d=t[e+o];for(let u=0;u<8;u++)if(d&1<<7-u){let c=jx(a<<8|o<<3|u);i.push(c)}}e+=s}return vs.decode.bytes=e-n,i},encodingLength(t){let e=[];for(let n=0;n<t.length;n++){let i=Vw(t[n]);e[i>>8]=Math.max(e[i>>8]||0,i&255)}let r=0;for(let n=0;n<e.length;n++)e[n]!==void 0&&(r+=2+Math.ceil((e[n]+1)/8));return r}}),Cw=Cr({encode(t,e,r){e||(e=new Uint8Array(Cw.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.nextDomain,e,r),r+=He.encode.bytes,vs.encode(t.rrtypes,e,r),r+=vs.encode.bytes,Cw.encode.bytes=r-n,rt(e,Cw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=It(t,e);return e+=2,n.nextDomain=He.decode(t,e),e+=He.decode.bytes,n.rrtypes=vs.decode(t,e,i-(e-r)),e+=vs.decode.bytes,Cw.decode.bytes=e-r,n},encodingLength(t){return 2+He.encodingLength(t.nextDomain)+vs.encodingLength(t.rrtypes)}}),$w=Cr({encode(t,e,r){e||(e=new Uint8Array($w.encodingLength(t))),r||(r=0);let n=r,i=t.salt;if(!qf(i))throw new Error("salt must be a Buffer");let a=t.nextDomain;if(!qf(a))throw new Error("nextDomain must be a Buffer");return r+=2,e[r]=t.algorithm,r+=1,e[r]=t.flags,r+=1,rt(e,t.iterations,r),r+=2,e[r]=i.length,r+=1,bs(i,e,r,0,i.length),r+=i.length,e[r]=a.length,r+=1,bs(a,e,r,0,a.length),r+=a.length,vs.encode(t.rrtypes,e,r),r+=vs.encode.bytes,$w.encode.bytes=r-n,rt(e,$w.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=It(t,e);e+=2,n.algorithm=t[e],e+=1,n.flags=t[e],e+=1,n.iterations=It(t,e),e+=2;let a=t[e];e+=1,n.salt=t.slice(e,e+a),e+=a;let s=t[e];return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=vs.decode(t,e,i-(e-r)),e+=vs.decode.bytes,$w.decode.bytes=e-r,n},encodingLength(t){return 8+t.salt.length+t.nextDomain.length+vs.encodingLength(t.rrtypes)}}),Ow=Cr({encode(t,e,r){e||(e=new Uint8Array(Ow.encodingLength(t))),r||(r=0);let n=r,i=t.digest;if(!qf(i))throw new Error("Digest must be a Buffer");return r+=2,rt(e,t.keyTag,r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.digestType,r+=1,bs(i,e,r,0,i.length),r+=i.length,Ow.encode.bytes=r-n,rt(e,Ow.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=It(t,e);return e+=2,n.keyTag=It(t,e),e+=2,n.algorithm=t[e],e+=1,n.digestType=t[e],e+=1,n.digest=t.slice(e,r+i+2),e+=n.digest.length,Ow.decode.bytes=e-r,n},encodingLength(t){return 6+el(t.digest)}}),Xh=Cr({encode(t,e,r){e||(e=new Uint8Array(Xh.encodingLength(t))),r||(r=0);let n=r;r+=2,e[r]=t.algorithm,r+=1,e[r]=t.hash,r+=1;let i=CK(t.fingerprint),a=RD(t.hash);if(i!==a)throw new Error(`Invalid length of fingerprint "${t.fingerprint}" for hashType=${t.hash}: ${i} != ${a}`);return hue(e,t.fingerprint,r,r+=i),Xh.encode.bytes=r-n,rt(e,Xh.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};e+=2,n.algorithm=t[e],e+=1,n.hash=t[e],e+=1;let i=RD(n.hash);return n.fingerprint=pue(t,e,e+i),e+=i,Xh.decode.bytes=e-r,n},encodingLength(t){return 4+CK(t.fingerprint)}});Xh.getFingerprintLengthForHashType=RD;Hs=Cr({encode(t,e,r){e||(e=new Uint8Array(Hs.encodingLength(t))),r||(r=0);let n=r;if(He.encode(t.name,e,r),r+=He.encode.bytes,rt(e,Vw(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");rt(e,t.udpPayloadSize||4096,r+2),e[r+4]=t.extendedRcode||0,e[r+5]=t.ednsVersion||0,rt(e,t.flags||0,r+6),r+=8,Zu.encode(t.options||[],e,r),r+=Zu.encode.bytes}else{let i=ML(t.class===void 0?"IN":t.class);t.flush&&(i|=ID),rt(e,i,r+2),Rd(e,t.ttl||0,r+4),r+=8;let a=gD(t.type);a.encode(t.data,e,r),r+=a.encode.bytes}return Hs.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={},n=e;if(r.name=He.decode(t,e),e+=He.decode.bytes,r.type=jx(It(t,e)),r.type==="OPT")r.udpPayloadSize=It(t,e+2),r.extendedRcode=t[e+4],r.ednsVersion=t[e+5],r.flags=It(t,e+6),r.flag_do=(r.flags>>15&1)===1,r.options=Zu.decode(t,e+8),e+=8+Zu.decode.bytes;else{let i=It(t,e+2);r.ttl=Id(t,e+4),r.class=jL(i&bue),r.flush=!!(i&ID);let a=gD(r.type);r.data=a.decode(t,e+8),e+=8+a.decode.bytes}return Hs.decode.bytes=e-n,r},encodingLength(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return He.encodingLength(t.name)+8+gD(t.type).encodingLength(e)}}),nm=Cr({encode(t,e,r){e||(e=new Uint8Array(nm.encodingLength(t))),r||(r=0);let n=r;return He.encode(t.name,e,r),r+=He.encode.bytes,rt(e,Vw(t.type),r),r+=2,rt(e,ML(t.class===void 0?"IN":t.class),r),r+=2,nm.encode.bytes=r-n,t},decode(t,e){e||(e=0);let r=e,n={};return n.name=He.decode(t,e),e+=He.decode.bytes,n.type=jx(It(t,e)),e+=2,n.class=jL(It(t,e)),e+=2,n.class&KL&&(n.class&=xue),nm.decode.bytes=e-r,n},encodingLength(t){return He.encodingLength(t.name)+4}}),Pue=1024,Ui={encode:function(t,e,r){let n=!e;n&&(e=new Uint8Array(_ue(t))),r||(r=0);let i=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Jh.encode(t,e,r),r+=Jh.encode.bytes,r=Bw(t.questions,nm,e,r),r=Bw(t.answers,Hs,e,r),r=Bw(t.authorities,Hs,e,r),r=Bw(t.additionals,Hs,e,r),Ui.encode.bytes=r-i,n&&_x.bytes!==e.length?e.slice(0,_x.bytes):e},decode:function(t,e){e||(e=0);let r=e,n=Jh.decode(t,e);return e+=Jh.decode.bytes,e=z1(n.questions,nm,t,e),e=z1(n.answers,Hs,t,e),e=z1(n.authorities,Hs,t,e),e=z1(n.additionals,Hs,t,e),Ui.decode.bytes=e-r,n},encodingLength:function(t){return Jh.encodingLength(t)+em(t.questions||[],nm)+em(t.answers||[],Hs)+em(t.authorities||[],Hs)+em(t.additionals||[],Hs)}};Ui.encode.bytes=0;Ui.decode.bytes=0;xx={encode:function(t,e,r){return e=Ui.encode(bx(t,"query"),e,r),xx.encode.bytes=Ui.encode.bytes,e},decode:function(t,e){let r=Ui.decode(t,e);return xx.decode.bytes=Ui.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return Ui.encodingLength(bx(t,"query"))}};xx.encode.bytes=0;xx.decode.bytes=0;Px={encode:function(t,e,r){return e=Ui.encode(bx(t,"response"),e,r),Px.encode.bytes=Ui.encode.bytes,e},decode:function(t,e){let r=Ui.decode(t,e);return Px.decode.bytes=Ui.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return Ui.encodingLength(bx(t,"response"))}};Px.encode.bytes=0;Px.decode.bytes=0;_x=Ui.encode,CD=Ui.decode,_ue=Ui.encodingLength;LL.bytes=0;zL.bytes=0;GL="dht";Due=0,Gu=7200,sx=";",So=",",VL={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},JL={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"};jK=$.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",YL=class $D extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.verificationMethods?.some(c=>!(c.algorithm in VL)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(c=>"id"in c).map(c=>c.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(c=>!c.id||!c.type||!c.serviceEndpoint))throw new Error("One or more services are missing required properties");let i=await e.generateKey({algorithm:"Ed25519"}),a=await e.getPublicKey({keyUri:i}),s=await tm.identityKeyToIdentifier({identityKey:a}),o={id:s,...r.alsoKnownAs&&{alsoKnownAs:r.alsoKnownAs},...r.controllers&&{controller:r.controllers}},d=[...r.verificationMethods??[]];d?.some(c=>c.id?.split("#").pop()==="0")||d.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let c of d){let l=c.id&&c.id.split("#").pop()==="0"?i:await e.generateKey({algorithm:c.algorithm}),f=await e.getPublicKey({keyUri:l}),h=c.id??f.kid??await lr({jwk:f});h=`${s}#${To(h)}`,o.verificationMethod??=[],o.verificationMethod.push({id:h,type:"JsonWebKey",controller:c.controller??s,publicKeyJwk:f});for(let p of c.purposes??[])o[p]??=[],o[p].push(h)}r.services?.forEach(c=>{o.service??=[],c.id=`${s}#${c.id.split("#").pop()}`,o.service.push(c)});let u=new ea({uri:s,document:o,metadata:{published:!1,...r.types&&{types:r.types}},keyManager:e});if(r.publish??!0){let c=await $D.publish({did:u,gatewayUri:r.gatewayUri});u.metadata=c.didDocumentMetadata}return u}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==$D.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(!n.document.verificationMethod?.some(i=>i.id?.split("#").pop()==="0"))throw new Xe("invalidDidDocument","DID document must contain an Identity Key");return n}static async getSigningMethod({didDocument:e,methodId:r="#0"}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(a=>To(a.id)===(To(r)??To(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:r=jK}){return await MK.put({did:e,gatewayUri:r})}static async resolve(e,r={}){let n=r?.gatewayUri??jK;try{await tm.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:a}=await MK.get({didUri:e,gatewayUri:n});return{...li,didDocument:i,didDocumentMetadata:a}}catch(i){if(!(i instanceof Xe))throw new Error(i);return{...li,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};YL.methodName="dht";tl=YL,MK=class Mw{static async get({didUri:e,gatewayUri:r}){let n=tm.identifierToIdentityKeyBytes({didUri:e}),i=await Mw.pkarrGet({gatewayUri:r,publicKeyBytes:n}),a=await tm.parseBep44GetMessage({bep44Message:i}),s=await Mw.fromDnsPacket({didUri:e,dnsPacket:a});return s.didDocumentMetadata.versionId=i.seq.toString(),s}static async put({did:e,gatewayUri:r}){let n=await Mw.toDnsPacket({didDocument:e.document,didMetadata:e.metadata,authoritativeGatewayUris:[r]}),i=await tm.createBep44PutMessage({dnsPacket:n,publicKeyBytes:tm.identifierToIdentityKeyBytes({didUri:e.uri}),signer:await e.getSigner({methodId:"0"})}),a=await Mw.pkarrPut({gatewayUri:r,bep44Message:i});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:a,versionId:i.seq.toString()},didRegistrationMetadata:{}}}static async pkarrGet(e){return Eue(e)}static async pkarrPut(e){return Sue(e)}static async fromDnsPacket(e){return Iue(e)}static async toDnsPacket(e){return Rue(e)}static getUniqueDidSuffix(e){return e.split(":")[2]}},tm=class{static async createBep44PutMessage(t){return Tue(t)}static async identifierToIdentityKey(t){return WL(t)}static identifierToIdentityKeyBytes(t){return yI(t)}static async identityKeyToIdentifier(t){return Aue(t)}static keyConverter(t){return gI(t)}static async parseBep44GetMessage(t){return kue(t)}static parseTxtDataToObject(t){return jw(t)}static parseTxtDataToString(t){return Zw(t)}static async validatePreviousDidProof(t){return HL(t)}static chunkDataIfNeeded(t){return ZL(t)}},An={DeltaExceedsMaximumSize:"DeltaExceedsMaximumSize",DidDocumentPublicKeyIdDuplicated:"DidDocumentPublicKeyIdDuplicated",DidDocumentPublicKeyMissingOrIncorrectType:"DidDocumentPublicKeyMissingOrIncorrectType",DidDocumentServiceIdDuplicated:"DidDocumentServiceIdDuplicated",DidSuffixIncorrectLength:"DidSuffixIncorrectLength",EncodedStringIncorrectEncoding:"EncodedStringIncorrectEncoding",IdNotUsingBase64UrlCharacterSet:"IdNotUsingBase64UrlCharacterSet",IdTooLong:"IdTooLong",JwkEs256kMissingOrInvalidCrv:"JwkEs256kMissingOrInvalidCrv",JwkEs256kMissingOrInvalidKty:"JwkEs256kMissingOrInvalidKty",JwkEs256kHasIncorrectLengthOfX:"JwkEs256kHasIncorrectLengthOfX",JwkEs256kHasIncorrectLengthOfY:"JwkEs256kHasIncorrectLengthOfY",JwkEs256kHasIncorrectLengthOfD:"JwkEs256kHasIncorrectLengthOfD",MultihashStringNotAMultihash:"MultihashStringNotAMultihash",MultihashUnsupportedHashAlgorithm:"MultihashUnsupportedHashAlgorithm",PublicKeyJwkEs256kHasUnexpectedProperty:"PublicKeyJwkEs256kHasUnexpectedProperty",PublicKeyPurposeDuplicated:"PublicKeyPurposeDuplicated",ServiceEndpointCannotBeAnArray:"ServiceEndpointCannotBeAnArray",ServiceEndpointStringNotValidUri:"ServiceEndpointStringNotValidUri",ServiceTypeTooLong:"ServiceTypeTooLong"},Dn=class extends Error{constructor(t,e){super(`${t}: ${e}`),this.code=t,Object.setPrototypeOf(this,new.target.prototype)}},y4e=new Uint8Array(0),Cue=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},$ue=class{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Oue=class{constructor(t,e,r){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return QL(this,t)}},Bue=class{constructor(t){this.decoders=t}or(t){return QL(this,t)}decode(t){let e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},QL=(t,e)=>new Bue({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),jue=class{constructor(t,e,r,n){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=n,this.encoder=new $ue(t,e,r),this.decoder=new Oue(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Mue=({name:t,prefix:e,encode:r,decode:n})=>new jue(t,e,r,n),Nue=(t,e,r,n)=>{let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let a=t.length;for(;t[a-1]==="=";)--a;let s=new Uint8Array(a*r/8|0),o=0,d=0,u=0;for(let c=0;c<a;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|l,o+=r,o>=8&&(o-=8,s[u++]=255&d>>o)}if(o>=r||255&d<<8-o)throw new SyntaxError("Unexpected end of data");return s},Uue=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,a="",s=0,o=0;for(let d=0;d<t.length;++d)for(o=o<<8|t[d],s+=8;s>r;)s-=r,a+=e[i&o>>s];if(s&&(a+=e[i&o<<r-s]),n)for(;a.length*r&7;)a+="=";return a},Mx=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Mue({prefix:e,name:t,encode(i){return Uue(i,n,r)},decode(i){return Nue(i,n,r,t)}}),g4e=Mx({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),w4e=Mx({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),NK=Mx({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),v4e=Mx({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),am=class ax{static encode(e){return NK.baseEncode(e)}static decodeAsBytes(e,r){if(!ax.isBase64UrlString(e))throw new Dn(An.EncodedStringIncorrectEncoding,`Given ${r} must be base64url string.`);return NK.baseDecode(e)}static decodeAsString(e,r){let n=ax.decodeAsBytes(e,r);return ax.bytesToString(n)}static isBase64UrlString(e){return/^[A-Za-z0-9_-]+$/.test(e)}static stringToBytes(e){return new TextEncoder().encode(e)}static bytesToString(e){return new TextDecoder().decode(e)}},Kue=Lf(Uoe(),1);(function(t){t.Public="public",t.Private="private"})(OD||(OD={}));Tc=OD,ys=class{static validateEs256kOperationKey(t,e){let r=new Set(["kty","crv","x","y"]);e===Tc.Private&&r.add("d");for(let n in t)if(!r.has(n))throw new Dn(An.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${n}'.`);if(t.crv!=="secp256k1")throw new Dn(An.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${t.crv}.'`);if(t.kty!=="EC")throw new Dn(An.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${t.kty}.'`);if(t.x.length!==43)throw new Dn(An.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(t.y.length!==43)throw new Dn(An.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(e===Tc.Private&&(t.d===void 0||t.d.length!==43))throw new Dn(An.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(t){if(t.length>50)throw new Dn(An.IdTooLong,`Key ID length ${t.length} exceed max allowed length of 50.`);if(!am.isBase64UrlString(t))throw new Dn(An.IdNotUsingBase64UrlCharacterSet,`Key ID '${t}' is not a Base64URL string.`)}static validatePublicKeyPurposes(t){if(t===void 0)return;let e=new Set;for(let r of t){if(e.has(r))throw new Dn(An.PublicKeyPurposeDuplicated,`Public key purpose '${r}' already specified.`);e.add(r)}}},wI=class{};wI.hashAlgorithmInMultihashCode=18;wI.maxCanonicalizedDeltaSizeInBytes=1e3;Ua=wI,que=Lf(Koe(),1),Yw=class BD{static canonicalizeAsBytes(e){let r=BD.removeAllUndefinedProperties(e),n=que.default(r);return am.stringToBytes(n)}static removeAllUndefinedProperties(e){for(let r in e)typeof e[r]=="object"?BD.removeAllUndefinedProperties(e[r]):e[r]===void 0&&delete e[r];return e}},Lue=XL,UK=128,zue=127,Fue=~zue,Gue=Math.pow(2,31);Wue=jD,Hue=128,KK=127;Vue=Math.pow(2,7),Jue=Math.pow(2,14),Zue=Math.pow(2,21),Yue=Math.pow(2,28),Que=Math.pow(2,35),Xue=Math.pow(2,42),ele=Math.pow(2,49),tle=Math.pow(2,56),rle=Math.pow(2,63),nle=function(t){return t<Vue?1:t<Jue?2:t<Zue?3:t<Yue?4:t<Que?5:t<Xue?6:t<ele?7:t<tle?8:t<rle?9:10},ile={encode:Lue,decode:Wue,encodingLength:nle},ole=ile,Ex=ole,qK=(t,e=0)=>[Ex.decode(t,e),Ex.decode.bytes],LK=(t,e,r=0)=>(Ex.encode(t,e,r),e),zK=t=>Ex.encodingLength(t),FK=(t,e)=>{let r=e.byteLength,n=zK(t),i=n+zK(r),a=new Uint8Array(i+r);return LK(t,a,0),LK(r,a,n),a.set(e,i),new e9(t,r,e,a)},sle=t=>{let e=Cue(t),[r,n]=qK(e),[i,a]=qK(e.subarray(n)),s=e.subarray(n+a);if(s.byteLength!==i)throw new Error("Incorrect length");return new e9(r,i,s,e)},e9=class{constructor(t,e,r,n){this.code=t,this.size=e,this.digest=r,this.bytes=n}},t9=({name:t,code:e,encode:r})=>new ale(t,e,r),ale=class{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?FK(this.code,e):e.then(r=>FK(this.code,r))}else throw Error("Unknown type, must be binary type")}},r9=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),GK=t9({name:"sha2-256",code:18,encode:r9("SHA-256")}),b4e=t9({name:"sha2-512",code:19,encode:r9("SHA-512")}),Ew=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},ws=class Nw{static hash(e,r){return Ew(this,void 0,void 0,function*(){let n;switch(r){case 18:n=(yield GK.digest(e)).bytes;break;default:throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,r){return Ew(this,void 0,void 0,function*(){let n;switch(r){case 18:n=yield GK.encode(e);break;default:throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=Yw.canonicalizeAsBytes(e);return yield Nw.hashThenEncode(n,r)})}static canonicalizeThenDoubleHashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=Yw.canonicalizeAsBytes(e),i=yield Nw.hashAsNonMultihashBytes(n,r);return yield Nw.hashThenEncode(i,r)})}static hashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=yield Nw.hash(e,r);return am.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,r){let n,i=am.decodeAsBytes(e,r);try{n=sle(i)}catch{throw new Dn(An.MultihashStringNotAMultihash,`Given ${r} string '${e}' is not a multihash after decoding.`)}let a=Ua.hashAlgorithmInMultihashCode;if(a!==n.code)throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Given ${r} uses unsupported multihash algorithm with code ${n.code}, should use ${a} or change IonSdkConfig to desired hashing algorithm.`)}};(function(t){t.Create="create",t.Update="update",t.Deactivate="deactivate",t.Recover="recover"})(MD||(MD={}));F1=MD;(function(t){t.Replace="replace",t.AddPublicKeys="add-public-keys",t.RemovePublicKeys="remove-public-keys",t.AddServices="add-services",t.RemoveServices="remove-services"})(ND||(ND={}));Hh=ND,G1=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},n9=class Gs{static createCreateRequest(e){return G1(this,void 0,void 0,function*(){let r=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,a=e.document.services;ys.validateEs256kOperationKey(r,Tc.Public),ys.validateEs256kOperationKey(n,Tc.Public),Gs.validateDidDocumentKeys(i),Gs.validateServices(a);let s=Ua.hashAlgorithmInMultihashCode,o=[{action:Hh.Replace,document:e.document}],d={updateCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(n,s),patches:o};Gs.validateDeltaSize(d);let u={deltaHash:yield ws.canonicalizeThenHashThenEncode(d,s),recoveryCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(r,s)};return{type:F1.Create,suffixData:u,delta:d}})}static createDeactivateRequest(e){return G1(this,void 0,void 0,function*(){Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.recoveryPublicKey,Tc.Public);let r=Ua.hashAlgorithmInMultihashCode,n=yield ws.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},a=yield e.signer.sign({alg:"ES256K"},i);return{type:F1.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:a}})}static createRecoverRequest(e){return G1(this,void 0,void 0,function*(){Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.recoveryPublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextRecoveryPublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextUpdatePublicKey,Tc.Public),Gs.validateDidDocumentKeys(e.document.publicKeys),Gs.validateServices(e.document.services);let r=Ua.hashAlgorithmInMultihashCode,n=yield ws.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i=[{action:Hh.Replace,document:e.document}],a=yield ws.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,r),s={patches:i,updateCommitment:a},o=yield ws.canonicalizeThenHashThenEncode(s,r),d={recoveryCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,r),recoveryKey:e.recoveryPublicKey,deltaHash:o},u=yield e.signer.sign({alg:"ES256K"},d);return{type:F1.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:u}})}static createUpdateRequest(e){return G1(this,void 0,void 0,function*(){if(Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.updatePublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextUpdatePublicKey,Tc.Public),Gs.validateServices(e.servicesToAdd),Gs.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let p of e.idsOfServicesToRemove)ys.validateId(p);if(e.idsOfPublicKeysToRemove!==void 0)for(let p of e.idsOfPublicKeysToRemove)ys.validateId(p);let r=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let p={action:Hh.AddServices,services:n};r.push(p)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let p={action:Hh.RemoveServices,ids:i};r.push(p)}let a=e.publicKeysToAdd;if(a!==void 0&&a.length>0){let p={action:Hh.AddPublicKeys,publicKeys:a};r.push(p)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let p={action:Hh.RemovePublicKeys,ids:s};r.push(p)}let o=Ua.hashAlgorithmInMultihashCode,d=yield ws.canonicalizeThenHashThenEncode(e.updatePublicKey,o),u=yield ws.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,o),c={patches:r,updateCommitment:u},l=yield ws.canonicalizeThenHashThenEncode(c,o),f={updateKey:e.updatePublicKey,deltaHash:l},h=yield e.signer.sign({alg:"ES256K"},f);return{type:F1.Update,didSuffix:e.didSuffix,revealValue:d,delta:c,signedData:h}})}static validateDidSuffix(e){ws.validateEncodedHashComputedUsingSupportedHashAlgorithm(e,"didSuffix")}static validateDidDocumentKeys(e){if(e===void 0)return;let r=new Set;for(let n of e){if(Array.isArray(n.publicKeyJwk))throw new Dn(An.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(ys.validateId(n.id),r.has(n.id))throw new Dn(An.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);r.add(n.id),ys.validatePublicKeyPurposes(n.purposes)}}static validateServices(e){if(e!==void 0&&e.length!==0){let r=new Set;for(let n of e){if(Gs.validateService(n),r.has(n.id))throw new Dn(An.DidDocumentServiceIdDuplicated,"Service id has to be unique");r.add(n.id)}}}static validateService(e){ys.validateId(e.id);let r=30;if(e.type.length>r){let n=`Service endpoint type length ${e.type.length} exceeds max allowed length of ${r}.`;throw new Dn(An.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new Dn(An.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&Kue.parse(e.serviceEndpoint).error!==void 0)throw new Dn(An.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let r=Yw.canonicalizeAsBytes(e);if(r.length>Ua.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${r.length} bytes exceeded limit of ${Ua.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new Dn(An.DeltaExceedsMaximumSize,n)}}},WK=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},cle=class i9{static createLongFormDid(e){return WK(this,void 0,void 0,function*(){let r=yield n9.createCreateRequest(e),n=yield i9.computeDidUniqueSuffix(r.suffixData),i;Ua.network===void 0||Ua.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${Ua.network}:${n}`;let a={suffixData:r.suffixData,delta:r.delta},s=Yw.canonicalizeAsBytes(a),o=am.encode(s);return`${i}:${o}`})}static computeDidUniqueSuffix(e){return WK(this,void 0,void 0,function*(){let r=Yw.canonicalizeAsBytes(e),n=yield ws.hash(r,Ua.hashAlgorithmInMultihashCode);return am.encode(n)})}},Bi=2n**255n-19n,cx=2n**252n+27742317777372353535851937790883648493n,UD=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,KD=0x6666666666666666666666666666666666666666666666666666666666666658n,W1={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:Bi,n:cx,h:8,Gx:UD,Gy:KD},Lo=(t="")=>{throw new Error(t)},o9=t=>typeof t=="string",vI=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?Lo("Uint8Array expected"):t,cm=t=>new Uint8Array(t),dle=(t,e)=>vI(o9(t)?xI(t):cm(t),e),st=(t,e=Bi)=>{let r=t%e;return r>=0n?r:e+r},HK=t=>t instanceof dm?t:Lo("Point expected"),dm=class Zh{constructor(e,r,n,i){this.ex=e,this.ey=r,this.ez=n,this.et=i}static fromAffine(e){return new Zh(e.x,e.y,1n,st(e.x*e.y))}static fromHex(e,r=!0){let{d:n}=W1;e=dle(e,32);let i=e.slice();i[31]=e[31]&-129;let a=lle(i);a===0n||(r&&!(0n<a&&a<Bi)&&Lo("bad y coord 1"),!r&&!(0n<a&&a<2n**256n)&&Lo("bad y coord 2"));let s=st(a*a),o=st(s-1n),d=st(n*s+1n),{isValid:u,value:c}=ple(o,d);u||Lo("bad y coordinate 3");let l=(c&1n)===1n;return(e[31]&128)!==0!==l&&(c=st(-c)),new Zh(c,a,1n,st(c*a))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:r,ey:n,ez:i}=this,{ex:a,ey:s,ez:o}=HK(e),d=st(r*o),u=st(a*i),c=st(n*o),l=st(s*i);return d===u&&c===l}is0(){return this.equals(dx)}negate(){return new Zh(st(-this.ex),this.ey,this.ez,st(-this.et))}double(){let{ex:e,ey:r,ez:n}=this,{a:i}=W1,a=st(e*e),s=st(r*r),o=st(2n*st(n*n)),d=st(i*a),u=e+r,c=st(st(u*u)-a-s),l=d+s,f=l-o,h=d-s,p=st(c*f),m=st(l*h),g=st(c*h),_=st(f*l);return new Zh(p,m,_,g)}add(e){let{ex:r,ey:n,ez:i,et:a}=this,{ex:s,ey:o,ez:d,et:u}=HK(e),{a:c,d:l}=W1,f=st(r*s),h=st(n*o),p=st(a*l*u),m=st(i*d),g=st((r+n)*(s+o)-f-h),_=st(m-p),v=st(m+p),E=st(h-c*f),T=st(g*_),D=st(v*E),R=st(g*E),N=st(_*v);return new Zh(T,D,N,R)}mul(e,r=!0){if(e===0n)return r===!0?Lo("cannot multiply by 0"):dx;if(typeof e=="bigint"&&0n<e&&e<cx||Lo("invalid scalar, must be < L"),!r&&this.is0()||e===1n)return this;if(this.equals(Sx))return yle(e).p;let n=dx,i=Sx;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):r&&(i=i.add(a));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(W1.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(cx/2n,!1).double();return cx%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:r,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=a9(n);return st(n*i)!==1n&&Lo("invalid inverse"),{x:st(e*i),y:st(r*i)}}toRawBytes(){let{x:e,y:r}=this.toAffine(),n=ule(r);return n[31]|=e&1n?128:0,n}toHex(){return bI(this.toRawBytes())}};dm.BASE=new dm(UD,KD,1n,st(UD*KD));dm.ZERO=new dm(0n,1n,1n,0n);({BASE:Sx,ZERO:dx}=dm),s9=(t,e)=>t.toString(16).padStart(e,"0"),bI=t=>Array.from(t).map(e=>s9(e,2)).join(""),xI=t=>{let e=t.length;(!o9(t)||e%2)&&Lo("hex invalid 1");let r=cm(e/2);for(let n=0;n<r.length;n++){let i=n*2,a=t.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&Lo("hex invalid 2"),r[n]=s}return r},ule=t=>xI(s9(t,32*2)).reverse(),lle=t=>BigInt("0x"+bI(cm(vI(t)).reverse())),JK=(...t)=>{let e=cm(t.reduce((n,i)=>n+vI(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},a9=(t,e=Bi)=>{(t===0n||e<=0n)&&Lo("no inverse n="+t+" mod="+e);let r=st(t,e),n=e,i=0n,a=1n,s=1n,o=0n;for(;r!==0n;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}return n===1n?st(i,e):Lo("no inverse")},_c=(t,e)=>{let r=t;for(;e-- >0n;)r*=r,r%=Bi;return r},fle=t=>{let e=t*t%Bi*t%Bi,r=_c(e,2n)*e%Bi,n=_c(r,1n)*t%Bi,i=_c(n,5n)*n%Bi,a=_c(i,10n)*i%Bi,s=_c(a,20n)*a%Bi,o=_c(s,40n)*s%Bi,d=_c(o,80n)*o%Bi,u=_c(d,80n)*o%Bi,c=_c(u,10n)*i%Bi;return{pow_p_5_8:_c(c,2n)*t%Bi,b2:e}},ZK=19681161376707505956807079304988542015446066515923890162744021073123829784752n,ple=(t,e)=>{let r=st(e*e*e),n=st(r*r*e),i=fle(t*n).pow_p_5_8,a=st(t*r*i),s=st(e*a*a),o=a,d=st(a*ZK),u=s===t,c=s===st(-t),l=s===st(-t*ZK);return u&&(a=o),(c||l)&&(a=d),(st(a)&1n)===1n&&(a=st(-a)),{isValid:u||c,value:a}},YK=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,hle={bytesToHex:bI,hexToBytes:xI,concatBytes:JK,mod:st,invert:a9,randomBytes:t=>{let e=YK();return e||Lo("crypto.getRandomValues must be defined"),e.getRandomValues(cm(t))},sha512Async:async(...t)=>{let e=YK();e||Lo("crypto.subtle or etc.sha512Async must be defined");let r=JK(...t);return cm(await e.subtle.digest("SHA-512",r.buffer))},sha512Sync:void 0};Object.defineProperties(hle,{sha512Sync:{configurable:!1,get(){return wD},set(t){wD||(wD=t)}}});Cf=8,mle=()=>{let t=[],e=256/Cf+1,r=Sx,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let a=1;a<2**(Cf-1);a++)n=n.add(r),t.push(n);r=n.double()}return t},yle=t=>{let e=VK||(VK=mle()),r=(c,l)=>{let f=l.negate();return c?f:l},n=dx,i=Sx,a=1+256/Cf,s=2**(Cf-1),o=BigInt(2**Cf-1),d=2**Cf,u=BigInt(Cf);for(let c=0;c<a;c++){let l=c*s,f=Number(t&o);t>>=u,f>s&&(f-=d,t+=1n);let h=l,p=l+Math.abs(f)-1,m=c%2!==0,g=f<0;f===0?i=i.add(r(m,e[h])):n=n.add(r(g,e[p]))}return{p:n,f:i}},PI=2n**256n,Nf=PI-0x1000003d1n,_I=PI-0x14551231950b75fc4402da1732fc9bebfn,c9=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,d9=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,u9={p:Nf,n:_I,a:0n,b:7n,Gx:c9,Gy:d9},im=32,QK=t=>Ye(Ye(t*t)*t+u9.b),ui=(t="")=>{throw new Error(t)},Nx=t=>typeof t=="bigint",l9=t=>typeof t=="string",vD=t=>Nx(t)&&0n<t&&t<Nf,f9=t=>Nx(t)&&0n<t&&t<_I,p9=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?ui("Uint8Array expected"):t,Qw=t=>new Uint8Array(t),EI=(t,e)=>p9(l9(t)?Ux(t):Qw(t),e),Ye=(t,e=Nf)=>{let r=t%e;return r>=0n?r:e+r},XK=t=>t instanceof um?t:ui("Point expected"),um=class Yh{constructor(e,r,n){this.px=e,this.py=r,this.pz=n}static fromAffine(e){return new Yh(e.x,e.y,1n)}static fromHex(e){e=EI(e);let r,n=e[0],i=e.subarray(1),a=tq(i,0,im),s=e.length;if(s===33&&[2,3].includes(n)){vD(a)||ui("Point hex invalid: x not FE");let o=gle(QK(a)),d=(o&1n)===1n;(n&1)===1!==d&&(o=Ye(-o)),r=new Yh(a,o,1n)}return s===65&&n===4&&(r=new Yh(a,tq(i,im,2*im),1n)),r?r.ok():ui("Point is not on curve")}static fromPrivateKey(e){return Lw.mul(wle(e))}get x(){return this.aff().x}get y(){return this.aff().y}equals(e){let{px:r,py:n,pz:i}=this,{px:a,py:s,pz:o}=XK(e),d=Ye(r*o),u=Ye(a*i),c=Ye(n*o),l=Ye(s*i);return d===u&&c===l}negate(){return new Yh(this.px,Ye(-this.py),this.pz)}double(){return this.add(this)}add(e){let{px:r,py:n,pz:i}=this,{px:a,py:s,pz:o}=XK(e),{a:d,b:u}=u9,c=0n,l=0n,f=0n,h=Ye(u*3n),p=Ye(r*a),m=Ye(n*s),g=Ye(i*o),_=Ye(r+n),v=Ye(a+s);_=Ye(_*v),v=Ye(p+m),_=Ye(_-v),v=Ye(r+i);let E=Ye(a+o);return v=Ye(v*E),E=Ye(p+g),v=Ye(v-E),E=Ye(n+i),c=Ye(s+o),E=Ye(E*c),c=Ye(m+g),E=Ye(E-c),f=Ye(d*v),c=Ye(h*g),f=Ye(c+f),c=Ye(m-f),f=Ye(m+f),l=Ye(c*f),m=Ye(p+p),m=Ye(m+p),g=Ye(d*g),v=Ye(h*v),m=Ye(m+g),g=Ye(p-g),g=Ye(d*g),v=Ye(v+g),p=Ye(m*v),l=Ye(l+p),p=Ye(E*v),c=Ye(_*c),c=Ye(c-p),p=Ye(_*m),f=Ye(E*f),f=Ye(f+p),new Yh(c,l,f)}mul(e,r=!0){if(!r&&e===0n)return ux;if(f9(e)||ui("invalid scalar"),this.equals(Lw))return Ple(e).p;let n=ux,i=Lw;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):r&&(i=i.add(a));return n}mulAddQUns(e,r,n){return this.mul(r,!1).add(e.mul(n,!1)).ok()}toAffine(){let{px:e,py:r,pz:n}=this;if(this.equals(ux))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let i=m9(n);return Ye(n*i)!==1n&&ui("invalid inverse"),{x:Ye(e*i),y:Ye(r*i)}}assertValidity(){let{x:e,y:r}=this.aff();return(!vD(e)||!vD(r))&&ui("Point invalid: x or y"),Ye(r*r)===QK(e)?this:ui("Point invalid: not on curve")}multiply(e){return this.mul(e)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(e=!0){let{x:r,y:n}=this.aff();return(e?(n&1n)===0n?"02":"03":"04")+rq(r)+(e?"":rq(n))}toRawBytes(e=!0){return Ux(this.toHex(e))}};um.BASE=new um(c9,d9,1n);um.ZERO=new um(0n,1n,0n);({BASE:Lw,ZERO:ux}=um),h9=(t,e)=>t.toString(16).padStart(e,"0"),SI=t=>Array.from(t).map(e=>h9(e,2)).join(""),Ux=t=>{let e=t.length;(!l9(t)||e%2)&&ui("hex invalid 1");let r=Qw(e/2);for(let n=0;n<r.length;n++){let i=n*2,a=t.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&ui("hex invalid 2"),r[n]=s}return r},Kx=t=>BigInt("0x"+(SI(t)||"0")),tq=(t,e,r)=>Kx(t.slice(e,r)),TI=t=>Nx(t)&&t>=0n&&t<PI?Ux(h9(t,2*im)):ui("bigint expected"),rq=t=>SI(TI(t)),nq=(...t)=>{let e=Qw(t.reduce((n,i)=>n+p9(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},m9=(t,e=Nf)=>{(t===0n||e<=0n)&&ui("no inverse n="+t+" mod="+e);let r=Ye(t,e),n=e,i=0n,a=1n,s=1n,o=0n;for(;r!==0n;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}return n===1n?Ye(i,e):ui("no inverse")},gle=t=>{let e=1n;for(let r=t,n=(Nf+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*r%Nf),r=r*r%Nf;return Ye(e*e)===t?e:ui("sqrt invalid")},wle=t=>(Nx(t)||(t=Kx(EI(t,im))),f9(t)?t:ui("private key out of range")),iq=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;ble={hexToBytes:Ux,bytesToHex:SI,concatBytes:nq,bytesToNumberBE:Kx,numberToBytesBE:TI,mod:Ye,invert:m9,hmacSha256Async:async(t,...e)=>{let r=iq();if(!r)return ui("etc.hmacSha256Async not set");let n=r.subtle,i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Qw(await n.sign("HMAC",i,nq(...e)))},hmacSha256Sync:lx,hashToPrivateKey:vle,randomBytes:t=>{let e=iq();return e||ui("crypto.getRandomValues must be defined"),e.getRandomValues(Qw(t))}};Object.defineProperties(ble,{hmacSha256Sync:{configurable:!1,get(){return lx},set(t){lx||(lx=t)}}});$f=8,xle=()=>{let t=[],e=256/$f+1,r=Lw,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let a=1;a<2**($f-1);a++)n=n.add(r),t.push(n);r=n.double()}return t},Ple=t=>{let e=eq||(eq=xle()),r=(c,l)=>{let f=l.negate();return c?f:l},n=ux,i=Lw,a=1+256/$f,s=2**($f-1),o=BigInt(2**$f-1),d=2**$f,u=BigInt($f);for(let c=0;c<a;c++){let l=c*s,f=Number(t&o);t>>=u,f>s&&(f-=d,t+=1n);let h=l,p=l+Math.abs(f)-1,m=c%2!==0,g=f<0;f===0?i=i.add(r(m,e[h])):n=n.add(r(g,e[p]))}return{p:n,f:i}};(function(t){t.Mainnet="mainnet",t.Testnet="test"})(oq||(oq={}));(function(t){t.Authentication="authentication",t.AssertionMethod="assertionMethod",t.CapabilityInvocation="capabilityInvocation",t.CapabilityDelegation="capabilityDelegation",t.KeyAgreement="keyAgreement"})(sq||(sq={}));Sw=class If{static appendPathToUrl({baseUrl:e,path:r}){let n=new URL(e);return n.pathname=n.pathname.endsWith("/")?n.pathname:n.pathname+"/",n.pathname+=r.startsWith("/")?r.substring(1):r,n.toString()}static async computeLongFormDidUri({recoveryKey:e,updateKey:r,services:n,verificationMethods:i}){let a=await If.createIonDocument({services:n,verificationMethods:i}),s=If.normalizeJwk(e),o=If.normalizeJwk(r);return await cle.createLongFormDid({document:a,recoveryKey:s,updateKey:o})}static async constructCreateRequest({ionDocument:e,recoveryKey:r,updateKey:n}){return await n9.createCreateRequest({document:e,recoveryKey:If.normalizeJwk(r),updateKey:If.normalizeJwk(n)})}static async createIonDocument({services:e,verificationMethods:r}){let n=[];for(let a of r){let s=a.id??a.publicKeyJwk.kid??await lr({jwk:a.publicKeyJwk});s=`${s.split("#").pop()}`;let o={id:s,publicKeyJwk:If.normalizeJwk(a.publicKeyJwk),purposes:a.purposes,type:"JsonWebKey2020"};n.push(o)}let i=e.map(a=>({...a,id:`${a.id.split("#").pop()}`}));return{publicKeys:n,services:i}}static normalizeJwk(e){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);return n}},_le=(t=>(t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519",t))(_le||{}),Ele={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},aq="https://ion.tbd.engineering",Sle=class Uw extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.verificationMethods?.some(p=>!(p.algorithm in Ele)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(p=>"id"in p).map(p=>p.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(p=>!p.id||!p.type||!p.serviceEndpoint))throw new Error("One or more services are missing required properties");let i={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},a=[];for(let p of r.verificationMethods??[i]){let m=await e.generateKey({algorithm:p.algorithm}),g=await e.getPublicKey({keyUri:m});a.push({id:p.id,publicKeyJwk:g,purposes:p.purposes??["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let s=await e.generateKey({algorithm:"secp256k1"}),o=await e.getPublicKey({keyUri:s}),d=await e.generateKey({algorithm:"secp256k1"}),u=await e.getPublicKey({keyUri:d}),c=await Sw.computeLongFormDidUri({recoveryKey:o,updateKey:u,services:r.services??[],verificationMethods:a}),{didDocument:l,didResolutionMetadata:f}=await Uw.resolve(c,{gatewayUri:r.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${f?.error}`);let h=new ea({uri:c,document:l,metadata:{published:!1,canonicalId:c.split(":",3).join(":"),recoveryKey:o,updateKey:u},keyManager:e});if(r.publish??!0){let p=await Uw.publish({did:h,gatewayUri:r.gatewayUri});h.metadata=p.didDocumentMetadata}return h}static async getSigningMethod({didDocument:e,methodId:r}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(a=>a.id===(r??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Uw.methodName)throw new Xe("methodNotSupported","Method not supported");return await ea.import({portableDid:e,keyManager:r})}static async publish({did:e,gatewayUri:r=aq}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:bL({didDocument:e.document,methodId:s.id})}))??[],i=await Sw.createIonDocument({services:e.document.service??[],verificationMethods:n}),a=await Sw.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=Sw.appendPathToUrl({baseUrl:r,path:"/operations"}),o=await fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:AbortSignal.timeout(3e4)});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:o.ok},didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:"internalError",errorMessage:`Failed to publish DID document for: ${e.uri}`}}}}static async resolve(e,r={}){let n=Vn.parse(e);if(!n)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Uw.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let i=r?.gatewayUri??aq;try{let a=Sw.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(a,{signal:AbortSignal.timeout(3e4)});if(!s.ok)throw new Xe("notFound",`Unable to find DID document for: ${e}`);let{didDocument:o,didDocumentMetadata:d}=await s.json();return{...li,...o&&{didDocument:o},didDocumentMetadata:{published:d?.method?.published,...d}}}catch(a){if(!(a instanceof Xe))throw new Error(a);return{...li,didResolutionMetadata:{error:a.code,...a.message&&{errorMessage:a.message}}}}}};Sle.methodName="ion";y9=class Kw extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),a=await e.getPublicKey({keyUri:i}),s=tt.object(a).toBase64Url(),o=`did:${Kw.methodName}:${s}`,d=(await Kw.resolve(o)).didDocument;return new ea({uri:o,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Vn.parse(e.id);if(r&&r.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return n}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Kw.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(n.document.verificationMethod.length!==1)throw new Xe("invalidDidDocument","DID document must contain exactly one verification method");return n}static async resolve(e,r){let n=Vn.parse(e),i;try{i=n?tt.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Kw.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let a={"@context":["https://www.w3.org/ns/did/v1"],id:n.uri},s=`${a.id}#0`;switch(a.verificationMethod=[{id:s,type:"JsonWebKey",controller:a.id,publicKeyJwk:i}],a.authentication=[s],a.assertionMethod=[s],a.capabilityInvocation=[s],a.capabilityDelegation=[s],a.keyAgreement=[s],i.use){case"sig":{delete a.keyAgreement;break}case"enc":{delete a.authentication,delete a.assertionMethod,delete a.capabilityInvocation,delete a.capabilityDelegation;break}}return{...li,didDocument:a}}};y9.methodName="jwk";Jf=y9,Tle={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},fx=class Qh{static async jwkToMulticodec({jwk:e}){let r=[];e.crv&&(r.push(e.crv),e.d?r.push("private"):r.push("public"));let n=r.join(":"),i=Qh.JWK_TO_MULTICODEC[n];if(i===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${n}'`);return{code:Xs.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let r={"P-256":no.compressPublicKey,secp256k1:ji.compressPublicKey}[e];if(!r)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${e}`);return r}static keyConverter(e){let r={Ed25519:Mi,"P-256":no,secp256k1:ji}[e];if(!r)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${e}`);return r}static async multicodecToJwk({code:e,name:r}){if(!(r?!e:e))throw new Error("Either 'name' or 'code' must be defined, but not both.");r=r===void 0?Xs.getNameFromCode({code:e}):r;let n=r,i=Qh.MULTICODEC_TO_JWK[n];if(i===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return{...i}}static async publicKeyToMultibaseId({publicKey:e}){if(!(e?.crv&&e.crv in Tle))throw new Xe("invalidPublicKeyType",`Public key contains an unsupported key type: ${e?.crv??"undefined"}`);let r=await Qh.keyConverter(e.crv).publicKeyToBytes({publicKey:e});/^(secp256k1|P-256|P-384|P-521)$/.test(e.crv)&&(r=await Qh.keyCompressor(e.crv)({publicKeyBytes:r}));let{name:n}=await Qh.jwkToMulticodec({jwk:e});return PL({keyBytes:r,multicodecName:n})}};fx.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv"},fx.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,237:32},fx.MULTICODEC_TO_JWK={"ed25519-pub":{crv:"Ed25519",kty:"OKP",x:""},"ed25519-priv":{crv:"Ed25519",kty:"OKP",x:"",d:""},"secp256k1-pub":{crv:"secp256k1",kty:"EC",x:"",y:""},"secp256k1-priv":{crv:"secp256k1",kty:"EC",x:"",y:"",d:""}};H1=fx,kle=(t=>(t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t))(kle||{}),cq={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},g9=class Vu extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),a=await e.getPublicKey({keyUri:i}),s=await H1.publicKeyToMultibaseId({publicKey:a}),o=`did:${Vu.methodName}:${s}`,d=(await Vu.resolve(o,r)).didDocument;return new ea({uri:o,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Vn.parse(e.id);if(r&&r.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(a=>a.id===n);if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Vu.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(n.document.verificationMethod.length!==1)throw new Xe("invalidDidDocument","DID document must contain exactly one verification method");return n}static async resolve(e,r){try{let n=await Vu.createDocument({didUri:e,options:r});return{...li,didDocument:n}}catch(n){if(!(n instanceof Xe))throw new Error(n);return{...li,didResolutionMetadata:{error:n.code,...n.message&&{errorMessage:n.message}}}}}static async createDocument({didUri:e,options:r={}}){let{defaultContext:n="https://www.w3.org/ns/did/v1",enableExperimentalPublicKeyTypes:i=!1,publicKeyFormat:a="JsonWebKey2020"}=r,s={id:""},o=Vn.parse(e);if(!o)throw new Xe("invalidDid",`Invalid DID URI: ${e}`);let d=o.id;if(o.method!==Vu.methodName)throw new Xe("methodNotSupported",`Method not supported: ${o.method}`);if(!Vu.validateIdentifier(o))throw new Xe("invalidDid",`Invalid DID URI: ${e}`);let u=await Vu.createSignatureMethod({didUri:e,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:i,publicKeyFormat:a}});s.id=o.uri,s.verificationMethod=[u],s.authentication=[u.id],s.assertionMethod=[u.id],s.capabilityInvocation=[u.id],s.capabilityDelegation=[u.id];let c=[n];return vL({didDocument:s}).forEach(l=>{let f=cq[l];c.push(f)}),s["@context"]=c,s}static async createSignatureMethod({didUri:e,multibaseValue:r,options:n}){let{enableExperimentalPublicKeyTypes:i,publicKeyFormat:a}=n,s={id:"",type:"",controller:""},{keyBytes:o,multicodecCode:d,multicodecName:u}=_L({multibaseKeyId:r}),c=o.byteLength,l=H1.MULTICODEC_PUBLIC_KEY_LENGTH[d];if(c!==l)throw new Xe("invalidPublicKeyLength",`Expected ${c} bytes. Actual: ${l}`);let f=!1;switch(u){case"secp256k1-pub":f=await ji.validatePublicKey({publicKeyBytes:o});break;case"ed25519-pub":f=await Mi.validatePublicKey({publicKeyBytes:o});break}if(!f)throw new Xe("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${r}`;try{new URL(s.id)}catch{throw new Xe("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(a in cq))throw new Xe("unsupportedPublicKeyType",`Unsupported format: ${a}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(a))throw new Xe("invalidPublicKeyType",`Specified '${a}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=a,s.controller=e,a==="Ed25519VerificationKey2020"&&(s.publicKeyMultibase=r),a==="JsonWebKey2020"){let{crv:h}=await H1.multicodecToJwk({code:d});s.publicKeyJwk=await H1.keyConverter(h).bytesToPublicKey({publicKeyBytes:o})}return s}static validateIdentifier(e){let{method:r,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&r==="key"&&!0&&bD(n)==="String"&&n.startsWith("z")}};g9.methodName="key";qx=g9,Ale=3e4;w9=class px extends n0{static async create({keyManager:e=new Ka,options:r}){if(!r.domain)throw new Xe("invalidDid","The 'domain' option is required for did:web creation");if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");let n=r.path?`${r.domain}:${r.path}`:r.domain,i=`did:${px.methodName}:${n}`;if(!Vn.parse(i))throw new Xe("invalidDid",`The constructed DID URI is invalid: ${i}`);let a=r.verificationMethods??[{algorithm:r.algorithm??"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]}],s={"@context":["https://www.w3.org/ns/did/v1"],id:i};for(let o=0;o<a.length;o++){let d=a[o],u=await e.generateKey({algorithm:d.algorithm}),c=await e.getPublicKey({keyUri:u}),l=d.id?.split("#").pop()??`key-${o}`,f=`${i}#${l}`;s.verificationMethod??=[],s.verificationMethod.push({id:f,type:"JsonWebKey",controller:d.controller??i,publicKeyJwk:c});for(let h of d.purposes??[])s[h]??=[],s[h].push(f)}return r.services&&(s.service=r.services.map(o=>({...o,id:`${i}#${o.id.split("#").pop()}`}))),new ea({uri:i,document:s,metadata:{published:!1},keyManager:e})}static async getSigningMethod({didDocument:e,methodId:r}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=To(r)??To(e.assertionMethod?.[0]),a=i?e.verificationMethod?.find(s=>To(s.id)===i):e.verificationMethod?.[0];if(!(a&&a.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return a}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==px.methodName)throw new Xe("methodNotSupported","Method not supported");return await ea.import({portableDid:e,keyManager:r})}static async resolve(e,r){let n=Vn.parse(e);if(!n)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==px.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let i=`https://${n.id.replace(/:/g,"/")}`;i=decodeURIComponent(i);let a=n.id.includes(":")?`${i}/did.json`:`${i}/.well-known/did.json`;try{let s=new URL(a);if(Dle(s.hostname))return{...li,didResolutionMetadata:{error:"notFound"}};let o=await fetch(a,{signal:AbortSignal.timeout(Ale)});if(!o.ok)throw new Error("HTTP error status code returned");let d=await o.json();return{...li,didDocument:d}}catch{return{...li,didResolutionMetadata:{error:"notFound"}}}}};w9.methodName="web";kI=w9,x4e=Lf(wq(),1),P4e=Lf(vq(),1),Ile=Lf(vq(),1),Lx=class{constructor({ttl:t="15m"}={}){this.cache=new Loe.default({ttl:(0,Ile.default)(t)})}async open(){}async get(t){if(!t)throw new Error("Key cannot be null or undefined");return this.cache.get(t)}async set(t,e){this.cache.set(t,e)}async delete(t){this.cache.delete(t)}async clear(){this.cache.clear()}async close(){}},Rle={open(){return Promise.resolve()},get(t){return Promise.resolve(void 0)},set(t,e){return Promise.resolve()},delete(t){return Promise.resolve()},clear(){return Promise.resolve()},close(){return Promise.resolve()}},s0=class{constructor({cache:t,didResolvers:e}){this.didResolvers=new Map,this.cache=t||Rle;for(let r of e)this.didResolvers.set(r.methodName,r)}async open(){await this.cache.open()}async close(){await this.cache.close()}async resolve(t,e){let r=Vn.parse(t);if(!r)return{...li,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${t}`}};let n=this.didResolvers.get(r.method);if(!n)return{...li,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${r.method}`}};let i=await this.cache.get(r.uri);if(i)return i;{let a=await n.resolve(r.uri,e);return a.didResolutionMetadata.error||await this.cache.set(r.uri,a),a}}async dereference(t,e){let r=Vn.parse(t);if(!r)return{dereferencingMetadata:{error:"invalidDidUrl"},contentStream:null,contentMetadata:{}};let{didDocument:n,didResolutionMetadata:i,didDocumentMetadata:a}=await this.resolve(r.uri);if(!n)return{dereferencingMetadata:{error:i.error},contentStream:null,contentMetadata:{}};if(!r.fragment||r.query)return{dereferencingMetadata:{contentType:"application/did+json"},contentStream:n,contentMetadata:a};let{service:s=[],verificationMethod:o=[]}=n,d=new Set([t,r.fragment,`#${r.fragment}`]),u;for(let c of o)if(d.has(c.id)){u=c;break}for(let c of s)if(d.has(c.id)){u=c;break}return u?{dereferencingMetadata:{contentType:"application/did+json"},contentStream:u,contentMetadata:i}:{dereferencingMetadata:{error:"notFound"},contentStream:null,contentMetadata:{}}}};});var v9=F(()=>{"use strict";y();ok();ik();or();ps();j4();N4();K4();hs();jU();MU();qU();LU();zU();FU();GU();WU();N1();dD();Fo();Yt()});var zx=F(()=>{"use strict";y()});import{Level as PNe}from"level";var rl=F(()=>{"use strict";y();zx()});var Gx=F(()=>{"use strict";y();Dy();rl()});var x9=F(()=>{y()});var P9,Ole,_9,Ble,E9,S9=F(()=>{y();dl();vp();P9=0,Ole="identity",_9=ia,Ble=t=>ml(P9,_9(t)),E9={code:P9,name:Ole,encode:_9,digest:Ble}});var T9,jle,k9,A9=F(()=>{y();Fp();T9=wn(Rs(),1);Yc();jle=async(t,e,r,n,i,a,s,o)=>{let d=await s.get(t,o),u=K_(d),c=u,l=r;for(;n.length>0;){let f=n[0];if(f in c){n.shift(),l=`${l}/${f}`;let h=$n.asCID(c[f]);if(h!=null)return{entry:{type:"object",name:e,path:r,cid:t,node:d,depth:a,size:BigInt(d.length),content:async function*(){yield u}},next:{cid:h,name:f,path:l,toResolve:n}};c=c[f]}else throw(0,T9.default)(new Error(`No property named ${f} found in cbor node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:e,path:r,cid:t,node:d,depth:a,size:BigInt(d.length),content:async function*(){yield u}}}},k9=jle});function Mle(t,e,r,n){let i=BigInt(t.length),a=BigInt(e+i);return r>=a||n<e?new Uint8Array(0):(n>=e&&n<a&&(t=t.subarray(0,Number(n-e))),r>=e&&r<a&&(t=t.subarray(Number(r-e))),t)}var Zf,Wx=F(()=>{y();Zf=Mle});var a0,Nle,mm,Hx=F(()=>{y();a0=wn(Rs(),1),Nle=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),a=BigInt(r);if(a!==n&&(a=i+a),a>n&&(a=n),i<0n)throw(0,a0.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,a0.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(a<0n)throw(0,a0.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(a>n)throw(0,a0.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:a}},mm=Nle});var D9,Ule,Kle,I9,R9=F(()=>{y();D9=wn(Rs(),1);vp();Xc();Wx();Hx();Ule=t=>{async function*e(r={}){let{start:n,end:i}=mm(t.length,r.offset,r.length),a=Zf(t,0n,n,i);r.onProgress?.(new hn("unixfs:exporter:progress:identity",{bytesRead:BigInt(a.byteLength),totalBytes:i-n,fileSize:BigInt(t.byteLength)})),yield a}return e},Kle=async(t,e,r,n,i,a,s,o)=>{if(n.length>0)throw(0,D9.default)(new Error(`No link named ${r} found in raw node ${t}`),"ERR_NOT_FOUND");let d=q0(t.multihash.bytes);return{entry:{type:"identity",name:e,path:r,cid:t,content:Ule(d.digest),depth:a,size:BigInt(d.digest.length),node:d.digest}}},I9=Kle});var C9,qle,Lle,$9,O9=F(()=>{y();C9=wn(Rs(),1);Xc();Wx();Hx();qle=t=>{async function*e(r={}){let{start:n,end:i}=mm(t.length,r.offset,r.length),a=Zf(t,0n,n,i);r.onProgress?.(new hn("unixfs:exporter:progress:raw",{bytesRead:BigInt(a.byteLength),totalBytes:i-n,fileSize:BigInt(t.byteLength)})),yield a}return e},Lle=async(t,e,r,n,i,a,s,o)=>{if(n.length>0)throw(0,C9.default)(new Error(`No link named ${r} found in raw node ${t}`),"ERR_NOT_FOUND");let d=await s.get(t,o);return{entry:{type:"raw",name:e,path:r,cid:t,content:qle(d),depth:a,size:BigInt(d.length),node:d}}},$9=Lle});var zle,Fle,B9,Gle,j9,M9,N9=F(()=>{y();Cs();KE();qE();zle=async function(t){return(await Nv.encode(t)).slice(0,8).reverse()},Fle=async(t,e,r)=>{await Promise.all(t.map(async n=>{if(n.Name==null)throw new Error("Unexpected Link without a Name");if(n.Name.length===2){let i=parseInt(n.Name,16);e._putObjectAt(i,new ec({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(n.Name.substring(2),!0)}))},B9=t=>t.toString(16).toUpperCase().padStart(2,"0").substring(0,2),Gle=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()},j9=async(t,e,r,n,i)=>{if(n==null){let c=qv({hashFn:zle});n={rootBucket:c,hamtDepth:1,lastBucket:c}}await Fle(t.Links,n.lastBucket,n.rootBucket);let a=await n.rootBucket._findNewBucketAndPos(e),s=B9(a.pos),o=Gle(a);o.length>n.hamtDepth&&(n.lastBucket=o[n.hamtDepth],s=B9(n.lastBucket._posAtParent));let d=t.Links.find(c=>{if(c.Name==null)return!1;let l=c.Name.substring(0,2),f=c.Name.substring(2);return!(l!==s||f!==""&&f!==e)});if(d==null)return;if(d.Name!=null&&d.Name.substring(2)===e)return d.Hash;n.hamtDepth++;let u=await r.get(d.Hash,i);return t=Qc(u),j9(t,e,r,n,i)},M9=j9});function Wle(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Vx,AI=F(()=>{y();Vx=Wle});function Hle(t){return t[Symbol.asyncIterator]!=null}function Vle(t,e){let r=0;if(Hle(t))return async function*(){for await(let d of t)await e(d,r++)&&(yield d)}();let n=Vx(t),{value:i,done:a}=n.next();if(a===!0)return function*(){}();let s=e(i,r++);if(typeof s.then=="function")return async function*(){await s&&(yield i);for(let d of n)await e(d,r++)&&(yield d)}();let o=e;return function*(){s===!0&&(yield i);for(let d of n)o(d,r++)&&(yield d)}()}var U9,K9=F(()=>{y();AI();U9=Vle});function Jle(t){return t[Symbol.asyncIterator]!=null}function Zle(t,e){let r=0;if(Jle(t))return async function*(){for await(let d of t)yield e(d,r++)}();let n=Vx(t),{value:i,done:a}=n.next();if(a===!0)return function*(){}();let s=e(i,r++);if(typeof s.then=="function")return async function*(){yield await s;for(let d of n)yield e(d,r++)}();let o=e;return function*(){yield s;for(let d of n)yield o(d,r++)}()}var ym,Jx=F(()=>{y();AI();ym=Zle});function Go(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zx=F(()=>{y()});async function*Yf(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,a=[],s=Go(),o=Go(),d=!1,u,c=!1;i.addEventListener("task-complete",()=>{o.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of t){if(a.length===r&&(s=Go(),await s.promise),c)break;let m={done:!1};a.push(m),p().then(g=>{m.done=!0,m.ok=!0,m.value=g,i.dispatchEvent(new Yx("task-complete"))},g=>{m.done=!0,m.err=g,i.dispatchEvent(new Yx("task-complete"))})}d=!0,i.dispatchEvent(new Yx("task-complete"))}catch(p){u=p,i.dispatchEvent(new Yx("task-complete"))}});function l(){return n?a[0]?.done:!!a.find(p=>p.done)}function*f(){for(;a.length>0&&a[0].done;){let p=a[0];if(a.shift(),p.ok)yield p.value;else throw c=!0,s.resolve(),p.err;s.resolve()}}function*h(){for(;l();)for(let p=0;p<a.length;p++)if(a[p].done){let m=a[p];if(a.splice(p,1),p--,m.ok)yield m.value;else throw c=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(l()||(o=Go(),await o.promise),u!=null||(n?yield*f():yield*h(),u!=null))throw u;if(d&&a.length===0)break}}var Yx,Qx=F(()=>{y();Zx();Yx=globalThis.CustomEvent??Event});var Xx,gm,q9=F(()=>{y();Xx=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},gm=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xx(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Xx(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}});function eP(t={}){return Yle(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Yle(t,e){e=e??{};let r=e.onEnd,n=new gm,i,a,s,o=Go(),d=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,_)=>{a=v=>{a=null,n.push(v);try{g(t(n))}catch(E){_(E)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{o.resolve(),o=Go()})}},u=g=>a!=null?a(g):(n.push(g),i),c=g=>(n=new gm,a!=null?a({error:g}):(n.push({error:g}),i)),l=g=>{if(s)return i;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},f=g=>s?i:(s=!0,g!=null?c(g):u({done:!0})),h=()=>(n=new gm,f(),{done:!0}),p=g=>(f(g),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:d,return:h,throw:p,push:l,end:f,get readableLength(){return n.size},onEmpty:async g=>{let _=g?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let v,E;_!=null&&(v=new Promise((T,D)=>{E=()=>{D(new DI)},_.addEventListener("abort",E)}));try{await Promise.race([o.promise,v])}finally{E!=null&&_!=null&&_?.removeEventListener("abort",E)}}},r==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(g){return m.end(g),r!=null&&(r(g),r=void 0),i},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},i}var DI,II=F(()=>{y();Zx();q9();DI=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}}});function Qle(t){return t.reason}async function L9(t,e,r){if(e==null)return t;let n=r?.translateError??Qle;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((a,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var z9=F(()=>{y()});function F9(){return new RI}var RI,G9=F(()=>{y();Zx();z9();RI=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Go(),this.haveNext=Go()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Go(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Go(),await L9(this.readNext.promise,r?.signal,r)}}});function Xle(t){return t[Symbol.asyncIterator]!=null}async function efe(t,e,r){try{await Promise.all(t.map(async n=>{for await(let i of n)await e.push(i,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*tfe(t){let e=new AbortController,r=F9();efe(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*rfe(t){for(let e of t)yield*e}function nfe(...t){let e=[];for(let r of t)Xle(r)||e.push(r);return e.length===t.length?rfe(e):tfe(t)}var W9,H9=F(()=>{y();G9();W9=nfe});function wm(t,...e){if(t==null)throw new Error("Empty pipeline");if(CI(t)){let n=t;t=()=>n.source}else if(J9(t)||V9(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&CI(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)CI(r[n])&&(r[n]=ofe(r[n]));return ife(...r)}var ife,V9,J9,CI,ofe,tP=F(()=>{y();II();H9();ife=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},V9=t=>t?.[Symbol.asyncIterator]!=null,J9=t=>t?.[Symbol.iterator]!=null,CI=t=>t==null?!1:t.sink!=null&&t.source!=null,ofe=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=eP({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,a=t.source;if(V9(a))i=async function*(){yield*a,n.end()};else if(J9(a))i=function*(){yield*a,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return W9(n,i())}return t.source}});var sfe,Z9,Y9=F(()=>{y();K9();Jx();Qx();tP();Xc();sfe=(t,e,r,n,i,a,s)=>{async function*o(d={}){let u=d.offset??0,c=d.length??e.Links.length,l=e.Links.slice(u,c);d.onProgress?.(new hn("unixfs:exporter:walk:directory",{cid:t})),yield*wm(l,f=>ym(f,h=>async()=>{let p=h.Name??"",m=`${n}/${p}`;return(await i(h.Hash,p,m,[],a+1,s,d)).entry}),f=>Yf(f,{ordered:!0}),f=>U9(f,h=>h!=null))}return o},Z9=sfe});var X9=_e((qUe,$I)=>{"use strict";y();var afe=Object.prototype.hasOwnProperty,ko="~";function c0(){}Object.create&&(c0.prototype=Object.create(null),new c0().__proto__||(ko=!1));function cfe(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Q9(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var a=new cfe(r,n||t,i),s=ko?ko+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],a]:t._events[s].push(a):(t._events[s]=a,t._eventsCount++),t}function rP(t,e){--t._eventsCount===0?t._events=new c0:delete t._events[e]}function oo(){this._events=new c0,this._eventsCount=0}oo.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)afe.call(r,n)&&e.push(ko?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};oo.prototype.listeners=function(e){var r=ko?ko+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,s=new Array(a);i<a;i++)s[i]=n[i].fn;return s};oo.prototype.listenerCount=function(e){var r=ko?ko+e:e,n=this._events[r];return n?n.fn?1:n.length:0};oo.prototype.emit=function(e,r,n,i,a,s){var o=ko?ko+e:e;if(!this._events[o])return!1;var d=this._events[o],u=arguments.length,c,l;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,r),!0;case 3:return d.fn.call(d.context,r,n),!0;case 4:return d.fn.call(d.context,r,n,i),!0;case 5:return d.fn.call(d.context,r,n,i,a),!0;case 6:return d.fn.call(d.context,r,n,i,a,s),!0}for(l=1,c=new Array(u-1);l<u;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var f=d.length,h;for(l=0;l<f;l++)switch(d[l].once&&this.removeListener(e,d[l].fn,void 0,!0),u){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,r);break;case 3:d[l].fn.call(d[l].context,r,n);break;case 4:d[l].fn.call(d[l].context,r,n,i);break;default:if(!c)for(h=1,c=new Array(u-1);h<u;h++)c[h-1]=arguments[h];d[l].fn.apply(d[l].context,c)}}return!0};oo.prototype.on=function(e,r,n){return Q9(this,e,r,n,!1)};oo.prototype.once=function(e,r,n){return Q9(this,e,r,n,!0)};oo.prototype.removeListener=function(e,r,n,i){var a=ko?ko+e:e;if(!this._events[a])return this;if(!r)return rP(this,a),this;var s=this._events[a];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&rP(this,a);else{for(var o=0,d=[],u=s.length;o<u;o++)(s[o].fn!==r||i&&!s[o].once||n&&s[o].context!==n)&&d.push(s[o]);d.length?this._events[a]=d.length===1?d[0]:d:rP(this,a)}return this};oo.prototype.removeAllListeners=function(e){var r;return e?(r=ko?ko+e:e,this._events[r]&&rP(this,r)):(this._events=new c0,this._eventsCount=0),this};oo.prototype.off=oo.prototype.removeListener;oo.prototype.addListener=oo.prototype.on;oo.prefixed=ko;oo.EventEmitter=oo;typeof $I<"u"&&($I.exports=oo)});var OI,ez=F(()=>{y();OI=wn(X9(),1)});function jI(t,e,r,n){let i,a=new Promise((s,o)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(e===Number.POSITIVE_INFINITY){s(t);return}if(n={customTimers:{setTimeout,clearTimeout},...n},n.signal){let{signal:d}=n;d.aborted&&o(rz(d)),d.addEventListener("abort",()=>{o(rz(d))})}i=n.customTimers.setTimeout.call(void 0,()=>{if(typeof r=="function"){try{s(r())}catch(c){o(c)}return}let d=typeof r=="string"?r:`Promise timed out after ${e} milliseconds`,u=r instanceof Error?r:new d0(d);typeof t.cancel=="function"&&t.cancel(),o(u)},e),(async()=>{try{s(await t)}catch(d){o(d)}finally{n.customTimers.clearTimeout.call(void 0,i)}})()});return a.clear=()=>{clearTimeout(i),i=void 0},a}var d0,BI,tz,rz,nz=F(()=>{y();d0=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},BI=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},tz=t=>globalThis.DOMException===void 0?new BI(t):new DOMException(t),rz=t=>{let e=t.reason===void 0?tz("This operation was aborted."):t.reason;return e instanceof Error?e:tz(e)}});function MI(t,e,r){let n=0,i=t.length;for(;i>0;){let a=Math.trunc(i/2),s=n+a;r(t[s],e)<=0?(n=++s,i-=a+1):i=a}return n}var iz=F(()=>{y()});var Qf,Bd,NI,oz,sz=F(()=>{y();iz();Qf=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},NI=class{constructor(){Bd.set(this,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&Qf(this,Bd,"f")[this.size-1].priority>=r.priority){Qf(this,Bd,"f").push(n);return}let i=MI(Qf(this,Bd,"f"),n,(a,s)=>s.priority-a.priority);Qf(this,Bd,"f").splice(i,0,n)}dequeue(){let e=Qf(this,Bd,"f").shift();return e?.run}filter(e){return Qf(this,Bd,"f").filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return Qf(this,Bd,"f").length}};Bd=new WeakMap;oz=NI});var cn,Ve,Rn,l0,f0,il,cP,p0,nP,qa,u0,Ps,iP,_s,h0,nl,oP,az,cz,lz,dz,uz,sP,UI,KI,dP,fz,aP,uP,qI,pz,hz=F(()=>{y();ez();nz();sz();cn=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Ve=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},uP=class extends Error{},qI=class extends OI.default{constructor(e){var r,n,i,a;if(super(),Rn.add(this),l0.set(this,void 0),f0.set(this,void 0),il.set(this,0),cP.set(this,void 0),p0.set(this,void 0),nP.set(this,0),qa.set(this,void 0),u0.set(this,void 0),Ps.set(this,void 0),iP.set(this,void 0),_s.set(this,0),h0.set(this,void 0),nl.set(this,void 0),oP.set(this,void 0),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:oz,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(n=(r=e.intervalCap)===null||r===void 0?void 0:r.toString())!==null&&n!==void 0?n:""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(a=(i=e.interval)===null||i===void 0?void 0:i.toString())!==null&&a!==void 0?a:""}\` (${typeof e.interval})`);cn(this,l0,e.carryoverConcurrencyCount,"f"),cn(this,f0,e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,"f"),cn(this,cP,e.intervalCap,"f"),cn(this,p0,e.interval,"f"),cn(this,Ps,new e.queueClass,"f"),cn(this,iP,e.queueClass,"f"),this.concurrency=e.concurrency,this.timeout=e.timeout,cn(this,oP,e.throwOnTimeout===!0,"f"),cn(this,nl,e.autoStart===!1,"f")}get concurrency(){return Ve(this,h0,"f")}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);cn(this,h0,e,"f"),Ve(this,Rn,"m",dP).call(this)}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:Ve(this,oP,"f"),...r},new Promise((n,i)=>{Ve(this,Ps,"f").enqueue(async()=>{var a,s,o;cn(this,_s,(s=Ve(this,_s,"f"),s++,s),"f"),cn(this,il,(o=Ve(this,il,"f"),o++,o),"f");try{if(!((a=r.signal)===null||a===void 0)&&a.aborted)throw new uP("The task was aborted.");let d=e({signal:r.signal});r.timeout&&(d=jI(Promise.resolve(d),r.timeout)),r.signal&&(d=Promise.race([d,Ve(this,Rn,"m",fz).call(this,r.signal)]));let u=await d;n(u),this.emit("completed",u)}catch(d){if(d instanceof d0&&!r.throwOnTimeout){n();return}i(d),this.emit("error",d)}finally{Ve(this,Rn,"m",lz).call(this)}},r),this.emit("add"),Ve(this,Rn,"m",sP).call(this)})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return Ve(this,nl,"f")?(cn(this,nl,!1,"f"),Ve(this,Rn,"m",dP).call(this),this):this}pause(){cn(this,nl,!0,"f")}clear(){cn(this,Ps,new(Ve(this,iP,"f")),"f")}async onEmpty(){Ve(this,Ps,"f").size!==0&&await Ve(this,Rn,"m",aP).call(this,"empty")}async onSizeLessThan(e){Ve(this,Ps,"f").size<e||await Ve(this,Rn,"m",aP).call(this,"next",()=>Ve(this,Ps,"f").size<e)}async onIdle(){Ve(this,_s,"f")===0&&Ve(this,Ps,"f").size===0||await Ve(this,Rn,"m",aP).call(this,"idle")}get size(){return Ve(this,Ps,"f").size}sizeBy(e){return Ve(this,Ps,"f").filter(e).length}get pending(){return Ve(this,_s,"f")}get isPaused(){return Ve(this,nl,"f")}};l0=new WeakMap,f0=new WeakMap,il=new WeakMap,cP=new WeakMap,p0=new WeakMap,nP=new WeakMap,qa=new WeakMap,u0=new WeakMap,Ps=new WeakMap,iP=new WeakMap,_s=new WeakMap,h0=new WeakMap,nl=new WeakMap,oP=new WeakMap,Rn=new WeakSet,az=function(){return Ve(this,f0,"f")||Ve(this,il,"f")<Ve(this,cP,"f")},cz=function(){return Ve(this,_s,"f")<Ve(this,h0,"f")},lz=function(){var e;cn(this,_s,(e=Ve(this,_s,"f"),e--,e),"f"),Ve(this,Rn,"m",sP).call(this),this.emit("next")},dz=function(){Ve(this,Rn,"m",KI).call(this),Ve(this,Rn,"m",UI).call(this),cn(this,u0,void 0,"f")},uz=function(){let e=Date.now();if(Ve(this,qa,"f")===void 0){let r=Ve(this,nP,"f")-e;if(r<0)cn(this,il,Ve(this,l0,"f")?Ve(this,_s,"f"):0,"f");else return Ve(this,u0,"f")===void 0&&cn(this,u0,setTimeout(()=>{Ve(this,Rn,"m",dz).call(this)},r),"f"),!0}return!1},sP=function(){if(Ve(this,Ps,"f").size===0)return Ve(this,qa,"f")&&clearInterval(Ve(this,qa,"f")),cn(this,qa,void 0,"f"),this.emit("empty"),Ve(this,_s,"f")===0&&this.emit("idle"),!1;if(!Ve(this,nl,"f")){let e=!Ve(this,Rn,"a",uz);if(Ve(this,Rn,"a",az)&&Ve(this,Rn,"a",cz)){let r=Ve(this,Ps,"f").dequeue();return r?(this.emit("active"),r(),e&&Ve(this,Rn,"m",UI).call(this),!0):!1}}return!1},UI=function(){Ve(this,f0,"f")||Ve(this,qa,"f")!==void 0||(cn(this,qa,setInterval(()=>{Ve(this,Rn,"m",KI).call(this)},Ve(this,p0,"f")),"f"),cn(this,nP,Date.now()+Ve(this,p0,"f"),"f"))},KI=function(){Ve(this,il,"f")===0&&Ve(this,_s,"f")===0&&Ve(this,qa,"f")&&(clearInterval(Ve(this,qa,"f")),cn(this,qa,void 0,"f")),cn(this,il,Ve(this,l0,"f")?Ve(this,_s,"f"):0,"f"),Ve(this,Rn,"m",dP).call(this)},dP=function(){for(;Ve(this,Rn,"m",sP).call(this););},fz=async function(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(new uP("The task was aborted."))},{once:!0})})},aP=async function(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})};pz=qI});async function mz(t,e,r,n,i,a,s){if(e instanceof Uint8Array){let u=Zf(e,n,i,a);r.push(u);return}if(e.Data==null)throw(0,Xf.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let o;try{o=ti.unmarshal(e.Data)}catch(u){throw(0,Xf.default)(u,"ERR_NOT_UNIXFS")}if(o.data!=null){let u=o.data,c=Zf(u,n,i,a);r.push(c),n+=BigInt(c.byteLength)}let d=[];if(e.Links.length!==o.blockSizes.length)throw(0,Xf.default)(new Error("Inconsistent block sizes and dag links"),"ERR_NOT_UNIXFS");for(let u=0;u<e.Links.length;u++){let c=e.Links[u],l=n,f=l+o.blockSizes[u];if((i>=l&&i<f||a>=l&&a<=f||i<l&&a>f)&&d.push({link:c,blockStart:n}),n=f,n>a)break}await wm(d,u=>ym(u,c=>async()=>{let l=await t.get(c.link.Hash,s);return{...c,block:l}}),u=>Yf(u,{ordered:!0}),async u=>{for await(let{link:c,block:l,blockStart:f}of u){let h;switch(c.Hash.code){case Oy:h=Qc(l);break;case iu:h=l;break;default:r.end((0,Xf.default)(new Error(`Unsupported codec: ${c.Hash.code}`),"ERR_NOT_UNIXFS"));return}let p=new pz({concurrency:1});p.on("error",m=>{r.end(m)}),p.add(async()=>{s.onProgress?.(new hn("unixfs:exporter:walk:file",{cid:c.Hash})),await mz(t,h,r,f,i,a,s)}),await p.onIdle()}}),n>=a&&r.end()}var Xf,dfe,LI,yz=F(()=>{y();Cs();Xf=wn(Rs(),1);nu();Jx();Qx();tP();II();Ly();hz();Xc();Wx();Hx();dfe=(t,e,r,n,i,a,s)=>{async function*o(d={}){let u=r.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:c,end:l}=mm(u,d.offset,d.length);if(l===0n)return;let f=0n,h=l-c,p=eP();d.onProgress?.(new hn("unixfs:exporter:walk:file",{cid:t})),mz(s,e,p,0n,c,l,d).catch(m=>{p.end(m)});for await(let m of p)if(m!=null){if(f+=BigInt(m.byteLength),f>h)throw p.end(),(0,Xf.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");f===h&&p.end(),d.onProgress?.(new hn("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:h,fileSize:u})),yield m}if(f<h)throw(0,Xf.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return o},LI=dfe});async function*gz(t,e,r,n,i,a){let s=t.Links,o=wm(s,d=>ym(d,u=>async()=>{let c=u.Name!=null?u.Name.substring(2):null;if(c!=null&&c!==""){let l=await r(u.Hash,c,`${e}/${c}`,[],n+1,i,a);return{entries:l.entry==null?[]:[l.entry]}}else{let l=await i.get(u.Hash,a);return t=Qc(l),a.onProgress?.(new hn("unixfs:exporter:walk:hamt-sharded-directory",{cid:u.Hash})),{entries:gz(t,e,r,n,i,a)}}}),d=>Yf(d,{ordered:!0}));for await(let{entries:d}of o)yield*d}var ufe,wz,vz=F(()=>{y();Cs();Jx();Qx();tP();Xc();ufe=(t,e,r,n,i,a,s)=>{function o(d={}){return d.onProgress?.(new hn("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),gz(e,n,i,a,s,d)}return o};wz=ufe});var m0,lfe,ffe,pfe,bz,xz=F(()=>{y();Cs();m0=wn(Rs(),1);nu();N9();Y9();yz();vz();lfe=(t,e)=>t.Links.find(n=>n.Name===e)?.Hash,ffe={raw:LI,file:LI,directory:Z9,"hamt-sharded-directory":wz,metadata:(t,e,r,n,i,a,s)=>()=>[],symlink:(t,e,r,n,i,a,s)=>()=>[]},pfe=async(t,e,r,n,i,a,s,o)=>{let d=await s.get(t,o),u=Qc(d),c,l;if(e==null&&(e=t.toString()),u.Data==null)throw(0,m0.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{c=ti.unmarshal(u.Data)}catch(h){throw(0,m0.default)(h,"ERR_NOT_UNIXFS")}if(r==null&&(r=e),n.length>0){let h;if(c?.type==="hamt-sharded-directory"?h=await M9(u,n[0],s):h=lfe(u,n[0]),h==null)throw(0,m0.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let p=n.shift(),m=`${r}/${p}`;l={cid:h,toResolve:n,name:p??"",path:m}}let f=ffe[c.type](t,u,c,r,i,a,s);if(f==null)throw(0,m0.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return c.isDirectory()?{entry:{type:"directory",name:e,path:r,cid:t,content:f,unixfs:c,depth:a,node:u,size:c.fileSize()},next:l}:{entry:{type:"file",name:e,path:r,cid:t,content:f,unixfs:c,depth:a,node:u,size:c.fileSize()},next:l}},bz=pfe});var hfe,OKe,Pz=F(()=>{y();Fp();Cs();hfe=wn(Rs(),1);Ly();S9();A9();R9();O9();xz();OKe={[Oy]:bz,[iu]:$9,[Rl]:k9,[E9.code]:I9}});var mfe,_z=F(()=>{y();mfe=wn(Rs(),1);x9();Yc();Pz()});var ZKe,YKe,Sz=F(()=>{"use strict";y();Gx();rl();eu();_z();FE();ZKe=new TextEncoder,YKe=new TextDecoder});var Tz=F(()=>{"use strict";y();_a();nc()});var zI=F(()=>{"use strict";y();yi();HE();nc();Tz();rl();mt();_a()});var kz=F(()=>{y();Dy();W_()});var Az=F(()=>{"use strict";y();kz();Fp();Gx();ed();Yc();rl();zx();zI();or();Ud();nc()});var Dz=F(()=>{"use strict";y();ed();rl()});var Iz=F(()=>{y()});var Rz=F(()=>{"use strict";y();Iz();_a();mt()});var FI=F(()=>{"use strict";y();lf()});var GI=F(()=>{"use strict";y();lf()});var Cz=F(()=>{"use strict";y();lf();FI();GI();rl()});var $z=F(()=>{"use strict";y();lf()});var Oz=F(()=>{"use strict";y();Fp();Yc();eu();Fo();JP();un();Wa();Yb();Qb();hs();iv();B1();j1();Bn();Vb();ww();Jb();U1();Po();yi();L0();Ud();Qi();rn();og();Yt();oh()});var Bz=F(()=>{"use strict";y();Qi()});var Jn=F(()=>{"use strict";y();Mm();fs();ik();LS();ok();ed();Vb();Jb();eu();oh();v9();jg();mt();Yt();un();Qb();og();Po();zx();Wa();or();Yb();ck();va();sk();hs();iv();Sf();B1();j1();Bn();ww();cD();U1();L0();Q2();nc();Qi();zS();Ul();Gx();Sz();zI();rl();Az();Dz();Rz();Cz();GI();FI();$z();lf();Oz();Bz()});var pP=_e((xze,Gz)=>{y();var xm=1e3,Pm=xm*60,_m=Pm*60,ep=_m*24,Ife=ep*7,Rfe=ep*365.25;Gz.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return Cfe(t);if(r==="number"&&isFinite(t))return e.long?Ofe(t):$fe(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Cfe(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*Rfe;case"weeks":case"week":case"w":return r*Ife;case"days":case"day":case"d":return r*ep;case"hours":case"hour":case"hrs":case"hr":case"h":return r*_m;case"minutes":case"minute":case"mins":case"min":case"m":return r*Pm;case"seconds":case"second":case"secs":case"sec":case"s":return r*xm;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function $fe(t){var e=Math.abs(t);return e>=ep?Math.round(t/ep)+"d":e>=_m?Math.round(t/_m)+"h":e>=Pm?Math.round(t/Pm)+"m":e>=xm?Math.round(t/xm)+"s":t+"ms"}function Ofe(t){var e=Math.abs(t);return e>=ep?fP(t,e,ep,"day"):e>=_m?fP(t,e,_m,"hour"):e>=Pm?fP(t,e,Pm,"minute"):e>=xm?fP(t,e,xm,"second"):t+" ms"}function fP(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});y();y();function Npe(t,e){return{definition:t}}y();y();y();Jn();Jn();var Te;(function(t){t.MessagesRead="MessagesRead",t.MessagesSubscribe="MessagesSubscribe",t.MessagesSync="MessagesSync",t.ProtocolsConfigure="ProtocolsConfigure",t.ProtocolsQuery="ProtocolsQuery",t.RecordsDelete="RecordsDelete",t.RecordsQuery="RecordsQuery",t.RecordsRead="RecordsRead",t.RecordsSubscribe="RecordsSubscribe",t.RecordsWrite="RecordsWrite"})(Te||(Te={}));var HI={[Te.MessagesRead]:df,[Te.MessagesSubscribe]:uf,[Te.MessagesSync]:Rh,[Te.ProtocolsConfigure]:Tf,[Te.ProtocolsQuery]:bd,[Te.RecordsDelete]:Ou,[Te.RecordsQuery]:hd,[Te.RecordsRead]:Bu,[Te.RecordsSubscribe]:xd,[Te.RecordsWrite]:Tn};y();Fo();Kt();y();Jn();y();Fo();Jn();var qz=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})};function VI(t,e){return qz(this,void 0,void 0,function*(){let r=yield e.dereference(`${t}#dwn`);if(r.dereferencingMetadata.error)throw new Error(`Failed to dereference '${t}#dwn': ${r.dereferencingMetadata.error}`);if(lI.isDwnDidService(r.contentStream)){let{serviceEndpoint:n}=r.contentStream,i=typeof n=="string"?[n]:Array.isArray(n)&&n.every(a=>typeof a=="string")?n:[];if(i.length>0)return i}return[]})}function Wo(t){return Se.getAuthor(t)}function Lz(t){let e=ir.decodePlainObjectPayload(t.authorization.signature);return e?.protocolRole}function vm(t){return!t||typeof t!="object"||t===null?!1:"message"in t&&typeof t.message=="object"&&t.message!==null&&"descriptor"in t.message&&typeof t.message.descriptor=="object"&&t.message.descriptor!==null&&"interface"in t.message.descriptor&&t.message.descriptor.interface===Ge.Records&&"method"in t.message.descriptor&&t.message.descriptor.method===ze.Write}function kfe(t){return Se.getCid(t)}function zz(t,e){return qz(this,void 0,void 0,function*(){let r=e===Ar.CreatedAscending||e===Ar.CreatedDescending?t.descriptor.dateCreated:t.descriptor.datePublished;if(r===void 0)throw new Error("The dateCreated or datePublished property is missing from the record descriptor.");return{messageCid:yield kfe(t),value:r}})}var bm=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},lP=class{constructor({didResolver:e,rpcClient:r}){this._didResolver=e,this._rpcClient=r}recordsQuery(e,r){return bm(this,void 0,void 0,function*(){let n=yield hd.create({filter:r.filter,dateSort:r.dateSort,pagination:r.pagination,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}recordsRead(e,r){return bm(this,void 0,void 0,function*(){let n=yield Bu.create({filter:r.filter,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}recordsSubscribe(e,r,n){return bm(this,void 0,void 0,function*(){let i=yield xd.create({filter:r.filter,dateSort:r.dateSort,pagination:r.pagination,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,i.message,void 0,n)})}recordsCount(e,r){return bm(this,void 0,void 0,function*(){let n=yield cf.create({filter:r.filter,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}protocolsQuery(e,r){return bm(this,void 0,void 0,function*(){let n=yield bd.create({filter:r?.filter,messageTimestamp:r?.messageTimestamp});return yield this.sendRequest(e,n.message)})}sendRequest(e,r,n,i){return bm(this,void 0,void 0,function*(){let a=yield VI(e,this._didResolver),s=[];for(let o of a)try{if(i!==void 0){if(!(yield this._rpcClient.getServerInfo(o)).webSocketSupport){s.push({url:o,message:"WebSocket support is not enabled on the server."});continue}let c=new URL(o);c.protocol=c.protocol==="http:"?"ws:":"wss:",o=c.toString()}return yield this._rpcClient.sendDwnRequest({dwnUrl:o,targetDid:e,message:r,data:n,subscriptionHandler:i})}catch(d){s.push({url:o,message:d instanceof Error?d.message:"Unknown error"})}throw new Error(`AnonymousDwnApi: Failed to send request to '${e}': ${JSON.stringify(s)}`)})}};y();y();rn();y();Fo();rn();y();Kt();Fo();y();y();rn();y();var Bfe=wn(pP(),1);Kt();Jn();var y0;(function(t){t.Create="Create",t.Resolve="Resolve"})(y0||(y0={}));y();Kt();Jn();rn();Fo();y();y();y();Jn();function ZI(t,e){return e.descriptor.interface+e.descriptor.method===t}function YI(t){return t===Te.RecordsDelete||t===Te.RecordsQuery||t===Te.RecordsRead||t===Te.RecordsSubscribe||t===Te.RecordsWrite}y();rn();Jn();y();y();Jn();y();Jn();y();y();y();Kd();var nFe=Ym("ed25519 seed");var iFe=new Uint8Array([0]);y();var Gfe=`abandon
|
|
10
|
+
deps: ${r}}`};var sne={keyword:"dependencies",type:"object",schemaType:"object",error:bc.error,code(t){let[e,r]=ane(t);CN(t,e),$N(t,r)}};function ane({schema:t}){let e={},r={};for(let n in t){if(n==="__proto__")continue;let i=Array.isArray(t[n])?e:r;i[n]=t[n]}return[e,r]}function CN(t,e=t.schema){let{gen:r,data:n,it:i}=t;if(Object.keys(e).length===0)return;let a=r.let("missing");for(let s in e){let o=e[s];if(o.length===0)continue;let d=(0,pw.propertyInData)(r,n,s,i.opts.ownProperties);t.setParams({property:s,depsCount:o.length,deps:o.join(", ")}),i.allErrors?r.if(d,()=>{for(let u of o)(0,pw.checkReportMissingProp)(t,u)}):(r.if((0,TA._)`${d} && (${(0,pw.checkMissingProp)(t,o,a)})`),(0,pw.reportMissingProp)(t,a),r.else())}}bc.validatePropertyDeps=CN;function $N(t,e=t.schema){let{gen:r,data:n,keyword:i,it:a}=t,s=r.name("valid");for(let o in e)(0,one.alwaysValidSchema)(a,e[o])||(r.if((0,pw.propertyInData)(r,n,o,a.opts.ownProperties),()=>{let d=t.subschema({keyword:i,schemaProp:o},s);t.mergeValidEvaluated(d,s)},()=>r.var(s,!0)),t.ok(s))}bc.validateSchemaDeps=$N;bc.default=sne});var BN=_e(kA=>{"use strict";y();Object.defineProperty(kA,"__esModule",{value:!0});var ON=St(),cne=Ut(),dne={message:"property name must be valid",params:({params:t})=>(0,ON._)`{propertyName: ${t.propertyName}}`},une={keyword:"propertyNames",type:"object",schemaType:["object","boolean"],error:dne,code(t){let{gen:e,schema:r,data:n,it:i}=t;if((0,cne.alwaysValidSchema)(i,r))return;let a=e.name("valid");e.forIn("key",n,s=>{t.setParams({propertyName:s}),t.subschema({keyword:"propertyNames",data:s,dataTypes:["string"],propertyName:s,compositeRule:!0},a),e.if((0,ON.not)(a),()=>{t.error(!0),i.allErrors||e.break()})}),t.ok(a)}};kA.default=une});var DA=_e(AA=>{"use strict";y();Object.defineProperty(AA,"__esModule",{value:!0});var A1=Ks(),ja=St(),lne=Us(),D1=Ut(),fne={message:"must NOT have additional properties",params:({params:t})=>(0,ja._)`{additionalProperty: ${t.additionalProperty}}`},pne={keyword:"additionalProperties",type:["object"],schemaType:["boolean","object"],allowUndefined:!0,trackErrors:!0,error:fne,code(t){let{gen:e,schema:r,parentSchema:n,data:i,errsCount:a,it:s}=t;if(!a)throw new Error("ajv implementation error");let{allErrors:o,opts:d}=s;if(s.props=!0,d.removeAdditional!=="all"&&(0,D1.alwaysValidSchema)(s,r))return;let u=(0,A1.allSchemaProperties)(n.properties),c=(0,A1.allSchemaProperties)(n.patternProperties);l(),t.ok((0,ja._)`${a} === ${lne.default.errors}`);function l(){e.forIn("key",i,g=>{!u.length&&!c.length?p(g):e.if(f(g),()=>p(g))})}function f(g){let _;if(u.length>8){let v=(0,D1.schemaRefOrVal)(s,n.properties,"properties");_=(0,A1.isOwnProperty)(e,v,g)}else u.length?_=(0,ja.or)(...u.map(v=>(0,ja._)`${g} === ${v}`)):_=ja.nil;return c.length&&(_=(0,ja.or)(_,...c.map(v=>(0,ja._)`${(0,A1.usePattern)(t,v)}.test(${g})`))),(0,ja.not)(_)}function h(g){e.code((0,ja._)`delete ${i}[${g}]`)}function p(g){if(d.removeAdditional==="all"||d.removeAdditional&&r===!1){h(g);return}if(r===!1){t.setParams({additionalProperty:g}),t.error(),o||e.break();return}if(typeof r=="object"&&!(0,D1.alwaysValidSchema)(s,r)){let _=e.name("valid");d.removeAdditional==="failing"?(m(g,_,!1),e.if((0,ja.not)(_),()=>{t.reset(),h(g)})):(m(g,_),o||e.if((0,ja.not)(_),()=>e.break()))}}function m(g,_,v){let E={keyword:"additionalProperties",dataProp:g,dataPropType:D1.Type.Str};v===!1&&Object.assign(E,{compositeRule:!0,createErrors:!1,allErrors:!1}),t.subschema(E,_)}}};AA.default=pne});var NN=_e(RA=>{"use strict";y();Object.defineProperty(RA,"__esModule",{value:!0});var hne=Qg(),jN=Ks(),IA=Ut(),MN=DA(),mne={keyword:"properties",type:"object",schemaType:"object",code(t){let{gen:e,schema:r,parentSchema:n,data:i,it:a}=t;a.opts.removeAdditional==="all"&&n.additionalProperties===void 0&&MN.default.code(new hne.KeywordCxt(a,MN.default,"additionalProperties"));let s=(0,jN.allSchemaProperties)(r);for(let l of s)a.definedProperties.add(l);a.opts.unevaluated&&s.length&&a.props!==!0&&(a.props=IA.mergeEvaluated.props(e,(0,IA.toHash)(s),a.props));let o=s.filter(l=>!(0,IA.alwaysValidSchema)(a,r[l]));if(o.length===0)return;let d=e.name("valid");for(let l of o)u(l)?c(l):(e.if((0,jN.propertyInData)(e,i,l,a.opts.ownProperties)),c(l),a.allErrors||e.else().var(d,!0),e.endIf()),t.it.definedProperties.add(l),t.ok(d);function u(l){return a.opts.useDefaults&&!a.compositeRule&&r[l].default!==void 0}function c(l){t.subschema({keyword:"properties",schemaProp:l,dataProp:l},d)}}};RA.default=mne});var LN=_e(CA=>{"use strict";y();Object.defineProperty(CA,"__esModule",{value:!0});var UN=Ks(),I1=St(),KN=Ut(),qN=Ut(),yne={keyword:"patternProperties",type:"object",schemaType:"object",code(t){let{gen:e,schema:r,data:n,parentSchema:i,it:a}=t,{opts:s}=a,o=(0,UN.allSchemaProperties)(r),d=o.filter(m=>(0,KN.alwaysValidSchema)(a,r[m]));if(o.length===0||d.length===o.length&&(!a.opts.unevaluated||a.props===!0))return;let u=s.strictSchema&&!s.allowMatchingProperties&&i.properties,c=e.name("valid");a.props!==!0&&!(a.props instanceof I1.Name)&&(a.props=(0,qN.evaluatedPropsToName)(e,a.props));let{props:l}=a;f();function f(){for(let m of o)u&&h(m),a.allErrors?p(m):(e.var(c,!0),p(m),e.if(c))}function h(m){for(let g in u)new RegExp(m).test(g)&&(0,KN.checkStrictMode)(a,`property ${g} matches pattern ${m} (use allowMatchingProperties)`)}function p(m){e.forIn("key",n,g=>{e.if((0,I1._)`${(0,UN.usePattern)(t,m)}.test(${g})`,()=>{let _=d.includes(m);_||t.subschema({keyword:"patternProperties",schemaProp:m,dataProp:g,dataPropType:qN.Type.Str},c),a.opts.unevaluated&&l!==!0?e.assign((0,I1._)`${l}[${g}]`,!0):!_&&!a.allErrors&&e.if((0,I1.not)(c),()=>e.break())})})}}};CA.default=yne});var zN=_e($A=>{"use strict";y();Object.defineProperty($A,"__esModule",{value:!0});var gne=Ut(),wne={keyword:"not",schemaType:["object","boolean"],trackErrors:!0,code(t){let{gen:e,schema:r,it:n}=t;if((0,gne.alwaysValidSchema)(n,r)){t.fail();return}let i=e.name("valid");t.subschema({keyword:"not",compositeRule:!0,createErrors:!1,allErrors:!1},i),t.failResult(i,()=>t.reset(),()=>t.error())},error:{message:"must NOT be valid"}};$A.default=wne});var FN=_e(OA=>{"use strict";y();Object.defineProperty(OA,"__esModule",{value:!0});var vne=Ks(),bne={keyword:"anyOf",schemaType:"array",trackErrors:!0,code:vne.validateUnion,error:{message:"must match a schema in anyOf"}};OA.default=bne});var GN=_e(BA=>{"use strict";y();Object.defineProperty(BA,"__esModule",{value:!0});var R1=St(),xne=Ut(),Pne={message:"must match exactly one schema in oneOf",params:({params:t})=>(0,R1._)`{passingSchemas: ${t.passing}}`},_ne={keyword:"oneOf",schemaType:"array",trackErrors:!0,error:Pne,code(t){let{gen:e,schema:r,parentSchema:n,it:i}=t;if(!Array.isArray(r))throw new Error("ajv implementation error");if(i.opts.discriminator&&n.discriminator)return;let a=r,s=e.let("valid",!1),o=e.let("passing",null),d=e.name("_valid");t.setParams({passing:o}),e.block(u),t.result(s,()=>t.reset(),()=>t.error(!0));function u(){a.forEach((c,l)=>{let f;(0,xne.alwaysValidSchema)(i,c)?e.var(d,!0):f=t.subschema({keyword:"oneOf",schemaProp:l,compositeRule:!0},d),l>0&&e.if((0,R1._)`${d} && ${s}`).assign(s,!1).assign(o,(0,R1._)`[${o}, ${l}]`).else(),e.if(d,()=>{e.assign(s,!0),e.assign(o,l),f&&t.mergeEvaluated(f,R1.Name)})})}}};BA.default=_ne});var WN=_e(jA=>{"use strict";y();Object.defineProperty(jA,"__esModule",{value:!0});var Ene=Ut(),Sne={keyword:"allOf",schemaType:"array",code(t){let{gen:e,schema:r,it:n}=t;if(!Array.isArray(r))throw new Error("ajv implementation error");let i=e.name("valid");r.forEach((a,s)=>{if((0,Ene.alwaysValidSchema)(n,a))return;let o=t.subschema({keyword:"allOf",schemaProp:s},i);t.ok(i),t.mergeEvaluated(o)})}};jA.default=Sne});var JN=_e(MA=>{"use strict";y();Object.defineProperty(MA,"__esModule",{value:!0});var C1=St(),VN=Ut(),Tne={message:({params:t})=>(0,C1.str)`must match "${t.ifClause}" schema`,params:({params:t})=>(0,C1._)`{failingKeyword: ${t.ifClause}}`},kne={keyword:"if",schemaType:["object","boolean"],trackErrors:!0,error:Tne,code(t){let{gen:e,parentSchema:r,it:n}=t;r.then===void 0&&r.else===void 0&&(0,VN.checkStrictMode)(n,'"if" without "then" and "else" is ignored');let i=HN(n,"then"),a=HN(n,"else");if(!i&&!a)return;let s=e.let("valid",!0),o=e.name("_valid");if(d(),t.reset(),i&&a){let c=e.let("ifClause");t.setParams({ifClause:c}),e.if(o,u("then",c),u("else",c))}else i?e.if(o,u("then")):e.if((0,C1.not)(o),u("else"));t.pass(s,()=>t.error(!0));function d(){let c=t.subschema({keyword:"if",compositeRule:!0,createErrors:!1,allErrors:!1},o);t.mergeEvaluated(c)}function u(c,l){return()=>{let f=t.subschema({keyword:c},o);e.assign(s,o),t.mergeValidEvaluated(f,s),l?e.assign(l,(0,C1._)`${c}`):t.setParams({ifClause:c})}}}};function HN(t,e){let r=t.schema[e];return r!==void 0&&!(0,VN.alwaysValidSchema)(t,r)}MA.default=kne});var ZN=_e(NA=>{"use strict";y();Object.defineProperty(NA,"__esModule",{value:!0});var Ane=Ut(),Dne={keyword:["then","else"],schemaType:["object","boolean"],code({keyword:t,parentSchema:e,it:r}){e.if===void 0&&(0,Ane.checkStrictMode)(r,`"${t}" without "if" is ignored`)}};NA.default=Dne});var YN=_e(UA=>{"use strict";y();Object.defineProperty(UA,"__esModule",{value:!0});var Ine=xA(),Rne=AN(),Cne=PA(),$ne=IN(),One=RN(),Bne=k1(),jne=BN(),Mne=DA(),Nne=NN(),Une=LN(),Kne=zN(),qne=FN(),Lne=GN(),zne=WN(),Fne=JN(),Gne=ZN();function Wne(t=!1){let e=[Kne.default,qne.default,Lne.default,zne.default,Fne.default,Gne.default,jne.default,Mne.default,Bne.default,Nne.default,Une.default];return t?e.push(Rne.default,$ne.default):e.push(Ine.default,Cne.default),e.push(One.default),e}UA.default=Wne});var qA=_e(hw=>{"use strict";y();Object.defineProperty(hw,"__esModule",{value:!0});hw.dynamicAnchor=void 0;var KA=St(),Hne=Us(),QN=ew(),Vne=x1(),Jne={keyword:"$dynamicAnchor",schemaType:"string",code:t=>XN(t,t.schema)};function XN(t,e){let{gen:r,it:n}=t;n.schemaEnv.root.dynamicAnchors[e]=!0;let i=(0,KA._)`${Hne.default.dynamicAnchors}${(0,KA.getProperty)(e)}`,a=n.errSchemaPath==="#"?n.validateName:Zne(t);r.if((0,KA._)`!${i}`,()=>r.assign(i,a))}hw.dynamicAnchor=XN;function Zne(t){let{schemaEnv:e,schema:r,self:n}=t.it,{root:i,baseId:a,localRefs:s,meta:o}=e.root,{schemaId:d}=n.opts,u=new QN.SchemaEnv({schema:r,schemaId:d,root:i,baseId:a,localRefs:s,meta:o});return QN.compileSchema.call(n,u),(0,Vne.getValidate)(t,u)}hw.default=Jne});var LA=_e(mw=>{"use strict";y();Object.defineProperty(mw,"__esModule",{value:!0});mw.dynamicRef=void 0;var eU=St(),Yne=Us(),tU=x1(),Qne={keyword:"$dynamicRef",schemaType:"string",code:t=>rU(t,t.schema)};function rU(t,e){let{gen:r,keyword:n,it:i}=t;if(e[0]!=="#")throw new Error(`"${n}" only supports hash fragment reference`);let a=e.slice(1);if(i.allErrors)s();else{let d=r.let("valid",!1);s(d),t.ok(d)}function s(d){if(i.schemaEnv.root.dynamicAnchors[a]){let u=r.let("_v",(0,eU._)`${Yne.default.dynamicAnchors}${(0,eU.getProperty)(a)}`);r.if(u,o(u,d),o(i.validateName,d))}else o(i.validateName,d)()}function o(d,u){return u?()=>r.block(()=>{(0,tU.callRef)(t,d),r.let(u,!0)}):()=>(0,tU.callRef)(t,d)}}mw.dynamicRef=rU;mw.default=Qne});var nU=_e(zA=>{"use strict";y();Object.defineProperty(zA,"__esModule",{value:!0});var Xne=qA(),eie=Ut(),tie={keyword:"$recursiveAnchor",schemaType:"boolean",code(t){t.schema?(0,Xne.dynamicAnchor)(t,""):(0,eie.checkStrictMode)(t.it,"$recursiveAnchor: false is ignored")}};zA.default=tie});var iU=_e(FA=>{"use strict";y();Object.defineProperty(FA,"__esModule",{value:!0});var rie=LA(),nie={keyword:"$recursiveRef",schemaType:"string",code:t=>(0,rie.dynamicRef)(t,t.schema)};FA.default=nie});var oU=_e(GA=>{"use strict";y();Object.defineProperty(GA,"__esModule",{value:!0});var iie=qA(),oie=LA(),sie=nU(),aie=iU(),cie=[iie.default,oie.default,sie.default,aie.default];GA.default=cie});var aU=_e(WA=>{"use strict";y();Object.defineProperty(WA,"__esModule",{value:!0});var sU=k1(),die={keyword:"dependentRequired",type:"object",schemaType:"object",error:sU.error,code:t=>(0,sU.validatePropertyDeps)(t)};WA.default=die});var cU=_e(HA=>{"use strict";y();Object.defineProperty(HA,"__esModule",{value:!0});var uie=k1(),lie={keyword:"dependentSchemas",type:"object",schemaType:"object",code:t=>(0,uie.validateSchemaDeps)(t)};HA.default=lie});var dU=_e(VA=>{"use strict";y();Object.defineProperty(VA,"__esModule",{value:!0});var fie=Ut(),pie={keyword:["maxContains","minContains"],type:"array",schemaType:"number",code({keyword:t,parentSchema:e,it:r}){e.contains===void 0&&(0,fie.checkStrictMode)(r,`"${t}" without "contains" is ignored`)}};VA.default=pie});var uU=_e(JA=>{"use strict";y();Object.defineProperty(JA,"__esModule",{value:!0});var hie=aU(),mie=cU(),yie=dU(),gie=[hie.default,mie.default,yie.default];JA.default=gie});var fU=_e(ZA=>{"use strict";y();Object.defineProperty(ZA,"__esModule",{value:!0});var $u=St(),lU=Ut(),wie=Us(),vie={message:"must NOT have unevaluated properties",params:({params:t})=>(0,$u._)`{unevaluatedProperty: ${t.unevaluatedProperty}}`},bie={keyword:"unevaluatedProperties",type:"object",schemaType:["boolean","object"],trackErrors:!0,error:vie,code(t){let{gen:e,schema:r,data:n,errsCount:i,it:a}=t;if(!i)throw new Error("ajv implementation error");let{allErrors:s,props:o}=a;o instanceof $u.Name?e.if((0,$u._)`${o} !== true`,()=>e.forIn("key",n,l=>e.if(u(o,l),()=>d(l)))):o!==!0&&e.forIn("key",n,l=>o===void 0?d(l):e.if(c(o,l),()=>d(l))),a.props=!0,t.ok((0,$u._)`${i} === ${wie.default.errors}`);function d(l){if(r===!1){t.setParams({unevaluatedProperty:l}),t.error(),s||e.break();return}if(!(0,lU.alwaysValidSchema)(a,r)){let f=e.name("valid");t.subschema({keyword:"unevaluatedProperties",dataProp:l,dataPropType:lU.Type.Str},f),s||e.if((0,$u.not)(f),()=>e.break())}}function u(l,f){return(0,$u._)`!${l} || !${l}[${f}]`}function c(l,f){let h=[];for(let p in l)l[p]===!0&&h.push((0,$u._)`${f} !== ${p}`);return(0,$u.and)(...h)}}};ZA.default=bie});var hU=_e(YA=>{"use strict";y();Object.defineProperty(YA,"__esModule",{value:!0});var Pf=St(),pU=Ut(),xie={message:({params:{len:t}})=>(0,Pf.str)`must NOT have more than ${t} items`,params:({params:{len:t}})=>(0,Pf._)`{limit: ${t}}`},Pie={keyword:"unevaluatedItems",type:"array",schemaType:["boolean","object"],error:xie,code(t){let{gen:e,schema:r,data:n,it:i}=t,a=i.items||0;if(a===!0)return;let s=e.const("len",(0,Pf._)`${n}.length`);if(r===!1)t.setParams({len:a}),t.fail((0,Pf._)`${s} > ${a}`);else if(typeof r=="object"&&!(0,pU.alwaysValidSchema)(i,r)){let d=e.var("valid",(0,Pf._)`${s} <= ${a}`);e.if((0,Pf.not)(d),()=>o(d,a)),t.ok(d)}i.items=!0;function o(d,u){e.forRange("i",u,s,c=>{t.subschema({keyword:"unevaluatedItems",dataProp:c,dataPropType:pU.Type.Num},d),i.allErrors||e.if((0,Pf.not)(d),()=>e.break())})}}};YA.default=Pie});var mU=_e(QA=>{"use strict";y();Object.defineProperty(QA,"__esModule",{value:!0});var _ie=fU(),Eie=hU(),Sie=[_ie.default,Eie.default];QA.default=Sie});var yU=_e(XA=>{"use strict";y();Object.defineProperty(XA,"__esModule",{value:!0});var kn=St(),Tie={message:({schemaCode:t})=>(0,kn.str)`must match format "${t}"`,params:({schemaCode:t})=>(0,kn._)`{format: ${t}}`},kie={keyword:"format",type:["number","string"],schemaType:"string",$data:!0,error:Tie,code(t,e){let{gen:r,data:n,$data:i,schema:a,schemaCode:s,it:o}=t,{opts:d,errSchemaPath:u,schemaEnv:c,self:l}=o;if(!d.validateFormats)return;i?f():h();function f(){let p=r.scopeValue("formats",{ref:l.formats,code:d.code.formats}),m=r.const("fDef",(0,kn._)`${p}[${s}]`),g=r.let("fType"),_=r.let("format");r.if((0,kn._)`typeof ${m} == "object" && !(${m} instanceof RegExp)`,()=>r.assign(g,(0,kn._)`${m}.type || "string"`).assign(_,(0,kn._)`${m}.validate`),()=>r.assign(g,(0,kn._)`"string"`).assign(_,m)),t.fail$data((0,kn.or)(v(),E()));function v(){return d.strictSchema===!1?kn.nil:(0,kn._)`${s} && !${_}`}function E(){let T=c.$async?(0,kn._)`(${m}.async ? await ${_}(${n}) : ${_}(${n}))`:(0,kn._)`${_}(${n})`,D=(0,kn._)`(typeof ${_} == "function" ? ${T} : ${_}.test(${n}))`;return(0,kn._)`${_} && ${_} !== true && ${g} === ${e} && !${D}`}}function h(){let p=l.formats[a];if(!p){v();return}if(p===!0)return;let[m,g,_]=E(p);m===e&&t.pass(T());function v(){if(d.strictSchema===!1){l.logger.warn(D());return}throw new Error(D());function D(){return`unknown format "${a}" ignored in schema at path "${u}"`}}function E(D){let R=D instanceof RegExp?(0,kn.regexpCode)(D):d.code.formats?(0,kn._)`${d.code.formats}${(0,kn.getProperty)(a)}`:void 0,N=r.scopeValue("formats",{key:a,ref:D,code:R});return typeof D=="object"&&!(D instanceof RegExp)?[D.type||"string",D.validate,(0,kn._)`${N}.validate`]:["string",D,N]}function T(){if(typeof p=="object"&&!(p instanceof RegExp)&&p.async){if(!c.$async)throw new Error("async format in sync schema");return(0,kn._)`await ${_}(${n})`}return typeof g=="function"?(0,kn._)`${_}(${n})`:(0,kn._)`${_}.test(${n})`}}}};XA.default=kie});var gU=_e(eD=>{"use strict";y();Object.defineProperty(eD,"__esModule",{value:!0});var Aie=yU(),Die=[Aie.default];eD.default=Die});var wU=_e(zh=>{"use strict";y();Object.defineProperty(zh,"__esModule",{value:!0});zh.contentVocabulary=zh.metadataVocabulary=void 0;zh.metadataVocabulary=["title","description","default","deprecated","readOnly","writeOnly","examples"];zh.contentVocabulary=["contentMediaType","contentEncoding","contentSchema"]});var bU=_e(tD=>{"use strict";y();Object.defineProperty(tD,"__esModule",{value:!0});var Iie=fN(),Rie=EN(),Cie=YN(),$ie=oU(),Oie=uU(),Bie=mU(),jie=gU(),vU=wU(),Mie=[$ie.default,Iie.default,Rie.default,(0,Cie.default)(!0),jie.default,vU.metadataVocabulary,vU.contentVocabulary,Oie.default,Bie.default];tD.default=Mie});var PU=_e($1=>{"use strict";y();Object.defineProperty($1,"__esModule",{value:!0});$1.DiscrError=void 0;var xU;(function(t){t.Tag="tag",t.Mapping="mapping"})(xU||($1.DiscrError=xU={}))});var EU=_e(nD=>{"use strict";y();Object.defineProperty(nD,"__esModule",{value:!0});var Fh=St(),rD=PU(),_U=ew(),Nie=Xg(),Uie=Ut(),Kie={message:({params:{discrError:t,tagName:e}})=>t===rD.DiscrError.Tag?`tag "${e}" must be string`:`value of tag "${e}" must be in oneOf`,params:({params:{discrError:t,tag:e,tagName:r}})=>(0,Fh._)`{error: ${t}, tag: ${r}, tagValue: ${e}}`},qie={keyword:"discriminator",type:"object",schemaType:"object",error:Kie,code(t){let{gen:e,data:r,schema:n,parentSchema:i,it:a}=t,{oneOf:s}=i;if(!a.opts.discriminator)throw new Error("discriminator: requires discriminator option");let o=n.propertyName;if(typeof o!="string")throw new Error("discriminator: requires propertyName");if(n.mapping)throw new Error("discriminator: mapping is not supported");if(!s)throw new Error("discriminator: requires oneOf keyword");let d=e.let("valid",!1),u=e.const("tag",(0,Fh._)`${r}${(0,Fh.getProperty)(o)}`);e.if((0,Fh._)`typeof ${u} == "string"`,()=>c(),()=>t.error(!1,{discrError:rD.DiscrError.Tag,tag:u,tagName:o})),t.ok(d);function c(){let h=f();e.if(!1);for(let p in h)e.elseIf((0,Fh._)`${u} === ${p}`),e.assign(d,l(h[p]));e.else(),t.error(!1,{discrError:rD.DiscrError.Mapping,tag:u,tagName:o}),e.endIf()}function l(h){let p=e.name("valid"),m=t.subschema({keyword:"oneOf",schemaProp:h},p);return t.mergeEvaluated(m,Fh.Name),p}function f(){var h;let p={},m=_(i),g=!0;for(let T=0;T<s.length;T++){let D=s[T];if(D?.$ref&&!(0,Uie.schemaHasRulesButRef)(D,a.self.RULES)){let N=D.$ref;if(D=_U.resolveRef.call(a.self,a.schemaEnv.root,a.baseId,N),D instanceof _U.SchemaEnv&&(D=D.schema),D===void 0)throw new Nie.default(a.opts.uriResolver,a.baseId,N)}let R=(h=D?.properties)===null||h===void 0?void 0:h[o];if(typeof R!="object")throw new Error(`discriminator: oneOf subschemas (or referenced schemas) must have "properties/${o}"`);g=g&&(m||_(D)),v(R,T)}if(!g)throw new Error(`discriminator: "${o}" must be required`);return p;function _({required:T}){return Array.isArray(T)&&T.includes(o)}function v(T,D){if(T.const)E(T.const,D);else if(T.enum)for(let R of T.enum)E(R,D);else throw new Error(`discriminator: "properties/${o}" must have "const" or "enum"`)}function E(T,D){if(typeof T!="string"||T in p)throw new Error(`discriminator: "${o}" values must be unique strings`);p[T]=D}}}};nD.default=qie});var SU=_e((t8e,Lie)=>{Lie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/schema",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0,"https://json-schema.org/draft/2020-12/vocab/applicator":!0,"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0,"https://json-schema.org/draft/2020-12/vocab/validation":!0,"https://json-schema.org/draft/2020-12/vocab/meta-data":!0,"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0,"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Core and Validation specifications meta-schema",allOf:[{$ref:"meta/core"},{$ref:"meta/applicator"},{$ref:"meta/unevaluated"},{$ref:"meta/validation"},{$ref:"meta/meta-data"},{$ref:"meta/format-annotation"},{$ref:"meta/content"}],type:["object","boolean"],$comment:"This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.",properties:{definitions:{$comment:'"definitions" has been replaced by "$defs".',type:"object",additionalProperties:{$dynamicRef:"#meta"},deprecated:!0,default:{}},dependencies:{$comment:'"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',type:"object",additionalProperties:{anyOf:[{$dynamicRef:"#meta"},{$ref:"meta/validation#/$defs/stringArray"}]},deprecated:!0,default:{}},$recursiveAnchor:{$comment:'"$recursiveAnchor" has been replaced by "$dynamicAnchor".',$ref:"meta/core#/$defs/anchorString",deprecated:!0},$recursiveRef:{$comment:'"$recursiveRef" has been replaced by "$dynamicRef".',$ref:"meta/core#/$defs/uriReferenceString",deprecated:!0}}}});var TU=_e((r8e,zie)=>{zie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/applicator",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/applicator":!0},$dynamicAnchor:"meta",title:"Applicator vocabulary meta-schema",type:["object","boolean"],properties:{prefixItems:{$ref:"#/$defs/schemaArray"},items:{$dynamicRef:"#meta"},contains:{$dynamicRef:"#meta"},additionalProperties:{$dynamicRef:"#meta"},properties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},patternProperties:{type:"object",additionalProperties:{$dynamicRef:"#meta"},propertyNames:{format:"regex"},default:{}},dependentSchemas:{type:"object",additionalProperties:{$dynamicRef:"#meta"},default:{}},propertyNames:{$dynamicRef:"#meta"},if:{$dynamicRef:"#meta"},then:{$dynamicRef:"#meta"},else:{$dynamicRef:"#meta"},allOf:{$ref:"#/$defs/schemaArray"},anyOf:{$ref:"#/$defs/schemaArray"},oneOf:{$ref:"#/$defs/schemaArray"},not:{$dynamicRef:"#meta"}},$defs:{schemaArray:{type:"array",minItems:1,items:{$dynamicRef:"#meta"}}}}});var kU=_e((n8e,Fie)=>{Fie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/unevaluated",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/unevaluated":!0},$dynamicAnchor:"meta",title:"Unevaluated applicator vocabulary meta-schema",type:["object","boolean"],properties:{unevaluatedItems:{$dynamicRef:"#meta"},unevaluatedProperties:{$dynamicRef:"#meta"}}}});var AU=_e((i8e,Gie)=>{Gie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/content",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/content":!0},$dynamicAnchor:"meta",title:"Content vocabulary meta-schema",type:["object","boolean"],properties:{contentEncoding:{type:"string"},contentMediaType:{type:"string"},contentSchema:{$dynamicRef:"#meta"}}}});var DU=_e((o8e,Wie)=>{Wie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/core",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/core":!0},$dynamicAnchor:"meta",title:"Core vocabulary meta-schema",type:["object","boolean"],properties:{$id:{$ref:"#/$defs/uriReferenceString",$comment:"Non-empty fragments not allowed.",pattern:"^[^#]*#?$"},$schema:{$ref:"#/$defs/uriString"},$ref:{$ref:"#/$defs/uriReferenceString"},$anchor:{$ref:"#/$defs/anchorString"},$dynamicRef:{$ref:"#/$defs/uriReferenceString"},$dynamicAnchor:{$ref:"#/$defs/anchorString"},$vocabulary:{type:"object",propertyNames:{$ref:"#/$defs/uriString"},additionalProperties:{type:"boolean"}},$comment:{type:"string"},$defs:{type:"object",additionalProperties:{$dynamicRef:"#meta"}}},$defs:{anchorString:{type:"string",pattern:"^[A-Za-z_][-A-Za-z0-9._]*$"},uriString:{type:"string",format:"uri"},uriReferenceString:{type:"string",format:"uri-reference"}}}});var IU=_e((s8e,Hie)=>{Hie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/format-annotation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/format-annotation":!0},$dynamicAnchor:"meta",title:"Format vocabulary meta-schema for annotation results",type:["object","boolean"],properties:{format:{type:"string"}}}});var RU=_e((a8e,Vie)=>{Vie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/meta-data",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/meta-data":!0},$dynamicAnchor:"meta",title:"Meta-data vocabulary meta-schema",type:["object","boolean"],properties:{title:{type:"string"},description:{type:"string"},default:!0,deprecated:{type:"boolean",default:!1},readOnly:{type:"boolean",default:!1},writeOnly:{type:"boolean",default:!1},examples:{type:"array",items:!0}}}});var CU=_e((c8e,Jie)=>{Jie.exports={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"https://json-schema.org/draft/2020-12/meta/validation",$vocabulary:{"https://json-schema.org/draft/2020-12/vocab/validation":!0},$dynamicAnchor:"meta",title:"Validation vocabulary meta-schema",type:["object","boolean"],properties:{type:{anyOf:[{$ref:"#/$defs/simpleTypes"},{type:"array",items:{$ref:"#/$defs/simpleTypes"},minItems:1,uniqueItems:!0}]},const:!0,enum:{type:"array",items:!0},multipleOf:{type:"number",exclusiveMinimum:0},maximum:{type:"number"},exclusiveMaximum:{type:"number"},minimum:{type:"number"},exclusiveMinimum:{type:"number"},maxLength:{$ref:"#/$defs/nonNegativeInteger"},minLength:{$ref:"#/$defs/nonNegativeIntegerDefault0"},pattern:{type:"string",format:"regex"},maxItems:{$ref:"#/$defs/nonNegativeInteger"},minItems:{$ref:"#/$defs/nonNegativeIntegerDefault0"},uniqueItems:{type:"boolean",default:!1},maxContains:{$ref:"#/$defs/nonNegativeInteger"},minContains:{$ref:"#/$defs/nonNegativeInteger",default:1},maxProperties:{$ref:"#/$defs/nonNegativeInteger"},minProperties:{$ref:"#/$defs/nonNegativeIntegerDefault0"},required:{$ref:"#/$defs/stringArray"},dependentRequired:{type:"object",additionalProperties:{$ref:"#/$defs/stringArray"}}},$defs:{nonNegativeInteger:{type:"integer",minimum:0},nonNegativeIntegerDefault0:{$ref:"#/$defs/nonNegativeInteger",default:0},simpleTypes:{enum:["array","boolean","integer","null","number","object","string"]},stringArray:{type:"array",items:{type:"string"},uniqueItems:!0,default:[]}}}});var $U=_e(iD=>{"use strict";y();Object.defineProperty(iD,"__esModule",{value:!0});var Zie=SU(),Yie=TU(),Qie=kU(),Xie=AU(),eoe=DU(),toe=IU(),roe=RU(),noe=CU(),ioe=["/properties"];function ooe(t){return[Zie,Yie,Qie,Xie,eoe,e(this,toe),roe,e(this,noe)].forEach(r=>this.addMetaSchema(r,void 0,!1)),this;function e(r,n){return t?r.$dataMetaSchema(n,ioe):n}}iD.default=ooe});var OU=_e((Hr,sD)=>{"use strict";y();Object.defineProperty(Hr,"__esModule",{value:!0});Hr.MissingRefError=Hr.ValidationError=Hr.CodeGen=Hr.Name=Hr.nil=Hr.stringify=Hr.str=Hr._=Hr.KeywordCxt=Hr.Ajv2020=void 0;var soe=aN(),aoe=bU(),coe=EU(),doe=$U(),oD="https://json-schema.org/draft/2020-12/schema",Gh=class extends soe.default{constructor(e={}){super({...e,dynamicRef:!0,next:!0,unevaluated:!0})}_addVocabularies(){super._addVocabularies(),aoe.default.forEach(e=>this.addVocabulary(e)),this.opts.discriminator&&this.addKeyword(coe.default)}_addDefaultMetaSchema(){super._addDefaultMetaSchema();let{$data:e,meta:r}=this.opts;r&&(doe.default.call(this,e),this.refs["http://json-schema.org/schema"]=oD)}defaultMeta(){return this.opts.defaultMeta=super.defaultMeta()||(this.getSchema(oD)?oD:void 0)}};Hr.Ajv2020=Gh;sD.exports=Hr=Gh;sD.exports.Ajv2020=Gh;Object.defineProperty(Hr,"__esModule",{value:!0});Hr.default=Gh;var uoe=Qg();Object.defineProperty(Hr,"KeywordCxt",{enumerable:!0,get:function(){return uoe.KeywordCxt}});var Wh=St();Object.defineProperty(Hr,"_",{enumerable:!0,get:function(){return Wh._}});Object.defineProperty(Hr,"str",{enumerable:!0,get:function(){return Wh.str}});Object.defineProperty(Hr,"stringify",{enumerable:!0,get:function(){return Wh.stringify}});Object.defineProperty(Hr,"nil",{enumerable:!0,get:function(){return Wh.nil}});Object.defineProperty(Hr,"Name",{enumerable:!0,get:function(){return Wh.Name}});Object.defineProperty(Hr,"CodeGen",{enumerable:!0,get:function(){return Wh.CodeGen}});var loe=f1();Object.defineProperty(Hr,"ValidationError",{enumerable:!0,get:function(){return loe.default}});var foe=Xg();Object.defineProperty(Hr,"MissingRefError",{enumerable:!0,get:function(){return foe.default}})});var _f,O1=F(()=>{"use strict";y();db();mt();_f=class t{static async authorizeConfigure(e){let{protocolsConfigureMessage:r,expectedGrantor:n,expectedGrantee:i,permissionGrant:a,messageStore:s}=e;await Ea.performBaseValidation({incomingMessage:r,expectedGrantor:n,expectedGrantee:i,permissionGrant:a,messageStore:s}),t.verifyScope(r,a.scope)}static async authorizeQuery(e){let{expectedGrantee:r,expectedGrantor:n,incomingMessage:i,permissionGrant:a,messageStore:s}=e;await Ea.performBaseValidation({incomingMessage:i,expectedGrantor:n,expectedGrantee:r,permissionGrant:a,messageStore:s});let d=a.scope.protocol,u=i.descriptor.filter?.protocol;if(d!==void 0&&u!==d)throw new le(ue.ProtocolsGrantAuthorizationQueryProtocolScopeMismatch,`Grant protocol scope ${d} does not match protocol in message ${u}`)}static verifyScope(e,r){if(r.protocol!==void 0&&r.protocol!==e.descriptor.definition.protocol)throw new le(ue.ProtocolsGrantAuthorizationScopeProtocolMismatch,"Grant scope specifies different protocol than what appears in the configure message.")}}});function Ef(t){let e=t.indexOf(":");if(e===-1)return;let r=t.substring(0,e),n=t.substring(e+1);return{alias:r,protocolPath:n}}function yw(t){return t.includes(":")}var Sf=F(()=>{"use strict";y();rn();oh()});var BU,Tf,B1=F(()=>{"use strict";y();Da();BU=wn(OU(),1);or();va();O1();Qi();mt();Yt();Sf();Bs();Mm();Tf=class t extends gn{static async parse(e){return Se.validateJsonSchema(e),t.validateProtocolDefinition(e.descriptor.definition),await Se.validateSignatureStructure(e.authorization.signature,e.descriptor),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Protocols,method:ze.Configure,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),definition:t.normalizeDefinition(e.definition),...e.permissionGrantId!==void 0&&{permissionGrantId:e.permissionGrantId}},n=await Se.createAuthorization({descriptor:r,signer:e.signer,delegatedGrant:e.delegatedGrant,permissionGrantId:e.permissionGrantId}),i={descriptor:r,authorization:n};return Se.validateJsonSchema(i),t.validateProtocolDefinition(i.descriptor.definition),new t(i)}async authorizeAuthorDelegate(e){let r=dr.parse(this.message.authorization.authorDelegatedGrant);await _f.authorizeConfigure({protocolsConfigureMessage:this.message,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:r,messageStore:e})}static validateProtocolDefinition(e){let{protocol:r,types:n,uses:i}=e;qn(r);for(let a in n){let s=n[a].schema;s!==void 0&&ic(s)}i!==void 0&&t.validateUses(i,r),t.validateStructure(e)}static validateUses(e,r){let n=/^[a-zA-Z][a-zA-Z0-9_-]*$/;for(let i in e){if(!n.test(i))throw new le(ue.ProtocolsConfigureInvalidUsesAlias,`invalid 'uses' alias '${i}': must match pattern ${n.toString()}.`);try{qn(e[i])}catch{throw new le(ue.ProtocolsConfigureInvalidUsesProtocolUrl,`invalid 'uses' protocol URL for alias '${i}': '${e[i]}' is not a valid normalized protocol URL.`)}if(e[i]===r)throw new le(ue.ProtocolsConfigureInvalidUsesSelfReference,`'uses' alias '${i}' references the protocol's own URI '${r}'. a protocol cannot compose itself.`)}}static validateStructure(e){let{uses:r}=e,n=Object.keys(e.types),i=t.fetchAllRolePathsRecursively("",e.structure,[]);t.validateRuleSetRecursively({ruleSet:e.structure,ruleSetProtocolPath:"",recordTypes:n,roles:i,uses:r,types:e.types})}static fetchAllRolePathsRecursively(e,r,n){if(e.split("/").length>10)throw new le(ue.ProtocolsConfigureRecordNestingDepthExceeded,"Record nesting depth exceeded 10 levels.");for(let i in r){if(i.startsWith("$"))continue;let a=r[i],s;e===""?s=i:s=`${e}/${i}`,a.$role?n.push(s):t.fetchAllRolePathsRecursively(s,a,n)}return n}static validateRuleSetRecursively(e){let{ruleSet:r,ruleSetProtocolPath:n,recordTypes:i,roles:a,uses:s,types:o}=e;if(r.$ref!==void 0){if(n.includes("/"))throw new le(ue.ProtocolsConfigureInvalidRefNotAtRoot,`'$ref' at protocol path '${n}' is not allowed: '$ref' nodes are only supported at the root level of the structure.`);t.validateRefNode(r,n,s)}if(r.$size!==void 0){let{min:u=0,max:c}=r.$size;if(c!==void 0&&c<u)throw new le(ue.ProtocolsConfigureInvalidSize,`Invalid size range found: max limit ${c} less than min limit ${u} at protocol path '${n}'`)}if(r.$recordLimit!==void 0){let{max:u,strategy:c}=r.$recordLimit;if(!Number.isInteger(u)||u<1)throw new le(ue.ProtocolsConfigureInvalidRecordLimit,`Invalid $recordLimit.max value ${u} at protocol path '${n}': must be an integer >= 1.`);let l=Object.values(pp);if(!l.includes(c))throw new le(ue.ProtocolsConfigureInvalidRecordLimit,`Invalid $recordLimit.strategy '${c}' at protocol path '${n}': must be one of ${l.join(", ")}.`)}if(r.$tags){let u=new BU.default.default,{$allowUndefinedTags:c,$requiredTags:l,...f}=r.$tags;for(let h in f){let p=f[h];if(!u.validateSchema(p)){let m=u.errorsText(u.errors,{dataVar:`${n}/$tags/${h}`});throw new le(ue.ProtocolsConfigureInvalidTagSchema,`tags schema validation error: ${m}`)}}}let d=r.$actions??[];for(let u=0;u<d.length;u++){let c=d[u];if(c.role!==void 0){if(yw(c.role))t.validateCrossProtocolAlias(c.role,s,n,"role");else if(!a.includes(c.role))throw new le(ue.ProtocolsConfigureRoleDoesNotExistAtGivenPath,`Role in action ${JSON.stringify(c)} for rule set ${n} does not exist.`)}if(c.who==="anyone"&&c.of)throw new le(ue.ProtocolsConfigureInvalidActionOfNotAllowed,`'of' is not allowed at rule set protocol path (${n})`);if(c.who===cl.Recipient&&c.of===void 0&&c.can.some(f=>![qi.CoUpdate,qi.CoDelete,qi.CoPrune].includes(f)))throw new le(ue.ProtocolsConfigureInvalidRecipientOfAction,"Rules for `recipient` without `of` property must have `can` containing only `co-update`, `co-delete`, and `co-prune`.");if(c.who===cl.Author&&!c.of)throw new le(ue.ProtocolsConfigureInvalidActionMissingOf,"'of' is required when 'author' is specified as 'who'");if(c.of!==void 0&&n!==""){if(yw(c.of))t.validateCrossProtocolAlias(c.of,s,n,"of");else if(!(n===c.of||n.startsWith(c.of+"/")))throw new le(ue.ProtocolsConfigureInvalidActionOfNotAnAncestor,`'of' value '${c.of}' is not an ancestor of protocol path '${n}' in action rule ${JSON.stringify(c)}.`)}if(c.can!==void 0){if(c.can.includes(qi.Update)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionUpdateWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'update' action but missing the required 'create' action.`);if(c.can.includes(qi.Delete)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionDeleteWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'delete' action but missing the required 'create' action.`);if(c.can.includes(qi.Prune)&&!c.can.includes(qi.Create))throw new le(ue.ProtocolsConfigureInvalidActionPruneWithoutCreate,`Action rule ${JSON.stringify(c)} contains 'prune' action but missing the required 'create' action.`)}for(let l=u+1;l<d.length;l++){let f=d[l];if(c.who!==void 0){if(c.who===f.who&&c.of===f.of)throw new le(ue.ProtocolsConfigureDuplicateActorInRuleSet,`More than one action rule per actor ${c.who} of ${c.of} not allowed within a rule set: ${JSON.stringify(c)}`)}else if(c.role===f.role)throw new le(ue.ProtocolsConfigureDuplicateRoleInRuleSet,`More than one action rule per role ${c.role} not allowed within a rule set: ${JSON.stringify(c)}`)}}if(n!==""){let u=n.split("/").pop();o[u]?.encryptionRequired===!0&&d.some(f=>f.who===cl.Anyone&&f.can.includes(qi.Read))&&console.warn(`ProtocolsConfigure: type '${u}' at path '${n}' has encryptionRequired: true but allows { who: 'anyone', can: ['read'] }. Anyone can read the record but no one outside the key holders can decrypt it.`)}r.$delivery!==void 0&&(r.$actions===void 0||r.$actions.length===0)&&console.warn(`ProtocolsConfigure: protocol path '${n}' has $delivery: '${r.$delivery}' but no $actions rules. The server uses $actions to determine delivery targets \u2014 without $actions, no participants can be resolved for delivery.`),r.$immutable===!0&&d.length>0&&d.some(c=>c.can.includes(qi.Update)||c.can.includes(qi.CoUpdate))&&console.warn(`ProtocolsConfigure: protocol path '${n}' has $immutable: true but $actions include 'update' or 'co-update'. The $immutable directive takes precedence \u2014 updates will always be rejected regardless of action rules.`);for(let u in r){if(u.startsWith("$"))continue;let c=r[u];if(c.$ref===void 0&&!i.includes(u))throw new le(ue.ProtocolsConfigureInvalidRuleSetRecordType,`Rule set ${u} is not declared as an allowed type in the protocol definition.`);let l;n===""?l=u:l=`${n}/${u}`,t.validateRuleSetRecursively({ruleSet:c,ruleSetProtocolPath:l,recordTypes:i,roles:a,uses:s,types:o})}}static validateRefNode(e,r,n){let i=e.$ref,a=Ef(i);if(a===void 0)throw new le(ue.ProtocolsConfigureInvalidRefAlias,`'$ref' value '${i}' at protocol path '${r}' must be in 'alias:typePath' format.`);if(n===void 0||n[a.alias]===void 0)throw new le(ue.ProtocolsConfigureInvalidRefAlias,`'$ref' alias '${a.alias}' at protocol path '${r}' does not exist in the 'uses' map.`);let s=["$actions","$role","$size","$tags","$encryption","$recordLimit","$immutable","$delivery","$squash"];for(let o of s)if(e[o]!==void 0)throw new le(ue.ProtocolsConfigureInvalidRefNodeHasDirectives,`'$ref' node at protocol path '${r}' must not have '${o}'. $ref nodes are pure attachment points \u2014 directives belong on child rule sets.`)}static validateCrossProtocolAlias(e,r,n,i){let a=Ef(e);if(a===void 0){let s=i==="role"?ue.ProtocolsConfigureInvalidCrossProtocolRole:ue.ProtocolsConfigureInvalidCrossProtocolOf;throw new le(s,`cross-protocol '${i}' reference '${e}' at protocol path '${n}' could not be parsed as a valid 'alias:path' format.`)}if(r===void 0||r[a.alias]===void 0){let s=i==="role"?ue.ProtocolsConfigureInvalidCrossProtocolRole:ue.ProtocolsConfigureInvalidCrossProtocolOf;throw new le(s,`cross-protocol '${i}' alias '${a.alias}' in '${e}' at protocol path '${n}' does not exist in the 'uses' map.`)}}static normalizeDefinition(e){let r={};for(let i in e.types)r[i]={...e.types[i]};for(let i in r){let a=r[i].schema;a!==void 0&&(r[i].schema=Fl(a))}let n;if(e.uses!==void 0){n={};for(let i in e.uses)try{n[i]=$o(e.uses[i])}catch{n[i]=e.uses[i]}}return{...e,protocol:$o(e.protocol),types:r,...n!==void 0&&{uses:n}}}}});var jU=F(()=>{"use strict";y();fs();or();ps();hs();B1();O1();mt();Yt();Sf()});var bd,j1=F(()=>{"use strict";y();Da();or();hs();O1();yi();Qi();mt();Yt();Bs();bd=class t extends gn{static async parse(e){return e.authorization!==void 0&&await Se.validateSignatureStructure(e.authorization.signature,e.descriptor),e.descriptor.filter!==void 0&&qn(e.descriptor.filter.protocol),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Protocols,method:ze.Query,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),filter:e.filter?t.normalizeFilter(e.filter):void 0,permissionGrantId:e.permissionGrantId};_r(r);let n;e.signer!==void 0&&(n=await Se.createAuthorization({descriptor:r,signer:e.signer,permissionGrantId:e.permissionGrantId}));let i={descriptor:r,authorization:n};return Se.validateJsonSchema(i),new t(i)}static normalizeFilter(e){return{...e,protocol:$o(e.protocol)}}async authorize(e,r){if(this.author!==e)if(this.author!==void 0&&this.signaturePayload.permissionGrantId){let n=await zt.fetchGrant(e,r,this.signaturePayload.permissionGrantId);await _f.authorizeQuery({expectedGrantor:e,expectedGrantee:this.author,incomingMessage:this.message,permissionGrant:n,messageStore:r})}else throw new le(ue.ProtocolsQueryUnauthorized,"The ProtocolsQuery failed authorization")}}});var MU=F(()=>{"use strict";y();fs();mt();ps();j1();yi();Yt()});var NU=F(()=>{"use strict";y();_a();Po();mt();Yt();Sf();Mm()});var UU=F(()=>{"use strict";y();Po();mt();Yt()});var KU=F(()=>{"use strict";y();Mm();_a();Bn();mt();Yt();Sf()});var kf=F(()=>{"use strict";y();Sf();nc();mt();Yt();NU();UU();KU()});var qU=F(()=>{"use strict";y();fs();or();ps();kf();Bn();Vb();Yt()});var Ou,ww=F(()=>{"use strict";y();Da();or();va();Bn();oc();yi();Qi();Yt();Ou=class t extends gn{static async parse(e){let r;return e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r=e.recordId,n=Et.getCurrentTimestamp(),i={interface:Ge.Records,method:ze.Delete,messageTimestamp:e.messageTimestamp??n,recordId:r,prune:e.prune??!1},a=await Se.createAuthorization({descriptor:i,signer:e.signer,protocolRole:e.protocolRole,permissionGrantId:e.permissionGrantId,delegatedGrant:e.delegatedGrant}),s={descriptor:i,authorization:a};return Se.validateJsonSchema(s),new t(s)}constructIndexes(e){let n={...this.message.descriptor},{protocol:i,protocolPath:a,recipient:s,schema:o,parentId:d,dateCreated:u}=e.descriptor,c={isLatestBaseState:!0,protocol:i,protocolPath:a,recipient:s,schema:o,parentId:d,dateCreated:u,contextId:e.contextId,author:this.author,...n};return _r(c),c}async authorizeDelegate(e,r){let n=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeDelete({recordsDeleteMessage:this.message,recordsWriteToDelete:e,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:n,messageStore:r})}}});var M1,N1=F(()=>{"use strict";y();(function(t){t.RecordsDelete="RecordsDelete",t.RecordsSquash="RecordsSquash"})(M1||(M1={}))});var LU=F(()=>{"use strict";y();fs();Yt();or();ps();hs();kf();Bn();ww();oc();Po();N1()});var zU=F(()=>{"use strict";y();fs();Ul();or();ps();kf();Bn();Jb();Po();nc();Yt()});var Bu,cD=F(()=>{"use strict";y();Da();Ul();or();va();Bn();oc();yi();Qi();mt();Yt();Bu=class t extends gn{static async parse(e){if(e.descriptor.filter.published===!1&&(e.descriptor.dateSort===Ar.PublishedAscending||e.descriptor.dateSort===Ar.PublishedDescending))throw new le(ue.RecordsReadParseFilterPublishedSortInvalid,`reads must not filter for \`published:false\` and sort by ${e.descriptor.dateSort}`);let r;return e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let{filter:r,signer:n,permissionGrantId:i,protocolRole:a,dateSort:s}=e,o=Et.getCurrentTimestamp();if(e.filter.published===!1&&(s===Ar.PublishedAscending||s===Ar.PublishedDescending))throw new le(ue.RecordsReadCreateFilterPublishedSortInvalid,`reads must not filter for \`published:false\` and sort by ${s}`);let d={interface:Ge.Records,method:ze.Read,filter:qt.normalizeFilter(r),messageTimestamp:e.messageTimestamp??o,permissionGrantId:i,dateSort:s};_r(d);let u;n!==void 0&&(u=await Se.createAuthorization({descriptor:d,signer:n,permissionGrantId:i,protocolRole:a,delegatedGrant:e.delegatedGrant}));let c={descriptor:d,authorization:u};return Se.validateJsonSchema(c),new t(c)}async authorizeDelegate(e,r){let n=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeRead({recordsReadMessage:this.message,recordsWriteMessageToBeRead:e,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:n,messageStore:r})}}});var FU=F(()=>{"use strict";y();fs();eu();un();or();ps();hs();kf();Bn();oc();cD();Po();mt();Yt()});var xd,U1=F(()=>{"use strict";y();Da();or();va();Bn();oc();yi();Qi();mt();Yt();Bs();xd=class t extends gn{static async parse(e){let r;if(e.authorization!==void 0&&(r=await Se.validateSignatureStructure(e.authorization.signature,e.descriptor)),await qt.validateDelegatedGrantReferentialIntegrity(e,r),r?.protocolRole!==void 0&&e.descriptor.filter.protocolPath===void 0)throw new le(ue.RecordsSubscribeFilterMissingRequiredProperties,"Role-authorized subscriptions must include `protocolPath` in the filter");return e.descriptor.filter.protocol!==void 0&&qn(e.descriptor.filter.protocol),e.descriptor.filter.schema!==void 0&&ic(e.descriptor.filter.schema),Et.validateTimestamp(e.descriptor.messageTimestamp),new t(e)}static async create(e){let r={interface:Ge.Records,method:ze.Subscribe,messageTimestamp:e.messageTimestamp??Et.getCurrentTimestamp(),filter:qt.normalizeFilter(e.filter),dateSort:e.dateSort,pagination:e.pagination,cursor:e.cursor};_r(r);let n=e.signer,i;n&&(i=await Se.createAuthorization({descriptor:r,signer:n,protocolRole:e.protocolRole,delegatedGrant:e.delegatedGrant}));let a={descriptor:r,authorization:i};return Se.validateJsonSchema(a),new t(a)}async authorizeDelegate(e){let r=dr.parse(this.message.authorization.authorDelegatedGrant);await ii.authorizeQueryOrSubscribe({incomingMessage:this.message,expectedGrantor:this.author,expectedGrantee:this.signer,permissionGrant:r,messageStore:e})}}});var GU=F(()=>{"use strict";y();fs();Ul();or();ps();kf();Bn();U1();Po();nc();mt();Yt()});var dD=F(()=>{"use strict";y();jg();_a();or();Bn();ww();Po();Yt()});var WU=F(()=>{"use strict";y();fs();ed();eu();jg();un();_a();or();ps();hs();kf();Bn();oc();Po();N1();nc();dD();mt();Yt()});function zoe(t,e){if(t.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 i=0;i<t.length;i++){var a=t.charAt(i),s=a.charCodeAt(0);if(r[s]!==255)throw new TypeError(a+" is ambiguous");r[s]=i}var o=t.length,d=t.charAt(0),u=Math.log(o)/Math.log(256),c=Math.log(256)/Math.log(o);function l(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var m=0,g=0,_=0,v=p.length;_!==v&&p[_]===0;)_++,m++;for(var E=(v-_)*c+1>>>0,T=new Uint8Array(E);_!==v;){for(var D=p[_],R=0,N=E-1;(D!==0||R<g)&&N!==-1;N--,R++)D+=256*T[N]>>>0,T[N]=D%o>>>0,D=D/o>>>0;if(D!==0)throw new Error("Non-zero carry");g=R,_++}for(var B=E-g;B!==E&&T[B]===0;)B++;for(var G=d.repeat(m);B<E;++B)G+=t.charAt(T[B]);return G}function f(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var m=0;if(p[m]!==" "){for(var g=0,_=0;p[m]===d;)g++,m++;for(var v=(p.length-m)*u+1>>>0,E=new Uint8Array(v);p[m];){var T=r[p.charCodeAt(m)];if(T===255)return;for(var D=0,R=v-1;(T!==0||D<_)&&R!==-1;R--,D++)T+=o*E[R]>>>0,E[R]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");_=D,m++}if(p[m]!==" "){for(var N=v-_;N!==v&&E[N]===0;)N++;for(var B=new Uint8Array(g+(v-N)),G=g;N!==v;)B[G++]=E[N++];return B}}}function h(p){var m=f(p);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:f,decode:h}}function ese(t){return t.byteOffset!==0||t.byteLength!==t.buffer.byteLength}function tse(t){return typeof t!="object"||t===null?!1:typeof t[Symbol.asyncIterator]=="function"}function bD(t){let e=Object.prototype.toString.call(t).match(/\s([a-zA-Z0-9]+)/),[r,n]=e;return n}function Tq(t,e,r){e=e||[],r=r||0;for(var n=r;t>=ase;)e[r++]=t&255|ZU,t/=128;for(;t&sse;)e[r++]=t&255|ZU,t>>>=7;return e[r]=t|0,Tq.bytes=r-n+1,e}function xD(t,n){var r=0,n=n||0,i=0,a=n,s,o=t.length;do{if(a>=o)throw xD.bytes=0,new RangeError("Could not decode varint");s=t[a++],r+=i<28?(s&YU)<<i:(s&YU)*Math.pow(2,i),i+=7}while(s>=dse);return xD.bytes=a-n,r}function kq(t){Object.keys(t).forEach(e=>{t[e]===void 0?delete t[e]:typeof t[e]=="object"&&kq(t[e])})}function Dc(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Uf(t){if(!Dc(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=Cse[t[r]];return e}function Iq(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function HD(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}function tK(t){if(t>=_d._0&&t<=_d._9)return t-_d._0;if(t>=_d._A&&t<=_d._F)return t-(_d._A-10);if(t>=_d._a&&t<=_d._f)return t-(_d._a-10)}function om(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,a=0;i<r;i++,a+=2){let s=tK(t.charCodeAt(a)),o=tK(t.charCodeAt(a+1));if(s===void 0||o===void 0){let d=t[a]+t[a+1];throw new Error('hex string expected, got non-hex character "'+d+'" at index '+a)}n[i]=s*16+o}return n}function jf(t){return HD(Uf(t))}function Yu(t){if(!Dc(t))throw new Error("Uint8Array expected");return HD(Uf(Uint8Array.from(t).reverse()))}function Ic(t,e){return om(t.toString(16).padStart(e*2,"0"))}function sm(t,e){return Ic(t,e).reverse()}function $se(t){return om(Iq(t))}function In(t,e,r){let n;if(typeof e=="string")try{n=om(e)}catch(a){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${a}`)}else if(Dc(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function Kf(...t){let e=0;for(let i=0;i<t.length;i++){let a=t[i];if(!Dc(a))throw new Error("Uint8Array expected");e+=a.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let a=t[i];r.set(a,n),n+=a.length}return r}function Ose(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Bse(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function jse(t){let e;for(e=0;t>Dq;t>>=Dx,e+=1);return e}function Mse(t,e){return t>>BigInt(e)&Dx}function Rq(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=uD(t),i=uD(t),a=0,s=()=>{n.fill(1),i.fill(0),a=0},o=(...c)=>r(i,n,...c),d=(c=uD())=>{i=o(rK([0]),c),n=o(),c.length!==0&&(i=o(rK([1]),c),n=o())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let c=0,l=[];for(;c<e;){n=o();let f=n.slice();l.push(f),c+=n.length}return Kf(...l)};return(c,l)=>{s(),d(c);let f;for(;!(f=l(u()));)d();return s(),f}}function zf(t,e,r={}){let n=(i,a,s)=>{let o=Use[a];if(typeof o!="function")throw new Error(`Invalid validator "${a}", expected function`);let d=t[i];if(!(s&&d===void 0)&&!o(d,t))throw new Error(`Invalid param ${String(i)}=${d} (${typeof d}), expected ${a}`)};for(let[i,a]of Object.entries(e))n(i,a,!1);for(let[i,a]of Object.entries(r))n(i,a,!0);return t}function nK(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function Kse(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Cq(t,...e){if(!Kse(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function qse(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");nK(t.outputLen),nK(t.blockLen)}function yx(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Lse(t,e){Cq(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}function $q(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Oq(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function JD(t){if(typeof t=="string"&&(t=Oq(t)),!$q(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Bq(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!$q(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let a=t[n];r.set(a,i),i+=a.length}return r}function Mq(t){let e=n=>t().update(JD(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function ZD(t=32){if(lD&&typeof lD.getRandomValues=="function")return lD.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Fse(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),a=BigInt(4294967295),s=Number(r>>i&a),o=Number(r&a),d=n?4:0,u=n?0:4;t.setUint32(e+d,s,n),t.setUint32(e+u,o,n)}function Nr(t,e){let r=t%e;return r>=Hn?r:e+r}function Kq(t,e,r){if(r<=Hn||e<Hn)throw new Error("Expected power/modulo > 0");if(r===Xr)return Hn;let n=Xr;for(;e>Hn;)e&Xr&&(n=n*t%r),t=t*t%r,e>>=Xr;return n}function sn(t,e,r){let n=t;for(;e-- >Hn;)n*=n,n%=r;return n}function ED(t,e){if(t===Hn||e<=Hn)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Nr(t,e),n=e,i=Hn,a=Xr,s=Xr,o=Hn;for(;r!==Hn;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}if(n!==Xr)throw new Error("invert: does not exist");return Nr(i,e)}function Yse(t){let e=(t-Xr)/Rf,r,n,i;for(r=t-Xr,n=0;r%Rf===Hn;r/=Rf,n++);for(i=Rf;i<t&&Kq(i,e,t)!==t-Xr;i++);if(n===1){let s=(t+Xr)/_D;return function(o,d){let u=o.pow(d,s);if(!o.eql(o.sqr(u),d))throw new Error("Cannot find square root");return u}}let a=(r+Xr)/Rf;return function(s,o){if(s.pow(o,e)===s.neg(s.ONE))throw new Error("Cannot find square root");let d=n,u=s.pow(s.mul(s.ONE,i),r),c=s.pow(o,a),l=s.pow(o,r);for(;!s.eql(l,s.ONE);){if(s.eql(l,s.ZERO))return s.ZERO;let f=1;for(let p=s.sqr(l);f<d&&!s.eql(p,s.ONE);f++)p=s.sqr(p);let h=s.pow(u,Xr<<BigInt(d-f-1));u=s.sqr(h),c=s.mul(c,h),l=s.mul(l,u),d=f}return c}}function Qse(t){if(t%_D===Jse){let e=(t+Xr)/_D;return function(r,n){let i=r.pow(n,e);if(!r.eql(r.sqr(i),n))throw new Error("Cannot find square root");return i}}if(t%oK===iK){let e=(t-iK)/oK;return function(r,n){let i=r.mul(n,Rf),a=r.pow(i,e),s=r.mul(n,a),o=r.mul(r.mul(s,Rf),a),d=r.mul(s,r.sub(o,r.ONE));if(!r.eql(r.sqr(d),n))throw new Error("Cannot find square root");return d}}return t%Zse,Yse(t)}function tae(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=eae.reduce((n,i)=>(n[i]="function",n),e);return zf(t,r)}function rae(t,e,r){if(r<Hn)throw new Error("Expected power > 0");if(r===Hn)return t.ONE;if(r===Xr)return e;let n=t.ONE,i=e;for(;r>Hn;)r&Xr&&(n=t.mul(n,i)),i=t.sqr(i),r>>=Xr;return n}function nae(t,e){let r=new Array(e.length),n=e.reduce((a,s,o)=>t.is0(s)?a:(r[o]=a,t.mul(a,s)),t.ONE),i=t.inv(n);return e.reduceRight((a,s,o)=>t.is0(s)?a:(r[o]=t.mul(a,r[o]),t.mul(a,s)),i),r}function qq(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function YD(t,e,r=!1,n={}){if(t<=Hn)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:a}=qq(t,e);if(a>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=Qse(t),o=Object.freeze({ORDER:t,BITS:i,BYTES:a,MASK:VD(i),ZERO:Hn,ONE:Xr,create:d=>Nr(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof d}`);return Hn<=d&&d<t},is0:d=>d===Hn,isOdd:d=>(d&Xr)===Xr,neg:d=>Nr(-d,t),eql:(d,u)=>d===u,sqr:d=>Nr(d*d,t),add:(d,u)=>Nr(d+u,t),sub:(d,u)=>Nr(d-u,t),mul:(d,u)=>Nr(d*u,t),pow:(d,u)=>rae(o,d,u),div:(d,u)=>Nr(d*ED(u,t),t),sqrN:d=>d*d,addN:(d,u)=>d+u,subN:(d,u)=>d-u,mulN:(d,u)=>d*u,inv:d=>ED(d,t),sqrt:n.sqrt||(d=>s(o,d)),invertBatch:d=>nae(o,d),cmov:(d,u,c)=>c?u:d,toBytes:d=>r?sm(d,a):Ic(d,a),fromBytes:d=>{if(d.length!==a)throw new Error(`Fp.fromBytes: expected ${a}, got ${d.length}`);return r?Yu(d):jf(d)}});return Object.freeze(o)}function iae(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function Lq(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function zq(t){let e=Lq(t);return e+Math.ceil(e/2)}function oae(t,e,r=!1){let n=t.length,i=Lq(e),a=zq(e);if(n<16||n<a||n>1024)throw new Error(`expected ${a}-1024 bytes of input, got ${n}`);let s=r?jf(t):Yu(t),o=Nr(s,e-Xr)+Xr;return r?sm(o,i):Ic(o,i)}function Fq(t,e){let r=(i,a)=>{let s=a.negate();return i?s:a},n=i=>{let a=Math.ceil(e/i)+1,s=2**(i-1);return{windows:a,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,a){let s=t.ZERO,o=i;for(;a>sae;)a&pD&&(s=s.add(o)),o=o.double(),a>>=pD;return s},precomputeWindow(i,a){let{windows:s,windowSize:o}=n(a),d=[],u=i,c=u;for(let l=0;l<s;l++){c=u,d.push(c);for(let f=1;f<o;f++)c=c.add(u),d.push(c);u=c.double()}return d},wNAF(i,a,s){let{windows:o,windowSize:d}=n(i),u=t.ZERO,c=t.BASE,l=BigInt(2**i-1),f=2**i,h=BigInt(i);for(let p=0;p<o;p++){let m=p*d,g=Number(s&l);s>>=h,g>d&&(g-=f,s+=pD);let _=m,v=m+Math.abs(g)-1,E=p%2!==0,T=g<0;g===0?c=c.add(r(E,a[_])):u=u.add(r(T,a[v]))}return{p:u,f:c}},wNAFCached(i,a,s,o){let d=i._WINDOW_SIZE||1,u=a.get(i);return u||(u=this.precomputeWindow(i,d),d!==1&&a.set(i,o(u))),this.wNAF(d,u,s)}}}function QD(t){return tae(t.Fp),zf(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...qq(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function aae(t){let e=QD(t);zf(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}function uae(t){let e=aae(t),{Fp:r}=e,n=e.toBytes||((p,m,g)=>{let _=m.toAffine();return Kf(Uint8Array.from([4]),r.toBytes(_.x),r.toBytes(_.y))}),i=e.fromBytes||(p=>{let m=p.subarray(1),g=r.fromBytes(m.subarray(0,r.BYTES)),_=r.fromBytes(m.subarray(r.BYTES,2*r.BYTES));return{x:g,y:_}});function a(p){let{a:m,b:g}=e,_=r.sqr(p),v=r.mul(_,p);return r.add(r.add(v,r.mul(p,m)),g)}if(!r.eql(r.sqr(e.Gy),a(e.Gx)))throw new Error("bad generator point: equation left != right");function s(p){return typeof p=="bigint"&&Dd<p&&p<e.n}function o(p){if(!s(p))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function d(p){let{allowedPrivateKeyLengths:m,nByteLength:g,wrapPrivateKey:_,n:v}=e;if(m&&typeof p!="bigint"){if(Dc(p)&&(p=Uf(p)),typeof p!="string"||!m.includes(p.length))throw new Error("Invalid key");p=p.padStart(g*2,"0")}let E;try{E=typeof p=="bigint"?p:jf(In("private key",p,g))}catch{throw new Error(`private key must be ${g} bytes, hex or bigint, not ${typeof p}`)}return _&&(E=Nr(E,v)),o(E),E}let u=new Map;function c(p){if(!(p instanceof l))throw new Error("ProjectivePoint expected")}class l{constructor(m,g,_){if(this.px=m,this.py=g,this.pz=_,m==null||!r.isValid(m))throw new Error("x required");if(g==null||!r.isValid(g))throw new Error("y required");if(_==null||!r.isValid(_))throw new Error("z required")}static fromAffine(m){let{x:g,y:_}=m||{};if(!m||!r.isValid(g)||!r.isValid(_))throw new Error("invalid affine point");if(m instanceof l)throw new Error("projective point not allowed");let v=E=>r.eql(E,r.ZERO);return v(g)&&v(_)?l.ZERO:new l(g,_,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let g=r.invertBatch(m.map(_=>_.pz));return m.map((_,v)=>_.toAffine(g[v])).map(l.fromAffine)}static fromHex(m){let g=l.fromAffine(i(In("pointHex",m)));return g.assertValidity(),g}static fromPrivateKey(m){return l.BASE.multiply(d(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y:g}=this.toAffine();if(!r.isValid(m)||!r.isValid(g))throw new Error("bad point: x or y not FE");let _=r.sqr(g),v=a(m);if(!r.eql(_,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(r.isOdd)return!r.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){c(m);let{px:g,py:_,pz:v}=this,{px:E,py:T,pz:D}=m,R=r.eql(r.mul(g,D),r.mul(E,v)),N=r.eql(r.mul(_,D),r.mul(T,v));return R&&N}negate(){return new l(this.px,r.neg(this.py),this.pz)}double(){let{a:m,b:g}=e,_=r.mul(g,sK),{px:v,py:E,pz:T}=this,D=r.ZERO,R=r.ZERO,N=r.ZERO,B=r.mul(v,v),G=r.mul(E,E),z=r.mul(T,T),U=r.mul(v,E);return U=r.add(U,U),N=r.mul(v,T),N=r.add(N,N),D=r.mul(m,N),R=r.mul(_,z),R=r.add(D,R),D=r.sub(G,R),R=r.add(G,R),R=r.mul(D,R),D=r.mul(U,D),N=r.mul(_,N),z=r.mul(m,z),U=r.sub(B,z),U=r.mul(m,U),U=r.add(U,N),N=r.add(B,B),B=r.add(N,B),B=r.add(B,z),B=r.mul(B,U),R=r.add(R,B),z=r.mul(E,T),z=r.add(z,z),B=r.mul(z,U),D=r.sub(D,B),N=r.mul(z,G),N=r.add(N,N),N=r.add(N,N),new l(D,R,N)}add(m){c(m);let{px:g,py:_,pz:v}=this,{px:E,py:T,pz:D}=m,R=r.ZERO,N=r.ZERO,B=r.ZERO,G=e.a,z=r.mul(e.b,sK),U=r.mul(g,E),H=r.mul(_,T),ee=r.mul(v,D),I=r.add(g,_),O=r.add(E,T);I=r.mul(I,O),O=r.add(U,H),I=r.sub(I,O),O=r.add(g,v);let b=r.add(E,D);return O=r.mul(O,b),b=r.add(U,ee),O=r.sub(O,b),b=r.add(_,v),R=r.add(T,D),b=r.mul(b,R),R=r.add(H,ee),b=r.sub(b,R),B=r.mul(G,O),R=r.mul(z,ee),B=r.add(R,B),R=r.sub(H,B),B=r.add(H,B),N=r.mul(R,B),H=r.add(U,U),H=r.add(H,U),ee=r.mul(G,ee),O=r.mul(z,O),H=r.add(H,ee),ee=r.sub(U,ee),ee=r.mul(G,ee),O=r.add(O,ee),U=r.mul(H,O),N=r.add(N,U),U=r.mul(b,O),R=r.mul(I,R),R=r.sub(R,U),U=r.mul(I,H),B=r.mul(b,B),B=r.add(B,U),new l(R,N,B)}subtract(m){return this.add(m.negate())}is0(){return this.equals(l.ZERO)}wNAF(m){return h.wNAFCached(this,u,m,g=>{let _=r.invertBatch(g.map(v=>v.pz));return g.map((v,E)=>v.toAffine(_[E])).map(l.fromAffine)})}multiplyUnsafe(m){let g=l.ZERO;if(m===Dd)return g;if(o(m),m===Vs)return this;let{endo:_}=e;if(!_)return h.unsafeLadder(this,m);let{k1neg:v,k1:E,k2neg:T,k2:D}=_.splitScalar(m),R=g,N=g,B=this;for(;E>Dd||D>Dd;)E&Vs&&(R=R.add(B)),D&Vs&&(N=N.add(B)),B=B.double(),E>>=Vs,D>>=Vs;return v&&(R=R.negate()),T&&(N=N.negate()),N=new l(r.mul(N.px,_.beta),N.py,N.pz),R.add(N)}multiply(m){o(m);let g=m,_,v,{endo:E}=e;if(E){let{k1neg:T,k1:D,k2neg:R,k2:N}=E.splitScalar(g),{p:B,f:G}=this.wNAF(D),{p:z,f:U}=this.wNAF(N);B=h.constTimeNegate(T,B),z=h.constTimeNegate(R,z),z=new l(r.mul(z.px,E.beta),z.py,z.pz),_=B.add(z),v=G.add(U)}else{let{p:T,f:D}=this.wNAF(g);_=T,v=D}return l.normalizeZ([_,v])[0]}multiplyAndAddUnsafe(m,g,_){let v=l.BASE,E=(D,R)=>R===Dd||R===Vs||!D.equals(v)?D.multiplyUnsafe(R):D.multiply(R),T=E(this,g).add(E(m,_));return T.is0()?void 0:T}toAffine(m){let{px:g,py:_,pz:v}=this,E=this.is0();m==null&&(m=E?r.ONE:r.inv(v));let T=r.mul(g,m),D=r.mul(_,m),R=r.mul(v,m);if(E)return{x:r.ZERO,y:r.ZERO};if(!r.eql(R,r.ONE))throw new Error("invZ was invalid");return{x:T,y:D}}isTorsionFree(){let{h:m,isTorsionFree:g}=e;if(m===Vs)return!0;if(g)return g(l,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:g}=e;return m===Vs?this:g?g(l,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(l,this,m)}toHex(m=!0){return Uf(this.toRawBytes(m))}}l.BASE=new l(e.Gx,e.Gy,r.ONE),l.ZERO=new l(r.ZERO,r.ONE,r.ZERO);let f=e.nBitLength,h=Fq(l,e.endo?Math.ceil(f/2):f);return{CURVE:e,ProjectivePoint:l,normPrivateKeyToScalar:d,weierstrassEquation:a,isWithinCurveOrder:s}}function lae(t){let e=QD(t);return zf(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function fae(t){let e=lae(t),{Fp:r,n}=e,i=r.BYTES+1,a=2*r.BYTES+1;function s(O){return Dd<O&&O<r.ORDER}function o(O){return Nr(O,n)}function d(O){return ED(O,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:c,weierstrassEquation:l,isWithinCurveOrder:f}=uae({...e,toBytes(O,b,P){let x=b.toAffine(),S=r.toBytes(x.x),A=Kf;return P?A(Uint8Array.from([b.hasEvenY()?2:3]),S):A(Uint8Array.from([4]),S,r.toBytes(x.y))},fromBytes(O){let b=O.length,P=O[0],x=O.subarray(1);if(b===i&&(P===2||P===3)){let S=jf(x);if(!s(S))throw new Error("Point is not on curve");let A=l(S),M=r.sqrt(A),L=(M&Vs)===Vs;return(P&1)===1!==L&&(M=r.neg(M)),{x:S,y:M}}else if(b===a&&P===4){let S=r.fromBytes(x.subarray(0,r.BYTES)),A=r.fromBytes(x.subarray(r.BYTES,2*r.BYTES));return{x:S,y:A}}else throw new Error(`Point of length ${b} was invalid. Expected ${i} compressed bytes or ${a} uncompressed bytes`)}}),h=O=>Uf(Ic(O,e.nByteLength));function p(O){let b=n>>Vs;return O>b}function m(O){return p(O)?o(-O):O}let g=(O,b,P)=>jf(O.slice(b,P));class _{constructor(b,P,x){this.r=b,this.s=P,this.recovery=x,this.assertValidity()}static fromCompact(b){let P=e.nByteLength;return b=In("compactSignature",b,P*2),new _(g(b,0,P),g(b,P,2*P))}static fromDER(b){let{r:P,s:x}=Of.toSig(In("DER",b));return new _(P,x)}assertValidity(){if(!f(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!f(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(b){return new _(this.r,this.s,b)}recoverPublicKey(b){let{r:P,s:x,recovery:S}=this,A=N(In("msgHash",b));if(S==null||![0,1,2,3].includes(S))throw new Error("recovery id invalid");let M=S===2||S===3?P+e.n:P;if(M>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let L=S&1?"03":"02",W=u.fromHex(L+h(M)),V=d(M),J=o(-A*V),Q=o(x*V),q=u.BASE.multiplyAndAddUnsafe(W,J,Q);if(!q)throw new Error("point at infinify");return q.assertValidity(),q}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new _(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return om(this.toDERHex())}toDERHex(){return Of.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return om(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let v={isValidPrivateKey(O){try{return c(O),!0}catch{return!1}},normPrivateKeyToScalar:c,randomPrivateKey:()=>{let O=zq(e.n);return oae(e.randomBytes(O),e.n)},precompute(O=8,b=u.BASE){return b._setWindowSize(O),b.multiply(BigInt(3)),b}};function E(O,b=!0){return u.fromPrivateKey(O).toRawBytes(b)}function T(O){let b=Dc(O),P=typeof O=="string",x=(b||P)&&O.length;return b?x===i||x===a:P?x===2*i||x===2*a:O instanceof u}function D(O,b,P=!0){if(T(O))throw new Error("first arg must be private key");if(!T(b))throw new Error("second arg must be public key");return u.fromHex(b).multiply(c(O)).toRawBytes(P)}let R=e.bits2int||function(O){let b=jf(O),P=O.length*8-e.nBitLength;return P>0?b>>BigInt(P):b},N=e.bits2int_modN||function(O){return o(R(O))},B=VD(e.nBitLength);function G(O){if(typeof O!="bigint")throw new Error("bigint expected");if(!(Dd<=O&&O<B))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ic(O,e.nByteLength)}function z(O,b,P=U){if(["recovered","canonical"].some(ne=>ne in P))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:S}=e,{lowS:A,prehash:M,extraEntropy:L}=P;A==null&&(A=!0),O=In("msgHash",O),M&&(O=In("prehashed msgHash",x(O)));let W=N(O),V=c(b),J=[G(V),G(W)];if(L!=null){let ne=L===!0?S(r.BYTES):L;J.push(In("extraEntropy",ne))}let Q=Kf(...J),q=W;function X(ne){let re=R(ne);if(!f(re))return;let Y=d(re),ce=u.BASE.multiply(re).toAffine(),de=o(ce.x);if(de===Dd)return;let pe=o(Y*o(q+de*V));if(pe===Dd)return;let we=(ce.x===de?0:2)|Number(ce.y&Vs),ae=pe;return A&&p(pe)&&(ae=m(pe),we^=1),new _(de,ae,we)}return{seed:Q,k2sig:X}}let U={lowS:e.lowS,prehash:!1},H={lowS:e.lowS,prehash:!1};function ee(O,b,P=U){let{seed:x,k2sig:S}=z(O,b,P),A=e;return Rq(A.hash.outputLen,A.nByteLength,A.hmac)(x,S)}u.BASE._setWindowSize(8);function I(O,b,P,x=H){let S=O;if(b=In("msgHash",b),P=In("publicKey",P),"strict"in x)throw new Error("options.strict was renamed to lowS");let{lowS:A,prehash:M}=x,L,W;try{if(typeof S=="string"||Dc(S))try{L=_.fromDER(S)}catch(Y){if(!(Y instanceof Of.Err))throw Y;L=_.fromCompact(S)}else if(typeof S=="object"&&typeof S.r=="bigint"&&typeof S.s=="bigint"){let{r:Y,s:ce}=S;L=new _(Y,ce)}else throw new Error("PARSE");W=u.fromHex(P)}catch(Y){if(Y.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(A&&L.hasHighS())return!1;M&&(b=e.hash(b));let{r:V,s:J}=L,Q=N(b),q=d(J),X=o(Q*q),ne=o(V*q),re=u.BASE.multiplyAndAddUnsafe(W,X,ne)?.toAffine();return re?o(re.x)===V:!1}return{CURVE:e,getPublicKey:E,getSharedSecret:D,sign:ee,verify:I,ProjectivePoint:u,Signature:_,utils:v}}function pae(t){return{hash:t,hmac:(e,...r)=>Wq(t,e,Bq(...r)),randomBytes:ZD}}function Hq(t,e){let r=n=>fae({...t,...pae(n)});return Object.freeze({...r(e),create:r})}function mae(t){let e=Vq,r=BigInt(3),n=BigInt(6),i=BigInt(11),a=BigInt(22),s=BigInt(23),o=BigInt(44),d=BigInt(88),u=t*t*t%e,c=u*u*t%e,l=sn(c,r,e)*c%e,f=sn(l,r,e)*c%e,h=sn(f,SD,e)*u%e,p=sn(h,i,e)*h%e,m=sn(p,a,e)*p%e,g=sn(m,o,e)*m%e,_=sn(g,d,e)*g%e,v=sn(_,o,e)*m%e,E=sn(v,r,e)*c%e,T=sn(E,s,e)*p%e,D=sn(T,n,e)*u%e,R=sn(D,SD,e);if(!TD.eql(TD.sqr(R),t))throw new Error("Cannot find square root");return R}function yae(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function Jq(t,...e){if(!yae(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function dK(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function gae(t,e){Jq(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}function wae(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Zq(t){return typeof t=="string"&&(t=wae(t)),Jq(t),t}function bae(t){let e=n=>t().update(Zq(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function xae(t=32){if(J1&&typeof J1.getRandomValues=="function")return J1.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function Pae(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),a=BigInt(4294967295),s=Number(r>>i&a),o=Number(r&a),d=n?4:0,u=n?0:4;t.setUint32(e+d,s,n),t.setUint32(e+u,o,n)}function Aae(t){let e=n=>{if(n!==null&&typeof n=="object"&&!Array.isArray(n)){let i=Object.keys(n).sort(),a={};for(let s of i)a[s]=e(n[s]);return a}return n},r=e(t);return JSON.stringify(r)}function lr(t){return Iae(this,arguments,void 0,function*({jwk:e}){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);kq(n);let i=Aae(n),a=tt.string(i).toUint8Array(),s=yield Yq.digest({data:a});return tt.uint8Array(s).toBase64Url()})}function Mf(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="EC"||typeof t.d!="string"||typeof t.x!="string")}function XD(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t)||"d"in t||t.kty!=="EC"||typeof t.x!="string")}function Cd(t){return!(!t||typeof t!="object"||!("kty"in t&&"crv"in t&&"x"in t&&"d"in t)||t.kty!=="OKP"||typeof t.d!="string"||typeof t.x!="string")}function eI(t){return!(!t||typeof t!="object"||"d"in t||!("kty"in t&&"crv"in t&&"x"in t)||t.kty!=="OKP"||typeof t.x!="string")}function Rae(t){if(!t||typeof t!="object")return!1;switch(t.kty){case"EC":case"OKP":case"RSA":return"d"in t;case"oct":return"k"in t;default:return!1}}function Xq(t,e=!1){return e?{h:Number(t&q1),l:Number(t>>kD&q1)}:{h:Number(t>>kD&q1)|0,l:Number(t&q1)|0}}function Mae(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:a,l:s}=Xq(t[i],e);[r[i],n[i]]=[a,s]}return[r,n]}function Yae(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}function uce(t){let e=QD(t);return zf(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function tI(t){let e=uce(t),{Fp:r,n,prehash:i,hash:a,randomBytes:s,nByteLength:o,h:d}=e,u=L1<<BigInt(o*8)-ms,c=r.create,l=e.uvRatio||((P,x)=>{try{return{isValid:!0,value:r.sqrt(P*r.inv(x))}}catch{return{isValid:!1,value:Ma}}}),f=e.adjustScalarBytes||(P=>P),h=e.domain||((P,x,S)=>{if(x.length||S)throw new Error("Contexts/pre-hash are not supported");return P}),p=P=>typeof P=="bigint"&&Ma<P,m=(P,x)=>p(P)&&p(x)&&P<x,g=P=>P===Ma||m(P,u);function _(P,x){if(m(P,x))return P;throw new Error(`Expected valid scalar < ${x}, got ${typeof P} ${P}`)}function v(P){return P===Ma?P:_(P,n)}let E=new Map;function T(P){if(!(P instanceof D))throw new Error("ExtendedPoint expected")}class D{constructor(x,S,A,M){if(this.ex=x,this.ey=S,this.ez=A,this.et=M,!g(x))throw new Error("x required");if(!g(S))throw new Error("y required");if(!g(A))throw new Error("z required");if(!g(M))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(x){if(x instanceof D)throw new Error("extended point not allowed");let{x:S,y:A}=x||{};if(!g(S)||!g(A))throw new Error("invalid affine point");return new D(S,A,ms,c(S*A))}static normalizeZ(x){let S=r.invertBatch(x.map(A=>A.ez));return x.map((A,M)=>A.toAffine(S[M])).map(D.fromAffine)}_setWindowSize(x){this._WINDOW_SIZE=x,E.delete(this)}assertValidity(){let{a:x,d:S}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:A,ey:M,ez:L,et:W}=this,V=c(A*A),J=c(M*M),Q=c(L*L),q=c(Q*Q),X=c(V*x),ne=c(Q*c(X+J)),re=c(q+c(S*c(V*J)));if(ne!==re)throw new Error("bad point: equation left != right (1)");let Y=c(A*M),ce=c(L*W);if(Y!==ce)throw new Error("bad point: equation left != right (2)")}equals(x){T(x);let{ex:S,ey:A,ez:M}=this,{ex:L,ey:W,ez:V}=x,J=c(S*V),Q=c(L*M),q=c(A*V),X=c(W*M);return J===Q&&q===X}is0(){return this.equals(D.ZERO)}negate(){return new D(c(-this.ex),this.ey,this.ez,c(-this.et))}double(){let{a:x}=e,{ex:S,ey:A,ez:M}=this,L=c(S*S),W=c(A*A),V=c(L1*c(M*M)),J=c(x*L),Q=S+A,q=c(c(Q*Q)-L-W),X=J+W,ne=X-V,re=J-W,Y=c(q*ne),ce=c(X*re),de=c(q*re),pe=c(ne*X);return new D(Y,ce,pe,de)}add(x){T(x);let{a:S,d:A}=e,{ex:M,ey:L,ez:W,et:V}=this,{ex:J,ey:Q,ez:q,et:X}=x;if(S===BigInt(-1)){let Pt=c((L-M)*(Q+J)),Pe=c((L+M)*(Q-J)),nt=c(Pe-Pt);if(nt===Ma)return this.double();let wt=c(W*L1*X),xt=c(V*L1*q),Ot=xt+wt,k=Pe+Pt,j=xt-wt,K=c(Ot*nt),te=c(k*j),se=c(Ot*j),he=c(nt*k);return new D(K,te,he,se)}let ne=c(M*J),re=c(L*Q),Y=c(V*A*X),ce=c(W*q),de=c((M+L)*(J+Q)-ne-re),pe=ce-Y,we=ce+Y,ae=c(re-S*ne),ge=c(de*pe),Be=c(we*ae),qe=c(de*ae),We=c(pe*we);return new D(ge,Be,We,qe)}subtract(x){return this.add(x.negate())}wNAF(x){return B.wNAFCached(this,E,x,D.normalizeZ)}multiply(x){let{p:S,f:A}=this.wNAF(_(x,n));return D.normalizeZ([S,A])[0]}multiplyUnsafe(x){let S=v(x);return S===Ma?N:this.equals(N)||S===ms?this:this.equals(R)?this.wNAF(S).p:B.unsafeLadder(this,S)}isSmallOrder(){return this.multiplyUnsafe(d).is0()}isTorsionFree(){return B.unsafeLadder(this,n).is0()}toAffine(x){let{ex:S,ey:A,ez:M}=this,L=this.is0();x==null&&(x=L?cce:r.inv(M));let W=c(S*x),V=c(A*x),J=c(M*x);if(L)return{x:Ma,y:ms};if(J!==ms)throw new Error("invZ was invalid");return{x:W,y:V}}clearCofactor(){let{h:x}=e;return x===ms?this:this.multiplyUnsafe(x)}static fromHex(x,S=!1){let{d:A,a:M}=e,L=r.BYTES;x=In("pointHex",x,L);let W=x.slice(),V=x[L-1];W[L-1]=V&-129;let J=Yu(W);J===Ma||(S?_(J,u):_(J,r.ORDER));let Q=c(J*J),q=c(Q-ms),X=c(A*Q-M),{isValid:ne,value:re}=l(q,X);if(!ne)throw new Error("Point.fromHex: invalid y coordinate");let Y=(re&ms)===ms,ce=(V&128)!==0;if(!S&&re===Ma&&ce)throw new Error("Point.fromHex: x=0 and x_0=1");return ce!==Y&&(re=c(-re)),D.fromAffine({x:re,y:J})}static fromPrivateKey(x){return U(x).point}toRawBytes(){let{x,y:S}=this.toAffine(),A=sm(S,r.BYTES);return A[A.length-1]|=x&ms?128:0,A}toHex(){return Uf(this.toRawBytes())}}D.BASE=new D(e.Gx,e.Gy,ms,c(e.Gx*e.Gy)),D.ZERO=new D(Ma,ms,ms,Ma);let{BASE:R,ZERO:N}=D,B=Fq(D,o*8);function G(P){return Nr(P,n)}function z(P){return G(Yu(P))}function U(P){let x=o;P=In("private key",P,x);let S=In("hashed private key",a(P),2*x),A=f(S.slice(0,x)),M=S.slice(x,2*x),L=z(A),W=R.multiply(L),V=W.toRawBytes();return{head:A,prefix:M,scalar:L,point:W,pointBytes:V}}function H(P){return U(P).pointBytes}function ee(P=new Uint8Array,...x){let S=Kf(...x);return z(a(h(S,In("context",P),!!i)))}function I(P,x,S={}){P=In("message",P),i&&(P=i(P));let{prefix:A,scalar:M,pointBytes:L}=U(x),W=ee(S.context,A,P),V=R.multiply(W).toRawBytes(),J=ee(S.context,V,L,P),Q=G(W+J*M);v(Q);let q=Kf(V,sm(Q,r.BYTES));return In("result",q,o*2)}let O=dce;function b(P,x,S,A=O){let{context:M,zip215:L}=A,W=r.BYTES;P=In("signature",P,2*W),x=In("message",x),i&&(x=i(x));let V=Yu(P.slice(W,2*W)),J,Q,q;try{J=D.fromHex(S,L),Q=D.fromHex(P.slice(0,W),L),q=R.multiplyUnsafe(V)}catch{return!1}if(!L&&J.isSmallOrder())return!1;let X=ee(M,Q.toRawBytes(),J.toRawBytes(),x);return Q.add(J.multiplyUnsafe(X)).subtract(q).clearCofactor().equals(D.ZERO)}return R._setWindowSize(8),{CURVE:e,getPublicKey:H,sign:I,verify:b,ExtendedPoint:D,utils:{getExtendedPublicKey:U,randomPrivateKey:()=>s(r.BYTES),precompute(P=8,x=D.BASE){return x._setWindowSize(P),x.multiply(BigInt(3)),x}}}}function lce(t){return zf(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function fce(t){let e=lce(t),{P:r}=e,n=E=>Nr(E,r),i=e.montgomeryBits,a=Math.ceil(i/8),s=e.nByteLength,o=e.adjustScalarBytes||(E=>E),d=e.powPminus2||(E=>Kq(E,r-BigInt(2),r));function u(E,T,D){let R=n(E*(T-D));return T=n(T-R),D=n(D+R),[T,D]}function c(E){if(typeof E=="bigint"&&xw<=E&&E<r)return E;throw new Error("Expected valid scalar 0 < scalar < CURVE.P")}let l=(e.a-BigInt(2))/BigInt(4);function f(E,T){let D=c(E),R=c(T),N=D,B=mD,G=xw,z=D,U=mD,H=xw,ee;for(let O=BigInt(i-1);O>=xw;O--){let b=R>>O&mD;H^=b,ee=u(H,B,z),B=ee[0],z=ee[1],ee=u(H,G,U),G=ee[0],U=ee[1],H=b;let P=B+G,x=n(P*P),S=B-G,A=n(S*S),M=x-A,L=z+U,W=z-U,V=n(W*P),J=n(L*S),Q=V+J,q=V-J;z=n(Q*Q),U=n(N*n(q*q)),B=n(x*A),G=n(M*(x+n(l*M)))}ee=u(H,B,z),B=ee[0],z=ee[1],ee=u(H,G,U),G=ee[0],U=ee[1];let I=d(G);return n(B*I)}function h(E){return sm(n(E),a)}function p(E){let T=In("u coordinate",E,a);return s===32&&(T[31]&=127),Yu(T)}function m(E){let T=In("scalar",E),D=T.length;if(D!==a&&D!==s)throw new Error(`Expected ${a} or ${s} bytes, got ${D}`);return Yu(o(T))}function g(E,T){let D=p(T),R=m(E),N=f(D,R);if(N===xw)throw new Error("Invalid private or public key received");return h(N)}let _=h(e.Gu);function v(E){return g(E,_)}return{scalarMult:g,scalarMultBase:v,getSharedSecret:(E,T)=>g(E,T),getPublicKey:E=>v(E),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:_}}function tL(t){let e=Ww,r=t*t%e*t%e,n=sn(r,AD,e)*r%e,i=sn(n,pce,e)*t%e,a=sn(i,hce,e)*i%e,s=sn(a,pK,e)*a%e,o=sn(s,mce,e)*s%e,d=sn(o,yce,e)*o%e,u=sn(d,hK,e)*d%e,c=sn(u,hK,e)*d%e,l=sn(c,pK,e)*a%e;return{pow_p_5_8:sn(l,AD,e)*t%e,b2:r}}function rL(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function gce(t,e){let r=Ww,n=Nr(e*e*e,r),i=Nr(n*n*e,r),a=tL(t*i).pow_p_5_8,s=Nr(t*n*a,r),o=Nr(e*s*s,r),d=s,u=Nr(s*fK,r),c=o===t,l=o===Nr(-t,r),f=o===Nr(-t*fK,r);return c&&(s=d),(l||f)&&(s=u),Xse(s,r)&&(s=Nr(-s,r)),{isValid:c||l,value:s}}function nL(t,e,r){if(e.length>255)throw new Error("Context is too big");return Bq(Oq("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}function wce(t){let{y:e}=Df.ExtendedPoint.fromHex(t),r=BigInt(1);return Qs.toBytes(Qs.create((r+e)*Qs.inv(r-e)))}function vce(t){let e=Hw.hash(t.subarray(0,32));return Hw.adjustScalarBytes(e).subarray(0,32)}function Dce(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;return e==="string"||e==="number"||e==="bigint"||e==="symbol"?e:e==="function"?"Function":Array.isArray(t)?"Array":t instanceof Uint8Array?"Uint8Array":t.constructor===Object?"Object":Ice(t)||"Object"}function Ice(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ace.includes(e))return e}function gx(t){return Xw&&globalThis.Buffer.isBuffer(t)}function iL(t){return t instanceof Uint8Array?gx(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}function oL(t,e){if(gx(t)&&gx(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function mK(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(i>=55296&&i<=57343&&(i=65533),e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}function lm(t,e,r){if(t.length-e<r)throw new Error(`${an} not enough data for type`)}function Ff(t,e,r){lm(t,e,1);let n=t[e];if(r.strict===!0&&n<Ni[0])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Gf(t,e,r){lm(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<Ni[1])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Wf(t,e,r){lm(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<Ni[2])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);return n}function Hf(t,e,r){lm(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],a=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&a<Ni[3])throw new Error(`${an} integer encoded in more bytes than necessary (strict decode)`);if(a<=Number.MAX_SAFE_INTEGER)return Number(a);if(r.allowBigInt===!0)return a;throw new Error(`${an} integers outside of the safe integer range are not supported`)}function Kce(t,e,r,n){return new Qe(be.uint,Ff(t,e+1,n),2)}function qce(t,e,r,n){return new Qe(be.uint,Gf(t,e+1,n),3)}function Lce(t,e,r,n){return new Qe(be.uint,Wf(t,e+1,n),5)}function zce(t,e,r,n){return new Qe(be.uint,Hf(t,e+1,n),9)}function Vf(t,e){return ta(t,0,e.value)}function ta(t,e,r){if(r<Ni[0]){let n=Number(r);t.push([e|n])}else if(r<Ni[1]){let n=Number(r);t.push([e|24,n])}else if(r<Ni[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<Ni[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<Ni[4]){let i=[e|27,0,0,0,0,0,0,0],a=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=a&255,a=a>>8,i[7]=a&255,a=a>>8,i[6]=a&255,a=a>>8,i[5]=a&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${an} encountered BigInt larger than allowable range`)}}function Fce(t,e,r,n){return new Qe(be.negint,-1-Ff(t,e+1,n),2)}function Gce(t,e,r,n){return new Qe(be.negint,-1-Gf(t,e+1,n),3)}function Wce(t,e,r,n){return new Qe(be.negint,-1-Wf(t,e+1,n),5)}function Hce(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i!="bigint"){let a=-1-i;if(a>=Number.MIN_SAFE_INTEGER)return new Qe(be.negint,a,9)}if(n.allowBigInt!==!0)throw new Error(`${an} integers outside of the safe integer range are not supported`);return new Qe(be.negint,rI-BigInt(i),9)}function nI(t,e){let r=e.value,n=typeof r=="bigint"?r*rI-cL:r*-1-1;ta(t,e.type.majorEncoded,n)}function t0(t,e,r,n){lm(t,e,r+n);let i=t.slice(e+r,e+r+n);return new Qe(be.bytes,i,r+n)}function Vce(t,e,r,n){return t0(t,e,1,r)}function Jce(t,e,r,n){return t0(t,e,2,Ff(t,e+1,n))}function Zce(t,e,r,n){return t0(t,e,3,Gf(t,e+1,n))}function Yce(t,e,r,n){return t0(t,e,5,Wf(t,e+1,n))}function Qce(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer bytes lengths not supported`);return t0(t,e,9,i)}function wx(t){return t.encodedBytes===void 0&&(t.encodedBytes=be.equals(t.type,be.string)?Oce(t.value):t.value),t.encodedBytes}function Ix(t,e){let r=wx(e);ta(t,e.type.majorEncoded,r.length),t.push(r)}function Xce(t,e){return t.length<e.length?-1:t.length>e.length?1:oL(t,e)}function tde(t,e,r){if(r-e<ede){let n="";for(let i=e;i<r;i++){let a=t[i];if(a&128)return yK.decode(t.subarray(e,r));n+=String.fromCharCode(a)}return n}return yK.decode(t.subarray(e,r))}function r0(t,e,r,n,i){let a=r+n;lm(t,e,a);let s=new Qe(be.string,tde(t,e+r,e+a),a);return i.retainStringBytes===!0&&(s.byteValue=t.slice(e+r,e+a)),s}function rde(t,e,r,n){return r0(t,e,1,r,n)}function nde(t,e,r,n){return r0(t,e,2,Ff(t,e+1,n),n)}function ide(t,e,r,n){return r0(t,e,3,Gf(t,e+1,n),n)}function ode(t,e,r,n){return r0(t,e,5,Wf(t,e+1,n),n)}function sde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer string lengths not supported`);return r0(t,e,9,i,n)}function fm(t,e,r,n){return new Qe(be.array,n,r)}function cde(t,e,r,n){return fm(t,e,1,r)}function dde(t,e,r,n){return fm(t,e,2,Ff(t,e+1,n))}function ude(t,e,r,n){return fm(t,e,3,Gf(t,e+1,n))}function lde(t,e,r,n){return fm(t,e,5,Wf(t,e+1,n))}function fde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer array lengths not supported`);return fm(t,e,9,i)}function pde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return fm(t,e,1,1/0)}function iI(t,e){ta(t,be.array.majorEncoded,e.value)}function pm(t,e,r,n){return new Qe(be.map,n,r)}function hde(t,e,r,n){return pm(t,e,1,r)}function mde(t,e,r,n){return pm(t,e,2,Ff(t,e+1,n))}function yde(t,e,r,n){return pm(t,e,3,Gf(t,e+1,n))}function gde(t,e,r,n){return pm(t,e,5,Wf(t,e+1,n))}function wde(t,e,r,n){let i=Hf(t,e+1,n);if(typeof i=="bigint")throw new Error(`${an} 64-bit integer map lengths not supported`);return pm(t,e,9,i)}function vde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return pm(t,e,1,1/0)}function oI(t,e){ta(t,be.map.majorEncoded,e.value)}function bde(t,e,r,n){return new Qe(be.tag,r,1)}function xde(t,e,r,n){return new Qe(be.tag,Ff(t,e+1,n),2)}function Pde(t,e,r,n){return new Qe(be.tag,Gf(t,e+1,n),3)}function _de(t,e,r,n){return new Qe(be.tag,Wf(t,e+1,n),5)}function Ede(t,e,r,n){return new Qe(be.tag,Hf(t,e+1,n),9)}function sI(t,e){ta(t,be.tag.majorEncoded,e.value)}function Sde(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${an} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new Qe(be.null,null,1):new Qe(be.undefined,void 0,1)}function Tde(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${an} indefinite length items not allowed`);return new Qe(be.break,void 0,1)}function aI(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${an} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${an} Infinity values are not supported`)}return new Qe(be.float,t,e)}function kde(t,e,r,n){return aI(dI(t,e+1),3,n)}function Ade(t,e,r,n){return aI(uI(t,e+1),5,n)}function Dde(t,e,r,n){return aI(yL(t,e+1),9,n)}function cI(t,e,r){let n=e.value;if(n===!1)t.push([be.float.majorEncoded|dL]);else if(n===!0)t.push([be.float.majorEncoded|uL]);else if(n===null)t.push([be.float.majorEncoded|lL]);else if(n===void 0)t.push([be.float.majorEncoded|fL]);else{let i,a=!1;(!r||r.float64!==!0)&&(hL(n),i=dI(Na,1),n===i||Number.isNaN(n)?(Na[0]=249,t.push(Na.slice(0,3)),a=!0):(mL(n),i=uI(Na,1),n===i&&(Na[0]=250,t.push(Na.slice(0,5)),a=!0))),a||(Ide(n),i=yL(Na,1),Na[0]=251,t.push(Na.slice(0,9)))}}function hL(t){if(t===1/0)Ws.setUint16(0,31744,!1);else if(t===-1/0)Ws.setUint16(0,64512,!1);else if(Number.isNaN(t))Ws.setUint16(0,32256,!1);else{Ws.setFloat32(0,t);let e=Ws.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Ws.setUint16(0,31744,!1);else if(r===0)Ws.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Ws.setUint16(0,0):i<-14?Ws.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Ws.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function dI(t,e){if(t.length-e<2)throw new Error(`${an} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,a;return n===0?a=i*2**-24:n!==31?a=(i+1024)*2**(n-25):a=i===0?1/0:NaN,r&32768?-a:a}function mL(t){Ws.setFloat32(0,t,!1)}function uI(t,e){if(t.length-e<4)throw new Error(`${an} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Ide(t){Ws.setFloat64(0,t,!1)}function yL(t,e){if(t.length-e<8)throw new Error(`${an} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}function rr(t,e,r){throw new Error(`${an} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function Rx(t){return()=>{throw new Error(`${an} ${t}`)}}function Rde(t){switch(t.type){case be.false:return kd([244]);case be.true:return kd([245]);case be.null:return kd([246]);case be.bytes:return t.value.length?void 0:kd([64]);case be.string:return t.value===""?kd([96]):void 0;case be.array:return t.value===0?kd([128]):void 0;case be.map:return t.value===0?kd([160]):void 0;case be.uint:return t.value<24?kd([Number(t.value)]):void 0;case be.negint:if(t.value>=-24)return kd([31-Number(t.value)])}}function $de(){let t=[];return t[be.uint.major]=Vf,t[be.negint.major]=nI,t[be.bytes.major]=Ix,t[be.string.major]=ade,t[be.array.major]=iI,t[be.map.major]=oI,t[be.tag.major]=sI,t[be.float.major]=cI,t}function Z1(t,e={},r){let n=Dce(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||Xu[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let a=Xu[n];if(!a)throw new Error(`${aL} unsupported type: ${n}`);return a(t,n,e,r)}function jde(t,e){e.mapSorter&&t.sort(e.mapSorter)}function Mde(t,e){if(t[0]instanceof Qe&&e[0]instanceof Qe){let r=t[0],n=e[0];return r._keyBytes||(r._keyBytes=wK(r.value)),n._keyBytes||(n._keyBytes=wK(n.value)),oL(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function wK(t){return Nde(t,Ode,Cde)}function wL(t,e,r,n){if(Array.isArray(e))for(let i of e)wL(t,i,r,n);else r[e.type.major](t,e,n)}function Nde(t,e,r,n){let i=n instanceof Uint8Array,a=i?new Uce(n):Bde,s=Z1(t,r);if(!Array.isArray(s)&&r.quickEncodeToken){let o=r.quickEncodeToken(s);if(o)return i?(a.push(o),a.toBytes()):o;let d=e[s.type.major];if(d.encodedSize){let u=d.encodedSize(s,r);if(i||(a=new sL(u)),d(a,s,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return i?a.toBytes():iL(a.chunks[0])}}return a.reset(),wL(a,s,e,r),a.toBytes(!0)}function To(t){if(typeof t=="string"&&t.length!==0)return t.split("#").pop()}function Ude({didDocument:t,id:e,type:r}){return t?.service?.filter(n=>!(e&&n.id!==e||r&&n.type!==r))??[]}async function Kde({didDocument:t,publicKeyJwk:e,publicKeyMultibase:r}){let n=Cx({didDocument:t});for(let i of n)if(e&&i.publicKeyJwk){if(await lr({jwk:e})===await lr({jwk:i.publicKeyJwk}))return i}else if(r&&i.publicKeyMultibase&&r===i.publicKeyMultibase)return i;return null}function Cx({didDocument:t}){if(!t)throw new TypeError("Required parameter missing: 'didDocument'");let e=[];return e.push(...t.verificationMethod?.filter(vx)??[]),Object.keys(kx).forEach(r=>{e.push(...t[r]?.filter(vx)??[])}),e}function vL({didDocument:t}){let e=Cx({didDocument:t}).map(r=>r.type);return[...new Set(e)]}function bL({didDocument:t,methodId:e}){let r=[];return Object.keys(kx).forEach(n=>{if(Array.isArray(t[n])){let i=t[n],a=To(e);i.some(s=>{let o=To(s)===a,d=vx(s)&&To(s.id)===a;return o||d})&&r.push(n)}}),r}function xL(t){return!t||typeof t!="object"||t===null?!1:"id"in t&&"type"in t&&"serviceEndpoint"in t}function qde(t){return!(!xL(t)||t.type!=="DecentralizedWebNode")}function vx(t){return!(!t||typeof t!="object"||t===null||!("id"in t&&"type"in t&&"controller"in t)||typeof t.id!="string"||typeof t.type!="string"||typeof t.controller!="string")}function $x(t){return!(!t||typeof t!="object"||t===null)&&"uri"in t&&"document"in t&&"metadata"in t&&(!("keyManager"in t)||t.keyManager===void 0)}function PL({keyBytes:t,multicodecCode:e,multicodecName:r}){let n=Xs.addPrefix({code:e,data:t,name:r}),i=tt.uint8Array(n).toBase58Btc();return tt.base58Btc(i).toMultibase()}function _L({multibaseKeyId:t}){try{let e=tt.multibase(t).toBase58Btc(),r=tt.base58Btc(e).toUint8Array(),{code:n,data:i,name:a}=Xs.removePrefix({prefixedData:r});return{keyBytes:i,multicodecCode:n,multicodecName:a}}catch{throw new Xe("invalidDid",`Invalid multibase identifier: ${t}`)}}function i0(t){let e=t<0?1:0;return t=Math.abs(Number(t||1)),Math.floor(Math.log10(t))+1+e}function DL(t){return ArrayBuffer.isView(t)?"arraybufferview":Array.isArray(t)?"array":t instanceof Number?"number":t instanceof Boolean?"boolean":t instanceof Set?"set":t instanceof Map?"map":t instanceof String?"string":t instanceof ArrayBuffer?"arraybuffer":typeof t}function sr(t,e,r){let n=[],i=null;return sr._encode(n,t),i=zde(n),sr.bytes=i.length,ArrayBuffer.isView(e)?(e.set(i,r),e):i}function CL(t,e,r){let n=0,i=1;for(let a=e;a<r;a++){let s=t[a];if(s<58&&s>=48){n=n*10+(s-48);continue}if(!(a===e&&s===43)){if(a===e&&s===45){i=-1;continue}if(s===46)break;throw new Error("not a number: buffer["+a+"] = "+s)}}return n*i}function pt(t,e,r,n){return t==null||t.length===0?null:(typeof e!="number"&&n==null&&(n=e,e=void 0),typeof r!="number"&&n==null&&(n=r,r=void 0),pt.position=0,pt.encoding=n||null,pt.data=ArrayBuffer.isView(t)?new Uint8Array(t.slice(e,r)):$d(t),pt.bytes=pt.data.length,pt.next())}function Xde(t){let e=2;for(let r of t)e+=Bx(r);return e}function eue(t){let e=2;for(let[r,n]of t){let i=$d(r).byteLength;e+=i0(i)+1+i,e+=Bx(n)}return e}function tue(t){let e=2,r=Object.keys(t);for(let n=0;n<r.length;n++){let i=$d(r[n]).byteLength;e+=i0(i)+1+i,e+=Bx(t[r[n]])}return e}function rue(t){let e=$d(t).byteLength;return i0(e)+1+e}function nue(t){let e=t.byteLength-t.byteOffset;return i0(e)+1+e}function Bx(t){if(t==null)return 0;let e=DL(t);switch(e){case"arraybufferview":return nue(t);case"string":return rue(t);case"array":case"set":return Xde(t);case"number":return 1+i0(Math.floor(t))+1;case"bigint":return 1+t.toString().length+1;case"object":return tue(t);case"map":return eue(t);default:throw new TypeError(`Unsupported value of type "${e}"`)}}function BL(t){if(Ac.isFormat(t))return Ac.size;if(Qu.isFormat(t))return Qu.size;throw Error(`Invalid ip address: ${t}`)}function aue(t){return BL(t)===Ac.size?1:2}function cue(t,e,r){r=~~r;let n=BL(t);return typeof e=="function"&&(e=e(r+n)),n===Ac.size?Ac.encode(t,e,r):Qu.encode(t,e,r)}function due(t,e,r){if(e=~~e,r=r||t.length-e,r===Ac.size)return Ac.decode(t,e,r);if(r===Qu.size)return Qu.decode(t,e,r);throw Error(`Invalid buffer size needs to be ${Ac.size} for v4 or ${Qu.size} for v6.`)}function jx(t){switch(t){case 1:return"A";case 10:return"NULL";case 28:return"AAAA";case 18:return"AFSDB";case 42:return"APL";case 257:return"CAA";case 60:return"CDNSKEY";case 59:return"CDS";case 37:return"CERT";case 5:return"CNAME";case 49:return"DHCID";case 32769:return"DLV";case 39:return"DNAME";case 48:return"DNSKEY";case 43:return"DS";case 55:return"HIP";case 13:return"HINFO";case 45:return"IPSECKEY";case 25:return"KEY";case 36:return"KX";case 29:return"LOC";case 15:return"MX";case 35:return"NAPTR";case 2:return"NS";case 47:return"NSEC";case 50:return"NSEC3";case 51:return"NSEC3PARAM";case 12:return"PTR";case 46:return"RRSIG";case 17:return"RP";case 24:return"SIG";case 6:return"SOA";case 99:return"SPF";case 33:return"SRV";case 44:return"SSHFP";case 32768:return"TA";case 249:return"TKEY";case 52:return"TLSA";case 250:return"TSIG";case 16:return"TXT";case 252:return"AXFR";case 251:return"IXFR";case 41:return"OPT";case 255:return"ANY"}return"UNKNOWN_"+t}function Vw(t){switch(t.toUpperCase()){case"A":return 1;case"NULL":return 10;case"AAAA":return 28;case"AFSDB":return 18;case"APL":return 42;case"CAA":return 257;case"CDNSKEY":return 60;case"CDS":return 59;case"CERT":return 37;case"CNAME":return 5;case"DHCID":return 49;case"DLV":return 32769;case"DNAME":return 39;case"DNSKEY":return 48;case"DS":return 43;case"HIP":return 55;case"HINFO":return 13;case"IPSECKEY":return 45;case"KEY":return 25;case"KX":return 36;case"LOC":return 29;case"MX":return 15;case"NAPTR":return 35;case"NS":return 2;case"NSEC":return 47;case"NSEC3":return 50;case"NSEC3PARAM":return 51;case"PTR":return 12;case"RRSIG":return 46;case"RP":return 17;case"SIG":return 24;case"SOA":return 6;case"SPF":return 99;case"SRV":return 33;case"SSHFP":return 44;case"TA":return 32768;case"TKEY":return 249;case"TLSA":return 52;case"TSIG":return 250;case"TXT":return 16;case"AXFR":return 252;case"IXFR":return 251;case"OPT":return 41;case"ANY":return 255;case"*":return 255}return t.toUpperCase().startsWith("UNKNOWN_")?parseInt(t.slice(8)):0}function uue(t){switch(t){case 0:return"NOERROR";case 1:return"FORMERR";case 2:return"SERVFAIL";case 3:return"NXDOMAIN";case 4:return"NOTIMP";case 5:return"REFUSED";case 6:return"YXDOMAIN";case 7:return"YXRRSET";case 8:return"NXRRSET";case 9:return"NOTAUTH";case 10:return"NOTZONE";case 11:return"RCODE_11";case 12:return"RCODE_12";case 13:return"RCODE_13";case 14:return"RCODE_14";case 15:return"RCODE_15"}return"RCODE_"+t}function lue(t){switch(t){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+t}function jL(t){switch(t){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+t}function ML(t){switch(t.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}function fue(t){switch(t){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return t<0?null:`OPTION_${t}`}function RK(t){if(typeof t=="number")return t;if(!t)return-1;switch(t.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}let e=t.match(/_(\d+)$/);return e?parseInt(e[1],10):-1}function NL(t){let e=0,r=t.length;for(let n=0;n<r;n+=1){let i=t.charCodeAt(n);if(i<=127)e+=1;else if(i<=2047)e+=2;else if((i&63488)!==55296)e+=3;else{let a=n+1;a===r||i>=56320||(t.charCodeAt(a)&64512)!==56320?e+=3:(n=a,e+=4)}}return e}function Jw(t,e,r){let n=t.length;r==null&&(r=0),e===void 0&&(e=new Uint8Array(NL(t)+r));let i=r;for(let a=0;a<n;a+=1){let s=t.charCodeAt(a);if(s<=127)e[i++]=s;else if(s<=2047)e[i++]=192|(s&1984)>>6,e[i++]=128|s&63;else if((s&63488)!==55296)e[i++]=224|(s&61440)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63;else{let o=a+1;if(o===n||s>=56320)e[i++]=239,e[i++]=191,e[i++]=189;else{let d=t.charCodeAt(o);(d&64512)!==56320?(e[i++]=239,e[i++]=191,e[i++]=189):(a=o,s=65536|(s&1023)<<10|d&1023,e[i++]=240|(s&1835008)>>18,e[i++]=128|(s&258048)>>12,e[i++]=128|(s&4032)>>6,e[i++]=128|s&63)}}}return Jw.bytes=i-r,e}function o0(t,e,r){let n="";e==null&&(e=0),r==null&&(r=t.length);for(let i=e;i<r;){let a=t[i++],s;if(a<=128)s=a;else if(a>191&&a<224)s=(a&31)<<6|t[i++]&63;else if(a>239&&a<365){s=((a&7)<<18|(t[i++]&63)<<12|(t[i++]&63)<<6|t[i++]&63)-65536;let o=55296|s>>10&1023;n+=String.fromCharCode(o),s=56320|s&1023}else s=(a&15)<<12|(t[i++]&63)<<6|t[i++]&63;n+=String.fromCharCode(s)}return o0.bytes=r-e,n}function el(t){return typeof t=="string"?NL(t):t.byteLength}function hI(t){return t instanceof Uint8Array?t:Array.isArray(t)?new Uint8Array(t):Jw(t)}function mI(t,e,r){if(typeof e!="string")throw new Error("unknown input type");return Jw(e,t,r),Jw.bytes}function pue(t,e,r){let n="";for(let i=e;i<r;){let a=t[i++];n+=UL[a]}return n}function CK(t){return t.length>>>1}function hue(t,e,r,n){let i=0;for(;r<n;){let a=e.substr(i,2),s=Dw[a];if(s===void 0)return;t[r++]=s,i+=2}return t}function bs(t,e,r,n,i){return r<0&&(n-=r,r=0),n<0&&(n=0),i<0?new Uint8Array(0):r>=e.length||n>=i?0:wue(t,e,r,n,i)}function wue(t,e,r,n,i){i-n>e.length-r&&(i=n+e.length-r);let a=i-n,s=t.length-n;return a>s&&(a=s),(n!==0||i<t.length)&&(t=new Uint8Array(t.buffer,t.byteOffset+n,a)),e.set(t,r),a}function Cr({bytes:t=0,encode:e,decode:r,encodingLength:n}){return e.bytes=t,r.bytes=t,{encode:e,decode:r,encodingLength:n||(()=>t)}}function RD(t){if(t===1)return 20;if(t===2)return 32;throw new Error(`Invalid hashType=${t}, supported=1,2`)}function gD(t){switch(t.toUpperCase()){case"A":return qL;case"PTR":return rm;case"CNAME":return rm;case"DNAME":return rm;case"TXT":return ex;case"NULL":return tx;case"AAAA":return ox;case"SRV":return nx;case"HINFO":return rx;case"CAA":return Ju;case"NS":return Q1;case"SOA":return X1;case"MX":return ix;case"OPT":return Zu;case"DNSKEY":return kc;case"RRSIG":return Iw;case"RP":return Rw;case"NSEC":return Cw;case"NSEC3":return $w;case"SSHFP":return Xh;case"DS":return Ow}return Y1}function bx(t,e){if(t.questions)throw new Error("Only one .question object expected instead of a .questions array!");let r=Object.assign({type:e},t);return r.question&&(r.questions=[r.question],delete r.question),r}function LL(t){let e=_x(t),r=new Uint8Array(2+e.byteLength);return rt(r,e.byteLength),bs(e,r,2,0,e.length),LL.bytes=r.byteLength,r}function zL(t){let e=Rt(t,0);if(t.byteLength<e+2)return null;let r=CD(t.slice(2));return zL.bytes=CD.bytes,r}function em(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function Bw(t,e,r,n){for(let i=0;i<t.length;i++)e.encode(t[i],r,n),n+=e.encode.bytes;return n}function z1(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e.decode(r,n),n+=e.decode.bytes;return n}function FL(t,e){let r=tt.uint8Array(t).toBase32Z();return new URL(r,e).href}async function Eue({gatewayUri:t,publicKeyBytes:e}){let r=tt.uint8Array(e).toBase32Z(),n=FL(e,t),i;try{if(i=await fetch(n,{method:"GET",signal:AbortSignal.timeout(3e4)}),!i.ok)throw new Xe("notFound",`Pkarr record not found for: ${r}`)}catch(s){throw s instanceof Xe?s:new Xe("internalError",`Failed to fetch Pkarr record: ${s.message}`)}let a=await i.arrayBuffer();if(!a)throw new Xe("notFound",`Pkarr record not found for: ${r}`);if(a.byteLength<72)throw new Xe("invalidDidDocumentLength",`Pkarr response must be at least 72 bytes but got: ${a.byteLength}`);if(a.byteLength>1072)throw new Xe("invalidDidDocumentLength",`Pkarr response exceeds 1000 byte limit: ${a.byteLength}`);return{k:e,seq:Number(new DataView(a).getBigUint64(64)),sig:new Uint8Array(a,0,64),v:new Uint8Array(a,72)}}async function Sue({gatewayUri:t,bep44Message:e}){let r=tt.uint8Array(e.k).toBase32Z(),n=FL(e.k,t),i=new Uint8Array(e.v.length+72);i.set(e.sig,0),new DataView(i.buffer).setBigUint64(e.sig.length,BigInt(e.seq)),i.set(e.v,e.sig.length+8);let a;try{a=await fetch(n,{method:"PUT",headers:{"Content-Type":"application/octet-stream"},body:i,signal:AbortSignal.timeout(3e4)})}catch(s){throw new Xe("internalError",`Failed to put Pkarr record for identifier ${r}: ${s.message}`)}return a.ok}async function Tue({dnsPacket:t,publicKeyBytes:e,signer:r}){let n=Math.ceil(Date.now()/1e3),i=_x(t),a=OL.encode({seq:n,v:i}).subarray(1,-1);if(a.length>1e3)throw new Xe("invalidDidDocumentLength",`DNS packet exceeds the 1000 byte maximum size: ${a.length} bytes`);let s=await r.sign({data:new Uint8Array(a)});return{k:e,seq:n,sig:s,v:i}}async function kue({bep44Message:t}){let e=await Mi.bytesToPublicKey({publicKeyBytes:t.k}),r=OL.encode({seq:t.seq,v:t.v}).subarray(1,-1);if(!await Mi.verify({key:e,signature:t.sig,data:new Uint8Array(r)}))throw new Xe("invalidSignature","Invalid signature for DHT BEP44 message");return CD(t.v)}async function WL({didUri:t}){let e=yI({didUri:t});return await Mi.bytesToPublicKey({publicKeyBytes:e})}function yI({didUri:t}){let e=Vn.parse(t);if(!e)throw new Xe("invalidDid",`Invalid DID URI: ${t}`);if(e.method!==GL)throw new Xe("methodNotSupported",`Method not supported: ${e.method}`);let r;try{r=tt.base32Z(e.id).toUint8Array()}catch{throw new Xe("invalidPublicKey","Failed to decode method-specific identifier")}if(r.length!==32)throw new Xe("invalidPublicKeyLength",`Invalid public key length: ${r.length}`);return r}async function Aue({identityKey:t}){let e=await Mi.publicKeyToBytes({publicKey:t}),r=tt.uint8Array(e).toBase32Z();return`did:${GL}:${r}`}function gI(t){let e={Ed25519:Mi,"P-256":{publicKeyToBytes:async({publicKey:r})=>{let n=await no.publicKeyToBytes({publicKey:r});return await no.compressPublicKey({publicKeyBytes:n})},bytesToPublicKey:no.bytesToPublicKey,privateKeyToBytes:no.privateKeyToBytes,bytesToPrivateKey:no.bytesToPrivateKey},secp256k1:{publicKeyToBytes:async({publicKey:r})=>{let n=await ji.publicKeyToBytes({publicKey:r});return await ji.compressPublicKey({publicKeyBytes:n})},bytesToPublicKey:ji.bytesToPublicKey,privateKeyToBytes:ji.privateKeyToBytes,bytesToPrivateKey:ji.bytesToPrivateKey},X25519:Vh}[t];if(!e)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${t}`);return e}async function HL({newDid:t,previousDidProof:e}){let r=await WL({didUri:e.previousDid}),n=yI({didUri:t}),i=tt.base64Url(e.signature).toUint8Array();if(!await Mi.verify({key:r,data:n,signature:i}))throw new Xe("invalidPreviousDidProof","The previous DID proof is invalid.")}function Zw(t){if(typeof t=="string")return t;if(t instanceof Uint8Array)return tt.uint8Array(t).toString();if(Array.isArray(t))return t.map(e=>Zw(e)).join("");throw new Xe("internalError","Pkarr returned DNS TXT record with invalid data type")}function jw(t){return Zw(t).split(sx).reduce((e,r)=>{let[n,i]=r.split("=");return e[n]=i,e},{})}function ZL(t){if(t.length<=255)return t;let e=[];for(let r=0;r<t.length;r+=255)e.push(t.slice(r,r+255));return e}async function Iue({didUri:t,dnsPacket:e}){let r={id:t},n={published:!0},i=new Map;for(let a of e?.answers??[]){if(a.type!=="TXT")continue;let s=a.name.split(".")[0].substring(1);switch(!0){case s.startsWith("aka"):{let o=Zw(a.data);r.alsoKnownAs=o.split(So);break}case s.startsWith("cnt"):{let o=Zw(a.data);r.controller=o.includes(So)?o.split(So):o;break}case s.startsWith("k"):{let{id:o,t:d,k:u,c,a:l}=jw(a.data),f=tt.base64Url(u).toUint8Array(),h=fI[Number(d)],p=await gI(h).bytesToPublicKey({publicKeyBytes:f});p.alg=l||JL[Number(d)];let m=s==="k0"?"0":o!==void 0?o:await lr({jwk:p});r.verificationMethod??=[];let g=`${t}#${m}`;r.verificationMethod.push({id:g,type:"JsonWebKey",controller:c??t,publicKeyJwk:p}),i.set(s,g);break}case s.startsWith("s"):{let{id:o,t:d,se:u,...c}=jw(a.data),l=u.includes(So)?u.split(So):[u],f=Object.fromEntries(Object.entries(c).map(([h,p])=>[h,p.includes(So)?p.split(So):p]));r.service??=[],r.service.push({...f,id:`${t}#${o}`,type:d,serviceEndpoint:l});break}case s.startsWith("typ"):{let{id:o}=jw(a.data);n.types=o.split(So).map(d=>Number(d));break}case s.startsWith("did"):{let o=h=>h.split(So).map(p=>i.get(p)).filter(p=>typeof p=="string"),{auth:d,asm:u,del:c,inv:l,agm:f}=jw(a.data);d&&(r.authentication=o(d)),u&&(r.assertionMethod=o(u)),c&&(r.capabilityDelegation=o(c)),l&&(r.capabilityInvocation=o(l)),f&&(r.keyAgreement=o(f));break}}}return{didDocument:r,didDocumentMetadata:n,didResolutionMetadata:{}}}async function Rue({didDocument:t,didMetadata:e,authoritativeGatewayUris:r,previousDidProof:n}){let i=[],a=[],s=new Map,o=[],d=[];if(n!==void 0){let{signature:c,previousDid:l}=n;await HL({newDid:t.id,previousDidProof:n}),i.push({type:"TXT",name:"_prv._did.",ttl:Gu,data:`id=${l};s=${c}`})}if(t.alsoKnownAs&&i.push({type:"TXT",name:"_aka._did.",ttl:Gu,data:t.alsoKnownAs.join(So)}),t.controller){let c=Array.isArray(t.controller)?t.controller.join(So):t.controller;i.push({type:"TXT",name:"_cnt._did.",ttl:Gu,data:c})}for(let[c,l]of t.verificationMethod?.entries()??[]){let f=`k${c}`;d.push(f);let h=l.id.split("#").pop();s.set(h,f);let p=l.publicKeyJwk;if(!(p?.crv&&p.crv in VL))throw new Xe("invalidPublicKeyType",`Verification method '${l.id}' contains an unsupported key type: ${p?.crv??"undefined"}`);let m=fI[p.crv],g=await gI(p.crv).publicKeyToBytes({publicKey:p}),_=tt.uint8Array(g).toBase64Url(),v=[`t=${m}`,`k=${_}`];h!=="0"&&await lr({jwk:p})!==h&&v.unshift(`id=${h}`),p.alg!==JL[m]&&v.push(`a=${p.alg}`),l.controller!==t.id&&v.push(`c=${l.controller}`),i.push({type:"TXT",name:`_${f}._did.`,ttl:Gu,data:v.join(sx)})}t.service?.forEach((c,l)=>{let f=`s${l}`;o.push(f);let{id:h,type:p,serviceEndpoint:m,...g}=c;h=To(h),m=Array.isArray(m)?m.join(","):m;let _=Object.entries({id:h,t:p,se:m,...g}).map(([E,T])=>`${E}=${T}`).join(sx),v=ZL(_);i.push({type:"TXT",name:`_${f}._did.`,ttl:Gu,data:v})});let u=[`v=${Due}`];if(d.length&&u.push(`vm=${d.join(So)}`),Object.keys(kx).forEach(c=>{let l=t[c]?.map(f=>s.get(f.split("#").pop()));if(l){let f=TL[c];u.push(`${f}=${l.join(So)}`)}}),o.length&&u.push(`svc=${o.join(So)}`),e.types?.length){let c=e.types.map(l=>typeof l=="string"?SL[l]:l);i.push({type:"TXT",name:"_typ._did.",ttl:Gu,data:`id=${c.join(So)}`})}i.push({type:"TXT",name:"_did."+BK(t.id)+".",ttl:Gu,data:u.join(sx)});for(let c of r||[])a.push({type:"NS",name:"_did."+BK(t.id)+".",ttl:Gu,data:c+"."});return{id:0,type:"response",flags:Pue,answers:[...i,...a]}}function BK(t){return t.split(":")[2]}function XL(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Gue;)e[r++]=t&255|UK,t/=128;for(;t&Fue;)e[r++]=t&255|UK,t>>>=7;return e[r]=t|0,XL.bytes=r-n+1,e}function jD(t,n){var r=0,n=n||0,i=0,a=n,s,o=t.length;do{if(a>=o)throw jD.bytes=0,new RangeError("Could not decode varint");s=t[a++],r+=i<28?(s&KK)<<i:(s&KK)*Math.pow(2,i),i+=7}while(s>=Hue);return jD.bytes=a-n,r}function vle(t){t=EI(t);let e=im+8;(t.length<e||t.length>1024)&&ui("expected proper params");let r=Ye(Kx(t),_I-1n)+1n;return TI(r)}function Dle(t){let e=t.toLowerCase();if(e==="localhost"||e==="localhost.")return!0;let r=e.split(".");if(r.length===4){let i=r.map(Number);if(i.every(a=>!Number.isNaN(a)&&a>=0&&a<=255)){let[a,s]=i;if(a===10||a===172&&s>=16&&s<=31||a===192&&s===168||a===127||a===169&&s===254||a===0)return!0}}let n=e;return n.startsWith("[")&&n.endsWith("]")&&(n=n.slice(1,-1)),!!(n.includes(":")&&(n==="::1"||n==="::"||n==="::0"||n.startsWith("fe80:")||n.startsWith("fe80%")||n.startsWith("fc")||n.startsWith("fd")))}var hoe,qD,moe,yoe,goe,woe,Ft,LD,voe,Lf,boe,xoe,Rc,Poe,_oe,zD,uq,lq,fq,Eoe,Soe,Toe,koe,Tx,FD,Bf,Aoe,Doe,pq,Ioe,Roe,hq,Coe,$oe,Ooe,HU,mq,Boe,yq,gq,joe,Moe,Noe,wq,Uoe,Koe,vq,kx,li,Oi,Vn,Xe,qoe,Ys,zo,Loe,Foe,Goe,Woe,gje,Hoe,GD,Voe,Joe,Zoe,_q,Yoe,Eq,Sq,Qoe,Xoe,xs,V1,wje,vje,bje,xje,Pje,_je,Eje,VU,Js,Sje,Tje,kje,Pd,Aje,vw,JU,K1,Af,tt,qw,rse,nse,Tw,ise,ZU,ose,sse,ase,cse,dse,YU,use,lse,fse,pse,hse,mse,yse,gse,wse,vse,bse,xse,hx,mx,zw,Fw,Pse,_se,Ese,WD,QU,XU,PD,Dje,Sse,Tse,kse,bw,Ase,eK,Dse,Xs,Ije,ju,Ise,Ax,Aq,Dq,Dx,Rse,Cse,_d,Nse,VD,uD,rK,Use,lD,fD,xc,zse,jq,Rje,Nq,Gse,Wse,Hse,Mu,Nu,Vse,Uq,Hn,Xr,Rf,Jse,_D,iK,oK,Cje,Zse,Xse,eae,sae,pD,cae,dae,Of,Dd,Vs,$je,sK,Oje,Gq,Wq,Vq,aK,hae,SD,cK,TD,gs,Bje,jje,J1,hD,Pc,Mje,vae,Nje,_ae,Eae,Sae,Tae,Uu,Ku,kae,Gw,Dae,Yq,Iae,uK,Ci,Cae,ji,Qq,$ae,Oae,Bae,zs,$i,jae,no,Ed,lK,q1,kD,Nae,Uae,Kae,qae,Lae,zae,Fae,Gae,Wae,Hae,Vae,Jae,Zae,Qae,Xae,ece,tce,rce,nce,ice,It,oce,sce,qu,Lu,ace,eL,Ma,ms,L1,cce,dce,xw,mD,Ww,fK,Uje,pce,AD,hce,pK,mce,yce,hK,Qs,Hw,Df,Kje,qje,kw,bce,Lje,zje,Fje,Gje,Wje,Hje,Vje,Jje,Zje,Yje,Fs,xce,Mi,Sd,Pce,_ce,Ece,zu,Sce,Vh,Pw,Tce,Td,yD,Ka,kce,Ace,be,Qe,Xw,Rce,Cce,$ce,Oce,kd,Bce,jce,Mce,Nce,sL,Uce,an,aL,e0,Ni,rI,cL,yK,ede,ade,dL,uL,lL,fL,pL,Ws,Na,Ce,Od,Cde,Ode,Bde,gK,Fu,Xu,Qje,Xje,e4e,t4e,r4e,n4e,i4e,o4e,s4e,a4e,c4e,d4e,u4e,vK,io,Zs,bK,xK,l4e,f4e,p4e,h4e,PK,_K,EK,SK,lI,ea,n0,SL,fI,TL,TK,kL,kK,Lde,zde,AK,Fde,_w,Gde,AL,Wde,$d,DK,IK,m4e,Ox,IL,RL,Hde,Vde,Jde,Zde,Yde,pI,Qde,$L,iue,OL,oue,sue,Ac,Qu,qf,Dw,UL,mue,yue,gue,Id,Rt,Rd,rt,vue,$K,ID,bue,KL,xue,He,Wn,Jh,Y1,Q1,X1,ex,tx,rx,rm,nx,Ju,ix,qL,ox,OK,Ad,Zu,kc,Iw,Rw,vs,Cw,$w,Ow,Xh,Hs,nm,Pue,Ui,xx,Px,_x,CD,_ue,GL,Due,Gu,sx,So,VL,JL,jK,YL,tl,MK,tm,An,Dn,y4e,Cue,$ue,Oue,Bue,QL,jue,Mue,Nue,Uue,Mx,g4e,w4e,NK,v4e,am,Kue,OD,Tc,ys,wI,Ua,que,Yw,Lue,UK,zue,Fue,Gue,Wue,Hue,KK,Vue,Jue,Zue,Yue,Que,Xue,ele,tle,rle,nle,ile,ole,Ex,qK,LK,zK,FK,sle,e9,t9,ale,r9,GK,b4e,Ew,ws,MD,F1,ND,Hh,G1,n9,WK,cle,Bi,cx,UD,KD,W1,Lo,o9,vI,cm,dle,st,HK,VK,dm,Sx,dx,s9,bI,xI,ule,lle,JK,a9,_c,fle,ZK,ple,wD,YK,hle,Cf,mle,yle,PI,Nf,_I,c9,d9,u9,im,QK,ui,Nx,l9,vD,f9,p9,Qw,EI,Ye,XK,eq,um,Lw,ux,h9,SI,Ux,Kx,tq,TI,rq,nq,m9,gle,wle,iq,lx,ble,$f,xle,Ple,oq,sq,Sw,_le,Ele,aq,Sle,y9,Jf,Tle,fx,H1,kle,cq,g9,qx,Ale,w9,kI,x4e,P4e,Ile,Lx,Rle,s0,Fo=F(()=>{"use strict";y();hoe=Object.create,qD=Object.defineProperty,moe=Object.getOwnPropertyDescriptor,yoe=Object.getOwnPropertyNames,goe=Object.getPrototypeOf,woe=Object.prototype.hasOwnProperty,Ft=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),LD=(t,e)=>{for(var r in e)qD(t,r,{get:e[r],enumerable:!0})},voe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yoe(e))!woe.call(t,i)&&i!==r&&qD(t,i,{get:()=>e[i],enumerable:!(n=moe(e,i))||n.enumerable});return t},Lf=(t,e,r)=>(r=t!=null?hoe(goe(t)):{},voe(e||!t||!t.__esModule?qD(r,"default",{value:t,enumerable:!0}):r,t)),boe=Ft((t,e)=>{var r=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,n=()=>r.now(),i=o=>o&&o===Math.floor(o)&&o>0&&isFinite(o),a=o=>o===1/0||i(o),s=class dq{constructor({max:d=1/0,ttl:u,updateAgeOnGet:c=!1,checkAgeOnGet:l=!1,noUpdateTTL:f=!1,dispose:h,noDisposeOnSet:p=!1}={}){if(this.expirations=Object.create(null),this.data=new Map,this.expirationMap=new Map,u!==void 0&&!a(u))throw new TypeError("ttl must be positive integer or Infinity if set");if(!a(d))throw new TypeError("max must be positive integer or Infinity");if(this.ttl=u,this.max=d,this.updateAgeOnGet=!!c,this.checkAgeOnGet=!!l,this.noUpdateTTL=!!f,this.noDisposeOnSet=!!p,h!==void 0){if(typeof h!="function")throw new TypeError("dispose must be function if set");this.dispose=h}this.timer=void 0,this.timerExpiration=void 0}setTimer(d,u){if(this.timerExpiration<d)return;this.timer&&clearTimeout(this.timer);let c=setTimeout(()=>{this.timer=void 0,this.timerExpiration=void 0,this.purgeStale();for(let l in this.expirations){this.setTimer(l,l-n());break}},u);c.unref&&c.unref(),this.timerExpiration=d,this.timer=c}cancelTimer(){this.timer&&(clearTimeout(this.timer),this.timerExpiration=void 0,this.timer=void 0)}cancelTimers(){return process.emitWarning('TTLCache.cancelTimers has been renamed to TTLCache.cancelTimer (no "s"), and will be removed in the next major version update'),this.cancelTimer()}clear(){let d=this.dispose!==dq.prototype.dispose?[...this]:[];this.data.clear(),this.expirationMap.clear(),this.cancelTimer(),this.expirations=Object.create(null);for(let[u,c]of d)this.dispose(c,u,"delete")}setTTL(d,u=this.ttl){let c=this.expirationMap.get(d);if(c!==void 0){let l=this.expirations[c];!l||l.length<=1?delete this.expirations[c]:this.expirations[c]=l.filter(f=>f!==d)}if(u!==1/0){let l=Math.floor(n()+u);this.expirationMap.set(d,l),this.expirations[l]||(this.expirations[l]=[],this.setTimer(l,u)),this.expirations[l].push(d)}else this.expirationMap.set(d,1/0)}set(d,u,{ttl:c=this.ttl,noUpdateTTL:l=this.noUpdateTTL,noDisposeOnSet:f=this.noDisposeOnSet}={}){if(!a(c))throw new TypeError("ttl must be positive integer or Infinity");if(this.expirationMap.has(d)){l||this.setTTL(d,c);let h=this.data.get(d);h!==u&&(this.data.set(d,u),f||this.dispose(h,d,"set"))}else this.setTTL(d,c),this.data.set(d,u);for(;this.size>this.max;)this.purgeToCapacity();return this}has(d){return this.data.has(d)}getRemainingTTL(d){let u=this.expirationMap.get(d);return u===1/0?u:u!==void 0?Math.max(0,Math.ceil(u-n())):0}get(d,{updateAgeOnGet:u=this.updateAgeOnGet,ttl:c=this.ttl,checkAgeOnGet:l=this.checkAgeOnGet}={}){let f=this.data.get(d);if(l&&this.getRemainingTTL(d)===0){this.delete(d);return}return u&&this.setTTL(d,c),f}dispose(d,u){}delete(d){let u=this.expirationMap.get(d);if(u!==void 0){let c=this.data.get(d);this.data.delete(d),this.expirationMap.delete(d);let l=this.expirations[u];return l&&(l.length<=1?delete this.expirations[u]:this.expirations[u]=l.filter(f=>f!==d)),this.dispose(c,d,"delete"),this.size===0&&this.cancelTimer(),!0}return!1}purgeToCapacity(){for(let d in this.expirations){let u=this.expirations[d];if(this.size-u.length>=this.max){delete this.expirations[d];let c=[];for(let l of u)c.push([l,this.data.get(l)]),this.data.delete(l),this.expirationMap.delete(l);for(let[l,f]of c)this.dispose(f,l,"evict")}else{let c=this.size-this.max,l=[];for(let f of u.splice(0,c))l.push([f,this.data.get(f)]),this.data.delete(f),this.expirationMap.delete(f);for(let[f,h]of l)this.dispose(h,f,"evict");return}}}get size(){return this.data.size}purgeStale(){let d=Math.ceil(n());for(let u in this.expirations){if(u==="Infinity"||u>d)return;let c=[...this.expirations[u]||[]],l=[];delete this.expirations[u];for(let f of c)l.push([f,this.data.get(f)]),this.data.delete(f),this.expirationMap.delete(f);for(let[f,h]of l)this.dispose(h,f,"stale")}this.size===0&&this.cancelTimer()}*entries(){for(let d in this.expirations)for(let u of this.expirations[d])yield[u,this.data.get(u)]}*keys(){for(let d in this.expirations)for(let u of this.expirations[d])yield u}*values(){for(let d in this.expirations)for(let u of this.expirations[d])yield this.data.get(u)}[Symbol.iterator](){return this.entries()}};e.exports=s}),xoe=Ft(t=>{"use strict";t.supports=function(...e){let r=e.reduce((n,i)=>Object.assign(n,i),{});return Object.assign(r,{snapshots:r.snapshots||!1,permanence:r.permanence||!1,seek:r.seek||!1,clear:r.clear||!1,getMany:r.getMany||!1,keyIterator:r.keyIterator||!1,valueIterator:r.valueIterator||!1,iteratorNextv:r.iteratorNextv||!1,iteratorAll:r.iteratorAll||!1,status:r.status||!1,createIfMissing:r.createIfMissing||!1,errorIfExists:r.errorIfExists||!1,deferredOpen:r.deferredOpen||!1,promises:r.promises||!1,streams:r.streams||!1,encodings:Object.assign({},r.encodings),events:Object.assign({},r.events),additionalMethods:Object.assign({},r.additionalMethods)})}}),Rc=Ft((t,e)=>{"use strict";e.exports=class extends Error{constructor(r,n){super(r||""),typeof n=="object"&&n!==null&&(n.code&&(this.code=String(n.code)),n.expected&&(this.expected=!0),n.transient&&(this.transient=!0),n.cause&&(this.cause=n.cause)),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}}}),Poe=Ft(t=>{"use strict";t.byteLength=d,t.toByteArray=c,t.fromByteArray=h;var e=[],r=[],n=typeof Uint8Array<"u"?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(a=0,s=i.length;a<s;++a)e[a]=i[a],r[i.charCodeAt(a)]=a;var a,s;r[45]=62,r[95]=63;function o(p){var m=p.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var g=p.indexOf("=");g===-1&&(g=m);var _=g===m?0:4-g%4;return[g,_]}function d(p){var m=o(p),g=m[0],_=m[1];return(g+_)*3/4-_}function u(p,m,g){return(m+g)*3/4-g}function c(p){var m,g=o(p),_=g[0],v=g[1],E=new n(u(p,_,v)),T=0,D=v>0?_-4:_,R;for(R=0;R<D;R+=4)m=r[p.charCodeAt(R)]<<18|r[p.charCodeAt(R+1)]<<12|r[p.charCodeAt(R+2)]<<6|r[p.charCodeAt(R+3)],E[T++]=m>>16&255,E[T++]=m>>8&255,E[T++]=m&255;return v===2&&(m=r[p.charCodeAt(R)]<<2|r[p.charCodeAt(R+1)]>>4,E[T++]=m&255),v===1&&(m=r[p.charCodeAt(R)]<<10|r[p.charCodeAt(R+1)]<<4|r[p.charCodeAt(R+2)]>>2,E[T++]=m>>8&255,E[T++]=m&255),E}function l(p){return e[p>>18&63]+e[p>>12&63]+e[p>>6&63]+e[p&63]}function f(p,m,g){for(var _,v=[],E=m;E<g;E+=3)_=(p[E]<<16&16711680)+(p[E+1]<<8&65280)+(p[E+2]&255),v.push(l(_));return v.join("")}function h(p){for(var m,g=p.length,_=g%3,v=[],E=16383,T=0,D=g-_;T<D;T+=E)v.push(f(p,T,T+E>D?D:T+E));return _===1?(m=p[g-1],v.push(e[m>>2]+e[m<<4&63]+"==")):_===2&&(m=(p[g-2]<<8)+p[g-1],v.push(e[m>>10]+e[m>>4&63]+e[m<<2&63]+"=")),v.join("")}}),_oe=Ft(t=>{t.read=function(e,r,n,i,a){var s,o,d=a*8-i-1,u=(1<<d)-1,c=u>>1,l=-7,f=n?a-1:0,h=n?-1:1,p=e[r+f];for(f+=h,s=p&(1<<-l)-1,p>>=-l,l+=d;l>0;s=s*256+e[r+f],f+=h,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=i;l>0;o=o*256+e[r+f],f+=h,l-=8);if(s===0)s=1-c;else{if(s===u)return o?NaN:(p?-1:1)*(1/0);o=o+Math.pow(2,i),s=s-c}return(p?-1:1)*o*Math.pow(2,s-i)},t.write=function(e,r,n,i,a,s){var o,d,u,c=s*8-a-1,l=(1<<c)-1,f=l>>1,h=a===23?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:s-1,m=i?1:-1,g=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(d=isNaN(r)?1:0,o=l):(o=Math.floor(Math.log(r)/Math.LN2),r*(u=Math.pow(2,-o))<1&&(o--,u*=2),o+f>=1?r+=h/u:r+=h*Math.pow(2,1-f),r*u>=2&&(o++,u/=2),o+f>=l?(d=0,o=l):o+f>=1?(d=(r*u-1)*Math.pow(2,a),o=o+f):(d=r*Math.pow(2,f-1)*Math.pow(2,a),o=0));a>=8;e[n+p]=d&255,p+=m,d/=256,a-=8);for(o=o<<a|d,c+=a;c>0;e[n+p]=o&255,p+=m,o/=256,c-=8);e[n+p-m]|=g*128}}),zD=Ft(t=>{"use strict";var e=Poe(),r=_oe(),n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=v,t.INSPECT_MAX_BYTES=50;var i=2147483647;t.kMaxLength=i,o.TYPED_ARRAY_SUPPORT=a(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function a(){try{let k=new Uint8Array(1),j={foo:function(){return 42}};return Object.setPrototypeOf(j,Uint8Array.prototype),Object.setPrototypeOf(k,j),k.foo()===42}catch{return!1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function s(k){if(k>i)throw new RangeError('The value "'+k+'" is invalid for option "size"');let j=new Uint8Array(k);return Object.setPrototypeOf(j,o.prototype),j}function o(k,j,K){if(typeof k=="number"){if(typeof j=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(k)}return d(k,j,K)}o.poolSize=8192;function d(k,j,K){if(typeof k=="string")return f(k,j);if(ArrayBuffer.isView(k))return p(k);if(k==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k);if(Pe(k,ArrayBuffer)||k&&Pe(k.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Pe(k,SharedArrayBuffer)||k&&Pe(k.buffer,SharedArrayBuffer)))return m(k,j,K);if(typeof k=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let te=k.valueOf&&k.valueOf();if(te!=null&&te!==k)return o.from(te,j,K);let se=g(k);if(se)return se;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof k[Symbol.toPrimitive]=="function")return o.from(k[Symbol.toPrimitive]("string"),j,K);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof k)}o.from=function(k,j,K){return d(k,j,K)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function u(k){if(typeof k!="number")throw new TypeError('"size" argument must be of type number');if(k<0)throw new RangeError('The value "'+k+'" is invalid for option "size"')}function c(k,j,K){return u(k),k<=0?s(k):j!==void 0?typeof K=="string"?s(k).fill(j,K):s(k).fill(j):s(k)}o.alloc=function(k,j,K){return c(k,j,K)};function l(k){return u(k),s(k<0?0:_(k)|0)}o.allocUnsafe=function(k){return l(k)},o.allocUnsafeSlow=function(k){return l(k)};function f(k,j){if((typeof j!="string"||j==="")&&(j="utf8"),!o.isEncoding(j))throw new TypeError("Unknown encoding: "+j);let K=E(k,j)|0,te=s(K),se=te.write(k,j);return se!==K&&(te=te.slice(0,se)),te}function h(k){let j=k.length<0?0:_(k.length)|0,K=s(j);for(let te=0;te<j;te+=1)K[te]=k[te]&255;return K}function p(k){if(Pe(k,Uint8Array)){let j=new Uint8Array(k);return m(j.buffer,j.byteOffset,j.byteLength)}return h(k)}function m(k,j,K){if(j<0||k.byteLength<j)throw new RangeError('"offset" is outside of buffer bounds');if(k.byteLength<j+(K||0))throw new RangeError('"length" is outside of buffer bounds');let te;return j===void 0&&K===void 0?te=new Uint8Array(k):K===void 0?te=new Uint8Array(k,j):te=new Uint8Array(k,j,K),Object.setPrototypeOf(te,o.prototype),te}function g(k){if(o.isBuffer(k)){let j=_(k.length)|0,K=s(j);return K.length===0||k.copy(K,0,0,j),K}if(k.length!==void 0)return typeof k.length!="number"||nt(k.length)?s(0):h(k);if(k.type==="Buffer"&&Array.isArray(k.data))return h(k.data)}function _(k){if(k>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.toString(16)+" bytes");return k|0}function v(k){return+k!=k&&(k=0),o.alloc(+k)}o.isBuffer=function(k){return k!=null&&k._isBuffer===!0&&k!==o.prototype},o.compare=function(k,j){if(Pe(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),Pe(j,Uint8Array)&&(j=o.from(j,j.offset,j.byteLength)),!o.isBuffer(k)||!o.isBuffer(j))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(k===j)return 0;let K=k.length,te=j.length;for(let se=0,he=Math.min(K,te);se<he;++se)if(k[se]!==j[se]){K=k[se],te=j[se];break}return K<te?-1:te<K?1:0},o.isEncoding=function(k){switch(String(k).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(k,j){if(!Array.isArray(k))throw new TypeError('"list" argument must be an Array of Buffers');if(k.length===0)return o.alloc(0);let K;if(j===void 0)for(j=0,K=0;K<k.length;++K)j+=k[K].length;let te=o.allocUnsafe(j),se=0;for(K=0;K<k.length;++K){let he=k[K];if(Pe(he,Uint8Array))se+he.length>te.length?(o.isBuffer(he)||(he=o.from(he)),he.copy(te,se)):Uint8Array.prototype.set.call(te,he,se);else if(o.isBuffer(he))he.copy(te,se);else throw new TypeError('"list" argument must be an Array of Buffers');se+=he.length}return te};function E(k,j){if(o.isBuffer(k))return k.length;if(ArrayBuffer.isView(k)||Pe(k,ArrayBuffer))return k.byteLength;if(typeof k!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof k);let K=k.length,te=arguments.length>2&&arguments[2]===!0;if(!te&&K===0)return 0;let se=!1;for(;;)switch(j){case"ascii":case"latin1":case"binary":return K;case"utf8":case"utf-8":return ge(k).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return K*2;case"hex":return K>>>1;case"base64":return We(k).length;default:if(se)return te?-1:ge(k).length;j=(""+j).toLowerCase(),se=!0}}o.byteLength=E;function T(k,j,K){let te=!1;if((j===void 0||j<0)&&(j=0),j>this.length||((K===void 0||K>this.length)&&(K=this.length),K<=0)||(K>>>=0,j>>>=0,K<=j))return"";for(k||(k="utf8");;)switch(k){case"hex":return S(this,j,K);case"utf8":case"utf-8":return I(this,j,K);case"ascii":return P(this,j,K);case"latin1":case"binary":return x(this,j,K);case"base64":return ee(this,j,K);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,j,K);default:if(te)throw new TypeError("Unknown encoding: "+k);k=(k+"").toLowerCase(),te=!0}}o.prototype._isBuffer=!0;function D(k,j,K){let te=k[j];k[j]=k[K],k[K]=te}o.prototype.swap16=function(){let k=this.length;if(k%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let j=0;j<k;j+=2)D(this,j,j+1);return this},o.prototype.swap32=function(){let k=this.length;if(k%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let j=0;j<k;j+=4)D(this,j,j+3),D(this,j+1,j+2);return this},o.prototype.swap64=function(){let k=this.length;if(k%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let j=0;j<k;j+=8)D(this,j,j+7),D(this,j+1,j+6),D(this,j+2,j+5),D(this,j+3,j+4);return this},o.prototype.toString=function(){let k=this.length;return k===0?"":arguments.length===0?I(this,0,k):T.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(k){if(!o.isBuffer(k))throw new TypeError("Argument must be a Buffer");return this===k?!0:o.compare(this,k)===0},o.prototype.inspect=function(){let k="",j=t.INSPECT_MAX_BYTES;return k=this.toString("hex",0,j).replace(/(.{2})/g,"$1 ").trim(),this.length>j&&(k+=" ... "),"<Buffer "+k+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(k,j,K,te,se){if(Pe(k,Uint8Array)&&(k=o.from(k,k.offset,k.byteLength)),!o.isBuffer(k))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof k);if(j===void 0&&(j=0),K===void 0&&(K=k?k.length:0),te===void 0&&(te=0),se===void 0&&(se=this.length),j<0||K>k.length||te<0||se>this.length)throw new RangeError("out of range index");if(te>=se&&j>=K)return 0;if(te>=se)return-1;if(j>=K)return 1;if(j>>>=0,K>>>=0,te>>>=0,se>>>=0,this===k)return 0;let he=se-te,xe=K-j,Bt=Math.min(he,xe),Mn=this.slice(te,se),$r=k.slice(j,K);for(let fr=0;fr<Bt;++fr)if(Mn[fr]!==$r[fr]){he=Mn[fr],xe=$r[fr];break}return he<xe?-1:xe<he?1:0};function R(k,j,K,te,se){if(k.length===0)return-1;if(typeof K=="string"?(te=K,K=0):K>2147483647?K=2147483647:K<-2147483648&&(K=-2147483648),K=+K,nt(K)&&(K=se?0:k.length-1),K<0&&(K=k.length+K),K>=k.length){if(se)return-1;K=k.length-1}else if(K<0)if(se)K=0;else return-1;if(typeof j=="string"&&(j=o.from(j,te)),o.isBuffer(j))return j.length===0?-1:N(k,j,K,te,se);if(typeof j=="number")return j=j&255,typeof Uint8Array.prototype.indexOf=="function"?se?Uint8Array.prototype.indexOf.call(k,j,K):Uint8Array.prototype.lastIndexOf.call(k,j,K):N(k,[j],K,te,se);throw new TypeError("val must be string, number or Buffer")}function N(k,j,K,te,se){let he=1,xe=k.length,Bt=j.length;if(te!==void 0&&(te=String(te).toLowerCase(),te==="ucs2"||te==="ucs-2"||te==="utf16le"||te==="utf-16le")){if(k.length<2||j.length<2)return-1;he=2,xe/=2,Bt/=2,K/=2}function Mn(fr,nr){return he===1?fr[nr]:fr.readUInt16BE(nr*he)}let $r;if(se){let fr=-1;for($r=K;$r<xe;$r++)if(Mn(k,$r)===Mn(j,fr===-1?0:$r-fr)){if(fr===-1&&(fr=$r),$r-fr+1===Bt)return fr*he}else fr!==-1&&($r-=$r-fr),fr=-1}else for(K+Bt>xe&&(K=xe-Bt),$r=K;$r>=0;$r--){let fr=!0;for(let nr=0;nr<Bt;nr++)if(Mn(k,$r+nr)!==Mn(j,nr)){fr=!1;break}if(fr)return $r}return-1}o.prototype.includes=function(k,j,K){return this.indexOf(k,j,K)!==-1},o.prototype.indexOf=function(k,j,K){return R(this,k,j,K,!0)},o.prototype.lastIndexOf=function(k,j,K){return R(this,k,j,K,!1)};function B(k,j,K,te){K=Number(K)||0;let se=k.length-K;te?(te=Number(te),te>se&&(te=se)):te=se;let he=j.length;te>he/2&&(te=he/2);let xe;for(xe=0;xe<te;++xe){let Bt=parseInt(j.substr(xe*2,2),16);if(nt(Bt))return xe;k[K+xe]=Bt}return xe}function G(k,j,K,te){return Pt(ge(j,k.length-K),k,K,te)}function z(k,j,K,te){return Pt(Be(j),k,K,te)}function U(k,j,K,te){return Pt(We(j),k,K,te)}function H(k,j,K,te){return Pt(qe(j,k.length-K),k,K,te)}o.prototype.write=function(k,j,K,te){if(j===void 0)te="utf8",K=this.length,j=0;else if(K===void 0&&typeof j=="string")te=j,K=this.length,j=0;else if(isFinite(j))j=j>>>0,isFinite(K)?(K=K>>>0,te===void 0&&(te="utf8")):(te=K,K=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let se=this.length-j;if((K===void 0||K>se)&&(K=se),k.length>0&&(K<0||j<0)||j>this.length)throw new RangeError("Attempt to write outside buffer bounds");te||(te="utf8");let he=!1;for(;;)switch(te){case"hex":return B(this,k,j,K);case"utf8":case"utf-8":return G(this,k,j,K);case"ascii":case"latin1":case"binary":return z(this,k,j,K);case"base64":return U(this,k,j,K);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,k,j,K);default:if(he)throw new TypeError("Unknown encoding: "+te);te=(""+te).toLowerCase(),he=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ee(k,j,K){return j===0&&K===k.length?e.fromByteArray(k):e.fromByteArray(k.slice(j,K))}function I(k,j,K){K=Math.min(k.length,K);let te=[],se=j;for(;se<K;){let he=k[se],xe=null,Bt=he>239?4:he>223?3:he>191?2:1;if(se+Bt<=K){let Mn,$r,fr,nr;switch(Bt){case 1:he<128&&(xe=he);break;case 2:Mn=k[se+1],(Mn&192)===128&&(nr=(he&31)<<6|Mn&63,nr>127&&(xe=nr));break;case 3:Mn=k[se+1],$r=k[se+2],(Mn&192)===128&&($r&192)===128&&(nr=(he&15)<<12|(Mn&63)<<6|$r&63,nr>2047&&(nr<55296||nr>57343)&&(xe=nr));break;case 4:Mn=k[se+1],$r=k[se+2],fr=k[se+3],(Mn&192)===128&&($r&192)===128&&(fr&192)===128&&(nr=(he&15)<<18|(Mn&63)<<12|($r&63)<<6|fr&63,nr>65535&&nr<1114112&&(xe=nr))}}xe===null?(xe=65533,Bt=1):xe>65535&&(xe-=65536,te.push(xe>>>10&1023|55296),xe=56320|xe&1023),te.push(xe),se+=Bt}return b(te)}var O=4096;function b(k){let j=k.length;if(j<=O)return String.fromCharCode.apply(String,k);let K="",te=0;for(;te<j;)K+=String.fromCharCode.apply(String,k.slice(te,te+=O));return K}function P(k,j,K){let te="";K=Math.min(k.length,K);for(let se=j;se<K;++se)te+=String.fromCharCode(k[se]&127);return te}function x(k,j,K){let te="";K=Math.min(k.length,K);for(let se=j;se<K;++se)te+=String.fromCharCode(k[se]);return te}function S(k,j,K){let te=k.length;(!j||j<0)&&(j=0),(!K||K<0||K>te)&&(K=te);let se="";for(let he=j;he<K;++he)se+=wt[k[he]];return se}function A(k,j,K){let te=k.slice(j,K),se="";for(let he=0;he<te.length-1;he+=2)se+=String.fromCharCode(te[he]+te[he+1]*256);return se}o.prototype.slice=function(k,j){let K=this.length;k=~~k,j=j===void 0?K:~~j,k<0?(k+=K,k<0&&(k=0)):k>K&&(k=K),j<0?(j+=K,j<0&&(j=0)):j>K&&(j=K),j<k&&(j=k);let te=this.subarray(k,j);return Object.setPrototypeOf(te,o.prototype),te};function M(k,j,K){if(k%1!==0||k<0)throw new RangeError("offset is not uint");if(k+j>K)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k],se=1,he=0;for(;++he<j&&(se*=256);)te+=this[k+he]*se;return te},o.prototype.readUintBE=o.prototype.readUIntBE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k+--j],se=1;for(;j>0&&(se*=256);)te+=this[k+--j]*se;return te},o.prototype.readUint8=o.prototype.readUInt8=function(k,j){return k=k>>>0,j||M(k,1,this.length),this[k]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(k,j){return k=k>>>0,j||M(k,2,this.length),this[k]|this[k+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(k,j){return k=k>>>0,j||M(k,2,this.length),this[k]<<8|this[k+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(k,j){return k=k>>>0,j||M(k,4,this.length),(this[k]|this[k+1]<<8|this[k+2]<<16)+this[k+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]*16777216+(this[k+1]<<16|this[k+2]<<8|this[k+3])},o.prototype.readBigUInt64LE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=j+this[++k]*2**8+this[++k]*2**16+this[++k]*2**24,se=this[++k]+this[++k]*2**8+this[++k]*2**16+K*2**24;return BigInt(te)+(BigInt(se)<<BigInt(32))}),o.prototype.readBigUInt64BE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=j*2**24+this[++k]*2**16+this[++k]*2**8+this[++k],se=this[++k]*2**24+this[++k]*2**16+this[++k]*2**8+K;return(BigInt(te)<<BigInt(32))+BigInt(se)}),o.prototype.readIntLE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=this[k],se=1,he=0;for(;++he<j&&(se*=256);)te+=this[k+he]*se;return se*=128,te>=se&&(te-=Math.pow(2,8*j)),te},o.prototype.readIntBE=function(k,j,K){k=k>>>0,j=j>>>0,K||M(k,j,this.length);let te=j,se=1,he=this[k+--te];for(;te>0&&(se*=256);)he+=this[k+--te]*se;return se*=128,he>=se&&(he-=Math.pow(2,8*j)),he},o.prototype.readInt8=function(k,j){return k=k>>>0,j||M(k,1,this.length),this[k]&128?(255-this[k]+1)*-1:this[k]},o.prototype.readInt16LE=function(k,j){k=k>>>0,j||M(k,2,this.length);let K=this[k]|this[k+1]<<8;return K&32768?K|4294901760:K},o.prototype.readInt16BE=function(k,j){k=k>>>0,j||M(k,2,this.length);let K=this[k+1]|this[k]<<8;return K&32768?K|4294901760:K},o.prototype.readInt32LE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]|this[k+1]<<8|this[k+2]<<16|this[k+3]<<24},o.prototype.readInt32BE=function(k,j){return k=k>>>0,j||M(k,4,this.length),this[k]<<24|this[k+1]<<16|this[k+2]<<8|this[k+3]},o.prototype.readBigInt64LE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=this[k+4]+this[k+5]*2**8+this[k+6]*2**16+(K<<24);return(BigInt(te)<<BigInt(32))+BigInt(j+this[++k]*2**8+this[++k]*2**16+this[++k]*2**24)}),o.prototype.readBigInt64BE=xt(function(k){k=k>>>0,de(k,"offset");let j=this[k],K=this[k+7];(j===void 0||K===void 0)&&pe(k,this.length-8);let te=(j<<24)+this[++k]*2**16+this[++k]*2**8+this[++k];return(BigInt(te)<<BigInt(32))+BigInt(this[++k]*2**24+this[++k]*2**16+this[++k]*2**8+K)}),o.prototype.readFloatLE=function(k,j){return k=k>>>0,j||M(k,4,this.length),r.read(this,k,!0,23,4)},o.prototype.readFloatBE=function(k,j){return k=k>>>0,j||M(k,4,this.length),r.read(this,k,!1,23,4)},o.prototype.readDoubleLE=function(k,j){return k=k>>>0,j||M(k,8,this.length),r.read(this,k,!0,52,8)},o.prototype.readDoubleBE=function(k,j){return k=k>>>0,j||M(k,8,this.length),r.read(this,k,!1,52,8)};function L(k,j,K,te,se,he){if(!o.isBuffer(k))throw new TypeError('"buffer" argument must be a Buffer instance');if(j>se||j<he)throw new RangeError('"value" argument is out of bounds');if(K+te>k.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(k,j,K,te){if(k=+k,j=j>>>0,K=K>>>0,!te){let xe=Math.pow(2,8*K)-1;L(this,k,j,K,xe,0)}let se=1,he=0;for(this[j]=k&255;++he<K&&(se*=256);)this[j+he]=k/se&255;return j+K},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(k,j,K,te){if(k=+k,j=j>>>0,K=K>>>0,!te){let xe=Math.pow(2,8*K)-1;L(this,k,j,K,xe,0)}let se=K-1,he=1;for(this[j+se]=k&255;--se>=0&&(he*=256);)this[j+se]=k/he&255;return j+K},o.prototype.writeUint8=o.prototype.writeUInt8=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,1,255,0),this[j]=k&255,j+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,65535,0),this[j]=k&255,this[j+1]=k>>>8,j+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,65535,0),this[j]=k>>>8,this[j+1]=k&255,j+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,4294967295,0),this[j+3]=k>>>24,this[j+2]=k>>>16,this[j+1]=k>>>8,this[j]=k&255,j+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,4294967295,0),this[j]=k>>>24,this[j+1]=k>>>16,this[j+2]=k>>>8,this[j+3]=k&255,j+4};function W(k,j,K,te,se){ce(j,te,se,k,K,7);let he=Number(j&BigInt(4294967295));k[K++]=he,he=he>>8,k[K++]=he,he=he>>8,k[K++]=he,he=he>>8,k[K++]=he;let xe=Number(j>>BigInt(32)&BigInt(4294967295));return k[K++]=xe,xe=xe>>8,k[K++]=xe,xe=xe>>8,k[K++]=xe,xe=xe>>8,k[K++]=xe,K}function V(k,j,K,te,se){ce(j,te,se,k,K,7);let he=Number(j&BigInt(4294967295));k[K+7]=he,he=he>>8,k[K+6]=he,he=he>>8,k[K+5]=he,he=he>>8,k[K+4]=he;let xe=Number(j>>BigInt(32)&BigInt(4294967295));return k[K+3]=xe,xe=xe>>8,k[K+2]=xe,xe=xe>>8,k[K+1]=xe,xe=xe>>8,k[K]=xe,K+8}o.prototype.writeBigUInt64LE=xt(function(k,j=0){return W(this,k,j,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=xt(function(k,j=0){return V(this,k,j,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(k,j,K,te){if(k=+k,j=j>>>0,!te){let Bt=Math.pow(2,8*K-1);L(this,k,j,K,Bt-1,-Bt)}let se=0,he=1,xe=0;for(this[j]=k&255;++se<K&&(he*=256);)k<0&&xe===0&&this[j+se-1]!==0&&(xe=1),this[j+se]=(k/he>>0)-xe&255;return j+K},o.prototype.writeIntBE=function(k,j,K,te){if(k=+k,j=j>>>0,!te){let Bt=Math.pow(2,8*K-1);L(this,k,j,K,Bt-1,-Bt)}let se=K-1,he=1,xe=0;for(this[j+se]=k&255;--se>=0&&(he*=256);)k<0&&xe===0&&this[j+se+1]!==0&&(xe=1),this[j+se]=(k/he>>0)-xe&255;return j+K},o.prototype.writeInt8=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,1,127,-128),k<0&&(k=255+k+1),this[j]=k&255,j+1},o.prototype.writeInt16LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,32767,-32768),this[j]=k&255,this[j+1]=k>>>8,j+2},o.prototype.writeInt16BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,2,32767,-32768),this[j]=k>>>8,this[j+1]=k&255,j+2},o.prototype.writeInt32LE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,2147483647,-2147483648),this[j]=k&255,this[j+1]=k>>>8,this[j+2]=k>>>16,this[j+3]=k>>>24,j+4},o.prototype.writeInt32BE=function(k,j,K){return k=+k,j=j>>>0,K||L(this,k,j,4,2147483647,-2147483648),k<0&&(k=4294967295+k+1),this[j]=k>>>24,this[j+1]=k>>>16,this[j+2]=k>>>8,this[j+3]=k&255,j+4},o.prototype.writeBigInt64LE=xt(function(k,j=0){return W(this,k,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=xt(function(k,j=0){return V(this,k,j,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function J(k,j,K,te,se,he){if(K+te>k.length)throw new RangeError("Index out of range");if(K<0)throw new RangeError("Index out of range")}function Q(k,j,K,te,se){return j=+j,K=K>>>0,se||J(k,j,K,4,34028234663852886e22,-34028234663852886e22),r.write(k,j,K,te,23,4),K+4}o.prototype.writeFloatLE=function(k,j,K){return Q(this,k,j,!0,K)},o.prototype.writeFloatBE=function(k,j,K){return Q(this,k,j,!1,K)};function q(k,j,K,te,se){return j=+j,K=K>>>0,se||J(k,j,K,8,17976931348623157e292,-17976931348623157e292),r.write(k,j,K,te,52,8),K+8}o.prototype.writeDoubleLE=function(k,j,K){return q(this,k,j,!0,K)},o.prototype.writeDoubleBE=function(k,j,K){return q(this,k,j,!1,K)},o.prototype.copy=function(k,j,K,te){if(!o.isBuffer(k))throw new TypeError("argument should be a Buffer");if(K||(K=0),!te&&te!==0&&(te=this.length),j>=k.length&&(j=k.length),j||(j=0),te>0&&te<K&&(te=K),te===K||k.length===0||this.length===0)return 0;if(j<0)throw new RangeError("targetStart out of bounds");if(K<0||K>=this.length)throw new RangeError("Index out of range");if(te<0)throw new RangeError("sourceEnd out of bounds");te>this.length&&(te=this.length),k.length-j<te-K&&(te=k.length-j+K);let se=te-K;return this===k&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(j,K,te):Uint8Array.prototype.set.call(k,this.subarray(K,te),j),se},o.prototype.fill=function(k,j,K,te){if(typeof k=="string"){if(typeof j=="string"?(te=j,j=0,K=this.length):typeof K=="string"&&(te=K,K=this.length),te!==void 0&&typeof te!="string")throw new TypeError("encoding must be a string");if(typeof te=="string"&&!o.isEncoding(te))throw new TypeError("Unknown encoding: "+te);if(k.length===1){let he=k.charCodeAt(0);(te==="utf8"&&he<128||te==="latin1")&&(k=he)}}else typeof k=="number"?k=k&255:typeof k=="boolean"&&(k=Number(k));if(j<0||this.length<j||this.length<K)throw new RangeError("Out of range index");if(K<=j)return this;j=j>>>0,K=K===void 0?this.length:K>>>0,k||(k=0);let se;if(typeof k=="number")for(se=j;se<K;++se)this[se]=k;else{let he=o.isBuffer(k)?k:o.from(k,te),xe=he.length;if(xe===0)throw new TypeError('The value "'+k+'" is invalid for argument "value"');for(se=0;se<K-j;++se)this[se+j]=he[se%xe]}return this};var X={};function ne(k,j,K){X[k]=class extends K{constructor(){super(),Object.defineProperty(this,"message",{value:j.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${k}]`,this.stack,delete this.name}get code(){return k}set code(te){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:te,writable:!0})}toString(){return`${this.name} [${k}]: ${this.message}`}}}ne("ERR_BUFFER_OUT_OF_BOUNDS",function(k){return k?`${k} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ne("ERR_INVALID_ARG_TYPE",function(k,j){return`The "${k}" argument must be of type number. Received type ${typeof j}`},TypeError),ne("ERR_OUT_OF_RANGE",function(k,j,K){let te=`The value of "${k}" is out of range.`,se=K;return Number.isInteger(K)&&Math.abs(K)>2**32?se=re(String(K)):typeof K=="bigint"&&(se=String(K),(K>BigInt(2)**BigInt(32)||K<-(BigInt(2)**BigInt(32)))&&(se=re(se)),se+="n"),te+=` It must be ${j}. Received ${se}`,te},RangeError);function re(k){let j="",K=k.length,te=k[0]==="-"?1:0;for(;K>=te+4;K-=3)j=`_${k.slice(K-3,K)}${j}`;return`${k.slice(0,K)}${j}`}function Y(k,j,K){de(j,"offset"),(k[j]===void 0||k[j+K]===void 0)&&pe(j,k.length-(K+1))}function ce(k,j,K,te,se,he){if(k>K||k<j){let xe=typeof j=="bigint"?"n":"",Bt;throw he>3?j===0||j===BigInt(0)?Bt=`>= 0${xe} and < 2${xe} ** ${(he+1)*8}${xe}`:Bt=`>= -(2${xe} ** ${(he+1)*8-1}${xe}) and < 2 ** ${(he+1)*8-1}${xe}`:Bt=`>= ${j}${xe} and <= ${K}${xe}`,new X.ERR_OUT_OF_RANGE("value",Bt,k)}Y(te,se,he)}function de(k,j){if(typeof k!="number")throw new X.ERR_INVALID_ARG_TYPE(j,"number",k)}function pe(k,j,K){throw Math.floor(k)!==k?(de(k,K),new X.ERR_OUT_OF_RANGE(K||"offset","an integer",k)):j<0?new X.ERR_BUFFER_OUT_OF_BOUNDS:new X.ERR_OUT_OF_RANGE(K||"offset",`>= ${K?1:0} and <= ${j}`,k)}var we=/[^+/0-9A-Za-z-_]/g;function ae(k){if(k=k.split("=")[0],k=k.trim().replace(we,""),k.length<2)return"";for(;k.length%4!==0;)k=k+"=";return k}function ge(k,j){j=j||1/0;let K,te=k.length,se=null,he=[];for(let xe=0;xe<te;++xe){if(K=k.charCodeAt(xe),K>55295&&K<57344){if(!se){if(K>56319){(j-=3)>-1&&he.push(239,191,189);continue}else if(xe+1===te){(j-=3)>-1&&he.push(239,191,189);continue}se=K;continue}if(K<56320){(j-=3)>-1&&he.push(239,191,189),se=K;continue}K=(se-55296<<10|K-56320)+65536}else se&&(j-=3)>-1&&he.push(239,191,189);if(se=null,K<128){if((j-=1)<0)break;he.push(K)}else if(K<2048){if((j-=2)<0)break;he.push(K>>6|192,K&63|128)}else if(K<65536){if((j-=3)<0)break;he.push(K>>12|224,K>>6&63|128,K&63|128)}else if(K<1114112){if((j-=4)<0)break;he.push(K>>18|240,K>>12&63|128,K>>6&63|128,K&63|128)}else throw new Error("Invalid code point")}return he}function Be(k){let j=[];for(let K=0;K<k.length;++K)j.push(k.charCodeAt(K)&255);return j}function qe(k,j){let K,te,se,he=[];for(let xe=0;xe<k.length&&!((j-=2)<0);++xe)K=k.charCodeAt(xe),te=K>>8,se=K%256,he.push(se),he.push(te);return he}function We(k){return e.toByteArray(ae(k))}function Pt(k,j,K,te){let se;for(se=0;se<te&&!(se+K>=j.length||se>=k.length);++se)j[se+K]=k[se];return se}function Pe(k,j){return k instanceof j||k!=null&&k.constructor!=null&&k.constructor.name!=null&&k.constructor.name===j.name}function nt(k){return k!==k}var wt=function(){let k="0123456789abcdef",j=new Array(256);for(let K=0;K<16;++K){let te=K*16;for(let se=0;se<16;++se)j[te+se]=k[K]+k[se]}return j}();function xt(k){return typeof BigInt>"u"?Ot:k}function Ot(){throw new Error("BigInt not supported")}}),uq=Ft((t,e)=>{"use strict";var r=null;e.exports=function(){return r===null&&(r={textEncoder:new TextEncoder,textDecoder:new TextDecoder}),r}}),lq=Ft(t=>{"use strict";var e=Rc(),r=new Set(["buffer","view","utf8"]),n=class{constructor(i){if(this.encode=i.encode||this.encode,this.decode=i.decode||this.decode,this.name=i.name||this.name,this.format=i.format||this.format,typeof this.encode!="function")throw new TypeError("The 'encode' property must be a function");if(typeof this.decode!="function")throw new TypeError("The 'decode' property must be a function");if(this.encode=this.encode.bind(this),this.decode=this.decode.bind(this),typeof this.name!="string"||this.name==="")throw new TypeError("The 'name' property must be a string");if(typeof this.format!="string"||!r.has(this.format))throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'");i.createViewTranscoder&&(this.createViewTranscoder=i.createViewTranscoder),i.createBufferTranscoder&&(this.createBufferTranscoder=i.createBufferTranscoder),i.createUTF8Transcoder&&(this.createUTF8Transcoder=i.createUTF8Transcoder)}get commonName(){return this.name.split("+")[0]}createBufferTranscoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'buffer'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createViewTranscoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'view'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}createUTF8Transcoder(){throw new e(`Encoding '${this.name}' cannot be transcoded to 'utf8'`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"})}};t.Encoding=n}),fq=Ft(t=>{"use strict";var{Buffer:e}=zD()||{},{Encoding:r}=lq(),n=uq(),i=class extends r{constructor(o){super({...o,format:"buffer"})}createViewTranscoder(){return new a({encode:this.encode,decode:o=>this.decode(e.from(o.buffer,o.byteOffset,o.byteLength)),name:`${this.name}+view`})}createBufferTranscoder(){return this}},a=class extends r{constructor(o){super({...o,format:"view"})}createBufferTranscoder(){return new i({encode:o=>{let d=this.encode(o);return e.from(d.buffer,d.byteOffset,d.byteLength)},decode:this.decode,name:`${this.name}+buffer`})}createViewTranscoder(){return this}},s=class extends r{constructor(o){super({...o,format:"utf8"})}createBufferTranscoder(){return new i({encode:o=>e.from(this.encode(o),"utf8"),decode:o=>this.decode(o.toString("utf8")),name:`${this.name}+buffer`})}createViewTranscoder(){let{textEncoder:o,textDecoder:d}=n();return new a({encode:u=>o.encode(this.encode(u)),decode:u=>this.decode(d.decode(u)),name:`${this.name}+view`})}createUTF8Transcoder(){return this}};t.BufferFormat=i,t.ViewFormat=a,t.UTF8Format=s}),Eoe=Ft(t=>{"use strict";var{Buffer:e}=zD()||{Buffer:{isBuffer:()=>!1}},{textEncoder:r,textDecoder:n}=uq()(),{BufferFormat:i,ViewFormat:a,UTF8Format:s}=fq(),o=d=>d;t.utf8=new s({encode:function(d){return e.isBuffer(d)?d.toString("utf8"):ArrayBuffer.isView(d)?n.decode(d):String(d)},decode:o,name:"utf8",createViewTranscoder(){return new a({encode:function(d){return ArrayBuffer.isView(d)?d:r.encode(d)},decode:function(d){return n.decode(d)},name:`${this.name}+view`})},createBufferTranscoder(){return new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:function(d){return d.toString("utf8")},name:`${this.name}+buffer`})}}),t.json=new s({encode:JSON.stringify,decode:JSON.parse,name:"json"}),t.buffer=new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:o,name:"buffer",createViewTranscoder(){return new a({encode:function(d){return ArrayBuffer.isView(d)?d:e.from(String(d),"utf8")},decode:function(d){return e.from(d.buffer,d.byteOffset,d.byteLength)},name:`${this.name}+view`})}}),t.view=new a({encode:function(d){return ArrayBuffer.isView(d)?d:r.encode(d)},decode:o,name:"view",createBufferTranscoder(){return new i({encode:function(d){return e.isBuffer(d)?d:ArrayBuffer.isView(d)?e.from(d.buffer,d.byteOffset,d.byteLength):e.from(String(d),"utf8")},decode:o,name:`${this.name}+buffer`})}}),t.hex=new i({encode:function(d){return e.isBuffer(d)?d:e.from(String(d),"hex")},decode:function(d){return d.toString("hex")},name:"hex"}),t.base64=new i({encode:function(d){return e.isBuffer(d)?d:e.from(String(d),"base64")},decode:function(d){return d.toString("base64")},name:"base64"})}),Soe=Ft(t=>{"use strict";var e=Rc(),r=Eoe(),{Encoding:n}=lq(),{BufferFormat:i,ViewFormat:a,UTF8Format:s}=fq(),o=Symbol("formats"),d=Symbol("encodings"),u=new Set(["buffer","view","utf8"]),c=class{constructor(g){if(Array.isArray(g)){if(!g.every(_=>u.has(_)))throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}else throw new TypeError("The first argument 'formats' must be an array");this[d]=new Map,this[o]=new Set(g);for(let _ in r)try{this.encoding(_)}catch(v){if(v.code!=="LEVEL_ENCODING_NOT_SUPPORTED")throw v}}encodings(){return Array.from(new Set(this[d].values()))}encoding(g){let _=this[d].get(g);if(_===void 0){if(typeof g=="string"&&g!==""){if(_=p[g],!_)throw new e(`Encoding '${g}' is not found`,{code:"LEVEL_ENCODING_NOT_FOUND"})}else{if(typeof g!="object"||g===null)throw new TypeError("First argument 'encoding' must be a string or object");_=l(g)}let{name:v,format:E}=_;if(!this[o].has(E))if(this[o].has("view"))_=_.createViewTranscoder();else if(this[o].has("buffer"))_=_.createBufferTranscoder();else if(this[o].has("utf8"))_=_.createUTF8Transcoder();else throw new e(`Encoding '${v}' cannot be transcoded`,{code:"LEVEL_ENCODING_NOT_SUPPORTED"});for(let T of[g,v,_.name,_.commonName])this[d].set(T,_)}return _}};t.Transcoder=c;function l(g){if(g instanceof n)return g;let _="type"in g&&typeof g.type=="string"?g.type:void 0,v=g.name||_||`anonymous-${m++}`;switch(f(g)){case"view":return new a({...g,name:v});case"utf8":return new s({...g,name:v});case"buffer":return new i({...g,name:v});default:throw new TypeError("Format must be one of 'buffer', 'view', 'utf8'")}}function f(g){return"format"in g&&g.format!==void 0?g.format:"buffer"in g&&typeof g.buffer=="boolean"?g.buffer?"buffer":"utf8":"code"in g&&Number.isInteger(g.code)?"view":"buffer"}var h={binary:r.buffer,"utf-8":r.utf8},p={...r,...h},m=0}),Toe=Ft((t,e)=>{"use strict";var r=Object.prototype.hasOwnProperty,n="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(n=!1));function a(u,c,l){this.fn=u,this.context=c,this.once=l||!1}function s(u,c,l,f,h){if(typeof l!="function")throw new TypeError("The listener must be a function");var p=new a(l,f||u,h),m=n?n+c:c;return u._events[m]?u._events[m].fn?u._events[m]=[u._events[m],p]:u._events[m].push(p):(u._events[m]=p,u._eventsCount++),u}function o(u,c){--u._eventsCount===0?u._events=new i:delete u._events[c]}function d(){this._events=new i,this._eventsCount=0}d.prototype.eventNames=function(){var u=[],c,l;if(this._eventsCount===0)return u;for(l in c=this._events)r.call(c,l)&&u.push(n?l.slice(1):l);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(c)):u},d.prototype.listeners=function(u){var c=n?n+u:u,l=this._events[c];if(!l)return[];if(l.fn)return[l.fn];for(var f=0,h=l.length,p=new Array(h);f<h;f++)p[f]=l[f].fn;return p},d.prototype.listenerCount=function(u){var c=n?n+u:u,l=this._events[c];return l?l.fn?1:l.length:0},d.prototype.emit=function(u,c,l,f,h,p){var m=n?n+u:u;if(!this._events[m])return!1;var g=this._events[m],_=arguments.length,v,E;if(g.fn){switch(g.once&&this.removeListener(u,g.fn,void 0,!0),_){case 1:return g.fn.call(g.context),!0;case 2:return g.fn.call(g.context,c),!0;case 3:return g.fn.call(g.context,c,l),!0;case 4:return g.fn.call(g.context,c,l,f),!0;case 5:return g.fn.call(g.context,c,l,f,h),!0;case 6:return g.fn.call(g.context,c,l,f,h,p),!0}for(E=1,v=new Array(_-1);E<_;E++)v[E-1]=arguments[E];g.fn.apply(g.context,v)}else{var T=g.length,D;for(E=0;E<T;E++)switch(g[E].once&&this.removeListener(u,g[E].fn,void 0,!0),_){case 1:g[E].fn.call(g[E].context);break;case 2:g[E].fn.call(g[E].context,c);break;case 3:g[E].fn.call(g[E].context,c,l);break;case 4:g[E].fn.call(g[E].context,c,l,f);break;default:if(!v)for(D=1,v=new Array(_-1);D<_;D++)v[D-1]=arguments[D];g[E].fn.apply(g[E].context,v)}}return!0},d.prototype.on=function(u,c,l){return s(this,u,c,l,!1)},d.prototype.once=function(u,c,l){return s(this,u,c,l,!0)},d.prototype.removeListener=function(u,c,l,f){var h=n?n+u:u;if(!this._events[h])return this;if(!c)return o(this,h),this;var p=this._events[h];if(p.fn)p.fn===c&&(!f||p.once)&&(!l||p.context===l)&&o(this,h);else{for(var m=0,g=[],_=p.length;m<_;m++)(p[m].fn!==c||f&&!p[m].once||l&&p[m].context!==l)&&g.push(p[m]);g.length?this._events[h]=g.length===1?g[0]:g:o(this,h)}return this},d.prototype.removeAllListeners=function(u){var c;return u?(c=n?n+u:u,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},d.prototype.off=d.prototype.removeListener,d.prototype.addListener=d.prototype.on,d.prefixed=n,d.EventEmitter=d,typeof e<"u"&&(e.exports=d)}),koe=Ft((t,e)=>{e.exports=typeof queueMicrotask=="function"?queueMicrotask:r=>Promise.resolve().then(r)}),Tx=Ft(t=>{"use strict";var e=koe();t.fromCallback=function(r,n){if(r===void 0){var i=new Promise(function(a,s){r=function(o,d){o?s(o):a(d)}});r[n!==void 0?n:"promise"]=i}else if(typeof r!="function")throw new TypeError("Callback must be a function");return r},t.fromPromise=function(r,n){if(n===void 0)return r;r.then(function(i){e(()=>n(null,i))}).catch(function(i){e(()=>n(i))})}}),FD=Ft(t=>{"use strict";t.getCallback=function(e,r){return typeof e=="function"?e:r},t.getOptions=function(e,r){return typeof e=="object"&&e!==null?e:r!==void 0?r:{}}}),Bf=Ft(t=>{"use strict";var{fromCallback:e}=Tx(),r=Rc(),{getOptions:n,getCallback:i}=FD(),a=Symbol("promise"),s=Symbol("callback"),o=Symbol("working"),d=Symbol("handleOne"),u=Symbol("handleMany"),c=Symbol("autoClose"),l=Symbol("finishWork"),f=Symbol("returnMany"),h=Symbol("closing"),p=Symbol("handleClose"),m=Symbol("closed"),g=Symbol("closeCallbacks"),_=Symbol("keyEncoding"),v=Symbol("valueEncoding"),E=Symbol("abortOnClose"),T=Symbol("legacy"),D=Symbol("keys"),R=Symbol("values"),N=Symbol("limit"),B=Symbol("count"),G=Object.freeze({}),z=()=>{},U=!1,H=class{constructor(P,x,S){if(typeof P!="object"||P===null){let A=P===null?"null":typeof P;throw new TypeError(`The first argument must be an abstract-level database, received ${A}`)}if(typeof x!="object"||x===null)throw new TypeError("The second argument must be an options object");this[m]=!1,this[g]=[],this[o]=!1,this[h]=!1,this[c]=!1,this[s]=null,this[d]=this[d].bind(this),this[u]=this[u].bind(this),this[p]=this[p].bind(this),this[_]=x[_],this[v]=x[v],this[T]=S,this[N]=Number.isInteger(x.limit)&&x.limit>=0?x.limit:1/0,this[B]=0,this[E]=!!x.abortOnClose,this.db=P,this.db.attachResource(this),this.nextTick=P.nextTick}get count(){return this[B]}get limit(){return this[N]}next(P){let x;if(P===void 0)x=new Promise((S,A)=>{P=(M,L,W)=>{M?A(M):this[T]?L===void 0&&W===void 0?S():S([L,W]):S(L)}});else if(typeof P!="function")throw new TypeError("Callback must be a function");return this[h]?this.nextTick(P,new r("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(P,new r("Iterator is busy: cannot call next() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[o]=!0,this[s]=P,this[B]>=this[N]?this.nextTick(this[d],null):this._next(this[d])),x}_next(P){this.nextTick(P)}nextv(P,x,S){return S=i(x,S),S=e(S,a),x=n(x,G),Number.isInteger(P)?(this[h]?this.nextTick(S,new r("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(S,new r("Iterator is busy: cannot call nextv() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(P<1&&(P=1),this[N]<1/0&&(P=Math.min(P,this[N]-this[B])),this[o]=!0,this[s]=S,P<=0?this.nextTick(this[u],null,[]):this._nextv(P,x,this[u])),S[a]):(this.nextTick(S,new TypeError("The first argument 'size' must be an integer")),S[a])}_nextv(P,x,S){let A=[],M=(L,W,V)=>{if(L)return S(L);if(this[T]?W===void 0&&V===void 0:W===void 0)return S(null,A);A.push(this[T]?[W,V]:W),A.length===P?S(null,A):this._next(M)};this._next(M)}all(P,x){return x=i(P,x),x=e(x,a),P=n(P,G),this[h]?this.nextTick(x,new r("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this[o]?this.nextTick(x,new r("Iterator is busy: cannot call all() until previous call has completed",{code:"LEVEL_ITERATOR_BUSY"})):(this[o]=!0,this[s]=x,this[c]=!0,this[B]>=this[N]?this.nextTick(this[u],null,[]):this._all(P,this[u])),x[a]}_all(P,x){let S=this[B],A=[],M=()=>{let W=this[N]<1/0?Math.min(1e3,this[N]-S):1e3;W<=0?this.nextTick(x,null,A):this._nextv(W,G,L)},L=(W,V)=>{W?x(W):V.length===0?x(null,A):(A.push.apply(A,V),S+=V.length,M())};M()}[l](){let P=this[s];return this[E]&&P===null?z:(this[o]=!1,this[s]=null,this[h]&&this._close(this[p]),P)}[f](P,x,S){this[c]?this.close(P.bind(null,x,S)):P(x,S)}seek(P,x){if(x=n(x,G),!this[h]){if(this[o])throw new r("Iterator is busy: cannot call seek() until next() has completed",{code:"LEVEL_ITERATOR_BUSY"});{let S=this.db.keyEncoding(x.keyEncoding||this[_]),A=S.format;x.keyEncoding!==A&&(x={...x,keyEncoding:A});let M=this.db.prefixKey(S.encode(P),A);this._seek(M,x)}}}_seek(P,x){throw new r("Iterator does not support seek()",{code:"LEVEL_NOT_SUPPORTED"})}close(P){return P=e(P,a),this[m]?this.nextTick(P):this[h]?this[g].push(P):(this[h]=!0,this[g].push(P),this[o]?this[E]&&this[l]()(new r("Aborted on iterator close()",{code:"LEVEL_ITERATOR_NOT_OPEN"})):this._close(this[p])),P[a]}_close(P){this.nextTick(P)}[p](){this[m]=!0,this.db.detachResource(this);let P=this[g];this[g]=[];for(let x of P)x()}async*[Symbol.asyncIterator](){try{let P;for(;(P=await this.next())!==void 0;)yield P}finally{this[m]||await this.close()}}},ee=class extends H{constructor(P,x){super(P,x,!0),this[D]=x.keys!==!1,this[R]=x.values!==!1}[d](P,x,S){let A=this[l]();if(P)return A(P);try{x=this[D]&&x!==void 0?this[_].decode(x):void 0,S=this[R]&&S!==void 0?this[v].decode(S):void 0}catch(M){return A(new b("entry",M))}x===void 0&&S===void 0||this[B]++,A(null,x,S)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A of x){let M=A[0],L=A[1];A[0]=this[D]&&M!==void 0?this[_].decode(M):void 0,A[1]=this[R]&&L!==void 0?this[v].decode(L):void 0}}catch(A){return this[f](S,new b("entries",A))}this[B]+=x.length,this[f](S,null,x)}end(P){return!U&&typeof console<"u"&&(U=!0,console.warn(new r("The iterator.end() method was renamed to close() and end() is an alias that will be removed in a future version",{code:"LEVEL_LEGACY"}))),this.close(P)}},I=class extends H{constructor(P,x){super(P,x,!1)}[d](P,x){let S=this[l]();if(P)return S(P);try{x=x!==void 0?this[_].decode(x):void 0}catch(A){return S(new b("key",A))}x!==void 0&&this[B]++,S(null,x)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A=0;A<x.length;A++){let M=x[A];x[A]=M!==void 0?this[_].decode(M):void 0}}catch(A){return this[f](S,new b("keys",A))}this[B]+=x.length,this[f](S,null,x)}},O=class extends H{constructor(P,x){super(P,x,!1)}[d](P,x){let S=this[l]();if(P)return S(P);try{x=x!==void 0?this[v].decode(x):void 0}catch(A){return S(new b("value",A))}x!==void 0&&this[B]++,S(null,x)}[u](P,x){let S=this[l]();if(P)return this[f](S,P);try{for(let A=0;A<x.length;A++){let M=x[A];x[A]=M!==void 0?this[v].decode(M):void 0}}catch(A){return this[f](S,new b("values",A))}this[B]+=x.length,this[f](S,null,x)}},b=class extends r{constructor(P,x){super(`Iterator could not decode ${P}`,{code:"LEVEL_DECODE_ERROR",cause:x})}};for(let P of["_ended property","_nexting property","_end method"])Object.defineProperty(ee.prototype,P.split(" ")[0],{get(){throw new r(`The ${P} has been removed`,{code:"LEVEL_LEGACY"})},set(){throw new r(`The ${P} has been removed`,{code:"LEVEL_LEGACY"})}});ee.keyEncoding=_,ee.valueEncoding=v,t.AbstractIterator=ee,t.AbstractKeyIterator=I,t.AbstractValueIterator=O}),Aoe=Ft(t=>{"use strict";var{AbstractKeyIterator:e,AbstractValueIterator:r}=Bf(),n=Symbol("iterator"),i=Symbol("callback"),a=Symbol("handleOne"),s=Symbol("handleMany"),o=class extends e{constructor(u,c){super(u,c),this[n]=u.iterator({...c,keys:!0,values:!1}),this[a]=this[a].bind(this),this[s]=this[s].bind(this)}},d=class extends r{constructor(u,c){super(u,c),this[n]=u.iterator({...c,keys:!1,values:!0}),this[a]=this[a].bind(this),this[s]=this[s].bind(this)}};for(let u of[o,d]){let c=u===o,l=c?f=>f[0]:f=>f[1];u.prototype._next=function(f){this[i]=f,this[n].next(this[a])},u.prototype[a]=function(f,h,p){let m=this[i];f?m(f):m(null,c?h:p)},u.prototype._nextv=function(f,h,p){this[i]=p,this[n].nextv(f,h,this[s])},u.prototype._all=function(f,h){this[i]=h,this[n].all(f,this[s])},u.prototype[s]=function(f,h){let p=this[i];f?p(f):p(null,h.map(l))},u.prototype._seek=function(f,h){this[n].seek(f,h)},u.prototype._close=function(f){this[n].close(f)}}t.DefaultKeyIterator=o,t.DefaultValueIterator=d}),Doe=Ft(t=>{"use strict";var{AbstractIterator:e,AbstractKeyIterator:r,AbstractValueIterator:n}=Bf(),i=Rc(),a=Symbol("nut"),s=Symbol("undefer"),o=Symbol("factory"),d=class extends e{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.iterator(f),this.db.defer(()=>this[s]())}},u=class extends r{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.keys(f),this.db.defer(()=>this[s]())}},c=class extends n{constructor(l,f){super(l,f),this[a]=null,this[o]=()=>l.values(f),this.db.defer(()=>this[s]())}};for(let l of[d,u,c])l.prototype[s]=function(){this.db.status==="open"&&(this[a]=this[o]())},l.prototype._next=function(f){this[a]!==null?this[a].next(f):this.db.status==="opening"?this.db.defer(()=>this._next(f)):this.nextTick(f,new i("Iterator is not open: cannot call next() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._nextv=function(f,h,p){this[a]!==null?this[a].nextv(f,h,p):this.db.status==="opening"?this.db.defer(()=>this._nextv(f,h,p)):this.nextTick(p,new i("Iterator is not open: cannot call nextv() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._all=function(f,h){this[a]!==null?this[a].all(h):this.db.status==="opening"?this.db.defer(()=>this._all(f,h)):this.nextTick(h,new i("Iterator is not open: cannot call all() after close()",{code:"LEVEL_ITERATOR_NOT_OPEN"}))},l.prototype._seek=function(f,h){this[a]!==null?this[a]._seek(f,h):this.db.status==="opening"&&this.db.defer(()=>this._seek(f,h))},l.prototype._close=function(f){this[a]!==null?this[a].close(f):this.db.status==="opening"?this.db.defer(()=>this._close(f)):this.nextTick(f)};t.DeferredIterator=d,t.DeferredKeyIterator=u,t.DeferredValueIterator=c}),pq=Ft(t=>{"use strict";var{fromCallback:e}=Tx(),r=Rc(),{getCallback:n,getOptions:i}=FD(),a=Symbol("promise"),s=Symbol("status"),o=Symbol("operations"),d=Symbol("finishClose"),u=Symbol("closeCallbacks"),c=class{constructor(l){if(typeof l!="object"||l===null){let f=l===null?"null":typeof l;throw new TypeError(`The first argument must be an abstract-level database, received ${f}`)}this[o]=[],this[u]=[],this[s]="open",this[d]=this[d].bind(this),this.db=l,this.db.attachResource(this),this.nextTick=l.nextTick}get length(){return this[o].length}put(l,f,h){if(this[s]!=="open")throw new r("Batch is not open: cannot call put() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let p=this.db._checkKey(l)||this.db._checkValue(f);if(p)throw p;let m=h&&h.sublevel!=null?h.sublevel:this.db,g=h,_=m.keyEncoding(h&&h.keyEncoding),v=m.valueEncoding(h&&h.valueEncoding),E=_.format;h={...h,keyEncoding:E,valueEncoding:v.format},m!==this.db&&(h.sublevel=null);let T=m.prefixKey(_.encode(l),E),D=v.encode(f);return this._put(T,D,h),this[o].push({...g,type:"put",key:l,value:f}),this}_put(l,f,h){}del(l,f){if(this[s]!=="open")throw new r("Batch is not open: cannot call del() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});let h=this.db._checkKey(l);if(h)throw h;let p=f&&f.sublevel!=null?f.sublevel:this.db,m=f,g=p.keyEncoding(f&&f.keyEncoding),_=g.format;return f={...f,keyEncoding:_},p!==this.db&&(f.sublevel=null),this._del(p.prefixKey(g.encode(l),_),f),this[o].push({...m,type:"del",key:l}),this}_del(l,f){}clear(){if(this[s]!=="open")throw new r("Batch is not open: cannot call clear() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"});return this._clear(),this[o]=[],this}_clear(){}write(l,f){return f=n(l,f),f=e(f,a),l=i(l),this[s]!=="open"?this.nextTick(f,new r("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"})):this.length===0?this.close(f):(this[s]="writing",this._write(l,h=>{this[s]="closing",this[u].push(()=>f(h)),h||this.db.emit("batch",this[o]),this._close(this[d])})),f[a]}_write(l,f){}close(l){return l=e(l,a),this[s]==="closing"?this[u].push(l):this[s]==="closed"?this.nextTick(l):(this[u].push(l),this[s]!=="writing"&&(this[s]="closing",this._close(this[d]))),l[a]}_close(l){this.nextTick(l)}[d](){this[s]="closed",this.db.detachResource(this);let l=this[u];this[u]=[];for(let f of l)f()}};t.AbstractChainedBatch=c}),Ioe=Ft(t=>{"use strict";var{AbstractChainedBatch:e}=pq(),r=Rc(),n=Symbol("encoded"),i=class extends e{constructor(a){super(a),this[n]=[]}_put(a,s,o){this[n].push({...o,type:"put",key:a,value:s})}_del(a,s){this[n].push({...s,type:"del",key:a})}_clear(){this[n]=[]}_write(a,s){this.db.status==="opening"?this.db.defer(()=>this._write(a,s)):this.db.status==="open"?this[n].length===0?this.nextTick(s):this.db._batch(this[n],a,s):this.nextTick(s,new r("Batch is not open: cannot call write() after write() or close()",{code:"LEVEL_BATCH_NOT_OPEN"}))}};t.DefaultChainedBatch=i}),Roe=Ft((t,e)=>{"use strict";var r=Rc(),n=Object.prototype.hasOwnProperty,i=new Set(["lt","lte","gt","gte"]);e.exports=function(a,s){let o={};for(let d in a)if(n.call(a,d)&&!(d==="keyEncoding"||d==="valueEncoding")){if(d==="start"||d==="end")throw new r(`The legacy range option '${d}' has been removed`,{code:"LEVEL_LEGACY"});if(d==="encoding")throw new r("The levelup-style 'encoding' alias has been removed, use 'valueEncoding' instead",{code:"LEVEL_LEGACY"});i.has(d)?o[d]=s.encode(a[d]):o[d]=a[d]}return o.reverse=!!o.reverse,o.limit=Number.isInteger(o.limit)&&o.limit>=0?o.limit:-1,o}}),hq=Ft((t,e)=>{var r;e.exports=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:globalThis):n=>(r||(r=Promise.resolve())).then(n).catch(i=>setTimeout(()=>{throw i},0))}),Coe=Ft((t,e)=>{"use strict";var r=hq();e.exports=function(n,...i){i.length===0?r(n):r(()=>n(...i))}}),$oe=Ft(t=>{"use strict";var{AbstractIterator:e,AbstractKeyIterator:r,AbstractValueIterator:n}=Bf(),i=Symbol("unfix"),a=Symbol("iterator"),s=Symbol("handleOne"),o=Symbol("handleMany"),d=Symbol("callback"),u=class extends e{constructor(f,h,p,m){super(f,h),this[a]=p,this[i]=m,this[s]=this[s].bind(this),this[o]=this[o].bind(this),this[d]=null}[s](f,h,p){let m=this[d];if(f)return m(f);h!==void 0&&(h=this[i](h)),m(f,h,p)}[o](f,h){let p=this[d];if(f)return p(f);for(let m of h){let g=m[0];g!==void 0&&(m[0]=this[i](g))}p(f,h)}},c=class extends r{constructor(f,h,p,m){super(f,h),this[a]=p,this[i]=m,this[s]=this[s].bind(this),this[o]=this[o].bind(this),this[d]=null}[s](f,h){let p=this[d];if(f)return p(f);h!==void 0&&(h=this[i](h)),p(f,h)}[o](f,h){let p=this[d];if(f)return p(f);for(let m=0;m<h.length;m++){let g=h[m];g!==void 0&&(h[m]=this[i](g))}p(f,h)}},l=class extends n{constructor(f,h,p){super(f,h),this[a]=p}};for(let f of[u,c])f.prototype._next=function(h){this[d]=h,this[a].next(this[s])},f.prototype._nextv=function(h,p,m){this[d]=m,this[a].nextv(h,p,this[o])},f.prototype._all=function(h,p){this[d]=p,this[a].all(h,this[o])};for(let f of[l])f.prototype._next=function(h){this[a].next(h)},f.prototype._nextv=function(h,p,m){this[a].nextv(h,p,m)},f.prototype._all=function(h,p){this[a].all(h,p)};for(let f of[u,c,l])f.prototype._seek=function(h,p){this[a].seek(h,p)},f.prototype._close=function(h){this[a].close(h)};t.AbstractSublevelIterator=u,t.AbstractSublevelKeyIterator=c,t.AbstractSublevelValueIterator=l}),Ooe=Ft((t,e)=>{"use strict";var r=Rc(),{Buffer:n}=zD()||{},{AbstractSublevelIterator:i,AbstractSublevelKeyIterator:a,AbstractSublevelValueIterator:s}=$oe(),o=Symbol("prefix"),d=Symbol("upperBound"),u=Symbol("prefixRange"),c=Symbol("parent"),l=Symbol("unfix"),f=new TextEncoder,h={separator:"!"};e.exports=function({AbstractLevel:E}){class T extends E{static defaults(R){if(typeof R=="string")throw new r("The subleveldown string shorthand for { separator } has been removed",{code:"LEVEL_LEGACY"});if(R&&R.open)throw new r("The subleveldown open option has been removed",{code:"LEVEL_LEGACY"});return R==null?h:R.separator?R:{...R,separator:"!"}}constructor(R,N,B){let{separator:G,manifest:z,...U}=T.defaults(B);N=v(N,G);let H=G.charCodeAt(0)+1,ee=R[c]||R;if(!f.encode(N).every(b=>b>H&&b<127))throw new r(`Prefix must use bytes > ${H} < 127`,{code:"LEVEL_INVALID_PREFIX"});super(p(ee,z),U);let I=(R.prefix||"")+G+N+G,O=I.slice(0,-1)+String.fromCharCode(H);this[c]=ee,this[o]=new g(I),this[d]=new g(O),this[l]=new _,this.nextTick=ee.nextTick}prefixKey(R,N){if(N==="utf8")return this[o].utf8+R;if(R.byteLength===0)return this[o][N];if(N==="view"){let B=this[o].view,G=new Uint8Array(B.byteLength+R.byteLength);return G.set(B,0),G.set(R,B.byteLength),G}else{let B=this[o].buffer;return n.concat([B,R],B.byteLength+R.byteLength)}}[u](R,N){R.gte!==void 0?R.gte=this.prefixKey(R.gte,N):R.gt!==void 0?R.gt=this.prefixKey(R.gt,N):R.gte=this[o][N],R.lte!==void 0?R.lte=this.prefixKey(R.lte,N):R.lt!==void 0?R.lt=this.prefixKey(R.lt,N):R.lte=this[d][N]}get prefix(){return this[o].utf8}get db(){return this[c]}_open(R,N){this[c].open({passive:!0},N)}_put(R,N,B,G){this[c].put(R,N,B,G)}_get(R,N,B){this[c].get(R,N,B)}_getMany(R,N,B){this[c].getMany(R,N,B)}_del(R,N,B){this[c].del(R,N,B)}_batch(R,N,B){this[c].batch(R,N,B)}_clear(R,N){this[u](R,R.keyEncoding),this[c].clear(R,N)}_iterator(R){this[u](R,R.keyEncoding);let N=this[c].iterator(R),B=this[l].get(this[o].utf8.length,R.keyEncoding);return new i(this,R,N,B)}_keys(R){this[u](R,R.keyEncoding);let N=this[c].keys(R),B=this[l].get(this[o].utf8.length,R.keyEncoding);return new a(this,R,N,B)}_values(R){this[u](R,R.keyEncoding);let N=this[c].values(R);return new s(this,R,N)}}return{AbstractSublevel:T}};var p=function(E,T){return{...E.supports,createIfMissing:!1,errorIfExists:!1,events:{},additionalMethods:{},...T,encodings:{utf8:m(E,"utf8"),buffer:m(E,"buffer"),view:m(E,"view")}}},m=function(E,T){return E.supports.encodings[T]?E.keyEncoding(T).name===T:!1},g=class{constructor(E){this.utf8=E,this.view=f.encode(E),this.buffer=n?n.from(this.view.buffer,0,this.view.byteLength):{}}},_=class{constructor(){this.cache=new Map}get(E,T){let D=this.cache.get(T);return D===void 0&&(T==="view"?D=(function(R,N){return N.subarray(R)}).bind(null,E):D=(function(R,N){return N.slice(R)}).bind(null,E),this.cache.set(T,D)),D}},v=function(E,T){let D=0,R=E.length;for(;D<R&&E[D]===T;)D++;for(;R>D&&E[R-1]===T;)R--;return E.slice(D,R)}}),HU=Ft(t=>{"use strict";var{supports:e}=xoe(),{Transcoder:r}=Soe(),{EventEmitter:n}=Toe(),{fromCallback:i}=Tx(),a=Rc(),{AbstractIterator:s}=Bf(),{DefaultKeyIterator:o,DefaultValueIterator:d}=Aoe(),{DeferredIterator:u,DeferredKeyIterator:c,DeferredValueIterator:l}=Doe(),{DefaultChainedBatch:f}=Ioe(),{getCallback:h,getOptions:p}=FD(),m=Roe(),g=Symbol("promise"),_=Symbol("landed"),v=Symbol("resources"),E=Symbol("closeResources"),T=Symbol("operations"),D=Symbol("undefer"),R=Symbol("deferOpen"),N=Symbol("options"),B=Symbol("status"),G=Symbol("defaultOptions"),z=Symbol("transcoder"),U=Symbol("keyEncoding"),H=Symbol("valueEncoding"),ee=()=>{},I=class extends n{constructor(x,S){if(super(),typeof x!="object"||x===null)throw new TypeError("The first argument 'manifest' must be an object");S=p(S);let{keyEncoding:A,valueEncoding:M,passive:L,...W}=S;this[v]=new Set,this[T]=[],this[R]=!0,this[N]=W,this[B]="opening",this.supports=e(x,{status:!0,promises:!0,clear:!0,getMany:!0,deferredOpen:!0,snapshots:x.snapshots!==!1,permanence:x.permanence!==!1,keyIterator:!0,valueIterator:!0,iteratorNextv:!0,iteratorAll:!0,encodings:x.encodings||{},events:Object.assign({},x.events,{opening:!0,open:!0,closing:!0,closed:!0,put:!0,del:!0,batch:!0,clear:!0})}),this[z]=new r(P(this)),this[U]=this[z].encoding(A||"utf8"),this[H]=this[z].encoding(M||"utf8");for(let V of this[z].encodings())this.supports.encodings[V.commonName]||(this.supports.encodings[V.commonName]=!0);this[G]={empty:Object.freeze({}),entry:Object.freeze({keyEncoding:this[U].commonName,valueEncoding:this[H].commonName}),key:Object.freeze({keyEncoding:this[U].commonName})},this.nextTick(()=>{this[R]&&this.open({passive:!1},ee)})}get status(){return this[B]}keyEncoding(x){return this[z].encoding(x??this[U])}valueEncoding(x){return this[z].encoding(x??this[H])}open(x,S){S=h(x,S),S=i(S,g),x={...this[N],...p(x)},x.createIfMissing=x.createIfMissing!==!1,x.errorIfExists=!!x.errorIfExists;let A=M=>{this[B]==="closing"||this[B]==="opening"?this.once(_,M?()=>A(M):A):this[B]!=="open"?S(new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN",cause:M})):S()};return x.passive?this[B]==="opening"?this.once(_,A):this.nextTick(A):this[B]==="closed"||this[R]?(this[R]=!1,this[B]="opening",this.emit("opening"),this._open(x,M=>{if(M){this[B]="closed",this[E](()=>{this.emit(_),A(M)}),this[D]();return}this[B]="open",this[D](),this.emit(_),this[B]==="open"&&this.emit("open"),this[B]==="open"&&this.emit("ready"),A()})):this[B]==="open"?this.nextTick(A):this.once(_,()=>this.open(x,S)),S[g]}_open(x,S){this.nextTick(S)}close(x){x=i(x,g);let S=A=>{this[B]==="opening"||this[B]==="closing"?this.once(_,A?S(A):S):this[B]!=="closed"?x(new a("Database is not closed",{code:"LEVEL_DATABASE_NOT_CLOSED",cause:A})):x()};if(this[B]==="open"){this[B]="closing",this.emit("closing");let A=M=>{this[B]="open",this[D](),this.emit(_),S(M)};this[E](()=>{this._close(M=>{if(M)return A(M);this[B]="closed",this[D](),this.emit(_),this[B]==="closed"&&this.emit("closed"),S()})})}else this[B]==="closed"?this.nextTick(S):this.once(_,()=>this.close(x));return x[g]}[E](x){if(this[v].size===0)return this.nextTick(x);let S=this[v].size,A=!0,M=()=>{--S===0&&(A?this.nextTick(x):x())};for(let L of this[v])L.close(M);A=!1,this[v].clear()}_close(x){this.nextTick(x)}get(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].entry),this[B]==="opening")return this.defer(()=>this.get(x,S,A)),A[g];if(b(this,A))return A[g];let M=this._checkKey(x);if(M)return this.nextTick(A,M),A[g];let L=this.keyEncoding(S.keyEncoding),W=this.valueEncoding(S.valueEncoding),V=L.format,J=W.format;return(S.keyEncoding!==V||S.valueEncoding!==J)&&(S=Object.assign({},S,{keyEncoding:V,valueEncoding:J})),this._get(this.prefixKey(L.encode(x),V),S,(Q,q)=>{if(Q)return(Q.code==="LEVEL_NOT_FOUND"||Q.notFound||/NotFound/i.test(Q))&&(Q.code||(Q.code="LEVEL_NOT_FOUND"),Q.notFound||(Q.notFound=!0),Q.status||(Q.status=404)),A(Q);try{q=W.decode(q)}catch(X){return A(new a("Could not decode value",{code:"LEVEL_DECODE_ERROR",cause:X}))}A(null,q)}),A[g]}_get(x,S,A){this.nextTick(A,new Error("NotFound"))}getMany(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].entry),this[B]==="opening")return this.defer(()=>this.getMany(x,S,A)),A[g];if(b(this,A))return A[g];if(!Array.isArray(x))return this.nextTick(A,new TypeError("The first argument 'keys' must be an array")),A[g];if(x.length===0)return this.nextTick(A,null,[]),A[g];let M=this.keyEncoding(S.keyEncoding),L=this.valueEncoding(S.valueEncoding),W=M.format,V=L.format;(S.keyEncoding!==W||S.valueEncoding!==V)&&(S=Object.assign({},S,{keyEncoding:W,valueEncoding:V}));let J=new Array(x.length);for(let Q=0;Q<x.length;Q++){let q=x[Q],X=this._checkKey(q);if(X)return this.nextTick(A,X),A[g];J[Q]=this.prefixKey(M.encode(q),W)}return this._getMany(J,S,(Q,q)=>{if(Q)return A(Q);try{for(let X=0;X<q.length;X++)q[X]!==void 0&&(q[X]=L.decode(q[X]))}catch(X){return A(new a(`Could not decode one or more of ${q.length} value(s)`,{code:"LEVEL_DECODE_ERROR",cause:X}))}A(null,q)}),A[g]}_getMany(x,S,A){this.nextTick(A,null,new Array(x.length).fill(void 0))}put(x,S,A,M){if(M=h(A,M),M=i(M,g),A=p(A,this[G].entry),this[B]==="opening")return this.defer(()=>this.put(x,S,A,M)),M[g];if(b(this,M))return M[g];let L=this._checkKey(x)||this._checkValue(S);if(L)return this.nextTick(M,L),M[g];let W=this.keyEncoding(A.keyEncoding),V=this.valueEncoding(A.valueEncoding),J=W.format,Q=V.format;(A.keyEncoding!==J||A.valueEncoding!==Q)&&(A=Object.assign({},A,{keyEncoding:J,valueEncoding:Q}));let q=this.prefixKey(W.encode(x),J),X=V.encode(S);return this._put(q,X,A,ne=>{if(ne)return M(ne);this.emit("put",x,S),M()}),M[g]}_put(x,S,A,M){this.nextTick(M)}del(x,S,A){if(A=h(S,A),A=i(A,g),S=p(S,this[G].key),this[B]==="opening")return this.defer(()=>this.del(x,S,A)),A[g];if(b(this,A))return A[g];let M=this._checkKey(x);if(M)return this.nextTick(A,M),A[g];let L=this.keyEncoding(S.keyEncoding),W=L.format;return S.keyEncoding!==W&&(S=Object.assign({},S,{keyEncoding:W})),this._del(this.prefixKey(L.encode(x),W),S,V=>{if(V)return A(V);this.emit("del",x),A()}),A[g]}_del(x,S,A){this.nextTick(A)}batch(x,S,A){if(!arguments.length){if(this[B]==="opening")return new f(this);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._chainedBatch()}if(typeof x=="function"?A=x:A=h(S,A),A=i(A,g),S=p(S,this[G].empty),this[B]==="opening")return this.defer(()=>this.batch(x,S,A)),A[g];if(b(this,A))return A[g];if(!Array.isArray(x))return this.nextTick(A,new TypeError("The first argument 'operations' must be an array")),A[g];if(x.length===0)return this.nextTick(A),A[g];let M=new Array(x.length),{keyEncoding:L,valueEncoding:W,...V}=S;for(let J=0;J<x.length;J++){if(typeof x[J]!="object"||x[J]===null)return this.nextTick(A,new TypeError("A batch operation must be an object")),A[g];let Q=Object.assign({},x[J]);if(Q.type!=="put"&&Q.type!=="del")return this.nextTick(A,new TypeError("A batch operation must have a type property that is 'put' or 'del'")),A[g];let q=this._checkKey(Q.key);if(q)return this.nextTick(A,q),A[g];let X=Q.sublevel!=null?Q.sublevel:this,ne=X.keyEncoding(Q.keyEncoding||L),re=ne.format;if(Q.key=X.prefixKey(ne.encode(Q.key),re),Q.keyEncoding=re,Q.type==="put"){let Y=this._checkValue(Q.value);if(Y)return this.nextTick(A,Y),A[g];let ce=X.valueEncoding(Q.valueEncoding||W);Q.value=ce.encode(Q.value),Q.valueEncoding=ce.format}X!==this&&(Q.sublevel=null),M[J]=Q}return this._batch(M,V,J=>{if(J)return A(J);this.emit("batch",x),A()}),A[g]}_batch(x,S,A){this.nextTick(A)}sublevel(x,S){return this._sublevel(x,O.defaults(S))}_sublevel(x,S){return new O(this,x,S)}prefixKey(x,S){return x}clear(x,S){if(S=h(x,S),S=i(S,g),x=p(x,this[G].empty),this[B]==="opening")return this.defer(()=>this.clear(x,S)),S[g];if(b(this,S))return S[g];let A=x,M=this.keyEncoding(x.keyEncoding);return x=m(x,M),x.keyEncoding=M.format,x.limit===0?this.nextTick(S):this._clear(x,L=>{if(L)return S(L);this.emit("clear",A),S()}),S[g]}_clear(x,S){this.nextTick(S)}iterator(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x.keys=x.keys!==!1,x.values=x.values!==!1,x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new u(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._iterator(x)}_iterator(x){return new s(this,x)}keys(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new c(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._keys(x)}_keys(x){return new o(this,x)}values(x){let S=this.keyEncoding(x&&x.keyEncoding),A=this.valueEncoding(x&&x.valueEncoding);if(x=m(x,S),x[s.keyEncoding]=S,x[s.valueEncoding]=A,x.keyEncoding=S.format,x.valueEncoding=A.format,this[B]==="opening")return new l(this,x);if(this[B]!=="open")throw new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"});return this._values(x)}_values(x){return new d(this,x)}defer(x){if(typeof x!="function")throw new TypeError("The first argument must be a function");this[T].push(x)}[D](){if(this[T].length===0)return;let x=this[T];this[T]=[];for(let S of x)S()}attachResource(x){if(typeof x!="object"||x===null||typeof x.close!="function")throw new TypeError("The first argument must be a resource object");this[v].add(x)}detachResource(x){this[v].delete(x)}_chainedBatch(){return new f(this)}_checkKey(x){if(x==null)return new a("Key cannot be null or undefined",{code:"LEVEL_INVALID_KEY"})}_checkValue(x){if(x==null)return new a("Value cannot be null or undefined",{code:"LEVEL_INVALID_VALUE"})}};I.prototype.nextTick=Coe();var{AbstractSublevel:O}=Ooe()({AbstractLevel:I});t.AbstractLevel=I,t.AbstractSublevel=O;var b=function(x,S){return x[B]!=="open"?(x.nextTick(S,new a("Database is not open",{code:"LEVEL_DATABASE_NOT_OPEN"})),!0):!1},P=function(x){return Object.keys(x.supports.encodings).filter(S=>!!x.supports.encodings[S])}}),mq=Ft(t=>{"use strict";t.AbstractLevel=HU().AbstractLevel,t.AbstractSublevel=HU().AbstractSublevel,t.AbstractIterator=Bf().AbstractIterator,t.AbstractKeyIterator=Bf().AbstractKeyIterator,t.AbstractValueIterator=Bf().AbstractValueIterator,t.AbstractChainedBatch=pq().AbstractChainedBatch}),Boe=Ft((t,e)=>{e.exports=n;var r=hq();function n(i,a,s){if(typeof a!="number")throw new Error("second argument must be a Number");let o,d,u,c,l,f=!0,h;Array.isArray(i)?(o=[],u=d=i.length):(c=Object.keys(i),o={},u=d=c.length);function p(g){function _(){s&&s(g,o),s=null}f?r(_):_()}function m(g,_,v){if(o[g]=v,_&&(l=!0),--u===0||_)p(_);else if(!l&&h<d){let E;c?(E=c[h],h+=1,i[E](function(T,D){m(E,T,D)})):(E=h,h+=1,i[E](function(T,D){m(E,T,D)}))}}h=a,u?c?c.some(function(g,_){return i[g](function(v,E){m(g,v,E)}),_===a-1}):i.some(function(g,_){return g(function(v,E){m(_,v,E)}),_===a-1}):p(null),f=!1}}),yq=Ft((t,e)=>{"use strict";e.exports=function(r){let n=r.gte!==void 0?r.gte:r.gt!==void 0?r.gt:void 0,i=r.lte!==void 0?r.lte:r.lt!==void 0?r.lt:void 0,a=r.gte===void 0,s=r.lte===void 0;return n!==void 0&&i!==void 0?IDBKeyRange.bound(n,i,a,s):n!==void 0?IDBKeyRange.lowerBound(n,a):i!==void 0?IDBKeyRange.upperBound(i,s):null}}),gq=Ft((t,e)=>{"use strict";var r=new TextEncoder;e.exports=function(n){return n instanceof Uint8Array?n:n instanceof ArrayBuffer?new Uint8Array(n):r.encode(n)}}),joe=Ft(t=>{"use strict";var{AbstractIterator:e}=mq(),r=yq(),n=gq(),i=Symbol("cache"),a=Symbol("finished"),s=Symbol("options"),o=Symbol("currentOptions"),d=Symbol("position"),u=Symbol("location"),c=Symbol("first"),l={},f=class extends e{constructor(p,m,g){super(p,g),this[i]=[],this[a]=this.limit===0,this[s]=g,this[o]={...g},this[d]=void 0,this[u]=m,this[c]=!0}_nextv(p,m,g){if(this[c]=!1,this[a])return this.nextTick(g,null,[]);if(this[i].length>0)return p=Math.min(p,this[i].length),this.nextTick(g,null,this[i].splice(0,p));this[d]!==void 0&&(this[s].reverse?(this[o].lt=this[d],this[o].lte=void 0):(this[o].gt=this[d],this[o].gte=void 0));let _;try{_=r(this[o])}catch{return this[a]=!0,this.nextTick(g,null,[])}let v=this.db.db.transaction([this[u]],"readonly"),E=v.objectStore(this[u]),T=[];if(this[s].reverse){let D=!this[s].values&&E.openKeyCursor?"openKeyCursor":"openCursor";E[D](_,"prev").onsuccess=R=>{let N=R.target.result;if(N){let{key:B,value:G}=N;this[d]=B,T.push([this[s].keys&&B!==void 0?n(B):void 0,this[s].values&&G!==void 0?n(G):void 0]),T.length<p?N.continue():h(v)}else this[a]=!0}}else{let D,R,N=()=>{if(D===void 0||R===void 0)return;let B=Math.max(D.length,R.length);B===0||p===1/0?this[a]=!0:this[d]=D[B-1],T.length=B;for(let G=0;G<B;G++){let z=D[G],U=R[G];T[G]=[this[s].keys&&z!==void 0?n(z):void 0,this[s].values&&U!==void 0?n(U):void 0]}h(v)};this[s].keys||p<1/0?E.getAllKeys(_,p<1/0?p:void 0).onsuccess=B=>{D=B.target.result,N()}:(D=[],this.nextTick(N)),this[s].values?E.getAll(_,p<1/0?p:void 0).onsuccess=B=>{R=B.target.result,N()}:(R=[],this.nextTick(N))}v.onabort=()=>{g(v.error||new Error("aborted by user")),g=null},v.oncomplete=()=>{g(null,T),g=null}}_next(p){if(this[i].length>0){let[m,g]=this[i].shift();this.nextTick(p,null,m,g)}else if(this[a])this.nextTick(p);else{let m=Math.min(100,this.limit-this.count);this[c]&&(this[c]=!1,m=1),this._nextv(m,l,(g,_)=>{if(g)return p(g);this[i]=_,this._next(p)})}}_all(p,m){this[c]=!1;let g=this[i].splice(0,this[i].length),_=this.limit-this.count-g.length;if(_<=0)return this.nextTick(m,null,g);this._nextv(_,l,(v,E)=>{if(v)return m(v);g.length>0&&(E=g.concat(E)),m(null,E)})}_seek(p,m){this[c]=!0,this[i]=[],this[a]=!1,this[d]=void 0,this[o]={...this[s]};let g;try{g=r(this[s])}catch{this[a]=!0;return}g!==null&&!g.includes(p)?this[a]=!0:this[s].reverse?this[o].lte=p:this[o].gte=p}};t.Iterator=f;function h(p){typeof p.commit=="function"&&p.commit()}}),Moe=Ft((t,e)=>{"use strict";e.exports=function(r,n,i,a,s){if(a.limit===0)return r.nextTick(s);let o=r.db.transaction([n],"readwrite"),d=o.objectStore(n),u=0;o.oncomplete=function(){s()},o.onabort=function(){s(o.error||new Error("aborted by user"))};let c=d.openKeyCursor?"openKeyCursor":"openCursor",l=a.reverse?"prev":"next";d[c](i,l).onsuccess=function(f){let h=f.target.result;h&&(d.delete(h.key).onsuccess=function(){(a.limit<=0||++u<a.limit)&&h.continue()})}}}),Noe=Ft(t=>{"use strict";var{AbstractLevel:e}=mq(),r=Rc(),n=Boe(),{fromCallback:i}=Tx(),{Iterator:a}=joe(),s=gq(),o=Moe(),d=yq(),u="level-js-",c=Symbol("idb"),l=Symbol("namePrefix"),f=Symbol("location"),h=Symbol("version"),p=Symbol("store"),m=Symbol("onComplete"),g=Symbol("promise"),_=class extends e{constructor(v,E,T){if(typeof E=="function"||typeof T=="function")throw new r("The levelup-style callback argument has been removed",{code:"LEVEL_LEGACY"});let{prefix:D,version:R,...N}=E||{};if(super({encodings:{view:!0},snapshots:!1,createIfMissing:!1,errorIfExists:!1,seek:!0},N),typeof v!="string")throw new Error("constructor requires a location string argument");this[f]=v,this[l]=D??u,this[h]=parseInt(R||1,10),this[c]=null}get location(){return this[f]}get namePrefix(){return this[l]}get version(){return this[h]}get db(){return this[c]}get type(){return"browser-level"}_open(v,E){let T=indexedDB.open(this[l]+this[f],this[h]);T.onerror=function(){E(T.error||new Error("unknown error"))},T.onsuccess=()=>{this[c]=T.result,E()},T.onupgradeneeded=D=>{let R=D.target.result;R.objectStoreNames.contains(this[f])||R.createObjectStore(this[f])}}[p](v){return this[c].transaction([this[f]],v).objectStore(this[f])}[m](v,E){let T=v.transaction;T.onabort=function(){E(T.error||new Error("aborted by user"))},T.oncomplete=function(){E(null,v.result)}}_get(v,E,T){let D=this[p]("readonly"),R;try{R=D.get(v)}catch(N){return this.nextTick(T,N)}this[m](R,function(N,B){if(N)return T(N);if(B===void 0)return T(new r("Entry not found",{code:"LEVEL_NOT_FOUND"}));T(null,s(B))})}_getMany(v,E,T){let D=this[p]("readonly"),R=v.map(N=>B=>{let G;try{G=D.get(N)}catch(z){return B(z)}G.onsuccess=()=>{let z=G.result;B(null,z===void 0?z:s(z))},G.onerror=z=>{z.stopPropagation(),B(G.error)}});n(R,16,T)}_del(v,E,T){let D=this[p]("readwrite"),R;try{R=D.delete(v)}catch(N){return this.nextTick(T,N)}this[m](R,T)}_put(v,E,T,D){let R=this[p]("readwrite"),N;try{N=R.put(E,v)}catch(B){return this.nextTick(D,B)}this[m](N,D)}_iterator(v){return new a(this,this[f],v)}_batch(v,E,T){let D=this[p]("readwrite"),R=D.transaction,N=0,B;R.onabort=function(){T(B||R.error||new Error("aborted by user"))},R.oncomplete=function(){T()};function G(){let z=v[N++],U=z.key,H;try{H=z.type==="del"?D.delete(U):D.put(z.value,U)}catch(ee){B=ee,R.abort();return}N<v.length?H.onsuccess=G:typeof R.commit=="function"&&R.commit()}G()}_clear(v,E){let T,D;try{T=d(v)}catch{return this.nextTick(E)}if(v.limit>=0)return o(this,this[f],T,v,E);try{let R=this[p]("readwrite");D=T?R.delete(T):R.clear()}catch(R){return this.nextTick(E,R)}this[m](D,E)}_close(v){this[c].close(),this.nextTick(v)}};_.destroy=function(v,E,T){typeof E=="function"&&(T=E,E=u),T=i(T,g);let D=indexedDB.deleteDatabase(E+v);return D.onsuccess=function(){T()},D.onerror=function(R){T(R)},T[g]},t.BrowserLevel=_}),wq=Ft(t=>{t.Level=Noe().BrowserLevel}),Uoe=Ft((t,e)=>{(function(r,n){typeof t=="object"&&typeof e<"u"?n(t):typeof define=="function"&&define.amd?define(["exports"],n):n(r.URI=r.URI||{})})(t,function(r){"use strict";function n(){for(var Z=arguments.length,ie=Array(Z),oe=0;oe<Z;oe++)ie[oe]=arguments[oe];if(ie.length>1){ie[0]=ie[0].slice(0,-1);for(var ye=ie.length-1,ve=1;ve<ye;++ve)ie[ve]=ie[ve].slice(1,-1);return ie[ye]=ie[ye].slice(1),ie.join("")}else return ie[0]}function i(Z){return"(?:"+Z+")"}function a(Z){return Z===void 0?"undefined":Z===null?"null":Object.prototype.toString.call(Z).split(" ").pop().split("]").shift().toLowerCase()}function s(Z){return Z.toUpperCase()}function o(Z){return Z!=null?Z instanceof Array?Z:typeof Z.length!="number"||Z.split||Z.setInterval||Z.call?[Z]:Array.prototype.slice.call(Z):[]}function d(Z,ie){var oe=Z;if(ie)for(var ye in ie)oe[ye]=ie[ye];return oe}function u(Z){var ie="[A-Za-z]",oe="[\\x0D]",ye="[0-9]",ve="[\\x22]",Fe=n(ye,"[A-Fa-f]"),Dt="[\\x0A]",ar="[\\x20]",Ur=i(i("%[EFef]"+Fe+"%"+Fe+Fe+"%"+Fe+Fe)+"|"+i("%[89A-Fa-f]"+Fe+"%"+Fe+Fe)+"|"+i("%"+Fe+Fe)),Kr="[\\:\\/\\?\\#\\[\\]\\@]",Xt="[\\!\\$\\&\\'\\(\\)\\*\\+\\,\\;\\=]",dn=n(Kr,Xt),Cn=Z?"[\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF]":"[]",en=Z?"[\\uE000-\\uF8FF]":"[]",gr=n(ie,ye,"[\\-\\.\\_\\~]",Cn),pr=i(ie+n(ie,ye,"[\\+\\-\\.]")+"*"),Ki=i(i(Ur+"|"+n(gr,Xt,"[\\:]"))+"*"),Cm=i(i("25[0-5]")+"|"+i("2[0-4]"+ye)+"|"+i("1"+ye+ye)+"|"+i("[1-9]"+ye)+"|"+ye),Ao=i(i("25[0-5]")+"|"+i("2[0-4]"+ye)+"|"+i("1"+ye+ye)+"|"+i("0?[1-9]"+ye)+"|0?0?"+ye),na=i(Ao+"\\."+Ao+"\\."+Ao+"\\."+Ao),wr=i(Fe+"{1,4}"),Ho=i(i(wr+"\\:"+wr)+"|"+na),Es=i(i(wr+"\\:")+"{6}"+Ho),Oc=i("\\:\\:"+i(wr+"\\:")+"{5}"+Ho),sl=i(i(wr)+"?\\:\\:"+i(wr+"\\:")+"{4}"+Ho),La=i(i(i(wr+"\\:")+"{0,1}"+wr)+"?\\:\\:"+i(wr+"\\:")+"{3}"+Ho),T0=i(i(i(wr+"\\:")+"{0,2}"+wr)+"?\\:\\:"+i(wr+"\\:")+"{2}"+Ho),k0=i(i(i(wr+"\\:")+"{0,3}"+wr)+"?\\:\\:"+wr+"\\:"+Ho),op=i(i(i(wr+"\\:")+"{0,4}"+wr)+"?\\:\\:"+Ho),sp=i(i(i(wr+"\\:")+"{0,5}"+wr)+"?\\:\\:"+wr),ap=i(i(i(wr+"\\:")+"{0,6}"+wr)+"?\\:\\:"),al=i([Es,Oc,sl,La,T0,k0,op,sp,ap].join("|")),cp=i(i(gr+"|"+Ur)+"+"),dp=i(al+"\\%25"+cp),I7=i(al+i("\\%25|\\%(?!"+Fe+"{2})")+cp),R7=i("[vV]"+Fe+"+\\."+n(gr,Xt,"[\\:]")+"+"),C7=i("\\["+i(I7+"|"+al+"|"+R7)+"\\]"),uR=i(i(Ur+"|"+n(gr,Xt))+"*"),$m=i(C7+"|"+na+"(?!"+uR+")|"+uR),Om=i(ye+"*"),lR=i(i(Ki+"@")+"?"+$m+i("\\:"+Om)+"?"),Bm=i(Ur+"|"+n(gr,Xt,"[\\:\\@]")),$7=i(Bm+"*"),fR=i(Bm+"+"),O7=i(i(Ur+"|"+n(gr,Xt,"[\\@]"))+"+"),Bc=i(i("\\/"+$7)+"*"),up=i("\\/"+i(fR+Bc)+"?"),IP=i(O7+Bc),A0=i(fR+Bc),lp="(?!"+Bm+")",Ape=i(Bc+"|"+up+"|"+IP+"|"+A0+"|"+lp),fp=i(i(Bm+"|"+n("[\\/\\?]",en))+"*"),jm=i(i(Bm+"|[\\/\\?]")+"*"),pR=i(i("\\/\\/"+lR+Bc)+"|"+up+"|"+A0+"|"+lp),B7=i(pr+"\\:"+pR+i("\\?"+fp)+"?"+i("\\#"+jm)+"?"),j7=i(i("\\/\\/"+lR+Bc)+"|"+up+"|"+IP+"|"+lp),M7=i(j7+i("\\?"+fp)+"?"+i("\\#"+jm)+"?"),Dpe=i(B7+"|"+M7),Ipe=i(pr+"\\:"+pR+i("\\?"+fp)+"?"),Rpe="^("+pr+")\\:"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+A0+"|"+lp+")")+i("\\?("+fp+")")+"?"+i("\\#("+jm+")")+"?$",Cpe="^(){0}"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+IP+"|"+lp+")")+i("\\?("+fp+")")+"?"+i("\\#("+jm+")")+"?$",$pe="^("+pr+")\\:"+i(i("\\/\\/("+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?)")+"?("+Bc+"|"+up+"|"+A0+"|"+lp+")")+i("\\?("+fp+")")+"?$",Ope="^"+i("\\#("+jm+")")+"?$",Bpe="^"+i("("+Ki+")@")+"?("+$m+")"+i("\\:("+Om+")")+"?$";return{NOT_SCHEME:new RegExp(n("[^]",ie,ye,"[\\+\\-\\.]"),"g"),NOT_USERINFO:new RegExp(n("[^\\%\\:]",gr,Xt),"g"),NOT_HOST:new RegExp(n("[^\\%\\[\\]\\:]",gr,Xt),"g"),NOT_PATH:new RegExp(n("[^\\%\\/\\:\\@]",gr,Xt),"g"),NOT_PATH_NOSCHEME:new RegExp(n("[^\\%\\/\\@]",gr,Xt),"g"),NOT_QUERY:new RegExp(n("[^\\%]",gr,Xt,"[\\:\\@\\/\\?]",en),"g"),NOT_FRAGMENT:new RegExp(n("[^\\%]",gr,Xt,"[\\:\\@\\/\\?]"),"g"),ESCAPE:new RegExp(n("[^]",gr,Xt),"g"),UNRESERVED:new RegExp(gr,"g"),OTHER_CHARS:new RegExp(n("[^\\%]",gr,dn),"g"),PCT_ENCODED:new RegExp(Ur,"g"),IPV4ADDRESS:new RegExp("^("+na+")$"),IPV6ADDRESS:new RegExp("^\\[?("+al+")"+i(i("\\%25|\\%(?!"+Fe+"{2})")+"("+cp+")")+"?\\]?$")}}var c=u(!1),l=u(!0),f=function(){function Z(ie,oe){var ye=[],ve=!0,Fe=!1,Dt=void 0;try{for(var ar=ie[Symbol.iterator](),Ur;!(ve=(Ur=ar.next()).done)&&(ye.push(Ur.value),!(oe&&ye.length===oe));ve=!0);}catch(Kr){Fe=!0,Dt=Kr}finally{try{!ve&&ar.return&&ar.return()}finally{if(Fe)throw Dt}}return ye}return function(ie,oe){if(Array.isArray(ie))return ie;if(Symbol.iterator in Object(ie))return Z(ie,oe);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),h=function(Z){if(Array.isArray(Z)){for(var ie=0,oe=Array(Z.length);ie<Z.length;ie++)oe[ie]=Z[ie];return oe}else return Array.from(Z)},p=2147483647,m=36,g=1,_=26,v=38,E=700,T=72,D=128,R="-",N=/^xn--/,B=/[^\0-\x7E]/,G=/[\x2E\u3002\uFF0E\uFF61]/g,z={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},U=m-g,H=Math.floor,ee=String.fromCharCode;function I(Z){throw new RangeError(z[Z])}function O(Z,ie){for(var oe=[],ye=Z.length;ye--;)oe[ye]=ie(Z[ye]);return oe}function b(Z,ie){var oe=Z.split("@"),ye="";oe.length>1&&(ye=oe[0]+"@",Z=oe[1]),Z=Z.replace(G,".");var ve=Z.split("."),Fe=O(ve,ie).join(".");return ye+Fe}function P(Z){for(var ie=[],oe=0,ye=Z.length;oe<ye;){var ve=Z.charCodeAt(oe++);if(ve>=55296&&ve<=56319&&oe<ye){var Fe=Z.charCodeAt(oe++);(Fe&64512)==56320?ie.push(((ve&1023)<<10)+(Fe&1023)+65536):(ie.push(ve),oe--)}else ie.push(ve)}return ie}var x=function(Z){return String.fromCodePoint.apply(String,h(Z))},S=function(Z){return Z-48<10?Z-22:Z-65<26?Z-65:Z-97<26?Z-97:m},A=function(Z,ie){return Z+22+75*(Z<26)-((ie!=0)<<5)},M=function(Z,ie,oe){var ye=0;for(Z=oe?H(Z/E):Z>>1,Z+=H(Z/ie);Z>U*_>>1;ye+=m)Z=H(Z/U);return H(ye+(U+1)*Z/(Z+v))},L=function(Z){var ie=[],oe=Z.length,ye=0,ve=D,Fe=T,Dt=Z.lastIndexOf(R);Dt<0&&(Dt=0);for(var ar=0;ar<Dt;++ar)Z.charCodeAt(ar)>=128&&I("not-basic"),ie.push(Z.charCodeAt(ar));for(var Ur=Dt>0?Dt+1:0;Ur<oe;){for(var Kr=ye,Xt=1,dn=m;;dn+=m){Ur>=oe&&I("invalid-input");var Cn=S(Z.charCodeAt(Ur++));(Cn>=m||Cn>H((p-ye)/Xt))&&I("overflow"),ye+=Cn*Xt;var en=dn<=Fe?g:dn>=Fe+_?_:dn-Fe;if(Cn<en)break;var gr=m-en;Xt>H(p/gr)&&I("overflow"),Xt*=gr}var pr=ie.length+1;Fe=M(ye-Kr,pr,Kr==0),H(ye/pr)>p-ve&&I("overflow"),ve+=H(ye/pr),ye%=pr,ie.splice(ye++,0,ve)}return String.fromCodePoint.apply(String,ie)},W=function(Z){var ie=[];Z=P(Z);var oe=Z.length,ye=D,ve=0,Fe=T,Dt=!0,ar=!1,Ur=void 0;try{for(var Kr=Z[Symbol.iterator](),Xt;!(Dt=(Xt=Kr.next()).done);Dt=!0){var dn=Xt.value;dn<128&&ie.push(ee(dn))}}catch(dp){ar=!0,Ur=dp}finally{try{!Dt&&Kr.return&&Kr.return()}finally{if(ar)throw Ur}}var Cn=ie.length,en=Cn;for(Cn&&ie.push(R);en<oe;){var gr=p,pr=!0,Ki=!1,Cm=void 0;try{for(var Ao=Z[Symbol.iterator](),na;!(pr=(na=Ao.next()).done);pr=!0){var wr=na.value;wr>=ye&&wr<gr&&(gr=wr)}}catch(dp){Ki=!0,Cm=dp}finally{try{!pr&&Ao.return&&Ao.return()}finally{if(Ki)throw Cm}}var Ho=en+1;gr-ye>H((p-ve)/Ho)&&I("overflow"),ve+=(gr-ye)*Ho,ye=gr;var Es=!0,Oc=!1,sl=void 0;try{for(var La=Z[Symbol.iterator](),T0;!(Es=(T0=La.next()).done);Es=!0){var k0=T0.value;if(k0<ye&&++ve>p&&I("overflow"),k0==ye){for(var op=ve,sp=m;;sp+=m){var ap=sp<=Fe?g:sp>=Fe+_?_:sp-Fe;if(op<ap)break;var al=op-ap,cp=m-ap;ie.push(ee(A(ap+al%cp,0))),op=H(al/cp)}ie.push(ee(A(op,0))),Fe=M(ve,Ho,en==Cn),ve=0,++en}}}catch(dp){Oc=!0,sl=dp}finally{try{!Es&&La.return&&La.return()}finally{if(Oc)throw sl}}++ve,++ye}return ie.join("")},V=function(Z){return b(Z,function(ie){return N.test(ie)?L(ie.slice(4).toLowerCase()):ie})},J=function(Z){return b(Z,function(ie){return B.test(ie)?"xn--"+W(ie):ie})},Q={version:"2.1.0",ucs2:{decode:P,encode:x},decode:L,encode:W,toASCII:J,toUnicode:V},q={};function X(Z){var ie=Z.charCodeAt(0),oe=void 0;return ie<16?oe="%0"+ie.toString(16).toUpperCase():ie<128?oe="%"+ie.toString(16).toUpperCase():ie<2048?oe="%"+(ie>>6|192).toString(16).toUpperCase()+"%"+(ie&63|128).toString(16).toUpperCase():oe="%"+(ie>>12|224).toString(16).toUpperCase()+"%"+(ie>>6&63|128).toString(16).toUpperCase()+"%"+(ie&63|128).toString(16).toUpperCase(),oe}function ne(Z){for(var ie="",oe=0,ye=Z.length;oe<ye;){var ve=parseInt(Z.substr(oe+1,2),16);if(ve<128)ie+=String.fromCharCode(ve),oe+=3;else if(ve>=194&&ve<224){if(ye-oe>=6){var Fe=parseInt(Z.substr(oe+4,2),16);ie+=String.fromCharCode((ve&31)<<6|Fe&63)}else ie+=Z.substr(oe,6);oe+=6}else if(ve>=224){if(ye-oe>=9){var Dt=parseInt(Z.substr(oe+4,2),16),ar=parseInt(Z.substr(oe+7,2),16);ie+=String.fromCharCode((ve&15)<<12|(Dt&63)<<6|ar&63)}else ie+=Z.substr(oe,9);oe+=9}else ie+=Z.substr(oe,3),oe+=3}return ie}function re(Z,ie){function oe(ye){var ve=ne(ye);return ve.match(ie.UNRESERVED)?ve:ye}return Z.scheme&&(Z.scheme=String(Z.scheme).replace(ie.PCT_ENCODED,oe).toLowerCase().replace(ie.NOT_SCHEME,"")),Z.userinfo!==void 0&&(Z.userinfo=String(Z.userinfo).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_USERINFO,X).replace(ie.PCT_ENCODED,s)),Z.host!==void 0&&(Z.host=String(Z.host).replace(ie.PCT_ENCODED,oe).toLowerCase().replace(ie.NOT_HOST,X).replace(ie.PCT_ENCODED,s)),Z.path!==void 0&&(Z.path=String(Z.path).replace(ie.PCT_ENCODED,oe).replace(Z.scheme?ie.NOT_PATH:ie.NOT_PATH_NOSCHEME,X).replace(ie.PCT_ENCODED,s)),Z.query!==void 0&&(Z.query=String(Z.query).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_QUERY,X).replace(ie.PCT_ENCODED,s)),Z.fragment!==void 0&&(Z.fragment=String(Z.fragment).replace(ie.PCT_ENCODED,oe).replace(ie.NOT_FRAGMENT,X).replace(ie.PCT_ENCODED,s)),Z}function Y(Z){return Z.replace(/^0*(.*)/,"$1")||"0"}function ce(Z,ie){var oe=Z.match(ie.IPV4ADDRESS)||[],ye=f(oe,2),ve=ye[1];return ve?ve.split(".").map(Y).join("."):Z}function de(Z,ie){var oe=Z.match(ie.IPV6ADDRESS)||[],ye=f(oe,3),ve=ye[1],Fe=ye[2];if(ve){for(var Dt=ve.toLowerCase().split("::").reverse(),ar=f(Dt,2),Ur=ar[0],Kr=ar[1],Xt=Kr?Kr.split(":").map(Y):[],dn=Ur.split(":").map(Y),Cn=ie.IPV4ADDRESS.test(dn[dn.length-1]),en=Cn?7:8,gr=dn.length-en,pr=Array(en),Ki=0;Ki<en;++Ki)pr[Ki]=Xt[Ki]||dn[gr+Ki]||"";Cn&&(pr[en-1]=ce(pr[en-1],ie));var Cm=pr.reduce(function(Es,Oc,sl){if(!Oc||Oc==="0"){var La=Es[Es.length-1];La&&La.index+La.length===sl?La.length++:Es.push({index:sl,length:1})}return Es},[]),Ao=Cm.sort(function(Es,Oc){return Oc.length-Es.length})[0],na=void 0;if(Ao&&Ao.length>1){var wr=pr.slice(0,Ao.index),Ho=pr.slice(Ao.index+Ao.length);na=wr.join(":")+"::"+Ho.join(":")}else na=pr.join(":");return Fe&&(na+="%"+Fe),na}else return Z}var pe=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,we="".match(/(){0}/)[1]===void 0;function ae(Z){var ie=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},oe={},ye=ie.iri!==!1?l:c;ie.reference==="suffix"&&(Z=(ie.scheme?ie.scheme+":":"")+"//"+Z);var ve=Z.match(pe);if(ve){we?(oe.scheme=ve[1],oe.userinfo=ve[3],oe.host=ve[4],oe.port=parseInt(ve[5],10),oe.path=ve[6]||"",oe.query=ve[7],oe.fragment=ve[8],isNaN(oe.port)&&(oe.port=ve[5])):(oe.scheme=ve[1]||void 0,oe.userinfo=Z.indexOf("@")!==-1?ve[3]:void 0,oe.host=Z.indexOf("//")!==-1?ve[4]:void 0,oe.port=parseInt(ve[5],10),oe.path=ve[6]||"",oe.query=Z.indexOf("?")!==-1?ve[7]:void 0,oe.fragment=Z.indexOf("#")!==-1?ve[8]:void 0,isNaN(oe.port)&&(oe.port=Z.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?ve[4]:void 0)),oe.host&&(oe.host=de(ce(oe.host,ye),ye)),oe.scheme===void 0&&oe.userinfo===void 0&&oe.host===void 0&&oe.port===void 0&&!oe.path&&oe.query===void 0?oe.reference="same-document":oe.scheme===void 0?oe.reference="relative":oe.fragment===void 0?oe.reference="absolute":oe.reference="uri",ie.reference&&ie.reference!=="suffix"&&ie.reference!==oe.reference&&(oe.error=oe.error||"URI is not a "+ie.reference+" reference.");var Fe=q[(ie.scheme||oe.scheme||"").toLowerCase()];if(!ie.unicodeSupport&&(!Fe||!Fe.unicodeSupport)){if(oe.host&&(ie.domainHost||Fe&&Fe.domainHost))try{oe.host=Q.toASCII(oe.host.replace(ye.PCT_ENCODED,ne).toLowerCase())}catch(Dt){oe.error=oe.error||"Host's domain name can not be converted to ASCII via punycode: "+Dt}re(oe,c)}else re(oe,ye);Fe&&Fe.parse&&Fe.parse(oe,ie)}else oe.error=oe.error||"URI can not be parsed.";return oe}function ge(Z,ie){var oe=ie.iri!==!1?l:c,ye=[];return Z.userinfo!==void 0&&(ye.push(Z.userinfo),ye.push("@")),Z.host!==void 0&&ye.push(de(ce(String(Z.host),oe),oe).replace(oe.IPV6ADDRESS,function(ve,Fe,Dt){return"["+Fe+(Dt?"%25"+Dt:"")+"]"})),(typeof Z.port=="number"||typeof Z.port=="string")&&(ye.push(":"),ye.push(String(Z.port))),ye.length?ye.join(""):void 0}var Be=/^\.\.?\//,qe=/^\/\.(\/|$)/,We=/^\/\.\.(\/|$)/,Pt=/^\/?(?:.|\n)*?(?=\/|$)/;function Pe(Z){for(var ie=[];Z.length;)if(Z.match(Be))Z=Z.replace(Be,"");else if(Z.match(qe))Z=Z.replace(qe,"/");else if(Z.match(We))Z=Z.replace(We,"/"),ie.pop();else if(Z==="."||Z==="..")Z="";else{var oe=Z.match(Pt);if(oe){var ye=oe[0];Z=Z.slice(ye.length),ie.push(ye)}else throw new Error("Unexpected dot segment condition")}return ie.join("")}function nt(Z){var ie=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},oe=ie.iri?l:c,ye=[],ve=q[(ie.scheme||Z.scheme||"").toLowerCase()];if(ve&&ve.serialize&&ve.serialize(Z,ie),Z.host&&!oe.IPV6ADDRESS.test(Z.host)&&(ie.domainHost||ve&&ve.domainHost))try{Z.host=ie.iri?Q.toUnicode(Z.host):Q.toASCII(Z.host.replace(oe.PCT_ENCODED,ne).toLowerCase())}catch(ar){Z.error=Z.error||"Host's domain name can not be converted to "+(ie.iri?"Unicode":"ASCII")+" via punycode: "+ar}re(Z,oe),ie.reference!=="suffix"&&Z.scheme&&(ye.push(Z.scheme),ye.push(":"));var Fe=ge(Z,ie);if(Fe!==void 0&&(ie.reference!=="suffix"&&ye.push("//"),ye.push(Fe),Z.path&&Z.path.charAt(0)!=="/"&&ye.push("/")),Z.path!==void 0){var Dt=Z.path;!ie.absolutePath&&(!ve||!ve.absolutePath)&&(Dt=Pe(Dt)),Fe===void 0&&(Dt=Dt.replace(/^\/\//,"/%2F")),ye.push(Dt)}return Z.query!==void 0&&(ye.push("?"),ye.push(Z.query)),Z.fragment!==void 0&&(ye.push("#"),ye.push(Z.fragment)),ye.join("")}function wt(Z,ie){var oe=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ye=arguments[3],ve={};return ye||(Z=ae(nt(Z,oe),oe),ie=ae(nt(ie,oe),oe)),oe=oe||{},!oe.tolerant&&ie.scheme?(ve.scheme=ie.scheme,ve.userinfo=ie.userinfo,ve.host=ie.host,ve.port=ie.port,ve.path=Pe(ie.path||""),ve.query=ie.query):(ie.userinfo!==void 0||ie.host!==void 0||ie.port!==void 0?(ve.userinfo=ie.userinfo,ve.host=ie.host,ve.port=ie.port,ve.path=Pe(ie.path||""),ve.query=ie.query):(ie.path?(ie.path.charAt(0)==="/"?ve.path=Pe(ie.path):((Z.userinfo!==void 0||Z.host!==void 0||Z.port!==void 0)&&!Z.path?ve.path="/"+ie.path:Z.path?ve.path=Z.path.slice(0,Z.path.lastIndexOf("/")+1)+ie.path:ve.path=ie.path,ve.path=Pe(ve.path)),ve.query=ie.query):(ve.path=Z.path,ie.query!==void 0?ve.query=ie.query:ve.query=Z.query),ve.userinfo=Z.userinfo,ve.host=Z.host,ve.port=Z.port),ve.scheme=Z.scheme),ve.fragment=ie.fragment,ve}function xt(Z,ie,oe){var ye=d({scheme:"null"},oe);return nt(wt(ae(Z,ye),ae(ie,ye),ye,!0),ye)}function Ot(Z,ie){return typeof Z=="string"?Z=nt(ae(Z,ie),ie):a(Z)==="object"&&(Z=ae(nt(Z,ie),ie)),Z}function k(Z,ie,oe){return typeof Z=="string"?Z=nt(ae(Z,oe),oe):a(Z)==="object"&&(Z=nt(Z,oe)),typeof ie=="string"?ie=nt(ae(ie,oe),oe):a(ie)==="object"&&(ie=nt(ie,oe)),Z===ie}function j(Z,ie){return Z&&Z.toString().replace(!ie||!ie.iri?c.ESCAPE:l.ESCAPE,X)}function K(Z,ie){return Z&&Z.toString().replace(!ie||!ie.iri?c.PCT_ENCODED:l.PCT_ENCODED,ne)}var te={scheme:"http",domainHost:!0,parse:function(Z,ie){return Z.host||(Z.error=Z.error||"HTTP URIs must have a host."),Z},serialize:function(Z,ie){var oe=String(Z.scheme).toLowerCase()==="https";return(Z.port===(oe?443:80)||Z.port==="")&&(Z.port=void 0),Z.path||(Z.path="/"),Z}},se={scheme:"https",domainHost:te.domainHost,parse:te.parse,serialize:te.serialize};function he(Z){return typeof Z.secure=="boolean"?Z.secure:String(Z.scheme).toLowerCase()==="wss"}var xe={scheme:"ws",domainHost:!0,parse:function(Z,ie){var oe=Z;return oe.secure=he(oe),oe.resourceName=(oe.path||"/")+(oe.query?"?"+oe.query:""),oe.path=void 0,oe.query=void 0,oe},serialize:function(Z,ie){if((Z.port===(he(Z)?443:80)||Z.port==="")&&(Z.port=void 0),typeof Z.secure=="boolean"&&(Z.scheme=Z.secure?"wss":"ws",Z.secure=void 0),Z.resourceName){var oe=Z.resourceName.split("?"),ye=f(oe,2),ve=ye[0],Fe=ye[1];Z.path=ve&&ve!=="/"?ve:void 0,Z.query=Fe,Z.resourceName=void 0}return Z.fragment=void 0,Z}},Bt={scheme:"wss",domainHost:xe.domainHost,parse:xe.parse,serialize:xe.serialize},Mn={},$r=!0,fr="[A-Za-z0-9\\-\\.\\_\\~"+($r?"\\xA0-\\u200D\\u2010-\\u2029\\u202F-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFEF":"")+"]",nr="[0-9A-Fa-f]",b7=i(i("%[EFef]"+nr+"%"+nr+nr+"%"+nr+nr)+"|"+i("%[89A-Fa-f]"+nr+"%"+nr+nr)+"|"+i("%"+nr+nr)),x7="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",P7="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_7=n(P7,'[\\"\\\\]'),E7="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",S7=new RegExp(fr,"g"),ip=new RegExp(b7,"g"),T7=new RegExp(n("[^]",x7,"[\\.]",'[\\"]',_7),"g"),sR=new RegExp(n("[^]",fr,E7),"g"),k7=sR;function DP(Z){var ie=ne(Z);return ie.match(S7)?ie:Z}var aR={scheme:"mailto",parse:function(Z,ie){var oe=Z,ye=oe.to=oe.path?oe.path.split(","):[];if(oe.path=void 0,oe.query){for(var ve=!1,Fe={},Dt=oe.query.split("&"),ar=0,Ur=Dt.length;ar<Ur;++ar){var Kr=Dt[ar].split("=");switch(Kr[0]){case"to":for(var Xt=Kr[1].split(","),dn=0,Cn=Xt.length;dn<Cn;++dn)ye.push(Xt[dn]);break;case"subject":oe.subject=K(Kr[1],ie);break;case"body":oe.body=K(Kr[1],ie);break;default:ve=!0,Fe[K(Kr[0],ie)]=K(Kr[1],ie);break}}ve&&(oe.headers=Fe)}oe.query=void 0;for(var en=0,gr=ye.length;en<gr;++en){var pr=ye[en].split("@");if(pr[0]=K(pr[0]),ie.unicodeSupport)pr[1]=K(pr[1],ie).toLowerCase();else try{pr[1]=Q.toASCII(K(pr[1],ie).toLowerCase())}catch(Ki){oe.error=oe.error||"Email address's domain name can not be converted to ASCII via punycode: "+Ki}ye[en]=pr.join("@")}return oe},serialize:function(Z,ie){var oe=Z,ye=o(Z.to);if(ye){for(var ve=0,Fe=ye.length;ve<Fe;++ve){var Dt=String(ye[ve]),ar=Dt.lastIndexOf("@"),Ur=Dt.slice(0,ar).replace(ip,DP).replace(ip,s).replace(T7,X),Kr=Dt.slice(ar+1);try{Kr=ie.iri?Q.toUnicode(Kr):Q.toASCII(K(Kr,ie).toLowerCase())}catch(en){oe.error=oe.error||"Email address's domain name can not be converted to "+(ie.iri?"Unicode":"ASCII")+" via punycode: "+en}ye[ve]=Ur+"@"+Kr}oe.path=ye.join(",")}var Xt=Z.headers=Z.headers||{};Z.subject&&(Xt.subject=Z.subject),Z.body&&(Xt.body=Z.body);var dn=[];for(var Cn in Xt)Xt[Cn]!==Mn[Cn]&&dn.push(Cn.replace(ip,DP).replace(ip,s).replace(sR,X)+"="+Xt[Cn].replace(ip,DP).replace(ip,s).replace(k7,X));return dn.length&&(oe.query=dn.join("&")),oe}},A7=/^([^\:]+)\:(.*)/,cR={scheme:"urn",parse:function(Z,ie){var oe=Z.path&&Z.path.match(A7),ye=Z;if(oe){var ve=ie.scheme||ye.scheme||"urn",Fe=oe[1].toLowerCase(),Dt=oe[2],ar=ve+":"+(ie.nid||Fe),Ur=q[ar];ye.nid=Fe,ye.nss=Dt,ye.path=void 0,Ur&&(ye=Ur.parse(ye,ie))}else ye.error=ye.error||"URN can not be parsed.";return ye},serialize:function(Z,ie){var oe=ie.scheme||Z.scheme||"urn",ye=Z.nid,ve=oe+":"+(ie.nid||ye),Fe=q[ve];Fe&&(Z=Fe.serialize(Z,ie));var Dt=Z,ar=Z.nss;return Dt.path=(ye||ie.nid)+":"+ar,Dt}},D7=/^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/,dR={scheme:"urn:uuid",parse:function(Z,ie){var oe=Z;return oe.uuid=oe.nss,oe.nss=void 0,!ie.tolerant&&(!oe.uuid||!oe.uuid.match(D7))&&(oe.error=oe.error||"UUID is not valid."),oe},serialize:function(Z,ie){var oe=Z;return oe.nss=(Z.uuid||"").toLowerCase(),oe}};q[te.scheme]=te,q[se.scheme]=se,q[xe.scheme]=xe,q[Bt.scheme]=Bt,q[aR.scheme]=aR,q[cR.scheme]=cR,q[dR.scheme]=dR,r.SCHEMES=q,r.pctEncChar=X,r.pctDecChars=ne,r.parse=ae,r.removeDotSegments=Pe,r.serialize=nt,r.resolveComponents=wt,r.resolve=xt,r.normalize=Ot,r.equal=k,r.escapeComponent=j,r.unescapeComponent=K,Object.defineProperty(r,"__esModule",{value:!0})})}),Koe=Ft((t,e)=>{"use strict";e.exports=function r(n){if(typeof n=="number"&&isNaN(n))throw new Error("NaN is not allowed");if(typeof n=="number"&&!isFinite(n))throw new Error("Infinity is not allowed");return n===null||typeof n!="object"?JSON.stringify(n):n.toJSON instanceof Function?r(n.toJSON()):Array.isArray(n)?`[${n.reduce((i,a,s)=>`${i}${s===0?"":","}${r(a===void 0||typeof a=="symbol"?null:a)}`,"")}]`:`{${Object.keys(n).sort().reduce((i,a)=>{if(n[a]===void 0||typeof n[a]=="symbol")return i;let s=i.length===0?"":",";return`${i}${s}${r(a)}:${r(n[a])}`},"")}}`}}),vq=Ft((t,e)=>{var r=1e3,n=r*60,i=n*60,a=i*24,s=a*7,o=a*365.25;e.exports=function(f,h){h=h||{};var p=typeof f;if(p==="string"&&f.length>0)return d(f);if(p==="number"&&isFinite(f))return h.long?c(f):u(f);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(f))};function d(f){if(f=String(f),!(f.length>100)){var h=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(f);if(h){var p=parseFloat(h[1]),m=(h[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return p*o;case"weeks":case"week":case"w":return p*s;case"days":case"day":case"d":return p*a;case"hours":case"hour":case"hrs":case"hr":case"h":return p*i;case"minutes":case"minute":case"mins":case"min":case"m":return p*n;case"seconds":case"second":case"secs":case"sec":case"s":return p*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return p;default:return}}}}function u(f){var h=Math.abs(f);return h>=a?Math.round(f/a)+"d":h>=i?Math.round(f/i)+"h":h>=n?Math.round(f/n)+"m":h>=r?Math.round(f/r)+"s":f+"ms"}function c(f){var h=Math.abs(f);return h>=a?l(f,h,a,"day"):h>=i?l(f,h,i,"hour"):h>=n?l(f,h,n,"minute"):h>=r?l(f,h,r,"second"):f+" ms"}function l(f,h,p,m){var g=h>=p*1.5;return Math.round(f/p)+" "+m+(g?"s":"")}}),kx=(t=>(t.authentication="authentication",t.assertionMethod="assertionMethod",t.keyAgreement="keyAgreement",t.capabilityInvocation="capabilityInvocation",t.capabilityDelegation="capabilityDelegation",t))(kx||{}),li={"@context":"https://w3id.org/did-resolution/v1",didResolutionMetadata:{},didDocument:null,didDocumentMetadata:{}},Oi=class bq{constructor({method:e,id:r,path:n,query:i,fragment:a,params:s}){this.uri=`did:${e}:${r}`,this.method=e,this.id=r,this.path=n,this.query=i,this.fragment=a,this.params=s}static parse(e){if(!e||e.length>2048)return null;let r=bq.DID_URI_PATTERN.exec(e);if(!r||!r.groups)return null;let{method:n,id:i,path:a,query:s,fragment:o}=r.groups,d={uri:`did:${n}:${i}`,method:n,id:i};if(a&&(d.path=a),s&&(d.query=s.slice(1)),o&&(d.fragment=o.slice(1)),s){let u={},c=s.slice(1).split("&");for(let l of c){let[f,h]=l.split("=");u[f]=h}d.params=u}return d}};Oi.METHOD_PATTERN="([a-z0-9]+)",Oi.PCT_ENCODED_PATTERN="(?:%[0-9a-fA-F]{2})",Oi.ID_CHAR_PATTERN=`(?:[a-zA-Z0-9._-]|${Oi.PCT_ENCODED_PATTERN})`,Oi.METHOD_ID_PATTERN=`((?:${Oi.ID_CHAR_PATTERN}*:)*(${Oi.ID_CHAR_PATTERN}+))`,Oi.PATH_PATTERN="(/[^#?]*)?",Oi.QUERY_PATTERN="([?][^#]*)?",Oi.FRAGMENT_PATTERN="(#.*)?",Oi.DID_URI_PATTERN=new RegExp("^did:(?<method>"+Oi.METHOD_PATTERN+"):(?<id>"+Oi.METHOD_ID_PATTERN+")(?<path>"+Oi.PATH_PATTERN+")(?<query>"+Oi.QUERY_PATTERN+")(?<fragment>"+Oi.FRAGMENT_PATTERN+")$");Vn=Oi,Xe=class xq extends Error{constructor(e,r){super(`${e}: ${r}`),this.code=e,this.name="DidError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,xq)}},qoe=(t=>(t.InvalidDid="invalidDid",t.MethodNotSupported="methodNotSupported",t.InternalError="internalError",t.InvalidDidDocument="invalidDidDocument",t.InvalidDidDocumentLength="invalidDidDocumentLength",t.InvalidDidUrl="invalidDidUrl",t.InvalidPreviousDidProof="invalidPreviousDidProof",t.InvalidPublicKey="invalidPublicKey",t.InvalidPublicKeyLength="invalidPublicKeyLength",t.InvalidPublicKeyType="invalidPublicKeyType",t.InvalidSignature="invalidSignature",t.NotFound="notFound",t.RepresentationNotSupported="representationNotSupported",t.UnsupportedPublicKeyType="unsupportedPublicKeyType",t))(qoe||{}),Ys=class Pq extends Error{constructor(e,r){super(r),this.code=e,this.name="CryptoError",Object.setPrototypeOf(this,new.target.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,Pq)}};(function(t){t.AlgorithmNotSupported="algorithmNotSupported",t.EncodingError="encodingError",t.InvalidCoseSign1="invalidCoseSign1",t.InvalidEat="invalidEat",t.InvalidJwe="invalidJwe",t.InvalidJwk="invalidJwk",t.OperationNotSupported="operationNotSupported"})(zo||(zo={}));Loe=Lf(boe(),1);Foe=zoe,Goe=Foe,Woe=Goe,gje=new Uint8Array(0),Hoe=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},GD=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},Voe=class{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Joe=class{constructor(t,e,r){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return _q(this,t)}},Zoe=class{constructor(t){this.decoders=t}or(t){return _q(this,t)}decode(t){let e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},_q=(t,e)=>new Zoe({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Yoe=class{constructor(t,e,r,n){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=n,this.encoder=new Voe(t,e,r),this.decoder=new Joe(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Eq=({name:t,prefix:e,encode:r,decode:n})=>new Yoe(t,e,r,n),Sq=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:i}=Woe(r,e);return Eq({prefix:t,name:e,encode:n,decode:a=>GD(i(a))})},Qoe=(t,e,r,n)=>{let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let a=t.length;for(;t[a-1]==="=";)--a;let s=new Uint8Array(a*r/8|0),o=0,d=0,u=0;for(let c=0;c<a;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|l,o+=r,o>=8&&(o-=8,s[u++]=255&d>>o)}if(o>=r||255&d<<8-o)throw new SyntaxError("Unexpected end of data");return s},Xoe=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,a="",s=0,o=0;for(let d=0;d<t.length;++d)for(o=o<<8|t[d],s+=8;s>r;)s-=r,a+=e[i&o>>s];if(s&&(a+=e[i&o<<r-s]),n)for(;a.length*r&7;)a+="=";return a},xs=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Eq({prefix:e,name:t,encode(i){return Xoe(i,n,r)},decode(i){return Qoe(i,n,r,t)}}),V1=xs({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),wje=xs({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vje=xs({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bje=xs({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xje=xs({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Pje=xs({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),_je=xs({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Eje=xs({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),VU=xs({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5}),Js=Sq({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sje=Sq({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"}),Tje=xs({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kje=xs({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pd=xs({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Aje=xs({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});vw=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},JU=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(a){r[a]=t[a]&&function(s){return new Promise(function(o,d){s=t[a](s),i(o,d,s.done,s.value)})}}function i(a,s,o,d){Promise.resolve(d).then(function(u){a({value:u,done:o})},s)}},K1=new TextEncoder,Af=new TextDecoder,tt=class qo{constructor(e,r){this.data=e,this.format=r}static arrayBuffer(e){return new qo(e,"ArrayBuffer")}static asyncIterable(e){if(!tse(e))throw new TypeError("Input must be of type AsyncIterable.");return new qo(e,"AsyncIterable")}static base32Z(e){return new qo(e,"Base32Z")}static base58Btc(e){return new qo(e,"Base58Btc")}static base64Url(e){return new qo(e,"Base64Url")}static bufferSource(e){return new qo(e,"BufferSource")}static hex(e){if(typeof e!="string")throw new TypeError("Hex input must be a string.");if(e.length%2!==0)throw new TypeError("Hex input must have an even number of characters.");return new qo(e,"Hex")}static multibase(e){return new qo(e,"Multibase")}static object(e){return new qo(e,"Object")}static string(e){return new qo(e,"String")}static uint8Array(e){return new qo(e,"Uint8Array")}toArrayBuffer(){switch(this.format){case"Base58Btc":return Js.baseDecode(this.data).buffer;case"Base64Url":return Pd.baseDecode(this.data).buffer;case"BufferSource":{if(bD(this.data)==="ArrayBuffer")return this.data;if(ArrayBuffer.isView(this.data))return ese(this.data)?this.data.buffer.slice(this.data.byteOffset,this.data.byteOffset+this.data.byteLength):this.data.buffer;throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":return this.toUint8Array().buffer;case"String":return this.toUint8Array().buffer;case"Uint8Array":return this.data.buffer;default:throw new TypeError(`Conversion from ${this.format} to ArrayBuffer is not supported.`)}}toArrayBufferAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":return yield(yield this.toBlobAsync()).arrayBuffer();default:throw new TypeError(`Asynchronous conversion from ${this.format} to ArrayBuffer is not supported.`)}})}toBase32Z(){switch(this.format){case"Uint8Array":return VU.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Z is not supported.`)}}toBase58Btc(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Js.baseEncode(e)}case"Multibase":return this.data.substring(1);case"Uint8Array":return Js.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base58Btc is not supported.`)}}toBase64Url(){switch(this.format){case"ArrayBuffer":{let e=new Uint8Array(this.data);return Pd.baseEncode(e)}case"BufferSource":{let e=this.toUint8Array();return Pd.baseEncode(e)}case"Object":{let e=JSON.stringify(this.data),r=K1.encode(e);return Pd.baseEncode(r)}case"String":{let e=K1.encode(this.data);return Pd.baseEncode(e)}case"Uint8Array":return Pd.baseEncode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Base64Url is not supported.`)}}toBlobAsync(){return vw(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let d=[];try{for(var a=!0,s=JU(this.data),o;o=yield s.next(),e=o.done,!e;a=!0){i=o.value,a=!1;let u=i;d.push(u)}}catch(u){r={error:u}}finally{try{!a&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return new Blob(d)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Blob is not supported.`)}})}toHex(){let e=Array.from({length:256},(r,n)=>n.toString(16).padStart(2,"0"));switch(this.format){case"ArrayBuffer":{let r=this.toUint8Array();return qo.uint8Array(r).toHex()}case"Base64Url":{let r=this.toUint8Array();return qo.uint8Array(r).toHex()}case"Uint8Array":{let r="";for(let n=0;n<this.data.length;n++)r+=e[this.data[n]];return r}default:throw new TypeError(`Conversion from ${this.format} to Hex is not supported.`)}}toMultibase(){switch(this.format){case"Base58Btc":return`z${this.data}`;default:throw new TypeError(`Conversion from ${this.format} to Multibase is not supported.`)}}toObject(){switch(this.format){case"Base64Url":{let e=Pd.baseDecode(this.data),r=Af.decode(e);return JSON.parse(r)}case"String":return JSON.parse(this.data);case"Uint8Array":{let e=Af.decode(this.data);return JSON.parse(e)}default:throw new TypeError(`Conversion from ${this.format} to Object is not supported.`)}}toObjectAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toStringAsync();return JSON.parse(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Object is not supported.`)}})}toString(){switch(this.format){case"ArrayBuffer":return Af.decode(this.data);case"Base64Url":{let e=Pd.baseDecode(this.data);return Af.decode(e)}case"Object":return JSON.stringify(this.data);case"Uint8Array":return Af.decode(this.data);default:throw new TypeError(`Conversion from ${this.format} to String is not supported.`)}}toStringAsync(){return vw(this,void 0,void 0,function*(){var e,r,n,i;switch(this.format){case"AsyncIterable":{let d="";try{for(var a=!0,s=JU(this.data),o;o=yield s.next(),e=o.done,!e;a=!0){i=o.value,a=!1;let u=i;typeof u=="string"?d+=u:d+=Af.decode(u,{stream:!0})}}catch(u){r={error:u}}finally{try{!a&&!e&&(n=s.return)&&(yield n.call(s))}finally{if(r)throw r.error}}return d+=Af.decode(void 0,{stream:!1}),d}default:throw new TypeError(`Asynchronous conversion from ${this.format} to String is not supported.`)}})}toUint8Array(){switch(this.format){case"ArrayBuffer":return new Uint8Array(this.data);case"Base32Z":return VU.baseDecode(this.data);case"Base58Btc":return Js.baseDecode(this.data);case"Base64Url":return Pd.baseDecode(this.data);case"BufferSource":{let e=bD(this.data);if(e==="Uint8Array")return this.data;if(e==="ArrayBuffer")return new Uint8Array(this.data);if(ArrayBuffer.isView(this.data))return new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength);throw new TypeError(`${this.format} value is not of type: ArrayBuffer, DataView, or TypedArray.`)}case"Hex":{let e=new Uint8Array(this.data.length/2);for(let r=0;r<this.data.length;r+=2){let n=parseInt(this.data.substring(r,r+2),16);if(isNaN(n))throw new TypeError("Input is not a valid hexadecimal string.");e[r/2]=n}return e}case"Object":{let e=JSON.stringify(this.data);return K1.encode(e)}case"String":return K1.encode(this.data);default:throw new TypeError(`Conversion from ${this.format} to Uint8Array is not supported.`)}}toUint8ArrayAsync(){return vw(this,void 0,void 0,function*(){switch(this.format){case"AsyncIterable":{let e=yield this.toArrayBufferAsync();return new Uint8Array(e)}default:throw new TypeError(`Asynchronous conversion from ${this.format} to Uint8Array is not supported.`)}})}};(function(t){t.Debug="debug",t.Silent="silent"})(qw||(qw={}));rse=class{constructor(){this.logLevel=qw.Silent}setLogLevel(t){this.logLevel=t}log(t){this.info(t)}info(t){this.logLevel!==qw.Silent&&console.info(t)}error(t){this.logLevel!==qw.Silent&&console.error(t)}},nse=new rse;typeof window<"u"&&(window.enboxLogger=nse);Tw={};LD(Tw,{decode:()=>mx,encodeTo:()=>zw,encodingLength:()=>Fw});ise=Tq,ZU=128,ose=127,sse=~ose,ase=Math.pow(2,31);cse=xD,dse=128,YU=127;use=Math.pow(2,7),lse=Math.pow(2,14),fse=Math.pow(2,21),pse=Math.pow(2,28),hse=Math.pow(2,35),mse=Math.pow(2,42),yse=Math.pow(2,49),gse=Math.pow(2,56),wse=Math.pow(2,63),vse=function(t){return t<use?1:t<lse?2:t<fse?3:t<pse?4:t<hse?5:t<mse?6:t<yse?7:t<gse?8:t<wse?9:10},bse={encode:ise,decode:cse,encodingLength:vse},xse=bse,hx=xse,mx=(t,e=0)=>[hx.decode(t,e),hx.decode.bytes],zw=(t,e,r=0)=>(hx.encode(t,e,r),e),Fw=t=>hx.encodingLength(t),Pse=(t,e)=>{let r=e.byteLength,n=Fw(t),i=n+Fw(r),a=new Uint8Array(i+r);return zw(t,a,0),zw(r,a,n),a.set(e,i),new WD(t,r,e,a)},_se=t=>{let e=GD(t),[r,n]=mx(e),[i,a]=mx(e.subarray(n)),s=e.subarray(n+a);if(s.byteLength!==i)throw new Error("Incorrect length");return new WD(r,i,s,e)},Ese=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Hoe(t.bytes,r.bytes)}},WD=class{constructor(t,e,r,n){this.code=t,this.size=e,this.digest=r,this.bytes=n}},QU=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Tse(r,PD(t),e||Js.encoder);default:return kse(r,PD(t),e||V1.encoder)}},XU=new WeakMap,PD=t=>{let e=XU.get(t);if(e==null){let r=new Map;return XU.set(t,r),r}return e},Dje=class ro{constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==bw)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ase)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return ro.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Pse(e,r);return ro.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return ro.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Ese(e.multihash,n.multihash)}toString(e){return QU(this,e)}toJSON(){return{"/":QU(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof ro)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:a,bytes:s}=r;return new ro(n,i,a,s||eK(n,i,a.bytes))}else if(r[Dse]===!0){let{version:n,multihash:i,code:a}=r,s=_se(i);return ro.create(n,a,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==bw)throw new Error(`Version 0 CID must use dag-pb (code: ${bw}) block encoding`);return new ro(e,r,n,n.bytes)}case 1:{let i=eK(e,r,n.bytes);return new ro(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return ro.create(0,bw,e)}static createV1(e,r){return ro.create(1,e,r)}static decode(e){let[r,n]=ro.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=ro.inspectBytes(e),n=r.size-r.multihashSize,i=GD(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let a=i.subarray(r.multihashSize-r.digestSize),s=new WD(r.multihashCode,r.digestSize,a,i);return[r.version===0?ro.createV0(s):ro.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,f]=mx(e.subarray(r));return r+=f,l},i=n(),a=bw;if(i===18?(i=0,r=0):a=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,o=n(),d=n(),u=r+d,c=u-s;return{version:i,codec:a,multihashCode:o,digestSize:d,multihashSize:c,size:u}}static parse(e,r){let[n,i]=Sse(e,r),a=ro.decode(i);if(a.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return PD(a).set(n,e),a}},Sse=(t,e)=>{switch(t[0]){case"Q":{let r=e||Js;return[Js.prefix,r.decode(`${Js.prefix}${t}`)]}case Js.prefix:{let r=e||Js;return[Js.prefix,r.decode(t)]}case V1.prefix:{let r=e||V1;return[V1.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},Tse=(t,e,r)=>{let{prefix:n}=r;if(n!==Js.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let a=r.encode(t).slice(1);return e.set(n,a),a}else return i},kse=(t,e,r)=>{let{prefix:n}=r,i=e.get(n);if(i==null){let a=r.encode(t);return e.set(n,a),a}else return i},bw=112,Ase=18,eK=(t,e,r)=>{let n=Fw(t),i=n+Fw(e),a=new Uint8Array(i+r.byteLength);return zw(t,a,0),zw(e,a,n),a.set(r,i),a},Dse=Symbol.for("@ipld/js-cid/CID"),Xs=class Wu{static addPrefix(e){var r;let{code:n,data:i,name:a}=e;if(!(a?!n:n))throw new Error("Either 'name' or 'code' must be defined, but not both.");if(n=Wu.codeToName.has(n)?n:Wu.nameToCode.get(a),n===void 0)throw new Error(`Unsupported multicodec: ${(r=e.name)!==null&&r!==void 0?r:e.code}`);let s=Tw.encodingLength(n),o=new Uint8Array(s+i.byteLength);return o.set(i,s),Tw.encodeTo(n,o),o}static getCodeFromData(e){let{prefixedData:r}=e,[n,i]=Tw.decode(r);return n}static getCodeFromName(e){let{name:r}=e,n=Wu.nameToCode.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static getNameFromCode(e){let{code:r}=e,n=Wu.codeToName.get(r);if(n===void 0)throw new Error(`Unsupported multicodec: ${r}`);return n}static registerCodec(e){Wu.codeToName.set(e.code,e.name),Wu.nameToCode.set(e.name,e.code)}static removePrefix(e){let{prefixedData:r}=e,[n,i]=Tw.decode(r),a=Wu.codeToName.get(n);if(a===void 0)throw new Error(`Unsupported multicodec: ${n}`);return{code:n,data:r.slice(i),name:a}}};Xs.codeToName=new Map;Xs.nameToCode=new Map;Xs.registerCodec({code:237,name:"ed25519-pub"});Xs.registerCodec({code:4864,name:"ed25519-priv"});Xs.registerCodec({code:236,name:"x25519-pub"});Xs.registerCodec({code:4866,name:"x25519-priv"});Xs.registerCodec({code:231,name:"secp256k1-pub"});Xs.registerCodec({code:4865,name:"secp256k1-priv"});Ije=Lf(wq(),1),ju=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Ise=class{constructor(){this.store=new Map}clear(){return ju(this,void 0,void 0,function*(){this.store.clear()})}open(){return ju(this,void 0,void 0,function*(){})}close(){return ju(this,void 0,void 0,function*(){})}delete(t){return ju(this,void 0,void 0,function*(){return this.store.delete(t)})}get(t){return ju(this,void 0,void 0,function*(){return this.store.get(t)})}has(t){return ju(this,void 0,void 0,function*(){return this.store.has(t)})}list(){return ju(this,void 0,void 0,function*(){return Array.from(this.store.values())})}set(t,e){return ju(this,void 0,void 0,function*(){this.store.set(t,e)})}},Ax=class{},Aq={};LD(Aq,{bitGet:()=>Mse,bitLen:()=>jse,bitMask:()=>VD,bitSet:()=>Nse,bytesToHex:()=>Uf,bytesToNumberBE:()=>jf,bytesToNumberLE:()=>Yu,concatBytes:()=>Kf,createHmacDrbg:()=>Rq,ensureBytes:()=>In,equalBytes:()=>Ose,hexToBytes:()=>om,hexToNumber:()=>HD,isBytes:()=>Dc,numberToBytesBE:()=>Ic,numberToBytesLE:()=>sm,numberToHexUnpadded:()=>Iq,numberToVarBytesBE:()=>$se,utf8ToBytes:()=>Bse,validateObject:()=>zf});Dq=BigInt(0),Dx=BigInt(1),Rse=BigInt(2);Cse=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));_d={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};Nse=(t,e,r)=>t|(r?Dx:Dq)<<BigInt(e),VD=t=>(Rse<<BigInt(t-1))-Dx,uD=t=>new Uint8Array(t),rK=t=>Uint8Array.from(t);Use={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Dc(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};lD=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;fD=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),xc=(t,e)=>t<<32-e|t>>>e,zse=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!zse)throw new Error("Non little-endian hardware is not supported");jq=class{clone(){return this._cloneInto()}},Rje={}.toString;Nq=class extends jq{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=fD(this.buffer)}update(t){yx(this);let{view:e,buffer:r,blockLen:n}=this;t=JD(t);let i=t.length;for(let a=0;a<i;){let s=Math.min(n-this.pos,i-a);if(s===n){let o=fD(t);for(;n<=i-a;a+=n)this.process(o,a);continue}r.set(t.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===n&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){yx(this),Lse(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:n,isLE:i}=this,{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>n-a&&(this.process(r,0),a=0);for(let c=a;c<n;c++)e[c]=0;Fse(r,n-8,BigInt(this.length*8),i),this.process(r,0);let s=fD(t),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=o/4,u=this.get();if(d>u.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<d;c++)s.setUint32(4*c,u[c],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:r,length:n,finished:i,destroyed:a,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=a,n%e&&t.buffer.set(r),t}},Gse=(t,e,r)=>t&e^~t&r,Wse=(t,e,r)=>t&e^t&r^e&r,Hse=new Uint32Array([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]),Mu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Nu=new Uint32Array(64),Vse=class extends Nq{constructor(){super(64,32,8,!1),this.A=Mu[0]|0,this.B=Mu[1]|0,this.C=Mu[2]|0,this.D=Mu[3]|0,this.E=Mu[4]|0,this.F=Mu[5]|0,this.G=Mu[6]|0,this.H=Mu[7]|0}get(){let{A:t,B:e,C:r,D:n,E:i,F:a,G:s,H:o}=this;return[t,e,r,n,i,a,s,o]}set(t,e,r,n,i,a,s,o){this.A=t|0,this.B=e|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=a|0,this.G=s|0,this.H=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)Nu[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let l=Nu[c-15],f=Nu[c-2],h=xc(l,7)^xc(l,18)^l>>>3,p=xc(f,17)^xc(f,19)^f>>>10;Nu[c]=p+Nu[c-7]+h+Nu[c-16]|0}let{A:r,B:n,C:i,D:a,E:s,F:o,G:d,H:u}=this;for(let c=0;c<64;c++){let l=xc(s,6)^xc(s,11)^xc(s,25),f=u+l+Gse(s,o,d)+Hse[c]+Nu[c]|0,h=(xc(r,2)^xc(r,13)^xc(r,22))+Wse(r,n,i)|0;u=d,d=o,o=s,s=a+f|0,a=i,i=n,n=r,r=f+h|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,o=o+this.F|0,d=d+this.G|0,u=u+this.H|0,this.set(r,n,i,a,s,o,d,u)}roundClean(){Nu.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Uq=Mq(()=>new Vse),Hn=BigInt(0),Xr=BigInt(1),Rf=BigInt(2),Jse=BigInt(3),_D=BigInt(4),iK=BigInt(5),oK=BigInt(8),Cje=BigInt(9),Zse=BigInt(16);Xse=(t,e)=>(Nr(t,e)&Xr)===Xr,eae=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];sae=BigInt(0),pD=BigInt(1);({bytesToNumberBE:cae,hexToBytes:dae}=Aq),Of={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(t){let{Err:e}=Of;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");let r=t[1],n=t.subarray(2,r+2);if(!r||n.length!==r)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:cae(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=Of,r=typeof t=="string"?dae(t):t;if(!Dc(r))throw new Error("ui8a expected");let n=r.length;if(n<2||r[0]!=48)throw new e("Invalid signature tag");if(r[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:a}=Of._parseInt(r.subarray(2)),{d:s,l:o}=Of._parseInt(a);if(o.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,r=u=>{let c=u.toString(16);return c.length&1?`0${c}`:c},n=e(r(t.s)),i=e(r(t.r)),a=n.length/2,s=i.length/2,o=r(a),d=r(s);return`30${r(s+a+4)}02${d}${i}02${o}${n}`}},Dd=BigInt(0),Vs=BigInt(1),$je=BigInt(2),sK=BigInt(3),Oje=BigInt(4);Gq=class extends jq{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,qse(t);let r=JD(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,i=new Uint8Array(n);i.set(r.length>n?t.create().update(r).digest():r);for(let a=0;a<i.length;a++)i[a]^=54;this.iHash.update(i),this.oHash=t.create();for(let a=0;a<i.length;a++)i[a]^=106;this.oHash.update(i),i.fill(0)}update(t){return yx(this),this.iHash.update(t),this}digestInto(t){yx(this),Cq(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:r,finished:n,destroyed:i,blockLen:a,outputLen:s}=this;return t=t,t.finished=n,t.destroyed=i,t.blockLen=a,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Wq=(t,e,r)=>new Gq(t,e).update(r).digest();Wq.create=(t,e)=>new Gq(t,e);Vq=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),aK=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),hae=BigInt(1),SD=BigInt(2),cK=(t,e)=>(t+e/SD)/e;TD=YD(Vq,void 0,void 0,{sqrt:mae}),gs=Hq({a:BigInt(0),b:BigInt(7),Fp:TD,n:aK,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=aK,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-hae*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),a=r,s=BigInt("0x100000000000000000000000000000000"),o=cK(a*t,e),d=cK(-n*t,e),u=Nr(t-o*r-d*i,e),c=Nr(-o*n-d*a,e),l=u>s,f=c>s;if(l&&(u=e-u),f&&(c=e-c),u>s||c>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:l,k1:u,k2neg:f,k2:c}}}},Uq),Bje=BigInt(0),jje=gs.ProjectivePoint;J1=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,hD=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Pc=(t,e)=>t<<32-e|t>>>e,Mje=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;vae=class{clone(){return this._cloneInto()}},Nje={}.toString;_ae=(t,e,r)=>t&e^~t&r,Eae=(t,e,r)=>t&e^t&r^e&r,Sae=class extends vae{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=hD(this.buffer)}update(t){dK(this);let{view:e,buffer:r,blockLen:n}=this;t=Zq(t);let i=t.length;for(let a=0;a<i;){let s=Math.min(n-this.pos,i-a);if(s===n){let o=hD(t);for(;n<=i-a;a+=n)this.process(o,a);continue}r.set(t.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===n&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){dK(this),gae(t,this),this.finished=!0;let{buffer:e,view:r,blockLen:n,isLE:i}=this,{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>n-a&&(this.process(r,0),a=0);for(let c=a;c<n;c++)e[c]=0;Pae(r,n-8,BigInt(this.length*8),i),this.process(r,0);let s=hD(t),o=this.outputLen;if(o%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let d=o/4,u=this.get();if(d>u.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<d;c++)s.setUint32(4*c,u[c],i)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:r,length:n,finished:i,destroyed:a,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=a,n%e&&t.buffer.set(r),t}},Tae=new Uint32Array([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]),Uu=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ku=new Uint32Array(64),kae=class extends Sae{constructor(){super(64,32,8,!1),this.A=Uu[0]|0,this.B=Uu[1]|0,this.C=Uu[2]|0,this.D=Uu[3]|0,this.E=Uu[4]|0,this.F=Uu[5]|0,this.G=Uu[6]|0,this.H=Uu[7]|0}get(){let{A:t,B:e,C:r,D:n,E:i,F:a,G:s,H:o}=this;return[t,e,r,n,i,a,s,o]}set(t,e,r,n,i,a,s,o){this.A=t|0,this.B=e|0,this.C=r|0,this.D=n|0,this.E=i|0,this.F=a|0,this.G=s|0,this.H=o|0}process(t,e){for(let c=0;c<16;c++,e+=4)Ku[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let l=Ku[c-15],f=Ku[c-2],h=Pc(l,7)^Pc(l,18)^l>>>3,p=Pc(f,17)^Pc(f,19)^f>>>10;Ku[c]=p+Ku[c-7]+h+Ku[c-16]|0}let{A:r,B:n,C:i,D:a,E:s,F:o,G:d,H:u}=this;for(let c=0;c<64;c++){let l=Pc(s,6)^Pc(s,11)^Pc(s,25),f=u+l+_ae(s,o,d)+Tae[c]+Ku[c]|0,h=(Pc(r,2)^Pc(r,13)^Pc(r,22))+Eae(r,n,i)|0;u=d,d=o,o=s,s=a+f|0,a=i,i=n,n=r,r=f+h|0}r=r+this.A|0,n=n+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,o=o+this.F|0,d=d+this.G|0,u=u+this.H|0,this.set(r,n,i,a,s,o,d,u)}roundClean(){Ku.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}},Gw=bae(()=>new kae);Dae=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Yq=class{static digest(t){return Dae(this,arguments,void 0,function*({data:e}){return Gw(e)})}},Iae=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},uK="urn:jwk:";Ci=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Cae=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},ji=class Ec{static adjustSignatureToLowS(e){return Ci(this,arguments,void 0,function*({signature:r}){let n=gs.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return Ci(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield Ec.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield Ec.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"secp256k1",x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static compressPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){return gs.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return Ci(this,arguments,void 0,function*({key:r}){let n=yield Ec.privateKeyToBytes({privateKey:r}),i=yield Ec.getCurvePoint({keyBytes:n}),a={kty:"EC",crv:"secp256k1",x:tt.uint8Array(i.x).toBase64Url(),y:tt.uint8Array(i.y).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertDerToCompactSignature(e){return Ci(this,arguments,void 0,function*({derSignature:r}){return gs.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){return gs.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return Ci(this,void 0,void 0,function*(){let e=gs.utils.randomPrivateKey(),r=yield Ec.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return Ci(this,arguments,void 0,function*({key:r}){var n;if(!(Mf(r)&&r.crv==="secp256k1"))throw new Error("Secp256k1: The provided key is not a secp256k1 private JWK.");let{d:i}=r,a=Cae(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return Ci(this,arguments,void 0,function*({privateKey:r}){if(!Mf(r))throw new Error("Secp256k1: The provided key is not a valid EC private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Ci(this,arguments,void 0,function*({publicKey:r}){if(!(XD(r)&&r.y))throw new Error("Secp256k1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=tt.base64Url(r.x).toUint8Array(),a=tt.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...a])})}static sharedSecret(e){return Ci(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256k1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Ec.privateKeyToBytes({privateKey:r}),a=yield Ec.publicKeyToBytes({publicKey:n});return gs.getSharedSecret(i,a,!0).slice(1)})}static sign(e){return Ci(this,arguments,void 0,function*({data:r,key:n}){let i=yield Ec.privateKeyToBytes({privateKey:n}),a=Gw(r);return gs.sign(a,i).toCompactRawBytes()})}static validatePrivateKey(e){return Ci(this,arguments,void 0,function*({privateKeyBytes:r}){return gs.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return Ci(this,arguments,void 0,function*({publicKeyBytes:r}){try{gs.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Ci(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Ec.publicKeyToBytes({publicKey:r}),s=Gw(i);return gs.verify(n,s,a,{lowS:!1})})}static getCurvePoint(e){return Ci(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=gs.getPublicKey(r));let n=gs.ProjectivePoint.fromHex(r),i=Ic(n.x,32),a=Ic(n.y,32);return{x:i,y:a}})}},Qq=YD(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),$ae=Qq.create(BigInt("-3")),Oae=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Bae=Hq({a:$ae,b:Oae,Fp:Qq,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Uq),zs=Bae,$i=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},jae=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},no=class Sc{static adjustSignatureToLowS(e){return $i(this,arguments,void 0,function*({signature:r}){let n=zs.Signature.fromCompact(r);return n.hasHighS()?n.normalizeS().toCompactRawBytes():r})}static bytesToPrivateKey(e){return $i(this,arguments,void 0,function*({privateKeyBytes:r}){let n=yield Sc.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){let n=yield Sc.getCurvePoint({keyBytes:r}),i={kty:"EC",crv:"P-256",x:tt.uint8Array(n.x).toBase64Url(),y:tt.uint8Array(n.y).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static compressPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){return zs.ProjectivePoint.fromHex(r).toRawBytes(!0)})}static computePublicKey(e){return $i(this,arguments,void 0,function*({key:r}){let n=yield Sc.privateKeyToBytes({privateKey:r}),i=yield Sc.getCurvePoint({keyBytes:n}),a={kty:"EC",crv:"P-256",x:tt.uint8Array(i.x).toBase64Url(),y:tt.uint8Array(i.y).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertDerToCompactSignature(e){return $i(this,arguments,void 0,function*({derSignature:r}){return zs.Signature.fromDER(r).toCompactRawBytes()})}static decompressPublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){return zs.ProjectivePoint.fromHex(r).toRawBytes(!1)})}static generateKey(){return $i(this,void 0,void 0,function*(){let e=zs.utils.randomPrivateKey(),r=yield Sc.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return $i(this,arguments,void 0,function*({key:r}){var n;if(!(Mf(r)&&r.crv==="P-256"))throw new Error("Secp256r1: The provided key is not a 'P-256' private JWK.");let{d:i}=r,a=jae(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return $i(this,arguments,void 0,function*({privateKey:r}){if(!Mf(r))throw new Error("Secp256r1: The provided key is not a valid EC private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return $i(this,arguments,void 0,function*({publicKey:r}){if(!(XD(r)&&r.y))throw new Error("Secp256r1: The provided key is not a valid EC public key.");let n=new Uint8Array([4]),i=tt.base64Url(r.x).toUint8Array(),a=tt.base64Url(r.y).toUint8Array();return new Uint8Array([...n,...i,...a])})}static sharedSecret(e){return $i(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("Secp256r1: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Sc.privateKeyToBytes({privateKey:r}),a=yield Sc.publicKeyToBytes({publicKey:n});return zs.getSharedSecret(i,a,!0).slice(1)})}static sign(e){return $i(this,arguments,void 0,function*({data:r,key:n}){let i=yield Sc.privateKeyToBytes({privateKey:n}),a=Gw(r);return zs.sign(a,i).toCompactRawBytes()})}static validatePrivateKey(e){return $i(this,arguments,void 0,function*({privateKeyBytes:r}){return zs.utils.isValidPrivateKey(r)})}static validatePublicKey(e){return $i(this,arguments,void 0,function*({publicKeyBytes:r}){try{zs.ProjectivePoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return $i(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Sc.publicKeyToBytes({publicKey:r}),s=Gw(i);return zs.verify(n,s,a,{lowS:!1})})}static getCurvePoint(e){return $i(this,arguments,void 0,function*({keyBytes:r}){r.byteLength===32&&(r=zs.getPublicKey(r));let n=zs.ProjectivePoint.fromHex(r),i=Ic(n.x,32),a=Ic(n.y,32);return{x:i,y:a}})}},Ed=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},lK=class extends Ax{bytesToPrivateKey(t){return Ed(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"ES256K":case"secp256k1":{let n=yield ji.bytesToPrivateKey({privateKeyBytes:r});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield no.bytesToPrivateKey({privateKeyBytes:r});return n.alg="ES256",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}bytesToPublicKey(t){return Ed(this,arguments,void 0,function*({algorithm:e,publicKeyBytes:r}){switch(e){case"ES256K":case"secp256k1":{let n=yield ji.bytesToPublicKey({publicKeyBytes:r});return n.alg="ES256K",n}case"ES256":case"secp256r1":{let n=yield no.bytesToPublicKey({publicKeyBytes:r});return n.alg="ES256",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Ed(this,arguments,void 0,function*({key:e}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let r=yield ji.computePublicKey({key:e});return r.alg="ES256K",r}case"P-256":{let r=yield no.computePublicKey({key:e});return r.alg="ES256",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Ed(this,arguments,void 0,function*({algorithm:e}){switch(e){case"ES256K":case"secp256k1":{let r=yield ji.generateKey();return r.alg="ES256K",r}case"ES256":case"secp256r1":{let r=yield no.generateKey();return r.alg="ES256",r}}})}getPublicKey(t){return Ed(this,arguments,void 0,function*({key:e}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":{let r=yield ji.getPublicKey({key:e});return r.alg="ES256K",r}case"P-256":{let r=yield no.getPublicKey({key:e});return r.alg="ES256",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}sign(t){return Ed(this,arguments,void 0,function*({key:e,data:r}){if(!Mf(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) private key.");switch(e.crv){case"secp256k1":return yield ji.sign({key:e,data:r});case"P-256":return yield no.sign({key:e,data:r});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}verify(t){return Ed(this,arguments,void 0,function*({key:e,signature:r,data:n}){if(!XD(e))throw new TypeError("Invalid key provided. Must be an elliptic curve (EC) public key.");switch(e.crv){case"secp256k1":return yield ji.verify({key:e,signature:r,data:n});case"P-256":return yield no.verify({key:e,signature:r,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Ed(this,arguments,void 0,function*({privateKey:e}){switch(e.crv){case"secp256k1":return yield ji.privateKeyToBytes({privateKey:e});case"P-256":return yield no.privateKeyToBytes({privateKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}publicKeyToBytes(t){return Ed(this,arguments,void 0,function*({publicKey:e}){switch(e.crv){case"secp256k1":return yield ji.publicKeyToBytes({publicKey:e});case"P-256":return yield no.publicKeyToBytes({publicKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}},q1=BigInt(4294967295),kD=BigInt(32);Nae=(t,e)=>BigInt(t>>>0)<<kD|BigInt(e>>>0),Uae=(t,e,r)=>t>>>r,Kae=(t,e,r)=>t<<32-r|e>>>r,qae=(t,e,r)=>t>>>r|e<<32-r,Lae=(t,e,r)=>t<<32-r|e>>>r,zae=(t,e,r)=>t<<64-r|e>>>r-32,Fae=(t,e,r)=>t>>>r-32|e<<64-r,Gae=(t,e)=>e,Wae=(t,e)=>t,Hae=(t,e,r)=>t<<r|e>>>32-r,Vae=(t,e,r)=>e<<r|t>>>32-r,Jae=(t,e,r)=>e<<r-32|t>>>64-r,Zae=(t,e,r)=>t<<r-32|e>>>64-r;Qae=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Xae=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,ece=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),tce=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,rce=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),nce=(t,e,r,n,i,a)=>e+r+n+i+a+(t/2**32|0)|0,ice={fromBig:Xq,split:Mae,toBig:Nae,shrSH:Uae,shrSL:Kae,rotrSH:qae,rotrSL:Lae,rotrBH:zae,rotrBL:Fae,rotr32H:Gae,rotr32L:Wae,rotlSH:Hae,rotlSL:Vae,rotlBH:Jae,rotlBL:Zae,add:Yae,add3L:Qae,add3H:Xae,add4L:ece,add4H:tce,add5H:nce,add5L:rce},It=ice,[oce,sce]=It.split(["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(t=>BigInt(t))),qu=new Uint32Array(80),Lu=new Uint32Array(80),ace=class extends Nq{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:r,Bl:n,Ch:i,Cl:a,Dh:s,Dl:o,Eh:d,El:u,Fh:c,Fl:l,Gh:f,Gl:h,Hh:p,Hl:m}=this;return[t,e,r,n,i,a,s,o,d,u,c,l,f,h,p,m]}set(t,e,r,n,i,a,s,o,d,u,c,l,f,h,p,m){this.Ah=t|0,this.Al=e|0,this.Bh=r|0,this.Bl=n|0,this.Ch=i|0,this.Cl=a|0,this.Dh=s|0,this.Dl=o|0,this.Eh=d|0,this.El=u|0,this.Fh=c|0,this.Fl=l|0,this.Gh=f|0,this.Gl=h|0,this.Hh=p|0,this.Hl=m|0}process(t,e){for(let v=0;v<16;v++,e+=4)qu[v]=t.getUint32(e),Lu[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let E=qu[v-15]|0,T=Lu[v-15]|0,D=It.rotrSH(E,T,1)^It.rotrSH(E,T,8)^It.shrSH(E,T,7),R=It.rotrSL(E,T,1)^It.rotrSL(E,T,8)^It.shrSL(E,T,7),N=qu[v-2]|0,B=Lu[v-2]|0,G=It.rotrSH(N,B,19)^It.rotrBH(N,B,61)^It.shrSH(N,B,6),z=It.rotrSL(N,B,19)^It.rotrBL(N,B,61)^It.shrSL(N,B,6),U=It.add4L(R,z,Lu[v-7],Lu[v-16]),H=It.add4H(U,D,G,qu[v-7],qu[v-16]);qu[v]=H|0,Lu[v]=U|0}let{Ah:r,Al:n,Bh:i,Bl:a,Ch:s,Cl:o,Dh:d,Dl:u,Eh:c,El:l,Fh:f,Fl:h,Gh:p,Gl:m,Hh:g,Hl:_}=this;for(let v=0;v<80;v++){let E=It.rotrSH(c,l,14)^It.rotrSH(c,l,18)^It.rotrBH(c,l,41),T=It.rotrSL(c,l,14)^It.rotrSL(c,l,18)^It.rotrBL(c,l,41),D=c&f^~c&p,R=l&h^~l&m,N=It.add5L(_,T,R,sce[v],Lu[v]),B=It.add5H(N,g,E,D,oce[v],qu[v]),G=N|0,z=It.rotrSH(r,n,28)^It.rotrBH(r,n,34)^It.rotrBH(r,n,39),U=It.rotrSL(r,n,28)^It.rotrBL(r,n,34)^It.rotrBL(r,n,39),H=r&i^r&s^i&s,ee=n&a^n&o^a&o;g=p|0,_=m|0,p=f|0,m=h|0,f=c|0,h=l|0,{h:c,l}=It.add(d|0,u|0,B|0,G|0),d=s|0,u=o|0,s=i|0,o=a|0,i=r|0,a=n|0;let I=It.add3L(G,U,ee);r=It.add3H(I,B,z,H),n=I|0}({h:r,l:n}=It.add(this.Ah|0,this.Al|0,r|0,n|0)),{h:i,l:a}=It.add(this.Bh|0,this.Bl|0,i|0,a|0),{h:s,l:o}=It.add(this.Ch|0,this.Cl|0,s|0,o|0),{h:d,l:u}=It.add(this.Dh|0,this.Dl|0,d|0,u|0),{h:c,l}=It.add(this.Eh|0,this.El|0,c|0,l|0),{h:f,l:h}=It.add(this.Fh|0,this.Fl|0,f|0,h|0),{h:p,l:m}=It.add(this.Gh|0,this.Gl|0,p|0,m|0),{h:g,l:_}=It.add(this.Hh|0,this.Hl|0,g|0,_|0),this.set(r,n,i,a,s,o,d,u,c,l,f,h,p,m,g,_)}roundClean(){qu.fill(0),Lu.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},eL=Mq(()=>new ace),Ma=BigInt(0),ms=BigInt(1),L1=BigInt(2),cce=BigInt(8),dce={zip215:!0};xw=BigInt(0),mD=BigInt(1);Ww=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),fK=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Uje=BigInt(0),pce=BigInt(1),AD=BigInt(2),hce=BigInt(5),pK=BigInt(10),mce=BigInt(20),yce=BigInt(40),hK=BigInt(80);Qs=YD(Ww,void 0,!0),Hw={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Qs,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:eL,randomBytes:ZD,adjustScalarBytes:rL,uvRatio:gce},Df=tI(Hw);Kje=tI({...Hw,domain:nL}),qje=tI({...Hw,domain:nL,prehash:eL}),kw=fce({P:Ww,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{let e=Ww,{pow_p_5_8:r,b2:n}=tL(t);return Nr(sn(r,BigInt(3),e)*n,e)},adjustScalarBytes:rL,randomBytes:ZD});bce=(Qs.ORDER+BigInt(3))/BigInt(8),Lje=Qs.pow(AD,bce),zje=Qs.sqrt(Qs.neg(Qs.ONE)),Fje=(Qs.ORDER-BigInt(5))/BigInt(8),Gje=BigInt(486662),Wje=iae(Qs,Qs.neg(BigInt(486664))),Hje=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Vje=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Jje=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Zje=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Yje=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Fs=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},xce=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Mi=class Hu{static bytesToPrivateKey(e){return Fs(this,arguments,void 0,function*({privateKeyBytes:r}){let n=Df.getPublicKey(r),i={crv:"Ed25519",d:tt.uint8Array(r).toBase64Url(),kty:"OKP",x:tt.uint8Array(n).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return Fs(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"Ed25519",x:tt.uint8Array(r).toBase64Url()};return n.kid=yield lr({jwk:n}),n})}static computePublicKey(e){return Fs(this,arguments,void 0,function*({key:r}){let n=yield Hu.privateKeyToBytes({privateKey:r}),i=Df.getPublicKey(n),a={kty:"OKP",crv:"Ed25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static convertPrivateKeyToX25519(e){return Fs(this,arguments,void 0,function*({privateKey:r}){let n=yield Hu.privateKeyToBytes({privateKey:r}),i=vce(n),a=kw.getPublicKey(i),s={kty:"OKP",crv:"X25519",d:tt.uint8Array(i).toBase64Url(),x:tt.uint8Array(a).toBase64Url()};return s.kid=yield lr({jwk:s}),s})}static convertPublicKeyToX25519(e){return Fs(this,arguments,void 0,function*({publicKey:r}){let n=yield Hu.publicKeyToBytes({publicKey:r});if(!(yield Hu.validatePublicKey({publicKeyBytes:n})))throw new Error("Ed25519: Invalid public key.");let i=wce(n),a={kty:"OKP",crv:"X25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static generateKey(){return Fs(this,void 0,void 0,function*(){let e=Df.utils.randomPrivateKey(),r=yield Hu.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return Fs(this,arguments,void 0,function*({key:r}){var n;if(!(Cd(r)&&r.crv==="Ed25519"))throw new Error("Ed25519: The provided key is not an Ed25519 private JWK.");let{d:i}=r,a=xce(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return Fs(this,arguments,void 0,function*({privateKey:r}){if(!Cd(r))throw new Error("Ed25519: The provided key is not a valid OKP private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return Fs(this,arguments,void 0,function*({publicKey:r}){if(!eI(r))throw new Error("Ed25519: The provided key is not a valid OKP public key.");return tt.base64Url(r.x).toUint8Array()})}static sign(e){return Fs(this,arguments,void 0,function*({key:r,data:n}){let i=yield Hu.privateKeyToBytes({privateKey:r});return Df.sign(n,i)})}static validatePublicKey(e){return Fs(this,arguments,void 0,function*({publicKeyBytes:r}){try{Df.ExtendedPoint.fromHex(r).assertValidity()}catch{return!1}return!0})}static verify(e){return Fs(this,arguments,void 0,function*({key:r,signature:n,data:i}){let a=yield Hu.publicKeyToBytes({publicKey:r});return Df.verify(n,i,a)})}},Sd=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Pce=class extends Ax{bytesToPrivateKey(t){return Sd(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"Ed25519":{let n=yield Mi.bytesToPrivateKey({privateKeyBytes:r});return n.alg="EdDSA",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}bytesToPublicKey(t){return Sd(this,arguments,void 0,function*({algorithm:e,publicKeyBytes:r}){switch(e){case"Ed25519":{let n=yield Mi.bytesToPublicKey({publicKeyBytes:r});return n.alg="EdDSA",n}default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Sd(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let r=yield Mi.computePublicKey({key:e});return r.alg="EdDSA",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Sd(this,arguments,void 0,function*({algorithm:e}){switch(e){case"Ed25519":{let r=yield Mi.generateKey();return r.alg="EdDSA",r}}})}getPublicKey(t){return Sd(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":{let r=yield Mi.getPublicKey({key:e});return r.alg="EdDSA",r}default:throw new Error(`Unsupported curve: ${e.crv}`)}})}sign(t){return Sd(this,arguments,void 0,function*({key:e,data:r}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"Ed25519":return yield Mi.sign({key:e,data:r});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}verify(t){return Sd(this,arguments,void 0,function*({key:e,signature:r,data:n}){if(!eI(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) public key.");switch(e.crv){case"Ed25519":return yield Mi.verify({key:e,signature:r,data:n});default:throw new Error(`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Sd(this,arguments,void 0,function*({privateKey:e}){switch(e.crv){case"Ed25519":return yield Mi.privateKeyToBytes({privateKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}publicKeyToBytes(t){return Sd(this,arguments,void 0,function*({publicKey:e}){switch(e.crv){case"Ed25519":return yield Mi.publicKeyToBytes({publicKey:e});default:throw new Ys(zo.AlgorithmNotSupported,`Curve not supported: ${e.crv}`)}})}},_ce=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Ece=class extends Ax{digest(t){return _ce(this,arguments,void 0,function*({algorithm:e,data:r}){switch(e){case"SHA-256":return yield Yq.digest({data:r})}})}},zu=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Sce=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},Vh=class Aw{static bytesToPrivateKey(e){return zu(this,arguments,void 0,function*({privateKeyBytes:r}){let n=kw.getPublicKey(r),i={kty:"OKP",crv:"X25519",d:tt.uint8Array(r).toBase64Url(),x:tt.uint8Array(n).toBase64Url()};return i.kid=yield lr({jwk:i}),i})}static bytesToPublicKey(e){return zu(this,arguments,void 0,function*({publicKeyBytes:r}){let n={kty:"OKP",crv:"X25519",x:tt.uint8Array(r).toBase64Url()};return n.kid=yield lr({jwk:n}),n})}static computePublicKey(e){return zu(this,arguments,void 0,function*({key:r}){let n=yield Aw.privateKeyToBytes({privateKey:r}),i=kw.getPublicKey(n),a={kty:"OKP",crv:"X25519",x:tt.uint8Array(i).toBase64Url()};return a.kid=yield lr({jwk:a}),a})}static generateKey(){return zu(this,void 0,void 0,function*(){let e=kw.utils.randomPrivateKey(),r=yield Aw.bytesToPrivateKey({privateKeyBytes:e});return r.kid=yield lr({jwk:r}),r})}static getPublicKey(e){return zu(this,arguments,void 0,function*({key:r}){var n;if(!(Cd(r)&&r.crv==="X25519"))throw new Error("X25519: The provided key is not an X25519 private JWK.");let{d:i}=r,a=Sce(r,["d"]);return(n=a.kid)!==null&&n!==void 0||(a.kid=yield lr({jwk:a})),a})}static privateKeyToBytes(e){return zu(this,arguments,void 0,function*({privateKey:r}){if(!Cd(r))throw new Error("X25519: The provided key is not a valid OKP private key.");return tt.base64Url(r.d).toUint8Array()})}static publicKeyToBytes(e){return zu(this,arguments,void 0,function*({publicKey:r}){if(!eI(r))throw new Error("X25519: The provided key is not a valid OKP public key.");return tt.base64Url(r.x).toUint8Array()})}static sharedSecret(e){return zu(this,arguments,void 0,function*({privateKeyA:r,publicKeyB:n}){if("x"in r&&"x"in n&&r.x===n.x)throw new Error("X25519: ECDH shared secret cannot be computed from a single key pair's public and private keys.");let i=yield Aw.privateKeyToBytes({privateKey:r}),a=yield Aw.publicKeyToBytes({publicKey:n});return kw.getSharedSecret(i,a)})}},Pw=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Tce=class extends Ax{bytesToPrivateKey(t){return Pw(this,arguments,void 0,function*({algorithm:e,privateKeyBytes:r}){switch(e){case"X25519":return Vh.bytesToPrivateKey({privateKeyBytes:r});default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}computePublicKey(t){return Pw(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return Vh.computePublicKey({key:e});default:throw new Ys(zo.AlgorithmNotSupported,`Unsupported curve: ${e.crv}`)}})}generateKey(t){return Pw(this,arguments,void 0,function*({algorithm:e}){switch(e){case"X25519":return Vh.generateKey();default:throw new Ys(zo.AlgorithmNotSupported,`Algorithm not supported: ${e}`)}})}getPublicKey(t){return Pw(this,arguments,void 0,function*({key:e}){if(!Cd(e))throw new TypeError("Invalid key provided. Must be an octet key pair (OKP) private key.");switch(e.crv){case"X25519":return Vh.getPublicKey({key:e});default:throw new Ys(zo.AlgorithmNotSupported,`Unsupported curve: ${e.crv}`)}})}privateKeyToBytes(t){return Pw(this,arguments,void 0,function*({privateKey:e}){return Vh.privateKeyToBytes({privateKey:e})})}},Td=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},yD={Ed25519:{implementation:Pce,names:["Ed25519"]},secp256k1:{implementation:lK,names:["ES256K","secp256k1"]},secp256r1:{implementation:lK,names:["ES256","secp256r1"]},"SHA-256":{implementation:Ece,names:["SHA-256"]},X25519:{implementation:Tce,names:["X25519"]}},Ka=class{constructor(t){var e;this._algorithmInstances=new Map,this._keyStore=(e=t?.keyStore)!==null&&e!==void 0?e:new Ise}digest(t){return Td(this,arguments,void 0,function*({algorithm:e,data:r}){return yield this.getAlgorithm({algorithm:e}).digest({algorithm:e,data:r})})}exportKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){return yield this.getPrivateKey({keyUri:e})})}generateKey(t){return Td(this,arguments,void 0,function*({algorithm:e}){let r=yield this.getAlgorithm({algorithm:e}).generateKey({algorithm:e});if(r?.kid===void 0)throw new Error("Generated key is missing a required property: kid");let n=`${uK}${r.kid}`;return yield this._keyStore.set(n,r),n})}getKeyUri(t){return Td(this,arguments,void 0,function*({key:e}){let r=yield lr({jwk:e});return`${uK}${r}`})}getPublicKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){let r=yield this.getPrivateKey({keyUri:e}),n=this.getAlgorithmName({key:r});return yield this.getAlgorithm({algorithm:n}).getPublicKey({key:r})})}importKey(t){return Td(this,arguments,void 0,function*({key:e}){var r;if(!Rae(e))throw new TypeError("Invalid key provided. Must be a private key in JWK format.");let n=structuredClone(e);(r=n.kid)!==null&&r!==void 0||(n.kid=yield lr({jwk:n}));let i=yield this.getKeyUri({key:n});return yield this._keyStore.set(i,n),i})}sign(t){return Td(this,arguments,void 0,function*({keyUri:e,data:r}){let n=yield this.getPrivateKey({keyUri:e}),i=this.getAlgorithmName({key:n});return this.getAlgorithm({algorithm:i}).sign({data:r,key:n})})}verify(t){return Td(this,arguments,void 0,function*({key:e,signature:r,data:n}){let i=this.getAlgorithmName({key:e});return this.getAlgorithm({algorithm:i}).verify({key:e,signature:r,data:n})})}getAlgorithm({algorithm:t}){var e;let r=(e=yD[t])===null||e===void 0?void 0:e.implementation;if(!r)throw new Error(`Algorithm not supported: ${t}`);return this._algorithmInstances.has(r)||this._algorithmInstances.set(r,new r),this._algorithmInstances.get(r)}getAlgorithmName({key:t}){let e=t.alg,r=t.crv;for(let n in yD){let i=yD[n];if(e&&i.names.includes(e)||r&&i.names.includes(r))return n}throw new Error(`Unable to determine algorithm based on provided input: alg=${e}, crv=${r}`)}getPrivateKey(t){return Td(this,arguments,void 0,function*({keyUri:e}){let r=yield this._keyStore.get(e);if(!r)throw new Error(`Key not found: ${e}`);return r})}},kce=class DD{static getJoseSignatureAlgorithmFromPublicKey(e){let r={Ed25519:"EdDSA","P-256":"ES256","P-384":"ES384","P-521":"ES512",secp256k1:"ES256K"};if(e.alg&&Object.values(r).includes(e.alg))return e.alg;if(e.crv&&Object.keys(r).includes(e.crv))return r[e.crv];throw new Error(`Unable to determine algorithm based on provided input: alg=${e.alg}, crv=${e.crv}. Supported 'alg' values: ${Object.values(r).join(", ")}. Supported 'crv' values: ${Object.keys(r).join(", ")}.`)}static randomBytes(e){return xae(e)}static randomUuid(){return J1.randomUUID()}static randomPin({length:e}){if(3>e||e>10)throw new Error("randomPin() can securely generate a PIN between 3 to 10 digits.");let r=Math.pow(10,e)-1,n;if(e<=6){let i=Math.pow(10,e);do{let a=DD.randomBytes(Math.ceil(e/2));n=new DataView(a.buffer).getUint16(0,!1)%i}while(n>r)}else{let i=Math.pow(10,10);do{let a=DD.randomBytes(4);n=new DataView(a.buffer).getUint32(0,!1)%i}while(n>r)}return n.toString().padStart(e,"0")}},Ace=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];be=class{constructor(t,e,r){this.major=t,this.majorEncoded=t<<5,this.name=e,this.terminal=r}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,e){return t===e||t.major===e.major&&t.name===e.name}};be.uint=new be(0,"uint",!0);be.negint=new be(1,"negint",!0);be.bytes=new be(2,"bytes",!0);be.string=new be(3,"string",!0);be.array=new be(4,"array",!1);be.map=new be(5,"map",!1);be.tag=new be(6,"tag",!1);be.float=new be(7,"float",!0);be.false=new be(7,"false",!0);be.true=new be(7,"true",!0);be.null=new be(7,"null",!0);be.undefined=new be(7,"undefined",!0);be.break=new be(7,"break",!0);Qe=class{constructor(t,e,r){this.type=t,this.value=e,this.encodedLength=r,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}},Xw=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Rce=new TextEncoder;Cce=24,$ce=200,Oce=Xw?t=>t.length>=Cce?globalThis.Buffer.from(t):mK(t):t=>t.length>=$ce?Rce.encode(t):mK(t),kd=t=>Uint8Array.from(t),Bce=Xw?(t,e,r)=>gx(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),jce=Xw?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),iL(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},Mce=Xw?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);Nce=256,sL=class{constructor(t=Nce){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let e=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let r=e.length-(this.maxCursor-this.cursor)-1;e.set(t,r)}else{if(e){let r=e.length-(this.maxCursor-this.cursor)-1;r<e.length&&(this.chunks[this.chunks.length-1]=e.subarray(0,r),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(e=Mce(this.chunkSize),this.chunks.push(e),this.maxCursor+=e.length,this._initReuseChunk===null&&(this._initReuseChunk=e),e.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let e;if(this.chunks.length===1){let r=this.chunks[0];t&&this.cursor>r.length/2?(e=this.cursor===r.length?r:r.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):e=Bce(r,0,this.cursor)}else e=jce(this.chunks,this.cursor);return t&&this.reset(),e}},Uce=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let e=this.dest.subarray(0,this.cursor);return t&&this.reset(),e}},an="CBOR decode error:",aL="CBOR encode error:",e0=[];e0[23]=1;e0[24]=2;e0[25]=3;e0[26]=5;e0[27]=9;Ni=[24,256,65536,4294967296,BigInt("18446744073709551616")];Vf.encodedSize=function(t){return ta.encodedSize(t.value)};ta.encodedSize=function(t){return t<Ni[0]?1:t<Ni[1]?2:t<Ni[2]?3:t<Ni[3]?5:9};Vf.compareTokens=function(t,e){return t.value<e.value?-1:t.value>e.value?1:0};rI=BigInt(-1),cL=BigInt(1);nI.encodedSize=function(t){let e=t.value,r=typeof e=="bigint"?e*rI-cL:e*-1-1;return r<Ni[0]?1:r<Ni[1]?2:r<Ni[2]?3:r<Ni[3]?5:9};nI.compareTokens=function(t,e){return t.value<e.value?1:t.value>e.value?-1:0};Ix.encodedSize=function(t){let e=wx(t);return ta.encodedSize(e.length)+e.length};Ix.compareTokens=function(t,e){return Xce(wx(t),wx(e))};yK=new TextDecoder,ede=32;ade=Ix;iI.compareTokens=Vf.compareTokens;iI.encodedSize=function(t){return ta.encodedSize(t.value)};oI.compareTokens=Vf.compareTokens;oI.encodedSize=function(t){return ta.encodedSize(t.value)};sI.compareTokens=Vf.compareTokens;sI.encodedSize=function(t){return ta.encodedSize(t.value)};dL=20,uL=21,lL=22,fL=23;cI.encodedSize=function(t,e){let r=t.value;if(r===!1||r===!0||r===null||r===void 0)return 1;if(!e||e.float64!==!0){hL(r);let n=dI(Na,1);if(r===n||Number.isNaN(r))return 3;if(mL(r),n=uI(Na,1),r===n)return 5}return 9};pL=new ArrayBuffer(9),Ws=new DataView(pL,1),Na=new Uint8Array(pL,0);cI.compareTokens=Vf.compareTokens;Ce=[];for(let t=0;t<=23;t++)Ce[t]=rr;Ce[24]=Kce;Ce[25]=qce;Ce[26]=Lce;Ce[27]=zce;Ce[28]=rr;Ce[29]=rr;Ce[30]=rr;Ce[31]=rr;for(let t=32;t<=55;t++)Ce[t]=rr;Ce[56]=Fce;Ce[57]=Gce;Ce[58]=Wce;Ce[59]=Hce;Ce[60]=rr;Ce[61]=rr;Ce[62]=rr;Ce[63]=rr;for(let t=64;t<=87;t++)Ce[t]=Vce;Ce[88]=Jce;Ce[89]=Zce;Ce[90]=Yce;Ce[91]=Qce;Ce[92]=rr;Ce[93]=rr;Ce[94]=rr;Ce[95]=Rx("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)Ce[t]=rde;Ce[120]=nde;Ce[121]=ide;Ce[122]=ode;Ce[123]=sde;Ce[124]=rr;Ce[125]=rr;Ce[126]=rr;Ce[127]=Rx("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)Ce[t]=cde;Ce[152]=dde;Ce[153]=ude;Ce[154]=lde;Ce[155]=fde;Ce[156]=rr;Ce[157]=rr;Ce[158]=rr;Ce[159]=pde;for(let t=160;t<=183;t++)Ce[t]=hde;Ce[184]=mde;Ce[185]=yde;Ce[186]=gde;Ce[187]=wde;Ce[188]=rr;Ce[189]=rr;Ce[190]=rr;Ce[191]=vde;for(let t=192;t<=215;t++)Ce[t]=bde;Ce[216]=xde;Ce[217]=Pde;Ce[218]=_de;Ce[219]=Ede;Ce[220]=rr;Ce[221]=rr;Ce[222]=rr;Ce[223]=rr;for(let t=224;t<=243;t++)Ce[t]=Rx("simple values are not supported");Ce[244]=rr;Ce[245]=rr;Ce[246]=rr;Ce[247]=Sde;Ce[248]=Rx("simple values are not supported");Ce[249]=kde;Ce[250]=Ade;Ce[251]=Dde;Ce[252]=rr;Ce[253]=rr;Ce[254]=rr;Ce[255]=Tde;Od=[];for(let t=0;t<24;t++)Od[t]=new Qe(be.uint,t,1);for(let t=-1;t>=-24;t--)Od[31-t]=new Qe(be.negint,t,1);Od[64]=new Qe(be.bytes,new Uint8Array(0),1);Od[96]=new Qe(be.string,"",1);Od[128]=new Qe(be.array,0,1);Od[160]=new Qe(be.map,0,1);Od[244]=new Qe(be.false,!1,1);Od[245]=new Qe(be.true,!0,1);Od[246]=new Qe(be.null,null,1);Cde=Object.freeze({float64:!0,mapSorter:Mde,quickEncodeToken:Rde});Ode=$de(),Bde=new sL,gK=class gL{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${aL} object contains circular references`);return new gL(r,e)}},Fu={null:new Qe(be.null,null),undefined:new Qe(be.undefined,void 0),true:new Qe(be.true,!0),false:new Qe(be.false,!1),emptyArray:new Qe(be.array,0),emptyMap:new Qe(be.map,0)},Xu={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new Qe(be.float,t):t>=0?new Qe(be.uint,t):new Qe(be.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new Qe(be.uint,t):new Qe(be.negint,t)},Uint8Array(t,e,r,n){return new Qe(be.bytes,t)},string(t,e,r,n){return new Qe(be.string,t)},boolean(t,e,r,n){return t?Fu.true:Fu.false},null(t,e,r,n){return Fu.null},undefined(t,e,r,n){return Fu.undefined},ArrayBuffer(t,e,r,n){return new Qe(be.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new Qe(be.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Fu.emptyArray,new Qe(be.break)]:Fu.emptyArray;n=gK.createCheck(n,t);let i=[],a=0;for(let s of t)i[a++]=Z1(s,r,n);return r.addBreakTokens?[new Qe(be.array,t.length),i,new Qe(be.break)]:[new Qe(be.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",a=i?t.keys():Object.keys(t),s=i?t.size:a.length,o;if(s){o=new Array(s),n=gK.createCheck(n,t);let d=!i&&r.ignoreUndefinedProperties,u=0;for(let c of a){let l=i?t.get(c):t[c];d&&l===void 0||(o[u++]=[Z1(c,r,n),Z1(l,r,n)])}u<s&&(o.length=u)}return o?.length?(jde(o,r),r.addBreakTokens?[new Qe(be.map,o.length),o,new Qe(be.break)]:[new Qe(be.map,o.length),o]):r.addBreakTokens===!0?[Fu.emptyMap,new Qe(be.break)]:Fu.emptyMap}};Xu.Map=Xu.Object;Xu.Buffer=Xu.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Xu[`${t}Array`]=Xu.DataView;Qje=be.uint.majorEncoded,Xje=be.negint.majorEncoded,e4e=be.bytes.majorEncoded,t4e=be.string.majorEncoded,r4e=be.array.majorEncoded,n4e=be.float.majorEncoded|dL,i4e=be.float.majorEncoded|uL,o4e=be.float.majorEncoded|lL,s4e=be.float.majorEncoded|fL,a4e=BigInt(-1),c4e=BigInt(1);d4e=Symbol.for("DONE"),u4e=Symbol.for("BREAK");(function(t){t[t.OKP=1]="OKP",t[t.EC2=2]="EC2",t[t.Symmetric=4]="Symmetric"})(vK||(vK={}));(function(t){t[t.P256=1]="P256",t[t.P384=2]="P384",t[t.P521=3]="P521",t[t.X25519=4]="X25519",t[t.X448=5]="X448",t[t.Ed25519=6]="Ed25519",t[t.Ed448=7]="Ed448",t[t.Secp256k1=8]="Secp256k1"})(io||(io={}));(function(t){t[t.EdDSA=-8]="EdDSA",t[t.ES256=-7]="ES256",t[t.ES384=-35]="ES384",t[t.ES512=-36]="ES512",t[t.ES256K=-47]="ES256K"})(Zs||(Zs={}));(function(t){t[t.Kty=1]="Kty",t[t.Kid=2]="Kid",t[t.Alg=3]="Alg",t[t.KeyOps=4]="KeyOps",t[t.BaseIv=5]="BaseIv"})(bK||(bK={}));(function(t){t[t.Crv=-1]="Crv",t[t.X=-2]="X",t[t.Y=-3]="Y",t[t.D=-4]="D"})(xK||(xK={}));l4e={"P-256":io.P256,"P-384":io.P384,"P-521":io.P521,X25519:io.X25519,Ed25519:io.Ed25519,Ed448:io.Ed448,secp256k1:io.Secp256k1},f4e={[io.P256]:"P-256",[io.P384]:"P-384",[io.P521]:"P-521",[io.X25519]:"X25519",[io.Ed25519]:"Ed25519",[io.Ed448]:"Ed448",[io.Secp256k1]:"secp256k1"},p4e={EdDSA:Zs.EdDSA,ES256:Zs.ES256,ES384:Zs.ES384,ES512:Zs.ES512,ES256K:Zs.ES256K},h4e={[Zs.EdDSA]:"EdDSA",[Zs.ES256]:"ES256",[Zs.ES384]:"ES384",[Zs.ES512]:"ES512",[Zs.ES256K]:"ES256K"};(function(t){t[t.Alg=1]="Alg",t[t.Crit=2]="Crit",t[t.ContentType=3]="ContentType",t[t.Kid=4]="Kid"})(PK||(PK={}));(function(t){t[t.Iss=1]="Iss",t[t.Sub=2]="Sub",t[t.Aud=3]="Aud",t[t.Exp=4]="Exp",t[t.Nbf=5]="Nbf",t[t.Iat=6]="Iat",t[t.Cti=7]="Cti",t[t.Nonce=10]="Nonce",t[t.Ueid=256]="Ueid",t[t.Sueids=257]="Sueids",t[t.Oemid=258]="Oemid",t[t.Hwmodel=259]="Hwmodel",t[t.Hwversion=260]="Hwversion",t[t.Secboot=262]="Secboot",t[t.Dbgstat=263]="Dbgstat",t[t.Location=264]="Location",t[t.Profile=265]="Profile",t[t.Submods=266]="Submods",t[t.Measres=272]="Measres",t[t.Intuse=268]="Intuse"})(_K||(_K={}));(function(t){t[t.Enabled=0]="Enabled",t[t.Disabled=1]="Disabled",t[t.DisabledSinceBoot=2]="DisabledSinceBoot",t[t.DisabledPermanently=3]="DisabledPermanently",t[t.DisabledFullyAndPermanently=4]="DisabledFullyAndPermanently"})(EK||(EK={}));(function(t){t[t.Unrestricted=1]="Unrestricted",t[t.Restricted=2]="Restricted",t[t.SecureRestricted=3]="SecureRestricted",t[t.Hardware=4]="Hardware"})(SK||(SK={}));lI={};LD(lI,{extractDidFragment:()=>To,getServices:()=>Ude,getVerificationMethodByKey:()=>Kde,getVerificationMethodTypes:()=>vL,getVerificationMethods:()=>Cx,getVerificationRelationshipsById:()=>bL,isDidService:()=>xL,isDidVerificationMethod:()=>vx,isDwnDidService:()=>qde,isPortableDid:()=>$x,keyBytesToMultibaseId:()=>PL,multibaseIdToKeyBytes:()=>_L});ea=class EL{constructor({uri:e,document:r,metadata:n,keyManager:i}){this.uri=e,this.document=r,this.metadata=n,this.keyManager=i}async export(){if(!(Array.isArray(this.document.verificationMethod)&&this.document.verificationMethod.length>0))throw new Error(`DID document for '${this.uri}' is missing verification methods`);let e=JSON.parse(JSON.stringify({uri:this.uri,document:this.document,metadata:this.metadata}));if("exportKey"in this.keyManager&&typeof this.keyManager.exportKey=="function"){let r=[];for(let n of this.document.verificationMethod){if(!n.publicKeyJwk)throw new Error(`Verification method '${n.id}' does not contain a public key in JWK format`);let i=await this.keyManager.getKeyUri({key:n.publicKeyJwk}),a=await this.keyManager.exportKey({keyUri:i});r.push({...a})}e.privateKeys=r}return e}async getSigner(e){let r=this.document.verificationMethod?.find(s=>To(s.id)===(To(e?.methodId)??To(this.document.assertionMethod?.[0])));if(!(r&&r.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");let n=await this.keyManager.getKeyUri({key:r.publicKeyJwk}),i=await this.keyManager.getPublicKey({keyUri:n}),a=this.keyManager;return{algorithm:kce.getJoseSignatureAlgorithmFromPublicKey(i),keyId:r.id,async sign({data:s}){return await a.sign({data:s,keyUri:n})},async verify({data:s,signature:o}){return await a.verify({data:s,key:i,signature:o})}}}static async import({portableDid:e,keyManager:r=new Ka}){let n=Cx({didDocument:e.document});if(n.length===0)throw new Xe("invalidDidDocument","At least one verification method is required but 0 were given");for(let i of e.privateKeys??[]){let a=await r.getKeyUri({key:i});await r.getPublicKey({keyUri:a}).then(()=>!0).catch(()=>!1)||await r.importKey({key:i})}for(let i of n){if(!i.publicKeyJwk)throw new Error(`Verification method '${i.id}' does not contain a public key in JWK format`);let a=await r.getKeyUri({key:i.publicKeyJwk});await r.getPublicKey({keyUri:a})}return new EL({uri:e.uri,document:e.document,metadata:e.metadata,keyManager:r})}},n0=class{static async getSigningMethod(t){throw new Error("Not implemented: Classes extending DidMethod must implement getSigningMethod()")}static async resolve(t,e){throw new Error("Not implemented: Classes extending DidMethod must implement resolve()")}},SL=(t=>(t[t.Discoverable=0]="Discoverable",t[t.Organization=1]="Organization",t[t.Government=2]="Government",t[t.Corporation=3]="Corporation",t[t.LocalBusiness=4]="LocalBusiness",t[t.SoftwarePackage=5]="SoftwarePackage",t[t.WebApp=6]="WebApp",t[t.FinancialInstitution=7]="FinancialInstitution",t))(SL||{}),fI=(t=>(t[t.Ed25519=0]="Ed25519",t[t.secp256k1=1]="secp256k1",t[t.secp256r1=2]="secp256r1",t[t.X25519=3]="X25519",t))(fI||{}),TL=(t=>(t.authentication="auth",t.assertionMethod="asm",t.capabilityDelegation="del",t.capabilityInvocation="inv",t.keyAgreement="agm",t))(TL||{}),TK="0123456789abcdef",kL=[],kK=[];for(let t=0;t<256;t++)kL[t]=TK[t>>4&15]+TK[t&15],t<16&&(t<10?kK[48+t]=t:kK[87+t]=t);Lde=t=>{let e=t.length,r="",n=0;for(;n<e;)r+=kL[t[n++]];return r},zde=(t,e=0)=>{let r=t.length||0;if(!e){let s=r;for(;s--;)e+=t[s].length}let n=new Uint8Array(e),i=e,a=r;for(;a--;)i-=t[a].length,n.set(t[a],i);return n},AK="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Fde=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(_w=0;_w<AK.length;_w++)Fde[AK.charCodeAt(_w)]=_w;Gde=new TextDecoder,AL=(t,e)=>e?new TextDecoder(e).decode(t):Gde.decode(t),Wde=new TextEncoder,$d=t=>Wde.encode(t),DK=typeof window<"u"?window:self,IK=DK.crypto||DK.msCrypto||{},m4e=IK.subtle||IK.webkitSubtle;sr.bytes=-1;sr._floatConversionDetected=!1;sr._encode=function(t,e){if(e!=null)switch(DL(e)){case"object":sr.dict(t,e);break;case"map":sr.dictMap(t,e);break;case"array":sr.list(t,e);break;case"set":sr.listSet(t,e);break;case"string":sr.string(t,e);break;case"number":sr.number(t,e);break;case"boolean":sr.number(t,e);break;case"arraybufferview":sr.buffer(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));break;case"arraybuffer":sr.buffer(t,new Uint8Array(e));break}};Ox=new Uint8Array([101]),IL=new Uint8Array([100]),RL=new Uint8Array([108]);sr.buffer=function(t,e){t.push($d(e.length+":"),e)};sr.string=function(t,e){t.push($d($d(e).byteLength+":"+e))};sr.number=function(t,e){if(Number.isInteger(e))return t.push($d("i"+BigInt(e)+"e"));let r=2147483648,n=e/r<<0,i=e%r<<0,a=n*r+i;t.push($d("i"+a+"e")),a!==e&&!sr._floatConversionDetected&&(sr._floatConversionDetected=!0,console.warn('WARNING: Possible data corruption detected with value "'+e+'":','Bencoding only defines support for integers, value was converted to "'+a+'"'),console.trace())};sr.dict=function(t,e){t.push(IL);let r=0,n,i=Object.keys(e).sort(),a=i.length;for(;r<a;r++)n=i[r],e[n]!=null&&(sr.string(t,n),sr._encode(t,e[n]));t.push(Ox)};sr.dictMap=function(t,e){t.push(IL);let r=Array.from(e.keys()).sort();for(let n of r)e.get(n)!=null&&(ArrayBuffer.isView(n)?sr._encode(t,n):sr.string(t,String(n)),sr._encode(t,e.get(n)));t.push(Ox)};sr.list=function(t,e){let r=0,n=e.length;for(t.push(RL);r<n;r++)e[r]!=null&&sr._encode(t,e[r]);t.push(Ox)};sr.listSet=function(t,e){t.push(RL);for(let r of e)r!=null&&sr._encode(t,r);t.push(Ox)};Hde=sr,Vde=105,Jde=58,Zde=100,Yde=108,pI=101;pt.bytes=0;pt.position=0;pt.data=null;pt.encoding=null;pt.next=function(){switch(pt.data[pt.position]){case Zde:return pt.dictionary();case Yde:return pt.list();case Vde:return pt.integer();default:return pt.buffer()}};pt.find=function(t){let e=pt.position,r=pt.data.length,n=pt.data;for(;e<r;){if(n[e]===t)return e;e++}throw new Error('Invalid data: Missing delimiter "'+String.fromCharCode(t)+'" [0x'+t.toString(16)+"]")};pt.dictionary=function(){pt.position++;let t={};for(;pt.data[pt.position]!==pI;){let e=pt.buffer(),r=AL(e);r.includes("\uFFFD")&&(r=Lde(e)),t[r]=pt.next()}return pt.position++,t};pt.list=function(){pt.position++;let t=[];for(;pt.data[pt.position]!==pI;)t.push(pt.next());return pt.position++,t};pt.integer=function(){let t=pt.find(pI),e=CL(pt.data,pt.position+1,t);return pt.position+=t+1-pt.position,e};pt.buffer=function(){let t=pt.find(Jde),e=CL(pt.data,pt.position,t),r=++t+e;return pt.position=r,pt.encoding?AL(pt.data.slice(t,r)):pt.data.slice(t,r)};Qde=pt;$L=Bx,iue=$L,OL={encode:Hde,decode:Qde,byteLength:$L,encodingLength:iue},oue=/^(\d{1,3}\.){3,3}\d{1,3}$/,sue=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,Ac={name:"v4",size:4,isFormat:t=>oue.test(t),encode(t,e,r){r=~~r,e=e||new Uint8Array(r+4);let n=t.length,i=0;for(let a=0;a<n;){let s=t.charCodeAt(a++);s===46?(e[r++]=i,i=0):i=i*10+(s-48)}return e[r]=i,e},decode(t,e){return e=~~e,`${t[e++]}.${t[e++]}.${t[e++]}.${t[e]}`}},Qu={name:"v6",size:16,isFormat:t=>t.length>0&&sue.test(t),encode(t,e,r){r=~~r;let n=r+16,i=-1,a=0,s=0,o=!0,d=!1;e=e||new Uint8Array(r+16);for(let u=0;u<t.length;u++){let c=t.charCodeAt(u);c===58?(o?i!==-1?(r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2):r<n&&(i=r):(d===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=a>>8),r<n-1&&(e[r+1]=a&255),r+=2),a=0,s=0),o=!0,d=!1):c===46?(r<n&&(e[r]=s),r++,s=0,a=0,o=!1,d=!0):(o=!1,c>=97?c-=87:c>=65?c-=55:(c-=48,s=s*10+c),a=(a<<4)+c)}if(o===!1)d===!0?(r<n&&(e[r]=s),r++):(r<n&&(e[r]=a>>8),r<n-1&&(e[r+1]=a&255),r+=2);else if(i===0)r<n&&(e[r]=0),r<n-1&&(e[r+1]=0),r+=2;else if(i!==-1){r+=2;for(let u=Math.min(r-1,n-1);u>=i+2;u--)e[u]=e[u-2];e[i]=0,e[i+1]=0,i=r}if(i!==r&&i!==-1)for(r>n-2&&(r=n-2);n>i;)e[--n]=r<n&&r>i?e[--r]:0;else for(;r<n;)e[r++]=0;return e},decode(t,e){e=~~e;let r="";for(let n=0;n<16;n+=2)n!==0&&(r+=":"),r+=(t[e+n]<<8|t[e+n+1]).toString(16);return r.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};Jw.bytes=0;o0.bytes=0;qf=t=>t instanceof Uint8Array;Dw={},UL=new Array(255);for(let t=0;t<=15;t+=1){let e=t.toString(16),r=e.toUpperCase();for(let n=0;n<=15;n+=1){let i=n.toString(16),a=i.toUpperCase(),s=t<<4|n,o=`${e}${i}`;UL[s]=o,Dw[o]=s,Dw[`${r}${i}`]=s,Dw[`${e}${a}`]=s,Dw[`${r}${a}`]=s}}mue=Math.pow(2,24),yue=Math.pow(2,16),gue=Math.pow(2,8),Id=(t,e)=>t[e]*mue+t[e+1]*yue+t[e+2]*gue+t[e+3],Rt=(t,e)=>t[e]<<8|t[e+1],Rd=(t,e,r)=>(e=+e,t[r+3]=e,e=e>>>8,t[r+2]=e,e=e>>>8,t[r+1]=e,e=e>>>8,t[r]=e,r+4),rt=(t,e,r)=>(t[r]=e>>8,t[r+1]=e&255,r+2);vue=0,$K=32768,ID=32768,bue=~ID,KL=32768,xue=~KL;He=Cr({encode(t,e,r){e||(e=new Uint8Array(He.encodingLength(t))),r||(r=0);let n=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let a=i.split(".");for(let s=0;s<a.length;s++){let o=mI(e,a[s],r+1);e[r]=o,r+=o+1}}return e[r++]=0,He.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=[],n=e,i=0,a=0,s=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let o=t[e++];if(a+=s?0:1,o===0)break;if(o&192)if((o&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let d=Rt(t,e-1)-49152;if(d>=n)throw new Error("Cannot decode name (bad pointer)");e=d,n=d,a+=s?0:1,s=!0}else throw new Error("Cannot decode name (bad label)");else{if(e+o>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=o+1,i>254)throw new Error("Cannot decode name (name too long)");r.push(o0(t,e,e+o)),e+=o,a+=s?0:o}}return He.decode.bytes=a,r.length===0?".":r.join(".")},encodingLength(t){return t==="."||t===".."?1:el(t.replace(/^\.|\.$/gm,""))+2}}),Wn=Cr({encode(t,e,r){e||(e=new Uint8Array(Wn.encodingLength(t))),r||(r=0);let n=mI(e,t,r+1);return e[r]=n,Wn.encode.bytes=n+1,e},decode(t,e){e||(e=0);let r=t[e],n=o0(t,e+1,e+1+r);return Wn.decode.bytes=r+1,n},encodingLength(t){return el(t)+1}}),Jh=Cr({bytes:12,encode(t,e,r){e||(e=new Uint8Array(Jh.encodingLength(t))),r||(r=0);let n=(t.flags||0)&32767,i=t.type==="response"?$K:vue;return rt(e,t.id||0,r),rt(e,n|i,r+2),rt(e,t.questions.length,r+4),rt(e,t.answers.length,r+6),rt(e,t.authorities.length,r+8),rt(e,t.additionals.length,r+10),e},decode(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=Rt(t,e+2);return{id:Rt(t,e),type:r&$K?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:lue(r>>11&15),flag_aa:(r>>10&1)===1,flag_tc:(r>>9&1)===1,flag_rd:(r>>8&1)===1,flag_ra:(r>>7&1)===1,flag_z:(r>>6&1)===1,flag_ad:(r>>5&1)===1,flag_cd:(r>>4&1)===1,rcode:uue(r&15),questions:new Array(Rt(t,e+4)),answers:new Array(Rt(t,e+6)),authorities:new Array(Rt(t,e+8)),additionals:new Array(Rt(t,e+10))}},encodingLength(){return 12}}),Y1=Cr({encode(t,e,r){e||(e=new Uint8Array(Y1.encodingLength(t))),r||(r=0);let n=t.length;return rt(e,n,r),bs(t,e,r+2,0,n),Y1.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=Rt(t,e),n=t.slice(e+2,e+2+r);return Y1.decode.bytes=r+2,n},encodingLength(t){return t.length+2}}),Q1=Cr({encode(t,e,r){return e||(e=new Uint8Array(Q1.encodingLength(t))),r||(r=0),He.encode(t,e,r+2),rt(e,He.encode.bytes,r),Q1.encode.bytes=He.encode.bytes+2,e},decode(t,e){e||(e=0);let r=Rt(t,e),n=He.decode(t,e+2);return Q1.decode.bytes=r+2,n},encodingLength(t){return He.encodingLength(t)+2}}),X1=Cr({encode(t,e,r){e||(e=new Uint8Array(X1.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.mname,e,r),r+=He.encode.bytes,He.encode(t.rname,e,r),r+=He.encode.bytes,Rd(e,t.serial||0,r),r+=4,Rd(e,t.refresh||0,r),r+=4,Rd(e,t.retry||0,r),r+=4,Rd(e,t.expire||0,r),r+=4,Rd(e,t.minimum||0,r),r+=4,rt(e,r-n-2,n),X1.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=He.decode(t,e),e+=He.decode.bytes,n.rname=He.decode(t,e),e+=He.decode.bytes,n.serial=Id(t,e),e+=4,n.refresh=Id(t,e),e+=4,n.retry=Id(t,e),e+=4,n.expire=Id(t,e),e+=4,n.minimum=Id(t,e),e+=4,X1.decode.bytes=e-r,n},encodingLength(t){return 22+He.encodingLength(t.mname)+He.encodingLength(t.rname)}}),ex=Cr({encode(t,e,r){Array.isArray(t)||(t=[t]);for(let i=0;i<t.length;i++)if(typeof t[i]=="string"&&(t[i]=hI(t[i])),!qf(t[i]))throw new Error("Must be a Buffer");e||(e=new Uint8Array(ex.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(i){e[r++]=i.length,bs(i,e,r,0,i.length),r+=i.length}),rt(e,r-n-2,n),ex.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=Rt(t,e);e+=2;let i=[];for(;n>0;){let a=t[e++];if(--n,n<a)throw new Error("Buffer overflow");i.push(t.slice(e,e+a)),e+=a,n-=a}return ex.decode.bytes=e-r,i},encodingLength(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=el(r)+1:e+=r.length+1}),e}}),tx=Cr({encode(t,e,r){e||(e=new Uint8Array(tx.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=hI(t)),t||(t=new Uint8Array(0));let n=r;r+=2;let i=t.length;return bs(t,e,r,0,i),r+=i,rt(e,r-n-2,n),tx.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=Rt(t,e);e+=2;let i=t.slice(e,e+n);return e+=n,tx.decode.bytes=e-r,i},encodingLength(t){return t?(qf(t)?t.length:el(t))+2:2}}),rx=Cr({encode(t,e,r){e||(e=new Uint8Array(rx.encodingLength(t))),r||(r=0);let n=r;return r+=2,Wn.encode(t.cpu,e,r),r+=Wn.encode.bytes,Wn.encode(t.os,e,r),r+=Wn.encode.bytes,rt(e,r-n-2,n),rx.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=Wn.decode(t,e),e+=Wn.decode.bytes,n.os=Wn.decode(t,e),e+=Wn.decode.bytes,rx.decode.bytes=e-r,n},encodingLength(t){return Wn.encodingLength(t.cpu)+Wn.encodingLength(t.os)+2}}),rm=Cr({encode(t,e,r){return e||(e=new Uint8Array(rm.encodingLength(t))),r||(r=0),He.encode(t,e,r+2),rt(e,He.encode.bytes,r),rm.encode.bytes=He.encode.bytes+2,e},decode(t,e){e||(e=0);let r=He.decode(t,e+2);return rm.decode.bytes=He.decode.bytes+2,r},encodingLength(t){return He.encodingLength(t)+2}}),nx=Cr({encode(t,e,r){e||(e=new Uint8Array(nx.encodingLength(t))),r||(r=0),rt(e,t.priority||0,r+2),rt(e,t.weight||0,r+4),rt(e,t.port||0,r+6),He.encode(t.target,e,r+8);let n=He.encode.bytes+6;return rt(e,n,r),nx.encode.bytes=n+2,e},decode(t,e){e||(e=0);let r=Rt(t,e),n={};return n.priority=Rt(t,e+2),n.weight=Rt(t,e+4),n.port=Rt(t,e+6),n.target=He.decode(t,e+8),nx.decode.bytes=r+2,n},encodingLength(t){return 8+He.encodingLength(t.target)}}),Ju=Cr({encode(t,e,r){let n=Ju.encodingLength(t);return e||(e=new Uint8Array(Ju.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=Ju.ISSUER_CRITICAL),rt(e,n-2,r),r+=2,e[r]=t.flags||0,r+=1,Wn.encode(t.tag,e,r),r+=Wn.encode.bytes,mI(e,t.value,r),r+=el(t.value),Ju.encode.bytes=n,e},decode(t,e){e||(e=0);let r=Rt(t,e);e+=2;let n=e,i={};return i.flags=t[e],e+=1,i.tag=Wn.decode(t,e),e+=Wn.decode.bytes,i.value=o0(t,e,n+r),i.issuerCritical=!!(i.flags&Ju.ISSUER_CRITICAL),Ju.decode.bytes=r+2,i},encodingLength(t){return Wn.encodingLength(t.tag)+Wn.encodingLength(t.value)+2}});Ju.ISSUER_CRITICAL=128;ix=Cr({encode(t,e,r){e||(e=new Uint8Array(ix.encodingLength(t))),r||(r=0);let n=r;return r+=2,rt(e,t.preference||0,r),r+=2,He.encode(t.exchange,e,r),r+=He.encode.bytes,rt(e,r-n-2,n),ix.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=Rt(t,e),e+=2,n.exchange=He.decode(t,e),e+=He.decode.bytes,ix.decode.bytes=e-r,n},encodingLength(t){return 4+He.encodingLength(t.exchange)}}),qL=Cr({encode(t,e,r){return e||(e=new Uint8Array(qL.encodingLength(t))),r||(r=0),rt(e,4,r),r+=2,Ac.encode(t,e,r),e},decode(t,e){return e||(e=0),e+=2,Ac.decode(t,e)},bytes:6}),ox=Cr({encode(t,e,r){return e||(e=new Uint8Array(ox.encodingLength(t))),r||(r=0),rt(e,16,r),r+=2,Qu.encode(t,e,r),ox.encode.bytes=18,e},decode(t,e){e||(e=0),e+=2;let r=Qu.decode(t,e);return ox.decode.bytes=18,r},bytes:18}),OK=t=>new Uint8Array(t),Ad=Cr({encode(t,e,r){e||(e=new Uint8Array(Ad.encodingLength(t))),r||(r=0);let n=r,i=RK(t.code);if(rt(e,i,r),r+=2,t.data)rt(e,t.data.length,r),r+=2,bs(t.data,e,r),r+=t.data.length;else switch(i){case 8:{let a=t.sourcePrefixLength||0,s=t.family||aue(t.ip,OK),o=cue(t.ip,OK),d=Math.ceil(a/8);rt(e,d+4,r),r+=2,rt(e,s,r),r+=2,e[r++]=a,e[r++]=t.scopePrefixLength||0,bs(o,e,r,0,d),r+=d}break;case 11:t.timeout?(rt(e,2,r),r+=2,rt(e,t.timeout,r),r+=2):(rt(e,0,r),r+=2);break;case 12:{let a=t.length||0;rt(e,a,r),r+=2,e.fill(0,r,r+a),r+=a}break;case 14:{let a=t.tags.length*2;rt(e,a,r),r+=2;for(let s of t.tags)rt(e,s,r),r+=2}break;default:throw new Error(`Unknown roption code: ${t.code}`)}return Ad.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={};r.code=Rt(t,e),r.type=fue(r.code),e+=2;let n=Rt(t,e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=Rt(t,e),e+=2,r.sourcePrefixLength=t[e++],r.scopePrefixLength=t[e++];{let i=new Uint8Array(r.family===1?4:16);bs(t,i,0,e,e+n-4),r.ip=due(i)}break;case 11:n>0&&(r.timeout=Rt(t,e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(Rt(t,e)),e+=2}return Ad.decode.bytes=n+4,r},encodingLength(t){if(t.data)return t.data.length+4;switch(RK(t.code)){case 8:{let e=t.sourcePrefixLength||0;return Math.ceil(e/8)+8}case 11:return typeof t.timeout=="number"?6:4;case 12:return t.length+4;case 14:return 4+t.tags.length*2}throw new Error(`Unknown roption code: ${t.code}`)}}),Zu=Cr({encode(t,e,r){e||(e=new Uint8Array(Zu.encodingLength(t))),r||(r=0);let n=r,i=em(t,Ad);return rt(e,i,r),r=Bw(t,Ad,e,r+2),Zu.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r=e,n=[],i=Rt(t,e);e+=2;let a=0;for(;i>0;)n[a++]=Ad.decode(t,e),e+=Ad.decode.bytes,i-=Ad.decode.bytes;return Zu.decode.bytes=e-r,n},encodingLength(t){return 2+em(t||[],Ad)}}),kc=Cr({encode(t,e,r){e||(e=new Uint8Array(kc.encodingLength(t))),r||(r=0);let n=r,i=t.key;if(!qf(i))throw new Error("Key must be a Buffer");return r+=2,rt(e,t.flags,r),r+=2,e[r]=kc.PROTOCOL_DNSSEC,r+=1,e[r]=t.algorithm,r+=1,bs(i,e,r,0,i.length),r+=i.length,kc.encode.bytes=r-n,rt(e,kc.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=Rt(t,e);if(e+=2,n.flags=Rt(t,e),e+=2,t[e]!==kc.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t[e],e+=1,n.key=t.slice(e,r+i+2),e+=n.key.length,kc.decode.bytes=e-r,n},encodingLength(t){return 6+el(t.key)}});kc.PROTOCOL_DNSSEC=3;kc.ZONE_KEY=128;kc.SECURE_ENTRYPOINT=32768;Iw=Cr({encode(t,e,r){e||(e=new Uint8Array(Iw.encodingLength(t))),r||(r=0);let n=r,i=t.signature;if(!qf(i))throw new Error("Signature must be a Buffer");return r+=2,rt(e,Vw(t.typeCovered),r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.labels,r+=1,Rd(e,t.originalTTL,r),r+=4,Rd(e,t.expiration,r),r+=4,Rd(e,t.inception,r),r+=4,rt(e,t.keyTag,r),r+=2,He.encode(t.signersName,e,r),r+=He.encode.bytes,bs(i,e,r,0,i.length),r+=i.length,Iw.encode.bytes=r-n,rt(e,Iw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=Rt(t,e);return e+=2,n.typeCovered=jx(Rt(t,e)),e+=2,n.algorithm=t[e],e+=1,n.labels=t[e],e+=1,n.originalTTL=Id(t,e),e+=4,n.expiration=Id(t,e),e+=4,n.inception=Id(t,e),e+=4,n.keyTag=Rt(t,e),e+=2,n.signersName=He.decode(t,e),e+=He.decode.bytes,n.signature=t.slice(e,r+i+2),e+=n.signature.length,Iw.decode.bytes=e-r,n},encodingLength(t){return 20+He.encodingLength(t.signersName)+el(t.signature)}}),Rw=Cr({encode(t,e,r){e||(e=new Uint8Array(Rw.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.mbox||".",e,r),r+=He.encode.bytes,He.encode(t.txt||".",e,r),r+=He.encode.bytes,Rw.encode.bytes=r-n,rt(e,Rw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=He.decode(t,e)||".",e+=He.decode.bytes,n.txt=He.decode(t,e)||".",e+=He.decode.bytes,Rw.decode.bytes=e-r,n},encodingLength(t){return 2+He.encodingLength(t.mbox||".")+He.encodingLength(t.txt||".")}}),vs=Cr({encode(t,e,r){e||(e=new Uint8Array(vs.encodingLength(t))),r||(r=0);let n=r,i=[];for(let a=0;a<t.length;a++){let s=Vw(t[a]);i[s>>8]===void 0&&(i[s>>8]=[]),i[s>>8][s>>3&31]|=1<<7-(s&7)}for(let a=0;a<i.length;a++)if(i[a]!==void 0){let s=hI(i[a]);e[r]=a,r+=1,e[r]=s.length,r+=1,bs(s,e,r,0,s.length),r+=s.length}return vs.encode.bytes=r-n,e},decode(t,e,r){e||(e=0);let n=e,i=[];for(;e-n<r;){let a=t[e];e+=1;let s=t[e];e+=1;for(let o=0;o<s;o++){let d=t[e+o];for(let u=0;u<8;u++)if(d&1<<7-u){let c=jx(a<<8|o<<3|u);i.push(c)}}e+=s}return vs.decode.bytes=e-n,i},encodingLength(t){let e=[];for(let n=0;n<t.length;n++){let i=Vw(t[n]);e[i>>8]=Math.max(e[i>>8]||0,i&255)}let r=0;for(let n=0;n<e.length;n++)e[n]!==void 0&&(r+=2+Math.ceil((e[n]+1)/8));return r}}),Cw=Cr({encode(t,e,r){e||(e=new Uint8Array(Cw.encodingLength(t))),r||(r=0);let n=r;return r+=2,He.encode(t.nextDomain,e,r),r+=He.encode.bytes,vs.encode(t.rrtypes,e,r),r+=vs.encode.bytes,Cw.encode.bytes=r-n,rt(e,Cw.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=Rt(t,e);return e+=2,n.nextDomain=He.decode(t,e),e+=He.decode.bytes,n.rrtypes=vs.decode(t,e,i-(e-r)),e+=vs.decode.bytes,Cw.decode.bytes=e-r,n},encodingLength(t){return 2+He.encodingLength(t.nextDomain)+vs.encodingLength(t.rrtypes)}}),$w=Cr({encode(t,e,r){e||(e=new Uint8Array($w.encodingLength(t))),r||(r=0);let n=r,i=t.salt;if(!qf(i))throw new Error("salt must be a Buffer");let a=t.nextDomain;if(!qf(a))throw new Error("nextDomain must be a Buffer");return r+=2,e[r]=t.algorithm,r+=1,e[r]=t.flags,r+=1,rt(e,t.iterations,r),r+=2,e[r]=i.length,r+=1,bs(i,e,r,0,i.length),r+=i.length,e[r]=a.length,r+=1,bs(a,e,r,0,a.length),r+=a.length,vs.encode(t.rrtypes,e,r),r+=vs.encode.bytes,$w.encode.bytes=r-n,rt(e,$w.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=Rt(t,e);e+=2,n.algorithm=t[e],e+=1,n.flags=t[e],e+=1,n.iterations=Rt(t,e),e+=2;let a=t[e];e+=1,n.salt=t.slice(e,e+a),e+=a;let s=t[e];return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=vs.decode(t,e,i-(e-r)),e+=vs.decode.bytes,$w.decode.bytes=e-r,n},encodingLength(t){return 8+t.salt.length+t.nextDomain.length+vs.encodingLength(t.rrtypes)}}),Ow=Cr({encode(t,e,r){e||(e=new Uint8Array(Ow.encodingLength(t))),r||(r=0);let n=r,i=t.digest;if(!qf(i))throw new Error("Digest must be a Buffer");return r+=2,rt(e,t.keyTag,r),r+=2,e[r]=t.algorithm,r+=1,e[r]=t.digestType,r+=1,bs(i,e,r,0,i.length),r+=i.length,Ow.encode.bytes=r-n,rt(e,Ow.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={},i=Rt(t,e);return e+=2,n.keyTag=Rt(t,e),e+=2,n.algorithm=t[e],e+=1,n.digestType=t[e],e+=1,n.digest=t.slice(e,r+i+2),e+=n.digest.length,Ow.decode.bytes=e-r,n},encodingLength(t){return 6+el(t.digest)}}),Xh=Cr({encode(t,e,r){e||(e=new Uint8Array(Xh.encodingLength(t))),r||(r=0);let n=r;r+=2,e[r]=t.algorithm,r+=1,e[r]=t.hash,r+=1;let i=CK(t.fingerprint),a=RD(t.hash);if(i!==a)throw new Error(`Invalid length of fingerprint "${t.fingerprint}" for hashType=${t.hash}: ${i} != ${a}`);return hue(e,t.fingerprint,r,r+=i),Xh.encode.bytes=r-n,rt(e,Xh.encode.bytes-2,n),e},decode(t,e){e||(e=0);let r=e,n={};e+=2,n.algorithm=t[e],e+=1,n.hash=t[e],e+=1;let i=RD(n.hash);return n.fingerprint=pue(t,e,e+i),e+=i,Xh.decode.bytes=e-r,n},encodingLength(t){return 4+CK(t.fingerprint)}});Xh.getFingerprintLengthForHashType=RD;Hs=Cr({encode(t,e,r){e||(e=new Uint8Array(Hs.encodingLength(t))),r||(r=0);let n=r;if(He.encode(t.name,e,r),r+=He.encode.bytes,rt(e,Vw(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");rt(e,t.udpPayloadSize||4096,r+2),e[r+4]=t.extendedRcode||0,e[r+5]=t.ednsVersion||0,rt(e,t.flags||0,r+6),r+=8,Zu.encode(t.options||[],e,r),r+=Zu.encode.bytes}else{let i=ML(t.class===void 0?"IN":t.class);t.flush&&(i|=ID),rt(e,i,r+2),Rd(e,t.ttl||0,r+4),r+=8;let a=gD(t.type);a.encode(t.data,e,r),r+=a.encode.bytes}return Hs.encode.bytes=r-n,e},decode(t,e){e||(e=0);let r={},n=e;if(r.name=He.decode(t,e),e+=He.decode.bytes,r.type=jx(Rt(t,e)),r.type==="OPT")r.udpPayloadSize=Rt(t,e+2),r.extendedRcode=t[e+4],r.ednsVersion=t[e+5],r.flags=Rt(t,e+6),r.flag_do=(r.flags>>15&1)===1,r.options=Zu.decode(t,e+8),e+=8+Zu.decode.bytes;else{let i=Rt(t,e+2);r.ttl=Id(t,e+4),r.class=jL(i&bue),r.flush=!!(i&ID);let a=gD(r.type);r.data=a.decode(t,e+8),e+=8+a.decode.bytes}return Hs.decode.bytes=e-n,r},encodingLength(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return He.encodingLength(t.name)+8+gD(t.type).encodingLength(e)}}),nm=Cr({encode(t,e,r){e||(e=new Uint8Array(nm.encodingLength(t))),r||(r=0);let n=r;return He.encode(t.name,e,r),r+=He.encode.bytes,rt(e,Vw(t.type),r),r+=2,rt(e,ML(t.class===void 0?"IN":t.class),r),r+=2,nm.encode.bytes=r-n,t},decode(t,e){e||(e=0);let r=e,n={};return n.name=He.decode(t,e),e+=He.decode.bytes,n.type=jx(Rt(t,e)),e+=2,n.class=jL(Rt(t,e)),e+=2,n.class&KL&&(n.class&=xue),nm.decode.bytes=e-r,n},encodingLength(t){return He.encodingLength(t.name)+4}}),Pue=1024,Ui={encode:function(t,e,r){let n=!e;n&&(e=new Uint8Array(_ue(t))),r||(r=0);let i=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Jh.encode(t,e,r),r+=Jh.encode.bytes,r=Bw(t.questions,nm,e,r),r=Bw(t.answers,Hs,e,r),r=Bw(t.authorities,Hs,e,r),r=Bw(t.additionals,Hs,e,r),Ui.encode.bytes=r-i,n&&_x.bytes!==e.length?e.slice(0,_x.bytes):e},decode:function(t,e){e||(e=0);let r=e,n=Jh.decode(t,e);return e+=Jh.decode.bytes,e=z1(n.questions,nm,t,e),e=z1(n.answers,Hs,t,e),e=z1(n.authorities,Hs,t,e),e=z1(n.additionals,Hs,t,e),Ui.decode.bytes=e-r,n},encodingLength:function(t){return Jh.encodingLength(t)+em(t.questions||[],nm)+em(t.answers||[],Hs)+em(t.authorities||[],Hs)+em(t.additionals||[],Hs)}};Ui.encode.bytes=0;Ui.decode.bytes=0;xx={encode:function(t,e,r){return e=Ui.encode(bx(t,"query"),e,r),xx.encode.bytes=Ui.encode.bytes,e},decode:function(t,e){let r=Ui.decode(t,e);return xx.decode.bytes=Ui.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return Ui.encodingLength(bx(t,"query"))}};xx.encode.bytes=0;xx.decode.bytes=0;Px={encode:function(t,e,r){return e=Ui.encode(bx(t,"response"),e,r),Px.encode.bytes=Ui.encode.bytes,e},decode:function(t,e){let r=Ui.decode(t,e);return Px.decode.bytes=Ui.decode.bytes,r.questions&&(r.question=r.questions[0],delete r.questions),r},encodingLength:function(t){return Ui.encodingLength(bx(t,"response"))}};Px.encode.bytes=0;Px.decode.bytes=0;_x=Ui.encode,CD=Ui.decode,_ue=Ui.encodingLength;LL.bytes=0;zL.bytes=0;GL="dht";Due=0,Gu=7200,sx=";",So=",",VL={Ed25519:0,ES256K:1,ES256:2,"P-256":2,secp256k1:1,secp256r1:2,X25519:3},JL={0:"EdDSA",1:"ES256K",2:"ES256",3:"ECDH-ES+A256KW"};jK=$.DID_DHT_GATEWAY_URI||"https://enbox-did-dht.fly.dev",YL=class $D extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.verificationMethods?.some(c=>!(c.algorithm in VL)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(c=>"id"in c).map(c=>c.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(c=>!c.id||!c.type||!c.serviceEndpoint))throw new Error("One or more services are missing required properties");let i=await e.generateKey({algorithm:"Ed25519"}),a=await e.getPublicKey({keyUri:i}),s=await tm.identityKeyToIdentifier({identityKey:a}),o={id:s,...r.alsoKnownAs&&{alsoKnownAs:r.alsoKnownAs},...r.controllers&&{controller:r.controllers}},d=[...r.verificationMethods??[]];d?.some(c=>c.id?.split("#").pop()==="0")||d.unshift({algorithm:"Ed25519",id:"0",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]});for(let c of d){let l=c.id&&c.id.split("#").pop()==="0"?i:await e.generateKey({algorithm:c.algorithm}),f=await e.getPublicKey({keyUri:l}),h=c.id??f.kid??await lr({jwk:f});h=`${s}#${To(h)}`,o.verificationMethod??=[],o.verificationMethod.push({id:h,type:"JsonWebKey",controller:c.controller??s,publicKeyJwk:f});for(let p of c.purposes??[])o[p]??=[],o[p].push(h)}r.services?.forEach(c=>{o.service??=[],c.id=`${s}#${c.id.split("#").pop()}`,o.service.push(c)});let u=new ea({uri:s,document:o,metadata:{published:!1,...r.types&&{types:r.types}},keyManager:e});if(r.publish??!0){let c=await $D.publish({did:u,gatewayUri:r.gatewayUri});u.metadata=c.didDocumentMetadata}return u}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==$D.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(!n.document.verificationMethod?.some(i=>i.id?.split("#").pop()==="0"))throw new Xe("invalidDidDocument","DID document must contain an Identity Key");return n}static async getSigningMethod({didDocument:e,methodId:r="#0"}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(a=>To(a.id)===(To(r)??To(e.assertionMethod?.[0])));if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async publish({did:e,gatewayUri:r=jK}){return await MK.put({did:e,gatewayUri:r})}static async resolve(e,r={}){let n=r?.gatewayUri??jK;try{await tm.identifierToIdentityKey({didUri:e});let{didDocument:i,didDocumentMetadata:a}=await MK.get({didUri:e,gatewayUri:n});return{...li,didDocument:i,didDocumentMetadata:a}}catch(i){if(!(i instanceof Xe))throw new Error(i);return{...li,didResolutionMetadata:{error:i.code,...i.message&&{errorMessage:i.message}}}}}};YL.methodName="dht";tl=YL,MK=class Mw{static async get({didUri:e,gatewayUri:r}){let n=tm.identifierToIdentityKeyBytes({didUri:e}),i=await Mw.pkarrGet({gatewayUri:r,publicKeyBytes:n}),a=await tm.parseBep44GetMessage({bep44Message:i}),s=await Mw.fromDnsPacket({didUri:e,dnsPacket:a});return s.didDocumentMetadata.versionId=i.seq.toString(),s}static async put({did:e,gatewayUri:r}){let n=await Mw.toDnsPacket({didDocument:e.document,didMetadata:e.metadata,authoritativeGatewayUris:[r]}),i=await tm.createBep44PutMessage({dnsPacket:n,publicKeyBytes:tm.identifierToIdentityKeyBytes({didUri:e.uri}),signer:await e.getSigner({methodId:"0"})}),a=await Mw.pkarrPut({gatewayUri:r,bep44Message:i});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:a,versionId:i.seq.toString()},didRegistrationMetadata:{}}}static async pkarrGet(e){return Eue(e)}static async pkarrPut(e){return Sue(e)}static async fromDnsPacket(e){return Iue(e)}static async toDnsPacket(e){return Rue(e)}static getUniqueDidSuffix(e){return e.split(":")[2]}},tm=class{static async createBep44PutMessage(t){return Tue(t)}static async identifierToIdentityKey(t){return WL(t)}static identifierToIdentityKeyBytes(t){return yI(t)}static async identityKeyToIdentifier(t){return Aue(t)}static keyConverter(t){return gI(t)}static async parseBep44GetMessage(t){return kue(t)}static parseTxtDataToObject(t){return jw(t)}static parseTxtDataToString(t){return Zw(t)}static async validatePreviousDidProof(t){return HL(t)}static chunkDataIfNeeded(t){return ZL(t)}},An={DeltaExceedsMaximumSize:"DeltaExceedsMaximumSize",DidDocumentPublicKeyIdDuplicated:"DidDocumentPublicKeyIdDuplicated",DidDocumentPublicKeyMissingOrIncorrectType:"DidDocumentPublicKeyMissingOrIncorrectType",DidDocumentServiceIdDuplicated:"DidDocumentServiceIdDuplicated",DidSuffixIncorrectLength:"DidSuffixIncorrectLength",EncodedStringIncorrectEncoding:"EncodedStringIncorrectEncoding",IdNotUsingBase64UrlCharacterSet:"IdNotUsingBase64UrlCharacterSet",IdTooLong:"IdTooLong",JwkEs256kMissingOrInvalidCrv:"JwkEs256kMissingOrInvalidCrv",JwkEs256kMissingOrInvalidKty:"JwkEs256kMissingOrInvalidKty",JwkEs256kHasIncorrectLengthOfX:"JwkEs256kHasIncorrectLengthOfX",JwkEs256kHasIncorrectLengthOfY:"JwkEs256kHasIncorrectLengthOfY",JwkEs256kHasIncorrectLengthOfD:"JwkEs256kHasIncorrectLengthOfD",MultihashStringNotAMultihash:"MultihashStringNotAMultihash",MultihashUnsupportedHashAlgorithm:"MultihashUnsupportedHashAlgorithm",PublicKeyJwkEs256kHasUnexpectedProperty:"PublicKeyJwkEs256kHasUnexpectedProperty",PublicKeyPurposeDuplicated:"PublicKeyPurposeDuplicated",ServiceEndpointCannotBeAnArray:"ServiceEndpointCannotBeAnArray",ServiceEndpointStringNotValidUri:"ServiceEndpointStringNotValidUri",ServiceTypeTooLong:"ServiceTypeTooLong"},Dn=class extends Error{constructor(t,e){super(`${t}: ${e}`),this.code=t,Object.setPrototypeOf(this,new.target.prototype)}},y4e=new Uint8Array(0),Cue=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},$ue=class{constructor(t,e,r){this.name=t,this.prefix=e,this.baseEncode=r}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Oue=class{constructor(t,e,r){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),this.baseDecode=r}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return QL(this,t)}},Bue=class{constructor(t){this.decoders=t}or(t){return QL(this,t)}decode(t){let e=t[0],r=this.decoders[e];if(r)return r.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},QL=(t,e)=>new Bue({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),jue=class{constructor(t,e,r,n){this.name=t,this.prefix=e,this.baseEncode=r,this.baseDecode=n,this.encoder=new $ue(t,e,r),this.decoder=new Oue(t,e,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Mue=({name:t,prefix:e,encode:r,decode:n})=>new jue(t,e,r,n),Nue=(t,e,r,n)=>{let i={};for(let c=0;c<e.length;++c)i[e[c]]=c;let a=t.length;for(;t[a-1]==="=";)--a;let s=new Uint8Array(a*r/8|0),o=0,d=0,u=0;for(let c=0;c<a;++c){let l=i[t[c]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|l,o+=r,o>=8&&(o-=8,s[u++]=255&d>>o)}if(o>=r||255&d<<8-o)throw new SyntaxError("Unexpected end of data");return s},Uue=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,a="",s=0,o=0;for(let d=0;d<t.length;++d)for(o=o<<8|t[d],s+=8;s>r;)s-=r,a+=e[i&o>>s];if(s&&(a+=e[i&o<<r-s]),n)for(;a.length*r&7;)a+="=";return a},Mx=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Mue({prefix:e,name:t,encode(i){return Uue(i,n,r)},decode(i){return Nue(i,n,r,t)}}),g4e=Mx({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),w4e=Mx({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),NK=Mx({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),v4e=Mx({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6}),am=class ax{static encode(e){return NK.baseEncode(e)}static decodeAsBytes(e,r){if(!ax.isBase64UrlString(e))throw new Dn(An.EncodedStringIncorrectEncoding,`Given ${r} must be base64url string.`);return NK.baseDecode(e)}static decodeAsString(e,r){let n=ax.decodeAsBytes(e,r);return ax.bytesToString(n)}static isBase64UrlString(e){return/^[A-Za-z0-9_-]+$/.test(e)}static stringToBytes(e){return new TextEncoder().encode(e)}static bytesToString(e){return new TextDecoder().decode(e)}},Kue=Lf(Uoe(),1);(function(t){t.Public="public",t.Private="private"})(OD||(OD={}));Tc=OD,ys=class{static validateEs256kOperationKey(t,e){let r=new Set(["kty","crv","x","y"]);e===Tc.Private&&r.add("d");for(let n in t)if(!r.has(n))throw new Dn(An.PublicKeyJwkEs256kHasUnexpectedProperty,`SECP256K1 JWK key has unexpected property '${n}'.`);if(t.crv!=="secp256k1")throw new Dn(An.JwkEs256kMissingOrInvalidCrv,`SECP256K1 JWK 'crv' property must be 'secp256k1' but got '${t.crv}.'`);if(t.kty!=="EC")throw new Dn(An.JwkEs256kMissingOrInvalidKty,`SECP256K1 JWK 'kty' property must be 'EC' but got '${t.kty}.'`);if(t.x.length!==43)throw new Dn(An.JwkEs256kHasIncorrectLengthOfX,"SECP256K1 JWK 'x' property must be 43 bytes.");if(t.y.length!==43)throw new Dn(An.JwkEs256kHasIncorrectLengthOfY,"SECP256K1 JWK 'y' property must be 43 bytes.");if(e===Tc.Private&&(t.d===void 0||t.d.length!==43))throw new Dn(An.JwkEs256kHasIncorrectLengthOfD,"SECP256K1 JWK 'd' property must be 43 bytes.")}static validateId(t){if(t.length>50)throw new Dn(An.IdTooLong,`Key ID length ${t.length} exceed max allowed length of 50.`);if(!am.isBase64UrlString(t))throw new Dn(An.IdNotUsingBase64UrlCharacterSet,`Key ID '${t}' is not a Base64URL string.`)}static validatePublicKeyPurposes(t){if(t===void 0)return;let e=new Set;for(let r of t){if(e.has(r))throw new Dn(An.PublicKeyPurposeDuplicated,`Public key purpose '${r}' already specified.`);e.add(r)}}},wI=class{};wI.hashAlgorithmInMultihashCode=18;wI.maxCanonicalizedDeltaSizeInBytes=1e3;Ua=wI,que=Lf(Koe(),1),Yw=class BD{static canonicalizeAsBytes(e){let r=BD.removeAllUndefinedProperties(e),n=que.default(r);return am.stringToBytes(n)}static removeAllUndefinedProperties(e){for(let r in e)typeof e[r]=="object"?BD.removeAllUndefinedProperties(e[r]):e[r]===void 0&&delete e[r];return e}},Lue=XL,UK=128,zue=127,Fue=~zue,Gue=Math.pow(2,31);Wue=jD,Hue=128,KK=127;Vue=Math.pow(2,7),Jue=Math.pow(2,14),Zue=Math.pow(2,21),Yue=Math.pow(2,28),Que=Math.pow(2,35),Xue=Math.pow(2,42),ele=Math.pow(2,49),tle=Math.pow(2,56),rle=Math.pow(2,63),nle=function(t){return t<Vue?1:t<Jue?2:t<Zue?3:t<Yue?4:t<Que?5:t<Xue?6:t<ele?7:t<tle?8:t<rle?9:10},ile={encode:Lue,decode:Wue,encodingLength:nle},ole=ile,Ex=ole,qK=(t,e=0)=>[Ex.decode(t,e),Ex.decode.bytes],LK=(t,e,r=0)=>(Ex.encode(t,e,r),e),zK=t=>Ex.encodingLength(t),FK=(t,e)=>{let r=e.byteLength,n=zK(t),i=n+zK(r),a=new Uint8Array(i+r);return LK(t,a,0),LK(r,a,n),a.set(e,i),new e9(t,r,e,a)},sle=t=>{let e=Cue(t),[r,n]=qK(e),[i,a]=qK(e.subarray(n)),s=e.subarray(n+a);if(s.byteLength!==i)throw new Error("Incorrect length");return new e9(r,i,s,e)},e9=class{constructor(t,e,r,n){this.code=t,this.size=e,this.digest=r,this.bytes=n}},t9=({name:t,code:e,encode:r})=>new ale(t,e,r),ale=class{constructor(t,e,r){this.name=t,this.code=e,this.encode=r}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?FK(this.code,e):e.then(r=>FK(this.code,r))}else throw Error("Unknown type, must be binary type")}},r9=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),GK=t9({name:"sha2-256",code:18,encode:r9("SHA-256")}),b4e=t9({name:"sha2-512",code:19,encode:r9("SHA-512")}),Ew=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},ws=class Nw{static hash(e,r){return Ew(this,void 0,void 0,function*(){let n;switch(r){case 18:n=(yield GK.digest(e)).bytes;break;default:throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static hashAsNonMultihashBytes(e,r){return Ew(this,void 0,void 0,function*(){let n;switch(r){case 18:n=yield GK.encode(e);break;default:throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Hash algorithm defined in multihash code ${r} is not supported.`)}return n})}static canonicalizeThenHashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=Yw.canonicalizeAsBytes(e);return yield Nw.hashThenEncode(n,r)})}static canonicalizeThenDoubleHashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=Yw.canonicalizeAsBytes(e),i=yield Nw.hashAsNonMultihashBytes(n,r);return yield Nw.hashThenEncode(i,r)})}static hashThenEncode(e,r){return Ew(this,void 0,void 0,function*(){let n=yield Nw.hash(e,r);return am.encode(n)})}static validateEncodedHashComputedUsingSupportedHashAlgorithm(e,r){let n,i=am.decodeAsBytes(e,r);try{n=sle(i)}catch{throw new Dn(An.MultihashStringNotAMultihash,`Given ${r} string '${e}' is not a multihash after decoding.`)}let a=Ua.hashAlgorithmInMultihashCode;if(a!==n.code)throw new Dn(An.MultihashUnsupportedHashAlgorithm,`Given ${r} uses unsupported multihash algorithm with code ${n.code}, should use ${a} or change IonSdkConfig to desired hashing algorithm.`)}};(function(t){t.Create="create",t.Update="update",t.Deactivate="deactivate",t.Recover="recover"})(MD||(MD={}));F1=MD;(function(t){t.Replace="replace",t.AddPublicKeys="add-public-keys",t.RemovePublicKeys="remove-public-keys",t.AddServices="add-services",t.RemoveServices="remove-services"})(ND||(ND={}));Hh=ND,G1=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},n9=class Gs{static createCreateRequest(e){return G1(this,void 0,void 0,function*(){let r=e.recoveryKey,n=e.updateKey,i=e.document.publicKeys,a=e.document.services;ys.validateEs256kOperationKey(r,Tc.Public),ys.validateEs256kOperationKey(n,Tc.Public),Gs.validateDidDocumentKeys(i),Gs.validateServices(a);let s=Ua.hashAlgorithmInMultihashCode,o=[{action:Hh.Replace,document:e.document}],d={updateCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(n,s),patches:o};Gs.validateDeltaSize(d);let u={deltaHash:yield ws.canonicalizeThenHashThenEncode(d,s),recoveryCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(r,s)};return{type:F1.Create,suffixData:u,delta:d}})}static createDeactivateRequest(e){return G1(this,void 0,void 0,function*(){Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.recoveryPublicKey,Tc.Public);let r=Ua.hashAlgorithmInMultihashCode,n=yield ws.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i={didSuffix:e.didSuffix,recoveryKey:e.recoveryPublicKey},a=yield e.signer.sign({alg:"ES256K"},i);return{type:F1.Deactivate,didSuffix:e.didSuffix,revealValue:n,signedData:a}})}static createRecoverRequest(e){return G1(this,void 0,void 0,function*(){Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.recoveryPublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextRecoveryPublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextUpdatePublicKey,Tc.Public),Gs.validateDidDocumentKeys(e.document.publicKeys),Gs.validateServices(e.document.services);let r=Ua.hashAlgorithmInMultihashCode,n=yield ws.canonicalizeThenHashThenEncode(e.recoveryPublicKey,r),i=[{action:Hh.Replace,document:e.document}],a=yield ws.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,r),s={patches:i,updateCommitment:a},o=yield ws.canonicalizeThenHashThenEncode(s,r),d={recoveryCommitment:yield ws.canonicalizeThenDoubleHashThenEncode(e.nextRecoveryPublicKey,r),recoveryKey:e.recoveryPublicKey,deltaHash:o},u=yield e.signer.sign({alg:"ES256K"},d);return{type:F1.Recover,didSuffix:e.didSuffix,revealValue:n,delta:s,signedData:u}})}static createUpdateRequest(e){return G1(this,void 0,void 0,function*(){if(Gs.validateDidSuffix(e.didSuffix),ys.validateEs256kOperationKey(e.updatePublicKey,Tc.Public),ys.validateEs256kOperationKey(e.nextUpdatePublicKey,Tc.Public),Gs.validateServices(e.servicesToAdd),Gs.validateDidDocumentKeys(e.publicKeysToAdd),e.idsOfServicesToRemove!==void 0)for(let p of e.idsOfServicesToRemove)ys.validateId(p);if(e.idsOfPublicKeysToRemove!==void 0)for(let p of e.idsOfPublicKeysToRemove)ys.validateId(p);let r=[],n=e.servicesToAdd;if(n!==void 0&&n.length>0){let p={action:Hh.AddServices,services:n};r.push(p)}let i=e.idsOfServicesToRemove;if(i!==void 0&&i.length>0){let p={action:Hh.RemoveServices,ids:i};r.push(p)}let a=e.publicKeysToAdd;if(a!==void 0&&a.length>0){let p={action:Hh.AddPublicKeys,publicKeys:a};r.push(p)}let s=e.idsOfPublicKeysToRemove;if(s!==void 0&&s.length>0){let p={action:Hh.RemovePublicKeys,ids:s};r.push(p)}let o=Ua.hashAlgorithmInMultihashCode,d=yield ws.canonicalizeThenHashThenEncode(e.updatePublicKey,o),u=yield ws.canonicalizeThenDoubleHashThenEncode(e.nextUpdatePublicKey,o),c={patches:r,updateCommitment:u},l=yield ws.canonicalizeThenHashThenEncode(c,o),f={updateKey:e.updatePublicKey,deltaHash:l},h=yield e.signer.sign({alg:"ES256K"},f);return{type:F1.Update,didSuffix:e.didSuffix,revealValue:d,delta:c,signedData:h}})}static validateDidSuffix(e){ws.validateEncodedHashComputedUsingSupportedHashAlgorithm(e,"didSuffix")}static validateDidDocumentKeys(e){if(e===void 0)return;let r=new Set;for(let n of e){if(Array.isArray(n.publicKeyJwk))throw new Dn(An.DidDocumentPublicKeyMissingOrIncorrectType,"DID Document key 'publicKeyJwk' property is not a non-array object.");if(ys.validateId(n.id),r.has(n.id))throw new Dn(An.DidDocumentPublicKeyIdDuplicated,`DID Document key with ID '${n.id}' already exists.`);r.add(n.id),ys.validatePublicKeyPurposes(n.purposes)}}static validateServices(e){if(e!==void 0&&e.length!==0){let r=new Set;for(let n of e){if(Gs.validateService(n),r.has(n.id))throw new Dn(An.DidDocumentServiceIdDuplicated,"Service id has to be unique");r.add(n.id)}}}static validateService(e){ys.validateId(e.id);let r=30;if(e.type.length>r){let n=`Service endpoint type length ${e.type.length} exceeds max allowed length of ${r}.`;throw new Dn(An.ServiceTypeTooLong,n)}if(Array.isArray(e.serviceEndpoint)){let n="Service endpoint value cannot be an array.";throw new Dn(An.ServiceEndpointCannotBeAnArray,n)}if(typeof e.serviceEndpoint=="string"&&Kue.parse(e.serviceEndpoint).error!==void 0)throw new Dn(An.ServiceEndpointStringNotValidUri,`Service endpoint string '${e.serviceEndpoint}' is not a URI.`)}static validateDeltaSize(e){let r=Yw.canonicalizeAsBytes(e);if(r.length>Ua.maxCanonicalizedDeltaSizeInBytes){let n=`Delta of ${r.length} bytes exceeded limit of ${Ua.maxCanonicalizedDeltaSizeInBytes} bytes.`;throw new Dn(An.DeltaExceedsMaximumSize,n)}}},WK=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},cle=class i9{static createLongFormDid(e){return WK(this,void 0,void 0,function*(){let r=yield n9.createCreateRequest(e),n=yield i9.computeDidUniqueSuffix(r.suffixData),i;Ua.network===void 0||Ua.network==="mainnet"?i=`did:ion:${n}`:i=`did:ion:${Ua.network}:${n}`;let a={suffixData:r.suffixData,delta:r.delta},s=Yw.canonicalizeAsBytes(a),o=am.encode(s);return`${i}:${o}`})}static computeDidUniqueSuffix(e){return WK(this,void 0,void 0,function*(){let r=Yw.canonicalizeAsBytes(e),n=yield ws.hash(r,Ua.hashAlgorithmInMultihashCode);return am.encode(n)})}},Bi=2n**255n-19n,cx=2n**252n+27742317777372353535851937790883648493n,UD=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,KD=0x6666666666666666666666666666666666666666666666666666666666666658n,W1={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:Bi,n:cx,h:8,Gx:UD,Gy:KD},Lo=(t="")=>{throw new Error(t)},o9=t=>typeof t=="string",vI=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?Lo("Uint8Array expected"):t,cm=t=>new Uint8Array(t),dle=(t,e)=>vI(o9(t)?xI(t):cm(t),e),st=(t,e=Bi)=>{let r=t%e;return r>=0n?r:e+r},HK=t=>t instanceof dm?t:Lo("Point expected"),dm=class Zh{constructor(e,r,n,i){this.ex=e,this.ey=r,this.ez=n,this.et=i}static fromAffine(e){return new Zh(e.x,e.y,1n,st(e.x*e.y))}static fromHex(e,r=!0){let{d:n}=W1;e=dle(e,32);let i=e.slice();i[31]=e[31]&-129;let a=lle(i);a===0n||(r&&!(0n<a&&a<Bi)&&Lo("bad y coord 1"),!r&&!(0n<a&&a<2n**256n)&&Lo("bad y coord 2"));let s=st(a*a),o=st(s-1n),d=st(n*s+1n),{isValid:u,value:c}=ple(o,d);u||Lo("bad y coordinate 3");let l=(c&1n)===1n;return(e[31]&128)!==0!==l&&(c=st(-c)),new Zh(c,a,1n,st(c*a))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:r,ey:n,ez:i}=this,{ex:a,ey:s,ez:o}=HK(e),d=st(r*o),u=st(a*i),c=st(n*o),l=st(s*i);return d===u&&c===l}is0(){return this.equals(dx)}negate(){return new Zh(st(-this.ex),this.ey,this.ez,st(-this.et))}double(){let{ex:e,ey:r,ez:n}=this,{a:i}=W1,a=st(e*e),s=st(r*r),o=st(2n*st(n*n)),d=st(i*a),u=e+r,c=st(st(u*u)-a-s),l=d+s,f=l-o,h=d-s,p=st(c*f),m=st(l*h),g=st(c*h),_=st(f*l);return new Zh(p,m,_,g)}add(e){let{ex:r,ey:n,ez:i,et:a}=this,{ex:s,ey:o,ez:d,et:u}=HK(e),{a:c,d:l}=W1,f=st(r*s),h=st(n*o),p=st(a*l*u),m=st(i*d),g=st((r+n)*(s+o)-f-h),_=st(m-p),v=st(m+p),E=st(h-c*f),T=st(g*_),D=st(v*E),R=st(g*E),N=st(_*v);return new Zh(T,D,N,R)}mul(e,r=!0){if(e===0n)return r===!0?Lo("cannot multiply by 0"):dx;if(typeof e=="bigint"&&0n<e&&e<cx||Lo("invalid scalar, must be < L"),!r&&this.is0()||e===1n)return this;if(this.equals(Sx))return yle(e).p;let n=dx,i=Sx;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):r&&(i=i.add(a));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(W1.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(cx/2n,!1).double();return cx%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:r,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=a9(n);return st(n*i)!==1n&&Lo("invalid inverse"),{x:st(e*i),y:st(r*i)}}toRawBytes(){let{x:e,y:r}=this.toAffine(),n=ule(r);return n[31]|=e&1n?128:0,n}toHex(){return bI(this.toRawBytes())}};dm.BASE=new dm(UD,KD,1n,st(UD*KD));dm.ZERO=new dm(0n,1n,1n,0n);({BASE:Sx,ZERO:dx}=dm),s9=(t,e)=>t.toString(16).padStart(e,"0"),bI=t=>Array.from(t).map(e=>s9(e,2)).join(""),xI=t=>{let e=t.length;(!o9(t)||e%2)&&Lo("hex invalid 1");let r=cm(e/2);for(let n=0;n<r.length;n++){let i=n*2,a=t.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&Lo("hex invalid 2"),r[n]=s}return r},ule=t=>xI(s9(t,32*2)).reverse(),lle=t=>BigInt("0x"+bI(cm(vI(t)).reverse())),JK=(...t)=>{let e=cm(t.reduce((n,i)=>n+vI(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},a9=(t,e=Bi)=>{(t===0n||e<=0n)&&Lo("no inverse n="+t+" mod="+e);let r=st(t,e),n=e,i=0n,a=1n,s=1n,o=0n;for(;r!==0n;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}return n===1n?st(i,e):Lo("no inverse")},_c=(t,e)=>{let r=t;for(;e-- >0n;)r*=r,r%=Bi;return r},fle=t=>{let e=t*t%Bi*t%Bi,r=_c(e,2n)*e%Bi,n=_c(r,1n)*t%Bi,i=_c(n,5n)*n%Bi,a=_c(i,10n)*i%Bi,s=_c(a,20n)*a%Bi,o=_c(s,40n)*s%Bi,d=_c(o,80n)*o%Bi,u=_c(d,80n)*o%Bi,c=_c(u,10n)*i%Bi;return{pow_p_5_8:_c(c,2n)*t%Bi,b2:e}},ZK=19681161376707505956807079304988542015446066515923890162744021073123829784752n,ple=(t,e)=>{let r=st(e*e*e),n=st(r*r*e),i=fle(t*n).pow_p_5_8,a=st(t*r*i),s=st(e*a*a),o=a,d=st(a*ZK),u=s===t,c=s===st(-t),l=s===st(-t*ZK);return u&&(a=o),(c||l)&&(a=d),(st(a)&1n)===1n&&(a=st(-a)),{isValid:u||c,value:a}},YK=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,hle={bytesToHex:bI,hexToBytes:xI,concatBytes:JK,mod:st,invert:a9,randomBytes:t=>{let e=YK();return e||Lo("crypto.getRandomValues must be defined"),e.getRandomValues(cm(t))},sha512Async:async(...t)=>{let e=YK();e||Lo("crypto.subtle or etc.sha512Async must be defined");let r=JK(...t);return cm(await e.subtle.digest("SHA-512",r.buffer))},sha512Sync:void 0};Object.defineProperties(hle,{sha512Sync:{configurable:!1,get(){return wD},set(t){wD||(wD=t)}}});Cf=8,mle=()=>{let t=[],e=256/Cf+1,r=Sx,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let a=1;a<2**(Cf-1);a++)n=n.add(r),t.push(n);r=n.double()}return t},yle=t=>{let e=VK||(VK=mle()),r=(c,l)=>{let f=l.negate();return c?f:l},n=dx,i=Sx,a=1+256/Cf,s=2**(Cf-1),o=BigInt(2**Cf-1),d=2**Cf,u=BigInt(Cf);for(let c=0;c<a;c++){let l=c*s,f=Number(t&o);t>>=u,f>s&&(f-=d,t+=1n);let h=l,p=l+Math.abs(f)-1,m=c%2!==0,g=f<0;f===0?i=i.add(r(m,e[h])):n=n.add(r(g,e[p]))}return{p:n,f:i}},PI=2n**256n,Nf=PI-0x1000003d1n,_I=PI-0x14551231950b75fc4402da1732fc9bebfn,c9=0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798n,d9=0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n,u9={p:Nf,n:_I,a:0n,b:7n,Gx:c9,Gy:d9},im=32,QK=t=>Ye(Ye(t*t)*t+u9.b),ui=(t="")=>{throw new Error(t)},Nx=t=>typeof t=="bigint",l9=t=>typeof t=="string",vD=t=>Nx(t)&&0n<t&&t<Nf,f9=t=>Nx(t)&&0n<t&&t<_I,p9=(t,e)=>!(t instanceof Uint8Array)||typeof e=="number"&&e>0&&t.length!==e?ui("Uint8Array expected"):t,Qw=t=>new Uint8Array(t),EI=(t,e)=>p9(l9(t)?Ux(t):Qw(t),e),Ye=(t,e=Nf)=>{let r=t%e;return r>=0n?r:e+r},XK=t=>t instanceof um?t:ui("Point expected"),um=class Yh{constructor(e,r,n){this.px=e,this.py=r,this.pz=n}static fromAffine(e){return new Yh(e.x,e.y,1n)}static fromHex(e){e=EI(e);let r,n=e[0],i=e.subarray(1),a=tq(i,0,im),s=e.length;if(s===33&&[2,3].includes(n)){vD(a)||ui("Point hex invalid: x not FE");let o=gle(QK(a)),d=(o&1n)===1n;(n&1)===1!==d&&(o=Ye(-o)),r=new Yh(a,o,1n)}return s===65&&n===4&&(r=new Yh(a,tq(i,im,2*im),1n)),r?r.ok():ui("Point is not on curve")}static fromPrivateKey(e){return Lw.mul(wle(e))}get x(){return this.aff().x}get y(){return this.aff().y}equals(e){let{px:r,py:n,pz:i}=this,{px:a,py:s,pz:o}=XK(e),d=Ye(r*o),u=Ye(a*i),c=Ye(n*o),l=Ye(s*i);return d===u&&c===l}negate(){return new Yh(this.px,Ye(-this.py),this.pz)}double(){return this.add(this)}add(e){let{px:r,py:n,pz:i}=this,{px:a,py:s,pz:o}=XK(e),{a:d,b:u}=u9,c=0n,l=0n,f=0n,h=Ye(u*3n),p=Ye(r*a),m=Ye(n*s),g=Ye(i*o),_=Ye(r+n),v=Ye(a+s);_=Ye(_*v),v=Ye(p+m),_=Ye(_-v),v=Ye(r+i);let E=Ye(a+o);return v=Ye(v*E),E=Ye(p+g),v=Ye(v-E),E=Ye(n+i),c=Ye(s+o),E=Ye(E*c),c=Ye(m+g),E=Ye(E-c),f=Ye(d*v),c=Ye(h*g),f=Ye(c+f),c=Ye(m-f),f=Ye(m+f),l=Ye(c*f),m=Ye(p+p),m=Ye(m+p),g=Ye(d*g),v=Ye(h*v),m=Ye(m+g),g=Ye(p-g),g=Ye(d*g),v=Ye(v+g),p=Ye(m*v),l=Ye(l+p),p=Ye(E*v),c=Ye(_*c),c=Ye(c-p),p=Ye(_*m),f=Ye(E*f),f=Ye(f+p),new Yh(c,l,f)}mul(e,r=!0){if(!r&&e===0n)return ux;if(f9(e)||ui("invalid scalar"),this.equals(Lw))return Ple(e).p;let n=ux,i=Lw;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):r&&(i=i.add(a));return n}mulAddQUns(e,r,n){return this.mul(r,!1).add(e.mul(n,!1)).ok()}toAffine(){let{px:e,py:r,pz:n}=this;if(this.equals(ux))return{x:0n,y:0n};if(n===1n)return{x:e,y:r};let i=m9(n);return Ye(n*i)!==1n&&ui("invalid inverse"),{x:Ye(e*i),y:Ye(r*i)}}assertValidity(){let{x:e,y:r}=this.aff();return(!vD(e)||!vD(r))&&ui("Point invalid: x or y"),Ye(r*r)===QK(e)?this:ui("Point invalid: not on curve")}multiply(e){return this.mul(e)}aff(){return this.toAffine()}ok(){return this.assertValidity()}toHex(e=!0){let{x:r,y:n}=this.aff();return(e?(n&1n)===0n?"02":"03":"04")+rq(r)+(e?"":rq(n))}toRawBytes(e=!0){return Ux(this.toHex(e))}};um.BASE=new um(c9,d9,1n);um.ZERO=new um(0n,1n,0n);({BASE:Lw,ZERO:ux}=um),h9=(t,e)=>t.toString(16).padStart(e,"0"),SI=t=>Array.from(t).map(e=>h9(e,2)).join(""),Ux=t=>{let e=t.length;(!l9(t)||e%2)&&ui("hex invalid 1");let r=Qw(e/2);for(let n=0;n<r.length;n++){let i=n*2,a=t.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&ui("hex invalid 2"),r[n]=s}return r},Kx=t=>BigInt("0x"+(SI(t)||"0")),tq=(t,e,r)=>Kx(t.slice(e,r)),TI=t=>Nx(t)&&t>=0n&&t<PI?Ux(h9(t,2*im)):ui("bigint expected"),rq=t=>SI(TI(t)),nq=(...t)=>{let e=Qw(t.reduce((n,i)=>n+p9(i).length,0)),r=0;return t.forEach(n=>{e.set(n,r),r+=n.length}),e},m9=(t,e=Nf)=>{(t===0n||e<=0n)&&ui("no inverse n="+t+" mod="+e);let r=Ye(t,e),n=e,i=0n,a=1n,s=1n,o=0n;for(;r!==0n;){let d=n/r,u=n%r,c=i-s*d,l=a-o*d;n=r,r=u,i=s,a=o,s=c,o=l}return n===1n?Ye(i,e):ui("no inverse")},gle=t=>{let e=1n;for(let r=t,n=(Nf+1n)/4n;n>0n;n>>=1n)n&1n&&(e=e*r%Nf),r=r*r%Nf;return Ye(e*e)===t?e:ui("sqrt invalid")},wle=t=>(Nx(t)||(t=Kx(EI(t,im))),f9(t)?t:ui("private key out of range")),iq=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;ble={hexToBytes:Ux,bytesToHex:SI,concatBytes:nq,bytesToNumberBE:Kx,numberToBytesBE:TI,mod:Ye,invert:m9,hmacSha256Async:async(t,...e)=>{let r=iq();if(!r)return ui("etc.hmacSha256Async not set");let n=r.subtle,i=await n.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]);return Qw(await n.sign("HMAC",i,nq(...e)))},hmacSha256Sync:lx,hashToPrivateKey:vle,randomBytes:t=>{let e=iq();return e||ui("crypto.getRandomValues must be defined"),e.getRandomValues(Qw(t))}};Object.defineProperties(ble,{hmacSha256Sync:{configurable:!1,get(){return lx},set(t){lx||(lx=t)}}});$f=8,xle=()=>{let t=[],e=256/$f+1,r=Lw,n=r;for(let i=0;i<e;i++){n=r,t.push(n);for(let a=1;a<2**($f-1);a++)n=n.add(r),t.push(n);r=n.double()}return t},Ple=t=>{let e=eq||(eq=xle()),r=(c,l)=>{let f=l.negate();return c?f:l},n=ux,i=Lw,a=1+256/$f,s=2**($f-1),o=BigInt(2**$f-1),d=2**$f,u=BigInt($f);for(let c=0;c<a;c++){let l=c*s,f=Number(t&o);t>>=u,f>s&&(f-=d,t+=1n);let h=l,p=l+Math.abs(f)-1,m=c%2!==0,g=f<0;f===0?i=i.add(r(m,e[h])):n=n.add(r(g,e[p]))}return{p:n,f:i}};(function(t){t.Mainnet="mainnet",t.Testnet="test"})(oq||(oq={}));(function(t){t.Authentication="authentication",t.AssertionMethod="assertionMethod",t.CapabilityInvocation="capabilityInvocation",t.CapabilityDelegation="capabilityDelegation",t.KeyAgreement="keyAgreement"})(sq||(sq={}));Sw=class If{static appendPathToUrl({baseUrl:e,path:r}){let n=new URL(e);return n.pathname=n.pathname.endsWith("/")?n.pathname:n.pathname+"/",n.pathname+=r.startsWith("/")?r.substring(1):r,n.toString()}static async computeLongFormDidUri({recoveryKey:e,updateKey:r,services:n,verificationMethods:i}){let a=await If.createIonDocument({services:n,verificationMethods:i}),s=If.normalizeJwk(e),o=If.normalizeJwk(r);return await cle.createLongFormDid({document:a,recoveryKey:s,updateKey:o})}static async constructCreateRequest({ionDocument:e,recoveryKey:r,updateKey:n}){return await n9.createCreateRequest({document:e,recoveryKey:If.normalizeJwk(r),updateKey:If.normalizeJwk(n)})}static async createIonDocument({services:e,verificationMethods:r}){let n=[];for(let a of r){let s=a.id??a.publicKeyJwk.kid??await lr({jwk:a.publicKeyJwk});s=`${s.split("#").pop()}`;let o={id:s,publicKeyJwk:If.normalizeJwk(a.publicKeyJwk),purposes:a.purposes,type:"JsonWebKey2020"};n.push(o)}let i=e.map(a=>({...a,id:`${a.id.split("#").pop()}`}));return{publicKeys:n,services:i}}static normalizeJwk(e){let r=e.kty,n;if(r==="EC")n={crv:e.crv,kty:e.kty,x:e.x,y:e.y};else if(r==="oct")n={k:e.k,kty:e.kty};else if(r==="OKP")n={crv:e.crv,kty:e.kty,x:e.x};else if(r==="RSA")n={e:e.e,kty:e.kty,n:e.n};else throw new Error(`Unsupported key type: ${r}`);return n}},_le=(t=>(t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t.X25519="X25519",t))(_le||{}),Ele={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},aq="https://ion.tbd.engineering",Sle=class Uw extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.verificationMethods?.some(p=>!(p.algorithm in Ele)))throw new Error("One or more verification method algorithms are not supported");let n=r.verificationMethods?.filter(p=>"id"in p).map(p=>p.id);if(n&&n.length!==new Set(n).size)throw new Error("One or more verification method IDs are not unique");if(r.services?.some(p=>!p.id||!p.type||!p.serviceEndpoint))throw new Error("One or more services are missing required properties");let i={algorithm:"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]},a=[];for(let p of r.verificationMethods??[i]){let m=await e.generateKey({algorithm:p.algorithm}),g=await e.getPublicKey({keyUri:m});a.push({id:p.id,publicKeyJwk:g,purposes:p.purposes??["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]})}let s=await e.generateKey({algorithm:"secp256k1"}),o=await e.getPublicKey({keyUri:s}),d=await e.generateKey({algorithm:"secp256k1"}),u=await e.getPublicKey({keyUri:d}),c=await Sw.computeLongFormDidUri({recoveryKey:o,updateKey:u,services:r.services??[],verificationMethods:a}),{didDocument:l,didResolutionMetadata:f}=await Uw.resolve(c,{gatewayUri:r.gatewayUri});if(l===null)throw new Error(`Unable to resolve DID during creation: ${f?.error}`);let h=new ea({uri:c,document:l,metadata:{published:!1,canonicalId:c.split(":",3).join(":"),recoveryKey:o,updateKey:u},keyManager:e});if(r.publish??!0){let p=await Uw.publish({did:h,gatewayUri:r.gatewayUri});h.metadata=p.didDocumentMetadata}return h}static async getSigningMethod({didDocument:e,methodId:r}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=e.verificationMethod?.find(a=>a.id===(r??e.assertionMethod?.[0]));if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Uw.methodName)throw new Xe("methodNotSupported","Method not supported");return await ea.import({portableDid:e,keyManager:r})}static async publish({did:e,gatewayUri:r=aq}){let n=e.document.verificationMethod?.map(s=>({id:s.id,publicKeyJwk:s.publicKeyJwk,purposes:bL({didDocument:e.document,methodId:s.id})}))??[],i=await Sw.createIonDocument({services:e.document.service??[],verificationMethods:n}),a=await Sw.constructCreateRequest({ionDocument:i,recoveryKey:e.metadata.recoveryKey,updateKey:e.metadata.updateKey});try{let s=Sw.appendPathToUrl({baseUrl:r,path:"/operations"}),o=await fetch(s,{method:"POST",mode:"cors",headers:{"Content-Type":"application/json"},body:JSON.stringify(a),signal:AbortSignal.timeout(3e4)});return{didDocument:e.document,didDocumentMetadata:{...e.metadata,published:o.ok},didRegistrationMetadata:{}}}catch{return{didDocument:null,didDocumentMetadata:{published:!1},didRegistrationMetadata:{error:"internalError",errorMessage:`Failed to publish DID document for: ${e.uri}`}}}}static async resolve(e,r={}){let n=Vn.parse(e);if(!n)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Uw.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let i=r?.gatewayUri??aq;try{let a=Sw.appendPathToUrl({baseUrl:i,path:`/identifiers/${e}`}),s=await fetch(a,{signal:AbortSignal.timeout(3e4)});if(!s.ok)throw new Xe("notFound",`Unable to find DID document for: ${e}`);let{didDocument:o,didDocumentMetadata:d}=await s.json();return{...li,...o&&{didDocument:o},didDocumentMetadata:{published:d?.method?.published,...d}}}catch(a){if(!(a instanceof Xe))throw new Error(a);return{...li,didResolutionMetadata:{error:a.code,...a.message&&{errorMessage:a.message}}}}}};Sle.methodName="ion";y9=class Kw extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),a=await e.getPublicKey({keyUri:i}),s=tt.object(a).toBase64Url(),o=`did:${Kw.methodName}:${s}`,d=(await Kw.resolve(o)).didDocument;return new ea({uri:o,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Vn.parse(e.id);if(r&&r.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.verificationMethod??[];if(!(n&&n.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return n}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Kw.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(n.document.verificationMethod.length!==1)throw new Xe("invalidDidDocument","DID document must contain exactly one verification method");return n}static async resolve(e,r){let n=Vn.parse(e),i;try{i=n?tt.base64Url(n.id).toObject():void 0}catch{}if(!n||!i)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==Kw.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let a={"@context":["https://www.w3.org/ns/did/v1"],id:n.uri},s=`${a.id}#0`;switch(a.verificationMethod=[{id:s,type:"JsonWebKey",controller:a.id,publicKeyJwk:i}],a.authentication=[s],a.assertionMethod=[s],a.capabilityInvocation=[s],a.capabilityDelegation=[s],a.keyAgreement=[s],i.use){case"sig":{delete a.keyAgreement;break}case"enc":{delete a.authentication,delete a.assertionMethod,delete a.capabilityInvocation,delete a.capabilityDelegation;break}}return{...li,didDocument:a}}};y9.methodName="jwk";Jf=y9,Tle={Ed25519:"Ed25519",ES256K:"secp256k1",ES256:"secp256r1","P-256":"secp256r1",secp256k1:"secp256k1",secp256r1:"secp256r1"},fx=class Qh{static async jwkToMulticodec({jwk:e}){let r=[];e.crv&&(r.push(e.crv),e.d?r.push("private"):r.push("public"));let n=r.join(":"),i=Qh.JWK_TO_MULTICODEC[n];if(i===void 0)throw new Error(`Unsupported JWK to Multicodec conversion: '${n}'`);return{code:Xs.getCodeFromName({name:i}),name:i}}static keyCompressor(e){let r={"P-256":no.compressPublicKey,secp256k1:ji.compressPublicKey}[e];if(!r)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${e}`);return r}static keyConverter(e){let r={Ed25519:Mi,"P-256":no,secp256k1:ji}[e];if(!r)throw new Xe("invalidPublicKeyType",`Unsupported curve: ${e}`);return r}static async multicodecToJwk({code:e,name:r}){if(!(r?!e:e))throw new Error("Either 'name' or 'code' must be defined, but not both.");r=r===void 0?Xs.getNameFromCode({code:e}):r;let n=r,i=Qh.MULTICODEC_TO_JWK[n];if(i===void 0)throw new Error("Unsupported Multicodec to JWK conversion");return{...i}}static async publicKeyToMultibaseId({publicKey:e}){if(!(e?.crv&&e.crv in Tle))throw new Xe("invalidPublicKeyType",`Public key contains an unsupported key type: ${e?.crv??"undefined"}`);let r=await Qh.keyConverter(e.crv).publicKeyToBytes({publicKey:e});/^(secp256k1|P-256|P-384|P-521)$/.test(e.crv)&&(r=await Qh.keyCompressor(e.crv)({publicKeyBytes:r}));let{name:n}=await Qh.jwkToMulticodec({jwk:e});return PL({keyBytes:r,multicodecName:n})}};fx.JWK_TO_MULTICODEC={"Ed25519:public":"ed25519-pub","Ed25519:private":"ed25519-priv","secp256k1:public":"secp256k1-pub","secp256k1:private":"secp256k1-priv"},fx.MULTICODEC_PUBLIC_KEY_LENGTH={231:33,237:32},fx.MULTICODEC_TO_JWK={"ed25519-pub":{crv:"Ed25519",kty:"OKP",x:""},"ed25519-priv":{crv:"Ed25519",kty:"OKP",x:"",d:""},"secp256k1-pub":{crv:"secp256k1",kty:"EC",x:"",y:""},"secp256k1-priv":{crv:"secp256k1",kty:"EC",x:"",y:"",d:""}};H1=fx,kle=(t=>(t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.secp256r1="secp256r1",t))(kle||{}),cq={Ed25519VerificationKey2020:"https://w3id.org/security/suites/ed25519-2020/v1",JsonWebKey2020:"https://w3id.org/security/suites/jws-2020/v1"},g9=class Vu extends n0{static async create({keyManager:e=new Ka,options:r={}}={}){if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");if(r.verificationMethods&&r.verificationMethods.length!==1)throw new Error("The 'verificationMethods' option must contain exactly one entry");let n=r.algorithm??r.verificationMethods?.[0]?.algorithm??"Ed25519",i=await e.generateKey({algorithm:n}),a=await e.getPublicKey({keyUri:i}),s=await H1.publicKeyToMultibaseId({publicKey:a}),o=`did:${Vu.methodName}:${s}`,d=(await Vu.resolve(o,r)).didDocument;return new ea({uri:o,document:d,metadata:{},keyManager:e})}static async getSigningMethod({didDocument:e}){let r=Vn.parse(e.id);if(r&&r.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${r.method}`);let[n]=e.assertionMethod||[],i=e.verificationMethod?.find(a=>a.id===n);if(!(i&&i.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return i}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==Vu.methodName)throw new Xe("methodNotSupported","Method not supported");let n=await ea.import({portableDid:e,keyManager:r});if(n.document.verificationMethod.length!==1)throw new Xe("invalidDidDocument","DID document must contain exactly one verification method");return n}static async resolve(e,r){try{let n=await Vu.createDocument({didUri:e,options:r});return{...li,didDocument:n}}catch(n){if(!(n instanceof Xe))throw new Error(n);return{...li,didResolutionMetadata:{error:n.code,...n.message&&{errorMessage:n.message}}}}}static async createDocument({didUri:e,options:r={}}){let{defaultContext:n="https://www.w3.org/ns/did/v1",enableExperimentalPublicKeyTypes:i=!1,publicKeyFormat:a="JsonWebKey2020"}=r,s={id:""},o=Vn.parse(e);if(!o)throw new Xe("invalidDid",`Invalid DID URI: ${e}`);let d=o.id;if(o.method!==Vu.methodName)throw new Xe("methodNotSupported",`Method not supported: ${o.method}`);if(!Vu.validateIdentifier(o))throw new Xe("invalidDid",`Invalid DID URI: ${e}`);let u=await Vu.createSignatureMethod({didUri:e,multibaseValue:d,options:{enableExperimentalPublicKeyTypes:i,publicKeyFormat:a}});s.id=o.uri,s.verificationMethod=[u],s.authentication=[u.id],s.assertionMethod=[u.id],s.capabilityInvocation=[u.id],s.capabilityDelegation=[u.id];let c=[n];return vL({didDocument:s}).forEach(l=>{let f=cq[l];c.push(f)}),s["@context"]=c,s}static async createSignatureMethod({didUri:e,multibaseValue:r,options:n}){let{enableExperimentalPublicKeyTypes:i,publicKeyFormat:a}=n,s={id:"",type:"",controller:""},{keyBytes:o,multicodecCode:d,multicodecName:u}=_L({multibaseKeyId:r}),c=o.byteLength,l=H1.MULTICODEC_PUBLIC_KEY_LENGTH[d];if(c!==l)throw new Xe("invalidPublicKeyLength",`Expected ${c} bytes. Actual: ${l}`);let f=!1;switch(u){case"secp256k1-pub":f=await ji.validatePublicKey({publicKeyBytes:o});break;case"ed25519-pub":f=await Mi.validatePublicKey({publicKeyBytes:o});break}if(!f)throw new Xe("invalidPublicKey","Invalid public key detected.");s.id=`${e}#${r}`;try{new URL(s.id)}catch{throw new Xe("invalidDidUrl","Verification Method ID is not a valid DID URL.")}if(!(a in cq))throw new Xe("unsupportedPublicKeyType",`Unsupported format: ${a}`);if(i===!1&&!["Multikey","JsonWebKey2020","Ed25519VerificationKey2020"].includes(a))throw new Xe("invalidPublicKeyType",`Specified '${a}' without setting enableExperimentalPublicKeyTypes to true.`);if(s.type=a,s.controller=e,a==="Ed25519VerificationKey2020"&&(s.publicKeyMultibase=r),a==="JsonWebKey2020"){let{crv:h}=await H1.multicodecToJwk({code:d});s.publicKeyJwk=await H1.keyConverter(h).bytesToPublicKey({publicKeyBytes:o})}return s}static validateIdentifier(e){let{method:r,id:n}=e,[i]=e.uri.split(":",1);return i==="did"&&r==="key"&&!0&&bD(n)==="String"&&n.startsWith("z")}};g9.methodName="key";qx=g9,Ale=3e4;w9=class px extends n0{static async create({keyManager:e=new Ka,options:r}){if(!r.domain)throw new Xe("invalidDid","The 'domain' option is required for did:web creation");if(r.algorithm&&r.verificationMethods)throw new Error("The 'algorithm' and 'verificationMethods' options are mutually exclusive");let n=r.path?`${r.domain}:${r.path}`:r.domain,i=`did:${px.methodName}:${n}`;if(!Vn.parse(i))throw new Xe("invalidDid",`The constructed DID URI is invalid: ${i}`);let a=r.verificationMethods??[{algorithm:r.algorithm??"Ed25519",purposes:["authentication","assertionMethod","capabilityDelegation","capabilityInvocation"]}],s={"@context":["https://www.w3.org/ns/did/v1"],id:i};for(let o=0;o<a.length;o++){let d=a[o],u=await e.generateKey({algorithm:d.algorithm}),c=await e.getPublicKey({keyUri:u}),l=d.id?.split("#").pop()??`key-${o}`,f=`${i}#${l}`;s.verificationMethod??=[],s.verificationMethod.push({id:f,type:"JsonWebKey",controller:d.controller??i,publicKeyJwk:c});for(let h of d.purposes??[])s[h]??=[],s[h].push(f)}return r.services&&(s.service=r.services.map(o=>({...o,id:`${i}#${o.id.split("#").pop()}`}))),new ea({uri:i,document:s,metadata:{published:!1},keyManager:e})}static async getSigningMethod({didDocument:e,methodId:r}){let n=Vn.parse(e.id);if(n&&n.method!==this.methodName)throw new Xe("methodNotSupported",`Method not supported: ${n.method}`);let i=To(r)??To(e.assertionMethod?.[0]),a=i?e.verificationMethod?.find(s=>To(s.id)===i):e.verificationMethod?.[0];if(!(a&&a.publicKeyJwk))throw new Xe("internalError","A verification method intended for signing could not be determined from the DID Document");return a}static async import({portableDid:e,keyManager:r=new Ka}){if(Vn.parse(e.uri)?.method!==px.methodName)throw new Xe("methodNotSupported","Method not supported");return await ea.import({portableDid:e,keyManager:r})}static async resolve(e,r){let n=Vn.parse(e);if(!n)return{...li,didResolutionMetadata:{error:"invalidDid"}};if(n.method!==px.methodName)return{...li,didResolutionMetadata:{error:"methodNotSupported"}};let i=`https://${n.id.replace(/:/g,"/")}`;i=decodeURIComponent(i);let a=n.id.includes(":")?`${i}/did.json`:`${i}/.well-known/did.json`;try{let s=new URL(a);if(Dle(s.hostname))return{...li,didResolutionMetadata:{error:"notFound"}};let o=await fetch(a,{signal:AbortSignal.timeout(Ale)});if(!o.ok)throw new Error("HTTP error status code returned");let d=await o.json();return{...li,didDocument:d}}catch{return{...li,didResolutionMetadata:{error:"notFound"}}}}};w9.methodName="web";kI=w9,x4e=Lf(wq(),1),P4e=Lf(vq(),1),Ile=Lf(vq(),1),Lx=class{constructor({ttl:t="15m"}={}){this.cache=new Loe.default({ttl:(0,Ile.default)(t)})}async open(){}async get(t){if(!t)throw new Error("Key cannot be null or undefined");return this.cache.get(t)}async set(t,e){this.cache.set(t,e)}async delete(t){this.cache.delete(t)}async clear(){this.cache.clear()}async close(){}},Rle={open(){return Promise.resolve()},get(t){return Promise.resolve(void 0)},set(t,e){return Promise.resolve()},delete(t){return Promise.resolve()},clear(){return Promise.resolve()},close(){return Promise.resolve()}},s0=class{constructor({cache:t,didResolvers:e}){this.didResolvers=new Map,this.cache=t||Rle;for(let r of e)this.didResolvers.set(r.methodName,r)}async open(){await this.cache.open()}async close(){await this.cache.close()}async resolve(t,e){let r=Vn.parse(t);if(!r)return{...li,didResolutionMetadata:{error:"invalidDid",errorMessage:`Invalid DID URI: ${t}`}};let n=this.didResolvers.get(r.method);if(!n)return{...li,didResolutionMetadata:{error:"methodNotSupported",errorMessage:`Method not supported: ${r.method}`}};let i=await this.cache.get(r.uri);if(i)return i;{let a=await n.resolve(r.uri,e);return a.didResolutionMetadata.error||await this.cache.set(r.uri,a),a}}async dereference(t,e){let r=Vn.parse(t);if(!r)return{dereferencingMetadata:{error:"invalidDidUrl"},contentStream:null,contentMetadata:{}};let{didDocument:n,didResolutionMetadata:i,didDocumentMetadata:a}=await this.resolve(r.uri);if(!n)return{dereferencingMetadata:{error:i.error},contentStream:null,contentMetadata:{}};if(!r.fragment||r.query)return{dereferencingMetadata:{contentType:"application/did+json"},contentStream:n,contentMetadata:a};let{service:s=[],verificationMethod:o=[]}=n,d=new Set([t,r.fragment,`#${r.fragment}`]),u;for(let c of o)if(d.has(c.id)){u=c;break}for(let c of s)if(d.has(c.id)){u=c;break}return u?{dereferencingMetadata:{contentType:"application/did+json"},contentStream:u,contentMetadata:i}:{dereferencingMetadata:{error:"notFound"},contentStream:null,contentMetadata:{}}}};});var v9=F(()=>{"use strict";y();ok();ik();or();ps();j4();N4();K4();hs();jU();MU();qU();LU();zU();FU();GU();WU();N1();dD();Fo();Yt()});var zx=F(()=>{"use strict";y()});import{Level as PNe}from"level";var rl=F(()=>{"use strict";y();zx()});var Gx=F(()=>{"use strict";y();Dy();rl()});var x9=F(()=>{y()});var P9,Ole,_9,Ble,E9,S9=F(()=>{y();dl();vp();P9=0,Ole="identity",_9=ia,Ble=t=>ml(P9,_9(t)),E9={code:P9,name:Ole,encode:_9,digest:Ble}});var T9,jle,k9,A9=F(()=>{y();Fp();T9=wn(Rs(),1);Yc();jle=async(t,e,r,n,i,a,s,o)=>{let d=await s.get(t,o),u=K_(d),c=u,l=r;for(;n.length>0;){let f=n[0];if(f in c){n.shift(),l=`${l}/${f}`;let h=$n.asCID(c[f]);if(h!=null)return{entry:{type:"object",name:e,path:r,cid:t,node:d,depth:a,size:BigInt(d.length),content:async function*(){yield u}},next:{cid:h,name:f,path:l,toResolve:n}};c=c[f]}else throw(0,T9.default)(new Error(`No property named ${f} found in cbor node ${t}`),"ERR_NO_PROP")}return{entry:{type:"object",name:e,path:r,cid:t,node:d,depth:a,size:BigInt(d.length),content:async function*(){yield u}}}},k9=jle});function Mle(t,e,r,n){let i=BigInt(t.length),a=BigInt(e+i);return r>=a||n<e?new Uint8Array(0):(n>=e&&n<a&&(t=t.subarray(0,Number(n-e))),r>=e&&r<a&&(t=t.subarray(Number(r-e))),t)}var Zf,Wx=F(()=>{y();Zf=Mle});var a0,Nle,mm,Hx=F(()=>{y();a0=wn(Rs(),1),Nle=(t,e=0,r=t)=>{let n=BigInt(t),i=BigInt(e??0),a=BigInt(r);if(a!==n&&(a=i+a),a>n&&(a=n),i<0n)throw(0,a0.default)(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(i>n)throw(0,a0.default)(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(a<0n)throw(0,a0.default)(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(a>n)throw(0,a0.default)(new Error("Length must be less than the file size"),"ERR_INVALID_PARAMS");return{start:i,end:a}},mm=Nle});var D9,Ule,Kle,I9,R9=F(()=>{y();D9=wn(Rs(),1);vp();Xc();Wx();Hx();Ule=t=>{async function*e(r={}){let{start:n,end:i}=mm(t.length,r.offset,r.length),a=Zf(t,0n,n,i);r.onProgress?.(new hn("unixfs:exporter:progress:identity",{bytesRead:BigInt(a.byteLength),totalBytes:i-n,fileSize:BigInt(t.byteLength)})),yield a}return e},Kle=async(t,e,r,n,i,a,s,o)=>{if(n.length>0)throw(0,D9.default)(new Error(`No link named ${r} found in raw node ${t}`),"ERR_NOT_FOUND");let d=q0(t.multihash.bytes);return{entry:{type:"identity",name:e,path:r,cid:t,content:Ule(d.digest),depth:a,size:BigInt(d.digest.length),node:d.digest}}},I9=Kle});var C9,qle,Lle,$9,O9=F(()=>{y();C9=wn(Rs(),1);Xc();Wx();Hx();qle=t=>{async function*e(r={}){let{start:n,end:i}=mm(t.length,r.offset,r.length),a=Zf(t,0n,n,i);r.onProgress?.(new hn("unixfs:exporter:progress:raw",{bytesRead:BigInt(a.byteLength),totalBytes:i-n,fileSize:BigInt(t.byteLength)})),yield a}return e},Lle=async(t,e,r,n,i,a,s,o)=>{if(n.length>0)throw(0,C9.default)(new Error(`No link named ${r} found in raw node ${t}`),"ERR_NOT_FOUND");let d=await s.get(t,o);return{entry:{type:"raw",name:e,path:r,cid:t,content:qle(d),depth:a,size:BigInt(d.length),node:d}}},$9=Lle});var zle,Fle,B9,Gle,j9,M9,N9=F(()=>{y();Cs();KE();qE();zle=async function(t){return(await Nv.encode(t)).slice(0,8).reverse()},Fle=async(t,e,r)=>{await Promise.all(t.map(async n=>{if(n.Name==null)throw new Error("Unexpected Link without a Name");if(n.Name.length===2){let i=parseInt(n.Name,16);e._putObjectAt(i,new ec({hash:r._options.hash,bits:r._options.bits},e,i));return}await r.put(n.Name.substring(2),!0)}))},B9=t=>t.toString(16).toUpperCase().padStart(2,"0").substring(0,2),Gle=t=>{let e=t.bucket,r=[];for(;e._parent!=null;)r.push(e),e=e._parent;return r.push(e),r.reverse()},j9=async(t,e,r,n,i)=>{if(n==null){let c=qv({hashFn:zle});n={rootBucket:c,hamtDepth:1,lastBucket:c}}await Fle(t.Links,n.lastBucket,n.rootBucket);let a=await n.rootBucket._findNewBucketAndPos(e),s=B9(a.pos),o=Gle(a);o.length>n.hamtDepth&&(n.lastBucket=o[n.hamtDepth],s=B9(n.lastBucket._posAtParent));let d=t.Links.find(c=>{if(c.Name==null)return!1;let l=c.Name.substring(0,2),f=c.Name.substring(2);return!(l!==s||f!==""&&f!==e)});if(d==null)return;if(d.Name!=null&&d.Name.substring(2)===e)return d.Hash;n.hamtDepth++;let u=await r.get(d.Hash,i);return t=Qc(u),j9(t,e,r,n,i)},M9=j9});function Wle(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var Vx,AI=F(()=>{y();Vx=Wle});function Hle(t){return t[Symbol.asyncIterator]!=null}function Vle(t,e){let r=0;if(Hle(t))return async function*(){for await(let d of t)await e(d,r++)&&(yield d)}();let n=Vx(t),{value:i,done:a}=n.next();if(a===!0)return function*(){}();let s=e(i,r++);if(typeof s.then=="function")return async function*(){await s&&(yield i);for(let d of n)await e(d,r++)&&(yield d)}();let o=e;return function*(){s===!0&&(yield i);for(let d of n)o(d,r++)&&(yield d)}()}var U9,K9=F(()=>{y();AI();U9=Vle});function Jle(t){return t[Symbol.asyncIterator]!=null}function Zle(t,e){let r=0;if(Jle(t))return async function*(){for await(let d of t)yield e(d,r++)}();let n=Vx(t),{value:i,done:a}=n.next();if(a===!0)return function*(){}();let s=e(i,r++);if(typeof s.then=="function")return async function*(){yield await s;for(let d of n)yield e(d,r++)}();let o=e;return function*(){yield s;for(let d of n)yield o(d,r++)}()}var ym,Jx=F(()=>{y();AI();ym=Zle});function Go(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zx=F(()=>{y()});async function*Yf(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,i=new EventTarget,a=[],s=Go(),o=Go(),d=!1,u,c=!1;i.addEventListener("task-complete",()=>{o.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of t){if(a.length===r&&(s=Go(),await s.promise),c)break;let m={done:!1};a.push(m),p().then(g=>{m.done=!0,m.ok=!0,m.value=g,i.dispatchEvent(new Yx("task-complete"))},g=>{m.done=!0,m.err=g,i.dispatchEvent(new Yx("task-complete"))})}d=!0,i.dispatchEvent(new Yx("task-complete"))}catch(p){u=p,i.dispatchEvent(new Yx("task-complete"))}});function l(){return n?a[0]?.done:!!a.find(p=>p.done)}function*f(){for(;a.length>0&&a[0].done;){let p=a[0];if(a.shift(),p.ok)yield p.value;else throw c=!0,s.resolve(),p.err;s.resolve()}}function*h(){for(;l();)for(let p=0;p<a.length;p++)if(a[p].done){let m=a[p];if(a.splice(p,1),p--,m.ok)yield m.value;else throw c=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(l()||(o=Go(),await o.promise),u!=null||(n?yield*f():yield*h(),u!=null))throw u;if(d&&a.length===0)break}}var Yx,Qx=F(()=>{y();Zx();Yx=globalThis.CustomEvent??Event});var Xx,gm,q9=F(()=>{y();Xx=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},gm=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Xx(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Xx(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}}});function eP(t={}){return Yle(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function Yle(t,e){e=e??{};let r=e.onEnd,n=new gm,i,a,s,o=Go(),d=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((g,_)=>{a=v=>{a=null,n.push(v);try{g(t(n))}catch(E){_(E)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{o.resolve(),o=Go()})}},u=g=>a!=null?a(g):(n.push(g),i),c=g=>(n=new gm,a!=null?a({error:g}):(n.push({error:g}),i)),l=g=>{if(s)return i;if(e?.objectMode!==!0&&g?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:g})},f=g=>s?i:(s=!0,g!=null?c(g):u({done:!0})),h=()=>(n=new gm,f(),{done:!0}),p=g=>(f(g),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:d,return:h,throw:p,push:l,end:f,get readableLength(){return n.size},onEmpty:async g=>{let _=g?.signal;if(_?.throwIfAborted(),n.isEmpty())return;let v,E;_!=null&&(v=new Promise((T,D)=>{E=()=>{D(new DI)},_.addEventListener("abort",E)}));try{await Promise.race([o.promise,v])}finally{E!=null&&_!=null&&_?.removeEventListener("abort",E)}}},r==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(g){return m.throw(g),r!=null&&(r(g),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:l,end(g){return m.end(g),r!=null&&(r(g),r=void 0),i},get readableLength(){return m.readableLength},onEmpty:g=>m.onEmpty(g)},i}var DI,II=F(()=>{y();Zx();q9();DI=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}}});function Qle(t){return t.reason}async function L9(t,e,r){if(e==null)return t;let n=r?.translateError??Qle;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let i;try{return await Promise.race([t,new Promise((a,s)=>{i=()=>{s(n(e))},e.addEventListener("abort",i)})])}finally{i!=null&&e.removeEventListener("abort",i)}}var z9=F(()=>{y()});function F9(){return new RI}var RI,G9=F(()=>{y();Zx();z9();RI=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Go(),this.haveNext=Go()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let e=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Go(),e}async throw(e){return this.ended=!0,this.error=e,e!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(e)),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return this.ended=!0,this.nextResult=e,this.haveNext.resolve(),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Go(),await L9(this.readNext.promise,r?.signal,r)}}});function Xle(t){return t[Symbol.asyncIterator]!=null}async function efe(t,e,r){try{await Promise.all(t.map(async n=>{for await(let i of n)await e.push(i,{signal:r}),r.throwIfAborted()})),await e.end(void 0,{signal:r})}catch(n){await e.end(n,{signal:r}).catch(()=>{})}}async function*tfe(t){let e=new AbortController,r=F9();efe(t,r,e.signal).catch(()=>{});try{yield*r}finally{e.abort()}}function*rfe(t){for(let e of t)yield*e}function nfe(...t){let e=[];for(let r of t)Xle(r)||e.push(r);return e.length===t.length?rfe(e):tfe(t)}var W9,H9=F(()=>{y();G9();W9=nfe});function wm(t,...e){if(t==null)throw new Error("Empty pipeline");if(CI(t)){let n=t;t=()=>n.source}else if(J9(t)||V9(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&CI(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)CI(r[n])&&(r[n]=ofe(r[n]));return ife(...r)}var ife,V9,J9,CI,ofe,tP=F(()=>{y();II();H9();ife=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},V9=t=>t?.[Symbol.asyncIterator]!=null,J9=t=>t?.[Symbol.iterator]!=null,CI=t=>t==null?!1:t.sink!=null&&t.source!=null,ofe=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=eP({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,a=t.source;if(V9(a))i=async function*(){yield*a,n.end()};else if(J9(a))i=function*(){yield*a,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return W9(n,i())}return t.source}});var sfe,Z9,Y9=F(()=>{y();K9();Jx();Qx();tP();Xc();sfe=(t,e,r,n,i,a,s)=>{async function*o(d={}){let u=d.offset??0,c=d.length??e.Links.length,l=e.Links.slice(u,c);d.onProgress?.(new hn("unixfs:exporter:walk:directory",{cid:t})),yield*wm(l,f=>ym(f,h=>async()=>{let p=h.Name??"",m=`${n}/${p}`;return(await i(h.Hash,p,m,[],a+1,s,d)).entry}),f=>Yf(f,{ordered:!0}),f=>U9(f,h=>h!=null))}return o},Z9=sfe});var X9=_e((qUe,$I)=>{"use strict";y();var afe=Object.prototype.hasOwnProperty,ko="~";function c0(){}Object.create&&(c0.prototype=Object.create(null),new c0().__proto__||(ko=!1));function cfe(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Q9(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var a=new cfe(r,n||t,i),s=ko?ko+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],a]:t._events[s].push(a):(t._events[s]=a,t._eventsCount++),t}function rP(t,e){--t._eventsCount===0?t._events=new c0:delete t._events[e]}function oo(){this._events=new c0,this._eventsCount=0}oo.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)afe.call(r,n)&&e.push(ko?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};oo.prototype.listeners=function(e){var r=ko?ko+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,s=new Array(a);i<a;i++)s[i]=n[i].fn;return s};oo.prototype.listenerCount=function(e){var r=ko?ko+e:e,n=this._events[r];return n?n.fn?1:n.length:0};oo.prototype.emit=function(e,r,n,i,a,s){var o=ko?ko+e:e;if(!this._events[o])return!1;var d=this._events[o],u=arguments.length,c,l;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),u){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,r),!0;case 3:return d.fn.call(d.context,r,n),!0;case 4:return d.fn.call(d.context,r,n,i),!0;case 5:return d.fn.call(d.context,r,n,i,a),!0;case 6:return d.fn.call(d.context,r,n,i,a,s),!0}for(l=1,c=new Array(u-1);l<u;l++)c[l-1]=arguments[l];d.fn.apply(d.context,c)}else{var f=d.length,h;for(l=0;l<f;l++)switch(d[l].once&&this.removeListener(e,d[l].fn,void 0,!0),u){case 1:d[l].fn.call(d[l].context);break;case 2:d[l].fn.call(d[l].context,r);break;case 3:d[l].fn.call(d[l].context,r,n);break;case 4:d[l].fn.call(d[l].context,r,n,i);break;default:if(!c)for(h=1,c=new Array(u-1);h<u;h++)c[h-1]=arguments[h];d[l].fn.apply(d[l].context,c)}}return!0};oo.prototype.on=function(e,r,n){return Q9(this,e,r,n,!1)};oo.prototype.once=function(e,r,n){return Q9(this,e,r,n,!0)};oo.prototype.removeListener=function(e,r,n,i){var a=ko?ko+e:e;if(!this._events[a])return this;if(!r)return rP(this,a),this;var s=this._events[a];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&rP(this,a);else{for(var o=0,d=[],u=s.length;o<u;o++)(s[o].fn!==r||i&&!s[o].once||n&&s[o].context!==n)&&d.push(s[o]);d.length?this._events[a]=d.length===1?d[0]:d:rP(this,a)}return this};oo.prototype.removeAllListeners=function(e){var r;return e?(r=ko?ko+e:e,this._events[r]&&rP(this,r)):(this._events=new c0,this._eventsCount=0),this};oo.prototype.off=oo.prototype.removeListener;oo.prototype.addListener=oo.prototype.on;oo.prefixed=ko;oo.EventEmitter=oo;typeof $I<"u"&&($I.exports=oo)});var OI,ez=F(()=>{y();OI=wn(X9(),1)});function jI(t,e,r,n){let i,a=new Promise((s,o)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(e===Number.POSITIVE_INFINITY){s(t);return}if(n={customTimers:{setTimeout,clearTimeout},...n},n.signal){let{signal:d}=n;d.aborted&&o(rz(d)),d.addEventListener("abort",()=>{o(rz(d))})}i=n.customTimers.setTimeout.call(void 0,()=>{if(typeof r=="function"){try{s(r())}catch(c){o(c)}return}let d=typeof r=="string"?r:`Promise timed out after ${e} milliseconds`,u=r instanceof Error?r:new d0(d);typeof t.cancel=="function"&&t.cancel(),o(u)},e),(async()=>{try{s(await t)}catch(d){o(d)}finally{n.customTimers.clearTimeout.call(void 0,i)}})()});return a.clear=()=>{clearTimeout(i),i=void 0},a}var d0,BI,tz,rz,nz=F(()=>{y();d0=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},BI=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},tz=t=>globalThis.DOMException===void 0?new BI(t):new DOMException(t),rz=t=>{let e=t.reason===void 0?tz("This operation was aborted."):t.reason;return e instanceof Error?e:tz(e)}});function MI(t,e,r){let n=0,i=t.length;for(;i>0;){let a=Math.trunc(i/2),s=n+a;r(t[s],e)<=0?(n=++s,i-=a+1):i=a}return n}var iz=F(()=>{y()});var Qf,Bd,NI,oz,sz=F(()=>{y();iz();Qf=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},NI=class{constructor(){Bd.set(this,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&Qf(this,Bd,"f")[this.size-1].priority>=r.priority){Qf(this,Bd,"f").push(n);return}let i=MI(Qf(this,Bd,"f"),n,(a,s)=>s.priority-a.priority);Qf(this,Bd,"f").splice(i,0,n)}dequeue(){let e=Qf(this,Bd,"f").shift();return e?.run}filter(e){return Qf(this,Bd,"f").filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return Qf(this,Bd,"f").length}};Bd=new WeakMap;oz=NI});var cn,Ve,Rn,l0,f0,il,cP,p0,nP,qa,u0,Ps,iP,_s,h0,nl,oP,az,cz,lz,dz,uz,sP,UI,KI,dP,fz,aP,uP,qI,pz,hz=F(()=>{y();ez();nz();sz();cn=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},Ve=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},uP=class extends Error{},qI=class extends OI.default{constructor(e){var r,n,i,a;if(super(),Rn.add(this),l0.set(this,void 0),f0.set(this,void 0),il.set(this,0),cP.set(this,void 0),p0.set(this,void 0),nP.set(this,0),qa.set(this,void 0),u0.set(this,void 0),Ps.set(this,void 0),iP.set(this,void 0),_s.set(this,0),h0.set(this,void 0),nl.set(this,void 0),oP.set(this,void 0),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:oz,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(n=(r=e.intervalCap)===null||r===void 0?void 0:r.toString())!==null&&n!==void 0?n:""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(a=(i=e.interval)===null||i===void 0?void 0:i.toString())!==null&&a!==void 0?a:""}\` (${typeof e.interval})`);cn(this,l0,e.carryoverConcurrencyCount,"f"),cn(this,f0,e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,"f"),cn(this,cP,e.intervalCap,"f"),cn(this,p0,e.interval,"f"),cn(this,Ps,new e.queueClass,"f"),cn(this,iP,e.queueClass,"f"),this.concurrency=e.concurrency,this.timeout=e.timeout,cn(this,oP,e.throwOnTimeout===!0,"f"),cn(this,nl,e.autoStart===!1,"f")}get concurrency(){return Ve(this,h0,"f")}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);cn(this,h0,e,"f"),Ve(this,Rn,"m",dP).call(this)}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:Ve(this,oP,"f"),...r},new Promise((n,i)=>{Ve(this,Ps,"f").enqueue(async()=>{var a,s,o;cn(this,_s,(s=Ve(this,_s,"f"),s++,s),"f"),cn(this,il,(o=Ve(this,il,"f"),o++,o),"f");try{if(!((a=r.signal)===null||a===void 0)&&a.aborted)throw new uP("The task was aborted.");let d=e({signal:r.signal});r.timeout&&(d=jI(Promise.resolve(d),r.timeout)),r.signal&&(d=Promise.race([d,Ve(this,Rn,"m",fz).call(this,r.signal)]));let u=await d;n(u),this.emit("completed",u)}catch(d){if(d instanceof d0&&!r.throwOnTimeout){n();return}i(d),this.emit("error",d)}finally{Ve(this,Rn,"m",lz).call(this)}},r),this.emit("add"),Ve(this,Rn,"m",sP).call(this)})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return Ve(this,nl,"f")?(cn(this,nl,!1,"f"),Ve(this,Rn,"m",dP).call(this),this):this}pause(){cn(this,nl,!0,"f")}clear(){cn(this,Ps,new(Ve(this,iP,"f")),"f")}async onEmpty(){Ve(this,Ps,"f").size!==0&&await Ve(this,Rn,"m",aP).call(this,"empty")}async onSizeLessThan(e){Ve(this,Ps,"f").size<e||await Ve(this,Rn,"m",aP).call(this,"next",()=>Ve(this,Ps,"f").size<e)}async onIdle(){Ve(this,_s,"f")===0&&Ve(this,Ps,"f").size===0||await Ve(this,Rn,"m",aP).call(this,"idle")}get size(){return Ve(this,Ps,"f").size}sizeBy(e){return Ve(this,Ps,"f").filter(e).length}get pending(){return Ve(this,_s,"f")}get isPaused(){return Ve(this,nl,"f")}};l0=new WeakMap,f0=new WeakMap,il=new WeakMap,cP=new WeakMap,p0=new WeakMap,nP=new WeakMap,qa=new WeakMap,u0=new WeakMap,Ps=new WeakMap,iP=new WeakMap,_s=new WeakMap,h0=new WeakMap,nl=new WeakMap,oP=new WeakMap,Rn=new WeakSet,az=function(){return Ve(this,f0,"f")||Ve(this,il,"f")<Ve(this,cP,"f")},cz=function(){return Ve(this,_s,"f")<Ve(this,h0,"f")},lz=function(){var e;cn(this,_s,(e=Ve(this,_s,"f"),e--,e),"f"),Ve(this,Rn,"m",sP).call(this),this.emit("next")},dz=function(){Ve(this,Rn,"m",KI).call(this),Ve(this,Rn,"m",UI).call(this),cn(this,u0,void 0,"f")},uz=function(){let e=Date.now();if(Ve(this,qa,"f")===void 0){let r=Ve(this,nP,"f")-e;if(r<0)cn(this,il,Ve(this,l0,"f")?Ve(this,_s,"f"):0,"f");else return Ve(this,u0,"f")===void 0&&cn(this,u0,setTimeout(()=>{Ve(this,Rn,"m",dz).call(this)},r),"f"),!0}return!1},sP=function(){if(Ve(this,Ps,"f").size===0)return Ve(this,qa,"f")&&clearInterval(Ve(this,qa,"f")),cn(this,qa,void 0,"f"),this.emit("empty"),Ve(this,_s,"f")===0&&this.emit("idle"),!1;if(!Ve(this,nl,"f")){let e=!Ve(this,Rn,"a",uz);if(Ve(this,Rn,"a",az)&&Ve(this,Rn,"a",cz)){let r=Ve(this,Ps,"f").dequeue();return r?(this.emit("active"),r(),e&&Ve(this,Rn,"m",UI).call(this),!0):!1}}return!1},UI=function(){Ve(this,f0,"f")||Ve(this,qa,"f")!==void 0||(cn(this,qa,setInterval(()=>{Ve(this,Rn,"m",KI).call(this)},Ve(this,p0,"f")),"f"),cn(this,nP,Date.now()+Ve(this,p0,"f"),"f"))},KI=function(){Ve(this,il,"f")===0&&Ve(this,_s,"f")===0&&Ve(this,qa,"f")&&(clearInterval(Ve(this,qa,"f")),cn(this,qa,void 0,"f")),cn(this,il,Ve(this,l0,"f")?Ve(this,_s,"f"):0,"f"),Ve(this,Rn,"m",dP).call(this)},dP=function(){for(;Ve(this,Rn,"m",sP).call(this););},fz=async function(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(new uP("The task was aborted."))},{once:!0})})},aP=async function(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})};pz=qI});async function mz(t,e,r,n,i,a,s){if(e instanceof Uint8Array){let u=Zf(e,n,i,a);r.push(u);return}if(e.Data==null)throw(0,Xf.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let o;try{o=ti.unmarshal(e.Data)}catch(u){throw(0,Xf.default)(u,"ERR_NOT_UNIXFS")}if(o.data!=null){let u=o.data,c=Zf(u,n,i,a);r.push(c),n+=BigInt(c.byteLength)}let d=[];if(e.Links.length!==o.blockSizes.length)throw(0,Xf.default)(new Error("Inconsistent block sizes and dag links"),"ERR_NOT_UNIXFS");for(let u=0;u<e.Links.length;u++){let c=e.Links[u],l=n,f=l+o.blockSizes[u];if((i>=l&&i<f||a>=l&&a<=f||i<l&&a>f)&&d.push({link:c,blockStart:n}),n=f,n>a)break}await wm(d,u=>ym(u,c=>async()=>{let l=await t.get(c.link.Hash,s);return{...c,block:l}}),u=>Yf(u,{ordered:!0}),async u=>{for await(let{link:c,block:l,blockStart:f}of u){let h;switch(c.Hash.code){case Oy:h=Qc(l);break;case iu:h=l;break;default:r.end((0,Xf.default)(new Error(`Unsupported codec: ${c.Hash.code}`),"ERR_NOT_UNIXFS"));return}let p=new pz({concurrency:1});p.on("error",m=>{r.end(m)}),p.add(async()=>{s.onProgress?.(new hn("unixfs:exporter:walk:file",{cid:c.Hash})),await mz(t,h,r,f,i,a,s)}),await p.onIdle()}}),n>=a&&r.end()}var Xf,dfe,LI,yz=F(()=>{y();Cs();Xf=wn(Rs(),1);nu();Jx();Qx();tP();II();Ly();hz();Xc();Wx();Hx();dfe=(t,e,r,n,i,a,s)=>{async function*o(d={}){let u=r.fileSize();if(u===void 0)throw new Error("File was a directory");let{start:c,end:l}=mm(u,d.offset,d.length);if(l===0n)return;let f=0n,h=l-c,p=eP();d.onProgress?.(new hn("unixfs:exporter:walk:file",{cid:t})),mz(s,e,p,0n,c,l,d).catch(m=>{p.end(m)});for await(let m of p)if(m!=null){if(f+=BigInt(m.byteLength),f>h)throw p.end(),(0,Xf.default)(new Error("Read too many bytes - the file size reported by the UnixFS data in the root node may be incorrect"),"ERR_OVER_READ");f===h&&p.end(),d.onProgress?.(new hn("unixfs:exporter:progress:unixfs:file",{bytesRead:f,totalBytes:h,fileSize:u})),yield m}if(f<h)throw(0,Xf.default)(new Error("Traversed entire DAG but did not read enough bytes"),"ERR_UNDER_READ")}return o},LI=dfe});async function*gz(t,e,r,n,i,a){let s=t.Links,o=wm(s,d=>ym(d,u=>async()=>{let c=u.Name!=null?u.Name.substring(2):null;if(c!=null&&c!==""){let l=await r(u.Hash,c,`${e}/${c}`,[],n+1,i,a);return{entries:l.entry==null?[]:[l.entry]}}else{let l=await i.get(u.Hash,a);return t=Qc(l),a.onProgress?.(new hn("unixfs:exporter:walk:hamt-sharded-directory",{cid:u.Hash})),{entries:gz(t,e,r,n,i,a)}}}),d=>Yf(d,{ordered:!0}));for await(let{entries:d}of o)yield*d}var ufe,wz,vz=F(()=>{y();Cs();Jx();Qx();tP();Xc();ufe=(t,e,r,n,i,a,s)=>{function o(d={}){return d.onProgress?.(new hn("unixfs:exporter:walk:hamt-sharded-directory",{cid:t})),gz(e,n,i,a,s,d)}return o};wz=ufe});var m0,lfe,ffe,pfe,bz,xz=F(()=>{y();Cs();m0=wn(Rs(),1);nu();N9();Y9();yz();vz();lfe=(t,e)=>t.Links.find(n=>n.Name===e)?.Hash,ffe={raw:LI,file:LI,directory:Z9,"hamt-sharded-directory":wz,metadata:(t,e,r,n,i,a,s)=>()=>[],symlink:(t,e,r,n,i,a,s)=>()=>[]},pfe=async(t,e,r,n,i,a,s,o)=>{let d=await s.get(t,o),u=Qc(d),c,l;if(e==null&&(e=t.toString()),u.Data==null)throw(0,m0.default)(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{c=ti.unmarshal(u.Data)}catch(h){throw(0,m0.default)(h,"ERR_NOT_UNIXFS")}if(r==null&&(r=e),n.length>0){let h;if(c?.type==="hamt-sharded-directory"?h=await M9(u,n[0],s):h=lfe(u,n[0]),h==null)throw(0,m0.default)(new Error("file does not exist"),"ERR_NOT_FOUND");let p=n.shift(),m=`${r}/${p}`;l={cid:h,toResolve:n,name:p??"",path:m}}let f=ffe[c.type](t,u,c,r,i,a,s);if(f==null)throw(0,m0.default)(new Error("could not find content exporter"),"ERR_NOT_FOUND");return c.isDirectory()?{entry:{type:"directory",name:e,path:r,cid:t,content:f,unixfs:c,depth:a,node:u,size:c.fileSize()},next:l}:{entry:{type:"file",name:e,path:r,cid:t,content:f,unixfs:c,depth:a,node:u,size:c.fileSize()},next:l}},bz=pfe});var hfe,OKe,Pz=F(()=>{y();Fp();Cs();hfe=wn(Rs(),1);Ly();S9();A9();R9();O9();xz();OKe={[Oy]:bz,[iu]:$9,[Rl]:k9,[E9.code]:I9}});var mfe,_z=F(()=>{y();mfe=wn(Rs(),1);x9();Yc();Pz()});var ZKe,YKe,Sz=F(()=>{"use strict";y();Gx();rl();eu();_z();FE();ZKe=new TextEncoder,YKe=new TextDecoder});var Tz=F(()=>{"use strict";y();_a();nc()});var zI=F(()=>{"use strict";y();yi();HE();nc();Tz();rl();mt();_a()});var kz=F(()=>{y();Dy();W_()});var Az=F(()=>{"use strict";y();kz();Fp();Gx();ed();Yc();rl();zx();zI();or();Ud();nc()});var Dz=F(()=>{"use strict";y();ed();rl()});var Iz=F(()=>{y()});var Rz=F(()=>{"use strict";y();Iz();_a();mt()});var FI=F(()=>{"use strict";y();lf()});var GI=F(()=>{"use strict";y();lf()});var Cz=F(()=>{"use strict";y();lf();FI();GI();rl()});var $z=F(()=>{"use strict";y();lf()});var Oz=F(()=>{"use strict";y();Fp();Yc();eu();Fo();JP();un();Wa();Yb();Qb();hs();iv();B1();j1();Bn();Vb();ww();Jb();U1();Po();yi();L0();Ud();Qi();rn();og();Yt();oh()});var Bz=F(()=>{"use strict";y();Qi()});var Jn=F(()=>{"use strict";y();Mm();fs();ik();LS();ok();ed();Vb();Jb();eu();oh();v9();jg();mt();Yt();un();Qb();og();Po();zx();Wa();or();Yb();ck();va();sk();hs();iv();Sf();B1();j1();Bn();ww();cD();U1();L0();Q2();nc();Qi();zS();Ul();Gx();Sz();zI();rl();Az();Dz();Rz();Cz();GI();FI();$z();lf();Oz();Bz()});var pP=_e((xze,Gz)=>{y();var xm=1e3,Pm=xm*60,_m=Pm*60,ep=_m*24,Ife=ep*7,Rfe=ep*365.25;Gz.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return Cfe(t);if(r==="number"&&isFinite(t))return e.long?Ofe(t):$fe(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function Cfe(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*Rfe;case"weeks":case"week":case"w":return r*Ife;case"days":case"day":case"d":return r*ep;case"hours":case"hour":case"hrs":case"hr":case"h":return r*_m;case"minutes":case"minute":case"mins":case"min":case"m":return r*Pm;case"seconds":case"second":case"secs":case"sec":case"s":return r*xm;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function $fe(t){var e=Math.abs(t);return e>=ep?Math.round(t/ep)+"d":e>=_m?Math.round(t/_m)+"h":e>=Pm?Math.round(t/Pm)+"m":e>=xm?Math.round(t/xm)+"s":t+"ms"}function Ofe(t){var e=Math.abs(t);return e>=ep?fP(t,e,ep,"day"):e>=_m?fP(t,e,_m,"hour"):e>=Pm?fP(t,e,Pm,"minute"):e>=xm?fP(t,e,xm,"second"):t+" ms"}function fP(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});y();y();function Npe(t,e){return{definition:t}}y();y();y();Jn();Jn();var Te;(function(t){t.MessagesRead="MessagesRead",t.MessagesSubscribe="MessagesSubscribe",t.MessagesSync="MessagesSync",t.ProtocolsConfigure="ProtocolsConfigure",t.ProtocolsQuery="ProtocolsQuery",t.RecordsDelete="RecordsDelete",t.RecordsQuery="RecordsQuery",t.RecordsRead="RecordsRead",t.RecordsSubscribe="RecordsSubscribe",t.RecordsWrite="RecordsWrite"})(Te||(Te={}));var HI={[Te.MessagesRead]:df,[Te.MessagesSubscribe]:uf,[Te.MessagesSync]:Rh,[Te.ProtocolsConfigure]:Tf,[Te.ProtocolsQuery]:bd,[Te.RecordsDelete]:Ou,[Te.RecordsQuery]:hd,[Te.RecordsRead]:Bu,[Te.RecordsSubscribe]:xd,[Te.RecordsWrite]:Tn};y();Fo();Kt();y();Jn();y();Fo();Jn();var qz=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})};function VI(t,e){return qz(this,void 0,void 0,function*(){let r=yield e.dereference(`${t}#dwn`);if(r.dereferencingMetadata.error)throw new Error(`Failed to dereference '${t}#dwn': ${r.dereferencingMetadata.error}`);if(lI.isDwnDidService(r.contentStream)){let{serviceEndpoint:n}=r.contentStream,i=typeof n=="string"?[n]:Array.isArray(n)&&n.every(a=>typeof a=="string")?n:[];if(i.length>0)return i}return[]})}function Wo(t){return Se.getAuthor(t)}function Lz(t){let e=ir.decodePlainObjectPayload(t.authorization.signature);return e?.protocolRole}function vm(t){return!t||typeof t!="object"||t===null?!1:"message"in t&&typeof t.message=="object"&&t.message!==null&&"descriptor"in t.message&&typeof t.message.descriptor=="object"&&t.message.descriptor!==null&&"interface"in t.message.descriptor&&t.message.descriptor.interface===Ge.Records&&"method"in t.message.descriptor&&t.message.descriptor.method===ze.Write}function kfe(t){return Se.getCid(t)}function zz(t,e){return qz(this,void 0,void 0,function*(){let r=e===Ar.CreatedAscending||e===Ar.CreatedDescending?t.descriptor.dateCreated:t.descriptor.datePublished;if(r===void 0)throw new Error("The dateCreated or datePublished property is missing from the record descriptor.");return{messageCid:yield kfe(t),value:r}})}var bm=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},lP=class{constructor({didResolver:e,rpcClient:r}){this._didResolver=e,this._rpcClient=r}recordsQuery(e,r){return bm(this,void 0,void 0,function*(){let n=yield hd.create({filter:r.filter,dateSort:r.dateSort,pagination:r.pagination,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}recordsRead(e,r){return bm(this,void 0,void 0,function*(){let n=yield Bu.create({filter:r.filter,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}recordsSubscribe(e,r,n){return bm(this,void 0,void 0,function*(){let i=yield xd.create({filter:r.filter,dateSort:r.dateSort,pagination:r.pagination,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,i.message,void 0,n)})}recordsCount(e,r){return bm(this,void 0,void 0,function*(){let n=yield cf.create({filter:r.filter,messageTimestamp:r.messageTimestamp});return yield this.sendRequest(e,n.message)})}protocolsQuery(e,r){return bm(this,void 0,void 0,function*(){let n=yield bd.create({filter:r?.filter,messageTimestamp:r?.messageTimestamp});return yield this.sendRequest(e,n.message)})}sendRequest(e,r,n,i){return bm(this,void 0,void 0,function*(){let a=yield VI(e,this._didResolver),s=[];for(let o of a)try{if(i!==void 0){if(!(yield this._rpcClient.getServerInfo(o)).webSocketSupport){s.push({url:o,message:"WebSocket support is not enabled on the server."});continue}let c=new URL(o);c.protocol=c.protocol==="http:"?"ws:":"wss:",o=c.toString()}return yield this._rpcClient.sendDwnRequest({dwnUrl:o,targetDid:e,message:r,data:n,subscriptionHandler:i})}catch(d){s.push({url:o,message:d instanceof Error?d.message:"Unknown error"})}throw new Error(`AnonymousDwnApi: Failed to send request to '${e}': ${JSON.stringify(s)}`)})}};y();y();rn();y();Fo();rn();y();Kt();Fo();y();y();rn();y();var Bfe=wn(pP(),1);Kt();Jn();var y0;(function(t){t.Create="Create",t.Resolve="Resolve"})(y0||(y0={}));y();Kt();Jn();rn();Fo();y();y();y();Jn();function ZI(t,e){return e.descriptor.interface+e.descriptor.method===t}function YI(t){return t===Te.RecordsDelete||t===Te.RecordsQuery||t===Te.RecordsRead||t===Te.RecordsSubscribe||t===Te.RecordsWrite}y();rn();Jn();y();y();Jn();y();Jn();y();y();y();Kd();var nFe=Ym("ed25519 seed");var iFe=new Uint8Array([0]);y();var Gfe=`abandon
|
|
11
11
|
ability
|
|
12
12
|
able
|
|
13
13
|
about
|
|
@@ -2055,7 +2055,7 @@ zebra
|
|
|
2055
2055
|
zero
|
|
2056
2056
|
zone
|
|
2057
2057
|
zoo`.split(`
|
|
2058
|
-
`);Fo();Kt();y();y();rn();y();Kt();rn();y();Kt();rn();y();rn();rn();Jn();y();Kt();rn();y();Fo();y();Kt();y();Jn();Kt();var Cc=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Yz=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},fi=class t{get agent(){if(!this._agent)throw new Error("AgentPermissionsApi: Agent is not set");return this._agent}set agent(e){this._agent=e}constructor({agent:e}={}){this._cachedPermissions=new Kl.default({ttl:60*1e3}),this._agent=e}getPermissionForRequest(e){return Cc(this,arguments,void 0,function*({connectedDid:r,delegateDid:n,delegate:i,messageType:a,protocol:s,cached:o=!1}){let d=[r,n,a,s].join("~"),u=o?this._cachedPermissions.get(d):void 0;if(u)return u;let c=yield this.fetchGrants({author:n,target:n,grantor:r,grantee:n}),l=yield t.matchGrantFromArray(r,n,{messageType:a,protocol:s},c,i);if(!l)throw new Error(`CachedPermissions: No permissions found for ${a}: ${s}`);return this._cachedPermissions.set(d,l),l})}fetchGrants(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantee:i,grantor:a,protocol:s,remote:o=!1,checkRevoked:d=!0}){let u=s?{protocol:s}:void 0,c={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{author:a,recipient:i,protocol:zt.uri,protocolPath:zt.grantPath,tags:u}}},{reply:l}=o?yield this.agent.sendDwnRequest(c):yield this.agent.processDwnRequest(c);if(l.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch grants: ${l.status.detail}`);let f=d?yield this.fetchRevokedGrantIds({author:r,target:n,grantor:a,remote:o,tags:u}):new Set,h=[];for(let p of l.entries){if(f.has(p.recordId))continue;let m=dr.parse(p);h.push({grant:m,message:p})}return h})}fetchRevokedGrantIds(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantor:i,remote:a,tags:s}){let o={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{author:i,protocol:zt.uri,protocolPath:zt.revocationPath,tags:s}}},{reply:d}=a?yield this.agent.sendDwnRequest(o):yield this.agent.processDwnRequest(o);if(d.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch revocations: ${d.status.detail}`);let u=new Set;for(let c of d.entries)c.descriptor.parentId!==void 0&&u.add(c.descriptor.parentId);return u})}fetchRequests(e){return Cc(this,arguments,void 0,function*({author:r,target:n,protocol:i,remote:a=!1}){let s=i?{protocol:i}:void 0,o={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{protocol:zt.uri,protocolPath:zt.requestPath,tags:s}}},{reply:d}=a?yield this.agent.sendDwnRequest(o):yield this.agent.processDwnRequest(o);if(d.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch requests: ${d.status.detail}`);let u=[];for(let c of d.entries){let l=Ia.parse(c);u.push({request:l,message:c})}return u})}isGrantRevoked(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantRecordId:i,remote:a=!1}){let s={author:r,target:n,messageType:Te.RecordsRead,messageParams:{filter:{parentId:i,protocol:zt.uri,protocolPath:zt.revocationPath}}},{reply:o}=a?yield this.agent.sendDwnRequest(s):yield this.agent.processDwnRequest(s);if(o.status.code===404)return!1;if(o.status.code===200)return!0;throw new Error(`PermissionsApi: Failed to check if grant is revoked: ${o.status.detail}`)})}createGrant(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,delegated:i=!1}=e,a=Yz(e,["author","store","delegated"]),s;zt.hasProtocolScope(a.scope)&&(s={protocol:a.scope.protocol});let o={dateExpires:a.dateExpires,requestId:a.requestId,description:a.description,delegated:i,scope:a.scope},d=Ue.object(o).toUint8Array(),u={recipient:a.grantedTo,protocol:zt.uri,protocolPath:zt.grantPath,dataFormat:"application/json",tags:s},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([d])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create grant: ${c.status.detail}`);let f=Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(d).toBase64Url()});return{grant:dr.parse(f),message:f}})}createRequest(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,delegated:i=!1}=e,a=Yz(e,["author","store","delegated"]),s;zt.hasProtocolScope(a.scope)&&(s={protocol:a.scope.protocol});let o={description:a.description,delegated:i,scope:a.scope},d=Ue.object(o).toUint8Array(),u={protocol:zt.uri,protocolPath:zt.requestPath,dataFormat:"application/json",tags:s},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([d])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create request: ${c.status.detail}`);let f=Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(d).toBase64Url()});return{request:Ia.parse(f),message:f}})}createRevocation(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,grant:i,description:a}=e,s={description:a},o=Ue.object(s).toUint8Array(),d;zt.hasProtocolScope(i.scope)&&(d={protocol:i.scope.protocol});let u={parentContextId:i.id,protocol:zt.uri,protocolPath:zt.revocationPath,dataFormat:"application/json",tags:d},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([o])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create revocation: ${c.status.detail}`);return{message:Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(o).toBase64Url()})}})}clear(){return Cc(this,void 0,void 0,function*(){this._cachedPermissions.clear()})}static matchGrantFromArray(e,r,n,i){return Cc(this,arguments,void 0,function*(a,s,o,d,u=!1){let c;for(let l of d){let{grant:f,message:h}=l;if(u===!0&&f.delegated!==!0)continue;let{messageType:p,protocol:m,protocolPath:g,contextId:_}=o;if(this.matchScopeFromGrant(a,s,p,f,m,g,_)){if(f.scope.interface+f.scope.method===p)return{grant:f,message:h};c||(c={grant:f,message:h})}}return c})}static matchScopeFromGrant(e,r,n,i,a,s,o){if(i.grantee!==r||i.grantor!==e)return!1;let d=i.scope,u=d.interface+d.method;if(u===n||u===Te.MessagesRead&&(n===Te.MessagesSync||n===Te.MessagesSubscribe))if(YI(n)){let l=d;if(l.protocol!==a)return!1;if(this.isUnrestrictedProtocolScope(l)||l.protocolPath!==void 0&&l.protocolPath===s||l.contextId!==void 0&&o?.startsWith(l.contextId))return!0}else{let l=d;return l.protocol===void 0?!0:l.protocol!==a?!1:this.isUnrestrictedProtocolScope(l)}return!1}static isUnrestrictedProtocolScope(e){return e.contextId===void 0&&e.protocolPath===void 0}};y();var s7=wn(pP(),1);Jn();import{Level as Xfe}from"level";y();Jn();function Qz(t){let e=t.descriptor;return e.interface!==Ge.Records||e.method!==ze.Write?!1:e.dateCreated===e.messageTimestamp}function Em(t){var e;if(t.length<=1)return t;let r=new Map,n=new Map,i=new Map,a=new Map;for(let l=0;l<t.length;l++){let f=t[l];r.set(l,f);let h=f.message.descriptor;if(h.interface===Ge.Protocols&&h.method===ze.Configure){let p=(e=h.definition)===null||e===void 0?void 0:e.protocol;p&&n.set(p,l)}if(h.interface===Ge.Records&&h.method===ze.Write){let p=f.message.recordId;Qz(f.message)&&p&&i.set(p,l),h.protocol===zt.uri&&h.protocolPath===zt.grantPath&&p&&a.set(p,l)}}let s=new Map,o=new Array(t.length).fill(0),d=(l,f)=>{if(l===f)return;s.has(l)||s.set(l,new Set);let h=s.get(l);h.has(f)||(h.add(f),o[f]++)};for(let l=0;l<t.length;l++){let f=t[l].message.descriptor;if(f.interface===Ge.Records){let p=f.protocol;p&&n.has(p)&&d(n.get(p),l)}if(f.interface===Ge.Records&&f.parentId){let p=f.parentId;i.has(p)&&d(i.get(p),l)}if(f.interface===Ge.Records&&f.method===ze.Write){let p=t[l].message.recordId;p&&!Qz(t[l].message)&&i.has(p)&&d(i.get(p),l)}if(f.interface===Ge.Records&&f.method===ze.Delete){let p=f.recordId;p&&i.has(p)&&d(i.get(p),l)}let h=f.permissionGrantId;h&&a.has(h)&&d(a.get(h),l)}let u=[];for(let l=0;l<t.length;l++)o[l]===0&&u.push(l);let c=[];for(;u.length>0;){let l=u.shift();c.push(r.get(l));let f=s.get(l);if(f)for(let h of f)o[h]--,o[h]===0&&u.push(h)}if(c.length<t.length){let l=new Set(c);for(let f=0;f<t.length;f++){let h=r.get(f);l.has(h)||c.push(h)}}return c}y();Jn();var tp=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Jfe=1048576;function e7(t){var e,r;return t.status.code===202||t.status.code===204||t.status.code===409||((e=t.entry)===null||e===void 0?void 0:e.message.descriptor.interface)===Ge.Records&&((r=t.entry)===null||r===void 0?void 0:r.message.descriptor.method)===ze.Delete&&t.status.code===404}function t7(t){return tp(this,void 0,void 0,function*(){try{return yield Se.getCid(t)}catch{return"unknown"}})}function r7(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,prefetched:s,agent:o,permissionsApi:d}){let u=[];if(s)for(let m of s){if(!m.message)continue;let g={message:m.message};if(m.encodedData){let _=ke.base64UrlToBytes(m.encodedData);g.bufferedData=_,g.dataStream=new ReadableStream({start(v){v.enqueue(_),v.close()}})}u.push(g)}let c=a.length>0?yield Xz({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:o,permissionsApi:d}):[],l=[...u,...c],f=Em(l);yield Zfe(f);let h=3,p=f;for(let m=0;m<=h&&p.length>0;m++){let g=[];for(let _ of p){let v=_.bufferedData?new ReadableStream({start(T){T.enqueue(_.bufferedData),T.close()}}):_.dataStream,E=yield o.dwn.processRawMessage(e,_.message,{dataStream:v});e7(E)||g.push(_)}if(g.length>0){let _=[],v=[];for(let E of g)if(E.bufferedData||!E.dataStream)v.push(E);else{let T=yield t7(E.message);_.push(T)}if(_.length>0){let E=yield Xz({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:_,agent:o,permissionsApi:d});v.push(...E)}p=Em(v)}else p=[]}})}function Zfe(t){return tp(this,void 0,void 0,function*(){for(let e of t){if(!e.dataStream)continue;let r=[],n=0,i=!1,a=e.dataStream.getReader();try{for(;;){let{done:d,value:u}=yield a.read();if(d)break;if(n+=u.byteLength,n>Jfe){i=!0;break}r.push(u)}}finally{a.releaseLock()}if(i){e.dataStream=void 0;continue}let s=new Uint8Array(n),o=0;for(let d of r)s.set(d,o),o+=d.byteLength;e.bufferedData=s,e.dataStream=new ReadableStream({start(d){d.enqueue(s),d.close()}})}})}function Xz(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:s,permissionsApi:o}){let d=[],u;n&&(u=(yield o.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesRead,delegateDid:n,protocol:i,cached:!0})).grant.id);let c=4,l=0;for(;l<a.length;){let f=a.slice(l,l+c);l+=c;let h=yield Promise.all(f.map(p=>tp(this,void 0,void 0,function*(){var m,g;let _=yield s.processDwnRequest({store:!1,author:e,target:e,messageType:Te.MessagesRead,granteeDid:n,messageParams:{messageCid:p,permissionGrantId:u}}),v;try{v=yield s.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:_.message})}catch(D){console.error(`SyncEngineLevel: pull - failed to read ${p} from ${r}:`,(m=D.message)!==null&&m!==void 0?m:D);return}if(v.status.code!==200||!(!((g=v.entry)===null||g===void 0)&&g.message))return;let E=v.entry,T;return vm(E)&&E.data&&(T=E.data),{message:E.message,dataStream:T}})));for(let p of h)p&&d.push(p)}return d})}function QI(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:s,permissionsApi:o}){var d;let u=[];for(let l of a){let f=yield Yfe({author:e,messageCid:l,delegateDid:n,protocol:i,agent:s,permissionsApi:o});f&&u.push(f)}let c=Em(u);for(let l of c)try{let f=yield s.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,data:l.dataStream,message:l.message});if(!e7(f)){let h=yield t7(l.message);console.error(`SyncEngineLevel: push failed for ${h}: ${f.status.code} ${f.status.detail}`)}}catch(f){let h=(d=f.message)!==null&&d!==void 0?d:f;throw new Error(`SyncEngineLevel: push to ${r} failed: ${h}`)}})}function Yfe(t){return tp(this,arguments,void 0,function*({author:e,delegateDid:r,protocol:n,messageCid:i,agent:a,permissionsApi:s}){let o;r&&(o=(yield s.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesRead,delegateDid:r,protocol:n,cached:!0})).grant.id);let{reply:d}=yield a.dwn.processRequest({author:e,target:e,messageType:Te.MessagesRead,granteeDid:r,messageParams:{messageCid:i,permissionGrantId:o}});if(d.status.code!==200||!d.entry)return;let u=d.entry,c={message:u.message};return vm(u)&&u.data&&(c.dataStream=u.data),c})}var Rt=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Qfe=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(a){r[a]=t[a]&&function(s){return new Promise(function(o,d){s=t[a](s),i(o,d,s.done,s.value)})}}function i(a,s,o,d){Promise.resolve(d).then(function(u){a({value:u,done:o})},s)}},n7=16,i7=8,epe=4,XI=class{constructor(e){this._waiting=[],this._permits=e}acquire(){return Rt(this,void 0,void 0,function*(){if(this._permits>0){this._permits--;return}return new Promise(e=>{this._waiting.push(e)})})}release(){let e=this._waiting.shift();e?e():this._permits++}run(e){return Rt(this,void 0,void 0,function*(){yield this.acquire();try{return yield e()}finally{this.release()}})}},o7="^",tpe=250,Sm=class t{constructor({agent:e,dataPath:r,db:n}){this._syncLock=!1,this._syncMode="poll",this._liveSubscriptions=[],this._localSubscriptions=[],this._connectivityState="unknown",this._pendingPushCids=new Map,this._consecutiveFailures=0,this._agent=e,this._permissionsApi=new fi({agent:e}),this._db=n||new Xfe(r??"DATA/AGENT/SYNC_STORE")}get agent(){if(this._agent===void 0)throw new Error("SyncEngineLevel: Unable to determine agent execution context.");return this._agent}set agent(e){this._agent=e,this._permissionsApi=new fi({agent:e})}get connectivityState(){return this._connectivityState}clear(){return Rt(this,void 0,void 0,function*(){yield this._permissionsApi.clear(),yield this._db.clear()})}close(){return Rt(this,void 0,void 0,function*(){yield this._db.close()})}registerIdentity(e){return Rt(this,arguments,void 0,function*({did:r,options:n}){let i=this._db.sublevel("registeredIdentities");if(yield this.getIdentityOptions(r))throw new Error(`SyncEngineLevel: Identity with DID ${r} is already registered.`);n??(n={protocols:[]}),yield i.put(r,JSON.stringify(n))})}unregisterIdentity(e){return Rt(this,void 0,void 0,function*(){let r=this._db.sublevel("registeredIdentities");if(!(yield this.getIdentityOptions(e)))throw new Error(`SyncEngineLevel: Identity with DID ${e} is not registered.`);yield r.del(e)})}getIdentityOptions(e){return Rt(this,void 0,void 0,function*(){let r=this._db.sublevel("registeredIdentities");try{let n=yield r.get(e);if(n)return JSON.parse(n)}catch(n){let i=n;if(i.code==="LEVEL_NOT_FOUND")return;throw new Error(`SyncEngineLevel: Error reading level: ${i.code}.`)}})}updateIdentityOptions(e){return Rt(this,arguments,void 0,function*({did:r,options:n}){let i=this._db.sublevel("registeredIdentities");if(!(yield this.getIdentityOptions(r)))throw new Error(`SyncEngineLevel: Identity with DID ${r} is not registered.`);yield i.put(r,JSON.stringify(n))})}sync(e){return Rt(this,void 0,void 0,function*(){if(this._syncLock)throw new Error("SyncEngineLevel: Sync operation is already in progress.");this._syncLock=!0;try{let r=yield this.getSyncTargets(),n=new Set,i=!1;for(let a of r){let{did:s,delegateDid:o,dwnUrl:d,protocol:u}=a;if(!n.has(d))try{let c=yield this.getLocalRoot(s,o,u),l=yield this.getRemoteRoot(s,d,o,u);if(c===l)continue;let f=yield this.diffWithRemote({did:s,dwnUrl:d,delegateDid:o,protocol:u});if((!e||e==="pull")&&f.onlyRemote.length>0){let h=[],p=[];for(let m of f.onlyRemote)m.message?m.message.descriptor.interface==="Records"&&m.message.descriptor.method==="Write"&&m.message.descriptor.dataCid&&!m.encodedData?p.push(m.messageCid):h.push(m):p.push(m.messageCid);yield this.pullMessages({did:s,dwnUrl:d,delegateDid:o,protocol:u,messageCids:p,prefetched:h})}(!e||e==="push")&&f.onlyLocal.length>0&&(yield this.pushMessages({did:s,dwnUrl:d,delegateDid:o,protocol:u,messageCids:f.onlyLocal}))}catch(c){n.add(d),i=!0,console.error(`SyncEngineLevel: Error syncing ${s} with ${d}`,c)}}i?(this._consecutiveFailures++,this._connectivityState==="online"&&(this._connectivityState="offline")):(this._consecutiveFailures=0,r.length>0&&(this._connectivityState="online"))}finally{this._syncLock=!1}})}startSync(e){return Rt(this,void 0,void 0,function*(){var r,n;let i=(r=e.mode)!==null&&r!==void 0?r:"poll",a=(n=e.interval)!==null&&n!==void 0?n:i==="live"?"5m":"2m",s=(0,s7.default)(a);(this._liveSubscriptions.length>0||this._localSubscriptions.length>0)&&(yield this.teardownLiveSync()),this._syncIntervalId&&(clearInterval(this._syncIntervalId),this._syncIntervalId=void 0),this._syncMode=i,i==="live"?yield this.startLiveSync(s):yield this.startPollSync(s)})}stopSync(){return Rt(this,arguments,void 0,function*(e=2e3){let r=0;for(;this._syncLock;){if(r>=e)throw new Error(`SyncEngineLevel: Existing sync operation did not complete within ${e} milliseconds.`);r+=100,yield new Promise(n=>{setTimeout(n,e<100?e:100)})}this._syncIntervalId&&(clearInterval(this._syncIntervalId),this._syncIntervalId=void 0),yield this.teardownLiveSync()})}startPollSync(e){return Rt(this,void 0,void 0,function*(){let r=()=>Rt(this,void 0,void 0,function*(){if(this._syncLock)return;clearInterval(this._syncIntervalId),this._syncIntervalId=void 0;try{yield this.sync()}catch(a){console.error("SyncEngineLevel: Error during sync operation",a)}let n=Math.min(Math.pow(2,this._consecutiveFailures),t.MAX_BACKOFF_MULTIPLIER),i=this._consecutiveFailures>0?e*n:e;this._syncIntervalId||(this._syncIntervalId=setInterval(r,i))});this._syncIntervalId&&clearInterval(this._syncIntervalId),this._syncIntervalId=setInterval(r,e),this._syncLock||(yield this.sync())})}startLiveSync(e){return Rt(this,void 0,void 0,function*(){try{yield this.sync()}catch(i){console.error("SyncEngineLevel: Error during initial live-sync catch-up",i)}let r=yield this.getSyncTargets();for(let i of r)try{yield this.openLivePullSubscription(i),yield this.openLocalPushSubscription(i)}catch(a){console.error(`SyncEngineLevel: Failed to open live subscription for ${i.did} -> ${i.dwnUrl}`,a)}let n=()=>Rt(this,void 0,void 0,function*(){if(!this._syncLock)try{yield this.sync()}catch(i){console.error("SyncEngineLevel: Error during SMT integrity check",i)}});this._syncIntervalId=setInterval(n,e)})}teardownLiveSync(){return Rt(this,void 0,void 0,function*(){this._pushDebounceTimer&&(clearTimeout(this._pushDebounceTimer),this._pushDebounceTimer=void 0),this._pendingPushCids.clear();for(let e of this._liveSubscriptions)try{yield e.close()}catch{}this._liveSubscriptions=[];for(let e of this._localSubscriptions)try{yield e.close()}catch{}this._localSubscriptions=[]})}openLivePullSubscription(e){return Rt(this,void 0,void 0,function*(){let{did:r,delegateDid:n,dwnUrl:i,protocol:a}=e,s=this.buildCursorKey(r,i,a),o=yield this.getCursor(s),d=a?[{protocol:a}]:[],u;if(n)try{u=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesSubscribe,delegateDid:n,protocol:a,cached:!0})).grant.id}catch{try{u=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesRead,delegateDid:n,protocol:a,cached:!0})).grant.id}catch(p){console.error("SyncEngineLevel: Could not find permission grant for live pull subscription",p);return}}let c=h=>Rt(this,void 0,void 0,function*(){if(h.type==="eose"){yield this.setCursor(s,h.cursor),this._connectivityState="online";return}if(h.type==="event"){let p=h.event;try{let m=this.extractDataStream(p);yield this.agent.dwn.processRawMessage(r,p.message,{dataStream:m})}catch(m){console.error(`SyncEngineLevel: Error processing live-pull event for ${r}`,m)}yield this.setCursor(s,h.cursor)}}),f=(yield this.agent.dwn.sendRequest({author:r,target:r,messageType:Te.MessagesSubscribe,granteeDid:n,messageParams:{filters:d,cursor:o,permissionGrantId:u},subscriptionHandler:c})).reply;if(f.status.code!==200||!f.subscription){console.error(`SyncEngineLevel: MessagesSubscribe failed for ${r} -> ${i}: ${f.status.code} ${f.status.detail}`);return}this._liveSubscriptions.push({did:r,dwnUrl:i,delegateDid:n,protocol:a,close:()=>Rt(this,void 0,void 0,function*(){yield f.subscription.close()})}),this._connectivityState="online"})}openLocalPushSubscription(e){return Rt(this,void 0,void 0,function*(){let{did:r,delegateDid:n,dwnUrl:i,protocol:a}=e,s=a?[{protocol:a}]:[],o;if(n)try{o=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesRead,delegateDid:n,protocol:a,cached:!0})).grant.id}catch{return}let d=l=>{if(l.type!=="event")return;let f=this.buildCursorKey(r,i,a),h=this.tryGetCidSync(l.event.message);if(h===void 0)return;let p=this._pendingPushCids.get(f);p||(p={did:r,dwnUrl:i,delegateDid:n,protocol:a,cids:[]},this._pendingPushCids.set(f,p)),p.cids.push(h),this._pushDebounceTimer&&clearTimeout(this._pushDebounceTimer),this._pushDebounceTimer=setTimeout(()=>{this.flushPendingPushes()},tpe)},c=(yield this.agent.dwn.processRequest({author:r,target:r,messageType:Te.MessagesSubscribe,granteeDid:n,messageParams:{filters:s,permissionGrantId:o},subscriptionHandler:d})).reply;if(c.status.code!==200||!c.subscription){console.error(`SyncEngineLevel: Local MessagesSubscribe failed for ${r}: ${c.status.code} ${c.status.detail}`);return}this._localSubscriptions.push({did:r,dwnUrl:i,delegateDid:n,protocol:a,close:()=>Rt(this,void 0,void 0,function*(){yield c.subscription.close()})})})}flushPendingPushes(){return Rt(this,void 0,void 0,function*(){this._pushDebounceTimer=void 0;let e=[...this._pendingPushCids.entries()];this._pendingPushCids.clear();for(let[,r]of e){let{did:n,dwnUrl:i,delegateDid:a,protocol:s,cids:o}=r;if(o.length!==0)try{yield QI({did:n,dwnUrl:i,delegateDid:a,protocol:s,messageCids:o,agent:this.agent,permissionsApi:this._permissionsApi})}catch(d){console.error(`SyncEngineLevel: Push-on-write failed for ${n} -> ${i}`,d)}}})}buildCursorKey(e,r,n){let i=`${e}${o7}${r}`;return n?`${i}${o7}${n}`:i}getCursor(e){return Rt(this,void 0,void 0,function*(){let r=this._db.sublevel("syncCursors");try{return yield r.get(e)}catch(n){if(n.code==="LEVEL_NOT_FOUND")return;throw n}})}setCursor(e,r){return Rt(this,void 0,void 0,function*(){yield this._db.sublevel("syncCursors").put(e,r)})}extractDataStream(e){if(vm(e)&&e.data)return e.data}tryGetCidSync(e){var r;let n;return Se.getCid(e).then(i=>{n=i}),(r=n??e.messageCid)!==null&&r!==void 0?r:void 0}getDefaultHashHex(e){return Rt(this,void 0,void 0,function*(){var r;if(this._defaultHashHex===void 0){let n=yield Ng(),i=new Map;for(let a=0;a<=n7;a++)i.set(a,md(n[a]));this._defaultHashHex=i}return(r=this._defaultHashHex.get(e))!==null&&r!==void 0?r:""})}static parseBitPrefix(e){return Array.from(e,r=>r==="1")}get stateIndex(){if(!this.agent.dwn.isRemoteMode)return this.agent.dwn.node.storage.stateIndex}getLocalRoot(e,r,n){return Rt(this,void 0,void 0,function*(){var i;let a=this.stateIndex;if(a){let u=n!==void 0?yield a.getProtocolRoot(e,n):yield a.getRoot(e);return md(u)}let s=yield this.getSyncPermissionGrantId(e,r,n);return(i=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:r,messageParams:{action:"root",protocol:n,permissionGrantId:s}})).reply.root)!==null&&i!==void 0?i:""})}getRemoteRoot(e,r,n,i){return Rt(this,void 0,void 0,function*(){var a;let s=yield this.getSyncPermissionGrantId(e,n,i),o=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"root",protocol:i,permissionGrantId:s}});return(a=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:o.message})).root)!==null&&a!==void 0?a:""})}walkTreeDiff(e){return Rt(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a}){let s=[],o=[],d=yield this.getSyncPermissionGrantId(r,i,a),u=new XI(epe),c=l=>Rt(this,void 0,void 0,function*(){let[f,h]=yield Promise.all([this.getLocalSubtreeHash(r,l,i,a,d),u.run(()=>this.getRemoteSubtreeHash(r,n,l,i,a,d))]);if(f===h)return;let p=yield this.getDefaultHashHex(l.length);if(h===p&&f!==p){let m=yield this.getLocalLeaves(r,l,i,a,d);s.push(...m);return}if(f===p&&h!==p){let m=yield u.run(()=>this.getRemoteLeaves(r,n,l,i,a,d));o.push(...m);return}if(l.length>=n7){let[m,g]=yield Promise.all([this.getLocalLeaves(r,l,i,a,d),u.run(()=>this.getRemoteLeaves(r,n,l,i,a,d))]),_=new Set(m),v=new Set(g);for(let E of m)v.has(E)||s.push(E);for(let E of g)_.has(E)||o.push(E);return}yield Promise.all([c(l+"0"),c(l+"1")])});return yield c(""),{onlyLocal:s,onlyRemote:o}})}diffWithRemote(e){return Rt(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a}){var s,o;let d=yield this.collectLocalSubtreeHashes(r,a,i7),u=yield this.getSyncPermissionGrantId(r,i,a),c=yield this.agent.dwn.processRequest({store:!1,author:r,target:r,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"diff",protocol:a,hashes:d,depth:i7,permissionGrantId:u}}),l=yield this.agent.rpc.sendDwnRequest({dwnUrl:n,targetDid:r,message:c.message});if(l.status.code!==200)throw new Error(`SyncEngineLevel: diff failed with ${l.status.code}: ${l.status.detail}`);let f=yield this.getSyncPermissionGrantId(r,i,a),h=[];for(let p of(s=l.onlyLocal)!==null&&s!==void 0?s:[]){let m=yield this.getLocalLeaves(r,p,i,a,f);h.push(...m)}return{onlyRemote:(o=l.onlyRemote)!==null&&o!==void 0?o:[],onlyLocal:h}})}collectLocalSubtreeHashes(e,r,n){return Rt(this,void 0,void 0,function*(){let i={},a=yield this.getDefaultHashHex(n),s=this.stateIndex,o=(d,u)=>Rt(this,void 0,void 0,function*(){let c;if(s){let l=t.parseBitPrefix(d),f=r!==void 0?yield s.getProtocolSubtreeHash(e,r,l):yield s.getSubtreeHash(e,l);c=md(f)}else c=yield this.getLocalSubtreeHash(e,d,void 0,r);if(c!==a){if(u>=n){i[d]=c;return}yield Promise.all([o(d+"0",u+1),o(d+"1",u+1)])}});return yield o("",0),i})}getLocalSubtreeHash(e,r,n,i,a){return Rt(this,void 0,void 0,function*(){var s;let o=this.stateIndex;if(o){let c=t.parseBitPrefix(r),l=i!==void 0?yield o.getProtocolSubtreeHash(e,i,c):yield o.getSubtreeHash(e,c);return md(l)}return(s=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"subtree",prefix:r,protocol:i,permissionGrantId:a}})).reply.hash)!==null&&s!==void 0?s:""})}getRemoteSubtreeHash(e,r,n,i,a,s){return Rt(this,void 0,void 0,function*(){var o;let d=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"subtree",prefix:n,protocol:a,permissionGrantId:s}});return(o=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:d.message})).hash)!==null&&o!==void 0?o:""})}getLocalLeaves(e,r,n,i,a){return Rt(this,void 0,void 0,function*(){var s;let o=this.stateIndex;if(o){let c=t.parseBitPrefix(r);return i!==void 0?yield o.getProtocolLeaves(e,i,c):yield o.getLeaves(e,c)}return(s=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"leaves",prefix:r,protocol:i,permissionGrantId:a}})).reply.entries)!==null&&s!==void 0?s:[]})}getRemoteLeaves(e,r,n,i,a,s){return Rt(this,void 0,void 0,function*(){var o;let d=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"leaves",prefix:n,protocol:a,permissionGrantId:s}});return(o=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:d.message})).entries)!==null&&o!==void 0?o:[]})}pullMessages(e){return Rt(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,prefetched:o}){return r7({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,prefetched:o,agent:this.agent,permissionsApi:this._permissionsApi})})}pushMessages(e){return Rt(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s}){return QI({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,agent:this.agent,permissionsApi:this._permissionsApi})})}static topologicalSort(e){return Em(e)}getSyncTargets(){return Rt(this,void 0,void 0,function*(){var e,r,n,i;let a=[];try{for(var s=!0,o=Qfe(this._db.sublevel("registeredIdentities").iterator()),d;d=yield o.next(),e=d.done,!e;s=!0){i=d.value,s=!1;let[u,c]=i,l;try{l=JSON.parse(c)}catch{l={protocols:[]}}let{protocols:f,delegateDid:h}=l,p=yield this.agent.dwn.getDwnEndpointUrlsForTarget(u);if(p.length!==0)for(let m of p)if(f.length===0)a.push({did:u,delegateDid:h,dwnUrl:m});else for(let g of f)a.push({did:u,delegateDid:h,dwnUrl:m,protocol:g})}}catch(u){r={error:u}}finally{try{!s&&!e&&(n=o.return)&&(yield n.call(o))}finally{if(r)throw r.error}}return a})}getSyncPermissionGrantId(e,r,n){return Rt(this,void 0,void 0,function*(){return r?(yield this._permissionsApi.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesSync,delegateDid:r,protocol:n,cached:!0})).grant.id:void 0})}};Sm.MAX_CONSECUTIVE_FAILURES=5;Sm.MAX_BACKOFF_MULTIPLIER=4;y();Jn();Fo();Kt();import{Level as VWe}from"level";y();y();y();Kt();rn();y();y();var a7=wn(pP(),1);Kt();var Tm=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},mP=class{constructor({ttl:e="15m"}={}){this.cache=new Kl.default({ttl:(0,a7.default)(e)})}get(e){return Tm(this,void 0,void 0,function*(){return this.cache.get(e)})}set(e,r){return Tm(this,void 0,void 0,function*(){this.cache.set(e,r)})}delete(e){return Tm(this,void 0,void 0,function*(){this.cache.delete(e)})}clear(){return Tm(this,void 0,void 0,function*(){this.cache.clear()})}open(){return Tm(this,void 0,void 0,function*(){})}close(){return Tm(this,void 0,void 0,function*(){})}};y();rn();Jn();y();var km=class extends Error{constructor(e,r){super(r??`Rate limit exceeded, retry after ${e}s`),this.name="RateLimitError",this.retryAfterSec=e}};y();var Am;(function(t){t[t.InvalidRequest=-32600]="InvalidRequest",t[t.MethodNotFound=-32601]="MethodNotFound",t[t.InvalidParams=-32602]="InvalidParams",t[t.InternalError=-32603]="InternalError",t[t.ParseError=-32700]="ParseError",t[t.TransportError=-32300]="TransportError",t[t.BadRequest=-50400]="BadRequest",t[t.Unauthorized=-50401]="Unauthorized",t[t.Forbidden=-50403]="Forbidden",t[t.Conflict=-50409]="Conflict",t[t.TooManyRequests=-50429]="TooManyRequests"})(Am||(Am={}));var Dm=(t,e,r)=>({jsonrpc:"2.0",id:t,method:e,params:r}),yP=(t,e,r,n)=>({jsonrpc:"2.0",id:t,method:e,params:r,subscription:{id:n??null}}),c7=(t,e)=>({jsonrpc:"2.0",method:"rpc.ack",params:{cursor:e},subscription:{id:t}});function rp(t){try{return JSON.parse(t)}catch{return null}}var eR=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},rpe=3,npe=500,ipe=1e4,ope=3e4,d7=new Set([408,429,500,502,503,504]);function spe(t,e){return t instanceof TypeError?!0:e?d7.has(e.status):!1}function ape(t,e,r){let n=Math.min(e*Math.pow(2,t),r),i=.5+Math.random()*.5;return n*i}function cpe(t){let e=t.headers.get("retry-after");if(e===null)return;let r=Number(e);if(!Number.isNaN(r)&&r>=0)return r*1e3;let n=new Date(e);if(!Number.isNaN(n.getTime())){let i=n.getTime()-Date.now();return i>0?i:0}}var gP=class t{constructor(e,r){var n,i,a;this.serverInfoCache=e??new mP,this._retryOptions={maxRetries:(n=r?.maxRetries)!==null&&n!==void 0?n:rpe,baseDelayMs:(i=r?.baseDelayMs)!==null&&i!==void 0?i:npe,maxDelayMs:(a=r?.maxDelayMs)!==null&&a!==void 0?a:ipe}}static isBunRuntime(){return typeof globalThis.Bun<"u"}get transportProtocols(){return["http:","https:"]}sendDwnRequest(e){return eR(this,void 0,void 0,function*(){var r,n,i;let a=gi.randomUuid(),s=Dm(a,"dwn.processMessage",{target:e.targetDid,message:e.message}),o={"dwn-request":JSON.stringify(s)},d={method:"POST",headers:o};if(e.data){o["content-type"]="application/octet-stream";let h=e.data;if(h instanceof ReadableStream)if(t.isBunRuntime()){let p=yield Hi.toBytes(h);h=new Blob([p],{type:"application/octet-stream"})}else d.duplex="half";d.body=h}let u=yield this.fetchWithRetry(e.dwnUrl,d);if(u.status===429){let h=parseInt((r=u.headers.get("retry-after"))!==null&&r!==void 0?r:"1",10);throw new km(h)}let c,l=u.headers.has("dwn-response");if(l){let h=rp(u.headers.get("dwn-response"));if(h==null)throw new Error(`failed to parse json rpc response. dwn url: ${e.dwnUrl}`);c=h}else{let h=yield u.text(),p=rp(h);if(p==null)throw new Error(`failed to parse json rpc response. dwn url: ${e.dwnUrl}, status: ${u.status}`);c=p}if(c.error){let{code:h,message:p}=c.error;if(h===Am.TooManyRequests){let m=(i=(n=c.error.data)===null||n===void 0?void 0:n.retryAfterSec)!==null&&i!==void 0?i:1;throw new km(m)}throw new Error(`(${h}) - ${p}`)}let{reply:f}=c.result;if(l){let h=new Uint8Array(yield u.arrayBuffer()),p=Hi.fromBytes(h);f.record?f.record.data=p:f.entry&&(f.entry.data=p)}return f})}getServerInfo(e){return eR(this,void 0,void 0,function*(){var r;let n=yield this.serverInfoCache.get(e);if(n)return n;let i=new URL(e);i.pathname.endsWith("/")?i.pathname+="info":i.pathname+="/info";try{let a=yield this.fetchWithRetry(i.toString());if(a.status===429){let s=parseInt((r=a.headers.get("retry-after"))!==null&&r!==void 0?r:"1",10);throw new km(s)}if(a.ok){let s=yield a.json(),o={maxFileSize:s.maxFileSize,maxInFlight:s.maxInFlight,providerAuth:s.providerAuth,registrationRequirements:s.registrationRequirements,server:s.server,sdkVersion:s.sdkVersion,url:s.url,version:s.version,webSocketSupport:s.webSocketSupport};return this.serverInfoCache.set(e,o),o}else throw new Error(`HTTP (${a.status}) - ${a.statusText}`)}catch(a){throw new Error(`Error encountered while processing response from ${i.toString()}: ${a.message}`)}})}fetchWithRetry(e,r){return eR(this,void 0,void 0,function*(){let{maxRetries:n,baseDelayMs:i,maxDelayMs:a}=this._retryOptions,s,o;for(let d=0;d<=n;d++){try{let f=AbortSignal.timeout(ope),h=Object.assign(Object.assign({},r),{signal:r?.signal?AbortSignal.any([r.signal,f]):f}),p=yield fetch(e,h);if(!d7.has(p.status)||d===n)return p;o=p}catch(f){if(!spe(f)||d===n)throw f;s=f}let u=o?cpe(o):void 0,c=ape(d,i,a),l=u!==void 0?Math.max(u,c):c;yield new Promise(f=>{setTimeout(f,l)})}if(o)return o;throw s})}};y();rn();var g0=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})};function tR(t){return typeof t=="string"?t:t instanceof ArrayBuffer?new TextDecoder().decode(t):t instanceof Uint8Array?new TextDecoder().decode(t):String(t)}var u7=3e3,dpe=3e4,upe=1e3,lpe=3e4,fpe=1/0,wP=class t{constructor(e,r,n,i){this.socket=e,this.responseTimeout=r,this.messageHandlers=new Map,this.subscriptionHandlerIds=new Set,this.closedByUser=!1,this.reconnecting=!1,this._isConnected=!1,this.url=n,this.options=i,this._isConnected=!0}get isConnected(){return this._isConnected}static connect(e){return g0(this,arguments,void 0,function*(r,n={}){var i;let{connectTimeout:a=u7,responseTimeout:s=dpe}=n,o;try{o=yield t.createWebSocket(r,a)}catch(u){throw(i=n.onerror)===null||i===void 0||i.call(n,u),u}let d=new t(o,s,r,n);return d.wireSocket(o),d})}close(){this.closedByUser=!0,this._isConnected=!1,this.socket.close()}request(e){return g0(this,void 0,void 0,function*(){return new Promise((r,n)=>{var i;(i=e.id)!==null&&i!==void 0||(e.id=gi.randomUuid());let a=s=>{let o=rp(tR(s.data));if(o.id===e.id)return this.messageHandlers.delete(e.id),r(o)};this.messageHandlers.set(e.id,a),this.send(e),setTimeout(()=>{this.messageHandlers.delete(e.id),n(new Error("request timed out"))},this.responseTimeout)})})}subscribe(e,r){return g0(this,void 0,void 0,function*(){if(!e.method.startsWith("rpc.subscribe."))throw new Error("subscribe rpc requests must include the `rpc.subscribe` prefix");if(!e.subscription)throw new Error("subscribe rpc requests must include subscribe options");let n=e.subscription.id,i=this.messageHandlers.get(n),a=d=>{let u=rp(tR(d.data));u.id===n&&(u.error!==void 0&&(this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n),this.closeSubscription(n).catch(()=>{})),r(u))};this.messageHandlers.set(n,a),this.subscriptionHandlerIds.add(n);let s=yield this.request(e);return s.error?(i?this.messageHandlers.set(n,i):(this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n)),{response:s}):{response:s,close:()=>g0(this,void 0,void 0,function*(){this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n),yield this.closeSubscription(n)})}})}closeSubscription(e){let r=gi.randomUuid(),n=yP(r,"rpc.subscribe.close",{},e);return this.request(n)}send(e){this.socket.send(JSON.stringify(e))}static createWebSocket(e,r){return new Promise((n,i)=>{let a=new WebSocket(e),s=()=>{u(),n(a)},o=c=>{u(),i(c)},d=setTimeout(()=>{u(),a.close(),i(new Error("connect timed out"))},r),u=()=>{clearTimeout(d),a.removeEventListener("open",s),a.removeEventListener("error",o)};a.addEventListener("open",s),a.addEventListener("error",o)})}wireSocket(e){e.addEventListener("message",r=>{let n=rp(tR(r.data));if(n===null)return;let i=this.messageHandlers.get(n.id);i&&i(r)}),e.addEventListener("close",()=>{var r,n,i,a,s;if(this._isConnected=!1,this.closedByUser){(n=(r=this.options).onclose)===null||n===void 0||n.call(r);return}this.rejectPendingRequests(),(a=(i=this.options).onclose)===null||a===void 0||a.call(i),((s=this.options.autoReconnect)!==null&&s!==void 0?s:!0)&&!this.reconnecting&&this.attemptReconnect()}),e.addEventListener("error",r=>{var n,i;(i=(n=this.options).onerror)===null||i===void 0||i.call(n,r)})}rejectPendingRequests(){for(let[e,r]of this.messageHandlers)if(!this.subscriptionHandlerIds.has(e)){let n=JSON.stringify({jsonrpc:"2.0",id:e,error:{code:Am.TransportError,message:"WebSocket connection closed unexpectedly"}});r({data:n}),this.messageHandlers.delete(e)}}attemptReconnect(){var e,r,n,i;this.reconnecting=!0;let a=(e=this.options.baseReconnectDelay)!==null&&e!==void 0?e:upe,s=(r=this.options.maxReconnectDelay)!==null&&r!==void 0?r:lpe,o=(n=this.options.maxReconnectAttempts)!==null&&n!==void 0?n:fpe,d=(i=this.options.connectTimeout)!==null&&i!==void 0?i:u7,u=0,c=()=>g0(this,void 0,void 0,function*(){var l,f,h,p;if(this.closedByUser){this.reconnecting=!1;return}if(u++,u>o){this.reconnecting=!1;return}(f=(l=this.options).onreconnecting)===null||f===void 0||f.call(l,u);let g=Math.min(a*Math.pow(2,u-1),s)*(.5+Math.random()*.5);if(yield new Promise(_=>setTimeout(_,g)),this.closedByUser){this.reconnecting=!1;return}try{let _=yield t.createWebSocket(this.url,d);this.socket=_,this._isConnected=!0,this.reconnecting=!1,this.wireSocket(_),(p=(h=this.options).onreconnected)===null||p===void 0||p.call(h)}catch{yield c()}});c()}};y();y();y();rn();y();rn();var Im=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},w0=class t{get transportProtocols(){return["ws:","wss:"]}sendDwnRequest(e){return Im(this,void 0,void 0,function*(){let r=new URL(e.dwnUrl);if(r.protocol!=="ws:"&&r.protocol!=="wss:")throw new Error(`Invalid websocket protocol ${r.protocol}`);if(!t.connections.has(r.host))try{let d=yield t.createConnection(r);t.connections.set(r.host,d)}catch(d){throw new Error(`Error connecting to ${r.host}: ${d.message}`)}let i=t.connections.get(r.host),{targetDid:a,message:s,subscription:o}=e;return o?t.subscriptionRequest(i,a,s,o.handler,o.resubscribeFactory):t.processMessage(i,a,s)})}static createConnection(e){return Im(this,void 0,void 0,function*(){let r=e.host,n=new Map,i=yield wP.connect(e.toString(),{onclose:()=>{t.connections.delete(r);for(let a of n.values())a.handler({type:"disconnected"})},onreconnecting:a=>{for(let s of n.values())s.handler({type:"reconnecting",attempt:a})},onreconnected:()=>{let a={socket:i,subscriptions:n,url:e.toString()};t.connections.set(r,a),t.resubscribeAll(a)}});return{socket:i,subscriptions:n,url:e.toString()}})}static processMessage(e,r,n){return Im(this,void 0,void 0,function*(){let i=gi.randomUuid(),a=Dm(i,"dwn.processMessage",{target:r,message:n}),{socket:s}=e,o=yield s.request(a),{error:d,result:u}=o;if(d!==void 0)throw new Error(`error sending DWN request: ${d.message}`);return u.reply})}static subscriptionRequest(e,r,n,i,a){return Im(this,void 0,void 0,function*(){let s=gi.randomUuid(),o=gi.randomUuid(),d=yP(s,"rpc.subscribe.dwn.processMessage",{target:r,message:n},o),{socket:u,subscriptions:c}=e,{response:l,close:f}=yield u.subscribe(d,g=>{let{result:_,error:v}=g;if(v){let T=c.get(o);T&&T.subscription.close(),c.delete(o);return}let E=_.subscription;if(i(E),"cursor"in E&&E.cursor){let T=c.get(o);T&&(T.lastCursor=E.cursor),u.send(c7(o,E.cursor))}}),{error:h,result:p}=l;if(h)throw new Error(`could not subscribe via jsonrpc socket: ${h.message}`);let{reply:m}=p;if(m.subscription&&f){let g=()=>Im(this,void 0,void 0,function*(){c.delete(o),yield f()}),_={subscription:Object.assign(Object.assign({},m.subscription),{close:g}),target:r,message:n,handler:i,resubscribeFactory:a};c.set(o,_),m.subscription.close=g}return m})}static resubscribeAll(e){return Im(this,void 0,void 0,function*(){let r=[...e.subscriptions.entries()];e.subscriptions.clear();for(let[,n]of r)try{let i;n.resubscribeFactory?i=yield n.resubscribeFactory(n.lastCursor):i=n.message,yield t.subscriptionRequest(e,n.target,i,n.handler,n.resubscribeFactory),n.handler({type:"reconnected"})}catch{}})}};w0.connections=new Map;var v0=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},l7;(function(t){t.Create="did.create",t.Resolve="did.resolve"})(l7||(l7={}));var Rm=class{constructor(e=[]){this.transportClients=new Map,e=[new rR,new nR,...e];for(let r of e)for(let n of r.transportProtocols)this.transportClients.set(n,r)}get transportProtocols(){return Array.from(this.transportClients.keys())}sendDidRequest(e){return v0(this,void 0,void 0,function*(){let r=new URL(e.url),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.sendDidRequest(e)})}sendDwnRequest(e){let r=new URL(e.dwnUrl),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.sendDwnRequest(e)}getServerInfo(e){return v0(this,void 0,void 0,function*(){let r=new URL(e),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.getServerInfo(e)})}},rR=class extends gP{sendDidRequest(e){return v0(this,void 0,void 0,function*(){let r=gi.randomUuid(),n=Dm(r,e.method,{data:e.data}),i=new Request(e.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),a;try{let s=yield fetch(i,{signal:AbortSignal.timeout(3e4)});if(s.ok){if(a=yield s.json(),a.error){let{code:o,message:d}=a.error;throw new Error(`JSON RPC (${o}) - ${d}`)}}else throw new Error(`HTTP (${s.status}) - ${s.statusText}`)}catch(s){throw new Error(`Error encountered while processing response from ${e.url}: ${s.message}`)}return a.result})}},nR=class extends w0{sendDidRequest(e){return v0(this,void 0,void 0,function*(){throw new Error(`not implemented for transports [${this.transportProtocols.join(", ")}]`)})}getServerInfo(e){return v0(this,void 0,void 0,function*(){throw new Error(`not implemented for transports [${this.transportProtocols.join(", ")}]`)})}};y();y();Fo();Kt();rn();Jn();y();Kt();Fo();var vP=class{constructor(e){this.agent=e.agent,this.connectedDid=e.connectedDid}async create(e){let{result:r,...n}=await this.agent.processDidRequest({messageType:y0.Create,messageParams:{...e}});return{did:r,...n}}async resolve(e,r){let{result:n}=await this.agent.processDidRequest({messageParams:{didUri:e,options:r},messageType:y0.Resolve});return n}};y();y();Kt();var b0=class{constructor(e){let{rawMessage:r,initialWrite:n,encodedData:i,data:a,remoteOrigin:s,anonymousDwn:o}=e;this._anonymousDwn=o,this._remoteOrigin=s;try{this._author=Wo(r)??"unknown"}catch{this._author="unknown"}try{this._creator=n?Wo(n)??this._author:this._author}catch{this._creator=this._author}this._descriptor=r.descriptor,this._recordId=r.recordId,this._contextId=r.contextId,this._initialWrite=n,this._authorization=r.authorization,this._attestation=r.attestation,this._encryption=r.encryption,i&&(this._encodedData=new Blob([Ue.base64Url(i).toUint8Array()],{type:this.dataFormat})),a&&(this._readableStream=a)}get id(){return this._recordId}get contextId(){return this._contextId}get dateCreated(){return this._descriptor.dateCreated}get parentId(){return this._descriptor.parentId}get protocol(){return this._descriptor.protocol}get protocolPath(){return this._descriptor.protocolPath}get recipient(){return this._descriptor.recipient}get schema(){return this._descriptor.schema}get dataFormat(){return this._descriptor.dataFormat}get dataCid(){return this._descriptor.dataCid}get dataSize(){return this._descriptor.dataSize}get datePublished(){return this._descriptor.datePublished}get published(){return this._descriptor.published}get tags(){return this._descriptor.tags}get author(){return this._author}get creator(){return this._creator}get timestamp(){return this._descriptor.messageTimestamp}get encryption(){return this._encryption}get authorization(){return this._authorization}get attestation(){return this._attestation}get initialWrite(){return this._initialWrite}get remoteOrigin(){return this._remoteOrigin}get data(){let e=this;return{async blob(){return new Blob([await Co.consumeToBytes({readableStream:await this.stream()})],{type:e.dataFormat})},async bytes(){return await Co.consumeToBytes({readableStream:await this.stream()})},async json(){return await Co.consumeToJson({readableStream:await this.stream()})},async text(){return await Co.consumeToText({readableStream:await this.stream()})},async stream(){if(e._encodedData)return Co.fromBlob(e._encodedData);if(e._readableStream){let n=e._readableStream;return e._readableStream=void 0,n}else return await e.readRecordData()},then(n,i){return this.stream().then(n,i)},catch(n){return this.stream().catch(n)}}}toJSON(){return{attestation:this.attestation,author:this.author,authorization:this.authorization,contextId:this.contextId,dataCid:this.dataCid,dataFormat:this.dataFormat,dataSize:this.dataSize,dateCreated:this.dateCreated,datePublished:this.datePublished,encryption:this.encryption,parentId:this.parentId,protocol:this.protocol,protocolPath:this.protocolPath,published:this.published,recipient:this.recipient,recordId:this.id,schema:this.schema,tags:this.tags,timestamp:this.timestamp}}toString(){let e=`ReadOnlyRecord: {
|
|
2058
|
+
`);Fo();Kt();y();y();rn();y();Kt();rn();y();Kt();rn();y();rn();rn();Jn();y();Kt();rn();y();Fo();y();Kt();y();Jn();Kt();var Cc=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Yz=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},fi=class t{get agent(){if(!this._agent)throw new Error("AgentPermissionsApi: Agent is not set");return this._agent}set agent(e){this._agent=e}constructor({agent:e}={}){this._cachedPermissions=new Kl.default({ttl:60*1e3}),this._agent=e}getPermissionForRequest(e){return Cc(this,arguments,void 0,function*({connectedDid:r,delegateDid:n,delegate:i,messageType:a,protocol:s,cached:o=!1}){let d=[r,n,a,s].join("~"),u=o?this._cachedPermissions.get(d):void 0;if(u)return u;let c=yield this.fetchGrants({author:n,target:n,grantor:r,grantee:n}),l=yield t.matchGrantFromArray(r,n,{messageType:a,protocol:s},c,i);if(!l)throw new Error(`CachedPermissions: No permissions found for ${a}: ${s}`);return this._cachedPermissions.set(d,l),l})}fetchGrants(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantee:i,grantor:a,protocol:s,remote:o=!1,checkRevoked:d=!0}){let u=s?{protocol:s}:void 0,c={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{author:a,recipient:i,protocol:zt.uri,protocolPath:zt.grantPath,tags:u}}},{reply:l}=o?yield this.agent.sendDwnRequest(c):yield this.agent.processDwnRequest(c);if(l.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch grants: ${l.status.detail}`);let f=d?yield this.fetchRevokedGrantIds({author:r,target:n,grantor:a,remote:o,tags:u}):new Set,h=[];for(let p of l.entries){if(f.has(p.recordId))continue;let m=dr.parse(p);h.push({grant:m,message:p})}return h})}fetchRevokedGrantIds(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantor:i,remote:a,tags:s}){let o={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{author:i,protocol:zt.uri,protocolPath:zt.revocationPath,tags:s}}},{reply:d}=a?yield this.agent.sendDwnRequest(o):yield this.agent.processDwnRequest(o);if(d.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch revocations: ${d.status.detail}`);let u=new Set;for(let c of d.entries)c.descriptor.parentId!==void 0&&u.add(c.descriptor.parentId);return u})}fetchRequests(e){return Cc(this,arguments,void 0,function*({author:r,target:n,protocol:i,remote:a=!1}){let s=i?{protocol:i}:void 0,o={author:r,target:n,messageType:Te.RecordsQuery,messageParams:{filter:{protocol:zt.uri,protocolPath:zt.requestPath,tags:s}}},{reply:d}=a?yield this.agent.sendDwnRequest(o):yield this.agent.processDwnRequest(o);if(d.status.code!==200)throw new Error(`PermissionsApi: Failed to fetch requests: ${d.status.detail}`);let u=[];for(let c of d.entries){let l=Ia.parse(c);u.push({request:l,message:c})}return u})}isGrantRevoked(e){return Cc(this,arguments,void 0,function*({author:r,target:n,grantRecordId:i,remote:a=!1}){let s={author:r,target:n,messageType:Te.RecordsRead,messageParams:{filter:{parentId:i,protocol:zt.uri,protocolPath:zt.revocationPath}}},{reply:o}=a?yield this.agent.sendDwnRequest(s):yield this.agent.processDwnRequest(s);if(o.status.code===404)return!1;if(o.status.code===200)return!0;throw new Error(`PermissionsApi: Failed to check if grant is revoked: ${o.status.detail}`)})}createGrant(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,delegated:i=!1}=e,a=Yz(e,["author","store","delegated"]),s;zt.hasProtocolScope(a.scope)&&(s={protocol:a.scope.protocol});let o={dateExpires:a.dateExpires,requestId:a.requestId,description:a.description,delegated:i,scope:a.scope},d=Ue.object(o).toUint8Array(),u={recipient:a.grantedTo,protocol:zt.uri,protocolPath:zt.grantPath,dataFormat:"application/json",tags:s},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([d])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create grant: ${c.status.detail}`);let f=Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(d).toBase64Url()});return{grant:dr.parse(f),message:f}})}createRequest(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,delegated:i=!1}=e,a=Yz(e,["author","store","delegated"]),s;zt.hasProtocolScope(a.scope)&&(s={protocol:a.scope.protocol});let o={description:a.description,delegated:i,scope:a.scope},d=Ue.object(o).toUint8Array(),u={protocol:zt.uri,protocolPath:zt.requestPath,dataFormat:"application/json",tags:s},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([d])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create request: ${c.status.detail}`);let f=Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(d).toBase64Url()});return{request:Ia.parse(f),message:f}})}createRevocation(e){return Cc(this,void 0,void 0,function*(){let{author:r,store:n=!1,grant:i,description:a}=e,s={description:a},o=Ue.object(s).toUint8Array(),d;zt.hasProtocolScope(i.scope)&&(d={protocol:i.scope.protocol});let u={parentContextId:i.id,protocol:zt.uri,protocolPath:zt.revocationPath,dataFormat:"application/json",tags:d},{reply:c,message:l}=yield this.agent.processDwnRequest({store:n,author:r,target:r,messageType:Te.RecordsWrite,messageParams:u,dataStream:new Blob([o])});if(c.status.code!==202)throw new Error(`PermissionsApi: Failed to create revocation: ${c.status.detail}`);return{message:Object.assign(Object.assign({},l),{encodedData:Ue.uint8Array(o).toBase64Url()})}})}clear(){return Cc(this,void 0,void 0,function*(){this._cachedPermissions.clear()})}static matchGrantFromArray(e,r,n,i){return Cc(this,arguments,void 0,function*(a,s,o,d,u=!1){let c;for(let l of d){let{grant:f,message:h}=l;if(u===!0&&f.delegated!==!0)continue;let{messageType:p,protocol:m,protocolPath:g,contextId:_}=o;if(this.matchScopeFromGrant(a,s,p,f,m,g,_)){if(f.scope.interface+f.scope.method===p)return{grant:f,message:h};c||(c={grant:f,message:h})}}return c})}static matchScopeFromGrant(e,r,n,i,a,s,o){if(i.grantee!==r||i.grantor!==e)return!1;let d=i.scope,u=d.interface+d.method;if(u===n||u===Te.MessagesRead&&(n===Te.MessagesSync||n===Te.MessagesSubscribe))if(YI(n)){let l=d;if(l.protocol!==a)return!1;if(this.isUnrestrictedProtocolScope(l)||l.protocolPath!==void 0&&l.protocolPath===s||l.contextId!==void 0&&o?.startsWith(l.contextId))return!0}else{let l=d;return l.protocol===void 0?!0:l.protocol!==a?!1:this.isUnrestrictedProtocolScope(l)}return!1}static isUnrestrictedProtocolScope(e){return e.contextId===void 0&&e.protocolPath===void 0}};y();var s7=wn(pP(),1);Jn();import{Level as Xfe}from"level";y();Jn();function Qz(t){let e=t.descriptor;return e.interface!==Ge.Records||e.method!==ze.Write?!1:e.dateCreated===e.messageTimestamp}function Em(t){var e;if(t.length<=1)return t;let r=new Map,n=new Map,i=new Map,a=new Map;for(let l=0;l<t.length;l++){let f=t[l];r.set(l,f);let h=f.message.descriptor;if(h.interface===Ge.Protocols&&h.method===ze.Configure){let p=(e=h.definition)===null||e===void 0?void 0:e.protocol;p&&n.set(p,l)}if(h.interface===Ge.Records&&h.method===ze.Write){let p=f.message.recordId;Qz(f.message)&&p&&i.set(p,l),h.protocol===zt.uri&&h.protocolPath===zt.grantPath&&p&&a.set(p,l)}}let s=new Map,o=new Array(t.length).fill(0),d=(l,f)=>{if(l===f)return;s.has(l)||s.set(l,new Set);let h=s.get(l);h.has(f)||(h.add(f),o[f]++)};for(let l=0;l<t.length;l++){let f=t[l].message.descriptor;if(f.interface===Ge.Records){let p=f.protocol;p&&n.has(p)&&d(n.get(p),l)}if(f.interface===Ge.Records&&f.parentId){let p=f.parentId;i.has(p)&&d(i.get(p),l)}if(f.interface===Ge.Records&&f.method===ze.Write){let p=t[l].message.recordId;p&&!Qz(t[l].message)&&i.has(p)&&d(i.get(p),l)}if(f.interface===Ge.Records&&f.method===ze.Delete){let p=f.recordId;p&&i.has(p)&&d(i.get(p),l)}let h=f.permissionGrantId;h&&a.has(h)&&d(a.get(h),l)}let u=[];for(let l=0;l<t.length;l++)o[l]===0&&u.push(l);let c=[];for(;u.length>0;){let l=u.shift();c.push(r.get(l));let f=s.get(l);if(f)for(let h of f)o[h]--,o[h]===0&&u.push(h)}if(c.length<t.length){let l=new Set(c);for(let f=0;f<t.length;f++){let h=r.get(f);l.has(h)||c.push(h)}}return c}y();Jn();var tp=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Jfe=1048576;function e7(t){var e,r;return t.status.code===202||t.status.code===204||t.status.code===409||((e=t.entry)===null||e===void 0?void 0:e.message.descriptor.interface)===Ge.Records&&((r=t.entry)===null||r===void 0?void 0:r.message.descriptor.method)===ze.Delete&&t.status.code===404}function t7(t){return tp(this,void 0,void 0,function*(){try{return yield Se.getCid(t)}catch{return"unknown"}})}function r7(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,prefetched:s,agent:o,permissionsApi:d}){let u=[];if(s)for(let m of s){if(!m.message)continue;let g={message:m.message};if(m.encodedData){let _=ke.base64UrlToBytes(m.encodedData);g.bufferedData=_,g.dataStream=new ReadableStream({start(v){v.enqueue(_),v.close()}})}u.push(g)}let c=a.length>0?yield Xz({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:o,permissionsApi:d}):[],l=[...u,...c],f=Em(l);yield Zfe(f);let h=3,p=f;for(let m=0;m<=h&&p.length>0;m++){let g=[];for(let _ of p){let v=_.bufferedData?new ReadableStream({start(T){T.enqueue(_.bufferedData),T.close()}}):_.dataStream,E=yield o.dwn.processRawMessage(e,_.message,{dataStream:v});e7(E)||g.push(_)}if(g.length>0){let _=[],v=[];for(let E of g)if(E.bufferedData||!E.dataStream)v.push(E);else{let T=yield t7(E.message);_.push(T)}if(_.length>0){let E=yield Xz({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:_,agent:o,permissionsApi:d});v.push(...E)}p=Em(v)}else p=[]}})}function Zfe(t){return tp(this,void 0,void 0,function*(){for(let e of t){if(!e.dataStream)continue;let r=[],n=0,i=!1,a=e.dataStream.getReader();try{for(;;){let{done:d,value:u}=yield a.read();if(d)break;if(n+=u.byteLength,n>Jfe){i=!0;break}r.push(u)}}finally{a.releaseLock()}if(i){e.dataStream=void 0;continue}let s=new Uint8Array(n),o=0;for(let d of r)s.set(d,o),o+=d.byteLength;e.bufferedData=s,e.dataStream=new ReadableStream({start(d){d.enqueue(s),d.close()}})}})}function Xz(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:s,permissionsApi:o}){let d=[],u;n&&(u=(yield o.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesRead,delegateDid:n,protocol:i,cached:!0})).grant.id);let c=4,l=0;for(;l<a.length;){let f=a.slice(l,l+c);l+=c;let h=yield Promise.all(f.map(p=>tp(this,void 0,void 0,function*(){var m,g;let _=yield s.processDwnRequest({store:!1,author:e,target:e,messageType:Te.MessagesRead,granteeDid:n,messageParams:{messageCid:p,permissionGrantId:u}}),v;try{v=yield s.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:_.message})}catch(D){console.error(`SyncEngineLevel: pull - failed to read ${p} from ${r}:`,(m=D.message)!==null&&m!==void 0?m:D);return}if(v.status.code!==200||!(!((g=v.entry)===null||g===void 0)&&g.message))return;let E=v.entry,T;return vm(E)&&E.data&&(T=E.data),{message:E.message,dataStream:T}})));for(let p of h)p&&d.push(p)}return d})}function QI(t){return tp(this,arguments,void 0,function*({did:e,dwnUrl:r,delegateDid:n,protocol:i,messageCids:a,agent:s,permissionsApi:o}){var d;let u=[];for(let l of a){let f=yield Yfe({author:e,messageCid:l,delegateDid:n,protocol:i,agent:s,permissionsApi:o});f&&u.push(f)}let c=Em(u);for(let l of c)try{let f=yield s.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,data:l.dataStream,message:l.message});if(!e7(f)){let h=yield t7(l.message);console.error(`SyncEngineLevel: push failed for ${h}: ${f.status.code} ${f.status.detail}`)}}catch(f){let h=(d=f.message)!==null&&d!==void 0?d:f;throw new Error(`SyncEngineLevel: push to ${r} failed: ${h}`)}})}function Yfe(t){return tp(this,arguments,void 0,function*({author:e,delegateDid:r,protocol:n,messageCid:i,agent:a,permissionsApi:s}){let o;r&&(o=(yield s.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesRead,delegateDid:r,protocol:n,cached:!0})).grant.id);let{reply:d}=yield a.dwn.processRequest({author:e,target:e,messageType:Te.MessagesRead,granteeDid:r,messageParams:{messageCid:i,permissionGrantId:o}});if(d.status.code!==200||!d.entry)return;let u=d.entry,c={message:u.message};return vm(u)&&u.data&&(c.dataStream=u.data),c})}var At=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},Qfe=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof __values=="function"?__values(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(a){r[a]=t[a]&&function(s){return new Promise(function(o,d){s=t[a](s),i(o,d,s.done,s.value)})}}function i(a,s,o,d){Promise.resolve(d).then(function(u){a({value:u,done:o})},s)}},n7=16,i7=8,epe=4,XI=class{constructor(e){this._waiting=[],this._permits=e}acquire(){return At(this,void 0,void 0,function*(){if(this._permits>0){this._permits--;return}return new Promise(e=>{this._waiting.push(e)})})}release(){let e=this._waiting.shift();e?e():this._permits++}run(e){return At(this,void 0,void 0,function*(){yield this.acquire();try{return yield e()}finally{this.release()}})}},o7="^",tpe=250,Sm=class t{constructor({agent:e,dataPath:r,db:n}){this._syncLock=!1,this._syncMode="poll",this._liveSubscriptions=[],this._localSubscriptions=[],this._connectivityState="unknown",this._pendingPushCids=new Map,this._consecutiveFailures=0,this._agent=e,this._permissionsApi=new fi({agent:e}),this._db=n||new Xfe(r??"DATA/AGENT/SYNC_STORE")}get agent(){if(this._agent===void 0)throw new Error("SyncEngineLevel: Unable to determine agent execution context.");return this._agent}set agent(e){this._agent=e,this._permissionsApi=new fi({agent:e})}get connectivityState(){return this._connectivityState}clear(){return At(this,void 0,void 0,function*(){yield this._permissionsApi.clear(),yield this._db.clear()})}close(){return At(this,void 0,void 0,function*(){yield this._db.close()})}registerIdentity(e){return At(this,arguments,void 0,function*({did:r,options:n}){let i=this._db.sublevel("registeredIdentities");if(yield this.getIdentityOptions(r))throw new Error(`SyncEngineLevel: Identity with DID ${r} is already registered.`);n??(n={protocols:[]}),yield i.put(r,JSON.stringify(n))})}unregisterIdentity(e){return At(this,void 0,void 0,function*(){let r=this._db.sublevel("registeredIdentities");if(!(yield this.getIdentityOptions(e)))throw new Error(`SyncEngineLevel: Identity with DID ${e} is not registered.`);yield r.del(e)})}getIdentityOptions(e){return At(this,void 0,void 0,function*(){let r=this._db.sublevel("registeredIdentities");try{let n=yield r.get(e);if(n)return JSON.parse(n)}catch(n){let i=n;if(i.code==="LEVEL_NOT_FOUND")return;throw new Error(`SyncEngineLevel: Error reading level: ${i.code}.`)}})}updateIdentityOptions(e){return At(this,arguments,void 0,function*({did:r,options:n}){let i=this._db.sublevel("registeredIdentities");if(!(yield this.getIdentityOptions(r)))throw new Error(`SyncEngineLevel: Identity with DID ${r} is not registered.`);yield i.put(r,JSON.stringify(n))})}sync(e){return At(this,void 0,void 0,function*(){if(this._syncLock)throw new Error("SyncEngineLevel: Sync operation is already in progress.");this._syncLock=!0;try{let r=yield this.getSyncTargets(),n=new Set,i=!1;for(let a of r){let{did:s,delegateDid:o,dwnUrl:d,protocol:u}=a;if(!n.has(d))try{let c=yield this.getLocalRoot(s,o,u),l=yield this.getRemoteRoot(s,d,o,u);if(c===l)continue;let f=yield this.diffWithRemote({did:s,dwnUrl:d,delegateDid:o,protocol:u});if((!e||e==="pull")&&f.onlyRemote.length>0){let h=[],p=[];for(let m of f.onlyRemote)m.message?m.message.descriptor.interface==="Records"&&m.message.descriptor.method==="Write"&&m.message.descriptor.dataCid&&!m.encodedData?p.push(m.messageCid):h.push(m):p.push(m.messageCid);yield this.pullMessages({did:s,dwnUrl:d,delegateDid:o,protocol:u,messageCids:p,prefetched:h})}(!e||e==="push")&&f.onlyLocal.length>0&&(yield this.pushMessages({did:s,dwnUrl:d,delegateDid:o,protocol:u,messageCids:f.onlyLocal}))}catch(c){n.add(d),i=!0,console.error(`SyncEngineLevel: Error syncing ${s} with ${d}`,c)}}i?(this._consecutiveFailures++,this._connectivityState==="online"&&(this._connectivityState="offline")):(this._consecutiveFailures=0,r.length>0&&(this._connectivityState="online"))}finally{this._syncLock=!1}})}startSync(e){return At(this,void 0,void 0,function*(){var r,n;let i=(r=e.mode)!==null&&r!==void 0?r:"poll",a=(n=e.interval)!==null&&n!==void 0?n:i==="live"?"5m":"2m",s=(0,s7.default)(a);(this._liveSubscriptions.length>0||this._localSubscriptions.length>0)&&(yield this.teardownLiveSync()),this._syncIntervalId&&(clearInterval(this._syncIntervalId),this._syncIntervalId=void 0),this._syncMode=i,i==="live"?yield this.startLiveSync(s):yield this.startPollSync(s)})}stopSync(){return At(this,arguments,void 0,function*(e=2e3){let r=0;for(;this._syncLock;){if(r>=e)throw new Error(`SyncEngineLevel: Existing sync operation did not complete within ${e} milliseconds.`);r+=100,yield new Promise(n=>{setTimeout(n,e<100?e:100)})}this._syncIntervalId&&(clearInterval(this._syncIntervalId),this._syncIntervalId=void 0),yield this.teardownLiveSync()})}startPollSync(e){return At(this,void 0,void 0,function*(){let r=()=>At(this,void 0,void 0,function*(){if(this._syncLock)return;clearInterval(this._syncIntervalId),this._syncIntervalId=void 0;try{yield this.sync()}catch(a){console.error("SyncEngineLevel: Error during sync operation",a)}let n=Math.min(Math.pow(2,this._consecutiveFailures),t.MAX_BACKOFF_MULTIPLIER),i=this._consecutiveFailures>0?e*n:e;this._syncIntervalId||(this._syncIntervalId=setInterval(r,i))});this._syncIntervalId&&clearInterval(this._syncIntervalId),this._syncIntervalId=setInterval(r,e),this._syncLock||(yield this.sync())})}startLiveSync(e){return At(this,void 0,void 0,function*(){try{yield this.sync()}catch(i){console.error("SyncEngineLevel: Error during initial live-sync catch-up",i)}let r=yield this.getSyncTargets();for(let i of r)try{yield this.openLivePullSubscription(i),yield this.openLocalPushSubscription(i)}catch(a){console.error(`SyncEngineLevel: Failed to open live subscription for ${i.did} -> ${i.dwnUrl}`,a)}let n=()=>At(this,void 0,void 0,function*(){if(!this._syncLock)try{yield this.sync()}catch(i){console.error("SyncEngineLevel: Error during SMT integrity check",i)}});this._syncIntervalId=setInterval(n,e)})}teardownLiveSync(){return At(this,void 0,void 0,function*(){this._pushDebounceTimer&&(clearTimeout(this._pushDebounceTimer),this._pushDebounceTimer=void 0),this._pendingPushCids.clear();for(let e of this._liveSubscriptions)try{yield e.close()}catch{}this._liveSubscriptions=[];for(let e of this._localSubscriptions)try{yield e.close()}catch{}this._localSubscriptions=[]})}openLivePullSubscription(e){return At(this,void 0,void 0,function*(){let{did:r,delegateDid:n,dwnUrl:i,protocol:a}=e,s=this.buildCursorKey(r,i,a),o=yield this.getCursor(s),d=a?[{protocol:a}]:[],u;if(n)try{u=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesSubscribe,delegateDid:n,protocol:a,cached:!0})).grant.id}catch{u=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesRead,delegateDid:n,protocol:a,cached:!0})).grant.id}let c=h=>At(this,void 0,void 0,function*(){if(h.type==="eose"){yield this.setCursor(s,h.cursor),this._connectivityState="online";return}if(h.type==="event"){let p=h.event;try{let m=this.extractDataStream(p);yield this.agent.dwn.processRawMessage(r,p.message,{dataStream:m})}catch(m){console.error(`SyncEngineLevel: Error processing live-pull event for ${r}`,m)}yield this.setCursor(s,h.cursor)}}),f=(yield this.agent.dwn.sendRequest({author:r,target:r,messageType:Te.MessagesSubscribe,granteeDid:n,messageParams:{filters:d,cursor:o,permissionGrantId:u},subscriptionHandler:c})).reply;if(f.status.code!==200||!f.subscription){console.error(`SyncEngineLevel: MessagesSubscribe failed for ${r} -> ${i}: ${f.status.code} ${f.status.detail}`);return}this._liveSubscriptions.push({did:r,dwnUrl:i,delegateDid:n,protocol:a,close:()=>At(this,void 0,void 0,function*(){yield f.subscription.close()})}),this._connectivityState="online"})}openLocalPushSubscription(e){return At(this,void 0,void 0,function*(){let{did:r,delegateDid:n,dwnUrl:i,protocol:a}=e,s=a?[{protocol:a}]:[],o;n&&(o=(yield this._permissionsApi.getPermissionForRequest({connectedDid:r,messageType:Te.MessagesRead,delegateDid:n,protocol:a,cached:!0})).grant.id);let d=l=>At(this,void 0,void 0,function*(){if(l.type!=="event")return;let f=this.buildCursorKey(r,i,a),h=yield Se.getCid(l.event.message);if(h===void 0)return;let p=this._pendingPushCids.get(f);p||(p={did:r,dwnUrl:i,delegateDid:n,protocol:a,cids:[]},this._pendingPushCids.set(f,p)),p.cids.push(h),this._pushDebounceTimer&&clearTimeout(this._pushDebounceTimer),this._pushDebounceTimer=setTimeout(()=>{this.flushPendingPushes()},tpe)}),c=(yield this.agent.dwn.processRequest({author:r,target:r,messageType:Te.MessagesSubscribe,granteeDid:n,messageParams:{filters:s,permissionGrantId:o},subscriptionHandler:d})).reply;if(c.status.code!==200||!c.subscription){console.error(`SyncEngineLevel: Local MessagesSubscribe failed for ${r}: ${c.status.code} ${c.status.detail}`);return}this._localSubscriptions.push({did:r,dwnUrl:i,delegateDid:n,protocol:a,close:()=>At(this,void 0,void 0,function*(){yield c.subscription.close()})})})}flushPendingPushes(){return At(this,void 0,void 0,function*(){this._pushDebounceTimer=void 0;let e=[...this._pendingPushCids.entries()];this._pendingPushCids.clear();for(let[,r]of e){let{did:n,dwnUrl:i,delegateDid:a,protocol:s,cids:o}=r;if(o.length!==0)try{yield QI({did:n,dwnUrl:i,delegateDid:a,protocol:s,messageCids:o,agent:this.agent,permissionsApi:this._permissionsApi})}catch(d){console.error(`SyncEngineLevel: Push-on-write failed for ${n} -> ${i}`,d)}}})}buildCursorKey(e,r,n){let i=`${e}${o7}${r}`;return n?`${i}${o7}${n}`:i}getCursor(e){return At(this,void 0,void 0,function*(){let r=this._db.sublevel("syncCursors");try{return yield r.get(e)}catch(n){if(n.code==="LEVEL_NOT_FOUND")return;throw n}})}setCursor(e,r){return At(this,void 0,void 0,function*(){yield this._db.sublevel("syncCursors").put(e,r)})}extractDataStream(e){if(vm(e)&&e.data)return e.data}getDefaultHashHex(e){return At(this,void 0,void 0,function*(){var r;if(this._defaultHashHex===void 0){let n=yield Ng(),i=new Map;for(let a=0;a<=n7;a++)i.set(a,md(n[a]));this._defaultHashHex=i}return(r=this._defaultHashHex.get(e))!==null&&r!==void 0?r:""})}static parseBitPrefix(e){return Array.from(e,r=>r==="1")}get stateIndex(){if(!this.agent.dwn.isRemoteMode)return this.agent.dwn.node.storage.stateIndex}getLocalRoot(e,r,n){return At(this,void 0,void 0,function*(){var i;let a=this.stateIndex;if(a){let u=n!==void 0?yield a.getProtocolRoot(e,n):yield a.getRoot(e);return md(u)}let s=yield this.getSyncPermissionGrantId(e,r,n);return(i=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:r,messageParams:{action:"root",protocol:n,permissionGrantId:s}})).reply.root)!==null&&i!==void 0?i:""})}getRemoteRoot(e,r,n,i){return At(this,void 0,void 0,function*(){var a;let s=yield this.getSyncPermissionGrantId(e,n,i),o=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"root",protocol:i,permissionGrantId:s}});return(a=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:o.message})).root)!==null&&a!==void 0?a:""})}walkTreeDiff(e){return At(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a}){let s=[],o=[],d=yield this.getSyncPermissionGrantId(r,i,a),u=new XI(epe),c=l=>At(this,void 0,void 0,function*(){let[f,h]=yield Promise.all([this.getLocalSubtreeHash(r,l,i,a,d),u.run(()=>this.getRemoteSubtreeHash(r,n,l,i,a,d))]);if(f===h)return;let p=yield this.getDefaultHashHex(l.length);if(h===p&&f!==p){let m=yield this.getLocalLeaves(r,l,i,a,d);s.push(...m);return}if(f===p&&h!==p){let m=yield u.run(()=>this.getRemoteLeaves(r,n,l,i,a,d));o.push(...m);return}if(l.length>=n7){let[m,g]=yield Promise.all([this.getLocalLeaves(r,l,i,a,d),u.run(()=>this.getRemoteLeaves(r,n,l,i,a,d))]),_=new Set(m),v=new Set(g);for(let E of m)v.has(E)||s.push(E);for(let E of g)_.has(E)||o.push(E);return}yield Promise.all([c(l+"0"),c(l+"1")])});return yield c(""),{onlyLocal:s,onlyRemote:o}})}diffWithRemote(e){return At(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a}){var s,o;let d=yield this.collectLocalSubtreeHashes(r,a,i7),u=yield this.getSyncPermissionGrantId(r,i,a),c=yield this.agent.dwn.processRequest({store:!1,author:r,target:r,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"diff",protocol:a,hashes:d,depth:i7,permissionGrantId:u}}),l=yield this.agent.rpc.sendDwnRequest({dwnUrl:n,targetDid:r,message:c.message});if(l.status.code!==200)throw new Error(`SyncEngineLevel: diff failed with ${l.status.code}: ${l.status.detail}`);let f=yield this.getSyncPermissionGrantId(r,i,a),h=[];for(let p of(s=l.onlyLocal)!==null&&s!==void 0?s:[]){let m=yield this.getLocalLeaves(r,p,i,a,f);h.push(...m)}return{onlyRemote:(o=l.onlyRemote)!==null&&o!==void 0?o:[],onlyLocal:h}})}collectLocalSubtreeHashes(e,r,n){return At(this,void 0,void 0,function*(){let i={},a=yield this.getDefaultHashHex(n),s=this.stateIndex,o=(d,u)=>At(this,void 0,void 0,function*(){let c;if(s){let l=t.parseBitPrefix(d),f=r!==void 0?yield s.getProtocolSubtreeHash(e,r,l):yield s.getSubtreeHash(e,l);c=md(f)}else c=yield this.getLocalSubtreeHash(e,d,void 0,r);if(c!==a){if(u>=n){i[d]=c;return}yield Promise.all([o(d+"0",u+1),o(d+"1",u+1)])}});return yield o("",0),i})}getLocalSubtreeHash(e,r,n,i,a){return At(this,void 0,void 0,function*(){var s;let o=this.stateIndex;if(o){let c=t.parseBitPrefix(r),l=i!==void 0?yield o.getProtocolSubtreeHash(e,i,c):yield o.getSubtreeHash(e,c);return md(l)}return(s=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"subtree",prefix:r,protocol:i,permissionGrantId:a}})).reply.hash)!==null&&s!==void 0?s:""})}getRemoteSubtreeHash(e,r,n,i,a,s){return At(this,void 0,void 0,function*(){var o;let d=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"subtree",prefix:n,protocol:a,permissionGrantId:s}});return(o=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:d.message})).hash)!==null&&o!==void 0?o:""})}getLocalLeaves(e,r,n,i,a){return At(this,void 0,void 0,function*(){var s;let o=this.stateIndex;if(o){let c=t.parseBitPrefix(r);return i!==void 0?yield o.getProtocolLeaves(e,i,c):yield o.getLeaves(e,c)}return(s=(yield this.agent.dwn.processRequest({author:e,target:e,messageType:Te.MessagesSync,granteeDid:n,messageParams:{action:"leaves",prefix:r,protocol:i,permissionGrantId:a}})).reply.entries)!==null&&s!==void 0?s:[]})}getRemoteLeaves(e,r,n,i,a,s){return At(this,void 0,void 0,function*(){var o;let d=yield this.agent.dwn.processRequest({store:!1,author:e,target:e,messageType:Te.MessagesSync,granteeDid:i,messageParams:{action:"leaves",prefix:n,protocol:a,permissionGrantId:s}});return(o=(yield this.agent.rpc.sendDwnRequest({dwnUrl:r,targetDid:e,message:d.message})).entries)!==null&&o!==void 0?o:[]})}pullMessages(e){return At(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,prefetched:o}){return r7({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,prefetched:o,agent:this.agent,permissionsApi:this._permissionsApi})})}pushMessages(e){return At(this,arguments,void 0,function*({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s}){return QI({did:r,dwnUrl:n,delegateDid:i,protocol:a,messageCids:s,agent:this.agent,permissionsApi:this._permissionsApi})})}static topologicalSort(e){return Em(e)}getSyncTargets(){return At(this,void 0,void 0,function*(){var e,r,n,i;let a=[];try{for(var s=!0,o=Qfe(this._db.sublevel("registeredIdentities").iterator()),d;d=yield o.next(),e=d.done,!e;s=!0){i=d.value,s=!1;let[u,c]=i,l;try{l=JSON.parse(c)}catch(m){console.warn(`SyncEngineLevel: Corrupt sync options for ${u}, falling back to global sync:`,m),l={protocols:[]}}let{protocols:f,delegateDid:h}=l,p=yield this.agent.dwn.getDwnEndpointUrlsForTarget(u);if(p.length!==0)for(let m of p)if(f.length===0)a.push({did:u,delegateDid:h,dwnUrl:m});else for(let g of f)a.push({did:u,delegateDid:h,dwnUrl:m,protocol:g})}}catch(u){r={error:u}}finally{try{!s&&!e&&(n=o.return)&&(yield n.call(o))}finally{if(r)throw r.error}}return a})}getSyncPermissionGrantId(e,r,n){return At(this,void 0,void 0,function*(){return r?(yield this._permissionsApi.getPermissionForRequest({connectedDid:e,messageType:Te.MessagesSync,delegateDid:r,protocol:n,cached:!0})).grant.id:void 0})}};Sm.MAX_CONSECUTIVE_FAILURES=5;Sm.MAX_BACKOFF_MULTIPLIER=4;y();Jn();Fo();Kt();import{Level as VWe}from"level";y();y();y();Kt();rn();y();y();var a7=wn(pP(),1);Kt();var Tm=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},mP=class{constructor({ttl:e="15m"}={}){this.cache=new Kl.default({ttl:(0,a7.default)(e)})}get(e){return Tm(this,void 0,void 0,function*(){return this.cache.get(e)})}set(e,r){return Tm(this,void 0,void 0,function*(){this.cache.set(e,r)})}delete(e){return Tm(this,void 0,void 0,function*(){this.cache.delete(e)})}clear(){return Tm(this,void 0,void 0,function*(){this.cache.clear()})}open(){return Tm(this,void 0,void 0,function*(){})}close(){return Tm(this,void 0,void 0,function*(){})}};y();rn();Jn();y();var km=class extends Error{constructor(e,r){super(r??`Rate limit exceeded, retry after ${e}s`),this.name="RateLimitError",this.retryAfterSec=e}};y();var Am;(function(t){t[t.InvalidRequest=-32600]="InvalidRequest",t[t.MethodNotFound=-32601]="MethodNotFound",t[t.InvalidParams=-32602]="InvalidParams",t[t.InternalError=-32603]="InternalError",t[t.ParseError=-32700]="ParseError",t[t.TransportError=-32300]="TransportError",t[t.BadRequest=-50400]="BadRequest",t[t.Unauthorized=-50401]="Unauthorized",t[t.Forbidden=-50403]="Forbidden",t[t.Conflict=-50409]="Conflict",t[t.TooManyRequests=-50429]="TooManyRequests"})(Am||(Am={}));var Dm=(t,e,r)=>({jsonrpc:"2.0",id:t,method:e,params:r}),yP=(t,e,r,n)=>({jsonrpc:"2.0",id:t,method:e,params:r,subscription:{id:n??null}}),c7=(t,e)=>({jsonrpc:"2.0",method:"rpc.ack",params:{cursor:e},subscription:{id:t}});function rp(t){try{return JSON.parse(t)}catch{return null}}var eR=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},rpe=3,npe=500,ipe=1e4,ope=3e4,d7=new Set([408,429,500,502,503,504]);function spe(t,e){return t instanceof TypeError?!0:e?d7.has(e.status):!1}function ape(t,e,r){let n=Math.min(e*Math.pow(2,t),r),i=.5+Math.random()*.5;return n*i}function cpe(t){let e=t.headers.get("retry-after");if(e===null)return;let r=Number(e);if(!Number.isNaN(r)&&r>=0)return r*1e3;let n=new Date(e);if(!Number.isNaN(n.getTime())){let i=n.getTime()-Date.now();return i>0?i:0}}var gP=class t{constructor(e,r){var n,i,a;this.serverInfoCache=e??new mP,this._retryOptions={maxRetries:(n=r?.maxRetries)!==null&&n!==void 0?n:rpe,baseDelayMs:(i=r?.baseDelayMs)!==null&&i!==void 0?i:npe,maxDelayMs:(a=r?.maxDelayMs)!==null&&a!==void 0?a:ipe}}static isBunRuntime(){return typeof globalThis.Bun<"u"}get transportProtocols(){return["http:","https:"]}sendDwnRequest(e){return eR(this,void 0,void 0,function*(){var r,n,i;let a=gi.randomUuid(),s=Dm(a,"dwn.processMessage",{target:e.targetDid,message:e.message}),o={"dwn-request":JSON.stringify(s)},d={method:"POST",headers:o};if(e.data){o["content-type"]="application/octet-stream";let h=e.data;if(h instanceof ReadableStream)if(t.isBunRuntime()){let p=yield Hi.toBytes(h);h=new Blob([p],{type:"application/octet-stream"})}else d.duplex="half";d.body=h}let u=yield this.fetchWithRetry(e.dwnUrl,d);if(u.status===429){let h=parseInt((r=u.headers.get("retry-after"))!==null&&r!==void 0?r:"1",10);throw new km(h)}let c,l=u.headers.has("dwn-response");if(l){let h=rp(u.headers.get("dwn-response"));if(h==null)throw new Error(`failed to parse json rpc response. dwn url: ${e.dwnUrl}`);c=h}else{let h=yield u.text(),p=rp(h);if(p==null)throw new Error(`failed to parse json rpc response. dwn url: ${e.dwnUrl}, status: ${u.status}`);c=p}if(c.error){let{code:h,message:p}=c.error;if(h===Am.TooManyRequests){let m=(i=(n=c.error.data)===null||n===void 0?void 0:n.retryAfterSec)!==null&&i!==void 0?i:1;throw new km(m)}throw new Error(`(${h}) - ${p}`)}let{reply:f}=c.result;if(l){let h=new Uint8Array(yield u.arrayBuffer()),p=Hi.fromBytes(h);f.record?f.record.data=p:f.entry&&(f.entry.data=p)}return f})}getServerInfo(e){return eR(this,void 0,void 0,function*(){var r;let n=yield this.serverInfoCache.get(e);if(n)return n;let i=new URL(e);i.pathname.endsWith("/")?i.pathname+="info":i.pathname+="/info";try{let a=yield this.fetchWithRetry(i.toString());if(a.status===429){let s=parseInt((r=a.headers.get("retry-after"))!==null&&r!==void 0?r:"1",10);throw new km(s)}if(a.ok){let s=yield a.json(),o={maxFileSize:s.maxFileSize,maxInFlight:s.maxInFlight,providerAuth:s.providerAuth,registrationRequirements:s.registrationRequirements,server:s.server,sdkVersion:s.sdkVersion,url:s.url,version:s.version,webSocketSupport:s.webSocketSupport};return this.serverInfoCache.set(e,o),o}else throw new Error(`HTTP (${a.status}) - ${a.statusText}`)}catch(a){throw new Error(`Error encountered while processing response from ${i.toString()}: ${a.message}`)}})}fetchWithRetry(e,r){return eR(this,void 0,void 0,function*(){let{maxRetries:n,baseDelayMs:i,maxDelayMs:a}=this._retryOptions,s,o;for(let d=0;d<=n;d++){try{let f=AbortSignal.timeout(ope),h=Object.assign(Object.assign({},r),{signal:r?.signal?AbortSignal.any([r.signal,f]):f}),p=yield fetch(e,h);if(!d7.has(p.status)||d===n)return p;o=p}catch(f){if(!spe(f)||d===n)throw f;s=f}let u=o?cpe(o):void 0,c=ape(d,i,a),l=u!==void 0?Math.max(u,c):c;yield new Promise(f=>{setTimeout(f,l)})}if(o)return o;throw s})}};y();rn();var g0=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})};function tR(t){return typeof t=="string"?t:t instanceof ArrayBuffer?new TextDecoder().decode(t):t instanceof Uint8Array?new TextDecoder().decode(t):String(t)}var u7=3e3,dpe=3e4,upe=1e3,lpe=3e4,fpe=1/0,wP=class t{constructor(e,r,n,i){this.socket=e,this.responseTimeout=r,this.messageHandlers=new Map,this.subscriptionHandlerIds=new Set,this.closedByUser=!1,this.reconnecting=!1,this._isConnected=!1,this.url=n,this.options=i,this._isConnected=!0}get isConnected(){return this._isConnected}static connect(e){return g0(this,arguments,void 0,function*(r,n={}){var i;let{connectTimeout:a=u7,responseTimeout:s=dpe}=n,o;try{o=yield t.createWebSocket(r,a)}catch(u){throw(i=n.onerror)===null||i===void 0||i.call(n,u),u}let d=new t(o,s,r,n);return d.wireSocket(o),d})}close(){this.closedByUser=!0,this._isConnected=!1,this.socket.close()}request(e){return g0(this,void 0,void 0,function*(){return new Promise((r,n)=>{var i;(i=e.id)!==null&&i!==void 0||(e.id=gi.randomUuid());let a=s=>{let o=rp(tR(s.data));if(o.id===e.id)return this.messageHandlers.delete(e.id),r(o)};this.messageHandlers.set(e.id,a),this.send(e),setTimeout(()=>{this.messageHandlers.delete(e.id),n(new Error("request timed out"))},this.responseTimeout)})})}subscribe(e,r){return g0(this,void 0,void 0,function*(){if(!e.method.startsWith("rpc.subscribe."))throw new Error("subscribe rpc requests must include the `rpc.subscribe` prefix");if(!e.subscription)throw new Error("subscribe rpc requests must include subscribe options");let n=e.subscription.id,i=this.messageHandlers.get(n),a=d=>{let u=rp(tR(d.data));u.id===n&&(u.error!==void 0&&(this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n),this.closeSubscription(n).catch(()=>{})),r(u))};this.messageHandlers.set(n,a),this.subscriptionHandlerIds.add(n);let s=yield this.request(e);return s.error?(i?this.messageHandlers.set(n,i):(this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n)),{response:s}):{response:s,close:()=>g0(this,void 0,void 0,function*(){this.messageHandlers.delete(n),this.subscriptionHandlerIds.delete(n),yield this.closeSubscription(n)})}})}closeSubscription(e){let r=gi.randomUuid(),n=yP(r,"rpc.subscribe.close",{},e);return this.request(n)}send(e){this.socket.send(JSON.stringify(e))}static createWebSocket(e,r){return new Promise((n,i)=>{let a=new WebSocket(e),s=()=>{u(),n(a)},o=c=>{u(),i(c)},d=setTimeout(()=>{u(),a.close(),i(new Error("connect timed out"))},r),u=()=>{clearTimeout(d),a.removeEventListener("open",s),a.removeEventListener("error",o)};a.addEventListener("open",s),a.addEventListener("error",o)})}wireSocket(e){e.addEventListener("message",r=>{let n=rp(tR(r.data));if(n===null)return;let i=this.messageHandlers.get(n.id);i&&i(r)}),e.addEventListener("close",()=>{var r,n,i,a,s;if(this._isConnected=!1,this.closedByUser){(n=(r=this.options).onclose)===null||n===void 0||n.call(r);return}this.rejectPendingRequests(),(a=(i=this.options).onclose)===null||a===void 0||a.call(i),((s=this.options.autoReconnect)!==null&&s!==void 0?s:!0)&&!this.reconnecting&&this.attemptReconnect()}),e.addEventListener("error",r=>{var n,i;(i=(n=this.options).onerror)===null||i===void 0||i.call(n,r)})}rejectPendingRequests(){for(let[e,r]of this.messageHandlers)if(!this.subscriptionHandlerIds.has(e)){let n=JSON.stringify({jsonrpc:"2.0",id:e,error:{code:Am.TransportError,message:"WebSocket connection closed unexpectedly"}});r({data:n}),this.messageHandlers.delete(e)}}attemptReconnect(){var e,r,n,i;this.reconnecting=!0;let a=(e=this.options.baseReconnectDelay)!==null&&e!==void 0?e:upe,s=(r=this.options.maxReconnectDelay)!==null&&r!==void 0?r:lpe,o=(n=this.options.maxReconnectAttempts)!==null&&n!==void 0?n:fpe,d=(i=this.options.connectTimeout)!==null&&i!==void 0?i:u7,u=0,c=()=>g0(this,void 0,void 0,function*(){var l,f,h,p;if(this.closedByUser){this.reconnecting=!1;return}if(u++,u>o){this.reconnecting=!1;return}(f=(l=this.options).onreconnecting)===null||f===void 0||f.call(l,u);let g=Math.min(a*Math.pow(2,u-1),s)*(.5+Math.random()*.5);if(yield new Promise(_=>setTimeout(_,g)),this.closedByUser){this.reconnecting=!1;return}try{let _=yield t.createWebSocket(this.url,d);this.socket=_,this._isConnected=!0,this.reconnecting=!1,this.wireSocket(_),(p=(h=this.options).onreconnected)===null||p===void 0||p.call(h)}catch{yield c()}});c()}};y();y();y();rn();y();rn();var Im=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},w0=class t{get transportProtocols(){return["ws:","wss:"]}sendDwnRequest(e){return Im(this,void 0,void 0,function*(){let r=new URL(e.dwnUrl);if(r.protocol!=="ws:"&&r.protocol!=="wss:")throw new Error(`Invalid websocket protocol ${r.protocol}`);if(!t.connections.has(r.host))try{let d=yield t.createConnection(r);t.connections.set(r.host,d)}catch(d){throw new Error(`Error connecting to ${r.host}: ${d.message}`)}let i=t.connections.get(r.host),{targetDid:a,message:s,subscription:o}=e;return o?t.subscriptionRequest(i,a,s,o.handler,o.resubscribeFactory):t.processMessage(i,a,s)})}static createConnection(e){return Im(this,void 0,void 0,function*(){let r=e.host,n=new Map,i=yield wP.connect(e.toString(),{onclose:()=>{t.connections.delete(r);for(let a of n.values())a.handler({type:"disconnected"})},onreconnecting:a=>{for(let s of n.values())s.handler({type:"reconnecting",attempt:a})},onreconnected:()=>{let a={socket:i,subscriptions:n,url:e.toString()};t.connections.set(r,a),t.resubscribeAll(a)}});return{socket:i,subscriptions:n,url:e.toString()}})}static processMessage(e,r,n){return Im(this,void 0,void 0,function*(){let i=gi.randomUuid(),a=Dm(i,"dwn.processMessage",{target:r,message:n}),{socket:s}=e,o=yield s.request(a),{error:d,result:u}=o;if(d!==void 0)throw new Error(`error sending DWN request: ${d.message}`);return u.reply})}static subscriptionRequest(e,r,n,i,a){return Im(this,void 0,void 0,function*(){let s=gi.randomUuid(),o=gi.randomUuid(),d=yP(s,"rpc.subscribe.dwn.processMessage",{target:r,message:n},o),{socket:u,subscriptions:c}=e,{response:l,close:f}=yield u.subscribe(d,g=>{let{result:_,error:v}=g;if(v){let T=c.get(o);T&&T.subscription.close(),c.delete(o);return}let E=_.subscription;if(i(E),"cursor"in E&&E.cursor){let T=c.get(o);T&&(T.lastCursor=E.cursor),u.send(c7(o,E.cursor))}}),{error:h,result:p}=l;if(h)throw new Error(`could not subscribe via jsonrpc socket: ${h.message}`);let{reply:m}=p;if(m.subscription&&f){let g=()=>Im(this,void 0,void 0,function*(){c.delete(o),yield f()}),_={subscription:Object.assign(Object.assign({},m.subscription),{close:g}),target:r,message:n,handler:i,resubscribeFactory:a};c.set(o,_),m.subscription.close=g}return m})}static resubscribeAll(e){return Im(this,void 0,void 0,function*(){let r=[...e.subscriptions.entries()];e.subscriptions.clear();for(let[,n]of r)try{let i;n.resubscribeFactory?i=yield n.resubscribeFactory(n.lastCursor):i=n.message,yield t.subscriptionRequest(e,n.target,i,n.handler,n.resubscribeFactory),n.handler({type:"reconnected"})}catch{}})}};w0.connections=new Map;var v0=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(s){s(a)})}return new(r||(r=Promise))(function(a,s){function o(c){try{u(n.next(c))}catch(l){s(l)}}function d(c){try{u(n.throw(c))}catch(l){s(l)}}function u(c){c.done?a(c.value):i(c.value).then(o,d)}u((n=n.apply(t,e||[])).next())})},l7;(function(t){t.Create="did.create",t.Resolve="did.resolve"})(l7||(l7={}));var Rm=class{constructor(e=[]){this.transportClients=new Map,e=[new rR,new nR,...e];for(let r of e)for(let n of r.transportProtocols)this.transportClients.set(n,r)}get transportProtocols(){return Array.from(this.transportClients.keys())}sendDidRequest(e){return v0(this,void 0,void 0,function*(){let r=new URL(e.url),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.sendDidRequest(e)})}sendDwnRequest(e){let r=new URL(e.dwnUrl),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.sendDwnRequest(e)}getServerInfo(e){return v0(this,void 0,void 0,function*(){let r=new URL(e),n=this.transportClients.get(r.protocol);if(!n){let i=new Error(`no ${r.protocol} transport client available`);throw i.name="NO_TRANSPORT_CLIENT",i}return n.getServerInfo(e)})}},rR=class extends gP{sendDidRequest(e){return v0(this,void 0,void 0,function*(){let r=gi.randomUuid(),n=Dm(r,e.method,{data:e.data}),i=new Request(e.url,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),a;try{let s=yield fetch(i,{signal:AbortSignal.timeout(3e4)});if(s.ok){if(a=yield s.json(),a.error){let{code:o,message:d}=a.error;throw new Error(`JSON RPC (${o}) - ${d}`)}}else throw new Error(`HTTP (${s.status}) - ${s.statusText}`)}catch(s){throw new Error(`Error encountered while processing response from ${e.url}: ${s.message}`)}return a.result})}},nR=class extends w0{sendDidRequest(e){return v0(this,void 0,void 0,function*(){throw new Error(`not implemented for transports [${this.transportProtocols.join(", ")}]`)})}getServerInfo(e){return v0(this,void 0,void 0,function*(){throw new Error(`not implemented for transports [${this.transportProtocols.join(", ")}]`)})}};y();y();Fo();Kt();rn();Jn();y();Kt();Fo();var vP=class{constructor(e){this.agent=e.agent,this.connectedDid=e.connectedDid}async create(e){let{result:r,...n}=await this.agent.processDidRequest({messageType:y0.Create,messageParams:{...e}});return{did:r,...n}}async resolve(e,r){let{result:n}=await this.agent.processDidRequest({messageParams:{didUri:e,options:r},messageType:y0.Resolve});return n}};y();y();Kt();var b0=class{constructor(e){let{rawMessage:r,initialWrite:n,encodedData:i,data:a,remoteOrigin:s,anonymousDwn:o}=e;this._anonymousDwn=o,this._remoteOrigin=s;try{this._author=Wo(r)??"unknown"}catch{this._author="unknown"}try{this._creator=n?Wo(n)??this._author:this._author}catch{this._creator=this._author}this._descriptor=r.descriptor,this._recordId=r.recordId,this._contextId=r.contextId,this._initialWrite=n,this._authorization=r.authorization,this._attestation=r.attestation,this._encryption=r.encryption,i&&(this._encodedData=new Blob([Ue.base64Url(i).toUint8Array()],{type:this.dataFormat})),a&&(this._readableStream=a)}get id(){return this._recordId}get contextId(){return this._contextId}get dateCreated(){return this._descriptor.dateCreated}get parentId(){return this._descriptor.parentId}get protocol(){return this._descriptor.protocol}get protocolPath(){return this._descriptor.protocolPath}get recipient(){return this._descriptor.recipient}get schema(){return this._descriptor.schema}get dataFormat(){return this._descriptor.dataFormat}get dataCid(){return this._descriptor.dataCid}get dataSize(){return this._descriptor.dataSize}get datePublished(){return this._descriptor.datePublished}get published(){return this._descriptor.published}get tags(){return this._descriptor.tags}get author(){return this._author}get creator(){return this._creator}get timestamp(){return this._descriptor.messageTimestamp}get encryption(){return this._encryption}get authorization(){return this._authorization}get attestation(){return this._attestation}get initialWrite(){return this._initialWrite}get remoteOrigin(){return this._remoteOrigin}get data(){let e=this;return{async blob(){return new Blob([await Co.consumeToBytes({readableStream:await this.stream()})],{type:e.dataFormat})},async bytes(){return await Co.consumeToBytes({readableStream:await this.stream()})},async json(){return await Co.consumeToJson({readableStream:await this.stream()})},async text(){return await Co.consumeToText({readableStream:await this.stream()})},async stream(){if(e._encodedData)return Co.fromBlob(e._encodedData);if(e._readableStream){let n=e._readableStream;return e._readableStream=void 0,n}else return await e.readRecordData()},then(n,i){return this.stream().then(n,i)},catch(n){return this.stream().catch(n)}}}toJSON(){return{attestation:this.attestation,author:this.author,authorization:this.authorization,contextId:this.contextId,dataCid:this.dataCid,dataFormat:this.dataFormat,dataSize:this.dataSize,dateCreated:this.dateCreated,datePublished:this.datePublished,encryption:this.encryption,parentId:this.parentId,protocol:this.protocol,protocolPath:this.protocolPath,published:this.published,recipient:this.recipient,recordId:this.id,schema:this.schema,tags:this.tags,timestamp:this.timestamp}}toString(){let e=`ReadOnlyRecord: {
|
|
2059
2059
|
`;return e+=` ID: ${this.id}
|
|
2060
2060
|
`,e+=this.contextId?` Context ID: ${this.contextId}
|
|
2061
2061
|
`:"",e+=this.protocol?` Protocol: ${this.protocol}
|