1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use ;
use serde_json;
use ;
/// Generates a [Capability] struct representing permission to
/// publish a sphere.
///
/// ```
/// use noosphere_ns::utils::generate_capability;
/// use noosphere_core::authority::{SphereAction, SphereReference};
/// use ucan::capability::{Capability, Resource, With};
///
/// let identity = "did:key:z6MkoE19WHXJzpLqkxbGP7uXdJX38sWZNUWwyjcuCmjhPpUP";
/// let expected_capability = Capability {
/// with: With::Resource {
/// kind: Resource::Scoped(SphereReference {
/// did: identity.to_owned(),
/// }),
/// },
/// can: SphereAction::Publish,
/// };
/// assert_eq!(generate_capability(identity), expected_capability);
/// ```
/// Generates a UCAN `"fct"` struct for the NS network, representing
/// the resolved sphere's revision as a [cid::Cid].
///
/// ```
/// use noosphere_ns::utils::generate_fact;
/// use noosphere_storage::encoding::derive_cid;
/// use libipld_cbor::DagCborCodec;
/// use serde_json::json;
///
/// let address = "bafy2bzaced25m65oooyocdin7uyehm7u6eak3iauyxbxxvoos6atwe7vvmv46";
/// assert_eq!(generate_fact(address), json!({ "address": address }));
/// ```