@ontrails/core 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.
- package/CHANGELOG.md +849 -0
- package/README.md +190 -0
- package/package.json +36 -0
- package/src/activation-provenance.ts +116 -0
- package/src/activation-source-compatibility.ts +430 -0
- package/src/activation-source-derivation.ts +227 -0
- package/src/activation-source.ts +93 -0
- package/src/blob-ref.ts +90 -0
- package/src/branded.ts +135 -0
- package/src/collections.ts +99 -0
- package/src/compose-batch.ts +69 -0
- package/src/compose-schema.ts +36 -0
- package/src/context.ts +66 -0
- package/src/derive.ts +485 -0
- package/src/detours.ts +8 -0
- package/src/diagnostics.ts +21 -0
- package/src/draft.ts +350 -0
- package/src/entity.ts +346 -0
- package/src/error-rendering.ts +87 -0
- package/src/errors.ts +483 -0
- package/src/execute.ts +1577 -0
- package/src/fetch.ts +138 -0
- package/src/fire.ts +1172 -0
- package/src/glob.ts +81 -0
- package/src/guards.ts +37 -0
- package/src/index.ts +704 -0
- package/src/internal/fork-ctx.ts +69 -0
- package/src/layer-field-rendering.ts +193 -0
- package/src/layer.ts +81 -0
- package/src/observe.ts +361 -0
- package/src/path-scope.ts +66 -0
- package/src/path-security.ts +98 -0
- package/src/patterns/bulk.ts +16 -0
- package/src/patterns/change.ts +12 -0
- package/src/patterns/date-range.ts +12 -0
- package/src/patterns/index.ts +8 -0
- package/src/patterns/pagination.ts +22 -0
- package/src/patterns/progress.ts +13 -0
- package/src/patterns/sorting.ts +14 -0
- package/src/patterns/status.ts +11 -0
- package/src/patterns/timestamps.ts +12 -0
- package/src/permits.ts +12 -0
- package/src/queue.ts +163 -0
- package/src/redaction/index.ts +3 -0
- package/src/redaction/patterns.ts +50 -0
- package/src/redaction/redactor.ts +178 -0
- package/src/resilience.ts +234 -0
- package/src/resource-config.ts +804 -0
- package/src/resource.ts +194 -0
- package/src/result.ts +212 -0
- package/src/run.ts +76 -0
- package/src/runtime-builtins.ts +69 -0
- package/src/schedule-runtime.ts +689 -0
- package/src/schedule.ts +326 -0
- package/src/serialization.ts +265 -0
- package/src/sha256.ts +136 -0
- package/src/signal-diagnostics.ts +633 -0
- package/src/signal-ref.ts +111 -0
- package/src/signal.ts +104 -0
- package/src/store/accessor-protocol.ts +56 -0
- package/src/store/index.ts +4 -0
- package/src/structured-examples.ts +248 -0
- package/src/surface-derivation.ts +91 -0
- package/src/surface-filter.ts +101 -0
- package/src/surface-overlay.ts +694 -0
- package/src/surface-versioning.ts +42 -0
- package/src/topo.ts +835 -0
- package/src/tracing.ts +346 -0
- package/src/trail-id-glob.ts +15 -0
- package/src/trail.ts +1351 -0
- package/src/trails/derive-trail.ts +835 -0
- package/src/trails/index.ts +9 -0
- package/src/trails/ingest.ts +152 -0
- package/src/trails-db.ts +212 -0
- package/src/transport-error-map.ts +163 -0
- package/src/type-utils.ts +87 -0
- package/src/types.ts +300 -0
- package/src/validate-established-topo.ts +73 -0
- package/src/validate-topo.ts +725 -0
- package/src/validation.ts +330 -0
- package/src/version-marker.ts +716 -0
- package/src/version-resolution.ts +308 -0
- package/src/version-runtime.ts +120 -0
- package/src/webhook.ts +461 -0
- package/src/workspace.ts +244 -0
- package/src/zod-wrappers.ts +72 -0
package/src/sha256.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure synchronous SHA-256 for runtime-portable fingerprints.
|
|
3
|
+
*
|
|
4
|
+
* `node:crypto`'s `createHash` is unavailable on edge runtimes without
|
|
5
|
+
* compatibility flags, and Web Crypto's `subtle.digest` is asynchronous,
|
|
6
|
+
* which does not fit the synchronous summary paths that need a digest
|
|
7
|
+
* (signal payload summaries, per-project store keys). This implementation
|
|
8
|
+
* follows FIPS 180-4 and produces output identical to
|
|
9
|
+
* `createHash('sha256').update(text).digest('hex')`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/* oxlint-disable no-bitwise, unicorn/prefer-math-trunc, unicorn/number-literal-case -- SHA-256 is defined over 32-bit words: rotations, xor, and `>>> 0` unsigned wrapping are the specified operations, and `Math.trunc()` is not equivalent to `>>> 0` (it neither wraps to 32 bits nor coerces to unsigned). number-literal-case is disabled because oxfmt normalizes hex digits to lowercase, which the rule rejects — the formatter wins. */
|
|
13
|
+
|
|
14
|
+
// FIPS 180-4 §4.2.2: first 32 bits of the fractional parts of the cube
|
|
15
|
+
// roots of the first 64 primes.
|
|
16
|
+
const K = Uint32Array.from([
|
|
17
|
+
0x42_8a_2f_98, 0x71_37_44_91, 0xb5_c0_fb_cf, 0xe9_b5_db_a5, 0x39_56_c2_5b,
|
|
18
|
+
0x59_f1_11_f1, 0x92_3f_82_a4, 0xab_1c_5e_d5, 0xd8_07_aa_98, 0x12_83_5b_01,
|
|
19
|
+
0x24_31_85_be, 0x55_0c_7d_c3, 0x72_be_5d_74, 0x80_de_b1_fe, 0x9b_dc_06_a7,
|
|
20
|
+
0xc1_9b_f1_74, 0xe4_9b_69_c1, 0xef_be_47_86, 0x0f_c1_9d_c6, 0x24_0c_a1_cc,
|
|
21
|
+
0x2d_e9_2c_6f, 0x4a_74_84_aa, 0x5c_b0_a9_dc, 0x76_f9_88_da, 0x98_3e_51_52,
|
|
22
|
+
0xa8_31_c6_6d, 0xb0_03_27_c8, 0xbf_59_7f_c7, 0xc6_e0_0b_f3, 0xd5_a7_91_47,
|
|
23
|
+
0x06_ca_63_51, 0x14_29_29_67, 0x27_b7_0a_85, 0x2e_1b_21_38, 0x4d_2c_6d_fc,
|
|
24
|
+
0x53_38_0d_13, 0x65_0a_73_54, 0x76_6a_0a_bb, 0x81_c2_c9_2e, 0x92_72_2c_85,
|
|
25
|
+
0xa2_bf_e8_a1, 0xa8_1a_66_4b, 0xc2_4b_8b_70, 0xc7_6c_51_a3, 0xd1_92_e8_19,
|
|
26
|
+
0xd6_99_06_24, 0xf4_0e_35_85, 0x10_6a_a0_70, 0x19_a4_c1_16, 0x1e_37_6c_08,
|
|
27
|
+
0x27_48_77_4c, 0x34_b0_bc_b5, 0x39_1c_0c_b3, 0x4e_d8_aa_4a, 0x5b_9c_ca_4f,
|
|
28
|
+
0x68_2e_6f_f3, 0x74_8f_82_ee, 0x78_a5_63_6f, 0x84_c8_78_14, 0x8c_c7_02_08,
|
|
29
|
+
0x90_be_ff_fa, 0xa4_50_6c_eb, 0xbe_f9_a3_f7, 0xc6_71_78_f2,
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const rotr = (value: number, bits: number): number =>
|
|
33
|
+
(value >>> bits) | (value << (32 - bits));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Total array accessor: every read in the compression loop is provably in
|
|
37
|
+
* range, so the fallback never fires — it only satisfies
|
|
38
|
+
* `noUncheckedIndexedAccess` without an assertion.
|
|
39
|
+
*/
|
|
40
|
+
const wordAt = (words: Uint32Array, index: number): number => words[index] ?? 0;
|
|
41
|
+
|
|
42
|
+
const padMessage = (bytes: Uint8Array): Uint8Array => {
|
|
43
|
+
const bitLength = bytes.length * 8;
|
|
44
|
+
// Message + 0x80 marker, padded to 56 mod 64, then a 64-bit big-endian
|
|
45
|
+
// bit length. Message sizes here are far below 2^32 bits, so the high
|
|
46
|
+
// word of the length is derived from the float division.
|
|
47
|
+
const paddedLength = (Math.floor((bytes.length + 8) / 64) + 1) * 64;
|
|
48
|
+
const padded = new Uint8Array(paddedLength);
|
|
49
|
+
padded.set(bytes);
|
|
50
|
+
padded[bytes.length] = 0x80;
|
|
51
|
+
const view = new DataView(padded.buffer);
|
|
52
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 0x1_00_00_00_00));
|
|
53
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
54
|
+
return padded;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const fillSchedule = (w: Uint32Array, view: DataView, offset: number): void => {
|
|
58
|
+
for (let i = 0; i < 16; i += 1) {
|
|
59
|
+
w[i] = view.getUint32(offset + i * 4);
|
|
60
|
+
}
|
|
61
|
+
for (let i = 16; i < 64; i += 1) {
|
|
62
|
+
const w15 = wordAt(w, i - 15);
|
|
63
|
+
const w2 = wordAt(w, i - 2);
|
|
64
|
+
const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);
|
|
65
|
+
const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);
|
|
66
|
+
w[i] = (wordAt(w, i - 16) + s0 + wordAt(w, i - 7) + s1) >>> 0;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// oxlint-disable-next-line max-statements -- the FIPS 180-4 compression loop reads more clearly as one block than split across helpers
|
|
71
|
+
const digestHex = (padded: Uint8Array): string => {
|
|
72
|
+
// FIPS 180-4 §5.3.3 initial hash value.
|
|
73
|
+
let h0 = 0x6a_09_e6_67;
|
|
74
|
+
let h1 = 0xbb_67_ae_85;
|
|
75
|
+
let h2 = 0x3c_6e_f3_72;
|
|
76
|
+
let h3 = 0xa5_4f_f5_3a;
|
|
77
|
+
let h4 = 0x51_0e_52_7f;
|
|
78
|
+
let h5 = 0x9b_05_68_8c;
|
|
79
|
+
let h6 = 0x1f_83_d9_ab;
|
|
80
|
+
let h7 = 0x5b_e0_cd_19;
|
|
81
|
+
|
|
82
|
+
const view = new DataView(padded.buffer);
|
|
83
|
+
const w = new Uint32Array(64);
|
|
84
|
+
|
|
85
|
+
for (let offset = 0; offset < padded.length; offset += 64) {
|
|
86
|
+
fillSchedule(w, view, offset);
|
|
87
|
+
|
|
88
|
+
let a = h0;
|
|
89
|
+
let b = h1;
|
|
90
|
+
let c = h2;
|
|
91
|
+
let d = h3;
|
|
92
|
+
let e = h4;
|
|
93
|
+
let f = h5;
|
|
94
|
+
let g = h6;
|
|
95
|
+
let h = h7;
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < 64; i += 1) {
|
|
98
|
+
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
99
|
+
const ch = (e & f) ^ (~e & g);
|
|
100
|
+
const temp1 = (h + s1 + ch + wordAt(K, i) + wordAt(w, i)) >>> 0;
|
|
101
|
+
const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
|
|
102
|
+
const maj = (a & b) ^ (a & c) ^ (b & c);
|
|
103
|
+
const temp2 = (s0 + maj) >>> 0;
|
|
104
|
+
|
|
105
|
+
h = g;
|
|
106
|
+
g = f;
|
|
107
|
+
f = e;
|
|
108
|
+
e = (d + temp1) >>> 0;
|
|
109
|
+
d = c;
|
|
110
|
+
c = b;
|
|
111
|
+
b = a;
|
|
112
|
+
a = (temp1 + temp2) >>> 0;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
h0 = (h0 + a) >>> 0;
|
|
116
|
+
h1 = (h1 + b) >>> 0;
|
|
117
|
+
h2 = (h2 + c) >>> 0;
|
|
118
|
+
h3 = (h3 + d) >>> 0;
|
|
119
|
+
h4 = (h4 + e) >>> 0;
|
|
120
|
+
h5 = (h5 + f) >>> 0;
|
|
121
|
+
h6 = (h6 + g) >>> 0;
|
|
122
|
+
h7 = (h7 + h) >>> 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return [h0, h1, h2, h3, h4, h5, h6, h7]
|
|
126
|
+
.map((word) => word.toString(16).padStart(8, '0'))
|
|
127
|
+
.join('');
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* SHA-256 of the UTF-8 encoding of `text`, as lowercase hex.
|
|
132
|
+
*
|
|
133
|
+
* Output-identical to `createHash('sha256').update(text).digest('hex')`.
|
|
134
|
+
*/
|
|
135
|
+
export const sha256Hex = (text: string): string =>
|
|
136
|
+
digestHex(padMessage(new TextEncoder().encode(text)));
|