Skip to main content

Crate aria_bsv_hasher

Crate aria_bsv_hasher 

Source
Expand description

aria-bsv-hasher — Canonical JSON serialization and SHA-256 hashing.

Implements the ARIA BRC-121 canonical JSON format, which is identical to the Python SDK’s canonical_json(): object keys are sorted lexicographically, arrays preserve order, and output is UTF-8 bytes with no whitespace.

§Example

use aria_bsv_hasher::{hash_object, hash_bytes, prefixed_hash};
use serde_json::json;

let h = hash_object(&json!({"b": 2, "a": 1})).unwrap();
assert_eq!(h.len(), 64);  // lowercase hex SHA-256

// Same result as: hash_bytes(b"{\"a\":1,\"b\":2}")
let direct = hash_bytes(b"{\"a\":1,\"b\":2}");
assert_eq!(h, direct);

assert_eq!(prefixed_hash(&h), format!("sha256:{}", h));

Enums§

HasherError
Errors produced by the hasher.

Functions§

canonical_json
Serialize v to deterministic JSON bytes.
equal
Compare two SHA-256 hex strings in a case-insensitive way.
hash_bytes
Hash raw bytes with SHA-256. Returns lowercase hex.
hash_object
Canonicalize v and return SHA-256 hex of the canonical bytes.
hash_object_prefixed
Canonicalize and hash v, returning "sha256:<hex>".
hash_string
Hash a UTF-8 string with SHA-256. Returns lowercase hex.
must_hash_object
Like hash_object but panics on error (useful in tests / infallible contexts).
prefixed_hash
Prepend "sha256:" to hash. Does not validate hash.