Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ i want to implement those API's as well.
- [x] AbortController
- [x] AbortSignal

- [ ] Crypto
- [ ] CryptoKey
- [x] Crypto
- [x] CryptoKey

- [x] Blob
- [ ] ByteLengthQueuingStrategy
Expand All @@ -85,25 +85,25 @@ i want to implement those API's as well.
- [x] async
- [x] sync

- [ ] FormData
- [ ] Headers
- [x] FormData
- [x] Headers
- [ ] ReadableByteStreamController
- [ ] ReadableStream
- [ ] ReadableStreamBYOBReader
- [ ] ReadableStreamBYOBRequest
- [ ] ReadableStreamDefaultController
- [ ] ReadableStreamDefaultReader
- [ ] Request
- [ ] Response
- [ ] SubtleCrypto
- [ ] TextDecoder
- [x] Request
- [x] Response
- [x] SubtleCrypto
- [x] TextDecoder
- [ ] TextDecoderStream
- [ ] TextEncoder
- [x] TextEncoder
- [ ] TextEncoderStream
- [ ] TransformStream
- [ ] TransformStreamDefaultController
- [ ] URL
- [ ] URLSearchParams
- [x] URL
- [x] URLSearchParams
- [ ] WritableStream
- [ ] WritableStreamDefaultController

Expand All @@ -115,7 +115,7 @@ i want to implement those API's as well.
- [ ] WebAssembly.Table

Global methods / properties:
- [ ] globalThis
- [x] globalThis
- [x] globalThis.atob()
- [x] globalThis.btoa()
- [x] globalThis.console
Expand All @@ -124,15 +124,15 @@ Global methods / properties:
- and also easier to implement OTEL later
- TODO: console.span(level: "info" | "debug" | "warn" | "error" | "trace", name: string, fn: (span) => void)
- TODO: console.table
- [ ] globalThis.crypto
- [x] globalThis.crypto
- [x] globalThis.fetch()
- [x] globalThis.navigator.userAgent
- [ ] globalThis.performance.now()
- [ ] globalThis.performance.timeOrigin
- [x] globalThis.performance.now()
- [x] globalThis.performance.timeOrigin
- [x] globalThis.queueMicrotask()
- [x] globalThis.setTimeout() / globalThis.clearTimeout()
- [x] globalThis.setInterval() / globalThis.clearInterval()
- [ ] globalThis.structuredClone()
- [x] globalThis.structuredClone()

- [ ] WASM
- [ ] globalThis.WebAssembly.compile()
Expand Down
69 changes: 67 additions & 2 deletions modules/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ tracing = "0.1.44"
itoa = "1.0.15"
ryu = "1.0.20"
simd-json = "0.17.0"
rand = "0.9.2"
rand_core = { version = "=0.10.0-rc-2" }
rand = { version = "0.10.0-rc.2", features = [
"std",
"std_rng",
"thread_rng",
], default-features = false }
tokio = { version = "1", features = ["full"], optional = true }

# intl
chrono = { version = "0.4", features = ["std", "clock"], default-features = false, optional = true }
chrono = { version = "0.4", features = [
"std",
"clock",
], default-features = false, optional = true }
chrono-tz = { version = "0.10", default-features = false, optional = true }
iana-time-zone = { version = "0.1", optional = true }

Expand Down Expand Up @@ -71,6 +79,61 @@ flate2 = { version = "1", features = ["miniz_oxide"], default-features = false }
zstd = { version = "0.13", default-features = false }


# crypto
crc32c = { version = "0.6", default-features = false }
crc32fast = { version = "1", default-features = false }
aes = { version = "0.9.0-rc.2" }
aes-gcm = { version = "0.11.0-rc.2", features = [
"alloc",
], default-features = false }
aes-kw = { version = "0.3.0-rc.1", features = [
"oid",
], default-features = false }
cbc = { version = "0.2.0-rc.2", features = ["alloc"] }
const-oid = { version = "0.10", features = ["db"], default-features = false }
ctr = { version = "0.10.0-rc.2", default-features = false }
der = { version = "0.8.0-rc.10", features = [
"derive",
"alloc",
], default-features = false }
ecdsa = { version = "0.17.0-rc.9", default-features = false }
elliptic-curve = { version = "0.14.0-rc.17", features = [
"alloc",
], default-features = false }
md-5 = { version = "0.11.0-rc.3", default-features = false }
rsa = { version = "0.10.0-rc.10", features = [
"std",
"sha2",
"encoding",
"os_rng",
], default-features = false }
p256 = { version = "0.14.0-rc.1", features = [
"ecdh",
"ecdsa",
"pkcs8",
], default-features = false }
p384 = { version = "0.14.0-rc.1", features = [
"ecdh",
"ecdsa",
"pkcs8",
], default-features = false }
p521 = { version = "0.14.0-rc.1", features = [
"ecdh",
"ecdsa",
"pkcs8",
], default-features = false }
pkcs8 = { version = "0.11.0-rc.8", default-features = false, features = [
"alloc",
] }
spki = { version = "0.8.0-rc.4", features = [
"alloc",
], default-features = false }
x25519-dalek = { version = "3.0.0-pre.3", features = [
"static_secrets",
"zeroize",
], default-features = false }


[features]
default = [
"event",
Expand All @@ -84,8 +147,10 @@ default = [
"url",
"fetch",
"intl",
"crypto",
]

crypto = []
event = []
abort = ["event"]
console = []
Expand Down
69 changes: 69 additions & 0 deletions modules/src/crypto/crc32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use std::hash::Hasher;

use crate::utils::bytes::ObjectBytes;
use crc32c::Crc32cHasher;
use rsquickjs::{prelude::This, Class, Ctx, Result};

#[rsquickjs::class]
#[derive(rsquickjs::class::Trace, rsquickjs::JsLifetime)]
pub struct Crc32c {
#[qjs(skip_trace)]
hasher: crc32c::Crc32cHasher,
}

#[rsquickjs::methods]
impl Crc32c {
#[qjs(constructor)]
fn new() -> Self {
Self {
hasher: Crc32cHasher::default(),
}
}

#[qjs(rename = "digest")]
fn crc32c_digest(&self) -> u64 {
self.hasher.finish()
}

#[qjs(rename = "update")]
fn crc32c_update<'js>(
this: This<Class<'js, Self>>,
ctx: Ctx<'js>,
bytes: ObjectBytes<'js>,
) -> Result<Class<'js, Self>> {
this.0.borrow_mut().hasher.write(bytes.as_bytes(&ctx)?);
Ok(this.0)
}
}

#[rsquickjs::class]
#[derive(rsquickjs::class::Trace, rsquickjs::JsLifetime)]
pub struct Crc32 {
#[qjs(skip_trace)]
hasher: crc32fast::Hasher,
}

#[rsquickjs::methods]
impl Crc32 {
#[qjs(constructor)]
fn new() -> Self {
Self {
hasher: crc32fast::Hasher::new(),
}
}

#[qjs(rename = "digest")]
fn crc32_digest(&self) -> u64 {
self.hasher.finish()
}

#[qjs(rename = "update")]
fn crc32_update<'js>(
this: This<Class<'js, Self>>,
ctx: Ctx<'js>,
bytes: ObjectBytes<'js>,
) -> Result<Class<'js, Self>> {
this.0.borrow_mut().hasher.write(bytes.as_bytes(&ctx)?);
Ok(this.0)
}
}
43 changes: 43 additions & 0 deletions modules/src/crypto/md5_hash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::utils::bytes::{bytes_to_typed_array, ObjectBytes};
use md5::{Digest as Md5Digest, Md5 as MdHasher};
use rsquickjs::{function::Opt, prelude::This, Class, Ctx, Result, Value};

use super::encoded_bytes;

#[rsquickjs::class]
#[derive(rsquickjs::class::Trace, rsquickjs::JsLifetime)]
pub struct Md5 {
#[qjs(skip_trace)]
hasher: MdHasher,
}

#[rsquickjs::methods]
impl Md5 {
#[qjs(constructor)]
fn new() -> Self {
Self {
hasher: MdHasher::new(),
}
}

#[qjs(rename = "digest")]
fn md5_digest<'js>(&self, ctx: Ctx<'js>, encoding: Opt<String>) -> Result<Value<'js>> {
let digest = self.hasher.clone().finalize();
let bytes: &[u8] = digest.as_ref();

match encoding.0 {
Some(encoding) => encoded_bytes(ctx, bytes, &encoding),
None => bytes_to_typed_array(ctx, bytes),
}
}

#[qjs(rename = "update")]
fn md5_update<'js>(
this: This<Class<'js, Self>>,
ctx: Ctx<'js>,
bytes: ObjectBytes<'js>,
) -> Result<Class<'js, Self>> {
this.0.borrow_mut().hasher.update(bytes.as_bytes(&ctx)?);
Ok(this.0)
}
}
Loading
Loading