openttt 0.1.2 → 0.2.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.
Files changed (78) hide show
  1. package/README.md +52 -30
  2. package/dist/adaptive_switch.d.ts +22 -7
  3. package/dist/adaptive_switch.js +52 -15
  4. package/dist/auto_mint.d.ts +22 -7
  5. package/dist/auto_mint.js +107 -30
  6. package/dist/ct_log.d.ts +47 -0
  7. package/dist/ct_log.js +107 -0
  8. package/dist/dynamic_fee.d.ts +13 -2
  9. package/dist/dynamic_fee.js +62 -11
  10. package/dist/errors.d.ts +44 -25
  11. package/dist/errors.js +58 -42
  12. package/dist/evm_connector.d.ts +28 -1
  13. package/dist/evm_connector.js +124 -32
  14. package/dist/grg_api_client.d.ts +41 -0
  15. package/dist/grg_api_client.js +116 -0
  16. package/dist/http_client.d.ts +98 -0
  17. package/dist/http_client.js +252 -0
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.js +5 -5
  20. package/dist/logger.d.ts +36 -4
  21. package/dist/logger.js +70 -11
  22. package/dist/networks.d.ts +21 -0
  23. package/dist/networks.js +30 -4
  24. package/dist/pool_registry.d.ts +9 -0
  25. package/dist/pool_registry.js +37 -0
  26. package/dist/pot_signer.d.ts +15 -0
  27. package/dist/pot_signer.js +28 -0
  28. package/dist/protocol_fee.d.ts +42 -26
  29. package/dist/protocol_fee.js +77 -54
  30. package/dist/revenue_tiers.d.ts +36 -0
  31. package/dist/revenue_tiers.js +83 -0
  32. package/dist/signer.d.ts +1 -2
  33. package/dist/signer.js +72 -14
  34. package/dist/time_synthesis.d.ts +38 -0
  35. package/dist/time_synthesis.js +131 -21
  36. package/dist/trust_store.d.ts +49 -0
  37. package/dist/trust_store.js +89 -0
  38. package/dist/ttt_builder.d.ts +1 -1
  39. package/dist/ttt_builder.js +2 -2
  40. package/dist/ttt_client.d.ts +42 -29
  41. package/dist/ttt_client.js +117 -28
  42. package/dist/types.d.ts +46 -3
  43. package/dist/v4_hook.d.ts +10 -2
  44. package/dist/v4_hook.js +10 -2
  45. package/dist/x402_enforcer.d.ts +17 -2
  46. package/dist/x402_enforcer.js +27 -2
  47. package/package.json +6 -2
  48. package/dist/golay.d.ts +0 -6
  49. package/dist/golay.js +0 -166
  50. package/dist/grg_forward.d.ts +0 -11
  51. package/dist/grg_forward.js +0 -74
  52. package/dist/grg_inverse.d.ts +0 -7
  53. package/dist/grg_inverse.js +0 -100
  54. package/dist/grg_pipeline.d.ts +0 -13
  55. package/dist/grg_pipeline.js +0 -64
  56. package/dist/reed_solomon.d.ts +0 -12
  57. package/dist/reed_solomon.js +0 -179
  58. package/vendor/helm-crypto/golay.d.ts +0 -6
  59. package/vendor/helm-crypto/golay.js +0 -167
  60. package/vendor/helm-crypto/golay.js.map +0 -1
  61. package/vendor/helm-crypto/grg_forward.d.ts +0 -22
  62. package/vendor/helm-crypto/grg_forward.js +0 -89
  63. package/vendor/helm-crypto/grg_forward.js.map +0 -1
  64. package/vendor/helm-crypto/grg_inverse.d.ts +0 -16
  65. package/vendor/helm-crypto/grg_inverse.js +0 -118
  66. package/vendor/helm-crypto/grg_inverse.js.map +0 -1
  67. package/vendor/helm-crypto/grg_pipeline.d.ts +0 -13
  68. package/vendor/helm-crypto/grg_pipeline.js +0 -66
  69. package/vendor/helm-crypto/grg_pipeline.js.map +0 -1
  70. package/vendor/helm-crypto/index.d.ts +0 -5
  71. package/vendor/helm-crypto/index.js +0 -17
  72. package/vendor/helm-crypto/index.js.map +0 -1
  73. package/vendor/helm-crypto/logger.d.ts +0 -6
  74. package/vendor/helm-crypto/logger.js +0 -11
  75. package/vendor/helm-crypto/logger.js.map +0 -1
  76. package/vendor/helm-crypto/reed_solomon.d.ts +0 -37
  77. package/vendor/helm-crypto/reed_solomon.js +0 -210
  78. package/vendor/helm-crypto/reed_solomon.js.map +0 -1
