Skip to content

Commit

Permalink
Merge pull request #185 from Sphereon-Opensource/feature/CWALL-166
Browse files Browse the repository at this point in the history
feature/CWALL-166
  • Loading branch information
BtencateSphereon authored May 7, 2024
2 parents ee17479 + 11a83b9 commit 4ea80ea
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 222 deletions.
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@
"@sphereon/ssi-sdk-ext.key-manager": "0.19.0",
"@sphereon/ssi-sdk-ext.key-utils": "0.19.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.19.0",
"@sphereon/ssi-sdk.contact-manager": "0.23.4",
"@sphereon/ssi-sdk.core": "0.23.4",
"@sphereon/ssi-sdk.data-store": "0.23.4",
"@sphereon/ssi-sdk.event-logger": "0.23.4",
"@sphereon/ssi-sdk.issuance-branding": "0.23.4",
"@sphereon/ssi-sdk.oid4vci-holder": "0.23.4",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.23.4",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.23.4",
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.23.4",
"@sphereon/ssi-sdk.contact-manager": "0.23.5-next.12",
"@sphereon/ssi-sdk.core": "0.23.5-next.12",
"@sphereon/ssi-sdk.data-store": "0.23.5-next.12",
"@sphereon/ssi-sdk.event-logger": "0.23.5-next.12",
"@sphereon/ssi-sdk.issuance-branding": "0.23.5-next.12",
"@sphereon/ssi-sdk.oid4vci-holder": "0.23.5-next.12",
"@sphereon/ssi-sdk.siopv2-oid4vp-op-auth": "0.23.5-next.12",
"@sphereon/ssi-sdk.vc-handler-ld-local": "0.23.5-next.12",
"@sphereon/ssi-sdk.xstate-machine-persistence": "0.23.5-next.12",
"@sphereon/ssi-types": "0.23.4",
"@sphereon/ui-components.core": "0.1.3-unstable.151",
"@sphereon/ui-components.ssi-react-native": "0.1.3-unstable.151",
"@sphereon/ui-components.core": "0.2.0",
"@sphereon/ui-components.ssi-react-native": "0.2.0",
"@veramo/core": "4.2.0",
"@veramo/credential-w3c": "4.2.0",
"@veramo/data-store": "4.2.0",
Expand Down Expand Up @@ -251,8 +251,8 @@
"@sphereon/ssi-sdk-ext.did-utils": "0.19.0",
"@sphereon/ssi-sdk-ext.kms-local": "0.19.0",
"@sphereon/ssi-sdk-ext.key-manager": "0.19.0",
"@sphereon/ssi-sdk.data-store": "0.23.4",
"@sphereon/ssi-sdk.contact-manager": "0.23.4",
"@sphereon/ssi-sdk.data-store": "0.23.5-next.12",
"@sphereon/ssi-sdk.contact-manager": "0.23.5-next.12",
"@sphereon/oid4vci-client": "0.10.3",
"@sphereon/oid4vci-common": "0.10.3",
"@sphereon/pex": "3.3.3",
Expand Down
170 changes: 76 additions & 94 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,23 @@ import {getResolver as getDidEbsiResolver} from '@sphereon/ssi-sdk-ext.did-resol
import {getDidJwkResolver} from '@sphereon/ssi-sdk-ext.did-resolver-jwk';
import {SphereonKeyManager} from '@sphereon/ssi-sdk-ext.key-manager';
import {SphereonKeyManagementSystem} from '@sphereon/ssi-sdk-ext.kms-local';
import {ContactManager, IContactManager} from '@sphereon/ssi-sdk.contact-manager';
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 {IIssuanceBranding, IssuanceBranding} from '@sphereon/ssi-sdk.issuance-branding';
import {
IOID4VCIHolder,
OID4VCIHolder,
OnContactIdentityCreatedArgs,
OnCredentialStoredArgs,
OnGetCredentialsArgs,
} from '@sphereon/ssi-sdk.oid4vci-holder';
import {DidAuthSiopOpAuthenticator, IDidAuthSiopOpAuthenticator} from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth';
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';
import {
CredentialHandlerLDLocal,
ICredentialHandlerLDLocal,
MethodNames,
SphereonEd25519Signature2018,
SphereonEd25519Signature2020,
SphereonJsonWebSignature2020,
} from '@sphereon/ssi-sdk.vc-handler-ld-local';
import {IMachineStatePersistence, MachineStatePersistence, MachineStatePersistEventType} from '@sphereon/ssi-sdk.xstate-machine-persistence';
import {createAgent, ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver} from '@veramo/core';
import {CredentialPlugin, ICredentialIssuer} from '@veramo/credential-w3c';
import {MachineStatePersistence, MachineStatePersistEventType} from '@sphereon/ssi-sdk.xstate-machine-persistence';
import {createAgent, IAgentPlugin} from '@veramo/core';
import {CredentialPlugin} from '@veramo/credential-w3c';
import {DataStore, DataStoreORM, DIDStore, KeyStore, PrivateKeyStore} from '@veramo/data-store';
import {DIDManager} from '@veramo/did-manager';
import {EthrDIDProvider} from '@veramo/did-provider-ethr';
Expand All @@ -38,18 +32,16 @@ import {OrPromise} from '@veramo/utils';
import {Resolver} from 'did-resolver';
import {DataSource} from 'typeorm';
import {getResolver as webDIDResolver} from 'web-did-resolver';

