hc_deepkey_types/
key_anchor.rs1use hdi::prelude::*;
2
3pub type KeyBytes = [u8; 32];
4
5#[hdk_entry_helper]
11#[derive(Clone, PartialEq)]
12pub struct KeyAnchor {
13 pub bytes: KeyBytes,
14}
15
16impl KeyAnchor {
17 pub fn new(bytes: KeyBytes) -> Self {
18 KeyAnchor { bytes }
19 }
20}
21
22impl TryFrom<AgentPubKey> for KeyAnchor {
23 type Error = WasmError;
24
25 fn try_from(input: AgentPubKey) -> Result<Self, Self::Error> {
26 Ok(Self {
27 bytes: input.get_raw_32().try_into().map_err(|e| {
28 wasm_error!(WasmErrorInner::Guest(format!(
29 "Failed AgentPubKey to [u8;32] conversion: {:?}",
30 e
31 )))
32 })?,
33 })
34 }
35}
36
37impl TryFrom<&AgentPubKey> for KeyAnchor {
38 type Error = WasmError;
39
40 fn try_from(input: &AgentPubKey) -> Result<Self, Self::Error> {
41 input.to_owned().try_into()
42 }
43}