Current section
Files
Jump to
Current section
Files
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