canic-utils
Small, deterministic utilities that Canic (and your canisters) rely on without pulling in the whole stack.
What you get:
- Fast xxHash3 helpers for non-crypto hashing.
- ChaCha20 PRNG seeded from the management canister
raw_rand(reseeding recommended). - String casing helpers (snake/constant/title/etc.).
- Small formatting helpers for logs/UI (
ellipsize_middle, instruction suffixes).
Quick hits
use ;
let digest = hash_u64; // fast sharding key
seed_from; // tests only; use raw_rand in canisters
let sample = next_u64.expect;
let bytes = random_bytes.expect;
let hex = random_hex.expect;
let short = ellipsize_middle;
let pretty = format_instructions;
Determinism notes
- Hashing: xxHash3 is not cryptographic. Use it for sharding, cache keys, and fingerprints—not for signatures or certified data.
- RNG: ChaCha20 PRNG seeded from
raw_randand deterministic between reseeds. Use frequent reseeding for sensitive randomness, seed in init + post_upgrade (Canic runtime schedules this automatically), and call RNG helpers from update methods so state advances.
Casing helper
use ;
assert_eq!;
assert!;
Testing
- RNG has basic sanity checks (not a statistical entropy test).
Layout
canic-utils/
├─ src/
│ ├─ case/ # casing helpers (snake, constant, title)
│ ├─ format.rs # tiny fmt helpers
│ ├─ hash.rs # xxHash3 helpers
│ ├─ instructions.rs# low-level wasm instr helpers
│ ├─ rand.rs # ChaCha20 PRNG seeded via raw_rand
│ └─ lib.rs
└─ Cargo.toml