Stdlib: Secure random bytes and UUID generation #245

Closed
opened 2026-01-12 02:36:35 +00:00 by navicore · 1 comment
navicore commented 2026-01-12 02:36:35 +00:00 (Migrated from github.com)

Summary

Add secure random number generation and UUID v4 support for tokens, session IDs, nonces, and unique identifiers.

Proposed API

# Generate cryptographically secure random bytes
32 crypto.random-bytes    # ( n -- Bytes ) n random bytes

# Generate UUID v4
crypto.uuid4              # ( -- String ) "550e8400-e29b-41d4-a716-446655440000"

# Convenience: random hex token
32 crypto.random-hex      # ( n -- String ) n random bytes as 2n hex chars

Implementation

FFI wrappers around:

  • rand crate with OsRng for cryptographic randomness
  • uuid crate for UUID generation

Estimated effort: Few hours

Deliverables Checklist

  • Runtime builtins in crates/runtime/src/crypto.rs
  • Unit tests for each function
  • Integration tests in tests/integration/src/test-random.seq
  • LSP support: signatures in BUILTIN_SIGNATURES, docs in BUILTIN_DOCS
  • Example: examples/crypto/token-generator.seq
  • Update docs/BATTERIES_INCLUDED.md status

Use Cases Unlocked

  • Session token generation
  • CSRF tokens
  • Nonces for crypto operations
  • Unique identifiers for records
  • Salts for password hashing

References

  • See docs/BATTERIES_INCLUDED.md Priority 4: Cryptography
## Summary Add secure random number generation and UUID v4 support for tokens, session IDs, nonces, and unique identifiers. ## Proposed API ```seq # Generate cryptographically secure random bytes 32 crypto.random-bytes # ( n -- Bytes ) n random bytes # Generate UUID v4 crypto.uuid4 # ( -- String ) "550e8400-e29b-41d4-a716-446655440000" # Convenience: random hex token 32 crypto.random-hex # ( n -- String ) n random bytes as 2n hex chars ``` ## Implementation FFI wrappers around: - `rand` crate with `OsRng` for cryptographic randomness - `uuid` crate for UUID generation Estimated effort: Few hours ## Deliverables Checklist - [ ] Runtime builtins in `crates/runtime/src/crypto.rs` - [ ] Unit tests for each function - [ ] Integration tests in `tests/integration/src/test-random.seq` - [ ] LSP support: signatures in `BUILTIN_SIGNATURES`, docs in `BUILTIN_DOCS` - [ ] Example: `examples/crypto/token-generator.seq` - [ ] Update `docs/BATTERIES_INCLUDED.md` status ## Use Cases Unlocked - Session token generation - CSRF tokens - Nonces for crypto operations - Unique identifiers for records - Salts for password hashing ## References - See `docs/BATTERIES_INCLUDED.md` Priority 4: Cryptography
navicore commented 2026-01-12 03:46:18 +00:00 (Migrated from github.com)
https://github.com/navicore/patch-seq/pull/254
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-seq#245
No description provided.