Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: trust domains based on trust lists #353

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion identity-wallet/bindings/AppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import type { DisplayCredential } from "./credentials/DisplayCredential";
import type { HistoryEvent } from "./history/HistoryEvent";
import type { ProfileSettings } from "./profile_settings/ProfileSettings";
import type { SearchResults } from "./search/SearchResults";
import type { TrustLists } from "./trust_list/TrustLists";

export interface AppState { dids: Record<string, string>, connections: Connections, credentials: Array<DisplayCredential>, search_results: SearchResults, profile_settings: ProfileSettings, current_user_prompt: CurrentUserPrompt | null, user_journey: any | null, debug_messages: Array<string>, history: Array<HistoryEvent>, dev_mode: DevMode, }
export interface AppState { dids: Record<string, string>, connections: Connections, credentials: Array<DisplayCredential>, trust_lists: TrustLists, search_results: SearchResults, profile_settings: ProfileSettings, current_user_prompt: CurrentUserPrompt | null, user_journey: any | null, debug_messages: Array<string>, history: Array<HistoryEvent>, dev_mode: DevMode, }
9 changes: 8 additions & 1 deletion identity-wallet/bindings/actions/Action.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { AddRecentSearch } from "./AddRecentSearch";
import type { AddTrustListEntry } from "./AddTrustListEntry";
import type { CancelUserFlow } from "./CancelUserFlow";
import type { CreateNew } from "./CreateNew";
import type { CredentialOffersSelected } from "./CredentialOffersSelected";
import type { CredentialsSelected } from "./CredentialsSelected";
import type { DeleteRecentSearch } from "./DeleteRecentSearch";
import type { DeleteTrustListEntry } from "./DeleteTrustListEntry";
import type { DevProfile } from "./DevProfile";
import type { EditTrustListEntry } from "./EditTrustListEntry";
import type { QrCodeScanned } from "./QrCodeScanned";
import type { SearchQuery } from "./SearchQuery";
import type { SetLocale } from "./SetLocale";
import type { SetPreferredDidMethod } from "./SetPreferredDidMethod";
import type { SetPreferredKeyType } from "./SetPreferredKeyType";
import type { ToggleTrustListEntry } from "./ToggleTrustListEntry";
import type { TrustListsAdd } from "./TrustListsAdd";
import type { TrustListsDelete } from "./TrustListsDelete";
import type { TrustListsEdit } from "./TrustListsEdit";
import type { UnlockStorage } from "./UnlockStorage";
import type { UpdateCredentialMetadata } from "./UpdateCredentialMetadata";
import type { UpdateProfileSettings } from "./UpdateProfileSettings";
import type { UpdateSortingPreference } from "./UpdateSortingPreference";

