Skip to content

Commit d6670ac

Browse files
committed
fixed
1 parent 9dbbecd commit d6670ac

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

examples/gm/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Client, type XmtpEnv } from "@xmtp/node-sdk";
2-
import { createSigner, getEncryptionKeyFromHex } from "@/helpers";
2+
import { createSigner, createUser, getEncryptionKeyFromHex } from "@/helpers";
33

44
/* Get the wallet key associated to the public key of
55
* the agent and the encryption key for the local db

helpers/index.ts

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import { getRandomValues } from "node:crypto";
2+
import type { Signer } from "@xmtp/node-sdk";
23
import { fromString, toString } from "uint8arrays";
3-
import { toBytes } from "viem";
4+
import { createWalletClient, http, toBytes } from "viem";
45
import { privateKeyToAccount } from "viem/accounts";
6+
import { sepolia } from "viem/chains";
57

6-
/**
7-
* Create a signer from a private key
8-
* @param privateKey - The private key of the account
9-
* @returns The signer
10-
*/
11-
export const createSigner = (privateKey: `0x${string}`) => {
12-
/* Convert the private key to an account */
13-
const account = privateKeyToAccount(privateKey);
14-
/* Return the signer */
8+
interface User {
9+
key: string;
10+
account: ReturnType<typeof privateKeyToAccount>;
11+
wallet: ReturnType<typeof createWalletClient>;
12+
}
13+
14+
export const createUser = (key: string): User => {
15+
const account = privateKeyToAccount(key as `0x${string}`);
16+
return {
17+
key,
18+
account,
19+
wallet: createWalletClient({
20+
account,
21+
chain: sepolia,
22+
transport: http(),
23+
}),
24+
};
25+
};
26+
27+
export const createSigner = (key: string): Signer => {
28+
const user = createUser(key);
1529
return {
16-
getAddress: () => account.address,
30+
walletType: "EOA",
31+
getAddress: () => user.account.address,
1732
signMessage: async (message: string) => {
18-
const signature = await account.signMessage({
33+
const signature = await user.wallet.signMessage({
1934
message,
35+
account: user.account,
2036
});
2137
return toBytes(signature);
2238
},

0 commit comments

Comments
 (0)