git clone https://github.com/SelfKeyFoundation/relying-party-direct-demo.git
cd relying-party-direct-demo
npm install
npm start
npm run start-dev
From routes/lws.js
// validate jwt token as challenge or access token
const decoded = await (tokenType === 'challenge'
? sk.auth.validateChallengeToken(tokenString, JWT_ALGORITHM, JWT_SECRET)
: sk.auth.validateAccessToken(tokenString, JWT_ALGORITHM, JWT_SECRET));
attributeManager = await sk.identity.AttributeManager.createWithSelfkeyRepository();
const challengeToken = await sk.auth.generateChallengeToken(did, JWT_ALGORITHM, JWT_SECRET)
const isValid = await sk.auth.verifyChallengeSignature(nonce, signature, did);
const accessToken = await sk.auth.generateAccessToken(did, JWT_ALGORITHM, JWT_SECRET);
// Validate attributes based on requirements (LWS_TEMPLATE)
const {
attributes: validated,
errors,
valid
} = await req.attributeManager.validateAttributes(attributes, LWS_TEMPLATE);
// create a human readable attribute map
// [{schemaId: 'http://platform.selfkey.org/schema/attribute/first-name.json', data: 'first name'}]
// Becomes
// { firstName: {schemaId: 'http://platform.selfkey.org/schema/attribute/first-name.json', data: 'first name'}}
attributes = sk.identity.utils.attributeMapBySchema(validated);
const jwt = await sk.jwt.issueJWT(did, JWT_ALGORITHM, JWT_SECRET);
const decoded = await sk.jwt.validateJWT(token, JWT_ALGORITHM, JWT_SECRET);
Copyright (c) 2018 SelfKey Foundation https://selfkey.org/