nostr-crypto-utils 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/crypto.nostr-crypto-utils.min.js +15 -1
- package/dist/browser/crypto.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/main.nostr-crypto-utils.min.js +32 -0
- package/dist/browser/main.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/nip-44.nostr-crypto-utils.min.js +21 -2
- package/dist/browser/nip-44.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/nip-46.nostr-crypto-utils.min.js +21 -2
- package/dist/browser/nip-46.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/nip-49.nostr-crypto-utils.min.js +13 -1
- package/dist/browser/nip-49.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/protocol.nostr-crypto-utils.min.js +2 -1
- package/dist/browser/protocol.nostr-crypto-utils.min.js.map +7 -0
- package/dist/browser/validation.nostr-crypto-utils.min.js +15 -1
- package/dist/browser/validation.nostr-crypto-utils.min.js.map +7 -0
- package/package.json +4 -7
- package/dist/browser/116.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/116.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/126.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/126.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
- package/dist/browser/287.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/287.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
- package/dist/browser/343.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/348.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/348.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/524.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/575.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/575.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/615.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/615.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/668.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/668.nostr-crypto-utils.min.js.LICENSE.txt +0 -6
- package/dist/browser/705.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/705.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/732.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/843.nostr-crypto-utils.min.js +0 -2
- package/dist/browser/843.nostr-crypto-utils.min.js.LICENSE.txt +0 -3
- package/dist/browser/main-31743c5a.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/main-96d4916e.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/main-9fdc67c2.nostr-crypto-utils.min.js +0 -1
- package/dist/browser/nip-44.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
- package/dist/browser/nip-46.nostr-crypto-utils.min.js.LICENSE.txt +0 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";var NostrCryptoUtils=(()=>{var ps=Object.create;var Se=Object.defineProperty;var ys=Object.getOwnPropertyDescriptor;var gs=Object.getOwnPropertyNames;var xs=Object.getPrototypeOf,bs=Object.prototype.hasOwnProperty;var ms=(e,t,r)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ws=(e,t)=>()=>(e&&(t=e(e=0)),t);var ne=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),kt=(e,t)=>{for(var r in t)Se(e,r,{get:t[r],enumerable:!0})},to=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gs(t))!bs.call(e,o)&&o!==r&&Se(e,o,{get:()=>t[o],enumerable:!(n=ys(t,o))||n.enumerable});return e};var Tr=(e,t,r)=>(r=e!=null?ps(xs(e)):{},to(t||!e||!e.__esModule?Se(r,"default",{value:e,enumerable:!0}):r,e)),Es=e=>to(Se({},"__esModule",{value:!0}),e);var st=(e,t,r)=>ms(e,typeof t!="symbol"?t+"":t,r);var Vo=ne((ku,Do)=>{"use strict";function Js(e){try{return JSON.stringify(e)}catch{return'"[Circular]"'}}Do.exports=Qs;function Qs(e,t,r){var n=r&&r.stringify||Js,o=1;if(typeof e=="object"&&e!==null){var i=t.length+o;if(i===1)return e;var s=new Array(i);s[0]=n(e);for(var c=1;c<i;c++)s[c]=n(t[c]);return s.join(" ")}if(typeof e!="string")return e;var a=t.length;if(a===0)return e;for(var f="",u=1-o,l=-1,d=e&&e.length||0,h=0;h<d;){if(e.charCodeAt(h)===37&&h+1<d){switch(l=l>-1?l:0,e.charCodeAt(h+1)){case 100:case 102:if(u>=a||t[u]==null)break;l<h&&(f+=e.slice(l,h)),f+=Number(t[u]),l=h+2,h++;break;case 105:if(u>=a||t[u]==null)break;l<h&&(f+=e.slice(l,h)),f+=Math.floor(Number(t[u])),l=h+2,h++;break;case 79:case 111:case 106:if(u>=a||t[u]===void 0)break;l<h&&(f+=e.slice(l,h));var x=typeof t[u];if(x==="string"){f+="'"+t[u]+"'",l=h+2,h++;break}if(x==="function"){f+=t[u].name||"<anonymous>",l=h+2,h++;break}f+=n(t[u]),l=h+2,h++;break;case 115:if(u>=a)break;l<h&&(f+=e.slice(l,h)),f+=String(t[u]),l=h+2,h++;break;case 37:l<h&&(f+=e.slice(l,h)),f+="%",l=h+2,h++,u--;break}++u}++h}return l===-1?e:(l<d&&(f+=e.slice(l)),f)}});var zo=ne((Ru,sr)=>{"use strict";var Fo=Vo();sr.exports=Dt;var _e=pc().console||{},tc={mapHttpRequest:nr,mapHttpResponse:nr,wrapRequestSerializer:Yr,wrapResponseSerializer:Yr,wrapErrorSerializer:Yr,req:nr,res:nr,err:qo,errWithCause:qo};function or(e,t){return e==="silent"?1/0:t.levels.values[e]}var Qr=Symbol("pino.logFuncs"),Xr=Symbol("pino.hierarchy"),ec={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Mo(e,t){let r={logger:t,parent:e[Xr]};t[Xr]=r}function rc(e,t,r){let n={};t.forEach(o=>{n[o]=r[o]?r[o]:_e[o]||_e[ec[o]||"log"]||Ne}),e[Qr]=n}function nc(e,t){return Array.isArray(e)?e.filter(function(n){return n!=="!stdSerializers.err"}):e===!0?Object.keys(t):!1}function Dt(e){e=e||{},e.browser=e.browser||{};let t=e.browser.transmit;if(t&&typeof t.send!="function")throw Error("pino: transmit option must have a send function");let r=e.browser.write||_e;e.browser.write&&(e.browser.asObject=!0);let n=e.serializers||{},o=nc(e.browser.serialize,n),i=e.browser.serialize;Array.isArray(e.browser.serialize)&&e.browser.serialize.indexOf("!stdSerializers.err")>-1&&(i=!1);let s=Object.keys(e.customLevels||{}),c=["error","fatal","warn","info","debug","trace"].concat(s);typeof r=="function"&&c.forEach(function(y){r[y]=r}),(e.enabled===!1||e.browser.disabled)&&(e.level="silent");let a=e.level||"info",f=Object.create(r);f.log||(f.log=Ne),rc(f,c,r),Mo({},f),Object.defineProperty(f,"levelVal",{get:l}),Object.defineProperty(f,"level",{get:d,set:h});let u={transmit:t,serialize:o,asObject:e.browser.asObject,formatters:e.browser.formatters,levels:c,timestamp:lc(e)};f.levels=oc(e),f.level=a,f.setMaxListeners=f.getMaxListeners=f.emit=f.addListener=f.on=f.prependListener=f.once=f.prependOnceListener=f.removeListener=f.removeAllListeners=f.listeners=f.listenerCount=f.eventNames=f.write=f.flush=Ne,f.serializers=n,f._serialize=o,f._stdErrSerialize=i,f.child=x,t&&(f._logEvent=Jr());function l(){return or(this.level,this)}function d(){return this._level}function h(y){if(y!=="silent"&&!this.levels.values[y])throw Error("unknown level "+y);this._level=y,Qt(this,u,f,"error"),Qt(this,u,f,"fatal"),Qt(this,u,f,"warn"),Qt(this,u,f,"info"),Qt(this,u,f,"debug"),Qt(this,u,f,"trace"),s.forEach(B=>{Qt(this,u,f,B)})}function x(y,B){if(!y)throw new Error("missing bindings for child Pino");B=B||{},o&&y.serializers&&(B.serializers=y.serializers);let I=B.serializers;if(o&&I){var L=Object.assign({},n,I),N=e.browser.serialize===!0?Object.keys(L):o;delete y.serializers,ir([y],N,L,this._stdErrSerialize)}function D(O){this._childLevel=(O._childLevel|0)+1,this.bindings=y,L&&(this.serializers=L,this._serialize=N),t&&(this._logEvent=Jr([].concat(O._logEvent.bindings,y)))}D.prototype=this;let K=new D(this);return Mo(this,K),K.level=this.level,K}return f}function oc(e){let t=e.customLevels||{},r=Object.assign({},Dt.levels.values,t),n=Object.assign({},Dt.levels.labels,ic(t));return{values:r,labels:n}}function ic(e){let t={};return Object.keys(e).forEach(function(r){t[e[r]]=r}),t}Dt.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}};Dt.stdSerializers=tc;Dt.stdTimeFunctions=Object.assign({},{nullTime:$o,epochTime:jo,unixTime:dc,isoTime:hc});function sc(e){let t=[];e.bindings&&t.push(e.bindings);let r=e[Xr];for(;r.parent;)r=r.parent,r.logger.bindings&&t.push(r.logger.bindings);return t.reverse()}function Qt(e,t,r,n){if(Object.defineProperty(e,n,{value:or(e.level,r)>or(n,r)?Ne:r[Qr][n],writable:!0,enumerable:!0,configurable:!0}),!t.transmit&&e[n]===Ne)return;e[n]=ac(e,t,r,n);let o=sc(e);o.length!==0&&(e[n]=cc(o,e[n]))}function cc(e,t){return function(){return t.apply(this,[...e,...arguments])}}function ac(e,t,r,n){return(function(o){return function(){let s=t.timestamp(),c=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===_e?_e:this;for(var f=0;f<c.length;f++)c[f]=arguments[f];if(t.serialize&&!t.asObject&&ir(c,this._serialize,this.serializers,this._stdErrSerialize),t.asObject||t.formatters?o.call(a,fc(this,n,c,s,t.formatters)):o.apply(a,c),t.transmit){let u=t.transmit.level||e._level,l=r.levels.values[u],d=r.levels.values[n];if(d<l)return;uc(this,{ts:s,methodLevel:n,methodValue:d,transmitLevel:u,transmitValue:r.levels.values[t.transmit.level||e._level],send:t.transmit.send,val:or(e._level,r)},c)}}})(e[Qr][n])}function fc(e,t,r,n,o={}){let{level:i=()=>e.levels.values[t],log:s=d=>d}=o;e._serialize&&ir(r,e._serialize,e.serializers,e._stdErrSerialize);let c=r.slice(),a=c[0],f={};n&&(f.time=n),f.level=i(t,e.levels.values[t]);let u=(e._childLevel|0)+1;if(u<1&&(u=1),a!==null&&typeof a=="object"){for(;u--&&typeof c[0]=="object";)Object.assign(f,c.shift());a=c.length?Fo(c.shift(),c):void 0}else typeof a=="string"&&(a=Fo(c.shift(),c));return a!==void 0&&(f.msg=a),s(f)}function ir(e,t,r,n){for(let o in e)if(n&&e[o]instanceof Error)e[o]=Dt.stdSerializers.err(e[o]);else if(typeof e[o]=="object"&&!Array.isArray(e[o]))for(let i in e[o])t&&t.indexOf(i)>-1&&i in r&&(e[o][i]=r[i](e[o][i]))}function uc(e,t,r){let n=t.send,o=t.ts,i=t.methodLevel,s=t.methodValue,c=t.val,a=e._logEvent.bindings;ir(r,e._serialize||Object.keys(e.serializers),e.serializers,e._stdErrSerialize===void 0?!0:e._stdErrSerialize),e._logEvent.ts=o,e._logEvent.messages=r.filter(function(f){return a.indexOf(f)===-1}),e._logEvent.level.label=i,e._logEvent.level.value=s,n(i,e._logEvent,c),e._logEvent=Jr(a)}function Jr(e){return{ts:0,messages:[],bindings:e||[],level:{label:"",value:0}}}function qo(e){let t={type:e.constructor.name,msg:e.message,stack:e.stack};for(let r in e)t[r]===void 0&&(t[r]=e[r]);return t}function lc(e){return typeof e.timestamp=="function"?e.timestamp:e.timestamp===!1?$o:jo}function nr(){return{}}function Yr(e){return e}function Ne(){}function $o(){return!1}function jo(){return Date.now()}function dc(){return Math.round(Date.now()/1e3)}function hc(){return new Date(Date.now()).toISOString()}function pc(){function e(t){return typeof t<"u"&&t}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return e(self)||e(window)||e(this)||{}}}sr.exports.default=Dt;sr.exports.pino=Dt});var tn={};kt(tn,{default:()=>gc});var gc,en=ws(()=>{gc={}});var li=ne(xe=>{"use strict";Object.defineProperty(xe,"__esModule",{value:!0});xe.bech32m=xe.bech32=void 0;var dr="qpzry9x8gf2tvdw0s3jn54khce6mua7l",fi={};for(let e=0;e<dr.length;e++){let t=dr.charAt(e);fi[t]=e}function ge(e){let t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function ai(e){let t=1;for(let r=0;r<e.length;++r){let n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=ge(t)^n>>5}t=ge(t);for(let r=0;r<e.length;++r){let n=e.charCodeAt(r);t=ge(t)^n&31}return t}function xn(e,t,r,n){let o=0,i=0,s=(1<<r)-1,c=[];for(let a=0;a<e.length;++a)for(o=o<<t|e[a],i+=t;i>=r;)i-=r,c.push(o>>i&s);if(n)i>0&&c.push(o<<r-i&s);else{if(i>=t)return"Excess padding";if(o<<r-i&s)return"Non-zero padding"}return c}function Sc(e){return xn(e,8,5,!0)}function Ic(e){let t=xn(e,5,8,!1);if(Array.isArray(t))return t}function vc(e){let t=xn(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function ui(e){let t;e==="bech32"?t=1:t=734539939;function r(s,c,a){if(a=a||90,s.length+7+c.length>a)throw new TypeError("Exceeds length limit");s=s.toLowerCase();let f=ai(s);if(typeof f=="string")throw new Error(f);let u=s+"1";for(let l=0;l<c.length;++l){let d=c[l];if(d>>5!==0)throw new Error("Non 5-bit word");f=ge(f)^d,u+=dr.charAt(d)}for(let l=0;l<6;++l)f=ge(f);f^=t;for(let l=0;l<6;++l){let d=f>>(5-l)*5&31;u+=dr.charAt(d)}return u}function n(s,c){if(c=c||90,s.length<8)return s+" too short";if(s.length>c)return"Exceeds length limit";let a=s.toLowerCase(),f=s.toUpperCase();if(s!==a&&s!==f)return"Mixed-case string "+s;s=a;let u=s.lastIndexOf("1");if(u===-1)return"No separator character for "+s;if(u===0)return"Missing prefix for "+s;let l=s.slice(0,u),d=s.slice(u+1);if(d.length<6)return"Data too short";let h=ai(l);if(typeof h=="string")return h;let x=[];for(let y=0;y<d.length;++y){let B=d.charAt(y),I=fi[B];if(I===void 0)return"Unknown character "+B;h=ge(h)^I,!(y+6>=d.length)&&x.push(I)}return h!==t?"Invalid checksum for "+s:{prefix:l,words:x}}function o(s,c){let a=n(s,c);if(typeof a=="object")return a}function i(s,c){let a=n(s,c);if(typeof a=="object")return a;throw new Error(a)}return{decodeUnsafe:o,decode:i,encode:r,toWords:Sc,fromWordsUnsafe:Ic,fromWords:vc}}xe.bech32=ui("bech32");xe.bech32m=ui("bech32m")});var pi=ne(hr=>{"use strict";hr.byteLength=Uc;hr.toByteArray=Rc;hr.fromByteArray=Lc;var St=[],bt=[],Tc=typeof Uint8Array<"u"?Uint8Array:Array,bn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(te=0,di=bn.length;te<di;++te)St[te]=bn[te],bt[bn.charCodeAt(te)]=te;var te,di;bt[45]=62;bt[95]=63;function hi(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Uc(e){var t=hi(e),r=t[0],n=t[1];return(r+n)*3/4-n}function kc(e,t,r){return(t+r)*3/4-r}function Rc(e){var t,r=hi(e),n=r[0],o=r[1],i=new Tc(kc(e,n,o)),s=0,c=o>0?n-4:n,a;for(a=0;a<c;a+=4)t=bt[e.charCodeAt(a)]<<18|bt[e.charCodeAt(a+1)]<<12|bt[e.charCodeAt(a+2)]<<6|bt[e.charCodeAt(a+3)],i[s++]=t>>16&255,i[s++]=t>>8&255,i[s++]=t&255;return o===2&&(t=bt[e.charCodeAt(a)]<<2|bt[e.charCodeAt(a+1)]>>4,i[s++]=t&255),o===1&&(t=bt[e.charCodeAt(a)]<<10|bt[e.charCodeAt(a+1)]<<4|bt[e.charCodeAt(a+2)]>>2,i[s++]=t>>8&255,i[s++]=t&255),i}function _c(e){return St[e>>18&63]+St[e>>12&63]+St[e>>6&63]+St[e&63]}function Nc(e,t,r){for(var n,o=[],i=t;i<r;i+=3)n=(e[i]<<16&16711680)+(e[i+1]<<8&65280)+(e[i+2]&255),o.push(_c(n));return o.join("")}function Lc(e){for(var t,r=e.length,n=r%3,o=[],i=16383,s=0,c=r-n;s<c;s+=i)o.push(Nc(e,s,s+i>c?c:s+i));return n===1?(t=e[r-1],o.push(St[t>>2]+St[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],o.push(St[t>>10]+St[t>>4&63]+St[t<<2&63]+"=")),o.join("")}});var yi=ne(mn=>{mn.read=function(e,t,r,n,o){var i,s,c=o*8-n-1,a=(1<<c)-1,f=a>>1,u=-7,l=r?o-1:0,d=r?-1:1,h=e[t+l];for(l+=d,i=h&(1<<-u)-1,h>>=-u,u+=c;u>0;i=i*256+e[t+l],l+=d,u-=8);for(s=i&(1<<-u)-1,i>>=-u,u+=n;u>0;s=s*256+e[t+l],l+=d,u-=8);if(i===0)i=1-f;else{if(i===a)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-f}return(h?-1:1)*s*Math.pow(2,i-n)};mn.write=function(e,t,r,n,o,i){var s,c,a,f=i*8-o-1,u=(1<<f)-1,l=u>>1,d=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:i-1,x=n?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(c=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(a=Math.pow(2,-s))<1&&(s--,a*=2),s+l>=1?t+=d/a:t+=d*Math.pow(2,1-l),t*a>=2&&(s++,a/=2),s+l>=u?(c=0,s=u):s+l>=1?(c=(t*a-1)*Math.pow(2,o),s=s+l):(c=t*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;e[r+h]=c&255,h+=x,c/=256,o-=8);for(s=s<<o|c,f+=o;f>0;e[r+h]=s&255,h+=x,s/=256,f-=8);e[r+h-x]|=y*128}});var Ni=ne(Ee=>{"use strict";var wn=pi(),me=yi(),gi=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Ee.Buffer=b;Ee.SlowBuffer=Vc;Ee.INSPECT_MAX_BYTES=50;var pr=2147483647;Ee.kMaxLength=pr;b.TYPED_ARRAY_SUPPORT=Cc();!b.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function Cc(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(b.prototype,"parent",{enumerable:!0,get:function(){if(b.isBuffer(this))return this.buffer}});Object.defineProperty(b.prototype,"offset",{enumerable:!0,get:function(){if(b.isBuffer(this))return this.byteOffset}});function Vt(e){if(e>pr)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,b.prototype),t}function b(e,t,r){if(typeof e=="number"){if(typeof t=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Sn(e)}return wi(e,t,r)}b.poolSize=8192;function wi(e,t,r){if(typeof e=="string")return Pc(e,t);if(ArrayBuffer.isView(e))return Hc(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(It(e,ArrayBuffer)||e&&It(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(It(e,SharedArrayBuffer)||e&&It(e.buffer,SharedArrayBuffer)))return Bn(e,t,r);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=e.valueOf&&e.valueOf();if(n!=null&&n!==e)return b.from(n,t,r);let o=Dc(e);if(o)return o;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return b.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}b.from=function(e,t,r){return wi(e,t,r)};Object.setPrototypeOf(b.prototype,Uint8Array.prototype);Object.setPrototypeOf(b,Uint8Array);function Ei(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function Oc(e,t,r){return Ei(e),e<=0?Vt(e):t!==void 0?typeof r=="string"?Vt(e).fill(t,r):Vt(e).fill(t):Vt(e)}b.alloc=function(e,t,r){return Oc(e,t,r)};function Sn(e){return Ei(e),Vt(e<0?0:In(e)|0)}b.allocUnsafe=function(e){return Sn(e)};b.allocUnsafeSlow=function(e){return Sn(e)};function Pc(e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!b.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let r=Bi(e,t)|0,n=Vt(r),o=n.write(e,t);return o!==r&&(n=n.slice(0,o)),n}function En(e){let t=e.length<0?0:In(e.length)|0,r=Vt(t);for(let n=0;n<t;n+=1)r[n]=e[n]&255;return r}function Hc(e){if(It(e,Uint8Array)){let t=new Uint8Array(e);return Bn(t.buffer,t.byteOffset,t.byteLength)}return En(e)}function Bn(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return t===void 0&&r===void 0?n=new Uint8Array(e):r===void 0?n=new Uint8Array(e,t):n=new Uint8Array(e,t,r),Object.setPrototypeOf(n,b.prototype),n}function Dc(e){if(b.isBuffer(e)){let t=In(e.length)|0,r=Vt(t);return r.length===0||e.copy(r,0,0,t),r}if(e.length!==void 0)return typeof e.length!="number"||Tn(e.length)?Vt(0):En(e);if(e.type==="Buffer"&&Array.isArray(e.data))return En(e.data)}function In(e){if(e>=pr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+pr.toString(16)+" bytes");return e|0}function Vc(e){return+e!=e&&(e=0),b.alloc(+e)}b.isBuffer=function(t){return t!=null&&t._isBuffer===!0&&t!==b.prototype};b.compare=function(t,r){if(It(t,Uint8Array)&&(t=b.from(t,t.offset,t.byteLength)),It(r,Uint8Array)&&(r=b.from(r,r.offset,r.byteLength)),!b.isBuffer(t)||!b.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===r)return 0;let n=t.length,o=r.length;for(let i=0,s=Math.min(n,o);i<s;++i)if(t[i]!==r[i]){n=t[i],o=r[i];break}return n<o?-1:o<n?1:0};b.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};b.concat=function(t,r){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return b.alloc(0);let n;if(r===void 0)for(r=0,n=0;n<t.length;++n)r+=t[n].length;let o=b.allocUnsafe(r),i=0;for(n=0;n<t.length;++n){let s=t[n];if(It(s,Uint8Array))i+s.length>o.length?(b.isBuffer(s)||(s=b.from(s)),s.copy(o,i)):Uint8Array.prototype.set.call(o,s,i);else if(b.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function Bi(e,t){if(b.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||It(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let r=e.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return An(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return _i(e).length;default:if(o)return n?-1:An(e).length;t=(""+t).toLowerCase(),o=!0}}b.byteLength=Bi;function Fc(e,t,r){let n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Yc(this,t,r);case"utf8":case"utf-8":return Si(this,t,r);case"ascii":return Wc(this,t,r);case"latin1":case"binary":return Zc(this,t,r);case"base64":return Gc(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Xc(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}b.prototype._isBuffer=!0;function ee(e,t,r){let n=e[t];e[t]=e[r],e[r]=n}b.prototype.swap16=function(){let t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let r=0;r<t;r+=2)ee(this,r,r+1);return this};b.prototype.swap32=function(){let t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let r=0;r<t;r+=4)ee(this,r,r+3),ee(this,r+1,r+2);return this};b.prototype.swap64=function(){let t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let r=0;r<t;r+=8)ee(this,r,r+7),ee(this,r+1,r+6),ee(this,r+2,r+5),ee(this,r+3,r+4);return this};b.prototype.toString=function(){let t=this.length;return t===0?"":arguments.length===0?Si(this,0,t):Fc.apply(this,arguments)};b.prototype.toLocaleString=b.prototype.toString;b.prototype.equals=function(t){if(!b.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:b.compare(this,t)===0};b.prototype.inspect=function(){let t="",r=Ee.INSPECT_MAX_BYTES;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"};gi&&(b.prototype[gi]=b.prototype.inspect);b.prototype.compare=function(t,r,n,o,i){if(It(t,Uint8Array)&&(t=b.from(t,t.offset,t.byteLength)),!b.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(r===void 0&&(r=0),n===void 0&&(n=t?t.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),r<0||n>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,o>>>=0,i>>>=0,this===t)return 0;let s=i-o,c=n-r,a=Math.min(s,c),f=this.slice(o,i),u=t.slice(r,n);for(let l=0;l<a;++l)if(f[l]!==u[l]){s=f[l],c=u[l];break}return s<c?-1:c<s?1:0};function Ai(e,t,r,n,o){if(e.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,Tn(r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0)if(o)r=0;else return-1;if(typeof t=="string"&&(t=b.from(t,n)),b.isBuffer(t))return t.length===0?-1:xi(e,t,r,n,o);if(typeof t=="number")return t=t&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):xi(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function xi(e,t,r,n,o){let i=1,s=e.length,c=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||t.length<2)return-1;i=2,s/=2,c/=2,r/=2}function a(u,l){return i===1?u[l]:u.readUInt16BE(l*i)}let f;if(o){let u=-1;for(f=r;f<s;f++)if(a(e,f)===a(t,u===-1?0:f-u)){if(u===-1&&(u=f),f-u+1===c)return u*i}else u!==-1&&(f-=f-u),u=-1}else for(r+c>s&&(r=s-c),f=r;f>=0;f--){let u=!0;for(let l=0;l<c;l++)if(a(e,f+l)!==a(t,l)){u=!1;break}if(u)return f}return-1}b.prototype.includes=function(t,r,n){return this.indexOf(t,r,n)!==-1};b.prototype.indexOf=function(t,r,n){return Ai(this,t,r,n,!0)};b.prototype.lastIndexOf=function(t,r,n){return Ai(this,t,r,n,!1)};function Mc(e,t,r,n){r=Number(r)||0;let o=e.length-r;n?(n=Number(n),n>o&&(n=o)):n=o;let i=t.length;n>i/2&&(n=i/2);let s;for(s=0;s<n;++s){let c=parseInt(t.substr(s*2,2),16);if(Tn(c))return s;e[r+s]=c}return s}function qc(e,t,r,n){return yr(An(t,e.length-r),e,r,n)}function $c(e,t,r,n){return yr(ea(t),e,r,n)}function jc(e,t,r,n){return yr(_i(t),e,r,n)}function zc(e,t,r,n){return yr(ra(t,e.length-r),e,r,n)}b.prototype.write=function(t,r,n,o){if(r===void 0)o="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")o=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,o===void 0&&(o="utf8")):(o=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let i=this.length-r;if((n===void 0||n>i)&&(n=i),t.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let s=!1;for(;;)switch(o){case"hex":return Mc(this,t,r,n);case"utf8":case"utf-8":return qc(this,t,r,n);case"ascii":case"latin1":case"binary":return $c(this,t,r,n);case"base64":return jc(this,t,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return zc(this,t,r,n);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};b.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Gc(e,t,r){return t===0&&r===e.length?wn.fromByteArray(e):wn.fromByteArray(e.slice(t,r))}function Si(e,t,r){r=Math.min(e.length,r);let n=[],o=t;for(;o<r;){let i=e[o],s=null,c=i>239?4:i>223?3:i>191?2:1;if(o+c<=r){let a,f,u,l;switch(c){case 1:i<128&&(s=i);break;case 2:a=e[o+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(s=l));break;case 3:a=e[o+1],f=e[o+2],(a&192)===128&&(f&192)===128&&(l=(i&15)<<12|(a&63)<<6|f&63,l>2047&&(l<55296||l>57343)&&(s=l));break;case 4:a=e[o+1],f=e[o+2],u=e[o+3],(a&192)===128&&(f&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(f&63)<<6|u&63,l>65535&&l<1114112&&(s=l))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),o+=c}return Kc(n)}var bi=4096;function Kc(e){let t=e.length;if(t<=bi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=bi));return r}function Wc(e,t,r){let n="";r=Math.min(e.length,r);for(let o=t;o<r;++o)n+=String.fromCharCode(e[o]&127);return n}function Zc(e,t,r){let n="";r=Math.min(e.length,r);for(let o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function Yc(e,t,r){let n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let o="";for(let i=t;i<r;++i)o+=na[e[i]];return o}function Xc(e,t,r){let n=e.slice(t,r),o="";for(let i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+n[i+1]*256);return o}b.prototype.slice=function(t,r){let n=this.length;t=~~t,r=r===void 0?n:~~r,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<t&&(r=t);let o=this.subarray(t,r);return Object.setPrototypeOf(o,b.prototype),o};function ot(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}b.prototype.readUintLE=b.prototype.readUIntLE=function(t,r,n){t=t>>>0,r=r>>>0,n||ot(t,r,this.length);let o=this[t],i=1,s=0;for(;++s<r&&(i*=256);)o+=this[t+s]*i;return o};b.prototype.readUintBE=b.prototype.readUIntBE=function(t,r,n){t=t>>>0,r=r>>>0,n||ot(t,r,this.length);let o=this[t+--r],i=1;for(;r>0&&(i*=256);)o+=this[t+--r]*i;return o};b.prototype.readUint8=b.prototype.readUInt8=function(t,r){return t=t>>>0,r||ot(t,1,this.length),this[t]};b.prototype.readUint16LE=b.prototype.readUInt16LE=function(t,r){return t=t>>>0,r||ot(t,2,this.length),this[t]|this[t+1]<<8};b.prototype.readUint16BE=b.prototype.readUInt16BE=function(t,r){return t=t>>>0,r||ot(t,2,this.length),this[t]<<8|this[t+1]};b.prototype.readUint32LE=b.prototype.readUInt32LE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};b.prototype.readUint32BE=b.prototype.readUInt32BE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};b.prototype.readBigUInt64LE=Wt(function(t){t=t>>>0,we(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Oe(t,this.length-8);let o=r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24,i=this[++t]+this[++t]*2**8+this[++t]*2**16+n*2**24;return BigInt(o)+(BigInt(i)<<BigInt(32))});b.prototype.readBigUInt64BE=Wt(function(t){t=t>>>0,we(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Oe(t,this.length-8);let o=r*2**24+this[++t]*2**16+this[++t]*2**8+this[++t],i=this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n;return(BigInt(o)<<BigInt(32))+BigInt(i)});b.prototype.readIntLE=function(t,r,n){t=t>>>0,r=r>>>0,n||ot(t,r,this.length);let o=this[t],i=1,s=0;for(;++s<r&&(i*=256);)o+=this[t+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*r)),o};b.prototype.readIntBE=function(t,r,n){t=t>>>0,r=r>>>0,n||ot(t,r,this.length);let o=r,i=1,s=this[t+--o];for(;o>0&&(i*=256);)s+=this[t+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*r)),s};b.prototype.readInt8=function(t,r){return t=t>>>0,r||ot(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};b.prototype.readInt16LE=function(t,r){t=t>>>0,r||ot(t,2,this.length);let n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n};b.prototype.readInt16BE=function(t,r){t=t>>>0,r||ot(t,2,this.length);let n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n};b.prototype.readInt32LE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};b.prototype.readInt32BE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};b.prototype.readBigInt64LE=Wt(function(t){t=t>>>0,we(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Oe(t,this.length-8);let o=this[t+4]+this[t+5]*2**8+this[t+6]*2**16+(n<<24);return(BigInt(o)<<BigInt(32))+BigInt(r+this[++t]*2**8+this[++t]*2**16+this[++t]*2**24)});b.prototype.readBigInt64BE=Wt(function(t){t=t>>>0,we(t,"offset");let r=this[t],n=this[t+7];(r===void 0||n===void 0)&&Oe(t,this.length-8);let o=(r<<24)+this[++t]*2**16+this[++t]*2**8+this[++t];return(BigInt(o)<<BigInt(32))+BigInt(this[++t]*2**24+this[++t]*2**16+this[++t]*2**8+n)});b.prototype.readFloatLE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),me.read(this,t,!0,23,4)};b.prototype.readFloatBE=function(t,r){return t=t>>>0,r||ot(t,4,this.length),me.read(this,t,!1,23,4)};b.prototype.readDoubleLE=function(t,r){return t=t>>>0,r||ot(t,8,this.length),me.read(this,t,!0,52,8)};b.prototype.readDoubleBE=function(t,r){return t=t>>>0,r||ot(t,8,this.length),me.read(this,t,!1,52,8)};function dt(e,t,r,n,o,i){if(!b.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}b.prototype.writeUintLE=b.prototype.writeUIntLE=function(t,r,n,o){if(t=+t,r=r>>>0,n=n>>>0,!o){let c=Math.pow(2,8*n)-1;dt(this,t,r,n,c,0)}let i=1,s=0;for(this[r]=t&255;++s<n&&(i*=256);)this[r+s]=t/i&255;return r+n};b.prototype.writeUintBE=b.prototype.writeUIntBE=function(t,r,n,o){if(t=+t,r=r>>>0,n=n>>>0,!o){let c=Math.pow(2,8*n)-1;dt(this,t,r,n,c,0)}let i=n-1,s=1;for(this[r+i]=t&255;--i>=0&&(s*=256);)this[r+i]=t/s&255;return r+n};b.prototype.writeUint8=b.prototype.writeUInt8=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,1,255,0),this[r]=t&255,r+1};b.prototype.writeUint16LE=b.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,2,65535,0),this[r]=t&255,this[r+1]=t>>>8,r+2};b.prototype.writeUint16BE=b.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=t&255,r+2};b.prototype.writeUint32LE=b.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255,r+4};b.prototype.writeUint32BE=b.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};function Ii(e,t,r,n,o){Ri(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r++]=i,i=i>>8,e[r++]=i,i=i>>8,e[r++]=i,i=i>>8,e[r++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s,s=s>>8,e[r++]=s,r}function vi(e,t,r,n,o){Ri(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r+7]=i,i=i>>8,e[r+6]=i,i=i>>8,e[r+5]=i,i=i>>8,e[r+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s=s>>8,e[r+2]=s,s=s>>8,e[r+1]=s,s=s>>8,e[r]=s,r+8}b.prototype.writeBigUInt64LE=Wt(function(t,r=0){return Ii(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeBigUInt64BE=Wt(function(t,r=0){return vi(this,t,r,BigInt(0),BigInt("0xffffffffffffffff"))});b.prototype.writeIntLE=function(t,r,n,o){if(t=+t,r=r>>>0,!o){let a=Math.pow(2,8*n-1);dt(this,t,r,n,a-1,-a)}let i=0,s=1,c=0;for(this[r]=t&255;++i<n&&(s*=256);)t<0&&c===0&&this[r+i-1]!==0&&(c=1),this[r+i]=(t/s>>0)-c&255;return r+n};b.prototype.writeIntBE=function(t,r,n,o){if(t=+t,r=r>>>0,!o){let a=Math.pow(2,8*n-1);dt(this,t,r,n,a-1,-a)}let i=n-1,s=1,c=0;for(this[r+i]=t&255;--i>=0&&(s*=256);)t<0&&c===0&&this[r+i+1]!==0&&(c=1),this[r+i]=(t/s>>0)-c&255;return r+n};b.prototype.writeInt8=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=t&255,r+1};b.prototype.writeInt16LE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,2,32767,-32768),this[r]=t&255,this[r+1]=t>>>8,r+2};b.prototype.writeInt16BE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=t&255,r+2};b.prototype.writeInt32LE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,4,2147483647,-2147483648),this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4};b.prototype.writeInt32BE=function(t,r,n){return t=+t,r=r>>>0,n||dt(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255,r+4};b.prototype.writeBigInt64LE=Wt(function(t,r=0){return Ii(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});b.prototype.writeBigInt64BE=Wt(function(t,r=0){return vi(this,t,r,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ti(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Ui(e,t,r,n,o){return t=+t,r=r>>>0,o||Ti(e,t,r,4,34028234663852886e22,-34028234663852886e22),me.write(e,t,r,n,23,4),r+4}b.prototype.writeFloatLE=function(t,r,n){return Ui(this,t,r,!0,n)};b.prototype.writeFloatBE=function(t,r,n){return Ui(this,t,r,!1,n)};function ki(e,t,r,n,o){return t=+t,r=r>>>0,o||Ti(e,t,r,8,17976931348623157e292,-17976931348623157e292),me.write(e,t,r,n,52,8),r+8}b.prototype.writeDoubleLE=function(t,r,n){return ki(this,t,r,!0,n)};b.prototype.writeDoubleBE=function(t,r,n){return ki(this,t,r,!1,n)};b.prototype.copy=function(t,r,n,o){if(!b.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),r>=t.length&&(r=t.length),r||(r=0),o>0&&o<n&&(o=n),o===n||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-r<o-n&&(o=t.length-r+n);let i=o-n;return this===t&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,o):Uint8Array.prototype.set.call(t,this.subarray(n,o),r),i};b.prototype.fill=function(t,r,n,o){if(typeof t=="string"){if(typeof r=="string"?(o=r,r=0,n=this.length):typeof n=="string"&&(o=n,n=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!b.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(t.length===1){let s=t.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(t=s)}}else typeof t=="number"?t=t&255:typeof t=="boolean"&&(t=Number(t));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);let i;if(typeof t=="number")for(i=r;i<n;++i)this[i]=t;else{let s=b.isBuffer(t)?t:b.from(t,o),c=s.length;if(c===0)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<n-r;++i)this[i+r]=s[i%c]}return this};var be={};function vn(e,t,r){be[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(o){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:o,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}vn("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError);vn("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError);vn("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=mi(String(r)):typeof r=="bigint"&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=mi(o)),o+="n"),n+=` It must be ${t}. Received ${o}`,n},RangeError);function mi(e){let t="",r=e.length,n=e[0]==="-"?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function Jc(e,t,r){we(t,"offset"),(e[t]===void 0||e[t+r]===void 0)&&Oe(t,e.length-(r+1))}function Ri(e,t,r,n,o,i){if(e>r||e<t){let s=typeof t=="bigint"?"n":"",c;throw i>3?t===0||t===BigInt(0)?c=`>= 0${s} and < 2${s} ** ${(i+1)*8}${s}`:c=`>= -(2${s} ** ${(i+1)*8-1}${s}) and < 2 ** ${(i+1)*8-1}${s}`:c=`>= ${t}${s} and <= ${r}${s}`,new be.ERR_OUT_OF_RANGE("value",c,e)}Jc(n,o,i)}function we(e,t){if(typeof e!="number")throw new be.ERR_INVALID_ARG_TYPE(t,"number",e)}function Oe(e,t,r){throw Math.floor(e)!==e?(we(e,r),new be.ERR_OUT_OF_RANGE(r||"offset","an integer",e)):t<0?new be.ERR_BUFFER_OUT_OF_BOUNDS:new be.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}var Qc=/[^+/0-9A-Za-z-_]/g;function ta(e){if(e=e.split("=")[0],e=e.trim().replace(Qc,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function An(e,t){t=t||1/0;let r,n=e.length,o=null,i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function ea(e){let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function ra(e,t){let r,n,o,i=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}function _i(e){return wn.toByteArray(ta(e))}function yr(e,t,r,n){let o;for(o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function It(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function Tn(e){return e!==e}var na=(function(){let e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){let n=r*16;for(let o=0;o<16;++o)t[n+o]=e[r]+e[o]}return t})();function Wt(e){return typeof BigInt>"u"?oa:e}function oa(){throw new Error("BigInt not supported")}});var Bf={};kt(Bf,{Nip46Method:()=>Fe,NostrEventKind:()=>Ur,NostrMessageType:()=>Ie,bytesToHex:()=>ls,bytesToUtf8:()=>hs,calculateEventId:()=>fn,computeSharedSecret:()=>hn,createEvent:()=>Xo,decrypt:()=>ei,decryptMessage:()=>dn,encrypt:()=>ti,encryptMessage:()=>ln,finalizeEvent:()=>Jo,generateKeyPair:()=>Zo,getPublicKey:()=>ar,getPublicKeySync:()=>on,hexToBytes:()=>us,nip01:()=>gn,nip04:()=>pn,nip19:()=>kn,nip26:()=>_n,nip44:()=>Gn,nip46:()=>Kn,nip49:()=>Xn,signEvent:()=>nn,utf8ToBytes:()=>ds,validateEvent:()=>ri,validateEventBase:()=>ur,validateEventId:()=>sn,validateEventSignature:()=>cn,validateFilter:()=>lr,validateKeyPair:()=>Yo,validateResponse:()=>oi,validateSignedEvent:()=>fr,validateSubscription:()=>ni,verifySignature:()=>Qo});var Ie=(c=>(c.EVENT="EVENT",c.NOTICE="NOTICE",c.OK="OK",c.EOSE="EOSE",c.REQ="REQ",c.CLOSE="CLOSE",c.AUTH="AUTH",c))(Ie||{});var Fe=(f=>(f.CONNECT="connect",f.PING="ping",f.GET_PUBLIC_KEY="get_public_key",f.SIGN_EVENT="sign_event",f.NIP04_ENCRYPT="nip04_encrypt",f.NIP04_DECRYPT="nip04_decrypt",f.NIP44_ENCRYPT="nip44_encrypt",f.NIP44_DECRYPT="nip44_decrypt",f.GET_RELAYS="get_relays",f))(Fe||{});var Ur=(p=>(p[p.SET_METADATA=0]="SET_METADATA",p[p.TEXT_NOTE=1]="TEXT_NOTE",p[p.RECOMMEND_SERVER=2]="RECOMMEND_SERVER",p[p.CONTACT_LIST=3]="CONTACT_LIST",p[p.ENCRYPTED_DIRECT_MESSAGE=4]="ENCRYPTED_DIRECT_MESSAGE",p[p.DELETE=5]="DELETE",p[p.REPOST=6]="REPOST",p[p.REACTION=7]="REACTION",p[p.BADGE_AWARD=8]="BADGE_AWARD",p[p.CHANNEL_CREATE=40]="CHANNEL_CREATE",p[p.CHANNEL_METADATA=41]="CHANNEL_METADATA",p[p.CHANNEL_MESSAGE=42]="CHANNEL_MESSAGE",p[p.CHANNEL_HIDE_MESSAGE=43]="CHANNEL_HIDE_MESSAGE",p[p.CHANNEL_MUTE_USER=44]="CHANNEL_MUTE_USER",p[p.CHANNEL_RESERVE=45]="CHANNEL_RESERVE",p[p.REPORTING=1984]="REPORTING",p[p.ZAP_REQUEST=9734]="ZAP_REQUEST",p[p.ZAP=9735]="ZAP",p[p.MUTE_LIST=1e4]="MUTE_LIST",p[p.PIN_LIST=10001]="PIN_LIST",p[p.RELAY_LIST_METADATA=10002]="RELAY_LIST_METADATA",p[p.CLIENT_AUTH=22242]="CLIENT_AUTH",p[p.AUTH_RESPONSE=22243]="AUTH_RESPONSE",p[p.NOSTR_CONNECT=24133]="NOSTR_CONNECT",p[p.CATEGORIZED_PEOPLE=3e4]="CATEGORIZED_PEOPLE",p[p.CATEGORIZED_BOOKMARKS=30001]="CATEGORIZED_BOOKMARKS",p[p.PROFILE_BADGES=30008]="PROFILE_BADGES",p[p.BADGE_DEFINITION=30009]="BADGE_DEFINITION",p[p.LONG_FORM=30023]="LONG_FORM",p[p.APPLICATION_SPECIFIC=30078]="APPLICATION_SPECIFIC",p))(Ur||{});var Zt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function qt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function et(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ht(e,...t){if(!qt(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function _t(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");et(e.outputLen),et(e.blockLen)}function ie(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ro(e,t){ht(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Me(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function pt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function se(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}function V(e,t){return e<<t|e>>>32-t>>>0}var Bs=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function As(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ss(e){for(let t=0;t<e.length;t++)e[t]=As(e[t]);return e}var kr=Bs?e=>e:Ss,no=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Is=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function yt(e){if(ht(e),no)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Is[e[r]];return t}var Rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function eo(e){if(e>=Rt._0&&e<=Rt._9)return e-Rt._0;if(e>=Rt.A&&e<=Rt.F)return e-(Rt.A-10);if(e>=Rt.a&&e<=Rt.f)return e-(Rt.a-10)}function Nt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(no)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,i=0;o<r;o++,i+=2){let s=eo(e.charCodeAt(i)),c=eo(e.charCodeAt(i+1));if(s===void 0||c===void 0){let a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}n[o]=s*16+c}return n}function ce(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function $t(e){return typeof e=="string"&&(e=ce(e)),ht(e),e}function Rr(e){return typeof e=="string"&&(e=ce(e)),ht(e),e}function J(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ht(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let i=e[n];r.set(i,o),o+=i.length}return r}function qe(e,t){if(t!==void 0&&{}.toString.call(t)!=="[object Object]")throw new Error("options should be object or undefined");return Object.assign(e,t)}var oe=class{};function oo(e){let t=n=>e().update($t(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function rt(e=32){if(Zt&&typeof Zt.getRandomValues=="function")return Zt.getRandomValues(new Uint8Array(e));if(Zt&&typeof Zt.randomBytes=="function")return Uint8Array.from(Zt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function vs(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),c=Number(r&i),a=n?4:0,f=n?0:4;e.setUint32(t+a,s,n),e.setUint32(t+f,c,n)}function io(e,t,r){return e&t^~e&r}function so(e,t,r){return e&t^e&r^t&r}var $e=class extends oe{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=se(this.buffer)}update(t){ie(this),t=$t(t),ht(t);let{view:r,buffer:n,blockLen:o}=this,i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let a=se(t);for(;o<=i-s;s+=o)this.process(a,s);continue}n.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){ie(this),ro(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,pt(this.buffer.subarray(s)),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;vs(n,o-8,BigInt(this.length*8),i),this.process(n,0);let c=se(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,u[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:c}=this;return t.destroyed=s,t.finished=i,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Lt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Ts=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]),jt=new Uint32Array(64),je=class extends $e{constructor(t=32){super(64,t,8,!1),this.A=Lt[0]|0,this.B=Lt[1]|0,this.C=Lt[2]|0,this.D=Lt[3]|0,this.E=Lt[4]|0,this.F=Lt[5]|0,this.G=Lt[6]|0,this.H=Lt[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:c,H:a}=this;return[t,r,n,o,i,s,c,a]}set(t,r,n,o,i,s,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)jt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let d=jt[l-15],h=jt[l-2],x=wt(d,7)^wt(d,18)^d>>>3,y=wt(h,17)^wt(h,19)^h>>>10;jt[l]=y+jt[l-7]+x+jt[l-16]|0}let{A:n,B:o,C:i,D:s,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let d=wt(c,6)^wt(c,11)^wt(c,25),h=u+d+io(c,a,f)+Ts[l]+jt[l]|0,y=(wt(n,2)^wt(n,13)^wt(n,22))+so(n,o,i)|0;u=f,f=a,a=c,c=s+h|0,s=i,i=o,o=n,n=h+y|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,i,s,c,a,f,u)}roundClean(){pt(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),pt(this.buffer)}};var Ct=oo(()=>new je);var ze=class extends oe{constructor(t,r){super(),this.finished=!1,this.destroyed=!1,_t(t);let n=$t(r);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?t.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=t.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),pt(i)}update(t){return ie(this),this.iHash.update(t),this}digestInto(t){ie(this),ht(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=i,t.blockLen=s,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Et=(e,t,r)=>new ze(e,t).update(r).digest();Et.create=(e,t)=>new ze(e,t);var Lr=BigInt(0),Nr=BigInt(1);function ve(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function zt(e,t,r=""){let n=qt(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return e}function ae(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Cr(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Lr:BigInt("0x"+e)}function At(e){return Cr(yt(e))}function Ge(e){return ht(e),Cr(yt(Uint8Array.from(e).reverse()))}function Yt(e,t){return Nt(e.toString(16).padStart(t*2,"0"))}function Ke(e,t){return Yt(e,t).reverse()}function Z(e,t,r){let n;if(typeof t=="string")try{n=Nt(t)}catch(i){throw new Error(e+" must be hex string or Uint8Array, cause: "+i)}else if(qt(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var _r=e=>typeof e=="bigint"&&Lr<=e;function fe(e,t,r){return _r(e)&&_r(t)&&_r(r)&&t<=e&&e<r}function Or(e,t,r,n){if(!fe(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Te(e){let t;for(t=0;e>Lr;e>>=Nr,t+=1);return t}var Ot=e=>(Nr<<BigInt(e))-Nr;function Pr(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),i=n(e),s=n(e),c=0,a=()=>{i.fill(1),s.fill(0),c=0},f=(...h)=>r(s,i,...h),u=(h=n(0))=>{s=f(o(0),h),i=f(),h.length!==0&&(s=f(o(1),h),i=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,x=[];for(;h<t;){i=f();let y=i.slice();x.push(y),h+=i.length}return J(...x)};return(h,x)=>{a(),u(h);let y;for(;!(y=x(l()));)u();return a(),y}}function Ue(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,s){let c=e[o];if(s&&c===void 0)return;let a=typeof c;if(a!==i||c===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${a}`)}Object.entries(t).forEach(([o,i])=>n(o,i,!1)),Object.entries(r).forEach(([o,i])=>n(o,i,!0))}function We(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let i=e(r,...n);return t.set(r,i),i}}var ut=BigInt(0),ft=BigInt(1),Xt=BigInt(2),fo=BigInt(3),uo=BigInt(4),lo=BigInt(5),Rs=BigInt(7),ho=BigInt(8),_s=BigInt(9),po=BigInt(16);function gt(e,t){let r=e%t;return r>=ut?r:t+r}function xt(e,t,r){let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function co(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=gt(e,t),n=t,o=ut,i=ft,s=ft,c=ut;for(;r!==ut;){let f=n/r,u=n%r,l=o-s*f,d=i-c*f;n=r,r=u,o=s,i=c,s=l,c=d}if(n!==ft)throw new Error("invert: does not exist");return gt(o,t)}function Hr(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function yo(e,t){let r=(e.ORDER+ft)/uo,n=e.pow(t,r);return Hr(e,n,t),n}function Ns(e,t){let r=(e.ORDER-lo)/ho,n=e.mul(t,Xt),o=e.pow(n,r),i=e.mul(t,o),s=e.mul(e.mul(i,Xt),o),c=e.mul(i,e.sub(s,e.ONE));return Hr(e,c,t),c}function Ls(e){let t=Gt(e),r=go(e),n=r(t,t.neg(t.ONE)),o=r(t,n),i=r(t,t.neg(n)),s=(e+Rs)/po;return(c,a)=>{let f=c.pow(a,s),u=c.mul(f,n),l=c.mul(f,o),d=c.mul(f,i),h=c.eql(c.sqr(u),a),x=c.eql(c.sqr(l),a);f=c.cmov(f,u,h),u=c.cmov(d,l,x);let y=c.eql(c.sqr(u),a),B=c.cmov(f,u,y);return Hr(c,B,a),B}}function go(e){if(e<fo)throw new Error("sqrt is not defined for small field");let t=e-ft,r=0;for(;t%Xt===ut;)t/=Xt,r++;let n=Xt,o=Gt(e);for(;ao(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return yo;let i=o.pow(n,t),s=(t+ft)/Xt;return function(a,f){if(a.is0(f))return f;if(ao(a,f)!==1)throw new Error("Cannot find square root");let u=r,l=a.mul(a.ONE,i),d=a.pow(f,t),h=a.pow(f,s);for(;!a.eql(d,a.ONE);){if(a.is0(d))return a.ZERO;let x=1,y=a.sqr(d);for(;!a.eql(y,a.ONE);)if(x++,y=a.sqr(y),x===u)throw new Error("Cannot find square root");let B=ft<<BigInt(u-x-1),I=a.pow(l,B);u=x,l=a.sqr(I),d=a.mul(d,l),h=a.mul(h,I)}return h}}function Cs(e){return e%uo===fo?yo:e%ho===lo?Ns:e%po===_s?Ls(e):go(e)}var Os=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Dr(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Os.reduce((n,o)=>(n[o]="function",n),t);return Ue(e,r),e}function Ps(e,t,r){if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return e.ONE;if(r===ft)return t;let n=e.ONE,o=t;for(;r>ut;)r&ft&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ft;return n}function Ze(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((s,c,a)=>e.is0(c)?s:(n[a]=s,e.mul(s,c)),e.ONE),i=e.inv(o);return t.reduceRight((s,c,a)=>e.is0(c)?s:(n[a]=e.mul(s,n[a]),e.mul(s,c)),i),n}function ao(e,t){let r=(e.ORDER-ft)/Xt,n=e.pow(t,r),o=e.eql(n,e.ONE),i=e.eql(n,e.ZERO),s=e.eql(n,e.neg(e.ONE));if(!o&&!i&&!s)throw new Error("invalid Legendre symbol result");return o?1:i?0:-1}function Ye(e,t){t!==void 0&&et(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Gt(e,t,r=!1,n={}){if(e<=ut)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,i,s=!1,c;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let d=t;d.BITS&&(o=d.BITS),d.sqrt&&(i=d.sqrt),typeof d.isLE=="boolean"&&(r=d.isLE),typeof d.modFromBytes=="boolean"&&(s=d.modFromBytes),c=d.allowedLengths}else typeof t=="number"&&(o=t),n.sqrt&&(i=n.sqrt);let{nBitLength:a,nByteLength:f}=Ye(e,o);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u,l=Object.freeze({ORDER:e,isLE:r,BITS:a,BYTES:f,MASK:Ot(a),ZERO:ut,ONE:ft,allowedLengths:c,create:d=>gt(d,e),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return ut<=d&&d<e},is0:d=>d===ut,isValidNot0:d=>!l.is0(d)&&l.isValid(d),isOdd:d=>(d&ft)===ft,neg:d=>gt(-d,e),eql:(d,h)=>d===h,sqr:d=>gt(d*d,e),add:(d,h)=>gt(d+h,e),sub:(d,h)=>gt(d-h,e),mul:(d,h)=>gt(d*h,e),pow:(d,h)=>Ps(l,d,h),div:(d,h)=>gt(d*co(h,e),e),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>co(d,e),sqrt:i||(d=>(u||(u=Cs(e)),u(l,d))),toBytes:d=>r?Ke(d,f):Yt(d,f),fromBytes:(d,h=!0)=>{if(c){if(!c.includes(d.length)||d.length>f)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+d.length);let y=new Uint8Array(f);y.set(d,r?0:y.length-d.length),d=y}if(d.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+d.length);let x=r?Ge(d):At(d);if(s&&(x=gt(x,e)),!h&&!l.isValid(x))throw new Error("invalid field element: outside of range 0..ORDER");return x},invertBatch:d=>Ze(l,d),cmov:(d,h,x)=>x?h:d});return Object.freeze(l)}function xo(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Vr(e){let t=xo(e);return t+Math.ceil(t/2)}function Xe(e,t,r=!1){let n=e.length,o=xo(t),i=Vr(t);if(n<16||n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let s=r?Ge(e):At(e),c=gt(s,t-ft)+ft;return r?Ke(c,o):Yt(c,o)}var ue=BigInt(0),Jt=BigInt(1);function ke(e,t){let r=t.negate();return e?r:t}function Qe(e,t){let r=Ze(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Eo(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Fr(e,t){Eo(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,i=Ot(e),s=BigInt(e);return{windows:r,windowSize:n,mask:i,maxNumber:o,shiftBy:s}}function bo(e,t,r){let{windowSize:n,mask:o,maxNumber:i,shiftBy:s}=r,c=Number(e&o),a=e>>s;c>n&&(c-=i,a+=Jt);let f=t*n,u=f+Math.abs(c)-1,l=c===0,d=c<0,h=t%2!==0;return{nextN:a,offset:u,isZero:l,isNeg:d,isNegF:h,offsetF:f}}function Ds(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Vs(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Mr=new WeakMap,Bo=new WeakMap;function qr(e){return Bo.get(e)||1}function mo(e){if(e!==ue)throw new Error("invalid wNAF")}var Je=class{constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>ue;)r&Jt&&(n=n.add(o)),o=o.double(),r>>=Jt;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Fr(r,this.bits),i=[],s=t,c=s;for(let a=0;a<n;a++){c=s,i.push(c);for(let f=1;f<o;f++)c=c.add(s),i.push(c);s=c.double()}return i}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,i=this.BASE,s=Fr(t,this.bits);for(let c=0;c<s.windows;c++){let{nextN:a,offset:f,isZero:u,isNeg:l,isNegF:d,offsetF:h}=bo(n,c,s);n=a,u?i=i.add(ke(d,r[h])):o=o.add(ke(l,r[f]))}return mo(n),{p:o,f:i}}wNAFUnsafe(t,r,n,o=this.ZERO){let i=Fr(t,this.bits);for(let s=0;s<i.windows&&n!==ue;s++){let{nextN:c,offset:a,isZero:f,isNeg:u}=bo(n,s,i);if(n=c,!f){let l=r[a];o=o.add(u?l.negate():l)}}return mo(n),o}getPrecomputes(t,r,n){let o=Mr.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Mr.set(r,o))),o}cached(t,r,n){let o=qr(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let i=qr(t);return i===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(i,this.getPrecomputes(i,t,n),r,o)}createCache(t,r){Eo(r,this.bits),Bo.set(t,r),Mr.delete(t)}hasCache(t){return qr(t)!==1}};function Ao(e,t,r,n){let o=t,i=e.ZERO,s=e.ZERO;for(;r>ue||n>ue;)r&Jt&&(i=i.add(o)),n&Jt&&(s=s.add(o)),o=o.double(),r>>=Jt,n>>=Jt;return{p1:i,p2:s}}function So(e,t,r,n){Ds(r,e),Vs(n,t);let o=r.length,i=n.length;if(o!==i)throw new Error("arrays of points and scalars must have equal length");let s=e.ZERO,c=Te(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=Ot(a),u=new Array(Number(f)+1).fill(s),l=Math.floor((t.BITS-1)/a)*a,d=s;for(let h=l;h>=0;h-=a){u.fill(s);for(let y=0;y<i;y++){let B=n[y],I=Number(B>>BigInt(h)&f);u[I]=u[I].add(r[y])}let x=s;for(let y=u.length-1,B=s;y>0;y--)B=B.add(u[y]),x=x.add(B);if(d=d.add(x),h!==0)for(let y=0;y<a;y++)d=d.double()}return d}function wo(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Dr(t),t}else return Gt(e,{isLE:r})}function Io(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>ue))throw new Error(`CURVE.${a} must be positive bigint`)}let o=wo(t.p,r.Fp,n),i=wo(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:i}}var vo=(e,t)=>(e+(e>=0?t:-t)/To)/t;function Fs(e,t,r){let[[n,o],[i,s]]=t,c=vo(s*e,r),a=vo(-o*e,r),f=e-c*n-a*i,u=-c*o-a*s,l=f<Ht,d=u<Ht;l&&(f=-f),d&&(u=-u);let h=Ot(Math.ceil(Te(r)/2))+le;if(f<Ht||f>=h||u<Ht||u>=h)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:d,k2:u}}function jr(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function $r(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ve(r.lowS,"lowS"),ve(r.prehash,"prehash"),r.format!==void 0&&jr(r.format),r}var zr=class extends Error{constructor(t=""){super(t)}},Pt={Err:zr,_tlv:{encode:(e,t)=>{let{Err:r}=Pt;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=ae(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?ae(o.length/2|128):"";return ae(e)+i+o+t},decode(e,t){let{Err:r}=Pt,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],i=!!(o&128),s=0;if(!i)s=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=a,s<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+s);if(c.length!==s)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+s)}}},_int:{encode(e){let{Err:t}=Pt;if(e<Ht)throw new t("integer: negative integers are not allowed");let r=ae(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Pt;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return At(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Pt,o=Z("signature",e),{v:i,l:s}=n.decode(48,o);if(s.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,i),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=Pt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),i=n+o;return t.encode(48,i)}},Ht=BigInt(0),le=BigInt(1),To=BigInt(2),tr=BigInt(3),Ms=BigInt(4);function Kt(e,t){let{BYTES:r}=e,n;if(typeof t=="bigint")n=t;else{let o=Z("private key",t);try{n=e.fromBytes(o)}catch{throw new Error(`invalid private key: expected ui8a of size ${r}, got ${typeof t}`)}}if(!e.isValidNot0(n))throw new Error("invalid private key: out of range [1..N-1]");return n}function qs(e,t={}){let r=Io("weierstrass",e,t),{Fp:n,Fn:o}=r,i=r.CURVE,{h:s,n:c}=i;Ue(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});let{endo:a}=t;if(a&&(!n.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=ko(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(_,m,p){let{x:g,y:E}=m.toAffine(),A=n.toBytes(g);if(ve(p,"isCompressed"),p){u();let v=!n.isOdd(E);return J(Uo(v),A)}else return J(Uint8Array.of(4),A,n.toBytes(E))}function d(_){zt(_,void 0,"Point");let{publicKey:m,publicKeyUncompressed:p}=f,g=_.length,E=_[0],A=_.subarray(1);if(g===m&&(E===2||E===3)){let v=n.fromBytes(A);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let w=y(v),S;try{S=n.sqrt(w)}catch($){let F=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}u();let T=n.isOdd(S);return(E&1)===1!==T&&(S=n.neg(S)),{x:v,y:S}}else if(g===p&&E===4){let v=n.BYTES,w=n.fromBytes(A.subarray(0,v)),S=n.fromBytes(A.subarray(v,v*2));if(!B(w,S))throw new Error("bad point: is not on curve");return{x:w,y:S}}else throw new Error(`bad point: got length ${g}, expected compressed=${m} or uncompressed=${p}`)}let h=t.toBytes||l,x=t.fromBytes||d;function y(_){let m=n.sqr(_),p=n.mul(m,_);return n.add(n.add(p,n.mul(_,i.a)),i.b)}function B(_,m){let p=n.sqr(m),g=y(_);return n.eql(p,g)}if(!B(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let I=n.mul(n.pow(i.a,tr),Ms),L=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(I,L)))throw new Error("bad curve params: a or b");function N(_,m,p=!1){if(!n.isValid(m)||p&&n.is0(m))throw new Error(`bad point coordinate ${_}`);return m}function D(_){if(!(_ instanceof U))throw new Error("ProjectivePoint expected")}function K(_){if(!a||!a.basises)throw new Error("no endo");return Fs(_,a.basises,o.ORDER)}let O=We((_,m)=>{let{X:p,Y:g,Z:E}=_;if(n.eql(E,n.ONE))return{x:p,y:g};let A=_.is0();m==null&&(m=A?n.ONE:n.inv(E));let v=n.mul(p,m),w=n.mul(g,m),S=n.mul(E,m);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(S,n.ONE))throw new Error("invZ was invalid");return{x:v,y:w}}),q=We(_=>{if(_.is0()){if(t.allowInfinityPoint&&!n.is0(_.Y))return;throw new Error("bad point: ZERO")}let{x:m,y:p}=_.toAffine();if(!n.isValid(m)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!B(m,p))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function M(_,m,p,g,E){return p=new U(n.mul(p.X,_),p.Y,p.Z),m=ke(g,m),p=ke(E,p),m.add(p)}class U{constructor(m,p,g){this.X=N("x",m),this.Y=N("y",p,!0),this.Z=N("z",g),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){let{x:p,y:g}=m||{};if(!m||!n.isValid(p)||!n.isValid(g))throw new Error("invalid affine point");if(m instanceof U)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(g)?U.ZERO:new U(p,g,n.ONE)}static fromBytes(m){let p=U.fromAffine(x(zt(m,void 0,"point")));return p.assertValidity(),p}static fromHex(m){return U.fromBytes(Z("pointHex",m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,p=!0){return C.createCache(this,m),p||this.multiply(tr),this}assertValidity(){q(this)}hasEvenY(){let{y:m}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(m)}equals(m){D(m);let{X:p,Y:g,Z:E}=this,{X:A,Y:v,Z:w}=m,S=n.eql(n.mul(p,w),n.mul(A,E)),T=n.eql(n.mul(g,w),n.mul(v,E));return S&&T}negate(){return new U(this.X,n.neg(this.Y),this.Z)}double(){let{a:m,b:p}=i,g=n.mul(p,tr),{X:E,Y:A,Z:v}=this,w=n.ZERO,S=n.ZERO,T=n.ZERO,k=n.mul(E,E),$=n.mul(A,A),F=n.mul(v,v),P=n.mul(E,A);return P=n.add(P,P),T=n.mul(E,v),T=n.add(T,T),w=n.mul(m,T),S=n.mul(g,F),S=n.add(w,S),w=n.sub($,S),S=n.add($,S),S=n.mul(w,S),w=n.mul(P,w),T=n.mul(g,T),F=n.mul(m,F),P=n.sub(k,F),P=n.mul(m,P),P=n.add(P,T),T=n.add(k,k),k=n.add(T,k),k=n.add(k,F),k=n.mul(k,P),S=n.add(S,k),F=n.mul(A,v),F=n.add(F,F),k=n.mul(F,P),w=n.sub(w,k),T=n.mul(F,$),T=n.add(T,T),T=n.add(T,T),new U(w,S,T)}add(m){D(m);let{X:p,Y:g,Z:E}=this,{X:A,Y:v,Z:w}=m,S=n.ZERO,T=n.ZERO,k=n.ZERO,$=i.a,F=n.mul(i.b,tr),P=n.mul(p,A),j=n.mul(g,v),W=n.mul(E,w),Q=n.add(p,g),z=n.add(A,v);Q=n.mul(Q,z),z=n.add(P,j),Q=n.sub(Q,z),z=n.add(p,E);let at=n.add(A,w);return z=n.mul(z,at),at=n.add(P,W),z=n.sub(z,at),at=n.add(g,E),S=n.add(v,w),at=n.mul(at,S),S=n.add(j,W),at=n.sub(at,S),k=n.mul($,z),S=n.mul(F,W),k=n.add(S,k),S=n.sub(j,k),k=n.add(j,k),T=n.mul(S,k),j=n.add(P,P),j=n.add(j,P),W=n.mul($,W),z=n.mul(F,z),j=n.add(j,W),W=n.sub(P,W),W=n.mul($,W),z=n.add(z,W),P=n.mul(j,z),T=n.add(T,P),P=n.mul(at,z),S=n.mul(Q,S),S=n.sub(S,P),P=n.mul(Q,j),k=n.mul(at,k),k=n.add(k,P),new U(S,T,k)}subtract(m){return this.add(m.negate())}is0(){return this.equals(U.ZERO)}multiply(m){let{endo:p}=t;if(!o.isValidNot0(m))throw new Error("invalid scalar: out of range");let g,E,A=v=>C.cached(this,v,w=>Qe(U,w));if(p){let{k1neg:v,k1:w,k2neg:S,k2:T}=K(m),{p:k,f:$}=A(w),{p:F,f:P}=A(T);E=$.add(P),g=M(p.beta,k,F,v,S)}else{let{p:v,f:w}=A(m);g=v,E=w}return Qe(U,[g,E])[0]}multiplyUnsafe(m){let{endo:p}=t,g=this;if(!o.isValid(m))throw new Error("invalid scalar: out of range");if(m===Ht||g.is0())return U.ZERO;if(m===le)return g;if(C.hasCache(this))return this.multiply(m);if(p){let{k1neg:E,k1:A,k2neg:v,k2:w}=K(m),{p1:S,p2:T}=Ao(U,g,A,w);return M(p.beta,S,T,E,v)}else return C.unsafe(g,m)}multiplyAndAddUnsafe(m,p,g){let E=this.multiplyUnsafe(p).add(m.multiplyUnsafe(g));return E.is0()?void 0:E}toAffine(m){return O(this,m)}isTorsionFree(){let{isTorsionFree:m}=t;return s===le?!0:m?m(U,this):C.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:m}=t;return s===le?this:m?m(U,this):this.multiplyUnsafe(s)}isSmallOrder(){return this.multiplyUnsafe(s).is0()}toBytes(m=!0){return ve(m,"isCompressed"),this.assertValidity(),h(U,this,m)}toHex(m=!0){return yt(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(m=!0){return this.toBytes(m)}_setWindowSize(m){this.precompute(m)}static normalizeZ(m){return Qe(U,m)}static msm(m,p){return So(U,o,m,p)}static fromPrivateKey(m){return U.BASE.multiply(Kt(o,m))}}U.BASE=new U(i.Gx,i.Gy,n.ONE),U.ZERO=new U(n.ZERO,n.ONE,n.ZERO),U.Fp=n,U.Fn=o;let H=o.BITS,C=new Je(U,t.endo?Math.ceil(H/2):H);return U.BASE.precompute(8),U}function Uo(e){return Uint8Array.of(e?2:3)}function ko(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function $s(e,t={}){let{Fn:r}=e,n=t.randomBytes||rt,o=Object.assign(ko(e.Fp,r),{seed:Vr(r.ORDER)});function i(h){try{return!!Kt(r,h)}catch{return!1}}function s(h,x){let{publicKey:y,publicKeyUncompressed:B}=o;try{let I=h.length;return x===!0&&I!==y||x===!1&&I!==B?!1:!!e.fromBytes(h)}catch{return!1}}function c(h=n(o.seed)){return Xe(zt(h,o.seed,"seed"),r.ORDER)}function a(h,x=!0){return e.BASE.multiply(Kt(r,h)).toBytes(x)}function f(h){let x=c(h);return{secretKey:x,publicKey:a(x)}}function u(h){if(typeof h=="bigint")return!1;if(h instanceof e)return!0;let{secretKey:x,publicKey:y,publicKeyUncompressed:B}=o;if(r.allowedLengths||x===y)return;let I=Z("key",h).length;return I===y||I===B}function l(h,x,y=!0){if(u(h)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let B=Kt(r,h);return e.fromHex(x).multiply(B).toBytes(y)}return Object.freeze({getPublicKey:a,getSharedSecret:l,keygen:f,Point:e,utils:{isValidSecretKey:i,isValidPublicKey:s,randomSecretKey:c,isValidPrivateKey:i,randomPrivateKey:c,normPrivateKeyToScalar:h=>Kt(r,h),precompute(h=8,x=e.BASE){return x.precompute(h,!1)}},lengths:o})}function js(e,t,r={}){_t(t),Ue(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let n=r.randomBytes||rt,o=r.hmac||((p,...g)=>Et(t,p,J(...g))),{Fp:i,Fn:s}=e,{ORDER:c,BITS:a}=s,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:d,lengths:h}=$s(e,r),x={prehash:!1,lowS:typeof r.lowS=="boolean"?r.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function B(p){let g=c>>le;return p>g}function I(p,g){if(!s.isValidNot0(g))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return g}function L(p,g){jr(g);let E=h.signature,A=g==="compact"?E:g==="recovered"?E+1:void 0;return zt(p,A,`${g} signature`)}class N{constructor(g,E,A){this.r=I("r",g),this.s=I("s",E),A!=null&&(this.recovery=A),Object.freeze(this)}static fromBytes(g,E=y){L(g,E);let A;if(E==="der"){let{r:T,s:k}=Pt.toSig(zt(g));return new N(T,k)}E==="recovered"&&(A=g[0],E="compact",g=g.subarray(1));let v=s.BYTES,w=g.subarray(0,v),S=g.subarray(v,v*2);return new N(s.fromBytes(w),s.fromBytes(S),A)}static fromHex(g,E){return this.fromBytes(Nt(g),E)}addRecoveryBit(g){return new N(this.r,this.s,g)}recoverPublicKey(g){let E=i.ORDER,{r:A,s:v,recovery:w}=this;if(w==null||![0,1,2,3].includes(w))throw new Error("recovery id invalid");if(c*To<E&&w>1)throw new Error("recovery id is ambiguous for h>1 curve");let T=w===2||w===3?A+c:A;if(!i.isValid(T))throw new Error("recovery id 2 or 3 invalid");let k=i.toBytes(T),$=e.fromBytes(J(Uo((w&1)===0),k)),F=s.inv(T),P=K(Z("msgHash",g)),j=s.create(-P*F),W=s.create(v*F),Q=e.BASE.multiplyUnsafe(j).add($.multiplyUnsafe(W));if(Q.is0())throw new Error("point at infinify");return Q.assertValidity(),Q}hasHighS(){return B(this.s)}toBytes(g=y){if(jr(g),g==="der")return Nt(Pt.hexFromSig(this));let E=s.toBytes(this.r),A=s.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return J(Uint8Array.of(this.recovery),E,A)}return J(E,A)}toHex(g){return yt(this.toBytes(g))}assertValidity(){}static fromCompact(g){return N.fromBytes(Z("sig",g),"compact")}static fromDER(g){return N.fromBytes(Z("sig",g),"der")}normalizeS(){return this.hasHighS()?new N(this.r,s.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return yt(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return yt(this.toBytes("compact"))}}let D=r.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");let E=At(g),A=g.length*8-a;return A>0?E>>BigInt(A):E},K=r.bits2int_modN||function(g){return s.create(D(g))},O=Ot(a);function q(p){return Or("num < 2^"+a,p,Ht,O),s.toBytes(p)}function M(p,g){return zt(p,void 0,"message"),g?zt(t(p),void 0,"prehashed message"):p}function U(p,g,E){if(["recovered","canonical"].some(j=>j in E))throw new Error("sign() legacy options not supported");let{lowS:A,prehash:v,extraEntropy:w}=$r(E,x);p=M(p,v);let S=K(p),T=Kt(s,g),k=[q(T),q(S)];if(w!=null&&w!==!1){let j=w===!0?n(h.secretKey):w;k.push(Z("extraEntropy",j))}let $=J(...k),F=S;function P(j){let W=D(j);if(!s.isValidNot0(W))return;let Q=s.inv(W),z=e.BASE.multiply(W).toAffine(),at=s.create(z.x);if(at===Ht)return;let Ve=s.create(Q*s.create(F+at*T));if(Ve===Ht)return;let Jn=(z.x===at?0:2)|Number(z.y&le),Qn=Ve;return A&&B(Ve)&&(Qn=s.neg(Ve),Jn^=1),new N(at,Qn,Jn)}return{seed:$,k2sig:P}}function H(p,g,E={}){p=Z("message",p);let{seed:A,k2sig:v}=U(p,g,E);return Pr(t.outputLen,s.BYTES,o)(A,v)}function C(p){let g,E=typeof p=="string"||qt(p),A=!E&&p!==null&&typeof p=="object"&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!E&&!A)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(A)g=new N(p.r,p.s);else if(E){try{g=N.fromBytes(Z("sig",p),"der")}catch(v){if(!(v instanceof Pt.Err))throw v}if(!g)try{g=N.fromBytes(Z("sig",p),"compact")}catch{return!1}}return g||!1}function _(p,g,E,A={}){let{lowS:v,prehash:w,format:S}=$r(A,x);if(E=Z("publicKey",E),g=M(Z("message",g),w),"strict"in A)throw new Error("options.strict was renamed to lowS");let T=S===void 0?C(p):N.fromBytes(Z("sig",p),S);if(T===!1)return!1;try{let k=e.fromBytes(E);if(v&&T.hasHighS())return!1;let{r:$,s:F}=T,P=K(g),j=s.inv(F),W=s.create(P*j),Q=s.create($*j),z=e.BASE.multiplyUnsafe(W).add(k.multiplyUnsafe(Q));return z.is0()?!1:s.create(z.x)===$}catch{return!1}}function m(p,g,E={}){let{prehash:A}=$r(E,x);return g=M(g,A),N.fromBytes(p,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:d,lengths:h,Point:e,sign:H,verify:_,recoverPublicKey:m,Signature:N,hash:t})}function zs(e){let t={a:e.a,b:e.b,p:e.Fp.ORDER,n:e.n,h:e.h,Gx:e.Gx,Gy:e.Gy},r=e.Fp,n=e.allowedPrivateKeyLengths?Array.from(new Set(e.allowedPrivateKeyLengths.map(s=>Math.ceil(s/2)))):void 0,o=Gt(t.n,{BITS:e.nBitLength,allowedLengths:n,modFromBytes:e.wrapPrivateKey}),i={Fp:r,Fn:o,allowInfinityPoint:e.allowInfinityPoint,endo:e.endo,isTorsionFree:e.isTorsionFree,clearCofactor:e.clearCofactor,fromBytes:e.fromBytes,toBytes:e.toBytes};return{CURVE:t,curveOpts:i}}function Gs(e){let{CURVE:t,curveOpts:r}=zs(e),n={hmac:e.hmac,randomBytes:e.randomBytes,lowS:e.lowS,bits2int:e.bits2int,bits2int_modN:e.bits2int_modN};return{CURVE:t,curveOpts:r,hash:e.hash,ecdsaOpts:n}}function Ks(e,t){let r=t.Point;return Object.assign({},t,{ProjectivePoint:r,CURVE:Object.assign({},e,Ye(r.Fn.ORDER,r.Fn.BITS))})}function Ro(e){let{CURVE:t,curveOpts:r,hash:n,ecdsaOpts:o}=Gs(e),i=qs(t,r),s=js(i,n,o);return Ks(e,s)}function _o(e,t){let r=n=>Ro({...e,hash:n});return{...r(t),create:r}}var de={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ws={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Zs=BigInt(0),No=BigInt(1),Gr=BigInt(2);function Ys(e){let t=de.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=xt(u,r,t)*u%t,d=xt(l,r,t)*u%t,h=xt(d,Gr,t)*f%t,x=xt(h,o,t)*h%t,y=xt(x,i,t)*x%t,B=xt(y,c,t)*y%t,I=xt(B,a,t)*B%t,L=xt(I,c,t)*y%t,N=xt(L,r,t)*u%t,D=xt(N,s,t)*x%t,K=xt(D,n,t)*f%t,O=xt(K,Gr,t);if(!er.eql(er.sqr(O),e))throw new Error("Cannot find square root");return O}var er=Gt(de.p,{sqrt:Ys}),Bt=_o({...de,Fp:er,lowS:!0,endo:Ws},Ct),Lo={};function rr(e,...t){let r=Lo[e];if(r===void 0){let n=Ct(ce(e));r=J(n,n),Lo[e]=r}return Ct(J(r,...t))}var Wr=e=>e.toBytes(!0).slice(1),he=Bt.Point,Zr=e=>e%Gr===Zs;function Kr(e){let{Fn:t,BASE:r}=he,n=Kt(t,e),o=r.multiply(n);return{scalar:Zr(o.y)?n:t.neg(n),bytes:Wr(o)}}function Oo(e){let t=er;if(!t.isValidNot0(e))throw new Error("invalid x: Fail if x \u2265 p");let r=t.create(e*e),n=t.create(r*e+BigInt(7)),o=t.sqrt(n);Zr(o)||(o=t.neg(o));let i=he.fromAffine({x:e,y:o});return i.assertValidity(),i}var Re=At;function Po(...e){return he.Fn.create(Re(rr("BIP0340/challenge",...e)))}function Co(e){return Kr(e).bytes}function Xs(e,t,r=rt(32)){let{Fn:n}=he,o=Z("message",e),{bytes:i,scalar:s}=Kr(t),c=Z("auxRand",r,32),a=n.toBytes(s^Re(rr("BIP0340/aux",c))),f=rr("BIP0340/nonce",a,i,o),{bytes:u,scalar:l}=Kr(f),d=Po(u,i,o),h=new Uint8Array(64);if(h.set(u,0),h.set(n.toBytes(n.create(l+d*s)),32),!Ho(h,o,i))throw new Error("sign: Invalid signature produced");return h}function Ho(e,t,r){let{Fn:n,BASE:o}=he,i=Z("signature",e,64),s=Z("message",t),c=Z("publicKey",r,32);try{let a=Oo(Re(c)),f=Re(i.subarray(0,32));if(!fe(f,No,de.p))return!1;let u=Re(i.subarray(32,64));if(!fe(u,No,de.n))return!1;let l=Po(n.toBytes(f),Wr(a),s),d=o.multiplyUnsafe(u).add(a.multiplyUnsafe(n.neg(l))),{x:h,y:x}=d.toAffine();return!(d.is0()||!Zr(x)||h!==f)}catch{return!1}}var nt=(()=>{let r=(o=rt(48))=>Xe(o,de.n);Bt.utils.randomSecretKey;function n(o){let i=r(o);return{secretKey:i,publicKey:Co(i)}}return{keygen:n,getPublicKey:Co,sign:Xs,verify:Ho,Point:he,utils:{randomSecretKey:r,randomPrivateKey:r,taggedHash:rr,lift_x:Oo,pointToBytes:Wr,numberToBytesBE:Yt,bytesToNumberBE:At,mod:gt},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var Y=yt;var X=Nt;var tt=Ct;var Go=Tr(zo());var G=(0,Go.default)({name:"nostr-crypto-utils",level:process.env.LOG_LEVEL||"info",transport:void 0,formatters:{level:e=>({level:e.toUpperCase()}),log:e=>{if(e&&typeof e=="object"&&"err"in e){let t={...e};if(t.err instanceof Error){let r=t.err;t.err={message:r.message,stack:r.stack,name:r.name}}return t}return e}}});function yc(e){try{return!!e.match(/^[A-Za-z0-9+/]*={0,2}$/)}catch{return!1}}function pe(e){return Buffer.from(e).toString("base64")}function ye(e){if(!yc(e))throw new Error("Invalid base64 string");return new Uint8Array(Buffer.from(e,"base64"))}var xc=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let e=await Promise.resolve().then(()=>(en(),tn));if(e.webcrypto)return e.webcrypto}catch{G.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},rn=class{constructor(){st(this,"cryptoInstance",null);st(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await xc()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(t){return(await this.ensureInitialized()).getRandomValues(t)}},cr=new rn,Ko=nt.sign,Wo=nt.verify;async function Zo(){let e=rt(32),t=Y(e);e.fill(0);let r=await ar(t);return{privateKey:t,publicKey:r}}async function ar(e){try{let t=X(e),r=nt.getPublicKey(t);return{hex:Y(r),bytes:r}}catch(t){throw G.error({error:t},"Failed to get public key"),t}}async function Yo(e){try{return(await ar(e.privateKey)).hex===e.publicKey.hex}catch(t){return G.error({error:t},"Failed to validate key pair"),!1}}function Xo(e){let t=Math.floor(Date.now()/1e3);return{...e,created_at:e.created_at||t,tags:e.tags||[],content:e.content||"",kind:e.kind||1}}async function nn(e,t){try{let r=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),n=tt(new TextEncoder().encode(r)),o=X(t),i=nt.sign(n,o);return{...e,id:Y(n),sig:Y(i)}}catch(r){throw G.error({error:r},"Failed to sign event"),r}}function on(e){let t=X(e),r=nt.getPublicKey(t);return Y(r)}async function Jo(e,t){let r=e.pubkey||on(t),n=e.created_at||Math.floor(Date.now()/1e3),o={kind:e.kind||1,created_at:n,tags:e.tags||[],content:e.content||"",pubkey:r};return nn(o,t)}async function Qo(e){try{let t=JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content]),r=tt(new TextEncoder().encode(t));if(Y(r)!==e.id)return G.error("Event ID mismatch"),!1;let o=X(e.sig),i=X(e.pubkey);return nt.verify(o,r,i)}catch(t){return G.error({error:t},"Failed to verify signature"),!1}}async function ti(e,t,r){try{let n=typeof t=="string"?t:t.hex,o=Bt.getSharedSecret(X(r),X(n)),i=o.slice(1,33),s=rt(16),c=await cr.getSubtle().then(d=>d.importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]));i.fill(0),o.fill(0);let a=new TextEncoder().encode(e),f=await cr.getSubtle().then(d=>d.encrypt({name:"AES-CBC",iv:s},c,a.buffer)),u=pe(new Uint8Array(f)),l=pe(s);return u+"?iv="+l}catch(n){throw G.error({error:n},"Failed to encrypt message"),n}}async function ei(e,t,r){try{let n=typeof t=="string"?t:t.hex,o=Bt.getSharedSecret(X(r),X(n)),i=o.slice(1,33),s,c;if(e.includes("?iv=")){let[u,l]=e.split("?iv=");c=ye(u),s=ye(l)}else{let u=X(e);s=u.slice(0,16),c=u.slice(16)}let a=await cr.getSubtle().then(u=>u.importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]));i.fill(0),o.fill(0);let f=await cr.getSubtle().then(u=>u.decrypt({name:"AES-CBC",iv:s},a,c.buffer));return new TextDecoder().decode(f)}catch(n){throw G.error({error:n},"Failed to decrypt message"),n}}function Le(e){return typeof e=="string"?e:e.hex}function bc(e){return new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16)))}function sn(e){try{let t=JSON.stringify([0,Le(e.pubkey),e.created_at,e.kind,e.tags,e.content]),r=Y(tt(new TextEncoder().encode(t)));return{isValid:r===e.id,error:r===e.id?void 0:"Invalid event ID"}}catch(t){return G.error({error:t},"Failed to validate event ID"),{isValid:!1,error:"Failed to validate event ID"}}}function cn(e){try{let t=JSON.stringify([0,Le(e.pubkey),e.created_at,e.kind,e.tags,e.content]),r=tt(new TextEncoder().encode(t)),n=Le(e.pubkey),o=bc(n),i=nt.verify(e.sig,r,o);return{isValid:i,error:i?void 0:"Invalid signature"}}catch(t){return G.error({error:t},"Failed to validate event signature"),{isValid:!1,error:"Failed to validate event signature"}}}function ri(e){let t=ur(e);if(!t.isValid)return t;let r=sn(e);return r.isValid?cn(e):r}function fr(e){try{let t=ur(e);if(!t.isValid)return t;let r=Le(e.pubkey);return!r||typeof r!="string"||r.length!==64?{isValid:!1,error:"Invalid public key format"}:!e.sig||typeof e.sig!="string"||e.sig.length!==128?{isValid:!1,error:"Invalid signature format"}:!e.id||typeof e.id!="string"||e.id.length!==64?{isValid:!1,error:"Invalid event ID format"}:{isValid:!0}}catch(t){return G.error({error:t},"Failed to validate signed event"),{isValid:!1,error:"Failed to validate signed event"}}}function ur(e){if(!e||typeof e!="object")return{isValid:!1,error:"Invalid event structure"};if(typeof e.kind!="number"||e.kind<0)return{isValid:!1,error:"Event kind must be a non-negative integer"};let t=Math.floor(Date.now()/1e3);if(typeof e.created_at!="number"||e.created_at>t+60)return{isValid:!1,error:"Event timestamp cannot be in the future"};if(typeof e.content!="string")return{isValid:!1,error:"Event content must be a string"};if(!e.pubkey)return{isValid:!1,error:"Missing public key"};let r=Le(e.pubkey);if(typeof r!="string"||!/^[0-9a-f]{64}$/.test(r))return{isValid:!1,error:"Invalid public key format"};if(!Array.isArray(e.tags))return{isValid:!1,error:"Event tags must be an array"};for(let n of e.tags){if(!Array.isArray(n))return{isValid:!1,error:"Each tag must be an array"};if(n.length===0)return{isValid:!1,error:"Empty tags are not allowed"};if(typeof n[0]!="string")return{isValid:!1,error:"Tag identifier must be a string"}}return{isValid:!0}}function lr(e){try{if(!e||typeof e!="object")return{isValid:!1,error:"Invalid filter structure"};if(e.ids&&(!Array.isArray(e.ids)||!e.ids.every(t=>typeof t=="string")))return{isValid:!1,error:"Filter ids must be an array of strings"};if(e.authors&&(!Array.isArray(e.authors)||!e.authors.every(t=>typeof t=="string")))return{isValid:!1,error:"Filter authors must be an array of strings"};if(e.kinds){if(!Array.isArray(e.kinds))return{isValid:!1,error:"Filter kinds must be an array of numbers"};if(!e.kinds.every(t=>typeof t=="number"&&Number.isInteger(t)&&t>=0))return{isValid:!1,error:"Filter kinds must be non-negative integers"}}return e.since&&typeof e.since!="number"?{isValid:!1,error:"Filter since must be a number"}:e.until&&typeof e.until!="number"?{isValid:!1,error:"Filter until must be a number"}:e.limit&&typeof e.limit!="number"?{isValid:!1,error:"Filter limit must be a number"}:e.search&&typeof e.search!="string"?{isValid:!1,error:"Filter search must be a string"}:{isValid:!0}}catch(t){return G.error({error:t},"Failed to validate filter"),{isValid:!1,error:"Failed to validate filter"}}}function ni(e){try{if(!e||typeof e!="object")return{isValid:!1,error:"Invalid subscription structure"};if(!e.id||typeof e.id!="string")return{isValid:!1,error:"Subscription must have a string ID"};if(!Array.isArray(e.filters))return{isValid:!1,error:"Subscription filters must be an array"};for(let t of e.filters){let r=lr(t);if(!r.isValid)return r}return{isValid:!0}}catch(t){return G.error({error:t},"Failed to validate subscription"),{isValid:!1,error:"Failed to validate subscription"}}}function oi(e){if(!Array.isArray(e))return{isValid:!1,error:"Invalid message format: must be an array"};if(e.length===0)return{isValid:!1,error:"Invalid message format: array is empty"};let t=e[0];if(!Object.values(Ie).includes(t))return{isValid:!1,error:`Invalid message type: ${t}`};switch(t){case"EVENT":return e.length!==2?{isValid:!1,error:"EVENT message must have exactly 2 elements"}:fr(e[1]);case"NOTICE":return e.length!==2||typeof e[1]!="string"?{isValid:!1,error:"NOTICE message must have exactly 2 elements with a string message"}:{isValid:!0};case"OK":return e.length!==4||typeof e[1]!="string"||typeof e[2]!="boolean"||typeof e[3]!="string"?{isValid:!1,error:"OK message must have exactly 4 elements: [type, eventId, success, message]"}:{isValid:!0};case"EOSE":return e.length!==2||typeof e[1]!="string"?{isValid:!1,error:"EOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"REQ":if(e.length<2)return{isValid:!1,error:"REQ message must have at least 2 elements"};if(typeof e[1]!="string")return{isValid:!1,error:"REQ message must have a string subscription ID"};for(let r=2;r<e.length;r++){let n=lr(e[r]);if(!n.isValid)return n}return{isValid:!0};case"CLOSE":return e.length!==2||typeof e[1]!="string"?{isValid:!1,error:"CLOSE message must have exactly 2 elements with a subscription ID"}:{isValid:!0};case"AUTH":return e.length!==2?{isValid:!1,error:"AUTH message must have exactly 2 elements"}:fr(e[1]);default:return{isValid:!1,error:`Unsupported message type: ${t}`}}}function ii(e){return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}async function an(e){try{let t=ii(e),r=await tt(new TextEncoder().encode(t));return yt(r)}catch(t){throw G.error({error:t},"Failed to get event hash"),t}}function fn(e){return an(e)}var pn={};kt(pn,{computeSharedSecret:()=>hn,decryptMessage:()=>dn,encryptMessage:()=>ln,generateSharedSecret:()=>hn});var mc=async()=>{if(typeof window<"u"&&window.crypto)return window.crypto;if(typeof global<"u"&&global.crypto)return global.crypto;try{let e=await Promise.resolve().then(()=>(en(),tn));if(e.webcrypto)return e.webcrypto}catch{G.debug("Node crypto not available")}throw new Error("No WebCrypto implementation available")},un=class{constructor(){st(this,"cryptoInstance",null);st(this,"initPromise");this.initPromise=this.initialize()}async initialize(){this.cryptoInstance=await mc()}async ensureInitialized(){if(await this.initPromise,!this.cryptoInstance)throw new Error("Crypto implementation not initialized");return this.cryptoInstance}async getSubtle(){return(await this.ensureInitialized()).subtle}async getRandomValues(t){return(await this.ensureInitialized()).getRandomValues(t)}},Ce=new un;async function ln(e,t,r){try{if(!e||!t||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(t))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,o=Bt.getSharedSecret(t,n),i=o.slice(1,33),s=await(await Ce.getSubtle()).importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["encrypt"]);i.fill(0),o.fill(0);let c=new Uint8Array(16);await Ce.getRandomValues(c);let a=new TextEncoder().encode(e),f=await(await Ce.getSubtle()).encrypt({name:"AES-CBC",iv:c},s,a.buffer),u=pe(new Uint8Array(f)),l=pe(c);return u+"?iv="+l}catch(n){throw G.error({error:n},"Failed to encrypt message"),n}}async function dn(e,t,r){try{if(!e||!t||!r)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(t))throw new Error("Invalid private key format");let n=r.startsWith("02")||r.startsWith("03")?r:"02"+r,o=Bt.getSharedSecret(t,n),i=o.slice(1,33),s=await(await Ce.getSubtle()).importKey("raw",i.buffer,{name:"AES-CBC",length:256},!1,["decrypt"]);i.fill(0),o.fill(0);let c,a;if(e.includes("?iv=")){let[u,l]=e.split("?iv=");a=ye(u),c=ye(l)}else{let u=X(e);c=u.slice(0,16),a=u.slice(16)}let f=await(await Ce.getSubtle()).decrypt({name:"AES-CBC",iv:c},s,a.buffer);return new TextDecoder().decode(f)}catch(n){throw G.error({error:n},"Failed to decrypt message"),n}}function hn(e,t){try{if(!e||!t)throw new Error("Invalid input parameters");if(!/^[0-9a-f]{64}$/i.test(e))throw new Error("Invalid private key format");let r=t.startsWith("02")||t.startsWith("03")?t:"02"+t;return{sharedSecret:Bt.getSharedSecret(e,r).slice(1,33)}}catch(r){throw G.error({error:r},"Failed to generate shared secret"),r}}var gn={};kt(gn,{calculateEventId:()=>ci,createEvent:()=>wc,getEventHash:()=>si,serializeEvent:()=>yn,signEvent:()=>Ec,validateEvent:()=>Ac,verifySignature:()=>Bc});function wc(e){let{kind:t,content:r,tags:n=[],created_at:o=Math.floor(Date.now()/1e3),pubkey:i=""}=e;return{kind:t,content:r,tags:n,created_at:o,pubkey:i}}function yn(e){return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}async function si(e){try{let t=yn(e),r=tt(new TextEncoder().encode(t));return Y(r)}catch(t){throw G.error({error:t},"Failed to get event hash"),t}}async function Ec(e,t){try{let r=await si(e),n=nt.sign(X(r),t);return{...e,id:r,sig:Y(n)}}catch(r){throw G.error({error:r},"Failed to sign event"),r}}function Bc(e){try{let t=ci(e);return e.id!==t?!1:nt.verify(X(e.sig),X(e.id),X(e.pubkey))}catch(t){return G.error({error:t},"Failed to verify signature"),!1}}function ci(e){let t=yn(e),r=tt(new TextEncoder().encode(t));return Y(r)}function Ac(e){try{if(typeof e.content!="string"||typeof e.created_at!="number"||typeof e.kind!="number"||!Array.isArray(e.tags)||typeof e.pubkey!="string")return!1;for(let t of e.tags)if(!Array.isArray(t)||t.length===0||typeof t[0]!="string")return!1;return!0}catch(t){return G.error({error:t},"Failed to validate event"),!1}}var kn={};kt(kn,{decode:()=>ha,naddrEncode:()=>la,neventEncode:()=>ua,noteEncode:()=>aa,nprofileEncode:()=>fa,npubEncode:()=>sa,nrelayEncode:()=>da,nsecEncode:()=>ca});var lt=Tr(li()),mt=Tr(Ni()),ia=["npub","nsec","note","nprofile","nevent","naddr","nrelay"],vt={SPECIAL:0,RELAY:1,AUTHOR:2,KIND:3,IDENTIFIER:4};function sa(e){Tt(e,64);let t=mt.Buffer.from(e,"hex"),r=lt.bech32.toWords(t);return lt.bech32.encode("npub",r,1e3)}function ca(e){Tt(e,64);let t=mt.Buffer.from(e,"hex"),r=lt.bech32.toWords(t);return lt.bech32.encode("nsec",r,1e3)}function aa(e){Tt(e,64);let t=mt.Buffer.from(e,"hex"),r=lt.bech32.toWords(t);return lt.bech32.encode("note",r,1e3)}function fa(e,t){Tt(e,64),t&&t.forEach(Be);let r=Un({type:"nprofile",data:e,relays:t});return lt.bech32.encode("nprofile",r,1e3)}function ua(e,t,r,n){if(Tt(e,64),t&&t.forEach(Be),r&&Tt(r,64),n!==void 0&&!Number.isInteger(n))throw new Error("Invalid event kind");let o=Un({type:"nevent",data:e,relays:t,author:r,kind:n});return lt.bech32.encode("nevent",o,1e3)}function la(e,t,r,n){if(Tt(e,64),!Number.isInteger(t))throw new Error("Invalid event kind");if(!r)throw new Error("Identifier is required");n&&n.forEach(Be);let o=Un({type:"naddr",data:e,kind:t,identifier:r,relays:n});return lt.bech32.encode("naddr",o,1e3)}function da(e){Be(e);let t=mt.Buffer.from(e,"utf8"),r=lt.bech32.toWords(t);return lt.bech32.encode("nrelay",r,1e3)}function ha(e){if(!e.includes("1"))throw new Error("Invalid bech32 string");let t=e.split("1")[0].toLowerCase();if(!ia.includes(t))throw new Error("Unknown prefix");try{let r=lt.bech32.decode(e,1e3),n=mt.Buffer.from(lt.bech32.fromWords(r.words)),o,i;switch(r.prefix){case"npub":case"nsec":case"note":return Tt(n.toString("hex"),64),{type:r.prefix,data:n.toString("hex")};case"nrelay":return o=n.toString("utf8"),Be(o),{type:"nrelay",data:o};case"nprofile":case"nevent":case"naddr":return i=pa(r.prefix,n),i;default:throw new Error("Unknown prefix")}}catch(r){throw r instanceof Error?r:new Error("Invalid bech32 string")}}function Tt(e,t){if(!/^[0-9a-fA-F]+$/.test(e))throw new Error("Invalid hex string");if(t&&e.length!==t)throw new Error(`Invalid hex string length (expected ${t})`)}function Be(e){try{let t=new URL(e);if(!["ws:","wss:"].includes(t.protocol))throw new Error("Invalid relay URL protocol")}catch{throw new Error("Invalid relay URL")}}function Un(e){let t=[],r=mt.Buffer.from(e.data,"hex");if(t.push(vt.SPECIAL,r.length),t.push(...r),e.relays?.length)for(let n of e.relays){let o=mt.Buffer.from(n,"utf8");t.push(vt.RELAY,o.length),t.push(...o)}if(e.author){let n=mt.Buffer.from(e.author,"hex");t.push(vt.AUTHOR,n.length),t.push(...n)}if(e.kind!==void 0){let n=mt.Buffer.alloc(4);n.writeUInt32BE(e.kind),t.push(vt.KIND,n.length),t.push(...n)}if(e.identifier){let n=mt.Buffer.from(e.identifier,"utf8");t.push(vt.IDENTIFIER,n.length),t.push(...n)}return lt.bech32.toWords(mt.Buffer.from(t))}function pa(e,t){let r={type:e,data:"",relays:[]},n=0,o;for(;n<t.length;){let i=t[n],s=t[n+1];if(n+2+s>t.length)throw new Error("Invalid TLV data");let c=t.slice(n+2,n+2+s);switch(i){case vt.SPECIAL:r.data=c.toString("hex"),Tt(r.data,64);break;case vt.RELAY:o=c.toString("utf8"),Be(o),r.relays=r.relays||[],r.relays.push(o);break;case vt.AUTHOR:r.author=c.toString("hex"),Tt(r.author,64);break;case vt.KIND:r.kind=c.readUInt32BE();break;case vt.IDENTIFIER:r.identifier=c.toString("utf8");break;default:break}n+=2+s}return r}var _n={};kt(_n,{addDelegationTag:()=>ba,checkDelegationConditions:()=>xa,createDelegation:()=>ya,extractDelegation:()=>ma,verifyDelegation:()=>ga});function ya(e,t,r){let n=Rn(r),o=Ea(e,t,n);return{delegator:Y(nt.getPublicKey(X(e))),delegatee:t,conditions:r,token:o}}async function ga(e){let t=Rn(e.conditions);return await Ba(e.delegator,e.delegatee,t,e.token)}function xa(e,t){return!(t.kind!==void 0&&e.kind!==t.kind||t.since!==void 0&&e.created_at<t.since||t.until!==void 0&&e.created_at>t.until)}function ba(e,t){let r=["delegation",t.delegator,Rn(t.conditions),t.token];return{...e,tags:[...e.tags,r]}}function ma(e){let t=e.tags.find(r=>r[0]==="delegation");return!t||t.length!==4?null:{delegator:t[1],delegatee:e.pubkey,conditions:wa(t[2]),token:t[3]}}function Rn(e){let t=[];return e.kind!==void 0&&t.push(`kind=${e.kind}`),e.since!==void 0&&t.push(`created_at>${e.since}`),e.until!==void 0&&t.push(`created_at<${e.until}`),t.join("&")}function wa(e){let t={},r=e.split("&");for(let n of r)n.startsWith("kind=")?t.kind=parseInt(n.slice(5)):n.startsWith("created_at>")?t.since=parseInt(n.slice(11)):n.startsWith("created_at<")&&(t.until=parseInt(n.slice(11)));return t}function Ea(e,t,r){let n=`nostr:delegation:${t}:${r}`,o=tt(new TextEncoder().encode(n)),i=Ko(o,e);return Y(i)}async function Ba(e,t,r,n){let o=tt(new TextEncoder().encode(`nostr:delegation:${t}:${r}`));return Wo(n,o,e)}var Gn={};kt(Gn,{calcPaddedLen:()=>Sr,decrypt:()=>vr,encrypt:()=>Ir,getConversationKey:()=>De,v2:()=>Ka});function Aa(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function gr(e){if(typeof e!="boolean")throw new Error(`boolean expected, not ${e}`)}function xr(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function it(e,t,r=""){let n=Aa(e),o=e?.length,i=t!==void 0;if(!n||i&&o!==t){let s=r&&`"${r}" `,c=i?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(s+"expected Uint8Array"+c+", got "+a)}return e}function Nn(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Li(e,t){it(e,void 0,"output");let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Ft(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Sa(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var Ia=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ci(e,t){if(t==null||typeof t!="object")throw new Error("options must be defined");return Object.assign(e,t)}function br(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}var Ln=(e,t)=>{function r(n,...o){if(it(n,void 0,"key"),!Ia)throw new Error("Non little-endian hardware is not yet supported");if(e.nonceLength!==void 0){let u=o[0];it(u,e.varSizeNonce?void 0:e.nonceLength,"nonce")}let i=e.tagLength;i&&o[1]!==void 0&&it(o[1],void 0,"AAD");let s=t(n,...o),c=(u,l)=>{if(l!==void 0){if(u!==2)throw new Error("cipher output not supported");it(l,void 0,"output")}},a=!1;return{encrypt(u,l){if(a)throw new Error("cannot encrypt() twice with same key + nonce");return a=!0,it(u),c(s.encrypt.length,l),s.encrypt(u,l)},decrypt(u,l){if(it(u),i&&u.length<i)throw new Error('"ciphertext" expected length bigger than tagLength='+i);return c(s.decrypt.length,l),s.decrypt(u,l)}}}return Object.assign(r,e),r};function Cn(e,t,r=!0){if(t===void 0)return new Uint8Array(e);if(t.length!==e)throw new Error('"output" expected Uint8Array of length '+e+", got: "+t.length);if(r&&!va(t))throw new Error("invalid output, must be aligned");return t}function Oi(e,t,r){gr(r);let n=new Uint8Array(16),o=Sa(n);return o.setBigUint64(0,BigInt(t),r),o.setBigUint64(8,BigInt(e),r),n}function va(e){return e.byteOffset%4===0}function Ae(e){return Uint8Array.from(e)}var Hi=e=>Uint8Array.from(e.split(""),t=>t.charCodeAt(0)),Ta=Hi("expand 16-byte k"),Ua=Hi("expand 32-byte k"),ka=Ft(Ta),Ra=Ft(Ua);function R(e,t){return e<<t|e>>>32-t}function On(e){return e.byteOffset%4===0}var mr=64,_a=16,Di=2**32-1,Pi=Uint32Array.of();function Na(e,t,r,n,o,i,s,c){let a=o.length,f=new Uint8Array(mr),u=Ft(f),l=On(o)&&On(i),d=l?Ft(o):Pi,h=l?Ft(i):Pi;for(let x=0;x<a;s++){if(e(t,r,n,u,s,c),s>=Di)throw new Error("arx: counter overflow");let y=Math.min(mr,a-x);if(l&&y===mr){let B=x/4;if(x%4!==0)throw new Error("arx: invalid block position");for(let I=0,L;I<_a;I++)L=B+I,h[L]=d[L]^u[I];x+=mr;continue}for(let B=0,I;B<y;B++)I=x+B,i[I]=o[I]^f[B];x+=y}}function Pn(e,t){let{allowShortKeys:r,extendNonceFn:n,counterLength:o,counterRight:i,rounds:s}=Ci({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!="function")throw new Error("core must be a function");return xr(o),xr(s),gr(i),gr(r),(c,a,f,u,l=0)=>{it(c,void 0,"key"),it(a,void 0,"nonce"),it(f,void 0,"data");let d=f.length;if(u===void 0&&(u=new Uint8Array(d)),it(u,void 0,"output"),xr(l),l<0||l>=Di)throw new Error("arx: counter overflow");if(u.length<d)throw new Error(`arx: output (${u.length}) is shorter than data (${d})`);let h=[],x=c.length,y,B;if(x===32)h.push(y=Ae(c)),B=Ra;else if(x===16&&r)y=new Uint8Array(32),y.set(c),y.set(c,16),B=ka,h.push(y);else throw it(c,32,"arx key"),new Error("invalid key size");On(a)||h.push(a=Ae(a));let I=Ft(y);if(n){if(a.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(B,I,Ft(a.subarray(0,16)),I),a=a.subarray(16)}let L=16-o;if(L!==a.length)throw new Error(`arx: nonce must be ${L} or 16 bytes`);if(L!==12){let D=new Uint8Array(12);D.set(a,i?0:12-a.length),a=D,h.push(a)}let N=Ft(a);return Na(e,B,I,N,f,u,l,s),Mt(...h),u}}function ct(e,t){return e[t++]&255|(e[t++]&255)<<8}var Hn=class{constructor(t){st(this,"blockLen",16);st(this,"outputLen",16);st(this,"buffer",new Uint8Array(16));st(this,"r",new Uint16Array(10));st(this,"h",new Uint16Array(10));st(this,"pad",new Uint16Array(8));st(this,"pos",0);st(this,"finished",!1);t=Ae(it(t,32,"key"));let r=ct(t,0),n=ct(t,2),o=ct(t,4),i=ct(t,6),s=ct(t,8),c=ct(t,10),a=ct(t,12),f=ct(t,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|o<<6)&7939,this.r[3]=(o>>>7|i<<9)&8191,this.r[4]=(i>>>4|s<<12)&255,this.r[5]=s>>>1&8190,this.r[6]=(s>>>14|c<<2)&8191,this.r[7]=(c>>>11|a<<5)&8065,this.r[8]=(a>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=ct(t,16+2*u)}process(t,r,n=!1){let o=n?0:2048,{h:i,r:s}=this,c=s[0],a=s[1],f=s[2],u=s[3],l=s[4],d=s[5],h=s[6],x=s[7],y=s[8],B=s[9],I=ct(t,r+0),L=ct(t,r+2),N=ct(t,r+4),D=ct(t,r+6),K=ct(t,r+8),O=ct(t,r+10),q=ct(t,r+12),M=ct(t,r+14),U=i[0]+(I&8191),H=i[1]+((I>>>13|L<<3)&8191),C=i[2]+((L>>>10|N<<6)&8191),_=i[3]+((N>>>7|D<<9)&8191),m=i[4]+((D>>>4|K<<12)&8191),p=i[5]+(K>>>1&8191),g=i[6]+((K>>>14|O<<2)&8191),E=i[7]+((O>>>11|q<<5)&8191),A=i[8]+((q>>>8|M<<8)&8191),v=i[9]+(M>>>5|o),w=0,S=w+U*c+H*(5*B)+C*(5*y)+_*(5*x)+m*(5*h);w=S>>>13,S&=8191,S+=p*(5*d)+g*(5*l)+E*(5*u)+A*(5*f)+v*(5*a),w+=S>>>13,S&=8191;let T=w+U*a+H*c+C*(5*B)+_*(5*y)+m*(5*x);w=T>>>13,T&=8191,T+=p*(5*h)+g*(5*d)+E*(5*l)+A*(5*u)+v*(5*f),w+=T>>>13,T&=8191;let k=w+U*f+H*a+C*c+_*(5*B)+m*(5*y);w=k>>>13,k&=8191,k+=p*(5*x)+g*(5*h)+E*(5*d)+A*(5*l)+v*(5*u),w+=k>>>13,k&=8191;let $=w+U*u+H*f+C*a+_*c+m*(5*B);w=$>>>13,$&=8191,$+=p*(5*y)+g*(5*x)+E*(5*h)+A*(5*d)+v*(5*l),w+=$>>>13,$&=8191;let F=w+U*l+H*u+C*f+_*a+m*c;w=F>>>13,F&=8191,F+=p*(5*B)+g*(5*y)+E*(5*x)+A*(5*h)+v*(5*d),w+=F>>>13,F&=8191;let P=w+U*d+H*l+C*u+_*f+m*a;w=P>>>13,P&=8191,P+=p*c+g*(5*B)+E*(5*y)+A*(5*x)+v*(5*h),w+=P>>>13,P&=8191;let j=w+U*h+H*d+C*l+_*u+m*f;w=j>>>13,j&=8191,j+=p*a+g*c+E*(5*B)+A*(5*y)+v*(5*x),w+=j>>>13,j&=8191;let W=w+U*x+H*h+C*d+_*l+m*u;w=W>>>13,W&=8191,W+=p*f+g*a+E*c+A*(5*B)+v*(5*y),w+=W>>>13,W&=8191;let Q=w+U*y+H*x+C*h+_*d+m*l;w=Q>>>13,Q&=8191,Q+=p*u+g*f+E*a+A*c+v*(5*B),w+=Q>>>13,Q&=8191;let z=w+U*B+H*y+C*x+_*h+m*d;w=z>>>13,z&=8191,z+=p*l+g*u+E*f+A*a+v*c,w+=z>>>13,z&=8191,w=(w<<2)+w|0,w=w+S|0,S=w&8191,w=w>>>13,T+=w,i[0]=S,i[1]=T,i[2]=k,i[3]=$,i[4]=F,i[5]=P,i[6]=j,i[7]=W,i[8]=Q,i[9]=z}finalize(){let{h:t,pad:r}=this,n=new Uint16Array(10),o=t[1]>>>13;t[1]&=8191;for(let c=2;c<10;c++)t[c]+=o,o=t[c]>>>13,t[c]&=8191;t[0]+=o*5,o=t[0]>>>13,t[0]&=8191,t[1]+=o,o=t[1]>>>13,t[1]&=8191,t[2]+=o,n[0]=t[0]+5,o=n[0]>>>13,n[0]&=8191;for(let c=1;c<10;c++)n[c]=t[c]+o,o=n[c]>>>13,n[c]&=8191;n[9]-=8192;let i=(o^1)-1;for(let c=0;c<10;c++)n[c]&=i;i=~i;for(let c=0;c<10;c++)t[c]=t[c]&i|n[c];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let s=t[0]+r[0];t[0]=s&65535;for(let c=1;c<8;c++)s=(t[c]+r[c]|0)+(s>>>16)|0,t[c]=s&65535;Mt(n)}update(t){Nn(this),it(t),t=Ae(t);let{buffer:r,blockLen:n}=this,o=t.length;for(let i=0;i<o;){let s=Math.min(n-this.pos,o-i);if(s===n){for(;n<=o-i;i+=n)this.process(t,i);continue}r.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){Mt(this.h,this.r,this.buffer,this.pad)}digestInto(t){Nn(this),Li(t,this),this.finished=!0;let{buffer:r,h:n}=this,{pos:o}=this;if(o){for(r[o++]=1;o<16;o++)r[o]=0;this.process(r,0,!0)}this.finalize();let i=0;for(let s=0;s<8;s++)t[i++]=n[s]>>>0,t[i++]=n[s]>>>8;return t}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}};function La(e){let t=(n,o)=>e(o).update(n).digest(),r=e(new Uint8Array(32));return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=n=>e(n),t}var Vi=La(e=>new Hn(e));function qi(e,t,r,n,o,i=20){let s=e[0],c=e[1],a=e[2],f=e[3],u=t[0],l=t[1],d=t[2],h=t[3],x=t[4],y=t[5],B=t[6],I=t[7],L=o,N=r[0],D=r[1],K=r[2],O=s,q=c,M=a,U=f,H=u,C=l,_=d,m=h,p=x,g=y,E=B,A=I,v=L,w=N,S=D,T=K;for(let $=0;$<i;$+=2)O=O+H|0,v=R(v^O,16),p=p+v|0,H=R(H^p,12),O=O+H|0,v=R(v^O,8),p=p+v|0,H=R(H^p,7),q=q+C|0,w=R(w^q,16),g=g+w|0,C=R(C^g,12),q=q+C|0,w=R(w^q,8),g=g+w|0,C=R(C^g,7),M=M+_|0,S=R(S^M,16),E=E+S|0,_=R(_^E,12),M=M+_|0,S=R(S^M,8),E=E+S|0,_=R(_^E,7),U=U+m|0,T=R(T^U,16),A=A+T|0,m=R(m^A,12),U=U+m|0,T=R(T^U,8),A=A+T|0,m=R(m^A,7),O=O+C|0,T=R(T^O,16),E=E+T|0,C=R(C^E,12),O=O+C|0,T=R(T^O,8),E=E+T|0,C=R(C^E,7),q=q+_|0,v=R(v^q,16),A=A+v|0,_=R(_^A,12),q=q+_|0,v=R(v^q,8),A=A+v|0,_=R(_^A,7),M=M+m|0,w=R(w^M,16),p=p+w|0,m=R(m^p,12),M=M+m|0,w=R(w^M,8),p=p+w|0,m=R(m^p,7),U=U+H|0,S=R(S^U,16),g=g+S|0,H=R(H^g,12),U=U+H|0,S=R(S^U,8),g=g+S|0,H=R(H^g,7);let k=0;n[k++]=s+O|0,n[k++]=c+q|0,n[k++]=a+M|0,n[k++]=f+U|0,n[k++]=u+H|0,n[k++]=l+C|0,n[k++]=d+_|0,n[k++]=h+m|0,n[k++]=x+p|0,n[k++]=y+g|0,n[k++]=B+E|0,n[k++]=I+A|0,n[k++]=L+v|0,n[k++]=N+w|0,n[k++]=D+S|0,n[k++]=K+T|0}function Ca(e,t,r,n){let o=e[0],i=e[1],s=e[2],c=e[3],a=t[0],f=t[1],u=t[2],l=t[3],d=t[4],h=t[5],x=t[6],y=t[7],B=r[0],I=r[1],L=r[2],N=r[3];for(let K=0;K<20;K+=2)o=o+a|0,B=R(B^o,16),d=d+B|0,a=R(a^d,12),o=o+a|0,B=R(B^o,8),d=d+B|0,a=R(a^d,7),i=i+f|0,I=R(I^i,16),h=h+I|0,f=R(f^h,12),i=i+f|0,I=R(I^i,8),h=h+I|0,f=R(f^h,7),s=s+u|0,L=R(L^s,16),x=x+L|0,u=R(u^x,12),s=s+u|0,L=R(L^s,8),x=x+L|0,u=R(u^x,7),c=c+l|0,N=R(N^c,16),y=y+N|0,l=R(l^y,12),c=c+l|0,N=R(N^c,8),y=y+N|0,l=R(l^y,7),o=o+f|0,N=R(N^o,16),x=x+N|0,f=R(f^x,12),o=o+f|0,N=R(N^o,8),x=x+N|0,f=R(f^x,7),i=i+u|0,B=R(B^i,16),y=y+B|0,u=R(u^y,12),i=i+u|0,B=R(B^i,8),y=y+B|0,u=R(u^y,7),s=s+l|0,I=R(I^s,16),d=d+I|0,l=R(l^d,12),s=s+l|0,I=R(I^s,8),d=d+I|0,l=R(l^d,7),c=c+a|0,L=R(L^c,16),h=h+L|0,a=R(a^h,12),c=c+a|0,L=R(L^c,8),h=h+L|0,a=R(a^h,7);let D=0;n[D++]=o,n[D++]=i,n[D++]=s,n[D++]=c,n[D++]=B,n[D++]=I,n[D++]=L,n[D++]=N}var wr=Pn(qi,{counterRight:!1,counterLength:4,allowShortKeys:!1}),Oa=Pn(qi,{counterRight:!1,counterLength:8,extendNonceFn:Ca,allowShortKeys:!1});var Pa=new Uint8Array(16),Fi=(e,t)=>{e.update(t);let r=t.length%16;r&&e.update(Pa.subarray(r))},Ha=new Uint8Array(32);function Mi(e,t,r,n,o){o!==void 0&&it(o,void 0,"AAD");let i=e(t,r,Ha),s=Oi(n.length,o?o.length:0,!0),c=Vi.create(i);o&&Fi(c,o),Fi(c,n),c.update(s);let a=c.digest();return Mt(i,s),a}var $i=e=>(t,r,n)=>({encrypt(i,s){let c=i.length;s=Cn(c+16,s,!1),s.set(i);let a=s.subarray(0,-16);e(t,r,a,a,1);let f=Mi(e,t,r,a,n);return s.set(f,c),Mt(f),s},decrypt(i,s){s=Cn(i.length-16,s,!1);let c=i.subarray(0,-16),a=i.subarray(-16),f=Mi(e,t,r,c,n);if(!br(a,f))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),e(t,r,s,s,1),Mt(f),s}}),Gl=Ln({blockSize:64,nonceLength:12,tagLength:16},$i(wr)),Dn=Ln({blockSize:64,nonceLength:24,tagLength:16},$i(Oa));function zi(e,t,r){return _t(e),r===void 0&&(r=new Uint8Array(e.outputLen)),Et(e,$t(r),$t(t))}var Vn=Uint8Array.from([0]),ji=Uint8Array.of();function Gi(e,t,r,n=32){_t(e),et(n);let o=e.outputLen;if(n>255*o)throw new Error("Length should be <= 255*HashLen");let i=Math.ceil(n/o);r===void 0&&(r=ji);let s=new Uint8Array(i*o),c=Et.create(e,t),a=c._cloneInto(),f=new Uint8Array(c.outputLen);for(let u=0;u<i;u++)Vn[0]=u+1,a.update(u===0?ji:f).update(r).update(Vn).digestInto(f),s.set(f,o*u),c._cloneInto(a);return c.destroy(),a.destroy(),pt(f,Vn),s.slice(0,n)}function $n(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Da(e){if(!$n(e))throw new Error("Uint8Array expected")}function Yi(e,t){return Array.isArray(t)?t.length===0?!0:e?t.every(r=>typeof r=="string"):t.every(r=>Number.isSafeInteger(r)):!1}function Va(e){if(typeof e!="function")throw new Error("function expected");return!0}function re(e,t){if(typeof t!="string")throw new Error(`${e}: string expected`);return!0}function jn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function Fn(e){if(!Array.isArray(e))throw new Error("array expected")}function Br(e,t){if(!Yi(!0,t))throw new Error(`${e}: array of strings expected`)}function Xi(e,t){if(!Yi(!1,t))throw new Error(`${e}: array of numbers expected`)}function Ji(...e){let t=i=>i,r=(i,s)=>c=>i(s(c)),n=e.map(i=>i.encode).reduceRight(r,t),o=e.map(i=>i.decode).reduce(r,t);return{encode:n,decode:o}}function Qi(e){let t=typeof e=="string"?e.split(""):e,r=t.length;Br("alphabet",t);let n=new Map(t.map((o,i)=>[o,i]));return{encode:o=>(Fn(o),o.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${e}`);return t[i]})),decode:o=>(Fn(o),o.map(i=>{re("alphabet.decode",i);let s=n.get(i);if(s===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${e}`);return s}))}}function ts(e=""){return re("join",e),{encode:t=>(Br("join.decode",t),t.join(e)),decode:t=>(re("join.decode",t),t.split(e))}}function Fa(e,t="="){return jn(e),re("padding",t),{encode(r){for(Br("padding.encode",r);r.length*e%8;)r.push(t);return r},decode(r){Br("padding.decode",r);let n=r.length;if(n*e%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===t;n--)if((n-1)*e%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}var es=(e,t)=>t===0?e:es(t,e%t),Ar=(e,t)=>e+(t-es(e,t)),Er=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})();function Mn(e,t,r,n){if(Fn(e),t<=0||t>32)throw new Error(`convertRadix2: wrong from=${t}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Ar(t,r)>32)throw new Error(`convertRadix2: carry overflow from=${t} to=${r} carryBits=${Ar(t,r)}`);let o=0,i=0,s=Er[t],c=Er[r]-1,a=[];for(let f of e){if(jn(f),f>=s)throw new Error(`convertRadix2: invalid data word=${f} from=${t}`);if(o=o<<t|f,i+t>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${t}`);for(i+=t;i>=r;i-=r)a.push((o>>i-r&c)>>>0);let u=Er[i];if(u===void 0)throw new Error("invalid carry");o&=u-1}if(o=o<<r-i&c,!n&&i>=t)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&i>0&&a.push(o>>>0),a}function rs(e,t=!1){if(jn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Ar(8,e)>32||Ar(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!$n(r))throw new Error("radix2.encode input should be Uint8Array");return Mn(Array.from(r),8,e,!t)},decode:r=>(Xi("radix2.decode",r),Uint8Array.from(Mn(r,e,8,t)))}}function Ki(e){return Va(e),function(...t){try{return e.apply(null,t)}catch{}}}var Ma=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",qa=(e,t)=>{re("base64",e);let r=t?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,n=t?"base64url":"base64";if(e.length>0&&!r.test(e))throw new Error("invalid base64");return Uint8Array.fromBase64(e,{alphabet:n,lastChunkHandling:"strict"})},zn=Ma?{encode(e){return Da(e),e.toBase64()},decode(e){return qa(e,!1)}}:Ji(rs(6),Qi("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Fa(6),ts(""));var qn=Ji(Qi("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ts("")),Wi=[996825010,642813549,513874426,1027748829,705979059];function Pe(e){let t=e>>25,r=(e&33554431)<<5;for(let n=0;n<Wi.length;n++)(t>>n&1)===1&&(r^=Wi[n]);return r}function Zi(e,t,r=1){let n=e.length,o=1;for(let i=0;i<n;i++){let s=e.charCodeAt(i);if(s<33||s>126)throw new Error(`Invalid prefix (${e})`);o=Pe(o)^s>>5}o=Pe(o);for(let i=0;i<n;i++)o=Pe(o)^e.charCodeAt(i)&31;for(let i of t)o=Pe(o)^i;for(let i=0;i<6;i++)o=Pe(o);return o^=r,qn.encode(Mn([o%Er[30]],30,5,!1))}function $a(e){let t=e==="bech32"?1:734539939,r=rs(5),n=r.decode,o=r.encode,i=Ki(n);function s(l,d,h=90){re("bech32.encode prefix",l),$n(d)&&(d=Array.from(d)),Xi("bech32.encode",d);let x=l.length;if(x===0)throw new TypeError(`Invalid prefix length ${x}`);let y=x+7+d.length;if(h!==!1&&y>h)throw new TypeError(`Length ${y} exceeds limit ${h}`);let B=l.toLowerCase(),I=Zi(B,d,t);return`${B}1${qn.encode(d)}${I}`}function c(l,d=90){re("bech32.decode input",l);let h=l.length;if(h<8||d!==!1&&h>d)throw new TypeError(`invalid string length: ${h} (${l}). Expected (8..${d})`);let x=l.toLowerCase();if(l!==x&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");let y=x.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');let B=x.slice(0,y),I=x.slice(y+1);if(I.length<6)throw new Error("Data must be at least 6 characters long");let L=qn.decode(I).slice(0,-6),N=Zi(B,L,t);if(!I.endsWith(N))throw new Error(`Invalid checksum in ${l}: expected "${N}"`);return{prefix:B,words:L}}let a=Ki(c);function f(l){let{prefix:d,words:h}=c(l,!1);return{prefix:d,words:h,bytes:n(h)}}function u(l,d){return s(l,o(d))}return{encode:s,decode:c,encodeFromBytes:u,decodeToBytes:f,decodeUnsafe:a,fromWords:n,fromWordsUnsafe:i,toWords:o}}var He=$a("bech32");var ns=new TextEncoder,ja=new TextDecoder,os=1,is=65535;function Sr(e){if(!Number.isSafeInteger(e)||e<1)throw new Error("expected positive integer");if(e<=32)return 32;let t=1<<Math.floor(Math.log2(e-1))+1,r=t<=256?32:t/8;return r*(Math.floor((e-1)/r)+1)}function za(e){let t=ns.encode(e),r=t.length;if(r<os||r>is)throw new Error("invalid plaintext length: must be between 1 and 65535 bytes");let n=new Uint8Array(2);new DataView(n.buffer).setUint16(0,r,!1);let o=new Uint8Array(Sr(r)-r);return J(n,t,o)}function Ga(e){let t=new DataView(e.buffer,e.byteOffset).getUint16(0,!1),r=e.subarray(2,2+t);if(t<os||t>is||r.length!==t||e.length!==2+Sr(t))throw new Error("invalid padding");return ja.decode(r)}function De(e,t){let n=Bt.getSharedSecret(e,"02"+t).subarray(1,33);return zi(tt,n,ns.encode("nip44-v2"))}function ss(e,t){let r=Gi(tt,e,t,76);return{chacha_key:r.subarray(0,32),chacha_nonce:r.subarray(32,44),hmac_key:r.subarray(44,76)}}function Ir(e,t,r=rt(32)){let{chacha_key:n,chacha_nonce:o,hmac_key:i}=ss(t,r),s=za(e),c=wr(n,o,s),a=Et(tt,i,J(r,c));return zn.encode(J(new Uint8Array([2]),r,c,a))}function vr(e,t){let r=zn.decode(e),n=r[0];if(n!==2)throw new Error(`unknown encryption version: ${n}`);if(r.length<99||r.length>65603)throw new Error("invalid payload size");let o=r.subarray(1,33),i=r.subarray(33,r.length-32),s=r.subarray(r.length-32),{chacha_key:c,chacha_nonce:a,hmac_key:f}=ss(t,o),u=Et(tt,f,J(o,i));if(!br(s,u))throw new Error("invalid MAC");let l=wr(c,a,i);return Ga(l)}var Ka={utils:{getConversationKey:De,calcPaddedLen:Sr},encrypt:Ir,decrypt:vr};var Kn={};kt(Kn,{connectRequest:()=>of,createBunkerURI:()=>Wa,createRequest:()=>Ut,createResponse:()=>Qa,createResponseFilter:()=>pf,createSession:()=>Ya,getPublicKeyRequest:()=>cf,getRelaysRequest:()=>hf,getSessionInfo:()=>Ja,isRequest:()=>tf,isResponse:()=>ef,nip04DecryptRequest:()=>uf,nip04EncryptRequest:()=>ff,nip44DecryptRequest:()=>df,nip44EncryptRequest:()=>lf,parseBunkerURI:()=>cs,parsePayload:()=>as,pingRequest:()=>sf,restoreSession:()=>Xa,signEventRequest:()=>af,unwrapEvent:()=>nf,validateBunkerURI:()=>Za,wrapEvent:()=>rf});function cs(e){if(!e.startsWith("bunker://"))throw new Error("invalid bunker URI: must start with bunker://");let t=new URL(e.replace("bunker://","https://")),r=t.hostname;if(!/^[0-9a-f]{64}$/.test(r))throw new Error("invalid bunker URI: remote pubkey must be 64 hex characters");let n=t.searchParams.getAll("relay");if(n.length===0)throw new Error("invalid bunker URI: at least one relay is required");let o=t.searchParams.get("secret")||void 0;return{remotePubkey:r,relays:n,secret:o}}function Wa(e,t,r){if(!/^[0-9a-f]{64}$/.test(e))throw new Error("remotePubkey must be 64 hex characters");if(t.length===0)throw new Error("at least one relay is required");let n=t.map(o=>`relay=${encodeURIComponent(o)}`);return r&&n.push(`secret=${encodeURIComponent(r)}`),`bunker://${e}?${n.join("&")}`}function Za(e){try{return{isValid:!0,uri:cs(e)}}catch(t){return{isValid:!1,error:t.message}}}function Ya(e){if(!/^[0-9a-f]{64}$/.test(e))throw new Error("remotePubkey must be 64 hex characters");let t=rt(32),r=Y(t),n=nt.getPublicKey(t),o=Y(n),i=De(t,e);return{clientSecretKey:r,clientPubkey:o,remotePubkey:e,conversationKey:i}}function Xa(e,t){let r=X(e),n=nt.getPublicKey(r),o=Y(n),i=De(r,t);return{clientSecretKey:e,clientPubkey:o,remotePubkey:t,conversationKey:i}}function Ja(e){return{clientPubkey:e.clientPubkey,remotePubkey:e.remotePubkey}}function Ut(e,t,r){return{id:r||Y(rt(16)),method:e,params:t}}function Qa(e,t,r){let n={id:e};return t!==void 0&&(n.result=t),r!==void 0&&(n.error=r),n}function as(e){let t=JSON.parse(e);if(typeof t.id!="string")throw new Error("invalid NIP-46 payload: missing id");return t}function tf(e){return"method"in e&&"params"in e}function ef(e){return"result"in e||"error"in e}async function rf(e,t,r){let n=JSON.stringify(e),o=Ir(n,t.conversationKey),s={kind:24133,created_at:Math.floor(Date.now()/1e3),tags:[["p",r]],content:o,pubkey:t.clientPubkey},c=JSON.stringify([0,s.pubkey,s.created_at,s.kind,s.tags,s.content]),a=tt(new TextEncoder().encode(c)),f=X(t.clientSecretKey),u=nt.sign(a,f);return{...s,id:Y(a),sig:Y(u)}}function nf(e,t){if(e.kind!==24133)throw new Error(`expected kind 24133, got ${e.kind}`);let r=vr(e.content,t.conversationKey);return as(r)}function of(e,t,r){let n=[e];return t?n.push(t):r&&n.push(""),r&&n.push(r),Ut("connect",n)}function sf(){return Ut("ping",[])}function cf(){return Ut("get_public_key",[])}function af(e){return Ut("sign_event",[e])}function ff(e,t){return Ut("nip04_encrypt",[e,t])}function uf(e,t){return Ut("nip04_decrypt",[e,t])}function lf(e,t){return Ut("nip44_encrypt",[e,t])}function df(e,t){return Ut("nip44_decrypt",[e,t])}function hf(){return Ut("get_relays",[])}function pf(e,t){let r={kinds:[24133],"#p":[e]};return t!==void 0&&(r.since=t),r}var Xn={};kt(Xn,{decrypt:()=>Ef,encrypt:()=>wf});function gf(e,t,r,n){_t(e);let o=qe({dkLen:32,asyncTick:10},n),{c:i,dkLen:s,asyncTick:c}=o;if(et(i),et(s),et(c),i<1)throw new Error("iterations (c) should be >= 1");let a=Rr(t),f=Rr(r),u=new Uint8Array(s),l=Et.create(e,a),d=l._cloneInto().update(f);return{c:i,dkLen:s,asyncTick:c,DK:u,PRF:l,PRFSalt:d}}function xf(e,t,r,n,o){return e.destroy(),t.destroy(),n&&n.destroy(),pt(o),r}function Wn(e,t,r,n){let{c:o,dkLen:i,DK:s,PRF:c,PRFSalt:a}=gf(e,t,r,n),f,u=new Uint8Array(4),l=se(u),d=new Uint8Array(c.outputLen);for(let h=1,x=0;x<i;h++,x+=c.outputLen){let y=s.subarray(x,x+c.outputLen);l.setInt32(0,h,!1),(f=a._cloneInto(f)).update(u).digestInto(d),y.set(d.subarray(0,y.length));for(let B=1;B<o;B++){c._cloneInto(f).update(d).digestInto(d);for(let I=0;I<y.length;I++)y[I]^=d[I]}}return xf(c,a,s,f,d)}function fs(e,t,r,n,o,i){let s=e[t++]^r[n++],c=e[t++]^r[n++],a=e[t++]^r[n++],f=e[t++]^r[n++],u=e[t++]^r[n++],l=e[t++]^r[n++],d=e[t++]^r[n++],h=e[t++]^r[n++],x=e[t++]^r[n++],y=e[t++]^r[n++],B=e[t++]^r[n++],I=e[t++]^r[n++],L=e[t++]^r[n++],N=e[t++]^r[n++],D=e[t++]^r[n++],K=e[t++]^r[n++],O=s,q=c,M=a,U=f,H=u,C=l,_=d,m=h,p=x,g=y,E=B,A=I,v=L,w=N,S=D,T=K;for(let k=0;k<8;k+=2)H^=V(O+v|0,7),p^=V(H+O|0,9),v^=V(p+H|0,13),O^=V(v+p|0,18),g^=V(C+q|0,7),w^=V(g+C|0,9),q^=V(w+g|0,13),C^=V(q+w|0,18),S^=V(E+_|0,7),M^=V(S+E|0,9),_^=V(M+S|0,13),E^=V(_+M|0,18),U^=V(T+A|0,7),m^=V(U+T|0,9),A^=V(m+U|0,13),T^=V(A+m|0,18),q^=V(O+U|0,7),M^=V(q+O|0,9),U^=V(M+q|0,13),O^=V(U+M|0,18),_^=V(C+H|0,7),m^=V(_+C|0,9),H^=V(m+_|0,13),C^=V(H+m|0,18),A^=V(E+g|0,7),p^=V(A+E|0,9),g^=V(p+A|0,13),E^=V(g+p|0,18),v^=V(T+S|0,7),w^=V(v+T|0,9),S^=V(w+v|0,13),T^=V(S+w|0,18);o[i++]=s+O|0,o[i++]=c+q|0,o[i++]=a+M|0,o[i++]=f+U|0,o[i++]=u+H|0,o[i++]=l+C|0,o[i++]=d+_|0,o[i++]=h+m|0,o[i++]=x+p|0,o[i++]=y+g|0,o[i++]=B+E|0,o[i++]=I+A|0,o[i++]=L+v|0,o[i++]=N+w|0,o[i++]=D+S|0,o[i++]=K+T|0}function Zn(e,t,r,n,o){let i=n+0,s=n+16*o;for(let c=0;c<16;c++)r[s+c]=e[t+(2*o-1)*16+c];for(let c=0;c<o;c++,i+=16,t+=16)fs(r,s,e,t,r,i),c>0&&(s+=16),fs(r,i,e,t+=16,r,s)}function bf(e,t,r){let n=qe({dkLen:32,asyncTick:10,maxmem:1073742848},r),{N:o,r:i,p:s,dkLen:c,asyncTick:a,maxmem:f,onProgress:u}=n;if(et(o),et(i),et(s),et(c),et(a),et(f),u!==void 0&&typeof u!="function")throw new Error("progressCb should be function");let l=128*i,d=l/4,h=Math.pow(2,32);if(o<=1||(o&o-1)!==0||o>h)throw new Error("Scrypt: N must be larger than 1, a power of 2, and less than 2^32");if(s<0||s>(h-1)*32/l)throw new Error("Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)");if(c<0||c>(h-1)*32)throw new Error("Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32");if(l*(o+s)>f)throw new Error("Scrypt: memused is bigger than maxMem. Expected 128 * r * (N + p) > maxmem of "+f);let y=Wn(Ct,e,t,{c:1,dkLen:l*s}),B=Me(y),I=Me(new Uint8Array(l*o)),L=Me(new Uint8Array(l)),N=()=>{};if(u){let D=2*o*s,K=Math.max(Math.floor(D/1e4),1),O=0;N=()=>{O++,u&&(!(O%K)||O===D)&&u(O/D)}}return{N:o,r:i,p:s,dkLen:c,blockSize32:d,V:I,B32:B,B:y,tmp:L,blockMixCb:N,asyncTick:a}}function mf(e,t,r,n,o){let i=Wn(Ct,e,r,{c:1,dkLen:t});return pt(r,n,o),i}function Yn(e,t,r){let{N:n,r:o,p:i,dkLen:s,blockSize32:c,V:a,B32:f,B:u,tmp:l,blockMixCb:d}=bf(e,t,r);kr(f);for(let h=0;h<i;h++){let x=c*h;for(let y=0;y<c;y++)a[y]=f[x+y];for(let y=0,B=0;y<n-1;y++)Zn(a,B,a,B+=c,o),d();Zn(a,(n-1)*c,f,x,o),d();for(let y=0;y<n;y++){let B=f[x+c-16]%n;for(let I=0;I<c;I++)l[I]=f[x+I]^a[B*c+I];Zn(l,0,f,x,o),d()}}return kr(f),mf(e,s,u,a,l)}function wf(e,t,r=16,n=2){let o=rt(16),i=2**r,s=t.normalize("NFKC"),c=Yn(s,o,{N:i,r:8,p:1,dkLen:32}),a=rt(24),f=Uint8Array.from([n]),l=Dn(c,a,f).encrypt(e),d=J(Uint8Array.from([2]),Uint8Array.from([r]),o,a,f,l),h=He.toWords(d);return He.encode("ncryptsec",h,200)}function Ef(e,t){let{prefix:r,words:n}=He.decode(e,200);if(r!=="ncryptsec")throw new Error("invalid ncryptsec prefix");let o=new Uint8Array(He.fromWords(n)),i=o[0];if(i!==2)throw new Error(`unknown ncryptsec version: ${i}`);let s=o[1],c=o.subarray(2,18),a=o.subarray(18,42),f=o[42],u=o.subarray(43),l=2**s,d=t.normalize("NFKC"),h=Yn(d,c,{N:l,r:8,p:1,dkLen:32}),x=Uint8Array.from([f]);return Dn(h,a,x).decrypt(u)}function us(e){let t=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)t[r/2]=parseInt(e.slice(r,r+2),16);return t}function ls(e){return Array.from(e).map(t=>t.toString(16).padStart(2,"0")).join("")}function ds(e){return new TextEncoder().encode(e)}function hs(e){return new TextDecoder().decode(e)}return Es(Bf);})();
|
|
2
|
+
/*! Bundled license information:
|
|
3
|
+
|
|
4
|
+
ieee754/index.js:
|
|
5
|
+
(*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
6
|
+
|
|
7
|
+
buffer/index.js:
|
|
8
|
+
(*!
|
|
9
|
+
* The buffer module from node.js, for the browser.
|
|
10
|
+
*
|
|
11
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
12
|
+
* @license MIT
|
|
13
|
+
*)
|
|
14
|
+
|
|
15
|
+
@noble/hashes/esm/utils.js:
|
|
16
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
17
|
+
|
|
18
|
+
@noble/curves/esm/utils.js:
|
|
19
|
+
@noble/curves/esm/abstract/modular.js:
|
|
20
|
+
@noble/curves/esm/abstract/curve.js:
|
|
21
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
22
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
23
|
+
@noble/curves/esm/secp256k1.js:
|
|
24
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
25
|
+
|
|
26
|
+
@noble/ciphers/utils.js:
|
|
27
|
+
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
28
|
+
|
|
29
|
+
@scure/base/index.js:
|
|
30
|
+
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
31
|
+
*/
|
|
32
|
+
//# sourceMappingURL=main.nostr-crypto-utils.min.js.map
|