-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: adds Turnkey to the list of signing providers (#35)
* docs: adds Turnkey to the list of signing providers * docs: uses LocalAccountSigner instead of WalletClientSigner
- Loading branch information
1 parent
744664a
commit edd3b8e
Showing
3 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |