diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d8bcaaf..c35cae99 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: strategy: fail-fast: false matrix: - feature: [ derive, stl, serde, async, rand ] + feature: [ derive, rand, stl, serde ] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -57,7 +57,7 @@ jobs: strategy: fail-fast: false matrix: - toolchain: [ nightly, beta, stable, 1.77.0 ] + toolchain: [ nightly, beta, stable, 1.81.0 ] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master diff --git a/Cargo.lock b/Cargo.lock index 65f8658c..82779761 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,22 +2,12 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - [[package]] name = "amplify" -version = "4.7.0" +version = "4.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7147b742325842988dd6c793d55f58df3ae36bccf7d9b6e07db10ab035be343d" +checksum = "448cf0c3afc71439b5f837aac5399a1ef2b223f5f38324dbfb4343deec3b80cc" dependencies = [ - "amplify_apfloat", "amplify_derive", "amplify_num", "amplify_syn", @@ -27,17 +17,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "amplify_apfloat" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "695e433882668b55b3d7fb0ba22bf9be66a91abe30d7ca1f1a774f8b90b4db4c" -dependencies = [ - "amplify_num", - "bitflags", - "wasm-bindgen", -] - [[package]] name = "amplify_derive" version = "4.0.1" @@ -82,9 +61,9 @@ dependencies = [ [[package]] name = "ascii-armor" -version = "0.7.2" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4966ac403dc4a666d8131dfe4df684f45acc68d4c7e768db89c463aa5617910" +checksum = "0269eb842ec952b027df0fc33184b6a0dea5ea473160b36992274eb53758461e" dependencies = [ "amplify", "baid64", @@ -93,22 +72,11 @@ dependencies = [ "strict_encoding", ] -[[package]] -name = "async-trait" -version = "0.1.83" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.79", -] - [[package]] name = "baid64" -version = "0.2.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95dabc2759e01e2c382968639868a701f384a18890934f9e75d4feb4d6623794" +checksum = "6cb4a8b2f1afee4ef00a190b260ad871842b93206177b59631fecd325d48d538" dependencies = [ "amplify", "base64", @@ -131,12 +99,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - [[package]] name = "block-buffer" version = "0.10.4" @@ -166,7 +128,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "client_side_validation" -version = "0.11.0-beta.9" +version = "0.12.0-beta.4" dependencies = [ "commit_verify", "serde", @@ -175,12 +137,11 @@ dependencies = [ [[package]] name = "commit_encoding_derive" -version = "0.11.0-beta.9" +version = "0.12.0-beta.4" dependencies = [ "amplify", "amplify_syn", "commit_verify", - "compiletest_rs", "proc-macro2", "quote", "strict_encoding", @@ -189,7 +150,7 @@ dependencies = [ [[package]] name = "commit_verify" -version = "0.11.0-beta.9" +version = "0.12.0-beta.4" dependencies = [ "amplify", "commit_encoding_derive", @@ -202,43 +163,15 @@ dependencies = [ "vesper-lang", ] -[[package]] -name = "compiletest_rs" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0f4b0a27f9efcea6a012305682f0f7c5691df7097b9eaf6abb50b75c89a8af" -dependencies = [ - "diff", - "filetime", - "getopts", - "lazy_static", - "libc", - "log", - "miow", - "regex", - "rustfix", - "serde", - "serde_derive", - "serde_json", - "tester", - "winapi", -] - [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "16b80225097f2e5ae4e7179dd2266824648f3e2f49d9134d584b76389d31c4c3" dependencies = [ "libc", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -249,12 +182,6 @@ dependencies = [ "typenum", ] -[[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" @@ -265,45 +192,12 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "dirs-next" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" -dependencies = [ - "cfg-if", - "dirs-sys-next", -] - -[[package]] -name = "dirs-sys-next" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" -dependencies = [ - "libc", - "redox_users", - "winapi", -] - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "filetime" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" -dependencies = [ - "cfg-if", - "libc", - "libredox", - "windows-sys 0.59.0", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -314,15 +208,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - [[package]] name = "getrandom" version = "0.2.15" @@ -334,21 +219,11 @@ dependencies = [ "wasi", ] -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" [[package]] name = "heck" @@ -356,50 +231,21 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "indexmap" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f" dependencies = [ "equivalent", "hashbrown", ] -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" -version = "0.2.159" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" - -[[package]] -name = "libredox" -version = "0.1.3" +version = "0.2.169" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" -dependencies = [ - "bitflags", - "libc", - "redox_syscall", -] +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "log" @@ -407,37 +253,12 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "miow" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52ffbca2f655e33c08be35d87278e5b18b89550a37dbd598c20db92f6a471123" -dependencies = [ - "windows-sys 0.42.0", -] - [[package]] name = "mnemonic" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b8f3a258db515d5e91a904ce4ae3f73e091149b90cadbdb93d210bee07f63b" -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" version = "1.20.2" @@ -450,12 +271,6 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" -[[package]] -name = "pin-project-lite" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" - [[package]] name = "ppv-lite86" version = "0.2.20" @@ -467,9 +282,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.87" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3e4daa0dcf6feba26f985457cdf104d4b4256fc5a09547140f3631bb076b19a" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -513,55 +328,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_users" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" -dependencies = [ - "getrandom", - "libredox", - "thiserror", -] - -[[package]] -name = "regex" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" - [[package]] name = "ripemd" version = "0.1.3" @@ -571,60 +337,24 @@ dependencies = [ "digest", ] -[[package]] -name = "rustfix" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f5b7fc8060f4f8373f9381a630304b42e1183535d9beb1d3f596b236c9106a" -dependencies = [ - "serde", - "serde_json", - "thiserror", - "tracing", -] - -[[package]] -name = "rustversion" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" - -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - [[package]] name = "serde" -version = "1.0.210" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.216" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", -] - -[[package]] -name = "serde_json" -version = "1.0.128" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", + "syn 2.0.91", ] [[package]] @@ -650,29 +380,28 @@ dependencies = [ [[package]] name = "single_use_seals" -version = "0.11.0-beta.9" +version = "0.12.0-beta.4" dependencies = [ - "amplify_derive", - "async-trait", + "serde", + "strict_encoding", ] [[package]] name = "strict_encoding" -version = "2.7.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d69b4893cf054e129d5288a565102124520d7b94eb9589d1e78202abc7e2092d" +checksum = "8fd36b71bb44ca146be0b2185ed6c6deb3684cc0d5c3a94284e97fe7fa6a642f" dependencies = [ "amplify", - "half", "strict_encoding_derive", "wasm-bindgen", ] [[package]] name = "strict_encoding_derive" -version = "2.7.0" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4f9b678862372f8e439bcaafc27df7610ea93b06d2deb6244dec0af4259ce6" +checksum = "34e3bc6e4a2450420b4dbfb6929d9ce005e8c36cf73bf215db99f0d09c9fa79f" dependencies = [ "amplify_syn", "heck", @@ -683,14 +412,13 @@ dependencies = [ [[package]] name = "strict_types" -version = "2.7.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f16e8855a575633815f01482ac927ebaca3d2485aec8e17226c6826de29154e" +checksum = "3e208d1bd29a0f70d7ee90a91d76446b8bb7b1b8212d06e031e396d52e2fe891" dependencies = [ "amplify", "ascii-armor", "baid64", - "half", "indexmap", "sha2", "strict_encoding", @@ -721,76 +449,33 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.79" +version = "2.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "term" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" -dependencies = [ - "dirs-next", - "rustversion", - "winapi", -] - -[[package]] -name = "tester" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89e8bf7e0eb2dd7b4228cc1b6821fc5114cd6841ae59f652a85488c016091e5f" -dependencies = [ - "cfg-if", - "getopts", - "libc", - "num_cpus", - "term", -] - [[package]] name = "thiserror" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.64" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", -] - -[[package]] -name = "tracing" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" -dependencies = [ - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" -dependencies = [ - "once_cell", + "syn 2.0.91", ] [[package]] @@ -801,15 +486,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" - -[[package]] -name = "unicode-width" -version = "0.1.14" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" [[package]] name = "version_check" @@ -819,9 +498,9 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vesper-lang" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f72ebd3b32f16ee8ace2bd3058c2bfa0f4820992bd4ea86e73ba228bb13dd2b0" +checksum = "cd2b7e3e27aeb0524204e58042f6e4531a720745d1b1a3978d3a084f1885f63d" dependencies = [ "amplify", "strict_encoding", @@ -835,9 +514,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -846,24 +525,23 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.91", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -871,174 +549,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.95" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.91", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.95" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "zerocopy" @@ -1058,5 +584,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.79", + "syn 2.0.91", ] diff --git a/Cargo.toml b/Cargo.toml index babd2e51..11596839 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,18 +13,19 @@ default-members = [ ] [workspace.package] -version = "0.11.0-beta.9" +version = "0.12.0-beta.4" authors = ["Dr Maxim Orlovsky "] homepage = "https://github.com/LNP-BP" repository = "https://github.com/LNP-BP/client_side_validation" -rust-version = "1.77.0" # Due to `rustfix` +rust-version = "1.81.0" # Due to Error in core edition = "2021" license = "Apache-2.0" [workspace.dependencies] -amplify = "4.7.0" -strict_encoding = "2.7.0" -strict_types = "2.7.0" +amplify = "~4.8.0" +strict_encoding = "~2.8.1" +strict_types = "~2.8.1" +serde = { version = "1", features = ["derive"] } [package] name = "client_side_validation" @@ -46,18 +47,17 @@ name = "client_side_validation" path = "src/lib.rs" [dependencies] -commit_verify = { version = "0.11.0-beta.9", path = "./commit_verify", default-features = false } -single_use_seals = { version = "0.11.0-beta.9", path = "./single_use_seals" } -serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true } +commit_verify = { version = "0.12.0-beta.4", path = "./commit_verify", default-features = false } +single_use_seals = { version = "0.12.0-beta.4", path = "./single_use_seals", features = ["strict_encoding"] } +serde = { workspace = true, optional = true } [features] default = ["derive"] -all = ["serde", "rand", "async", "stl"] +all = ["serde", "rand", "stl"] stl = ["commit_verify/stl"] -async = ["single_use_seals/async"] rand = ["commit_verify/rand"] derive = ["commit_verify/derive"] -serde = ["serde_crate", "commit_verify/serde"] +serde = ["dep:serde", "commit_verify/serde"] [package.metadata.docs.rs] features = ["all"] diff --git a/MANIFEST.yml b/MANIFEST.yml deleted file mode 100644 index eb94ce12..00000000 --- a/MANIFEST.yml +++ /dev/null @@ -1,14 +0,0 @@ -Name: strict_encoding -Type: Library -Kind: Free software -License: Apache-2.0 -Language: Rust -Compiler: 1.77 -Author: Maxim Orlovsky -Maintained: UBIDECO Institute, Switzerland -Maintainers: - Maxim Orlovsky: - GitHub: @dr-orlovsky - GPG: EAE730CEC0C663763F028A5860094BAF18A26EC9 - SSH: BoSGFzbyOKC7Jm28MJElFboGepihCpHop60nS8OoG/A - EMail: dr@orlovsky.ch diff --git a/README.md b/README.md index f98f9a63..1231d236 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) [![Apache-2 licensed](https://img.shields.io/crates/l/client_side_validation)](./LICENSE) -This is an implementation defining standard of client-side-validation +This is an implementation defining standard of client-side-validation representing a set of its Foundation libraries. The standards covered by the -libraries include [LNPBP-4], [LNPBP-7], [LNPBP-8], [LNPBP-9], and [LNPBP-81] +libraries include [LNPBP-4], [LNPBP-7], [LNPBP-8], [LNPBP-9], and [LNPBP-81] (see [Components](#components) section below for more details). Client-side-validation is a paradigm for distributed computing, based on top of @@ -22,48 +22,47 @@ or other type of distributed consensus system. The development of the library is supported by [LNP/BP Standards Association][lnpbp-web] and is performed on its [GitHub page][lnpbp-github]. -The original idea of client-side-validation was proposed by Peter Todd with its +The original idea of client-side-validation was proposed by Peter Todd with its possible applications designed by Giacomo Zucco. It was shaped into the protocol design by Dr Maxim Orlovsky with a big input from the community. -Minimum supported rust version for the library (MSRV) is 1.66 and 2021 rust +Minimum supported rust version for the library (MSRV) is 1.66 and 2021 rust edition. - ## Documentation Detailed developer & API documentation for all libraries can be accessed at: + - - - To learn about the technologies enabled by the library please check -[slides from our tech presentations][presentations] and +[slides from our tech presentations][presentations] and [LNP/BP tech talks videos][lnpbp-youtube]. - ## Components This library consists of the following main three components, which define independent parts constituting together client-side-validation API and its core functionality. These are: + - [Commit-verify](commit_verify/README.md) client-side-validation-specific APIs: - * consensus commitments (part of [LNPBP-8] standard) - * multi-commitments ([LNPBP-4] standard) - * merklization for client-side-validation ([LNPBP-81] standard) + * consensus commitments (part of [LNPBP-8] standard) + * multi-commitments ([LNPBP-4] standard) + * merklization for client-side-validation ([LNPBP-81] standard) - [Single-use-seals](single_use_seals/README.md) API ([LNPBP-8] standard) -- Client-side-validation API from the library root, linking those components +- Client-side-validation API from the library root, linking those components together according to [LNPBP-9] standard. - ## Usage The repository contains rust libraries for client-side validation. ### Use library in other projects -To use libraries, you just need latest version of libraries, published to -[crates.io](https://crates.io) into `[dependencies]` section of your project +To use libraries, you just need latest version of libraries, published to +[crates.io](https://crates.io) into `[dependencies]` section of your project `Cargo.toml`. Here is the full list of available libraries from this repository: ```toml @@ -73,10 +72,11 @@ single_use_seals = "1" # Generic (non-bitcoin-specific) API ``` "Umbrella" `client_side_validation` library is configured with default set of -features enabling all of its functionality (and including all of other libraries +features enabling all of its functionality (and including all of other libraries from this repository, listed above). If you need to restrict this set, either use specific libraries - or configure main library with a set of features in the following way: + ```toml [dependencies.client_side_validation] version = "1" @@ -85,12 +85,12 @@ features = [] # Your set of features goes here ``` The library has four feature flags, all of which are not used by default: + - `rand`, providing support for generating random 32-byte sequences of `Slice32` type, used in many LNP/BP applications (for instance as hash-lock preimages or during LNPBP-4 multi-commitments); - `serde`, providing support for data structure serialization with serde across - all library; -- `async`, providing async traits for projects using async rust. + all library. For specific features which may be enabled for the libraries, please check library-specific guidelines, located in `README.md` files in each of library @@ -98,28 +98,27 @@ subdirectories. ### Libraries based on client-side-validation -Most of the developers will be probably interested in a more high-level +Most of the developers will be probably interested in a more high-level libraries based on client-side-validation, applying it to a specific commitment mediums (bitcoin transaction graph from blockchain or state channels, or more exotic systems like confidential bitcoin transactions used by elements & liquid, or mimblewimble-based systems). Here is (potentially incomplete) list of such libraries: -- Bitcoin: [BP Core Lib](https://github.com/LNP-BP/bp-core), which contains - bitcoin UTXO single-use-seal implementations for pay-to-contract and - sign-to-contract types of seals, as well as a library for deterministic + +- Bitcoin: [BP Core Lib](https://github.com/LNP-BP/bp-core), which contains + bitcoin UTXO single-use-seal implementations for pay-to-contract and + sign-to-contract types of seals, as well as a library for deterministic bitcoin commitments. This library is maintained by LNP/BP Association. -- [Pandora sealchain](https://github.com/pandora-network/sealchain-rs), an - experimental blockchain of [Pandora Network](https://pandora.network), - playing with client-side-validation using modified bitcoin consensus rules, - extended with eltoo- and covenants-related functionality and with removed +- [Pandora sealchain](https://github.com/pandora-network/sealchain-rs), an + experimental blockchain of [Pandora Network](https://pandora.network), + playing with client-side-validation using modified bitcoin consensus rules, + extended with eltoo- and covenants-related functionality and with removed native blockchain-level coin. - ## Contributing Contribution guidelines can be found in [CONTRIBUTING](CONTRIBUTING.md) - ## Licensing The libraries are distributed on the terms of Apache 2.0 opensource license. @@ -127,13 +126,21 @@ See [LICENCE](LICENSE) file for the license details. [lnpbp-web]: https://lnp-bp.org + [lnpbp-github]: https://github.com/LNP-BP + [lnpbp-youtube]: https://www.youtube.com/@LNPBP + [presentations]: https://github.com/LNP-BP/FAQ/blob/master/Presentation%20slides/ [LNPBP-4]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0004.md + [LNPBP-7]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0007.md + [LNPBP-8]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0008.md + [LNPBP-9]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0009.md + [LNPBP-42]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0042.md + [LNPBP-81]: https://github.com/LNP-BP/LNPBPs/blob/master/lnpbp-0081.md diff --git a/codecov.yml b/codecov.yml index 240d7310..453306aa 100644 --- a/codecov.yml +++ b/codecov.yml @@ -8,12 +8,10 @@ coverage: status: project: default: - target: 75% threshold: 1% branches: - master patch: default: - target: 60% threshold: 1% only_pulls: true diff --git a/commit_verify/Cargo.toml b/commit_verify/Cargo.toml index 860d875e..cfdd7963 100644 --- a/commit_verify/Cargo.toml +++ b/commit_verify/Cargo.toml @@ -22,15 +22,15 @@ name = "commit-stl" required-features = ["stl"] [dependencies] -amplify = { workspace = true, features = ["hex", "apfloat"] } +amplify = { workspace = true } strict_encoding = { workspace = true } strict_types = { workspace = true } -vesper-lang = "0.1.0" -commit_encoding_derive = { version = "0.11.0-beta.8", path = "derive" } +vesper-lang = "0.2.1" +commit_encoding_derive = { version = "0.12.0-beta.4", path = "derive" } sha2 = "0.10.8" ripemd = "0.1.3" rand = { version = "0.8.5", optional = true } -serde_crate = { version = "1.0", package = "serde", optional = true } +serde = { version = "1.0", package = "serde", optional = true } [dev-dependencies] rand = "0.8.5" @@ -38,7 +38,7 @@ rand = "0.8.5" [features] default = ["derive"] all = ["rand", "serde", "stl", "derive"] -serde = ["serde_crate", "amplify/serde"] +serde = ["dep:serde", "amplify/serde"] stl = ["strict_types/armor"] derive = [] diff --git a/commit_verify/derive/Cargo.toml b/commit_verify/derive/Cargo.toml index ed9a0a22..a6c99624 100644 --- a/commit_verify/derive/Cargo.toml +++ b/commit_verify/derive/Cargo.toml @@ -24,5 +24,4 @@ amplify_syn = "2.0.1" [dev-dependencies] commit_verify = { path = ".." } -compiletest_rs = "0.11.0" strict_encoding = { workspace = true } diff --git a/commit_verify/derive/src/derive.rs b/commit_verify/derive/src/derive.rs index 31cc8242..797cd720 100644 --- a/commit_verify/derive/src/derive.rs +++ b/commit_verify/derive/src/derive.rs @@ -44,8 +44,7 @@ impl CommitDerive { engine.commit_to_serialized(self.as_inner()); }, StrategyAttr::Merklize => quote! { - use amplify::Wrapper; - engine.commit_to_merkle(self.as_inner().merklize()); + engine.commit_to_merkle(self); }, }; diff --git a/commit_verify/derive/src/params.rs b/commit_verify/derive/src/params.rs index 4b8c5678..a1da3f64 100644 --- a/commit_verify/derive/src/params.rs +++ b/commit_verify/derive/src/params.rs @@ -45,6 +45,7 @@ pub enum StrategyAttr { ConcealStrict, Transparent, Merklize, + // TODO: Add Hash strategy } impl TryFrom<&Path> for StrategyAttr { diff --git a/commit_verify/derive/tests/common/mod.rs b/commit_verify/derive/tests/common/mod.rs index b3702ba3..a6bfda1c 100644 --- a/commit_verify/derive/tests/common/mod.rs +++ b/commit_verify/derive/tests/common/mod.rs @@ -19,22 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate compiletest_rs as compiletest; - use std::fmt::{Debug, Display, Formatter}; -use std::path::PathBuf; - -#[allow(dead_code)] -pub fn compile_test(mode: &'static str) { - let mut config = compiletest::Config { - mode: mode.parse().expect("Invalid mode"), - src_base: PathBuf::from(format!("tests/{}", mode)), - ..default!() - }; - config.link_deps(); - config.clean_rmeta(); - compiletest::run_tests(&config); -} #[derive(Display)] #[display(inner)] diff --git a/commit_verify/src/convolve.rs b/commit_verify/src/convolve.rs index d9a3598e..2f722180 100644 --- a/commit_verify/src/convolve.rs +++ b/commit_verify/src/convolve.rs @@ -26,11 +26,7 @@ use crate::{CommitmentProtocol, VerifyEq}; /// Error during commitment verification #[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)] #[display(doc_comments)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))] pub enum ConvolveVerifyError { /// commitment doesn't match the message. CommitmentMismatch, diff --git a/commit_verify/src/id.rs b/commit_verify/src/id.rs index d41ad062..b8435fd7 100644 --- a/commit_verify/src/id.rs +++ b/commit_verify/src/id.rs @@ -110,7 +110,7 @@ impl CommitEngine { pub fn commit_to_hash + StrictType>( &mut self, - value: T, + value: &T, ) { let fqn = commitment_fqn::(); self.layout @@ -145,7 +145,7 @@ impl CommitEngine { self.inner_commit_to::<_, COMMIT_MAX_LEN>(&concealed); } - pub fn commit_to_list( + pub fn commit_to_linear_list( &mut self, collection: &Confined, MIN, MAX>, ) where @@ -160,7 +160,7 @@ impl CommitEngine { self.inner_commit_to::<_, COMMIT_MAX_LEN>(&collection); } - pub fn commit_to_set( + pub fn commit_to_linear_set( &mut self, collection: &Confined, MIN, MAX>, ) where @@ -175,7 +175,7 @@ impl CommitEngine { self.inner_commit_to::<_, COMMIT_MAX_LEN>(&collection); } - pub fn commit_to_map( + pub fn commit_to_linear_map( &mut self, collection: &Confined, MIN, MAX>, ) where @@ -209,9 +209,6 @@ impl CommitEngine { pub fn finish_layout(self) -> (Sha256, TinyVec) { (self.hasher, self.layout) } } -/// Prepares the data to the *consensus commit* procedure by first running -/// necessary conceal and merklization procedures, and them performing strict -/// encoding for the resulted data. pub trait CommitEncode { /// Type of the resulting commitment. type CommitmentId: CommitmentId; @@ -263,7 +260,7 @@ where T: CommitEncode + StrictDumb /// High-level API used in client-side validation for producing a single /// commitment to the data, which includes running all necessary procedures like -/// concealment with [`crate::Conceal`], merklization, strict encoding, +/// concealment with [`Conceal`], merklization, strict encoding, /// wrapped into [`CommitEncode`], followed by the actual commitment to its /// output. /// @@ -291,13 +288,9 @@ impl CommitId for T { #[derive(Wrapper, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)] #[wrapper(Deref, BorrowSlice, Display, FromStr, Hex, Index, RangeOps)] -#[derive(StrictDumb, strict_encoding::StrictType, StrictEncode, StrictDecode)] +#[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", transparent) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))] pub struct StrictHash( #[from] #[from([u8; 32])] diff --git a/commit_verify/src/lib.rs b/commit_verify/src/lib.rs index 9b509cb3..59381866 100644 --- a/commit_verify/src/lib.rs +++ b/commit_verify/src/lib.rs @@ -39,8 +39,7 @@ extern crate strict_encoding; extern crate commit_encoding_derive; #[cfg(feature = "serde")] #[macro_use] -extern crate serde_crate as serde; -extern crate core; +extern crate serde; #[cfg(feature = "derive")] pub use commit_encoding_derive::CommitEncode; @@ -136,8 +135,8 @@ mod _reserved { mod _serde { use std::fmt; - use serde_crate::de::Visitor; - use serde_crate::{de, Deserialize, Deserializer, Serialize, Serializer}; + use serde::de::Visitor; + use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use super::*; @@ -155,7 +154,7 @@ mod _reserved { #[derive(Default)] pub struct UntaggedUnitVisitor; - impl<'de> Visitor<'de> for UntaggedUnitVisitor { + impl Visitor<'_> for UntaggedUnitVisitor { type Value = (); fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { diff --git a/commit_verify/src/merkle.rs b/commit_verify/src/merkle.rs index e51985c7..adcb426b 100644 --- a/commit_verify/src/merkle.rs +++ b/commit_verify/src/merkle.rs @@ -19,8 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{iter, slice}; -use std::collections::{btree_set, BTreeSet}; +use std::collections::BTreeSet; use std::ops::SubAssign; use amplify::confinement::Confined; @@ -107,11 +106,7 @@ impl MerkleNode { #[wrapper(Deref, BorrowSlice, Display, FromStr, Hex, Index, RangeOps)] #[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", transparent) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))] pub struct MerkleHash( #[from] #[from([u8; 32])] @@ -202,76 +197,49 @@ impl MerkleHash { pub trait MerkleLeaves { type Leaf: CommitId; - type LeafIter<'tmp>: ExactSizeIterator - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_>; + fn merkle_leaves(&self) -> impl ExactSizeIterator; } impl MerkleLeaves for Confined, MIN, { u8::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u8::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u16::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u16::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u32::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } impl MerkleLeaves for Confined, MIN, { u32::MAX as usize }> -where T: CommitId + Copy +where T: CommitId { type Leaf = T; - type LeafIter<'tmp> - = iter::Copied> - where Self: 'tmp; - - fn merkle_leaves(&self) -> Self::LeafIter<'_> { self.iter().copied() } + fn merkle_leaves(&self) -> impl ExactSizeIterator { self.iter() } } /// Helper struct to track depth when working with Merkle blocks. diff --git a/commit_verify/src/mpc/atoms.rs b/commit_verify/src/mpc/atoms.rs index 00c03448..028daa2d 100644 --- a/commit_verify/src/mpc/atoms.rs +++ b/commit_verify/src/mpc/atoms.rs @@ -30,6 +30,17 @@ use crate::{CommitmentId, DigestExt}; pub const MPC_MINIMAL_DEPTH: u5 = u5::with(3); +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)] +#[display(lowercase)] +#[derive(StrictType, StrictEncode, StrictDecode)] +#[strict_type(lib = crate::LIB_NAME_COMMIT_VERIFY, tags = repr, try_from_u8, into_u8)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))] +#[repr(u8)] +pub enum Method { + #[default] + Sha256t = 0, +} + /// Map from protocol ids to commitment messages. pub type MessageMap = MediumOrdMap; @@ -41,11 +52,7 @@ pub type MessageMap = MediumOrdMap; #[wrapper(Deref, BorrowSlice, Display, FromStr, Hex, Index, RangeOps)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = crate::LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", transparent) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))] pub struct ProtocolId( #[from] #[from([u8; 32])] @@ -65,11 +72,7 @@ impl ProtocolId { #[wrapper(Deref, BorrowSlice, Display, FromStr, Hex, Index, RangeOps)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = crate::LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", transparent) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))] pub struct Message( #[from] #[from([u8; 32])] @@ -121,11 +124,7 @@ impl StrictDumb for Leaf { #[wrapper(Deref, BorrowSlice, Display, FromStr, Hex, Index, RangeOps)] #[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)] #[strict_type(lib = crate::LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", transparent) -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))] pub struct Commitment( #[from] #[from([u8; 32])] @@ -149,6 +148,7 @@ impl From for Commitment { /// Structured source multi-message data for commitment creation #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct MultiSource { + pub method: Method, /// Minimal depth of the created LNPBP-4 commitment tree pub min_depth: u5, /// Map of the messages by their respective protocol ids @@ -160,6 +160,7 @@ impl Default for MultiSource { #[inline] fn default() -> Self { MultiSource { + method: Default::default(), min_depth: MPC_MINIMAL_DEPTH, messages: Default::default(), static_entropy: None, diff --git a/commit_verify/src/mpc/block.rs b/commit_verify/src/mpc/block.rs index 229d364e..a7125ec2 100644 --- a/commit_verify/src/mpc/block.rs +++ b/commit_verify/src/mpc/block.rs @@ -32,7 +32,7 @@ use crate::id::CommitId; use crate::merkle::{MerkleBuoy, MerkleHash}; use crate::mpc::atoms::Leaf; use crate::mpc::tree::protocol_id_pos; -use crate::mpc::{Commitment, MerkleTree, Message, MessageMap, Proof, ProtocolId}; +use crate::mpc::{Commitment, MerkleTree, Message, MessageMap, Method, Proof, ProtocolId}; use crate::{Conceal, LIB_NAME_COMMIT_VERIFY}; /// commitment under protocol id {0} is absent from the known part of a given @@ -46,11 +46,7 @@ pub struct LeafNotKnown(ProtocolId); /// {width}. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Display, Error)] #[display(doc_comments)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))] pub struct InvalidProof { protocol_id: ProtocolId, expected: u32, @@ -81,7 +77,7 @@ pub enum MergeError { tags = order, dumb = { TreeNode::ConcealedNode { depth: u5::ZERO, hash: [0u8; 32].into() } } )] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] enum TreeNode { /// A node of the tree with concealed leaf or tree branch information. ConcealedNode { @@ -134,11 +130,7 @@ impl TreeNode { #[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] #[derive(CommitEncode)] #[commit_encode(crate = crate, strategy = strict, id = Commitment)] -#[cfg_attr( - feature = "serde", - derive(Serialize, Deserialize), - serde(crate = "serde_crate", rename_all = "camelCase") -)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "camelCase"))] pub struct MerkleConcealed { /// Tree depth (up to 16). depth: u5, @@ -163,8 +155,12 @@ impl Conceal for MerkleConcealed { #[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] #[derive(CommitEncode)] #[commit_encode(crate = crate, strategy = conceal, id = Commitment)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct MerkleBlock { + /// Method used to construct MPC proof (hash function, merklization). + #[getter(as_copy)] + method: Method, + /// Tree depth (up to 16). #[getter(as_copy)] depth: u5, @@ -187,6 +183,7 @@ pub struct MerkleBlock { impl StrictDumb for MerkleBlock { fn strict_dumb() -> Self { MerkleBlock { + method: Method::Sha256t, depth: u5::ONE, cofactor: 0, cross_section: NonEmptyVec::with(TreeNode::strict_dumb()), @@ -221,6 +218,7 @@ impl From<&MerkleTree> for MerkleBlock { NonEmptyVec::try_from_iter(iter).expect("tree width guarantees are broken"); MerkleBlock { + method: tree.method, depth: tree.depth, cofactor: tree.cofactor, cross_section, @@ -281,6 +279,7 @@ impl MerkleBlock { NonEmptyVec::try_from(cross_section).expect("tree width guarantees are broken"); Ok(MerkleBlock { + method: proof.method, depth: u5::with(path.len() as u8), cofactor: proof.cofactor, cross_section, @@ -576,6 +575,7 @@ Changed commitment id: {}", "MerkleBlock conceal procedure is broken" ); Ok(MerkleProof { + method: self.method, pos: self.protocol_id_pos(protocol_id), cofactor: self.cofactor, path: Confined::try_from_iter(map.into_values()) @@ -601,6 +601,13 @@ Changed commitment id: {}", /// `2 ^ depth - cofactor`. pub fn factored_width(&self) -> u32 { self.width_limit() - self.cofactor as u32 } + pub fn known_protocol_ids(&self) -> impl Iterator + '_ { + self.cross_section.iter().filter_map(|item| match item { + TreeNode::ConcealedNode { .. } => None, + TreeNode::CommitmentLeaf { protocol_id, .. } => Some(*protocol_id), + }) + } + /// Constructs [`MessageMap`] for revealed protocols and messages. pub fn to_known_message_map(&self) -> MessageMap { Confined::try_from_iter( @@ -617,6 +624,18 @@ Changed commitment id: {}", ) .expect("same collection size") } + + pub fn into_known_proofs(self) -> impl Iterator { + self.known_protocol_ids() + .collect::>() + .into_iter() + .map(move |id| { + let proof = self + .to_merkle_proof(id) + .expect("protocol ids must strictly match"); + (id, proof) + }) + } } impl Conceal for MerkleBlock { @@ -648,8 +667,12 @@ impl Conceal for MerkleBlock { #[derive(Getters, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)] #[derive(StrictType, StrictEncode, StrictDecode)] #[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct MerkleProof { + /// Method used to construct MPC proof (hash function, merklization). + #[getter(as_copy)] + method: Method, + /// Position of the leaf in the tree. /// /// Used to determine chirality of the node hashing partners on each step diff --git a/commit_verify/src/mpc/mod.rs b/commit_verify/src/mpc/mod.rs index c733263f..3044e0bd 100644 --- a/commit_verify/src/mpc/mod.rs +++ b/commit_verify/src/mpc/mod.rs @@ -28,7 +28,7 @@ mod tree; mod block; pub use atoms::{ - Commitment, Leaf, Message, MessageMap, MultiSource, ProtocolId, MPC_MINIMAL_DEPTH, + Commitment, Leaf, Message, MessageMap, Method, MultiSource, ProtocolId, MPC_MINIMAL_DEPTH, }; pub use block::{ InvalidProof, LeafNotKnown, MergeError, MerkleBlock, MerkleConcealed, MerkleProof, diff --git a/commit_verify/src/mpc/tree.rs b/commit_verify/src/mpc/tree.rs index 26c6d267..f1999fc9 100644 --- a/commit_verify/src/mpc/tree.rs +++ b/commit_verify/src/mpc/tree.rs @@ -27,7 +27,8 @@ pub use self::commit::Error; use crate::merkle::MerkleHash; use crate::mpc::atoms::Leaf; use crate::mpc::{ - Commitment, MerkleBlock, MerkleConcealed, Message, MessageMap, Proof, ProtocolId, + Commitment, MerkleBlock, MerkleConcealed, MerkleProof, Message, MessageMap, Method, Proof, + ProtocolId, }; use crate::{CommitId, Conceal, LIB_NAME_COMMIT_VERIFY}; @@ -44,6 +45,9 @@ type OrderedMap = MediumOrdMap; #[derive(CommitEncode)] #[commit_encode(crate = crate, strategy = conceal, id = Commitment)] pub struct MerkleTree { + /// Method used to construct MPC proof (hash function, merklization). + pub(super) method: Method, + /// Tree depth (up to 32). pub(super) depth: u5, @@ -155,6 +159,7 @@ mod commit { map.insert(pos, (*protocol, *message)).is_none() }) { return Ok(MerkleTree { + method: source.method, depth, entropy, cofactor, @@ -201,6 +206,11 @@ impl MerkleTree { pub fn cofactor(&self) -> u16 { self.cofactor } pub fn entropy(&self) -> u64 { self.entropy } + + pub fn into_proofs(self) -> impl Iterator { + let block = MerkleBlock::from(self); + block.into_known_proofs() + } } #[cfg(test)] @@ -244,6 +254,7 @@ pub(crate) mod test_helpers { pub fn make_random_tree(msgs: &BTreeMap) -> MerkleTree { let src = MultiSource { + method: Method::Sha256t, min_depth: u5::ZERO, messages: Confined::try_from_iter(msgs.iter().map(|(a, b)| (*a, *b))).unwrap(), static_entropy: None, diff --git a/commit_verify/src/stl.rs b/commit_verify/src/stl.rs index 4fcd398e..98288c29 100644 --- a/commit_verify/src/stl.rs +++ b/commit_verify/src/stl.rs @@ -24,7 +24,7 @@ use strict_types::{CompileError, LibBuilder, TypeLib}; use crate::{mpc, MerkleHash, MerkleNode, ReservedBytes, StrictHash, LIB_NAME_COMMIT_VERIFY}; pub const LIB_ID_COMMIT_VERIFY: &str = - "stl:egMd32l9-y$Kod0o-$FRcNAV-Q4U$O5h-pskW9YM-$irF0yY#miller-pancake-elastic"; + "stl:~lvTV1Mw-5xmhpcL-cppKeUz-ZLKBRTZ-cpYZPxp-Okxn5dk#uranium-alien-extend"; fn _commit_verify_stl() -> Result { LibBuilder::new(libname!(LIB_NAME_COMMIT_VERIFY), tiny_bset! { diff --git a/single_use_seals/Cargo.toml b/single_use_seals/Cargo.toml index 2839dbfa..bd6be1b5 100644 --- a/single_use_seals/Cargo.toml +++ b/single_use_seals/Cargo.toml @@ -17,13 +17,12 @@ name = "single_use_seals" path = "src/lib.rs" [dependencies] -amplify_derive = "4.0.1" -async-trait = { version = "0.1.81", optional = true } +strict_encoding = { workspace = true, optional = true } +serde = { workspace = true, optional = true } [features] default = [] -all = ["async"] -async = ["async-trait"] +all = ["strict_encoding", "serde"] [package.metadata.docs.rs] features = ["all"] diff --git a/single_use_seals/src/lib.rs b/single_use_seals/src/lib.rs index 872267d8..65e22b6f 100644 --- a/single_use_seals/src/lib.rs +++ b/single_use_seals/src/lib.rs @@ -19,17 +19,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Coding conventions -#![deny( - non_upper_case_globals, - non_camel_case_types, - non_snake_case, - unused_mut, - unused_imports, - dead_code, - missing_docs -)] #![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(not(feature = "strict_encoding"), no_std)] //! # Single-use-seals //! @@ -79,7 +70,7 @@ //! if the seal is open; i.e. seal status may be either "closed over message" //! or "unknown". Some specific implementations of single-use-seals may define //! procedure to deterministically prove that a given seal is not closed (i.e. -//! opened), however this is not a part of the specification and we should +//! opened), however this is not a part of the specification, and we should //! not rely on the existence of such possibility in all cases. //! //! ## Trait structure @@ -112,11 +103,37 @@ //! and Proof-of-Publication. 1. Single-Use-Seal Definition. //! +#[cfg(feature = "strict_encoding")] #[macro_use] -extern crate amplify_derive; -#[cfg(feature = "async")] +extern crate strict_encoding; + +#[cfg(feature = "serde")] #[macro_use] -extern crate async_trait; +extern crate serde; + +use core::borrow::Borrow; +use core::convert::Infallible; +use core::error::Error; +use core::fmt::{self, Debug, Display, Formatter}; +use core::marker::PhantomData; + +#[cfg(feature = "strict_encoding")] +use strict_encoding::{StrictDecode, StrictDumb, StrictEncode}; + +#[cfg(not(feature = "strict_encoding"))] +trait StrictDumb {} +#[cfg(not(feature = "strict_encoding"))] +impl StrictDumb for T {} + +#[cfg(not(feature = "strict_encoding"))] +trait StrictEncode {} +#[cfg(not(feature = "strict_encoding"))] +impl StrictEncode for T {} + +#[cfg(not(feature = "strict_encoding"))] +trait StrictDecode {} +#[cfg(not(feature = "strict_encoding"))] +impl StrictDecode for T {} /// Trait for proof-of-publication medium on which the seals are defined, /// closed, verified and which can be used for convenience operations related to @@ -126,376 +143,188 @@ extern crate async_trait; /// * get some identifier on the exact place of the witness publication /// * check validity of the witness publication identifier /// -/// Since the medium may require network communications or extensive computing -/// involved (like in case with blockchain) there is a special asynchronous -/// version of the seal medium [`SealProtocolAsync`], which requires use of -/// `async` feature of this crate. -/// /// All these operations are medium-specific; for the same single-use-seal type /// they may differ when are applied to different proof of publication mediums. /// /// To read more on proof-of-publication please check /// -pub trait SealProtocol { - /// Associated type for the witness produced by the single-use-seal close - /// procedure - type Witness; +pub trait SingleUseSeal: + Clone + Debug + Display + StrictDumb + StrictEncode + StrictDecode +{ + /// Message type that is supported by the current single-use-seal. + type Message: Copy + Eq; - /// Message type that is supported by the current single-use-seal - type Message; + type PubWitness: PublishedWitness + StrictDumb + StrictEncode + StrictDecode; - /// Publication id that may be used for referencing publication of - /// witness data in the medium. By default set `()`, so [`SealProtocol`] - /// may not implement publication id and related functions - type PublicationId; + type CliWitness: ClientSideWitness + StrictDumb + StrictEncode + StrictDecode; - /// Error type that contains reasons of medium access failure - type Error: std::error::Error; + fn is_included(&self, message: Self::Message, witness: &SealWitness) -> bool; +} - /// Checks the status for a given seal in proof-of-publication medium - fn get_seal_status(&self, seal: &Seal) -> Result; +pub trait ClientSideWitness: Eq { + /// Client-side witness is specific to just one type of single-use seals, + /// provided as an associated type. + type Seal: SingleUseSeal; + /// Proof which is passed from the client-side witness to the public-side + /// witness during single-use seal validation. + type Proof; + type Error: Clone + Error; - /// Publishes witness data to the medium. Function has default - /// implementation doing nothing and returning - /// [`SealMediumError::PublicationNotSupported`] error. - fn publish_witness( - &mut self, - _witness: &Self::Witness, - ) -> Result> { - Err(SealMediumError::PublicationNotSupported) - } - - /// Returns [`Self::PublicationId`] for a given witness, if any; the id is - /// returned as an option. Function has default implementation doing - /// nothing and just returning - /// [`SealMediumError::PublicationNotSupported`] error. - fn get_witness_publication_id( + fn convolve_commit( &self, - _witness: &Self::Witness, - ) -> Result, SealMediumError> { - Err(SealMediumError::PublicationNotSupported) - } + msg: ::Message, + ) -> Result; - /// Validates whether a given publication id is present in the medium. - /// Function has default implementation doing nothing and returning - /// [`SealMediumError::PublicationNotSupported`] error. - fn validate_publication_id( - &self, - _publication_id: &Self::PublicationId, - ) -> Result> { - Err(SealMediumError::PublicationNotSupported) - } -} - -/// Adds support for the seal close operation to [`SealProtocol`]. -pub trait CloseSeal: SealProtocol { - /// Closes seal over a message, producing *witness*. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - fn close_seal( - &mut self, - seal: &Seal, - over: &Self::Message, - ) -> Result; - - /// Closes number of related seals over the same message, producing a single - /// *witness*. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - fn close_all_seals<'seal>( - &mut self, - seals: impl IntoIterator, - over: &Self::Message, - ) -> Result - where - Seal: 'seal; + fn merge(&mut self, other: Self) -> Result<(), impl Error> + where Self: Sized; } -/// Adds support to [`SealProtocol`] for merging seal close operation into an -/// existing witness data (closing some other seals). -pub trait MergeCloseSeal: SealProtocol { - /// Closes seal over a message, adding witness to some existing *witness* - /// container. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - fn merge_close_seal( - &mut self, - seal: &Seal, - over: &Self::Message, - witness_proto: Self::Witness, - ) -> Result; +#[derive(Copy, Clone, Debug, Default)] +pub struct NoWitness(PhantomData); - /// Closes number of related seals over the same message, adding witness to - /// some existing *witness* container. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - fn merge_close_all_seals<'seal>( - &mut self, - seals: impl IntoIterator, - over: &Self::Message, - ) -> Result - where - Seal: 'seal; +impl PartialEq for NoWitness { + fn eq(&self, _: &Self) -> bool { true } } +impl Eq for NoWitness {} -/// Seal witness which can verify seal or multiple seals. -pub trait SealWitness { - /// Message type that is supported by the current single-use-seal - type Message; +impl ClientSideWitness for NoWitness { + type Seal = Seal; + type Proof = Seal::Message; + type Error = Infallible; - /// Error type that contains reasons of medium access failure - type Error: std::error::Error; + fn convolve_commit(&self, msg: Seal::Message) -> Result { Ok(msg) } - /// Verifies that the seal was indeed closed over the message with the - /// provided seal closure witness. - fn verify_seal(&self, seal: &Seal, msg: &Self::Message) -> Result<(), Self::Error>; - - /// Performs batch verification of the seals. - /// - /// Default implementation iterates through the seals and calls - /// [`Self::verify_seal`] for each of them, returning `false` on first - /// failure (not verifying the rest of seals). - fn verify_many_seals<'seal>( - &self, - seals: impl IntoIterator, - msg: &Self::Message, - ) -> Result<(), Self::Error> - where - Seal: 'seal, - { - for seal in seals { - self.verify_seal(seal, msg)?; - } - Ok(()) + fn merge(&mut self, _: Self) -> Result<(), impl Error> + where Self: Sized { + Ok::<_, Infallible>(()) } } -/// Asynchronous version of the [`SealProtocol`] trait. -#[cfg(feature = "async")] -#[async_trait] -pub trait SealProtocolAsync -where - Seal: Sync + Send, - Self: Send + Sync, -{ - /// Associated type for the witness produced by the single-use-seal close - /// procedure - type Witness: Sync + Send; - - /// Message type that is supported by the current single-use-seal - type Message; - +/// Public witness can be used by multiple types of single-use seals, hence it +/// has the seal type as a generic parameter. +pub trait PublishedWitness { /// Publication id that may be used for referencing publication of - /// witness data in the medium. By default set `()`, so - /// [`SealProtocolAsync`] may not implement publication id and related - /// functions - type PublicationId: Sync; - - /// Error type that contains reasons of medium access failure - type Error: std::error::Error; - - /// Checks the status for a given seal in proof-of-publication medium - async fn get_seal_status_async(&self, seal: &Seal) -> Result; + /// witness data in the medium. By default, set `()`, so [`SingleUseSeal`] + /// may not implement publication id and related functions. + type PubId: Copy + Ord + Debug + Display; + type Error: Clone + Error; - /// Publishes witness data to the medium. Function has default - /// implementation doing nothing and returning - /// [`SealMediumError::PublicationNotSupported`] error. - async fn publish_witness_async( - &mut self, - _witness: &Self::Witness, - ) -> Result> { - Err(SealMediumError::PublicationNotSupported) - } - - /// Returns [`Self::PublicationId`] for a given witness, if any; the id is - /// returned as an option. Function has default implementation doing - /// nothing and just returning - /// [`SealMediumError::PublicationNotSupported`] error. - async fn get_witness_publication_id_async( - &self, - _witness: &Self::Witness, - ) -> Result, SealMediumError> { - Err(SealMediumError::PublicationNotSupported) - } - - /// Validates whether a given publication id is present in the medium. - /// Function has default implementation doing nothing and returning - /// [`SealMediumError::PublicationNotSupported`] error. - async fn validate_publication_id_async( + fn pub_id(&self) -> Self::PubId; + fn verify_commitment( &self, - _publication_id: &Self::PublicationId, - ) -> Result> { - Err(SealMediumError::PublicationNotSupported) - } + proof: ::Proof, + ) -> Result<(), Self::Error>; } -/// Adds support for the seal close operation to [`SealProtocolAsync`]. -#[cfg(feature = "async")] -#[async_trait] -pub trait CloseSealAsync: SealProtocolAsync -where Seal: Sync + Send -{ - /// Closes seal over a message, producing *witness*. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - async fn close_seal_async( - &mut self, - seal: &Seal, - over: &Self::Message, - ) -> Result; - - /// Closes number of related seals over the same message, producing a single - /// *witness*. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - async fn seal_close_all_async<'seal>( - &mut self, - seals: impl IntoIterator, - over: &Self::Message, - ) -> Result - where - Seal: 'seal; -} - -/// Adds support to [`SealProtocolAsync`] for merging seal close operation into -/// an existing witness data (closing some other seals). -#[cfg(feature = "async")] -#[async_trait] -pub trait MergeCloseSealAsync: SealProtocolAsync -where Seal: Sync + Send +/// Seal closing witness. +#[derive(Clone, Copy)] +#[cfg_attr( + feature = "strict_encoding", + derive(StrictType, StrictDumb, StrictEncode, StrictDecode), + strict_type(lib = "SingleUseSeals") +)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(bound = "Seal::PubWitness: serde::Serialize + for<'d> serde::Deserialize<'d>, \ + Seal::CliWitness: serde::Serialize + for<'d> serde::Deserialize<'d>") +)] +pub struct SealWitness +where Seal: SingleUseSeal { - /// Closes seal over a message, adding witness to some existing *witness* - /// container. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - async fn merge_close_seal_async( - &mut self, - seal: &Seal, - over: &Self::Message, - witness_proto: Self::Witness, - ) -> Result; - - /// Closes number of related seals over the same message, adding witness to - /// some existing *witness* container. - /// - /// NB: Closing of the seal MUST not change the internal state of the - /// seal itself; all the data produced by the process must be placed - /// into the returned Witness type. - /// - /// The witness _is not_ published by this method to the seal medium. - async fn merge_close_all_seals_async<'seal>( - &mut self, - seals: impl IntoIterator, - over: &Self::Message, - ) -> Result - where - Seal: 'seal; + pub published: Seal::PubWitness, + pub client: Seal::CliWitness, + #[cfg_attr(feature = "serde", serde(skip))] + #[cfg_attr(feature = "strict_encoding", strict_type(skip))] + _phantom: PhantomData, } -/// Async version of [`SealWitness`] which can verify seal or multiple seals. -#[cfg(feature = "async")] -#[async_trait] -pub trait SealWitnessAsync -where Seal: Sync + Send +impl SealWitness +where Seal: SingleUseSeal { - /// Message type that is supported by the current single-use-seal - type Message: Sync; - - /// Error type that contains reasons of medium access failure - type Error: std::error::Error; + pub fn new(published: Seal::PubWitness, client: Seal::CliWitness) -> Self { + Self { + published, + client, + _phantom: PhantomData, + } + } - /// Verifies that the seal was indeed closed over the message with the - /// provided seal closure witness. - async fn verify_seal_async(&self, seal: &Seal, msg: &Self::Message) -> Result<(), Self::Error>; + pub fn verify_seal_closing( + &self, + seal: impl Borrow, + message: Seal::Message, + ) -> Result<(), SealError> { + self.verify_seals_closing([seal], message) + } - /// Performs batch verification of the seals. - /// - /// Default implementation iterates through the seals and calls - /// [`Self::verify_seal_async`] for each of them, returning `false` on - /// first failure (not verifying the rest of seals). - async fn verify_all_seals_async<'seal, I>( + pub fn verify_seals_closing( &self, - seals: I, - msg: &Self::Message, - ) -> Result<(), Self::Error> - where - I: IntoIterator + Send, - I::IntoIter: Send, - Seal: 'seal, - { + seals: impl IntoIterator>, + message: Seal::Message, + ) -> Result<(), SealError> { + // ensure that witness includes all seals for seal in seals { - self.verify_seal_async(seal, msg).await?; + seal.borrow() + .is_included(message, self) + .then_some(()) + .ok_or(SealError::NotIncluded(seal.borrow().clone(), self.published.pub_id()))?; } - return Ok(()); + // ensure that published witness contains the commitment to the + // f(message), where `f` is defined in the client-side witness + let f_msg = self + .client + .convolve_commit(message) + .map_err(SealError::Client)?; + self.published + .verify_commitment(f_msg) + .map_err(SealError::Published) } } -/// Single-use-seal status returned by [`SealProtocol::get_seal_status`] and -/// `SealProtocolAsync::get_seal_status` functions. -/// -/// NB: It's important to note, that while its possible to deterministically -/// define was a given seal closed it yet may be not possible to find out -/// if the seal is open without provision of the message and witness; i.e. -/// seal status may be either "closed over message" -/// or "unknown". Some specific implementations of single-use-seals may define -/// procedure to deterministically prove that a given seal is not closed (i.e. -/// opened), however this is not a part of the specification and we should -/// not rely on the existence of such possibility in all cases. -#[derive(Clone, Copy, Debug, Display)] -#[display(Debug)] -#[repr(u8)] -pub enum SealStatus { - /// It is unknown/undetermined whether the seal was closed - Undefined = 0, +#[derive(Clone)] +pub enum SealError { + NotIncluded(Seal, >::PubId), + Published(>::Error), + Client(::Error), +} - /// The seal is closed - Closed = 1, +impl Debug for SealError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + SealError::NotIncluded(seal, pub_id) => f + .debug_tuple("SealError::NotIncluded") + .field(seal) + .field(pub_id) + .finish(), + SealError::Published(err) => f.debug_tuple("SealError::Published").field(err).finish(), + SealError::Client(err) => f.debug_tuple("SealError::Client(err").field(err).finish(), + } + } } -/// Error returned by [`SealProtocol`] and `SealProtocolAsync` functions related -/// to work with publication id ([`SealProtocol::PublicationId`]). Required -/// since not all implementation of [`SealProtocol`] may define publication -/// identifier, and the traits provide default implementation for these -/// functions always returning [`SealMediumError::PublicationNotSupported`]. If -/// the implementation would like to provide custom implementation, it may embed -/// standard error related to [`SealProtocol`] operations within -/// [`SealMediumError::MediumAccessError`] case; the type of MediumAccessError -/// is defined through generic argument to [`SealMediumError`]. -#[derive(Clone, Copy, Debug, Display, Error, From)] -#[display(doc_comments)] -pub enum SealMediumError { - /// Can't access the publication medium - #[from] - MediumAccessError(E), +impl Display for SealError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + SealError::NotIncluded(seal, pub_id) => { + write!(f, "seal {seal} is not included in the witness {pub_id}") + } + SealError::Published(err) => Display::fmt(err, f), + SealError::Client(err) => Display::fmt(err, f), + } + } +} - /// Publication id is not supported - PublicationNotSupported, +impl Error for SealError +where + <::PubWitness as PublishedWitness>::Error: 'static, + <::CliWitness as ClientSideWitness>::Error: 'static, +{ + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + SealError::NotIncluded(..) => None, + SealError::Published(e) => Some(e), + SealError::Client(e) => Some(e), + } + } } diff --git a/src/api.rs b/src/api.rs index 32db4010..7b462d5c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -133,7 +133,7 @@ pub trait ValidationReport { /// Client-side-validation status containing all reports from the validation /// process #[derive(Clone, PartialEq, Eq, Hash, Debug, Default)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Status where R: ValidationReport { @@ -389,133 +389,3 @@ pub trait SealResolver { /// (like network connectivity) or if the seal is not (yet) closed. fn resolve_trust(&mut self, seal: &Seal) -> Result<(), Self::Error>; } - -#[cfg(test)] -mod test { - // Tests use emulation of a simple client-side-validated state, consisting - // of an array of data items, each of which has a name bound to a certain - // bitcoin single-use-seal. - - use single_use_seals::{SealProtocol, SealStatus, SealWitness}; - - use super::*; - - #[test] - #[allow(dead_code)] - fn test() { - #[derive(Clone, PartialEq, Eq, Hash, Debug, Default)] - #[derive(Serialize, Deserialize)] - #[serde(crate = "serde_crate")] - struct Seal {} - - struct Protocol {} - - impl SealProtocol for Protocol { - type Witness = (); - type Message = Vec; - type PublicationId = (); - type Error = Issue; - - fn get_seal_status(&self, _seal: &Seal) -> Result { - Ok(SealStatus::Undefined) - } - } - - #[allow(non_local_definitions)] - impl SealWitness for () { - type Message = Vec; - type Error = Issue; - - fn verify_seal(&self, _seal: &Seal, _msg: &Self::Message) -> Result<(), Self::Error> { - Ok(()) - } - } - - #[derive(Clone, PartialEq, Eq, Hash, Debug)] - struct Report {} - - #[derive(Clone, PartialEq, Eq, Hash, Debug)] - #[derive(Serialize, Deserialize)] - #[serde(crate = "serde_crate")] - struct Issue { - seal: Seal, - } - impl Display for Issue { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.write_str("") } - } - impl std::error::Error for Issue {} - - impl ValidationLog for Issue {} - - impl ValidationFailure for Issue {} - - impl SealIssue for Issue { - type Seal = Seal; - - fn seal(&self) -> &Self::Seal { &self.seal } - } - - impl ValidationReport for Report { - type SealIssue = Issue; - type Failure = Issue; - type Warning = Issue; - type Info = Issue; - } - - #[derive(Default)] - struct Data { - seals: Vec, - } - - impl<'a> ClientData<'a> for Data - where Data: 'a - { - type ValidationReport = Report; - type SealIterator = std::slice::Iter<'a, Seal>; - - fn single_use_seals(&'a self) -> Self::SealIterator { self.seals.iter() } - - fn validate_internal_consistency(&self) -> Status { - Status::new() - } - } - - struct State { - pub data: Vec, - } - - impl<'a> ClientData<'a> for State { - type ValidationReport = Report; - type SealIterator = std::slice::Iter<'a, Seal>; - - fn single_use_seals(&self) -> Self::SealIterator { [].iter() } - - fn validate_internal_consistency(&self) -> Status { - Status::new() - } - } - - impl<'a> ClientSideValidate<'a> for State { - type ValidationItem = Data; - type ValidationIter = std::slice::Iter<'a, Data>; - - fn validation_iter(&'a self) -> Self::ValidationIter { self.data.iter() } - } - - #[derive(Default)] - struct Resolver {} - - impl SealResolver for Resolver { - type Error = Issue; - - fn resolve_trust(&mut self, _seal: &Seal) -> Result<(), Self::Error> { Ok(()) } - } - - let state = State { - data: vec![Data::default()], - }; - let mut resolver = Resolver::default(); - let status = state.client_side_validate(&mut resolver); - assert_eq!(status, Status::new()); - } -} diff --git a/src/lib.rs b/src/lib.rs index 05bd3ab7..e95a4b94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ pub extern crate single_use_seals as seals; #[cfg(feature = "serde")] #[macro_use] -extern crate serde_crate as serde; +extern crate serde; mod api; diff --git a/stl/CommitVerify@0.1.0.sta b/stl/CommitVerify@0.1.0.sta index 5af897f2..6ae045a7 100644 --- a/stl/CommitVerify@0.1.0.sta +++ b/stl/CommitVerify@0.1.0.sta @@ -1,34 +1,36 @@ -----BEGIN STRICT TYPE LIB----- -Id: stl:egMd32l9-y$Kod0o-$FRcNAV-Q4U$O5h-pskW9YM-$irF0yY#miller-pancake-elastic +Id: stl:~lvTV1Mw-5xmhpcL-cppKeUz-ZLKBRTZ-cpYZPxp-Okxn5dk#uranium-alien-extend Name: CommitVerify -Dependencies: Std#ralph-blue-lucky -Check-SHA256: ce5ec3f773efffb6535247e84c9da1bfc1656c1a35c616832abf5eecaa5feb44 +Dependencies: Std#delete-roman-hair +Check-SHA256: 12d6d38f44d9e6a9a9c3c592144a23d22f94eeb9330280208889ba8d4c7f8b35 -3`1{iZE18?WpZg|c>&5S9&dx0-7pM3Z=O*v*GCA9fL-<|HrZsA`NnJlR3`&dbYuYoQ*>kj0A^Tl*p6J$ -36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k^)sV5C958Z*6U9bZupBbOiwb2LJ#-AOHkRWnpFn0uTvlZfId* +3`1{iZE18?WpZg|c>#in>rD>}a8$2!O9kk`*PSB+rd(so&!uOW`TABoF=_)-bYuYoQ*>kj0A^Tl*p6J$ +36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k^)sV5daE9Z*6U9bZupBbOiwb2LJ#-AOHkRWnpFn0uTvlZfId* X>?^|00sgGaB^>SZ)0z40Wg(*<{e=)S-S-YV@1=_p5>Oab-~jCR3C`SFec^=zG+gvC|O;Wo~qGZ*X}41_B3VZgg^QaCra#2m^3$a{vGY3r%HmYiwmg -Y;R+01_T9UWpH$80?I5NZ-bfLFbqC#o>4E?M+l67UG^w8*<_XZ#%uyqCuUf1*p6J$36SYb7g#;qpQBTp -wL(~+!(f@;t~vt?k_cmOW?^G=Z*l+t0t{nvZ*y}~Wn*+{Z*Bkx0ob*-9G+(AKhLw+s!eDmlO2> -&}_PPHjCBJR{;P3000000RR90{{R3000(7mbaHQSc>n|g00eGtZe;)f009JZZ*64&1pxp62oFtVa%*g5 -LvLy0X3z7(9Z)Ra*bZ>G100IhaWpZn5Wm0c%bOAV?Lxv|61vo|G100IbYWpi_3 -XJvB$3IQ;ce&!uvG+Da^2;||fJ!&Dp*8BS%F@mRgpt-$m)gMQunKY@^NKR1twFJLRYVe -6X<)?o3YaX0000000030|Nj6000003ZDDW#3IG5E00ja8FqMAh9bq(Cy9Eg3;jcYvA-~r9`yDZYr+MW? -bl_I80W~+NQ5DGQh1^p2tAX-yWl;qtQ~GYywm#W>|38j$F|Rkm*bpSUudIqf?x@I6Zgfm#VP*gZ0t#?)Z**^C -Z){0q0Wg(*<{e=)S-S-YV@1=_p5>Oab-~j -CR3C`SFec^=zG+gvC{ +Y;R+01_cIfWprq7WB~(WnmCQUKfIKMdeaUn;%i1on4VMq8@@As0m&QqLVg8gWpH$80)mO_O%DrjRIhYP +1?a)oog)LLTw}}6rDvG=`c^zKYGzn)*p6J$36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k_cmOW?^G=Z*l+t +0t{nvZ*y}~Wn*+{Z*Bkx0ob*-9G+(AKhLw+s!eDmlO2>&}_PPHjCBJR{;P3000000RR90{{R30 +00(7mbaHQSc>n|g00eGtZe;)f009JZZ*64&1pxp62oFtVa%*g5LvLrD>} +a8$2!O9kk`*PSB+rd(so&!uOW`TABoF=}R5aM+Gq(Fu_0Ocz)^+@GUUoV7w&pu=F9->y0X3z7(9Z)Ra* +bZ>G100IhaWpZn5Wm0c%bOAV?Lxv|61vo|G100IbYWpi_3XJvB$3IQ;c +e&!uvG+Da^2;||fJ!&Dp*8BS%F@mRgpt-$m)gMQunKY@^NKR1twFJLRYVe6X<)?o3YaX +0000000030|Nj6000003ZDDW#3IG5E00ja8FqMAh9bq(Cy9Eg3;jcYvA-~r9`yDZYr+MW?bl_I80W~+N +Q5DGQh1^p2tAX-yWl;qtQ+pX>Mn1WdR0aa$#;`XaWjQa&L5RV{dFp +WCZ~L2LJ#-AOH?hWpib6c4cHjd30rSF$Dnt2LJ#-0RRqCWpib6c4cHjd30rSG6ewu2LJ#-0sszDWpib6 +c4cHjd30rSGz9?w2LJ#-1ON(CbaH89bVy-yXaxZP2LJ#-AOHwda%E*sZ)9Zz0sswTZ*F5{VQgh&PH$vo +00sgDWMy!4Xaa(X>rD>}a8$2!O9kk`*PSB+rd(so&!uOW`TABoF=}R5aM+Gq(Fu_0Ocz)^+@GUUoV7w& +pu=F9->y0X3z7tAVRL8!IG#g>Clv)aMjKgwAH@`bu1x<7g|G$};xvA~n-$_S0S;qtZEb0EZDnqBOl4ta +00sgIaB^>SZ)0z4Nn`;qm44Q3WPbltNdpi4*91)SI!> -----END STRICT TYPE LIB----- diff --git a/stl/CommitVerify@0.1.0.stl b/stl/CommitVerify@0.1.0.stl index 6f83b362..f3e3d6ea 100644 Binary files a/stl/CommitVerify@0.1.0.stl and b/stl/CommitVerify@0.1.0.stl differ diff --git a/stl/CommitVerify@0.1.0.sty b/stl/CommitVerify@0.1.0.sty index ab2f6ba6..078b1bb7 100644 --- a/stl/CommitVerify@0.1.0.sty +++ b/stl/CommitVerify@0.1.0.sty @@ -1,5 +1,5 @@ {- - Id: stl:egMd32l9-y$Kod0o-$FRcNAV-Q4U$O5h-pskW9YM-$irF0yY#miller-pancake-elastic + Id: stl:~lvTV1Mw-5xmhpcL-cppKeUz-ZLKBRTZ-cpYZPxp-Okxn5dk#uranium-alien-extend Name: CommitVerify Version: 0.1.0 Description: Client-side-validation deterministic commitments @@ -11,7 +11,7 @@ @context typelib CommitVerify -import Std#ralph-blue-lucky +import Std#delete-roman-hair use U5#orbit-graph-sonic @@ -22,8 +22,9 @@ data Commitment : [Byte ^ 32] data Leaf : inhabited#16 (protocol ProtocolId, message Message) | entropy (entropy U64, pos U32) -@mnemonic(snake-kitchen-june) -data MerkleBlock : depth Std.U5 +@mnemonic(gong-elite-seminar) +data MerkleBlock : method Method + , depth Std.U5 , cofactor U16 , crossSection [TreeNode ^ 1..0xffffffff] , entropy U64? @@ -43,13 +44,15 @@ data MerkleNode : branching NodeBranching , node1 MerkleHash , node2 MerkleHash -@mnemonic(potato-rubber-hobby) -data MerkleProof : pos U32 +@mnemonic(edison-pablo-orinoco) +data MerkleProof : method Method + , pos U32 , cofactor U16 , path [MerkleHash ^ ..0x20] -@mnemonic(horizon-pigment-dialog) -data MerkleTree : depth Std.U5 +@mnemonic(jump-respond-panda) +data MerkleTree : method Method + , depth Std.U5 , entropy U64 , cofactor U16 , messages {ProtocolId -> ^ ..0xffffff Message} @@ -58,6 +61,10 @@ data MerkleTree : depth Std.U5 @mnemonic(druid-blitz-rover) data Message : [Byte ^ 32] +@mnemonic(subject-justin-cowboy) +data Method : sha256t | (|) + + @mnemonic(member-dexter-price) data NodeBranching : void | single | branch diff --git a/stl/Merkle.vesper b/stl/Merkle.vesper index c4ee87a0..7c82750c 100644 --- a/stl/Merkle.vesper +++ b/stl/Merkle.vesper @@ -10,91 +10,93 @@ Merklization vesper lexicon=types+commitments -- General merklization workflows -MerkleHash commitment hasher=SHA256 tagged=urn:ubideco:merkle:node#2024-01-31 - MerkleNode serialized +commitment MerkleHash, hasher SHA256, tagged urn:ubideco:merkle:node#2024-01-31 + serialized MerkleNode -MerkleNode rec - branching enum NodeBranching void=0 single=1 branch=2 - depth is U8 - width is U256 - node1 bytes len=32 aka=MerkleHash - node2 bytes len=32 aka=MerkleHash +rec MerkleNode + enum branching, NodeBranching, void 0, single 1, branch 2 + is depth, U8 + is width, U256 + bytes node1, len 32, aka MerkleHash + bytes node2, len 32, aka MerkleHash -- Multi-protocol commitment workflows -MerkleHash commitment hasher=SHA256 tagged=urn:ubideco:merkle:node#2024-01-31 - Leaf serialized - -Leaf union - inhabited rec tag=0 - protocol bytes len=32 aka=ProtocolId - message bytes len=32 aka=Message - entropy rec tag=1 - entropy is U64 - pos is U32 - -Commitment commitment hasher=SHA256 tagged=urn:ubideco:mpc:commitment#2024-01-31 - MerkleConcealed serialized - -MerkleConcealed rec - depth enum { - U5 _0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 - _8=8 _9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 - _16=16 _17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 - _24=24 _25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 +commitment MerkleHash, hasher SHA256, tagged urn:ubideco:merkle:node#2024-01-31 + serialized Leaf + +union Leaf + rec inhabited, tag 0 + bytes protocol, len 32, aka ProtocolId + bytes message, len 32, aka Message + rec entropy, tag 1 + is entropy, U64 + is pos, U32 + +commitment Commitment, hasher SHA256, tagged urn:ubideco:mpc:commitment#2024-01-31 + serialized MerkleConcealed + +rec MerkleConcealed + enum depth { + U5, _0 0, _1 1, _2 2, _3 3, _4 4, _5 5, _6 6, _7 7 + _8 8, _9 9, _10 10, _11 11, _12 12, _13 13, _14 14, _15 15 + _16 16, _17 17, _18 18, _19 19, _20 20, _21 21, _22 22, _23 23 + _24 24, _25 25, _26 26, _27 27, _28 28, _29 29, _30 30, _31 31 } - cofactor is U16 - merkleRoot bytes len=32 aka=MerkleHash - -Commitment commitment hasher=SHA256 tagged=urn:ubideco:mpc:commitment#2024-01-31 - MerkleConcealed concealed concealed=MerkleConcealed - -MerkleBlock rec - depth enum { - U5 _0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 - _8=8 _9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 - _16=16 _17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 - _24=24 _25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 + is cofactor, U16 + bytes merkleRoot, len 32, aka MerkleHash + +commitment Commitment, hasher SHA256, tagged urn:ubideco:mpc:commitment#2024-01-31 + concealed MerkleConcealed, concealed MerkleConcealed + +rec MerkleBlock + enum method, Method, sha256t 0 + enum depth { + U5, _0 0, _1 1, _2 2, _3 3, _4 4, _5 5, _6 6, _7 7 + _8 8, _9 9, _10 10, _11 11, _12 12, _13 13, _14 14, _15 15 + _16 16, _17 17, _18 18, _19 19, _20 20, _21 21, _22 22, _23 23 + _24 24, _25 25, _26 26, _27 27, _28 28, _29 29, _30 30, _31 31 } - cofactor is U16 - crossSection list len=1..MAX32 - TreeNode union - concealedNode rec tag=0 - depth enum { - U5 _0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 - _8=8 _9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 - _16=16 _17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 - _24=24 _25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 + is cofactor, U16 + list crossSection, len 1..MAX32 + union TreeNode + rec concealedNode, tag 0 + enum depth { + U5, _0 0, _1 1, _2 2, _3 3, _4 4, _5 5, _6 6, _7 7 + _8 8, _9 9, _10 10, _11 11, _12 12, _13 13, _14 14, _15 15 + _16 16, _17 17, _18 18, _19 19, _20 20, _21 21, _22 22, _23 23 + _24 24, _25 25, _26 26, _27 27, _28 28, _29 29, _30 30, _31 31 } - hash bytes len=32 aka=MerkleHash - commitmentLeaf rec tag=1 - protocolId bytes len=32 aka=ProtocolId - message bytes len=32 aka=Message - some is U64 option wrapped tag=1 - -Commitment commitment hasher=SHA256 tagged=urn:ubideco:mpc:commitment#2024-01-31 - MerkleConcealed concealed concealed=MerkleConcealed - -MerkleTree rec - depth enum { - U5 _0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 - _8=8 _9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 - _16=16 _17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 - _24=24 _25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 + bytes hash, len 32, aka MerkleHash + rec commitmentLeaf, tag 1 + bytes protocolId, len 32, aka ProtocolId + bytes message, len 32, aka Message + is some, U64, option, wrapped, tag 1 + +commitment Commitment, hasher SHA256, tagged urn:ubideco:mpc:commitment#2024-01-31 + concealed MerkleConcealed, concealed MerkleConcealed + +rec MerkleTree + enum method, Method, sha256t 0 + enum depth { + U5, _0 0, _1 1, _2 2, _3 3, _4 4, _5 5, _6 6, _7 7 + _8 8, _9 9, _10 10, _11 11, _12 12, _13 13, _14 14, _15 15 + _16 16, _17 17, _18 18, _19 19, _20 20, _21 21, _22 22, _23 23 + _24 24, _25 25, _26 26, _27 27, _28 28, _29 29, _30 30, _31 31 } - entropy is U64 - cofactor is U16 - messages map len=0..MAX24 - key bytes len=32 aka=ProtocolId - value bytes len=32 aka=Message - map map len=0..MAX24 - key is U32 - value tuple - _ bytes len=32 aka=ProtocolId - _ bytes len=32 aka=Message + is entropy, U64 + is cofactor, U16 + map messages, len 0..MAX24 + bytes key, len 32, aka ProtocolId + bytes value, len 32, aka Message + map map, len 0..MAX24 + is key, U32 + tuple value + bytes _, len 32, aka ProtocolId + bytes _, len 32, aka Message