@libp2p/mdns 12.0.30 → 12.0.31

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/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMdns = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PMdns=(()=>{var ga=Object.create;var Dr=Object.defineProperty;var ma=Object.getOwnPropertyDescriptor;var ya=Object.getOwnPropertyNames;var wa=Object.getPrototypeOf,ba=Object.prototype.hasOwnProperty;var me=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ce=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},ye=(t,e)=>{for(var r in e)Dr(t,r,{get:e[r],enumerable:!0})},Ai=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ya(e))!ba.call(t,o)&&o!==r&&Dr(t,o,{get:()=>e[o],enumerable:!(n=ma(e,o))||n.enumerable});return t};var ir=(t,e,r)=>(r=t!=null?ga(wa(t)):{},Ai(e||!t||!t.__esModule?Dr(r,"default",{value:t,enumerable:!0}):r,t)),xa=t=>Ai(Dr({},"__esModule",{value:!0}),t);var Ui=Ce(On=>{"use strict";On.toString=function(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};On.toType=function(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}});var _i=Ce(Dn=>{"use strict";Dn.toString=function(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};Dn.toRcode=function(t){switch(t.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var Pi=Ce(Un=>{"use strict";Un.toString=function(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};Un.toOpcode=function(t){switch(t.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var Ri=Ce(_n=>{"use strict";_n.toString=function(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};_n.toClass=function(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}});var Ni=Ce(Pn=>{"use strict";Pn.toString=function(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}`};Pn.toCode=function(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}});var Ki=Ce((ki,Rn)=>{var Fi=(function(t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode=d,t.encode=l,t.familyOf=u,t.name=void 0,t.sizeOf=c,t.v6=t.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,r=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,o=16,i={name:"v4",size:r,isFormat:f=>e.test(f),encode(f,h,p){p=~~p,h=h||new Uint8Array(p+r);let w=f.length,I=0;for(let x=0;x<w;){let C=f.charCodeAt(x++);C===46?(h[p++]=I,I=0):I=I*10+(C-48)}return h[p]=I,h},decode(f,h){return h=~~h,`${f[h++]}.${f[h++]}.${f[h++]}.${f[h]}`}};t.v4=i;let s={name:"v6",size:o,isFormat:f=>f.length>0&&n.test(f),encode(f,h,p){p=~~p;let w=p+o,I=-1,x=0,C=0,q=!0,F=!1;h=h||new Uint8Array(p+o);for(let H=0;H<f.length;H++){let k=f.charCodeAt(H);k===58?(q?I!==-1?(p<w&&(h[p]=0),p<w-1&&(h[p+1]=0),p+=2):p<w&&(I=p):(F===!0?(p<w&&(h[p]=C),p++):(p<w&&(h[p]=x>>8),p<w-1&&(h[p+1]=x&255),p+=2),x=0,C=0),q=!0,F=!1):k===46?(p<w&&(h[p]=C),p++,C=0,x=0,q=!1,F=!0):(q=!1,k>=97?k-=87:k>=65?k-=55:(k-=48,C=C*10+k),x=(x<<4)+k)}if(q===!1)F===!0?(p<w&&(h[p]=C),p++):(p<w&&(h[p]=x>>8),p<w-1&&(h[p+1]=x&255),p+=2);else if(I===0)p<w&&(h[p]=0),p<w-1&&(h[p+1]=0),p+=2;else if(I!==-1){p+=2;for(let H=Math.min(p-1,w-1);H>=I+2;H--)h[H]=h[H-2];h[I]=0,h[I+1]=0,I=p}if(I!==p&&I!==-1)for(p>w-2&&(p=w-2);w>I;)h[--w]=p<w&&p>I?h[--p]:0;else for(;p<w;)h[p++]=0;return h},decode(f,h){h=~~h;let p="";for(let w=0;w<o;w+=2)w!==0&&(p+=":"),p+=(f[h+w]<<8|f[h+w+1]).toString(16);return p.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};t.v6=s;let a="ip";t.name=a;function c(f){if(i.isFormat(f))return i.size;if(s.isFormat(f))return s.size;throw Error(`Invalid ip address: ${f}`)}function u(f){return c(f)===i.size?1:2}function l(f,h,p){p=~~p;let w=c(f);return typeof h=="function"&&(h=h(p+w)),w===i.size?i.encode(f,h,p):s.encode(f,h,p)}function d(f,h,p){if(h=~~h,p=p||f.length-h,p===i.size)return i.decode(f,h,p);if(p===s.size)return s.decode(f,h,p);throw Error(`Invalid buffer size needs to be ${i.size} for v4 or ${s.size} for v6.`)}return"default"in t?t.default:t})({});typeof define=="function"&&define.amd?define([],function(){return Fi}):typeof Rn=="object"&&typeof ki=="object"&&(Rn.exports=Fi)});var qi=Ce(B=>{"use strict";var A=me("buffer").Buffer,ct=Ui(),va=_i(),Ba=Pi(),Fr=Ri(),Nn=Ni(),Ct=Ki(),Aa=0,Mi=32768,Fn=32768,Ca=~Fn,Hi=32768,La=~Hi,y=B.name={};y.encode=function(t,e,r,{mail:n=!1}={}){e||(e=A.alloc(y.encodingLength(t))),r||(r=0);let o=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let s=[];if(n){let a="";i.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=i.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],r+1);e[r]=c,r+=c+1}}return e[r++]=0,y.encode.bytes=r-o,e};y.encode.bytes=0;y.decode=function(t,e,{mail:r=!1}={}){e||(e=0);let n=[],o=e,i=0,s=0,a=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let c=t[e++];if(s+=a?0:1,c===0)break;if((c&192)===0){if(e+c>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");let u=t.toString("utf-8",e,e+c);r&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}else if((c&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let u=t.readUInt16BE(e-1)-49152;if(u>=o)throw new Error("Cannot decode name (bad pointer)");e=u,o=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)")}return y.decode.bytes=s,n.length===0?".":n.join(".")};y.decode.bytes=0;y.encodingLength=function(t){return t==="."||t===".."?1:A.byteLength(t.replace(/^\.|\.$/gm,""))+2};var U={};U.encode=function(t,e,r){e||(e=A.alloc(U.encodingLength(t))),r||(r=0);let n=e.write(t,r+1);return e[r]=n,U.encode.bytes=n+1,e};U.encode.bytes=0;U.decode=function(t,e){e||(e=0);let r=t[e],n=t.toString("utf-8",e+1,e+1+r);return U.decode.bytes=r+1,n};U.decode.bytes=0;U.encodingLength=function(t){return A.byteLength(t)+1};var De={};De.encode=function(t,e,r){e||(e=De.encodingLength(t)),r||(r=0);let n=(t.flags||0)&32767,o=t.type==="response"?Mi:Aa;return e.writeUInt16BE(t.id||0,r),e.writeUInt16BE(n|o,r+2),e.writeUInt16BE(t.questions.length,r+4),e.writeUInt16BE(t.answers.length,r+6),e.writeUInt16BE(t.authorities.length,r+8),e.writeUInt16BE(t.additionals.length,r+10),e};De.encode.bytes=12;De.decode=function(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=t.readUInt16BE(e+2);return{id:t.readUInt16BE(e),type:r&Mi?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:Ba.toString(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:va.toString(r&15),questions:new Array(t.readUInt16BE(e+4)),answers:new Array(t.readUInt16BE(e+6)),authorities:new Array(t.readUInt16BE(e+8)),additionals:new Array(t.readUInt16BE(e+10))}};De.decode.bytes=12;De.encodingLength=function(){return 12};var Qe=B.unknown={};Qe.encode=function(t,e,r){return e||(e=A.alloc(Qe.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.length,r),t.copy(e,r+2),Qe.encode.bytes=t.length+2,e};Qe.encode.bytes=0;Qe.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=t.slice(e+2,e+2+r);return Qe.decode.bytes=r+2,n};Qe.decode.bytes=0;Qe.encodingLength=function(t){return t.length+2};var Je=B.ns={};Je.encode=function(t,e,r){return e||(e=A.alloc(Je.encodingLength(t))),r||(r=0),y.encode(t,e,r+2),e.writeUInt16BE(y.encode.bytes,r),Je.encode.bytes=y.encode.bytes+2,e};Je.encode.bytes=0;Je.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=y.decode(t,e+2);return Je.decode.bytes=r+2,n};Je.decode.bytes=0;Je.encodingLength=function(t){return y.encodingLength(t)+2};var et=B.soa={};et.encode=function(t,e,r){e||(e=A.alloc(et.encodingLength(t))),r||(r=0);let n=r;return r+=2,y.encode(t.mname,e,r),r+=y.encode.bytes,y.encode(t.rname,e,r,{mail:!0}),r+=y.encode.bytes,e.writeUInt32BE(t.serial||0,r),r+=4,e.writeUInt32BE(t.refresh||0,r),r+=4,e.writeUInt32BE(t.retry||0,r),r+=4,e.writeUInt32BE(t.expire||0,r),r+=4,e.writeUInt32BE(t.minimum||0,r),r+=4,e.writeUInt16BE(r-n-2,n),et.encode.bytes=r-n,e};et.encode.bytes=0;et.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=y.decode(t,e),e+=y.decode.bytes,n.rname=y.decode(t,e,{mail:!0}),e+=y.decode.bytes,n.serial=t.readUInt32BE(e),e+=4,n.refresh=t.readUInt32BE(e),e+=4,n.retry=t.readUInt32BE(e),e+=4,n.expire=t.readUInt32BE(e),e+=4,n.minimum=t.readUInt32BE(e),e+=4,et.decode.bytes=e-r,n};et.decode.bytes=0;et.encodingLength=function(t){return 22+y.encodingLength(t.mname)+y.encodingLength(t.rname)};var tt=B.txt={};tt.encode=function(t,e,r){Array.isArray(t)||(t=[t]);for(let o=0;o<t.length;o++)if(typeof t[o]=="string"&&(t[o]=A.from(t[o])),!A.isBuffer(t[o]))throw new Error("Must be a Buffer");e||(e=A.alloc(tt.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(o){e[r++]=o.length,o.copy(e,r,0,o.length),r+=o.length}),e.writeUInt16BE(r-n-2,n),tt.encode.bytes=r-n,e};tt.encode.bytes=0;tt.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let o=[];for(;n>0;){let i=t[e++];if(--n,n<i)throw new Error("Buffer overflow");o.push(t.slice(e,e+i)),e+=i,n-=i}return tt.decode.bytes=e-r,o};tt.decode.bytes=0;tt.encodingLength=function(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=A.byteLength(r)+1:e+=r.length+1}),e};var rt=B.null={};rt.encode=function(t,e,r){e||(e=A.alloc(rt.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=A.from(t)),t||(t=A.alloc(0));let n=r;r+=2;let o=t.length;return t.copy(e,r,0,o),r+=o,e.writeUInt16BE(r-n-2,n),rt.encode.bytes=r-n,e};rt.encode.bytes=0;rt.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let o=t.slice(e,e+n);return e+=n,rt.decode.bytes=e-r,o};rt.decode.bytes=0;rt.encodingLength=function(t){return t?(A.isBuffer(t)?t.length:A.byteLength(t))+2:2};var nt=B.hinfo={};nt.encode=function(t,e,r){e||(e=A.alloc(nt.encodingLength(t))),r||(r=0);let n=r;return r+=2,U.encode(t.cpu,e,r),r+=U.encode.bytes,U.encode(t.os,e,r),r+=U.encode.bytes,e.writeUInt16BE(r-n-2,n),nt.encode.bytes=r-n,e};nt.encode.bytes=0;nt.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=U.decode(t,e),e+=U.decode.bytes,n.os=U.decode(t,e),e+=U.decode.bytes,nt.decode.bytes=e-r,n};nt.decode.bytes=0;nt.encodingLength=function(t){return U.encodingLength(t.cpu)+U.encodingLength(t.os)+2};var Te=B.ptr={},Ta=B.cname=Te,Oa=B.dname=Te;Te.encode=function(t,e,r){return e||(e=A.alloc(Te.encodingLength(t))),r||(r=0),y.encode(t,e,r+2),e.writeUInt16BE(y.encode.bytes,r),Te.encode.bytes=y.encode.bytes+2,e};Te.encode.bytes=0;Te.decode=function(t,e){e||(e=0);let r=y.decode(t,e+2);return Te.decode.bytes=y.decode.bytes+2,r};Te.decode.bytes=0;Te.encodingLength=function(t){return y.encodingLength(t)+2};var ot=B.srv={};ot.encode=function(t,e,r){e||(e=A.alloc(ot.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.priority||0,r+2),e.writeUInt16BE(t.weight||0,r+4),e.writeUInt16BE(t.port||0,r+6),y.encode(t.target,e,r+8);let n=y.encode.bytes+6;return e.writeUInt16BE(n,r),ot.encode.bytes=n+2,e};ot.encode.bytes=0;ot.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n={};return n.priority=t.readUInt16BE(e+2),n.weight=t.readUInt16BE(e+4),n.port=t.readUInt16BE(e+6),n.target=y.decode(t,e+8),ot.decode.bytes=r+2,n};ot.decode.bytes=0;ot.encodingLength=function(t){return 8+y.encodingLength(t.target)};var we=B.caa={};we.ISSUER_CRITICAL=128;we.encode=function(t,e,r){let n=we.encodingLength(t);return e||(e=A.alloc(we.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=we.ISSUER_CRITICAL),e.writeUInt16BE(n-2,r),r+=2,e.writeUInt8(t.flags||0,r),r+=1,U.encode(t.tag,e,r),r+=U.encode.bytes,e.write(t.value,r),r+=A.byteLength(t.value),we.encode.bytes=n,e};we.encode.bytes=0;we.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e);e+=2;let n=e,o={};return o.flags=t.readUInt8(e),e+=1,o.tag=U.decode(t,e),e+=U.decode.bytes,o.value=t.toString("utf-8",e,n+r),o.issuerCritical=!!(o.flags&we.ISSUER_CRITICAL),we.decode.bytes=r+2,o};we.decode.bytes=0;we.encodingLength=function(t){return U.encodingLength(t.tag)+U.encodingLength(t.value)+2};var gt=B.mx={};gt.encode=function(t,e,r){e||(e=A.alloc(gt.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,y.encode(t.exchange,e,r),r+=y.encode.bytes,e.writeUInt16BE(r-n-2,n),gt.encode.bytes=r-n,e};gt.encode.bytes=0;gt.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=t.readUInt16BE(e),e+=2,n.exchange=y.decode(t,e),e+=y.decode.bytes,gt.decode.bytes=e-r,n};gt.encodingLength=function(t){return 4+y.encodingLength(t.exchange)};var it=B.a={};it.encode=function(t,e,r){return e||(e=A.alloc(it.encodingLength(t))),r||(r=0),e.writeUInt16BE(4,r),r+=2,Ct.v4.encode(t,e,r),it.encode.bytes=6,e};it.encode.bytes=0;it.decode=function(t,e){e||(e=0),e+=2;let r=Ct.v4.decode(t,e);return it.decode.bytes=6,r};it.decode.bytes=0;it.encodingLength=function(){return 6};var st=B.aaaa={};st.encode=function(t,e,r){return e||(e=A.alloc(st.encodingLength(t))),r||(r=0),e.writeUInt16BE(16,r),r+=2,Ct.v6.encode(t,e,r),st.encode.bytes=18,e};st.encode.bytes=0;st.decode=function(t,e){e||(e=0),e+=2;let r=Ct.v6.decode(t,e);return st.decode.bytes=18,r};st.decode.bytes=0;st.encodingLength=function(){return 18};var pe=B.option={};pe.encode=function(t,e,r){e||(e=A.alloc(pe.encodingLength(t))),r||(r=0);let n=r,o=Nn.toCode(t.code);if(e.writeUInt16BE(o,r),r+=2,t.data)e.writeUInt16BE(t.data.length,r),r+=2,t.data.copy(e,r),r+=t.data.length;else switch(o){case 8:let i=t.sourcePrefixLength||0,s=t.family||Ct.familyOf(t.ip),a=Ct.encode(t.ip,A.alloc),c=Math.ceil(i/8);e.writeUInt16BE(c+4,r),r+=2,e.writeUInt16BE(s,r),r+=2,e.writeUInt8(i,r++),e.writeUInt8(t.scopePrefixLength||0,r++),a.copy(e,r,0,c),r+=c;break;case 11:t.timeout?(e.writeUInt16BE(2,r),r+=2,e.writeUInt16BE(t.timeout,r),r+=2):(e.writeUInt16BE(0,r),r+=2);break;case 12:let u=t.length||0;e.writeUInt16BE(u,r),r+=2,e.fill(0,r,r+u),r+=u;break;case 14:let l=t.tags.length*2;e.writeUInt16BE(l,r),r+=2;for(let d of t.tags)e.writeUInt16BE(d,r),r+=2;break;default:throw new Error(`Unknown roption code: ${t.code}`)}return pe.encode.bytes=r-n,e};pe.encode.bytes=0;pe.decode=function(t,e){e||(e=0);let r={};r.code=t.readUInt16BE(e),r.type=Nn.toString(r.code),e+=2;let n=t.readUInt16BE(e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=t.readUInt16BE(e),e+=2,r.sourcePrefixLength=t.readUInt8(e++),r.scopePrefixLength=t.readUInt8(e++);let o=A.alloc(r.family===1?4:16);t.copy(o,0,e,e+n-4),r.ip=Ct.decode(o);break;case 11:n>0&&(r.timeout=t.readUInt16BE(e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(t.readUInt16BE(e)),e+=2}return pe.decode.bytes=n+4,r};pe.decode.bytes=0;pe.encodingLength=function(t){if(t.data)return t.data.length+4;switch(Nn.toCode(t.code)){case 8:let r=t.sourcePrefixLength||0;return Math.ceil(r/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}`)};var xe=B.opt={};xe.encode=function(t,e,r){e||(e=A.alloc(xe.encodingLength(t))),r||(r=0);let n=r,o=Nt(t,pe);return e.writeUInt16BE(o,r),r=cr(t,pe,e,r+2),xe.encode.bytes=r-n,e};xe.encode.bytes=0;xe.decode=function(t,e){e||(e=0);let r=e,n=[],o=t.readUInt16BE(e);e+=2;let i=0;for(;o>0;)n[i++]=pe.decode(t,e),e+=pe.decode.bytes,o-=pe.decode.bytes;return xe.decode.bytes=e-r,n};xe.decode.bytes=0;xe.encodingLength=function(t){return 2+Nt(t||[],pe)};var ae=B.dnskey={};ae.PROTOCOL_DNSSEC=3;ae.ZONE_KEY=128;ae.SECURE_ENTRYPOINT=32768;ae.encode=function(t,e,r){e||(e=A.alloc(ae.encodingLength(t))),r||(r=0);let n=r,o=t.key;if(!A.isBuffer(o))throw new Error("Key must be a Buffer");return r+=2,e.writeUInt16BE(t.flags,r),r+=2,e.writeUInt8(ae.PROTOCOL_DNSSEC,r),r+=1,e.writeUInt8(t.algorithm,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,ae.encode.bytes=r-n,e.writeUInt16BE(ae.encode.bytes-2,n),e};ae.encode.bytes=0;ae.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);if(e+=2,n.flags=t.readUInt16BE(e),e+=2,t.readUInt8(e)!==ae.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t.readUInt8(e),e+=1,n.key=t.slice(e,r+o+2),e+=n.key.length,ae.decode.bytes=e-r,n};ae.decode.bytes=0;ae.encodingLength=function(t){return 6+A.byteLength(t.key)};var ke=B.rrsig={};ke.encode=function(t,e,r){e||(e=A.alloc(ke.encodingLength(t))),r||(r=0);let n=r,o=t.signature;if(!A.isBuffer(o))throw new Error("Signature must be a Buffer");return r+=2,e.writeUInt16BE(ct.toType(t.typeCovered),r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.labels,r),r+=1,e.writeUInt32BE(t.originalTTL,r),r+=4,e.writeUInt32BE(t.expiration,r),r+=4,e.writeUInt32BE(t.inception,r),r+=4,e.writeUInt16BE(t.keyTag,r),r+=2,y.encode(t.signersName,e,r),r+=y.encode.bytes,o.copy(e,r,0,o.length),r+=o.length,ke.encode.bytes=r-n,e.writeUInt16BE(ke.encode.bytes-2,n),e};ke.encode.bytes=0;ke.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.typeCovered=ct.toString(t.readUInt16BE(e)),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.labels=t.readUInt8(e),e+=1,n.originalTTL=t.readUInt32BE(e),e+=4,n.expiration=t.readUInt32BE(e),e+=4,n.inception=t.readUInt32BE(e),e+=4,n.keyTag=t.readUInt16BE(e),e+=2,n.signersName=y.decode(t,e),e+=y.decode.bytes,n.signature=t.slice(e,r+o+2),e+=n.signature.length,ke.decode.bytes=e-r,n};ke.decode.bytes=0;ke.encodingLength=function(t){return 20+y.encodingLength(t.signersName)+A.byteLength(t.signature)};var Ke=B.rp={};Ke.encode=function(t,e,r){e||(e=A.alloc(Ke.encodingLength(t))),r||(r=0);let n=r;return r+=2,y.encode(t.mbox||".",e,r,{mail:!0}),r+=y.encode.bytes,y.encode(t.txt||".",e,r),r+=y.encode.bytes,Ke.encode.bytes=r-n,e.writeUInt16BE(Ke.encode.bytes-2,n),e};Ke.encode.bytes=0;Ke.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=y.decode(t,e,{mail:!0})||".",e+=y.decode.bytes,n.txt=y.decode(t,e)||".",e+=y.decode.bytes,Ke.decode.bytes=e-r,n};Ke.decode.bytes=0;Ke.encodingLength=function(t){return 2+y.encodingLength(t.mbox||".")+y.encodingLength(t.txt||".")};var J={};J.encode=function(t,e,r){e||(e=A.alloc(J.encodingLength(t))),r||(r=0);let n=r;for(var o=[],i=0;i<t.length;i++){var s=ct.toType(t[i]);o[s>>8]===void 0&&(o[s>>8]=[]),o[s>>8][s>>3&31]|=1<<7-(s&7)}for(i=0;i<o.length;i++)if(o[i]!==void 0){var a=A.from(o[i]);e.writeUInt8(i,r),r+=1,e.writeUInt8(a.length,r),r+=1,a.copy(e,r),r+=a.length}return J.encode.bytes=r-n,e};J.encode.bytes=0;J.decode=function(t,e,r){e||(e=0);let n=e;for(var o=[];e-n<r;){var i=t.readUInt8(e);e+=1;var s=t.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=t.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=ct.toString(i<<8|a<<3|u);o.push(l)}e+=s}return J.decode.bytes=e-n,o};J.decode.bytes=0;J.encodingLength=function(t){for(var e=[],r=0;r<t.length;r++){var n=ct.toType(t[r]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var o=0;for(r=0;r<e.length;r++)e[r]!==void 0&&(o+=2+Math.ceil((e[r]+1)/8));return o};var Me=B.nsec={};Me.encode=function(t,e,r){e||(e=A.alloc(Me.encodingLength(t))),r||(r=0);let n=r;return r+=2,y.encode(t.nextDomain,e,r),r+=y.encode.bytes,J.encode(t.rrtypes,e,r),r+=J.encode.bytes,Me.encode.bytes=r-n,e.writeUInt16BE(Me.encode.bytes-2,n),e};Me.encode.bytes=0;Me.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.nextDomain=y.decode(t,e),e+=y.decode.bytes,n.rrtypes=J.decode(t,e,o-(e-r)),e+=J.decode.bytes,Me.decode.bytes=e-r,n};Me.decode.bytes=0;Me.encodingLength=function(t){return 2+y.encodingLength(t.nextDomain)+J.encodingLength(t.rrtypes)};var He=B.nsec3={};He.encode=function(t,e,r){e||(e=A.alloc(He.encodingLength(t))),r||(r=0);let n=r,o=t.salt;if(!A.isBuffer(o))throw new Error("salt must be a Buffer");let i=t.nextDomain;if(!A.isBuffer(i))throw new Error("nextDomain must be a Buffer");return r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.flags,r),r+=1,e.writeUInt16BE(t.iterations,r),r+=2,e.writeUInt8(o.length,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,e.writeUInt8(i.length,r),r+=1,i.copy(e,r,0,i.length),r+=i.length,J.encode(t.rrtypes,e,r),r+=J.encode.bytes,He.encode.bytes=r-n,e.writeUInt16BE(He.encode.bytes-2,n),e};He.encode.bytes=0;He.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);e+=2,n.algorithm=t.readUInt8(e),e+=1,n.flags=t.readUInt8(e),e+=1,n.iterations=t.readUInt16BE(e),e+=2;let i=t.readUInt8(e);e+=1,n.salt=t.slice(e,e+i),e+=i;let s=t.readUInt8(e);return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=J.decode(t,e,o-(e-r)),e+=J.decode.bytes,He.decode.bytes=e-r,n};He.decode.bytes=0;He.encodingLength=function(t){return 8+t.salt.length+t.nextDomain.length+J.encodingLength(t.rrtypes)};var qe=B.ds={};qe.encode=function(t,e,r){e||(e=A.alloc(qe.encodingLength(t))),r||(r=0);let n=r,o=t.digest;if(!A.isBuffer(o))throw new Error("Digest must be a Buffer");return r+=2,e.writeUInt16BE(t.keyTag,r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.digestType,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,qe.encode.bytes=r-n,e.writeUInt16BE(qe.encode.bytes-2,n),e};qe.encode.bytes=0;qe.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.keyTag=t.readUInt16BE(e),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.digestType=t.readUInt8(e),e+=1,n.digest=t.slice(e,r+o+2),e+=n.digest.length,qe.decode.bytes=e-r,n};qe.decode.bytes=0;qe.encodingLength=function(t){return 6+A.byteLength(t.digest)};var be=B.sshfp={};be.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};be.encode=function(e,r,n){r||(r=A.alloc(be.encodingLength(e))),n||(n=0);let o=n;n+=2,r[n]=e.algorithm,n+=1,r[n]=e.hash,n+=1;let i=A.from(e.fingerprint.toUpperCase(),"hex");if(i.length!==be.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return i.copy(r,n),n+=i.byteLength,be.encode.bytes=n-o,r.writeUInt16BE(be.encode.bytes-2,o),r};be.encode.bytes=0;be.decode=function(e,r){r||(r=0);let n=r,o={};r+=2,o.algorithm=e[r],r+=1,o.hash=e[r],r+=1;let i=be.getFingerprintLengthForHashType(o.hash);return o.fingerprint=e.slice(r,r+i).toString("hex").toUpperCase(),r+=i,be.decode.bytes=r-n,o};be.decode.bytes=0;be.encodingLength=function(t){return 4+A.from(t.fingerprint,"hex").byteLength};var ze=B.naptr={};ze.encode=function(t,e,r){e||(e=A.alloc(ze.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.order||0,r),r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,U.encode(t.flags,e,r),r+=U.encode.bytes,U.encode(t.services,e,r),r+=U.encode.bytes,U.encode(t.regexp,e,r),r+=U.encode.bytes,y.encode(t.replacement,e,r),r+=y.encode.bytes,ze.encode.bytes=r-n,e.writeUInt16BE(ze.encode.bytes-2,n),e};ze.encode.bytes=0;ze.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.order=t.readUInt16BE(e),e+=2,n.preference=t.readUInt16BE(e),e+=2,n.flags=U.decode(t,e),e+=U.decode.bytes,n.services=U.decode(t,e),e+=U.decode.bytes,n.regexp=U.decode(t,e),e+=U.decode.bytes,n.replacement=y.decode(t,e),e+=y.decode.bytes,ze.decode.bytes=e-r,n};ze.decode.bytes=0;ze.encodingLength=function(t){return U.encodingLength(t.flags)+U.encodingLength(t.services)+U.encodingLength(t.regexp)+y.encodingLength(t.replacement)+6};var $e=B.tlsa={};$e.encode=function(t,e,r){e||(e=A.alloc($e.encodingLength(t))),r||(r=0);let n=r,o=t.certificate;if(!A.isBuffer(o))throw new Error("Certificate must be a Buffer");return r+=2,e.writeUInt8(t.usage,r),r+=1,e.writeUInt8(t.selector,r),r+=1,e.writeUInt8(t.matchingType,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,$e.encode.bytes=r-n,e.writeUInt16BE($e.encode.bytes-2,n),e};$e.encode.bytes=0;$e.decode=function(t,e){e||(e=0);let r=e,n={},o=t.readUInt16BE(e);return e+=2,n.usage=t.readUInt8(e),e+=1,n.selector=t.readUInt8(e),e+=1,n.matchingType=t.readUInt8(e),e+=1,n.certificate=t.slice(e,r+o+2),e+=n.certificate.length,$e.decode.bytes=e-r,n};$e.decode.bytes=0;$e.encodingLength=function(t){return 5+A.byteLength(t.certificate)};var kn=B.record=function(t){switch(t.toUpperCase()){case"A":return it;case"PTR":return Te;case"CNAME":return Ta;case"DNAME":return Oa;case"TXT":return tt;case"NULL":return rt;case"AAAA":return st;case"SRV":return ot;case"HINFO":return nt;case"CAA":return we;case"NS":return Je;case"SOA":return et;case"MX":return gt;case"OPT":return xe;case"DNSKEY":return ae;case"RRSIG":return ke;case"RP":return Ke;case"NSEC":return Me;case"NSEC3":return He;case"SSHFP":return be;case"DS":return qe;case"NAPTR":return ze;case"TLSA":return $e}return Qe},te=B.answer={};te.encode=function(t,e,r){e||(e=A.alloc(te.encodingLength(t))),r||(r=0);let n=r;if(y.encode(t.name,e,r),r+=y.encode.bytes,e.writeUInt16BE(ct.toType(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(t.udpPayloadSize||4096,r+2),e.writeUInt8(t.extendedRcode||0,r+4),e.writeUInt8(t.ednsVersion||0,r+5),e.writeUInt16BE(t.flags||0,r+6),r+=8,xe.encode(t.options||[],e,r),r+=xe.encode.bytes}else{let o=Fr.toClass(t.class===void 0?"IN":t.class);t.flush&&(o|=Fn),e.writeUInt16BE(o,r+2),e.writeUInt32BE(t.ttl||0,r+4),r+=8;let i=kn(t.type);i.encode(t.data,e,r),r+=i.encode.bytes}return te.encode.bytes=r-n,e};te.encode.bytes=0;te.decode=function(t,e){e||(e=0);let r={},n=e;if(r.name=y.decode(t,e),e+=y.decode.bytes,r.type=ct.toString(t.readUInt16BE(e)),r.type==="OPT")r.udpPayloadSize=t.readUInt16BE(e+2),r.extendedRcode=t.readUInt8(e+4),r.ednsVersion=t.readUInt8(e+5),r.flags=t.readUInt16BE(e+6),r.flag_do=(r.flags>>15&1)===1,r.options=xe.decode(t,e+8),e+=8+xe.decode.bytes;else{let o=t.readUInt16BE(e+2);r.ttl=t.readUInt32BE(e+4),r.class=Fr.toString(o&Ca),r.flush=!!(o&Fn);let i=kn(r.type);r.data=i.decode(t,e+8),e+=8+i.decode.bytes}return te.decode.bytes=e-n,r};te.decode.bytes=0;te.encodingLength=function(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return y.encodingLength(t.name)+8+kn(t.type).encodingLength(e)};var Oe=B.question={};Oe.encode=function(t,e,r){e||(e=A.alloc(Oe.encodingLength(t))),r||(r=0);let n=r;return y.encode(t.name,e,r),r+=y.encode.bytes,e.writeUInt16BE(ct.toType(t.type),r),r+=2,e.writeUInt16BE(Fr.toClass(t.class===void 0?"IN":t.class),r),r+=2,Oe.encode.bytes=r-n,t};Oe.encode.bytes=0;Oe.decode=function(t,e){e||(e=0);let r=e,n={};return n.name=y.decode(t,e),e+=y.decode.bytes,n.type=ct.toString(t.readUInt16BE(e)),e+=2,n.class=Fr.toString(t.readUInt16BE(e)),e+=2,n.class&Hi&&(n.class&=La),Oe.decode.bytes=e-r,n};Oe.decode.bytes=0;Oe.encodingLength=function(t){return y.encodingLength(t.name)+4};B.AUTHORITATIVE_ANSWER=1024;B.TRUNCATED_RESPONSE=512;B.RECURSION_DESIRED=256;B.RECURSION_AVAILABLE=128;B.AUTHENTIC_DATA=32;B.CHECKING_DISABLED=16;B.DNSSEC_OK=32768;B.encode=function(t,e,r){let n=!e;n&&(e=A.alloc(B.encodingLength(t))),r||(r=0);let o=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),De.encode(t,e,r),r+=De.encode.bytes,r=cr(t.questions,Oe,e,r),r=cr(t.answers,te,e,r),r=cr(t.authorities,te,e,r),r=cr(t.additionals,te,e,r),B.encode.bytes=r-o,n&&B.encode.bytes!==e.length?e.slice(0,B.encode.bytes):e};B.encode.bytes=0;B.decode=function(t,e){e||(e=0);let r=e,n=De.decode(t,e);return e+=De.decode.bytes,e=Nr(n.questions,Oe,t,e),e=Nr(n.answers,te,t,e),e=Nr(n.authorities,te,t,e),e=Nr(n.additionals,te,t,e),B.decode.bytes=e-r,n};B.decode.bytes=0;B.encodingLength=function(t){return De.encodingLength(t)+Nt(t.questions||[],Oe)+Nt(t.answers||[],te)+Nt(t.authorities||[],te)+Nt(t.additionals||[],te)};B.streamEncode=function(t){let e=B.encode(t),r=A.alloc(2);r.writeUInt16BE(e.byteLength);let n=A.concat([r,e]);return B.streamEncode.bytes=n.byteLength,n};B.streamEncode.bytes=0;B.streamDecode=function(t){let e=t.readUInt16BE(0);if(t.byteLength<e+2)return null;let r=B.decode(t.slice(2));return B.streamDecode.bytes=B.decode.bytes,r};B.streamDecode.bytes=0;function Nt(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function cr(t,e,r,n){for(let o=0;o<t.length;o++)e.encode(t[o],r,n),n+=e.encode.bytes;return n}function Nr(t,e,r,n){for(let o=0;o<t.length;o++)t[o]=e.decode(r,n),n+=e.decode.bytes;return n}});var Vi=Ce((ap,$i)=>{"use strict";var zi=Na;process.nextTick(Ra,42);$i.exports=Da;function Da(t){var e=n;return r;function r(o){e(o||_a)}function n(o){var i=[o];e=s,t(a);function s(c){i.push(c)}function a(c){var u=arguments;for(e=Ua(c)?n:l;i.length;)l(i.shift());function l(d){zi(Pa,d,u)}}}}function Ua(t){return Object.prototype.toString.call(t)==="[object Error]"}function _a(){}function Pa(t,e){t.apply(null,e)}function Ra(t){t===42&&(zi=process.nextTick)}function Na(t,e,r){process.nextTick(function(){t(e,r)})}});var Gi=Ce((up,Yi)=>{var Kn=qi(),Fa=me("dgram"),ka=Vi(),Ka=me("events"),Hn=me("os"),Mn=function(){};Yi.exports=function(t){t||(t={});var e=new Ka.EventEmitter,r=typeof t.port=="number"?t.port:5353,n=t.type||"udp4",o=t.ip||t.host||(n==="udp4"?"224.0.0.251":null),i={address:o,port:r},s={},a=!1,c=null;if(n==="udp6"&&(!o||!t.interface))throw new Error("For IPv6 multicast you must specify `ip` and `interface`");var u=t.socket||Fa.createSocket({type:n,reuseAddr:t.reuseAddr!==!1,toString:function(){return n}});u.on("error",function(d){d.code==="EACCES"||d.code==="EADDRINUSE"?e.emit("error",d):e.emit("warning",d)}),u.on("message",function(d,f){try{d=Kn.decode(d)}catch(h){e.emit("warning",h);return}e.emit("packet",d,f),d.type==="query"&&e.emit("query",d,f),d.type==="response"&&e.emit("response",d,f)}),u.on("listening",function(){r||(r=i.port=u.address().port),t.multicast!==!1&&(e.update(),c=setInterval(e.update,5e3),u.setMulticastTTL(t.ttl||255),u.setMulticastLoopback(t.loopback!==!1))});var l=ka(function(d){if(!r||t.bind===!1)return d(null);u.once("error",d),u.bind(r,t.bind||t.interface,function(){u.removeListener("error",d),d(null)})});return l(function(d){if(d)return e.emit("error",d);e.emit("ready")}),e.send=function(d,f,h){if(typeof f=="function")return e.send(d,null,f);h||(h=Mn),f?!f.host&&!f.address&&(f.address=i.address):f=i,l(p);function p(w){if(a)return h();if(w)return h(w);var I=Kn.encode(d);u.send(I,0,I.length,f.port,f.address||f.host,h)}},e.response=e.respond=function(d,f,h){Array.isArray(d)&&(d={answers:d}),d.type="response",d.flags=(d.flags||0)|Kn.AUTHORITATIVE_ANSWER,e.send(d,f,h)},e.query=function(d,f,h,p){if(typeof f=="function")return e.query(d,null,null,f);if(typeof f=="object"&&f&&f.port)return e.query(d,null,f,h);if(typeof h=="function")return e.query(d,f,null,h);p||(p=Mn),typeof d=="string"&&(d=[{name:d,type:f||"ANY"}]),Array.isArray(d)&&(d={type:"query",questions:d}),d.type="query",e.send(d,h,p)},e.destroy=function(d){if(d||(d=Mn),a)return process.nextTick(d);a=!0,clearInterval(c);for(var f in s)try{u.dropMembership(o,f)}catch{}s={},u.close(d)},e.update=function(){for(var d=t.interface?[].concat(t.interface):Ha(),f=!1,h=0;h<d.length;h++){var p=d[h];if(!s[p])try{u.addMembership(o,p),s[p]=!0,f=!0}catch(w){e.emit("warning",w)}}if(f){if(u.setMulticastInterface)try{u.setMulticastInterface(t.interface||Ma())}catch(w){e.emit("warning",w)}e.emit("networkInterface")}},e};function Ma(){for(var t=Hn.networkInterfaces(),e=Object.keys(t),r=0;r<e.length;r++)for(var n=t[e[r]],o=0;o<n.length;o++){var i=n[o];if(ji(i.family)&&!i.internal)return Hn.platform()==="darwin"&&e[r]==="en0"?i.address:"0.0.0.0"}return"127.0.0.1"}function Ha(){for(var t=Hn.networkInterfaces(),e=Object.keys(t),r=[],n=0;n<e.length;n++)for(var o=t[e[n]],i=0;i<o.length;i++){var s=o[i];if(ji(s.family)){r.push(s.address);break}}return r}function ji(t){return t===4||t==="IPv4"}});var hi=Ce(Jt=>{"use strict";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.Netmask4Impl=void 0;Jt.ip2long=Qt;Jt.long2ip=Xe;function Xe(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var hl=48,pl=97,fl=65;function gl(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let i=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-hl)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-pl)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-fl)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===i)throw new Error("empty octet");return[e,o]}function Qt(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=gl(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var li=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Qt(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Qt(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Xe(this.netLong),this.mask=Xe(this.maskLong),this.hostmask=Xe(~this.maskLong),this.first=this.bitmask<=30?Xe(this.netLong+1):this.base,this.last=this.bitmask<=30?Xe(this.netLong+this.size-2):Xe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Xe(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Qt(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Xe(this.netLong+this.size*e),this.mask)}forEach(e){let r=Qt(this.first),n=Qt(this.last),o=0;for(;r<=n;)e(Xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Jt.Netmask4Impl=li});var qc=Ce(er=>{"use strict";Object.defineProperty(er,"__esModule",{value:!0});er.Netmask6Impl=void 0;er.ip6bigint=fi;er.bigint2ip6=_t;var ml=hi(),pi=(1n<<128n)-1n;function fi(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,ml.ip2long)(n),i=t.substring(0,r+1)+"0:0";return Hc(i)&~0xffffffffn|BigInt(o)}return Hc(t)}function Hc(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),i=t.substring(e+2),s=o===""?[]:o.split(":"),a=i===""?[]:i.split(":"),c=8-s.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...s,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let i=r[o];if(i.length===0||i.length>4)throw new Error('Invalid IPv6: bad group "'+i+'"');let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error('Invalid IPv6: bad group "'+i+'"');n=n<<16n|BigInt(s)}return n}function _t(t){if(t<0n||t>pi)throw new Error("Invalid IPv6 address value");let e=[];for(let s=0;s<8;s++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,i=0;for(let s=0;s<8;s++)e[s]===0?o===-1?(o=s,i=1):i++:(i>n&&i>=2&&(r=o,n=i),o=-1,i=0);if(i>n&&i>=2&&(r=o,n=i),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let s=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return s.join(":")+"::"+a.join(":")}else return e.map(s=>s.toString(16)).join(":")}var gi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=pi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=fi(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=_t(this.netBigint),this.mask=_t(this.maskBigint),this.hostmask=_t(~this.maskBigint&pi),this.first=this.base,this.last=_t(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(fi(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(_t(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,i=0;for(;r<=o;)e(_t(r),Number(r),i),i++,r++}toString(){return this.base+"/"+this.bitmask}};er.Netmask6Impl=gi});var zc=Ce(At=>{"use strict";Object.defineProperty(At,"__esModule",{value:!0});At.long2ip=At.ip2long=At.Netmask=void 0;var In=hi();Object.defineProperty(At,"ip2long",{enumerable:!0,get:function(){return In.ip2long}});Object.defineProperty(At,"long2ip",{enumerable:!0,get:function(){return In.long2ip}});var yl=qc(),mi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new yl.Netmask6Impl(e,r):this._impl=new In.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof In.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};At.Netmask=mi});var Sh={};ye(Sh,{mdns:()=>Ih});var Le=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ur=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var _r=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Pr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var sr=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ci=Symbol.for("@libp2p/peer-discovery");var Ln=Symbol.for("@libp2p/peer-id");var Li=me("node:events"),Ti=(t,...e)=>{try{(0,Li.setMaxListeners)(t,...e)}catch{}};function Ea(t){return typeof t?.handleEvent=="function"}function Ia(t){return t===!0||t===!1}function Sa(t){return Ia(t)?t:t?.capture??!1}function Tn(t){let e={capture:Sa(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function Oi(t,e){return Tn(t).capture===Tn(e).capture}var Rr=class extends EventTarget{#e=new Map;constructor(){super(),Ti(1/0,this)}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Tn(n);if(o?.signal?.aborted===!0)return;let i=u=>{o.once&&this.removeEventListener(e,r,o),Ea(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:Oi(u.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&Oi(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Di=Symbol.for("@libp2p/service-capabilities");var la=ir(Gi(),1);var jn={};ye(jn,{base58btc:()=>G,base58flickr:()=>Wa});var dp=new Uint8Array(0);function Xi(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}function ue(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Lt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Lt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Zi(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Wi=4096;function Qi(t){let e=t.length;if(e<=Wi)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Wi));return r}function qa(t){return t?.buffer instanceof ArrayBuffer}function Lt(t){return qa(t)?t:t.slice()}function za(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var l=t.length,d=t.charAt(0),f=Math.log(l)/Math.log(256),h=Math.log(256)/Math.log(l);function p(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var C=0,q=0,F=0,H=x.length;F!==H&&x[F]===0;)F++,C++;for(var k=(H-F)*h+1>>>0,W=new Uint8Array(k);F!==H;){for(var Q=x[F],ge=0,K=k-1;(Q!==0||ge<q)&&K!==-1;K--,ge++)Q+=256*W[K]>>>0,W[K]=Q%l>>>0,Q=Q/l>>>0;if(Q!==0)throw new Error("Non-zero carry");q=ge,F++}for(var ce=k-q;ce!==k&&W[ce]===0;)ce++;for(var _=d.repeat(C);ce<k;++ce)_+=t.charAt(W[ce]);return _}function w(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var C=0;if(x[C]!==" "){for(var q=0,F=0;x[C]===d;)q++,C++;for(var H=(x.length-C)*f+1>>>0,k=new Uint8Array(H);x[C];){var W=n[x.charCodeAt(C)];if(W===255)return;for(var Q=0,ge=H-1;(W!==0||Q<F)&&ge!==-1;ge--,Q++)W+=l*k[ge]>>>0,k[ge]=W%256>>>0,W=W/256>>>0;if(W!==0)throw new Error("Non-zero carry");F=Q,C++}if(x[C]!==" "){for(var K=H-F;K!==H&&k[K]===0;)K++;for(var ce=new Uint8Array(q+(H-K)),_=q;K!==H;)ce[_++]=k[K++];return ce}}}function I(x){var C=w(x);if(C)return C;throw new Error(`Non-${e} character`)}return{encode:p,decodeUnsafe:w,decode:I}}var $a=za,Va=$a,es=Va;var qn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},zn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ts(this,e)}},$n=class{decoders;constructor(e){this.decoders=e}or(e){return ts(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ts(t,e){return new $n({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new qn(e,r,n),this.decoder=new zn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ft({name:t,prefix:e,encode:r,decode:n}){return new Vn(t,e,r,n)}function mt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=es(r,t,n);return Ft({prefix:e,name:t,encode:o,decode:s=>ue(i(s))})}function ja(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ya(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ga(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function V({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=Ga(n,o);return Ft({prefix:e,name:t,encode(s){return Ya(s,n,r)},decode(s){return ja(s,i,r,t)}})}var G=mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wa=mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Yn={};ye(Yn,{base32:()=>yt,base32hex:()=>Ja,base32hexpad:()=>tu,base32hexpadupper:()=>ru,base32hexupper:()=>eu,base32pad:()=>Za,base32padupper:()=>Qa,base32upper:()=>Xa,base32z:()=>nu});var yt=V({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Xa=V({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Za=V({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Qa=V({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ja=V({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),eu=V({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),tu=V({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ru=V({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),nu=V({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gn={};ye(Gn,{base36:()=>ar,base36upper:()=>ou});var ar=mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ou=mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var iu=os,rs=128,su=127,cu=~su,au=Math.pow(2,31);function os(t,e,r){e=e||[],r=r||0;for(var n=r;t>=au;)e[r++]=t&255|rs,t/=128;for(;t&cu;)e[r++]=t&255|rs,t>>>=7;return e[r]=t|0,os.bytes=r-n+1,e}var uu=Wn,du=128,ns=127;function Wn(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Wn.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ns)<<o:(s&ns)*Math.pow(2,o),o+=7}while(s>=du);return Wn.bytes=i-n,r}var lu=Math.pow(2,7),hu=Math.pow(2,14),pu=Math.pow(2,21),fu=Math.pow(2,28),gu=Math.pow(2,35),mu=Math.pow(2,42),yu=Math.pow(2,49),wu=Math.pow(2,56),bu=Math.pow(2,63),xu=function(t){return t<lu?1:t<hu?2:t<pu?3:t<fu?4:t<gu?5:t<mu?6:t<yu?7:t<wu?8:t<bu?9:10},Eu={encode:iu,decode:uu,encodingLength:xu},Iu=Eu,ur=Iu;function dr(t,e=0){let r=ur.decode(t,e),n=ur.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function kt(t,e,r=0){return ur.encode(t,e,r),e}function Kt(t){return ur.encodingLength(t)}function Ht(t,e){let r=e.byteLength,n=Kt(t),o=n+Kt(r),i=new Uint8Array(o+r);return kt(t,i,0),kt(r,i,n),i.set(e,o),new Mt(t,r,e,i)}function lr(t){let e=ue(t),[r,n]=dr(e),[o,i]=dr(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Mt(r,o,s,e)}function is(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Xi(t.bytes,r.bytes)}}var Mt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Lt(n),this.bytes=Lt(o)}};function ss(t,e){let{bytes:r,version:n}=t;return n===0?vu(r,Xn(t),e??G.encoder):Bu(r,Xn(t),e??yt.encoder)}var cs=new WeakMap;function Xn(t){let e=cs.get(t);if(e==null){let r=new Map;return cs.set(t,r),r}return e}var re=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Lt(o),this["/"]=this.bytes}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!==hr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Au)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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=Ht(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&is(e.multihash,n.multihash)}toString(e){return ss(this,e)}toJSON(){return{"/":ss(this)}}link(){return this}[Symbol.toStringTag]="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 t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??as(n,o,i.bytes))}else if(r[Cu]===!0){let{version:n,multihash:o,code:i}=r,s=lr(o);return t.create(n,i,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!==hr)throw new Error(`Version 0 CID must use dag-pb (code: ${hr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=as(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,hr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=ue(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Mt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,f]=dr(e.subarray(r));return r+=f,d},o=n(),i=hr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=Su(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Xn(i).set(n,e),i}};function Su(t,e){switch(t[0]){case"Q":{let r=e??G;return[G.prefix,r.decode(`${G.prefix}${t}`)]}case G.prefix:{let r=e??G;return[G.prefix,r.decode(t)]}case yt.prefix:{let r=e??yt;return[yt.prefix,r.decode(t)]}case ar.prefix:{let r=e??ar;return[ar.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function vu(t,e,r){let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Bu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var hr=112,Au=18;function as(t,e,r){let n=Kt(t),o=n+Kt(e),i=new Uint8Array(o+r.byteLength);return kt(t,i,0),kt(e,i,n),i.set(r,o),i}var Cu=Symbol.for("@ipld/js-cid/CID");var Zn={};ye(Zn,{identity:()=>Ue});var us=0,Lu="identity",ds=ue;function Tu(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ht(us,ds(t))}var Ue={code:us,name:Lu,encode:ds,digest:Tu};function fe(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}function Ou(t){return t.buffer instanceof ArrayBuffer}function wt(t){return Ou(t)?t:t.slice()}async function ls(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,wt(e),wt(r.subarray()));return n?.signal?.throwIfAborted(),i}var Qn=me("node:buffer");function bt(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ve(t=0){return bt(Qn.Buffer.alloc(t))}function Ee(t=0){return bt(Qn.Buffer.allocUnsafe(t))}var hs=me("node:buffer");function _e(t,e){return bt(hs.Buffer.concat(t,e))}var fs=Symbol.for("@achingbrain/uint8arraylist");function ps(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Kr(t){return!!t?.[fs]}var Ie=class t{bufs;length;[fs]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=ps(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ps(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Kr(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return _e(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:_e(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Kr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=c;d+=l){l=0;for(let f=u;f>=0;f--){let h=this.get(d+f);if(n[f]!==h){l=Math.max(1,f-a[h]);break}}if(l===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=Ve(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=Ve(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=Ve(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Ee(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=Ve(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=Ve(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=Ve(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=Ve(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=Ve(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!fe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var xs=me("node:buffer");var Jn={};ye(Jn,{base10:()=>Du});var Du=mt({prefix:"9",name:"base10",alphabet:"0123456789"});var eo={};ye(eo,{base16:()=>Uu,base16upper:()=>_u});var Uu=V({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),_u=V({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var to={};ye(to,{base2:()=>Pu});var Pu=V({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};ye(ro,{base256emoji:()=>Ku});var gs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ru=gs.reduce((t,e,r)=>(t[r]=e,t),[]),Nu=gs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Fu(t){return t.reduce((e,r)=>(e+=Ru[r],e),"")}function ku(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Nu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ku=Ft({prefix:"\u{1F680}",name:"base256emoji",encode:Fu,decode:ku});var oo={};ye(oo,{base64:()=>Mu,base64pad:()=>Hu,base64url:()=>no,base64urlpad:()=>qu});var Mu=V({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hu=V({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=V({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qu=V({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var io={};ye(io,{base8:()=>zu});var zu=V({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};ye(so,{identity:()=>$u});var $u=Ft({prefix:"\0",name:"identity",encode:t=>Qi(ue(t)),decode:t=>ue(Zi(t))});var Wp=new TextEncoder,Xp=new TextDecoder;var ho={};ye(ho,{sha256:()=>lo,sha512:()=>Gu});var uo=ir(me("node:crypto"),1);var Yu=20;function ao({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new co(t,e,r,n,o)}var co=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Yu,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ms(n,this.code,r?.truncate):n.then(o=>ms(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ms(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ht(e,t)}var lo=ao({name:"sha2-256",code:18,encode:t=>ue(uo.default.createHash("sha256").update(t).digest())}),Gu=ao({name:"sha2-512",code:19,encode:t=>ue(uo.default.createHash("sha512").update(t).digest())});var pr={...so,...to,...io,...Jn,...eo,...Yn,...Gn,...jn,...oo,...ro},u0={...ho,...Zn};function bs(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ws=bs("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),po=bs("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ee(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Wu={utf8:ws,"utf-8":ws,hex:pr.base16,latin1:po,ascii:po,binary:po,...pr},Mr=Wu;function de(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?bt(xs.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var Es=me("node:buffer");function j(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Es.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var Xu=parseInt("11111",2),fo=parseInt("10000000",2),Zu=parseInt("01111111",2),Is={0:fr,1:fr,2:Qu,3:td,4:rd,5:ed,6:Ju,16:fr,22:fr,48:fr};function go(t,e={offset:0}){let r=t[e.offset]&Xu;if(e.offset++,Is[r]!=null)return Is[r](t,e);throw new Error("No decoder for tag "+r)}function gr(t,e){let r=0;if((t[e.offset]&fo)===fo){let n=t[e.offset]&Zu,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function fr(t,e){gr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=go(t,e);if(n===null)break;r.push(n)}return r}function Qu(t,e){let r=gr(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Ju(t,e){let r=gr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let d=0;d<c.length;d++)l+=c[d]<<d*7;a+=`.${l}`,c=[]}}return a}function ed(t,e){return e.offset++,null}function td(t,e){let r=gr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function rd(t,e){let r=gr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function nd(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function mo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=nd(t.byteLength);return new Ie(Uint8Array.from([e.byteLength|fo]),e)}function Ss(t){let e=new Ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Ie(Uint8Array.from([2]),mo(e),e)}function vs(t){let e=Uint8Array.from([0]),r=new Ie(e,t);return new Ie(Uint8Array.from([3]),mo(r),r)}function Hr(t,e=48){let r=new Ie;for(let n of t)r.append(n);return new Ie(Uint8Array.from([e]),mo(r),r)}var od=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),id=Uint8Array.from([6,5,43,129,4,0,34]),sd=Uint8Array.from([6,5,43,129,4,0,35]),cd={ext:!0,kty:"EC",crv:"P-256"},ad={ext:!0,kty:"EC",crv:"P-384"},ud={ext:!0,kty:"EC",crv:"P-521"},yo=32,wo=48,bo=66;function Bs(t){let e=go(t);return As(e)}function As(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===yo*2+1)return n=j(e.subarray(r,r+yo),"base64url"),o=j(e.subarray(r+yo),"base64url"),new zt({...cd,key_ops:["verify"],x:n,y:o});if(e.byteLength===wo*2+1)return n=j(e.subarray(r,r+wo),"base64url"),o=j(e.subarray(r+wo),"base64url"),new zt({...ad,key_ops:["verify"],x:n,y:o});if(e.byteLength===bo*2+1)return n=j(e.subarray(r,r+bo),"base64url"),o=j(e.subarray(r+bo),"base64url"),new zt({...ud,key_ops:["verify"],x:n,y:o});throw new Le(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Cs(t){return Hr([Ss(Uint8Array.from([1])),Hr([dd(t.crv)],160),Hr([vs(new Ie(Uint8Array.from([4]),de(t.x??"","base64url"),de(t.y??"","base64url")))],161)]).subarray()}function dd(t){if(t==="P-256")return od;if(t==="P-384")return id;if(t==="P-521")return sd;throw new Le(`Invalid curve ${t}`)}var zt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Cs(this.jwk)),this._raw}toMultihash(){return Ue.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}async verify(e,r,n){return ls(this.jwk,r,e,n)}};var sn=ir(me("crypto"),1);var ld=t=>t/2**32|0,hd=t=>t>>>0;function Ls(t,e,r,n){let o=ld(r),i=hd(r);t.setUint32(e,n?i:o,n),t.setUint32(e+4,n?o:i,n)}function qr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var xo=t=>t?`"${t}" `:"";function at(t,e=""){if(typeof t!="number")throw new TypeError(xo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(xo(e)+"expected integer >= 0, got "+t);return t}function je(t,e,r=""){if(qr(t)&&(e===void 0||t.length===e))return t;e!==void 0&&at(e,"length");let n=qr(t),o=e!==void 0?` of length ${e}`:"",i=n?`length=${t.length}`:`type=${typeof t}`,s=xo(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function zr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(at(t.outputLen),at(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Ts=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)};function Vt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function $r(t,e){je(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function mr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Vr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Pe(t,e){return t<<32-e|t>>>e}var Ds=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",pd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function jr(t){if(je(t),Ds)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=pd[t[r]];return e}function Os(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Eo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ds)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Os(t.charCodeAt(i)),a=Os(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Us(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];je(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function fd(t,e,r="opts"){return Ts(t,"defaults"),e!==void 0&&Ts(e,r),Object.assign(t,e)}function _s(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=fd({},e,"info");let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ps(t=32){at(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Rs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ns(t,e,r){return t&e^~t&r}function Fs(t,e,r){return t&e^t&r^e&r}var Yr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Vr(this.buffer)}update(e){Vt(this),je(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let u=Vr(e);for(;o<=i-a;a+=o)this.process(u,a);s=!0;continue}n.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){Vt(this),$r(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),Ls(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=e===r?n:Vr(e),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,s&&e.buffer.set(r),e}clone(){return this._cloneInto()}},ks=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var gd=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),xt=new Uint32Array(64),Io=class extends Yr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let d=0;d<16;d++,r+=4)xt[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let f=xt[d-15],h=xt[d-2],p=Pe(f,7)^Pe(f,18)^f>>>3,w=Pe(h,17)^Pe(h,19)^h>>>10;xt[d]=w+xt[d-7]+p+xt[d-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let f=Pe(a,6)^Pe(a,11)^Pe(a,25),h=l+f+Ns(a,c,u)+gd[d]+xt[d]|0,w=(Pe(n,2)^Pe(n,13)^Pe(n,22))+Fs(n,o,i)|0;l=u,u=c,c=a,a=s+h|0,s=i,i=o,o=n,n=h+w|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,i,s,a,c,u,l)}roundClean(){mr(xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),mr(this.buffer)}},So=class extends Io{constructor(){super(32,ks)}};var Ks=_s(()=>new So,Rs(1));function Wr(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var X=(t,e,r)=>je(t,e,r),vo=at;function Hs(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function Et(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Tt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Bo=jr,ut=(...t)=>Us(...t),Xr=t=>Eo(t),jt=qr,Zr=t=>Ps(t),Gr=BigInt(0),Ms=BigInt(1),md=t=>t?`"${t}" `:"";function Ye(t,e=""){if(typeof t!="boolean")throw new TypeError(md(e)+"expected boolean, got type="+typeof t);return t}function Qr(t){if(typeof t=="bigint"){if(!It(t))throw new RangeError("positive bigint expected, got "+t)}else vo(t);return t}function Yt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function yr(t){let e=Qr(t).toString(16);return e.length&1?"0"+e:e}function qs(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Gr:BigInt("0x"+t)}function Ge(t){return qs(jr(t))}function Ao(t){return qs(jr(yd(je(t)).reverse()))}function Jr(t,e){if(at(e),e===0)throw new Error("zero output length is invalid");t=Qr(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Eo(n.padStart(r,"0"))}function Co(t,e){return Jr(t,e).reverse()}function yd(t){return Uint8Array.from(X(t))}function It(t){return typeof t=="bigint"&&Gr<=t}function Lo(t,e,r){return It(t)&&It(e)&&It(r)&&e<=t&&t<r}function To(t,e,r,n){if(!Lo(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Gt(t){if(t<Gr)throw new Error("expected non-negative bigint, got "+t);return t===Gr?0:t.toString(2).length}var wr=t=>(Yt(t,"n"),(Ms<<BigInt(t))-Ms);function zs(t,e,r){if(at(t,"hashLen"),at(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=I=>new Uint8Array(I),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),l=0,d=()=>{c.fill(1),u.fill(0),l=0},f=(...I)=>r(u,ut(c,...I)),h=(I=o)=>{u=f(i,I),c=f(),I.length!==0&&(u=f(s,I),c=f())},p=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let I=0,x=[];for(;I<e;){c=f();let C=c.slice();x.push(C),I+=c.length}return ut(...x)};return(I,x)=>{d(),h(I);let C;for(;(C=x(p()))===void 0;)h();return d(),C}}function St(t,e={},r={},n="object"){Et(t,n),Et(e,"fields"),Et(r,"optFields");function o(s,a,c){let u=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,l=t[s];if(!Object.hasOwn(t,s)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let d=typeof l;if(d!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let i=(s,a)=>Object.entries(s).forEach(([c,u])=>o(c,u,a));i(e,!1),i(r,!0)}var Z=BigInt(0),N=BigInt(1),vt=BigInt(2),Ys=BigInt(3),Oo=BigInt(4),Gs=BigInt(5),wd=BigInt(7),Ws=BigInt(8),bd=BigInt(9),xd=BigInt(15),Xs=BigInt(16),Ed=BigInt("0x10000000000000000");function Se(t,e){if(e<=Z)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Z?r:e+r}function Zs(t,e,r){if(r<=N)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Z)throw new Error("invalid exponent, negatives unsupported");if(e===Z)return N;if(e===N)return t;let n=t%r;if(n<Z&&(n+=r),e<Ed){let a=N;for(;e>Z;)e&N&&(a=a*n%r),n=n*n%r,e>>=N;return a}let o=[];for(;e>Z;)o.push(Number(e&xd)),e>>=Oo;let i=new Array(16);i[0]=N,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function ve(t,e,r){if(r<=N)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Z)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Z;)n*=n,n%=r;return n}function $s(t,e){if(t===Z)throw new Error("invert: expected non-zero number");if(e<=N)throw new Error("invert: expected modulus > 1, got "+e);let r=Se(t,e),n=e,o=Z,i=N;for(;r!==Z;){let a=n/r,c=n-r*a,u=o-i*a;n=r,r=c,o=i,i=u}if(n!==N)throw new Error("invert: does not exist");return Se(o,e)}function Qs(t,e){if(e<=N)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Se(t,e);if(r===Z)throw new Error("invertCt: expected non-zero number");let n=Zs(r,e-vt,e);if(Se(r*n,e)!==N)throw new Error("invertCt: does not exist");return n}function Do(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Uo(t,e){if((t&N)===Z)throw new Error(e+": expected odd modulus, got "+t)}function Js(t,e){let r=t,n=(r.ORDER+N)/Oo,o=r.pow(e,n);return Do(r,o,e),o}function Id(t,e){let r=t,n=(r.ORDER-Gs)/Ws,o=r.mul(e,vt),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,vt),i),c=r.mul(s,r.sub(a,r.ONE));return Do(r,c,e),c}function Sd(t){let e=Xt(t),r=ec(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+wd)/Xs;return((a,c)=>{let u=a,l=u.pow(c,s),d=u.mul(l,n),f=u.mul(l,o),h=u.mul(l,i),p=u.eql(u.sqr(d),c),w=u.eql(u.sqr(f),c);l=u.cmov(l,d,p),d=u.cmov(h,f,w);let I=u.eql(u.sqr(d),c),x=u.cmov(l,d,I);return Do(u,x,c),x})}function ec(t){if(t<Ys)throw new Error("sqrt is not defined for small field");Uo(t,"tonelliShanks");let e=t-N,r=0;for(;e%vt===Z;)e/=vt,r++;let n=vt,o=Xt(t);for(;Vs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Js;let i=o.pow(n,e),s=(e+N)/vt;return function(c,u){let l=c;if(l.is0(u))return u;if(Vs(l,u)!==1)throw new Error("Cannot find square root");let d=r,f=l.mul(l.ONE,i),h=l.pow(u,e),p=l.pow(u,s);for(;!l.eql(h,l.ONE);){if(l.is0(h))throw new Error("Cannot find square root: probably non-prime P");let w=1,I=l.sqr(h);for(;!l.eql(I,l.ONE);)if(w++,I=l.sqr(I),w===d)throw new Error("Cannot find square root");let x=N<<BigInt(d-w-1),C=l.pow(f,x);d=w,f=l.sqr(C),h=l.mul(h,f),p=l.mul(p,C)}return p}}function vd(t){return Uo(t,"Fp.sqrt"),t%Oo===Ys?Js:t%Ws===Gs?Id:t%Xs===bd?Sd(t):ec(t)}var Bd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Wt(t){if(Et(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Yt(t.BYTES,"BYTES"),Yt(t.BITS,"BITS");for(let e of Bd)Tt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=N)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function _o(t,e,r=!1){Wt(t),Wr(e,"nums"),Ye(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function Vs(t,e){Wt(t);let r=t;Uo(r.ORDER,"FpLegendre");let n=(r.ORDER-N)/vt,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Ad(t,e){if(e!==void 0&&vo(e),t<=Z)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Gt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var js=new WeakMap,en=class{ORDER;BITS;BYTES;isLE;ZERO=Z;ONE=N;_lengths;_mod;constructor(e,r={}){if(e<=N)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Ad(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return Se(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Z<=e&&e<this.ORDER}is0(e){return e===Z}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&N)===N}neg(e){return Se(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Se(e*e,this.ORDER)}add(e,r){return Se(e+r,this.ORDER)}sub(e,r){return Se(e-r,this.ORDER)}mul(e,r){return Se(e*r,this.ORDER)}pow(e,r){return Zs(e,r,this.ORDER)}div(e,r){return Se(e*$s(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return $s(e,this.ORDER)}sqrt(e){let r=js.get(this);return r||js.set(this,r=vd(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Co(e,this.BYTES):Jr(e,this.BYTES)}fromBytes(e,r=!1){X(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,i?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Ao(e):Ge(e);if(a&&(c=Se(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return _o(this,e,!0)}cmov(e,r,n){return Ye(n,"condition"),n?r:e}};function Xt(t,e={}){return Object.freeze(en.prototype),new en(t,e)}function tc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=N)throw new Error("field order must be greater than 1");let e=Gt(t-N);return Math.ceil(e/8)}function tn(t){let e=tc(t);return e+Math.ceil(e/2)}function rn(t,e,r=!1){X(t);let n=t.length,o=tc(e),i=Math.max(tn(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ao(t):Ge(t),a=Se(s,e-N)+N;return r?Co(a,o):Jr(a,o)}var No=BigInt(0),br=BigInt(1),Cd=BigInt(4),Po=16,rc=128,Ld=5,nc=2**31;function Zt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Tt(e.fromAffine,"Point.fromAffine"),Tt(e.fromBytes,"Point.fromBytes"),Tt(e.fromHex,"Point.fromHex"),Et(e.BASE,"Point.BASE"),Et(e.ZERO,"Point.ZERO"),Wt(e.Fp),Wt(e.Fn)}function ic(t,e){Zt(t),sc(e,t);let r=_o(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Td(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Od(t,e){let r=t*(4*e+128);if(r>nc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+nc/2**20+" MiB")}function Fo(t,e){if(t!==void 0){Tt(t,"randomBytes");try{let r=t(e);if(!jt(r)||r.length!==e)return}catch{return}return t}}function sc(t,e){Wr(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Dd(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):It(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var cc=new WeakMap;function Ro(t){return cc.get(t)||1}function Ud(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function _d(t,e){let r=2**e,n=r/2,o=BigInt(r-1),i=[];for(;t>No;){let s=0;t&br&&(s=Number(t&o),s>=n&&(s-=r),t-=BigInt(s)),i.push(s),t>>=br}return i}function Pd(t,e,r){let n=2**e,o=n/2,i=BigInt(n-1),s=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&i);t>>=s,u>o&&(u-=n,t+=br),a.push(u)}if(t!==No)throw new Error("invalid wnaf");return a}function Rd(t,e,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=t;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var nn=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Zt(e),this.randomBytes=Fo(r,Po),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=e;for(let c=0;c<o;c++){let u=a;for(let l=0;l<i;l++)s.push(u),u=u.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(e,r){let{W:n,windows:o,comp:i}=e,s=2**(n-1),a=Pd(r,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let d=a[l],f=l*s,h=Math.abs(d)-1,p=i[f];for(let I=1;I<s;I++)p=I===h?i[f+I]:p;let w=p.negate();d===0?u=u.add(i[f]):c=c.add(d<0?w:p)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===e&&a.bits===n);return s||(s=this.buildWnafTable(r,e,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!Lo(r,br,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let i=Ro(e);return i===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+rc,i=this.randomBytes(Po);if(!jt(i)||i.length!==Po)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+Ge(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,n)}fixedWindowCT(e,r,n){let o=Ld,i=1<<o,s=wr(o),a=new Array(i);a[0]=this.ZERO;for(let l=1;l<i;l++)a[l]=a[l-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let h=0;h<o;h++)u=u.double();let d=Number(r>>BigInt(l*o)&s),f=a[0];for(let h=1;h<i;h++)f=h===d?a[h]:f;u=u.add(f)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===br?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!It(r))throw new Error("invalid scalar");let o=Ro(e);if(o===1||r>=this.Point.Fn.ORDER)return on(this.Point,[e],[r],!0);let i=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(e,r){this.assertPoint(e),Td(r,this.bits);let n=Math.ceil((this.bits+rc)/r)+1;Od(n*2**(r-1),this.Point.Fp.BYTES),cc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Ro(e)!==1}};function on(t,e,r,n=!1){if(Zt(t),sc(e,t),Ye(n,"allowOversized"),Dd(r,t.Fn,n?t.Fn.ORDER**Cd:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>Ud(s,4)),i=r.map(s=>_d(s,4));return Rd(t.ZERO,o,i)}function oc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Wt(e),e}else return Xt(t,{isLE:r})}function ac(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);St(r);for(let c of["p","n","h"]){let u=e[c];if(!(It(u)&&u!==No))throw new Error(`CURVE.${c} must be positive bigint`)}let o=oc(e.p,r.Fp,n),i=oc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function uc(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var af=sn.default.generateKeyPairSync,xr=32;var Nd=64;function dc(t,e,r){if(t.byteLength!==xr)throw new TypeError('"key" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(e.byteLength!==Nd)throw new TypeError('"sig" must be 64 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=sn.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:j(t,"base64url"),kty:"OKP"}});return sn.default.verify(null,r instanceof Uint8Array?r:r.subarray(),n,e)}function hc(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var cn=class{type="Ed25519";raw;constructor(e){this.raw=ko(e,xr)}toMultihash(){return Ue.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,e);return hc(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function pc(t){return t=ko(t,xr),new cn(t)}function ko(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Le(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var kd=Math.pow(2,7),Kd=Math.pow(2,14),Md=Math.pow(2,21),Ko=Math.pow(2,28),Mo=Math.pow(2,35),Ho=Math.pow(2,42),qo=Math.pow(2,49),z=128,ie=127;function We(t){if(t<kd)return 1;if(t<Kd)return 2;if(t<Md)return 3;if(t<Ko)return 4;if(t<Mo)return 5;if(t<Ho)return 6;if(t<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Er(t,e,r=0){switch(We(t)){case 8:e[r++]=t&255|z,t/=128;case 7:e[r++]=t&255|z,t/=128;case 6:e[r++]=t&255|z,t/=128;case 5:e[r++]=t&255|z,t/=128;case 4:e[r++]=t&255|z,t>>>=7;case 3:e[r++]=t&255|z,t>>>=7;case 2:e[r++]=t&255|z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function zo(t,e){let r=t[e],n=0;if(n+=r&ie,r<z||(r=t[e+1],n+=(r&ie)<<7,r<z)||(r=t[e+2],n+=(r&ie)<<14,r<z)||(r=t[e+3],n+=(r&ie)<<21,r<z)||(r=t[e+4],n+=(r&ie)*Ko,r<z)||(r=t[e+5],n+=(r&ie)*Mo,r<z)||(r=t[e+6],n+=(r&ie)*Ho,r<z)||(r=t[e+7],n+=(r&ie)*qo,r<z))return n;throw new RangeError("Could not decode varint")}function Hd(t,e){let r=t.get(e),n=0;if(n+=r&ie,r<z||(r=t.get(e+1),n+=(r&ie)<<7,r<z)||(r=t.get(e+2),n+=(r&ie)<<14,r<z)||(r=t.get(e+3),n+=(r&ie)<<21,r<z)||(r=t.get(e+4),n+=(r&ie)*Ko,r<z)||(r=t.get(e+5),n+=(r&ie)*Mo,r<z)||(r=t.get(e+6),n+=(r&ie)*Ho,r<z)||(r=t.get(e+7),n+=(r&ie)*qo,r<z))return n;throw new RangeError("Could not decode varint")}function $o(t,e=0){return t instanceof Uint8Array?zo(t,e):Hd(t,e)}var Vo=new Float32Array([-0]),Bt=new Uint8Array(Vo.buffer);function fc(t,e,r){Vo[0]=t,e[r]=Bt[0],e[r+1]=Bt[1],e[r+2]=Bt[2],e[r+3]=Bt[3]}function gc(t,e){return Bt[0]=t[e],Bt[1]=t[e+1],Bt[2]=t[e+2],Bt[3]=t[e+3],Vo[0]}var jo=new Float64Array([-0]),se=new Uint8Array(jo.buffer);function mc(t,e,r){jo[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3],e[r+4]=se[4],e[r+5]=se[5],e[r+6]=se[6],e[r+7]=se[7]}function yc(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],se[4]=t[e+4],se[5]=t[e+5],se[6]=t[e+6],se[7]=t[e+7],jo[0]}var zd=BigInt(Number.MAX_SAFE_INTEGER),$d=BigInt(Number.MIN_SAFE_INTEGER),Be=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ot;if(e<zd&&e>$d)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>wc&&(o=0n,++n>wc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ot;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Ot}},Ot=new Be(0,0);Ot.toBigInt=function(){return 0n};Ot.zzEncode=Ot.zzDecode=function(){return this};Ot.length=function(){return 1};var wc=4294967296n;function bc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function xc(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Yo(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Re(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function an(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Go=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=wt(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Re(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Re(this,4);return an(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Re(this,4);return an(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Re(this,4);let e=gc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Re(this,4);let e=yc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Re(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return xc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Re(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Re(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Be(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Re(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Re(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Re(this,8);let e=an(this.buf,this.pos+=4),r=an(this.buf,this.pos+=4);return new Be(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=zo(this.buf,this.pos);return this.pos+=We(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Ir(t){return new Go(t instanceof Uint8Array?t:t.subarray())}function un(t,e,r){let n=Ir(t);return e.decode(n,void 0,r)}function Wo(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return Ee(s);o+s>e&&(n=Ee(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Dt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Xo(){}var Qo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Vd=Wo();function jd(t){return globalThis.Buffer!=null?Ee(t):Vd(t)}var vr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dt(Xo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Dt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Jo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(dn,10,Be.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Be.fromBigInt(e);return this._push(dn,r.length(),r)}uint64Number(e){return this._push(Er,We(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Be.fromBigInt(e).zzEncode();return this._push(dn,r.length(),r)}sint64Number(e){let r=Be.fromNumber(e).zzEncode();return this._push(dn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Zo,1,e?1:0)}fixed32(e){return this._push(Sr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Be.fromBigInt(e);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64Number(e){let r=Be.fromNumber(e);return this._push(Sr,4,r.lo)._push(Sr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(fc,4,e)}double(e){return this._push(mc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(Gd,r,e)}string(e){let r=bc(e);return r!==0?this.uint32(r)._push(Yo,r,e):this._push(Zo,1,0)}fork(){return this.states=new Qo(this),this.head=this.tail=new Dt(Xo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Dt(Xo,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=jd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Zo(t,e,r){e[r]=t&255}function Yd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Jo=class extends Dt{next;constructor(e,r){super(Yd,e,r),this.next=void 0}};function dn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Sr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Gd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(vr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Wd,e,t),this},vr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Xd,e,t),this});function Wd(t,e,r){e.set(t,r)}function Xd(t,e,r){t.length<40?Yo(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(de(t),r)}function ei(){return new vr}function ln(t,e){let r=ei();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*hn(t,e,r){let n=Ir(t);yield*e.stream(n,void 0,"$",r)}var pn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function fn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function ti(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return fn("enum",pn.VARINT,r,n,o)}function gn(t,e,r){return fn("message",pn.LENGTH_DELIMITED,t,e,r)}var le;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(le||(le={}));var ri;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(ri||(ri={}));(function(t){t.codec=()=>ti(ri)})(le||(le={}));var Br;(function(t){let e;t.codec=()=>(e==null&&(e=gn((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),le.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.Type=le.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return ln(i,t.codec())}t.encode=r;function n(i,s){return un(i,t.codec(),s)}t.decode=n;function o(i,s){return hn(i,t.codec(),s)}t.stream=o})(Br||(Br={}));var ni;(function(t){let e;t.codec=()=>(e==null&&(e=gn((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),le.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.Type=le.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return ln(i,t.codec())}t.encode=r;function n(i,s){return un(i,t.codec(),s)}t.decode=n;function o(i,s){return hn(i,t.codec(),s)}t.stream=o})(ni||(ni={}));var Oc=ir(me("node:crypto"),1);var mn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(zr(e),je(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),mr(o)}update(e){return Vt(this),this.iHash.update(e),this}digestInto(e){Vt(this),$r(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ic=(()=>{let t=((e,r,n)=>new mn(e,r).update(n).digest());return t.create=(e,r)=>new mn(e,r),t})();var Qd=BigInt(0),oi=class extends Error{constructor(e=""){super(e)}},dt={Err:oi,_tlv:{encode:(t,e)=>{let{Err:r}=dt;if(Yt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Hs(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=yr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?yr(o.length/2|128):"";return yr(t)+i+o+e},decode(t,e){let{Err:r}=dt;e=X(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)s=s<<8|l;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=dt;if(Qr(t),t<Qd)throw new e("integer: negative integers are not allowed");let r=yr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=dt;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ge(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=dt,o=X(t,void 0,"signature"),{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=dt;St(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},ii=(Object.freeze(dt._tlv),Object.freeze(dt._int),Object.freeze(dt));var Sc=(t,e)=>(t+(t>=0?e:-e)/vc)/e;function Jd(t,e,r){To("scalar",t,lt,r);let[[n,o],[i,s]]=e,a=Sc(s*t,r),c=Sc(-o*t,r),u=t-a*n-c*i,l=-a*o-c*s,d=u<lt,f=l<lt;d&&(u=-u),f&&(l=-l);let h=wr(Math.ceil(Gt(r)/2))+Ut;if(u<lt||u>=h||l<lt||l>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:f,k2:l}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){St(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ye(r.lowS,"lowS"),Ye(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var lt=BigInt(0),Ut=BigInt(1),vc=BigInt(2),ci=BigInt(3),el=BigInt(4);function Bc(t,e={}){let r=ac("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;St(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u}=e,l=e.randomBytes===void 0?Zr:e.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let d=Cc(n,o);function f(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(P,m,S){if(u&&m.is0())return Uint8Array.of(0);let{x:L,y:O}=m.toAffine(),b=n.toBytes(L);if(Ye(S,"isCompressed"),S){f();let g=!n.isOdd(O);return ut(Ac(g),b)}else return ut(Uint8Array.of(4),b,n.toBytes(O))}function p(P){X(P,void 0,"Point");let{publicKey:m,publicKeyUncompressed:S}=d,L=P.length,O=P[0],b=P.subarray(1);if(u&&L===1&&O===0)return{x:n.ZERO,y:n.ZERO};if(L===m&&(O===2||O===3)){let g=n.fromBytes(b);if(!n.isValid(g))throw new Error("bad point: is not on curve, wrong x");let E=q(g),v;try{v=n.sqrt(E)}catch(M){let R=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+R)}f();let D=n.isOdd(v);return(O&1)===1!==D&&(v=n.neg(v)),{x:g,y:v}}else if(L===S&&O===4){let g=n.BYTES,E=n.fromBytes(b.subarray(0,g)),v=n.fromBytes(b.subarray(g,g*2));if(!F(E,v))throw new Error("bad point: is not on curve");return{x:E,y:v}}else throw new Error(`bad point: got length ${L}, expected compressed=${m} or uncompressed=${S}`)}let w=e.toBytes===void 0?h:e.toBytes,I=e.fromBytes===void 0?p:e.fromBytes,x=n.mul(i.b,ci),C=n.is0(i.a)?P=>n.ZERO:P=>n.mul(i.a,P);function q(P){let m=n.sqr(P),S=n.mul(m,P);return n.add(n.add(S,n.mul(P,i.a)),i.b)}function F(P,m){let S=n.sqr(m),L=q(P);return n.eql(S,L)}if(!F(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let H=n.mul(n.pow(i.a,ci),el),k=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(H,k)))throw new Error("bad curve params: a or b");function W(P,m,S=!1){if(!n.isValid(m)||S&&n.is0(m))throw new Error(`bad point coordinate ${P}`);return m}function Q(P){if(!(P instanceof _))throw new Error("Weierstrass Point expected")}function ge(P){if(!c||!c.basises)throw new Error("no endo");return Jd(P,c.basises,o.ORDER)}function K(P,m,S,L){if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(c){let{k1neg:O,k1:b,k2neg:g,k2:E}=ge(L),v=new _(n.mul(S.X,c.beta),S.Y,S.Z);P.push(O?S.negate():S,g?v.negate():v),m.push(b,E)}else P.push(S),m.push(L)}let ce=new WeakSet;class _{static BASE=new _(i.Gx,i.Gy,n.ONE);static ZERO=new _(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(m,S,L){this.X=W("x",m),this.Y=W("y",S,!0),this.Z=W("z",L),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:S,y:L}=m||{};if(!m||!n.isValid(S)||!n.isValid(L))throw new Error("invalid affine point");if(m instanceof _)throw new Error("projective point not allowed");return n.is0(S)&&n.is0(L)?_.ZERO:new _(S,L,n.ONE)}static fromBytes(m){let S=_.fromAffine(I(X(m,void 0,"point")));return S.assertValidity(),S}static fromHex(m){return _.fromBytes(Xr(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=6,S=!0){return Ze.setWindowSize(this,m),S||this.multiply(ci),this}assertValidity(){let m=this;if(m.is0()){if(e.allowInfinityPoint&&n.is0(m.X)&&n.eql(m.Y,n.ONE)&&n.is0(m.Z))return;throw new Error("bad point: ZERO")}if(ce.has(m))return;let{x:S,y:L}=m.toAffine();if(!n.isValid(S)||!n.isValid(L))throw new Error("bad point: x or y not field elements");if(!F(S,L))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");ce.add(m)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){Q(m);let{X:S,Y:L,Z:O}=this,{X:b,Y:g,Z:E}=m,v=n.eql(n.mul(S,E),n.mul(b,O)),D=n.eql(n.mul(L,E),n.mul(g,O));return v&&D}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{X:m,Y:S,Z:L}=this,O=n.ZERO,b=n.ZERO,g=n.ZERO,E=n.mul(m,m),v=n.mul(S,S),D=n.mul(L,L),T=n.mul(m,S);return T=n.add(T,T),g=n.mul(m,L),g=n.add(g,g),O=C(g),b=n.mul(x,D),b=n.add(O,b),O=n.sub(v,b),b=n.add(v,b),b=n.mul(O,b),O=n.mul(T,O),g=n.mul(x,g),D=C(D),T=n.sub(E,D),T=C(T),T=n.add(T,g),g=n.add(E,E),E=n.add(g,E),E=n.add(E,D),E=n.mul(E,T),b=n.add(b,E),D=n.mul(S,L),D=n.add(D,D),E=n.mul(D,T),O=n.sub(O,E),g=n.mul(D,v),g=n.add(g,g),g=n.add(g,g),new _(O,b,g)}add(m){Q(m);let{X:S,Y:L,Z:O}=this,{X:b,Y:g,Z:E}=m,v=n.ZERO,D=n.ZERO,T=n.ZERO,M=n.mul(S,b),R=n.mul(L,g),Y=n.mul(O,E),he=n.add(S,L),$=n.add(b,g);he=n.mul(he,$),$=n.add(M,R),he=n.sub(he,$),$=n.add(S,O);let oe=n.add(b,E);return $=n.mul($,oe),oe=n.add(M,Y),$=n.sub($,oe),oe=n.add(L,O),v=n.add(g,E),oe=n.mul(oe,v),v=n.add(R,Y),oe=n.sub(oe,v),T=C($),v=n.mul(x,Y),T=n.add(v,T),v=n.sub(R,T),T=n.add(R,T),D=n.mul(v,T),R=n.add(M,M),R=n.add(R,M),Y=C(Y),$=n.mul(x,$),R=n.add(R,Y),Y=n.sub(M,Y),Y=C(Y),$=n.add($,Y),M=n.mul(R,$),D=n.add(D,M),M=n.mul(oe,$),v=n.mul(he,v),v=n.sub(v,M),M=n.mul(he,R),T=n.mul(oe,T),T=n.add(T,M),new _(v,D,T)}subtract(m){return Q(m),this.add(m.negate())}is0(){return this.equals(_.ZERO)}multiply(m){if(!o.isValidNot0(m))throw new RangeError("invalid scalar: out of range");let{p:S,f:L}=Ze.mulSecret(this,m,s,rr);return rr([S,L])[0]}multiplyUnsafe(m){let S=this,L=m;if(!o.isValid(L))throw new RangeError("invalid scalar: out of range");if(L===lt||S.is0())return _.ZERO;if(L===Ut)return S;if(Ze.hasWindowSize(this))return Ze.mulUnsafe(S,L,rr);let O=[],b=[];return K(O,b,S,L),on(_,O,b)}mulAddUnsafe(m,S,L){Q(S);let O=[],b=[];return K(O,b,this,m),K(O,b,S,L),on(_,O,b)}toAffine(m){let S=this,L=m;if(L!=null&&!n.isValid(L))throw new RangeError('"invertedZ" expected valid field element');let{X:O,Y:b,Z:g}=S;if(n.eql(g,n.ONE))return{x:O,y:b};let E=S.is0();L==null&&(L=E?n.ONE:n.inv(g));let v=n.mul(O,L),D=n.mul(b,L),T=n.mul(g,L);if(E)return{x:n.ZERO,y:n.ZERO};if(!n.eql(T,n.ONE))throw new Error("invZ was invalid");return{x:v,y:D}}isTorsionFree(){let{isTorsionFree:m}=e;return s===Ut?!0:m?m(_,this):Ze.mulUnsafe(this,a).is0()}clearCofactor(){let{clearCofactor:m}=e;return s===Ut?this:m?m(_,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Ut?this.is0():this.clearCofactor().is0()}toBytes(m=!0){return Ye(m,"isCompressed"),this.assertValidity(),w(_,this,m)}toHex(m=!0){return Bo(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let rr=P=>ic(_,P),Ze=new nn(_,l);return Ze.bits>=6&&_.BASE.precompute(6),Object.freeze(_.prototype),Object.freeze(_),_}function Ac(t){return Uint8Array.of(t?2:3)}function Cc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function tl(t,e={}){Zt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Zr:e.randomBytes,o=Object.assign(Cc(t.Fp,r),{seed:Math.max(tn(r.ORDER),16)});function i(h){try{let p=r.fromBytes(h);return r.isValidNot0(p)}catch{return!1}}function s(h,p){let{publicKey:w,publicKeyUncompressed:I}=o;try{let x=h.length;return p===!0&&x!==w||p===!1&&x!==I?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,rn(X(h,o.seed,"seed"),r.ORDER)}function c(h,p=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(p)}function u(h){let{secretKey:p,publicKey:w,publicKeyUncompressed:I}=o,x=r._lengths;if(!jt(h))return;let C=X(h,void 0,"key").length,q=C===w||C===I,F=C===p||!!x?.includes(C);if(!(q&&F))return q}function l(h,p,w=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");let I=r.fromBytes(h);return t.fromBytes(p).multiply(I).toBytes(w)}let d={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},f=uc(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:f,Point:t,utils:d,lengths:o})}function Lc(t,e,r={}){Zt(t);let n=e;zr(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?Zr:o.randomBytes,s=o.hmac===void 0?(b,g)=>Ic(n,b,g):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:l}=c,d=tn(u),f=Fo(i,d),{keygen:h,getPublicKey:p,getSharedSecret:w,utils:I,lengths:x}=tl(t,o),C={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},q=u*vc+Ut<a.ORDER;function F(b){let g=u>>Ut;return b>g}function H(b,g){if(!c.isValidNot0(g))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return g}function k(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function W(b,g,E){return k(),(b===E?0:2)|Number(a.isOdd(g))}function Q(){if(q)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function ge(b,g){ai(g);let E=x.signature,v=g==="compact"?E:g==="recovered"?E+1:void 0;return X(b,v)}class K{r;s;recovery;constructor(g,E,v){if(this.r=H("r",g),this.s=H("s",E),v!=null){if(Q(),![0,1,2,3].includes(v))throw new Error("invalid recovery id");this.recovery=v}Object.freeze(this)}static fromBytes(g,E=C.format){ge(g,E);let v;if(E==="der"){let{r:R,s:Y}=ii.toSig(X(g));return new K(R,Y)}E==="recovered"&&(v=g[0],E="compact",g=g.subarray(1));let D=x.signature/2,T=g.subarray(0,D),M=g.subarray(D,D*2);return new K(c.fromBytes(T),c.fromBytes(M),v)}static fromHex(g,E){return this.fromBytes(Xr(g),E)}assertRecovery(){let{recovery:g}=this;if(g==null)throw new Error("invalid recovery id: must be present");return g}addRecoveryBit(g){return new K(this.r,this.s,g)}recoverPublicKey(g){let{r:E,s:v}=this,D=this.assertRecovery(),T=D===2||D===3?E+u:E;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let M=a.toBytes(T),R=t.fromBytes(ut(Ac((D&1)===0),M)),Y=c.inv(T),he=_(X(g,void 0,"msgHash")),$=c.create(-he*Y),oe=c.create(v*Y),Ne=t.BASE.mulAddUnsafe($,R,oe);if(Ne.is0())throw new Error("invalid recovery: point at infinify");return Ne.assertValidity(),Ne}hasHighS(){return F(this.s)}toBytes(g=C.format){if(ai(g),g==="der")return Xr(ii.hexFromSig(this));let{r:E,s:v}=this,D=c.toBytes(E),T=c.toBytes(v);return g==="recovered"?(Q(),ut(Uint8Array.of(this.assertRecovery()),D,T)):ut(D,T)}toHex(g){return Bo(this.toBytes(g))}}Object.freeze(K.prototype),Object.freeze(K);let ce=o.bits2int===void 0?function(g){if(g.length>8192)throw new Error("input is too large");let E=Ge(g),v=g.length*8-l;return v>0?E>>BigInt(v):E}:o.bits2int,_=o.bits2int_modN===void 0?function(g){return c.create(ce(g))}:o.bits2int_modN,rr=wr(l);function Ze(b){return To("num < 2^"+l,b,lt,rr),c.toBytes(b)}function P(b,g){return X(b,void 0,"message"),g?X(n(b),void 0,"prehashed message"):b}function m(b,g,E){let{lowS:v,prehash:D,extraEntropy:T}=si(E,C);b=P(b,D);let M=_(b),R=c.fromBytes(g);if(!c.isValidNot0(R))throw new Error("invalid private key");let Y=[Ze(R),Ze(M)];if(T!=null&&T!==!1){let Ne=T===!0?i(x.secretKey):T;Y.push(X(Ne,void 0,"extraEntropy"))}let he=ut(...Y),$=M;function oe(Ne){let Rt=ce(Ne);if(!c.isValidNot0(Rt))return;let nr=t.BASE.multiply(Rt).toAffine(),ft=c.create(nr.x);if(ft===lt)return;let Fe;if(f!==void 0){let or=Ge(rn(f(d),u)),ha=c.inv(c.mul(or,Rt)),pa=c.mul(or,$),fa=c.mul(or,R);Fe=c.create(ha*c.create(pa+fa*ft))}else{let or=Qs(Rt,u);Fe=c.create(or*c.create($+ft*R))}if(Fe===lt)return;let Cn=W(nr.x,nr.y,ft),Bi=Fe;return v&&F(Fe)&&(Bi=c.neg(Fe),Cn^=1),new K(ft,Bi,q?void 0:Cn)}return{seed:he,k2sig:oe}}function S(b,g,E={}){let{seed:v,k2sig:D}=m(b,g,E);return zs(n.outputLen,c.BYTES,s)(v,D).toBytes(E.format)}function L(b,g,E,v={}){let{lowS:D,prehash:T,format:M}=si(v,C);if(E=X(E,void 0,"publicKey"),g=P(g,T),!jt(b)){let R=b instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}ge(b,M);try{let R=K.fromBytes(b,M),Y=t.fromBytes(E);if(D&&R.hasHighS())return!1;let{r:he,s:$}=R,oe=_(g),Ne=c.inv($),Rt=c.create(oe*Ne),nr=c.create(he*Ne),ft=t.BASE.mulAddUnsafe(Rt,Y,nr);if(ft.is0())return!1;let Fe=ft.toAffine();return!(c.create(Fe.x)!==he||M==="recovered"&&R.recovery!==W(Fe.x,Fe.y,he))}catch{return!1}}function O(b,g,E={}){let{prehash:v}=si(E,C);return g=P(g,v),K.fromBytes(b,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:h,getPublicKey:p,getSharedSecret:w,utils:I,lengths:x,Point:t,sign:S,verify:L,recoverPublicKey:O,Signature:K,hash:n})}var di={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},rl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Tc=BigInt(2);function nl(t){let e=di.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,d=ve(l,r,e)*l%e,f=ve(d,r,e)*l%e,h=ve(f,Tc,e)*u%e,p=ve(h,o,e)*h%e,w=ve(p,i,e)*p%e,I=ve(w,a,e)*w%e,x=ve(I,c,e)*I%e,C=ve(x,a,e)*w%e,q=ve(C,r,e)*l%e,F=ve(q,s,e)*p%e,H=ve(F,n,e)*u%e,k=ve(H,Tc,e);if(!ui.eql(ui.sqr(k),t))throw new Error("Cannot find square root");return k}var ui=Xt(di.p,{sqrt:nl}),ol=Bc(di,{Fp:ui,endo:rl}),Ar=Lc(ol,Ks);var yn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}};function Dc(t,e,r,n){n?.signal?.throwIfAborted();let o=Oc.default.createHash("sha256");if(r instanceof Uint8Array)o.update(r);else for(let s of r)o.update(s);let i=o.digest();try{return Ar.verify(e,i,t,{prehash:!1,format:"der"})}catch(s){throw new yn(String(s))}}var wn=class{type="secp256k1";raw;_key;constructor(e){this._key=_c(e),this.raw=Uc(this._key)}toMultihash(){return Ue.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return G.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Dc(this._key,r,e,n)}};function Pc(t){return new wn(t)}function Uc(t){return Ar.Point.fromBytes(t).toBytes()}function _c(t){try{return Ar.Point.fromBytes(t),t}catch(e){throw new Ur(String(e))}}function Rc(t){let{Type:e,Data:r}=Br.decode(t.digest),n=r??new Uint8Array;switch(e){case le.Ed25519:return pc(n);case le.secp256k1:return Pc(n);case le.ECDSA:return Bs(n);default:throw new sr}}function $t(t){return Br.encode({Type:le[t.type],Data:t.raw})}var Nc=Symbol.for("nodejs.util.inspect.custom"),il=114,Cr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ln]=!0;toString(){return this.string==null&&(this.string=G.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return re.createV1(il,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Nc](){return`PeerId(${this.toString()})`}},bn=class extends Cr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},xn=class extends Cr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},En=class extends Cr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},sl=2336,Lr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ue.digest(de(this.url))}[Nc](){return`PeerId(${this.url})`}[Ln]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return re.createV1(sl,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=j(e)),e.toString()===this.toString())}};var cl=114,Fc=2336;function kc(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=lr(G.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return al(re.parse(t));if(e==null)throw new Le('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=lr(e.decode(t))}return Kc(r)}function Kc(t){if(dl(t))return new bn({multihash:t});if(ul(t))try{let e=Rc(t);if(e.type==="Ed25519")return new xn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new En({multihash:t,publicKey:e})}catch{let r=j(t.digest);return new Lr(new URL(r))}throw new Pr("Supplied PeerID Multihash is invalid")}function al(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==cl&&t.code!==Fc)throw new _r("Supplied PeerID CID is invalid");if(t.code===Fc){let e=j(t.multihash.digest);return new Lr(new URL(e))}return Kc(t.multihash)}function ul(t){return t.code===Ue.code}function dl(t){return t.code===lo.code}function ll(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function Mc(t){let e=ll(t);if(e==null)throw new Le(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var Ae=me("node:net");var $c=ir(zc(),1),wl=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],bl=wl.map(t=>new $c.Netmask(t));function yi(t){for(let e of bl)if(e.contains(t))return!0;return!1}function xl(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function El(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return yi(o)}function Il(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Sl(t){let e=t.split(":"),r=e[e.length-1];return yi(r)}function vl(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Vc(t){if((0,Ae.isIPv4)(t))return yi(t);if(xl(t))return El(t);if(Il(t))return Sl(t);if((0,Ae.isIPv6)(t))return vl(t)}function jc(t){try{let e=Mc(t);switch(e.type){case"ip4":case"ip6":return Vc(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ne=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ht=class extends Error{static name="ValidationError";name="ValidationError"},Sn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},vn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function bi(t){return e=>j(e,t)}function xi(t){return e=>de(e,t)}function tr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Pt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=de(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pt(n);return _e([r,o],r.length+o.length)}function Gc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=yt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pt(n);return _e([r,o],r.length+o.length)}function Ei(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=j(e,"base32"),o=tr(r);return`${n}:${o}`}var Ii=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ne("Invalid byte value in IP address");e[n]=o}),e},Wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let i=(0,Ae.isIPv4)(r[n]),s;i&&(s=Ii(r[n]),r[n]=j(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,j(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new ne("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Xc=function(t){if(t.byteLength!==4)throw new ne("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Zc=function(t){if(t.byteLength!==16)throw new ne("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],i=t[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ne(`Invalid IPv6 address "${r}"`)}};function Qc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ne(`Invalid IPv6 address "${t}"`)}}var wi=Object.values(pr).map(t=>t.decoder),Bl=(function(){let t=wi[0].or(wi[1]);return wi.slice(2).forEach(e=>t=t.or(e)),t})();function Jc(t){return Bl.decode(t)}function ea(t){return e=>t.encoder.encode(e)}function Al(t){if(parseInt(t).toString()!==t)throw new ht("Value must be an integer")}function Cl(t){if(t<0)throw new ht("Value must be a positive integer, or zero")}function Ll(t){return e=>{if(e>t)throw new ht(`Value must be smaller than or equal to ${t}`)}}function Tl(...t){return e=>{for(let r of t)r(e)}}var Tr=Tl(Al,Cl,Ll(65535));var ee=-1,Si=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new vn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},pt=new Si,gh=[{code:4,name:"ip4",size:32,valueToBytes:Ii,bytesToValue:Xc,validate:t=>{if(!(0,Ae.isIPv4)(t))throw new ht(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pt,bytesToValue:tr,validate:Tr},{code:273,name:"udp",size:16,valueToBytes:Pt,bytesToValue:tr,validate:Tr},{code:33,name:"dccp",size:16,valueToBytes:Pt,bytesToValue:tr,validate:Tr},{code:41,name:"ip6",size:128,valueToBytes:Wc,bytesToValue:Zc,stringToValue:Qc,validate:t=>{if(!(0,Ae.isIPv6)(t))throw new ht(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ee},{code:43,name:"ipcidr",size:8,bytesToValue:bi("base10"),valueToBytes:xi("base10")},{code:53,name:"dns",size:ee},{code:54,name:"dns4",size:ee},{code:55,name:"dns6",size:ee},{code:56,name:"dnsaddr",size:ee},{code:132,name:"sctp",size:16,valueToBytes:Pt,bytesToValue:tr,validate:Tr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ee,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ee,bytesToValue:bi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?xi("base58btc")(t):re.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ei,valueToBytes:Yc},{code:445,name:"onion3",size:296,bytesToValue:Ei,valueToBytes:Gc},{code:446,name:"garlic64",size:ee},{code:447,name:"garlic32",size:ee},{code:448,name:"tls"},{code:449,name:"sni",size:ee},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ee,bytesToValue:ea(no),valueToBytes:Jc},{code:480,name:"http"},{code:481,name:"http-path",size:ee,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ee}];gh.forEach(t=>{pt.addProtocol(t)});function ta(t){let e=[],r=0;for(;r<t.length;){let n=$o(t,r),o=pt.getProtocol(n),i=We(n),s=mh(o,t,r+i),a=0;s>0&&o.size===ee&&(a=We(s));let c=i+a+s,u={code:n,name:o.name,bytes:wt(t.subarray(r,r+c))};if(s>0){let l=r+i+a,d=t.subarray(l,l+s);u.value=o.bytesToValue?.(d)??j(d)}e.push(u),r+=c}return e}function ra(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=pt.getProtocol(n.code),i=We(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??de(n.value),a=s.byteLength,o.size===ee&&(c=We(a)));let u=new Uint8Array(i+c+a),l=0;Er(n.code,u,l),l+=i,s!=null&&(o.size===ee&&(Er(a,u,l),l+=c),u.set(s,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return _e(r,e)}function na(t){if(t.charAt(0)!=="/")throw new ne('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let i=1;i<t.length;i++){let s=t.charAt(i);s!=="/"&&(r==="protocol"?o+=t.charAt(i):n+=t.charAt(i));let a=i===t.length-1;if(s==="/"||a){let c=pt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ne(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ne(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ne("Incomplete multiaddr");return e}function oa(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=pt.getProtocol(e.code);if(r==null)throw new ne(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function mh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:$o(e,r)}var yh=Symbol.for("nodejs.util.inspect.custom"),vi=Symbol.for("@multiformats/multiaddr");function wh(t){if(t==null&&(t="/"),ia(t))return t.getComponents();if(t instanceof Uint8Array)return ta(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),na(t);if(Array.isArray(t))return t;throw new ne("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Bn=class t{[vi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=wh(e),r.validate!==!1&&bh(this)}get bytes(){return this.#r==null&&(this.#r=ra(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=oa(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Sn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return fe(this.bytes,e.bytes)}[yh](){return`Multiaddr(${this.toString()})`}};function bh(t){t.getComponents().forEach(e=>{let r=pt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ia(t){return!!t?.[vi]}function sa(t){return new Bn(t)}function ca(t,e,r,n){let o=()=>{n?.log.trace("query",e),t.query({questions:[{name:e,type:"PTR"}]})};return o(),setInterval(o,r)}function aa(t,e,r,n){if(t.answers==null)return;let o,i=[];if(t.answers.forEach(s=>{switch(s.type){case"PTR":o=s;break;case"TXT":i.push(s);break;default:break}}),t.additionals.forEach(s=>{s.type==="TXT"&&i.push(s)}),!(o==null||o?.name!==r||i.length===0||o.data.startsWith(e)))try{let s=i.flatMap(c=>c.data).filter(c=>c.toString().startsWith("dnsaddr=")).map(c=>sa(c.toString().substring(8))),a=s[0].getComponents().findLast(c=>c.code===421)?.value;if(a==null)throw new Error("Multiaddr doesn't contain PeerId");return n?.log("peer found %p",a),{id:kc(a),multiaddrs:s.map(c=>c.decapsulateCode(421))}}catch(s){n?.log.error("failed to parse mdns response - %e",s)}}function ua(t,e,r,n,o,i,s){if(!i){s?.log("not responding to mDNS query as broadcast mode is false");return}if(n.length!==0&&t.questions[0]!=null&&t.questions[0].name===o){let a=[];a.push({name:o,type:"PTR",class:"IN",ttl:120,data:r+"."+o}),n.filter(xh).forEach(c=>{let u="dnsaddr="+c.toString();if(u.length>255){s?.log("multiaddr %a is too long to use in mDNS query response",c);return}if(c.getComponents().findLast(l=>l.code===421)?.value==null){s?.log("multiaddr %a did not have a peer ID so cannot be used in mDNS query response",c);return}a.push({name:r+"."+o,type:"TXT",class:"IN",ttl:120,data:u})}),s?.log.trace("responding to query"),e.respond(a)}}function xh(t){return!!jc(t)}function da(t){let e="",r="abcdefghijklmnopqrstuvwxyz0123456789";for(let n=0;n<t;n++)e+=r.charAt(Math.floor(Math.random()*r.length));return e}var An=class extends Rr{mdns;log;broadcast;interval;serviceTag;peerName;port;ip;_queryInterval;components;constructor(e,r={}){if(super(),this.log=e.logger.forComponent("libp2p:mdns"),this.broadcast=r.broadcast!==!1,this.interval=r.interval??1e3*10,this.serviceTag=r.serviceTag??"_p2p._udp.local",this.ip=r.ip??"224.0.0.251",this.peerName=r.peerName??da(63),this.peerName.length>=64)throw new Error("Peer name should be less than 64 chars long");this.port=r.port??5353,this.components=e,this._queryInterval=null,this._onMdnsQuery=this._onMdnsQuery.bind(this),this._onMdnsResponse=this._onMdnsResponse.bind(this),this._onMdnsWarning=this._onMdnsWarning.bind(this),this._onMdnsError=this._onMdnsError.bind(this)}[Ci]=this;[Symbol.toStringTag]="@libp2p/mdns";[Di]=["@libp2p/peer-discovery"];isStarted(){return!!this.mdns}async start(){this.mdns==null&&(this.mdns=(0,la.default)({port:this.port,ip:this.ip}),this.mdns.on("query",this._onMdnsQuery),this.mdns.on("response",this._onMdnsResponse),this.mdns.on("warning",this._onMdnsWarning),this.mdns.on("error",this._onMdnsError),this._queryInterval=ca(this.mdns,this.serviceTag,this.interval,{log:this.log}))}_onMdnsQuery(e){this.mdns!=null&&(this.log.trace("received incoming mDNS query"),ua(e,this.mdns,this.peerName,this.components.addressManager.getAddresses(),this.serviceTag,this.broadcast,{log:this.log}))}_onMdnsResponse(e){this.log.trace("received mDNS query response");try{let r=aa(e,this.peerName,this.serviceTag,{log:this.log});r!=null&&(this.log("discovered peer in mDNS query response %p",r.id),this.dispatchEvent(new CustomEvent("peer",{detail:r})))}catch(r){this.log.error("error processing peer response - %e",r)}}_onMdnsWarning(e){this.log.error("mdns warning - %e",e)}_onMdnsError(e){this.log.error("mdns error - %e",e)}async stop(){this.mdns!=null&&(this.mdns.removeListener("query",this._onMdnsQuery),this.mdns.removeListener("response",this._onMdnsResponse),this.mdns.removeListener("warning",this._onMdnsWarning),this.mdns.removeListener("error",this._onMdnsError),this._queryInterval!=null&&(clearInterval(this._queryInterval),this._queryInterval=null),await new Promise(e=>{this.mdns!=null?this.mdns.destroy(e):e()}),this.mdns=void 0)}};function Ih(t={}){return e=>new An(e,t)}return xa(Sh);})();
2
+ "use strict";var Libp2PMdns=(()=>{var ga=Object.create;var Dr=Object.defineProperty;var ma=Object.getOwnPropertyDescriptor;var ya=Object.getOwnPropertyNames;var wa=Object.getPrototypeOf,ba=Object.prototype.hasOwnProperty;var ge=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Oe=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},me=(t,e)=>{for(var r in e)Dr(t,r,{get:e[r],enumerable:!0})},Ai=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ya(e))!ba.call(t,o)&&o!==r&&Dr(t,o,{get:()=>e[o],enumerable:!(n=ma(e,o))||n.enumerable});return t};var nr=(t,e,r)=>(r=t!=null?ga(wa(t)):{},Ai(e||!t||!t.__esModule?Dr(r,"default",{value:t,enumerable:!0}):r,t)),xa=t=>Ai(Dr({},"__esModule",{value:!0}),t);var Ui=Oe(Dn=>{"use strict";Dn.toString=function(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};Dn.toType=function(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}});var _i=Oe(Un=>{"use strict";Un.toString=function(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};Un.toRcode=function(t){switch(t.toUpperCase()){case"NOERROR":return 0;case"FORMERR":return 1;case"SERVFAIL":return 2;case"NXDOMAIN":return 3;case"NOTIMP":return 4;case"REFUSED":return 5;case"YXDOMAIN":return 6;case"YXRRSET":return 7;case"NXRRSET":return 8;case"NOTAUTH":return 9;case"NOTZONE":return 10;case"RCODE_11":return 11;case"RCODE_12":return 12;case"RCODE_13":return 13;case"RCODE_14":return 14;case"RCODE_15":return 15}return 0}});var Pi=Oe(_n=>{"use strict";_n.toString=function(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};_n.toOpcode=function(t){switch(t.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}});var Ri=Oe(Pn=>{"use strict";Pn.toString=function(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};Pn.toClass=function(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}});var Ni=Oe(Rn=>{"use strict";Rn.toString=function(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}`};Rn.toCode=function(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}});var Ki=Oe((ki,Nn)=>{var Fi=(function(t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode=d,t.encode=l,t.familyOf=u,t.name=void 0,t.sizeOf=c,t.v6=t.v4=void 0;let e=/^(\d{1,3}\.){3,3}\d{1,3}$/,r=4,n=/^(::)?(((\d{1,3}\.){3}(\d{1,3}){1})?([0-9a-f]){0,4}:{0,2}){1,8}(::)?$/i,o=16,i={name:"v4",size:r,isFormat:g=>e.test(g),encode(g,h,f){f=~~f,h=h||new Uint8Array(f+r);let b=g.length,E=0;for(let x=0;x<b;){let O=g.charCodeAt(x++);O===46?(h[f++]=E,E=0):E=E*10+(O-48)}return h[f]=E,h},decode(g,h){return h=~~h,`${g[h++]}.${g[h++]}.${g[h++]}.${g[h]}`}};t.v4=i;let s={name:"v6",size:o,isFormat:g=>g.length>0&&n.test(g),encode(g,h,f){f=~~f;let b=f+o,E=-1,x=0,O=0,q=!0,k=!1;h=h||new Uint8Array(f+o);for(let F=0;F<g.length;F++){let _=g.charCodeAt(F);_===58?(q?E!==-1?(f<b&&(h[f]=0),f<b-1&&(h[f+1]=0),f+=2):f<b&&(E=f):(k===!0?(f<b&&(h[f]=O),f++):(f<b&&(h[f]=x>>8),f<b-1&&(h[f+1]=x&255),f+=2),x=0,O=0),q=!0,k=!1):_===46?(f<b&&(h[f]=O),f++,O=0,x=0,q=!1,k=!0):(q=!1,_>=97?_-=87:_>=65?_-=55:(_-=48,O=O*10+_),x=(x<<4)+_)}if(q===!1)k===!0?(f<b&&(h[f]=O),f++):(f<b&&(h[f]=x>>8),f<b-1&&(h[f+1]=x&255),f+=2);else if(E===0)f<b&&(h[f]=0),f<b-1&&(h[f+1]=0),f+=2;else if(E!==-1){f+=2;for(let F=Math.min(f-1,b-1);F>=E+2;F--)h[F]=h[F-2];h[E]=0,h[E+1]=0,E=f}if(E!==f&&E!==-1)for(f>b-2&&(f=b-2);b>E;)h[--b]=f<b&&f>E?h[--f]:0;else for(;f<b;)h[f++]=0;return h},decode(g,h){h=~~h;let f="";for(let b=0;b<o;b+=2)b!==0&&(f+=":"),f+=(g[h+b]<<8|g[h+b+1]).toString(16);return f.replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}};t.v6=s;let a="ip";t.name=a;function c(g){if(i.isFormat(g))return i.size;if(s.isFormat(g))return s.size;throw Error(`Invalid ip address: ${g}`)}function u(g){return c(g)===i.size?1:2}function l(g,h,f){f=~~f;let b=c(g);return typeof h=="function"&&(h=h(f+b)),b===i.size?i.encode(g,h,f):s.encode(g,h,f)}function d(g,h,f){if(h=~~h,f=f||g.length-h,f===i.size)return i.decode(g,h,f);if(f===s.size)return s.decode(g,h,f);throw Error(`Invalid buffer size needs to be ${i.size} for v4 or ${s.size} for v6.`)}return"default"in t?t.default:t})({});typeof define=="function"&&define.amd?define([],function(){return Fi}):typeof Nn=="object"&&typeof ki=="object"&&(Nn.exports=Fi)});var qi=Oe(S=>{"use strict";var v=ge("buffer").Buffer,it=Ui(),va=_i(),Ba=Pi(),Fr=Ri(),Fn=Ni(),At=Ki(),Aa=0,Mi=32768,kn=32768,Ca=~kn,Hi=32768,Oa=~Hi,w=S.name={};w.encode=function(t,e,r,{mail:n=!1}={}){e||(e=v.alloc(w.encodingLength(t))),r||(r=0);let o=r,i=t.replace(/^\.|\.$/gm,"");if(i.length){let s=[];if(n){let a="";i.split(".").forEach(c=>{c.endsWith("\\")?a+=(a.length?".":"")+c.slice(0,-1):s.length===0&&a.length?s.push(a+"."+c):s.push(c)})}else s=i.split(".");for(let a=0;a<s.length;a++){let c=e.write(s[a],r+1);e[r]=c,r+=c+1}}return e[r++]=0,w.encode.bytes=r-o,e};w.encode.bytes=0;w.decode=function(t,e,{mail:r=!1}={}){e||(e=0);let n=[],o=e,i=0,s=0,a=!1;for(;;){if(e>=t.length)throw new Error("Cannot decode name (buffer overflow)");let c=t[e++];if(s+=a?0:1,c===0)break;if((c&192)===0){if(e+c>t.length)throw new Error("Cannot decode name (buffer overflow)");if(i+=c+1,i>254)throw new Error("Cannot decode name (name too long)");let u=t.toString("utf-8",e,e+c);r&&(u=u.replace(/\./g,"\\.")),n.push(u),e+=c,s+=a?0:c}else if((c&192)===192){if(e+1>t.length)throw new Error("Cannot decode name (buffer overflow)");let u=t.readUInt16BE(e-1)-49152;if(u>=o)throw new Error("Cannot decode name (bad pointer)");e=u,o=u,s+=a?0:1,a=!0}else throw new Error("Cannot decode name (bad label)")}return w.decode.bytes=s,n.length===0?".":n.join(".")};w.decode.bytes=0;w.encodingLength=function(t){return t==="."||t===".."?1:v.byteLength(t.replace(/^\.|\.$/gm,""))+2};var D={};D.encode=function(t,e,r){e||(e=v.alloc(D.encodingLength(t))),r||(r=0);let n=e.write(t,r+1);return e[r]=n,D.encode.bytes=n+1,e};D.encode.bytes=0;D.decode=function(t,e){e||(e=0);let r=t[e],n=t.toString("utf-8",e+1,e+1+r);return D.decode.bytes=r+1,n};D.decode.bytes=0;D.encodingLength=function(t){return v.byteLength(t)+1};var Ue={};Ue.encode=function(t,e,r){e||(e=Ue.encodingLength(t)),r||(r=0);let n=(t.flags||0)&32767,o=t.type==="response"?Mi:Aa;return e.writeUInt16BE(t.id||0,r),e.writeUInt16BE(n|o,r+2),e.writeUInt16BE(t.questions.length,r+4),e.writeUInt16BE(t.answers.length,r+6),e.writeUInt16BE(t.authorities.length,r+8),e.writeUInt16BE(t.additionals.length,r+10),e};Ue.encode.bytes=12;Ue.decode=function(t,e){if(e||(e=0),t.length<12)throw new Error("Header must be 12 bytes");let r=t.readUInt16BE(e+2);return{id:t.readUInt16BE(e),type:r&Mi?"response":"query",flags:r&32767,flag_qr:(r>>15&1)===1,opcode:Ba.toString(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:va.toString(r&15),questions:new Array(t.readUInt16BE(e+4)),answers:new Array(t.readUInt16BE(e+6)),authorities:new Array(t.readUInt16BE(e+8)),additionals:new Array(t.readUInt16BE(e+10))}};Ue.decode.bytes=12;Ue.encodingLength=function(){return 12};var Xe=S.unknown={};Xe.encode=function(t,e,r){return e||(e=v.alloc(Xe.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.length,r),t.copy(e,r+2),Xe.encode.bytes=t.length+2,e};Xe.encode.bytes=0;Xe.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=t.slice(e+2,e+2+r);return Xe.decode.bytes=r+2,n};Xe.decode.bytes=0;Xe.encodingLength=function(t){return t.length+2};var Ze=S.ns={};Ze.encode=function(t,e,r){return e||(e=v.alloc(Ze.encodingLength(t))),r||(r=0),w.encode(t,e,r+2),e.writeUInt16BE(w.encode.bytes,r),Ze.encode.bytes=w.encode.bytes+2,e};Ze.encode.bytes=0;Ze.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n=w.decode(t,e+2);return Ze.decode.bytes=r+2,n};Ze.decode.bytes=0;Ze.encodingLength=function(t){return w.encodingLength(t)+2};var Qe=S.soa={};Qe.encode=function(t,e,r){e||(e=v.alloc(Qe.encodingLength(t))),r||(r=0);let n=r;return r+=2,w.encode(t.mname,e,r),r+=w.encode.bytes,w.encode(t.rname,e,r,{mail:!0}),r+=w.encode.bytes,e.writeUInt32BE(t.serial||0,r),r+=4,e.writeUInt32BE(t.refresh||0,r),r+=4,e.writeUInt32BE(t.retry||0,r),r+=4,e.writeUInt32BE(t.expire||0,r),r+=4,e.writeUInt32BE(t.minimum||0,r),r+=4,e.writeUInt16BE(r-n-2,n),Qe.encode.bytes=r-n,e};Qe.encode.bytes=0;Qe.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mname=w.decode(t,e),e+=w.decode.bytes,n.rname=w.decode(t,e,{mail:!0}),e+=w.decode.bytes,n.serial=t.readUInt32BE(e),e+=4,n.refresh=t.readUInt32BE(e),e+=4,n.retry=t.readUInt32BE(e),e+=4,n.expire=t.readUInt32BE(e),e+=4,n.minimum=t.readUInt32BE(e),e+=4,Qe.decode.bytes=e-r,n};Qe.decode.bytes=0;Qe.encodingLength=function(t){return 22+w.encodingLength(t.mname)+w.encodingLength(t.rname)};var Je=S.txt={};Je.encode=function(t,e,r){Array.isArray(t)||(t=[t]);for(let o=0;o<t.length;o++)if(typeof t[o]=="string"&&(t[o]=v.from(t[o])),!v.isBuffer(t[o]))throw new Error("Must be a Buffer");e||(e=v.alloc(Je.encodingLength(t))),r||(r=0);let n=r;return r+=2,t.forEach(function(o){e[r++]=o.length,o.copy(e,r,0,o.length),r+=o.length}),e.writeUInt16BE(r-n-2,n),Je.encode.bytes=r-n,e};Je.encode.bytes=0;Je.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let o=[];for(;n>0;){let i=t[e++];if(--n,n<i)throw new Error("Buffer overflow");o.push(t.slice(e,e+i)),e+=i,n-=i}return Je.decode.bytes=e-r,o};Je.decode.bytes=0;Je.encodingLength=function(t){Array.isArray(t)||(t=[t]);let e=2;return t.forEach(function(r){typeof r=="string"?e+=v.byteLength(r)+1:e+=r.length+1}),e};var et=S.null={};et.encode=function(t,e,r){e||(e=v.alloc(et.encodingLength(t))),r||(r=0),typeof t=="string"&&(t=v.from(t)),t||(t=v.alloc(0));let n=r;r+=2;let o=t.length;return t.copy(e,r,0,o),r+=o,e.writeUInt16BE(r-n-2,n),et.encode.bytes=r-n,e};et.encode.bytes=0;et.decode=function(t,e){e||(e=0);let r=e,n=t.readUInt16BE(e);e+=2;let o=t.slice(e,e+n);return e+=n,et.decode.bytes=e-r,o};et.decode.bytes=0;et.encodingLength=function(t){return t?(v.isBuffer(t)?t.length:v.byteLength(t))+2:2};var tt=S.hinfo={};tt.encode=function(t,e,r){e||(e=v.alloc(tt.encodingLength(t))),r||(r=0);let n=r;return r+=2,D.encode(t.cpu,e,r),r+=D.encode.bytes,D.encode(t.os,e,r),r+=D.encode.bytes,e.writeUInt16BE(r-n-2,n),tt.encode.bytes=r-n,e};tt.encode.bytes=0;tt.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.cpu=D.decode(t,e),e+=D.decode.bytes,n.os=D.decode(t,e),e+=D.decode.bytes,tt.decode.bytes=e-r,n};tt.decode.bytes=0;tt.encodingLength=function(t){return D.encodingLength(t.cpu)+D.encodingLength(t.os)+2};var Le=S.ptr={},Ta=S.cname=Le,La=S.dname=Le;Le.encode=function(t,e,r){return e||(e=v.alloc(Le.encodingLength(t))),r||(r=0),w.encode(t,e,r+2),e.writeUInt16BE(w.encode.bytes,r),Le.encode.bytes=w.encode.bytes+2,e};Le.encode.bytes=0;Le.decode=function(t,e){e||(e=0);let r=w.decode(t,e+2);return Le.decode.bytes=w.decode.bytes+2,r};Le.decode.bytes=0;Le.encodingLength=function(t){return w.encodingLength(t)+2};var rt=S.srv={};rt.encode=function(t,e,r){e||(e=v.alloc(rt.encodingLength(t))),r||(r=0),e.writeUInt16BE(t.priority||0,r+2),e.writeUInt16BE(t.weight||0,r+4),e.writeUInt16BE(t.port||0,r+6),w.encode(t.target,e,r+8);let n=w.encode.bytes+6;return e.writeUInt16BE(n,r),rt.encode.bytes=n+2,e};rt.encode.bytes=0;rt.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e),n={};return n.priority=t.readUInt16BE(e+2),n.weight=t.readUInt16BE(e+4),n.port=t.readUInt16BE(e+6),n.target=w.decode(t,e+8),rt.decode.bytes=r+2,n};rt.decode.bytes=0;rt.encodingLength=function(t){return 8+w.encodingLength(t.target)};var ye=S.caa={};ye.ISSUER_CRITICAL=128;ye.encode=function(t,e,r){let n=ye.encodingLength(t);return e||(e=v.alloc(ye.encodingLength(t))),r||(r=0),t.issuerCritical&&(t.flags=ye.ISSUER_CRITICAL),e.writeUInt16BE(n-2,r),r+=2,e.writeUInt8(t.flags||0,r),r+=1,D.encode(t.tag,e,r),r+=D.encode.bytes,e.write(t.value,r),r+=v.byteLength(t.value),ye.encode.bytes=n,e};ye.encode.bytes=0;ye.decode=function(t,e){e||(e=0);let r=t.readUInt16BE(e);e+=2;let n=e,o={};return o.flags=t.readUInt8(e),e+=1,o.tag=D.decode(t,e),e+=D.decode.bytes,o.value=t.toString("utf-8",e,n+r),o.issuerCritical=!!(o.flags&ye.ISSUER_CRITICAL),ye.decode.bytes=r+2,o};ye.decode.bytes=0;ye.encodingLength=function(t){return D.encodingLength(t.tag)+D.encodingLength(t.value)+2};var pt=S.mx={};pt.encode=function(t,e,r){e||(e=v.alloc(pt.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,w.encode(t.exchange,e,r),r+=w.encode.bytes,e.writeUInt16BE(r-n-2,n),pt.encode.bytes=r-n,e};pt.encode.bytes=0;pt.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.preference=t.readUInt16BE(e),e+=2,n.exchange=w.decode(t,e),e+=w.decode.bytes,pt.decode.bytes=e-r,n};pt.encodingLength=function(t){return 4+w.encodingLength(t.exchange)};var nt=S.a={};nt.encode=function(t,e,r){return e||(e=v.alloc(nt.encodingLength(t))),r||(r=0),e.writeUInt16BE(4,r),r+=2,At.v4.encode(t,e,r),nt.encode.bytes=6,e};nt.encode.bytes=0;nt.decode=function(t,e){e||(e=0),e+=2;let r=At.v4.decode(t,e);return nt.decode.bytes=6,r};nt.decode.bytes=0;nt.encodingLength=function(){return 6};var ot=S.aaaa={};ot.encode=function(t,e,r){return e||(e=v.alloc(ot.encodingLength(t))),r||(r=0),e.writeUInt16BE(16,r),r+=2,At.v6.encode(t,e,r),ot.encode.bytes=18,e};ot.encode.bytes=0;ot.decode=function(t,e){e||(e=0),e+=2;let r=At.v6.decode(t,e);return ot.decode.bytes=18,r};ot.decode.bytes=0;ot.encodingLength=function(){return 18};var pe=S.option={};pe.encode=function(t,e,r){e||(e=v.alloc(pe.encodingLength(t))),r||(r=0);let n=r,o=Fn.toCode(t.code);if(e.writeUInt16BE(o,r),r+=2,t.data)e.writeUInt16BE(t.data.length,r),r+=2,t.data.copy(e,r),r+=t.data.length;else switch(o){case 8:let i=t.sourcePrefixLength||0,s=t.family||At.familyOf(t.ip),a=At.encode(t.ip,v.alloc),c=Math.ceil(i/8);e.writeUInt16BE(c+4,r),r+=2,e.writeUInt16BE(s,r),r+=2,e.writeUInt8(i,r++),e.writeUInt8(t.scopePrefixLength||0,r++),a.copy(e,r,0,c),r+=c;break;case 11:t.timeout?(e.writeUInt16BE(2,r),r+=2,e.writeUInt16BE(t.timeout,r),r+=2):(e.writeUInt16BE(0,r),r+=2);break;case 12:let u=t.length||0;e.writeUInt16BE(u,r),r+=2,e.fill(0,r,r+u),r+=u;break;case 14:let l=t.tags.length*2;e.writeUInt16BE(l,r),r+=2;for(let d of t.tags)e.writeUInt16BE(d,r),r+=2;break;default:throw new Error(`Unknown roption code: ${t.code}`)}return pe.encode.bytes=r-n,e};pe.encode.bytes=0;pe.decode=function(t,e){e||(e=0);let r={};r.code=t.readUInt16BE(e),r.type=Fn.toString(r.code),e+=2;let n=t.readUInt16BE(e);switch(e+=2,r.data=t.slice(e,e+n),r.code){case 8:r.family=t.readUInt16BE(e),e+=2,r.sourcePrefixLength=t.readUInt8(e++),r.scopePrefixLength=t.readUInt8(e++);let o=v.alloc(r.family===1?4:16);t.copy(o,0,e,e+n-4),r.ip=At.decode(o);break;case 11:n>0&&(r.timeout=t.readUInt16BE(e),e+=2);break;case 14:r.tags=[];for(let i=0;i<n;i+=2)r.tags.push(t.readUInt16BE(e)),e+=2}return pe.decode.bytes=n+4,r};pe.decode.bytes=0;pe.encodingLength=function(t){if(t.data)return t.data.length+4;switch(Fn.toCode(t.code)){case 8:let r=t.sourcePrefixLength||0;return Math.ceil(r/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}`)};var be=S.opt={};be.encode=function(t,e,r){e||(e=v.alloc(be.encodingLength(t))),r||(r=0);let n=r,o=Nt(t,pe);return e.writeUInt16BE(o,r),r=ir(t,pe,e,r+2),be.encode.bytes=r-n,e};be.encode.bytes=0;be.decode=function(t,e){e||(e=0);let r=e,n=[],o=t.readUInt16BE(e);e+=2;let i=0;for(;o>0;)n[i++]=pe.decode(t,e),e+=pe.decode.bytes,o-=pe.decode.bytes;return be.decode.bytes=e-r,n};be.decode.bytes=0;be.encodingLength=function(t){return 2+Nt(t||[],pe)};var ae=S.dnskey={};ae.PROTOCOL_DNSSEC=3;ae.ZONE_KEY=128;ae.SECURE_ENTRYPOINT=32768;ae.encode=function(t,e,r){e||(e=v.alloc(ae.encodingLength(t))),r||(r=0);let n=r,o=t.key;if(!v.isBuffer(o))throw new Error("Key must be a Buffer");return r+=2,e.writeUInt16BE(t.flags,r),r+=2,e.writeUInt8(ae.PROTOCOL_DNSSEC,r),r+=1,e.writeUInt8(t.algorithm,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,ae.encode.bytes=r-n,e.writeUInt16BE(ae.encode.bytes-2,n),e};ae.encode.bytes=0;ae.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);if(e+=2,n.flags=t.readUInt16BE(e),e+=2,t.readUInt8(e)!==ae.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return e+=1,n.algorithm=t.readUInt8(e),e+=1,n.key=t.slice(e,r+o+2),e+=n.key.length,ae.decode.bytes=e-r,n};ae.decode.bytes=0;ae.encodingLength=function(t){return 6+v.byteLength(t.key)};var Fe=S.rrsig={};Fe.encode=function(t,e,r){e||(e=v.alloc(Fe.encodingLength(t))),r||(r=0);let n=r,o=t.signature;if(!v.isBuffer(o))throw new Error("Signature must be a Buffer");return r+=2,e.writeUInt16BE(it.toType(t.typeCovered),r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.labels,r),r+=1,e.writeUInt32BE(t.originalTTL,r),r+=4,e.writeUInt32BE(t.expiration,r),r+=4,e.writeUInt32BE(t.inception,r),r+=4,e.writeUInt16BE(t.keyTag,r),r+=2,w.encode(t.signersName,e,r),r+=w.encode.bytes,o.copy(e,r,0,o.length),r+=o.length,Fe.encode.bytes=r-n,e.writeUInt16BE(Fe.encode.bytes-2,n),e};Fe.encode.bytes=0;Fe.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.typeCovered=it.toString(t.readUInt16BE(e)),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.labels=t.readUInt8(e),e+=1,n.originalTTL=t.readUInt32BE(e),e+=4,n.expiration=t.readUInt32BE(e),e+=4,n.inception=t.readUInt32BE(e),e+=4,n.keyTag=t.readUInt16BE(e),e+=2,n.signersName=w.decode(t,e),e+=w.decode.bytes,n.signature=t.slice(e,r+o+2),e+=n.signature.length,Fe.decode.bytes=e-r,n};Fe.decode.bytes=0;Fe.encodingLength=function(t){return 20+w.encodingLength(t.signersName)+v.byteLength(t.signature)};var ke=S.rp={};ke.encode=function(t,e,r){e||(e=v.alloc(ke.encodingLength(t))),r||(r=0);let n=r;return r+=2,w.encode(t.mbox||".",e,r,{mail:!0}),r+=w.encode.bytes,w.encode(t.txt||".",e,r),r+=w.encode.bytes,ke.encode.bytes=r-n,e.writeUInt16BE(ke.encode.bytes-2,n),e};ke.encode.bytes=0;ke.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.mbox=w.decode(t,e,{mail:!0})||".",e+=w.decode.bytes,n.txt=w.decode(t,e)||".",e+=w.decode.bytes,ke.decode.bytes=e-r,n};ke.decode.bytes=0;ke.encodingLength=function(t){return 2+w.encodingLength(t.mbox||".")+w.encodingLength(t.txt||".")};var J={};J.encode=function(t,e,r){e||(e=v.alloc(J.encodingLength(t))),r||(r=0);let n=r;for(var o=[],i=0;i<t.length;i++){var s=it.toType(t[i]);o[s>>8]===void 0&&(o[s>>8]=[]),o[s>>8][s>>3&31]|=1<<7-(s&7)}for(i=0;i<o.length;i++)if(o[i]!==void 0){var a=v.from(o[i]);e.writeUInt8(i,r),r+=1,e.writeUInt8(a.length,r),r+=1,a.copy(e,r),r+=a.length}return J.encode.bytes=r-n,e};J.encode.bytes=0;J.decode=function(t,e,r){e||(e=0);let n=e;for(var o=[];e-n<r;){var i=t.readUInt8(e);e+=1;var s=t.readUInt8(e);e+=1;for(var a=0;a<s;a++)for(var c=t.readUInt8(e+a),u=0;u<8;u++)if(c&1<<7-u){var l=it.toString(i<<8|a<<3|u);o.push(l)}e+=s}return J.decode.bytes=e-n,o};J.decode.bytes=0;J.encodingLength=function(t){for(var e=[],r=0;r<t.length;r++){var n=it.toType(t[r]);e[n>>8]=Math.max(e[n>>8]||0,n&255)}var o=0;for(r=0;r<e.length;r++)e[r]!==void 0&&(o+=2+Math.ceil((e[r]+1)/8));return o};var Ke=S.nsec={};Ke.encode=function(t,e,r){e||(e=v.alloc(Ke.encodingLength(t))),r||(r=0);let n=r;return r+=2,w.encode(t.nextDomain,e,r),r+=w.encode.bytes,J.encode(t.rrtypes,e,r),r+=J.encode.bytes,Ke.encode.bytes=r-n,e.writeUInt16BE(Ke.encode.bytes-2,n),e};Ke.encode.bytes=0;Ke.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.nextDomain=w.decode(t,e),e+=w.decode.bytes,n.rrtypes=J.decode(t,e,o-(e-r)),e+=J.decode.bytes,Ke.decode.bytes=e-r,n};Ke.decode.bytes=0;Ke.encodingLength=function(t){return 2+w.encodingLength(t.nextDomain)+J.encodingLength(t.rrtypes)};var Me=S.nsec3={};Me.encode=function(t,e,r){e||(e=v.alloc(Me.encodingLength(t))),r||(r=0);let n=r,o=t.salt;if(!v.isBuffer(o))throw new Error("salt must be a Buffer");let i=t.nextDomain;if(!v.isBuffer(i))throw new Error("nextDomain must be a Buffer");return r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.flags,r),r+=1,e.writeUInt16BE(t.iterations,r),r+=2,e.writeUInt8(o.length,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,e.writeUInt8(i.length,r),r+=1,i.copy(e,r,0,i.length),r+=i.length,J.encode(t.rrtypes,e,r),r+=J.encode.bytes,Me.encode.bytes=r-n,e.writeUInt16BE(Me.encode.bytes-2,n),e};Me.encode.bytes=0;Me.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);e+=2,n.algorithm=t.readUInt8(e),e+=1,n.flags=t.readUInt8(e),e+=1,n.iterations=t.readUInt16BE(e),e+=2;let i=t.readUInt8(e);e+=1,n.salt=t.slice(e,e+i),e+=i;let s=t.readUInt8(e);return e+=1,n.nextDomain=t.slice(e,e+s),e+=s,n.rrtypes=J.decode(t,e,o-(e-r)),e+=J.decode.bytes,Me.decode.bytes=e-r,n};Me.decode.bytes=0;Me.encodingLength=function(t){return 8+t.salt.length+t.nextDomain.length+J.encodingLength(t.rrtypes)};var He=S.ds={};He.encode=function(t,e,r){e||(e=v.alloc(He.encodingLength(t))),r||(r=0);let n=r,o=t.digest;if(!v.isBuffer(o))throw new Error("Digest must be a Buffer");return r+=2,e.writeUInt16BE(t.keyTag,r),r+=2,e.writeUInt8(t.algorithm,r),r+=1,e.writeUInt8(t.digestType,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,He.encode.bytes=r-n,e.writeUInt16BE(He.encode.bytes-2,n),e};He.encode.bytes=0;He.decode=function(t,e){e||(e=0);let r=e;var n={},o=t.readUInt16BE(e);return e+=2,n.keyTag=t.readUInt16BE(e),e+=2,n.algorithm=t.readUInt8(e),e+=1,n.digestType=t.readUInt8(e),e+=1,n.digest=t.slice(e,r+o+2),e+=n.digest.length,He.decode.bytes=e-r,n};He.decode.bytes=0;He.encodingLength=function(t){return 6+v.byteLength(t.digest)};var we=S.sshfp={};we.getFingerprintLengthForHashType=function(e){switch(e){case 1:return 20;case 2:return 32}};we.encode=function(e,r,n){r||(r=v.alloc(we.encodingLength(e))),n||(n=0);let o=n;n+=2,r[n]=e.algorithm,n+=1,r[n]=e.hash,n+=1;let i=v.from(e.fingerprint.toUpperCase(),"hex");if(i.length!==we.getFingerprintLengthForHashType(e.hash))throw new Error("Invalid fingerprint length");return i.copy(r,n),n+=i.byteLength,we.encode.bytes=n-o,r.writeUInt16BE(we.encode.bytes-2,o),r};we.encode.bytes=0;we.decode=function(e,r){r||(r=0);let n=r,o={};r+=2,o.algorithm=e[r],r+=1,o.hash=e[r],r+=1;let i=we.getFingerprintLengthForHashType(o.hash);return o.fingerprint=e.slice(r,r+i).toString("hex").toUpperCase(),r+=i,we.decode.bytes=r-n,o};we.decode.bytes=0;we.encodingLength=function(t){return 4+v.from(t.fingerprint,"hex").byteLength};var qe=S.naptr={};qe.encode=function(t,e,r){e||(e=v.alloc(qe.encodingLength(t))),r||(r=0);let n=r;return r+=2,e.writeUInt16BE(t.order||0,r),r+=2,e.writeUInt16BE(t.preference||0,r),r+=2,D.encode(t.flags,e,r),r+=D.encode.bytes,D.encode(t.services,e,r),r+=D.encode.bytes,D.encode(t.regexp,e,r),r+=D.encode.bytes,w.encode(t.replacement,e,r),r+=w.encode.bytes,qe.encode.bytes=r-n,e.writeUInt16BE(qe.encode.bytes-2,n),e};qe.encode.bytes=0;qe.decode=function(t,e){e||(e=0);let r=e,n={};return e+=2,n.order=t.readUInt16BE(e),e+=2,n.preference=t.readUInt16BE(e),e+=2,n.flags=D.decode(t,e),e+=D.decode.bytes,n.services=D.decode(t,e),e+=D.decode.bytes,n.regexp=D.decode(t,e),e+=D.decode.bytes,n.replacement=w.decode(t,e),e+=w.decode.bytes,qe.decode.bytes=e-r,n};qe.decode.bytes=0;qe.encodingLength=function(t){return D.encodingLength(t.flags)+D.encodingLength(t.services)+D.encodingLength(t.regexp)+w.encodingLength(t.replacement)+6};var ze=S.tlsa={};ze.encode=function(t,e,r){e||(e=v.alloc(ze.encodingLength(t))),r||(r=0);let n=r,o=t.certificate;if(!v.isBuffer(o))throw new Error("Certificate must be a Buffer");return r+=2,e.writeUInt8(t.usage,r),r+=1,e.writeUInt8(t.selector,r),r+=1,e.writeUInt8(t.matchingType,r),r+=1,o.copy(e,r,0,o.length),r+=o.length,ze.encode.bytes=r-n,e.writeUInt16BE(ze.encode.bytes-2,n),e};ze.encode.bytes=0;ze.decode=function(t,e){e||(e=0);let r=e,n={},o=t.readUInt16BE(e);return e+=2,n.usage=t.readUInt8(e),e+=1,n.selector=t.readUInt8(e),e+=1,n.matchingType=t.readUInt8(e),e+=1,n.certificate=t.slice(e,r+o+2),e+=n.certificate.length,ze.decode.bytes=e-r,n};ze.decode.bytes=0;ze.encodingLength=function(t){return 5+v.byteLength(t.certificate)};var Kn=S.record=function(t){switch(t.toUpperCase()){case"A":return nt;case"PTR":return Le;case"CNAME":return Ta;case"DNAME":return La;case"TXT":return Je;case"NULL":return et;case"AAAA":return ot;case"SRV":return rt;case"HINFO":return tt;case"CAA":return ye;case"NS":return Ze;case"SOA":return Qe;case"MX":return pt;case"OPT":return be;case"DNSKEY":return ae;case"RRSIG":return Fe;case"RP":return ke;case"NSEC":return Ke;case"NSEC3":return Me;case"SSHFP":return we;case"DS":return He;case"NAPTR":return qe;case"TLSA":return ze}return Xe},te=S.answer={};te.encode=function(t,e,r){e||(e=v.alloc(te.encodingLength(t))),r||(r=0);let n=r;if(w.encode(t.name,e,r),r+=w.encode.bytes,e.writeUInt16BE(it.toType(t.type),r),t.type.toUpperCase()==="OPT"){if(t.name!==".")throw new Error("OPT name must be root.");e.writeUInt16BE(t.udpPayloadSize||4096,r+2),e.writeUInt8(t.extendedRcode||0,r+4),e.writeUInt8(t.ednsVersion||0,r+5),e.writeUInt16BE(t.flags||0,r+6),r+=8,be.encode(t.options||[],e,r),r+=be.encode.bytes}else{let o=Fr.toClass(t.class===void 0?"IN":t.class);t.flush&&(o|=kn),e.writeUInt16BE(o,r+2),e.writeUInt32BE(t.ttl||0,r+4),r+=8;let i=Kn(t.type);i.encode(t.data,e,r),r+=i.encode.bytes}return te.encode.bytes=r-n,e};te.encode.bytes=0;te.decode=function(t,e){e||(e=0);let r={},n=e;if(r.name=w.decode(t,e),e+=w.decode.bytes,r.type=it.toString(t.readUInt16BE(e)),r.type==="OPT")r.udpPayloadSize=t.readUInt16BE(e+2),r.extendedRcode=t.readUInt8(e+4),r.ednsVersion=t.readUInt8(e+5),r.flags=t.readUInt16BE(e+6),r.flag_do=(r.flags>>15&1)===1,r.options=be.decode(t,e+8),e+=8+be.decode.bytes;else{let o=t.readUInt16BE(e+2);r.ttl=t.readUInt32BE(e+4),r.class=Fr.toString(o&Ca),r.flush=!!(o&kn);let i=Kn(r.type);r.data=i.decode(t,e+8),e+=8+i.decode.bytes}return te.decode.bytes=e-n,r};te.decode.bytes=0;te.encodingLength=function(t){let e=t.data!==null&&t.data!==void 0?t.data:t.options;return w.encodingLength(t.name)+8+Kn(t.type).encodingLength(e)};var De=S.question={};De.encode=function(t,e,r){e||(e=v.alloc(De.encodingLength(t))),r||(r=0);let n=r;return w.encode(t.name,e,r),r+=w.encode.bytes,e.writeUInt16BE(it.toType(t.type),r),r+=2,e.writeUInt16BE(Fr.toClass(t.class===void 0?"IN":t.class),r),r+=2,De.encode.bytes=r-n,t};De.encode.bytes=0;De.decode=function(t,e){e||(e=0);let r=e,n={};return n.name=w.decode(t,e),e+=w.decode.bytes,n.type=it.toString(t.readUInt16BE(e)),e+=2,n.class=Fr.toString(t.readUInt16BE(e)),e+=2,n.class&Hi&&(n.class&=Oa),De.decode.bytes=e-r,n};De.decode.bytes=0;De.encodingLength=function(t){return w.encodingLength(t.name)+4};S.AUTHORITATIVE_ANSWER=1024;S.TRUNCATED_RESPONSE=512;S.RECURSION_DESIRED=256;S.RECURSION_AVAILABLE=128;S.AUTHENTIC_DATA=32;S.CHECKING_DISABLED=16;S.DNSSEC_OK=32768;S.encode=function(t,e,r){let n=!e;n&&(e=v.alloc(S.encodingLength(t))),r||(r=0);let o=r;return t.questions||(t.questions=[]),t.answers||(t.answers=[]),t.authorities||(t.authorities=[]),t.additionals||(t.additionals=[]),Ue.encode(t,e,r),r+=Ue.encode.bytes,r=ir(t.questions,De,e,r),r=ir(t.answers,te,e,r),r=ir(t.authorities,te,e,r),r=ir(t.additionals,te,e,r),S.encode.bytes=r-o,n&&S.encode.bytes!==e.length?e.slice(0,S.encode.bytes):e};S.encode.bytes=0;S.decode=function(t,e){e||(e=0);let r=e,n=Ue.decode(t,e);return e+=Ue.decode.bytes,e=Nr(n.questions,De,t,e),e=Nr(n.answers,te,t,e),e=Nr(n.authorities,te,t,e),e=Nr(n.additionals,te,t,e),S.decode.bytes=e-r,n};S.decode.bytes=0;S.encodingLength=function(t){return Ue.encodingLength(t)+Nt(t.questions||[],De)+Nt(t.answers||[],te)+Nt(t.authorities||[],te)+Nt(t.additionals||[],te)};S.streamEncode=function(t){let e=S.encode(t),r=v.alloc(2);r.writeUInt16BE(e.byteLength);let n=v.concat([r,e]);return S.streamEncode.bytes=n.byteLength,n};S.streamEncode.bytes=0;S.streamDecode=function(t){let e=t.readUInt16BE(0);if(t.byteLength<e+2)return null;let r=S.decode(t.slice(2));return S.streamDecode.bytes=S.decode.bytes,r};S.streamDecode.bytes=0;function Nt(t,e){let r=0;for(let n=0;n<t.length;n++)r+=e.encodingLength(t[n]);return r}function ir(t,e,r,n){for(let o=0;o<t.length;o++)e.encode(t[o],r,n),n+=e.encode.bytes;return n}function Nr(t,e,r,n){for(let o=0;o<t.length;o++)t[o]=e.decode(r,n),n+=e.decode.bytes;return n}});var ji=Oe((up,$i)=>{"use strict";var zi=Na;process.nextTick(Ra,42);$i.exports=Da;function Da(t){var e=n;return r;function r(o){e(o||_a)}function n(o){var i=[o];e=s,t(a);function s(c){i.push(c)}function a(c){var u=arguments;for(e=Ua(c)?n:l;i.length;)l(i.shift());function l(d){zi(Pa,d,u)}}}}function Ua(t){return Object.prototype.toString.call(t)==="[object Error]"}function _a(){}function Pa(t,e){t.apply(null,e)}function Ra(t){t===42&&(zi=process.nextTick)}function Na(t,e,r){process.nextTick(function(){t(e,r)})}});var Gi=Oe((dp,Yi)=>{var Mn=qi(),Fa=ge("dgram"),ka=ji(),Ka=ge("events"),qn=ge("os"),Hn=function(){};Yi.exports=function(t){t||(t={});var e=new Ka.EventEmitter,r=typeof t.port=="number"?t.port:5353,n=t.type||"udp4",o=t.ip||t.host||(n==="udp4"?"224.0.0.251":null),i={address:o,port:r},s={},a=!1,c=null;if(n==="udp6"&&(!o||!t.interface))throw new Error("For IPv6 multicast you must specify `ip` and `interface`");var u=t.socket||Fa.createSocket({type:n,reuseAddr:t.reuseAddr!==!1,toString:function(){return n}});u.on("error",function(d){d.code==="EACCES"||d.code==="EADDRINUSE"?e.emit("error",d):e.emit("warning",d)}),u.on("message",function(d,g){try{d=Mn.decode(d)}catch(h){e.emit("warning",h);return}e.emit("packet",d,g),d.type==="query"&&e.emit("query",d,g),d.type==="response"&&e.emit("response",d,g)}),u.on("listening",function(){r||(r=i.port=u.address().port),t.multicast!==!1&&(e.update(),c=setInterval(e.update,5e3),u.setMulticastTTL(t.ttl||255),u.setMulticastLoopback(t.loopback!==!1))});var l=ka(function(d){if(!r||t.bind===!1)return d(null);u.once("error",d),u.bind(r,t.bind||t.interface,function(){u.removeListener("error",d),d(null)})});return l(function(d){if(d)return e.emit("error",d);e.emit("ready")}),e.send=function(d,g,h){if(typeof g=="function")return e.send(d,null,g);h||(h=Hn),g?!g.host&&!g.address&&(g.address=i.address):g=i,l(f);function f(b){if(a)return h();if(b)return h(b);var E=Mn.encode(d);u.send(E,0,E.length,g.port,g.address||g.host,h)}},e.response=e.respond=function(d,g,h){Array.isArray(d)&&(d={answers:d}),d.type="response",d.flags=(d.flags||0)|Mn.AUTHORITATIVE_ANSWER,e.send(d,g,h)},e.query=function(d,g,h,f){if(typeof g=="function")return e.query(d,null,null,g);if(typeof g=="object"&&g&&g.port)return e.query(d,null,g,h);if(typeof h=="function")return e.query(d,g,null,h);f||(f=Hn),typeof d=="string"&&(d=[{name:d,type:g||"ANY"}]),Array.isArray(d)&&(d={type:"query",questions:d}),d.type="query",e.send(d,h,f)},e.destroy=function(d){if(d||(d=Hn),a)return process.nextTick(d);a=!0,clearInterval(c);for(var g in s)try{u.dropMembership(o,g)}catch{}s={},u.close(d)},e.update=function(){for(var d=t.interface?[].concat(t.interface):Ha(),g=!1,h=0;h<d.length;h++){var f=d[h];if(!s[f])try{u.addMembership(o,f),s[f]=!0,g=!0}catch(b){e.emit("warning",b)}}if(g){if(u.setMulticastInterface)try{u.setMulticastInterface(t.interface||Ma())}catch(b){e.emit("warning",b)}e.emit("networkInterface")}},e};function Ma(){for(var t=qn.networkInterfaces(),e=Object.keys(t),r=0;r<e.length;r++)for(var n=t[e[r]],o=0;o<n.length;o++){var i=n[o];if(Vi(i.family)&&!i.internal)return qn.platform()==="darwin"&&e[r]==="en0"?i.address:"0.0.0.0"}return"127.0.0.1"}function Ha(){for(var t=qn.networkInterfaces(),e=Object.keys(t),r=[],n=0;n<e.length;n++)for(var o=t[e[n]],i=0;i<o.length;i++){var s=o[i];if(Vi(s.family)){r.push(s.address);break}}return r}function Vi(t){return t===4||t==="IPv4"}});var hi=Oe(Qt=>{"use strict";Object.defineProperty(Qt,"__esModule",{value:!0});Qt.Netmask4Impl=void 0;Qt.ip2long=Zt;Qt.long2ip=We;function We(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var pl=48,fl=97,gl=65;function ml(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let i=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-pl)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-fl)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-gl)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===i)throw new Error("empty octet");return[e,o]}function Zt(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=ml(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var li=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Zt(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Zt(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=We(this.netLong),this.mask=We(this.maskLong),this.hostmask=We(~this.maskLong),this.first=this.bitmask<=30?We(this.netLong+1):this.base,this.last=this.bitmask<=30?We(this.netLong+this.size-2):We(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?We(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(Zt(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(We(this.netLong+this.size*e),this.mask)}forEach(e){let r=Zt(this.first),n=Zt(this.last),o=0;for(;r<=n;)e(We(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Qt.Netmask4Impl=li});var qc=Oe(Jt=>{"use strict";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.Netmask6Impl=void 0;Jt.ip6bigint=fi;Jt.bigint2ip6=_t;var yl=hi(),pi=(1n<<128n)-1n;function fi(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,yl.ip2long)(n),i=t.substring(0,r+1)+"0:0";return Hc(i)&~0xffffffffn|BigInt(o)}return Hc(t)}function Hc(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),i=t.substring(e+2),s=o===""?[]:o.split(":"),a=i===""?[]:i.split(":"),c=8-s.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...s,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let i=r[o];if(i.length===0||i.length>4)throw new Error('Invalid IPv6: bad group "'+i+'"');let s=parseInt(i,16);if(isNaN(s)||s<0||s>65535)throw new Error('Invalid IPv6: bad group "'+i+'"');n=n<<16n|BigInt(s)}return n}function _t(t){if(t<0n||t>pi)throw new Error("Invalid IPv6 address value");let e=[];for(let s=0;s<8;s++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,i=0;for(let s=0;s<8;s++)e[s]===0?o===-1?(o=s,i=1):i++:(i>n&&i>=2&&(r=o,n=i),o=-1,i=0);if(i>n&&i>=2&&(r=o,n=i),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let s=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return s.join(":")+"::"+a.join(":")}else return e.map(s=>s.toString(16)).join(":")}var gi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=pi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=fi(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=_t(this.netBigint),this.mask=_t(this.maskBigint),this.hostmask=_t(~this.maskBigint&pi),this.first=this.base,this.last=_t(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(fi(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(_t(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,i=0;for(;r<=o;)e(_t(r),Number(r),i),i++,r++}toString(){return this.base+"/"+this.bitmask}};Jt.Netmask6Impl=gi});var zc=Oe(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.long2ip=vt.ip2long=vt.Netmask=void 0;var Sn=hi();Object.defineProperty(vt,"ip2long",{enumerable:!0,get:function(){return Sn.ip2long}});Object.defineProperty(vt,"long2ip",{enumerable:!0,get:function(){return Sn.long2ip}});var wl=qc(),mi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new wl.Netmask6Impl(e,r):this._impl=new Sn.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Sn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};vt.Netmask=mi});var vh={};me(vh,{mdns:()=>Sh});var Te=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ur=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var _r=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Pr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var or=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Ci=Symbol.for("@libp2p/peer-discovery");var Tn=Symbol.for("@libp2p/peer-id");var Oi=ge("node:events"),Ti=(t,...e)=>{try{(0,Oi.setMaxListeners)(t,...e)}catch{}};function Ea(t){return typeof t?.handleEvent=="function"}function Ia(t){return t===!0||t===!1}function Sa(t){return Ia(t)?t:t?.capture??!1}function Ln(t){let e={capture:Sa(t),once:!!t?.once};return t?.passive!=null&&(e.passive=t?.passive),t?.signal!=null&&(e.signal=t?.signal),e}function Li(t,e){return Ln(t).capture===Ln(e).capture}var Rr=class extends EventTarget{#e=new Map;constructor(){super(),Ti(1/0,this)}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let o=Ln(n);if(o?.signal?.aborted===!0)return;let i=u=>{o.once&&this.removeEventListener(e,r,o),Ea(r)?r.handleEvent(u):r(u)},s=this.#e.get(e);if(s==null&&(s=[],this.#e.set(e,s)),s.some(u=>u.callback!==r?!1:Li(u.options,o)))return;super.addEventListener(e,i,o);let c=()=>{this.removeEventListener(e,r,o)};o.signal?.addEventListener("abort",c),s.push({callback:r,wrapper:i,options:o,onAbort:c})}removeEventListener(e,r,n){let o=this.#e.get(e);if(o==null){super.removeEventListener(e,r??null,n);return}this.#e.set(e,o.filter(i=>i.callback===r&&Li(i.options,n)?(super.removeEventListener(e,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Di=Symbol.for("@libp2p/service-capabilities");var la=nr(Gi(),1);var Yn={};me(Yn,{base58btc:()=>W,base58flickr:()=>Wa});var lp=new Uint8Array(0);function Xi(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}function ue(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ct(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ct(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function Zi(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var Wi=4096;function Qi(t){let e=t.length;if(e<=Wi)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=Wi));return r}function qa(t){return t?.buffer instanceof ArrayBuffer}function Ct(t){return qa(t)?t:t.slice()}function za(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),a=s.charCodeAt(0);if(n[a]!==255)throw new TypeError(s+" is ambiguous");if(n[a]=i,r){var c=s.toLowerCase().charCodeAt(0),u=s.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var l=t.length,d=t.charAt(0),g=Math.log(l)/Math.log(256),h=Math.log(256)/Math.log(l);function f(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var O=0,q=0,k=0,F=x.length;k!==F&&x[k]===0;)k++,O++;for(var _=(F-k)*h+1>>>0,$=new Uint8Array(_);k!==F;){for(var oe=x[k],ce=0,K=_-1;(oe!==0||ce<q)&&K!==-1;K--,ce++)oe+=256*$[K]>>>0,$[K]=oe%l>>>0,oe=oe/l>>>0;if(oe!==0)throw new Error("Non-zero carry");q=ce,k++}for(var he=_-q;he!==_&&$[he]===0;)he++;for(var Ae=d.repeat(O);he<_;++he)Ae+=t.charAt($[he]);return Ae}function b(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var O=0;if(x[O]!==" "){for(var q=0,k=0;x[O]===d;)q++,O++;for(var F=(x.length-O)*g+1>>>0,_=new Uint8Array(F);x[O];){var $=n[x.charCodeAt(O)];if($===255)return;for(var oe=0,ce=F-1;($!==0||oe<k)&&ce!==-1;ce--,oe++)$+=l*_[ce]>>>0,_[ce]=$%256>>>0,$=$/256>>>0;if($!==0)throw new Error("Non-zero carry");k=oe,O++}if(x[O]!==" "){for(var K=F-k;K!==F&&_[K]===0;)K++;for(var he=new Uint8Array(q+(F-K)),Ae=q;K!==F;)he[Ae++]=_[K++];return he}}}function E(x){var O=b(x);if(O)return O;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:b,decode:E}}var $a=za,ja=$a,es=ja;var zn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},$n=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ts(this,e)}},jn=class{decoders;constructor(e){this.decoders=e}or(e){return ts(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ts(t,e){return new jn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new zn(e,r,n),this.decoder=new $n(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ft({name:t,prefix:e,encode:r,decode:n}){return new Vn(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:i}=es(r,t,n);return Ft({prefix:e,name:t,encode:o,decode:s=>ue(i(s))})}function Va(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,s+=r,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ya(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ga(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),i=t[n].toUpperCase();o!==t[n]&&(r[o]=n),i!==t[n]&&(r[i]=n)}return r}function j({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let i=Ga(n,o);return Ft({prefix:e,name:t,encode(s){return Ya(s,n,r)},decode(s){return Va(s,i,r,t)}})}var W=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wa=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Gn={};me(Gn,{base32:()=>gt,base32hex:()=>Ja,base32hexpad:()=>tu,base32hexpadupper:()=>ru,base32hexupper:()=>eu,base32pad:()=>Za,base32padupper:()=>Qa,base32upper:()=>Xa,base32z:()=>nu});var gt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Xa=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Za=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Qa=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Ja=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),eu=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),tu=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),ru=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),nu=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Wn={};me(Wn,{base36:()=>sr,base36upper:()=>ou});var sr=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),ou=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var iu=os,rs=128,su=127,cu=~su,au=Math.pow(2,31);function os(t,e,r){e=e||[],r=r||0;for(var n=r;t>=au;)e[r++]=t&255|rs,t/=128;for(;t&cu;)e[r++]=t&255|rs,t>>>=7;return e[r]=t|0,os.bytes=r-n+1,e}var uu=Xn,du=128,ns=127;function Xn(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw Xn.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&ns)<<o:(s&ns)*Math.pow(2,o),o+=7}while(s>=du);return Xn.bytes=i-n,r}var lu=Math.pow(2,7),hu=Math.pow(2,14),pu=Math.pow(2,21),fu=Math.pow(2,28),gu=Math.pow(2,35),mu=Math.pow(2,42),yu=Math.pow(2,49),wu=Math.pow(2,56),bu=Math.pow(2,63),xu=function(t){return t<lu?1:t<hu?2:t<pu?3:t<fu?4:t<gu?5:t<mu?6:t<yu?7:t<wu?8:t<bu?9:10},Eu={encode:iu,decode:uu,encodingLength:xu},Iu=Eu,cr=Iu;function ar(t,e=0){let r=cr.decode(t,e),n=cr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function kt(t,e,r=0){return cr.encode(t,e,r),e}function Kt(t){return cr.encodingLength(t)}function Ht(t,e){let r=e.byteLength,n=Kt(t),o=n+Kt(r),i=new Uint8Array(o+r);return kt(t,i,0),kt(r,i,n),i.set(e,o),new Mt(t,r,e,i)}function ur(t){let e=ue(t),[r,n]=ar(e),[o,i]=ar(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Mt(r,o,s,e)}function is(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Xi(t.bytes,r.bytes)}}var Mt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ct(n),this.bytes=Ct(o)}};function ss(t,e){let{bytes:r,version:n}=t;return n===0?vu(r,Zn(t),e??W.encoder):Bu(r,Zn(t),e??gt.encoder)}var cs=new WeakMap;function Zn(t){let e=cs.get(t);if(e==null){let r=new Map;return cs.set(t,r),r}return e}var re=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ct(o),this["/"]=this.bytes}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!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Au)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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=Ht(e,r);return t.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 t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&is(e.multihash,n.multihash)}toString(e){return ss(this,e)}toJSON(){return{"/":ss(this)}}link(){return this}[Symbol.toStringTag]="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 t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??as(n,o,i.bytes))}else if(r[Cu]===!0){let{version:n,multihash:o,code:i}=r,s=ur(o);return t.create(n,i,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!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=as(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,dr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=ue(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new Mt(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[d,g]=ar(e.subarray(r));return r+=g,d},o=n(),i=dr;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=Su(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Zn(i).set(n,e),i}};function Su(t,e){switch(t[0]){case"Q":{let r=e??W;return[W.prefix,r.decode(`${W.prefix}${t}`)]}case W.prefix:{let r=e??W;return[W.prefix,r.decode(t)]}case gt.prefix:{let r=e??gt;return[gt.prefix,r.decode(t)]}case sr.prefix:{let r=e??sr;return[sr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function vu(t,e,r){let{prefix:n}=r;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Bu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var dr=112,Au=18;function as(t,e,r){let n=Kt(t),o=n+Kt(e),i=new Uint8Array(o+r.byteLength);return kt(t,i,0),kt(e,i,n),i.set(r,o),i}var Cu=Symbol.for("@ipld/js-cid/CID");var Qn={};me(Qn,{identity:()=>_e});var us=0,Ou="identity",ds=ue;function Tu(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Ht(us,ds(t))}var _e={code:us,name:Ou,encode:ds,digest:Tu};function fe(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}function Lu(t){return t.buffer instanceof ArrayBuffer}function mt(t){return Lu(t)?t:t.slice()}async function ls(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,mt(e),mt(r.subarray()));return n?.signal?.throwIfAborted(),i}var Jn=ge("node:buffer");function yt(t){if(t.buffer instanceof ArrayBuffer)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function $e(t=0){return yt(Jn.Buffer.alloc(t))}function xe(t=0){return yt(Jn.Buffer.allocUnsafe(t))}var hs=ge("node:buffer");function Pe(t,e){return yt(hs.Buffer.concat(t,e))}var fs=Symbol.for("@achingbrain/uint8arraylist");function ps(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function Kr(t){return!!t?.[fs]}var Ee=class t{bufs;length;[fs]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Kr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Kr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=ps(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ps(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Kr(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Pe(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Pe(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),i=new t;return i.length=o,i.bufs=n,i}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let i=0;i<this.bufs.length;i++){let s=this.bufs[i],a=o,c=a+s.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(s);break}let d=e-a;n.push(s.subarray(d,d+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Kr(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let i=256,s=new Int32Array(i);for(let d=0;d<i;d++)s[d]=-1;for(let d=0;d<o;d++)s[n[d]]=d;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let d=r;d<=c;d+=l){l=0;for(let g=u;g>=0;g--){let h=this.get(d+g);if(n[g]!==h){l=Math.max(1,g-a[h]);break}}if(l===0)return d}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=xe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=$e(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=xe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=$e(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=$e(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=$e(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!fe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,i)=>o+i.byteLength,0)),n.length=r,n}};var xs=ge("node:buffer");var eo={};me(eo,{base10:()=>Du});var Du=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};me(to,{base16:()=>Uu,base16upper:()=>_u});var Uu=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),_u=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var ro={};me(ro,{base2:()=>Pu});var Pu=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var no={};me(no,{base256emoji:()=>Ku});var gs=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ru=gs.reduce((t,e,r)=>(t[r]=e,t),[]),Nu=gs.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Fu(t){return t.reduce((e,r)=>(e+=Ru[r],e),"")}function ku(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Nu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Ku=Ft({prefix:"\u{1F680}",name:"base256emoji",encode:Fu,decode:ku});var io={};me(io,{base64:()=>Mu,base64pad:()=>Hu,base64url:()=>oo,base64urlpad:()=>qu});var Mu=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Hu=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),oo=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),qu=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};me(so,{base8:()=>zu});var zu=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var co={};me(co,{identity:()=>$u});var $u=Ft({prefix:"\0",name:"identity",encode:t=>Qi(ue(t)),decode:t=>ue(Zi(t))});var Xp=new TextEncoder,Zp=new TextDecoder;var po={};me(po,{sha256:()=>ho,sha512:()=>Gu});var lo=nr(ge("node:crypto"),1);var Yu=20;function uo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ao(t,e,r,n,o)}var ao=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Yu,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ms(n,this.code,r?.truncate):n.then(o=>ms(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ms(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Ht(e,t)}var ho=uo({name:"sha2-256",code:18,encode:t=>ue(lo.default.createHash("sha256").update(t).digest())}),Gu=uo({name:"sha2-512",code:19,encode:t=>ue(lo.default.createHash("sha512").update(t).digest())});var lr={...co,...ro,...so,...eo,...to,...Gn,...Wn,...Yn,...io,...no},d0={...po,...Qn};function bs(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ws=bs("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),fo=bs("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=xe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Wu={utf8:ws,"utf-8":ws,hex:lr.base16,latin1:fo,ascii:fo,binary:fo,...lr},Mr=Wu;function de(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?yt(xs.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var Es=ge("node:buffer");function V(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Es.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var Xu=parseInt("11111",2),go=parseInt("10000000",2),Zu=parseInt("01111111",2),Is={0:hr,1:hr,2:Qu,3:td,4:rd,5:ed,6:Ju,16:hr,22:hr,48:hr};function mo(t,e={offset:0}){let r=t[e.offset]&Xu;if(e.offset++,Is[r]!=null)return Is[r](t,e);throw new Error("No decoder for tag "+r)}function pr(t,e){let r=0;if((t[e.offset]&go)===go){let n=t[e.offset]&Zu,o="0x";e.offset++;for(let i=0;i<n;i++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function hr(t,e){pr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=mo(t,e);if(n===null)break;r.push(n)}return r}function Qu(t,e){let r=pr(t,e),n=e.offset,o=e.offset+r,i=[];for(let s=n;s<o;s++)s===n&&t[s]===0||i.push(t[s]);return e.offset+=r,Uint8Array.from(i)}function Ju(t,e){let r=pr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let i=0,s=0;o<40?(i=0,s=o):o<80?(i=1,s=o-40):(i=2,s=o-80);let a=`${i}.${s}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let d=0;d<c.length;d++)l+=c[d]<<d*7;a+=`.${l}`,c=[]}}return a}function ed(t,e){return e.offset++,null}function td(t,e){let r=pr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function rd(t,e){let r=pr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function nd(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new Ee;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function yo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=nd(t.byteLength);return new Ee(Uint8Array.from([e.byteLength|go]),e)}function Ss(t){let e=new Ee,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new Ee(Uint8Array.from([2]),yo(e),e)}function vs(t){let e=Uint8Array.from([0]),r=new Ee(e,t);return new Ee(Uint8Array.from([3]),yo(r),r)}function Hr(t,e=48){let r=new Ee;for(let n of t)r.append(n);return new Ee(Uint8Array.from([e]),yo(r),r)}var od=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),id=Uint8Array.from([6,5,43,129,4,0,34]),sd=Uint8Array.from([6,5,43,129,4,0,35]),cd={ext:!0,kty:"EC",crv:"P-256"},ad={ext:!0,kty:"EC",crv:"P-384"},ud={ext:!0,kty:"EC",crv:"P-521"},wo=32,bo=48,xo=66;function Bs(t){let e=mo(t);return As(e)}function As(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===wo*2+1)return n=V(e.subarray(r,r+wo),"base64url"),o=V(e.subarray(r+wo),"base64url"),new zt({...cd,key_ops:["verify"],x:n,y:o});if(e.byteLength===bo*2+1)return n=V(e.subarray(r,r+bo),"base64url"),o=V(e.subarray(r+bo),"base64url"),new zt({...ad,key_ops:["verify"],x:n,y:o});if(e.byteLength===xo*2+1)return n=V(e.subarray(r,r+xo),"base64url"),o=V(e.subarray(r+xo),"base64url"),new zt({...ud,key_ops:["verify"],x:n,y:o});throw new Te(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Cs(t){return Hr([Ss(Uint8Array.from([1])),Hr([dd(t.crv)],160),Hr([vs(new Ee(Uint8Array.from([4]),de(t.x??"","base64url"),de(t.y??"","base64url")))],161)]).subarray()}function dd(t){if(t==="P-256")return od;if(t==="P-384")return id;if(t==="P-521")return sd;throw new Te(`Invalid curve ${t}`)}var zt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Cs(this.jwk)),this._raw}toMultihash(){return _e.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}async verify(e,r,n){return ls(this.jwk,r,e,n)}};var sn=nr(ge("crypto"),1);var ld=t=>t/2**32|0,hd=t=>t>>>0;function Os(t,e,r,n){let o=ld(r),i=hd(r);t.setUint32(e,n?i:o,n),t.setUint32(e+4,n?o:i,n)}function qr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Eo=t=>t?`"${t}" `:"";function st(t,e=""){if(typeof t!="number")throw new TypeError(Eo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Eo(e)+"expected integer >= 0, got "+t);return t}function je(t,e,r=""){if(qr(t)&&(e===void 0||t.length===e))return t;e!==void 0&&st(e,"length");let n=qr(t),o=e!==void 0?` of length ${e}`:"",i=n?`length=${t.length}`:`type=${typeof t}`,s=Eo(r)+"expected Uint8Array"+o+", got "+i;throw n?new RangeError(s):new TypeError(s)}function zr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(st(t.outputLen),st(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var pd=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ts=(t,e)=>{pd(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function jt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function $r(t,e){je(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function fr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function jr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}var Ds=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Vr(t){if(je(t),Ds)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=fd[t[r]];return e}function Ls(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Io(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Ds)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=Ls(t.charCodeAt(i)),a=Ls(t.charCodeAt(i+1));if(s===void 0||a===void 0){let c=t[i]+t[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[o]=s*16+a}return n}function Us(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];je(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let i=t[n];r.set(i,o),o+=i.length}return r}function gd(t,e,r="opts"){return Ts(t,"defaults"),e!==void 0&&Ts(e,r),Object.assign(Object.create(null),t,e)}function _s(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=gd({},e,"info");let r=(o,i)=>t(i).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ps(t=32){st(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Rs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ns(t,e,r){return t&e^~t&r}function Fs(t,e,r){return t&e^t&r^e&r}var Yr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=jr(this.buffer)}update(e){jt(this),je(e);let{view:r,buffer:n,blockLen:o}=this,i=e.length,s=!1;for(let a=0;a<i;){let c=Math.min(o-this.pos,i-a);if(c===o){let u=jr(e);for(;o<=i-a;a+=o)this.process(u,a);s=!0;continue}n.set(a===0&&c===i?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,s=!0)}return this.length+=e.length,s&&this.roundClean(),this}digestInto(e){jt(this),$r(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,r.fill(0,s),this.padOffset>o-s&&(this.process(n,0),r.fill(0)),Os(n,o-8,this.length*8,i),this.process(n,0),this.roundClean();let a=e===r?n:jr(e),c=this.outputLen,u=c/4,l=this.get();if(c%4||u>l.length)throw new Error("invalid outputLen");for(let d=0;d<u;d++)a.setUint32(4*d,l[d],i)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:i,pos:s}=this;return e.destroyed=i,e.finished=o,e.length=n,e.pos=s,s&&e.buffer.set(r),e}clone(){return this._cloneInto()}},ks=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var md=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),wt=new Uint32Array(64),So=class extends Yr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[e,r,n,o,i,s,a,c]}set(e,r,n,o,i,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let d=0;d<16;d++,r+=4)wt[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){let g=wt[d-15],h=wt[d-2],f=Re(g,7)^Re(g,18)^g>>>3,b=Re(h,17)^Re(h,19)^h>>>10;wt[d]=b+wt[d-7]+f+wt[d-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let d=0;d<64;d++){let g=Re(a,6)^Re(a,11)^Re(a,25),h=l+g+Ns(a,c,u)+md[d]+wt[d]|0,b=(Re(n,2)^Re(n,13)^Re(n,22))+Fs(n,o,i)|0;l=u,u=c,c=a,a=s+h|0,s=i,i=o,o=n,n=h+b|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,i,s,a,c,u,l)}roundClean(){fr(wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),fr(this.buffer)}},vo=class extends So{constructor(){super(32,ks)}};var Ks=_s(()=>new vo,Rs(1));function Wr(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var X=(t,e,r)=>je(t,e,r),Bo=st;function Hs(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function bt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ot(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Ao=Vr,ct=(...t)=>Us(...t),Xr=t=>Io(t),Vt=qr,Zr=t=>Ps(t),Gr=BigInt(0),Ms=BigInt(1),yd=t=>t?`"${t}" `:"";function Ve(t,e=""){if(typeof t!="boolean")throw new TypeError(yd(e)+"expected boolean, got type="+typeof t);return t}function Qr(t){if(typeof t=="bigint"){if(!xt(t))throw new RangeError("positive bigint expected, got "+t)}else Bo(t);return t}function Tt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function gr(t){let e=Qr(t).toString(16);return e.length&1?"0"+e:e}function qs(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Gr:BigInt("0x"+t)}function Ye(t){return qs(Vr(t))}function Co(t){return qs(Vr(wd(je(t)).reverse()))}function Jr(t,e){if(st(e),e===0)throw new Error("zero output length is invalid");t=Qr(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Io(n.padStart(r,"0"))}function Oo(t,e){return Jr(t,e).reverse()}function wd(t){return Uint8Array.from(X(t))}function xt(t){return typeof t=="bigint"&&Gr<=t}function To(t,e,r){return xt(t)&&xt(e)&&xt(r)&&e<=t&&t<r}function Lo(t,e,r,n){if(!To(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Yt(t){if(t<Gr)throw new Error("expected non-negative bigint, got "+t);return t===Gr?0:t.toString(2).length}var mr=t=>(Tt(t,"n"),(Ms<<BigInt(t))-Ms);function zs(t,e,r){if(st(t,"hashLen"),st(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=E=>new Uint8Array(E),o=Uint8Array.of(),i=Uint8Array.of(0),s=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),l=0,d=()=>{c.fill(1),u.fill(0),l=0},g=(...E)=>r(u,ct(c,...E)),h=(E=o)=>{u=g(i,E),c=g(),E.length!==0&&(u=g(s,E),c=g())},f=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let E=0,x=[];for(;E<e;){c=g();let O=c.slice();x.push(O),E+=c.length}return ct(...x)};return(E,x)=>{d(),h(E);let O;for(;(O=x(f()))===void 0;)h();return d(),O}}function Et(t,e={},r={},n="object"){bt(t,n),bt(e,"fields"),bt(r,"optFields");function o(s,a,c){let u=n==="object"?`param "${String(s)}"`:`"${n}.${String(s)}"`,l=t[s];if(!Object.hasOwn(t,s)&&(c?l!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&l===void 0)return;let d=typeof l;if(d!==a||l===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${d}`)}let i=(s,a)=>Object.entries(s).forEach(([c,u])=>o(c,u,a));i(e,!1),i(r,!0)}var Z=BigInt(0),N=BigInt(1),It=BigInt(2),Ys=BigInt(3),Do=BigInt(4),Gs=BigInt(5),bd=BigInt(7),Ws=BigInt(8),xd=BigInt(9),Ed=BigInt(15),Xs=BigInt(16),Id=BigInt("0x10000000000000000");function Ie(t,e){if(e<=Z)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=Z?r:e+r}function Zs(t,e,r){if(r<=N)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<Z)throw new Error("invalid exponent, negatives unsupported");if(e===Z)return N;if(e===N)return t;let n=t%r;if(n<Z&&(n+=r),e<Id){let a=N;for(;e>Z;)e&N&&(a=a*n%r),n=n*n%r,e>>=N;return a}let o=[];for(;e>Z;)o.push(Number(e&Ed)),e>>=Do;let i=new Array(16);i[0]=N,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let s=i[o[o.length-1]];for(let a=o.length-2;a>=0;a--){s=s*s%r,s=s*s%r,s=s*s%r,s=s*s%r;let c=o[a];c!==0&&(s=s*i[c]%r)}return s}function Se(t,e,r){if(r<=N)throw new Error("pow2: expected modulus > 1, got "+r);if(e<Z)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >Z;)n*=n,n%=r;return n}function $s(t,e){if(t===Z)throw new Error("invert: expected non-zero number");if(e<=N)throw new Error("invert: expected modulus > 1, got "+e);let r=Ie(t,e),n=e,o=Z,i=N;for(;r!==Z;){let a=n/r,c=n-r*a,u=o-i*a;n=r,r=c,o=i,i=u}if(n!==N)throw new Error("invert: does not exist");return Ie(o,e)}function Qs(t,e){if(e<=N)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=Ie(t,e);if(r===Z)throw new Error("invertCt: expected non-zero number");let n=Zs(r,e-It,e);if(Ie(r*n,e)!==N)throw new Error("invertCt: does not exist");return n}function Uo(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function _o(t,e){if((t&N)===Z)throw new Error(e+": expected odd modulus, got "+t)}function Js(t,e){let r=t,n=(r.ORDER+N)/Do,o=r.pow(e,n);return Uo(r,o,e),o}function Sd(t,e){let r=t,n=(r.ORDER-Gs)/Ws,o=r.mul(e,It),i=r.pow(o,n),s=r.mul(e,i),a=r.mul(r.mul(s,It),i),c=r.mul(s,r.sub(a,r.ONE));return Uo(r,c,e),c}function vd(t){let e=Wt(t),r=ec(t),n=r(e,e.neg(e.ONE)),o=r(e,n),i=r(e,e.neg(n)),s=(t+bd)/Xs;return((a,c)=>{let u=a,l=u.pow(c,s),d=u.mul(l,n),g=u.mul(l,o),h=u.mul(l,i),f=u.eql(u.sqr(d),c),b=u.eql(u.sqr(g),c);l=u.cmov(l,d,f),d=u.cmov(h,g,b);let E=u.eql(u.sqr(d),c),x=u.cmov(l,d,E);return Uo(u,x,c),x})}function ec(t){if(t<Ys)throw new Error("sqrt is not defined for small field");_o(t,"tonelliShanks");let e=t-N,r=0;for(;e%It===Z;)e/=It,r++;let n=It,o=Wt(t);for(;js(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Js;let i=o.pow(n,e),s=(e+N)/It;return function(c,u){let l=c;if(l.is0(u))return u;if(js(l,u)!==1)throw new Error("Cannot find square root");let d=r,g=l.mul(l.ONE,i),h=l.pow(u,e),f=l.pow(u,s);for(;!l.eql(h,l.ONE);){if(l.is0(h))throw new Error("Cannot find square root: probably non-prime P");let b=1,E=l.sqr(h);for(;!l.eql(E,l.ONE);)if(b++,E=l.sqr(E),b===d)throw new Error("Cannot find square root");let x=N<<BigInt(d-b-1),O=l.pow(g,x);d=b,g=l.sqr(O),h=l.mul(h,g),f=l.mul(f,O)}return f}}function Bd(t){return _o(t,"Fp.sqrt"),t%Do===Ys?Js:t%Ws===Gs?Sd:t%Xs===xd?vd(t):ec(t)}var Ad=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Gt(t){if(bt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);Tt(t.BYTES,"BYTES"),Tt(t.BITS,"BITS");for(let e of Ad)Ot(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=N)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Po(t,e,r=!1){Gt(t),Wr(e,"nums"),Ve(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),i=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),s=n.inv(i);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),s),o}function js(t,e){Gt(t);let r=t;_o(r.ORDER,"FpLegendre");let n=(r.ORDER-N)/It,o=r.pow(e,n),i=r.eql(o,r.ONE),s=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!i&&!s&&!a)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Cd(t,e){if(e!==void 0&&Bo(e),t<=Z)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Yt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Vs=new WeakMap,en=class{ORDER;BITS;BYTES;isLE;ZERO=Z;ONE=N;_lengths;_mod;constructor(e,r={}){if(e<=N)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:i}=Cd(e,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=i,Object.freeze(this)}create(e){return Ie(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return Z<=e&&e<this.ORDER}is0(e){return e===Z}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&N)===N}neg(e){return Ie(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Ie(e*e,this.ORDER)}add(e,r){return Ie(e+r,this.ORDER)}sub(e,r){return Ie(e-r,this.ORDER)}mul(e,r){return Ie(e*r,this.ORDER)}pow(e,r){return Zs(e,r,this.ORDER)}div(e,r){return Ie(e*$s(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return $s(e,this.ORDER)}sqrt(e){let r=Vs.get(this);return r||Vs.set(this,r=Bd(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Oo(e,this.BYTES):Jr(e,this.BYTES)}fromBytes(e,r=!1){X(e);let{_lengths:n,BYTES:o,isLE:i,ORDER:s,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,i?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=i?Co(e):Ye(e);if(a&&(c=Ie(c,s)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Po(this,e,!0)}cmov(e,r,n){return Ve(n,"condition"),n?r:e}};function Wt(t,e={}){return Object.freeze(en.prototype),new en(t,e)}function tc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=N)throw new Error("field order must be greater than 1");let e=Yt(t-N);return Math.ceil(e/8)}function tn(t){let e=tc(t);return e+Math.ceil(e/2)}function rn(t,e,r=!1){X(t);let n=t.length,o=tc(e),i=Math.max(tn(e),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Co(t):Ye(t),a=Ie(s,e-N)+N;return r?Oo(a,o):Jr(a,o)}var Fo=BigInt(0),yr=BigInt(1),Od=BigInt(4),Ro=16,rc=128,Td=5,nc=2**31;function Xt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ot(e.fromAffine,"Point.fromAffine"),Ot(e.fromBytes,"Point.fromBytes"),Ot(e.fromHex,"Point.fromHex"),bt(e.BASE,"Point.BASE"),bt(e.ZERO,"Point.ZERO"),Gt(e.Fp),Gt(e.Fn)}function ic(t,e){Xt(t),sc(e,t);let r=Po(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function Ld(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Dd(t,e){let r=t*(4*e+128);if(r>nc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+nc/2**20+" MiB")}function ko(t,e){if(t!==void 0){Ot(t,"randomBytes");try{let r=t(e);if(!Vt(r)||r.length!==e)return}catch{return}return t}}function sc(t,e){Wr(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Ud(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):xt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var cc=new WeakMap;function No(t){return cc.get(t)||1}function _d(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function Pd(t,e){let r=2**e,n=r/2,o=BigInt(r-1),i=[];for(;t>Fo;){let s=0;t&yr&&(s=Number(t&o),s>=n&&(s-=r),t-=BigInt(s)),i.push(s),t>>=yr}return i}function Rd(t,e,r){let n=2**e,o=n/2,i=BigInt(n-1),s=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&i);t>>=s,u>o&&(u-=n,t+=yr),a.push(u)}if(t!==Fo)throw new Error("invalid wnaf");return a}function Nd(t,e,r){let n=0;for(let i of r)n=Math.max(n,i.length);let o=t;for(let i=n-1;i>=0;i--){i!==n-1&&(o=o.double());for(let s=0;s<r.length;s++){let a=r[s][i];if(a){let c=e[s][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var nn=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Xt(e),this.randomBytes=ko(r,Ro),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,i=2**(r-1),s=[],a=e;for(let c=0;c<o;c++){let u=a;for(let l=0;l<i;l++)s.push(u),u=u.add(a);a=s[s.length-1].double()}return{W:r,bits:n,windows:o,comp:s}}wnafCachedCT(e,r){let{W:n,windows:o,comp:i}=e,s=2**(n-1),a=Rd(r,n,o),c=this.ZERO,u=this.BASE;for(let l=0;l<o;l++){let d=a[l],g=l*s,h=Math.abs(d)-1,f=i[g];for(let E=1;E<s;E++)f=E===h?i[g+E]:f;let b=f.negate();d===0?u=u.add(i[g]):c=c.add(d<0?b:f)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let i=this.wnafPrecomputes.get(r),s=i?.find(a=>a.W===e&&a.bits===n);return s||(s=this.buildWnafTable(r,e,n),typeof o=="function"&&(s={...s,comp:o(s.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(s)),s}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!To(r,yr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let i=No(e);return i===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+rc,i=this.randomBytes(Ro);if(!Vt(i)||i.length!==Ro)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let s=r+Ye(i)*this.Point.Fn.ORDER;return this.runCT(e,s,o,n)}fixedWindowCT(e,r,n){let o=Td,i=1<<o,s=mr(o),a=new Array(i);a[0]=this.ZERO;for(let l=1;l<i;l++)a[l]=a[l-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let l=c-1;l>=0;l--){if(l!==c-1)for(let h=0;h<o;h++)u=u.double();let d=Number(r>>BigInt(l*o)&s),g=a[0];for(let h=1;h<i;h++)g=h===d?a[h]:g;u=u.add(g)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===yr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!xt(r))throw new Error("invalid scalar");let o=No(e);if(o===1||r>=this.Point.Fn.ORDER)return on(this.Point,[e],[r],!0);let i=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(e,r){this.assertPoint(e),Ld(r,this.bits);let n=Math.ceil((this.bits+rc)/r)+1;Dd(n*2**(r-1),this.Point.Fp.BYTES),cc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return No(e)!==1}};function on(t,e,r,n=!1){if(Xt(t),sc(e,t),Ve(n,"allowOversized"),Ud(r,t.Fn,n?t.Fn.ORDER**Od:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(s=>_d(s,4)),i=r.map(s=>Pd(s,4));return Nd(t.ZERO,o,i)}function oc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Gt(e),e}else return Wt(t,{isLE:r})}function ac(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Et(r);for(let c of["p","n","h"]){let u=e[c];if(!(xt(u)&&u!==Fo))throw new Error(`CURVE.${c} must be positive bigint`)}let o=oc(e.p,r.Fp,n),i=oc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:i}}function uc(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var uf=sn.default.generateKeyPairSync,wr=32;var Fd=64;function dc(t,e,r){if(t.byteLength!==wr)throw new TypeError('"key" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(e.byteLength!==Fd)throw new TypeError('"sig" must be 64 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=sn.default.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:V(t,"base64url"),kty:"OKP"}});return sn.default.verify(null,r instanceof Uint8Array?r:r.subarray(),n,e)}function hc(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var cn=class{type="Ed25519";raw;constructor(e){this.raw=Ko(e,wr)}toMultihash(){return _e.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,e);return hc(o)?o.then(i=>(n?.signal?.throwIfAborted(),i)):o}};function pc(t){return t=Ko(t,wr),new cn(t)}function Ko(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Te(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Kd=Math.pow(2,7),Md=Math.pow(2,14),Hd=Math.pow(2,21),Mo=Math.pow(2,28),Ho=Math.pow(2,35),qo=Math.pow(2,42),zo=Math.pow(2,49),z=128,ie=127;function Ge(t){if(t<Kd)return 1;if(t<Md)return 2;if(t<Hd)return 3;if(t<Mo)return 4;if(t<Ho)return 5;if(t<qo)return 6;if(t<zo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function br(t,e,r=0){switch(Ge(t)){case 8:e[r++]=t&255|z,t/=128;case 7:e[r++]=t&255|z,t/=128;case 6:e[r++]=t&255|z,t/=128;case 5:e[r++]=t&255|z,t/=128;case 4:e[r++]=t&255|z,t>>>=7;case 3:e[r++]=t&255|z,t>>>=7;case 2:e[r++]=t&255|z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function $o(t,e){let r=t[e],n=0;if(n+=r&ie,r<z||(r=t[e+1],n+=(r&ie)<<7,r<z)||(r=t[e+2],n+=(r&ie)<<14,r<z)||(r=t[e+3],n+=(r&ie)<<21,r<z)||(r=t[e+4],n+=(r&ie)*Mo,r<z)||(r=t[e+5],n+=(r&ie)*Ho,r<z)||(r=t[e+6],n+=(r&ie)*qo,r<z)||(r=t[e+7],n+=(r&ie)*zo,r<z))return n;throw new RangeError("Could not decode varint")}function qd(t,e){let r=t.get(e),n=0;if(n+=r&ie,r<z||(r=t.get(e+1),n+=(r&ie)<<7,r<z)||(r=t.get(e+2),n+=(r&ie)<<14,r<z)||(r=t.get(e+3),n+=(r&ie)<<21,r<z)||(r=t.get(e+4),n+=(r&ie)*Mo,r<z)||(r=t.get(e+5),n+=(r&ie)*Ho,r<z)||(r=t.get(e+6),n+=(r&ie)*qo,r<z)||(r=t.get(e+7),n+=(r&ie)*zo,r<z))return n;throw new RangeError("Could not decode varint")}function jo(t,e=0){return t instanceof Uint8Array?$o(t,e):qd(t,e)}var Vo=new Float32Array([-0]),St=new Uint8Array(Vo.buffer);function fc(t,e,r){Vo[0]=t,e[r]=St[0],e[r+1]=St[1],e[r+2]=St[2],e[r+3]=St[3]}function gc(t,e){return St[0]=t[e],St[1]=t[e+1],St[2]=t[e+2],St[3]=t[e+3],Vo[0]}var Yo=new Float64Array([-0]),se=new Uint8Array(Yo.buffer);function mc(t,e,r){Yo[0]=t,e[r]=se[0],e[r+1]=se[1],e[r+2]=se[2],e[r+3]=se[3],e[r+4]=se[4],e[r+5]=se[5],e[r+6]=se[6],e[r+7]=se[7]}function yc(t,e){return se[0]=t[e],se[1]=t[e+1],se[2]=t[e+2],se[3]=t[e+3],se[4]=t[e+4],se[5]=t[e+5],se[6]=t[e+6],se[7]=t[e+7],Yo[0]}var $d=BigInt(Number.MAX_SAFE_INTEGER),jd=BigInt(Number.MIN_SAFE_INTEGER),ve=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Lt;if(e<$d&&e>jd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>wc&&(o=0n,++n>wc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Lt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Lt}},Lt=new ve(0,0);Lt.toBigInt=function(){return 0n};Lt.zzEncode=Lt.zzDecode=function(){return this};Lt.length=function(){return 1};var wc=4294967296n;function bc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function xc(t,e,r){if(r-e<1)return"";let o,i=[],s=0,a;for(;e<r;)a=t[e++],a<128?i[s++]=a:a>191&&a<224?i[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,i[s++]=55296+(a>>10),i[s++]=56320+(a&1023)):i[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o!=null?(s>0&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))}function Go(t,e,r){let n=r,o,i;for(let s=0;s<t.length;++s)o=t.charCodeAt(s),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((i=t.charCodeAt(s+1))&64512)===56320?(o=65536+((o&1023)<<10)+(i&1023),++s,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ne(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function an(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Wo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=mt(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ne(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ne(this,4);return an(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ne(this,4);return an(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ne(this,4);let e=gc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ne(this,4);let e=yc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return xc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ne(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new ve(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ne(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ne(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ne(this,8);let e=an(this.buf,this.pos+=4),r=an(this.buf,this.pos+=4);return new ve(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=$o(this.buf,this.pos);return this.pos+=Ge(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function xr(t){return new Wo(t instanceof Uint8Array?t:t.subarray())}function un(t,e,r){let n=xr(t);return e.decode(n,void 0,r)}function Xo(t){let e=t??8192,r=e>>>1,n,o=e;return function(s){if(s<1||s>r)return xe(s);o+s>e&&(n=xe(e),o=0);let a=n.subarray(o,o+=s);return(o&7)!==0&&(o=(o|7)+1),a}}var Dt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Zo(){}var Jo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Vd=Xo();function Yd(t){return globalThis.Buffer!=null?xe(t):Vd(t)}var Ir=class{len;head;tail;states;constructor(){this.len=0,this.head=new Dt(Zo,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Dt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ei((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(dn,10,ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=ve.fromBigInt(e);return this._push(dn,r.length(),r)}uint64Number(e){return this._push(br,Ge(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=ve.fromBigInt(e).zzEncode();return this._push(dn,r.length(),r)}sint64Number(e){let r=ve.fromNumber(e).zzEncode();return this._push(dn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Qo,1,e?1:0)}fixed32(e){return this._push(Er,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=ve.fromBigInt(e);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64Number(e){let r=ve.fromNumber(e);return this._push(Er,4,r.lo)._push(Er,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(fc,4,e)}double(e){return this._push(mc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Qo,1,0):this.uint32(r)._push(Wd,r,e)}string(e){let r=bc(e);return r!==0?this.uint32(r)._push(Go,r,e):this._push(Qo,1,0)}fork(){return this.states=new Jo(this),this.head=this.tail=new Dt(Zo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Dt(Zo,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Yd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Qo(t,e,r){e[r]=t&255}function Gd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ei=class extends Dt{next;constructor(e,r){super(Gd,e,r),this.next=void 0}};function dn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Er(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Wd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Ir.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Xd,e,t),this},Ir.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Zd,e,t),this});function Xd(t,e,r){e.set(t,r)}function Zd(t,e,r){t.length<40?Go(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(de(t),r)}function ti(){return new Ir}function ln(t,e){let r=ti();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*hn(t,e,r){let n=xr(t);yield*e.stream(n,void 0,"$",r)}var pn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function fn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function ri(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(s,a){let c=e(s);a.int32(c)},n=function(s){let a=s.int32();return e(a)},o=function*(s){let a=s.int32();yield e(a)};return fn("enum",pn.VARINT,r,n,o)}function gn(t,e,r){return fn("message",pn.LENGTH_DELIMITED,t,e,r)}var le;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(le||(le={}));var ni;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(ni||(ni={}));(function(t){t.codec=()=>ri(ni)})(le||(le={}));var Sr;(function(t){let e;t.codec=()=>(e==null&&(e=gn((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),le.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.Type=le.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return ln(i,t.codec())}t.encode=r;function n(i,s){return un(i,t.codec(),s)}t.decode=n;function o(i,s){return hn(i,t.codec(),s)}t.stream=o})(Sr||(Sr={}));var oi;(function(t){let e;t.codec=()=>(e==null&&(e=gn((i,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),i.Type!=null&&(s.uint32(8),le.codec().encode(i.Type,s)),i.Data!=null&&(s.uint32(18),s.bytes(i.Data)),a.lengthDelimited!==!1&&s.ldelim()},(i,s,a={})=>{let c={},u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.Type=le.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(l&7);break}}}return c},function*(i,s,a,c={}){let u=s==null?i.len:i.pos+s;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:le.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(l&7);break}}}})),e);function r(i){return ln(i,t.codec())}t.encode=r;function n(i,s){return un(i,t.codec(),s)}t.decode=n;function o(i,s){return hn(i,t.codec(),s)}t.stream=o})(oi||(oi={}));var Lc=nr(ge("node:crypto"),1);var mn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(zr(e),je(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=e.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),fr(o)}update(e){return jt(this),this.iHash.update(e),this}digestInto(e){jt(this),$r(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ic=(()=>{let t=((e,r,n)=>new mn(e,r).update(n).digest());return t.create=(e,r)=>new mn(e,r),t})();var Jd=BigInt(0),ii=class extends Error{constructor(e=""){super(e)}},at={Err:ii,_tlv:{encode:(t,e)=>{let{Err:r}=at;if(Tt(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Hs(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=gr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?gr(o.length/2|128):"";return gr(t)+i+o+e},decode(t,e){let{Err:r}=at;e=X(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)s=s<<8|l;if(n+=c,s<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(t){let{Err:e}=at;if(Qr(t),t<Jd)throw new e("integer: negative integers are not allowed");let r=gr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=at;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ye(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=at;if(e!==void 0&&(Tt(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=X(t,void 0,"signature"),{v:s,l:a}=o.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,s),{v:l,l:d}=o.decode(2,u);if(d.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||l.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(l)}},hexFromSig(t){let{_tlv:e,_int:r}=at;Et(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),i=n+o;return e.encode(48,i)}},yn=(Object.freeze(at._tlv),Object.freeze(at._int),Object.freeze(at));var Sc=(t,e)=>(t+(t>=0?e:-e)/vc)/e;function el(t,e,r){Lo("scalar",t,ut,r);let[[n,o],[i,s]]=e,a=Sc(s*t,r),c=Sc(-o*t,r),u=t-a*n-c*i,l=-a*o-c*s,d=u<ut,g=l<ut;d&&(u=-u),g&&(l=-l);let h=mr(Math.ceil(Yt(r)/2))+Ut;if(u<ut||u>=h||l<ut||l>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:u,k2neg:g,k2:l}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){Et(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ve(r.lowS,"lowS"),Ve(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var ut=BigInt(0),Ut=BigInt(1),vc=BigInt(2),ci=BigInt(3),tl=BigInt(4);function Bc(t,e={}){let r=ac("weierstrass",t,e),n=r.Fp,o=r.Fn,i=r.CURVE,{h:s,n:a}=i;Et(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:l,isTorsionFree:d,fromBytes:g,toBytes:h}=e,f=e.randomBytes===void 0?Zr:e.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let b=c?{beta:c.beta,basises:c.basises.map(I=>[...I])}:void 0,E=Cc(n,o);function x(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function O(I,p,m){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:y,y:B}=p.toAffine(),A=n.toBytes(y);if(Ve(m,"isCompressed"),m){x();let C=!n.isOdd(B);return ct(Ac(C),A)}else return ct(Uint8Array.of(4),A,n.toBytes(B))}function q(I){X(I,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=E,y=I.length,B=I[0],A=I.subarray(1);if(u&&y===1&&B===0)return{x:n.ZERO,y:n.ZERO};if(y===p&&(B===2||B===3)){let C=n.fromBytes(A);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let T=oe(C),L;try{L=n.sqrt(T)}catch(Y){let M=Y instanceof Error?": "+Y.message:"";throw new Error("bad point: is not on curve, sqrt error"+M)}x();let P=n.isOdd(L);return(B&1)===1!==P&&(L=n.neg(L)),{x:C,y:L}}else if(y===m&&B===4){let C=n.BYTES,T=n.fromBytes(A.subarray(0,C)),L=n.fromBytes(A.subarray(C,C*2));if(!ce(T,L))throw new Error("bad point: is not on curve");return{x:T,y:L}}else throw new Error(`bad point: got length ${y}, expected compressed=${p} or uncompressed=${m}`)}let k=h===void 0?O:h,F=g===void 0?q:g,_=n.mul(i.b,ci),$=n.is0(i.a)?I=>n.ZERO:I=>n.mul(i.a,I);function oe(I){let p=n.sqr(I),m=n.mul(p,I);return n.add(n.add(m,n.mul(I,i.a)),i.b)}function ce(I,p){let m=n.sqr(p),y=oe(I);return n.eql(m,y)}if(!ce(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let K=n.mul(n.pow(i.a,ci),tl),he=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(K,he)))throw new Error("bad curve params: a or b");function Ae(I,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${I}`);return typeof p=="object"&&p!==null?n.create(p):p}function Rt(I){if(!(I instanceof R))throw new Error("Weierstrass Point expected")}function Tr(I){if(!b||!b.basises)throw new Error("no endo");return el(I,b.basises,o.ORDER)}function Bt(I,p,m,y){if(!o.isValid(y))throw new RangeError("invalid scalar: out of range");if(b){let{k1neg:B,k1:A,k2neg:C,k2:T}=Tr(y),L=new R(n.mul(m.X,b.beta),m.Y,m.Z);I.push(B?m.negate():m,C?L.negate():L),p.push(A,T)}else I.push(m),p.push(y)}let Lr=new WeakSet;class R{static BASE=new R(i.Gx,i.Gy,n.ONE);static ZERO=new R(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,m,y){this.X=Ae("x",p),this.Y=Ae("y",m,!0),this.Z=Ae("z",y),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y}=p||{};if(!p||!n.isValid(m)||!n.isValid(y))throw new Error("invalid affine point");if(p instanceof R)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(y)?R.ZERO:new R(m,y,n.ONE)}static fromBytes(p){let m=R.fromAffine(F(X(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return R.fromBytes(Xr(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,m=!0){return ht.setWindowSize(this,p),m||this.multiply(ci),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(Lr.has(p))return;let{x:m,y}=p.toAffine();if(!n.isValid(m)||!n.isValid(y))throw new Error("bad point: x or y not field elements");if(!ce(m,y))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");Lr.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){Rt(p);let{X:m,Y:y,Z:B}=this,{X:A,Y:C,Z:T}=p,L=n.eql(n.mul(m,T),n.mul(A,B)),P=n.eql(n.mul(y,T),n.mul(C,B));return L&&P}negate(){return new R(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:m,Z:y}=this,B=n.ZERO,A=n.ZERO,C=n.ZERO,T=n.mul(p,p),L=n.mul(m,m),P=n.mul(y,y),U=n.mul(p,m);return U=n.add(U,U),C=n.mul(p,y),C=n.add(C,C),B=$(C),A=n.mul(_,P),A=n.add(B,A),B=n.sub(L,A),A=n.add(L,A),A=n.mul(B,A),B=n.mul(U,B),C=n.mul(_,C),P=$(P),U=n.sub(T,P),U=$(U),U=n.add(U,C),C=n.add(T,T),T=n.add(C,T),T=n.add(T,P),T=n.mul(T,U),A=n.add(A,T),P=n.mul(m,y),P=n.add(P,P),T=n.mul(P,U),B=n.sub(B,T),C=n.mul(P,L),C=n.add(C,C),C=n.add(C,C),new R(B,A,C)}add(p){Rt(p);let{X:m,Y:y,Z:B}=this,{X:A,Y:C,Z:T}=p,L=n.ZERO,P=n.ZERO,U=n.ZERO,Y=n.mul(m,A),M=n.mul(y,C),Q=n.mul(B,T),Ce=n.add(m,y),H=n.add(A,C);Ce=n.mul(Ce,H),H=n.add(Y,M),Ce=n.sub(Ce,H),H=n.add(m,B);let G=n.add(A,T);return H=n.mul(H,G),G=n.add(Y,Q),H=n.sub(H,G),G=n.add(y,B),L=n.add(C,T),G=n.mul(G,L),L=n.add(M,Q),G=n.sub(G,L),U=$(H),L=n.mul(_,Q),U=n.add(L,U),L=n.sub(M,U),U=n.add(M,U),P=n.mul(L,U),M=n.add(Y,Y),M=n.add(M,Y),Q=$(Q),H=n.mul(_,H),M=n.add(M,Q),Q=n.sub(Y,Q),Q=$(Q),H=n.add(H,Q),Y=n.mul(M,H),P=n.add(P,Y),Y=n.mul(G,H),L=n.mul(Ce,L),L=n.sub(L,Y),Y=n.mul(Ce,M),U=n.mul(G,U),U=n.add(U,Y),new R(L,P,U)}subtract(p){return Rt(p),this.add(p.negate())}is0(){return this.equals(R.ZERO)}multiply(p){if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:m,f:y}=ht.mulSecret(this,p,s,tr);return tr([m,y])[0]}multiplyUnsafe(p){let m=this,y=p;if(!o.isValid(y))throw new RangeError("invalid scalar: out of range");if(y===ut||m.is0())return R.ZERO;if(y===Ut)return m;if(ht.hasWindowSize(this))return ht.mulUnsafe(m,y,tr);let B=[],A=[];return Bt(B,A,m,y),on(R,B,A)}mulAddUnsafe(p,m,y){Rt(m);let B=[],A=[];return Bt(B,A,this,p),Bt(B,A,m,y),on(R,B,A)}toAffine(p){let m=this,y=p;if(y!=null&&!n.isValid(y))throw new RangeError('"invertedZ" expected valid field element');let{X:B,Y:A,Z:C}=m;if(n.eql(C,n.ONE))return{x:B,y:A};let T=m.is0();y==null&&(y=T?n.ONE:n.inv(C));let L=n.mul(B,y),P=n.mul(A,y),U=n.mul(C,y);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(U,n.ONE))throw new Error("invZ was invalid");return{x:L,y:P}}isTorsionFree(){return s===Ut?!0:d?d(R,this):ht.mulUnsafe(this,a).is0()}clearCofactor(){return s===Ut?this:l?l(R,this):this.multiplyUnsafe(s)}isSmallOrder(){return s===Ut?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Ve(p,"isCompressed"),this.assertValidity(),k(R,this,p)}toHex(p=!0){return Ao(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let tr=I=>ic(R,I),ht=new nn(R,f);return ht.bits>=6&&R.BASE.precompute(6),Object.freeze(R.prototype),Object.freeze(R),R}function Ac(t){return Uint8Array.of(t?2:3)}function Cc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function rl(t,e={}){Xt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Zr:e.randomBytes,o=Object.assign(Cc(t.Fp,r),{seed:Math.max(tn(r.ORDER),16)});function i(h){try{let f=r.fromBytes(h);return r.isValidNot0(f)}catch{return!1}}function s(h,f){let{publicKey:b,publicKeyUncompressed:E}=o;try{let x=h.length;return f===!0&&x!==b||f===!1&&x!==E?!1:!t.fromBytes(h).is0()}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,rn(X(h,o.seed,"seed"),r.ORDER)}function c(h,f=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(f)}function u(h){let{secretKey:f,publicKey:b,publicKeyUncompressed:E}=o,x=r._lengths;if(!Vt(h))return;let O=X(h,void 0,"key").length,q=O===b||O===E,k=O===f||!!x?.includes(O);if(!(q&&k))return q}function l(h,f,b=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(f)===!1)throw new Error("second arg must be public key");let E=r.fromBytes(h),x=t.fromBytes(f);if(x.is0())throw new Error("invalid public key: point at infinity");return x.multiply(E).toBytes(b)}let d={isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:a},g=uc(a,c);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:g,Point:t,utils:d,lengths:o})}function Oc(t,e,r={}){Xt(t);let n=e;zr(n),Et(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),i=o.randomBytes===void 0?Zr:o.randomBytes,s=o.hmac===void 0?(I,p)=>Ic(n,I,p):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:l}=c,d=tn(u),g=ko(i,d),{keygen:h,getPublicKey:f,getSharedSecret:b,utils:E,lengths:x}=rl(t,o),O={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},q=u*vc+Ut<a.ORDER;function k(I){let p=u>>Ut;return I>p}function F(I,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${I}: out of range 1..Point.Fn.ORDER`);return p}function _(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function $(I,p,m){return _(),(I===m?0:2)|Number(a.isOdd(p))}function oe(){if(q)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function ce(I,p){ai(p);let m=x.signature,y=p==="compact"?m:p==="recovered"?m+1:void 0;return X(I,y)}class K{r;s;recovery;constructor(p,m,y){if(this.r=F("r",p),this.s=F("s",m),y!=null){if(oe(),![0,1,2,3].includes(y))throw new Error("invalid recovery id");this.recovery=y}Object.freeze(this)}static fromBytes(p,m=O.format){ce(p,m);let y;if(m==="der"){if(p.length>2*c.BYTES+16)throw new yn.Err("invalid signature: DER signature too long");let{r:T,s:L}=yn.toSig(X(p),c.BYTES+1);return new K(T,L)}m==="recovered"&&(y=p[0],m="compact",p=p.subarray(1));let B=x.signature/2,A=p.subarray(0,B),C=p.subarray(B,B*2);return new K(c.fromBytes(A),c.fromBytes(C),y)}static fromHex(p,m){return this.fromBytes(Xr(p),m)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new K(this.r,this.s,p)}recoverPublicKey(p){let{r:m,s:y}=this,B=this.assertRecovery(),A=B===2||B===3?m+u:m;if(!a.isValid(A))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=a.toBytes(A),T=t.fromBytes(ct(Ac((B&1)===0),C)),L=c.inv(A),P=Ae(X(p,void 0,"msgHash")),U=c.create(-P*L),Y=c.create(y*L),M=t.BASE.mulAddUnsafe(U,T,Y);if(M.is0())throw new Error("invalid recovery: point at infinify");return M.assertValidity(),M}hasHighS(){return k(this.s)}toBytes(p=O.format){if(ai(p),p==="der")return Xr(yn.hexFromSig(this));let{r:m,s:y}=this,B=c.toBytes(m),A=c.toBytes(y);return p==="recovered"?(oe(),ct(Uint8Array.of(this.assertRecovery()),B,A)):ct(B,A)}toHex(p){return Ao(this.toBytes(p))}}Object.freeze(K.prototype),Object.freeze(K);let he=o.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let m=Ye(p),y=p.length*8-l;return y>0?m>>BigInt(y):m}:o.bits2int,Ae=o.bits2int_modN===void 0?function(p){return c.create(he(p))}:o.bits2int_modN,Rt=mr(l);function Tr(I){return Lo("num < 2^"+l,I,ut,Rt),c.toBytes(I)}function Bt(I,p){return X(I,void 0,"message"),p?X(n(I),void 0,"prehashed message"):I}function Lr(I,p,m){let{lowS:y,prehash:B,extraEntropy:A}=si(m,O);I=Bt(I,B);let C=Ae(I),T=c.fromBytes(p);if(!c.isValidNot0(T))throw new Error("invalid private key");let L=[Tr(T),Tr(C)];if(A!=null&&A!==!1){let M=A===!0?i(x.secretKey):A;L.push(X(M,void 0,"extraEntropy"))}let P=ct(...L),U=C;function Y(M){let Q=he(M);if(!c.isValidNot0(Q))return;let Ce=t.BASE.multiply(Q).toAffine(),H=c.create(Ce.x);if(H===ut)return;let G;if(g!==void 0){let rr=Ye(rn(g(d),u)),ha=c.inv(c.mul(rr,Q)),pa=c.mul(rr,U),fa=c.mul(rr,T);G=c.create(ha*c.create(pa+fa*H))}else{let rr=Qs(Q,u);G=c.create(rr*c.create(U+H*T))}if(G===ut)return;let On=$(Ce.x,Ce.y,H),Bi=G;return y&&k(G)&&(Bi=c.neg(G),On^=1),new K(H,Bi,q?void 0:On)}return{seed:P,k2sig:Y}}function R(I,p,m={}){let{seed:y,k2sig:B}=Lr(I,p,m);return zs(n.outputLen,c.BYTES,s)(y,B).toBytes(m.format)}function tr(I,p,m,y={}){let{lowS:B,prehash:A,format:C}=si(y,O);if(m=X(m,void 0,"publicKey"),p=Bt(p,A),!Vt(I)){let T=I instanceof K?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+T)}ce(I,C);try{let T=K.fromBytes(I,C),L=t.fromBytes(m);if(L.is0()||B&&T.hasHighS())return!1;let{r:P,s:U}=T,Y=Ae(p),M=c.inv(U),Q=c.create(Y*M),Ce=c.create(P*M),H=t.BASE.mulAddUnsafe(Q,L,Ce);if(H.is0())return!1;let G=H.toAffine();return!(c.create(G.x)!==P||C==="recovered"&&T.recovery!==$(G.x,G.y,P))}catch{return!1}}function ht(I,p,m={}){let{prehash:y}=si(m,O);return p=Bt(p,y),K.fromBytes(I,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:h,getPublicKey:f,getSharedSecret:b,utils:E,lengths:x,Point:t,sign:R,verify:tr,recoverPublicKey:ht,Signature:K,hash:n})}var di={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},nl={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Tc=BigInt(2);function ol(t){let e=di.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,d=Se(l,r,e)*l%e,g=Se(d,r,e)*l%e,h=Se(g,Tc,e)*u%e,f=Se(h,o,e)*h%e,b=Se(f,i,e)*f%e,E=Se(b,a,e)*b%e,x=Se(E,c,e)*E%e,O=Se(x,a,e)*b%e,q=Se(O,r,e)*l%e,k=Se(q,s,e)*f%e,F=Se(k,n,e)*u%e,_=Se(F,Tc,e);if(!ui.eql(ui.sqr(_),t))throw new Error("Cannot find square root");return _}var ui=Wt(di.p,{sqrt:ol}),il=Bc(di,{Fp:ui,endo:nl}),vr=Oc(il,Ks);var wn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}};function Dc(t,e,r,n){n?.signal?.throwIfAborted();let o=Lc.default.createHash("sha256");if(r instanceof Uint8Array)o.update(r);else for(let s of r)o.update(s);let i=o.digest();try{return vr.verify(e,i,t,{prehash:!1,format:"der"})}catch(s){throw new wn(String(s))}}var bn=class{type="secp256k1";raw;_key;constructor(e){this._key=_c(e),this.raw=Uc(this._key)}toMultihash(){return _e.digest($t(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:fe(this.raw,e.raw)}verify(e,r,n){return Dc(this._key,r,e,n)}};function Pc(t){return new bn(t)}function Uc(t){return vr.Point.fromBytes(t).toBytes()}function _c(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new Ur(String(e))}}function Rc(t){let{Type:e,Data:r}=Sr.decode(t.digest),n=r??new Uint8Array;switch(e){case le.Ed25519:return pc(n);case le.secp256k1:return Pc(n);case le.ECDSA:return Bs(n);default:throw new or}}function $t(t){return Sr.encode({Type:le[t.type],Data:t.raw})}var Nc=Symbol.for("nodejs.util.inspect.custom"),sl=114,Br=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Tn]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return re.createV1(sl,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return fe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return fe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Nc](){return`PeerId(${this.toString()})`}},xn=class extends Br{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},En=class extends Br{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},In=class extends Br{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},cl=2336,Ar=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=_e.digest(de(this.url))}[Nc](){return`PeerId(${this.url})`}[Tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return re.createV1(cl,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=V(e)),e.toString()===this.toString())}};var al=114,Fc=2336;function kc(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=ur(W.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return ul(re.parse(t));if(e==null)throw new Te('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=ur(e.decode(t))}return Kc(r)}function Kc(t){if(ll(t))return new xn({multihash:t});if(dl(t))try{let e=Rc(t);if(e.type==="Ed25519")return new En({multihash:t,publicKey:e});if(e.type==="secp256k1")return new In({multihash:t,publicKey:e})}catch{let r=V(t.digest);return new Ar(new URL(r))}throw new Pr("Supplied PeerID Multihash is invalid")}function ul(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==al&&t.code!==Fc)throw new _r("Supplied PeerID CID is invalid");if(t.code===Fc){let e=V(t.multihash.digest);return new Ar(new URL(e))}return Kc(t.multihash)}function dl(t){return t.code===_e.code}function ll(t){return t.code===ho.code}function hl(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function Mc(t){let e=hl(t);if(e==null)throw new Te(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}var Be=ge("node:net");var $c=nr(zc(),1),bl=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],xl=bl.map(t=>new $c.Netmask(t));function yi(t){for(let e of xl)if(e.contains(t))return!0;return!1}function El(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Il(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return yi(o)}function Sl(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function vl(t){let e=t.split(":"),r=e[e.length-1];return yi(r)}function Bl(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function jc(t){if((0,Be.isIPv4)(t))return yi(t);if(El(t))return Il(t);if(Sl(t))return vl(t);if((0,Be.isIPv6)(t))return Bl(t)}function Vc(t){try{let e=Mc(t);switch(e.type){case"ip4":case"ip6":return jc(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ne=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},dt=class extends Error{static name="ValidationError";name="ValidationError"},vn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Bn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function bi(t){return e=>V(e,t)}function xi(t){return e=>de(e,t)}function er(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Pt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=de(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pt(n);return Pe([r,o],r.length+o.length)}function Gc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=gt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Pt(n);return Pe([r,o],r.length+o.length)}function Ei(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=V(e,"base32"),o=er(r);return`${n}:${o}`}var Ii=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new ne("Invalid byte value in IP address");e[n]=o}),e},Wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let i=(0,Be.isIPv4)(r[n]),s;i&&(s=Ii(r[n]),r[n]=V(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,V(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new ne("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Xc=function(t){if(t.byteLength!==4)throw new ne("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Zc=function(t){if(t.byteLength!==16)throw new ne("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],i=t[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new ne(`Invalid IPv6 address "${r}"`)}};function Qc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new ne(`Invalid IPv6 address "${t}"`)}}var wi=Object.values(lr).map(t=>t.decoder),Al=(function(){let t=wi[0].or(wi[1]);return wi.slice(2).forEach(e=>t=t.or(e)),t})();function Jc(t){return Al.decode(t)}function ea(t){return e=>t.encoder.encode(e)}function Cl(t){if(parseInt(t).toString()!==t)throw new dt("Value must be an integer")}function Ol(t){if(t<0)throw new dt("Value must be a positive integer, or zero")}function Tl(t){return e=>{if(e>t)throw new dt(`Value must be smaller than or equal to ${t}`)}}function Ll(...t){return e=>{for(let r of t)r(e)}}var Cr=Ll(Cl,Ol,Tl(65535));var ee=-1,Si=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Bn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},lt=new Si,mh=[{code:4,name:"ip4",size:32,valueToBytes:Ii,bytesToValue:Xc,validate:t=>{if(!(0,Be.isIPv4)(t))throw new dt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Pt,bytesToValue:er,validate:Cr},{code:273,name:"udp",size:16,valueToBytes:Pt,bytesToValue:er,validate:Cr},{code:33,name:"dccp",size:16,valueToBytes:Pt,bytesToValue:er,validate:Cr},{code:41,name:"ip6",size:128,valueToBytes:Wc,bytesToValue:Zc,stringToValue:Qc,validate:t=>{if(!(0,Be.isIPv6)(t))throw new dt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:ee},{code:43,name:"ipcidr",size:8,bytesToValue:bi("base10"),valueToBytes:xi("base10")},{code:53,name:"dns",size:ee},{code:54,name:"dns4",size:ee},{code:55,name:"dns6",size:ee},{code:56,name:"dnsaddr",size:ee},{code:132,name:"sctp",size:16,valueToBytes:Pt,bytesToValue:er,validate:Cr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ee,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:ee,bytesToValue:bi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?xi("base58btc")(t):re.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Ei,valueToBytes:Yc},{code:445,name:"onion3",size:296,bytesToValue:Ei,valueToBytes:Gc},{code:446,name:"garlic64",size:ee},{code:447,name:"garlic32",size:ee},{code:448,name:"tls"},{code:449,name:"sni",size:ee},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ee,bytesToValue:ea(oo),valueToBytes:Jc},{code:480,name:"http"},{code:481,name:"http-path",size:ee,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ee}];mh.forEach(t=>{lt.addProtocol(t)});function ta(t){let e=[],r=0;for(;r<t.length;){let n=jo(t,r),o=lt.getProtocol(n),i=Ge(n),s=yh(o,t,r+i),a=0;s>0&&o.size===ee&&(a=Ge(s));let c=i+a+s,u={code:n,name:o.name,bytes:mt(t.subarray(r,r+c))};if(s>0){let l=r+i+a,d=t.subarray(l,l+s);u.value=o.bytesToValue?.(d)??V(d)}e.push(u),r+=c}return e}function ra(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=lt.getProtocol(n.code),i=Ge(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??de(n.value),a=s.byteLength,o.size===ee&&(c=Ge(a)));let u=new Uint8Array(i+c+a),l=0;br(n.code,u,l),l+=i,s!=null&&(o.size===ee&&(br(a,u,l),l+=c),u.set(s,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Pe(r,e)}function na(t){if(t.charAt(0)!=="/")throw new ne('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let i=1;i<t.length;i++){let s=t.charAt(i);s!=="/"&&(r==="protocol"?o+=t.charAt(i):n+=t.charAt(i));let a=i===t.length-1;if(s==="/"||a){let c=lt.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new ne(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new ne(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ne("Incomplete multiaddr");return e}function oa(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=lt.getProtocol(e.code);if(r==null)throw new ne(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function yh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:jo(e,r)}var wh=Symbol.for("nodejs.util.inspect.custom"),vi=Symbol.for("@multiformats/multiaddr");function bh(t){if(t==null&&(t="/"),ia(t))return t.getComponents();if(t instanceof Uint8Array)return ta(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),na(t);if(Array.isArray(t))return t;throw new ne("Must be a string, Uint8Array, Component[], or another Multiaddr")}var An=class t{[vi]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=bh(e),r.validate!==!1&&xh(this)}get bytes(){return this.#r==null&&(this.#r=ra(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=oa(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new vn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return fe(this.bytes,e.bytes)}[wh](){return`Multiaddr(${this.toString()})`}};function xh(t){t.getComponents().forEach(e=>{let r=lt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ia(t){return!!t?.[vi]}function sa(t){return new An(t)}function ca(t,e,r,n){let o=()=>{n?.log.trace("query",e),t.query({questions:[{name:e,type:"PTR"}]})};return o(),setInterval(o,r)}function aa(t,e,r,n){if(t.answers==null)return;let o,i=[];if(t.answers.forEach(s=>{switch(s.type){case"PTR":o=s;break;case"TXT":i.push(s);break;default:break}}),t.additionals.forEach(s=>{s.type==="TXT"&&i.push(s)}),!(o==null||o?.name!==r||i.length===0||o.data.startsWith(e)))try{let s=i.flatMap(c=>c.data).filter(c=>c.toString().startsWith("dnsaddr=")).map(c=>sa(c.toString().substring(8))),a=s[0].getComponents().findLast(c=>c.code===421)?.value;if(a==null)throw new Error("Multiaddr doesn't contain PeerId");return n?.log("peer found %p",a),{id:kc(a),multiaddrs:s.map(c=>c.decapsulateCode(421))}}catch(s){n?.log.error("failed to parse mdns response - %e",s)}}function ua(t,e,r,n,o,i,s){if(!i){s?.log("not responding to mDNS query as broadcast mode is false");return}if(n.length!==0&&t.questions[0]!=null&&t.questions[0].name===o){let a=[];a.push({name:o,type:"PTR",class:"IN",ttl:120,data:r+"."+o}),n.filter(Eh).forEach(c=>{let u="dnsaddr="+c.toString();if(u.length>255){s?.log("multiaddr %a is too long to use in mDNS query response",c);return}if(c.getComponents().findLast(l=>l.code===421)?.value==null){s?.log("multiaddr %a did not have a peer ID so cannot be used in mDNS query response",c);return}a.push({name:r+"."+o,type:"TXT",class:"IN",ttl:120,data:u})}),s?.log.trace("responding to query"),e.respond(a)}}function Eh(t){return!!Vc(t)}function da(t){let e="",r="abcdefghijklmnopqrstuvwxyz0123456789";for(let n=0;n<t;n++)e+=r.charAt(Math.floor(Math.random()*r.length));return e}var Cn=class extends Rr{mdns;log;broadcast;interval;serviceTag;peerName;port;ip;_queryInterval;components;constructor(e,r={}){if(super(),this.log=e.logger.forComponent("libp2p:mdns"),this.broadcast=r.broadcast!==!1,this.interval=r.interval??1e3*10,this.serviceTag=r.serviceTag??"_p2p._udp.local",this.ip=r.ip??"224.0.0.251",this.peerName=r.peerName??da(63),this.peerName.length>=64)throw new Error("Peer name should be less than 64 chars long");this.port=r.port??5353,this.components=e,this._queryInterval=null,this._onMdnsQuery=this._onMdnsQuery.bind(this),this._onMdnsResponse=this._onMdnsResponse.bind(this),this._onMdnsWarning=this._onMdnsWarning.bind(this),this._onMdnsError=this._onMdnsError.bind(this)}[Ci]=this;[Symbol.toStringTag]="@libp2p/mdns";[Di]=["@libp2p/peer-discovery"];isStarted(){return!!this.mdns}async start(){this.mdns==null&&(this.mdns=(0,la.default)({port:this.port,ip:this.ip}),this.mdns.on("query",this._onMdnsQuery),this.mdns.on("response",this._onMdnsResponse),this.mdns.on("warning",this._onMdnsWarning),this.mdns.on("error",this._onMdnsError),this._queryInterval=ca(this.mdns,this.serviceTag,this.interval,{log:this.log}))}_onMdnsQuery(e){this.mdns!=null&&(this.log.trace("received incoming mDNS query"),ua(e,this.mdns,this.peerName,this.components.addressManager.getAddresses(),this.serviceTag,this.broadcast,{log:this.log}))}_onMdnsResponse(e){this.log.trace("received mDNS query response");try{let r=aa(e,this.peerName,this.serviceTag,{log:this.log});r!=null&&(this.log("discovered peer in mDNS query response %p",r.id),this.dispatchEvent(new CustomEvent("peer",{detail:r})))}catch(r){this.log.error("error processing peer response - %e",r)}}_onMdnsWarning(e){this.log.error("mdns warning - %e",e)}_onMdnsError(e){this.log.error("mdns error - %e",e)}async stop(){this.mdns!=null&&(this.mdns.removeListener("query",this._onMdnsQuery),this.mdns.removeListener("response",this._onMdnsResponse),this.mdns.removeListener("warning",this._onMdnsWarning),this.mdns.removeListener("error",this._onMdnsError),this._queryInterval!=null&&(clearInterval(this._queryInterval),this._queryInterval=null),await new Promise(e=>{this.mdns!=null?this.mdns.destroy(e):e()}),this.mdns=void 0)}};function Sh(t={}){return e=>new Cn(e,t)}return xa(vh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: