Skip to content

Commit

Permalink
Add app_hmac argument to VanadiumAppClient::new
Browse files Browse the repository at this point in the history
  • Loading branch information
bigspider committed Oct 11, 2024
1 parent bfa036c commit 5612090
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
10 changes: 5 additions & 5 deletions apps/test/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
let transport = TransportWrapper::new(transport_raw.clone());

TestClient::new(Box::new(
VanadiumAppClient::new(&app_path_str, Arc::new(transport))
.await
.map_err(|_| "Failed to create client")?,
))
let (client, _) = VanadiumAppClient::new(&app_path_str, Arc::new(transport), None)
.await
.map_err(|_| "Failed to create client")?;

TestClient::new(Box::new(client))
};

loop {
Expand Down
17 changes: 10 additions & 7 deletions client-sdk/src/vanadium_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ impl VanadiumAppClient {
pub async fn new<E: std::fmt::Debug + Send + Sync + 'static>(
elf_path: &str,
transport: Arc<dyn Transport<Error = E>>,
) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
app_hmac: Option<[u8; 32]>,
) -> Result<(Self, [u8; 32]), Box<dyn std::error::Error + Send + Sync>> {
// Create ELF file and manifest
let elf_file = ElfFile::new(Path::new(&elf_path))?;
let manifest = Manifest::new(
Expand All @@ -689,16 +690,18 @@ impl VanadiumAppClient {
elf_file.data_segment.end,
[0u8; 32],
0,
)
.unwrap();
)?;

let mut client = GenericVanadiumClient::new();

// Register and run the V-App
let app_hmac = client.register_vapp(transport.clone(), &manifest).await?;
client.run_vapp(transport.clone(), &manifest, &app_hmac, &elf_file)?;
// Register the V-App if the hmac was not given
let app_hmac =
app_hmac.unwrap_or(client.register_vapp(transport.clone(), &manifest).await?);

// run the V-App
client.run_vapp(transport, &manifest, &app_hmac, &elf_file)?;

Ok(Self { client })
Ok((Self { client }, app_hmac))
}
}

Expand Down

0 comments on commit 5612090

Please sign in to comment.