move key export to examples

rm webpack example
This commit is contained in:
kilic 2020-06-07 17:39:40 +03:00
parent e6e563413c
commit 600775f069
8 changed files with 30 additions and 5583 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
/target
/pkg
/examples/www
node_modules
*.key
Cargo.lock

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>rln prover example</title>
</head>
<body>
<script src="./index.js"></script>
</body>
</html>

View File

@ -1,16 +0,0 @@
// import key from 'binary-loader!./verifier.key';
// var hexdata = Buffer.from(key, 'ascii').toString('hex');
const js = import('../../pkg/rln.js');
js.then((js) => {
bufi = Buffer.alloc(64, 1);
buf0 = Buffer.alloc(32, 0);
// console.log(buf);
try {
let result = js.RLNWasm.generate_proof(bufi, buf0);
console.log(result);
console.log(buf0[0]);
} catch (err) {
console.log('LOGS ERROR');
console.log(err);
}
});

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +0,0 @@
{
"scripts": {
"serve": "webpack-dev-server"
},
"devDependencies": {
"binary-loader": "0.0.1",
"file-loader": "^6.0.0",
"raw-loader": "^4.0.1",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10"
}
}

View File

@ -1,25 +0,0 @@
const path = require('path');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
},
// module: {
// rules: [{ test: /\.key$/, use: 'raw-loader' }],
// },
// module: {
// rules: [
// {
// test: /\.(key)$/i,
// use: [
// {
// loader: 'file-loader',
// },
// ],
// },
// ],
// },
mode: 'development',
};

View File

@ -0,0 +1,29 @@
use sapling_crypto::bellman::pairing::Engine;
use std::fs::File;
fn main() {
use sapling_crypto::bellman::pairing::bn256::Bn256;
let merkle_depth = 32usize;
export_test_keys::<Bn256>(merkle_depth);
}
fn export_test_keys<E: Engine>(merkle_depth: usize) {
use rand::{SeedableRng, XorShiftRng};
use rln::circuit::poseidon::PoseidonCircuit;
use rln::circuit::rln::{RLNCircuit, RLNInputs};
use rln::poseidon::PoseidonParams;
use sapling_crypto::bellman::groth16::generate_random_parameters;
let poseidon_params = PoseidonParams::<E>::default();
let mut rng = XorShiftRng::from_seed([0x3dbe6258, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let hasher = PoseidonCircuit::new(poseidon_params.clone());
let circuit = RLNCircuit::<E> {
inputs: RLNInputs::<E>::empty(merkle_depth),
hasher: hasher.clone(),
};
let parameters = generate_random_parameters(circuit, &mut rng).unwrap();
let mut file_vk = File::create("verifier.key").unwrap();
let vk = parameters.vk.clone();
vk.write(&mut file_vk).unwrap();
let mut file_paramaters = File::create("parameters.key").unwrap();
parameters.write(&mut file_paramaters).unwrap();
}

View File

@ -1,44 +0,0 @@
use hex;
use sapling_crypto::bellman::pairing::Engine;
use std::fs::File;
use std::io::prelude::*;
fn main() {
use sapling_crypto::bellman::pairing::bn256::Bn256;
let merkle_depth = 32usize;
export_test_keys::<Bn256>(merkle_depth);
}
fn export_test_keys<E: Engine>(merkle_depth: usize) {
// use rand::{Rand, SeedableRng, XorShiftRng};
// use rln::circuit::poseidon::PoseidonCircuit;
// use rln::circuit::rln::{RLNCircuit, RLNInputs};
// use rln::poseidon::PoseidonParams;
use sapling_crypto::bellman::groth16::{generate_random_parameters, Parameters};
// let poseidon_params = PoseidonParams::<E>::default();
// let mut rng = XorShiftRng::from_seed([0x3dbe6258, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
// let hasher = PoseidonCircuit::new(poseidon_params.clone());
// let circuit = RLNCircuit::<E> {
// inputs: RLNInputs::<E>::empty(merkle_depth),
// hasher: hasher.clone(),
// };
// let parameters = generate_random_parameters(circuit, &mut rng).unwrap();
// let mut file_vk = File::create("verifier.key").unwrap();
// let vk = parameters.vk.clone();
// let s = "1122";
// let r = hex::decode(s);
// println!("{:?}", r);
let mut s: Vec<u8> = vec![0; 63];
// vk.write(&mut s).unwrap();
// println!("{:x?}", s);
// println!("{}", s.len());
// println!("{}", hex::encode(&s));
// file_vk.write_all(&s).unwrap();
let parameters2 = Parameters::<E>::read(&mut s.as_slice(), true).unwrap();
println!("{:?}", parameters2.h);
println!("xxx");
}