Skip to content

Commit

Permalink
docs: adds Turnkey to the list of signing providers (#35)
Browse files Browse the repository at this point in the history
* docs: adds Turnkey to the list of signing providers

* docs: uses LocalAccountSigner instead of WalletClientSigner
  • Loading branch information
MaxBlaushild authored Sep 29, 2023
1 parent 744664a commit edd3b8e
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions site/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
83 changes: 83 additions & 0 deletions site/smart-accounts/signers/turnkey.md
Original file line number Diff line number Diff line change
@@ -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

:::
49 changes: 49 additions & 0 deletions site/snippets/turnkey.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit edd3b8e

Please sign in to comment.