@ping-app/ping-openmls-sdk 0.10.4 → 0.10.6
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.cjs +168 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +69 -15
- package/dist/index.d.ts +69 -15
- package/dist/index.js +168 -64
- package/dist/index.js.map +1 -1
- package/dist/notification-preview.d.cts +1 -1
- package/dist/notification-preview.d.ts +1 -1
- package/dist/storage/indexeddb.d.cts +1 -1
- package/dist/storage/indexeddb.d.ts +1 -1
- package/dist/transport/websocket.d.cts +1 -1
- package/dist/transport/websocket.d.ts +1 -1
- package/dist/{types-omhvRjtq.d.cts → types-D8fIp-_0.d.cts} +28 -0
- package/dist/{types-omhvRjtq.d.ts → types-D8fIp-_0.d.ts} +28 -0
- package/dist/worker.cjs +34 -5
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +38 -6
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/wasm/package.json +1 -1
- package/wasm/ping_wasm.d.ts +43 -2
- package/wasm/ping_wasm.js +104 -35
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +6 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Storage, M as MessageEnvelope, T as Transport, E as ExpectedOwner, C as ConversationId, K as KeyPackageEntry, A as AddMembersReport, a as DeviceId, U as UserId, b as ConversationMeta, c as DeviceReauthProof, d as DeviceLinkApproval, e as DeviceLinkPossession, L as LinkingTicketV3, f as CommitInDoubt, g as MemberInfo, h as ConversationPolicy, I as IncomingMessage, F as FetchedSealedGroupInfo, i as SelfAdmitResult, j as SelfAdmitManyEntry, k as SequencedEnvelope, l as ApplyBatchResult, m as SyncStepResult, n as LogPosition, o as LogHole, p as LogHead, P as PendingApply, q as CatchupSnapshotView, r as CatchupAppEvent, s as LinkGeneration, t as LinkedDevice, B as BackupPhraseCheck, H as HistoryDeliveryKeyStatement, u as HistoryBundle, O as OpenedHistory, v as HistoryShipDecision, w as AdmitChatEntry, x as AdmitChatOutcome, y as DeviceRemovalReport, z as ExportedSecret, G as MessageBatchMeta } from './types-
|
|
2
|
-
export { J as AddMemberStatus, N as AddMemberVerdict, Q as BackupCheckFailure, R as BufferOverflow, V as Bytes, W as CatchupSnapshotEntry, X as ConversationRemoval, Y as ConversationUpdate, Z as DeviceInfo, _ as DeviceRemovalFailure, D as DiscoveredDevice, $ as ExternalCommitAnswer, a0 as ExternalCommitPosted, a1 as HistoryAppEvent, a2 as Hlc, a3 as HoleReason, a4 as JournalFullAt, a5 as LogAck, a6 as LogGap, a7 as MessageKind, a8 as OverflowReason, a9 as SealedGroupInfoRow, aa as SealedGroupInfoUpload, ab as SealedGroupInfoWrap, ac as SealingStatementRow, ad as SelfAdmission, ae as SelfAdmissionState, af as SelfAdmitRefusal, ag as SelfAdmitWait, ah as SenderRole, ai as StrandReason, aj as StrandedConversation, ak as WelcomeFailure, al as WelcomeFailureReason } from './types-
|
|
1
|
+
import { S as Storage, M as MessageEnvelope, T as Transport, E as ExpectedOwner, C as ConversationId, K as KeyPackageEntry, A as AddMembersReport, a as DeviceId, U as UserId, b as ConversationMeta, c as DeviceReauthProof, d as DeviceLinkApproval, e as DeviceLinkPossession, L as LinkingTicketV3, f as CommitInDoubt, g as MemberInfo, h as ConversationPolicy, I as IncomingMessage, F as FetchedSealedGroupInfo, i as SelfAdmitResult, j as SelfAdmitManyEntry, k as SequencedEnvelope, l as ApplyBatchResult, m as SyncStepResult, n as LogPosition, o as LogHole, p as LogHead, P as PendingApply, q as CatchupSnapshotView, r as CatchupAppEvent, s as LinkGeneration, t as LinkedDevice, B as BackupPhraseCheck, H as HistoryDeliveryKeyStatement, u as HistoryBundle, O as OpenedHistory, v as HistoryShipDecision, w as AdmitChatEntry, x as AdmitChatOutcome, y as DeviceRemovalReport, z as ExportedSecret, G as MessageBatchMeta } from './types-D8fIp-_0.cjs';
|
|
2
|
+
export { J as AddMemberStatus, N as AddMemberVerdict, Q as BackupCheckFailure, R as BufferOverflow, V as Bytes, W as CatchupSnapshotEntry, X as ConversationRemoval, Y as ConversationUpdate, Z as DeviceInfo, _ as DeviceRemovalFailure, D as DiscoveredDevice, $ as ExternalCommitAnswer, a0 as ExternalCommitPosted, a1 as HistoryAppEvent, a2 as Hlc, a3 as HoleReason, a4 as JournalFullAt, a5 as LogAck, a6 as LogGap, a7 as MessageKind, a8 as OverflowReason, a9 as SealedGroupInfoRow, aa as SealedGroupInfoUpload, ab as SealedGroupInfoWrap, ac as SealingStatementRow, ad as SelfAdmission, ae as SelfAdmissionState, af as SelfAdmitRefusal, ag as SelfAdmitWait, ah as SenderRole, ai as StrandReason, aj as StrandedConversation, ak as WelcomeFailure, al as WelcomeFailureReason } from './types-D8fIp-_0.cjs';
|
|
3
3
|
export { IndexedDbStorage } from './storage/indexeddb.cjs';
|
|
4
4
|
export { WebSocketTransport } from './transport/websocket.cjs';
|
|
5
5
|
export { MAX_PREVIEW_PREREQUISITES, NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.cjs';
|
|
@@ -23,6 +23,25 @@ interface NewAccountDevice {
|
|
|
23
23
|
statement: SealingStatement;
|
|
24
24
|
deviceSigningSecretKey: Uint8Array;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* What `AccountSetup.prepareDeviceKey` answers: the device id (SHA-256 of the
|
|
28
|
+
* public key) and the public key a sign-in BY CODE names, and the device key
|
|
29
|
+
* for the host's protected store. `deviceSigningSecretKey` is a secret: store
|
|
30
|
+
* it BEFORE any request names the key, never log it.
|
|
31
|
+
*/
|
|
32
|
+
interface PreparedDeviceKey {
|
|
33
|
+
deviceId: Uint8Array;
|
|
34
|
+
devicePublicKey: Uint8Array;
|
|
35
|
+
deviceSigningSecretKey: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What `AccountSetup.deviceStartCheck` answers (ruling V904): what a start from
|
|
39
|
+
* the device record would answer on this store. `startable`: the store holds a
|
|
40
|
+
* device record and its device key (if it holds one yet) is the record's.
|
|
41
|
+
* `no-device-record`: set up, link or restore. `device-key-mismatch`: the
|
|
42
|
+
* store's device key, or the expected device id, is not the record's.
|
|
43
|
+
*/
|
|
44
|
+
type DeviceStartCheck = "startable" | "no-device-record" | "device-key-mismatch";
|
|
26
45
|
interface AccountBackupParts {
|
|
27
46
|
rootPart: Uint8Array;
|
|
28
47
|
statePart: Uint8Array;
|
|
@@ -234,6 +253,30 @@ declare class AccountSetup {
|
|
|
234
253
|
identityState: string | undefined;
|
|
235
254
|
persistentStorage?: boolean;
|
|
236
255
|
}): Promise<NewAccountDevice>;
|
|
256
|
+
/**
|
|
257
|
+
* THE PREPARED DEVICE KEY (rulings V895 to V900, V913, V965): the device key
|
|
258
|
+
* a sign-in BY CODE names on a store with no device record, before the
|
|
259
|
+
* account exists. The SDK draws it (no argument is a key), keeps it in one
|
|
260
|
+
* row of this store and answers it; a repeat answers the SAME key, and two
|
|
261
|
+
* tabs that call at once answer one key (the origin's account lock).
|
|
262
|
+
* `createAccount`, the in-memory session and `MessagingClient.beginDeviceLink`
|
|
263
|
+
* then make the device with that key; a restore or a take-back never uses
|
|
264
|
+
* it. Store the secret BEFORE any request names the key. Refusals:
|
|
265
|
+
* `account-already-set-up` (the store holds a device), `rotation-in-progress`,
|
|
266
|
+
* `device-key-held-by-link` (a link was begun in this slot: offer "Finish
|
|
267
|
+
* linking" or "Start over", never a retry), `prepared-key-mismatch`.
|
|
268
|
+
*/
|
|
269
|
+
prepareDeviceKey(): Promise<PreparedDeviceKey>;
|
|
270
|
+
/** Delete a FREE prepared device key and nothing else; answers whether a
|
|
271
|
+
* row was deleted. Log the key's session out FIRST, and delete the host's
|
|
272
|
+
* own copy of the secret last. Refuses as `prepareDeviceKey` does. */
|
|
273
|
+
discardPreparedDeviceKey(): Promise<boolean>;
|
|
274
|
+
/** THE PREDICATE (ruling V904): what a start from the device record would
|
|
275
|
+
* answer on this store, as a typed value. It starts nothing, writes
|
|
276
|
+
* nothing and sends nothing. `expectedDeviceId` is the PUBLIC device id
|
|
277
|
+
* the host keeps, if it keeps one. Decide stop or retry on the answer,
|
|
278
|
+
* never on the words of an error. */
|
|
279
|
+
deviceStartCheck(expectedDeviceId?: Uint8Array): Promise<DeviceStartCheck>;
|
|
237
280
|
/** Whether the slot holds the pending root this device expects (rule R32).
|
|
238
281
|
* No prompt, no read of the seed. */
|
|
239
282
|
pendingStatus(slot: string): Promise<PendingRootStatus>;
|
|
@@ -357,7 +400,10 @@ declare class AccountSetup {
|
|
|
357
400
|
* Begin a set-up session whose root is in memory only (rule R34 a): for the
|
|
358
401
|
* person who makes the backup during set-up. One session per object; it
|
|
359
402
|
* lives in the Worker until `sessionFinish`, `sessionKeepAsPending` or
|
|
360
|
-
* `close`.
|
|
403
|
+
* `close`. It begins ON THIS STORE (read, nothing written): the session's
|
|
404
|
+
* device is made for the store's free prepared device key, when
|
|
405
|
+
* `prepareDeviceKey` made one. `device-key-held-by-link`: a link was begun
|
|
406
|
+
* in this slot.
|
|
361
407
|
*/
|
|
362
408
|
beginInMemory(identityState: string | undefined): Promise<void>;
|
|
363
409
|
/** The session's backup. */
|
|
@@ -653,9 +699,11 @@ declare class MessagingClient {
|
|
|
653
699
|
*/
|
|
654
700
|
private metaCache;
|
|
655
701
|
/**
|
|
656
|
-
*
|
|
657
|
-
* to the worker at once, frames that arrive while that batch is
|
|
658
|
-
* go out as ONE `processSequencedBatch` when it returns
|
|
702
|
+
* ONE lane of sequenced live frames for every conversation: the first
|
|
703
|
+
* frame goes to the worker at once, frames that arrive while that batch is
|
|
704
|
+
* in flight go out as ONE `processSequencedBatch` when it returns, in
|
|
705
|
+
* arrival order. Rows the engine did not take (`notTaken`) stay in the
|
|
706
|
+
* lane and are handed again after the next `confirmApplied`. See
|
|
659
707
|
* {@link dispatchIncoming}.
|
|
660
708
|
*/
|
|
661
709
|
private readonly coalescer;
|
|
@@ -907,10 +955,14 @@ declare class MessagingClient {
|
|
|
907
955
|
* position, holds it ahead of a hole and drops it at or below what was
|
|
908
956
|
* applied, whatever order it arrived in. What it needs is BATCHING: one
|
|
909
957
|
* MLS checkpoint and one host transaction per burst instead of one per
|
|
910
|
-
* frame. So the first frame
|
|
911
|
-
*
|
|
912
|
-
* accumulate and go out as ONE `processSequencedBatch` when it returns
|
|
913
|
-
*
|
|
958
|
+
* frame. So the first frame goes to the worker at once as a batch of one,
|
|
959
|
+
* and frames of ANY conversation that arrive while that batch is in flight
|
|
960
|
+
* accumulate and go out as ONE `processSequencedBatch` when it returns, in
|
|
961
|
+
* arrival order (one lane for all conversations: a catch-up of 200
|
|
962
|
+
* conversations is about 20 Worker calls, not 400); no timer ever delays a
|
|
963
|
+
* frame. Rows the engine did not take because the pending-apply journal
|
|
964
|
+
* had no room (`notTaken`) stay in the lane, in order, and are handed
|
|
965
|
+
* again after the next `confirmApplied`. Own-device echoes are NOT dropped on this
|
|
914
966
|
* path: the core advances the position past them without touching MLS,
|
|
915
967
|
* and dropping one would leave a hole the next frame reports as a gap. A
|
|
916
968
|
* sequenced frame at `serverSeq` 0 is a legacy frame in a wrapper and
|
|
@@ -922,10 +974,12 @@ declare class MessagingClient {
|
|
|
922
974
|
/** The actual routing, run inside the per-conversation chain. */
|
|
923
975
|
private dispatchIncomingOrdered;
|
|
924
976
|
/**
|
|
925
|
-
* One coalesced batch of live frames
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
977
|
+
* One coalesced batch of live frames, of any number of conversations.
|
|
978
|
+
* Answers the indexes of the rows the engine did not take (the journal
|
|
979
|
+
* had no room): the lane keeps those and hands them again after the next
|
|
980
|
+
* `confirmApplied`. A rejection goes to the lane, which hands a refused
|
|
981
|
+
* batch again one conversation at a time; `dispatchIncoming` logs what
|
|
982
|
+
* still fails at debug and resolves.
|
|
929
983
|
*/
|
|
930
984
|
private applyLiveBatch;
|
|
931
985
|
/** Start a fill for every gap a batch reported; each is single-flight. */
|
|
@@ -2096,4 +2150,4 @@ declare function emulateSendBatch(transport: Pick<Transport, "send">, envelopes:
|
|
|
2096
2150
|
* server error code rides along for diagnostics. */
|
|
2097
2151
|
declare function describeTransportError(e: unknown): string;
|
|
2098
2152
|
|
|
2099
|
-
export { type AccountBackupParts, AccountSetup, AccountSetupClosedError, type AccountSetupConfig, AddMembersReport, AdmitChatEntry, AdmitChatOutcome, type AdoptedGeneration, ApplyBatchResult, BATCH_PARTIAL_PREFIX, BackupPhraseCheck, CONTENT_TYPE_CBOR, CONTENT_TYPE_CBOR_LEGACY_V1, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_LEGACY_V1, CatchupAppEvent, CatchupSnapshotView, type ClientConfig, CommitInDoubt, type Conversation, ConversationId, ConversationMeta, ConversationPolicy, DEVICE_GROUP_BEHIND_PREFIX, DeviceGroupBehindError, DeviceId, DeviceLinkApproval, type DeviceLinkBegun, type DeviceLinkClientConfig, DeviceLinkPossession, DeviceReauthProof, type DeviceRecordClientConfig, DeviceRemovalReport, EphemeralWorkerError, ExpectedOwner, ExportedSecret, FetchedSealedGroupInfo, HISTORY_REFUSED_PREFIX, HPKE_PQ_ENC_BYTES, HPKE_PQ_PUBLIC_KEY_BYTES, HistoryBundle, HistoryDeliveryKeyStatement, type HistoryRefusalReason, HistoryRefusedError, HistoryShipDecision, IncomingMessage, JOURNAL_FULL_PREFIX, JournalFullError, KeyPackageEntry, LINK_ADD_REFUSED_PREFIX, LINK_CHAIN_TOO_DEEP_PREFIX, LINK_COMMITMENT_MISMATCH_PREFIX, LinkAddRefusedError, LinkChainTooDeepError, type LinkCommitment, LinkCommitmentMismatchError, type LinkExpected, LinkGeneration, LinkedDevice, LinkingTicketV3, LogHead, LogHole, LogPosition, MemberInfo, MessageBatchMeta, MessageEnvelope, MessagingClient, MessagingClientClosedError, NOT_PERMITTED_PREFIX, type NewAccountDevice, NotPermittedError, OpenedHistory, PING_WIRE_CONTRACT_HEADER, PING_WIRE_CONTRACT_HEADER_VALUE, PING_WIRE_CONTRACT_VERSION, PendingApply, type PendingRootStatus, type PendingRotation, READ_ONLY_PREFIX, ReadOnlyError, type RestoreJoined, type RestoreOpened, type RotationAnswer, type RotationBuild, type RotationBuilt, type RotationKeptRefusal, type RotationOutcome, type RotationPhase, type RotationPlan, type RotationRecordState, type RotationRequest, type RotationStart, type RotationStartDevice, SENDER_MISMATCH_PREFIX, STALE_GENERATION_PREFIX, STORE_MOVED_PREFIX, type SealingStatement, SelfAdmitManyEntry, SelfAdmitResult, SenderMismatchError, SequencedEnvelope, StaleGenerationError, type StateOpened, type StateRefreshed, Storage, StoreMovedError, SyncStepResult, Transport, UserId, ValidationError, type VerifiedLinkHandshakeInfo, WELCOME_MISLABELED_PREFIX, WELCOME_WAITS_PREFIX, WIRE_VERSION_MIN_ACCEPTED, WelcomeMislabeledError, WelcomeWaitsError, accountRefusalCode, backupPhraseCheckFromWire, describeTransportError, emulateSendBatch, isDeviceGroupBehindError, isHistoryRefusedError, isJournalFullError, isLinkAddRefusedError, isLinkChainTooDeepError, isLinkCommitmentMismatchError, isNotPermittedError, isReadOnlyError, isSenderMismatchError, isStaleGenerationError, isStoreMovedError, isWelcomeMislabeledError, isWelcomeWaitsError, negotiates, notPermittedRule, validate, verifyApplicationContentHash };
|
|
2153
|
+
export { type AccountBackupParts, AccountSetup, AccountSetupClosedError, type AccountSetupConfig, AddMembersReport, AdmitChatEntry, AdmitChatOutcome, type AdoptedGeneration, ApplyBatchResult, BATCH_PARTIAL_PREFIX, BackupPhraseCheck, CONTENT_TYPE_CBOR, CONTENT_TYPE_CBOR_LEGACY_V1, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_LEGACY_V1, CatchupAppEvent, CatchupSnapshotView, type ClientConfig, CommitInDoubt, type Conversation, ConversationId, ConversationMeta, ConversationPolicy, DEVICE_GROUP_BEHIND_PREFIX, DeviceGroupBehindError, DeviceId, DeviceLinkApproval, type DeviceLinkBegun, type DeviceLinkClientConfig, DeviceLinkPossession, DeviceReauthProof, type DeviceRecordClientConfig, DeviceRemovalReport, type DeviceStartCheck, EphemeralWorkerError, ExpectedOwner, ExportedSecret, FetchedSealedGroupInfo, HISTORY_REFUSED_PREFIX, HPKE_PQ_ENC_BYTES, HPKE_PQ_PUBLIC_KEY_BYTES, HistoryBundle, HistoryDeliveryKeyStatement, type HistoryRefusalReason, HistoryRefusedError, HistoryShipDecision, IncomingMessage, JOURNAL_FULL_PREFIX, JournalFullError, KeyPackageEntry, LINK_ADD_REFUSED_PREFIX, LINK_CHAIN_TOO_DEEP_PREFIX, LINK_COMMITMENT_MISMATCH_PREFIX, LinkAddRefusedError, LinkChainTooDeepError, type LinkCommitment, LinkCommitmentMismatchError, type LinkExpected, LinkGeneration, LinkedDevice, LinkingTicketV3, LogHead, LogHole, LogPosition, MemberInfo, MessageBatchMeta, MessageEnvelope, MessagingClient, MessagingClientClosedError, NOT_PERMITTED_PREFIX, type NewAccountDevice, NotPermittedError, OpenedHistory, PING_WIRE_CONTRACT_HEADER, PING_WIRE_CONTRACT_HEADER_VALUE, PING_WIRE_CONTRACT_VERSION, PendingApply, type PendingRootStatus, type PendingRotation, type PreparedDeviceKey, READ_ONLY_PREFIX, ReadOnlyError, type RestoreJoined, type RestoreOpened, type RotationAnswer, type RotationBuild, type RotationBuilt, type RotationKeptRefusal, type RotationOutcome, type RotationPhase, type RotationPlan, type RotationRecordState, type RotationRequest, type RotationStart, type RotationStartDevice, SENDER_MISMATCH_PREFIX, STALE_GENERATION_PREFIX, STORE_MOVED_PREFIX, type SealingStatement, SelfAdmitManyEntry, SelfAdmitResult, SenderMismatchError, SequencedEnvelope, StaleGenerationError, type StateOpened, type StateRefreshed, Storage, StoreMovedError, SyncStepResult, Transport, UserId, ValidationError, type VerifiedLinkHandshakeInfo, WELCOME_MISLABELED_PREFIX, WELCOME_WAITS_PREFIX, WIRE_VERSION_MIN_ACCEPTED, WelcomeMislabeledError, WelcomeWaitsError, accountRefusalCode, backupPhraseCheckFromWire, describeTransportError, emulateSendBatch, isDeviceGroupBehindError, isHistoryRefusedError, isJournalFullError, isLinkAddRefusedError, isLinkChainTooDeepError, isLinkCommitmentMismatchError, isNotPermittedError, isReadOnlyError, isSenderMismatchError, isStaleGenerationError, isStoreMovedError, isWelcomeMislabeledError, isWelcomeWaitsError, negotiates, notPermittedRule, validate, verifyApplicationContentHash };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as Storage, M as MessageEnvelope, T as Transport, E as ExpectedOwner, C as ConversationId, K as KeyPackageEntry, A as AddMembersReport, a as DeviceId, U as UserId, b as ConversationMeta, c as DeviceReauthProof, d as DeviceLinkApproval, e as DeviceLinkPossession, L as LinkingTicketV3, f as CommitInDoubt, g as MemberInfo, h as ConversationPolicy, I as IncomingMessage, F as FetchedSealedGroupInfo, i as SelfAdmitResult, j as SelfAdmitManyEntry, k as SequencedEnvelope, l as ApplyBatchResult, m as SyncStepResult, n as LogPosition, o as LogHole, p as LogHead, P as PendingApply, q as CatchupSnapshotView, r as CatchupAppEvent, s as LinkGeneration, t as LinkedDevice, B as BackupPhraseCheck, H as HistoryDeliveryKeyStatement, u as HistoryBundle, O as OpenedHistory, v as HistoryShipDecision, w as AdmitChatEntry, x as AdmitChatOutcome, y as DeviceRemovalReport, z as ExportedSecret, G as MessageBatchMeta } from './types-
|
|
2
|
-
export { J as AddMemberStatus, N as AddMemberVerdict, Q as BackupCheckFailure, R as BufferOverflow, V as Bytes, W as CatchupSnapshotEntry, X as ConversationRemoval, Y as ConversationUpdate, Z as DeviceInfo, _ as DeviceRemovalFailure, D as DiscoveredDevice, $ as ExternalCommitAnswer, a0 as ExternalCommitPosted, a1 as HistoryAppEvent, a2 as Hlc, a3 as HoleReason, a4 as JournalFullAt, a5 as LogAck, a6 as LogGap, a7 as MessageKind, a8 as OverflowReason, a9 as SealedGroupInfoRow, aa as SealedGroupInfoUpload, ab as SealedGroupInfoWrap, ac as SealingStatementRow, ad as SelfAdmission, ae as SelfAdmissionState, af as SelfAdmitRefusal, ag as SelfAdmitWait, ah as SenderRole, ai as StrandReason, aj as StrandedConversation, ak as WelcomeFailure, al as WelcomeFailureReason } from './types-
|
|
1
|
+
import { S as Storage, M as MessageEnvelope, T as Transport, E as ExpectedOwner, C as ConversationId, K as KeyPackageEntry, A as AddMembersReport, a as DeviceId, U as UserId, b as ConversationMeta, c as DeviceReauthProof, d as DeviceLinkApproval, e as DeviceLinkPossession, L as LinkingTicketV3, f as CommitInDoubt, g as MemberInfo, h as ConversationPolicy, I as IncomingMessage, F as FetchedSealedGroupInfo, i as SelfAdmitResult, j as SelfAdmitManyEntry, k as SequencedEnvelope, l as ApplyBatchResult, m as SyncStepResult, n as LogPosition, o as LogHole, p as LogHead, P as PendingApply, q as CatchupSnapshotView, r as CatchupAppEvent, s as LinkGeneration, t as LinkedDevice, B as BackupPhraseCheck, H as HistoryDeliveryKeyStatement, u as HistoryBundle, O as OpenedHistory, v as HistoryShipDecision, w as AdmitChatEntry, x as AdmitChatOutcome, y as DeviceRemovalReport, z as ExportedSecret, G as MessageBatchMeta } from './types-D8fIp-_0.js';
|
|
2
|
+
export { J as AddMemberStatus, N as AddMemberVerdict, Q as BackupCheckFailure, R as BufferOverflow, V as Bytes, W as CatchupSnapshotEntry, X as ConversationRemoval, Y as ConversationUpdate, Z as DeviceInfo, _ as DeviceRemovalFailure, D as DiscoveredDevice, $ as ExternalCommitAnswer, a0 as ExternalCommitPosted, a1 as HistoryAppEvent, a2 as Hlc, a3 as HoleReason, a4 as JournalFullAt, a5 as LogAck, a6 as LogGap, a7 as MessageKind, a8 as OverflowReason, a9 as SealedGroupInfoRow, aa as SealedGroupInfoUpload, ab as SealedGroupInfoWrap, ac as SealingStatementRow, ad as SelfAdmission, ae as SelfAdmissionState, af as SelfAdmitRefusal, ag as SelfAdmitWait, ah as SenderRole, ai as StrandReason, aj as StrandedConversation, ak as WelcomeFailure, al as WelcomeFailureReason } from './types-D8fIp-_0.js';
|
|
3
3
|
export { IndexedDbStorage } from './storage/indexeddb.js';
|
|
4
4
|
export { WebSocketTransport } from './transport/websocket.js';
|
|
5
5
|
export { MAX_PREVIEW_PREREQUISITES, NotificationPreviewOptions, NotificationPreviewSession, openNotificationPreview } from './notification-preview.js';
|
|
@@ -23,6 +23,25 @@ interface NewAccountDevice {
|
|
|
23
23
|
statement: SealingStatement;
|
|
24
24
|
deviceSigningSecretKey: Uint8Array;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* What `AccountSetup.prepareDeviceKey` answers: the device id (SHA-256 of the
|
|
28
|
+
* public key) and the public key a sign-in BY CODE names, and the device key
|
|
29
|
+
* for the host's protected store. `deviceSigningSecretKey` is a secret: store
|
|
30
|
+
* it BEFORE any request names the key, never log it.
|
|
31
|
+
*/
|
|
32
|
+
interface PreparedDeviceKey {
|
|
33
|
+
deviceId: Uint8Array;
|
|
34
|
+
devicePublicKey: Uint8Array;
|
|
35
|
+
deviceSigningSecretKey: Uint8Array;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* What `AccountSetup.deviceStartCheck` answers (ruling V904): what a start from
|
|
39
|
+
* the device record would answer on this store. `startable`: the store holds a
|
|
40
|
+
* device record and its device key (if it holds one yet) is the record's.
|
|
41
|
+
* `no-device-record`: set up, link or restore. `device-key-mismatch`: the
|
|
42
|
+
* store's device key, or the expected device id, is not the record's.
|
|
43
|
+
*/
|
|
44
|
+
type DeviceStartCheck = "startable" | "no-device-record" | "device-key-mismatch";
|
|
26
45
|
interface AccountBackupParts {
|
|
27
46
|
rootPart: Uint8Array;
|
|
28
47
|
statePart: Uint8Array;
|
|
@@ -234,6 +253,30 @@ declare class AccountSetup {
|
|
|
234
253
|
identityState: string | undefined;
|
|
235
254
|
persistentStorage?: boolean;
|
|
236
255
|
}): Promise<NewAccountDevice>;
|
|
256
|
+
/**
|
|
257
|
+
* THE PREPARED DEVICE KEY (rulings V895 to V900, V913, V965): the device key
|
|
258
|
+
* a sign-in BY CODE names on a store with no device record, before the
|
|
259
|
+
* account exists. The SDK draws it (no argument is a key), keeps it in one
|
|
260
|
+
* row of this store and answers it; a repeat answers the SAME key, and two
|
|
261
|
+
* tabs that call at once answer one key (the origin's account lock).
|
|
262
|
+
* `createAccount`, the in-memory session and `MessagingClient.beginDeviceLink`
|
|
263
|
+
* then make the device with that key; a restore or a take-back never uses
|
|
264
|
+
* it. Store the secret BEFORE any request names the key. Refusals:
|
|
265
|
+
* `account-already-set-up` (the store holds a device), `rotation-in-progress`,
|
|
266
|
+
* `device-key-held-by-link` (a link was begun in this slot: offer "Finish
|
|
267
|
+
* linking" or "Start over", never a retry), `prepared-key-mismatch`.
|
|
268
|
+
*/
|
|
269
|
+
prepareDeviceKey(): Promise<PreparedDeviceKey>;
|
|
270
|
+
/** Delete a FREE prepared device key and nothing else; answers whether a
|
|
271
|
+
* row was deleted. Log the key's session out FIRST, and delete the host's
|
|
272
|
+
* own copy of the secret last. Refuses as `prepareDeviceKey` does. */
|
|
273
|
+
discardPreparedDeviceKey(): Promise<boolean>;
|
|
274
|
+
/** THE PREDICATE (ruling V904): what a start from the device record would
|
|
275
|
+
* answer on this store, as a typed value. It starts nothing, writes
|
|
276
|
+
* nothing and sends nothing. `expectedDeviceId` is the PUBLIC device id
|
|
277
|
+
* the host keeps, if it keeps one. Decide stop or retry on the answer,
|
|
278
|
+
* never on the words of an error. */
|
|
279
|
+
deviceStartCheck(expectedDeviceId?: Uint8Array): Promise<DeviceStartCheck>;
|
|
237
280
|
/** Whether the slot holds the pending root this device expects (rule R32).
|
|
238
281
|
* No prompt, no read of the seed. */
|
|
239
282
|
pendingStatus(slot: string): Promise<PendingRootStatus>;
|
|
@@ -357,7 +400,10 @@ declare class AccountSetup {
|
|
|
357
400
|
* Begin a set-up session whose root is in memory only (rule R34 a): for the
|
|
358
401
|
* person who makes the backup during set-up. One session per object; it
|
|
359
402
|
* lives in the Worker until `sessionFinish`, `sessionKeepAsPending` or
|
|
360
|
-
* `close`.
|
|
403
|
+
* `close`. It begins ON THIS STORE (read, nothing written): the session's
|
|
404
|
+
* device is made for the store's free prepared device key, when
|
|
405
|
+
* `prepareDeviceKey` made one. `device-key-held-by-link`: a link was begun
|
|
406
|
+
* in this slot.
|
|
361
407
|
*/
|
|
362
408
|
beginInMemory(identityState: string | undefined): Promise<void>;
|
|
363
409
|
/** The session's backup. */
|
|
@@ -653,9 +699,11 @@ declare class MessagingClient {
|
|
|
653
699
|
*/
|
|
654
700
|
private metaCache;
|
|
655
701
|
/**
|
|
656
|
-
*
|
|
657
|
-
* to the worker at once, frames that arrive while that batch is
|
|
658
|
-
* go out as ONE `processSequencedBatch` when it returns
|
|
702
|
+
* ONE lane of sequenced live frames for every conversation: the first
|
|
703
|
+
* frame goes to the worker at once, frames that arrive while that batch is
|
|
704
|
+
* in flight go out as ONE `processSequencedBatch` when it returns, in
|
|
705
|
+
* arrival order. Rows the engine did not take (`notTaken`) stay in the
|
|
706
|
+
* lane and are handed again after the next `confirmApplied`. See
|
|
659
707
|
* {@link dispatchIncoming}.
|
|
660
708
|
*/
|
|
661
709
|
private readonly coalescer;
|
|
@@ -907,10 +955,14 @@ declare class MessagingClient {
|
|
|
907
955
|
* position, holds it ahead of a hole and drops it at or below what was
|
|
908
956
|
* applied, whatever order it arrived in. What it needs is BATCHING: one
|
|
909
957
|
* MLS checkpoint and one host transaction per burst instead of one per
|
|
910
|
-
* frame. So the first frame
|
|
911
|
-
*
|
|
912
|
-
* accumulate and go out as ONE `processSequencedBatch` when it returns
|
|
913
|
-
*
|
|
958
|
+
* frame. So the first frame goes to the worker at once as a batch of one,
|
|
959
|
+
* and frames of ANY conversation that arrive while that batch is in flight
|
|
960
|
+
* accumulate and go out as ONE `processSequencedBatch` when it returns, in
|
|
961
|
+
* arrival order (one lane for all conversations: a catch-up of 200
|
|
962
|
+
* conversations is about 20 Worker calls, not 400); no timer ever delays a
|
|
963
|
+
* frame. Rows the engine did not take because the pending-apply journal
|
|
964
|
+
* had no room (`notTaken`) stay in the lane, in order, and are handed
|
|
965
|
+
* again after the next `confirmApplied`. Own-device echoes are NOT dropped on this
|
|
914
966
|
* path: the core advances the position past them without touching MLS,
|
|
915
967
|
* and dropping one would leave a hole the next frame reports as a gap. A
|
|
916
968
|
* sequenced frame at `serverSeq` 0 is a legacy frame in a wrapper and
|
|
@@ -922,10 +974,12 @@ declare class MessagingClient {
|
|
|
922
974
|
/** The actual routing, run inside the per-conversation chain. */
|
|
923
975
|
private dispatchIncomingOrdered;
|
|
924
976
|
/**
|
|
925
|
-
* One coalesced batch of live frames
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
*
|
|
977
|
+
* One coalesced batch of live frames, of any number of conversations.
|
|
978
|
+
* Answers the indexes of the rows the engine did not take (the journal
|
|
979
|
+
* had no room): the lane keeps those and hands them again after the next
|
|
980
|
+
* `confirmApplied`. A rejection goes to the lane, which hands a refused
|
|
981
|
+
* batch again one conversation at a time; `dispatchIncoming` logs what
|
|
982
|
+
* still fails at debug and resolves.
|
|
929
983
|
*/
|
|
930
984
|
private applyLiveBatch;
|
|
931
985
|
/** Start a fill for every gap a batch reported; each is single-flight. */
|
|
@@ -2096,4 +2150,4 @@ declare function emulateSendBatch(transport: Pick<Transport, "send">, envelopes:
|
|
|
2096
2150
|
* server error code rides along for diagnostics. */
|
|
2097
2151
|
declare function describeTransportError(e: unknown): string;
|
|
2098
2152
|
|
|
2099
|
-
export { type AccountBackupParts, AccountSetup, AccountSetupClosedError, type AccountSetupConfig, AddMembersReport, AdmitChatEntry, AdmitChatOutcome, type AdoptedGeneration, ApplyBatchResult, BATCH_PARTIAL_PREFIX, BackupPhraseCheck, CONTENT_TYPE_CBOR, CONTENT_TYPE_CBOR_LEGACY_V1, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_LEGACY_V1, CatchupAppEvent, CatchupSnapshotView, type ClientConfig, CommitInDoubt, type Conversation, ConversationId, ConversationMeta, ConversationPolicy, DEVICE_GROUP_BEHIND_PREFIX, DeviceGroupBehindError, DeviceId, DeviceLinkApproval, type DeviceLinkBegun, type DeviceLinkClientConfig, DeviceLinkPossession, DeviceReauthProof, type DeviceRecordClientConfig, DeviceRemovalReport, EphemeralWorkerError, ExpectedOwner, ExportedSecret, FetchedSealedGroupInfo, HISTORY_REFUSED_PREFIX, HPKE_PQ_ENC_BYTES, HPKE_PQ_PUBLIC_KEY_BYTES, HistoryBundle, HistoryDeliveryKeyStatement, type HistoryRefusalReason, HistoryRefusedError, HistoryShipDecision, IncomingMessage, JOURNAL_FULL_PREFIX, JournalFullError, KeyPackageEntry, LINK_ADD_REFUSED_PREFIX, LINK_CHAIN_TOO_DEEP_PREFIX, LINK_COMMITMENT_MISMATCH_PREFIX, LinkAddRefusedError, LinkChainTooDeepError, type LinkCommitment, LinkCommitmentMismatchError, type LinkExpected, LinkGeneration, LinkedDevice, LinkingTicketV3, LogHead, LogHole, LogPosition, MemberInfo, MessageBatchMeta, MessageEnvelope, MessagingClient, MessagingClientClosedError, NOT_PERMITTED_PREFIX, type NewAccountDevice, NotPermittedError, OpenedHistory, PING_WIRE_CONTRACT_HEADER, PING_WIRE_CONTRACT_HEADER_VALUE, PING_WIRE_CONTRACT_VERSION, PendingApply, type PendingRootStatus, type PendingRotation, READ_ONLY_PREFIX, ReadOnlyError, type RestoreJoined, type RestoreOpened, type RotationAnswer, type RotationBuild, type RotationBuilt, type RotationKeptRefusal, type RotationOutcome, type RotationPhase, type RotationPlan, type RotationRecordState, type RotationRequest, type RotationStart, type RotationStartDevice, SENDER_MISMATCH_PREFIX, STALE_GENERATION_PREFIX, STORE_MOVED_PREFIX, type SealingStatement, SelfAdmitManyEntry, SelfAdmitResult, SenderMismatchError, SequencedEnvelope, StaleGenerationError, type StateOpened, type StateRefreshed, Storage, StoreMovedError, SyncStepResult, Transport, UserId, ValidationError, type VerifiedLinkHandshakeInfo, WELCOME_MISLABELED_PREFIX, WELCOME_WAITS_PREFIX, WIRE_VERSION_MIN_ACCEPTED, WelcomeMislabeledError, WelcomeWaitsError, accountRefusalCode, backupPhraseCheckFromWire, describeTransportError, emulateSendBatch, isDeviceGroupBehindError, isHistoryRefusedError, isJournalFullError, isLinkAddRefusedError, isLinkChainTooDeepError, isLinkCommitmentMismatchError, isNotPermittedError, isReadOnlyError, isSenderMismatchError, isStaleGenerationError, isStoreMovedError, isWelcomeMislabeledError, isWelcomeWaitsError, negotiates, notPermittedRule, validate, verifyApplicationContentHash };
|
|
2153
|
+
export { type AccountBackupParts, AccountSetup, AccountSetupClosedError, type AccountSetupConfig, AddMembersReport, AdmitChatEntry, AdmitChatOutcome, type AdoptedGeneration, ApplyBatchResult, BATCH_PARTIAL_PREFIX, BackupPhraseCheck, CONTENT_TYPE_CBOR, CONTENT_TYPE_CBOR_LEGACY_V1, CONTENT_TYPE_JSON, CONTENT_TYPE_JSON_LEGACY_V1, CatchupAppEvent, CatchupSnapshotView, type ClientConfig, CommitInDoubt, type Conversation, ConversationId, ConversationMeta, ConversationPolicy, DEVICE_GROUP_BEHIND_PREFIX, DeviceGroupBehindError, DeviceId, DeviceLinkApproval, type DeviceLinkBegun, type DeviceLinkClientConfig, DeviceLinkPossession, DeviceReauthProof, type DeviceRecordClientConfig, DeviceRemovalReport, type DeviceStartCheck, EphemeralWorkerError, ExpectedOwner, ExportedSecret, FetchedSealedGroupInfo, HISTORY_REFUSED_PREFIX, HPKE_PQ_ENC_BYTES, HPKE_PQ_PUBLIC_KEY_BYTES, HistoryBundle, HistoryDeliveryKeyStatement, type HistoryRefusalReason, HistoryRefusedError, HistoryShipDecision, IncomingMessage, JOURNAL_FULL_PREFIX, JournalFullError, KeyPackageEntry, LINK_ADD_REFUSED_PREFIX, LINK_CHAIN_TOO_DEEP_PREFIX, LINK_COMMITMENT_MISMATCH_PREFIX, LinkAddRefusedError, LinkChainTooDeepError, type LinkCommitment, LinkCommitmentMismatchError, type LinkExpected, LinkGeneration, LinkedDevice, LinkingTicketV3, LogHead, LogHole, LogPosition, MemberInfo, MessageBatchMeta, MessageEnvelope, MessagingClient, MessagingClientClosedError, NOT_PERMITTED_PREFIX, type NewAccountDevice, NotPermittedError, OpenedHistory, PING_WIRE_CONTRACT_HEADER, PING_WIRE_CONTRACT_HEADER_VALUE, PING_WIRE_CONTRACT_VERSION, PendingApply, type PendingRootStatus, type PendingRotation, type PreparedDeviceKey, READ_ONLY_PREFIX, ReadOnlyError, type RestoreJoined, type RestoreOpened, type RotationAnswer, type RotationBuild, type RotationBuilt, type RotationKeptRefusal, type RotationOutcome, type RotationPhase, type RotationPlan, type RotationRecordState, type RotationRequest, type RotationStart, type RotationStartDevice, SENDER_MISMATCH_PREFIX, STALE_GENERATION_PREFIX, STORE_MOVED_PREFIX, type SealingStatement, SelfAdmitManyEntry, SelfAdmitResult, SenderMismatchError, SequencedEnvelope, StaleGenerationError, type StateOpened, type StateRefreshed, Storage, StoreMovedError, SyncStepResult, Transport, UserId, ValidationError, type VerifiedLinkHandshakeInfo, WELCOME_MISLABELED_PREFIX, WELCOME_WAITS_PREFIX, WIRE_VERSION_MIN_ACCEPTED, WelcomeMislabeledError, WelcomeWaitsError, accountRefusalCode, backupPhraseCheckFromWire, describeTransportError, emulateSendBatch, isDeviceGroupBehindError, isHistoryRefusedError, isJournalFullError, isLinkAddRefusedError, isLinkChainTooDeepError, isLinkCommitmentMismatchError, isNotPermittedError, isReadOnlyError, isSenderMismatchError, isStaleGenerationError, isStoreMovedError, isWelcomeMislabeledError, isWelcomeWaitsError, negotiates, notPermittedRule, validate, verifyApplicationContentHash };
|
package/dist/index.js
CHANGED
|
@@ -90,9 +90,10 @@ var GapFiller = class {
|
|
|
90
90
|
// src/inbound-coalescer.ts
|
|
91
91
|
var InboundCoalescer = class {
|
|
92
92
|
/**
|
|
93
|
-
* @param apply Applies one batch. A rejection
|
|
94
|
-
*
|
|
95
|
-
*
|
|
93
|
+
* @param apply Applies one batch. A rejection of a batch that carries
|
|
94
|
+
* several conversations hands it again one conversation at a time; the
|
|
95
|
+
* frames of a conversation whose own batch is rejected settle with the
|
|
96
|
+
* error and the lane moves on, so one bad batch cannot wedge it.
|
|
96
97
|
* @param maxBatch Upper bound on frames per batch. A burst larger than
|
|
97
98
|
* this goes out as consecutive batches of at most `maxBatch`, so a
|
|
98
99
|
* flood cannot turn into one unbounded wasm call.
|
|
@@ -103,57 +104,98 @@ var InboundCoalescer = class {
|
|
|
103
104
|
}
|
|
104
105
|
apply;
|
|
105
106
|
maxBatch;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
queue = [];
|
|
108
|
+
running = false;
|
|
109
|
+
/** The last batch left rows for want of room and no confirm came since. */
|
|
110
|
+
waitingForRoom = false;
|
|
111
|
+
/** Confirms seen, so that one landing while a batch is in flight is not lost. */
|
|
112
|
+
confirms = 0;
|
|
113
|
+
/**
|
|
114
|
+
* Queue a frame of the conversation `key`. Resolves when the batch that
|
|
115
|
+
* carried it has been applied (rejects if that batch failed), so a
|
|
116
|
+
* transport that awaits the dispatch to ack a watermark still sees the
|
|
117
|
+
* truth: a frame the engine did not take stays pending until it is.
|
|
111
118
|
*/
|
|
112
119
|
push(key, item) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
return new Promise((resolve, reject) => {
|
|
121
|
+
this.queue.push({ key, item, resolve, reject });
|
|
122
|
+
this.pump();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The host confirmed messages (`confirmApplied` returned): the journal has
|
|
127
|
+
* room again, and the frames kept for want of it are handed now.
|
|
128
|
+
*/
|
|
129
|
+
roomFreed() {
|
|
130
|
+
this.confirms += 1;
|
|
131
|
+
if (this.waitingForRoom) {
|
|
132
|
+
this.waitingForRoom = false;
|
|
133
|
+
this.pump();
|
|
119
134
|
}
|
|
120
|
-
const fresh = { queued: [], waiters: [] };
|
|
121
|
-
this.lanes.set(key, fresh);
|
|
122
|
-
return this.run(key, fresh, [item], []);
|
|
123
135
|
}
|
|
124
|
-
/**
|
|
136
|
+
/** Batches in flight: 0 or 1 (diagnostics / tests). */
|
|
125
137
|
get inFlight() {
|
|
126
|
-
return this.
|
|
138
|
+
return this.running ? 1 : 0;
|
|
127
139
|
}
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
/** Frames waiting in the lane (diagnostics / tests). */
|
|
141
|
+
get queued() {
|
|
142
|
+
return this.queue.length;
|
|
143
|
+
}
|
|
144
|
+
pump() {
|
|
145
|
+
if (this.running || this.waitingForRoom || this.queue.length === 0) return;
|
|
146
|
+
this.running = true;
|
|
147
|
+
const batch = this.queue.splice(0, this.maxBatch);
|
|
148
|
+
void this.run(batch).then(() => {
|
|
149
|
+
this.running = false;
|
|
150
|
+
this.pump();
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async run(batch) {
|
|
154
|
+
const confirmsAtHand = this.confirms;
|
|
155
|
+
let left = [];
|
|
130
156
|
try {
|
|
131
|
-
|
|
157
|
+
left = await this.hand(batch);
|
|
132
158
|
} catch (e) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
139
|
-
(e) => {
|
|
140
|
-
for (const w of waiters) w.reject(e);
|
|
159
|
+
const groups = /* @__PURE__ */ new Map();
|
|
160
|
+
for (const entry of batch) {
|
|
161
|
+
const group = groups.get(entry.key);
|
|
162
|
+
if (group === void 0) groups.set(entry.key, [entry]);
|
|
163
|
+
else group.push(entry);
|
|
141
164
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
165
|
+
if (groups.size <= 1) {
|
|
166
|
+
for (const entry of batch) entry.reject(e);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
for (const group of groups.values()) {
|
|
170
|
+
try {
|
|
171
|
+
left.push(...await this.hand(group));
|
|
172
|
+
} catch (error) {
|
|
173
|
+
for (const entry of group) entry.reject(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const order = new Map(batch.map((entry, index) => [entry, index]));
|
|
177
|
+
left.sort((a, b) => (order.get(a) ?? 0) - (order.get(b) ?? 0));
|
|
178
|
+
}
|
|
179
|
+
if (left.length > 0) {
|
|
180
|
+
this.queue.unshift(...left);
|
|
181
|
+
this.waitingForRoom = this.confirms === confirmsAtHand;
|
|
182
|
+
}
|
|
148
183
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
184
|
+
/** Hand `entries`; settle the taken ones; return the ones not taken, in order. */
|
|
185
|
+
async hand(entries) {
|
|
186
|
+
let attempt;
|
|
187
|
+
try {
|
|
188
|
+
attempt = this.apply(entries.map((entry) => entry.item));
|
|
189
|
+
} catch (e) {
|
|
190
|
+
attempt = Promise.reject(e);
|
|
153
191
|
}
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
192
|
+
const notTaken = new Set(await attempt ?? []);
|
|
193
|
+
const back = [];
|
|
194
|
+
entries.forEach((entry, index) => {
|
|
195
|
+
if (notTaken.has(index)) back.push(entry);
|
|
196
|
+
else entry.resolve();
|
|
197
|
+
});
|
|
198
|
+
return back;
|
|
157
199
|
}
|
|
158
200
|
};
|
|
159
201
|
|
|
@@ -287,7 +329,11 @@ function outcomesFromWire(r) {
|
|
|
287
329
|
holes: (r.holes ?? []).map(logHoleFromWire),
|
|
288
330
|
acks: (r.acks ?? []).map(logAckFromWire),
|
|
289
331
|
// Absent from an older wasm, which never stopped for the journal.
|
|
290
|
-
journalFull: (r.journal_full ?? []).map(journalFullAtFromWire)
|
|
332
|
+
journalFull: (r.journal_full ?? []).map(journalFullAtFromWire),
|
|
333
|
+
// Absent from an older wasm, which did not state its room: 0, so a host
|
|
334
|
+
// that cuts its hand by the room waits for a confirm instead of guessing.
|
|
335
|
+
journalRoomRows: Number(r.journal_room_rows ?? 0),
|
|
336
|
+
journalRoomBytes: Number(r.journal_room_bytes ?? 0)
|
|
291
337
|
};
|
|
292
338
|
}
|
|
293
339
|
function applyBatchResultFromWire(r) {
|
|
@@ -301,6 +347,8 @@ function applyBatchResultFromWire(r) {
|
|
|
301
347
|
joined: r.joined,
|
|
302
348
|
updated: r.updated.map(conversationUpdateFromWire),
|
|
303
349
|
...outcomesFromWire(r),
|
|
350
|
+
// Absent from an older wasm, which named no row: nothing to hand again.
|
|
351
|
+
notTaken: (r.not_taken ?? []).map(Number),
|
|
304
352
|
// Present only when the SDK says it: said once, with the batch at which
|
|
305
353
|
// the anchor record was seen to change.
|
|
306
354
|
...r.state_backup_owed === true ? { stateBackupOwed: true } : {}
|
|
@@ -690,6 +738,50 @@ var AccountSetup = class _AccountSetup {
|
|
|
690
738
|
storageFeatures: storageFeaturesOf(this.storage)
|
|
691
739
|
});
|
|
692
740
|
}
|
|
741
|
+
/**
|
|
742
|
+
* THE PREPARED DEVICE KEY (rulings V895 to V900, V913, V965): the device key
|
|
743
|
+
* a sign-in BY CODE names on a store with no device record, before the
|
|
744
|
+
* account exists. The SDK draws it (no argument is a key), keeps it in one
|
|
745
|
+
* row of this store and answers it; a repeat answers the SAME key, and two
|
|
746
|
+
* tabs that call at once answer one key (the origin's account lock).
|
|
747
|
+
* `createAccount`, the in-memory session and `MessagingClient.beginDeviceLink`
|
|
748
|
+
* then make the device with that key; a restore or a take-back never uses
|
|
749
|
+
* it. Store the secret BEFORE any request names the key. Refusals:
|
|
750
|
+
* `account-already-set-up` (the store holds a device), `rotation-in-progress`,
|
|
751
|
+
* `device-key-held-by-link` (a link was begun in this slot: offer "Finish
|
|
752
|
+
* linking" or "Start over", never a retry), `prepared-key-mismatch`.
|
|
753
|
+
*/
|
|
754
|
+
prepareDeviceKey() {
|
|
755
|
+
return this.call({
|
|
756
|
+
kind: "prepareDeviceKey",
|
|
757
|
+
id: this.nextId++,
|
|
758
|
+
nowMs: this.now(),
|
|
759
|
+
storageFeatures: storageFeaturesOf(this.storage)
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
/** Delete a FREE prepared device key and nothing else; answers whether a
|
|
763
|
+
* row was deleted. Log the key's session out FIRST, and delete the host's
|
|
764
|
+
* own copy of the secret last. Refuses as `prepareDeviceKey` does. */
|
|
765
|
+
discardPreparedDeviceKey() {
|
|
766
|
+
return this.call({
|
|
767
|
+
kind: "discardPreparedDeviceKey",
|
|
768
|
+
id: this.nextId++,
|
|
769
|
+
storageFeatures: storageFeaturesOf(this.storage)
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
/** THE PREDICATE (ruling V904): what a start from the device record would
|
|
773
|
+
* answer on this store, as a typed value. It starts nothing, writes
|
|
774
|
+
* nothing and sends nothing. `expectedDeviceId` is the PUBLIC device id
|
|
775
|
+
* the host keeps, if it keeps one. Decide stop or retry on the answer,
|
|
776
|
+
* never on the words of an error. */
|
|
777
|
+
deviceStartCheck(expectedDeviceId) {
|
|
778
|
+
return this.call({
|
|
779
|
+
kind: "deviceStartCheck",
|
|
780
|
+
id: this.nextId++,
|
|
781
|
+
expectedDeviceId,
|
|
782
|
+
storageFeatures: storageFeaturesOf(this.storage)
|
|
783
|
+
});
|
|
784
|
+
}
|
|
693
785
|
/** Whether the slot holds the pending root this device expects (rule R32).
|
|
694
786
|
* No prompt, no read of the seed. */
|
|
695
787
|
pendingStatus(slot) {
|
|
@@ -925,14 +1017,18 @@ var AccountSetup = class _AccountSetup {
|
|
|
925
1017
|
* Begin a set-up session whose root is in memory only (rule R34 a): for the
|
|
926
1018
|
* person who makes the backup during set-up. One session per object; it
|
|
927
1019
|
* lives in the Worker until `sessionFinish`, `sessionKeepAsPending` or
|
|
928
|
-
* `close`.
|
|
1020
|
+
* `close`. It begins ON THIS STORE (read, nothing written): the session's
|
|
1021
|
+
* device is made for the store's free prepared device key, when
|
|
1022
|
+
* `prepareDeviceKey` made one. `device-key-held-by-link`: a link was begun
|
|
1023
|
+
* in this slot.
|
|
929
1024
|
*/
|
|
930
1025
|
async beginInMemory(identityState) {
|
|
931
1026
|
await this.call({
|
|
932
1027
|
kind: "beginAccountSetupInMemory",
|
|
933
1028
|
id: this.nextId++,
|
|
934
1029
|
identityState,
|
|
935
|
-
nowMs: this.now()
|
|
1030
|
+
nowMs: this.now(),
|
|
1031
|
+
storageFeatures: storageFeaturesOf(this.storage)
|
|
936
1032
|
});
|
|
937
1033
|
}
|
|
938
1034
|
/** The session's backup. */
|
|
@@ -1175,13 +1271,15 @@ var MessagingClient = class _MessagingClient {
|
|
|
1175
1271
|
*/
|
|
1176
1272
|
metaCache = /* @__PURE__ */ new Map();
|
|
1177
1273
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
* to the worker at once, frames that arrive while that batch is
|
|
1180
|
-
* go out as ONE `processSequencedBatch` when it returns
|
|
1274
|
+
* ONE lane of sequenced live frames for every conversation: the first
|
|
1275
|
+
* frame goes to the worker at once, frames that arrive while that batch is
|
|
1276
|
+
* in flight go out as ONE `processSequencedBatch` when it returns, in
|
|
1277
|
+
* arrival order. Rows the engine did not take (`notTaken`) stay in the
|
|
1278
|
+
* lane and are handed again after the next `confirmApplied`. See
|
|
1181
1279
|
* {@link dispatchIncoming}.
|
|
1182
1280
|
*/
|
|
1183
1281
|
coalescer = new InboundCoalescer(
|
|
1184
|
-
(
|
|
1282
|
+
(items) => this.applyLiveBatch(items)
|
|
1185
1283
|
);
|
|
1186
1284
|
/** Single-flight gap fills, one `syncConversationStep` loop per conversation. */
|
|
1187
1285
|
gapFiller = new GapFiller();
|
|
@@ -1790,10 +1888,14 @@ var MessagingClient = class _MessagingClient {
|
|
|
1790
1888
|
* position, holds it ahead of a hole and drops it at or below what was
|
|
1791
1889
|
* applied, whatever order it arrived in. What it needs is BATCHING: one
|
|
1792
1890
|
* MLS checkpoint and one host transaction per burst instead of one per
|
|
1793
|
-
* frame. So the first frame
|
|
1794
|
-
*
|
|
1795
|
-
* accumulate and go out as ONE `processSequencedBatch` when it returns
|
|
1796
|
-
*
|
|
1891
|
+
* frame. So the first frame goes to the worker at once as a batch of one,
|
|
1892
|
+
* and frames of ANY conversation that arrive while that batch is in flight
|
|
1893
|
+
* accumulate and go out as ONE `processSequencedBatch` when it returns, in
|
|
1894
|
+
* arrival order (one lane for all conversations: a catch-up of 200
|
|
1895
|
+
* conversations is about 20 Worker calls, not 400); no timer ever delays a
|
|
1896
|
+
* frame. Rows the engine did not take because the pending-apply journal
|
|
1897
|
+
* had no room (`notTaken`) stay in the lane, in order, and are handed
|
|
1898
|
+
* again after the next `confirmApplied`. Own-device echoes are NOT dropped on this
|
|
1797
1899
|
* path: the core advances the position past them without touching MLS,
|
|
1798
1900
|
* and dropping one would leave a hole the next frame reports as a gap. A
|
|
1799
1901
|
* sequenced frame at `serverSeq` 0 is a legacy frame in a wrapper and
|
|
@@ -1802,7 +1904,9 @@ var MessagingClient = class _MessagingClient {
|
|
|
1802
1904
|
dispatchIncoming(frame) {
|
|
1803
1905
|
if (isSequencedFrame(frame)) {
|
|
1804
1906
|
if (frame.serverSeq > 0) {
|
|
1805
|
-
return this.coalescer.push(hexOf(frame.envelope.conversation_id), frame)
|
|
1907
|
+
return this.coalescer.push(hexOf(frame.envelope.conversation_id), frame).catch((e) => {
|
|
1908
|
+
if (typeof console !== "undefined") console.debug("[ping-sdk] sequenced batch failed:", errorKind(e));
|
|
1909
|
+
});
|
|
1806
1910
|
}
|
|
1807
1911
|
return this.dispatchLegacy(frame.envelope);
|
|
1808
1912
|
}
|
|
@@ -1846,17 +1950,16 @@ var MessagingClient = class _MessagingClient {
|
|
|
1846
1950
|
}
|
|
1847
1951
|
}
|
|
1848
1952
|
/**
|
|
1849
|
-
* One coalesced batch of live frames
|
|
1850
|
-
*
|
|
1851
|
-
*
|
|
1852
|
-
*
|
|
1953
|
+
* One coalesced batch of live frames, of any number of conversations.
|
|
1954
|
+
* Answers the indexes of the rows the engine did not take (the journal
|
|
1955
|
+
* had no room): the lane keeps those and hands them again after the next
|
|
1956
|
+
* `confirmApplied`. A rejection goes to the lane, which hands a refused
|
|
1957
|
+
* batch again one conversation at a time; `dispatchIncoming` logs what
|
|
1958
|
+
* still fails at debug and resolves.
|
|
1853
1959
|
*/
|
|
1854
1960
|
async applyLiveBatch(items) {
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
} catch (e) {
|
|
1858
|
-
if (typeof console !== "undefined") console.debug("[ping-sdk] sequenced batch failed:", errorKind(e));
|
|
1859
|
-
}
|
|
1961
|
+
const result = await this.processSequencedBatch(items);
|
|
1962
|
+
return result.notTaken;
|
|
1860
1963
|
}
|
|
1861
1964
|
/** Start a fill for every gap a batch reported; each is single-flight. */
|
|
1862
1965
|
scheduleGapFills(result) {
|
|
@@ -2562,6 +2665,7 @@ var MessagingClient = class _MessagingClient {
|
|
|
2562
2665
|
async confirmApplied(journalIds) {
|
|
2563
2666
|
if (journalIds.length === 0) return;
|
|
2564
2667
|
await this.call({ kind: "confirmApplied", id: this.nextId++, journalIds });
|
|
2668
|
+
this.coalescer.roomFreed();
|
|
2565
2669
|
}
|
|
2566
2670
|
/**
|
|
2567
2671
|
* The version 3 handshake payload this NEW device publishes: its own signing key,
|