Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olehmisar/nodash
A utility library for Noir
https://github.com/olehmisar/nodash
library noir-lang utility zero-knowledge
Last synced: 3 months ago
JSON representation
A utility library for Noir
- Host: GitHub
- URL: https://github.com/olehmisar/nodash
- Owner: olehmisar
- Created: 2024-06-27T18:12:31.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-17T22:27:53.000Z (4 months ago)
- Last Synced: 2024-07-18T02:23:20.795Z (4 months ago)
- Topics: library, noir-lang, utility, zero-knowledge
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-noir - nodash - a generic utility library. "Lodash for Noir" (Get Coding / Libraries)
README
# Nodash - Lodash for Noir
Nodash is a utility library for [Noir](https://github.com/noir-lang/noir) language.
## Installation
Put this into your Nargo.toml.
If you are using Noir:
```toml
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "noir-v0.31.2" }
```If you are using Aztec:
```toml
nodash = { git = "https://github.com/olehmisar/nodash/", tag = "aztec-v0.46.7" }
```## Docs
### `math::sqrt`
```rs
use nodash::math::sqrt::sqrt;assert(sqrt(4 as u64) == 2);
// it floors the result
assert(sqrt(8 as u64) == 2);
```### `math::clamp`
```rs
use nodash::math::clamp;// if too small, return min
assert(clamp(1 as u64, 2 as u64, 3 as u64) == 2 as u64);
// if too big, return max
assert(clamp(4 as u64, 1 as u64, 3 as u64) == 3 as u64);
// if in range, return value
assert(clamp(2 as u64, 1 as u64, 3 as u64) == 2 as u64);
```### `solidity::encode_with_selector`
Equivalent to `abi.encodeWithSelector` in Solidity.
_Note: due to Noir limitations, you have to pass the result array as the last argument. The length of the array should be `4 + N * 32` where `N` is the number of arguments. In the example below, `4 + 2 * 32 == 68`_
```rs
use nodash::solidity::encode_with_selector;let selector: u32 = 0xa9059cbb; // transfer(address,uint256)
let args: [Field; 2] = [
0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, // address
123 // uint256
];
let encoded = encode_with_selector(selector, args, [0; 68]);
// typeof encoded: [u8; 68]
```