hd-wallet-ui 2.1.3 → 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 +47 -2
- package/dist/browser/sdn-wallet-public-client.js +1 -1
- package/dist/client/asset-review.js +444 -439
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.js +986 -762
- package/dist/client/sdn.js +152 -147
- package/dist/client/types.d.ts +41 -2
- package/dist/wallet-origin/index.js +2219 -1876
- package/dist/wallet-origin-host/assets/{wallet-origin.83503193e638837518c50e7a3002b11d16574d6ff37e53ee6337486cb3db515d.css → wallet-origin.154fa2fd7f7dc1bf2051e35c1490915763fcaa6f05d88a3d32f1973ef0da5844.css} +1 -1
- package/dist/wallet-origin-host/assets/wallet-origin.c31bc2645e955c72dea686ed92e596c7d7348e80d1cd56d965d833a4bb7374b9.js +13880 -0
- package/dist/wallet-origin-host/assets/wallet-origin.c66954bde582bdefa0bd25d09628b36ddf90f917f63af56c52d1168ed995962d.wasm +0 -0
- package/dist/wallet-origin-host/index.html +2 -2
- package/dist/wallet-origin-host/integrity.json +1 -1
- package/package.json +3 -3
- package/dist/wallet-origin-host/assets/wallet-origin.03379597b86b0df5afbdfde8e251f33003611be5bf11fd014a624eb7e5312dcc.js +0 -13465
- package/dist/wallet-origin-host/assets/wallet-origin.b3fbc9f99c1c835b83651acb7326a69d9dee7baf4e314e82f0424edc8fb1d561.wasm +0 -0
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.
|
|
11
|
+
npm install hd-wallet-ui@2.2.2
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
`hd-wallet-wasm` 2.
|
|
14
|
+
`hd-wallet-wasm` 2.2.2 is the package's only runtime dependency.
|
|
15
15
|
|
|
16
16
|
## Published surfaces
|
|
17
17
|
|
|
@@ -81,6 +81,51 @@ wallet window opens. The caller receives only a public identity or a bounded
|
|
|
81
81
|
signature response; credential material and signing keys remain on the wallet
|
|
82
82
|
origin.
|
|
83
83
|
|
|
84
|
+
## Sealed fields and database keys
|
|
85
|
+
|
|
86
|
+
Two registered documentation sites can ask the wallet to open data sealed to
|
|
87
|
+
the signed-in user's contact-encryption key (X25519, `m/44'/0'/0'/1'/0'`) with
|
|
88
|
+
the SDN Unified ECIES field cipher. The wallet opens it only after the user
|
|
89
|
+
approves, only for the site the data is bound to, and returns only the opened
|
|
90
|
+
bytes. Keys and shared secrets never leave the wallet.
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
// sdn-flatbuffers-pages-v1: fields with their SDS $ENC headers.
|
|
94
|
+
const opened = await wallet.openFields({
|
|
95
|
+
fields: [{ enc, context, fieldId, ciphertext }], // 1..16, <= 4096 B each, <= 12288 B in all
|
|
96
|
+
});
|
|
97
|
+
// [{ plaintext: Uint8Array } | { refused: 'NOT_ADDRESSED_TO_ACCOUNT' }], in order
|
|
98
|
+
|
|
99
|
+
// sdn-flatsql-pages-v1: one database's content key, an $ENC + $KMF pair.
|
|
100
|
+
const { contentKey } = await wallet.unwrapKey({ enc, kmf, context });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `context` is the HKDF info and must equal the header's CONTEXT:
|
|
104
|
+
`sdn-field-encryption/v1|<site>|<schema>|<field>|k<version>`. The site is
|
|
105
|
+
`flatbuffers` for `sdn-flatbuffers-pages-v1` and `flatsql` for
|
|
106
|
+
`sdn-flatsql-pages-v1` (registry rows `flatbuffers-field-open-v1` and
|
|
107
|
+
`flatsql-key-unwrap-v1`). Data bound to another site is refused by the
|
|
108
|
+
client and, independently, by the wallet before it asks for a password.
|
|
109
|
+
- The header must carry `RECIPIENT_KEY_ID` = sha256(contact public key)[:8].
|
|
110
|
+
A field sealed to another key comes back `refused`; an unwrap rejects with
|
|
111
|
+
`NOT_ADDRESSED_TO_ACCOUNT`.
|
|
112
|
+
- `contentKey` is the database's own 32-byte content key, scoped to that
|
|
113
|
+
database. It is not a wallet key.
|
|
114
|
+
- The prompt names the site and the number of fields. "Don't ask again for
|
|
115
|
+
this site" covers that site and account for 15 minutes or 20 openings,
|
|
116
|
+
whichever ends first; signing out of the wallet forgets it. Every opening
|
|
117
|
+
still needs the wallet unlocked.
|
|
118
|
+
- The wallet seals its answer to a one-use X25519 key the client makes for
|
|
119
|
+
the request (the same field cipher, info `sdn-wallet-reply/v1`), so the relay
|
|
120
|
+
that carries the answer never holds a plaintext. The browser needs Web
|
|
121
|
+
Crypto X25519.
|
|
122
|
+
|
|
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.
|
|
128
|
+
|
|
84
129
|
## Callback page
|
|
85
130
|
|
|
86
131
|
Deploy the generated `dist/browser/wallet-callback.html` and its adjacent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const lt=Object.freeze({cm:.01,km:1e3,m:1,mm:.001}),ut=Object.freeze({metersPerSourceUnit:lt,quaternionNormTolerance:1e-6,scaleComponentExclusiveMin:0,scaleComponentInclusiveMax:1e6,translationComponentAbsMax:1e6,upAxes:Object.freeze(["X_UP","Y_UP","Z_UP"])}),ht=Object.freeze({reviewedTransform:ut,schemaVersion:1}),V=new TextEncoder,B=Object.getPrototypeOf(Uint8Array.prototype);Object.getOwnPropertyDescriptor(B,"buffer").get,Object.getOwnPropertyDescriptor(B,"length").get,Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get,typeof SharedArrayBuffer>"u"||Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype,"byteLength").get;const P="sdn-bip32-slip10-purpose-v1",x="password-scrypt-v2",J="ed25519-over-sha256-jcs-v1",ft=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,dt=/^[0-9a-f]{64}$/u,yt=/^sha256:[0-9a-f]{64}$/u,mt=/^[1-9A-HJ-NP-Za-km-z]+$/u,Rt=131072,pt=["accountFingerprint","accountIndex","accountLabel","accountPeerId","accountXpub","identityScheme","keys","schemaVersion","seedProfile"],Et=["bip32Fingerprint","curve","derivation","encoding","identityScheme","keyId","path","publicKeyHex","purpose","seedProfile","signatureProfile"],bt=["connectionExpiresAt","event","identity","schemaVersion"];function u(r){throw new TypeError(r)}function At(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const t=Object.getPrototypeOf(r);return t===Object.prototype||t===null}function v(r,t){typeof r!="string"&&u(`${t} must be a string`);for(let e=0;e<r.length;e+=1){const i=r.charCodeAt(e);let s=i;if(i>=55296&&i<=56319){const o=r.charCodeAt(e+1);o>=56320&&o<=57343||u(`${t} contains an unpaired surrogate`),s=65536+(i-55296<<10)+(o-56320),e+=1}else i>=56320&&i<=57343&&u(`${t} contains an unpaired surrogate`);((s&65535)===65534||(s&65535)===65535||s>=64976&&s<=65007)&&u(`${t} contains a Unicode noncharacter`)}return r}function Ot(r){typeof r!="string"&&u("wire JSON must be a string"),V.encode(r).byteLength>Rt&&u("wire JSON is too large"),r.charCodeAt(0)===65279&&u("wire JSON must not contain a BOM");let t=0,e=0;const i=()=>{for(;t<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[t]);)t+=1},s=()=>{r[t]!=='"'&&u("invalid JSON string");const l=t;for(t+=1;t<r.length;){const a=r.charCodeAt(t);if(a===34){t+=1;let h;try{h=JSON.parse(r.slice(l,t))}catch{u("invalid JSON string")}return v(h,"JSON string")}a<32&&u("invalid JSON control character"),a===92&&(t+=1,t>=r.length&&u("unterminated JSON escape")),t+=1}u("unterminated JSON string")},o=(l=0)=>{l>32&&u("wire JSON nesting is too deep"),e+=1,e>4096&&u("wire JSON contains too many values"),i();const a=r[t];if(a==='"')return s();if(a==="{"){t+=1;const d=Object.create(null),y=new Set;if(i(),r[t]==="}")return t+=1,d;for(;t<r.length;){i();const m=s();if(y.has(m)&&u(`duplicate JSON field: ${m}`),y.add(m),i(),r[t]!==":"&&u("missing JSON object colon"),t+=1,d[m]=o(l+1),i(),r[t]==="}")return t+=1,d;r[t]!==","&&u("invalid JSON object separator"),t+=1}u("unterminated JSON object")}if(a==="["){t+=1;const d=[];if(i(),r[t]==="]")return t+=1,d;for(;t<r.length;){if(d.push(o(l+1)),i(),r[t]==="]")return t+=1,d;r[t]!==","&&u("invalid JSON array separator"),t+=1}u("unterminated JSON array")}for(const[d,y]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(d,t))return t+=d.length,y;const h=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(t));h||u("invalid JSON value"),t+=h[0].length;const f=Number(h[0]);return Number.isFinite(f)||u("wire JSON number must be finite"),f};i();const n=o();return i(),t!==r.length&&u("wire JSON contains trailing bytes"),n}function wt(r){return typeof r=="string"?Ot(r):r}function vt(r,t){if(r.byteLength!==t.byteLength)return!1;let e=0;for(let i=0;i<r.byteLength;i+=1)e|=r[i]^t[i];return e===0}function O(r,t,e){const i=wt(r);At(i)||u(`${e} must be a JSON object`),Object.getOwnPropertySymbols(i).length!==0&&u(`${e} has an unknown symbol field`);const s=Object.getOwnPropertyNames(i).sort(),o=[...t].sort(),n=V.encode(s.join("\0")),l=V.encode(o.join("\0"));vt(n,l)||u(`${e} has missing or unknown fields`);for(const a of s){const h=Object.getOwnPropertyDescriptor(i,a);(!h||!h.enumerable||!("value"in h))&&u(`${e}.${a} must be an enumerable data field`),h.value===void 0&&u(`${e}.${a} must not be undefined`)}return i}function N(r){if(!r||typeof r!="object"||Object.isFrozen(r))return r;for(const t of Object.values(r))N(t);return Object.freeze(r)}function L(r){return N(Object.fromEntries([...r].sort(([t],[e])=>t<e?-1:t>e?1:0)))}function W(r,t,e){(!Array.isArray(r)||Object.getPrototypeOf(r)!==Array.prototype||r.length!==t)&&u(`${e} must be a plain array with exactly ${t} values`);const i=[...Array.from({length:t},(o,n)=>String(n)),"length"],s=Reflect.ownKeys(r);(s.length!==i.length||s.some((o,n)=>o!==i[n]))&&u(`${e} must be a dense plain array`);for(let o=0;o<t;o+=1){const n=Object.getOwnPropertyDescriptor(r,String(o));(!n||!n.enumerable||!("value"in n)||n.value===void 0)&&u(`${e} must contain enumerable data values`)}}function Lt(r){const t=O(r,["reviewedTransform","schemaVersion"],"asset review protocol policy");R(t.schemaVersion,1,"asset review protocol schemaVersion");const e=O(t.reviewedTransform,["metersPerSourceUnit","quaternionNormTolerance","scaleComponentExclusiveMin","scaleComponentInclusiveMax","translationComponentAbsMax","upAxes"],"asset review transform policy"),i=O(e.metersPerSourceUnit,["cm","km","m","mm"],"asset review unit policy");for(const[s,o]of Object.entries(i))(typeof o!="number"||!Number.isFinite(o)||o<=0)&&u(`asset review unit policy ${s} must be positive and finite`);for(const[s,o]of[["quaternionNormTolerance",e.quaternionNormTolerance],["scaleComponentExclusiveMin",e.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",e.scaleComponentInclusiveMax],["translationComponentAbsMax",e.translationComponentAbsMax]])(typeof o!="number"||!Number.isFinite(o))&&u(`asset review transform policy ${s} must be finite`);return(e.quaternionNormTolerance<=0||e.scaleComponentInclusiveMax<=e.scaleComponentExclusiveMin||e.translationComponentAbsMax<=0)&&u("asset review transform policy bounds are inconsistent"),W(e.upAxes,3,"asset review up-axis policy"),e.upAxes.join("\0")!=="X_UP\0Y_UP\0Z_UP"&&u("asset review up-axis policy is invalid"),L([["metersPerSourceUnit",L(Object.entries(i))],["quaternionNormTolerance",e.quaternionNormTolerance],["scaleComponentExclusiveMin",e.scaleComponentExclusiveMin],["scaleComponentInclusiveMax",e.scaleComponentInclusiveMax],["translationComponentAbsMax",e.translationComponentAbsMax],["upAxes",Object.freeze(Array.from({length:3},(s,o)=>e.upAxes[o]))]])}Lt(ht);function R(r,t,e){return r!==t&&u(`${e} must equal ${JSON.stringify(t)}`),r}function _t(r,t,e){return t.includes(r)||u(`${e} is not an allowed value`),r}function $(r,t,e){return v(r,e),t.test(r)||u(`${e} has an invalid encoding`),r}function Tt(r,t){return v(r,t),(!ft.test(r)||new Date(r).toISOString()!==r)&&u(`${t} must be exact RFC3339 milliseconds UTC`),r}function It(r,t){const e=O(r,Et,`identity key ${t.purpose}`);return R(e.purpose,t.purpose,"key purpose"),R(e.identityScheme,P,"key identityScheme"),R(e.seedProfile,x,"key seedProfile"),R(e.signatureProfile,t.signatureProfile,"key signatureProfile"),R(e.curve,t.curve,"key curve"),R(e.derivation,"slip10","key derivation"),R(e.path,t.path,"key path"),R(e.encoding,"raw","key encoding"),$(e.publicKeyHex,dt,"key publicKeyHex"),R(e.bip32Fingerprint,null,"key bip32Fingerprint"),$(e.keyId,yt,"key keyId"),L([["bip32Fingerprint",null],["curve",e.curve],["derivation","slip10"],["encoding","raw"],["identityScheme",P],["keyId",e.keyId],["path",e.path],["publicKeyHex",e.publicKeyHex],["purpose",e.purpose],["seedProfile",x],["signatureProfile",e.signatureProfile]])}function St(r){const t=O(r,pt,"WalletPublicIdentity");R(t.schemaVersion,1,"identity schemaVersion"),R(t.identityScheme,P,"identity identityScheme"),R(t.seedProfile,x,"identity seedProfile"),t.accountIndex!==0&&u("public wallet identity must use account 0"),R(t.accountLabel,null,"identity accountLabel"),v(t.accountXpub,"identity accountXpub"),/^xpub[1-9A-HJ-NP-Za-km-z]{107}$/u.test(t.accountXpub)||u("identity accountXpub is invalid"),v(t.accountPeerId,"identity accountPeerId"),(!t.accountPeerId.startsWith("16Uiu2H")||t.accountPeerId.length<40||t.accountPeerId.length>64||!mt.test(t.accountPeerId))&&u("identity accountPeerId is invalid"),$(t.accountFingerprint,/^[0-9a-f]{8}$/u,"identity accountFingerprint"),W(t.keys,3,"public identity keys array");const e=[{purpose:"asset-review-approval",curve:"ed25519",signatureProfile:J,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:J,path:"m/44'/0'/0'/0'/0'"}],i=Array.from({length:3},(s,o)=>It(t.keys[o],e[o]));return L([["accountFingerprint",t.accountFingerprint],["accountIndex",0],["accountLabel",null],["accountPeerId",t.accountPeerId],["accountXpub",t.accountXpub],["identityScheme",P],["keys",N(i)],["schemaVersion",1],["seedProfile",x]])}function q(r,t){const e=O(r,bt,`${t} result`);R(e.schemaVersion,1,"connection result schemaVersion"),_t(e.event,["connected","disconnected"],"connection event"),t==="connect"&&e.event!=="connected"&&u("connect result must be connected");let i=null,s=null;return e.event==="connected"?(i=St(e.identity),s=Tt(e.connectionExpiresAt,"connectionExpiresAt")):(e.identity!==null||e.connectionExpiresAt!==null)&&u("disconnected result must clear identity and expiry"),L([["connectionExpiresAt",s],["event",e.event],["identity",i],["schemaVersion",1]])}function K(r,t){return O(r,[],t),N({})}function Ct(r={}){return K(r,"wallet connect request")}function Pt(r){return q(r,"connect")}function xt(r={}){return K(r,"wallet account request")}function Nt(r){return q(r,"account")}const _="https://wallet.spacedatanetwork.org",j="sdn.wallet.callback.v1:",T=/^[0-9a-f]{64}$/u,z=/^[A-Za-z0-9_-]{43}$/u,jt=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u,gt=250,Dt=3e4,kt=3e5,Mt=9e5,Yt=12e4,Vt=8,X=4096,H=70*1024,$t=64,Q=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.",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."}),Z=new TextEncoder,Ut=new TextDecoder("utf-8",{fatal:!0});class I extends Error{constructor(t){super(Q[t]),this.name="WalletClientError",Object.defineProperty(this,"code",{configurable:!1,enumerable:!0,value:t,writable:!1})}}function c(r){return Object.hasOwn(Q,r)?new I(r):new I("RELAY_ERROR")}function Ft(r){if(r===null||typeof r!="object"||Array.isArray(r))return!1;const t=Object.getPrototypeOf(r);return t===Object.prototype||t===null}function g(r,t){if(typeof r!="string"||r.length>t||Z.encode(r).byteLength>t||r.charCodeAt(0)===65279)throw c("RELAY_ERROR");let e=0,i=0;const s=()=>{for(;e<r.length&&/[\u0009\u000a\u000d\u0020]/u.test(r[e]);)e+=1},o=()=>{if(r[e]!=='"')throw c("RELAY_ERROR");const a=e;for(e+=1;e<r.length;){const h=r.charCodeAt(e);if(h===34){e+=1;let f;try{f=JSON.parse(r.slice(a,e))}catch{throw c("RELAY_ERROR")}for(let d=0;d<f.length;d+=1){const y=f.charCodeAt(d);if(y>=55296&&y<=56319){const m=f.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 f}if(h<32||h===92&&(e+=1,e>=r.length))throw c("RELAY_ERROR");e+=1}throw c("RELAY_ERROR")},n=(a=0)=>{if(a>32||++i>4096)throw c("RELAY_ERROR");s();const h=r[e];if(h==='"')return o();if(h==="{"){e+=1;const y=Object.create(null),m=new Set;if(s(),r[e]==="}")return e+=1,y;for(;e<r.length;){s();const A=o();if(m.has(A)||(m.add(A),s(),r[e]!==":"))throw c("RELAY_ERROR");if(e+=1,y[A]=n(a+1),s(),r[e]==="}")return e+=1,y;if(r[e]!==",")throw c("RELAY_ERROR");e+=1}throw c("RELAY_ERROR")}if(h==="["){e+=1;const y=[];if(s(),r[e]==="]")return e+=1,y;for(;e<r.length;){if(y.push(n(a+1)),s(),r[e]==="]")return e+=1,y;if(r[e]!==",")throw c("RELAY_ERROR");e+=1}throw c("RELAY_ERROR")}for(const[y,m]of[["true",!0],["false",!1],["null",null]])if(r.startsWith(y,e))return e+=y.length,m;const f=/^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/u.exec(r.slice(e));if(!f)throw c("RELAY_ERROR");e+=f[0].length;const d=Number(f[0]);if(!Number.isFinite(d))throw c("RELAY_ERROR");return d};s();const l=n();if(s(),e!==r.length)throw c("RELAY_ERROR");return l}function D(r,t,e="RELAY_ERROR"){if(!Ft(r)||Object.getOwnPropertySymbols(r).length!==0)throw c(e);const i=Object.getOwnPropertyNames(r).sort(),s=[...t].sort();if(i.length!==s.length||i.some((o,n)=>o!==s[n]))throw c(e);for(const o of i){const n=Object.getOwnPropertyDescriptor(r,o);if(!n?.enumerable||!("value"in n)||n.value===void 0)throw c(e)}return r}function k(r,t="RELAY_ERROR"){if(typeof r!="string"||!jt.test(r))throw c(t);const e=Date.parse(r);if(!Number.isFinite(e)||new Date(e).toISOString()!==r)throw c(t);return e}function b(r){return Array.isArray(r)?Object.freeze(r.map(b)):r&&typeof r=="object"?Object.freeze(Object.fromEntries(Object.entries(r).map(([t,e])=>[t,b(e)]))):r}function G(r){const t={identity:r.identity===null?null:b(r.identity),status:r.status};return r.connectionExpiresAt!==void 0&&(t.connectionExpiresAt=r.connectionExpiresAt),r.error!==void 0&&(t.error=b(r.error)),b(t)}function S(r){return Object.freeze({code:r.code,message:r.message})}function tt(r){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";let e=0,i=0,s="";for(const o of r)for(e=e<<8|o,i+=8;i>=6;)i-=6,s+=t[e>>>i&63],e&=(1<<i)-1;return i!==0&&(s+=t[e<<6-i&63]),s}function et(r){let t="";for(const e of r)t+=e.toString(16).padStart(2,"0");return t}function U(r,t){const e=new Uint8Array(32);return Reflect.apply(t,r,[e]),e}function Bt(r){const t=r?.headers?.get?.("content-type");return typeof t=="string"&&/^application\/json(?:\s*;\s*charset=utf-8)?$/iu.test(t.trim())}function F(r){try{Promise.resolve(r).catch(()=>{})}catch{}}function C(r){try{const t=r?.body,e=t?.cancel;typeof e=="function"&&F(Reflect.apply(e,t,[]))}catch{}}function rt(r){try{const t=r?.cancel;typeof t=="function"&&F(Reflect.apply(t,r,[]))}catch{}}function Jt(r){try{const t=r?.releaseLock;typeof t=="function"&&Reflect.apply(t,r,[])}catch{}}function w(r,t,e=null){try{r.abort()}catch{}e&&rt(e),C(t)}function M(r,t,e=null){let i;try{i=Promise.resolve(r)}catch(s){return Promise.reject(s)}return new Promise((s,o)=>{let n=!1;const l=()=>{try{t.removeEventListener("abort",h)}catch{}},a=(f,d)=>n?!1:(n=!0,l(),f(d),!0),h=()=>{a(o,c("RELAY_ERROR"))};try{t.addEventListener("abort",h,{once:!0}),t.aborted&&h()}catch{h()}i.then(f=>{if(n){try{e?.(f)}catch{}return}a(s,f)},f=>{n||a(o,f)})})}async function it(r,t,e){let i=null;const s=[];let o=0;try{if(!Bt(r)||typeof r?.body?.getReader!="function")throw c("RELAY_ERROR");for(i=r.body.getReader();;){const a=i.read(),{done:h,value:f}=await M(a,e.signal);if(h)break;if(!(f instanceof Uint8Array)||(o+=f.byteLength,o>t))throw c("RELAY_ERROR");s.push(f)}const n=new Uint8Array(o);let l=0;for(const a of s)n.set(a,l),l+=a.byteLength;return Ut.decode(n)}catch{try{e.abort()}catch{}throw i&&rt(i),c("RELAY_ERROR")}finally{i&&Jt(i)}}function Y(r,t){const e={body:JSON.stringify(r),cache:"no-store",credentials:"omit",headers:{"Content-Type":"application/json"},method:"POST",mode:"cors",redirect:"error",referrerPolicy:"no-referrer"};return t!==void 0&&(e.signal=t),e}function Wt(r,t,e){let i;try{i=g(r,2048),D(i,["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR")}catch{throw c("CALLBACK_ERROR")}if(i.schemaVersion!==1||i.state!==t||!T.test(i.code))throw c("CALLBACK_ERROR");const s=k(i.expiresAt,"CALLBACK_ERROR");if(s<=e||s-e>Yt)throw c("CALLBACK_ERROR");return{code:i.code,expiresAt:s,state:i.state}}function qt(){let r;return{promise:new Promise(e=>{r=e}),resolve:r}}function st(){let r,t;return{promise:new Promise((i,s)=>{r=s,t=i}),reject:r,resolve:t}}function Kt(){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 zt{#k;#M;#C=!1;#l=!1;#Y=!1;#n=null;#w=null;#b=new Set;#t;#v=null;#r=!1;#R=0;#L=0;#_=new Set;#P=[];#o=null;#x=!1;#y=new Set;#V=Object.freeze({identity:null,status:"dormant"});#u=null;#T=null;#A=null;#p=new Set;#m;constructor({adapters:t,clientId:e,dependencies:i}){this.#k=t,this.#M=e,this.#t=i??Kt(),this.#m=this.#t.window}getSnapshot(){return this.#F(),G(this.#V)}subscribe(t){if(typeof t!="function")throw c("INVALID_REQUEST");if(this.#r)throw c("DESTROYED");this.#_.add(t);try{t(this.getSnapshot())}catch{}let e=!0;return()=>{e&&(e=!1,this.#_.delete(t))}}execute(t,e){if(this.#r)return Promise.reject(c("DESTROYED"));const i=this.#R,s=this.#k[t];if(!s)return Promise.reject(c("INVALID_REQUEST"));let o;try{o=s.buildRequest(e)}catch{const p=this.#e(i);return p?Promise.reject(p):Promise.reject(c("INVALID_REQUEST"))}let n=this.#e(i);if(n)return Promise.reject(n);if(this.#C)return this.#l=!0,Promise.reject(c("REPLACED"));const l=++this.#R;if(this.#Q(),n=this.#e(l),n)return Promise.reject(n);if(this.#l)return Promise.reject(c("CALLBACK_ERROR"));if(this.#F(),n=this.#e(l),n)return Promise.reject(n);const a=this.#s();if(n=this.#e(l),n)return Promise.reject(n);const h=this.#n&&this.#n.expiresAtMs>a?this.#n:null;if(n=this.#e(l),n)return Promise.reject(n);const f=this.#o;let d,y,m;try{const p=this.#t.crypto,E=p?.getRandomValues,ie=p?.subtle?.digest,at=this.#m?.open;if(n=this.#e(l),n)throw n;if(typeof E!="function"||typeof ie!="function"||typeof at!="function")throw c("CRYPTO_UNAVAILABLE");if(d=et(U(p,E)),n=this.#e(l),n||(y=et(U(p,E)),n=this.#e(l),n)||(m=tt(U(p,E)),n=this.#e(l),n))throw n;if(!T.test(d)||!T.test(y)||!z.test(m))throw c("CRYPTO_UNAVAILABLE");if(Reflect.apply(at,this.#m,[`${_}/transaction/${d}`,"_blank","noopener"]),n=this.#e(l),n)throw n}catch(p){if(n=this.#e(l),n)return Promise.reject(n);let E;try{E=p instanceof I?p:c("CRYPTO_UNAVAILABLE")}catch{E=c("CRYPTO_UNAVAILABLE")}return f&&(this.#I(f,"REPLACED",!1),n=this.#e(l),n)?Promise.reject(n):(this.#$(null,E,h,s.kind),Promise.reject(E))}if(f&&(this.#I(f,"REPLACED",!1),n=this.#e(l),n))return Promise.reject(n);const A=st(),re=qt(),ct={active:!0,adapter:s,callbackBusy:!1,challenge:null,cleanup:re,cleanupFinished:!1,cleanupStarted:!1,controllers:new Set,expiryTimer:null,generation:++this.#L,operationTimer:null,phase:"hashing",pollTimer:null,priorConnection:h,promise:A.promise,registrationDeadlineMs:a+Dt,registrationOutcome:"none",reject:A.reject,request:o,resolve:A.resolve,retryResolve:null,retryTimer:null,state:y,transactionExpiresAtMs:null,transactionId:d,verifier:m};return this.#o=ct,this.#i({...h?{connectionExpiresAt:h.expiresAt,identity:h.identity}:{identity:null},status:"opening"}),this.#W(ct),A.promise}async disconnect(){if(this.#r)throw c("DESTROYED");const t=++this.#R;this.#f();const e=this.#o;let i=Promise.resolve();e&&(i=this.#I(e,"DISCONNECTED",!1));let s=this.#e(t);if(s)throw await i,s;if(this.#i({identity:null,status:"dormant"}),await i,s=this.#e(t),s)throw s}destroy(){if(this.#v)return this.#v;const t=st();this.#v=t.promise,this.#R+=1;try{this.#J(),t.resolve()}catch{t.reject(c("RELAY_ERROR"))}return this.#v}#J(){this.#r=!0,this.#L+=1,this.#f();const t=[],e=this.#o;e&&(e.active=!1,this.#o=null,this.#S(e),e.reject(c("DESTROYED")),e.challenge&&e.verifier&&t.push(e));for(const i of this.#y)i.challenge&&i.verifier&&t.push(i);for(const i of this.#b)i.abort();this.#b.clear();for(const i of this.#p)this.#t.clearTimeout(i),this.#t.clearInterval(i);if(this.#p.clear(),this.#A)try{this.#A()}catch{}this.#T=null,this.#A=null,this.#u=null,this.#_.clear();for(const i of t)this.#H(i);e&&this.#a(e);for(const i of[...this.#y])this.#a(i);this.#i({error:S(c("DESTROYED")),identity:null,status:"error"})}async#W(t){if(!(!this.#c(t)||t.cleanupFinished))try{t.operationTimer=this.#O(()=>{if(!t.cleanupFinished){if(t.phase==="hashing"){this.#c(t)&&this.#h(t,"CRYPTO_UNAVAILABLE",!1);return}if(t.phase==="registering")for(const l of t.controllers)l.abort()}},Math.max(0,t.registrationDeadlineMs-this.#s()));const e=await this.#t.crypto.subtle.digest("SHA-256",Z.encode(t.verifier)),i=tt(new Uint8Array(e));if(!z.test(i))throw c("CRYPTO_UNAVAILABLE");if(!this.#c(t)){t.registrationOutcome="not-started",this.#a(t);return}t.challenge=i,t.phase="registering";const s=this.#j(t);let o,n=null;try{try{const a=this.#t.fetch(`${_}/relay/v1/transactions`,Y({clientId:this.#M,codeChallenge:t.challenge,codeChallengeMethod:"S256",operation:t.adapter.operation,request:t.request,schemaVersion:1,state:t.state,transactionId:t.transactionId},s.signal));n=await M(a,s.signal,C)}catch{t.registrationOutcome="ambiguous",t.active?this.#h(t,"RELAY_ERROR"):this.#E(t);return}t.registrationOutcome="ambiguous";let l;try{l=n.status}catch{w(s,n),t.active?this.#h(t,"RELAY_ERROR"):this.#E(t);return}if(l!==201){t.registrationOutcome="definitive-failure",w(s,n),t.active?this.#h(t,"RELAY_ERROR",!1):this.#a(t);return}try{const a=await it(n,X,s),h=D(g(a,X),["expiresAt","schemaVersion","transactionId"]);if(h.schemaVersion!==1||h.transactionId!==t.transactionId)throw c("RELAY_ERROR");o=k(h.expiresAt);const f=this.#s();if(o<=f||o-f>kt)throw c("RELAY_ERROR")}catch{t.registrationOutcome="ambiguous",w(s,n),t.active?this.#h(t,"RELAY_ERROR"):this.#E(t);return}}finally{try{s.abort()}catch{}this.#g(t,s),this.#d(t.operationTimer),t.operationTimer=null}if(t.transactionExpiresAtMs=o,t.registrationOutcome="registered",!this.#c(t)){this.#E(t);return}t.phase="waiting-callback",t.expiryTimer=this.#O(()=>{this.#c(t)&&this.#h(t,"WALLET_NOT_COMPLETED")},Math.max(0,t.transactionExpiresAtMs-this.#s())),t.pollTimer=this.#X(()=>{this.#N(t,!1)},gt),await this.#N(t,!1)}catch(e){if(!t.active){t.registrationOutcome==="ambiguous"||t.registrationOutcome==="registered"?this.#E(t):this.#a(t);return}const i=e instanceof I?e.code:t.phase==="hashing"?"CRYPTO_UNAVAILABLE":"RELAY_ERROR";this.#h(t,i,t.registrationOutcome!=="none")}}async#N(t,e){if(!this.#c(t)||t.phase!=="waiting-callback"||t.callbackBusy||!this.#u)return;const i=`${j}${t.state}`;let s;try{s=this.#u.getItem(i)}catch{e&&this.#h(t,"CALLBACK_ERROR");return}if(s===null)return;t.callbackBusy=!0;let o;try{o=Wt(s,t.state,this.#s()),this.#u.removeItem(i)}catch{try{this.#u.removeItem(i)}catch{}this.#h(t,"CALLBACK_ERROR");return}if(!this.#c(t))return;t.phase="redeeming",this.#d(t.pollTimer,!0),t.pollTimer=null;const n=this.#j(t);let l=null;try{const a=this.#t.fetch(`${_}/relay/v1/codes/redeem`,Y({code:o.code,codeVerifier:t.verifier,schemaVersion:1,state:t.state,transactionId:t.transactionId},n.signal));if(l=await M(a,n.signal,C),l.status!==200)throw c("RELAY_ERROR");const h=await it(l,H,n),f=D(g(h,H),["result","schemaVersion","transactionId"]);if(f.schemaVersion!==1||f.transactionId!==t.transactionId)throw c("RELAY_ERROR");let d;try{d=t.adapter.parseResult(f.result)}catch{throw c("RELAY_ERROR")}if(!this.#c(t))return;this.#q(t,d)}catch(a){if(l&&w(n,l),!this.#c(t))return;const h=a instanceof I?a.code:"RELAY_ERROR";this.#h(t,h)}finally{try{n.abort()}catch{}this.#g(t,n)}}#q(t,e){if(!this.#c(t))return;let i=null;(t.adapter.kind==="connect"||t.adapter.kind==="account"&&e.event==="connected")&&(i=this.#K(e)),t.active=!1,this.#o=null,this.#S(t);let s=e;t.adapter.kind==="connect"?(this.#U(i),s=b(e.identity)):t.adapter.kind==="account"?(e.event==="connected"?this.#U(i):(this.#f(),this.#i({identity:null,status:"dormant"})),s=void 0):this.#z(t,void 0),t.resolve(s),this.#a(t)}#h(t,e,i=!0){this.#c(t)&&this.#I(t,e,!0,i)}#I(t,e,i,s=!0){if(!t.active)return t.cleanup.promise;const o=this.#R;t.active=!1,this.#o===t&&(this.#o=null),this.#L+=1,this.#S(t);for(const a of t.controllers)t.phase!=="registering"&&a.abort();const n=this.#e(o),l=n??c(e);return t.reject(l),i&&!n&&this.#$(t,l,t.priorConnection,t.adapter.kind),this.#r?(t.challenge&&t.verifier&&this.#B(t),this.#a(t),t.cleanup.promise):(!s||t.registrationOutcome==="definitive-failure"||t.registrationOutcome==="not-started"?this.#a(t):t.phase==="hashing"?(t.registrationOutcome="not-started",this.#a(t)):t.phase==="registering"&&t.registrationOutcome==="none"?this.#D(t):(this.#D(t),this.#E(t)),t.cleanup.promise)}#$(t,e,i,s){if(i?.expiresAtMs>this.#s()){this.#n=i,this.#i({connectionExpiresAt:i.expiresAt,error:S(e),identity:i.identity,status:"connected"});return}this.#f(),this.#i({error:S(e),identity:null,status:"error"})}#K(t){const e=k(t.connectionExpiresAt),i=this.#s();if(e<=i||e-i>Mt)throw c("RELAY_ERROR");return{expiresAt:t.connectionExpiresAt,expiresAtMs:e,identity:b(t.identity)}}#U(t){const e=this.#s();this.#f(),this.#n=t;const i=this.#n;this.#w=this.#O(()=>{this.#n===i&&(this.#n=null,this.#w=null,this.#o?this.#i({identity:null,status:"opening"}):this.#i({identity:null,status:"dormant"}))},Math.max(0,t.expiresAtMs-e)),this.#i({connectionExpiresAt:t.expiresAt,identity:this.#n.identity,status:"connected"})}#z(t,e){const i=t.priorConnection;i?.expiresAtMs>this.#s()?(this.#n=i,this.#i({connectionExpiresAt:i.expiresAt,...e?{error:S(e)}:{},identity:i.identity,status:"connected"})):e?(this.#f(),this.#i({error:S(e),identity:null,status:"error"})):(this.#f(),this.#i({identity:null,status:"dormant"}))}#F(){!this.#n||this.#n.expiresAtMs>this.#s()||(this.#f(),this.#o?this.#i({identity:null,status:"opening"}):this.#i({identity:null,status:"dormant"}))}#f(){this.#n=null,this.#d(this.#w),this.#w=null}#i(t){const e=b(t);if(this.#V=e,this.#P.push(e),!this.#x){this.#x=!0;try{for(;this.#P.length!==0;){const i=this.#P.shift();for(const s of[...this.#_])try{s(G(i))}catch{}}}finally{this.#x=!1}}}#c(t){return!this.#r&&t.active&&this.#o===t&&t.generation===this.#L}#e(t){return this.#r?c("DESTROYED"):t!==this.#R?c("REPLACED"):null}#s(){return this.#t.now()}#j(t){const e=new this.#t.AbortController;return t.controllers.add(e),this.#b.add(e),e}#g(t,e){t.controllers.delete(e),this.#b.delete(e)}#O(t,e){let i;return i=this.#t.setTimeout(()=>{this.#p.delete(i),t()},Math.max(0,e)),this.#p.add(i),i}#X(t,e){const i=this.#t.setInterval(t,e);return this.#p.add(i),i}#d(t,e=!1){t!=null&&(e?this.#t.clearInterval(t):this.#t.clearTimeout(t),this.#p.delete(t))}#S(t){this.#d(t.expiryTimer),this.#d(t.pollTimer,!0),t.expiryTimer=null,t.pollTimer=null}#D(t){if(!(t.cleanupFinished||this.#y.has(t)))for(this.#y.add(t);this.#y.size>Vt;){const e=this.#y.values().next().value;for(const i of e.controllers)i.abort();this.#a(e)}}async#E(t){if(t.cleanupFinished||t.cleanupStarted||this.#r)return t.cleanup.promise;t.cleanupStarted=!0,this.#D(t);let e=100,i=!0;for(;!this.#r&&!t.cleanupFinished&&(i||this.#s()<=t.registrationDeadlineMs);){i=!1;const s=await this.#B(t);if(t.cleanupFinished)return t.cleanup.promise;if(s==="done")return this.#a(t),t.cleanup.promise;const o=t.registrationDeadlineMs-this.#s();if(o<=0)break;await new Promise(n=>{t.retryResolve=n,t.retryTimer=this.#O(()=>{t.retryResolve=null,n()},Math.min(e,o))}),t.retryResolve=null,t.retryTimer=null,e=Math.min(e*2,4e3)}return this.#a(t),t.cleanup.promise}async#B(t){if(!t.verifier||!t.challenge)return"done";const e=this.#j(t),i=t.registrationDeadlineMs-this.#s(),s=i>0?Math.min(4e3,i):1e3,o=this.#O(()=>e.abort(),Math.max(1,s));let n=null;try{const l=this.#t.fetch(`${_}/relay/v1/transactions/${t.transactionId}/cancel`,Y({codeVerifier:t.verifier,schemaVersion:1,state:t.state,transactionId:t.transactionId},e.signal));n=await M(l,e.signal,C);const a=n.status;return w(e,n),n=null,a===204||a===400||a===403||a===409||a===410?"done":"retry"}catch{return n&&w(e,n),"retry"}finally{try{e.abort()}catch{}this.#d(o),this.#g(t,e)}}#H(t){let e;try{e=this.#t.fetch(`${_}/relay/v1/transactions/${t.transactionId}/cancel`,{...Y({codeVerifier:t.verifier,schemaVersion:1,state:t.state,transactionId:t.transactionId}),keepalive:!0})}catch{return}F(Promise.resolve(e).then(C))}#a(t){if(!t.cleanupFinished){t.cleanupFinished=!0,this.#d(t.retryTimer),t.retryResolve?.(),t.retryResolve=null,t.retryTimer=null,this.#d(t.operationTimer),t.operationTimer=null,this.#S(t);for(const e of t.controllers)e.abort(),this.#b.delete(e);t.controllers.clear(),this.#y.delete(t),t.adapter=null,t.challenge=null,t.priorConnection=null,t.request=null,t.state=null,t.transactionExpiresAtMs=null,t.transactionId=null,t.verifier=null,t.cleanup.resolve()}}#Q(){if(!(this.#Y||this.#r)){this.#Y=!0,this.#C=!0;try{let t=null;try{const o=this.#t.getStorage;t=typeof o=="function"?Reflect.apply(o,void 0,[]):this.#t.storage??null}catch{t=null,this.#l=!0}try{(!t||typeof t.getItem!="function"||typeof t.removeItem!="function")&&(this.#l=!0)}catch{this.#l=!0}if(this.#r||this.#l){this.#u=null;return}if(this.#u=t,this.#Z(),this.#r||this.#l){this.#u=null;return}const e=o=>{const n=this.#o;if(!n||!this.#c(n))return;const l=`${j}${n.state}`;o?.key===l&&this.#N(n,!0)};this.#T=e;let i=!1,s=null;try{const o=this.#m?.addEventListener,n=this.#m?.removeEventListener;if(typeof o!="function"||typeof n!="function")throw new TypeError("storage events unavailable");s=()=>Reflect.apply(n,this.#m,["storage",e]),this.#A=s,Reflect.apply(o,this.#m,["storage",this.#T]),i=!0}catch{this.#l=!0}if(!i||this.#r||this.#l){try{s?.()}catch{}this.#T=null,this.#A=null,this.#u=null}}finally{this.#C=!1}}}#Z(){const t=this.#u;if(!t)return;let e;try{e=t.length}catch{return}if(!Number.isSafeInteger(e)||e<0)return;const i=Math.min(e,$t),s=[];for(let o=0;o<i&&!this.#r&&!this.#l;o+=1){let n;try{n=t.key(o)}catch{continue}s.push(n)}for(const o of s){if(this.#r||this.#l)return;if(typeof o!="string"||!o.startsWith(j))continue;const n=o.slice(j.length);if(T.test(n))try{const l=t.getItem(o);if(l===null)continue;const a=D(g(l,2048),["code","expiresAt","schemaVersion","state"],"CALLBACK_ERROR");if(a.schemaVersion!==1||a.state!==n||!T.test(a.code))continue;k(a.expiresAt,"CALLBACK_ERROR")<=this.#s()&&t.removeItem(o)}catch{}}}}function Xt(r){return new zt(r)}function Ht(r,t={}){const e=(s,o)=>s!==0?Promise.reject(c("INVALID_REQUEST")):o(),i={connect(...s){return e(s.length,()=>r.execute("connect",void 0))},destroy(...s){return e(s.length,()=>r.destroy())},disconnect(...s){return e(s.length,()=>r.disconnect())},getSnapshot(...s){if(s.length!==0)throw c("INVALID_REQUEST");return r.getSnapshot()},openAccount(...s){return e(s.length,()=>r.execute("account",void 0))},subscribe(s,...o){if(o.length!==0)throw c("INVALID_REQUEST");return r.subscribe(s)}};for(const[s,o]of Object.entries(t))i[s]=function(l,...a){return a.length!==0?Promise.reject(c("INVALID_REQUEST")):r.execute(o,l)};return Object.freeze(i)}const Qt=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 Zt(r){let t;try{const e=Reflect.ownKeys(r);if(r===null||typeof r!="object"||Array.isArray(r)||Object.getPrototypeOf(r)!==Object.prototype||e.length!==1||e[0]!=="clientId")throw c("INVALID_REQUEST");t=Object.getOwnPropertyDescriptor(r,"clientId")}catch{throw c("INVALID_REQUEST")}if(!t?.enumerable||!("value"in t)||typeof t.value!="string")throw c("INVALID_REQUEST");if(!Qt.includes(t.value))throw c("INVALID_CLIENT");return t.value}const Gt=Object.freeze({account:Object.freeze({buildRequest:()=>xt({}),kind:"account",operation:"sdn.wallet.account.v1",parseResult:Nt}),connect:Object.freeze({buildRequest:()=>Ct({}),kind:"connect",operation:"sdn.wallet.connect.v1",parseResult:Pt})});function nt(r){if(arguments.length!==1)throw c("INVALID_REQUEST");const t=Zt(r),e=Xt({adapters:Gt,clientId:t});return Ht(e)}const ot="SDNWalletPublicClient";if(Object.prototype.hasOwnProperty.call(globalThis,ot))throw new Error("SDN wallet public client global already exists");function te(r){return arguments.length!==1?nt(...arguments):nt(r)}const ee=Object.freeze({create:te});Object.defineProperty(globalThis,ot,{configurable:!1,enumerable:!1,value:ee,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})})();
|