JavaScript Browser
Overview
The @turnkey/sdk-browser
package enables developers to build browser-based applications that interact with the Turnkey API using multiple authentication methods.
It includes:
indexedDbClient
: The recommended client for authentication and session creation using secure, unextractable P-256 keys stored in the browser’s IndexedDB.passkeyClient
: For passkey registration and signing flows.iframeClient
: Used for secure credential injection and import/export operations.walletClient
: For signing with external wallets like MetaMask.
If you’re building with React, check out our @turnkey/sdk-react
package.
Installation
Initialization
Authentication
loginWithPasskey
Creates a session for a user authenticated with a passkey. The session is stored in localStorage
, and signing operations are done with an unextractable keypair stored in IndexedDB.
loginWithBundle
Used to authenticate a user with a credential bundle (e.g. from Email Auth). Must be used from an iframeClient
.
loginWithSession
Logs in using a session string (JWT) that was created elsewhere (e.g. server action). Only valid on indexedDbClient
.
loginWithWallet
Uses a Web3 wallet to authenticate the user and store a read-write session.
refreshSession
Refreshes the current session and extends its expiration time. The correct publicKey
must be provided for read-write sessions.
IndexedDbClient
The indexedDbClient
is the recommended way to manage secure keys for session-based authentication.
init
Initializes and stores an unextractable P-256 keypair in the browser.
getPublicKey
Returns the base64url-encoded public key of the stored keypair.
clear
Removes all key material from IndexedDB.
resetKeyPair
Deletes and regenerates the stored keypair.
IframeClient
Primarily used for secure credential injection and key export/import.
injectCredentialBundle
Injects a read-write session credential bundle into the iframe.
injectWalletExportBundle
injectKeyExportBundle
injectImportBundle
extractWalletEncryptedBundle
extractKeyEncryptedBundle
getEmbeddedPublicKey
initEmbeddedKey
clearEmbeddedKey
PasskeyClient
createUserPasskey
Registers a new passkey using WebAuthn.
WalletClient
getPublicKey
getWalletInterface
Session Management
getSession
Returns the active session if it exists and hasn’t expired.
getRawSession
Returns the raw JWT string if a valid session exists.
logout
Clears all stored session and client data.