From 34dc50d031e94959cfe9730cf2c9622746416718 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sat, 5 Dec 2020 23:14:09 +0100 Subject: [PATCH] Run prettier --- docs/api.md | 58 +++++++++++++++++++-------------------- src/claims.js | 6 ++++- src/serviceproviders.js | 60 ++++++++++++++++++++++------------------- 3 files changed, 66 insertions(+), 58 deletions(-) diff --git a/docs/api.md b/docs/api.md index ccea21d..0584d90 100644 --- a/docs/api.md +++ b/docs/api.md @@ -50,11 +50,11 @@ Verifies the identity behind the provided **array of uris** using the **fingerpr **Parameters** -| Name | Type | Mandatory | Description | -| ----------- | ------ | --------- | -------------------------------- | -| uriArray | array | true | array of uris | -| fingerprint | string | false | the fingerprint of the claim | -| opts | object | false | options (see below) | +| Name | Type | Mandatory | Description | +| ----------- | ------ | --------- | ---------------------------- | +| uriArray | array | true | array of uris | +| fingerprint | string | false | the fingerprint of the claim | +| opts | object | false | options (see below) | **Options** @@ -71,15 +71,15 @@ _(async)_ doip.claims.verify(key, [fingerprint], [opts]) Verifies the identity behind the claims contained within the provided **key** using the **fingerprint**. This key is outputted by the -[keys.fetch.*()](#keysfetchuriuri) commands. +[keys.fetch.\*()](#keysfetchuriuri) commands. **Parameters** -| Name | Type | Mandatory | Description | -| ----------- | ------ | --------- | -------------------------------- | -| key | object | true | a public key | -| fingerprint | string | false | the fingerprint of the claim | -| opts | object | false | options (see below) | +| Name | Type | Mandatory | Description | +| ----------- | ------ | --------- | ---------------------------- | +| key | object | true | a public key | +| fingerprint | string | false | the fingerprint of the claim | +| opts | object | false | options (see below) | **Options** @@ -99,9 +99,9 @@ other `keys.fetch.*` commands. **Parameters** -| Name | Type | Mandatory | Description | -| ----------- | ------ | --------- | -------------------------------- | -| uri | string | true | public key identifier | +| Name | Type | Mandatory | Description | +| ---- | ------ | --------- | --------------------- | +| uri | string | true | public key identifier | Possible formats for `uri`: @@ -110,7 +110,7 @@ Possible formats for `uri`: `hkp:EMAIL` ⇒ `keys.fetch.hkp(EMAIL)` `hkp:EMAIL:KEYSERVER` ⇒ `keys.fetch.hkp(EMAIL, KEYSERVER)` `wkd:EMAIL` ⇒ `keys.fetch.wkd(EMAIL)` -`kb:USERNAME:FINGERPRINT` ⇒ `keys.fetch.keybase(USERNAME, FINGERPRINT)` +`kb:USERNAME:FINGERPRINT` ⇒ `keys.fetch.keybase(USERNAME, FINGERPRINT)` **Returns** @@ -124,10 +124,10 @@ Fetches a key using HKP-compatible key servers. **Parameters** -| Name | Type | Mandatory | Description | -| ---------------- | ------ | --------- | -------------------------------- | -| fingerprint | string | true | public key identifier | -| keyserverBaseUrl | string | false | base URL of keyserver | +| Name | Type | Mandatory | Description | +| ---------------- | ------ | --------- | --------------------- | +| fingerprint | string | true | public key identifier | +| keyserverBaseUrl | string | false | base URL of keyserver | `keyserverBaseUrl` defaults to `https://keys.openpgp.org/`. @@ -143,10 +143,10 @@ Fetches a key using HKP-compatible key servers. **Parameters** -| Name | Type | Mandatory | Description | -| ---------------- | ------ | --------- | -------------------------------- | -| email | string | true | public key identifier | -| keyserverBaseUrl | string | false | base URL of keyserver | +| Name | Type | Mandatory | Description | +| ---------------- | ------ | --------- | --------------------- | +| email | string | true | public key identifier | +| keyserverBaseUrl | string | false | base URL of keyserver | `keyserverBaseUrl` defaults to `https://keys.openpgp.org/`. @@ -162,9 +162,9 @@ Fetches a key using the WKD protocol. **Parameters** -| Name | Type | Mandatory | Description | -| ----------- | ------ | --------- | -------------------------------- | -| wkdId | string | true | WKD identifier | +| Name | Type | Mandatory | Description | +| ----- | ------ | --------- | -------------- | +| wkdId | string | true | WKD identifier | `wkdId` looks like an email address and is formatted as `username@domain.org`. @@ -180,9 +180,9 @@ Parses the `keyPlaintext`. **Parameters** -| Name | Type | Mandatory | Description | -| ------------ | ------ | --------- | -------------------------------- | -| keyPlaintext | string | true | ASCII key content | +| Name | Type | Mandatory | Description | +| ------------ | ------ | --------- | ----------------- | +| keyPlaintext | string | true | ASCII key content | **Returns** diff --git a/src/claims.js b/src/claims.js index ad31a26..395ba3e 100644 --- a/src/claims.js +++ b/src/claims.js @@ -16,7 +16,11 @@ limitations under the License. const path = require('path') const mergeOptions = require('merge-options') const validUrl = require('valid-url') -const openpgp = require(path.join(require.resolve('openpgp'), '..', 'openpgp.min.js')) +const openpgp = require(path.join( + require.resolve('openpgp'), + '..', + 'openpgp.min.js' +)) const serviceproviders = require('./serviceproviders') const keys = require('./keys') const utils = require('./utils') diff --git a/src/serviceproviders.js b/src/serviceproviders.js index b21805c..da580ae 100644 --- a/src/serviceproviders.js +++ b/src/serviceproviders.js @@ -65,37 +65,41 @@ const match = (uri, opts) => { return matches } -const directRequestHandler = async (spData, opts) => { - const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri - let res +const directRequestHandler = (spData, opts) => { + return new Promise(async (resolve, reject) => { + const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri + let res - switch (spData.proof.format) { - case 'json': - res = await req(url, null, { - Accept: 'application/json', - 'User-Agent': `doipjs/${require('../package.json').version}`, - }) - return await res.json() - break - case 'text': - res = await req(url) - return await res.text() - break - default: - throw new Error('No specified proof data format') - break - } + switch (spData.proof.format) { + case 'json': + res = await req(url, null, { + Accept: 'application/json', + 'User-Agent': `doipjs/${require('../package.json').version}`, + }) + resolve(await res.json()) + break + case 'text': + res = await req(url) + resolve(await res.text()) + break + default: + reject('No specified proof data format') + break + } + }) } -const proxyRequestHandler = async (spData, opts) => { - const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri - const res = await req( - utils.generateProxyURL(spData.proof.format, url, opts), - null, - { Accept: 'application/json' } - ) - const json = await res.json() - return json.content +const proxyRequestHandler = (spData, opts) => { + return new Promise(async (resolve, reject) => { + const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri + const res = await req( + utils.generateProxyURL(spData.proof.format, url, opts), + null, + { Accept: 'application/json' } + ) + const json = await res.json() + resolve(json.content) + }) } exports.list = list