@xmtp/browser-sdk 6.4.1 → 7.0.0-dev.b5cdc06
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/README.md +17 -0
- package/dist/index.d.ts +206 -8
- 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/package.json +16 -7
- package/src/Client.ts +250 -5
- package/src/Conversation.ts +13 -0
- package/src/WorkerClient.ts +64 -2
- package/src/WorkerConversation.ts +4 -0
- package/src/index.ts +5 -0
- package/src/types/actions/client.ts +81 -1
- package/src/types/actions/conversation.ts +10 -0
- package/src/types/options.ts +19 -0
- package/src/utils/WorkerBridge.ts +1 -1
- package/src/utils/createClient.ts +11 -4
- package/src/utils/signer.ts +37 -1
- package/src/workers/client.ts +56 -1
package/README.md
CHANGED
|
@@ -57,6 +57,23 @@ pnpm install @xmtp/browser-sdk
|
|
|
57
57
|
yarn add @xmtp/browser-sdk
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
## Signer utilities
|
|
61
|
+
|
|
62
|
+
The SDK exports `createEOASigner` and `createSCWSigner` helper functions for creating XMTP-compatible signers. These require `viem` as a peer dependency, which is optional and only needs to be installed if you use these utilities.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install viem
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Example**
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { createEOASigner } from "@xmtp/browser-sdk";
|
|
72
|
+
|
|
73
|
+
// Create an EOA signer (generates a random key if none provided)
|
|
74
|
+
const eoaSigner = createEOASigner();
|
|
75
|
+
```
|
|
76
|
+
|
|
60
77
|
## Developing
|
|
61
78
|
|
|
62
79
|
Run `yarn dev` to build the SDK and watch for changes, which will trigger a rebuild.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _xmtp_wasm_bindings from '@xmtp/wasm-bindings';
|
|
2
|
-
import { ContentTypeId as ContentTypeId$1, DeliveryStatus, GroupMessageKind, Reaction, DecodedMessage as DecodedMessage$1, LeaveRequest, ReadReceipt, Attachment, RemoteAttachment, TransactionReference, WalletSendCalls, Actions, Intent, MultiRemoteAttachment, GroupUpdated, DeletedMessage, Backend, LogLevel, Identifier, Conversations as Conversations$1, ConsentState, ListConversationsOptions, CreateGroupOptions, CreateDmOptions, Conversation as Conversation$1, ConversationType, Message, Client as Client$1, Consent, ConsentEntityType, UserPreferenceUpdate, SignatureRequestHandle, KeyPackageStatus, ArchiveOptions, GroupMember, PermissionUpdateType, PermissionPolicy, MetadataField, EncodedContent, SendMessageOpts, Reply, ListMessagesOptions, MessageDisappearingSettings, HmacKey, ConversationDebugInfo, GroupPermissionsOptions, PermissionPolicySet, GroupMetadata, ApiStats, IdentityStats, InboxState
|
|
3
|
-
export { Action, ActionStyle, Actions, ApiStats, ArchiveOptions, Attachment, Backend, BackendBuilder, BackupElementSelectionOption, Consent, ConsentEntityType, ConsentState, ContentType, ConversationDebugInfo, ConversationListItem, ConversationType, CreateDmOptions, CreateGroupOptions, Cursor, DeliveryStatus, EncryptedAttachment, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, GroupSyncSummary, GroupUpdated, HmacKey, Identifier, IdentifierKind, IdentityStats, Inbox, InboxState, Installation, Intent, KeyPackageStatus, LeaveRequest, Lifetime, ListConversationsOptions, ListConversationsOrderBy, ListMessagesOptions, LogLevel, LogOptions, Message, MessageDisappearingSettings, MessageSortBy, MetadataField, MetadataFieldChange, MultiRemoteAttachment, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, Reaction, ReactionAction, ReactionSchema, ReadReceipt, RemoteAttachment, Reply, SendMessageOpts, SignatureRequestHandle, SortDirection, TransactionMetadata, TransactionReference, UserPreferenceUpdate, WalletCall, WalletSendCalls } from '@xmtp/wasm-bindings';
|
|
2
|
+
import { ContentTypeId as ContentTypeId$1, DeliveryStatus, GroupMessageKind, Reaction, DecodedMessage as DecodedMessage$1, LeaveRequest, ReadReceipt, Attachment, RemoteAttachment, TransactionReference, WalletSendCalls, Actions, Intent, MultiRemoteAttachment, GroupUpdated, DeletedMessage, Backend, LogLevel, WorkerConfigOptions, WasmVisibilityConfirmationOptions, Identifier, Conversations as Conversations$1, ConsentState, ListConversationsOptions, CreateGroupOptions, CreateDmOptions, Conversation as Conversation$1, ConversationType, Message, Client as Client$1, Consent, ConsentEntityType, UserPreferenceUpdate, SignatureRequestHandle, KeyPackageStatus, ArchiveOptions, AvailableArchiveInfo, ArchiveMetadata, GroupSyncSummary, GroupMember, PermissionUpdateType, PermissionPolicy, MetadataField, EncodedContent, SendMessageOpts, Reply, ListMessagesOptions, MessageDisappearingSettings, HmacKey, ConversationDebugInfo, GroupPermissionsOptions, PermissionPolicySet, GroupMetadata, ApiStats, IdentityStats, InboxState } from '@xmtp/wasm-bindings';
|
|
3
|
+
export { Action, ActionStyle, Actions, ApiStats, ArchiveMetadata, ArchiveOptions, Attachment, AvailableArchiveInfo, Backend, BackendBuilder, BackupElementSelectionOption, Consent, ConsentEntityType, ConsentState, ContentType, ConversationDebugInfo, ConversationListItem, ConversationType, CreateDmOptions, CreateGroupOptions, Cursor, DeliveryStatus, EncryptedAttachment, GroupMember, GroupMembershipState, GroupMessageKind, GroupMetadata, GroupPermissions, GroupPermissionsOptions, GroupSyncSummary, GroupUpdated, HmacKey, Identifier, IdentifierKind, IdentityStats, Inbox, InboxState, Installation, Intent, KeyPackageStatus, LeaveRequest, Lifetime, ListConversationsOptions, ListConversationsOrderBy, ListMessagesOptions, LogLevel, LogOptions, Message, MessageDisappearingSettings, MessageSortBy, MetadataField, MetadataFieldChange, MultiRemoteAttachment, PermissionLevel, PermissionPolicy, PermissionPolicySet, PermissionUpdateType, Reaction, ReactionAction, ReactionSchema, ReadReceipt, RemoteAttachment, Reply, SendMessageOpts, SignatureRequestHandle, SortDirection, TransactionMetadata, TransactionReference, UserPreferenceUpdate, WalletCall, WalletSendCalls, WorkerConfigOptions, WorkerIntervalOverride, WorkerKind } from '@xmtp/wasm-bindings';
|
|
4
4
|
import { ContentCodec, ContentTypeId } from '@xmtp/content-type-primitives';
|
|
5
5
|
|
|
6
6
|
type ResolveValue<T> = {
|
|
@@ -131,6 +131,7 @@ declare class DecodedMessage<ContentTypes = unknown> {
|
|
|
131
131
|
constructor(codecRegistry: CodecRegistry, message: DecodedMessage$1);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
type VisibilityConfirmationOptions = WasmVisibilityConfirmationOptions;
|
|
134
135
|
type XmtpEnv = "local" | "dev" | "production" | "testnet-staging" | "testnet-dev" | "testnet" | "mainnet";
|
|
135
136
|
/**
|
|
136
137
|
* Network options
|
|
@@ -214,10 +215,25 @@ type OtherOptions = {
|
|
|
214
215
|
* Logging level
|
|
215
216
|
*/
|
|
216
217
|
loggingLevel?: LogLevel;
|
|
218
|
+
/**
|
|
219
|
+
* Tuning for the background worker scheduler (intervals, jitter, per-worker
|
|
220
|
+
* overrides, and disabled workers). All fields are optional; omitting this
|
|
221
|
+
* object preserves the default worker behavior.
|
|
222
|
+
*
|
|
223
|
+
* Intervals are specified in nanoseconds.
|
|
224
|
+
*/
|
|
225
|
+
workerConfig?: WorkerConfigOptions;
|
|
217
226
|
/**
|
|
218
227
|
* Disable automatic registration when creating a client
|
|
219
228
|
*/
|
|
220
229
|
disableAutoRegister?: boolean;
|
|
230
|
+
/**
|
|
231
|
+
* Options for waiting until client registration is visible on the network.
|
|
232
|
+
*
|
|
233
|
+
* When set, `registerIdentity` will wait for the specified quorum of nodes
|
|
234
|
+
* to confirm the registration before resolving.
|
|
235
|
+
*/
|
|
236
|
+
waitForRegistrationVisible?: VisibilityConfirmationOptions;
|
|
221
237
|
};
|
|
222
238
|
type ClientOptions = (NetworkOptions | {
|
|
223
239
|
backend: Backend;
|
|
@@ -263,6 +279,8 @@ type SafeSigner = {
|
|
|
263
279
|
chainId: bigint;
|
|
264
280
|
blockNumber?: bigint;
|
|
265
281
|
};
|
|
282
|
+
declare const createEOASigner: (key?: `0x${string}`) => Signer;
|
|
283
|
+
declare const createSCWSigner: (address: `0x${string}`, signMessage: (message: string) => Promise<string> | string, chainId: bigint) => Signer;
|
|
266
284
|
declare const toSafeSigner: (signer: Signer, signature: Uint8Array) => Promise<SafeSigner>;
|
|
267
285
|
|
|
268
286
|
declare class WorkerConversations {
|
|
@@ -331,6 +349,8 @@ declare class WorkerClient {
|
|
|
331
349
|
get debugInformation(): WorkerDebugInformation;
|
|
332
350
|
get preferences(): WorkerPreferences;
|
|
333
351
|
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
352
|
+
fetchLatestInboxUpdatesCount(inboxIds: string[]): Promise<Record<string, number>>;
|
|
353
|
+
fetchOwnInboxUpdatesCount(): Promise<number>;
|
|
334
354
|
addSignature(signatureRequest: SignatureRequestHandle, signer: SafeSigner): Promise<void>;
|
|
335
355
|
applySignatureRequest(signatureRequest: SignatureRequestHandle): Promise<void>;
|
|
336
356
|
processSignatureRequest(signer: SafeSigner, signatureRequest: SignatureRequestHandle): Promise<void>;
|
|
@@ -340,13 +360,20 @@ declare class WorkerClient {
|
|
|
340
360
|
revokeAllOtherInstallationsSignatureRequest(): Promise<SignatureRequestHandle | undefined>;
|
|
341
361
|
revokeInstallationsSignatureRequest(installationIds: Uint8Array[]): Promise<SignatureRequestHandle>;
|
|
342
362
|
changeRecoveryIdentifierSignatureRequest(identifier: Identifier): Promise<SignatureRequestHandle>;
|
|
343
|
-
registerIdentity(signer: SafeSigner, signatureRequest: SignatureRequestHandle): Promise<void>;
|
|
363
|
+
registerIdentity(signer: SafeSigner, signatureRequest: SignatureRequestHandle, visibilityConfirmationOptions?: VisibilityConfirmationOptions): Promise<void>;
|
|
344
364
|
getInboxIdByIdentifier(identifier: Identifier): Promise<string | undefined>;
|
|
345
365
|
signWithInstallationKey(signatureText: string): Uint8Array<ArrayBufferLike>;
|
|
346
366
|
verifySignedWithInstallationKey(signatureText: string, signatureBytes: Uint8Array): boolean;
|
|
347
367
|
verifySignedWithPublicKey(signatureText: string, signatureBytes: Uint8Array, publicKey: Uint8Array): boolean;
|
|
348
368
|
fetchKeyPackageStatuses(installationIds: string[]): Promise<Map<string, KeyPackageStatus>>;
|
|
349
369
|
sendSyncRequest(options: ArchiveOptions, serverUrl: string): Promise<void>;
|
|
370
|
+
sendSyncArchive(options: ArchiveOptions, serverUrl: string, pin: string): Promise<void>;
|
|
371
|
+
processSyncArchive(archivePin?: string | null): Promise<void>;
|
|
372
|
+
listAvailableArchives(daysCutoff: number): AvailableArchiveInfo[];
|
|
373
|
+
createArchive(opts: ArchiveOptions, key: Uint8Array): Promise<Uint8Array>;
|
|
374
|
+
importArchive(data: Uint8Array, key: Uint8Array): Promise<void>;
|
|
375
|
+
archiveMetadata(data: Uint8Array, key: Uint8Array): Promise<ArchiveMetadata>;
|
|
376
|
+
syncAllDeviceSyncGroups(): Promise<GroupSyncSummary>;
|
|
350
377
|
}
|
|
351
378
|
|
|
352
379
|
declare class WorkerConversation {
|
|
@@ -386,6 +413,7 @@ declare class WorkerConversation {
|
|
|
386
413
|
addSuperAdmin(inboxId: string): Promise<void>;
|
|
387
414
|
removeSuperAdmin(inboxId: string): Promise<void>;
|
|
388
415
|
publishMessages(): Promise<void>;
|
|
416
|
+
processStreamedMessage(envelopeBytes: Uint8Array): Promise<Message[]>;
|
|
389
417
|
send(encodedContent: EncodedContent, opts?: SendMessageOpts): Promise<string>;
|
|
390
418
|
sendText(text: string, isOptimistic?: boolean): Promise<string>;
|
|
391
419
|
sendMarkdown(markdown: string, isOptimistic?: boolean): Promise<string>;
|
|
@@ -532,6 +560,7 @@ type ClientAction = {
|
|
|
532
560
|
data: {
|
|
533
561
|
signer: SafeSigner;
|
|
534
562
|
signatureRequestId: string;
|
|
563
|
+
waitForRegistrationVisible?: VisibilityConfirmationOptions;
|
|
535
564
|
};
|
|
536
565
|
} | {
|
|
537
566
|
action: "client.addAccount";
|
|
@@ -589,6 +618,18 @@ type ClientAction = {
|
|
|
589
618
|
data: {
|
|
590
619
|
identifiers: Identifier[];
|
|
591
620
|
};
|
|
621
|
+
} | {
|
|
622
|
+
action: "client.fetchLatestInboxUpdatesCount";
|
|
623
|
+
id: string;
|
|
624
|
+
result: Record<string, number>;
|
|
625
|
+
data: {
|
|
626
|
+
inboxIds: string[];
|
|
627
|
+
};
|
|
628
|
+
} | {
|
|
629
|
+
action: "client.fetchOwnInboxUpdatesCount";
|
|
630
|
+
id: string;
|
|
631
|
+
result: number;
|
|
632
|
+
data: Record<string, never>;
|
|
592
633
|
} | {
|
|
593
634
|
action: "client.getInboxIdByIdentifier";
|
|
594
635
|
id: string;
|
|
@@ -635,6 +676,58 @@ type ClientAction = {
|
|
|
635
676
|
options: ArchiveOptions;
|
|
636
677
|
serverUrl: string;
|
|
637
678
|
};
|
|
679
|
+
} | {
|
|
680
|
+
action: "client.sendSyncArchive";
|
|
681
|
+
id: string;
|
|
682
|
+
result: undefined;
|
|
683
|
+
data: {
|
|
684
|
+
options: ArchiveOptions;
|
|
685
|
+
serverUrl: string;
|
|
686
|
+
pin: string;
|
|
687
|
+
};
|
|
688
|
+
} | {
|
|
689
|
+
action: "client.processSyncArchive";
|
|
690
|
+
id: string;
|
|
691
|
+
result: undefined;
|
|
692
|
+
data: {
|
|
693
|
+
archivePin?: string | null;
|
|
694
|
+
};
|
|
695
|
+
} | {
|
|
696
|
+
action: "client.listAvailableArchives";
|
|
697
|
+
id: string;
|
|
698
|
+
result: AvailableArchiveInfo[];
|
|
699
|
+
data: {
|
|
700
|
+
daysCutoff: number;
|
|
701
|
+
};
|
|
702
|
+
} | {
|
|
703
|
+
action: "client.createArchive";
|
|
704
|
+
id: string;
|
|
705
|
+
result: Uint8Array;
|
|
706
|
+
data: {
|
|
707
|
+
opts: ArchiveOptions;
|
|
708
|
+
key: Uint8Array;
|
|
709
|
+
};
|
|
710
|
+
} | {
|
|
711
|
+
action: "client.importArchive";
|
|
712
|
+
id: string;
|
|
713
|
+
result: undefined;
|
|
714
|
+
data: {
|
|
715
|
+
data: Uint8Array;
|
|
716
|
+
key: Uint8Array;
|
|
717
|
+
};
|
|
718
|
+
} | {
|
|
719
|
+
action: "client.archiveMetadata";
|
|
720
|
+
id: string;
|
|
721
|
+
result: ArchiveMetadata;
|
|
722
|
+
data: {
|
|
723
|
+
data: Uint8Array;
|
|
724
|
+
key: Uint8Array;
|
|
725
|
+
};
|
|
726
|
+
} | {
|
|
727
|
+
action: "client.syncAllDeviceSyncGroups";
|
|
728
|
+
id: string;
|
|
729
|
+
result: GroupSyncSummary;
|
|
730
|
+
data: undefined;
|
|
638
731
|
};
|
|
639
732
|
|
|
640
733
|
type ConversationAction = {
|
|
@@ -660,6 +753,14 @@ type ConversationAction = {
|
|
|
660
753
|
data: {
|
|
661
754
|
id: string;
|
|
662
755
|
};
|
|
756
|
+
} | {
|
|
757
|
+
action: "conversation.processStreamedMessage";
|
|
758
|
+
id: string;
|
|
759
|
+
result: Message[];
|
|
760
|
+
data: {
|
|
761
|
+
id: string;
|
|
762
|
+
envelopeBytes: Uint8Array;
|
|
763
|
+
};
|
|
663
764
|
} | {
|
|
664
765
|
action: "conversation.messages";
|
|
665
766
|
id: string;
|
|
@@ -1397,6 +1498,13 @@ declare class Conversation<ContentTypes = unknown> {
|
|
|
1397
1498
|
* @returns Promise that resolves when publishing is complete
|
|
1398
1499
|
*/
|
|
1399
1500
|
publishMessages(): Promise<void>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Decodes, decrypts, and persists a raw envelope from a group message stream.
|
|
1503
|
+
*
|
|
1504
|
+
* @param envelopeBytes - Raw protobuf-encoded envelope bytes from the stream
|
|
1505
|
+
* @returns The processed and stored messages
|
|
1506
|
+
*/
|
|
1507
|
+
processStreamedMessage(envelopeBytes: Uint8Array): Promise<_xmtp_wasm_bindings.Message[]>;
|
|
1400
1508
|
/**
|
|
1401
1509
|
* Sends a message
|
|
1402
1510
|
*
|
|
@@ -2401,6 +2509,19 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
2401
2509
|
* @returns Whether the client can message the identifiers
|
|
2402
2510
|
*/
|
|
2403
2511
|
canMessage(identifiers: Identifier[]): Promise<Map<string, boolean>>;
|
|
2512
|
+
/**
|
|
2513
|
+
* Fetches the latest inbox updates count for the specified inbox IDs
|
|
2514
|
+
*
|
|
2515
|
+
* @param inboxIds - The inbox IDs to check
|
|
2516
|
+
* @returns Map of inbox IDs to their updates count
|
|
2517
|
+
*/
|
|
2518
|
+
fetchLatestInboxUpdatesCount(inboxIds: string[]): Promise<Map<string, number>>;
|
|
2519
|
+
/**
|
|
2520
|
+
* Fetches the latest inbox updates count for the client's inbox
|
|
2521
|
+
*
|
|
2522
|
+
* @returns The latest inbox updates count
|
|
2523
|
+
*/
|
|
2524
|
+
fetchOwnInboxUpdatesCount(): Promise<number>;
|
|
2404
2525
|
/**
|
|
2405
2526
|
* Checks if the specified identifiers can be messaged
|
|
2406
2527
|
*
|
|
@@ -2419,6 +2540,27 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
2419
2540
|
* of `XmtpEnv`.
|
|
2420
2541
|
*/
|
|
2421
2542
|
static canMessage(identifiers: Identifier[], env?: XmtpEnv): Promise<Map<string, boolean>>;
|
|
2543
|
+
/**
|
|
2544
|
+
* Fetches the latest inbox updates count for the specified inbox IDs
|
|
2545
|
+
* without a client
|
|
2546
|
+
*
|
|
2547
|
+
* @param inboxIds - The inbox IDs to check
|
|
2548
|
+
* @param backend - Optional `Backend` instance created with `createBackend()`
|
|
2549
|
+
* @returns Map of inbox IDs to their updates count
|
|
2550
|
+
*/
|
|
2551
|
+
static fetchLatestInboxUpdatesCount(inboxIds: string[], backendOrEnv?: Backend | XmtpEnv): Promise<Map<string, number>>;
|
|
2552
|
+
/**
|
|
2553
|
+
* Fetches the latest inbox updates count for the specified inbox IDs
|
|
2554
|
+
* without a client
|
|
2555
|
+
*
|
|
2556
|
+
* @param inboxIds - The inbox IDs to check
|
|
2557
|
+
* @param env - Optional XMTP environment
|
|
2558
|
+
* @param gatewayHost - Optional gateway host
|
|
2559
|
+
* @returns Map of inbox IDs to their updates count
|
|
2560
|
+
* @deprecated Pass a `Backend` instance created with `createBackend()` instead
|
|
2561
|
+
* of `XmtpEnv` and `gatewayHost`.
|
|
2562
|
+
*/
|
|
2563
|
+
static fetchLatestInboxUpdatesCount(inboxIds: string[], env?: XmtpEnv, gatewayHost?: string): Promise<Map<string, number>>;
|
|
2422
2564
|
/**
|
|
2423
2565
|
* Fetches the inbox ID for a given identifier from the local database
|
|
2424
2566
|
* If not found, fetches from the network
|
|
@@ -2462,11 +2604,67 @@ declare class Client<ContentTypes = ExtractCodecContentTypes> {
|
|
|
2462
2604
|
/**
|
|
2463
2605
|
* Send a sync request to other devices on the network
|
|
2464
2606
|
*
|
|
2465
|
-
* @param options - Archive options specifying what to sync
|
|
2466
|
-
* @param serverUrl - The server URL for the sync request
|
|
2607
|
+
* @param options - Archive options specifying what to sync (defaults to consent and messages)
|
|
2608
|
+
* @param serverUrl - The server URL for the sync request (defaults to environment-specific URL)
|
|
2467
2609
|
* @returns Promise that resolves when the sync request is sent
|
|
2468
2610
|
*/
|
|
2469
|
-
sendSyncRequest(options
|
|
2611
|
+
sendSyncRequest(options?: ArchiveOptions, serverUrl?: string): Promise<void>;
|
|
2612
|
+
/**
|
|
2613
|
+
* Send a sync archive to the sync group
|
|
2614
|
+
*
|
|
2615
|
+
* @param pin - The pin used for reference when importing
|
|
2616
|
+
* @param options - Archive options specifying what to sync (defaults to consent and messages)
|
|
2617
|
+
* @param serverUrl - The server URL for the sync archive (defaults to environment-specific URL)
|
|
2618
|
+
* @returns Promise that resolves when the sync archive is sent
|
|
2619
|
+
*/
|
|
2620
|
+
sendSyncArchive(pin: string, options?: ArchiveOptions, serverUrl?: string): Promise<void>;
|
|
2621
|
+
/**
|
|
2622
|
+
* Process a sync archive that matches the pin given
|
|
2623
|
+
*
|
|
2624
|
+
* @param archivePin - Optional pin to match. If not provided, processes the last archive sent
|
|
2625
|
+
* @returns Promise that resolves when the archive is processed
|
|
2626
|
+
*/
|
|
2627
|
+
processSyncArchive(archivePin?: string | null): Promise<void>;
|
|
2628
|
+
/**
|
|
2629
|
+
* List the archives available for import in the sync group
|
|
2630
|
+
*
|
|
2631
|
+
* You may need to manually sync the sync group before calling
|
|
2632
|
+
* this function to see recently uploaded archives.
|
|
2633
|
+
*
|
|
2634
|
+
* @param daysCutoff - Number of days to look back for archives
|
|
2635
|
+
* @returns Promise that resolves with array of available archive information
|
|
2636
|
+
*/
|
|
2637
|
+
listAvailableArchives(daysCutoff: number): Promise<AvailableArchiveInfo[]>;
|
|
2638
|
+
/**
|
|
2639
|
+
* Export archive data to bytes for later restoration
|
|
2640
|
+
*
|
|
2641
|
+
* @param key - Encryption key for the archive
|
|
2642
|
+
* @param opts - Archive options specifying what to include (defaults to consent and messages)
|
|
2643
|
+
* @returns Promise that resolves with the archive data as bytes
|
|
2644
|
+
*/
|
|
2645
|
+
createArchive(key: Uint8Array, opts?: ArchiveOptions): Promise<Uint8Array>;
|
|
2646
|
+
/**
|
|
2647
|
+
* Import an archive from bytes
|
|
2648
|
+
*
|
|
2649
|
+
* @param data - The archive data as bytes
|
|
2650
|
+
* @param key - Encryption key for the archive
|
|
2651
|
+
* @returns Promise that resolves when the archive is imported
|
|
2652
|
+
*/
|
|
2653
|
+
importArchive(data: Uint8Array, key: Uint8Array): Promise<void>;
|
|
2654
|
+
/**
|
|
2655
|
+
* Load the metadata for an archive to see what it contains
|
|
2656
|
+
*
|
|
2657
|
+
* @param data - The archive data as bytes
|
|
2658
|
+
* @param key - Encryption key for the archive
|
|
2659
|
+
* @returns Promise that resolves with the archive metadata
|
|
2660
|
+
*/
|
|
2661
|
+
archiveMetadata(data: Uint8Array, key: Uint8Array): Promise<ArchiveMetadata>;
|
|
2662
|
+
/**
|
|
2663
|
+
* Manually sync all device sync groups
|
|
2664
|
+
*
|
|
2665
|
+
* @returns Promise that resolves with a summary of the sync operation
|
|
2666
|
+
*/
|
|
2667
|
+
syncAllDeviceSyncGroups(): Promise<GroupSyncSummary>;
|
|
2470
2668
|
}
|
|
2471
2669
|
|
|
2472
2670
|
declare class Opfs {
|
|
@@ -2619,5 +2817,5 @@ declare const isIntent: (m: DecodedMessage) => m is DecodedMessage<Intent>;
|
|
|
2619
2817
|
declare const isActions: (m: DecodedMessage) => m is DecodedMessage<Actions>;
|
|
2620
2818
|
declare const isMarkdown: (m: DecodedMessage) => m is DecodedMessage<string>;
|
|
2621
2819
|
|
|
2622
|
-
export { AccountAlreadyAssociatedError, ApiUrls, Client, ClientNotInitializedError, Conversation, Conversations, DEFAULT_RETRY_ATTEMPTS, DEFAULT_RETRY_DELAY, DecodedMessage, Dm, Group, GroupNotFoundError, HistorySyncUrls, InboxReassignError, Opfs, OpfsInitializationError, OpfsNotInitializedError, SignerUnavailableError, StreamFailedError, StreamInvalidRetryAttemptsError, StreamNotFoundError, contentTypeActions, contentTypeAttachment, contentTypeGroupUpdated, contentTypeIntent, contentTypeLeaveRequest, contentTypeMarkdown, contentTypeMultiRemoteAttachment, contentTypeReaction, contentTypeReadReceipt, contentTypeRemoteAttachment, contentTypeReply, contentTypeText, contentTypeTransactionReference, contentTypeWalletSendCalls, createBackend, createStream, decryptAttachment, encodeActions, encodeAttachment, encodeIntent, encodeMarkdown, encodeMultiRemoteAttachment, encodeReaction, encodeReadReceipt, encodeRemoteAttachment, encodeText, encodeTransactionReference, encodeWalletSendCalls, encryptAttachment, generateInboxId, getInboxIdForIdentifier, isActions, isAttachment, isGroupUpdated, isIntent, isLeaveRequest, isMarkdown, isMultiRemoteAttachment, isReaction, isReadReceipt, isRemoteAttachment, isReply, isText, isTextReply, isTransactionReference, isWalletSendCalls, metadataFieldName, toSafeConversation, toSafeSigner };
|
|
2623
|
-
export type { AsyncStreamProxy, BuiltInContentTypes, ClientOptions, ContentOptions, DeviceSyncOptions, EOASigner, EnrichedReply, ExtractCodecContentTypes, HmacKeys, LastReadTimes, NetworkOptions, OtherOptions, SCWSigner, SafeConversation, SafeSigner, Signer, StorageOptions, StreamCallback, StreamFunction, StreamOptions, StreamValueMutator, XmtpEnv };
|
|
2820
|
+
export { AccountAlreadyAssociatedError, ApiUrls, Client, ClientNotInitializedError, Conversation, Conversations, DEFAULT_RETRY_ATTEMPTS, DEFAULT_RETRY_DELAY, DecodedMessage, Dm, Group, GroupNotFoundError, HistorySyncUrls, InboxReassignError, Opfs, OpfsInitializationError, OpfsNotInitializedError, SignerUnavailableError, StreamFailedError, StreamInvalidRetryAttemptsError, StreamNotFoundError, contentTypeActions, contentTypeAttachment, contentTypeGroupUpdated, contentTypeIntent, contentTypeLeaveRequest, contentTypeMarkdown, contentTypeMultiRemoteAttachment, contentTypeReaction, contentTypeReadReceipt, contentTypeRemoteAttachment, contentTypeReply, contentTypeText, contentTypeTransactionReference, contentTypeWalletSendCalls, createBackend, createEOASigner, createSCWSigner, createStream, decryptAttachment, encodeActions, encodeAttachment, encodeIntent, encodeMarkdown, encodeMultiRemoteAttachment, encodeReaction, encodeReadReceipt, encodeRemoteAttachment, encodeText, encodeTransactionReference, encodeWalletSendCalls, encryptAttachment, generateInboxId, getInboxIdForIdentifier, isActions, isAttachment, isGroupUpdated, isIntent, isLeaveRequest, isMarkdown, isMultiRemoteAttachment, isReaction, isReadReceipt, isRemoteAttachment, isReply, isText, isTextReply, isTransactionReference, isWalletSendCalls, metadataFieldName, toSafeConversation, toSafeSigner };
|
|
2821
|
+
export type { AsyncStreamProxy, BuiltInContentTypes, ClientOptions, ContentOptions, DeviceSyncOptions, EOASigner, EnrichedReply, ExtractCodecContentTypes, HmacKeys, LastReadTimes, NetworkOptions, OtherOptions, SCWSigner, SafeConversation, SafeSigner, Signer, StorageOptions, StreamCallback, StreamFunction, StreamOptions, StreamValueMutator, VisibilityConfirmationOptions, XmtpEnv };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e,{encodeActions as t,encodeAttachment as n,encodeIntent as s,encodeMarkdown as i,encodeMultiRemoteAttachment as r,encodeReaction as a,encodeReadReceipt as o,encodeRemoteAttachment as c,encodeText as d,encodeTransactionReference as u,encodeWalletSendCalls as h,contentTypeActions as p,contentTypeAttachment as l,contentTypeGroupUpdated as y,contentTypeIntent as g,contentTypeLeaveRequest as w,contentTypeMarkdown as m,contentTypeMultiRemoteAttachment as k,contentTypeReaction as I,contentTypeReadReceipt as v,contentTypeRemoteAttachment as f,contentTypeReply as x,contentTypeText as R,contentTypeTransactionReference as b,contentTypeWalletSendCalls as S,encryptAttachment as A,decryptAttachment as T,ConversationType as M,XmtpEnv as D,BackendBuilder as C,generateInboxId as q,getInboxIdForIdentifier as B,inboxStateFromInboxIds as E,applySignatureRequest as N,revokeInstallationsSignatureRequest as O,LogLevel as P,Backend as F,metadataFieldName as L}from"@xmtp/wasm-bindings";export{ActionStyle,BackupElementSelectionOption,ConsentEntityType,ConsentState,ContentType,ConversationType,DeliveryStatus,GroupMembershipState,GroupMessageKind,GroupPermissionsOptions,IdentifierKind,ListConversationsOrderBy,LogLevel,MessageSortBy,MetadataField,PermissionLevel,PermissionPolicy,PermissionUpdateType,ReactionAction,ReactionSchema,SortDirection}from"@xmtp/wasm-bindings";import{contentTypeToString as U}from"@xmtp/content-type-primitives";class G{#e;constructor(e){this.#e=new Map(e.map(e=>[U(e.contentType),e]))}getCodec(e){return this.#e.get(U(e))}}const W=t=>async(...n)=>(await e(),t(...n)),V=W(t),K=W(n),_=W(s),$=W(i),j=W(r),H=W(a),z=W(o),X=W(c),J=W(d),Q=W(u),Y=W(h),Z=W(p),ee=W(l),te=W(y),ne=W(g),se=W(w),ie=W(m),re=W(k),ae=W(I),oe=W(v),ce=W(f),de=W(x),ue=W(R),he=W(b),pe=W(S),le=W(A),ye=W(T);function ge(e){return new Date(Number(e/1000000n))}const we=e=>{switch(e.type){case"text":case"markdown":case"reply":case"reaction":case"attachment":case"remoteAttachment":case"multiRemoteAttachment":case"transactionReference":case"groupUpdated":case"readReceipt":case"leaveRequest":case"walletSendCalls":case"intent":case"actions":case"deletedMessage":case"custom":return e.content;default:return null}};class me{content;contentType;conversationId;deliveryStatus;expiresAtNs;expiresAt;fallback;id;kind;numReplies;reactions;senderInboxId;sentAt;sentAtNs;constructor(e,t){switch(this.id=t.id,this.expiresAtNs=t.expiresAtNs,this.expiresAt=t.expiresAtNs?ge(t.expiresAtNs):void 0,this.sentAtNs=t.sentAtNs,this.sentAt=ge(t.sentAtNs),this.conversationId=t.conversationId,this.senderInboxId=t.senderInboxId,this.contentType=t.contentType,this.fallback=t.fallback??void 0,this.kind=t.kind,this.deliveryStatus=t.deliveryStatus,this.numReplies=t.numReplies,this.reactions=t.reactions.map(t=>new me(e,t)),this.content=we(t.content)??void 0,t.content.type){case"reply":{const n=t.content.content;let s=we(n.content);if("custom"===n.content.type){const t=e.getCodec(n.content.content.type);if(t)try{s=t.decode(s)}catch(e){e instanceof Error?console.warn(`Error decoding custom content: ${e.message}`):console.warn("Error decoding custom content")}}this.content={referenceId:n.referenceId,content:s,contentType:()=>(async e=>{switch(e.type){case"text":return ue();case"markdown":return ie();case"reply":return de();case"reaction":return ae();case"attachment":return ee();case"remoteAttachment":return ce();case"multiRemoteAttachment":return re();case"transactionReference":return he();case"groupUpdated":return te();case"readReceipt":return oe();case"leaveRequest":return se();case"walletSendCalls":return pe();case"intent":return ne();case"actions":return Z();case"deletedMessage":default:return;case"custom":return e.content.type}})(n.content),inReplyTo:n.inReplyTo?new me(e,n.inReplyTo):null};break}case"custom":{const n=t.content.content,s=e.getCodec(this.contentType);if(s)try{this.content=s.decode(n)}catch(e){e instanceof Error?console.warn(`Error decoding custom content: ${e.message}`):console.warn("Error decoding custom content"),this.content=void 0}else console.warn(`No codec found for content type "${U(this.contentType)}"`),this.content=void 0;break}}}}class ke{isDone=!1;#t=[];#n;onDone;onReturn;constructor(){this.#n=[],this.isDone=!1}flush(){for(;this.#t.length>0;){const e=this.#t.shift();e&&e({done:!0,value:void 0})}}done(){this.flush(),this.#n=[],this.#t=[],this.isDone=!0,this.onDone?.()}push=e=>{if(this.isDone)return;const t=this.#t.shift();t?t({done:!1,value:e}):this.#n.push(e)};next=()=>this.isDone?Promise.resolve({done:!0,value:void 0}):this.#n.length>0?Promise.resolve({done:!1,value:this.#n.shift()}):new Promise(e=>{this.#t.push(e)});return=()=>(this.onReturn?.(),this.done(),Promise.resolve({done:!0,value:void 0}));end=()=>this.return();[Symbol.asyncIterator](){return this}}const Ie=["end","isDone","next","return",Symbol.asyncIterator],ve=e=>Ie.includes(e);class fe extends Error{constructor(){super("Client not initialized, use Client.create or Client.build to create a client")}}class xe extends Error{constructor(){super("Signer unavailable, use Client.create to create a client with a signer")}}class Re extends Error{constructor(){super("Unable to create add account signature text, `allowInboxReassign` must be true")}}class be extends Error{constructor(e){super(`Account already associated with inbox ${e}`)}}class Se extends Error{constructor(e){super(`Group "${e}" not found`)}}class Ae extends Error{constructor(e){super(`Stream "${e}" not found`)}}class Te extends Error{constructor(e){super(`Stream failed, retried ${e} ${"time"+(1!==e?"s":"")}`)}}class Me extends Error{constructor(){super("Stream retry attempts must be greater than 0")}}class De extends Error{constructor(){super("OPFS must be initialized before accessing its methods")}}class Ce extends Error{constructor(){super("Failed to initialize OPFS, ensure that there are no other active XMTP clients or Opfs instances")}}const qe=1e4,Be=6,Ee=async(e,t,n)=>{const{onEnd:s,onError:i,onFail:r,onRestart:a,onRetry:o,onValue:c,retryAttempts:d=Be,retryDelay:u=qe,retryOnFail:h=!0}=n??{};if(h&&d<0)throw new Me;const p=new ke,l=(e,n)=>{if(e)i?.(e);else if(void 0!==n)try{if(t){const e=t(n);(e=>!!e&&("object"==typeof e||"function"==typeof e)&&"then"in e&&"function"==typeof e.then)(e)?e.then(e=>{void 0!==e&&(p.push(e),c?.(e))}).catch(e=>{i?.(e)}):void 0!==e&&(p.push(e),c?.(e))}else p.push(n),c?.(n)}catch(e){i?.(e)}},y=async(t=d)=>{try{if(0===t)throw p.end(),new Te(d);await(n=u,new Promise(e=>setTimeout(e,n))),o?.(d-t+1,d);const i=await e(l,()=>{r?.(),y()});p.onDone=()=>{i(),s?.()},a?.()}catch(e){i?.(e),y(t-1)}var n},g=()=>{if(!h)throw p.end(),new Te(0);y()};try{const t=await e(l,()=>{r?.(),g()});p.onDone=()=>{t(),s?.()}}catch(e){i?.(e),g()}return new Proxy(p,{get(e,t,n){if(ve(t))return Reflect.get(e,t,n)},set:()=>!0,has:(e,t)=>ve(t),ownKeys:()=>Ie,getOwnPropertyDescriptor(e,t){if(ve(t))return{enumerable:!0,configurable:!0,value:Reflect.get(e,t)}}})},Ne=()=>{const e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")};class Oe{#s;#i;#r;#a;#o;#c;constructor(e,t,n,s){this.#c=e,this.#i=t,this.#a=n,this.#d(s)}#d(e){this.#s=e?.addedByInboxId,this.#o=e?.metadata,this.#r=e?.createdAtNs}get id(){return this.#a}get addedByInboxId(){return this.#s}get createdAtNs(){return this.#r}get createdAt(){return this.#r?ge(this.#r):void 0}get metadata(){return this.#o}get topic(){return`/xmtp/mls/1/g-${this.id}/proto`}async lastMessage(){const e=await this.#c.action("conversation.lastMessage",{id:this.#a});return e?new me(this.#i,e):void 0}async isActive(){return this.#c.action("conversation.isActive",{id:this.#a})}async members(){return this.#c.action("conversation.members",{id:this.#a})}async sync(){const e=await this.#c.action("conversation.sync",{id:this.#a});return this.#d(e),e}async publishMessages(){return this.#c.action("conversation.publishMessages",{id:this.#a})}async send(e,t){return this.#c.action("conversation.send",{id:this.#a,content:e,options:t})}async sendText(e,t){return this.#c.action("conversation.sendText",{id:this.#a,text:e,isOptimistic:t})}async sendMarkdown(e,t){return this.#c.action("conversation.sendMarkdown",{id:this.#a,markdown:e,isOptimistic:t})}async sendReaction(e,t){return this.#c.action("conversation.sendReaction",{id:this.#a,reaction:e,isOptimistic:t})}async sendReadReceipt(e){return this.#c.action("conversation.sendReadReceipt",{id:this.#a,isOptimistic:e})}async sendReply(e,t){return this.#c.action("conversation.sendReply",{id:this.#a,reply:e,isOptimistic:t})}async sendTransactionReference(e,t){return this.#c.action("conversation.sendTransactionReference",{id:this.#a,transactionReference:e,isOptimistic:t})}async sendWalletSendCalls(e,t){return this.#c.action("conversation.sendWalletSendCalls",{id:this.#a,walletSendCalls:e,isOptimistic:t})}async sendActions(e,t){return this.#c.action("conversation.sendActions",{id:this.#a,actions:e,isOptimistic:t})}async sendIntent(e,t){return this.#c.action("conversation.sendIntent",{id:this.#a,intent:e,isOptimistic:t})}async sendAttachment(e,t){return this.#c.action("conversation.sendAttachment",{id:this.#a,attachment:e,isOptimistic:t})}async sendMultiRemoteAttachment(e,t){return this.#c.action("conversation.sendMultiRemoteAttachment",{id:this.#a,multiRemoteAttachment:e,isOptimistic:t})}async sendRemoteAttachment(e,t){return this.#c.action("conversation.sendRemoteAttachment",{id:this.#a,remoteAttachment:e,isOptimistic:t})}async messages(e){return(await this.#c.action("conversation.messages",{id:this.#a,options:e})).map(e=>new me(this.#i,e))}async countMessages(e){return await this.#c.action("conversation.countMessages",{id:this.#a,options:e})}async consentState(){return this.#c.action("conversation.consentState",{id:this.#a})}async updateConsentState(e){return this.#c.action("conversation.updateConsentState",{id:this.#a,state:e})}async messageDisappearingSettings(){return this.#c.action("conversation.messageDisappearingSettings",{id:this.#a})}async updateMessageDisappearingSettings(e,t){return this.#c.action("conversation.updateMessageDisappearingSettings",{id:this.#a,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#c.action("conversation.removeMessageDisappearingSettings",{id:this.#a})}async isMessageDisappearingEnabled(){return this.#c.action("conversation.isMessageDisappearingEnabled",{id:this.#a})}async stream(e){return Ee(async(t,n)=>{const s=Ne();return e?.disableSync||await this.sync(),await this.#c.action("conversation.stream",{groupId:this.#a,streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>new me(this.#i,e),e)}async pausedForVersion(){return this.#c.action("conversation.pausedForVersion",{id:this.#a})}async hmacKeys(){return this.#c.action("conversation.hmacKeys",{id:this.#a})}async debugInfo(){return this.#c.action("conversation.debugInfo",{id:this.#a})}async lastReadTimes(){return this.#c.action("conversation.lastReadTimes",{id:this.#a})}}class Pe extends Oe{#i;#c;#a;constructor(e,t,n,s){super(e,t,n,s),this.#c=e,this.#i=t,this.#a=n}async peerInboxId(){return this.#c.action("dm.peerInboxId",{id:this.#a})}async duplicateDms(){return(await this.#c.action("dm.duplicateDms",{id:this.#a})).map(e=>new Pe(this.#c,this.#i,e.id,e))}}class Fe extends Oe{#u=[];#h;#c;#p;#a;#l;#y;#g=[];#d(e){this.#y=e?.name??"",this.#l=e?.imageUrl??"",this.#p=e?.description??"",this.#h=e?.appData??"",this.#u=e?.admins??[],this.#g=e?.superAdmins??[]}constructor(e,t,n,s){super(e,t,n,s),this.#c=e,this.#a=n,this.#d(s)}async sync(){const e=await super.sync();return this.#d(e),e}get name(){return this.#y}async updateName(e){await this.#c.action("group.updateName",{id:this.#a,name:e}),this.#y=e}get imageUrl(){return this.#l}async updateImageUrl(e){await this.#c.action("group.updateImageUrl",{id:this.#a,imageUrl:e}),this.#l=e}get description(){return this.#p}async updateDescription(e){await this.#c.action("group.updateDescription",{id:this.#a,description:e}),this.#p=e}get appData(){return this.#h}async updateAppData(e){await this.#c.action("group.updateAppData",{id:this.#a,appData:e}),this.#h=e}get admins(){return this.#u}get superAdmins(){return this.#g}async listAdmins(){const e=await this.#c.action("group.listAdmins",{id:this.#a});return this.#u=e,e}async listSuperAdmins(){const e=await this.#c.action("group.listSuperAdmins",{id:this.#a});return this.#g=e,e}async permissions(){return this.#c.action("group.permissions",{id:this.#a})}async updatePermission(e,t,n){return this.#c.action("group.updatePermission",{id:this.#a,permissionType:e,policy:t,metadataField:n})}async isAdmin(e){return(await this.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembersByIdentifiers(e){return this.#c.action("group.addMembersByIdentifiers",{id:this.#a,identifiers:e})}async addMembers(e){return this.#c.action("group.addMembers",{id:this.#a,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#c.action("group.removeMembersByIdentifiers",{id:this.#a,identifiers:e})}async removeMembers(e){return this.#c.action("group.removeMembers",{id:this.#a,inboxIds:e})}async addAdmin(e){return this.#c.action("group.addAdmin",{id:this.#a,inboxId:e})}async removeAdmin(e){return this.#c.action("group.removeAdmin",{id:this.#a,inboxId:e})}async addSuperAdmin(e){return this.#c.action("group.addSuperAdmin",{id:this.#a,inboxId:e})}async removeSuperAdmin(e){return this.#c.action("group.removeSuperAdmin",{id:this.#a,inboxId:e})}async requestRemoval(){return this.#c.action("group.requestRemoval",{id:this.#a})}async isPendingRemoval(){return this.#c.action("group.isPendingRemoval",{id:this.#a})}}class Le{#w;#i;#c;constructor(e,t,n){this.#w=e,this.#c=t,this.#i=n}get topic(){return this.#w.installationId?`/xmtp/mls/1/w-${this.#w.installationId}/proto`:void 0}async sync(){return this.#c.action("conversations.sync")}async syncAll(e){return this.#c.action("conversations.syncAll",{consentStates:e})}async getConversationById(e){const t=await this.#c.action("conversations.getConversationById",{id:e});if(t)switch(t.metadata.conversationType){case M.Group:return new Fe(this.#c,this.#i,t.id,t);case M.Dm:return new Pe(this.#c,this.#i,t.id,t);default:return}}async getMessageById(e){const t=await this.#c.action("conversations.getMessageById",{id:e});return t?new me(this.#i,t):void 0}async getDmByInboxId(e){const t=await this.#c.action("conversations.getDmByInboxId",{inboxId:e});return t?new Pe(this.#c,this.#i,t.id,t):void 0}async fetchDmByIdentifier(e){const t=await this.#c.action("client.getInboxIdByIdentifier",{identifier:e});if(t)return this.getDmByInboxId(t)}async list(e){return(await this.#c.action("conversations.list",{options:e})).map(e=>{switch(e.metadata.conversationType){case M.Dm:return new Pe(this.#c,this.#i,e.id,e);case M.Group:return new Fe(this.#c,this.#i,e.id,e);default:return}}).filter(e=>void 0!==e)}async listGroups(e){return(await this.#c.action("conversations.listGroups",{options:e})).map(e=>new Fe(this.#c,this.#i,e.id,e))}async listDms(e){return(await this.#c.action("conversations.listDms",{options:e})).map(e=>new Pe(this.#c,this.#i,e.id,e))}async createGroupOptimistic(e){const t=await this.#c.action("conversations.createGroupOptimistic",{options:e});return new Fe(this.#c,this.#i,t.id,t)}async createGroupWithIdentifiers(e,t){const n=await this.#c.action("conversations.createGroupWithIdentifiers",{identifiers:e,options:t});return new Fe(this.#c,this.#i,n.id,n)}async createGroup(e,t){const n=await this.#c.action("conversations.createGroup",{inboxIds:e,options:t});return new Fe(this.#c,this.#i,n.id,n)}async createDmWithIdentifier(e,t){const n=await this.#c.action("conversations.createDmWithIdentifier",{identifier:e,options:t});return new Pe(this.#c,this.#i,n.id,n)}async createDm(e,t){const n=await this.#c.action("conversations.createDm",{inboxId:e,options:t});return new Pe(this.#c,this.#i,n.id,n)}async hmacKeys(){return this.#c.action("conversations.hmacKeys")}async stream(e){return Ee(async(t,n)=>{const s=Ne();return e?.disableSync||await this.sync(),await this.#c.action("conversations.stream",{streamId:s,conversationType:e?.conversationType}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>{switch(e.metadata.conversationType){case M.Group:return new Fe(this.#c,this.#i,e.id,e);case M.Dm:return new Pe(this.#c,this.#i,e.id,e);default:return void console.warn(`Unknown conversation type: ${e.metadata.conversationType}`)}},e)}async streamGroups(e){return this.stream({...e,conversationType:M.Group})}async streamDms(e){return this.stream({...e,conversationType:M.Dm})}async streamAllMessages(e){return Ee(async(t,n)=>{const s=Ne();return e?.disableSync||await this.sync(),await this.#c.action("conversations.streamAllMessages",{streamId:s,conversationType:e?.conversationType,consentStates:e?.consentStates}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>new me(this.#i,e),e)}async streamAllGroupMessages(e){return this.streamAllMessages({...e,conversationType:M.Group})}async streamAllDmMessages(e){return this.streamAllMessages({...e,conversationType:M.Dm})}async streamMessageDeletions(e){return Ee(async t=>{const n=Ne();return await this.#c.action("conversations.streamDeletedMessages",{streamId:n}),this.#c.handleStreamMessage(n,t,e)},e=>e.id,e)}async streamDeletedMessages(e){return Ee(async t=>{const n=Ne();return await this.#c.action("conversations.streamDeletedMessages",{streamId:n}),this.#c.handleStreamMessage(n,t,e)},e=>new me(this.#i,e),e)}}class Ue{#c;constructor(e){this.#c=e}apiStatistics(){return this.#c.action("debugInformation.apiStatistics")}apiIdentityStatistics(){return this.#c.action("debugInformation.apiIdentityStatistics")}apiAggregateStatistics(){return this.#c.action("debugInformation.apiAggregateStatistics")}clearAllStatistics(){return this.#c.action("debugInformation.clearAllStatistics")}}class Ge{#c;constructor(e){this.#c=e}sync(){return this.#c.action("preferences.sync")}async inboxState(){return this.#c.action("preferences.inboxState",{refreshFromNetwork:!1})}async fetchInboxState(){return this.#c.action("preferences.inboxState",{refreshFromNetwork:!0})}async getInboxStates(e){return this.#c.action("preferences.getInboxStates",{inboxIds:e,refreshFromNetwork:!1})}async fetchInboxStates(e){return this.#c.action("preferences.getInboxStates",{inboxIds:e,refreshFromNetwork:!0})}async setConsentStates(e){return this.#c.action("preferences.setConsentStates",{records:e})}async getConsentState(e,t){return this.#c.action("preferences.getConsentState",{entityType:e,entity:t})}async streamConsent(e){return Ee(async(t,n)=>{const s=Ne();return e?.disableSync||await this.sync(),await this.#c.action("preferences.streamConsent",{streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},void 0,e)}async streamPreferences(e){return Ee(async(t,n)=>{const s=Ne();return e?.disableSync||await this.sync(),await this.#c.action("preferences.streamPreferences",{streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},void 0,e)}}const We={local:D.Local,dev:D.Dev,production:D.Production,"testnet-staging":D.TestnetStaging,"testnet-dev":D.TestnetDev,testnet:D.Testnet,mainnet:D.Mainnet};D.Local,D.Dev,D.Production,D.TestnetStaging,D.TestnetDev,D.Testnet,D.Mainnet;const Ve=async t=>{await e();let n=new C(We[t?.env??"dev"]);return t?.apiUrl&&(n=n.setApiUrl(t.apiUrl)),t?.gatewayHost&&(n=n.setGatewayHost(t.gatewayHost)),t?.appVersion&&(n=n.setAppVersion(t.appVersion)),n.build()},Ke=async(t,n)=>(await e(),q(t,n)),_e=async(t,n)=>(await e(),B(t,n)),$e=async(t,n,s,i)=>{await e();const r=await n.getIdentifier(),{signatureText:a,signatureRequest:o}=await(async(t,n,s,i)=>{await e();const r=O(t,n,s,i);return{signatureText:await r.signatureText(),signatureRequest:r}})(t,r,s,i),c=await n.signMessage(a);switch(n.type){case"EOA":await o.addEcdsaSignature(c);break;case"SCW":await o.addScwSignature(r,c,n.getChainId(),n.getBlockNumber?.())}await N(t,o)},je=async(e,t)=>{switch(e.type){case"EOA":return{type:"EOA",identifier:await e.getIdentifier(),signature:t};case"SCW":return{type:"SCW",identifier:await e.getIdentifier(),signature:t,chainId:e.getChainId(),blockNumber:e.getBlockNumber?.()}}},He=e=>{console.error(`[worker] error: ${e.message}`)};class ze{#c;#m;#k=new Map;constructor(e,t){this.#c=e,this.#c.addEventListener("message",this.handleMessage),this.#c.addEventListener("error",He),this.#m=t??!1}action(e,...t){const n=Ne();this.#c.postMessage({action:e,id:n,data:t[0]});return new Promise((e,t)=>{this.#k.set(n,{resolve:e,reject:t})})}handleMessage=e=>{const t=e.data;this.#m&&console.log("[worker] client received event data",t);const n=this.#k.get(t.id);n&&(this.#k.delete(t.id),"error"in t?n.reject(t.error):n.resolve(t.result))};handleStreamMessage=(e,t,n)=>{const s=s=>{const i=s.data;if(i.streamId===e){if("stream.fail"===i.action)return void n?.onFail?.();"error"in i?t(i.error,void 0):t(null,i.result)}};return this.#c.addEventListener("message",s),async()=>{await this.action("endStream",{streamId:e}),this.#c.removeEventListener("message",s)}};close(){this.#c.removeEventListener("message",this.handleMessage),this.#c.removeEventListener("error",He),this.#c.terminate()}}const Xe=async(e,t)=>e instanceof F?e:Ve({env:e,gatewayHost:t});class Je{#I;#i;#v;#f;#x;#R;#b;#S;#A;#T=!1;#M;#D;#C;#q;#c;constructor(e){e&&Object.defineProperty(e,"codecs",{value:e.codecs,enumerable:!1});const t=new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),n=void 0!==e?.loggingLevel&&e.loggingLevel!==P.Off;this.#c=new ze(t,n),this.#i=new G([...e?.codecs??[]]),this.#D=e,this.#v=new Le(this,this.#c,this.#i),this.#f=new Ue(this.#c),this.#C=new Ge(this.#c)}async init(e){const t=await this.#c.action("client.init",{identifier:e,options:this.#D});this.#I=t.appVersion,this.#x=t.env,this.#R=e,this.#b=t.inboxId,this.#S=t.installationId,this.#A=t.installationIdBytes,this.#M=t.libxmtpVersion,this.#T=!0}close(){this.#c.close(),this.#T=!1}static async create(e,t){const n=new Je(t);return n.#q=e,await n.init(await e.getIdentifier()),t?.disableAutoRegister||await n.register(),n}static async build(e,t){const n=new Je({...t,disableAutoRegister:!0});return await n.init(e),n}get options(){return this.#D}get signer(){return this.#q}get isReady(){return this.#T}get inboxId(){return this.#b}get accountIdentifier(){return this.#R}get installationId(){return this.#S}get installationIdBytes(){return this.#A}get conversations(){return this.#v}get debugInformation(){return this.#f}get preferences(){return this.#C}get libxmtpVersion(){return this.#M}get appVersion(){return this.#I}get env(){return this.#x}async unsafe_createInboxSignatureText(){return this.#c.action("client.createInboxSignatureText",{signatureRequestId:Ne()})}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Re;return this.#c.action("client.addAccountSignatureText",{newIdentifier:e,signatureRequestId:Ne()})}async unsafe_removeAccountSignatureText(e){return this.#c.action("client.removeAccountSignatureText",{identifier:e,signatureRequestId:Ne()})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.#c.action("client.revokeAllOtherInstallationsSignatureText",{signatureRequestId:Ne()})}async unsafe_revokeInstallationsSignatureText(e){return this.#c.action("client.revokeInstallationsSignatureText",{installationIds:e,signatureRequestId:Ne()})}async unsafe_changeRecoveryIdentifierSignatureText(e){return this.#c.action("client.changeRecoveryIdentifierSignatureText",{identifier:e,signatureRequestId:Ne()})}async unsafe_applySignatureRequest(e,t){return this.#c.action("client.applySignatureRequest",{signer:e,signatureRequestId:t})}async register(){if(!this.#q)throw new xe;const{signatureText:e,signatureRequestId:t}=await this.unsafe_createInboxSignatureText();if(!e||!t)return;const n=await this.#q.signMessage(e),s=await je(this.#q,n);return this.#c.action("client.registerIdentity",{signer:s,signatureRequestId:t})}async unsafe_addAccount(e,t=!1){if(!this.#q)throw new xe;if(!t)throw new Re;const n=await this.fetchInboxIdByIdentifier(await e.getIdentifier());if(n)throw new be(n);const{signatureText:s,signatureRequestId:i}=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0),r=await e.signMessage(s),a=await je(e,r);return this.#c.action("client.addAccount",{identifier:a.identifier,signer:a,signatureRequestId:i})}async removeAccount(e){if(!this.#q)throw new xe;const{signatureText:t,signatureRequestId:n}=await this.unsafe_removeAccountSignatureText(e),s=await this.#q.signMessage(t),i=await je(this.#q,s);return this.#c.action("client.removeAccount",{identifier:e,signer:i,signatureRequestId:n})}async revokeAllOtherInstallations(){if(!this.#q)throw new xe;const{signatureText:e,signatureRequestId:t}=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)return;const n=await this.#q.signMessage(e),s=await je(this.#q,n);return this.#c.action("client.revokeAllOtherInstallations",{signer:s,signatureRequestId:t})}async revokeInstallations(e){if(!this.#q)throw new xe;const{signatureText:t,signatureRequestId:n}=await this.unsafe_revokeInstallationsSignatureText(e),s=await this.#q.signMessage(t),i=await je(this.#q,s);return this.#c.action("client.revokeInstallations",{installationIds:e,signer:i,signatureRequestId:n})}static async revokeInstallations(e,t,n,s,i){const r=await Xe(s,i);await $e(r,e,t,n)}static async fetchInboxStates(t,n,s){return(async(t,n)=>(await e(),E(t,n)))(await Xe(n,s),t)}async changeRecoveryIdentifier(e){if(!this.#q)throw new xe;const{signatureText:t,signatureRequestId:n}=await this.unsafe_changeRecoveryIdentifierSignatureText(e),s=await this.#q.signMessage(t),i=await je(this.#q,s);return this.#c.action("client.changeRecoveryIdentifier",{identifier:e,signer:i,signatureRequestId:n})}async isRegistered(){return this.#c.action("client.isRegistered")}async canMessage(e){return this.#c.action("client.canMessage",{identifiers:e})}static async canMessage(e,t){const n=await Xe(t),s=new Map;for(const t of e){const e=await _e(n,t);s.set(t.identifier.toLowerCase(),void 0!==e)}return s}async fetchInboxIdByIdentifier(e){return this.#c.action("client.getInboxIdByIdentifier",{identifier:e})}signWithInstallationKey(e){return this.#c.action("client.signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.#c.action("client.verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,n){return this.#c.action("client.verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:n})}async fetchKeyPackageStatuses(e){return this.#c.action("client.fetchKeyPackageStatuses",{installationIds:e})}async sendSyncRequest(e,t){return this.#c.action("client.sendSyncRequest",{options:e,serverUrl:t})}}class Qe{#c;#m;constructor(e){const t=new Worker(new URL("./workers/opfs",import.meta.url),{type:"module"});this.#c=new ze(t,e),this.#m=e??!1}async init(){await this.#c.action("opfs.init",{enableLogging:this.#m})}close(){this.#c.close()}static async create(e){const t=new Qe(e);return await t.init(),t}async listFiles(){return this.#c.action("opfs.listFiles")}async fileCount(){return this.#c.action("opfs.fileCount")}async poolCapacity(){return this.#c.action("opfs.poolCapacity")}async fileExists(e){return this.#c.action("opfs.fileExists",{path:e})}async deleteFile(e){return this.#c.action("opfs.deleteFile",{path:e})}async exportDb(e){return this.#c.action("opfs.exportDb",{path:e})}async importDb(e,t){return this.#c.action("opfs.importDb",{path:e,data:t})}async clearAll(){return this.#c.action("opfs.clearAll")}}const Ye=async t=>(await e(),L(t)),Ze={local:"http://localhost:5557",dev:"https://api.dev.xmtp.network:5558",production:"https://api.production.xmtp.network:5558"},et={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network","testnet-staging":"https://message-history.dev.ephemera.network","testnet-dev":"https://message-history.dev.ephemera.network",testnet:"https://message-history.dev.ephemera.network",mainnet:"https://message-history.production.ephemera.network"},tt=async e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,appData:e.appData,permissions:e.permissions(),addedByInboxId:e.addedByInboxId,metadata:await e.metadata(),admins:e.listAdmins(),superAdmins:e.listSuperAdmins(),createdAtNs:e.createdAtNs}),nt=e=>"xmtp.org"===e.contentType.authorityId&&"reaction"===e.contentType.typeId,st=e=>"xmtp.org"===e.contentType.authorityId&&"reply"===e.contentType.typeId,it=e=>st(e)&&"string"==typeof e.content?.content,rt=e=>"xmtp.org"===e.contentType.authorityId&&"text"===e.contentType.typeId,at=e=>"xmtp.org"===e.contentType.authorityId&&"remoteStaticAttachment"===e.contentType.typeId,ot=e=>"xmtp.org"===e.contentType.authorityId&&"attachment"===e.contentType.typeId,ct=e=>"xmtp.org"===e.contentType.authorityId&&"multiRemoteStaticAttachment"===e.contentType.typeId,dt=e=>"xmtp.org"===e.contentType.authorityId&&"transactionReference"===e.contentType.typeId,ut=e=>"xmtp.org"===e.contentType.authorityId&&"group_updated"===e.contentType.typeId,ht=e=>"xmtp.org"===e.contentType.authorityId&&"readReceipt"===e.contentType.typeId,pt=e=>"xmtp.org"===e.contentType.authorityId&&"leave_request"===e.contentType.typeId,lt=e=>"xmtp.org"===e.contentType.authorityId&&"walletSendCalls"===e.contentType.typeId,yt=e=>"coinbase.com"===e.contentType.authorityId&&"intent"===e.contentType.typeId,gt=e=>"coinbase.com"===e.contentType.authorityId&&"actions"===e.contentType.typeId,wt=e=>"xmtp.org"===e.contentType.authorityId&&"markdown"===e.contentType.typeId;export{be as AccountAlreadyAssociatedError,Ze as ApiUrls,Je as Client,fe as ClientNotInitializedError,Oe as Conversation,Le as Conversations,me as DecodedMessage,Pe as Dm,Fe as Group,Se as GroupNotFoundError,et as HistorySyncUrls,Re as InboxReassignError,Qe as Opfs,Ce as OpfsInitializationError,De as OpfsNotInitializedError,xe as SignerUnavailableError,Te as StreamFailedError,Me as StreamInvalidRetryAttemptsError,Ae as StreamNotFoundError,Z as contentTypeActions,ee as contentTypeAttachment,te as contentTypeGroupUpdated,ne as contentTypeIntent,se as contentTypeLeaveRequest,ie as contentTypeMarkdown,re as contentTypeMultiRemoteAttachment,ae as contentTypeReaction,oe as contentTypeReadReceipt,ce as contentTypeRemoteAttachment,de as contentTypeReply,ue as contentTypeText,he as contentTypeTransactionReference,pe as contentTypeWalletSendCalls,Ve as createBackend,ye as decryptAttachment,V as encodeActions,K as encodeAttachment,_ as encodeIntent,$ as encodeMarkdown,j as encodeMultiRemoteAttachment,H as encodeReaction,z as encodeReadReceipt,X as encodeRemoteAttachment,J as encodeText,Q as encodeTransactionReference,Y as encodeWalletSendCalls,le as encryptAttachment,Ke as generateInboxId,_e as getInboxIdForIdentifier,gt as isActions,ot as isAttachment,ut as isGroupUpdated,yt as isIntent,pt as isLeaveRequest,wt as isMarkdown,ct as isMultiRemoteAttachment,nt as isReaction,ht as isReadReceipt,at as isRemoteAttachment,st as isReply,rt as isText,it as isTextReply,dt as isTransactionReference,lt as isWalletSendCalls,Ye as metadataFieldName,tt as toSafeConversation,je as toSafeSigner};
|
|
1
|
+
import e,{encodeActions as t,encodeAttachment as n,encodeIntent as s,encodeMarkdown as i,encodeMultiRemoteAttachment as r,encodeReaction as a,encodeReadReceipt as o,encodeRemoteAttachment as c,encodeText as d,encodeTransactionReference as u,encodeWalletSendCalls as h,contentTypeActions as p,contentTypeAttachment as l,contentTypeGroupUpdated as y,contentTypeIntent as g,contentTypeLeaveRequest as w,contentTypeMarkdown as m,contentTypeMultiRemoteAttachment as v,contentTypeReaction as k,contentTypeReadReceipt as f,contentTypeRemoteAttachment as I,contentTypeReply as b,contentTypeText as x,contentTypeTransactionReference as R,contentTypeWalletSendCalls as A,encryptAttachment as S,decryptAttachment as T,ConversationType as D,XmtpEnv as M,BackendBuilder as C,getInboxIdForIdentifier as E,generateInboxId as O,DeviceSyncMode as q,createClientWithBackend as B,inboxStateFromInboxIds as L,applySignatureRequest as U,revokeInstallationsSignatureRequest as P,IdentifierKind as N,LogLevel as F,BackupElementSelectionOption as G,Backend as K,metadataFieldName as V}from"@xmtp/wasm-bindings";export{ActionStyle,BackupElementSelectionOption,ConsentEntityType,ConsentState,ContentType,ConversationType,DeliveryStatus,GroupMembershipState,GroupMessageKind,GroupPermissionsOptions,IdentifierKind,ListConversationsOrderBy,LogLevel,MessageSortBy,MetadataField,PermissionLevel,PermissionPolicy,PermissionUpdateType,ReactionAction,ReactionSchema,SortDirection,WorkerKind}from"@xmtp/wasm-bindings";import{contentTypeToString as W}from"@xmtp/content-type-primitives";import{toBytes as $}from"viem";import{privateKeyToAccount as _,generatePrivateKey as j}from"viem/accounts";class H{#e;constructor(e){this.#e=new Map(e.map(e=>[W(e.contentType),e]))}getCodec(e){return this.#e.get(W(e))}}const z={local:"http://localhost:5557",dev:"https://api.dev.xmtp.network:5558",production:"https://api.production.xmtp.network:5558"},X={local:"http://localhost:5558",dev:"https://message-history.dev.ephemera.network",production:"https://message-history.production.ephemera.network","testnet-staging":"https://message-history.dev.ephemera.network","testnet-dev":"https://message-history.dev.ephemera.network",testnet:"https://message-history.dev.ephemera.network",mainnet:"https://message-history.production.ephemera.network"},J=t=>async(...n)=>(await e(),t(...n)),Q=J(t),Y=J(n),Z=J(s),ee=J(i),te=J(r),ne=J(a),se=J(o),ie=J(c),re=J(d),ae=J(u),oe=J(h),ce=J(p),de=J(l),ue=J(y),he=J(g),pe=J(w),le=J(m),ye=J(v),ge=J(k),we=J(f),me=J(I),ve=J(b),ke=J(x),fe=J(R),Ie=J(A),be=J(S),xe=J(T);function Re(e){return new Date(Number(e/1000000n))}const Ae=e=>{switch(e.type){case"text":case"markdown":case"reply":case"reaction":case"attachment":case"remoteAttachment":case"multiRemoteAttachment":case"transactionReference":case"groupUpdated":case"readReceipt":case"leaveRequest":case"walletSendCalls":case"intent":case"actions":case"deletedMessage":case"custom":return e.content;default:return null}};class Se{content;contentType;conversationId;deliveryStatus;expiresAtNs;expiresAt;fallback;id;kind;numReplies;reactions;senderInboxId;sentAt;sentAtNs;constructor(e,t){switch(this.id=t.id,this.expiresAtNs=t.expiresAtNs,this.expiresAt=t.expiresAtNs?Re(t.expiresAtNs):void 0,this.sentAtNs=t.sentAtNs,this.sentAt=Re(t.sentAtNs),this.conversationId=t.conversationId,this.senderInboxId=t.senderInboxId,this.contentType=t.contentType,this.fallback=t.fallback??void 0,this.kind=t.kind,this.deliveryStatus=t.deliveryStatus,this.numReplies=t.numReplies,this.reactions=t.reactions.map(t=>new Se(e,t)),this.content=Ae(t.content)??void 0,t.content.type){case"reply":{const n=t.content.content;let s=Ae(n.content);if("custom"===n.content.type){const t=e.getCodec(n.content.content.type);if(t)try{s=t.decode(s)}catch(e){e instanceof Error?console.warn(`Error decoding custom content: ${e.message}`):console.warn("Error decoding custom content")}}this.content={referenceId:n.referenceId,content:s,contentType:()=>(async e=>{switch(e.type){case"text":return ke();case"markdown":return le();case"reply":return ve();case"reaction":return ge();case"attachment":return de();case"remoteAttachment":return me();case"multiRemoteAttachment":return ye();case"transactionReference":return fe();case"groupUpdated":return ue();case"readReceipt":return we();case"leaveRequest":return pe();case"walletSendCalls":return Ie();case"intent":return he();case"actions":return ce();case"deletedMessage":default:return;case"custom":return e.content.type}})(n.content),inReplyTo:n.inReplyTo?new Se(e,n.inReplyTo):null};break}case"custom":{const n=t.content.content,s=e.getCodec(this.contentType);if(s)try{this.content=s.decode(n)}catch(e){e instanceof Error?console.warn(`Error decoding custom content: ${e.message}`):console.warn("Error decoding custom content"),this.content=void 0}else console.warn(`No codec found for content type "${W(this.contentType)}"`),this.content=void 0;break}}}}class Te{isDone=!1;#t=[];#n;onDone;onReturn;constructor(){this.#n=[],this.isDone=!1}flush(){for(;this.#t.length>0;){const e=this.#t.shift();e&&e({done:!0,value:void 0})}}done(){this.flush(),this.#n=[],this.#t=[],this.isDone=!0,this.onDone?.()}push=e=>{if(this.isDone)return;const t=this.#t.shift();t?t({done:!1,value:e}):this.#n.push(e)};next=()=>this.isDone?Promise.resolve({done:!0,value:void 0}):this.#n.length>0?Promise.resolve({done:!1,value:this.#n.shift()}):new Promise(e=>{this.#t.push(e)});return=()=>(this.onReturn?.(),this.done(),Promise.resolve({done:!0,value:void 0}));end=()=>this.return();[Symbol.asyncIterator](){return this}}const De=["end","isDone","next","return",Symbol.asyncIterator],Me=e=>De.includes(e);class Ce extends Error{constructor(){super("Client not initialized, use Client.create or Client.build to create a client")}}class Ee extends Error{constructor(){super("Signer unavailable, use Client.create to create a client with a signer")}}class Oe extends Error{constructor(){super("Unable to create add account signature text, `allowInboxReassign` must be true")}}class qe extends Error{constructor(e){super(`Account already associated with inbox ${e}`)}}class Be extends Error{constructor(e){super(`Group "${e}" not found`)}}class Le extends Error{constructor(e){super(`Stream "${e}" not found`)}}class Ue extends Error{constructor(e){super(`Stream failed, retried ${e} ${"time"+(1!==e?"s":"")}`)}}class Pe extends Error{constructor(){super("Stream retry attempts must be greater than 0")}}class Ne extends Error{constructor(){super("OPFS must be initialized before accessing its methods")}}class Fe extends Error{constructor(){super("Failed to initialize OPFS, ensure that there are no other active XMTP clients or Opfs instances")}}const Ge=1e4,Ke=6,Ve=async(e,t,n)=>{const{onEnd:s,onError:i,onFail:r,onRestart:a,onRetry:o,onValue:c,retryAttempts:d=Ke,retryDelay:u=Ge,retryOnFail:h=!0}=n??{};if(h&&d<0)throw new Pe;const p=new Te,l=(e,n)=>{if(e)i?.(e);else if(void 0!==n)try{if(t){const e=t(n);(e=>!!e&&("object"==typeof e||"function"==typeof e)&&"then"in e&&"function"==typeof e.then)(e)?e.then(e=>{void 0!==e&&(p.push(e),c?.(e))}).catch(e=>{i?.(e)}):void 0!==e&&(p.push(e),c?.(e))}else p.push(n),c?.(n)}catch(e){i?.(e)}},y=async(t=d)=>{try{if(0===t)throw p.end(),new Ue(d);await(n=u,new Promise(e=>setTimeout(e,n))),o?.(d-t+1,d);const i=await e(l,()=>{r?.(),y()});p.onDone=()=>{i(),s?.()},a?.()}catch(e){i?.(e),y(t-1)}var n},g=()=>{if(!h)throw p.end(),new Ue(0);y()};try{const t=await e(l,()=>{r?.(),g()});p.onDone=()=>{t(),s?.()}}catch(e){i?.(e),g()}return new Proxy(p,{get(e,t,n){if(Me(t))return Reflect.get(e,t,n)},set:()=>!0,has:(e,t)=>Me(t),ownKeys:()=>De,getOwnPropertyDescriptor(e,t){if(Me(t))return{enumerable:!0,configurable:!0,value:Reflect.get(e,t)}}})},We=()=>{const e=new Uint8Array(16);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")};class $e{#s;#i;#r;#a;#o;#c;constructor(e,t,n,s){this.#c=e,this.#i=t,this.#a=n,this.#d(s)}#d(e){this.#s=e?.addedByInboxId,this.#o=e?.metadata,this.#r=e?.createdAtNs}get id(){return this.#a}get addedByInboxId(){return this.#s}get createdAtNs(){return this.#r}get createdAt(){return this.#r?Re(this.#r):void 0}get metadata(){return this.#o}get topic(){return`/xmtp/mls/1/g-${this.id}/proto`}async lastMessage(){const e=await this.#c.action("conversation.lastMessage",{id:this.#a});return e?new Se(this.#i,e):void 0}async isActive(){return this.#c.action("conversation.isActive",{id:this.#a})}async members(){return this.#c.action("conversation.members",{id:this.#a})}async sync(){const e=await this.#c.action("conversation.sync",{id:this.#a});return this.#d(e),e}async publishMessages(){return this.#c.action("conversation.publishMessages",{id:this.#a})}async processStreamedMessage(e){return this.#c.action("conversation.processStreamedMessage",{id:this.#a,envelopeBytes:e})}async send(e,t){return this.#c.action("conversation.send",{id:this.#a,content:e,options:t})}async sendText(e,t){return this.#c.action("conversation.sendText",{id:this.#a,text:e,isOptimistic:t})}async sendMarkdown(e,t){return this.#c.action("conversation.sendMarkdown",{id:this.#a,markdown:e,isOptimistic:t})}async sendReaction(e,t){return this.#c.action("conversation.sendReaction",{id:this.#a,reaction:e,isOptimistic:t})}async sendReadReceipt(e){return this.#c.action("conversation.sendReadReceipt",{id:this.#a,isOptimistic:e})}async sendReply(e,t){return this.#c.action("conversation.sendReply",{id:this.#a,reply:e,isOptimistic:t})}async sendTransactionReference(e,t){return this.#c.action("conversation.sendTransactionReference",{id:this.#a,transactionReference:e,isOptimistic:t})}async sendWalletSendCalls(e,t){return this.#c.action("conversation.sendWalletSendCalls",{id:this.#a,walletSendCalls:e,isOptimistic:t})}async sendActions(e,t){return this.#c.action("conversation.sendActions",{id:this.#a,actions:e,isOptimistic:t})}async sendIntent(e,t){return this.#c.action("conversation.sendIntent",{id:this.#a,intent:e,isOptimistic:t})}async sendAttachment(e,t){return this.#c.action("conversation.sendAttachment",{id:this.#a,attachment:e,isOptimistic:t})}async sendMultiRemoteAttachment(e,t){return this.#c.action("conversation.sendMultiRemoteAttachment",{id:this.#a,multiRemoteAttachment:e,isOptimistic:t})}async sendRemoteAttachment(e,t){return this.#c.action("conversation.sendRemoteAttachment",{id:this.#a,remoteAttachment:e,isOptimistic:t})}async messages(e){return(await this.#c.action("conversation.messages",{id:this.#a,options:e})).map(e=>new Se(this.#i,e))}async countMessages(e){return await this.#c.action("conversation.countMessages",{id:this.#a,options:e})}async consentState(){return this.#c.action("conversation.consentState",{id:this.#a})}async updateConsentState(e){return this.#c.action("conversation.updateConsentState",{id:this.#a,state:e})}async messageDisappearingSettings(){return this.#c.action("conversation.messageDisappearingSettings",{id:this.#a})}async updateMessageDisappearingSettings(e,t){return this.#c.action("conversation.updateMessageDisappearingSettings",{id:this.#a,fromNs:e,inNs:t})}async removeMessageDisappearingSettings(){return this.#c.action("conversation.removeMessageDisappearingSettings",{id:this.#a})}async isMessageDisappearingEnabled(){return this.#c.action("conversation.isMessageDisappearingEnabled",{id:this.#a})}async stream(e){return Ve(async(t,n)=>{const s=We();return e?.disableSync||await this.sync(),await this.#c.action("conversation.stream",{groupId:this.#a,streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>new Se(this.#i,e),e)}async pausedForVersion(){return this.#c.action("conversation.pausedForVersion",{id:this.#a})}async hmacKeys(){return this.#c.action("conversation.hmacKeys",{id:this.#a})}async debugInfo(){return this.#c.action("conversation.debugInfo",{id:this.#a})}async lastReadTimes(){return this.#c.action("conversation.lastReadTimes",{id:this.#a})}}class _e extends $e{#i;#c;#a;constructor(e,t,n,s){super(e,t,n,s),this.#c=e,this.#i=t,this.#a=n}async peerInboxId(){return this.#c.action("dm.peerInboxId",{id:this.#a})}async duplicateDms(){return(await this.#c.action("dm.duplicateDms",{id:this.#a})).map(e=>new _e(this.#c,this.#i,e.id,e))}}class je extends $e{#u=[];#h;#c;#p;#a;#l;#y;#g=[];#d(e){this.#y=e?.name??"",this.#l=e?.imageUrl??"",this.#p=e?.description??"",this.#h=e?.appData??"",this.#u=e?.admins??[],this.#g=e?.superAdmins??[]}constructor(e,t,n,s){super(e,t,n,s),this.#c=e,this.#a=n,this.#d(s)}async sync(){const e=await super.sync();return this.#d(e),e}get name(){return this.#y}async updateName(e){await this.#c.action("group.updateName",{id:this.#a,name:e}),this.#y=e}get imageUrl(){return this.#l}async updateImageUrl(e){await this.#c.action("group.updateImageUrl",{id:this.#a,imageUrl:e}),this.#l=e}get description(){return this.#p}async updateDescription(e){await this.#c.action("group.updateDescription",{id:this.#a,description:e}),this.#p=e}get appData(){return this.#h}async updateAppData(e){await this.#c.action("group.updateAppData",{id:this.#a,appData:e}),this.#h=e}get admins(){return this.#u}get superAdmins(){return this.#g}async listAdmins(){const e=await this.#c.action("group.listAdmins",{id:this.#a});return this.#u=e,e}async listSuperAdmins(){const e=await this.#c.action("group.listSuperAdmins",{id:this.#a});return this.#g=e,e}async permissions(){return this.#c.action("group.permissions",{id:this.#a})}async updatePermission(e,t,n){return this.#c.action("group.updatePermission",{id:this.#a,permissionType:e,policy:t,metadataField:n})}async isAdmin(e){return(await this.listAdmins()).includes(e)}async isSuperAdmin(e){return(await this.listSuperAdmins()).includes(e)}async addMembersByIdentifiers(e){return this.#c.action("group.addMembersByIdentifiers",{id:this.#a,identifiers:e})}async addMembers(e){return this.#c.action("group.addMembers",{id:this.#a,inboxIds:e})}async removeMembersByIdentifiers(e){return this.#c.action("group.removeMembersByIdentifiers",{id:this.#a,identifiers:e})}async removeMembers(e){return this.#c.action("group.removeMembers",{id:this.#a,inboxIds:e})}async addAdmin(e){return this.#c.action("group.addAdmin",{id:this.#a,inboxId:e})}async removeAdmin(e){return this.#c.action("group.removeAdmin",{id:this.#a,inboxId:e})}async addSuperAdmin(e){return this.#c.action("group.addSuperAdmin",{id:this.#a,inboxId:e})}async removeSuperAdmin(e){return this.#c.action("group.removeSuperAdmin",{id:this.#a,inboxId:e})}async requestRemoval(){return this.#c.action("group.requestRemoval",{id:this.#a})}async isPendingRemoval(){return this.#c.action("group.isPendingRemoval",{id:this.#a})}}class He{#w;#i;#c;constructor(e,t,n){this.#w=e,this.#c=t,this.#i=n}get topic(){return this.#w.installationId?`/xmtp/mls/1/w-${this.#w.installationId}/proto`:void 0}async sync(){return this.#c.action("conversations.sync")}async syncAll(e){return this.#c.action("conversations.syncAll",{consentStates:e})}async getConversationById(e){const t=await this.#c.action("conversations.getConversationById",{id:e});if(t)switch(t.metadata.conversationType){case D.Group:return new je(this.#c,this.#i,t.id,t);case D.Dm:return new _e(this.#c,this.#i,t.id,t);default:return}}async getMessageById(e){const t=await this.#c.action("conversations.getMessageById",{id:e});return t?new Se(this.#i,t):void 0}async getDmByInboxId(e){const t=await this.#c.action("conversations.getDmByInboxId",{inboxId:e});return t?new _e(this.#c,this.#i,t.id,t):void 0}async fetchDmByIdentifier(e){const t=await this.#c.action("client.getInboxIdByIdentifier",{identifier:e});if(t)return this.getDmByInboxId(t)}async list(e){return(await this.#c.action("conversations.list",{options:e})).map(e=>{switch(e.metadata.conversationType){case D.Dm:return new _e(this.#c,this.#i,e.id,e);case D.Group:return new je(this.#c,this.#i,e.id,e);default:return}}).filter(e=>void 0!==e)}async listGroups(e){return(await this.#c.action("conversations.listGroups",{options:e})).map(e=>new je(this.#c,this.#i,e.id,e))}async listDms(e){return(await this.#c.action("conversations.listDms",{options:e})).map(e=>new _e(this.#c,this.#i,e.id,e))}async createGroupOptimistic(e){const t=await this.#c.action("conversations.createGroupOptimistic",{options:e});return new je(this.#c,this.#i,t.id,t)}async createGroupWithIdentifiers(e,t){const n=await this.#c.action("conversations.createGroupWithIdentifiers",{identifiers:e,options:t});return new je(this.#c,this.#i,n.id,n)}async createGroup(e,t){const n=await this.#c.action("conversations.createGroup",{inboxIds:e,options:t});return new je(this.#c,this.#i,n.id,n)}async createDmWithIdentifier(e,t){const n=await this.#c.action("conversations.createDmWithIdentifier",{identifier:e,options:t});return new _e(this.#c,this.#i,n.id,n)}async createDm(e,t){const n=await this.#c.action("conversations.createDm",{inboxId:e,options:t});return new _e(this.#c,this.#i,n.id,n)}async hmacKeys(){return this.#c.action("conversations.hmacKeys")}async stream(e){return Ve(async(t,n)=>{const s=We();return e?.disableSync||await this.sync(),await this.#c.action("conversations.stream",{streamId:s,conversationType:e?.conversationType}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>{switch(e.metadata.conversationType){case D.Group:return new je(this.#c,this.#i,e.id,e);case D.Dm:return new _e(this.#c,this.#i,e.id,e);default:return void console.warn(`Unknown conversation type: ${e.metadata.conversationType}`)}},e)}async streamGroups(e){return this.stream({...e,conversationType:D.Group})}async streamDms(e){return this.stream({...e,conversationType:D.Dm})}async streamAllMessages(e){return Ve(async(t,n)=>{const s=We();return e?.disableSync||await this.sync(),await this.#c.action("conversations.streamAllMessages",{streamId:s,conversationType:e?.conversationType,consentStates:e?.consentStates}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},e=>new Se(this.#i,e),e)}async streamAllGroupMessages(e){return this.streamAllMessages({...e,conversationType:D.Group})}async streamAllDmMessages(e){return this.streamAllMessages({...e,conversationType:D.Dm})}async streamMessageDeletions(e){return Ve(async t=>{const n=We();return await this.#c.action("conversations.streamDeletedMessages",{streamId:n}),this.#c.handleStreamMessage(n,t,e)},e=>e.id,e)}async streamDeletedMessages(e){return Ve(async t=>{const n=We();return await this.#c.action("conversations.streamDeletedMessages",{streamId:n}),this.#c.handleStreamMessage(n,t,e)},e=>new Se(this.#i,e),e)}}class ze{#c;constructor(e){this.#c=e}apiStatistics(){return this.#c.action("debugInformation.apiStatistics")}apiIdentityStatistics(){return this.#c.action("debugInformation.apiIdentityStatistics")}apiAggregateStatistics(){return this.#c.action("debugInformation.apiAggregateStatistics")}clearAllStatistics(){return this.#c.action("debugInformation.clearAllStatistics")}}class Xe{#c;constructor(e){this.#c=e}sync(){return this.#c.action("preferences.sync")}async inboxState(){return this.#c.action("preferences.inboxState",{refreshFromNetwork:!1})}async fetchInboxState(){return this.#c.action("preferences.inboxState",{refreshFromNetwork:!0})}async getInboxStates(e){return this.#c.action("preferences.getInboxStates",{inboxIds:e,refreshFromNetwork:!1})}async fetchInboxStates(e){return this.#c.action("preferences.getInboxStates",{inboxIds:e,refreshFromNetwork:!0})}async setConsentStates(e){return this.#c.action("preferences.setConsentStates",{records:e})}async getConsentState(e,t){return this.#c.action("preferences.getConsentState",{entityType:e,entity:t})}async streamConsent(e){return Ve(async(t,n)=>{const s=We();return e?.disableSync||await this.sync(),await this.#c.action("preferences.streamConsent",{streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},void 0,e)}async streamPreferences(e){return Ve(async(t,n)=>{const s=We();return e?.disableSync||await this.sync(),await this.#c.action("preferences.streamPreferences",{streamId:s}),this.#c.handleStreamMessage(s,t,{...e,onFail:n})},void 0,e)}}const Je={local:M.Local,dev:M.Dev,production:M.Production,"testnet-staging":M.TestnetStaging,"testnet-dev":M.TestnetDev,testnet:M.Testnet,mainnet:M.Mainnet},Qe={[M.Local]:"local",[M.Dev]:"dev",[M.Production]:"production",[M.TestnetStaging]:"testnet-staging",[M.TestnetDev]:"testnet-dev",[M.Testnet]:"testnet",[M.Mainnet]:"mainnet"},Ye=async t=>{await e();let n=new C(Je[t?.env??"dev"]);return t?.apiUrl&&(n=n.setApiUrl(t.apiUrl)),t?.gatewayHost&&(n=n.setGatewayHost(t.gatewayHost)),t?.appVersion&&(n=n.setAppVersion(t.appVersion)),n.build()},Ze=["env","apiUrl","gatewayHost","appVersion"],et=async(e,t)=>{const n=await(async e=>{if(!e)return Ye();if((e=>"backend"in e)(e)){const t=Ze.filter(t=>t in e&&null!=e[t]);if(t.length>0)throw new Error(`Cannot specify both 'backend' and network options (${t.join(", ")}). Use either a pre-built Backend or network options, not both.`);return e.backend}return Ye(e)})(t),s=await E(n,e)||O(e),i=(r=n.env,Qe[r]);var r;const a=void 0===t?.dbPath?`xmtp-${i}-${s}.db3`:t.dbPath,o=t&&(void 0!==t.loggingLevel||t.structuredLogging||t.performanceLogging),c=t?.disableDeviceSync?q.Disabled:q.Enabled;return{client:await B(n,s,e,a,t?.dbEncryptionKey,c,t?.workerConfig,o?{structured:t.structuredLogging??!1,performance:t.performanceLogging??!1,level:t.loggingLevel}:void 0,void 0,void 0),env:i}},tt=async(t,n)=>(await e(),O(t,n)),nt=async(t,n)=>(await e(),E(t,n)),st=async(t,n,s,i)=>{await e();const r=await n.getIdentifier(),{signatureText:a,signatureRequest:o}=await(async(t,n,s,i)=>{await e();const r=P(t,n,s,i);return{signatureText:await r.signatureText(),signatureRequest:r}})(t,r,s,i),c=await n.signMessage(a);switch(n.type){case"EOA":await o.addEcdsaSignature(c);break;case"SCW":await o.addScwSignature(r,c,n.getChainId(),n.getBlockNumber?.())}await U(t,o)},it=(e=j())=>{const t=_(e);return{type:"EOA",getIdentifier:()=>({identifier:t.address.toLowerCase(),identifierKind:N.Ethereum}),signMessage:async e=>{const n=await t.signMessage({message:e});return $(n)}}},rt=(e,t,n)=>({type:"SCW",getIdentifier:()=>({identifier:e.toLowerCase(),identifierKind:N.Ethereum}),signMessage:async e=>{const n=await t(e);return $(n)},getChainId:()=>n}),at=async(e,t)=>{switch(e.type){case"EOA":return{type:"EOA",identifier:await e.getIdentifier(),signature:t};case"SCW":return{type:"SCW",identifier:await e.getIdentifier(),signature:t,chainId:e.getChainId(),blockNumber:e.getBlockNumber?.()}}},ot=e=>{console.error(`[worker] error: ${e.message}`)};class ct{#c;#m;#v=new Map;constructor(e,t){this.#c=e,this.#c.addEventListener("message",this.handleMessage),this.#c.addEventListener("error",ot),this.#m=t??!1}action(e,...t){const n=We();this.#c.postMessage({action:e,id:n,data:t[0]});return new Promise((e,t)=>{this.#v.set(n,{resolve:e,reject:t})})}handleMessage=e=>{const t=e.data;this.#m&&console.log("[worker] client received event data",t);const n=this.#v.get(t.id);n&&(this.#v.delete(t.id),"error"in t?n.reject(t.error):n.resolve(t.result))};handleStreamMessage=(e,t,n)=>{const s=s=>{const i=s.data;if(i.streamId===e){if("stream.fail"===i.action)return void n?.onFail?.();"error"in i?t(i.error,void 0):t(null,i.result)}};return this.#c.addEventListener("message",s),async()=>{await this.action("endStream",{streamId:e}),this.#c.removeEventListener("message",s)}};close(){this.#c.removeEventListener("message",this.handleMessage),this.#c.removeEventListener("error",ot),this.#c.terminate()}}const dt=async(e,t)=>e instanceof K?e:Ye({env:e,gatewayHost:t}),ut=e=>e instanceof Map?e:new Map(Object.entries(e));class ht{#k;#i;#f;#I;#b;#x;#R;#A;#S;#T=!1;#D;#M;#C;#E;#c;constructor(e){e&&Object.defineProperty(e,"codecs",{value:e.codecs,enumerable:!1});const t=new Worker(new URL("./workers/client",import.meta.url),{type:"module"}),n=void 0!==e?.loggingLevel&&e.loggingLevel!==F.Off;this.#c=new ct(t,n),this.#i=new H([...e?.codecs??[]]),this.#M=e,this.#f=new He(this,this.#c,this.#i),this.#I=new ze(this.#c),this.#C=new Xe(this.#c)}async init(e){const t=await this.#c.action("client.init",{identifier:e,options:this.#M});this.#k=t.appVersion,this.#b=t.env,this.#x=e,this.#R=t.inboxId,this.#A=t.installationId,this.#S=t.installationIdBytes,this.#D=t.libxmtpVersion,this.#T=!0}close(){this.#c.close(),this.#T=!1}static async create(e,t){const n=new ht(t);return n.#E=e,await n.init(await e.getIdentifier()),t?.disableAutoRegister||await n.register(),n}static async build(e,t){const n=new ht({...t,disableAutoRegister:!0});return await n.init(e),n}get options(){return this.#M}get signer(){return this.#E}get isReady(){return this.#T}get inboxId(){return this.#R}get accountIdentifier(){return this.#x}get installationId(){return this.#A}get installationIdBytes(){return this.#S}get conversations(){return this.#f}get debugInformation(){return this.#I}get preferences(){return this.#C}get libxmtpVersion(){return this.#D}get appVersion(){return this.#k}get env(){return this.#b}async unsafe_createInboxSignatureText(){return this.#c.action("client.createInboxSignatureText",{signatureRequestId:We()})}async unsafe_addAccountSignatureText(e,t=!1){if(!t)throw new Oe;return this.#c.action("client.addAccountSignatureText",{newIdentifier:e,signatureRequestId:We()})}async unsafe_removeAccountSignatureText(e){return this.#c.action("client.removeAccountSignatureText",{identifier:e,signatureRequestId:We()})}async unsafe_revokeAllOtherInstallationsSignatureText(){return this.#c.action("client.revokeAllOtherInstallationsSignatureText",{signatureRequestId:We()})}async unsafe_revokeInstallationsSignatureText(e){return this.#c.action("client.revokeInstallationsSignatureText",{installationIds:e,signatureRequestId:We()})}async unsafe_changeRecoveryIdentifierSignatureText(e){return this.#c.action("client.changeRecoveryIdentifierSignatureText",{identifier:e,signatureRequestId:We()})}async unsafe_applySignatureRequest(e,t){return this.#c.action("client.applySignatureRequest",{signer:e,signatureRequestId:t})}async register(){if(!this.#E)throw new Ee;const{signatureText:e,signatureRequestId:t}=await this.unsafe_createInboxSignatureText();if(!e||!t)return;const n=await this.#E.signMessage(e),s=await at(this.#E,n);return this.#c.action("client.registerIdentity",{signer:s,signatureRequestId:t,waitForRegistrationVisible:this.#M?.waitForRegistrationVisible})}async unsafe_addAccount(e,t=!1){if(!this.#E)throw new Ee;if(!t)throw new Oe;const n=await this.fetchInboxIdByIdentifier(await e.getIdentifier());if(n)throw new qe(n);const{signatureText:s,signatureRequestId:i}=await this.unsafe_addAccountSignatureText(await e.getIdentifier(),!0),r=await e.signMessage(s),a=await at(e,r);return this.#c.action("client.addAccount",{identifier:a.identifier,signer:a,signatureRequestId:i})}async removeAccount(e){if(!this.#E)throw new Ee;const{signatureText:t,signatureRequestId:n}=await this.unsafe_removeAccountSignatureText(e),s=await this.#E.signMessage(t),i=await at(this.#E,s);return this.#c.action("client.removeAccount",{identifier:e,signer:i,signatureRequestId:n})}async revokeAllOtherInstallations(){if(!this.#E)throw new Ee;const{signatureText:e,signatureRequestId:t}=await this.unsafe_revokeAllOtherInstallationsSignatureText();if(!e)return;const n=await this.#E.signMessage(e),s=await at(this.#E,n);return this.#c.action("client.revokeAllOtherInstallations",{signer:s,signatureRequestId:t})}async revokeInstallations(e){if(!this.#E)throw new Ee;const{signatureText:t,signatureRequestId:n}=await this.unsafe_revokeInstallationsSignatureText(e),s=await this.#E.signMessage(t),i=await at(this.#E,s);return this.#c.action("client.revokeInstallations",{installationIds:e,signer:i,signatureRequestId:n})}static async revokeInstallations(e,t,n,s,i){const r=await dt(s,i);await st(r,e,t,n)}static async fetchInboxStates(t,n,s){return(async(t,n)=>(await e(),L(t,n)))(await dt(n,s),t)}async changeRecoveryIdentifier(e){if(!this.#E)throw new Ee;const{signatureText:t,signatureRequestId:n}=await this.unsafe_changeRecoveryIdentifierSignatureText(e),s=await this.#E.signMessage(t),i=await at(this.#E,s);return this.#c.action("client.changeRecoveryIdentifier",{identifier:e,signer:i,signatureRequestId:n})}async isRegistered(){return this.#c.action("client.isRegistered")}async canMessage(e){return this.#c.action("client.canMessage",{identifiers:e})}async fetchLatestInboxUpdatesCount(e){const t=await this.#c.action("client.fetchLatestInboxUpdatesCount",{inboxIds:e});return ut(t)}async fetchOwnInboxUpdatesCount(){return this.#c.action("client.fetchOwnInboxUpdatesCount",{})}static async canMessage(e,t){const n=await dt(t),s=new Map;for(const t of e){const e=await nt(n,t);s.set(t.identifier.toLowerCase(),void 0!==e)}return s}static async fetchLatestInboxUpdatesCount(e,t,n){const s=await dt(t,n),{client:i}=await et((()=>{const e=new Uint8Array(20);return globalThis.crypto.getRandomValues(e),{identifier:`0x${Array.from(e,e=>e.toString(16).padStart(2,"0")).join("")}`,identifierKind:N.Ethereum}})(),{backend:s,dbPath:null,disableDeviceSync:!0});try{const t=await i.fetchLatestInboxUpdatesCount(!0,e);return ut(t)}finally{i.free()}}async fetchInboxIdByIdentifier(e){return this.#c.action("client.getInboxIdByIdentifier",{identifier:e})}signWithInstallationKey(e){return this.#c.action("client.signWithInstallationKey",{signatureText:e})}verifySignedWithInstallationKey(e,t){return this.#c.action("client.verifySignedWithInstallationKey",{signatureText:e,signatureBytes:t})}verifySignedWithPublicKey(e,t,n){return this.#c.action("client.verifySignedWithPublicKey",{signatureText:e,signatureBytes:t,publicKey:n})}async fetchKeyPackageStatuses(e){return this.#c.action("client.fetchKeyPackageStatuses",{installationIds:e})}#O(){return{elements:[G.Consent,G.Messages],excludeDisappearingMessages:!1}}#q(){const e=this.#b??"dev";return X[e]}async sendSyncRequest(e,t){const n=e??this.#O(),s=t??this.#q();return this.#c.action("client.sendSyncRequest",{options:n,serverUrl:s})}async sendSyncArchive(e,t,n){const s=t??this.#O(),i=n??this.#q();return this.#c.action("client.sendSyncArchive",{options:s,serverUrl:i,pin:e})}async processSyncArchive(e){return this.#c.action("client.processSyncArchive",{archivePin:e})}async listAvailableArchives(e){return this.#c.action("client.listAvailableArchives",{daysCutoff:e})}async createArchive(e,t){const n=t??this.#O();return this.#c.action("client.createArchive",{opts:n,key:e})}async importArchive(e,t){return this.#c.action("client.importArchive",{data:e,key:t})}async archiveMetadata(e,t){return this.#c.action("client.archiveMetadata",{data:e,key:t})}async syncAllDeviceSyncGroups(){return this.#c.action("client.syncAllDeviceSyncGroups")}}class pt{#c;#m;constructor(e){const t=new Worker(new URL("./workers/opfs",import.meta.url),{type:"module"});this.#c=new ct(t,e),this.#m=e??!1}async init(){await this.#c.action("opfs.init",{enableLogging:this.#m})}close(){this.#c.close()}static async create(e){const t=new pt(e);return await t.init(),t}async listFiles(){return this.#c.action("opfs.listFiles")}async fileCount(){return this.#c.action("opfs.fileCount")}async poolCapacity(){return this.#c.action("opfs.poolCapacity")}async fileExists(e){return this.#c.action("opfs.fileExists",{path:e})}async deleteFile(e){return this.#c.action("opfs.deleteFile",{path:e})}async exportDb(e){return this.#c.action("opfs.exportDb",{path:e})}async importDb(e,t){return this.#c.action("opfs.importDb",{path:e,data:t})}async clearAll(){return this.#c.action("opfs.clearAll")}}const lt=async t=>(await e(),V(t)),yt=async e=>({id:e.id,name:e.name,imageUrl:e.imageUrl,description:e.description,appData:e.appData,permissions:e.permissions(),addedByInboxId:e.addedByInboxId,metadata:await e.metadata(),admins:e.listAdmins(),superAdmins:e.listSuperAdmins(),createdAtNs:e.createdAtNs}),gt=e=>"xmtp.org"===e.contentType.authorityId&&"reaction"===e.contentType.typeId,wt=e=>"xmtp.org"===e.contentType.authorityId&&"reply"===e.contentType.typeId,mt=e=>wt(e)&&"string"==typeof e.content?.content,vt=e=>"xmtp.org"===e.contentType.authorityId&&"text"===e.contentType.typeId,kt=e=>"xmtp.org"===e.contentType.authorityId&&"remoteStaticAttachment"===e.contentType.typeId,ft=e=>"xmtp.org"===e.contentType.authorityId&&"attachment"===e.contentType.typeId,It=e=>"xmtp.org"===e.contentType.authorityId&&"multiRemoteStaticAttachment"===e.contentType.typeId,bt=e=>"xmtp.org"===e.contentType.authorityId&&"transactionReference"===e.contentType.typeId,xt=e=>"xmtp.org"===e.contentType.authorityId&&"group_updated"===e.contentType.typeId,Rt=e=>"xmtp.org"===e.contentType.authorityId&&"readReceipt"===e.contentType.typeId,At=e=>"xmtp.org"===e.contentType.authorityId&&"leave_request"===e.contentType.typeId,St=e=>"xmtp.org"===e.contentType.authorityId&&"walletSendCalls"===e.contentType.typeId,Tt=e=>"coinbase.com"===e.contentType.authorityId&&"intent"===e.contentType.typeId,Dt=e=>"coinbase.com"===e.contentType.authorityId&&"actions"===e.contentType.typeId,Mt=e=>"xmtp.org"===e.contentType.authorityId&&"markdown"===e.contentType.typeId;export{qe as AccountAlreadyAssociatedError,z as ApiUrls,ht as Client,Ce as ClientNotInitializedError,$e as Conversation,He as Conversations,Se as DecodedMessage,_e as Dm,je as Group,Be as GroupNotFoundError,X as HistorySyncUrls,Oe as InboxReassignError,pt as Opfs,Fe as OpfsInitializationError,Ne as OpfsNotInitializedError,Ee as SignerUnavailableError,Ue as StreamFailedError,Pe as StreamInvalidRetryAttemptsError,Le as StreamNotFoundError,ce as contentTypeActions,de as contentTypeAttachment,ue as contentTypeGroupUpdated,he as contentTypeIntent,pe as contentTypeLeaveRequest,le as contentTypeMarkdown,ye as contentTypeMultiRemoteAttachment,ge as contentTypeReaction,we as contentTypeReadReceipt,me as contentTypeRemoteAttachment,ve as contentTypeReply,ke as contentTypeText,fe as contentTypeTransactionReference,Ie as contentTypeWalletSendCalls,Ye as createBackend,it as createEOASigner,rt as createSCWSigner,xe as decryptAttachment,Q as encodeActions,Y as encodeAttachment,Z as encodeIntent,ee as encodeMarkdown,te as encodeMultiRemoteAttachment,ne as encodeReaction,se as encodeReadReceipt,ie as encodeRemoteAttachment,re as encodeText,ae as encodeTransactionReference,oe as encodeWalletSendCalls,be as encryptAttachment,tt as generateInboxId,nt as getInboxIdForIdentifier,Dt as isActions,ft as isAttachment,xt as isGroupUpdated,Tt as isIntent,At as isLeaveRequest,Mt as isMarkdown,It as isMultiRemoteAttachment,gt as isReaction,Rt as isReadReceipt,kt as isRemoteAttachment,wt as isReply,vt as isText,mt as isTextReply,bt as isTransactionReference,St as isWalletSendCalls,lt as metadataFieldName,yt as toSafeConversation,at as toSafeSigner};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|