@xmtp/browser-sdk 0.0.13 → 0.0.15
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 +37 -10
- 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.map +1 -1
- package/package.json +2 -2
- package/src/Conversations.ts +4 -0
- package/src/WorkerConversations.ts +5 -0
- package/src/constants.ts +6 -0
- package/src/index.ts +2 -1
- package/src/types/clientEvents.ts +7 -0
- package/src/types/options.ts +13 -8
- package/src/utils/conversions.ts +20 -0
- package/src/utils/createClient.ts +5 -6
- package/src/workers/client.ts +15 -0
package/src/utils/conversions.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
type DeliveryStatus,
|
|
19
19
|
type GroupMembershipState,
|
|
20
20
|
type GroupMessageKind,
|
|
21
|
+
type HmacKey,
|
|
21
22
|
type InboxState,
|
|
22
23
|
type Installation,
|
|
23
24
|
type Message,
|
|
@@ -210,6 +211,7 @@ export type SafePermissionPolicySet = {
|
|
|
210
211
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
211
212
|
updateGroupNamePolicy: PermissionPolicy;
|
|
212
213
|
updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
|
|
214
|
+
updateMessageExpirationPolicy: PermissionPolicy;
|
|
213
215
|
};
|
|
214
216
|
|
|
215
217
|
export const toSafePermissionPolicySet = (
|
|
@@ -223,6 +225,7 @@ export const toSafePermissionPolicySet = (
|
|
|
223
225
|
updateGroupImageUrlSquarePolicy: policySet.updateGroupImageUrlSquarePolicy,
|
|
224
226
|
updateGroupNamePolicy: policySet.updateGroupNamePolicy,
|
|
225
227
|
updateGroupPinnedFrameUrlPolicy: policySet.updateGroupPinnedFrameUrlPolicy,
|
|
228
|
+
updateMessageExpirationPolicy: policySet.updateMessageExpirationPolicy,
|
|
226
229
|
});
|
|
227
230
|
|
|
228
231
|
export const fromSafePermissionPolicySet = (
|
|
@@ -237,6 +240,7 @@ export const fromSafePermissionPolicySet = (
|
|
|
237
240
|
policySet.updateGroupDescriptionPolicy,
|
|
238
241
|
policySet.updateGroupImageUrlSquarePolicy,
|
|
239
242
|
policySet.updateGroupPinnedFrameUrlPolicy,
|
|
243
|
+
policySet.updateMessageExpirationPolicy,
|
|
240
244
|
);
|
|
241
245
|
|
|
242
246
|
export type SafeCreateGroupOptions = {
|
|
@@ -292,6 +296,7 @@ export type SafeConversation = {
|
|
|
292
296
|
updateGroupImageUrlSquarePolicy: PermissionPolicy;
|
|
293
297
|
updateGroupNamePolicy: PermissionPolicy;
|
|
294
298
|
updateGroupPinnedFrameUrlPolicy: PermissionPolicy;
|
|
299
|
+
updateMessageExpirationPolicy: PermissionPolicy;
|
|
295
300
|
};
|
|
296
301
|
};
|
|
297
302
|
isActive: boolean;
|
|
@@ -328,6 +333,8 @@ export const toSafeConversation = async (
|
|
|
328
333
|
conversation.permissions.policySet.updateGroupNamePolicy,
|
|
329
334
|
updateGroupPinnedFrameUrlPolicy:
|
|
330
335
|
conversation.permissions.policySet.updateGroupPinnedFrameUrlPolicy,
|
|
336
|
+
updateMessageExpirationPolicy:
|
|
337
|
+
conversation.permissions.policySet.updateMessageExpirationPolicy,
|
|
331
338
|
},
|
|
332
339
|
},
|
|
333
340
|
isActive: conversation.isActive,
|
|
@@ -405,3 +412,16 @@ export const fromSafeGroupMember = (member: SafeGroupMember): GroupMember =>
|
|
|
405
412
|
member.permissionLevel,
|
|
406
413
|
member.consentState,
|
|
407
414
|
);
|
|
415
|
+
|
|
416
|
+
export type SafeHmacKey = {
|
|
417
|
+
key: Uint8Array;
|
|
418
|
+
epoch: bigint;
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
export const toSafeHmacKey = (hmacKey: HmacKey): SafeHmacKey => ({
|
|
422
|
+
key: hmacKey.key,
|
|
423
|
+
epoch: hmacKey.epoch,
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
export type HmacKeys = Map<string, HmacKey[]>;
|
|
427
|
+
export type SafeHmacKeys = Record<string, SafeHmacKey[]>;
|
|
@@ -4,7 +4,7 @@ import init, {
|
|
|
4
4
|
getInboxIdForAddress,
|
|
5
5
|
LogOptions,
|
|
6
6
|
} from "@xmtp/wasm-bindings";
|
|
7
|
-
import { ApiUrls } from "@/constants";
|
|
7
|
+
import { ApiUrls, HistorySyncUrls } from "@/constants";
|
|
8
8
|
import type { ClientOptions } from "@/types";
|
|
9
9
|
|
|
10
10
|
export const createClient = async (
|
|
@@ -16,10 +16,6 @@ export const createClient = async (
|
|
|
16
16
|
await init();
|
|
17
17
|
|
|
18
18
|
const host = options?.apiUrl ?? ApiUrls[options?.env ?? "dev"];
|
|
19
|
-
// TODO: add db path validation
|
|
20
|
-
// - must end with .db3
|
|
21
|
-
// - must not contain invalid characters
|
|
22
|
-
// - must not start with a dot
|
|
23
19
|
const dbPath =
|
|
24
20
|
options?.dbPath ?? `xmtp-${options?.env ?? "dev"}-${accountAddress}.db3`;
|
|
25
21
|
|
|
@@ -33,13 +29,16 @@ export const createClient = async (
|
|
|
33
29
|
options.structuredLogging ||
|
|
34
30
|
options.performanceLogging);
|
|
35
31
|
|
|
32
|
+
const historySyncUrl =
|
|
33
|
+
options?.historySyncUrl ?? HistorySyncUrls[options?.env ?? "dev"];
|
|
34
|
+
|
|
36
35
|
return createWasmClient(
|
|
37
36
|
host,
|
|
38
37
|
inboxId,
|
|
39
38
|
accountAddress,
|
|
40
39
|
dbPath,
|
|
41
40
|
encryptionKey,
|
|
42
|
-
|
|
41
|
+
historySyncUrl,
|
|
43
42
|
isLogging
|
|
44
43
|
? new LogOptions(
|
|
45
44
|
options.structuredLogging ?? false,
|
package/src/workers/client.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
fromEncodedContent,
|
|
9
9
|
fromSafeEncodedContent,
|
|
10
10
|
toSafeConversation,
|
|
11
|
+
toSafeHmacKey,
|
|
11
12
|
toSafeInboxState,
|
|
12
13
|
toSafeMessage,
|
|
13
14
|
} from "@/utils/conversions";
|
|
@@ -376,6 +377,20 @@ self.onmessage = async (event: MessageEvent<ClientEventsClientMessageData>) => {
|
|
|
376
377
|
});
|
|
377
378
|
break;
|
|
378
379
|
}
|
|
380
|
+
case "getHmacKeys": {
|
|
381
|
+
const result = client.conversations.getHmacKeys();
|
|
382
|
+
postMessage({
|
|
383
|
+
id,
|
|
384
|
+
action,
|
|
385
|
+
result: Object.fromEntries(
|
|
386
|
+
Array.from(result.entries()).map(([groupId, hmacKeys]) => [
|
|
387
|
+
groupId,
|
|
388
|
+
hmacKeys.map(toSafeHmacKey),
|
|
389
|
+
]),
|
|
390
|
+
),
|
|
391
|
+
});
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
379
394
|
/**
|
|
380
395
|
* Group actions
|
|
381
396
|
*/
|