Skip to content

tkhq/sdk

Repository files navigation

Turnkey SDK

js-build

Overview

The Turnkey SDK includes functionality to interact with Turnkey in various contexts and ecosystems. It consists of three main NPM package groups.

The diagram below helps visualize the packages in our SDK organized by the functionality they expose.

homepage screenshot

Primary Turnkey Web SDK Packages

The following packages expose the main functionality required to build Turnkey-powered applications. Each package exposes functions, and/or client classes with methods that manage the process of authenticating requests to the Turnkey API in the contexts of a generic browser environment or react client environment, or a server environment.

While these higher level packages are the main points of reference to be used while designing and building Turnkey applications, they wrap other packages with lower level functionality which we also expose separately for those who would like to explore them for more specialized use cases. These packages are listed and described below in the Advanced Functionality SDK Packages section.

Our main web SDK packages are as follows:

Package Description NPM Changelog Docs
@turnkey/sdk-browser The @turnkey/sdk-browser package exposes functionality that lets developers build browser based applications that interact with the Turnkey API with different types of authentication. It consists of different clients that enable requests to the API to be authenticated via different auth methods like user sessions, passkeys and iFrames. It also contains methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests. npm CHANGELOG Docs
@turnkey/sdk-server The @turnkey/sdk-server package exposes functionality that lets developers build server-side functionality for applications that interact with the Turnkey API with different types of authentication – allowing applications to authenticate users, manage sessions, and perform organizational operations securely and efficiently. It consists of an API Client and API Proxies that enable requests to the Turnkey API to be authenticated with the appropriate credentials. Specifically, the API Client manages requests signed by the user's authentication details, and the API proxies handle requests signed by the parent organization's authentication details. Use this package to handle server-side interactions for applications that interact with the Turnkey API. npm CHANGELOG Docs
@turnkey/sdk-react The @turnkey/sdk-react package wraps the functionality from the @turnkey/sdk-browser package to allow developers to build react based applications that interact with the Turnkey API with different types of authentication. It allows developers to use the same clients exposed in @turnkey/sdk-browser that enable requests to the API to be authenticated via different auth methods like user sessions, passkey and iFrames. It also contains the same methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests. Use this package when you're building React-based frontend applications that interact with the Turnkey API. npm CHANGELOG Docs

The diagram below helps visualize how each package can be used to devlop the appropriate service in your Turnkey Powered Application, and how Turnkey requests would flow between those services.

homepage screenshot

Chain/Ecosystem-Specific Signing SDK Packages

The following packages contain chain or ecosystem specific signers that take some of our Primary Turnkey Web SDK Packages (usually @turnkey/sdk-browser or @turnkey/sdk-server) and add additional support based on the signing process or transaction structure relevant to that specific chain or ecosystem.

Package NPM Description Changelog
@turnkey/ethers npm Turnkey Signer for Ethers CHANGELOG
@turnkey/viem npm Turnkey Signer for Viem CHANGELOG
@turnkey/cosmjs npm Turnkey Signer for CosmJS CHANGELOG
@turnkey/solana npm Turnkey Signer for Solana CHANGELOG
@turnkey/eip-1193-provider npm Turnkey-compatible EIP-1193 Provider CHANGELOG

Advanced Functionality SDK Packages

For those with more specialized use cases, Turnkey exposes it's lower level-libraries stamping and encryption libraries to be used directly. Note: for most use-cases, these libraries are not meant to be used directly and we encourage working on designing your application mainlyusing our Primary Turnkey Web SDK Packages along with our Chain and Ecosystem Specific SDK Packages as per your use case!

Request Stamping

Package NPM Description Changelog Docs
@turnkey/http npm Lower-level, fully typed HTTP client for interacting with Turnkey API CHANGELOG Docs
@turnkey/api-key-stamper npm Provide API key signatures over Turnkey requests CHANGELOG Docs
@turnkey/iframe-stamper npm Provide API key signatures over Turnkey requests within iframe contexts CHANGELOG Docs
@turnkey/webauthn-stamper npm Provide Webauthn signatures over Turnkey requests CHANGELOG Docs
@turnkey/wallet-stamper npm Provide wallet signatures over Turnkey requests CHANGELOG Docs
@turnkey/sdk-react-native-passkey-stamper npm Provide Passkey signatures over Turnkey requests in a React Native context CHANGELOG Docs

Utilities

