diff --git a/.env.example b/.env.example index 39d4caea..c9e9aaf5 100644 --- a/.env.example +++ b/.env.example @@ -6,3 +6,6 @@ DAPP_DID_MNEMONIC= DAPP_DID_URI= DAPP_NAME= JWT_SIGNER_SECRET= +CTYPE_HASH= +TRUSTED_ATTESTERS= +REQUIRED_PROPERTIES= diff --git a/backend/src/access/login.ts b/backend/src/access/login.ts index 27e01d6e..acc4071c 100644 --- a/backend/src/access/login.ts +++ b/backend/src/access/login.ts @@ -1,15 +1,11 @@ import { Response, Request } from 'express' -import { emailRequest } from '../credentials/listOfRequests' +import { requestedCTypeForLogin } from '../credentials/listOfRequests' import { buildCredentialRequest } from '../credentials/buildCredentialRequest' import { verifySubmittedCredential } from '../credentials/verifySubmittedCredential' import { setAccessCookie } from './setAccessCookie' -// Here you can set which type of credential (cType) your dApp will request users to login. -// You can change it by importing a different one from the list. -const requestedCTypeForLogin = emailRequest - /** First half of the login with credentials.*/ export async function buildLoginCredentialRequest( request: Request, diff --git a/backend/src/config.ts b/backend/src/config.ts index 4d67d40e..a136fb25 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -16,14 +16,31 @@ import { getApi } from './utils/connection' const envPath = path.resolve(__dirname, '../..', '.env') dotenv.config({ path: envPath }) +// Blockchain address with a default of Peregrine the testnet export const WSS_ADDRESS = process.env.WSS_ADDRESS ?? 'wss://peregrine.kilt.io' -export const BACKEND_PORT = process.env.BACKEND_PORT ?? 2525 +export const BACKEND_PORT = process.env.BACKEND_PORT ?? 3000 export const DAPP_ACCOUNT_MNEMONIC = loadEnv('DAPP_ACCOUNT_MNEMONIC') export const DAPP_DID_MNEMONIC = loadEnv('DAPP_DID_MNEMONIC') export const DAPP_DID_URI = loadEnv('DAPP_DID_URI') as Kilt.DidUri export const DAPP_NAME = process.env.DAPP_NAME ?? 'Web3-Login-Demo' export const JWT_SIGNER_SECRET = loadEnv('JWT_SIGNER_SECRET') +// CType information +const SOCIAL_KYC_EMAIL_CTYPE = + '0x3291bb126e33b4862d421bfaa1d2f272e6cdfc4f96658988fbcffea8914bd9ac' +// Required properties for socialKYC +export const SOCIAL_KYC_EMAIL_REQUIRED_PORPERTIES = 'Email' +// Social KYC Trusted Attester +export const SOCIAL_KYC_ATTESTER = + 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY' + +// Configerable Credential types +export const CTYPE_HASH = loadEnv('CTYPE_HASH') || SOCIAL_KYC_EMAIL_CTYPE +export const TRUSTED_ATTESTERS = + loadEnv('TRUSTED_ATTESTERS') || SOCIAL_KYC_ATTESTER +export const REQUIRED_PROPERTIES = + loadEnv('REQUIRED_PROPERTIES') || SOCIAL_KYC_EMAIL_REQUIRED_PORPERTIES + export let DAPP_ACCOUNT_ADDRESS: string function loadEnv(name: string) { diff --git a/backend/src/credentials/listOfRequests.ts b/backend/src/credentials/listOfRequests.ts index b9ea9036..6b2eff2a 100644 --- a/backend/src/credentials/listOfRequests.ts +++ b/backend/src/credentials/listOfRequests.ts @@ -1,27 +1,32 @@ import * as Kilt from '@kiltprotocol/sdk-js' +import { CTYPE_HASH, REQUIRED_PROPERTIES, TRUSTED_ATTESTERS } from '../config' + +// Here you can set which type of credential (cType) your dApp will request users to login. +// You can change it by importing a different one. +// The default is the Email CType by SocialKYC and SocialKYC as the Issuer // Establish which cTypes our dApp accepts and which attesters we trust: +const trustedAttestersValues = TRUSTED_ATTESTERS.split(',') +const requiredPropertiesValues = REQUIRED_PROPERTIES.split(',') + +const requiredProperties = requiredPropertiesValues.map( + (requiredProperties) => requiredProperties +) + +const trustedAttesters = trustedAttestersValues.map( + (trustedAttesters) => trustedAttesters as Kilt.DidUri +) + /** - * Email Credential Type attested from SocialKYC.io + * Credential for users to configure default as SocialKYC Email Credential */ -export const emailRequest: Kilt.IRequestCredentialContent = { +export const requestedCTypeForLogin: Kilt.IRequestCredentialContent = { cTypes: [ { - cTypeHash: - '0x3291bb126e33b4862d421bfaa1d2f272e6cdfc4f96658988fbcffea8914bd9ac', - trustedAttesters: [ - 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY' - ], - requiredProperties: ['Email'] - }, - { - cTypeHash: - '0xae5bc64e500eb576b7b137288cec5d532094e103be46872f1ad54641e477d9fe', - trustedAttesters: [ - 'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY' - ], - requiredProperties: ['Email'] + cTypeHash: CTYPE_HASH as `0x${string}`, + trustedAttesters, + requiredProperties } ] }