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

feat: [SIW-1844] Add trustmark generation functions #156

Merged
merged 27 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
429e854
feat: add `getCredentialTrustmarkJwt` function
mastro993 Nov 14, 2024
2d680a0
fix: exports
mastro993 Nov 15, 2024
ec20c72
chore: delete unused typo
mastro993 Nov 15, 2024
68484be
feat: add trustmark reducer and thunks
mastro993 Nov 15, 2024
2228b00
feat: add trustmark screen
mastro993 Nov 15, 2024
86f2dd9
chore: add `rn-qr-generator`
mastro993 Nov 15, 2024
bd6625e
feat: add trustmkar qr code generation
mastro993 Nov 15, 2024
b24425c
refactor: move trustmark to credential store
mastro993 Nov 16, 2024
e201527
refactor: remove modal to simply debug
mastro993 Nov 16, 2024
0b7cae3
docs: update documentation
mastro993 Nov 17, 2024
d0ddceb
fix: trustmark url
mastro993 Nov 17, 2024
0f03f20
fix: tsc errors
mastro993 Nov 18, 2024
a3863c5
chore: add document number obfuscation
mastro993 Nov 18, 2024
32cd260
Update example/src/screens/TrustmarkScreen.tsx
mastro993 Nov 18, 2024
5582429
refactor: credential document number check
mastro993 Nov 18, 2024
1529158
fix: reducer
mastro993 Nov 18, 2024
ae8c8c1
chore: check holder public key
mastro993 Nov 18, 2024
642b76b
docs: update function documentation
mastro993 Nov 19, 2024
487e770
chore: avoid adding `subtyp` if doc number not set
mastro993 Nov 19, 2024
cc872b1
fix: imports
mastro993 Nov 19, 2024
88bd9ee
chore: compare key thumbrpints
mastro993 Nov 19, 2024
3e46f0c
fix: tests
mastro993 Nov 19, 2024
177c488
chore: remove delete key
mastro993 Nov 19, 2024
b6c4f17
chore: update trustmark function signature and implementation
mastro993 Nov 19, 2024
352cefc
fix: exports
mastro993 Nov 19, 2024
30f2130
chore: update example app
mastro993 Nov 19, 2024
58769d2
chore: fix trustmark screen
mastro993 Nov 19, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Different flows are provided to perform common operations. Each flow is a set of
- [Issuance](./src/credential/issuance/README.md)
- [Presentation](./src/credential/presentation/README.md) (TODO)
- [Status](./src/credential/status/README.md)
- [Trustmark](./src/credential/trustmark/README.md)

### Example

Expand Down
4 changes: 3 additions & 1 deletion example/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ PRE_WALLET_PID_PROVIDER_BASE_URL='example'
PRE_WALLET_EAA_PROVIDER_BASE_URL='example'
PRE_REDIRECT_URI='example://cb'
PRE_GOOGLE_CLOUD_PROJECT_NUMBER='000000000000'
PRE_VERIFIER_BASE_URL='example'

# PROD SECTION
PROD_WALLET_PROVIDER_BASE_URL='example'
PROD_WALLET_PID_PROVIDER_BASE_URL='example'
PROD_WALLET_EAA_PROVIDER_BASE_URL='example'
PROD_REDIRECT_URI='example://cb'
PROD_GOOGLE_CLOUD_PROJECT_NUMBER='000000000000'
PROD_GOOGLE_CLOUD_PROJECT_NUMBER='000000000000'
PROD_VERIFIER_BASE_URL='example'
12 changes: 12 additions & 0 deletions example/ios/Podfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"react-redux": "^9.1.2",
"redux": "^5.0.1",
"redux-persist": "^6.0.0",
"rn-qr-generator": "^1.4.2",
"typesafe-actions": "^5.1.0",
"url-parse": "^1.5.10"
},
Expand Down
63 changes: 63 additions & 0 deletions example/src/components/QrCodeImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from "react";
import {
Image,
useWindowDimensions,
type ImageSourcePropType,
} from "react-native";
import Placeholder from "rn-placeholder";
import RNQRGenerator from "rn-qr-generator";

