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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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())
}
}