From 2516903c980e082e5e665b73bef84b73037ce992 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 10:49:15 -0600 Subject: [PATCH 1/7] Update node bindings exports --- sdks/node-sdk/src/index.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/sdks/node-sdk/src/index.ts b/sdks/node-sdk/src/index.ts index bfbdfed7e..51eb404c4 100644 --- a/sdks/node-sdk/src/index.ts +++ b/sdks/node-sdk/src/index.ts @@ -10,5 +10,33 @@ export { Conversation } from "./Conversation"; export { Conversations } from "./Conversations"; export { DecodedMessage } from "./DecodedMessage"; export type { StreamCallback } from "./AsyncStream"; -export type * from "@xmtp/node-bindings"; +export type { + Consent, + ContentTypeId, + CreateGroupOptions, + EncodedContent, + InboxState, + Installation, + ListConversationsOptions, + ListMessagesOptions, + Message, + PermissionPolicySet, +} from "@xmtp/node-bindings"; +export { + ConsentEntityType, + ConsentState, + ConversationType, + DeliveryStatus, + GroupMember, + GroupMembershipState, + GroupMessageKind, + GroupMetadata, + GroupPermissions, + GroupPermissionsOptions, + PermissionLevel, + PermissionPolicy, + PermissionUpdateType, + SignatureRequestType, + SortDirection, +} from "@xmtp/node-bindings"; export { generateInboxId, getInboxIdForAddress } from "./helpers/inboxId"; From 3e82b0a6cc5ae3a7e8a576d493e3e1c1ef075b38 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 10:50:08 -0600 Subject: [PATCH 2/7] Update canMessage return type --- sdks/node-sdk/src/Client.ts | 3 ++- sdks/node-sdk/test/Client.test.ts | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 4eb9214df..5a17fb40b 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -182,7 +182,8 @@ export class Client { } async canMessage(accountAddresses: string[]) { - return this.#innerClient.canMessage(accountAddresses); + const canMessage = await this.#innerClient.canMessage(accountAddresses); + return new Map(Object.entries(canMessage)); } addSignature( diff --git a/sdks/node-sdk/test/Client.test.ts b/sdks/node-sdk/test/Client.test.ts index bee24fcf4..cb3be7527 100644 --- a/sdks/node-sdk/test/Client.test.ts +++ b/sdks/node-sdk/test/Client.test.ts @@ -29,16 +29,15 @@ describe("Client", () => { const client2 = await createRegisteredClient(user); expect(client2.isRegistered).toBe(true); expect(await client2.createInboxSignatureText()).toBe(null); - expect(await client2.canMessage([user.account.address])).toEqual({ - [user.account.address.toLowerCase()]: true, - }); }); it("should be able to message registered identity", async () => { const user = createUser(); const client = await createRegisteredClient(user); const canMessage = await client.canMessage([user.account.address]); - expect(canMessage).toEqual({ [user.account.address.toLowerCase()]: true }); + expect(Object.fromEntries(canMessage)).toEqual({ + [user.account.address.toLowerCase()]: true, + }); }); it("should get an inbox ID from an address", async () => { From c9bb765420210e9a33806916bbdbc765f69520b9 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 10:50:33 -0600 Subject: [PATCH 3/7] Require encryption key --- sdks/node-sdk/src/Client.ts | 12 ++++++------ sdks/node-sdk/test/helpers.ts | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 5a17fb40b..1736c7b8f 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -50,10 +50,6 @@ export type NetworkOptions = { * Storage options */ export type StorageOptions = { - /** - * Encryption key to use for the local DB - */ - encryptionKey?: Uint8Array | null; /** * Path to the local DB */ @@ -96,7 +92,11 @@ export class Client { ); } - static async create(accountAddress: string, options?: ClientOptions) { + static async create( + accountAddress: string, + encryptionKey: Uint8Array, + options?: ClientOptions, + ) { const host = options?.apiUrl ?? ApiUrls[options?.env ?? "dev"]; const isSecure = host.startsWith("https"); const dbPath = @@ -113,7 +113,7 @@ export class Client { dbPath, inboxId, accountAddress, - options?.encryptionKey, + encryptionKey, options?.requestHistorySync, options?.logging ?? "off", ), diff --git a/sdks/node-sdk/test/helpers.ts b/sdks/node-sdk/test/helpers.ts index 4b306a5ce..29bde1b71 100644 --- a/sdks/node-sdk/test/helpers.ts +++ b/sdks/node-sdk/test/helpers.ts @@ -1,3 +1,4 @@ +import { getRandomValues } from "node:crypto"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { @@ -13,6 +14,7 @@ import { sepolia } from "viem/chains"; import { Client, type ClientOptions } from "@/Client"; const __dirname = dirname(fileURLToPath(import.meta.url)); +const testEncryptionKey = getRandomValues(new Uint8Array(32)); export const createUser = () => { const key = generatePrivateKey(); @@ -47,7 +49,7 @@ export const createClient = async (user: User, options?: ClientOptions) => { ...options, env: options?.env ?? "local", }; - return Client.create(user.account.address, { + return Client.create(user.account.address, testEncryptionKey, { ...opts, dbPath: join(__dirname, `./test-${user.uuid}.db3`), }); From 509c79383e24d065af5224a9e4d3baeb4bbfdb49 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 10:52:03 -0600 Subject: [PATCH 4/7] Upgrade node bindings --- sdks/node-sdk/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sdks/node-sdk/package.json b/sdks/node-sdk/package.json index fb70a929b..804a38831 100644 --- a/sdks/node-sdk/package.json +++ b/sdks/node-sdk/package.json @@ -52,7 +52,7 @@ "@xmtp/content-type-group-updated": "^1.0.0", "@xmtp/content-type-primitives": "^1.0.2", "@xmtp/content-type-text": "^1.0.0", - "@xmtp/node-bindings": "^0.0.17", + "@xmtp/node-bindings": "^0.0.18", "@xmtp/proto": "^3.62.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 0928c6afa..776044270 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4842,10 +4842,10 @@ __metadata: languageName: unknown linkType: soft -"@xmtp/node-bindings@npm:^0.0.17": - version: 0.0.17 - resolution: "@xmtp/node-bindings@npm:0.0.17" - checksum: 10/2f461623966ba04dfcf7710f5229f762a9bffceedbc01474d58eb7bbb1f2f138e0e2891eadef416fb03f9fcfa3d32edadf050e007656b64f1cd9da1989c5ee9d +"@xmtp/node-bindings@npm:^0.0.18": + version: 0.0.18 + resolution: "@xmtp/node-bindings@npm:0.0.18" + checksum: 10/5cca0748f163728c013ff17cf7fba81a64a7a6029a9782c6b568fd1044940c8ae641110f0a187ee2ac7787f303552712ebe1d5c515c5dad4dc0baa31506d8b83 languageName: node linkType: hard @@ -4860,7 +4860,7 @@ __metadata: "@xmtp/content-type-group-updated": "npm:^1.0.0" "@xmtp/content-type-primitives": "npm:^1.0.2" "@xmtp/content-type-text": "npm:^1.0.0" - "@xmtp/node-bindings": "npm:^0.0.17" + "@xmtp/node-bindings": "npm:^0.0.18" "@xmtp/proto": "npm:^3.62.1" "@xmtp/xmtp-js": "workspace:^" fast-glob: "npm:^3.3.2" From 2b8923ef88d8bb89ca322157315dd33ce9c4210a Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 11:06:54 -0600 Subject: [PATCH 5/7] Update logging options --- sdks/node-sdk/src/Client.ts | 17 ++++++++++++++--- sdks/node-sdk/src/index.ts | 2 ++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 1736c7b8f..a1eb69562 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -15,8 +15,10 @@ import { generateInboxId, getInboxIdForAddress, GroupMessageKind, + Level, type Consent, type ConsentEntityType, + type LogOptions, type Message, type Client as NodeClient, type SignatureRequestType, @@ -69,9 +71,13 @@ export type OtherOptions = { */ requestHistorySync?: string; /** - * Optionally set the logging level (default: 'off') + * Enable structured JSON logging */ - logging?: "debug" | "info" | "warn" | "error" | "off"; + structuredLogging?: boolean; + /** + * Logging level + */ + loggingLevel?: Level; }; export type ClientOptions = NetworkOptions & @@ -106,6 +112,11 @@ export class Client { (await getInboxIdForAddress(host, isSecure, accountAddress)) || generateInboxId(accountAddress); + const logOptions: LogOptions = { + structured: options?.structuredLogging ?? false, + level: options?.loggingLevel ?? Level.off, + }; + return new Client( await createClient( host, @@ -115,7 +126,7 @@ export class Client { accountAddress, encryptionKey, options?.requestHistorySync, - options?.logging ?? "off", + logOptions, ), [new GroupUpdatedCodec(), new TextCodec(), ...(options?.codecs ?? [])], ); diff --git a/sdks/node-sdk/src/index.ts b/sdks/node-sdk/src/index.ts index 51eb404c4..aef488ac5 100644 --- a/sdks/node-sdk/src/index.ts +++ b/sdks/node-sdk/src/index.ts @@ -19,6 +19,7 @@ export type { Installation, ListConversationsOptions, ListMessagesOptions, + LogOptions, Message, PermissionPolicySet, } from "@xmtp/node-bindings"; @@ -33,6 +34,7 @@ export { GroupMetadata, GroupPermissions, GroupPermissionsOptions, + Level, PermissionLevel, PermissionPolicy, PermissionUpdateType, From 1f1e7137d1aabf0bb805d64baebf2bb70441373f Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 11:07:18 -0600 Subject: [PATCH 6/7] Add smart wallet contract support --- sdks/node-sdk/src/Client.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index a1eb69562..b84e1c37a 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -204,6 +204,15 @@ export class Client { void this.#innerClient.addSignature(signatureType, signatureBytes); } + async addScwSignature( + type: SignatureRequestType, + bytes: Uint8Array, + chainId: bigint, + blockNumber?: bigint, + ) { + return this.#innerClient.addScwSignature(type, bytes, chainId, blockNumber); + } + async applySignatures() { return this.#innerClient.applySignatureRequests(); } From 31ca82d9aa612bb3c0cd099b2793bf516cc52be4 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Wed, 13 Nov 2024 11:54:50 -0600 Subject: [PATCH 7/7] Create ninety-moons-agree.md --- .changeset/ninety-moons-agree.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/ninety-moons-agree.md diff --git a/.changeset/ninety-moons-agree.md b/.changeset/ninety-moons-agree.md new file mode 100644 index 000000000..5a046b068 --- /dev/null +++ b/.changeset/ninety-moons-agree.md @@ -0,0 +1,5 @@ +--- +"@xmtp/node-sdk": patch +--- + +Update Node SDK