Skip to content

Commit

Permalink
Merge pull request #5 from gunet/wwwallet-sync
Browse files Browse the repository at this point in the history
Wwwallet sync
  • Loading branch information
kkmanos authored Nov 4, 2024
2 parents 5495c55 + 6471d71 commit 271949a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PORT=3000
REACT_APP_WS_URL=ws://wallet-backend-server:8002
REACT_APP_WALLET_BACKEND_URL=http://wallet-backend-server:8002
REACT_APP_LOGIN_WITH_PASSWORD=false
REACT_APP_FIREBASE_ENABLED=false
REACT_APP_FIREBASE_VAPIDKEY=<Your_Vapid_Key>
REACT_APP_FIREBASE_API_KEY=<Your_Firebase_API_Key>
REACT_APP_FIREBASE_AUTH_DOMAIN=<Your_Firebase_Auth_Domain>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Popups/RedirectPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ const RedirectPopup = ({ loading, availableCredentialConfigurations, onClose, ha

{configurationsCount > 1 && Object.keys(availableCredentialConfigurations).map((credentialConfigurationId, index) => {
return (
<div class="flex items-center mb-4">
<div key={credentialConfigurationId} className="flex items-center mb-4">
<input
id={"radio-" + index}
onChange={handleOptionChange}
type="radio"
value={credentialConfigurationId}
name="default-radio"
class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"
checked={selectedConfiguration === credentialConfigurationId}
aria-label={`Option ${credentialConfigurationId}`}
/>
<label for={"radio-" + index} class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">
{(availableCredentialConfigurations[credentialConfigurationId]?.display ? availableCredentialConfigurations[credentialConfigurationId]?.display.filter((d) => d.locale === locale)[0].name : null) ?? credentialConfigurationId}
<label htmlFor={"radio-" + index} className="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">
{(availableCredentialConfigurations[credentialConfigurationId]?.display ? availableCredentialConfigurations[credentialConfigurationId]?.display.filter((d) => d.locale === locale)[0]?.name : null) ?? credentialConfigurationId}
</label>
</div>
)
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const FIREBASE = {
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
};
export const FIREBASE_ENABLED: boolean = process.env.REACT_APP_FIREBASE_ENABLED ? JSON.parse(process.env.REACT_APP_FIREBASE_ENABLED) === true : false;
export const FIREBASE_VAPIDKEY = process.env.REACT_APP_FIREBASE_VAPIDKEY;
export const INACTIVE_LOGOUT_MILLIS = (process.env.REACT_APP_INACTIVE_LOGOUT_SECONDS ? parseInt(process.env.REACT_APP_INACTIVE_LOGOUT_SECONDS, 10) : 60 * 15) * 1000
export const LOGIN_WITH_PASSWORD: boolean = process.env.REACT_APP_LOGIN_WITH_PASSWORD ? JSON.parse(process.env.REACT_APP_LOGIN_WITH_PASSWORD) === true : false;
Expand Down
16 changes: 10 additions & 6 deletions src/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ export const notificationApiIsSupported =
'serviceWorker' in navigator &&
'PushManager' in window;

export async function isEnabledAndIsSupported() {
return config.FIREBASE_ENABLED && await isSupported();
}

export async function register() {
if (await isSupported() && 'serviceWorker' in navigator) {
if (await isEnabledAndIsSupported() && 'serviceWorker' in navigator) {
try {
const existingRegistration = await navigator.serviceWorker.getRegistration('/notifications/');
if (existingRegistration) {
Expand All @@ -28,7 +32,7 @@ export async function register() {
};

const requestForToken = async () => {
if (!await isSupported()) {
if (!await isEnabledAndIsSupported()) {
return null;
}
if (messaging) {
Expand Down Expand Up @@ -61,7 +65,7 @@ const requestForToken = async () => {
};

const reRegisterServiceWorkerAndGetToken = async () => {
if (!await isSupported()) {
if (!await isEnabledAndIsSupported()) {
return null;
}
if ('serviceWorker' in navigator) {
Expand Down Expand Up @@ -90,7 +94,7 @@ const reRegisterServiceWorkerAndGetToken = async () => {
};

export const fetchToken = async () => {
if (await isSupported() && messaging) {
if (await isEnabledAndIsSupported() && messaging) {
const token = await requestForToken();
console.log('token:', token);
if (token) {
Expand All @@ -112,7 +116,7 @@ export const fetchToken = async () => {

export const onMessageListener = () =>
new Promise(async (resolve) => {
if (await isSupported()) {
if (await isEnabledAndIsSupported()) {
onMessage(messaging, (payload) => {
resolve(payload);
});
Expand All @@ -121,7 +125,7 @@ export const onMessageListener = () =>

const initializeFirebaseAndMessaging = async () => {
if (notificationApiIsSupported) {
let supported = await isSupported();
let supported = await isEnabledAndIsSupported();
if (supported) {
initializeApp(config.FIREBASE);
messaging = getMessaging();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/OpenID4VPRelyingParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class OpenID4VPRelyingParty implements IOpenID4VPRelyingParty {
const [header, payload] = requestObject.split('.');
const parsedHeader = JSON.parse(new TextDecoder().decode(base64url.decode(header)));

const publicKey = await importX509(getPublicKeyFromB64Cert(parsedHeader.x5c[0]), 'RS256');
const publicKey = await importX509(getPublicKeyFromB64Cert(parsedHeader.x5c[0]), parsedHeader.alg);
const verificationResult = await jwtVerify(requestObject, publicKey).catch(() => null);
if (verificationResult == null) {
console.log("Signature verification of request_uri failed");
Expand Down

0 comments on commit 271949a

Please sign in to comment.