Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ntge-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
authors = ["Yisi Liu <yisiliu@gmail.com>", "CMK <cirno.mainasuk@gmail.com>", "Tlaster <tlaster@outlook.com>", "Brad Gao <ugling88@hotmail.com>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -23,3 +26,18 @@ serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11.1"
serde_bytes = "0.11.3"
bs58 = "0.3.0"

wasm-bindgen = { version = "0.2", optional = true }
console_error_panic_hook = { version = "0.1.6", optional = true }
js-sys = { version = "0.3", optional = true }
web-sys = { version = "0.3", features=["console"], optional = true }

[features]
wasm = ["wasm-bindgen", "console_error_panic_hook", "js-sys", "web-sys"]

[target.wasm32-unknown-unknown.dependencies]
rand = { version = "0.7.3", features = ["wasm-bindgen"] }

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "z"
3 changes: 3 additions & 0 deletions ntge-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ pub mod error;
pub mod key_utils;
pub mod message;
pub mod x25519;

#[cfg(feature = "wasm")]
pub mod wasm;
6 changes: 3 additions & 3 deletions ntge-core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ pub(crate) const PAYLOAD_KEY_LABEL: &[u8] = b"ntge-message-payload";

#[derive(Debug, Serialize, Deserialize)]
pub struct MessageRecipientHeader {
pub key_type: String,
pub(crate) key_type: String,
#[serde(with = "serde_bytes")]
pub ephemeral_public_key: Vec<u8>,
pub(crate) ephemeral_public_key: Vec<u8>,
#[serde(with = "serde_bytes")]
pub encrypted_file_key: Vec<u8>, // 32 bytes
pub(crate) encrypted_file_key: Vec<u8>, // 32 bytes
}

impl MessageRecipientHeader {
Expand Down
72 changes: 72 additions & 0 deletions ntge-core/src/wasm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use wasm_bindgen::prelude::*;
extern crate js_sys;
extern crate web_sys;
use web_sys::console;
use crate::ed25519;
use ed25519_dalek::{Keypair, PublicKey, SecretKey};

// A macro to provide `println!(..)`-style syntax for `console.log` logging.
macro_rules! log {
( $( $t:tt )* ) => {
web_sys::console::log_1(&format!( $( $t )* ).into());
}
}

#[wasm_bindgen]
pub struct NTGEKeypair {
_keypair: ed25519_dalek::Keypair
}

#[wasm_bindgen]
impl NTGEKeypair {
pub fn new() -> NTGEKeypair {
log!("rust::Creating Keypair");
console_error_panic_hook::set_once();
let inter_keypair = ed25519::create_keypair();
log!("rust::Created Keypair");
NTGEKeypair {
_keypair: inter_keypair
}
}

pub fn get_public_key(&self) -> NTGEPublicKey {
NTGEPublicKey {
_pubkey: self._keypair.public
}
}

pub fn get_secret_key(&self) -> Option<NTGESecretKey> {
match ed25519_dalek::SecretKey::from_bytes(&(self._keypair.secret.to_bytes())).ok() {
Some(sk) => Some(NTGESecretKey {
_privkey: sk
}),
None => None
}
}
}

#[wasm_bindgen]
pub struct NTGEPublicKey {
_pubkey: PublicKey
}

#[wasm_bindgen]
impl NTGEPublicKey {
pub fn serialize(&self) -> String {
// JsValue::from_serde(&self._pubkey).unwrap()
ed25519::serialize_public_key(&self._pubkey)
}
}

#[wasm_bindgen]
pub struct NTGESecretKey {
_privkey: ed25519_dalek::SecretKey
}

#[wasm_bindgen]
impl NTGESecretKey {
pub fn serialize(&self) -> String {
// JsValue::from_serde(&self._pubkey).unwrap()
ed25519::serialize_private_key(&self._privkey)
}
}
24 changes: 24 additions & 0 deletions ntge-core/www/.bin/create-wasm-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env node

const { spawn } = require("child_process");
const fs = require("fs");

let folderName = '.';

if (process.argv.length >= 3) {
folderName = process.argv[2];
if (!fs.existsSync(folderName)) {
fs.mkdirSync(folderName);
}
}

const clone = spawn("git", ["clone", "https://github.com/rustwasm/create-wasm-app.git", folderName]);

clone.on("close", code => {
if (code !== 0) {
console.error("cloning the template failed!")
process.exit(code);
} else {
console.log("🦀 Rust + 🕸 Wasm = ❤");
}
});
2 changes: 2 additions & 0 deletions ntge-core/www/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
5 changes: 5 additions & 0 deletions ntge-core/www/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js: "10"

script:
- ./node_modules/.bin/webpack
Loading