export type Action = { "type": "[App] Get state" } | { "type": "[Storage] Unlock", payload: UnlockStorage, } | { "type": "[App] Reset" } | { "type": "[DID] Create new", payload: CreateNew, } | { "type": "[Settings] Set locale", payload: SetLocale, } | { "type": "[Settings] Update profile", payload: UpdateProfileSettings, } | { "type": "[QR Code] Scanned", payload: QrCodeScanned, } | { "type": "[Authenticate] Connection accepted" } | { "type": "[User Flow] Cancel", payload?: CancelUserFlow, } | { "type": "[DEV] Load DEV profile", payload: DevProfile, } | { "type": "[DEV] Toggle DEV mode" } | { "type": "[Authenticate] Credentials selected", payload: CredentialsSelected, } | { "type": "[Credential Offer] Selected", payload: CredentialOffersSelected, } | { "type": "[Credential Metadata] Update", payload: UpdateCredentialMetadata, } | { "type": "[User Journey] Cancel" } | { "type": "[Settings] Update sorting preference", payload: UpdateSortingPreference, } | { "type": "[Search] Query", payload: SearchQuery, } | { "type": "[Search] Add recent", payload: AddRecentSearch, } | { "type": "[Search] Delete recent", payload: DeleteRecentSearch, } | { "type": "[DID] Set preferred method", payload: SetPreferredDidMethod, } | { "type": "[Keys] Set preferred key type", payload: SetPreferredKeyType, };
export type Action = { "type": "[App] Get state" } | { "type": "[Storage] Unlock", payload: UnlockStorage, } | { "type": "[App] Reset" } | { "type": "[DID] Create new", payload: CreateNew, } | { "type": "[Settings] Set locale", payload: SetLocale, } | { "type": "[Settings] Update profile", payload: UpdateProfileSettings, } | { "type": "[QR Code] Scanned", payload: QrCodeScanned, } | { "type": "[Authenticate] Connection accepted" } | { "type": "[User Flow] Cancel", payload?: CancelUserFlow, } | { "type": "[DEV] Load DEV profile", payload: DevProfile, } | { "type": "[DEV] Toggle DEV mode" } | { "type": "[Authenticate] Credentials selected", payload: CredentialsSelected, } | { "type": "[Credential Offer] Selected", payload: CredentialOffersSelected, } | { "type": "[Credential Metadata] Update", payload: UpdateCredentialMetadata, } | { "type": "[User Journey] Cancel" } | { "type": "[Settings] Update sorting preference", payload: UpdateSortingPreference, } | { "type": "[Search] Query", payload: SearchQuery, } | { "type": "[Search] Add recent", payload: AddRecentSearch, } | { "type": "[Search] Delete recent", payload: DeleteRecentSearch, } | { "type": "[DID] Set preferred method", payload: SetPreferredDidMethod, } | { "type": "[Keys] Set preferred key type", payload: SetPreferredKeyType, } | { "type": "[Trust List] Add Entry", payload: AddTrustListEntry, } | { "type": "[Trust List] Edit Entry", payload: EditTrustListEntry, } | { "type": "[Trust List] Delete Entry", payload: DeleteTrustListEntry, } | { "type": "[Trust List] Toggle Entry", payload: ToggleTrustListEntry, } | { "type": "[Trust Lists] Add", payload: TrustListsAdd, } | { "type": "[Trust Lists] Edit", payload: TrustListsEdit, } | { "type": "[Trust Lists] Delete", payload: TrustListsDelete, };
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/AddTrustListEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface AddTrustListEntry { trust_list_id: string, domain: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/DeleteTrustListEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface DeleteTrustListEntry { trust_list_id: string, domain: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/EditTrustListEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface EditTrustListEntry { trust_list_id: string, old_domain: string, new_domain: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/ToggleTrustListEntry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface ToggleTrustListEntry { trust_list_id: string, domain: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/TrustListsAdd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TrustListsAdd { display_name: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/TrustListsDelete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TrustListsDelete { trust_list_id: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/actions/TrustListsEdit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TrustListsEdit { trust_list_id: string, new_display_name: string, }
3 changes: 3 additions & 0 deletions identity-wallet/bindings/trust_list/TrustList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TrustList { id: string, display_name: string, custom: boolean, entries: Record<string, boolean>, }
4 changes: 4 additions & 0 deletions identity-wallet/bindings/trust_list/TrustLists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { TrustList } from "./TrustList";

export type TrustLists = Array<TrustList>;
4 changes: 4 additions & 0 deletions identity-wallet/resources/default_trust_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"display_name": "Impierce (Development)",
"domains": ["agent-dev.impierce.com", "ngdil.com", "selv.iota.org"]
}
19 changes: 19 additions & 0 deletions identity-wallet/src/state/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ mod bindings {
search::actions::{
add_recent_search::AddRecentSearch, delete_recent_search::DeleteRecentSearch, search_query::SearchQuery,
},
trust_list::actions::{
add_trust_list_entry::AddTrustListEntry, delete_trust_list_entry::DeleteTrustListEntry,
edit_trust_list_entry::EditTrustListEntry, toggle_trust_list_entry::ToggleTrustListEntry,
trust_list_add::TrustListsAdd, trust_list_delete::TrustListsDelete, trust_list_edit::TrustListsEdit,
},
};

#[derive(Serialize, Deserialize, TS)]
Expand Down Expand Up @@ -131,5 +136,19 @@ mod bindings {
SetPreferredDidMethod { payload: SetPreferredDidMethod },
#[serde(rename = "[Keys] Set preferred key type")]
SetPreferredKeyType { payload: SetPreferredKeyType },
#[serde(rename = "[Trust List] Add Entry")]
AddTrustListEntry { payload: AddTrustListEntry },
#[serde(rename = "[Trust List] Edit Entry")]
EditTrustListEntry { payload: EditTrustListEntry },
#[serde(rename = "[Trust List] Delete Entry")]
DeleteTrustListEntry { payload: DeleteTrustListEntry },
#[serde(rename = "[Trust List] Toggle Entry")]
ToggleTrustListEntry { payload: ToggleTrustListEntry },
#[serde(rename = "[Trust Lists] Add")]
TrustListsAdd { payload: TrustListsAdd },
#[serde(rename = "[Trust Lists] Edit")]
TrustListsEdit { payload: TrustListsEdit },
#[serde(rename = "[Trust Lists] Delete")]
TrustListsDelete { payload: TrustListsDelete },
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
credentials::VerifiableCredentialRecord,
dev_mode::DevMode,
profile_settings::{AppTheme, Profile},
trust_list::TrustList,
user_prompt::CurrentUserPrompt,
AppState, SUPPORTED_DID_METHODS, SUPPORTED_SIGNING_ALGORITHMS,
},
Expand All @@ -22,7 +23,7 @@ use jsonwebtoken::Algorithm;
use lazy_static::lazy_static;
use log::info;
use oid4vc::{oid4vc_core::Subject, oid4vc_manager::ProviderManager, oid4vci::Wallet};
use serde_json::json;
use serde_json::{json, Value};
use std::{fs::File, io::Write, sync::Arc};

lazy_static! {
Expand Down Expand Up @@ -287,6 +288,31 @@ pub async fn load_ferris_profile() -> Result<AppState, AppError> {
OPEN_BADGE.display_credential.id.clone(),
];

// Import trusted domains
let mut default_trust_list = TrustList::new();
let default_trust_list_json: Value =
serde_json::from_slice::<Value>(include_bytes!("../../../../resources/default_trust_list.json")).unwrap();

default_trust_list.display_name = default_trust_list_json
.get("display_name")
.unwrap()
.as_str()
.unwrap()
.to_string();

default_trust_list.entries = default_trust_list_json
.get("domains")
.unwrap()
.as_array()
.unwrap()
.iter()
.map(|domain| (domain.as_str().unwrap().to_string(), true))
.collect();

default_trust_list.custom = false;

state.trust_lists.insert(default_trust_list);

state.current_user_prompt = Some(CurrentUserPrompt::Redirect {
target: "me".to_string(),
});
Expand Down
3 changes: 3 additions & 0 deletions identity-wallet/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod did;
pub mod profile_settings;
pub mod qr_code;
pub mod search;
pub mod trust_list;
pub mod user_journey;
pub mod user_prompt;

Expand All @@ -28,6 +29,7 @@ use jsonwebtoken::Algorithm;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::VecDeque, pin::Pin};
use trust_list::TrustLists;
use ts_rs::TS;

/// The AppState is the main state of the application shared between the backend and the frontend.
Expand Down Expand Up @@ -87,6 +89,7 @@ pub struct AppState {
pub dids: HashMap<String, String>,
pub connections: Connections,
pub credentials: Vec<DisplayCredential>,
pub trust_lists: TrustLists,
pub search_results: SearchResults,
/// This field contains utils needed for the backend to perform its tasks.
#[serde(skip)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::reducer;
use crate::state::trust_list::reducers::add_entry::add_trust_list_entry;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/AddTrustListEntry.ts")]
pub struct AddTrustListEntry {
pub trust_list_id: String,
pub domain: String,
}

#[typetag::serde(name = "[Trust List] Add Entry")]
impl ActionTrait for AddTrustListEntry {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(add_trust_list_entry)]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::reducer;
use crate::state::trust_list::reducers::delete_entry::delete_trust_list_entry;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/DeleteTrustListEntry.ts")]
pub struct DeleteTrustListEntry {
pub trust_list_id: String,
pub domain: String,
}

#[typetag::serde(name = "[Trust List] Delete Entry")]
impl ActionTrait for DeleteTrustListEntry {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(delete_trust_list_entry)]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::reducer;
use crate::state::trust_list::reducers::edit_entry::edit_trust_list_entry;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/EditTrustListEntry.ts")]
pub struct EditTrustListEntry {
pub trust_list_id: String,
pub old_domain: String,
pub new_domain: String,
}

#[typetag::serde(name = "[Trust List] Edit Entry")]
impl ActionTrait for EditTrustListEntry {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(edit_trust_list_entry)]
}
}
7 changes: 7 additions & 0 deletions identity-wallet/src/state/trust_list/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod add_trust_list_entry;
pub mod delete_trust_list_entry;
pub mod edit_trust_list_entry;
pub mod toggle_trust_list_entry;
pub mod trust_list_add;
pub mod trust_list_delete;
pub mod trust_list_edit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::reducer;
use crate::state::trust_list::reducers::toggle_entry::toggle_trust_list_entry;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/ToggleTrustListEntry.ts")]
pub struct ToggleTrustListEntry {
pub trust_list_id: String,
pub domain: String,
}

#[typetag::serde(name = "[Trust List] Toggle Entry")]
impl ActionTrait for ToggleTrustListEntry {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(toggle_trust_list_entry)]
}
}
19 changes: 19 additions & 0 deletions identity-wallet/src/state/trust_list/actions/trust_list_add.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::reducer;
use crate::state::trust_list::reducers::trust_list_add::trust_list_add;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/TrustListsAdd.ts")]
pub struct TrustListsAdd {
pub display_name: String,
}

#[typetag::serde(name = "[Trust Lists] Add")]
impl ActionTrait for TrustListsAdd {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(trust_list_add)]
}
}
19 changes: 19 additions & 0 deletions identity-wallet/src/state/trust_list/actions/trust_list_delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use crate::reducer;
use crate::state::trust_list::reducers::trust_list_delete::trust_list_delete;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/TrustListsDelete.ts")]
pub struct TrustListsDelete {
pub trust_list_id: String,
}

#[typetag::serde(name = "[Trust Lists] Delete")]
impl ActionTrait for TrustListsDelete {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(trust_list_delete)]
}
}
20 changes: 20 additions & 0 deletions identity-wallet/src/state/trust_list/actions/trust_list_edit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::reducer;
use crate::state::trust_list::reducers::trust_list_edit::trust_list_edit;
use crate::state::{actions::ActionTrait, Reducer};

use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Serialize, Deserialize, Debug, TS, Clone)]
#[ts(export, export_to = "bindings/actions/TrustListsEdit.ts")]
pub struct TrustListsEdit {
pub trust_list_id: String,
pub new_display_name: String,
}

#[typetag::serde(name = "[Trust Lists] Edit")]
impl ActionTrait for TrustListsEdit {
fn reducers<'a>(&self) -> Vec<Reducer<'a>> {
vec![reducer!(trust_list_edit)]
}
}
Loading
Loading