nish 0.39.0 → 0.41.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/README.md +190 -555
- package/docs/AI.md +112 -33
- package/docs/INSTALL.md +79 -133
- package/llms.txt +2 -9
- package/package.json +17 -19
- package/runtime/nish.d.ts +21 -17
- package/runtime/nish.h +10 -0
- package/runtime/page-frame.d.ts +123 -0
- package/runtime/page-frame.mjs +736 -0
- package/runtime/page-game.d.ts +132 -0
- package/runtime/page-game.mjs +738 -0
- package/runtime/runtime-aes.c +85 -8
- package/runtime/runtime-bytes.c +88 -4
- package/runtime/runtime-net.c +32 -0
- package/runtime/runtime-sandbox.c +55 -28
- package/runtime/runtime-uring.c +1194 -0
- package/runtime/runtime-wasm.c +422 -0
- package/runtime/vite.mjs +1 -1
- package/scripts/build.sh +22 -6
- package/std/README.md +74 -87
- package/std/array.ts +36 -3
- package/std/collections.ts +51 -0
- package/std/crypto/hmac.ts +37 -10
- package/std/crypto/p256.ts +1388 -2664
- package/std/crypto/pki.ts +116 -4
- package/std/crypto/sha256.ts +34 -6
- package/std/crypto/x509.ts +7 -0
- package/std/host/game.ts +273 -0
- package/std/input.ts +56 -0
- package/std/json-tokenizer.ts +325 -112
- package/std/json-typed.ts +43 -8
- package/std/json-value.ts +144 -3
- package/std/json.ts +63 -8
- package/std/net/fetch.ts +22 -4
- package/std/net/http-server.ts +3382 -0
- package/std/net/http1-client-codec.ts +6 -2
- package/std/net/http1-codec.ts +137 -12
- package/std/net/http1-server.ts +83 -29
- package/std/net/http2.ts +47 -14
- package/std/net/http3-server.ts +29 -3
- package/std/net/http3.ts +180 -7
- package/std/net/prefork.ts +49 -13
- package/std/net/quic-recovery.ts +240 -9
- package/std/net/quic-stream.ts +21 -1
- package/std/net/quic.ts +98 -4
- package/std/net/router.ts +378 -31
- package/std/net/serve.ts +873 -65
- package/std/net/tls/verify.ts +19 -1
- package/std/net/url.ts +83 -35
- package/std/net/websocket.ts +74 -1
- package/std/net/webtransport.ts +7 -1
- package/std/raster.ts +837 -0
- package/std/release.ts +593 -0
- package/std/synth.ts +143 -0
- package/std/temporal.ts +3091 -0
- package/std/threads.ts +298 -0
- package/std/yaml-json.ts +368 -28
- package/std/yaml.ts +122 -27
- package/scripts/bootstrap.sh +0 -375
- package/scripts/build-id-smoke.sh +0 -28
- package/scripts/changelog-gen.mjs +0 -649
- package/scripts/changelog-section.sh +0 -28
- package/scripts/check-hardening.mjs +0 -202
- package/scripts/ci-profile.mjs +0 -200
- package/scripts/codes-registry.js +0 -85
- package/scripts/fuzz.sh +0 -280
- package/scripts/gen-diagnostic-codes.mjs +0 -243
- package/scripts/gen-json-pow5.mjs +0 -130
- package/scripts/gen-p256-table.mjs +0 -177
- package/scripts/gen-pow10-table.py +0 -80
- package/scripts/gen-regex-unicode.mjs +0 -822
- package/scripts/gen-union-scale.mjs +0 -294
- package/scripts/nish-compiler.sh +0 -19
- package/scripts/platform-package.mjs +0 -93
- package/scripts/security-scope.mjs +0 -139
- package/scripts/shard-costs.mjs +0 -429
- package/scripts/size-report.sh +0 -84
- package/scripts/smoke.sh +0 -105
- package/scripts/std-module-paths.mjs +0 -25
- package/scripts/undocumented.txt +0 -14
- package/scripts/verify-binaries.sh +0 -214
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Generate the fixed-base comb table of `std/crypto/p256.ts`.
|
|
4
|
-
*
|
|
5
|
-
* node scripts/gen-p256-table.mjs rewrite the table in std/crypto/p256.ts
|
|
6
|
-
* node scripts/gen-p256-table.mjs --check exit 1 if the table there differs by a byte
|
|
7
|
-
*
|
|
8
|
-
* The table is the region of `p256.ts` between the `gen-p256-table:begin` and
|
|
9
|
-
* `gen-p256-table:end` lines: `p256BaseTable`, which answers 16 sub-tables of
|
|
10
|
-
* 15 affine points each. Sub-table `c`, entry `j` (1 to 15), is
|
|
11
|
-
*
|
|
12
|
-
* (j_0 + j_1 2^64 + j_2 2^128 + j_3 2^192) 2^(4c) G
|
|
13
|
-
*
|
|
14
|
-
* where `j_b` is bit `b` of `j`, so a 4-tooth comb whose teeth are 64 bits
|
|
15
|
-
* apart, one sub-table per 4-bit offset of the comb. `p256BaseMult` reads the
|
|
16
|
-
* scalar's bits `i`, `i + 64`, `i + 128` and `i + 192` as one digit and adds
|
|
17
|
-
* the entry it names; 4 rows of 16 such additions, with a doubling between
|
|
18
|
-
* rows, are the whole multiplication. Each entry is X then Y, eight 32-bit
|
|
19
|
-
* limbs each, least significant first, in the Montgomery domain (x 2^256 mod
|
|
20
|
-
* p) that fiat's arithmetic works in: 3,840 limbs, 15 KiB.
|
|
21
|
-
*
|
|
22
|
-
* Computed here with BigInt from SEC 2 §2.4.2's p, b and G, by the textbook
|
|
23
|
-
* affine formulas: the table is public, so nothing here needs to be constant
|
|
24
|
-
* time. The region lives inside `p256.ts` rather than in a module of its own
|
|
25
|
-
* because a file under `std/` is a public `nish/` module, listed as one by the
|
|
26
|
-
* compiler and the release.
|
|
27
|
-
*/
|
|
28
|
-
import fs from "node:fs"
|
|
29
|
-
import path from "node:path"
|
|
30
|
-
import { fileURLToPath } from "node:url"
|
|
31
|
-
|
|
32
|
-
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
|
33
|
-
const target = path.join(root, "std", "crypto", "p256.ts")
|
|
34
|
-
|
|
35
|
-
const P = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffffn
|
|
36
|
-
const B = 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604bn
|
|
37
|
-
const G = {
|
|
38
|
-
x: 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296n,
|
|
39
|
-
y: 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5n,
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** The comb's shape: teeth 64 bits apart, one sub-table per 4-bit offset. */
|
|
43
|
-
const TEETH = 4
|
|
44
|
-
const SPACING = 64
|
|
45
|
-
const SUBTABLES = 16
|
|
46
|
-
|
|
47
|
-
const mod = (a) => ((a % P) + P) % P
|
|
48
|
-
|
|
49
|
-
/** `a^-1 mod p`, by Fermat: p is prime. */
|
|
50
|
-
const inverse = (a) => {
|
|
51
|
-
let result = 1n
|
|
52
|
-
let base = mod(a)
|
|
53
|
-
let e = P - 2n
|
|
54
|
-
while (e > 0n) {
|
|
55
|
-
if (e & 1n) {
|
|
56
|
-
result = (result * base) % P
|
|
57
|
-
}
|
|
58
|
-
base = (base * base) % P
|
|
59
|
-
e >>= 1n
|
|
60
|
-
}
|
|
61
|
-
return result
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** The affine sum of two points, `null` the identity. */
|
|
65
|
-
const add = (p, q) => {
|
|
66
|
-
if (p === null) {
|
|
67
|
-
return q
|
|
68
|
-
}
|
|
69
|
-
if (q === null) {
|
|
70
|
-
return p
|
|
71
|
-
}
|
|
72
|
-
if (p.x === q.x) {
|
|
73
|
-
if (mod(p.y + q.y) === 0n) {
|
|
74
|
-
return null
|
|
75
|
-
}
|
|
76
|
-
const l = mod(3n * p.x * p.x - 3n) * inverse(2n * p.y)
|
|
77
|
-
return finish(p, q, mod(l))
|
|
78
|
-
}
|
|
79
|
-
return finish(p, q, mod(mod(q.y - p.y) * inverse(q.x - p.x)))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const finish = (p, q, l) => {
|
|
83
|
-
const x = mod(l * l - p.x - q.x)
|
|
84
|
-
return { x, y: mod(l * (p.x - x) - p.y) }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** `2^n p`. */
|
|
88
|
-
const shift = (p, n) => {
|
|
89
|
-
let q = p
|
|
90
|
-
for (let i = 0; i < n; i++) {
|
|
91
|
-
q = add(q, q)
|
|
92
|
-
}
|
|
93
|
-
return q
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const onCurve = (p) => mod(p.y * p.y) === mod(p.x * p.x * p.x - 3n * p.x + B)
|
|
97
|
-
|
|
98
|
-
/** The eight 32-bit limbs of `a 2^256 mod p`, least significant first. */
|
|
99
|
-
const montgomeryLimbs = (a) => {
|
|
100
|
-
const m = mod(a << 256n)
|
|
101
|
-
const limbs = []
|
|
102
|
-
for (let i = 0n; i < 8n; i++) {
|
|
103
|
-
limbs.push(Number((m >> (32n * i)) & 0xffffffffn))
|
|
104
|
-
}
|
|
105
|
-
return limbs
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const limbs = []
|
|
109
|
-
// The teeth of sub-table c, 2^(4c + 64b) G for b = 0 to 3: sub-table 0's from
|
|
110
|
-
// G, each later one's four doublings past the one before.
|
|
111
|
-
let teeth = []
|
|
112
|
-
for (let b = 0; b < TEETH; b++) {
|
|
113
|
-
teeth.push(shift(G, SPACING * b))
|
|
114
|
-
}
|
|
115
|
-
for (let c = 0; c < SUBTABLES; c++) {
|
|
116
|
-
if (c > 0) {
|
|
117
|
-
teeth = teeth.map((t) => shift(t, 4))
|
|
118
|
-
}
|
|
119
|
-
for (let j = 1; j < 1 << TEETH; j++) {
|
|
120
|
-
let point = null
|
|
121
|
-
for (let b = 0; b < TEETH; b++) {
|
|
122
|
-
if ((j >> b) & 1) {
|
|
123
|
-
point = add(point, teeth[b])
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (point === null || !onCurve(point)) {
|
|
127
|
-
throw new Error(`gen-p256-table: sub-table ${c}, entry ${j} is not a point of the curve`)
|
|
128
|
-
}
|
|
129
|
-
limbs.push(...montgomeryLimbs(point.x), ...montgomeryLimbs(point.y))
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Biome's layout for an array of numbers at two spaces of indent and 110 columns.
|
|
134
|
-
const PER_LINE = 9
|
|
135
|
-
const lines = []
|
|
136
|
-
for (let i = 0; i < limbs.length; i += PER_LINE) {
|
|
137
|
-
const row = limbs.slice(i, i + PER_LINE).map((l) => `0x${l.toString(16).padStart(8, "0")},`)
|
|
138
|
-
lines.push(` ${row.join(" ")}`)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const BEGIN = "// gen-p256-table:begin"
|
|
142
|
-
const END = "// gen-p256-table:end"
|
|
143
|
-
const region = [
|
|
144
|
-
`${BEGIN} -- generated by scripts/gen-p256-table.mjs; edit that, not this.`,
|
|
145
|
-
"/**",
|
|
146
|
-
" * The fixed-base comb table `p256BaseMult` reads: sub-table `c` (0 to 15),",
|
|
147
|
-
" * entry `j` (1 to 15) at limb `(15c + j - 1) * 16`, is the affine point",
|
|
148
|
-
" * (j_0 + j_1 2^64 + j_2 2^128 + j_3 2^192) 2^(4c) G, `j_b` bit `b` of `j`, as",
|
|
149
|
-
" * X then Y in the Montgomery domain. Public: a function of G alone.",
|
|
150
|
-
" */",
|
|
151
|
-
"const p256BaseTable = (): u32[] => [",
|
|
152
|
-
...lines,
|
|
153
|
-
"]",
|
|
154
|
-
END,
|
|
155
|
-
].join("\n")
|
|
156
|
-
|
|
157
|
-
const source = fs.readFileSync(target, "utf8")
|
|
158
|
-
const from = source.indexOf(BEGIN)
|
|
159
|
-
const to = source.indexOf(END)
|
|
160
|
-
if (from < 0 || to < from) {
|
|
161
|
-
console.error(`gen-p256-table: no ${BEGIN} ... ${END} region in ${path.relative(root, target)}`)
|
|
162
|
-
process.exit(1)
|
|
163
|
-
}
|
|
164
|
-
const next = source.slice(0, from) + region + source.slice(to + END.length)
|
|
165
|
-
|
|
166
|
-
if (process.argv.includes("--check")) {
|
|
167
|
-
if (next !== source) {
|
|
168
|
-
console.error(
|
|
169
|
-
`gen-p256-table: the table in ${path.relative(root, target)} is not what the generator writes; run node scripts/gen-p256-table.mjs`
|
|
170
|
-
)
|
|
171
|
-
process.exit(1)
|
|
172
|
-
}
|
|
173
|
-
console.log(`gen-p256-table: ${limbs.length} limbs, as generated`)
|
|
174
|
-
} else {
|
|
175
|
-
fs.writeFileSync(target, next)
|
|
176
|
-
console.log(`gen-p256-table: wrote ${limbs.length} limbs to ${path.relative(root, target)}`)
|
|
177
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Regenerate the power-of-ten table `runtime/runtime-text.c` uses for Zmij.
|
|
3
|
-
|
|
4
|
-
python3 scripts/gen-pow10-table.py
|
|
5
|
-
|
|
6
|
-
Prints the C to stdout; paste it over the `NISH_POW10_SIG` definition. The
|
|
7
|
-
point of having this in the tree is that the ~10 KB of constants in the
|
|
8
|
-
runtime are *derived*, with exact integer arithmetic, rather than transcribed
|
|
9
|
-
from somewhere -- so a reader can check them rather than trust them. See
|
|
10
|
-
docs/wp15-performance.md section 7a.
|
|
11
|
-
|
|
12
|
-
Each row is the 128-bit significand of 10^k, normalised so its top bit is set
|
|
13
|
-
and rounded *down*, as `{ hi, lo }`: the convention of Zmij's
|
|
14
|
-
`pow10_significands` (zmij.c, Copyright (c) 2025 - present, Victor Zverovich,
|
|
15
|
-
used under the Boost Software License, Version 1.0; runtime/LICENSE-zmij has
|
|
16
|
-
the text and THIRD_PARTY_NOTICES.md the entry). Upstream ships 10^-307 to
|
|
17
|
-
10^341 because its fixed-precision paths read further out; the shortest-digits
|
|
18
|
-
path, the only one ported, reaches fewer, and the range below is computed from
|
|
19
|
-
the same exponent arithmetic `nish_shortest_digits` does rather than copied.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
M = (1 << 64) - 1
|
|
23
|
-
EXP_OFFSET = 1075 # a double is sig * 2^(raw_exp - 1075)
|
|
24
|
-
EXTRA_SHIFT = 6
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def dec_exp_of(bin_exp, regular):
|
|
28
|
-
# compute_dec_exp: floor(log10(2^bin_exp)), or of 3/4 of it when irregular.
|
|
29
|
-
# Python's >> floors like the arithmetic shift clang emits for C's int.
|
|
30
|
-
return (bin_exp * 315653 - (0 if regular else 131072)) >> 20
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def exp_shift(bin_exp, dec_exp):
|
|
34
|
-
# compute_exp_shift(bin_exp, dec_exp + 1) + extra_shift, as the runtime does it.
|
|
35
|
-
return bin_exp + ((-(dec_exp + 1) * 217707) >> 16) + 1 + EXTRA_SHIFT
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def significand(k):
|
|
39
|
-
# floor(10^k * 2^s) for the s that leaves exactly 128 bits.
|
|
40
|
-
if k >= 0:
|
|
41
|
-
p = 10**k
|
|
42
|
-
s = 128 - p.bit_length()
|
|
43
|
-
v = p << s if s >= 0 else p >> -s
|
|
44
|
-
else:
|
|
45
|
-
p = 10**-k
|
|
46
|
-
# 2^(127 + b) / 10^-k with b the bit length of 10^-k lands in [2^127, 2^128).
|
|
47
|
-
v = (1 << (127 + p.bit_length())) // p
|
|
48
|
-
assert v >> 127 == 1, k
|
|
49
|
-
return v
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
# Every power the shortest path reads: raw_exp 1 (the subnormals and 2^-1022,
|
|
53
|
-
# which share its spacing) to 2046, the irregular branch only from 2 up.
|
|
54
|
-
reach = set()
|
|
55
|
-
for raw_exp in range(1, 2047):
|
|
56
|
-
bin_exp = raw_exp - EXP_OFFSET
|
|
57
|
-
for regular in (True, False) if raw_exp > 1 else (True,):
|
|
58
|
-
d = dec_exp_of(bin_exp, regular)
|
|
59
|
-
shift = exp_shift(bin_exp, d)
|
|
60
|
-
# `bin_sig << shift` must keep a 53-bit significand, and the half-ulp
|
|
61
|
-
# shift `extra_shift + 1 - shift` must be a legal shift count.
|
|
62
|
-
assert 0 <= shift and 53 + shift <= 64, (raw_exp, shift)
|
|
63
|
-
assert 0 <= EXTRA_SHIFT + 1 - shift < 64, (raw_exp, shift)
|
|
64
|
-
reach.add(-d - 1)
|
|
65
|
-
lo, hi = min(reach), max(reach)
|
|
66
|
-
assert reach == set(range(lo, hi + 1))
|
|
67
|
-
assert (lo, hi) == (-293, 323), (lo, hi)
|
|
68
|
-
|
|
69
|
-
# Spot checks against values a reader can do by hand.
|
|
70
|
-
assert significand(0) == 1 << 127
|
|
71
|
-
assert significand(-1) == int("cc" * 16, 16)
|
|
72
|
-
assert significand(1) == 0xA << 124
|
|
73
|
-
|
|
74
|
-
print(f"/* Generated by scripts/gen-pow10-table.py; do not hand-edit. 10^{lo} to 10^{hi}. */")
|
|
75
|
-
print(f"#define NISH_POW10_MIN ({lo})")
|
|
76
|
-
print(f"static const uint64_t NISH_POW10_SIG[{hi - lo + 1}][2] = {{")
|
|
77
|
-
for k in range(lo, hi + 1):
|
|
78
|
-
v = significand(k)
|
|
79
|
-
print(f" {{ 0x{v >> 64:016x}u, 0x{v & M:016x}u }},")
|
|
80
|
-
print("};")
|