Module hdi::prelude

source ·
Expand description

Exports common types and functions according to the Rust prelude pattern.

Re-exports

pub use crate::chain::must_get_agent_activity;
pub use crate::ed25519::verify_signature;
pub use crate::ed25519::verify_signature_raw;
pub use crate::entry::must_get_action;
pub use crate::entry::must_get_entry;
pub use crate::entry::must_get_valid_record;
pub use crate::info::dna_info;
pub use crate::info::zome_info;
pub use crate::link::LinkTypeFilterExt;
pub use crate::map_extern;
pub use crate::map_extern;
pub use crate::map_extern::ExternResult;
pub use crate::x_salsa20_poly1305::x_25519_x_salsa20_poly1305_decrypt;
pub use crate::x_salsa20_poly1305::x_salsa20_poly1305_decrypt;
pub use hdk_derive;
pub use holo_hash;
pub use crate::hash::*;
pub use crate::hdi::*;
pub use crate::op::*;

Modules

Capability Grants and Claims
Source Chain Filtering
Countersigned entries involve preflights between many agents to build a session that is part of the entry.
Re-exported dependencies
An Entry is a unit of data in a Holochain Source Chain.
Types related to the genesis process whereby a user commits their initial records and validates them to the best of their ability. Full validation may not be possible if network access is required, so they perform a “self-check” (as in “check yourself before you wreck yourself”) before joining to ensure that they can catch any problems they can before being subject to the scrutiny of their peers and facing possible rejection.
Information about the current zome and dna.
Dht Operations
Rate limiting data types
Defines a Record, the basic unit of Holochain data.
Wrapper types to enable optimized handling of &[u8] and Vec<u8>.
Signature for authenticity of data
A microsecond-precision UTC timestamp for use in Holochain’s actions.
Types related to the debug host function
A Zome is a module of app-defined code which can be run by Holochain. A group of Zomes are composed to form a DnaDef.

Macros

Implements conversion traits to allow a struct to be handled as an app entry. If you have some need to implement custom serialization logic or metadata injection you can do so by implementing these traits manually instead.
Serialization for fixed arrays is generally not available in a way that can be derived. Being able to wrap fixed size arrays is important e.g. for crypto safety etc. so this is a simple way to implement serialization so that we can send these types between the host/guest.
unidiomatic way to derive default trait implementations of TryFrom in/out of SerializedBytes
Cryptographic secrets are fiddly at the best of times.
A simple macro to wrap return_err_ptr in an analogy to the native rust ?.
Helper macro for returning an error from a WASM.

Structs

