Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to node 45 #39

Merged
merged 4 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions helpers/index.ts
Original file line number Diff line number Diff line change
@@ -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<typeof privateKeyToAccount>;
wallet: ReturnType<typeof createWalletClient>;
}

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);
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
22 changes: 21 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading