Skip to content

Conversation

@Gozala
Copy link
Contributor

@Gozala Gozala commented Dec 19, 2025

Description

This PR fixes WASM compilation errors and adds proper cross-platform time
support using web-time.

Problem

The crate had WASM-specific code using js_sys::Date, wasm_bindgen, and
JsError but:

  1. These dependencies weren't declared in Cargo.toml
  2. std::time::SystemTime::now() panics on WASM with "time not implemented
    on this platform

Changes

Add missing WASM dependencies (ucan/Cargo.toml)

  • Added js-sys, wasm-bindgen, and web-time as wasm32 target dependencies

Fix cross-platform time support (ucan/src/time/timestamp.rs,
ucan/src/time/error.rs)

  • Use web-time crate for SystemTime, Duration, and UNIX_EPOCH on WASM
  • Use std::time on native platforms

Fix WASM Timestamp methods (ucan/src/time/timestamp.rs)

  • Removed #[wasm_bindgen] attribute from the WASM impl block (was causing
    trait bound errors)
  • Fixed self.time → self.0 bug in to_date()
  • Changed from_date() return type from Result<Timestamp, JsError> to
    Result<Timestamp, OutOfRangeError>

@Gozala Gozala requested a review from expede as a code owner December 19, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant