mirror of
https://github.com/fluencelabs/trust-graph-test
synced 2025-04-24 19:52:27 +00:00
:
This commit is contained in:
parent
c999fbc0ef
commit
e50b247417
@ -16,3 +16,20 @@ func verify_trust(node: string, trust: Trust, issuer_peer_id: string) -> VerifyT
|
||||
timestamp_sec <- Peer.timestamp_sec()
|
||||
result <- TrustGraph.verify_trust(trust, issuer_peer_id, timestamp_sec)
|
||||
<- result
|
||||
|
||||
func add_trust(node: string, trust: Trust, issuer_peer_id: string) -> AddTrustResult:
|
||||
on node:
|
||||
timestamp_sec <- Peer.timestamp_sec()
|
||||
result <- TrustGraph.add_trust(trust, issuer_peer_id, timestamp_sec)
|
||||
<- result
|
||||
|
||||
func add_root(node: string, peer_id: string, weight: u32) -> AddRootResult:
|
||||
on node:
|
||||
result <- TrustGraph.add_root(peer_id, weight)
|
||||
<- result
|
||||
|
||||
func get_weight(node: string, peer_id: string) -> WeightResult:
|
||||
on node:
|
||||
timestamp_sec <- Peer.timestamp_sec()
|
||||
result <- TrustGraph.get_weight(peer_id, timestamp_sec)
|
||||
<- result
|
||||
|
@ -1,3 +1,3 @@
|
||||
import get_trust_metadata, issue_trust, verify_trust from "../../aqua/trust-graph-api.aqua"
|
||||
import get_trust_metadata, issue_trust, verify_trust, add_trust, add_root, get_weight from "../../aqua/trust-graph-api.aqua"
|
||||
|
||||
export get_trust_metadata, issue_trust, verify_trust
|
||||
export get_trust_metadata, issue_trust, verify_trust, add_trust, add_root, get_weight
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { get_trust_metadata, issue_trust, verify_trust } from "./generated/export";
|
||||
import { get_trust_metadata, issue_trust, verify_trust, add_trust, add_root, get_weight } from "./generated/export";
|
||||
import { Fluence, KeyPair } from "@fluencelabs/fluence";
|
||||
import { Node } from "@fluencelabs/fluence-network-environment";
|
||||
const bs58 = require('bs58');
|
||||
@ -33,22 +33,35 @@ let local: Node[] = [
|
||||
];
|
||||
|
||||
async function main(environment: Node[]) {
|
||||
await Fluence.start({ connectTo: environment[0] });
|
||||
let builtins_keypair = await KeyPair.fromBytes(bs58.decode("5CGiJio6m76GxJ2wLj46PzSu6V7SRa5agv6meR3SJBKtvTgethRCmgBJKXWDSpSEBpgNUPd7Re5cZjF8mWW4kBfs"));
|
||||
await Fluence.start({ connectTo: environment[0], KeyPair: builtins_keypair});
|
||||
console.log(
|
||||
"📗 created a fluence peer %s with relay %s",
|
||||
Fluence.getStatus().peerId,
|
||||
Fluence.getStatus().relayPeerId
|
||||
);
|
||||
|
||||
|
||||
let trust_metadata = await get_trust_metadata(local[0].peerId, local[1].peerId, 99999999999, 0);
|
||||
const issuer_kp = await KeyPair.fromBytes(bs58.decode("29Apzfedhw2Jxh94Jj4rNSmavQ1TkNe8ALYRA7bMegobwp423aLrURxLk32WtXgXHDqoSz7GAT9fQfoMhVd1e5Ww"));
|
||||
console.log("Issuer peer id: %", issuer_kp.Libp2pPeerId.toB58String());
|
||||
|
||||
let add_root_result = await add_root(local[0].peerId, local[0].peerId, 2);
|
||||
console.log("Add root weight result: %s", add_root_result);
|
||||
|
||||
let trust_metadata = await get_trust_metadata(local[0].peerId, local[0].peerId, 99999999999, 0);
|
||||
const signed_metadata = await issuer_kp.Libp2pPeerId.privKey.sign(Uint8Array.from(trust_metadata.result));
|
||||
let trust = await issue_trust(local[0].peerId, local[1].peerId, 99999999999, 0, Array.from(signed_metadata));
|
||||
console.log("Trust %s", trust.trust);
|
||||
let result = await verify_trust(local[0].peerId, trust.trust, local[0].peerId);
|
||||
console.log("Verify trust result: %s", result);
|
||||
|
||||
let root_trust = await issue_trust(local[0].peerId, local[0].peerId, 99999999999, 0, Array.from(signed_metadata));
|
||||
console.log("Root trust %s", root_trust.trust);
|
||||
|
||||
let result = await verify_trust(local[0].peerId, root_trust.trust, local[0].peerId);
|
||||
console.log("Verify root trust result: %s", result);
|
||||
|
||||
let result_add = await add_trust(local[0].peerId, root_trust.trust, local[0].peerId);
|
||||
console.log("Add root trust result: %s", result_add);
|
||||
|
||||
let root_weight_result = await get_weight(local[0].peerId, local[0].peerId);
|
||||
console.log("Root weight: %s", root_weight_result);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,15 +39,16 @@ fn get_all_certs(issued_for: String, timestamp_sec: u64) -> AllCertsResult {
|
||||
|
||||
#[marine]
|
||||
/// could add only a host of a trust graph service
|
||||
// TODO: rename to add_root_weight_factor
|
||||
fn add_root(peer_id: String, weight: u32) -> AddRootResult {
|
||||
let call_parameters: CallParameters = marine_rs_sdk::get_call_parameters();
|
||||
let init_peer_id = call_parameters.init_peer_id.clone();
|
||||
if call_parameters.host_id == init_peer_id {
|
||||
if call_parameters.service_creator_peer_id == init_peer_id {
|
||||
add_root_impl(peer_id, weight).into()
|
||||
} else {
|
||||
return AddRootResult {
|
||||
success: false,
|
||||
error: "Root could add only a host of trust graph service".to_string(),
|
||||
error: "Root could add only by trust graph service owner".to_string(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user