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
use super::CapSecret;
use holo_hash::*;
use holochain_serialized_bytes::prelude::*;

/// System entry to hold a capability token claim for use as a caller.
/// Stored by a claimant so they can remember what's necessary to exercise
/// this capability by sending the secret to the grantor.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, SerializedBytes)]
pub struct CapClaim {
    /// A string by which to later query for saved claims.
    /// This does not need to be unique within a source chain.
    tag: String,
    /// AgentPubKey of agent who authored the corresponding CapGrant.
    grantor: AgentPubKey,
    /// The secret needed to exercise this capability.
    /// This is the only bit sent over the wire to attempt a remote call.
    /// Note that the grantor may have revoked the corresponding grant since we received the claim
    /// so claims are only ever a 'best effort' basis.
    secret: CapSecret,
}

impl CapClaim {
    /// Constructor.
    pub fn new(tag: String, grantor: AgentPubKey, secret: CapSecret) -> Self {
        CapClaim {
            tag,
            grantor,
            secret,
        }
    }

    /// Access the secret.
    pub fn secret(&self) -> &CapSecret {
        &self.secret
    }

    /// Access the tag
    pub fn tag(&self) -> &str {
        &self.tag
    }

    /// Access the grantor
    pub fn grantor(&self) -> &AgentPubKey {
        &self.grantor
    }
}