Compare commits

..

5 Commits

Author SHA1 Message Date
a21733b034 fix tests 2022-01-20 18:28:52 +03:00
a491cf15e2 update service and aqua api 2022-01-20 17:41:22 +03:00
6b6f717c6c add missing example secret key 2022-01-17 02:43:08 +03:00
7ee8cacc03 fix 2022-01-17 02:35:59 +03:00
a207c52ce8 pr fixes 2022-01-17 02:34:05 +03:00
26 changed files with 5001 additions and 1238 deletions

289
Cargo.lock generated
View File

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

@ -49,24 +49,29 @@ async function main(environment: Node[]) {
Fluence.getStatus().peerId, Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId Fluence.getStatus().relayPeerId
); );
let root_sk_b58 = fs.readFileSync("./root_secret_key.ed25519").toString(); let root_sk_b58 = fs.readFileSync("./root_secret_key.ed25519").toString();
let issuer_sk_b58 = fs.readFileSync("./issuer_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 root_kp = await KeyPair.fromEd25519SK(bs58.decode(root_sk_b58));
let issuer_kp = await KeyPair.fromEd25519SK(bs58.decode(issuer_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 private key: %s", root_sk_b58);
console.log("Root peer id: %s", root_kp.Libp2pPeerId.toB58String()); console.log("Root peer id: %s", root_kp.Libp2pPeerId.toB58String());
console.log("Issuer private key: %s", issuer_sk_b58); console.log("Issuer private key: %s", issuer_sk_b58);
let cur_time = await timestamp_sec(node); let cur_time = await timestamp_sec(node);
let expires_at = cur_time + 60 * 60 * 24 * 365; let expires_at = cur_time + 60 * 60 * 24 * 365;
let certificates = [];
let common_chain = [] as any; let common_chain = [] as any;
// self-signed root trust // 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)); 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 // 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)); 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++) { for (let i = 0; i < krasnodar.length; i++) {
// from issuer to node // from issuer to node
let trust = await issue_trust_helper(node, issuer_kp, issuer_kp.Libp2pPeerId.toB58String(), krasnodar[i].peerId, expires_at, cur_time); 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", "author": "Fluence Labs",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@fluencelabs/aqua": "0.5.0-246", "@fluencelabs/aqua": "^0.5.2-257",
"@fluencelabs/aqua-lib": "0.2.1", "@fluencelabs/aqua-lib": "^0.3.2",
"@fluencelabs/fluence": "0.15.0", "@fluencelabs/fluence": "^0.18.0",
"@fluencelabs/fluence-network-environment": "^1.0.10", "@fluencelabs/fluence-network-environment": "^1.0.10",
"@fluencelabs/trust-graph": "file:../aqua", "@fluencelabs/trust-graph": "file:../aqua",
"bs58": "^4.0.1" "bs58": "^4.0.1"

View File

@ -1,78 +0,0 @@
module TrustGraph declares *
import "trust-graph.aqua"
import "trust-graph-api.aqua"
func add_root_trust_wrapped(node: string, max_chain_len: u32, expires_at_sec: u64) -> ?string:
on node:
error <- add_root_trust(max_chain_len, expires_at_sec)
<- error
func add_root_wrapped(node: string, peer_id: string, max_chain_len: u32) -> AddRootResult:
on node:
result <- add_root(peer_id, max_chain_len)
<- result
func get_weight_wrapped(node: string, peer_id: string) -> WeightResult:
on node:
result <- get_weight(peer_id)
<- result
func issue_trust_wrapped(node: string, issued_for_peer_id: string, expires_at_sec: u64) -> ?Trust, ?string:
on node:
result, error <- issue_trust(issued_for_peer_id, expires_at_sec)
<- result, error
func add_trust_wrapped(node: string, issued_for_peer_id: string, expires_at_sec: u64) -> ?string:
on node:
error <- add_trust(issued_for_peer_id, expires_at_sec)
<- error
func import_trust_wrapped(node: string, trust: Trust) -> ?string:
on node:
error <- import_trust(trust)
<- error
func verify_trust_wrapped(node: string, trust: Trust, issuer_peer_id: string) -> VerifyTrustResult:
on node:
result <- verify_trust(trust, issuer_peer_id)
<- result
func issue_revocation_wrapped(node: string, revoked_peer_id: string) -> ?Revocation, ?string:
on node:
result, error <- issue_revocation(revoked_peer_id)
<- result, error
func revoke_wrapped(node: string, revoked_peer_id: string) -> ?string:
on node:
error <- revoke(revoked_peer_id)
<- error
func import_revocation_wrapped(node: string, revocation: Revocation) -> ?string:
on node:
error <- import_revocation(revocation)
<- error
func get_host_certs_from_wrapped(node: string, issuer: string) -> AllCertsResult:
on node:
result <- get_host_certs_from(issuer)
<- result
func get_all_certs_wrapped(node: string, issued_for: string) -> AllCertsResult:
on node:
result <- get_all_certs(issued_for)
<- result
func get_host_certs_wrapped(node: string) -> AllCertsResult:
on node:
result <- get_host_certs()
<- result
func insert_cert_wrapped(node: string, certificate: Certificate) -> InsertResult:
on node:
result <- insert_cert(certificate)
<- result
func isFluencePeer_wrapped(node: string) -> ?bool, ?string:
on node:
result, error <- isFluencePeer()
<- result, error

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

View File

@ -1,6 +1,6 @@
{ {
"name": "@fluencelabs/trust-graph", "name": "@fluencelabs/trust-graph",
"version": "0.2.0", "version": "0.2.2",
"description": "Aqua Trust Graph API library", "description": "Aqua Trust Graph API library",
"files": [ "files": [
"*.aqua" "*.aqua"

View File

@ -1,26 +1,39 @@
import "trust-graph.aqua" import "trust-graph.aqua"
import "@fluencelabs/aqua-lib/builtin.aqua" import "misc.aqua"
import Sig, Peer from "@fluencelabs/aqua-lib/builtin.aqua"
func add_root(peer_id: string, max_chain_len: u32) -> AddRootResult: alias PeerId: string
weight_factor <- TrustGraph.get_weight_factor(max_chain_len) alias Error: string
result <- TrustGraph.add_root(peer_id, weight_factor)
-- 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 set_root(peer_id: PeerId, max_chain_len: u32) -> SetRootResult:
result <- TrustGraph.set_root(peer_id, max_chain_len)
<- result <- result
func get_weight(peer_id: string) -> WeightResult: -- Create and sign trust with private key from 'sig_id' service
timestamp_sec <- Peer.timestamp_sec() -- If `sig_id` is nil, default Sig service will be used with %init_peer_id% private key
result <- TrustGraph.get_weight(peer_id, timestamp_sec) func issue_trust(issued_for: PeerId, expires_at_sec: u64, sig_id: ?string) -> ?Trust, ?Error:
<- result on HOST_PEER_ID:
func issue_trust(issued_for_peer_id: string, expires_at_sec: u64) -> ?Trust, ?string:
issued_at_sec <- Peer.timestamp_sec() issued_at_sec <- Peer.timestamp_sec()
bytes <- TrustGraph.get_trust_bytes(issued_for_peer_id, expires_at_sec, issued_at_sec) bytes <- TrustGraph.get_trust_bytes(issued_for, expires_at_sec, issued_at_sec)
result: ?Trust result: ?Trust
error: ?string error: ?string
if bytes.success: if bytes.success:
on %init_peer_id% via HOST_PEER_ID: sig_service: ?string
if sig_id != nil:
sig_service <<- sig_id!
else:
sig_service <<- "sig"
Sig sig_service!
signature <- Sig.sign(bytes.result) signature <- Sig.sign(bytes.result)
issue_result <- TrustGraph.issue_trust(issued_for_peer_id, expires_at_sec, issued_at_sec, signature)
on HOST_PEER_ID:
issue_result <- TrustGraph.issue_trust(issued_for, expires_at_sec, issued_at_sec, signature)
if issue_result.success: if issue_result.success:
result <<- issue_result.trust result <<- issue_result.trust
else: else:
@ -29,58 +42,99 @@ func issue_trust(issued_for_peer_id: string, expires_at_sec: u64) -> ?Trust, ?st
error <<- bytes.error error <<- bytes.error
<- result, error <- result, error
func add_trust(issued_for_peer_id: string, expires_at_sec: u64) -> ?string: -- Add trust to TG instance on current node
trust, issue_error <- issue_trust(issued_for_peer_id, expires_at_sec) func import_trust(trust: Trust, issuer: PeerId) -> ?Error:
error: ?string error: ?string
if trust == nil:
error <<- issue_error!
else:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.add_trust(trust!, %init_peer_id%, timestamp_sec) add_result <- TrustGraph.add_trust(trust, issuer, timestamp_sec)
if add_result.success != true: if add_result.success != true:
error <<- add_result.error error <<- add_result.error
<- error <- error
func add_root_trust(max_chain_len: u32, expires_at_sec: u64) -> ?string: -- Issue trust and add to TG instance on `node`
add_root_result <- add_root(%init_peer_id%, max_chain_len) -- If `issuer` != %init_peer_id%, Sig service should be registered with issuer's peer id as a service id.
error: *?string func add_trust(node: PeerId, issuer: PeerId, issued_for: PeerId, expires_at_sec: u64) -> ?Error:
if add_root_result.success: sig_service: ?string
error <- add_trust(%init_peer_id%, expires_at_sec) if issuer != %init_peer_id%:
sig_service <<- issuer
trust, issue_error <- issue_trust(issued_for, expires_at_sec, sig_service)
error: *?Error
if trust == nil:
error <<- issue_error
else:
on node:
error <- import_trust(trust!, issuer)
<- error!
-- Set `peer_id` as a root and add self-signed trust to TG instance on `node`
-- If `peer_id` != %init_peer_id%, Sig service should be registered with this peer id as a service id.
func add_root_trust(node: PeerId, peer_id: PeerId, max_chain_len: u32, expires_at_sec: u64) -> ?Error:
sig_service: ?string
if peer_id != %init_peer_id%:
sig_service <<- peer_id
trust, issue_error <- issue_trust(peer_id, expires_at_sec, sig_service)
error: *?Error
if trust == nil:
error <<- issue_error
else:
on node:
set_root_result <- set_root(peer_id, max_chain_len)
if set_root_result.success:
error <- import_trust(trust!, peer_id)
else: else:
-- converting string to ?string -- converting string to ?string
tmp: *string tmp: *string
tmp <<- add_root_result.error tmp <<- set_root_result.error
error <<- tmp error <<- tmp
<- error! <- error!
func import_trust(trust: Trust) -> ?string: -- Check signature and expiration time of trust
error: ?string func verify_trust(trust: Trust, issuer: PeerId) -> VerifyTrustResult:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.add_trust(trust, %init_peer_id%, timestamp_sec) result <- TrustGraph.verify_trust(trust, issuer, timestamp_sec)
if add_result.success != true:
error <<- add_result.error
<- error
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 <- result
func issue_revocation(revoked_peer_id: string) -> ?Revocation, ?string: -- 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: PeerId) -> WeightResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_weight(peer_id, timestamp_sec)
<- result
-- Get maximum weight of trust among all chains which contain trust from `issuer`
func get_weight_from(peer_id: PeerId, issuer: PeerId) -> WeightResult:
timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_weight_from(peer_id, issuer, timestamp_sec)
<- result
-- Create revocation signed by %init_peer_id%
-- If `sig_id` is nil, default Sig service will be used with %init_peer_id% private key
func issue_revocation(revoked_by: PeerId, revoked: PeerId, sig_id: ?string) -> ?Revocation, ?Error:
on HOST_PEER_ID:
issued_at_sec <- Peer.timestamp_sec() issued_at_sec <- Peer.timestamp_sec()
bytes <- TrustGraph.get_revocation_bytes(revoked_peer_id, issued_at_sec) bytes <- TrustGraph.get_revocation_bytes(revoked, issued_at_sec)
result: ?Revocation result: ?Revocation
error: ?string error: ?string
if bytes.success: if bytes.success:
on %init_peer_id% via HOST_PEER_ID: sig_service: ?string
if sig_id != nil:
sig_service <<- sig_id!
else:
sig_service <<- "sig"
Sig sig_service!
signature <- Sig.sign(bytes.result) signature <- Sig.sign(bytes.result)
issue_result <- TrustGraph.issue_revocation(revoked_peer_id, %init_peer_id%, issued_at_sec, signature)
if issue_result.success != true: on HOST_PEER_ID:
issue_result <- TrustGraph.issue_revocation(revoked_by, revoked, issued_at_sec, signature)
if issue_result.success:
result <<- issue_result.revocation result <<- issue_result.revocation
else: else:
error <<- issue_result.error error <<- issue_result.error
@ -88,22 +142,8 @@ func issue_revocation(revoked_peer_id: string) -> ?Revocation, ?string:
error <<- bytes.error error <<- bytes.error
<- result, error <- result, error
func revoke(revoked_peer_id: string) -> ?string: -- Import revocation to current node's TG instance
revocation, issue_error <- issue_revocation(revoked_peer_id) func import_revocation(revocation: Revocation) -> ?Error:
error: ?string
if revocation == nil:
error <<- issue_error!
else:
timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.revoke(revocation!, timestamp_sec)
if add_result.success != true:
error <<- add_result.error
<- error
func import_revocation(revocation: Revocation) -> ?string:
error: ?string error: ?string
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
add_result <- TrustGraph.revoke(revocation, timestamp_sec) add_result <- TrustGraph.revoke(revocation, timestamp_sec)
@ -112,36 +152,60 @@ func import_revocation(revocation: Revocation) -> ?string:
<- error <- error
func get_host_certs_from(issuer: string) -> AllCertsResult: -- Revoke all certificates on `node` TG instance
-- which contain path from %init_peer_id% to `revoked_peer_id`
-- If `revoked_by` != %init_peer_id%, Sig service should be registered with this peer id as a service id.
func revoke(node: PeerId, revoked_by: PeerId, revoked: PeerId) -> ?Error:
sig_service: ?string
if revoked_by != %init_peer_id%:
sig_service <<- revoked_by
revocation, issue_error <- issue_revocation(revoked_by, revoked, sig_service)
error: *?string
if revocation == nil:
error <<- issue_error
else:
on node:
error <- import_revocation(revocation!)
<- error!
-- Return all certificates issued for current node which contains trust from `issuer`
func get_host_certs_from(issuer: PeerId) -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_host_certs_from(issuer, timestamp_sec) result <- TrustGraph.get_host_certs_from(issuer, timestamp_sec)
<- result <- result
func get_all_certs(issued_for: string) -> AllCertsResult: -- Return all certificates issued for given peer id
func get_all_certs(issued_for: PeerId) -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_all_certs(issued_for, timestamp_sec) result <- TrustGraph.get_all_certs(issued_for, timestamp_sec)
<- result <- result
-- Return all certificates issued for given peer id which contains trust from `issuer`
func get_all_certs_from(issued_for: PeerId, issuer: PeerId) -> 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: func get_host_certs() -> AllCertsResult:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.get_host_certs(timestamp_sec) result <- TrustGraph.get_host_certs(timestamp_sec)
<- result <- result
-- Insert certificate to TG instance on current node
func insert_cert(certificate: Certificate) -> InsertResult: func insert_cert(certificate: Certificate) -> InsertResult:
timestamp_sec <- Peer.timestamp_sec() timestamp_sec <- Peer.timestamp_sec()
result <- TrustGraph.insert_cert(certificate, timestamp_sec) result <- TrustGraph.insert_cert(certificate, timestamp_sec)
<- result <- result
-- helpers for isFluencePeer -- returns `true` if current node is identified as official Fluence Labs peer
service TrustOp("op"):
array_length(a: []Trust) -> u32
service BoolOp("op"):
array_length(a: []bool) -> u32
-- returns `true` if current relay is identified as official Fluence Labs peer
-- returns `false` otherwise -- returns `false` otherwise
func isFluencePeer() -> ?bool, ?string: func isFluencePeer() -> ?bool, ?Error:
certs_result <- get_host_certs_from("12D3KooWM45u7AQxsb4MuQJNYT3NWHHMLU7JTbBV66RTfF3KSzdR") certs_result <- get_host_certs_from("12D3KooWM45u7AQxsb4MuQJNYT3NWHHMLU7JTbBV66RTfF3KSzdR")
result: ?bool result: ?bool
error: ?string error: ?string

View File

@ -1,9 +1,5 @@
module TrustGraph declares * module TrustGraph declares *
data AddRootResult:
success: bool
error: string
data AddTrustResult: data AddTrustResult:
success: bool success: bool
error: string error: string
@ -24,6 +20,18 @@ data AllCertsResult:
certificates: []Certificate certificates: []Certificate
error: string error: string
data Revocation:
revoked_peer_id: string
revoked_at: u64
signature: string
sig_type: string
revoked_by: string
data ExportRevocationsResult:
success: bool
revocations: []Revocation
error: string
data GetRevokeBytesResult: data GetRevokeBytesResult:
success: bool success: bool
error: string error: string
@ -38,13 +46,6 @@ data InsertResult:
success: bool success: bool
error: string error: string
data Revocation:
revoked_peer_id: string
revoked_at: u64
signature: string
sig_type: string
revoked_by: string
data IssueRevocationResult: data IssueRevocationResult:
success: bool success: bool
error: string error: string
@ -59,6 +60,10 @@ data RevokeResult:
success: bool success: bool
error: string error: string
data SetRootResult:
success: bool
error: string
data VerifyTrustResult: data VerifyTrustResult:
success: bool success: bool
error: string error: string
@ -70,18 +75,20 @@ data WeightResult:
error: string error: string
service TrustGraph("trust-graph"): 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 add_trust(trust: Trust, issuer_peer_id: string, timestamp_sec: u64) -> AddTrustResult
export_revocations(issued_for: string) -> ExportRevocationsResult
get_all_certs(issued_for: string, timestamp_sec: u64) -> AllCertsResult 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(timestamp_sec: u64) -> AllCertsResult
get_host_certs_from(issuer: string, timestamp_sec: u64) -> AllCertsResult get_host_certs_from(issuer: string, timestamp_sec: u64) -> AllCertsResult
get_revocation_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_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(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(certificate: Certificate, timestamp_sec: u64) -> InsertResult
insert_cert_raw(certificate: string, 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 issue_revocation(revoked_by_peer_id: string, revoked_peer_id: string, revoked_at_sec: u64, signature_bytes: []u8) -> IssueRevocationResult
issue_trust(issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64, trust_bytes: []u8) -> IssueTrustResult issue_trust(issued_for_peer_id: string, expires_at_sec: u64, issued_at_sec: u64, trust_bytes: []u8) -> IssueTrustResult
revoke(revoke: Revocation, timestamp_sec: u64) -> RevokeResult revoke(revoke: Revocation, timestamp_sec: u64) -> RevokeResult
set_root(peer_id: string, max_chain_len: u32) -> SetRootResult
verify_trust(trust: Trust, issuer_peer_id: string, timestamp_sec: u64) -> VerifyTrustResult verify_trust(trust: Trust, issuer_peer_id: string, timestamp_sec: u64) -> VerifyTrustResult

View File

@ -1,6 +1,6 @@
(seq (seq
(seq (seq
(call relay ("trust-graph" "add_root") ["12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB" 2] add_root_res) (call relay ("trust-graph" "set_root") ["12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB" 5] add_root_res)
(xor (xor
(match add_root_res.$.success! true (match add_root_res.$.success! true
(null) (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` 1. Go to `local-network`
2. Run `docker compose up -d` to start Fluence node 2. Run `docker compose up -d` to start Fluence node
3. Go back to `../example` 3. Go back to `../example`
4. Run `npm i` 4. Run `npm i`
5. Run `npm run start` 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

@ -13,12 +13,15 @@ service TrustedComputation("op"):
func trusted_computation(node: string) -> ?u64: func trusted_computation(node: string) -> ?u64:
result: ?u64 result: ?u64
on node: -- on our trusted relay
certs_result <- get_host_certs_from(%init_peer_id%) 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: if certs_result.success:
len <- CertOp.array_length(certs_result.certificates) len <- CertOp.array_length(certs_result.certificates)
-- if there is any certificate node is trusted and computation is possible
if len != 0: if len != 0:
on node:
result <- TrustedComputation.identity(5) result <- TrustedComputation.identity(5)
<- result <- result

View File

@ -1,13 +1,13 @@
import "@fluencelabs/trust-graph/export.aqua" import add_root_trust, add_trust, revoke from "@fluencelabs/trust-graph/trust-graph-api.aqua"
export add_root_trust, add_trust, revoke
export issue_trust_wrapped as issue_trust, verify_trust_wrapped as verify_trust, add_trust_wrapped as add_trust, import_trust_wrapped as import_trust
export add_root_trust_wrapped as add_root_trust, add_root_wrapped as add_root, get_weight_wrapped as get_weight, get_all_certs_wrapped as get_all_certs, insert_cert_wrapped as insert_cert
export issue_revocation_wrapped as issue_revocation, revoke_wrapped as revoke, isFluencePeer_wrapped as isFluencePeer
import Peer from "@fluencelabs/aqua-lib/builtin.aqua" import Peer from "@fluencelabs/aqua-lib/builtin.aqua"
alias PeerId: string
func timestamp_sec() -> u64: func timestamp_sec() -> u64:
on HOST_PEER_ID: on HOST_PEER_ID:
result <- Peer.timestamp_sec() result <- Peer.timestamp_sec()
<- result <- result
service Sig:
sign(msg: []u8) -> []u8

View File

@ -19,6 +19,7 @@ import * as tg from "./generated/export";
import {Fluence, FluencePeer, KeyPair} from "@fluencelabs/fluence"; import {Fluence, FluencePeer, KeyPair} from "@fluencelabs/fluence";
import {krasnodar, Node, testNet, stage} from "@fluencelabs/fluence-network-environment"; import {krasnodar, Node, testNet, stage} from "@fluencelabs/fluence-network-environment";
import assert from "assert"; import assert from "assert";
import {add_root_trust, registerSig} from "./generated/export";
const bs58 = require('bs58'); const bs58 = require('bs58');
let local: Node[] = [ let local: Node[] = [
@ -39,47 +40,35 @@ let local: Node[] = [
}, },
]; ];
async function add_roots() { async function revoke_all(relay: string, revoked_by: string) {
let current_time = await tg.timestamp_sec();
let far_future = current_time + 9999999;
for (var node of local) { for (var node of local) {
let error = await tg.add_root_trust(node.peerId, 2, far_future); let error = await tg.revoke(relay, revoked_by, node.peerId);
console.log("Added root trust for %s", node.peerId) console.log(error)
assert(error == null); assert(error == null);
} }
} }
async function add_root(relay: string, peer_id: string) {
async function is_fluence_peer(node: string) { let current_time = await tg.timestamp_sec();
let [result, error] = await tg.isFluencePeer(node); let far_future = current_time + 9999999;
let error = await tg.add_root_trust(relay, peer_id, 2, far_future);
console.log("%s %s", result, error); assert(error == null);
if (error !== null) {
console.error("Something went wrong: %s", error);
} else {
assert(result !== null);
if (result) {
console.log("Current relay %s identified as Fluence Labs' peer", Fluence.getStatus().relayPeerId)
} else {
console.log("Current relay %s is not Fluence Labs' peer", Fluence.getStatus().relayPeerId)
}
}
} }
async function add_new_trust_checked(node: string, issued_for_peer_id: string, expires_at_sec: number) { async function add_new_trust_checked(relay: string, issuer: string, issued_for_peer_id: string, expires_at_sec: number) {
let error = await tg.add_trust(node, issued_for_peer_id, expires_at_sec); let error = await tg.add_trust(relay, issuer, issued_for_peer_id, expires_at_sec);
if (error !== null) { if (error !== null) {
console.error("%s", error); console.error("%s", error);
} else { } else {
console.log("Trust to node %s successfully added", node) console.log("Trust issued for %s successfully added", issued_for_peer_id)
} }
} }
async function revoke_checked(node: string, revoked_peer_id: string) { async function revoke_checked(relay: string, revoked_by: string, revoked_peer_id: string) {
let error = await tg.revoke(node, revoked_peer_id); let error = await tg.revoke(relay, revoked_by, revoked_peer_id);
if (error !== null) { if (error !== null) {
console.error("%s", error); console.log("%s", error);
} else { } else {
console.log("Trust to node %s revoked", node) console.log("Trust issued for %s revoked", revoked_peer_id)
} }
} }
@ -87,48 +76,63 @@ async function exec_trusted_computation(node: string) {
let result = await trusted_computation(node) let result = await trusted_computation(node)
if (result !== null) { if (result !== null) {
console.log("Trusted computation on node %s successful, result is %s", node, result) console.log("📗 Trusted computation on node %s successful, result is %s", node, result)
} else { } else {
console.log("Trusted computation on node %s failed", node) console.log("📕 Trusted computation on node %s failed", node)
} }
} }
async function main() { 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"); console.log("📘 Will connect to local nodes");
// key from local-network/builtins_secret_key.ed25519 to connect as builtins owner // 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 sk = bs58.decode("5FwE32bDcphFzuMca7Y2qW1gdR64fTBYoRNvD4MLE1hecDGhCMQGKn8aseMr5wRo4Xo2CRFdrEAawUNLYkgQD78K").slice(0, 32); // first 32 bytes - secret key, second - public key
let builtins_keypair = await KeyPair.fromEd25519SK(sk); 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( console.log(
"📗 created a fluence peer %s with relay %s", "📗 created a fluence peer %s with relay %s",
Fluence.getStatus().peerId, Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId Fluence.getStatus().relayPeerId
); );
let local_peer_id = Fluence.getStatus().peerId;
await add_roots(); assert(local_peer_id !== null);
let nodeA = local[0].peerId
let nodeB = local[1].peerId
let nodeC = local[2].peerId
await revoke_checked(nodeB, nodeB);
await exec_trusted_computation(nodeA);
await exec_trusted_computation(nodeB);
await exec_trusted_computation(nodeC);
let current_time = await tg.timestamp_sec(); let current_time = await tg.timestamp_sec();
let far_future = current_time + 9999999; let far_future = current_time + 9999999;
await add_new_trust_checked(nodeB, nodeB, far_future); // clear all trusts from our peer id on relay
await revoke_all(relay.peerId, local_peer_id);
// 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));
await exec_trusted_computation(nodeA); // set our peer id as root to our relay
await exec_trusted_computation(nodeB); await add_root(relay.peerId, local_peer_id);
await exec_trusted_computation(nodeC);
await revoke_checked(nodeB, nodeB); let nodeA = local[0].peerId
let nodeB = local[1].peerId
let nodeC = local[2].peerId
await exec_trusted_computation(nodeA); // try to exec computation on every node, will fail
await exec_trusted_computation(nodeB); await exec_trusted_computation(nodeA); // fail
await exec_trusted_computation(nodeC); await exec_trusted_computation(nodeB); // fail
await exec_trusted_computation(nodeC); // fail
console.log("🌀 Issue trust to nodeB: %s", nodeB);
await add_new_trust_checked(relay.peerId, local_peer_id, 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, local_peer_id, nodeB);
await exec_trusted_computation(nodeA); // fail
await exec_trusted_computation(nodeB); // fail
await exec_trusted_computation(nodeC); // fail
return; return;
} }

View File

@ -0,0 +1 @@
E5ay3731i4HN8XjJozouV92RDMGAn3qSnb9dKSnujiWv

View File

@ -60,9 +60,9 @@ pub struct AllCertsResult {
impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult { impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
fn from(result: Result<Vec<Certificate>, ServiceError>) -> Self { fn from(result: Result<Vec<Certificate>, ServiceError>) -> Self {
match result { match result {
Ok(certs) => AllCertsResult { Ok(certificates) => AllCertsResult {
success: true, success: true,
certificates: certs, certificates,
error: "".to_string(), error: "".to_string(),
}, },
Err(e) => AllCertsResult { Err(e) => AllCertsResult {
@ -75,19 +75,19 @@ impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
} }
#[marine] #[marine]
pub struct AddRootResult { pub struct SetRootResult {
pub success: bool, pub success: bool,
pub error: String, pub error: String,
} }
impl From<Result<(), ServiceError>> for AddRootResult { impl From<Result<(), ServiceError>> for SetRootResult {
fn from(result: Result<(), ServiceError>) -> Self { fn from(result: Result<(), ServiceError>) -> Self {
match result { match result {
Ok(()) => AddRootResult { Ok(()) => SetRootResult {
success: true, success: true,
error: "".to_string(), error: "".to_string(),
}, },
Err(e) => AddRootResult { Err(e) => SetRootResult {
success: false, success: false,
error: format!("{}", e), error: format!("{}", e),
}, },
@ -256,3 +256,27 @@ impl From<Result<(), ServiceError>> for RevokeResult {
} }
} }
} }
#[marine]
pub struct ExportRevocationsResult {
pub success: bool,
pub revocations: Vec<Revocation>,
pub error: String,
}
impl From<Result<Vec<Revocation>, ServiceError>> for ExportRevocationsResult {
fn from(result: Result<Vec<Revocation>, ServiceError>) -> Self {
match result {
Ok(revocations) => ExportRevocationsResult {
success: true,
revocations,
error: "".to_string(),
},
Err(e) => ExportRevocationsResult {
success: false,
revocations: vec![],
error: format!("{}", e),
},
}
}
}

View File

@ -2,9 +2,9 @@ use crate::dto::{Certificate, Revocation, Trust};
use crate::error::ServiceError; use crate::error::ServiceError;
use crate::misc::{check_timestamp_tetraplets, extract_public_key, with_tg, wrapped_try}; use crate::misc::{check_timestamp_tetraplets, extract_public_key, with_tg, wrapped_try};
use crate::results::{ use crate::results::{
AddRootResult, AddTrustResult, AllCertsResult, GetRevokeBytesResult, GetTrustBytesResult, AddTrustResult, AllCertsResult, ExportRevocationsResult, GetRevokeBytesResult,
InsertResult, IssueRevocationResult, IssueTrustResult, RevokeResult, VerifyTrustResult, GetTrustBytesResult, InsertResult, IssueRevocationResult, IssueTrustResult, RevokeResult,
WeightResult, SetRootResult, VerifyTrustResult, WeightResult,
}; };
use crate::storage_impl::SQLiteStorage; use crate::storage_impl::SQLiteStorage;
use fluence_keypair::Signature; use fluence_keypair::Signature;
@ -12,27 +12,22 @@ use marine_rs_sdk::{get_call_parameters, marine, CallParameters};
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use trust_graph::{TrustGraph, MAX_WEIGHT_FACTOR}; use trust_graph::TrustGraph;
#[marine] #[marine]
fn get_weight_factor(max_chain_len: u32) -> u32 { /// could set only a owner of a trust graph service
MAX_WEIGHT_FACTOR.checked_sub(max_chain_len).unwrap_or(0u32) fn set_root(peer_id: String, max_chain_len: u32) -> SetRootResult {
}
#[marine]
/// could add only a owner of a trust graph service
fn add_root(peer_id: String, weight_factor: u32) -> AddRootResult {
let call_parameters: CallParameters = marine_rs_sdk::get_call_parameters(); let call_parameters: CallParameters = marine_rs_sdk::get_call_parameters();
let init_peer_id = call_parameters.init_peer_id; let init_peer_id = call_parameters.init_peer_id;
if call_parameters.service_creator_peer_id == init_peer_id { if call_parameters.service_creator_peer_id == init_peer_id {
with_tg(|tg| { with_tg(|tg| {
let public_key = extract_public_key(peer_id)?; let public_key = extract_public_key(peer_id)?;
tg.add_root_weight_factor(public_key, weight_factor)?; tg.set_root(public_key, max_chain_len)?;
Ok(()) Ok(())
}) })
.into() .into()
} else { } else {
return AddRootResult { return SetRootResult {
success: false, success: false,
error: ServiceError::NotOwner.to_string(), error: ServiceError::NotOwner.to_string(),
}; };
@ -71,17 +66,40 @@ fn get_certs(
tg: &mut TrustGraph<SQLiteStorage>, tg: &mut TrustGraph<SQLiteStorage>,
issued_for: String, issued_for: String,
timestamp_sec: u64, timestamp_sec: u64,
) -> Result<impl Iterator<Item = Certificate>, ServiceError> { ) -> Result<Vec<Certificate>, ServiceError> {
let public_key = extract_public_key(issued_for)?; let public_key = extract_public_key(issued_for)?;
let certs = tg.get_all_certs(public_key, Duration::from_secs(timestamp_sec))?; 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] #[marine]
fn get_all_certs(issued_for: String, timestamp_sec: u64) -> AllCertsResult { fn get_all_certs(issued_for: String, timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| { with_tg(|tg| {
check_timestamp_tetraplets(&marine_rs_sdk::get_call_parameters(), 1)?; 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() .into()
} }
@ -91,7 +109,7 @@ fn get_host_certs(timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| { with_tg(|tg| {
let cp = marine_rs_sdk::get_call_parameters(); let cp = marine_rs_sdk::get_call_parameters();
check_timestamp_tetraplets(&cp, 0)?; 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() .into()
} }
@ -101,10 +119,7 @@ fn get_host_certs_from(issuer: String, timestamp_sec: u64) -> AllCertsResult {
with_tg(|tg| { with_tg(|tg| {
let cp = get_call_parameters(); let cp = get_call_parameters();
check_timestamp_tetraplets(&cp, 1)?; check_timestamp_tetraplets(&cp, 1)?;
get_certs(tg, cp.host_id, timestamp_sec).map(|c| { get_certs_from(tg, cp.host_id, issuer, timestamp_sec)
c.filter(|cert: &Certificate| cert.chain.iter().any(|t| t.issued_for == issuer))
.collect()
})
}) })
.into() .into()
} }
@ -121,6 +136,20 @@ fn get_weight(peer_id: String, timestamp_sec: u64) -> WeightResult {
.into() .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] #[marine]
fn get_trust_bytes( fn get_trust_bytes(
issued_for_peer_id: String, issued_for_peer_id: String,
@ -187,12 +216,11 @@ fn add_trust(trust: Trust, issuer_peer_id: String, timestamp_sec: u64) -> AddTru
return Err(ServiceError::InvalidTimestamp("trust".to_string())); return Err(ServiceError::InvalidTimestamp("trust".to_string()));
} }
tg.add_trust( Ok(tg.add_trust(
&trust.try_into()?, &trust.try_into()?,
public_key, public_key,
Duration::from_secs(timestamp_sec), Duration::from_secs(timestamp_sec),
) )?)
.map_err(ServiceError::TGError)
}) })
.into() .into()
} }
@ -211,8 +239,8 @@ fn get_revocation_bytes(revoked_peer_id: String, revoked_at: u64) -> GetRevokeBy
#[marine] #[marine]
fn issue_revocation( fn issue_revocation(
revoked_peer_id: String,
revoked_by_peer_id: String, revoked_by_peer_id: String,
revoked_peer_id: String,
revoked_at_sec: u64, revoked_at_sec: u64,
signature_bytes: Vec<u8>, signature_bytes: Vec<u8>,
) -> IssueRevocationResult { ) -> IssueRevocationResult {
@ -222,7 +250,7 @@ fn issue_revocation(
let revoked_at = Duration::from_secs(revoked_at_sec); let revoked_at = Duration::from_secs(revoked_at_sec);
let signature = Signature::from_bytes(revoked_by_pk.get_key_format(), signature_bytes); let signature = Signature::from_bytes(revoked_by_pk.get_key_format(), signature_bytes);
Ok(trust_graph::Revocation::new(revoked_pk, revoked_by_pk, revoked_at, signature).into()) Ok(trust_graph::Revocation::new(revoked_by_pk, revoked_pk, revoked_at, signature).into())
}) })
.into() .into()
} }
@ -236,7 +264,20 @@ fn revoke(revoke: Revocation, timestamp_sec: u64) -> RevokeResult {
return Err(ServiceError::InvalidTimestamp("revoke".to_string())); return Err(ServiceError::InvalidTimestamp("revoke".to_string()));
} }
tg.revoke(revoke.try_into()?).map_err(ServiceError::TGError) Ok(tg.revoke(revoke.try_into()?)?)
})
.into()
}
#[marine]
fn export_revocations(issued_for: String) -> ExportRevocationsResult {
with_tg(|tg| {
let issued_for_pk = extract_public_key(issued_for)?;
Ok(tg
.get_revocations(issued_for_pk)?
.into_iter()
.map(|r| r.into())
.collect())
}) })
.into() .into()
} }

View File

@ -293,7 +293,7 @@ impl Storage for SQLiteStorage {
} }
} }
fn add_root_weight_factor( fn set_root_weight_factor(
&mut self, &mut self,
pk: PK, pk: PK,
weight_factor: WeightFactor, weight_factor: WeightFactor,

View File

@ -87,8 +87,8 @@ mod service_tests {
cp cp
} }
fn add_root_peer_id(trust_graph: &mut ServiceInterface, peer_id: PeerId, weight_factor: u32) { fn set_root_peer_id(trust_graph: &mut ServiceInterface, peer_id: PeerId, max_chain_len: u32) {
let result = trust_graph.add_root(peer_id.to_base58(), weight_factor); let result = trust_graph.set_root(peer_id.to_base58(), max_chain_len);
assert!(result.success, "{}", result.error); assert!(result.success, "{}", result.error);
} }
@ -97,9 +97,9 @@ mod service_tests {
issuer_kp: &KeyPair, issuer_kp: &KeyPair,
issued_at_sec: u64, issued_at_sec: u64,
expires_at_sec: u64, expires_at_sec: u64,
weight_factor: u32, max_chain_len: u32,
) -> Trust { ) -> Trust {
let result = trust_graph.add_root(issuer_kp.get_peer_id().to_base58(), weight_factor); let result = trust_graph.set_root(issuer_kp.get_peer_id().to_base58(), max_chain_len);
assert!(result.success, "{}", result.error); assert!(result.success, "{}", result.error);
add_trust( add_trust(
trust_graph, trust_graph,
@ -206,8 +206,8 @@ mod service_tests {
let revoke_bytes = issuer_kp.sign(&result.result).unwrap().to_vec().to_vec(); let revoke_bytes = issuer_kp.sign(&result.result).unwrap().to_vec().to_vec();
let issue_result = trust_graph.issue_revocation( let issue_result = trust_graph.issue_revocation(
revoked_peer_id.to_base58(),
issuer_kp.get_peer_id().to_base58(), issuer_kp.get_peer_id().to_base58(),
revoked_peer_id.to_base58(),
revoked_at_sec, revoked_at_sec,
revoke_bytes, revoke_bytes,
); );
@ -325,7 +325,7 @@ mod service_tests {
}; };
let some_peer_id = KeyPair::generate_ed25519().get_peer_id(); let some_peer_id = KeyPair::generate_ed25519().get_peer_id();
let result = trust_graph.add_root_cp(some_peer_id.to_base58(), 0, cp); let result = trust_graph.set_root_cp(some_peer_id.to_base58(), 0, cp);
assert!(!result.success); assert!(!result.success);
assert_eq!(result.error, ServiceError::NotOwner.to_string()); assert_eq!(result.error, ServiceError::NotOwner.to_string());
} }
@ -343,7 +343,7 @@ mod service_tests {
}; };
let some_peer_id = KeyPair::generate_ed25519().get_peer_id(); let some_peer_id = KeyPair::generate_ed25519().get_peer_id();
let result = trust_graph.add_root_cp(some_peer_id.to_base58(), 0, cp); let result = trust_graph.set_root_cp(some_peer_id.to_base58(), 0, cp);
assert!(result.success, "{}", result.error); assert!(result.success, "{}", result.error);
} }
@ -357,7 +357,7 @@ mod service_tests {
let expires_at_sec = 9999u64; let expires_at_sec = 9999u64;
let issued_at_sec = 0u64; let issued_at_sec = 0u64;
add_root_peer_id(&mut trust_graph, root_kp.get_peer_id(), 4u32); set_root_peer_id(&mut trust_graph, root_kp.get_peer_id(), 4u32);
let result = let result =
trust_graph.get_trust_bytes(root_peer_id.to_base58(), expires_at_sec, issued_at_sec); trust_graph.get_trust_bytes(root_peer_id.to_base58(), expires_at_sec, issued_at_sec);
@ -408,7 +408,7 @@ mod service_tests {
&root_kp, &root_kp,
cur_time, cur_time,
root_expired_time - 1, root_expired_time - 1,
4, 10,
); );
let trust_kp = KeyPair::generate_ed25519(); let trust_kp = KeyPair::generate_ed25519();
@ -447,7 +447,7 @@ mod service_tests {
let peerA_kp = KeyPair::generate_ed25519(); let peerA_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64; let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 4u32); add_root_with_trust(&mut trust_graph, &peerA_kp, cur_time, cur_time + 9999, 10);
let peerB_kp = KeyPair::generate_ed25519(); let peerB_kp = KeyPair::generate_ed25519();
add_trust( add_trust(
@ -490,7 +490,7 @@ mod service_tests {
let mut cur_time = current_time(); let mut cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id(); let root_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root_peer_id, 2); set_root_peer_id(&mut trust_graph, root_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time); add_trusts(&mut trust_graph, &trusts, cur_time);
let target_peer_id = key_pairs[4].get_peer_id(); let target_peer_id = key_pairs[4].get_peer_id();
@ -536,7 +536,7 @@ mod service_tests {
let cur_time = current_time(); let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id(); let root_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root_peer_id, 2); set_root_peer_id(&mut trust_graph, root_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time); add_trusts(&mut trust_graph, &trusts, cur_time);
let issued_by = key_pairs.last().unwrap().get_peer_id(); let issued_by = key_pairs.last().unwrap().get_peer_id();
@ -577,7 +577,7 @@ mod service_tests {
let cur_time = current_time(); let cur_time = current_time();
let root1_peer_id = key_pairs[0].get_peer_id(); let root1_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root1_peer_id, 2); set_root_peer_id(&mut trust_graph, root1_peer_id, 10);
add_trusts(&mut trust_graph, &trusts, cur_time); add_trusts(&mut trust_graph, &trusts, cur_time);
let issued_by = key_pairs.last().unwrap().get_peer_id(); let issued_by = key_pairs.last().unwrap().get_peer_id();
@ -620,7 +620,7 @@ mod service_tests {
let cur_time = current_time(); let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id(); let root_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root_peer_id, 1); set_root_peer_id(&mut trust_graph, root_peer_id, 10);
for auth in trusts.iter() { for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time); add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
@ -649,9 +649,9 @@ mod service_tests {
let far_future = cur_time + 9999; let far_future = cur_time + 9999;
// add first and last trusts as roots // add first and last trusts as roots
add_root_peer_id(&mut trust_graph, kps[0].get_peer_id(), 0); set_root_peer_id(&mut trust_graph, kps[0].get_peer_id(), 10);
add_trusts(&mut trust_graph, &trusts, cur_time); add_trusts(&mut trust_graph, &trusts, cur_time);
add_root_with_trust(&mut trust_graph, &kps[5], cur_time, far_future, 0); add_root_with_trust(&mut trust_graph, &kps[5], cur_time, far_future, 10);
let certs = get_all_certs(&mut trust_graph, kps[5].get_peer_id(), cur_time); let certs = get_all_certs(&mut trust_graph, kps[5].get_peer_id(), cur_time);
// first with self-signed last trust, second - without // first with self-signed last trust, second - without
@ -667,7 +667,7 @@ mod service_tests {
let root_kp = KeyPair::generate_ed25519(); let root_kp = KeyPair::generate_ed25519();
let cur_time = 100u64; let cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 4u32); add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 10);
let trust_kp = KeyPair::generate_ed25519(); let trust_kp = KeyPair::generate_ed25519();
add_trust( add_trust(
@ -712,7 +712,7 @@ mod service_tests {
let root_kp = KeyPair::generate_ed25519(); let root_kp = KeyPair::generate_ed25519();
let mut cur_time = 100u64; let mut cur_time = 100u64;
add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 4u32); add_root_with_trust(&mut trust_graph, &root_kp, cur_time, cur_time + 999, 10);
let trust_kp = KeyPair::generate_ed25519(); let trust_kp = KeyPair::generate_ed25519();
let expires_at_sec = cur_time + 10; let expires_at_sec = cur_time + 10;
@ -752,10 +752,10 @@ mod service_tests {
let root2_kp = KeyPair::generate_ed25519(); let root2_kp = KeyPair::generate_ed25519();
let cur_time = 100; let cur_time = 100;
let far_future = cur_time + 99999; let far_future = cur_time + 99999;
// root with bigger weight (smaller weight factor) // root with bigger weight (bigger max_chain_len)
add_root_with_trust(&mut trust_graph, &root1_kp, cur_time, far_future, 0u32); add_root_with_trust(&mut trust_graph, &root1_kp, cur_time, far_future, 10);
// opposite // opposite
add_root_with_trust(&mut trust_graph, &root2_kp, cur_time, far_future, 5u32); add_root_with_trust(&mut trust_graph, &root2_kp, cur_time, far_future, 5);
// issue trust from root2 to any other peer_id // issue trust from root2 to any other peer_id
let issued_by_root2_peer_id = KeyPair::generate_ed25519().get_peer_id(); let issued_by_root2_peer_id = KeyPair::generate_ed25519().get_peer_id();
@ -832,7 +832,7 @@ mod service_tests {
let cur_time = current_time(); let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id(); let root_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root_peer_id, 1); set_root_peer_id(&mut trust_graph, root_peer_id, 10);
for auth in trusts.iter() { for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time); add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
@ -862,7 +862,7 @@ mod service_tests {
let cur_time = current_time(); let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id(); let root_peer_id = key_pairs[0].get_peer_id();
add_root_peer_id(&mut trust_graph, root_peer_id, 1); set_root_peer_id(&mut trust_graph, root_peer_id, 10);
for auth in trusts.iter() { for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time); add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);

View File

@ -50,8 +50,8 @@ pub struct Revocation {
impl Revocation { impl Revocation {
#[allow(dead_code)] #[allow(dead_code)]
pub fn new( pub fn new(
pk: PublicKey,
revoked_by: PublicKey, revoked_by: PublicKey,
pk: PublicKey,
revoked_at: Duration, revoked_at: Duration,
signature: Signature, signature: Signature,
) -> Self { ) -> Self {
@ -69,7 +69,7 @@ impl Revocation {
let msg = Revocation::signature_bytes(&to_revoke, revoked_at); let msg = Revocation::signature_bytes(&to_revoke, revoked_at);
let signature = revoker.sign(&msg).unwrap(); let signature = revoker.sign(&msg).unwrap();
Revocation::new(to_revoke, revoker.public(), revoked_at, signature) Revocation::new(revoker.public(), to_revoke, revoked_at, signature)
} }
pub fn signature_bytes(pk: &PublicKey, revoked_at: Duration) -> Vec<u8> { pub fn signature_bytes(pk: &PublicKey, revoked_at: Duration) -> Vec<u8> {
@ -120,8 +120,8 @@ mod tests {
let duration2 = Duration::new(95, 0); let duration2 = Duration::new(95, 0);
let corrupted_revoke = Revocation::new( let corrupted_revoke = Revocation::new(
to_revoke.public(),
revoker.public(), revoker.public(),
to_revoke.public(),
duration2, duration2,
revoke.signature, revoke.signature,
); );

View File

@ -94,6 +94,10 @@ impl From<TrustGraphError> for String {
} }
} }
fn get_weight_factor(max_chain_len: u32) -> u32 {
MAX_WEIGHT_FACTOR.checked_sub(max_chain_len).unwrap_or(0u32)
}
pub fn get_weight_from_factor(wf: WeightFactor) -> u32 { pub fn get_weight_from_factor(wf: WeightFactor) -> u32 {
2u32.pow(MAX_WEIGHT_FACTOR.saturating_sub(wf)) 2u32.pow(MAX_WEIGHT_FACTOR.saturating_sub(wf))
} }
@ -107,12 +111,10 @@ where
} }
/// Insert new root weight /// Insert new root weight
pub fn add_root_weight_factor( pub fn set_root(&mut self, pk: PublicKey, max_chain_len: u32) -> Result<(), TrustGraphError> {
&mut self, Ok(self
pk: PublicKey, .storage
weight: WeightFactor, .set_root_weight_factor(pk.into(), get_weight_factor(max_chain_len))?)
) -> Result<(), TrustGraphError> {
Ok(self.storage.add_root_weight_factor(pk.into(), weight)?)
} }
pub fn add_trust<T, P>( pub fn add_trust<T, P>(
@ -198,6 +200,29 @@ where
Ok(max_weight) 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 /// Calculate weight from given certificates
/// Returns None if there is no such public key /// Returns None if there is no such public key
/// or some trust between this key and a root key is revoked. /// or some trust between this key and a root key is revoked.
@ -300,6 +325,27 @@ where
Ok(terminated_chains) 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 /// 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. /// and one of the destinations is the root of this chain.
pub fn get_all_certs<P>( pub fn get_all_certs<P>(
@ -344,4 +390,11 @@ where
Ok(self.storage.revoke(revocation)?) Ok(self.storage.revoke(revocation)?)
} }
pub fn get_revocations<P>(&self, issued_for: P) -> Result<Vec<Revocation>, TrustGraphError>
where
P: Borrow<PublicKey>,
{
Ok(self.storage.get_revocations(issued_for.borrow().as_ref())?)
}
} }

View File

@ -22,7 +22,11 @@ pub trait Storage {
fn insert(&mut self, node: TrustRelation) -> Result<(), Self::Error>; fn insert(&mut self, node: TrustRelation) -> Result<(), Self::Error>;
fn get_root_weight_factor(&self, pk: &PK) -> Result<Option<WeightFactor>, Self::Error>; fn get_root_weight_factor(&self, pk: &PK) -> Result<Option<WeightFactor>, Self::Error>;
fn add_root_weight_factor(&mut self, pk: PK, weight: WeightFactor) -> Result<(), Self::Error>; fn set_root_weight_factor(
&mut self,
pk: PK,
weight_factor: WeightFactor,
) -> Result<(), Self::Error>;
fn root_keys(&self) -> Result<Vec<PK>, Self::Error>; fn root_keys(&self) -> Result<Vec<PK>, Self::Error>;
fn revoke(&mut self, revocation: Revocation) -> Result<(), Self::Error>; fn revoke(&mut self, revocation: Revocation) -> Result<(), Self::Error>;
fn update_auth(&mut self, auth: Auth, cur_time: Duration) -> Result<(), Self::Error>; fn update_auth(&mut self, auth: Auth, cur_time: Duration) -> Result<(), Self::Error>;