import {DID_PREFIX, DIF_UNIRESOLVER_RESOLVE_URL} from '../@config/constants';
import {LdContexts} from '../@config/credentials';
import {DB_CONNECTION_NAME, DB_ENCRYPTION_KEY} from '../@config/database';
import {addLinkListeners} from '../handlers/LinkHandlers';
import {oid4vciStateNavigationListener} from '../navigation/machines/oid4vciStateNavigation';
import OpenId4VcIssuanceProvider from '../providers/credential/OpenId4VcIssuanceProvider';
import {getDbConnection} from '../services/databaseService';
import {dispatchIdentifier} from '../services/identityService';
import store from '../store';
import {dispatchVerifiableCredential} from '../store/actions/credential.actions';
import {KeyManagementSystemEnum, QrTypesEnum, SupportedDidMethodEnum} from '../types';
import {ADD_IDENTITY_SUCCESS} from '../types/store/contact.action.types';
import {KeyManagementSystemEnum, SupportedDidMethodEnum, TAgentTypes} from '../types';

export const didResolver = new Resolver({
...getUniResolver(SupportedDidMethodEnum.DID_ETHR, {
Expand Down Expand Up @@ -85,81 +77,72 @@ const privateKeyStore: PrivateKeyStore = new PrivateKeyStore(dbConnection, new S

export const linkHandlers: LinkHandlers = new LinkHandlers().add(new LogLinkHandler());

const agent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IDidAuthSiopOpAuthenticator &
IContactManager &
ICredentialPlugin &
ICredentialIssuer &
ICredentialHandlerLDLocal &
IIssuanceBranding &
IOID4VCIHolder &
IMachineStatePersistence
>({
plugins: [
new DataStore(dbConnection),
new DataStoreORM(dbConnection),
new SphereonKeyManager({
store: new KeyStore(dbConnection),
kms: {
local: new SphereonKeyManagementSystem(privateKeyStore),
},
}),
new DIDManager({
store: new DIDStore(dbConnection),
defaultProvider: `${DID_PREFIX}:${SupportedDidMethodEnum.DID_KEY}`,
providers: didProviders,
}),
new DIDResolverPlugin({
resolver: didResolver,
}),
new DidAuthSiopOpAuthenticator(),
new ContactManager({
store: new ContactStore(dbConnection),
}),
new IssuanceBranding({
store: new IssuanceBrandingStore(dbConnection),
}),
new CredentialPlugin(),
new CredentialHandlerLDLocal({
contextMaps: [LdContexts],
suites: [
new SphereonEd25519Signature2018(),
new SphereonEd25519Signature2020(),
// new SphereonBbsBlsSignature2020(),
new SphereonJsonWebSignature2020(),
],
bindingOverrides: new Map([
['verifyCredentialLD', MethodNames.verifyCredentialLDLocal],
['verifyPresentationLD', MethodNames.verifyPresentationLDLocal],
['createVerifiableCredentialLD', MethodNames.createVerifiableCredentialLDLocal],
['createVerifiablePresentationLD', MethodNames.createVerifiablePresentationLDLocal],
]),
keyStore: privateKeyStore,
}),
new OID4VCIHolder({
onGetCredentials: async (args: OnGetCredentialsArgs) => new OpenId4VcIssuanceProvider().getCredentials(args),
onContactIdentityCreated: async (args: OnContactIdentityCreatedArgs): Promise<void> => {
store.dispatch({type: ADD_IDENTITY_SUCCESS, payload: args});
},
onCredentialStored: async (args: OnCredentialStoredArgs): Promise<void> => {
const {credential, vcHash} = args;
store.dispatch<any>(dispatchVerifiableCredential(vcHash, credential));
},
}),
new MachineStatePersistence({
store: new MachineStateStore(dbConnection),
eventTypes: [MachineStatePersistEventType.EVERY],
}),
new LinkHandlerPlugin({
eventTypes: [LinkHandlerEventType.LINK_HANDLER_URL],
handlers: linkHandlers,
}),
],
const agentPlugins: Array<IAgentPlugin> = [
new DataStore(dbConnection),
new DataStoreORM(dbConnection),
new SphereonKeyManager({
store: new KeyStore(dbConnection),
kms: {
local: new SphereonKeyManagementSystem(privateKeyStore),
},
}),
new DIDManager({
store: new DIDStore(dbConnection),
defaultProvider: `${DID_PREFIX}:${SupportedDidMethodEnum.DID_KEY}`,
providers: didProviders,
}),
new DIDResolverPlugin({
resolver: didResolver,
}),
new DidAuthSiopOpAuthenticator(),
new ContactManager({
store: new ContactStore(dbConnection),
}),
new IssuanceBranding({
store: new IssuanceBrandingStore(dbConnection),
}),
new CredentialPlugin(),
new CredentialHandlerLDLocal({
contextMaps: [LdContexts],
suites: [
new SphereonEd25519Signature2018(),
new SphereonEd25519Signature2020(),
// new SphereonBbsBlsSignature2020(),
new SphereonJsonWebSignature2020(),
],
bindingOverrides: new Map([
['verifyCredentialLD', MethodNames.verifyCredentialLDLocal],
['verifyPresentationLD', MethodNames.verifyPresentationLDLocal],
['createVerifiableCredentialLD', MethodNames.createVerifiableCredentialLDLocal],
['createVerifiablePresentationLD', MethodNames.createVerifiablePresentationLDLocal],
]),
keyStore: privateKeyStore,
}),
new OID4VCIHolder({
onContactIdentityCreated: async (args: OnContactIdentityCreatedArgs): Promise<void> => {
store.dispatch({type: ADD_IDENTITY_SUCCESS, payload: args});
},
onCredentialStored: async (args: OnCredentialStoredArgs): Promise<void> => {
const {credential, vcHash} = args;
store.dispatch<any>(dispatchVerifiableCredential(vcHash, credential));
},
onIdentifierCreated: async (args: OnIdentifierCreatedArgs): Promise<void> => {
const {identifier} = args;
await dispatchIdentifier({identifier});
},
}),
new MachineStatePersistence({
store: new MachineStateStore(dbConnection),
eventTypes: [MachineStatePersistEventType.EVERY],
}),
new LinkHandlerPlugin({
eventTypes: [LinkHandlerEventType.LINK_HANDLER_URL],
handlers: linkHandlers,
}),
];

const agent = createAgent<TAgentTypes>({
plugins: agentPlugins,
});

export const didManagerCreate = agent.didManagerCreate;
Expand All @@ -180,7 +163,6 @@ export const ibAddCredentialBranding = agent.ibAddCredentialBranding;
export const ibGetCredentialBranding = agent.ibGetCredentialBranding;
export const ibCredentialLocaleBrandingFrom = agent.ibCredentialLocaleBrandingFrom;
export const ibRemoveCredentialBranding = agent.ibRemoveCredentialBranding;
export const oid4vciHolderGetMachineInterpreter = agent.oid4vciHolderGetMachineInterpreter;

export default agent;

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/LinkHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {oid4vciStateNavigationListener} from '../../navigation/machines/oid4vciS
import {QrTypesEnum} from '../../types';
import {SIOPv2OID4VPLinkHandler} from './SIOPLinkHandler';

export const addLinkListeners = (linkHandlers: LinkHandlers, context: IAgentContext<any>) => {
export const addLinkListeners = (linkHandlers: LinkHandlers, context: IAgentContext<any>): void => {
linkHandlers.add([
new OID4VCIHolderLinkHandler({
protocols: [QrTypesEnum.OPENID_CREDENTIAL_OFFER + ':', QrTypesEnum.OPENID_INITIATE_ISSUANCE + ':'],
protocols: [`${QrTypesEnum.OPENID_CREDENTIAL_OFFER}:`, `${QrTypesEnum.OPENID_INITIATE_ISSUANCE}:`],
stateNavigationListener: oid4vciStateNavigationListener,
context,
}),
Expand Down
4 changes: 2 additions & 2 deletions src/localization/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"connection_details_view_details": "Details",
"action_confirm_label": "Bevestigen",
"action_cancel_label": "Annuleren",
"action_decline_label": "weigeren",
"action_accept_label": "accepteren",
"action_decline_label": "Weigeren",
"action_accept_label": "Accepteren",
"verification_code_title": "Voer uw\nverificatie code in",
"verification_code_subtitle": "U zult een code nodig hebben om aanspraak te maken op de {{credentialName}} credential.",
"verification_code_accessibility_label": "Verificatie code",
Expand Down
5 changes: 3 additions & 2 deletions src/navigation/machines/oid4vciStateNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const navigateAddContact = async (args: OID4VCIMachineNavigationArgs): Promise<v
},
// FIXME maybe its nicer if we can also just use the id only
// TODO using the predefined party type from the contact migrations here
// TODO this is not used as the screen itself adds one, look at the params of the screen, this is not being passed in
partyType: {
id: '3875c12e-fdaa-4ef6-a340-c936e054b627',
type: PartyTypeEnum.ORGANIZATION,
Expand Down Expand Up @@ -250,9 +251,9 @@ const navigateReviewCredentialOffers = async (args: OID4VCIMachineNavigationArgs
const navigateFinal = async (args: OID4VCIMachineNavigationArgs): Promise<void> => {
const {navigation, oid4vciMachine} = args;

debug(`Stopping oid4vci machine...`);
debug('Stopping oid4vci machine...');
oid4vciMachine.stop();
debug(`Stopped oid4vci machine`);
debug('Stopped oid4vci machine');

navigation.navigate(NavigationBarRoutesEnum.CREDENTIALS, {
screen: ScreenRoutesEnum.CREDENTIALS_OVERVIEW,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/credential/OpenId4VcIssuanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
OpenId4VCIVersion,
ProofOfPossessionCallbacks,
toAuthorizationResponsePayload,
CredentialOfferFormatJwtVcJsonLdAndLdpVc,
} from '@sphereon/oid4vci-common';
import {CredentialOfferFormatJwtVcJsonLdAndLdpVc} from '@sphereon/oid4vci-common/lib/types/Generic.types';
import {KeyUse} from '@sphereon/ssi-sdk-ext.did-resolver-jwk';
import {getFirstKeyWithRelation} from '@sphereon/ssi-sdk-ext.did-utils';
import {IBasicCredentialLocaleBranding} from '@sphereon/ssi-sdk.data-store';
Expand Down
1 change: 1 addition & 0 deletions src/screens/SSIContactAddScreen/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class SSIContactAddScreen extends PureComponent<IProps, IState> {
componentDidMount(): void {
const {onAliasChange} = this.props.route.params;
this.hardwareBackPressListener = BackHandler.addEventListener('hardwareBackPress', this.onBack);
// FIXME we should set the default name in the machine and pass that to the screen
if (onAliasChange) {
void onAliasChange(this.state.contactAlias);
}
Expand Down
22 changes: 17 additions & 5 deletions src/services/identityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import {didManagerCreate, didManagerFind, didManagerGet} from '../agent';
import store from '../store';
import {getContacts} from '../store/actions/contact.actions';
import {addIdentifier} from '../store/actions/user.actions';
import {ICreateIdentifierArgs, ICreateOrGetIdentifierArgs, IdentifierAliasEnum, KeyManagementSystemEnum, SupportedDidMethodEnum} from '../types';
import {
ICreateIdentifierArgs,
ICreateOrGetIdentifierArgs,
IdentifierAliasEnum,
IDispatchIdentifierArgs,
KeyManagementSystemEnum,
SupportedDidMethodEnum,
} from '../types';

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

Expand All @@ -23,15 +30,20 @@ export const createIdentifier = async (args?: ICreateIdentifierArgs): Promise<II
options: args?.createOpts?.options,
});

await dispatchIdentifier({identifier});

return identifier;
};

export const dispatchIdentifier = async (args: IDispatchIdentifierArgs): Promise<void> => {
const {identifier} = args;
if (store.getState().user.users.size > 0) {
await store.dispatch<any>(addIdentifier({did: identifier.did})).then(() => {
setTimeout(() => {
await store.dispatch<any>(addIdentifier({did: identifier.did})).then((): void => {
setTimeout((): void => {
store.dispatch<any>(getContacts());
}, 1000);
});
}

return identifier;
};

export const getOrCreatePrimaryIdentifier = async (args?: ICreateOrGetIdentifierArgs): Promise<IIdentifier> => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/signatureService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createJWT, Signer} from 'did-jwt';

import {keyManagerSign} from '../agent';
import {ISignJwtArgs} from '../types';
import {signatureAlgorithmFromKey} from '../utils/KeyUtils';
import {signatureAlgorithmFromKey} from '../utils';

export const signJWT = async (args: ISignJwtArgs): Promise<string> => {
const options = {
Expand Down
22 changes: 22 additions & 0 deletions src/types/agent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IResolver} from '@veramo/core';
import {IDidAuthSiopOpAuthenticator} from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth';
import {IContactManager} from '@sphereon/ssi-sdk.contact-manager';
import {ICredentialIssuer} from '@veramo/credential-w3c';
import {ICredentialHandlerLDLocal} from '@sphereon/ssi-sdk.vc-handler-ld-local';
import {IIssuanceBranding} from '@sphereon/ssi-sdk.issuance-branding';
import {IOID4VCIHolder} from '@sphereon/ssi-sdk.oid4vci-holder';
import {IMachineStatePersistence} from '@sphereon/ssi-sdk.xstate-machine-persistence';

export type TAgentTypes = IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IDidAuthSiopOpAuthenticator &
IContactManager &
ICredentialPlugin &
ICredentialIssuer &
ICredentialHandlerLDLocal &
IIssuanceBranding &
IOID4VCIHolder &
IMachineStatePersistence;
Loading

0 comments on commit 4ea80ea

Please sign in to comment.