export type QrCodeImageProps = {
// Value to decode and present using a QR Code
value: string;
// Relative or absolute size of the QRCode image
size?: number | `${number}%`;
// Optional background color for the QR Code image
backgroundColor?: string;
};

/**
* This components renders a QR Code which resolves in the provided value
*/
const QrCodeImage = ({
value,
size = 200,
backgroundColor,
}: QrCodeImageProps) => {
const [source, setSource] = React.useState<ImageSourcePropType>();
const { width } = useWindowDimensions();
const realSize = React.useMemo<number>(() => {
if (typeof size === "number") {
return size;
}

return (parseFloat(size) / 100.0) * width;
}, [size, width]);

React.useEffect(() => {
RNQRGenerator.generate({
value,
height: realSize,
width: realSize,
backgroundColor,
correctionLevel: "L",
})
.then((result) => setSource(result))
.catch((_) => undefined);
}, [value, realSize, backgroundColor]);

return source ? (
<Image source={source} />
) : (
<Placeholder.Box
height={realSize}
width={realSize}
animate="fade"
radius={16}
/>
);
};

const MemoizedQrCodeImage = React.memo(QrCodeImage);

export { MemoizedQrCodeImage as QrCodeImage };
2 changes: 2 additions & 0 deletions example/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ declare module "@env" {
export const PRE_WALLET_EAA_PROVIDER_BASE_URL: string;
export const PRE_REDIRECT_URI: string;
export const PRE_GOOGLE_CLOUD_PROJECT_NUMBER: string;
export const PRE_VERIFIER_BASE_URL: string;
// PROD SECTION
export const PROD_WALLET_PROVIDER_BASE_URL: string;
export const PROD_WALLET_PID_PROVIDER_BASE_URL: string;
export const PROD_WALLET_EAA_PROVIDER_BASE_URL: string;
export const PROD_REDIRECT_URI: string;
export const PROD_GOOGLE_CLOUD_PROJECT_NUMBER: string;
export const PROD_VERIFIER_BASE_URL: string;
}
48 changes: 35 additions & 13 deletions example/src/navigator/MainStackNavigator.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React, { useCallback } from "react";
import { selectIoAuthToken } from "../store/reducers/sesssion";
import { useSelector } from "react-redux";
import HomeScreen from "../screens/HomeScreen";
import IdpSelectionScreen from "../screens/login/IdpSelectionScreen";
import IdpLoginScreen from "../screens/login/IdpLoginScreen";
import { IconButton, IOThemeLight } from "@pagopa/io-app-design-system";
import {
DefaultTheme,
NavigationContainer,
type Theme,
} from "@react-navigation/native";
import { IconButton, IOThemeLight } from "@pagopa/io-app-design-system";
import { WalletInstanceScreen } from "../screens/WalletInstanceScreen";
import { PidScreen } from "../screens/PidScreen";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import React, { useCallback } from "react";
import { useSelector } from "react-redux";
import { CredentialScreen } from "../screens/CredentialScreen";
import { StatusAttestationScreen } from "../screens/StatusAttestationScreen";
import { useAppDispatch } from "../store/utils";
import { setDebugVisibility } from "../store/reducers/debug";
import HomeScreen from "../screens/HomeScreen";
import IdpLoginScreen from "../screens/login/IdpLoginScreen";
import IdpSelectionScreen from "../screens/login/IdpSelectionScreen";
import PidSpidLoginScreen from "../screens/login/PidSpidLoginScreen";
import { PidScreen } from "../screens/PidScreen";
import SettingsScreen from "../screens/SettingsScreen";
import { StatusAttestationScreen } from "../screens/StatusAttestationScreen";
import {
TrustmarkQrCodeScreen,
TrustmarkScreen,
} from "../screens/TrustmarkScreen";
import { WalletInstanceScreen } from "../screens/WalletInstanceScreen";
import { setDebugVisibility } from "../store/reducers/debug";
import { selectIoAuthToken } from "../store/reducers/sesssion";
import type { SupportedCredentialsWithoutPid } from "../store/types";
import { useAppDispatch } from "../store/utils";
import { labelByCredentialType } from "../utils/ui";

