openttt 0.2.7 → 0.2.9

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.
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GrgPipeline = void 0;
4
- // sdk/src/grg_pipeline.ts
5
- const grg_forward_1 = require("./grg_forward");
6
- const grg_inverse_1 = require("./grg_inverse");
7
- const logger_1 = require("./logger");
8
- class GrgPipeline {
9
- static MAX_INPUT_SIZE = 100 * 1024 * 1024; // 100 MB
10
- static processForward(data, chainId, poolAddress) {
11
- if (data.length > this.MAX_INPUT_SIZE) {
12
- throw new Error(`[GRG] Input size ${data.length} exceeds MAX_INPUT_SIZE ${this.MAX_INPUT_SIZE}`);
13
- }
14
- logger_1.logger.info("Starting GRG forward pipeline...");
15
- try {
16
- const shards = grg_forward_1.GrgForward.encode(data, chainId, poolAddress);
17
- logger_1.logger.info(`GRG forward pipeline complete. Generated ${shards.length} shards.`);
18
- return shards;
19
- }
20
- catch (error) {
21
- logger_1.logger.error(`GRG forward pipeline failed: ${error}`);
22
- throw error;
23
- }
24
- }
25
- static processInverse(shards, originalLength, chainId, poolAddress) {
26
- logger_1.logger.info("Starting GRG inverse pipeline...");
27
- try {
28
- const hmacKey = grg_forward_1.GrgForward.deriveHmacKey(chainId, poolAddress);
29
- const decodedShards = shards.map(s => {
30
- try {
31
- return s ? grg_inverse_1.GrgInverse.golayDecodeWrapper(s, hmacKey) : null;
32
- }
33
- catch (e) {
34
- logger_1.logger.warn(`Golay decode failed for a shard: ${e}`);
35
- return null;
36
- }
37
- });
38
- const withLen = grg_inverse_1.GrgInverse.redstuffDecode(decodedShards);
39
- const decodedLength = (withLen[0] << 24) | (withLen[1] << 16) | (withLen[2] << 8) | withLen[3];
40
- const compressed = withLen.subarray(4);
41
- const decompressed = grg_inverse_1.GrgInverse.golombDecode(compressed);
42
- const final = decompressed.subarray(0, decodedLength);
43
- if (final.length !== originalLength) {
44
- throw new Error(`[GRG] Length mismatch in inverse: expected ${originalLength}, got ${final.length}`);
45
- }
46
- logger_1.logger.info("GRG inverse pipeline complete.");
47
- return final;
48
- }
49
- catch (error) {
50
- logger_1.logger.error(`GRG inverse pipeline failed: ${error}`);
51
- throw error;
52
- }
53
- }
54
- }
55
- exports.GrgPipeline = GrgPipeline;
@@ -1,13 +0,0 @@
1
- export declare class ReedSolomon {
2
- private static expTable;
3
- private static logTable;
4
- private static initialized;
5
- private static vandermondeCache;
6
- static init(): void;
7
- static mul(a: number, b: number): number;
8
- static div(a: number, b: number): number;
9
- static invertMatrix(matrix: number[][]): number[][];
10
- static buildVandermonde(rows: number, cols: number): number[][];
11
- static encode(data: Uint8Array, dataShards?: number, parityShards?: number): Uint8Array[];
12
- static decode(shards: (Uint8Array | null)[], dataShards?: number, parityShards?: number): Uint8Array;
13
- }
@@ -1,170 +0,0 @@
1
- "use strict";
2
- // sdk/src/reed_solomon.ts
3
- // Reed-Solomon GF(2^8) erasure coding
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.ReedSolomon = void 0;
6
- class ReedSolomon {
7
- static expTable = new Uint8Array(256);
8
- static logTable = new Uint8Array(256);
9
- static initialized = false;
10
- static vandermondeCache = new Map();
11
- static init() {
12
- if (this.initialized)
13
- return;
14
- let x = 1;
15
- for (let i = 0; i < 255; i++) {
16
- this.expTable[i] = x;
17
- this.logTable[x] = i;
18
- x <<= 1;
19
- if (x & 0x100) {
20
- x ^= 0x11D; // x^8 + x^4 + x^3 + x^2 + 1
21
- }
22
- }
23
- this.expTable[255] = this.expTable[0];
24
- this.logTable[0] = 0;
25
- this.initialized = true;
26
- }
27
- static mul(a, b) {
28
- if (a === 0 || b === 0)
29
- return 0;
30
- return this.expTable[(this.logTable[a] + this.logTable[b]) % 255];
31
- }
32
- static div(a, b) {
33
- if (b === 0)
34
- throw new Error("Division by zero");
35
- if (a === 0)
36
- return 0;
37
- return this.expTable[(this.logTable[a] - this.logTable[b] + 255) % 255];
38
- }
39
- static invertMatrix(matrix) {
40
- const n = matrix.length;
41
- const aug = [];
42
- for (let i = 0; i < n; i++) {
43
- aug[i] = [];
44
- for (let j = 0; j < n; j++)
45
- aug[i][j] = matrix[i][j];
46
- for (let j = 0; j < n; j++)
47
- aug[i][j + n] = (i === j) ? 1 : 0;
48
- }
49
- for (let i = 0; i < n; i++) {
50
- let pivot = i;
51
- while (pivot < n && aug[pivot][i] === 0)
52
- pivot++;
53
- if (pivot === n)
54
- throw new Error("Singular matrix");
55
- if (pivot !== i) {
56
- const temp = aug[i];
57
- aug[i] = aug[pivot];
58
- aug[pivot] = temp;
59
- }
60
- const pivotVal = aug[i][i];
61
- if (pivotVal !== 1) {
62
- for (let j = i; j < 2 * n; j++)
63
- aug[i][j] = this.div(aug[i][j], pivotVal);
64
- }
65
- for (let j = 0; j < n; j++) {
66
- if (i !== j && aug[j][i] !== 0) {
67
- const factor = aug[j][i];
68
- for (let k = i; k < 2 * n; k++)
69
- aug[j][k] ^= this.mul(factor, aug[i][k]);
70
- }
71
- }
72
- }
73
- const inv = [];
74
- for (let i = 0; i < n; i++) {
75
- inv[i] = [];
76
- for (let j = 0; j < n; j++)
77
- inv[i][j] = aug[i][j + n];
78
- }
79
- return inv;
80
- }
81
- static buildVandermonde(rows, cols) {
82
- const cacheKey = `${rows}-${cols}`;
83
- const cached = this.vandermondeCache.get(cacheKey);
84
- if (cached)
85
- return cached;
86
- const V = [];
87
- for (let r = 0; r < rows; r++) {
88
- V[r] = [];
89
- const x = r + 1;
90
- for (let c = 0; c < cols; c++) {
91
- V[r][c] = c === 0 ? 1 : this.mul(V[r][c - 1], x);
92
- }
93
- }
94
- const V_top = [];
95
- for (let i = 0; i < cols; i++)
96
- V_top.push([...V[i]]);
97
- const V_top_inv = this.invertMatrix(V_top);
98
- const G = [];
99
- for (let r = 0; r < rows; r++) {
100
- G[r] = [];
101
- for (let c = 0; c < cols; c++) {
102
- let val = 0;
103
- for (let k = 0; k < cols; k++)
104
- val ^= this.mul(V[r][k], V_top_inv[k][c]);
105
- G[r][c] = val;
106
- }
107
- }
108
- this.vandermondeCache.set(cacheKey, G);
109
- return G;
110
- }
111
- static encode(data, dataShards = 4, parityShards = 2) {
112
- this.init();
113
- const totalShards = dataShards + parityShards;
114
- const rawShardSize = Math.ceil(data.length / dataShards);
115
- const shardSize = Math.ceil(rawShardSize / 3) * 3;
116
- const matrix = this.buildVandermonde(totalShards, dataShards);
117
- const shards = [];
118
- for (let i = 0; i < totalShards; i++)
119
- shards.push(new Uint8Array(shardSize));
120
- for (let i = 0; i < dataShards; i++) {
121
- shards[i].set(data.subarray(i * shardSize, Math.min((i + 1) * shardSize, data.length)));
122
- }
123
- for (let c = 0; c < shardSize; c++) {
124
- for (let r = dataShards; r < totalShards; r++) {
125
- let val = 0;
126
- for (let j = 0; j < dataShards; j++)
127
- val ^= this.mul(matrix[r][j], shards[j][c]);
128
- shards[r][c] = val;
129
- }
130
- }
131
- return shards;
132
- }
133
- static decode(shards, dataShards = 4, parityShards = 2) {
134
- this.init();
135
- const totalShards = dataShards + parityShards;
136
- if (shards.length !== totalShards) {
137
- throw new Error(`[RS] Expected ${totalShards} shards, got ${shards.length}`);
138
- }
139
- const presentIndices = [];
140
- const presentShards = [];
141
- for (let i = 0; i < totalShards; i++) {
142
- if (shards[i] !== null && shards[i] !== undefined) {
143
- presentIndices.push(i);
144
- presentShards.push(shards[i]);
145
- if (presentIndices.length === dataShards)
146
- break;
147
- }
148
- }
149
- if (presentIndices.length < dataShards) {
150
- throw new Error(`[RS] Not enough shards for recovery: need ${dataShards}, got ${presentIndices.length}`);
151
- }
152
- const shardSize = presentShards[0].length;
153
- const origMatrix = this.buildVandermonde(totalShards, dataShards);
154
- const subMatrix = [];
155
- for (let i = 0; i < dataShards; i++)
156
- subMatrix.push([...origMatrix[presentIndices[i]]]);
157
- const invMatrix = this.invertMatrix(subMatrix);
158
- const result = new Uint8Array(shardSize * dataShards);
159
- for (let c = 0; c < shardSize; c++) {
160
- for (let r = 0; r < dataShards; r++) {
161
- let val = 0;
162
- for (let j = 0; j < dataShards; j++)
163
- val ^= this.mul(invMatrix[r][j], presentShards[j][c]);
164
- result[r * shardSize + c] = val;
165
- }
166
- }
167
- return result;
168
- }
169
- }
170
- exports.ReedSolomon = ReedSolomon;
@@ -1,131 +0,0 @@
1
- import { EventEmitter } from "events";
2
- import { AutoMintConfig, TTTClientConfig, MintResult, HealthStatus } from "./types";
3
- import { HttpOnlyClient, HttpOnlyClientOptions } from "./http_client";
4
- export { HealthStatus } from "./types";
5
- /**
6
- * Typed event map for TTTClient EventEmitter.
7
- */
8
- export interface TTTClientEvents {
9
- mint: [result: MintResult];
10
- error: [error: Error];
11
- alert: [alert: string];
12
- latency: [ms: number];
13
- modeSwitch: [mode: string];
14
- }
15
- /**
16
- * TTTClient - SDK entry point for DEX operators.
17
- * Initializes all internal modules and manages the auto-minting process.
18
- */
19
- export declare class TTTClient extends EventEmitter {
20
- private config;
21
- private autoMintEngine;
22
- private poolRegistry;
23
- private isInitialized;
24
- private mintCount;
25
- private mintFailures;
26
- private totalFeesPaid;
27
- private signer;
28
- private lastTokenId;
29
- private mintLatencies;
30
- private maxLatencyHistory;
31
- private lastMintAt;
32
- private startedAt;
33
- private minBalanceWei;
34
- constructor(config: AutoMintConfig);
35
- /**
36
- * Static factory for Base Mainnet
37
- */
38
- static forBase(config: Omit<TTTClientConfig, 'network'>): Promise<TTTClient>;
39
- /**
40
- * Static factory for Base Sepolia
41
- */
42
- static forSepolia(config: Omit<TTTClientConfig, 'network'>): Promise<TTTClient>;
43
- /**
44
- * Zero-friction sandbox mode — no ETH, no signer, no on-chain interaction.
45
- *
46
- * Returns an HttpOnlyClient that fetches verified time from NIST, Apple,
47
- * Google, and Cloudflare HTTPS endpoints and produces HMAC-signed PoTs.
48
- *
49
- * @example
50
- * // Zero-friction: no wallet, no RPC, no gas
51
- * const client = TTTClient.httpOnly();
52
- * const pot = await client.generatePoT();
53
- * console.log(pot.timestamp, pot.confidence);
54
- *
55
- * // Verify locally (no on-chain check needed)
56
- * const result = client.verifyPoT(pot);
57
- * console.log(result.valid); // true
58
- */
59
- static httpOnly(options?: HttpOnlyClientOptions): HttpOnlyClient;
60
- /**
61
- * Universal factory to create and initialize a client
62
- */
63
- static create(config: TTTClientConfig): Promise<TTTClient>;
64
- /**
65
- * Gracefully shuts down the SDK, stopping all background processes and listeners.
66
- */
67
- destroy(): Promise<void>;
68
- /**
69
- * Initialize the SDK: RPC connection, time sources, fee engine wiring.
70
- */
71
- initialize(): Promise<void>;
72
- /**
73
- * Start the auto-minting process.
74
- */
75
- startAutoMint(): void;
76
- /**
77
- * Stop the auto-minting process.
78
- */
79
- stopAutoMint(): void;
80
- /**
81
- * Resume auto-minting after a circuit breaker trip.
82
- * Resets consecutive failure count and restarts the engine.
83
- */
84
- resume(): void;
85
- /**
86
- * List registered pools.
87
- */
88
- listPools(): string[];
89
- /**
90
- * Get stats for a specific pool.
91
- */
92
- getPoolStats(poolAddress: string): {
93
- minted: bigint;
94
- burned: bigint;
95
- } | null;
96
- /**
97
- * Set minimum ETH balance threshold for health alerts.
98
- */
99
- setMinBalance(weiAmount: bigint): void;
100
- /**
101
- * Register alert callback for real-time notifications.
102
- * Backward compatible: delegates to EventEmitter 'alert' event.
103
- */
104
- onAlert(callback: (alert: string) => void): void;
105
- private emitAlert;
106
- /**
107
- * Record a mint failure (called internally or externally).
108
- */
109
- recordMintFailure(): void;
110
- /**
111
- * Record mint latency in ms (called from auto-mint wrapper).
112
- */
113
- recordMintLatency(ms: number): void;
114
- /**
115
- * Production health check — liveness + readiness + metrics.
116
- * No exceptions: always returns a HealthStatus object.
117
- */
118
- getHealth(): Promise<HealthStatus>;
119
- /**
120
- * Return current SDK status and statistics (balance, mint count, fees, etc.)
121
- */
122
- getStatus(): Promise<{
123
- isInitialized: boolean;
124
- tier: string;
125
- mintCount: number;
126
- totalFeesPaid: string;
127
- balance: string;
128
- tttBalance: string;
129
- lastTokenId: string | null;
130
- }>;
131
- }