From fcd0e440914c7f623803b1617df24f8d9c8f40d9 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 2 Dec 2024 16:42:14 -0600 Subject: [PATCH 1/4] 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 6471cfaa..fe7dd54e 100644 --- a/sdks/node-sdk/package.json +++ b/sdks/node-sdk/package.json @@ -53,7 +53,7 @@ "@xmtp/content-type-group-updated": "^1.0.1", "@xmtp/content-type-primitives": "^1.0.3", "@xmtp/content-type-text": "^1.0.1", - "@xmtp/node-bindings": "^0.0.27", + "@xmtp/node-bindings": "^0.0.28", "@xmtp/proto": "^3.72.3" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 3a3dabbc..5a7d61a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5086,10 +5086,10 @@ __metadata: languageName: node linkType: hard -"@xmtp/node-bindings@npm:^0.0.27": - version: 0.0.27 - resolution: "@xmtp/node-bindings@npm:0.0.27" - checksum: 10/e5c737f41169caa58b55241e7f8e544076e8f7d7e3ba9703703885bda73d352c26984a8a4a4d1277a30d3837da9a0023a94dfadf40b5c8f8f3b6366260f3d20e +"@xmtp/node-bindings@npm:^0.0.28": + version: 0.0.28 + resolution: "@xmtp/node-bindings@npm:0.0.28" + checksum: 10/0ceea72582926dcce03c8e3839b7101d7ce4aef56a55b46421c2e46e96f65c90a224b1649ff765c1f3cb1e2e21a730d1891bb369260c94712066b85d358fb6f4 languageName: node linkType: hard @@ -5117,7 +5117,7 @@ __metadata: "@xmtp/content-type-group-updated": "npm:^1.0.1" "@xmtp/content-type-primitives": "npm:^1.0.3" "@xmtp/content-type-text": "npm:^1.0.1" - "@xmtp/node-bindings": "npm:^0.0.27" + "@xmtp/node-bindings": "npm:^0.0.28" "@xmtp/proto": "npm:^3.72.3" "@xmtp/xmtp-js": "workspace:^" fast-glob: "npm:^3.3.2" From 13d1317965f4d825171e4da6a310751ca25f4a13 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 2 Dec 2024 16:42:44 -0600 Subject: [PATCH 2/4] Add static methods to client --- sdks/node-sdk/src/Client.ts | 34 ++++++++++++++++++------------- sdks/node-sdk/test/Client.test.ts | 22 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/sdks/node-sdk/src/Client.ts b/sdks/node-sdk/src/Client.ts index 66416229..674b4c15 100644 --- a/sdks/node-sdk/src/Client.ts +++ b/sdks/node-sdk/src/Client.ts @@ -15,6 +15,8 @@ import { generateInboxId, getInboxIdForAddress, GroupMessageKind, + isAddressAuthorized as isAddressAuthorizedBinding, + isInstallationAuthorized as isInstallationAuthorizedBinding, LogLevel, SignatureRequestType, verifySignedWithPublicKey as verifySignedWithPublicKeyBinding, @@ -172,20 +174,6 @@ export class Client { return this.#innerClient.isRegistered(); } - async isAddressAuthorized( - inboxId: string, - address: string, - ): Promise { - return this.#innerClient.isAddressAuthorized(inboxId, address); - } - - async isInstallationAuthorized( - inboxId: string, - installationId: Uint8Array, - ): Promise { - return this.#innerClient.isInstallationAuthorized(inboxId, installationId); - } - async #createInboxSignatureText() { try { const signatureText = await this.#innerClient.createInboxSignatureText(); @@ -452,4 +440,22 @@ export class Client { return false; } } + + static async isAddressAuthorized( + inboxId: string, + address: string, + options?: NetworkOptions, + ): Promise { + const host = options?.apiUrl || ApiUrls[options?.env || "dev"]; + return await isAddressAuthorizedBinding(host, inboxId, address); + } + + static async isInstallationAuthorized( + inboxId: string, + installation: Uint8Array, + options?: NetworkOptions, + ): Promise { + const host = options?.apiUrl || ApiUrls[options?.env || "dev"]; + return await isInstallationAuthorizedBinding(host, inboxId, installation); + } } diff --git a/sdks/node-sdk/test/Client.test.ts b/sdks/node-sdk/test/Client.test.ts index 59e742f2..b382dde0 100644 --- a/sdks/node-sdk/test/Client.test.ts +++ b/sdks/node-sdk/test/Client.test.ts @@ -231,4 +231,26 @@ describe("Client", () => { ); expect(verified4).toBe(false); }); + + it("should check if an address is authorized", async () => { + const user = createUser(); + const client = await createRegisteredClient(user); + const authorized = await Client.isAddressAuthorized( + client.inboxId, + user.account.address.toLowerCase(), + { env: "local" }, + ); + expect(authorized).toBe(true); + }); + + it("should check if an installation is authorized", async () => { + const user = createUser(); + const client = await createRegisteredClient(user); + const authorized = await Client.isInstallationAuthorized( + client.inboxId, + client.installationIdBytes, + { env: "local" }, + ); + expect(authorized).toBe(true); + }); }); From 8acbbe151f7795bdc58b34144d69ff604975f457 Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 2 Dec 2024 16:44:42 -0600 Subject: [PATCH 3/4] Create clean-students-sell.md --- .changeset/clean-students-sell.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clean-students-sell.md diff --git a/.changeset/clean-students-sell.md b/.changeset/clean-students-sell.md new file mode 100644 index 00000000..64c7a060 --- /dev/null +++ b/.changeset/clean-students-sell.md @@ -0,0 +1,5 @@ +--- +"@xmtp/node-sdk": patch +--- + +Add static authorization methods to Node SDK Client From c8d7dea557c5cb7cd67680baa4e4460833050c2d Mon Sep 17 00:00:00 2001 From: Ry Racherbaumer Date: Mon, 2 Dec 2024 16:51:47 -0600 Subject: [PATCH 4/4] Add more tests --- sdks/node-sdk/test/Client.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sdks/node-sdk/test/Client.test.ts b/sdks/node-sdk/test/Client.test.ts index b382dde0..33965c46 100644 --- a/sdks/node-sdk/test/Client.test.ts +++ b/sdks/node-sdk/test/Client.test.ts @@ -241,6 +241,13 @@ describe("Client", () => { { env: "local" }, ); expect(authorized).toBe(true); + + const notAuthorized = await Client.isAddressAuthorized( + client.inboxId, + "0x1234567890123456789012345678901234567890", + { env: "local" }, + ); + expect(notAuthorized).toBe(false); }); it("should check if an installation is authorized", async () => { @@ -252,5 +259,12 @@ describe("Client", () => { { env: "local" }, ); expect(authorized).toBe(true); + + const notAuthorized = await Client.isInstallationAuthorized( + client.inboxId, + new Uint8Array(32), + { env: "local" }, + ); + expect(notAuthorized).toBe(false); }); });