Skip to content
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
19 changes: 19 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"walletkit",
"walletkit-db",
"walletkit-cli",
"walletkit-testkit",
]
resolver = "2"

Expand Down
1 change: 1 addition & 0 deletions walletkit-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ path = "src/main.rs"

[dependencies]
walletkit-core = { workspace = true, features = ["issuers", "embed-zkeys"] }
walletkit-testkit = { path = "../walletkit-testkit" }
world-id-core = { workspace = true }
world-id-proof = { workspace = true, features = ["zk-ownership-verify"] }
alloy = { version = "2", default-features = false, features = ["contract", "json", "getrandom", "signer-local"] }
Expand Down
72 changes: 5 additions & 67 deletions walletkit-cli/src/commands/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
use clap::Subcommand;
use eyre::WrapErr as _;
use walletkit_core::{Credential, FieldElement};
use walletkit_testkit::issuer::issue_faux_credential;
use walletkit_testkit::TestEnv;

use crate::output;

Expand Down Expand Up @@ -210,75 +212,11 @@ async fn run_show(cli: &Cli, issuer_schema_id: u64) -> eyre::Result<()> {
Ok(())
}

const FAUX_ISSUER_URL: &str = "https://faux-issuer.us.id-infra.worldcoin.dev/issue";
pub const FAUX_ISSUER_SCHEMA_ID: u64 = 128;

/// Result of issuing a test credential from the faux issuer.
pub struct IssuedTestCredential {
pub credential_id: u64,
pub issuer_schema_id: u64,
pub expires_at: u64,
pub blinding_factor: FieldElement,
}

/// Issues a test credential from the staging faux issuer (schema 128).
pub async fn issue_test_credential(
authenticator: &walletkit_core::Authenticator,
store: &walletkit_core::storage::CredentialStore,
) -> eyre::Result<IssuedTestCredential> {
let bf = authenticator
.generate_credential_blinding_factor_remote(FAUX_ISSUER_SCHEMA_ID)
.await
.wrap_err("blinding factor generation failed")?;

let sub = authenticator.compute_credential_sub(&bf);
let sub_hex = sub.to_hex_string();

let client = reqwest::Client::new();
let resp = client
.post(FAUX_ISSUER_URL)
.json(&serde_json::json!({ "sub": sub_hex }))
.send()
.await
.wrap_err("faux issuer request failed")?;

if !resp.status().is_success() {
let status = resp.status();
let body = resp.text().await.unwrap_or_default();
eyre::bail!("faux issuer returned {status}: {body}");
}

let body: serde_json::Value = resp
.json()
.await
.wrap_err("failed to parse faux issuer response")?;

let cred_value = body.get("credential").ok_or_else(|| {
eyre::eyre!("faux issuer response missing 'credential' field")
})?;

let cred_bytes =
serde_json::to_vec(cred_value).wrap_err("failed to serialize credential")?;
let cred = Credential::from_bytes(cred_bytes)
.wrap_err("invalid credential from faux issuer")?;
let expires_at = cred.expires_at();

let now = now_secs()?;
let id = store
.store_credential(&cred, &bf, expires_at, None, now)
.wrap_err("store credential failed")?;

Ok(IssuedTestCredential {
credential_id: id,
issuer_schema_id: FAUX_ISSUER_SCHEMA_ID,
expires_at,
blinding_factor: bf,
})
}

async fn run_issue_test(cli: &Cli) -> eyre::Result<()> {
let (authenticator, store) = init_authenticator(cli).await?;
let result = issue_test_credential(&authenticator, &store).await?;
let env = TestEnv::staging();
let now = now_secs()?;
let result = issue_faux_credential(&env, &authenticator, &store, now).await?;

if cli.json {
output::print_json_data(
Expand Down
2 changes: 1 addition & 1 deletion walletkit-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use eyre::WrapErr as _;
use walletkit_core::storage::{cache_embedded_groth16_material, CredentialStore};
use walletkit_core::{Authenticator, Groth16Materials};

use crate::provider::create_fs_credential_store;
use walletkit_testkit::storage::create_fs_credential_store;

/// `WalletKit` CLI — developer tool for World ID wallet operations.
#[derive(Parser)]
Expand Down
Loading
Loading