Skip to content
Closed
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
62 changes: 30 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ sha2 = "0.10"
sqlite-wasm-rs = "0.5"
strum = "0.27"
subtle = "2"
taceo-oprf = { version = "0.17", default-features = false }
taceo-oprf = { version = "0.18.1", default-features = false }
tempfile = "3"
test-case = "3.3"
thiserror = "2"
Expand All @@ -78,8 +78,8 @@ zeroize = "1"
zip = { version = "2", default-features = false }

# world-id-protocol crates
world-id-core = { version = "0.13", default-features = false }
world-id-proof = { version = "0.13", default-features = false }
world-id-core = { git = "https://github.com/worldcoin/world-id-protocol", rev = "79f3983e5f1c29326de2938fe56eff76c156c698", default-features = false }
world-id-proof = { git = "https://github.com/worldcoin/world-id-protocol", rev = "79f3983e5f1c29326de2938fe56eff76c156c698", default-features = false }

# internal
walletkit-core = { version = "0.21.2", path = "crates/walletkit-core", default-features = false }
Expand Down
30 changes: 20 additions & 10 deletions crates/walletkit-cli/src/commands/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ pub enum ProofCommand {
/// Nonce used when generating the proof, as a 32-byte hex field element (with optional `0x` prefix).
#[arg(long)]
nonce: String,
/// Context that binds the proof to the issuer operation, as a 32-byte hex field element.
#[arg(long)]
context: String,
/// Credential `sub` (commitment) the proof claims ownership of, as a 32-byte hex field element.
#[arg(long)]
sub: String,
Expand Down Expand Up @@ -131,9 +134,8 @@ fn read_file_or_stdin(path: &str) -> eyre::Result<String> {
fn parse_proof_type_arg(value: &str) -> Result<ProofType, String> {
match value.trim().to_ascii_lowercase().as_str() {
"uniqueness" => Ok(ProofType::Uniqueness),
"create-session" | "create_session" => Ok(ProofType::CreateSession),
"session" => Ok(ProofType::Session),
_ => Err("expected one of: uniqueness, create-session, session".to_string()),
_ => Err("expected one of: uniqueness, session".to_string()),
}
}

Expand Down Expand Up @@ -252,12 +254,9 @@ fn run_generate_test_request(
session_id: Option<SessionId>,
) -> eyre::Result<()> {
let session_id = match (proof_type, session_id) {
(ProofType::Uniqueness | ProofType::CreateSession, Some(_)) => {
(ProofType::Uniqueness, Some(_)) => {
eyre::bail!("--session-id is only valid with --proof-type session");
}
(ProofType::Session, None) => {
eyre::bail!("--session-id is required with --proof-type session");
}
(ProofType::Session, Some(session_id)) => Some(session_id),
(_, None) => None,
};
Expand Down Expand Up @@ -360,6 +359,7 @@ fn run_verify_ownership(
cli: &Cli,
proof_path: &str,
nonce: &str,
context: &str,
sub: &str,
) -> eyre::Result<()> {
let b64 = read_file_or_stdin(proof_path)?;
Expand All @@ -370,12 +370,19 @@ fn run_verify_ownership(
.wrap_err("failed to decode ownership proof CBOR")?;

let nonce_fe = parse_field_element(nonce, "--nonce")?;
let context_fe = parse_field_element(context, "--context")?;
let sub_fe = parse_field_element(sub, "--sub")?;

let root = resolve_root(cli)?;
let artifacts = create_artifact_source(&root);

let result = verify_ownership_proof(&proof, nonce_fe, sub_fe, artifacts.as_ref());
let result = verify_ownership_proof(
&proof,
nonce_fe,
sub_fe,
context_fe,
artifacts.as_ref(),
);
let merkle_root = proof.merkle_root.to_string();

if cli.json {
Expand Down Expand Up @@ -432,8 +439,11 @@ pub async fn run(cli: &Cli, action: &ProofCommand) -> eyre::Result<()> {
signal,
verifier_address,
} => run_test(cli, signal, verifier_address.as_deref()).await,
ProofCommand::VerifyOwnership { proof, nonce, sub } => {
run_verify_ownership(cli, proof, nonce, sub)
}
ProofCommand::VerifyOwnership {
proof,
nonce,
context,
sub,
} => run_verify_ownership(cli, proof, nonce, context, sub),
}
}
23 changes: 14 additions & 9 deletions crates/walletkit-cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ fn proof_generate_test_request_defaults_to_uniqueness() {
}

#[test]
fn proof_generate_test_request_supports_create_session() {
fn proof_generate_test_request_supports_canonical_session_creation() {
let output = Command::new(walletkit_bin())
.args([
"--json",
Expand All @@ -327,7 +327,7 @@ fn proof_generate_test_request_supports_create_session() {
"--issuer-schema-id",
"47",
"--proof-type",
"create-session",
"session",
])
.output()
.expect("failed to run");
Expand All @@ -341,9 +341,9 @@ fn proof_generate_test_request_supports_create_session() {
let parsed: serde_json::Value =
serde_json::from_str(&stdout).expect("invalid json");
let data = &parsed["data"];
assert_eq!(data["proof_type"], "create_session");
assert_eq!(data["proof_type"], "session");
assert!(data["action"].is_null());
assert!(data["session_id"].is_null());
assert_eq!(data["session_id"], "create");
}

#[test]
Expand Down Expand Up @@ -383,16 +383,21 @@ fn proof_generate_test_request_supports_session() {
}

#[test]
fn proof_generate_test_request_requires_session_id_for_session() {
fn proof_generate_test_request_rejects_session_id_for_uniqueness() {
let session_id = serde_json::to_value(SessionId::default())
.expect("session id should serialize")
.as_str()
.expect("session id should serialize as string")
.to_string();
let output = Command::new(walletkit_bin())
.args([
"--json",
"proof",
"generate-test-request",
"--issuer-schema-id",
"47",
"--proof-type",
"session",
"--session-id",
&session_id,
])
.output()
.expect("failed to run");
Expand All @@ -405,8 +410,8 @@ fn proof_generate_test_request_requires_session_id_for_session() {
parsed["error"]["message"]
.as_str()
.unwrap()
.contains("--session-id is required"),
"expected missing session id error, got: {stderr}"
.contains("--session-id is only valid"),
"expected uniqueness session id error, got: {stderr}"
);
}

Expand Down
Loading
Loading