@@ -1,167 +0,0 @@
1
- "use strict";
2
- // sdk/src/golay.ts
3
- // 🔱 Golay(24,12) Extended Binary Golay Code (RE-SURGERY)
4
- // Corrects up to 3 bit errors, detects 4 bit errors.
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.golayEncode = golayEncode;
7
- exports.golayDecode = golayDecode;
8
- // Standard Golay Parity Matrix P (12x12) - Systematic Form [I12 | P]
9
- // Every row has weight 7.
10
- // Verified: P*P^T = I (mod 2), all rows weight 7.
11
- // Derived from g(x) = x^11+x^10+x^6+x^5+x^4+x^2+1 with parity extension.
12
- const P = [
13
- 0xC75, 0x49F, 0xD4B, 0x6E3, 0x9B3, 0xB66,
14
- 0xECC, 0x1ED, 0x3DA, 0x7B4, 0xB1D, 0xE3A
15
- ];
16
- // R7-P0-1: P^T (transpose of P) — required for second syndrome computation.
17
- // P is NOT symmetric, so s2 = s*P^T must use this separate matrix.
18
- // Without this, decodeWord fails ~24% of weight-2 and ~50% of weight-3 error patterns.
19
- const PT = [
20
- 0xAE3, 0xF25, 0x16F, 0x2DE, 0x5BC, 0xB78,
21
- 0x9D5, 0xC8F, 0x63B, 0xC76, 0x7C9, 0xF92
22
- ];
23
- const UNIT_VECTORS = [
24
- 0x800, 0x400, 0x200, 0x100, 0x080, 0x040,
25
- 0x020, 0x010, 0x008, 0x004, 0x002, 0x001
26
- ];
27
- /**
28
- * Calculates weight (number of set bits).
29
- */
30
- function weight(n) {
31
- let count = 0;
32
- let temp = n & 0xFFF;
33
- while (temp > 0) {
34
- temp &= (temp - 1);
35
- count++;
36
- }
37
- return count;
38
- }
39
- /**
40
- * Multiplies a 12-bit vector by the parity matrix P.
41
- */
42
- function multiplyP(v) {
43
- let res = 0;
44
- for (let i = 0; i < 12; i++) {
45
- if ((v >> (11 - i)) & 1) {
46
- res ^= P[i];
47
- }
48
- }
49
- return res & 0xFFF;
50
- }
51
- /**
52
- * R7-P0-1: Multiplies a 12-bit vector by P^T (transpose of P).
53
- * Required for second syndrome computation in decodeWord steps 3-5.
54
- */
55
- function multiplyPT(v) {
56
- let res = 0;
57
- for (let i = 0; i < 12; i++) {
58
- if ((v >> (11 - i)) & 1) {
59
- res ^= PT[i];
60
- }
61
- }
62
- return res & 0xFFF;
63
- }
64
- function encodeWord(msg) {
65
- const parity = multiplyP(msg & 0xFFF);
66
- return ((msg & 0xFFF) << 12) | parity;
67
- }
68
- /**
69
- * Full Syndrome Decoding for Golay(24,12)
70
- */
71
- function decodeWord(received) {
72
- let r_m = (received >> 12) & 0xFFF;
73
- const r_p = received & 0xFFF;
74
- // Syndrome s = r_m * P + r_p
75
- const s = multiplyP(r_m) ^ r_p;
76
- if (s === 0)
77
- return { msg: r_m, corrected: 0, uncorrectable: false };
78
- // 1. wt(s) <= 3 -> Error in parity
79
- if (weight(s) <= 3) {
80
- return { msg: r_m, corrected: weight(s), uncorrectable: false };
81
- }
82
- // 2. wt(s + P_i) <= 2 -> Error in msg bit i (+ possible 1-2 errors in parity)
83
- for (let i = 0; i < 12; i++) {
84
- if (weight(s ^ P[i]) <= 2) {
85
- return { msg: r_m ^ UNIT_VECTORS[i], corrected: weight(s ^ P[i]) + 1, uncorrectable: false };
86
- }
87
- }
88
- // 3. R7-P0-1: Second syndrome s2 = s * P^T (NOT s * P — P is not symmetric!)
89
- const s2 = multiplyPT(s);
90
- // 4. wt(s2) <= 3 -> Error in message
91
- if (weight(s2) <= 3) {
92
- return { msg: r_m ^ s2, corrected: weight(s2), uncorrectable: false };
93
- }
94
- // 5. wt(s2 + PT_i) <= 2 -> Error in parity bit i + message errors
95
- // R7-P0-1: Must use PT rows (columns of P), not P rows
96
- for (let i = 0; i < 12; i++) {
97
- if (weight(s2 ^ PT[i]) <= 2) {
98
- const error_m = s2 ^ PT[i];
99
- return { msg: r_m ^ error_m, corrected: weight(s2 ^ PT[i]) + 1, uncorrectable: false };
100
- }
101
- }
102
- return { msg: r_m, corrected: 0, uncorrectable: true };
103
- }
104
- function golayEncode(data) {
105
- // B1-6: Correct output size calculation to avoid buffer overflow
106
- const out = new Uint8Array(Math.ceil(data.length / 3) * 6);
107
- let outIdx = 0;
108
- // Process in 3-byte blocks -> two 12-bit words -> two 24-bit (3-byte) codewords
109
- for (let i = 0; i < data.length; i += 3) {
110
- const b1 = data[i];
111
- const b2 = i + 1 < data.length ? data[i + 1] : 0;
112
- const b3 = i + 2 < data.length ? data[i + 2] : 0;
113
- // Word 1 (12 bits)
114
- const w1 = (b1 << 4) | (b2 >> 4);
115
- const c1 = encodeWord(w1);
116
- out[outIdx++] = (c1 >> 16) & 0xFF;
117
- out[outIdx++] = (c1 >> 8) & 0xFF;
118
- out[outIdx++] = c1 & 0xFF;
119
- if (i + 1 < data.length) {
120
- // Word 2 (12 bits)
121
- const w2 = ((b2 & 0x0F) << 8) | b3;
122
- const c2 = encodeWord(w2);
123
- out[outIdx++] = (c2 >> 16) & 0xFF;
124
- out[outIdx++] = (c2 >> 8) & 0xFF;
125
- out[outIdx++] = c2 & 0xFF;
126
- }
127
- }
128
- return out;
129
- }
130
- function golayDecode(encoded) {
131
- // B1-6: Throws if length is not a multiple of 6
132
- if (encoded.length % 6 !== 0) {
133
- throw new Error("Invalid Golay encoded data: length must be multiple of 6");
134
- }
135
- const outLen = Math.floor(encoded.length / 2);
136
- const out = new Uint8Array(outLen);
137
- let outIdx = 0;
138
- let totalCorrected = 0;
139
- let anyUncorrectable = false;
140
- for (let i = 0; i < encoded.length; i += 6) {
141
- const c1 = (encoded[i] << 16) | (encoded[i + 1] << 8) | encoded[i + 2];
142
- const res1 = decodeWord(c1);
143
- totalCorrected += res1.corrected;
144
- if (res1.uncorrectable)
145
- anyUncorrectable = true;
146
- if (outIdx < outLen)
147
- out[outIdx++] = (res1.msg >> 4) & 0xFF;
148
- const b2_high = (res1.msg & 0x0F) << 4;
149
- if (i + 3 < encoded.length) {
150
- const c2 = (encoded[i + 3] << 16) | (encoded[i + 4] << 8) | encoded[i + 5];
151
- const res2 = decodeWord(c2);
152
- totalCorrected += res2.corrected;
153
- if (res2.uncorrectable)
154
- anyUncorrectable = true;
155
- if (outIdx < outLen)
156
- out[outIdx++] = b2_high | (res2.msg >> 8);
157
- if (outIdx < outLen)
158
- out[outIdx++] = res2.msg & 0xFF;
159
- }
160
- else {
161
- if (outIdx < outLen)
162
- out[outIdx++] = b2_high;
163
- }
164
- }
165
- return { data: out, corrected: totalCorrected, uncorrectable: anyUncorrectable };
166
- }
167
- //# sourceMappingURL=golay.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"golay.js","sourceRoot":"","sources":["../src/golay.ts"],"names":[],"mappings":";AAAA,mBAAmB;AACnB,0DAA0D;AAC1D,qDAAqD;;AAiHrD,kCA4BC;AAED,kCAkCC;AA/KD,qEAAqE;AACrE,0BAA0B;AAC1B,kDAAkD;AAClD,yEAAyE;AACzE,MAAM,CAAC,GAAG;IACN,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACxC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;CAC3C,CAAC;AAEF,4EAA4E;AAC5E,mEAAmE;AACnE,uFAAuF;AACvF,MAAM,EAAE,GAAG;IACP,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACxC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;CAC3C,CAAC;AAEF,MAAM,YAAY,GAAG;IACjB,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IACxC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;CAC3C,CAAC;AAEF;;GAEG;AACH,SAAS,MAAM,CAAC,CAAS;IACrB,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC;IACrB,OAAO,IAAI,GAAG,CAAC,EAAE,CAAC;QACd,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QACnB,KAAK,EAAE,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AC/D,IAAI,MAAM,GAAG,MAAM;gBAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QACzD,CAAC;aAAM,CAAC;YACJ,IAAI,MAAM,GAAG,MAAM;gBAAE,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC;QACjD,CAAC;IACL,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC;AACrF,CAAC"}
@@ -1,22 +0,0 @@
1
- export declare class GrgForward {
2
- /**
3
- * Golomb-Rice encoding.
4
- *
5
- * Golomb-Rice is optimal for small-value biased distributions (e.g., timestamp deltas).
6
- * For uniformly distributed data (random bytes), expect ~50% expansion.
7
- * The primary purpose in the GRG pipeline is structured encoding for error correction,
8
- * not compression.
9
- *
10
- * @param data Raw bytes to encode.
11
- * @param m Golomb divisor (must be a power of 2, default 16).
12
- */
13
- static golombEncode(data: Uint8Array, m?: number): Uint8Array;
14
- static redstuffEncode(data: Uint8Array, shards?: number, parity?: number): Uint8Array[];
15
- /**
16
- * Derives an HMAC key from GRG payload context (chainId + poolAddress).
17
- * Both parameters are required — no default key fallback.
18
- */
19
- static deriveHmacKey(chainId: number, poolAddress: string): Buffer;
20
- static golayEncodeWrapper(data: Uint8Array, hmacKey: Buffer): Uint8Array;
21
- static encode(data: Uint8Array, chainId: number, poolAddress: string): Uint8Array[];
22
- }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GrgForward = void 0;
4
- const crypto_1 = require("crypto");
5
- const ethers_1 = require("ethers");
6
- const golay_1 = require("./golay");
7
- const reed_solomon_1 = require("./reed_solomon");
8
- class GrgForward {
9
- /**
10
- * Golomb-Rice encoding.
11
- *
12
- * Golomb-Rice is optimal for small-value biased distributions (e.g., timestamp deltas).
13
- * For uniformly distributed data (random bytes), expect ~50% expansion.
14
- * The primary purpose in the GRG pipeline is structured encoding for error correction,
15
- * not compression.
16
- *
17
- * @param data Raw bytes to encode.
18
- * @param m Golomb divisor (must be a power of 2, default 16).
19
- */
20
- static golombEncode(data, m = 16) {
21
- if (m < 2)
22
- throw new Error("[GRG] Golomb parameter m must be >= 2");
23
- const k = Math.log2(m);
24
- if (!Number.isInteger(k))
25
- throw new Error("M must be power of 2");
26
- const bits = [];
27
- for (const byte of data) {
28
- const q = Math.floor(byte / m);
29
- const r = byte % m;
30
- for (let i = 0; i < q; i++)
31
- bits.push(1);
32
- bits.push(0);
33
- for (let i = k - 1; i >= 0; i--)
34
- bits.push((r >> i) & 1);
35
- }
36
- const out = new Uint8Array(Math.ceil(bits.length / 8));
37
- for (let i = 0; i < bits.length; i++) {
38
- if (bits[i])
39
- out[i >> 3] |= (0x80 >> (i & 7));
40
- }
41
- return out;
42
- }
43
- // 2. RedStuff Erasure Coding (Reed-Solomon GF(2^8))
44
- static redstuffEncode(data, shards = 4, parity = 2) {
45
- return reed_solomon_1.ReedSolomon.encode(data, shards, parity);
46
- }
47
- /**
48
- * Derives an HMAC key from GRG payload context (chainId + poolAddress).
49
- * Both parameters are required — no default key fallback.
50
- */
51
- static deriveHmacKey(chainId, poolAddress) {
52
- if (chainId === undefined || chainId === null || !poolAddress) {
53
- throw new Error("[GRG] chainId and poolAddress are required for HMAC key derivation. No default key is allowed.");
54
- }
55
- const packed = (0, ethers_1.keccak256)(ethers_1.AbiCoder.defaultAbiCoder().encode(["uint256", "address"], [chainId, poolAddress]));
56
- return Buffer.from(packed.slice(2), "hex"); // 32 bytes
57
- }
58
- // 3. Golay(24,12) Error Correction Encoding
59
- static golayEncodeWrapper(data, hmacKey) {
60
- const encoded = (0, golay_1.golayEncode)(data);
61
- // 🔱 Integrity: Append 8-byte HMAC-SHA256 of the encoded shard (keyed hash)
62
- const key = hmacKey;
63
- const mac = (0, crypto_1.createHmac)("sha256", key).update(Buffer.from(encoded)).digest();
64
- const checksum = mac.subarray(0, 8);
65
- const final = new Uint8Array(encoded.length + 8);
66
- final.set(encoded);
67
- final.set(checksum, encoded.length);
68
- return final;
69
- }
70
- static encode(data, chainId, poolAddress) {
71
- // R3-P0-3: Reject empty input — roundtrip breaks ([] → [0])
72
- if (data.length === 0) {
73
- throw new Error("[GRG] Cannot encode empty input — roundtrip identity violation");
74
- }
75
- const compressed = this.golombEncode(data);
76
- // Prepend original length (4 bytes, big-endian) for exact roundtrip
77
- const withLen = new Uint8Array(4 + compressed.length);
78
- withLen[0] = (data.length >> 24) & 0xFF;
79
- withLen[1] = (data.length >> 16) & 0xFF;
80
- withLen[2] = (data.length >> 8) & 0xFF;
81
- withLen[3] = data.length & 0xFF;
82
- withLen.set(compressed, 4);
83
- const shards = this.redstuffEncode(withLen);
84
- const hmacKey = this.deriveHmacKey(chainId, poolAddress);
85
- return shards.map(s => this.golayEncodeWrapper(s, hmacKey));
86
- }
87
- }
88
- exports.GrgForward = GrgForward;
89
- //# sourceMappingURL=grg_forward.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grg_forward.js","sourceRoot":"","sources":["../src/grg_forward.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAChD,mCAA6C;AAC7C,mCAAsC;AACtC,iDAA6C;AAE7C,MAAa,UAAU;IAErB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,YAAY,CAAC,IAAgB,EAAE,IAAY,EAAE;QAClD,IAAI,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QACpE,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAElE,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,CAAC,GAA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,CAAC;QAC3C,oEAAoE;QACpE,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACxC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACxC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;QACvC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACzD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AArFD,gCAqFC"}
@@ -1,16 +0,0 @@
1
- export declare class GrgInverse {
2
- static golayDecodeWrapper(data: Uint8Array, hmacKey: Buffer): Uint8Array;
3
- static redstuffDecode(shards: (Uint8Array | null)[], dataShardCount?: number, parityShardCount?: number): Uint8Array;
4
- private static readonly MAX_GOLOMB_Q;
5
- /**
6
- * Decode a Golomb-Rice compressed byte stream.
7
- *
8
- * @param data - Golomb-encoded bit-packed bytes
9
- * @param m - Golomb divisor (must be power of 2, default 16)
10
- * @param originalLength - If provided, stop decoding once this many values
11
- * have been emitted. This prevents phantom trailing bytes caused by
12
- * zero-padding in the last byte of the encoded stream.
13
- */
14
- static golombDecode(data: Uint8Array, m?: number, originalLength?: number): Uint8Array;
15
- static verify(data: Uint8Array, originalShards: Uint8Array[], chainId: number, poolAddress: string): boolean;
16
- }
@@ -1,118 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GrgInverse = void 0;
4
- const crypto_1 = require("crypto");
5
- const golay_1 = require("./golay");
6
- const grg_forward_1 = require("./grg_forward");
7
- const logger_1 = require("./logger");
8
- const reed_solomon_1 = require("./reed_solomon");
9
- class GrgInverse {
10
- // 1. Golay Decoding & Integrity Check
11
- static golayDecodeWrapper(data, hmacKey) {
12
- if (data.length < 8)
13
- throw new Error("GRG shard too short for checksum");
14
- // Split data and checksum (last 8 bytes)
15
- const encoded = data.subarray(0, data.length - 8);
16
- const checksum = data.subarray(data.length - 8);
17
- // Verify HMAC-SHA256 Checksum (keyed hash, B1-5: 8 bytes truncated)
18
- const key = hmacKey;
19
- const mac = (0, crypto_1.createHmac)("sha256", key).update(Buffer.from(encoded)).digest();
20
- const expected = mac.subarray(0, 8);
21
- if (!Buffer.from(checksum).equals(Buffer.from(expected))) {
22
- throw new Error("GRG tamper detected: HMAC-SHA256 checksum mismatch");
23
- }
24
- // Proceed to Golay decode
25
- const res = (0, golay_1.golayDecode)(encoded);
26
- if (res.uncorrectable) {
27
- throw new Error("GRG tamper detected: uncorrectable bit errors in Golay codeword");
28
- }
29
- return res.data;
30
- }
31
- // 2. RedStuff Decoding (Reed-Solomon GF(2^8))
32
- static redstuffDecode(shards, dataShardCount = 4, parityShardCount = 2) {
33
- return reed_solomon_1.ReedSolomon.decode(shards, dataShardCount, parityShardCount);
34
- }
35
- /**
36
- * Decode a Golomb-Rice compressed byte stream.
37
- *
38
- * @param data - Golomb-encoded bit-packed bytes
39
- * @param m - Golomb divisor (must be power of 2, default 16)
40
- * @param originalLength - If provided, stop decoding once this many values
41
- * have been emitted. This prevents phantom trailing bytes caused by
42
- * zero-padding in the last byte of the encoded stream.
43
- */
44
- static golombDecode(data, m = 16, originalLength) {
45
- if (m < 2)
46
- throw new Error("[GRG] Golomb parameter m must be >= 2");
47
- const k = Math.log2(m);
48
- const totalBits = data.length * 8;
49
- // Helper to read a single bit from the packed byte array
50
- const readBit = (pos) => {
51
- return (data[pos >> 3] >> (7 - (pos & 7))) & 1;
52
- };
53
- const result = [];
54
- let i = 0;
55
- while (i < totalBits) {
56
- // Guard: stop at expected length to avoid processing padding bits
57
- if (originalLength !== undefined && result.length >= originalLength)
58
- break;
59
- // Read unary part: count 1-bits until a 0-bit
60
- let q = 0;
61
- while (i < totalBits && readBit(i) === 1) {
62
- q++;
63
- i++;
64
- if (q > this.MAX_GOLOMB_Q)
65
- throw new Error(`[GRG] Golomb decode: unary run exceeds ${this.MAX_GOLOMB_Q} — malformed or malicious input`);
66
- }
67
- if (i < totalBits && readBit(i) === 0)
68
- i++; // skip the 0 delimiter
69
- // Read k-bit remainder
70
- if (i + k > totalBits)
71
- break;
72
- let r = 0;
73
- for (let j = 0; j < k; j++) {
74
- r = (r << 1) | readBit(i + j);
75
- }
76
- result.push(q * m + r);
77
- i += k;
78
- }
79
- return new Uint8Array(result);
80
- }
81
- static verify(data, originalShards, chainId, poolAddress) {
82
- try {
83
- const hmacKey = grg_forward_1.GrgForward.deriveHmacKey(chainId, poolAddress);
84
- const decodedShards = originalShards.map(s => {
85
- try {
86
- return this.golayDecodeWrapper(s, hmacKey);
87
- }
88
- catch {
89
- return null;
90
- }
91
- });
92
- const withLen = this.redstuffDecode(decodedShards);
93
- // Extract original length
94
- if (withLen.length < 4)
95
- return false;
96
- const origLen = (withLen[0] << 24) | (withLen[1] << 16) | (withLen[2] << 8) | withLen[3];
97
- const compressed = withLen.subarray(4);
98
- const decoded = this.golombDecode(compressed);
99
- const final = decoded.subarray(0, origLen);
100
- if (final.length !== data.length)
101
- return false;
102
- for (let i = 0; i < data.length; i++) {
103
- if (final[i] !== data[i])
104
- return false;
105
- }
106
- return true;
107
- }
108
- catch (e) {
109
- logger_1.logger.warn(`[GRG Inverse] Verification failed: ${e}`);
110
- return false;
111
- }
112
- }
113
- }
114
- exports.GrgInverse = GrgInverse;
115
- // 3. Golomb-Rice Decompression
116
- // R4-P2-3: Max unary run length to prevent amplification DoS
117
- GrgInverse.MAX_GOLOMB_Q = 1000000;
118
- //# sourceMappingURL=grg_inverse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grg_inverse.js","sourceRoot":"","sources":["../src/grg_inverse.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAChD,mCAAsC;AACtC,+CAA2C;AAC3C,qCAAkC;AAClC,iDAA6C;AAE7C,MAAa,UAAU;IAErB,sCAAsC;IACtC,MAAM,CAAC,kBAAkB,CAAC,IAAgB,EAAE,OAAe;QACzD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAEzE,yCAAyC;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAEhD,oEAAoE;QACpE,MAAM,GAAG,GAAG,OAAO,CAAC;QACpB,MAAM,GAAG,GAAG,IAAA,mBAAU,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC5E,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAEpC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAA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omb-Rice -> RedStuff (Erasure) -> Golay(24,12)
6
- */
7
- static processForward(data: Uint8Array, chainId: number, poolAddress: string): Uint8Array[];
8
- /**
9
- * Runs the full inverse pipeline:
10
- * Golay(24,12) -> RedStuff (Reconstruction) -> Golomb-Rice Decompression
11
- */
12
- static processInverse(shards: Uint8Array[], originalLength: number, chainId: number, poolAddress: string): Uint8Array;
13
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GrgPipeline = void 0;
4
- const grg_forward_1 = require("./grg_forward");
5
- const grg_inverse_1 = require("./grg_inverse");
6
- const logger_1 = require("./logger");
7
- class GrgPipeline {
8
- /**
9
- * Runs the full forward pipeline:
10
- * Golomb-Rice -> RedStuff (Erasure) -> Golay(24,12)
11
- */
12
- static processForward(data, chainId, poolAddress) {
13
- if (data.length > this.MAX_INPUT_SIZE) {
14
- throw new Error(`[GRG] Input size ${data.length} exceeds MAX_INPUT_SIZE ${this.MAX_INPUT_SIZE}`);
15
- }
16
- logger_1.logger.info("Starting GRG forward pipeline...");
17
- try {
18
- const shards = grg_forward_1.GrgForward.encode(data, chainId, poolAddress);
19
- logger_1.logger.info(`GRG forward pipeline complete. Generated ${shards.length} shards.`);
20
- return shards;
21
- }
22
- catch (error) {
23
- logger_1.logger.error(`GRG forward pipeline failed: ${error}`);
24
- throw error;
25
- }
26
- }
27
- /**
28
- * Runs the full inverse pipeline:
29
- * Golay(24,12) -> RedStuff (Reconstruction) -> Golomb-Rice Decompression
30
- */
31
- static processInverse(shards, originalLength, chainId, poolAddress) {
32
- logger_1.logger.info("Starting GRG inverse pipeline...");
33
- try {
34
- const hmacKey = grg_forward_1.GrgForward.deriveHmacKey(chainId, poolAddress);
35
- const decodedShards = shards.map(s => {
36
- try {
37
- return grg_inverse_1.GrgInverse.golayDecodeWrapper(s, hmacKey);
38
- }
39
- catch (e) {
40
- logger_1.logger.warn(`Golay decode failed for a shard: ${e}`);
41
- return null;
42
- }
43
- });
44
- const withLen = grg_inverse_1.GrgInverse.redstuffDecode(decodedShards);
45
- // Extract original length from the first 4 bytes
46
- const decodedLength = (withLen[0] << 24) | (withLen[1] << 16) | (withLen[2] << 8) | withLen[3];
47
- const compressed = withLen.subarray(4);
48
- const decompressed = grg_inverse_1.GrgInverse.golombDecode(compressed);
49
- const final = decompressed.subarray(0, decodedLength);
50
- // P1-4 FIX: Length mismatch is a corruption signal — throw instead of warn
51
- if (final.length !== originalLength) {
52
- throw new Error(`[GRG] Length mismatch in inverse: expected ${originalLength}, got ${final.length}`);
53
- }
54
- logger_1.logger.info("GRG inverse pipeline complete.");
55
- return final;
56
- }
57
- catch (error) {
58
- logger_1.logger.error(`GRG inverse pipeline failed: ${error}`);
59
- throw error;
60
- }
61
- }
62
- }
63
- exports.GrgPipeline = GrgPipeline;
64
- // P1-3: Max input size to prevent OOM attacks (100 MB)
65
- GrgPipeline.MAX_INPUT_SIZE = 100 * 1024 * 1024;
66
- //# sourceMappingURL=grg_pipeline.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"grg_pipeline.js","sourceRoot":"","sources":["../src/grg_pipeline.ts"],"names":[],"mappings":";;;AAAA,+CAA2C;AAC3C,+CAA2C;AAC3C,qCAAkC;AAElC,MAAa,WAAW;IAItB;;;OAGG;IACH,MAAM,CAAC,cAAc,CAAC,IAAgB,EAAE,OAAe,EAAE,WAAmB;QAC1E,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CAAC,oBAAoB,IAAI,CAAC,MAAM,2BAA2B,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;QACnG,CAAC;QACD,eAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;QAChD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,wBAAU,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;YAC7D,eAAM,CAAC,IAAI,CAAC,4CA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G,YAAY,CAAC,QAAQ,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC;YAEtD,2EAA2E;YAC3E,IAAI,KAAK,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CAAC,8CAA8C,cAAc,SAAS,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YACvG,CAAC;YAED,eAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;YAC9C,OAAO,KAAK,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,eAAM,CAAC,KAAK,CAAC,gCAAgC,KAAK,EAAE,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;;AA3DH,kCA4DC;AA3DC,uDAAuD;AACvC,0BAAc,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC"}
@@ -1,5 +0,0 @@
1
- export { golayEncode, golayDecode } from "./golay";
2
- export { ReedSolomon } from "./reed_solomon";
3
- export { GrgForward } from "./grg_forward";
4
- export { GrgInverse } from "./grg_inverse";
5
- export { GrgPipeline } from "./grg_pipeline";
@@ -1,17 +0,0 @@
1
- "use strict";
2
- // @helm-protocol/helm-crypto — GRG Cryptographic Pipeline (PRIVATE)
3
- // Golomb-Rice -> Reed-Solomon -> Golay(24,12)
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.GrgPipeline = exports.GrgInverse = exports.GrgForward = exports.ReedSolomon = exports.golayDecode = exports.golayEncode = void 0;
6
- var golay_1 = require("./golay");
7
- Object.defineProperty(exports, "golayEncode", { enumerable: true, get: function () { return golay_1.golayEncode; } });
8
- Object.defineProperty(exports, "golayDecode", { enumerable: true, get: function () { return golay_1.golayDecode; } });
9
- var reed_solomon_1 = require("./reed_solomon");
10
- Object.defineProperty(exports, "ReedSolomon", { enumerable: true, get: function () { return reed_solomon_1.ReedSolomon; } });
11
- var grg_forward_1 = require("./grg_forward");
12
- Object.defineProperty(exports, "GrgForward", { enumerable: true, get: function () { return grg_forward_1.GrgForward; } });
13
- var grg_inverse_1 = require("./grg_inverse");
14
- Object.defineProperty(exports, "GrgInverse", { enumerable: true, get: function () { return grg_inverse_1.GrgInverse; } });
15
- var grg_pipeline_1 = require("./grg_pipeline");
16
- Object.defineProperty(exports, "GrgPipeline", { enumerable: true, get: function () { return grg_pipeline_1.GrgPipeline; } });
17
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,oEAAoE;AACpE,8CAA8C;;;AAE9C,iCAAmD;AAA1C,oGAAA,WAAW,OAAA;AAAE,oGAAA,WAAW,OAAA;AACjC,+CAA6C;AAApC,2GAAA,WAAW,OAAA;AACpB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
@@ -1,6 +0,0 @@
1
- export declare const logger: {
2
- info: (msg: string) => void;
3
- warn: (msg: string) => void;
4
- error: (msg: string) => void;
5
- debug: (msg: string) => void;
6
- };
@@ -1,11 +0,0 @@
1
- "use strict";
2
- // Minimal logger for helm-crypto (standalone, no external dependency)
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.logger = void 0;
5
- exports.logger = {
6
- info: (msg) => console.log(`[helm-crypto] ${msg}`),
7
- warn: (msg) => console.warn(`[helm-crypto] ${msg}`),
8
- error: (msg) => console.error(`[helm-crypto] ${msg}`),
9
- debug: (msg) => console.debug(`[helm-crypto] ${msg}`),
10
- };
11
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,sEAAsE;;;AAEzD,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,GAAG,EAAE,CAAC;IAC1D,IAAI,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;IAC3D,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,EAAE,CAAC;IAC7D,KAAK,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,EAAE,CAAC;CAC9D,CAAC"}
@@ -1,37 +0,0 @@
1
- export declare class ReedSolomon {
2
- private static expTable;
3
- private static logTable;
4
- private static initialized;
5
- /**
6
- * Static Vandermonde matrix cache keyed by "${totalShards}-${dataShards}".
7
- * Avoids recomputing the GF(2^8) Vandermonde + inverse on every tick,
8
- * which is the most expensive part of RS encoding/decoding.
9
- */
10
- private static vandermondeCache;
11
- static init(): void;
12
- static mul(a: number, b: number): number;
13
- static div(a: number, b: number): number;
14
- private static invertMatrix;
15
- /**
16
- * Build (or retrieve from cache) the normalized Vandermonde encoding matrix.
17
- * Cache key: "${rows}-${cols}" — RS parameters rarely change within a session,
18
- * so caching eliminates redundant GF(2^8) matrix inversion on every tick.
19
- */
20
- private static buildVandermonde;
21
- static encode(data: Uint8Array, dataShards?: number, parityShards?: number): Uint8Array[];
22
- /**
23
- * Decode data from a set of Reed-Solomon shards (data + parity).
24
- *
25
- * Shards should be provided in order of reliability: place higher-quality,
26
- * more trustworthy shards first. The decoder selects the first `dataShards`
27
- * non-null entries for recovery, so ordering by reliability ensures the
28
- * most dependable shards are preferred. The implementation already handles
29
- * missing (null) shards transparently via GF(2^8) matrix inversion.
30
- *
31
- * @param shards - Array of shard buffers (null for missing/corrupted shards)
32
- * @param dataShards - Number of data shards (default 4)
33
- * @param parityShards - Number of parity shards (default 2)
34
- * @returns Reconstructed data as a single Uint8Array
35
- */
36
- static decode(shards: (Uint8Array | null)[], dataShards?: number, parityShards?: number): Uint8Array;
37
- }