TrustGraph::Holochain is a Rust library, intended to allow for Holochain developers to easily use the Trust Graph protocol in their Happs.
TrustGraph::Holochain is a very young codebase; expect limited functionality, and don’t use it in production just yet -- but do come collaborate and play as we develop it!
In your Cargo.toml
:
trust_atom = {git = "https://github.com/trustgraph/trustgraph-holochain.git", rev="v1.2.3", package = "trust_atom"}
Replace v1.2.3
with the tag corresponding to the version you want. See the list of available tags.
HDK version correspondence:
v0.0.1
- v0.0.6
works with hdk
version 0.0.116
v0.0.7
works with hdk
version 0.0.125
v0.0.8
(pulled)v0.0.9
works with hdk
version 0.0.131
v0.1.0
works with hdk
version 0.1.1
and hdi
version 0.2.1
pub struct TrustAtomInput {
pub target: AnyLinkableHash,
pub content: Option<String>,
pub value: Option<String>,
pub extra: Option<BTreeMap<String, String>>,
}
#[hdk_extern]
pub fn create_trust_atom(input: TrustAtomInput) -> ExternResult<TrustAtom> {
// ...
}
pub struct QueryInput {
pub source: Option<AnyLinkableHash>,
pub target: Option<AnyLinkableHash>,
pub content_full: Option<String>,
pub content_starts_with: Option<String>,
pub value_starts_with: Option<String>,
}
#[hdk_extern]
pub fn query(input: QueryInput) -> ExternResult<Vec<TrustAtom>> {
// ...
}
Client-facing representation of a Trust Atom (this is what is returned to client from a query
)
pub struct TrustAtom {
pub source_hash: AnyLinkableHash,
pub target_hash: AnyLinkableHash,
pub content: Option<String>,
pub value: Option<String>,
pub extra: Option<BTreeMap<String, String>>,
}
For more detailed usage, see also the tests: https://github.com/trustgraph/trustgraph-holochain/blob/main/zomes/trust_atom/tests/trust_atom_tests.rs
We encode TrustAtoms as links, with the following components:
base
== TrustAtom source
- creating agent (AgentPubKey
)target
== TrustAtom target
- entity being rated/reviewed/etc - AnyLinkableHash
tag
* (max 999 bytes) - formatted as UTF-8 string[0xC5][0xA6]
(which together comprise the unicode character Ŧ
) (required)[0x21][0x92]
(unicode →
) means: HC target = TA target[0x21][0xA9]
(unicode ↩
) means: HC target = TA sourcecontent
- semantic info (eg sushi) - max 900 bytes[0x00]
value
- rating ( "-0.999999999"
to "0.999999999"
) - max 12 chars[0x00]
[0x00]
EntryHash
if additional metadata is needed:
BTreeMap<String, String>
EntryHash
(eg uhCEkto7…
) for debugging purposes, not raw bytes*This format is designed to allow us to encode trust atoms as Holochain links, and search them by their tags. Holochain can search for all links starting with a given set of bytes (characters).
Ŧ→[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF
Ŧ↩[0x00]sushi[0x00]0.999999999[0x00]892412523[0x00]uhCEk…UFnFF
Ŧ→[0x00]content[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc
Ŧ↩[0x00]content[0x00]0.800000000[0x00]087423432[0x00]uhCEk…qS5wc
Ŧ→[0x00]spam[0x00]-0.999999999[0x00]328425615[0x00]uhCEk…VaaDd
Ŧ→[0x00]block[0x00]-0.999999999[0x00]837592944[0x00]uhCEk…VaaDd
👤 Harlan T Wood (https://github.com/harlantwood) 👤 Zeek (https://github.com/dauphin3)
Contributions, issues and feature requests are welcome!
Report a Bug · Request a Feature · Ask a Question
Give a ⭐️ if you like the project!
If you're new to holochain dev, start here: https://developer.holochain.org/quick-start. Then, from a terminal in the root of this repo:
nix develop
Then within nix shell:
bin/run test # rust tests
bin/run test_watch # rust tests with watch
bin/run clippy # rust linter
bin/run clippy_watch # rust linter with watch
bin/run clean # reset to clean repo state; removes all gitignored files
Or to run all checks:
bin/run checks
When you have commits that you are ready to push, to run checks and push only if checks are all green:
bin/run shipit
Copyright © 2022 Harlan T Wood (https://github.com/harlantwood).
This project is Apache-2.0 licensed.