Skip to content

Commit

Permalink
WIP pick credential for SignIn
Browse files Browse the repository at this point in the history
  • Loading branch information
edeykholt committed Sep 26, 2024
1 parent 64a1783 commit 4558c70
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 218 deletions.
195 changes: 151 additions & 44 deletions KeriAuth.BrowserExtension/UI/Components/CredentialDisplay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -5,69 +5,176 @@
@using System.Text.Json;
@using System.Diagnostics;
@using System.Diagnostics.CodeAnalysis;
@using KeriAuth.BrowserExtension.Helper.DictionaryConverters
@using static KeriAuth.BrowserExtension.Helper.Identicon;
@inject ILogger<CredentialDisplay> logger
@inject IJSRuntime js
@inject ISnackbar snackbar
@inject IStorageService storageService

<MudPaper Class="mb-2 pa-3">
<MudText Typo="Typo.caption">Issued By:</MudText>
<MudStack Row="true">
<MudText>DID Issuer</MudText>
</MudStack>
<div class="mt-3">
<MudText Typo="Typo.caption">Claims:</MudText>
</div>
@{
// var claims = WalletCredential.PrismCredential.GetClaims();
}
<MudExpansionPanels Dense="true" Class="mt-3 mb-3">
<MudExpansionPanel Dense="true" Text="Show Details">
<MudStack Row="true" Class="mb-1">
<div>
<MudText Typo="Typo.body2"><strong>Created at:</strong> datetime...</MudText>
</div>
</MudStack>
<MudStack Row="true" Class="mb-1">
<MudText Typo="Typo.body2"><strong>Signature:</strong></MudText>
<MudText Typo="Typo.body2" Style="max-height: 20px;">
<Ellipsis IncludeCopyIcon="true" StringContent="signature...."></Ellipsis>
</MudText>
</MudStack>
<MudStack Row="true" Class="mb-1">
<MudText Typo="Typo.body2"><strong>Json:</strong></MudText>
<MudText Typo="Typo.body2" Style="max-height: 20px;">
<Ellipsis IncludeCopyIcon="true" StringContent=" json ...."></Ellipsis>
</MudText>
</MudStack>
<MudCard Class="pa-3">
<MudStack>
@{
string SchemaTitle = " ";
string SchemaDescr = " ";
try
{
SchemaTitle = DictionaryConverter.GetValueByPath(credential, "schema.title")?.Value?.ToString() ?? string.Empty;
SchemaDescr = DictionaryConverter.GetValueByPath(credential, "schema.description")?.Value?.ToString() ?? string.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting schema title or description");
}
finally
{
if (displayDetail == CredentialDisplayDetail.Minimal)
{
<MudText><b>@SchemaTitle </b></MudText>
}
else if (displayDetail == CredentialDisplayDetail.Typical)
{
<MudText><b>@SchemaTitle </b><br /><em>@SchemaDescr</em></MudText>
}
}
}

@if (displayDetail != CredentialDisplayDetail.Minimal)
{

// Issued date
string dt = " ";
try
{
dt = DictionaryConverter.GetValueByPath(credential, "sad.a.dt")?.Value?.ToString()?.Substring(0, 10) ?? string.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting date issued");
}
finally
{
<MudText>Issued: <b>@dt</b></MudText>
}

</MudExpansionPanel>
</MudExpansionPanels>
<MudStack Row="true">
<MudButton Variant="Variant.Filled" EndIcon="@Icons.Material.Filled.CopyAll">Copy</MudButton>
<MudSpacer></MudSpacer>
<MudIconButton Icon="@Icons.Material.Filled.Delete" Variant="Variant.Text" OnClick="async () => await DeleteCredential()"></MudIconButton>



// Issuer
string iLabel = " ";
string iValue = " ";
try
{
iLabel = DictionaryConverter.GetValueByPath(credential, "schema.properties.i.description")?.Value?.ToString() ?? String.Empty;
iValue = DictionaryConverter.GetValueByPath(credential, "sad.i")?.Value.ToString()?.Substring(0, 10) ?? String.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting issuer AID or date issued");
}
finally
{
if (iLabel != String.Empty)
{
<MudText>@iLabel: <b>@iValue</b></MudText>

/*
<MudIcon ViewBox="0 0 100 100" Icon="@MakeIdenticon(iValue)" Style="border-style:solid; border-color:black; border-width:2px; border-radius:50%; width:35px; height:35px; overflow:hidden;" />
*/
}
}
}

