Skip to content

Commit

Permalink
docs: dfns new signer (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
avarobinson committed Dec 12, 2023
1 parent cb462d9 commit 33141b0
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 15 deletions.
1 change: 1 addition & 0 deletions site/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default defineConfig({
{ text: "Capsule", link: "/capsule" },
{ text: "Lit Protocol", link: "/lit" },
{ text: "Particle Network", link: "/particle-network" },
{ text: "Dfns", link: "/dfns" },
{ text: "Externally Owned Account (EOA)", link: "/eoa" },
{ text: "Using Your Own", link: "/custom-signer" },
],
Expand Down
2 changes: 1 addition & 1 deletion site/overview/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To learn how to deploy a `LightAccount`, see [Light Account](/smart-accounts/acc

### Signers

A Signer is responsible for securely managing the private key and signing transaction requests on the smart account. Account Kit supports many popular wallet signers including [Magic](/smart-accounts/signers/guides/magic), [web3auth](/smart-accounts/signers/guides/web3auth), [Turnkey](/smart-accounts/signers/guides/turnkey), [Privy](/smart-accounts/signers/guides/privy), [Dynamic](/smart-accounts/signers/guides/dynamic), [Fireblocks](/smart-accounts/signers/guides/fireblocks), [Portal](/smart-accounts/signers/guides/portal), [Capsule](/smart-accounts/signers/guides/capsule) and [Lit Protocol](/smart-accounts/signers/guides/lit). It also supports self-custodial wallets like MetaMask or Ledger.
A Signer is responsible for securely managing the private key and signing transaction requests on the smart account. Account Kit supports many popular wallet signers. It also supports self-custodial wallets like MetaMask or Ledger.

To get started with a Signer, read the doc: [How to Choose a Signer](/smart-accounts/signers/choosing-a-signer).

Expand Down
4 changes: 2 additions & 2 deletions site/overview/why-account-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ Streamline your sign up flow with simple web2 login options supported by Account
- Self-custodial wallets like MetaMask or Ledger
- and more

Account Kit integrates all the leading wallet Signers with bespoke integration guides for [Magic](/smart-accounts/signers/guides/magic), [web3auth](/smart-accounts/signers/guides/web3auth), [Turnkey](/smart-accounts/signers/guides/turnkey), [Privy](/smart-accounts/signers/guides/privy), [Dynamic](/smart-accounts/signers/guides/dynamic), [Fireblocks](/smart-accounts/signers/guides/fireblocks), [Portal](/smart-accounts/signers/guides/portal), [Capsule](/smart-accounts/signers/guides/capsule) and [Lit Protocol](/smart-accounts/signers/guides/lit). Account Kit even supports self-custodial wallets like MetaMask or Ledger. Users can even change their Signer later via Account Kit’s [ownership transfer](/tutorials/transferring-ownership) functionality.
Account Kit integrates all the leading wallet Signers with integration guides that you can find [here](/smart-accounts/signers/choosing-a-signer). Account Kit even supports self-custodial wallets like MetaMask or Ledger. Users can even change their Signer later via Account Kit’s [ownership transfer](/tutorials/transferring-ownership) functionality.

Learn [how to choose the right Signer for your use case in this doc](/smart-accounts/signers/choosing-a-signer).
Learn [how to choose and integrate the right Signer for your use case in this doc](/smart-accounts/signers/choosing-a-signer).

## Sponsor gas

Expand Down
13 changes: 1 addition & 12 deletions site/smart-accounts/signers/choosing-a-signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,7 @@ The Signer plays a crucial role in your app because it controls the user’s sma

## Supported Signers

Account Kit is compatible with any EIP-1193 provider. Many of the most popular signers can be configured in minutes through our integration guides below:

- [Magic](/smart-accounts/signers/guides/magic)
- [web3auth](/smart-accounts/signers/guides/web3auth)
- [Turnkey](/smart-accounts/signers/guides/turnkey)
- [Privy](/smart-accounts/signers/guides/privy)
- [Dynamic](/smart-accounts/signers/guides/dynamic)
- [Fireblocks](/smart-accounts/signers/guides/fireblocks)
- [Portal](/smart-accounts/signers/guides/portal)
- [Capsule](/smart-accounts/signers/guides/capsule)
- [Lit Protocol](/smart-accounts/signers/guides/lit)
- [Self-custodial wallets like MetaMask or Ledger](/smart-accounts/signers/guides/eoa)
Account Kit is compatible with any EIP-1193 provider. Many of the most popular signers can be configured in minutes through our integration signer guides.

If you want to use another Signer, you can integrate any other Signer by wrapping it in an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider or using [`SmartAccountSigner`](/smart-accounts/signers/guides/custom-signer#implementing-smartaccountsigner) to adapt non-standard Signer.

Expand Down
79 changes: 79 additions & 0 deletions site/smart-accounts/signers/guides/dfns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
outline: deep
head:
- - meta
- property: og:title
content: Dfns
- - meta
- name: description
content: Guide for using Dfns as a Signer
- - meta
- property: og:description
content: Guide for using Dfns as a Signer
---

# Dfns Integration Guide

[Dfns](https://www.dfns.co) is an MPC/TSS Wallet-as-a-Service API/SDK provider. Dfns aims to optimize the balance of security and UX by deploying key shares into a decentralized network on the backend while enabling wallet access via biometric open standards on the frontend like Webauthn. Reach out [here](https://www.dfns.co/learn-more) to set up a sandbox environment to get started.

Dfns seamlessly integrates with Account Abstraction by signing `UserOperation`s. See the examples below for initializing a DFNS signer and creating a provider with that signer. You can follow [this](https://accountkit.alchemy.com/tutorials/sponsoring-gas/sponsoring-gas.html) guide to send and sponsor `UserOperation`s with the provider created.

Dfns created a full example of a gas-less transaction via a paymaster [in our SDK](https://github.com/dfnsext/typescript-sdk/blob/m/examples/viem/alchemy-aa-gasless/README.md), adapted from our [gas sponsorship example](https://accountkit.alchemy.com/guides/sponsoring-gas.html).

## Install Dfns SDK

::: code-group

```bash [npm]
npm i @dfns/lib-viem @dfns/sdk @dfns/sdk-keysigner
```

```bash [yarn]
yarn add @dfns/lib-viem @dfns/sdk @dfns/sdk-keysigner
```

:::

### Create a SmartAccountSigner

Setup the Dfns Web3 Provider and wrap it in an `AlchemyProvider`.

<<< @/snippets/dfns.ts

### Use it with Light Account

::: code-group

```ts [example.ts]
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { encodeFunctionData, parseAbi } from "viem";
import { sepolia } from "viem/chains";
import { createDfnsSigner } from "./dfns";

// Remember to replace "ALCHEMY_API_KEY" with your own Alchemy API key, get one here: https://dashboard.alchemy.com/
const ALCHEMY_API_KEY = "API_KEY";
const chain = sepolia;

const createAlchemyProvider = async (): Promise<AlchemyProvider> => {
return new AlchemyProvider({
apiKey: ALCHEMY_API_KEY,
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
chain,
owner: await createDfnsSigner(),
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
};
```

<<< @/snippets/dfns.ts

:::
42 changes: 42 additions & 0 deletions site/snippets/dfns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core";
import { DfnsWallet } from "@dfns/lib-viem";
import { DfnsApiClient } from "@dfns/sdk";
import { AsymmetricKeySigner } from "@dfns/sdk-keysigner";
import { LocalAccount, toAccount } from "viem/accounts";

// See the Dfns example https://github.com/dfnsext/typescript-sdk/blob/m/examples/viem/alchemy-aa-gasless/README.md for details on populating the environment variables.
const DFNS_PRIVATE_KEY = null;
const DFNS_CRED_ID = null;
const DFNS_APP_ORIGIN = null;
const DFNS_APP_ID = null;
const DFNS_AUTH_TOKEN = null;
const DFNS_API_URL = null;
const SEPOLIA_WALLET_ID = null;

const initDfnsWallet = (walletId: string) => {
const signer = new AsymmetricKeySigner({
privateKey: DFNS_PRIVATE_KEY!,
credId: DFNS_CRED_ID!,
appOrigin: DFNS_APP_ORIGIN!,
});

const dfnsClient = new DfnsApiClient({
appId: DFNS_APP_ID!,
authToken: DFNS_AUTH_TOKEN!,
baseUrl: DFNS_API_URL!,
signer,
});

return DfnsWallet.init({
walletId,
dfnsClient,
maxRetries: 10,
});
};

export const createDfnsSigner = async (): Promise<SmartAccountSigner> => {
const sepoliaWallet = await initDfnsWallet(SEPOLIA_WALLET_ID!);
const account = toAccount(sepoliaWallet) as LocalAccount;
const dfnsSigner = new LocalAccountSigner(account as any);
return dfnsSigner;
};

0 comments on commit 33141b0

Please sign in to comment.