@vorionsys/runtime 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/common/logger.d.ts +12 -0
- package/dist/common/logger.d.ts.map +1 -0
- package/dist/common/logger.js +23 -0
- package/dist/common/logger.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/intent-pipeline/index.d.ts +65 -0
- package/dist/intent-pipeline/index.d.ts.map +1 -0
- package/dist/intent-pipeline/index.js +244 -0
- package/dist/intent-pipeline/index.js.map +1 -0
- package/dist/intent-pipeline/types.d.ts +78 -0
- package/dist/intent-pipeline/types.d.ts.map +1 -0
- package/dist/intent-pipeline/types.js +17 -0
- package/dist/intent-pipeline/types.js.map +1 -0
- package/dist/proof-committer/index.d.ts +86 -0
- package/dist/proof-committer/index.d.ts.map +1 -0
- package/dist/proof-committer/index.js +252 -0
- package/dist/proof-committer/index.js.map +1 -0
- package/dist/proof-committer/types.d.ts +107 -0
- package/dist/proof-committer/types.d.ts.map +1 -0
- package/dist/proof-committer/types.js +58 -0
- package/dist/proof-committer/types.js.map +1 -0
- package/dist/stores/index.d.ts +10 -0
- package/dist/stores/index.d.ts.map +1 -0
- package/dist/stores/index.js +10 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/stores/sqlite-proof-store.d.ts +61 -0
- package/dist/stores/sqlite-proof-store.d.ts.map +1 -0
- package/dist/stores/sqlite-proof-store.js +239 -0
- package/dist/stores/sqlite-proof-store.js.map +1 -0
- package/dist/stores/sqlite-trust-store.d.ts +124 -0
- package/dist/stores/sqlite-trust-store.d.ts.map +1 -0
- package/dist/stores/sqlite-trust-store.js +297 -0
- package/dist/stores/sqlite-trust-store.js.map +1 -0
- package/dist/trust-facade/index.d.ts +72 -0
- package/dist/trust-facade/index.d.ts.map +1 -0
- package/dist/trust-facade/index.js +410 -0
- package/dist/trust-facade/index.js.map +1 -0
- package/dist/trust-facade/types.d.ts +211 -0
- package/dist/trust-facade/types.d.ts.map +1 -0
- package/dist/trust-facade/types.js +45 -0
- package/dist/trust-facade/types.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProofCommitter - Zero-Latency Proof System
|
|
3
|
+
*
|
|
4
|
+
* Synchronous hash commitment (<1ms) with async batch processing.
|
|
5
|
+
* Uses Merkle trees for batch integrity and optional Ed25519 signing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
import * as crypto from 'node:crypto';
|
|
10
|
+
import { createLogger } from '../common/logger.js';
|
|
11
|
+
import { DEFAULT_PROOF_COMMITTER_CONFIG, InMemoryProofStore } from './types.js';
|
|
12
|
+
export * from './types.js';
|
|
13
|
+
const logger = createLogger({ component: 'proof-committer' });
|
|
14
|
+
/**
|
|
15
|
+
* ProofCommitter - Fast synchronous commitment with async persistence
|
|
16
|
+
*/
|
|
17
|
+
export class ProofCommitter {
|
|
18
|
+
config;
|
|
19
|
+
buffer = [];
|
|
20
|
+
store;
|
|
21
|
+
flushTimer = null;
|
|
22
|
+
privateKey = null;
|
|
23
|
+
isFlushing = false;
|
|
24
|
+
pendingFlush = null;
|
|
25
|
+
// Metrics
|
|
26
|
+
totalCommitments = 0;
|
|
27
|
+
totalBatches = 0;
|
|
28
|
+
totalFlushTimeMs = 0;
|
|
29
|
+
constructor(config, store) {
|
|
30
|
+
this.config = { ...DEFAULT_PROOF_COMMITTER_CONFIG, ...config };
|
|
31
|
+
this.store = store ?? new InMemoryProofStore();
|
|
32
|
+
// Load signing key if provided
|
|
33
|
+
if (this.config.enableSigning && this.config.privateKey) {
|
|
34
|
+
try {
|
|
35
|
+
this.privateKey = crypto.createPrivateKey({
|
|
36
|
+
key: Buffer.from(this.config.privateKey, 'base64'),
|
|
37
|
+
format: 'der',
|
|
38
|
+
type: 'pkcs8',
|
|
39
|
+
});
|
|
40
|
+
logger.info('Signing key loaded');
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
logger.error({ error }, 'Failed to load signing key');
|
|
44
|
+
throw new Error('Invalid signing key');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Start flush timer
|
|
48
|
+
this.startFlushTimer();
|
|
49
|
+
logger.info({ config: this.config }, 'ProofCommitter initialized');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Commit an event - MUST complete in <1ms
|
|
53
|
+
*
|
|
54
|
+
* This is the HOT PATH - synchronous, fast
|
|
55
|
+
*/
|
|
56
|
+
commit(event) {
|
|
57
|
+
const startTime = performance.now();
|
|
58
|
+
const commitment = {
|
|
59
|
+
id: crypto.randomUUID(),
|
|
60
|
+
hash: this.fastHash(event),
|
|
61
|
+
timestamp: Date.now(),
|
|
62
|
+
event,
|
|
63
|
+
};
|
|
64
|
+
this.buffer.push(commitment);
|
|
65
|
+
this.totalCommitments++;
|
|
66
|
+
// Trigger async flush if buffer full
|
|
67
|
+
if (this.buffer.length >= this.config.maxBufferSize) {
|
|
68
|
+
setImmediate(() => this.flush());
|
|
69
|
+
}
|
|
70
|
+
const latencyMs = performance.now() - startTime;
|
|
71
|
+
// Warn if we exceeded 1ms
|
|
72
|
+
if (latencyMs > 1) {
|
|
73
|
+
logger.warn({ latencyMs, commitmentId: commitment.id }, 'Commitment exceeded 1ms target');
|
|
74
|
+
}
|
|
75
|
+
return commitment.id;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Fast hash - SHA-256, no signing, ~0.1ms
|
|
79
|
+
*/
|
|
80
|
+
fastHash(event) {
|
|
81
|
+
const hash = crypto.createHash('sha256');
|
|
82
|
+
hash.update(JSON.stringify(event));
|
|
83
|
+
return hash.digest('hex');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Flush buffer to proof store (COLD PATH - async)
|
|
87
|
+
*/
|
|
88
|
+
async flush() {
|
|
89
|
+
// Prevent concurrent flushes
|
|
90
|
+
if (this.isFlushing) {
|
|
91
|
+
return this.pendingFlush ?? Promise.resolve();
|
|
92
|
+
}
|
|
93
|
+
if (this.buffer.length === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.isFlushing = true;
|
|
97
|
+
const startTime = performance.now();
|
|
98
|
+
// Take current buffer and reset
|
|
99
|
+
const batch = this.buffer.splice(0, this.buffer.length);
|
|
100
|
+
this.pendingFlush = (async () => {
|
|
101
|
+
try {
|
|
102
|
+
// Build Merkle tree
|
|
103
|
+
const merkleRoot = this.buildMerkleRoot(batch.map((c) => c.hash));
|
|
104
|
+
// Sign if enabled
|
|
105
|
+
const signature = this.sign(merkleRoot);
|
|
106
|
+
// Create batch
|
|
107
|
+
const proofBatch = {
|
|
108
|
+
batchId: crypto.randomUUID(),
|
|
109
|
+
merkleRoot,
|
|
110
|
+
signature,
|
|
111
|
+
commitments: batch,
|
|
112
|
+
createdAt: new Date(),
|
|
113
|
+
eventCount: batch.length,
|
|
114
|
+
};
|
|
115
|
+
// Persist to store
|
|
116
|
+
await this.store.writeBatch(proofBatch);
|
|
117
|
+
this.totalBatches++;
|
|
118
|
+
const flushTimeMs = performance.now() - startTime;
|
|
119
|
+
this.totalFlushTimeMs += flushTimeMs;
|
|
120
|
+
logger.debug({
|
|
121
|
+
batchId: proofBatch.batchId,
|
|
122
|
+
eventCount: batch.length,
|
|
123
|
+
merkleRoot: merkleRoot.substring(0, 16) + '...',
|
|
124
|
+
flushTimeMs,
|
|
125
|
+
}, 'Batch flushed');
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
// On error, put events back in buffer (don't lose them)
|
|
129
|
+
this.buffer.unshift(...batch);
|
|
130
|
+
logger.error({ error, eventCount: batch.length }, 'Flush failed, events returned to buffer');
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
this.isFlushing = false;
|
|
135
|
+
this.pendingFlush = null;
|
|
136
|
+
}
|
|
137
|
+
})();
|
|
138
|
+
return this.pendingFlush;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Build Merkle root from hashes
|
|
142
|
+
*/
|
|
143
|
+
buildMerkleRoot(hashes) {
|
|
144
|
+
if (hashes.length === 0) {
|
|
145
|
+
return '0'.repeat(64);
|
|
146
|
+
}
|
|
147
|
+
if (hashes.length === 1) {
|
|
148
|
+
return hashes[0];
|
|
149
|
+
}
|
|
150
|
+
// Pad to even number
|
|
151
|
+
const leaves = [...hashes];
|
|
152
|
+
if (leaves.length % 2 !== 0) {
|
|
153
|
+
leaves.push(leaves[leaves.length - 1]);
|
|
154
|
+
}
|
|
155
|
+
// Build tree bottom-up
|
|
156
|
+
while (leaves.length > 1) {
|
|
157
|
+
const newLevel = [];
|
|
158
|
+
for (let i = 0; i < leaves.length; i += 2) {
|
|
159
|
+
const left = leaves[i];
|
|
160
|
+
const right = leaves[i + 1] ?? left;
|
|
161
|
+
const combined = crypto.createHash('sha256').update(left + right).digest('hex');
|
|
162
|
+
newLevel.push(combined);
|
|
163
|
+
}
|
|
164
|
+
leaves.length = 0;
|
|
165
|
+
leaves.push(...newLevel);
|
|
166
|
+
}
|
|
167
|
+
return leaves[0];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sign data with Ed25519 (if enabled)
|
|
171
|
+
*/
|
|
172
|
+
sign(data) {
|
|
173
|
+
if (!this.privateKey) {
|
|
174
|
+
return '';
|
|
175
|
+
}
|
|
176
|
+
const signature = crypto.sign(null, Buffer.from(data), this.privateKey);
|
|
177
|
+
return signature.toString('base64');
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Start periodic flush timer
|
|
181
|
+
*/
|
|
182
|
+
startFlushTimer() {
|
|
183
|
+
this.flushTimer = setInterval(() => {
|
|
184
|
+
if (this.buffer.length > 0) {
|
|
185
|
+
this.flush().catch((error) => {
|
|
186
|
+
logger.error({ error }, 'Periodic flush failed');
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}, this.config.flushIntervalMs);
|
|
190
|
+
// Don't block process exit
|
|
191
|
+
this.flushTimer.unref();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Stop the committer (flush remaining and cleanup)
|
|
195
|
+
*/
|
|
196
|
+
async stop() {
|
|
197
|
+
if (this.flushTimer) {
|
|
198
|
+
clearInterval(this.flushTimer);
|
|
199
|
+
this.flushTimer = null;
|
|
200
|
+
}
|
|
201
|
+
// Final flush
|
|
202
|
+
await this.flush();
|
|
203
|
+
logger.info({
|
|
204
|
+
totalCommitments: this.totalCommitments,
|
|
205
|
+
totalBatches: this.totalBatches,
|
|
206
|
+
avgFlushTimeMs: this.totalBatches > 0 ? this.totalFlushTimeMs / this.totalBatches : 0,
|
|
207
|
+
}, 'ProofCommitter stopped');
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get current buffer size
|
|
211
|
+
*/
|
|
212
|
+
getBufferSize() {
|
|
213
|
+
return this.buffer.length;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get metrics
|
|
217
|
+
*/
|
|
218
|
+
getMetrics() {
|
|
219
|
+
return {
|
|
220
|
+
totalCommitments: this.totalCommitments,
|
|
221
|
+
totalBatches: this.totalBatches,
|
|
222
|
+
avgFlushTimeMs: this.totalBatches > 0 ? this.totalFlushTimeMs / this.totalBatches : 0,
|
|
223
|
+
bufferSize: this.buffer.length,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Get commitment by ID (from store)
|
|
228
|
+
*/
|
|
229
|
+
async getCommitment(commitmentId) {
|
|
230
|
+
return this.store.getCommitment(commitmentId);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get all commitments for an entity
|
|
234
|
+
*/
|
|
235
|
+
async getCommitmentsForEntity(entityId) {
|
|
236
|
+
return this.store.getCommitmentsForEntity(entityId);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Verify a commitment's hash
|
|
240
|
+
*/
|
|
241
|
+
verifyCommitment(commitment) {
|
|
242
|
+
const expectedHash = this.fastHash(commitment.event);
|
|
243
|
+
return commitment.hash === expectedHash;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a new ProofCommitter instance
|
|
248
|
+
*/
|
|
249
|
+
export function createProofCommitter(config, store) {
|
|
250
|
+
return new ProofCommitter(config, store);
|
|
251
|
+
}
|
|
252
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proof-committer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAQnD,OAAO,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhF,cAAc,YAAY,CAAC;AAE3B,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,MAAM,CAAuB;IAC7B,MAAM,GAAsB,EAAE,CAAC;IAC/B,KAAK,CAAa;IAClB,UAAU,GAA0B,IAAI,CAAC;IACzC,UAAU,GAA4B,IAAI,CAAC;IAC3C,UAAU,GAAG,KAAK,CAAC;IACnB,YAAY,GAAyB,IAAI,CAAC;IAElD,UAAU;IACF,gBAAgB,GAAG,CAAC,CAAC;IACrB,YAAY,GAAG,CAAC,CAAC;IACjB,gBAAgB,GAAG,CAAC,CAAC;IAE7B,YAAY,MAAsC,EAAE,KAAkB;QACpE,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,8BAA8B,EAAE,GAAG,MAAM,EAAE,CAAC;QAC/D,IAAI,CAAC,KAAK,GAAG,KAAK,IAAI,IA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
* ProofCommitter Types
|
|
3
|
+
*
|
|
4
|
+
* Zero-latency proof design with async batching.
|
|
5
|
+
* Synchronous hash commitment (<1ms) with async batch processing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Event types that can be recorded in the proof plane
|
|
11
|
+
*/
|
|
12
|
+
export type ProofEventType = 'intent_submitted' | 'decision_made' | 'execution_started' | 'execution_completed' | 'trust_signal' | 'agent_admitted' | 'agent_revoked' | 'parity_violation';
|
|
13
|
+
/**
|
|
14
|
+
* A proof event to be committed
|
|
15
|
+
*/
|
|
16
|
+
export interface ProofEvent {
|
|
17
|
+
/** Event type */
|
|
18
|
+
type: ProofEventType;
|
|
19
|
+
/** Entity ID (agent, intent, etc.) */
|
|
20
|
+
entityId: string;
|
|
21
|
+
/** Event payload */
|
|
22
|
+
payload: Record<string, unknown>;
|
|
23
|
+
/** Timestamp */
|
|
24
|
+
timestamp: number;
|
|
25
|
+
/** Optional correlation ID for linking events */
|
|
26
|
+
correlationId?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A commitment in the buffer
|
|
30
|
+
*/
|
|
31
|
+
export interface ProofCommitment {
|
|
32
|
+
/** Unique commitment ID */
|
|
33
|
+
id: string;
|
|
34
|
+
/** SHA-256 hash of the event */
|
|
35
|
+
hash: string;
|
|
36
|
+
/** Timestamp when committed */
|
|
37
|
+
timestamp: number;
|
|
38
|
+
/** The original event (held until flushed) */
|
|
39
|
+
event: ProofEvent;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A batch of commitments ready for persistence
|
|
43
|
+
*/
|
|
44
|
+
export interface ProofBatch {
|
|
45
|
+
/** Unique batch ID */
|
|
46
|
+
batchId: string;
|
|
47
|
+
/** Merkle root of all commitments */
|
|
48
|
+
merkleRoot: string;
|
|
49
|
+
/** Ed25519 signature of merkle root */
|
|
50
|
+
signature: string;
|
|
51
|
+
/** All commitments in this batch */
|
|
52
|
+
commitments: ProofCommitment[];
|
|
53
|
+
/** When batch was created */
|
|
54
|
+
createdAt: Date;
|
|
55
|
+
/** Number of events in batch */
|
|
56
|
+
eventCount: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for ProofCommitter
|
|
60
|
+
*/
|
|
61
|
+
export interface ProofCommitterConfig {
|
|
62
|
+
/** Maximum buffer size before auto-flush */
|
|
63
|
+
maxBufferSize: number;
|
|
64
|
+
/** Flush interval in milliseconds */
|
|
65
|
+
flushIntervalMs: number;
|
|
66
|
+
/** Enable signing (requires private key) */
|
|
67
|
+
enableSigning: boolean;
|
|
68
|
+
/** Private key for signing (base64-encoded Ed25519) */
|
|
69
|
+
privateKey?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Default configuration
|
|
73
|
+
*/
|
|
74
|
+
export declare const DEFAULT_PROOF_COMMITTER_CONFIG: ProofCommitterConfig;
|
|
75
|
+
/**
|
|
76
|
+
* Proof store interface for persistence
|
|
77
|
+
*/
|
|
78
|
+
export interface ProofStore {
|
|
79
|
+
/** Write a batch to storage */
|
|
80
|
+
writeBatch(batch: ProofBatch): Promise<void>;
|
|
81
|
+
/** Get a batch by ID */
|
|
82
|
+
getBatch(batchId: string): Promise<ProofBatch | null>;
|
|
83
|
+
/** Get commitment by ID */
|
|
84
|
+
getCommitment(commitmentId: string): Promise<ProofCommitment | null>;
|
|
85
|
+
/** Get all commitments for an entity */
|
|
86
|
+
getCommitmentsForEntity(entityId: string): Promise<ProofCommitment[]>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* In-memory proof store for testing/development
|
|
90
|
+
*/
|
|
91
|
+
export declare class InMemoryProofStore implements ProofStore {
|
|
92
|
+
private batches;
|
|
93
|
+
private commitments;
|
|
94
|
+
private entityIndex;
|
|
95
|
+
writeBatch(batch: ProofBatch): Promise<void>;
|
|
96
|
+
getBatch(batchId: string): Promise<ProofBatch | null>;
|
|
97
|
+
getCommitment(commitmentId: string): Promise<ProofCommitment | null>;
|
|
98
|
+
getCommitmentsForEntity(entityId: string): Promise<ProofCommitment[]>;
|
|
99
|
+
/** Get stats for testing */
|
|
100
|
+
getStats(): {
|
|
101
|
+
batches: number;
|
|
102
|
+
commitments: number;
|
|
103
|
+
};
|
|
104
|
+
/** Clear all data */
|
|
105
|
+
clear(): void;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/proof-committer/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,eAAe,GACf,mBAAmB,GACnB,qBAAqB,GACrB,cAAc,GACd,gBAAgB,GAChB,eAAe,GACf,kBAAkB,CAAC;AAEvB;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB;IACjB,IAAI,EAAE,cAAc,CAAC;IACrB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,SAAS,EAAE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AAI,CAAC;IAIpE,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAK3E,4BAA4B;IAC5B,QAAQ,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAOpD,qBAAqB;IACrB,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProofCommitter Types
|
|
3
|
+
*
|
|
4
|
+
* Zero-latency proof design with async batching.
|
|
5
|
+
* Synchronous hash commitment (<1ms) with async batch processing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Default configuration
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_PROOF_COMMITTER_CONFIG = {
|
|
13
|
+
maxBufferSize: 100,
|
|
14
|
+
flushIntervalMs: 100,
|
|
15
|
+
enableSigning: false,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* In-memory proof store for testing/development
|
|
19
|
+
*/
|
|
20
|
+
export class InMemoryProofStore {
|
|
21
|
+
batches = new Map();
|
|
22
|
+
commitments = new Map();
|
|
23
|
+
entityIndex = new Map();
|
|
24
|
+
async writeBatch(batch) {
|
|
25
|
+
this.batches.set(batch.batchId, batch);
|
|
26
|
+
for (const commitment of batch.commitments) {
|
|
27
|
+
this.commitments.set(commitment.id, commitment);
|
|
28
|
+
// Index by entity
|
|
29
|
+
const entityCommitments = this.entityIndex.get(commitment.event.entityId) ?? [];
|
|
30
|
+
entityCommitments.push(commitment.id);
|
|
31
|
+
this.entityIndex.set(commitment.event.entityId, entityCommitments);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async getBatch(batchId) {
|
|
35
|
+
return this.batches.get(batchId) ?? null;
|
|
36
|
+
}
|
|
37
|
+
async getCommitment(commitmentId) {
|
|
38
|
+
return this.commitments.get(commitmentId) ?? null;
|
|
39
|
+
}
|
|
40
|
+
async getCommitmentsForEntity(entityId) {
|
|
41
|
+
const ids = this.entityIndex.get(entityId) ?? [];
|
|
42
|
+
return ids.map((id) => this.commitments.get(id)).filter(Boolean);
|
|
43
|
+
}
|
|
44
|
+
/** Get stats for testing */
|
|
45
|
+
getStats() {
|
|
46
|
+
return {
|
|
47
|
+
batches: this.batches.size,
|
|
48
|
+
commitments: this.commitments.size,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/** Clear all data */
|
|
52
|
+
clear() {
|
|
53
|
+
this.batches.clear();
|
|
54
|
+
this.commitments.clear();
|
|
55
|
+
this.entityIndex.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/proof-committer/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA6EH;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAyB;IAClE,aAAa,EAAE,GAAG;IAClB,eAAe,EAAE,GAAG;IACpB,aAAa,EAAE,KAAK;CACrB,CAAC;AAgBF;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACrB,OAAO,GAA4B,IAAI,GAAG,EAAE,CAAC;IAC7C,WAAW,GAAiC,IAAI,GAAG,EAAE,CAAC;IACtD,WAAW,GAA0B,IAAI,GAAG,EAAE,CAAC;IAEvD,KAAK,CAAC,UAAU,CAAC,KAAiB;QAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAEvC,KAAK,MAAM,UAAU,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YAEhD,kBAAkB;YAClB,MAAM,iBAAiB,GAAG,IAAI,CAAC,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"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Proof Store
|
|
3
|
+
*
|
|
4
|
+
* Persistent storage for proof commitments and batches using SQLite.
|
|
5
|
+
*
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
*/
|
|
8
|
+
import type { ProofStore, ProofBatch, ProofCommitment } from '../proof-committer/types.js';
|
|
9
|
+
export interface SQLiteProofStoreConfig {
|
|
10
|
+
/** Database file path (use ':memory:' for in-memory) */
|
|
11
|
+
dbPath: string;
|
|
12
|
+
/** Enable WAL mode for better concurrency (default: true) */
|
|
13
|
+
walMode?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* SQLite implementation of ProofStore
|
|
17
|
+
*/
|
|
18
|
+
export declare class SQLiteProofStore implements ProofStore {
|
|
19
|
+
private db;
|
|
20
|
+
private config;
|
|
21
|
+
private stmts;
|
|
22
|
+
constructor(config: SQLiteProofStoreConfig);
|
|
23
|
+
private initializeSchema;
|
|
24
|
+
private prepareStatements;
|
|
25
|
+
/**
|
|
26
|
+
* Write a batch to storage
|
|
27
|
+
*/
|
|
28
|
+
writeBatch(batch: ProofBatch): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Get a batch by ID
|
|
31
|
+
*/
|
|
32
|
+
getBatch(batchId: string): Promise<ProofBatch | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Get commitment by ID
|
|
35
|
+
*/
|
|
36
|
+
getCommitment(commitmentId: string): Promise<ProofCommitment | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Get all commitments for an entity
|
|
39
|
+
*/
|
|
40
|
+
getCommitmentsForEntity(entityId: string): Promise<ProofCommitment[]>;
|
|
41
|
+
/**
|
|
42
|
+
* Get statistics
|
|
43
|
+
*/
|
|
44
|
+
getStats(): {
|
|
45
|
+
batches: number;
|
|
46
|
+
commitments: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Clear all data (useful for testing)
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Close the database connection
|
|
54
|
+
*/
|
|
55
|
+
close(): void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a new SQLite proof store
|
|
59
|
+
*/
|
|
60
|
+
export declare function createSQLiteProofStore(config: SQLiteProofStoreConfig): SQLiteProofStore;
|
|
61
|
+
//# sourceMappingURL=sqlite-proof-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite-proof-store.d.ts","sourceRoot":"","sources":["../../src/stores/sqlite-proof-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAA8B,MAAM,6BAA6B,CAAC;AAIvH,MAAM,WAAW,sBAAsB;IACrC,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,UAAU;IACjD,OAAO,CAAC,EAAE,CAAoB;IAC9B,OAAO,CAAC,MAAM,CAAyB;IAGvC,OAAO,CAAC,KAAK,CAMG;gBAEJ,MAAM,EAAE,sBAAsB;IAmB1C,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,iBAAiB;IAiCzB;;OAEG;IACG,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAoClD;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAmD3D;;OAEG;IACG,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA6B1E;;OAEG;IACG,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IA2B3E;;OAEG;IACH,QAAQ,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAUpD;;OAEG;IACH,KAAK,IAAI,IAAI;IAMb;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,sBAAsB,GAAG,gBAAgB,CAEvF"}
|