diff --git a/Cargo.lock b/Cargo.lock index c034ea5f7..4fd3d0e2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1228,7 +1228,7 @@ dependencies = [ "cocoa-foundation", "core-foundation", "core-graphics", - "foreign-types 0.5.0", + "foreign-types", "libc", "objc", ] @@ -1316,7 +1316,7 @@ checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "consumer" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "did_iota", "did_jwk", @@ -1365,7 +1365,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -1929,7 +1929,7 @@ dependencies = [ [[package]] name = "did_iota" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "bls12_381_plus 0.8.17", "identity_iota", @@ -1943,7 +1943,7 @@ dependencies = [ [[package]] name = "did_jwk" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "did-jwk", "identity_iota", @@ -1960,7 +1960,7 @@ dependencies = [ [[package]] name = "did_key" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "did-method-key", "identity_iota", @@ -1978,7 +1978,7 @@ dependencies = [ [[package]] name = "did_manager" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "consumer", "producer", @@ -2006,7 +2006,7 @@ dependencies = [ [[package]] name = "did_web" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "did-web", "identity_iota", @@ -2025,7 +2025,7 @@ dependencies = [ [[package]] name = "dif-presentation-exchange" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "getset", "jsonpath_lib", @@ -2636,15 +2636,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -2652,7 +2643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -2666,12 +2657,6 @@ dependencies = [ "syn 2.0.71", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -4131,7 +4116,7 @@ dependencies = [ [[package]] name = "identity_core" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "js-sys", "multibase 0.9.1", @@ -4147,7 +4132,7 @@ dependencies = [ [[package]] name = "identity_credential" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "anyhow", "async-trait", @@ -4176,7 +4161,7 @@ dependencies = [ [[package]] name = "identity_did" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "did_url_parser", "form_urlencoded", @@ -4190,7 +4175,7 @@ dependencies = [ [[package]] name = "identity_document" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "did_url_parser", "identity_core", @@ -4205,7 +4190,7 @@ dependencies = [ [[package]] name = "identity_eddsa_verifier" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "identity_jose", "iota-crypto", @@ -4214,7 +4199,7 @@ dependencies = [ [[package]] name = "identity_iota" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "identity_core", "identity_credential", @@ -4229,7 +4214,7 @@ dependencies = [ [[package]] name = "identity_iota_core" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "async-trait", "futures", @@ -4252,7 +4237,7 @@ dependencies = [ [[package]] name = "identity_jose" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "bls12_381_plus 0.8.17", "identity_core", @@ -4268,7 +4253,7 @@ dependencies = [ [[package]] name = "identity_resolver" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "anyhow", "async-trait", @@ -4286,7 +4271,7 @@ dependencies = [ [[package]] name = "identity_storage" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "anyhow", "async-trait", @@ -4306,7 +4291,7 @@ dependencies = [ [[package]] name = "identity_stronghold" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "async-trait", "identity_storage", @@ -4322,7 +4307,7 @@ dependencies = [ [[package]] name = "identity_stronghold_ext" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "async-trait", "elliptic-curve 0.13.8", @@ -4341,7 +4326,7 @@ dependencies = [ [[package]] name = "identity_verification" version = "1.3.1" -source = "git+https://github.com/impierce/identity.rs?branch=fix/compile-fixes#d36175ce30d3be6c40da0c39f7d6c95ae424894e" +source = "git+https://github.com/impierce/identity.rs?rev=309c399#309c3998437de1fd07bdbc443fd029ee5f4c732c" dependencies = [ "identity_core", "identity_did", @@ -4742,24 +4727,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" -[[package]] -name = "josekit" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b85e2125819afc4fd2ae57416207e792c7e12797858e5db2a6c6f24a166829" -dependencies = [ - "anyhow", - "base64 0.22.1", - "flate2", - "once_cell", - "openssl", - "regex", - "serde", - "serde_json", - "thiserror", - "time", -] - [[package]] name = "js-sys" version = "0.3.69" @@ -6034,7 +6001,7 @@ dependencies = [ [[package]] name = "oid4vc" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "dif-presentation-exchange", "oid4vc-core", @@ -6047,7 +6014,7 @@ dependencies = [ [[package]] name = "oid4vc-core" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "anyhow", "async-trait", @@ -6071,7 +6038,7 @@ dependencies = [ [[package]] name = "oid4vc-manager" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "anyhow", "async-trait", @@ -6103,7 +6070,7 @@ dependencies = [ [[package]] name = "oid4vci" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "anyhow", "derivative", @@ -6127,7 +6094,7 @@ dependencies = [ [[package]] name = "oid4vp" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "anyhow", "chrono", @@ -6174,50 +6141,12 @@ dependencies = [ "pathdiff", ] -[[package]] -name = "openssl" -version = "0.10.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types 0.3.2", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.71", -] - [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "openssl-sys" -version = "0.9.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "option-ext" version = "0.2.0" @@ -6940,7 +6869,7 @@ dependencies = [ [[package]] name = "producer" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "did_iota", "did_jwk", @@ -7848,14 +7777,13 @@ dependencies = [ [[package]] name = "sd-jwt-payload" version = "0.3.0" -source = "git+https://github.com/iotaledger/sd-jwt-payload.git?rev=0300fc5#0300fc5bb2bd6c595127f58a023e0cbb33a7d423" +source = "git+https://github.com/impierce/sd-jwt-payload.git?rev=318dad9#318dad904f1a1c3d7e510b0446fc75c6c71a49b5" dependencies = [ "anyhow", "async-trait", "indexmap 2.6.0", "iota-crypto", "itertools 0.12.1", - "josekit", "json-pointer", "multibase 0.9.1", "rand 0.8.5", @@ -8276,7 +8204,7 @@ dependencies = [ [[package]] name = "shared" version = "0.1.0" -source = "git+https://git@github.com/impierce/did-manager.git?rev=c1cfda0#c1cfda09ae1e5797ba013ead8aa6ace616b75a6d" +source = "git+https://git@github.com/impierce/did-manager.git?rev=c8a141d#c8a141df13cfb910203a3e43d2088c0c3376b6bd" dependencies = [ "identity_iota", "identity_storage", @@ -8368,7 +8296,7 @@ dependencies = [ [[package]] name = "siopv2" version = "0.1.0" -source = "git+https://git@github.com/impierce/openid4vc.git?rev=bc4d6d2#bc4d6d2f9ea8cae7ab61da2099af3b95e9616585" +source = "git+https://git@github.com/impierce/openid4vc.git?rev=5933fd6#5933fd60811923a50aba98fcea2fe1cd76270bc6" dependencies = [ "anyhow", "async-trait", @@ -8452,7 +8380,7 @@ dependencies = [ "bytemuck", "cfg_aliases 0.2.1", "core-graphics", - "foreign-types 0.5.0", + "foreign-types", "js-sys", "log", "objc2", diff --git a/Cargo.toml b/Cargo.toml index 53b816a35..66a2c47a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,11 +27,10 @@ tauri-winres = "=0.1" agent_shared = { git = "https://git@github.com/impierce/ssi-agent.git", rev = "1823810" } # did_manager = { git = "https://git@github.com/impierce/did-manager.git", tag = "v1.0.0-beta.3" } -did_manager = { git = "https://git@github.com/impierce/did-manager.git", rev = "c1cfda0" } +did_manager = { git = "https://git@github.com/impierce/did-manager.git", rev = "c8a141d" } jsonwebtoken = "9.3" log = "^0.4" -oid4vc = { git = "https://git@github.com/impierce/openid4vc.git", rev = "bc4d6d2" } -# oid4vc = { path = "../openid4vc" } +oid4vc = { git = "https://git@github.com/impierce/openid4vc.git", rev = "5933fd6" } rand = "0.8" serde_json = "1.0" serial_test = "2.0" diff --git a/identity-wallet/Cargo.toml b/identity-wallet/Cargo.toml index cda10d15b..bd0c143d7 100644 --- a/identity-wallet/Cargo.toml +++ b/identity-wallet/Cargo.toml @@ -17,17 +17,17 @@ downcast-rs = "1.2" dyn-clone = "1.0" futures = "0.3" icu = "1.4.0" -identity_credential = { git = "https://github.com/impierce/identity.rs", branch = "fix/compile-fixes", default-features = false, features = [ +identity_credential = { git = "https://github.com/impierce/identity.rs", rev = "309c399", default-features = false, features = [ "credential", "domain-linkage", "presentation", "validator", "sd-jwt-vc" ] } -identity_core = { git = "https://github.com/impierce/identity.rs", branch = "fix/compile-fixes" } -identity_eddsa_verifier = { git = "https://github.com/impierce/identity.rs", branch = "fix/compile-fixes" } -identity_iota = { git = "https://github.com/impierce/identity.rs", branch = "fix/compile-fixes" } -identity_jose = { git = "https://github.com/impierce/identity.rs", branch = "fix/compile-fixes" } +identity_core = { git = "https://github.com/impierce/identity.rs", rev = "309c399" } +identity_eddsa_verifier = { git = "https://github.com/impierce/identity.rs", rev = "309c399" } +identity_iota = { git = "https://github.com/impierce/identity.rs", rev = "309c399" } +identity_jose = { git = "https://github.com/impierce/identity.rs", rev = "309c399" } iota_stronghold = { version = "2.1" } itertools = "0.10.5" jsonwebtoken.workspace = true diff --git a/identity-wallet/bindings/credentials/DisplayCredential.ts b/identity-wallet/bindings/credentials/DisplayCredential.ts index f416f4d6c..e2f70048d 100644 --- a/identity-wallet/bindings/credentials/DisplayCredential.ts +++ b/identity-wallet/bindings/credentials/DisplayCredential.ts @@ -1,4 +1,4 @@ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. import type { CredentialMetadata } from "./CredentialMetadata"; -export interface DisplayCredential { id: string, issuer_name: string, data: any, metadata: CredentialMetadata, connection_id?: string, display_name: string, } \ No newline at end of file +export interface DisplayCredential { id: string, format: string, issuer_name: string, data: any, metadata: CredentialMetadata, connection_id?: string, display_name: string, } \ No newline at end of file diff --git a/identity-wallet/src/state/credentials/mod.rs b/identity-wallet/src/state/credentials/mod.rs index fd581befb..3d8986f94 100644 --- a/identity-wallet/src/state/credentials/mod.rs +++ b/identity-wallet/src/state/credentials/mod.rs @@ -62,47 +62,42 @@ impl TryFrom for VerifiableCredentialRecord { fn try_from(verifiable_credential: serde_json::Value) -> Result { let display_credential = { // FIX THIS - if let Ok(sd_jwt_vc) = SdJwtVc::from_str(verifiable_credential.as_str().unwrap()) { + let (id, format, data, issuance_date) = if let Ok(sd_jwt_vc) = SdJwtVc::from_str( + verifiable_credential + .as_str() + .ok_or(AppError::Error("Credential is not a valid JWT".to_string()))?, + ) { info!("sd_jwt_vc: {:#?}", sd_jwt_vc); let issuance_date = sd_jwt_vc.claims().iat.map(|iat| iat.to_rfc3339()).unwrap_or_default(); - let credential_subject = sd_jwt_vc.clone().into_disclosed_object(&Sha256Hasher::new()).unwrap(); - - let hash = sha256::digest( - json!( - { - "type": ["VerifiableCredential"], - "credentialSubject": credential_subject - } - ) - .to_string(), - ); - - DisplayCredential { - id: Uuid::from_slice(&hash.as_bytes()[..16]).unwrap().to_string(), - format: CredentialFormats::VcSdJwt(()), - data: json!({ - "type": ["VerifiableCredential"], - "issuer": sd_jwt_vc.claims().iss, - "credentialSubject": credential_subject - - }), - metadata: CredentialMetadata { - is_favorite: false, - date_added: DateUtils::new_date_string(), - date_issued: issuance_date.to_string(), - }, - // The other fields will be filled in at a later stage. - ..Default::default() - } + let credential_subject = sd_jwt_vc + .clone() + .into_disclosed_object(&Sha256Hasher::new()) + .map_err(|_| AppError::Error("Failed to convert SD JWT VC to Disclosed Object".to_string()))?; + + // TODO: We are using this hash as Credential ID so that we can prevent credential duplication in + // demo situations. Now we can actually delete Credentials in UniMe we don't need to use the hash of the + // credential as the ID anymore. We should simply generate a random UUID. + let hash = sha256::digest(json!(credential_subject).to_string()); + + let id = Uuid::from_slice(&hash.as_bytes()[..16]).unwrap().to_string(); + let format = CredentialFormats::VcSdJwt(()); + // TODO: Remove this workaround that is basically a way of disguising the SD JWT VC as a VC so that + // it can be displayed in the Frontend. + let data = json!({ + "type": ["VerifiableCredential"], + "issuer": sd_jwt_vc.claims().iss, + "credentialSubject": credential_subject + + }); + + (id, format, data, issuance_date) } else { let credential_display = get_unverified_jwt_claims(&verifiable_credential)?["vc"].clone(); - info!( - "Credential Display: {:#?}", - serde_json::to_string_pretty(&credential_display).unwrap() - ); - + // TODO: We are using this hash as Credential ID so that we can prevent credential duplication in + // demo situations. Now we can actually delete Credentials in UniMe we don't need to use the hash of the + // credential as the ID anymore. We should simply generate a random UUID. // Derive the hash from the credential display. let hash = { let type_value = credential_display["type"].clone(); @@ -131,19 +126,29 @@ impl TryFrom for VerifiableCredentialRecord { .as_str() .map(ToString::to_string) .unwrap_or_default(); - - DisplayCredential { - id: Uuid::from_slice(&hash.as_bytes()[..16]).unwrap().to_string(), - format: CredentialFormats::JwtVcJson(()), - data: credential_display, - metadata: CredentialMetadata { - is_favorite: false, - date_added: DateUtils::new_date_string(), - date_issued: issuance_date.to_string(), - }, - // The other fields will be filled in at a later stage. - ..Default::default() - } + let id = Uuid::from_slice(&hash.as_bytes()[..16]).unwrap().to_string(); + let format = CredentialFormats::JwtVcJson(()); + let data = credential_display; + + (id, format, data, issuance_date) + }; + + info!( + "Credential Display: {:#?}", + serde_json::to_string_pretty(&data).unwrap() + ); + + DisplayCredential { + id, + format, + data, + metadata: CredentialMetadata { + is_favorite: false, + date_added: DateUtils::new_date_string(), + date_issued: issuance_date, + }, + // The other fields will be filled in at a later stage. + ..Default::default() } }; diff --git a/identity-wallet/src/state/credentials/reducers/handle_oid4vp_authorization_request.rs b/identity-wallet/src/state/credentials/reducers/handle_oid4vp_authorization_request.rs index 257794f4c..bca2e1491 100644 --- a/identity-wallet/src/state/credentials/reducers/handle_oid4vp_authorization_request.rs +++ b/identity-wallet/src/state/credentials/reducers/handle_oid4vp_authorization_request.rs @@ -12,16 +12,15 @@ use crate::{ user_prompt::CurrentUserPrompt, AppState, }, - subject::SubjectWrapper, }; use identity_credential::{ credential::Jwt, presentation::Presentation, - sd_jwt_v2::{KeyBindingJwt, Sha256Hasher}, + sd_jwt_v2::Sha256Hasher, sd_jwt_vc::{SdJwtVc, SdJwtVcPresentationBuilder}, }; -use identity_iota::{core::Timestamp, did::CoreDID}; +use identity_iota::did::CoreDID; use jsonwebtoken::Algorithm; use log::info; use oid4vc::oid4vp::{authorization_request::ClientMetadataParameters, oid4vp::PresentationInputType}; @@ -55,12 +54,6 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action .as_ref() .ok_or(MissingManagerError("identity"))? .provider_manager; - let subject = state_guard - .identity_manager - .as_ref() - .ok_or(MissingManagerError("identity"))? - .subject - .clone(); let oid4vp_authorization_request = match serde_json::from_value(serde_json::json!(state.core_utils.active_connection_request)).unwrap() { @@ -76,7 +69,7 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action .unwrap() .iter() .filter_map(|verifiable_credential_record| { - info!("verifiable_credential_record: {:#?}", verifiable_credential_record); + info!("Verifiable Credential Record: {:#?}", verifiable_credential_record); let share_credential = credential_uuids .contains(&verifiable_credential_record.display_credential.id.parse().unwrap()) @@ -95,31 +88,6 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action }) .collect(); - let subject_syntax_type = state - .profile_settings - .preferred_did_methods - .first() - .unwrap() - .to_string(); - - let subject_wrapper = SubjectWrapper { - subject, - subject_syntax_type, - }; - - let sd_jwt_vcs: Vec = verifiable_credentials - .iter() - .filter_map(|(format, vc)| { - if format == &CredentialFormats::VcSdJwt(()) { - Some(vc.clone()) - } else { - None - } - }) - .collect(); - - let now = Timestamp::now_utc(); - let mut verifiable_presentation_input = vec![]; let mut presentation_submissions = vec![]; @@ -128,10 +96,19 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action serde_json::to_string_pretty(&oid4vp_authorization_request).unwrap() ); - let nonce = oid4vp_authorization_request.body.extension.nonce.clone(); - let aud = oid4vp_authorization_request.body.client_id.clone(); + let sd_jwt_vcs: Vec = verifiable_credentials + .iter() + .filter_map(|(format, vc)| (format == &CredentialFormats::VcSdJwt(())).then(|| vc.clone())) + .collect(); + + info!("sd_jwt_vcs: {:#?}", sd_jwt_vcs); + + let verifiable_credentials: Vec = verifiable_credentials + .iter() + .filter_map(|(format, vc)| (format == &CredentialFormats::JwtVcJson(())).then(|| vc.clone())) + .collect(); - let OID4VPClientMetadata { algorithm, .. } = get_oid4vp_client_name_and_logo_uri(&oid4vp_authorization_request); + info!("verifiable_credentials: {:#?}", verifiable_credentials); for sd_jwt_vc in sd_jwt_vcs { let sd_jwt_vc = sd_jwt_vc @@ -139,20 +116,6 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action .and_then(|sd_jwt_vc| SdJwtVc::parse(sd_jwt_vc).ok()) .ok_or(AppError::Error("Failed to parse SD-JWT VC".to_string()))?; - let alg = sd_jwt_vc - .header() - .get("alg") - .and_then(|alg| alg.as_str()) - .map(ToString::to_string) - .unwrap_or(serde_json::json!(algorithm).as_str().unwrap().to_string()); - let kb_jwt = KeyBindingJwt::builder() - .iat(now.to_unix()) - .aud(aud.clone()) - .nonce(nonce.clone()) - .finish(&sd_jwt_vc, &Sha256Hasher::new(), &alg, &subject_wrapper) - .await - .map_err(|e| AppError::Error(format!("Failed to create KeyBindingJwt for SD-JWT VC: {:?}", e)))?; - let (sd_jwt_vc, _) = SdJwtVcPresentationBuilder::new(sd_jwt_vc, &Sha256Hasher::new()) .map_err(|e| { AppError::Error(format!( @@ -160,17 +123,26 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action e )) })? - .attach_key_binding_jwt(kb_jwt) + // TODO: Implement Key Binding + // .attach_key_binding_jwt(kb_jwt) .finish() .map_err(|e| AppError::Error(format!("Failed to attach KeyBindingJwt to SD-JWT VC: {:?}", e)))?; + info!( + "SD-JWT VC: {}", + serde_json::to_string_pretty(&sd_jwt_vc.clone().into_disclosed_object(&Sha256Hasher::new()).unwrap()) + .unwrap() + ); + let presentation_submission = create_sd_jwt_presentation_submission( &oid4vp_authorization_request.body.extension.presentation_definition, &[serde_json::json!(sd_jwt_vc .clone() .into_disclosed_object(&Sha256Hasher::new()) - // FIX THIS - .unwrap())], + .map_err(|e| AppError::Error(format!( + "Failed to create Disclosed Object for SD-JWT VC: {:?}", + e + )))?)], ) .map_err(|e| { AppError::Error(format!( @@ -183,19 +155,6 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action presentation_submissions.push(presentation_submission); } - let verifiable_credentials: Vec = verifiable_credentials - .iter() - .filter_map(|(format, vc)| { - if format == &CredentialFormats::JwtVcJson(()) { - Some(vc.clone()) - } else { - None - } - }) - .collect(); - - info!("verifiable_credentials: {:#?}", verifiable_credentials); - if !verifiable_credentials.is_empty() { let presentation_submission = create_presentation_submission( &oid4vp_authorization_request.body.extension.presentation_definition, @@ -240,16 +199,25 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action )); } - let presentation_submission = if presentation_submissions.len() > 1 { - merge_submissions(presentation_submissions) - } else { - presentation_submissions.pop().ok_or(AppError::Error( - "Failed to create a Presentation Submission".to_string(), - ))? - }; - info!("Verifiable Presentation Input: {:#?}", verifiable_presentation_input); + if verifiable_presentation_input.len() != 1 { + let presentation_submission = if presentation_submissions.len() > 1 { + merge_submissions(presentation_submissions.clone()) + } else { + presentation_submissions.pop().ok_or(AppError::Error( + "Failed to create a Presentation Submission".to_string(), + ))? + }; + + // If multiple presentations are provided, this means that the `vp_token` in the Authorization + // Response will be a sequence which cannot be serialized into a x-www-form-urlencoded string by `reqwest`. + // See: https://github.com/nox/serde_urlencoded/issues/75#issuecomment-648257888 + return Err(AppError::Error( + "Sending multiple presentations is not supported".to_string(), + )); + } + info!("get the provider_manager"); info!("generating response"); @@ -258,7 +226,7 @@ pub async fn handle_oid4vp_authorization_request(state: AppState, action: Action &oid4vp_authorization_request, oid4vp::AuthorizationResponseInput { verifiable_presentation_input, - presentation_submission, + presentation_submission: presentation_submissions.first().clone().unwrap().clone(), }, ) .await @@ -365,8 +333,9 @@ pub fn get_oid4vp_client_name_and_logo_uri( .get(&ClaimFormatDesignation::JwtVcJson) .and_then(|claim_format_property| match claim_format_property { ClaimFormatProperty::Alg(alg) => alg.first().cloned(), + ClaimFormatProperty::SdJwt { sd_jwt_alg_values, .. } => sd_jwt_alg_values.first().cloned(), // TODO: implement `ProofType`. - ClaimFormatProperty::ProofType(_) | _ => None, + ClaimFormatProperty::ProofType(_) => None, }) .unwrap_or(Algorithm::EdDSA); diff --git a/identity-wallet/src/state/qr_code/reducers/read_authorization_request.rs b/identity-wallet/src/state/qr_code/reducers/read_authorization_request.rs index 8eec8d86f..6de82e3a4 100644 --- a/identity-wallet/src/state/qr_code/reducers/read_authorization_request.rs +++ b/identity-wallet/src/state/qr_code/reducers/read_authorization_request.rs @@ -155,30 +155,22 @@ pub async fn read_authorization_request(state: AppState, action: Action) -> Resu verifiable_credentials .iter() .find_map(|verifiable_credential_record| { - if verifiable_credential_record.display_credential.format == CredentialFormats::VcSdJwt(()) + let credential = if verifiable_credential_record.display_credential.format + == CredentialFormats::VcSdJwt(()) { - let unconceiled_credential = serde_json::json!(verifiable_credential_record + serde_json::json!(verifiable_credential_record .verifiable_credential - .as_str() - // FIX THIS - .unwrap() + .as_str()? .parse::() - // FIX THIS - .unwrap() + .ok()? .into_disclosed_object(&Sha256Hasher::new()) - // FIX THIS - .unwrap()); - - evaluate_input(input_descriptor, &unconceiled_credential) - .then_some(verifiable_credential_record.display_credential.id.clone()) + .ok()?) } else { - evaluate_input( - input_descriptor, - &get_unverified_jwt_claims(&verifiable_credential_record.verifiable_credential) - .unwrap(), - ) + get_unverified_jwt_claims(&verifiable_credential_record.verifiable_credential).unwrap() + }; + + evaluate_input(input_descriptor, &credential) .then_some(verifiable_credential_record.display_credential.id.clone()) - } }) .ok_or(NoMatchingCredentialError) }) diff --git a/unime/src/routes/(app)/me/settings/app/trust-list/+layout.ts b/unime/src/routes/(app)/me/settings/app/trust-list/+layout.ts new file mode 100644 index 000000000..d43d0cd2a --- /dev/null +++ b/unime/src/routes/(app)/me/settings/app/trust-list/+layout.ts @@ -0,0 +1 @@ +export const prerender = false; diff --git a/unime/src/routes/(app)/me/settings/app/trust-list/[id]/+page.svelte b/unime/src/routes/(app)/me/settings/app/trust-list/[id]/+page.svelte index f5e442fba..3d8559a7c 100644 --- a/unime/src/routes/(app)/me/settings/app/trust-list/[id]/+page.svelte +++ b/unime/src/routes/(app)/me/settings/app/trust-list/[id]/+page.svelte @@ -134,7 +134,7 @@ {:else}