@napplet/conformance-cli 0.4.0 → 0.4.1
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.
|
@@ -1,4 +1,53 @@
|
|
|
1
|
-
(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))t(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&t(o)}).observe(document,{childList:!0,subtree:!0});function s(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function t(r){if(r.ep)return;r.ep=!0;const i=s(r);fetch(r.href,i)}})();var Ce=["shell","relay","identity","storage","inc","theme","keys","media","notify","config","resource","cvm","outbox","upload","intent","ble","webrtc","link","count","lists","serial","fs","common","dm","gamepad"],c={id:"string"},Rt={"gamepad.subscribe":{dir:"out",forbiddenFields:["id"],forbiddenReason:"NAP-GAMEPAD fire-and-forget envelopes do not carry it"},"gamepad.unsubscribe":{dir:"out",forbiddenFields:["id"],forbiddenReason:"NAP-GAMEPAD fire-and-forget envelopes do not carry it"},"gamepad.state":{dir:"in",fields:{available:"boolean",focused:"boolean",pads:"array"}},"shell.ready":{dir:"out"},"shell.init":{dir:"in",fields:{capabilities:"object",services:"array"}},"relay.subscribe":{dir:"out",fields:{...c,subId:"string",filters:"array"}},"relay.close":{dir:"out",fields:{...c,subId:"string"}},"relay.publish":{dir:"out",fields:{...c,event:"object"}},"relay.publishEncrypted":{dir:"out",fields:{...c,event:"object",recipient:"string"}},"relay.query":{dir:"out",fields:{...c,filters:"array"}},"relay.event":{dir:"in"},"relay.eose":{dir:"in"},"relay.closed":{dir:"in"},"relay.publish.result":{dir:"in"},"relay.publishEncrypted.result":{dir:"in"},"relay.query.result":{dir:"in"},"identity.getPublicKey":{dir:"out",fields:{...c}},"identity.getRelays":{dir:"out",fields:{...c}},"identity.getProfile":{dir:"out",fields:{...c}},"identity.getFollows":{dir:"out",fields:{...c}},"identity.getList":{dir:"out",fields:{...c,listType:"string"}},"identity.getZaps":{dir:"out",fields:{...c}},"identity.getMutes":{dir:"out",fields:{...c}},"identity.getBlocked":{dir:"out",fields:{...c}},"identity.getBadges":{dir:"out",fields:{...c}},"identity.changed":{dir:"in"},"identity.getPublicKey.result":{dir:"in"},"identity.getRelays.result":{dir:"in"},"identity.getProfile.result":{dir:"in"},"identity.getFollows.result":{dir:"in"},"identity.getList.result":{dir:"in"},"identity.getZaps.result":{dir:"in"},"identity.getMutes.result":{dir:"in"},"identity.getBlocked.result":{dir:"in"},"identity.getBadges.result":{dir:"in"},"storage.get":{dir:"out",fields:{...c,key:"string"}},"storage.set":{dir:"out",fields:{...c,key:"string",value:"string"}},"storage.remove":{dir:"out",fields:{...c,key:"string"}},"storage.keys":{dir:"out",fields:{...c}},"storage.get.result":{dir:"in"},"storage.set.result":{dir:"in"},"storage.remove.result":{dir:"in"},"storage.keys.result":{dir:"in"},"inc.emit":{dir:"out",fields:{topic:"string"},forbiddenFields:["sender"]},"inc.subscribe":{dir:"out",fields:{...c,topic:"string"}},"inc.unsubscribe":{dir:"out",fields:{topic:"string"}},"inc.channel.open":{dir:"out",fields:{...c,target:"string"}},"inc.channel.emit":{dir:"out",fields:{channelId:"string"}},"inc.channel.broadcast":{dir:"out"},"inc.channel.list":{dir:"out",fields:{...c}},"inc.channel.close":{dir:"out",fields:{channelId:"string"}},"inc.subscribe.result":{dir:"in"},"inc.event":{dir:"in",fields:{topic:"string",sender:"string"}},"inc.channel.open.result":{dir:"in"},"inc.channel.opened":{dir:"in",fields:{channelId:"string",peer:"string"}},"inc.channel.event":{dir:"in"},"inc.channel.list.result":{dir:"in"},"inc.channel.closed":{dir:"in"},"theme.get":{dir:"out",fields:{...c}},"theme.get.result":{dir:"in"},"theme.changed":{dir:"in"},"keys.forward":{dir:"out",fields:{key:"string",code:"string",ctrl:"boolean",alt:"boolean",shift:"boolean",meta:"boolean"}},"keys.registerAction":{dir:"out",fields:{...c,action:"object"}},"keys.unregisterAction":{dir:"out",fields:{actionId:"string"}},"keys.registerAction.result":{dir:"in"},"keys.bindings":{dir:"in"},"keys.action":{dir:"in"},"media.session.create":{dir:"out",fields:{...c,owner:"object"}},"media.session.update":{dir:"out",fields:{sessionId:"string",metadata:"object"}},"media.session.destroy":{dir:"out",fields:{sessionId:"string"}},"media.state":{dir:"out",fields:{sessionId:"string",status:"string"}},"media.capabilities":{dir:"out",fields:{sessionId:"string",actions:"array"}},"media.session.create.result":{dir:"in"},"media.command":{dir:"in"},"media.controls":{dir:"in"},"notify.send":{dir:"out",fields:{...c,title:"string"}},"notify.dismiss":{dir:"out",fields:{notificationId:"string"}},"notify.badge":{dir:"out",fields:{count:"number"}},"notify.channel.register":{dir:"out",fields:{channelId:"string",label:"string"}},"notify.permission.request":{dir:"out",fields:{...c}},"notify.send.result":{dir:"in"},"notify.permission.result":{dir:"in"},"notify.action":{dir:"in"},"notify.clicked":{dir:"in"},"notify.dismissed":{dir:"in"},"notify.controls":{dir:"in"},"config.registerSchema":{dir:"out",fields:{...c,schema:"object"}},"config.get":{dir:"out",fields:{...c}},"config.subscribe":{dir:"out"},"config.unsubscribe":{dir:"out"},"config.openSettings":{dir:"out"},"config.registerSchema.result":{dir:"in"},"config.values":{dir:"in"},"config.schemaError":{dir:"in"},"resource.info":{dir:"out",fields:{...c}},"resource.bytes":{dir:"out",fields:{...c,url:"string"}},"resource.bytesMany":{dir:"out",fields:{...c,requests:"array"}},"resource.cancel":{dir:"out",fields:{...c}},"resource.info.result":{dir:"in"},"resource.info.error":{dir:"in"},"resource.bytes.result":{dir:"in"},"resource.bytes.error":{dir:"in"},"resource.bytesMany.result":{dir:"in"},"resource.bytesMany.error":{dir:"in"},"cvm.discover":{dir:"out",fields:{...c}},"cvm.request":{dir:"out",fields:{...c,server:"object",message:"object"}},"cvm.close":{dir:"out",fields:{...c,server:"object"}},"cvm.registry.list":{dir:"out",fields:{...c}},"cvm.registry.has":{dir:"out",fields:{...c,family:"string"}},"cvm.registry.describe":{dir:"out",fields:{...c,family:"string"}},"cvm.registry.call":{dir:"out",fields:{...c,family:"string",tool:"string"}},"cvm.discover.result":{dir:"in"},"cvm.request.result":{dir:"in"},"cvm.close.result":{dir:"in"},"cvm.event":{dir:"in"},"cvm.registry.list.result":{dir:"in"},"cvm.registry.has.result":{dir:"in"},"cvm.registry.describe.result":{dir:"in"},"cvm.registry.call.result":{dir:"in"},"outbox.getEvent":{dir:"out",fields:{...c,eventId:"string"}},"outbox.query":{dir:"out",fields:{...c,filters:"present"}},"outbox.subscribe":{dir:"out",fields:{...c,subId:"string",filters:"present"}},"outbox.close":{dir:"out",fields:{...c,subId:"string"}},"outbox.publish":{dir:"out",fields:{...c,event:"object"}},"outbox.resolveRelays":{dir:"out",fields:{...c,target:"present"}},"outbox.getEvent.result":{dir:"in"},"outbox.query.result":{dir:"in"},"outbox.event":{dir:"in"},"outbox.closed":{dir:"in"},"outbox.publish.result":{dir:"in"},"outbox.resolveRelays.result":{dir:"in"},"upload.info":{dir:"out",fields:{...c}},"upload.upload":{dir:"out",fields:{...c,request:"object"}},"upload.status":{dir:"out",fields:{...c,uploadId:"string"}},"upload.info.result":{dir:"in"},"upload.upload.result":{dir:"in"},"upload.status.result":{dir:"in"},"upload.status.changed":{dir:"in"},"intent.invoke":{dir:"out",fields:{...c,request:"object"}},"intent.available":{dir:"out",fields:{...c,archetype:"string"}},"intent.handlers":{dir:"out",fields:{...c}},"intent.invoke.result":{dir:"in",fields:{...c,result:"object"}},"intent.available.result":{dir:"in"},"intent.handlers.result":{dir:"in"},"intent.deliver":{dir:"in",fields:{delivery:"object"}},"intent.changed":{dir:"in"},"ble.open":{dir:"out",fields:{...c,request:"object"}},"ble.services":{dir:"out",fields:{...c,sessionId:"string"}},"ble.read":{dir:"out",fields:{...c,sessionId:"string",target:"object"}},"ble.write":{dir:"out",fields:{...c,sessionId:"string",target:"object",data:"array"}},"ble.subscribe":{dir:"out",fields:{...c,sessionId:"string",target:"object"}},"ble.unsubscribe":{dir:"out",fields:{...c,sessionId:"string",target:"object"}},"ble.close":{dir:"out",fields:{...c,sessionId:"string"}},"ble.open.result":{dir:"in"},"ble.services.result":{dir:"in"},"ble.read.result":{dir:"in"},"ble.write.result":{dir:"in"},"ble.subscribe.result":{dir:"in"},"ble.unsubscribe.result":{dir:"in"},"ble.close.result":{dir:"in"},"ble.event":{dir:"in"},"common.encodeNip19":{dir:"out",fields:{...c,input:"object"}},"common.decodeNip19":{dir:"out",fields:{...c,value:"string"}},"common.getProfile":{dir:"out",fields:{...c,target:"string"}},"common.follows":{dir:"out",fields:{...c}},"common.follow":{dir:"out",fields:{...c,pubkeys:"array"}},"common.unfollow":{dir:"out",fields:{...c,pubkeys:"array"}},"common.react":{dir:"out",fields:{...c,targetEventId:"string",reaction:"string"}},"common.report":{dir:"out",fields:{...c,target:"object",reason:"string",text:"string"}},"common.encodeNip19.result":{dir:"in"},"common.decodeNip19.result":{dir:"in"},"common.getProfile.result":{dir:"in"},"common.follows.result":{dir:"in"},"common.follow.result":{dir:"in"},"common.unfollow.result":{dir:"in"},"common.react.result":{dir:"in"},"common.report.result":{dir:"in"},"webrtc.open":{dir:"out",fields:{...c,request:"object"}},"webrtc.send":{dir:"out",fields:{...c,sessionId:"string",payload:"present"}},"webrtc.close":{dir:"out",fields:{...c,sessionId:"string"}},"webrtc.open.result":{dir:"in"},"webrtc.send.result":{dir:"in"},"webrtc.close.result":{dir:"in"},"webrtc.event":{dir:"in"},"link.open":{dir:"out",fields:{...c,url:"string"}},"link.open.result":{dir:"in"},"count.query":{dir:"out",fields:{...c,filters:"array"}},"count.query.result":{dir:"in"},"lists.supported":{dir:"out",fields:{...c}},"lists.add":{dir:"out",fields:{...c,list:"object",items:"array"}},"lists.remove":{dir:"out",fields:{...c,list:"object",items:"array"}},"lists.supported.result":{dir:"in"},"lists.add.result":{dir:"in"},"lists.remove.result":{dir:"in"},"serial.open":{dir:"out",fields:{...c,request:"object"}},"serial.write":{dir:"out",fields:{...c,sessionId:"string",data:"array"}},"serial.close":{dir:"out",fields:{...c,sessionId:"string"}},"serial.open.result":{dir:"in"},"serial.write.result":{dir:"in"},"serial.close.result":{dir:"in"},"serial.event":{dir:"in"},"fs.info":{dir:"out",fields:{...c}},"fs.pickFile":{dir:"out",fields:{...c}},"fs.pickFiles":{dir:"out",fields:{...c}},"fs.pickDirectory":{dir:"out",fields:{...c}},"fs.pickSaveFile":{dir:"out",fields:{...c}},"fs.stat":{dir:"out",fields:{...c,path:"string"}},"fs.list":{dir:"out",fields:{...c,path:"string"}},"fs.read":{dir:"out",fields:{...c,path:"string"}},"fs.write":{dir:"out",fields:{...c,path:"string",data:"string"}},"fs.mkdir":{dir:"out",fields:{...c,path:"string"}},"fs.remove":{dir:"out",fields:{...c,path:"string"}},"fs.move":{dir:"out",fields:{...c,fromPath:"string",toPath:"string"}},"fs.watch":{dir:"out",fields:{...c,path:"string"}},"fs.unwatch":{dir:"out",fields:{...c,watchId:"string"}},"fs.info.result":{dir:"in"},"fs.pickFile.result":{dir:"in"},"fs.pickFiles.result":{dir:"in"},"fs.pickDirectory.result":{dir:"in"},"fs.pickSaveFile.result":{dir:"in"},"fs.stat.result":{dir:"in"},"fs.list.result":{dir:"in"},"fs.read.result":{dir:"in"},"fs.write.result":{dir:"in"},"fs.mkdir.result":{dir:"in"},"fs.remove.result":{dir:"in"},"fs.move.result":{dir:"in"},"fs.watch.result":{dir:"in"},"fs.unwatch.result":{dir:"in"},"fs.changed":{dir:"in"},"dm.status":{dir:"out",fields:{...c}},"dm.conversations":{dir:"out",fields:{...c}},"dm.messages":{dir:"out",fields:{...c,conversationId:"string"}},"dm.send":{dir:"out",fields:{...c,recipients:"array",content:"string"}},"dm.subscribe":{dir:"out",fields:{...c}},"dm.unsubscribe":{dir:"out",fields:{...c,subscriptionId:"string"}},"dm.status.result":{dir:"in"},"dm.conversations.result":{dir:"in"},"dm.messages.result":{dir:"in"},"dm.send.result":{dir:"in"},"dm.subscribe.result":{dir:"in"},"dm.unsubscribe.result":{dir:"in"},"dm.message":{dir:"in"}};function He(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return"array";const n=typeof e;return n==="string"||n==="number"||n==="boolean"?n:n==="object"?"object":"present"}function It(e,n){return n==="present"?e!=null:He(e)===n}function kt(e,n){if(typeof e!="object"||e===null||Array.isArray(e))return;const s=e;typeof s.archetype!="string"&&n.push({code:s.archetype===void 0?"missing-field":"wrong-type",message:'Intent request requires a string "archetype" field',field:"request.archetype"});for(const r of["action","convention"])typeof s[r]!="string"&&n.push({code:s[r]===void 0?"missing-field":"wrong-type",message:`Intent request field "${r}" must be a string`,field:`request.${r}`});const t=typeof s.convention=="string"?/^napplet:([^/?#]+)\/([^/?#]+)$/.exec(s.convention):null;(!t||t[1]!==s.archetype||t[2]!==s.action)&&n.push({code:"wrong-type",message:"Intent convention must be stable and match archetype and action",field:"request.convention"}),s.handler!==void 0&&typeof s.handler!="string"&&n.push({code:"wrong-type",message:'Intent request field "handler" must be a string',field:"request.handler"}),s.behavior!==void 0&&He(s.behavior)!=="object"&&n.push({code:"wrong-type",message:'Intent request field "behavior" must be an object',field:"request.behavior"}),s.handlerHint!==void 0&&xt(s.handlerHint,n),"sender"in s&&n.push({code:"forbidden-field",message:"Intent request does not define a caller-supplied sender field",field:"request.sender"})}function xt(e,n){if(He(e)!=="object"){n.push({code:"wrong-type",message:'Intent request field "handlerHint" must be an object',field:"request.handlerHint"});return}const{address:s,relays:t}=e;(typeof s!="string"||!/^35129:[0-9a-f]{64}:.+$/s.test(s))&&n.push({code:s===void 0?"missing-field":"wrong-type",message:'Intent handler hint "address" must be a 35129:<pubkey>:<d> coordinate',field:"request.handlerHint.address"}),t!==void 0&&!(Array.isArray(t)&&t.every(r=>typeof r=="string"))&&n.push({code:"wrong-type",message:'Intent handler hint "relays" must be an array of strings',field:"request.handlerHint.relays"})}function Dn(e,n,s){Array.isArray(e)&&e.every(t=>typeof t=="string")||s.push({code:"wrong-type",message:`Field "${n}" must be an array of strings`,field:n})}function Ut(e,n){e.servers!==void 0&&Dn(e.servers,"servers",n)}function Mt(e,n){if(Array.isArray(e)){if(e.length===0){n.push({code:"invalid-resource-request",message:'Field "requests" must contain at least one resource request',field:"requests"});return}for(const[s,t]of e.entries()){const r=`requests[${s}]`;if(typeof t!="object"||t===null||Array.isArray(t)){n.push({code:"invalid-resource-request",message:`Field "${r}" must be a resource request object`,field:r});continue}const i=t;typeof i.url!="string"&&n.push({code:i.url===void 0?"missing-field":"wrong-type",message:`Field "${r}.url" must be a string`,field:`${r}.url`}),i.servers!==void 0&&Dn(i.servers,`${r}.servers`,n)}}}function Pt(e){const n=[];if(typeof e!="object"||e===null||Array.isArray(e))return{ok:!1,errors:[{code:"not-an-object",message:"Envelope must be a non-null object"}]};const s=e,t=s.type;if(typeof t!="string")return{ok:!1,errors:[{code:"missing-type",message:"Envelope is missing a string `type` field"}]};const r=t.indexOf(".");if(r<=0)return{ok:!1,type:t,errors:[{code:"malformed-type",message:`Envelope type "${t}" is not in domain.action form`}]};const i=t.slice(0,r);if(!Ce.includes(i))return{ok:!1,type:t,domain:i,errors:[{code:"unknown-domain",message:`"${i}" is not a known NAP domain`}]};const l=Rt[t];if(!l)return{ok:!1,type:t,domain:i,errors:[{code:"unknown-type",message:`"${t}" is not a known ${i} message type`}]};for(const[a,d]of Object.entries(l.fields??{})){if(!(a in s)||s[a]===void 0){n.push({code:"missing-field",message:`Required field "${a}" is missing`,field:a});continue}It(s[a],d)||n.push({code:"wrong-type",message:`Field "${a}" should be ${d} but is ${He(s[a])}`,field:a})}if(l.dir==="in")return{ok:!1,type:t,domain:i,direction:"in",errors:[{code:"inbound-type-emitted",message:`"${t}" is a shell→napplet message; a napplet must not emit it`},...n]};for(const a of l.forbiddenFields??[])a in s&&n.push({code:"forbidden-field",message:`Field "${a}" cannot be emitted by a napplet: ${l.forbiddenReason??"it must be runtime-derived"}`,field:a});return t==="intent.invoke"&&kt(s.request,n),t==="resource.bytes"&&Ut(s,n),t==="resource.bytesMany"&&Mt(s.requests,n),{ok:n.length===0,type:t,domain:i,direction:"out",errors:n}}var Nn=5129,At=15129,ce=35129,dn=[Nn,At,ce];function $n(e,n){return e.tags.find(s=>s[0]===n)}function jt(e){return dn.includes(e)}function Ln(e){return typeof e=="string"&&/^[0-9a-f]{64}$/.test(e)}function Fn(e){return $n(e,"d")?.[1]||void 0}function Ot(e){return e.tags.filter(n=>n[0]==="R").map(n=>n[1]?.trim()??"").filter(Boolean)}function Gn(e){return Fn(e)??$n(e,"title")?.[1]??e.id}function Be(e){const n=[],s=[];if(!e)return{ok:!1,requires:[],optional:[],errors:[{code:"missing-manifest-event",message:"No NIP-5D manifest event was resolved"}],warnings:s};const t=Fn(e),r=Ot(e);jt(e.kind)||n.push({code:"invalid-napplet-kind",message:`Manifest event kind ${e.kind} is not a NIP-5D napplet kind`});const i=e.tags.filter(l=>l[0]==="d");e.kind===ce&&(i.length!==1||!t)?n.push({code:"missing-d-tag",message:"Named manifests require exactly one non-empty d tag"}):e.kind!==ce&&i.length>0&&n.push({code:"unexpected-d-tag",message:"Only named manifests carry a d tag"});const o=e.tags.filter(l=>l[0]==="x");return(o.length!==1||o[0].length!==2||!Ln(o[0][1]))&&n.push({code:"invalid-artifact-hash",message:"Manifest requires exactly one x tag with the lowercase sha256 of /index.html"}),(typeof e.content!="string"||!e.content.trim())&&n.push({code:"missing-description",message:"Manifest content must contain a non-empty plain-text description"}),qt(e,n,s),Ct(e,n,s),{ok:n.length===0,kind:e.kind,dTag:t,requires:r,optional:e.tags.filter(l=>l[0]==="O").map(l=>l[1]).filter(Boolean),errors:n,warnings:s}}function qt(e,n,s){for(const t of e.tags.filter(r=>r[0]==="R"||r[0]==="O")){const r=t[1];t.length!==2||!r||/[.:\s]/.test(r)||r.startsWith("NAP-")?n.push({code:t[0]==="R"?"invalid-required-nap":"invalid-optional-nap",message:`${t[0]} must name one bare NAP domain`}):Ce.includes(r)||s.push({code:"unknown-required-nap",message:`Domain "${r}" is not in this tool's registry; check its NAP and runtime availability`})}}function Ct(e,n,s){for(const r of["title","source","a","A"]){const i=e.tags.filter(o=>o[0]===r);(i.length>1||i.length&&(r==="a"||r==="A")&&e.kind!==Nn)&&n.push({code:"invalid-metadata",message:`Invalid ${r} tag cardinality for kind ${e.kind}`})}for(const r of e.tags.filter(i=>i[0]==="source"))(r.length!==2||!Ht(r[1]))&&n.push({code:"invalid-metadata",message:"source must contain one HTTP(S), SSH, Git, or SCP repository location"});for(const r of e.tags.filter(i=>i[0]==="i"))(!r[1]?.trim()||r[1].includes("?"))&&n.push({code:"invalid-metadata",message:"Intent advertisements must be non-empty queryless identities"});const t=e.tags.filter(r=>r[0]==="icon");(t.length>1||t.some(r=>r.length!==3||!Ln(r[1])||!["image/png","image/jpeg","image/webp"].includes(r[2])))&&s.push({code:"invalid-icon",message:"Ignore invalid icon metadata and use generic artwork (NIP-5D §Icon)"})}function Ht(e){if(!e||/^[a-z]:[\\/]/i.test(e))return!1;try{const{protocol:n}=new URL(e);if(["http:","https:","ssh:","git:"].includes(n))return!0;if(n==="file:")return!1}catch{}return!e.includes("://")&&/^(?:[^@\s/:]+@)?[^:\s/]+:[^\s]+$/.test(e)}var de="f".repeat(64),Bt={id:"reference-source-endpoint",catalogId:"reference-source"},Dt="https://reference.invalid/blob",Nt=`named:${de}:reference-handler`,$t={kind:35129,pubkey:de,id:"0".repeat(64),tags:[["d","reference-handler"],["z","note"],["i","napplet:note/open","event"]]},Lt="reference-subscriber",Ft="napplet:note/open";function _e(e,n,s){return p({type:e,id:n,result:{entries:[s]}})}var p=e=>[e],A=()=>[];function vn(e){if(typeof e!="string"||!e.startsWith("data:"))return null;const n=e.indexOf(",");if(n<0)return{blob:new Blob([],{type:"text/plain"}),mime:"text/plain"};const s=e.slice(5,n),t=e.slice(n+1),r=s.split(";").filter(Boolean),i=r.includes("base64"),o=r.find(l=>l.includes("/"))??"text/plain";try{if(i){const l=globalThis.atob(t),a=Uint8Array.from(l,d=>d.charCodeAt(0));return{blob:new Blob([a],{type:o}),mime:o}}return{blob:new Blob([decodeURIComponent(t)],{type:o}),mime:o}}catch{return null}}var Gt={"gamepad.subscribe":()=>p({type:"gamepad.state",available:!1,reason:"unavailable",focused:!1,pads:[]}),"gamepad.unsubscribe":A,"relay.subscribe":e=>p({type:"relay.eose",subId:e.subId}),"relay.close":A,"relay.publish":e=>p({type:"relay.publish.result",id:e.id,ok:!0,event:e.event}),"relay.publishEncrypted":e=>p({type:"relay.publishEncrypted.result",id:e.id,ok:!0,event:e.event}),"relay.query":e=>p({type:"relay.query.result",id:e.id,events:[]}),"identity.getPublicKey":e=>p({type:"identity.getPublicKey.result",id:e.id,pubkey:de}),"identity.getRelays":e=>p({type:"identity.getRelays.result",id:e.id,relays:{}}),"identity.getProfile":e=>p({type:"identity.getProfile.result",id:e.id,profile:null}),"identity.getFollows":e=>p({type:"identity.getFollows.result",id:e.id,pubkeys:[]}),"identity.getList":e=>p({type:"identity.getList.result",id:e.id,entries:[]}),"identity.getZaps":e=>p({type:"identity.getZaps.result",id:e.id,zaps:[]}),"identity.getMutes":e=>p({type:"identity.getMutes.result",id:e.id,pubkeys:[]}),"identity.getBlocked":e=>p({type:"identity.getBlocked.result",id:e.id,pubkeys:[]}),"identity.getBadges":e=>p({type:"identity.getBadges.result",id:e.id,badges:[]}),"storage.get":e=>p({type:"storage.get.result",id:e.id,value:null}),"storage.set":e=>p({type:"storage.set.result",id:e.id}),"storage.remove":e=>p({type:"storage.remove.result",id:e.id}),"storage.keys":e=>p({type:"storage.keys.result",id:e.id,keys:[]}),"inc.emit":A,"inc.subscribe":e=>p({type:"inc.subscribe.result",id:e.id}),"inc.unsubscribe":A,"inc.channel.open":e=>p({type:"inc.channel.open.result",id:e.id,channelId:`chan-${String(e.id)}`,peer:"reference-peer"}),"inc.channel.emit":A,"inc.channel.broadcast":A,"inc.channel.list":e=>p({type:"inc.channel.list.result",id:e.id,channels:[]}),"inc.channel.close":A,"theme.get":e=>p({type:"theme.get.result",id:e.id,theme:{colors:{background:"#000000",text:"#ffffff",primary:"#663399"}}}),"keys.forward":A,"keys.registerAction":e=>p({type:"keys.registerAction.result",id:e.id,actionId:`action-${String(e.id)}`}),"keys.unregisterAction":A,"media.session.create":e=>p({type:"media.session.create.result",id:e.id,sessionId:`session-${String(e.id)}`,owner:e.owner}),"media.session.update":A,"media.session.destroy":A,"media.state":A,"media.capabilities":A,"notify.send":e=>p({type:"notify.send.result",id:e.id,notificationId:`notif-${String(e.id)}`}),"notify.dismiss":A,"notify.badge":A,"notify.channel.register":A,"notify.permission.request":e=>p({type:"notify.permission.result",id:e.id,granted:!0}),"config.registerSchema":e=>p({type:"config.registerSchema.result",id:e.id,ok:!0}),"config.get":e=>p({type:"config.values",id:e.id,values:{}}),"config.subscribe":()=>p({type:"config.values",values:{}}),"config.unsubscribe":A,"config.openSettings":A,"resource.bytes":e=>{const n=vn(e.url);return p(n?{type:"resource.bytes.result",id:e.id,blob:n.blob,mime:n.mime}:{type:"resource.bytes.result",id:e.id,blob:new Blob([]),mime:"application/octet-stream"})},"resource.bytesMany":e=>p({type:"resource.bytesMany.result",id:e.id,items:Array.isArray(e.requests)?e.requests.map(n=>{const s=typeof n=="object"&&n!==null&&!Array.isArray(n)?n.url:void 0,t=vn(s);return{url:typeof s=="string"?s:"",ok:!0,blob:t?.blob??new Blob([]),mime:t?.mime??"application/octet-stream"}}):[]}),"resource.info":e=>p({type:"resource.info.result",id:e.id,info:{schemes:[{scheme:"data",enabled:!0},{scheme:"https",enabled:!0}],maxServers:8}}),"resource.cancel":A,"cvm.discover":e=>p({type:"cvm.discover.result",id:e.id,servers:[]}),"cvm.request":e=>p({type:"cvm.request.result",id:e.id,message:{}}),"cvm.close":e=>p({type:"cvm.close.result",id:e.id}),"outbox.getEvent":e=>p({type:"outbox.getEvent.result",id:e.id}),"outbox.query":e=>p({type:"outbox.query.result",id:e.id,events:[]}),"outbox.subscribe":e=>p({type:"outbox.closed",subId:e.subId,reason:"reference shell complete"}),"outbox.close":A,"outbox.publish":e=>p({type:"outbox.publish.result",id:e.id,ok:!0}),"outbox.resolveRelays":e=>p({type:"outbox.resolveRelays.result",id:e.id,plan:{}}),"upload.info":e=>p({type:"upload.info.result",id:e.id,info:{rails:[{rail:"nip96",enabled:!0,returns:["https"]},{rail:"blossom",enabled:!0,returns:["https","blossom"]}]}}),"upload.upload":e=>p({type:"upload.upload.result",id:e.id,result:{url:Dt}}),"upload.status":e=>p({type:"upload.status.result",id:e.id,status:{}}),"ble.open":e=>p({type:"ble.open.result",id:e.id,session:{id:"ble-reference",state:"open",device:{id:"reference-device",name:"Reference BLE"}}}),"ble.services":e=>p({type:"ble.services.result",id:e.id,services:[]}),"ble.read":e=>p({type:"ble.read.result",id:e.id,data:[]}),"ble.write":e=>p({type:"ble.write.result",id:e.id}),"ble.subscribe":e=>p({type:"ble.subscribe.result",id:e.id}),"ble.unsubscribe":e=>p({type:"ble.unsubscribe.result",id:e.id}),"ble.close":e=>p({type:"ble.close.result",id:e.id}),"common.encodeNip19":e=>p({type:"common.encodeNip19.result",id:e.id,ok:!0,value:"npub1reference",nip19Type:"npub"}),"common.decodeNip19":e=>p({type:"common.decodeNip19.result",id:e.id,ok:!0,nip19Type:"npub",hex:de}),"common.getProfile":e=>p({type:"common.getProfile.result",id:e.id,ok:!0,pubkey:de,profile:null}),"common.follows":e=>p({type:"common.follows.result",id:e.id,ok:!0,pubkeys:[]}),"common.follow":e=>p({type:"common.follow.result",id:e.id,ok:!0}),"common.unfollow":e=>p({type:"common.unfollow.result",id:e.id,ok:!0}),"common.react":e=>p({type:"common.react.result",id:e.id,ok:!0,eventId:"0".repeat(64)}),"common.report":e=>p({type:"common.report.result",id:e.id,ok:!0,eventId:"1".repeat(64)}),"webrtc.open":e=>p({type:"webrtc.open.result",id:e.id,session:{id:"webrtc-reference",scope:{type:"direct",pubkey:de},channel:"default",state:"connecting"}}),"webrtc.send":e=>p({type:"webrtc.send.result",id:e.id}),"webrtc.close":e=>p({type:"webrtc.close.result",id:e.id}),"link.open":e=>p({type:"link.open.result",id:e.id,status:"opened"}),"count.query":e=>p({type:"count.query.result",id:e.id,ok:!0,count:0}),"lists.supported":e=>p({type:"lists.supported.result",id:e.id,lists:[]}),"lists.add":e=>p({type:"lists.add.result",id:e.id,ok:!0,added:0,skipped:0}),"lists.remove":e=>p({type:"lists.remove.result",id:e.id,ok:!0,removed:0,skipped:0}),"serial.open":e=>p({type:"serial.open.result",id:e.id,session:{id:`serial-${String(e.id)}`,state:"open"}}),"serial.write":e=>p({type:"serial.write.result",id:e.id}),"serial.close":e=>p({type:"serial.close.result",id:e.id}),"fs.info":e=>p({type:"fs.info.result",id:e.id,info:{roots:[{path:"/shared",name:"Shared files",permissions:["read","list","write","create","delete","watch"]}],limits:{maxReadBytes:1048576,maxWriteBytes:1048576,maxWatchCount:16}}}),"fs.pickFile":e=>_e("fs.pickFile.result",e.id,{path:"/picked/file.txt",kind:"file",name:"file.txt",permissions:["read"]}),"fs.pickFiles":e=>_e("fs.pickFiles.result",e.id,{path:"/picked/file.txt",kind:"file",name:"file.txt",permissions:["read"]}),"fs.pickDirectory":e=>_e("fs.pickDirectory.result",e.id,{path:"/picked",kind:"directory",name:"picked",permissions:["read","list"]}),"fs.pickSaveFile":e=>_e("fs.pickSaveFile.result",e.id,{path:"/picked/export.json",kind:"file",name:"export.json",permissions:["write","create"]}),"fs.stat":e=>p({type:"fs.stat.result",id:e.id,metadata:{path:e.path,kind:"file",size:0}}),"fs.list":e=>p({type:"fs.list.result",id:e.id,entries:[]}),"fs.read":e=>p({type:"fs.read.result",id:e.id,result:{data:"",offset:0,bytesRead:0,eof:!0,size:0}}),"fs.write":e=>p({type:"fs.write.result",id:e.id,result:{bytesWritten:0,size:0}}),"fs.mkdir":e=>p({type:"fs.mkdir.result",id:e.id}),"fs.remove":e=>p({type:"fs.remove.result",id:e.id}),"fs.move":e=>p({type:"fs.move.result",id:e.id}),"fs.watch":e=>p({type:"fs.watch.result",id:e.id,watchId:`watch-${String(e.id)}`}),"fs.unwatch":e=>p({type:"fs.unwatch.result",id:e.id})};function Wt(e){const n=new Set;return(s,t)=>{const r=Vt(t),i=Pt(t);if(e.records.push({envelope:t,verdict:i,timestamp:e.now()}),!r||!i.ok)return[];const o=s.domains??Ce;if(!o.includes(r.slice(0,r.indexOf("."))))return[];if(r==="shell.ready")return n.has(s.id)?[]:(n.add(s.id),p({type:"shell.init",capabilities:{domains:[...o]},services:[]}));const l=t;if(r==="intent.invoke")return e.intents.handleInvoke(s,l);if(r==="intent.available")return p({type:"intent.available.result",id:l.id,availability:e.intents.availability(l.archetype)});if(r==="intent.handlers")return p({type:"intent.handlers.result",id:l.id,handlers:e.intents.handlers()});if(r==="inc.emit")return Qt(s,l,e.queueDelivery);const a=Gt[r];return a?a(l):[]}}function Vt(e){if(!e||typeof e!="object")return;const n=e.type;return typeof n=="string"?n:void 0}function Qt(e,n,s){if(n.topic!==Ft)return[];const t={type:"inc.event",topic:n.topic,sender:e.id};return"payload"in n&&(t.payload=n.payload),s(Lt,t),[]}function zt(e){return e.kind===5129?`snapshot:${e.id}`:e.kind===15129?`root:${e.pubkey}`:`named:${e.pubkey}:${e.tags.find(n=>n[0]==="d")?.[1]??""}`}function Kt(e,n){if(!e.tags.some(t=>t[0]==="z"&&t[1]===n))return[];const s=[];for(const t of e.tags)t[0]!=="i"||/^napplet:([^/?#]+)\/([^/?#]+)$/.exec(t[1]??"")?.[1]!==n||s.push({convention:t[1],params:t.slice(2)});return s}function Zt(e,n,s){const t=[];for(const r of e){const i=Kt(r,n);if(!i.length)continue;const o=r.tags.find(a=>a[0]==="title")?.[1],l=zt(r);t.push({id:l,...o?{title:o}:{},actions:[...new Set(i.map(({convention:a})=>a.slice(a.indexOf("/")+1)))],conventions:[...new Set(i.map(({convention:a})=>a))],contracts:i,...l===s?{isDefault:!0}:{}})}return{archetype:n,available:t.length>0,candidates:t,hasDefault:t.some(r=>r.isDefault)}}function Yt(e,n=[$t],s={note:Nt}){const t=r=>Zt(n,String(r),s[String(r)]);return{availability:t,handlers:()=>[...new Set(n.flatMap(r=>r.tags.filter(i=>i[0]==="z").map(i=>i[1])))].map(t),handleInvoke(r,i){const o=i.request,l=t(o.archetype).candidates.filter(g=>g.conventions.includes(o.convention)),a=o.handler&&!["default","choose"].includes(o.handler),d=o.handler==="choose"?void 0:a?l.find(g=>g.id===o.handler):l.find(g=>g.isDefault)??l[0];if(!d)return p({type:"intent.invoke.result",id:i.id,result:{ok:!1,error:"no handler"}});const{archetype:h,action:u,convention:f}=o;return e(d.id,structuredClone({type:"intent.deliver",delivery:{sender:r.catalogId,archetype:h,action:u,convention:f,..."payload"in o?{payload:o.payload}:{}}})),p({type:"intent.invoke.result",id:i.id,result:{ok:!0,archetype:h,action:u,convention:f,handler:d.id}})}}}function Xt(e={}){const n=[],s=Jt(),t=Wt({now:e.now??Date.now,records:n,queueDelivery:s.queue,intents:Yt(s.queue,e.manifests,e.defaults)});return{get records(){return n},handle:r=>t(Bt,r),handleFrom:t,takeDeliveries:s.take,reset(){n.length=0,s.clear()}}}function Jt(){const e=new Map;return{queue(n,s){const t=e.get(n);t?t.push(s):e.set(n,[s])},take(n){const s=e.get(n)??[];return e.delete(n),s},clear(){e.clear()}}}function es(e){return{manifestHtml:e.manifestHtml,manifestEvent:e.manifestEvent??null,sandbox:e.sandbox??{allowScripts:!0,allowSameOrigin:!1},installedGlobal:e.boot.installedGlobal,bootError:e.boot.bootError,emitted:e.boot.emitted,forbiddenGlobals:e.forbiddenGlobals??[],degraded:e.boot.degraded,lifecycle:e.lifecycle??null}}var Wn="__nappletConformance.error",Vn="__nappletConformance.installed";function wn(e){return new Promise(n=>setTimeout(n,e))}function ns(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}var ts=`(() => {
|
|
1
|
+
(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))t(s);new MutationObserver(s=>{for(const i of s)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&t(o)}).observe(document,{childList:!0,subtree:!0});function r(s){const i={};return s.integrity&&(i.integrity=s.integrity),s.referrerPolicy&&(i.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?i.credentials="include":s.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function t(s){if(s.ep)return;s.ep=!0;const i=r(s);fetch(s.href,i)}})();var Le=["shell","relay","identity","storage","inc","theme","keys","media","notify","config","resource","cvm","outbox","upload","intent","ble","webrtc","link","count","lists","serial","fs","common","dm","gamepad","llm"],u={id:"string"},Dt={"llm.select":{dir:"out",fields:{...u}},"llm.select.result":{dir:"in",fields:{...u}},"llm.describe":{dir:"out",fields:{...u,handle:"string"}},"llm.describe.result":{dir:"in",fields:{...u}},"llm.generate":{dir:"out",fields:{...u,request:"object"}},"llm.generate.result":{dir:"in",fields:{...u}},"llm.delta":{dir:"in",fields:{requestId:"string",sequence:"number",text:"string"}},"llm.cancel":{dir:"out",fields:{...u,requestId:"string"}},"llm.cancel.result":{dir:"in",fields:{...u}},"gamepad.subscribe":{dir:"out",forbiddenFields:["id"],forbiddenReason:"NAP-GAMEPAD fire-and-forget envelopes do not carry it"},"gamepad.unsubscribe":{dir:"out",forbiddenFields:["id"],forbiddenReason:"NAP-GAMEPAD fire-and-forget envelopes do not carry it"},"gamepad.state":{dir:"in",fields:{available:"boolean",focused:"boolean",pads:"array"}},"shell.ready":{dir:"out"},"shell.init":{dir:"in",fields:{capabilities:"object",services:"array"}},"relay.subscribe":{dir:"out",fields:{...u,subId:"string",filters:"array"}},"relay.close":{dir:"out",fields:{...u,subId:"string"}},"relay.publish":{dir:"out",fields:{...u,event:"object"}},"relay.publishEncrypted":{dir:"out",fields:{...u,event:"object",recipient:"string"}},"relay.query":{dir:"out",fields:{...u,filters:"array"}},"relay.event":{dir:"in"},"relay.eose":{dir:"in"},"relay.closed":{dir:"in"},"relay.publish.result":{dir:"in"},"relay.publishEncrypted.result":{dir:"in"},"relay.query.result":{dir:"in"},"identity.getPublicKey":{dir:"out",fields:{...u}},"identity.getRelays":{dir:"out",fields:{...u}},"identity.getProfile":{dir:"out",fields:{...u}},"identity.getFollows":{dir:"out",fields:{...u}},"identity.getList":{dir:"out",fields:{...u,listType:"string"}},"identity.getZaps":{dir:"out",fields:{...u}},"identity.getMutes":{dir:"out",fields:{...u}},"identity.getBlocked":{dir:"out",fields:{...u}},"identity.getBadges":{dir:"out",fields:{...u}},"identity.changed":{dir:"in"},"identity.getPublicKey.result":{dir:"in"},"identity.getRelays.result":{dir:"in"},"identity.getProfile.result":{dir:"in"},"identity.getFollows.result":{dir:"in"},"identity.getList.result":{dir:"in"},"identity.getZaps.result":{dir:"in"},"identity.getMutes.result":{dir:"in"},"identity.getBlocked.result":{dir:"in"},"identity.getBadges.result":{dir:"in"},"storage.get":{dir:"out",fields:{...u,key:"string"}},"storage.set":{dir:"out",fields:{...u,key:"string",value:"string"}},"storage.remove":{dir:"out",fields:{...u,key:"string"}},"storage.keys":{dir:"out",fields:{...u}},"storage.get.result":{dir:"in"},"storage.set.result":{dir:"in"},"storage.remove.result":{dir:"in"},"storage.keys.result":{dir:"in"},"inc.emit":{dir:"out",fields:{topic:"string"},forbiddenFields:["sender"]},"inc.subscribe":{dir:"out",fields:{...u,topic:"string"}},"inc.unsubscribe":{dir:"out",fields:{topic:"string"}},"inc.channel.open":{dir:"out",fields:{...u,target:"string"}},"inc.channel.emit":{dir:"out",fields:{channelId:"string"}},"inc.channel.broadcast":{dir:"out"},"inc.channel.list":{dir:"out",fields:{...u}},"inc.channel.close":{dir:"out",fields:{channelId:"string"}},"inc.subscribe.result":{dir:"in"},"inc.event":{dir:"in",fields:{topic:"string",sender:"string"}},"inc.channel.open.result":{dir:"in"},"inc.channel.opened":{dir:"in",fields:{channelId:"string",peer:"string"}},"inc.channel.event":{dir:"in"},"inc.channel.list.result":{dir:"in"},"inc.channel.closed":{dir:"in"},"theme.get":{dir:"out",fields:{...u}},"theme.get.result":{dir:"in"},"theme.changed":{dir:"in"},"keys.forward":{dir:"out",fields:{key:"string",code:"string",ctrl:"boolean",alt:"boolean",shift:"boolean",meta:"boolean"}},"keys.registerAction":{dir:"out",fields:{...u,action:"object"}},"keys.unregisterAction":{dir:"out",fields:{actionId:"string"}},"keys.registerAction.result":{dir:"in"},"keys.bindings":{dir:"in"},"keys.action":{dir:"in"},"media.session.create":{dir:"out",fields:{...u,owner:"object"}},"media.session.update":{dir:"out",fields:{sessionId:"string",metadata:"object"}},"media.session.destroy":{dir:"out",fields:{sessionId:"string"}},"media.state":{dir:"out",fields:{sessionId:"string",status:"string"}},"media.capabilities":{dir:"out",fields:{sessionId:"string",actions:"array"}},"media.session.create.result":{dir:"in"},"media.command":{dir:"in"},"media.controls":{dir:"in"},"notify.send":{dir:"out",fields:{...u,title:"string"}},"notify.dismiss":{dir:"out",fields:{notificationId:"string"}},"notify.badge":{dir:"out",fields:{count:"number"}},"notify.channel.register":{dir:"out",fields:{channelId:"string",label:"string"}},"notify.permission.request":{dir:"out",fields:{...u}},"notify.send.result":{dir:"in"},"notify.permission.result":{dir:"in"},"notify.action":{dir:"in"},"notify.clicked":{dir:"in"},"notify.dismissed":{dir:"in"},"notify.controls":{dir:"in"},"config.registerSchema":{dir:"out",fields:{...u,schema:"object"}},"config.get":{dir:"out",fields:{...u}},"config.subscribe":{dir:"out"},"config.unsubscribe":{dir:"out"},"config.openSettings":{dir:"out"},"config.registerSchema.result":{dir:"in"},"config.values":{dir:"in"},"config.schemaError":{dir:"in"},"resource.info":{dir:"out",fields:{...u}},"resource.bytes":{dir:"out",fields:{...u,url:"string"}},"resource.bytesMany":{dir:"out",fields:{...u,requests:"array"}},"resource.cancel":{dir:"out",fields:{...u}},"resource.info.result":{dir:"in"},"resource.info.error":{dir:"in"},"resource.bytes.result":{dir:"in"},"resource.bytes.error":{dir:"in"},"resource.bytesMany.result":{dir:"in"},"resource.bytesMany.error":{dir:"in"},"cvm.discover":{dir:"out",fields:{...u}},"cvm.request":{dir:"out",fields:{...u,server:"object",message:"object"}},"cvm.close":{dir:"out",fields:{...u,server:"object"}},"cvm.registry.list":{dir:"out",fields:{...u}},"cvm.registry.has":{dir:"out",fields:{...u,family:"string"}},"cvm.registry.describe":{dir:"out",fields:{...u,family:"string"}},"cvm.registry.call":{dir:"out",fields:{...u,family:"string",tool:"string"}},"cvm.discover.result":{dir:"in"},"cvm.request.result":{dir:"in"},"cvm.close.result":{dir:"in"},"cvm.event":{dir:"in"},"cvm.registry.list.result":{dir:"in"},"cvm.registry.has.result":{dir:"in"},"cvm.registry.describe.result":{dir:"in"},"cvm.registry.call.result":{dir:"in"},"outbox.getEvent":{dir:"out",fields:{...u,eventId:"string"}},"outbox.query":{dir:"out",fields:{...u,filters:"present"}},"outbox.subscribe":{dir:"out",fields:{...u,subId:"string",filters:"present"}},"outbox.close":{dir:"out",fields:{...u,subId:"string"}},"outbox.publish":{dir:"out",fields:{...u,event:"object"}},"outbox.resolveRelays":{dir:"out",fields:{...u,target:"present"}},"outbox.getEvent.result":{dir:"in"},"outbox.query.result":{dir:"in"},"outbox.event":{dir:"in"},"outbox.closed":{dir:"in"},"outbox.publish.result":{dir:"in"},"outbox.resolveRelays.result":{dir:"in"},"upload.info":{dir:"out",fields:{...u}},"upload.upload":{dir:"out",fields:{...u,request:"object"}},"upload.status":{dir:"out",fields:{...u,uploadId:"string"}},"upload.info.result":{dir:"in"},"upload.upload.result":{dir:"in"},"upload.status.result":{dir:"in"},"upload.status.changed":{dir:"in"},"intent.invoke":{dir:"out",fields:{...u,request:"object"}},"intent.available":{dir:"out",fields:{...u,archetype:"string"}},"intent.handlers":{dir:"out",fields:{...u}},"intent.invoke.result":{dir:"in",fields:{...u,result:"object"}},"intent.available.result":{dir:"in"},"intent.handlers.result":{dir:"in"},"intent.deliver":{dir:"in",fields:{delivery:"object"}},"intent.changed":{dir:"in"},"ble.open":{dir:"out",fields:{...u,request:"object"}},"ble.services":{dir:"out",fields:{...u,sessionId:"string"}},"ble.read":{dir:"out",fields:{...u,sessionId:"string",target:"object"}},"ble.write":{dir:"out",fields:{...u,sessionId:"string",target:"object",data:"array"}},"ble.subscribe":{dir:"out",fields:{...u,sessionId:"string",target:"object"}},"ble.unsubscribe":{dir:"out",fields:{...u,sessionId:"string",target:"object"}},"ble.close":{dir:"out",fields:{...u,sessionId:"string"}},"ble.open.result":{dir:"in"},"ble.services.result":{dir:"in"},"ble.read.result":{dir:"in"},"ble.write.result":{dir:"in"},"ble.subscribe.result":{dir:"in"},"ble.unsubscribe.result":{dir:"in"},"ble.close.result":{dir:"in"},"ble.event":{dir:"in"},"common.encodeNip19":{dir:"out",fields:{...u,input:"object"}},"common.decodeNip19":{dir:"out",fields:{...u,value:"string"}},"common.getProfile":{dir:"out",fields:{...u,target:"string"}},"common.follows":{dir:"out",fields:{...u}},"common.follow":{dir:"out",fields:{...u,pubkeys:"array"}},"common.unfollow":{dir:"out",fields:{...u,pubkeys:"array"}},"common.react":{dir:"out",fields:{...u,targetEventId:"string",reaction:"string"}},"common.report":{dir:"out",fields:{...u,target:"object",reason:"string",text:"string"}},"common.encodeNip19.result":{dir:"in"},"common.decodeNip19.result":{dir:"in"},"common.getProfile.result":{dir:"in"},"common.follows.result":{dir:"in"},"common.follow.result":{dir:"in"},"common.unfollow.result":{dir:"in"},"common.react.result":{dir:"in"},"common.report.result":{dir:"in"},"webrtc.open":{dir:"out",fields:{...u,request:"object"}},"webrtc.send":{dir:"out",fields:{...u,sessionId:"string",payload:"present"}},"webrtc.close":{dir:"out",fields:{...u,sessionId:"string"}},"webrtc.open.result":{dir:"in"},"webrtc.send.result":{dir:"in"},"webrtc.close.result":{dir:"in"},"webrtc.event":{dir:"in"},"link.open":{dir:"out",fields:{...u,url:"string"}},"link.open.result":{dir:"in"},"count.query":{dir:"out",fields:{...u,filters:"array"}},"count.query.result":{dir:"in"},"lists.supported":{dir:"out",fields:{...u}},"lists.add":{dir:"out",fields:{...u,list:"object",items:"array"}},"lists.remove":{dir:"out",fields:{...u,list:"object",items:"array"}},"lists.supported.result":{dir:"in"},"lists.add.result":{dir:"in"},"lists.remove.result":{dir:"in"},"serial.open":{dir:"out",fields:{...u,request:"object"}},"serial.write":{dir:"out",fields:{...u,sessionId:"string",data:"array"}},"serial.close":{dir:"out",fields:{...u,sessionId:"string"}},"serial.open.result":{dir:"in"},"serial.write.result":{dir:"in"},"serial.close.result":{dir:"in"},"serial.event":{dir:"in"},"fs.info":{dir:"out",fields:{...u}},"fs.pickFile":{dir:"out",fields:{...u}},"fs.pickFiles":{dir:"out",fields:{...u}},"fs.pickDirectory":{dir:"out",fields:{...u}},"fs.pickSaveFile":{dir:"out",fields:{...u}},"fs.stat":{dir:"out",fields:{...u,path:"string"}},"fs.list":{dir:"out",fields:{...u,path:"string"}},"fs.read":{dir:"out",fields:{...u,path:"string"}},"fs.write":{dir:"out",fields:{...u,path:"string",data:"string"}},"fs.mkdir":{dir:"out",fields:{...u,path:"string"}},"fs.remove":{dir:"out",fields:{...u,path:"string"}},"fs.move":{dir:"out",fields:{...u,fromPath:"string",toPath:"string"}},"fs.watch":{dir:"out",fields:{...u,path:"string"}},"fs.unwatch":{dir:"out",fields:{...u,watchId:"string"}},"fs.info.result":{dir:"in"},"fs.pickFile.result":{dir:"in"},"fs.pickFiles.result":{dir:"in"},"fs.pickDirectory.result":{dir:"in"},"fs.pickSaveFile.result":{dir:"in"},"fs.stat.result":{dir:"in"},"fs.list.result":{dir:"in"},"fs.read.result":{dir:"in"},"fs.write.result":{dir:"in"},"fs.mkdir.result":{dir:"in"},"fs.remove.result":{dir:"in"},"fs.move.result":{dir:"in"},"fs.watch.result":{dir:"in"},"fs.unwatch.result":{dir:"in"},"fs.changed":{dir:"in"},"dm.status":{dir:"out",fields:{...u}},"dm.conversations":{dir:"out",fields:{...u}},"dm.messages":{dir:"out",fields:{...u,conversationId:"string"}},"dm.send":{dir:"out",fields:{...u,recipients:"array",content:"string"}},"dm.subscribe":{dir:"out",fields:{...u}},"dm.unsubscribe":{dir:"out",fields:{...u,subscriptionId:"string"}},"dm.status.result":{dir:"in"},"dm.conversations.result":{dir:"in"},"dm.messages.result":{dir:"in"},"dm.send.result":{dir:"in"},"dm.subscribe.result":{dir:"in"},"dm.unsubscribe.result":{dir:"in"},"dm.message":{dir:"in"}},Nt=e=>typeof e=="string",we=e=>typeof e=="string"&&e.length>0,Rn=e=>typeof e=="boolean",Ee=(...e)=>n=>typeof n=="string"&&e.includes(n),Bt=e=>typeof e=="string"&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)&&e.length>=4;function _e(e,n={}){return r=>{if(typeof r!="object"||r===null||Array.isArray(r))return!1;const t=r;return Object.keys(t).some(s=>!(s in e)&&!(s in n))?!1:Object.entries(e).every(([s,i])=>i(t[s]))&&Object.entries(n).every(([s,i])=>t[s]===void 0||i(t[s]))}}var Qn=e=>n=>Array.isArray(n)&&n.length>0&&n.every(e),Lt=_e({type:Ee("text"),text:Nt}),$t=_e({type:Ee("image"),mimeType:Ee("image/png","image/jpeg","image/webp"),data:Bt}),Ft=e=>Lt(e)||$t(e),Gt=_e({role:Ee("system","user","assistant"),content:Qn(Ft)}),Wt=_e({},{model:we,images:Rn,json:Rn}),Vt=_e({handle:we,messages:Qn(Gt)},{format:Ee("text","json")}),zt={"llm.select":{optional:{requirements:Wt}},"llm.describe":{required:{handle:we}},"llm.generate":{required:{request:Vt}},"llm.cancel":{required:{requestId:we}}};function Qt(e,n,r){const t=zt[e];if(!t)return;const s=t.required??{},i=t.optional??{};n.id!==void 0&&!we(n.id)&&r.push({code:"wrong-type",field:"id",message:"NAP-LLM request ids are non-empty text"});for(const o of Object.keys(n))o==="type"||o==="id"||o in s||o in i||r.push({code:"forbidden-field",field:o,message:`Field "${o}" is not a parameter of ${e}; NAP-LLM requests carry exactly their API row parameters`});for(const[o,l]of Object.entries({...s,...i})){const a=n[o];if(a===void 0){o in s&&r.push({code:"missing-field",field:o,message:`Field "${o}" is required by ${e}`});continue}l(a)||r.push({code:"wrong-type",field:o,message:`Field "${o}" must match the NAP-LLM ${e} schema`})}}function $e(e){if(e===void 0)return"undefined";if(e===null)return"null";if(Array.isArray(e))return"array";const n=typeof e;return n==="string"||n==="number"||n==="boolean"?n:n==="object"?"object":"present"}function Kt(e,n){return n==="present"?e!=null:$e(e)===n}function Zt(e,n){if(typeof e!="object"||e===null||Array.isArray(e))return;const r=e;typeof r.archetype!="string"&&n.push({code:r.archetype===void 0?"missing-field":"wrong-type",message:'Intent request requires a string "archetype" field',field:"request.archetype"});for(const s of["action","convention"])typeof r[s]!="string"&&n.push({code:r[s]===void 0?"missing-field":"wrong-type",message:`Intent request field "${s}" must be a string`,field:`request.${s}`});const t=typeof r.convention=="string"?/^napplet:([^/?#]+)\/([^/?#]+)$/.exec(r.convention):null;(!t||t[1]!==r.archetype||t[2]!==r.action)&&n.push({code:"wrong-type",message:"Intent convention must be stable and match archetype and action",field:"request.convention"}),r.handler!==void 0&&typeof r.handler!="string"&&n.push({code:"wrong-type",message:'Intent request field "handler" must be a string',field:"request.handler"}),r.behavior!==void 0&&$e(r.behavior)!=="object"&&n.push({code:"wrong-type",message:'Intent request field "behavior" must be an object',field:"request.behavior"}),r.handlerHint!==void 0&&Yt(r.handlerHint,n),"sender"in r&&n.push({code:"forbidden-field",message:"Intent request does not define a caller-supplied sender field",field:"request.sender"})}function Yt(e,n){if($e(e)!=="object"){n.push({code:"wrong-type",message:'Intent request field "handlerHint" must be an object',field:"request.handlerHint"});return}const{address:r,relays:t}=e;(typeof r!="string"||!/^35129:[0-9a-f]{64}:.+$/s.test(r))&&n.push({code:r===void 0?"missing-field":"wrong-type",message:'Intent handler hint "address" must be a 35129:<pubkey>:<d> coordinate',field:"request.handlerHint.address"}),t!==void 0&&!(Array.isArray(t)&&t.every(s=>typeof s=="string"))&&n.push({code:"wrong-type",message:'Intent handler hint "relays" must be an array of strings',field:"request.handlerHint.relays"})}function Kn(e,n,r){Array.isArray(e)&&e.every(t=>typeof t=="string")||r.push({code:"wrong-type",message:`Field "${n}" must be an array of strings`,field:n})}function Xt(e,n){e.servers!==void 0&&Kn(e.servers,"servers",n)}function Jt(e,n){if(Array.isArray(e)){if(e.length===0){n.push({code:"invalid-resource-request",message:'Field "requests" must contain at least one resource request',field:"requests"});return}for(const[r,t]of e.entries()){const s=`requests[${r}]`;if(typeof t!="object"||t===null||Array.isArray(t)){n.push({code:"invalid-resource-request",message:`Field "${s}" must be a resource request object`,field:s});continue}const i=t;typeof i.url!="string"&&n.push({code:i.url===void 0?"missing-field":"wrong-type",message:`Field "${s}.url" must be a string`,field:`${s}.url`}),i.servers!==void 0&&Kn(i.servers,`${s}.servers`,n)}}}function er(e){const n=[];if(typeof e!="object"||e===null||Array.isArray(e))return{ok:!1,errors:[{code:"not-an-object",message:"Envelope must be a non-null object"}]};const r=e,t=r.type;if(typeof t!="string")return{ok:!1,errors:[{code:"missing-type",message:"Envelope is missing a string `type` field"}]};const s=t.indexOf(".");if(s<=0)return{ok:!1,type:t,errors:[{code:"malformed-type",message:`Envelope type "${t}" is not in domain.action form`}]};const i=t.slice(0,s);if(!Le.includes(i))return{ok:!1,type:t,domain:i,errors:[{code:"unknown-domain",message:`"${i}" is not a known NAP domain`}]};const l=Dt[t];if(!l)return{ok:!1,type:t,domain:i,errors:[{code:"unknown-type",message:`"${t}" is not a known ${i} message type`}]};for(const[a,d]of Object.entries(l.fields??{})){if(!(a in r)||r[a]===void 0){n.push({code:"missing-field",message:`Required field "${a}" is missing`,field:a});continue}Kt(r[a],d)||n.push({code:"wrong-type",message:`Field "${a}" should be ${d} but is ${$e(r[a])}`,field:a})}if(l.dir==="in")return{ok:!1,type:t,domain:i,direction:"in",errors:[{code:"inbound-type-emitted",message:`"${t}" is a shell→napplet message; a napplet must not emit it`},...n]};for(const a of l.forbiddenFields??[])a in r&&n.push({code:"forbidden-field",message:`Field "${a}" cannot be emitted by a napplet: ${l.forbiddenReason??"it must be runtime-derived"}`,field:a});return i==="llm"&&Qt(t,r,n),t==="intent.invoke"&&Zt(r.request,n),t==="resource.bytes"&&Xt(r,n),t==="resource.bytesMany"&&Jt(r.requests,n),{ok:n.length===0,type:t,domain:i,direction:"out",errors:n}}var Zn=5129,nr=15129,ce=35129,gn=[Zn,nr,ce],Yn=["image/png","image/jpeg","image/webp"],Xn=/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i;function Jn(e,n){return e.tags.find(r=>r[0]===n)}function tr(e){return gn.includes(e)}function Fe(e){return typeof e=="string"&&/^[0-9a-f]{64}$/.test(e)}function et(e){return Jn(e,"d")?.[1]||void 0}function rr(e){return e.tags.filter(n=>n[0]==="R").map(n=>n[1]?.trim()??"").filter(Boolean)}function nt(e){return et(e)??Jn(e,"title")?.[1]??e.id}function sr(e){const n=[],r=[];for(const i of e.tags.filter(o=>o[0]==="screenshot")){const o=In(i,n);o&&r.push(o)}const t=e.tags.filter(i=>i[0]==="preview");let s;return t.length>1?n.push({code:"invalid-presentation-media",message:"Multiple preview tags; clients ignore the preview (NIP-5D §Presentation media)"}):t.length===1&&(s=In(t[0],n)),{screenshots:r,preview:s,warnings:n}}function In(e,n){const r=e[0],t=c=>{n.push({code:"invalid-presentation-media",message:`Ignore ${r} tag: ${c} (NIP-5D §Presentation media)`})},s=new Map;for(const c of e.slice(1)){const m=typeof c=="string"?c.indexOf(" "):-1,y=m<0?c:c.slice(0,m),w=m<0?void 0:c.slice(m+1),P=s.get(y)??[];w!==void 0?P.push(w):P.push(""),s.set(y,P)}const i=s.get("x");if(!i||i.length!==1||!Fe(i[0]))return t("exactly one x field with a lowercase sha256 is required");const o={sha256:i[0]},l=(c,m)=>{const y=s.get(c);if(y){if(y.length!==1||!m(y[0])){n.push({code:"invalid-presentation-media",message:`Ignore ${c} field on ${r} ${o.sha256}: malformed or repeated (NIP-5D §Presentation media)`});return}return y[0]}},a=l("m",c=>Xn.test(c));if(a!==void 0){if(!(r==="preview"?a.toLowerCase().startsWith("video/"):Yn.includes(a.toLowerCase())))return t(`${a} cannot match a decodable ${r==="preview"?"video":"PNG, JPEG or WebP"} format`);o.mimeType=a}const d=l("dim",c=>/^[1-9][0-9]*x[1-9][0-9]*$/.test(c));if(d!==void 0){const[c,m]=d.split("x").map(Number);o.dim={width:c,height:m}}const h=l("size",c=>/^(?:0|[1-9][0-9]*)$/.test(c));if(h!==void 0&&(o.size=Number(h)),r==="preview"){const c=l("duration",m=>/^(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/.test(m));c!==void 0&&(o.duration=Number(c))}const p=l("alt",c=>c.trim().length>0);return p!==void 0&&(o.alt=p),o}function Ge(e){const n=[],r=[];if(!e)return{ok:!1,requires:[],optional:[],errors:[{code:"missing-manifest-event",message:"No NIP-5D manifest event was resolved"}],warnings:r};const t=et(e),s=rr(e);tr(e.kind)||n.push({code:"invalid-napplet-kind",message:`Manifest event kind ${e.kind} is not a NIP-5D napplet kind`});const i=e.tags.filter(l=>l[0]==="d");e.kind===ce&&(i.length!==1||!t)?n.push({code:"missing-d-tag",message:"Named manifests require exactly one non-empty d tag"}):e.kind!==ce&&i.length>0&&n.push({code:"unexpected-d-tag",message:"Only named manifests carry a d tag"});const o=e.tags.filter(l=>l[0]==="x");return(o.length!==1||o[0].length!==2||!Fe(o[0][1]))&&n.push({code:"invalid-artifact-hash",message:"Manifest requires exactly one x tag with the lowercase sha256 of /index.html"}),(typeof e.content!="string"||!e.content.trim())&&n.push({code:"missing-description",message:"Manifest content must contain a non-empty plain-text description"}),ir(e,n,r),or(e,n,r),{ok:n.length===0,kind:e.kind,dTag:t,requires:s,optional:e.tags.filter(l=>l[0]==="O").map(l=>l[1]).filter(Boolean),errors:n,warnings:r}}function ir(e,n,r){for(const t of e.tags.filter(s=>s[0]==="R"||s[0]==="O")){const s=t[1];t.length!==2||!s||/[.:\s]/.test(s)||s.startsWith("NAP-")?n.push({code:t[0]==="R"?"invalid-required-nap":"invalid-optional-nap",message:`${t[0]} must name one bare NAP domain`}):Le.includes(s)||r.push({code:"unknown-required-nap",message:`Domain "${s}" is not in this tool's registry; check its NAP and runtime availability`})}}function or(e,n,r){for(const i of["title","source","a","A"]){const o=e.tags.filter(l=>l[0]===i);(o.length>1||o.length&&(i==="a"||i==="A")&&e.kind!==Zn)&&n.push({code:"invalid-metadata",message:`Invalid ${i} tag cardinality for kind ${e.kind}`})}const t=e.tags.filter(i=>i[0]==="source");for(const i of t)(i.length!==2||!xn(i[1]))&&n.push({code:"invalid-metadata",message:"source must contain one HTTP(S), SSH, Git, SCP, or nostr repository location"});ar(e,t.length===1&&t[0].length===2&&xn(t[0][1]),n,r);for(const i of e.tags.filter(o=>o[0]==="i"))(!i[1]?.trim()||i[1].includes("?"))&&n.push({code:"invalid-metadata",message:"Intent advertisements must be non-empty queryless identities"});const s=e.tags.filter(i=>i[0]==="icon");(s.length>1||s.some(i=>i.length!==3||!Fe(i[1])||!Yn.includes(i[2])))&&r.push({code:"invalid-icon",message:"Ignore invalid icon metadata and use generic artwork (NIP-5D §Icon)"}),r.push(...sr(e).warnings)}function ar(e,n,r,t){const s=e.tags.filter(o=>o[0]==="source-commit");s.length>1||s.some(o=>o.length!==2||!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(o[1]))?r.push({code:"invalid-metadata",message:"source-commit must appear once with a full lowercase-hex Git commit ID (40 or 64 characters)"}):s.length===1&&!n&&t.push({code:"unused-source-commit",message:"source-commit without a Git repository source is ignored (NIP-5D §Source)"});const i=e.tags.filter(o=>o[0]==="source-archive");(i.length>1||i.some(o=>o.length!==4||!lr(o[1])||!Fe(o[2])||!Xn.test(o[3]??"")))&&r.push({code:"invalid-metadata",message:"source-archive must appear once with an HTTPS URL without credentials or fragment, a lowercase sha256, and a MIME type"})}function lr(e){if(!e||e.includes("#"))return!1;try{const n=new URL(e);return n.protocol==="https:"&&!n.username&&!n.password}catch{return!1}}function xn(e){if(!e||/^[a-z]:[\\/]/i.test(e))return!1;try{const{protocol:n}=new URL(e);if(["http:","https:","ssh:","git:"].includes(n))return!0;if(n==="nostr:")return e.length>8&&e.startsWith("nostr://");if(n==="file:")return!1}catch{}return!e.includes("://")&&/^(?:[^@\s/:]+@)?[^:\s/]+:[^\s]+$/.test(e)}var de="f".repeat(64),dr={id:"reference-source-endpoint",catalogId:"reference-source"},cr="https://reference.invalid/blob",ur=`named:${de}:reference-handler`,pr={kind:35129,pubkey:de,id:"0".repeat(64),tags:[["d","reference-handler"],["z","note"],["i","napplet:note/open","event"]]},fr="reference-subscriber",mr="napplet:note/open";function ke(e,n,r){return f({type:e,id:n,result:{entries:[r]}})}var f=e=>[e],j=()=>[];function kn(e){if(typeof e!="string"||!e.startsWith("data:"))return null;const n=e.indexOf(",");if(n<0)return{blob:new Blob([],{type:"text/plain"}),mime:"text/plain"};const r=e.slice(5,n),t=e.slice(n+1),s=r.split(";").filter(Boolean),i=s.includes("base64"),o=s.find(l=>l.includes("/"))??"text/plain";try{if(i){const l=globalThis.atob(t),a=Uint8Array.from(l,d=>d.charCodeAt(0));return{blob:new Blob([a],{type:o}),mime:o}}return{blob:new Blob([decodeURIComponent(t)],{type:o}),mime:o}}catch{return null}}var gr={"gamepad.subscribe":()=>f({type:"gamepad.state",available:!1,reason:"unavailable",focused:!1,pads:[]}),"gamepad.unsubscribe":j,"relay.subscribe":e=>f({type:"relay.eose",subId:e.subId}),"relay.close":j,"relay.publish":e=>f({type:"relay.publish.result",id:e.id,ok:!0,event:e.event}),"relay.publishEncrypted":e=>f({type:"relay.publishEncrypted.result",id:e.id,ok:!0,event:e.event}),"relay.query":e=>f({type:"relay.query.result",id:e.id,events:[]}),"identity.getPublicKey":e=>f({type:"identity.getPublicKey.result",id:e.id,pubkey:de}),"identity.getRelays":e=>f({type:"identity.getRelays.result",id:e.id,relays:{}}),"identity.getProfile":e=>f({type:"identity.getProfile.result",id:e.id,profile:null}),"identity.getFollows":e=>f({type:"identity.getFollows.result",id:e.id,pubkeys:[]}),"identity.getList":e=>f({type:"identity.getList.result",id:e.id,entries:[]}),"identity.getZaps":e=>f({type:"identity.getZaps.result",id:e.id,zaps:[]}),"identity.getMutes":e=>f({type:"identity.getMutes.result",id:e.id,pubkeys:[]}),"identity.getBlocked":e=>f({type:"identity.getBlocked.result",id:e.id,pubkeys:[]}),"identity.getBadges":e=>f({type:"identity.getBadges.result",id:e.id,badges:[]}),"storage.get":e=>f({type:"storage.get.result",id:e.id,value:null}),"storage.set":e=>f({type:"storage.set.result",id:e.id}),"storage.remove":e=>f({type:"storage.remove.result",id:e.id}),"storage.keys":e=>f({type:"storage.keys.result",id:e.id,keys:[]}),"inc.emit":j,"inc.subscribe":e=>f({type:"inc.subscribe.result",id:e.id}),"inc.unsubscribe":j,"inc.channel.open":e=>f({type:"inc.channel.open.result",id:e.id,channelId:`chan-${String(e.id)}`,peer:"reference-peer"}),"inc.channel.emit":j,"inc.channel.broadcast":j,"inc.channel.list":e=>f({type:"inc.channel.list.result",id:e.id,channels:[]}),"inc.channel.close":j,"theme.get":e=>f({type:"theme.get.result",id:e.id,theme:{colors:{background:"#000000",text:"#ffffff",primary:"#663399"}}}),"keys.forward":j,"keys.registerAction":e=>f({type:"keys.registerAction.result",id:e.id,actionId:`action-${String(e.id)}`}),"keys.unregisterAction":j,"media.session.create":e=>f({type:"media.session.create.result",id:e.id,sessionId:`session-${String(e.id)}`,owner:e.owner}),"media.session.update":j,"media.session.destroy":j,"media.state":j,"media.capabilities":j,"notify.send":e=>f({type:"notify.send.result",id:e.id,notificationId:`notif-${String(e.id)}`}),"notify.dismiss":j,"notify.badge":j,"notify.channel.register":j,"notify.permission.request":e=>f({type:"notify.permission.result",id:e.id,granted:!0}),"config.registerSchema":e=>f({type:"config.registerSchema.result",id:e.id,ok:!0}),"config.get":e=>f({type:"config.values",id:e.id,values:{}}),"config.subscribe":()=>f({type:"config.values",values:{}}),"config.unsubscribe":j,"config.openSettings":j,"resource.bytes":e=>{const n=kn(e.url);return f(n?{type:"resource.bytes.result",id:e.id,blob:n.blob,mime:n.mime}:{type:"resource.bytes.result",id:e.id,blob:new Blob([]),mime:"application/octet-stream"})},"resource.bytesMany":e=>f({type:"resource.bytesMany.result",id:e.id,items:Array.isArray(e.requests)?e.requests.map(n=>{const r=typeof n=="object"&&n!==null&&!Array.isArray(n)?n.url:void 0,t=kn(r);return{url:typeof r=="string"?r:"",ok:!0,blob:t?.blob??new Blob([]),mime:t?.mime??"application/octet-stream"}}):[]}),"resource.info":e=>f({type:"resource.info.result",id:e.id,info:{schemes:[{scheme:"data",enabled:!0},{scheme:"https",enabled:!0}],maxServers:8}}),"resource.cancel":j,"cvm.discover":e=>f({type:"cvm.discover.result",id:e.id,servers:[]}),"cvm.request":e=>f({type:"cvm.request.result",id:e.id,message:{}}),"cvm.close":e=>f({type:"cvm.close.result",id:e.id}),"outbox.getEvent":e=>f({type:"outbox.getEvent.result",id:e.id}),"outbox.query":e=>f({type:"outbox.query.result",id:e.id,events:[]}),"outbox.subscribe":e=>f({type:"outbox.closed",subId:e.subId,reason:"reference shell complete"}),"outbox.close":j,"outbox.publish":e=>f({type:"outbox.publish.result",id:e.id,ok:!0}),"outbox.resolveRelays":e=>f({type:"outbox.resolveRelays.result",id:e.id,plan:{}}),"upload.info":e=>f({type:"upload.info.result",id:e.id,info:{rails:[{rail:"nip96",enabled:!0,returns:["https"]},{rail:"blossom",enabled:!0,returns:["https","blossom"]}]}}),"upload.upload":e=>f({type:"upload.upload.result",id:e.id,result:{url:cr}}),"upload.status":e=>f({type:"upload.status.result",id:e.id,status:{}}),"ble.open":e=>f({type:"ble.open.result",id:e.id,session:{id:"ble-reference",state:"open",device:{id:"reference-device",name:"Reference BLE"}}}),"ble.services":e=>f({type:"ble.services.result",id:e.id,services:[]}),"ble.read":e=>f({type:"ble.read.result",id:e.id,data:[]}),"ble.write":e=>f({type:"ble.write.result",id:e.id}),"ble.subscribe":e=>f({type:"ble.subscribe.result",id:e.id}),"ble.unsubscribe":e=>f({type:"ble.unsubscribe.result",id:e.id}),"ble.close":e=>f({type:"ble.close.result",id:e.id}),"common.encodeNip19":e=>f({type:"common.encodeNip19.result",id:e.id,ok:!0,value:"npub1reference",nip19Type:"npub"}),"common.decodeNip19":e=>f({type:"common.decodeNip19.result",id:e.id,ok:!0,nip19Type:"npub",hex:de}),"common.getProfile":e=>f({type:"common.getProfile.result",id:e.id,ok:!0,pubkey:de,profile:null}),"common.follows":e=>f({type:"common.follows.result",id:e.id,ok:!0,pubkeys:[]}),"common.follow":e=>f({type:"common.follow.result",id:e.id,ok:!0}),"common.unfollow":e=>f({type:"common.unfollow.result",id:e.id,ok:!0}),"common.react":e=>f({type:"common.react.result",id:e.id,ok:!0,eventId:"0".repeat(64)}),"common.report":e=>f({type:"common.report.result",id:e.id,ok:!0,eventId:"1".repeat(64)}),"webrtc.open":e=>f({type:"webrtc.open.result",id:e.id,session:{id:"webrtc-reference",scope:{type:"direct",pubkey:de},channel:"default",state:"connecting"}}),"webrtc.send":e=>f({type:"webrtc.send.result",id:e.id}),"webrtc.close":e=>f({type:"webrtc.close.result",id:e.id}),"link.open":e=>f({type:"link.open.result",id:e.id,status:"opened"}),"count.query":e=>f({type:"count.query.result",id:e.id,ok:!0,count:0}),"lists.supported":e=>f({type:"lists.supported.result",id:e.id,lists:[]}),"lists.add":e=>f({type:"lists.add.result",id:e.id,ok:!0,added:0,skipped:0}),"lists.remove":e=>f({type:"lists.remove.result",id:e.id,ok:!0,removed:0,skipped:0}),"serial.open":e=>f({type:"serial.open.result",id:e.id,session:{id:`serial-${String(e.id)}`,state:"open"}}),"serial.write":e=>f({type:"serial.write.result",id:e.id}),"serial.close":e=>f({type:"serial.close.result",id:e.id}),"fs.info":e=>f({type:"fs.info.result",id:e.id,info:{roots:[{path:"/shared",name:"Shared files",permissions:["read","list","write","create","delete","watch"]}],limits:{maxReadBytes:1048576,maxWriteBytes:1048576,maxWatchCount:16}}}),"fs.pickFile":e=>ke("fs.pickFile.result",e.id,{path:"/picked/file.txt",kind:"file",name:"file.txt",permissions:["read"]}),"fs.pickFiles":e=>ke("fs.pickFiles.result",e.id,{path:"/picked/file.txt",kind:"file",name:"file.txt",permissions:["read"]}),"fs.pickDirectory":e=>ke("fs.pickDirectory.result",e.id,{path:"/picked",kind:"directory",name:"picked",permissions:["read","list"]}),"fs.pickSaveFile":e=>ke("fs.pickSaveFile.result",e.id,{path:"/picked/export.json",kind:"file",name:"export.json",permissions:["write","create"]}),"fs.stat":e=>f({type:"fs.stat.result",id:e.id,metadata:{path:e.path,kind:"file",size:0}}),"fs.list":e=>f({type:"fs.list.result",id:e.id,entries:[]}),"fs.read":e=>f({type:"fs.read.result",id:e.id,result:{data:"",offset:0,bytesRead:0,eof:!0,size:0}}),"fs.write":e=>f({type:"fs.write.result",id:e.id,result:{bytesWritten:0,size:0}}),"fs.mkdir":e=>f({type:"fs.mkdir.result",id:e.id}),"fs.remove":e=>f({type:"fs.remove.result",id:e.id}),"fs.move":e=>f({type:"fs.move.result",id:e.id}),"fs.watch":e=>f({type:"fs.watch.result",id:e.id,watchId:`watch-${String(e.id)}`}),"fs.unwatch":e=>f({type:"fs.unwatch.result",id:e.id})},tt={name:"Reference connection",model:"reference-model",route:"Reference shell → reference provider (no network)",images:!0,json:!0},be=(e,n)=>({error:{code:e,message:n}}),qe=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{};function hr(e,n){let r=e.get(n.id);return r||(r={handles:new Set,active:new Map,sequence:0},e.set(n.id,r)),r}function rt(e){return{handle:e,...tt}}function yr(e,n){const r=qe(n.requirements);if(r.model!==void 0&&r.model!==tt.model)return be("unsupported","No connection offers the requested model");e.sequence+=1;const t=`reference-llm-h${e.sequence}`;return e.handles.add(t),{model:rt(t)}}function br(e,n){const r=String(n.handle);return e.handles.has(r)?{model:rt(r)}:be("selection-expired","Select a model again")}function vr(e){const n=Array.isArray(e.messages)?e.messages:[];let r="";for(const t of n){const s=qe(t);if(!(s.role!=="user"||!Array.isArray(s.content)))for(const i of s.content){const o=qe(i);o.type==="text"&&typeof o.text=="string"&&(r=o.text)}}return r}function wr(e,n,r){const t=a=>[{type:"llm.generate.result",id:n,...a}];if(e.active.has(n))return t(be("invalid-request","Request id is still active"));const s=qe(r.request);if(!e.handles.has(String(s.handle)))return t(be("selection-expired","Select a model again"));const i=vr(s);if(i.includes("[[decline]]"))return t(be("user-cancelled","The user declined disclosure"));if(i.includes("[[stall]]"))return e.active.set(n,r),[];if(i.includes("[[refuse]]"))return t({result:{text:"",finish:"refusal"}});const o=s.format==="json"?JSON.stringify({echo:i}):`Echo: ${i}`,l={inputTokens:JSON.stringify(s.messages).length,outputTokens:o.length};return[{type:"llm.delta",requestId:n,sequence:0,text:o.slice(0,Math.ceil(o.length/2))},...t({result:{text:o,finish:"stop",usage:l}})]}function Er(e,n,r){const t=String(r.requestId);return e.active.delete(t)?[{type:"llm.generate.result",id:t,error:{code:"cancelled",message:"Generation cancelled; provider charges may still apply."}},{type:"llm.cancel.result",id:n,cancelled:!0}]:[{type:"llm.cancel.result",id:n,cancelled:!1}]}function Sr(e,n,r){const t=String(r.type),s=String(r.id),i=hr(e,n);switch(t){case"llm.select":return[{type:"llm.select.result",id:s,...yr(i,r)}];case"llm.describe":return[{type:"llm.describe.result",id:s,...br(i,r)}];case"llm.generate":return structuredClone(wr(i,s,r));case"llm.cancel":return Er(i,s,r);default:return[{type:`${t}.result`,id:s,error:{code:"invalid-request",message:`Unknown operation ${t}`}}]}}function Tr(){const e=new Map;return{handle:(n,r)=>Sr(e,n,r),reset(){e.clear()}}}function _r(e){const n=new Set,r=Tr();return Object.assign((s,i)=>{const o=Rr(i),l=er(i);if(e.records.push({envelope:i,verdict:l,timestamp:e.now()}),!o||!l.ok)return[];const a=s.domains??Le;if(!a.includes(o.slice(0,o.indexOf("."))))return[];if(o==="shell.ready")return n.has(s.id)?[]:(n.add(s.id),f({type:"shell.init",capabilities:{domains:[...a]},services:[]}));const d=i;if(o.startsWith("llm."))return r.handle(s,d);if(o==="intent.invoke")return e.intents.handleInvoke(s,d);if(o==="intent.available")return f({type:"intent.available.result",id:d.id,availability:e.intents.availability(d.archetype)});if(o==="intent.handlers")return f({type:"intent.handlers.result",id:d.id,handlers:e.intents.handlers()});if(o==="inc.emit")return Ir(s,d,e.queueDelivery);const h=gr[o];return h?h(d):[]},{reset(){r.reset()}})}function Rr(e){if(!e||typeof e!="object")return;const n=e.type;return typeof n=="string"?n:void 0}function Ir(e,n,r){if(n.topic!==mr)return[];const t={type:"inc.event",topic:n.topic,sender:e.id};return"payload"in n&&(t.payload=n.payload),r(fr,t),[]}function xr(e){return e.kind===5129?`snapshot:${e.id}`:e.kind===15129?`root:${e.pubkey}`:`named:${e.pubkey}:${e.tags.find(n=>n[0]==="d")?.[1]??""}`}function kr(e,n){if(!e.tags.some(t=>t[0]==="z"&&t[1]===n))return[];const r=[];for(const t of e.tags)t[0]!=="i"||/^napplet:([^/?#]+)\/([^/?#]+)$/.exec(t[1]??"")?.[1]!==n||r.push({convention:t[1],params:t.slice(2)});return r}function Mr(e,n,r){const t=[];for(const s of e){const i=kr(s,n);if(!i.length)continue;const o=s.tags.find(a=>a[0]==="title")?.[1],l=xr(s);t.push({id:l,...o?{title:o}:{},actions:[...new Set(i.map(({convention:a})=>a.slice(a.indexOf("/")+1)))],conventions:[...new Set(i.map(({convention:a})=>a))],contracts:i,...l===r?{isDefault:!0}:{}})}return{archetype:n,available:t.length>0,candidates:t,hasDefault:t.some(s=>s.isDefault)}}function Ur(e,n=[pr],r={note:ur}){const t=s=>Mr(n,String(s),r[String(s)]);return{availability:t,handlers:()=>[...new Set(n.flatMap(s=>s.tags.filter(i=>i[0]==="z").map(i=>i[1])))].map(t),handleInvoke(s,i){const o=i.request,l=t(o.archetype).candidates.filter(m=>m.conventions.includes(o.convention)),a=o.handler&&!["default","choose"].includes(o.handler),d=o.handler==="choose"?void 0:a?l.find(m=>m.id===o.handler):l.find(m=>m.isDefault)??l[0];if(!d)return f({type:"intent.invoke.result",id:i.id,result:{ok:!1,error:"no handler"}});const{archetype:h,action:p,convention:c}=o;return e(d.id,structuredClone({type:"intent.deliver",delivery:{sender:s.catalogId,archetype:h,action:p,convention:c,..."payload"in o?{payload:o.payload}:{}}})),f({type:"intent.invoke.result",id:i.id,result:{ok:!0,archetype:h,action:p,convention:c,handler:d.id}})}}}function Pr(e={}){const n=[],r=Ar(),t=_r({now:e.now??Date.now,records:n,queueDelivery:r.queue,intents:Ur(r.queue,e.manifests,e.defaults)});return{get records(){return n},handle:s=>t(dr,s),handleFrom:t,takeDeliveries:r.take,reset(){n.length=0,t.reset(),r.clear()}}}function Ar(){const e=new Map;return{queue(n,r){const t=e.get(n);t?t.push(r):e.set(n,[r])},take(n){const r=e.get(n)??[];return e.delete(n),r},clear(){e.clear()}}}function jr(e){return{manifestHtml:e.manifestHtml,manifestEvent:e.manifestEvent??null,sandbox:e.sandbox??{allowScripts:!0,allowSameOrigin:!1},installedGlobal:e.boot.installedGlobal,bootError:e.boot.bootError,emitted:e.boot.emitted,forbiddenGlobals:e.forbiddenGlobals??[],degraded:e.boot.degraded,lifecycle:e.lifecycle??null}}var qr=`
|
|
2
|
+
if (domains.includes('llm')) {
|
|
3
|
+
const llmFields = { 'llm.select.result': 'model', 'llm.describe.result': 'model', 'llm.generate.result': 'result', 'llm.cancel.result': 'cancelled' };
|
|
4
|
+
const llmDeltas = new Map();
|
|
5
|
+
window.addEventListener('message', (event) => {
|
|
6
|
+
if (event.source !== window.parent) return;
|
|
7
|
+
const msg = event.data;
|
|
8
|
+
if (!msg || typeof msg !== 'object' || msg.type !== 'llm.delta' || 'id' in msg || typeof msg.requestId !== 'string') return;
|
|
9
|
+
const entry = llmDeltas.get(msg.requestId);
|
|
10
|
+
if (!entry || typeof msg.sequence !== 'number' || typeof msg.text !== 'string') return;
|
|
11
|
+
if (msg.sequence !== entry.next) { entry.next = Infinity; return; }
|
|
12
|
+
entry.next += 1;
|
|
13
|
+
if (entry.onDelta) entry.onDelta({ requestId: msg.requestId, sequence: msg.sequence, text: msg.text });
|
|
14
|
+
});
|
|
15
|
+
const llmRequest = (payload, id) => {
|
|
16
|
+
const type = payload.type;
|
|
17
|
+
return request(id === undefined ? payload : { ...payload, id }, type + '.result').then((message) => {
|
|
18
|
+
const field = llmFields[message.type];
|
|
19
|
+
const hasValue = message[field] !== undefined && message[field] !== null;
|
|
20
|
+
const hasError = message.error !== undefined && message.error !== null;
|
|
21
|
+
if (hasValue === hasError) throw new Error(type + '.result must carry exactly one of ' + field + ' or error');
|
|
22
|
+
if (hasError) {
|
|
23
|
+
const failure = new Error(String(message.error.message));
|
|
24
|
+
failure.name = 'LlmError';
|
|
25
|
+
failure.code = message.error.code;
|
|
26
|
+
throw failure;
|
|
27
|
+
}
|
|
28
|
+
return message[field];
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
napplet.llm = {
|
|
32
|
+
select: (requirements) => llmRequest(requirements === undefined ? { type: 'llm.select' } : { type: 'llm.select', requirements }),
|
|
33
|
+
describe: (handle) => llmRequest({ type: 'llm.describe', handle }),
|
|
34
|
+
generate: (generation, options) => {
|
|
35
|
+
const id = nextId();
|
|
36
|
+
const entry = { next: 0, onDelta: options && options.onDelta };
|
|
37
|
+
llmDeltas.set(id, entry);
|
|
38
|
+
const signal = options && options.signal;
|
|
39
|
+
const abort = () => { napplet.llm.cancel(id).catch(() => undefined); };
|
|
40
|
+
if (signal) { if (signal.aborted) abort(); else signal.addEventListener('abort', abort, { once: true }); }
|
|
41
|
+
const pendingGeneration = llmRequest({ type: 'llm.generate', request: generation }, id).finally(() => {
|
|
42
|
+
llmDeltas.delete(id);
|
|
43
|
+
if (signal) signal.removeEventListener('abort', abort);
|
|
44
|
+
});
|
|
45
|
+
return Object.assign(pendingGeneration, { requestId: id });
|
|
46
|
+
},
|
|
47
|
+
cancel: (requestId) => llmRequest({ type: 'llm.cancel', requestId }),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
`,st="__nappletConformance.error",it="__nappletConformance.installed";function Mn(e){return new Promise(n=>setTimeout(n,e))}function Or(e){return e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}var Cr=`(() => {
|
|
2
51
|
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
3
52
|
const numberIn = (value, min, max) => typeof value === 'number' && Number.isFinite(value) && value >= min && value <= max;
|
|
4
53
|
const isGamepadState = (value) => {
|
|
@@ -25,23 +74,21 @@
|
|
|
25
74
|
return copy;
|
|
26
75
|
};
|
|
27
76
|
return { isGamepadState, copyGamepadState };
|
|
28
|
-
})()`;function
|
|
77
|
+
})()`;function Hr(){return`(() => {
|
|
29
78
|
const report = (reason) => {
|
|
30
|
-
try { window.parent.postMessage({ type: '${
|
|
79
|
+
try { window.parent.postMessage({ type: '${st}', reason: String(reason && reason.message || reason) }, '*'); }
|
|
31
80
|
catch {}
|
|
32
81
|
};
|
|
33
82
|
window.addEventListener('error', (event) => report(event.error || event.message));
|
|
34
83
|
window.addEventListener('unhandledrejection', (event) => report(event.reason));
|
|
35
|
-
})();`}
|
|
36
|
-
;globalThis.NappletShimPrelude.install(${JSON.stringify({domains:e})});
|
|
37
|
-
${s}`:`
|
|
84
|
+
})();`}var Dr=`
|
|
38
85
|
(() => {
|
|
39
|
-
const domains =
|
|
86
|
+
const domains = `,Nr=`;
|
|
40
87
|
const napplet = {};
|
|
41
88
|
for (const domain of domains) {
|
|
42
89
|
if (domain === 'resource' || domain === 'gamepad') napplet[domain] = {};
|
|
43
90
|
}
|
|
44
|
-
const gamepadTools =
|
|
91
|
+
const gamepadTools = `,Br=`;
|
|
45
92
|
let gamepadState = { available: true, focused: false, pads: [] };
|
|
46
93
|
const gamepadHandlers = new Set();
|
|
47
94
|
// Subscribe on first use, like the nap binding, so napplets that never touch
|
|
@@ -140,10 +187,13 @@ ${s}`:`
|
|
|
140
187
|
return handle;
|
|
141
188
|
};
|
|
142
189
|
}
|
|
190
|
+
${qr}
|
|
143
191
|
window.napplet = napplet;
|
|
144
|
-
|
|
192
|
+
`,Lr=`
|
|
145
193
|
})();
|
|
146
|
-
`}function is(e,n,s,t){const r=`<base href="${ns(n)}">`,i=rs(s,t).replace(/<\/script/gi,"<\\/script"),o=`<script>${ss()}<\/script><script>${i}<\/script>`,l=/<head(?:\s[^>]*)?>/i.exec(e);if(l){const a=l.index+l[0].length;return`${e.slice(0,a)}${r}${o}${e.slice(a)}`}return`${r}${o}${e}`}function os(e){if(!e.startsWith("data:"))return null;const n=e.indexOf(",");if(n<0)return"";const s=e.slice(0,n),t=e.slice(n+1);return s.endsWith(";base64")?atob(t):decodeURIComponent(t)}async function as(e){if(e==="about:blank")return"<!doctype html><html><head></head><body></body></html>";const n=os(e);if(n!==null)return n;const s=await fetch(e);if(!s.ok)throw new Error(`Failed to fetch napplet HTML: ${s.status} ${s.statusText}`);return s.text()}async function En(e,n,s,t){const r=Xt(),i=s.createElement("iframe");i.setAttribute("sandbox",n.allowSameOrigin?"allow-scripts allow-same-origin":"allow-scripts"),i.setAttribute("allow","gamepad 'none'"),i.setAttribute("aria-hidden","true"),i.style.position="absolute",i.style.width="1px",i.style.height="1px",i.style.left="-9999px";let o=null,l=!1;const a=u=>{if(u.source!==i.contentWindow)return;const f=u.data;if(f&&typeof f=="object"&&f.type===Vn){l=f.installed===!0;return}if(f&&typeof f=="object"&&f.type===Wn){o=`napplet boot error: ${String(f.reason??"unknown error")}`;return}const g=r.handle(u.data),b=u.source;for(const E of g)b?.postMessage(E,"*")};let d=!1;const h=new Promise(u=>{i.addEventListener("load",()=>{d=!0,u()},{once:!0})});t.addEventListener("message",a);try{const u=n.html??await as(n.url);i.srcdoc=is(u,n.url,e,n.runtimePreludeSource),(s.body??s.documentElement).appendChild(i)}catch(u){o=u instanceof Error?u.message:String(u)}if(!o){const u=Symbol("timeout");await Promise.race([h.then(()=>"loaded"),wn(n.readyTimeoutMs).then(()=>u)])===u||!d?o=`napplet did not boot (iframe did not load within ${n.readyTimeoutMs}ms; a conformant napplet must run under sandbox="allow-scripts" without allow-same-origin)`:await wn(n.settleMs)}t.removeEventListener("message",a);try{i.remove()}catch{}return{installedGlobal:l,bootError:o,emitted:[...r.records]}}async function ls(e){const n=e.document??document,s=e.window??window,t={url:e.url,html:e.html,readyTimeoutMs:e.readyTimeoutMs??5e3,settleMs:e.settleMs,allowSameOrigin:e.allowSameOrigin??!1,runtimePreludeSource:e.runtimePreludeSource},r=await En(Ce,t,n,s);let i=null;{const o=await En([],t,n,s);i={bootError:o.bootError,emitted:o.emitted}}return{installedGlobal:r.installedGlobal,bootError:r.bootError,emitted:r.emitted,degraded:i}}var ds=e=>({status:"pass",detail:e}),cs=(e,n)=>({status:"fail",detail:e,diagnostics:n}),us=e=>({status:"skip",detail:e}),P={pass:ds,fail:cs,skip:us};function ps(e,n){const s=Be(e.manifestEvent);return[...s.errors,...s.warnings].filter(t=>n.includes(t.code))}function Te(e,n,s,t="error"){return{id:e,area:"manifest",severity:t,title:n,run:r=>{if(!r.manifestEvent)return P.skip("No NIP-5D manifest event was resolved");const i=ps(r,s);return i.length?P.fail(i[0].message,i):P.pass()}}}var fs=[Te("manifest/event-kind","Resolved event is a NIP-5D napplet manifest",["invalid-napplet-kind","missing-d-tag","unexpected-d-tag"]),Te("manifest/index-html","Manifest declares a hashed /index.html",["invalid-artifact-hash","missing-description","invalid-metadata"]),Te("manifest/requires","R/O tags name bare NAP domains",["invalid-required-nap","invalid-optional-nap"]),Te("manifest/requires-known","R/O domains are in this toolchain registry (advisory)",["unknown-required-nap"],"warning"),{id:"boot/sandbox-allow-scripts",area:"boot",severity:"error",title:"Runs under allow-scripts without allow-same-origin",run:e=>e.sandbox.allowScripts?e.sandbox.allowSameOrigin?P.fail("Napplet relied on allow-same-origin, which a shell must not grant"):P.pass():P.fail("Napplet was not loaded with allow-scripts")},{id:"boot/installs-global",area:"boot",severity:"error",title:"Runs after runtime-injected window.napplet is installed",run:e=>e.installedGlobal?P.pass():P.fail("runtime did not inject window.napplet before load")},{id:"boot/no-boot-error",area:"boot",severity:"error",title:"Boots without an uncaught error",run:e=>e.bootError?P.fail(e.bootError):P.pass()},{id:"boot/no-forbidden-globals",area:"boot",severity:"error",title:"Does not access forbidden browser authority surfaces",run:e=>e.forbiddenGlobals.length?P.fail(`Accessed forbidden surface(s): ${e.forbiddenGlobals.join(", ")}`,e.forbiddenGlobals):P.pass()},{id:"wire/envelope-well-formed",area:"wire",severity:"error",title:"Every emitted envelope is well-formed",run:e=>{if(e.emitted.length===0)return P.skip("Napplet emitted no envelopes");const n=e.emitted.filter(t=>!t.verdict.ok);if(n.length===0)return P.pass(`${e.emitted.length} envelope(s) valid`);const s=n.map(t=>({envelope:t.envelope,errors:t.verdict.errors}));return P.fail(`${n.length}/${e.emitted.length} emitted envelope(s) invalid`,s)}},{id:"degrade/domain-absence",area:"degradation",severity:"error",title:"Does not crash when no NAP domains are injected",run:e=>e.degraded?e.degraded.bootError?P.fail(`Crashed with no injected domains: ${e.degraded.bootError}`):P.pass():P.skip("Host did not run the degraded (no-capabilities) pass")},{id:"lifecycle/clean-teardown",area:"lifecycle",severity:"warning",title:"Tears down listeners on unload",run:e=>e.lifecycle?e.lifecycle.listenerLeak?P.fail("Message listeners remained after unload"):P.pass():P.skip("Lifecycle not measured")}];function ms(e,n={}){const s=n.now??(()=>Date.now()),t=n.checks??fs,r=s(),i=t.map(a=>{const d=a.run(e);return{id:a.id,area:a.area,severity:a.severity,title:a.title,status:d.status,detail:d.detail,diagnostics:d.diagnostics}}),o={total:i.length,passed:i.filter(a=>a.status==="pass").length,failed:i.filter(a=>a.status==="fail").length,skipped:i.filter(a=>a.status==="skip").length,errors:i.filter(a=>a.status==="fail"&&a.severity==="error").length,warnings:i.filter(a=>a.status==="fail"&&a.severity==="warning").length};return{napplet:e.manifestEvent?Gn(e.manifestEvent):void 0,startedAt:r,finishedAt:s(),checks:i,summary:o,ok:o.errors===0}}function gs(e,n){const s=r=>e.tags.find(i=>i[0]===r)?.[1],t=e.tags.filter(r=>r[0]==="server").map(r=>r[1]).filter(Boolean);return[["event",e.id],["kind",e.kind],["d",s("d")],["name",Gn(e)],["requires",n.requires.join(", ")],["optional",n.optional.join(", ")],["artifact hash (x)",s("x")],["servers",t.join(", ")]]}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function hs(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function cn(e,n=""){if(!Number.isSafeInteger(e)||e<0){const s=n&&`"${n}" `;throw new Error(`${s}expected integer >= 0, got ${e}`)}}function $(e,n,s=""){const t=hs(e),r=e?.length,i=n!==void 0;if(!t||i&&r!==n){const o=s&&`"${s}" `,l=i?` of length ${n}`:"",a=t?`length=${r}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+l+", got "+a)}return e}function Sn(e,n=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(n&&e.finished)throw new Error("Hash#digest() has already been called")}function ys(e,n){$(e,void 0,"digestInto() output");const s=n.outputLen;if(e.length<s)throw new Error('"digestInto() output" expected to be of length >='+s)}function Je(...e){for(let n=0;n<e.length;n++)e[n].fill(0)}function Ge(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function K(e,n){return e<<32-n|e>>>n}const Qn=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",bs=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));function C(e){if($(e),Qn)return e.toHex();let n="";for(let s=0;s<e.length;s++)n+=bs[e[s]];return n}const X={_0:48,_9:57,A:65,F:70,a:97,f:102};function _n(e){if(e>=X._0&&e<=X._9)return e-X._0;if(e>=X.A&&e<=X.F)return e-(X.A-10);if(e>=X.a&&e<=X.f)return e-(X.a-10)}function Y(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(Qn)return Uint8Array.fromHex(e);const n=e.length,s=n/2;if(n%2)throw new Error("hex string expected, got unpadded hex of length "+n);const t=new Uint8Array(s);for(let r=0,i=0;r<s;r++,i+=2){const o=_n(e.charCodeAt(i)),l=_n(e.charCodeAt(i+1));if(o===void 0||l===void 0){const a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}t[r]=o*16+l}return t}function Me(...e){let n=0;for(let t=0;t<e.length;t++){const r=e[t];$(r),n+=r.length}const s=new Uint8Array(n);for(let t=0,r=0;t<e.length;t++){const i=e[t];s.set(i,r),r+=i.length}return s}function vs(e,n={}){const s=(r,i)=>e(i).update(r).digest(),t=e(void 0);return s.outputLen=t.outputLen,s.blockLen=t.blockLen,s.create=r=>e(r),Object.assign(s,n),Object.freeze(s)}function zn(e=32){const n=typeof globalThis=="object"?globalThis.crypto:null;if(typeof n?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return n.getRandomValues(new Uint8Array(e))}const ws=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Kn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Zn(e,n){return Array.isArray(n)?n.length===0?!0:e?n.every(s=>typeof s=="string"):n.every(s=>Number.isSafeInteger(s)):!1}function Es(e){if(typeof e!="function")throw new Error("function expected");return!0}function be(e,n){if(typeof n!="string")throw new Error(`${e}: string expected`);return!0}function Yn(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function en(e){if(!Array.isArray(e))throw new Error("array expected")}function Xn(e,n){if(!Zn(!0,n))throw new Error(`${e}: array of strings expected`)}function Jn(e,n){if(!Zn(!1,n))throw new Error(`${e}: array of numbers expected`)}function Ss(...e){const n=i=>i,s=(i,o)=>l=>i(o(l)),t=e.map(i=>i.encode).reduceRight(s,n),r=e.map(i=>i.decode).reduce(s,n);return{encode:t,decode:r}}function _s(e){const n=typeof e=="string"?e.split(""):e,s=n.length;Xn("alphabet",n);const t=new Map(n.map((r,i)=>[r,i]));return{encode:r=>(en(r),r.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=s)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${e}`);return n[i]})),decode:r=>(en(r),r.map(i=>{be("alphabet.decode",i);const o=t.get(i);if(o===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${e}`);return o}))}}function Ts(e=""){return be("join",e),{encode:n=>(Xn("join.decode",n),n.join(e)),decode:n=>(be("join.decode",n),n.split(e))}}const et=(e,n)=>n===0?e:et(n,e%n),Pe=(e,n)=>e+(n-et(e,n)),xe=(()=>{let e=[];for(let n=0;n<40;n++)e.push(2**n);return e})();function nn(e,n,s,t){if(en(e),n<=0||n>32)throw new Error(`convertRadix2: wrong from=${n}`);if(s<=0||s>32)throw new Error(`convertRadix2: wrong to=${s}`);if(Pe(n,s)>32)throw new Error(`convertRadix2: carry overflow from=${n} to=${s} carryBits=${Pe(n,s)}`);let r=0,i=0;const o=xe[n],l=xe[s]-1,a=[];for(const d of e){if(Yn(d),d>=o)throw new Error(`convertRadix2: invalid data word=${d} from=${n}`);if(r=r<<n|d,i+n>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${n}`);for(i+=n;i>=s;i-=s)a.push((r>>i-s&l)>>>0);const h=xe[i];if(h===void 0)throw new Error("invalid carry");r&=h-1}if(r=r<<s-i&l,!t&&i>=n)throw new Error("Excess padding");if(!t&&r>0)throw new Error(`Non-zero padding: ${r}`);return t&&i>0&&a.push(r>>>0),a}function Rs(e,n=!1){if(Yn(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Pe(8,e)>32||Pe(e,8)>32)throw new Error("radix2: carry overflow");return{encode:s=>{if(!Kn(s))throw new Error("radix2.encode input should be Uint8Array");return nn(Array.from(s),8,e,!n)},decode:s=>(Jn("radix2.decode",s),Uint8Array.from(nn(s,e,8,n)))}}function Tn(e){return Es(e),function(...n){try{return e.apply(null,n)}catch{}}}const tn=Ss(_s("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Ts("")),Rn=[996825010,642813549,513874426,1027748829,705979059];function me(e){const n=e>>25;let s=(e&33554431)<<5;for(let t=0;t<Rn.length;t++)(n>>t&1)===1&&(s^=Rn[t]);return s}function In(e,n,s=1){const t=e.length;let r=1;for(let i=0;i<t;i++){const o=e.charCodeAt(i);if(o<33||o>126)throw new Error(`Invalid prefix (${e})`);r=me(r)^o>>5}r=me(r);for(let i=0;i<t;i++)r=me(r)^e.charCodeAt(i)&31;for(let i of n)r=me(r)^i;for(let i=0;i<6;i++)r=me(r);return r^=s,tn.encode(nn([r%xe[30]],30,5,!1))}function Is(e){const n=e==="bech32"?1:734539939,s=Rs(5),t=s.decode,r=s.encode,i=Tn(t);function o(u,f,g=90){be("bech32.encode prefix",u),Kn(f)&&(f=Array.from(f)),Jn("bech32.encode",f);const b=u.length;if(b===0)throw new TypeError(`Invalid prefix length ${b}`);const E=b+7+f.length;if(g!==!1&&E>g)throw new TypeError(`Length ${E} exceeds limit ${g}`);const j=u.toLowerCase(),O=In(j,f,n);return`${j}1${tn.encode(f)}${O}`}function l(u,f=90){be("bech32.decode input",u);const g=u.length;if(g<8||f!==!1&&g>f)throw new TypeError(`invalid string length: ${g} (${u}). Expected (8..${f})`);const b=u.toLowerCase();if(u!==b&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");const E=b.lastIndexOf("1");if(E===0||E===-1)throw new Error('Letter "1" must be present between prefix and data only');const j=b.slice(0,E),O=b.slice(E+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const Q=tn.decode(O).slice(0,-6),J=In(j,Q,n);if(!O.endsWith(J))throw new Error(`Invalid checksum in ${u}: expected "${J}"`);return{prefix:j,words:Q}}const a=Tn(l);function d(u){const{prefix:f,words:g}=l(u,!1);return{prefix:f,words:g,bytes:t(g)}}function h(u,f){return o(u,r(f))}return{encode:o,decode:l,encodeFromBytes:h,decodeToBytes:d,decodeUnsafe:a,fromWords:t,fromWordsUnsafe:i,toWords:r}}const kn=Is("bech32");var Re=new TextDecoder("utf-8");new TextEncoder;var ks=5e3;function xs(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),Us(e)}catch{return{type:"invalid",data:null}}}function Us(e){let{prefix:n,words:s}=kn.decode(e,ks),t=new Uint8Array(kn.fromWords(s));switch(n){case"nprofile":{let r=We(t);if(!r[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(r[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:C(r[0][0]),relays:r[1]?r[1].map(i=>Re.decode(i)):[]}}}case"nevent":{let r=We(t);if(!r[0]?.[0])throw new Error("missing TLV 0 for nevent");if(r[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(r[2]&&r[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(r[3]&&r[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:C(r[0][0]),relays:r[1]?r[1].map(i=>Re.decode(i)):[],author:r[2]?.[0]?C(r[2][0]):void 0,kind:r[3]?.[0]?parseInt(C(r[3][0]),16):void 0}}}case"naddr":{let r=We(t);if(!r[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!r[2]?.[0])throw new Error("missing TLV 2 for naddr");if(r[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!r[3]?.[0])throw new Error("missing TLV 3 for naddr");if(r[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Re.decode(r[0][0]),pubkey:C(r[2][0]),kind:parseInt(C(r[3][0]),16),relays:r[1]?r[1].map(i=>Re.decode(i)):[]}}}case"nsec":return{type:n,data:t};case"npub":case"note":return{type:n,data:C(t)};default:throw new Error(`unknown prefix ${n}`)}}function We(e){let n={},s=e;for(;s.length>0;){let t=s[0],r=s[1],i=s.slice(2,2+r);if(s=s.slice(2+r),i.length<r)throw new Error(`not enough data to read on TLV ${t}`);n[t]=n[t]||[],n[t].push(i)}return n}function Ms(e,n,s){return e&n^~e&s}function Ps(e,n,s){return e&n^e&s^n&s}class As{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(n,s,t,r){this.blockLen=n,this.outputLen=s,this.padOffset=t,this.isLE=r,this.buffer=new Uint8Array(n),this.view=Ge(this.buffer)}update(n){Sn(this),$(n);const{view:s,buffer:t,blockLen:r}=this,i=n.length;for(let o=0;o<i;){const l=Math.min(r-this.pos,i-o);if(l===r){const a=Ge(n);for(;r<=i-o;o+=r)this.process(a,o);continue}t.set(n.subarray(o,o+l),this.pos),this.pos+=l,o+=l,this.pos===r&&(this.process(s,0),this.pos=0)}return this.length+=n.length,this.roundClean(),this}digestInto(n){Sn(this),ys(n,this),this.finished=!0;const{buffer:s,view:t,blockLen:r,isLE:i}=this;let{pos:o}=this;s[o++]=128,Je(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(t,0),o=0);for(let u=o;u<r;u++)s[u]=0;t.setBigUint64(r-8,BigInt(this.length*8),i),this.process(t,0);const l=Ge(n),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const d=a/4,h=this.get();if(d>h.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<d;u++)l.setUint32(4*u,h[u],i)}digest(){const{buffer:n,outputLen:s}=this;this.digestInto(n);const t=n.slice(0,s);return this.destroy(),t}_cloneInto(n){n||=new this.constructor,n.set(...this.get());const{blockLen:s,buffer:t,length:r,finished:i,destroyed:o,pos:l}=this;return n.destroyed=o,n.finished=i,n.length=r,n.pos=l,r%s&&n.buffer.set(t),n}clone(){return this._cloneInto()}}const ee=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),js=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]),ne=new Uint32Array(64);class Os extends As{constructor(n){super(64,n,8,!1)}get(){const{A:n,B:s,C:t,D:r,E:i,F:o,G:l,H:a}=this;return[n,s,t,r,i,o,l,a]}set(n,s,t,r,i,o,l,a){this.A=n|0,this.B=s|0,this.C=t|0,this.D=r|0,this.E=i|0,this.F=o|0,this.G=l|0,this.H=a|0}process(n,s){for(let u=0;u<16;u++,s+=4)ne[u]=n.getUint32(s,!1);for(let u=16;u<64;u++){const f=ne[u-15],g=ne[u-2],b=K(f,7)^K(f,18)^f>>>3,E=K(g,17)^K(g,19)^g>>>10;ne[u]=E+ne[u-7]+b+ne[u-16]|0}let{A:t,B:r,C:i,D:o,E:l,F:a,G:d,H:h}=this;for(let u=0;u<64;u++){const f=K(l,6)^K(l,11)^K(l,25),g=h+f+Ms(l,a,d)+js[u]+ne[u]|0,E=(K(t,2)^K(t,13)^K(t,22))+Ps(t,r,i)|0;h=d,d=a,a=l,l=o+g|0,o=i,i=r,r=t,t=g+E|0}t=t+this.A|0,r=r+this.B|0,i=i+this.C|0,o=o+this.D|0,l=l+this.E|0,a=a+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(t,r,i,o,l,a,d,h)}roundClean(){Je(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),Je(this.buffer)}}class qs extends Os{A=ee[0]|0;B=ee[1]|0;C=ee[2]|0;D=ee[3]|0;E=ee[4]|0;F=ee[5]|0;G=ee[6]|0;H=ee[7]|0;constructor(){super(32)}}const Ae=vs(()=>new qs,ws(1));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const un=BigInt(0),sn=BigInt(1);function xn(e,n=""){if(typeof e!="boolean"){const s=n&&`"${n}" `;throw new Error(s+"expected boolean, got type="+typeof e)}return e}function Cs(e){if(typeof e=="bigint"){if(!Ds(e))throw new Error("positive bigint expected, got "+e)}else cn(e);return e}function nt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?un:BigInt("0x"+e)}function pn(e){return nt(C(e))}function tt(e){return nt(C(Hs($(e)).reverse()))}function fn(e,n){cn(n),e=Cs(e);const s=Y(e.toString(16).padStart(n*2,"0"));if(s.length!==n)throw new Error("number too large");return s}function st(e,n){return fn(e,n).reverse()}function Hs(e){return Uint8Array.from(e)}function Bs(e){return Uint8Array.from(e,(n,s)=>{const t=n.charCodeAt(0);if(n.length!==1||t>127)throw new Error(`string contains non-ASCII character "${e[s]}" with code ${t} at position ${s}`);return t})}const Ds=e=>typeof e=="bigint"&&un<=e;function Ns(e){let n;for(n=0;e>un;e>>=sn,n+=1);return n}const rt=e=>(sn<<BigInt(e))-sn;function it(e,n={},s={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function t(i,o,l){const a=e[i];if(l&&a===void 0)return;const d=typeof a;if(d!==o||a===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${d}`)}const r=(i,o)=>Object.entries(i).forEach(([l,a])=>t(l,a,o));r(n,!1),r(s,!0)}function Un(e){const n=new WeakMap;return(s,...t)=>{const r=n.get(s);if(r!==void 0)return r;const i=e(s,...t);return n.set(s,i),i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const N=BigInt(0),D=BigInt(1),ie=BigInt(2),ot=BigInt(3),at=BigInt(4),lt=BigInt(5),$s=BigInt(7),dt=BigInt(8),Ls=BigInt(9),ct=BigInt(16);function V(e,n){const s=e%n;return s>=N?s:n+s}function F(e,n,s){let t=e;for(;n-- >N;)t*=t,t%=s;return t}function Mn(e,n){if(e===N)throw new Error("invert: expected non-zero number");if(n<=N)throw new Error("invert: expected positive modulus, got "+n);let s=V(e,n),t=n,r=N,i=D;for(;s!==N;){const l=t/s,a=t%s,d=r-i*l;t=s,s=a,r=i,i=d}if(t!==D)throw new Error("invert: does not exist");return V(r,n)}function mn(e,n,s){if(!e.eql(e.sqr(n),s))throw new Error("Cannot find square root")}function ut(e,n){const s=(e.ORDER+D)/at,t=e.pow(n,s);return mn(e,t,n),t}function Fs(e,n){const s=(e.ORDER-lt)/dt,t=e.mul(n,ie),r=e.pow(t,s),i=e.mul(n,r),o=e.mul(e.mul(i,ie),r),l=e.mul(i,e.sub(o,e.ONE));return mn(e,l,n),l}function Gs(e){const n=De(e),s=pt(e),t=s(n,n.neg(n.ONE)),r=s(n,t),i=s(n,n.neg(t)),o=(e+$s)/ct;return(l,a)=>{let d=l.pow(a,o),h=l.mul(d,t);const u=l.mul(d,r),f=l.mul(d,i),g=l.eql(l.sqr(h),a),b=l.eql(l.sqr(u),a);d=l.cmov(d,h,g),h=l.cmov(f,u,b);const E=l.eql(l.sqr(h),a),j=l.cmov(d,h,E);return mn(l,j,a),j}}function pt(e){if(e<ot)throw new Error("sqrt is not defined for small field");let n=e-D,s=0;for(;n%ie===N;)n/=ie,s++;let t=ie;const r=De(e);for(;Pn(r,t)===1;)if(t++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(s===1)return ut;let i=r.pow(t,n);const o=(n+D)/ie;return function(a,d){if(a.is0(d))return d;if(Pn(a,d)!==1)throw new Error("Cannot find square root");let h=s,u=a.mul(a.ONE,i),f=a.pow(d,n),g=a.pow(d,o);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let b=1,E=a.sqr(f);for(;!a.eql(E,a.ONE);)if(b++,E=a.sqr(E),b===h)throw new Error("Cannot find square root");const j=D<<BigInt(h-b-1),O=a.pow(u,j);h=b,u=a.sqr(O),f=a.mul(f,u),g=a.mul(g,O)}return g}}function Ws(e){return e%at===ot?ut:e%dt===lt?Fs:e%ct===Ls?Gs(e):pt(e)}const Vs=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Qs(e){const n={ORDER:"bigint",BYTES:"number",BITS:"number"},s=Vs.reduce((t,r)=>(t[r]="function",t),n);return it(e,s),e}function zs(e,n,s){if(s<N)throw new Error("invalid exponent, negatives unsupported");if(s===N)return e.ONE;if(s===D)return n;let t=e.ONE,r=n;for(;s>N;)s&D&&(t=e.mul(t,r)),r=e.sqr(r),s>>=D;return t}function ft(e,n,s=!1){const t=new Array(n.length).fill(s?e.ZERO:void 0),r=n.reduce((o,l,a)=>e.is0(l)?o:(t[a]=o,e.mul(o,l)),e.ONE),i=e.inv(r);return n.reduceRight((o,l,a)=>e.is0(l)?o:(t[a]=e.mul(o,t[a]),e.mul(o,l)),i),t}function Pn(e,n){const s=(e.ORDER-D)/ie,t=e.pow(n,s),r=e.eql(t,e.ONE),i=e.eql(t,e.ZERO),o=e.eql(t,e.neg(e.ONE));if(!r&&!i&&!o)throw new Error("invalid Legendre symbol result");return r?1:i?0:-1}function Ks(e,n){n!==void 0&&cn(n);const s=n!==void 0?n:e.toString(2).length,t=Math.ceil(s/8);return{nBitLength:s,nByteLength:t}}class Zs{ORDER;BITS;BYTES;isLE;ZERO=N;ONE=D;_lengths;_sqrt;_mod;constructor(n,s={}){if(n<=N)throw new Error("invalid field: expected ORDER > 0, got "+n);let t;this.isLE=!1,s!=null&&typeof s=="object"&&(typeof s.BITS=="number"&&(t=s.BITS),typeof s.sqrt=="function"&&(this.sqrt=s.sqrt),typeof s.isLE=="boolean"&&(this.isLE=s.isLE),s.allowedLengths&&(this._lengths=s.allowedLengths?.slice()),typeof s.modFromBytes=="boolean"&&(this._mod=s.modFromBytes));const{nBitLength:r,nByteLength:i}=Ks(n,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=n,this.BITS=r,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(n){return V(n,this.ORDER)}isValid(n){if(typeof n!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof n);return N<=n&&n<this.ORDER}is0(n){return n===N}isValidNot0(n){return!this.is0(n)&&this.isValid(n)}isOdd(n){return(n&D)===D}neg(n){return V(-n,this.ORDER)}eql(n,s){return n===s}sqr(n){return V(n*n,this.ORDER)}add(n,s){return V(n+s,this.ORDER)}sub(n,s){return V(n-s,this.ORDER)}mul(n,s){return V(n*s,this.ORDER)}pow(n,s){return zs(this,n,s)}div(n,s){return V(n*Mn(s,this.ORDER),this.ORDER)}sqrN(n){return n*n}addN(n,s){return n+s}subN(n,s){return n-s}mulN(n,s){return n*s}inv(n){return Mn(n,this.ORDER)}sqrt(n){return this._sqrt||(this._sqrt=Ws(this.ORDER)),this._sqrt(this,n)}toBytes(n){return this.isLE?st(n,this.BYTES):fn(n,this.BYTES)}fromBytes(n,s=!1){$(n);const{_lengths:t,BYTES:r,isLE:i,ORDER:o,_mod:l}=this;if(t){if(!t.includes(n.length)||n.length>r)throw new Error("Field.fromBytes: expected "+t+" bytes, got "+n.length);const d=new Uint8Array(r);d.set(n,i?0:d.length-n.length),n=d}if(n.length!==r)throw new Error("Field.fromBytes: expected "+r+" bytes, got "+n.length);let a=i?tt(n):pn(n);if(l&&(a=V(a,o)),!s&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(n){return ft(this,n)}cmov(n,s,t){return t?s:n}}function De(e,n={}){return new Zs(e,n)}function mt(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const n=e.toString(2).length;return Math.ceil(n/8)}function Ys(e){const n=mt(e);return n+Math.ceil(n/2)}function Xs(e,n,s=!1){$(e);const t=e.length,r=mt(n),i=Ys(n);if(t<16||t<i||t>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+t);const o=s?tt(e):pn(e),l=V(o,n-D)+D;return s?st(l,r):fn(l,r)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ue=BigInt(0),oe=BigInt(1);function je(e,n){const s=n.negate();return e?s:n}function An(e,n){const s=ft(e.Fp,n.map(t=>t.Z));return n.map((t,r)=>e.fromAffine(t.toAffine(s[r])))}function gt(e,n){if(!Number.isSafeInteger(e)||e<=0||e>n)throw new Error("invalid window size, expected [1.."+n+"], got W="+e)}function Ve(e,n){gt(e,n);const s=Math.ceil(n/e)+1,t=2**(e-1),r=2**e,i=rt(e),o=BigInt(e);return{windows:s,windowSize:t,mask:i,maxNumber:r,shiftBy:o}}function jn(e,n,s){const{windowSize:t,mask:r,maxNumber:i,shiftBy:o}=s;let l=Number(e&r),a=e>>o;l>t&&(l-=i,a+=oe);const d=n*t,h=d+Math.abs(l)-1,u=l===0,f=l<0,g=n%2!==0;return{nextN:a,offset:h,isZero:u,isNeg:f,isNegF:g,offsetF:d}}const Qe=new WeakMap,ht=new WeakMap;function ze(e){return ht.get(e)||1}function On(e){if(e!==ue)throw new Error("invalid wNAF")}class Js{BASE;ZERO;Fn;bits;constructor(n,s){this.BASE=n.BASE,this.ZERO=n.ZERO,this.Fn=n.Fn,this.bits=s}_unsafeLadder(n,s,t=this.ZERO){let r=n;for(;s>ue;)s&oe&&(t=t.add(r)),r=r.double(),s>>=oe;return t}precomputeWindow(n,s){const{windows:t,windowSize:r}=Ve(s,this.bits),i=[];let o=n,l=o;for(let a=0;a<t;a++){l=o,i.push(l);for(let d=1;d<r;d++)l=l.add(o),i.push(l);o=l.double()}return i}wNAF(n,s,t){if(!this.Fn.isValid(t))throw new Error("invalid scalar");let r=this.ZERO,i=this.BASE;const o=Ve(n,this.bits);for(let l=0;l<o.windows;l++){const{nextN:a,offset:d,isZero:h,isNeg:u,isNegF:f,offsetF:g}=jn(t,l,o);t=a,h?i=i.add(je(f,s[g])):r=r.add(je(u,s[d]))}return On(t),{p:r,f:i}}wNAFUnsafe(n,s,t,r=this.ZERO){const i=Ve(n,this.bits);for(let o=0;o<i.windows&&t!==ue;o++){const{nextN:l,offset:a,isZero:d,isNeg:h}=jn(t,o,i);if(t=l,!d){const u=s[a];r=r.add(h?u.negate():u)}}return On(t),r}getPrecomputes(n,s,t){let r=Qe.get(s);return r||(r=this.precomputeWindow(s,n),n!==1&&(typeof t=="function"&&(r=t(r)),Qe.set(s,r))),r}cached(n,s,t){const r=ze(n);return this.wNAF(r,this.getPrecomputes(r,n,t),s)}unsafe(n,s,t,r){const i=ze(n);return i===1?this._unsafeLadder(n,s,r):this.wNAFUnsafe(i,this.getPrecomputes(i,n,t),s,r)}createCache(n,s){gt(s,this.bits),ht.set(n,s),Qe.delete(n)}hasCache(n){return ze(n)!==1}}function er(e,n,s,t){let r=n,i=e.ZERO,o=e.ZERO;for(;s>ue||t>ue;)s&oe&&(i=i.add(r)),t&oe&&(o=o.add(r)),r=r.double(),s>>=oe,t>>=oe;return{p1:i,p2:o}}function qn(e,n,s){if(n){if(n.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Qs(n),n}else return De(e,{isLE:s})}function nr(e,n,s={},t){if(t===void 0&&(t=e==="edwards"),!n||typeof n!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const d=n[a];if(!(typeof d=="bigint"&&d>ue))throw new Error(`CURVE.${a} must be positive bigint`)}const r=qn(n.p,s.Fp,t),i=qn(n.n,s.Fn,t),l=["Gx","Gy","a","b"];for(const a of l)if(!r.isValid(n[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return n=Object.freeze(Object.assign({},n)),{CURVE:n,Fp:r,Fn:i}}function tr(e,n){return function(t){const r=e(t);return{secretKey:r,publicKey:n(r)}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Cn=(e,n)=>(e+(e>=0?n:-n)/rr)/n;function sr(e,n,s){const[[t,r],[i,o]]=n,l=Cn(o*e,s),a=Cn(-r*e,s);let d=e-l*t-a*i,h=-l*r-a*o;const u=d<ge,f=h<ge;u&&(d=-d),f&&(h=-h);const g=rt(Math.ceil(Ns(s)/2))+Ue;if(d<ge||d>=g||h<ge||h>=g)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:u,k1:d,k2neg:f,k2:h}}const ge=BigInt(0),Ue=BigInt(1),rr=BigInt(2),Ie=BigInt(3),ir=BigInt(4);function or(e,n={}){const s=nr("weierstrass",e,n),{Fp:t,Fn:r}=s;let i=s.CURVE;const{h:o,n:l}=i;it(n,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:a}=n;if(a&&(!t.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const d=lr(t,r);function h(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(k,m,y){const{x:w,y:S}=m.toAffine(),x=t.toBytes(w);if(xn(y,"isCompressed"),y){h();const R=!t.isOdd(S);return Me(ar(R),x)}else return Me(Uint8Array.of(4),x,t.toBytes(S))}function f(k){$(k,void 0,"Point");const{publicKey:m,publicKeyUncompressed:y}=d,w=k.length,S=k[0],x=k.subarray(1);if(w===m&&(S===2||S===3)){const R=t.fromBytes(x);if(!t.isValid(R))throw new Error("bad point: is not on curve, wrong x");const _=E(R);let v;try{v=t.sqrt(_)}catch(L){const q=L instanceof Error?": "+L.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}h();const T=t.isOdd(v);return(S&1)===1!==T&&(v=t.neg(v)),{x:R,y:v}}else if(w===y&&S===4){const R=t.BYTES,_=t.fromBytes(x.subarray(0,R)),v=t.fromBytes(x.subarray(R,R*2));if(!j(_,v))throw new Error("bad point: is not on curve");return{x:_,y:v}}else throw new Error(`bad point: got length ${w}, expected compressed=${m} or uncompressed=${y}`)}const g=n.toBytes||u,b=n.fromBytes||f;function E(k){const m=t.sqr(k),y=t.mul(m,k);return t.add(t.add(y,t.mul(k,i.a)),i.b)}function j(k,m){const y=t.sqr(m),w=E(k);return t.eql(y,w)}if(!j(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const O=t.mul(t.pow(i.a,Ie),ir),Q=t.mul(t.sqr(i.b),BigInt(27));if(t.is0(t.add(O,Q)))throw new Error("bad curve params: a or b");function J(k,m,y=!1){if(!t.isValid(m)||y&&t.is0(m))throw new Error(`bad point coordinate ${k}`);return m}function we(k){if(!(k instanceof M))throw new Error("Weierstrass Point expected")}function Ee(k){if(!a||!a.basises)throw new Error("no endo");return sr(k,a.basises,r.ORDER)}const Se=Un((k,m)=>{const{X:y,Y:w,Z:S}=k;if(t.eql(S,t.ONE))return{x:y,y:w};const x=k.is0();m==null&&(m=x?t.ONE:t.inv(S));const R=t.mul(y,m),_=t.mul(w,m),v=t.mul(S,m);if(x)return{x:t.ZERO,y:t.ZERO};if(!t.eql(v,t.ONE))throw new Error("invZ was invalid");return{x:R,y:_}}),Tt=Un(k=>{if(k.is0()){if(n.allowInfinityPoint&&!t.is0(k.Y))return;throw new Error("bad point: ZERO")}const{x:m,y}=k.toAffine();if(!t.isValid(m)||!t.isValid(y))throw new Error("bad point: x or y not field elements");if(!j(m,y))throw new Error("bad point: equation left != right");if(!k.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function yn(k,m,y,w,S){return y=new M(t.mul(y.X,k),y.Y,y.Z),m=je(w,m),y=je(S,y),m.add(y)}class M{static BASE=new M(i.Gx,i.Gy,t.ONE);static ZERO=new M(t.ZERO,t.ONE,t.ZERO);static Fp=t;static Fn=r;X;Y;Z;constructor(m,y,w){this.X=J("x",m),this.Y=J("y",y,!0),this.Z=J("z",w),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){const{x:y,y:w}=m||{};if(!m||!t.isValid(y)||!t.isValid(w))throw new Error("invalid affine point");if(m instanceof M)throw new Error("projective point not allowed");return t.is0(y)&&t.is0(w)?M.ZERO:new M(y,w,t.ONE)}static fromBytes(m){const y=M.fromAffine(b($(m,void 0,"point")));return y.assertValidity(),y}static fromHex(m){return M.fromBytes(Y(m))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return fe.createCache(this,m),y||this.multiply(Ie),this}assertValidity(){Tt(this)}hasEvenY(){const{y:m}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(m)}equals(m){we(m);const{X:y,Y:w,Z:S}=this,{X:x,Y:R,Z:_}=m,v=t.eql(t.mul(y,_),t.mul(x,S)),T=t.eql(t.mul(w,_),t.mul(R,S));return v&&T}negate(){return new M(this.X,t.neg(this.Y),this.Z)}double(){const{a:m,b:y}=i,w=t.mul(y,Ie),{X:S,Y:x,Z:R}=this;let _=t.ZERO,v=t.ZERO,T=t.ZERO,I=t.mul(S,S),L=t.mul(x,x),q=t.mul(R,R),U=t.mul(S,x);return U=t.add(U,U),T=t.mul(S,R),T=t.add(T,T),_=t.mul(m,T),v=t.mul(w,q),v=t.add(_,v),_=t.sub(L,v),v=t.add(L,v),v=t.mul(_,v),_=t.mul(U,_),T=t.mul(w,T),q=t.mul(m,q),U=t.sub(I,q),U=t.mul(m,U),U=t.add(U,T),T=t.add(I,I),I=t.add(T,I),I=t.add(I,q),I=t.mul(I,U),v=t.add(v,I),q=t.mul(x,R),q=t.add(q,q),I=t.mul(q,U),_=t.sub(_,I),T=t.mul(q,L),T=t.add(T,T),T=t.add(T,T),new M(_,v,T)}add(m){we(m);const{X:y,Y:w,Z:S}=this,{X:x,Y:R,Z:_}=m;let v=t.ZERO,T=t.ZERO,I=t.ZERO;const L=i.a,q=t.mul(i.b,Ie);let U=t.mul(y,x),G=t.mul(w,R),W=t.mul(S,_),ae=t.add(y,w),B=t.add(x,R);ae=t.mul(ae,B),B=t.add(U,G),ae=t.sub(ae,B),B=t.add(y,S);let z=t.add(x,_);return B=t.mul(B,z),z=t.add(U,W),B=t.sub(B,z),z=t.add(w,S),v=t.add(R,_),z=t.mul(z,v),v=t.add(G,W),z=t.sub(z,v),I=t.mul(L,B),v=t.mul(q,W),I=t.add(v,I),v=t.sub(G,I),I=t.add(G,I),T=t.mul(v,I),G=t.add(U,U),G=t.add(G,U),W=t.mul(L,W),B=t.mul(q,B),G=t.add(G,W),W=t.sub(U,W),W=t.mul(L,W),B=t.add(B,W),U=t.mul(G,B),T=t.add(T,U),U=t.mul(z,B),v=t.mul(ae,v),v=t.sub(v,U),U=t.mul(ae,G),I=t.mul(z,I),I=t.add(I,U),new M(v,T,I)}subtract(m){return this.add(m.negate())}is0(){return this.equals(M.ZERO)}multiply(m){const{endo:y}=n;if(!r.isValidNot0(m))throw new Error("invalid scalar: out of range");let w,S;const x=R=>fe.cached(this,R,_=>An(M,_));if(y){const{k1neg:R,k1:_,k2neg:v,k2:T}=Ee(m),{p:I,f:L}=x(_),{p:q,f:U}=x(T);S=L.add(U),w=yn(y.beta,I,q,R,v)}else{const{p:R,f:_}=x(m);w=R,S=_}return An(M,[w,S])[0]}multiplyUnsafe(m){const{endo:y}=n,w=this;if(!r.isValid(m))throw new Error("invalid scalar: out of range");if(m===ge||w.is0())return M.ZERO;if(m===Ue)return w;if(fe.hasCache(this))return this.multiply(m);if(y){const{k1neg:S,k1:x,k2neg:R,k2:_}=Ee(m),{p1:v,p2:T}=er(M,w,x,_);return yn(y.beta,v,T,S,R)}else return fe.unsafe(w,m)}toAffine(m){return Se(this,m)}isTorsionFree(){const{isTorsionFree:m}=n;return o===Ue?!0:m?m(M,this):fe.unsafe(this,l).is0()}clearCofactor(){const{clearCofactor:m}=n;return o===Ue?this:m?m(M,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(m=!0){return xn(m,"isCompressed"),this.assertValidity(),g(M,this,m)}toHex(m=!0){return C(this.toBytes(m))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const bn=r.BITS,fe=new Js(M,n.endo?Math.ceil(bn/2):bn);return M.BASE.precompute(8),M}function ar(e){return Uint8Array.of(e?2:3)}function lr(e,n){return{secretKey:n.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*n.BYTES}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ne={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},dr={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},cr=BigInt(0),rn=BigInt(2);function ur(e){const n=Ne.p,s=BigInt(3),t=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),l=BigInt(44),a=BigInt(88),d=e*e*e%n,h=d*d*e%n,u=F(h,s,n)*h%n,f=F(u,s,n)*h%n,g=F(f,rn,n)*d%n,b=F(g,r,n)*g%n,E=F(b,i,n)*b%n,j=F(E,l,n)*E%n,O=F(j,a,n)*j%n,Q=F(O,l,n)*E%n,J=F(Q,s,n)*h%n,we=F(J,o,n)*b%n,Ee=F(we,t,n)*d%n,Se=F(Ee,rn,n);if(!Oe.eql(Oe.sqr(Se),e))throw new Error("Cannot find square root");return Se}const Oe=De(Ne.p,{sqrt:ur}),pe=or(Ne,{Fp:Oe,endo:dr}),Hn={};function qe(e,...n){let s=Hn[e];if(s===void 0){const t=Ae(Bs(e));s=Me(t,t),Hn[e]=s}return Ae(Me(s,...n))}const gn=e=>e.toBytes(!0).slice(1),hn=e=>e%rn===cr;function on(e){const{Fn:n,BASE:s}=pe,t=n.fromBytes(e),r=s.multiply(t);return{scalar:hn(r.y)?t:n.neg(t),bytes:gn(r)}}function yt(e){const n=Oe;if(!n.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const s=n.create(e*e),t=n.create(s*e+BigInt(7));let r=n.sqrt(t);hn(r)||(r=n.neg(r));const i=pe.fromAffine({x:e,y:r});return i.assertValidity(),i}const ye=pn;function bt(...e){return pe.Fn.create(ye(qe("BIP0340/challenge",...e)))}function Bn(e){return on(e).bytes}function pr(e,n,s=zn(32)){const{Fn:t}=pe,r=$(e,void 0,"message"),{bytes:i,scalar:o}=on(n),l=$(s,32,"auxRand"),a=t.toBytes(o^ye(qe("BIP0340/aux",l))),d=qe("BIP0340/nonce",a,i,r),{bytes:h,scalar:u}=on(d),f=bt(h,i,r),g=new Uint8Array(64);if(g.set(h,0),g.set(t.toBytes(t.create(u+f*o)),32),!vt(g,r,i))throw new Error("sign: Invalid signature produced");return g}function vt(e,n,s){const{Fp:t,Fn:r,BASE:i}=pe,o=$(e,64,"signature"),l=$(n,void 0,"message"),a=$(s,32,"publicKey");try{const d=yt(ye(a)),h=ye(o.subarray(0,32));if(!t.isValidNot0(h))return!1;const u=ye(o.subarray(32,64));if(!r.isValidNot0(u))return!1;const f=bt(r.toBytes(h),gn(d),l),g=i.multiplyUnsafe(u).add(d.multiplyUnsafe(r.neg(f))),{x:b,y:E}=g.toAffine();return!(g.is0()||!hn(E)||b!==h)}catch{return!1}}const Z=(()=>{const s=(t=zn(48))=>Xs(t,Ne.n);return{keygen:tr(s,Bn),getPublicKey:Bn,sign:pr,verify:vt,Point:pe,utils:{randomSecretKey:s,taggedHash:qe,lift_x:yt,pointToBytes:gn},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var re=Symbol("verified"),fr=e=>e instanceof Object;function mr(e){if(!fr(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let n=0;n<e.tags.length;n++){let s=e.tags[n];if(!Array.isArray(s))return!1;for(let t=0;t<s.length;t++)if(typeof s[t]!="string")return!1}return!0}new TextDecoder("utf-8");var gr=new TextEncoder;function he(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let n=new URL(e);return n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),n.pathname=n.pathname.replace(/\/+/g,"/"),n.pathname.endsWith("/")&&(n.pathname=n.pathname.slice(0,-1)),(n.port==="80"&&n.protocol==="ws:"||n.port==="443"&&n.protocol==="wss:")&&(n.port=""),n.searchParams.sort(),n.hash="",n.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}var hr=class{generateSecretKey(){return Z.utils.randomSecretKey()}getPublicKey(n){return C(Z.getPublicKey(n))}finalizeEvent(n,s){const t=n;return t.pubkey=C(Z.getPublicKey(s)),t.id=Ke(t),t.sig=C(Z.sign(Y(Ke(t)),s)),t[re]=!0,t}verifyEvent(n){if(typeof n[re]=="boolean")return n[re];try{const s=Ke(n);if(s!==n.id)return n[re]=!1,!1;const t=Z.verify(Y(n.sig),Y(s),Y(n.pubkey));return n[re]=t,t}catch{return n[re]=!1,!1}}};function yr(e){if(!mr(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function Ke(e){let n=Ae(gr.encode(yr(e)));return C(n)}var $e=new hr;$e.generateSecretKey;$e.getPublicKey;$e.finalizeEvent;var br=$e.verifyEvent,vr=22242;function wr(e,n){if(e.ids&&e.ids.indexOf(n.id)===-1||e.kinds&&e.kinds.indexOf(n.kind)===-1||e.authors&&e.authors.indexOf(n.pubkey)===-1)return!1;for(let s in e)if(s[0]==="#"){let t=s.slice(1),r=e[`#${t}`];if(r&&!n.tags.find(([i,o])=>i===s.slice(1)&&r.indexOf(o)!==-1))return!1}return!(e.since&&n.created_at<e.since||e.until&&n.created_at>e.until)}function Er(e,n){for(let s=0;s<e.length;s++)if(wr(e[s],n))return!0;return!1}function Sr(e,n){let s=n.length+3,t=e.indexOf(`"${n}":`)+s,r=e.slice(t).indexOf('"')+t+1;return e.slice(r,r+64)}function _r(e){let n=e.slice(0,22).indexOf('"EVENT"');if(n===-1)return null;let s=e.slice(n+7+1).indexOf('"');if(s===-1)return null;let t=n+7+1+s,r=e.slice(t+1,80).indexOf('"');if(r===-1)return null;let i=t+1+r;return e.slice(t+1,i)}function Tr(e,n){return{kind:vr,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",n]],content:""}}var wt=class extends Error{constructor(e,n){super(`Tried to send message '${e} on a closed connection to ${n}.`),this.name="SendingOnClosedConnection"}},Et=class{url;_connected=!1;onclose=null;onnotice=e=>console.debug(`NOTICE from ${this.url}: ${e}`);onauth;baseEoseTimeout=4400;publishTimeout=4400;pingFrequency=29e3;pingTimeout=2e4;resubscribeBackoff=[1e4,1e4,1e4,2e4,2e4,3e4,6e4];openSubs=new Map;enablePing;enableReconnect;idleSince=Date.now();ongoingOperations=0;reconnectTimeoutHandle;pingIntervalHandle;reconnectAttempts=0;skipReconnection=!1;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,n){this.url=he(e),this.verifyEvent=n.verifyEvent,this._WebSocket=n.websocketImplementation||WebSocket,this.enablePing=n.enablePing,this.enableReconnect=n.enableReconnect||!1}static async connect(e,n){const s=new Et(e,n);return await s.connect(n),s}closeAllSubscriptions(e){for(let[n,s]of this.openSubs)s.close(e);this.openSubs.clear();for(let[n,s]of this.openEventPublishes)s.reject(new Error(e));this.openEventPublishes.clear();for(let[n,s]of this.openCountRequests)s.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},e)}handleHardClose(e){this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0,this.idleSince=void 0,this.enableReconnect&&!this.skipReconnection?this.reconnect():(this.onclose?.(),this.closeAllSubscriptions(e))}async connect(e){let n;return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.skipReconnection=!1,this.connectionPromise=new Promise((s,t)=>{e?.timeout&&(n=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection timed out")},e.timeout)),e?.abort&&(e.abort.onabort=t);try{this.ws=new this._WebSocket(this.url)}catch(r){clearTimeout(n),t(r);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(n),this._connected=!0;const r=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const i of this.openSubs.values()){if(i.eosed=!1,r)for(let o=0;o<i.filters.length;o++)i.lastEmitted&&(i.filters[o].since=i.lastEmitted+1);i.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),s()},this.ws.onerror=()=>{clearTimeout(n),t("connection failed"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection failed")},this.ws.onclose=r=>{clearTimeout(n),t(r.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,n)=>{if(!this.connectionPromise)return n(new Error(`no connection to ${this.url}, can't ping`));try{const s=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"<forced-ping>",oneose:()=>{e(!0),s.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(s){n(s)}})}async pingpong(){this.ws?.readyState===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(n=>setTimeout(()=>n(!1),this.pingTimeout))])||this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close())}async send(e){if(!this.connectionPromise)throw new wt(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const n=this.challenge;if(!n)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(s,t)=>{try{let r=await e(Tr(this.url,n)),i=setTimeout(()=>{let o=this.openEventPublishes.get(r.id);o&&(o.reject(new Error("auth timed out")),this.openEventPublishes.delete(r.id))},this.publishTimeout);this.openEventPublishes.set(r.id,{resolve:s,reject:t,timeout:i}),this.send('["AUTH",'+JSON.stringify(r)+"]")}catch(r){console.warn("subscribe auth function failed:",r)}}),this.authPromise)}async publish(e){this.idleSince=void 0,this.ongoingOperations++;const n=new Promise((s,t)=>{const r=setTimeout(()=>{const i=this.openEventPublishes.get(e.id);i&&(i.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:s,reject:t,timeout:r})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),this.ongoingOperations--,this.ongoingOperations===0&&(this.idleSince=Date.now()),n}async count(e,n){this.serial++;const s=n?.id||"count:"+this.serial,t=new Promise((r,i)=>{this.openCountRequests.set(s,{resolve:r,reject:i})});return this.send('["COUNT","'+s+'",'+JSON.stringify(e).substring(1)),t}subscribe(e,n){n.label!=="<forced-ping>"&&(this.idleSince=void 0,this.ongoingOperations++);const s=this.prepareSubscription(e,n);return s.fire(),n.abort&&(n.abort.onabort=()=>s.close(String(n.abort.reason||"<aborted>"))),s}prepareSubscription(e,n){this.serial++;const s=n.id||(n.label?n.label+":":"sub:")+this.serial,t=new Rr(this,s,e,n);return this.openSubs.set(s,t),t}close(){this.skipReconnection=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.idleSince=void 0,this.onclose?.(),this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close()}_onmessage(e){const n=e.data;if(!n)return;const s=_r(n);if(s){const t=this.openSubs.get(s);if(!t)return;const r=Sr(n,"id"),i=t.alreadyHaveEvent?.(r);if(t.receivedEvent?.(this,r),i)return}try{let t=JSON.parse(n);switch(t[0]){case"EVENT":{const r=this.openSubs.get(t[1]),i=t[2];this.verifyEvent(i)&&Er(r.filters,i)?r.onevent(i):r.oninvalidevent?.(i),(!r.lastEmitted||r.lastEmitted<i.created_at)&&(r.lastEmitted=i.created_at);return}case"COUNT":{const r=t[1],i=t[2],o=this.openCountRequests.get(r);o&&(o.resolve(i.count),this.openCountRequests.delete(r));return}case"EOSE":{const r=this.openSubs.get(t[1]);if(!r)return;r.receivedEose();return}case"OK":{const r=t[1],i=t[2],o=t[3],l=this.openEventPublishes.get(r);l&&(clearTimeout(l.timeout),i?l.resolve(o):l.reject(new Error(o)),this.openEventPublishes.delete(r));return}case"CLOSED":{const r=t[1],i=this.openSubs.get(r);if(!i)return;i.closed=!0,i.close(t[2]);return}case"NOTICE":{this.onnotice(t[1]);return}case"AUTH":{this.challenge=t[1],this.onauth&&this.auth(this.onauth);return}default:{this.openSubs.get(t[1])?.oncustom?.(t);return}}}catch(t){try{const[r,i,o]=JSON.parse(n);console.warn(`[nostr] relay ${this.url} error processing message:`,t,o)}catch{console.warn(`[nostr] relay ${this.url} error processing message:`,t)}return}}},Rr=class{relay;id;lastEmitted;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oninvalidevent;oneose;onclose;oncustom;eoseTimeout;eoseTimeoutHandle;constructor(e,n,s,t){if(s.length===0)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=s,this.id=n,this.alreadyHaveEvent=t.alreadyHaveEvent,this.receivedEvent=t.receivedEvent,this.eoseTimeout=t.eoseTimeout||e.baseEoseTimeout,this.oneose=t.oneose,this.onclose=t.onclose,this.oninvalidevent=t.oninvalidevent,this.onevent=t.onevent||(r=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,r)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(n){if(!(n instanceof wt))throw n}this.closed=!0}this.relay.openSubs.delete(this.id),this.relay.ongoingOperations--,this.relay.ongoingOperations===0&&(this.relay.idleSince=Date.now()),this.onclose?.(e)}},Ir=e=>(e[re]=!0,!0),kr=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;enableReconnect;automaticallyAuth;trustedRelayURLs=new Set;onRelayConnectionFailure;onRelayConnectionSuccess;allowConnectingToRelay;maxWaitForConnection;_WebSocket;constructor(e){this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth,this.onRelayConnectionFailure=e.onRelayConnectionFailure,this.onRelayConnectionSuccess=e.onRelayConnectionSuccess,this.allowConnectingToRelay=e.allowConnectingToRelay,this.maxWaitForConnection=e.maxWaitForConnection||3e3}async ensureRelay(e,n){e=he(e);let s=this.relays.get(e);if(s||(s=new Et(e,{verifyEvent:this.trustedRelayURLs.has(e)?Ir:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),s.onclose=()=>{this.relays.delete(e)},this.relays.set(e,s)),this.automaticallyAuth){const t=this.automaticallyAuth(e);t&&(s.onauth=t)}try{await s.connect({timeout:n?.connectionTimeout,abort:n?.abort})}catch(t){throw this.relays.delete(e),t}return s}close(e){e.map(he).forEach(n=>{this.relays.get(n)?.close(),this.relays.delete(n)})}subscribe(e,n,s){const t=[],r=[];for(let i=0;i<e.length;i++){const o=he(e[i]);t.find(l=>l.url===o)||r.indexOf(o)===-1&&(r.push(o),t.push({url:o,filter:n}))}return this.subscribeMap(t,s)}subscribeMany(e,n,s){return this.subscribe(e,n,s)}subscribeMap(e,n){const s=new Map;for(const f of e){const{url:g,filter:b}=f;s.has(g)||s.set(g,[]),s.get(g).push(b)}const t=Array.from(s.entries()).map(([f,g])=>({url:f,filters:g}));this.trackRelays&&(n.receivedEvent=(f,g)=>{let b=this.seenOn.get(g);b||(b=new Set,this.seenOn.set(g,b)),b.add(f)});const r=new Set,i=[],o=[];let l=f=>{o[f]||(o[f]=!0,o.filter(g=>g).length===t.length&&(n.oneose?.(),l=()=>{}))};const a=[];let d=(f,g)=>{a[f]||(l(f),a[f]=g,a.filter(b=>b).length===t.length&&(n.onclose?.(a),d=()=>{}))};const h=f=>{if(n.alreadyHaveEvent?.(f))return!0;const g=r.has(f);return r.add(f),g},u=Promise.all(t.map(async({url:f,filters:g},b)=>{if(this.allowConnectingToRelay?.(f,["read",g])===!1){d(b,"connection skipped by allowConnectingToRelay");return}let E;try{E=await this.ensureRelay(f,{connectionTimeout:this.maxWaitForConnection<(n.maxWait||0)?Math.max(n.maxWait*.8,n.maxWait-1e3):this.maxWaitForConnection,abort:n.abort})}catch(O){this.onRelayConnectionFailure?.(f),d(b,O?.message||String(O));return}this.onRelayConnectionSuccess?.(f);let j=E.subscribe(g,{...n,oneose:()=>l(b),onclose:O=>{O.startsWith("auth-required: ")&&n.onauth?E.auth(n.onauth).then(()=>{E.subscribe(g,{...n,oneose:()=>l(b),onclose:Q=>{d(b,Q)},alreadyHaveEvent:h,eoseTimeout:n.maxWait,abort:n.abort})}).catch(Q=>{d(b,`auth was required and attempted, but failed with: ${Q}`)}):d(b,O)},alreadyHaveEvent:h,eoseTimeout:n.maxWait,abort:n.abort});i.push(j)}));return{async close(f){await u,i.forEach(g=>{g.close(f)})}}}subscribeEose(e,n,s){let t;return t=this.subscribe(e,n,{...s,oneose(){const r="closed automatically on eose";t?t.close(r):s.onclose?.(e.map(i=>r))}}),t}subscribeManyEose(e,n,s){return this.subscribeEose(e,n,s)}async querySync(e,n,s){return new Promise(async t=>{const r=[];this.subscribeEose(e,n,{...s,onevent(i){r.push(i)},onclose(i){t(r)}})})}async get(e,n,s){n.limit=1;const t=await this.querySync(e,n,s);return t.sort((r,i)=>i.created_at-r.created_at),t[0]||null}publish(e,n,s){return e.map(he).map(async(t,r,i)=>{if(i.indexOf(t)!==r)return Promise.reject("duplicate url");if(this.allowConnectingToRelay?.(t,["write",n])===!1)return Promise.reject("connection skipped by allowConnectingToRelay");let o;try{o=await this.ensureRelay(t,{connectionTimeout:this.maxWaitForConnection<(s?.maxWait||0)?Math.max(s.maxWait*.8,s.maxWait-1e3):this.maxWaitForConnection,abort:s?.abort})}catch(l){return this.onRelayConnectionFailure?.(t),"connection failure: "+String(l)}return o.publish(n).catch(async l=>{if(l instanceof Error&&l.message.startsWith("auth-required: ")&&s?.onauth)return await o.auth(s.onauth),o.publish(n);throw l}).then(l=>{if(this.trackRelays){let a=this.seenOn.get(n.id);a||(a=new Set,this.seenOn.set(n.id,a)),a.add(o)}return l})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((n,s)=>e.set(s,n.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}pruneIdleRelays(e=1e4){const n=[];for(const[s,t]of this.relays)t.idleSince&&Date.now()-t.idleSince>=e&&(this.relays.delete(s),n.push(s),t.close());return n}},St;try{St=WebSocket}catch{}var xr=class extends kr{constructor(e){super({verifyEvent:br,websocketImplementation:St,maxWaitForConnection:3e3,...e})}},le=Symbol("verified"),Ur=e=>e instanceof Object;function Mr(e){if(!Ur(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let n=0;n<e.tags.length;n++){let s=e.tags[n];if(!Array.isArray(s))return!1;for(let t=0;t<s.length;t++)if(typeof s[t]!="string")return!1}return!0}new TextDecoder("utf-8");var Pr=new TextEncoder,Ar=class{generateSecretKey(){return Z.utils.randomSecretKey()}getPublicKey(e){return C(Z.getPublicKey(e))}finalizeEvent(e,n){const s=e;return s.pubkey=C(Z.getPublicKey(n)),s.id=Ze(s),s.sig=C(Z.sign(Y(Ze(s)),n)),s[le]=!0,s}verifyEvent(e){if(typeof e[le]=="boolean")return e[le];try{const n=Ze(e);if(n!==e.id)return e[le]=!1,!1;const s=Z.verify(Y(e.sig),Y(n),Y(e.pubkey));return e[le]=s,s}catch{return e[le]=!1,!1}}};function jr(e){if(!Mr(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function Ze(e){let n=Ae(Pr.encode(jr(e)));return C(n)}var Le=new Ar;Le.generateSecretKey;Le.getPublicKey;Le.finalizeEvent;var Or=Le.verifyEvent;const qr=8e3;function Cr(e){return typeof e=="number"&&dn.includes(e)}function Hr(e){try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function Br(e){const n=[];for(const s of e??[])try{const t=new URL(s);if(t.protocol!=="ws:"&&t.protocol!=="wss:")continue;n.push(t.href)}catch{}return[...new Set(n)]}function Dr(e){const n=xs(e.trim());if(n.type!=="nevent"&&n.type!=="naddr")throw new Error("Enter a NIP-19 nevent or naddr for a NIP-5D napplet manifest event");const s=Br(n.data.relays);if(s.length===0)throw new Error("The pointer does not include relay hints; include at least one relay in the nevent/naddr");if(n.type==="nevent"){if(n.data.kind!==void 0&&!Cr(n.data.kind))throw new Error(`nevent points at kind ${n.data.kind}, not a NIP-5D napplet manifest kind`);return{type:"nevent",relays:s,filter:{ids:[n.data.id],kinds:n.data.kind===void 0?[...dn]:[n.data.kind],authors:n.data.author?[n.data.author]:void 0,limit:1}}}if(n.data.kind!==ce)throw new Error(`naddr kind ${n.data.kind} is not the named napplet kind ${ce}`);return{type:"naddr",relays:s,filter:{kinds:[ce],authors:[n.data.pubkey],"#d":[n.data.identifier],limit:1}}}function Nr(e){return{id:e.id,pubkey:e.pubkey,kind:e.kind,tags:e.tags,content:e.content}}async function $r(e){const n=typeof e=="string"?new TextEncoder().encode(e):e,s=new Uint8Array(n.byteLength);s.set(n);const t=await crypto.subtle.digest("SHA-256",s.buffer);return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Lr(e){const n=[];for(const s of e.tags)if(!(s[0]!=="server"||!s[1]))try{const t=new URL(s[1]);(t.protocol==="http:"||t.protocol==="https:")&&n.push(t.href)}catch{}return[...new Set(n)]}function Fr(e,n){const s=e.endsWith("/")?e:`${e}/`;return new URL(n,s).href}async function Gr(e,n=fetch){const s=Be(e);if(!s.ok)throw new Error(s.errors.map(o=>o.message).join("; "));const t=e.tags.find(o=>o[0]==="x")[1],r=Lr(e);if(r.length===0)throw new Error("Manifest does not include any usable Blossom server hints");const i=[];for(const o of r){const l=Fr(o,t);try{const a=await n(l,{mode:"cors"});if(!a.ok){i.push(`${l}: HTTP ${a.status}`);continue}const d=new Uint8Array(await a.arrayBuffer()),h=await $r(d);if(h!==t){i.push(`${l}: sha256 ${h} did not match manifest ${t}`);continue}return new TextDecoder().decode(d)}catch(a){i.push(`${l}: ${a instanceof Error?a.message:String(a)}`)}}throw new Error(`Unable to fetch verified /index.html from Blossom servers: ${i.join("; ")}`)}async function Wr(e,n){try{const t=await(await n(e,{mode:"cors"})).text();return{source:"url",input:e,label:e,bootUrl:e,html:t,fetched:!0,manifestEvent:null}}catch{return{source:"url",input:e,label:e,bootUrl:e,html:"",fetched:!1,manifestEvent:null}}}async function Vr(e,n){const s=Dr(e),t=!n.pool,r=n.pool??new xr;try{const i=await r.get(s.relays,{...s.filter},{maxWait:n.maxRelayWaitMs??qr});if(!i)throw new Error("No matching napplet manifest event was found on the pointer relay hints");if(!Or(i))throw new Error("Resolved manifest event signature is invalid");const o=Nr(i),l=Be(o);if(!l.ok)throw new Error(`Resolved event is not a valid NIP-5D napplet manifest: ${l.errors[0]?.message}`);const a=await Gr(o,n.fetcher??fetch),d=(n.createObjectUrl??URL.createObjectURL)(new Blob([a],{type:"text/html;charset=utf-8"})),h=()=>(n.revokeObjectUrl??URL.revokeObjectURL)(d);return{source:"nostr",input:e,label:o.id??e,bootUrl:d,html:a,fetched:!0,manifestEvent:o,revoke:h}}finally{t&&r.destroy()}}async function Qr(e,n={}){const s=e.trim();if(!s)throw new Error("Enter a NIP-19 nevent/naddr, or an HTTP URL for local dev");return Hr(s)?Wr(s,n.fetcher??fetch):Vr(s,n)}const zr=`"use strict";
|
|
194
|
+
`;function $r(e,n){const r=`window.parent.postMessage({ type: '${it}', installed: !!window.napplet }, '*');`;return n!==void 0?`${n}
|
|
195
|
+
;globalThis.NappletShimPrelude.install(${JSON.stringify({domains:e})});
|
|
196
|
+
${r}`:Dr+JSON.stringify(e)+Nr+Cr+Br+r+Lr}function Fr(e,n,r,t){const s=`<base href="${Or(n)}">`,i=$r(r,t).replace(/<\/script/gi,"<\\/script"),o=`<script>${Hr()}<\/script><script>${i}<\/script>`,l=/<head(?:\s[^>]*)?>/i.exec(e);if(l){const a=l.index+l[0].length;return`${e.slice(0,a)}${s}${o}${e.slice(a)}`}return`${s}${o}${e}`}function Gr(e){if(!e.startsWith("data:"))return null;const n=e.indexOf(",");if(n<0)return"";const r=e.slice(0,n),t=e.slice(n+1);return r.endsWith(";base64")?atob(t):decodeURIComponent(t)}async function Wr(e){if(e==="about:blank")return"<!doctype html><html><head></head><body></body></html>";const n=Gr(e);if(n!==null)return n;const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch napplet HTML: ${r.status} ${r.statusText}`);return r.text()}async function Un(e,n,r,t){const s=Pr(),i=r.createElement("iframe");i.setAttribute("sandbox",n.allowSameOrigin?"allow-scripts allow-same-origin":"allow-scripts"),i.setAttribute("allow","gamepad 'none'"),i.setAttribute("aria-hidden","true"),i.style.position="absolute",i.style.width="1px",i.style.height="1px",i.style.left="-9999px";let o=null,l=!1;const a=p=>{if(p.source!==i.contentWindow)return;const c=p.data;if(c&&typeof c=="object"&&c.type===it){l=c.installed===!0;return}if(c&&typeof c=="object"&&c.type===st){o=`napplet boot error: ${String(c.reason??"unknown error")}`;return}const m=s.handle(p.data),y=p.source;for(const w of m)y?.postMessage(w,"*")};let d=!1;const h=new Promise(p=>{i.addEventListener("load",()=>{d=!0,p()},{once:!0})});t.addEventListener("message",a);try{const p=n.html??await Wr(n.url);i.srcdoc=Fr(p,n.url,e,n.runtimePreludeSource),(r.body??r.documentElement).appendChild(i)}catch(p){o=p instanceof Error?p.message:String(p)}if(!o){const p=Symbol("timeout");await Promise.race([h.then(()=>"loaded"),Mn(n.readyTimeoutMs).then(()=>p)])===p||!d?o=`napplet did not boot (iframe did not load within ${n.readyTimeoutMs}ms; a conformant napplet must run under sandbox="allow-scripts" without allow-same-origin)`:await Mn(n.settleMs)}t.removeEventListener("message",a);try{i.remove()}catch{}return{installedGlobal:l,bootError:o,emitted:[...s.records]}}async function Vr(e){const n=e.document??document,r=e.window??window,t={url:e.url,html:e.html,readyTimeoutMs:e.readyTimeoutMs??5e3,settleMs:e.settleMs,allowSameOrigin:e.allowSameOrigin??!1,runtimePreludeSource:e.runtimePreludeSource},s=await Un(Le,t,n,r);let i=null;{const o=await Un([],t,n,r);i={bootError:o.bootError,emitted:o.emitted}}return{installedGlobal:s.installedGlobal,bootError:s.bootError,emitted:s.emitted,degraded:i}}var zr=e=>({status:"pass",detail:e}),Qr=(e,n)=>({status:"fail",detail:e,diagnostics:n}),Kr=e=>({status:"skip",detail:e}),A={pass:zr,fail:Qr,skip:Kr};function Zr(e,n){const r=Ge(e.manifestEvent);return[...r.errors,...r.warnings].filter(t=>n.includes(t.code))}function me(e,n,r,t="error"){return{id:e,area:"manifest",severity:t,title:n,run:s=>{if(!s.manifestEvent)return A.skip("No NIP-5D manifest event was resolved");const i=Zr(s,r);return i.length?A.fail(i[0].message,i):A.pass()}}}var Yr=[me("manifest/event-kind","Resolved event is a NIP-5D napplet manifest",["invalid-napplet-kind","missing-d-tag","unexpected-d-tag"]),me("manifest/index-html","Manifest declares a hashed /index.html",["invalid-artifact-hash","missing-description","invalid-metadata"]),me("manifest/requires","R/O tags name bare NAP domains",["invalid-required-nap","invalid-optional-nap"]),me("manifest/requires-known","R/O domains are in this toolchain registry (advisory)",["unknown-required-nap"],"warning"),me("manifest/media-usable","Icon, screenshots, preview and source pins are usable (advisory)",["invalid-icon","invalid-presentation-media","unused-source-commit"],"warning"),{id:"boot/sandbox-allow-scripts",area:"boot",severity:"error",title:"Runs under allow-scripts without allow-same-origin",run:e=>e.sandbox.allowScripts?e.sandbox.allowSameOrigin?A.fail("Napplet relied on allow-same-origin, which a shell must not grant"):A.pass():A.fail("Napplet was not loaded with allow-scripts")},{id:"boot/installs-global",area:"boot",severity:"error",title:"Runs after runtime-injected window.napplet is installed",run:e=>e.installedGlobal?A.pass():A.fail("runtime did not inject window.napplet before load")},{id:"boot/no-boot-error",area:"boot",severity:"error",title:"Boots without an uncaught error",run:e=>e.bootError?A.fail(e.bootError):A.pass()},{id:"boot/no-forbidden-globals",area:"boot",severity:"error",title:"Does not access forbidden browser authority surfaces",run:e=>e.forbiddenGlobals.length?A.fail(`Accessed forbidden surface(s): ${e.forbiddenGlobals.join(", ")}`,e.forbiddenGlobals):A.pass()},{id:"wire/envelope-well-formed",area:"wire",severity:"error",title:"Every emitted envelope is well-formed",run:e=>{if(e.emitted.length===0)return A.skip("Napplet emitted no envelopes");const n=e.emitted.filter(t=>!t.verdict.ok);if(n.length===0)return A.pass(`${e.emitted.length} envelope(s) valid`);const r=n.map(t=>({envelope:t.envelope,errors:t.verdict.errors}));return A.fail(`${n.length}/${e.emitted.length} emitted envelope(s) invalid`,r)}},{id:"degrade/domain-absence",area:"degradation",severity:"error",title:"Does not crash when no NAP domains are injected",run:e=>e.degraded?e.degraded.bootError?A.fail(`Crashed with no injected domains: ${e.degraded.bootError}`):A.pass():A.skip("Host did not run the degraded (no-capabilities) pass")},{id:"lifecycle/clean-teardown",area:"lifecycle",severity:"warning",title:"Tears down listeners on unload",run:e=>e.lifecycle?e.lifecycle.listenerLeak?A.fail("Message listeners remained after unload"):A.pass():A.skip("Lifecycle not measured")}];function Xr(e,n={}){const r=n.now??(()=>Date.now()),t=n.checks??Yr,s=r(),i=t.map(a=>{const d=a.run(e);return{id:a.id,area:a.area,severity:a.severity,title:a.title,status:d.status,detail:d.detail,diagnostics:d.diagnostics}}),o={total:i.length,passed:i.filter(a=>a.status==="pass").length,failed:i.filter(a=>a.status==="fail").length,skipped:i.filter(a=>a.status==="skip").length,errors:i.filter(a=>a.status==="fail"&&a.severity==="error").length,warnings:i.filter(a=>a.status==="fail"&&a.severity==="warning").length};return{napplet:e.manifestEvent?nt(e.manifestEvent):void 0,startedAt:s,finishedAt:r(),checks:i,summary:o,ok:o.errors===0}}function Jr(e,n){const r=s=>e.tags.find(i=>i[0]===s)?.[1],t=e.tags.filter(s=>s[0]==="server").map(s=>s[1]).filter(Boolean);return[["event",e.id],["kind",e.kind],["d",r("d")],["name",nt(e)],["requires",n.requires.join(", ")],["optional",n.optional.join(", ")],["artifact hash (x)",r("x")],["servers",t.join(", ")]]}/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function es(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function hn(e,n=""){if(!Number.isSafeInteger(e)||e<0){const r=n&&`"${n}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function L(e,n,r=""){const t=es(e),s=e?.length,i=n!==void 0;if(!t||i&&s!==n){const o=r&&`"${r}" `,l=i?` of length ${n}`:"",a=t?`length=${s}`:`type=${typeof e}`;throw new Error(o+"expected Uint8Array"+l+", got "+a)}return e}function Pn(e,n=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(n&&e.finished)throw new Error("Hash#digest() has already been called")}function ns(e,n){L(e,void 0,"digestInto() output");const r=n.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function on(...e){for(let n=0;n<e.length;n++)e[n].fill(0)}function Ze(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function K(e,n){return e<<32-n|e>>>n}const ot=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ts=Array.from({length:256},(e,n)=>n.toString(16).padStart(2,"0"));function C(e){if(L(e),ot)return e.toHex();let n="";for(let r=0;r<e.length;r++)n+=ts[e[r]];return n}const X={_0:48,_9:57,A:65,F:70,a:97,f:102};function An(e){if(e>=X._0&&e<=X._9)return e-X._0;if(e>=X.A&&e<=X.F)return e-(X.A-10);if(e>=X.a&&e<=X.f)return e-(X.a-10)}function Y(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ot)return Uint8Array.fromHex(e);const n=e.length,r=n/2;if(n%2)throw new Error("hex string expected, got unpadded hex of length "+n);const t=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){const o=An(e.charCodeAt(i)),l=An(e.charCodeAt(i+1));if(o===void 0||l===void 0){const a=e[i]+e[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}t[s]=o*16+l}return t}function Oe(...e){let n=0;for(let t=0;t<e.length;t++){const s=e[t];L(s),n+=s.length}const r=new Uint8Array(n);for(let t=0,s=0;t<e.length;t++){const i=e[t];r.set(i,s),s+=i.length}return r}function rs(e,n={}){const r=(s,i)=>e(i).update(s).digest(),t=e(void 0);return r.outputLen=t.outputLen,r.blockLen=t.blockLen,r.create=s=>e(s),Object.assign(r,n),Object.freeze(r)}function at(e=32){const n=typeof globalThis=="object"?globalThis.crypto:null;if(typeof n?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return n.getRandomValues(new Uint8Array(e))}const ss=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function lt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function dt(e,n){return Array.isArray(n)?n.length===0?!0:e?n.every(r=>typeof r=="string"):n.every(r=>Number.isSafeInteger(r)):!1}function is(e){if(typeof e!="function")throw new Error("function expected");return!0}function Se(e,n){if(typeof n!="string")throw new Error(`${e}: string expected`);return!0}function ct(e){if(!Number.isSafeInteger(e))throw new Error(`invalid integer: ${e}`)}function an(e){if(!Array.isArray(e))throw new Error("array expected")}function ut(e,n){if(!dt(!0,n))throw new Error(`${e}: array of strings expected`)}function pt(e,n){if(!dt(!1,n))throw new Error(`${e}: array of numbers expected`)}function os(...e){const n=i=>i,r=(i,o)=>l=>i(o(l)),t=e.map(i=>i.encode).reduceRight(r,n),s=e.map(i=>i.decode).reduce(r,n);return{encode:t,decode:s}}function as(e){const n=typeof e=="string"?e.split(""):e,r=n.length;ut("alphabet",n);const t=new Map(n.map((s,i)=>[s,i]));return{encode:s=>(an(s),s.map(i=>{if(!Number.isSafeInteger(i)||i<0||i>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${e}`);return n[i]})),decode:s=>(an(s),s.map(i=>{Se("alphabet.decode",i);const o=t.get(i);if(o===void 0)throw new Error(`Unknown letter: "${i}". Allowed: ${e}`);return o}))}}function ls(e=""){return Se("join",e),{encode:n=>(ut("join.decode",n),n.join(e)),decode:n=>(Se("join.decode",n),n.split(e))}}const ft=(e,n)=>n===0?e:ft(n,e%n),Ce=(e,n)=>e+(n-ft(e,n)),Ae=(()=>{let e=[];for(let n=0;n<40;n++)e.push(2**n);return e})();function ln(e,n,r,t){if(an(e),n<=0||n>32)throw new Error(`convertRadix2: wrong from=${n}`);if(r<=0||r>32)throw new Error(`convertRadix2: wrong to=${r}`);if(Ce(n,r)>32)throw new Error(`convertRadix2: carry overflow from=${n} to=${r} carryBits=${Ce(n,r)}`);let s=0,i=0;const o=Ae[n],l=Ae[r]-1,a=[];for(const d of e){if(ct(d),d>=o)throw new Error(`convertRadix2: invalid data word=${d} from=${n}`);if(s=s<<n|d,i+n>32)throw new Error(`convertRadix2: carry overflow pos=${i} from=${n}`);for(i+=n;i>=r;i-=r)a.push((s>>i-r&l)>>>0);const h=Ae[i];if(h===void 0)throw new Error("invalid carry");s&=h-1}if(s=s<<r-i&l,!t&&i>=n)throw new Error("Excess padding");if(!t&&s>0)throw new Error(`Non-zero padding: ${s}`);return t&&i>0&&a.push(s>>>0),a}function ds(e,n=!1){if(ct(e),e<=0||e>32)throw new Error("radix2: bits should be in (0..32]");if(Ce(8,e)>32||Ce(e,8)>32)throw new Error("radix2: carry overflow");return{encode:r=>{if(!lt(r))throw new Error("radix2.encode input should be Uint8Array");return ln(Array.from(r),8,e,!n)},decode:r=>(pt("radix2.decode",r),Uint8Array.from(ln(r,e,8,n)))}}function jn(e){return is(e),function(...n){try{return e.apply(null,n)}catch{}}}const dn=os(as("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ls("")),qn=[996825010,642813549,513874426,1027748829,705979059];function ge(e){const n=e>>25;let r=(e&33554431)<<5;for(let t=0;t<qn.length;t++)(n>>t&1)===1&&(r^=qn[t]);return r}function On(e,n,r=1){const t=e.length;let s=1;for(let i=0;i<t;i++){const o=e.charCodeAt(i);if(o<33||o>126)throw new Error(`Invalid prefix (${e})`);s=ge(s)^o>>5}s=ge(s);for(let i=0;i<t;i++)s=ge(s)^e.charCodeAt(i)&31;for(let i of n)s=ge(s)^i;for(let i=0;i<6;i++)s=ge(s);return s^=r,dn.encode(ln([s%Ae[30]],30,5,!1))}function cs(e){const n=e==="bech32"?1:734539939,r=ds(5),t=r.decode,s=r.encode,i=jn(t);function o(p,c,m=90){Se("bech32.encode prefix",p),lt(c)&&(c=Array.from(c)),pt("bech32.encode",c);const y=p.length;if(y===0)throw new TypeError(`Invalid prefix length ${y}`);const w=y+7+c.length;if(m!==!1&&w>m)throw new TypeError(`Length ${w} exceeds limit ${m}`);const P=p.toLowerCase(),q=On(P,c,n);return`${P}1${dn.encode(c)}${q}`}function l(p,c=90){Se("bech32.decode input",p);const m=p.length;if(m<8||c!==!1&&m>c)throw new TypeError(`invalid string length: ${m} (${p}). Expected (8..${c})`);const y=p.toLowerCase();if(p!==y&&p!==p.toUpperCase())throw new Error("String must be lowercase or uppercase");const w=y.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const P=y.slice(0,w),q=y.slice(w+1);if(q.length<6)throw new Error("Data must be at least 6 characters long");const z=dn.decode(q).slice(0,-6),J=On(P,z,n);if(!q.endsWith(J))throw new Error(`Invalid checksum in ${p}: expected "${J}"`);return{prefix:P,words:z}}const a=jn(l);function d(p){const{prefix:c,words:m}=l(p,!1);return{prefix:c,words:m,bytes:t(m)}}function h(p,c){return o(p,s(c))}return{encode:o,decode:l,encodeFromBytes:h,decodeToBytes:d,decodeUnsafe:a,fromWords:t,fromWordsUnsafe:i,toWords:s}}const Cn=cs("bech32");var Me=new TextDecoder("utf-8");new TextEncoder;var us=5e3;function ps(e){try{return e.startsWith("nostr:")&&(e=e.substring(6)),fs(e)}catch{return{type:"invalid",data:null}}}function fs(e){let{prefix:n,words:r}=Cn.decode(e,us),t=new Uint8Array(Cn.fromWords(r));switch(n){case"nprofile":{let s=Ye(t);if(!s[0]?.[0])throw new Error("missing TLV 0 for nprofile");if(s[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");return{type:"nprofile",data:{pubkey:C(s[0][0]),relays:s[1]?s[1].map(i=>Me.decode(i)):[]}}}case"nevent":{let s=Ye(t);if(!s[0]?.[0])throw new Error("missing TLV 0 for nevent");if(s[0][0].length!==32)throw new Error("TLV 0 should be 32 bytes");if(s[2]&&s[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(s[3]&&s[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"nevent",data:{id:C(s[0][0]),relays:s[1]?s[1].map(i=>Me.decode(i)):[],author:s[2]?.[0]?C(s[2][0]):void 0,kind:s[3]?.[0]?parseInt(C(s[3][0]),16):void 0}}}case"naddr":{let s=Ye(t);if(!s[0]?.[0])throw new Error("missing TLV 0 for naddr");if(!s[2]?.[0])throw new Error("missing TLV 2 for naddr");if(s[2][0].length!==32)throw new Error("TLV 2 should be 32 bytes");if(!s[3]?.[0])throw new Error("missing TLV 3 for naddr");if(s[3][0].length!==4)throw new Error("TLV 3 should be 4 bytes");return{type:"naddr",data:{identifier:Me.decode(s[0][0]),pubkey:C(s[2][0]),kind:parseInt(C(s[3][0]),16),relays:s[1]?s[1].map(i=>Me.decode(i)):[]}}}case"nsec":return{type:n,data:t};case"npub":case"note":return{type:n,data:C(t)};default:throw new Error(`unknown prefix ${n}`)}}function Ye(e){let n={},r=e;for(;r.length>0;){let t=r[0],s=r[1],i=r.slice(2,2+s);if(r=r.slice(2+s),i.length<s)throw new Error(`not enough data to read on TLV ${t}`);n[t]=n[t]||[],n[t].push(i)}return n}function ms(e,n,r){return e&n^~e&r}function gs(e,n,r){return e&n^e&r^n&r}class hs{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(n,r,t,s){this.blockLen=n,this.outputLen=r,this.padOffset=t,this.isLE=s,this.buffer=new Uint8Array(n),this.view=Ze(this.buffer)}update(n){Pn(this),L(n);const{view:r,buffer:t,blockLen:s}=this,i=n.length;for(let o=0;o<i;){const l=Math.min(s-this.pos,i-o);if(l===s){const a=Ze(n);for(;s<=i-o;o+=s)this.process(a,o);continue}t.set(n.subarray(o,o+l),this.pos),this.pos+=l,o+=l,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=n.length,this.roundClean(),this}digestInto(n){Pn(this),ns(n,this),this.finished=!0;const{buffer:r,view:t,blockLen:s,isLE:i}=this;let{pos:o}=this;r[o++]=128,on(this.buffer.subarray(o)),this.padOffset>s-o&&(this.process(t,0),o=0);for(let p=o;p<s;p++)r[p]=0;t.setBigUint64(s-8,BigInt(this.length*8),i),this.process(t,0);const l=Ze(n),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const d=a/4,h=this.get();if(d>h.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<d;p++)l.setUint32(4*p,h[p],i)}digest(){const{buffer:n,outputLen:r}=this;this.digestInto(n);const t=n.slice(0,r);return this.destroy(),t}_cloneInto(n){n||=new this.constructor,n.set(...this.get());const{blockLen:r,buffer:t,length:s,finished:i,destroyed:o,pos:l}=this;return n.destroyed=o,n.finished=i,n.length=s,n.pos=l,s%r&&n.buffer.set(t),n}clone(){return this._cloneInto()}}const ee=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ys=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]),ne=new Uint32Array(64);class bs extends hs{constructor(n){super(64,n,8,!1)}get(){const{A:n,B:r,C:t,D:s,E:i,F:o,G:l,H:a}=this;return[n,r,t,s,i,o,l,a]}set(n,r,t,s,i,o,l,a){this.A=n|0,this.B=r|0,this.C=t|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=l|0,this.H=a|0}process(n,r){for(let p=0;p<16;p++,r+=4)ne[p]=n.getUint32(r,!1);for(let p=16;p<64;p++){const c=ne[p-15],m=ne[p-2],y=K(c,7)^K(c,18)^c>>>3,w=K(m,17)^K(m,19)^m>>>10;ne[p]=w+ne[p-7]+y+ne[p-16]|0}let{A:t,B:s,C:i,D:o,E:l,F:a,G:d,H:h}=this;for(let p=0;p<64;p++){const c=K(l,6)^K(l,11)^K(l,25),m=h+c+ms(l,a,d)+ys[p]+ne[p]|0,w=(K(t,2)^K(t,13)^K(t,22))+gs(t,s,i)|0;h=d,d=a,a=l,l=o+m|0,o=i,i=s,s=t,t=m+w|0}t=t+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,l=l+this.E|0,a=a+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(t,s,i,o,l,a,d,h)}roundClean(){on(ne)}destroy(){this.set(0,0,0,0,0,0,0,0),on(this.buffer)}}class vs extends bs{A=ee[0]|0;B=ee[1]|0;C=ee[2]|0;D=ee[3]|0;E=ee[4]|0;F=ee[5]|0;G=ee[6]|0;H=ee[7]|0;constructor(){super(32)}}const He=rs(()=>new vs,ss(1));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const yn=BigInt(0),cn=BigInt(1);function Hn(e,n=""){if(typeof e!="boolean"){const r=n&&`"${n}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function ws(e){if(typeof e=="bigint"){if(!Ts(e))throw new Error("positive bigint expected, got "+e)}else hn(e);return e}function mt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?yn:BigInt("0x"+e)}function bn(e){return mt(C(e))}function gt(e){return mt(C(Es(L(e)).reverse()))}function vn(e,n){hn(n),e=ws(e);const r=Y(e.toString(16).padStart(n*2,"0"));if(r.length!==n)throw new Error("number too large");return r}function ht(e,n){return vn(e,n).reverse()}function Es(e){return Uint8Array.from(e)}function Ss(e){return Uint8Array.from(e,(n,r)=>{const t=n.charCodeAt(0);if(n.length!==1||t>127)throw new Error(`string contains non-ASCII character "${e[r]}" with code ${t} at position ${r}`);return t})}const Ts=e=>typeof e=="bigint"&&yn<=e;function _s(e){let n;for(n=0;e>yn;e>>=cn,n+=1);return n}const yt=e=>(cn<<BigInt(e))-cn;function bt(e,n={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function t(i,o,l){const a=e[i];if(l&&a===void 0)return;const d=typeof a;if(d!==o||a===null)throw new Error(`param "${i}" is invalid: expected ${o}, got ${d}`)}const s=(i,o)=>Object.entries(i).forEach(([l,a])=>t(l,a,o));s(n,!1),s(r,!0)}function Dn(e){const n=new WeakMap;return(r,...t)=>{const s=n.get(r);if(s!==void 0)return s;const i=e(r,...t);return n.set(r,i),i}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const B=BigInt(0),N=BigInt(1),ie=BigInt(2),vt=BigInt(3),wt=BigInt(4),Et=BigInt(5),Rs=BigInt(7),St=BigInt(8),Is=BigInt(9),Tt=BigInt(16);function V(e,n){const r=e%n;return r>=B?r:n+r}function F(e,n,r){let t=e;for(;n-- >B;)t*=t,t%=r;return t}function Nn(e,n){if(e===B)throw new Error("invert: expected non-zero number");if(n<=B)throw new Error("invert: expected positive modulus, got "+n);let r=V(e,n),t=n,s=B,i=N;for(;r!==B;){const l=t/r,a=t%r,d=s-i*l;t=r,r=a,s=i,i=d}if(t!==N)throw new Error("invert: does not exist");return V(s,n)}function wn(e,n,r){if(!e.eql(e.sqr(n),r))throw new Error("Cannot find square root")}function _t(e,n){const r=(e.ORDER+N)/wt,t=e.pow(n,r);return wn(e,t,n),t}function xs(e,n){const r=(e.ORDER-Et)/St,t=e.mul(n,ie),s=e.pow(t,r),i=e.mul(n,s),o=e.mul(e.mul(i,ie),s),l=e.mul(i,e.sub(o,e.ONE));return wn(e,l,n),l}function ks(e){const n=We(e),r=Rt(e),t=r(n,n.neg(n.ONE)),s=r(n,t),i=r(n,n.neg(t)),o=(e+Rs)/Tt;return(l,a)=>{let d=l.pow(a,o),h=l.mul(d,t);const p=l.mul(d,s),c=l.mul(d,i),m=l.eql(l.sqr(h),a),y=l.eql(l.sqr(p),a);d=l.cmov(d,h,m),h=l.cmov(c,p,y);const w=l.eql(l.sqr(h),a),P=l.cmov(d,h,w);return wn(l,P,a),P}}function Rt(e){if(e<vt)throw new Error("sqrt is not defined for small field");let n=e-N,r=0;for(;n%ie===B;)n/=ie,r++;let t=ie;const s=We(e);for(;Bn(s,t)===1;)if(t++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return _t;let i=s.pow(t,n);const o=(n+N)/ie;return function(a,d){if(a.is0(d))return d;if(Bn(a,d)!==1)throw new Error("Cannot find square root");let h=r,p=a.mul(a.ONE,i),c=a.pow(d,n),m=a.pow(d,o);for(;!a.eql(c,a.ONE);){if(a.is0(c))return a.ZERO;let y=1,w=a.sqr(c);for(;!a.eql(w,a.ONE);)if(y++,w=a.sqr(w),y===h)throw new Error("Cannot find square root");const P=N<<BigInt(h-y-1),q=a.pow(p,P);h=y,p=a.sqr(q),c=a.mul(c,p),m=a.mul(m,q)}return m}}function Ms(e){return e%wt===vt?_t:e%St===Et?xs:e%Tt===Is?ks(e):Rt(e)}const Us=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ps(e){const n={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Us.reduce((t,s)=>(t[s]="function",t),n);return bt(e,r),e}function As(e,n,r){if(r<B)throw new Error("invalid exponent, negatives unsupported");if(r===B)return e.ONE;if(r===N)return n;let t=e.ONE,s=n;for(;r>B;)r&N&&(t=e.mul(t,s)),s=e.sqr(s),r>>=N;return t}function It(e,n,r=!1){const t=new Array(n.length).fill(r?e.ZERO:void 0),s=n.reduce((o,l,a)=>e.is0(l)?o:(t[a]=o,e.mul(o,l)),e.ONE),i=e.inv(s);return n.reduceRight((o,l,a)=>e.is0(l)?o:(t[a]=e.mul(o,t[a]),e.mul(o,l)),i),t}function Bn(e,n){const r=(e.ORDER-N)/ie,t=e.pow(n,r),s=e.eql(t,e.ONE),i=e.eql(t,e.ZERO),o=e.eql(t,e.neg(e.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function js(e,n){n!==void 0&&hn(n);const r=n!==void 0?n:e.toString(2).length,t=Math.ceil(r/8);return{nBitLength:r,nByteLength:t}}class qs{ORDER;BITS;BYTES;isLE;ZERO=B;ONE=N;_lengths;_sqrt;_mod;constructor(n,r={}){if(n<=B)throw new Error("invalid field: expected ORDER > 0, got "+n);let t;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(t=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));const{nBitLength:s,nByteLength:i}=js(n,t);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=n,this.BITS=s,this.BYTES=i,this._sqrt=void 0,Object.preventExtensions(this)}create(n){return V(n,this.ORDER)}isValid(n){if(typeof n!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof n);return B<=n&&n<this.ORDER}is0(n){return n===B}isValidNot0(n){return!this.is0(n)&&this.isValid(n)}isOdd(n){return(n&N)===N}neg(n){return V(-n,this.ORDER)}eql(n,r){return n===r}sqr(n){return V(n*n,this.ORDER)}add(n,r){return V(n+r,this.ORDER)}sub(n,r){return V(n-r,this.ORDER)}mul(n,r){return V(n*r,this.ORDER)}pow(n,r){return As(this,n,r)}div(n,r){return V(n*Nn(r,this.ORDER),this.ORDER)}sqrN(n){return n*n}addN(n,r){return n+r}subN(n,r){return n-r}mulN(n,r){return n*r}inv(n){return Nn(n,this.ORDER)}sqrt(n){return this._sqrt||(this._sqrt=Ms(this.ORDER)),this._sqrt(this,n)}toBytes(n){return this.isLE?ht(n,this.BYTES):vn(n,this.BYTES)}fromBytes(n,r=!1){L(n);const{_lengths:t,BYTES:s,isLE:i,ORDER:o,_mod:l}=this;if(t){if(!t.includes(n.length)||n.length>s)throw new Error("Field.fromBytes: expected "+t+" bytes, got "+n.length);const d=new Uint8Array(s);d.set(n,i?0:d.length-n.length),n=d}if(n.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+n.length);let a=i?gt(n):bn(n);if(l&&(a=V(a,o)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(n){return It(this,n)}cmov(n,r,t){return t?r:n}}function We(e,n={}){return new qs(e,n)}function xt(e){if(typeof e!="bigint")throw new Error("field order must be bigint");const n=e.toString(2).length;return Math.ceil(n/8)}function Os(e){const n=xt(e);return n+Math.ceil(n/2)}function Cs(e,n,r=!1){L(e);const t=e.length,s=xt(n),i=Os(n);if(t<16||t<i||t>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+t);const o=r?gt(e):bn(e),l=V(o,n-N)+N;return r?ht(l,s):vn(l,s)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ue=BigInt(0),oe=BigInt(1);function De(e,n){const r=n.negate();return e?r:n}function Ln(e,n){const r=It(e.Fp,n.map(t=>t.Z));return n.map((t,s)=>e.fromAffine(t.toAffine(r[s])))}function kt(e,n){if(!Number.isSafeInteger(e)||e<=0||e>n)throw new Error("invalid window size, expected [1.."+n+"], got W="+e)}function Xe(e,n){kt(e,n);const r=Math.ceil(n/e)+1,t=2**(e-1),s=2**e,i=yt(e),o=BigInt(e);return{windows:r,windowSize:t,mask:i,maxNumber:s,shiftBy:o}}function $n(e,n,r){const{windowSize:t,mask:s,maxNumber:i,shiftBy:o}=r;let l=Number(e&s),a=e>>o;l>t&&(l-=i,a+=oe);const d=n*t,h=d+Math.abs(l)-1,p=l===0,c=l<0,m=n%2!==0;return{nextN:a,offset:h,isZero:p,isNeg:c,isNegF:m,offsetF:d}}const Je=new WeakMap,Mt=new WeakMap;function en(e){return Mt.get(e)||1}function Fn(e){if(e!==ue)throw new Error("invalid wNAF")}class Hs{BASE;ZERO;Fn;bits;constructor(n,r){this.BASE=n.BASE,this.ZERO=n.ZERO,this.Fn=n.Fn,this.bits=r}_unsafeLadder(n,r,t=this.ZERO){let s=n;for(;r>ue;)r&oe&&(t=t.add(s)),s=s.double(),r>>=oe;return t}precomputeWindow(n,r){const{windows:t,windowSize:s}=Xe(r,this.bits),i=[];let o=n,l=o;for(let a=0;a<t;a++){l=o,i.push(l);for(let d=1;d<s;d++)l=l.add(o),i.push(l);o=l.double()}return i}wNAF(n,r,t){if(!this.Fn.isValid(t))throw new Error("invalid scalar");let s=this.ZERO,i=this.BASE;const o=Xe(n,this.bits);for(let l=0;l<o.windows;l++){const{nextN:a,offset:d,isZero:h,isNeg:p,isNegF:c,offsetF:m}=$n(t,l,o);t=a,h?i=i.add(De(c,r[m])):s=s.add(De(p,r[d]))}return Fn(t),{p:s,f:i}}wNAFUnsafe(n,r,t,s=this.ZERO){const i=Xe(n,this.bits);for(let o=0;o<i.windows&&t!==ue;o++){const{nextN:l,offset:a,isZero:d,isNeg:h}=$n(t,o,i);if(t=l,!d){const p=r[a];s=s.add(h?p.negate():p)}}return Fn(t),s}getPrecomputes(n,r,t){let s=Je.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&(typeof t=="function"&&(s=t(s)),Je.set(r,s))),s}cached(n,r,t){const s=en(n);return this.wNAF(s,this.getPrecomputes(s,n,t),r)}unsafe(n,r,t,s){const i=en(n);return i===1?this._unsafeLadder(n,r,s):this.wNAFUnsafe(i,this.getPrecomputes(i,n,t),r,s)}createCache(n,r){kt(r,this.bits),Mt.set(n,r),Je.delete(n)}hasCache(n){return en(n)!==1}}function Ds(e,n,r,t){let s=n,i=e.ZERO,o=e.ZERO;for(;r>ue||t>ue;)r&oe&&(i=i.add(s)),t&oe&&(o=o.add(s)),s=s.double(),r>>=oe,t>>=oe;return{p1:i,p2:o}}function Gn(e,n,r){if(n){if(n.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ps(n),n}else return We(e,{isLE:r})}function Ns(e,n,r={},t){if(t===void 0&&(t=e==="edwards"),!n||typeof n!="object")throw new Error(`expected valid ${e} CURVE object`);for(const a of["p","n","h"]){const d=n[a];if(!(typeof d=="bigint"&&d>ue))throw new Error(`CURVE.${a} must be positive bigint`)}const s=Gn(n.p,r.Fp,t),i=Gn(n.n,r.Fn,t),l=["Gx","Gy","a","b"];for(const a of l)if(!s.isValid(n[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return n=Object.freeze(Object.assign({},n)),{CURVE:n,Fp:s,Fn:i}}function Bs(e,n){return function(t){const s=e(t);return{secretKey:s,publicKey:n(s)}}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Wn=(e,n)=>(e+(e>=0?n:-n)/$s)/n;function Ls(e,n,r){const[[t,s],[i,o]]=n,l=Wn(o*e,r),a=Wn(-s*e,r);let d=e-l*t-a*i,h=-l*s-a*o;const p=d<he,c=h<he;p&&(d=-d),c&&(h=-h);const m=yt(Math.ceil(_s(r)/2))+je;if(d<he||d>=m||h<he||h>=m)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:p,k1:d,k2neg:c,k2:h}}const he=BigInt(0),je=BigInt(1),$s=BigInt(2),Ue=BigInt(3),Fs=BigInt(4);function Gs(e,n={}){const r=Ns("weierstrass",e,n),{Fp:t,Fn:s}=r;let i=r.CURVE;const{h:o,n:l}=i;bt(n,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});const{endo:a}=n;if(a&&(!t.is0(i.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const d=Vs(t,s);function h(){if(!t.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(x,g,b){const{x:E,y:S}=g.toAffine(),k=t.toBytes(E);if(Hn(b,"isCompressed"),b){h();const R=!t.isOdd(S);return Oe(Ws(R),k)}else return Oe(Uint8Array.of(4),k,t.toBytes(S))}function c(x){L(x,void 0,"Point");const{publicKey:g,publicKeyUncompressed:b}=d,E=x.length,S=x[0],k=x.subarray(1);if(E===g&&(S===2||S===3)){const R=t.fromBytes(k);if(!t.isValid(R))throw new Error("bad point: is not on curve, wrong x");const T=w(R);let v;try{v=t.sqrt(T)}catch($){const O=$ instanceof Error?": "+$.message:"";throw new Error("bad point: is not on curve, sqrt error"+O)}h();const _=t.isOdd(v);return(S&1)===1!==_&&(v=t.neg(v)),{x:R,y:v}}else if(E===b&&S===4){const R=t.BYTES,T=t.fromBytes(k.subarray(0,R)),v=t.fromBytes(k.subarray(R,R*2));if(!P(T,v))throw new Error("bad point: is not on curve");return{x:T,y:v}}else throw new Error(`bad point: got length ${E}, expected compressed=${g} or uncompressed=${b}`)}const m=n.toBytes||p,y=n.fromBytes||c;function w(x){const g=t.sqr(x),b=t.mul(g,x);return t.add(t.add(b,t.mul(x,i.a)),i.b)}function P(x,g){const b=t.sqr(g),E=w(x);return t.eql(b,E)}if(!P(i.Gx,i.Gy))throw new Error("bad curve params: generator point");const q=t.mul(t.pow(i.a,Ue),Fs),z=t.mul(t.sqr(i.b),BigInt(27));if(t.is0(t.add(q,z)))throw new Error("bad curve params: a or b");function J(x,g,b=!1){if(!t.isValid(g)||b&&t.is0(g))throw new Error(`bad point coordinate ${x}`);return g}function Re(x){if(!(x instanceof U))throw new Error("Weierstrass Point expected")}function Ie(x){if(!a||!a.basises)throw new Error("no endo");return Ls(x,a.basises,s.ORDER)}const xe=Dn((x,g)=>{const{X:b,Y:E,Z:S}=x;if(t.eql(S,t.ONE))return{x:b,y:E};const k=x.is0();g==null&&(g=k?t.ONE:t.inv(S));const R=t.mul(b,g),T=t.mul(E,g),v=t.mul(S,g);if(k)return{x:t.ZERO,y:t.ZERO};if(!t.eql(v,t.ONE))throw new Error("invZ was invalid");return{x:R,y:T}}),Ht=Dn(x=>{if(x.is0()){if(n.allowInfinityPoint&&!t.is0(x.Y))return;throw new Error("bad point: ZERO")}const{x:g,y:b}=x.toAffine();if(!t.isValid(g)||!t.isValid(b))throw new Error("bad point: x or y not field elements");if(!P(g,b))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function Tn(x,g,b,E,S){return b=new U(t.mul(b.X,x),b.Y,b.Z),g=De(E,g),b=De(S,b),g.add(b)}class U{static BASE=new U(i.Gx,i.Gy,t.ONE);static ZERO=new U(t.ZERO,t.ONE,t.ZERO);static Fp=t;static Fn=s;X;Y;Z;constructor(g,b,E){this.X=J("x",g),this.Y=J("y",b,!0),this.Z=J("z",E),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){const{x:b,y:E}=g||{};if(!g||!t.isValid(b)||!t.isValid(E))throw new Error("invalid affine point");if(g instanceof U)throw new Error("projective point not allowed");return t.is0(b)&&t.is0(E)?U.ZERO:new U(b,E,t.ONE)}static fromBytes(g){const b=U.fromAffine(y(L(g,void 0,"point")));return b.assertValidity(),b}static fromHex(g){return U.fromBytes(Y(g))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,b=!0){return fe.createCache(this,g),b||this.multiply(Ue),this}assertValidity(){Ht(this)}hasEvenY(){const{y:g}=this.toAffine();if(!t.isOdd)throw new Error("Field doesn't support isOdd");return!t.isOdd(g)}equals(g){Re(g);const{X:b,Y:E,Z:S}=this,{X:k,Y:R,Z:T}=g,v=t.eql(t.mul(b,T),t.mul(k,S)),_=t.eql(t.mul(E,T),t.mul(R,S));return v&&_}negate(){return new U(this.X,t.neg(this.Y),this.Z)}double(){const{a:g,b}=i,E=t.mul(b,Ue),{X:S,Y:k,Z:R}=this;let T=t.ZERO,v=t.ZERO,_=t.ZERO,I=t.mul(S,S),$=t.mul(k,k),O=t.mul(R,R),M=t.mul(S,k);return M=t.add(M,M),_=t.mul(S,R),_=t.add(_,_),T=t.mul(g,_),v=t.mul(E,O),v=t.add(T,v),T=t.sub($,v),v=t.add($,v),v=t.mul(T,v),T=t.mul(M,T),_=t.mul(E,_),O=t.mul(g,O),M=t.sub(I,O),M=t.mul(g,M),M=t.add(M,_),_=t.add(I,I),I=t.add(_,I),I=t.add(I,O),I=t.mul(I,M),v=t.add(v,I),O=t.mul(k,R),O=t.add(O,O),I=t.mul(O,M),T=t.sub(T,I),_=t.mul(O,$),_=t.add(_,_),_=t.add(_,_),new U(T,v,_)}add(g){Re(g);const{X:b,Y:E,Z:S}=this,{X:k,Y:R,Z:T}=g;let v=t.ZERO,_=t.ZERO,I=t.ZERO;const $=i.a,O=t.mul(i.b,Ue);let M=t.mul(b,k),G=t.mul(E,R),W=t.mul(S,T),ae=t.add(b,E),D=t.add(k,R);ae=t.mul(ae,D),D=t.add(M,G),ae=t.sub(ae,D),D=t.add(b,S);let Q=t.add(k,T);return D=t.mul(D,Q),Q=t.add(M,W),D=t.sub(D,Q),Q=t.add(E,S),v=t.add(R,T),Q=t.mul(Q,v),v=t.add(G,W),Q=t.sub(Q,v),I=t.mul($,D),v=t.mul(O,W),I=t.add(v,I),v=t.sub(G,I),I=t.add(G,I),_=t.mul(v,I),G=t.add(M,M),G=t.add(G,M),W=t.mul($,W),D=t.mul(O,D),G=t.add(G,W),W=t.sub(M,W),W=t.mul($,W),D=t.add(D,W),M=t.mul(G,D),_=t.add(_,M),M=t.mul(Q,D),v=t.mul(ae,v),v=t.sub(v,M),M=t.mul(ae,G),I=t.mul(Q,I),I=t.add(I,M),new U(v,_,I)}subtract(g){return this.add(g.negate())}is0(){return this.equals(U.ZERO)}multiply(g){const{endo:b}=n;if(!s.isValidNot0(g))throw new Error("invalid scalar: out of range");let E,S;const k=R=>fe.cached(this,R,T=>Ln(U,T));if(b){const{k1neg:R,k1:T,k2neg:v,k2:_}=Ie(g),{p:I,f:$}=k(T),{p:O,f:M}=k(_);S=$.add(M),E=Tn(b.beta,I,O,R,v)}else{const{p:R,f:T}=k(g);E=R,S=T}return Ln(U,[E,S])[0]}multiplyUnsafe(g){const{endo:b}=n,E=this;if(!s.isValid(g))throw new Error("invalid scalar: out of range");if(g===he||E.is0())return U.ZERO;if(g===je)return E;if(fe.hasCache(this))return this.multiply(g);if(b){const{k1neg:S,k1:k,k2neg:R,k2:T}=Ie(g),{p1:v,p2:_}=Ds(U,E,k,T);return Tn(b.beta,v,_,S,R)}else return fe.unsafe(E,g)}toAffine(g){return xe(this,g)}isTorsionFree(){const{isTorsionFree:g}=n;return o===je?!0:g?g(U,this):fe.unsafe(this,l).is0()}clearCofactor(){const{clearCofactor:g}=n;return o===je?this:g?g(U,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(g=!0){return Hn(g,"isCompressed"),this.assertValidity(),m(U,this,g)}toHex(g=!0){return C(this.toBytes(g))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}const _n=s.BITS,fe=new Hs(U,n.endo?Math.ceil(_n/2):_n);return U.BASE.precompute(8),U}function Ws(e){return Uint8Array.of(e?2:3)}function Vs(e,n){return{secretKey:n.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*n.BYTES}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ve={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},zs={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Qs=BigInt(0),un=BigInt(2);function Ks(e){const n=Ve.p,r=BigInt(3),t=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),l=BigInt(44),a=BigInt(88),d=e*e*e%n,h=d*d*e%n,p=F(h,r,n)*h%n,c=F(p,r,n)*h%n,m=F(c,un,n)*d%n,y=F(m,s,n)*m%n,w=F(y,i,n)*y%n,P=F(w,l,n)*w%n,q=F(P,a,n)*P%n,z=F(q,l,n)*w%n,J=F(z,r,n)*h%n,Re=F(J,o,n)*y%n,Ie=F(Re,t,n)*d%n,xe=F(Ie,un,n);if(!Ne.eql(Ne.sqr(xe),e))throw new Error("Cannot find square root");return xe}const Ne=We(Ve.p,{sqrt:Ks}),pe=Gs(Ve,{Fp:Ne,endo:zs}),Vn={};function Be(e,...n){let r=Vn[e];if(r===void 0){const t=He(Ss(e));r=Oe(t,t),Vn[e]=r}return He(Oe(r,...n))}const En=e=>e.toBytes(!0).slice(1),Sn=e=>e%un===Qs;function pn(e){const{Fn:n,BASE:r}=pe,t=n.fromBytes(e),s=r.multiply(t);return{scalar:Sn(s.y)?t:n.neg(t),bytes:En(s)}}function Ut(e){const n=Ne;if(!n.isValidNot0(e))throw new Error("invalid x: Fail if x ≥ p");const r=n.create(e*e),t=n.create(r*e+BigInt(7));let s=n.sqrt(t);Sn(s)||(s=n.neg(s));const i=pe.fromAffine({x:e,y:s});return i.assertValidity(),i}const ve=bn;function Pt(...e){return pe.Fn.create(ve(Be("BIP0340/challenge",...e)))}function zn(e){return pn(e).bytes}function Zs(e,n,r=at(32)){const{Fn:t}=pe,s=L(e,void 0,"message"),{bytes:i,scalar:o}=pn(n),l=L(r,32,"auxRand"),a=t.toBytes(o^ve(Be("BIP0340/aux",l))),d=Be("BIP0340/nonce",a,i,s),{bytes:h,scalar:p}=pn(d),c=Pt(h,i,s),m=new Uint8Array(64);if(m.set(h,0),m.set(t.toBytes(t.create(p+c*o)),32),!At(m,s,i))throw new Error("sign: Invalid signature produced");return m}function At(e,n,r){const{Fp:t,Fn:s,BASE:i}=pe,o=L(e,64,"signature"),l=L(n,void 0,"message"),a=L(r,32,"publicKey");try{const d=Ut(ve(a)),h=ve(o.subarray(0,32));if(!t.isValidNot0(h))return!1;const p=ve(o.subarray(32,64));if(!s.isValidNot0(p))return!1;const c=Pt(s.toBytes(h),En(d),l),m=i.multiplyUnsafe(p).add(d.multiplyUnsafe(s.neg(c))),{x:y,y:w}=m.toAffine();return!(m.is0()||!Sn(w)||y!==h)}catch{return!1}}const Z=(()=>{const r=(t=at(48))=>Cs(t,Ve.n);return{keygen:Bs(r,zn),getPublicKey:zn,sign:Zs,verify:At,Point:pe,utils:{randomSecretKey:r,taggedHash:Be,lift_x:Ut,pointToBytes:En},lengths:{secretKey:32,publicKey:32,publicKeyHasPrefix:!1,signature:64,seed:48}}})();var se=Symbol("verified"),Ys=e=>e instanceof Object;function Xs(e){if(!Ys(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let n=0;n<e.tags.length;n++){let r=e.tags[n];if(!Array.isArray(r))return!1;for(let t=0;t<r.length;t++)if(typeof r[t]!="string")return!1}return!0}new TextDecoder("utf-8");var Js=new TextEncoder;function ye(e){try{e.indexOf("://")===-1&&(e="wss://"+e);let n=new URL(e);return n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),n.pathname=n.pathname.replace(/\/+/g,"/"),n.pathname.endsWith("/")&&(n.pathname=n.pathname.slice(0,-1)),(n.port==="80"&&n.protocol==="ws:"||n.port==="443"&&n.protocol==="wss:")&&(n.port=""),n.searchParams.sort(),n.hash="",n.toString()}catch{throw new Error(`Invalid URL: ${e}`)}}var ei=class{generateSecretKey(){return Z.utils.randomSecretKey()}getPublicKey(n){return C(Z.getPublicKey(n))}finalizeEvent(n,r){const t=n;return t.pubkey=C(Z.getPublicKey(r)),t.id=nn(t),t.sig=C(Z.sign(Y(nn(t)),r)),t[se]=!0,t}verifyEvent(n){if(typeof n[se]=="boolean")return n[se];try{const r=nn(n);if(r!==n.id)return n[se]=!1,!1;const t=Z.verify(Y(n.sig),Y(r),Y(n.pubkey));return n[se]=t,t}catch{return n[se]=!1,!1}}};function ni(e){if(!Xs(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function nn(e){let n=He(Js.encode(ni(e)));return C(n)}var ze=new ei;ze.generateSecretKey;ze.getPublicKey;ze.finalizeEvent;var ti=ze.verifyEvent,ri=22242;function si(e,n){if(e.ids&&e.ids.indexOf(n.id)===-1||e.kinds&&e.kinds.indexOf(n.kind)===-1||e.authors&&e.authors.indexOf(n.pubkey)===-1)return!1;for(let r in e)if(r[0]==="#"){let t=r.slice(1),s=e[`#${t}`];if(s&&!n.tags.find(([i,o])=>i===r.slice(1)&&s.indexOf(o)!==-1))return!1}return!(e.since&&n.created_at<e.since||e.until&&n.created_at>e.until)}function ii(e,n){for(let r=0;r<e.length;r++)if(si(e[r],n))return!0;return!1}function oi(e,n){let r=n.length+3,t=e.indexOf(`"${n}":`)+r,s=e.slice(t).indexOf('"')+t+1;return e.slice(s,s+64)}function ai(e){let n=e.slice(0,22).indexOf('"EVENT"');if(n===-1)return null;let r=e.slice(n+7+1).indexOf('"');if(r===-1)return null;let t=n+7+1+r,s=e.slice(t+1,80).indexOf('"');if(s===-1)return null;let i=t+1+s;return e.slice(t+1,i)}function li(e,n){return{kind:ri,created_at:Math.floor(Date.now()/1e3),tags:[["relay",e],["challenge",n]],content:""}}var jt=class extends Error{constructor(e,n){super(`Tried to send message '${e} on a closed connection to ${n}.`),this.name="SendingOnClosedConnection"}},qt=class{url;_connected=!1;onclose=null;onnotice=e=>console.debug(`NOTICE from ${this.url}: ${e}`);onauth;baseEoseTimeout=4400;publishTimeout=4400;pingFrequency=29e3;pingTimeout=2e4;resubscribeBackoff=[1e4,1e4,1e4,2e4,2e4,3e4,6e4];openSubs=new Map;enablePing;enableReconnect;idleSince=Date.now();ongoingOperations=0;reconnectTimeoutHandle;pingIntervalHandle;reconnectAttempts=0;skipReconnection=!1;connectionPromise;openCountRequests=new Map;openEventPublishes=new Map;ws;challenge;authPromise;serial=0;verifyEvent;_WebSocket;constructor(e,n){this.url=ye(e),this.verifyEvent=n.verifyEvent,this._WebSocket=n.websocketImplementation||WebSocket,this.enablePing=n.enablePing,this.enableReconnect=n.enableReconnect||!1}static async connect(e,n){const r=new qt(e,n);return await r.connect(n),r}closeAllSubscriptions(e){for(let[n,r]of this.openSubs)r.close(e);this.openSubs.clear();for(let[n,r]of this.openEventPublishes)r.reject(new Error(e));this.openEventPublishes.clear();for(let[n,r]of this.openCountRequests)r.reject(new Error(e));this.openCountRequests.clear()}get connected(){return this._connected}async reconnect(){const e=this.resubscribeBackoff[Math.min(this.reconnectAttempts,this.resubscribeBackoff.length-1)];this.reconnectAttempts++,this.reconnectTimeoutHandle=setTimeout(async()=>{try{await this.connect()}catch{}},e)}handleHardClose(e){this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this._connected=!1,this.connectionPromise=void 0,this.idleSince=void 0,this.enableReconnect&&!this.skipReconnection?this.reconnect():(this.onclose?.(),this.closeAllSubscriptions(e))}async connect(e){let n;return this.connectionPromise?this.connectionPromise:(this.challenge=void 0,this.authPromise=void 0,this.skipReconnection=!1,this.connectionPromise=new Promise((r,t)=>{e?.timeout&&(n=setTimeout(()=>{t("connection timed out"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection timed out")},e.timeout)),e?.abort&&(e.abort.onabort=t);try{this.ws=new this._WebSocket(this.url)}catch(s){clearTimeout(n),t(s);return}this.ws.onopen=()=>{this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),clearTimeout(n),this._connected=!0;const s=this.reconnectAttempts>0;this.reconnectAttempts=0;for(const i of this.openSubs.values()){if(i.eosed=!1,s)for(let o=0;o<i.filters.length;o++)i.lastEmitted&&(i.filters[o].since=i.lastEmitted+1);i.fire()}this.enablePing&&(this.pingIntervalHandle=setInterval(()=>this.pingpong(),this.pingFrequency)),r()},this.ws.onerror=()=>{clearTimeout(n),t("connection failed"),this.connectionPromise=void 0,this.skipReconnection=!0,this.onclose?.(),this.handleHardClose("relay connection failed")},this.ws.onclose=s=>{clearTimeout(n),t(s.message||"websocket closed"),this.handleHardClose("relay connection closed")},this.ws.onmessage=this._onmessage.bind(this)}),this.connectionPromise)}waitForPingPong(){return new Promise(e=>{this.ws.once("pong",()=>e(!0)),this.ws.ping()})}waitForDummyReq(){return new Promise((e,n)=>{if(!this.connectionPromise)return n(new Error(`no connection to ${this.url}, can't ping`));try{const r=this.subscribe([{ids:["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"],limit:0}],{label:"<forced-ping>",oneose:()=>{e(!0),r.close()},onclose(){e(!0)},eoseTimeout:this.pingTimeout+1e3})}catch(r){n(r)}})}async pingpong(){this.ws?.readyState===1&&(await Promise.any([this.ws&&this.ws.ping&&this.ws.once?this.waitForPingPong():this.waitForDummyReq(),new Promise(n=>setTimeout(()=>n(!1),this.pingTimeout))])||this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close())}async send(e){if(!this.connectionPromise)throw new jt(e,this.url);this.connectionPromise.then(()=>{this.ws?.send(e)})}async auth(e){const n=this.challenge;if(!n)throw new Error("can't perform auth, no challenge was received");return this.authPromise?this.authPromise:(this.authPromise=new Promise(async(r,t)=>{try{let s=await e(li(this.url,n)),i=setTimeout(()=>{let o=this.openEventPublishes.get(s.id);o&&(o.reject(new Error("auth timed out")),this.openEventPublishes.delete(s.id))},this.publishTimeout);this.openEventPublishes.set(s.id,{resolve:r,reject:t,timeout:i}),this.send('["AUTH",'+JSON.stringify(s)+"]")}catch(s){console.warn("subscribe auth function failed:",s)}}),this.authPromise)}async publish(e){this.idleSince=void 0,this.ongoingOperations++;const n=new Promise((r,t)=>{const s=setTimeout(()=>{const i=this.openEventPublishes.get(e.id);i&&(i.reject(new Error("publish timed out")),this.openEventPublishes.delete(e.id))},this.publishTimeout);this.openEventPublishes.set(e.id,{resolve:r,reject:t,timeout:s})});return this.send('["EVENT",'+JSON.stringify(e)+"]"),this.ongoingOperations--,this.ongoingOperations===0&&(this.idleSince=Date.now()),n}async count(e,n){this.serial++;const r=n?.id||"count:"+this.serial,t=new Promise((s,i)=>{this.openCountRequests.set(r,{resolve:s,reject:i})});return this.send('["COUNT","'+r+'",'+JSON.stringify(e).substring(1)),t}subscribe(e,n){n.label!=="<forced-ping>"&&(this.idleSince=void 0,this.ongoingOperations++);const r=this.prepareSubscription(e,n);return r.fire(),n.abort&&(n.abort.onabort=()=>r.close(String(n.abort.reason||"<aborted>"))),r}prepareSubscription(e,n){this.serial++;const r=n.id||(n.label?n.label+":":"sub:")+this.serial,t=new di(this,r,e,n);return this.openSubs.set(r,t),t}close(){this.skipReconnection=!0,this.reconnectTimeoutHandle&&(clearTimeout(this.reconnectTimeoutHandle),this.reconnectTimeoutHandle=void 0),this.pingIntervalHandle&&(clearInterval(this.pingIntervalHandle),this.pingIntervalHandle=void 0),this.closeAllSubscriptions("relay connection closed by us"),this._connected=!1,this.idleSince=void 0,this.onclose?.(),this.ws?.readyState===this._WebSocket.OPEN&&this.ws?.close()}_onmessage(e){const n=e.data;if(!n)return;const r=ai(n);if(r){const t=this.openSubs.get(r);if(!t)return;const s=oi(n,"id"),i=t.alreadyHaveEvent?.(s);if(t.receivedEvent?.(this,s),i)return}try{let t=JSON.parse(n);switch(t[0]){case"EVENT":{const s=this.openSubs.get(t[1]),i=t[2];this.verifyEvent(i)&&ii(s.filters,i)?s.onevent(i):s.oninvalidevent?.(i),(!s.lastEmitted||s.lastEmitted<i.created_at)&&(s.lastEmitted=i.created_at);return}case"COUNT":{const s=t[1],i=t[2],o=this.openCountRequests.get(s);o&&(o.resolve(i.count),this.openCountRequests.delete(s));return}case"EOSE":{const s=this.openSubs.get(t[1]);if(!s)return;s.receivedEose();return}case"OK":{const s=t[1],i=t[2],o=t[3],l=this.openEventPublishes.get(s);l&&(clearTimeout(l.timeout),i?l.resolve(o):l.reject(new Error(o)),this.openEventPublishes.delete(s));return}case"CLOSED":{const s=t[1],i=this.openSubs.get(s);if(!i)return;i.closed=!0,i.close(t[2]);return}case"NOTICE":{this.onnotice(t[1]);return}case"AUTH":{this.challenge=t[1],this.onauth&&this.auth(this.onauth);return}default:{this.openSubs.get(t[1])?.oncustom?.(t);return}}}catch(t){try{const[s,i,o]=JSON.parse(n);console.warn(`[nostr] relay ${this.url} error processing message:`,t,o)}catch{console.warn(`[nostr] relay ${this.url} error processing message:`,t)}return}}},di=class{relay;id;lastEmitted;closed=!1;eosed=!1;filters;alreadyHaveEvent;receivedEvent;onevent;oninvalidevent;oneose;onclose;oncustom;eoseTimeout;eoseTimeoutHandle;constructor(e,n,r,t){if(r.length===0)throw new Error("subscription can't be created with zero filters");this.relay=e,this.filters=r,this.id=n,this.alreadyHaveEvent=t.alreadyHaveEvent,this.receivedEvent=t.receivedEvent,this.eoseTimeout=t.eoseTimeout||e.baseEoseTimeout,this.oneose=t.oneose,this.onclose=t.onclose,this.oninvalidevent=t.oninvalidevent,this.onevent=t.onevent||(s=>{console.warn(`onevent() callback not defined for subscription '${this.id}' in relay ${this.relay.url}. event received:`,s)})}fire(){this.relay.send('["REQ","'+this.id+'",'+JSON.stringify(this.filters).substring(1)),this.eoseTimeoutHandle=setTimeout(this.receivedEose.bind(this),this.eoseTimeout)}receivedEose(){this.eosed||(clearTimeout(this.eoseTimeoutHandle),this.eosed=!0,this.oneose?.())}close(e="closed by caller"){if(!this.closed&&this.relay.connected){try{this.relay.send('["CLOSE",'+JSON.stringify(this.id)+"]")}catch(n){if(!(n instanceof jt))throw n}this.closed=!0}this.relay.openSubs.delete(this.id),this.relay.ongoingOperations--,this.relay.ongoingOperations===0&&(this.relay.idleSince=Date.now()),this.onclose?.(e)}},ci=e=>(e[se]=!0,!0),ui=class{relays=new Map;seenOn=new Map;trackRelays=!1;verifyEvent;enablePing;enableReconnect;automaticallyAuth;trustedRelayURLs=new Set;onRelayConnectionFailure;onRelayConnectionSuccess;allowConnectingToRelay;maxWaitForConnection;_WebSocket;constructor(e){this.verifyEvent=e.verifyEvent,this._WebSocket=e.websocketImplementation,this.enablePing=e.enablePing,this.enableReconnect=e.enableReconnect||!1,this.automaticallyAuth=e.automaticallyAuth,this.onRelayConnectionFailure=e.onRelayConnectionFailure,this.onRelayConnectionSuccess=e.onRelayConnectionSuccess,this.allowConnectingToRelay=e.allowConnectingToRelay,this.maxWaitForConnection=e.maxWaitForConnection||3e3}async ensureRelay(e,n){e=ye(e);let r=this.relays.get(e);if(r||(r=new qt(e,{verifyEvent:this.trustedRelayURLs.has(e)?ci:this.verifyEvent,websocketImplementation:this._WebSocket,enablePing:this.enablePing,enableReconnect:this.enableReconnect}),r.onclose=()=>{this.relays.delete(e)},this.relays.set(e,r)),this.automaticallyAuth){const t=this.automaticallyAuth(e);t&&(r.onauth=t)}try{await r.connect({timeout:n?.connectionTimeout,abort:n?.abort})}catch(t){throw this.relays.delete(e),t}return r}close(e){e.map(ye).forEach(n=>{this.relays.get(n)?.close(),this.relays.delete(n)})}subscribe(e,n,r){const t=[],s=[];for(let i=0;i<e.length;i++){const o=ye(e[i]);t.find(l=>l.url===o)||s.indexOf(o)===-1&&(s.push(o),t.push({url:o,filter:n}))}return this.subscribeMap(t,r)}subscribeMany(e,n,r){return this.subscribe(e,n,r)}subscribeMap(e,n){const r=new Map;for(const c of e){const{url:m,filter:y}=c;r.has(m)||r.set(m,[]),r.get(m).push(y)}const t=Array.from(r.entries()).map(([c,m])=>({url:c,filters:m}));this.trackRelays&&(n.receivedEvent=(c,m)=>{let y=this.seenOn.get(m);y||(y=new Set,this.seenOn.set(m,y)),y.add(c)});const s=new Set,i=[],o=[];let l=c=>{o[c]||(o[c]=!0,o.filter(m=>m).length===t.length&&(n.oneose?.(),l=()=>{}))};const a=[];let d=(c,m)=>{a[c]||(l(c),a[c]=m,a.filter(y=>y).length===t.length&&(n.onclose?.(a),d=()=>{}))};const h=c=>{if(n.alreadyHaveEvent?.(c))return!0;const m=s.has(c);return s.add(c),m},p=Promise.all(t.map(async({url:c,filters:m},y)=>{if(this.allowConnectingToRelay?.(c,["read",m])===!1){d(y,"connection skipped by allowConnectingToRelay");return}let w;try{w=await this.ensureRelay(c,{connectionTimeout:this.maxWaitForConnection<(n.maxWait||0)?Math.max(n.maxWait*.8,n.maxWait-1e3):this.maxWaitForConnection,abort:n.abort})}catch(q){this.onRelayConnectionFailure?.(c),d(y,q?.message||String(q));return}this.onRelayConnectionSuccess?.(c);let P=w.subscribe(m,{...n,oneose:()=>l(y),onclose:q=>{q.startsWith("auth-required: ")&&n.onauth?w.auth(n.onauth).then(()=>{w.subscribe(m,{...n,oneose:()=>l(y),onclose:z=>{d(y,z)},alreadyHaveEvent:h,eoseTimeout:n.maxWait,abort:n.abort})}).catch(z=>{d(y,`auth was required and attempted, but failed with: ${z}`)}):d(y,q)},alreadyHaveEvent:h,eoseTimeout:n.maxWait,abort:n.abort});i.push(P)}));return{async close(c){await p,i.forEach(m=>{m.close(c)})}}}subscribeEose(e,n,r){let t;return t=this.subscribe(e,n,{...r,oneose(){const s="closed automatically on eose";t?t.close(s):r.onclose?.(e.map(i=>s))}}),t}subscribeManyEose(e,n,r){return this.subscribeEose(e,n,r)}async querySync(e,n,r){return new Promise(async t=>{const s=[];this.subscribeEose(e,n,{...r,onevent(i){s.push(i)},onclose(i){t(s)}})})}async get(e,n,r){n.limit=1;const t=await this.querySync(e,n,r);return t.sort((s,i)=>i.created_at-s.created_at),t[0]||null}publish(e,n,r){return e.map(ye).map(async(t,s,i)=>{if(i.indexOf(t)!==s)return Promise.reject("duplicate url");if(this.allowConnectingToRelay?.(t,["write",n])===!1)return Promise.reject("connection skipped by allowConnectingToRelay");let o;try{o=await this.ensureRelay(t,{connectionTimeout:this.maxWaitForConnection<(r?.maxWait||0)?Math.max(r.maxWait*.8,r.maxWait-1e3):this.maxWaitForConnection,abort:r?.abort})}catch(l){return this.onRelayConnectionFailure?.(t),"connection failure: "+String(l)}return o.publish(n).catch(async l=>{if(l instanceof Error&&l.message.startsWith("auth-required: ")&&r?.onauth)return await o.auth(r.onauth),o.publish(n);throw l}).then(l=>{if(this.trackRelays){let a=this.seenOn.get(n.id);a||(a=new Set,this.seenOn.set(n.id,a)),a.add(o)}return l})})}listConnectionStatus(){const e=new Map;return this.relays.forEach((n,r)=>e.set(r,n.connected)),e}destroy(){this.relays.forEach(e=>e.close()),this.relays=new Map}pruneIdleRelays(e=1e4){const n=[];for(const[r,t]of this.relays)t.idleSince&&Date.now()-t.idleSince>=e&&(this.relays.delete(r),n.push(r),t.close());return n}},Ot;try{Ot=WebSocket}catch{}var pi=class extends ui{constructor(e){super({verifyEvent:ti,websocketImplementation:Ot,maxWaitForConnection:3e3,...e})}},le=Symbol("verified"),fi=e=>e instanceof Object;function mi(e){if(!fi(e)||typeof e.kind!="number"||typeof e.content!="string"||typeof e.created_at!="number"||typeof e.pubkey!="string"||!e.pubkey.match(/^[a-f0-9]{64}$/)||!Array.isArray(e.tags))return!1;for(let n=0;n<e.tags.length;n++){let r=e.tags[n];if(!Array.isArray(r))return!1;for(let t=0;t<r.length;t++)if(typeof r[t]!="string")return!1}return!0}new TextDecoder("utf-8");var gi=new TextEncoder,hi=class{generateSecretKey(){return Z.utils.randomSecretKey()}getPublicKey(e){return C(Z.getPublicKey(e))}finalizeEvent(e,n){const r=e;return r.pubkey=C(Z.getPublicKey(n)),r.id=tn(r),r.sig=C(Z.sign(Y(tn(r)),n)),r[le]=!0,r}verifyEvent(e){if(typeof e[le]=="boolean")return e[le];try{const n=tn(e);if(n!==e.id)return e[le]=!1,!1;const r=Z.verify(Y(e.sig),Y(n),Y(e.pubkey));return e[le]=r,r}catch{return e[le]=!1,!1}}};function yi(e){if(!mi(e))throw new Error("can't serialize event with wrong or missing properties");return JSON.stringify([0,e.pubkey,e.created_at,e.kind,e.tags,e.content])}function tn(e){let n=He(gi.encode(yi(e)));return C(n)}var Qe=new hi;Qe.generateSecretKey;Qe.getPublicKey;Qe.finalizeEvent;var bi=Qe.verifyEvent;const vi=8e3;function wi(e){return typeof e=="number"&&gn.includes(e)}function Ei(e){try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function Si(e){const n=[];for(const r of e??[])try{const t=new URL(r);if(t.protocol!=="ws:"&&t.protocol!=="wss:")continue;n.push(t.href)}catch{}return[...new Set(n)]}function Ti(e){const n=ps(e.trim());if(n.type!=="nevent"&&n.type!=="naddr")throw new Error("Enter a NIP-19 nevent or naddr for a NIP-5D napplet manifest event");const r=Si(n.data.relays);if(r.length===0)throw new Error("The pointer does not include relay hints; include at least one relay in the nevent/naddr");if(n.type==="nevent"){if(n.data.kind!==void 0&&!wi(n.data.kind))throw new Error(`nevent points at kind ${n.data.kind}, not a NIP-5D napplet manifest kind`);return{type:"nevent",relays:r,filter:{ids:[n.data.id],kinds:n.data.kind===void 0?[...gn]:[n.data.kind],authors:n.data.author?[n.data.author]:void 0,limit:1}}}if(n.data.kind!==ce)throw new Error(`naddr kind ${n.data.kind} is not the named napplet kind ${ce}`);return{type:"naddr",relays:r,filter:{kinds:[ce],authors:[n.data.pubkey],"#d":[n.data.identifier],limit:1}}}function _i(e){return{id:e.id,pubkey:e.pubkey,kind:e.kind,tags:e.tags,content:e.content}}async function Ri(e){const n=typeof e=="string"?new TextEncoder().encode(e):e,r=new Uint8Array(n.byteLength);r.set(n);const t=await crypto.subtle.digest("SHA-256",r.buffer);return[...new Uint8Array(t)].map(s=>s.toString(16).padStart(2,"0")).join("")}function Ii(e){const n=[];for(const r of e.tags)if(!(r[0]!=="server"||!r[1]))try{const t=new URL(r[1]);(t.protocol==="http:"||t.protocol==="https:")&&n.push(t.href)}catch{}return[...new Set(n)]}function xi(e,n){const r=e.endsWith("/")?e:`${e}/`;return new URL(n,r).href}async function ki(e,n=fetch){const r=Ge(e);if(!r.ok)throw new Error(r.errors.map(o=>o.message).join("; "));const t=e.tags.find(o=>o[0]==="x")[1],s=Ii(e);if(s.length===0)throw new Error("Manifest does not include any usable Blossom server hints");const i=[];for(const o of s){const l=xi(o,t);try{const a=await n(l,{mode:"cors"});if(!a.ok){i.push(`${l}: HTTP ${a.status}`);continue}const d=new Uint8Array(await a.arrayBuffer()),h=await Ri(d);if(h!==t){i.push(`${l}: sha256 ${h} did not match manifest ${t}`);continue}return new TextDecoder().decode(d)}catch(a){i.push(`${l}: ${a instanceof Error?a.message:String(a)}`)}}throw new Error(`Unable to fetch verified /index.html from Blossom servers: ${i.join("; ")}`)}async function Mi(e,n){try{const t=await(await n(e,{mode:"cors"})).text();return{source:"url",input:e,label:e,bootUrl:e,html:t,fetched:!0,manifestEvent:null}}catch{return{source:"url",input:e,label:e,bootUrl:e,html:"",fetched:!1,manifestEvent:null}}}async function Ui(e,n){const r=Ti(e),t=!n.pool,s=n.pool??new pi;try{const i=await s.get(r.relays,{...r.filter},{maxWait:n.maxRelayWaitMs??vi});if(!i)throw new Error("No matching napplet manifest event was found on the pointer relay hints");if(!bi(i))throw new Error("Resolved manifest event signature is invalid");const o=_i(i),l=Ge(o);if(!l.ok)throw new Error(`Resolved event is not a valid NIP-5D napplet manifest: ${l.errors[0]?.message}`);const a=await ki(o,n.fetcher??fetch),d=(n.createObjectUrl??URL.createObjectURL)(new Blob([a],{type:"text/html;charset=utf-8"})),h=()=>(n.revokeObjectUrl??URL.revokeObjectURL)(d);return{source:"nostr",input:e,label:o.id??e,bootUrl:d,html:a,fetched:!0,manifestEvent:o,revoke:h}}finally{t&&s.destroy()}}async function Pi(e,n={}){const r=e.trim();if(!r)throw new Error("Enter a NIP-19 nevent/naddr, or an HTTP URL for local dev");return Ei(r)?Mi(r,n.fetcher??fetch):Ui(r,n)}const Ai=`"use strict";
|
|
147
197
|
var NappletShimPrelude = (() => {
|
|
148
198
|
var __defProp = Object.defineProperty;
|
|
149
199
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -173,7 +223,7 @@ var NappletShimPrelude = (() => {
|
|
|
173
223
|
});
|
|
174
224
|
|
|
175
225
|
// ../core/dist/index.js
|
|
176
|
-
var NAP_DOMAINS = ["shell", "relay", "identity", "storage", "inc", "theme", "keys", "media", "notify", "config", "resource", "cvm", "outbox", "upload", "intent", "ble", "webrtc", "link", "count", "lists", "serial", "fs", "common", "dm", "gamepad"];
|
|
226
|
+
var NAP_DOMAINS = ["shell", "relay", "identity", "storage", "inc", "theme", "keys", "media", "notify", "config", "resource", "cvm", "outbox", "upload", "intent", "ble", "webrtc", "link", "count", "lists", "serial", "fs", "common", "dm", "gamepad", "llm"];
|
|
177
227
|
function createDispatch() {
|
|
178
228
|
const handlers3 = /* @__PURE__ */ new Map();
|
|
179
229
|
function registerNap2(domain, handler) {
|
|
@@ -302,6 +352,134 @@ var NappletShimPrelude = (() => {
|
|
|
302
352
|
sendEnvelope(window.parent, message);
|
|
303
353
|
}
|
|
304
354
|
|
|
355
|
+
// ../nap/dist/chunk-WBYAVRXN.js
|
|
356
|
+
var REQUEST_TIMEOUT_MS = 3e4;
|
|
357
|
+
var SELECT_TIMEOUT_MS = 12e4;
|
|
358
|
+
var GENERATE_TIMEOUT_MS = 18e5;
|
|
359
|
+
var RESULT_FIELDS = {
|
|
360
|
+
"llm.select.result": "model",
|
|
361
|
+
"llm.describe.result": "model",
|
|
362
|
+
"llm.generate.result": "result",
|
|
363
|
+
"llm.cancel.result": "cancelled"
|
|
364
|
+
};
|
|
365
|
+
var pending = /* @__PURE__ */ new Map();
|
|
366
|
+
var installed = false;
|
|
367
|
+
var LlmError = class extends Error {
|
|
368
|
+
/** NAP-LLM error code; unknown codes are still failures. */
|
|
369
|
+
code;
|
|
370
|
+
/**
|
|
371
|
+
* @param failure The \`error\` record from a result envelope.
|
|
372
|
+
* @example throw new LlmError({ code: 'selection-expired', message: 'Select a model again.' });
|
|
373
|
+
*/
|
|
374
|
+
constructor(failure) {
|
|
375
|
+
super(failure.message);
|
|
376
|
+
this.name = "LlmError";
|
|
377
|
+
this.code = failure.code;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
function isFailure(value) {
|
|
381
|
+
if (!value || typeof value !== "object") return false;
|
|
382
|
+
const record = value;
|
|
383
|
+
return typeof record.code === "string" && record.code.length > 0 && typeof record.message === "string";
|
|
384
|
+
}
|
|
385
|
+
function settle(id, entry) {
|
|
386
|
+
pending.delete(id);
|
|
387
|
+
clearTimeout(entry.timeout);
|
|
388
|
+
entry.cleanup?.();
|
|
389
|
+
}
|
|
390
|
+
function sendRequest(type, payload, timeoutMs, id = crypto.randomUUID()) {
|
|
391
|
+
return new Promise((resolve, reject) => {
|
|
392
|
+
const timeout = setTimeout(() => {
|
|
393
|
+
const entry = pending.get(id);
|
|
394
|
+
if (entry) {
|
|
395
|
+
settle(id, entry);
|
|
396
|
+
reject(new Error(\`\${type} timed out\`));
|
|
397
|
+
}
|
|
398
|
+
}, timeoutMs);
|
|
399
|
+
pending.set(id, { type: \`\${type}.result\`, resolve, reject, timeout, nextSequence: 0 });
|
|
400
|
+
try {
|
|
401
|
+
postToShell({ type, id, ...payload });
|
|
402
|
+
} catch (error) {
|
|
403
|
+
settle(id, pending.get(id));
|
|
404
|
+
reject(error);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
function handleDelta(message) {
|
|
409
|
+
if ("id" in message || typeof message.requestId !== "string" || typeof message.sequence !== "number" || typeof message.text !== "string") return;
|
|
410
|
+
const entry = pending.get(message.requestId);
|
|
411
|
+
if (!entry || entry.type !== "llm.generate.result") return;
|
|
412
|
+
if (message.sequence !== entry.nextSequence) {
|
|
413
|
+
entry.nextSequence = Number.POSITIVE_INFINITY;
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
entry.nextSequence += 1;
|
|
417
|
+
entry.onDelta?.({ requestId: message.requestId, sequence: message.sequence, text: message.text });
|
|
418
|
+
}
|
|
419
|
+
function handleLlmMessage(message) {
|
|
420
|
+
if (message.type === "llm.delta") {
|
|
421
|
+
handleDelta(message);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (typeof message.id !== "string") return;
|
|
425
|
+
const entry = pending.get(message.id);
|
|
426
|
+
if (!entry || entry.type !== message.type) return;
|
|
427
|
+
settle(message.id, entry);
|
|
428
|
+
const field = RESULT_FIELDS[message.type];
|
|
429
|
+
const hasValue = message[field] !== void 0 && message[field] !== null;
|
|
430
|
+
const hasError = message.error !== void 0 && message.error !== null;
|
|
431
|
+
if (hasValue === hasError) {
|
|
432
|
+
entry.reject(new Error(\`\${message.type} must carry exactly one of \${field} or error\`));
|
|
433
|
+
} else if (hasError) {
|
|
434
|
+
entry.reject(isFailure(message.error) ? new LlmError(message.error) : new Error(\`\${message.type} returned a malformed error\`));
|
|
435
|
+
} else {
|
|
436
|
+
entry.resolve(message[field]);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function select(requirements) {
|
|
440
|
+
return sendRequest("llm.select", requirements === void 0 ? {} : { requirements }, SELECT_TIMEOUT_MS);
|
|
441
|
+
}
|
|
442
|
+
function describe(handle) {
|
|
443
|
+
return sendRequest("llm.describe", { handle }, REQUEST_TIMEOUT_MS);
|
|
444
|
+
}
|
|
445
|
+
function generate(request7, options = {}) {
|
|
446
|
+
const id = crypto.randomUUID();
|
|
447
|
+
const promise = sendRequest("llm.generate", { request: request7 }, GENERATE_TIMEOUT_MS, id);
|
|
448
|
+
const entry = pending.get(id);
|
|
449
|
+
if (entry) {
|
|
450
|
+
entry.onDelta = options.onDelta;
|
|
451
|
+
const signal = options.signal;
|
|
452
|
+
if (signal) {
|
|
453
|
+
const abort = () => {
|
|
454
|
+
void cancel(id).catch(() => void 0);
|
|
455
|
+
};
|
|
456
|
+
if (signal.aborted) abort();
|
|
457
|
+
else {
|
|
458
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
459
|
+
entry.cleanup = () => signal.removeEventListener("abort", abort);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return Object.assign(promise, { requestId: id });
|
|
464
|
+
}
|
|
465
|
+
function cancel(requestId) {
|
|
466
|
+
return sendRequest("llm.cancel", { requestId }, REQUEST_TIMEOUT_MS);
|
|
467
|
+
}
|
|
468
|
+
function installLlmShim() {
|
|
469
|
+
if (installed) return () => void 0;
|
|
470
|
+
installed = true;
|
|
471
|
+
let disposed = false;
|
|
472
|
+
return () => {
|
|
473
|
+
if (disposed) return;
|
|
474
|
+
disposed = true;
|
|
475
|
+
for (const [id, entry] of pending) {
|
|
476
|
+
settle(id, entry);
|
|
477
|
+
entry.reject(new Error("llm shim disposed"));
|
|
478
|
+
}
|
|
479
|
+
installed = false;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
|
|
305
483
|
// ../nap/dist/chunk-LNFGQGQD.js
|
|
306
484
|
function createGamepadStateTools() {
|
|
307
485
|
function record(value) {
|
|
@@ -350,7 +528,7 @@ var NappletShimPrelude = (() => {
|
|
|
350
528
|
return tools.copyGamepadState(state2);
|
|
351
529
|
}
|
|
352
530
|
var state = { available: true, focused: false, pads: [] };
|
|
353
|
-
var
|
|
531
|
+
var installed2 = false;
|
|
354
532
|
var subscribed = false;
|
|
355
533
|
var handlers = /* @__PURE__ */ new Set();
|
|
356
534
|
function subscribe() {
|
|
@@ -409,8 +587,8 @@ var NappletShimPrelude = (() => {
|
|
|
409
587
|
}
|
|
410
588
|
}
|
|
411
589
|
function installGamepadShim() {
|
|
412
|
-
if (
|
|
413
|
-
|
|
590
|
+
if (installed2) return () => void 0;
|
|
591
|
+
installed2 = true;
|
|
414
592
|
let closed = false;
|
|
415
593
|
return () => {
|
|
416
594
|
if (closed) return;
|
|
@@ -419,7 +597,7 @@ var NappletShimPrelude = (() => {
|
|
|
419
597
|
if (subscribed) postToShell({ type: "gamepad.unsubscribe" });
|
|
420
598
|
} finally {
|
|
421
599
|
subscribed = false;
|
|
422
|
-
|
|
600
|
+
installed2 = false;
|
|
423
601
|
handlers.clear();
|
|
424
602
|
state = { available: true, focused: false, pads: [] };
|
|
425
603
|
}
|
|
@@ -427,7 +605,7 @@ var NappletShimPrelude = (() => {
|
|
|
427
605
|
}
|
|
428
606
|
|
|
429
607
|
// ../nap/dist/chunk-ALQSWWJK.js
|
|
430
|
-
var
|
|
608
|
+
var installed3 = false;
|
|
431
609
|
var environment;
|
|
432
610
|
var readyHandlers = /* @__PURE__ */ new Set();
|
|
433
611
|
var waiters = /* @__PURE__ */ new Set();
|
|
@@ -470,11 +648,11 @@ var NappletShimPrelude = (() => {
|
|
|
470
648
|
for (const callback of callbacks) callback(environment);
|
|
471
649
|
}
|
|
472
650
|
function installShellShim() {
|
|
473
|
-
if (
|
|
474
|
-
|
|
651
|
+
if (installed3) return () => void 0;
|
|
652
|
+
installed3 = true;
|
|
475
653
|
postToShell({ type: "shell.ready" });
|
|
476
654
|
return () => {
|
|
477
|
-
|
|
655
|
+
installed3 = false;
|
|
478
656
|
environment = void 0;
|
|
479
657
|
readyHandlers.clear();
|
|
480
658
|
waiters.clear();
|
|
@@ -485,7 +663,7 @@ var NappletShimPrelude = (() => {
|
|
|
485
663
|
var suppressMap = /* @__PURE__ */ new Map();
|
|
486
664
|
var actionHandlers = /* @__PURE__ */ new Map();
|
|
487
665
|
var pendingRegistrations = /* @__PURE__ */ new Map();
|
|
488
|
-
var
|
|
666
|
+
var installed4 = false;
|
|
489
667
|
var activeCleanup = null;
|
|
490
668
|
var RESERVED_KEYS = /* @__PURE__ */ new Set(["Tab", "Shift+Tab", "Escape"]);
|
|
491
669
|
function isMessageType(msg, type) {
|
|
@@ -537,14 +715,14 @@ var NappletShimPrelude = (() => {
|
|
|
537
715
|
}
|
|
538
716
|
}
|
|
539
717
|
function handleRegisterResult(msg) {
|
|
540
|
-
const
|
|
541
|
-
if (!
|
|
718
|
+
const pending5 = pendingRegistrations.get(msg.id);
|
|
719
|
+
if (!pending5) return;
|
|
542
720
|
pendingRegistrations.delete(msg.id);
|
|
543
721
|
if (msg.error) {
|
|
544
|
-
|
|
722
|
+
pending5.reject(new Error(msg.error));
|
|
545
723
|
return;
|
|
546
724
|
}
|
|
547
|
-
|
|
725
|
+
pending5.resolve({
|
|
548
726
|
actionId: msg.actionId,
|
|
549
727
|
binding: msg.binding
|
|
550
728
|
});
|
|
@@ -632,17 +810,17 @@ var NappletShimPrelude = (() => {
|
|
|
632
810
|
};
|
|
633
811
|
}
|
|
634
812
|
function installKeysShim() {
|
|
635
|
-
if (
|
|
813
|
+
if (installed4 && activeCleanup) {
|
|
636
814
|
return activeCleanup;
|
|
637
815
|
}
|
|
638
816
|
document.addEventListener("keydown", handleKeydown, true);
|
|
639
|
-
|
|
817
|
+
installed4 = true;
|
|
640
818
|
activeCleanup = () => {
|
|
641
819
|
document.removeEventListener("keydown", handleKeydown, true);
|
|
642
820
|
suppressMap.clear();
|
|
643
821
|
actionHandlers.clear();
|
|
644
822
|
pendingRegistrations.clear();
|
|
645
|
-
|
|
823
|
+
installed4 = false;
|
|
646
824
|
activeCleanup = null;
|
|
647
825
|
};
|
|
648
826
|
return activeCleanup;
|
|
@@ -654,20 +832,20 @@ var NappletShimPrelude = (() => {
|
|
|
654
832
|
var controlsHandlers = /* @__PURE__ */ new Map();
|
|
655
833
|
var stateHandlers = /* @__PURE__ */ new Map();
|
|
656
834
|
var capabilitiesHandlers = /* @__PURE__ */ new Map();
|
|
657
|
-
var
|
|
835
|
+
var installed5 = false;
|
|
658
836
|
function isMessageType2(msg, type) {
|
|
659
837
|
return msg.type === type;
|
|
660
838
|
}
|
|
661
839
|
function handleCreateResult(msg) {
|
|
662
|
-
const
|
|
663
|
-
if (!
|
|
840
|
+
const pending5 = pendingCreates.get(msg.id);
|
|
841
|
+
if (!pending5) return;
|
|
664
842
|
pendingCreates.delete(msg.id);
|
|
665
|
-
clearTimeout(
|
|
843
|
+
clearTimeout(pending5.timeout);
|
|
666
844
|
const result = {};
|
|
667
845
|
if (msg.sessionId !== void 0) result.sessionId = msg.sessionId;
|
|
668
846
|
if (msg.owner !== void 0) result.owner = msg.owner;
|
|
669
847
|
if (msg.error !== void 0) result.error = msg.error;
|
|
670
|
-
|
|
848
|
+
pending5.resolve(result);
|
|
671
849
|
}
|
|
672
850
|
function handleCommand(msg) {
|
|
673
851
|
const handlers3 = commandHandlers.get(msg.sessionId);
|
|
@@ -838,54 +1016,54 @@ var NappletShimPrelude = (() => {
|
|
|
838
1016
|
};
|
|
839
1017
|
}
|
|
840
1018
|
function installMediaShim() {
|
|
841
|
-
if (
|
|
1019
|
+
if (installed5) {
|
|
842
1020
|
return () => void 0;
|
|
843
1021
|
}
|
|
844
|
-
|
|
1022
|
+
installed5 = true;
|
|
845
1023
|
return () => {
|
|
846
|
-
for (const
|
|
847
|
-
clearTimeout(
|
|
1024
|
+
for (const pending5 of pendingCreates.values()) {
|
|
1025
|
+
clearTimeout(pending5.timeout);
|
|
848
1026
|
}
|
|
849
1027
|
pendingCreates.clear();
|
|
850
1028
|
commandHandlers.clear();
|
|
851
1029
|
controlsHandlers.clear();
|
|
852
1030
|
stateHandlers.clear();
|
|
853
1031
|
capabilitiesHandlers.clear();
|
|
854
|
-
|
|
1032
|
+
installed5 = false;
|
|
855
1033
|
};
|
|
856
1034
|
}
|
|
857
1035
|
|
|
858
1036
|
// ../nap/dist/chunk-2THSWWB3.js
|
|
859
|
-
var
|
|
1037
|
+
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
860
1038
|
var pendingSends = /* @__PURE__ */ new Map();
|
|
861
1039
|
var pendingPermissions = /* @__PURE__ */ new Map();
|
|
862
1040
|
var actionHandlers2 = /* @__PURE__ */ new Set();
|
|
863
1041
|
var clickedHandlers = /* @__PURE__ */ new Set();
|
|
864
1042
|
var dismissedHandlers = /* @__PURE__ */ new Set();
|
|
865
1043
|
var controlsHandlers2 = /* @__PURE__ */ new Set();
|
|
866
|
-
var
|
|
1044
|
+
var installed6 = false;
|
|
867
1045
|
function isMessageType3(msg, type) {
|
|
868
1046
|
return msg.type === type;
|
|
869
1047
|
}
|
|
870
1048
|
function handleSendResult(msg) {
|
|
871
|
-
const
|
|
872
|
-
if (!
|
|
1049
|
+
const pending5 = pendingSends.get(msg.id);
|
|
1050
|
+
if (!pending5) return;
|
|
873
1051
|
pendingSends.delete(msg.id);
|
|
874
1052
|
if (msg.error) {
|
|
875
|
-
|
|
1053
|
+
pending5.reject(new Error(msg.error));
|
|
876
1054
|
return;
|
|
877
1055
|
}
|
|
878
1056
|
if (msg.notificationId) {
|
|
879
|
-
|
|
1057
|
+
pending5.resolve({ notificationId: msg.notificationId });
|
|
880
1058
|
} else {
|
|
881
|
-
|
|
1059
|
+
pending5.reject(new Error("notify.send.result missing notificationId"));
|
|
882
1060
|
}
|
|
883
1061
|
}
|
|
884
1062
|
function handlePermissionResult(msg) {
|
|
885
|
-
const
|
|
886
|
-
if (!
|
|
1063
|
+
const pending5 = pendingPermissions.get(msg.id);
|
|
1064
|
+
if (!pending5) return;
|
|
887
1065
|
pendingPermissions.delete(msg.id);
|
|
888
|
-
|
|
1066
|
+
pending5.resolve({ granted: msg.granted });
|
|
889
1067
|
}
|
|
890
1068
|
function handleAction2(msg) {
|
|
891
1069
|
for (const cb of actionHandlers2) {
|
|
@@ -936,7 +1114,7 @@ var NappletShimPrelude = (() => {
|
|
|
936
1114
|
if (pendingSends.delete(id)) {
|
|
937
1115
|
reject(new Error("notify.send timed out"));
|
|
938
1116
|
}
|
|
939
|
-
},
|
|
1117
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
940
1118
|
});
|
|
941
1119
|
}
|
|
942
1120
|
function dismiss(notificationId) {
|
|
@@ -974,7 +1152,7 @@ var NappletShimPrelude = (() => {
|
|
|
974
1152
|
if (pendingPermissions.delete(id)) {
|
|
975
1153
|
reject(new Error("notify.permission.request timed out"));
|
|
976
1154
|
}
|
|
977
|
-
},
|
|
1155
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
978
1156
|
});
|
|
979
1157
|
}
|
|
980
1158
|
function onAction2(callback) {
|
|
@@ -1010,10 +1188,10 @@ var NappletShimPrelude = (() => {
|
|
|
1010
1188
|
};
|
|
1011
1189
|
}
|
|
1012
1190
|
function installNotifyShim() {
|
|
1013
|
-
if (
|
|
1191
|
+
if (installed6) {
|
|
1014
1192
|
return () => void 0;
|
|
1015
1193
|
}
|
|
1016
|
-
|
|
1194
|
+
installed6 = true;
|
|
1017
1195
|
return () => {
|
|
1018
1196
|
pendingSends.clear();
|
|
1019
1197
|
pendingPermissions.clear();
|
|
@@ -1021,13 +1199,13 @@ var NappletShimPrelude = (() => {
|
|
|
1021
1199
|
clickedHandlers.clear();
|
|
1022
1200
|
dismissedHandlers.clear();
|
|
1023
1201
|
controlsHandlers2.clear();
|
|
1024
|
-
|
|
1202
|
+
installed6 = false;
|
|
1025
1203
|
};
|
|
1026
1204
|
}
|
|
1027
1205
|
|
|
1028
1206
|
// ../nap/dist/chunk-Q2OL6E2V.js
|
|
1029
1207
|
var pendingResponses = /* @__PURE__ */ new Map();
|
|
1030
|
-
var
|
|
1208
|
+
var REQUEST_TIMEOUT_MS3 = 5e3;
|
|
1031
1209
|
function handleStateResponse(event) {
|
|
1032
1210
|
if (event.source !== window.parent) return;
|
|
1033
1211
|
const msg = event.data;
|
|
@@ -1035,14 +1213,14 @@ var NappletShimPrelude = (() => {
|
|
|
1035
1213
|
if (!msg.type.startsWith("storage.") || !msg.type.endsWith(".result")) return;
|
|
1036
1214
|
const id = msg.id;
|
|
1037
1215
|
if (!id) return;
|
|
1038
|
-
const
|
|
1039
|
-
if (!
|
|
1216
|
+
const pending5 = pendingResponses.get(id);
|
|
1217
|
+
if (!pending5) return;
|
|
1040
1218
|
pendingResponses.delete(id);
|
|
1041
1219
|
if (msg.error) {
|
|
1042
|
-
|
|
1220
|
+
pending5.reject(new Error(msg.error));
|
|
1043
1221
|
return;
|
|
1044
1222
|
}
|
|
1045
|
-
|
|
1223
|
+
pending5.resolve(msg);
|
|
1046
1224
|
}
|
|
1047
1225
|
function sendStorageRequest(message) {
|
|
1048
1226
|
return new Promise((resolve, reject) => {
|
|
@@ -1052,7 +1230,7 @@ var NappletShimPrelude = (() => {
|
|
|
1052
1230
|
if (pendingResponses.delete(message.id)) {
|
|
1053
1231
|
reject(new Error("State request timed out"));
|
|
1054
1232
|
}
|
|
1055
|
-
},
|
|
1233
|
+
}, REQUEST_TIMEOUT_MS3);
|
|
1056
1234
|
});
|
|
1057
1235
|
}
|
|
1058
1236
|
async function getItemScoped(key, scope) {
|
|
@@ -1175,10 +1353,10 @@ var NappletShimPrelude = (() => {
|
|
|
1175
1353
|
}
|
|
1176
1354
|
|
|
1177
1355
|
// ../nap/dist/chunk-DMVIO3SO.js
|
|
1178
|
-
var
|
|
1356
|
+
var REQUEST_TIMEOUT_MS4 = 3e4;
|
|
1179
1357
|
var pendingRequests = /* @__PURE__ */ new Map();
|
|
1180
1358
|
var changeHandlers = /* @__PURE__ */ new Set();
|
|
1181
|
-
var
|
|
1359
|
+
var installed7 = false;
|
|
1182
1360
|
var IDENTITY_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
1183
1361
|
"identity.getPublicKey.result",
|
|
1184
1362
|
"identity.getRelays.result",
|
|
@@ -1253,21 +1431,21 @@ var NappletShimPrelude = (() => {
|
|
|
1253
1431
|
}
|
|
1254
1432
|
}
|
|
1255
1433
|
function resolvePending(id, value) {
|
|
1256
|
-
const
|
|
1257
|
-
if (!
|
|
1434
|
+
const pending5 = pendingRequests.get(id);
|
|
1435
|
+
if (!pending5) return;
|
|
1258
1436
|
pendingRequests.delete(id);
|
|
1259
|
-
clearTimeout(
|
|
1260
|
-
|
|
1437
|
+
clearTimeout(pending5.timeout);
|
|
1438
|
+
pending5.resolve(value);
|
|
1261
1439
|
}
|
|
1262
1440
|
function resolveOrReject(id, value, error) {
|
|
1263
|
-
const
|
|
1264
|
-
if (!
|
|
1441
|
+
const pending5 = pendingRequests.get(id);
|
|
1442
|
+
if (!pending5) return;
|
|
1265
1443
|
pendingRequests.delete(id);
|
|
1266
|
-
clearTimeout(
|
|
1444
|
+
clearTimeout(pending5.timeout);
|
|
1267
1445
|
if (error) {
|
|
1268
|
-
|
|
1446
|
+
pending5.reject(new Error(error));
|
|
1269
1447
|
} else {
|
|
1270
|
-
|
|
1448
|
+
pending5.resolve(value);
|
|
1271
1449
|
}
|
|
1272
1450
|
}
|
|
1273
1451
|
function notifyChanged(pubkey) {
|
|
@@ -1276,13 +1454,13 @@ var NappletShimPrelude = (() => {
|
|
|
1276
1454
|
handler(pubkey);
|
|
1277
1455
|
}
|
|
1278
1456
|
}
|
|
1279
|
-
function
|
|
1457
|
+
function sendRequest2(msg) {
|
|
1280
1458
|
return new Promise((resolve, reject) => {
|
|
1281
1459
|
const timeout = setTimeout(() => {
|
|
1282
1460
|
if (pendingRequests.delete(msg.id)) {
|
|
1283
1461
|
reject(new Error(\`\${msg.type} timed out\`));
|
|
1284
1462
|
}
|
|
1285
|
-
},
|
|
1463
|
+
}, REQUEST_TIMEOUT_MS4);
|
|
1286
1464
|
pendingRequests.set(msg.id, {
|
|
1287
1465
|
resolve,
|
|
1288
1466
|
reject,
|
|
@@ -1298,7 +1476,7 @@ var NappletShimPrelude = (() => {
|
|
|
1298
1476
|
type: "identity.getPublicKey",
|
|
1299
1477
|
id: crypto.randomUUID()
|
|
1300
1478
|
};
|
|
1301
|
-
return
|
|
1479
|
+
return sendRequest2(msg);
|
|
1302
1480
|
}
|
|
1303
1481
|
function onChanged(handler) {
|
|
1304
1482
|
changeHandlers.add(handler);
|
|
@@ -1316,21 +1494,21 @@ var NappletShimPrelude = (() => {
|
|
|
1316
1494
|
type: "identity.getRelays",
|
|
1317
1495
|
id: crypto.randomUUID()
|
|
1318
1496
|
};
|
|
1319
|
-
return
|
|
1497
|
+
return sendRequest2(msg);
|
|
1320
1498
|
}
|
|
1321
1499
|
function getProfile() {
|
|
1322
1500
|
const msg = {
|
|
1323
1501
|
type: "identity.getProfile",
|
|
1324
1502
|
id: crypto.randomUUID()
|
|
1325
1503
|
};
|
|
1326
|
-
return
|
|
1504
|
+
return sendRequest2(msg);
|
|
1327
1505
|
}
|
|
1328
1506
|
function getFollows() {
|
|
1329
1507
|
const msg = {
|
|
1330
1508
|
type: "identity.getFollows",
|
|
1331
1509
|
id: crypto.randomUUID()
|
|
1332
1510
|
};
|
|
1333
|
-
return
|
|
1511
|
+
return sendRequest2(msg);
|
|
1334
1512
|
}
|
|
1335
1513
|
function getList(listType) {
|
|
1336
1514
|
const msg = {
|
|
@@ -1338,56 +1516,56 @@ var NappletShimPrelude = (() => {
|
|
|
1338
1516
|
id: crypto.randomUUID(),
|
|
1339
1517
|
listType
|
|
1340
1518
|
};
|
|
1341
|
-
return
|
|
1519
|
+
return sendRequest2(msg);
|
|
1342
1520
|
}
|
|
1343
1521
|
function getZaps() {
|
|
1344
1522
|
const msg = {
|
|
1345
1523
|
type: "identity.getZaps",
|
|
1346
1524
|
id: crypto.randomUUID()
|
|
1347
1525
|
};
|
|
1348
|
-
return
|
|
1526
|
+
return sendRequest2(msg);
|
|
1349
1527
|
}
|
|
1350
1528
|
function getMutes() {
|
|
1351
1529
|
const msg = {
|
|
1352
1530
|
type: "identity.getMutes",
|
|
1353
1531
|
id: crypto.randomUUID()
|
|
1354
1532
|
};
|
|
1355
|
-
return
|
|
1533
|
+
return sendRequest2(msg);
|
|
1356
1534
|
}
|
|
1357
1535
|
function getBlocked() {
|
|
1358
1536
|
const msg = {
|
|
1359
1537
|
type: "identity.getBlocked",
|
|
1360
1538
|
id: crypto.randomUUID()
|
|
1361
1539
|
};
|
|
1362
|
-
return
|
|
1540
|
+
return sendRequest2(msg);
|
|
1363
1541
|
}
|
|
1364
1542
|
function getBadges() {
|
|
1365
1543
|
const msg = {
|
|
1366
1544
|
type: "identity.getBadges",
|
|
1367
1545
|
id: crypto.randomUUID()
|
|
1368
1546
|
};
|
|
1369
|
-
return
|
|
1547
|
+
return sendRequest2(msg);
|
|
1370
1548
|
}
|
|
1371
1549
|
function installIdentityShim() {
|
|
1372
|
-
if (
|
|
1550
|
+
if (installed7) {
|
|
1373
1551
|
return () => void 0;
|
|
1374
1552
|
}
|
|
1375
|
-
|
|
1553
|
+
installed7 = true;
|
|
1376
1554
|
return () => {
|
|
1377
|
-
for (const
|
|
1378
|
-
clearTimeout(
|
|
1555
|
+
for (const pending5 of pendingRequests.values()) {
|
|
1556
|
+
clearTimeout(pending5.timeout);
|
|
1379
1557
|
}
|
|
1380
1558
|
pendingRequests.clear();
|
|
1381
1559
|
changeHandlers.clear();
|
|
1382
|
-
|
|
1560
|
+
installed7 = false;
|
|
1383
1561
|
};
|
|
1384
1562
|
}
|
|
1385
1563
|
|
|
1386
1564
|
// ../nap/dist/chunk-K4GHL555.js
|
|
1387
|
-
var
|
|
1565
|
+
var REQUEST_TIMEOUT_MS5 = 3e4;
|
|
1388
1566
|
var pendingRequests2 = /* @__PURE__ */ new Map();
|
|
1389
1567
|
var changeHandlers2 = /* @__PURE__ */ new Set();
|
|
1390
|
-
var
|
|
1568
|
+
var installed8 = false;
|
|
1391
1569
|
var THEME_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
1392
1570
|
"theme.get.result",
|
|
1393
1571
|
"theme.changed",
|
|
@@ -1413,14 +1591,14 @@ var NappletShimPrelude = (() => {
|
|
|
1413
1591
|
}
|
|
1414
1592
|
}
|
|
1415
1593
|
function resolveOrReject2(id, value, error) {
|
|
1416
|
-
const
|
|
1417
|
-
if (!
|
|
1594
|
+
const pending5 = pendingRequests2.get(id);
|
|
1595
|
+
if (!pending5) return;
|
|
1418
1596
|
pendingRequests2.delete(id);
|
|
1419
|
-
clearTimeout(
|
|
1597
|
+
clearTimeout(pending5.timeout);
|
|
1420
1598
|
if (error) {
|
|
1421
|
-
|
|
1599
|
+
pending5.reject(new Error(error));
|
|
1422
1600
|
} else {
|
|
1423
|
-
|
|
1601
|
+
pending5.resolve(value);
|
|
1424
1602
|
}
|
|
1425
1603
|
}
|
|
1426
1604
|
function notifyChanged2(theme) {
|
|
@@ -1428,13 +1606,13 @@ var NappletShimPrelude = (() => {
|
|
|
1428
1606
|
handler(theme);
|
|
1429
1607
|
}
|
|
1430
1608
|
}
|
|
1431
|
-
function
|
|
1609
|
+
function sendRequest3(msg) {
|
|
1432
1610
|
return new Promise((resolve, reject) => {
|
|
1433
1611
|
const timeout = setTimeout(() => {
|
|
1434
1612
|
if (pendingRequests2.delete(msg.id)) {
|
|
1435
1613
|
reject(new Error(\`\${msg.type} timed out\`));
|
|
1436
1614
|
}
|
|
1437
|
-
},
|
|
1615
|
+
}, REQUEST_TIMEOUT_MS5);
|
|
1438
1616
|
pendingRequests2.set(msg.id, {
|
|
1439
1617
|
resolve,
|
|
1440
1618
|
reject,
|
|
@@ -1450,7 +1628,7 @@ var NappletShimPrelude = (() => {
|
|
|
1450
1628
|
type: "theme.get",
|
|
1451
1629
|
id: crypto.randomUUID()
|
|
1452
1630
|
};
|
|
1453
|
-
return
|
|
1631
|
+
return sendRequest3(msg);
|
|
1454
1632
|
}
|
|
1455
1633
|
function onChanged2(handler) {
|
|
1456
1634
|
changeHandlers2.add(handler);
|
|
@@ -1464,17 +1642,17 @@ var NappletShimPrelude = (() => {
|
|
|
1464
1642
|
};
|
|
1465
1643
|
}
|
|
1466
1644
|
function installThemeShim() {
|
|
1467
|
-
if (
|
|
1645
|
+
if (installed8) {
|
|
1468
1646
|
return () => void 0;
|
|
1469
1647
|
}
|
|
1470
|
-
|
|
1648
|
+
installed8 = true;
|
|
1471
1649
|
return () => {
|
|
1472
|
-
for (const
|
|
1473
|
-
clearTimeout(
|
|
1650
|
+
for (const pending5 of pendingRequests2.values()) {
|
|
1651
|
+
clearTimeout(pending5.timeout);
|
|
1474
1652
|
}
|
|
1475
1653
|
pendingRequests2.clear();
|
|
1476
1654
|
changeHandlers2.clear();
|
|
1477
|
-
|
|
1655
|
+
installed8 = false;
|
|
1478
1656
|
};
|
|
1479
1657
|
}
|
|
1480
1658
|
|
|
@@ -1527,7 +1705,7 @@ var NappletShimPrelude = (() => {
|
|
|
1527
1705
|
}
|
|
1528
1706
|
|
|
1529
1707
|
// ../nap/dist/chunk-7SQ43TNY.js
|
|
1530
|
-
var
|
|
1708
|
+
var REQUEST_TIMEOUT_MS6 = 3e4;
|
|
1531
1709
|
var MAX_RETAINED_OPENED = 100;
|
|
1532
1710
|
var MAX_RETAINED_EVENTS = 100;
|
|
1533
1711
|
var topicHandlers = /* @__PURE__ */ new Map();
|
|
@@ -1672,7 +1850,7 @@ var NappletShimPrelude = (() => {
|
|
|
1672
1850
|
return new Promise((resolve, reject) => {
|
|
1673
1851
|
const timeout = setTimeout(() => {
|
|
1674
1852
|
if (pendingOpen.delete(id)) reject(new Error("inc.channel.open timed out"));
|
|
1675
|
-
},
|
|
1853
|
+
}, REQUEST_TIMEOUT_MS6);
|
|
1676
1854
|
pendingOpen.set(id, { target, resolve, reject, timeout });
|
|
1677
1855
|
const message = {
|
|
1678
1856
|
type: "inc.channel.open",
|
|
@@ -1699,7 +1877,7 @@ var NappletShimPrelude = (() => {
|
|
|
1699
1877
|
return new Promise((resolve, reject) => {
|
|
1700
1878
|
const timeout = setTimeout(() => {
|
|
1701
1879
|
if (pendingList.delete(id)) reject(new Error("inc.channel.list timed out"));
|
|
1702
|
-
},
|
|
1880
|
+
}, REQUEST_TIMEOUT_MS6);
|
|
1703
1881
|
pendingList.set(id, { resolve, reject, timeout });
|
|
1704
1882
|
const message = {
|
|
1705
1883
|
type: "inc.channel.list",
|
|
@@ -1731,15 +1909,15 @@ var NappletShimPrelude = (() => {
|
|
|
1731
1909
|
for (const callback of handlers3) callback(event);
|
|
1732
1910
|
}
|
|
1733
1911
|
function handleOpenResult(msg) {
|
|
1734
|
-
const
|
|
1735
|
-
if (!
|
|
1912
|
+
const pending5 = pendingOpen.get(msg.id);
|
|
1913
|
+
if (!pending5) return;
|
|
1736
1914
|
pendingOpen.delete(msg.id);
|
|
1737
|
-
clearTimeout(
|
|
1915
|
+
clearTimeout(pending5.timeout);
|
|
1738
1916
|
if (!msg.channelId) {
|
|
1739
|
-
|
|
1917
|
+
pending5.reject(new Error(msg.error ?? "inc.channel.open failed"));
|
|
1740
1918
|
return;
|
|
1741
1919
|
}
|
|
1742
|
-
|
|
1920
|
+
pending5.resolve(createHandle(msg.channelId, msg.peer ?? pending5.target));
|
|
1743
1921
|
}
|
|
1744
1922
|
function handleOpened(msg) {
|
|
1745
1923
|
retainOpened(createHandle(msg.channelId, msg.peer));
|
|
@@ -1763,11 +1941,11 @@ var NappletShimPrelude = (() => {
|
|
|
1763
1941
|
state2.events.push(event);
|
|
1764
1942
|
}
|
|
1765
1943
|
function handleListResult(msg) {
|
|
1766
|
-
const
|
|
1767
|
-
if (!
|
|
1944
|
+
const pending5 = pendingList.get(msg.id);
|
|
1945
|
+
if (!pending5) return;
|
|
1768
1946
|
pendingList.delete(msg.id);
|
|
1769
|
-
clearTimeout(
|
|
1770
|
-
|
|
1947
|
+
clearTimeout(pending5.timeout);
|
|
1948
|
+
pending5.resolve(msg.channels);
|
|
1771
1949
|
}
|
|
1772
1950
|
function handleClosed(msg) {
|
|
1773
1951
|
const state2 = channels.get(msg.channelId);
|
|
@@ -1838,13 +2016,13 @@ var NappletShimPrelude = (() => {
|
|
|
1838
2016
|
}
|
|
1839
2017
|
function installIncShim() {
|
|
1840
2018
|
return () => {
|
|
1841
|
-
for (const
|
|
1842
|
-
clearTimeout(
|
|
1843
|
-
|
|
2019
|
+
for (const pending5 of pendingOpen.values()) {
|
|
2020
|
+
clearTimeout(pending5.timeout);
|
|
2021
|
+
pending5.reject(new Error("INC shim disposed"));
|
|
1844
2022
|
}
|
|
1845
|
-
for (const
|
|
1846
|
-
clearTimeout(
|
|
1847
|
-
|
|
2023
|
+
for (const pending5 of pendingList.values()) {
|
|
2024
|
+
clearTimeout(pending5.timeout);
|
|
2025
|
+
pending5.reject(new Error("INC shim disposed"));
|
|
1848
2026
|
}
|
|
1849
2027
|
for (const state2 of channels.values()) closeState(state2, "endpoint destroyed", true);
|
|
1850
2028
|
pendingOpen.clear();
|
|
@@ -1860,14 +2038,14 @@ var NappletShimPrelude = (() => {
|
|
|
1860
2038
|
function isMessageType4(msg, type) {
|
|
1861
2039
|
return msg.type === type;
|
|
1862
2040
|
}
|
|
1863
|
-
var
|
|
2041
|
+
var REQUEST_TIMEOUT_MS7 = 3e4;
|
|
1864
2042
|
var currentSchema = null;
|
|
1865
2043
|
var lastValues = null;
|
|
1866
2044
|
var subscribers = /* @__PURE__ */ new Set();
|
|
1867
2045
|
var schemaErrorHandlers = /* @__PURE__ */ new Set();
|
|
1868
2046
|
var pendingGets = /* @__PURE__ */ new Map();
|
|
1869
2047
|
var pendingRegistrations2 = /* @__PURE__ */ new Map();
|
|
1870
|
-
var
|
|
2048
|
+
var installed9 = false;
|
|
1871
2049
|
function handleConfigMessage(msg) {
|
|
1872
2050
|
if (isMessageType4(msg, "config.registerSchema.result")) {
|
|
1873
2051
|
handleRegisterSchemaResult(msg);
|
|
@@ -1878,25 +2056,25 @@ var NappletShimPrelude = (() => {
|
|
|
1878
2056
|
}
|
|
1879
2057
|
}
|
|
1880
2058
|
function handleRegisterSchemaResult(msg) {
|
|
1881
|
-
const
|
|
1882
|
-
if (!
|
|
2059
|
+
const pending5 = pendingRegistrations2.get(msg.id);
|
|
2060
|
+
if (!pending5) return;
|
|
1883
2061
|
pendingRegistrations2.delete(msg.id);
|
|
1884
2062
|
if (msg.ok) {
|
|
1885
|
-
currentSchema =
|
|
1886
|
-
|
|
2063
|
+
currentSchema = pending5.schema;
|
|
2064
|
+
pending5.resolve();
|
|
1887
2065
|
} else {
|
|
1888
2066
|
const code = msg.code ?? "invalid-schema";
|
|
1889
2067
|
const error = msg.error ?? "schema rejected";
|
|
1890
|
-
|
|
2068
|
+
pending5.reject(new Error(\`\${code}: \${error}\`));
|
|
1891
2069
|
}
|
|
1892
2070
|
}
|
|
1893
2071
|
function handleValues(msg) {
|
|
1894
2072
|
lastValues = msg.values;
|
|
1895
2073
|
if (typeof msg.id === "string") {
|
|
1896
|
-
const
|
|
1897
|
-
if (!
|
|
2074
|
+
const pending5 = pendingGets.get(msg.id);
|
|
2075
|
+
if (!pending5) return;
|
|
1898
2076
|
pendingGets.delete(msg.id);
|
|
1899
|
-
|
|
2077
|
+
pending5.resolve(msg.values);
|
|
1900
2078
|
return;
|
|
1901
2079
|
}
|
|
1902
2080
|
for (const cb of subscribers) {
|
|
@@ -1925,7 +2103,7 @@ var NappletShimPrelude = (() => {
|
|
|
1925
2103
|
if (pendingRegistrations2.delete(id)) {
|
|
1926
2104
|
reject(new Error("config.registerSchema timed out"));
|
|
1927
2105
|
}
|
|
1928
|
-
},
|
|
2106
|
+
}, REQUEST_TIMEOUT_MS7);
|
|
1929
2107
|
});
|
|
1930
2108
|
}
|
|
1931
2109
|
function get2() {
|
|
@@ -1938,7 +2116,7 @@ var NappletShimPrelude = (() => {
|
|
|
1938
2116
|
if (pendingGets.delete(id)) {
|
|
1939
2117
|
reject(new Error("config.get timed out"));
|
|
1940
2118
|
}
|
|
1941
|
-
},
|
|
2119
|
+
}, REQUEST_TIMEOUT_MS7);
|
|
1942
2120
|
});
|
|
1943
2121
|
}
|
|
1944
2122
|
function subscribe2(callback) {
|
|
@@ -1980,7 +2158,7 @@ var NappletShimPrelude = (() => {
|
|
|
1980
2158
|
};
|
|
1981
2159
|
}
|
|
1982
2160
|
function installConfigShim() {
|
|
1983
|
-
if (
|
|
2161
|
+
if (installed9) {
|
|
1984
2162
|
return () => void 0;
|
|
1985
2163
|
}
|
|
1986
2164
|
const configWindow = window;
|
|
@@ -1998,7 +2176,7 @@ var NappletShimPrelude = (() => {
|
|
|
1998
2176
|
configurable: false
|
|
1999
2177
|
});
|
|
2000
2178
|
napplet.config = api;
|
|
2001
|
-
|
|
2179
|
+
installed9 = true;
|
|
2002
2180
|
return () => {
|
|
2003
2181
|
subscribers.clear();
|
|
2004
2182
|
schemaErrorHandlers.clear();
|
|
@@ -2007,17 +2185,17 @@ var NappletShimPrelude = (() => {
|
|
|
2007
2185
|
lastValues = null;
|
|
2008
2186
|
currentSchema = null;
|
|
2009
2187
|
if (napplet.config === api) delete napplet.config;
|
|
2010
|
-
|
|
2188
|
+
installed9 = false;
|
|
2011
2189
|
};
|
|
2012
2190
|
}
|
|
2013
2191
|
|
|
2014
2192
|
// ../nap/dist/chunk-UVOJ27SS.js
|
|
2015
|
-
var
|
|
2193
|
+
var REQUEST_TIMEOUT_MS8 = 3e4;
|
|
2016
2194
|
var inflight = /* @__PURE__ */ new Map();
|
|
2017
2195
|
var pendingBytes = /* @__PURE__ */ new Map();
|
|
2018
2196
|
var pendingInfo = /* @__PURE__ */ new Map();
|
|
2019
2197
|
var pendingMany = /* @__PURE__ */ new Map();
|
|
2020
|
-
var
|
|
2198
|
+
var installed10 = false;
|
|
2021
2199
|
function isMessageType5(msg, type) {
|
|
2022
2200
|
return msg.type === type;
|
|
2023
2201
|
}
|
|
@@ -2072,7 +2250,7 @@ var NappletShimPrelude = (() => {
|
|
|
2072
2250
|
if (pendingInfo.delete(id)) {
|
|
2073
2251
|
reject(new Error("resource.info timed out"));
|
|
2074
2252
|
}
|
|
2075
|
-
},
|
|
2253
|
+
}, REQUEST_TIMEOUT_MS8);
|
|
2076
2254
|
pendingInfo.set(id, { resolve, reject, timeout });
|
|
2077
2255
|
const msg = {
|
|
2078
2256
|
type: "resource.info",
|
|
@@ -2087,7 +2265,7 @@ var NappletShimPrelude = (() => {
|
|
|
2087
2265
|
if (pendingBytes.delete(id)) {
|
|
2088
2266
|
reject(new Error(\`resource.bytes timed out for \${url}\`));
|
|
2089
2267
|
}
|
|
2090
|
-
},
|
|
2268
|
+
}, REQUEST_TIMEOUT_MS8);
|
|
2091
2269
|
pendingBytes.set(id, { resolve, reject, timeout });
|
|
2092
2270
|
const msg = {
|
|
2093
2271
|
type: "resource.bytes",
|
|
@@ -2104,7 +2282,7 @@ var NappletShimPrelude = (() => {
|
|
|
2104
2282
|
if (pendingMany.delete(id)) {
|
|
2105
2283
|
reject(new Error(\`resource.bytesMany timed out for \${requests.length} requests\`));
|
|
2106
2284
|
}
|
|
2107
|
-
},
|
|
2285
|
+
}, REQUEST_TIMEOUT_MS8);
|
|
2108
2286
|
pendingMany.set(id, { resolve, reject, timeout });
|
|
2109
2287
|
const msg = {
|
|
2110
2288
|
type: "resource.bytesMany",
|
|
@@ -2250,16 +2428,16 @@ var NappletShimPrelude = (() => {
|
|
|
2250
2428
|
});
|
|
2251
2429
|
}
|
|
2252
2430
|
function installResourceShim() {
|
|
2253
|
-
if (
|
|
2431
|
+
if (installed10) {
|
|
2254
2432
|
return () => void 0;
|
|
2255
2433
|
}
|
|
2256
|
-
|
|
2434
|
+
installed10 = true;
|
|
2257
2435
|
return () => {
|
|
2258
2436
|
inflight.clear();
|
|
2259
2437
|
pendingInfo.clear();
|
|
2260
2438
|
pendingBytes.clear();
|
|
2261
2439
|
pendingMany.clear();
|
|
2262
|
-
|
|
2440
|
+
installed10 = false;
|
|
2263
2441
|
};
|
|
2264
2442
|
}
|
|
2265
2443
|
function info() {
|
|
@@ -2342,7 +2520,7 @@ var NappletShimPrelude = (() => {
|
|
|
2342
2520
|
}
|
|
2343
2521
|
|
|
2344
2522
|
// ../nap/dist/chunk-BFHWB3MF.js
|
|
2345
|
-
var
|
|
2523
|
+
var REQUEST_TIMEOUT_MS9 = 3e4;
|
|
2346
2524
|
var pendingDiscover = /* @__PURE__ */ new Map();
|
|
2347
2525
|
var pendingRequest = /* @__PURE__ */ new Map();
|
|
2348
2526
|
var pendingClose = /* @__PURE__ */ new Map();
|
|
@@ -2351,9 +2529,9 @@ var NappletShimPrelude = (() => {
|
|
|
2351
2529
|
var pendingRegistryDescribe = /* @__PURE__ */ new Map();
|
|
2352
2530
|
var pendingRegistryCall = /* @__PURE__ */ new Map();
|
|
2353
2531
|
var eventHandlers = /* @__PURE__ */ new Set();
|
|
2354
|
-
var
|
|
2532
|
+
var installed11 = false;
|
|
2355
2533
|
function setInstalled(value) {
|
|
2356
|
-
|
|
2534
|
+
installed11 = value;
|
|
2357
2535
|
}
|
|
2358
2536
|
function isMessageType6(msg, type) {
|
|
2359
2537
|
return msg.type === type;
|
|
@@ -2477,7 +2655,7 @@ var NappletShimPrelude = (() => {
|
|
|
2477
2655
|
return new Promise((resolve, reject) => {
|
|
2478
2656
|
const timeout = setTimeout(() => {
|
|
2479
2657
|
if (pendingDiscover.delete(id)) reject(new Error("cvm.discover timed out"));
|
|
2480
|
-
},
|
|
2658
|
+
}, REQUEST_TIMEOUT_MS9);
|
|
2481
2659
|
pendingDiscover.set(id, { resolve, reject, timeout });
|
|
2482
2660
|
const msg = {
|
|
2483
2661
|
type: "cvm.discover",
|
|
@@ -2489,7 +2667,7 @@ var NappletShimPrelude = (() => {
|
|
|
2489
2667
|
}
|
|
2490
2668
|
function request(server, message, options) {
|
|
2491
2669
|
const id = crypto.randomUUID();
|
|
2492
|
-
const timeoutMs = options?.timeoutMs ??
|
|
2670
|
+
const timeoutMs = options?.timeoutMs ?? REQUEST_TIMEOUT_MS9;
|
|
2493
2671
|
return new Promise((resolve, reject) => {
|
|
2494
2672
|
const timeout = setTimeout(() => {
|
|
2495
2673
|
if (pendingRequest.delete(id)) reject(new Error("cvm.request timed out"));
|
|
@@ -2554,7 +2732,7 @@ var NappletShimPrelude = (() => {
|
|
|
2554
2732
|
return new Promise((resolve, reject) => {
|
|
2555
2733
|
const timeout = setTimeout(() => {
|
|
2556
2734
|
if (pendingClose.delete(id)) reject(new Error("cvm.close timed out"));
|
|
2557
|
-
},
|
|
2735
|
+
}, REQUEST_TIMEOUT_MS9);
|
|
2558
2736
|
pendingClose.set(id, { resolve, reject, timeout });
|
|
2559
2737
|
const msg = {
|
|
2560
2738
|
type: "cvm.close",
|
|
@@ -2577,7 +2755,7 @@ var NappletShimPrelude = (() => {
|
|
|
2577
2755
|
return new Promise((resolve, reject) => {
|
|
2578
2756
|
const timeout = setTimeout(() => {
|
|
2579
2757
|
if (pendingRegistryList.delete(id)) reject(new Error("cvm.registry.list timed out"));
|
|
2580
|
-
},
|
|
2758
|
+
}, REQUEST_TIMEOUT_MS9);
|
|
2581
2759
|
pendingRegistryList.set(id, { resolve, reject, timeout });
|
|
2582
2760
|
const msg = {
|
|
2583
2761
|
type: "cvm.registry.list",
|
|
@@ -2592,7 +2770,7 @@ var NappletShimPrelude = (() => {
|
|
|
2592
2770
|
return new Promise((resolve, reject) => {
|
|
2593
2771
|
const timeout = setTimeout(() => {
|
|
2594
2772
|
if (pendingRegistryHas.delete(id)) reject(new Error("cvm.registry.has timed out"));
|
|
2595
|
-
},
|
|
2773
|
+
}, REQUEST_TIMEOUT_MS9);
|
|
2596
2774
|
pendingRegistryHas.set(id, { resolve, reject, timeout });
|
|
2597
2775
|
const msg = {
|
|
2598
2776
|
type: "cvm.registry.has",
|
|
@@ -2608,7 +2786,7 @@ var NappletShimPrelude = (() => {
|
|
|
2608
2786
|
return new Promise((resolve, reject) => {
|
|
2609
2787
|
const timeout = setTimeout(() => {
|
|
2610
2788
|
if (pendingRegistryDescribe.delete(id)) reject(new Error("cvm.registry.describe timed out"));
|
|
2611
|
-
},
|
|
2789
|
+
}, REQUEST_TIMEOUT_MS9);
|
|
2612
2790
|
pendingRegistryDescribe.set(id, { resolve, reject, timeout });
|
|
2613
2791
|
const msg = {
|
|
2614
2792
|
type: "cvm.registry.describe",
|
|
@@ -2621,7 +2799,7 @@ var NappletShimPrelude = (() => {
|
|
|
2621
2799
|
}
|
|
2622
2800
|
function registryCall(family, tool, args, options) {
|
|
2623
2801
|
const id = crypto.randomUUID();
|
|
2624
|
-
const timeoutMs = options?.timeoutMs ??
|
|
2802
|
+
const timeoutMs = options?.timeoutMs ?? REQUEST_TIMEOUT_MS9;
|
|
2625
2803
|
return new Promise((resolve, reject) => {
|
|
2626
2804
|
const timeout = setTimeout(() => {
|
|
2627
2805
|
if (pendingRegistryCall.delete(id)) reject(new Error("cvm.registry.call timed out"));
|
|
@@ -2639,10 +2817,10 @@ var NappletShimPrelude = (() => {
|
|
|
2639
2817
|
});
|
|
2640
2818
|
}
|
|
2641
2819
|
function installCvmShim() {
|
|
2642
|
-
if (
|
|
2820
|
+
if (installed11) return () => void 0;
|
|
2643
2821
|
setInstalled(true);
|
|
2644
2822
|
return () => {
|
|
2645
|
-
for (const
|
|
2823
|
+
for (const pending5 of [
|
|
2646
2824
|
...pendingDiscover.values(),
|
|
2647
2825
|
...pendingRequest.values(),
|
|
2648
2826
|
...pendingClose.values(),
|
|
@@ -2650,7 +2828,7 @@ var NappletShimPrelude = (() => {
|
|
|
2650
2828
|
...pendingRegistryHas.values(),
|
|
2651
2829
|
...pendingRegistryDescribe.values(),
|
|
2652
2830
|
...pendingRegistryCall.values()
|
|
2653
|
-
]) clearTimeout(
|
|
2831
|
+
]) clearTimeout(pending5.timeout);
|
|
2654
2832
|
pendingDiscover.clear();
|
|
2655
2833
|
pendingRequest.clear();
|
|
2656
2834
|
pendingClose.clear();
|
|
@@ -2664,13 +2842,13 @@ var NappletShimPrelude = (() => {
|
|
|
2664
2842
|
}
|
|
2665
2843
|
|
|
2666
2844
|
// ../nap/dist/chunk-FPY43PPU.js
|
|
2667
|
-
var
|
|
2845
|
+
var REQUEST_TIMEOUT_MS10 = 3e4;
|
|
2668
2846
|
var pendingGetEvent = /* @__PURE__ */ new Map();
|
|
2669
2847
|
var pendingQuery = /* @__PURE__ */ new Map();
|
|
2670
2848
|
var pendingPublish = /* @__PURE__ */ new Map();
|
|
2671
2849
|
var pendingResolve = /* @__PURE__ */ new Map();
|
|
2672
2850
|
var subscriptions = /* @__PURE__ */ new Map();
|
|
2673
|
-
var
|
|
2851
|
+
var installed12 = false;
|
|
2674
2852
|
function isMessageType7(msg, type) {
|
|
2675
2853
|
return msg.type === type;
|
|
2676
2854
|
}
|
|
@@ -2758,7 +2936,7 @@ var NappletShimPrelude = (() => {
|
|
|
2758
2936
|
}
|
|
2759
2937
|
function getEvent(eventId, options) {
|
|
2760
2938
|
const id = crypto.randomUUID();
|
|
2761
|
-
const timeoutMs = options?.timeoutMs ??
|
|
2939
|
+
const timeoutMs = options?.timeoutMs ?? REQUEST_TIMEOUT_MS10;
|
|
2762
2940
|
return new Promise((resolve, reject) => {
|
|
2763
2941
|
const timeout = setTimeout(() => {
|
|
2764
2942
|
if (pendingGetEvent.delete(id)) reject(new Error("outbox.getEvent timed out"));
|
|
@@ -2775,7 +2953,7 @@ var NappletShimPrelude = (() => {
|
|
|
2775
2953
|
}
|
|
2776
2954
|
function query(filters, options) {
|
|
2777
2955
|
const id = crypto.randomUUID();
|
|
2778
|
-
const timeoutMs = options?.timeoutMs ??
|
|
2956
|
+
const timeoutMs = options?.timeoutMs ?? REQUEST_TIMEOUT_MS10;
|
|
2779
2957
|
return new Promise((resolve, reject) => {
|
|
2780
2958
|
const timeout = setTimeout(() => {
|
|
2781
2959
|
if (pendingQuery.delete(id)) reject(new Error("outbox.query timed out"));
|
|
@@ -2828,7 +3006,7 @@ var NappletShimPrelude = (() => {
|
|
|
2828
3006
|
return new Promise((resolve, reject) => {
|
|
2829
3007
|
const timeout = setTimeout(() => {
|
|
2830
3008
|
if (pendingPublish.delete(id)) reject(new Error("outbox.publish timed out"));
|
|
2831
|
-
},
|
|
3009
|
+
}, REQUEST_TIMEOUT_MS10);
|
|
2832
3010
|
pendingPublish.set(id, { resolve, reject, timeout });
|
|
2833
3011
|
const msg = {
|
|
2834
3012
|
type: "outbox.publish",
|
|
@@ -2844,7 +3022,7 @@ var NappletShimPrelude = (() => {
|
|
|
2844
3022
|
return new Promise((resolve, reject) => {
|
|
2845
3023
|
const timeout = setTimeout(() => {
|
|
2846
3024
|
if (pendingResolve.delete(id)) reject(new Error("outbox.resolveRelays timed out"));
|
|
2847
|
-
},
|
|
3025
|
+
}, REQUEST_TIMEOUT_MS10);
|
|
2848
3026
|
pendingResolve.set(id, { resolve, reject, timeout });
|
|
2849
3027
|
const msg = {
|
|
2850
3028
|
type: "outbox.resolveRelays",
|
|
@@ -2855,10 +3033,10 @@ var NappletShimPrelude = (() => {
|
|
|
2855
3033
|
});
|
|
2856
3034
|
}
|
|
2857
3035
|
function installOutboxShim() {
|
|
2858
|
-
if (
|
|
3036
|
+
if (installed12) {
|
|
2859
3037
|
return () => void 0;
|
|
2860
3038
|
}
|
|
2861
|
-
|
|
3039
|
+
installed12 = true;
|
|
2862
3040
|
return () => {
|
|
2863
3041
|
for (const p of pendingGetEvent.values()) clearTimeout(p.timeout);
|
|
2864
3042
|
for (const p of pendingQuery.values()) clearTimeout(p.timeout);
|
|
@@ -2869,17 +3047,17 @@ var NappletShimPrelude = (() => {
|
|
|
2869
3047
|
pendingPublish.clear();
|
|
2870
3048
|
pendingResolve.clear();
|
|
2871
3049
|
subscriptions.clear();
|
|
2872
|
-
|
|
3050
|
+
installed12 = false;
|
|
2873
3051
|
};
|
|
2874
3052
|
}
|
|
2875
3053
|
|
|
2876
3054
|
// ../nap/dist/chunk-QCYYTDDB.js
|
|
2877
|
-
var
|
|
3055
|
+
var REQUEST_TIMEOUT_MS11 = 3e4;
|
|
2878
3056
|
var pendingInfo2 = /* @__PURE__ */ new Map();
|
|
2879
3057
|
var pendingUpload = /* @__PURE__ */ new Map();
|
|
2880
3058
|
var pendingStatus = /* @__PURE__ */ new Map();
|
|
2881
3059
|
var statusHandlers = /* @__PURE__ */ new Set();
|
|
2882
|
-
var
|
|
3060
|
+
var installed13 = false;
|
|
2883
3061
|
function isMessageType8(msg, type) {
|
|
2884
3062
|
return msg.type === type;
|
|
2885
3063
|
}
|
|
@@ -2936,7 +3114,7 @@ var NappletShimPrelude = (() => {
|
|
|
2936
3114
|
return new Promise((resolve, reject) => {
|
|
2937
3115
|
const timeout = setTimeout(() => {
|
|
2938
3116
|
if (pendingInfo2.delete(id)) reject(new Error("upload.info timed out"));
|
|
2939
|
-
},
|
|
3117
|
+
}, REQUEST_TIMEOUT_MS11);
|
|
2940
3118
|
pendingInfo2.set(id, { resolve, reject, timeout });
|
|
2941
3119
|
const msg = {
|
|
2942
3120
|
type: "upload.info",
|
|
@@ -2950,7 +3128,7 @@ var NappletShimPrelude = (() => {
|
|
|
2950
3128
|
return new Promise((resolve, reject) => {
|
|
2951
3129
|
const timeout = setTimeout(() => {
|
|
2952
3130
|
if (pendingUpload.delete(id)) reject(new Error("upload.upload timed out"));
|
|
2953
|
-
},
|
|
3131
|
+
}, REQUEST_TIMEOUT_MS11);
|
|
2954
3132
|
pendingUpload.set(id, { resolve, reject, timeout });
|
|
2955
3133
|
const msg = {
|
|
2956
3134
|
type: "upload.upload",
|
|
@@ -2965,7 +3143,7 @@ var NappletShimPrelude = (() => {
|
|
|
2965
3143
|
return new Promise((resolve, reject) => {
|
|
2966
3144
|
const timeout = setTimeout(() => {
|
|
2967
3145
|
if (pendingStatus.delete(id)) reject(new Error("upload.status timed out"));
|
|
2968
|
-
},
|
|
3146
|
+
}, REQUEST_TIMEOUT_MS11);
|
|
2969
3147
|
pendingStatus.set(id, { resolve, reject, timeout });
|
|
2970
3148
|
const msg = {
|
|
2971
3149
|
type: "upload.status",
|
|
@@ -2984,10 +3162,10 @@ var NappletShimPrelude = (() => {
|
|
|
2984
3162
|
};
|
|
2985
3163
|
}
|
|
2986
3164
|
function installUploadShim() {
|
|
2987
|
-
if (
|
|
3165
|
+
if (installed13) {
|
|
2988
3166
|
return () => void 0;
|
|
2989
3167
|
}
|
|
2990
|
-
|
|
3168
|
+
installed13 = true;
|
|
2991
3169
|
return () => {
|
|
2992
3170
|
for (const p of pendingInfo2.values()) clearTimeout(p.timeout);
|
|
2993
3171
|
for (const p of pendingUpload.values()) clearTimeout(p.timeout);
|
|
@@ -2996,7 +3174,7 @@ var NappletShimPrelude = (() => {
|
|
|
2996
3174
|
pendingUpload.clear();
|
|
2997
3175
|
pendingStatus.clear();
|
|
2998
3176
|
statusHandlers.clear();
|
|
2999
|
-
|
|
3177
|
+
installed13 = false;
|
|
3000
3178
|
};
|
|
3001
3179
|
}
|
|
3002
3180
|
|
|
@@ -3558,14 +3736,14 @@ var NappletShimPrelude = (() => {
|
|
|
3558
3736
|
...handlerHint !== void 0 ? { handlerHint } : {}
|
|
3559
3737
|
};
|
|
3560
3738
|
}
|
|
3561
|
-
var
|
|
3739
|
+
var REQUEST_TIMEOUT_MS12 = 3e4;
|
|
3562
3740
|
var pendingInvoke = /* @__PURE__ */ new Map();
|
|
3563
3741
|
var pendingAvailable = /* @__PURE__ */ new Map();
|
|
3564
3742
|
var pendingHandlers = /* @__PURE__ */ new Map();
|
|
3565
3743
|
var deliveryHandlers = /* @__PURE__ */ new Set();
|
|
3566
3744
|
var deliveries = [];
|
|
3567
3745
|
var changedHandlers = /* @__PURE__ */ new Set();
|
|
3568
|
-
var
|
|
3746
|
+
var installed14 = false;
|
|
3569
3747
|
function isMessageType9(msg, type) {
|
|
3570
3748
|
return msg.type === type;
|
|
3571
3749
|
}
|
|
@@ -3576,37 +3754,37 @@ var NappletShimPrelude = (() => {
|
|
|
3576
3754
|
return result.ok === true && typeof result.archetype === "string" && typeof result.action === "string" && typeof result.convention === "string" && typeof result.handler === "string";
|
|
3577
3755
|
}
|
|
3578
3756
|
function handleInvokeResult(msg) {
|
|
3579
|
-
const
|
|
3580
|
-
if (!
|
|
3757
|
+
const pending5 = pendingInvoke.get(msg.id);
|
|
3758
|
+
if (!pending5) return;
|
|
3581
3759
|
pendingInvoke.delete(msg.id);
|
|
3582
|
-
clearTimeout(
|
|
3760
|
+
clearTimeout(pending5.timeout);
|
|
3583
3761
|
if (isIntentResult(msg.result)) {
|
|
3584
|
-
|
|
3762
|
+
pending5.resolve(msg.result);
|
|
3585
3763
|
return;
|
|
3586
3764
|
}
|
|
3587
|
-
|
|
3765
|
+
pending5.reject(new Error("invalid intent.invoke.result"));
|
|
3588
3766
|
}
|
|
3589
3767
|
function handleAvailableResult(msg) {
|
|
3590
|
-
const
|
|
3591
|
-
if (!
|
|
3768
|
+
const pending5 = pendingAvailable.get(msg.id);
|
|
3769
|
+
if (!pending5) return;
|
|
3592
3770
|
pendingAvailable.delete(msg.id);
|
|
3593
|
-
clearTimeout(
|
|
3771
|
+
clearTimeout(pending5.timeout);
|
|
3594
3772
|
if (msg.availability !== void 0) {
|
|
3595
|
-
|
|
3773
|
+
pending5.resolve(msg.availability);
|
|
3596
3774
|
return;
|
|
3597
3775
|
}
|
|
3598
|
-
|
|
3776
|
+
pending5.reject(new Error(msg.error ?? "intent availability unavailable"));
|
|
3599
3777
|
}
|
|
3600
3778
|
function handleHandlersResult(msg) {
|
|
3601
|
-
const
|
|
3602
|
-
if (!
|
|
3779
|
+
const pending5 = pendingHandlers.get(msg.id);
|
|
3780
|
+
if (!pending5) return;
|
|
3603
3781
|
pendingHandlers.delete(msg.id);
|
|
3604
|
-
clearTimeout(
|
|
3782
|
+
clearTimeout(pending5.timeout);
|
|
3605
3783
|
if (msg.handlers !== void 0) {
|
|
3606
|
-
|
|
3784
|
+
pending5.resolve(msg.handlers);
|
|
3607
3785
|
return;
|
|
3608
3786
|
}
|
|
3609
|
-
|
|
3787
|
+
pending5.reject(new Error(msg.error ?? "intent handlers unavailable"));
|
|
3610
3788
|
}
|
|
3611
3789
|
function handleChanged(msg) {
|
|
3612
3790
|
if (!msg.availability) return;
|
|
@@ -3632,7 +3810,7 @@ var NappletShimPrelude = (() => {
|
|
|
3632
3810
|
return new Promise((resolve, reject) => {
|
|
3633
3811
|
const timeout = setTimeout(() => {
|
|
3634
3812
|
if (pendingInvoke.delete(id)) reject(new Error("intent.invoke timed out"));
|
|
3635
|
-
},
|
|
3813
|
+
}, REQUEST_TIMEOUT_MS12);
|
|
3636
3814
|
pendingInvoke.set(id, { resolve, reject, timeout });
|
|
3637
3815
|
const msg = {
|
|
3638
3816
|
type: "intent.invoke",
|
|
@@ -3653,7 +3831,7 @@ var NappletShimPrelude = (() => {
|
|
|
3653
3831
|
return new Promise((resolve, reject) => {
|
|
3654
3832
|
const timeout = setTimeout(() => {
|
|
3655
3833
|
if (pendingAvailable.delete(id)) reject(new Error("intent.available timed out"));
|
|
3656
|
-
},
|
|
3834
|
+
}, REQUEST_TIMEOUT_MS12);
|
|
3657
3835
|
pendingAvailable.set(id, { resolve, reject, timeout });
|
|
3658
3836
|
const msg = {
|
|
3659
3837
|
type: "intent.available",
|
|
@@ -3668,7 +3846,7 @@ var NappletShimPrelude = (() => {
|
|
|
3668
3846
|
return new Promise((resolve, reject) => {
|
|
3669
3847
|
const timeout = setTimeout(() => {
|
|
3670
3848
|
if (pendingHandlers.delete(id)) reject(new Error("intent.handlers timed out"));
|
|
3671
|
-
},
|
|
3849
|
+
}, REQUEST_TIMEOUT_MS12);
|
|
3672
3850
|
pendingHandlers.set(id, { resolve, reject, timeout });
|
|
3673
3851
|
const msg = {
|
|
3674
3852
|
type: "intent.handlers",
|
|
@@ -3694,27 +3872,27 @@ var NappletShimPrelude = (() => {
|
|
|
3694
3872
|
} };
|
|
3695
3873
|
}
|
|
3696
3874
|
function installIntentShim() {
|
|
3697
|
-
if (
|
|
3698
|
-
|
|
3875
|
+
if (installed14) return () => void 0;
|
|
3876
|
+
installed14 = true;
|
|
3699
3877
|
return () => {
|
|
3700
|
-
for (const
|
|
3701
|
-
for (const
|
|
3702
|
-
for (const
|
|
3878
|
+
for (const pending5 of pendingInvoke.values()) clearTimeout(pending5.timeout);
|
|
3879
|
+
for (const pending5 of pendingAvailable.values()) clearTimeout(pending5.timeout);
|
|
3880
|
+
for (const pending5 of pendingHandlers.values()) clearTimeout(pending5.timeout);
|
|
3703
3881
|
pendingInvoke.clear();
|
|
3704
3882
|
pendingAvailable.clear();
|
|
3705
3883
|
pendingHandlers.clear();
|
|
3706
3884
|
changedHandlers.clear();
|
|
3707
3885
|
deliveryHandlers.clear();
|
|
3708
3886
|
deliveries.length = 0;
|
|
3709
|
-
|
|
3887
|
+
installed14 = false;
|
|
3710
3888
|
};
|
|
3711
3889
|
}
|
|
3712
3890
|
|
|
3713
3891
|
// ../nap/dist/chunk-5QWBBZC6.js
|
|
3714
|
-
var
|
|
3715
|
-
var
|
|
3892
|
+
var REQUEST_TIMEOUT_MS13 = 3e4;
|
|
3893
|
+
var pending2 = /* @__PURE__ */ new Map();
|
|
3716
3894
|
var eventHandlers2 = /* @__PURE__ */ new Set();
|
|
3717
|
-
var
|
|
3895
|
+
var installed15 = false;
|
|
3718
3896
|
var WEBRTC_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
3719
3897
|
"webrtc.open",
|
|
3720
3898
|
"webrtc.open.result",
|
|
@@ -3730,9 +3908,9 @@ var NappletShimPrelude = (() => {
|
|
|
3730
3908
|
function request2(msg, resultType, project) {
|
|
3731
3909
|
return new Promise((resolve, reject) => {
|
|
3732
3910
|
const timeout = setTimeout(() => {
|
|
3733
|
-
if (
|
|
3734
|
-
},
|
|
3735
|
-
|
|
3911
|
+
if (pending2.delete(msg.id)) reject(new Error(\`\${msg.type} timed out\`));
|
|
3912
|
+
}, REQUEST_TIMEOUT_MS13);
|
|
3913
|
+
pending2.set(msg.id, {
|
|
3736
3914
|
resolve,
|
|
3737
3915
|
reject,
|
|
3738
3916
|
timeout,
|
|
@@ -3756,9 +3934,9 @@ var NappletShimPrelude = (() => {
|
|
|
3756
3934
|
return;
|
|
3757
3935
|
}
|
|
3758
3936
|
if (!("id" in msg) || typeof msg.id !== "string") return;
|
|
3759
|
-
const entry =
|
|
3937
|
+
const entry = pending2.get(msg.id);
|
|
3760
3938
|
if (!entry || msg.type !== entry.resultType) return;
|
|
3761
|
-
|
|
3939
|
+
pending2.delete(msg.id);
|
|
3762
3940
|
clearTimeout(entry.timeout);
|
|
3763
3941
|
try {
|
|
3764
3942
|
entry.resolve(entry.project(msg));
|
|
@@ -3805,21 +3983,21 @@ var NappletShimPrelude = (() => {
|
|
|
3805
3983
|
};
|
|
3806
3984
|
}
|
|
3807
3985
|
function installWebrtcShim() {
|
|
3808
|
-
if (
|
|
3809
|
-
|
|
3986
|
+
if (installed15) return () => void 0;
|
|
3987
|
+
installed15 = true;
|
|
3810
3988
|
return () => {
|
|
3811
|
-
for (const entry of
|
|
3812
|
-
|
|
3989
|
+
for (const entry of pending2.values()) clearTimeout(entry.timeout);
|
|
3990
|
+
pending2.clear();
|
|
3813
3991
|
eventHandlers2.clear();
|
|
3814
|
-
|
|
3992
|
+
installed15 = false;
|
|
3815
3993
|
};
|
|
3816
3994
|
}
|
|
3817
3995
|
|
|
3818
3996
|
// ../nap/dist/chunk-23C42MT6.js
|
|
3819
|
-
var
|
|
3820
|
-
var
|
|
3997
|
+
var REQUEST_TIMEOUT_MS14 = 3e4;
|
|
3998
|
+
var pending3 = /* @__PURE__ */ new Map();
|
|
3821
3999
|
var eventHandlers3 = /* @__PURE__ */ new Set();
|
|
3822
|
-
var
|
|
4000
|
+
var installed16 = false;
|
|
3823
4001
|
var BLE_MESSAGE_TYPES = /* @__PURE__ */ new Set([
|
|
3824
4002
|
"ble.open",
|
|
3825
4003
|
"ble.open.result",
|
|
@@ -3843,9 +4021,9 @@ var NappletShimPrelude = (() => {
|
|
|
3843
4021
|
function request3(msg, resultType, project) {
|
|
3844
4022
|
return new Promise((resolve, reject) => {
|
|
3845
4023
|
const timeout = setTimeout(() => {
|
|
3846
|
-
if (
|
|
3847
|
-
},
|
|
3848
|
-
|
|
4024
|
+
if (pending3.delete(msg.id)) reject(new Error(\`\${msg.type} timed out\`));
|
|
4025
|
+
}, REQUEST_TIMEOUT_MS14);
|
|
4026
|
+
pending3.set(msg.id, {
|
|
3849
4027
|
resolve,
|
|
3850
4028
|
reject,
|
|
3851
4029
|
timeout,
|
|
@@ -3869,9 +4047,9 @@ var NappletShimPrelude = (() => {
|
|
|
3869
4047
|
return;
|
|
3870
4048
|
}
|
|
3871
4049
|
if (!("id" in msg) || typeof msg.id !== "string") return;
|
|
3872
|
-
const entry =
|
|
4050
|
+
const entry = pending3.get(msg.id);
|
|
3873
4051
|
if (!entry || msg.type !== entry.resultType) return;
|
|
3874
|
-
|
|
4052
|
+
pending3.delete(msg.id);
|
|
3875
4053
|
clearTimeout(entry.timeout);
|
|
3876
4054
|
try {
|
|
3877
4055
|
entry.resolve(entry.project(msg));
|
|
@@ -3958,20 +4136,20 @@ var NappletShimPrelude = (() => {
|
|
|
3958
4136
|
};
|
|
3959
4137
|
}
|
|
3960
4138
|
function installBleShim() {
|
|
3961
|
-
if (
|
|
3962
|
-
|
|
4139
|
+
if (installed16) return () => void 0;
|
|
4140
|
+
installed16 = true;
|
|
3963
4141
|
return () => {
|
|
3964
|
-
for (const entry of
|
|
3965
|
-
|
|
4142
|
+
for (const entry of pending3.values()) clearTimeout(entry.timeout);
|
|
4143
|
+
pending3.clear();
|
|
3966
4144
|
eventHandlers3.clear();
|
|
3967
|
-
|
|
4145
|
+
installed16 = false;
|
|
3968
4146
|
};
|
|
3969
4147
|
}
|
|
3970
4148
|
|
|
3971
4149
|
// ../nap/dist/chunk-A6WF7BXA.js
|
|
3972
|
-
var
|
|
4150
|
+
var REQUEST_TIMEOUT_MS15 = 3e4;
|
|
3973
4151
|
var pendingOpen2 = /* @__PURE__ */ new Map();
|
|
3974
|
-
var
|
|
4152
|
+
var installed17 = false;
|
|
3975
4153
|
function isMessageType10(msg, type) {
|
|
3976
4154
|
return msg.type === type;
|
|
3977
4155
|
}
|
|
@@ -3996,7 +4174,7 @@ var NappletShimPrelude = (() => {
|
|
|
3996
4174
|
return new Promise((resolve, reject) => {
|
|
3997
4175
|
const timeout = setTimeout(() => {
|
|
3998
4176
|
if (pendingOpen2.delete(id)) reject(new Error("link.open timed out"));
|
|
3999
|
-
},
|
|
4177
|
+
}, REQUEST_TIMEOUT_MS15);
|
|
4000
4178
|
pendingOpen2.set(id, { resolve, reject, timeout });
|
|
4001
4179
|
const msg = {
|
|
4002
4180
|
type: "link.open",
|
|
@@ -4008,24 +4186,24 @@ var NappletShimPrelude = (() => {
|
|
|
4008
4186
|
});
|
|
4009
4187
|
}
|
|
4010
4188
|
function installLinkShim() {
|
|
4011
|
-
if (
|
|
4189
|
+
if (installed17) {
|
|
4012
4190
|
return () => void 0;
|
|
4013
4191
|
}
|
|
4014
|
-
|
|
4192
|
+
installed17 = true;
|
|
4015
4193
|
return () => {
|
|
4016
4194
|
for (const p of pendingOpen2.values()) {
|
|
4017
4195
|
clearTimeout(p.timeout);
|
|
4018
4196
|
p.reject(new Error("link shim uninstalled"));
|
|
4019
4197
|
}
|
|
4020
4198
|
pendingOpen2.clear();
|
|
4021
|
-
|
|
4199
|
+
installed17 = false;
|
|
4022
4200
|
};
|
|
4023
4201
|
}
|
|
4024
4202
|
|
|
4025
4203
|
// ../nap/dist/chunk-HNGITPFS.js
|
|
4026
|
-
var
|
|
4204
|
+
var REQUEST_TIMEOUT_MS16 = 3e4;
|
|
4027
4205
|
var pendingQuery2 = /* @__PURE__ */ new Map();
|
|
4028
|
-
var
|
|
4206
|
+
var installed18 = false;
|
|
4029
4207
|
function isMessageType11(msg, type) {
|
|
4030
4208
|
return msg.type === type;
|
|
4031
4209
|
}
|
|
@@ -4033,11 +4211,11 @@ var NappletShimPrelude = (() => {
|
|
|
4033
4211
|
return Array.isArray(filters) ? filters : [filters];
|
|
4034
4212
|
}
|
|
4035
4213
|
function handleQueryResult2(msg) {
|
|
4036
|
-
const
|
|
4037
|
-
if (!
|
|
4214
|
+
const pending5 = pendingQuery2.get(msg.id);
|
|
4215
|
+
if (!pending5) return;
|
|
4038
4216
|
pendingQuery2.delete(msg.id);
|
|
4039
|
-
clearTimeout(
|
|
4040
|
-
|
|
4217
|
+
clearTimeout(pending5.timeout);
|
|
4218
|
+
pending5.resolve({
|
|
4041
4219
|
ok: msg.ok,
|
|
4042
4220
|
...msg.count === void 0 ? {} : { count: msg.count },
|
|
4043
4221
|
...msg.approximate === void 0 ? {} : { approximate: msg.approximate },
|
|
@@ -4061,7 +4239,7 @@ var NappletShimPrelude = (() => {
|
|
|
4061
4239
|
return new Promise((resolve, reject) => {
|
|
4062
4240
|
const timeout = setTimeout(() => {
|
|
4063
4241
|
if (pendingQuery2.delete(id)) reject(new Error("count.query timed out"));
|
|
4064
|
-
},
|
|
4242
|
+
}, REQUEST_TIMEOUT_MS16);
|
|
4065
4243
|
pendingQuery2.set(id, { resolve, reject, timeout });
|
|
4066
4244
|
const msg = {
|
|
4067
4245
|
type: "count.query",
|
|
@@ -4073,30 +4251,30 @@ var NappletShimPrelude = (() => {
|
|
|
4073
4251
|
});
|
|
4074
4252
|
}
|
|
4075
4253
|
function installCountShim() {
|
|
4076
|
-
if (
|
|
4254
|
+
if (installed18) {
|
|
4077
4255
|
return () => void 0;
|
|
4078
4256
|
}
|
|
4079
|
-
|
|
4257
|
+
installed18 = true;
|
|
4080
4258
|
return () => {
|
|
4081
|
-
for (const
|
|
4259
|
+
for (const pending5 of pendingQuery2.values()) clearTimeout(pending5.timeout);
|
|
4082
4260
|
pendingQuery2.clear();
|
|
4083
|
-
|
|
4261
|
+
installed18 = false;
|
|
4084
4262
|
};
|
|
4085
4263
|
}
|
|
4086
4264
|
|
|
4087
4265
|
// ../nap/dist/chunk-ESEMRW4T.js
|
|
4088
|
-
var
|
|
4266
|
+
var REQUEST_TIMEOUT_MS17 = 3e4;
|
|
4089
4267
|
var pendingSupported = /* @__PURE__ */ new Map();
|
|
4090
4268
|
var pendingAdd = /* @__PURE__ */ new Map();
|
|
4091
4269
|
var pendingRemove = /* @__PURE__ */ new Map();
|
|
4092
|
-
var
|
|
4270
|
+
var installed19 = false;
|
|
4093
4271
|
function isMessageType12(msg, type) {
|
|
4094
4272
|
return msg.type === type;
|
|
4095
4273
|
}
|
|
4096
|
-
function
|
|
4097
|
-
const p =
|
|
4274
|
+
function settle2(pending5, id, resolveValue, fallbackError, error) {
|
|
4275
|
+
const p = pending5.get(id);
|
|
4098
4276
|
if (!p) return;
|
|
4099
|
-
|
|
4277
|
+
pending5.delete(id);
|
|
4100
4278
|
clearTimeout(p.timeout);
|
|
4101
4279
|
if (resolveValue !== void 0) {
|
|
4102
4280
|
p.resolve(resolveValue);
|
|
@@ -4125,7 +4303,7 @@ var NappletShimPrelude = (() => {
|
|
|
4125
4303
|
return result;
|
|
4126
4304
|
}
|
|
4127
4305
|
function handleSupportedResult(msg) {
|
|
4128
|
-
|
|
4306
|
+
settle2(
|
|
4129
4307
|
pendingSupported,
|
|
4130
4308
|
msg.id,
|
|
4131
4309
|
msg.lists,
|
|
@@ -4134,10 +4312,10 @@ var NappletShimPrelude = (() => {
|
|
|
4134
4312
|
);
|
|
4135
4313
|
}
|
|
4136
4314
|
function handleAddResult(msg) {
|
|
4137
|
-
|
|
4315
|
+
settle2(pendingAdd, msg.id, addResultFrom(msg), "lists.add failed");
|
|
4138
4316
|
}
|
|
4139
4317
|
function handleRemoveResult(msg) {
|
|
4140
|
-
|
|
4318
|
+
settle2(pendingRemove, msg.id, removeResultFrom(msg), "lists.remove failed");
|
|
4141
4319
|
}
|
|
4142
4320
|
function handleListsMessage(msg) {
|
|
4143
4321
|
if (isMessageType12(msg, "lists.supported.result")) {
|
|
@@ -4148,13 +4326,13 @@ var NappletShimPrelude = (() => {
|
|
|
4148
4326
|
handleRemoveResult(msg);
|
|
4149
4327
|
}
|
|
4150
4328
|
}
|
|
4151
|
-
function request4(type,
|
|
4329
|
+
function request4(type, pending5, payload) {
|
|
4152
4330
|
const id = crypto.randomUUID();
|
|
4153
4331
|
return new Promise((resolve, reject) => {
|
|
4154
4332
|
const timeout = setTimeout(() => {
|
|
4155
|
-
if (
|
|
4156
|
-
},
|
|
4157
|
-
|
|
4333
|
+
if (pending5.delete(id)) reject(new Error(\`\${type} timed out\`));
|
|
4334
|
+
}, REQUEST_TIMEOUT_MS17);
|
|
4335
|
+
pending5.set(id, { resolve, reject, timeout });
|
|
4158
4336
|
postToShell({
|
|
4159
4337
|
type,
|
|
4160
4338
|
id,
|
|
@@ -4180,10 +4358,10 @@ var NappletShimPrelude = (() => {
|
|
|
4180
4358
|
});
|
|
4181
4359
|
}
|
|
4182
4360
|
function installListsShim() {
|
|
4183
|
-
if (
|
|
4361
|
+
if (installed19) {
|
|
4184
4362
|
return () => void 0;
|
|
4185
4363
|
}
|
|
4186
|
-
|
|
4364
|
+
installed19 = true;
|
|
4187
4365
|
return () => {
|
|
4188
4366
|
for (const p of pendingSupported.values()) {
|
|
4189
4367
|
clearTimeout(p.timeout);
|
|
@@ -4200,12 +4378,12 @@ var NappletShimPrelude = (() => {
|
|
|
4200
4378
|
pendingSupported.clear();
|
|
4201
4379
|
pendingAdd.clear();
|
|
4202
4380
|
pendingRemove.clear();
|
|
4203
|
-
|
|
4381
|
+
installed19 = false;
|
|
4204
4382
|
};
|
|
4205
4383
|
}
|
|
4206
4384
|
|
|
4207
4385
|
// ../nap/dist/chunk-EALGKE7J.js
|
|
4208
|
-
var
|
|
4386
|
+
var REQUEST_TIMEOUT_MS18 = 3e4;
|
|
4209
4387
|
var pendingEncode = /* @__PURE__ */ new Map();
|
|
4210
4388
|
var pendingDecode = /* @__PURE__ */ new Map();
|
|
4211
4389
|
var pendingProfile = /* @__PURE__ */ new Map();
|
|
@@ -4214,7 +4392,7 @@ var NappletShimPrelude = (() => {
|
|
|
4214
4392
|
var pendingUnfollow = /* @__PURE__ */ new Map();
|
|
4215
4393
|
var pendingReact = /* @__PURE__ */ new Map();
|
|
4216
4394
|
var pendingReport = /* @__PURE__ */ new Map();
|
|
4217
|
-
var
|
|
4395
|
+
var installed20 = false;
|
|
4218
4396
|
function isMessageType13(msg, type) {
|
|
4219
4397
|
return msg.type === type;
|
|
4220
4398
|
}
|
|
@@ -4222,10 +4400,10 @@ var NappletShimPrelude = (() => {
|
|
|
4222
4400
|
const { type: _type, id: _id, ...result } = msg;
|
|
4223
4401
|
return result;
|
|
4224
4402
|
}
|
|
4225
|
-
function resolveResult(
|
|
4226
|
-
const p =
|
|
4403
|
+
function resolveResult(pending5, msg, fallback) {
|
|
4404
|
+
const p = pending5.get(msg.id);
|
|
4227
4405
|
if (!p) return;
|
|
4228
|
-
|
|
4406
|
+
pending5.delete(msg.id);
|
|
4229
4407
|
clearTimeout(p.timeout);
|
|
4230
4408
|
if (typeof msg.ok === "boolean") {
|
|
4231
4409
|
p.resolve(withoutEnvelope(msg));
|
|
@@ -4233,13 +4411,13 @@ var NappletShimPrelude = (() => {
|
|
|
4233
4411
|
}
|
|
4234
4412
|
p.reject(new Error(msg.error ?? fallback));
|
|
4235
4413
|
}
|
|
4236
|
-
function request5(
|
|
4414
|
+
function request5(pending5, timeoutMessage, message) {
|
|
4237
4415
|
const id = crypto.randomUUID();
|
|
4238
4416
|
return new Promise((resolve, reject) => {
|
|
4239
4417
|
const timeout = setTimeout(() => {
|
|
4240
|
-
if (
|
|
4241
|
-
},
|
|
4242
|
-
|
|
4418
|
+
if (pending5.delete(id)) reject(new Error(timeoutMessage));
|
|
4419
|
+
}, REQUEST_TIMEOUT_MS18);
|
|
4420
|
+
pending5.set(id, { resolve, reject, timeout });
|
|
4243
4421
|
postToShell(message(id));
|
|
4244
4422
|
});
|
|
4245
4423
|
}
|
|
@@ -4322,12 +4500,12 @@ var NappletShimPrelude = (() => {
|
|
|
4322
4500
|
}));
|
|
4323
4501
|
}
|
|
4324
4502
|
function installCommonShim() {
|
|
4325
|
-
if (
|
|
4503
|
+
if (installed20) {
|
|
4326
4504
|
return () => void 0;
|
|
4327
4505
|
}
|
|
4328
|
-
|
|
4506
|
+
installed20 = true;
|
|
4329
4507
|
return () => {
|
|
4330
|
-
for (const
|
|
4508
|
+
for (const pending5 of [
|
|
4331
4509
|
pendingEncode,
|
|
4332
4510
|
pendingDecode,
|
|
4333
4511
|
pendingProfile,
|
|
@@ -4337,55 +4515,55 @@ var NappletShimPrelude = (() => {
|
|
|
4337
4515
|
pendingReact,
|
|
4338
4516
|
pendingReport
|
|
4339
4517
|
]) {
|
|
4340
|
-
for (const p of
|
|
4341
|
-
|
|
4518
|
+
for (const p of pending5.values()) clearTimeout(p.timeout);
|
|
4519
|
+
pending5.clear();
|
|
4342
4520
|
}
|
|
4343
|
-
|
|
4521
|
+
installed20 = false;
|
|
4344
4522
|
};
|
|
4345
4523
|
}
|
|
4346
4524
|
|
|
4347
4525
|
// ../nap/dist/chunk-6GWPHINR.js
|
|
4348
|
-
var
|
|
4526
|
+
var REQUEST_TIMEOUT_MS19 = 3e4;
|
|
4349
4527
|
var pendingOpen3 = /* @__PURE__ */ new Map();
|
|
4350
4528
|
var pendingWrite = /* @__PURE__ */ new Map();
|
|
4351
4529
|
var pendingClose2 = /* @__PURE__ */ new Map();
|
|
4352
4530
|
var eventHandlers4 = /* @__PURE__ */ new Set();
|
|
4353
|
-
var
|
|
4531
|
+
var installed21 = false;
|
|
4354
4532
|
function isMessageType14(msg, type) {
|
|
4355
4533
|
return msg.type === type;
|
|
4356
4534
|
}
|
|
4357
4535
|
function handleOpenResult3(msg) {
|
|
4358
|
-
const
|
|
4359
|
-
if (!
|
|
4536
|
+
const pending5 = pendingOpen3.get(msg.id);
|
|
4537
|
+
if (!pending5) return;
|
|
4360
4538
|
pendingOpen3.delete(msg.id);
|
|
4361
|
-
clearTimeout(
|
|
4539
|
+
clearTimeout(pending5.timeout);
|
|
4362
4540
|
if (msg.session !== void 0) {
|
|
4363
|
-
|
|
4541
|
+
pending5.resolve({ session: msg.session });
|
|
4364
4542
|
return;
|
|
4365
4543
|
}
|
|
4366
|
-
|
|
4544
|
+
pending5.reject(new Error(msg.error ?? "serial open failed"));
|
|
4367
4545
|
}
|
|
4368
4546
|
function handleWriteResult(msg) {
|
|
4369
|
-
const
|
|
4370
|
-
if (!
|
|
4547
|
+
const pending5 = pendingWrite.get(msg.id);
|
|
4548
|
+
if (!pending5) return;
|
|
4371
4549
|
pendingWrite.delete(msg.id);
|
|
4372
|
-
clearTimeout(
|
|
4550
|
+
clearTimeout(pending5.timeout);
|
|
4373
4551
|
if (msg.error) {
|
|
4374
|
-
|
|
4552
|
+
pending5.reject(new Error(msg.error));
|
|
4375
4553
|
return;
|
|
4376
4554
|
}
|
|
4377
|
-
|
|
4555
|
+
pending5.resolve();
|
|
4378
4556
|
}
|
|
4379
4557
|
function handleCloseResult2(msg) {
|
|
4380
|
-
const
|
|
4381
|
-
if (!
|
|
4558
|
+
const pending5 = pendingClose2.get(msg.id);
|
|
4559
|
+
if (!pending5) return;
|
|
4382
4560
|
pendingClose2.delete(msg.id);
|
|
4383
|
-
clearTimeout(
|
|
4561
|
+
clearTimeout(pending5.timeout);
|
|
4384
4562
|
if (msg.error) {
|
|
4385
|
-
|
|
4563
|
+
pending5.reject(new Error(msg.error));
|
|
4386
4564
|
return;
|
|
4387
4565
|
}
|
|
4388
|
-
|
|
4566
|
+
pending5.resolve();
|
|
4389
4567
|
}
|
|
4390
4568
|
function handleEvent4(msg) {
|
|
4391
4569
|
if (!msg.event) return;
|
|
@@ -4407,7 +4585,7 @@ var NappletShimPrelude = (() => {
|
|
|
4407
4585
|
return new Promise((resolve, reject) => {
|
|
4408
4586
|
const timeout = setTimeout(() => {
|
|
4409
4587
|
if (pendingOpen3.delete(id)) reject(new Error("serial.open timed out"));
|
|
4410
|
-
},
|
|
4588
|
+
}, REQUEST_TIMEOUT_MS19);
|
|
4411
4589
|
pendingOpen3.set(id, { resolve, reject, timeout });
|
|
4412
4590
|
const msg = {
|
|
4413
4591
|
type: "serial.open",
|
|
@@ -4422,7 +4600,7 @@ var NappletShimPrelude = (() => {
|
|
|
4422
4600
|
return new Promise((resolve, reject) => {
|
|
4423
4601
|
const timeout = setTimeout(() => {
|
|
4424
4602
|
if (pendingWrite.delete(id)) reject(new Error("serial.write timed out"));
|
|
4425
|
-
},
|
|
4603
|
+
}, REQUEST_TIMEOUT_MS19);
|
|
4426
4604
|
pendingWrite.set(id, { resolve, reject, timeout });
|
|
4427
4605
|
const msg = {
|
|
4428
4606
|
type: "serial.write",
|
|
@@ -4438,7 +4616,7 @@ var NappletShimPrelude = (() => {
|
|
|
4438
4616
|
return new Promise((resolve, reject) => {
|
|
4439
4617
|
const timeout = setTimeout(() => {
|
|
4440
4618
|
if (pendingClose2.delete(id)) reject(new Error("serial.close timed out"));
|
|
4441
|
-
},
|
|
4619
|
+
}, REQUEST_TIMEOUT_MS19);
|
|
4442
4620
|
pendingClose2.set(id, { resolve, reject, timeout });
|
|
4443
4621
|
const msg = {
|
|
4444
4622
|
type: "serial.close",
|
|
@@ -4458,27 +4636,27 @@ var NappletShimPrelude = (() => {
|
|
|
4458
4636
|
};
|
|
4459
4637
|
}
|
|
4460
4638
|
function installSerialShim() {
|
|
4461
|
-
if (
|
|
4639
|
+
if (installed21) {
|
|
4462
4640
|
return () => void 0;
|
|
4463
4641
|
}
|
|
4464
|
-
|
|
4642
|
+
installed21 = true;
|
|
4465
4643
|
return () => {
|
|
4466
|
-
for (const
|
|
4467
|
-
for (const
|
|
4468
|
-
for (const
|
|
4644
|
+
for (const pending5 of pendingOpen3.values()) clearTimeout(pending5.timeout);
|
|
4645
|
+
for (const pending5 of pendingWrite.values()) clearTimeout(pending5.timeout);
|
|
4646
|
+
for (const pending5 of pendingClose2.values()) clearTimeout(pending5.timeout);
|
|
4469
4647
|
pendingOpen3.clear();
|
|
4470
4648
|
pendingWrite.clear();
|
|
4471
4649
|
pendingClose2.clear();
|
|
4472
4650
|
eventHandlers4.clear();
|
|
4473
|
-
|
|
4651
|
+
installed21 = false;
|
|
4474
4652
|
};
|
|
4475
4653
|
}
|
|
4476
4654
|
|
|
4477
4655
|
// ../nap/dist/chunk-PONXETIR.js
|
|
4478
|
-
var
|
|
4479
|
-
var
|
|
4656
|
+
var REQUEST_TIMEOUT_MS20 = 3e4;
|
|
4657
|
+
var pending4 = /* @__PURE__ */ new Map();
|
|
4480
4658
|
var changeHandlers3 = /* @__PURE__ */ new Set();
|
|
4481
|
-
var
|
|
4659
|
+
var installed22 = false;
|
|
4482
4660
|
var RESULT_TYPES = /* @__PURE__ */ new Set([
|
|
4483
4661
|
"fs.info.result",
|
|
4484
4662
|
"fs.pickFile.result",
|
|
@@ -4499,9 +4677,9 @@ var NappletShimPrelude = (() => {
|
|
|
4499
4677
|
const id = crypto.randomUUID();
|
|
4500
4678
|
return new Promise((resolve, reject) => {
|
|
4501
4679
|
const timeout = setTimeout(() => {
|
|
4502
|
-
if (
|
|
4503
|
-
},
|
|
4504
|
-
|
|
4680
|
+
if (pending4.delete(id)) reject(new Error(\`\${type} timed out\`));
|
|
4681
|
+
}, REQUEST_TIMEOUT_MS20);
|
|
4682
|
+
pending4.set(id, { resolve, reject, timeout });
|
|
4505
4683
|
postToShell({ type, id, ...payload });
|
|
4506
4684
|
});
|
|
4507
4685
|
}
|
|
@@ -4515,9 +4693,9 @@ var NappletShimPrelude = (() => {
|
|
|
4515
4693
|
function handleResult(msg) {
|
|
4516
4694
|
const id = msg.id;
|
|
4517
4695
|
if (typeof id !== "string") return;
|
|
4518
|
-
const entry =
|
|
4696
|
+
const entry = pending4.get(id);
|
|
4519
4697
|
if (!entry) return;
|
|
4520
|
-
|
|
4698
|
+
pending4.delete(id);
|
|
4521
4699
|
clearTimeout(entry.timeout);
|
|
4522
4700
|
if (typeof msg.error === "string") {
|
|
4523
4701
|
entry.reject(new Error(msg.error));
|
|
@@ -4602,20 +4780,20 @@ var NappletShimPrelude = (() => {
|
|
|
4602
4780
|
};
|
|
4603
4781
|
}
|
|
4604
4782
|
function installFsShim() {
|
|
4605
|
-
if (
|
|
4783
|
+
if (installed22) {
|
|
4606
4784
|
return () => void 0;
|
|
4607
4785
|
}
|
|
4608
|
-
|
|
4786
|
+
installed22 = true;
|
|
4609
4787
|
return () => {
|
|
4610
|
-
for (const entry of
|
|
4611
|
-
|
|
4788
|
+
for (const entry of pending4.values()) clearTimeout(entry.timeout);
|
|
4789
|
+
pending4.clear();
|
|
4612
4790
|
changeHandlers3.clear();
|
|
4613
|
-
|
|
4791
|
+
installed22 = false;
|
|
4614
4792
|
};
|
|
4615
4793
|
}
|
|
4616
4794
|
|
|
4617
4795
|
// ../nap/dist/chunk-DNUVIJ5U.js
|
|
4618
|
-
var
|
|
4796
|
+
var REQUEST_TIMEOUT_MS21 = 3e4;
|
|
4619
4797
|
var pendingStatus2 = /* @__PURE__ */ new Map();
|
|
4620
4798
|
var pendingConversations = /* @__PURE__ */ new Map();
|
|
4621
4799
|
var pendingMessages = /* @__PURE__ */ new Map();
|
|
@@ -4623,7 +4801,7 @@ var NappletShimPrelude = (() => {
|
|
|
4623
4801
|
var pendingSubscribe = /* @__PURE__ */ new Map();
|
|
4624
4802
|
var pendingUnsubscribe = /* @__PURE__ */ new Map();
|
|
4625
4803
|
var messageHandlers = /* @__PURE__ */ new Set();
|
|
4626
|
-
var
|
|
4804
|
+
var installed23 = false;
|
|
4627
4805
|
function isMessageType15(msg, type) {
|
|
4628
4806
|
return msg.type === type;
|
|
4629
4807
|
}
|
|
@@ -4631,28 +4809,28 @@ var NappletShimPrelude = (() => {
|
|
|
4631
4809
|
return new Promise((resolve, reject) => {
|
|
4632
4810
|
const timeout = setTimeout(() => {
|
|
4633
4811
|
if (map.delete(id)) reject(new Error(\`\${action} timed out\`));
|
|
4634
|
-
},
|
|
4812
|
+
}, REQUEST_TIMEOUT_MS21);
|
|
4635
4813
|
map.set(id, { resolve, reject, timeout });
|
|
4636
4814
|
});
|
|
4637
4815
|
}
|
|
4638
|
-
function
|
|
4639
|
-
const
|
|
4640
|
-
if (!
|
|
4816
|
+
function settle3(map, id, error, fallbackError, getValue) {
|
|
4817
|
+
const pending5 = map.get(id);
|
|
4818
|
+
if (!pending5) return;
|
|
4641
4819
|
map.delete(id);
|
|
4642
|
-
clearTimeout(
|
|
4820
|
+
clearTimeout(pending5.timeout);
|
|
4643
4821
|
if (error) {
|
|
4644
|
-
|
|
4822
|
+
pending5.reject(new Error(error));
|
|
4645
4823
|
return;
|
|
4646
4824
|
}
|
|
4647
4825
|
const value = getValue();
|
|
4648
4826
|
if (value === void 0) {
|
|
4649
|
-
|
|
4827
|
+
pending5.reject(new Error(fallbackError));
|
|
4650
4828
|
return;
|
|
4651
4829
|
}
|
|
4652
|
-
|
|
4830
|
+
pending5.resolve(value);
|
|
4653
4831
|
}
|
|
4654
4832
|
function handleStatusResult2(msg) {
|
|
4655
|
-
|
|
4833
|
+
settle3(
|
|
4656
4834
|
pendingStatus2,
|
|
4657
4835
|
msg.id,
|
|
4658
4836
|
msg.error,
|
|
@@ -4671,7 +4849,7 @@ var NappletShimPrelude = (() => {
|
|
|
4671
4849
|
);
|
|
4672
4850
|
}
|
|
4673
4851
|
function handleConversationsResult(msg) {
|
|
4674
|
-
|
|
4852
|
+
settle3(
|
|
4675
4853
|
pendingConversations,
|
|
4676
4854
|
msg.id,
|
|
4677
4855
|
msg.error,
|
|
@@ -4686,7 +4864,7 @@ var NappletShimPrelude = (() => {
|
|
|
4686
4864
|
);
|
|
4687
4865
|
}
|
|
4688
4866
|
function handleMessagesResult(msg) {
|
|
4689
|
-
|
|
4867
|
+
settle3(
|
|
4690
4868
|
pendingMessages,
|
|
4691
4869
|
msg.id,
|
|
4692
4870
|
msg.error,
|
|
@@ -4701,7 +4879,7 @@ var NappletShimPrelude = (() => {
|
|
|
4701
4879
|
);
|
|
4702
4880
|
}
|
|
4703
4881
|
function handleSendResult2(msg) {
|
|
4704
|
-
|
|
4882
|
+
settle3(
|
|
4705
4883
|
pendingSend,
|
|
4706
4884
|
msg.id,
|
|
4707
4885
|
msg.error,
|
|
@@ -4713,7 +4891,7 @@ var NappletShimPrelude = (() => {
|
|
|
4713
4891
|
);
|
|
4714
4892
|
}
|
|
4715
4893
|
function handleSubscribeResult(msg) {
|
|
4716
|
-
|
|
4894
|
+
settle3(
|
|
4717
4895
|
pendingSubscribe,
|
|
4718
4896
|
msg.id,
|
|
4719
4897
|
msg.error,
|
|
@@ -4725,7 +4903,7 @@ var NappletShimPrelude = (() => {
|
|
|
4725
4903
|
);
|
|
4726
4904
|
}
|
|
4727
4905
|
function handleUnsubscribeResult(msg) {
|
|
4728
|
-
|
|
4906
|
+
settle3(
|
|
4729
4907
|
pendingUnsubscribe,
|
|
4730
4908
|
msg.id,
|
|
4731
4909
|
msg.error,
|
|
@@ -4828,17 +5006,17 @@ var NappletShimPrelude = (() => {
|
|
|
4828
5006
|
};
|
|
4829
5007
|
}
|
|
4830
5008
|
function installDmShim() {
|
|
4831
|
-
if (
|
|
5009
|
+
if (installed23) {
|
|
4832
5010
|
return () => void 0;
|
|
4833
5011
|
}
|
|
4834
|
-
|
|
5012
|
+
installed23 = true;
|
|
4835
5013
|
return () => {
|
|
4836
|
-
for (const
|
|
4837
|
-
for (const
|
|
4838
|
-
for (const
|
|
4839
|
-
for (const
|
|
4840
|
-
for (const
|
|
4841
|
-
for (const
|
|
5014
|
+
for (const pending5 of pendingStatus2.values()) clearTimeout(pending5.timeout);
|
|
5015
|
+
for (const pending5 of pendingConversations.values()) clearTimeout(pending5.timeout);
|
|
5016
|
+
for (const pending5 of pendingMessages.values()) clearTimeout(pending5.timeout);
|
|
5017
|
+
for (const pending5 of pendingSend.values()) clearTimeout(pending5.timeout);
|
|
5018
|
+
for (const pending5 of pendingSubscribe.values()) clearTimeout(pending5.timeout);
|
|
5019
|
+
for (const pending5 of pendingUnsubscribe.values()) clearTimeout(pending5.timeout);
|
|
4842
5020
|
pendingStatus2.clear();
|
|
4843
5021
|
pendingConversations.clear();
|
|
4844
5022
|
pendingMessages.clear();
|
|
@@ -4846,7 +5024,7 @@ var NappletShimPrelude = (() => {
|
|
|
4846
5024
|
pendingSubscribe.clear();
|
|
4847
5025
|
pendingUnsubscribe.clear();
|
|
4848
5026
|
messageHandlers.clear();
|
|
4849
|
-
|
|
5027
|
+
installed23 = false;
|
|
4850
5028
|
};
|
|
4851
5029
|
}
|
|
4852
5030
|
|
|
@@ -5087,6 +5265,14 @@ var NappletShimPrelude = (() => {
|
|
|
5087
5265
|
|
|
5088
5266
|
// src/runtime-globals-services.ts
|
|
5089
5267
|
function installServiceDomains(domains, napplet) {
|
|
5268
|
+
if (domains.has("llm")) {
|
|
5269
|
+
napplet.llm = {
|
|
5270
|
+
select,
|
|
5271
|
+
describe,
|
|
5272
|
+
generate,
|
|
5273
|
+
cancel
|
|
5274
|
+
};
|
|
5275
|
+
}
|
|
5090
5276
|
installNetworkDomains(domains, napplet);
|
|
5091
5277
|
installDeviceDomains(domains, napplet);
|
|
5092
5278
|
installFilesystemDomains(domains, napplet);
|
|
@@ -5251,6 +5437,7 @@ var NappletShimPrelude = (() => {
|
|
|
5251
5437
|
var installedDomainShims = /* @__PURE__ */ new Set();
|
|
5252
5438
|
var messageListenerInstalled = false;
|
|
5253
5439
|
var DOMAIN_ROUTERS = [
|
|
5440
|
+
["llm.", handleLlmMessage],
|
|
5254
5441
|
["gamepad.", handleGamepadMessage],
|
|
5255
5442
|
["shell.", handleShellMessage],
|
|
5256
5443
|
["keys.", handleKeysMessage],
|
|
@@ -5297,6 +5484,9 @@ var NappletShimPrelude = (() => {
|
|
|
5297
5484
|
if (installedDomainShims.has(domain)) return;
|
|
5298
5485
|
installedDomainShims.add(domain);
|
|
5299
5486
|
switch (domain) {
|
|
5487
|
+
case "llm":
|
|
5488
|
+
installLlmShim();
|
|
5489
|
+
return;
|
|
5300
5490
|
case "gamepad":
|
|
5301
5491
|
installGamepadShim();
|
|
5302
5492
|
return;
|
|
@@ -5417,9 +5607,9 @@ var NappletShimPrelude = (() => {
|
|
|
5417
5607
|
@scure/base/index.js:
|
|
5418
5608
|
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
5419
5609
|
*/
|
|
5420
|
-
//# sourceMappingURL=prelude.global.js.map`,
|
|
5610
|
+
//# sourceMappingURL=prelude.global.js.map`,ji=/\bwindow\s*\.\s*nostr\b|\bglobalThis\s*\.\s*nostr\b/,qi="/__conformance__/events",fn=new URLSearchParams(location.search),Ct=fn.get("live")==="1";function te(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const re=document.getElementById("app");function Oi(){return re.innerHTML=`
|
|
5421
5611
|
<header class="masthead">
|
|
5422
|
-
<h1>napplet conformance ${
|
|
5612
|
+
<h1>napplet conformance ${Ct?'<span class="live-badge" id="live-badge">● live</span>':""}</h1>
|
|
5423
5613
|
<p>Load a napplet by <code>nevent</code> or <code>naddr</code> and run NAP protocol conformance live. Same engine as <code>napplet-conformance</code> CI.</p>
|
|
5424
5614
|
</header>
|
|
5425
5615
|
<form id="run-form" class="runbar">
|
|
@@ -5429,22 +5619,22 @@ var NappletShimPrelude = (() => {
|
|
|
5429
5619
|
</form>
|
|
5430
5620
|
<p id="status" class="status" role="status"></p>
|
|
5431
5621
|
<section id="output" class="output"></section>
|
|
5432
|
-
`,{targetInput:
|
|
5622
|
+
`,{targetInput:re.querySelector("#target"),runButton:re.querySelector("#run"),rerunButton:re.querySelector("#rerun"),liveBadge:re.querySelector("#live-badge")??document.createElement("span"),status:re.querySelector("#status"),output:re.querySelector("#output")}}const H=Oi();let Te="",mn=0;function Pe(e,n="info"){H.status.textContent=e,H.status.dataset.kind=n}function rn(e){return String(e).padStart(2,"0")}function Ci(e){const n=new Date(e);return`${rn(n.getHours())}:${rn(n.getMinutes())}:${rn(n.getSeconds())}`}function Hi(e){const n=e.ok?"conformant":"non-conformant",t=[...new Set(e.checks.map(o=>o.area))].map(o=>{const l=e.checks.filter(a=>a.area===o).map(a=>{const d=a.severity==="warning"&&a.status==="fail"?' <span class="tag warn">warning</span>':"",h=a.detail?`<span class="detail">${te(a.detail)}</span>`:"";return`<li class="check ${a.status}"><span class="badge ${a.status}">${a.status}</span><span class="id">${te(a.id)}</span>${d}${h}</li>`}).join("");return`<div class="area"><h3>${te(o)}</h3><ul>${l}</ul></div>`}).join(""),s=e.summary,i=mn>1?`<span class="run-stamp">run #${mn} · ${Ci(e.finishedAt)}</span>`:"";return`
|
|
5433
5623
|
<div class="verdict ${n}">
|
|
5434
5624
|
<span class="result">${e.ok?"CONFORMANT":"NON-CONFORMANT"}</span>
|
|
5435
|
-
<span class="counts">${
|
|
5625
|
+
<span class="counts">${s.passed} passed · ${s.failed} failed · ${s.skipped} skipped${s.warnings?` · ${s.warnings} warning(s)`:""}</span>
|
|
5436
5626
|
${i}
|
|
5437
5627
|
</div>
|
|
5438
5628
|
<div class="checks">${t}</div>
|
|
5439
|
-
`}function
|
|
5629
|
+
`}function Di(e){return e.length===0?'<p class="empty">No envelopes were emitted.</p>':`<ul class="envlog">${e.map(r=>{const t=r.verdict.ok?"ok":"bad",s=r.verdict.ok?"":`<div class="errs">${r.verdict.errors.map(i=>te(`${i.code}: ${i.message}`)).join("<br>")}</div>`;return`<li class="env ${t}"><code>${te(JSON.stringify(r.envelope))}</code>${s}</li>`}).join("")}</ul>`}function Ni(e){const n=(r,t)=>`<tr><th>${te(r)}</th><td>${t?te(String(t)):"<em>—</em>"}</td></tr>`;if(e.manifestEvent){const r=e.manifestEvent,t=Ge(r);return`
|
|
5440
5630
|
<table class="manifest">
|
|
5441
|
-
${
|
|
5631
|
+
${Jr(r,t).map(([s,i])=>n(s,i)).join("")}
|
|
5442
5632
|
</table>
|
|
5443
|
-
${t.errors.length?`<div class="errs">${t.errors.map(
|
|
5444
|
-
`}return e.fetched?'<p class="empty">Local URL mode booted raw HTML. It does not include a signed NIP-5D manifest event, so manifest-event checks are skipped.</p>':`<p class="empty">Couldn't fetch the local URL HTML, likely because of CORS. Use a NIP-19 <code>nevent</code>/<code>naddr</code> for authoritative manifest checks, or use the CLI for local URL runs.</p>`}function
|
|
5445
|
-
${
|
|
5633
|
+
${t.errors.length?`<div class="errs">${t.errors.map(s=>te(`${s.code}: ${s.message}`)).join("<br>")}</div>`:""}
|
|
5634
|
+
`}return e.fetched?'<p class="empty">Local URL mode booted raw HTML. It does not include a signed NIP-5D manifest event, so manifest-event checks are skipped.</p>':`<p class="empty">Couldn't fetch the local URL HTML, likely because of CORS. Use a NIP-19 <code>nevent</code>/<code>naddr</code> for authoritative manifest checks, or use the CLI for local URL runs.</p>`}function Bi(e,n,r){H.output.innerHTML=`
|
|
5635
|
+
${Hi(e)}
|
|
5446
5636
|
<div class="panels">
|
|
5447
|
-
<section class="panel"><h2>Emitted envelopes (${n.length})</h2>${
|
|
5448
|
-
<section class="panel"><h2>Manifest</h2>${
|
|
5637
|
+
<section class="panel"><h2>Emitted envelopes (${n.length})</h2>${Di(n)}</section>
|
|
5638
|
+
<section class="panel"><h2>Manifest</h2>${Ni(r)}</section>
|
|
5449
5639
|
</div>
|
|
5450
|
-
`}async function
|
|
5640
|
+
`}async function Ke(e){Te=e,H.runButton.disabled=!0,H.rerunButton.disabled=!0;let n=null;try{Pe(`Resolving ${e} …`),n=await Pi(e);const r=ji.test(n.html)?["window.nostr"]:[];Pe("Booting napplet in a sandboxed iframe …");const t=await Vr({url:n.bootUrl,html:n.html,readyTimeoutMs:5e3,settleMs:800,runDegraded:!0,runtimePreludeSource:Ai}),s=jr({manifestHtml:n.html,manifestEvent:n.manifestEvent,boot:t,forbiddenGlobals:r}),i=Xr(s);mn+=1,Pe(i.ok?"Done — conformant.":"Done — non-conformant.",i.ok?"info":"error"),Bi(i,t.emitted,n),H.rerunButton.hidden=!1}catch(r){Pe(`Error: ${r instanceof Error?r.message:String(r)}`,"error")}finally{n?.revoke?.(),H.runButton.disabled=!1,H.rerunButton.disabled=!1}}function Li(){if(!Ct||typeof EventSource>"u")return;let e=!1;const n=new EventSource(qi);n.addEventListener("rerun",()=>{!Te||e||(e=!0,setTimeout(()=>{e=!1,Ke(Te)},50))}),n.addEventListener("open",()=>{H.liveBadge&&(H.liveBadge.dataset.state="connected")}),n.addEventListener("error",()=>{H.liveBadge&&(H.liveBadge.dataset.state="disconnected")})}H.runButton.parentElement.addEventListener("submit",e=>{e.preventDefault();const n=H.targetInput.value.trim();if(n){const r=new URL(location.href);r.searchParams.set("target",n),r.searchParams.delete("url"),history.replaceState(null,"",r),Ke(n)}});H.rerunButton.addEventListener("click",()=>{Te&&Ke(Te)});Li();const sn=fn.get("target")??fn.get("url");sn&&(H.targetInput.value=sn,Ke(sn));
|