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

Check required attributes #352

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/browser-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Validation of required attributes when adding a credential.

### Fixed

- Incorrect verifiable presentations created, due to incorrect identity/identityProviderIndex used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,25 @@ export default function AddWeb3IdCredential({ onAllow, onReject }: Props) {
() => setError(t('error.schema')),
[schemas.loading]
);

useEffect(() => {
if (schema) {
// Ensure that all attributes required by the schema are in the attributes. If not, then
// the credential should not be allowed to be added.
const missingRequiredAttributeKeys = [];
const requiredAttributes = schema.properties.credentialSubject.properties.attributes.required;
for (const requiredAttribute of requiredAttributes) {
if (!Object.keys(credential.credentialSubject.attributes).includes(requiredAttribute)) {
missingRequiredAttributeKeys.push(requiredAttribute);
}
}

if (missingRequiredAttributeKeys.length > 0) {
setError(t('error.attribute', { attributeKeys: missingRequiredAttributeKeys }));
}
}
}, [schema?.properties.credentialSubject.properties.attributes.required]);

useEffect(() => () => controller.abort(), []);

const localization = useAsyncMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const t: typeof en = {
// We don't translate these because they are mainly for bug reporting.
metadata: en.error.metadata,
schema: en.error.schema,
attribute: en.error.attribute,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const t = {
'We are unable to add the web3Id credential to the wallet due to the following issue, please report this to the issuer:',
metadata: 'We are unable to load the metadata for the credential.',
schema: 'We are unable to load the schema specification for the credential.',
attribute: 'The received credential is missing one or more required attributes ({{ attributeKeys }})',
},
};

Expand Down
Loading