Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add live getter for iframe targetEmbeddedKey #533

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-chicken-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@turnkey/iframe-stamper": minor
---

Add `getLivePublicKey()` async function to get the public key of the live embedded key within the iframe
11 changes: 11 additions & 0 deletions packages/iframe-stamper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export enum IframeEventType {
// Event sent by the parent to establish secure communication via MessageChannel API.
// Value: MessageChannel port
TurnkeyInitMessageChannel = "TURNKEY_INIT_MESSAGE_CHANNEL",
// Event sent by the parent to get the target embedded key's public key.
// Value: public key
EmbeddedKey = "EMBEDDED_KEY",
// Event sent by the iframe to communicate an error
// Value: serialized error
Error = "ERROR",
Expand Down Expand Up @@ -272,6 +275,14 @@ export class IframeStamper {
return this.iframePublicKey;
}

/**
* Returns the public key, or `null` if the underlying iframe isn't properly initialized.
* This differs from the above in that it reaches out to the iframe to see if an embedded key exists.
*/
async getLivePublicKey(): Promise<string | null> {
return this.createRequest<string | null>(IframeEventType.EmbeddedKey);
}

/**
* Generic function to abstract away request creation
* @param type
Expand Down
Loading