Action for an agent validation package, used to determine whether an agent is allowed to participate in this DNA
Newtype for the bytes comprising an App entry
Information about a class of Entries provided by the DNA
Identifier for an entry definition. This may be removed.
An ordered set based on a B-Tree.
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.
A CapSecret is used by a caller to prove to a callee access to a committed CapGrant.
Filter source chain items. Starting from some chain position given as an ActionHash the chain is walked backwards to genesis. The filter can stop early by specifying the number of chain items to take and / or an ActionHash to consume until.
When migrating to a new version of a DNA, this action is committed to the old chain to declare the migration path taken. Currently unused
Every countersigning agent must sign against their chain state. The chain must be frozen until each agent decides to sign or exit the session.
All the data required for a countersigning session.
Every countersigning session must complete a full set of actions between the start and end times to be valid.
A action which “speaks” Entry content into being. The same content can be referenced by multiple such actions.
Base data for Create actions.
Declares that a metadata Link should be made between two EntryHashes
Declare that a previously published Action should be nullified and considered deleted.
Placeholder for future when we want to have deletes on actions Not currently in use.
Declares that a previously made Link should be nullified and considered removed.
The Dna Action is always the first action in a source chain
Information about the current DNA.
All definitions for all entry types in an integrity zome.
A newtype for a collection of EntryHashes, needed for some wasm return types.
Combination of the three main rate limiting data types, for convenience
The output of ephemeral signing. The private key for this public key has been discarded by this point. The signatures match the public key provided but cannot be reproduced or forged because the private key no longer exists. The signatures match the input items positionally in the vector, it is up to the caller to reconstruct/align/zip them back together.
A single function name.
Data passed into the genesis_self_check callback for verifying the initial chain entries
256 Bit generic hash.
512 Bit generic hash.
A hash set implemented as a HashMap where the value is ().
A HoloHash contains a vector of 36 bytes representing a 32-byte blake2b hash plus 4 bytes representing a DHT location. It also contains a zero-sized type which specifies what it is a hash of.
Represents some piece of content along with its hash representation, so that hashes need not be calculated multiple times. Provides an easy constructor which consumes the content.
A action which declares that all zome init functions have successfully completed, and the chain is ready for commits. Contains no explicit data.
Opaque tag for the link applied at the app layer, used to differentiate between different semantics and validation rules for different links
Zome input for must_get_action.
Input to the must_get_agent_activity call.
Zome input for must_get_entry.
Zome input for must_get_valid_record.
When migrating to a new version of a DNA, this action is committed to the new chain to declare the migration path taken. Currently unused
Every preflight request can have optional arbitrary bytes that can be agreed to.
The same PreflightRequest is sent to every agent. Each agent signs this data as part of their PreflightResponse. Every preflight must be identical and signed by every agent for a session to be valid.
Every agent must send back a preflight response. All the preflight response data is signed by each agent and included in the session data.
Combination of two rate limiting data types, for convenience
a chain record containing the signed action along with the entry if the action type has one.
Registers a new Action on an agent source chain. This is the act of creating any Action and publishing it to the DHT.
Registers a link between two Entrys. This is the act of creating a Action::CreateLink and publishing it to the DHT. The authority is the entry authority for the base Entry.
Registers a deletion of an instance of an Entry in the DHT. This is the act of creating a Action::Delete and publishing it to the DHT.
Deletes a link between two Entrys. This is the act of creating a Action::DeleteLink and publishing it to the DHT. The delete always references a specific Action::CreateLink.
Registers an update from an instance of an Entry in the DHT. This is the act of creating a Action::Update and publishing it to the DHT. Note that the Action::Update stores an new instance of an Entry and registers it as an update to the original Entry. This operation is only concerned with registering the update.
The number of validations required for an entry to be considered published.
Agents can have a role specific to each countersigning session. The role is app defined and opaque to the subconscious.
A type with the zome that it is defined in.
zome types that are in scope for the calling zome.
The set of EntryDefIndex and LinkTypes in scope for the calling zome.
A Canonical Serialized Bytes representation for data If you have a data structure that needs a canonical byte representation use this Always round-trip through SerializedBytes via. a single TryFrom implementation. This ensures that the internal bytes of SerializedBytes are indeed canonical. The corrolary is that if bytes are NOT wrapped in SerializedBytes we can assume they are NOT canonical. Typically we need a canonical serialization when data is to be handled at the byte level by independently implemented and maintained systems.
The raw bytes of a signature.
Any content that has been hashed and signed.
Stores a new Entry in the DHT. This is the act of creating a either a Action::Create or a Action::Update and publishing it to the DHT. These actions create a new instance of an Entry.
Stores a new Record in the DHT. This is the act of creating a new Action and publishing it to the DHT. Note that not all Actions contain an Entry.
A microsecond-precision UTC timestamp for use in Holochain’s actions.
Representation of message to be logged via the debug host function
UnsafeBytes the only way to implement a custom round trip through bytes for SerializedBytes It is intended to be an internal implementation in TryFrom implementations The assumption is that any code using UnsafeBytes is NOT valid messagepack data This allows us to enforce that all data round-tripping through SerializedBytes is via TryFrom and also allow for custom non-messagepack canonical representations of data types.
A action which specifies that some new Entry content is intended to be an update to some old Entry.
Placeholder for future when we want to have updates on actions Not currently in use.
Base data for Update actions.
Mirror struct for Sign that includes a signature to verify against a key and data.
Wraps a WasmErrorInner with a file and line number. The easiest way to generate this is with the wasm_error! macro that will insert the correct file/line and can create strings by forwarding args to the format! macro.
Data that can be encrypted with secretbox.
Key refs represent shared secrets stored in the keystore. They can either be user-specified, or auto-generated at time of secret creation, or ingestion.
The entry for the ZomeCall capability grant. This data is committed to the callee’s source chain as a private entry. The remote calling agent must provide a secret and we source their pubkey from the active network connection. This must match the strictness of the CapAccess.
The index into the ZomeIndex vec.
this id is an internal reference, which also serves as a canonical ordering for zome initialization. The value should be auto-generated from the Zome Bundle def
The properties of the current dna/zome being called.
ZomeName as a String.
A key to the ScopedZomeTypes container.

Enums

Action contains variants for each type of action.
Enum to mirror Action for all the shared data required to build session actions. Does NOT hold any agent specific information.
A unit enum which just maps onto the different Action variants, without containing any extra data
Represents access requirements for capability grants.
Represents a potentially valid access grant to a zome call. Zome call response will be Unauthorized without a valid grant.
Specify which Actions to allow through this filter.
Errors related to the secure primitive macro.
Structure holding the entry portion of a chain record.
Either a Action::Create or a Action::Update. These actions both create a new instance of an Entry.
Errors involving app entry creation
Allows Actions which reference Entries to know what type of Entry it is referencing. Useful for examining Actions without needing to fetch the corresponding Entries.
A collection of zome/function pairs
Input to holochain hash function.
Output from the holochain hashing host function.
Maps directly to the tracing Levels but here to define the interface. See https://docs.rs/tracing-core/0.1.17/tracing_core/struct.Level.html
Filter on a set of LinkTypes.
These are the operations that can be applied to Holochain data. Every Action produces a set of operations. These operations are each sent to an authority for validation.
Data specific to the Op::RegisterAgentActivity operation.
Data specific to the Op::RegisterDelete operation.
Data specific to the Op::StoreEntry operation.
Data specific to the Op::StoreRecord operation.
A convenience type for validation Ops.
Data specific to the Op::RegisterUpdate operation.
A preflight request can be accepted, or invalid, or valid but the local agent cannot accept it.
Represents the different ways the entry_address reference within an action can be intepreted
The level of validation package required by an entry.
Errors related to the secure primitive macro.
Unresolved dependencies that are either a set of hashes or an agent activity query.
Enum of all possible ERROR states that wasm can encounter.
Input to the weigh callback. Includes an “unweighed” action, and Entry if applicable.

