openttt 0.2.6 → 0.2.8
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/LICENSE +1 -1
- package/README.md +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/osnma_source.d.ts +82 -0
- package/dist/osnma_source.js +169 -0
- package/dist/time_synthesis.d.ts +1 -1
- package/dist/time_synthesis.js +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +47 -3
- package/dist/adaptive_switch.d.ts +0 -59
- package/dist/adaptive_switch.js +0 -145
- package/dist/auto_mint.d.ts +0 -61
- package/dist/auto_mint.js +0 -330
- package/dist/golay.d.ts +0 -7
- package/dist/golay.js +0 -139
- package/dist/grg_forward.d.ts +0 -7
- package/dist/grg_forward.js +0 -68
- package/dist/grg_inverse.d.ts +0 -7
- package/dist/grg_inverse.js +0 -93
- package/dist/grg_pipeline.d.ts +0 -5
- package/dist/grg_pipeline.js +0 -55
- package/dist/reed_solomon.d.ts +0 -13
- package/dist/reed_solomon.js +0 -170
package/dist/grg_pipeline.js
DELETED
|
@@ -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;
|
package/dist/reed_solomon.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/reed_solomon.js
DELETED
|
@@ -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;
|