mirror of
https://github.com/fluencelabs/trust-graph
synced 2024-12-04 23:30:19 +00:00
40 lines
1.4 KiB
Plaintext
40 lines
1.4 KiB
Plaintext
import "misc.aqua"
|
|
import get_host_certs_from from "trust-graph-api.aqua"
|
|
|
|
alias Error: string
|
|
|
|
-- TrustGraph builtin distributed with predefined certificates which used to identify Fluence Labs peers.
|
|
-- Each certificate contains 3 trusts: self-signed fluence root trust, trust for label trust and trust to target peer.
|
|
--
|
|
-- Usage:
|
|
-- on target_node:
|
|
-- result, error <- isFluencePeer()
|
|
--
|
|
-- Returns:
|
|
-- `true, nil` if `target_node` is identified as official Fluence Labs peer
|
|
-- `false, nil` otherwise
|
|
--
|
|
-- Errors:
|
|
-- if get_host_certs_from failed, `nil, error_msg` is returned
|
|
func isFluencePeer() -> ?bool, ?Error:
|
|
fluence_root_peer_id = "12D3KooWNbZKaPWRZ8wgjGvrxdJFz9Fq5uVwkR6ERV1f74HhPdyB"
|
|
label_peer_id = "12D3KooWM45u7AQxsb4MuQJNYT3NWHHMLU7JTbBV66RTfF3KSzdR"
|
|
|
|
result: ?bool
|
|
error: *Error
|
|
-- get all certs issued by `label_peer_id` to current host
|
|
certs_result <- get_host_certs_from(label_peer_id)
|
|
|
|
if certs_result.success:
|
|
for cert <- certs_result.certificates:
|
|
len <- TrustOp.array_length(cert.chain)
|
|
if len == 3:
|
|
if cert.chain!0.issued_for == fluence_root_peer_id:
|
|
if cert.chain!1.issued_for == label_peer_id:
|
|
result <<- true
|
|
if result == nil:
|
|
result <<- false
|
|
else:
|
|
error <<- certs_result.error
|
|
<- result, error
|