@xmtp/node-sdk 3.2.0-rc2 → 3.2.1-dev.cb2628c

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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GroupUpdatedCodec, ContentTypeGroupUpdated } from '@xmtp/content-type-group-updated';
2
2
  import { ContentTypeText, TextCodec } from '@xmtp/content-type-text';
3
- import { generateInboxId as generateInboxId$1, getInboxIdForIdentifier as getInboxIdForIdentifier$1, createClient as createClient$1, revokeInstallationsSignatureRequest, applySignatureRequest, inboxStateFromInboxIds, verifySignedWithPublicKey, isAddressAuthorized, isInstallationAuthorized } from '@xmtp/node-bindings';
4
- export { ConsentEntityType, ConsentState, ConversationType, DeliveryStatus, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, IdentifierKind, LogLevel, MetadataField, PermissionLevel, PermissionPolicy, PermissionUpdateType, SignatureRequestHandle, SortDirection } from '@xmtp/node-bindings';
3
+ import { generateInboxId as generateInboxId$1, getInboxIdForIdentifier as getInboxIdForIdentifier$1, createClient as createClient$1, verifySignedWithPublicKey, isAddressAuthorized, isInstallationAuthorized } from '@xmtp/node-bindings';
4
+ export { ConsentEntityType, ConsentState, ConversationType, DeliveryStatus, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, IdentifierKind, LogLevel, MetadataField, PermissionLevel, PermissionPolicy, PermissionUpdateType, SignatureRequestType, SortDirection } from '@xmtp/node-bindings';
5
5
  import { ContentTypeId } from '@xmtp/content-type-primitives';
6
6
  import { join } from 'node:path';
7
7
  import process from 'node:process';
@@ -35,49 +35,52 @@ const HistorySyncUrls = {
35
35
  };
36
36
 
37
37
  class AsyncStream {
38
- #isDone = false;
38
+ #done = false;
39
39
  #resolveNext;
40
40
  #rejectNext;
41
41
  #queue;
42
42
  #error;
43
- onReturn;
44
- onError;
43
+ onReturn = undefined;
44
+ onError = undefined;
45
45
  constructor() {
46
46
  this.#queue = [];
47
- this.#isDone = false;
47
+ this.#resolveNext = null;
48
+ this.#rejectNext = null;
49
+ this.#error = null;
50
+ this.#done = false;
48
51
  }
49
- #done() {
52
+ #endStream() {
50
53
  this.#queue = [];
51
- this.#resolveNext = undefined;
52
- this.#rejectNext = undefined;
53
- this.#isDone = true;
54
+ this.#resolveNext = null;
55
+ this.#rejectNext = null;
56
+ this.#done = true;
54
57
  }
55
58
  get error() {
56
59
  return this.#error;
57
60
  }
58
61
  get isDone() {
59
- return this.#isDone;
62
+ return this.#done;
60
63
  }
61
64
  callback = (error, value) => {
62
- if (this.#isDone) {
63
- return;
64
- }
65
65
  if (error) {
66
66
  this.#error = error;
67
67
  if (this.#rejectNext) {
68
68
  this.#rejectNext(error);
69
- this.#done();
69
+ this.#endStream();
70
70
  this.onError?.(error);
71
71
  }
72
72
  return;
73
73
  }
74
+ if (this.#done) {
75
+ return;
76
+ }
74
77
  if (this.#resolveNext) {
75
78
  this.#resolveNext({
76
79
  done: false,
77
80
  value,
78
81
  });
79
- this.#resolveNext = undefined;
80
- this.#rejectNext = undefined;
82
+ this.#resolveNext = null;
83
+ this.#rejectNext = null;
81
84
  }
82
85
  else {
83
86
  this.#queue.push(value);
@@ -85,7 +88,7 @@ class AsyncStream {
85
88
  };
86
89
  next = () => {
87
90
  if (this.#error) {
88
- this.#done();
91
+ this.#endStream();
89
92
  this.onError?.(this.#error);
90
93
  return Promise.reject(this.#error);
91
94
  }
@@ -95,22 +98,24 @@ class AsyncStream {
95
98
  value: this.#queue.shift(),
96
99
  });
97
100
  }
101
+ if (this.#done) {
102
+ return Promise.resolve({
103
+ done: true,
104
+ value: undefined,
105
+ });
106
+ }
98
107
  return new Promise((resolve, reject) => {
99
108
  this.#resolveNext = resolve;
100
109
  this.#rejectNext = reject;
101
110
  });
102
111
  };
103
112
  return = (value) => {
104
- this.#resolveNext?.({
105
- done: true,
106
- value,
107
- });
113
+ this.#endStream();
108
114
  this.onReturn?.();
109
- this.#done();
110
- return {
115
+ return Promise.resolve({
111
116
  done: true,
112
117
  value,
113
- };
118
+ });
114
119
  };
115
120
  end = () => this.return();