Constants

The number of bits we want for a comfy secret.
The number of bytes we want for a comfy secret.
Entries larger than this number of bytes cannot be created
8 seems like a reasonable limit of agents to countersign.
Need at least two to countersign.
One million
Any action with a action_seq less than this value is part of a record created during genesis. Anything with this seq or higher was created after genesis.
The timestamps on actions for a session use this offset relative to the session start time. This makes it easier for agents to accept a preflight request with actions that are after their current chain top, after network latency.
Maximum time in the future the session start can be in the opinion of the participating agent. As the action will be SESSION_ACTION_TIME_OFFSET after the session start we include that here.
Ed25519 signatures are always the same length, 64 bytes.

Traits

A trait to unify the “inner” parts of an Action, i.e. the structs inside the Action enum’s variants. This trait is used for the “unweighed” version of each struct, i.e. the version with weight information erased.
A trait to unify the “inner” parts of an Action, i.e. the structs inside the Action enum’s variants. This trait is used for the “weighed” version of each struct, i.e. the version without weight information erased.
A data structure that can be deserialized from any data format supported by Serde.
Trait for binding static EntryDef property access for a type. This trait maps a type to its corresponding EntryDef property at compile time.
Helper trait for deserializing Entrys to the correct type.
Anything which has an owned HoloHashOf.
A helper trait for finding the app defined link type from a ZomeIndex and LinkType.
A data structure that can be serialized into any data format supported by Serde.
Simple and safe type conversions that may fail in a controlled way under some circumstances. It is the reciprocal of TryInto.
An attempted conversion that consumes self, which may or may not be expensive.
Helper trait for types that are internally represented as u8 but need to be used as indicies into containers.
A utility trait for associating a data enum with a unit enum that has the same variants.

Functions

Helpful pattern for debug formatting many bytes. If the size is > 32 bytes, only the first 8 and last 8 bytes will be displayed.
Receive arguments from the host. The guest sets the type O that the host needs to match. If deserialization fails then a GuestPtr to a WasmError::Deserialize is returned. The guest should immediately return an Err back to the host. The WasmError::Deserialize enum contains the bytes that failed to deserialize so the host can unambiguously provide debug information.
Given an extern that we expect the host to provide:
Given a pointer and a length, return a u64 merged GuestPtrLen. Works via a simple bitwise shift to move the pointer to high bits then OR the length into the low bits.
Convert a WasmError to a GuestPtrLen as best we can. This is not necessarily straightforward as the serialization process can error recursively. In the worst case we can’t even serialize an enum variant, in which case we panic. The casts from usize to u32 are safe as long as the guest code is compiled for wasm32-unknown-unknown target.
Convert any serializable value into a GuestPtr that can be returned to the host. The host is expected to know how to consume and deserialize it.
Given a merged GuestPtrLen, split out a u32 pointer and length. Performs the inverse of merge_u64. Takes the low u32 bits as the length then shifts the 32 high bits down and takes those as the pointer.

Type Definitions

The hash of an action
An Agent public signing key. Not really a hash, more of an “identity hash”.
The hash of anything referrable in the DHT. This is a composite of either an EntryHash or a ActionHash
The hash of anything linkable.
The data type written to the source chain to denote a capability claim
The data type written to the source chain when explicitly granting a capability. NB: this is not simply CapGrant, because the CapGrant::ChainAuthor grant is already implied by Entry::Agent, so that should not be committed to a chain. This is a type alias because if we add other capability types in the future, we may want to include them
A fixed size array of bytes that a secret must be.
Alias for a list of agents and their roles.
The hash of a DnaDef
The hash of an Entry.
An Entry paired with its EntryHash
The hash of some external data that can’t or doesn’t exist on the DHT.
a single zome/function pair
A WasmSize that points to a position in wasm linear memory that the host and guest are sharing to communicate across function calls.
Enough bits to fit a pointer and length into so we can return it. The externs defined as “C” don’t support multiple return values (unlike wasm). The native Rust support for wasm externs is not stable at the time of writing.
A WasmSize integer that represents the size of bytes to read/write to memory.
App-specific payload for proving membership in the membrane of the app
The amount that a bucket is “filled”
A bucket ID, for rate limiting
The normalized total size of this action, for rate limiting
The weight of this action, for rate limiting
An EntryDefIndex within the scope of the zome where it’s defined.
A LinkType within the scope of the zome where it’s defined.
The hashed action and the signature that signed it
Something like usize for wasm. Wasm has a memory limit of 4GB so offsets and lengths fit in u32.

Attribute Macros

Declares the integrity zome’s entry types.
Helper for entry data types.
Implements all the required types needed for a LinkTypes enum.

Derive Macros