Compare commits

...

6 Commits

Author SHA1 Message Date
7ee8cacc03 fix 2022-01-17 02:35:59 +03:00
a207c52ce8 pr fixes 2022-01-17 02:34:05 +03:00
f27a7e635e fix ci 2022-01-11 17:07:10 +03:00
dce846d1c7 pr fix 2022-01-11 17:01:15 +03:00
6384d3d67d fix 2022-01-11 16:55:54 +03:00
bf30873fcb add hl-api, add example with trusted computation 2021-12-30 03:52:16 +03:00
26 changed files with 12330 additions and 2100 deletions

View File

@ -16,7 +16,7 @@ jobs:
sudo bash .github/download_marine.sh
- restore_cache:
keys:
- trust-graph00-{{ checksum "./service/Cargo.lock" }}-{{ checksum "./Cargo.lock" }}-{{ checksum "./keypair/Cargo.lock" }}
- trust-graph00-{{ checksum "./Cargo.lock" }}-{{ checksum "./keypair/Cargo.lock" }}
- run: |
rustup target add wasm32-wasi
cargo test --no-fail-fast --release --all-features --

289
Cargo.lock generated
View File

@ -39,9 +39,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.51"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
[[package]]
name = "arrayref"
@ -143,7 +143,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array 0.14.4",
"generic-array 0.14.5",
]
[[package]]
@ -175,9 +175,9 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3"
[[package]]
name = "bumpalo"
version = "3.8.0"
version = "3.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
[[package]]
name = "byte-tools"
@ -331,9 +331,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -352,9 +352,9 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -365,9 +365,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
@ -395,7 +395,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab"
dependencies = [
"generic-array 0.14.4",
"generic-array 0.14.5",
"subtle 2.4.1",
]
@ -417,7 +417,7 @@ checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61"
dependencies = [
"byteorder",
"digest 0.9.0",
"rand_core 0.5.1",
"rand_core",
"subtle 2.4.1",
"zeroize",
]
@ -434,12 +434,12 @@ dependencies = [
[[package]]
name = "darling"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12"
checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4"
dependencies = [
"darling_core 0.13.0",
"darling_macro 0.13.0",
"darling_core 0.13.1",
"darling_macro 0.13.1",
]
[[package]]
@ -458,9 +458,9 @@ dependencies = [
[[package]]
name = "darling_core"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3"
checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324"
dependencies = [
"fnv",
"ident_case",
@ -483,11 +483,11 @@ dependencies = [
[[package]]
name = "darling_macro"
version = "0.13.0"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc"
checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b"
dependencies = [
"darling_core 0.13.0",
"darling_core 0.13.1",
"quote",
"syn",
]
@ -524,7 +524,7 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array 0.14.4",
"generic-array 0.14.5",
]
[[package]]
@ -545,10 +545,10 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d"
dependencies = [
"curve25519-dalek",
"ed25519",
"rand 0.7.3",
"rand",
"serde",
"serde_bytes",
"sha2 0.9.8",
"sha2 0.9.9",
"zeroize",
]
@ -570,9 +570,9 @@ dependencies = [
[[package]]
name = "erased-serde"
version = "0.3.16"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3de9ad4541d99dc22b59134e7ff8dc3d6c988c89ecd7324bf10a8362b07a2afa"
checksum = "44a5d80251b806a14cd3e4e1a582e912d5cbf6904ab19fdefbd7a56adca088e1"
dependencies = [
"serde",
]
@ -648,6 +648,15 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"
[[package]]
name = "fastrand"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "779d043b6a0b90cc4c0ed7ee380a6504394cee7efd7db050e3774eee387324b2"
dependencies = [
"instant",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
@ -716,14 +725,14 @@ dependencies = [
"log",
"multihash",
"parking_lot 0.11.2",
"pin-project 1.0.8",
"pin-project 1.0.10",
"prost",
"prost-build",
"rand 0.7.3",
"rand",
"ring",
"rw-stream-sink",
"serde",
"sha2 0.9.8",
"sha2 0.9.9",
"smallvec",
"thiserror",
"unsigned-varint 0.7.1",
@ -740,7 +749,7 @@ dependencies = [
"bytes",
"futures",
"log",
"pin-project 1.0.8",
"pin-project 1.0.10",
"smallvec",
"unsigned-varint 0.7.1",
]
@ -789,13 +798,13 @@ dependencies = [
"lazy_static",
"libsecp256k1",
"quickcheck",
"rand 0.7.3",
"rand",
"ring",
"serde",
"serde_bytes",
"serde_json",
"serde_with",
"sha2 0.9.8",
"sha2 0.9.9",
"signature",
"thiserror",
"zeroize",
@ -819,9 +828,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd0210d8c325c245ff06fd95a3b13689a1a276ac8cfa8e8720cb840bfb84b9e"
checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4"
dependencies = [
"futures-channel",
"futures-core",
@ -834,9 +843,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27"
checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b"
dependencies = [
"futures-core",
"futures-sink",
@ -844,15 +853,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445"
checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7"
[[package]]
name = "futures-executor"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97"
checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a"
dependencies = [
"futures-core",
"futures-task",
@ -862,15 +871,15 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11"
checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2"
[[package]]
name = "futures-macro"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd"
checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c"
dependencies = [
"proc-macro2",
"quote",
@ -879,15 +888,15 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af"
checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508"
[[package]]
name = "futures-task"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12"
checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72"
[[package]]
name = "futures-timer"
@ -897,9 +906,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c"
[[package]]
name = "futures-util"
version = "0.3.18"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e"
checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164"
dependencies = [
"futures-channel",
"futures-core",
@ -934,9 +943,9 @@ dependencies = [
[[package]]
name = "generic-array"
version = "0.14.4"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
dependencies = [
"typenum",
"version_check",
@ -1085,9 +1094,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown",
@ -1105,9 +1114,9 @@ dependencies = [
[[package]]
name = "inventory"
version = "0.2.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1367fed6750ff2a5bcb967a631528303bb85631f167a75eb1bf7762d57eb7678"
checksum = "aa2f6fdbc5fd6457ae78e0313ba2eb5cb509655bbcfe8c577096cdbae8ff621c"
dependencies = [
"ctor",
"ghost",
@ -1151,9 +1160,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "0.4.8"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "js-sys"
@ -1191,9 +1200,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.109"
version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01"
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libsecp256k1"
@ -1205,7 +1214,7 @@ dependencies = [
"crunchy",
"digest 0.8.1",
"hmac-drbg",
"rand 0.7.3",
"rand",
"sha2 0.8.2",
"subtle 2.4.1",
"typenum",
@ -1213,9 +1222,9 @@ dependencies = [
[[package]]
name = "libsqlite3-sys"
version = "0.23.1"
version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abd5850c449b40bacb498b2bbdfaff648b1b055630073ba8db499caf2d0ea9f2"
checksum = "d2cafc7c74096c336d9d27145f7ebd4f4b6f95ba16aa5a282387267e6925cb58"
dependencies = [
"pkg-config",
"vcpkg",
@ -1539,9 +1548,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dac63698b887d2d929306ea48b63760431ff8a24fac40ddb22f9c7f49fb7cab"
dependencies = [
"digest 0.9.0",
"generic-array 0.14.4",
"generic-array 0.14.5",
"multihash-derive",
"sha2 0.9.8",
"sha2 0.9.9",
"unsigned-varint 0.5.1",
]
@ -1619,9 +1628,9 @@ dependencies = [
[[package]]
name = "num_cpus"
version = "1.13.0"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
dependencies = [
"hermit-abi",
"libc",
@ -1638,9 +1647,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "opaque-debug"
@ -1752,27 +1761,27 @@ dependencies = [
[[package]]
name = "pin-project"
version = "0.4.28"
version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f"
checksum = "9615c18d31137579e9ff063499264ddc1278e7b1982757ebc111028c4d1dc909"
dependencies = [
"pin-project-internal 0.4.28",
"pin-project-internal 0.4.29",
]
[[package]]
name = "pin-project"
version = "1.0.8"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08"
checksum = "58ad3879ad3baf4e44784bc6a718a8698867bb991f8ce24d1bcbe2cfb4c3a75e"
dependencies = [
"pin-project-internal 1.0.8",
"pin-project-internal 1.0.10",
]
[[package]]
name = "pin-project-internal"
version = "0.4.28"
version = "0.4.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e"
checksum = "044964427019eed9d49d9d5bbce6047ef18f37100ea400912a9fa4a3523ab12a"
dependencies = [
"proc-macro2",
"quote",
@ -1781,9 +1790,9 @@ dependencies = [
[[package]]
name = "pin-project-internal"
version = "1.0.8"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389"
checksum = "744b6f092ba29c3650faf274db506afd39944f48420f6c86b17cfe0ee1cb36bb"
dependencies = [
"proc-macro2",
"quote",
@ -1792,9 +1801,9 @@ dependencies = [
[[package]]
name = "pin-project-lite"
version = "0.2.7"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443"
checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
[[package]]
name = "pin-utils"
@ -1804,9 +1813,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.23"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1a3ea4f0dd7f1f3e512cf97bf100819aa547f36a6eccac8dbaae839eb92363e"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "polyplets"
@ -1821,9 +1830,9 @@ dependencies = [
[[package]]
name = "ppv-lite86"
version = "0.2.15"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba"
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]]
name = "proc-macro-crate"
@ -1861,9 +1870,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.33"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
@ -1938,15 +1947,15 @@ checksum = "a44883e74aa97ad63db83c4bf8ca490f02b2fc02f92575e720c8551e843c945f"
dependencies = [
"env_logger",
"log",
"rand 0.7.3",
"rand_core 0.5.1",
"rand",
"rand_core",
]
[[package]]
name = "quote"
version = "1.0.10"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d"
dependencies = [
"proc-macro2",
]
@ -1959,21 +1968,9 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"getrandom 0.1.16",
"libc",
"rand_chacha 0.2.2",
"rand_core 0.5.1",
"rand_hc 0.2.0",
]
[[package]]
name = "rand"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
dependencies = [
"libc",
"rand_chacha 0.3.1",
"rand_core 0.6.3",
"rand_hc 0.3.1",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
@ -1983,17 +1980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
"ppv-lite86",
"rand_core 0.5.1",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core 0.6.3",
"rand_core",
]
[[package]]
@ -2005,31 +1992,13 @@ dependencies = [
"getrandom 0.1.16",
]
[[package]]
name = "rand_core"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [
"getrandom 0.2.3",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "rand_hc"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
dependencies = [
"rand_core 0.6.3",
"rand_core",
]
[[package]]
@ -2167,9 +2136,9 @@ dependencies = [
[[package]]
name = "rusqlite"
version = "0.26.1"
version = "0.26.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a82b0b91fad72160c56bf8da7a549b25d7c31109f52cc1437eac4c0ad2550a7"
checksum = "4ba4d3462c8b2e4d7f4fcfcf2b296dc6b65404fbbc7b63daa37fd485c149daf7"
dependencies = [
"bitflags",
"fallible-iterator",
@ -2202,15 +2171,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4da5fcb054c46f5a5dff833b129285a93d3f0179531735e6c866e8cc307d2020"
dependencies = [
"futures",
"pin-project 0.4.28",
"pin-project 0.4.29",
"static_assertions",
]
[[package]]
name = "ryu"
version = "1.0.6"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
[[package]]
name = "safe-transmute"
@ -2308,9 +2277,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.72"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142"
dependencies = [
"itoa",
"ryu",
@ -2333,7 +2302,7 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e47be9471c72889ebafb5e14d5ff930d89ae7a67bbdb5f8abb564f845a927e"
dependencies = [
"darling 0.13.0",
"darling 0.13.1",
"proc-macro2",
"quote",
"syn",
@ -2353,9 +2322,9 @@ dependencies = [
[[package]]
name = "sha2"
version = "0.9.8"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer 0.9.0",
"cfg-if 1.0.0",
@ -2366,9 +2335,9 @@ dependencies = [
[[package]]
name = "signature"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788"
checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4"
[[package]]
name = "slab"
@ -2414,9 +2383,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.82"
version = "1.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7"
dependencies = [
"proc-macro2",
"quote",
@ -2443,13 +2412,13 @@ checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d"
[[package]]
name = "tempfile"
version = "3.2.0"
version = "3.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
dependencies = [
"cfg-if 1.0.0",
"fastrand",
"libc",
"rand 0.8.4",
"redox_syscall 0.2.10",
"remove_dir_all",
"winapi",
@ -2521,12 +2490,12 @@ dependencies = [
"fluence-keypair",
"log",
"nonempty",
"rand 0.7.3",
"rand",
"ref-cast",
"serde",
"serde_json",
"serde_with",
"sha2 0.9.8",
"sha2 0.9.9",
"signature",
"thiserror",
]
@ -2557,9 +2526,9 @@ dependencies = [
[[package]]
name = "typenum"
version = "1.14.0"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]]
name = "typetag"
@ -2675,9 +2644,9 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "version_check"
version = "0.9.3"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "void"

View File

@ -2,7 +2,7 @@
Trust Graph is network-wide peer relationship layer. It's designed to be used to prioritize resources and control permissions in open networks. Being a decentralized graph of relationships, basically a Web of Trust, Trust Graph is distributed among all network peers.
Specifically, Trust Graph is used is used to prioritize connections from known peers to counteract Sybil attacks while still keeping network open by reserving resources for unknown peers.
Specifically, Trust Graph is used to prioritize connections from known peers to counteract Sybil attacks while still keeping network open by reserving resources for unknown peers.
At the same time, Trust Graph can be used at the application level in various ways such as prioritization of service execution on authorized peers or to define an interconnected subnetwork among peers of a single protocol.
@ -14,7 +14,7 @@ See [example](./example):
## API
Low-level API is defined in the [trust-graph-api.aqua](./aqua/trust-graph-api.aqua) module.
High-level API is defined in the [trust-graph-api.aqua](./aqua/trust-graph-api.aqua) module.
## Directory structure
@ -22,9 +22,9 @@ Low-level API is defined in the [trust-graph-api.aqua](./aqua/trust-graph-api.aq
- [`keypair`](./keypair) directory is an abstracted cryptographical layer (key pairs, public keys, signatures, etc.)
- [`service`](./service) is a package that provides `marine` API and could be compiled to a Wasm file. It is uses `SQLite` as storage.
- [`service`](./service) is a package that provides `marine` API and could be compiled to a Wasm file. It is uses `SQLite` as storage
- [`example`](./example) is a `js` script that shows how to issue, sign trusts/revocations, export certificates and distinguish Fluence nodes
- [`example`](./example) is a `js` script that shows how to use Trust Graph to label peers
- [`builtin-package`](./builtin-package) contains blueprint, configs and scripts for generation builtin package locally or via CI
@ -35,3 +35,32 @@ Low-level API is defined in the [trust-graph-api.aqua](./aqua/trust-graph-api.aq
* [Aqua Book](https://fluence.dev/aqua-book/)
* [Aqua Playground](https://github.com/fluencelabs/aqua-playground)
* [Aqua repo](https://github.com/fluencelabs/aqua)
## How to use in Aqua
```
import "@fluencelabs/trust-graph/trust-graph-api.aqua"
import "@fluencelabs/trust-graph/trust-graph.aqua"
func my_function(peer_id: string) -> u32:
on HOST_PEER_ID:
result <- get_weight(peer_id)
<- result
```
## How to use is js
1. Add the following to your dependencies
- `@fluencelabs/trust-graph`
- `@fluencelabs/aqua`
- `@fluencelabs/aqua-lib`
- `@fluencelabs/fluence`
- `@fluencelabs/fluence-network-environment`
2. Import dependencies
```typescript
import * as tg from "./generated/export";
import { Fluence, KeyPair } from "@fluencelabs/fluence";
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
```
3. Add root and issue root trust.
4. For now, trusts/revocations can only be signed by client's private key.

View File

@ -10,3 +10,5 @@
all Fluence Labs relations. Trust from issuer key to any peer id means that this peer is official Fluence Labs peer.
isFluencePeer method from [trust-graph-api.aqua](./aqua/trust-graph-api.aqua) module checks these relations. You can build your own
structure of peers similarly.
`example_secret_key.ed25519` publicly available and used for test purposes.

View File

@ -1,4 +1,4 @@
import get_trust_bytes, issue_trust from "../../aqua/trust-graph-api.aqua"
import "@fluencelabs/trust-graph/trust-graph.aqua"
export get_trust_bytes, issue_trust
import "@fluencelabs/aqua-lib/builtin.aqua"
@ -7,3 +7,13 @@ func timestamp_sec(node: string) -> u64:
on node:
result <- Peer.timestamp_sec()
<- result
func get_trust_bytes(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64) -> GetTrustBytesResult:
on node:
result <- TrustGraph.get_trust_bytes(issued_for_peer_id, expires_at_sec, issued_at_sec)
<- result
func issue_trust(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64, trust_bytes: []u8) ->IssueTrustResult:
on node:
result <- TrustGraph.issue_trust(issued_for_peer_id, expires_at_sec, issued_at_sec, trust_bytes)
<- result

View File

@ -52,21 +52,27 @@ async function main(environment: Node[]) {
let root_sk_b58 = fs.readFileSync("./root_secret_key.ed25519").toString();
let issuer_sk_b58 = fs.readFileSync("./issuer_secret_key.ed25519").toString();
let example_sk_b58 = fs.readFileSync("../example_secret_key.ed25519").toString();
let root_kp = await KeyPair.fromEd25519SK(bs58.decode(root_sk_b58));
let issuer_kp = await KeyPair.fromEd25519SK(bs58.decode(issuer_sk_b58));
let example_kp = await KeyPair.fromEd25519SK(bs58.decode(example_sk_b58));
console.log("Root private key: %s", root_sk_b58);
console.log("Root peer id: %s", root_kp.Libp2pPeerId.toB58String());
console.log("Issuer private key: %s", issuer_sk_b58);
let cur_time = await timestamp_sec(node);
let expires_at = cur_time + 60 * 60 * 24 * 365;
let certificates = [];
let common_chain = [] as any;
// self-signed root trust
common_chain.push(await issue_trust_helper(node, root_kp, root_kp.Libp2pPeerId.toB58String(), root_kp.Libp2pPeerId.toB58String(), expires_at, cur_time));
// from root to issuer
common_chain.push(await issue_trust_helper(node, root_kp, root_kp.Libp2pPeerId.toB58String(), issuer_kp.Libp2pPeerId.toB58String(), expires_at, cur_time));
// from root to example
let trust = await issue_trust_helper(node, root_kp, root_kp.Libp2pPeerId.toB58String(), example_kp.Libp2pPeerId.toB58String(), expires_at, cur_time);
let cert = {chain: [...common_chain, trust]};
certificates.push(cert);
let certificates = [];
for (let i = 0; i < krasnodar.length; i++) {
// from issuer to node
let trust = await issue_trust_helper(node, issuer_kp, issuer_kp.Libp2pPeerId.toB58String(), krasnodar[i].peerId, expires_at, cur_time);

5120
admin/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,9 +13,9 @@
"author": "Fluence Labs",
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua": "0.5.0-246",
"@fluencelabs/aqua-lib": "0.2.1",
"@fluencelabs/fluence": "0.15.0",
"@fluencelabs/aqua": "^0.5.2-257",
"@fluencelabs/aqua-lib": "^0.3.2",
"@fluencelabs/fluence": "^0.18.0",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"@fluencelabs/trust-graph": "file:../aqua",
"bs58": "^4.0.1"

8
aqua/misc.aqua Normal file
View File

@ -0,0 +1,8 @@
import "trust-graph.aqua"
-- helpers for isFluencePeer
service TrustOp("op"):
array_length(a: []Trust) -> u32
service BoolOp("op"):
array_length(a: []bool) -> u32

3070
aqua/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{
"name": "@fluencelabs/trust-graph",
"version": "0.2.0",
"version": "0.2.1",
"description": "Aqua Trust Graph API library",
"files": [
"*.aqua"
],
"dependencies": {
"@fluencelabs/aqua-lib": "0.2.0"
"@fluencelabs/aqua-lib": "^0.3.1"
},
"scripts": {
"generate-aqua": "../service/build.sh",
@ -31,6 +31,6 @@
},
"homepage": "https://github.com/fluencelabs/trust-graph#readme",
"devDependencies": {
"@fluencelabs/aqua": "0.4.1-240"
"@fluencelabs/aqua": "^0.5.2-257"
}
}

View File

@ -1,100 +1,183 @@
import "trust-graph.aqua"
import "misc.aqua"
import "@fluencelabs/aqua-lib/builtin.aqua"
func get_trust_bytes(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64) -> GetTrustBytesResult:
on node:
result <- TrustGraph.get_trust_bytes(issued_for_peer_id, expires_at_sec, issued_at_sec)
-- Set peer_id as a root to TG instance on current node
-- Self-signed trust should be added in next call for correct behaviour
-- `max_chain_len` specifies maximum chain length after root trust,
-- if `max_chain_len` is zero there is no trusts except self-signed root trust in certificates for this root
func add_root(peer_id: string, max_chain_len: u32) -> AddRootResult:
weight_factor <- TrustGraph.get_weight_factor(max_chain_len)
result <- TrustGraph.add_root(peer_id, weight_factor)
<- result
func issue_trust(node: string, issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64, trust_bytes: []u8) -> IssueTrustResult:
on node:
result <- TrustGraph.issue_trust(issued_for_peer_id, expires_at_sec, issued_at_sec, trust_bytes)
<- result
-- Create and sign trust with %init_peer_id%'s private key
func issue_trust(issued_for_peer_id: string, expires_at_sec: u64) -> ?Trust, ?string:
issued_at_sec <- Peer.timestamp_sec()
bytes <- TrustGraph.get_trust_bytes(issued_for_peer_id, expires_at_sec, issued_at_sec)
func verify_trust(node: string, trust: Trust, issuer_peer_id: string) -> VerifyTrustResult:
on node:
result: ?Trust
error: ?string
if bytes.success:
on %init_peer_id% via HOST_PEER_ID:
signature <- Sig.sign(bytes.result)
issue_result <- TrustGraph.issue_trust(issued_for_peer_id, expires_at_sec, issued_at_sec, signature)
if issue_result.success:
result <<- issue_result.trust
else:
error <<- issue_result.error
else:
error <<- bytes.error
<- result, error
-- Issue trust and add to TG instance on current node
func add_trust(issued_for_peer_id: string, expires_at_sec: u64) -> ?string:
trust, issue_error <- issue_trust(issued_for_peer_id, expires_at_sec)
error: ?string
if trust == nil:
error <<- issue_error!
else:
timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.add_trust(trust!, %init_peer_id%, timestamp_sec)
if add_result.success != true:
error <<- add_result.error
<- error
-- Add trust to TG instance on current node
func import_trust(trust: Trust) -> ?string:
error: ?string
timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.add_trust(trust, %init_peer_id%, timestamp_sec)
if add_result.success != true:
error <<- add_result.error
<- error
-- Set %init_peer_id% as a root and add self-signed trust to TG instance on current node
func add_root_trust(max_chain_len: u32, expires_at_sec: u64) -> ?string:
add_root_result <- add_root(%init_peer_id%, max_chain_len)
error: *?string
if add_root_result.success:
error <- add_trust(%init_peer_id%, expires_at_sec)
else:
-- converting string to ?string
tmp: *string
tmp <<- add_root_result.error
error <<- tmp
<- error!
-- Check signature and expiration time of trust
func verify_trust(trust: Trust, issuer_peer_id: string) -> VerifyTrustResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.verify_trust(trust, issuer_peer_id, timestamp_sec)
<- result
func add_trust(node: string, trust: Trust, issuer_peer_id: string) -> AddTrustResult:
on node:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.add_trust(trust, issuer_peer_id, timestamp_sec)
<- result
func add_root(node: string, peer_id: string, weight_factor: u32) -> AddRootResult:
on node:
result <- TrustGraph.add_root(peer_id, weight_factor)
<- result
func get_weight(node: string, peer_id: string) -> WeightResult:
on node:
-- Get the maximum weight of trust for one peer id
-- Trust has weight if there is at least 1 trust chain from one of the roots
func get_weight(peer_id: string) -> WeightResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_weight(peer_id, timestamp_sec)
<- result
func get_all_certs(node: string, issued_for: string) -> AllCertsResult:
on node:
-- Get maximum weight of trust among all chains which contain trust from `issuer`
func get_weight_from(peer_id: string, issuer: string) -> WeightResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_all_certs(issued_for, timestamp_sec)
result <- TrustGraph.get_weight_from(peer_id, issuer, timestamp_sec)
<- result
func get_host_certs(node: string, issued_for: string) -> AllCertsResult:
on node:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_host_certs(timestamp_sec)
<- result
-- Create revocation signed by %init_peer_id%
func issue_revocation(revoked_peer_id: string) -> ?Revocation, ?string:
issued_at_sec <- Peer.timestamp_sec()
bytes <- TrustGraph.get_revocation_bytes(revoked_peer_id, issued_at_sec)
result: ?Revocation
error: ?string
if bytes.success:
on %init_peer_id% via HOST_PEER_ID:
signature <- Sig.sign(bytes.result)
issue_result <- TrustGraph.issue_revocation(revoked_peer_id, %init_peer_id%, issued_at_sec, signature)
if issue_result.success:
result <<- issue_result.revocation
else:
error <<- issue_result.error
else:
error <<- bytes.error
<- result, error
-- Revoke all certificates on current node's TG instance
-- which contain path from %init_peer_id% to `revoked_peer_id`
func revoke(revoked_peer_id: string) -> ?string:
revocation, issue_error <- issue_revocation(revoked_peer_id)
error: ?string
if revocation == nil:
error <<- issue_error!
else:
timestamp_sec <- Peer.timestamp_sec()
revoke_result <- TrustGraph.revoke(revocation!, timestamp_sec)
if revoke_result.success != true:
error <<- revoke_result.error
<- error
-- Import revocation to current node's TG instance
func import_revocation(revocation: Revocation) -> ?string:
error: ?string
timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.revoke(revocation, timestamp_sec)
if add_result.success != true:
error <<- add_result.error
<- error
-- Return all certificates issued for current node which contains trust from `issuer`
func get_host_certs_from(issuer: string) -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_host_certs_from(issuer, timestamp_sec)
<- result
func insert_cert(node: string, certificate: Certificate) -> InsertResult:
on node:
-- Return all certificates issued for given peer id
func get_all_certs(issued_for: string) -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_all_certs(issued_for, timestamp_sec)
<- result
-- Return all certificates issued for given peer id which contains trust from `issuer`
func get_all_certs_from(issued_for: string, issuer: string) -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_all_certs_from(issued_for, issuer, timestamp_sec)
<- result
-- Return all certificates issued for current node
func get_host_certs() -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_host_certs(timestamp_sec)
<- result
-- Insert certificate to TG instance on current node
func insert_cert(certificate: Certificate) -> InsertResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.insert_cert(certificate, timestamp_sec)
<- result
func get_revoke_bytes(node: string, revoked_peer_id: string, revoked_at: u64) -> GetRevokeBytesResult:
on node:
result <- TrustGraph.get_revoke_bytes(revoked_peer_id, revoked_at)
<- result
func issue_revocation(node: string, revoked_peer_id: string, revoked_by_peer_id: string, revoked_at_sec: u64, signature_bytes: []u8) -> IssueRevocationResult:
on node:
result <- TrustGraph.issue_revocation(revoked_peer_id, revoked_by_peer_id, revoked_at_sec, signature_bytes)
<- result
func revoke(node: string, revocation: Revocation) -> RevokeResult:
on node:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.revoke(revocation, timestamp_sec)
<- result
service TrustOp("op"):
array_length(a: []Trust) -> u32
service BoolOp("op"):
array_length(a: []bool) -> u32
func isFluencePeer(node: string) -> bool:
on node:
-- returns `true` if current node is identified as official Fluence Labs peer
-- returns `false` otherwise
func isFluencePeer() -> ?bool, ?string:
certs_result <- get_host_certs_from("12D3KooWM45u7AQxsb4MuQJNYT3NWHHMLU7JTbBV66RTfF3KSzdR")
resultBox: *bool
result: ?bool
error: ?string
if certs_result.success:
for cert <- certs_result.certificates:
len <- TrustOp.array_length(cert.chain)
if len == 3:
if cert.chain!0.issued_for == "12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB":
if cert.chain!1.issued_for == "12D3KooWM45u7AQxsb4MuQJNYT3NWHHMLU7JTbBV66RTfF3KSzdR":
resultBox <<- true
result_len <- BoolOp.array_length(resultBox)
result: *bool
if result_len == 0:
result <<- true
if result == nil:
result <<- false
else:
result <<- true
<- result!
error <<- certs_result.error
<- result, error

View File

@ -73,12 +73,14 @@ service TrustGraph("trust-graph"):
add_root(peer_id: string, weight_factor: u32) -> AddRootResult
add_trust(trust: Trust, issuer_peer_id: string, timestamp_sec: u64) -> AddTrustResult
get_all_certs(issued_for: string, timestamp_sec: u64) -> AllCertsResult
get_all_certs_from(issued_for: string, issuer: string, timestamp_sec: u64) -> AllCertsResult
get_host_certs(timestamp_sec: u64) -> AllCertsResult
get_host_certs_from(issuer: string, timestamp_sec: u64) -> AllCertsResult
get_revoke_bytes(revoked_peer_id: string, revoked_at: u64) -> GetRevokeBytesResult
get_revocation_bytes(revoked_peer_id: string, revoked_at: u64) -> GetRevokeBytesResult
get_trust_bytes(issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64) -> GetTrustBytesResult
get_weight(peer_id: string, timestamp_sec: u64) -> WeightResult
get_weight_factor(max_chain_len: u32) -> u32
get_weight_from(peer_id: string, issuer: string, timestamp_sec: u64) -> WeightResult
insert_cert(certificate: Certificate, timestamp_sec: u64) -> InsertResult
insert_cert_raw(certificate: string, timestamp_sec: u64) -> InsertResult
issue_revocation(revoked_peer_id: string, revoked_by_peer_id: string, revoked_at_sec: u64, signature_bytes: []u8) -> IssueRevocationResult

View File

@ -1,6 +1,9 @@
(seq
(seq
(call relay ("trust-graph" "add_root") ["12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB" 2] add_root_res)
(seq
(call relay ("trust-graph" "get_weight_factor") [5] weight_factor)
(call relay ("trust-graph" "add_root") ["12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB" weight_factor] add_root_res)
)
(xor
(match add_root_res.$.success! true
(null)

File diff suppressed because one or more lines are too long

View File

@ -1,23 +1,10 @@
# Run example locally
## Description
This example shows how to use Trust Graph to label peers. There are some `trusted_computation` which can only be executed
on labeled peer. The label is determined by the presence of certificate from `%init_peer_id` to this peer.
## Run example locally
1. Go to `local-network`
2. Run `docker compose up -d` to start Fluence node
3. Go back to `../example`
4. Run `npm i`
5. Run `npm run start`
## How to use
1. Add the following to your dependencies
- `@fluencelabs/trust-graph`
- `@fluencelabs/aqua`
- `@fluencelabs/aqua-lib`
- `@fluencelabs/fluence`
- `@fluencelabs/fluence-network-environment`
2. Import dependencies
```typescript
import * as tg from "./generated/export";
import { Fluence, KeyPair } from "@fluencelabs/fluence";
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
```
3. Add root and issue self-signed root trust.
4. For now, you can sign trusts/revocations only on js side with KeyPair.

View File

@ -0,0 +1,27 @@
import "@fluencelabs/trust-graph/trust-graph-api.aqua"
import "@fluencelabs/trust-graph/trust-graph.aqua"
import "@fluencelabs/aqua-lib/builtin.aqua"
export trusted_computation
service CertOp("op"):
array_length(a: []Certificate) -> u32
service TrustedComputation("op"):
identity(s: u64) -> u64
func trusted_computation(node: string) -> ?u64:
result: ?u64
-- on our trusted relay
on HOST_PEER_ID:
-- get all certificates issued for given node by our client's peer id
certs_result <- get_all_certs_from(node, %init_peer_id%)
if certs_result.success:
len <- CertOp.array_length(certs_result.certificates)
-- if there is any certificate node is trusted and computation is possible
if len != 0:
on node:
result <- TrustedComputation.identity(5)
<- result

View File

@ -1,10 +1,24 @@
import get_trust_bytes, issue_trust, verify_trust, add_trust, add_root, get_weight, get_all_certs, insert_cert, get_revoke_bytes, issue_revocation, revoke, isFluencePeer from "../../aqua/trust-graph-api.aqua"
use add_root_trust, add_trust, revoke from "@fluencelabs/trust-graph/trust-graph-api.aqua" as TrustGraph
export add_root_trust, add_trust, revoke
import Peer from "@fluencelabs/aqua-lib/builtin.aqua"
export get_trust_bytes, issue_trust, verify_trust, add_trust, add_root, get_weight, get_all_certs, insert_cert, get_revoke_bytes, issue_revocation, revoke, isFluencePeer
import "@fluencelabs/aqua-lib/builtin.aqua"
func timestamp_sec(node: string) -> u64:
-- here we define wrappers with `on` for export functions used in script
func add_root_trust(node: string, max_chain_len: u32, expires_at_sec: u64) -> ?string:
on node:
error <- TrustGraph.add_root_trust(max_chain_len, expires_at_sec)
<- error
func add_trust(node: string, issued_for_peer_id: string, expires_at_sec: u64) -> ?string:
on node:
error <- TrustGraph.add_trust(issued_for_peer_id, expires_at_sec)
<- error
func revoke(node: string, revoked_peer_id: string) -> ?string:
on node:
error <- TrustGraph.revoke(revoked_peer_id)
<- error
func timestamp_sec() -> u64:
on HOST_PEER_ID:
result <- Peer.timestamp_sec()
<- result

View File

@ -14,10 +14,12 @@
* limitations under the License.
*/
import {trusted_computation} from "./generated/computation";
import * as tg from "./generated/export";
import { Fluence, KeyPair } from "@fluencelabs/fluence";
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
import {Fluence, FluencePeer, KeyPair} from "@fluencelabs/fluence";
import {krasnodar, Node, testNet, stage} from "@fluencelabs/fluence-network-environment";
import assert from "assert";
import {add_root_trust} from "./generated/export";
const bs58 = require('bs58');
let local: Node[] = [
@ -31,105 +33,103 @@ let local: Node[] = [
multiaddr:
"/ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv",
},
{
peerId: "12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5",
multiaddr:
"/ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5",
},
];
async function is_fluence_peer(relay: string) {
let result = await tg.isFluencePeer(relay);
if (result) {
console.log("Current relay %s identified as Fluence Labs' peer", relay)
} else {
console.log("Current relay %s is not Fluence Labs' peer", relay)
async function revoke_all(relay: string) {
for (var node of local) {
let error = await tg.revoke(relay, node.peerId);
assert(error == null);
}
}
async function add_root(relay: string) {
let current_time = await tg.timestamp_sec();
let far_future = current_time + 9999999;
let error = await tg.add_root_trust(relay, 2, far_future);
assert(error == null);
}
async function add_trust_helper(relay: string, issuer_kp: KeyPair, issuer_peer_id: string, issued_for_peer_id: string, expires_at_sec: number, issued_at_sec: number) {
let trust_metadata = await tg.get_trust_bytes(relay, issued_for_peer_id, expires_at_sec, issued_at_sec);
const signed_metadata = await issuer_kp.Libp2pPeerId.privKey.sign(Uint8Array.from(trust_metadata.result));
let trust = await tg.issue_trust(relay, issued_for_peer_id, expires_at_sec, issued_at_sec, Array.from(signed_metadata));
assert(trust.success)
let result = await tg.verify_trust(relay, trust.trust, issuer_peer_id);
assert(result.success)
let result_add = await tg.add_trust(relay, trust.trust, issuer_peer_id);
assert(result_add.success)
async function add_new_trust_checked(relay: string, issued_for_peer_id: string, expires_at_sec: number) {
let error = await tg.add_trust(relay, issued_for_peer_id, expires_at_sec);
if (error !== null) {
console.error("%s", error);
} else {
console.log("Trust issued for %s successfully added", issued_for_peer_id)
}
}
async function revoke_helper(node: string, issuer_kp: KeyPair, revoked_by_peer_id: string, revoked_peer_id: string, revoked_at_sec: number) {
let trust_metadata = await tg.get_revoke_bytes(node, revoked_peer_id, revoked_at_sec);
const signed_metadata = await issuer_kp.Libp2pPeerId.privKey.sign(Uint8Array.from(trust_metadata.result));
async function revoke_checked(relay: string, revoked_peer_id: string) {
let error = await tg.revoke(relay, revoked_peer_id);
if (error !== null) {
console.log("%s", error);
} else {
console.log("Trust issued for %s revoked", revoked_peer_id)
}
}
let revocation = await tg.issue_revocation(node, revoked_peer_id, revoked_by_peer_id, revoked_at_sec, Array.from(signed_metadata));
assert(revocation.success)
async function exec_trusted_computation(node: string) {
let result = await trusted_computation(node)
let result_add = await tg.revoke(node, revocation.revocation);
assert(result_add.success)
if (result !== null) {
console.log("📗 Trusted computation on node %s successful, result is %s", node, result)
} else {
console.log("📕 Trusted computation on node %s failed", node)
}
}
async function main() {
console.log("In this example we try to execute some trusted computations based on trusts");
console.log("📘 Will connect to local nodes");
// key from local-network/builtins_secret_key.ed25519 to connect as builtins owner
let sk = bs58.decode("5FwE32bDcphFzuMca7Y2qW1gdR64fTBYoRNvD4MLE1hecDGhCMQGKn8aseMr5wRo4Xo2CRFdrEAawUNLYkgQD78K").slice(0, 32); // first 32 bytes - secret key, second - public key
let builtins_keypair = await KeyPair.fromEd25519SK(sk);
await Fluence.start({ connectTo: local[0], KeyPair: builtins_keypair});
let relay = local[0];
await Fluence.start({ connectTo: relay, KeyPair: builtins_keypair});
console.log(
"📗 created a fluence peer %s with relay %s",
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId
);
let relay = local[0].peerId
let nodeA = local[0].peerId
let nodeB = local[1].peerId
// keypair if nodeA specified in local-network/docker-compose.yml
const issuer_kp = await KeyPair.fromEd25519SK(bs58.decode("29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww"));
let current_time = await tg.timestamp_sec();
let far_future = current_time + 9999999;
// set nodeA as a root
let add_root_result = await tg.add_root(relay, nodeA, 2);
assert(add_root_result.success)
// add self-signed root trust
const issued_timestamp_sec = await tg.timestamp_sec(relay);
const expires_at_sec = issued_timestamp_sec + 999999999;
await add_trust_helper(relay, issuer_kp, nodeA, nodeB, expires_at_sec, issued_timestamp_sec);
let root_weight_result = await tg.get_weight(relay, nodeA);
assert(root_weight_result.success)
console.log("Root weight (nodeA) is: %s", root_weight_result.weight);
// issue trust by nodeA to nodeB and add to tg
await add_trust_helper(relay, issuer_kp, nodeA, nodeB, expires_at_sec, issued_timestamp_sec);
let weight_result = await tg.get_weight(relay, nodeB);
console.log("Weight of nodeB: is %s", weight_result.weight);
assert(root_weight_result.weight / 2 === weight_result.weight);
let certs = await tg.get_all_certs(relay, nodeB);
assert(certs.certificates.length === 1);
console.log("There is one cert for nodeB with chain len %s", certs.certificates[0].chain.length);
console.log("It contains self-signed nodeA root trust and nodeA->nodeB trust");
// wait to create revoke after trust (because timestamp in secs)
// clear all trusts from our peer id on relay
await revoke_all(relay.peerId);
// wait to be sure that last revocation will be older than future trusts at least on 1 second (because timestamp in secs)
await new Promise(f => setTimeout(f, 1000));
console.log("Now we will revoke trust for nodeB")
// revoke nodeB by nodeA
await revoke_helper(relay, issuer_kp, nodeA, nodeB, await tg.timestamp_sec(relay));
// set our peer id as root to our relay
await add_root(relay.peerId);
let empty_certs = await tg.get_all_certs(relay, nodeB);
assert(empty_certs.certificates.length === 0);
console.log("Now there is no certs for nodeB");
let nodeA = local[0].peerId
let nodeB = local[1].peerId
let nodeC = local[2].peerId
console.log("Let's check if our node is Fluence Labs peer");
await is_fluence_peer(relay);
// try to exec computation on every node, will fail
await exec_trusted_computation(nodeA); // fail
await exec_trusted_computation(nodeB); // fail
await exec_trusted_computation(nodeC); // fail
console.log("Now let's check some krasnodar's node");
await is_fluence_peer(krasnodar[0].peerId);
console.log("🌀 Issue trust to nodeB: %s", nodeB);
await add_new_trust_checked(relay.peerId, nodeB, far_future);
await exec_trusted_computation(nodeA); // fail
await exec_trusted_computation(nodeB); // success
await exec_trusted_computation(nodeC); // fail
await new Promise(f => setTimeout(f, 1000));
console.log("🚫 Revoke trust to nodeB");
await revoke_checked(relay.peerId, nodeB);
await exec_trusted_computation(nodeA); // fail
await exec_trusted_computation(nodeB); // fail
await exec_trusted_computation(nodeC); // fail
return;
}

5179
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,9 +13,9 @@
"author": "Fluence Labs",
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua": "0.5.0-247",
"@fluencelabs/aqua-lib": "0.2.1",
"@fluencelabs/fluence": "0.15.1",
"@fluencelabs/aqua": "^0.5.2-257",
"@fluencelabs/aqua-lib": "^0.3.2",
"@fluencelabs/fluence": "^0.18.0",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"@fluencelabs/trust-graph": "file:../aqua",
"bs58": "^4.0.1"

View File

@ -1,17 +1,17 @@
# management secret key is NAB5rGwT4qOEB+6nLQawkTfCOV2eiFSjgQK8bfEdZXY=
services:
fluence-0: # /ip4/127.0.0.1/tcp/9990/ws/p2p/12D3KooWHBG9oaVx4i3vi6c1rSBUm7MLBmyGmmbHoZ23pmjDCnvK
command: -f ed25519 -k 29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7770 -w 9990 # --bootstraps /dns4/fluence-1/tcp/7771 /dns4/fluence-2/tcp/7772
command: -f ed25519 -k 29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7770 -w 9990 --bootstraps /dns4/fluence-1/tcp/7771 /dns4/fluence-2/tcp/7772
container_name: fluence-0
environment:
RUST_BACKTRACE: full
RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
WASM_LOG: info
image: fluencelabs/node:latest
image: fluencelabs/node:tg-hl-api_v345
ports:
- 7770:7770 # tcp
- 9990:9990 # ws
- 5002:5001 # ipfs rpc
- 5003:5001 # ipfs rpc
- 4000:4001 # ipfs swarm
- 18080:18080 # /metrics
restart: always
@ -22,56 +22,58 @@ services:
networks:
- fluence
# fluence-1: # /ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv
# command: -f ed25519 -k 5fNENMwkUT4dW3hPs9ZwqV4qA5pdTtUChTazAx9Awe2Vpz1yaJu3VCmcEZow6YgdFBGoZoFAZUZBbF3c2Ebd2iL -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7771 -w 9991 --bootstraps /dns4/fluence-0/tcp/7770 /dns4/fluence-2/tcp/7772 #/dns4/kras-00.fluence.dev/tcp/7770
# container_name: fluence-1
# environment:
# RUST_BACKTRACE: full
# RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
# WASM_LOG: info
# image: fluencelabs/node:latest
# ports:
# - 7771:7771 # tcp
# - 9991:9991 # ws
# - 5001:5001 # ipfs rpc
# - 4001:4001 # ipfs swarm
# - 18081:18080 # /metrics
# restart: always
# volumes:
# - fluence-1:/.fluence
# - data-1:/config
# networks:
# - fluence
#
# fluence-2: # /ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5
# command: -f ed25519 -k 5DTs9LQS8Ay2dM8xBcikDRwYLMcanhsC6tynSSgpLyBZEv5Ey34LVw1fYcCuUj9A9EfvQJB2bsaGhSRoHQ7D6UE5 -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7772 -w 9992 --bootstraps /dns4/fluence-0/tcp/7770 /dns4/fluence-1/tcp/7771 #/dns4/kras-00.fluence.dev/tcp/7770
# container_name: fluence-2
# environment:
# RUST_BACKTRACE: full
# RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
# WASM_LOG: info
# image: fluencelabs/node:latest
# ports:
# - 7772:7772 # tcp
# - 9992:9992 # ws
# - 5002:5001 # ipfs rpc
# - 4002:4001 # ipfs swarm
# - 18082:18080 # /metrics
# restart: always
# volumes:
# - fluence-2:/.fluence
# - data-2:/config
# networks:
# - fluence
fluence-1: # /ip4/127.0.0.1/tcp/9991/ws/p2p/12D3KooWRABanQHUn28dxavN9ZS1zZghqoZVAYtFpoN7FdtoGTFv
command: -f ed25519 -k 5fNENMwkUT4dW3hPs9ZwqV4qA5pdTtUChTazAx9Awe2Vpz1yaJu3VCmcEZow6YgdFBGoZoFAZUZBbF3c2Ebd2iL -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7771 -w 9991 --bootstraps /dns4/fluence-0/tcp/7770 /dns4/fluence-2/tcp/7772 #/dns4/kras-00.fluence.dev/tcp/7770
container_name: fluence-1
environment:
RUST_BACKTRACE: full
RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
WASM_LOG: info
image: fluencelabs/node:tg-hl-api_v345
ports:
- 7771:7771 # tcp
- 9991:9991 # ws
- 5001:5001 # ipfs rpc
- 4001:4001 # ipfs swarm
- 18081:18080 # /metrics
restart: always
volumes:
- fluence-1:/.fluence
- data-1:/config
- ./builtins_secret_key.ed25519:/.fluence/v1/builtins_secret_key.ed25519
networks:
- fluence
fluence-2: # /ip4/127.0.0.1/tcp/9992/ws/p2p/12D3KooWFpQ7LHxcC9FEBUh3k4nSCC12jBhijJv3gJbi7wsNYzJ5
command: -f ed25519 -k 5DTs9LQS8Ay2dM8xBcikDRwYLMcanhsC6tynSSgpLyBZEv5Ey34LVw1fYcCuUj9A9EfvQJB2bsaGhSRoHQ7D6UE5 -m 12D3KooWFRgVmb1uWcmCbmJqLr8tBQghL6ysSpK2VyE2VZbaQ6wy -t 7772 -w 9992 --bootstraps /dns4/fluence-0/tcp/7770 /dns4/fluence-1/tcp/7771 #/dns4/kras-00.fluence.dev/tcp/7770
container_name: fluence-2
environment:
RUST_BACKTRACE: full
RUST_LOG: info,network=trace,aquamarine=info,aquamarine::actor=info,tokio_threadpool=info,tokio_reactor=info,mio=info,tokio_io=info,soketto=info,yamux=info,multistream_select=info,libp2p_secio=info,libp2p_websocket::framed=info,libp2p_ping=info,libp2p_core::upgrade::apply=info,libp2p_kad::kbucket=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,cranelift_codegen=info,wasmer_wasi=info,async_io=info,polling=info,wasmer_interface_types_fl=info,particle_server::behaviour::identify=info,libp2p_mplex=info,libp2p_identify=info,walrus=info,particle_protocol::libp2p_protocol::upgrade=info,kademlia::behaviour=info
WASM_LOG: info
image: fluencelabs/node:tg-hl-api_v345
ports:
- 7772:7772 # tcp
- 9992:9992 # ws
- 5002:5001 # ipfs rpc
- 4002:4001 # ipfs swarm
- 18082:18080 # /metrics
restart: always
volumes:
- fluence-2:/.fluence
- data-2:/config
- ./builtins_secret_key.ed25519:/.fluence/v1/builtins_secret_key.ed25519
networks:
- fluence
version: "3.5"
volumes:
fluence-0:
# fluence-1:
# fluence-2:
fluence-1:
fluence-2:
data-0:
# data-1:
# data-2:
data-1:
data-2:
networks:
fluence:

View File

@ -71,17 +71,40 @@ fn get_certs(
tg: &mut TrustGraph<SQLiteStorage>,
issued_for: String,
timestamp_sec: u64,
) -> Result<impl Iterator<Item = Certificate>, ServiceError> {
) -> Result<Vec<Certificate>, ServiceError> {
let public_key = extract_public_key(issued_for)?;
let certs = tg.get_all_certs(public_key, Duration::from_secs(timestamp_sec))?;
Ok(certs.into_iter().map(|c| c.into()))
Ok(certs.into_iter().map(|c| c.into()).collect())
}
fn get_certs_from(
tg: &mut TrustGraph<SQLiteStorage>,
issued_for: String,
issuer: String,
timestamp_sec: u64,
) -> Result<Vec<Certificate>, ServiceError> {
let issued_for_pk = extract_public_key(issued_for)?;
let issuer_pk = extract_public_key(issuer)?;
let certs =
tg.get_all_certs_from(issued_for_pk, issuer_pk, Duration::from_secs(timestamp_sec))?;
Ok(certs.into_iter().map(|c| c.into()).collect())
}
#[marine]
fn get_all_certs(issued_for: String, timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| {
check_timestamp_tetraplets(&marine_rs_sdk::get_call_parameters(), 1)?;
get_certs(tg, issued_for, timestamp_sec).map(|iter| iter.collect())
get_certs(tg, issued_for, timestamp_sec)
})
.into()
}
#[marine]
fn get_all_certs_from(issued_for: String, issuer: String, timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| {
let cp = get_call_parameters();
check_timestamp_tetraplets(&cp, 1)?;
get_certs_from(tg, issued_for, issuer, timestamp_sec)
})
.into()
}
@ -91,7 +114,7 @@ fn get_host_certs(timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| {
let cp = marine_rs_sdk::get_call_parameters();
check_timestamp_tetraplets(&cp, 0)?;
get_certs(tg, cp.host_id, timestamp_sec).map(|iter| iter.collect())
get_certs(tg, cp.host_id, timestamp_sec)
})
.into()
}
@ -101,10 +124,7 @@ fn get_host_certs_from(issuer: String, timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| {
let cp = get_call_parameters();
check_timestamp_tetraplets(&cp, 1)?;
get_certs(tg, cp.host_id, timestamp_sec).map(|c| {
c.filter(|cert: &Certificate| cert.chain.iter().any(|t| t.issued_for == issuer))
.collect()
})
get_certs_from(tg, cp.host_id, issuer, timestamp_sec)
})
.into()
}
@ -121,6 +141,20 @@ fn get_weight(peer_id: String, timestamp_sec: u64) -> WeightResult {
.into()
}
#[marine]
fn get_weight_from(peer_id: String, issuer: String, timestamp_sec: u64) -> WeightResult {
with_tg(|tg| {
check_timestamp_tetraplets(&marine_rs_sdk::get_call_parameters(), 1)?;
let issued_for_pk = extract_public_key(peer_id.clone())?;
let issuer_pk = extract_public_key(issuer)?;
let weight =
tg.weight_from(issued_for_pk, issuer_pk, Duration::from_secs(timestamp_sec))?;
Ok(weight)
})
.map(|w| (w, peer_id))
.into()
}
#[marine]
fn get_trust_bytes(
issued_for_peer_id: String,
@ -198,7 +232,7 @@ fn add_trust(trust: Trust, issuer_peer_id: String, timestamp_sec: u64) -> AddTru
}
#[marine]
fn get_revoke_bytes(revoked_peer_id: String, revoked_at: u64) -> GetRevokeBytesResult {
fn get_revocation_bytes(revoked_peer_id: String, revoked_at: u64) -> GetRevokeBytesResult {
wrapped_try(|| {
let public_key = extract_public_key(revoked_peer_id)?;
Ok(trust_graph::Revocation::signature_bytes(

View File

@ -321,7 +321,6 @@ impl Storage for SQLiteStorage {
let mut roots = vec![];
while let Some(row) = cursor.next()? {
log::info!("row: {:?}", row);
let pk = row[0].as_string().ok_or(PublicKeyConversion)?;
let pk: PK = PK::from_str(pk).map_err(|e| PublicKeyFromStr(e.to_string()))?;

View File

@ -201,7 +201,7 @@ mod service_tests {
revoked_peer_id: &PeerId,
revoked_at_sec: u64,
) -> Revocation {
let result = trust_graph.get_revoke_bytes(revoked_peer_id.to_base58(), revoked_at_sec);
let result = trust_graph.get_revocation_bytes(revoked_peer_id.to_base58(), revoked_at_sec);
assert!(result.success, "{}", result.error);
let revoke_bytes = issuer_kp.sign(&result.result).unwrap().to_vec().to_vec();

View File

@ -198,6 +198,29 @@ where
Ok(max_weight)
}
/// Get the maximum weight of trust for one public key.
/// for all chains which contain `issuer`
pub fn weight_from<P>(
&mut self,
issued_for: P,
issuer: P,
cur_time: Duration,
) -> Result<u32, TrustGraphError>
where
P: Borrow<PublicKey>,
{
let mut max_weight = 0;
// get all possible certificates from the given public key to all roots in the graph
// which contain `issuer`
let certs = self.get_all_certs_from(issued_for, issuer, cur_time)?;
if let Some(weight_factor) = self.certificates_weight_factor(certs)? {
max_weight = std::cmp::max(max_weight, get_weight_from_factor(weight_factor))
}
Ok(max_weight)
}
/// Calculate weight from given certificates
/// Returns None if there is no such public key
/// or some trust between this key and a root key is revoked.
@ -300,6 +323,27 @@ where
Ok(terminated_chains)
}
/// Get all possible certificates where `issued_for` will be the last element of the chain,
/// all certificates contain `issuer`
/// and one of the destinations is the root of this chain.
pub fn get_all_certs_from<P>(
&mut self,
issued_for: P,
issuer: P,
cur_time: Duration,
) -> Result<Vec<Certificate>, TrustGraphError>
where
P: Borrow<PublicKey>,
{
self.get_all_certs(issued_for, cur_time).map(|c| {
c.into_iter()
.filter(|cert: &Certificate| {
cert.chain.iter().any(|t| t.issued_for.eq(issuer.borrow()))
})
.collect()
})
}
/// Get all possible certificates where `issued_for` will be the last element of the chain
/// and one of the destinations is the root of this chain.
pub fn get_all_certs<P>(