116
121
  [Symbol.asyncIterator]() {
@@ -217,6 +222,29 @@ class AccountAlreadyAssociatedError extends Error {
217
222
  super(`Account already associated with inbox ${inboxId}`);
218
223
  }
219
224
  }
225
+ class GenerateSignatureError extends Error {
226
+ constructor(signatureType) {
227
+ let type = "";
228
+ switch (signatureType) {
229
+ case 0 /* SignatureRequestType.AddWallet */:
230
+ type = "add account";
231
+ break;
232
+ case 1 /* SignatureRequestType.CreateInbox */:
233
+ type = "create inbox";
234
+ break;
235
+ case 2 /* SignatureRequestType.RevokeWallet */:
236
+ type = "remove account";
237
+ break;
238
+ case 3 /* SignatureRequestType.RevokeInstallations */:
239
+ type = "revoke installations";
240
+ break;
241
+ case 4 /* SignatureRequestType.ChangeRecoveryIdentifier */:
242
+ type = "change recovery identifier";
243
+ break;
244
+ }
245
+ super(`Failed to generate ${type} signature text`);
246
+ }
247
+ }
220
248
  class InvalidGroupMembershipChangeError extends Error {
221
249
  constructor(messageId) {
222
250
  super(`Invalid group membership change for message ${messageId}`);
@@ -325,7 +353,7 @@ class Conversation {
325
353
  * @param callback - Optional callback function for handling new stream values
326
354
  * @returns Stream instance for new messages
327
355
  */
328
- stream(callback, onFail) {
356
+ stream(callback) {
329
357
  const asyncStream = new AsyncStream();
330
358
  const stream = this.#conversation.stream((error, value) => {
331
359
  let err = error;
@@ -340,10 +368,8 @@ class Conversation {
340
368
  }
341
369
  asyncStream.callback(err, message);
342
370
  callback?.(err, message);
343
- }, onFail ?? (() => { }));
344
- asyncStream.onReturn = () => {
345
- stream.end();
346
- };
371
+ });
372
+ asyncStream.onReturn = stream.end.bind(stream);
347
373
  return asyncStream;
348
374
  }
349
375
  /**
@@ -895,7 +921,7 @@ class Conversations {
895
921
  * @param callback - Optional callback function for handling new stream value
896
922
  * @returns Stream instance for new conversations
897
923
  */
898
- stream(callback, onFail) {
924
+ stream(callback) {
899
925
  const asyncStream = new AsyncStream();
900
926
  const stream = this.#conversations.stream((err, value) => {
901
927
  if (err) {
@@ -925,7 +951,7 @@ class Conversations {
925
951
  asyncStream.callback(error, undefined);
926
952
  callback?.(error, undefined);
927
953
  });
928
- }, onFail ?? (() => { }));
954
+ });
929
955
  asyncStream.onReturn = stream.end.bind(stream);
930
956
  return asyncStream;
931
957
  }
@@ -935,7 +961,7 @@ class Conversations {
935
961
  * @param callback - Optional callback function for handling new stream value
936
962
  * @returns Stream instance for new group conversations
937
963
  */
938
- streamGroups(callback, onFail) {
964
+ streamGroups(callback) {
939
965
  const asyncStream = new AsyncStream();
940
966
  const stream = this.#conversations.stream((error, value) => {
941
967
  let err = error;
@@ -950,7 +976,7 @@ class Conversations {
950
976
  }
951
977
  asyncStream.callback(err, group);
952
978
  callback?.(err, group);
953
- }, onFail ?? (() => { }), 1 /* ConversationType.Group */);
979
+ }, 1 /* ConversationType.Group */);
954
980
  asyncStream.onReturn = stream.end.bind(stream);
955
981
  return asyncStream;
956
982
  }
@@ -960,7 +986,7 @@ class Conversations {
960
986
  * @param callback - Optional callback function for handling new stream value
961
987
  * @returns Stream instance for new DM conversations
962
988
  */
963
- streamDms(callback, onFail) {
989
+ streamDms(callback) {
964
990
  const asyncStream = new AsyncStream();
965
991
  const stream = this.#conversations.stream((error, value) => {
966
992
  let err = error;
@@ -975,7 +1001,7 @@ class Conversations {
975
1001
  }
976
1002
  asyncStream.callback(err, dm);
977
1003
  callback?.(err, dm);
978
- }, onFail ?? (() => { }), 0 /* ConversationType.Dm */);
1004
+ }, 0 /* ConversationType.Dm */);
979
1005
  asyncStream.onReturn = stream.end.bind(stream);
980
1006
  return asyncStream;
981
1007
  }
@@ -985,7 +1011,7 @@ class Conversations {
985
1011
  * @param callback - Optional callback function for handling new stream value
986
1012
  * @returns Stream instance for new messages
987
1013
  */
988
- async streamAllMessages(callback, conversationType, consentStates, onFail) {
1014
+ async streamAllMessages(callback, conversationType, consentStates) {
989
1015
  // sync conversations first
990
1016
  await this.sync();
991
1017
  const asyncStream = new AsyncStream();
@@ -1002,7 +1028,7 @@ class Conversations {
1002
1028
  }
1003
1029
  asyncStream.callback(err, message);
1004
1030
  callback?.(err, message);
1005
- }, onFail ?? (() => { }), conversationType, consentStates);
1031
+ }, conversationType, consentStates);
1006
1032
  asyncStream.onReturn = stream.end.bind(stream);
