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

Fix lint warnings #493

Draft
wants to merge 1 commit into
base: feat/protocol-optimization
Choose a base branch
from
Draft
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
5 changes: 1 addition & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, Suspense, useState, useContext } from 'react';
import React, { useEffect, Suspense } from 'react';
import { Routes, Route, Outlet, useLocation } from 'react-router-dom';
// Import i18next and set up translations
import { I18nextProvider } from 'react-i18next';
Expand All @@ -11,7 +11,6 @@ import HandlerNotification from './components/Notifications/HandlerNotification'
import Snowfalling from './components/ChristmasAnimation/Snowfalling';
import Spinner from './components/Shared/Spinner';

import { withContainerContext } from './context/ContainerContext';
import { withCredentialsContext } from './context/CredentialsContext';

import UpdateNotification from './components/Notifications/UpdateNotification';
Expand Down Expand Up @@ -67,8 +66,6 @@ const lazyWithDelay = (importFunction, delay = 1000) => {
);
};

const MessagePopup = React.lazy(() => import('./components/Popups/MessagePopup'));
const PinInputPopup = React.lazy(() => import('./components/Popups/PinInput'));
const PrivateRoute = reactLazyWithNonDefaultExports(
() => import('./components/Auth/PrivateRoute'),
'NotificationPermissionWarning',
Expand Down
2 changes: 1 addition & 1 deletion src/UriHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, createContext, useState, useContext } from "react";
import React, { useEffect, useState, useContext } from "react";
import { useLocation } from "react-router-dom";
import { checkForUpdates } from './offlineRegistrationSW';
import StatusContext from "./context/StatusContext";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Shared/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Slider = ({ items, renderSlideContent, onSlideChange, initialSlide = 1 })
{items.map((item, index) => (
<SwiperSlide
key={item.id || index}
className={`rounded-xl ${Math.abs(currentSlide - (index + 1)) > 1 && 'invisible pointer-events-none'} ${currentSlide == (index + 1) && 'overflow-visible-force'} `}
className={`rounded-xl ${Math.abs(currentSlide - (index + 1)) > 1 && 'invisible pointer-events-none'} ${currentSlide === (index + 1) && 'overflow-visible-force'} `}
>
{renderSlideContent(item, index)}
</SwiperSlide>
Expand Down
2 changes: 1 addition & 1 deletion src/context/CredentialParserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const CredentialParserContextProvider = ({ children }) => {
const isValidMetadata = !('error' in getSdJwtVcMetadataResult) && getSdJwtVcMetadataResult.credentialMetadata;

// Extract metadata and claims
const metadata = isValidMetadata && getSdJwtVcMetadataResult.credentialMetadata?.display?.find((d) => d.lang === defaultLocale) || null;
const metadata = (isValidMetadata && getSdJwtVcMetadataResult.credentialMetadata?.display?.find((d) => d.lang === defaultLocale)) || null;
const claims = isValidMetadata && getSdJwtVcMetadataResult.credentialMetadata?.claims?.length
? getSdJwtVcMetadataResult.credentialMetadata.claims
: null;
Expand Down
2 changes: 1 addition & 1 deletion src/context/CredentialsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const CredentialsProvider = ({ children }) => {

const vcEntityList = (await Promise.all(fetchedVcList.map(async (vcEntity) => {
return { ...vcEntity };
}))).filter((vcEntity) => vcEntity.instanceId == 0); // show only the first instance
}))).filter((vcEntity) => vcEntity.instanceId === 0); // show only the first instance

vcEntityList.sort(reverse(compareBy(vc => vc.id)));

Expand Down
4 changes: 2 additions & 2 deletions src/context/OpenID4VPContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useContext, createContext } from "react";
import React, { useState, useContext, createContext } from "react";
import SelectCredentialsPopup from "../components/Popups/SelectCredentialsPopup";
import CredentialsContext from '../context/CredentialsContext';
import { useOpenID4VP } from "../lib/services/OpenID4VP/OpenID4VP";
Expand All @@ -13,7 +13,7 @@ const OpenID4VPContext: React.Context<OpenID4VPContextValue> = createContext({
});

