Skip to content

Commit 4048637

Browse files
add guide for passkey as a signer
* add guide for passkey as a signer * minor fixes
1 parent b19b9c6 commit 4048637

File tree

6 files changed

+108
-3
lines changed

6 files changed

+108
-3
lines changed

gator-sidebar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const sidebar = {
6767
'guides/smart-accounts/signers/dynamic',
6868
'guides/smart-accounts/signers/embedded-wallets',
6969
'guides/smart-accounts/signers/eoa-wallets',
70+
'guides/smart-accounts/signers/passkey',
7071
'guides/smart-accounts/signers/privy',
7172
],
7273
},

smart-accounts-kit/guides/smart-accounts/signers/dynamic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ that allows you to use Dynamic's EOA wallet as a signer for MetaMask Smart Accou
1313
View the complete code for this guide at [gator-examples repository](https://github.com/MetaMask/gator-examples/tree/main/examples/smart-accounts/signers/dynamic).
1414

1515
:::info
16-
This guide is targeted towards React and React-based frameworks.
16+
This guide supports React and React-based frameworks.
1717
:::
1818

1919
## Prerequisites

smart-accounts-kit/guides/smart-accounts/signers/embedded-wallets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ users to access Web3 applications through familiar authentication methods in und
1313
MetaMask Smart Accounts is a signer agnostic implementation that allows you to use Embedded Wallets as a signer for MetaMask Smart Accounts.
1414

1515
:::info
16-
This guide is targeted towards React and React-based frameworks.
16+
This guide supports React and React-based frameworks.
1717
:::
1818

1919
## Prerequisites

smart-accounts-kit/guides/smart-accounts/signers/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Checkout the following guides to learn how to configure different signers:
4040
title: "EOA (e.g. MetaMask)",
4141
description: "Learn how to use EOAs like MetaMask with MetaMask Smart Accounts.",
4242
},
43+
{
44+
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/passkey",
45+
title: "Passkey",
46+
description: "Learn how to use a passkey with MetaMask Smart Accounts.",
47+
},
4348
{
4449
href: "/smart-accounts-kit/development/guides/smart-accounts/signers/privy",
4550
title: "Privy",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
description: Learn how to use Passkey with MetaMask Smart Accounts.
3+
sidebar_label: Passkey
4+
keywords: [passkey, smart account, signer, metamask smart account]
5+
---
6+
7+
# Use a passkey with MetaMask Smart Accounts
8+
9+
Passkeys eliminate the need for traditional seed phrases that are difficult to remember, enabling a more seamless
10+
and secure way for users to access their Externally Owned Accounts (EOAs). Compared to traditional EOAs which use
11+
secp256k1 elliptic curve to generate key pairs and signatures, a passkey-based EOA uses the
12+
secp256r1 (P-256) elliptic curve.
13+
14+
MetaMask Smart Accounts is signer agnostic and natively supports passkeys (P-256 elliptic curve signatures), so you can use a passkey as the signer.
15+
16+
## Prerequisites
17+
18+
- Install [Node.js](https://nodejs.org/en/blog/release/v18.18.0) v18 or later
19+
- Install [Yarn](https://yarnpkg.com/),
20+
[npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), or another package manager
21+
22+
## Steps
23+
24+
### 1. Install dependencies
25+
26+
Install the [Smart Accounts Kit](https://www.npmjs.com/package/@metamask/smart-accounts-kit) and other dependencies in your project:
27+
28+
```bash npm2yarn
29+
npm install @metamask/smart-accounts-kit ox
30+
```
31+
32+
### 2. Create a passkey
33+
34+
To create a passkey signer, use Viem's [`createWebAuthnCredential`](https://viem.sh/account-abstraction/accounts/webauthn/createWebAuthnCredential) function to securely register the passkey (WebAuthn credential).
35+
36+
```ts
37+
import { createWebAuthnCredential } from 'viem/account-abstraction'
38+
39+
const credential = await createWebAuthnCredential({
40+
name: 'MetaMask Smart Account',
41+
})
42+
```
43+
44+
### 3. Create a smart account
45+
46+
Once the passkey is created, use the [Viem WebAuthn Account](https://viem.sh/account-abstraction/accounts/webauthn) to configure your passkey as a MetaMask smart account signer.
47+
48+
The `deployParams` parameter needs the X and Y coordinates of the P-256 public key. Since WebAuthn credentials store
49+
a compressed public key, you need to deserialize it, and extract the X and Y coordinates.
50+
51+
<Tabs>
52+
<TabItem value="example.ts">
53+
54+
```typescript
55+
import { publicClient } from "./config.ts"
56+
import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts-kit";
57+
import { toWebAuthnAccount } from "viem/account-abstraction";
58+
import { Address, PublicKey } from "ox";
59+
import { toHex } from "viem";
60+
61+
const webAuthnAccount = toWebAuthnAccount({ credential });
62+
63+
// Deserialize compressed public key
64+
const publicKey = PublicKey.fromHex(credential.publicKey);
65+
66+
// Convert public key to address
67+
const owner = Address.fromPublicKey(publicKey);
68+
69+
const smartAccount = await toMetaMaskSmartAccount({
70+
client: publicClient,
71+
implementation: Implementation.Hybrid,
72+
deployParams: [owner, [toHex(credential.id)], [publicKey.x], [publicKey.y]],
73+
deploySalt: "0x",
74+
signer: { webAuthnAccount, keyId: toHex(credential.id) },
75+
});
76+
```
77+
78+
</TabItem>
79+
80+
<TabItem value="config.ts">
81+
82+
```typescript
83+
import { http, createPublicClient } from "viem";
84+
import { sepolia as chain } from "viem/chains";
85+
86+
const transport = http();
87+
export const publicClient = createPublicClient({
88+
transport,
89+
chain,
90+
});
91+
```
92+
93+
</TabItem>
94+
</Tabs>
95+
96+
## Next steps
97+
98+
- See how to [send a user operation](../send-user-operation.md).
99+
- To sponsor gas for end users, see how to [send a gasless transaction](../send-gasless-transaction.md).

smart-accounts-kit/guides/smart-accounts/signers/privy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ keywords: [privy, smart account, signer, metamask smart account]
1010
that allows you to use Privy's EOA wallet as a signer for MetaMask Smart Accounts.
1111

1212
:::info
13-
This guide is targeted towards React and React-based frameworks.
13+
This guide supports React and React-based frameworks.
1414
:::
1515

1616
## Prerequisites

0 commit comments

Comments
 (0)