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

[INJIMOB-2963]: Credential offer endpoint changes. #1830

Open
wants to merge 2 commits into
base: credential-offer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fileignoreconfig:
- filename: screens/Home/MyVcs/GetIdInputModal.tsx
checksum: 5c736ed79a372d0ffa7c02eb33d0dc06edbbb08d120978ff287f5f06cd6c7746
- filename: shared/openId4VCI/Utils.ts
checksum: 78473ce25cd52c8d07da9ba98683bdb64ae83a9de8fa907c62f2ebeca7dd21dc
checksum: 40b9af91348c8c80e4da7920374110d56f3782aa8f1317e211bdea02efb0d943
- filename: shared/cryptoutil/cryptoUtil.ts
checksum: 281f061ae6eb722c75c2caf2bdfb5b1bf72f292b471318d972c898c5a972c65f
- filename: shared/telemetry/TelemetryConstants.js
Expand Down
2 changes: 1 addition & 1 deletion components/ui/svg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ export class SvgImage {
}

function getIssuerLogo(props: displayType) {
return {uri: props.logo.url};
return {uri: props.logo.url || props.logo.uri};
}

interface LogoProps {
Expand Down
54 changes: 51 additions & 3 deletions machines/Issuers/IssuersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
REQUEST_TIMEOUT,
isIOS,
EXPIRED_VC_ERROR_CODE,
CredentialOfferParams,
} from '../../shared/constants';
import {assign, send} from 'xstate';
import {StoreEvents} from '../store';
Expand All @@ -26,7 +27,7 @@ import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants';
import {NativeModules} from 'react-native';
import {KeyTypes} from '../../shared/cryptoutil/KeyTypes';
import {VCActivityLog} from '../../components/ActivityLogEvent';
import {isNetworkError} from '../../shared/Utils';
import {getSearchParamsFromUri, isNetworkError} from '../../shared/Utils';

const {RNSecureKeystoreModule} = NativeModules;
export const IssuersActions = (model: any) => {
Expand Down Expand Up @@ -234,8 +235,13 @@ export const IssuersActions = (model: any) => {
}),

setSelectedIssuers: model.assign({
selectedIssuer: (context: any, event: any) =>
context.issuers.find(issuer => issuer.issuer_id === event.id),
selectedIssuer: (context: any, event: any) => {
if (context.credentialOfferData) {
return context.credentialOfferData;
} else {
return context.issuers.find(issuer => issuer.issuer_id === event.id);
}
},
}),

updateIssuerFromWellknown: model.assign({
Expand All @@ -248,6 +254,43 @@ export const IssuersActions = (model: any) => {
}),
}),

updateCredentialOfferValues: assign((context: any, event: any) => {
try {
const searchParams = getSearchParamsFromUri(event.data);
if (!searchParams) return {};

const credentialOfferURI = searchParams.get(CredentialOfferParams.URI);
const credentialOfferEncodedData = searchParams.get(
CredentialOfferParams.DATA,
);

return {
...(credentialOfferURI && {credentialOfferURI}),
...(credentialOfferEncodedData && {
credentialOfferData: JSON.parse(
decodeURIComponent(credentialOfferEncodedData),
),
}),
};
} catch (error) {
console.error('Error extracting credential offer:', error);
return {};
}
}),

setCredentialOfferData: model.assign({
credentialOfferData: (context: any, event: any) => ({
...context.credentialOfferData,
...(event.data?.credential_issuer && {
credential_issuer: event.data.credential_issuer,
}),
...(event.data?.credential_configuration_ids && {
credential_configuration_ids: event.data.credential_configuration_ids,
}),
...(event.data?.grants && {grants: event.data.grants}),
}),
}),

