impierce / identity-wallet

A Tauri-based Identity Wallet for people to manage Decentralized Identities and Verifiable Credentials.
https://www.impierce.com
Apache License 2.0
17 stars 4 forks source link

feat: treat Credential Offers and OID4VP Authorization Requests as connections #157

Closed nanderstabel closed 3 months ago

nanderstabel commented 3 months ago

Description of change

This change ensures that when there is a CredentialsShared or a CredentialsAdded event with a new Connection, that a ConnectionAdded event will be fired first.

This change also ensures that the connection_url can be derived from both the credential_issuer_url and the redirect_url in a similar fashion. This means that if a server is both a Credential Issuer as well as a Relying Party, then it's connection_url while in the Credential Issuer role will be equal to it's connection_url while in the Relying Party role.

This in turn enables us to use the issuer/client_name together with the connection_url to generate Connection IDs (instead of just based on the issuer/client_name which has severe security risks).

Abstracting the code for inserting and updating of Connections results in cleaner and less error-prone code:

        let previously_connected = state.connections.contains(connection_url, &issuer_name);
        let mut connections = state.connections;
        let connection = connections.insert_or_update(connection_url, &issuer_name);

At a later stage we could implement something similar for History, e.g:


        // History
        if !history_credentials.is_empty() {
            // Only add a `ConnectionAdded` event if the connection was not previously connected.
            if !previously_connected {
                state.history.push(HistoryEvent {
                    connection_name: connection.name.clone(),
                    event_type: EventType::ConnectionAdded,
                    connection_id: connection.id.clone(),
                    date: connection.last_interacted.clone(),
                    credentials: vec![],
                });
            }
            state.history.push(HistoryEvent {
                connection_name: connection.name.clone(),
                event_type: EventType::CredentialsAdded,
                connection_id: connection.id.clone(),
                date: connection.last_interacted.clone(),
                credentials: history_credentials,
            });
        }

would be converted to:


        // History
        if !history_credentials.is_empty() {
            // Only add a `ConnectionAdded` event if the connection was not previously connected.
            if !previously_connected {
                state.history.append_connection_added_event(connection, vec![]);
            }
            state.history.append_credentials_added_event(connection, history_credentials);
        }

Links to any relevant issues

fixes #125

How the change has been tested

Definition of Done checklist

Add an x to the boxes that are relevant to your changes.