diff --git a/ng-net/src/app_protocol.rs b/ng-net/src/app_protocol.rs index 3bcc536..903f179 100644 --- a/ng-net/src/app_protocol.rs +++ b/ng-net/src/app_protocol.rs @@ -15,6 +15,7 @@ use regex::Regex; use serde::{Deserialize, Serialize}; use ng_repo::errors::NgError; +#[allow(unused_imports)] use ng_repo::log::*; use ng_repo::types::*; use ng_repo::utils::{decode_digest, decode_key, decode_sym_key}; diff --git a/ng-repo/src/block.rs b/ng-repo/src/block.rs index fce43cc..b9f900e 100644 --- a/ng-repo/src/block.rs +++ b/ng-repo/src/block.rs @@ -79,10 +79,11 @@ impl BlockV0 { } } -impl From for String { - fn from(id: BlockId) -> Self { - base64_url::encode(&serde_bare::to_vec(&id).unwrap()) - //hex::encode(to_vec(&id).unwrap()) +impl From<&Digest> for String { + fn from(id: &Digest) -> Self { + let mut ser = serde_bare::to_vec(id).unwrap(); + ser.reverse(); + base64_url::encode(&ser) } } diff --git a/ng-repo/src/types.rs b/ng-repo/src/types.rs index ba18485..2db0748 100644 --- a/ng-repo/src/types.rs +++ b/ng-repo/src/types.rs @@ -57,8 +57,7 @@ impl Digest { impl fmt::Display for Digest { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let ser = serde_bare::to_vec(&self).unwrap(); - write!(f, "{}", base64_url::encode(&ser)) + write!(f, "{}", std::string::String::from(self)) } } @@ -114,7 +113,8 @@ impl SymKey { impl fmt::Display for SymKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let ser = serde_bare::to_vec(&self).unwrap(); + let mut ser = serde_bare::to_vec(&self).unwrap(); + ser.reverse(); write!(f, "{}", base64_url::encode(&ser)) } } @@ -196,7 +196,8 @@ impl PubKey { impl fmt::Display for PubKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let ser = serde_bare::to_vec(&self).unwrap(); + let mut ser = serde_bare::to_vec(&self).unwrap(); + ser.reverse(); write!(f, "{}", base64_url::encode(&ser)) } } @@ -278,7 +279,8 @@ impl TryFrom<&str> for PrivKey { impl fmt::Display for PrivKey { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let ser = serde_bare::to_vec(&self).unwrap(); + let mut ser = serde_bare::to_vec(&self).unwrap(); + ser.reverse(); write!(f, "{}", base64_url::encode(&ser)) } } @@ -543,8 +545,9 @@ pub enum OverlayId { impl fmt::Display for OverlayId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let overlay_ser = serde_bare::to_vec(&self).unwrap(); - write!(f, "{}", base64_url::encode(&overlay_ser)) + let mut ser = serde_bare::to_vec(&self).unwrap(); + ser.reverse(); + write!(f, "{}", base64_url::encode(&ser)) } } diff --git a/ng-repo/src/utils.rs b/ng-repo/src/utils.rs index cbcd0cd..c1eb1db 100644 --- a/ng-repo/src/utils.rs +++ b/ng-repo/src/utils.rs @@ -56,27 +56,32 @@ pub fn from_ed_privkey_to_dh_privkey(private: &PrivKey) -> PrivKey { /// don't forget to zeroize the string later on pub fn decode_key(key_string: &str) -> Result { - let vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + let mut vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + vec.reverse(); Ok(serde_bare::from_slice(&vec).map_err(|_| NgError::InvalidKey)?) } pub fn decode_priv_key(key_string: &str) -> Result { - let vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + let mut vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + vec.reverse(); Ok(serde_bare::from_slice(&vec).map_err(|_| NgError::InvalidKey)?) } pub fn decode_sym_key(key_string: &str) -> Result { - let vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + let mut vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + vec.reverse(); Ok(serde_bare::from_slice(&vec).map_err(|_| NgError::InvalidKey)?) } pub fn decode_digest(key_string: &str) -> Result { - let vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + let mut vec = base64_url::decode(key_string).map_err(|_| NgError::InvalidKey)?; + vec.reverse(); Ok(serde_bare::from_slice(&vec).map_err(|_| NgError::InvalidKey)?) } pub fn decode_overlayid(id_string: &str) -> Result { - let vec = base64_url::decode(id_string).map_err(|_| NgError::InvalidKey)?; + let mut vec = base64_url::decode(id_string).map_err(|_| NgError::InvalidKey)?; + vec.reverse(); Ok(serde_bare::from_slice(&vec).map_err(|_| NgError::InvalidKey)?) } diff --git a/ng-sdk-js/app-node/index.js b/ng-sdk-js/app-node/index.js index 912d16e..fabe7c3 100644 --- a/ng-sdk-js/app-node/index.js +++ b/ng-sdk-js/app-node/index.js @@ -13,9 +13,9 @@ const ng = require("nextgraph"); global.WebSocket = WebSocket; let config = { - server_peer_id: "ALyGZgFaDDALXLppJZLS2TrMScG0TQIS68RzRcPv99aN", - admin_user_key:"ABI7mSYq1jzulcatewG6ssaFuCjYVVxF_esEmV33oBW4", - client_peer_key:"APbhJBuWUUmwZbuYwVm88eJ0b_ZulpSMOlA-9Zwi-S0Q" + server_peer_id: "FtdzuDYGewfXWdoPuXIPb0wnd0SAg1WoA2B14S7jW3MA", + admin_user_key: "pye0YFzk1ix1amKEwd6AeqaUAN_PNpH5zGLomh0M1PAA", + client_peer_key: "GRP0QnlzaB8o2vdiBaNoOYDNOFX-uehLZMxeCaG3JA0A" }; ng.init_headless(config).then( async() => { @@ -24,9 +24,9 @@ ng.init_headless(config).then( async() => { //let user_id = await ng.admin_create_user(config); //console.log("user created: ",user_id); - let other_user_id = "ACO9_6356BOZdCAwUr9mzTod8Wv-BM7p48sQzGNa2PwI"; + let user_id = "tJVG293o6xirl3Ys5rzxMgdnPE_1d3IPAdrlR5qGRAIA"; - let session = await ng.session_headless_start(other_user_id); + let session = await ng.session_headless_start(user_id); session_id = session.session_id; console.log(session); @@ -39,12 +39,12 @@ ng.init_headless(config).then( async() => { console.log(q); } - await ng.sparql_update(session.session_id, "DELETE DATA { }"); + // await ng.sparql_update(session.session_id, "DELETE DATA { }"); - //await ng.sparql_update(session.session_id, "INSERT DATA { }"); - //await ng.sparql_update(session.session_id, "INSERT { ?s } WHERE { ?s } "); + // await ng.sparql_update(session.session_id, "INSERT DATA { }"); + // await ng.sparql_update(session.session_id, "INSERT { ?s } WHERE { ?s } "); - //await ng.sparql_update(session.session_id, "INSERT DATA { . }"); + // await ng.sparql_update(session.session_id, "INSERT DATA { . }"); sparql_result = await ng.sparql_query(session.session_id, "SELECT ?a WHERE { ?a _:abc. _:abc }"); console.log(sparql_result); @@ -89,7 +89,7 @@ ng.init_headless(config).then( async() => { // if you set this to true, the dataset is closed and removed from memory on the server. // next time you will open a session for this user, the dataset will be loaded again. let res = await ng.session_headless_stop(session.session_id, false); - console.log(res); + //console.log(res); } catch (e) { console.error(e); diff --git a/ngone/src/main.rs b/ngone/src/main.rs index 36b9bd1..a9d9e1a 100644 --- a/ngone/src/main.rs +++ b/ngone/src/main.rs @@ -91,8 +91,7 @@ impl Server { fn get_wallet(&self, encoded_id: String) -> Result { log_debug!("DOWNLOAD wallet {}", encoded_id); - let id = base64_url::decode(&encoded_id).map_err(|_e| NgHttpError::InvalidParams)?; - let wallet_id: PubKey = from_slice(&id).map_err(|_e| NgHttpError::InvalidParams)?; + let wallet_id: PubKey = decode_key(&encoded_id).map_err(|_e| NgHttpError::InvalidParams)?; let wallet_record = WalletRecord::open(&wallet_id, &self.store).map_err(|_e| NgHttpError::NotFound)?; let wallet = wallet_record.wallet().map_err(|_e| NgHttpError::NotFound)?;