fluence_actor_sdk/lib.rs
1/*
2 * Copyright 2024 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17mod sys;
18
19pub use fluence_fendermint_shared::TARGET_HASH_SIZE;
20pub use fvm_shared::error::ErrorNumber;
21
22/// Run RandomX in the light mode with the supplied global (K) and local (H) nonce,
23/// return its result hash.
24pub fn run_randomx(
25 global_nonce: Vec<u8>,
26 local_nonce: Vec<u8>,
27) -> Result<[u8; TARGET_HASH_SIZE], fvm_shared::error::ErrorNumber> {
28 unsafe {
29 sys::run_randomx(
30 global_nonce.as_ptr(),
31 global_nonce.len() as u32,
32 local_nonce.as_ptr(),
33 local_nonce.len() as u32,
34 )
35 }
36}