@{
// Issuee
string personValue = " ";
string personLabel = " ";
string aiLabel = " ";
string iValueValue = " ";

string ecrLabel = " ";
string ecrValue = " ";
try
{
// Get label for personLegalName
var collectionResult = DictionaryConverter.GetValueByPath(credential, "schema.properties.a.oneOf");
var collection = collectionResult?.Value as List<object>;
Debug.Assert(collection is not null && collection.Count > 1);
var secondItem = collection[1] as Dictionary<string, object>;
Debug.Assert(secondItem is not null);
personLabel = DictionaryConverter.GetValueByPath(secondItem, "properties.personLegalName.description")?.Value.ToString() ?? String.Empty;

// Get value for personLegalName
personValue = DictionaryConverter.GetValueByPath(credential, "sad.a.personLegalName")?.Value.ToString() ?? String.Empty;

// get label for i (e.g. Issuee AID or LE Issuer AID (typo in schema?), depending on credential Type)
aiLabel = DictionaryConverter.GetValueByPath(secondItem, "properties.i.description")?.Value.ToString() ?? String.Empty;
// get value for i
iValueValue = DictionaryConverter.GetValueByPath(credential, "sad.a.i")?.Value.ToString() ?? String.Empty;

ecrLabel = @DictionaryConverter.GetValueByPath(secondItem, "properties.engagementContextRole.description")?.Value.ToString() ?? String.Empty;
ecrValue = @DictionaryConverter.GetValueByPath(credential, "sad.a.engagementContextRole")?.Value.ToString() ?? String.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting personLegalName or i or engagementContextRole");
}
finally
{
if (personLabel != String.Empty && displayDetail != CredentialDisplayDetail.Minimal)
{
<MudText>@personLabel: <b>@personValue</b></MudText>
}
if (aiLabel != String.Empty)
{
<MudStack Row Style="align-items: center;">
<MudIcon ViewBox="0 0 100 100" Icon="@MakeIdenticon(iValueValue)" Style="border-style:solid; border-color:black; border-width:2px; border-radius:50%; width:35px; height:35px; overflow:hidden;" />
<MudText Style="overflow-wrap: anywhere;">@aiLabel: <br /><b>@iValueValue</b></MudText>
</MudStack>
}
if (ecrLabel != String.Empty)
{
<MudText>@ecrLabel: <b>@ecrValue</b></MudText>
}
}
}
</MudStack>
</MudPaper>
<MudStack Row>
<MudSpacer />
<MudIconButton Style="padding: 0px !important;" Size="Size.Small" OnClick="async () => await UIHelper.Copy2Clipboard(JsonSerializer.Serialize(credential))" Icon="@Icons.Material.Filled.ContentCopy" aria-label="delete"></MudIconButton>
</MudStack>
</MudCard>

@code {

/*
[Parameter]
[NotNull]
public EventCallback<int> OnCredentialDeleted { get; init; }
*/

// [Parameter]
// [NotNull]
// public WalletCredential? WalletCredential { get; init; }
[Parameter]
[NotNull]
public Dictionary<string, object>? credential { get; init; }


[Parameter]
[NotNull]
public CredentialDisplayDetail displayDetail { get; init; }

public enum CredentialDisplayDetail
{
Minimal,
Typical,
Full
}

/*
private async Task DeleteCredential()
{
{
// Debug.Assert(WalletCredential is not null);
// await WalletService.DeleteCredential(WalletCredential);
await OnCredentialDeleted.InvokeAsync();
StateHasChanged();
}
}
*/

}
17 changes: 16 additions & 1 deletion KeriAuth.BrowserExtension/UI/Layouts/DialogLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
<MudSnackbarProvider Style="z-index:9999" />

<MudLayout id="@this.GetType().Name" Style="overflow-y:hidden; overflow-x:hidden; box-sizing: border-box; position:absolute; top:0; width:100vw;">
@Body

<MudAppBar Elevation="2" Style="padding-left: 0px; padding-right: 0px; height:var(--bt-appbar-height);">
<MudStack Style="height:inherit; width: 100%; padding-bottom:8px;" Class="d-flex pt-2" Row="true">
<MudButton Style="padding: 10px; height:fit-content; align-self:center; border:none; border-radius:16px; background:#00000020;">
<img src="images/512_keri_logo.png" alt="Icon" style="width: 24px; height: 24px;" />
<MudText Style="margin-left:7px; font-size:larger; color:hsl(183deg 100% 50%); font-variant: small-caps;">KeriAuth</MudText>
</MudButton>

<MudSpacer />
</MudStack>
</MudAppBar>
<MudMainContent Class="bt-main-content" Style="left:0; top:61px;">
<MudContainer MaxWidth="MaxWidth.Large" Style="height:inherit; min-height:inherit; padding-left:0; padding-right:0;">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>

