@xmtp/node-sdk 3.2.0 → 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.d.ts +70 -127
- package/dist/index.js +264 -268
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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,
|
|
4
|
-
export { ConsentEntityType, ConsentState, ConversationType, DeliveryStatus, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, IdentifierKind, LogLevel, MetadataField, PermissionLevel, PermissionPolicy, PermissionUpdateType,
|
|
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,99 +35,83 @@ const HistorySyncUrls = {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
class AsyncStream {
|
|
38
|
-
#
|
|
39
|
-
#
|
|
38
|
+
#done = false;
|
|
39
|
+
#resolveNext;
|
|
40
|
+
#rejectNext;
|
|
40
41
|
#queue;
|
|
41
42
|
#error;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
#onError;
|
|
43
|
+
onReturn = undefined;
|
|
44
|
+
onError = undefined;
|
|
45
45
|
constructor() {
|
|
46
46
|
this.#queue = [];
|
|
47
|
-
this.#
|
|
47
|
+
this.#resolveNext = null;
|
|
48
|
+
this.#rejectNext = null;
|
|
49
|
+
this.#error = null;
|
|
50
|
+
this.#done = false;
|
|
48
51
|
}
|
|
49
|
-
#
|
|
50
|
-
while (this.#pendingPromises.length > 0) {
|
|
51
|
-
const nextPendingPromise = this.#pendingPromises.shift();
|
|
52
|
-
if (nextPendingPromise) {
|
|
53
|
-
nextPendingPromise.resolve({ done: true, value });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
#done(value) {
|
|
58
|
-
this.#flush(value);
|
|
52
|
+
#endStream() {
|
|
59
53
|
this.#queue = [];
|
|
60
|
-
this.#
|
|
61
|
-
this.#
|
|
62
|
-
this.#
|
|
63
|
-
if (this.#error) {
|
|
64
|
-
this.#onError?.(this.#error);
|
|
65
|
-
}
|
|
54
|
+
this.#resolveNext = null;
|
|
55
|
+
this.#rejectNext = null;
|
|
56
|
+
this.#done = true;
|
|
66
57
|
}
|
|
67
58
|
get error() {
|
|
68
59
|
return this.#error;
|
|
69
60
|
}
|
|
70
61
|
get isDone() {
|
|
71
|
-
return this.#
|
|
72
|
-
}
|
|
73
|
-
set onReturn(callback) {
|
|
74
|
-
this.#onReturn = callback;
|
|
75
|
-
}
|
|
76
|
-
set onError(callback) {
|
|
77
|
-
this.#onError = callback;
|
|
78
|
-
}
|
|
79
|
-
set onDone(callback) {
|
|
80
|
-
this.#onDone = callback;
|
|
62
|
+
return this.#done;
|
|
81
63
|
}
|
|
82
64
|
callback = (error, value) => {
|
|
83
|
-
if (
|
|
65
|
+
if (error) {
|
|
66
|
+
this.#error = error;
|
|
67
|
+
if (this.#rejectNext) {
|
|
68
|
+
this.#rejectNext(error);
|
|
69
|
+
this.#endStream();
|
|
70
|
+
this.onError?.(error);
|
|
71
|
+
}
|
|
84
72
|
return;
|
|
85
73
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
done: false,
|
|
97
|
-
value,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
74
|
+
if (this.#done) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (this.#resolveNext) {
|
|
78
|
+
this.#resolveNext({
|
|
79
|
+
done: false,
|
|
80
|
+
value,
|
|
81
|
+
});
|
|
82
|
+
this.#resolveNext = null;
|
|
83
|
+
this.#rejectNext = null;
|
|
100
84
|
}
|
|
101
85
|
else {
|
|
102
|
-
this.#queue.push(
|
|
86
|
+
this.#queue.push(value);
|
|
103
87
|
}
|
|
104
88
|
};
|
|
105
89
|
next = () => {
|
|
106
|
-
if (this.#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
90
|
+
if (this.#error) {
|
|
91
|
+
this.#endStream();
|
|
92
|
+
this.onError?.(this.#error);
|
|
93
|
+
return Promise.reject(this.#error);
|
|
111
94
|
}
|
|
112
95
|
if (this.#queue.length > 0) {
|
|
113
|
-
const value = this.#queue.shift();
|
|
114
|
-
if (value instanceof Error) {
|
|
115
|
-
this.#error = value;
|
|
116
|
-
this.#done();
|
|
117
|
-
return Promise.reject(value);
|
|
118
|
-
}
|
|
119
96
|
return Promise.resolve({
|
|
120
97
|
done: false,
|
|
121
|
-
value,
|
|
98
|
+
value: this.#queue.shift(),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (this.#done) {
|
|
102
|
+
return Promise.resolve({
|
|
103
|
+
done: true,
|
|
104
|
+
value: undefined,
|
|
122
105
|
});
|
|
123
106
|
}
|
|
124
107
|
return new Promise((resolve, reject) => {
|
|
125
|
-
this.#
|
|
108
|
+
this.#resolveNext = resolve;
|
|
109
|
+
this.#rejectNext = reject;
|
|
126
110
|
});
|
|
127
111
|
};
|
|
128
112
|
return = (value) => {
|
|
129
|
-
this.#
|
|
130
|
-
this
|
|
113
|
+
this.#endStream();
|
|
114
|
+
this.onReturn?.();
|
|
131
115
|
return Promise.resolve({
|
|
132
116
|
done: true,
|
|
133
117
|
value,
|
|
@@ -238,6 +222,29 @@ class AccountAlreadyAssociatedError extends Error {
|
|
|
238
222
|
super(`Account already associated with inbox ${inboxId}`);
|
|
239
223
|
}
|
|
240
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
|
+
}
|
|
241
248
|
class InvalidGroupMembershipChangeError extends Error {
|
|
242
249
|
constructor(messageId) {
|
|
243
250
|
super(`Invalid group membership change for message ${messageId}`);
|
|
@@ -346,7 +353,7 @@ class Conversation {
|
|
|
346
353
|
* @param callback - Optional callback function for handling new stream values
|
|
347
354
|
* @returns Stream instance for new messages
|
|
348
355
|
*/
|
|
349
|
-
stream(callback
|
|
356
|
+
stream(callback) {
|
|
350
357
|
const asyncStream = new AsyncStream();
|
|
351
358
|
const stream = this.#conversation.stream((error, value) => {
|
|
352
359
|
let err = error;
|
|
@@ -361,10 +368,8 @@ class Conversation {
|
|
|
361
368
|
}
|
|
362
369
|
asyncStream.callback(err, message);
|
|
363
370
|
callback?.(err, message);
|
|
364
|
-
}
|
|
365
|
-
asyncStream.
|
|
366
|
-
stream.end();
|
|
367
|
-
};
|
|
371
|
+
});
|
|
372
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
368
373
|
return asyncStream;
|
|
369
374
|
}
|
|
370
375
|
/**
|
|
@@ -916,7 +921,7 @@ class Conversations {
|
|
|
916
921
|
* @param callback - Optional callback function for handling new stream value
|
|
917
922
|
* @returns Stream instance for new conversations
|
|
918
923
|
*/
|
|
919
|
-
stream(callback
|
|
924
|
+
stream(callback) {
|
|
920
925
|
const asyncStream = new AsyncStream();
|
|
921
926
|
const stream = this.#conversations.stream((err, value) => {
|
|
922
927
|
if (err) {
|
|
@@ -946,10 +951,8 @@ class Conversations {
|
|
|
946
951
|
asyncStream.callback(error, undefined);
|
|
947
952
|
callback?.(error, undefined);
|
|
948
953
|
});
|
|
949
|
-
}
|
|
950
|
-
asyncStream.
|
|
951
|
-
stream.end();
|
|
952
|
-
};
|
|
954
|
+
});
|
|
955
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
953
956
|
return asyncStream;
|
|
954
957
|
}
|
|
955
958
|
/**
|
|
@@ -958,7 +961,7 @@ class Conversations {
|
|
|
958
961
|
* @param callback - Optional callback function for handling new stream value
|
|
959
962
|
* @returns Stream instance for new group conversations
|
|
960
963
|
*/
|
|
961
|
-
streamGroups(callback
|
|
964
|
+
streamGroups(callback) {
|
|
962
965
|
const asyncStream = new AsyncStream();
|
|
963
966
|
const stream = this.#conversations.stream((error, value) => {
|
|
964
967
|
let err = error;
|
|
@@ -973,10 +976,8 @@ class Conversations {
|
|
|
973
976
|
}
|
|
974
977
|
asyncStream.callback(err, group);
|
|
975
978
|
callback?.(err, group);
|
|
976
|
-
},
|
|
977
|
-
asyncStream.
|
|
978
|
-
stream.end();
|
|
979
|
-
};
|
|
979
|
+
}, 1 /* ConversationType.Group */);
|
|
980
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
980
981
|
return asyncStream;
|
|
981
982
|
}
|
|
982
983
|
/**
|
|
@@ -985,7 +986,7 @@ class Conversations {
|
|
|
985
986
|
* @param callback - Optional callback function for handling new stream value
|
|
986
987
|
* @returns Stream instance for new DM conversations
|
|
987
988
|
*/
|
|
988
|
-
streamDms(callback
|
|
989
|
+
streamDms(callback) {
|
|
989
990
|
const asyncStream = new AsyncStream();
|
|
990
991
|
const stream = this.#conversations.stream((error, value) => {
|
|
991
992
|
let err = error;
|
|
@@ -1000,10 +1001,8 @@ class Conversations {
|
|
|
1000
1001
|
}
|
|
1001
1002
|
asyncStream.callback(err, dm);
|
|
1002
1003
|
callback?.(err, dm);
|
|
1003
|
-
},
|
|
1004
|
-
asyncStream.
|
|
1005
|
-
stream.end();
|
|
1006
|
-
};
|
|
1004
|
+
}, 0 /* ConversationType.Dm */);
|
|
1005
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
1007
1006
|
return asyncStream;
|
|
1008
1007
|
}
|
|
1009
1008
|
/**
|
|
@@ -1012,7 +1011,7 @@ class Conversations {
|
|
|
1012
1011
|
* @param callback - Optional callback function for handling new stream value
|
|
1013
1012
|
* @returns Stream instance for new messages
|
|
1014
1013
|
*/
|
|
1015
|
-
async streamAllMessages(callback, conversationType, consentStates
|
|
1014
|
+
async streamAllMessages(callback, conversationType, consentStates) {
|
|
1016
1015
|
// sync conversations first
|
|
1017
1016
|
await this.sync();
|
|
1018
1017
|
const asyncStream = new AsyncStream();
|
|
@@ -1029,10 +1028,8 @@ class Conversations {
|
|
|
1029
1028
|
}
|
|
1030
1029
|
asyncStream.callback(err, message);
|
|
1031
1030
|
callback?.(err, message);
|
|
1032
|
-
},
|
|
1033
|
-
asyncStream.
|
|
1034
|
-
stream.end();
|
|
1035
|
-
};
|
|
1031
|
+
}, conversationType, consentStates);
|
|
1032
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
1036
1033
|
return asyncStream;
|
|
1037
1034
|
}
|
|
1038
1035
|
/**
|
|
@@ -1041,8 +1038,8 @@ class Conversations {
|
|
|
1041
1038
|
* @param callback - Optional callback function for handling new stream value
|
|
1042
1039
|
* @returns Stream instance for new group messages
|
|
1043
1040
|
*/
|
|
1044
|
-
async streamAllGroupMessages(callback, consentStates
|
|
1045
|
-
return this.streamAllMessages(callback, 1 /* ConversationType.Group */, consentStates
|
|
1041
|
+
async streamAllGroupMessages(callback, consentStates) {
|
|
1042
|
+
return this.streamAllMessages(callback, 1 /* ConversationType.Group */, consentStates);
|
|
1046
1043
|
}
|
|
1047
1044
|
/**
|
|
1048
1045
|
* Creates a stream for all new DM messages
|
|
@@ -1050,8 +1047,8 @@ class Conversations {
|
|
|
1050
1047
|
* @param callback - Optional callback function for handling new stream value
|
|
1051
1048
|
* @returns Stream instance for new DM messages
|
|
1052
1049
|
*/
|
|
1053
|
-
async streamAllDmMessages(callback, consentStates
|
|
1054
|
-
return this.streamAllMessages(callback, 0 /* ConversationType.Dm */, consentStates
|
|
1050
|
+
async streamAllDmMessages(callback, consentStates) {
|
|
1051
|
+
return this.streamAllMessages(callback, 0 /* ConversationType.Dm */, consentStates);
|
|
1055
1052
|
}
|
|
1056
1053
|
/**
|
|
1057
1054
|
* Retrieves HMAC keys for all conversations
|
|
@@ -1063,37 +1060,6 @@ class Conversations {
|
|
|
1063
1060
|
}
|
|
1064
1061
|
}
|
|
1065
1062
|
|
|
1066
|
-
/**
|
|
1067
|
-
* Debug information helpers for the client
|
|
1068
|
-
*
|
|
1069
|
-
* This class is not intended to be initialized directly.
|
|
1070
|
-
*/
|
|
1071
|
-
class DebugInformation {
|
|
1072
|
-
#client;
|
|
1073
|
-
#options;
|
|
1074
|
-
constructor(client, options) {
|
|
1075
|
-
this.#client = client;
|
|
1076
|
-
this.#options = options;
|
|
1077
|
-
}
|
|
1078
|
-
apiStatistics() {
|
|
1079
|
-
return this.#client.apiStatistics();
|
|
1080
|
-
}
|
|
1081
|
-
apiIdentityStatistics() {
|
|
1082
|
-
return this.#client.apiIdentityStatistics();
|
|
1083
|
-
}
|
|
1084
|
-
apiAggregateStatistics() {
|
|
1085
|
-
return this.#client.apiAggregateStatistics();
|
|
1086
|
-
}
|
|
1087
|
-
clearAllStatistics() {
|
|
1088
|
-
this.#client.clearAllStatistics();
|
|
1089
|
-
}
|
|
1090
|
-
uploadDebugArchive(serverUrl) {
|
|
1091
|
-
const env = this.#options?.env || "dev";
|
|
1092
|
-
const historySyncUrl = this.#options?.historySyncUrl || HistorySyncUrls[env];
|
|
1093
|
-
return this.#client.uploadDebugArchive(serverUrl || historySyncUrl);
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
1063
|
/**
|
|
1098
1064
|
* Manages user preferences and consent states
|
|
1099
1065
|
*
|
|
@@ -1168,7 +1134,7 @@ class Preferences {
|
|
|
1168
1134
|
* @param callback - Optional callback function for handling stream updates
|
|
1169
1135
|
* @returns Stream instance for consent updates
|
|
1170
1136
|
*/
|
|
1171
|
-
streamConsent(callback
|
|
1137
|
+
streamConsent(callback) {
|
|
1172
1138
|
const asyncStream = new AsyncStream();
|
|
1173
1139
|
const stream = this.#conversations.streamConsent((err, value) => {
|
|
1174
1140
|
if (err) {
|
|
@@ -1178,10 +1144,8 @@ class Preferences {
|
|
|
1178
1144
|
}
|
|
1179
1145
|
asyncStream.callback(null, value);
|
|
1180
1146
|
callback?.(null, value);
|
|
1181
|
-
}
|
|
1182
|
-
asyncStream.
|
|
1183
|
-
stream.end();
|
|
1184
|
-
};
|
|
1147
|
+
});
|
|
1148
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
1185
1149
|
return asyncStream;
|
|
1186
1150
|
}
|
|
1187
1151
|
/**
|
|
@@ -1190,7 +1154,7 @@ class Preferences {
|
|
|
1190
1154
|
* @param callback - Optional callback function for handling stream updates
|
|
1191
1155
|
* @returns Stream instance for preference updates
|
|
1192
1156
|
*/
|
|
1193
|
-
streamPreferences(callback
|
|
1157
|
+
streamPreferences(callback) {
|
|
1194
1158
|
const asyncStream = new AsyncStream();
|
|
1195
1159
|
const stream = this.#conversations.streamPreferences((err, value) => {
|
|
1196
1160
|
if (err) {
|
|
@@ -1201,10 +1165,8 @@ class Preferences {
|
|
|
1201
1165
|
// TODO: remove this once the node bindings type is updated
|
|
1202
1166
|
asyncStream.callback(null, value);
|
|
1203
1167
|
callback?.(null, value);
|
|
1204
|
-
}
|
|
1205
|
-
asyncStream.
|
|
1206
|
-
stream.end();
|
|
1207
|
-
};
|
|
1168
|
+
});
|
|
1169
|
+
asyncStream.onReturn = stream.end.bind(stream);
|
|
1208
1170
|
return asyncStream;
|
|
1209
1171
|
}
|
|
1210
1172
|
}
|
|
@@ -1248,7 +1210,6 @@ const version = `${bindingsVersion.branch}@${bindingsVersion.version} (${binding
|
|
|
1248
1210
|
class Client {
|
|
1249
1211
|
#client;
|
|
1250
1212
|
#conversations;
|
|
1251
|
-
#debugInformation;
|
|
1252
1213
|
#preferences;
|
|
1253
1214
|
#signer;
|
|
1254
1215
|
#codecs;
|
|
@@ -1287,7 +1248,6 @@ class Client {
|
|
|
1287
1248
|
this.#client = await createClient(identifier, this.#options);
|
|
1288
1249
|
const conversations = this.#client.conversations();
|
|
1289
1250
|
this.#conversations = new Conversations(this, conversations);
|
|
1290
|
-
this.#debugInformation = new DebugInformation(this.#client, this.#options);
|
|
1291
1251
|
this.#preferences = new Preferences(this.#client, conversations);
|
|
1292
1252
|
}
|
|
1293
1253
|
/**
|
|
@@ -1392,17 +1352,6 @@ class Client {
|
|
|
1392
1352
|
}
|
|
1393
1353
|
return this.#conversations;
|
|
1394
1354
|
}
|
|
1395
|
-
/**
|
|
1396
|
-
* Gets the debug information helpersfor this client
|
|
1397
|
-
*
|
|
1398
|
-
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1399
|
-
*/
|
|
1400
|
-
get debugInformation() {
|
|
1401
|
-
if (!this.#debugInformation) {
|
|
1402
|
-
throw new ClientNotInitializedError();
|
|
1403
|
-
}
|
|
1404
|
-
return this.#debugInformation;
|
|
1405
|
-
}
|
|
1406
1355
|
/**
|
|
1407
1356
|
* Gets the preferences manager for this client
|
|
1408
1357
|
*
|
|
@@ -1415,42 +1364,7 @@ class Client {
|
|
|
1415
1364
|
return this.#preferences;
|
|
1416
1365
|
}
|
|
1417
1366
|
/**
|
|
1418
|
-
*
|
|
1419
|
-
* provided signer)
|
|
1420
|
-
*
|
|
1421
|
-
* WARNING: This function should be used with caution. It is only provided
|
|
1422
|
-
* for use in special cases where the provided workflows do not meet the
|
|
1423
|
-
* requirements of an application.
|
|
1424
|
-
*
|
|
1425
|
-
* It is highly recommended to use the `register`, `unsafe_addAccount`,
|
|
1426
|
-
* `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
|
|
1427
|
-
* methods instead.
|
|
1428
|
-
*
|
|
1429
|
-
* @param signatureRequest - The signature request to add the signature to
|
|
1430
|
-
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1431
|
-
* @throws {SignerUnavailableError} if no signer is available
|
|
1432
|
-
*/
|
|
1433
|
-
async unsafe_addSignature(signatureRequest, signer) {
|
|
1434
|
-
if (!this.#client) {
|
|
1435
|
-
throw new ClientNotInitializedError();
|
|
1436
|
-
}
|
|
1437
|
-
if (!this.#signer) {
|
|
1438
|
-
throw new SignerUnavailableError();
|
|
1439
|
-
}
|
|
1440
|
-
const finalSigner = signer ?? this.#signer;
|
|
1441
|
-
const signature = await finalSigner.signMessage(await signatureRequest.signatureText());
|
|
1442
|
-
const identifier = await finalSigner.getIdentifier();
|
|
1443
|
-
switch (finalSigner.type) {
|
|
1444
|
-
case "SCW":
|
|
1445
|
-
await signatureRequest.addScwSignature(identifier, signature, finalSigner.getChainId(), finalSigner.getBlockNumber?.());
|
|
1446
|
-
break;
|
|
1447
|
-
case "EOA":
|
|
1448
|
-
await signatureRequest.addEcdsaSignature(signature);
|
|
1449
|
-
break;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Returns a signature request handler for creating a new inbox
|
|
1367
|
+
* Creates signature text for creating a new inbox
|
|
1454
1368
|
*
|
|
1455
1369
|
* WARNING: This function should be used with caution. It is only provided
|
|
1456
1370
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1461,15 +1375,20 @@ class Client {
|
|
|
1461
1375
|
* @returns The signature text
|
|
1462
1376
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1463
1377
|
*/
|
|
1464
|
-
async
|
|
1378
|
+
async unsafe_createInboxSignatureText() {
|
|
1465
1379
|
if (!this.#client) {
|
|
1466
1380
|
throw new ClientNotInitializedError();
|
|
1467
1381
|
}
|
|
1468
|
-
|
|
1382
|
+
try {
|
|
1383
|
+
const signatureText = await this.#client.createInboxSignatureText();
|
|
1384
|
+
return signatureText;
|
|
1385
|
+
}
|
|
1386
|
+
catch {
|
|
1387
|
+
return undefined;
|
|
1388
|
+
}
|
|
1469
1389
|
}
|
|
1470
1390
|
/**
|
|
1471
|
-
*
|
|
1472
|
-
* client's inbox
|
|
1391
|
+
* Creates signature text for adding a new account to the client's inbox
|
|
1473
1392
|
*
|
|
1474
1393
|
* WARNING: This function should be used with caution. It is only provided
|
|
1475
1394
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1485,18 +1404,23 @@ class Client {
|
|
|
1485
1404
|
* @returns The signature text
|
|
1486
1405
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1487
1406
|
*/
|
|
1488
|
-
async
|
|
1407
|
+
async unsafe_addAccountSignatureText(newAccountIdentifier, allowInboxReassign = false) {
|
|
1489
1408
|
if (!this.#client) {
|
|
1490
1409
|
throw new ClientNotInitializedError();
|
|
1491
1410
|
}
|
|
1492
1411
|
if (!allowInboxReassign) {
|
|
1493
1412
|
throw new InboxReassignError();
|
|
1494
1413
|
}
|
|
1495
|
-
|
|
1414
|
+
try {
|
|
1415
|
+
const signatureText = await this.#client.addIdentifierSignatureText(newAccountIdentifier);
|
|
1416
|
+
return signatureText;
|
|
1417
|
+
}
|
|
1418
|
+
catch {
|
|
1419
|
+
return undefined;
|
|
1420
|
+
}
|
|
1496
1421
|
}
|
|
1497
1422
|
/**
|
|
1498
|
-
*
|
|
1499
|
-
* client's inbox
|
|
1423
|
+
* Creates signature text for removing an account from the client's inbox
|
|
1500
1424
|
*
|
|
1501
1425
|
* WARNING: This function should be used with caution. It is only provided
|
|
1502
1426
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1508,15 +1432,21 @@ class Client {
|
|
|
1508
1432
|
* @returns The signature text
|
|
1509
1433
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1510
1434
|
*/
|
|
1511
|
-
async
|
|
1435
|
+
async unsafe_removeAccountSignatureText(identifier) {
|
|
1512
1436
|
if (!this.#client) {
|
|
1513
1437
|
throw new ClientNotInitializedError();
|
|
1514
1438
|
}
|
|
1515
|
-
|
|
1439
|
+
try {
|
|
1440
|
+
const signatureText = await this.#client.revokeIdentifierSignatureText(identifier);
|
|
1441
|
+
return signatureText;
|
|
1442
|
+
}
|
|
1443
|
+
catch {
|
|
1444
|
+
return undefined;
|
|
1445
|
+
}
|
|
1516
1446
|
}
|
|
1517
1447
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1448
|
+
* Creates signature text for revoking all other installations of the
|
|
1449
|
+
* client's inbox
|
|
1520
1450
|
*
|
|
1521
1451
|
* WARNING: This function should be used with caution. It is only provided
|
|
1522
1452
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1527,15 +1457,21 @@ class Client {
|
|
|
1527
1457
|
* @returns The signature text
|
|
1528
1458
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1529
1459
|
*/
|
|
1530
|
-
async
|
|
1460
|
+
async unsafe_revokeAllOtherInstallationsSignatureText() {
|
|
1531
1461
|
if (!this.#client) {
|
|
1532
1462
|
throw new ClientNotInitializedError();
|
|
1533
1463
|
}
|
|
1534
|
-
|
|
1464
|
+
try {
|
|
1465
|
+
const signatureText = await this.#client.revokeAllOtherInstallationsSignatureText();
|
|
1466
|
+
return signatureText;
|
|
1467
|
+
}
|
|
1468
|
+
catch {
|
|
1469
|
+
return undefined;
|
|
1470
|
+
}
|
|
1535
1471
|
}
|
|
1536
1472
|
/**
|
|
1537
|
-
*
|
|
1538
|
-
*
|
|
1473
|
+
* Creates signature text for revoking specific installations of the
|
|
1474
|
+
* client's inbox
|
|
1539
1475
|
*
|
|
1540
1476
|
* WARNING: This function should be used with caution. It is only provided
|
|
1541
1477
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1547,15 +1483,21 @@ class Client {
|
|
|
1547
1483
|
* @returns The signature text
|
|
1548
1484
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1549
1485
|
*/
|
|
1550
|
-
async
|
|
1486
|
+
async unsafe_revokeInstallationsSignatureText(installationIds) {
|
|
1551
1487
|
if (!this.#client) {
|
|
1552
1488
|
throw new ClientNotInitializedError();
|
|
1553
1489
|
}
|
|
1554
|
-
|
|
1490
|
+
try {
|
|
1491
|
+
const signatureText = await this.#client.revokeInstallationsSignatureText(installationIds);
|
|
1492
|
+
return signatureText;
|
|
1493
|
+
}
|
|
1494
|
+
catch {
|
|
1495
|
+
return undefined;
|
|
1496
|
+
}
|
|
1555
1497
|
}
|
|
1556
1498
|
/**
|
|
1557
|
-
*
|
|
1558
|
-
*
|
|
1499
|
+
* Creates signature text for changing the recovery identifier for this
|
|
1500
|
+
* client's inbox
|
|
1559
1501
|
*
|
|
1560
1502
|
* WARNING: This function should be used with caution. It is only provided
|
|
1561
1503
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1567,14 +1509,49 @@ class Client {
|
|
|
1567
1509
|
* @returns The signature text
|
|
1568
1510
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1569
1511
|
*/
|
|
1570
|
-
async
|
|
1512
|
+
async unsafe_changeRecoveryIdentifierSignatureText(identifier) {
|
|
1513
|
+
if (!this.#client) {
|
|
1514
|
+
throw new ClientNotInitializedError();
|
|
1515
|
+
}
|
|
1516
|
+
try {
|
|
1517
|
+
const signatureText = await this.#client.changeRecoveryIdentifierSignatureText(identifier);
|
|
1518
|
+
return signatureText;
|
|
1519
|
+
}
|
|
1520
|
+
catch {
|
|
1521
|
+
return undefined;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Adds a signature for a specific request type
|
|
1526
|
+
*
|
|
1527
|
+
* WARNING: This function should be used with caution. It is only provided
|
|
1528
|
+
* for use in special cases where the provided workflows do not meet the
|
|
1529
|
+
* requirements of an application.
|
|
1530
|
+
*
|
|
1531
|
+
* It is highly recommended to use the `register`, `unsafe_addAccount`,
|
|
1532
|
+
* `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
|
|
1533
|
+
* methods instead.
|
|
1534
|
+
*
|
|
1535
|
+
* @param signatureType - The type of signature request
|
|
1536
|
+
* @param signatureText - The text to sign
|
|
1537
|
+
* @param signer - The signer to use
|
|
1538
|
+
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1539
|
+
*/
|
|
1540
|
+
async unsafe_addSignature(signatureType, signatureText, signer) {
|
|
1571
1541
|
if (!this.#client) {
|
|
1572
1542
|
throw new ClientNotInitializedError();
|
|
1573
1543
|
}
|
|
1574
|
-
|
|
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
|
+
}
|
|
1575
1552
|
}
|
|
1576
1553
|
/**
|
|
1577
|
-
* Applies
|
|
1554
|
+
* Applies all pending signatures
|
|
1578
1555
|
*
|
|
1579
1556
|
* WARNING: This function should be used with caution. It is only provided
|
|
1580
1557
|
* for use in special cases where the provided workflows do not meet the
|
|
@@ -1586,11 +1563,11 @@ class Client {
|
|
|
1586
1563
|
*
|
|
1587
1564
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1588
1565
|
*/
|
|
1589
|
-
async
|
|
1566
|
+
async unsafe_applySignatures() {
|
|
1590
1567
|
if (!this.#client) {
|
|
1591
1568
|
throw new ClientNotInitializedError();
|
|
1592
1569
|
}
|
|
1593
|
-
return this.#client.
|
|
1570
|
+
return this.#client.applySignatureRequests();
|
|
1594
1571
|
}
|
|
1595
1572
|
/**
|
|
1596
1573
|
* Registers the client with the XMTP network
|
|
@@ -1601,12 +1578,19 @@ class Client {
|
|
|
1601
1578
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1602
1579
|
*/
|
|
1603
1580
|
async register() {
|
|
1604
|
-
|
|
1605
|
-
|
|
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) {
|
|
1606
1590
|
return;
|
|
1607
1591
|
}
|
|
1608
|
-
await this.unsafe_addSignature(
|
|
1609
|
-
|
|
1592
|
+
await this.unsafe_addSignature(1 /* SignatureRequestType.CreateInbox */, signatureText, this.#signer);
|
|
1593
|
+
return this.#client.registerIdentity();
|
|
1610
1594
|
}
|
|
1611
1595
|
/**
|
|
1612
1596
|
* Adds a new account to the client inbox
|
|
@@ -1622,20 +1606,27 @@ class Client {
|
|
|
1622
1606
|
*
|
|
1623
1607
|
* @param newAccountSigner - The signer for the new account
|
|
1624
1608
|
* @param allowInboxReassign - Whether to allow inbox reassignment
|
|
1625
|
-
* @throws {AccountAlreadyAssociatedError} if the account is already associated with an inbox ID
|
|
1626
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
|
|
1627
1612
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1628
1613
|
*/
|
|
1629
1614
|
async unsafe_addAccount(newAccountSigner, allowInboxReassign = false) {
|
|
1615
|
+
if (!this.#client) {
|
|
1616
|
+
throw new ClientNotInitializedError();
|
|
1617
|
+
}
|
|
1630
1618
|
// check for existing inbox id
|
|
1631
1619
|
const identifier = await newAccountSigner.getIdentifier();
|
|
1632
1620
|
const existingInboxId = await this.getInboxIdByIdentifier(identifier);
|
|
1633
1621
|
if (existingInboxId && !allowInboxReassign) {
|
|
1634
1622
|
throw new AccountAlreadyAssociatedError(existingInboxId);
|
|
1635
1623
|
}
|
|
1636
|
-
const
|
|
1637
|
-
|
|
1638
|
-
|
|
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();
|
|
1639
1630
|
}
|
|
1640
1631
|
/**
|
|
1641
1632
|
* Removes an account from the client's inbox
|
|
@@ -1644,12 +1635,22 @@ class Client {
|
|
|
1644
1635
|
*
|
|
1645
1636
|
* @param identifier - The identifier of the account to remove
|
|
1646
1637
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1638
|
+
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
1647
1639
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1648
1640
|
*/
|
|
1649
1641
|
async removeAccount(identifier) {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
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();
|
|
1653
1654
|
}
|
|
1654
1655
|
/**
|
|
1655
1656
|
* Revokes all other installations of the client's inbox
|
|
@@ -1657,12 +1658,22 @@ class Client {
|
|
|
1657
1658
|
* Requires a signer, use `Client.create` to create a client with a signer.
|
|
1658
1659
|
*
|
|
1659
1660
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1661
|
+
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
1660
1662
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1661
1663
|
*/
|
|
1662
1664
|
async revokeAllOtherInstallations() {
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
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();
|
|
1666
1677
|
}
|
|
1667
1678
|
/**
|
|
1668
1679
|
* Revokes specific installations of the client's inbox
|
|
@@ -1672,46 +1683,21 @@ class Client {
|
|
|
1672
1683
|
* @param installationIds - The installation IDs to revoke
|
|
1673
1684
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1674
1685
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1686
|
+
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
1675
1687
|
*/
|
|
1676
1688
|
async revokeInstallations(installationIds) {
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
await this.unsafe_applySignatureRequest(signatureRequest);
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* Revokes specific installations of the client's inbox without a client
|
|
1683
|
-
*
|
|
1684
|
-
* @param env - The environment to use
|
|
1685
|
-
* @param signer - The signer to use
|
|
1686
|
-
* @param inboxId - The inbox ID to revoke installations for
|
|
1687
|
-
* @param installationIds - The installation IDs to revoke
|
|
1688
|
-
*/
|
|
1689
|
-
static async revokeInstallations(signer, inboxId, installationIds, env) {
|
|
1690
|
-
const host = ApiUrls[env ?? "dev"];
|
|
1691
|
-
const identifier = await signer.getIdentifier();
|
|
1692
|
-
const signatureRequest = await revokeInstallationsSignatureRequest(host, identifier, inboxId, installationIds);
|
|
1693
|
-
const signatureText = await signatureRequest.signatureText();
|
|
1694
|
-
const signature = await signer.signMessage(signatureText);
|
|
1695
|
-
switch (signer.type) {
|
|
1696
|
-
case "SCW":
|
|
1697
|
-
await signatureRequest.addScwSignature(identifier, signature, signer.getChainId(), signer.getBlockNumber?.());
|
|
1698
|
-
break;
|
|
1699
|
-
case "EOA":
|
|
1700
|
-
await signatureRequest.addEcdsaSignature(signature);
|
|
1701
|
-
break;
|
|
1689
|
+
if (!this.#client) {
|
|
1690
|
+
throw new ClientNotInitializedError();
|
|
1702
1691
|
}
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
static async inboxStateFromInboxIds(inboxIds, env) {
|
|
1713
|
-
const host = ApiUrls[env ?? "dev"];
|
|
1714
|
-
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();
|
|
1715
1701
|
}
|
|
1716
1702
|
/**
|
|
1717
1703
|
* Changes the recovery identifier for the client's inbox
|
|
@@ -1721,11 +1707,21 @@ class Client {
|
|
|
1721
1707
|
* @param identifier - The new recovery identifier
|
|
1722
1708
|
* @throws {ClientNotInitializedError} if the client is not initialized
|
|
1723
1709
|
* @throws {SignerUnavailableError} if no signer is available
|
|
1710
|
+
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
1724
1711
|
*/
|
|
1725
1712
|
async changeRecoveryIdentifier(identifier) {
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
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();
|
|
1729
1725
|
}
|
|
1730
1726
|
/**
|
|
1731
1727
|
* Checks if the client can message the specified identifiers
|
|
@@ -1890,8 +1886,8 @@ class Client {
|
|
|
1890
1886
|
* @param options - Optional network options
|
|
1891
1887
|
* @returns Whether the address is authorized
|
|
1892
1888
|
*/
|
|
1893
|
-
static async isAddressAuthorized(inboxId, address,
|
|
1894
|
-
const host = ApiUrls[env
|
|
1889
|
+
static async isAddressAuthorized(inboxId, address, options) {
|
|
1890
|
+
const host = options?.apiUrl || ApiUrls[options?.env || "dev"];
|
|
1895
1891
|
return await isAddressAuthorized(host, inboxId, address);
|
|
1896
1892
|
}
|
|
1897
1893
|
/**
|
|
@@ -1902,8 +1898,8 @@ class Client {
|
|
|
1902
1898
|
* @param options - Optional network options
|
|
1903
1899
|
* @returns Whether the installation is authorized
|
|
1904
1900
|
*/
|
|
1905
|
-
static async isInstallationAuthorized(inboxId, installation,
|
|
1906
|
-
const host = ApiUrls[env
|
|
1901
|
+
static async isInstallationAuthorized(inboxId, installation, options) {
|
|
1902
|
+
const host = options?.apiUrl || ApiUrls[options?.env || "dev"];
|
|
1907
1903
|
return await isInstallationAuthorized(host, inboxId, installation);
|
|
1908
1904
|
}
|
|
1909
1905
|
/**
|
|
@@ -1914,5 +1910,5 @@ class Client {
|
|
|
1914
1910
|
}
|
|
1915
1911
|
}
|
|
1916
1912
|
|
|
1917
|
-
export {
|
|
1913
|
+
export { ApiUrls, Client, Conversation, Conversations, DecodedMessage, Dm, Group, HistorySyncUrls, generateInboxId, getInboxIdForIdentifier };
|
|
1918
1914
|
//# sourceMappingURL=index.js.map
|