Commit 847d003b authored by Éloïs's avatar Éloïs

[ref] spli code into several files

parent 267f36e8
use dup_crypto::keys::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool {
let pubkey = match ed25519::PublicKey::from_base58(pubkey) {
Ok(pubkey) => pubkey,
Err(_) => return false,
};
let sig = match ed25519::Signature::from_base64(signature) {
Ok(signature) => signature,
Err(_) => return false,
};
pubkey.verify(datas.as_bytes(), &sig)
}
#[wasm_bindgen]
pub fn generate_ed25519_keypair(salt: &str, password: &str) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes());
format!("{}:{}", keypair.pubkey, keypair.privkey)
}
#[wasm_bindgen]
pub fn generate_ed25519_pubkey(salt: &str, password: &str) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes());
format!("{}", keypair.pubkey)
}
extern crate cfg_if;
extern crate dubp_documents;
extern crate dup_crypto;
extern crate durs_network_documents;
extern crate serde_json;
extern crate wasm_bindgen;
pub mod crypto;
pub mod parsers;
mod utils;
use cfg_if::cfg_if;
use dup_crypto::keys::*;
use wasm_bindgen::prelude::*;
cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
......@@ -17,43 +20,3 @@ cfg_if! {
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
}
}
#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}
#[wasm_bindgen]
pub fn greet() {
alert("Hello, dup-tools-wasm 2 !");
}
#[wasm_bindgen]
pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool {
let pubkey = match ed25519::PublicKey::from_base58(pubkey) {
Ok(pubkey) => pubkey,
Err(_) => return false,
};
let sig = match ed25519::Signature::from_base64(signature) {
Ok(signature) => signature,
Err(_) => return false,
};
pubkey.verify(datas.as_bytes(), &sig)
}
#[wasm_bindgen]
pub fn generate_ed25519_keypair(salt: &str, password: &str) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes());
format!("{}:{}", keypair.pubkey, keypair.privkey)
}
#[wasm_bindgen]
pub fn generate_ed25519_pubkey(salt: &str, password: &str) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes());
format!("{}", keypair.pubkey)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment