hc_deepkey_sdk/
lib.rs

1pub use hc_deepkey_types::*;
2
3pub use hdk;
4
5use hdk::prelude::{holo_hash::DnaHash, *};
6use serde_bytes::ByteArray;
7
8#[hdk_entry_helper]
9#[derive(Clone)]
10pub enum KeyState {
11    NotFound,
12    Invalid(Option<SignedActionHashed>),
13    Valid(SignedActionHashed),
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct KeyRevocationInput {
18    pub prior_key_registration: ActionHash,
19    pub revocation_authorization: Vec<(u8, ByteArray<64>)>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct DerivationDetails {
24    pub app_index: u32,
25    pub key_index: u32,
26}
27
28impl DerivationDetails {
29    pub fn to_derivation_path(&self) -> Vec<u32> {
30        vec![self.app_index, self.key_index]
31    }
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct AppBindingInput {
36    pub app_name: String,
37    pub installed_app_id: String,
38    pub dna_hashes: Vec<DnaHash>,
39    #[serde(default)]
40    pub metadata: MetaData,
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
44pub struct DerivationDetailsInput {
45    pub app_index: u32,
46    pub key_index: u32,
47    #[serde(with = "serde_bytes")]
48    pub derivation_seed: Vec<u8>,
49    #[serde(with = "serde_bytes")]
50    pub derivation_bytes: Vec<u8>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct CreateKeyInput {
55    pub key_generation: KeyGeneration,
56    pub app_binding: AppBindingInput,
57    pub derivation_details: Option<DerivationDetailsInput>,
58    #[serde(default)]
59    pub create_only: bool,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct UpdateKeyInput {
64    pub key_revocation: KeyRevocation,
65    pub key_generation: KeyGeneration,
66    pub derivation_details: Option<DerivationDetailsInput>,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct RevokeKeyInput {
71    pub key_revocation: KeyRevocation,
72}
73
74impl TryFrom<KeyRevocationInput> for KeyRevocation {
75    type Error = WasmError;
76
77    fn try_from(input: KeyRevocationInput) -> ExternResult<Self> {
78        Ok(Self {
79            prior_key_registration: input.prior_key_registration,
80            revocation_authorization: input
81                .revocation_authorization
82                .into_iter()
83                .map(|(index, signature)| (index, Signature::from(signature.into_array())))
84                .collect(),
85        })
86    }
87}
88
89#[derive(Serialize, Deserialize, Clone, Debug)]
90pub struct AuthoritySpecInput {
91    pub sigs_required: u8,
92    pub authorized_signers: Vec<ByteArray<32>>,
93}
94
95impl From<AuthoritySpecInput> for AuthoritySpec {
96    fn from(input: AuthoritySpecInput) -> Self {
97        Self {
98            sigs_required: input.sigs_required,
99            authorized_signers: input
100                .authorized_signers
101                .iter()
102                .map(|key| key.into_array())
103                .collect(),
104        }
105    }
106}
107
108#[derive(Serialize, Deserialize, Clone, Debug)]
109pub struct UpdateChangeRuleInput {
110    pub authority_spec: AuthoritySpecInput,
111    pub authorizations: Option<Vec<Authorization>>,
112}