@amritk/nish-aarch64-linux 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/INSTALL.md +79 -133
- package/bin/nish +0 -0
- package/docs/AI.md +112 -33
- package/package.json +1 -1
- 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/std/array.ts
CHANGED
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
* };
|
|
11
11
|
*
|
|
12
12
|
* **A program does not need to import this module.** A `.map(...)`,
|
|
13
|
-
* `.filter(...)`, `.some(...)`, `.every(...)`, `.findIndex(...)
|
|
14
|
-
* `.slice(...)` call on an array is what loads it (the checker's
|
|
13
|
+
* `.filter(...)`, `.some(...)`, `.every(...)`, `.findIndex(...)`,
|
|
14
|
+
* `.forEach(...)` or `.slice(...)` call on an array is what loads it (the checker's
|
|
15
15
|
* `importArrayMethods`), and the checker routes the call to the template here
|
|
16
16
|
* that matches it: `xs.map(f)` is `map(xs, f)` when `f` takes one parameter
|
|
17
17
|
* and `mapIndexed(xs, f)` when it takes two. `f` is a compile-time function
|
|
18
18
|
* parameter, so each callback is an instantiation of its own whose body calls
|
|
19
19
|
* it directly — there is no function pointer, and importing a template here
|
|
20
20
|
* by name and calling it gives the same code as the method. Under Node,
|
|
21
|
-
* `--emit-ts` leaves `map`, `filter`, `some`, `every
|
|
21
|
+
* `--emit-ts` leaves `map`, `filter`, `some`, `every`, `findIndex` and
|
|
22
|
+
* `forEach` as the
|
|
22
23
|
* platform's own `Array.prototype` methods, writes `slice` as the runtime's
|
|
23
24
|
* checked `sliceArray`, and copies an answer that holds records inline with
|
|
24
25
|
* `copyRecords`, so nothing here runs there.
|
|
@@ -219,6 +220,38 @@ export const findIndexIndexed = <T>(xs: readonly T[], pred: (x: T, i: number) =>
|
|
|
219
220
|
return -1
|
|
220
221
|
}
|
|
221
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Calls `f` with each element of `xs`, in order: what `xs.forEach(f)`
|
|
225
|
+
* compiles to when `f` takes one parameter. The walk stops at the length the
|
|
226
|
+
* array had when the call began, so an element the callback pushes is not
|
|
227
|
+
* visited, and at the current length, so one it pops is not either, as
|
|
228
|
+
* `Array.prototype.forEach` does.
|
|
229
|
+
*
|
|
230
|
+
* @param xs the array read; the callback may change it.
|
|
231
|
+
* @param f called once per element, in order.
|
|
232
|
+
*/
|
|
233
|
+
export const forEach = <T>(xs: readonly T[], f: (x: T) => void): void => {
|
|
234
|
+
const n = xs.length
|
|
235
|
+
for (let i: number = 0; i < n && i < xs.length; i++) {
|
|
236
|
+
f(xs[i])
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Calls `f` with each element of `xs` and its index, in order: what
|
|
242
|
+
* `xs.forEach(f)` compiles to when `f` takes two parameters. The walk stops
|
|
243
|
+
* where `forEach`'s does.
|
|
244
|
+
*
|
|
245
|
+
* @param xs the array read; the callback may change it.
|
|
246
|
+
* @param f called once per element, in order, with the element and its index.
|
|
247
|
+
*/
|
|
248
|
+
export const forEachIndexed = <T>(xs: readonly T[], f: (x: T, i: number) => void): void => {
|
|
249
|
+
const n = xs.length
|
|
250
|
+
for (let i: number = 0; i < n && i < xs.length; i++) {
|
|
251
|
+
f(xs[i], i)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
222
255
|
/**
|
|
223
256
|
* A copy of `xs[start..end)` in a new array: what `xs.slice(start, end)`
|
|
224
257
|
* compiles to, with string `slice`'s rule. The range must satisfy
|
package/std/collections.ts
CHANGED
|
@@ -688,3 +688,54 @@ export class Set<T> {
|
|
|
688
688
|
* of an earlier function records.
|
|
689
689
|
*/
|
|
690
690
|
const storedKey = <K>(key: K): K => key
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Calls `f` with the value and the key of each entry of `m`, in insertion
|
|
694
|
+
* order: what `m.forEach(f)` compiles to when `f` takes two parameters. It is
|
|
695
|
+
* the walk a `for...of` over `m.keys()` makes, and reads the value from the
|
|
696
|
+
* entry the walk is on, so each entry costs no probe. An entry the callback
|
|
697
|
+
* adds is visited and one it deletes is not, as `Map.prototype.forEach` does.
|
|
698
|
+
* Placed after `storedKey` so that no earlier line moved.
|
|
699
|
+
*
|
|
700
|
+
* @param m the table walked; the callback may change it.
|
|
701
|
+
* @param f called once per live entry, with its value and then its key.
|
|
702
|
+
*/
|
|
703
|
+
export const forEachEntry = <K, V>(m: Map<K, V>, f: (value: V, key: K) => void): void => {
|
|
704
|
+
m.walkOpen()
|
|
705
|
+
for (let i: i32 = m.walkNext(0); i >= 0; i = m.walkNext(i + 1)) {
|
|
706
|
+
f(m.valueAt(i), m.keyAt(i))
|
|
707
|
+
}
|
|
708
|
+
m.walkClose()
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Calls `f` with the value of each entry of `m`, in insertion order: what
|
|
713
|
+
* `m.forEach(f)` compiles to when `f` takes one parameter. The walk is
|
|
714
|
+
* `forEachEntry`'s.
|
|
715
|
+
*
|
|
716
|
+
* @param m the table walked; the callback may change it.
|
|
717
|
+
* @param f called once per live entry, with its value.
|
|
718
|
+
*/
|
|
719
|
+
export const forEachValue = <K, V>(m: Map<K, V>, f: (value: V) => void): void => {
|
|
720
|
+
m.walkOpen()
|
|
721
|
+
for (let i: i32 = m.walkNext(0); i >= 0; i = m.walkNext(i + 1)) {
|
|
722
|
+
f(m.valueAt(i))
|
|
723
|
+
}
|
|
724
|
+
m.walkClose()
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Calls `f` with each element of `s`, in insertion order: what `s.forEach(f)`
|
|
729
|
+
* compiles to. The walk is a `for...of` over `s`, with its rule for elements
|
|
730
|
+
* the callback adds or deletes.
|
|
731
|
+
*
|
|
732
|
+
* @param s the set walked; the callback may change it.
|
|
733
|
+
* @param f called once per live element.
|
|
734
|
+
*/
|
|
735
|
+
export const forEachElement = <T>(s: Set<T>, f: (value: T) => void): void => {
|
|
736
|
+
s.walkOpen()
|
|
737
|
+
for (let i: i32 = s.walkNext(0); i >= 0; i = s.walkNext(i + 1)) {
|
|
738
|
+
f(s.keyAt(i))
|
|
739
|
+
}
|
|
740
|
+
s.walkClose()
|
|
741
|
+
}
|
package/std/crypto/hmac.ts
CHANGED
|
@@ -152,6 +152,10 @@ const hmacCheckKey = (key: u8[]): void => {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
+
/** Whether `[off, off + len)` is a window inside an array of `length` elements. */
|
|
156
|
+
const hmacWindowFits = (length: i32, off: i32, len: i32): boolean =>
|
|
157
|
+
off >= 0 && len >= 0 && off <= length - len
|
|
158
|
+
|
|
155
159
|
/**
|
|
156
160
|
* Keys `inner` with `k XOR ipad` and `outer` with `k XOR opad`, `k` no longer
|
|
157
161
|
* than SHA-256's block, in one block that is rewritten between the two and
|
|
@@ -250,17 +254,26 @@ export class HmacSha256 {
|
|
|
250
254
|
inner: Sha256
|
|
251
255
|
/** H(K XOR opad, …), fed the key block in the constructor and the inner digest last. */
|
|
252
256
|
outer: Sha256
|
|
257
|
+
/**
|
|
258
|
+
* Where `digestInto` puts the inner digest on its way into `outer`, so that
|
|
259
|
+
* it allocates nothing; zero except during that call, which wipes it.
|
|
260
|
+
*/
|
|
261
|
+
innerDigest: u8[]
|
|
253
262
|
|
|
254
263
|
/**
|
|
255
264
|
* Keys the computation. A key longer than 64 bytes is replaced by its
|
|
256
265
|
* SHA-256 (RFC 2104 §2), which is wiped once used (`hmacKeySha256`).
|
|
257
266
|
*
|
|
267
|
+
* Besides the two hashers it allocates the 32-byte `innerDigest` buffer
|
|
268
|
+
* that every `digest` and `digestInto` reuses.
|
|
269
|
+
*
|
|
258
270
|
* @param key The secret key; it is read, not kept, and the caller still
|
|
259
271
|
* wipes it.
|
|
260
272
|
*/
|
|
261
273
|
constructor(key: u8[]) {
|
|
262
274
|
this.inner = new Sha256()
|
|
263
275
|
this.outer = new Sha256()
|
|
276
|
+
this.innerDigest = new Array<u8>(SHA256_SIZE)
|
|
264
277
|
hmacKeySha256(this.inner, this.outer, key)
|
|
265
278
|
}
|
|
266
279
|
|
|
@@ -277,18 +290,36 @@ export class HmacSha256 {
|
|
|
277
290
|
}
|
|
278
291
|
|
|
279
292
|
/**
|
|
280
|
-
* Ends the computation and wipes both hashers.
|
|
293
|
+
* Ends the computation and wipes both hashers and the inner digest. The tag
|
|
294
|
+
* is the one allocation.
|
|
281
295
|
*
|
|
282
296
|
* @returns A fresh 32-byte tag, which the caller owns.
|
|
283
297
|
*/
|
|
284
298
|
digest(): u8[] {
|
|
285
|
-
const
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
299
|
+
const tag: u8[] = new Array<u8>(SHA256_SIZE)
|
|
300
|
+
this.digestInto(tag, HMAC_FROM)
|
|
301
|
+
return tag
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Writes the 32-byte tag at `out[at .. at + 32)`, ends the computation and
|
|
306
|
+
* wipes both hashers and the inner digest, with nothing allocated. A window
|
|
307
|
+
* outside `out` panics before anything is written; so does a second
|
|
308
|
+
* `digest` or `digestInto`, in the inner hasher.
|
|
309
|
+
*
|
|
310
|
+
* @param out The caller's array the tag is written into.
|
|
311
|
+
* @param at Where the 32 tag bytes start in `out`.
|
|
312
|
+
*/
|
|
313
|
+
digestInto(out: u8[], at: i32): void {
|
|
314
|
+
if (!hmacWindowFits(toI32(out.length), at, SHA256_SIZE)) {
|
|
315
|
+
panic("HmacSha256: the tag window is outside its array")
|
|
316
|
+
}
|
|
317
|
+
this.inner.digestInto(this.innerDigest, HMAC_FROM)
|
|
318
|
+
this.outer.update(this.innerDigest, HMAC_FROM, SHA256_SIZE)
|
|
319
|
+
wipe(this.innerDigest)
|
|
320
|
+
this.outer.digestInto(out, at)
|
|
289
321
|
hmacWipeSha256(this.inner)
|
|
290
322
|
hmacWipeSha256(this.outer)
|
|
291
|
-
return tag
|
|
292
323
|
}
|
|
293
324
|
}
|
|
294
325
|
|
|
@@ -580,10 +611,6 @@ export const hmacCopySha384 = (from: Sha384, to: Sha384): void => {
|
|
|
580
611
|
to.engine.finished = from.engine.finished
|
|
581
612
|
}
|
|
582
613
|
|
|
583
|
-
/** Whether `[off, off + len)` is a window inside an array of `length` elements. */
|
|
584
|
-
const hmacWindowFits = (length: i32, off: i32, len: i32): boolean =>
|
|
585
|
-
off >= 0 && len >= 0 && off <= length - len
|
|
586
|
-
|
|
587
614
|
/**
|
|
588
615
|
* HMAC-SHA-256 over hashers the caller owns: allocate one, then for each tag
|
|
589
616
|
* `begin` with the key, `update` with the message, and `finishInto` the
|