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: config ctype #43

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ DAPP_DID_MNEMONIC=
DAPP_DID_URI=
DAPP_NAME=
JWT_SIGNER_SECRET=
CTYPE_HASH=
TRUSTED_ATTESTERS=
REQUIRED_PROPERTIES=
6 changes: 1 addition & 5 deletions backend/src/access/login.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
19 changes: 18 additions & 1 deletion backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Dudleyneedham marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
37 changes: 21 additions & 16 deletions backend/src/credentials/listOfRequests.ts
weichweich marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
}
]
}