p2party 0.14.2 → 0.14.7

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.
Files changed (126) hide show
  1. package/README.md +230 -30
  2. package/docs/getting-started.md +15 -0
  3. package/docs/protocol-v4-security.md +40 -0
  4. package/docs/references.md +28 -8
  5. package/docs/session-api.md +10 -2
  6. package/lib/api/signalingServerApi.d.ts +13 -2
  7. package/lib/api/webrtc/applyIceConfiguration.d.ts +9 -0
  8. package/lib/api/webrtc/dataChannelHandler.d.ts +10 -0
  9. package/lib/api/webrtc/deleteRoomData.d.ts +13 -0
  10. package/lib/api/webrtc/disconnectFromAllRoomsQuery.d.ts +2 -1
  11. package/lib/api/webrtc/disconnectFromRoomQuery.d.ts +2 -1
  12. package/lib/api/webrtc/disconnectQuery.d.ts +2 -1
  13. package/lib/api/webrtc/iceRepair.d.ts +3 -1
  14. package/lib/api/webrtc/index.d.ts +2 -1
  15. package/lib/api/webrtc/interfaces.d.ts +37 -0
  16. package/lib/api/webrtc/negotiationLock.d.ts +24 -0
  17. package/lib/api/webrtc/pendingOffer.d.ts +29 -0
  18. package/lib/api/webrtc/rebindDeadline.d.ts +61 -0
  19. package/lib/api/webrtc/remoteTransportChange.d.ts +142 -0
  20. package/lib/api/webrtc/retiredRemoteTransports.d.ts +70 -0
  21. package/lib/api/webrtc/roomEdgeBudget.d.ts +10 -0
  22. package/lib/api/webrtc/setDescriptionQuery.d.ts +8 -1
  23. package/lib/api/webrtc/settleOnClose.d.ts +36 -0
  24. package/lib/blindRendezvous/admissionInput.d.ts +11 -0
  25. package/lib/blindRendezvous/admissionPolicy.d.ts +217 -0
  26. package/lib/blindRendezvous/canonicalSchema.d.ts +139 -0
  27. package/lib/blindRendezvous/carrierEnvelope.d.ts +105 -0
  28. package/lib/blindRendezvous/coreReduce.d.ts +199 -0
  29. package/lib/blindRendezvous/derivations.d.ts +381 -0
  30. package/lib/blindRendezvous/identityHelloAdmission.d.ts +89 -0
  31. package/lib/blindRendezvous/identityHelloAdmissionPersistence.d.ts +133 -0
  32. package/lib/blindRendezvous/identityHelloHistoricalEvidence.d.ts +52 -0
  33. package/lib/blindRendezvous/identityHelloOpen.d.ts +167 -0
  34. package/lib/blindRendezvous/identityHelloTrial.d.ts +271 -0
  35. package/lib/blindRendezvous/localAdmissibleProject.d.ts +101 -0
  36. package/lib/blindRendezvous/localPresenceKeyBinding.d.ts +108 -0
  37. package/lib/blindRendezvous/localStableIdentityCustody.d.ts +46 -0
  38. package/lib/blindRendezvous/normativeKernel.d.ts +222 -0
  39. package/lib/blindRendezvous/operation.d.ts +137 -0
  40. package/lib/blindRendezvous/operationPayload.d.ts +134 -0
  41. package/lib/blindRendezvous/pairBootstrapSuite.d.ts +93 -0
  42. package/lib/blindRendezvous/pairCrypto.d.ts +122 -0
  43. package/lib/blindRendezvous/pairLedger.d.ts +154 -0
  44. package/lib/blindRendezvous/pairOpenBudget.d.ts +67 -0
  45. package/lib/blindRendezvous/pairOpenReservation.d.ts +157 -0
  46. package/lib/blindRendezvous/pairPlaintext.d.ts +240 -0
  47. package/lib/blindRendezvous/pairStepEnvelope.d.ts +60 -0
  48. package/lib/blindRendezvous/plannerState.d.ts +61 -0
  49. package/lib/blindRendezvous/projections.d.ts +71 -0
  50. package/lib/blindRendezvous/publicWindow.d.ts +330 -0
  51. package/lib/blindRendezvous/retainedOperationStore.d.ts +187 -0
  52. package/lib/blindRendezvous/roomInviteV2.d.ts +92 -0
  53. package/lib/blindRendezvous/roomPolicyV4.d.ts +90 -0
  54. package/lib/blindRendezvous/schemas.d.ts +221 -0
  55. package/lib/blindRendezvous/storeDescriptor.d.ts +160 -0
  56. package/lib/cryptography/aeadWasm.d.ts +18 -0
  57. package/lib/cryptography/byteInput.d.ts +12 -0
  58. package/lib/cryptography/carrierAead.d.ts +23 -0
  59. package/lib/cryptography/chacha20poly1305.d.ts +7 -0
  60. package/lib/cryptography/fips202.d.ts +10 -0
  61. package/lib/cryptography/hpke.d.ts +84 -0
  62. package/lib/cryptography/hpkeSuite.d.ts +39 -0
  63. package/lib/cryptography/hybridKem.d.ts +42 -0
  64. package/lib/cryptography/hybridKemSuite.d.ts +22 -0
  65. package/lib/cryptography/interfaces.d.ts +3 -0
  66. package/lib/cryptography/mlkem.d.ts +27 -1
  67. package/lib/cryptography/mnemonic.d.ts +65 -1
  68. package/lib/cryptography/ownedEd25519KeyMaterial.d.ts +27 -0
  69. package/lib/cryptography/webCryptoSha256.d.ts +20 -0
  70. package/lib/cryptography/x25519.d.ts +18 -0
  71. package/lib/cryptography/xchacha20poly1305.d.ts +7 -0
  72. package/lib/db/api.d.ts +6 -3
  73. package/lib/db/identityEd25519ClientBoundary.d.ts +13 -0
  74. package/lib/db/src/getDB.d.ts +2 -2
  75. package/lib/db/types.d.ts +52 -4
  76. package/lib/db.worker.js +1 -1
  77. package/lib/handlers/coverChannelRegistry.d.ts +22 -0
  78. package/lib/handlers/edgeTeardownFollowUp.d.ts +35 -0
  79. package/lib/handlers/handleChallenge.d.ts +2 -1
  80. package/lib/handlers/handleConnectToPeer.d.ts +1 -1
  81. package/lib/handlers/handleHandshake.d.ts +2 -6
  82. package/lib/handlers/handleSendMessage.d.ts +60 -7
  83. package/lib/handlers/handleWebSocketMessage.d.ts +1 -1
  84. package/lib/handlers/handshakeCore.d.ts +2 -7
  85. package/lib/handlers/handshakeFrame.d.ts +25 -0
  86. package/lib/handlers/ratchetGateWait.d.ts +13 -0
  87. package/lib/handlers/reconcile.d.ts +24 -0
  88. package/lib/handlers/requestRoom.d.ts +30 -0
  89. package/lib/handlers/roomResponse.d.ts +53 -0
  90. package/lib/index.d.ts +99 -12
  91. package/lib/index.js +1 -1
  92. package/lib/index.min.js +1 -1
  93. package/lib/index.mjs +1 -1
  94. package/lib/libcrypto.provenance.json +5 -5
  95. package/lib/libcrypto.wasm +0 -0
  96. package/lib/middleware/roomListenerMiddleware.d.ts +4 -1
  97. package/lib/reducers/commonSlice.d.ts +3 -2
  98. package/lib/reducers/keyPairSlice.d.ts +3 -6
  99. package/lib/reducers/roomSlice.d.ts +81 -5
  100. package/lib/reducers/signalingServerSlice.d.ts +3 -2
  101. package/lib/session.d.ts +6 -3
  102. package/lib/session.js +1 -1
  103. package/lib/session.mjs +1 -1
  104. package/lib/store.d.ts +4 -2
  105. package/lib/utils/constants.d.ts +12 -0
  106. package/lib/utils/correlationId.d.ts +4 -0
  107. package/lib/utils/identityRestore.d.ts +108 -0
  108. package/lib/utils/interfaces.d.ts +25 -6
  109. package/lib/utils/roomConnectAdmission.d.ts +15 -0
  110. package/lib/utils/roomLeaveCoordinator.d.ts +38 -0
  111. package/lib/utils/roomRequestCoordinator.d.ts +104 -0
  112. package/lib/utils/roomRosterReconciler.d.ts +83 -0
  113. package/lib/utils/sdpFingerprint.d.ts +6 -0
  114. package/lib/utils/signalingAttemptLifecycle.d.ts +33 -0
  115. package/lib/utils/signalingAuth.d.ts +21 -2
  116. package/lib/utils/signalingBounds.d.ts +6 -0
  117. package/lib/utils/signalingFrame.d.ts +21 -0
  118. package/lib/utils/signalingHeartbeatWatchdog.d.ts +45 -0
  119. package/lib/utils/signalingIngressQueue.d.ts +49 -0
  120. package/lib/utils/signalingPeerRequestDebouncer.d.ts +13 -0
  121. package/lib/utils/signalingRoomLifecycle.d.ts +7 -0
  122. package/lib/utils/signalingRoomOperationLifecycle.d.ts +14 -0
  123. package/lib/utils/signalingServerBoundary.d.ts +11 -0
  124. package/lib/utils/terminalSettlement.d.ts +53 -0
  125. package/lib/utils/transportIdentity.d.ts +5 -0
  126. package/package.json +1 -1
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Internal, pure Section 4.8 admission-policy semantics.
3
+ *
4
+ * This module deliberately does not implement `Admit()`, trusted snapshot or
5
+ * custody capture, provenance brands, pair opening/binding, effectful
6
+ * persistence, outbound-intent atomicity, or the pre-SDP runtime gate. Its
7
+ * canonical codecs only preserve already-validated structural values; decoding
8
+ * bytes does not make a lease trusted or current. Structural inputs are useful
9
+ * only after a future trusted constructor has obtained the same facts
10
+ * atomically. Nothing here may turn a caller-supplied authority availability
11
+ * bit, digest, or revocation list into trusted state.
12
+ *
13
+ * The helpers do own the deterministic policy order and lease arithmetic once
14
+ * those facts are available. This file is not exported from the package barrel.
15
+ */
16
+ import type { LibCrypto } from "../cryptography/libcrypto";
17
+ import type { CoreFaultV1, CoreRevocationFloorV1 } from "./coreReduce";
18
+ import type { AdmissionGrantV1 } from "./operationPayload";
19
+ import type { RoomPolicyV4 } from "./roomPolicyV4";
20
+ export type CanonicalBytes32SetV1 = readonly Uint8Array[];
21
+ export interface FrontendRoomControlsV1 {
22
+ readonly version: 1;
23
+ readonly policyGeneration: bigint;
24
+ readonly onlyConnectWithKnownPeers: boolean;
25
+ readonly allowedStableIdentityKeys: CanonicalBytes32SetV1;
26
+ readonly deniedStableIdentityKeys: CanonicalBytes32SetV1;
27
+ readonly deniedRoomIdentityCommitments: CanonicalBytes32SetV1;
28
+ }
29
+ export interface AuthorityWindowFaultV1 {
30
+ readonly logicalWindow: bigint;
31
+ readonly proofOperationIds: readonly Uint8Array[];
32
+ }
33
+ /**
34
+ * Structural policy projection only. A future private authority-view
35
+ * constructor must derive this from a branded atomic snapshot. This interface
36
+ * and its digest field do not establish provenance.
37
+ */
38
+ export interface AuthorityAdmissionPolicyViewV1 {
39
+ readonly version: 1;
40
+ readonly roomContextId: Uint8Array;
41
+ readonly stableIdentityCommitment: Uint8Array;
42
+ readonly referenceWindow: bigint;
43
+ readonly status: "available" | "unavailable";
44
+ readonly revocationFacts: readonly CoreRevocationFloorV1[];
45
+ readonly authorityAdmissionStateDigest: Uint8Array;
46
+ }
47
+ export interface PairAttemptLeaseV1 {
48
+ readonly version: 1;
49
+ readonly helloOperationId: Uint8Array;
50
+ readonly pairEdgeId: Uint8Array;
51
+ readonly endpointPresenceOperationIds: readonly [Uint8Array, Uint8Array];
52
+ readonly attemptMode: "planner" | "explicit";
53
+ readonly helloLogicalWindow: bigint;
54
+ readonly validThroughLogicalWindow: bigint;
55
+ }
56
+ export interface BootstrapAdmissionDecisionLeaseV1 {
57
+ readonly version: 1;
58
+ readonly roomContextId: Uint8Array;
59
+ readonly stableEd25519PublicKey: Uint8Array;
60
+ readonly stableIdentityCommitment: Uint8Array;
61
+ readonly grantId: Uint8Array | null;
62
+ readonly grantGeneration: bigint | null;
63
+ readonly localPolicyGeneration: bigint;
64
+ readonly authorityAdmissionStateDigest: Uint8Array | null;
65
+ readonly admittedPresenceOperationId: Uint8Array;
66
+ readonly admittedIdentityOperationId: Uint8Array;
67
+ readonly decidedAtLogicalWindow: bigint;
68
+ readonly validThroughLogicalWindow: bigint;
69
+ }
70
+ export interface StableEdgeAdmissionLeaseV1 {
71
+ readonly version: 1;
72
+ readonly roomContextId: Uint8Array;
73
+ readonly stableEdgeId: Uint8Array;
74
+ readonly confirmedPairTranscriptId: Uint8Array;
75
+ readonly rendezvousChannelId: Uint8Array;
76
+ readonly v4WireBinding: Uint8Array;
77
+ readonly remoteStableEd25519PublicKey: Uint8Array;
78
+ readonly remoteStableIdentityCommitment: Uint8Array;
79
+ readonly grantId: Uint8Array | null;
80
+ readonly grantGeneration: bigint | null;
81
+ readonly localPolicyGeneration: bigint;
82
+ readonly authorityAdmissionStateDigest: Uint8Array | null;
83
+ readonly decidedAtLogicalWindow: bigint;
84
+ readonly validThroughLogicalWindow: bigint | null;
85
+ }
86
+ export type AdmissionAllowReason = "open" | "address-book" | "authority-grant";
87
+ export type AdmissionDenyReason = "blacklisted" | "not-in-address-book" | "missing-grant" | "invalid-grant" | "revoked" | "policy-unavailable";
88
+ export interface AllowedPeerAdmissionPolicyV1 {
89
+ readonly result: "allow";
90
+ readonly reason: AdmissionAllowReason;
91
+ readonly localPolicyGeneration: bigint;
92
+ readonly grantId: Uint8Array | null;
93
+ readonly grantGeneration: bigint | null;
94
+ readonly authorityAdmissionStateDigest: Uint8Array | null;
95
+ readonly grantValidThroughLogicalWindow: bigint | null;
96
+ }
97
+ export interface DeniedPeerAdmissionPolicyV1 {
98
+ readonly result: "deny";
99
+ readonly reason: AdmissionDenyReason;
100
+ }
101
+ export type PeerAdmissionPolicyDecisionV1 = AllowedPeerAdmissionPolicyV1 | DeniedPeerAdmissionPolicyV1;
102
+ export type PairAdmissionDecision = {
103
+ readonly result: "allow";
104
+ readonly reason: AdmissionAllowReason;
105
+ readonly bootstrapLease: BootstrapAdmissionDecisionLeaseV1;
106
+ readonly pairAttemptLease: PairAttemptLeaseV1;
107
+ } | DeniedPeerAdmissionPolicyV1;
108
+ export type StableEdgeAdmissionDecision = {
109
+ readonly result: "allow";
110
+ readonly reason: AdmissionAllowReason;
111
+ readonly lease: StableEdgeAdmissionLeaseV1;
112
+ } | DeniedPeerAdmissionPolicyV1;
113
+ /**
114
+ * Unbranded facts consumed by the semantic policy helper. Production code must
115
+ * obtain the corresponding values from `TrustedAdmissionSnapshotV1`; this type
116
+ * is intentionally not named or presented as that trusted snapshot.
117
+ */
118
+ export interface PeerAdmissionPolicySemanticInputV1 {
119
+ readonly roomContextId: Uint8Array;
120
+ readonly roomPolicy: RoomPolicyV4;
121
+ readonly referenceWindow: bigint;
122
+ readonly frontendControls: FrontendRoomControlsV1 | null;
123
+ readonly authorityView: AuthorityAdmissionPolicyViewV1 | null;
124
+ readonly stableEd25519PublicKey: Uint8Array;
125
+ readonly stableIdentityCommitment: Uint8Array;
126
+ readonly optionalGrant: AdmissionGrantV1 | null;
127
+ readonly grantCarriedAtLogicalWindow: bigint | null;
128
+ }
129
+ export interface BootstrapAdmissionLeaseSemanticInputV1 {
130
+ readonly policy: AllowedPeerAdmissionPolicyV1;
131
+ readonly roomContextId: Uint8Array;
132
+ readonly stableEd25519PublicKey: Uint8Array;
133
+ readonly stableIdentityCommitment: Uint8Array;
134
+ readonly admittedPresenceOperationId: Uint8Array;
135
+ readonly admittedIdentityOperationId: Uint8Array;
136
+ readonly admittedIdentityOperationLogicalWindow: bigint;
137
+ readonly admittedIdentityOperationValidThroughLogicalWindow: bigint;
138
+ readonly admittedPresenceEvidenceRetainThroughLogicalWindow: bigint;
139
+ readonly basePairAttemptLease: PairAttemptLeaseV1;
140
+ readonly referenceWindow: bigint;
141
+ }
142
+ export interface StableEdgeAdmissionLeaseSemanticInputV1 {
143
+ readonly policy: AllowedPeerAdmissionPolicyV1;
144
+ readonly roomContextId: Uint8Array;
145
+ readonly stableEdgeId: Uint8Array;
146
+ readonly confirmedPairTranscriptId: Uint8Array;
147
+ readonly rendezvousChannelId: Uint8Array;
148
+ readonly v4WireBinding: Uint8Array;
149
+ readonly remoteStableEd25519PublicKey: Uint8Array;
150
+ readonly remoteStableIdentityCommitment: Uint8Array;
151
+ readonly referenceWindow: bigint;
152
+ }
153
+ export declare class AdmissionPolicySemanticError extends Error {
154
+ readonly name = "AdmissionPolicySemanticError";
155
+ constructor(message: string);
156
+ }
157
+ export declare const validateAndCopyFrontendRoomControlsV1: (value: unknown) => FrontendRoomControlsV1;
158
+ /** Canonical bytes for one already-local frontend policy snapshot. */
159
+ export declare const encodeFrontendRoomControlsV1: (value: unknown) => Uint8Array;
160
+ /**
161
+ * Restore an owned structural snapshot. This does not establish frontend
162
+ * provenance or make the policy generation current.
163
+ */
164
+ export declare const decodeFrontendRoomControlsV1: (bytes: Uint8Array) => FrontendRoomControlsV1;
165
+ /** Membership over an already validated canonical byte set. */
166
+ export declare const canonicalBytes32SetHas: (values: CanonicalBytes32SetV1, candidate: Uint8Array) => boolean;
167
+ /**
168
+ * `ApplicableRevocationFacts(commitment, referenceWindow)` from Section 4.8.
169
+ * Input order and exact duplicate delivery do not affect the result.
170
+ */
171
+ export declare const selectApplicableRevocationFacts: (facts: readonly CoreRevocationFloorV1[], stableIdentityCommitment: Uint8Array, referenceWindow: bigint) => readonly CoreRevocationFloorV1[];
172
+ export declare const authorityFaultValidThrough: (roomPolicy: RoomPolicyV4, faultWindow: bigint) => bigint;
173
+ export interface BlockingAuthorityWindowFaultSelectionV1 {
174
+ readonly blockingAuthorityWindowFaults: readonly AuthorityWindowFaultV1[];
175
+ readonly unavailableThroughLogicalWindow: bigint | null;
176
+ }
177
+ /**
178
+ * Select every still-blocking pinned-authority author-window fault. Custody
179
+ * saturation is intentionally absent; the future trusted view constructor must
180
+ * combine this selection with its protected custody projection.
181
+ */
182
+ export declare const selectBlockingAuthorityWindowFaults: (faults: readonly CoreFaultV1[], roomPolicy: RoomPolicyV4, referenceWindow: bigint) => BlockingAuthorityWindowFaultSelectionV1;
183
+ export declare const authorityGenerationAllowed: (generation: bigint, authorityView: Pick<AuthorityAdmissionPolicyViewV1, "status" | "revocationFacts">) => boolean;
184
+ /**
185
+ * The one semantic policy order shared by future bootstrap and stable-edge
186
+ * wrappers. It intentionally does not verify trusted snapshot/view provenance.
187
+ */
188
+ export declare const evaluatePeerAdmissionPolicySemantics: (input: PeerAdmissionPolicySemanticInputV1, module?: LibCrypto) => Promise<PeerAdmissionPolicyDecisionV1>;
189
+ export declare const validateAndCopyPairAttemptLeaseV1: (value: unknown) => PairAttemptLeaseV1;
190
+ /** Canonical durable bytes for one structurally valid pair-attempt lease. */
191
+ export declare const encodePairAttemptLeaseV1: (value: unknown) => Uint8Array;
192
+ /**
193
+ * Restore an owned structural pair-attempt lease. Callers must still bind it
194
+ * to the fresh trusted pair state before treating it as authority to act.
195
+ */
196
+ export declare const decodePairAttemptLeaseV1: (bytes: Uint8Array) => PairAttemptLeaseV1;
197
+ export declare const validateAndCopyBootstrapAdmissionDecisionLeaseV1: (value: unknown) => BootstrapAdmissionDecisionLeaseV1;
198
+ /** Canonical durable bytes for one bootstrap admission decision lease. */
199
+ export declare const encodeBootstrapAdmissionDecisionLeaseV1: (value: unknown) => Uint8Array;
200
+ /**
201
+ * Restore an owned structural bootstrap lease. The decoded record is not a
202
+ * trusted admission decision until its bindings and freshness are rechecked.
203
+ */
204
+ export declare const decodeBootstrapAdmissionDecisionLeaseV1: (bytes: Uint8Array) => BootstrapAdmissionDecisionLeaseV1;
205
+ export declare const validateAndCopyAllowedPeerAdmissionPolicyV1: (value: unknown) => AllowedPeerAdmissionPolicyV1;
206
+ /**
207
+ * Narrow the authenticated base pair-attempt horizon by the admitted grant,
208
+ * then construct both immutable bootstrap leases. A future trusted wrapper
209
+ * must verify every pair/presence coordinate before calling this semantic
210
+ * helper and must persist only this returned pair-attempt lease.
211
+ */
212
+ export declare const constructBootstrapAdmissionDecisionLease: (input: BootstrapAdmissionLeaseSemanticInputV1) => PairAdmissionDecision;
213
+ /**
214
+ * Construct only the stable-edge lease/result after a future branded stable
215
+ * context and fresh trusted snapshot have passed the shared policy helper.
216
+ */
217
+ export declare const constructStableEdgeAdmissionLease: (input: StableEdgeAdmissionLeaseSemanticInputV1) => StableEdgeAdmissionDecision;
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Canonical binary schema: the single source of truth for blind-rendezvous
3
+ * wire bytes.
4
+ *
5
+ * Section 4 of the L2/L3 blind-rendezvous specification writes `Canonical(x)`
6
+ * for "the unique encoding in the companion binary-schema artifact". This
7
+ * module is that artifact's executable form. It owns field order, integer
8
+ * widths, enum values, collection ordering, and bounds, so no other module may
9
+ * hand-roll a second encoding of the same value.
10
+ *
11
+ * Status: PROPOSED, NOT FROZEN. Phase 0 of the delivery roadmap freezes these
12
+ * widths and publishes deterministic vectors under one release-registry hash.
13
+ * Until that freeze and its external review, no hash derived from this module
14
+ * may be published as a v0.4 release artifact, and no interoperability claim
15
+ * follows from two implementations agreeing with it.
16
+ *
17
+ * The codec is descriptor-driven rather than hand-written per type. A
18
+ * descriptor is the SSOT: encoders, decoders, key tables, and bound checks are
19
+ * all derived from it, which is what makes the generated projections in
20
+ * `projections.ts` mechanically checkable instead of hand-maintained.
21
+ */
22
+ export type Bytes32 = Uint8Array;
23
+ /** Maximum entries in any bounded collection with a 16-bit count prefix. */
24
+ export declare const MAX_U16_COLLECTION_ENTRIES = 65535;
25
+ /** Bound on any canonical NFC text field, in UTF-8 bytes. */
26
+ export declare const MAX_CANONICAL_TEXT_BYTES = 4096;
27
+ /** Bound on a single canonically encoded value, in bytes. */
28
+ export declare const MAX_CANONICAL_ENCODING_BYTES: number;
29
+ export declare class CanonicalSchemaError extends Error {
30
+ readonly name = "CanonicalSchemaError";
31
+ readonly path: string;
32
+ constructor(path: string, message: string);
33
+ }
34
+ export interface FieldDescriptor {
35
+ readonly name: string;
36
+ readonly type: TypeDescriptor;
37
+ }
38
+ export type TypeDescriptor = {
39
+ readonly kind: "u8";
40
+ } | {
41
+ readonly kind: "u16";
42
+ } | {
43
+ readonly kind: "u32";
44
+ } | {
45
+ readonly kind: "u64";
46
+ } | {
47
+ readonly kind: "bool";
48
+ } | {
49
+ readonly kind: "fixedBytes";
50
+ readonly length: number;
51
+ } | {
52
+ readonly kind: "varBytes";
53
+ readonly maxLength: number;
54
+ } | {
55
+ readonly kind: "text";
56
+ readonly maxBytes: number;
57
+ } | {
58
+ readonly kind: "enum";
59
+ readonly name: string;
60
+ readonly values: readonly string[];
61
+ } | {
62
+ readonly kind: "array";
63
+ readonly item: TypeDescriptor;
64
+ readonly maxEntries: number;
65
+ readonly ordering: "sorted-unique" | "sequence";
66
+ } | {
67
+ readonly kind: "optional";
68
+ readonly value: TypeDescriptor;
69
+ } | {
70
+ readonly kind: "record";
71
+ readonly name: string;
72
+ readonly fields: readonly FieldDescriptor[];
73
+ } | {
74
+ readonly kind: "union";
75
+ readonly name: string;
76
+ readonly discriminant: string;
77
+ readonly variants: readonly {
78
+ readonly tag: string;
79
+ readonly type: TypeDescriptor;
80
+ }[];
81
+ };
82
+ export declare const u8: TypeDescriptor;
83
+ export declare const u16: TypeDescriptor;
84
+ export declare const u32: TypeDescriptor;
85
+ export declare const u64: TypeDescriptor;
86
+ export declare const bool: TypeDescriptor;
87
+ export declare const fixedBytes: (length: number) => TypeDescriptor;
88
+ export declare const bytes32: TypeDescriptor;
89
+ export declare const bytes64: TypeDescriptor;
90
+ export declare const varBytes: (maxLength: number) => TypeDescriptor;
91
+ export declare const text: (maxBytes?: number) => TypeDescriptor;
92
+ export declare const enumOf: (name: string, values: readonly string[]) => TypeDescriptor;
93
+ export declare const array: (item: TypeDescriptor, maxEntries: number, ordering?: "sorted-unique" | "sequence") => TypeDescriptor;
94
+ export declare const optional: (value: TypeDescriptor) => TypeDescriptor;
95
+ export declare const record: (name: string, fields: readonly FieldDescriptor[]) => TypeDescriptor;
96
+ export declare const union: (name: string, discriminant: string, variants: readonly {
97
+ readonly tag: string;
98
+ readonly type: TypeDescriptor;
99
+ }[]) => TypeDescriptor;
100
+ export declare const bytesEqual: (left: Uint8Array, right: Uint8Array) => boolean;
101
+ /** The unique canonical encoding of `value` under `descriptor`. */
102
+ export declare const encodeCanonical: (descriptor: TypeDescriptor, value: unknown, path?: string) => Uint8Array;
103
+ /**
104
+ * Decode exactly one canonical value. Trailing bytes, non-minimal encodings,
105
+ * unknown enum/union tags, unsorted collections, and out-of-bound lengths are
106
+ * rejected rather than repaired.
107
+ */
108
+ export declare const decodeCanonical: (descriptor: TypeDescriptor, bytes: Uint8Array, path?: string) => unknown;
109
+ /**
110
+ * Decode, then prove the result re-encodes to the exact input bytes. Callers
111
+ * at a security boundary use this so a value that decodes but is not the
112
+ * unique encoding of itself can never be accepted.
113
+ */
114
+ export declare const decodeCanonicalStrict: (descriptor: TypeDescriptor, bytes: Uint8Array, path?: string) => unknown;
115
+ export declare const descriptorName: (descriptor: TypeDescriptor) => string;
116
+ /**
117
+ * The exact field-name projection of a record descriptor, in wire order.
118
+ *
119
+ * Section 1.4 makes generated projections mandatory: a hand-maintained key
120
+ * table that disagrees with the schema is a release failure. Consumers import
121
+ * this instead of restating field names.
122
+ */
123
+ export declare const recordFieldNames: (descriptor: TypeDescriptor) => readonly string[];
124
+ /**
125
+ * The complete field list of a record descriptor.
126
+ *
127
+ * A signed wire type is its body plus a signature, so it reuses the body's
128
+ * fields rather than restating them — the signature transcript is exactly the
129
+ * body encoding, and a divergence between the two lists would be silent.
130
+ */
131
+ export declare const recordFields: (descriptor: TypeDescriptor) => readonly FieldDescriptor[];
132
+ /** The descriptor of one named field of a record descriptor. */
133
+ export declare const recordFieldType: (descriptor: TypeDescriptor, fieldName: string) => TypeDescriptor;
134
+ /** The descriptor of one named variant of a union descriptor. */
135
+ export declare const unionVariantType: (descriptor: TypeDescriptor, tag: string) => TypeDescriptor;
136
+ /** The exact enum-value projection, in wire-byte order. */
137
+ export declare const enumValues: (descriptor: TypeDescriptor) => readonly string[];
138
+ /** The wire byte assigned to one enum member. */
139
+ export declare const enumByte: (descriptor: TypeDescriptor, value: string) => number;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Carrier-separated envelope framing (Section 4.5).
3
+ *
4
+ * The same logical operation is wrapped independently for every carrier
5
+ * context, with carrier-domain-separated keys and nonce material, so two
6
+ * stores never receive byte-identical ciphertext or a common object
7
+ * identifier. A client deduplicates the rewrapped copies by the private
8
+ * `OperationId` after decryption — an identifier a store never sees.
9
+ *
10
+ * ## The sealing primitive
11
+ *
12
+ * `carrierAeadSuite = 1` is the frozen XChaCha20-Poly1305 construction from
13
+ * `draft-irtf-cfrg-xchacha-03` with a 32-byte key, 24-byte nonce, and 16-byte
14
+ * tag. `createCarrierAeadProvider` binds it from the pinned libsodium build.
15
+ *
16
+ * The AEAD stays an injected provider rather than a direct import for two
17
+ * reasons: a caller must supply an initialized WASM module anyway, and a build
18
+ * that lacks the export fails closed with a typed error instead of silently
19
+ * sealing under some other construction. Substituting a different AEAD, or
20
+ * composing XChaCha20 in TypeScript, remains forbidden by SEC-002 and SEC-019.
21
+ */
22
+ import type { LibCrypto } from "../cryptography/libcrypto";
23
+ import type { CarrierEnvelopeCoordinates } from "./derivations";
24
+ export declare const CARRIER_ENVELOPE_VERSION = 1;
25
+ export declare const CARRIER_AEAD_SUITE_1_KEY_BYTES = 32;
26
+ export declare const CARRIER_AEAD_SUITE_1_NONCE_BYTES = 24;
27
+ export declare const CARRIER_AEAD_SUITE_1_TAG_BYTES = 16;
28
+ export interface CarrierEnvelopeV1 {
29
+ version: 1;
30
+ deliveryProfileHash: Uint8Array;
31
+ ingressWindow: bigint;
32
+ sizeClass: number;
33
+ carrierContextId: Uint8Array;
34
+ nonce: Uint8Array;
35
+ ciphertextAndTag: Uint8Array;
36
+ }
37
+ export interface CarrierPlaintextV1 {
38
+ /** Exact canonical signed operation bytes, identical across carriers. */
39
+ operationBytes: Uint8Array;
40
+ /** Fills this profile's carrier size class. */
41
+ carrierPadding: Uint8Array;
42
+ }
43
+ /**
44
+ * The exact AEAD required by `carrierAeadSuite = 1`.
45
+ *
46
+ * An implementation must be XChaCha20-Poly1305 with the stated key, nonce, and
47
+ * tag sizes. `open` returns null — never a partial or unauthenticated
48
+ * plaintext — on any tag, length, or associated-data failure.
49
+ */
50
+ export interface CarrierAeadProvider {
51
+ readonly suite: 1;
52
+ seal(key: Uint8Array, nonce: Uint8Array, associatedData: Uint8Array, plaintext: Uint8Array): Promise<Uint8Array>;
53
+ open(key: Uint8Array, nonce: Uint8Array, associatedData: Uint8Array, ciphertextAndTag: Uint8Array): Promise<Uint8Array | null>;
54
+ }
55
+ export declare class CarrierAeadUnavailableError extends Error {
56
+ readonly name = "CarrierAeadUnavailableError";
57
+ readonly code = "carrier-aead-suite-1-unavailable";
58
+ readonly suite = 1;
59
+ constructor();
60
+ }
61
+ export declare class CarrierEnvelopeError extends Error {
62
+ readonly name = "CarrierEnvelopeError";
63
+ constructor(message: string);
64
+ }
65
+ /**
66
+ * The conforming `carrierAeadSuite = 1` provider, bound to an initialized
67
+ * cryptography module.
68
+ */
69
+ export declare const createCarrierAeadProvider: (module: LibCrypto) => CarrierAeadProvider;
70
+ /**
71
+ * Build the canonical carrier plaintext, padded to the profile's size class.
72
+ *
73
+ * Padding is what makes real and dummy objects the same length; a caller that
74
+ * skipped it would publish a length that varies with the operation.
75
+ */
76
+ export declare const buildCarrierPlaintext: (operationBytes: Uint8Array, fixedCarrierObjectBytes: number) => CarrierPlaintextV1;
77
+ /**
78
+ * Seal one operation for one carrier context.
79
+ *
80
+ * The nonce is sampled by the caller per `(OperationId, profile, context,
81
+ * ingressWindow, sizeClass)` wrap slot and persisted with the envelope before
82
+ * first publication, so an exact retry resends the same bytes rather than
83
+ * re-encrypting under a fresh nonce.
84
+ */
85
+ export declare const sealCarrierEnvelope: (roomRootBytes: Uint8Array, coordinates: CarrierEnvelopeCoordinates, nonce: Uint8Array, plaintext: CarrierPlaintextV1, provider: CarrierAeadProvider | null) => Promise<CarrierEnvelopeV1>;
86
+ /**
87
+ * Open an envelope, returning null when it is not for this room.
88
+ *
89
+ * A dummy is indistinguishable from a real object at this layer by
90
+ * construction: it has the same public header and body length and simply fails
91
+ * authentication, so the caller must treat null as "not mine", never as
92
+ * evidence of a fault.
93
+ */
94
+ export declare const openCarrierEnvelope: (roomRootBytes: Uint8Array, envelope: CarrierEnvelopeV1, provider: CarrierAeadProvider | null) => Promise<CarrierPlaintextV1 | null>;
95
+ /** The exact canonical encoding of an envelope, as published to a carrier. */
96
+ export declare const encodeCarrierEnvelope: (envelope: CarrierEnvelopeV1) => Uint8Array;
97
+ export declare const decodeCarrierEnvelope: (encoded: Uint8Array) => CarrierEnvelopeV1;
98
+ /** `CarrierObjectId`, meaningful only inside one carrier context. */
99
+ export declare const deriveCarrierObjectId: (envelope: CarrierEnvelopeV1) => Promise<Uint8Array>;
100
+ /**
101
+ * Two envelopes of the same operation for different carrier contexts must not
102
+ * share ciphertext or object identifier. Exposed so the carrier-separation
103
+ * requirement is testable rather than assumed.
104
+ */
105
+ export declare const envelopesAreCarrierSeparated: (left: CarrierEnvelopeV1, right: CarrierEnvelopeV1) => boolean;
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Deterministic outer-layer reduction (Section 4.7).
3
+ *
4
+ * `Merge` is set union and `CoreReduce` is a pure function of the validated
5
+ * operation set, the immutable room policy, and an explicit reference window.
6
+ * It reads no arrival timestamp, server identity, fetch order, frontend
7
+ * allow/deny state, planner preference, wall clock, "first response" state,
8
+ * pair secret, or inner pair validity — that exclusion list is the whole
9
+ * reason two honest clients with the same delivered set derive byte-identical
10
+ * state no matter which carrier delivered what, in which order.
11
+ *
12
+ * The reducer consumes only process-private results of the validation ingress.
13
+ * It integrates payload facts only after arrival-independent author
14
+ * fork/quota classification, then applies semantic-slot/dependency rules and
15
+ * emits the exact CoreRoomStateV1 projections. Frontend admission, route
16
+ * activation, planner preference, and pair plaintext remain outside this
17
+ * room-wide state.
18
+ */
19
+ import type { LibCrypto } from "../cryptography/libcrypto";
20
+ import type { AuthenticatedRoomOperationV1, OperationValidationContext } from "./operation";
21
+ import type { PresenceV1 } from "./operationPayload";
22
+ import type { PairStepEnvelopeV1 } from "./pairStepEnvelope";
23
+ import type { RoomPolicyV4 } from "./roomPolicyV4";
24
+ import type { StoreDescriptorV1, StoreRouteV1 } from "./storeDescriptor";
25
+ declare const outerValidatedIdentifiedOperationBrand: unique symbol;
26
+ declare const activePairOperationCandidateBrand: unique symbol;
27
+ /**
28
+ * Process-local proof that one exact PAIR_STEP was active in one genuine
29
+ * CoreReduce result. It intentionally exposes no structural fields.
30
+ */
31
+ export interface ActivePairOperationCandidateV1 {
32
+ readonly [activePairOperationCandidateBrand]: true;
33
+ }
34
+ export interface PairAuthorChainPrefixEvidenceV1 {
35
+ readonly operationId: Uint8Array;
36
+ readonly exactOperationBytes: Uint8Array;
37
+ }
38
+ export interface ActivePairOperationCandidateSnapshotV1 {
39
+ readonly exactOperationBytes: Uint8Array;
40
+ readonly operationId: Uint8Array;
41
+ readonly operation: AuthenticatedRoomOperationV1;
42
+ readonly envelope: PairStepEnvelopeV1;
43
+ readonly roomContextId: Uint8Array;
44
+ readonly roomPolicy: RoomPolicyV4;
45
+ readonly referenceWindow: bigint;
46
+ readonly evidenceValidThroughWindow: bigint;
47
+ readonly exactCoreStateBytes: Uint8Array;
48
+ readonly authorChainPrefix: readonly PairAuthorChainPrefixEvidenceV1[];
49
+ }
50
+ declare const verifiedHistoricalPairPresenceBrand: unique symbol;
51
+ /**
52
+ * Process-local proof that one exact signed PRESENCE was an observed roster
53
+ * fact in a genuine CoreReduce result. Generic author-prefix evidence cannot
54
+ * instantiate this capability.
55
+ */
56
+ export interface VerifiedHistoricalPairPresenceEvidenceV1 {
57
+ readonly [verifiedHistoricalPairPresenceBrand]: true;
58
+ }
59
+ /** Exact durable record defined by Section 4.9. */
60
+ export interface HistoricalPairPresenceEvidenceV1 {
61
+ readonly exactPresenceOperationBytes: Uint8Array;
62
+ readonly presenceOperationId: Uint8Array;
63
+ readonly retainThroughLogicalWindow: bigint;
64
+ }
65
+ export interface VerifiedHistoricalPairPresenceSnapshotV1 extends HistoricalPairPresenceEvidenceV1 {
66
+ readonly operation: AuthenticatedRoomOperationV1;
67
+ readonly presence: PresenceV1;
68
+ readonly provedAtLogicalWindow: bigint;
69
+ readonly roomContextId: Uint8Array;
70
+ readonly roomPolicy: RoomPolicyV4;
71
+ readonly exactCoreStateBytes: Uint8Array;
72
+ readonly authorChainPrefix: readonly PairAuthorChainPrefixEvidenceV1[];
73
+ }
74
+ /** One outer-authenticated candidate together with its private candidate ID. */
75
+ export interface OuterValidatedIdentifiedOperationV1 {
76
+ readonly [outerValidatedIdentifiedOperationBrand]: true;
77
+ readonly operationId: Uint8Array;
78
+ readonly operation: AuthenticatedRoomOperationV1;
79
+ }
80
+ /**
81
+ * The sole ingress from untrusted decoded bytes into the reducer domain.
82
+ *
83
+ * The caller-owned object is canonically snapshotted before the first await;
84
+ * all validation and ID derivation use that private copy. OperationId is
85
+ * derived only after complete outer validation, including PAIR_STEP slot
86
+ * binding and the author signature. Non-pair nested signature work is
87
+ * deliberately deferred until CoreReduce has classified author quota/forks.
88
+ * The returned provenance brand is process-local and never persisted.
89
+ */
90
+ export declare const validateAndIdentifyOperationCandidate: (operation: AuthenticatedRoomOperationV1, context: OperationValidationContext, module?: LibCrypto) => Promise<OuterValidatedIdentifiedOperationV1>;
91
+ /**
92
+ * Capture one active, provenance-checked PAIR_STEP ingress.
93
+ *
94
+ * This is the only bridge from room-wide outer validation into pair opening.
95
+ * It requires both the candidate and the room state to be live results of
96
+ * their private validation/reduction entrypoints and rechecks their canonical
97
+ * bytes on every call. Persisted bytes must therefore pass validation and
98
+ * CoreReduce again after restart; a merely outer-valid future, forked,
99
+ * overquota, expired, or dependency-inert candidate cannot spend pair-open
100
+ * work or reach admission.
101
+ *
102
+ * The returned value is an opaque process-local capability. Pair-kernel code
103
+ * accepts that capability, never a caller-assembled snapshot or prebinding.
104
+ */
105
+ export declare const captureActivePairOperationCandidate: (candidate: OuterValidatedIdentifiedOperationV1, roomState: CoreRoomStateV1) => Promise<ActivePairOperationCandidateV1>;
106
+ /**
107
+ * Take an owned pair-kernel snapshot from a genuine active-operation handle.
108
+ *
109
+ * The returned bytes are data, not provenance: downstream state machines must
110
+ * continue accepting the opaque `ActivePairOperationCandidateV1` and call this
111
+ * accessor themselves. Exact Core bytes are included for the later durable
112
+ * compare-and-swap that prevents an asynchronous open from committing against
113
+ * a superseded room view.
114
+ */
115
+ export declare const snapshotActivePairOperationCandidate: (candidate: ActivePairOperationCandidateV1) => ActivePairOperationCandidateSnapshotV1;
116
+ /**
117
+ * Capture one current roster fact for bounded pair-private use after that
118
+ * presence leaves the live roster.
119
+ *
120
+ * Restore repeats operation validation and CoreReduce at the exact HELLO
121
+ * logical window before calling this constructor. That equality is
122
+ * load-bearing: a capability captured before an effective LEAVE cannot prove
123
+ * a HELLO created at or after the leave. Exact signed bytes alone, a decoded
124
+ * CoreRoomState, or generic author-prefix evidence are insufficient.
125
+ */
126
+ export declare const captureHistoricalPairPresenceEvidence: (candidate: OuterValidatedIdentifiedOperationV1, roomState: CoreRoomStateV1, helloLogicalWindow: bigint) => Promise<VerifiedHistoricalPairPresenceEvidenceV1>;
127
+ /**
128
+ * Return owned bytes from a genuine historical-presence capability.
129
+ *
130
+ * Downstream admission code accepts the opaque capability and calls this
131
+ * accessor itself. The structural result is suitable for persistence only; it
132
+ * cannot be passed back as proof after restart without validation and
133
+ * CoreReduce reconstructing a new capability.
134
+ */
135
+ export declare const snapshotHistoricalPairPresenceEvidence: (evidence: VerifiedHistoricalPairPresenceEvidenceV1) => VerifiedHistoricalPairPresenceSnapshotV1;
136
+ export type CoreFaultV1 = {
137
+ readonly kind: "author-fork-or-overquota";
138
+ readonly authorEpochEd25519Key: Uint8Array;
139
+ readonly logicalWindow: bigint;
140
+ readonly proofOperationIds: readonly Uint8Array[];
141
+ } | {
142
+ readonly kind: "presence-or-leave-fork";
143
+ readonly semanticSlot: Uint8Array;
144
+ readonly proofOperationIds: readonly Uint8Array[];
145
+ } | {
146
+ readonly kind: "store-generation-fork";
147
+ readonly storeId: Uint8Array;
148
+ readonly descriptorGeneration: bigint;
149
+ readonly descriptorHashes: readonly [Uint8Array, Uint8Array];
150
+ };
151
+ export interface CorePresenceFactV1 {
152
+ readonly presenceOperationId: Uint8Array;
153
+ readonly authorEpochEd25519Key: Uint8Array;
154
+ readonly logicalWindow: bigint;
155
+ readonly presence: PresenceV1;
156
+ }
157
+ export interface CoreStoreFactV1 {
158
+ readonly storeId: Uint8Array;
159
+ readonly descriptorGeneration: bigint;
160
+ readonly descriptorHash: Uint8Array;
161
+ readonly sourceOperationId: Uint8Array;
162
+ readonly descriptor: StoreDescriptorV1;
163
+ readonly routes: readonly StoreRouteV1[];
164
+ readonly hintValidThroughLogicalWindow: bigint;
165
+ }
166
+ export interface CoreRevocationFloorV1 {
167
+ readonly stableIdentityCommitment: Uint8Array;
168
+ readonly minimumAcceptedGeneration: bigint;
169
+ readonly effectiveLogicalWindow: bigint;
170
+ readonly validThroughLogicalWindow: bigint;
171
+ readonly revokeOperationId: Uint8Array;
172
+ }
173
+ export interface CoreRoomStateV1 {
174
+ readonly version: 1;
175
+ readonly referenceWindow: bigint;
176
+ readonly roomCapacityState: "within-policy" | "overcapacity";
177
+ readonly activeOperationIds: readonly Uint8Array[];
178
+ readonly observedPresences: readonly CorePresenceFactV1[];
179
+ readonly effectiveLeaveOperationIds: readonly Uint8Array[];
180
+ readonly storeCatalogFacts: readonly CoreStoreFactV1[];
181
+ readonly revocationFloors: readonly CoreRevocationFloorV1[];
182
+ readonly activePairOuterOperationIds: readonly Uint8Array[];
183
+ readonly faults: readonly CoreFaultV1[];
184
+ readonly operationsDigest: Uint8Array;
185
+ }
186
+ /** The unique canonical encoding of a reduced room state. */
187
+ export declare const encodeCoreRoomStateV1: (state: CoreRoomStateV1) => Promise<Uint8Array>;
188
+ /** Strictly decode one canonical reduced room state. */
189
+ export declare const decodeCoreRoomStateV1: (bytes: Uint8Array) => Promise<CoreRoomStateV1>;
190
+ export declare const mergeOperationCandidateSets: (left: readonly OuterValidatedIdentifiedOperationV1[], right: readonly OuterValidatedIdentifiedOperationV1[]) => OuterValidatedIdentifiedOperationV1[];
191
+ /**
192
+ * Exact deterministic `CoreReduce`.
193
+ *
194
+ * Every decision is a function of privately snapshotted operation bytes and
195
+ * one immutable room context/reference window. Fork and overquota
196
+ * classification precedes payload reduction and is arrival-independent.
197
+ */
198
+ export declare const coreReduce: (operations: readonly OuterValidatedIdentifiedOperationV1[], context: OperationValidationContext, module?: LibCrypto) => Promise<CoreRoomStateV1>;
199
+ export {};