diff --git a/site/.vitepress/config.ts b/site/.vitepress/config.ts index b62c0a3510..5d2d678d0e 100644 --- a/site/.vitepress/config.ts +++ b/site/.vitepress/config.ts @@ -48,6 +48,7 @@ export default defineConfig({ link: "/overview", items: [ { text: "Magic.Link", link: "/magic-link" }, + { text: "Turnkey", link: "/turnkey"}, { text: "Web3Auth", link: "/web3auth" }, { text: "Externally Owned Account", link: "/eoa" }, { text: "Using Your Own", link: "/using-your-own" }, diff --git a/site/smart-accounts/signers/turnkey.md b/site/smart-accounts/signers/turnkey.md new file mode 100644 index 0000000000..0d58d4476a --- /dev/null +++ b/site/smart-accounts/signers/turnkey.md @@ -0,0 +1,83 @@ +--- +outline: deep +head: + - - meta + - property: og:title + content: Turnkey + - - meta + - name: description + content: Guide to use Turnkey as a signer + - - meta + - property: og:description + content: Guide to use Turnkey as a signer +--- + +# Turnkey + +[Turnkey](https://turnkey.com) provides simple APIs to securely manage your private keys. With Turnkey, users are able to spin up thousands of wallets and sign millions of transactions, all without compromising on security. + +## Integration + +### Sign up for a Turnkey Account + +Signing up for a Turnkey Account is quick and easy. You can follow our [quickstart guide](https://docs.turnkey.com/getting-started/quickstart) to create a your first organization, API key and private key in minutes. + +### Install the SDK + +::: code-group + +```bash [npm] +npm i -s @turnkey/api-key-stamper +npm i -s @turnkey/http +npm i -s @turnkey/viem +``` + +```bash [yarn] +yarn add @turnkey/api-key-stamper +yarn add @turnkey/http +yarn add @turnkey/viem +``` + +::: + +### Create a SmartAccountSigner + +Next, setup the Turnkey sdk and create a `SmartAccountSigner`: + +<<< @/snippets/turnkey.ts + +### Use it with LightAccount + +Let's see it in action with `aa-alchemy` and `LightSmartContractAccount` from `aa-accounts`: +::: code-group + +```ts [example.ts] +import { AlchemyProvider } from "@alchemy/aa-alchemy"; +import { LightSmartContractAccount } from "@alchemy/aa-accounts"; +import { sepolia } from "viem/chains"; +import { newTurnkeySigner } from "./turnkey"; + +async function main() { + const owner = await newTurnkeySigner(); + const chain = sepolia; + const provider = new AlchemyProvider({ + apiKey: "ALCHEMY_API_KEY", + chain, + entryPointAddress: "0x...", + }).connect( + (rpcClient) => + new LightSmartContractAccount({ + entryPointAddress: "0x...", + chain: rpcClient.chain, + owner, + factoryAddress: "0x...", + rpcClient, + }) + ); +} + +``` + +<<< @/snippets/turnkey.ts + +::: diff --git a/site/snippets/turnkey.ts b/site/snippets/turnkey.ts new file mode 100644 index 0000000000..0b527cd94e --- /dev/null +++ b/site/snippets/turnkey.ts @@ -0,0 +1,49 @@ +import { createAccount } from "@turnkey/viem"; +import { TurnkeyClient } from "@turnkey/http"; +import { ApiKeyStamper } from "@turnkey/api-key-stamper"; +import { createWalletClient, http } from "viem"; +import { sepolia } from "viem/chains"; +import { SmartAccountSigner, LocalAccountSigner } from "@alchemy/aa-core" + +export async function newTurnkeySigner () { + const turnkeyClient = new TurnkeyClient( + { + /* + Configurable, but you will likely use "https://api.turnkey.com". + */ + baseUrl: process.env.TURNKEY_BASE_URL!, + }, + new ApiKeyStamper({ + /* + You will generate these values as part of our quickstart guide: + + https://docs.turnkey.com/getting-started/quickstart + + They are what the signer will use to authenticate requests to the Turnkey.com. + */ + apiPublicKey: process.env.TURNKEY_API_PUBLIC_KEY!, + apiPrivateKey: process.env.TURNKEY_API_PRIVATE_KEY!, + }) + ); + + const turnkeyAccount = await createAccount({ + client: turnkeyClient, + /* + You can pull this from the top right widget in the Turnkey dashboard. + The quickstart guide details how to do this. + */ + organizationId: process.env.TURNKEY_ORGANIZATION_ID!, + /* + This value should be the ID of the private key that you want to own + the light smart contract. Similarly pulled from the dashboard and + documented in the quickstart guide. + */ + privateKeyId: process.env.TURNKEY_PRIVATE_KEY_ID!, + }); + + const turnkeySigner: SmartAccountSigner = new LocalAccountSigner( + turnkeyAccount + ); + + return turnkeySigner; +}