-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3de7520
commit 8d8f182
Showing
15 changed files
with
3,457 additions
and
8 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
[workspace] | ||
members = [ | ||
"dnas/*/zomes/coordinator/*", | ||
"dnas/*/zomes/integrity/*", | ||
] | ||
resolver = "2" | ||
|
||
[profile.dev] | ||
opt-level = "z" | ||
|
||
[profile.release] | ||
opt-level = "z" | ||
|
||
[workspace] | ||
members = ["dnas/*/zomes/coordinator/*", "dnas/*/zomes/integrity/*"] | ||
resolver = "2" | ||
|
||
[workspace.dependencies] | ||
hdi = "=0.4.0-beta-dev.24" | ||
hdk = "=0.3.0-beta-dev.28" | ||
serde = "1.0" | ||
|
||
[workspace.dependencies.trusted] | ||
path = "dnas/trusted/zomes/coordinator/trusted" | ||
|
||
[workspace.dependencies.trusted_integrity] | ||
path = "dnas/trusted/zomes/integrity/trusted" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
manifest_version: "1" | ||
name: trusted | ||
integrity: | ||
network_seed: ~ | ||
properties: ~ | ||
origin_time: 1708106482076894 | ||
zomes: | ||
- name: trusted_integrity | ||
hash: ~ | ||
bundled: "../../../target/wasm32-unknown-unknown/release/trusted_integrity.wasm" | ||
dependencies: ~ | ||
dylib: ~ | ||
coordinator: | ||
zomes: | ||
- name: trusted | ||
hash: ~ | ||
bundled: "../../../target/wasm32-unknown-unknown/release/trusted.wasm" | ||
dependencies: | ||
- name: trusted_integrity | ||
dylib: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "trusted" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
name = "trusted" | ||
|
||
[dependencies] | ||
hdk = { workspace = true } | ||
|
||
serde = { workspace = true } | ||
|
||
trusted_integrity = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use hdk::prelude::*; | ||
use trusted_integrity::*; | ||
#[hdk_extern] | ||
pub fn create_gpg_key(gpg_key: GpgKey) -> ExternResult<Record> { | ||
let gpg_key_hash = create_entry(&EntryTypes::GpgKey(gpg_key.clone()))?; | ||
let record = get(gpg_key_hash.clone(), GetOptions::default())? | ||
.ok_or( | ||
wasm_error!( | ||
WasmErrorInner::Guest(String::from("Could not find the newly created GpgKey")) | ||
), | ||
)?; | ||
Ok(record) | ||
} | ||
#[hdk_extern] | ||
pub fn get_gpg_key(gpg_key_hash: ActionHash) -> ExternResult<Option<Record>> { | ||
let Some(details) = get_details(gpg_key_hash, GetOptions::default())? else { | ||
return Ok(None); | ||
}; | ||
match details { | ||
Details::Record(details) => Ok(Some(details.record)), | ||
_ => { | ||
Err( | ||
wasm_error!( | ||
WasmErrorInner::Guest(String::from("Malformed get details response")) | ||
), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
pub mod gpg_key; | ||
use hdk::prelude::*; | ||
use trusted_integrity::*; | ||
// Called the first time a zome call is made to the cell containing this zome | ||
#[hdk_extern] | ||
pub fn init(_: ()) -> ExternResult<InitCallbackResult> { | ||
Ok(InitCallbackResult::Pass) | ||
} | ||
// Don't modify this enum if you want the scaffolding tool to generate appropriate signals for your entries and links | ||
#[derive(Serialize, Deserialize, Debug)] | ||
#[serde(tag = "type")] | ||
pub enum Signal { | ||
EntryCreated { action: SignedActionHashed, app_entry: EntryTypes }, | ||
EntryUpdated { | ||
action: SignedActionHashed, | ||
app_entry: EntryTypes, | ||
original_app_entry: EntryTypes, | ||
}, | ||
EntryDeleted { action: SignedActionHashed, original_app_entry: EntryTypes }, | ||
} | ||
// Whenever an action is committed, we emit a signal to the UI elements to reactively update them | ||
#[hdk_extern(infallible)] | ||
pub fn post_commit(committed_actions: Vec<SignedActionHashed>) { | ||
// Don't modify this loop if you want the scaffolding tool to generate appropriate signals for your entries and links | ||
for action in committed_actions { | ||
if let Err(err) = signal_action(action) { | ||
error!("Error signaling new action: {:?}", err); | ||
} | ||
} | ||
} | ||
// Don't modify this function if you want the scaffolding tool to generate appropriate signals for your entries and links | ||
fn signal_action(action: SignedActionHashed) -> ExternResult<()> { | ||
match action.hashed.content.clone() { | ||
Action::Create(_create) => { | ||
if let Ok(Some(app_entry)) = get_entry_for_action(&action.hashed.hash) { | ||
emit_signal(Signal::EntryCreated { | ||
action, | ||
app_entry, | ||
})?; | ||
} | ||
Ok(()) | ||
} | ||
Action::Update(update) => { | ||
if let Ok(Some(app_entry)) = get_entry_for_action(&action.hashed.hash) { | ||
if let Ok(Some(original_app_entry)) = get_entry_for_action( | ||
&update.original_action_address, | ||
) { | ||
emit_signal(Signal::EntryUpdated { | ||
action, | ||
app_entry, | ||
original_app_entry, | ||
})?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
Action::Delete(delete) => { | ||
if let Ok(Some(original_app_entry)) = get_entry_for_action( | ||
&delete.deletes_address, | ||
) { | ||
emit_signal(Signal::EntryDeleted { | ||
action, | ||
original_app_entry, | ||
})?; | ||
} | ||
Ok(()) | ||
} | ||
_ => Ok(()), | ||
} | ||
} | ||
fn get_entry_for_action(action_hash: &ActionHash) -> ExternResult<Option<EntryTypes>> { | ||
let record = match get_details(action_hash.clone(), GetOptions::default())? { | ||
Some(Details::Record(record_details)) => record_details.record, | ||
_ => { | ||
return Ok(None); | ||
} | ||
}; | ||
let entry = match record.entry().as_option() { | ||
Some(entry) => entry, | ||
None => { | ||
return Ok(None); | ||
} | ||
}; | ||
let (zome_index, entry_index) = match record.action().entry_type() { | ||
Some(EntryType::App(AppEntryDef { zome_index, entry_index, .. })) => { | ||
(zome_index, entry_index) | ||
} | ||
_ => { | ||
return Ok(None); | ||
} | ||
}; | ||
Ok( | ||
EntryTypes::deserialize_from_type( | ||
zome_index.clone(), | ||
entry_index.clone(), | ||
entry, | ||
)?, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "trusted_integrity" | ||
version = "0.0.1" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
name = "trusted_integrity" | ||
|
||
[dependencies] | ||
hdi = { workspace = true } | ||
|
||
serde = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use hdi::prelude::*; | ||
#[hdk_entry_helper] | ||
#[derive(Clone, PartialEq)] | ||
pub struct GpgKey { | ||
pub public_key: Vec<u32>, | ||
pub fingerprint: String, | ||
} | ||
pub fn validate_create_gpg_key( | ||
_action: EntryCreationAction, | ||
_gpg_key: GpgKey, | ||
) -> ExternResult<ValidateCallbackResult> { | ||
Ok(ValidateCallbackResult::Valid) | ||
} | ||
pub fn validate_update_gpg_key( | ||
_action: Update, | ||
_gpg_key: GpgKey, | ||
_original_action: EntryCreationAction, | ||
_original_gpg_key: GpgKey, | ||
) -> ExternResult<ValidateCallbackResult> { | ||
Ok(ValidateCallbackResult::Invalid(String::from("Gpg Keys cannot be updated"))) | ||
} | ||
pub fn validate_delete_gpg_key( | ||
_action: Delete, | ||
_original_action: EntryCreationAction, | ||
_original_gpg_key: GpgKey, | ||
) -> ExternResult<ValidateCallbackResult> { | ||
Ok(ValidateCallbackResult::Invalid(String::from("Gpg Keys cannot be deleted"))) | ||
} |
Oops, something went wrong.