diff --git a/apps/server/src/national/national.service.ts b/apps/server/src/national/national.service.ts index ea46ccd..6631a11 100644 --- a/apps/server/src/national/national.service.ts +++ b/apps/server/src/national/national.service.ts @@ -16,7 +16,10 @@ export class NationalService { ) {} generateJwtPayload(user: UserDocument): LoginResponse { - const payload = { username: user.nationalId, sub: user._id.toHexString() }; + const payload = { + username: user.hashedNationalId, + sub: user._id.toHexString(), + }; return { id: user._id.toHexString(), token: this.jwtService.sign(payload), diff --git a/apps/server/src/user/user.schema.ts b/apps/server/src/user/user.schema.ts index 4531eae..7f1179b 100644 --- a/apps/server/src/user/user.schema.ts +++ b/apps/server/src/user/user.schema.ts @@ -7,7 +7,7 @@ export type UserDocument = HydratedDocument; @Schema() export class User { @Prop({ required: true }) - nationalId: string; + hashedNationalId: string; @Prop({ type: SchemaTypes.ObjectId, ref: 'Identity' }) currentIdentity: Identity; diff --git a/apps/server/src/user/user.service.ts b/apps/server/src/user/user.service.ts index a0f97df..c131684 100644 --- a/apps/server/src/user/user.service.ts +++ b/apps/server/src/user/user.service.ts @@ -1,3 +1,4 @@ +import { createHash } from 'crypto'; import { Injectable, NotFoundException } from '@nestjs/common'; import { User, UserDocument } from './user.schema'; import { InjectModel } from '@nestjs/mongoose'; @@ -59,9 +60,11 @@ export class UsersService { } async findOrCreate(nationalId: string): Promise { + const hashFunc = createHash('sha256'); + const hashedNationalId = hashFunc.update(nationalId).digest('hex'); return this.userModel.findOneAndUpdate( - { nationalId }, - { nationalId }, + { hashedNationalId }, + { hashedNationalId }, { upsert: true, new: true, setDefaultsOnInsert: true } ); } @@ -98,8 +101,8 @@ export class UsersService { return this.updateIdentity(userId, 'semaphoreCommitment', value); } - findOne(nationalId: string): Promise { - return this.userModel.findOne({ nationalId }); + findOne(hashedNationalId: string): Promise { + return this.userModel.findOne({ hashedNationalId }); } async revokeIdentity(userId: string): Promise { diff --git a/apps/wallet/src/pages/CredentialSelection.tsx b/apps/wallet/src/pages/CredentialSelection.tsx index 8a4efd2..697c1a8 100644 --- a/apps/wallet/src/pages/CredentialSelection.tsx +++ b/apps/wallet/src/pages/CredentialSelection.tsx @@ -22,12 +22,12 @@ export function CredentialSelection() { const credentials = useCredentials( CredentialMode.Select, - user?.nationalId, + user?.hashedNationalId, user?.ethereumAccount ); const handleAction = async ( - credentialKey: CredentialType, + credentialKey: CredentialType, actionId: ActionId ) => { let vc: VerifiableCredential | null = null; @@ -45,7 +45,7 @@ export function CredentialSelection() { sendCredential(MessageAction.SELECT_CREDENTIAL, vc); } } - } + }; // if (isConnected) return ( diff --git a/apps/wallet/src/pages/CredentialView.tsx b/apps/wallet/src/pages/CredentialView.tsx index bece8b1..65adf37 100644 --- a/apps/wallet/src/pages/CredentialView.tsx +++ b/apps/wallet/src/pages/CredentialView.tsx @@ -18,10 +18,10 @@ export function CredentialView() { getSemaphoreGroup, generateSemaphoreIdentity, } = useTwDid(); - + const credentials = useCredentials( CredentialMode.List, - user?.nationalId, + user?.hashedNationalId, user?.ethereumAccount ); diff --git a/apps/wallet/src/pages/Welcome.tsx b/apps/wallet/src/pages/Welcome.tsx index 1ef7303..944b2c2 100644 --- a/apps/wallet/src/pages/Welcome.tsx +++ b/apps/wallet/src/pages/Welcome.tsx @@ -15,25 +15,27 @@ export function Welcome() { const gotoView = async () => { navigate({ to: '/view-credential' }); return; - } + }; const gotoSelect = async () => { navigate({ to: '/select-credential' }); return; - } - + }; + /* TODO: the credentials should be loaded from ls */ /* TODO: let user be undefined if no credential stored */ - const user = credentials ? { - nationalId: credentials[CredentialType.ETHEREUM].fields[0].value, - walletAddr: credentials[CredentialType.ETHEREUM].fields[1].value, - } : undefined; + const user = credentials + ? { + hashedNationalId: credentials[CredentialType.ETHEREUM].fields[0].value, + walletAddr: credentials[CredentialType.ETHEREUM].fields[1].value, + } + : undefined; return ( <> { @@ -19,7 +19,7 @@ export function Welcome() { return ( ); diff --git a/libs/react-library/src/lib/components/layout/ConnectionsCard/ConnectionCard.tsx b/libs/react-library/src/lib/components/layout/ConnectionsCard/ConnectionCard.tsx index 44649b6..89659cb 100644 --- a/libs/react-library/src/lib/components/layout/ConnectionsCard/ConnectionCard.tsx +++ b/libs/react-library/src/lib/components/layout/ConnectionsCard/ConnectionCard.tsx @@ -5,13 +5,11 @@ import { EthLogo } from '../../common/icons/ethLogo'; import { SuccessIcon } from '../../common/icons/success'; import { ErrorIcon } from '../../common/icons/error'; import { ShortenAddr } from '../../common/shortenAddr'; -import { maskString } from '../../../utils/utils'; export const ConnectionCard = ({ fidoState, walletState, bindState, - nationID, walletAddr, }: { fidoState?: number; @@ -35,12 +33,6 @@ export const ConnectionCard = ({ {fidoState !== undefined && fidoState === 2 && } {fidoState !== undefined && fidoState === 3 && } - {nationID && ( -
-
{t('nationalId')}
-
{maskString(nationID)}
-
- )} {bindState !== undefined && bindState === 1 && } diff --git a/libs/react-library/src/lib/components/layout/action-screen/WalletHomeScreen.tsx b/libs/react-library/src/lib/components/layout/action-screen/WalletHomeScreen.tsx index 275c945..fb8cdb5 100644 --- a/libs/react-library/src/lib/components/layout/action-screen/WalletHomeScreen.tsx +++ b/libs/react-library/src/lib/components/layout/action-screen/WalletHomeScreen.tsx @@ -11,13 +11,13 @@ import { ConnectionCardSimple } from '../ConnectionsCardSimple/ConnectionCardSim export const WalletHomeScreen = ({ user, - mode, + mode, gotoRegister, gotoView, gotoSelect, }: { user?: { - nationalId: string; + hashedNationalId: string; walletAddr: string; }; mode: 'view' | 'select'; @@ -84,7 +84,7 @@ export const WalletHomeScreen = ({

{currentState.title}

{user && ( )} diff --git a/libs/react-library/src/lib/contexts/TwDidContext.tsx b/libs/react-library/src/lib/contexts/TwDidContext.tsx index 02bbd53..110cc81 100644 --- a/libs/react-library/src/lib/contexts/TwDidContext.tsx +++ b/libs/react-library/src/lib/contexts/TwDidContext.tsx @@ -70,7 +70,7 @@ class UpdateSemaphoreCommitmentError extends Error { } interface User { - nationalId: string; + hashedNationalId: string; ethereumAccount: string; semaphoreCommitment: string; id: string; @@ -144,10 +144,10 @@ export const TwDidProvider: React.FC = ({ children }) => { }); const user = await res.json(); if (res.status === 200) { - const { nationalId, currentIdentity } = user; + const { hashedNationalId, currentIdentity } = user; const { ethereumAccount, semaphoreCommitment } = currentIdentity || {}; setUser({ - nationalId, + hashedNationalId, ethereumAccount, semaphoreCommitment, id, diff --git a/libs/react-library/src/lib/hooks/useCredential.tsx b/libs/react-library/src/lib/hooks/useCredential.tsx index 1de6339..c528f23 100644 --- a/libs/react-library/src/lib/hooks/useCredential.tsx +++ b/libs/react-library/src/lib/hooks/useCredential.tsx @@ -19,7 +19,7 @@ export enum CredentialMode { export function useCredentials( mode: CredentialMode, - nationalId = '', + hashedNationalId = '', ethereumAccount = '' ): CredentialMap { const { t } = useTranslation(); @@ -31,11 +31,6 @@ export function useCredentials( [CredentialType.ETHEREUM]: { type: CredentialType.ETHEREUM, fields: [ - { - key: CredentialFieldKey.NATION_ID, - label: t('nationalId'), - value: nationalId, - }, { key: CredentialFieldKey.ETHEREUM_ADDRESS, label: t('account'),