Skip to main content

work

Function work 

Source
pub async fn work(
    data: &[u8],
    salt: Option<&[u8]>,
    opts: WorkOptions,
) -> Result<String, SeaError>
Expand description

Compute proof-of-work or content hash.

§PBKDF2 Mode (default)

  • Algorithm: PBKDF2-HMAC-SHA256
  • Iterations: 100,000 (configurable via WorkOptions::iterations)
  • Salt: random 9 bytes if not provided (matching Gun.js)
  • Output: base64-encoded derived key

§SHA-256 Mode

  • Triggered when WorkOptions::name starts with "sha" (case-insensitive)
  • Direct SHA-256 hash of input data
  • Output: base64-encoded hash

§Arguments

  • data — Input bytes to hash
  • salt — Optional salt (PBKDF2 mode only). If None, uses WorkOptions::salt or generates a random 9-byte salt.
  • opts — Configuration (see WorkOptions)

§Errors

Returns SeaError::Crypto on task join failure or internal error.