fix bug get_all_certs_from, update example (#44)

This commit is contained in:
Aleksey Proshutisnkiy 2022-07-06 14:24:33 +04:00 committed by GitHub
parent 7fbaaaa8f9
commit b9a996eba8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16226 additions and 1492 deletions

9337
aqua/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"*.aqua"
],
"dependencies": {
"@fluencelabs/aqua-lib": "^0.3.4"
"@fluencelabs/aqua-lib": "^0.5.2"
},
"scripts": {
"generate-aqua": "../service/build.sh",
@ -31,6 +31,6 @@
},
"homepage": "https://github.com/fluencelabs/trust-graph#readme",
"devDependencies": {
"@fluencelabs/aqua": "^0.5.2-257"
"@fluencelabs/aqua": "^0.7.4-322"
}
}

View File

@ -11,8 +11,9 @@ service CertOp("op"):
service TrustedComputation("op"):
identity(s: u64) -> u64
func trusted_computation(node: string) -> ?u64:
func trusted_computation(node: string) -> ?u64, ?string:
result: ?u64
error: ?string
-- on our trusted relay
on HOST_PEER_ID:
-- get all certificates issued for given node by our client's peer id
@ -20,8 +21,11 @@ func trusted_computation(node: string) -> ?u64:
if certs_result.success:
len <- CertOp.array_length(certs_result.certificates)
-- if there is any certificate node is trusted and computation is possible
if len != 0:
on node:
result <- TrustedComputation.identity(5)
<- result
if len != 0:
on node:
result <- TrustedComputation.identity(5)
else:
error <<- "there is no certs for this peer"
else:
error <<- certs_result.error
<- result, error

View File

@ -1,5 +1,6 @@
module Export
import add_root_trust, add_trust, revoke from "@fluencelabs/trust-graph/trust-graph-api.aqua"
export add_root_trust, add_trust, revoke
export add_root_trust, add_trust, revoke, timestamp_sec
import Peer from "@fluencelabs/aqua-lib/builtin.aqua"
alias PeerId: string

View File

@ -42,7 +42,7 @@ let local: Node[] = [
async function revoke_all(relay: string, revoked_by: string) {
for (var node of local) {
let error = await tg.revoke(relay, revoked_by, node.peerId);
if (error === null) {
if (error !== null) {
console.log(error)
}
}
@ -51,7 +51,7 @@ async function add_root(relay: string, peer_id: string) {
let current_time = await tg.timestamp_sec();
let far_future = current_time + 9999999;
let error = await tg.add_root_trust(relay, peer_id, 2, far_future);
if (error === null) {
if (error !== null) {
console.log(error)
}
}
@ -75,12 +75,12 @@ async function revoke_checked(relay: string, revoked_by: string, revoked_peer_id
}
async function exec_trusted_computation(node: string) {
let result = await trusted_computation(node)
let [result, error] = await trusted_computation(node)
if (result !== null) {
console.log("📗 Trusted computation on node %s successful, result is %s", node, result)
} else {
console.log("📕 Trusted computation on node %s failed", node)
console.log("📕 Trusted computation on node %s failed, error:", node, error)
}
}

8302
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,14 +13,14 @@
"author": "Fluence Labs",
"license": "MIT",
"dependencies": {
"@fluencelabs/aqua": "^0.5.2-257",
"@fluencelabs/aqua-lib": "^0.3.4",
"@fluencelabs/fluence": "^0.18.0",
"@fluencelabs/aqua-lib": "^0.5.2",
"@fluencelabs/fluence": "^0.23.0",
"@fluencelabs/fluence-network-environment": "^1.0.10",
"@fluencelabs/trust-graph": "file:../aqua",
"@fluencelabs/trust-graph": "3.0.2",
"bs58": "^4.0.1"
},
"devDependencies": {
"typescript": "^4.5.2"
"typescript": "^4.5.2",
"@fluencelabs/aqua": "^0.7.4-325"
}
}

View File

@ -98,7 +98,7 @@ fn get_all_certs(issued_for: String, timestamp_sec: u64) -> AllCertsResult {
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)?;
check_timestamp_tetraplets(&cp, 2)?;
get_certs_from(tg, issued_for, issuer, timestamp_sec)
})
.into()

View File

@ -887,4 +887,40 @@ mod service_tests {
assert_eq!(*trust, trusts[i].trust);
}
}
#[test]
fn test_get_all_cert_from() {
let mut trust_graph = ServiceInterface::new();
clear_env();
let (key_pairs, trusts) =
generate_trust_chain_with_len(&mut trust_graph, 5, HashMap::new());
let cur_time = current_time();
let root_peer_id = key_pairs[0].get_peer_id();
set_root_peer_id(&mut trust_graph, root_peer_id, 10);
for auth in trusts.iter() {
add_trust_checked(&mut trust_graph, auth.trust.clone(), auth.issuer, cur_time);
}
let cp = get_correct_timestamp_cp_with_host_id(
2,
key_pairs.last().unwrap().get_peer_id().to_base58(),
);
let certs = trust_graph.get_all_certs_from_cp(
key_pairs[4].get_peer_id().to_base58(),
key_pairs[3].get_peer_id().to_base58(),
cur_time,
cp,
);
assert!(certs.success, "{}", certs.error);
let certs = certs.certificates;
assert_eq!(certs.len(), 1);
assert_eq!(certs[0].chain.len(), 5);
for (i, trust) in certs[0].chain.iter().enumerate() {
assert_eq!(*trust, trusts[i].trust);
}
}
}