diff --git a/Cargo.toml b/Cargo.toml index 882d01e..f5c7fdc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ base64 = "0.21.4" http = "1.1.0" jsonpath_lib = "0.3.0" jsonschema = "0.18.0" +oid4vp-frontend = { version = "0.1.0", path = "oid4vp-frontend" } p256 = { version = "0.13.2", features = ["jwk"], optional = true } rand = { version = "0.8.5", optional = true } reqwest = { version = "0.12.5", features = ["rustls-tls"], optional = true } diff --git a/oid4vp-frontend/Cargo.lock b/oid4vp-frontend/Cargo.lock new file mode 100644 index 0000000..e949d98 --- /dev/null +++ b/oid4vp-frontend/Cargo.lock @@ -0,0 +1,96 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "oid4vp-frontend" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.125" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/oid4vp-frontend/Cargo.toml b/oid4vp-frontend/Cargo.toml new file mode 100644 index 0000000..e17a8d9 --- /dev/null +++ b/oid4vp-frontend/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "oid4vp-frontend" +version = "0.1.0" +edition = "2021" + +[dependencies] +serde = "1.0" +serde_json = "1.0" diff --git a/oid4vp-frontend/src/lib.rs b/oid4vp-frontend/src/lib.rs new file mode 100644 index 0000000..8e7cc3b --- /dev/null +++ b/oid4vp-frontend/src/lib.rs @@ -0,0 +1,50 @@ +//! OID4VP library data structures that are needed on the frontend, without all of the other +//! dependencies that can cause compilation issues with web targets. +use serde::{Deserialize, Serialize}; +use serde_json::Value as Json; + +/// Status of an OID4VP session. +#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)] +pub enum Status { + /// Wallet has been sent the request by reference, waiting for the wallet to request the request. + SentRequestByReference, + /// Wallet has received the request, waiting on the wallet to process the request. + SentRequest, + /// Verifier has received the response and is now processing it. + ReceivedResponse, + /// Verifier has finished processing the response. + Complete(Outcome), +} + +/// Outcome of an OID4VP session. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub enum Outcome { + /// An error occurred during response processing. + Error { cause: String }, + /// The authorization response did not pass verification. + Failure { reason: String }, + /// The authorization response is verified. + Success { info: Json }, +} + +impl PartialEq for Outcome { + fn eq(&self, other: &Self) -> bool { + core::mem::discriminant(self) == core::mem::discriminant(other) + } +} + +impl Outcome { + fn ordering(&self) -> u8 { + match self { + Outcome::Error { .. } => 0, + Outcome::Failure { .. } => 1, + Outcome::Success { .. } => 2, + } + } +} + +impl PartialOrd for Outcome { + fn partial_cmp(&self, other: &Self) -> Option { + self.ordering().partial_cmp(&other.ordering()) + } +} diff --git a/src/verifier/session.rs b/src/verifier/session.rs index 909871e..37e3e26 100644 --- a/src/verifier/session.rs +++ b/src/verifier/session.rs @@ -1,8 +1,8 @@ use std::{collections::BTreeMap, fmt::Debug, sync::Arc}; -use anyhow::{bail, Error, Ok, Result}; +use anyhow::{bail, Ok, Result}; use async_trait::async_trait; -use serde_json::Value as Json; +pub use oid4vp_frontend::*; use tokio::sync::Mutex; use uuid::Uuid; @@ -20,28 +20,6 @@ pub struct Session { pub presentation_definition: PresentationDefinition, } -#[derive(Debug, Clone, PartialEq, PartialOrd)] -pub enum Status { - /// Wallet has been sent the request by reference, waiting for the wallet to request the request. - SentRequestByReference, - /// Wallet has received the request, waiting on the wallet to process the request. - SentRequest, - /// Verifier has received the response and is now processing it. - ReceivedResponse, - /// Verifier has finished processing the response. - Complete(Outcome), -} - -#[derive(Debug, Clone)] -pub enum Outcome { - /// An error occurred during response processing. - Error { cause: Arc }, - /// The authorization response did not pass verification. - Failure { reason: String }, - /// The authorization response is verified. - Success { info: Json }, -} - /// Storage interface for session information. #[async_trait] pub trait SessionStore: Debug { @@ -100,25 +78,3 @@ impl SessionStore for MemoryStore { bail!("session not found") } } - -impl PartialEq for Outcome { - fn eq(&self, other: &Self) -> bool { - core::mem::discriminant(self) == core::mem::discriminant(other) - } -} - -impl Outcome { - fn ordering(&self) -> u8 { - match self { - Outcome::Error { .. } => 0, - Outcome::Failure { .. } => 1, - Outcome::Success { .. } => 2, - } - } -} - -impl PartialOrd for Outcome { - fn partial_cmp(&self, other: &Self) -> Option { - self.ordering().partial_cmp(&other.ordering()) - } -} diff --git a/tests/e2e.rs b/tests/e2e.rs index 8e2df83..2aeb5a4 100644 --- a/tests/e2e.rs +++ b/tests/e2e.rs @@ -152,8 +152,5 @@ async fn w3c_vc_did_client_direct_post() { assert_eq!(None, redirect); let status = verifier.poll_status(id).await.unwrap(); - match status { - Status::Complete(Outcome::Success { .. }) => (), - _ => panic!("unexpected status: {status:?}"), - } + assert!(matches!(status, Status::Complete(Outcome::Success { .. }))) }