Skip to content

Commit

Permalink
feat: private backpointer (#90)
Browse files Browse the repository at this point in the history
* Encrypt the ratchet key

* Rename `RatchetKey` to `RevisionKey`

* Fix wasm crate

* Rename `*Serde` into `*Serializable`

* Add `previous` backlinks to `PrivateDirectory` schema

* Remember persisted CID in PrivateDirectory

And store previous CID in previous links.

Co-authored-by: Stephen <[email protected]>

* Fixed not resetting `persisted_as` correctly

Co-authored-by: Stephen <[email protected]>

* Also implement `prepare_next_revision` for private files

* Add TODOs for fixing up serialization

* Make use of `let-else` ✨ 💄

* Store `previous` in `PrivateNodeHistory`.

* Resolve bias in previous iterator towards `previous` nodes

* Add docs & test

* Also rotate the `inumber` when re-attaching trees

* fix: Private shard block labels according to spec

https://github.com/wnfs-wg/spec/blob/main/spec/private-wnfs.md#44-sharded-file-content-access

* chore: Remove some logging, reduce diff

* Documentation for `Encrypted`

* Try to align on `impl BlockStore` and `impl RngCore`

* Take a reference (fix incorrect manual merge)

* Force a patch version for chrono

Co-authored-by: Stephen <[email protected]>
  • Loading branch information
matheus23 and appcypher authored Jan 10, 2023
1 parent 22b50c1 commit e38d039
Show file tree
Hide file tree
Showing 19 changed files with 729 additions and 329 deletions.
3 changes: 2 additions & 1 deletion wnfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ async-std = { version = "1.11", features = ["attributes"] }
async-stream = "0.3"
async-trait = "0.1"
bitvec = { version = "1.0", features = ["serde"] }
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
chrono = { version = "0.4.23", default-features = false, features = ["clock", "std"] }
either = "1.8"
futures = "0.3"
futures-util = "0.3"
libipld = { version = "0.15", features = ["dag-cbor", "derive", "serde-codec"] }
log = "0.4"
multihash = "0.16"
once_cell = "1.16"
proptest = { version = "1.0", optional = true }
rand = { version = "0.8", optional = true }
Expand Down
9 changes: 4 additions & 5 deletions wnfs/examples/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ async fn main() {
println!("{:#?}", dir);
}

async fn get_forest_cid_and_private_ref<B, R>(store: &mut B, rng: &mut R) -> (Cid, PrivateRef)
where
B: BlockStore,
R: RngCore,
{
async fn get_forest_cid_and_private_ref(
store: &mut impl BlockStore,
rng: &mut impl RngCore,
) -> (Cid, PrivateRef) {
// Create the private forest (a HAMT), a map-like structure where file and directory ciphertexts are stored.
let forest = Rc::new(PrivateForest::new());

Expand Down
10 changes: 3 additions & 7 deletions wnfs/src/common/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,12 @@ pub trait BlockStore {
self.put_block(bytes, IpldCodec::DagCbor).await
}

async fn put_private_serializable<V, R>(
async fn put_private_serializable<V: Serialize>(
&mut self,
value: &V,
key: &Key,
rng: &mut R,
) -> Result<Cid>
where
V: Serialize,
R: RngCore,
{
rng: &mut impl RngCore,
) -> Result<Cid> {
let ipld = ipld_serde::to_ipld(value)?;
let mut bytes = Vec::new();
ipld.encode(DagCborCodec, &mut bytes)?;
Expand Down
4 changes: 2 additions & 2 deletions wnfs/src/common/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ pub mod dagcbor {
}

/// Encodes an async serializable value into DagCbor bytes.
pub async fn async_encode<V: AsyncSerialize, B: BlockStore>(
pub async fn async_encode<V: AsyncSerialize>(
value: &V,
store: &mut B,
store: &mut impl BlockStore,
) -> Result<Vec<u8>> {
let ipld = value.async_serialize_ipld(store).await?;
let mut bytes = Vec::new();
Expand Down
6 changes: 3 additions & 3 deletions wnfs/src/common/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<T> Link<T> {
}

/// Gets the value stored in link. It attempts to get it from the store if it is not present in link.
pub async fn resolve_value<B: BlockStore>(&self, store: &B) -> Result<&T>
pub async fn resolve_value<B: BlockStore + ?Sized>(&self, store: &B) -> Result<&T>
where
T: DeserializeOwned,
{
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<T> Link<T> {
}

/// Compares two links for equality. Attempts to get them from store if they are not already cached.
pub async fn deep_eq<B: BlockStore>(&self, other: &Link<T>, store: &mut B) -> Result<bool>
pub async fn deep_eq(&self, other: &Link<T>, store: &mut impl BlockStore) -> Result<bool>
where
T: PartialEq + AsyncSerialize,
{
Expand All @@ -137,7 +137,7 @@ impl<T> Link<T> {

#[async_trait(?Send)]
impl<T: PartialEq + AsyncSerialize> IpldEq for Link<T> {
async fn eq<B: BlockStore>(&self, other: &Link<T>, store: &mut B) -> Result<bool> {
async fn eq<B: BlockStore + ?Sized>(&self, other: &Link<T>, store: &mut B) -> Result<bool> {
if self == other {
return Ok(true);
}
Expand Down
Loading

0 comments on commit e38d039

Please sign in to comment.