https://github.com/selfkeyfoundation/relying-party-direct-demo
https://github.com/selfkeyfoundation/relying-party-direct-demo
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/selfkeyfoundation/relying-party-direct-demo
- Owner: SelfKeyFoundation
- License: gpl-3.0
- Created: 2020-01-02T16:45:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T01:04:04.000Z (over 3 years ago)
- Last Synced: 2025-04-06T20:49:48.471Z (over 1 year ago)
- Language: JavaScript
- Size: 2.58 MB
- Stars: 0
- Watchers: 4
- Forks: 2
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Login With Selfkey Demo for direct integrations
## Contents
- [Usage](#usage)
- [License](#license)
## Usage
### Install
```sh
git clone https://github.com/SelfKeyFoundation/relying-party-direct-demo.git
cd relying-party-direct-demo
npm install
```
### Run
```sh
npm start
```
### Run dev
```sh
npm run start-dev
```
### SDK code examples
From [routes/lws.js](https://github.com/SelfKeyFoundation/relying-party-direct-demo/blob/master/routes/lws.js)
```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));
```
```js
attributeManager = await sk.identity.AttributeManager.createWithSelfkeyRepository();
```
```js
const challengeToken = await sk.auth.generateChallengeToken(did, JWT_ALGORITHM, JWT_SECRET)
```
```js
const isValid = await sk.auth.verifyChallengeSignature(nonce, signature, did);
```
```js
const accessToken = await sk.auth.generateAccessToken(did, JWT_ALGORITHM, JWT_SECRET);
```
```js
// Validate attributes based on requirements (LWS_TEMPLATE)
const {
attributes: validated,
errors,
valid
} = await req.attributeManager.validateAttributes(attributes, LWS_TEMPLATE);
```
```js
// 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);
```
```js
const jwt = await sk.jwt.issueJWT(did, JWT_ALGORITHM, JWT_SECRET);
```
```js
const decoded = await sk.jwt.validateJWT(token, JWT_ALGORITHM, JWT_SECRET);
```
[The GPL-3.0 License](http://opensource.org/licenses/GPL-3.0)
Copyright (c) 2018 SelfKey Foundation