Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Refactor entry points #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 1 addition & 65 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,3 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier'],
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
// Turn off certain typescript-eslint rules
'@typescript-eslint/no-unused-vars': 0, // This is enabled in our tsconfig file becuase the lint doens't support JSX usage
'@typescript-eslint/array-type': 0,
'@typescript-eslint/explicit-function-return-type': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/prefer-interface': 0,
'@typescript-eslint/prefer-namespace-keyword': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-parameter-properties': 0,
// https://github.com/typescript-eslint/typescript-eslint/issues/249
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/no-object-literal-type-assertion': 0,
'@typescript-eslint/indent': 0,

// Override certain typescript-eslint rules
'@typescript-eslint/member-delimiter-style': [
2,
{
multiline: {
delimiter: 'none',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/explicit-member-accessibility': [
2,
{
accessibility: 'no-public',
overrides: {parameterProperties: 'explicit'},
},
],
'@typescript-eslint/interface-name-prefix': [2, 'always'],

// Turn on the prettier rules
'prettier/prettier': 'error',
// This is a weird one and needs to be duped here and .prettierrc
// https://github.com/prettier/eslint-config-prettier#max-len
'max-len': [
2,
{
code: 140,
tabWidth: 2,
ignoreUrls: true,
ignoreComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
},
extends: ['@bloomprotocol/eslint-config'],
}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
*.log
.DS_Store
node_modules
.rts2_cache_cjs
.rts2_cache_esm
.rts2_cache_umd
dist
9 changes: 1 addition & 8 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
module.exports = {
semi: false,
singleQuote: true,
printWidth: 140,
trailingComma: 'all',
jsxBracketSameLine: false,
bracketSpacing: false,
}
module.exports = require('@bloomprotocol/prettier-config')
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 2.0.0

**Improvements**

- By making the public API smaller it is now easier to know how to use this library
- `validateVerifiablePresentationResponse` now returns "invalid" if any of the onchain validations comes back invalid

**Breaking**

- Most functions have been removed from the public API. The two main entry points are now `validateVerifiablePresentationResponse` and `validateVerifiableAuthResponse`
- All `type`s have been removed from this library, they are exported by [Attestations Lib](https://github.com/hellobloom/attestations-lib) now.

## 1.0.0

- Initial release
61 changes: 44 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ When the user allows access you get a response back.

### ResponseData

The payload is formatted as specified by Bloom's interpretation of the [W3C Verifiable Presentation Data Model](https://w3c.github.io/vc-data-model/#presentations-0). The payload differs depending on whether or not the verification is for purposes of sharing Verifiable Credential(s), or Verifiable Authentication.
The payload is formatted as specified by Bloom's interpretation of the [W3C Verifiable Presentation Data Model](https://w3c.github.io/vc-data-model/#presentations-0). The payload differs depending on whether or not the verification is for purposes of sharing Verifiable Credential(s), or Verifiable Authentication.

Format of the HTTP POST request (Verifiable Credential):

Expand All @@ -54,12 +54,12 @@ Format of the HTTP POST request (Verifiable Credential):

Format of the HTTP POST request (Verifiable Authentication):

| Name | Description | Type |
| -------------------- | ------------------------------------------------------------------------------ | -------------------------- |
| context | URLs linking to machine readable documents describing how to interpet the data | \`string[]\` |
| type | Standard type string specifying the document ('VerifiableAuth') | \`string\` |
| proof | Presentation proof showing the sender's authority over the shared data | \`AuthenticationProof\` |
| signature | Signature of \`packedData\` by the user with their mnemonic. | \`string\` |
| Name | Description | Type |
| --------- | ------------------------------------------------------------------------------ | ----------------------- |
| context | URLs linking to machine readable documents describing how to interpet the data | \`string[]\` |
| type | Standard type string specifying the document ('VerifiableAuth') | \`string\` |
| proof | Presentation proof showing the sender's authority over the shared data | \`AuthenticationProof\` |
| signature | Signature of \`packedData\` by the user with their mnemonic. | \`string\` |

### Verifiable Credential

Expand Down Expand Up @@ -242,13 +242,13 @@ Format of a users verified data

Format of a users verified data

| Name | Description | Type |
| -------------- | --------------------------------------------------------------- | ---------- |
| type | Identifier of this type of presentation proof | \`string\` |
| created | RFC3339 datetime of when this proof was generated and signed | \`string\` |
| creator | Identifier of holder sharing the credential. Eth address or DID | \`string\` |
| nonce | Token used to make this request unique | \`string\` |
| domain | Website of recipient where user intends to share the data | \`string\` |
| Name | Description | Type |
| ------- | --------------------------------------------------------------- | ---------- |
| type | Identifier of this type of presentation proof | \`string\` |
| created | RFC3339 datetime of when this proof was generated and signed | \`string\` |
| creator | Identifier of holder sharing the credential. Eth address or DID | \`string\` |
| nonce | Token used to make this request unique | \`string\` |
| domain | Website of recipient where user intends to share the data | \`string\` |

`

Expand Down Expand Up @@ -348,14 +348,14 @@ Format of a users verified data

## Receive

The endpoint specified in the QR code should be configured to accept data in the format shown in [ResponseData](#responsedata).
The endpoint specified in the QR code should be configured to accept data in the format shown in [ResponseData](#responsedata). In addition to using this library to validate the received data you should enusre that the `token` passed back is valid, it should be treated as a one-time use token to avoid replay attacks.

```typescript
import {validateUntypedResponseData} from '@bloomprotocol/verify-kit'
import {validateVerifiablePresentationResponse} from '@bloomprotocol/verify-kit'

app.post('/scan', async (req, res) => {
try {
const verifiedData = await validateUntypedResponseData(req.body, {
const verifiedData = await validateVerifiablePresentationResponse(req.body, {
validateOnChain: env.validateOnChain,
web3Provider: env.web3Provider,
})
Expand All @@ -379,6 +379,33 @@ app.post('/scan', async (req, res) => {
})
```

Or if you are expecting an auth reponse:

```typescript
import {validateVerifiableAuthResponse} from '@bloomprotocol/verify-kit'

app.post('/scan', async (req, res) => {
try {
const verifiedAuth = validateVerifiableAuthResponse(req.body)
if (verifiedAuth.kind === 'invalid') {
res.status(400).json({
success: false,
message: 'Auth is not valid',
verifiedAuth,
})
return
}

res.status(200).json({success: true, message: 'Auth Received'})
} catch (err) {
res.status(400).json({
success: false,
message: 'Something went wrong',
})
}
})
```

# Using Verify Kit for BloomID Sign-In

In conjuction with this libary you will use [Share Kit](https://github.com/hellobloom/share-kit) to render an element to request users share their data with you.
Expand Down
Loading