Skip to content

Commit

Permalink
Add static canMessage to Client
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Nov 15, 2024
1 parent c8249b8 commit d7e39b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sdks/browser-sdk/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,23 @@ export class Client extends ClientWorkerClass {
return this.sendMessage("canMessage", { accountAddresses });
}

static async canMessage(accountAddresses: string[], env?: XmtpEnv) {
const accountAddress = "0x0000000000000000000000000000000000000000";
const signer: Signer = {
getAddress: () => accountAddress,
signMessage: () => new Uint8Array(),
};
const client = await Client.create(
signer,
window.crypto.getRandomValues(new Uint8Array(32)),
{
disableAutoRegister: true,
env,
},
);
return client.canMessage(accountAddresses);
}

async findInboxIdByAddress(address: string) {
return this.sendMessage("findInboxIdByAddress", { address });
}
Expand Down
10 changes: 10 additions & 0 deletions sdks/browser-sdk/test/Client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ConsentEntityType, ConsentState } from "@xmtp/wasm-bindings";
import { v4 } from "uuid";
import { describe, expect, it } from "vitest";
import { Client } from "@/Client";
import { Conversation } from "@/Conversation";
import {
createClient,
Expand Down Expand Up @@ -35,6 +36,15 @@ describe.concurrent("Client", () => {
});
});

it("should be able to check if can message without client instance", async () => {
const user = createUser();
await createRegisteredClient(user);
const canMessage = await Client.canMessage([user.account.address], "local");
expect(Object.fromEntries(canMessage)).toEqual({
[user.account.address.toLowerCase()]: true,
});
});

it("should get an inbox ID from an address", async () => {
const user = createUser();
const client = await createRegisteredClient(user);
Expand Down

0 comments on commit d7e39b8

Please sign in to comment.