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 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/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 4eb9214df..b84e1c37a 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, @@ -50,10 +52,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 */ @@ -73,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 & @@ -96,7 +98,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 = @@ -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, @@ -113,9 +124,9 @@ export class Client { dbPath, inboxId, accountAddress, - options?.encryptionKey, + encryptionKey, options?.requestHistorySync, - options?.logging ?? "off", + logOptions, ), [new GroupUpdatedCodec(), new TextCodec(), ...(options?.codecs ?? [])], ); @@ -182,7 +193,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( @@ -192,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(); } diff --git a/sdks/node-sdk/src/index.ts b/sdks/node-sdk/src/index.ts index bfbdfed7e..aef488ac5 100644 --- a/sdks/node-sdk/src/index.ts +++ b/sdks/node-sdk/src/index.ts @@ -10,5 +10,35 @@ 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, + LogOptions, + Message, + PermissionPolicySet, +} from "@xmtp/node-bindings"; +export { + ConsentEntityType, + ConsentState, + ConversationType, + DeliveryStatus, + GroupMember, + GroupMembershipState, + GroupMessageKind, + GroupMetadata, + GroupPermissions, + GroupPermissionsOptions, + Level, + PermissionLevel, + PermissionPolicy, + PermissionUpdateType, + SignatureRequestType, + SortDirection, +} from "@xmtp/node-bindings"; export { generateInboxId, getInboxIdForAddress } from "./helpers/inboxId"; 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 () => { 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`), }); 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"