use crate as zt;
use crate::cell::CellId;
use crate::zome::FunctionName;
use crate::zome::ZomeName;
use holo_hash::AgentPubKey;
pub use holochain_integrity_types::zome_io::*;
use holochain_serialized_bytes::prelude::*;
macro_rules! wasm_io_types {
( $( fn $f:ident ( $in_arg:ty ) -> $out_arg:ty; )* ) => {
pub trait HostFnApiT {
$(
fn $f(&self, _: $in_arg) -> Result<$out_arg, HostFnApiError>;
)*
}
}
}
wasm_io_types! {
fn accept_countersigning_preflight_request(zt::countersigning::PreflightRequest) -> zt::countersigning::PreflightRequestAcceptance;
fn agent_info (()) -> zt::info::AgentInfo;
fn dna_info (()) -> zt::info::DnaInfo;
fn call_info (()) -> zt::info::CallInfo;
fn call (Vec<zt::call::Call>) -> Vec<zt::ZomeCallResponse>;
fn capability_claims (()) -> ();
fn capability_grants (()) -> ();
fn capability_info (()) -> ();
fn create (zt::entry::CreateInput) -> holo_hash::ActionHash;
fn create_link (zt::link::CreateLinkInput) -> holo_hash::ActionHash;
fn create_x25519_keypair(()) -> zt::x_salsa20_poly1305::x25519::X25519PubKey;
fn trace (zt::trace::TraceMsg) -> ();
fn delete_link (zt::link::DeleteLinkInput) -> holo_hash::ActionHash;
fn delete (zt::entry::DeleteInput) -> holo_hash::ActionHash;
fn emit_signal (zt::signal::AppSignal) -> ();
fn get_agent_activity (zt::agent_activity::GetAgentActivityInput) -> zt::query::AgentActivity;
fn get_details (Vec<zt::entry::GetInput>) -> Vec<Option<zt::metadata::Details>>;
fn get_link_details (Vec<zt::link::GetLinksInput>) -> Vec<zt::link::LinkDetails>;
fn get_links (Vec<zt::link::GetLinksInput>) -> Vec<Vec<zt::link::Link>>;
fn get (Vec<zt::entry::GetInput>) -> Vec<Option<zt::record::Record>>;
fn hash (zt::hash::HashInput) -> zt::hash::HashOutput;
fn must_get_valid_record (zt::entry::MustGetValidRecordInput) -> zt::record::Record;
fn must_get_entry (zt::entry::MustGetEntryInput) -> zt::entry::EntryHashed;
fn must_get_action (zt::entry::MustGetActionInput) -> zt::SignedActionHashed;
fn must_get_agent_activity (zt::chain::MustGetAgentActivityInput) -> Vec<zt::op::RegisterAgentActivity>;
fn query (zt::query::ChainQueryFilter) -> Vec<crate::Record>;
fn random_bytes (u32) -> zt::bytes::Bytes;
fn remote_signal (zt::signal::RemoteSignal) -> ();
fn schedule (String) -> ();
fn sleep (core::time::Duration) -> ();
fn version (()) -> zt::version::ZomeApiVersion;
fn sign (zt::signature::Sign) -> zt::signature::Signature;
fn sign_ephemeral (zt::signature::SignEphemeral) -> zt::signature::EphemeralSignatures;
fn sys_time (()) -> zt::timestamp::Timestamp;
fn update (zt::entry::UpdateInput) -> holo_hash::ActionHash;
fn verify_signature (zt::signature::VerifySignature) -> bool;
fn x_salsa20_poly1305_shared_secret_create_random(
Option<zt::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef>
) -> zt::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef;
fn x_salsa20_poly1305_shared_secret_export(
zt::x_salsa20_poly1305::XSalsa20Poly1305SharedSecretExport
) -> zt::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData;
fn x_salsa20_poly1305_shared_secret_ingest(
zt::x_salsa20_poly1305::XSalsa20Poly1305SharedSecretIngest
) -> zt::x_salsa20_poly1305::key_ref::XSalsa20Poly1305KeyRef;
fn x_salsa20_poly1305_encrypt(
zt::x_salsa20_poly1305::XSalsa20Poly1305Encrypt
) -> zt::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData;
fn x_salsa20_poly1305_decrypt(
zt::x_salsa20_poly1305::XSalsa20Poly1305Decrypt
) -> Option<zt::x_salsa20_poly1305::data::XSalsa20Poly1305Data>;
fn x_25519_x_salsa20_poly1305_encrypt(zt::x_salsa20_poly1305::X25519XSalsa20Poly1305Encrypt) -> zt::x_salsa20_poly1305::encrypted_data::XSalsa20Poly1305EncryptedData;
fn x_25519_x_salsa20_poly1305_decrypt(zt::x_salsa20_poly1305::X25519XSalsa20Poly1305Decrypt) -> Option<zt::x_salsa20_poly1305::data::XSalsa20Poly1305Data>;
fn zome_info (()) -> zt::info::ZomeInfo;
}
#[derive(thiserror::Error, Debug)]
pub enum HostFnApiError {
#[error("Error from within host function implementation: {0}")]
RibosomeError(Box<dyn std::error::Error + Send + Sync>),
}
#[derive(PartialEq, Clone, Debug, serde::Serialize, serde::Deserialize)]
pub enum ZomeCallAuthorization {
Authorized,
BadSignature,
BadCapGrant,
BadNonce(String),
}
impl std::fmt::Display for ZomeCallAuthorization {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
impl ZomeCallAuthorization {
pub fn is_authorized(&self) -> bool {
matches!(self, ZomeCallAuthorization::Authorized)
}
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, SerializedBytes, PartialEq)]
pub enum ZomeCallResponse {
Ok(crate::ExternIO),
Unauthorized(
ZomeCallAuthorization,
CellId,
ZomeName,
FunctionName,
AgentPubKey,
),
NetworkError(String),
CountersigningSession(String),
}
#[derive(Clone, Copy)]
pub struct Nonce256Bits([u8; 32]);
holochain_integrity_types::secure_primitive!(Nonce256Bits, 32);
impl Nonce256Bits {
pub fn into_inner(self) -> [u8; 32] {
self.0
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ZomeCallUnsigned {
pub provenance: AgentPubKey,
pub cell_id: CellId,
pub zome_name: ZomeName,
pub fn_name: FunctionName,
pub cap_secret: Option<crate::CapSecret>,
pub payload: ExternIO,
pub nonce: Nonce256Bits,
pub expires_at: crate::Timestamp,
}
impl ZomeCallUnsigned {
pub fn data_to_sign(&self) -> Result<std::sync::Arc<[u8]>, SerializedBytesError> {
Ok(holo_hash::encode::blake2b_256(&holochain_serialized_bytes::encode(&self)?).into())
}
}