<style>
Expand Down
130 changes: 3 additions & 127 deletions KeriAuth.BrowserExtension/UI/Pages/CredentialsPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,133 +34,9 @@
@if (credentials.Any())
{
<MudStack>
@{
foreach (var credential in credentials)
{
<MudCard Class="pa-3">
<MudStack>
@{
string SchemaTitle = " ";
string SchemaDescr = " ";
try
{
SchemaTitle = DictionaryConverter.GetValueByPath(credential, "schema.title")?.Value?.ToString() ?? string.Empty;
SchemaDescr = DictionaryConverter.GetValueByPath(credential, "schema.description")?.Value?.ToString() ?? string.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting schema title or description");
}
finally
{
<MudText><b>@SchemaTitle </b><br /><em>@SchemaDescr</em></MudText>
}
}

@{
// Issued date
string dt = " ";
try
{
dt = DictionaryConverter.GetValueByPath(credential, "sad.a.dt")?.Value?.ToString()?.Substring(0, 10) ?? string.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting date issued");
}
finally
{
<MudText>Issued: <b>@dt</b></MudText>
}
}

@{
// Issuer
string iLabel = " ";
string iValue = " ";
try
{
iLabel = DictionaryConverter.GetValueByPath(credential, "schema.properties.i.description")?.Value?.ToString() ?? String.Empty;
iValue = DictionaryConverter.GetValueByPath(credential, "sad.i")?.Value.ToString()?.Substring(0, 10) ?? String.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting issuer AID or date issued");
}
finally
{
if (iLabel != String.Empty)
{
<MudText>@iLabel: <b>@iValue</b></MudText>

/*
<MudIcon ViewBox="0 0 100 100" Icon="@MakeIdenticon(iValue)" Style="border-style:solid; border-color:black; border-width:2px; border-radius:50%; width:35px; height:35px; overflow:hidden;" />
*/
}
}
}

@{
// Issuee
string personValue = " ";
string personLabel = " ";
string aiLabel = " ";
string iValueValue = " ";

string ecrLabel = " ";
string ecrValue = " ";
try
{
// Get label for personLegalName
var collectionResult = DictionaryConverter.GetValueByPath(credential, "schema.properties.a.oneOf");
var collection = collectionResult?.Value as List<object>;
Debug.Assert(collection is not null && collection.Count > 1);
var secondItem = collection[1] as Dictionary<string, object>;
Debug.Assert(secondItem is not null);
personLabel = DictionaryConverter.GetValueByPath(secondItem, "properties.personLegalName.description")?.Value.ToString() ?? String.Empty;

// Get value for personLegalName
personValue = DictionaryConverter.GetValueByPath(credential, "sad.a.personLegalName")?.Value.ToString() ?? String.Empty;

// get label for i (e.g. Issuee AID or LE Issuer AID (typo in schema?), depending on credential Type)
aiLabel = DictionaryConverter.GetValueByPath(secondItem, "properties.i.description")?.Value.ToString() ?? String.Empty;
// get value for i
iValueValue = DictionaryConverter.GetValueByPath(credential, "sad.a.i")?.Value.ToString() ?? String.Empty;

ecrLabel = @DictionaryConverter.GetValueByPath(secondItem, "properties.engagementContextRole.description")?.Value.ToString() ?? String.Empty;
ecrValue = @DictionaryConverter.GetValueByPath(credential, "sad.a.engagementContextRole")?.Value.ToString() ?? String.Empty;
}
catch (Exception ex)
{
logger.LogError(ex, "Error getting personLegalName or i or engagementContextRole");
}
finally
{
if (personLabel != String.Empty)
{
<MudText>@personLabel: <b>@personValue</b></MudText>
}
if (aiLabel != String.Empty)
{
<MudStack Row Style="align-items: center;">
<MudIcon ViewBox="0 0 100 100" Icon="@MakeIdenticon(iValueValue)" Style="border-style:solid; border-color:black; border-width:2px; border-radius:50%; width:35px; height:35px; overflow:hidden;" />
<MudText>@aiLabel: </MudText>
<MudText><b>@iValueValue</b></MudText>
</MudStack>
}
if (ecrLabel != String.Empty)
{
<MudText>@ecrLabel: <b>@ecrValue</b></MudText>
}
}
}
</MudStack>
<MudStack Row>
<MudSpacer />
<MudIconButton Style="padding: 0px !important;" Size="Size.Small" OnClick="async () => await UIHelper.Copy2Clipboard(JsonSerializer.Serialize(credential))" Icon="@Icons.Material.Filled.ContentCopy" aria-label="delete"></MudIconButton>
</MudStack>
</MudCard>
}
@foreach (var credential in credentials)
{
<CredentialDisplay credential="@credential" displayDetail="@CredentialDisplay.CredentialDisplayDetail.Typical" />
}
</MudStack>
}
Expand Down
Loading

0 comments on commit 4558c70

Please sign in to comment.