@turnkey/iframe-stamper
This package contains functions to stamp a Turnkey request through credentials contained in an iframe. It is meant to be used with @turnkey/http
to build flows. To stamp the request, use the Recovery and Auth flows to request and inject a credential bundle.
Usage:
Recovery and Auth
import { IframeStamper } from "@turnkey/iframe-stamper";
import { TurnkeyClient } from "@turnkey/http";
const TurnkeyIframeContainerId = "turnkey-iframe-container";
const TurnkeyIframeElementId = "turnkey-iframe";
const iframeStamper = new IframeStamper({
iframeUrl: process.env.AUTH_IFRAME_URL!,
iframeContainer: document.getElementById(TurnkeyIframeContainerId),
iframeElementId: TurnkeyIframeElementId,
});
const publicKey = await iframeStamper.init();
const injected = await iframeStamper.injectCredentialBundle(credentialBundle);
const httpClient = new TurnkeyClient(
{ baseUrl: "https://api.turnkey.com" },
iframeStamper
);
Key or Wallet Export
import { IframeStamper } from "@turnkey/iframe-stamper";
import { TurnkeyClient } from "@turnkey/http";
const TurnkeyIframeContainerId = "turnkey-iframe-container";
const TurnkeyIframeElementId = "turnkey-iframe";
const iframeStamper = new IframeStamper({
iframeUrl: process.env.EXPORT_IFRAME_URL!,
iframeContainer: document.getElementById(TurnkeyIframeContainerId),
iframeElementId: TurnkeyIframeElementId,
});
const publicKey = await iframeStamper.init();
const injected = await iframeStamper.injectWalletExportBundle(exportBundle);
if (injected !== true) {
throw new Error("unexpected error while injecting export bundle");
}
setIframeDisplay("block");
Key or Wallet Import
import { IframeStamper } from "@turnkey/iframe-stamper";
import { TurnkeyClient } from "@turnkey/http";
const TurnkeyIframeContainerId = "turnkey-iframe-container";
const TurnkeyIframeElementId = "turnkey-iframe";
const iframeStamper = new IframeStamper({
iframeUrl: process.env.IMPORT_IFRAME_URL!,
iframeContainer: document.getElementById(TurnkeyIframeContainerId),
iframeElementId: TurnkeyIframeElementId,
});
await iframeStamper.init();
const injected = await iframeStamper.injectImportBundle(importBundle);
if (injected !== true) {
throw new Error("unexpected error while injecting import bundle");
}
setIframeDisplay("block");
const encryptedBundle = await iframeStamper.extractWalletEncryptedBundle();