diff --git a/src/consent.ts b/src/consent.ts index 1a57ac1..c5eea60 100644 --- a/src/consent.ts +++ b/src/consent.ts @@ -22,6 +22,8 @@ export default class Consent { enabled: boolean; }; + flowConfig: string; + publicKey: string; isLoggedIn: boolean; @@ -56,6 +58,7 @@ export default class Consent { enabled: false, scopes: scope, }; + this.flowConfig = "normal"; this.publicKey = publicKey; this.communicationMux = consentStream; this.provider = provider; diff --git a/src/embed.ts b/src/embed.ts index a0d66d6..fcb3a71 100644 --- a/src/embed.ts +++ b/src/embed.ts @@ -162,6 +162,8 @@ class Upbond { }; }; + flowConfig: string; + private loginHint = ""; private useWalletConnect: boolean; @@ -226,6 +228,7 @@ class Upbond { origin: "", }, }, + flowConfig = "normal", }: IUpbondEmbedParams = {}): Promise { // Send WARNING for deprecated buildEnvs // Give message to use others instead @@ -305,6 +308,7 @@ class Upbond { log.setDefaultLevel(logLevel); this.consentConfiguration = consentConfiguration; + this.flowConfig = flowConfig; const upbondIframeUrl = new URL(torusUrl); if (upbondIframeUrl.pathname.endsWith("/")) upbondIframeUrl.pathname += "popup"; @@ -373,6 +377,7 @@ class Upbond { redirectUrl: dappRedirectUri, }, consentConfiguration: this.consentConfiguration, + flowConfig, }, }); }; @@ -642,6 +647,47 @@ class Upbond { }); } + getTkey(message?: string) { + return new Promise((resolve, reject) => { + if (this.isLoggedIn) { + const tkeyAccessStream = this.communicationMux.getStream("tkey_access") as Substream; + tkeyAccessStream.write({ name: "tkey_access_request" }); + const tkeyAccessHandler = (chunk) => { + const { + name, + data: { approved, payload, rejected, newRequest }, + } = chunk; + if (name === "tkey_access_response") { + if (approved) { + resolve(payload); + } else if (rejected) { + reject(new Error("User rejected the request")); + } else if (newRequest) { + const tkeyInfoStream = this.communicationMux.getStream("tkey") as Substream; + const tkeyInfoHandler = (handlerChunk) => { + if (handlerChunk.name === "tkey_response") { + if (handlerChunk.data.approved) { + resolve(handlerChunk.data.payload); + } else { + reject(new Error("User rejected the request")); + } + } + }; + handleStream(tkeyInfoStream, "data", tkeyInfoHandler); + const preopenInstanceId = getPreopenInstanceId(); + this._handleWindow(preopenInstanceId, { + target: "_blank", + features: FEATURES_PROVIDER_CHANGE_WINDOW, + }); + tkeyInfoStream.write({ name: "tkey_request", data: { message, preopenInstanceId } }); + } + } + }; + handleStream(tkeyAccessStream, "data", tkeyAccessHandler); + } else reject(new Error("User has not logged in yet")); + }); + } + initiateTopup(provider: PAYMENT_PROVIDER_TYPE, params: PaymentParams): Promise { return new Promise((resolve, reject) => { if (this.isInitialized) { diff --git a/src/interfaces.ts b/src/interfaces.ts index 49f0514..b33e7de 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -850,6 +850,8 @@ export interface IUpbondEmbedParams { origin: string; }; }; + + flowConfig?: "normal" | "fastlogin"; } export interface UnvalidatedJsonRpcRequest {