@xmtp/browser-sdk 2.2.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +309 -129
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/workers/client.js +1 -1
- package/dist/workers/client.js.map +1 -1
- package/dist/workers/utils.js +1 -1
- package/dist/workers/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Client.ts +138 -169
- package/src/DebugInformation.ts +48 -0
- package/src/Utils.ts +77 -0
- package/src/WorkerClient.ts +55 -83
- package/src/WorkerDebugInformation.ts +41 -0
- package/src/index.ts +3 -2
- package/src/types/actions/client.ts +84 -58
- package/src/types/actions/debugInformation.ts +35 -0
- package/src/types/actions/utils.ts +33 -0
- package/src/types/actions.ts +3 -1
- package/src/utils/conversions.ts +2 -2
- package/src/utils/errors.ts +0 -27
- package/src/utils/signer.ts +36 -0
- package/src/workers/client.ts +140 -34
- package/src/workers/utils.ts +50 -0
package/dist/workers/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t,
|
|
1
|
+
import e,{inboxStateFromInboxIds as t,revokeInstallationsSignatureRequest as i,applySignatureRequest as a,generateInboxId as n,getInboxIdForIdentifier as s}from"@xmtp/wasm-bindings";import"@xmtp/content-type-primitives";const o={local:"http://localhost:5555",dev:"https://dev.xmtp.network",production:"https://production.xmtp.network"},r=e=>({bytes:e.bytes,clientTimestampNs:e.clientTimestampNs,id:e.id}),d=e=>{self.postMessage(e)};let c=!1;self.onmessage=async l=>{const{action:g,id:b,data:u}=l.data;c&&console.log("utils worker received event data",l.data),await e();try{switch(g){case"utils.init":c=u.enableLogging,d({id:b,action:g,result:void 0});break;case"utils.generateInboxId":{const e=n(u.identifier);d({id:b,action:g,result:e});break}case"utils.getInboxIdForIdentifier":{const e=await(async(e,t)=>s(t?o[t]:o.dev,e))(u.identifier,u.env);d({id:b,action:g,result:e});break}case"utils.revokeInstallationsSignatureText":{const e=o[u.env??"dev"],t=await i(e,u.identifier,u.inboxId,u.installationIds),a=await t.signatureText();d({id:b,action:g,result:a});break}case"utils.revokeInstallations":{const e=o[u.env??"dev"],t=await i(e,u.signer.identifier,u.inboxId,u.installationIds);switch(u.signer.type){case"EOA":await t.addEcdsaSignature(u.signer.signature);break;case"SCW":await t.addScwSignature(u.signer.identifier,u.signer.signature,u.signer.chainId,u.signer.blockNumber)}await a(e,t),d({id:b,action:g,result:void 0});break}case"utils.inboxStateFromInboxIds":{const e=o[u.env??"dev"],i=(await t(e,u.inboxIds)).map((e=>(e=>({identifiers:e.accountIdentifiers,inboxId:e.inboxId,installations:e.installations.map(r),recoveryIdentifier:e.recoveryIdentifier}))(e)));d({id:b,action:g,result:i});break}}}catch(e){(e=>{self.postMessage(e)})({id:b,action:g,error:e})}};
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/constants.ts","../../src/workers/utils.ts"],"sourcesContent":[null,null],"names":["ApiUrls","local","dev","production","postMessage","data","self","enableLogging","onmessage","async","event","action","
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/constants.ts","../../src/utils/conversions.ts","../../src/workers/utils.ts"],"sourcesContent":[null,null,null],"names":["ApiUrls","local","dev","production","toSafeInstallation","installation","bytes","clientTimestampNs","id","postMessage","data","self","enableLogging","onmessage","async","event","action","console","log","init","result","undefined","generateInboxId","identifier","env","get_inbox_id_for_identifier","getInboxIdForIdentifier","host","signatureRequest","revokeInstallationsSignatureRequest","inboxId","installationIds","signatureText","signer","type","addEcdsaSignature","signature","addScwSignature","chainId","blockNumber","applySignatureRequest","inboxStateFromInboxIds","inboxIds","map","inboxState","identifiers","accountIdentifiers","installations","recoveryIdentifier","toSafeInboxState","e","postMessageError","error"],"mappings":"4NAQO,MAAMA,EAAU,CACrBC,MAAO,wBACPC,IAAK,2BACLC,WAAY,mCCiYDC,EACXC,IACsB,CACtBC,MAAOD,EAAaC,MACpBC,kBAAmBF,EAAaE,kBAChCC,GAAIH,EAAaG,KC3XbC,EACJC,IAEAC,KAAKF,YAAYC,EAAK,EAkBxB,IAAIE,GAAgB,EAEpBD,KAAKE,UAAYC,MACfC,IAEA,MAAMC,OAAEA,EAAMR,GAAEA,EAAEE,KAAEA,GAASK,EAAML,KAE/BE,GACFK,QAAQC,IAAI,mCAAoCH,EAAML,YAIlDS,IAEN,IACE,OAAQH,GACN,IAAK,aACHJ,EAAgBF,EAAKE,cACrBH,EAAY,CAAED,KAAIQ,SAAQI,YAAQC,IAClC,MAEF,IAAK,wBAAyB,CAC5B,MAAMD,EAASE,EAAgBZ,EAAKa,YACpCd,EAAY,CACVD,KACAQ,SACAI,WAEF,MAEF,IAAK,gCAAiC,CACpC,MAAMA,OAvCkBN,OAC9BS,EACAC,IAGOC,EADMD,EAAMxB,EAAQwB,GAAOxB,EAAQE,IACDqB,GAkCdG,CAAwBhB,EAAKa,WAAYb,EAAKc,KACnEf,EAAY,CAAED,KAAIQ,SAAQI,WAC1B,MAEF,IAAK,yCAA0C,CAC7C,MAAMO,EAAO3B,EAAQU,EAAKc,KAAO,OAC3BI,QAAyBC,EAC7BF,EACAjB,EAAKa,WACLb,EAAKoB,QACLpB,EAAKqB,iBAEDC,QAAsBJ,EAAiBI,gBAC7CvB,EAAY,CAAED,KAAIQ,SAAQI,OAAQY,IAClC,MAEF,IAAK,4BAA6B,CAChC,MAAML,EAAO3B,EAAQU,EAAKc,KAAO,OAC3BI,QAAyBC,EAC7BF,EACAjB,EAAKuB,OAAOV,WACZb,EAAKoB,QACLpB,EAAKqB,iBAEP,OAAQrB,EAAKuB,OAAOC,MAClB,IAAK,YACGN,EAAiBO,kBAAkBzB,EAAKuB,OAAOG,WACrD,MACF,IAAK,YACGR,EAAiBS,gBACrB3B,EAAKuB,OAAOV,WACZb,EAAKuB,OAAOG,UACZ1B,EAAKuB,OAAOK,QACZ5B,EAAKuB,OAAOM,mBAIZC,EAAsBb,EAAMC,GAClCnB,EAAY,CAAED,KAAIQ,SAAQI,YAAQC,IAClC,MAEF,IAAK,+BAAgC,CACnC,MAAMM,EAAO3B,EAAQU,EAAKc,KAAO,OAE3BJ,SADoBqB,EAAuBd,EAAMjB,EAAKgC,WACjCC,KAAKC,GDqSR,CAACA,IAA4C,CAC3EC,YAAaD,EAAWE,mBACxBhB,QAASc,EAAWd,QACpBiB,cAAeH,EAAWG,cAAcJ,IAAIvC,GAC5C4C,mBAAoBJ,EAAWI,qBCxSvBC,CAAiBL,KAEnBnC,EAAY,CAAED,KAAIQ,SAAQI,WAC1B,QAGJ,MAAO8B,GA9Fc,CAACxC,IACxBC,KAAKF,YAAYC,EAAK,EA8FpByC,CAAiB,CAAE3C,KAAIQ,SAAQoC,MAAOF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmtp/browser-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "XMTP client SDK for browsers written in TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"xmtp",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@xmtp/content-type-group-updated": "^2.0.2",
|
|
64
64
|
"@xmtp/content-type-primitives": "^2.0.2",
|
|
65
65
|
"@xmtp/content-type-text": "^2.0.2",
|
|
66
|
-
"@xmtp/wasm-bindings": "1.2.
|
|
66
|
+
"@xmtp/wasm-bindings": "1.2.5",
|
|
67
67
|
"uuid": "^11.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
package/src/Client.ts
CHANGED
|
@@ -7,13 +7,11 @@ import type {
|
|
|
7
7
|
ContentTypeId,
|
|
8
8
|
} from "@xmtp/content-type-primitives";
|
|
9
9
|
import { TextCodec } from "@xmtp/content-type-text";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
SignatureRequestType,
|
|
13
|
-
type Identifier,
|
|
14
|
-
} from "@xmtp/wasm-bindings";
|
|
10
|
+
import { GroupMessageKind, type Identifier } from "@xmtp/wasm-bindings";
|
|
11
|
+
import { v4 } from "uuid";
|
|
15
12
|
import { ClientWorkerClass } from "@/ClientWorkerClass";
|
|
16
13
|
import { Conversations } from "@/Conversations";
|
|
14
|
+
import { DebugInformation } from "@/DebugInformation";
|
|
17
15
|
import { Preferences } from "@/Preferences";
|
|
18
16
|
import type { ClientOptions, XmtpEnv } from "@/types/options";
|
|
19
17
|
import { Utils } from "@/Utils";
|
|
@@ -25,12 +23,11 @@ import {
|
|
|
25
23
|
import {
|
|
26
24
|
AccountAlreadyAssociatedError,
|
|
27
25
|
CodecNotFoundError,
|
|
28
|
-
GenerateSignatureError,
|
|
29
26
|
InboxReassignError,
|
|
30
27
|
InvalidGroupMembershipChangeError,
|
|
31
28
|
SignerUnavailableError,
|
|
32
29
|
} from "@/utils/errors";
|
|
33
|
-
import { type Signer } from "@/utils/signer";
|
|
30
|
+
import { toSafeSigner, type SafeSigner, type Signer } from "@/utils/signer";
|
|
34
31
|
|
|
35
32
|
export type ExtractCodecContentTypes<C extends ContentCodec[] = []> =
|
|
36
33
|
[...C, GroupUpdatedCodec, TextCodec][number] extends ContentCodec<infer T>
|
|
@@ -45,6 +42,7 @@ export class Client<
|
|
|
45
42
|
> extends ClientWorkerClass {
|
|
46
43
|
#codecs: Map<string, ContentCodec>;
|
|
47
44
|
#conversations: Conversations<ContentTypes>;
|
|
45
|
+
#debugInformation: DebugInformation<ContentTypes>;
|
|
48
46
|
#identifier?: Identifier;
|
|
49
47
|
#inboxId: string | undefined;
|
|
50
48
|
#installationId: string | undefined;
|
|
@@ -72,6 +70,7 @@ export class Client<
|
|
|
72
70
|
);
|
|
73
71
|
this.#options = options;
|
|
74
72
|
this.#conversations = new Conversations(this);
|
|
73
|
+
this.#debugInformation = new DebugInformation(this);
|
|
75
74
|
this.#preferences = new Preferences(this);
|
|
76
75
|
const codecs = [
|
|
77
76
|
new GroupUpdatedCodec(),
|
|
@@ -208,6 +207,13 @@ export class Client<
|
|
|
208
207
|
return this.#conversations;
|
|
209
208
|
}
|
|
210
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Gets the debug information helpers for this client
|
|
212
|
+
*/
|
|
213
|
+
get debugInformation() {
|
|
214
|
+
return this.#debugInformation;
|
|
215
|
+
}
|
|
216
|
+
|
|
211
217
|
/**
|
|
212
218
|
* Gets the preferences manager for this client
|
|
213
219
|
*/
|
|
@@ -224,10 +230,12 @@ export class Client<
|
|
|
224
230
|
*
|
|
225
231
|
* It is highly recommended to use the `register` method instead.
|
|
226
232
|
*
|
|
227
|
-
* @returns The signature text
|
|
233
|
+
* @returns The signature text and signature request ID
|
|
228
234
|
*/
|
|
229
235
|
async unsafe_createInboxSignatureText() {
|
|
230
|
-
return this.sendMessage("client.createInboxSignatureText",
|
|
236
|
+
return this.sendMessage("client.createInboxSignatureText", {
|
|
237
|
+
signatureRequestId: v4(),
|
|
238
|
+
});
|
|
231
239
|
}
|
|
232
240
|
|
|
233
241
|
/**
|
|
@@ -241,7 +249,8 @@ export class Client<
|
|
|
241
249
|
*
|
|
242
250
|
* @param newIdentifier - The identifier of the new account
|
|
243
251
|
* @param allowInboxReassign - Whether to allow inbox reassignment
|
|
244
|
-
* @
|
|
252
|
+
* @throws {InboxReassignError} if `allowInboxReassign` is false
|
|
253
|
+
* @returns The signature text and signature request ID
|
|
245
254
|
*/
|
|
246
255
|
async unsafe_addAccountSignatureText(
|
|
247
256
|
newIdentifier: Identifier,
|
|
@@ -253,6 +262,7 @@ export class Client<
|
|
|
253
262
|
|
|
254
263
|
return this.sendMessage("client.addAccountSignatureText", {
|
|
255
264
|
newIdentifier,
|
|
265
|
+
signatureRequestId: v4(),
|
|
256
266
|
});
|
|
257
267
|
}
|
|
258
268
|
|
|
@@ -266,11 +276,12 @@ export class Client<
|
|
|
266
276
|
* It is highly recommended to use the `removeAccount` method instead.
|
|
267
277
|
*
|
|
268
278
|
* @param identifier - The identifier of the account to remove
|
|
269
|
-
* @returns The signature text
|
|
279
|
+
* @returns The signature text and signature request ID
|
|
270
280
|
*/
|
|
271
281
|
async unsafe_removeAccountSignatureText(identifier: Identifier) {
|
|
272
282
|
return this.sendMessage("client.removeAccountSignatureText", {
|
|
273
283
|
identifier,
|
|
284
|
+
signatureRequestId: v4(),
|
|
274
285
|
});
|
|
275
286
|
}
|
|
276
287
|
|
|
@@ -284,13 +295,12 @@ export class Client<
|
|
|
284
295
|
*
|
|
285
296
|
* It is highly recommended to use the `revokeAllOtherInstallations` method instead.
|
|
286
297
|
*
|
|
287
|
-
* @returns The signature text
|
|
298
|
+
* @returns The signature text and signature request ID
|
|
288
299
|
*/
|
|
289
300
|
async unsafe_revokeAllOtherInstallationsSignatureText() {
|
|
290
|
-
return this.sendMessage(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
);
|
|
301
|
+
return this.sendMessage("client.revokeAllOtherInstallationsSignatureText", {
|
|
302
|
+
signatureRequestId: v4(),
|
|
303
|
+
});
|
|
294
304
|
}
|
|
295
305
|
|
|
296
306
|
/**
|
|
@@ -304,11 +314,12 @@ export class Client<
|
|
|
304
314
|
* It is highly recommended to use the `revokeInstallations` method instead.
|
|
305
315
|
*
|
|
306
316
|
* @param installationIds - The installation IDs to revoke
|
|
307
|
-
* @returns The signature text
|
|
317
|
+
* @returns The signature text and signature request ID
|
|
308
318
|
*/
|
|
309
319
|
async unsafe_revokeInstallationsSignatureText(installationIds: Uint8Array[]) {
|
|
310
320
|
return this.sendMessage("client.revokeInstallationsSignatureText", {
|
|
311
321
|
installationIds,
|
|
322
|
+
signatureRequestId: v4(),
|
|
312
323
|
});
|
|
313
324
|
}
|
|
314
325
|
|
|
@@ -323,68 +334,37 @@ export class Client<
|
|
|
323
334
|
* It is highly recommended to use the `changeRecoveryIdentifier` method instead.
|
|
324
335
|
*
|
|
325
336
|
* @param identifier - The new recovery identifier
|
|
326
|
-
* @returns The signature text
|
|
337
|
+
* @returns The signature text and signature request ID
|
|
327
338
|
*/
|
|
328
339
|
async unsafe_changeRecoveryIdentifierSignatureText(identifier: Identifier) {
|
|
329
340
|
return this.sendMessage("client.changeRecoveryIdentifierSignatureText", {
|
|
330
341
|
identifier,
|
|
342
|
+
signatureRequestId: v4(),
|
|
331
343
|
});
|
|
332
344
|
}
|
|
333
345
|
|
|
334
346
|
/**
|
|
335
|
-
*
|
|
347
|
+
* Applies a signature request to the client
|
|
336
348
|
*
|
|
337
349
|
* WARNING: This function should be used with caution. It is only provided
|
|
338
350
|
* for use in special cases where the provided workflows do not meet the
|
|
339
351
|
* requirements of an application.
|
|
340
352
|
*
|
|
341
353
|
* It is highly recommended to use the `register`, `unsafe_addAccount`,
|
|
342
|
-
* `removeAccount`, `revokeAllOtherInstallations`,
|
|
343
|
-
*
|
|
354
|
+
* `removeAccount`, `revokeAllOtherInstallations`, `revokeInstallations`,
|
|
355
|
+
* or `changeRecoveryIdentifier` method instead.
|
|
344
356
|
*
|
|
345
|
-
* @param signatureType - The type of signature request
|
|
346
|
-
* @param signatureText - The text to sign
|
|
347
357
|
* @param signer - The signer to use
|
|
348
|
-
* @
|
|
358
|
+
* @param signatureRequestId - The ID of the signature request to apply
|
|
349
359
|
*/
|
|
350
|
-
async
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
signer: Signer,
|
|
360
|
+
async unsafe_applySignatureRequest(
|
|
361
|
+
signer: SafeSigner,
|
|
362
|
+
signatureRequestId: string,
|
|
354
363
|
) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
await this.sendMessage("client.addScwSignature", {
|
|
360
|
-
type: signatureType,
|
|
361
|
-
bytes: signature,
|
|
362
|
-
chainId: signer.getChainId(),
|
|
363
|
-
blockNumber: signer.getBlockNumber?.(),
|
|
364
|
-
});
|
|
365
|
-
break;
|
|
366
|
-
case "EOA":
|
|
367
|
-
await this.sendMessage("client.addEcdsaSignature", {
|
|
368
|
-
type: signatureType,
|
|
369
|
-
bytes: signature,
|
|
370
|
-
});
|
|
371
|
-
break;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Applies all pending signatures
|
|
377
|
-
*
|
|
378
|
-
* WARNING: This function should be used with caution. It is only provided
|
|
379
|
-
* for use in special cases where the provided workflows do not meet the
|
|
380
|
-
* requirements of an application.
|
|
381
|
-
*
|
|
382
|
-
* It is highly recommended to use the `register`, `unsafe_addAccount`,
|
|
383
|
-
* `removeAccount`, `revokeAllOtherInstallations`, or `revokeInstallations`
|
|
384
|
-
* methods instead.
|
|
385
|
-
*/
|
|
386
|
-
async unsafe_applySignatures() {
|
|
387
|
-
return this.sendMessage("client.applySignatures", undefined);
|
|
364
|
+
return this.sendMessage("client.applySignatureRequest", {
|
|
365
|
+
signer,
|
|
366
|
+
signatureRequestId,
|
|
367
|
+
});
|
|
388
368
|
}
|
|
389
369
|
|
|
390
370
|
/**
|
|
@@ -399,20 +379,21 @@ export class Client<
|
|
|
399
379
|
throw new SignerUnavailableError();
|
|
400
380
|
}
|
|
401
381
|
|
|
402
|
-
const signatureText
|
|
382
|
+
const { signatureText, signatureRequestId } =
|
|
383
|
+
await this.unsafe_createInboxSignatureText();
|
|
403
384
|
|
|
404
|
-
// if the signature text is not available,
|
|
405
|
-
if (!signatureText) {
|
|
385
|
+
// if the signature text or request ID is not available, don't register
|
|
386
|
+
if (!signatureText || !signatureRequestId) {
|
|
406
387
|
return;
|
|
407
388
|
}
|
|
408
389
|
|
|
409
|
-
await this.
|
|
410
|
-
|
|
411
|
-
signatureText,
|
|
412
|
-
this.#signer,
|
|
413
|
-
);
|
|
390
|
+
const signature = await this.#signer.signMessage(signatureText);
|
|
391
|
+
const signer = await toSafeSigner(this.#signer, signature);
|
|
414
392
|
|
|
415
|
-
return this.sendMessage("client.registerIdentity",
|
|
393
|
+
return this.sendMessage("client.registerIdentity", {
|
|
394
|
+
signer,
|
|
395
|
+
signatureRequestId,
|
|
396
|
+
});
|
|
416
397
|
}
|
|
417
398
|
|
|
418
399
|
/**
|
|
@@ -429,39 +410,43 @@ export class Client<
|
|
|
429
410
|
*
|
|
430
411
|
* @param newAccountSigner - The signer for the new account
|
|
431
412
|
* @param allowInboxReassign - Whether to allow inbox reassignment
|
|
432
|
-
* @throws {AccountAlreadyAssociatedError} if the account is already associated with an inbox ID
|
|
433
|
-
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
434
413
|
* @throws {SignerUnavailableError} if no signer is available
|
|
414
|
+
* @throws {InboxReassignError} if `allowInboxReassign` is false
|
|
415
|
+
* @throws {AccountAlreadyAssociatedError} if the account is already associated with an inbox ID
|
|
435
416
|
*/
|
|
436
417
|
async unsafe_addAccount(
|
|
437
418
|
newAccountSigner: Signer,
|
|
438
419
|
allowInboxReassign: boolean = false,
|
|
439
420
|
) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
);
|
|
421
|
+
if (!this.#signer) {
|
|
422
|
+
throw new SignerUnavailableError();
|
|
423
|
+
}
|
|
444
424
|
|
|
445
|
-
if (
|
|
446
|
-
throw new
|
|
425
|
+
if (!allowInboxReassign) {
|
|
426
|
+
throw new InboxReassignError();
|
|
447
427
|
}
|
|
448
428
|
|
|
449
|
-
|
|
429
|
+
// check for existing inbox id
|
|
430
|
+
const existingInboxId = await this.findInboxIdByIdentifier(
|
|
450
431
|
await newAccountSigner.getIdentifier(),
|
|
451
|
-
true,
|
|
452
432
|
);
|
|
453
433
|
|
|
454
|
-
if (
|
|
455
|
-
throw new
|
|
434
|
+
if (existingInboxId) {
|
|
435
|
+
throw new AccountAlreadyAssociatedError(existingInboxId);
|
|
456
436
|
}
|
|
457
437
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
await
|
|
438
|
+
const { signatureText, signatureRequestId } =
|
|
439
|
+
await this.unsafe_addAccountSignatureText(
|
|
440
|
+
await newAccountSigner.getIdentifier(),
|
|
441
|
+
true,
|
|
442
|
+
);
|
|
443
|
+
const signature = await newAccountSigner.signMessage(signatureText);
|
|
444
|
+
const signer = await toSafeSigner(newAccountSigner, signature);
|
|
445
|
+
return this.sendMessage("client.addAccount", {
|
|
446
|
+
identifier: signer.identifier,
|
|
447
|
+
signer,
|
|
448
|
+
signatureRequestId,
|
|
449
|
+
});
|
|
465
450
|
}
|
|
466
451
|
|
|
467
452
|
/**
|
|
@@ -470,28 +455,23 @@ export class Client<
|
|
|
470
455
|
* Requires a signer, use `Client.create` to create a client with a signer.
|
|
471
456
|
*
|
|
472
457
|
* @param accountIdentifier - The identifier of the account to remove
|
|
473
|
-
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
474
458
|
* @throws {SignerUnavailableError} if no signer is available
|
|
475
459
|
*/
|
|
476
|
-
async removeAccount(
|
|
460
|
+
async removeAccount(identifier: Identifier) {
|
|
477
461
|
if (!this.#signer) {
|
|
478
462
|
throw new SignerUnavailableError();
|
|
479
463
|
}
|
|
480
464
|
|
|
481
|
-
const signatureText =
|
|
482
|
-
await this.unsafe_removeAccountSignatureText(
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
throw new GenerateSignatureError(SignatureRequestType.RevokeWallet);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
await this.unsafe_addSignature(
|
|
489
|
-
SignatureRequestType.RevokeWallet,
|
|
490
|
-
signatureText,
|
|
491
|
-
this.#signer,
|
|
492
|
-
);
|
|
465
|
+
const { signatureText, signatureRequestId } =
|
|
466
|
+
await this.unsafe_removeAccountSignatureText(identifier);
|
|
467
|
+
const signature = await this.#signer.signMessage(signatureText);
|
|
468
|
+
const signer = await toSafeSigner(this.#signer, signature);
|
|
493
469
|
|
|
494
|
-
|
|
470
|
+
return this.sendMessage("client.removeAccount", {
|
|
471
|
+
identifier,
|
|
472
|
+
signer,
|
|
473
|
+
signatureRequestId,
|
|
474
|
+
});
|
|
495
475
|
}
|
|
496
476
|
|
|
497
477
|
/**
|
|
@@ -499,7 +479,6 @@ export class Client<
|
|
|
499
479
|
*
|
|
500
480
|
* Requires a signer, use `Client.create` to create a client with a signer.
|
|
501
481
|
*
|
|
502
|
-
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
503
482
|
* @throws {SignerUnavailableError} if no signer is available
|
|
504
483
|
*/
|
|
505
484
|
async revokeAllOtherInstallations() {
|
|
@@ -507,22 +486,15 @@ export class Client<
|
|
|
507
486
|
throw new SignerUnavailableError();
|
|
508
487
|
}
|
|
509
488
|
|
|
510
|
-
const signatureText =
|
|
489
|
+
const { signatureText, signatureRequestId } =
|
|
511
490
|
await this.unsafe_revokeAllOtherInstallationsSignatureText();
|
|
491
|
+
const signature = await this.#signer.signMessage(signatureText);
|
|
492
|
+
const signer = await toSafeSigner(this.#signer, signature);
|
|
512
493
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
await this.unsafe_addSignature(
|
|
520
|
-
SignatureRequestType.RevokeInstallations,
|
|
521
|
-
signatureText,
|
|
522
|
-
this.#signer,
|
|
523
|
-
);
|
|
524
|
-
|
|
525
|
-
await this.unsafe_applySignatures();
|
|
494
|
+
return this.sendMessage("client.revokeAllOtherInstallations", {
|
|
495
|
+
signer,
|
|
496
|
+
signatureRequestId,
|
|
497
|
+
});
|
|
526
498
|
}
|
|
527
499
|
|
|
528
500
|
/**
|
|
@@ -531,7 +503,6 @@ export class Client<
|
|
|
531
503
|
* Requires a signer, use `Client.create` to create a client with a signer.
|
|
532
504
|
*
|
|
533
505
|
* @param installationIds - The installation IDs to revoke
|
|
534
|
-
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
535
506
|
* @throws {SignerUnavailableError} if no signer is available
|
|
536
507
|
*/
|
|
537
508
|
async revokeInstallations(installationIds: Uint8Array[]) {
|
|
@@ -539,22 +510,49 @@ export class Client<
|
|
|
539
510
|
throw new SignerUnavailableError();
|
|
540
511
|
}
|
|
541
512
|
|
|
542
|
-
const signatureText =
|
|
513
|
+
const { signatureText, signatureRequestId } =
|
|
543
514
|
await this.unsafe_revokeInstallationsSignatureText(installationIds);
|
|
515
|
+
const signature = await this.#signer.signMessage(signatureText);
|
|
516
|
+
const signer = await toSafeSigner(this.#signer, signature);
|
|
544
517
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
518
|
+
return this.sendMessage("client.revokeInstallations", {
|
|
519
|
+
installationIds,
|
|
520
|
+
signer,
|
|
521
|
+
signatureRequestId,
|
|
522
|
+
});
|
|
523
|
+
}
|
|
550
524
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
525
|
+
/**
|
|
526
|
+
* Revokes specific installations of the client's inbox without a client
|
|
527
|
+
*
|
|
528
|
+
* @param env - The environment to use
|
|
529
|
+
* @param signer - The signer to use
|
|
530
|
+
* @param inboxId - The inbox ID to revoke installations for
|
|
531
|
+
* @param installationIds - The installation IDs to revoke
|
|
532
|
+
*/
|
|
533
|
+
static async revokeInstallations(
|
|
534
|
+
signer: Signer,
|
|
535
|
+
inboxId: string,
|
|
536
|
+
installationIds: Uint8Array[],
|
|
537
|
+
env?: XmtpEnv,
|
|
538
|
+
) {
|
|
539
|
+
const utils = new Utils();
|
|
540
|
+
await utils.revokeInstallations(signer, inboxId, installationIds, env);
|
|
541
|
+
utils.close();
|
|
542
|
+
}
|
|
556
543
|
|
|
557
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Gets the inbox state for the specified inbox IDs without a client
|
|
546
|
+
*
|
|
547
|
+
* @param inboxIds - The inbox IDs to get the state for
|
|
548
|
+
* @param env - The environment to use
|
|
549
|
+
* @returns The inbox state for the specified inbox IDs
|
|
550
|
+
*/
|
|
551
|
+
static async inboxStateFromInboxIds(inboxIds: string[], env?: XmtpEnv) {
|
|
552
|
+
const utils = new Utils();
|
|
553
|
+
const result = await utils.inboxStateFromInboxIds(inboxIds, env);
|
|
554
|
+
utils.close();
|
|
555
|
+
return result;
|
|
558
556
|
}
|
|
559
557
|
|
|
560
558
|
/**
|
|
@@ -563,7 +561,6 @@ export class Client<
|
|
|
563
561
|
* Requires a signer, use `Client.create` to create a client with a signer.
|
|
564
562
|
*
|
|
565
563
|
* @param identifier - The new recovery identifier
|
|
566
|
-
* @throws {GenerateSignatureError} if the signature cannot be generated
|
|
567
564
|
* @throws {SignerUnavailableError} if no signer is available
|
|
568
565
|
*/
|
|
569
566
|
async changeRecoveryIdentifier(identifier: Identifier) {
|
|
@@ -571,22 +568,16 @@ export class Client<
|
|
|
571
568
|
throw new SignerUnavailableError();
|
|
572
569
|
}
|
|
573
570
|
|
|
574
|
-
const signatureText =
|
|
571
|
+
const { signatureText, signatureRequestId } =
|
|
575
572
|
await this.unsafe_changeRecoveryIdentifierSignatureText(identifier);
|
|
573
|
+
const signature = await this.#signer.signMessage(signatureText);
|
|
574
|
+
const signer = await toSafeSigner(this.#signer, signature);
|
|
576
575
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
await this.unsafe_addSignature(
|
|
584
|
-
SignatureRequestType.ChangeRecoveryIdentifier,
|
|
585
|
-
signatureText,
|
|
586
|
-
this.#signer,
|
|
587
|
-
);
|
|
588
|
-
|
|
589
|
-
await this.unsafe_applySignatures();
|
|
576
|
+
return this.sendMessage("client.changeRecoveryIdentifier", {
|
|
577
|
+
identifier,
|
|
578
|
+
signer,
|
|
579
|
+
signatureRequestId,
|
|
580
|
+
});
|
|
590
581
|
}
|
|
591
582
|
|
|
592
583
|
/**
|
|
@@ -763,26 +754,4 @@ export class Client<
|
|
|
763
754
|
installationIds,
|
|
764
755
|
});
|
|
765
756
|
}
|
|
766
|
-
|
|
767
|
-
apiStatistics() {
|
|
768
|
-
return this.sendMessage("client.apiStatistics", undefined);
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
apiIdentityStatistics() {
|
|
772
|
-
return this.sendMessage("client.apiIdentityStatistics", undefined);
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
apiAggregateStatistics() {
|
|
776
|
-
return this.sendMessage("client.apiAggregateStatistics", undefined);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
clearAllStatistics() {
|
|
780
|
-
return this.sendMessage("client.clearAllStatistics", undefined);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
async uploadDebugArchive(serverUrl?: string) {
|
|
784
|
-
return this.sendMessage("client.uploadDebugArchive", {
|
|
785
|
-
serverUrl,
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
757
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Client } from "./Client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Debug information helpers for the client
|
|
5
|
+
*
|
|
6
|
+
* This class is not intended to be initialized directly.
|
|
7
|
+
*/
|
|
8
|
+
export class DebugInformation<ContentTypes = unknown> {
|
|
9
|
+
#client: Client<ContentTypes>;
|
|
10
|
+
|
|
11
|
+
constructor(client: Client<ContentTypes>) {
|
|
12
|
+
this.#client = client;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
apiStatistics() {
|
|
16
|
+
return this.#client.sendMessage(
|
|
17
|
+
"debugInformation.apiStatistics",
|
|
18
|
+
undefined,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
apiIdentityStatistics() {
|
|
23
|
+
return this.#client.sendMessage(
|
|
24
|
+
"debugInformation.apiIdentityStatistics",
|
|
25
|
+
undefined,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
apiAggregateStatistics() {
|
|
30
|
+
return this.#client.sendMessage(
|
|
31
|
+
"debugInformation.apiAggregateStatistics",
|
|
32
|
+
undefined,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
clearAllStatistics() {
|
|
37
|
+
return this.#client.sendMessage(
|
|
38
|
+
"debugInformation.clearAllStatistics",
|
|
39
|
+
undefined,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
uploadDebugArchive(serverUrl?: string) {
|
|
44
|
+
return this.#client.sendMessage("debugInformation.uploadDebugArchive", {
|
|
45
|
+
serverUrl,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|