Package NPM Description Changelog
@turnkey/encoding npm Encoding and decoding utilities, primarily for internal usage CHANGELOG
@turnkey/crypto npm Cryptographic utilities for P256 keys, encryption, and decryption CHANGELOG

Code Examples

Instant examples (powered by Stackblitz)

The following code examples have been loaded into Stackblitz web environments so you can test them out immediately

Example Description Stackblitz Link
email-auth-local-storage A NextJS app demonstrating a complete email auth flow using a locally stored target embedded key Test it out on Stackblitz!
with-eth-passkey-signers A NextJS app powering users to create suborgs and sign messages via Viem or Ethers Test it out on Stackblitz!
with-solana Create a new Solana address, then sign and broadcast a transaction on Solana's devnet Test it out on Stackblitz!
with-solana-passkeys A NextJS app powering users to create suborgs, sign messages, and create transactions sponsored by the parent org using @turnkey/solana Test it out on Stackblitz!

Other Code Examples

The below examples will require a local installation of node.js. Follow the specific instructions in the respective README's of each examples to run them!

Example Description
demo-consumer-wallet A minimal consumer wallet app powered by Turnkey and WalletConnect
demo-passkey-wallet A minimal consumer wallet app powered by Turnkey and passkeys
demo-ethers-passkeys A NextJS app that demonstrates how to use @turnkey/ethers to build a passkey-powered application
demo-viem-passkeys A NextJS app that demonstrates how to use @turnkey/viem to build a passkey-powered application
passkeyapp A React Native + Expo app powered by Turnkey and passkeys
deployer Compile and deploy a smart contract
email-auth A NextJS app demonstrating a complete email auth flow using Turnkey iframes
email-recovery A NextJS app demonstrating a complete email recovery flow using Turnkey iframes
wallet-import-export A NextJS app demonstrating complete wallet import and export flows
rebalancer A demo application which showcases an example of how to use Turnkey for managing multiple types of keys & users
sweeper Sweep funds from one address to a different address
trading-runner A sample application demonstrating a trading operation, using various private keys, users, and policies, powered by Uniswap
with-ethers Create a new Ethereum address, then sign and broadcast a transaction using the Ethers signer with Infura
with-viem Sign and broadcast a transaction using the Turnkey Custom Account and Infura
with-cosmjs Create a new Cosmos address, then sign and broadcast a transaction on Celestia testnet using the CosmJS signer
with-bitcoin Create a new wallet, derive a BTC address, create, sign, and broadcast a transaction using BitcoinJS and other external APIs
with-gnosis Create new Ethereum addresses, configure a 3/3 Gnosis safe, and create + execute a transaction from it
with-uniswap Sign and broadcast a Uniswap v3 trade using the Ethers signer with Infura
with-nonce-manager Create a new Ethereum address, then sign and broadcast multiple transactions in a sequential or optimistic manner
with-offline Sign a Turnkey request in offline context
with-federated-passkeys A NextJS app that demonstrates how to use Turnkey to build a federated, webauthn powered authentication flow
with-eip-1193-provider A NextJS app that demonstrates how to use Turnkey the @turnkey/eip-1193-provider in your app
with-wallet-stamper A NextJS app that demonstrates how to use Turnkey the @turnkey/wallet-stamper in your app

Demos built with Turnkey

Demo Consumer Wallet (code)

A minimal consumer wallet app powered by Turnkey. Behind the scenes, it uses @turnkey/ethers for signing and WalletConnect (v1) for accessing dapps.

with-uniswap.mp4

See https://github.com/tkhq/demo-consumer-wallet for the code.

Demo Passkey Wallet (code, live link)

A wallet application showing how users can register and authenticate using passkeys. This demo uses the Turnkey API to create a new Turnkey Sub-Organization for each user, create a testnet Ethereum address and send a transaction on Sepolia (ETH testnet).

homepage screenshot

See https://wallet.tx.xyz (and https://github.com/tkhq/demo-passkey-wallet for the code).

Demo Ethers Passkeys (code)

A simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/ethers signer, using passkeys.

homepage screenshot

See https://github.com/tkhq/demo-ethers-passkeys for the code.

Demo Viem Passkeys (code)

A similar, simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/viem signer, using passkeys.

homepage screenshot

See https://github.com/tkhq/demo-viem-passkeys for the code.

React Native Passkey App (code)

A simple React Native app that demonstrates sign up and sign in with passkeys, as well as Email Auth support.

passkeyapp_demo.mp4

See https://github.com/tkhq/passkeyapp for the code.