@openfort/openfort-js 0.8.42 → 0.8.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sdk/src/evm/provider/eip6963.js +1 -1
- package/dist/cjs/sdk/src/iframe/iframeManager.js +1 -1
- package/dist/cjs/sdk/src/utils/crypto.js +1 -1
- package/dist/cjs/sdk/src/version.js +1 -1
- package/dist/sdk/src/evm/provider/eip6963.js +1 -1
- package/dist/sdk/src/iframe/iframeManager.js +1 -1
- package/dist/sdk/src/utils/crypto.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e={icon:'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="597.32 331.34 171.36 105.32" ><g><rect x="673.9" y="404.26" width="18.2" height="32.4" /><polygon points="768.68,331.36 768.68,331.36 768.68,331.34 610.78,331.34 610.78,331.36 597.32,331.36 597.32,436.64 615.52,436.64 615.52,349.54 750.48,349.54 750.48,436.64 768.68,436.64 " /><polygon points="732.16,367.79 633.83,367.79 633.83,370.19 633.79,370.19 633.79,436.64 651.99,436.64 651.99,385.99 713.9,385.99 713.9,436.64 732.09,436.64 732.09,385.99 732.16,385.99 " /></g></svg>',name:"Openfort",rdns:"xyz.openfort",uuid:crypto.randomUUID()};exports.announceProvider=function(e){if("undefined"==typeof window)return;const n=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(e)});window.dispatchEvent(n),window.addEventListener("eip6963:requestProvider",(()=>window.dispatchEvent(n)))},exports.openfortProviderInfo=e;
|
|
1
|
+
"use strict";const e={icon:'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="597.32 331.34 171.36 105.32" ><g><rect x="673.9" y="404.26" width="18.2" height="32.4" /><polygon points="768.68,331.36 768.68,331.36 768.68,331.34 610.78,331.34 610.78,331.36 597.32,331.36 597.32,436.64 615.52,436.64 615.52,349.54 750.48,349.54 750.48,436.64 768.68,436.64 " /><polygon points="732.16,367.79 633.83,367.79 633.83,370.19 633.79,370.19 633.79,436.64 651.99,436.64 651.99,385.99 713.9,385.99 713.9,436.64 732.09,436.64 732.09,385.99 732.16,385.99 " /></g></svg>',name:"Openfort",rdns:"xyz.openfort",uuid:require("../../utils/crypto.js").randomUUID()};exports.announceProvider=function(e){if("undefined"==typeof window)return;const n=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(e)});window.dispatchEvent(n),window.addEventListener("eip6963:requestProvider",(()=>window.dispatchEvent(n)))},exports.openfortProviderInfo=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../storage/istorage.js"),
|
|
1
|
+
"use strict";var e=require("../storage/istorage.js"),r=require("../storage/localStorage.js"),t=require("../utils/crypto.js"),i=require("./types.js");class o extends Error{constructor(){super("This embedded signer requires a password to be recovered")}}class s extends Error{constructor(){super("MissingProjectEntropyError")}}class n extends Error{constructor(){super("Wrong recovery password for this embedded signer")}}class a extends Error{constructor(){super("No response from iframe")}}class d extends Error{message;constructor(e){super(`Unknown response from iframe: ${e}`),this.message=e||""}}class c extends Error{constructor(){super("Invalid response from iframe")}}class h extends Error{constructor(){super("Not configured")}}exports.IframeManager=class{iframe;responses=new Map;storage;sdkConfiguration;constructor(e){this.sdkConfiguration=e,this.storage=new r.LocalStorage}async iframeSetup(){if(window.addEventListener){window.addEventListener("message",(e=>{const r=new URL(this.sdkConfiguration.iframeUrl).origin;if(new URL(e.origin).origin===r){const{data:r}=e;r.action&&(r.action===i.Event.PONG&&this.responses.set("FIRST",r),this.responses.set(r.uuid,r))}}));const e=document.getElementById("openfort-iframe");e&&document.body.removeChild(e);const r=document.createElement("iframe");r.style.display="none",r.id="openfort-iframe",document.body.appendChild(r),this.sdkConfiguration.shieldConfiguration?.debug?r.src=`${this.sdkConfiguration.iframeUrl}?debug=true`:r.src=this.sdkConfiguration.iframeUrl,this.iframe=r}else{if(!global.openfort)return;global.openfort.iframeListener((e=>{const r=new URL(this.sdkConfiguration.iframeUrl).origin;if(new URL(e.origin).origin===r){let{data:r}=e;"string"==typeof r&&(r=JSON.parse(r)),r.action&&this.responses.set(r.uuid,r)}})),this.iframe={contentWindow:{postMessage:e=>{global.openfort&&global.openfort.iframePostMessage(e)}}}}}isLoaded(){return void 0!==this.responses.get("FIRST")}async waitForIframeLoad(){this.iframe||await this.iframeSetup();const e=async()=>{if(!this.isLoaded()){const r=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(new i.PingRequest(t.randomUUID()),r),await new Promise((e=>{setTimeout(e,100)})),await e()}};await e()}responseConstructors={[i.Event.CONFIGURED]:i.ConfigureResponse,[i.Event.AUTHENTICATION_UPDATED]:i.UpdateAuthenticationResponse,[i.Event.CURRENT_DEVICE]:i.GetCurrentDeviceResponse,[i.Event.SIGNED]:i.SignResponse,[i.Event.CHAIN_SWITCHED]:i.SwitchChainResponse,[i.Event.LOGGED_OUT]:i.LogoutResponse,[i.Event.SET_RECOVERY_METHOD]:i.SetRecoveryMethodResponse,[i.Event.EXPORT]:i.ExportPrivateKeyResponse};waitForResponse(e){return new Promise(((r,t)=>{let u=0;const f=setInterval((()=>{u>100&&(clearInterval(f),t(new a)),u++;const g=this.responses.get(e);if(g){clearInterval(f),this.responses.delete(e);const a=this.responseConstructors[g.action];i.isErrorResponse(g)?(g.error===i.NOT_CONFIGURED_ERROR?t(new h):g.error===i.MISSING_USER_ENTROPY_ERROR?t(new o):g.error===i.MISSING_PROJECT_ENTROPY_ERROR?t(new s):g.error===i.INCORRECT_USER_ENTROPY_ERROR&&t(new n),t(new d(g.error))):a?r(g):t(new c)}}),100)}))}async configure(r){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");await this.waitForIframeLoad();const s={uuid:t.randomUUID(),action:i.Event.CONFIGURE,chainId:r.chainId,recovery:r.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration.shieldPublishableKey,accessToken:r.accessToken,playerID:r.playerID,thirdPartyProvider:r.thirdPartyProvider,thirdPartyTokenType:r.thirdPartyTokenType,encryptionKey:r.password,encryptionPart:this.sdkConfiguration?.shieldConfiguration?.shieldEncryptionKey??null,encryptionSession:r.recovery?.encryptionSession??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl},a=new URL(this.sdkConfiguration.iframeUrl).origin;let d;this.iframe?.contentWindow?.postMessage(s,a);try{d=await this.waitForResponse(s.uuid)}catch(r){throw(r instanceof n||r instanceof o)&&this.storage.remove(e.StorageKeys.SIGNER),r}return sessionStorage.setItem("iframe-version",d.version??"undefined"),d}async sign(e,r,o,s){await this.waitForIframeLoad();const n=t.randomUUID(),a={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},d=new i.SignRequest(n,r,o,s,a),c=new URL(this.sdkConfiguration.iframeUrl).origin;let u;this.iframe?.contentWindow?.postMessage(d,c);try{u=await this.waitForResponse(n)}catch(t){if(t instanceof h)return await this.configure(e),this.sign(e,r,o,s);throw t}return sessionStorage.setItem("iframe-version",u.version??"undefined"),u.signature}async switchChain(e,r){await this.waitForIframeLoad();const o=t.randomUUID(),s={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},n=new i.SwitchChainRequest(o,r,s),a=new URL(this.sdkConfiguration.iframeUrl).origin;let d;this.iframe?.contentWindow?.postMessage(n,a);try{d=await this.waitForResponse(o)}catch(t){if(t instanceof h)return await this.configure(e),this.switchChain(e,r);throw t}return sessionStorage.setItem("iframe-version",d.version??"undefined"),d}async export(e){await this.waitForIframeLoad();const r=t.randomUUID(),o={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},s=new i.ExportPrivateKeyRequest(r,o),n=new URL(this.sdkConfiguration.iframeUrl).origin;let a;this.iframe?.contentWindow?.postMessage(s,n);try{a=await this.waitForResponse(r)}catch(r){if(r instanceof h)return await this.configure(e),this.export(e);throw r}return sessionStorage.setItem("iframe-version",a.version??"undefined"),a.key}async setEmbeddedRecovery(e,r,o,s){await this.waitForIframeLoad();const n=t.randomUUID(),a={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},d=new i.SetRecoveryMethodRequest(n,r,o,s,a),c=new URL(this.sdkConfiguration.iframeUrl).origin;let u;this.iframe?.contentWindow?.postMessage(d,c);try{u=await this.waitForResponse(n)}catch(t){if(t instanceof h)return await this.configure(e),this.setEmbeddedRecovery(e,r,o,s);throw t}return sessionStorage.setItem("iframe-version",u.version??"undefined"),Promise.resolve()}async getCurrentUser(e){await this.waitForIframeLoad();const r=t.randomUUID(),o=new i.GetCurrentDeviceRequest(r,e),s=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(o,s);try{const e=await this.waitForResponse(r);return sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof h)return null;throw e}}async logout(){await this.waitForIframeLoad();const e=t.randomUUID(),r=new i.LogoutRequest(e),o=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(r,o),await this.waitForResponse(e)}async updateAuthentication(e,r,o){e.accessToken=r,o===i.ShieldAuthType.OPENFORT&&e.recovery&&(e.recovery.token=r),await this.waitForIframeLoad();const s=t.randomUUID(),n=new i.UpdateAuthenticationRequest(s,r),a=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(n,a);try{await this.waitForResponse(s)}catch(t){if(t instanceof h)return await this.configure(e),void await this.updateAuthentication(e,r,o);throw t}}},exports.InvalidResponseError=c,exports.MissingProjectEntropyError=s,exports.MissingRecoveryPasswordError=o,exports.NoResponseError=a,exports.NotConfiguredError=h,exports.UnknownResponseError=d,exports.WrongRecoveryPasswordError=n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("@noble/curves/secp256k1");var e=require("@noble/hashes/utils");function t(t){if(t instanceof Uint8Array)return t;const r=t.match(/^(0x|)((?:.{1,2})*)$/);if(!r)throw new Error("invalid hex string");return e.hexToBytes(r[2])}function r(e,{dir:t,size:r=32}={}){if(null===r)return e;const n=e.replace("0x","");if(n.length>2*r)throw new Error("Hex string is too long");return`0x${n["right"===t?"padEnd":"padStart"](2*r,"0")}`}function n(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function i(e){return n(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}class o extends Error{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`)}}function s(e,{size:t}){if(i(e)>t)throw new o({givenSize:i(e),maxSize:t})}function
|
|
1
|
+
"use strict";require("@noble/curves/secp256k1");var e=require("@noble/hashes/utils");function t(t){if(t instanceof Uint8Array)return t;const r=t.match(/^(0x|)((?:.{1,2})*)$/);if(!r)throw new Error("invalid hex string");return e.hexToBytes(r[2])}function r(e,{dir:t,size:r=32}={}){if(null===r)return e;const n=e.replace("0x","");if(n.length>2*r)throw new Error("Hex string is too long");return`0x${n["right"===t?"padEnd":"padStart"](2*r,"0")}`}function n(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function i(e){return n(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}class o extends Error{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`)}}function s(e,{size:t}){if(i(e)>t)throw new o({givenSize:i(e),maxSize:t})}function c(e,{dir:t="left"}={}){let r="string"==typeof e?e.replace("0x",""):e,n=0;for(let e=0;e<r.length-1&&"0"===r["left"===t?e:r.length-e-1].toString();e++)n++;return r="left"===t?r.slice(n):r.slice(0,r.length-n),"string"==typeof e?(1===r.length&&"right"===t&&(r=`${r}0`),`0x${r.length%2==1?`0${r}`:r}`):r}exports.SizeOverflowError=o,exports.assertSize=s,exports.hexToBytes=t,exports.hexToString=function(e,r={}){let n=t(e);return r.size&&(s(n,{size:r.size}),n=c(n,{dir:"right"})),(new TextDecoder).decode(n)},exports.isHex=n,exports.numberToHex=function(e,t={}){const{size:n}=t,i=BigInt(e);let o;if(n?o=BigInt(2)**(BigInt(n)*BigInt(8))-BigInt(1):"number"==typeof e&&(o=BigInt(Number.MAX_SAFE_INTEGER)),o&&i>o||i<0){throw new Error(`Value out of bounds: ${i}${"bigint"==typeof e?"n":""}`)}const s=`0x${i.toString(16)}`;return n?r(s,{size:n}):s},exports.padHex=r,exports.randomUUID=function(){const e=new Uint8Array(16);crypto.getRandomValues(e),e[6]=16*Math.floor(e[6]/16)+4,e[8]=64*Math.floor(e[8]/64)+128;const t=Array.from(e,(e=>e.toString(16).padStart(2,"0")));return[t.slice(0,4).join(""),t.slice(4,6).join(""),t.slice(6,8).join(""),t.slice(8,10).join(""),t.slice(10,16).join("")].join("-")},exports.sizeValue=i,exports.trim=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.8.
|
|
1
|
+
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.8.43";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
import{randomUUID as e}from"../../utils/crypto.js";const n={icon:'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="597.32 331.34 171.36 105.32" ><g><rect x="673.9" y="404.26" width="18.2" height="32.4" /><polygon points="768.68,331.36 768.68,331.36 768.68,331.34 610.78,331.34 610.78,331.36 597.32,331.36 597.32,436.64 615.52,436.64 615.52,349.54 750.48,349.54 750.48,436.64 768.68,436.64 " /><polygon points="732.16,367.79 633.83,367.79 633.83,370.19 633.79,370.19 633.79,436.64 651.99,436.64 651.99,385.99 713.9,385.99 713.9,436.64 732.09,436.64 732.09,385.99 732.16,385.99 " /></g></svg>',name:"Openfort",rdns:"xyz.openfort",uuid:e()};function t(e){if("undefined"==typeof window)return;const n=new CustomEvent("eip6963:announceProvider",{detail:Object.freeze(e)});window.dispatchEvent(n);window.addEventListener("eip6963:requestProvider",(()=>window.dispatchEvent(n)))}export{t as announceProvider,n as openfortProviderInfo};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{StorageKeys as e}from"../storage/istorage.js";import{LocalStorage as
|
|
1
|
+
import{StorageKeys as e}from"../storage/istorage.js";import{LocalStorage as i}from"../storage/localStorage.js";import{randomUUID as r}from"../utils/crypto.js";import{Event as t,ConfigureResponse as o,UpdateAuthenticationResponse as s,GetCurrentDeviceResponse as n,SignResponse as a,SwitchChainResponse as d,LogoutResponse as c,SetRecoveryMethodResponse as h,ExportPrivateKeyResponse as f,isErrorResponse as u,NOT_CONFIGURED_ERROR as g,MISSING_USER_ENTROPY_ERROR as w,MISSING_PROJECT_ENTROPY_ERROR as l,INCORRECT_USER_ENTROPY_ERROR as p,ShieldAuthType as m,PingRequest as y,SignRequest as k,SwitchChainRequest as C,ExportPrivateKeyRequest as v,SetRecoveryMethodRequest as U,GetCurrentDeviceRequest as b,LogoutRequest as P,UpdateAuthenticationRequest as T}from"./types.js";class R extends Error{constructor(){super("This embedded signer requires a password to be recovered")}}class I extends Error{constructor(){super("MissingProjectEntropyError")}}class E extends Error{constructor(){super("Wrong recovery password for this embedded signer")}}class L extends Error{constructor(){super("No response from iframe")}}class F extends Error{message;constructor(e){super(`Unknown response from iframe: ${e}`),this.message=e||""}}class S extends Error{constructor(){super("Invalid response from iframe")}}class K extends Error{constructor(){super("Not configured")}}class M{iframe;responses=new Map;storage;sdkConfiguration;constructor(e){this.sdkConfiguration=e,this.storage=new i}async iframeSetup(){if(window.addEventListener){window.addEventListener("message",(e=>{const i=new URL(this.sdkConfiguration.iframeUrl).origin;if(new URL(e.origin).origin===i){const{data:i}=e;i.action&&(i.action===t.PONG&&this.responses.set("FIRST",i),this.responses.set(i.uuid,i))}}));const e=document.getElementById("openfort-iframe");e&&document.body.removeChild(e);const i=document.createElement("iframe");i.style.display="none",i.id="openfort-iframe",document.body.appendChild(i),this.sdkConfiguration.shieldConfiguration?.debug?i.src=`${this.sdkConfiguration.iframeUrl}?debug=true`:i.src=this.sdkConfiguration.iframeUrl,this.iframe=i}else{if(!global.openfort)return;global.openfort.iframeListener((e=>{const i=new URL(this.sdkConfiguration.iframeUrl).origin;if(new URL(e.origin).origin===i){let{data:i}=e;"string"==typeof i&&(i=JSON.parse(i)),i.action&&this.responses.set(i.uuid,i)}})),this.iframe={contentWindow:{postMessage:e=>{global.openfort&&global.openfort.iframePostMessage(e)}}}}}isLoaded(){return void 0!==this.responses.get("FIRST")}async waitForIframeLoad(){this.iframe||await this.iframeSetup();const e=async()=>{if(!this.isLoaded()){const i=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(new y(r()),i),await new Promise((e=>{setTimeout(e,100)})),await e()}};await e()}responseConstructors={[t.CONFIGURED]:o,[t.AUTHENTICATION_UPDATED]:s,[t.CURRENT_DEVICE]:n,[t.SIGNED]:a,[t.CHAIN_SWITCHED]:d,[t.LOGGED_OUT]:c,[t.SET_RECOVERY_METHOD]:h,[t.EXPORT]:f};waitForResponse(e){return new Promise(((i,r)=>{let t=0;const o=setInterval((()=>{t>100&&(clearInterval(o),r(new L)),t++;const s=this.responses.get(e);if(s){clearInterval(o),this.responses.delete(e);const t=this.responseConstructors[s.action];u(s)?(s.error===g?r(new K):s.error===w?r(new R):s.error===l?r(new I):s.error===p&&r(new E),r(new F(s.error))):t?i(s):r(new S)}}),100)}))}async configure(i){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");await this.waitForIframeLoad();const o={uuid:r(),action:t.CONFIGURE,chainId:i.chainId,recovery:i.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration.shieldPublishableKey,accessToken:i.accessToken,playerID:i.playerID,thirdPartyProvider:i.thirdPartyProvider,thirdPartyTokenType:i.thirdPartyTokenType,encryptionKey:i.password,encryptionPart:this.sdkConfiguration?.shieldConfiguration?.shieldEncryptionKey??null,encryptionSession:i.recovery?.encryptionSession??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl},s=new URL(this.sdkConfiguration.iframeUrl).origin;let n;this.iframe?.contentWindow?.postMessage(o,s);try{n=await this.waitForResponse(o.uuid)}catch(i){throw(i instanceof E||i instanceof R)&&this.storage.remove(e.SIGNER),i}return sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async sign(e,i,t,o){await this.waitForIframeLoad();const s=r(),n={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},a=new k(s,i,t,o,n),d=new URL(this.sdkConfiguration.iframeUrl).origin;let c;this.iframe?.contentWindow?.postMessage(a,d);try{c=await this.waitForResponse(s)}catch(r){if(r instanceof K)return await this.configure(e),this.sign(e,i,t,o);throw r}return sessionStorage.setItem("iframe-version",c.version??"undefined"),c.signature}async switchChain(e,i){await this.waitForIframeLoad();const t=r(),o={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},s=new C(t,i,o),n=new URL(this.sdkConfiguration.iframeUrl).origin;let a;this.iframe?.contentWindow?.postMessage(s,n);try{a=await this.waitForResponse(t)}catch(r){if(r instanceof K)return await this.configure(e),this.switchChain(e,i);throw r}return sessionStorage.setItem("iframe-version",a.version??"undefined"),a}async export(e){await this.waitForIframeLoad();const i=r(),t={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},o=new v(i,t),s=new URL(this.sdkConfiguration.iframeUrl).origin;let n;this.iframe?.contentWindow?.postMessage(o,s);try{n=await this.waitForResponse(i)}catch(i){if(i instanceof K)return await this.configure(e),this.export(e);throw i}return sessionStorage.setItem("iframe-version",n.version??"undefined"),n.key}async setEmbeddedRecovery(e,i,t,o){await this.waitForIframeLoad();const s=r(),n={thirdPartyProvider:e.thirdPartyProvider??void 0,thirdPartyTokenType:e.thirdPartyTokenType??void 0,token:e.accessToken??void 0,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl},a=new U(s,i,t,o,n),d=new URL(this.sdkConfiguration.iframeUrl).origin;let c;this.iframe?.contentWindow?.postMessage(a,d);try{c=await this.waitForResponse(s)}catch(r){if(r instanceof K)return await this.configure(e),this.setEmbeddedRecovery(e,i,t,o);throw r}return sessionStorage.setItem("iframe-version",c.version??"undefined"),Promise.resolve()}async getCurrentUser(e){await this.waitForIframeLoad();const i=r(),t=new b(i,e),o=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(t,o);try{const e=await this.waitForResponse(i);return sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof K)return null;throw e}}async logout(){await this.waitForIframeLoad();const e=r(),i=new P(e),t=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(i,t),await this.waitForResponse(e)}async updateAuthentication(e,i,t){e.accessToken=i,t===m.OPENFORT&&e.recovery&&(e.recovery.token=i),await this.waitForIframeLoad();const o=r(),s=new T(o,i),n=new URL(this.sdkConfiguration.iframeUrl).origin;this.iframe?.contentWindow?.postMessage(s,n);try{await this.waitForResponse(o)}catch(r){if(r instanceof K)return await this.configure(e),void await this.updateAuthentication(e,i,t);throw r}}}export{M as IframeManager,S as InvalidResponseError,I as MissingProjectEntropyError,R as MissingRecoveryPasswordError,L as NoResponseError,K as NotConfiguredError,F as UnknownResponseError,E as WrongRecoveryPasswordError};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@noble/curves/secp256k1";import{hexToBytes as t}from"@noble/hashes/utils";function e(e){if(e instanceof Uint8Array)return e;const n=e.match(/^(0x|)((?:.{1,2})*)$/);if(!n)throw new Error("invalid hex string");return t(n[2])}function
|
|
1
|
+
import"@noble/curves/secp256k1";import{hexToBytes as t}from"@noble/hashes/utils";function e(){const t=new Uint8Array(16);crypto.getRandomValues(t),t[6]=16*Math.floor(t[6]/16)+4,t[8]=64*Math.floor(t[8]/64)+128;const e=Array.from(t,(t=>t.toString(16).padStart(2,"0")));return[e.slice(0,4).join(""),e.slice(4,6).join(""),e.slice(6,8).join(""),e.slice(8,10).join(""),e.slice(10,16).join("")].join("-")}function n(e){if(e instanceof Uint8Array)return e;const n=e.match(/^(0x|)((?:.{1,2})*)$/);if(!n)throw new Error("invalid hex string");return t(n[2])}function i(t,{dir:e,size:n=32}={}){if(null===n)return t;const i=t.replace("0x","");if(i.length>2*n)throw new Error("Hex string is too long");return`0x${i["right"===e?"padEnd":"padStart"](2*n,"0")}`}function r(t,e={}){const{size:n}=e,r=BigInt(t);let o;if(n?o=BigInt(2)**(BigInt(n)*BigInt(8))-BigInt(1):"number"==typeof t&&(o=BigInt(Number.MAX_SAFE_INTEGER)),o&&r>o||r<0){throw new Error(`Value out of bounds: ${r}${"bigint"==typeof t?"n":""}`)}const s=`0x${r.toString(16)}`;return n?i(s,{size:n}):s}function o(t,{strict:e=!0}={}){return!!t&&("string"==typeof t&&(e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")))}function s(t){return o(t,{strict:!1})?Math.ceil((t.length-2)/2):t.length}class c extends Error{constructor({givenSize:t,maxSize:e}){super(`Size cannot exceed ${e} bytes. Given size: ${t} bytes.`)}}function l(t,{size:e}){if(s(t)>e)throw new c({givenSize:s(t),maxSize:e})}function f(t,{dir:e="left"}={}){let n="string"==typeof t?t.replace("0x",""):t,i=0;for(let t=0;t<n.length-1&&"0"===n["left"===e?t:n.length-t-1].toString();t++)i++;return n="left"===e?n.slice(i):n.slice(0,n.length-i),"string"==typeof t?(1===n.length&&"right"===e&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}function g(t,e={}){let i=n(t);return e.size&&(l(i,{size:e.size}),i=f(i,{dir:"right"})),(new TextDecoder).decode(i)}export{c as SizeOverflowError,l as assertSize,n as hexToBytes,g as hexToString,o as isHex,r as numberToHex,i as padHex,e as randomUUID,s as sizeValue,f as trim};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.8.
|
|
1
|
+
const o="0.8.43",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
package/package.json
CHANGED