export const OpenID4VPContextProvider = ({ children }) => {
const { vcEntityList, vcEntityListInstances, latestCredentials, currentSlide, setCurrentSlide } = useContext<any>(CredentialsContext);
const { vcEntityList, vcEntityListInstances } = useContext<any>(CredentialsContext);

const [popupState, setPopupState] = useState({
isOpen: false,
Expand Down
20 changes: 7 additions & 13 deletions src/lib/services/OpenID4VCI/OpenID4VCI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as config from '../../../config';
import { VerifiableCredentialFormat } from '../../schemas/vc';
import { useHttpProxy } from '../HttpProxy/HttpProxy';
import { useOpenID4VCIClientStateRepository } from '../OpenID4VCIClientStateRepository';
import { useContext, useEffect, useMemo } from 'react';
import { useContext, useMemo } from 'react';
import SessionContext from '../../../context/SessionContext';
import { useOpenID4VCIPushedAuthorizationRequest } from './OpenID4VCIAuthorizationRequest/OpenID4VCIPushedAuthorizationRequest';
import { useOpenID4VCIAuthorizationRequestForFirstPartyApplications } from './OpenID4VCIAuthorizationRequest/OpenID4VCIAuthorizationRequestForFirstPartyApplications';
Expand Down Expand Up @@ -174,7 +174,7 @@ export function useOpenID4VCI(): IOpenID4VCI {


const credentialArray = [];
if (numberOfProofs == 1 && credentialResponse.data.credential) {
if (numberOfProofs === 1 && credentialResponse.data.credential) {
const { credential } = credentialResponse.data;
credentialArray.push(credential);
}
Expand Down Expand Up @@ -229,9 +229,8 @@ export function useOpenID4VCI(): IOpenID4VCI {
}
}) {

const [authzServerMetadata, credentialIssuerMetadata, clientId] = await Promise.all([
const [authzServerMetadata, clientId] = await Promise.all([
openID4VCIHelper.getAuthorizationServerMetadata(credentialIssuerIdentifier),
openID4VCIHelper.getCredentialIssuerMetadata(credentialIssuerIdentifier),
openID4VCIHelper.getClientId(credentialIssuerIdentifier)
]);
if (requestCredentialsParams.usingActiveAccessToken) {
Expand Down Expand Up @@ -291,7 +290,6 @@ export function useOpenID4VCI(): IOpenID4VCI {

let dpopPrivateKey: jose.KeyLike | Uint8Array | null = null;
let dpopPrivateKeyJwk: jose.JWK | null = null;
let dpopPublicKey: jose.KeyLike | Uint8Array | null = null;
let dpopPublicKeyJwk: jose.JWK | null = null;

if (!flowState.dpop) { // if DPoP keys have not been generated, then generate them
Expand All @@ -302,15 +300,13 @@ export function useOpenID4VCI(): IOpenID4VCI {
]);

dpopPrivateKey = privateKey;
dpopPublicKey = publicKey;
}
else { // if already generated, then reuse them
dpopPrivateKeyJwk = flowState.dpop.dpopPrivateKeyJwk;
dpopPublicKeyJwk = flowState.dpop.dpopPublicKeyJwk;

[dpopPrivateKey, dpopPublicKey] = await Promise.all([
jose.importJWK(flowState.dpop.dpopPrivateKeyJwk, flowState.dpop.dpopAlg),
jose.importJWK(flowState.dpop.dpopPublicKeyJwk, flowState.dpop.dpopAlg)
[dpopPrivateKey] = await Promise.all([
jose.importJWK(flowState.dpop.dpopPrivateKeyJwk, flowState.dpop.dpopAlg)
])
}
const jti = generateRandomIdentifier(8);
Expand Down Expand Up @@ -434,8 +430,7 @@ export function useOpenID4VCI(): IOpenID4VCI {
throw new Error("Only authorization_code grant is supported");
}

const [authzServerMetadata, credentialIssuerMetadata] = await Promise.all([
openID4VCIHelper.getAuthorizationServerMetadata(offer.credential_issuer),
const [credentialIssuerMetadata] = await Promise.all([
openID4VCIHelper.getCredentialIssuerMetadata(offer.credential_issuer)
]);

Expand All @@ -454,8 +449,7 @@ export function useOpenID4VCI(): IOpenID4VCI {
}

async function getAvailableCredentialConfigurations(credentialIssuerIdentifier: string): Promise<Record<string, CredentialConfigurationSupported>> {
const [authzServerMetadata, credentialIssuerMetadata] = await Promise.all([
openID4VCIHelper.getAuthorizationServerMetadata(credentialIssuerIdentifier),
const [credentialIssuerMetadata] = await Promise.all([
openID4VCIHelper.getCredentialIssuerMetadata(credentialIssuerIdentifier)
]);
if (!credentialIssuerMetadata.metadata?.credential_configurations_supported) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function useOpenID4VCIAuthorizationRequestForFirstPartyApplications(): IO
const err = res.err;
if (err) {
if (err?.data && err?.data?.error === "insufficient_authorization") { // Authorization Error Response
const { error, auth_session, presentation } = err?.data;
const { auth_session, presentation } = err?.data;

// this function should prompt the user for presentation selection
const result = await openID4VP.handleAuthorizationRequest("openid4vp:" + presentation).then((res) => {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/services/OpenID4VCIHelper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { IHttpProxy } from "../interfaces/IHttpProxy";
import { IOpenID4VCIHelper } from "../interfaces/IOpenID4VCIHelper";
import { OpenidAuthorizationServerMetadata, OpenidAuthorizationServerMetadataSchema } from "../schemas/OpenidAuthorizationServerMetadataSchema";
import { OpenidCredentialIssuerMetadata, OpenidCredentialIssuerMetadataSchema } from "../schemas/OpenidCredentialIssuerMetadataSchema";
Expand Down Expand Up @@ -50,7 +49,7 @@ export function useOpenID4VCIHelper(): IOpenID4VCIHelper {
try {
const issuerResponse = await api.getExternalEntity('/issuer/all', undefined, true);
const trustedCredentialIssuers = issuerResponse.data;
const issuer = trustedCredentialIssuers.filter((issuer: any) => issuer.credentialIssuerIdentifier == credentialIssuerIdentifier)[0];
const issuer = trustedCredentialIssuers.filter((issuer: any) => issuer.credentialIssuerIdentifier === credentialIssuerIdentifier)[0];
if (issuer) {
return { client_id: issuer.clientId };
}
Expand Down
7 changes: 3 additions & 4 deletions src/lib/services/OpenID4VP/OpenID4VP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { BACKEND_URL, OPENID4VP_SAN_DNS_CHECK_SSL_CERTS, OPENID4VP_SAN_DNS_CHECK
import { useCredentialBatchHelper } from "../CredentialBatchHelper";
import { toBase64 } from "../../../util";
import { useHttpProxy } from "../HttpProxy/HttpProxy";
import { useCredentialParserRegistry } from "../CredentialParserRegistry";
import { useContext } from "react";
import SessionContext from "../../../context/SessionContext";
import CredentialParserContext from "../../../context/CredentialParserContext";
Expand Down Expand Up @@ -348,7 +347,7 @@ export function useOpenID4VP({ showCredentialSelectionPopup }: { showCredentialS
const rp_eph_pub_jwk = S.client_metadata.jwks.keys[0];
const rp_eph_pub = await importJWK(rp_eph_pub_jwk, S.client_metadata.authorization_encrypted_response_alg);
const jwe = await new EncryptJWT({
vp_token: generatedVPs.length == 1 ? generatedVPs[0] : generatedVPs,
vp_token: generatedVPs.length === 1 ? generatedVPs[0] : generatedVPs,
presentation_submission: presentationSubmission,
state: S.state ?? undefined
})
Expand All @@ -359,7 +358,7 @@ export function useOpenID4VP({ showCredentialSelectionPopup }: { showCredentialS
console.log("JWE = ", jwe)
}
else {
formData.append('vp_token', generatedVPs.length == 1 ? generatedVPs[0] : JSON.stringify(generatedVPs));
formData.append('vp_token', generatedVPs.length === 1 ? generatedVPs[0] : JSON.stringify(generatedVPs));
formData.append('presentation_submission', JSON.stringify(presentationSubmission));
if (S.state) {
formData.append('state', S.state);
Expand All @@ -369,7 +368,7 @@ export function useOpenID4VP({ showCredentialSelectionPopup }: { showCredentialS

const credentialIdentifiers = originalVCs.map((vc) => vc.credentialIdentifier);

const presentations = "b64:" + toBase64(new TextEncoder().encode(generatedVPs.length == 1 ? generatedVPs[0] : JSON.stringify(generatedVPs)));
const presentations = "b64:" + toBase64(new TextEncoder().encode(generatedVPs.length === 1 ? generatedVPs[0] : JSON.stringify(generatedVPs)));
const storePresentationPromise = storeVerifiablePresentation(presentations, presentationSubmission, credentialIdentifiers, client_id);
const updateCredentialPromise = filteredVCEntities.map(async (cred) => credentialBatchHelper.useCredential(cred))

Expand Down
2 changes: 1 addition & 1 deletion src/pages/AddCredentials/AddCredentials.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useContext, useCallback } from 'react';
import React, { useState, useEffect, useContext } from 'react';
import { useTranslation } from 'react-i18next';

import StatusContext from '../../context/StatusContext';
Expand Down
Loading