@axtary/ledger 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 +35 -0
- package/dist/index.d.ts +324 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +382 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @axtary/ledger
|
|
2
|
+
|
|
3
|
+
Append-only JSONL action ledger with hash-chain verification for Axtary.
|
|
4
|
+
|
|
5
|
+
This package is private workspace code while the local runtime plane is still being shaped.
|
|
6
|
+
|
|
7
|
+
## What It Does
|
|
8
|
+
|
|
9
|
+
- Appends Axtary ledger records to local JSONL.
|
|
10
|
+
- Maintains a `previousLedgerHash -> ledgerHash` chain.
|
|
11
|
+
- Reads ledger records back in order.
|
|
12
|
+
- Verifies hash-chain continuity and record integrity.
|
|
13
|
+
- Exports verified records by inclusive date range and decision type.
|
|
14
|
+
- Formats verified exports as JSON, raw ledger JSONL, or SIEM-friendly JSONL events.
|
|
15
|
+
- Syncs a verified export to an optional hosted endpoint.
|
|
16
|
+
- Fails closed on malformed JSONL records.
|
|
17
|
+
- Carries trace IDs and sanitized provider evidence for GitHub, Slack, and Linear records when that evidence was present at decision time.
|
|
18
|
+
|
|
19
|
+
## Design Notes
|
|
20
|
+
|
|
21
|
+
The ledger is local-first. It is not a database, SIEM, or remote audit service. It gives the proxy and adapters a durable local trail that can later be uploaded, exported, or re-verified. Export and sync both verify the full hash chain before returning or sending filtered records. SIEM JSONL events include timestamps, trace IDs, outcomes, provider/resource summaries, policy metadata, reasons, and hashes without expanding protected action payloads or credential-bearing provider responses.
|
|
22
|
+
|
|
23
|
+
Hosted sync should use signed ledger sync tokens rather than dashboard user sessions. Sync tokens carry a signed `kid` so hosted verification can rotate keys with `AXTARY_LEDGER_SYNC_TOKEN_KID` and a JSON `AXTARY_LEDGER_SYNC_TOKEN_SECRETS` keyring. Hosted retention can be bounded with `AXTARY_LEDGER_SYNC_MAX_BATCHES`, `AXTARY_LEDGER_SYNC_MAX_AGE_DAYS`, or stricter limits embedded in the signed sync token.
|
|
24
|
+
|
|
25
|
+
The hosted sync store now sits behind a persistence adapter. The default adapter is local JSON at `.axtary/hosted-ledger-sync.json`; set `AXTARY_LEDGER_SYNC_STORE=neon` plus `AXTARY_LEDGER_SYNC_DATABASE_URL` to use the Neon/Postgres adapter. Apply `migrations/neon/001_hosted_ledger_sync_batches.sql` for deployed environments; `docs/neon-hosted-sync-runbook.md` covers the hosted setup and verification flow. Source file paths can be reduced before storage with `AXTARY_LEDGER_SYNC_REDACT_SOURCE_FILE_PATH=basename` or `redact`. Hash-bound ledger record fields are preserved so synced evidence remains verifiable.
|
|
26
|
+
|
|
27
|
+
Hosted audit search is available through `/api/ledger/sync?view=records` with optional `q`, `decision`, `from`, `to`, and `limit` query parameters. The ledger dashboard exposes those filters for tenant-scoped synced evidence, including record detail inspection, normalized provider resources, GitHub diff/file summaries, Slack channel/message evidence, Linear issue field changes, trace IDs, and batch-id drilldown. SIEM exports remain available through `/api/ledger/sync?format=siem-jsonl`.
|
|
28
|
+
|
|
29
|
+
Fail-closed and secret boundaries:
|
|
30
|
+
|
|
31
|
+
- Ledger export fails if any source record breaks JSON parsing, previous-hash continuity, or record-hash integrity.
|
|
32
|
+
- Hosted sync accepts only verified exports through the sync route and keeps provider credentials, sync tokens, dashboard sessions, cookies, and auth headers out of stored batches and browser payloads.
|
|
33
|
+
- Provider evidence is extracted from normalized actions, not raw provider HTTP responses. GitHub content payloads record paths and lengths rather than file bodies unless an explicit sanitized diff is supplied.
|
|
34
|
+
|
|
35
|
+
Concurrent writers should coordinate through a single process or external file lock. The first proxy should own writes for a given ledger file.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { type LedgerRecord, type NormalizedAction, type PolicyDecision } from "@axtary/actionpass";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const LOCAL_LEDGER_SCHEMA_VERSION = "axtary.local-ledger.v0";
|
|
4
|
+
export declare const LEDGER_EXPORT_SCHEMA_VERSION = "axtary.ledger_export.v0";
|
|
5
|
+
export declare const LEDGER_SYNC_SCHEMA_VERSION = "axtary.ledger_sync.v0";
|
|
6
|
+
export declare const LEDGER_SIEM_EVENT_SCHEMA_VERSION = "axtary.siem_event.v0";
|
|
7
|
+
export declare const LedgerAppendResultSchema: z.ZodObject<{
|
|
8
|
+
record: z.ZodObject<{
|
|
9
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger.v0">;
|
|
10
|
+
id: z.ZodString;
|
|
11
|
+
occurredAt: z.ZodString;
|
|
12
|
+
actionHash: z.ZodString;
|
|
13
|
+
payloadHash: z.ZodString;
|
|
14
|
+
decision: z.ZodEnum<{
|
|
15
|
+
allow: "allow";
|
|
16
|
+
deny: "deny";
|
|
17
|
+
step_up: "step_up";
|
|
18
|
+
}>;
|
|
19
|
+
reasons: z.ZodArray<z.ZodString>;
|
|
20
|
+
policy: z.ZodObject<{
|
|
21
|
+
nativeRule: z.ZodString;
|
|
22
|
+
version: z.ZodString;
|
|
23
|
+
cedarCompatible: z.ZodBoolean;
|
|
24
|
+
opaCompatible: z.ZodBoolean;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
providerEvidence: z.ZodOptional<z.ZodObject<{
|
|
27
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger_provider_evidence.v0">;
|
|
28
|
+
provider: z.ZodEnum<{
|
|
29
|
+
github: "github";
|
|
30
|
+
slack: "slack";
|
|
31
|
+
linear: "linear";
|
|
32
|
+
}>;
|
|
33
|
+
tool: z.ZodString;
|
|
34
|
+
operation: z.ZodString;
|
|
35
|
+
resource: z.ZodObject<{
|
|
36
|
+
provider: z.ZodEnum<{
|
|
37
|
+
github: "github";
|
|
38
|
+
slack: "slack";
|
|
39
|
+
linear: "linear";
|
|
40
|
+
}>;
|
|
41
|
+
kind: z.ZodString;
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
label: z.ZodOptional<z.ZodString>;
|
|
44
|
+
url: z.ZodOptional<z.ZodString>;
|
|
45
|
+
}, z.core.$strict>;
|
|
46
|
+
normalized: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>>;
|
|
47
|
+
fieldChanges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
48
|
+
field: z.ZodString;
|
|
49
|
+
before: z.ZodOptional<z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>;
|
|
50
|
+
after: z.ZodOptional<z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>;
|
|
51
|
+
}, z.core.$strip>>>;
|
|
52
|
+
diff: z.ZodOptional<z.ZodObject<{
|
|
53
|
+
provider: z.ZodEnum<{
|
|
54
|
+
github: "github";
|
|
55
|
+
slack: "slack";
|
|
56
|
+
linear: "linear";
|
|
57
|
+
}>;
|
|
58
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
59
|
+
files: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
60
|
+
path: z.ZodString;
|
|
61
|
+
oldPath: z.ZodOptional<z.ZodString>;
|
|
62
|
+
status: z.ZodEnum<{
|
|
63
|
+
added: "added";
|
|
64
|
+
modified: "modified";
|
|
65
|
+
deleted: "deleted";
|
|
66
|
+
renamed: "renamed";
|
|
67
|
+
}>;
|
|
68
|
+
additions: z.ZodDefault<z.ZodNumber>;
|
|
69
|
+
deletions: z.ZodDefault<z.ZodNumber>;
|
|
70
|
+
hunks: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
71
|
+
header: z.ZodString;
|
|
72
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
73
|
+
type: z.ZodEnum<{
|
|
74
|
+
context: "context";
|
|
75
|
+
addition: "addition";
|
|
76
|
+
deletion: "deletion";
|
|
77
|
+
}>;
|
|
78
|
+
content: z.ZodString;
|
|
79
|
+
oldLine: z.ZodOptional<z.ZodNumber>;
|
|
80
|
+
newLine: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
}, z.core.$strip>>>;
|
|
83
|
+
}, z.core.$strip>>>;
|
|
84
|
+
}, z.core.$strip>>;
|
|
85
|
+
}, z.core.$strip>>;
|
|
86
|
+
traceId: z.ZodOptional<z.ZodString>;
|
|
87
|
+
actionPassId: z.ZodNullable<z.ZodString>;
|
|
88
|
+
previousLedgerHash: z.ZodNullable<z.ZodString>;
|
|
89
|
+
ledgerHash: z.ZodString;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
lineNumber: z.ZodNumber;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
export type LedgerAppendResult = z.infer<typeof LedgerAppendResultSchema>;
|
|
94
|
+
export type AppendDecisionInput = {
|
|
95
|
+
action: NormalizedAction;
|
|
96
|
+
decision: PolicyDecision;
|
|
97
|
+
actionPassId?: string | null;
|
|
98
|
+
occurredAt?: Date;
|
|
99
|
+
};
|
|
100
|
+
export type VerifyLedgerResult = {
|
|
101
|
+
valid: true;
|
|
102
|
+
records: LedgerRecord[];
|
|
103
|
+
lastLedgerHash: string | null;
|
|
104
|
+
} | {
|
|
105
|
+
valid: false;
|
|
106
|
+
records: LedgerRecord[];
|
|
107
|
+
lineNumber: number;
|
|
108
|
+
reason: string;
|
|
109
|
+
};
|
|
110
|
+
export declare const LedgerExportFilterSchema: z.ZodObject<{
|
|
111
|
+
from: z.ZodNullable<z.ZodString>;
|
|
112
|
+
to: z.ZodNullable<z.ZodString>;
|
|
113
|
+
decisions: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
114
|
+
allow: "allow";
|
|
115
|
+
deny: "deny";
|
|
116
|
+
step_up: "step_up";
|
|
117
|
+
}>>>;
|
|
118
|
+
}, z.core.$strip>;
|
|
119
|
+
export type LedgerExportFilter = z.infer<typeof LedgerExportFilterSchema>;
|
|
120
|
+
export declare const LedgerExportSchema: z.ZodObject<{
|
|
121
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger_export.v0">;
|
|
122
|
+
exportedAt: z.ZodString;
|
|
123
|
+
source: z.ZodObject<{
|
|
124
|
+
filePath: z.ZodString;
|
|
125
|
+
totalRecords: z.ZodNumber;
|
|
126
|
+
lastLedgerHash: z.ZodNullable<z.ZodString>;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
filters: z.ZodObject<{
|
|
129
|
+
from: z.ZodNullable<z.ZodString>;
|
|
130
|
+
to: z.ZodNullable<z.ZodString>;
|
|
131
|
+
decisions: z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
132
|
+
allow: "allow";
|
|
133
|
+
deny: "deny";
|
|
134
|
+
step_up: "step_up";
|
|
135
|
+
}>>>;
|
|
136
|
+
}, z.core.$strip>;
|
|
137
|
+
records: z.ZodArray<z.ZodObject<{
|
|
138
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger.v0">;
|
|
139
|
+
id: z.ZodString;
|
|
140
|
+
occurredAt: z.ZodString;
|
|
141
|
+
actionHash: z.ZodString;
|
|
142
|
+
payloadHash: z.ZodString;
|
|
143
|
+
decision: z.ZodEnum<{
|
|
144
|
+
allow: "allow";
|
|
145
|
+
deny: "deny";
|
|
146
|
+
step_up: "step_up";
|
|
147
|
+
}>;
|
|
148
|
+
reasons: z.ZodArray<z.ZodString>;
|
|
149
|
+
policy: z.ZodObject<{
|
|
150
|
+
nativeRule: z.ZodString;
|
|
151
|
+
version: z.ZodString;
|
|
152
|
+
cedarCompatible: z.ZodBoolean;
|
|
153
|
+
opaCompatible: z.ZodBoolean;
|
|
154
|
+
}, z.core.$strip>;
|
|
155
|
+
providerEvidence: z.ZodOptional<z.ZodObject<{
|
|
156
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger_provider_evidence.v0">;
|
|
157
|
+
provider: z.ZodEnum<{
|
|
158
|
+
github: "github";
|
|
159
|
+
slack: "slack";
|
|
160
|
+
linear: "linear";
|
|
161
|
+
}>;
|
|
162
|
+
tool: z.ZodString;
|
|
163
|
+
operation: z.ZodString;
|
|
164
|
+
resource: z.ZodObject<{
|
|
165
|
+
provider: z.ZodEnum<{
|
|
166
|
+
github: "github";
|
|
167
|
+
slack: "slack";
|
|
168
|
+
linear: "linear";
|
|
169
|
+
}>;
|
|
170
|
+
kind: z.ZodString;
|
|
171
|
+
id: z.ZodString;
|
|
172
|
+
label: z.ZodOptional<z.ZodString>;
|
|
173
|
+
url: z.ZodOptional<z.ZodString>;
|
|
174
|
+
}, z.core.$strict>;
|
|
175
|
+
normalized: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>>;
|
|
176
|
+
fieldChanges: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
177
|
+
field: z.ZodString;
|
|
178
|
+
before: z.ZodOptional<z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>;
|
|
179
|
+
after: z.ZodOptional<z.ZodType<import("@axtary/actionpass").JsonValue, unknown, z.core.$ZodTypeInternals<import("@axtary/actionpass").JsonValue, unknown>>>;
|
|
180
|
+
}, z.core.$strip>>>;
|
|
181
|
+
diff: z.ZodOptional<z.ZodObject<{
|
|
182
|
+
provider: z.ZodEnum<{
|
|
183
|
+
github: "github";
|
|
184
|
+
slack: "slack";
|
|
185
|
+
linear: "linear";
|
|
186
|
+
}>;
|
|
187
|
+
summary: z.ZodOptional<z.ZodString>;
|
|
188
|
+
files: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
189
|
+
path: z.ZodString;
|
|
190
|
+
oldPath: z.ZodOptional<z.ZodString>;
|
|
191
|
+
status: z.ZodEnum<{
|
|
192
|
+
added: "added";
|
|
193
|
+
modified: "modified";
|
|
194
|
+
deleted: "deleted";
|
|
195
|
+
renamed: "renamed";
|
|
196
|
+
}>;
|
|
197
|
+
additions: z.ZodDefault<z.ZodNumber>;
|
|
198
|
+
deletions: z.ZodDefault<z.ZodNumber>;
|
|
199
|
+
hunks: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
200
|
+
header: z.ZodString;
|
|
201
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
202
|
+
type: z.ZodEnum<{
|
|
203
|
+
context: "context";
|
|
204
|
+
addition: "addition";
|
|
205
|
+
deletion: "deletion";
|
|
206
|
+
}>;
|
|
207
|
+
content: z.ZodString;
|
|
208
|
+
oldLine: z.ZodOptional<z.ZodNumber>;
|
|
209
|
+
newLine: z.ZodOptional<z.ZodNumber>;
|
|
210
|
+
}, z.core.$strip>>;
|
|
211
|
+
}, z.core.$strip>>>;
|
|
212
|
+
}, z.core.$strip>>>;
|
|
213
|
+
}, z.core.$strip>>;
|
|
214
|
+
}, z.core.$strip>>;
|
|
215
|
+
traceId: z.ZodOptional<z.ZodString>;
|
|
216
|
+
actionPassId: z.ZodNullable<z.ZodString>;
|
|
217
|
+
previousLedgerHash: z.ZodNullable<z.ZodString>;
|
|
218
|
+
ledgerHash: z.ZodString;
|
|
219
|
+
}, z.core.$strip>>;
|
|
220
|
+
}, z.core.$strip>;
|
|
221
|
+
export type LedgerExport = z.infer<typeof LedgerExportSchema>;
|
|
222
|
+
export declare const LedgerExportFormatSchema: z.ZodEnum<{
|
|
223
|
+
json: "json";
|
|
224
|
+
jsonl: "jsonl";
|
|
225
|
+
"siem-jsonl": "siem-jsonl";
|
|
226
|
+
}>;
|
|
227
|
+
export type LedgerExportFormat = z.infer<typeof LedgerExportFormatSchema>;
|
|
228
|
+
export declare const LedgerSiemEventSchema: z.ZodObject<{
|
|
229
|
+
"@timestamp": z.ZodString;
|
|
230
|
+
schemaVersion: z.ZodLiteral<"axtary.siem_event.v0">;
|
|
231
|
+
event: z.ZodObject<{
|
|
232
|
+
kind: z.ZodLiteral<"event">;
|
|
233
|
+
category: z.ZodArray<z.ZodString>;
|
|
234
|
+
type: z.ZodArray<z.ZodString>;
|
|
235
|
+
action: z.ZodLiteral<"axtary.policy.decision">;
|
|
236
|
+
outcome: z.ZodEnum<{
|
|
237
|
+
unknown: "unknown";
|
|
238
|
+
success: "success";
|
|
239
|
+
failure: "failure";
|
|
240
|
+
}>;
|
|
241
|
+
}, z.core.$strip>;
|
|
242
|
+
axtary: z.ZodObject<{
|
|
243
|
+
ledger: z.ZodObject<{
|
|
244
|
+
id: z.ZodString;
|
|
245
|
+
hash: z.ZodString;
|
|
246
|
+
previousHash: z.ZodNullable<z.ZodString>;
|
|
247
|
+
sourceHash: z.ZodNullable<z.ZodString>;
|
|
248
|
+
}, z.core.$strip>;
|
|
249
|
+
trace: z.ZodObject<{
|
|
250
|
+
id: z.ZodNullable<z.ZodString>;
|
|
251
|
+
}, z.core.$strip>;
|
|
252
|
+
action: z.ZodObject<{
|
|
253
|
+
hash: z.ZodString;
|
|
254
|
+
payloadHash: z.ZodString;
|
|
255
|
+
passId: z.ZodNullable<z.ZodString>;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
decision: z.ZodObject<{
|
|
258
|
+
value: z.ZodEnum<{
|
|
259
|
+
allow: "allow";
|
|
260
|
+
deny: "deny";
|
|
261
|
+
step_up: "step_up";
|
|
262
|
+
}>;
|
|
263
|
+
reasons: z.ZodArray<z.ZodString>;
|
|
264
|
+
policyVersion: z.ZodString;
|
|
265
|
+
nativeRule: z.ZodString;
|
|
266
|
+
}, z.core.$strip>;
|
|
267
|
+
provider: z.ZodOptional<z.ZodObject<{
|
|
268
|
+
name: z.ZodEnum<{
|
|
269
|
+
github: "github";
|
|
270
|
+
slack: "slack";
|
|
271
|
+
linear: "linear";
|
|
272
|
+
}>;
|
|
273
|
+
tool: z.ZodString;
|
|
274
|
+
operation: z.ZodString;
|
|
275
|
+
resourceKind: z.ZodString;
|
|
276
|
+
resourceId: z.ZodString;
|
|
277
|
+
}, z.core.$strip>>;
|
|
278
|
+
}, z.core.$strip>;
|
|
279
|
+
}, z.core.$strip>;
|
|
280
|
+
export type LedgerSiemEvent = z.infer<typeof LedgerSiemEventSchema>;
|
|
281
|
+
export type FormatLedgerExportInput = {
|
|
282
|
+
export: LedgerExport;
|
|
283
|
+
format?: LedgerExportFormat;
|
|
284
|
+
};
|
|
285
|
+
export declare const LedgerSyncResultSchema: z.ZodObject<{
|
|
286
|
+
schemaVersion: z.ZodLiteral<"axtary.ledger_sync.v0">;
|
|
287
|
+
endpoint: z.ZodString;
|
|
288
|
+
syncedAt: z.ZodString;
|
|
289
|
+
status: z.ZodNumber;
|
|
290
|
+
records: z.ZodNumber;
|
|
291
|
+
lastLedgerHash: z.ZodNullable<z.ZodString>;
|
|
292
|
+
response: z.ZodNullable<z.ZodUnknown>;
|
|
293
|
+
}, z.core.$strip>;
|
|
294
|
+
export type LedgerSyncResult = z.infer<typeof LedgerSyncResultSchema>;
|
|
295
|
+
export type ExportLedgerRecordsInput = {
|
|
296
|
+
filePath: string;
|
|
297
|
+
from?: Date | string | null;
|
|
298
|
+
to?: Date | string | null;
|
|
299
|
+
decisions?: Array<LedgerRecord["decision"]> | null;
|
|
300
|
+
exportedAt?: Date;
|
|
301
|
+
};
|
|
302
|
+
export type SyncLedgerExportInput = {
|
|
303
|
+
endpoint: string;
|
|
304
|
+
export: LedgerExport;
|
|
305
|
+
tenant?: string;
|
|
306
|
+
token?: string;
|
|
307
|
+
fetch?: typeof fetch;
|
|
308
|
+
timeoutMs?: number;
|
|
309
|
+
};
|
|
310
|
+
export declare class LocalJsonlLedger {
|
|
311
|
+
readonly filePath: string;
|
|
312
|
+
constructor(filePath: string);
|
|
313
|
+
appendDecision(input: AppendDecisionInput): Promise<LedgerAppendResult>;
|
|
314
|
+
appendRecord(recordInput: LedgerRecord): Promise<LedgerAppendResult>;
|
|
315
|
+
readRecords(): Promise<LedgerRecord[]>;
|
|
316
|
+
verify(): Promise<VerifyLedgerResult>;
|
|
317
|
+
}
|
|
318
|
+
export declare function readLedgerRecords(filePath: string): Promise<LedgerRecord[]>;
|
|
319
|
+
export declare function verifyLedgerFile(filePath: string): Promise<VerifyLedgerResult>;
|
|
320
|
+
export declare function exportLedgerRecords(input: ExportLedgerRecordsInput): Promise<LedgerExport>;
|
|
321
|
+
export declare function syncLedgerExport(input: SyncLedgerExportInput): Promise<LedgerSyncResult>;
|
|
322
|
+
export declare function formatLedgerExport(input: FormatLedgerExportInput): string;
|
|
323
|
+
export declare function computeLedgerHash(record: Omit<LedgerRecord, "ledgerHash">): string;
|
|
324
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,2BAA2B,2BAA2B,CAAC;AACpE,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AACtE,eAAO,MAAM,0BAA0B,0BAA0B,CAAC;AAClE,eAAO,MAAM,gCAAgC,yBAAyB,CAAC;AAEvE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGnC,CAAC;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,EAAE,cAAc,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,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AAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CA0C3B;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAiBzE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,GAAG,MAAM,CAElF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { AxtaryDecisionSchema, hashJson, LedgerRecordSchema, recordDecision, } from "@axtary/actionpass";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const LOCAL_LEDGER_SCHEMA_VERSION = "axtary.local-ledger.v0";
|
|
6
|
+
export const LEDGER_EXPORT_SCHEMA_VERSION = "axtary.ledger_export.v0";
|
|
7
|
+
export const LEDGER_SYNC_SCHEMA_VERSION = "axtary.ledger_sync.v0";
|
|
8
|
+
export const LEDGER_SIEM_EVENT_SCHEMA_VERSION = "axtary.siem_event.v0";
|
|
9
|
+
export const LedgerAppendResultSchema = z.object({
|
|
10
|
+
record: LedgerRecordSchema,
|
|
11
|
+
lineNumber: z.number().int().positive(),
|
|
12
|
+
});
|
|
13
|
+
export const LedgerExportFilterSchema = z.object({
|
|
14
|
+
from: z.string().datetime().nullable(),
|
|
15
|
+
to: z.string().datetime().nullable(),
|
|
16
|
+
decisions: z.array(AxtaryDecisionSchema).nullable(),
|
|
17
|
+
});
|
|
18
|
+
export const LedgerExportSchema = z.object({
|
|
19
|
+
schemaVersion: z.literal(LEDGER_EXPORT_SCHEMA_VERSION),
|
|
20
|
+
exportedAt: z.string().datetime(),
|
|
21
|
+
source: z.object({
|
|
22
|
+
filePath: z.string().min(1),
|
|
23
|
+
totalRecords: z.number().int().nonnegative(),
|
|
24
|
+
lastLedgerHash: z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable(),
|
|
25
|
+
}),
|
|
26
|
+
filters: LedgerExportFilterSchema,
|
|
27
|
+
records: z.array(LedgerRecordSchema),
|
|
28
|
+
});
|
|
29
|
+
export const LedgerExportFormatSchema = z.enum(["json", "jsonl", "siem-jsonl"]);
|
|
30
|
+
export const LedgerSiemEventSchema = z.object({
|
|
31
|
+
"@timestamp": z.string().datetime(),
|
|
32
|
+
schemaVersion: z.literal(LEDGER_SIEM_EVENT_SCHEMA_VERSION),
|
|
33
|
+
event: z.object({
|
|
34
|
+
kind: z.literal("event"),
|
|
35
|
+
category: z.array(z.string()),
|
|
36
|
+
type: z.array(z.string()),
|
|
37
|
+
action: z.literal("axtary.policy.decision"),
|
|
38
|
+
outcome: z.enum(["success", "failure", "unknown"]),
|
|
39
|
+
}),
|
|
40
|
+
axtary: z.object({
|
|
41
|
+
ledger: z.object({
|
|
42
|
+
id: z.string().min(1),
|
|
43
|
+
hash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
44
|
+
previousHash: z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable(),
|
|
45
|
+
sourceHash: z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable(),
|
|
46
|
+
}),
|
|
47
|
+
trace: z.object({
|
|
48
|
+
id: z.string().min(1).nullable(),
|
|
49
|
+
}),
|
|
50
|
+
action: z.object({
|
|
51
|
+
hash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
52
|
+
payloadHash: z.string().regex(/^sha256:[a-f0-9]{64}$/),
|
|
53
|
+
passId: z.string().min(1).nullable(),
|
|
54
|
+
}),
|
|
55
|
+
decision: z.object({
|
|
56
|
+
value: AxtaryDecisionSchema,
|
|
57
|
+
reasons: z.array(z.string().min(1)),
|
|
58
|
+
policyVersion: z.string().min(1),
|
|
59
|
+
nativeRule: z.string().min(1),
|
|
60
|
+
}),
|
|
61
|
+
provider: z
|
|
62
|
+
.object({
|
|
63
|
+
name: z.enum(["github", "slack", "linear"]),
|
|
64
|
+
tool: z.string().min(1),
|
|
65
|
+
operation: z.string().min(1),
|
|
66
|
+
resourceKind: z.string().min(1),
|
|
67
|
+
resourceId: z.string().min(1),
|
|
68
|
+
})
|
|
69
|
+
.optional(),
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
export const LedgerSyncResultSchema = z.object({
|
|
73
|
+
schemaVersion: z.literal(LEDGER_SYNC_SCHEMA_VERSION),
|
|
74
|
+
endpoint: z.string().url(),
|
|
75
|
+
syncedAt: z.string().datetime(),
|
|
76
|
+
status: z.number().int(),
|
|
77
|
+
records: z.number().int().nonnegative(),
|
|
78
|
+
lastLedgerHash: z.string().regex(/^sha256:[a-f0-9]{64}$/).nullable(),
|
|
79
|
+
response: z.unknown().nullable(),
|
|
80
|
+
});
|
|
81
|
+
export class LocalJsonlLedger {
|
|
82
|
+
filePath;
|
|
83
|
+
constructor(filePath) {
|
|
84
|
+
this.filePath = filePath;
|
|
85
|
+
}
|
|
86
|
+
async appendDecision(input) {
|
|
87
|
+
const records = await this.readRecords();
|
|
88
|
+
const previousLedgerHash = records.at(-1)?.ledgerHash ?? null;
|
|
89
|
+
const record = recordDecision({
|
|
90
|
+
action: input.action,
|
|
91
|
+
decision: input.decision,
|
|
92
|
+
actionPassId: input.actionPassId ?? null,
|
|
93
|
+
previousLedgerHash,
|
|
94
|
+
occurredAt: input.occurredAt,
|
|
95
|
+
});
|
|
96
|
+
return this.appendRecord(record);
|
|
97
|
+
}
|
|
98
|
+
async appendRecord(recordInput) {
|
|
99
|
+
const records = await this.readRecords();
|
|
100
|
+
const previousRecord = records.at(-1) ?? null;
|
|
101
|
+
const record = LedgerRecordSchema.parse(recordInput);
|
|
102
|
+
if (record.previousLedgerHash !== (previousRecord?.ledgerHash ?? null)) {
|
|
103
|
+
throw new Error("ledger_previous_hash_mismatch");
|
|
104
|
+
}
|
|
105
|
+
assertRecordHash(record);
|
|
106
|
+
await mkdir(dirname(this.filePath), { recursive: true });
|
|
107
|
+
const nextContent = [...records, record]
|
|
108
|
+
.map((entry) => JSON.stringify(entry))
|
|
109
|
+
.join("\n");
|
|
110
|
+
const tmpPath = `${this.filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
111
|
+
await writeFile(tmpPath, `${nextContent}\n`, { encoding: "utf8", flag: "wx" });
|
|
112
|
+
await rename(tmpPath, this.filePath);
|
|
113
|
+
return LedgerAppendResultSchema.parse({
|
|
114
|
+
record,
|
|
115
|
+
lineNumber: records.length + 1,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async readRecords() {
|
|
119
|
+
const text = await readLedgerFile(this.filePath);
|
|
120
|
+
if (!text.trim()) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
return text
|
|
124
|
+
.split("\n")
|
|
125
|
+
.filter((line) => line.trim().length > 0)
|
|
126
|
+
.map((line, index) => parseLedgerLine(line, index + 1));
|
|
127
|
+
}
|
|
128
|
+
async verify() {
|
|
129
|
+
const records = [];
|
|
130
|
+
const text = await readLedgerFile(this.filePath);
|
|
131
|
+
const lines = text.split("\n").filter((line) => line.trim().length > 0);
|
|
132
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
133
|
+
const lineNumber = index + 1;
|
|
134
|
+
let record;
|
|
135
|
+
try {
|
|
136
|
+
record = parseLedgerLine(lines[index], lineNumber);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return {
|
|
140
|
+
valid: false,
|
|
141
|
+
records,
|
|
142
|
+
lineNumber,
|
|
143
|
+
reason: error instanceof Error ? error.message : "invalid_ledger_line",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const expectedPreviousHash = records.at(-1)?.ledgerHash ?? null;
|
|
147
|
+
if (record.previousLedgerHash !== expectedPreviousHash) {
|
|
148
|
+
return {
|
|
149
|
+
valid: false,
|
|
150
|
+
records,
|
|
151
|
+
lineNumber,
|
|
152
|
+
reason: "ledger_previous_hash_mismatch",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
try {
|
|
156
|
+
assertRecordHash(record);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
return {
|
|
160
|
+
valid: false,
|
|
161
|
+
records,
|
|
162
|
+
lineNumber,
|
|
163
|
+
reason: error instanceof Error ? error.message : "ledger_hash_mismatch",
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
records.push(record);
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
valid: true,
|
|
170
|
+
records,
|
|
171
|
+
lastLedgerHash: records.at(-1)?.ledgerHash ?? null,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
export async function readLedgerRecords(filePath) {
|
|
176
|
+
return new LocalJsonlLedger(filePath).readRecords();
|
|
177
|
+
}
|
|
178
|
+
export async function verifyLedgerFile(filePath) {
|
|
179
|
+
return new LocalJsonlLedger(filePath).verify();
|
|
180
|
+
}
|
|
181
|
+
export async function exportLedgerRecords(input) {
|
|
182
|
+
const ledger = new LocalJsonlLedger(input.filePath);
|
|
183
|
+
const verified = await ledger.verify();
|
|
184
|
+
if (!verified.valid) {
|
|
185
|
+
throw new Error(`ledger_export_invalid:${verified.lineNumber}:${verified.reason}`);
|
|
186
|
+
}
|
|
187
|
+
const filters = normalizeExportFilters(input);
|
|
188
|
+
const fromTime = filters.from ? new Date(filters.from).getTime() : null;
|
|
189
|
+
const toTime = filters.to ? new Date(filters.to).getTime() : null;
|
|
190
|
+
const decisionSet = filters.decisions ? new Set(filters.decisions) : null;
|
|
191
|
+
const records = verified.records.filter((record) => {
|
|
192
|
+
const occurredAt = new Date(record.occurredAt).getTime();
|
|
193
|
+
if (fromTime !== null && occurredAt < fromTime)
|
|
194
|
+
return false;
|
|
195
|
+
if (toTime !== null && occurredAt > toTime)
|
|
196
|
+
return false;
|
|
197
|
+
if (decisionSet && !decisionSet.has(record.decision))
|
|
198
|
+
return false;
|
|
199
|
+
return true;
|
|
200
|
+
});
|
|
201
|
+
return LedgerExportSchema.parse({
|
|
202
|
+
schemaVersion: LEDGER_EXPORT_SCHEMA_VERSION,
|
|
203
|
+
exportedAt: (input.exportedAt ?? new Date()).toISOString(),
|
|
204
|
+
source: {
|
|
205
|
+
filePath: input.filePath,
|
|
206
|
+
totalRecords: verified.records.length,
|
|
207
|
+
lastLedgerHash: verified.lastLedgerHash,
|
|
208
|
+
},
|
|
209
|
+
filters,
|
|
210
|
+
records,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export async function syncLedgerExport(input) {
|
|
214
|
+
const fetchImpl = input.fetch ?? globalThis.fetch;
|
|
215
|
+
if (!fetchImpl) {
|
|
216
|
+
throw new Error("ledger_sync_fetch_required");
|
|
217
|
+
}
|
|
218
|
+
const exportPayload = LedgerExportSchema.parse(input.export);
|
|
219
|
+
const response = await fetchWithTimeout(fetchImpl, input.endpoint, {
|
|
220
|
+
method: "POST",
|
|
221
|
+
headers: {
|
|
222
|
+
...(input.token ? { authorization: `Bearer ${input.token}` } : {}),
|
|
223
|
+
"content-type": "application/json",
|
|
224
|
+
accept: "application/json",
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify({
|
|
227
|
+
schemaVersion: LEDGER_SYNC_SCHEMA_VERSION,
|
|
228
|
+
tenant: input.tenant,
|
|
229
|
+
export: exportPayload,
|
|
230
|
+
}),
|
|
231
|
+
}, input.timeoutMs);
|
|
232
|
+
const responseText = await response.text();
|
|
233
|
+
const responseBody = responseText ? JSON.parse(responseText) : null;
|
|
234
|
+
if (!response.ok) {
|
|
235
|
+
throw new Error(`ledger_sync_failed:${response.status}`);
|
|
236
|
+
}
|
|
237
|
+
return LedgerSyncResultSchema.parse({
|
|
238
|
+
schemaVersion: LEDGER_SYNC_SCHEMA_VERSION,
|
|
239
|
+
endpoint: input.endpoint,
|
|
240
|
+
syncedAt: new Date().toISOString(),
|
|
241
|
+
status: response.status,
|
|
242
|
+
records: exportPayload.records.length,
|
|
243
|
+
lastLedgerHash: exportPayload.source.lastLedgerHash,
|
|
244
|
+
response: responseBody,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
export function formatLedgerExport(input) {
|
|
248
|
+
const exported = LedgerExportSchema.parse(input.export);
|
|
249
|
+
const format = LedgerExportFormatSchema.parse(input.format ?? "json");
|
|
250
|
+
if (format === "json") {
|
|
251
|
+
return `${JSON.stringify(exported, null, 2)}\n`;
|
|
252
|
+
}
|
|
253
|
+
if (format === "jsonl") {
|
|
254
|
+
return toJsonLines(exported.records);
|
|
255
|
+
}
|
|
256
|
+
return toJsonLines(exported.records.map((record) => LedgerSiemEventSchema.parse(toSiemEvent(record, exported))));
|
|
257
|
+
}
|
|
258
|
+
export function computeLedgerHash(record) {
|
|
259
|
+
return hashJson(record);
|
|
260
|
+
}
|
|
261
|
+
function toSiemEvent(record, exported) {
|
|
262
|
+
return {
|
|
263
|
+
"@timestamp": record.occurredAt,
|
|
264
|
+
schemaVersion: LEDGER_SIEM_EVENT_SCHEMA_VERSION,
|
|
265
|
+
event: {
|
|
266
|
+
kind: "event",
|
|
267
|
+
category: ["iam", "configuration"],
|
|
268
|
+
type: [record.decision === "allow" ? "allowed" : "denied"],
|
|
269
|
+
action: "axtary.policy.decision",
|
|
270
|
+
outcome: decisionOutcome(record.decision),
|
|
271
|
+
},
|
|
272
|
+
axtary: {
|
|
273
|
+
ledger: {
|
|
274
|
+
id: record.id,
|
|
275
|
+
hash: record.ledgerHash,
|
|
276
|
+
previousHash: record.previousLedgerHash,
|
|
277
|
+
sourceHash: exported.source.lastLedgerHash,
|
|
278
|
+
},
|
|
279
|
+
trace: {
|
|
280
|
+
id: record.traceId ?? null,
|
|
281
|
+
},
|
|
282
|
+
action: {
|
|
283
|
+
hash: record.actionHash,
|
|
284
|
+
payloadHash: record.payloadHash,
|
|
285
|
+
passId: record.actionPassId,
|
|
286
|
+
},
|
|
287
|
+
decision: {
|
|
288
|
+
value: record.decision,
|
|
289
|
+
reasons: record.reasons,
|
|
290
|
+
policyVersion: record.policy.version,
|
|
291
|
+
nativeRule: record.policy.nativeRule,
|
|
292
|
+
},
|
|
293
|
+
provider: record.providerEvidence
|
|
294
|
+
? {
|
|
295
|
+
name: record.providerEvidence.provider,
|
|
296
|
+
tool: record.providerEvidence.tool,
|
|
297
|
+
operation: record.providerEvidence.operation,
|
|
298
|
+
resourceKind: record.providerEvidence.resource.kind,
|
|
299
|
+
resourceId: record.providerEvidence.resource.id,
|
|
300
|
+
}
|
|
301
|
+
: undefined,
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function decisionOutcome(decision) {
|
|
306
|
+
if (decision === "allow")
|
|
307
|
+
return "success";
|
|
308
|
+
if (decision === "deny")
|
|
309
|
+
return "failure";
|
|
310
|
+
return "unknown";
|
|
311
|
+
}
|
|
312
|
+
function toJsonLines(values) {
|
|
313
|
+
return values.map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
314
|
+
}
|
|
315
|
+
function normalizeExportFilters(input) {
|
|
316
|
+
const from = normalizeDateFilter(input.from, "from");
|
|
317
|
+
const to = normalizeDateFilter(input.to, "to");
|
|
318
|
+
if (from && to && new Date(from).getTime() > new Date(to).getTime()) {
|
|
319
|
+
throw new Error("ledger_export_invalid_range");
|
|
320
|
+
}
|
|
321
|
+
return LedgerExportFilterSchema.parse({
|
|
322
|
+
from,
|
|
323
|
+
to,
|
|
324
|
+
decisions: input.decisions && input.decisions.length > 0
|
|
325
|
+
? [...new Set(input.decisions.map((decision) => AxtaryDecisionSchema.parse(decision)))]
|
|
326
|
+
: null,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
function normalizeDateFilter(value, field) {
|
|
330
|
+
if (value === undefined || value === null) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
334
|
+
if (Number.isNaN(date.getTime())) {
|
|
335
|
+
throw new Error(`ledger_export_invalid_${field}`);
|
|
336
|
+
}
|
|
337
|
+
return date.toISOString();
|
|
338
|
+
}
|
|
339
|
+
function parseLedgerLine(line, lineNumber) {
|
|
340
|
+
try {
|
|
341
|
+
return LedgerRecordSchema.parse(JSON.parse(line));
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
const message = error instanceof Error ? error.message : "invalid_json";
|
|
345
|
+
throw new Error(`invalid_ledger_line:${lineNumber}:${message}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function assertRecordHash(record) {
|
|
349
|
+
const { ledgerHash, ...recordWithoutHash } = record;
|
|
350
|
+
const expectedHash = computeLedgerHash(recordWithoutHash);
|
|
351
|
+
if (ledgerHash !== expectedHash) {
|
|
352
|
+
throw new Error("ledger_hash_mismatch");
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
async function readLedgerFile(filePath) {
|
|
356
|
+
try {
|
|
357
|
+
return await readFile(filePath, "utf8");
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
361
|
+
return "";
|
|
362
|
+
}
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
async function fetchWithTimeout(fetchImpl, url, init, timeoutMs = 10_000) {
|
|
367
|
+
const controller = new AbortController();
|
|
368
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
369
|
+
try {
|
|
370
|
+
return await fetchImpl(url, {
|
|
371
|
+
...init,
|
|
372
|
+
signal: controller.signal,
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
clearTimeout(timeout);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function isNodeError(error) {
|
|
380
|
+
return error instanceof Error && "code" in error;
|
|
381
|
+
}
|
|
382
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,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MAAM,CAAC;IACpD,MAAM,YAAY,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAE1D,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,SAAuB,EACvB,GAAW,EACX,IAAiB,EACjB,SAAS,GAAG,MAAM;IAElB,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,EAAE,SAAS,CAAC,CAAC;IAEhE,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,CAAC,GAAG,EAAE;YAC1B,GAAG,IAAI;YACP,MAAM,EAAE,UAAU,CAAC,MAAM;SAC1B,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AACnD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@axtary/ledger",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Append-only JSONL action ledger with hash-chain verification for Axtary.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "UNLICENSED",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/axtary/axtary.git",
|
|
11
|
+
"directory": "packages/ledger"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"ai-agents",
|
|
15
|
+
"audit-log",
|
|
16
|
+
"jsonl",
|
|
17
|
+
"hash-chain",
|
|
18
|
+
"authorization"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"prebuild": "npm run build -w @axtary/actionpass",
|
|
25
|
+
"build": "npm run clean && tsc -p tsconfig.json",
|
|
26
|
+
"clean": "rm -rf dist",
|
|
27
|
+
"prepack": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"README.md",
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"main": "./dist/index.js",
|
|
37
|
+
"exports": {
|
|
38
|
+
".": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"import": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@axtary/actionpass": "0.0.1",
|
|
46
|
+
"zod": "^4.4.3"
|
|
47
|
+
}
|
|
48
|
+
}
|