diff --git a/nextgraph/src/local_broker.rs b/nextgraph/src/local_broker.rs index c6d8e32..b5ade53 100644 --- a/nextgraph/src/local_broker.rs +++ b/nextgraph/src/local_broker.rs @@ -379,7 +379,7 @@ struct LocalBroker { pub sessions: HashMap, - pub opened_sessions: HashMap, + pub opened_sessions: HashMap, pub opened_sessions_list: Vec>, } @@ -518,7 +518,7 @@ impl LocalBroker { } else { #[cfg(not(target_family = "wasm"))] { - let mut key_material = wallet + let key_material = wallet .client() .as_ref() .unwrap() @@ -529,8 +529,9 @@ impl LocalBroker { "block{}", wallet.client().as_ref().unwrap().id.to_hash_string() ))?; - let mut key: [u8; 32] = + let key: [u8; 32] = derive_key("NextGraph Client BlockStorage BLAKE3 key", key_material); + Arc::new(std::sync::RwLock::new(RocksDbBlockStorage::open( &path, key, )?)) @@ -761,10 +762,10 @@ impl LocalBroker { verifier, })); let idx = broker.opened_sessions_list.len() - 1; - broker.opened_sessions.insert(user_id, idx as u8); + broker.opened_sessions.insert(user_id, idx as u64); Ok(SessionInfo { - session_id: idx as u8, + session_id: idx as u64, user: user_id, }) } @@ -1414,7 +1415,7 @@ pub async fn wallet_remove(wallet_name: String) -> Result<(), NgError> { /// fetches a document's content, or performs a mutation on the document. pub async fn doc_fetch( - session_id: u8, + session_id: u64, nuri: String, payload: Option, ) -> Result<(Receiver, CancelFn), NgError> { @@ -1433,7 +1434,7 @@ pub async fn doc_fetch( } /// retrieves the ID of one of the 3 stores of a the personal Site (3P: public, protected, or private) -pub async fn personal_site_store(session_id: u8, store: SiteStoreType) -> Result { +pub async fn personal_site_store(session_id: u64, store: SiteStoreType) -> Result { let broker = match LOCAL_BROKER.get() { None | Some(Err(_)) => return Err(NgError::LocalBrokerNotInitialized), Some(Ok(broker)) => broker.read().await, diff --git a/ng-net/src/actors/noise.rs b/ng-net/src/actors/noise.rs index aa5cd41..7c83505 100644 --- a/ng-net/src/actors/noise.rs +++ b/ng-net/src/actors/noise.rs @@ -20,6 +20,7 @@ use std::any::{Any, TypeId}; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct NoiseV0 { // contains the handshake messages or the encrypted content of a ProtocolMessage + #[serde(with = "serde_bytes")] pub data: Vec, } diff --git a/ng-net/src/actors/start.rs b/ng-net/src/actors/start.rs index f72a667..9abb120 100644 --- a/ng-net/src/actors/start.rs +++ b/ng-net/src/actors/start.rs @@ -67,6 +67,7 @@ pub struct CoreHello { pub noise: Noise, /// Noise encrypted payload (a CoreMessage::CoreRequest::BrokerConnect) + #[serde(with = "serde_bytes")] pub payload: Vec, } @@ -132,6 +133,7 @@ pub struct ExtHello { pub noise: Noise, /// Noise encrypted payload (an ExtRequest) + #[serde(with = "serde_bytes")] pub payload: Vec, } diff --git a/ng-repo/src/types.rs b/ng-repo/src/types.rs index 61725c4..90b71c0 100644 --- a/ng-repo/src/types.rs +++ b/ng-repo/src/types.rs @@ -1723,6 +1723,7 @@ pub enum RemoveSignerCap { /// DEPS are the last HEAD of wallet updates. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct WalletUpdateV0 { + #[serde(with = "serde_bytes")] pub op: Vec, /// Metadata diff --git a/ng-verifier/src/types.rs b/ng-verifier/src/types.rs index 69fd576..bbc5f2d 100644 --- a/ng-verifier/src/types.rs +++ b/ng-verifier/src/types.rs @@ -215,10 +215,14 @@ pub struct GraphUpdate { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum DiscreteUpdate { /// A yrs::Update + #[serde(with = "serde_bytes")] YMap(Vec), + #[serde(with = "serde_bytes")] YXml(Vec), + #[serde(with = "serde_bytes")] YText(Vec), /// An automerge::Patch + #[serde(with = "serde_bytes")] Automerge(Vec), } @@ -248,8 +252,8 @@ pub enum AppRequestPayloadV0 { Update(AppUpdate), Delete(AppDelete), SmallFilePut(SmallFile), - RandomAccessFilePut(String), // content_type - RandomAccessFilePutChunk((ObjectId, Vec)), // end the upload with an empty vec + RandomAccessFilePut(String), // content_type + RandomAccessFilePutChunk((ObjectId, serde_bytes::ByteBuf)), // end the upload with an empty vec } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -260,10 +264,14 @@ pub enum AppRequestPayload { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum DiscretePatch { /// A yrs::Update + #[serde(with = "serde_bytes")] YMap(Vec), + #[serde(with = "serde_bytes")] YXml(Vec), + #[serde(with = "serde_bytes")] YText(Vec), /// An automerge::Patch + #[serde(with = "serde_bytes")] Automerge(Vec), } @@ -277,10 +285,14 @@ pub struct GraphPatch { #[derive(Clone, Debug, Serialize, Deserialize)] pub enum DiscreteState { /// A yrs::StateVector + #[serde(with = "serde_bytes")] YMap(Vec), + #[serde(with = "serde_bytes")] YXml(Vec), + #[serde(with = "serde_bytes")] YText(Vec), // the output of Automerge::save() + #[serde(with = "serde_bytes")] Automerge(Vec), } @@ -314,6 +326,7 @@ pub enum AppResponseV0 { Patch(AppPatch), Text(String), File(FileName), + #[serde(with = "serde_bytes")] FileBinary(Vec), QueryResult, // see sparesults } diff --git a/ng-wallet/src/types.rs b/ng-wallet/src/types.rs index 9092d73..df11e52 100644 --- a/ng-wallet/src/types.rs +++ b/ng-wallet/src/types.rs @@ -128,7 +128,7 @@ impl SessionWalletStorageV0 { #[derive(Clone, Debug, Serialize, Deserialize)] pub struct SessionInfo { - pub session_id: u8, + pub session_id: u64, pub user: UserId, } @@ -214,6 +214,7 @@ pub struct LocalWalletStorageV0 { pub client_id: ClientId, pub client_auto_open: Vec, pub client_name: Option, + #[serde(with = "serde_bytes")] pub encrypted_client_storage: Vec, } @@ -440,7 +441,7 @@ pub struct SensitiveWalletV0 { /// third parties data saved in the wallet. the string (key) in the hashmap should be unique among vendors. /// the format of the byte array (value) is up to the vendor, to serde as needed. #[zeroize(skip)] - pub third_parties: HashMap>, + pub third_parties: HashMap, #[zeroize(skip)] pub log: Option, @@ -745,7 +746,7 @@ impl WalletLogV0 { WalletOperation::RemoveSiteBootstrapV0(_) => {} WalletOperation::AddThirdPartyDataV0((key, value)) => { if self.is_last_and_not_deleted_afterwards(op, "RemoveThirdPartyDataV0") { - let _ = wallet.third_parties.insert(key.to_string(), value.to_vec()); + let _ = wallet.third_parties.insert(key.to_string(), value.clone()); } } WalletOperation::RemoveThirdPartyDataV0(_) => {} // WalletOperation::SetSiteRBDRefV0((site, store_type, rbdr)) => { @@ -894,7 +895,7 @@ pub enum WalletOperation { RemoveSiteCoreV0((PubKey, PubKey)), AddSiteBootstrapV0((PubKey, PubKey)), RemoveSiteBootstrapV0((PubKey, PubKey)), - AddThirdPartyDataV0((String, Vec)), + AddThirdPartyDataV0((String, serde_bytes::ByteBuf)), RemoveThirdPartyDataV0(String), //SetSiteRBDRefV0((PubKey, SiteStoreType, ObjectRef)), //SetSiteRepoSecretV0((PubKey, SiteStoreType, RepoWriteCapSecret)), @@ -1284,7 +1285,7 @@ pub struct CreateWalletResultV0 { /// is this an in_memory wallet that should not be saved to disk by the LocalBroker? pub in_memory: bool, - pub session_id: u8, + pub session_id: u64, } impl CreateWalletResultV0 {