Skip to content

Commit 2d19dec

Browse files
authored
Merge branch 'main' into ava/update-sa-client
2 parents bf2fad5 + e0962c5 commit 2d19dec

File tree

9 files changed

+449
-0
lines changed

9 files changed

+449
-0
lines changed

docs/docs.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ navigation:
207207
path: wallets/pages/transactions/retry-transactions/index.mdx
208208
- page: Sponsor gas on Solana
209209
path: wallets/pages/transactions/solana/sponsor-gas-solana.mdx
210+
- section: Signing
211+
contents:
212+
- page: Sign messages
213+
path: wallets/pages/transactions/signing/sign-messages/index.mdx
214+
- page: Sign typed data
215+
path: wallets/pages/transactions/signing/sign-typed-data/index.mdx
210216
- page: Configure client
211217
path: wallets/pages/concepts/smart-account-client.mdx
212218
- section: Low-Level Infra
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<Info>Required SDK version: ^v4.59.1</Info>
2+
3+
See the [`signMessage` SDK
4+
reference](/wallets/reference/account-kit/wallet-client/functions/signMessage)
5+
for full descriptions of the parameters used in the following example.
6+
7+
<CodeBlocks>
8+
9+
```ts title="signRawMessage.ts"
10+
import { client } from "./client";
11+
12+
// Sign a raw hex message
13+
const rawSignature = await client.signMessage({
14+
message: {
15+
raw: "0x48656c6c6f2c20776f726c6421", // "Hello, world!" in hex
16+
},
17+
});
18+
19+
console.log("Signature over raw data:", rawSignature);
20+
```
21+
22+
```ts title="client.ts"
23+
import "dotenv/config";
24+
import type { Hex } from "viem";
25+
import { LocalAccountSigner } from "@aa-sdk/core";
26+
import { alchemy, sepolia } from "@account-kit/infra";
27+
import { createSmartWalletClient } from "@account-kit/wallet-client";
28+
29+
const clientParams = {
30+
transport: alchemy({
31+
apiKey: process.env.ALCHEMY_API_KEY!,
32+
}),
33+
chain: sepolia,
34+
signer: LocalAccountSigner.privateKeyToAccountSigner(
35+
process.env.PRIVATE_KEY! as Hex,
36+
),
37+
};
38+
39+
const clientWithoutAccount = createSmartWalletClient(clientParams);
40+
41+
const account = await clientWithoutAccount.requestAccount();
42+
43+
export const client = createSmartWalletClient({
44+
...clientParams,
45+
account: account.address,
46+
});
47+
```
48+
49+
</CodeBlocks>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<Info>Required SDK version: ^v4.59.1</Info>
2+
3+
See the [`signMessage` SDK
4+
reference](/wallets/reference/account-kit/wallet-client/functions/signMessage)
5+
for full descriptions of the parameters used in the following example.
6+
7+
<CodeBlocks>
8+
9+
```ts title="signTextMessage.ts"
10+
import { client } from "./client";
11+
12+
// Sign a simple text message
13+
const textSignature = await client.signMessage({
14+
message: "Hello, world!",
15+
});
16+
17+
console.log("Signature over text:", textSignature);
18+
```
19+
20+
```ts title="client.ts"
21+
import "dotenv/config";
22+
import type { Hex } from "viem";
23+
import { LocalAccountSigner } from "@aa-sdk/core";
24+
import { alchemy, sepolia } from "@account-kit/infra";
25+
import { createSmartWalletClient } from "@account-kit/wallet-client";
26+
27+
const clientParams = {
28+
transport: alchemy({
29+
apiKey: process.env.ALCHEMY_API_KEY!,
30+
}),
31+
chain: sepolia,
32+
signer: LocalAccountSigner.privateKeyToAccountSigner(
33+
process.env.PRIVATE_KEY! as Hex,
34+
),
35+
};
36+
37+
const clientWithoutAccount = createSmartWalletClient(clientParams);
38+
39+
const account = await clientWithoutAccount.requestAccount();
40+
41+
export const client = createSmartWalletClient({
42+
...clientParams,
43+
account: account.address,
44+
});
45+
```
46+
47+
</CodeBlocks>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Sign messages
3+
description: Sign messages using your Smart Wallet
4+
slug: wallets/transactions/signing/sign-messages
5+
---
6+
7+
This guide will teach you how to sign messages using your Smart Wallet. Message signing is a key feature that allows users to authenticate and prove ownership of their wallet without spending gas.
8+
9+
Smart Wallets will generate signatures that can be validated using [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271). If the wallet is an undeployed smart contract account (also known as a counterfactual address), then the signature will be wrapped according to [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492).
10+
11+
## Prerequisites
12+
13+
- API key from your [dashboard](https://dashboard.alchemy.com/apps)
14+
- A Smart Wallet with an associated signer
15+
16+
## What is message signing?
17+
18+
Message signing allows users to:
19+
20+
- **Authenticate** without spending gas
21+
- **Prove ownership** of their wallet
22+
- **Sign arbitrary data** for offchain verification
23+
- **Interact with dApps** that require signature-based authentication
24+
25+
Smart Wallets support EIP-191 message signing, which is the standard for Ethereum message signing. You may also see EIP-191 referred to as the `personal_sign` message format.
26+
27+
## Text messages
28+
29+
<Tabs>
30+
<Tab title="React" language="react">
31+
<Markdown src="react-text.mdx" />
32+
</Tab>
33+
<Tab title="JavaScript" language="javascript">
34+
<Markdown src="client-text.mdx" />
35+
</Tab>
36+
</Tabs>
37+
38+
## Raw hex messages
39+
40+
<Tabs>
41+
<Tab title="React" language="react">
42+
<Markdown src="react-raw.mdx" />
43+
</Tab>
44+
<Tab title="JavaScript" language="javascript">
45+
<Markdown src="client-raw.mdx" />
46+
</Tab>
47+
</Tabs>
48+
49+
## Next steps
50+
51+
Build more:
52+
53+
- [Sign typed data](/wallets/transactions/signing/sign-typed-data)
54+
- [Send transactions](/wallets/transactions/send-transactions)
55+
56+
Troubleshooting:
57+
58+
- [Common errors](/wallets/resources/faqs#common-errors)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Info>Required SDK version: ^v4.59.1</Info>
2+
3+
Use the [`useSignMessage`](/wallets/reference/account-kit/react/hooks/useSignMessage) hook to sign raw hex messages with your Smart Wallet.
4+
5+
<CodeBlocks>
6+
7+
```tsx title="signRawMessage.tsx"
8+
import { useSignMessage, useSmartAccountClient } from "@account-kit/react";
9+
10+
export default function SignRawMessage() {
11+
const { client } = useSmartAccountClient({});
12+
const { signMessageAsync } = useSignMessage({
13+
client,
14+
});
15+
16+
const handleSignRawMessage = async () => {
17+
const signature = await signMessageAsync({
18+
message: {
19+
raw: "0x48656c6c6f2c20776f726c6421", // "Hello, world!" in hex
20+
},
21+
});
22+
23+
console.log("Raw signature:", signature);
24+
};
25+
26+
return (
27+
<div>
28+
<button onClick={handleSignRawMessage}>Sign Raw Message</button>
29+
</div>
30+
);
31+
}
32+
```
33+
34+
</CodeBlocks>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Info>Required SDK version: ^v4.59.1</Info>
2+
3+
Use the [`useSignMessage`](/wallets/reference/account-kit/react/hooks/useSignMessage) hook to sign text messages with your Smart Wallet.
4+
5+
<CodeBlocks>
6+
7+
```tsx title="signTextMessage.tsx"
8+
import { useSignMessage, useSmartAccountClient } from "@account-kit/react";
9+
10+
export default function SignTextMessage() {
11+
const { client } = useSmartAccountClient({});
12+
const { signMessageAsync } = useSignMessage({
13+
client,
14+
});
15+
16+
const handleSignTextMessage = async () => {
17+
const signature = await signMessageAsync({
18+
message: "Hello, world!",
19+
});
20+
21+
console.log("Signature:", signature);
22+
};
23+
24+
return (
25+
<div>
26+
<button onClick={handleSignTextMessage}>Sign Text Message</button>
27+
</div>
28+
);
29+
}
30+
```
31+
32+
</CodeBlocks>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<Info>Required SDK version: ^v4.59.1</Info>
2+
3+
See the [`signTypedData` SDK
4+
reference](/wallets/reference/account-kit/wallet-client/functions/signTypedData)
5+
for full descriptions of the parameters used in the following example.
6+
7+
<CodeBlocks>
8+
9+
```ts title="signTypedData.ts"
10+
import { client } from "./client";
11+
12+
// Sign typed data
13+
const typedData = {
14+
domain: {
15+
name: "MyDApp",
16+
version: "1",
17+
chainId: 1,
18+
verifyingContract: "0x...",
19+
},
20+
types: {
21+
Auth: [
22+
{ name: "user", type: "address" },
23+
{ name: "nonce", type: "uint256" },
24+
{ name: "timestamp", type: "uint256" },
25+
],
26+
},
27+
primaryType: "Auth",
28+
message: {
29+
user: "0x...", // wallet address
30+
nonce: 12345,
31+
timestamp: Date.now(),
32+
},
33+
} as const;
34+
35+
const signature = await client.signTypedData(typedData);
36+
37+
console.log("Typed data signature:", signature);
38+
```
39+
40+
```ts title="client.ts"
41+
import "dotenv/config";
42+
import type { Hex } from "viem";
43+
import { LocalAccountSigner } from "@aa-sdk/core";
44+
import { alchemy, sepolia } from "@account-kit/infra";
45+
import { createSmartWalletClient } from "@account-kit/wallet-client";
46+
47+
const clientParams = {
48+
transport: alchemy({
49+
apiKey: process.env.ALCHEMY_API_KEY!,
50+
}),
51+
chain: sepolia,
52+
signer: LocalAccountSigner.privateKeyToAccountSigner(
53+
process.env.PRIVATE_KEY! as Hex,
54+
),
55+
};
56+
57+
const clientWithoutAccount = createSmartWalletClient(clientParams);
58+
59+
const account = await clientWithoutAccount.requestAccount();
60+
61+
export const client = createSmartWalletClient({
62+
...clientParams,
63+
account: account.address,
64+
});
65+
```
66+
67+
</CodeBlocks>

0 commit comments

Comments
 (0)