init vrf test

This commit is contained in:
boneyard93501 2022-04-01 03:22:45 -05:00
parent 97b87090b2
commit bb4f253b8a
6 changed files with 92 additions and 0 deletions

5
vrf-wasm/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
debug/
target/
Cargo.lock
**/*.bk
**/*.bak

25
vrf-wasm/Cargo.toml Normal file
View File

@ -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"

6
vrf-wasm/Config.toml Normal file
View File

@ -0,0 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "vrf_wasm"
mem_pages_count = 1
logger_enabled = true

View File

@ -0,0 +1,11 @@
{
"vrf-wasm": {
"name": "vrf-wasm",
"modules": [
{
"name": "vrf-wasm",
"path": "./artifacts/vrf_wasm.wasm"
}
]
}
}

7
vrf-wasm/scripts/build.sh Executable file
View File

@ -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/

38
vrf-wasm/src/main.rs Normal file
View File

@ -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);
}