Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement safe API for ripemd160 #643

Closed
austinabell opened this issue Nov 24, 2021 · 4 comments · Fixed by #648
Closed

Implement safe API for ripemd160 #643

austinabell opened this issue Nov 24, 2021 · 4 comments · Fixed by #648
Assignees
Labels

Comments

@austinabell
Copy link
Contributor

This could have use cases, so we should support this interface. Unlike the APIs that exist within the SDK for other hash functions, an array of 20 bytes should be returned ([u8; 20]), since it is guaranteed this is always the length and fixed.

API should look roughly like:

pub fn ripemd(value: &[u8]) -> [u8; 20] {
 // ...
}

and live in near_sdk::env

@austinabell
Copy link
Contributor Author

This will be made very easy after #646 comes in

@austinabell austinabell added the good first issue Good for newcomers label Nov 25, 2021
@itegulov itegulov self-assigned this Nov 29, 2021
@itegulov
Copy link
Contributor

@austinabell While trying to implement a safe API call for RIPEMD-160 (based on top of #646 as per your last comment), I encountered this error:

  = note: /usr/bin/ld: /home/itegulov/Work/near/near-sdk-rs/target/debug/deps/near_sdk-56b2f12843352185.c0qiw6jpquo2vdz.rcgu.o: in function `near_sdk::environment::env::ripemd160_hash':
          /home/itegulov/Work/near/near-sdk-rs/near-sdk/src/environment/env.rs:294: undefined reference to `ripemd160'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

At first, I thought this was because of the old nearcore crate (as ripemd160 seems to have been introduced fairly recently) so I tried rebasing on top of #639. Unfortunately the issue did not go away and I am not sure what I am doing wrong... Maybe I need to re-generate something? My branch is here: https://github.com/near/near-sdk-rs/tree/safe-api-ripemd-160

@itegulov
Copy link
Contributor

Nevermind, just took a look at literally the next issue in the list (#631) and instantly realized what went wrong 🤦 I was missing a mocked implementation of ripemd160...

@austinabell
Copy link
Contributor Author

My apologies, forgot to link to that PR! You only need this for mocked implementation and you are trying to write a unit test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants