Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4 zome re structure and crate docs #89

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,760 changes: 942 additions & 818 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 49 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,74 @@ opt-level = "z"

[workspace]
resolver = "2"
members = ["crates/*"]
members = ["crates/*/coordinator","crates/*/integrity"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this pattern not imply that holoom_types, jaq_wrapper, shared_utils aren't workspace members?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are dependency packages .. i dont think they need to be members.


[workspace.dependencies]
hdi = "=0.5.0-dev.9"
hdk = "=0.4.0-dev.10"
holo_hash = { version = "=0.4.0-dev.8", features = ["encoding"] }
hdi = "=0.5.0-dev.10"
hdk = "=0.4.0-dev.12"
holo_hash = { version = "=0.4.0-dev.9", features = ["encoding"] }
serde = "1"
serde_json = "1"
bincode = "1.3.3"
hex = "0.4.3"
alloy-primitives = { version = "0.6.3", features = ["serde", "k256"] }
ed25519-dalek = { version = "2.1.1", features = ["serde"] }
bs58 = "0.5.0"
bs58 = "0.5"
ethers-signers = "0.6.2"
holochain = { version = "=0.4.0-dev.12", default-features = false, features = [
holochain = { version = "=0.4.0-dev.16", default-features = false, features = [
"test_utils",
] }
holochain_keystore = "=0.4.0-dev.12"
holochain_keystore = "=0.4.0-dev.15"
#holochain_integrity_types = "0.3"

[workspace.dependencies.holoom_types]
path = "crates/holoom_types"

[workspace.dependencies.jaq_wrapper]
path = "crates/jaq_wrapper"

[workspace.dependencies.username_registry_utils]
path = "crates/username_registry_utils"
[workspace.dependencies.shared_utils]
path = "crates/shared_utils"

[workspace.dependencies.username_registry_validation]
path = "crates/username_registry_validation"
[workspace.dependencies.evm_attestation_coordinator]
path = "crates/evm_attestation/coordinator"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

evm_attestation_* is a misleading name. It should probably be evm_signing_offer_*.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i used the term for a package name to refer to all EVM operations that would imply some kind of attestation.. we can change the package name


[workspace.dependencies.username_registry_integrity]
path = "crates/username_registry_integrity"
[workspace.dependencies.evm_attestation_integrity]
path = "crates/evm_attestation/integrity"

[workspace.dependencies.username_registry_coordinator]
path = "crates/username_registry_coordinator"
[workspace.dependencies.username_attestation_coordinator]
path = "crates/username_attestation/coordinator"

[workspace.dependencies.username_attestation_integrity]
path = "crates/username_attestation/integrity"

[workspace.dependencies.external_attestation]
path = "crates/external_attestation/coordinator"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confusing name. The crate is specifically for attesting external IDs. The attestation isn't itself external.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shortened the name as .. i thought it obvious that the attestation would be on an ID


[workspace.dependencies.external_attestation_integrity]
path = "crates/external_attestation/integrity"

[workspace.dependencies.wallet_attestation]
path = "crates/wallet_attestation/coordinator"

[workspace.dependencies.wallet_attestation_integrity]
path = "crates/wallet_attestation/integrity"

[workspace.dependencies.oracle_document]
path = "crates/oracle_document/coordinator"

[workspace.dependencies.oracle_document_integrity]
path = "crates/oracle_document/integrity"

[workspace.dependencies.holoom_recipe]
path = "crates/holoom_recipe/coordinator"

[workspace.dependencies.holoom_recipe_integrity]
path = "crates/holoom_recipe/integrity"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for adding holoom_ to the name of recipe related crates, but not the others?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me They are meta operations .. you could create recipes for anything... but here we are creating recipes specifically for holoom crates/packages


[workspace.dependencies.holoom_recipe_execution]
path = "crates/holoom_recipe_execution/coordinator"

[workspace.dependencies.holoom_recipe_execution_integrity]
path = "crates/holoom_recipe_execution/integrity"

[workspace.dependencies.signer_coordinator]
path = "crates/signer_coordinator"
20 changes: 20 additions & 0 deletions crates/evm_attestation/coordinator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "evm_attestation"
version = "0.0.1"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
name = "evm_attestation"

[dependencies]
hdk = { workspace = true }
serde = { workspace = true }
holoom_types = { workspace = true }
shared_utils = { workspace = true }
evm_attestation_integrity = { workspace = true }
jaq_wrapper = { workspace = true }

#[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] #avoids mio bug
#holochain = { workspace = true, default-features = false, features = ["test_utils"] }
#tokio = "1.38.0"
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use holoom_types::{
EvmAddress, LocalHoloomSignal, RemoteHoloomSignal,
};
use jaq_wrapper::{parse_single_json, Val};
use username_registry_integrity::{EntryTypes, LinkTypes};
use username_registry_utils::{deserialize_record_entry, hash_evm_address, hash_identifier};
use evm_attestation_integrity::{EntryTypes, LinkTypes};
use shared_utils::{deserialize_record_entry, hash_evm_address, hash_identifier};

#[hdk_extern]
fn create_signed_evm_signing_offer(payload: CreateEvmSigningOfferPayload) -> ExternResult<Record> {
Expand Down
53 changes: 53 additions & 0 deletions crates/evm_attestation/coordinator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
pub mod evm_signing_offer;
use hdk::prelude::*;
use holoom_types::{LocalHoloomSignal, RemoteHoloomSignal};
use shared_utils::get_authority_agent;

#[hdk_extern]
pub fn init(_: ()) -> ExternResult<InitCallbackResult> {
let authority_agent = get_authority_agent()?;
let my_pubkey = agent_info()?.agent_initial_pubkey;
let mut functions = BTreeSet::new();
let zome_name = zome_info()?.name;
if my_pubkey == authority_agent {
functions.insert((
zome_name.clone(), "ingest_signed_username".into(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not relevant to this zome

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right that one might be a mistake..

));
}
functions.insert((zome_name, "recv_remote_signal".into()));
create_cap_grant(CapGrantEntry {
tag: "".into(),
access: ().into(),
functions: GrantedFunctions::Listed(functions),
})?;

Ok(InitCallbackResult::Pass)
}

#[hdk_extern]
fn recv_remote_signal(signal_io: ExternIO) -> ExternResult<()> {
let remote_holoom_signal: RemoteHoloomSignal = signal_io
.decode()
.map_err(|e| wasm_error!(WasmErrorInner::Serialize(e)))?;

match remote_holoom_signal {
RemoteHoloomSignal::EvmSignatureProvided {
request_id,
signed_u256_array,
} => emit_signal(LocalHoloomSignal::EvmSignatureProvided {
request_id,
signed_u256_array,
})?,
RemoteHoloomSignal::EvmSignatureRequestRejected { request_id, reason } => {
emit_signal(LocalHoloomSignal::EvmSignatureRequestRejected { request_id, reason })?
}
_=>{}
}

Ok(())
}

#[hdk_extern]
fn get_authority(_: ()) -> ExternResult<AgentPubKey> {
get_authority_agent()
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "username_registry_integrity"
name = "evm_attestation_integrity"
version = "0.0.1"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]
name = "username_registry_integrity"
name = "evm_attestation_integrity"

[dependencies]
hdi = { workspace = true }
serde = { workspace = true }
holoom_types = { workspace = true }
username_registry_validation = { workspace = true }
shared_utils = { workspace = true }
24 changes: 24 additions & 0 deletions crates/evm_attestation/integrity/src/entry_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use hdi::prelude::*;
use holoom_types::evm_signing_offer::SignedEvmSigningOffer;
use crate::evm_signing_offer::*;

#[derive(Serialize, Deserialize)]
#[serde(tag = "type")]
#[hdk_entry_types]
#[unit_enum(UnitEntryTypes)]
pub enum EntryTypes {
SignedEvmSigningOffer(SignedEvmSigningOffer),
}

impl EntryTypes {
pub fn validate_create(self, action: Create) -> ExternResult<ValidateCallbackResult> {
match self {
EntryTypes::SignedEvmSigningOffer(evm_signing_offer) => {
validate_create_signed_evm_signing_offer(
EntryCreationAction::Create(action),
evm_signing_offer,
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hdi::prelude::*;
use holoom_types::evm_signing_offer::SignedEvmSigningOffer;
use username_registry_utils::{deserialize_record_entry, hash_evm_address};
use shared_utils::{deserialize_record_entry, hash_evm_address};

pub fn validate_create_link_evm_address_to_signing_offer(
action: CreateLink,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use holoom_types::{
evm_signing_offer::{EvmU256Item, SignedEvmSigningOffer},
recipe::Recipe,
};
use username_registry_utils::deserialize_record_entry;
use shared_utils::deserialize_record_entry;

pub fn validate_create_signed_evm_signing_offer(
_action: EntryCreationAction,
Expand Down
141 changes: 141 additions & 0 deletions crates/evm_attestation/integrity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
use hdi::prelude::*;
pub mod entry_types;
pub use entry_types::*;
pub mod link_types;
pub use link_types::*;
pub mod evm_address_to_signing_offer;
pub use evm_address_to_signing_offer::*;
pub mod evm_signing_offer;
pub use evm_signing_offer::*;
pub mod name_to_evm_signing_offer;
pub use name_to_evm_signing_offer::*;


#[hdk_extern]
pub fn genesis_self_check(_data: GenesisSelfCheckData) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Valid)
}
pub fn validate_agent_joining(
_agent_pub_key: AgentPubKey,
_membrane_proof: &Option<MembraneProof>,
) -> ExternResult<ValidateCallbackResult> {
Ok(ValidateCallbackResult::Valid)
}
#[hdk_extern]
pub fn validate(op: Op) -> ExternResult<ValidateCallbackResult> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to find a way to generalise this since it's repeated so many times now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is another one we have to swallow.. as every zome has these common validation functions. trying to separate them from the zomes validation files.. wont work and breaks modularity.

match op.flattened::<EntryTypes, LinkTypes>()? {
FlatOp::StoreEntry(store_entry) => match store_entry {
OpEntry::CreateEntry { app_entry, action } => app_entry.validate_create(action),
OpEntry::UpdateEntry { .. } => Ok(ValidateCallbackResult::Invalid(
"App EntryTypes cannot be updated".into(),
)),
_ => Ok(ValidateCallbackResult::Valid),
},
FlatOp::RegisterUpdate(update_entry) => match update_entry {
OpUpdate::Entry { .. } => Ok(ValidateCallbackResult::Invalid(
"App EntryTypes cannot be updated".into(),
)),
_ => Ok(ValidateCallbackResult::Valid),
},
FlatOp::RegisterDelete(_) => Ok(ValidateCallbackResult::Invalid(
"App EntryTypes cannot be deleted".into(),
)),
FlatOp::RegisterCreateLink {
link_type,
base_address,
target_address,
tag,
action,
} => link_type.validate_create(action, base_address, target_address, tag),
FlatOp::RegisterDeleteLink {
link_type,
base_address,
target_address,
tag,
original_action,
action,
} => link_type.validate_delete(action, original_action, base_address, target_address, tag),
FlatOp::StoreRecord(store_record) => {
match store_record {
OpRecord::CreateEntry { app_entry, action } => app_entry.validate_create(action),
OpRecord::UpdateEntry { .. } => Ok(ValidateCallbackResult::Invalid(
"App EntryTypes cannot be updated".into(),
)),
OpRecord::DeleteEntry { .. } => Ok(ValidateCallbackResult::Invalid(
"App EntryTypes cannot be deleted".into(),
)),
OpRecord::CreateLink {
base_address,
target_address,
tag,
link_type,
action,
} => link_type.validate_create(action, base_address, target_address, tag),
OpRecord::DeleteLink {
original_action_hash,
base_address,
action,
} => {
let record = must_get_valid_record(original_action_hash)?;
let create_link = match record.action() {
Action::CreateLink(create_link) => create_link.clone(),
_ => {
return Ok(ValidateCallbackResult::Invalid(
"The action that a DeleteLink deletes must be a CreateLink"
.to_string(),
));
}
};
let link_type = match LinkTypes::from_type(
create_link.zome_index,
create_link.link_type,
)? {
Some(lt) => lt,
None => {
// @todo This must be treated as valid due to holochain bug
// see https://github.com/holochain/holochain/issues/2868
return Ok(ValidateCallbackResult::Valid);
}
};
link_type.validate_delete(
action,
create_link.clone(),
base_address,
create_link.target_address,
create_link.tag,
)
}
OpRecord::CreatePrivateEntry { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::UpdatePrivateEntry { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::CreateCapClaim { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::CreateCapGrant { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::UpdateCapClaim { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::UpdateCapGrant { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::Dna { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::OpenChain { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::CloseChain { .. } => Ok(ValidateCallbackResult::Valid),
OpRecord::InitZomesComplete { .. } => Ok(ValidateCallbackResult::Valid),
_ => Ok(ValidateCallbackResult::Valid),
}
}
FlatOp::RegisterAgentActivity(agent_activity) => match agent_activity {
OpActivity::CreateAgent { agent, action } => {
let previous_action = must_get_action(action.prev_action)?;
match previous_action.action() {
Action::AgentValidationPkg(
AgentValidationPkg { membrane_proof, .. },
) => validate_agent_joining(agent, membrane_proof),
_ => {
Ok(
ValidateCallbackResult::Invalid(
"The previous action for a `CreateAgent` action must be an `AgentValidationPkg`"
.to_string(),
),
)
}
}
}
_ => Ok(ValidateCallbackResult::Valid),
},
}
}
Loading