updateAuthorizationEndpoint: model.assign({
selectedIssuer: (context: any, event: any) => ({
...context.selectedIssuer,
Expand Down Expand Up @@ -343,6 +386,11 @@ export const IssuersActions = (model: any) => {
verificationErrorMessage: () => '',
}),

resetCredentialOfferValues: model.assign({
credentialOfferURI: () => '',
credentialOfferData: () => null,
}),

sendDownloadingFailedToVcMeta: send(
(_: any) => ({
type: 'VC_DOWNLOADING_FAILED',
Expand Down
3 changes: 3 additions & 0 deletions machines/Issuers/IssuersEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ export const IssuersEvents = {
STORE_ERROR: (error: Error, requester?: string) => ({error, requester}),
RESET_VERIFY_ERROR: () => ({}),
SELECTED_CREDENTIAL_TYPE: (credType: CredentialTypes) => ({credType}),
SCAN_CREDENTIAL_OFFER_QR_CODE: () => ({}),
QR_CODE_SCANNED: (data: string) => ({data}),
SELECTED_CREDENTIAL_OFFER_ISSUER: (id: string) => ({id}),
};
5 changes: 5 additions & 0 deletions machines/Issuers/IssuersGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {ErrorMessage, OIDCErrors} from '../../shared/openId4VCI/Utils';
import {isHardwareKeystoreExists} from '../../shared/cryptoutil/cryptoUtil';
import {BiometricCancellationError} from '../../shared/error/BiometricCancellationError';
import {VerificationErrorType} from '../../shared/vcjs/verifyCredential';
import {getSearchParamsFromUri} from '../../shared/Utils';
import {CredentialOfferParams} from '../../shared/constants';

export const IssuersGuards = () => {
return {
Expand Down Expand Up @@ -57,5 +59,8 @@ export const IssuersGuards = () => {
const errorMessage = event.data.message;
return errorMessage === ErrorMessage.GENERIC;
},
hasCredentialOfferUri: (_: any, event: any) => {
return getSearchParamsFromUri(event.data).get(CredentialOfferParams.URI);
},
};
};
48 changes: 48 additions & 0 deletions machines/Issuers/IssuersMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,48 @@ export const IssuersMachine = model.createMachine(
],
target: 'downloadIssuerWellknown',
},
SCAN_CREDENTIAL_OFFER_QR_CODE: {
target: 'scanCredentialOfferQrCode',
},
SELECTED_CREDENTIAL_OFFER_ISSUER: {
actions: [
'setSelectedIssuerId',
'setLoadingReasonAsSettingUp',
'setSelectedIssuers',
],
target: 'downloadIssuerWellknown',
},
},
},
scanCredentialOfferQrCode: {
description: 'waits for the user to scan Qr Code',
on: {
QR_CODE_SCANNED: [
{
actions: 'updateCredentialOfferValues',
cond: 'hasCredentialOfferUri',
target: 'downloadCredentialOfferData',
},
{
actions: 'updateCredentialOfferValues',
target: 'selectingIssuer',
},
],
},
},

downloadCredentialOfferData: {
description: 'fetches the credential offer data',
invoke: {
src: 'downloadCredentialOfferData',
onDone: {
actions: 'setCredentialOfferData',
target: 'selectingIssuer',
},
onError: {
actions: 'resetCredentialOfferValues',
target: 'selectingIssuer',
},
},
},
downloadIssuerWellknown: {
Expand Down Expand Up @@ -537,3 +579,9 @@ export interface issuerType {
authorizationEndpoint: string;
credential_issuer_host: string;
}

export interface CredentialOfferData {
credential_issuer: string;
credential_configuration_ids: [string];
grants: object;
}
32 changes: 29 additions & 3 deletions machines/Issuers/IssuersMachine.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface Typegen0 {
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'done.invoke.issuersMachine.downloadCredentialOfferData:invocation[0]': {
type: 'done.invoke.issuersMachine.downloadCredentialOfferData:invocation[0]';
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'done.invoke.issuersMachine.downloadCredentialTypes:invocation[0]': {
type: 'done.invoke.issuersMachine.downloadCredentialTypes:invocation[0]';
data: unknown;
Expand Down Expand Up @@ -76,6 +81,10 @@ export interface Typegen0 {
type: 'error.platform.issuersMachine.displayIssuers:invocation[0]';
data: unknown;
};
'error.platform.issuersMachine.downloadCredentialOfferData:invocation[0]': {
type: 'error.platform.issuersMachine.downloadCredentialOfferData:invocation[0]';
data: unknown;
};
'error.platform.issuersMachine.downloadCredentialTypes:invocation[0]': {
type: 'error.platform.issuersMachine.downloadCredentialTypes:invocation[0]';
data: unknown;
Expand Down Expand Up @@ -113,6 +122,7 @@ export interface Typegen0 {
invokeSrcNameMap: {
checkInternet: 'done.invoke.checkInternet';
downloadCredential: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]';
downloadCredentialOfferData: 'done.invoke.issuersMachine.downloadCredentialOfferData:invocation[0]';
downloadCredentialTypes: 'done.invoke.issuersMachine.downloadCredentialTypes:invocation[0]';
downloadIssuerWellknown: 'done.invoke.issuersMachine.downloadIssuerWellknown:invocation[0]';
downloadIssuersList: 'done.invoke.issuersMachine.displayIssuers:invocation[0]';
Expand All @@ -130,6 +140,7 @@ export interface Typegen0 {
| 'downloadIssuerWellknown'
| 'loadKeyPair'
| 'logDownloaded'
| 'resetCredentialOfferValues'
| 'resetError'
| 'resetLoadingReason'
| 'resetSelectedCredentialType'
Expand All @@ -140,6 +151,7 @@ export interface Typegen0 {
| 'sendErrorEndEvent'
| 'sendImpressionEvent'
| 'sendSuccessEndEvent'
| 'setCredentialOfferData'
| 'setCredentialTypeListDownloadFailureError'
| 'setCredentialWrapper'
| 'setError'
Expand Down Expand Up @@ -168,12 +180,14 @@ export interface Typegen0 {
| 'storeVerifiableCredentialData'
| 'storeVerifiableCredentialMeta'
| 'updateAuthorizationEndpoint'
| 'updateCredentialOfferValues'
| 'updateIssuerFromWellknown'
| 'updateSelectedIssuerWellknownResponse'
| 'updateVerificationErrorMessage';
delays: never;
guards:
| 'canSelectIssuerAgain'
| 'hasCredentialOfferUri'
| 'hasKeyPair'
| 'hasUserCancelledBiometric'
| 'isCustomSecureKeystore'
Expand All @@ -188,6 +202,7 @@ export interface Typegen0 {
services:
| 'checkInternet'
| 'downloadCredential'
| 'downloadCredentialOfferData'
| 'downloadCredentialTypes'
| 'downloadIssuerWellknown'
| 'downloadIssuersList'
Expand All @@ -206,6 +221,7 @@ export interface Typegen0 {
logDownloaded:
| 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'
| 'error.platform.issuersMachine.verifyingCredential:invocation[0]';
resetCredentialOfferValues: 'error.platform.issuersMachine.downloadCredentialOfferData:invocation[0]';
resetError:
| 'RESET_ERROR'
| 'TRY_AGAIN'
Expand Down Expand Up @@ -238,6 +254,7 @@ export interface Typegen0 {
sendErrorEndEvent: 'error.platform.issuersMachine.verifyingCredential:invocation[0]';
sendImpressionEvent: 'done.invoke.issuersMachine.displayIssuers:invocation[0]';
sendSuccessEndEvent: 'done.invoke.issuersMachine.verifyingCredential:invocation[0]';
setCredentialOfferData: 'done.invoke.issuersMachine.downloadCredentialOfferData:invocation[0]';
setCredentialTypeListDownloadFailureError: 'error.platform.issuersMachine.downloadCredentialTypes:invocation[0]';
setCredentialWrapper: 'done.invoke.issuersMachine.downloadCredentials:invocation[0]';
setError:
Expand All @@ -255,6 +272,7 @@ export interface Typegen0 {
| 'error.platform.issuersMachine.performAuthorization.getKeyPairFromKeystore:invocation[0]';
setLoadingReasonAsSettingUp:
| 'RESET_ERROR'
| 'SELECTED_CREDENTIAL_OFFER_ISSUER'
| 'SELECTED_ISSUER'
| 'TRY_AGAIN'
| 'done.invoke.issuersMachine.performAuthorization:invocation[0]';
Expand All @@ -269,8 +287,8 @@ export interface Typegen0 {
setPrivateKey: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]';
setPublicKey: 'done.invoke.issuersMachine.generateKeyPair:invocation[0]';
setSelectedCredentialType: 'SELECTED_CREDENTIAL_TYPE';
setSelectedIssuerId: 'SELECTED_ISSUER';
setSelectedIssuers: 'SELECTED_ISSUER';
setSelectedIssuerId: 'SELECTED_CREDENTIAL_OFFER_ISSUER' | 'SELECTED_ISSUER';
setSelectedIssuers: 'SELECTED_CREDENTIAL_OFFER_ISSUER' | 'SELECTED_ISSUER';
setSelectedKey: 'done.invoke.issuersMachine.performAuthorization.setSelectedKey:invocation[0]';
setSupportedCredentialTypes: 'done.invoke.issuersMachine.downloadCredentialTypes:invocation[0]';
setTokenResponse: 'done.invoke.issuersMachine.performAuthorization:invocation[0]';
Expand All @@ -293,13 +311,15 @@ export interface Typegen0 {
| 'done.invoke.issuersMachine.verifyingCredential:invocation[0]'
| 'error.platform.issuersMachine.verifyingCredential:invocation[0]';
updateAuthorizationEndpoint: 'done.invoke.issuersMachine.fetchAuthorizationEndpoint:invocation[0]';
updateCredentialOfferValues: 'QR_CODE_SCANNED';
updateIssuerFromWellknown: 'done.invoke.issuersMachine.downloadIssuerWellknown:invocation[0]';
updateSelectedIssuerWellknownResponse: 'done.invoke.issuersMachine.downloadIssuerWellknown:invocation[0]';
updateVerificationErrorMessage: 'error.platform.issuersMachine.verifyingCredential:invocation[0]';
};
eventsCausingDelays: {};
eventsCausingGuards: {
canSelectIssuerAgain: 'TRY_AGAIN';
hasCredentialOfferUri: 'QR_CODE_SCANNED';
hasKeyPair: 'done.invoke.issuersMachine.checkKeyPair:invocation[0]';
hasUserCancelledBiometric:
| 'error.platform.issuersMachine.downloadCredentials:invocation[0]'
Expand All @@ -321,8 +341,12 @@ export interface Typegen0 {
downloadCredential:
| 'done.invoke.issuersMachine.checkKeyPair:invocation[0]'
| 'done.invoke.issuersMachine.generateKeyPair:invocation[0]';
downloadCredentialOfferData: 'QR_CODE_SCANNED';
downloadCredentialTypes: 'done.invoke.issuersMachine.downloadIssuerWellknown:invocation[0]';
downloadIssuerWellknown: 'SELECTED_ISSUER' | 'TRY_AGAIN';
downloadIssuerWellknown:
| 'SELECTED_CREDENTIAL_OFFER_ISSUER'
| 'SELECTED_ISSUER'
| 'TRY_AGAIN';
downloadIssuersList: 'CANCEL' | 'TRY_AGAIN' | 'xstate.init';
fetchAuthorizationEndpoint: 'SELECTED_CREDENTIAL_TYPE';
generateKeyPair: 'done.invoke.issuersMachine.checkKeyPair:invocation[0]';
Expand All @@ -344,6 +368,7 @@ export interface Typegen0 {
| 'checkKeyPair'
| 'displayIssuers'
| 'done'
| 'downloadCredentialOfferData'
| 'downloadCredentialTypes'
| 'downloadCredentials'
| 'downloadCredentials.idle'
Expand All @@ -361,6 +386,7 @@ export interface Typegen0 {
| 'performAuthorization.idle'
| 'performAuthorization.setSelectedKey'
| 'performAuthorization.userCancelledBiometric'
| 'scanCredentialOfferQrCode'
| 'selectingCredentialType'
| 'selectingIssuer'
| 'storing'
Expand Down
4 changes: 3 additions & 1 deletion machines/Issuers/IssuersModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import {AppServices} from '../../shared/GlobalContext';
import {VCMetadata} from '../../shared/VCMetadata';
import {IssuersEvents} from './IssuersEvents';
import {issuerType} from './IssuersMachine';
import {CredentialOfferData, issuerType} from './IssuersMachine';

export const IssuersModel = createModel(
{
Expand All @@ -31,6 +31,8 @@ export const IssuersModel = createModel(
vcMetadata: {} as VCMetadata,
keyType: 'RS256' as string,
wellknownKeyTypes: [] as string[],
credentialOfferData: null as CredentialOfferData | null,
credentialOfferURI: '' as string,
},
{
events: IssuersEvents,
Expand Down
8 changes: 8 additions & 0 deletions machines/Issuers/IssuersSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ export function selectSelectingCredentialType(state: State) {
export function selectSupportedCredentialTypes(state: State) {
return state.context.supportedCredentialTypes;
}

export function selectIsQrScanning(state: State) {
return state.matches('scanCredentialOfferQrCode');
}

export function selectCredentialOfferData(state: State) {
return state.context.credentialOfferData;
}
Loading