@rubric-protocol/attest-decision 1.0.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/attestor.d.ts +81 -0
- package/dist/attestor.d.ts.map +1 -0
- package/dist/attestor.js +211 -0
- package/dist/attestor.js.map +1 -0
- package/dist/constants.d.ts +54 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/dar.d.ts +55 -0
- package/dist/dar.d.ts.map +1 -0
- package/dist/dar.js +118 -0
- package/dist/dar.js.map +1 -0
- package/dist/hash.d.ts +11 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +25 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/jcs.d.ts +18 -0
- package/dist/jcs.d.ts.map +1 -0
- package/dist/jcs.js +101 -0
- package/dist/jcs.js.map +1 -0
- package/dist/spool.d.ts +58 -0
- package/dist/spool.d.ts.map +1 -0
- package/dist/spool.js +210 -0
- package/dist/spool.js.map +1 -0
- package/dist/transport.d.ts +33 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +52 -0
- package/dist/transport.js.map +1 -0
- package/dist/ulid.d.ts +9 -0
- package/dist/ulid.d.ts.map +1 -0
- package/dist/ulid.js +71 -0
- package/dist/ulid.js.map +1 -0
- package/package.json +28 -0
- package/src/attestor.ts +249 -0
- package/src/constants.ts +64 -0
- package/src/dar.ts +168 -0
- package/src/hash.ts +27 -0
- package/src/index.ts +42 -0
- package/src/jcs.ts +116 -0
- package/src/spool.ts +244 -0
- package/src/transport.ts +76 -0
- package/src/ulid.ts +75 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attestor — the fire-and-forget façade (tasks/P1.md).
|
|
3
|
+
*
|
|
4
|
+
* `attest()` builds a DAR, appends it durably to the spool, enqueues it, and
|
|
5
|
+
* returns immediately (adds <1 ms to the caller). It NEVER throws into app code;
|
|
6
|
+
* any failure is reported to the optional `onError` sink and swallowed.
|
|
7
|
+
*
|
|
8
|
+
* The batcher flushes when the queue reaches `maxBatch` (64) or `maxWaitMs`
|
|
9
|
+
* (5000 ms) elapses, whichever comes first — one POST per flush. A delivered
|
|
10
|
+
* batch is acked in the spool; a failed batch is returned to the front of the
|
|
11
|
+
* queue and retried, so it is never lost. On construction the spool is drained:
|
|
12
|
+
* anything left by a previous run is re-queued and per-agent chain heads reseeded.
|
|
13
|
+
*/
|
|
14
|
+
import type { TransmitMode } from "./constants.js";
|
|
15
|
+
import { type DarBuildInput } from "./dar.js";
|
|
16
|
+
import type { Transport } from "./transport.js";
|
|
17
|
+
export interface AttestorOptions {
|
|
18
|
+
transport: Transport;
|
|
19
|
+
spoolPath: string;
|
|
20
|
+
maxBatch?: number;
|
|
21
|
+
maxWaitMs?: number;
|
|
22
|
+
maxSpoolBytes?: number;
|
|
23
|
+
retryMs?: number;
|
|
24
|
+
/** Max re-send attempts per batch during close() before leaving it spooled. */
|
|
25
|
+
closeRetries?: number;
|
|
26
|
+
/** Cap on in-memory queued (un-acked) records; oldest are dropped past it. Default 100000. */
|
|
27
|
+
maxQueue?: number;
|
|
28
|
+
/** Reject a decision whose canonical form exceeds this many bytes. Default 256 KiB. */
|
|
29
|
+
maxDecisionBytes?: number;
|
|
30
|
+
/** `hash-only` (default) sends DAR cores only; `payload` also carries raw content in the envelope. */
|
|
31
|
+
mode?: TransmitMode;
|
|
32
|
+
now?: () => number;
|
|
33
|
+
newDecisionId?: () => string;
|
|
34
|
+
onError?: (err: unknown) => void;
|
|
35
|
+
/** Replay leftover spool records on construction. Default true. */
|
|
36
|
+
autoRecover?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare class Attestor {
|
|
39
|
+
private readonly builder;
|
|
40
|
+
private readonly spool;
|
|
41
|
+
private readonly transport;
|
|
42
|
+
private readonly maxBatch;
|
|
43
|
+
private readonly maxWaitMs;
|
|
44
|
+
private readonly retryMs;
|
|
45
|
+
private readonly closeRetries;
|
|
46
|
+
private readonly maxQueue;
|
|
47
|
+
private readonly mode;
|
|
48
|
+
private readonly onError?;
|
|
49
|
+
private queue;
|
|
50
|
+
private timer;
|
|
51
|
+
private flushing;
|
|
52
|
+
private closed;
|
|
53
|
+
constructor(options: AttestorOptions);
|
|
54
|
+
/**
|
|
55
|
+
* Fire-and-forget. Returns the minted `decisionId`, or `null` if the record
|
|
56
|
+
* could not be built/spooled (never throws). Adds <1 ms to the caller.
|
|
57
|
+
*/
|
|
58
|
+
attest(input: DarBuildInput): string | null;
|
|
59
|
+
/** Flush at most one batch. Safe to call directly; concurrency-guarded. */
|
|
60
|
+
flush(): Promise<void>;
|
|
61
|
+
/** Flush repeatedly until the queue is empty (used by tests and shutdown). */
|
|
62
|
+
drain(): Promise<void>;
|
|
63
|
+
/** Number of records still queued (not yet acknowledged). */
|
|
64
|
+
pendingCount(): number;
|
|
65
|
+
/**
|
|
66
|
+
* Stop accepting records, drain the queue (retrying each batch up to
|
|
67
|
+
* `closeRetries` times), and close the spool. Anything still undelivered after
|
|
68
|
+
* the retries remains durably spooled for the next run's recovery.
|
|
69
|
+
*/
|
|
70
|
+
close(): Promise<void>;
|
|
71
|
+
/** Raw payloads for a batch — only in `payload` mode; ride in the envelope. */
|
|
72
|
+
private payloadsOf;
|
|
73
|
+
private recover;
|
|
74
|
+
private scheduleNext;
|
|
75
|
+
private armTimer;
|
|
76
|
+
private scheduleRetry;
|
|
77
|
+
private scheduleFlush;
|
|
78
|
+
private clearTimer;
|
|
79
|
+
private reportError;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=attestor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attestor.d.ts","sourceRoot":"","sources":["../src/attestor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK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AAC,QAAQ,CAAC,OAAO,CAAC,CAAyB;IAElD,OAAO,CAAC,KAAK,CAAmB;IAChC,OAAO,CAAC,KAAK,CAA8C;IAC3D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,EAAE,eAAe;IAsBpC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI;IAsB3C,2EAA2E;IACrE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,8EAA8E;IACxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B,6DAA6D;IAC7D,YAAY,IAAI,MAAM;IAItB;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B5B,+EAA+E;IAC/E,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,WAAW;CAOpB"}
|
package/dist/attestor.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { DarBuilder, toPayload } from "./dar.js";
|
|
2
|
+
import { Spool } from "./spool.js";
|
|
3
|
+
const sleep0 = () => new Promise((r) => setImmediate(r));
|
|
4
|
+
const delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5
|
+
export class Attestor {
|
|
6
|
+
builder;
|
|
7
|
+
spool;
|
|
8
|
+
transport;
|
|
9
|
+
maxBatch;
|
|
10
|
+
maxWaitMs;
|
|
11
|
+
retryMs;
|
|
12
|
+
closeRetries;
|
|
13
|
+
maxQueue;
|
|
14
|
+
mode;
|
|
15
|
+
onError;
|
|
16
|
+
queue = [];
|
|
17
|
+
timer = null;
|
|
18
|
+
flushing = false;
|
|
19
|
+
closed = false;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.transport = options.transport;
|
|
22
|
+
this.onError = options.onError;
|
|
23
|
+
this.spool = new Spool(options.spoolPath, {
|
|
24
|
+
maxBytes: options.maxSpoolBytes,
|
|
25
|
+
onDrop: (n) => this.reportError(new Error(`spool dropped ${n} oldest record(s) at the size cap`)),
|
|
26
|
+
});
|
|
27
|
+
this.builder = new DarBuilder({
|
|
28
|
+
newDecisionId: options.newDecisionId,
|
|
29
|
+
now: options.now,
|
|
30
|
+
maxDecisionBytes: options.maxDecisionBytes,
|
|
31
|
+
});
|
|
32
|
+
this.maxBatch = options.maxBatch ?? 64;
|
|
33
|
+
this.maxWaitMs = options.maxWaitMs ?? 5000;
|
|
34
|
+
this.retryMs = options.retryMs ?? 1000;
|
|
35
|
+
this.closeRetries = options.closeRetries ?? 3;
|
|
36
|
+
this.maxQueue = options.maxQueue ?? 100_000;
|
|
37
|
+
this.mode = options.mode ?? "hash-only";
|
|
38
|
+
if (options.autoRecover !== false)
|
|
39
|
+
this.recover();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fire-and-forget. Returns the minted `decisionId`, or `null` if the record
|
|
43
|
+
* could not be built/spooled (never throws). Adds <1 ms to the caller.
|
|
44
|
+
*/
|
|
45
|
+
attest(input) {
|
|
46
|
+
if (this.closed)
|
|
47
|
+
return null;
|
|
48
|
+
try {
|
|
49
|
+
const dar = this.builder.build(input);
|
|
50
|
+
const payload = this.mode === "payload" ? toPayload(dar.decisionId, input) : undefined;
|
|
51
|
+
const seq = this.spool.append(dar, payload);
|
|
52
|
+
this.queue.push({ seq, dar, payload });
|
|
53
|
+
// Bound in-memory growth under sustained transport failure: drop oldest
|
|
54
|
+
// queued records past the cap (they are surfaced, not silently lost).
|
|
55
|
+
while (this.queue.length > this.maxQueue) {
|
|
56
|
+
this.queue.shift();
|
|
57
|
+
this.reportError(new Error("attest queue cap exceeded; dropped oldest queued record"));
|
|
58
|
+
}
|
|
59
|
+
if (this.queue.length >= this.maxBatch)
|
|
60
|
+
this.scheduleFlush();
|
|
61
|
+
else
|
|
62
|
+
this.armTimer();
|
|
63
|
+
return dar.decisionId;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
this.reportError(err);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Flush at most one batch. Safe to call directly; concurrency-guarded. */
|
|
71
|
+
async flush() {
|
|
72
|
+
if (this.flushing || this.closed)
|
|
73
|
+
return;
|
|
74
|
+
if (this.queue.length === 0)
|
|
75
|
+
return;
|
|
76
|
+
this.flushing = true;
|
|
77
|
+
this.clearTimer();
|
|
78
|
+
const batch = this.queue.splice(0, this.maxBatch);
|
|
79
|
+
try {
|
|
80
|
+
this.spool.compactIfNeeded(); // enforce the 50 MB cap off the caller path
|
|
81
|
+
this.spool.fsync();
|
|
82
|
+
await this.transport.send(batch.map((b) => b.dar), this.payloadsOf(batch));
|
|
83
|
+
this.spool.ack(batch[batch.length - 1].seq);
|
|
84
|
+
this.flushing = false;
|
|
85
|
+
this.scheduleNext();
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
// Retain: return the batch to the front (order preserved) and retry.
|
|
89
|
+
this.queue.unshift(...batch);
|
|
90
|
+
this.flushing = false;
|
|
91
|
+
this.reportError(err);
|
|
92
|
+
this.scheduleRetry();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Flush repeatedly until the queue is empty (used by tests and shutdown). */
|
|
96
|
+
async drain() {
|
|
97
|
+
for (;;) {
|
|
98
|
+
while (this.flushing)
|
|
99
|
+
await sleep0();
|
|
100
|
+
if (this.queue.length === 0 || this.closed)
|
|
101
|
+
return;
|
|
102
|
+
await this.flush();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Number of records still queued (not yet acknowledged). */
|
|
106
|
+
pendingCount() {
|
|
107
|
+
return this.queue.length;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Stop accepting records, drain the queue (retrying each batch up to
|
|
111
|
+
* `closeRetries` times), and close the spool. Anything still undelivered after
|
|
112
|
+
* the retries remains durably spooled for the next run's recovery.
|
|
113
|
+
*/
|
|
114
|
+
async close() {
|
|
115
|
+
this.closed = true;
|
|
116
|
+
this.clearTimer();
|
|
117
|
+
while (this.flushing)
|
|
118
|
+
await sleep0();
|
|
119
|
+
this.spool.compactIfNeeded();
|
|
120
|
+
while (this.queue.length > 0) {
|
|
121
|
+
const batch = this.queue.splice(0, this.maxBatch);
|
|
122
|
+
let delivered = false;
|
|
123
|
+
for (let attempt = 0; attempt <= this.closeRetries; attempt++) {
|
|
124
|
+
try {
|
|
125
|
+
this.spool.fsync();
|
|
126
|
+
await this.transport.send(batch.map((b) => b.dar), this.payloadsOf(batch));
|
|
127
|
+
this.spool.ack(batch[batch.length - 1].seq);
|
|
128
|
+
delivered = true;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
this.reportError(err);
|
|
133
|
+
if (attempt < this.closeRetries)
|
|
134
|
+
await delay(this.retryMs);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!delivered) {
|
|
138
|
+
// Give up: leave this batch (and the rest) durably spooled for recovery.
|
|
139
|
+
this.queue.unshift(...batch);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
this.spool.close();
|
|
144
|
+
}
|
|
145
|
+
// --- internals ---
|
|
146
|
+
/** Raw payloads for a batch — only in `payload` mode; ride in the envelope. */
|
|
147
|
+
payloadsOf(batch) {
|
|
148
|
+
if (this.mode !== "payload")
|
|
149
|
+
return undefined;
|
|
150
|
+
const payloads = batch
|
|
151
|
+
.map((b) => b.payload)
|
|
152
|
+
.filter((p) => p !== undefined);
|
|
153
|
+
return payloads.length > 0 ? payloads : undefined;
|
|
154
|
+
}
|
|
155
|
+
recover() {
|
|
156
|
+
const pending = this.spool.pending();
|
|
157
|
+
for (const { dar } of pending)
|
|
158
|
+
this.builder.seedHead(dar.agentId, dar.decisionId);
|
|
159
|
+
for (const item of pending)
|
|
160
|
+
this.queue.push(item);
|
|
161
|
+
if (this.queue.length > 0)
|
|
162
|
+
this.scheduleFlush();
|
|
163
|
+
}
|
|
164
|
+
scheduleNext() {
|
|
165
|
+
if (this.queue.length >= this.maxBatch)
|
|
166
|
+
this.scheduleFlush();
|
|
167
|
+
else if (this.queue.length > 0)
|
|
168
|
+
this.armTimer();
|
|
169
|
+
}
|
|
170
|
+
armTimer() {
|
|
171
|
+
if (this.timer || this.flushing || this.closed)
|
|
172
|
+
return;
|
|
173
|
+
this.timer = setTimeout(() => {
|
|
174
|
+
this.timer = null;
|
|
175
|
+
this.scheduleFlush();
|
|
176
|
+
}, this.maxWaitMs);
|
|
177
|
+
this.timer.unref?.();
|
|
178
|
+
}
|
|
179
|
+
scheduleRetry() {
|
|
180
|
+
if (this.timer || this.flushing || this.closed)
|
|
181
|
+
return;
|
|
182
|
+
this.timer = setTimeout(() => {
|
|
183
|
+
this.timer = null;
|
|
184
|
+
this.scheduleFlush();
|
|
185
|
+
}, this.retryMs);
|
|
186
|
+
this.timer.unref?.();
|
|
187
|
+
}
|
|
188
|
+
scheduleFlush() {
|
|
189
|
+
this.clearTimer();
|
|
190
|
+
if (this.flushing || this.closed)
|
|
191
|
+
return;
|
|
192
|
+
setImmediate(() => {
|
|
193
|
+
void this.flush();
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
clearTimer() {
|
|
197
|
+
if (this.timer) {
|
|
198
|
+
clearTimeout(this.timer);
|
|
199
|
+
this.timer = null;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
reportError(err) {
|
|
203
|
+
try {
|
|
204
|
+
this.onError?.(err);
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// An onError that throws must not escape attest().
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=attestor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AAG,IAAI,CAAC;YAClB,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACzC,YAAY,CAAC,GAAG,EAAE;YAChB,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAEO,WAAW,CAAC,GAAY;QAC9B,IAAI,CAAC;YACH,IAAI,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC;QACtB,CAAC;QAAC,MAAM,CAAC;YACP,mDAAmD;QACrD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen DAR/0.1 constants and types (spec/dar-0.1.md §2, §4).
|
|
3
|
+
*/
|
|
4
|
+
/** Record format tag for the frozen DAR/0.1 field set. */
|
|
5
|
+
export declare const DAR_VERSION: "DAR/0.1";
|
|
6
|
+
/** Hash algorithm invariant (spec §4.1). SHA3-256 everywhere. */
|
|
7
|
+
export declare const HASH_ALGORITHM: "sha3-256";
|
|
8
|
+
/** Prefix on hash-valued fields (spec §4.2), i.e. `sha3-256:`. */
|
|
9
|
+
export declare const HASH_PREFIX: "sha3-256:";
|
|
10
|
+
/** Attestation endpoint. Test + standard traffic both flush here (CLAUDE.md). */
|
|
11
|
+
export declare const TIERED_ATTEST_PATH: "/v1/tiered-attest";
|
|
12
|
+
/** The single credential env var the SDK reads (CLAUDE.md invariant). */
|
|
13
|
+
export declare const API_KEY_ENV: "RUBRIC_API_KEY";
|
|
14
|
+
/** Leaf discriminant values (spec §2, `leafType`). */
|
|
15
|
+
export type LeafType = "decision" | "schema-change" | "checkpoint";
|
|
16
|
+
/** A `sha3-256:<hex>` encoded hash string. */
|
|
17
|
+
export type HashString = `${typeof HASH_ALGORITHM}:${string}`;
|
|
18
|
+
/** Identifies the adapter that produced a decision's inputs (spec §2). */
|
|
19
|
+
export interface AdapterInfo {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
}
|
|
23
|
+
/** Transmit mode: `hash-only` (default) sends DAR cores; `payload` also carries raw content in the envelope. */
|
|
24
|
+
export type TransmitMode = "hash-only" | "payload";
|
|
25
|
+
/** Raw content transmitted ONLY in `payload` mode, in the transport envelope — never in the DAR core. */
|
|
26
|
+
export interface PayloadRecord {
|
|
27
|
+
decisionId: string;
|
|
28
|
+
schema?: unknown;
|
|
29
|
+
input: unknown;
|
|
30
|
+
output: unknown;
|
|
31
|
+
meta?: unknown;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The DAR core: the frozen, HASHES-ONLY field set (spec §2). It never carries
|
|
35
|
+
* raw content — only commitments. The Merkle leaf hash is computed over the JCS
|
|
36
|
+
* canonicalization of this object.
|
|
37
|
+
*/
|
|
38
|
+
export interface DarCore {
|
|
39
|
+
readonly v: typeof DAR_VERSION;
|
|
40
|
+
readonly decisionId: string;
|
|
41
|
+
readonly agentId: string;
|
|
42
|
+
/** Client-claimed decision time; trusted time is the HCS consensus timestamp. */
|
|
43
|
+
readonly ts: string;
|
|
44
|
+
readonly prev: string | null;
|
|
45
|
+
readonly leafType: LeafType;
|
|
46
|
+
readonly schemaHash: HashString;
|
|
47
|
+
readonly inputHash: HashString;
|
|
48
|
+
readonly outputHash: HashString;
|
|
49
|
+
/** SHA3-256 over JCS of { schemaHash, inputHash, outputHash }. */
|
|
50
|
+
readonly decisionHash: HashString;
|
|
51
|
+
readonly schemaRef?: string;
|
|
52
|
+
readonly adapter?: AdapterInfo;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,WAAW,EAAG,SAAkB,CAAC;AAE9C,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAG,UAAmB,CAAC;AAElD,kEAAkE;AAClE,eAAO,MAAM,WAAW,aAAgC,CAAC;AAEzD,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,EAAG,mBAA4B,CAAC;AAE/D,yEAAyE;AACzE,eAAO,MAAM,WAAW,EAAG,gBAAyB,CAAC;AAErD,sDAAsD;AACtD,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,eAAe,GAAG,YAAY,CAAC;AAEnE,8CAA8C;AAC9C,MAAM,MAAM,UAAU,GAAG,GAAG,OAAO,cAAc,IAAI,MAAM,EAAE,CAAC;AAE9D,0EAA0E;AAC1E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,gHAAgH;AAChH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;AAEnD,yGAAyG;AACzG,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,EAAE,OAAO,WAAW,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,kEAAkE;IAClE,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAChC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frozen DAR/0.1 constants and types (spec/dar-0.1.md §2, §4).
|
|
3
|
+
*/
|
|
4
|
+
/** Record format tag for the frozen DAR/0.1 field set. */
|
|
5
|
+
export const DAR_VERSION = "DAR/0.1";
|
|
6
|
+
/** Hash algorithm invariant (spec §4.1). SHA3-256 everywhere. */
|
|
7
|
+
export const HASH_ALGORITHM = "sha3-256";
|
|
8
|
+
/** Prefix on hash-valued fields (spec §4.2), i.e. `sha3-256:`. */
|
|
9
|
+
export const HASH_PREFIX = `${HASH_ALGORITHM}:`;
|
|
10
|
+
/** Attestation endpoint. Test + standard traffic both flush here (CLAUDE.md). */
|
|
11
|
+
export const TIERED_ATTEST_PATH = "/v1/tiered-attest";
|
|
12
|
+
/** The single credential env var the SDK reads (CLAUDE.md invariant). */
|
|
13
|
+
export const API_KEY_ENV = "RUBRIC_API_KEY";
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,WAAW,GAAG,SAAkB,CAAC;AAE9C,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,UAAmB,CAAC;AAElD,kEAAkE;AAClE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,cAAc,GAAY,CAAC;AAEzD,iFAAiF;AACjF,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAA4B,CAAC;AAE/D,yEAAyE;AACzE,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAyB,CAAC"}
|
package/dist/dar.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAR builder (spec/dar-0.1.md §2). Assembles a HASHES-ONLY DAR core from
|
|
3
|
+
* adapter inputs: hashes the schema, input, and output (JCS+SHA3-256), derives
|
|
4
|
+
* `decisionHash` over those three commitments, mints a ULID `decisionId`, and
|
|
5
|
+
* maintains the per-agent `prev` chain. The core never carries raw content.
|
|
6
|
+
*/
|
|
7
|
+
import { type AdapterInfo, type DarCore, type HashString, type LeafType, type PayloadRecord } from "./constants.js";
|
|
8
|
+
/** Non-content metadata an adapter may attach to a decision. */
|
|
9
|
+
export interface DarMeta {
|
|
10
|
+
schemaRef?: string;
|
|
11
|
+
adapter?: AdapterInfo;
|
|
12
|
+
leafType?: LeafType;
|
|
13
|
+
}
|
|
14
|
+
export interface DarBuildInput {
|
|
15
|
+
agentId: string;
|
|
16
|
+
/** Adapter-supplied decision input; hashed to `inputHash`. */
|
|
17
|
+
input: unknown;
|
|
18
|
+
/** Adapter-supplied decision output; hashed to `outputHash`. */
|
|
19
|
+
output: unknown;
|
|
20
|
+
/** Schema descriptor to hash, or a precomputed `schemaHash`. One is required. */
|
|
21
|
+
schema?: unknown;
|
|
22
|
+
schemaHash?: HashString;
|
|
23
|
+
meta?: DarMeta;
|
|
24
|
+
}
|
|
25
|
+
export interface DarBuilderDeps {
|
|
26
|
+
/** Injectable id generator (default: monotonic ULID). */
|
|
27
|
+
newDecisionId?: () => string;
|
|
28
|
+
/** Injectable clock in epoch ms (default: Date.now). */
|
|
29
|
+
now?: () => number;
|
|
30
|
+
/** Reject a decision whose canonical input+output exceeds this many bytes. Default 256 KiB. */
|
|
31
|
+
maxDecisionBytes?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Derive `decisionHash` from the three content commitments (spec §4.2). */
|
|
34
|
+
export declare function decisionHashOf(schemaHash: HashString, inputHash: HashString, outputHash: HashString): HashString;
|
|
35
|
+
export declare class DarBuilder {
|
|
36
|
+
private readonly newDecisionId;
|
|
37
|
+
private readonly now;
|
|
38
|
+
private readonly maxDecisionBytes;
|
|
39
|
+
private readonly heads;
|
|
40
|
+
private readonly schemaCache;
|
|
41
|
+
constructor(deps?: DarBuilderDeps);
|
|
42
|
+
build(input: DarBuildInput): DarCore;
|
|
43
|
+
private resolveSchemaHash;
|
|
44
|
+
/** Current chain head (last minted decisionId) for an agent, if any. */
|
|
45
|
+
getHead(agentId: string): string | undefined;
|
|
46
|
+
/** Seed a chain head — used to continue chains after spool recovery. */
|
|
47
|
+
seedHead(agentId: string, decisionId: string): void;
|
|
48
|
+
}
|
|
49
|
+
/** Build the raw payload record for `payload`-mode transmission (never in the core). */
|
|
50
|
+
export declare function toPayload(decisionId: string, input: DarBuildInput): PayloadRecord;
|
|
51
|
+
/** The Merkle leaf hash of a DAR core: SHA3-256 over its JCS bytes (spec §4.3). */
|
|
52
|
+
export declare function leafHash(dar: DarCore): HashString;
|
|
53
|
+
/** JCS canonicalization of a DAR core — the exact leaf-hash preimage. */
|
|
54
|
+
export declare function canonicalDar(dar: DarCore): string;
|
|
55
|
+
//# sourceMappingURL=dar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dar.d.ts","sourceRoot":"","sources":["../src/dar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KA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AAM,GAAG,SAAS;IAI5C,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;CAGpD;AAED,wFAAwF;AACxF,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,CAQjF;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAEjD;AAED,yEAAyE;AACzE,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAEjD"}
|
package/dist/dar.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DAR builder (spec/dar-0.1.md §2). Assembles a HASHES-ONLY DAR core from
|
|
3
|
+
* adapter inputs: hashes the schema, input, and output (JCS+SHA3-256), derives
|
|
4
|
+
* `decisionHash` over those three commitments, mints a ULID `decisionId`, and
|
|
5
|
+
* maintains the per-agent `prev` chain. The core never carries raw content.
|
|
6
|
+
*/
|
|
7
|
+
import { DAR_VERSION, } from "./constants.js";
|
|
8
|
+
import { hashJson, sha3_256 } from "./hash.js";
|
|
9
|
+
import { canonicalize, canonicalizeToBytes } from "./jcs.js";
|
|
10
|
+
import { ulid as defaultUlid } from "./ulid.js";
|
|
11
|
+
const LEAF_TYPES = new Set(["decision", "schema-change", "checkpoint"]);
|
|
12
|
+
const HASH_STRING = /^sha3-256:[0-9a-f]{64}$/;
|
|
13
|
+
const DEFAULT_MAX_DECISION_BYTES = 256 * 1024; // bounds attest() latency + payload size
|
|
14
|
+
/** Derive `decisionHash` from the three content commitments (spec §4.2). */
|
|
15
|
+
export function decisionHashOf(schemaHash, inputHash, outputHash) {
|
|
16
|
+
return hashJson({ schemaHash, inputHash, outputHash });
|
|
17
|
+
}
|
|
18
|
+
export class DarBuilder {
|
|
19
|
+
newDecisionId;
|
|
20
|
+
now;
|
|
21
|
+
maxDecisionBytes;
|
|
22
|
+
heads = new Map();
|
|
23
|
+
// Keyed by object identity: reusing the same schema object across build()
|
|
24
|
+
// calls skips re-hashing. CONTRACT: schema objects must be treated as
|
|
25
|
+
// immutable — mutating one in place after its first build() would return the
|
|
26
|
+
// stale cached hash. Distinct objects with identical contents are re-hashed.
|
|
27
|
+
schemaCache = new WeakMap();
|
|
28
|
+
constructor(deps = {}) {
|
|
29
|
+
this.newDecisionId = deps.newDecisionId ?? defaultUlid;
|
|
30
|
+
this.now = deps.now ?? Date.now;
|
|
31
|
+
this.maxDecisionBytes = deps.maxDecisionBytes ?? DEFAULT_MAX_DECISION_BYTES;
|
|
32
|
+
}
|
|
33
|
+
build(input) {
|
|
34
|
+
const { agentId } = input;
|
|
35
|
+
if (typeof agentId !== "string" || agentId.length === 0) {
|
|
36
|
+
throw new Error("DAR: agentId must be a non-empty string");
|
|
37
|
+
}
|
|
38
|
+
const leafType = input.meta?.leafType ?? "decision";
|
|
39
|
+
if (!LEAF_TYPES.has(leafType)) {
|
|
40
|
+
throw new Error(`DAR: unknown leafType '${leafType}'`);
|
|
41
|
+
}
|
|
42
|
+
const schemaHash = this.resolveSchemaHash(input);
|
|
43
|
+
// Canonicalize input/output once, cap the combined size, then hash.
|
|
44
|
+
const inputBytes = canonicalizeToBytes(input.input);
|
|
45
|
+
const outputBytes = canonicalizeToBytes(input.output);
|
|
46
|
+
if (inputBytes.length + outputBytes.length > this.maxDecisionBytes) {
|
|
47
|
+
throw new Error(`DAR: input+output is ${inputBytes.length + outputBytes.length} bytes; exceeds maxDecisionBytes (${this.maxDecisionBytes})`);
|
|
48
|
+
}
|
|
49
|
+
const inputHash = sha3_256(inputBytes);
|
|
50
|
+
const outputHash = sha3_256(outputBytes);
|
|
51
|
+
const decisionHash = decisionHashOf(schemaHash, inputHash, outputHash);
|
|
52
|
+
const decisionId = this.newDecisionId();
|
|
53
|
+
const prev = this.heads.get(agentId) ?? null;
|
|
54
|
+
const ts = new Date(this.now()).toISOString();
|
|
55
|
+
const dar = {
|
|
56
|
+
v: DAR_VERSION,
|
|
57
|
+
decisionId,
|
|
58
|
+
agentId,
|
|
59
|
+
ts,
|
|
60
|
+
prev,
|
|
61
|
+
leafType,
|
|
62
|
+
schemaHash,
|
|
63
|
+
inputHash,
|
|
64
|
+
outputHash,
|
|
65
|
+
decisionHash,
|
|
66
|
+
...(input.meta?.schemaRef !== undefined ? { schemaRef: input.meta.schemaRef } : {}),
|
|
67
|
+
...(input.meta?.adapter !== undefined ? { adapter: input.meta.adapter } : {}),
|
|
68
|
+
};
|
|
69
|
+
this.heads.set(agentId, decisionId);
|
|
70
|
+
return dar;
|
|
71
|
+
}
|
|
72
|
+
resolveSchemaHash(input) {
|
|
73
|
+
if (input.schemaHash) {
|
|
74
|
+
if (!HASH_STRING.test(input.schemaHash)) {
|
|
75
|
+
throw new Error(`DAR: schemaHash must be 'sha3-256:<64 hex>', got '${input.schemaHash}'`);
|
|
76
|
+
}
|
|
77
|
+
return input.schemaHash;
|
|
78
|
+
}
|
|
79
|
+
if (input.schema === undefined)
|
|
80
|
+
throw new Error("DAR: schema or schemaHash is required");
|
|
81
|
+
if (typeof input.schema === "object" && input.schema !== null) {
|
|
82
|
+
const cached = this.schemaCache.get(input.schema);
|
|
83
|
+
if (cached)
|
|
84
|
+
return cached;
|
|
85
|
+
const h = hashJson(input.schema);
|
|
86
|
+
this.schemaCache.set(input.schema, h);
|
|
87
|
+
return h;
|
|
88
|
+
}
|
|
89
|
+
return hashJson(input.schema);
|
|
90
|
+
}
|
|
91
|
+
/** Current chain head (last minted decisionId) for an agent, if any. */
|
|
92
|
+
getHead(agentId) {
|
|
93
|
+
return this.heads.get(agentId);
|
|
94
|
+
}
|
|
95
|
+
/** Seed a chain head — used to continue chains after spool recovery. */
|
|
96
|
+
seedHead(agentId, decisionId) {
|
|
97
|
+
this.heads.set(agentId, decisionId);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Build the raw payload record for `payload`-mode transmission (never in the core). */
|
|
101
|
+
export function toPayload(decisionId, input) {
|
|
102
|
+
return {
|
|
103
|
+
decisionId,
|
|
104
|
+
...(input.schema !== undefined ? { schema: input.schema } : {}),
|
|
105
|
+
input: input.input,
|
|
106
|
+
output: input.output,
|
|
107
|
+
...(input.meta !== undefined ? { meta: input.meta } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** The Merkle leaf hash of a DAR core: SHA3-256 over its JCS bytes (spec §4.3). */
|
|
111
|
+
export function leafHash(dar) {
|
|
112
|
+
return hashJson(dar);
|
|
113
|
+
}
|
|
114
|
+
/** JCS canonicalization of a DAR core — the exact leaf-hash preimage. */
|
|
115
|
+
export function canonicalDar(dar) {
|
|
116
|
+
return canonicalize(dar);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=dar.js.map
|
package/dist/dar.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dar.js","sourceRoot":"","sources":["../src/dar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,WAAW,GAMZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC;AAC7F,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,yCAAyC;AA8BxF,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,UAAsB,EAAE,SAAqB,EAAE,UAAsB;IAClG,OAAO,QAAQ,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC;AACz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M,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/D,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC1D,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,QAAQ,CAAC,GAAY;IACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/hash.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HashString } from "./constants.js";
|
|
2
|
+
/** Raw SHA3-256 as lowercase hex (no prefix). */
|
|
3
|
+
export declare function sha3_256Hex(input: string | Uint8Array): string;
|
|
4
|
+
/** SHA3-256 as a prefixed `sha3-256:<hex>` HashString. */
|
|
5
|
+
export declare function sha3_256(input: string | Uint8Array): HashString;
|
|
6
|
+
/**
|
|
7
|
+
* Canonicalize (JCS) then hash — the one hashing path (spec §3.1).
|
|
8
|
+
* Returns a prefixed HashString over the RFC 8785 bytes of `value`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hashJson(value: unknown): HashString;
|
|
11
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG9E,iDAAiD;AACjD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAI9D;AAED,0DAA0D;AAC1D,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU,CAE/D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAEnD"}
|
package/dist/hash.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA3-256 hashing (spec/dar-0.1.md §4). SHA3-256 everywhere — an invariant,
|
|
3
|
+
* not a per-call choice. Hash strings are `sha3-256:<64 lowercase hex>`.
|
|
4
|
+
*/
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { HASH_ALGORITHM, HASH_PREFIX } from "./constants.js";
|
|
7
|
+
import { canonicalizeToBytes } from "./jcs.js";
|
|
8
|
+
/** Raw SHA3-256 as lowercase hex (no prefix). */
|
|
9
|
+
export function sha3_256Hex(input) {
|
|
10
|
+
const h = createHash(HASH_ALGORITHM);
|
|
11
|
+
h.update(typeof input === "string" ? Buffer.from(input, "utf8") : input);
|
|
12
|
+
return h.digest("hex");
|
|
13
|
+
}
|
|
14
|
+
/** SHA3-256 as a prefixed `sha3-256:<hex>` HashString. */
|
|
15
|
+
export function sha3_256(input) {
|
|
16
|
+
return `${HASH_PREFIX}${sha3_256Hex(input)}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Canonicalize (JCS) then hash — the one hashing path (spec §3.1).
|
|
20
|
+
* Returns a prefixed HashString over the RFC 8785 bytes of `value`.
|
|
21
|
+
*/
|
|
22
|
+
export function hashJson(value) {
|
|
23
|
+
return sha3_256(canonicalizeToBytes(value));
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C,iDAAiD;AACjD,MAAM,UAAU,WAAW,CAAC,KAA0B;IACpD,MAAM,CAAC,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;IACrC,CAAC,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACzE,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,QAAQ,CAAC,KAA0B;IACjD,OAAO,GAAG,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,EAAgB,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,QAAQ,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rubric-protocol/attest-decision — core SDK (DAR/0.1).
|
|
3
|
+
*
|
|
4
|
+
* Public surface: fire-and-forget attestation (`Attestor`), the DAR builder,
|
|
5
|
+
* JCS canonicalization, SHA3-256 hashing, ULID minting, the durable spool, and
|
|
6
|
+
* transports. See spec/dar-0.1.md and tasks/P1.md.
|
|
7
|
+
*/
|
|
8
|
+
export { DAR_VERSION, HASH_ALGORITHM, HASH_PREFIX, TIERED_ATTEST_PATH, API_KEY_ENV, type LeafType, type HashString, type DarCore, type AdapterInfo, type TransmitMode, type PayloadRecord, } from "./constants.js";
|
|
9
|
+
export { canonicalize, canonicalizeToBytes, JcsError } from "./jcs.js";
|
|
10
|
+
export { sha3_256, sha3_256Hex, hashJson } from "./hash.js";
|
|
11
|
+
export { ulid, monotonicUlidFactory } from "./ulid.js";
|
|
12
|
+
export { DarBuilder, leafHash, canonicalDar, decisionHashOf, toPayload, type DarBuildInput, type DarBuilderDeps, type DarMeta, } from "./dar.js";
|
|
13
|
+
export { Spool, DEFAULT_MAX_BYTES, type SpoolRecord, type SpoolOptions } from "./spool.js";
|
|
14
|
+
export { HttpTransport, type Transport, type HttpTransportOptions, } from "./transport.js";
|
|
15
|
+
export { Attestor, type AttestorOptions } from "./attestor.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,WAAW,EACX,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,OAAO,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EACL,aAAa,EACb,KAAK,SAAS,EACd,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC"}
|