@substrate-system/bab
v0.4.4
Published
An implementation of the Bab family of hash functions, and its WILLIAM3 instantiation.
Downloads
5
Readme
Bab
A Rust implementation of the Bab family of hash functions in general, and the WILLIAM3 instantiation in particular.
See the docs for more details.
Fork
This is a fork of worm-blossom/bab_rs.
This fork builds a web assembly version of the wormblossom rust library.
Example
import init, {
william3_hash,
William3HasherWasm,
william3_width
} from '@substrate-system/bab'
await init()
const input = 'hello bab'
const encoder = new TextEncoder()
const data = encoder.encode(input)
const hash = william3_hash(data)
const hasher = new William3HasherWasm()
hasher.write(encoder.encode('hello'))
const hash2 = hasher.finish_hex();
console.log(hash2)
// 5d70555767754cbd...Start the example page with a localhost vite server:
npm startWASM
Compile the Rust code to web assembly.
Prerequisites
Install wasm-pack:
cargo install wasm-packCompile
npm run buildThis will create a pkg/ directory containing the compiled WebAssembly module.
bump the version and publish
Cargo.tonl is the source of truth for the version, because this is primarily
a rust package.
Bump the version
There's a cargo plugin cargo-edit that makes this easier.
Install cargo-edit (first time only)
cargo install cargo-editBump patch version (0.4.3 → 0.4.4)
cargo set-version --bump patchBump minor version (0.4.3 → 0.5.0)
cargo set-version --bump minorBump major version (0.4.3 → 1.0.0)
cargo set-version --bump majorSet specific version
cargo set-version 0.5.0Publish
Publish the package to npm.
Build the WASM package
Frist build the package. It will use the version number from Cargo.toml.
./build-wasm.shNavigate to the generated package directory
cd pkgpublish
npm publishTest
cargo test --features stdPublish to crates.io
cargo publishConsume
In a Web Browser
See the file ./example/index.ts for an example of using this module.
import init, {
william3_hash,
William3HasherWasm,
william3_width
} from '@substrate-system/bab'