Skip to content

Commit a88df22

Browse files
committed
resolved share
1 parent 51ee8ad commit a88df22

12 files changed

Lines changed: 78 additions & 34 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ name = "encrypted_upload_test"
7474
path = "examples/encrypted_upload_test.rs"
7575

7676
[workspace.package]
77-
version = "0.2.10"
77+
version = "0.2.11"
7878
edition = "2021"
7979
license = "MIT OR Apache-2.0"
8080
repository = "https://github.com/functionland/fula-api"

crates/fula-crypto/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ thiserror = { workspace = true }
5757
anyhow = { workspace = true }
5858
zeroize = { version = "1.8", features = ["derive"] }
5959

60+
# WASM-specific dependencies
61+
[target.'cfg(target_arch = "wasm32")'.dependencies]
62+
js-sys = "0.3"
63+
6064
[dev-dependencies]
6165
criterion = { workspace = true }
6266
proptest = { workspace = true }

crates/fula-crypto/src/inbox.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,14 @@ use crate::{
4343
hpke::{EncryptedData, Encryptor, Decryptor, SharePermissions},
4444
keys::{DekKey, KekKeyPair, PublicKey, SecretKey},
4545
sharing::{ShareToken, ShareMode, SnapshotBinding},
46+
time::now_timestamp,
4647
};
4748
use serde::{Deserialize, Serialize};
4849
use std::collections::HashMap;
49-
use std::time::{SystemTime, UNIX_EPOCH};
5050

51-
/// Get current Unix timestamp in seconds
51+
/// Get current Unix timestamp in seconds (WASM-compatible)
5252
fn current_timestamp() -> i64 {
53-
SystemTime::now()
54-
.duration_since(UNIX_EPOCH)
55-
.unwrap_or_default()
56-
.as_secs() as i64
53+
now_timestamp()
5754
}
5855

5956
/// Generate a unique inbox entry ID

crates/fula-crypto/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub mod sharing;
8383
pub mod streaming;
8484
pub mod subtree_keys;
8585
pub mod symmetric;
86+
pub mod time;
8687

8788
pub use chunked::{ChunkedEncoder, ChunkedDecoder, ChunkedFileMetadata, EncryptedChunk, should_use_chunked, CHUNKED_THRESHOLD, VerifiedStreamingDecoder};
8889
#[cfg(feature = "tokio-runtime")]

crates/fula-crypto/src/private_metadata.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
CryptoError, Result,
1616
keys::DekKey,
1717
symmetric::{Aead, Nonce},
18+
time::now_timestamp,
1819
};
1920
use serde::{Deserialize, Serialize};
2021
use std::collections::HashMap;
@@ -45,11 +46,8 @@ pub struct PrivateMetadata {
4546
impl PrivateMetadata {
4647
/// Create new private metadata
4748
pub fn new(original_key: impl Into<String>, actual_size: u64) -> Self {
48-
let now = std::time::SystemTime::now()
49-
.duration_since(std::time::UNIX_EPOCH)
50-
.unwrap_or_default()
51-
.as_secs() as i64;
52-
49+
let now = now_timestamp();
50+
5351
Self {
5452
original_key: original_key.into(),
5553
actual_size,

crates/fula-crypto/src/sharing.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use crate::{
1111
CryptoError, Result,
1212
hpke::{Encryptor, Decryptor, EncryptedData, SharePermissions},
1313
keys::{DekKey, KekKeyPair, PublicKey, SecretKey},
14+
time::now_timestamp,
1415
};
1516
use serde::{Deserialize, Serialize};
1617
use std::collections::HashMap;
17-
use std::time::{SystemTime, UNIX_EPOCH};
1818

1919
// ═══════════════════════════════════════════════════════════════════════════
2020
// SHARE MODE (WNFS-Inspired Snapshot vs Temporal Semantics)
@@ -130,12 +130,11 @@ pub enum SnapshotVerification {
130130
TimestampChanged,
131131
}
132132

133-
/// Get current Unix timestamp in seconds
133+
/// Get current Unix timestamp in seconds (WASM-compatible)
134+
///
135+
/// This function works in both native and WASM environments.
134136
pub fn current_timestamp() -> i64 {
135-
SystemTime::now()
136-
.duration_since(UNIX_EPOCH)
137-
.unwrap_or_default()
138-
.as_secs() as i64
137+
now_timestamp()
139138
}
140139

141140
/// A share token that grants access to encrypted content

crates/fula-crypto/src/subtree_keys.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ use crate::{
3434
keys::DekKey,
3535
hpke::{EncryptedData, Encryptor, Decryptor, SharePermissions},
3636
keys::{KekKeyPair, PublicKey, SecretKey},
37+
time::now_timestamp,
3738
};
3839
use serde::{Deserialize, Serialize};
3940
use std::collections::HashMap;
40-
use std::time::{SystemTime, UNIX_EPOCH};
4141

42-
/// Get current Unix timestamp in seconds
42+
/// Get current Unix timestamp in seconds (WASM-compatible)
4343
fn current_timestamp() -> i64 {
44-
SystemTime::now()
45-
.duration_since(UNIX_EPOCH)
46-
.unwrap_or_default()
47-
.as_secs() as i64
44+
now_timestamp()
4845
}
4946

5047
// ═══════════════════════════════════════════════════════════════════════════

crates/fula-crypto/src/time.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! WASM-compatible time utilities
2+
//!
3+
//! This module provides time functions that work in both native and WASM environments.
4+
//! In WASM, `std::time::SystemTime` is not available, so we use `js_sys::Date::now()` instead.
5+
6+
/// Get current Unix timestamp in seconds (WASM-compatible)
7+
///
8+
/// Returns the current time as seconds since the Unix epoch.
9+
/// Works in both native Rust and WASM environments.
10+
#[cfg(target_arch = "wasm32")]
11+
pub fn now_timestamp() -> i64 {
12+
(js_sys::Date::now() / 1000.0) as i64
13+
}
14+
15+
/// Get current Unix timestamp in seconds (native)
16+
#[cfg(not(target_arch = "wasm32"))]
17+
pub fn now_timestamp() -> i64 {
18+
std::time::SystemTime::now()
19+
.duration_since(std::time::UNIX_EPOCH)
20+
.unwrap_or_default()
21+
.as_secs() as i64
22+
}
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use super::*;
27+
28+
#[test]
29+
fn test_now_timestamp_reasonable() {
30+
let ts = now_timestamp();
31+
// Should be after Jan 1, 2020 (timestamp: 1577836800)
32+
assert!(ts > 1577836800, "Timestamp should be after 2020");
33+
// Should be before Jan 1, 2100 (timestamp: 4102444800)
34+
assert!(ts < 4102444800, "Timestamp should be before 2100");
35+
}
36+
}

packages/fula_client/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.11] - 2026-01-13
9+
10+
### Fixed
11+
12+
- **WASM time compatibility bug**: Fixed `time not implemented on this platform` panic when validating share tokens in browser
13+
- Added centralized `time::now_timestamp()` function using `js_sys::Date::now()` for WASM and `std::time::SystemTime` for native
14+
15+
### Changed
16+
17+
- Updated `fula-crypto` to use WASM-compatible time functions in sharing, inbox, private_metadata, and subtree_keys modules
18+
819
## [0.2.10] - 2026-01-12
920

1021
### Added

0 commit comments

Comments
 (0)