Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: dfns new signer #313

Merged
merged 21 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
35bddae
docs: new signer dfns
avarobinson Dec 6, 2023
17d5e45
fix: prettier on dfns doc
avarobinson Dec 11, 2023
7cf8a10
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
6aa7e9f
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
36f1968
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
2ee47b1
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
6eb3318
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
e38c6ce
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
6f17e0d
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
137c430
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
92dac9b
docs: small text fix
avarobinson Dec 11, 2023
e6364d0
docs: prettier run
avarobinson Dec 11, 2023
64719a9
fix: link typo
avarobinson Dec 11, 2023
45fb579
docs: Update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
83d03b2
docs: update site/snippets/dfns.ts
avarobinson Dec 11, 2023
2b753c4
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
46c2b59
docs: update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
d166c08
docs: Update site/smart-accounts/signers/guides/dfns.md
avarobinson Dec 11, 2023
ba4f80e
docs: removing manual list of signer choices
avarobinson Dec 11, 2023
910193a
Update site/smart-accounts/signers/choosing-a-signer.md
avasisht23 Dec 11, 2023
8d91364
docs: update
avasisht23 Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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
129 changes: 129 additions & 0 deletions site/smart-accounts/signers/guides/dfns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
outline: deep
head:
- - meta
- property: og:title
content: Dfns
- - meta
- name: description
content: Guide for using Dfns as a signer
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
- - meta
- property: og:description
content: Guide for using Dfns as a signer
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
---

# Dfns Integration Guide

[Dfns](https://www.dfns.co) is an MPC/TSS Wallet-as-a-Service API/SDK provider. We have optimized 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. [Ping us](https://www.dfns.co/learn-more) to set up a sandbox environment to get started.
avarobinson marked this conversation as resolved.
Show resolved Hide resolved

Dfns seamlessly integrates with Account Abstraction by signing User Operations. We've created a full example of a gasless transaction via a paymaster [in our SDK](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/viem/alchemy-aa-gasless) adapted from Alchemy's [sponsor gas example](https://accountkit.alchemy.com/guides/sponsoring-gas.html). Clone the repo to get started and see the comments in the [Readme](https://github.com/dfns/dfns-sdk-ts/tree/m/examples/viem/alchemy-aa-gasless/README.md).
avarobinson marked this conversation as resolved.
Show resolved Hide resolved

## 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 Dfns SmartAccountSigner

Setup the Dfns Web3 Provider and wrap it in an AlchemyProvider. See the Dfns example [Readme](https://github.com/dfnsext/typescript-sdk/blob/m/examples/viem/alchemy-aa-gasless/README.md) for detail on populating the environment variables.
avarobinson marked this conversation as resolved.
Show resolved Hide resolved

```ts
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import { LocalAccountSigner } from "@alchemy/aa-core";
import { DfnsWallet } from "@dfns/lib-viem";
import { DfnsApiClient } from "@dfns/sdk";
import { AsymmetricKeySigner } from "@dfns/sdk-keysigner";
import dotenv from "dotenv";
import { encodeFunctionData, parseAbi } from "viem";
import { toAccount } from "viem/accounts";
import { sepolia } from "viem/chains";

dotenv.config();

const initDfnsWallet = (walletId: string) => {
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
const signer = new AsymmetricKeySigner({
privateKey: process.env.DFNS_PRIVATE_KEY!,
credId: process.env.DFNS_CRED_ID!,
appOrigin: process.env.DFNS_APP_ORIGIN!,
});

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

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

const alchemyProvider = async (): Promise<AlchemyProvider> => {
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
const sepoliaWallet = await initDfnsWallet(process.env.SEPOLIA_WALLET_ID!);
const account = toAccount(sepoliaWallet);
const eoaSigner = new LocalAccountSigner(account);

return new AlchemyProvider({
apiKey: process.env.ALCHEMY_SEPOLIA_KEY!,
chain: sepolia,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
chain: sepolia,
owner: eoaSigner,
factoryAddress: getDefaultLightAccountFactoryAddress(sepolia),
rpcClient,
})
);
};
```

### Execute a Gasless Transaction

```ts
const main = async () => {
const provider = await alchemyProvider();
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
const address = await provider.getAddress();
console.log(`Smart account address: ${address}`);

// link the provider with the Gas Manager. This ensures user operations
// sent with this provider get sponsorship from the Gas Manager.
provider.withAlchemyGasManager({
policyId: process.env.ALCHEMY_GAS_POLICY_ID!,
});

const alchemyToken = "0x6F3c1baeF15F2Ac6eD52ef897f60cac0B10d90C3";
avarobinson marked this conversation as resolved.
Show resolved Hide resolved

// send a sponsored user operation to mint some tokens
const { hash: uoHash } = await provider.sendUserOperation({
target: alchemyToken,
avarobinson marked this conversation as resolved.
Show resolved Hide resolved
data: encodeFunctionData({
abi: parseAbi(["function mint(address recipient)"]),
functionName: "mint",
args: [address],
}),
});
console.log(`User operation hash: ${uoHash}`);

const txHash = await provider.waitForUserOperationTransaction(uoHash);
console.log(`Transaction: https://sepolia.etherscan.io/tx/${txHash}`);
};

main();
```
Loading