diff --git a/vrf-wasm/.gitignore b/vrf-wasm/.gitignore new file mode 100644 index 0000000..bbccc88 --- /dev/null +++ b/vrf-wasm/.gitignore @@ -0,0 +1,5 @@ +debug/ +target/ +Cargo.lock +**/*.bk +**/*.bak diff --git a/vrf-wasm/Cargo.toml b/vrf-wasm/Cargo.toml new file mode 100644 index 0000000..d9a4c67 --- /dev/null +++ b/vrf-wasm/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "vrf_wasm" +version = "0.1.5" +authors = ["boneyard93501 <4523011+boneyard93501@users.noreply.github.com>"] +edition = "2018" +description = "vrf-wasm, a Marine wasi module" +license = "Apache-2.0" + +[[bin]] +name = "vrf_wasm" +path = "src/main.rs" + +[dependencies] +marine-rs-sdk = { version = "0.6.15", features = ["logger"] } +log = "0.4.14" +vrf = "0.2.3" +# openssl-sys = { version = "0.9.72", features = ["vendored"] } +hex = { version = "0.4.3", default-features = false } + +[dev-dependencies] +marine-rs-sdk-test = "0.4.1" + +[dev] +[profile.release] +opt-level = "s" diff --git a/vrf-wasm/Config.toml b/vrf-wasm/Config.toml new file mode 100644 index 0000000..1806aec --- /dev/null +++ b/vrf-wasm/Config.toml @@ -0,0 +1,6 @@ +modules_dir = "artifacts/" + +[[module]] + name = "vrf_wasm" + mem_pages_count = 1 + logger_enabled = true diff --git a/vrf-wasm/configs/deployment_cfg.json b/vrf-wasm/configs/deployment_cfg.json new file mode 100644 index 0000000..8d5edae --- /dev/null +++ b/vrf-wasm/configs/deployment_cfg.json @@ -0,0 +1,11 @@ +{ + "vrf-wasm": { + "name": "vrf-wasm", + "modules": [ + { + "name": "vrf-wasm", + "path": "./artifacts/vrf_wasm.wasm" + } + ] + } +} diff --git a/vrf-wasm/scripts/build.sh b/vrf-wasm/scripts/build.sh new file mode 100755 index 0000000..07671e6 --- /dev/null +++ b/vrf-wasm/scripts/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash -o errexit -o nounset -o pipefail +cargo update --aggressive + +mkdir -p artifacts +rm -f artifacts/*.wasm +marine build --release +cp target/wasm32-wasi/release/vrf_wasm.wasm artifacts/ diff --git a/vrf-wasm/src/main.rs b/vrf-wasm/src/main.rs new file mode 100644 index 0000000..ed56d41 --- /dev/null +++ b/vrf-wasm/src/main.rs @@ -0,0 +1,38 @@ +/* + * Copyright 2021 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use marine_rs_sdk::{marine, module_manifest, WasmLoggerBuilder}; +use vrf::openssl::{CipherSuite, ECVRF}; +use vrf::VRF; + +module_manifest!(); + +pub fn main() { + WasmLoggerBuilder::new().build().unwrap(); +} + +fn get_vrf(sk: String, message: String) { + let mut vrf = ECVRF::from_suite(CipherSuite::SECP256K1_SHA256_TAI).unwrap(); + let secret_key = + hex::decode("c9afa9d845ba75166b5c215767b1d6934e50c3db36e89b127b8a622b120f6721").unwrap(); + let public_key = vrf.derive_public_key(&secret_key).unwrap(); + let message: &[u8] = message.as_bytes(); + + let pi = vrf.prove(&secret_key, &message).unwrap(); + let hash = vrf.proof_to_hash(&pi).unwrap(); + + let beta = vrf.verify(&public_key, &pi, &message); +}