@xmtp/browser-sdk 6.4.0 → 6.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +112 -54
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +131 -15
- package/src/Conversations.ts +1 -1
- package/src/WorkerClient.ts +14 -7
- package/src/WorkerConversation.ts +4 -4
- package/src/constants.ts +5 -0
- package/src/index.ts +5 -1
- package/src/types/actions/client.ts +10 -2
- package/src/types/options.ts +27 -13
- package/src/utils/createBackend.ts +45 -0
- package/src/utils/createClient.ts +58 -27
- package/src/utils/inboxId.ts +5 -15
- package/src/utils/inboxState.ts +5 -9
- package/src/utils/installations.ts +8 -17
- package/src/workers/client.ts +2 -1
package/src/utils/inboxId.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
generateInboxId as wasmGenerateInboxId,
|
|
3
3
|
getInboxIdForIdentifier as wasmGetInboxIdForIdentifier,
|
|
4
|
+
type Backend,
|
|
4
5
|
type Identifier,
|
|
5
6
|
} from "@xmtp/wasm-bindings";
|
|
6
|
-
import { ApiUrls } from "@/constants";
|
|
7
|
-
import type { XmtpEnv } from "@/types/options";
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Generates an inbox ID for a given identifier
|
|
@@ -22,25 +21,16 @@ export const generateInboxId = async (
|
|
|
22
21
|
};
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
|
-
* Gets the inbox ID for a specific identifier
|
|
24
|
+
* Gets the inbox ID for a specific identifier using a Backend
|
|
26
25
|
*
|
|
26
|
+
* @param backend - The Backend instance for API communication
|
|
27
27
|
* @param identifier - The identifier to get the inbox ID for
|
|
28
|
-
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
29
|
-
* @param gatewayHost - Optional gateway host override
|
|
30
28
|
* @returns Promise that resolves with the inbox ID for the identifier
|
|
31
29
|
*/
|
|
32
30
|
export const getInboxIdForIdentifier = async (
|
|
31
|
+
backend: Backend,
|
|
33
32
|
identifier: Identifier,
|
|
34
|
-
env?: XmtpEnv,
|
|
35
|
-
gatewayHost?: string,
|
|
36
33
|
): Promise<string | undefined> => {
|
|
37
34
|
await init();
|
|
38
|
-
|
|
39
|
-
const isSecure = host.startsWith("https");
|
|
40
|
-
return wasmGetInboxIdForIdentifier(
|
|
41
|
-
host,
|
|
42
|
-
gatewayHost ?? null,
|
|
43
|
-
isSecure,
|
|
44
|
-
identifier,
|
|
45
|
-
);
|
|
35
|
+
return wasmGetInboxIdForIdentifier(backend, identifier);
|
|
46
36
|
};
|
package/src/utils/inboxState.ts
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
inboxStateFromInboxIds as wasmInboxStateFromInboxIds,
|
|
3
|
+
type Backend,
|
|
3
4
|
} from "@xmtp/wasm-bindings";
|
|
4
|
-
import { ApiUrls } from "@/constants";
|
|
5
|
-
import type { XmtpEnv } from "@/types/options";
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
|
-
* Gets the inbox state for the specified inbox IDs
|
|
7
|
+
* Gets the inbox state for the specified inbox IDs using a Backend
|
|
9
8
|
*
|
|
9
|
+
* @param backend - The Backend instance for API communication
|
|
10
10
|
* @param inboxIds - The inbox IDs to get the state for
|
|
11
|
-
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
12
|
-
* @param gatewayHost - Optional gateway host override
|
|
13
11
|
* @returns The inbox state for the specified inbox IDs
|
|
14
12
|
*/
|
|
15
13
|
export const inboxStateFromInboxIds = async (
|
|
14
|
+
backend: Backend,
|
|
16
15
|
inboxIds: string[],
|
|
17
|
-
env?: XmtpEnv,
|
|
18
|
-
gatewayHost?: string,
|
|
19
16
|
) => {
|
|
20
17
|
await init();
|
|
21
|
-
|
|
22
|
-
return wasmInboxStateFromInboxIds(host, gatewayHost ?? null, inboxIds);
|
|
18
|
+
return wasmInboxStateFromInboxIds(backend, inboxIds);
|
|
23
19
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import init, {
|
|
2
2
|
applySignatureRequest,
|
|
3
3
|
revokeInstallationsSignatureRequest,
|
|
4
|
+
type Backend,
|
|
4
5
|
type Identifier,
|
|
5
6
|
type SignatureRequestHandle,
|
|
6
7
|
} from "@xmtp/wasm-bindings";
|
|
7
|
-
import { ApiUrls } from "@/constants";
|
|
8
|
-
import type { XmtpEnv } from "@/types/options";
|
|
9
8
|
import type { Signer } from "@/utils/signer";
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -17,28 +16,24 @@ import type { Signer } from "@/utils/signer";
|
|
|
17
16
|
*
|
|
18
17
|
* It is highly recommended to use the `revokeInstallations` function instead.
|
|
19
18
|
*
|
|
19
|
+
* @param backend - The Backend instance for API communication
|
|
20
20
|
* @param identifier - The identifier to revoke installations for
|
|
21
21
|
* @param inboxId - The inbox ID to revoke installations for
|
|
22
22
|
* @param installationIds - The installation IDs to revoke
|
|
23
|
-
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
24
|
-
* @param gatewayHost - Optional gateway host override
|
|
25
23
|
* @returns The signature text and signature request ID
|
|
26
24
|
*/
|
|
27
25
|
export const revokeInstallationsSignatureText = async (
|
|
26
|
+
backend: Backend,
|
|
28
27
|
identifier: Identifier,
|
|
29
28
|
inboxId: string,
|
|
30
29
|
installationIds: Uint8Array[],
|
|
31
|
-
env?: XmtpEnv,
|
|
32
|
-
gatewayHost?: string,
|
|
33
30
|
): Promise<{
|
|
34
31
|
signatureText: string;
|
|
35
32
|
signatureRequest: SignatureRequestHandle;
|
|
36
33
|
}> => {
|
|
37
34
|
await init();
|
|
38
|
-
const host = ApiUrls[env ?? "dev"];
|
|
39
35
|
const signatureRequest = revokeInstallationsSignatureRequest(
|
|
40
|
-
|
|
41
|
-
gatewayHost ?? null,
|
|
36
|
+
backend,
|
|
42
37
|
identifier,
|
|
43
38
|
inboxId,
|
|
44
39
|
installationIds,
|
|
@@ -50,32 +45,28 @@ export const revokeInstallationsSignatureText = async (
|
|
|
50
45
|
/**
|
|
51
46
|
* Revokes installations for a given inbox ID
|
|
52
47
|
*
|
|
48
|
+
* @param backend - The Backend instance for API communication
|
|
53
49
|
* @param signer - The signer to use
|
|
54
50
|
* @param inboxId - The inbox ID to revoke installations for
|
|
55
51
|
* @param installationIds - The installation IDs to revoke
|
|
56
|
-
* @param env - Optional XMTP environment configuration (default: "dev")
|
|
57
|
-
* @param gatewayHost - Optional gateway host override
|
|
58
52
|
* @returns Promise that resolves when the revoke installations operation is complete
|
|
59
53
|
*/
|
|
60
54
|
export const revokeInstallations = async (
|
|
55
|
+
backend: Backend,
|
|
61
56
|
signer: Signer,
|
|
62
57
|
inboxId: string,
|
|
63
58
|
installationIds: Uint8Array[],
|
|
64
|
-
env?: XmtpEnv,
|
|
65
|
-
gatewayHost?: string,
|
|
66
59
|
): Promise<void> => {
|
|
67
60
|
await init();
|
|
68
61
|
const identifier = await signer.getIdentifier();
|
|
69
62
|
const { signatureText, signatureRequest } =
|
|
70
63
|
await revokeInstallationsSignatureText(
|
|
64
|
+
backend,
|
|
71
65
|
identifier,
|
|
72
66
|
inboxId,
|
|
73
67
|
installationIds,
|
|
74
|
-
env,
|
|
75
|
-
gatewayHost,
|
|
76
68
|
);
|
|
77
69
|
const signature = await signer.signMessage(signatureText);
|
|
78
|
-
const host = ApiUrls[env ?? "dev"];
|
|
79
70
|
|
|
80
71
|
switch (signer.type) {
|
|
81
72
|
case "EOA":
|
|
@@ -91,5 +82,5 @@ export const revokeInstallations = async (
|
|
|
91
82
|
break;
|
|
92
83
|
}
|
|
93
84
|
|
|
94
|
-
await applySignatureRequest(
|
|
85
|
+
await applySignatureRequest(backend, signatureRequest);
|
|
95
86
|
};
|
package/src/workers/client.ts
CHANGED
|
@@ -91,6 +91,7 @@ self.onmessage = async (
|
|
|
91
91
|
action,
|
|
92
92
|
result: {
|
|
93
93
|
appVersion: maybeClient.appVersion,
|
|
94
|
+
env: maybeClient.env,
|
|
94
95
|
inboxId: maybeClient.inboxId,
|
|
95
96
|
installationId: maybeClient.installationId,
|
|
96
97
|
installationIdBytes: maybeClient.installationIdBytes,
|
|
@@ -338,7 +339,7 @@ self.onmessage = async (
|
|
|
338
339
|
break;
|
|
339
340
|
}
|
|
340
341
|
case "client.sendSyncRequest": {
|
|
341
|
-
await client.sendSyncRequest();
|
|
342
|
+
await client.sendSyncRequest(data.options, data.serverUrl);
|
|
342
343
|
postMessage({ id, action, result: undefined });
|
|
343
344
|
break;
|
|
344
345
|
}
|