hd-wallet-ui 2.0.21 → 2.0.27
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/LICENSE +190 -0
- package/README.md +101 -123
- package/data/common-passwords-sdn-v1.source.json +12 -0
- package/data/common-passwords-sdn-v1.txt +10000 -0
- package/dist/browser/sdn-wallet-callback.js +1 -0
- package/dist/browser/sdn-wallet-public-client.js +1 -0
- package/dist/browser/wallet-callback.html +6 -0
- package/dist/client/asset-review.d.ts +8 -0
- package/dist/client/asset-review.js +1570 -0
- package/dist/client/callback.d.ts +13 -0
- package/dist/client/callback.js +29 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +1379 -0
- package/dist/client/sdn.d.ts +8 -0
- package/dist/client/sdn.js +1542 -0
- package/dist/client/style.css +32 -0
- package/dist/client/types.d.ts +278 -0
- package/dist/compat/index.d.ts +26 -0
- package/dist/compat/index.js +62 -0
- package/dist/wallet-origin/index.d.ts +21 -0
- package/dist/wallet-origin/index.js +4607 -0
- package/dist/wallet-origin-host/assets/wallet-origin.43cf84e0eba17742309357ec6bc2c544736e155ffd5d76d5024408e998500a57.wasm +0 -0
- package/dist/wallet-origin-host/assets/wallet-origin.4c9455f1a2618948e203f720485add9d8ebf77b5542b41f933594afcfbb34361.css +1 -0
- package/dist/wallet-origin-host/assets/wallet-origin.aedc355452e665e16c0f72a6597602873378dbc39d4cbf6104621c07579347e0.js +12463 -0
- package/dist/wallet-origin-host/index.html +10 -0
- package/dist/wallet-origin-host/integrity.json +1 -0
- package/package.json +46 -18
- package/src/address-derivation.js +0 -514
- package/src/app.js +0 -6008
- package/src/blockchain-trust.js +0 -752
- package/src/clipboard.js +0 -44
- package/src/constants.js +0 -66
- package/src/hash.js +0 -9
- package/src/lib.js +0 -66
- package/src/template.js +0 -626
- package/src/trust-ui.js +0 -745
- package/src/wallet-storage.js +0 -773
- package/styles/main.css +0 -6220
- package/styles/widget.css +0 -6212
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){"use strict";const l="Wallet return could not be completed. Close this page and try Login again.",h=/^#code=([0-9a-f]{64})&state=([0-9a-f]{64})$/u;function a(){throw new Error(l)}function w(t,e,o,c){let n;try{n=t.hash;const g=typeof t.pathname=="string"&&t.pathname.startsWith("/")?t.pathname:"/",S=typeof t.search=="string"&&t.search.startsWith("?")?t.search:"";o.replaceState(null,"",`${g}${S}`)}catch{a()}const r=h.exec(n);r||a();const[,f,i]=r,m=new Date(Date.now()+12e4).toISOString(),y=`sdn.wallet.callback.v1:${i}`,u=JSON.stringify({schemaVersion:1,code:f,state:i,expiresAt:m});try{e.setItem(y,u)}catch{a()}try{c()}catch{}}const d="Wallet return could not be completed. Close this page and try Login again.";function s(){window.document?.body&&(window.document.body.textContent=d)}function p(){const t=typeof window.location?.pathname=="string"&&window.location.pathname.startsWith("/")?window.location.pathname:"/",e=typeof window.location?.search=="string"&&window.location.search.startsWith("?")?window.location.search:"";window.history.replaceState(null,"",`${t}${e}`)}if(window.top!==window){try{p()}catch{}s()}else{let t=!1;const e=()=>{if(!t){t=!0;try{window.close()}catch{}}};try{const o={setItem(c,n){window.localStorage.setItem(c,n)}};w(window.location,o,window.history,e)}catch{s()}}})();
|
|
@@ -0,0 +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})})();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<meta charset="utf-8">
|
|
3
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'">
|
|
4
|
+
<meta name="referrer" content="no-referrer">
|
|
5
|
+
<title>Wallet return</title>
|
|
6
|
+
<script defer src="./sdn-wallet-callback.js" integrity="sha384-UZG2zFMk46nuXFtMDyh5Rgfsai9CJXgmqvWILzXVbKJfdbSvg+7GRavCRgLXL5xy" crossorigin="anonymous"></script>
|