Packages

A Gleam implementation of CUID2, the secure, collision-resistant ids optimized for horizontal scaling and performance.

Current section

Files

Jump to
glecuid src glecuid internals crypto.gleam
Raw

src/glecuid/internals/crypto.gleam

import gleam/string
import glecuid/internals/util
/// Hashes the input.
///
pub fn hash(input: String) -> String {
// https://github.com/paralleldrive/cuid2/blob/v3.0.0/src/index.js#L32
// Drop the first character because it will bias the histogram
// to the left.
do_hash(input)
|> util.bit_array_to_base36()
|> string.drop_start(1)
}
@external(erlang, "glecuid_ffi", "hash")
@external(javascript, "../../crypto_ffi.ts", "hash")
fn do_hash(input: String) -> BitArray