trust-graph/aqua/labelling.aqua

45 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

aqua Labelling declares *
export isFluencePeer
2022-02-04 15:45:37 +00:00
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
2022-02-04 15:45:37 +00:00
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 == []:
2022-02-04 15:45:37 +00:00
result <<- false
else:
error <<- certs_result.error
2022-02-04 15:45:37 +00:00
<- result, error