Using the Nois Toolbox in js

The Nois Toolbox can be compiled to JavaScript via WebAssembly. This way you can simulate the outputs for every randomness value. The results match those of CosmWasm contracts using the same tools. The Nois Simulator is a good example for such a usecase. In order to keep the JS/Wasm interface simple, there is a wrapper in the module lib/js which takes the randomness inputs in hex format and uses types and error handling that plays well with JS. JS/Wasm bindings are created using wasm-bindgen. The JS does not match 100% the contract implementation. The differences are documented here.

Contract functionJS functionStatusNote
nois::coinflipcoinflip✅ ReadyReturns string instead of enum
nois::roll_diceroll_dice✅ Ready----
https://docs.rs/nois/latest/nois/fn.pick.htmlpick✅ Ready----
nois::select_from_weightedselect_from_weighted✅ Ready----
nois::int_in_rangeint_in_range✅ ReadyOnly supports half-oen range, i.e. the end value is always exluded
nois::ints_in_rangeints_in_range✅ Ready----
nois::random_decimalrandom_decimal✅ ReadyEncodes result Decimal as string
nois::sub_randomnesssub_randomness✅ ReadyTakes a count argument and returns an Array instead of an iterator
nois::nois_shuffleshuffle✅ Ready----