From 60d98e38593384459c4a6ad8e376c974e2bcf947 Mon Sep 17 00:00:00 2001 From: fabri Date: Wed, 26 Feb 2025 19:06:39 -0300 Subject: [PATCH 1/4] upgrade node --- helpers/index.ts | 1 + package.json | 3 ++- yarn.lock | 22 +++++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/helpers/index.ts b/helpers/index.ts index 3fe2b8f..6a3df7f 100644 --- a/helpers/index.ts +++ b/helpers/index.ts @@ -13,6 +13,7 @@ export const createSigner = (privateKey: `0x${string}`) => { const account = privateKeyToAccount(privateKey); /* Return the signer */ return { + walletType: "EOA", getAddress: () => account.address, signMessage: async (message: string) => { const signature = await account.signMessage({ 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" From 9dbbecdfc58ed445b15d767c7592661af9b21ab7 Mon Sep 17 00:00:00 2001 From: fabri Date: Wed, 26 Feb 2025 19:08:25 -0300 Subject: [PATCH 2/4] remove changes --- helpers/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/helpers/index.ts b/helpers/index.ts index 6a3df7f..3fe2b8f 100644 --- a/helpers/index.ts +++ b/helpers/index.ts @@ -13,7 +13,6 @@ export const createSigner = (privateKey: `0x${string}`) => { const account = privateKeyToAccount(privateKey); /* Return the signer */ return { - walletType: "EOA", getAddress: () => account.address, signMessage: async (message: string) => { const signature = await account.signMessage({ From d6670ac163b7dd8dc820cbf8e88a8bd6625c44aa Mon Sep 17 00:00:00 2001 From: fabri Date: Thu, 27 Feb 2025 20:46:39 -0300 Subject: [PATCH 3/4] fixed --- examples/gm/index.ts | 2 +- helpers/index.ts | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/examples/gm/index.ts b/examples/gm/index.ts index e5e85fa..9653a42 100644 --- a/examples/gm/index.ts +++ b/examples/gm/index.ts @@ -1,5 +1,5 @@ import { Client, type XmtpEnv } from "@xmtp/node-sdk"; -import { createSigner, getEncryptionKeyFromHex } from "@/helpers"; +import { createSigner, createUser, getEncryptionKeyFromHex } from "@/helpers"; /* Get the wallet key associated to the public key of * the agent and the encryption key for the local db 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); }, From 568c9fef5433173cdfc5fcf03ed6d28bbbd9d986 Mon Sep 17 00:00:00 2001 From: fabri Date: Thu, 27 Feb 2025 20:48:10 -0300 Subject: [PATCH 4/4] fix linter --- examples/gm/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gm/index.ts b/examples/gm/index.ts index 9653a42..e5e85fa 100644 --- a/examples/gm/index.ts +++ b/examples/gm/index.ts @@ -1,5 +1,5 @@ import { Client, type XmtpEnv } from "@xmtp/node-sdk"; -import { createSigner, createUser, getEncryptionKeyFromHex } from "@/helpers"; +import { createSigner, getEncryptionKeyFromHex } from "@/helpers"; /* Get the wallet key associated to the public key of * the agent and the encryption key for the local db