@mindpeeker/negentropy 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.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +160 -0
  3. package/dist/errors.d.ts +12 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/errors.js +11 -0
  6. package/dist/errors.js.map +1 -0
  7. package/dist/estimators/entropy.d.ts +22 -0
  8. package/dist/estimators/entropy.d.ts.map +1 -0
  9. package/dist/estimators/entropy.js +78 -0
  10. package/dist/estimators/entropy.js.map +1 -0
  11. package/dist/estimators/frequency.d.ts +18 -0
  12. package/dist/estimators/frequency.d.ts.map +1 -0
  13. package/dist/estimators/frequency.js +57 -0
  14. package/dist/estimators/frequency.js.map +1 -0
  15. package/dist/estimators/negentropy.d.ts +62 -0
  16. package/dist/estimators/negentropy.d.ts.map +1 -0
  17. package/dist/estimators/negentropy.js +104 -0
  18. package/dist/estimators/negentropy.js.map +1 -0
  19. package/dist/estimators/pipeline.d.ts +25 -0
  20. package/dist/estimators/pipeline.d.ts.map +1 -0
  21. package/dist/estimators/pipeline.js +30 -0
  22. package/dist/estimators/pipeline.js.map +1 -0
  23. package/dist/estimators/vasicek.d.ts +18 -0
  24. package/dist/estimators/vasicek.d.ts.map +1 -0
  25. package/dist/estimators/vasicek.js +57 -0
  26. package/dist/estimators/vasicek.js.map +1 -0
  27. package/dist/estimators/windowed.d.ts +27 -0
  28. package/dist/estimators/windowed.d.ts.map +1 -0
  29. package/dist/estimators/windowed.js +66 -0
  30. package/dist/estimators/windowed.js.map +1 -0
  31. package/dist/experiment/batch.d.ts +15 -0
  32. package/dist/experiment/batch.d.ts.map +1 -0
  33. package/dist/experiment/batch.js +179 -0
  34. package/dist/experiment/batch.js.map +1 -0
  35. package/dist/experiment/composite.d.ts +12 -0
  36. package/dist/experiment/composite.d.ts.map +1 -0
  37. package/dist/experiment/composite.js +26 -0
  38. package/dist/experiment/composite.js.map +1 -0
  39. package/dist/experiment/registration.d.ts +20 -0
  40. package/dist/experiment/registration.d.ts.map +1 -0
  41. package/dist/experiment/registration.js +54 -0
  42. package/dist/experiment/registration.js.map +1 -0
  43. package/dist/experiment/session.d.ts +47 -0
  44. package/dist/experiment/session.d.ts.map +1 -0
  45. package/dist/experiment/session.js +245 -0
  46. package/dist/experiment/session.js.map +1 -0
  47. package/dist/experiment/types.d.ts +68 -0
  48. package/dist/experiment/types.d.ts.map +1 -0
  49. package/dist/experiment/types.js +2 -0
  50. package/dist/experiment/types.js.map +1 -0
  51. package/dist/extract/accounting.d.ts +52 -0
  52. package/dist/extract/accounting.d.ts.map +1 -0
  53. package/dist/extract/accounting.js +130 -0
  54. package/dist/extract/accounting.js.map +1 -0
  55. package/dist/extract/condition.d.ts +23 -0
  56. package/dist/extract/condition.d.ts.map +1 -0
  57. package/dist/extract/condition.js +50 -0
  58. package/dist/extract/condition.js.map +1 -0
  59. package/dist/extract/debias.d.ts +25 -0
  60. package/dist/extract/debias.d.ts.map +1 -0
  61. package/dist/extract/debias.js +80 -0
  62. package/dist/extract/debias.js.map +1 -0
  63. package/dist/extract/health.d.ts +44 -0
  64. package/dist/extract/health.d.ts.map +1 -0
  65. package/dist/extract/health.js +115 -0
  66. package/dist/extract/health.js.map +1 -0
  67. package/dist/extract/toeplitz.d.ts +19 -0
  68. package/dist/extract/toeplitz.d.ts.map +1 -0
  69. package/dist/extract/toeplitz.js +83 -0
  70. package/dist/extract/toeplitz.js.map +1 -0
  71. package/dist/index.d.ts +39 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +23 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/internal/bytes.d.ts +6 -0
  76. package/dist/internal/bytes.d.ts.map +1 -0
  77. package/dist/internal/bytes.js +36 -0
  78. package/dist/internal/bytes.js.map +1 -0
  79. package/dist/internal/kahan.d.ts +7 -0
  80. package/dist/internal/kahan.d.ts.map +1 -0
  81. package/dist/internal/kahan.js +15 -0
  82. package/dist/internal/kahan.js.map +1 -0
  83. package/dist/internal/prng.d.ts +7 -0
  84. package/dist/internal/prng.d.ts.map +1 -0
  85. package/dist/internal/prng.js +16 -0
  86. package/dist/internal/prng.js.map +1 -0
  87. package/dist/internal/special.d.ts +36 -0
  88. package/dist/internal/special.d.ts.map +1 -0
  89. package/dist/internal/special.js +258 -0
  90. package/dist/internal/special.js.map +1 -0
  91. package/dist/internal/welford.d.ts +13 -0
  92. package/dist/internal/welford.d.ts.map +1 -0
  93. package/dist/internal/welford.js +30 -0
  94. package/dist/internal/welford.js.map +1 -0
  95. package/dist/numerics.d.ts +32 -0
  96. package/dist/numerics.d.ts.map +1 -0
  97. package/dist/numerics.js +32 -0
  98. package/dist/numerics.js.map +1 -0
  99. package/dist/stats/calibration.d.ts +14 -0
  100. package/dist/stats/calibration.d.ts.map +1 -0
  101. package/dist/stats/calibration.js +41 -0
  102. package/dist/stats/calibration.js.map +1 -0
  103. package/dist/stats/cumdev.d.ts +15 -0
  104. package/dist/stats/cumdev.d.ts.map +1 -0
  105. package/dist/stats/cumdev.js +38 -0
  106. package/dist/stats/cumdev.js.map +1 -0
  107. package/dist/stats/network.d.ts +29 -0
  108. package/dist/stats/network.d.ts.map +1 -0
  109. package/dist/stats/network.js +119 -0
  110. package/dist/stats/network.js.map +1 -0
  111. package/dist/stats/pvalues.d.ts +11 -0
  112. package/dist/stats/pvalues.d.ts.map +1 -0
  113. package/dist/stats/pvalues.js +18 -0
  114. package/dist/stats/pvalues.js.map +1 -0
  115. package/dist/stats/trials.d.ts +34 -0
  116. package/dist/stats/trials.d.ts.map +1 -0
  117. package/dist/stats/trials.js +149 -0
  118. package/dist/stats/trials.js.map +1 -0
  119. package/dist/stats/zscores.d.ts +10 -0
  120. package/dist/stats/zscores.d.ts.map +1 -0
  121. package/dist/stats/zscores.js +26 -0
  122. package/dist/stats/zscores.js.map +1 -0
  123. package/dist/types.d.ts +61 -0
  124. package/dist/types.d.ts.map +1 -0
  125. package/dist/types.js +2 -0
  126. package/dist/types.js.map +1 -0
  127. package/package.json +46 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Von Neumann debiasing: consume bit pairs, 01→0, 10→1, 00/11 discarded.
