@kyberonai/trailproof 0.1.0
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 +511 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +202 -0
- package/dist/index.d.ts +202 -0
- package/dist/index.js +479 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailproof error hierarchy.
|
|
3
|
+
*/
|
|
4
|
+
/** Base error for all Trailproof operations. */
|
|
5
|
+
declare class TrailproofError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/** Raised when event data is invalid (missing or empty required fields). */
|
|
9
|
+
declare class ValidationError extends TrailproofError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
/** Raised when a storage operation fails (disk, permissions, corruption). */
|
|
13
|
+
declare class StoreError extends TrailproofError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** Raised when the hash chain is broken. */
|
|
17
|
+
declare class ChainError extends TrailproofError {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
/** Raised when HMAC signature verification fails. */
|
|
21
|
+
declare class SignatureError extends TrailproofError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Trailproof core data types.
|
|
27
|
+
*/
|
|
28
|
+
/** A single event in the audit trail.
|
|
29
|
+
*
|
|
30
|
+
* Contains the 10-field event envelope. Domain-specific data
|
|
31
|
+
* goes in the payload field, which Trailproof stores opaquely.
|
|
32
|
+
*
|
|
33
|
+
* Field names use snake_case to match the wire format.
|
|
34
|
+
*/
|
|
35
|
+
interface TrailEvent {
|
|
36
|
+
readonly event_id: string;
|
|
37
|
+
readonly event_type: string;
|
|
38
|
+
readonly timestamp: string;
|
|
39
|
+
readonly actor_id: string;
|
|
40
|
+
readonly tenant_id: string;
|
|
41
|
+
readonly payload: Record<string, unknown>;
|
|
42
|
+
readonly prev_hash: string;
|
|
43
|
+
readonly hash: string;
|
|
44
|
+
readonly trace_id?: string | null;
|
|
45
|
+
readonly session_id?: string | null;
|
|
46
|
+
readonly signature?: string | null;
|
|
47
|
+
}
|
|
48
|
+
/** Filters for querying events from a store.
|
|
49
|
+
*
|
|
50
|
+
* All fields are optional. No filters returns all events up to limit.
|
|
51
|
+
*/
|
|
52
|
+
interface QueryFilters {
|
|
53
|
+
readonly event_type?: string | null;
|
|
54
|
+
readonly actor_id?: string | null;
|
|
55
|
+
readonly tenant_id?: string | null;
|
|
56
|
+
readonly trace_id?: string | null;
|
|
57
|
+
readonly session_id?: string | null;
|
|
58
|
+
readonly from_time?: string | null;
|
|
59
|
+
readonly to_time?: string | null;
|
|
60
|
+
readonly limit?: number;
|
|
61
|
+
readonly cursor?: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** Result of a query operation.
|
|
64
|
+
*
|
|
65
|
+
* Contains the matching events and an optional cursor for pagination.
|
|
66
|
+
*/
|
|
67
|
+
interface QueryResult {
|
|
68
|
+
readonly events: TrailEvent[];
|
|
69
|
+
readonly next_cursor: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** Result of a chain verification operation.
|
|
72
|
+
*
|
|
73
|
+
* intact is true when the entire chain is valid.
|
|
74
|
+
* broken contains the indices of events with invalid hashes.
|
|
75
|
+
*/
|
|
76
|
+
interface VerifyResult {
|
|
77
|
+
readonly intact: boolean;
|
|
78
|
+
readonly total: number;
|
|
79
|
+
readonly broken: number[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Abstract store interface for trail events.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Append-only storage backend for trail events.
|
|
88
|
+
*
|
|
89
|
+
* All store implementations must implement these five methods.
|
|
90
|
+
* Stores are append-only — events cannot be modified or deleted.
|
|
91
|
+
*/
|
|
92
|
+
interface TrailStore {
|
|
93
|
+
/** Append a single event to the store. */
|
|
94
|
+
append(event: TrailEvent): void;
|
|
95
|
+
/** Return all events in insertion order. */
|
|
96
|
+
readAll(): TrailEvent[];
|
|
97
|
+
/** Query events with optional filters and pagination. */
|
|
98
|
+
query(filters: QueryFilters): QueryResult;
|
|
99
|
+
/** Return the hash of the most recent event, or genesis hash if empty. */
|
|
100
|
+
lastHash(): string;
|
|
101
|
+
/** Return the total number of stored events. */
|
|
102
|
+
count(): number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Trailproof facade class — the main public API.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/** Options for constructing a Trailproof instance. */
|
|
110
|
+
interface TrailproofOptions {
|
|
111
|
+
/** Store type — "memory" (default) or "jsonl". */
|
|
112
|
+
store?: string;
|
|
113
|
+
/** File path for JSONL store. Required when store="jsonl". */
|
|
114
|
+
path?: string;
|
|
115
|
+
/** Optional HMAC-SHA256 key for event signing. */
|
|
116
|
+
signingKey?: string;
|
|
117
|
+
/** Default tenant_id used when emit() is called without one. */
|
|
118
|
+
defaultTenantId?: string;
|
|
119
|
+
}
|
|
120
|
+
/** Options for querying events. */
|
|
121
|
+
interface QueryOptions {
|
|
122
|
+
/** Filter by exact event type match. */
|
|
123
|
+
eventType?: string;
|
|
124
|
+
/** Filter by exact actor ID match. */
|
|
125
|
+
actorId?: string;
|
|
126
|
+
/** Filter by exact tenant ID match. */
|
|
127
|
+
tenantId?: string;
|
|
128
|
+
/** Filter by exact trace ID match. */
|
|
129
|
+
traceId?: string;
|
|
130
|
+
/** Filter by exact session ID match. */
|
|
131
|
+
sessionId?: string;
|
|
132
|
+
/** Include events at or after this ISO-8601 timestamp. */
|
|
133
|
+
fromTime?: string;
|
|
134
|
+
/** Include events at or before this ISO-8601 timestamp. */
|
|
135
|
+
toTime?: string;
|
|
136
|
+
/** Maximum number of events to return (default 100). */
|
|
137
|
+
limit?: number;
|
|
138
|
+
/** Resume pagination from this event_id. */
|
|
139
|
+
cursor?: string;
|
|
140
|
+
}
|
|
141
|
+
/** Options for emitting a new event. */
|
|
142
|
+
interface EmitOptions {
|
|
143
|
+
/** Namespaced event type (e.g., "memproof.memory.write"). */
|
|
144
|
+
eventType: string;
|
|
145
|
+
/** Who performed the action. */
|
|
146
|
+
actorId: string;
|
|
147
|
+
/** Domain-specific data (stored opaquely). */
|
|
148
|
+
payload: Record<string, unknown>;
|
|
149
|
+
/** Tenant/org isolation key. Falls back to defaultTenantId. */
|
|
150
|
+
tenantId?: string;
|
|
151
|
+
/** Optional cross-system correlation ID. */
|
|
152
|
+
traceId?: string;
|
|
153
|
+
/** Optional session grouping ID. */
|
|
154
|
+
sessionId?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Tamper-evident audit trail using hash chains and optional HMAC signing.
|
|
158
|
+
*
|
|
159
|
+
* The main entry point for recording, querying, and verifying events.
|
|
160
|
+
*/
|
|
161
|
+
declare class Trailproof {
|
|
162
|
+
/** @internal */
|
|
163
|
+
readonly _store: TrailStore;
|
|
164
|
+
private readonly _signingKey;
|
|
165
|
+
private readonly defaultTenantId;
|
|
166
|
+
constructor(options?: TrailproofOptions);
|
|
167
|
+
/**
|
|
168
|
+
* Record a new event in the audit trail.
|
|
169
|
+
*
|
|
170
|
+
* Validates required fields, generates event_id and timestamp,
|
|
171
|
+
* computes the hash chain link, and appends to the store.
|
|
172
|
+
*/
|
|
173
|
+
emit(options: EmitOptions): TrailEvent;
|
|
174
|
+
/**
|
|
175
|
+
* Query events with optional filters and cursor pagination.
|
|
176
|
+
*
|
|
177
|
+
* All filter parameters are optional. No filters returns all events
|
|
178
|
+
* up to the limit.
|
|
179
|
+
*/
|
|
180
|
+
query(options?: QueryOptions): QueryResult;
|
|
181
|
+
/**
|
|
182
|
+
* Return all events with the given trace_id, ordered by timestamp.
|
|
183
|
+
*/
|
|
184
|
+
getTrace(traceId: string): TrailEvent[];
|
|
185
|
+
/**
|
|
186
|
+
* Verify the integrity of the entire hash chain.
|
|
187
|
+
*
|
|
188
|
+
* Walks every event and recomputes its hash. If any event's hash
|
|
189
|
+
* does not match, that index and all subsequent indices are reported
|
|
190
|
+
* as broken (cascading breaks).
|
|
191
|
+
*/
|
|
192
|
+
verify(): VerifyResult;
|
|
193
|
+
/**
|
|
194
|
+
* Flush any buffered data to the underlying store.
|
|
195
|
+
*
|
|
196
|
+
* For MemoryStore this is a no-op.
|
|
197
|
+
*/
|
|
198
|
+
flush(): void;
|
|
199
|
+
private validateRequired;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { ChainError, type EmitOptions, type QueryFilters, type QueryOptions, type QueryResult, SignatureError, StoreError, type TrailEvent, Trailproof, TrailproofError, type TrailproofOptions, ValidationError, type VerifyResult };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trailproof error hierarchy.
|
|
3
|
+
*/
|
|
4
|
+
/** Base error for all Trailproof operations. */
|
|
5
|
+
declare class TrailproofError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
/** Raised when event data is invalid (missing or empty required fields). */
|
|
9
|
+
declare class ValidationError extends TrailproofError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
/** Raised when a storage operation fails (disk, permissions, corruption). */
|
|
13
|
+
declare class StoreError extends TrailproofError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
/** Raised when the hash chain is broken. */
|
|
17
|
+
declare class ChainError extends TrailproofError {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
/** Raised when HMAC signature verification fails. */
|
|
21
|
+
declare class SignatureError extends TrailproofError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Trailproof core data types.
|
|
27
|
+
*/
|
|
28
|
+
/** A single event in the audit trail.
|
|
29
|
+
*
|
|
30
|
+
* Contains the 10-field event envelope. Domain-specific data
|
|
31
|
+
* goes in the payload field, which Trailproof stores opaquely.
|
|
32
|
+
*
|
|
33
|
+
* Field names use snake_case to match the wire format.
|
|
34
|
+
*/
|
|
35
|
+
interface TrailEvent {
|
|
36
|
+
readonly event_id: string;
|
|
37
|
+
readonly event_type: string;
|
|
38
|
+
readonly timestamp: string;
|
|
39
|
+
readonly actor_id: string;
|
|
40
|
+
readonly tenant_id: string;
|
|
41
|
+
readonly payload: Record<string, unknown>;
|
|
42
|
+
readonly prev_hash: string;
|
|
43
|
+
readonly hash: string;
|
|
44
|
+
readonly trace_id?: string | null;
|
|
45
|
+
readonly session_id?: string | null;
|
|
46
|
+
readonly signature?: string | null;
|
|
47
|
+
}
|
|
48
|
+
/** Filters for querying events from a store.
|
|
49
|
+
*
|
|
50
|
+
* All fields are optional. No filters returns all events up to limit.
|
|
51
|
+
*/
|
|
52
|
+
interface QueryFilters {
|
|
53
|
+
readonly event_type?: string | null;
|
|
54
|
+
readonly actor_id?: string | null;
|
|
55
|
+
readonly tenant_id?: string | null;
|
|
56
|
+
readonly trace_id?: string | null;
|
|
57
|
+
readonly session_id?: string | null;
|
|
58
|
+
readonly from_time?: string | null;
|
|
59
|
+
readonly to_time?: string | null;
|
|
60
|
+
readonly limit?: number;
|
|
61
|
+
readonly cursor?: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** Result of a query operation.
|
|
64
|
+
*
|
|
65
|
+
* Contains the matching events and an optional cursor for pagination.
|
|
66
|
+
*/
|
|
67
|
+
interface QueryResult {
|
|
68
|
+
readonly events: TrailEvent[];
|
|
69
|
+
readonly next_cursor: string | null;
|
|
70
|
+
}
|
|
71
|
+
/** Result of a chain verification operation.
|
|
72
|
+
*
|
|
73
|
+
* intact is true when the entire chain is valid.
|
|
74
|
+
* broken contains the indices of events with invalid hashes.
|
|
75
|
+
*/
|
|
76
|
+
interface VerifyResult {
|
|
77
|
+
readonly intact: boolean;
|
|
78
|
+
readonly total: number;
|
|
79
|
+
readonly broken: number[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Abstract store interface for trail events.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Append-only storage backend for trail events.
|
|
88
|
+
*
|
|
89
|
+
* All store implementations must implement these five methods.
|
|
90
|
+
* Stores are append-only — events cannot be modified or deleted.
|
|
91
|
+
*/
|
|
92
|
+
interface TrailStore {
|
|
93
|
+
/** Append a single event to the store. */
|
|
94
|
+
append(event: TrailEvent): void;
|
|
95
|
+
/** Return all events in insertion order. */
|
|
96
|
+
readAll(): TrailEvent[];
|
|
97
|
+
/** Query events with optional filters and pagination. */
|
|
98
|
+
query(filters: QueryFilters): QueryResult;
|
|
99
|
+
/** Return the hash of the most recent event, or genesis hash if empty. */
|
|
100
|
+
lastHash(): string;
|
|
101
|
+
/** Return the total number of stored events. */
|
|
102
|
+
count(): number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Trailproof facade class — the main public API.
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/** Options for constructing a Trailproof instance. */
|
|
110
|
+
interface TrailproofOptions {
|
|
111
|
+
/** Store type — "memory" (default) or "jsonl". */
|
|
112
|
+
store?: string;
|
|
113
|
+
/** File path for JSONL store. Required when store="jsonl". */
|
|
114
|
+
path?: string;
|
|
115
|
+
/** Optional HMAC-SHA256 key for event signing. */
|
|
116
|
+
signingKey?: string;
|
|
117
|
+
/** Default tenant_id used when emit() is called without one. */
|
|
118
|
+
defaultTenantId?: string;
|
|
119
|
+
}
|
|
120
|
+
/** Options for querying events. */
|
|
121
|
+
interface QueryOptions {
|
|
122
|
+
/** Filter by exact event type match. */
|
|
123
|
+
eventType?: string;
|
|
124
|
+
/** Filter by exact actor ID match. */
|
|
125
|
+
actorId?: string;
|
|
126
|
+
/** Filter by exact tenant ID match. */
|
|
127
|
+
tenantId?: string;
|
|
128
|
+
/** Filter by exact trace ID match. */
|
|
129
|
+
traceId?: string;
|
|
130
|
+
/** Filter by exact session ID match. */
|
|
131
|
+
sessionId?: string;
|
|
132
|
+
/** Include events at or after this ISO-8601 timestamp. */
|
|
133
|
+
fromTime?: string;
|
|
134
|
+
/** Include events at or before this ISO-8601 timestamp. */
|
|
135
|
+
toTime?: string;
|
|
136
|
+
/** Maximum number of events to return (default 100). */
|
|
137
|
+
limit?: number;
|
|
138
|
+
/** Resume pagination from this event_id. */
|
|
139
|
+
cursor?: string;
|
|
140
|
+
}
|
|
141
|
+
/** Options for emitting a new event. */
|
|
142
|
+
interface EmitOptions {
|
|
143
|
+
/** Namespaced event type (e.g., "memproof.memory.write"). */
|
|
144
|
+
eventType: string;
|
|
145
|
+
/** Who performed the action. */
|
|
146
|
+
actorId: string;
|
|
147
|
+
/** Domain-specific data (stored opaquely). */
|
|
148
|
+
payload: Record<string, unknown>;
|
|
149
|
+
/** Tenant/org isolation key. Falls back to defaultTenantId. */
|
|
150
|
+
tenantId?: string;
|
|
151
|
+
/** Optional cross-system correlation ID. */
|
|
152
|
+
traceId?: string;
|
|
153
|
+
/** Optional session grouping ID. */
|
|
154
|
+
sessionId?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Tamper-evident audit trail using hash chains and optional HMAC signing.
|
|
158
|
+
*
|
|
159
|
+
* The main entry point for recording, querying, and verifying events.
|
|
160
|
+
*/
|
|
161
|
+
declare class Trailproof {
|
|
162
|
+
/** @internal */
|
|
163
|
+
readonly _store: TrailStore;
|
|
164
|
+
private readonly _signingKey;
|
|
165
|
+
private readonly defaultTenantId;
|
|
166
|
+
constructor(options?: TrailproofOptions);
|
|
167
|
+
/**
|
|
168
|
+
* Record a new event in the audit trail.
|
|
169
|
+
*
|
|
170
|
+
* Validates required fields, generates event_id and timestamp,
|
|
171
|
+
* computes the hash chain link, and appends to the store.
|
|
172
|
+
*/
|
|
173
|
+
emit(options: EmitOptions): TrailEvent;
|
|
174
|
+
/**
|
|
175
|
+
* Query events with optional filters and cursor pagination.
|
|
176
|
+
*
|
|
177
|
+
* All filter parameters are optional. No filters returns all events
|
|
178
|
+
* up to the limit.
|
|
179
|
+
*/
|
|
180
|
+
query(options?: QueryOptions): QueryResult;
|
|
181
|
+
/**
|
|
182
|
+
* Return all events with the given trace_id, ordered by timestamp.
|
|
183
|
+
*/
|
|
184
|
+
getTrace(traceId: string): TrailEvent[];
|
|
185
|
+
/**
|
|
186
|
+
* Verify the integrity of the entire hash chain.
|
|
187
|
+
*
|
|
188
|
+
* Walks every event and recomputes its hash. If any event's hash
|
|
189
|
+
* does not match, that index and all subsequent indices are reported
|
|
190
|
+
* as broken (cascading breaks).
|
|
191
|
+
*/
|
|
192
|
+
verify(): VerifyResult;
|
|
193
|
+
/**
|
|
194
|
+
* Flush any buffered data to the underlying store.
|
|
195
|
+
*
|
|
196
|
+
* For MemoryStore this is a no-op.
|
|
197
|
+
*/
|
|
198
|
+
flush(): void;
|
|
199
|
+
private validateRequired;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { ChainError, type EmitOptions, type QueryFilters, type QueryOptions, type QueryResult, SignatureError, StoreError, type TrailEvent, Trailproof, TrailproofError, type TrailproofOptions, ValidationError, type VerifyResult };
|