hd-wallet-ui 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,10 +8,10 @@ and signed approval requests.
8
8
  ## Install
9
9
 
10
10
  ```sh
11
- npm install hd-wallet-ui@2.2.1
11
+ npm install hd-wallet-ui@2.2.2
12
12
  ```
13
13
 
14
- `hd-wallet-wasm` 2.2.1 is the package's only runtime dependency.
14
+ `hd-wallet-wasm` 2.2.2 is the package's only runtime dependency.
15
15
 
16
16
  ## Published surfaces
17
17
 
@@ -120,8 +120,11 @@ const { contentKey } = await wallet.unwrapKey({ enc, kmf, context });
120
120
  that carries the answer never holds a plaintext. The browser needs Web
121
121
  Crypto X25519.
122
122
 
123
- Pages on one origin are one security principal to the browser: every page on
124
- `https://digitalarsenal.github.io` can name either client ID.
123
+ Pages on one origin are one security principal to the browser, so each of
124
+ these clients has its own origin (`https://flatbuffers.spacedatanetwork.org`,
125
+ `https://flatsql.spacedatanetwork.org`). The shared
126
+ `https://digitalarsenal.github.io` origin is the one client
127
+ `digitalarsenal-pages-v1`, which signs in only.
125
128
 
126
129
  ## Callback page
127
130
 
