Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
prog: migrate blake2b->blake3
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed May 18, 2023
1 parent 2494a01 commit 1de305a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion rust/noosphere-car/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
fn symmetric_header_v1() {
let digest = multihash::Code::Blake2b256.digest(b"test");
let digest = multihash::Code::Blake3_256.digest(b"test");
let cid = Cid::new_v1(DagCborCodec.into(), digest);

let header = CarHeaderV1::from(vec![cid]);
Expand Down
4 changes: 2 additions & 2 deletions rust/noosphere-car/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ mod tests {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn car_write_read() {
let digest_test = multihash::Code::Blake2b256.digest(b"test");
let digest_test = multihash::Code::Blake3_256.digest(b"test");
let cid_test = Cid::new_v1(DagCborCodec.into(), digest_test);

let digest_foo = multihash::Code::Blake2b256.digest(b"foo");
let digest_foo = multihash::Code::Blake3_256.digest(b"foo");
let cid_foo = Cid::new_v1(DagCborCodec.into(), digest_foo);

let header = CarHeader::V1(CarHeaderV1::from(vec![cid_foo]));
Expand Down
46 changes: 23 additions & 23 deletions rust/noosphere-collections/src/hamt/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ async fn test_set_if_absent() {

assert_eq!(
c.to_string().as_str(),
"bafy2bzaceb5xnigrmqoa3pcxwjhyrosrqm6wu3hyid67oickgm5dh72tdh2nq"
"bafyr4ielno5vz5topwq5hlc6lo6vck7pwjjjk2lr3e4abvnf5x2bahp23a"
);
let stats = store.to_stats().await;

Expand Down Expand Up @@ -139,7 +139,7 @@ async fn set_with_no_effect_does_not_put() {
let c = begn.flush().await.unwrap();
assert_eq!(
c.to_string().as_str(),
"bafy2bzacec4jvhfbm7r5rvjog5ulmofu43jl7ocbxswfb6ssy4zuzdqng4yh2"
"bafyr4id7q2hdrwdwg2mhhq5atyep6jme6ywfr26h7rl4b5upx62c4535bm"
);

begn.set(
Expand All @@ -151,7 +151,7 @@ async fn set_with_no_effect_does_not_put() {
let c2 = begn.flush().await.unwrap();
assert_eq!(
c2.to_string().as_str(),
"bafy2bzaceaiyvp6t7qzgryfzelbxwdxfsfb3a65en2ysaruoycndsei6cndxi"
"bafyr4ifyaz43okfrnriizp6xbqp6gd57ryix7berzhw3tv52juvfa3pzle"
);
let stats = store.to_stats().await;

Expand All @@ -162,7 +162,7 @@ async fn set_with_no_effect_does_not_put() {
writes: 18,
removes: 0,
bytes_read: 0,
bytes_written: 1282,
bytes_written: 1246,
bytes_removed: 0,
flushes: 0
}
Expand All @@ -178,7 +178,7 @@ async fn set_with_no_effect_does_not_put() {
let c3 = begn.flush().await.unwrap();
assert_eq!(
c3.to_string().as_str(),
"bafy2bzaceaiyvp6t7qzgryfzelbxwdxfsfb3a65en2ysaruoycndsei6cndxi"
"bafyr4ifyaz43okfrnriizp6xbqp6gd57ryix7berzhw3tv52juvfa3pzle"
);

let stats = store.to_stats().await;
Expand All @@ -190,7 +190,7 @@ async fn set_with_no_effect_does_not_put() {
writes: 19,
removes: 0,
bytes_read: 0,
bytes_written: 1372,
bytes_written: 1332,
bytes_removed: 0,
flushes: 0
}
Expand All @@ -217,7 +217,7 @@ async fn delete() {
let c = hamt.flush().await.unwrap();
assert_eq!(
c.to_string().as_str(),
"bafy2bzaceb2r5tut4pz7akosfode6fm2tsnbfmqmw7v4pwynthuwnpwecg2ae"
"bafyr4igjyveicvho3k32dboteukk527s4m27fdln3qrksaxc2hx5vcufji"
);

let mut h2 = Hamt::<_, String, String>::load(&c, store.clone())
Expand All @@ -229,7 +229,7 @@ async fn delete() {
let c2 = h2.flush().await.unwrap();
assert_eq!(
c2.to_string().as_str(),
"bafy2bzaceaavokfk2jkspe2g6hvowyicg57tm2plzc32alwfeehzmpjuak3vi"
"bafyr4iagi6t6khdrtbhmyjpjgvdlwv6pzylxhuhstxhkdp52rju7er325i"
);
let stats = store.to_stats().await;
assert_eq!(
Expand Down Expand Up @@ -261,7 +261,7 @@ async fn delete_case() {
let c = hamt.flush().await.unwrap();
assert_eq!(
c.to_string().as_str(),
"bafy2bzaceahota7ggilynp67qscapocgvfycri4ky52dqwnqt2uacxzzzgdvm"
"bafyr4ibscqqwfidiqfxikgpt6qocun4tylbw4mccfrxlmxznb3zym7en2a"
);

let mut h2: Hamt<_, ByteBuf, Vec<u8>> = Hamt::load(&c, store.clone()).await.unwrap();
Expand All @@ -271,7 +271,7 @@ async fn delete_case() {
let c2 = h2.flush().await.unwrap();
assert_eq!(
c2.to_string().as_str(),
"bafy2bzaceamp42wmmgr2g2ymg46euououzfyck7szknvfacqscohrvaikwfay"
"bafyr4iglr65wqmb4ffdvf2q47w3sptju5cvutaxgqmwjfknlm4lp2bgloi"
);
let stats = store.to_stats().await;
assert_eq!(
Expand Down Expand Up @@ -305,7 +305,7 @@ async fn reload_empty() {
assert_eq!(c, c2);
assert_eq!(
c.to_string().as_str(),
"bafy2bzaceamp42wmmgr2g2ymg46euououzfyck7szknvfacqscohrvaikwfay"
"bafyr4iglr65wqmb4ffdvf2q47w3sptju5cvutaxgqmwjfknlm4lp2bgloi"
);
#[rustfmt::skip]
let stats = store.to_stats().await;
Expand Down Expand Up @@ -340,7 +340,7 @@ async fn set_delete_many() {
let c1 = hamt.flush().await.unwrap();
assert_eq!(
c1.to_string().as_str(),
"bafy2bzacedhuekpbloj7daxgdzzezb5u5vpdtk4tcjb7bx5qavo4fgthm73ra"
"bafyr4igb6depnsaoyu4vj24bve5rp53zvwamnedh2ru2zvuaijlvf7b2oe"
);

for i in 200..400 {
Expand All @@ -350,7 +350,7 @@ async fn set_delete_many() {
let cid_all = hamt.flush().await.unwrap();
assert_eq!(
cid_all.to_string().as_str(),
"bafy2bzacecgzjkxti6czw5i3uv334aqb5awcz4bqwobuodlsft4y7yuznfpri"
"bafyr4if7dszb5im3uadfkn62z64td6dmrtv57qdzzyof2gzojhettpszsa"
);

for i in 200..400 {
Expand All @@ -364,7 +364,7 @@ async fn set_delete_many() {
let cid_d = hamt.flush().await.unwrap();
assert_eq!(
cid_d.to_string().as_str(),
"bafy2bzacedhuekpbloj7daxgdzzezb5u5vpdtk4tcjb7bx5qavo4fgthm73ra"
"bafyr4igb6depnsaoyu4vj24bve5rp53zvwamnedh2ru2zvuaijlvf7b2oe"
);

let stats = store.to_stats().await;
Expand All @@ -375,7 +375,7 @@ async fn set_delete_many() {
writes: 91,
removes: 0,
bytes_read: 0,
bytes_written: 9251,
bytes_written: 9075,
bytes_removed: 0,
flushes: 0
}
Expand Down Expand Up @@ -438,7 +438,7 @@ async fn for_each() {
let c = hamt.flush().await.unwrap();
assert_eq!(
c.to_string().as_str(),
"bafy2bzacedhuekpbloj7daxgdzzezb5u5vpdtk4tcjb7bx5qavo4fgthm73ra",
"bafyr4igb6depnsaoyu4vj24bve5rp53zvwamnedh2ru2zvuaijlvf7b2oe"
);

let mut hamt: Hamt<_, i32, i32> = Hamt::load_with_bit_width(&c, store.clone(), 5)
Expand Down Expand Up @@ -470,7 +470,7 @@ async fn for_each() {
let c = hamt.flush().await.unwrap();
assert_eq!(
c.to_string().as_str(),
"bafy2bzacedhuekpbloj7daxgdzzezb5u5vpdtk4tcjb7bx5qavo4fgthm73ra",
"bafyr4igb6depnsaoyu4vj24bve5rp53zvwamnedh2ru2zvuaijlvf7b2oe",
);

let stats = store.to_stats().await;
Expand All @@ -481,8 +481,8 @@ async fn for_each() {
reads: 29,
writes: 30,
removes: 0,
bytes_read: 2536,
bytes_written: 3803,
bytes_read: 2480,
bytes_written: 3691,
bytes_removed: 0,
flushes: 0
}
Expand Down Expand Up @@ -708,7 +708,7 @@ async fn clean_child_ordering() {
let root = h.flush().await.unwrap();
assert_eq!(
root.to_string().as_str(),
"bafy2bzacebqox3gtng4ytexyacr6zmaliyins3llnhbnfbcrqmhzuhmuuawqk"
"bafyr4ic3fjkghhv2aedghk2otgnjq4ykjfcm3lsks3uue3l6qffr7ndnfq"
);
let mut h = Hamt::<_, u8>::load_with_bit_width(&root, store.clone(), 5)
.await
Expand All @@ -723,7 +723,7 @@ async fn clean_child_ordering() {

assert_eq!(
root.to_string().as_str(),
"bafy2bzacedlyeuub3mo4aweqs7zyxrbldsq2u4a2taswubudgupglu2j4eru6"
"bafyr4ihgjokfxpyh7qnprh5odqc3isvvf4obldvpzc2l7odyhsri7lw67u"
);

let stats = store.to_stats().await;
Expand All @@ -734,8 +734,8 @@ async fn clean_child_ordering() {
reads: 3,
writes: 11,
removes: 0,
bytes_read: 1449,
bytes_written: 1751,
bytes_read: 1415,
bytes_written: 1717,
bytes_removed: 0,
flushes: 0
}
Expand Down
8 changes: 4 additions & 4 deletions rust/noosphere-ns/src/records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ mod test {
async fn test_nsrecord_self_signed() -> Result<(), anyhow::Error> {
let sphere_key = generate_ed25519_key();
let sphere_identity = Did::from(sphere_key.get_did().await?);
let link = "bafy2bzacec4p5h37mjk2n6qi6zukwyzkruebvwdzqpdxzutu4sgoiuhqwne72";
let link = "bafyr4iagi6t6khdrtbhmyjpjgvdlwv6pzylxhuhstxhkdp52rju7er325i";
let cid_link: Cid = link.parse()?;
let store = SphereDb::new(&MemoryStorage::default()).await.unwrap();

Expand All @@ -461,7 +461,7 @@ mod test {
let sphere_key = generate_ed25519_key();
let sphere_identity = Did::from(sphere_key.get_did().await?);
let mut did_parser = DidParser::new(SUPPORTED_KEYS);
let link = "bafy2bzacec4p5h37mjk2n6qi6zukwyzkruebvwdzqpdxzutu4sgoiuhqwne72";
let link = "bafyr4iagi6t6khdrtbhmyjpjgvdlwv6pzylxhuhstxhkdp52rju7er325i";
let cid_link: Cid = link.parse()?;
let mut store = SphereDb::new(&MemoryStorage::default()).await.unwrap();

Expand All @@ -485,8 +485,8 @@ mod test {
.build()?
.sign()
.await?;
let _ = store.write_token(&delegate_ucan.encode()?).await?;

let out_cid = store.write_token(&delegate_ucan.encode()?).await?;
println!("OUT CID {}", out_cid.to_string());
// Attempt `owner` publishing `sphere` with the proper authorization.
let proofs = vec![delegate_ucan.clone()];
let record =
Expand Down
2 changes: 1 addition & 1 deletion rust/noosphere-storage/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub trait BlockStore: Clone + BlockStoreSendSync {
{
let codec = C::default();
let block = codec.encode(&data)?;
let cid = Cid::new_v1(codec.into(), Code::Blake2b256.digest(&block));
let cid = Cid::new_v1(codec.into(), Code::Blake3_256.digest(&block));

self.put_block(&cid, &block).await?;
self.put_links::<C>(&cid, &block).await?;
Expand Down
4 changes: 2 additions & 2 deletions rust/noosphere-storage/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ pub fn base64_decode(encoded: &str) -> Result<Vec<u8>> {
Ok(base64::decode_config(encoded, base64::URL_SAFE_NO_PAD)?)
}

/// Produces a CID for a block with a Blake2b hash; note that the bytes are
/// Produces a CID for a block with a Blake3_256 hash; note that the bytes are
/// presumed to be encoded with the specified codec (honor system; this is
/// not validated in any way).
pub fn derive_cid<C>(block: &[u8]) -> Cid
where
C: Codec + Default,
u64: From<C>,
{
Cid::new_v1(u64::from(C::default()), Code::Blake2b256.digest(block))
Cid::new_v1(u64::from(C::default()), Code::Blake3_256.digest(block))
}

/// Encode any encodable type as a block using the specified codec
Expand Down

0 comments on commit 1de305a

Please sign in to comment.