Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turnkey/sdk-browser

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turnkey/sdk-browser

Javascript Browser SDK

  • 1.10.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
increased by9.32%
Maintainers
0
Weekly downloads
 
Created
Source

@turnkey/sdk-browser

npm

A SDK client with browser-specific abstractions for interacting with Turnkey API. Also includes @turnkey/http, a lower-level, fully typed HTTP client.

Turnkey API documentation lives here: https://docs.turnkey.com.

Getting started

$ npm install @turnkey/sdk-browser

Initialize

import { Turnkey } from "@turnkey/sdk-browser";

const turnkey = new Turnkey({
  apiBaseUrl: "https://api.turnkey.com",
  defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID,
  // Optional: Your relying party ID - for use with Passkey authentication
  rpId: process.env.TURNKEY_RP_ID,
});

Turnkey Clients

Passkey

The Passkey client allows for authentication to Turnkey's API using Passkeys.

const passkeyClient = turnkey.passkeyClient();

// User will be prompted to login with their passkey
await passkeyClient.login();

// Make authenticated requests to Turnkey API, such as listing user's wallets
const walletsResponse = await passkeyClient.getWallets();
Iframe

The Iframe client can be initialized to interact with Turnkey's hosted iframes for sensitive operations. The iframeContainer parameter is required, and should be a reference to the DOM element that will host the iframe. The iframeUrl is the URL of the iframe you wish to interact with.

The example below demonstrates how to initialize the Iframe client for use with Email Auth by passing in https://auth.turnkey.com as the iframeUrl.

const iframeClient = await turnkey.iframeClient({
  // The container element that will host the iframe
  iframeContainer: document.getElementById("<iframe container id>"),
  iframeUrl: "https://auth.turnkey.com",
});

const injectedResponse = await iframeClient.injectCredentialBundle(
  "<Credential from Email>"
);
if (injectedResponse) {
  await iframeClient.getWallets();
}
IFrame URLs:
FlowURL
Email Authauth.turnkey.com
Email Recoveryrecovery.turnkey.com
Import Walletimport.turnkey.com
Export Walletexport.turnkey.com
Wallet

The Wallet client is designed for using your Solana or EVM wallet to stamp and approve activity requests for Turnkey's API. This stamping process leverages the wallet's signature to authenticate requests.

The example below showcases how to use an injected Ethereum wallet to stamp requests to Turnkey's API. The user will be prompted to sign a message containing the activity request payload to be sent to Turnkey.

import {
  createWalletClient,
  custom,
  recoverPublicKey,
  hashMessage,
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";

import { WalletStamper, EthereumWallet } from "@turnkey/wallet-stamper";

const walletClient = turnkey.walletClient(new EthereumWallet());

// Make authenticated requests to Turnkey API, such as listing user's wallets
// User will be prompted to sign a message to authenticate the request
const walletsResponse = await walletClient.getWallets();

Helpers

@turnkey/sdk-browser provides TurnkeySDKBrowserClient, which offers wrappers around commonly used Turnkey activities, such as creating new wallets and wallet accounts.

Keywords

FAQs

Package last updated on 09 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc