Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/MyDidCom/mydid-auth


https://github.com/MyDidCom/mydid-auth

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

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);
}
```