Skip to content

Commit

Permalink
feat: update holochain deps to dev.7 and use new zome signing (#131)
Browse files Browse the repository at this point in the history
The Zome parameters and signing of them has been changed. This change
uses the new, more flexible approach.
  • Loading branch information
cdunster authored Nov 29, 2024
1 parent 21cae54 commit 1ecd21d
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 244 deletions.
361 changes: 183 additions & 178 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ resolver = "2"
members = ["fixture/zomes/foo"]

[workspace.dependencies]
holochain_zome_types = "0.5.0-dev.0"
holochain_zome_types = "0.5.0-dev.7"

[dependencies]
again = "0.1"
Expand All @@ -31,9 +31,9 @@ async-trait = "0.1"
parking_lot = "0.12.1"

holo_hash = { version = "0.5.0-dev.0", features = ["encoding"] }
holochain_conductor_api = "0.5.0-dev.0"
holochain_websocket = "0.5.0-dev.0"
holochain_types = "0.5.0-dev.0"
holochain_conductor_api = "0.5.0-dev.7"
holochain_websocket = "0.5.0-dev.7"
holochain_types = "0.5.0-dev.7"
holochain_nonce = "0.5.0-dev.0"
holochain_zome_types = { workspace = true }

Expand All @@ -44,7 +44,7 @@ tokio = { version = "1.36", features = ["rt"] }

[dev-dependencies]
fixt = "0.5.0-dev.0"
holochain = { version = "0.5.0-dev.0", features = ["test_utils"] }
holochain = { version = "0.5.0-dev.7", features = ["test_utils"] }

[features]
default = ["lair_signing"]
Expand Down
16 changes: 9 additions & 7 deletions src/app_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use anyhow::{anyhow, Result};
use holo_hash::AgentPubKey;
use holochain_conductor_api::{
AppAuthenticationToken, AppInfo, AppRequest, AppResponse, CellInfo, NetworkInfo,
ProvisionedCell, ZomeCall,
ProvisionedCell, ZomeCallParamsSigned,
};
use holochain_nonce::fresh_nonce;
use holochain_types::app::{
Expand All @@ -17,7 +17,7 @@ use holochain_types::app::{
use holochain_types::prelude::{CloneId, Signal};
use holochain_zome_types::{
clone::ClonedCell,
prelude::{CellId, ExternIO, FunctionName, RoleName, Timestamp, ZomeCallUnsigned, ZomeName},
prelude::{CellId, ExternIO, FunctionName, RoleName, Timestamp, ZomeCallParams, ZomeName},
};
use std::net::ToSocketAddrs;
use std::sync::Arc;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl AppWebsocket {
let (nonce, expires_at) =
fresh_nonce(Timestamp::now()).map_err(ConductorApiError::FreshNonceError)?;

let zome_call_unsigned = ZomeCallUnsigned {
let params = ZomeCallParams {
provenance: self.signer.get_provenance(&cell_id).ok_or(
ConductorApiError::SignZomeCallError("Provenance not found".to_string()),
)?,
Expand All @@ -139,16 +139,18 @@ impl AppWebsocket {
expires_at,
nonce,
};

let signed_zome_call = sign_zome_call(zome_call_unsigned, self.signer.clone())
let signed_zome_call = sign_zome_call(params, self.signer.clone())
.await
.map_err(|e| ConductorApiError::SignZomeCallError(e.to_string()))?;

self.signed_call_zome(signed_zome_call).await
}

pub async fn signed_call_zome(&self, call: ZomeCall) -> ConductorApiResult<ExternIO> {
let app_request = AppRequest::CallZome(Box::new(call));
pub async fn signed_call_zome(
&self,
signed_params: ZomeCallParamsSigned,
) -> ConductorApiResult<ExternIO> {
let app_request = AppRequest::CallZome(Box::new(signed_params));
let response = self.inner.send(app_request).await?;

match response {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use error::{ConductorApiError, ConductorApiResult};
pub use holochain_conductor_api::{
AdminRequest, AdminResponse, AppAuthenticationRequest, AppAuthenticationToken,
AppAuthenticationTokenIssued, AppInfo, AppRequest, AppResponse, AppStatusFilter,
IssueAppAuthenticationTokenPayload, ZomeCall,
IssueAppAuthenticationTokenPayload,
};
pub use holochain_types::{
app::{InstallAppPayload, InstalledAppId},
Expand Down
33 changes: 12 additions & 21 deletions src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use std::sync::Arc;
use anyhow::Result;
use async_trait::async_trait;
use holo_hash::AgentPubKey;
use holochain_conductor_api::ZomeCall;
use holochain_conductor_api::ZomeCallParamsSigned;
use holochain_zome_types::{
capability::CapSecret, cell::CellId, dependencies::holochain_integrity_types::Signature,
zome_io::ZomeCallUnsigned,
capability::CapSecret,
cell::CellId,
dependencies::holochain_integrity_types::Signature,
zome_io::{ExternIO, ZomeCallParams},
};

pub(crate) mod client_signing;
Expand All @@ -32,28 +34,17 @@ pub trait AgentSigner {

/// Signs an unsigned zome call using the provided signing implementation
pub(crate) async fn sign_zome_call(
zome_call_unsigned: ZomeCallUnsigned,
params: ZomeCallParams,
signer: Arc<dyn AgentSigner + Send + Sync>,
) -> Result<ZomeCall> {
let pub_key = zome_call_unsigned.provenance.clone();

let data_to_sign = zome_call_unsigned.data_to_sign().map_err(|e| {
anyhow::anyhow!("Failed to get data to sign from unsigned zome call: {}", e)
})?;

) -> Result<ZomeCallParamsSigned> {
let pub_key = params.provenance.clone();
let (bytes, bytes_hash) = params.serialize_and_hash()?;
let signature = signer
.sign(&zome_call_unsigned.cell_id, pub_key, data_to_sign)
.sign(&params.cell_id, pub_key, bytes_hash.into())
.await?;

Ok(ZomeCall {
cell_id: zome_call_unsigned.cell_id,
zome_name: zome_call_unsigned.zome_name,
fn_name: zome_call_unsigned.fn_name,
payload: zome_call_unsigned.payload,
cap_secret: zome_call_unsigned.cap_secret,
provenance: zome_call_unsigned.provenance,
nonce: zome_call_unsigned.nonce,
expires_at: zome_call_unsigned.expires_at,
Ok(ZomeCallParamsSigned {
bytes: ExternIO(bytes),
signature,
})
}
30 changes: 11 additions & 19 deletions tests/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use holochain_zome_types::prelude::ExternIO;
use kitsune_p2p_types::fixt::AgentInfoSignedFixturator;
use std::collections::BTreeSet;
use std::net::Ipv4Addr;
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;

const ROLE_NAME: &str = "foo";

Expand Down Expand Up @@ -45,9 +45,8 @@ async fn signed_zome_call() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -122,9 +121,8 @@ async fn storage_info() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -158,9 +156,8 @@ async fn dump_network_stats() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand All @@ -171,7 +168,7 @@ async fn dump_network_stats() {

let network_stats = admin_ws.dump_network_stats().await.unwrap();

assert!(network_stats.contains("\"backend\": \"tx2-quic\""));
assert!(network_stats.contains("\"backend\": \"backendMem\""));
}

#[tokio::test(flavor = "multi_thread")]
Expand All @@ -187,9 +184,8 @@ async fn get_compatible_cells() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -232,9 +228,8 @@ async fn revoke_agent_key() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: None,
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -277,8 +272,7 @@ async fn agent_info() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
existing_cells: HashMap::new(),
membrane_proofs: Some(HashMap::new()),
roles_settings: None,
network_seed: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
Expand All @@ -289,8 +283,7 @@ async fn agent_info() {
admin_ws.enable_app(app_id.clone()).await.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
// 2 agent infos expected, 1 app agent and 1 DPKI agent.
assert_eq!(agent_infos.len(), 2);
assert_eq!(agent_infos.len(), 1);

let other_agent = fixt::fixt!(AgentInfoSigned);
admin_ws
Expand All @@ -299,7 +292,7 @@ async fn agent_info() {
.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
assert_eq!(agent_infos.len(), 3);
assert_eq!(agent_infos.len(), 2);
assert!(agent_infos.contains(&other_agent));
}

Expand All @@ -316,8 +309,7 @@ async fn list_cell_ids() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key),
installed_app_id: Some(app_id.clone()),
existing_cells: HashMap::new(),
membrane_proofs: Some(HashMap::new()),
roles_settings: None,
network_seed: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
Expand Down
12 changes: 4 additions & 8 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ async fn network_info() {
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -113,9 +112,8 @@ async fn handle_signal() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -211,9 +209,8 @@ async fn close_on_drop_is_clone_safe() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -280,9 +277,8 @@ async fn deferred_memproof_installation() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Bundle(app_bundle_deferred_memproofs),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down
8 changes: 3 additions & 5 deletions tests/clone_cell.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::net::Ipv4Addr;
use std::{collections::HashMap, path::PathBuf};
use std::path::PathBuf;

use holochain::{
prelude::{DeleteCloneCellPayload, DisableCloneCellPayload, EnableCloneCellPayload},
Expand Down Expand Up @@ -32,9 +32,8 @@ async fn clone_cell_management() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down Expand Up @@ -185,9 +184,8 @@ pub async fn app_info_refresh() {
.install_app(InstallAppPayload {
agent_key: None,
installed_app_id: Some(app_id.clone()),
membrane_proofs: None,
network_seed: None,
existing_cells: HashMap::new(),
roles_settings: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
allow_throwaway_random_agent_key: false,
Expand Down

0 comments on commit 1ecd21d

Please sign in to comment.