/**
* MainStackNav parameters list for each defined screen.
Expand All @@ -29,6 +35,8 @@ export type MainStackNavParamList = {
Pid: undefined;
Credentials: undefined;
StatusAttestation: undefined;
Trustmark: undefined;
TrustmarkQrCode: { credentialType: SupportedCredentialsWithoutPid };
Login: undefined;
IdpSelection: undefined;
IdpLogin: { idp: string };
Expand Down Expand Up @@ -104,6 +112,20 @@ export const MainStackNavigator = () => {
component={StatusAttestationScreen}
options={{ title: "Test credentials attestations" }}
/>
<Stack.Screen
name="Trustmark"
component={TrustmarkScreen}
options={{ title: "Test credentials trustmark" }}
/>
<Stack.Screen
name="TrustmarkQrCode"
component={TrustmarkQrCodeScreen}
options={({ route }) => ({
title: `${
labelByCredentialType[route.params.credentialType]
} trustmark`,
})}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
Expand Down
30 changes: 22 additions & 8 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable react-native/no-inline-styles */
import React, { useMemo } from "react";
import { Alert, FlatList, SafeAreaView } from "react-native";
import { selectIoAuthToken } from "../store/reducers/sesssion";
import { useAppSelector } from "../store/utils";
import {
IOVisualCostants,
ModuleSummary,
VSpacer,
} from "@pagopa/io-app-design-system";
import { useNavigation } from "@react-navigation/native";
import type { ComponentProps } from "react";
import React, { useMemo } from "react";
import { Alert, FlatList, SafeAreaView } from "react-native";
import { useDebugInfo } from "../hooks/useDebugInfo";
import { selectCredential } from "../store/reducers/credential";
import { selectCredentials } from "../store/reducers/credential";
import { selectHasInstanceKeyTag } from "../store/reducers/instance";
import { selectPid } from "../store/reducers/pid";
import { selectIoAuthToken } from "../store/reducers/sesssion";
import { useAppSelector } from "../store/utils";

type ModuleSummaryProps = ComponentProps<typeof ModuleSummary>;

Expand All @@ -26,12 +26,17 @@ const HomeScreen = () => {
const hasIntegrityKeyTag = useAppSelector(selectHasInstanceKeyTag);
const pid = useAppSelector(selectPid);
const session = useAppSelector(selectIoAuthToken);
const mdl = useAppSelector(selectCredential("MDL"));
const credentials = useAppSelector(selectCredentials);

useDebugInfo({
session,
});

const hasSomeCredential = React.useMemo(
() => Object.values(credentials).filter((_) => !!_).length > 0,
[credentials]
);

const sections: Array<ModuleSummaryProps> = useMemo(
() => [
{
Expand Down Expand Up @@ -63,18 +68,27 @@ const HomeScreen = () => {
description: "Obtain the status attestation of a credential",
icon: "chevronRight",
onPress: () =>
mdl
credentials.MDL
? navigation.navigate("StatusAttestation")
: Alert.alert("Obtain a MDL first"),
},
{
label: "Trustmark",
description: "Obtain the trustmark of a credential",
icon: "chevronRight",
onPress: () =>
hasSomeCredential
? navigation.navigate("Trustmark")
: Alert.alert("Obtain a credential first"),
},
{
label: "Settings",
description: "Change the environment and logout",
icon: "chevronRight",
onPress: () => navigation.navigate("Settings"),
},
],
[hasIntegrityKeyTag, mdl, navigation, pid]
[hasIntegrityKeyTag, navigation, pid, credentials, hasSomeCredential]
);

return (
Expand Down
Loading
Loading