1007
1033
  return asyncStream;
1008
1034
  }
@@ -1012,8 +1038,8 @@ class Conversations {
1012
1038
  * @param callback - Optional callback function for handling new stream value
1013
1039
  * @returns Stream instance for new group messages
1014
1040
  */
1015
- async streamAllGroupMessages(callback, consentStates, onFail) {
1016
- return this.streamAllMessages(callback, 1 /* ConversationType.Group */, consentStates, onFail);
1041
+ async streamAllGroupMessages(callback, consentStates) {
1042
+ return this.streamAllMessages(callback, 1 /* ConversationType.Group */, consentStates);
1017
1043
  }
1018
1044
  /**
1019
1045
  * Creates a stream for all new DM messages
@@ -1021,8 +1047,8 @@ class Conversations {
1021
1047
  * @param callback - Optional callback function for handling new stream value
1022
1048
  * @returns Stream instance for new DM messages
1023
1049
  */
1024
- async streamAllDmMessages(callback, consentStates, onFail) {
1025
- return this.streamAllMessages(callback, 0 /* ConversationType.Dm */, consentStates, onFail);
1050
+ async streamAllDmMessages(callback, consentStates) {
1051
+ return this.streamAllMessages(callback, 0 /* ConversationType.Dm */, consentStates);
1026
1052
  }
1027
1053
  /**
1028
1054
  * Retrieves HMAC keys for all conversations
@@ -1034,37 +1060,6 @@ class Conversations {
1034
1060
  }
1035
1061
  }
1036
1062
 
1037
- /**
1038
- * Debug information helpers for the client
1039
- *
1040
- * This class is not intended to be initialized directly.
1041
- */
1042
- class DebugInformation {
1043
- #client;
1044
- #options;
1045
- constructor(client, options) {
1046
- this.#client = client;
1047
- this.#options = options;
1048
- }
1049
- apiStatistics() {
1050
- return this.#client.apiStatistics();
1051
- }
1052
- apiIdentityStatistics() {
1053
- return this.#client.apiIdentityStatistics();
1054
- }
1055
- apiAggregateStatistics() {
1056
- return this.#client.apiAggregateStatistics();
1057
- }
1058
- clearAllStatistics() {
1059
- this.#client.clearAllStatistics();
1060
- }
1061
- uploadDebugArchive(serverUrl) {
1062
- const env = this.#options?.env || "dev";
1063
- const historySyncUrl = this.#options?.historySyncUrl || HistorySyncUrls[env];
1064
- return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
1065
- }
1066
- }
1067
-
1068
1063
  /**
1069
1064
  * Manages user preferences and consent states
1070
1065
  *
@@ -1139,7 +1134,7 @@ class Preferences {
1139
1134
  * @param callback - Optional callback function for handling stream updates
1140
1135
  * @returns Stream instance for consent updates
1141
1136
  */
1142
- streamConsent(callback, onFail) {
1137
+ streamConsent(callback) {
1143
1138
  const asyncStream = new AsyncStream();
1144
1139
  const stream = this.#conversations.streamConsent((err, value) => {
1145
1140
  if (err) {
@@ -1149,7 +1144,7 @@ class Preferences {
1149
1144
  }
1150
1145
  asyncStream.callback(null, value);
1151
1146
  callback?.(null, value);
1152
- }, onFail ?? (() => { }));
1147
+ });
1153
1148
  asyncStream.onReturn = stream.end.bind(stream);
1154
1149
  return asyncStream;
1155
1150
  }
@@ -1159,7 +1154,7 @@ class Preferences {
1159
1154
  * @param callback - Optional callback function for handling stream updates
1160
1155
  * @returns Stream instance for preference updates
1161
1156
  */
1162
- streamPreferences(callback, onFail) {
1157
+ streamPreferences(callback) {
1163
1158
  const asyncStream = new AsyncStream();
1164
1159
  const stream = this.#conversations.streamPreferences((err, value) => {
1165
1160
  if (err) {
@@ -1170,7 +1165,7 @@ class Preferences {
1170
1165
  // TODO: remove this once the node bindings type is updated
1171
1166
  asyncStream.callback(null, value);
1172
1167
  callback?.(null, value);
1173
- }, onFail ?? (() => { }));
1168
+ });
1174
1169
  asyncStream.onReturn = stream.end.bind(stream);
1175
1170
  return asyncStream;
1176
1171
  }
@@ -1215,7 +1210,6 @@ const version = `${bindingsVersion.branch}@${bindingsVersion.version} (${binding
1215
1210
  class Client {
1216
1211
  #client;
1217
1212
  #conversations;
1218
- #debugInformation;
1219
1213
  #preferences;
1220
1214
  #signer;
1221
1215
  #codecs;
@@ -1254,7 +1248,6 @@ class Client {
1254
1248
  this.#client = await createClient(identifier, this.#options);
1255
1249
  const conversations = this.#client.conversations();
1256
1250
  this.#conversations = new Conversations(this, conversations);
1257
- this.#debugInformation = new DebugInformation(this.#client, this.#options);
1258
1251
  this.#preferences = new Preferences(this.#client, conversations);
1259
1252
  }
1260
1253
  /**
@@ -1359,17 +1352,6 @@ class Client {
1359
1352
  }
1360
1353
  return this.#conversations;
1361
1354
  }
1362
- /**
1363
- * Gets the debug information helpersfor this client
1364
- *
1365
- * @throws {ClientNotInitializedError} if the client is not initialized
1366
- */
1367
- get debugInformation() {
1368
- if (!this.#debugInformation) {
1369
- throw new ClientNotInitializedError();
1370
- }
1371
- return this.#debugInformation;
1372
- }
1373
1355
  /**
1374
1356
  * Gets the preferences manager for this client
1375
1357
  *
@@ -1382,42 +1364,7 @@ class Client {
1382
1364
  return this.#preferences;
1383
1365
  }
1384
1366
  /**
1385
- * Adds a signature to a signature request using the client's signer (or the
1386
- * provided signer)
1387
- *
1388
- * WARNING: This function should be used with caution. It is only provided
1389
- * for use in special cases where the provided workflows do not meet the
1390
- * requirements of an application.
1391
- *
1392
- * It is highly recommended to use the `register`, `unsafe_addAccount`,
1393
- * `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
1394
- * methods instead.
1395
- *
1396
- * @param signatureRequest - The signature request to add the signature to
1397
- * @throws {ClientNotInitializedError} if the client is not initialized
1398
- * @throws {SignerUnavailableError} if no signer is available
1399
- */
1400
- async unsafe_addSignature(signatureRequest, signer) {
1401
- if (!this.#client) {
1402
- throw new ClientNotInitializedError();
1403
- }
1404
- if (!this.#signer) {
1405
- throw new SignerUnavailableError();
1406
- }
1407
- const finalSigner = signer ?? this.#signer;
1408
- const signature = await finalSigner.signMessage(await signatureRequest.signatureText());
1409
- const identifier = await finalSigner.getIdentifier();
1410
- switch (finalSigner.type) {
1411
- case "SCW":
1412
- await signatureRequest.addScwSignature(identifier, signature, finalSigner.getChainId(), finalSigner.getBlockNumber?.());
1413
- break;
1414
- case "EOA":
1415
- await signatureRequest.addEcdsaSignature(signature);
1416
- break;
1417
- }
1418
- }
1419
- /**
1420
- * Returns a signature request handler for creating a new inbox
1367
+ * Creates signature text for creating a new inbox
1421
1368
  *
1422
1369
  * WARNING: This function should be used with caution. It is only provided
1423
1370
  * for use in special cases where the provided workflows do not meet the
@@ -1428,15 +1375,20 @@ class Client {
1428
1375
  * @returns The signature text
1429
1376
  * @throws {ClientNotInitializedError} if the client is not initialized
1430
1377
  */
1431
- async unsafe_createInboxSignatureRequest() {
1378
+ async unsafe_createInboxSignatureText() {
1432
1379
  if (!this.#client) {
1433
1380
  throw new ClientNotInitializedError();
1434
1381
  }
1435
- return this.#client.createInboxSignatureRequest();
1382
+ try {
1383
+ const signatureText = await this.#client.createInboxSignatureText();
1384
+ return signatureText;
1385
+ }
1386
+ catch {
1387
+ return undefined;
1388
+ }
1436
1389
  }
1437
1390
  /**
1438
- * Returns a signature request handler for adding a new account to the
1439
- * client's inbox
1391
+ * Creates signature text for adding a new account to the client's inbox
1440
1392
  *
1441
1393
  * WARNING: This function should be used with caution. It is only provided
1442
1394
  * for use in special cases where the provided workflows do not meet the
@@ -1452,18 +1404,23 @@ class Client {
1452
1404
  * @returns The signature text
1453
1405
  * @throws {ClientNotInitializedError} if the client is not initialized
1454
1406
  */
1455
- async unsafe_addAccountSignatureRequest(newAccountIdentifier, allowInboxReassign = false) {
1407
+ async unsafe_addAccountSignatureText(newAccountIdentifier, allowInboxReassign = false) {
1456
1408
  if (!this.#client) {
1457
1409
  throw new ClientNotInitializedError();
1458
1410
  }
1459
1411
  if (!allowInboxReassign) {
1460
1412
  throw new InboxReassignError();
1461
1413
  }
1462
- return this.#client.addIdentifierSignatureRequest(newAccountIdentifier);
1414
+ try {
1415
+ const signatureText = await this.#client.addIdentifierSignatureText(newAccountIdentifier);
1416
+ return signatureText;
1417
+ }
1418
+ catch {
1419
+ return undefined;
1420
+ }
1463
1421
  }
1464
1422
  /**
1465
- * Returns a signature request handler for removing an account from the
1466
- * client's inbox
1423
+ * Creates signature text for removing an account from the client's inbox
1467
1424
  *
1468
1425
  * WARNING: This function should be used with caution. It is only provided
1469
1426
  * for use in special cases where the provided workflows do not meet the
@@ -1475,15 +1432,21 @@ class Client {
1475
1432
  * @returns The signature text
1476
1433
  * @throws {ClientNotInitializedError} if the client is not initialized
1477
1434
  */
1478
- async unsafe_removeAccountSignatureRequest(identifier) {
1435
+ async unsafe_removeAccountSignatureText(identifier) {
1479
1436
  if (!this.#client) {
1480
1437
  throw new ClientNotInitializedError();
1481
1438
  }
1482
- return this.#client.revokeIdentifierSignatureRequest(identifier);
1439
+ try {
1440
+ const signatureText = await this.#client.revokeIdentifierSignatureText(identifier);
1441
+ return signatureText;
1442
+ }
1443
+ catch {
1444
+ return undefined;
1445
+ }
1483
1446
  }
1484
1447
  /**
1485
- * Returns a signature request handler for revoking all other installations
1486
- * of the client's inbox
1448
+ * Creates signature text for revoking all other installations of the
1449
+ * client's inbox
1487
1450
  *
1488
1451
  * WARNING: This function should be used with caution. It is only provided
1489
1452
  * for use in special cases where the provided workflows do not meet the
@@ -1494,15 +1457,21 @@ class Client {
1494
1457
  * @returns The signature text
1495
1458
  * @throws {ClientNotInitializedError} if the client is not initialized
1496
1459
  */
1497
- async unsafe_revokeAllOtherInstallationsSignatureRequest() {
1460
+ async unsafe_revokeAllOtherInstallationsSignatureText() {
1498
1461
  if (!this.#client) {
1499
1462
  throw new ClientNotInitializedError();
1500
1463
  }
1501
- return this.#client.revokeAllOtherInstallationsSignatureRequest();
1464
+ try {
1465
+ const signatureText = await this.#client.revokeAllOtherInstallationsSignatureText();
1466
+ return signatureText;
1467
+ }
1468
+ catch {
1469
+ return undefined;
1470
+ }
1502
1471
  }
1503
1472
  /**
1504
- * Returns a signature request handler for revoking specific installations
1505
- * of the client's inbox
1473
+ * Creates signature text for revoking specific installations of the
1474
+ * client's inbox
1506
1475
  *
1507
1476
  * WARNING: This function should be used with caution. It is only provided
1508
1477
  * for use in special cases where the provided workflows do not meet the
@@ -1514,15 +1483,21 @@ class Client {
1514
1483
  * @returns The signature text
1515
1484
  * @throws {ClientNotInitializedError} if the client is not initialized
1516
1485
  */
1517
- async unsafe_revokeInstallationsSignatureRequest(installationIds) {
1486
+ async unsafe_revokeInstallationsSignatureText(installationIds) {
1518
1487
  if (!this.#client) {
1519
1488
  throw new ClientNotInitializedError();
1520
1489
  }
1521
- return this.#client.revokeInstallationsSignatureRequest(installationIds);
1490
+ try {
1491
+ const signatureText = await this.#client.revokeInstallationsSignatureText(installationIds);
1492
+ return signatureText;
1493
+ }
1494
+ catch {
1495
+ return undefined;
1496
+ }
1522
1497
  }
1523
1498
  /**
1524
- * Returns a signature request handler for changing the recovery identifier
1525
- * for this client's inbox
1499
+ * Creates signature text for changing the recovery identifier for this
1500
+ * client's inbox
1526
1501
  *
1527
1502
  * WARNING: This function should be used with caution. It is only provided
1528
1503
  * for use in special cases where the provided workflows do not meet the
@@ -1534,14 +1509,20 @@ class Client {
1534
1509
  * @returns The signature text
1535
1510
  * @throws {ClientNotInitializedError} if the client is not initialized
1536
1511
  */
1537
- async unsafe_changeRecoveryIdentifierSignatureRequest(identifier) {
1512
+ async unsafe_changeRecoveryIdentifierSignatureText(identifier) {
1538
1513
  if (!this.#client) {
1539
1514
  throw new ClientNotInitializedError();
1540
1515
  }
1541
- return this.#client.changeRecoveryIdentifierSignatureRequest(identifier);
1516
+ try {
1517
+ const signatureText = await this.#client.changeRecoveryIdentifierSignatureText(identifier);
1518
+ return signatureText;
1519
+ }
1520
+ catch {
1521
+ return undefined;
1522
+ }
1542
1523
  }
1543
1524
  /**
1544
- * Applies a signature request to the client
1525
+ * Adds a signature for a specific request type
1545
1526
  *
1546
1527
  * WARNING: This function should be used with caution. It is only provided
1547
1528
  * for use in special cases where the provided workflows do not meet the
@@ -1551,13 +1532,42 @@ class Client {
1551
1532
  * `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
1552
1533
  * methods instead.
1553
1534
  *
1535
+ * @param signatureType - The type of signature request
1536
+ * @param signatureText - The text to sign
1537
+ * @param signer - The signer to use
1554
1538
  * @throws {ClientNotInitializedError} if the client is not initialized
1555
1539
  */
1556
- async unsafe_applySignatureRequest(signatureRequest) {
1540
+ async unsafe_addSignature(signatureType, signatureText, signer) {
1557
1541
  if (!this.#client) {
1558
1542
  throw new ClientNotInitializedError();
1559
1543
  }
1560
- return this.#client.applySignatureRequest(signatureRequest);
1544
+ switch (signer.type) {
1545
+ case "SCW":
1546
+ await this.#client.addScwSignature(signatureType, await signer.signMessage(signatureText), signer.getChainId(), signer.getBlockNumber?.());
1547
+ break;
1548
+ case "EOA":
1549
+ await this.#client.addEcdsaSignature(signatureType, await signer.signMessage(signatureText));
1550
+ break;
1551
+ }
1552
+ }
1553
+ /**
1554
+ * Applies all pending signatures
1555
+ *
1556
+ * WARNING: This function should be used with caution. It is only provided
1557
+ * for use in special cases where the provided workflows do not meet the
1558
+ * requirements of an application.
1559
+ *
1560
+ * It is highly recommended to use the `register`, `unsafe_addAccount`,
1561
+ * `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
1562
+ * methods instead.
1563
+ *
1564
+ * @throws {ClientNotInitializedError} if the client is not initialized
1565
+ */
1566
+ async unsafe_applySignatures() {
1567
+ if (!this.#client) {
1568
+ throw new ClientNotInitializedError();
1569
+ }
1570
+ return this.#client.applySignatureRequests();
1561
1571
  }
1562
1572
  /**
1563
1573
  * Registers the client with the XMTP network
@@ -1568,12 +1578,19 @@ class Client {
1568
1578
  * @throws {SignerUnavailableError} if no signer is available
1569
1579
  */
1570
1580
  async register() {
1571
- const signatureRequest = await this.unsafe_createInboxSignatureRequest();
1572
- if (!signatureRequest) {
1581
+ if (!this.#client) {
1582
+ throw new ClientNotInitializedError();
1583
+ }
1584
+ if (!this.#signer) {
1585
+ throw new SignerUnavailableError();
1586
+ }
1587
+ const signatureText = await this.unsafe_createInboxSignatureText();
1588
+ // if the signature text is not available, the client is already registered
1589
+ if (!signatureText) {
1573
1590
  return;
1574
1591
  }
1575
- await this.unsafe_addSignature(signatureRequest);
1576
- await this.#client?.registerIdentity(signatureRequest);
1592
+ await this.unsafe_addSignature(1 /* SignatureRequestType.CreateInbox */, signatureText, this.#signer);
1593
+ return this.#client.registerIdentity();
1577
1594
  }
1578
1595
  /**
1579
1596
  * Adds a new account to the client inbox
@@ -1589,20 +1606,27 @@ class Client {
1589
1606
  *
1590
1607
  * @param newAccountSigner - The signer for the new account
1591
1608
  * @param allowInboxReassign - Whether to allow inbox reassignment
1592
- * @throws {AccountAlreadyAssociatedError} if the account is already associated with an inbox ID
1593
1609
  * @throws {ClientNotInitializedError} if the client is not initialized
1610
+ * @throws {AccountAlreadyAssociatedError} if the account is already associated with an inbox ID
1611
+ * @throws {GenerateSignatureError} if the signature cannot be generated
1594
1612
  * @throws {SignerUnavailableError} if no signer is available
1595
1613
  */
1596
1614
  async unsafe_addAccount(newAccountSigner, allowInboxReassign = false) {
1615
+ if (!this.#client) {
1616
+ throw new ClientNotInitializedError();
1617
+ }
1597
1618
  // check for existing inbox id
1598
1619
  const identifier = await newAccountSigner.getIdentifier();
1599
1620
  const existingInboxId = await this.getInboxIdByIdentifier(identifier);
1600
1621
  if (existingInboxId && !allowInboxReassign) {
1601
1622
  throw new AccountAlreadyAssociatedError(existingInboxId);
1602
1623
  }
1603
- const signatureRequest = await this.unsafe_addAccountSignatureRequest(identifier, allowInboxReassign);
1604
- await this.unsafe_addSignature(signatureRequest, newAccountSigner);
1605
- await this.unsafe_applySignatureRequest(signatureRequest);
1624
+ const signatureText = await this.unsafe_addAccountSignatureText(identifier, true);
1625
+ if (!signatureText) {
1626
+ throw new GenerateSignatureError(0 /* SignatureRequestType.AddWallet */);
1627
+ }
1628
+ await this.unsafe_addSignature(0 /* SignatureRequestType.AddWallet */, signatureText, newAccountSigner);
1629
+ await this.unsafe_applySignatures();
1606
1630
  }
1607
1631
  /**
1608
1632
  * Removes an account from the client's inbox
@@ -1611,12 +1635,22 @@ class Client {
1611
1635
  *
1612
1636
  * @param identifier - The identifier of the account to remove
1613
1637
  * @throws {ClientNotInitializedError} if the client is not initialized
1638
+ * @throws {GenerateSignatureError} if the signature cannot be generated
1614
1639
  * @throws {SignerUnavailableError} if no signer is available
1615
1640
  */
1616
1641
  async removeAccount(identifier) {
1617
- const signatureRequest = await this.unsafe_removeAccountSignatureRequest(identifier);
1618
- await this.unsafe_addSignature(signatureRequest);
1619
- await this.unsafe_applySignatureRequest(signatureRequest);
1642
+ if (!this.#client) {
1643
+ throw new ClientNotInitializedError();
1644
+ }
1645
+ if (!this.#signer) {
1646
+ throw new SignerUnavailableError();
1647
+ }
1648
+ const signatureText = await this.unsafe_removeAccountSignatureText(identifier);
1649
+ if (!signatureText) {
1650
+ throw new GenerateSignatureError(2 /* SignatureRequestType.RevokeWallet */);
1651
+ }
1652
+ await this.unsafe_addSignature(2 /* SignatureRequestType.RevokeWallet */, signatureText, this.#signer);
1653
+ await this.unsafe_applySignatures();
1620
1654
  }
1621
1655
  /**
1622
1656
  * Revokes all other installations of the client's inbox
@@ -1624,12 +1658,22 @@ class Client {
1624
1658
  * Requires a signer, use `Client.create` to create a client with a signer.
1625
1659
  *
1626
1660
  * @throws {ClientNotInitializedError} if the client is not initialized
1661
+ * @throws {GenerateSignatureError} if the signature cannot be generated
1627
1662
  * @throws {SignerUnavailableError} if no signer is available
1628
1663
  */
1629
1664
  async revokeAllOtherInstallations() {
1630
- const signatureRequest = await this.unsafe_revokeAllOtherInstallationsSignatureRequest();
1631
- await this.unsafe_addSignature(signatureRequest);
1632
- await this.unsafe_applySignatureRequest(signatureRequest);
1665
+ if (!this.#client) {
1666
+ throw new ClientNotInitializedError();
1667
+ }
1668
+ if (!this.#signer) {
1669
+ throw new SignerUnavailableError();
1670
+ }
1671
+ const signatureText = await this.unsafe_revokeAllOtherInstallationsSignatureText();
1672
+ if (!signatureText) {
1673
+ throw new GenerateSignatureError(3 /* SignatureRequestType.RevokeInstallations */);
1674
+ }
1675
+ await this.unsafe_addSignature(3 /* SignatureRequestType.RevokeInstallations */, signatureText, this.#signer);
1676
+ await this.unsafe_applySignatures();
1633
1677
  }
1634
1678
  /**
1635
1679
  * Revokes specific installations of the client's inbox
@@ -1639,46 +1683,21 @@ class Client {
1639
1683
  * @param installationIds - The installation IDs to revoke
1640
1684
  * @throws {ClientNotInitializedError} if the client is not initialized
1641
1685
  * @throws {SignerUnavailableError} if no signer is available
1686
+ * @throws {GenerateSignatureError} if the signature cannot be generated
1642
1687
  */
1643
1688
  async revokeInstallations(installationIds) {
1644
- const signatureRequest = await this.unsafe_revokeInstallationsSignatureRequest(installationIds);
1645
- await this.unsafe_addSignature(signatureRequest);
1646
- await this.unsafe_applySignatureRequest(signatureRequest);
1647
- }
1648
- /**
1649
- * Revokes specific installations of the client's inbox without a client
1650
- *
1651
- * @param env - The environment to use
1652
- * @param signer - The signer to use
1653
- * @param inboxId - The inbox ID to revoke installations for
1654
- * @param installationIds - The installation IDs to revoke
1655
- */
1656
- static async revokeInstallations(signer, inboxId, installationIds, env) {
1657
- const host = ApiUrls[env ?? "dev"];
1658
- const identifier = await signer.getIdentifier();
1659
- const signatureRequest = await revokeInstallationsSignatureRequest(host, identifier, inboxId, installationIds);
1660
- const signatureText = await signatureRequest.signatureText();
1661
- const signature = await signer.signMessage(signatureText);
1662
- switch (signer.type) {
1663
- case "SCW":
1664
- await signatureRequest.addScwSignature(identifier, signature, signer.getChainId(), signer.getBlockNumber?.());
1665
- break;
1666
- case "EOA":
1667
- await signatureRequest.addEcdsaSignature(signature);
1668
- break;
1689
+ if (!this.#client) {
1690
+ throw new ClientNotInitializedError();
1669
1691
  }
1670
- await applySignatureRequest(host, signatureRequest);
1671
- }
1672
- /**
1673
- * Gets the inbox state for the specified inbox IDs without a client
1674
- *
1675
- * @param env - The environment to use
1676
- * @param inboxIds - The inbox IDs to get the state for
1677
- * @returns The inbox state for the specified inbox IDs
1678
- */
1679
- static async inboxStateFromInboxIds(inboxIds, env) {
1680
- const host = ApiUrls[env ?? "dev"];
1681
- return inboxStateFromInboxIds(host, inboxIds);
1692
+ if (!this.#signer) {
1693
+ throw new SignerUnavailableError();
1694
+ }
1695
+ const signatureText = await this.unsafe_revokeInstallationsSignatureText(installationIds);
1696
+ if (!signatureText) {
1697
+ throw new GenerateSignatureError(3 /* SignatureRequestType.RevokeInstallations */);
1698
+ }
1699
+ await this.unsafe_addSignature(3 /* SignatureRequestType.RevokeInstallations */, signatureText, this.#signer);
1700
+ await this.unsafe_applySignatures();
1682
1701
  }
1683
1702
  /**
1684
1703
  * Changes the recovery identifier for the client's inbox
@@ -1688,11 +1707,21 @@ class Client {
1688
1707
  * @param identifier - The new recovery identifier
1689
1708
  * @throws {ClientNotInitializedError} if the client is not initialized
1690
1709
  * @throws {SignerUnavailableError} if no signer is available
1710
+ * @throws {GenerateSignatureError} if the signature cannot be generated
1691
1711
  */
1692
1712
  async changeRecoveryIdentifier(identifier) {
1693
- const signatureRequest = await this.unsafe_changeRecoveryIdentifierSignatureRequest(identifier);
1694
- await this.unsafe_addSignature(signatureRequest);
1695
- await this.unsafe_applySignatureRequest(signatureRequest);
1713
+ if (!this.#client) {
1714
+ throw new ClientNotInitializedError();
1715
+ }
1716
+ if (!this.#signer) {
1717
+ throw new SignerUnavailableError();
1718
+ }
1719
+ const signatureText = await this.unsafe_changeRecoveryIdentifierSignatureText(identifier);
1720
+ if (!signatureText) {
1721
+ throw new GenerateSignatureError(4 /* SignatureRequestType.ChangeRecoveryIdentifier */);
1722
+ }
1723
+ await this.unsafe_addSignature(4 /* SignatureRequestType.ChangeRecoveryIdentifier */, signatureText, this.#signer);
1724
+ await this.unsafe_applySignatures();
1696
1725
  }
1697
1726
  /**
1698
1727
  * Checks if the client can message the specified identifiers
@@ -1857,8 +1886,8 @@ class Client {
1857
1886
  * @param options - Optional network options
1858
1887
  * @returns Whether the address is authorized
1859
1888
  */
1860
- static async isAddressAuthorized(inboxId, address, env) {
1861
- const host = ApiUrls[env ?? "dev"];
1889
+ static async isAddressAuthorized(inboxId, address, options) {
1890
+ const host = options?.apiUrl || ApiUrls[options?.env || "dev"];
1862
1891
  return await isAddressAuthorized(host, inboxId, address);
1863
1892
  }
1864
1893
  /**
@@ -1869,8 +1898,8 @@ class Client {
1869
1898
  * @param options - Optional network options
1870
1899
  * @returns Whether the installation is authorized
1871
1900
  */
1872
- static async isInstallationAuthorized(inboxId, installation, env) {
1873
- const host = ApiUrls[env ?? "dev"];
1901
+ static async isInstallationAuthorized(inboxId, installation, options) {
1902
+ const host = options?.apiUrl || ApiUrls[options?.env || "dev"];
1874
1903
  return await isInstallationAuthorized(host, inboxId, installation);
1875
1904
  }
1876
1905
  /**
@@ -1881,5 +1910,5 @@ class Client {
1881
1910
  }
1882
1911
  }
1883
1912
 
1884
- export { AccountAlreadyAssociatedError, ApiUrls, Client, ClientNotInitializedError, CodecNotFoundError, Conversation, Conversations, DecodedMessage, Dm, Group, HistorySyncUrls, InboxReassignError, InvalidGroupMembershipChangeError, MissingContentTypeError, SignerUnavailableError, generateInboxId, getInboxIdForIdentifier };
1913
+ export { ApiUrls, Client, Conversation, Conversations, DecodedMessage, Dm, Group, HistorySyncUrls, generateInboxId, getInboxIdForIdentifier };
1885
1914
  //# sourceMappingURL=index.js.map