@xmtp/browser-sdk 2.2.1 → 3.0.0

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/src/Utils.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Identifier } from "@xmtp/wasm-bindings";
2
2
  import type { XmtpEnv } from "@/types/options";
3
+ import { toSafeSigner, type Signer } from "@/utils/signer";
3
4
  import { UtilsWorkerClass } from "@/UtilsWorkerClass";
4
5
 
5
6
  /**
@@ -43,4 +44,80 @@ export class Utils extends UtilsWorkerClass {
43
44
  env,
44
45
  });
45
46
  }
47
+
48
+ /**
49
+ * Creates signature text for revoking installations
50
+ *
51
+ * WARNING: This function should be used with caution. It is only provided
52
+ * for use in special cases where the provided workflows do not meet the
53
+ * requirements of an application.
54
+ *
55
+ * It is highly recommended to use the `revokeInstallations` method instead.
56
+ *
57
+ * @param env - The environment to use
58
+ * @param identifier - The identifier to revoke installations for
59
+ * @param inboxId - The inbox ID to revoke installations for
60
+ * @param installationIds - The installation IDs to revoke
61
+ * @returns The signature text
62
+ */
63
+ async revokeInstallationsSignatureText(
64
+ identifier: Identifier,
65
+ inboxId: string,
66
+ installationIds: Uint8Array[],
67
+ env?: XmtpEnv,
68
+ ) {
69
+ return this.sendMessage("utils.revokeInstallationsSignatureText", {
70
+ env,
71
+ identifier,
72
+ inboxId,
73
+ installationIds,
74
+ });
75
+ }
76
+
77
+ /**
78
+ * Revokes installations for a given inbox ID
79
+ *
80
+ * @param env - The environment to use
81
+ * @param signer - The signer to use
82
+ * @param inboxId - The inbox ID to revoke installations for
83
+ * @param installationIds - The installation IDs to revoke
84
+ * @returns Promise that resolves with the result of the revoke installations operation
85
+ */
86
+ async revokeInstallations(
87
+ signer: Signer,
88
+ inboxId: string,
89
+ installationIds: Uint8Array[],
90
+ env?: XmtpEnv,
91
+ ) {
92
+ const identifier = await signer.getIdentifier();
93
+ const signatureText = await this.revokeInstallationsSignatureText(
94
+ identifier,
95
+ inboxId,
96
+ installationIds,
97
+ env,
98
+ );
99
+ const signature = await signer.signMessage(signatureText);
100
+ const safeSigner = await toSafeSigner(signer, signature);
101
+
102
+ return this.sendMessage("utils.revokeInstallations", {
103
+ signer: safeSigner,
104
+ inboxId,
105
+ installationIds,
106
+ env,
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Gets the inbox state for the specified inbox IDs without a client
112
+ *
113
+ * @param inboxIds - The inbox IDs to get the state for
114
+ * @param env - The environment to use
115
+ * @returns The inbox state for the specified inbox IDs
116
+ */
117
+ async inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv) {
118
+ return this.sendMessage("utils.inboxStateFromInboxIds", {
119
+ inboxIds,
120
+ env,
121
+ });
122
+ }
46
123
  }
@@ -3,26 +3,27 @@ import {
3
3
  type Client,
4
4
  type Identifier,
5
5
  type KeyPackageStatus,
6
- type SignatureRequestType,
6
+ type SignatureRequestHandle,
7
7
  } from "@xmtp/wasm-bindings";
8
- import { HistorySyncUrls } from "@/constants";
9
8
  import type { ClientOptions } from "@/types/options";
10
9
  import { createClient } from "@/utils/createClient";
10
+ import type { SafeSigner } from "@/utils/signer";
11
11
  import { WorkerConversations } from "@/WorkerConversations";
12
+ import { WorkerDebugInformation } from "@/WorkerDebugInformation";
12
13
  import { WorkerPreferences } from "@/WorkerPreferences";
13
14
 
14
15
  export class WorkerClient {
15
16
  #client: Client;
16
17
  #conversations: WorkerConversations;
17
- #options?: ClientOptions;
18
+ #debugInformation: WorkerDebugInformation;
18
19
  #preferences: WorkerPreferences;
19
20
 
20
21
  constructor(client: Client, options?: ClientOptions) {
21
22
  this.#client = client;
22
23
  const conversations = client.conversations();
23
24
  this.#conversations = new WorkerConversations(this, conversations);
25
+ this.#debugInformation = new WorkerDebugInformation(client, options);
24
26
  this.#preferences = new WorkerPreferences(client, conversations);
25
- this.#options = options;
26
27
  }
27
28
 
28
29
  static async create(
@@ -57,87 +58,81 @@ export class WorkerClient {
57
58
  return this.#conversations;
58
59
  }
59
60
 
61
+ get debugInformation() {
62
+ return this.#debugInformation;
63
+ }
64
+
60
65
  get preferences() {
61
66
  return this.#preferences;
62
67
  }
63
68
 
64
- createInboxSignatureText() {
65
- try {
66
- return this.#client.createInboxSignatureText();
67
- } catch {
68
- return undefined;
69
- }
69
+ async canMessage(identifiers: Identifier[]) {
70
+ return this.#client.canMessage(identifiers) as Promise<
71
+ Map<string, boolean>
72
+ >;
70
73
  }
71
74
 
72
- async addAccountSignatureText(identifier: Identifier) {
73
- try {
74
- return await this.#client.addWalletSignatureText(identifier);
75
- } catch {
76
- return undefined;
75
+ async addSignature(
76
+ signatureRequest: SignatureRequestHandle,
77
+ signer: SafeSigner,
78
+ ) {
79
+ switch (signer.type) {
80
+ case "SCW":
81
+ await signatureRequest.addScwSignature(
82
+ signer.identifier,
83
+ signer.signature,
84
+ signer.chainId,
85
+ signer.blockNumber,
86
+ );
87
+ break;
88
+ case "EOA":
89
+ await signatureRequest.addEcdsaSignature(signer.signature);
90
+ break;
77
91
  }
78
92
  }
79
93
 
80
- async removeAccountSignatureText(identifier: Identifier) {
81
- try {
82
- return await this.#client.revokeWalletSignatureText(identifier);
83
- } catch {
84
- return undefined;
85
- }
94
+ async applySignatureRequest(signatureRequest: SignatureRequestHandle) {
95
+ return this.#client.applySignatureRequest(signatureRequest);
86
96
  }
87
97
 
88
- async revokeAllAOtherInstallationsSignatureText() {
89
- try {
90
- return await this.#client.revokeAllOtherInstallationsSignatureText();
91
- } catch {
92
- return undefined;
93
- }
98
+ async processSignatureRequest(
99
+ signer: SafeSigner,
100
+ signatureRequest: SignatureRequestHandle,
101
+ ) {
102
+ await this.addSignature(signatureRequest, signer);
103
+ await this.applySignatureRequest(signatureRequest);
94
104
  }
95
105
 
96
- async revokeInstallationsSignatureText(installationIds: Uint8Array[]) {
97
- try {
98
- return await this.#client.revokeInstallationsSignatureText(
99
- installationIds,
100
- );
101
- } catch {
102
- return undefined;
103
- }
106
+ createInboxSignatureRequest() {
107
+ return this.#client.createInboxSignatureRequest();
104
108
  }
105
109
 
106
- async changeRecoveryIdentifierSignatureText(identifier: Identifier) {
107
- try {
108
- return await this.#client.changeRecoveryIdentifierSignatureText(
109
- identifier,
110
- );
111
- } catch {
112
- return undefined;
113
- }
110
+ async addAccountSignatureRequest(newAccountIdentifier: Identifier) {
111
+ return this.#client.addWalletSignatureRequest(newAccountIdentifier);
114
112
  }
115
113
 
116
- async addEcdsaSignature(type: SignatureRequestType, bytes: Uint8Array) {
117
- return this.#client.addEcdsaSignature(type, bytes);
114
+ async removeAccountSignatureRequest(identifier: Identifier) {
115
+ return this.#client.revokeWalletSignatureRequest(identifier);
118
116
  }
119
117
 
120
- async addScwSignature(
121
- type: SignatureRequestType,
122
- bytes: Uint8Array,
123
- chainId: bigint,
124
- blockNumber?: bigint,
125
- ) {
126
- return this.#client.addScwSignature(type, bytes, chainId, blockNumber);
118
+ async revokeAllOtherInstallationsSignatureRequest() {
119
+ return this.#client.revokeAllOtherInstallationsSignatureRequest();
127
120
  }
128
121
 
129
- async applySignatures() {
130
- return this.#client.applySignatureRequests();
122
+ async revokeInstallationsSignatureRequest(installationIds: Uint8Array[]) {
123
+ return this.#client.revokeInstallationsSignatureRequest(installationIds);
131
124
  }
132
125
 
133
- async canMessage(identifiers: Identifier[]) {
134
- return this.#client.canMessage(identifiers) as Promise<
135
- Map<string, boolean>
136
- >;
126
+ async changeRecoveryIdentifierSignatureRequest(identifier: Identifier) {
127
+ return this.#client.changeRecoveryIdentifierSignatureRequest(identifier);
137
128
  }
138
129
 
139
- async registerIdentity() {
140
- return this.#client.registerIdentity();
130
+ async registerIdentity(
131
+ signer: SafeSigner,
132
+ signatureRequest: SignatureRequestHandle,
133
+ ) {
134
+ await this.addSignature(signatureRequest, signer);
135
+ await this.#client.registerIdentity(signatureRequest);
141
136
  }
142
137
 
143
138
  async findInboxIdByIdentifier(identifier: Identifier) {
@@ -181,27 +176,4 @@ export class WorkerClient {
181
176
  installationIds,
182
177
  ) as Promise<Map<string, KeyPackageStatus>>;
183
178
  }
184
-
185
- apiStatistics() {
186
- return this.#client.apiStatistics();
187
- }
188
-
189
- apiIdentityStatistics() {
190
- return this.#client.apiIdentityStatistics();
191
- }
192
-
193
- apiAggregateStatistics() {
194
- return this.#client.apiAggregateStatistics();
195
- }
196
-
197
- clearAllStatistics() {
198
- this.#client.clearAllStatistics();
199
- }
200
-
201
- async uploadDebugArchive(serverUrl?: string) {
202
- const env = this.#options?.env || "dev";
203
- const historySyncUrl =
204
- this.#options?.historySyncUrl || HistorySyncUrls[env];
205
- return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
206
- }
207
179
  }
@@ -0,0 +1,41 @@
1
+ import type { Client } from "@xmtp/wasm-bindings";
2
+ import { HistorySyncUrls } from "@/constants";
3
+ import type { ClientOptions } from "@/types/options";
4
+
5
+ /**
6
+ * Debug information helpers for the client
7
+ *
8
+ * This class is not intended to be initialized directly.
9
+ */
10
+ export class WorkerDebugInformation {
11
+ #client: Client;
12
+ #options?: ClientOptions;
13
+
14
+ constructor(client: Client, options?: ClientOptions) {
15
+ this.#client = client;
16
+ this.#options = options;
17
+ }
18
+
19
+ apiStatistics() {
20
+ return this.#client.apiStatistics();
21
+ }
22
+
23
+ apiIdentityStatistics() {
24
+ return this.#client.apiIdentityStatistics();
25
+ }
26
+
27
+ apiAggregateStatistics() {
28
+ return this.#client.apiAggregateStatistics();
29
+ }
30
+
31
+ clearAllStatistics() {
32
+ this.#client.clearAllStatistics();
33
+ }
34
+
35
+ uploadDebugArchive(serverUrl?: string) {
36
+ const env = this.#options?.env || "dev";
37
+ const historySyncUrl =
38
+ this.#options?.historySyncUrl || HistorySyncUrls[env];
39
+ return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
40
+ }
41
+ }
package/src/index.ts CHANGED
@@ -47,8 +47,9 @@ export {
47
47
  PermissionPolicy,
48
48
  PermissionPolicySet,
49
49
  PermissionUpdateType,
50
- SignatureRequestType,
50
+ SignatureRequestHandle,
51
51
  SortDirection,
52
52
  } from "@xmtp/wasm-bindings";
53
- export type { Signer } from "./utils/signer";
53
+ export type { Signer, SafeSigner, EOASigner, SCWSigner } from "./utils/signer";
54
+ export { toSafeSigner } from "./utils/signer";
54
55
  export * from "./utils/errors";
@@ -1,10 +1,7 @@
1
- import type { Identifier, SignatureRequestType } from "@xmtp/wasm-bindings";
1
+ import type { Identifier } from "@xmtp/wasm-bindings";
2
2
  import type { ClientOptions } from "@/types/options";
3
- import type {
4
- SafeApiStats,
5
- SafeIdentityStats,
6
- SafeKeyPackageStatus,
7
- } from "@/utils/conversions";
3
+ import type { SafeKeyPackageStatus } from "@/utils/conversions";
4
+ import type { SafeSigner } from "@/utils/signer";
8
5
 
9
6
  export type ClientAction =
10
7
  | {
@@ -20,81 +17,142 @@ export type ClientAction =
20
17
  options?: ClientOptions;
21
18
  };
22
19
  }
20
+ | {
21
+ action: "client.applySignatureRequest";
22
+ id: string;
23
+ result: undefined;
24
+ data: {
25
+ signer: SafeSigner;
26
+ signatureRequestId: string;
27
+ };
28
+ }
23
29
  | {
24
30
  action: "client.createInboxSignatureText";
25
31
  id: string;
26
- result: string | undefined;
27
- data: undefined;
32
+ result: {
33
+ signatureText?: string;
34
+ signatureRequestId?: string;
35
+ };
36
+ data: {
37
+ signatureRequestId: string;
38
+ };
28
39
  }
29
40
  | {
30
41
  action: "client.addAccountSignatureText";
31
42
  id: string;
32
- result: string | undefined;
43
+ result: {
44
+ signatureText: string;
45
+ signatureRequestId: string;
46
+ };
33
47
  data: {
34
48
  newIdentifier: Identifier;
49
+ signatureRequestId: string;
35
50
  };
36
51
  }
37
52
  | {
38
53
  action: "client.removeAccountSignatureText";
39
54
  id: string;
40
- result: string | undefined;
55
+ result: {
56
+ signatureText: string;
57
+ signatureRequestId: string;
58
+ };
41
59
  data: {
42
60
  identifier: Identifier;
61
+ signatureRequestId: string;
43
62
  };
44
63
  }
45
64
  | {
46
65
  action: "client.revokeAllOtherInstallationsSignatureText";
47
66
  id: string;
48
- result: string | undefined;
49
- data: undefined;
67
+ result: {
68
+ signatureText: string;
69
+ signatureRequestId: string;
70
+ };
71
+ data: {
72
+ signatureRequestId: string;
73
+ };
50
74
  }
51
75
  | {
52
76
  action: "client.revokeInstallationsSignatureText";
53
77
  id: string;
54
- result: string | undefined;
78
+ result: {
79
+ signatureText: string;
80
+ signatureRequestId: string;
81
+ };
55
82
  data: {
56
83
  installationIds: Uint8Array[];
84
+ signatureRequestId: string;
57
85
  };
58
86
  }
59
87
  | {
60
88
  action: "client.changeRecoveryIdentifierSignatureText";
61
89
  id: string;
62
- result: string | undefined;
90
+ result: {
91
+ signatureText: string;
92
+ signatureRequestId: string;
93
+ };
63
94
  data: {
64
95
  identifier: Identifier;
96
+ signatureRequestId: string;
65
97
  };
66
98
  }
67
99
  | {
68
- action: "client.addEcdsaSignature";
100
+ action: "client.registerIdentity";
69
101
  id: string;
70
102
  result: undefined;
71
103
  data: {
72
- type: SignatureRequestType;
73
- bytes: Uint8Array;
104
+ signer: SafeSigner;
105
+ signatureRequestId: string;
74
106
  };
75
107
  }
76
108
  | {
77
- action: "client.addScwSignature";
109
+ action: "client.addAccount";
78
110
  id: string;
79
111
  result: undefined;
80
112
  data: {
81
- type: SignatureRequestType;
82
- bytes: Uint8Array;
83
- chainId: bigint;
84
- blockNumber?: bigint;
113
+ identifier: Identifier;
114
+ signer: SafeSigner;
115
+ signatureRequestId: string;
85
116
  };
86
117
  }
87
118
  | {
88
- action: "client.applySignatures";
119
+ action: "client.removeAccount";
89
120
  id: string;
90
121
  result: undefined;
91
- data: undefined;
122
+ data: {
123
+ identifier: Identifier;
124
+ signer: SafeSigner;
125
+ signatureRequestId: string;
126
+ };
92
127
  }
93
128
  | {
94
- action: "client.registerIdentity";
129
+ action: "client.revokeAllOtherInstallations";
95
130
  id: string;
96
131
  result: undefined;
97
- data: undefined;
132
+ data: {
133
+ signer: SafeSigner;
134
+ signatureRequestId: string;
135
+ };
136
+ }
137
+ | {
138
+ action: "client.changeRecoveryIdentifier";
139
+ id: string;
140
+ result: undefined;
141
+ data: {
142
+ identifier: Identifier;
143
+ signer: SafeSigner;
144
+ signatureRequestId: string;
145
+ };
146
+ }
147
+ | {
148
+ action: "client.revokeInstallations";
149
+ id: string;
150
+ result: undefined;
151
+ data: {
152
+ installationIds: Uint8Array[];
153
+ signer: SafeSigner;
154
+ signatureRequestId: string;
155
+ };
98
156
  }
99
157
  | {
100
158
  action: "client.isRegistered";
@@ -152,36 +210,4 @@ export type ClientAction =
152
210
  data: {
153
211
  installationIds: string[];
154
212
  };
155
- }
156
- | {
157
- action: "client.apiStatistics";
158
- id: string;
159
- result: SafeApiStats;
160
- data: undefined;
161
- }
162
- | {
163
- action: "client.apiIdentityStatistics";
164
- id: string;
165
- result: SafeIdentityStats;
166
- data: undefined;
167
- }
168
- | {
169
- action: "client.apiAggregateStatistics";
170
- id: string;
171
- result: string;
172
- data: undefined;
173
- }
174
- | {
175
- action: "client.clearAllStatistics";
176
- id: string;
177
- result: undefined;
178
- data: undefined;
179
- }
180
- | {
181
- action: "client.uploadDebugArchive";
182
- id: string;
183
- result: string;
184
- data: {
185
- serverUrl?: string;
186
- };
187
213
  };
@@ -0,0 +1,35 @@
1
+ import type { SafeApiStats, SafeIdentityStats } from "@/utils/conversions";
2
+
3
+ export type DebugInformationAction =
4
+ | {
5
+ action: "debugInformation.apiStatistics";
6
+ id: string;
7
+ result: SafeApiStats;
8
+ data: undefined;
9
+ }
10
+ | {
11
+ action: "debugInformation.apiIdentityStatistics";
12
+ id: string;
13
+ result: SafeIdentityStats;
14
+ data: undefined;
15
+ }
16
+ | {
17
+ action: "debugInformation.apiAggregateStatistics";
18
+ id: string;
19
+ result: string;
20
+ data: undefined;
21
+ }
22
+ | {
23
+ action: "debugInformation.clearAllStatistics";
24
+ id: string;
25
+ result: undefined;
26
+ data: undefined;
27
+ }
28
+ | {
29
+ action: "debugInformation.uploadDebugArchive";
30
+ id: string;
31
+ result: string;
32
+ data: {
33
+ serverUrl?: string;
34
+ };
35
+ };
@@ -1,5 +1,7 @@
1
1
  import type { Identifier } from "@xmtp/wasm-bindings";
2
2
  import type { XmtpEnv } from "@/types/options";
3
+ import type { SafeInboxState } from "@/utils/conversions";
4
+ import type { SafeSigner } from "@/utils/signer";
3
5
 
4
6
  export type UtilsWorkerAction =
5
7
  | {
@@ -26,4 +28,35 @@ export type UtilsWorkerAction =
26
28
  identifier: Identifier;
27
29
  env?: XmtpEnv;
28
30
  };
31
+ }
32
+ | {
33
+ action: "utils.revokeInstallationsSignatureText";
34
+ id: string;
35
+ result: string;
36
+ data: {
37
+ env?: XmtpEnv;
38
+ identifier: Identifier;
39
+ inboxId: string;
40
+ installationIds: Uint8Array[];
41
+ };
42
+ }
43
+ | {
44
+ action: "utils.revokeInstallations";
45
+ id: string;
46
+ result: undefined;
47
+ data: {
48
+ env?: XmtpEnv;
49
+ signer: SafeSigner;
50
+ inboxId: string;
51
+ installationIds: Uint8Array[];
52
+ };
53
+ }
54
+ | {
55
+ action: "utils.inboxStateFromInboxIds";
56
+ id: string;
57
+ result: SafeInboxState[];
58
+ data: {
59
+ inboxIds: string[];
60
+ env?: XmtpEnv;
61
+ };
29
62
  };
@@ -1,6 +1,7 @@
1
1
  import type { ClientAction } from "@/types/actions/client";
2
2
  import type { ConversationAction } from "@/types/actions/conversation";
3
3
  import type { ConversationsAction } from "@/types/actions/conversations";
4
+ import type { DebugInformationAction } from "@/types/actions/debugInformation";
4
5
  import type { DmAction } from "@/types/actions/dm";
5
6
  import type { GroupAction } from "@/types/actions/group";
6
7
  import type { PreferencesAction } from "@/types/actions/preferences";
@@ -26,7 +27,8 @@ export type ClientWorkerAction =
26
27
  | ConversationsAction
27
28
  | DmAction
28
29
  | GroupAction
29
- | PreferencesAction;
30
+ | PreferencesAction
31
+ | DebugInformationAction;
30
32
 
31
33
  export type ActionName<T extends UnknownAction> = T["action"];
32
34
 
@@ -403,14 +403,14 @@ export const toSafeInstallation = (
403
403
  });
404
404
 
405
405
  export type SafeInboxState = {
406
- accountIdentifiers: Identifier[];
406
+ identifiers: Identifier[];
407
407
  inboxId: string;
408
408
  installations: SafeInstallation[];
409
409
  recoveryIdentifier: Identifier;
410
410
  };
411
411
 
412
412
  export const toSafeInboxState = (inboxState: InboxState): SafeInboxState => ({
413
- accountIdentifiers: inboxState.accountIdentifiers,
413
+ identifiers: inboxState.accountIdentifiers,
414
414
  inboxId: inboxState.inboxId,
415
415
  installations: inboxState.installations.map(toSafeInstallation),
416
416
  recoveryIdentifier: inboxState.recoveryIdentifier,