diff --git a/Cargo.lock b/Cargo.lock index a4a721e..5a5b99a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.1.3" @@ -19,9 +34,58 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +dependencies = [ + "derive_arbitrary", +] + +[[package]] +name = "arrayref" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "assert_matches" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" + +[[package]] +name = "async-stream" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd56dd203fef61ac097dd65721a419ddccb106b2d2b70ba60a6b529f03961a51" +dependencies = [ + "async-stream-impl", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] [[package]] name = "atty" @@ -36,9 +100,24 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] [[package]] name = "base-x" @@ -69,15 +148,59 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "blake2s_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94230421e395b9920d23df13ea5d77a20e1725331f90fbbf6df6040b33f756ae" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + +[[package]] +name = "blake3" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30cca6d3674597c30ddf2c587bf8d9d65c9a84d2326d941cc79c9842dfe0ef52" +dependencies = [ + "arrayref", + "arrayvec", + "cc", + "cfg-if 1.0.0", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] [[package]] name = "blockstore" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358358b19add120a5afc3dd1c8e9161d6d06c44dfec2ef8da58b7fe5c369c90d" +checksum = "65439a69f3edc14658a7e1e14336b7e5668741c7eb54a79234686a10727a9be1" dependencies = [ "cid", "dashmap", @@ -91,6 +214,18 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + [[package]] name = "cast" version = "0.3.0" @@ -106,6 +241,12 @@ dependencies = [ "serde", ] +[[package]] +name = "cc" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" + [[package]] name = "cfg-if" version = "0.1.10" @@ -173,21 +314,21 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.4" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" dependencies = [ "anstyle", - "clap_lex 0.7.0", + "clap_lex 0.7.1", ] [[package]] @@ -201,9 +342,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "console_error_panic_hook" @@ -215,6 +356,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + [[package]] name = "core2" version = "0.4.0" @@ -224,6 +371,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + [[package]] name = "criterion" version = "0.4.0" @@ -257,7 +413,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.5.4", + "clap 4.5.8", "criterion-plot", "is-terminal", "itertools", @@ -305,9 +461,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -315,6 +471,16 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "dashmap" version = "5.5.3" @@ -322,7 +488,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "hashbrown 0.14.3", + "hashbrown 0.14.5", "lock_api", "once_cell", "parking_lot_core", @@ -330,15 +496,15 @@ dependencies = [ [[package]] name = "data-encoding" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" [[package]] name = "data-encoding-macro" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20c01c06f5f429efdf2bae21eb67c28b3df3cf85b7dd2d8ef09c0838dac5d33e" +checksum = "f1559b6cba622276d6d63706db152618eeb15b89b3e4041446b05876e352e639" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -346,25 +512,46 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0047d07f2c89b17dd631c80450d69841a6b5d7fb17278cbc43d7e4cfcf2576f3" +checksum = "332d754c0af53bc87c108fed664d121ecf59207ec4196041f04d6ab9002ad33f" dependencies = [ "data-encoding", "syn 1.0.109", ] +[[package]] +name = "derive_arbitrary" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "either" -version = "1.11.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "equivalent" @@ -374,9 +561,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys", @@ -384,9 +571,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fnv" @@ -400,17 +587,39 @@ version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", "libc", "wasi", ] +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + [[package]] name = "half" version = "2.4.1" @@ -429,9 +638,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" @@ -465,29 +674,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.3", + "hashbrown 0.14.5", ] [[package]] name = "inline_ipld" version = "0.1.0" dependencies = [ + "assert_matches", "blockstore", + "cid", "console_error_panic_hook", "criterion 0.4.0", "criterion 0.5.1", "futures", "ipld-core", "js-sys", - "multihash", + "multihash-codetable", "multihash-derive", "nonempty", "pretty_assertions", "proptest", + "proptest-arbitrary-interop", "serde", "serde_ipld_dagcbor", + "serde_ipld_dagjson", "thiserror", - "trait-variant", + "tokio", + "tokio-test", "wasm-bindgen", "wasm-bindgen-futures 0.3.27", "wasm-bindgen-test", @@ -497,8 +711,7 @@ dependencies = [ [[package]] name = "ipld-core" version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ede82a79e134f179f4b29b5fdb1eb92bd1b38c4dfea394c539051150a21b9b" +source = "git+https://github.com/expede/rust-ipld-core?branch=compose-codecs#b56d3afee2d79c20b06d481a3e61c0e80347f841" dependencies = [ "cid", "serde", @@ -540,17 +753,26 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libm" @@ -560,15 +782,15 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -576,15 +798,24 @@ dependencies = [ [[package]] name = "log" -version = "0.4.21" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] [[package]] name = "multibase" @@ -608,6 +839,26 @@ dependencies = [ "unsigned-varint 0.7.2", ] +[[package]] +name = "multihash-codetable" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c35f0fb09f635b18e95053fc2a9a4843272d3acf898792a14471dcf6f83df0cc" +dependencies = [ + "arbitrary", + "blake2b_simd", + "blake2s_simd", + "blake3", + "core2", + "digest", + "multihash-derive", + "ripemd", + "sha1", + "sha2", + "sha3", + "strobe-rs", +] + [[package]] name = "multihash-derive" version = "0.9.0" @@ -621,15 +872,15 @@ dependencies = [ [[package]] name = "multihash-derive-impl" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d38685e08adb338659871ecfc6ee47ba9b22dcc8abcf6975d379cc49145c3040" +checksum = "3958713ce794e12f7c6326fac9aa274c68d74c4881dd37b3e2662b8a2046bb19" dependencies = [ "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.68", "synstructure", ] @@ -641,14 +892,23 @@ checksum = "995defdca0a589acfdd1bd2e8e3b896b4d4f7675a31fd14c32611440c7f608e6" [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", ] +[[package]] +name = "object" +version = "0.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.19.0" @@ -669,22 +929,28 @@ checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets", ] +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + [[package]] name = "plotters" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" dependencies = [ "num-traits", "plotters-backend", @@ -695,15 +961,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" +checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" [[package]] name = "plotters-svg" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" dependencies = [ "plotters-backend", ] @@ -726,11 +992,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "1.3.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" dependencies = [ - "once_cell", + "toml_datetime", "toml_edit", ] @@ -760,22 +1026,22 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.81" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.5.0", + "bitflags 2.6.0", "lazy_static", "num-traits", "rand", @@ -787,6 +1053,16 @@ dependencies = [ "unarray", ] +[[package]] +name = "proptest-arbitrary-interop" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1981e49bd2432249da8b0e11e5557099a8e74690d6b94e721f7dc0bb7f3555f" +dependencies = [ + "arbitrary", + "proptest", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -863,18 +1139,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.6.0", ] [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -884,9 +1160,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -895,17 +1171,32 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -926,9 +1217,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -953,37 +1244,37 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.198" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] name = "serde_ipld_dagcbor" -version = "0.6.0" -source = "git+https://github.com/expede/serde_ipld_dagcbor.git#47594a9f20f814af47143617d7acb8954087b261" +version = "0.6.1" +source = "git+https://github.com/expede/serde_ipld_dagcbor?branch=from_u64#7244516f85046dc8859497bb980d1bd82c5f3052" dependencies = [ "cbor4ii", "ipld-core", @@ -991,23 +1282,84 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_ipld_dagjson" +version = "0.2.0" +source = "git+https://github.com/expede/serde_ipld_dagjson?branch=update-codec#021b0ef2321b1bedaef918d287758104e8477c8b" +dependencies = [ + "ipld-core", + "serde", + "serde_json", +] + [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ "itoa", "ryu", "serde", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "strobe-rs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabb238a1cccccfa4c4fb703670c0d157e1256c1ba695abf1b93bd2bb14bab2d" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "keccak", + "subtle", + "zeroize", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "1.0.109" @@ -1021,9 +1373,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.60" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -1032,14 +1384,13 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.12.6" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", - "unicode-xid", + "syn 2.0.68", ] [[package]] @@ -1062,22 +1413,22 @@ checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.59" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -1090,17 +1441,63 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tokio" +version = "1.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a" +dependencies = [ + "backtrace", + "pin-project-lite", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + +[[package]] +name = "tokio-stream" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-test" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2468baabc3311435b55dd935f702f42cd1b8abb7e754fb7dfb16bd36aa88f9f7" +dependencies = [ + "async-stream", + "bytes", + "futures-core", + "tokio", + "tokio-stream", +] + [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.15" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" dependencies = [ "indexmap 2.2.6", "toml_datetime", @@ -1108,15 +1505,10 @@ dependencies = [ ] [[package]] -name = "trait-variant" -version = "0.1.2" +name = "typenum" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70977707304198400eb4835a78f6a9f928bf41bba420deb8fdb175cd965d77a7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.60", -] +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unarray" @@ -1130,12 +1522,6 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "unsigned-varint" version = "0.7.2" @@ -1200,7 +1586,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -1247,7 +1633,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1280,7 +1666,7 @@ checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.60", + "syn 2.0.68", ] [[package]] @@ -1311,11 +1697,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys", ] [[package]] @@ -1330,22 +1716,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1354,46 +1725,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -1406,48 +1759,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" @@ -1468,3 +1797,23 @@ name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] diff --git a/Cargo.toml b/Cargo.toml index 2599d02..7397a65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,9 @@ authors = ["Brooklyn Zelenka "] edition = "2021" license = "Apache-2.0" +[package.metadata.docs.rs] +all-features = true + [lib] bench = false crate-type = ["cdylib", "rlib"] @@ -25,24 +28,27 @@ name = "bench" harness = false [features] -# default = ["dag-cbor", "dag-json", "serde-codec"] -# dag-cbor = ["libipld-cbor"] -# dag-json = ["libipld-json"] -# serde-codec = ["libipld/serde-codec", "serde"] +default = ["dag_cbor", "dag_json"] +dag_cbor = ["serde_ipld_dagcbor", "serde_ipld_dagcbor/std", "serde_ipld_dagcbor/codec"] +dag_json = ["serde_ipld_dagjson"] +test_utils = ["multihash-codetable", "multihash-codetable/arb", "proptest", "proptest-arbitrary-interop", "serde_ipld_dagjson"] +total_codec = [] [dependencies] -# FIXME ipld_dagpb = { version = "0.2", optional = true } -serde_ipld_dagcbor = { version = "0.6", git = "https://github.com/expede/serde_ipld_dagcbor.git" } -# FIXME serde_ipld_dagcbor = { version = "0.6", optional = true } -# FIXME serde_ipld_dagjson = { version = "0.2", optional = true } -blockstore = "0.5" -ipld-core = { version = "0.4", features = ["serde"] } -multihash = "0.19" -multihash-derive = "0.9" +serde_ipld_dagcbor = { version = "0.6", git = "https://github.com/expede/serde_ipld_dagcbor", branch = "from_u64", optional = true, features = ["std", "codec"] } +serde_ipld_dagjson = { version = "0.2", git = "https://github.com/expede/serde_ipld_dagjson", branch = "update-codec", optional = true } +blockstore = "0.6" +cid = "0.11" +ipld-core = { version = "0.4.1", features = ["serde"], git = "https://github.com/expede/rust-ipld-core", branch = "compose-codecs" } +multihash-derive = { version = "0.9" } +multihash-codetable = { version = "0.1", optional = true, features = ["sha2"] } nonempty = "0.9.0" -serde = { version = "1.0", optional = true } +proptest = { version = "1.5", optional = true } +serde = { version = "1.0" } # FIXME, optional = true } thiserror = "1.0" -trait-variant = "0.1.2" +# trait-variant = "0.1.2" + +proptest-arbitrary-interop = { version = "0.1", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = { version = "0.1", optional = true } @@ -50,7 +56,14 @@ wasm-bindgen = "0.2" web-sys = {version = "0.3", features = ["console"]} [dev-dependencies] +assert_matches = "1.5" pretty_assertions = "1.4" +tokio = { version = "1.38", features = ["macros"] } +tokio-test = "0.4" + +# FIXME? +proptest-arbitrary-interop = "0.1" +multihash-codetable = { version = "0.1", features = ["arb", "sha2"] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] criterion = "0.5" diff --git a/flake.lock b/flake.lock index 2b598e6..9cca9b8 100644 --- a/flake.lock +++ b/flake.lock @@ -56,11 +56,11 @@ }, "nixos-unstable": { "locked": { - "lastModified": 1713454724, - "narHash": "sha256-0Htjy5e/ELoFH9/r20/9MsGHLD9adqsPMF5ns8B0m74=", + "lastModified": 1719451888, + "narHash": "sha256-Ky0sgEEJMcBmNEJztY6KcVn+6bq74EKM7pd1CR1wnPQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "bc279bbacf1f11a48e1f9cdf32228f27e28f0291", + "rev": "3664857c48feacb35770c00abfdc671e55849be5", "type": "github" }, "original": { @@ -86,11 +86,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1713344939, - "narHash": "sha256-jpHkAt0sG2/J7ueKnG7VvLLkBYUMQbXQ2L8OBpVG53s=", + "lastModified": 1719234068, + "narHash": "sha256-1AjSIedDC/aERt24KsCUftLpVppW61S7awfjGe7bMio=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e402c3eb6d88384ca6c52ef1c53e61bdc9b84ddd", + "rev": "90bd1b26e23760742fdcb6152369919098f05417", "type": "github" }, "original": { @@ -110,19 +110,16 @@ }, "rust-overlay": { "inputs": { - "flake-utils": [ - "flake-utils" - ], "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1713406362, - "narHash": "sha256-85f70DM03RWqzahxXChSWcbnUYAKYBDBvyQ4P+kXVBk=", + "lastModified": 1719454714, + "narHash": "sha256-MojqG0lyUINkEk0b3kM2drsU5vyaF8DFZe/FAlZVOGs=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "05a4f1b28ee59f589c8a0ad877741de3c3bf894d", + "rev": "d1c527659cf076ecc4b96a91c702d080b213801e", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 34c3b8e..399f104 100644 --- a/flake.nix +++ b/flake.nix @@ -153,10 +153,13 @@ "${cargo} watch --clear --exec 'clippy -- -W clippy::pedantic'"; "watch:test:host" = cmd "Run all host tests on save" - "${cargo} watch --clear --exec 'test --features=test_utils'"; + "${cargo} watch --clear --exec 'test --all-features'"; + + "watch:test:docs" = cmd "Run all host tests on save" + "${cargo} watch --clear --exec 'test --doc --all-features'"; "watch:test:wasm" = cmd "Run all Wasm tests on save" - "${cargo} watch --clear --exec 'test --target=wasm32-unknown-unknown'"; + "${cargo} watch --clear --exec 'test --all-features --target=wasm32-unknown-unknown'"; }; test = { diff --git a/inline_ipld/src/store/memory.rs b/inline_ipld/src/store/memory.rs deleted file mode 100644 index 8b13789..0000000 --- a/inline_ipld/src/store/memory.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/cid/config.rs b/src/cid/config.rs index 49e24bc..34b4ce5 100644 --- a/src/cid/config.rs +++ b/src/cid/config.rs @@ -7,37 +7,37 @@ use ipld_core::{ codec::Codec, ipld::Ipld, }; -use multihash_derive::Hasher; +use multihash_derive::MultihashDigest; /// A container for the configuration of a [`Cid`] #[derive(Copy, Clone, Debug, PartialEq)] -pub struct Config + Clone, H: Hasher + Clone> { +pub struct Config + Clone, H: MultihashDigest<64>> { // FIXME force these to be copy? /// The codec to use pub codec: C, /// The hash digest function to use - pub hasher: H, + pub multihasher: H, /// The version of the CID to create pub version: Version, // FIXME needs to conatrain version to codec } -impl + Clone, H: Hasher + Into + Clone> Config { +impl + Clone, H: MultihashDigest<64>> Config { /// Create a [`Cid`] for some [`Ipld`] /// /// # Examples /// /// ``` /// # use inline_ipld::cid; - /// # use libipld::{ipld, cid::Version}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use ipld_core::{ipld, cid::Version}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use multihash_codetable::Code::Sha2_256; /// # use std::{collections::BTreeMap, str::FromStr}; /// # /// let cfg = cid::Config { /// codec: DagCborCodec, - /// hasher: Sha2_256, + /// multihasher: Sha2_256, /// version: Version::V1, /// }; /// @@ -51,24 +51,20 @@ impl + Clone, H: Hasher + Into + Clone> Config { /// assert_eq!(observed_456, expected_456); /// ``` pub fn cidify>(&self, ipld: &I) -> Cid { - util::new(ipld, self.codec.clone(), self.hasher.clone(), self.version) + util::new(ipld, self.codec.clone(), self.multihasher, self.version) } } -impl + Clone + TryFrom, H: Hasher + TryFrom + Clone> TryFrom<&Cid> - for Config -{ +impl + Clone, H: MultihashDigest<64>> TryFrom<&Cid> for Config { type Error = ConfigError; fn try_from(cid: &Cid) -> Result { - let raw_codec = cid.codec(); + let code = cid.codec(); let raw_hasher = cid.hash().code(); Ok(Config { - codec: raw_codec - .try_into() - .map_err(|_| ConfigError::CodecDecodeError(raw_codec))?, - hasher: raw_hasher + codec: C::try_from_code(code).ok_or(ConfigError::CodecDecodeError(code))?, + multihasher: raw_hasher .try_into() .map_err(|_| ConfigError::HasherDecodeError(raw_hasher))?, version: cid.version(), @@ -77,32 +73,33 @@ impl + Clone + TryFrom, H: Hasher + TryFrom + Clone> Tr } #[cfg(test)] -use libipld::cid; +use ipld_core::cid; #[cfg(test)] use proptest::prelude::*; #[cfg(test)] -impl + Arbitrary + Default, H: Arbitrary + Hasher> Arbitrary for Config { +use proptest_arbitrary_interop::{arb, ArbInterop}; + +#[cfg(test)] +impl< + C: 'static + Codec + Arbitrary + Default + Clone, + // FIXME H: ArbInterop + MultihashDigest<64>, + > Arbitrary for Config +{ type Parameters = (); type Strategy = BoxedStrategy; fn arbitrary_with(_: Self::Parameters) -> Self::Strategy { - prop_oneof![ - // IPLD encoding in libipld currently always fails with DagPb, so generic CID v0 fails - // any::().prop_map(|SuperMultihash(hasher)| CidConfig { - // hasher: hasher, - // codec: IpldCodec::DagPb, - // version: cid::Version::V0, - // }), - (any::(), any::()).prop_map(|(codec, hasher)| { + prop_oneof![(any::(), arb::()).prop_map( + |(codec, multihasher)| { Config { codec, - hasher, + multihasher, version: cid::Version::V1, } - }), - ] + } + )] .boxed() } } @@ -111,16 +108,18 @@ impl + Arbitrary + Default, H: Arbitrary + Hasher> Arbitrary for mod tests { use super::*; use crate::{ - cid::config::Config, codec::TotalCodec, test_util::super_ipld::SuperIpld, - test_util::super_multihash::SuperMultihash, + cid::config::Config, + codec::total::TotalCodec, + test_util::super_ipld::SuperIpld, + // test_util::super_multihash::SuperMultihash, }; proptest! { #[test] - fn cifidy_config_prop_test((SuperIpld(ipld), cfg @ Config {codec, hasher, version}) in (any::(), any::>())) { + fn cifidy_config_prop_test((SuperIpld(ipld), cfg @ Config {codec, multihasher, version}) in (any::(), any::>())) { let cid = cfg.cidify(&ipld); - prop_assert_eq!(cid.codec(), u64::from(codec)); - prop_assert_eq!(cid.hash().code(), u64::from(hasher)); + prop_assert_eq!(cid.codec(), >::to_code(&codec)); + prop_assert_eq!(cid.hash().code(), u64::from(multihasher)); prop_assert_eq!(cid.version(), version); } } diff --git a/src/cid/error.rs b/src/cid/error.rs index 431acca..4382122 100644 --- a/src/cid/error.rs +++ b/src/cid/error.rs @@ -21,7 +21,11 @@ pub enum ConfigError { // #[derive(Clone, Debug, Error, PartialEq, Eq)] // #[error("Unsupported codec {0}")] // pub struct UnsupportedCodec(pub u64); - +// // #[derive(Clone, Debug, Error, PartialEq, Eq)] // #[error("Block not found: {0}")] // pub struct BlockNotFound(pub Cid); +// +// #[derive(Clone, Debug, Error, PartialEq, Eq)] +// #[error("Unable to store block: {0}")] +// pub struct BlockStoreError(pub Cid); // FIXME BlockStorageError? diff --git a/src/cid/util.rs b/src/cid/util.rs index ca2fe9f..07c417f 100644 --- a/src/cid/util.rs +++ b/src/cid/util.rs @@ -1,21 +1,15 @@ use crate::codec::EncodableAs; -use ipld_core::{ - cid, - cid::{Cid, CidGeneric}, - codec::Codec, - ipld::Ipld, -}; -use multihash::Multihash; -use multihash_derive::Hasher; +use ipld_core::{cid, cid::CidGeneric, codec::Codec, ipld::Ipld}; +use multihash_derive::MultihashDigest; /// Create a [`Cid`] for some [`Ipld`] /// /// # Arguments /// -/// * `ipld` - [`Ipld`] to create the [`Cid`] for -/// * `codec` - The [`Codec`] the [`Ipld`] is encoded with -/// * `hasher` - The [`MultihashDigest`] used in the [`Cid`] -/// * `version` - The [`Cid`] version +/// * `ipld` - [`Ipld`] to create the [`Cid`] for +/// * `codec` - The [`Codec`] the [`Ipld`] is encoded with +/// * `multihasher` - The [`MultihashDigest`] used in the [`Cid`] +/// * `version` - The [`Cid`] version /// /// # Panics /// @@ -26,29 +20,25 @@ use multihash_derive::Hasher; /// /// ``` /// # use inline_ipld::cid; -/// # use libipld::{ipld, cid::Version}; -/// # use libipld::cbor::DagCborCodec; -/// # use multihash::Code::Sha2_256; +/// # use ipld_core::{ipld, cid::Version}; +/// # use serde_ipld_dagcbor::codec::DagCborCodec; +/// # use multihash_codetable::Code::Sha2_256; /// # use std::{collections::BTreeMap, str::FromStr}; /// # /// let observed = cid::new(&ipld!([1, 2, 3]), DagCborCodec, Sha2_256, Version::V1); /// let expected = FromStr::from_str("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44").unwrap(); /// assert_eq!(observed, expected); /// ``` -pub fn new, H: Hasher + Into + Clone, I: EncodableAs>( +pub fn new + Clone, H: MultihashDigest, I: EncodableAs>( ipld: &I, codec: C, - mut hasher: H, + multihasher: H, version: cid::Version, -) -> Cid { - let encoded: Vec = ipld.encodable_as(codec).guaranteed_encode(); - let code = hasher.clone().into(); +) -> CidGeneric { + let encoded: Vec = ipld.encodable_as(codec.clone()).guaranteed_encode(); + let multihash = multihasher.digest(encoded.as_slice()); - hasher.update(&encoded); // FIXME traot Multihasher - let hash = hasher.finalize(); - let multihash = Multihash::wrap(code, hash).unwrap(); // FIXME - - CidGeneric::new(version, C::CODE, multihash) + CidGeneric::new(version, codec.to_code(), multihash) .expect("should not fail unless `EncodableAs` is improperly implemented for your codec") } @@ -56,16 +46,18 @@ pub fn new, H: Hasher + Into + Clone, I: EncodableAs>( mod tests { use super::*; use crate::{ - cid::config::Config, codec::TotalCodec, test_util::super_ipld::SuperIpld, - test_util::super_multihash::SuperMultihash, + cid::config::Config, + codec::total::TotalCodec, + test_util::super_ipld::SuperIpld, + // test_util::super_multihash::SuperMultihash, }; - use libipld::cbor::DagCborCodec; use proptest::prelude::*; + use serde_ipld_dagcbor::codec::DagCborCodec; proptest! { #[test] - fn basic_build_prop_test((SuperIpld(ipld), Config {hasher, version, ..}) in (any::(), any::>())) { - let observed = new(&ipld, DagCborCodec, hasher, version); + fn basic_build_prop_test((SuperIpld(ipld), Config {multihasher, version, ..}) in (any::(), any::>())) { + let observed = new(&ipld, DagCborCodec, multihasher, version); prop_assert_eq!(observed.codec(), ::from(DagCborCodec)); prop_assert_eq!(observed.version(), version); } diff --git a/src/codec.rs b/src/codec.rs index ae21279..66f88ed 100644 --- a/src/codec.rs +++ b/src/codec.rs @@ -3,3 +3,6 @@ mod encodable; pub use encodable::{EncodableAs, EncodableIpld}; + +#[cfg(feature = "total_codec")] +pub mod total; diff --git a/src/codec/encodable/ipld.rs b/src/codec/encodable/ipld.rs index b9af986..6d3c9d6 100644 --- a/src/codec/encodable/ipld.rs +++ b/src/codec/encodable/ipld.rs @@ -38,8 +38,8 @@ impl<'a, C: Codec> EncodableIpld<'a, C> { /// /// ``` /// # use inline_ipld::codec::{EncodableAs, EncodableIpld}; - /// # use libipld::{ipld, codec::Codec}; - /// # use libipld_cbor::DagCborCodec; + /// # use ipld_core::{ipld, codec::Codec}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; /// # use pretty_assertions::assert_eq; /// # /// let dag = ipld!([1, 2, 3]); @@ -48,7 +48,7 @@ impl<'a, C: Codec> EncodableIpld<'a, C> { /// assert_eq!(observed, vec![0x83, 0x01, 0x02, 0x03]); /// ``` pub fn guaranteed_encode(&self) -> Vec { - match C::encode_to_vec(&self.ipld) { + match self.codec.encode_to_vec(&self.ipld) { Ok(bytes) => bytes, Err(_err) => panic!("should never fail if `encodable_as` is implemented correctly"), } diff --git a/src/codec/encodable/traits.rs b/src/codec/encodable/traits.rs index 4f883b8..d80929a 100644 --- a/src/codec/encodable/traits.rs +++ b/src/codec/encodable/traits.rs @@ -4,10 +4,13 @@ use super::ipld::EncodableIpld; use ipld_core::{codec::Codec, ipld::Ipld}; #[cfg(feature = "dag-cbor")] -use libipld_cbor::DagCborCodec; +use serde_ipld_dagcbor::DagCborCodec; #[cfg(feature = "dag-json")] -use libipld_json::DagJsonCodec; +use serde_ipld_dagjson::DagJsonCodec; + +#[cfg(feature = "total_codec")] +use crate::codec::total::TotalCodec; /// [`EncodableAs`] describes codecs that never fail on data that can /// be [`encode`][libipld::codec::Encode::encode]d as [`Ipld`] @@ -45,8 +48,8 @@ pub trait EncodableAs> { /// /// ``` /// # use inline_ipld::codec::EncodableAs; - /// # use libipld::{Ipld, codec::Codec}; - /// # use libipld_cbor::DagCborCodec; + /// # use ipld_core::{ipld::Ipld, codec::Codec}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; /// # use pretty_assertions::assert_eq; /// # /// let dag = Ipld::Float(3.14159); @@ -55,6 +58,12 @@ pub trait EncodableAs> { /// assert_eq!(observed, vec![251, 64, 9, 33, 249, 240, 27, 134, 110]); /// ``` fn encodable_as<'a>(&'a self, codec: C) -> EncodableIpld<'a, C>; + + /// Encode some [`Ipld`] to a [`Vec`] of bytes using the specified "guaranteed" codec + /// FIXME show example + fn encode_to(&self, codec: C) -> Vec { + self.encodable_as(codec).guaranteed_encode() + } } impl<'a, C: Codec + Copy> EncodableAs for EncodableIpld<'a, C> { @@ -70,9 +79,17 @@ impl EncodableAs for Ipld { } } -#[cfg(feature = "dag-cbor")] -impl EncodableAs for Ipld { +// FIXME #[cfg(feature = "dag-cbor")] +use serde_ipld_dagcbor::codec::DagCborCodec; +impl EncodableAs<::serde_ipld_dagcbor::codec::DagCborCodec> for Ipld { fn encodable_as(&self, codec: DagCborCodec) -> EncodableIpld { EncodableIpld { ipld: self, codec } } } + +#[cfg(feature = "total_codec")] +impl EncodableAs for Ipld { + fn encodable_as(&self, codec: TotalCodec) -> EncodableIpld { + EncodableIpld { ipld: self, codec } + } +} diff --git a/src/codec/total.rs b/src/codec/total.rs new file mode 100644 index 0000000..d20e93d --- /dev/null +++ b/src/codec/total.rs @@ -0,0 +1,128 @@ +use ipld_core::{ + cid::Cid, + codec::{Codec, Links}, + ipld::Ipld, +}; +use std::io::{BufRead, Write}; +use thiserror::Error; + +#[cfg(feature = "dag_cbor")] +use serde_ipld_dagcbor::codec::DagCborCodec; + +#[cfg(feature = "dag_json")] +use serde_ipld_dagjson::codec::DagJsonCodec; + +#[cfg(feature = "test_utils")] +use proptest::prelude::*; + +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum TotalCodec { + #[default] + DagCbor, + DagJson, +} + +impl Links for TotalCodec { + type LinksError = LinksError; + + fn links(&self, bytes: &[u8]) -> Result, Self::LinksError> { + match self { + TotalCodec::DagCbor => Ok(DagCborCodec.links(bytes)?.collect::>().into_iter()), // FIXME gross + TotalCodec::DagJson => Ok(DagJsonCodec.links(bytes)?.collect::>().into_iter()), // FIXME gross + } + } +} + +#[derive(Debug, Error)] +pub enum LinksError { + #[error("dag-cbor links error: {0}")] + DagCborLinksError(#[from] serde_ipld_dagcbor::error::CodecError), + + #[error("dag-json links error: {0}")] + DagJsonLinksError(#[from] serde_ipld_dagjson::error::CodecError), +} + +impl serde::Deserialize<'de>> Codec for TotalCodec { + type Error = (); // FIXME + + fn to_code(&self) -> u64 { + match self { + TotalCodec::DagCbor => Codec::::to_code(&DagCborCodec), + TotalCodec::DagJson => Codec::::to_code(&DagJsonCodec), + } + } + + fn try_from_code(code: u64) -> Option { + if code == Codec::::to_code(&DagCborCodec) { + return Some(TotalCodec::DagCbor); + } + + if code == Codec::::to_code(&DagJsonCodec) { + return Some(TotalCodec::DagJson); + } + + None + } + + fn encode(&self, writer: W, data: &T) -> Result<(), Self::Error> { + match self { + TotalCodec::DagCbor => DagCborCodec.encode(writer, data).map_err(|_| ()), + TotalCodec::DagJson => DagJsonCodec.encode(writer, data).map_err(|_| ()), + } + } + + fn decode(&self, reader: R) -> Result { + match self { + TotalCodec::DagCbor => DagCborCodec.decode(reader).map_err(|_| ()), + TotalCodec::DagJson => DagJsonCodec.decode(reader).map_err(|_| ()), + } + } +} + +#[cfg(feature = "dag_cbor")] +impl From for TotalCodec { + fn from(_: DagCborCodec) -> Self { + TotalCodec::DagCbor + } +} + +#[cfg(feature = "dag_json")] +impl From for TotalCodec { + fn from(_: DagJsonCodec) -> Self { + TotalCodec::DagJson + } +} + +#[cfg(feature = "dag_cbor")] +impl TryFrom for DagCborCodec { + type Error = &'static str; + + fn try_from(value: TotalCodec) -> Result { + match value { + TotalCodec::DagCbor => Ok(DagCborCodec), + _ => Err("not a DagCborCodec"), + } + } +} + +#[cfg(feature = "dag_json")] +impl TryFrom for DagJsonCodec { + type Error = &'static str; + + fn try_from(value: TotalCodec) -> Result { + match value { + TotalCodec::DagJson => Ok(DagJsonCodec), + _ => Err("not a DagJsonCodec"), + } + } +} + +#[cfg(feature = "test_utils")] +impl Arbitrary for TotalCodec { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + prop_oneof![Just(TotalCodec::DagCbor), Just(TotalCodec::DagJson)].boxed() + } +} diff --git a/src/extractor.rs b/src/extractor.rs index 4b37a94..99f7351 100644 --- a/src/extractor.rs +++ b/src/extractor.rs @@ -5,30 +5,23 @@ use blockstore::Blockstore; use ipld_core::{ cid::{Cid, Version}, codec::Codec, + ipld, ipld::Ipld, }; -use multihash_derive::Hasher; +use multihash_derive::MultihashDigest; use serde_ipld_dagcbor::codec::DagCborCodec; use std::collections::btree_map::{BTreeMap, Keys}; -/// A common [`Extractor`] configuration -// FIXME pub type CommonExtractor<'a> = Extractor<'a, TotalCodec, multihash::Sha2_256>; - /// The general [`Ipld`] extraction strategy /// /// Converts Inline IPLD into "regular" [`Ipld`]. This does a series of graph nodes. #[derive(Clone, Debug, PartialEq)] -pub struct Extractor< - 'a, - C: Codec + Clone + TryFrom, - H: Hasher + Clone + Into + TryFrom, -> { +pub struct Extractor<'a, C: Codec + Clone, H: MultihashDigest<64>> { iterator: post_order::CidAware<'a, C, H>, stack: Vec, } -impl<'a, C: Codec + Clone + TryFrom, H: Hasher + Into + TryFrom + Clone> - Extractor<'a, C, H> +impl<'a, C: Codec + Clone, H: MultihashDigest<64>> Extractor<'a, C, H> where Ipld: EncodableAs, { @@ -36,17 +29,17 @@ where /// /// # Arguments /// - /// * `ipld` - The inline [`Ipld`] to extract - /// * `codec` - The [`Codec`] to fall back to if the inline IPLD doesn't contain a [`Cid`] - /// * `hasher` - The hash digest function to use if the inline IPLD doesn't contain a [`Cid`] + /// * `inline_ipld` - The [`InlineIpld`] to extract + /// * `codec` - The [`Codec`] to fall back to if the inline IPLD doesn't contain a [`Cid`] + /// * `multihasher` - The hash digest function to use if the inline IPLD doesn't contain a [`Cid`] /// * `cid_version` - The [`Cid`] version to use if the inline IPLD doesn't contain a [`Cid`] - pub fn new(inline_ipld: &'a InlineIpld, codec: C, hasher: H, version: Version) -> Self { + pub fn new(inline_ipld: &'a InlineIpld, codec: C, multihasher: H, version: Version) -> Self { Extractor { iterator: post_order::CidAware::new( - inline_ipld.into(), + inline_ipld.into(), // FIXME that `into` could be expensive cid::Config { codec, - hasher, + multihasher, version, }, ), @@ -68,42 +61,43 @@ where /// # Examples /// /// ``` - /// # use inline_ipld::{store::Store, extractor::Extractor, InlineIpld}; + /// # use inline_ipld::{extractor::Extractor, InlineIpld, codec::EncodableAs}; /// # - /// # use libipld::{ipld, cid::Version}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use ipld_core::{ipld, ipld::Ipld, cid::Cid, cid::Version, }; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use multihash_codetable::Code::Sha2_256; + /// # use blockstore::{Blockstore, InMemoryBlockstore}; /// # use std::{collections::BTreeMap, str::FromStr}; /// # - /// let inner = ipld!([4, 5, 6]); - /// let inner_cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); - /// - /// let outer = ipld!({"a": 123, "b": {".": [4, 5, 6]}}); - /// let outer_cid = FromStr::from_str("bafyreignkagaefshuw6wloom3qh2mb2ytavv6y3s7sogi7hpeoetb7ejki").unwrap(); + /// tokio_test::block_on(async { + /// let inner = ipld!([4, 5, 6]); + /// let inner_cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); /// - /// let mut expected = BTreeMap::new(); - /// expected.put_keyed(inner_cid, &ipld!([4, 5, 6])); - /// expected.put_keyed(outer_cid, &ipld!({"a": 123, "b": inner_cid})); + /// let outer = ipld!({"a": 123, "b": {".": [4, 5, 6]}}); + /// let outer_cid: Cid = FromStr::from_str("bafyreignkagaefshuw6wloom3qh2mb2ytavv6y3s7sogi7hpeoetb7ejki").unwrap(); /// - /// let inlined = InlineIpld::attest(ipld!({"a": 123, "b": {"/": {".": ipld!([4, 5, 6])}}})); - /// let mut extractor = Extractor::new(&inlined, DagCborCodec, Sha2_256, Version::V1); - /// let mut store = BTreeMap::new(); - /// extractor.extract_to(&mut store); + /// let inlined = InlineIpld::attest(ipld!({"a": 123, "b": {"/": {".": ipld!([4, 5, 6])}}})); + /// let mut extractor = Extractor::new(&inlined, DagCborCodec, Sha2_256, Version::V1); + /// let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); + /// extractor.extract_to(&mut store).await; /// - /// assert_eq!(store, expected); + /// assert_eq!(store.len(), 2); + /// assert_eq!(store.get(&inner_cid).await.unwrap(), Some(ipld!([4, 5, 6]).encode_to(DagCborCodec))); + /// assert_eq!(store.get(&outer_cid).await.unwrap(), Some(ipld!({"a": 123, "b": inner_cid}).encode_to(DagCborCodec))); + /// }); /// ``` /// /// FIXME show error case - pub async fn extract_to( + pub async fn extract_to( &mut self, - store: &mut S, + store: &mut B, ) -> Result<(), cid::error::ConfigError> { for result in self { match result { Err(err) => return Err(err), Ok((cid, ref dag)) => { - let bytes = >::encode_to_vec(dag).unwrap(); - store.put_keyed(&cid, &bytes).await.expect("FIXME"); + let bytes = DagCborCodec.encode_to_vec(dag).unwrap(); // FIXME + store.put_keyed(&cid, &bytes).await.expect("FIXME") } } } @@ -130,8 +124,7 @@ where } } -impl<'a, C: Codec + Clone + TryFrom, H: Hasher + Into + TryFrom + Clone> - Iterator for Extractor<'a, C, H> +impl<'a, C: Codec + Clone, H: MultihashDigest<64>> Iterator for Extractor<'a, C, H> where Ipld: EncodableAs, { @@ -217,30 +210,34 @@ where mod tests { use super::*; use crate::{ - cid, codec::TotalCodec, test_util::super_ipld::SuperIpld, - test_util::super_multihash::SuperMultihash, InlineIpld, + cid, + codec::total::TotalCodec, + test_util::super_ipld::SuperIpld, + // test_util::super_multihash::SuperMultihash, + InlineIpld, }; - use libipld::{cbor::DagCborCodec, cid::CidGeneric, ipld}; - use multihash::Code::Sha2_256; + use ipld_core::{cid::CidGeneric, ipld}; + use multihash_codetable::Code::Sha2_256; use pretty_assertions::assert_eq; use proptest::prelude::*; + use serde_ipld_dagcbor::codec::DagCborCodec; use std::collections::BTreeMap; // FIXME more props! proptest! { #[test] - fn identity_ipld_prop_test((SuperIpld(ipld), cid::Config{ hasher, version, codec }) in (any::(), any::>())) { + fn identity_ipld_prop_test((SuperIpld(ipld), cid::Config{ multihasher, version, codec }) in (any::(), any::>())) { let inline = InlineIpld::attest(ipld.clone()); - let mut ext = Extractor::new(&inline, codec, hasher, version); + let mut ext = Extractor::new(&inline, codec, multihasher, version); prop_assert_eq!(ext.next().unwrap().unwrap().1, ipld); } #[test] - fn correct_cid_prop_test((SuperIpld(ipld), cid::Config{ hasher, version, codec }) in (any::(), any::>())) { + fn correct_cid_prop_test((SuperIpld(ipld), cid::Config{ multihasher, version, codec }) in (any::(), any::>())) { let inline = InlineIpld::attest(ipld); - for result in Extractor::new(&inline, codec, hasher, version) { + for result in Extractor::new(&inline, codec, multihasher, version) { let (cid, ref dag) = result.expect("CIDs should parse successfully"); - prop_assert_eq!(cid, cid::new(dag, codec, hasher, version)); + prop_assert_eq!(cid, cid::new(dag, codec, multihasher, version)); } } } @@ -283,32 +280,21 @@ mod tests { observed.insert(cid, node); } - let cid1: Cid = + let cid: Cid = CidGeneric::try_from("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44") .unwrap(); - let cid2: Cid = - CidGeneric::try_from("bafyreihnubkcms63243zlfgnwiugmk6ijitz63me7bqf455ia2fpbn4ceq") - .unwrap(); - - let mut expected = BTreeMap::new(); - expected.insert(cid1, ipld!([1, 2, 3])); - expected.insert(cid2, ipld!(cid1)); - - assert_eq!(observed, expected); + assert!(observed.get(&cid).is_some()); + assert_eq!(observed.len(), 1); } #[test] fn store_single_top_linkful_test() { - let arr_cid: Cid = + let cid: Cid = CidGeneric::try_from("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44") .unwrap(); - let outer_cid: Cid = - CidGeneric::try_from("bafyreihnubkcms63243zlfgnwiugmk6ijitz63me7bqf455ia2fpbn4ceq") - .unwrap(); - - let inline = InlineIpld::new(Some(arr_cid), ipld!([1, 2, 3])); + let inline = InlineIpld::new(Some(cid), ipld!([1, 2, 3])); let mut observed: BTreeMap = BTreeMap::new(); for result in Extractor::new(&inline, DagCborCodec, Sha2_256, Version::V1) { @@ -317,8 +303,7 @@ mod tests { } let mut expected = BTreeMap::new(); - expected.insert(arr_cid, ipld!([1, 2, 3])); - expected.insert(outer_cid, ipld!(arr_cid)); + expected.insert(cid, ipld!([1, 2, 3])); assert_eq!(observed, expected); } diff --git a/src/inliner/at_least_once.rs b/src/inliner/at_least_once.rs index 4392056..8c65d04 100644 --- a/src/inliner/at_least_once.rs +++ b/src/inliner/at_least_once.rs @@ -3,7 +3,8 @@ use super::traits::{Inliner, Stuck}; use crate::{iterator::PostOrderIpldIter, InlineIpld}; use blockstore::Blockstore; -use ipld_core::{cid::Cid, ipld::Ipld}; +use ipld_core::{cid::Cid, codec::Codec, ipld::Ipld}; +use serde_ipld_dagcbor::codec::DagCborCodec; use std::collections::BTreeMap; /// Inline directly, stopping at missing nodes, but without deduplication. @@ -48,15 +49,15 @@ impl<'a> Iterator for AtLeastOnce<'a> { } } -use ipld_core::codec::Codec; -use serde_ipld_dagcbor::codec::DagCborCodec; - -async fn my_get(store: &S, cid: &Cid) -> Result { +async fn my_get( + store: &S, + cid: &Cid, +) -> Option> { match store.get(cid).await { - Err(err) => Err(err), + Err(err) => Some(Err(err)), // FIXME get the codec from the CID - Ok(Some(bytes)) => Ok(>::decode_from_slice(&bytes).unwrap()), - _ => panic!("No error, but no bytes either"), // FIXME + Ok(Some(bytes)) => Some(Ok(DagCborCodec.decode_from_slice(&bytes).unwrap())), + _ => None, // FIXME STUCK! } } @@ -72,8 +73,8 @@ impl<'a> Inliner for AtLeastOnce<'a> { ) -> Option>> { for node in &mut self.po { match node { - Ipld::Link(cid) => { - if let Ok(ipld) = my_get(store, cid).await { + Ipld::Link(cid) => match my_get(store, cid).await { + Some(Ok(ipld)) => { let mut inner = BTreeMap::new(); inner.insert("&".into(), Ipld::Link(*cid)); inner.insert(".".into(), ipld.clone()); @@ -82,10 +83,16 @@ impl<'a> Inliner for AtLeastOnce<'a> { outer.insert("/".into(), Ipld::Map(inner)); self.stack.push(Ipld::Map(outer)); - } else { + } + Some(Err(_err)) => { + // FIXME probably shoudl unify these errors instead of that `Option` return Some(Err(self.stuck_at(*cid))); } - } + None => { + self.needs = Some(*cid); + return Some(Err(self.stuck_at(*cid))); + } + }, Ipld::Map(btree) => { let keys = btree.keys(); @@ -115,23 +122,32 @@ impl<'a> Inliner for AtLeastOnce<'a> { #[cfg(test)] mod tests { use super::*; - use crate::store::MemoryStore; - use libipld::ipld; + use blockstore::InMemoryBlockstore; + use ipld_core::ipld; use pretty_assertions::assert_eq; use std::str::FromStr; - #[test] - fn inliner_resolve_test() { + #[tokio::test] + async fn resolve_with_ignore_test() { let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi") .unwrap(); - let mut store = MemoryStore::new(); + let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); + let dag = ipld!({"a": 1, "b": cid}); + let mut observed = None; - if let Some(Err(stuck)) = AtLeastOnce::new(&ipld!({"a": 1, "b": cid})).run(&mut store) { - observed = Some(stuck.ignore().run(&mut store).unwrap().unwrap()); + if let Some(Err(stuck)) = AtLeastOnce::new(&dag).run(&mut store).await { + observed = stuck.ignore().run(&mut store).await; } - assert_eq!(observed.unwrap(), ipld!({"a": 1, "b": cid})); + assert_eq!( + Ipld::from( + observed + .expect("not stuck because we ignored the missing CID") + .expect("no blockstore error") + ), + ipld!({"/": {".": {"a": 1, "b": cid}}}) + ); } } diff --git a/src/inliner/traits.rs b/src/inliner/traits.rs index 9794c9c..fc17557 100644 --- a/src/inliner/traits.rs +++ b/src/inliner/traits.rs @@ -1,12 +1,14 @@ //! Traits for inlining [`Ipld`] + use crate::InlineIpld; -use blockstore::Blockstore; +use blockstore::{cond_send::CondSend, Blockstore}; +use ipld_core; use ipld_core::{cid::Cid, codec::Codec, ipld::Ipld}; use serde_ipld_dagcbor::codec::DagCborCodec; -use std::ops::DerefMut; +use std::{future::Future, ops::DerefMut}; /// A trait for inlining [`Ipld`] -#[trait_variant::make(SendableInliner: Send + Sized)] +// FIXME #[trait_variant::make(SendableInliner: Send + Sized)] pub trait Inliner { /// Unblock a stuck [`Iterator`]. /// @@ -25,31 +27,33 @@ pub trait Inliner { /// /// # Examples /// + /// FIXME add positive example + /// /// ``` - /// # use inline_ipld::{ - /// # inliner::{AtLeastOnce, Inliner}, - /// # store::{ - /// # Store, - /// # MemoryStore - /// # } - /// # }; - /// # use libipld::{ipld, Cid, cid::{CidGeneric, Version}}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; - /// # use pretty_assertions::assert_eq; + /// # use inline_ipld::{inliner::{AtLeastOnce, Inliner, Stuck}}; + /// # use ipld_core::{ipld, cid::{Cid, CidGeneric, Version}}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use blockstore::InMemoryBlockstore; + /// # use multihash_codetable::Code::Sha2_256; + /// # use pretty_assertions as pretty; + /// # use assert_matches::assert_matches; /// # - /// let store = MemoryStore::new(); // NOTE: completely blank through entire example - /// let missing_cid: Cid = CidGeneric::try_from("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44") - /// .unwrap(); + /// tokio_test::block_on(async { + /// let missing_cid: Cid = "bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44" + /// .try_into() + /// .unwrap(); + /// + /// let dag = ipld!({"a": 1, "b": missing_cid}); + /// let mut inliner = AtLeastOnce::new(&dag); /// - /// let dag = ipld!({"a": 1, "b": missing_cid}); - /// let mut inliner = AtLeastOnce::new(&dag); - /// assert!(inliner.run(&store).unwrap().is_err()); + /// let store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); // NOTE: completely blank through entire example + /// assert_matches!(inliner.run(&store).await, Some(Err(Stuck{ .. }))); + /// }); /// ``` - async fn run( + fn run( self, store: &S, - ) -> Option>>; + ) -> impl Future>>> + CondSend; /// Manually convert an [`Inliner`] to a [`Stuck`] /// @@ -61,27 +65,23 @@ pub trait Inliner { /// # Examples /// /// ``` - /// # use inline_ipld::{ - /// # inliner::{ - /// # AtLeastOnce, - /// # Inliner, - /// # Stuck - /// # }, - /// # store::{ - /// # Store, - /// # MemoryStore - /// # } + /// # use inline_ipld::inliner::{ + /// # AtLeastOnce, + /// # Inliner, + /// # Stuck /// # }; - /// # use libipld::{ipld, Ipld, cid::{CidGeneric, Version}}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use ipld_core::{ipld::{self, Ipld}, cid::{CidGeneric, Version}}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use multihash_codetable::Code::Sha2_256; + /// # use blockstore::InMemoryBlockstore; /// # use std::str::FromStr; /// # use pretty_assertions::assert_eq; /// # - /// let mut store = MemoryStore::new(); + /// let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); /// let cid = FromStr::from_str("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44").unwrap(); /// /// let mut inliner = AtLeastOnce::new(&Ipld::Null); + /// dbg!(&inliner); /// assert_eq!(inliner.stuck_at(cid).needs(), cid); /// ``` fn stuck_at(self, needs: Cid) -> Stuck @@ -119,39 +119,53 @@ impl Stuck { /// /// ``` /// # use inline_ipld::{ - /// # inliner::{AtLeastOnce, Inliner}, - /// # store::{ - /// # Store, - /// # MemoryStore - /// # } + /// # codec::EncodableAs, + /// # inliner::{AtLeastOnce, Inliner} /// # }; - /// # use libipld::{ipld, Ipld, cid::{CidGeneric, Version}, Cid}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use ipld_core::{ipld, ipld::Ipld, cid::{Cid, CidGeneric, Version}}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use multihash_codetable::Code::Sha2_256; + /// # use blockstore::{Blockstore, InMemoryBlockstore}; /// # use std::str::FromStr; /// # use pretty_assertions::assert_eq; /// # - /// let mut store = MemoryStore::new(); - /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); - /// let expected = ipld!({"a": 1, "b": {"/": {"&": cid, ".": [1, 2, 3]}}}); - /// - /// let mut observed = None; - /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld!({"a": 1, "b": cid})).run(&store) { - /// observed = Some(stuck.resolve(ipld!([1, 2, 3]), &mut store).run(&store).expect("A").expect("B")); - /// } - /// - /// /// The IPLD is inlined - /// assert_eq!(observed.unwrap(), expected); - /// - /// // The IPLD is now stored - /// assert_eq!(store.get(cid).unwrap(), &ipld!([1, 2, 3])); + /// tokio_test::block_on(async { + /// let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); + /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); + /// let expected = ipld!({ + /// "/": { + /// ".": { + /// "a": 1, "b": {"/": {"&": cid, ".": [1, 2, 3]}} + /// } + /// } + /// }); + /// + /// let mut observed = None; + /// + /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld!({"a": 1, "b": cid})) + /// .run(&store) + /// .await { + /// observed = Some(stuck.resolve(ipld!([1, 2, 3]), &mut store) + /// .await + /// .run(&store) + /// .await + /// .expect("A") + /// .expect("B")); + /// } + /// + /// /// The IPLD is inlined + /// assert_eq!(Ipld::from(observed.unwrap()), expected); + /// + /// // The IPLD is now stored + /// assert_eq!(store.get(&cid).await.unwrap().unwrap(), ipld!([1, 2, 3]).encode_to(DagCborCodec)); + /// }); /// ``` #[must_use] pub async fn resolve(self, ipld: Ipld, store: &mut S) -> Box { // store.put_keyed(&self.needs, &ipld); // self.stub(ipld) - let bytes = >::encode_to_vec(&ipld).unwrap(); + let bytes = DagCborCodec.encode_to_vec(&ipld).unwrap(); store.put_keyed(&self.needs, &bytes).await.expect("FIXME"); self.stub(ipld) } @@ -162,28 +176,31 @@ impl Stuck { /// /// ``` /// # use inline_ipld::{ - /// # inliner::{AtLeastOnce, Inliner}, - /// # store::{ - /// # Store, - /// # MemoryStore - /// # } + /// # InlineIpld, + /// # codec::EncodableAs, + /// # inliner::{AtLeastOnce, Inliner} /// # }; - /// # use libipld::{ipld, Ipld, cid::{CidGeneric, Version}, Cid}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use ipld_core::{ipld, ipld::Ipld, cid::{Cid, CidGeneric, Version}}; + /// # use blockstore::InMemoryBlockstore; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use multihash_codetable::Code::Sha2_256; /// # use pretty_assertions::assert_eq; /// # use std::str::FromStr; /// # - /// let mut store = MemoryStore::new(); - /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); - /// let expected = ipld!({"a": 1, "b": {"/": {"&": cid, ".": [1, 2, 3]}}}); - /// - /// let mut observed = None; - /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld!({"a": 1, "b": cid})).run(&store) { - /// observed = Some(stuck.stub(ipld!([1, 2, 3])).run(&store).expect("A").expect("B")); - /// } - /// - /// assert_eq!(observed.unwrap(), expected); + /// tokio_test::block_on(async { + /// let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); + /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); + /// let expected = InlineIpld::new(None, ipld!({"a": 1, "b": {"/": {"&": cid, ".": [1, 2, 3]}}})); + /// + /// let mut observed = None; + /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld!({"a": 1, "b": cid})).run(&store).await { + /// observed = Some(stuck.stub(ipld!([1, 2, 3])).run(&store).await.expect("A").expect("B")); + /// } + /// dbg!(Ipld::from(observed.clone().unwrap())); + /// dbg!(Ipld::from(expected.clone())); + /// + /// assert_eq!(observed, Some(expected.into())); + /// }); /// ``` #[must_use] pub fn stub(mut self, ipld: Ipld) -> Box { @@ -201,29 +218,33 @@ impl Stuck { /// # Examples /// /// ``` - /// # use inline_ipld::{ - /// # inliner::{AtLeastOnce, Inliner}, - /// # store::{ - /// # Store, - /// # MemoryStore - /// # } - /// # }; - /// # use libipld::{ipld, Ipld, cid::{CidGeneric, Version}, Cid}; - /// # use libipld::cbor::DagCborCodec; - /// # use multihash::Code::Sha2_256; + /// # use inline_ipld::inliner::{AtLeastOnce, Inliner}; + /// # use ipld_core::{ipld, ipld::Ipld, cid::{Cid, CidGeneric, Version}}; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use blockstore::InMemoryBlockstore; + /// # use multihash_codetable::Code::Sha2_256; /// # use std::str::FromStr; /// # use pretty_assertions::assert_eq; /// # - /// let mut store = MemoryStore::new(); - /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); - /// let ipld = ipld!({"a": 1, "b": cid}); - /// let expected = ipld!({"a": 1, "b": cid}); - /// - /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld).run(&mut store) { - /// assert_eq!(stuck.needs(), cid); - /// let result = stuck.ignore().run(&store); - /// assert_eq!(result.unwrap().unwrap(), expected); - /// } + /// tokio_test::block_on(async { + /// let mut store: InMemoryBlockstore<64> = InMemoryBlockstore::new(); + /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); + /// let ipld = ipld!({"a": 1, "b": cid}); + /// let expected = ipld!({ + /// "/": { + /// ".": { + /// "a": 1, + /// "b": cid + /// } + /// } + /// }); + /// + /// if let Some(Err(mut stuck)) = AtLeastOnce::new(&ipld).run(&mut store).await { + /// assert_eq!(stuck.needs(), cid); + /// let result = stuck.ignore().run(&store).await; + /// assert_eq!(Ipld::from(result.unwrap().unwrap()), expected); + /// } + /// }); /// ``` #[must_use] pub fn ignore(mut self) -> Box { diff --git a/src/ipld/inline.rs b/src/ipld/inline.rs index a10072b..c5133ed 100644 --- a/src/ipld/inline.rs +++ b/src/ipld/inline.rs @@ -17,11 +17,11 @@ use ipld_core::{cid::Cid, ipld, ipld::Ipld}; /// /// ``` /// # use inline_ipld::{cid, InlineIpld}; -/// # use libipld::{ipld, Ipld}; +/// # use ipld_core::{ipld, ipld::Ipld}; /// # /// let inlined = InlineIpld::new(None, ipld!([1, 2, 3])); -/// let ipld = ipld!({"a": 1, "b": inlined}); -/// assert_eq!(ipld, ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}})); +/// let dag = ipld!({"a": 1, "b": inlined}); +/// assert_eq!(dag, ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}})); /// ``` /// /// [spec]: https://github.com/ucan-wg/inline-ipld @@ -34,15 +34,14 @@ pub struct InlineIpld { cid: Option, } -impl PartialEq for InlineIpld { - fn eq(&self, other: &Ipld) -> bool { - other.eq(&self.ipld) - } -} - impl From for Ipld { fn from(inline: InlineIpld) -> Ipld { - inline.ipld + ipld!({ + "/": match inline.cid { + Some(link) => ipld!({".": inline.ipld, "&": link}), + None => ipld!({".": inline.ipld}) + } + }) } } @@ -78,19 +77,19 @@ impl InlineIpld { /// /// ``` /// # use inline_ipld::{cid, InlineIpld}; - /// # use libipld::{ipld, Ipld}; + /// # use ipld_core::{ipld, ipld::Ipld}; /// # /// let observed = InlineIpld::new(None, ipld!([1, 2, 3])); - /// assert_eq!(observed, ipld!({"/": {".": ipld!([1, 2, 3])}})); + /// assert_eq!(Ipld::from(observed), ipld!({"/": {".": [1, 2, 3]}})); /// ``` /// /// ``` /// # use inline_ipld::{cid, InlineIpld}; - /// # use libipld::{ipld, Ipld, Cid}; + /// # use ipld_core::{ipld, ipld::Ipld, cid::Cid}; /// # use std::str::FromStr; /// # /// let cid: Cid = FromStr::from_str("bafyreihscx57i276zr5pgnioa5omevods6eseu5h4mllmow6csasju6eqi").unwrap(); - /// assert_eq!(InlineIpld::new(Some(cid), ipld!([1, 2, 3])), ipld!({ + /// assert_eq!(Ipld::from(InlineIpld::new(Some(cid), ipld!([1, 2, 3]))), ipld!({ /// "/": { /// ".": ipld!([1, 2, 3]), /// "&": cid @@ -101,15 +100,16 @@ impl InlineIpld { /// /// [spec]: https://github.com/ucan-wg/ipld-inline-links pub fn new(cid: Option, ipld: Ipld) -> Self { - let inner = match cid { - Some(link) => ipld!({".": ipld, "&": link}), - None => ipld!({ ".": ipld }), - }; + InlineIpld { ipld, cid } + // let inner = match cid { + // Some(link) => ipld!({".": ipld, "&": link}), + // None => ipld!({".": ipld}), + // }; - InlineIpld { - cid, - ipld: ipld!({ "/": inner }), - } + // InlineIpld { + // cid, + // ipld: ipld!({ "/": inner }), + // } } /// Tag some already-inlined [`Ipld`] to [`InlineIpld`] @@ -128,18 +128,18 @@ impl InlineIpld { /// ``` /// # use inline_ipld::{cid, InlineIpld}; /// # use std::str::FromStr; - /// # use multihash::Code::Sha2_256; - /// # use libipld::{ + /// # use multihash_codetable::Code::Sha2_256; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use ipld_core::{ /// # cid::Version, - /// # cbor::DagCborCodec, /// # ipld, - /// # Ipld, - /// # Cid + /// # ipld::Ipld, + /// # cid::Cid /// # }; /// # /// let ready = ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}}); /// let observed = InlineIpld::attest(ready.clone()); - /// assert_eq!(observed, ready) + /// assert_eq!(Ipld::from(observed), ipld!({"/": {".": ready}})); /// ``` pub fn attest(ipld: Ipld) -> Self { InlineIpld { ipld, cid: None } @@ -152,13 +152,13 @@ impl InlineIpld { /// ``` /// # use inline_ipld::{cid, InlineIpld}; /// # use std::str::FromStr; - /// # use multihash::Code::Sha2_256; - /// # use libipld::{ + /// # use multihash_codetable::Code::Sha2_256; + /// # use serde_ipld_dagcbor::codec::DagCborCodec; + /// # use ipld_core::{ /// # cid::Version, - /// # cbor::DagCborCodec, /// # ipld, - /// # Ipld, - /// # Cid + /// # ipld::Ipld, + /// # cid::Cid /// # }; /// # /// let ipld = ipld!({"a": 1, "b": {"/": {".": [1, 2, 3]}}}); diff --git a/src/iterator/post_order.rs b/src/iterator/post_order.rs index b9a439c..e983549 100644 --- a/src/iterator/post_order.rs +++ b/src/iterator/post_order.rs @@ -62,7 +62,7 @@ impl<'a> Iterator for PostOrderIpldIter<'a> { #[cfg(test)] mod tests { use super::*; - use libipld::{cid::CidGeneric, ipld}; + use ipld_core::{cid::CidGeneric, ipld}; use pretty_assertions::assert_eq; #[test] diff --git a/src/iterator/post_order/cid_aware.rs b/src/iterator/post_order/cid_aware.rs index 22a24b7..773984a 100644 --- a/src/iterator/post_order/cid_aware.rs +++ b/src/iterator/post_order/cid_aware.rs @@ -1,17 +1,17 @@ use crate::cid; use ipld_core::{codec::Codec, ipld::Ipld}; -use multihash_derive::Hasher; +use multihash_derive::MultihashDigest; use nonempty::{nonempty, NonEmpty}; /// FIXME better name? #[derive(Clone, Debug, PartialEq)] -pub struct CidAware<'a, C: Codec + Clone, H: Hasher + Into + Clone> { +pub struct CidAware<'a, C: Codec + Clone, H: MultihashDigest<64>> { inbound: Vec<&'a Ipld>, outbound: Vec<&'a Ipld>, cid_context_stack: NonEmpty>, } -impl<'a, C: Codec + Clone, H: Hasher + Into + Clone> CidAware<'a, C, H> { +impl<'a, C: Codec + Clone, H: MultihashDigest<64>> CidAware<'a, C, H> { /// Initialize a new [`PostOrderIpldIter`][super::PostOrderIpldIter] pub fn new(ipld: &'a Ipld, cid_config: cid::Config) -> Self { CidAware { @@ -46,9 +46,7 @@ impl<'a, C: Codec + Clone, H: Hasher + Into + Clone> CidAware<'a, C, } } -impl<'a, C: Codec + Clone + TryFrom, H: Hasher + Clone + Into + TryFrom> - Iterator for CidAware<'a, C, H> -{ +impl<'a, C: Codec + Clone, H: MultihashDigest<64>> Iterator for CidAware<'a, C, H> { type Item = Result<&'a Ipld, cid::error::ConfigError>; fn next(&mut self) -> Option { diff --git a/src/lib.rs b/src/lib.rs index c47d977..ea25a6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ pub mod iterator; mod ipld; pub use ipld::InlineIpld; -#[cfg(test)] +#[cfg(feature = "test_utils")] pub mod test_util; #[cfg(target_arch = "wasm32")] diff --git a/src/store/memory.rs b/src/store/memory.rs deleted file mode 100644 index 20dfa42..0000000 --- a/src/store/memory.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! An in-memory [`Ipld`] store - -use super::traits::Store; -use crate::cid::error::BlockNotFound; -use ipld_core::{cid::Cid, ipld::Ipld}; -use std::collections::BTreeMap; - -#[cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::wasm_bindgen; - -/// A basic in-memory [`Ipld`] store -#[derive(Clone, Debug, Default, PartialEq)] -#[cfg_attr(target_arch = "wasm32", wasm_bindgen)] -#[cfg_attr(feature = "serde-codec", derive(serde::Serialize))] -#[allow(clippy::module_name_repetitions)] -pub struct MemoryStore { - store: BTreeMap, -} - -impl MemoryStore { - /// Initialize an empty [`MemoryStore`] - #[must_use] - pub const fn new() -> Self { - MemoryStore { - store: BTreeMap::new(), - } - } -} - -impl From> for MemoryStore { - fn from(store: BTreeMap) -> Self { - MemoryStore { store } - } -} - -impl From for BTreeMap { - fn from(ms: MemoryStore) -> Self { - ms.store - } -} - -impl Store for MemoryStore { - fn get(&self, cid: Cid) -> Result<&Ipld, BlockNotFound> { - Store::get(&self.store, cid) - } - - fn put_keyed(&mut self, cid: Cid, ipld: &Ipld) { - self.store.put_keyed(cid, ipld); - } -} diff --git a/src/store/traits.rs b/src/store/traits.rs deleted file mode 100644 index d6cb292..0000000 --- a/src/store/traits.rs +++ /dev/null @@ -1,209 +0,0 @@ -//! Content-addressed store trait - -use crate::{ - cid, - cid::error::{BlockNotFound, UnsupportedCodec}, - codec::EncodableAs, -}; -use ipld_core::{ - cid::{Cid, Version}, - codec::Codec, - ipld::Ipld, -}; -use multihash_derive::Hasher; -use std::collections::BTreeMap; -use thiserror::Error; - -/// A trait describing inline/extract-capable content addressed stores -pub trait Store { - /// Retrieve a block by CID - /// - /// # Arguments - /// - /// * `self` - The block store - /// * `cid` - The [`Cid`] to look up by - /// - /// # Errors - /// - /// * [`BlockNotFound`] - If the [`Cid`] is not found in the store - /// - /// # Examples - /// - /// ``` - /// # use inline_ipld::store::Store; - /// # use std::{collections::BTreeMap, str::FromStr}; - /// # use multihash::Code::Sha2_256; - /// # use libipld::{ - /// # cid::Version, - /// # cbor::DagCborCodec, - /// # ipld - /// # }; - /// # - /// let block = ipld!([1, 2, 3]); - /// let mut store = BTreeMap::new(); - /// let cid = store.put(&block, DagCborCodec, Sha2_256, Version::V1); - /// - /// assert_eq!(Store::get(&store, cid).unwrap(), &block); - /// ``` - fn get(&self, cid: Cid) -> Result<&Ipld, BlockNotFound>; - - /// Insert a block manually with a user-specified CID - /// - /// Since this method _may_ result in a invalid content address, [`Store::put`] should be preferred where possible. - /// However, [`Store::put_keyed`] is easier to define in a trait implementation. - /// - /// # Arguments - /// - /// * `self` - The block store - /// * `cid` - The explicit [`Cid`] to index this block by - /// * `ipld` - The [`Ipld`] to store - /// - /// # Examples - /// - /// ``` - /// # use inline_ipld::store::Store; - /// # use libipld::{cid, ipld}; - /// # use std::{collections::BTreeMap, str::FromStr}; - /// # - /// # let block = ipld!([1, 2, 3]); - /// # let cid = FromStr::from_str("bafyreickxqyrg7hhhdm2z24kduovd4k4vvbmfmenzn7nc6pxg6qzjm2v44").unwrap(); - /// # - /// let mut store = BTreeMap::new(); - /// store.put_keyed(cid, &block); - /// - /// assert_eq!(Store::get(&store, cid).unwrap(), &block); - /// ``` - fn put_keyed(&mut self, cid: Cid, ipld: &Ipld); - - /// Insert a block into content addressed storage - /// - /// A variant of this method (`put_default`) is available if the `"sha2"` flag is enabled on [`libipld`]. - /// - /// # Arguments - /// - /// * `self` - The block store - /// * `ipld` - The [`Ipld`] to store - /// * `codec` - The [`Codec`] that the IPLD is encoded as - /// * `hasher` - The hash function to use when generating the [`Cid`] - /// * `cid_version` - The [`Cid`] version - /// - /// # Examples - /// - /// ``` - /// # use inline_ipld::store::Store; - /// # use std::{collections::BTreeMap, str::FromStr}; - /// # use multihash::Code::Sha2_256; - /// # use libipld::{ - /// # cid::Version, - /// # cbor::DagCborCodec, - /// # ipld - /// # }; - /// # - /// let block = ipld!([1, 2, 3]); - /// let mut store = BTreeMap::new(); - /// let cid = store.put(&block, DagCborCodec, Sha2_256, Version::V1); - /// - /// assert_eq!(Store::get(&store, cid).unwrap(), &block); - /// ``` - fn put, H: Hasher>( - &mut self, - ipld: &Ipld, - codec: C, - hasher: H, - cid_version: Version, - ) -> Cid - where - Ipld: EncodableAs, - { - let block_cid = cid::new(ipld, codec, hasher, cid_version); - self.put_keyed(block_cid, ipld); - block_cid - } - - #[cfg(feature = "dag-cbor")] - /// [`Store::put`] but defaults to [`Sha2_256`] and [`DagCborCodec`][`libipld::cbor::DagCborCodec`] - fn put_default(&mut self, ipld: &Ipld) -> Cid { - use libipld_cbor::DagCborCodec; - self.put(ipld, DagCborCodec, Sha2_256, Version::V1) - } - - /// Retrieve a block by CID as a raw vector of bytes. - /// - /// # Arguments - /// - /// * `self` - The block store - /// * `cid` - The [`Cid`] to look up by - /// - /// # Errors - /// - /// * [`GetRawError`] - If the [`Cid`] is not found in the store, or if the [`Ipld`] cannot be encoded - /// - /// # Examples - /// - /// ``` - /// # use inline_ipld::store::Store; - /// # use std::{collections::BTreeMap, str::FromStr}; - /// # use multihash::Code::Sha2_256; - /// # use libipld::{ - /// # cid::Version, - /// # cbor::DagCborCodec, - /// # ipld - /// # }; - /// # - /// let mut store = BTreeMap::new(); - /// let cid = store.put(&ipld!([1, 2, 3]), DagCborCodec, Sha2_256, Version::V1); - /// let observed = store.get_raw(cid).unwrap(); - /// - /// assert_eq!(observed, vec![131, 1, 2, 3]); - /// ``` - fn get_raw(&self, cid: Cid) -> Result, GetRawError> { - let ipld = self.get(cid).map_err(GetRawError::NotFound)?; - let codec_id: u64 = cid.codec(); - let codec: TotalCodec = codec_id.try_into().map_err(GetRawError::UnknownCodec)?; - - let mut buffer = vec![]; - ipld.encode(codec, &mut buffer) - .expect("should not fail is `EncodableAs` for your codec is implemented correctly"); - - Ok(buffer) - } -} - -impl Store for BTreeMap { - fn get(&self, cid: Cid) -> Result<&Ipld, BlockNotFound> { - self.get(&cid).ok_or(BlockNotFound(cid)) - } - - fn put_keyed(&mut self, cid: Cid, ipld: &Ipld) { - self.insert(cid, ipld.clone()); - } -} - -/// Error cases for [`Store::get_raw`] -#[derive(Debug, Error)] -pub enum GetRawError { - /// Forwards a (lifted) [BlockNotFound] - #[error(transparent)] - NotFound(#[from] BlockNotFound), - - /// Forwards a (lifted) [UnsupportedCodec] - #[error(transparent)] - UnknownCodec(#[from] UnsupportedCodec), -} - -impl PartialEq for GetRawError { - fn eq(&self, other: &GetRawError) -> bool { - match (self, other) { - ( - &GetRawError::NotFound(BlockNotFound(cid_a)), - &GetRawError::NotFound(BlockNotFound(cid_b)), - ) => cid_a.eq(&cid_b), - ( - &GetRawError::UnknownCodec(UnsupportedCodec(codec_a)), - &GetRawError::UnknownCodec(UnsupportedCodec(codec_b)), - ) => codec_a.eq(&codec_b), - // libipld::error::Error is existentially quantified, and not constrained with PartialEq, so false - _ => false, - } - } -} diff --git a/src/test_util.rs b/src/test_util.rs index 97f4390..75e8216 100644 --- a/src/test_util.rs +++ b/src/test_util.rs @@ -1,6 +1,6 @@ //! Miscellaneous test helpers and utilities -pub mod some_codec; pub mod super_ipld; -pub mod super_multihash; +// pub mod super_multihash; pub mod super_version; +pub mod total_codec; diff --git a/src/test_util/some_codec.rs b/src/test_util/some_codec.rs deleted file mode 100644 index 968c0c2..0000000 --- a/src/test_util/some_codec.rs +++ /dev/null @@ -1,45 +0,0 @@ -use libipld::codec_impl::IpldCodec; -use proptest::prelude::*; - -#[derive(Copy, Clone, Debug, PartialEq)] -pub struct SomeCodec(pub IpldCodec); - -impl SomeCodec { - pub fn new(codec: IpldCodec) -> Self { - SomeCodec(codec) - } -} - -impl From for SomeCodec { - fn from(codec: IpldCodec) -> Self { - SomeCodec(codec) - } -} - -impl From for IpldCodec { - fn from(wrapper: SomeCodec) -> Self { - wrapper.0 - } -} - -impl Default for SomeCodec { - fn default() -> Self { - SomeCodec(IpldCodec::DagCbor) - } -} - -impl Arbitrary for SomeCodec { - type Parameters = (); - type Strategy = BoxedStrategy; - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - prop_oneof![ - Just(IpldCodec::Raw), - Just(IpldCodec::DagPb), - Just(IpldCodec::DagCbor), - Just(IpldCodec::DagJson), - ] - .prop_map(SomeCodec) - .boxed() - } -} diff --git a/src/test_util/super_ipld.rs b/src/test_util/super_ipld.rs index 20a1d65..2c3e285 100644 --- a/src/test_util/super_ipld.rs +++ b/src/test_util/super_ipld.rs @@ -1,8 +1,12 @@ -use super::super_multihash::SuperMultihash; -use crate::{cid, codec::TotalCodec}; -use libipld::Ipld; +// use super::super_multihash::SuperMultihash; +use crate::{cid, codec::total::TotalCodec}; +use ipld_core::ipld::Ipld; use proptest::prelude::*; +use ipld_core::codec::Codec; +use multihash_codetable::Multihash; +use proptest_arbitrary_interop::{arb, ArbInterop}; + #[derive(Clone, Debug, PartialEq)] pub struct SuperIpld(pub Ipld); @@ -17,16 +21,21 @@ impl Arbitrary for SuperIpld { any::>().prop_map(Ipld::Bytes), any::().prop_flat_map(move |i| { any::().prop_map(move |codec| match codec { - TotalCodec::DagCbor(_) => Ipld::Integer((i as i64).into()), - TotalCodec::DagJson(_) => Ipld::Integer((i % (2 ^ 53)).into()), // RAGE + TotalCodec::DagCbor => Ipld::Integer((i as i64).into()), + TotalCodec::DagJson => Ipld::Integer((i % (2 ^ 53)).into()), // RAGE }) }), any::().prop_map(Ipld::Float), ".*".prop_map(Ipld::String), // We don't deref these Links, so just use numbers - any::<(u64, cid::Config)>().prop_map( - |(some_u64, config)| Ipld::Link(config.cidify(&Ipld::Integer(some_u64 as i128))) - ) + any::<(u64, TotalCodec)>().prop_map(|(some_u64, codec)| { + let config: cid::Config = cid::Config { + codec: codec, + multihasher: multihash_codetable::Code::Sha2_256.into(), + version: ipld_core::cid::Version::V1, + }; + Ipld::Link(config.cidify(&Ipld::Integer(some_u64 as i128))) + }) ]; let coll = leaf.clone().prop_recursive(16, 1024, 128, |inner| { diff --git a/src/test_util/super_multihash.rs b/src/test_util/super_multihash.rs index e125d8a..48ef0e7 100644 --- a/src/test_util/super_multihash.rs +++ b/src/test_util/super_multihash.rs @@ -1,5 +1,5 @@ -use libipld::cid::multihash::Code; -use libipld::cid::multihash::{MultihashDigest, MultihashGeneric}; +use multihash_codetable::Code; +use multihash_derive::{Multihash, MultihashDigest}; use proptest::prelude::*; #[derive(Eq, Copy, Clone, Debug, PartialEq)] @@ -45,11 +45,11 @@ impl TryFrom for SuperMultihash { } impl MultihashDigest<64> for SuperMultihash { - fn digest(&self, input: &[u8]) -> MultihashGeneric<64> { + fn digest(&self, input: &[u8]) -> Multihash<64> { self.0.digest(input) } - fn wrap(&self, digest: &[u8]) -> Result, Self::Error> { + fn wrap(&self, digest: &[u8]) -> Result, multihash_derive::Error> { self.0.wrap(digest) } } diff --git a/src/test_util/super_version.rs b/src/test_util/super_version.rs index 039ddbd..5f3c8c1 100644 --- a/src/test_util/super_version.rs +++ b/src/test_util/super_version.rs @@ -1,4 +1,4 @@ -use libipld::cid::Version; +use cid::Version; use proptest::prelude::*; #[derive(Copy, Clone, Debug, PartialEq)] diff --git a/src/test_util/total_codec.rs b/src/test_util/total_codec.rs new file mode 100644 index 0000000..78b1066 --- /dev/null +++ b/src/test_util/total_codec.rs @@ -0,0 +1,17 @@ +use proptest::prelude::*; + +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)] +pub enum TotalCodec { + #[default] + DagCbor, + DagJson, +} + +impl Arbitrary for TotalCodec { + type Parameters = (); + type Strategy = BoxedStrategy; + + fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { + prop_oneof![Just(TotalCodec::DagCbor), Just(TotalCodec::DagJson)].boxed() + } +} diff --git a/src/wasm.rs b/src/wasm.rs index 8867f95..4801405 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -1,6 +1,5 @@ //! FIXME -// use crate::store::MemoryStore; use wasm_bindgen::prelude::*; #[cfg(feature = "console_error_panic_hook")] @@ -20,10 +19,11 @@ extern "C" { fn alert(s: &str); } +// FIXME // #[wasm_bindgen] // #[derive(Clone, Debug)] // pub struct JsMemStore { -// store: MemoryStore, +// store: InMemoryStore, // } // // #[wasm_bindgen]