3
+ * Output is exactly unbiased WHEN INPUT BITS ARE IID — correlated input
4
+ * yields biased output. Yield is pq ≤ 25%; a trailing unpaired bit is dropped.
5
+ */
6
+ export declare function vonNeumann(bits: ArrayLike<number>): number[];
7
+ /**
8
+ * Peres iterated von Neumann (Peres 1992, Ann. Statist. 20(1)): recursively
9
+ * recycles what von Neumann throws away — the pair-XOR sequence U and the
10
+ * equal-pair values V — as Peres(x) = VN(x) ++ Peres(U) ++ Peres(V) (that
11
+ * concatenation order is this implementation's frozen convention). Extraction
12
+ * rate approaches the full Shannon entropy H(p) as depth grows, vs von
13
+ * Neumann's pq ceiling. Same iid-input requirement as von Neumann.
14
+ */
15
+ export declare function peres(bits: ArrayLike<number>, maxDepth?: number): number[];
16
+ /**
17
+ * Expected Peres output rate (bits out per bit in) at recursion depth d for
18
+ * iid input bias p, via the exact recurrence
19
+ * R₍d₊₁₎(p) = pq + ½·R_d(2pq) + ((p²+q²)/2)·R_d(p²/(p²+q²)), R₀ = 0.
20
+ * R₁ = pq is von Neumann; R_d → H(p) as d → ∞. Exact values at p = ½:
21
+ * ¼, 7/16, 37/64, … Cost is O(2^depth) — the recursion branches on distinct
22
+ * biases — hence the depth ≤ 25 cap.
23
+ */
24
+ export declare function peresRate(p: number, depth: number): number;
25
+ //# sourceMappingURL=debias.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debias.d.ts","sourceRoot":"","sources":["../../src/extract/debias.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAQ5D;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,SAA2B,GAAG,MAAM,EAAE,CAY5F;AAkBD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAW1D"}
@@ -0,0 +1,80 @@
1
+ import { NegentropyError } from '../errors.js';
2
+ /**
3
+ * Von Neumann debiasing: consume bit pairs, 01→0, 10→1, 00/11 discarded.
4
+ * Output is exactly unbiased WHEN INPUT BITS ARE IID — correlated input
5
+ * yields biased output. Yield is pq ≤ 25%; a trailing unpaired bit is dropped.
6
+ */
7
+ export function vonNeumann(bits) {
8
+ const out = [];
9
+ for (let i = 0; i + 1 < bits.length; i += 2) {
10
+ const a = bits[i] & 1;
11
+ const b = bits[i + 1] & 1;
12
+ if (a !== b)
13
+ out.push(a);
14
+ }
15
+ return out;
16
+ }
17
+ /**
18
+ * Peres iterated von Neumann (Peres 1992, Ann. Statist. 20(1)): recursively
19
+ * recycles what von Neumann throws away — the pair-XOR sequence U and the
20
+ * equal-pair values V — as Peres(x) = VN(x) ++ Peres(U) ++ Peres(V) (that
21
+ * concatenation order is this implementation's frozen convention). Extraction
22
+ * rate approaches the full Shannon entropy H(p) as depth grows, vs von
23
+ * Neumann's pq ceiling. Same iid-input requirement as von Neumann.
24
+ */
25
+ export function peres(bits, maxDepth = Number.POSITIVE_INFINITY) {
26
+ if (maxDepth !== Number.POSITIVE_INFINITY && (!Number.isInteger(maxDepth) || maxDepth < 1)) {
27
+ throw new NegentropyError('invalid_config', `maxDepth must be a positive integer, got ${maxDepth}`);
28
+ }
29
+ const input = new Uint8Array(bits.length);
30
+ for (let i = 0; i < bits.length; i++)
31
+ input[i] = bits[i] & 1;
32
+ const out = [];
33
+ peresInto(input, maxDepth, out);
34
+ return out;
35
+ }
36
+ function peresInto(bits, depth, out) {
37
+ if (bits.length < 2 || depth < 1)
38
+ return;
39
+ const pairs = bits.length >> 1;
40
+ const u = new Uint8Array(pairs);
41
+ const v = [];
42
+ for (let i = 0; i < pairs; i++) {
43
+ const a = bits[2 * i];
44
+ const b = bits[2 * i + 1];
45
+ if (a !== b)
46
+ out.push(a);
47
+ u[i] = a ^ b;
48
+ if (a === b)
49
+ v.push(a);
50
+ }
51
+ peresInto(u, depth - 1, out);
52
+ peresInto(Uint8Array.from(v), depth - 1, out);
53
+ }
54
+ /**
55
+ * Expected Peres output rate (bits out per bit in) at recursion depth d for
56
+ * iid input bias p, via the exact recurrence
57
+ * R₍d₊₁₎(p) = pq + ½·R_d(2pq) + ((p²+q²)/2)·R_d(p²/(p²+q²)), R₀ = 0.
58
+ * R₁ = pq is von Neumann; R_d → H(p) as d → ∞. Exact values at p = ½:
59
+ * ¼, 7/16, 37/64, … Cost is O(2^depth) — the recursion branches on distinct
60
+ * biases — hence the depth ≤ 25 cap.
61
+ */
62
+ export function peresRate(p, depth) {
63
+ if (!(p > 0 && p < 1)) {
64
+ throw new NegentropyError('invalid_config', `bias p must be in (0, 1), got ${p}`);
65
+ }
66
+ if (!Number.isInteger(depth) || depth < 0 || depth > 25) {
67
+ throw new NegentropyError('invalid_config', `depth must be an integer in [0, 25] (cost grows as 2^depth), got ${depth}`);
68
+ }
69
+ return rate(p, depth);
70
+ }
71
+ function rate(p, depth) {
72
+ // repeated p²/(p²+q²) mapping drives extreme biases to exactly 0 or 1 in
73
+ // float64 — those branches are deterministic and carry zero extractable entropy
74
+ if (depth === 0 || p <= 0 || p >= 1)
75
+ return 0;
76
+ const q = 1 - p;
77
+ const equal = p * p + q * q;
78
+ return p * q + 0.5 * rate(2 * p * q, depth - 1) + (equal / 2) * rate((p * p) / equal, depth - 1);
79
+ }
80
+ //# sourceMappingURL=debias.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debias.js","sourceRoot":"","sources":["../../src/extract/debias.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,IAAuB;IAChD,MAAM,GAAG,G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AK,EAAE,CAC5E,CAAA;IACH,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAA;AACvB,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,KAAa;IACpC,yEAAyE;IACzE,gFAAgF;IAChF,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IAC7C,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACf,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC3B,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAA;AAClG,CAAC"}
@@ -0,0 +1,44 @@
1
+ /** SP 800-90B §4.4.1 Repetition Count Test cutoff: C = 1 + ⌈20/H⌉ at α = 2⁻²⁰. */
2
+ export declare function rctCutoff(h: number): number;
3
+ /**
4
+ * SP 800-90B §4.4.2 Adaptive Proportion Test cutoff:
5
+ * 1 + smallest k with P(Binomial(W, 2⁻ᴴ) ≤ k) ≥ 1 − 2⁻²⁰. The pmf terms are
6
+ * computed in log space — at low H the lower binomial tail underflows float64
7
+ * (e.g. 0.19⁵¹² ≈ 1e-371), which would silently disable the test.
8
+ */
9
+ export declare function aptCutoff(h: number, windowSize: number): number;
10
+ export interface HealthConfig {
11
+ /** Assessed min-entropy H in bits per raw sample byte. May be fractional. */
12
+ minEntropyPerSample: number;
13
+ /** APT window: 512 (default, non-binary samples) or 1024 (binary sources). */
14
+ windowSize?: 512 | 1024;
15
+ /**
16
+ * strict: throw NegentropyError('health_test') on the first alarm — the
17
+ * randomness-supplier behavior. Default false: record alarms and keep
18
+ * running — the anomaly-logger behavior (an alarm resets that test's
19
+ * counter so one long run is one alarm, not one per sample).
20
+ */
21
+ strict?: boolean;
22
+ }
23
+ export interface HealthAlarm {
24
+ test: 'rct' | 'apt';
25
+ /** Global index of the sample that tripped the test (0-based). */
26
+ sample: number;
27
+ count: number;
28
+ cutoff: number;
29
+ }
30
+ /**
31
+ * SP 800-90B §4.4 continuous health tests (Repetition Count + Adaptive
32
+ * Proportion) over raw samples, in an observational shell.
33
+ */
34
+ export declare class ContinuousHealth {
35
+ #private;
36
+ readonly rctCutoff: number;
37
+ readonly aptCutoff: number;
38
+ constructor(config: HealthConfig, source?: string);
39
+ get alarms(): readonly HealthAlarm[];
40
+ get samplesSeen(): number;
41
+ /** Feed raw samples; returns the alarms THIS call raised ([] = healthy). */
42
+ push(samples: Uint8Array): HealthAlarm[];
43
+ }
44
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/extract/health.ts"],"names":[],"mappings":"AAKA,kFAAkF;AAClF,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAa/D;AAED,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,mBAAmB,EAAE,MAAM,CAAA;IAC3B,8EAA8E;IAC9E,UAAU,CAAC,EAAE,GAAG,GAAG,IAAI,CAAA;IACvB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IACnB,kEAAkE;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,qBAAa,gBAAgB;;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;gBAgBd,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM;IAYjD,IAAI,MAAM,IAAI,SAAS,WAAW,EAAE,CAEnC;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAiBD,4EAA4E;IAC5E,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,WAAW,EAAE;CAqCzC"}
@@ -0,0 +1,115 @@
1
+ import { NegentropyError } from '../errors.js';
2
+ import { lnGamma } from '../internal/special.js';
3
+ const ALPHA = 2 ** -20; // false-positive rate for both tests (SP 800-90B recommendation)
4
+ /** SP 800-90B §4.4.1 Repetition Count Test cutoff: C = 1 + ⌈20/H⌉ at α = 2⁻²⁰. */
5
+ export function rctCutoff(h) {
6
+ return 1 + Math.ceil(20 / h);
7
+ }
8
+ /**
9
+ * SP 800-90B §4.4.2 Adaptive Proportion Test cutoff:
10
+ * 1 + smallest k with P(Binomial(W, 2⁻ᴴ) ≤ k) ≥ 1 − 2⁻²⁰. The pmf terms are
11
+ * computed in log space — at low H the lower binomial tail underflows float64
12
+ * (e.g. 0.19⁵¹² ≈ 1e-371), which would silently disable the test.
13
+ */
14
+ export function aptCutoff(h, windowSize) {
15
+ const p = 2 ** -h;
16
+ const lnP = Math.log(p);
17
+ const lnQ = Math.log1p(-p);
18
+ const lnChooseBase = lnGamma(windowSize + 1);
19
+ let cdf = 0;
20
+ for (let k = 0; k <= windowSize; k++) {
21
+ const logPmf = lnChooseBase - lnGamma(k + 1) - lnGamma(windowSize - k + 1) + k * lnP + (windowSize - k) * lnQ;
22
+ cdf += Math.exp(logPmf);
23
+ if (cdf >= 1 - ALPHA)
24
+ return 1 + k;
25
+ }
26
+ return 1 + windowSize;
27
+ }
28
+ /**
29
+ * SP 800-90B §4.4 continuous health tests (Repetition Count + Adaptive
30
+ * Proportion) over raw samples, in an observational shell.
31
+ */
32
+ export class ContinuousHealth {
33
+ rctCutoff;
34
+ aptCutoff;
35
+ #windowSize;
36
+ #strict;
37
+ #source;
38
+ #alarms = [];
39
+ #samplesSeen = 0;
40
+ // Repetition Count Test state
41
+ #lastSample = -1;
42
+ #runLength = 0;
43
+ // Adaptive Proportion Test state
44
+ #windowIndex = 0;
45
+ #reference = -1;
46
+ #referenceCount = 0;
47
+ constructor(config, source) {
48
+ const { minEntropyPerSample, windowSize = 512, strict = false } = config;
49
+ if (!(minEntropyPerSample > 0)) {
50
+ throw new NegentropyError('invalid_config', 'minEntropyPerSample must be > 0', { source });
51
+ }
52
+ this.rctCutoff = rctCutoff(minEntropyPerSample);
53
+ this.aptCutoff = aptCutoff(minEntropyPerSample, windowSize);
54
+ this.#windowSize = windowSize;
55
+ this.#strict = strict;
56
+ this.#source = source;
57
+ }
58
+ get alarms() {
59
+ return this.#alarms;
60
+ }
61
+ get samplesSeen() {
62
+ return this.#samplesSeen;
63
+ }
64
+ #alarm(test, count, cutoff) {
65
+ const alarm = { test, sample: this.#samplesSeen, count, cutoff };
66
+ this.#alarms.push(alarm);
67
+ if (this.#strict) {
68
+ throw new NegentropyError('health_test', test === 'rct'
69
+ ? `repetition count test failed: ${count} identical samples (cutoff ${cutoff})`
70
+ : `adaptive proportion test failed: value seen ${count}× in a ${this.#windowSize}-sample window (cutoff ${cutoff})`, { source: this.#source });
71
+ }
72
+ return alarm;
73
+ }
74
+ /** Feed raw samples; returns the alarms THIS call raised ([] = healthy). */
75
+ push(samples) {
76
+ const raised = [];
77
+ for (const sample of samples) {
78
+ // Repetition Count Test
79
+ if (sample === this.#lastSample) {
80
+ this.#runLength++;
81
+ if (this.#runLength >= this.rctCutoff) {
82
+ raised.push(this.#alarm('rct', this.#runLength, this.rctCutoff));
83
+ this.#runLength = 1; // observational: restart the run so alarms don't flood
84
+ }
85
+ }
86
+ else {
87
+ this.#lastSample = sample;
88
+ this.#runLength = 1;
89
+ }
90
+ // Adaptive Proportion Test
91
+ if (this.#windowIndex === 0) {
92
+ this.#reference = sample;
93
+ this.#referenceCount = 1;
94
+ this.#windowIndex = 1;
95
+ }
96
+ else {
97
+ if (sample === this.#reference) {
98
+ this.#referenceCount++;
99
+ if (this.#referenceCount >= this.aptCutoff) {
100
+ raised.push(this.#alarm('apt', this.#referenceCount, this.aptCutoff));
101
+ this.#windowIndex = 0; // observational: restart the window
102
+ this.#samplesSeen++;
103
+ continue;
104
+ }
105
+ }
106
+ this.#windowIndex++;
107
+ if (this.#windowIndex === this.#windowSize)
108
+ this.#windowIndex = 0;
109
+ }
110
+ this.#samplesSeen++;
111
+ }
112
+ return raised;
113
+ }
114
+ }
115
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/extract/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAEhD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,EAAE,CAAA,CAAC,iEAAiE;AAExF,kFAAkF;AAClF,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS,EAAE,UAAkB;IACrD,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;IACjB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACvB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC1B,MAAM,YAAY,GAAG,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;IAC5C,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,KAAK,IAAI,CAA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
3
+ * T[i][j] = seed bit (i − j) + (n − 1); output yᵢ = ⊕ⱼ T[i][j]·xⱼ.
4
+ * Leftover hash lemma: with input min-entropy ≥ k bits, choosing
5
+ * m ≤ k − 2·log₂(1/ε) output bits puts the output within statistical
6
+ * distance ε of uniform — EVEN IF THE SEED IS PUBLIC (strong extractor;
7
+ * the seed is reusable). The seed must be uniform and independent of the
8
+ * input — never derive it from the stream being extracted.
9
+ */
10
+ export interface ToeplitzExtractor {
11
+ readonly inputBits: number;
12
+ readonly outputBits: number;
13
+ /** Extract from exactly ⌈inputBits/8⌉ bytes (MSB-first; trailing pad bits ignored). */
14
+ extract(input: Uint8Array): Uint8Array;
15
+ }
16
+ /** Leftover-hash-lemma output length: m = ⌊k − 2·log₂(1/ε)⌋. Default ε = 2⁻³². */
17
+ export declare function toeplitzOutputBits(minEntropyBits: number, epsilon?: number): number;
18
+ export declare function toeplitzExtractor(seed: Uint8Array, inputBits: number, outputBits: number): ToeplitzExtractor;
19
+ //# sourceMappingURL=toeplitz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toeplitz.d.ts","sourceRoot":"","sources":["../../src/extract/toeplitz.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,uFAAuF;IACvF,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAA;CACvC;AAED,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,SAAW,GAAG,MAAM,CAKrF;AA0BD,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,iBAAiB,CA6DnB"}
@@ -0,0 +1,83 @@
1
+ import { NegentropyError } from '../errors.js';
2
+ /** Leftover-hash-lemma output length: m = ⌊k − 2·log₂(1/ε)⌋. Default ε = 2⁻³². */
3
+ export function toeplitzOutputBits(minEntropyBits, epsilon = 2 ** -32) {
4
+ if (!(epsilon > 0 && epsilon < 1)) {
5
+ throw new NegentropyError('invalid_config', `epsilon must be in (0, 1), got ${epsilon}`);
6
+ }
7
+ return Math.floor(minEntropyBits - 2 * Math.log2(1 / epsilon));
8
+ }
9
+ /** Read bit t (global MSB-first order) from a byte array. */
10
+ function bitAt(bytes, t) {
11
+ return (bytes[t >> 3] >> (7 - (t & 7))) & 1;
12
+ }
13
+ /** Pack bits[0..count) (MSB-first order) into 32-bit words, bit t at word t>>5, position t&31. */
14
+ function packWords(bytes, count) {
15
+ const words = new Uint32Array(Math.ceil(count / 32));
16
+ for (let t = 0; t < count; t++) {
17
+ if (bitAt(bytes, t))
18
+ words[t >> 5] = (words[t >> 5] | (1 << (t & 31))) >>> 0;
19
+ }
20
+ return words;
21
+ }
22
+ function parity32(v) {
23
+ let x = v;
24
+ x ^= x >>> 16;
25
+ x ^= x >>> 8;
26
+ x ^= x >>> 4;
27
+ x ^= x >>> 2;
28
+ x ^= x >>> 1;
29
+ return x & 1;
30
+ }
31
+ export function toeplitzExtractor(seed, inputBits, outputBits) {
32
+ if (!Number.isInteger(inputBits) || inputBits < 2) {
33
+ throw new NegentropyError('invalid_config', `inputBits must be an integer ≥ 2, got ${inputBits}`);
34
+ }
35
+ if (!Number.isInteger(outputBits) || outputBits < 1 || outputBits >= inputBits) {
36
+ throw new NegentropyError('invalid_config', `outputBits must be an integer in [1, inputBits), got ${outputBits}`);
37
+ }
38
+ const seedBits = inputBits + outputBits - 1;
39
+ const expectedSeedBytes = Math.ceil(seedBits / 8);
40
+ if (seed.length !== expectedSeedBytes) {
41
+ throw new NegentropyError('invalid_config', `seed must be exactly ${expectedSeedBytes} bytes (${seedBits} bits), got ${seed.length}`);
42
+ }
43
+ // yᵢ = parity over t of seed[i + t]·xrev[t], xrev[t] = x[n−1−t]: row i of T is a
44
+ // sliding n-bit window of the seed against the reversed input — word-wise below.
45
+ const inputWords = Math.ceil(inputBits / 32);
46
+ const seedWords = packWords(seed, seedBits);
47
+ const lastMask = inputBits % 32 === 0 ? 0xffffffff : (1 << (inputBits % 32)) - 1; // valid bits of the last window word
48
+ return {
49
+ inputBits,
50
+ outputBits,
51
+ extract(input) {
52
+ if (input.length !== Math.ceil(inputBits / 8)) {
53
+ throw new NegentropyError('invalid_config', `input must be exactly ${Math.ceil(inputBits / 8)} bytes, got ${input.length}`);
54
+ }
55
+ // pack reversed input bits into words
56
+ const xrev = new Uint32Array(inputWords);
57
+ for (let t = 0; t < inputBits; t++) {
58
+ if (bitAt(input, inputBits - 1 - t)) {
59
+ xrev[t >> 5] = (xrev[t >> 5] | (1 << (t & 31))) >>> 0;
60
+ }
61
+ }
62
+ const out = new Uint8Array(Math.ceil(outputBits / 8));
63
+ for (let i = 0; i < outputBits; i++) {
64
+ const base = i >> 5;
65
+ const off = i & 31;
66
+ let acc = 0;
67
+ for (let w = 0; w < inputWords; w++) {
68
+ let window = seedWords[base + w] >>> off;
69
+ if (off !== 0)
70
+ window |= (seedWords[base + w + 1] ?? 0) << (32 - off);
71
+ window >>>= 0;
72
+ if (w === inputWords - 1)
73
+ window &= lastMask;
74
+ acc ^= window & xrev[w];
75
+ }
76
+ if (parity32(acc))
77
+ out[i >> 3] = out[i >> 3] | (1 << (7 - (i & 7)));
78
+ }
79
+ return out;
80
+ },
81
+ };
82
+ }
83
+ //# sourceMappingURL=toeplitz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toeplitz.js","sourceRoot":"","sources":["../../src/extract/toeplitz.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAkB9C,kFAAkF;AAClF,MAAM,UAAU,kBAAkB,CAAC,cAAsB,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE;IAC3E,IAAI,CAAC,CAAC,OAAO,GAAG,CAAC,IAAI,OAA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BACpD,IAAI,GAAG,KAAK,CAAC;wBAAE,MAAM,IAAK,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAY,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAA;oBACjF,MAAM,MAAM,CAAC,CAAA;oBACb,IAAI,CAAC,KAAK,UAAU,GAAG,CAAC;wBAAE,MAAM,IAAI,QAAQ,CAAA;oBAC5C,GAAG,IAAI,MAAM,GAAI,IAAI,CAAC,CAAC,CAAY,CAAA;gBACrC,CAAC;gBACD,IAAI,QAAQ,CAAC,GAAG,CAAC;oBAAE,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YACjF,CAAC;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ export type { NegentropyErrorCode, NegentropyErrorOptions } from './errors.js';
2
+ export { NegentropyError } from './errors.js';
3
+ export { markovMinEntropyPerBit, mcvMinEntropy, shannonEntropy, toBits, } from './estimators/entropy.js';
4
+ export { chiSquareBytes, monobit, runsTest, serialCorrelation } from './estimators/frequency.js';
5
+ export type { ContrastNegentropy, MomentNegentropy } from './estimators/negentropy.js';
6
+ export { EXP_GAUSSIAN_MEAN, EXP_GAUSSIAN_VARIANCE, EXP_NULL_VARIANCE, LOGCOSH_GAUSSIAN_MEAN, LOGCOSH_GAUSSIAN_VARIANCE, LOGCOSH_NULL_VARIANCE, negentropyExp, negentropyKurtosis, negentropyLogcosh, } from './estimators/negentropy.js';
7
+ export type { DitherOptions } from './estimators/pipeline.js';
8
+ export { ditheredTrialZ, probitBytes } from './estimators/pipeline.js';
9
+ export { negentropyVasicek, vasicekEntropy } from './estimators/vasicek.js';
10
+ export type { WindowedEstimator, WindowedNegentropyOptions, WindowedNegentropyPoint, } from './estimators/windowed.js';
11
+ export { windowedNegentropy } from './estimators/windowed.js';
12
+ export { analyzeBytes, analyzeTrials } from './experiment/batch.js';
13
+ export { bonferroni, compositeZ } from './experiment/composite.js';
14
+ export type { RegisteredExperiment } from './experiment/registration.js';
15
+ export { canonicalJson, registerExperiment } from './experiment/registration.js';
16
+ export type { Session, SessionOptions, SessionTick } from './experiment/session.js';
17
+ export { session } from './experiment/session.js';
18
+ export type { EventResult, EventSpec, EventStatistic, ExperimentComposite, ExperimentConfig, ExperimentResult, } from './experiment/types.js';
19
+ export type { AccountedBytes, EntropyClaim, PipelineOp, PipelineStep, } from './extract/accounting.js';
20
+ export { claimBytes, conditionAccounted, debiasAccounted, extractAccounted, vettedOutputEntropy, } from './extract/accounting.js';
21
+ export type { ConditionStreamOptions } from './extract/condition.js';
22
+ export { conditionStream, hmacCondition, sha256Condition } from './extract/condition.js';
23
+ export { peres, peresRate, vonNeumann } from './extract/debias.js';
24
+ export type { HealthAlarm, HealthConfig } from './extract/health.js';
25
+ export { aptCutoff, ContinuousHealth, rctCutoff } from './extract/health.js';
26
+ export type { ToeplitzExtractor } from './extract/toeplitz.js';
27
+ export { toeplitzExtractor, toeplitzOutputBits } from './extract/toeplitz.js';
28
+ export type { CalibrateOptions } from './stats/calibration.js';
29
+ export { calibrate, theoreticalCalibration } from './stats/calibration.js';
30
+ export { cumulativeDeviation, significanceEnvelope } from './stats/cumdev.js';
31
+ export type { PairCorrelation } from './stats/network.js';
32
+ export { devvar, interSourceCorrelation, netvar } from './stats/network.js';
33
+ export type { Tail } from './stats/pvalues.js';
34
+ export { chiSquareP, normalP, P_FLOOR } from './stats/pvalues.js';
35
+ export type { TrialStreamConfig } from './stats/trials.js';
36
+ export { DEFAULT_BITS_PER_TRIAL, trialStream, trialsFromBytes } from './stats/trials.js';
37
+ export { stoufferZ, zScores } from './stats/zscores.js';
38
+ export type { Calibration, StatResult, Trial, TrialClock, TrialConfig, TrialSeries, TrialSource, TrialStreamOptions, } from './types.js';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAChG,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AACtF,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,4BAA4B,CAAA;AACnC,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC3E,YAAY,EACV,iBAAiB,EACjB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAClE,YAAY,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAChF,YAA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,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACjE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACvD,YAAY,EACV,WAAW,EACX,UAAU,EACV,KAAK,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,WAAW,EACX,kBAAkB,GACnB,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ export { NegentropyError } from './errors.js';
2
+ export { markovMinEntropyPerBit, mcvMinEntropy, shannonEntropy, toBits, } from './estimators/entropy.js';
3
+ export { chiSquareBytes, monobit, runsTest, serialCorrelation } from './estimators/frequency.js';
4
+ export { EXP_GAUSSIAN_MEAN, EXP_GAUSSIAN_VARIANCE, EXP_NULL_VARIANCE, LOGCOSH_GAUSSIAN_MEAN, LOGCOSH_GAUSSIAN_VARIANCE, LOGCOSH_NULL_VARIANCE, negentropyExp, negentropyKurtosis, negentropyLogcosh, } from './estimators/negentropy.js';
5
+ export { ditheredTrialZ, probitBytes } from './estimators/pipeline.js';
6
+ export { negentropyVasicek, vasicekEntropy } from './estimators/vasicek.js';
7
+ export { windowedNegentropy } from './estimators/windowed.js';
8
+ export { analyzeBytes, analyzeTrials } from './experiment/batch.js';
9
+ export { bonferroni, compositeZ } from './experiment/composite.js';
10
+ export { canonicalJson, registerExperiment } from './experiment/registration.js';
11
+ export { session } from './experiment/session.js';
12
+ export { claimBytes, conditionAccounted, debiasAccounted, extractAccounted, vettedOutputEntropy, } from './extract/accounting.js';
13
+ export { conditionStream, hmacCondition, sha256Condition } from './extract/condition.js';
14
+ export { peres, peresRate, vonNeumann } from './extract/debias.js';
15
+ export { aptCutoff, ContinuousHealth, rctCutoff } from './extract/health.js';
16
+ export { toeplitzExtractor, toeplitzOutputBits } from './extract/toeplitz.js';
17
+ export { calibrate, theoreticalCalibration } from './stats/calibration.js';
18
+ export { cumulativeDeviation, significanceEnvelope } from './stats/cumdev.js';
19
+ export { devvar, interSourceCorrelation, netvar } from './stats/network.js';
20
+ export { chiSquareP, normalP, P_FLOOR } from './stats/pvalues.js';
21
+ export { DEFAULT_BITS_PER_TRIAL, trialStream, trialsFromBytes } from './stats/trials.js';
22
+ export { stoufferZ, zScores } from './stats/zscores.js';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,cAAc,EACd,MAAM,GACP,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAEhG,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,yBAAyB,EACzB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAM3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAElE,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AAejD,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE7E,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAE7E,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAE3E,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAEjE,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,6 @@
1
+ /** Number of one-bits in each byte value. */
2
+ export declare const POPCOUNT: Uint8Array;
3
+ /** Unpack bytes into bits, MSB first (the SDK-wide bit order). */
4
+ export declare function toBits(data: Uint8Array): Uint8Array;
5
+ export declare function concatBytes(chunks: readonly Uint8Array[]): Uint8Array;
6
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/internal/bytes.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,eAAO,MAAM,QAAQ,EAAE,UAYnB,CAAA;AAEJ,kEAAkE;AAClE,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMnD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG,UAAU,CAUrE"}
@@ -0,0 +1,36 @@
1
+ /** Number of one-bits in each byte value. */
2
+ export const POPCOUNT = (() => {
3
+ const table = new Uint8Array(256);
4
+ for (let i = 0; i < 256; i++) {
5
+ let v = i;
6
+ let count = 0;
7
+ while (v) {
8
+ count += v & 1;
9
+ v >>= 1;
10
+ }
11
+ table[i] = count;
12
+ }
13
+ return table;
14
+ })();
15
+ /** Unpack bytes into bits, MSB first (the SDK-wide bit order). */
16
+ export function toBits(data) {
17
+ const bits = new Uint8Array(data.length * 8);
18
+ for (let i = 0; i < data.length; i++) {
19
+ for (let b = 0; b < 8; b++)
20
+ bits[i * 8 + b] = (data[i] >> (7 - b)) & 1;
21
+ }
22
+ return bits;
23
+ }
24
+ export function concatBytes(chunks) {
25
+ let total = 0;
26
+ for (const chunk of chunks)
27
+ total += chunk.length;
28
+ const out = new Uint8Array(total);
29
+ let offset = 0;
30
+ for (const chunk of chunks) {
31
+ out.set(chunk, offset);
32
+ offset += chunk.length;
33
+ }
34
+ return out;
35
+ }
36
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/internal/bytes.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,CAAC,MAAM,QAAQ,GAAe,CAAC,GAAG,EAAE;IACxC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IACjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,OAAO,CAAC,EAAE,CAAC;YACT,KAAK,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+ add(x: number): void;
5
+ get value(): number;
6
+ }
7
+ //# sourceMappingURL=kahan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kahan.d.ts","sourceRoot":"","sources":["../../src/internal/kahan.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,qBAAa,QAAQ;;IAInB,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAOpB,IAAI,KAAK,IAAI,MAAM,CAElB;CACF"}
@@ -0,0 +1,15 @@
1
+ /** Kahan-compensated summation — keeps long accumulations at O(ε) error. */
2
+ export class KahanSum {
3
+ #sum = 0;
4
+ #compensation = 0;
5
+ add(x) {
6
+ const y = x - this.#compensation;
7
+ const t = this.#sum + y;
8
+ this.#compensation = t - this.#sum - y;
9
+ this.#sum = t;
10
+ }
11
+ get value() {
12
+ return this.#sum;
13
+ }
14
+ }
15
+ //# sourceMappingURL=kahan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kahan.js","sourceRoot":"","sources":["../../src/internal/kahan.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,OAAO,QAAQ;IACnB,IAAI,GAAG,CAAC,CAAA;IACR,aAAa,GAAG,CAAC,CAAA;IAEjB,GAAG,CAAC,CAAS;QACX,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAA;QAChC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;QACvB,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAA;IACf,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Deterministic xorshift32 uniform stream in (0, 1) exclusive. Used for
3
+ * dither noise — dither must be reproducible and must NEVER spend the
4
+ * randomness under test.
5
+ */
6
+ export declare function uniformStream(seed?: number): () => number;
7
+ //# sourceMappingURL=prng.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prng.d.ts","sourceRoot":"","sources":["../../src/internal/prng.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,SAAa,GAAG,MAAM,MAAM,CAS7D"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Deterministic xorshift32 uniform stream in (0, 1) exclusive. Used for
3
+ * dither noise — dither must be reproducible and must NEVER spend the
4
+ * randomness under test.
5
+ */
6
+ export function uniformStream(seed = 0x9e3779b9) {
7
+ let state = seed >>> 0 || 1;
8
+ return () => {
9
+ state ^= state << 13;
10
+ state ^= state >>> 17;
11
+ state ^= state << 5;
12
+ state >>>= 0;
13
+ return (state + 0.5) / 4294967296;
14
+ };
15
+ }
16
+ //# sourceMappingURL=prng.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prng.js","sourceRoot":"","sources":["../../src/internal/prng.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAI,GAAG,UAAU;IAC7C,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;IAC3B,OAAO,GAAG,EAAE;QACV,KAAK,IAAI,KAAK,IAAI,EAAE,CAAA;QACpB,KAAK,IAAI,KAAK,KAAK,EAAE,CAAA;QACrB,KAAK,IAAI,KAAK,IAAI,CAAC,CAAA;QACnB,KAAK,MAAM,CAAC,CAAA;QACZ,OAAO,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,UAAU,CAAA;IACnC,CAAC,CAAA;AACH,CAAC"}