diff --git a/helpers/index.ts b/helpers/index.ts index 3fe2b8f..6680c42 100644 --- a/helpers/index.ts +++ b/helpers/index.ts @@ -1,22 +1,38 @@ import { getRandomValues } from "node:crypto"; +import type { Signer } from "@xmtp/node-sdk"; import { fromString, toString } from "uint8arrays"; -import { toBytes } from "viem"; +import { createWalletClient, http, toBytes } from "viem"; import { privateKeyToAccount } from "viem/accounts"; +import { sepolia } from "viem/chains"; -/** - * Create a signer from a private key - * @param privateKey - The private key of the account - * @returns The signer - */ -export const createSigner = (privateKey: `0x${string}`) => { - /* Convert the private key to an account */ - const account = privateKeyToAccount(privateKey); - /* Return the signer */ +interface User { + key: string; + account: ReturnType; + wallet: ReturnType; +} + +export const createUser = (key: string): User => { + const account = privateKeyToAccount(key as `0x${string}`); + return { + key, + account, + wallet: createWalletClient({ + account, + chain: sepolia, + transport: http(), + }), + }; +}; + +export const createSigner = (key: string): Signer => { + const user = createUser(key); return { - getAddress: () => account.address, + walletType: "EOA", + getAddress: () => user.account.address, signMessage: async (message: string) => { - const signature = await account.signMessage({ + const signature = await user.wallet.signMessage({ message, + account: user.account, }); return toBytes(signature); }, diff --git a/package.json b/package.json index c963392..95d9ef0 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "integrations/*" ], "scripts": { + "build": "tsc", "clean": "rimraf node_modules && yarn clean:dbs", "clean:dbs": "rimraf *.db3* ||:", "examples:gated": "tsx --env-file=.env examples/gated-group/index.ts", @@ -20,7 +21,7 @@ "typecheck": "tsc" }, "dependencies": { - "@xmtp/node-sdk": "0.0.42", + "@xmtp/node-sdk": "0.0.45", "alchemy-sdk": "^3.0.0", "openai": "latest", "tsx": "^4.19.2", diff --git a/yarn.lock b/yarn.lock index 6f159de..c1e12f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1281,6 +1281,13 @@ __metadata: languageName: node linkType: hard +"@xmtp/node-bindings@npm:^0.0.38": + version: 0.0.38 + resolution: "@xmtp/node-bindings@npm:0.0.38" + checksum: 10/a9452a913cdda5cd050b91ed34358b8975524d1c5e6434db51b1d60f13a29069b531ee566811ab4ed339713ad0e041e83f24fc916684c968c322ba63f21319f3 + languageName: node + linkType: hard + "@xmtp/node-sdk@npm:0.0.42": version: 0.0.42 resolution: "@xmtp/node-sdk@npm:0.0.42" @@ -1294,6 +1301,19 @@ __metadata: languageName: node linkType: hard +"@xmtp/node-sdk@npm:0.0.45": + version: 0.0.45 + resolution: "@xmtp/node-sdk@npm:0.0.45" + dependencies: + "@xmtp/content-type-group-updated": "npm:^2.0.0" + "@xmtp/content-type-primitives": "npm:^2.0.0" + "@xmtp/content-type-text": "npm:^2.0.0" + "@xmtp/node-bindings": "npm:^0.0.38" + "@xmtp/proto": "npm:^3.72.3" + checksum: 10/70eb659105a585e651f9c9a538b98014476212a1023308b88012317a5c64e58b4a2d920891c131e763d449823cb8d1e126a4041ff73a803b5593702f43c08e8c + languageName: node + linkType: hard + "@xmtp/proto@npm:^3.72.0, @xmtp/proto@npm:^3.72.3": version: 3.73.0 resolution: "@xmtp/proto@npm:3.73.0" @@ -3831,7 +3851,7 @@ __metadata: "@ianvs/prettier-plugin-sort-imports": "npm:^4.4.1" "@types/eslint__js": "npm:^8.42.3" "@types/node": "npm:^22.13.0" - "@xmtp/node-sdk": "npm:0.0.42" + "@xmtp/node-sdk": "npm:0.0.45" alchemy-sdk: "npm:^3.0.0" eslint: "npm:^9.19.0" eslint-config-prettier: "npm:^10.0.1"