Skip to content

Commit

Permalink
Merge pull request #197 from Sphereon-Opensource/feature/MWALL-702
Browse files Browse the repository at this point in the history
feat: use new multi-type credential store
  • Loading branch information
nklomp authored Jul 31, 2024
2 parents 036d72a + f01fe0b commit 27cc5a0
Show file tree
Hide file tree
Showing 19 changed files with 609 additions and 325 deletions.
1 change: 1 addition & 0 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'reflect-metadata';
import {NavigationContainer} from '@react-navigation/native';
import crypto from '@sphereon/isomorphic-webcrypto';
import {backgroundColors} from '@sphereon/ui-components.core';
Expand Down
63 changes: 34 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,37 @@
"@reduxjs/toolkit": "^1.9.7",
"@scure/base": "^1.1.6",
"@sphereon/did-auth-siop": "0.6.4",
"@sphereon/did-provider-oyd": "0.23.1-next.5",
"@sphereon/did-provider-oyd": "0.23.1-next.42",
"@sphereon/isomorphic-webcrypto": "2.4.1-unstable.0",
"@sphereon/oid4vci-client": "0.15.1-next.9",
"@sphereon/oid4vci-common": "0.15.1-next.9",
"@sphereon/pex": "4.0.1",
"@sphereon/pex-models": "^2.2.4",
"@sphereon/react-native-argon2": "2.0.9",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-provider-key": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-resolver-ebsi": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-resolver-key": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.key-manager": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.key-utils": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.kms-local": "0.23.1-next.5",
"@sphereon/ssi-sdk.contact-manager": "0.28.1-next.13",
"@sphereon/ssi-sdk.core": "0.28.1-next.13",
"@sphereon/ssi-sdk.data-store": "0.28.1-next.13",
"@sphereon/ssi-sdk.event-logger": "0.28.1-next.13",
"@sphereon/ssi-sdk.issuance-branding": "0.28.1-next.13",
"@sphereon/ssi-sdk.oid4vci-holder": "0.28.1-next.13",
"@sphereon/ssi-sdk.sd-jwt": "0.28.1-next.13",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.28.1-next.13",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.28.1-next.13",
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.28.1-next.13",
"@sphereon/ssi-types": "0.28.1-next.13",
"@sphereon/ui-components.core": "0.2.1-next.85",
"@sphereon/ui-components.ssi-react-native": "0.2.1-next.85",
"@sphereon/ui-components.credential-branding": "0.2.1-next.85",
"@sphereon/ssi-sdk-ext.did-provider-jwk": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-provider-key": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-resolver-ebsi": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-resolver-key": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-utils": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.key-manager": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.key-utils": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.kms-local": "0.23.1-next.42",
"@sphereon/ssi-sdk.contact-manager": "0.28.1-next.49",
"@sphereon/ssi-sdk.core": "0.28.1-next.49",
"@sphereon/ssi-sdk.credential-store": "0.28.1-next.49",
"@sphereon/ssi-sdk.data-store": "0.28.1-next.49",
"@sphereon/ssi-sdk.event-logger": "0.28.1-next.49",
"@sphereon/ssi-sdk.issuance-branding": "0.28.1-next.49",
"@sphereon/ssi-sdk.oid4vci-holder": "0.28.1-next.49",
"@sphereon/ssi-sdk.sd-jwt": "0.28.1-next.49",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.28.1-next.49",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.28.1-next.49",
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.28.1-next.49",
"@sphereon/ssi-types": "0.28.1-next.49",
"@sphereon/ui-components.core": "0.2.1-unstable.97",
"@sphereon/ui-components.credential-branding": "0.2.1-unstable.97",
"@sphereon/ui-components.ssi-react-native": "0.2.1-unstable.97",
"@veramo/core": "4.2.0",
"@veramo/credential-w3c": "4.2.0",
"@veramo/data-store": "4.2.0",
Expand Down Expand Up @@ -164,6 +165,7 @@
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.24.7",
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-syntax-bigint": "^7.8.3",
"@babel/plugin-syntax-import-assertions": "^7.18.6",
Expand Down Expand Up @@ -248,13 +250,16 @@
"ajv": "^8.12.0",
"@sphereon/isomorphic-argon2": "1.0.1",
"@sphereon/did-auth-siop": "0.6.4",
"@sphereon/ssi-sdk-ext.key-utils": "0.23.1-next.5",
"@sphereon/ssi-sdk-ext.did-utils": "0.23.1-next.5",
"@sphereon/ssi-types": "0.28.1-next.13",
"@sphereon/ssi-sdk.core": "0.28.1-next.13",
"@sphereon/ssi-sdk.data-store": "0.28.1-next.13",
"@sphereon/ssi-sdk-ext.key-utils": "0.23.1-next.42",
"@sphereon/ssi-sdk-ext.did-utils": "0.23.1-next.42",
"@sphereon/ssi-types": "0.28.1-next.49",
"@sphereon/ssi-sdk.core": "0.28.1-next.49",
"@sphereon/ssi-sdk.data-store": "0.28.1-next.49",
"@sphereon/oid4vci-client": "0.15.1-next.9",
"@sphereon/oid4vci-common": "0.15.1-next.9",
"@sphereon/ui-components.core": "0.2.1-unstable.97",
"@sphereon/ui-components.ssi-react-native": "0.2.1-unstable.97",
"@sphereon/ui-components.credential-branding": "0.2.1-unstable.97",
"@sphereon/pex": "4.0.1",
"@sphereon/pex-models": "2.2.4",
"@mattrglobal/bbs-signatures": "npm:empty-npm-package",
Expand Down
10 changes: 9 additions & 1 deletion src/@config/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
DataStoreContactEntities,
DataStoreDigitalCredentialEntities,
DataStoreDigitalCredentialMigrations,
DataStoreIssuanceBrandingEntities,
DataStoreMachineStateEntities,
DataStoreMigrations,
Expand All @@ -16,7 +18,13 @@ const sqliteConfig: ReactNativeConnectionOptions = {
database: 'sphereon-mobile-wallet.sqlite',
location: '.',
driver: typeORMDriver,
entities: [...VeramoDataStoreEntities, ...DataStoreContactEntities, ...DataStoreIssuanceBrandingEntities, ...DataStoreMachineStateEntities],
entities: [
...VeramoDataStoreEntities,
...DataStoreContactEntities,
...DataStoreIssuanceBrandingEntities,
...DataStoreMachineStateEntities,
...DataStoreDigitalCredentialEntities,
],
migrations: [...VeramoDataStoreMigrations, ...DataStoreMigrations],
migrationsRun: false, // We run migrations from code to ensure proper ordering with Redux
synchronize: false, // We do not enable synchronize, as we use migrations from code
Expand Down
12 changes: 7 additions & 5 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {SphereonKeyManagementSystem} from '@sphereon/ssi-sdk-ext.kms-local';
import {ContactManager} from '@sphereon/ssi-sdk.contact-manager';
import {LinkHandlerEventType, LinkHandlerPlugin, LinkHandlers, LogLinkHandler} from '@sphereon/ssi-sdk.core';
import {OnIdentifierCreatedArgs} from '@sphereon/ssi-sdk.oid4vci-holder/src/types/IOID4VCIHolder';
import {ContactStore, IssuanceBrandingStore, MachineStateStore} from '@sphereon/ssi-sdk.data-store';
import {ContactStore, DigitalCredentialStore, IssuanceBrandingStore, MachineStateStore} from '@sphereon/ssi-sdk.data-store';
import {IssuanceBranding} from '@sphereon/ssi-sdk.issuance-branding';
import {OID4VCIHolder, OnContactIdentityCreatedArgs, OnCredentialStoredArgs} from '@sphereon/ssi-sdk.oid4vci-holder';
import {DidAuthSiopOpAuthenticator} from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth';
Expand Down Expand Up @@ -46,6 +46,7 @@ import {dispatchVerifiableCredential} from '../store/actions/credential.actions'
import {generateSalt, generateDigest} from '../utils';
import {ADD_IDENTITY_SUCCESS} from '../types/store/contact.action.types';
import {KeyManagementSystemEnum, SupportedDidMethodEnum, TAgentTypes} from '../types';
import {CredentialStore} from '@sphereon/ssi-sdk.credential-store';

export const didResolver = new Resolver({
...getUniResolver(SupportedDidMethodEnum.DID_ETHR, {
Expand Down Expand Up @@ -126,6 +127,7 @@ const agentPlugins: Array<IAgentPlugin> = [
]),
keyStore: privateKeyStore,
}),
new CredentialStore({store: new DigitalCredentialStore(dbConnection)}),
new OID4VCIHolder({
onContactIdentityCreated: async (args: OnContactIdentityCreatedArgs): Promise<void> => {
store.dispatch({type: ADD_IDENTITY_SUCCESS, payload: args});
Expand Down Expand Up @@ -166,11 +168,11 @@ export const cmUpdateContact = agent.cmUpdateContact;
export const cmRemoveContact = agent.cmRemoveContact;
export const cmAddIdentity = agent.cmAddIdentity;
export const didManagerGet = agent.didManagerGet;
export const dataStoreORMGetVerifiableCredentials = agent.dataStoreORMGetVerifiableCredentials;
export const dataStoreSaveVerifiableCredential = agent.dataStoreSaveVerifiableCredential;
export const keyManagerSign = agent.keyManagerSign;
export const dataStoreGetVerifiableCredential = agent.dataStoreGetVerifiableCredential;
export const dataStoreDeleteVerifiableCredential = agent.dataStoreDeleteVerifiableCredential;
export const credentialStoreGetVerifiableCredentials = agent.crsGetUniqueCredentials;
export const credentialStoreGetVerifiableCredentialByIdOrHash = agent.crsGetUniqueCredentialByIdOrHash;
export const credentialStoreAddCredential = agent.crsAddCredential;
export const credentialStoreDeleteVerifiableCredential = agent.crsDeleteCredential;
export const createVerifiableCredential = agent.createVerifiableCredential;
export const ibAddCredentialBranding = agent.ibAddCredentialBranding;
export const ibGetCredentialBranding = agent.ibGetCredentialBranding;
Expand Down
11 changes: 7 additions & 4 deletions src/components/views/SSICredentialRequiredViewItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {backgroundColors, gradientsColors, statusColors} from '@sphereon/ui-components.core';
import {UniqueVerifiableCredential} from '@veramo/core';
import React, {FC, ForwardedRef} from 'react';
import {View} from 'react-native';

Expand All @@ -22,12 +21,14 @@ import {fontStyle} from '../../../styles/typography';
import {getCredentialTypeAsString} from '../../../utils';
import SSICheckmarkIcon from '../../assets/icons/SSICheckmarkIcon';
import {LinearGradientText} from 'react-native-linear-gradient-text';
import {UniqueDigitalCredential} from '@sphereon/ssi-sdk.credential-store';
import {VerifiableCredential} from '@veramo/core';

export interface Props {
id: string;
title: string;
selected: Array<UniqueVerifiableCredential>;
available?: Array<UniqueVerifiableCredential>;
selected: Array<UniqueDigitalCredential>;
available?: Array<UniqueDigitalCredential>;
purpose?: string;
isMatching: boolean;
listIndex: number;
Expand Down Expand Up @@ -55,7 +56,9 @@ const SSICredentialRequiredViewItem: FC<Props> = React.forwardRef((props: Props,
{purpose && <CredentialPurposeCaption>{purpose}</CredentialPurposeCaption>}
{selected.length > 0 ? (
// TODO currently only supporting one selected credential, Also fix the naming
<CredentialSelectedCaption>{getCredentialTypeAsString(selected[0].verifiableCredential)}</CredentialSelectedCaption>
<CredentialSelectedCaption>
{getCredentialTypeAsString(selected[0].originalVerifiableCredential as VerifiableCredential)}
</CredentialSelectedCaption>
) : available && available.length === 0 ? (
<NoneAvailableCaption>{translate('credentials_required_no_available_label')}</NoneAvailableCaption>
) : (
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/IntentHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {readFile} from '../../services/fileService';
import store from '../../store';
import {storeVerifiableCredential} from '../../store/actions/credential.actions';
import {NavigationBarRoutesEnum, ScreenRoutesEnum, ToastTypeEnum} from '../../types';
import {parseDeepLink} from '../../utils';
import {parseDeepLink, showToast} from '../../utils';
import {toNonPersistedCredentialSummary} from '@sphereon/ui-components.credential-branding';
import {showToast} from '../../utils';
import LockingHandler from '../LockingHandler';
import {CredentialRole} from '@sphereon/ssi-sdk.data-store';

const debug: Debugger = Debug(`${APP_ID}:IntentHandler`);

Expand Down Expand Up @@ -193,7 +193,7 @@ class IntentHandler {
screen: ScreenRoutesEnum.CREDENTIAL_DETAILS,
params: {
rawCredential: vc,
credential: await toNonPersistedCredentialSummary(vc),
credential: await toNonPersistedCredentialSummary(vc, CredentialRole.HOLDER),
primaryAction: {
caption: translate('action_accept_label'),
onPress: async (): Promise<void> =>
Expand Down
9 changes: 7 additions & 2 deletions src/navigation/machines/oid4vciStateNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
} from '@sphereon/ssi-sdk.data-store';
import {
CreateContactEvent,
OID4VCIContext as OID4VCIContextType,
OID4VCIMachineEvents,
OID4VCIMachineInterpreter,
OID4VCIMachineNavigationArgs,
OID4VCIMachineState,
OID4VCIMachineStates,
OID4VCIProviderProps,
OID4VCIContext as OID4VCIContextType,
} from '@sphereon/ssi-sdk.oid4vci-holder';
import {translate} from '../../localization/Localization';
import RootNavigation from './../rootNavigation';
Expand Down Expand Up @@ -241,7 +241,12 @@ const navigateReviewCredentials = async (args: OID4VCIMachineNavigationArgs): Pr
params: {
headerTitle: translate(signingMode ? 'credential_sign_title' : 'credential_offer_title'),
rawCredential: credentialsToAccept[0].rawVerifiableCredential,
credential: await toNonPersistedCredentialSummary(credentialsToAccept[0].uniformVerifiableCredential!, localeBranding, contact),
credential: await toNonPersistedCredentialSummary(
credentialsToAccept[0].uniformVerifiableCredential!,
CredentialRole.HOLDER,
localeBranding,
contact,
),
primaryAction: {
caption: translate(signingMode ? 'action_sign_label' : 'action_accept_label'),
onPress: onNext,
Expand Down
8 changes: 4 additions & 4 deletions src/providers/authentication/SIOPv2Provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CheckLinkedDomain, SupportedVersion, VerifiedAuthorizationRequest} from '@sphereon/did-auth-siop';
import {getIdentifier, getKey, determineKid} from '@sphereon/ssi-sdk-ext.did-utils';
import {ConnectionType, DidAuthConfig} from '@sphereon/ssi-sdk.data-store';
import {determineKid, getIdentifier, getKey} from '@sphereon/ssi-sdk-ext.did-utils';
import {ConnectionType, CredentialRole, DidAuthConfig} from '@sphereon/ssi-sdk.data-store';
import {OID4VP, OpSession, VerifiableCredentialsWithDefinition, VerifiablePresentationWithDefinition} from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth';
import {CredentialMapper, PresentationSubmission} from '@sphereon/ssi-types'; // FIXME we should fix the export of these objects
import {IIdentifier} from '@veramo/core';
Expand Down Expand Up @@ -92,7 +92,7 @@ export const siopSendAuthorizationResponse = async (

const credentialsAndDefinitions = args.verifiableCredentialsWithDefinition
? args.verifiableCredentialsWithDefinition
: await oid4vp.filterCredentialsAgainstAllDefinitions();
: await oid4vp.filterCredentialsAgainstAllDefinitions(CredentialRole.HOLDER);
const domain =
((await request.authorizationRequest.getMergedProperty('client_id')) as string) ??
request.issuer ??
Expand All @@ -111,7 +111,7 @@ export const siopSendAuthorizationResponse = async (
}
}

presentationsAndDefs = await oid4vp.createVerifiablePresentations(credentialsAndDefinitions, {
presentationsAndDefs = await oid4vp.createVerifiablePresentations(CredentialRole.HOLDER, credentialsAndDefinitions, {
identifierOpts: {identifier},
proofOpts: {
nonce: session.nonce,
Expand Down
20 changes: 15 additions & 5 deletions src/screens/SSICredentialsOverviewScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import {
SSIRippleContainerStyled as ItemContainer,
SSIStatusBarDarkModeStyled as StatusBar,
} from '../../styles/components';
import {IUser, IUserIdentifier, MainRoutesEnum, RootState, ScreenRoutesEnum, StackParamList} from '../../types';
import {getOriginalVerifiableCredential} from '../../utils';
import {IUser, IUserIdentifier, MainRoutesEnum, RootState, ScreenRoutesEnum, StackParamList, ToastTypeEnum} from '../../types';
import {getOriginalVerifiableCredential, showToast} from '../../utils';
import {backgroundColors, borderColors} from '@sphereon/ui-components.core';
import {CredentialSummary} from '@sphereon/ui-components.credential-branding';
import {Loggers} from '@sphereon/ssi-types';

export const logger = Loggers.DEFAULT.get('sphereon:screens');

interface IProps extends NativeStackScreenProps<StackParamList, ScreenRoutesEnum.CREDENTIALS_OVERVIEW> {
getVerifiableCredentials: () => void;
Expand Down Expand Up @@ -61,13 +64,19 @@ class SSICredentialsOverviewScreen extends PureComponent<IProps, IState> {
};

onItemPress = async (credential: CredentialSummary): Promise<void> => {
getVerifiableCredential({hash: credential.hash}).then((vc: VerifiableCredential) =>
try {
const vc: VerifiableCredential = await getVerifiableCredential({credentialRole: credential.credentialRole, hash: credential.hash});

this.props.navigation.navigate(ScreenRoutesEnum.CREDENTIAL_DETAILS, {
rawCredential: getOriginalVerifiableCredential(vc),
credential,
showActivity: false,
}),
);
});
} catch (e) {
// onPress doesn't handle promise rejections, so log it for now.
logger.error('onItemPress failed', e);
showToast(ToastTypeEnum.TOAST_ERROR, {message: translate('information_retrieve_failed_toast_message', {message: (e as Error).message})});
}
};

renderItem = (itemInfo: ListRenderItemInfo<CredentialSummary>): JSX.Element => {
Expand All @@ -84,6 +93,7 @@ class SSICredentialsOverviewScreen extends PureComponent<IProps, IState> {
expirationDate={itemInfo.item.expirationDate}
credentialStatus={itemInfo.item.credentialStatus}
properties={[]}
credentialRole={itemInfo.item.credentialRole}
/>
);

Expand Down
Loading

0 comments on commit 27cc5a0

Please sign in to comment.