Skip to content
Merged
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
540 changes: 412 additions & 128 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ phf = { version = "0.11.2", features = ["macros"] }
rsa = { version = "0.9.2" }
getrandom = { version = "0.2.10", features = ["custom"] }
p256 = {version = "0.13.2", features = ["ecdsa-core", "arithmetic", "serde"]}
ed25519-zebra = { version = "4.1.0", features = ["alloc"] }
cosmos-sdk-proto = {package = "cosmos-sdk-proto", git = "https://github.com/burnt-labs/cosmos-rust", branch = "feat/xion-zk", default-features = false, features = ["cosmwasm", "xion"]}
url = "2.5.2"
1 change: 1 addition & 0 deletions contracts/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ base64 = { workspace = true }
rsa = { workspace = true }
getrandom = { workspace = true }
p256 = { workspace = true }
ed25519-zebra = { workspace = true }
cosmos-sdk-proto = { workspace = true }
5 changes: 4 additions & 1 deletion contracts/account/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub enum AddAuthenticator {
ZKEmail {
id: u8,
email_salt: String,
allowed_email_hosts: Vec<String>,
signature: Binary,
},
}
Expand Down Expand Up @@ -94,6 +95,7 @@ pub enum Authenticator {
},
ZKEmail {
email_salt: String,
allowed_email_hosts: Vec<String>,
},
}

Expand Down Expand Up @@ -170,9 +172,10 @@ impl Authenticator {
}
Authenticator::ZKEmail {
email_salt,
allowed_email_hosts,
} => {
let tx_bytes_hash = util::base64url_encode(tx_bytes);
let verification = zkemail::verify(deps, tx_bytes_hash.as_bytes(), sig_bytes, email_salt)?;
let verification = zkemail::verify(deps, tx_bytes_hash.as_bytes(), sig_bytes, email_salt, allowed_email_hosts)?;
Ok(verification)
}
}
Expand Down
5 changes: 5 additions & 0 deletions contracts/account/src/auth/zkemail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn verify(
tx_bytes: &[u8],
sig_bytes: &[u8],
email_salt: &str,
allowed_email_hosts: &[String],
) -> ContractResult<bool> {
// split the sig_bytes into 2 parts proof and publicOutputs
let sig: ZKEmailSignature = from_json(sig_bytes.to_vec())?;
Expand All @@ -43,6 +44,7 @@ pub fn verify(
proof: serde_json::to_vec(&proof)?,
public_inputs: public_inputs.clone(),
email_hash: email_salt.to_string(),
allowed_email_hosts: allowed_email_hosts.to_vec(),
};

let verification_request_bytes = verification_request.to_bytes()?;
Expand Down Expand Up @@ -470,19 +472,22 @@ mod tests {
let signature = sample_zkemail_signature();
let tx_bytes = "test_transaction";
let email_salt = "test_salt";
let allowed_email_hosts = vec!["example.com".to_string(), "test.com".to_string()];

// Test creating QueryVerifyRequest from signature components
let verification_request = QueryVerifyRequest {
tx_bytes: tx_bytes.as_bytes().to_vec(),
proof: serde_json::to_vec(&signature.proof).unwrap(),
public_inputs: signature.public_inputs.clone(),
email_hash: email_salt.to_string(),
allowed_email_hosts: allowed_email_hosts.clone(),
};

// Verify the request is properly constructed
assert_eq!(verification_request.tx_bytes, tx_bytes.as_bytes());
assert_eq!(verification_request.email_hash, email_salt.to_string());
assert_eq!(verification_request.public_inputs, signature.public_inputs);
assert_eq!(verification_request.allowed_email_hosts, allowed_email_hosts);

// Verify proof serialization
let proof_bytes = serde_json::to_vec(&signature.proof).unwrap();
Expand Down
15 changes: 14 additions & 1 deletion contracts/account/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use cosmwasm_std::{
};

use crate::error::ContractError;
use crate::execute::{add_auth_method, assert_self, emit, remove_auth_method};
use crate::execute::{
add_auth_method, add_allowed_email_host, assert_self, emit, remove_allowed_email_host,
remove_auth_method, update_allowed_email_hosts,
};
use crate::msg::{ExecuteMsg, MigrateMsg};
use crate::{
error::ContractResult,
Expand Down Expand Up @@ -91,6 +94,16 @@ pub fn execute(
}
ExecuteMsg::RemoveAuthMethod { id } => remove_auth_method(deps, env, *id),
ExecuteMsg::Emit { data } => emit(env, data.to_string()),
ExecuteMsg::UpdateAllowedEmailHosts {
id,
allowed_email_hosts,
} => update_allowed_email_hosts(deps, env, *id, allowed_email_hosts.clone()),
ExecuteMsg::AddAllowedEmailHost { id, email_host } => {
add_allowed_email_host(deps, env, *id, email_host.clone())
}
ExecuteMsg::RemoveAllowedEmailHost { id, email_host } => {
remove_allowed_email_host(deps, env, *id, email_host.clone())
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions contracts/account/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ pub enum ContractError {

#[error("invalid ethereum address")]
InvalidEthAddress,

#[error("at least one allowed email host must be present")]
NoAllowedEmailHosts,

#[error("authenticator not found")]
AuthenticatorNotFound,

#[error("operation not supported for this authenticator type")]
UnsupportedAuthenticatorOperation,
}

pub type ContractResult<T> = Result<T, ContractError>;
Expand Down
Loading
Loading