https://github.com/MyDidCom/mydid-auth
https://github.com/MyDidCom/mydid-auth
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/MyDidCom/mydid-auth
- Owner: MyDidCom
- Created: 2021-10-25T08:06:43.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T16:40:03.000Z (over 1 year ago)
- Last Synced: 2025-03-24T17:46:03.400Z (over 1 year ago)
- Language: TypeScript
- Size: 389 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-ccamel - MyDidCom/mydid-auth - (TypeScript)
README
# mydid-auth
## Usage
Install package :
```shell
npm i @mydidcom/mydid-auth
```
Import package :
```javascript
const mydidAuth = require("@mydidcom/mydid-auth");
```
**Initialize with provider and smart contract address :**
_initialize: (config: object)_
```javascript
try {
mydidAuth.initialize({
web3GivenProvider: "https://data-seed-prebsc-1-s1.binance.org:8545/",
smartContractAddress: "0x6828adf1aED03be429eE42053a4F72CDd3c70846",
});
} catch (err) {
// Handle error
console.log("Error trying to initialize mydid-auth : " + err);
}
```
> If module is not initialized, will used default value :
>
> - web3GivenProvider: 'https://data-seed-prebsc-1-s1.binance.org:8545/'
> - smartContractAddress: '0x6828adf1aED03be429eE42053a4F72CDd3c70846'
**Create verifiable presentation request :**
_createVPRequest: (challenge: string, domain: string, verifiableCredentials: string[])_
```javascript
const VPRequest = mydidAuth.createVPRequest(
// Custom string for identifying challenge in database
"6360c6acfe7951946f0532dcee1d314645312a4b5480d80646ff9241ce68892d",
// Callback where will be sent verifiable presentation
"https://mywebsite.com/api/v1/callback",
// Verifiable credentials asked for authentication
["email", "nationality"]
);
```
> If not verifiable credentials are needed, set verifiableCredentials to an empty array.
**Validate consistency of verifiable presentation :**
_validateVPConsistency: (VPData: object)_
```javascript
try {
mydidAuth.validateVPConsistency(verifiablePresentation);
} catch (err) {
// Handle error
console.log('Can't valid verifiable presentation consistency : ' + err);
}
```
**Validate authenticity of verifiable presentation :**
_validateVPAuthenticity: async (VPData: object)_
```javascript
try {
await mydidAuth.validateVPAuthenticity(verifiablePresentation);
} catch (err) {
// Handle error
console.log('Can't valid verifiable presentation authenticity : ' + err);
}
```