@dopamint-fun/open-sdk 0.1.0-dev.0 → 0.2.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,9 @@ export declare const SESSION_TERMINAL_TAG = 12;
10
10
  export declare const SESSION_ERROR_TAG = 13;
11
11
  export declare const SEAT_AUTHORIZATION_CHALLENGE_TAG = 15;
12
12
  export declare const SEAT_AUTHORIZATION_RESPONSE_TAG = 16;
13
+ export declare const PREDICTION_GATE_RELEASED_TAG = 17;
14
+ export declare const PREDICTION_GATE_PREPARED_TAG = 18;
15
+ export declare const PREDICTION_GATE_OPENED_TAG = 19;
13
16
  export declare const MAX_TRANSPORT_FRAME_BYTES: number;
14
17
  export interface WireEnvelope {
15
18
  message: string;
@@ -56,12 +59,80 @@ export interface SeatAuthChallenge {
56
59
  coordinatorProof: Uint8Array;
57
60
  coordinatorPublicKey: Uint8Array;
58
61
  }
62
+ /** ADR-0096's ceiling on added pacing for one next-action prediction window,
63
+ * as `arena_session::prediction_gate::MAX_PREDICTION_PACING_MS`. */
64
+ export declare const MAX_PREDICTION_PACING_MS = 25000n;
65
+ /** The in-play window a gate names. The session reuses this identity; it
66
+ * never mints a second one. */
67
+ export interface PredictionWindowRef {
68
+ windowId: bigint;
69
+ marketId: bigint;
70
+ /** The only contract kind a gate can hold a seat behind (wire tag 1). */
71
+ contract: "pokerActionV1";
72
+ }
73
+ /** A durably committed preparation: the frozen window identity, the target
74
+ * the acting seat is held on, its original committed deadline, and the
75
+ * persisted instant publication started. */
76
+ export interface PredictionGatePreparation {
77
+ window: PredictionWindowRef;
78
+ actingSeat: number;
79
+ state: StateRef;
80
+ receipt: ReceiptRef | null;
81
+ originalDeadlineMs: bigint;
82
+ preparedAtMs: bigint;
83
+ }
84
+ /** Acknowledged publication. `closesAtMs` is the service-committed close
85
+ * instant, never the action deadline. */
86
+ export interface PredictionGateOpening {
87
+ preparation: PredictionGatePreparation;
88
+ openedAtMs: bigint;
89
+ closesAtMs: bigint;
90
+ }
91
+ /** The terminal overlay: how the gate closed, and the bounded same-receipt
92
+ * deadline it admits. `lockCappedMs` and `participantDeadlineMs` are derived
93
+ * the way the shared crate derives them, so a recipient never has to repeat
94
+ * the arithmetic to know which later deadline is legal. */
95
+ export interface PredictionGateRelease {
96
+ window: PredictionWindowRef;
97
+ actingSeat: number;
98
+ state: StateRef;
99
+ receipt: ReceiptRef | null;
100
+ terminal: "locked" | "cancelled";
101
+ originalDeadlineMs: bigint;
102
+ arrivalMs: bigint;
103
+ lockedAtMs: bigint;
104
+ lockCappedMs: bigint;
105
+ budgetMs: bigint;
106
+ participantDeadlineMs: bigint;
107
+ }
108
+ /** The gate facts a participant retains for one revision. */
109
+ export type PredictionGateStatus = {
110
+ phase: "prepared";
111
+ preparation: PredictionGatePreparation;
112
+ } | {
113
+ phase: "open";
114
+ opening: PredictionGateOpening;
115
+ } | {
116
+ phase: "released";
117
+ release: PredictionGateRelease;
118
+ };
119
+ /** One named lifecycle step, as a value: what the fold below applies. */
120
+ export type PredictionGateMessage = {
121
+ kind: "prepared";
122
+ preparation: PredictionGatePreparation;
123
+ } | {
124
+ kind: "opened";
125
+ opening: PredictionGateOpening;
126
+ } | {
127
+ kind: "released";
128
+ release: PredictionGateRelease;
129
+ };
59
130
  export type AuthorityMessage = {
60
131
  type: "sessionJoined";
61
132
  context: SessionContext;
62
133
  sequence: bigint;
63
134
  policy: SessionPolicy;
64
- view: ViewSnapshot;
135
+ view: ViewSnapshot | null;
65
136
  cursor: ResumeCursor;
66
137
  } | {
67
138
  type: "participantView";
@@ -97,7 +168,10 @@ export type AuthorityMessage = {
97
168
  type: "sessionResumed";
98
169
  context: SessionContext;
99
170
  sequence: bigint;
100
- view: ViewSnapshot;
171
+ /** The boundary the authority replayed from. It must precede the event
172
+ itself, or the resume names a suffix it cannot have replayed. */
173
+ replayFrom: bigint;
174
+ view: ViewSnapshot | null;
101
175
  cursor: ResumeCursor;
102
176
  } | {
103
177
  type: "sessionTerminal";
@@ -107,6 +181,24 @@ export type AuthorityMessage = {
107
181
  finalState: StateRef;
108
182
  cursor: ResumeCursor;
109
183
  finalReceipt: ReceiptRef | null;
184
+ } | {
185
+ type: "predictionGatePrepared";
186
+ context: SessionContext;
187
+ sequence: bigint;
188
+ preparation: PredictionGatePreparation;
189
+ cursor: ResumeCursor;
190
+ } | {
191
+ type: "predictionGateOpened";
192
+ context: SessionContext;
193
+ sequence: bigint;
194
+ opening: PredictionGateOpening;
195
+ cursor: ResumeCursor;
196
+ } | {
197
+ type: "predictionGateReleased";
198
+ context: SessionContext;
199
+ sequence: bigint;
200
+ release: PredictionGateRelease;
201
+ cursor: ResumeCursor;
110
202
  } | {
111
203
  type: "error";
112
204
  retryable: boolean;
@@ -125,6 +217,19 @@ export declare function sessionErrorName(tag: number): string;
125
217
  * join supersedes the older binding, and the older client's next message
126
218
  * finds its session gone. Both used to read as transport flakiness. */
127
219
  export declare function sessionErrorHint(tag: number): string | null;
220
+ export declare function equalStateRef(left: StateRef, right: StateRef): boolean;
221
+ export declare function equalReceiptRef(left: ReceiptRef | null, right: ReceiptRef | null): boolean;
222
+ export declare function equalPredictionGatePreparation(left: PredictionGatePreparation, right: PredictionGatePreparation): boolean;
223
+ export declare function equalPredictionGateRelease(left: PredictionGateRelease, right: PredictionGateRelease): boolean;
224
+ /** The structural refusals of `PredictionGatePreparation::new`, made wherever
225
+ * a preparation enters this process - the wire, or a retained seat state. */
226
+ export declare function bindPredictionGatePreparation(fields: PredictionGatePreparation): PredictionGatePreparation;
227
+ /** The structural refusals of `PredictionGateOpening::new`. */
228
+ export declare function bindPredictionGateOpening(fields: PredictionGateOpening): PredictionGateOpening;
229
+ /** The structural refusals of `PredictionGateRelease::new`, with the bounded
230
+ * overlay derived here rather than trusted from a sender or a stored file:
231
+ * the lock instant capped at the pacing ceiling, plus the budget. */
232
+ export declare function bindPredictionGateRelease(fields: Omit<PredictionGateRelease, "lockCappedMs" | "participantDeadlineMs">): PredictionGateRelease;
128
233
  export declare function decodeAuthorityMessage(bytes: Uint8Array): AuthorityMessage;
129
234
  export declare function encodeSeatAuthSuccessFrame(context: SessionContext, actionId: Uint8Array, signature: Uint8Array): Uint8Array;
130
235
  export declare function extractProtocolInput(payload: Uint8Array): Uint8Array;
@@ -137,3 +242,60 @@ export declare function takePrincipalProof(bytes: Uint8Array): {
137
242
  signature: Uint8Array;
138
243
  rest: Uint8Array;
139
244
  };
245
+ /** A refused phase transition, named as the shared crate names it. */
246
+ export declare class PredictionGateConflictError extends Error {
247
+ readonly conflict: "PredictionGatePhaseConflict" | "PredictionGateReleaseConflict";
248
+ constructor(conflict: "PredictionGatePhaseConflict" | "PredictionGateReleaseConflict", detail: string);
249
+ }
250
+ /** The lifecycle step an authority message carries, or null where it carries
251
+ * none. The fold takes the value, not the envelope. */
252
+ export declare function predictionGateMessage(message: AuthorityMessage): PredictionGateMessage | null;
253
+ /** The committed preparation behind any phase, or null once released - a
254
+ * release carries the identity but not the persisted preparation instant. */
255
+ export declare function predictionGatePreparationOf(status: PredictionGateStatus): PredictionGatePreparation | null;
256
+ /** The receipt the gate targets. A recipient behind it still receives every
257
+ * notice, because each notice cursor names that recipient's own floor. */
258
+ export declare function predictionGateTargetReceipt(status: PredictionGateStatus): ReceiptRef | null;
259
+ /** Whether a newly named preparation supersedes the retained facts.
260
+ *
261
+ * Only a released gate can be superseded: a held gate's turn has not closed,
262
+ * so a second preparation contradicts it. Once released, the next selected
263
+ * turn always targets a later committed state and therefore its own receipt.
264
+ * A seat that is itself withheld for that next turn never witnesses the view
265
+ * that would otherwise retire the closed gate - which is exactly the second
266
+ * window of a hand, held on the seat that was a bystander for the first. A
267
+ * preparation naming the same revision is the same-target conflict, not a
268
+ * supersession. */
269
+ export declare function predictionGateSupersededByPreparation(status: PredictionGateStatus, nextTurn: PredictionGatePreparation): boolean;
270
+ export declare function applyPredictionGateStatus(current: PredictionGateStatus | null, message: PredictionGateMessage): PredictionGateStatus;
271
+ export interface AcceptedSessionBoundary {
272
+ context: SessionContext | null;
273
+ /** The last accepted authority event sequence; zero before the first. */
274
+ sequence: bigint;
275
+ receiptFloor: ReceiptRef | null;
276
+ /** The view last disclosed to this seat, or null while it is withheld. */
277
+ view: ViewSnapshot | null;
278
+ predictionGate: PredictionGateStatus | null;
279
+ /** Whether a viewless admission still owes its named prepared prefix. */
280
+ awaitingGatePrefix: boolean;
281
+ }
282
+ /** A refused event, named as `SessionSemanticError` names it. */
283
+ export declare class SessionBoundaryError extends Error {
284
+ readonly reason: string;
285
+ constructor(reason: string, detail: string);
286
+ }
287
+ /** The boundary a seat that has accepted nothing holds. */
288
+ export declare function freshSessionBoundary(): AcceptedSessionBoundary;
289
+ /** What the seam did with an event.
290
+ *
291
+ * `applied` is the only disposition that moved the boundary, and so the only
292
+ * one a consumer may act on: a re-delivery was applied and acknowledged once
293
+ * already, and acting on it a second time would decide a turn that is over,
294
+ * count a commit twice, or walk the acknowledged cursor backwards. */
295
+ export type AuthorityEventDisposition = "applied" | "replay" | "boundaryless";
296
+ export interface AdmittedAuthorityEvent {
297
+ disposition: AuthorityEventDisposition;
298
+ /** The boundary to retain. Unchanged unless the event was applied. */
299
+ boundary: AcceptedSessionBoundary;
300
+ }
301
+ export declare function admitAuthorityEvent(accepted: AcceptedSessionBoundary, message: AuthorityMessage): AdmittedAuthorityEvent;