Skip to content
Snippets Groups Projects
Commit b95931fa authored by Éloïs's avatar Éloïs
Browse files

[deps] upgrade all dubp deps (use dubp-rs-libs)

parent 0174f07d
No related branches found
No related tags found
No related merge requests found
Pipeline #9614 failed
...@@ -9,9 +9,9 @@ variables: ...@@ -9,9 +9,9 @@ variables:
.rust_stable_lin64: &rust_stable_lin64 .rust_stable_lin64: &rust_stable_lin64
image: registry.duniter.org/docker/duniter-rs-ci:v0.1.0 image: registry.duniter.org/docker/rust/rust-x64-stable-ci:latest
tags: tags:
- redshift-rs-stable - redshift
before_script: before_script:
- export PATH="$HOME/.cargo/bin:$PATH" - export PATH="$HOME/.cargo/bin:$PATH"
- rustup show - rustup show
...@@ -20,7 +20,7 @@ variables: ...@@ -20,7 +20,7 @@ variables:
.rust_stable_wasm: &rust_stable_wasm .rust_stable_wasm: &rust_stable_wasm
image: registry.duniter.org/docker/rust/wasm:v0.0.4 image: registry.duniter.org/docker/rust/wasm:v0.0.4
tags: tags:
- redshift-rs-nightly - redshift
before_script: before_script:
- export PATH="$HOME/.cargo/bin:$PATH" - export PATH="$HOME/.cargo/bin:$PATH"
- rustc --version && cargo --version - rustc --version && cargo --version
...@@ -43,9 +43,9 @@ tests:wasm:stable: ...@@ -43,9 +43,9 @@ tests:wasm:stable:
clippy: clippy:
<<: *rust_stable_lin64 <<: *rust_stable_lin64
before_script: before_script:
- cargo clippy -- -V
stage: clippy stage: clippy
script: script:
- cargo clippy -- -V
- cargo clippy --all -- -D warnings --verbose - cargo clippy --all -- -D warnings --verbose
publish:npm: publish:npm:
......
[package] [package]
name = "dup-tools-wasm" name = "dup-tools-wasm"
version = "0.2.1" version = "0.3.0"
authors = ["librelois <elois@ifee.fr>"] authors = ["librelois <elois@duniter.org>"]
description = "Tools for DUP Protocol." description = "Tools for DUP Protocol."
repository = "https://git.duniter.org/tools/dup-tools-wasm" repository = "https://git.duniter.org/tools/dup-tools-wasm"
license = "AGPL-3.0" license = "AGPL-3.0"
...@@ -14,24 +14,32 @@ crate-type = ["cdylib", "rlib"] ...@@ -14,24 +14,32 @@ crate-type = ["cdylib", "rlib"]
default = ["console_error_panic_hook"] default = ["console_error_panic_hook"]
[dependencies] [dependencies]
base58 = "0.1.*" cfg-if = "0.1.10"
cfg-if = "0.1.2" dubp-documents = { version = "0.20.0", features = ["crypto_scrypt"] }
dup-crypto = "0.6.0" dubp-documents-parser = { version = "0.5.1", features = ["crypto_scrypt"] }
dubp-documents = "0.12.0" #durs-network-documents = "0.3.1"
durs-network-documents = "0.3.1"
serde_derive = "1.0.*" serde_derive = "1.0.*"
wasm-bindgen = "0.2" wasm-bindgen = "0.2.67"
# The `console_error_panic_hook` crate provides better debugging of panics by # The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires # logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying. # code size when deploying.
console_error_panic_hook = { version = "0.1.1", optional = true } [dependencies.console_error_panic_hook]
version = "0.1.6"
optional = true
[dev-dependencies] [dev-dependencies]
pretty_assertions = "0.5.1" pretty_assertions = "0.6.1"
wasm-bindgen-test = "0.2" wasm-bindgen-test = "0.3.17"
[profile.release] [profile.release]
# Tell `rustc` to optimize for small code size. # Tell `rustc` to optimize for small code size.
opt-level = "s" #opt-level = "s"
[package.metadata.wasm-pack.profile.release]
wasm-opt = false
[patch.crates-io]
#dubp-documents = { path = "../../libs/dubp-rs-libs/documents" }
#dubp-documents-parser = { path = "../../libs/dubp-rs-libs/documents-parser" }
\ No newline at end of file
use base58::ToBase58; // Copyright (C) 2020 Éloïs SANCHEZ.
use dup_crypto::bases::*; //
use dup_crypto::hashs::*; // This program is free software: you can redistribute it and/or modify
use dup_crypto::keys::*; // it under the terms of the GNU Affero General Public License as
use wasm_bindgen::prelude::*; // published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
#[wasm_bindgen] #[wasm_bindgen]
pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool { pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool {
...@@ -15,58 +26,31 @@ pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool { ...@@ -15,58 +26,31 @@ pub fn verify(datas: &str, pubkey: &str, signature: &str) -> bool {
Err(_) => return false, Err(_) => return false,
}; };
pubkey.verify(datas.as_bytes(), &sig) pubkey.verify(datas.as_bytes(), &sig).is_ok()
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn generate_ed25519_keypair(salt: &str, password: &str) -> String { pub fn generate_ed25519_pubkey(salt: String, password: String) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters() let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes()); .generate(ed25519::SaltedPassword::new(salt, password));
format!("{}:{}", keypair.pubkey, keypair.privkey) format!("{}", keypair.public_key())
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn generate_ed25519_pubkey(salt: &str, password: &str) -> String { pub fn generate_seed_from_salted_password(salt: String, password: String) -> String {
let keypair = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate(salt.as_bytes(), password.as_bytes());
format!("{}", keypair.pubkey)
}
#[wasm_bindgen]
pub fn generate_seed_from_salted_password(salt: &str, password: &str, base: usize) -> String {
if base != 16 && base != 58 {
return "Error : invalid param base : accepted values are : 16, 58.".to_owned();
}
let seed = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters() let seed = ed25519::KeyPairFromSaltedPasswordGenerator::with_default_parameters()
.generate_seed(salt.as_bytes(), password.as_bytes()); .generate_seed(salt.as_bytes(), password.as_bytes());
match base { seed.to_base58()
16 => Hash(seed).to_hex(),
58 => seed.to_base58(),
_ => unreachable!(),
}
}
#[wasm_bindgen]
pub fn generate_ed25519_keypair_from_seed(seed: &str, base: usize) -> String {
match parse_seed(seed, base) {
Ok(seed) => {
let keypair = ed25519::KeyPairFromSeedGenerator::generate(&seed);
format!("{}:{}", keypair.pubkey, keypair.privkey)
}
Err(error_message) => error_message,
}
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn generate_ed25519_pubkey_from_seed(seed: &str, base: usize) -> String { pub fn generate_ed25519_pubkey_from_seed(seed: &str, base: usize) -> String {
match parse_seed(seed, base) { match parse_seed(seed, base) {
Ok(seed) => { Ok(seed_bytes) => {
let keypair = ed25519::KeyPairFromSeedGenerator::generate(&seed); let keypair = ed25519::KeyPairFromSeed32Generator::generate(Seed32::new(seed_bytes));
format!("{}", keypair.pubkey) format!("{}", keypair.public_key())
} }
Err(error_message) => error_message, Err(error_message) => error_message,
} }
...@@ -79,7 +63,7 @@ fn parse_seed(seed: &str, base: usize) -> Result<[u8; 32], String> { ...@@ -79,7 +63,7 @@ fn parse_seed(seed: &str, base: usize) -> Result<[u8; 32], String> {
Err(err) => Err(format!("{}", err)), Err(err) => Err(format!("{}", err)),
}, },
58 => match b58::str_base58_to_32bytes(seed) { 58 => match b58::str_base58_to_32bytes(seed) {
Ok(seed) => Ok(seed), Ok((seed, _leading_1)) => Ok(seed),
Err(err) => Err(format!("{}", err)), Err(err) => Err(format!("{}", err)),
}, },
_ => Err("Error : invalid param base : accepted values are : 16, 58.".to_owned()), _ => Err("Error : invalid param base : accepted values are : 16, 58.".to_owned()),
......
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*; use crate::*;
#[wasm_bindgen] #[wasm_bindgen]
...@@ -55,12 +70,12 @@ IdtyUniqueID: tic ...@@ -55,12 +70,12 @@ IdtyUniqueID: tic
IdtyTimestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 IdtyTimestamp: 0-E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855
IdtySignature: 1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMMmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg== IdtySignature: 1eubHHbuNfilHMM0G2bI30iZzebQ2cQ1PC7uPAw08FGMMmQCRerlF/3pc4sAcsnexsxBseA/3lY03KlONqJBAg==
XXOgI++6qpY9O31ml/FcfbXCE6aixIrgkT5jL7kBle3YOMr+8wrp7Rt+z9hDVjrNfYX2gpeJsuMNfG4T/fzVDQ==".to_owned(), XXOgI++6qpY9O31ml/FcfbXCE6aixIrgkT5jL7kBle3YOMr+8wrp7Rt+z9hDVjrNfYX2gpeJsuMNfG4T/fzVDQ==".to_owned(),
DocumentType::PeerV11 => "11:g1:0:7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb:50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370 /*DocumentType::PeerV11 => "11:g1:0:7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb:50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370
WS2P V2 S 7 g1.durs.ifee.fr 443 ws2p WS2P V2 S 7 g1.durs.ifee.fr 443 ws2p
WS2P V2 S 7 84.16.72.210 443 ws2p WS2P V2 S 7 84.16.72.210 443 ws2p
EQ2D5almq2RNUi3XZNtTpjo9nWtJF0PzsCW7ROAzCQKiEtpI7/fW8Z23GJ2a/SIxfYSzlq/cZqksE4EoVe1rAw==".to_owned(), EQ2D5almq2RNUi3XZNtTpjo9nWtJF0PzsCW7ROAzCQKiEtpI7/fW8Z23GJ2a/SIxfYSzlq/cZqksE4EoVe1rAw==".to_owned(),
DocumentType::HeadV3 => "3:g1:0:0:0:0:0:7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb:50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370:durs:0.1.0-a0.1 DocumentType::HeadV3 => "3:g1:0:0:0:0:0:7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb:50-000005B1CEB4EC5245EF7E33101A330A1C9A358EC45A25FC13F78BB58C9E7370:durs:0.1.0-a0.1
vwlxpkCbv83qYSiClYA/GD35hs0AsZBnqv7uoE8hqlarT2c6jVRKhjp8JBqmRI7Se4IDwC2owk0mF4CglvyACQ== vwlxpkCbv83qYSiClYA/GD35hs0AsZBnqv7uoE8hqlarT2c6jVRKhjp8JBqmRI7Se4IDwC2owk0mF4CglvyACQ==
2".to_owned(), 2".to_owned(),*/
} }
} }
extern crate cfg_if; // Copyright (C) 2020 Éloïs SANCHEZ.
extern crate dubp_documents; //
extern crate dup_crypto; // This program is free software: you can redistribute it and/or modify
extern crate durs_network_documents; // it under the terms of the GNU Affero General Public License as
extern crate serde_derive; // published by the Free Software Foundation, either version 3 of the
extern crate wasm_bindgen; // License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub mod crypto; pub mod crypto;
pub mod examples; pub mod examples;
pub mod parsers; pub mod parsers;
mod utils;
use cfg_if::cfg_if; // Crate imports
use wasm_bindgen::prelude::*; pub(crate) use cfg_if::cfg_if;
pub(crate) use dubp_documents::certification::*;
pub(crate) use dubp_documents::dubp_common::crypto::bases::b58::ToBase58;
pub(crate) use dubp_documents::dubp_common::crypto::bases::*;
pub(crate) use dubp_documents::dubp_common::crypto::keys::*;
pub(crate) use dubp_documents::identity::*;
pub(crate) use dubp_documents::membership::*;
pub(crate) use dubp_documents::prelude::*;
pub(crate) use dubp_documents::revocation::*;
pub(crate) use dubp_documents::transaction::*;
pub(crate) use dubp_documents_parser::prelude::*;
pub(crate) use dubp_documents_parser::{PestError, RawTextParseError};
pub(crate) use std::ops::Deref;
pub(crate) use wasm_bindgen::prelude::*;
cfg_if! { cfg_if! {
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
...@@ -22,6 +42,21 @@ cfg_if! { ...@@ -22,6 +42,21 @@ cfg_if! {
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
} }
} }
cfg_if! {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook;
pub use self::console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
...@@ -32,6 +67,6 @@ pub enum DocumentType { ...@@ -32,6 +67,6 @@ pub enum DocumentType {
MembershipV10, MembershipV10,
CertificationV10, CertificationV10,
RevocationV10, RevocationV10,
PeerV11, //PeerV11,
HeadV3, //HeadV3,
} }
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub mod wallet_script;
use crate::*; use crate::*;
use dubp_documents::documents::certification::*; //use durs_network_documents::network_head::NetworkHead;
use dubp_documents::documents::identity::*; //use durs_network_documents::network_head_v3::NetworkHeadV3;
use dubp_documents::documents::membership::*; //use durs_network_documents::network_peer::*;
use dubp_documents::documents::revocation::*; //use durs_network_documents::*;
use dubp_documents::documents::transaction::*;
use dubp_documents::documents::*;
use dubp_documents::Document;
use dubp_documents::*;
use dup_crypto::keys::text_signable::TextSignable;
use durs_network_documents::network_head::NetworkHead;
use durs_network_documents::network_head_v3::NetworkHeadV3;
use durs_network_documents::network_peer::*;
use durs_network_documents::*;
use std::ops::Deref;
use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[derive(Debug, Copy, Clone, Eq, PartialEq)]
...@@ -26,53 +32,22 @@ pub enum DocCheckResult { ...@@ -26,53 +32,22 @@ pub enum DocCheckResult {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Document_ { pub enum Document_ {
DUBPDocument(DUBPDocument), DubpDocument(DubpDocument),
NetworkDocument(NetworkDocument), //NetworkDocument(NetworkDocument),
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckResult { pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckResult {
if let Ok(document) = parse_doc(source, doc_type) { if let Ok(document) = parse_doc(source, doc_type) {
let valid_sig = match document { let valid_sig = match document {
Document_::DUBPDocument(blockchain_document) => match blockchain_document { Document_::DubpDocument(blockchain_document) => match blockchain_document {
DUBPDocument::Transaction(doc) => { DubpDocument::Transaction(doc) => doc.verify_signatures().is_ok(),
if let VerificationResult::Valid() = doc.verify_signatures() { DubpDocument::Identity(doc) => doc.verify_signatures().is_ok(),
true DubpDocument::Membership(doc) => doc.verify_signatures().is_ok(),
} else { DubpDocument::Certification(doc) => doc.verify_signatures().is_ok(),
false DubpDocument::Revocation(doc) => doc.verify_signatures().is_ok(),
}
}
DUBPDocument::Identity(doc) => {
if let VerificationResult::Valid() = doc.verify_signatures() {
true
} else {
false
}
}
DUBPDocument::Membership(doc) => {
if let VerificationResult::Valid() = doc.verify_signatures() {
true
} else {
false
}
}
DUBPDocument::Certification(doc) => {
if let VerificationResult::Valid() = doc.verify_signatures() {
true
} else {
false
}
}
DUBPDocument::Revocation(doc) => {
if let VerificationResult::Valid() = doc.verify_signatures() {
true
} else {
false
}
}
_ => unimplemented!(),
}, },
Document_::NetworkDocument(network_document) => match network_document { /*Document_::NetworkDocument(network_document) => match network_document {
NetworkDocument::Peer(peer_box) => match peer_box.deref() { NetworkDocument::Peer(peer_box) => match peer_box.deref() {
PeerCard::V11(peer_v11) => peer_v11.verify().is_ok(), PeerCard::V11(peer_v11) => peer_v11.verify().is_ok(),
_ => unimplemented!(), _ => unimplemented!(),
...@@ -81,7 +56,7 @@ pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckRes ...@@ -81,7 +56,7 @@ pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckRes
NetworkHead::V3(head_v3_box) => head_v3_box.deref().verify().is_ok(), NetworkHead::V3(head_v3_box) => head_v3_box.deref().verify().is_ok(),
_ => unimplemented!(), _ => unimplemented!(),
}, },
}, },*/
}; };
if valid_sig { if valid_sig {
DocCheckResult::ValidSig DocCheckResult::ValidSig
...@@ -99,17 +74,17 @@ pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckRes ...@@ -99,17 +74,17 @@ pub fn parse_doc_and_verify(source: &str, doc_type: DocumentType) -> DocCheckRes
pub fn parse_doc_into_json(doc: &str, doc_type: DocumentType) -> String { pub fn parse_doc_into_json(doc: &str, doc_type: DocumentType) -> String {
match parse_doc(doc, doc_type) { match parse_doc(doc, doc_type) {
Ok(document) => match document { Ok(document) => match document {
Document_::DUBPDocument(blockchain_document) => match blockchain_document { Document_::DubpDocument(blockchain_document) => match blockchain_document {
DUBPDocument::Transaction(ref tx_box) => { DubpDocument::Transaction(ref tx_box) => {
let mut tx = tx_box.deref().clone(); let tx = tx_box.deref().clone();
tx.compute_hash(); tx.compute_hash();
DUBPDocument::to_json_string_pretty(&DUBPDocument::Transaction(Box::new(tx))) DubpDocument::to_json_string_pretty(&DubpDocument::Transaction(Box::new(tx)))
.unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()) .unwrap_or_else(|_| "Fail to jsonifie document.".to_owned())
} }
_ => DUBPDocument::to_json_string_pretty(&blockchain_document) _ => DubpDocument::to_json_string_pretty(&blockchain_document)
.unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()), .unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()),
}, },
Document_::NetworkDocument(network_document) => match network_document { /*Document_::NetworkDocument(network_document) => match network_document {
NetworkDocument::Peer(peer_box) => match peer_box.deref() { NetworkDocument::Peer(peer_box) => match peer_box.deref() {
PeerCard::V11(peer_v11) => PeerCardV11::to_json_string_pretty(&peer_v11) PeerCard::V11(peer_v11) => PeerCardV11::to_json_string_pretty(&peer_v11)
.unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()), .unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()),
...@@ -120,48 +95,52 @@ pub fn parse_doc_into_json(doc: &str, doc_type: DocumentType) -> String { ...@@ -120,48 +95,52 @@ pub fn parse_doc_into_json(doc: &str, doc_type: DocumentType) -> String {
.unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()), .unwrap_or_else(|_| "Fail to jsonifie document.".to_owned()),
_ => unimplemented!(), _ => unimplemented!(),
}, },
}, },*/
}, },
Err(parse_error) => match parse_error { Err(parse_error) => match parse_error {
TextDocumentParseError::UnknownType => { RawTextParseError::UnknownType => {
"Invalid document. Specify the expected document type for more information." "Invalid document. Specify the expected document type for more information."
.to_owned() .to_owned()
} }
TextDocumentParseError::PestError(pest_error) => pest_error, RawTextParseError::PestError(PestError(pest_error)) => pest_error,
_ => format!("{:?}", parse_error), _ => format!("{:?}", parse_error),
}, },
} }
} }
fn parse_doc(doc: &str, doc_type: DocumentType) -> Result<Document_, TextDocumentParseError> { fn parse_doc(doc: &str, doc_type: DocumentType) -> Result<Document_, RawTextParseError> {
match doc_type { match doc_type {
DocumentType::Any => match NetworkDocument::parse(doc) { DocumentType::Any => /*match NetworkDocument::parse(doc) {
Ok(network_document) => Ok(Document_::NetworkDocument(network_document)), Ok(network_document) => Ok(Document_::NetworkDocument(network_document)),
Err(_) => match DUBPDocument::parse(doc) { Err(_) => match DubpDocument::parse(doc) {
Ok(blockchain_document) => Ok(Document_::DUBPDocument(blockchain_document)), Ok(blockchain_document) => Ok(Document_::DubpDocument(blockchain_document)),
Err(_) => Err(TextDocumentParseError::UnknownType), Err(_) => Err(RawTextParseError::UnknownType),
}, },*/
}, match DubpDocument::parse_from_raw_text(doc) {
DocumentType::TxV10 => Ok(Document_::DUBPDocument(DUBPDocument::Transaction( Ok(blockchain_document) => Ok(Document_::DubpDocument(blockchain_document)),
Box::new(TransactionDocumentParser::parse(doc)?), Err(_) => Err(RawTextParseError::UnknownType),
}
//},
DocumentType::TxV10 => Ok(Document_::DubpDocument(DubpDocument::Transaction(
Box::new(TransactionDocument::parse_from_raw_text(doc)?),
))), ))),
DocumentType::IdentityV10 => Ok(Document_::DUBPDocument(DUBPDocument::Identity( DocumentType::IdentityV10 => Ok(Document_::DubpDocument(DubpDocument::Identity(
IdentityDocumentParser::parse(doc)?, IdentityDocument::parse_from_raw_text(doc)?,
))), ))),
DocumentType::MembershipV10 => Ok(Document_::DUBPDocument(DUBPDocument::Membership( DocumentType::MembershipV10 => Ok(Document_::DubpDocument(DubpDocument::Membership(
MembershipDocumentParser::parse(doc)?, MembershipDocument::parse_from_raw_text(doc)?,
))), ))),
DocumentType::CertificationV10 => Ok(Document_::DUBPDocument(DUBPDocument::Certification( DocumentType::CertificationV10 => Ok(Document_::DubpDocument(DubpDocument::Certification(
Box::new(CertificationDocumentParser::parse(doc)?), Box::new(CertificationDocument::parse_from_raw_text(doc)?),
))), ))),
DocumentType::RevocationV10 => Ok(Document_::DUBPDocument(DUBPDocument::Revocation( DocumentType::RevocationV10 => Ok(Document_::DubpDocument(DubpDocument::Revocation(
Box::new(RevocationDocumentParser::parse(doc)?), Box::new(RevocationDocument::parse_from_raw_text(doc)?),
))), ))),
DocumentType::PeerV11 => Ok(Document_::NetworkDocument(NetworkDocument::Peer(Box::new( /*DocumentType::PeerV11 => Ok(Document_::NetworkDocument(NetworkDocument::Peer(Box::new(
PeerCard::V11(PeerCardV11::parse(doc)?), PeerCard::V11(PeerCardV11::parse(doc)?),
)))), )))),
DocumentType::HeadV3 => Ok(Document_::NetworkDocument(NetworkDocument::Head( DocumentType::HeadV3 => Ok(Document_::NetworkDocument(NetworkDocument::Head(
NetworkHead::V3(Box::new(NetworkHeadV3::parse(doc)?)), NetworkHead::V3(Box::new(NetworkHeadV3::parse(doc)?)),
))), ))),*/
} }
} }
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
#[wasm_bindgen]
pub fn parse_wallet_script(script_str: &str) -> String {
match dubp_documents_parser::wallet_script_from_str(script_str) {
Ok(script) => format!("{:#?}", script),
Err(e) => format!("{:#?}", e),
}
}
use cfg_if::cfg_if;
cfg_if! {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
if #[cfg(feature = "console_error_panic_hook")] {
extern crate console_error_panic_hook;
pub use self::console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}
...@@ -18,8 +18,8 @@ wasm_bindgen_test_configure!(run_in_browser); ...@@ -18,8 +18,8 @@ wasm_bindgen_test_configure!(run_in_browser);
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn test_generate_ed25519_keypair() { fn test_generate_ed25519_keypair() {
let pubkey = generate_ed25519_pubkey( let pubkey = generate_ed25519_pubkey(
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV", "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV".to_owned(),
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_", "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_".to_owned(),
); );
assert_eq!( assert_eq!(
...@@ -30,22 +30,13 @@ fn test_generate_ed25519_keypair() { ...@@ -30,22 +30,13 @@ fn test_generate_ed25519_keypair() {
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn test_generate_ed25519_keypair_from_seed() { fn test_generate_ed25519_keypair_from_seed() {
let seed_b16 = generate_seed_from_salted_password(
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV",
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_",
16,
);
let seed_b58 = generate_seed_from_salted_password( let seed_b58 = generate_seed_from_salted_password(
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV", "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV".to_owned(),
"JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_", "JhxtHB7UcsDbA9wMSyMKXUzBZUQvqVyB32KwzS9SWoLkjrUhHV_".to_owned(),
58,
); );
let pubkey_from_seed_b16 = generate_ed25519_pubkey_from_seed(&seed_b16, 16);
let pubkey_from_seed_b58 = generate_ed25519_pubkey_from_seed(&seed_b58, 58); let pubkey_from_seed_b58 = generate_ed25519_pubkey_from_seed(&seed_b58, 58);
assert_eq!(pubkey_from_seed_b16, pubkey_from_seed_b58);
assert_eq!( assert_eq!(
pubkey_from_seed_b58.as_str(), pubkey_from_seed_b58.as_str(),
"7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb" "7iMV3b6j2hSj5WtrfchfvxivS9swN3opDgxudeHq64fb"
...@@ -122,7 +113,7 @@ fn test_parse_and_verify_example_tx_v10() { ...@@ -122,7 +113,7 @@ fn test_parse_and_verify_example_tx_v10() {
); );
} }
#[wasm_bindgen_test] /*#[wasm_bindgen_test]
fn test_parse_and_verify_example_peer_v11() { fn test_parse_and_verify_example_peer_v11() {
let doc = example_doc(DocumentType::PeerV11); let doc = example_doc(DocumentType::PeerV11);
...@@ -134,9 +125,9 @@ fn test_parse_and_verify_example_peer_v11() { ...@@ -134,9 +125,9 @@ fn test_parse_and_verify_example_peer_v11() {
parse_doc_and_verify(&doc, DocumentType::Any), parse_doc_and_verify(&doc, DocumentType::Any),
DocCheckResult::ValidSig, DocCheckResult::ValidSig,
); );
} }*/
#[wasm_bindgen_test] /*#[wasm_bindgen_test]
fn test_parse_and_verify_example_head_v3() { fn test_parse_and_verify_example_head_v3() {
let doc = example_doc(DocumentType::HeadV3); let doc = example_doc(DocumentType::HeadV3);
...@@ -148,7 +139,7 @@ fn test_parse_and_verify_example_head_v3() { ...@@ -148,7 +139,7 @@ fn test_parse_and_verify_example_head_v3() {
parse_doc_and_verify(&doc, DocumentType::Any), parse_doc_and_verify(&doc, DocumentType::Any),
DocCheckResult::ValidSig, DocCheckResult::ValidSig,
); );
} }*/
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn test_verify_sig() { fn test_verify_sig() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment