nish 0.50.0 → 0.51.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 (53) hide show
  1. package/docs/AI.md +4 -1
  2. package/package.json +5 -5
  3. package/runtime/nish.d.ts +82 -2
  4. package/runtime/nish.h +5 -0
  5. package/runtime/runtime-host.c +21 -5
  6. package/std/README.md +7 -7
  7. package/std/base64.ts +61 -95
  8. package/std/bytes.ts +6 -4
  9. package/std/cli-args.ts +150 -107
  10. package/std/compress/checksum.ts +68 -10
  11. package/std/compress/deflate.ts +193 -100
  12. package/std/compress/gzip.ts +124 -49
  13. package/std/compress/zlib.ts +57 -15
  14. package/std/crypto/aes.ts +51 -9
  15. package/std/crypto/ed25519.ts +12 -10
  16. package/std/crypto/hkdf.ts +405 -283
  17. package/std/crypto/hmac.ts +483 -148
  18. package/std/crypto/jwt.ts +19 -21
  19. package/std/crypto/p256.ts +5 -7
  20. package/std/crypto/pki-roots.ts +28 -8
  21. package/std/crypto/rsa-sign.ts +5 -2
  22. package/std/crypto/sha256.ts +81 -26
  23. package/std/crypto/sha512.ts +135 -49
  24. package/std/json-value.ts +14 -15
  25. package/std/net/buffer-pool.ts +25 -14
  26. package/std/net/fetch.ts +108 -27
  27. package/std/net/handler.ts +11 -22
  28. package/std/net/hpack.ts +38 -19
  29. package/std/net/http-compress.ts +21 -12
  30. package/std/net/http-server.ts +9 -4
  31. package/std/net/http1-client-codec.ts +22 -15
  32. package/std/net/http1-codec.ts +37 -36
  33. package/std/net/http3-server.ts +127 -45
  34. package/std/net/http3.ts +99 -50
  35. package/std/net/postgres-async.ts +5 -10
  36. package/std/net/qpack.ts +83 -17
  37. package/std/net/quic-listener.ts +42 -27
  38. package/std/net/quic-packet.ts +91 -50
  39. package/std/net/quic-stream.ts +29 -22
  40. package/std/net/quic.ts +48 -23
  41. package/std/net/static.ts +5 -3
  42. package/std/net/tls/client.ts +81 -34
  43. package/std/net/tls/codec.ts +3 -4
  44. package/std/net/tls/record.ts +54 -22
  45. package/std/net/tls/schedule.ts +339 -149
  46. package/std/net/tls.ts +42 -12
  47. package/std/net/upstream.ts +18 -19
  48. package/std/net/url.ts +78 -21
  49. package/std/net/websocket.ts +3 -11
  50. package/std/net/webtransport.ts +95 -21
  51. package/std/raster.ts +12 -2
  52. package/std/term-pixels.ts +18 -2
  53. package/std/text.ts +5 -5
@@ -117,9 +117,6 @@ export const ED25519_PUBLIC_KEY_SIZE: i32 = 32
117
117
  /** The length in bytes of a signature, `R || S`. */
118
118
  export const ED25519_SIGNATURE_SIZE: i32 = 64
119
119
 
120
- /** Where a method call starts reading an array: its first byte. */
121
- const ED25519_FROM: i32 = 0
122
-
123
120
  /** Where the prefix starts in the seed's hash, and how long R, A and a scalar are. */
124
121
  const ED25519_HALF: i32 = 32
125
122
 
@@ -763,7 +760,8 @@ const ed25519ScalarCanonical = (s: u8[]): boolean => {
763
760
  */
764
761
  const ed25519Expand = (seed: u8[]): u8[] => {
765
762
  const hasher = new Sha512()
766
- hasher.update(seed, ED25519_FROM, ED25519_SEED_SIZE)
763
+ // The whole seed: both callers have checked it is ED25519_SEED_SIZE bytes.
764
+ hasher.engine.absorbWhole(seed)
767
765
  const h: u8[] = hasher.digest()
768
766
  ed25519WipeHasher(hasher)
769
767
  // SHA-512's 64 bytes, as a literal the prover reads for h[0] and h[31].
@@ -778,9 +776,11 @@ const ed25519Expand = (seed: u8[]): u8[] => {
778
776
  /** k = SHA-512(R || A || M) mod L (§5.1.6 step 4, §5.1.7 step 2); public. */
779
777
  const ed25519Challenge = (r: u8[], pub: u8[], msg: u8[]): u8[] => {
780
778
  const hasher = new Sha512()
781
- hasher.update(r, ED25519_FROM, ED25519_HALF)
782
- hasher.update(pub, ED25519_FROM, ED25519_HALF)
783
- hasher.update(msg, ED25519_FROM, toI32(msg.length))
779
+ // Each array whole: R and A are 32 bytes, from `ed25519Encode` or checked
780
+ // by `ed25519Verify`, and the message is the whole message signed.
781
+ hasher.engine.absorbWhole(r)
782
+ hasher.engine.absorbWhole(pub)
783
+ hasher.engine.absorbWhole(msg)
784
784
  const k: u8[] = new Array<u8>(32)
785
785
  ed25519Reduce(k, hasher.digest())
786
786
  return k
@@ -848,8 +848,10 @@ const ed25519SignExposed = (seed: u8[], msg: u8[]): u8[] | null => {
848
848
  const pub: u8[] = ed25519Encode(point, s)
849
849
 
850
850
  const nonceHasher = new Sha512()
851
- nonceHasher.update(h, ED25519_HALF, ED25519_HALF)
852
- nonceHasher.update(msg, ED25519_FROM, toI32(msg.length))
851
+ // The prefix, h's upper half: `false` only for an `h` shorter than its 64
852
+ // bytes, answered as `null` once everything is wiped below.
853
+ const prefixFed: boolean = nonceHasher.update(h, ED25519_HALF, ED25519_HALF)
854
+ nonceHasher.engine.absorbWhole(msg)
853
855
  const nonceWide: u8[] = nonceHasher.digest()
854
856
  ed25519WipeHasher(nonceHasher)
855
857
  const nonce: u8[] = new Array<u8>(32)
@@ -868,7 +870,7 @@ const ed25519SignExposed = (seed: u8[], msg: u8[]): u8[] | null => {
868
870
  ed25519WipeScratch(s)
869
871
 
870
872
  const sig: u8[] = new Array<u8>(64)
871
- if (toI32(r.length) < 32 || toI32(sBytes.length) < 32) {
873
+ if (!prefixFed || toI32(r.length) < 32 || toI32(sBytes.length) < 32) {
872
874
  return null
873
875
  }
874
876
  for (let i: i32 = 0; i < 32; i++) {