Skip to content

Commit

Permalink
Allow secret line to be overwritten, and use that to restore special …
Browse files Browse the repository at this point in the history
…identity attribute handling
  • Loading branch information
Hjort authored and soer8647 committed Sep 2, 2023
1 parent d59c3aa commit 4b0eff7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { useDisplayAttributeValue } from '@popup/shared/utils/identity-helpers';
import { ConfirmedIdentity, CredentialSchemaSubject, WalletCredential } from '@shared/storage/types';
import React, { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { SecretStatement, useStatementName, useStatementValue } from '../IdProofRequest/DisplayStatement/utils';
import CredentialSelector from './CredentialSelector';
import { DisplayRevealStatements } from './Display/DisplayRevealStatements';
import { DisplaySecretStatements } from './Display/DisplaySecretStatements';
import { OverwriteSecretLine } from './Display/utils';
import { DisplayCredentialStatementProps, SecretStatementV2 } from './utils';

export function DisplayAccount({ option }: { option: WalletCredential }) {
Expand Down Expand Up @@ -65,6 +67,15 @@ export default function AccountStatement({
}
}, []);

const accountCreateSecretLine: OverwriteSecretLine = (statement: SecretStatementV2) => {
const value = useStatementValue(statement as SecretStatement);
const attribute = useStatementName(statement as SecretStatement);
return {
attribute,
value,
};
};

if (!identity) {
return null;
}
Expand Down Expand Up @@ -97,6 +108,7 @@ export default function AccountStatement({
statements={secrets}
formatAttribute={displayAttribute}
schema={IDENTITY_SUBJECT_SCHEMA as CredentialSchemaSubject}
overwriteSecretLine={accountCreateSecretLine}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,22 @@ export function DisplaySecretStatements<Attribute extends AttributeType>({
attributes,
className,
formatAttribute = (_, value) => value.toString(),
overwriteSecretLine = () => ({}),
}: DisplayProps<SecretStatementV2, Attribute>) {
const { t } = useTranslation('web3IdProofRequest', { keyPrefix: 'displayStatement' });
const header = t('headers.secret');

const lines = statements.map((s) => {
const value = getStatementValue(s, schema, t, formatAttribute);
const title = getPropertyTitle(s.attributeTag, schema);
const attribute = getPropertyTitle(s.attributeTag, schema);
const description = getStatementDescription(s, schema, t, formatAttribute);

return {
attribute: title,
value,
isRequirementMet: canProveAtomicStatement(s, attributes),
attribute,
description,
...overwriteSecretLine(s),
isRequirementMet: canProveAtomicStatement(s, attributes),
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { CredentialSchemaSubject } from '@shared/storage/types';
import { ClassName } from 'wallet-common-helpers';
import { SecretStatementV2 } from '../utils';

export function getPropertyTitle(attributeTag: string, schemaSubject: CredentialSchemaSubject) {
// TODO use localization here
const property = schemaSubject.properties.attributes.properties[attributeTag];
return property ? property.title : attributeTag;
}

export type OverwriteSecretLine = (statement: SecretStatementV2) => {
attribute?: string;
value?: string;
description?: string;
};

export type DisplayProps<StatementType, Attribute> = ClassName & {
statements: StatementType[];
attributes: Record<string, Attribute>;
schema: CredentialSchemaSubject;
className: string;
formatAttribute?: (key: string, value: Attribute) => string;
overwriteSecretLine?: OverwriteSecretLine;
};

0 comments on commit 4b0eff7

Please sign in to comment.