### Account Setup Quickstart Source: https://docs.turnkey.com/llms.txt Guide for setting up your Turnkey organization and generating API keypairs. ```APIDOC ## Account Setup Quickstart ### Description This quickstart guide covers the initial steps for setting up your organization within Turnkey and generating the necessary API keypair to access the platform's full capabilities. ### Method Not applicable (quickstart guide). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example Not applicable. ### Response Not applicable. ``` -------------------------------- ### Delegated Access Setup Examples Source: https://docs.turnkey.com/llms-full.txt Provides examples for setting up delegated access control using Turnkey. ```javascript // Example usage for with-delegated // This snippet would demonstrate the configuration and usage of Turnkey's delegated access features. ``` -------------------------------- ### Install Dependencies for Polymarket Builder Example Source: https://docs.turnkey.com/llms-full.txt Install project dependencies using npm after cloning the repository. ```bash npm install ``` -------------------------------- ### Embedded Wallets Quickstart Source: https://docs.turnkey.com/llms.txt Guide to integrating Turnkey's Embedded Wallets for custom and secure wallet experiences. ```APIDOC ## Embedded Wallets Quickstart ### Description This guide explains how to integrate Turnkey's Embedded Wallets, allowing for secure, custom wallet experiences directly within your product. It emphasizes features like advanced security, seamless authentication, and flexible UX options, enabling developers to focus on product development while Turnkey manages private key complexities. ### Method Not applicable (quickstart guide). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example Not applicable. ### Response Not applicable. ``` -------------------------------- ### SDKs - Using the CLI Source: https://docs.turnkey.com/llms.txt A quickstart guide for using Turnkey's Command Line Interface (CLI) for onboarding, API key management, wallet creation, and transaction signing. ```APIDOC ## Using the CLI ### Description This quickstart will guide you through Turnkey’s onboarding, adding an API key, creating a wallet, and signing your first Ethereum transaction using the CLI. ### Installation ```bash npm install -g @turnkey/cli ``` ### Usage - **Onboarding**: `turnkey onboard` - **Add API Key**: `turnkey apikey add` - **Create Wallet**: `turnkey wallet create --name MyWallet` - **Sign Transaction**: `turnkey eth sign --wallet MyWallet --to 0x... --value 1000` ``` -------------------------------- ### Company Wallets Quickstart Source: https://docs.turnkey.com/llms.txt Guide to implementing Turnkey's Company Wallets for secure, programmatic signing workflows. ```APIDOC ## Company Wallets Quickstart ### Description This guide introduces Turnkey's Company Wallets, enabling secure, programmatic signing workflows directly within applications. It highlights features such as customizable policies, multi-party approvals, and broad blockchain support for automating complex signing operations. ### Method Not applicable (quickstart guide). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example Not applicable. ### Response Not applicable. ``` -------------------------------- ### Install @turnkey/react-wallet-kit Source: https://docs.turnkey.com/sdks/react/migrating-sdk-react Install the new SDK using pnpm or npm. ```bash pnpm add @turnkey/react-wallet-kit # or npm i @turnkey/react-wallet-kit ``` -------------------------------- ### Install @turnkey/sdk-browser Source: https://docs.turnkey.com/sdks/typescript-frontend/legacy Installation commands for the legacy browser SDK. ```bash npm install @turnkey/sdk-browser ``` ```bash yarn add @turnkey/sdk-browser ``` -------------------------------- ### Get Wallet Request Examples Source: https://docs.turnkey.com/api-reference/queries/get-wallet Implementation examples for retrieving wallet details using cURL and the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/query/get_wallet \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "walletId": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getWallet({ organizationId: " (Unique identifier for a given organization.)", walletId: " (Unique identifier for a given wallet.)" }); ``` -------------------------------- ### Get Latest Boot Proof using JavaScript SDK Source: https://docs.turnkey.com/api-reference/queries/get-the-latest-boot-proof-for-an-app This JavaScript example demonstrates how to use the Turnkey SDK to fetch the latest boot proof. Ensure your API keys and organization ID are set as environment variables. ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getLatestBootProof({ organizationId: " (Unique identifier for a given Organization.)", appName: " (Name of enclave app.)" }); ``` -------------------------------- ### Turnkey Verifiable Cloud Quickstart Source: https://docs.turnkey.com/llms.txt Guide to running code in isolated, verifiable secure enclaves using Turnkey's infrastructure. ```APIDOC ## Turnkey Verifiable Cloud Quickstart ### Description This quickstart guide explains how to leverage Turnkey's Verifiable Cloud to run code within isolated, verifiable secure enclaves, powered by Turnkey's trusted infrastructure. ### Method Not applicable (quickstart guide). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example Not applicable. ### Response Not applicable. ``` -------------------------------- ### Install Turnkey Core SDK with yarn Source: https://docs.turnkey.com/llms-full.txt Install the Turnkey Core SDK using yarn. Ensure you have yarn installed to use this command. ```bash yarn add @turnkey/core ``` -------------------------------- ### Clone Polymarket Safe Builder Example Source: https://docs.turnkey.com/llms-full.txt Clone the Polymarket Safe Builder example repository to get started with gasless trading and order attribution. ```bash git clone https://github.com/Polymarket/turnkey-safe-builder-example.git ``` -------------------------------- ### Install Turnkey SDKs Source: https://docs.turnkey.com/cookbook/base-builder-codes Install the necessary Turnkey SDKs for viem integration. ```bash npm i @turnkey/viem @turnkey/sdk-server ``` ```bash pnpm add @turnkey/viem @turnkey/sdk-server ``` ```bash yarn add @turnkey/viem @turnkey/sdk-server ``` -------------------------------- ### Initialize WalletStamper with Solana Source: https://docs.turnkey.com/sdks/advanced/wallet-stamper Example implementation of a Solana wallet and initialization of the TurnkeyClient. ```js // Import the dependencies for the Solana import { Keypair } from "@solana/web3.js"; import { decodeUTF8 } from "tweetnacl-util"; import nacl from "tweetnacl"; import { TurnkeyClient } from "@turnkey/http"; import { WalletStamper, SolanaWalletInterface } from "@turnkey/wallet-stamper"; class SolanaWallet implements SolanaWalletInterface { keypair = Keypair.fromSecretKey(SOLANA_PRIVATE_KEY); type = "solana" as const; async signMessage(message: string): Promise { const messageBytes = decodeUTF8(message); const signature = nacl.sign.detached(messageBytes, this.keypair.secretKey); return Buffer.from(signature).toString("hex"); } recoverPublicKey(): string { // Convert the base24 encoded Solana wallet public key (the one displayed in the wallet) // into the ed25519 decoded public key const ed25519PublicKey = Buffer.from( this.keypair.publicKey.toBuffer(), ).toString("hex"); return ed25519PublicKey; } } // Instantiate the WalletStamper with the SolanaWallet const walletStamper = new WalletStamper(new SolanaWallet()); // Instantiate the TurnkeyClient with the WalletStamper const client = new TurnkeyClient({ baseUrl: BASE_URL }, walletStamper); // You're now ready to make requests to Turnkey's API 🎉 ``` -------------------------------- ### Get API Key Request Examples Source: https://docs.turnkey.com/api-reference/queries/get-api-key Examples for querying the get_api_key endpoint using cURL and the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/query/get_api_key \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "apiKeyId": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getApiKey({ organizationId: " (Unique identifier for a given organization.)", apiKeyId: " (Unique identifier for a given API key.)" }); ``` -------------------------------- ### EIP-1193 Provider Integration Example Source: https://docs.turnkey.com/networks/ethereum This example demonstrates how to use Turnkey's EIP-1193 provider for seamless integration with EVM chains. Ensure you have the necessary Turnkey SDK and dependencies installed. ```typescript import { TurnkeySigner } from "@turnkey/ethers"; import { ethers } from "ethers"; const turnkeySigner = new TurnkeySigner({ apiPublicKey: "YOUR_API_PUBLIC_KEY", apiSecretKey: "YOUR_API_SECRET_KEY", }); const provider = new ethers.BrowserProvider(turnkeySigner); // Now you can use the provider to interact with the blockchain const signer = await provider.getSigner(); console.log("Signer address:", await signer.getAddress()); ``` -------------------------------- ### Import Wallet Request Examples Source: https://docs.turnkey.com/api-reference/activities/import-wallet Examples showing how to initiate a wallet import request using cURL and the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/submit/import_wallet \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "type": "ACTIVITY_TYPE_IMPORT_WALLET", "timestampMs": " (e.g. 1746736509954)", "organizationId": " (Your Organization ID)", "parameters": { "userId": "", "walletName": "", "encryptedBundle": "", "accounts": [ { "curve": "", "pathFormat": "", "path": "", "addressFormat": "" } ] } }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().importWallet({ userId: " (The ID of the User importing a Wallet.)", walletName: " (Human-readable name for a Wallet.)", encryptedBundle: " (Bundle containing a wallet mnemonic encrypted to the enclave's target public key.)", accounts: [{ // A list of wallet Accounts., curve: "" // curve field, pathFormat: "" // pathFormat field, path: " (Path used to generate a wallet Account.)", addressFormat: "" // addressFormat field, }] }); ``` -------------------------------- ### Get API Key Response Example Source: https://docs.turnkey.com/api-reference/queries/get-api-key A sample JSON response returned by the get_api_key endpoint. ```json { "apiKey": { "credential": { "publicKey": "", "type": "" }, "apiKeyId": "", "apiKeyName": "" ``` -------------------------------- ### Install Turnkey and Viem dependencies Source: https://docs.turnkey.com/cookbook/0x Install the required packages for Turnkey integration and Ethereum interaction. ```bash npm install @turnkey/react-wallet-kit @turnkey/viem viem wagmi ``` -------------------------------- ### Get Authenticator Request Source: https://docs.turnkey.com/llms-full.txt Examples for querying authenticator details using cURL and the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/query/get_authenticator \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "authenticatorId": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getAuthenticator({ organizationId: " (Unique identifier for a given organization.)", authenticatorId: " (Unique identifier for a given authenticator.)" }); ``` -------------------------------- ### Install @turnkey/core SDK Source: https://docs.turnkey.com/sdks/typescript-frontend/getting-started Install the Turnkey Core SDK using your preferred package manager. ```bash npm install @turnkey/core ``` ```bash pnpm add @turnkey/core ``` ```bash yarn add @turnkey/core ``` -------------------------------- ### Get Private Key Response Example Source: https://docs.turnkey.com/api-reference/queries/get-private-key This is an example JSON response from the Turnkey API when successfully retrieving private key details. It includes identifiers, public key, associated addresses, and metadata like creation and update timestamps. ```json { "privateKey": { "privateKeyId": "", "publicKey": "", "privateKeyName": "", "curve": "", "addresses": [ { "format": "", "address": "" } ], "privateKeyTags": [ "" ], "createdAt": { "seconds": "", "nanos": "" }, "updatedAt": { "seconds": "", "nanos": "" }, "exported": "", "imported": "" } } ``` -------------------------------- ### Initialize Turnkey Client and Perform OTP Login Source: https://docs.turnkey.com/api-reference/activities/login-with-otp Demonstrates how to initialize the Turnkey client with API credentials and perform an OTP login. Ensure environment variables for API keys and organization ID are set. ```javascript const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().otpLogin({ verificationToken: " (Signed Verification Token containing a unique id, expiry, verification type, contact)", publicKey: " (Client-side public key generated by the user, used as the session public key upon successful login)", clientSignature: { // clientSignature field, publicKey: " (The public component of a cryptographic key pair used to create the signature.)", scheme: "", // scheme field, message: " (The message that was signed.)", signature: " (The cryptographic signature over the message.)" }, expirationSeconds: " (Expiration window (in seconds) indicating how long the Session is valid for. If not provided, a default of 15 minutes will be used.)", invalidateExisting: true // Invalidate all other previously generated Login sessions }); ``` -------------------------------- ### Sign Transactions with Viem Source: https://docs.turnkey.com/llms.txt Example of signing transactions using Viem in a server context. Ensure Viem is installed and configured. ```typescript import { createWalletClient, http, privateKeyToAccount } from "viem"; import { mainnet } from "viem/chains"; // Assume you have a Turnkey client instance and a wallet private key const privateKey = "0x..."; // Your wallet's private key const account = privateKeyToAccount(privateKey); const client = createWalletClient({ account, chain: mainnet, transport: http("YOUR_RPC_URL"), }); const transaction = { to: "0xRecipientAddress", value: BigInt(100000000000000000n), // 0.1 ETH gas: BigInt(21000), }; async function signTransaction() { const signedTx = await client.signTransaction(transaction); console.log("Signed Transaction:", signedTx); } signTransaction(); ``` -------------------------------- ### Run development server Source: https://docs.turnkey.com/cookbook/polymarket-builders Start the local development server. ```bash npm run dev ``` -------------------------------- ### Sign Transactions with Ethers Source: https://docs.turnkey.com/llms.txt Example of signing transactions using Ethers in a server context. Ensure Ethers is installed and configured. ```typescript import { ethers } from "ethers"; // Assume you have a Turnkey client instance and a wallet private key const turnkeyClient = new TurnkeyClient({ baseUrl: "https://api.turnkey.com", }); const privateKey = "0x..."; // Your wallet's private key const provider = new ethers.providers.JsonRpcProvider("YOUR_RPC_URL"); const wallet = new ethers.Wallet(privateKey, provider); const transaction = { to: "0xRecipientAddress", value: ethers.utils.parseEther("0.1"), gasLimit: 21000, }; async function signTransaction() { const signedTx = await wallet.signTransaction(transaction); console.log("Signed Transaction:", signedTx); } signTransaction(); ``` -------------------------------- ### Get Send Transaction Status Request Source: https://docs.turnkey.com/llms-full.txt Examples of how to query the transaction status using cURL or the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/query/get_send_transaction_status \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "sendTransactionStatusId": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getSendTransactionStatus({ organizationId: " (Unique identifier for a given organization.)", sendTransactionStatusId: " (The unique identifier of a send transaction request.)" }); ``` -------------------------------- ### Examples Overview Source: https://docs.turnkey.com/llms.txt Overview of Turnkey's flexible infrastructure and low-level primitives. ```APIDOC ## Examples Overview ### Description This section provides an overview of Turnkey's infrastructure, emphasizing its flexibility and the use of low-level primitives to avoid developer blockers and enable the creation of novel applications. ### Method Not applicable (overview). ### Endpoint Not applicable. ### Parameters Not applicable. ### Request Example Not applicable. ### Response Not applicable. ``` -------------------------------- ### Get Smart Contract Interface Request Source: https://docs.turnkey.com/api-reference/queries/get-smart-contract-interface Examples for querying the smart contract interface using cURL or the Turnkey JavaScript SDK. ```bash curl --request POST \ --url https://api.turnkey.com/public/v1/query/get_smart_contract_interface \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "smartContractInterfaceId": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getSmartContractInterface({ organizationId: " (Unique identifier for a given organization.)", smartContractInterfaceId: " (Unique identifier for a given smart contract interface.)" }); ``` -------------------------------- ### Install dependencies Source: https://docs.turnkey.com/cookbook/jupiter Install the required Turnkey and Solana packages for the integration. ```bash npm install @turnkey/react-wallet-kit @turnkey/solana @solana/web3.js ``` -------------------------------- ### Sign Transactions with Solana Source: https://docs.turnkey.com/llms.txt Example of signing transactions using the Solana SDK in a server context. Ensure necessary Solana packages are installed. ```typescript import { Connection, Keypair, SystemProgram, Transaction } from "@solana/web3.js"; // Assume you have a Turnkey client instance and a wallet private key const privateKey = "..."; // Your wallet's private key (base58 encoded) const keypair = Keypair.fromSecretKey(Uint8Array.from(Buffer.from(privateKey, "base64"))); const connection = new Connection("YOUR_SOLANA_RPC_URL"); async function signTransaction() { const fromPubkey = keypair.publicKey; const toPubkey = SystemProgram.programId; // Example recipient const lamports = 1000; const transaction = new Transaction().add( SystemProgram.transfer({ fromPubkey, toPubkey, lamports, }) ); transaction.feePayer = fromPubkey; const signedTx = await keypair.signTransaction(transaction); console.log("Signed Transaction:", signedTx.serialize().toString("base64")); } signTransaction(); ``` -------------------------------- ### Create Turnkey API Client and Get Wallets Source: https://docs.turnkey.com/sdks/javascript-server Obtain an API client instance to make authenticated requests to the Turnkey API. This example demonstrates fetching wallets. ```javascript const apiClient = turnkey.apiClient(); const walletsResponse = await apiClient.getWallets(); // this will sign the request with the configured api credentials ``` -------------------------------- ### Install @turnkey/sdk-react Source: https://docs.turnkey.com/sdks/react/legacy Commands to install the legacy SDK using common package managers. ```bash npm install @turnkey/sdk-react ``` ```bash yarn add @turnkey/sdk-react ``` -------------------------------- ### Initialize Turnkey SDK and Wallet Client Source: https://docs.turnkey.com/embedded-wallets/code-examples/wallet-auth Initializes the Turnkey SDK with configuration and sets up a wallet client for Ethereum using the EthereumWallet interface. Ensure `turnkeyConfig` is properly defined. ```typescript import { Turnkey } from '@turnkey/sdk-browser'; import { EthereumWallet } from '@turnkey/wallet-stamper'; import { turnkeyConfig } from './config'; // Initialize the Turnkey SDK with the config object defined above const turnkey = new Turnkey(turnkeyConfig); // Initialize the Wallet Client with the EthereumWallet interface const walletClient = turnkey.walletClient(new EthereumWallet()); ``` -------------------------------- ### Get Wallet Account API Request Source: https://docs.turnkey.com/llms-full.txt Use these examples to fetch wallet account details. Ensure the X-Stamp header is correctly generated according to Turnkey authorization requirements. ```bash --url https://api.turnkey.com/public/v1/query/get_wallet_account \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ --header "X-Stamp: (see Authorizations)" \ --data '{ "organizationId": "", "walletId": "", "address": "", "path": "" }' ``` ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getWalletAccount({ organizationId: " (Unique identifier for a given organization.)", walletId: " (Unique identifier for a given wallet.)", address: " (Address corresponding to a wallet account.)", path: " (Path corresponding to a wallet account.)" }); ``` -------------------------------- ### Install @turnkey/sdk-server with NPM Source: https://docs.turnkey.com/sdks/javascript-server Install the server SDK package using NPM. This is the first step to integrate Turnkey server-side functionality. ```bash npm install @turnkey/sdk-server ``` -------------------------------- ### Response Example for Get Authenticator Source: https://docs.turnkey.com/api-reference/queries/get-authenticator This JSON structure represents a successful response when retrieving authenticator details. It includes information about the authenticator's transports, credential details, and timestamps. ```json { "authenticator": { "transports": [ "" ], "attestationType": "", "aaguid": "", "credentialId": "", "model": "", "credential": { "publicKey": "", "type": "" }, "authenticatorId": "", "authenticatorName": "", "createdAt": { "seconds": "", "nanos": "" }, "updatedAt": { "seconds": "", "nanos": "" } } } ``` -------------------------------- ### Get Boot Proof using Turnkey SDK (JavaScript) Source: https://docs.turnkey.com/llms-full.txt This JavaScript snippet demonstrates how to use the Turnkey SDK to fetch a boot proof. Initialize the client with your API credentials and organization ID, then call the `getBootProof` method with the required parameters. ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getBootProof({ organizationId: " (Unique identifier for a given Organization.)", ephemeralKey: " (Hex encoded ephemeral public key.)" }); ``` -------------------------------- ### Configure Turnkey Swift SDK for Organization Source: https://docs.turnkey.com/llms.txt Learn how to configure the Turnkey Swift SDK, including organization setup and basic app configuration. Swift Package Manager installation is covered. ```swift import TurnkeyClient // Initialize Turnkey client with organization ID and API keys let turnkey = TurnkeyClient(organizationId: "YOUR_ORGANIZATION_ID", apiPublicKey: "YOUR_API_PUBLIC_KEY", privateKey: "YOUR_PRIVATE_KEY") // Use the turnkey instance for further operations ``` -------------------------------- ### List App Proofs using JavaScript SDK Source: https://docs.turnkey.com/api-reference/queries/list-app-proofs-for-an-activity This JavaScript example demonstrates how to use the Turnkey SDK to fetch application proofs. Initialize the Turnkey client with your API credentials and organization ID, then call the getAppProofs method with the required parameters. ```javascript import { Turnkey } from "@turnkey/sdk-server"; const turnkeyClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPublicKey: process.env.API_PUBLIC_KEY!, apiPrivateKey: process.env.API_PRIVATE_KEY!, defaultOrganizationId: process.env.ORGANIZATION_ID!, }); const response = await turnkeyClient.apiClient().getAppProofs({ organizationId: " (Unique identifier for a given Organization.)", activityId: " (Unique identifier for a given activity.)" }); ``` -------------------------------- ### Implement Delegated Access Setup Flow with Turnkey Source: https://docs.turnkey.com/concepts/policies/delegated-access-backend This snippet shows the complete process of setting up delegated access. It includes initializing the Turnkey client, creating a sub-organization with a delegated access user, defining a policy to control access, and updating the root quorum. Ensure you have your Turnkey API keys and organization ID configured in your environment variables. ```javascript import { Turnkey } from "@turnkey/sdk-server"; import dotenv from "dotenv"; dotenv.config(); // Initialize the Turnkey Server Client on the server-side const turnkeyServer = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPrivateKey: process.env.TURNKEY_API_PRIVATE_KEY, apiPublicKey: process.env.TURNKEY_API_PUBLIC_KEY, defaultOrganizationId: process.env.TURNKEY_ORGANIZATION_ID, }).apiClient(); // To create an API key programmatically check https://github.com/tkhq/sdk/blob/main/examples/kitchen-sink/src/sdk-server/createApiKey.ts const publicKey = ""; const curveType = "API_KEY_CURVE_P256"; // this is the default const apiKeys = [ { apiKeyName: "Delegated - API Key", publicKey, curveType, }, ]; // STEP 1: Create a sub org with End User and Delegated Access user in Root Quorum const subOrg = await turnkeyClient.createSubOrganization({ organizationId: process.env.TURNKEY_ORGANIZATION_ID!, subOrganizationName: `Sub Org - With Delegated Access User`, rootUsers: [ { userName: "Delegated Access User", apiKeys, authenticators: [], oauthProviders: [] }, { userName: "End User", userEmail: "", apiKeys: [], authenticators: [], oauthProviders: [] }, ], rootQuorumThreshold: 1, wallet: { "walletName": "Default ETH Wallet", "accounts": [ { "curve": "CURVE_SECP256K1", "pathFormat": "PATH_FORMAT_BIP32", "path": "m/44'/60'/0'/0/0", "addressFormat": "ADDRESS_FORMAT_ETHEREUM" } ] }, }); console.log("sub-org id:", subOrg.subOrganizationId); // Initializing the Turkey client used by the Delegated Access User // Notice the subOrganizationId created above const turnkeyDelegatedAccessClient = new Turnkey({ apiBaseUrl: "https://api.turnkey.com", apiPrivateKey: process.env.DELEGATED_API_PRIVATE_KEY!, apiPublicKey: process.env.DELEGATED_API_PUBLIC_KEY!, defaultOrganizationId: subOrg.subOrganizationId, }).apiClient(); // STEP 2: Create a policy allowing the Delegated access user to send Ethereum transactions to a particular address // Creating a policy for the Delegated account const delegated_userid = subOrg.rootUserIds[0]; const policyName = "Allow Delegated Account to sign transactions to specific address"; const effect = "EFFECT_ALLOW"; const consensus = `approvers.any(user, user.id == '${delegated_userid}')`; const condition = `eth.tx.to == '${process.env.RECIPIENT_ADDRESS}'`; const notes = ""; const { policyId } = await turnkeyDelegated.createPolicy({ policyName, condition, consensus, effect, notes, }); // STEP 3: Update the root quorum to only include the End User, removing the Delegated Access user // Remove the Delegated Account from the root quorum const RootQuorum = await turnkeyDelegated.updateRootQuorum({ threshold: 1, userIds: [subOrg.rootUserIds[1]], // retain the end user }); ``` -------------------------------- ### Quick Authentication with useTurnkey Hook Source: https://docs.turnkey.com/sdks/react/auth Use the `handleLogin` function from the `useTurnkey` hook for a simple login or signup flow that displays a modal with configured authentication methods. This is the easiest way to get started. ```tsx "use client"; import { useTurnkey } from "@turnkey/react-wallet-kit"; function LoginButton() { const { handleLogin } = useTurnkey(); return ; } export default function Home() { return ( ); } ``` -------------------------------- ### Initialize and Use Solana WalletStamper with TurnkeyClient Source: https://docs.turnkey.com/llms-full.txt Demonstrates initializing the WalletStamper with a SolanaWallet and then using it with the TurnkeyClient to make API requests. Ensure SOLANA_PRIVATE_KEY and BASE_URL are defined. ```javascript // Import the dependencies for the Solana import { Keypair } from "@solana/web3.js"; import { decodeUTF8 } from "tweetnacl-util"; import nacl from "tweetnacl"; import { TurnkeyClient } from "@turnkey/http"; import { WalletStamper, SolanaWalletInterface } from "@turnkey/wallet-stamper"; class SolanaWallet implements SolanaWalletInterface { keypair = Keypair.fromSecretKey(SOLANA_PRIVATE_KEY); type = "solana" as const; async signMessage(message: string): Promise { const messageBytes = decodeUTF8(message); const signature = nacl.sign.detached(messageBytes, this.keypair.secretKey); return Buffer.from(signature).toString("hex"); } recoverPublicKey(): string { // Convert the base24 encoded Solana wallet public key (the one displayed in the wallet) // into the ed25519 decoded public key const ed25519PublicKey = Buffer.from( this.keypair.publicKey.toBuffer(), ).toString("hex"); return ed25519PublicKey; } } // Instantiate the WalletStamper with the SolanaWallet const walletStamper = new WalletStamper(new SolanaWallet()); // Instantiate the TurnkeyClient with the WalletStamper const client = new TurnkeyClient({ baseUrl: BASE_URL }, walletStamper); // You're now ready to make requests to Turnkey's API 🎉 ```