@xyo-network/event-kit-protocol 0.0.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.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # `@xyo-network/event-kit-protocol`
2
+
3
+ Transport-neutral verification and admission orchestration for Event Kit
4
+ wakes:
5
+
6
+ 1. Verify a real ES256K wallet JWT with the XYO SDK
7
+ 2. Bind JWT `eventHash` to the wake Payload data hash
8
+ 3. Bind the Payload to one immutable audience/deployment/queue/controller route
9
+ 4. Require a fresh, evidenced Statement Graph grant
10
+ 5. Resolve replay, logical idempotency, receipt creation, and durable enqueue
11
+ through one atomic inbox boundary
12
+
13
+ The D-002 split now exists as pure `verifyWakeRequest` plus stateful
14
+ `admitAndEnqueue` over explicit `WakeGrantAuthorizer` and `AtomicWakeInbox`
15
+ ports. Protocol code owns no cloud or transport SDK. The stateful layer invokes
16
+ injected I/O, while the inbox contract deliberately owns durable enqueue or a
17
+ transactional outbox instead of exposing a split queue callback. See Yellow
18
+ Paper §6 and §13.
19
+
20
+ D-002's target is a raw strict XYO Payload plus a real short-lived wallet JWT;
21
+ there is no separate event signature.
22
+
23
+ `createMemoryWakeInbox` ships one conformant `AtomicWakeInbox`: it serializes
24
+ the critical section, binds a fresh `jti` to an existing wake receipt, and hands
25
+ the wake to its sink before consuming either identity, so a failing sink leaves
26
+ the attempt retryable. It is single-process and loses state on restart — a
27
+ durable adapter and full runtime qualification are still pending, so this is not
28
+ production evidence.
29
+
30
+ The pre-D-002 `admitWake` / `acceptWake` callback scaffold, its injected crypto
31
+ port, the split `has`/`remember` replay store, and the `isPublisherEnabled`
32
+ grant viewer have been removed. `verifyWakeRequest` + `admitAndEnqueue` over
33
+ `WakeGrantAuthorizer` and `AtomicWakeInbox` are the only admission surface.
@@ -0,0 +1,110 @@
1
+ import type { DeploymentId, Hash, NormalizedAddress, WakeId, WakeJwtAudience, WakeJwtId } from '@xyo-network/event-kit-schemas';
2
+ import type { AdmittedWake } from './types.ts';
3
+ /** Replay records survive token expiry by this amount to cover receiver skew. */
4
+ export declare const EVENT_KIT_REPLAY_RETENTION_SKEW_SECONDS = 60;
5
+ export interface WakeGrantAuthorizationRequest {
6
+ readonly controller: NormalizedAddress;
7
+ readonly deploymentId: DeploymentId;
8
+ readonly expectedHead: number;
9
+ readonly publisher: NormalizedAddress;
10
+ readonly queueId?: string;
11
+ }
12
+ /** Concrete grant evidence required for every enabled decision. */
13
+ export interface WakeGrantEvidence {
14
+ readonly assertedAtBlock: number;
15
+ readonly controller: NormalizedAddress;
16
+ readonly deploymentId: DeploymentId;
17
+ readonly id: string;
18
+ readonly queueId?: string;
19
+ readonly target: NormalizedAddress;
20
+ }
21
+ export interface WakeGrantAuthorizationDisabled {
22
+ readonly atBlock: number;
23
+ readonly enabled: false;
24
+ /** Optional diagnostics. The core rejects disagreement with its trusted input. */
25
+ readonly expectedHead?: number;
26
+ /** Optional diagnostics. The core recomputes lag instead of trusting this value. */
27
+ readonly lag?: number;
28
+ }
29
+ export interface WakeGrantAuthorizationEnabled {
30
+ readonly atBlock: number;
31
+ readonly enabled: true;
32
+ /** Optional diagnostics. The core rejects disagreement with its trusted input. */
33
+ readonly expectedHead?: number;
34
+ readonly grant: WakeGrantEvidence;
35
+ /** Optional diagnostics. The core recomputes lag instead of trusting this value. */
36
+ readonly lag?: number;
37
+ }
38
+ export type WakeGrantAuthorizationDecision = WakeGrantAuthorizationDisabled | WakeGrantAuthorizationEnabled;
39
+ /**
40
+ * Stateful Statement Graph authorization port. Implementations must evaluate
41
+ * the exact controller, scope, publisher, and expected finalized head supplied
42
+ * for this request.
43
+ */
44
+ export interface WakeGrantAuthorizer {
45
+ authorizePublisher: (request: WakeGrantAuthorizationRequest) => Promise<WakeGrantAuthorizationDecision>;
46
+ }
47
+ /** Normalized grant snapshot accepted by the protocol core. */
48
+ export interface AuthorizedWakeGrant {
49
+ readonly atBlock: number;
50
+ readonly expectedHead: number;
51
+ readonly grant: WakeGrantEvidence;
52
+ readonly lag: number;
53
+ }
54
+ export interface WakeAdmissionAttempt {
55
+ readonly audience: WakeJwtAudience;
56
+ readonly eventHash: Hash;
57
+ readonly jwtId: WakeJwtId;
58
+ readonly publisher: NormalizedAddress;
59
+ /** Token replay record retention deadline (`exp + 60`). */
60
+ readonly retainJwtUntil: number;
61
+ readonly wakeId: WakeId;
62
+ }
63
+ /** Stable receipt bound to both durable admission indexes. */
64
+ export interface WakeAdmissionReceipt {
65
+ readonly audience: WakeJwtAudience;
66
+ readonly eventHash: Hash;
67
+ readonly id: string;
68
+ readonly publisher: NormalizedAddress;
69
+ readonly wakeId: WakeId;
70
+ }
71
+ export type WakeAttemptResolution = {
72
+ readonly kind: 'new';
73
+ } | {
74
+ readonly kind: 'duplicate';
75
+ readonly receipt: WakeAdmissionReceipt;
76
+ } | {
77
+ readonly kind: 'jwt-id-collision';
78
+ } | {
79
+ readonly kind: 'wake-id-collision';
80
+ };
81
+ export type WakeCommitResult = {
82
+ readonly kind: 'enqueued';
83
+ readonly receipt: WakeAdmissionReceipt;
84
+ } | {
85
+ readonly kind: 'duplicate';
86
+ readonly receipt: WakeAdmissionReceipt;
87
+ } | {
88
+ readonly kind: 'jwt-id-collision';
89
+ } | {
90
+ readonly kind: 'wake-id-collision';
91
+ };
92
+ /**
93
+ * Durable linearizable admission boundary.
94
+ *
95
+ * `resolveAttempt` must atomically bind a fresh JWT id to an existing matching
96
+ * wake receipt. It must not consume either identity when returning `new`.
97
+ *
98
+ * `commitAuthorized` must atomically recheck both identities, persist both
99
+ * mappings and their stable receipt, and durably enqueue the wake (or write a
100
+ * transactional outbox record). A separate fallible enqueue is nonconforming.
101
+ */
102
+ export interface AtomicWakeInbox {
103
+ commitAuthorized: (input: {
104
+ readonly attempt: WakeAdmissionAttempt;
105
+ readonly grant: AuthorizedWakeGrant;
106
+ readonly wake: AdmittedWake;
107
+ }) => Promise<WakeCommitResult>;
108
+ resolveAttempt: (attempt: WakeAdmissionAttempt) => Promise<WakeAttemptResolution>;
109
+ }
110
+ //# sourceMappingURL=admissionTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admissionTypes.d.ts","sourceRoot":"","sources":["../../src/admissionTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,IAAI,EACJ,iBAAiB,EACjB,MAAM,EACN,eAAe,EACf,SAAS,EACV,MAAM,gCAAgC,CAAA;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAE9C,iFAAiF;AACjF,eAAO,MAAM,uCAAuC,KAAK,CAAA;AAEzD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAA;IACtC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAA;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAC1B;AAED,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,UAAU,EAAE,iBAAiB,CAAA;IACtC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CACnC;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAA;IACvB,kFAAkF;IAClF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,oFAAoF;IACpF,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,6BAA6B;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AAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,MAAM,qBAAqB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAA;CAAE,GACxB;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE5C,MAAM,MAAM,gBAAgB,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GACrE;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;CAAE,CAAA;AAE5C;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,CAAC,KAAK,EAAE;QACxB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;QACtC,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAA;QACnC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;KAC5B,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC/B,cAAc,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAA;CAClF"}
@@ -0,0 +1,29 @@
1
+ import type { AtomicWakeInbox, WakeAdmissionReceipt, WakeGrantAuthorizer } from './admissionTypes.ts';
2
+ import type { AdmittedWake } from './types.ts';
3
+ import type { VerifiedWakeRequest } from './verifyWakeRequest.ts';
4
+ export interface AdmitAndEnqueueInput {
5
+ /** Independently trusted finalized XL1 head for this admission attempt. */
6
+ readonly expectedHead: number;
7
+ readonly grants: WakeGrantAuthorizer;
8
+ readonly inbox: AtomicWakeInbox;
9
+ readonly verified: VerifiedWakeRequest;
10
+ }
11
+ export type AdmitAndEnqueueFailureReason = 'grant-missing' | 'grant-unavailable' | 'grant-view-invalid' | 'grant-view-stale' | 'inbox-unavailable' | 'jwt-id-collision' | 'wake-id-collision';
12
+ export interface AdmitAndEnqueueFailure {
13
+ readonly details?: readonly string[];
14
+ readonly ok: false;
15
+ readonly reason: AdmitAndEnqueueFailureReason;
16
+ }
17
+ export interface AdmitAndEnqueueSuccess {
18
+ readonly disposition: 'duplicate' | 'enqueued';
19
+ readonly ok: true;
20
+ readonly receipt: WakeAdmissionReceipt;
21
+ readonly wake: AdmittedWake;
22
+ }
23
+ export type AdmitAndEnqueueResult = AdmitAndEnqueueFailure | AdmitAndEnqueueSuccess;
24
+ /**
25
+ * Performs D-002 durable replay/idempotency resolution, live grant
26
+ * authorization, and atomic enqueue after pure request verification.
27
+ */
28
+ export declare function admitAndEnqueue(input: AdmitAndEnqueueInput): Promise<AdmitAndEnqueueResult>;
29
+ //# sourceMappingURL=admitAndEnqueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admitAndEnqueue.d.ts","sourceRoot":"","sources":["../../src/admitAndEnqueue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,oBAAoB,EAGpB,mBAAmB,EAEpB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAEjE,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,MAAM,EAAE,mBAAmB,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;IAC/B,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAA;CACvC;AAED,MAAM,MAAM,4BAA4B,GAClC,eAAe,GACf,mBAAmB,GACnB,oBAAoB,GACpB,kBAAkB,GAClB,mBAAmB,GACnB,kBAAkB,GAClB,mBAAmB,CAAA;AAEzB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;IAClB,QAAQ,CAAC,MAAM,EAAE,4BAA4B,CAAA;CAC9C;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAAA;IAC9C,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAA;IACjB,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;IACtC,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAC5B;AAED,MAAM,MAAM,qBAAqB,GAAG,sBAAsB,GAAG,sBAAsB,CAAA;AAEnF;;;GAGG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAgBjG"}
@@ -0,0 +1,19 @@
1
+ export type { AtomicWakeInbox, AuthorizedWakeGrant, WakeAdmissionAttempt, WakeAdmissionReceipt, WakeAttemptResolution, WakeCommitResult, WakeGrantAuthorizationDecision, WakeGrantAuthorizationDisabled, WakeGrantAuthorizationEnabled, WakeGrantAuthorizationRequest, WakeGrantAuthorizer, WakeGrantEvidence, } from './admissionTypes.ts';
2
+ export { EVENT_KIT_REPLAY_RETENTION_SKEW_SECONDS } from './admissionTypes.ts';
3
+ export type { AdmitAndEnqueueFailure, AdmitAndEnqueueFailureReason, AdmitAndEnqueueInput, AdmitAndEnqueueResult, AdmitAndEnqueueSuccess, } from './admitAndEnqueue.ts';
4
+ export { admitAndEnqueue } from './admitAndEnqueue.ts';
5
+ export type { MemoryStatementGrantGraph } from './memoryStatementGrantGraph.ts';
6
+ export { createMemoryStatementGrantGraph } from './memoryStatementGrantGraph.ts';
7
+ export type { MemoryWakeInbox, MemoryWakeInboxOptions, } from './memoryWakeInbox.ts';
8
+ export { createMemoryWakeInbox } from './memoryWakeInbox.ts';
9
+ export type { MemoryWakeQueue } from './memoryWakeQueue.ts';
10
+ export { createMemoryWakeQueue } from './memoryWakeQueue.ts';
11
+ export type { StatementGrantClaim, StatementGrantClaimQuery, StatementGrantObject, StatementGraphGrantReadModel, } from './statementGraphPorts.ts';
12
+ export type { StatementGraphWakeGrantAuthorizerOptions } from './statementGraphWakeGrantAuthorizer.ts';
13
+ export { createStatementGraphWakeGrantAuthorizer } from './statementGraphWakeGrantAuthorizer.ts';
14
+ export type { AdmittedWake } from './types.ts';
15
+ export type { VerifiedWakeRequest, VerifyWakeRequestFailure, VerifyWakeRequestInput, VerifyWakeRequestRejectionReason, VerifyWakeRequestResult, VerifyWakeRequestSuccess, WakeAdmissionRoute, } from './verifyWakeRequest.ts';
16
+ export { EVENT_KIT_MAX_FUTURE_IAT_SECONDS, EVENT_KIT_MAX_JWT_LIFETIME_SECONDS, verifyWakeRequest, } from './verifyWakeRequest.ts';
17
+ export type { LeasedWake, WakeHandler, WakeQueue, } from './wakeQueue.ts';
18
+ export { drainQueue } from './wakeQueue.ts';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,EAC7B,6BAA6B,EAC7B,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,uCAAuC,EAAE,MAAM,qBAAqB,CAAA;AAC7E,YAAY,EACV,sB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