diff --git a/examples/email-auth/src/pages/index.tsx b/examples/email-auth/src/pages/index.tsx index 02c9969eb..b64e2a7ea 100644 --- a/examples/email-auth/src/pages/index.tsx +++ b/examples/email-auth/src/pages/index.tsx @@ -23,7 +23,6 @@ type AuthResponse = { type InjectCredentialsFormData = { walletName: string; authBundle: string; - // authenticatorName: string; }; type AuthFormData = { email: string; @@ -87,7 +86,7 @@ export default function AuthPage() { } try { - await iframeStamper.injectAuthBundle(data.authBundle); + await iframeStamper.injectCredentialBundle(data.authBundle); } catch (e) { const msg = `error while injecting bundle: ${e}`; console.error(msg); diff --git a/examples/email-recovery/src/pages/index.tsx b/examples/email-recovery/src/pages/index.tsx index be7105e58..625c6ebc2 100644 --- a/examples/email-recovery/src/pages/index.tsx +++ b/examples/email-recovery/src/pages/index.tsx @@ -87,7 +87,7 @@ export default function RecoveryPage() { } try { - await iframeStamper.injectRecoveryBundle(data.recoveryBundle); + await iframeStamper.injectCredentialBundle(data.recoveryBundle); } catch (e) { const msg = `error while injecting bundle: ${e}`; console.error(msg); diff --git a/packages/iframe-stamper/README.md b/packages/iframe-stamper/README.md index 5b0f45509..a413a9933 100644 --- a/packages/iframe-stamper/README.md +++ b/packages/iframe-stamper/README.md @@ -25,7 +25,7 @@ const iframeStamper = new IframeStamper({ const publicKey = await iframeStamper.init(); // Injects a new credential in the iframe -const injected = await iframeStamper.injectRecoveryBundle(recoveryBundle); +const injected = await iframeStamper.injectCredentialBundle(recoveryBundle); // New HTTP client able to sign with the credentials inside of the iframe const httpClient = new TurnkeyClient( @@ -75,7 +75,7 @@ const iframeStamper = new IframeStamper({ const publicKey = await iframeStamper.init(); // Injects a new credential in the iframe -const injected = await iframeStamper.injectAuthBundle(authBundle); +const injected = await iframeStamper.injectCredentialBundle(authBundle); // New HTTP client able to sign with the credentials inside of the iframe const httpClient = new TurnkeyClient( diff --git a/packages/iframe-stamper/src/index.ts b/packages/iframe-stamper/src/index.ts index 1a7100c4a..48733b0b2 100644 --- a/packages/iframe-stamper/src/index.ts +++ b/packages/iframe-stamper/src/index.ts @@ -8,18 +8,15 @@ export enum IframeEventType { // Event sent by the iframe to its parent to indicate readiness. // Value: the iframe public key PublicKeyReady = "PUBLIC_KEY_READY", - // Event sent by the parent to inject a recovery bundle into the iframe. + // Event sent by the parent to inject a credential bundle (for recovery or auth) into the iframe. // Value: the bundle to inject - InjectRecoveryBundle = "INJECT_RECOVERY_BUNDLE", + InjectCredentialBundle = "INJECT_CREDENTIAL_BUNDLE", // Event sent by the parent to inject a private key export bundle into the iframe. // Value: the bundle to inject InjectKeyExportBundle = "INJECT_KEY_EXPORT_BUNDLE", // Event sent by the parent to inject a wallet export bundle into the iframe. // Value: the bundle to inject InjectWalletExportBundle = "INJECT_WALLET_EXPORT_BUNDLE", - // Event sent by the parent to inject an auth bundle into the iframe. - // Value: the bundle to inject - InjectAuthBundle = "INJECT_AUTH_BUNDLE", // Event sent by the iframe to its parent when `InjectBundle` is successful // Value: true (boolean) BundleInjected = "BUNDLE_INJECTED", @@ -132,13 +129,13 @@ export class IframeStamper { * Function to inject a new credential into the iframe * The bundle should be encrypted to the iframe's initial public key * Encryption should be performed with HPKE (RFC 9180). - * This is used during recovery flows. + * This is used during recovery and auth flows. */ - async injectRecoveryBundle(bundle: string): Promise { + async injectCredentialBundle(bundle: string): Promise { return new Promise((resolve, reject) => { this.iframe.contentWindow?.postMessage( { - type: IframeEventType.InjectRecoveryBundle, + type: IframeEventType.InjectCredentialBundle, value: bundle, }, "*" @@ -236,42 +233,6 @@ export class IframeStamper { }); } - /** - * Function to inject a new credential into the iframe - * The bundle should be encrypted to the iframe's initial public key - * Encryption should be performed with HPKE (RFC 9180). - * This is used during auth flows. - */ - async injectAuthBundle(bundle: string): Promise { - return new Promise((resolve, reject) => { - this.iframe.contentWindow?.postMessage( - { - type: IframeEventType.InjectAuthBundle, - value: bundle, - }, - "*" - ); - - window.addEventListener( - "message", - (event) => { - if (event.origin !== this.iframeOrigin) { - // There might be other things going on in the window, for example: react dev tools, other extensions, etc. - // Instead of erroring out we simply return. Not our event! - return; - } - if (event.data?.type === IframeEventType.BundleInjected) { - resolve(event.data["value"]); - } - if (event.data?.type === IframeEventType.Error) { - reject(event.data["value"]); - } - }, - false - ); - }); - } - /** * Function to sign a payload with the underlying iframe */