@@ -1 +1 @@
1
- (function(){"use strict";const xe=Object.freeze({cm:.01,km:1e3,m:1,mm:.001}),Ce=Object.freeze({metersPerSourceUnit:xe,quaternionNormTolerance:1e-6,scaleComponentExclusiveMin:0,scaleComponentInclusiveMax:1e6,translationComponentAbsMax:1e6,upAxes:Object.freeze(["X_UP","Y_UP","Z_UP"])}),Pe=Object.freeze({reviewedTransform:Ce,schemaVersion:1}),k=new TextEncoder,Z=Object.getPrototypeOf(Uint8Array.prototype);Object.getOwnPropertyDescriptor(Z,"buffer").get,Object.getOwnPropertyDescriptor(Z,"length").get,Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,typeof SharedArrayBuffer>"u"||Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype,"byteLength").get;const B="sdn-bip32-slip10-purpose-v1",$="password-scrypt-v2",G="ed25519-over-sha256-jcs-v1",Ne=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,U=/^[0-9a-f]{64}$/u,ge=/^sha256:[0-9a-f]{64}$/u,De=/^[1-9A-HJ-NP-Za-km-z]+$/u,je=131072,ke=["accountFingerprint","accountIndex","accountLabel","accountPeerId","accountXpub","identityScheme","keys","schemaVersion","seedProfile"],Be=["bip32Fingerprint","curve","derivation","encoding","identityScheme","keyId","path","publicKeyHex","purpose","seedProfile","signatureProfile"],$e=["connectionExpiresAt","event","identity","schemaVersion"];function u(r){throw new TypeError(r)}function ee(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}function v(r,e){typeof r!="string"&&u(`${e} must be a string`);for(let t=0;t<r.length;t+=1){const s=r.charCodeAt(t);let i=s;if(s>=55296&&s<=56319){const o=r.charCodeAt(t+1);o>=56320&&o<=57343||u(`${e} contains an unpaired surrogate`),i=65536+(s-55296<<10)+(o-56320),t+=1}else s>=56320&&s<=57343&&u(`${e} contains an unpaired surrogate`);((i&65535)===65534||(i&65535)===65535||i>=64976&&i<=65007)&&u(`${e} contains a Unicode noncharacter`)}return r}function Ue(r){typeof r!="string"&&u("wire JSON must be a string"),k.encode(r).byteLength>je&&u("wire JSON is too large"),r.charCodeAt(0)===65279&&u("wire JSON must not contain a BOM");let e=0,t=0;const s=()=>{for(;e<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[e]);)e+=1},i=()=>{r[e]!=='"'&&u("invalid JSON string");const a=e;for(e+=1;e<r.length;){const l=r.charCodeAt(e);if(l===34){e+=1;let f;try{f=JSON.parse(r.slice(a,e))}catch{u("invalid JSON string")}return v(f,"JSON string")}l<32&&u("invalid JSON control character"),l===92&&(e+=1,e>=r.length&&u("unterminated JSON escape")),e+=1}u("unterminated JSON string")},o=(a=0)=>{a>32&&u("wire JSON nesting is too deep"),t+=1,t>4096&&u("wire JSON contains too many values"),s();const l=r[e];if(l==='"')return i();if(l==="{"){e+=1;const d=Object.create(null),y=new Set;if(s(),r[e]==="}")return e+=1,d;for(;e<r.length;){s();const m=i();if(y.has(m)&&u(`duplicate JSON field: ${m}`),y.add(m),s(),r[e]!==":"&&u("missing JSON object colon"),e+=1,d[m]=o(a+1),s(),r[e]==="}")return e+=1,d;r[e]!==","&&u("invalid JSON object separator"),e+=1}u("unterminated JSON object")}if(l==="["){e+=1;const d=[];if(s(),r[e]==="]")return e+=1,d;for(;e<r.length;){if(d.push(o(a+1)),s(),r[e]==="]")return e+=1,d;r[e]!==","&&u("invalid JSON array separator"),e+=1}u("unterminated JSON array")}for(const[d,y]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(d,e))return e+=d.length,y;const f=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(e));f||u("invalid JSON value"),e+=f[0].length;const h=Number(f[0]);return Number.isFinite(h)||u("wire JSON number must be finite"),h};s();const n=o();return s(),e!==r.length&&u("wire JSON contains trailing bytes"),n}function Me(r){return typeof r=="string"?Ue(r):r}function Ve(r,e){if(r.byteLength!==e.byteLength)return!1;let t=0;for(let s=0;s<r.byteLength;s+=1)t|=r[s]^e[s];return t===0}function R(r,e,t){const s=Me(r);ee(s)||u(`${t} must be a JSON object`),Object.getOwnPropertySymbols(s).length!==0&&u(`${t} has an unknown symbol field`);const i=Object.getOwnPropertyNames(s).sort(),o=[...e].sort(),n=k.encode(i.join("\0")),a=k.encode(o.join("\0"));Ve(n,a)||u(`${t} has missing or unknown fields`);for(const l of i){const f=Object.getOwnPropertyDescriptor(s,l);(!f||!f.enumerable||!("value"in f))&&u(`${t}.${l} must be an enumerable data field`),f.value===void 0&&u(`${t}.${l} must not be undefined`)}return s}function L(r){if(!r||typeof r!="object"||Object.isFrozen(r))return r;for(const e of Object.values(r))L(e);return Object.freeze(r)}function b(r){return L(Object.fromEntries([...r].sort(([e],[t])=>e<t?-1:e>t?1:0)))}function x(r,e,t){(!Array.isArray(r)||Object.getPrototypeOf(r)!==Array.prototype||r.length!==e)&&u(`${t} must be a plain array with exactly ${e} values`);const s=[...Array.from({length:e},(o,n)=>String(n)),"length"],i=Reflect.ownKeys(r);(i.length!==s.length||i.some((o,n)=>o!==s[n]))&&u(`${t} must be a dense plain array`);for(let o=0;o<e;o+=1){const n=Object.getOwnPropertyDescriptor(r,String(o));(!n||!n.enumerable||!("value"in n)||n.value===void 0)&&u(`${t} must contain enumerable data values`)}}function Ye(r){const e=R(r,["reviewedTransform","schemaVersion"],"asset review protocol policy");p(e.schemaVersion,1,"asset review protocol schemaVersion");const t=R(e.reviewedTransform,["metersPerSourceUnit","quaternionNormTolerance","scaleComponentExclusiveMin","scaleComponentInclusiveMax","translationComponentAbsMax","upAxes"],"asset review transform policy"),s=R(t.metersPerSourceUnit,["cm","km","m","mm"],"asset review unit policy");for(const[i,o]of Object.entries(s))(typeof o!="number"||!Number.isFinite(o)||o<=0)&&u(`asset review unit policy ${i} must be positive and finite`);for(const[i,o]of[["quaternionNormTolerance",t.quaternionNormTolerance],["scaleComponentExclusiveMin",t.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",t.scaleComponentInclusiveMax],["translationComponentAbsMax",t.translationComponentAbsMax]])(typeof o!="number"||!Number.isFinite(o))&&u(`asset review transform policy ${i} must be finite`);return(t.quaternionNormTolerance<=0||t.scaleComponentInclusiveMax<=t.scaleComponentExclusiveMin||t.translationComponentAbsMax<=0)&&u("asset review transform policy bounds are inconsistent"),x(t.upAxes,3,"asset review up-axis policy"),t.upAxes.join("\0")!=="X_UP\0Y_UP\0Z_UP"&&u("asset review up-axis policy is invalid"),b([["metersPerSourceUnit",b(Object.entries(s))],["quaternionNormTolerance",t.quaternionNormTolerance],["scaleComponentExclusiveMin",t.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",t.scaleComponentInclusiveMax],["translationComponentAbsMax",t.translationComponentAbsMax],["upAxes",Object.freeze(Array.from({length:3},(i,o)=>t.upAxes[o]))]])}Ye(Pe);function p(r,e,t){return r!==e&&u(`${t} must equal ${JSON.stringify(e)}`),r}function Fe(r,e,t){return e.includes(r)||u(`${t} is not an allowed value`),r}function T(r,e,t){return v(r,t),e.test(r)||u(`${t} has an invalid encoding`),r}function Ke(r,e){return v(r,e),(!Ne.test(r)||new Date(r).toISOString()!==r)&&u(`${e} must be exact RFC3339 milliseconds UTC`),r}function qe(r,e){const t=R(r,Be,`identity key ${e.purpose}`);return p(t.purpose,e.purpose,"key purpose"),p(t.identityScheme,B,"key identityScheme"),p(t.seedProfile,$,"key seedProfile"),p(t.signatureProfile,e.signatureProfile,"key signatureProfile"),p(t.curve,e.curve,"key curve"),p(t.derivation,"slip10","key derivation"),p(t.path,e.path,"key path"),p(t.encoding,"raw","key encoding"),T(t.publicKeyHex,U,"key publicKeyHex"),p(t.bip32Fingerprint,null,"key bip32Fingerprint"),T(t.keyId,ge,"key keyId"),b([["bip32Fingerprint",null],["curve",t.curve],["derivation","slip10"],["encoding","raw"],["identityScheme",B],["keyId",t.keyId],["path",t.path],["publicKeyHex",t.publicKeyHex],["purpose",t.purpose],["seedProfile",$],["signatureProfile",t.signatureProfile]])}function ze(r){const e=R(r,ke,"WalletPublicIdentity");p(e.schemaVersion,1,"identity schemaVersion"),p(e.identityScheme,B,"identity identityScheme"),p(e.seedProfile,$,"identity seedProfile"),e.accountIndex!==0&&u("public wallet identity must use account 0"),p(e.accountLabel,null,"identity accountLabel"),v(e.accountXpub,"identity accountXpub"),/^xpub[1-9A-HJ-NP-Za-km-z]{107}$/u.test(e.accountXpub)||u("identity accountXpub is invalid"),v(e.accountPeerId,"identity accountPeerId"),(!e.accountPeerId.startsWith("16Uiu2H")||e.accountPeerId.length<40||e.accountPeerId.length>64||!De.test(e.accountPeerId))&&u("identity accountPeerId is invalid"),T(e.accountFingerprint,/^[0-9a-f]{8}$/u,"identity accountFingerprint"),x(e.keys,3,"public identity keys array");const t=[{purpose:"asset-review-approval",curve:"ed25519",signatureProfile:G,path:"m/44'/0'/0'/2'/0'"},{purpose:"contact-encryption",curve:"x25519",signatureProfile:null,path:"m/44'/0'/0'/1'/0'"},{purpose:"sdn-authentication",curve:"ed25519",signatureProfile:G,path:"m/44'/0'/0'/0'/0'"}],s=Array.from({length:3},(i,o)=>qe(e.keys[o],t[o]));return b([["accountFingerprint",e.accountFingerprint],["accountIndex",0],["accountLabel",null],["accountPeerId",e.accountPeerId],["accountXpub",e.accountXpub],["identityScheme",B],["keys",L(s)],["schemaVersion",1],["seedProfile",$]])}function te(r,e){const t=R(r,$e,`${e} result`);p(t.schemaVersion,1,"connection result schemaVersion"),Fe(t.event,["connected","disconnected"],"connection event"),e==="connect"&&t.event!=="connected"&&u("connect result must be connected");let s=null,i=null;return t.event==="connected"?(s=ze(t.identity),i=Ke(t.connectionExpiresAt,"connectionExpiresAt")):(t.identity!==null||t.connectionExpiresAt!==null)&&u("disconnected result must clear identity and expiry"),b([["connectionExpiresAt",i],["event",t.event],["identity",s],["schemaVersion",1]])}function re(r,e){return R(r,[],e),L({})}function He(r={}){return re(r,"wallet connect request")}function Je(r){return te(r,"connect")}function We(r={}){return re(r,"wallet account request")}function Xe(r){return te(r,"account")}const E=Object.freeze({envelopeBytes:512,fieldBytes:4096,batchBytes:12288,fields:16,contextBytes:256}),Qe=/^sdn-field-encryption\/v1\|[A-Za-z0-9_.-]{1,64}\|[A-Za-z0-9_.-]{1,64}\|[A-Za-z0-9_.-]{1,64}\|k[1-9][0-9]{0,8}$/u,se=["ciphertextBase64url","context","encBase64url","fieldId"],Ze=["fields","protocolVersion","replyPublicKeyHex"],ie=["context","encBase64url","kmfBase64url","protocolVersion","replyPublicKeyHex"],Ge=["fields","replyEphemeralPublicKeyHex","schemaVersion"],et=/^[A-Za-z0-9_-]*$/u;function M(r,e){return(!ArrayBuffer.isView(r)||!(r instanceof Uint8Array)||Object.getPrototypeOf(r)!==Uint8Array.prototype)&&u(`${e} must be a plain Uint8Array`),Uint8Array.from(r)}function C(r){let e="";for(let t=0;t<r.length;t+=1)e+=String.fromCharCode(r[t]);return globalThis.btoa(e).replace(/\+/gu,"-").replace(/\//gu,"_").replace(/=+$/gu,"")}function I(r,e,t,s){v(r,s),(!et.test(r)||r.length%4===1||r.length>Math.ceil(t*4/3))&&u(`${s} must be canonical unpadded base64url`);let i;try{i=globalThis.atob(r.replace(/-/gu,"+").replace(/_/gu,"/").padEnd(Math.ceil(r.length/4)*4,"="))}catch{u(`${s} must be valid base64url`)}const o=Uint8Array.from(i,n=>n.charCodeAt(0));return(o.length<e||o.length>t||C(o)!==r)&&u(`${s} must canonically encode ${e}..${t} bytes`),o}function H(r,e){return v(r,e),(k.encode(r).byteLength>E.contextBytes||!Qe.test(r))&&u(`${e} must be sdn-field-encryption/v1|<site>|<schema>|<field>|k<version>`),r}function tt(r){return H(r,"context").split("|")[1]}function ne(r){const e=R(r,Ze,"field-open request");p(e.protocolVersion,1,"field-open protocolVersion"),T(e.replyPublicKeyHex,U,"replyPublicKeyHex"),(!Array.isArray(e.fields)||e.fields.length<1||e.fields.length>E.fields)&&u(`field-open request carries 1..${E.fields} fields`),x(e.fields,e.fields.length,"field-open fields");let t=0;const s=e.fields.map((i,o)=>{const n=R(i,se,`field ${o}`);return I(n.encBase64url,1,E.envelopeBytes,`field ${o} encBase64url`),t+=I(n.ciphertextBase64url,1,E.fieldBytes,`field ${o} ciphertextBase64url`).length,H(n.context,`field ${o} context`),(!Number.isInteger(n.fieldId)||n.fieldId<0||n.fieldId>65535)&&u(`field ${o} fieldId must be 0..65535`),b(se.map(a=>[a,n[a]]))});return t>E.batchBytes&&u(`field-open ciphertext exceeds ${E.batchBytes} bytes`),b([["fields",L(s)],["protocolVersion",1],["replyPublicKeyHex",e.replyPublicKeyHex]])}function oe(r){const e=R(r,ie,"key-unwrap request");return p(e.protocolVersion,1,"key-unwrap protocolVersion"),T(e.replyPublicKeyHex,U,"replyPublicKeyHex"),H(e.context,"key-unwrap context"),I(e.encBase64url,1,E.envelopeBytes,"key-unwrap encBase64url"),I(e.kmfBase64url,1,E.envelopeBytes,"key-unwrap kmfBase64url"),b(ie.map(t=>[t,e[t]]))}function ce(r,e){const t=R(r,Ge,"field result");p(t.schemaVersion,1,"field result schemaVersion"),T(t.replyEphemeralPublicKeyHex,U,"replyEphemeralPublicKeyHex"),(!Array.isArray(t.fields)||t.fields.length<1||t.fields.length>e)&&u(`field result carries 1..${e} fields`),x(t.fields,t.fields.length,"field result fields");const s=t.fields.map((i,o)=>{if((ee(i)?i.status:void 0)==="opened"){const l=R(i,["ciphertextBase64url","status"],`field result ${o}`);return I(l.ciphertextBase64url,1,E.fieldBytes,`field result ${o} ciphertext`),b([["ciphertextBase64url",l.ciphertextBase64url],["status","opened"]])}const a=R(i,["reason","status"],`field result ${o}`);return p(a.status,"refused",`field result ${o} status`),p(a.reason,"NOT_ADDRESSED_TO_ACCOUNT",`field result ${o} reason`),b([["reason","NOT_ADDRESSED_TO_ACCOUNT"],["status","refused"]])});return b([["fields",L(s)],["replyEphemeralPublicKeyHex",t.replyEphemeralPublicKeyHex],["schemaVersion",1]])}function rt(r,e="0".repeat(64)){const t=R(r,["fields"],"openFields input");return Array.isArray(t.fields)||u("openFields fields must be an array"),x(t.fields,t.fields.length,"openFields fields"),ne({fields:t.fields.map((s,i)=>{const o=R(s,["ciphertext","context","enc","fieldId"],`openFields field ${i}`);return{ciphertextBase64url:C(M(o.ciphertext,`field ${i} ciphertext`)),context:o.context,encBase64url:C(M(o.enc,`field ${i} enc`)),fieldId:o.fieldId}}),protocolVersion:1,replyPublicKeyHex:e})}function st(r){return ne(r)}function it(r){return ce(r,E.fields)}function nt(r,e="0".repeat(64)){const t=R(r,["context","enc","kmf"],"unwrapKey input");return oe({context:t.context,encBase64url:C(M(t.enc,"enc")),kmfBase64url:C(M(t.kmf,"kmf")),protocolVersion:1,replyPublicKeyHex:e})}function ot(r){return oe(r)}function ct(r){return ce(r,1)}const at=new TextEncoder().encode("sdn-wallet-reply/v1"),lt=new TextEncoder().encode("flatbuffers-field"),ut=new TextEncoder().encode("flatbuffers-iv");function ft(r){return Array.from(r,e=>e.toString(16).padStart(2,"0")).join("")}function ht(r){return Uint8Array.from(r.match(/../gu),e=>Number.parseInt(e,16))}function ae(r,e){const t=new Uint8Array(r.length+6);return t.set(r),t[r.length]=e>>8,t[r.length+1]=e&255,t}async function J(r,e,t,s){const i=await r.importKey("raw",e,"HKDF",!1,["deriveBits"]);return new Uint8Array(await r.deriveBits({hash:"SHA-256",info:t,name:"HKDF",salt:new Uint8Array(0)},i,s))}async function dt(r){const e=r?.subtle;if(!e)throw new Error("Web Crypto is unavailable");const t=await e.generateKey({name:"X25519"},!1,["deriveBits"]),s=new Uint8Array(await e.exportKey("raw",t.publicKey));if(s.length!==32)throw new Error("X25519 public key is not 32 bytes");let i=t.privateKey;return Object.freeze({publicKeyHex:ft(s),async open(o,n){if(!i)throw new Error("reply key already used");const a=i;i=null;const l=await e.importKey("raw",ht(o),{name:"X25519"},!1,[]),f=new Uint8Array(await e.deriveBits({name:"X25519",public:l},a,256)),h=await J(e,f,at,256);f.fill(0);try{return await Promise.all(n.map(async(d,y)=>{if(d===null)return null;const m=await J(e,h,ae(lt,y),256),w=await J(e,h,ae(ut,y),128),Q=await e.importKey("raw",m,"AES-CTR",!1,["decrypt"]);return m.fill(0),new Uint8Array(await e.decrypt({counter:w,length:128,name:"AES-CTR"},Q,d))}))}finally{h.fill(0)}}})}const P="https://wallet.spacedatanetwork.org",V="sdn.wallet.callback.v1:",N=/^[0-9a-f]{64}$/u,le=/^[A-Za-z0-9_-]{43}$/u,yt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,pt=250,mt=3e4,Rt=3e5,Et=9e5,bt=12e4,At=8,ue=4096,fe=70*1024,wt=64,he=Object.freeze({CALLBACK_ERROR:"The wallet return could not be verified. Try again.",CRYPTO_UNAVAILABLE:"Secure browser cryptography is unavailable.",DESTROYED:"This wallet client has been destroyed.",DISCONNECTED:"The wallet was disconnected.",EXPIRED:"The wallet connection expired.",INVALID_CLIENT:"This wallet client is not registered.",INVALID_REQUEST:"The wallet request is invalid.",NOT_ADDRESSED_TO_ACCOUNT:"This data is not sealed to your wallet.",RELAY_ERROR:"The wallet service could not complete the request. Try again.",REPLACED:"A newer wallet request replaced this one.",WALLET_NOT_COMPLETED:"The wallet did not complete. Check popup settings and try again."}),de=new TextEncoder,Ot=new TextDecoder("utf-8",{fatal:!0});class g extends Error{constructor(e){super(he[e]),this.name="WalletClientError",Object.defineProperty(this,"code",{configurable:!1,enumerable:!0,value:e,writable:!1})}}function c(r){return Object.hasOwn(he,r)?new g(r):new g("RELAY_ERROR")}function _t(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}function Y(r,e){if(typeof r!="string"||r.length>e||de.encode(r).byteLength>e||r.charCodeAt(0)===65279)throw c("RELAY_ERROR");let t=0,s=0;const i=()=>{for(;t<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[t]);)t+=1},o=()=>{if(r[t]!=='"')throw c("RELAY_ERROR");const l=t;for(t+=1;t<r.length;){const f=r.charCodeAt(t);if(f===34){t+=1;let h;try{h=JSON.parse(r.slice(l,t))}catch{throw c("RELAY_ERROR")}for(let d=0;d<h.length;d+=1){const y=h.charCodeAt(d);if(y>=55296&&y<=56319){const m=h.charCodeAt(d+1);if(!(m>=56320&&m<=57343))throw c("RELAY_ERROR");d+=1}else if(y>=56320&&y<=57343)throw c("RELAY_ERROR")}return h}if(f<32||f===92&&(t+=1,t>=r.length))throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")},n=(l=0)=>{if(l>32||++s>4096)throw c("RELAY_ERROR");i();const f=r[t];if(f==='"')return o();if(f==="{"){t+=1;const y=Object.create(null),m=new Set;if(i(),r[t]==="}")return t+=1,y;for(;t<r.length;){i();const w=o();if(m.has(w)||(m.add(w),i(),r[t]!==":"))throw c("RELAY_ERROR");if(t+=1,y[w]=n(l+1),i(),r[t]==="}")return t+=1,y;if(r[t]!==",")throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")}if(f==="["){t+=1;const y=[];if(i(),r[t]==="]")return t+=1,y;for(;t<r.length;){if(y.push(n(l+1)),i(),r[t]==="]")return t+=1,y;if(r[t]!==",")throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")}for(const[y,m]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(y,t))return t+=y.length,m;const h=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(t));if(!h)throw c("RELAY_ERROR");t+=h[0].length;const d=Number(h[0]);if(!Number.isFinite(d))throw c("RELAY_ERROR");return d};i();const a=n();if(i(),t!==r.length)throw c("RELAY_ERROR");return a}function F(r,e,t="RELAY_ERROR"){if(!_t(r)||Object.getOwnPropertySymbols(r).length!==0)throw c(t);const s=Object.getOwnPropertyNames(r).sort(),i=[...e].sort();if(s.length!==i.length||s.some((o,n)=>o!==i[n]))throw c(t);for(const o of s){const n=Object.getOwnPropertyDescriptor(r,o);if(!n?.enumerable||!("value"in n)||n.value===void 0)throw c(t)}return r}function K(r,e="RELAY_ERROR"){if(typeof r!="string"||!yt.test(r))throw c(e);const t=Date.parse(r);if(!Number.isFinite(t)||new Date(t).toISOString()!==r)throw c(e);return t}function _(r){return Array.isArray(r)?Object.freeze(r.map(_)):r&&typeof r=="object"?Object.freeze(Object.fromEntries(Object.entries(r).map(([e,t])=>[e,_(t)]))):r}function ye(r){const e={identity:r.identity===null?null:_(r.identity),status:r.status};return r.connectionExpiresAt!==void 0&&(e.connectionExpiresAt=r.connectionExpiresAt),r.error!==void 0&&(e.error=_(r.error)),_(e)}function D(r){return Object.freeze({code:r.code,message:r.message})}function pe(r){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";let t=0,s=0,i="";for(const o of r)for(t=t<<8|o,s+=8;s>=6;)s-=6,i+=e[t>>>s&63],t&=(1<<s)-1;return s!==0&&(i+=e[t<<6-s&63]),i}function me(r){let e="";for(const t of r)e+=t.toString(16).padStart(2,"0");return e}function W(r,e){const t=new Uint8Array(32);return Reflect.apply(e,r,[t]),t}function vt(r){const e=r?.headers?.get?.("content-type");return typeof e=="string"&&/^application\/json(?:\s*;\s*charset=utf-8)?$/iu.test(e.trim())}function X(r){try{Promise.resolve(r).catch(()=>{})}catch{}}function j(r){try{const e=r?.body,t=e?.cancel;typeof t=="function"&&X(Reflect.apply(t,e,[]))}catch{}}function Re(r){try{const e=r?.cancel;typeof e=="function"&&X(Reflect.apply(e,r,[]))}catch{}}function Lt(r){try{const e=r?.releaseLock;typeof e=="function"&&Reflect.apply(e,r,[])}catch{}}function S(r,e,t=null){try{r.abort()}catch{}t&&Re(t),j(e)}function q(r,e,t=null){let s;try{s=Promise.resolve(r)}catch(i){return Promise.reject(i)}return new Promise((i,o)=>{let n=!1;const a=()=>{try{e.removeEventListener("abort",f)}catch{}},l=(h,d)=>n?!1:(n=!0,a(),h(d),!0),f=()=>{l(o,c("RELAY_ERROR"))};try{e.addEventListener("abort",f,{once:!0}),e.aborted&&f()}catch{f()}s.then(h=>{if(n){try{t?.(h)}catch{}return}l(i,h)},h=>{n||l(o,h)})})}async function Ee(r,e,t){let s=null;const i=[];let o=0;try{if(!vt(r)||typeof r?.body?.getReader!="function")throw c("RELAY_ERROR");for(s=r.body.getReader();;){const l=s.read(),{done:f,value:h}=await q(l,t.signal);if(f)break;if(!(h instanceof Uint8Array)||(o+=h.byteLength,o>e))throw c("RELAY_ERROR");i.push(h)}const n=new Uint8Array(o);let a=0;for(const l of i)n.set(l,a),a+=l.byteLength;return Ot.decode(n)}catch{try{t.abort()}catch{}throw s&&Re(s),c("RELAY_ERROR")}finally{s&&Lt(s)}}function z(r,e){const t={body:JSON.stringify(r),cache:"no-store",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"error",referrerPolicy:"no-referrer"};return e!==void 0&&(t.signal=e),t}function Tt(r,e,t){let s;try{s=Y(r,2048),F(s,["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR")}catch{throw c("CALLBACK_ERROR")}if(s.schemaVersion!==1||s.state!==e||!N.test(s.code))throw c("CALLBACK_ERROR");const i=K(s.expiresAt,"CALLBACK_ERROR");if(i<=t||i-t>bt)throw c("CALLBACK_ERROR");return{code:s.code,expiresAt:i,state:s.state}}function It(){let r;return{promise:new Promise(t=>{r=t}),resolve:r}}function be(){let r,e;return{promise:new Promise((s,i)=>{r=i,e=s}),reject:r,resolve:e}}function St(){const r=globalThis.window;return Object.freeze({AbortController:globalThis.AbortController,clearInterval:globalThis.clearInterval.bind(globalThis),clearTimeout:globalThis.clearTimeout.bind(globalThis),crypto:globalThis.crypto,fetch:typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,getStorage:()=>{try{return r?.localStorage??null}catch{return null}},now:()=>Date.now(),setInterval:globalThis.setInterval.bind(globalThis),setTimeout:globalThis.setTimeout.bind(globalThis),window:r})}class xt{#k;#B;#x=!1;#l=!1;#$=!1;#n=null;#O=null;#b=new Set;#e;#_=null;#r=!1;#m=0;#v=0;#L=new Set;#C=[];#o=null;#P=!1;#y=new Set;#U=Object.freeze({identity:null,status:"dormant"});#u=null;#T=null;#A=null;#R=new Set;#p;constructor({adapters:e,clientId:t,dependencies:s}){this.#k=e,this.#B=t,this.#e=s??St(),this.#p=this.#e.window}getSnapshot(){return this.#Y(),ye(this.#U)}subscribe(e){if(typeof e!="function")throw c("INVALID_REQUEST");if(this.#r)throw c("DESTROYED");this.#L.add(e);try{e(this.getSnapshot())}catch{}let t=!0;return()=>{t&&(t=!1,this.#L.delete(e))}}execute(e,t){if(this.#r)return Promise.reject(c("DESTROYED"));const s=this.#m,i=this.#k[e];if(!i)return Promise.reject(c("INVALID_REQUEST"));let o;try{o=i.buildRequest(t)}catch{const A=this.#t(s);return A?Promise.reject(A):Promise.reject(c("INVALID_REQUEST"))}let n=this.#t(s);if(n)return Promise.reject(n);if(this.#x)return this.#l=!0,Promise.reject(c("REPLACED"));const a=++this.#m;if(this.#Q(),n=this.#t(a),n)return Promise.reject(n);if(this.#l)return Promise.reject(c("CALLBACK_ERROR"));if(this.#Y(),n=this.#t(a),n)return Promise.reject(n);const l=this.#i();if(n=this.#t(a),n)return Promise.reject(n);const f=this.#n&&this.#n.expiresAtMs>l?this.#n:null;if(n=this.#t(a),n)return Promise.reject(n);const h=this.#o;let d,y,m;try{const A=this.#e.crypto,O=A?.getRandomValues,Bt=A?.subtle?.digest,Se=this.#p?.open;if(n=this.#t(a),n)throw n;if(typeof O!="function"||typeof Bt!="function"||typeof Se!="function")throw c("CRYPTO_UNAVAILABLE");if(d=me(W(A,O)),n=this.#t(a),n||(y=me(W(A,O)),n=this.#t(a),n)||(m=pe(W(A,O)),n=this.#t(a),n))throw n;if(!N.test(d)||!N.test(y)||!le.test(m))throw c("CRYPTO_UNAVAILABLE");if(Reflect.apply(Se,this.#p,[`${P}/transaction/${d}`,"_blank","noopener"]),n=this.#t(a),n)throw n}catch(A){if(n=this.#t(a),n)return Promise.reject(n);let O;try{O=A instanceof g?A:c("CRYPTO_UNAVAILABLE")}catch{O=c("CRYPTO_UNAVAILABLE")}return h&&(this.#I(h,"REPLACED",!1),n=this.#t(a),n)?Promise.reject(n):(this.#M(null,O,f,i.kind),Promise.reject(O))}if(h&&(this.#I(h,"REPLACED",!1),n=this.#t(a),n))return Promise.reject(n);const w=be(),Q=It(),Ie={active:!0,adapter:i,callbackBusy:!1,challenge:null,cleanup:Q,cleanupFinished:!1,cleanupStarted:!1,controllers:new Set,expiryTimer:null,generation:++this.#v,operationTimer:null,phase:"hashing",pollTimer:null,priorConnection:f,promise:w.promise,registrationDeadlineMs:l+mt,registrationOutcome:"none",reject:w.reject,openResult:null,request:o,resolve:w.resolve,retryResolve:null,retryTimer:null,state:y,transactionExpiresAtMs:null,transactionId:d,verifier:m};return this.#o=Ie,this.#s({...f?{connectionExpiresAt:f.expiresAt,identity:f.identity}:{identity:null},status:"opening"}),this.#q(Ie),w.promise}async disconnect(){if(this.#r)throw c("DESTROYED");const e=++this.#m;this.#h();const t=this.#o;let s=Promise.resolve();t&&(s=this.#I(t,"DISCONNECTED",!1));let i=this.#t(e);if(i)throw await s,i;if(this.#s({identity:null,status:"dormant"}),await s,i=this.#t(e),i)throw i}destroy(){if(this.#_)return this.#_;const e=be();this.#_=e.promise,this.#m+=1;try{this.#K(),e.resolve()}catch{e.reject(c("RELAY_ERROR"))}return this.#_}#K(){this.#r=!0,this.#v+=1,this.#h();const e=[],t=this.#o;t&&(t.active=!1,this.#o=null,this.#S(t),t.reject(c("DESTROYED")),t.challenge&&t.verifier&&e.push(t));for(const s of this.#y)s.challenge&&s.verifier&&e.push(s);for(const s of this.#b)s.abort();this.#b.clear();for(const s of this.#R)this.#e.clearTimeout(s),this.#e.clearInterval(s);if(this.#R.clear(),this.#A)try{this.#A()}catch{}this.#T=null,this.#A=null,this.#u=null,this.#L.clear();for(const s of e)this.#X(s);t&&this.#a(t);for(const s of[...this.#y])this.#a(s);this.#s({error:D(c("DESTROYED")),identity:null,status:"error"})}async#q(e){if(!(!this.#c(e)||e.cleanupFinished))try{if(e.operationTimer=this.#w(()=>{if(!e.cleanupFinished){if(e.phase==="hashing"){this.#c(e)&&this.#f(e,"CRYPTO_UNAVAILABLE",!1);return}if(e.phase==="registering")for(const a of e.controllers)a.abort()}},Math.max(0,e.registrationDeadlineMs-this.#i())),typeof e.adapter.seal=="function"){const a=await e.adapter.seal(e.request,this.#e.crypto);e.request=a.request,e.openResult=a.open}const t=await this.#e.crypto.subtle.digest("SHA-256",de.encode(e.verifier)),s=pe(new Uint8Array(t));if(!le.test(s))throw c("CRYPTO_UNAVAILABLE");if(!this.#c(e)){e.registrationOutcome="not-started",this.#a(e);return}e.challenge=s,e.phase="registering";const i=this.#g(e);let o,n=null;try{try{const l=this.#e.fetch(`${P}/relay/v1/transactions`,z({clientId:this.#B,codeChallenge:e.challenge,codeChallengeMethod:"S256",operation:e.adapter.operation,request:e.request,schemaVersion:1,state:e.state,transactionId:e.transactionId},i.signal));n=await q(l,i.signal,j)}catch{e.registrationOutcome="ambiguous",e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}e.registrationOutcome="ambiguous";let a;try{a=n.status}catch{S(i,n),e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}if(a!==201){e.registrationOutcome="definitive-failure",S(i,n),e.active?this.#f(e,"RELAY_ERROR",!1):this.#a(e);return}try{const l=await Ee(n,ue,i),f=F(Y(l,ue),["expiresAt","schemaVersion","transactionId"]);if(f.schemaVersion!==1||f.transactionId!==e.transactionId)throw c("RELAY_ERROR");o=K(f.expiresAt);const h=this.#i();if(o<=h||o-h>Rt)throw c("RELAY_ERROR")}catch{e.registrationOutcome="ambiguous",S(i,n),e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}}finally{try{i.abort()}catch{}this.#D(e,i),this.#d(e.operationTimer),e.operationTimer=null}if(e.transactionExpiresAtMs=o,e.registrationOutcome="registered",!this.#c(e)){this.#E(e);return}e.phase="waiting-callback",e.expiryTimer=this.#w(()=>{this.#c(e)&&this.#f(e,"WALLET_NOT_COMPLETED")},Math.max(0,e.transactionExpiresAtMs-this.#i())),e.pollTimer=this.#W(()=>{this.#N(e,!1)},pt),await this.#N(e,!1)}catch(t){if(!e.active){e.registrationOutcome==="ambiguous"||e.registrationOutcome==="registered"?this.#E(e):this.#a(e);return}const s=t instanceof g?t.code:e.phase==="hashing"?"CRYPTO_UNAVAILABLE":"RELAY_ERROR";this.#f(e,s,e.registrationOutcome!=="none")}}async#N(e,t){if(!this.#c(e)||e.phase!=="waiting-callback"||e.callbackBusy||!this.#u)return;const s=`${V}${e.state}`;let i;try{i=this.#u.getItem(s)}catch{t&&this.#f(e,"CALLBACK_ERROR");return}if(i===null)return;e.callbackBusy=!0;let o;try{o=Tt(i,e.state,this.#i()),this.#u.removeItem(s)}catch{try{this.#u.removeItem(s)}catch{}this.#f(e,"CALLBACK_ERROR");return}if(!this.#c(e))return;e.phase="redeeming",this.#d(e.pollTimer,!0),e.pollTimer=null;const n=this.#g(e);let a=null;try{const l=this.#e.fetch(`${P}/relay/v1/codes/redeem`,z({code:o.code,codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId},n.signal));if(a=await q(l,n.signal,j),a.status!==200)throw c("RELAY_ERROR");const f=await Ee(a,fe,n),h=F(Y(f,fe),["result","schemaVersion","transactionId"]);if(h.schemaVersion!==1||h.transactionId!==e.transactionId)throw c("RELAY_ERROR");let d;try{d=e.adapter.parseResult(h.result)}catch{throw c("RELAY_ERROR")}if(e.openResult&&(d=await e.openResult(d)),!this.#c(e))return;this.#z(e,d)}catch(l){if(a&&S(n,a),!this.#c(e))return;const f=l instanceof g?l.code:"RELAY_ERROR";this.#f(e,f)}finally{try{n.abort()}catch{}this.#D(e,n)}}#z(e,t){if(!this.#c(e))return;let s=null;(e.adapter.kind==="connect"||e.adapter.kind==="account"&&t.event==="connected")&&(s=this.#H(t)),e.active=!1,this.#o=null,this.#S(e);let i=t;e.adapter.kind==="connect"?(this.#V(s),i=_(t.identity)):e.adapter.kind==="account"?(t.event==="connected"?this.#V(s):(this.#h(),this.#s({identity:null,status:"dormant"})),i=void 0):this.#J(e,void 0),e.resolve(i),this.#a(e)}#f(e,t,s=!0){this.#c(e)&&this.#I(e,t,!0,s)}#I(e,t,s,i=!0){if(!e.active)return e.cleanup.promise;const o=this.#m;e.active=!1,this.#o===e&&(this.#o=null),this.#v+=1,this.#S(e);for(const l of e.controllers)e.phase!=="registering"&&l.abort();const n=this.#t(o),a=n??c(t);return e.reject(a),s&&!n&&this.#M(e,a,e.priorConnection,e.adapter.kind),this.#r?(e.challenge&&e.verifier&&this.#F(e),this.#a(e),e.cleanup.promise):(!i||e.registrationOutcome==="definitive-failure"||e.registrationOutcome==="not-started"?this.#a(e):e.phase==="hashing"?(e.registrationOutcome="not-started",this.#a(e)):e.phase==="registering"&&e.registrationOutcome==="none"?this.#j(e):(this.#j(e),this.#E(e)),e.cleanup.promise)}#M(e,t,s,i){if(s?.expiresAtMs>this.#i()){this.#n=s,this.#s({connectionExpiresAt:s.expiresAt,error:D(t),identity:s.identity,status:"connected"});return}this.#h(),this.#s({error:D(t),identity:null,status:"error"})}#H(e){const t=K(e.connectionExpiresAt),s=this.#i();if(t<=s||t-s>Et)throw c("RELAY_ERROR");return{expiresAt:e.connectionExpiresAt,expiresAtMs:t,identity:_(e.identity)}}#V(e){const t=this.#i();this.#h(),this.#n=e;const s=this.#n;this.#O=this.#w(()=>{this.#n===s&&(this.#n=null,this.#O=null,this.#o?this.#s({identity:null,status:"opening"}):this.#s({identity:null,status:"dormant"}))},Math.max(0,e.expiresAtMs-t)),this.#s({connectionExpiresAt:e.expiresAt,identity:this.#n.identity,status:"connected"})}#J(e,t){const s=e.priorConnection;s?.expiresAtMs>this.#i()?(this.#n=s,this.#s({connectionExpiresAt:s.expiresAt,...t?{error:D(t)}:{},identity:s.identity,status:"connected"})):t?(this.#h(),this.#s({error:D(t),identity:null,status:"error"})):(this.#h(),this.#s({identity:null,status:"dormant"}))}#Y(){!this.#n||this.#n.expiresAtMs>this.#i()||(this.#h(),this.#o?this.#s({identity:null,status:"opening"}):this.#s({identity:null,status:"dormant"}))}#h(){this.#n=null,this.#d(this.#O),this.#O=null}#s(e){const t=_(e);if(this.#U=t,this.#C.push(t),!this.#P){this.#P=!0;try{for(;this.#C.length!==0;){const s=this.#C.shift();for(const i of[...this.#L])try{i(ye(s))}catch{}}}finally{this.#P=!1}}}#c(e){return!this.#r&&e.active&&this.#o===e&&e.generation===this.#v}#t(e){return this.#r?c("DESTROYED"):e!==this.#m?c("REPLACED"):null}#i(){return this.#e.now()}#g(e){const t=new this.#e.AbortController;return e.controllers.add(t),this.#b.add(t),t}#D(e,t){e.controllers.delete(t),this.#b.delete(t)}#w(e,t){let s;return s=this.#e.setTimeout(()=>{this.#R.delete(s),e()},Math.max(0,t)),this.#R.add(s),s}#W(e,t){const s=this.#e.setInterval(e,t);return this.#R.add(s),s}#d(e,t=!1){e!=null&&(t?this.#e.clearInterval(e):this.#e.clearTimeout(e),this.#R.delete(e))}#S(e){this.#d(e.expiryTimer),this.#d(e.pollTimer,!0),e.expiryTimer=null,e.pollTimer=null}#j(e){if(!(e.cleanupFinished||this.#y.has(e)))for(this.#y.add(e);this.#y.size>At;){const t=this.#y.values().next().value;for(const s of t.controllers)s.abort();this.#a(t)}}async#E(e){if(e.cleanupFinished||e.cleanupStarted||this.#r)return e.cleanup.promise;e.cleanupStarted=!0,this.#j(e);let t=100,s=!0;for(;!this.#r&&!e.cleanupFinished&&(s||this.#i()<=e.registrationDeadlineMs);){s=!1;const i=await this.#F(e);if(e.cleanupFinished)return e.cleanup.promise;if(i==="done")return this.#a(e),e.cleanup.promise;const o=e.registrationDeadlineMs-this.#i();if(o<=0)break;await new Promise(n=>{e.retryResolve=n,e.retryTimer=this.#w(()=>{e.retryResolve=null,n()},Math.min(t,o))}),e.retryResolve=null,e.retryTimer=null,t=Math.min(t*2,4e3)}return this.#a(e),e.cleanup.promise}async#F(e){if(!e.verifier||!e.challenge)return"done";const t=this.#g(e),s=e.registrationDeadlineMs-this.#i(),i=s>0?Math.min(4e3,s):1e3,o=this.#w(()=>t.abort(),Math.max(1,i));let n=null;try{const a=this.#e.fetch(`${P}/relay/v1/transactions/${e.transactionId}/cancel`,z({codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId},t.signal));n=await q(a,t.signal,j);const l=n.status;return S(t,n),n=null,l===204||l===400||l===403||l===409||l===410?"done":"retry"}catch{return n&&S(t,n),"retry"}finally{try{t.abort()}catch{}this.#d(o),this.#D(e,t)}}#X(e){let t;try{t=this.#e.fetch(`${P}/relay/v1/transactions/${e.transactionId}/cancel`,{...z({codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId}),keepalive:!0})}catch{return}X(Promise.resolve(t).then(j))}#a(e){if(!e.cleanupFinished){e.cleanupFinished=!0,this.#d(e.retryTimer),e.retryResolve?.(),e.retryResolve=null,e.retryTimer=null,this.#d(e.operationTimer),e.operationTimer=null,this.#S(e);for(const t of e.controllers)t.abort(),this.#b.delete(t);e.controllers.clear(),this.#y.delete(e),e.adapter=null,e.challenge=null,e.priorConnection=null,e.request=null,e.state=null,e.transactionExpiresAtMs=null,e.transactionId=null,e.verifier=null,e.cleanup.resolve()}}#Q(){if(!(this.#$||this.#r)){this.#$=!0,this.#x=!0;try{let e=null;try{const o=this.#e.getStorage;e=typeof o=="function"?Reflect.apply(o,void 0,[]):this.#e.storage??null}catch{e=null,this.#l=!0}try{(!e||typeof e.getItem!="function"||typeof e.removeItem!="function")&&(this.#l=!0)}catch{this.#l=!0}if(this.#r||this.#l){this.#u=null;return}if(this.#u=e,this.#Z(),this.#r||this.#l){this.#u=null;return}const t=o=>{const n=this.#o;if(!n||!this.#c(n))return;const a=`${V}${n.state}`;o?.key===a&&this.#N(n,!0)};this.#T=t;let s=!1,i=null;try{const o=this.#p?.addEventListener,n=this.#p?.removeEventListener;if(typeof o!="function"||typeof n!="function")throw new TypeError("storage events unavailable");i=()=>Reflect.apply(n,this.#p,["storage",t]),this.#A=i,Reflect.apply(o,this.#p,["storage",this.#T]),s=!0}catch{this.#l=!0}if(!s||this.#r||this.#l){try{i?.()}catch{}this.#T=null,this.#A=null,this.#u=null}}finally{this.#x=!1}}}#Z(){const e=this.#u;if(!e)return;let t;try{t=e.length}catch{return}if(!Number.isSafeInteger(t)||t<0)return;const s=Math.min(t,wt),i=[];for(let o=0;o<s&&!this.#r&&!this.#l;o+=1){let n;try{n=e.key(o)}catch{continue}i.push(n)}for(const o of i){if(this.#r||this.#l)return;if(typeof o!="string"||!o.startsWith(V))continue;const n=o.slice(V.length);if(N.test(n))try{const a=e.getItem(o);if(a===null)continue;const l=F(Y(a,2048),["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR");if(l.schemaVersion!==1||l.state!==n||!N.test(l.code))continue;K(l.expiresAt,"CALLBACK_ERROR")<=this.#i()&&e.removeItem(o)}catch{}}}}function Ae(r){return new xt(r)}function we(r,e={}){const t=(i,o)=>i!==0?Promise.reject(c("INVALID_REQUEST")):o(),s={connect(...i){return t(i.length,()=>r.execute("connect",void 0))},destroy(...i){return t(i.length,()=>r.destroy())},disconnect(...i){return t(i.length,()=>r.disconnect())},getSnapshot(...i){if(i.length!==0)throw c("INVALID_REQUEST");return r.getSnapshot()},openAccount(...i){return t(i.length,()=>r.execute("account",void 0))},subscribe(i,...o){if(o.length!==0)throw c("INVALID_REQUEST");return r.subscribe(i)}};for(const[i,o]of Object.entries(e))s[i]=function(a,...l){return l.length!==0?Promise.reject(c("INVALID_REQUEST")):r.execute(o,a)};return Object.freeze(s)}const Ct=Object.freeze(["orbpro-pages-v1","sdn-asset-models-pages-v1","sdn-asset-review-v1","sdn-flatbuffers-pages-v1","sdn-flatsql-pages-v1","sdn-landing-web-v1","sdn-module-sdk-pages-v1","sdn-node-console-v1","sdn-standards-web-v1","spaceaware-web-v1"]);function Pt(r){let e;try{const t=Reflect.ownKeys(r);if(r===null||typeof r!="object"||Array.isArray(r)||Object.getPrototypeOf(r)!==Object.prototype||t.length!==1||t[0]!=="clientId")throw c("INVALID_REQUEST");e=Object.getOwnPropertyDescriptor(r,"clientId")}catch{throw c("INVALID_REQUEST")}if(!e?.enumerable||!("value"in e)||typeof e.value!="string")throw c("INVALID_REQUEST");if(!Ct.includes(e.value))throw c("INVALID_CLIENT");return e.value}const Oe=Object.freeze({account:Object.freeze({buildRequest:()=>We({}),kind:"account",operation:"sdn.wallet.account.v1",parseResult:Xe}),connect:Object.freeze({buildRequest:()=>He({}),kind:"connect",operation:"sdn.wallet.connect.v1",parseResult:Je})});function _e(r,e){if(tt(r)!==e)throw c("INVALID_REQUEST")}function ve({operation:r,buildRequest:e,parseRequest:t,parseResult:s,openResult:i}){return Object.freeze({buildRequest:e,kind:"typed",operation:r,parseResult:s,async seal(o,n){let a;try{a=await dt(n)}catch{throw c("CRYPTO_UNAVAILABLE")}return Object.freeze({request:t({...o,replyPublicKeyHex:a.publicKeyHex}),async open(l){const f=l.fields.map(d=>d.status==="opened"?I(d.ciphertextBase64url,1,E.fieldBytes,"reply"):null);let h;try{h=await a.open(l.replyEphemeralPublicKeyHex,f)}catch{throw c("CRYPTO_UNAVAILABLE")}return i(h)}})}})}const Nt=r=>ve({operation:"sdn.wallet.field-open.v1",buildRequest(e){const t=rt(e);for(const s of t.fields)_e(s.context,r);return t},parseRequest:st,parseResult:it,openResult:e=>Object.freeze(e.map(t=>Object.freeze(t===null?{refused:"NOT_ADDRESSED_TO_ACCOUNT"}:{plaintext:t})))}),gt=r=>ve({operation:"sdn.wallet.key-unwrap.v1",buildRequest(e){const t=nt(e);return _e(t.context,r),t},parseRequest:ot,parseResult:ct,openResult([e]){if(e===null)throw c("NOT_ADDRESSED_TO_ACCOUNT");if(e.length!==32)throw c("RELAY_ERROR");return Object.freeze({contentKey:e})}}),Dt=Object.freeze({"sdn-flatbuffers-pages-v1":Object.freeze({method:"openFields",adapter:Nt("flatbuffers")}),"sdn-flatsql-pages-v1":Object.freeze({method:"unwrapKey",adapter:gt("flatsql")})});function Le(r){if(arguments.length!==1)throw c("INVALID_REQUEST");const e=Pt(r),t=Dt[e];if(!t){const i=Ae({adapters:Oe,clientId:e});return we(i)}const s=Ae({adapters:Object.freeze({...Oe,sealed:t.adapter}),clientId:e});return we(s,{[t.method]:"sealed"})}const Te="SDNWalletPublicClient";if(Object.prototype.hasOwnProperty.call(globalThis,Te))throw new Error("SDN wallet public client global already exists");function jt(r){return arguments.length!==1?Le(...arguments):Le(r)}const kt=Object.freeze({create:jt});Object.defineProperty(globalThis,Te,{configurable:!1,enumerable:!1,value:kt,writable:!1})})();
1
+ (function(){"use strict";const xe=Object.freeze({cm:.01,km:1e3,m:1,mm:.001}),Ce=Object.freeze({metersPerSourceUnit:xe,quaternionNormTolerance:1e-6,scaleComponentExclusiveMin:0,scaleComponentInclusiveMax:1e6,translationComponentAbsMax:1e6,upAxes:Object.freeze(["X_UP","Y_UP","Z_UP"])}),Pe=Object.freeze({reviewedTransform:Ce,schemaVersion:1}),k=new TextEncoder,Z=Object.getPrototypeOf(Uint8Array.prototype);Object.getOwnPropertyDescriptor(Z,"buffer").get,Object.getOwnPropertyDescriptor(Z,"length").get,Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,typeof SharedArrayBuffer>"u"||Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype,"byteLength").get;const B="sdn-bip32-slip10-purpose-v1",$="password-scrypt-v2",G="ed25519-over-sha256-jcs-v1",Ne=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,U=/^[0-9a-f]{64}$/u,ge=/^sha256:[0-9a-f]{64}$/u,De=/^[1-9A-HJ-NP-Za-km-z]+$/u,je=131072,ke=["accountFingerprint","accountIndex","accountLabel","accountPeerId","accountXpub","identityScheme","keys","schemaVersion","seedProfile"],Be=["bip32Fingerprint","curve","derivation","encoding","identityScheme","keyId","path","publicKeyHex","purpose","seedProfile","signatureProfile"],$e=["connectionExpiresAt","event","identity","schemaVersion"];function u(r){throw new TypeError(r)}function ee(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}function v(r,e){typeof r!="string"&&u(`${e} must be a string`);for(let t=0;t<r.length;t+=1){const s=r.charCodeAt(t);let i=s;if(s>=55296&&s<=56319){const o=r.charCodeAt(t+1);o>=56320&&o<=57343||u(`${e} contains an unpaired surrogate`),i=65536+(s-55296<<10)+(o-56320),t+=1}else s>=56320&&s<=57343&&u(`${e} contains an unpaired surrogate`);((i&65535)===65534||(i&65535)===65535||i>=64976&&i<=65007)&&u(`${e} contains a Unicode noncharacter`)}return r}function Ue(r){typeof r!="string"&&u("wire JSON must be a string"),k.encode(r).byteLength>je&&u("wire JSON is too large"),r.charCodeAt(0)===65279&&u("wire JSON must not contain a BOM");let e=0,t=0;const s=()=>{for(;e<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[e]);)e+=1},i=()=>{r[e]!=='"'&&u("invalid JSON string");const a=e;for(e+=1;e<r.length;){const l=r.charCodeAt(e);if(l===34){e+=1;let f;try{f=JSON.parse(r.slice(a,e))}catch{u("invalid JSON string")}return v(f,"JSON string")}l<32&&u("invalid JSON control character"),l===92&&(e+=1,e>=r.length&&u("unterminated JSON escape")),e+=1}u("unterminated JSON string")},o=(a=0)=>{a>32&&u("wire JSON nesting is too deep"),t+=1,t>4096&&u("wire JSON contains too many values"),s();const l=r[e];if(l==='"')return i();if(l==="{"){e+=1;const d=Object.create(null),y=new Set;if(s(),r[e]==="}")return e+=1,d;for(;e<r.length;){s();const m=i();if(y.has(m)&&u(`duplicate JSON field: ${m}`),y.add(m),s(),r[e]!==":"&&u("missing JSON object colon"),e+=1,d[m]=o(a+1),s(),r[e]==="}")return e+=1,d;r[e]!==","&&u("invalid JSON object separator"),e+=1}u("unterminated JSON object")}if(l==="["){e+=1;const d=[];if(s(),r[e]==="]")return e+=1,d;for(;e<r.length;){if(d.push(o(a+1)),s(),r[e]==="]")return e+=1,d;r[e]!==","&&u("invalid JSON array separator"),e+=1}u("unterminated JSON array")}for(const[d,y]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(d,e))return e+=d.length,y;const f=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(e));f||u("invalid JSON value"),e+=f[0].length;const h=Number(f[0]);return Number.isFinite(h)||u("wire JSON number must be finite"),h};s();const n=o();return s(),e!==r.length&&u("wire JSON contains trailing bytes"),n}function Me(r){return typeof r=="string"?Ue(r):r}function Ve(r,e){if(r.byteLength!==e.byteLength)return!1;let t=0;for(let s=0;s<r.byteLength;s+=1)t|=r[s]^e[s];return t===0}function R(r,e,t){const s=Me(r);ee(s)||u(`${t} must be a JSON object`),Object.getOwnPropertySymbols(s).length!==0&&u(`${t} has an unknown symbol field`);const i=Object.getOwnPropertyNames(s).sort(),o=[...e].sort(),n=k.encode(i.join("\0")),a=k.encode(o.join("\0"));Ve(n,a)||u(`${t} has missing or unknown fields`);for(const l of i){const f=Object.getOwnPropertyDescriptor(s,l);(!f||!f.enumerable||!("value"in f))&&u(`${t}.${l} must be an enumerable data field`),f.value===void 0&&u(`${t}.${l} must not be undefined`)}return s}function L(r){if(!r||typeof r!="object"||Object.isFrozen(r))return r;for(const e of Object.values(r))L(e);return Object.freeze(r)}function b(r){return L(Object.fromEntries([...r].sort(([e],[t])=>e<t?-1:e>t?1:0)))}function x(r,e,t){(!Array.isArray(r)||Object.getPrototypeOf(r)!==Array.prototype||r.length!==e)&&u(`${t} must be a plain array with exactly ${e} values`);const s=[...Array.from({length:e},(o,n)=>String(n)),"length"],i=Reflect.ownKeys(r);(i.length!==s.length||i.some((o,n)=>o!==s[n]))&&u(`${t} must be a dense plain array`);for(let o=0;o<e;o+=1){const n=Object.getOwnPropertyDescriptor(r,String(o));(!n||!n.enumerable||!("value"in n)||n.value===void 0)&&u(`${t} must contain enumerable data values`)}}function Ye(r){const e=R(r,["reviewedTransform","schemaVersion"],"asset review protocol policy");p(e.schemaVersion,1,"asset review protocol schemaVersion");const t=R(e.reviewedTransform,["metersPerSourceUnit","quaternionNormTolerance","scaleComponentExclusiveMin","scaleComponentInclusiveMax","translationComponentAbsMax","upAxes"],"asset review transform policy"),s=R(t.metersPerSourceUnit,["cm","km","m","mm"],"asset review unit policy");for(const[i,o]of Object.entries(s))(typeof o!="number"||!Number.isFinite(o)||o<=0)&&u(`asset review unit policy ${i} must be positive and finite`);for(const[i,o]of[["quaternionNormTolerance",t.quaternionNormTolerance],["scaleComponentExclusiveMin",t.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",t.scaleComponentInclusiveMax],["translationComponentAbsMax",t.translationComponentAbsMax]])(typeof o!="number"||!Number.isFinite(o))&&u(`asset review transform policy ${i} must be finite`);return(t.quaternionNormTolerance<=0||t.scaleComponentInclusiveMax<=t.scaleComponentExclusiveMin||t.translationComponentAbsMax<=0)&&u("asset review transform policy bounds are inconsistent"),x(t.upAxes,3,"asset review up-axis policy"),t.upAxes.join("\0")!=="X_UP\0Y_UP\0Z_UP"&&u("asset review up-axis policy is invalid"),b([["metersPerSourceUnit",b(Object.entries(s))],["quaternionNormTolerance",t.quaternionNormTolerance],["scaleComponentExclusiveMin",t.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",t.scaleComponentInclusiveMax],["translationComponentAbsMax",t.translationComponentAbsMax],["upAxes",Object.freeze(Array.from({length:3},(i,o)=>t.upAxes[o]))]])}Ye(Pe);function p(r,e,t){return r!==e&&u(`${t} must equal ${JSON.stringify(e)}`),r}function Fe(r,e,t){return e.includes(r)||u(`${t} is not an allowed value`),r}function T(r,e,t){return v(r,t),e.test(r)||u(`${t} has an invalid encoding`),r}function Ke(r,e){return v(r,e),(!Ne.test(r)||new Date(r).toISOString()!==r)&&u(`${e} must be exact RFC3339 milliseconds UTC`),r}function qe(r,e){const t=R(r,Be,`identity key ${e.purpose}`);return p(t.purpose,e.purpose,"key purpose"),p(t.identityScheme,B,"key identityScheme"),p(t.seedProfile,$,"key seedProfile"),p(t.signatureProfile,e.signatureProfile,"key signatureProfile"),p(t.curve,e.curve,"key curve"),p(t.derivation,"slip10","key derivation"),p(t.path,e.path,"key path"),p(t.encoding,"raw","key encoding"),T(t.publicKeyHex,U,"key publicKeyHex"),p(t.bip32Fingerprint,null,"key bip32Fingerprint"),T(t.keyId,ge,"key keyId"),b([["bip32Fingerprint",null],["curve",t.curve],["derivation","slip10"],["encoding","raw"],["identityScheme",B],["keyId",t.keyId],["path",t.path],["publicKeyHex",t.publicKeyHex],["purpose",t.purpose],["seedProfile",$],["signatureProfile",t.signatureProfile]])}function ze(r){const e=R(r,ke,"WalletPublicIdentity");p(e.schemaVersion,1,"identity schemaVersion"),p(e.identityScheme,B,"identity identityScheme"),p(e.seedProfile,$,"identity seedProfile"),e.accountIndex!==0&&u("public wallet identity must use account 0"),p(e.accountLabel,null,"identity accountLabel"),v(e.accountXpub,"identity accountXpub"),/^xpub[1-9A-HJ-NP-Za-km-z]{107}$/u.test(e.accountXpub)||u("identity accountXpub is invalid"),v(e.accountPeerId,"identity accountPeerId"),(!e.accountPeerId.startsWith("16Uiu2H")||e.accountPeerId.length<40||e.accountPeerId.length>64||!De.test(e.accountPeerId))&&u("identity accountPeerId is invalid"),T(e.accountFingerprint,/^[0-9a-f]{8}$/u,"identity accountFingerprint"),x(e.keys,3,"public identity keys array");const t=[{purpose:"asset-review-approval",curve:"ed25519",signatureProfile:G,path:"m/44'/0'/0'/2'/0'"},{purpose:"contact-encryption",curve:"x25519",signatureProfile:null,path:"m/44'/0'/0'/1'/0'"},{purpose:"sdn-authentication",curve:"ed25519",signatureProfile:G,path:"m/44'/0'/0'/0'/0'"}],s=Array.from({length:3},(i,o)=>qe(e.keys[o],t[o]));return b([["accountFingerprint",e.accountFingerprint],["accountIndex",0],["accountLabel",null],["accountPeerId",e.accountPeerId],["accountXpub",e.accountXpub],["identityScheme",B],["keys",L(s)],["schemaVersion",1],["seedProfile",$]])}function te(r,e){const t=R(r,$e,`${e} result`);p(t.schemaVersion,1,"connection result schemaVersion"),Fe(t.event,["connected","disconnected"],"connection event"),e==="connect"&&t.event!=="connected"&&u("connect result must be connected");let s=null,i=null;return t.event==="connected"?(s=ze(t.identity),i=Ke(t.connectionExpiresAt,"connectionExpiresAt")):(t.identity!==null||t.connectionExpiresAt!==null)&&u("disconnected result must clear identity and expiry"),b([["connectionExpiresAt",i],["event",t.event],["identity",s],["schemaVersion",1]])}function re(r,e){return R(r,[],e),L({})}function He(r={}){return re(r,"wallet connect request")}function Je(r){return te(r,"connect")}function We(r={}){return re(r,"wallet account request")}function Xe(r){return te(r,"account")}const E=Object.freeze({envelopeBytes:512,fieldBytes:4096,batchBytes:12288,fields:16,contextBytes:256}),Qe=/^sdn-field-encryption\/v1\|[A-Za-z0-9_.-]{1,64}\|[A-Za-z0-9_.-]{1,64}\|[A-Za-z0-9_.-]{1,64}\|k[1-9][0-9]{0,8}$/u,se=["ciphertextBase64url","context","encBase64url","fieldId"],Ze=["fields","protocolVersion","replyPublicKeyHex"],ie=["context","encBase64url","kmfBase64url","protocolVersion","replyPublicKeyHex"],Ge=["fields","replyEphemeralPublicKeyHex","schemaVersion"],et=/^[A-Za-z0-9_-]*$/u;function M(r,e){return(!ArrayBuffer.isView(r)||!(r instanceof Uint8Array)||Object.getPrototypeOf(r)!==Uint8Array.prototype)&&u(`${e} must be a plain Uint8Array`),Uint8Array.from(r)}function C(r){let e="";for(let t=0;t<r.length;t+=1)e+=String.fromCharCode(r[t]);return globalThis.btoa(e).replace(/\+/gu,"-").replace(/\//gu,"_").replace(/=+$/gu,"")}function I(r,e,t,s){v(r,s),(!et.test(r)||r.length%4===1||r.length>Math.ceil(t*4/3))&&u(`${s} must be canonical unpadded base64url`);let i;try{i=globalThis.atob(r.replace(/-/gu,"+").replace(/_/gu,"/").padEnd(Math.ceil(r.length/4)*4,"="))}catch{u(`${s} must be valid base64url`)}const o=Uint8Array.from(i,n=>n.charCodeAt(0));return(o.length<e||o.length>t||C(o)!==r)&&u(`${s} must canonically encode ${e}..${t} bytes`),o}function H(r,e){return v(r,e),(k.encode(r).byteLength>E.contextBytes||!Qe.test(r))&&u(`${e} must be sdn-field-encryption/v1|<site>|<schema>|<field>|k<version>`),r}function tt(r){return H(r,"context").split("|")[1]}function ne(r){const e=R(r,Ze,"field-open request");p(e.protocolVersion,1,"field-open protocolVersion"),T(e.replyPublicKeyHex,U,"replyPublicKeyHex"),(!Array.isArray(e.fields)||e.fields.length<1||e.fields.length>E.fields)&&u(`field-open request carries 1..${E.fields} fields`),x(e.fields,e.fields.length,"field-open fields");let t=0;const s=e.fields.map((i,o)=>{const n=R(i,se,`field ${o}`);return I(n.encBase64url,1,E.envelopeBytes,`field ${o} encBase64url`),t+=I(n.ciphertextBase64url,1,E.fieldBytes,`field ${o} ciphertextBase64url`).length,H(n.context,`field ${o} context`),(!Number.isInteger(n.fieldId)||n.fieldId<0||n.fieldId>65535)&&u(`field ${o} fieldId must be 0..65535`),b(se.map(a=>[a,n[a]]))});return t>E.batchBytes&&u(`field-open ciphertext exceeds ${E.batchBytes} bytes`),b([["fields",L(s)],["protocolVersion",1],["replyPublicKeyHex",e.replyPublicKeyHex]])}function oe(r){const e=R(r,ie,"key-unwrap request");return p(e.protocolVersion,1,"key-unwrap protocolVersion"),T(e.replyPublicKeyHex,U,"replyPublicKeyHex"),H(e.context,"key-unwrap context"),I(e.encBase64url,1,E.envelopeBytes,"key-unwrap encBase64url"),I(e.kmfBase64url,1,E.envelopeBytes,"key-unwrap kmfBase64url"),b(ie.map(t=>[t,e[t]]))}function ce(r,e){const t=R(r,Ge,"field result");p(t.schemaVersion,1,"field result schemaVersion"),T(t.replyEphemeralPublicKeyHex,U,"replyEphemeralPublicKeyHex"),(!Array.isArray(t.fields)||t.fields.length<1||t.fields.length>e)&&u(`field result carries 1..${e} fields`),x(t.fields,t.fields.length,"field result fields");const s=t.fields.map((i,o)=>{if((ee(i)?i.status:void 0)==="opened"){const l=R(i,["ciphertextBase64url","status"],`field result ${o}`);return I(l.ciphertextBase64url,1,E.fieldBytes,`field result ${o} ciphertext`),b([["ciphertextBase64url",l.ciphertextBase64url],["status","opened"]])}const a=R(i,["reason","status"],`field result ${o}`);return p(a.status,"refused",`field result ${o} status`),p(a.reason,"NOT_ADDRESSED_TO_ACCOUNT",`field result ${o} reason`),b([["reason","NOT_ADDRESSED_TO_ACCOUNT"],["status","refused"]])});return b([["fields",L(s)],["replyEphemeralPublicKeyHex",t.replyEphemeralPublicKeyHex],["schemaVersion",1]])}function rt(r,e="0".repeat(64)){const t=R(r,["fields"],"openFields input");return Array.isArray(t.fields)||u("openFields fields must be an array"),x(t.fields,t.fields.length,"openFields fields"),ne({fields:t.fields.map((s,i)=>{const o=R(s,["ciphertext","context","enc","fieldId"],`openFields field ${i}`);return{ciphertextBase64url:C(M(o.ciphertext,`field ${i} ciphertext`)),context:o.context,encBase64url:C(M(o.enc,`field ${i} enc`)),fieldId:o.fieldId}}),protocolVersion:1,replyPublicKeyHex:e})}function st(r){return ne(r)}function it(r){return ce(r,E.fields)}function nt(r,e="0".repeat(64)){const t=R(r,["context","enc","kmf"],"unwrapKey input");return oe({context:t.context,encBase64url:C(M(t.enc,"enc")),kmfBase64url:C(M(t.kmf,"kmf")),protocolVersion:1,replyPublicKeyHex:e})}function ot(r){return oe(r)}function ct(r){return ce(r,1)}const at=new TextEncoder().encode("sdn-wallet-reply/v1"),lt=new TextEncoder().encode("flatbuffers-field"),ut=new TextEncoder().encode("flatbuffers-iv");function ft(r){return Array.from(r,e=>e.toString(16).padStart(2,"0")).join("")}function ht(r){return Uint8Array.from(r.match(/../gu),e=>Number.parseInt(e,16))}function ae(r,e){const t=new Uint8Array(r.length+6);return t.set(r),t[r.length]=e>>8,t[r.length+1]=e&255,t}async function J(r,e,t,s){const i=await r.importKey("raw",e,"HKDF",!1,["deriveBits"]);return new Uint8Array(await r.deriveBits({hash:"SHA-256",info:t,name:"HKDF",salt:new Uint8Array(0)},i,s))}async function dt(r){const e=r?.subtle;if(!e)throw new Error("Web Crypto is unavailable");const t=await e.generateKey({name:"X25519"},!1,["deriveBits"]),s=new Uint8Array(await e.exportKey("raw",t.publicKey));if(s.length!==32)throw new Error("X25519 public key is not 32 bytes");let i=t.privateKey;return Object.freeze({publicKeyHex:ft(s),async open(o,n){if(!i)throw new Error("reply key already used");const a=i;i=null;const l=await e.importKey("raw",ht(o),{name:"X25519"},!1,[]),f=new Uint8Array(await e.deriveBits({name:"X25519",public:l},a,256)),h=await J(e,f,at,256);f.fill(0);try{return await Promise.all(n.map(async(d,y)=>{if(d===null)return null;const m=await J(e,h,ae(lt,y),256),w=await J(e,h,ae(ut,y),128),Q=await e.importKey("raw",m,"AES-CTR",!1,["decrypt"]);return m.fill(0),new Uint8Array(await e.decrypt({counter:w,length:128,name:"AES-CTR"},Q,d))}))}finally{h.fill(0)}}})}const P="https://wallet.spacedatanetwork.org",V="sdn.wallet.callback.v1:",N=/^[0-9a-f]{64}$/u,le=/^[A-Za-z0-9_-]{43}$/u,yt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,pt=250,mt=3e4,Rt=3e5,Et=9e5,bt=12e4,At=8,ue=4096,fe=70*1024,wt=64,he=Object.freeze({CALLBACK_ERROR:"The wallet return could not be verified. Try again.",CRYPTO_UNAVAILABLE:"Secure browser cryptography is unavailable.",DESTROYED:"This wallet client has been destroyed.",DISCONNECTED:"The wallet was disconnected.",EXPIRED:"The wallet connection expired.",INVALID_CLIENT:"This wallet client is not registered.",INVALID_REQUEST:"The wallet request is invalid.",NOT_ADDRESSED_TO_ACCOUNT:"This data is not sealed to your wallet.",RELAY_ERROR:"The wallet service could not complete the request. Try again.",REPLACED:"A newer wallet request replaced this one.",WALLET_NOT_COMPLETED:"The wallet did not complete. Check popup settings and try again."}),de=new TextEncoder,Ot=new TextDecoder("utf-8",{fatal:!0});class g extends Error{constructor(e){super(he[e]),this.name="WalletClientError",Object.defineProperty(this,"code",{configurable:!1,enumerable:!0,value:e,writable:!1})}}function c(r){return Object.hasOwn(he,r)?new g(r):new g("RELAY_ERROR")}function _t(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const e=Object.getPrototypeOf(r);return e===Object.prototype||e===null}function Y(r,e){if(typeof r!="string"||r.length>e||de.encode(r).byteLength>e||r.charCodeAt(0)===65279)throw c("RELAY_ERROR");let t=0,s=0;const i=()=>{for(;t<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[t]);)t+=1},o=()=>{if(r[t]!=='"')throw c("RELAY_ERROR");const l=t;for(t+=1;t<r.length;){const f=r.charCodeAt(t);if(f===34){t+=1;let h;try{h=JSON.parse(r.slice(l,t))}catch{throw c("RELAY_ERROR")}for(let d=0;d<h.length;d+=1){const y=h.charCodeAt(d);if(y>=55296&&y<=56319){const m=h.charCodeAt(d+1);if(!(m>=56320&&m<=57343))throw c("RELAY_ERROR");d+=1}else if(y>=56320&&y<=57343)throw c("RELAY_ERROR")}return h}if(f<32||f===92&&(t+=1,t>=r.length))throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")},n=(l=0)=>{if(l>32||++s>4096)throw c("RELAY_ERROR");i();const f=r[t];if(f==='"')return o();if(f==="{"){t+=1;const y=Object.create(null),m=new Set;if(i(),r[t]==="}")return t+=1,y;for(;t<r.length;){i();const w=o();if(m.has(w)||(m.add(w),i(),r[t]!==":"))throw c("RELAY_ERROR");if(t+=1,y[w]=n(l+1),i(),r[t]==="}")return t+=1,y;if(r[t]!==",")throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")}if(f==="["){t+=1;const y=[];if(i(),r[t]==="]")return t+=1,y;for(;t<r.length;){if(y.push(n(l+1)),i(),r[t]==="]")return t+=1,y;if(r[t]!==",")throw c("RELAY_ERROR");t+=1}throw c("RELAY_ERROR")}for(const[y,m]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(y,t))return t+=y.length,m;const h=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(t));if(!h)throw c("RELAY_ERROR");t+=h[0].length;const d=Number(h[0]);if(!Number.isFinite(d))throw c("RELAY_ERROR");return d};i();const a=n();if(i(),t!==r.length)throw c("RELAY_ERROR");return a}function F(r,e,t="RELAY_ERROR"){if(!_t(r)||Object.getOwnPropertySymbols(r).length!==0)throw c(t);const s=Object.getOwnPropertyNames(r).sort(),i=[...e].sort();if(s.length!==i.length||s.some((o,n)=>o!==i[n]))throw c(t);for(const o of s){const n=Object.getOwnPropertyDescriptor(r,o);if(!n?.enumerable||!("value"in n)||n.value===void 0)throw c(t)}return r}function K(r,e="RELAY_ERROR"){if(typeof r!="string"||!yt.test(r))throw c(e);const t=Date.parse(r);if(!Number.isFinite(t)||new Date(t).toISOString()!==r)throw c(e);return t}function _(r){return Array.isArray(r)?Object.freeze(r.map(_)):r&&typeof r=="object"?Object.freeze(Object.fromEntries(Object.entries(r).map(([e,t])=>[e,_(t)]))):r}function ye(r){const e={identity:r.identity===null?null:_(r.identity),status:r.status};return r.connectionExpiresAt!==void 0&&(e.connectionExpiresAt=r.connectionExpiresAt),r.error!==void 0&&(e.error=_(r.error)),_(e)}function D(r){return Object.freeze({code:r.code,message:r.message})}function pe(r){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";let t=0,s=0,i="";for(const o of r)for(t=t<<8|o,s+=8;s>=6;)s-=6,i+=e[t>>>s&63],t&=(1<<s)-1;return s!==0&&(i+=e[t<<6-s&63]),i}function me(r){let e="";for(const t of r)e+=t.toString(16).padStart(2,"0");return e}function W(r,e){const t=new Uint8Array(32);return Reflect.apply(e,r,[t]),t}function vt(r){const e=r?.headers?.get?.("content-type");return typeof e=="string"&&/^application\/json(?:\s*;\s*charset=utf-8)?$/iu.test(e.trim())}function X(r){try{Promise.resolve(r).catch(()=>{})}catch{}}function j(r){try{const e=r?.body,t=e?.cancel;typeof t=="function"&&X(Reflect.apply(t,e,[]))}catch{}}function Re(r){try{const e=r?.cancel;typeof e=="function"&&X(Reflect.apply(e,r,[]))}catch{}}function Lt(r){try{const e=r?.releaseLock;typeof e=="function"&&Reflect.apply(e,r,[])}catch{}}function S(r,e,t=null){try{r.abort()}catch{}t&&Re(t),j(e)}function q(r,e,t=null){let s;try{s=Promise.resolve(r)}catch(i){return Promise.reject(i)}return new Promise((i,o)=>{let n=!1;const a=()=>{try{e.removeEventListener("abort",f)}catch{}},l=(h,d)=>n?!1:(n=!0,a(),h(d),!0),f=()=>{l(o,c("RELAY_ERROR"))};try{e.addEventListener("abort",f,{once:!0}),e.aborted&&f()}catch{f()}s.then(h=>{if(n){try{t?.(h)}catch{}return}l(i,h)},h=>{n||l(o,h)})})}async function Ee(r,e,t){let s=null;const i=[];let o=0;try{if(!vt(r)||typeof r?.body?.getReader!="function")throw c("RELAY_ERROR");for(s=r.body.getReader();;){const l=s.read(),{done:f,value:h}=await q(l,t.signal);if(f)break;if(!(h instanceof Uint8Array)||(o+=h.byteLength,o>e))throw c("RELAY_ERROR");i.push(h)}const n=new Uint8Array(o);let a=0;for(const l of i)n.set(l,a),a+=l.byteLength;return Ot.decode(n)}catch{try{t.abort()}catch{}throw s&&Re(s),c("RELAY_ERROR")}finally{s&&Lt(s)}}function z(r,e){const t={body:JSON.stringify(r),cache:"no-store",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"error",referrerPolicy:"no-referrer"};return e!==void 0&&(t.signal=e),t}function Tt(r,e,t){let s;try{s=Y(r,2048),F(s,["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR")}catch{throw c("CALLBACK_ERROR")}if(s.schemaVersion!==1||s.state!==e||!N.test(s.code))throw c("CALLBACK_ERROR");const i=K(s.expiresAt,"CALLBACK_ERROR");if(i<=t||i-t>bt)throw c("CALLBACK_ERROR");return{code:s.code,expiresAt:i,state:s.state}}function It(){let r;return{promise:new Promise(t=>{r=t}),resolve:r}}function be(){let r,e;return{promise:new Promise((s,i)=>{r=i,e=s}),reject:r,resolve:e}}function St(){const r=globalThis.window;return Object.freeze({AbortController:globalThis.AbortController,clearInterval:globalThis.clearInterval.bind(globalThis),clearTimeout:globalThis.clearTimeout.bind(globalThis),crypto:globalThis.crypto,fetch:typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0,getStorage:()=>{try{return r?.localStorage??null}catch{return null}},now:()=>Date.now(),setInterval:globalThis.setInterval.bind(globalThis),setTimeout:globalThis.setTimeout.bind(globalThis),window:r})}class xt{#k;#B;#x=!1;#l=!1;#$=!1;#n=null;#O=null;#b=new Set;#e;#_=null;#r=!1;#m=0;#v=0;#L=new Set;#C=[];#o=null;#P=!1;#y=new Set;#U=Object.freeze({identity:null,status:"dormant"});#u=null;#T=null;#A=null;#R=new Set;#p;constructor({adapters:e,clientId:t,dependencies:s}){this.#k=e,this.#B=t,this.#e=s??St(),this.#p=this.#e.window}getSnapshot(){return this.#Y(),ye(this.#U)}subscribe(e){if(typeof e!="function")throw c("INVALID_REQUEST");if(this.#r)throw c("DESTROYED");this.#L.add(e);try{e(this.getSnapshot())}catch{}let t=!0;return()=>{t&&(t=!1,this.#L.delete(e))}}execute(e,t){if(this.#r)return Promise.reject(c("DESTROYED"));const s=this.#m,i=this.#k[e];if(!i)return Promise.reject(c("INVALID_REQUEST"));let o;try{o=i.buildRequest(t)}catch{const A=this.#t(s);return A?Promise.reject(A):Promise.reject(c("INVALID_REQUEST"))}let n=this.#t(s);if(n)return Promise.reject(n);if(this.#x)return this.#l=!0,Promise.reject(c("REPLACED"));const a=++this.#m;if(this.#Q(),n=this.#t(a),n)return Promise.reject(n);if(this.#l)return Promise.reject(c("CALLBACK_ERROR"));if(this.#Y(),n=this.#t(a),n)return Promise.reject(n);const l=this.#i();if(n=this.#t(a),n)return Promise.reject(n);const f=this.#n&&this.#n.expiresAtMs>l?this.#n:null;if(n=this.#t(a),n)return Promise.reject(n);const h=this.#o;let d,y,m;try{const A=this.#e.crypto,O=A?.getRandomValues,Bt=A?.subtle?.digest,Se=this.#p?.open;if(n=this.#t(a),n)throw n;if(typeof O!="function"||typeof Bt!="function"||typeof Se!="function")throw c("CRYPTO_UNAVAILABLE");if(d=me(W(A,O)),n=this.#t(a),n||(y=me(W(A,O)),n=this.#t(a),n)||(m=pe(W(A,O)),n=this.#t(a),n))throw n;if(!N.test(d)||!N.test(y)||!le.test(m))throw c("CRYPTO_UNAVAILABLE");if(Reflect.apply(Se,this.#p,[`${P}/transaction/${d}`,"_blank","noopener"]),n=this.#t(a),n)throw n}catch(A){if(n=this.#t(a),n)return Promise.reject(n);let O;try{O=A instanceof g?A:c("CRYPTO_UNAVAILABLE")}catch{O=c("CRYPTO_UNAVAILABLE")}return h&&(this.#I(h,"REPLACED",!1),n=this.#t(a),n)?Promise.reject(n):(this.#M(null,O,f,i.kind),Promise.reject(O))}if(h&&(this.#I(h,"REPLACED",!1),n=this.#t(a),n))return Promise.reject(n);const w=be(),Q=It(),Ie={active:!0,adapter:i,callbackBusy:!1,challenge:null,cleanup:Q,cleanupFinished:!1,cleanupStarted:!1,controllers:new Set,expiryTimer:null,generation:++this.#v,operationTimer:null,phase:"hashing",pollTimer:null,priorConnection:f,promise:w.promise,registrationDeadlineMs:l+mt,registrationOutcome:"none",reject:w.reject,openResult:null,request:o,resolve:w.resolve,retryResolve:null,retryTimer:null,state:y,transactionExpiresAtMs:null,transactionId:d,verifier:m};return this.#o=Ie,this.#s({...f?{connectionExpiresAt:f.expiresAt,identity:f.identity}:{identity:null},status:"opening"}),this.#q(Ie),w.promise}async disconnect(){if(this.#r)throw c("DESTROYED");const e=++this.#m;this.#h();const t=this.#o;let s=Promise.resolve();t&&(s=this.#I(t,"DISCONNECTED",!1));let i=this.#t(e);if(i)throw await s,i;if(this.#s({identity:null,status:"dormant"}),await s,i=this.#t(e),i)throw i}destroy(){if(this.#_)return this.#_;const e=be();this.#_=e.promise,this.#m+=1;try{this.#K(),e.resolve()}catch{e.reject(c("RELAY_ERROR"))}return this.#_}#K(){this.#r=!0,this.#v+=1,this.#h();const e=[],t=this.#o;t&&(t.active=!1,this.#o=null,this.#S(t),t.reject(c("DESTROYED")),t.challenge&&t.verifier&&e.push(t));for(const s of this.#y)s.challenge&&s.verifier&&e.push(s);for(const s of this.#b)s.abort();this.#b.clear();for(const s of this.#R)this.#e.clearTimeout(s),this.#e.clearInterval(s);if(this.#R.clear(),this.#A)try{this.#A()}catch{}this.#T=null,this.#A=null,this.#u=null,this.#L.clear();for(const s of e)this.#X(s);t&&this.#a(t);for(const s of[...this.#y])this.#a(s);this.#s({error:D(c("DESTROYED")),identity:null,status:"error"})}async#q(e){if(!(!this.#c(e)||e.cleanupFinished))try{if(e.operationTimer=this.#w(()=>{if(!e.cleanupFinished){if(e.phase==="hashing"){this.#c(e)&&this.#f(e,"CRYPTO_UNAVAILABLE",!1);return}if(e.phase==="registering")for(const a of e.controllers)a.abort()}},Math.max(0,e.registrationDeadlineMs-this.#i())),typeof e.adapter.seal=="function"){const a=await e.adapter.seal(e.request,this.#e.crypto);e.request=a.request,e.openResult=a.open}const t=await this.#e.crypto.subtle.digest("SHA-256",de.encode(e.verifier)),s=pe(new Uint8Array(t));if(!le.test(s))throw c("CRYPTO_UNAVAILABLE");if(!this.#c(e)){e.registrationOutcome="not-started",this.#a(e);return}e.challenge=s,e.phase="registering";const i=this.#g(e);let o,n=null;try{try{const l=this.#e.fetch(`${P}/relay/v1/transactions`,z({clientId:this.#B,codeChallenge:e.challenge,codeChallengeMethod:"S256",operation:e.adapter.operation,request:e.request,schemaVersion:1,state:e.state,transactionId:e.transactionId},i.signal));n=await q(l,i.signal,j)}catch{e.registrationOutcome="ambiguous",e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}e.registrationOutcome="ambiguous";let a;try{a=n.status}catch{S(i,n),e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}if(a!==201){e.registrationOutcome="definitive-failure",S(i,n),e.active?this.#f(e,"RELAY_ERROR",!1):this.#a(e);return}try{const l=await Ee(n,ue,i),f=F(Y(l,ue),["expiresAt","schemaVersion","transactionId"]);if(f.schemaVersion!==1||f.transactionId!==e.transactionId)throw c("RELAY_ERROR");o=K(f.expiresAt);const h=this.#i();if(o<=h||o-h>Rt)throw c("RELAY_ERROR")}catch{e.registrationOutcome="ambiguous",S(i,n),e.active?this.#f(e,"RELAY_ERROR"):this.#E(e);return}}finally{try{i.abort()}catch{}this.#D(e,i),this.#d(e.operationTimer),e.operationTimer=null}if(e.transactionExpiresAtMs=o,e.registrationOutcome="registered",!this.#c(e)){this.#E(e);return}e.phase="waiting-callback",e.expiryTimer=this.#w(()=>{this.#c(e)&&this.#f(e,"WALLET_NOT_COMPLETED")},Math.max(0,e.transactionExpiresAtMs-this.#i())),e.pollTimer=this.#W(()=>{this.#N(e,!1)},pt),await this.#N(e,!1)}catch(t){if(!e.active){e.registrationOutcome==="ambiguous"||e.registrationOutcome==="registered"?this.#E(e):this.#a(e);return}const s=t instanceof g?t.code:e.phase==="hashing"?"CRYPTO_UNAVAILABLE":"RELAY_ERROR";this.#f(e,s,e.registrationOutcome!=="none")}}async#N(e,t){if(!this.#c(e)||e.phase!=="waiting-callback"||e.callbackBusy||!this.#u)return;const s=`${V}${e.state}`;let i;try{i=this.#u.getItem(s)}catch{t&&this.#f(e,"CALLBACK_ERROR");return}if(i===null)return;e.callbackBusy=!0;let o;try{o=Tt(i,e.state,this.#i()),this.#u.removeItem(s)}catch{try{this.#u.removeItem(s)}catch{}this.#f(e,"CALLBACK_ERROR");return}if(!this.#c(e))return;e.phase="redeeming",this.#d(e.pollTimer,!0),e.pollTimer=null;const n=this.#g(e);let a=null;try{const l=this.#e.fetch(`${P}/relay/v1/codes/redeem`,z({code:o.code,codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId},n.signal));if(a=await q(l,n.signal,j),a.status!==200)throw c("RELAY_ERROR");const f=await Ee(a,fe,n),h=F(Y(f,fe),["result","schemaVersion","transactionId"]);if(h.schemaVersion!==1||h.transactionId!==e.transactionId)throw c("RELAY_ERROR");let d;try{d=e.adapter.parseResult(h.result)}catch{throw c("RELAY_ERROR")}if(e.openResult&&(d=await e.openResult(d)),!this.#c(e))return;this.#z(e,d)}catch(l){if(a&&S(n,a),!this.#c(e))return;const f=l instanceof g?l.code:"RELAY_ERROR";this.#f(e,f)}finally{try{n.abort()}catch{}this.#D(e,n)}}#z(e,t){if(!this.#c(e))return;let s=null;(e.adapter.kind==="connect"||e.adapter.kind==="account"&&t.event==="connected")&&(s=this.#H(t)),e.active=!1,this.#o=null,this.#S(e);let i=t;e.adapter.kind==="connect"?(this.#V(s),i=_(t.identity)):e.adapter.kind==="account"?(t.event==="connected"?this.#V(s):(this.#h(),this.#s({identity:null,status:"dormant"})),i=void 0):this.#J(e,void 0),e.resolve(i),this.#a(e)}#f(e,t,s=!0){this.#c(e)&&this.#I(e,t,!0,s)}#I(e,t,s,i=!0){if(!e.active)return e.cleanup.promise;const o=this.#m;e.active=!1,this.#o===e&&(this.#o=null),this.#v+=1,this.#S(e);for(const l of e.controllers)e.phase!=="registering"&&l.abort();const n=this.#t(o),a=n??c(t);return e.reject(a),s&&!n&&this.#M(e,a,e.priorConnection,e.adapter.kind),this.#r?(e.challenge&&e.verifier&&this.#F(e),this.#a(e),e.cleanup.promise):(!i||e.registrationOutcome==="definitive-failure"||e.registrationOutcome==="not-started"?this.#a(e):e.phase==="hashing"?(e.registrationOutcome="not-started",this.#a(e)):e.phase==="registering"&&e.registrationOutcome==="none"?this.#j(e):(this.#j(e),this.#E(e)),e.cleanup.promise)}#M(e,t,s,i){if(s?.expiresAtMs>this.#i()){this.#n=s,this.#s({connectionExpiresAt:s.expiresAt,error:D(t),identity:s.identity,status:"connected"});return}this.#h(),this.#s({error:D(t),identity:null,status:"error"})}#H(e){const t=K(e.connectionExpiresAt),s=this.#i();if(t<=s||t-s>Et)throw c("RELAY_ERROR");return{expiresAt:e.connectionExpiresAt,expiresAtMs:t,identity:_(e.identity)}}#V(e){const t=this.#i();this.#h(),this.#n=e;const s=this.#n;this.#O=this.#w(()=>{this.#n===s&&(this.#n=null,this.#O=null,this.#o?this.#s({identity:null,status:"opening"}):this.#s({identity:null,status:"dormant"}))},Math.max(0,e.expiresAtMs-t)),this.#s({connectionExpiresAt:e.expiresAt,identity:this.#n.identity,status:"connected"})}#J(e,t){const s=e.priorConnection;s?.expiresAtMs>this.#i()?(this.#n=s,this.#s({connectionExpiresAt:s.expiresAt,...t?{error:D(t)}:{},identity:s.identity,status:"connected"})):t?(this.#h(),this.#s({error:D(t),identity:null,status:"error"})):(this.#h(),this.#s({identity:null,status:"dormant"}))}#Y(){!this.#n||this.#n.expiresAtMs>this.#i()||(this.#h(),this.#o?this.#s({identity:null,status:"opening"}):this.#s({identity:null,status:"dormant"}))}#h(){this.#n=null,this.#d(this.#O),this.#O=null}#s(e){const t=_(e);if(this.#U=t,this.#C.push(t),!this.#P){this.#P=!0;try{for(;this.#C.length!==0;){const s=this.#C.shift();for(const i of[...this.#L])try{i(ye(s))}catch{}}}finally{this.#P=!1}}}#c(e){return!this.#r&&e.active&&this.#o===e&&e.generation===this.#v}#t(e){return this.#r?c("DESTROYED"):e!==this.#m?c("REPLACED"):null}#i(){return this.#e.now()}#g(e){const t=new this.#e.AbortController;return e.controllers.add(t),this.#b.add(t),t}#D(e,t){e.controllers.delete(t),this.#b.delete(t)}#w(e,t){let s;return s=this.#e.setTimeout(()=>{this.#R.delete(s),e()},Math.max(0,t)),this.#R.add(s),s}#W(e,t){const s=this.#e.setInterval(e,t);return this.#R.add(s),s}#d(e,t=!1){e!=null&&(t?this.#e.clearInterval(e):this.#e.clearTimeout(e),this.#R.delete(e))}#S(e){this.#d(e.expiryTimer),this.#d(e.pollTimer,!0),e.expiryTimer=null,e.pollTimer=null}#j(e){if(!(e.cleanupFinished||this.#y.has(e)))for(this.#y.add(e);this.#y.size>At;){const t=this.#y.values().next().value;for(const s of t.controllers)s.abort();this.#a(t)}}async#E(e){if(e.cleanupFinished||e.cleanupStarted||this.#r)return e.cleanup.promise;e.cleanupStarted=!0,this.#j(e);let t=100,s=!0;for(;!this.#r&&!e.cleanupFinished&&(s||this.#i()<=e.registrationDeadlineMs);){s=!1;const i=await this.#F(e);if(e.cleanupFinished)return e.cleanup.promise;if(i==="done")return this.#a(e),e.cleanup.promise;const o=e.registrationDeadlineMs-this.#i();if(o<=0)break;await new Promise(n=>{e.retryResolve=n,e.retryTimer=this.#w(()=>{e.retryResolve=null,n()},Math.min(t,o))}),e.retryResolve=null,e.retryTimer=null,t=Math.min(t*2,4e3)}return this.#a(e),e.cleanup.promise}async#F(e){if(!e.verifier||!e.challenge)return"done";const t=this.#g(e),s=e.registrationDeadlineMs-this.#i(),i=s>0?Math.min(4e3,s):1e3,o=this.#w(()=>t.abort(),Math.max(1,i));let n=null;try{const a=this.#e.fetch(`${P}/relay/v1/transactions/${e.transactionId}/cancel`,z({codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId},t.signal));n=await q(a,t.signal,j);const l=n.status;return S(t,n),n=null,l===204||l===400||l===403||l===409||l===410?"done":"retry"}catch{return n&&S(t,n),"retry"}finally{try{t.abort()}catch{}this.#d(o),this.#D(e,t)}}#X(e){let t;try{t=this.#e.fetch(`${P}/relay/v1/transactions/${e.transactionId}/cancel`,{...z({codeVerifier:e.verifier,schemaVersion:1,state:e.state,transactionId:e.transactionId}),keepalive:!0})}catch{return}X(Promise.resolve(t).then(j))}#a(e){if(!e.cleanupFinished){e.cleanupFinished=!0,this.#d(e.retryTimer),e.retryResolve?.(),e.retryResolve=null,e.retryTimer=null,this.#d(e.operationTimer),e.operationTimer=null,this.#S(e);for(const t of e.controllers)t.abort(),this.#b.delete(t);e.controllers.clear(),this.#y.delete(e),e.adapter=null,e.challenge=null,e.priorConnection=null,e.request=null,e.state=null,e.transactionExpiresAtMs=null,e.transactionId=null,e.verifier=null,e.cleanup.resolve()}}#Q(){if(!(this.#$||this.#r)){this.#$=!0,this.#x=!0;try{let e=null;try{const o=this.#e.getStorage;e=typeof o=="function"?Reflect.apply(o,void 0,[]):this.#e.storage??null}catch{e=null,this.#l=!0}try{(!e||typeof e.getItem!="function"||typeof e.removeItem!="function")&&(this.#l=!0)}catch{this.#l=!0}if(this.#r||this.#l){this.#u=null;return}if(this.#u=e,this.#Z(),this.#r||this.#l){this.#u=null;return}const t=o=>{const n=this.#o;if(!n||!this.#c(n))return;const a=`${V}${n.state}`;o?.key===a&&this.#N(n,!0)};this.#T=t;let s=!1,i=null;try{const o=this.#p?.addEventListener,n=this.#p?.removeEventListener;if(typeof o!="function"||typeof n!="function")throw new TypeError("storage events unavailable");i=()=>Reflect.apply(n,this.#p,["storage",t]),this.#A=i,Reflect.apply(o,this.#p,["storage",this.#T]),s=!0}catch{this.#l=!0}if(!s||this.#r||this.#l){try{i?.()}catch{}this.#T=null,this.#A=null,this.#u=null}}finally{this.#x=!1}}}#Z(){const e=this.#u;if(!e)return;let t;try{t=e.length}catch{return}if(!Number.isSafeInteger(t)||t<0)return;const s=Math.min(t,wt),i=[];for(let o=0;o<s&&!this.#r&&!this.#l;o+=1){let n;try{n=e.key(o)}catch{continue}i.push(n)}for(const o of i){if(this.#r||this.#l)return;if(typeof o!="string"||!o.startsWith(V))continue;const n=o.slice(V.length);if(N.test(n))try{const a=e.getItem(o);if(a===null)continue;const l=F(Y(a,2048),["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR");if(l.schemaVersion!==1||l.state!==n||!N.test(l.code))continue;K(l.expiresAt,"CALLBACK_ERROR")<=this.#i()&&e.removeItem(o)}catch{}}}}function Ae(r){return new xt(r)}function we(r,e={}){const t=(i,o)=>i!==0?Promise.reject(c("INVALID_REQUEST")):o(),s={connect(...i){return t(i.length,()=>r.execute("connect",void 0))},destroy(...i){return t(i.length,()=>r.destroy())},disconnect(...i){return t(i.length,()=>r.disconnect())},getSnapshot(...i){if(i.length!==0)throw c("INVALID_REQUEST");return r.getSnapshot()},openAccount(...i){return t(i.length,()=>r.execute("account",void 0))},subscribe(i,...o){if(o.length!==0)throw c("INVALID_REQUEST");return r.subscribe(i)}};for(const[i,o]of Object.entries(e))s[i]=function(a,...l){return l.length!==0?Promise.reject(c("INVALID_REQUEST")):r.execute(o,a)};return Object.freeze(s)}const Ct=Object.freeze(["digitalarsenal-pages-v1","sdn-asset-models-pages-v1","sdn-asset-review-v1","sdn-flatbuffers-pages-v1","sdn-flatsql-pages-v1","sdn-landing-web-v1","sdn-module-sdk-pages-v1","sdn-node-console-v1","sdn-standards-web-v1","spaceaware-web-v1"]);function Pt(r){let e;try{const t=Reflect.ownKeys(r);if(r===null||typeof r!="object"||Array.isArray(r)||Object.getPrototypeOf(r)!==Object.prototype||t.length!==1||t[0]!=="clientId")throw c("INVALID_REQUEST");e=Object.getOwnPropertyDescriptor(r,"clientId")}catch{throw c("INVALID_REQUEST")}if(!e?.enumerable||!("value"in e)||typeof e.value!="string")throw c("INVALID_REQUEST");if(!Ct.includes(e.value))throw c("INVALID_CLIENT");return e.value}const Oe=Object.freeze({account:Object.freeze({buildRequest:()=>We({}),kind:"account",operation:"sdn.wallet.account.v1",parseResult:Xe}),connect:Object.freeze({buildRequest:()=>He({}),kind:"connect",operation:"sdn.wallet.connect.v1",parseResult:Je})});function _e(r,e){if(tt(r)!==e)throw c("INVALID_REQUEST")}function ve({operation:r,buildRequest:e,parseRequest:t,parseResult:s,openResult:i}){return Object.freeze({buildRequest:e,kind:"typed",operation:r,parseResult:s,async seal(o,n){let a;try{a=await dt(n)}catch{throw c("CRYPTO_UNAVAILABLE")}return Object.freeze({request:t({...o,replyPublicKeyHex:a.publicKeyHex}),async open(l){const f=l.fields.map(d=>d.status==="opened"?I(d.ciphertextBase64url,1,E.fieldBytes,"reply"):null);let h;try{h=await a.open(l.replyEphemeralPublicKeyHex,f)}catch{throw c("CRYPTO_UNAVAILABLE")}return i(h)}})}})}const Nt=r=>ve({operation:"sdn.wallet.field-open.v1",buildRequest(e){const t=rt(e);for(const s of t.fields)_e(s.context,r);return t},parseRequest:st,parseResult:it,openResult:e=>Object.freeze(e.map(t=>Object.freeze(t===null?{refused:"NOT_ADDRESSED_TO_ACCOUNT"}:{plaintext:t})))}),gt=r=>ve({operation:"sdn.wallet.key-unwrap.v1",buildRequest(e){const t=nt(e);return _e(t.context,r),t},parseRequest:ot,parseResult:ct,openResult([e]){if(e===null)throw c("NOT_ADDRESSED_TO_ACCOUNT");if(e.length!==32)throw c("RELAY_ERROR");return Object.freeze({contentKey:e})}}),Dt=Object.freeze({"sdn-flatbuffers-pages-v1":Object.freeze({method:"openFields",adapter:Nt("flatbuffers")}),"sdn-flatsql-pages-v1":Object.freeze({method:"unwrapKey",adapter:gt("flatsql")})});function Le(r){if(arguments.length!==1)throw c("INVALID_REQUEST");const e=Pt(r),t=Dt[e];if(!t){const i=Ae({adapters:Oe,clientId:e});return we(i)}const s=Ae({adapters:Object.freeze({...Oe,sealed:t.adapter}),clientId:e});return we(s,{[t.method]:"sealed"})}const Te="SDNWalletPublicClient";if(Object.prototype.hasOwnProperty.call(globalThis,Te))throw new Error("SDN wallet public client global already exists");function jt(r){return arguments.length!==1?Le(...arguments):Le(r)}const kt=Object.freeze({create:jt});Object.defineProperty(globalThis,Te,{configurable:!1,enumerable:!1,value:kt,writable:!1})})();
@@ -1485,7 +1485,7 @@ function de(r, e = {}) {
1485
1485
  return Object.freeze(s);
1486
1486
  }
1487
1487
  const xt = Object.freeze([
1488
- "orbpro-pages-v1",
1488
+ "digitalarsenal-pages-v1",
1489
1489
  "sdn-asset-models-pages-v1",
1490
1490
  "sdn-asset-review-v1",
1491
1491
  "sdn-flatbuffers-pages-v1",
@@ -11,7 +11,7 @@ export type WalletRelayOperation =
11
11
 
12
12
  export type WalletClientStatus = 'dormant' | 'opening' | 'connected' | 'error';
13
13
  export type WalletClientId =
14
- | 'orbpro-pages-v1'
14
+ | 'digitalarsenal-pages-v1'
15
15
  | 'sdn-asset-models-pages-v1'
16
16
  | 'sdn-asset-review-v1'
17
17
  | 'sdn-flatbuffers-pages-v1'