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: relocation of ctype config #78

Merged
merged 15 commits into from
Mar 13, 2024
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=
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
TRUSTED_ATTESTERS=
REQUIRED_PROPERTIES=
8 changes: 8 additions & 0 deletions .oldenv
rompemoldes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WSS_ADDRESS=wss://peregrine.kilt.io/;
FRONTEND_PORT=6565
BACKEND_PORT=2525
DAPP_ACCOUNT_MNEMONIC=pottery own enforce glory infant weekend sheriff timber magnet core among certain
DAPP_DID_MNEMONIC=route frog lazy display tape bomb crisp frequent gym emerge history sock
DAPP_DID_URI=did:kilt:4sr7LmcWSL3ow1qMQSqs9oyCAXkvbKHm6ZET2W79iJ4Feehz
DAPP_NAME=TEST
JWT_SIGNER_SECRET=281x6Sj0Aycg4r5SeFcj8wD3CHpXpudM8dCt48T6Iap_gMDBu3wE4BaY1o2Ke4znkMvqDR4B_BoSlJIMZ9e-YA
5 changes: 1 addition & 4 deletions backend/src/access/login.ts
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,14 +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(
Expand Down
16 changes: 16 additions & 0 deletions backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ 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')

// To determine which CType to use, refer to the CType Hash
const SOCIAL_KYC_EMAIL_CTYPE =
'0x3291bb126e33b4862d421bfaa1d2f272e6cdfc4f96658988fbcffea8914bd9ac'
// Required properties for socialKYC
export const SOCIAL_KYC_EMAIL_REQUIRED_PORPERTIES = 'Email'
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
// Specify the Social KYC Trusted Attester DID. Credentials issued by this Attester will be accepted.
export const SOCIAL_KYC_ATTESTER =
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
'did:kilt:4pehddkhEanexVTTzWAtrrfo2R7xPnePpuiJLC7shQU894aY'
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved

// Configerable Credential types
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
export const CTYPE_HASH = loadEnv('CTYPE_HASH') || SOCIAL_KYC_EMAIL_CTYPE
ntn-x2 marked this conversation as resolved.
Show resolved Hide resolved
export const TRUSTED_ATTESTERS =
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
loadEnv('TRUSTED_ATTESTERS') || SOCIAL_KYC_ATTESTER
export const REQUIRED_PROPERTIES =
loadEnv('REQUIRED_PROPERTIES') || SOCIAL_KYC_EMAIL_REQUIRED_PORPERTIES

aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
export let DAPP_ACCOUNT_ADDRESS: string

function loadEnv(name: string) {
Expand Down
39 changes: 22 additions & 17 deletions backend/src/credentials/listOfRequests.ts
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:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that all this comments could go inside the variable explainer (docs) from requestedCTypeForLogin. Maybe a bit more structured and explaining how to change the imports.

const trustedAttestersValues = TRUSTED_ATTESTERS.split(',')
const requiredPropertiesValues = REQUIRED_PROPERTIES.split(',')

const requiredProperties = requiredPropertiesValues.map(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this snippet of code doing exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment still not addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a experimental change to accept more than one TRUSTED_ATTESTERS which separated by a comma

(requiredProperties) => requiredProperties
)

const trustedAttesters = trustedAttestersValues.map(
(trustedAttesters) => trustedAttesters as Kilt.DidUri
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
)
const trustedAttesters = TRUSTED_ATTESTERS.split(',') as Kilt.DidUri[]
const requiredProperties = REQUIRED_PROPERTIES.split(',')


/**
* 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 = {
aybarsayan marked this conversation as resolved.
Show resolved Hide resolved
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
}
]
}
}
Loading