From 62df82b5c880f22d65d023db866226a90095cde5 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Tue, 17 Nov 2020 02:18:08 +0100 Subject: [PATCH] Allow verification of keys and claim arrays --- src/claims.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/claims.js b/src/claims.js index 196a126..e9f0f1d 100644 --- a/src/claims.js +++ b/src/claims.js @@ -15,7 +15,9 @@ limitations under the License. */ const mergeOptions = require('merge-options') const validUrl = require('valid-url') +const openpgp = require('openpgp') const serviceproviders = require('./serviceproviders') +const keys = require('./keys') const utils = require('./utils') const runVerificationJson = ( @@ -106,20 +108,42 @@ const runVerification = (proofData, spData) => { return res } -const verify = async (uri, fingerprint, opts) => { +const verify = async (input, fingerprint, opts) => { + if (input instanceof openpgp.key.Key) { + const fingerprintLocal = await keys.getFingerprint(input) + const claims = await keys.getClaims(input) + return await verify(claims, fingerprintLocal, opts) + } + if (input instanceof Array) { + const promises = input.map(async (uri, i) => { + return new Promise(async (resolve, reject) => { + try { + const res = await verify(uri, fingerprint, opts) + resolve(res) + } catch (e) { + console.error(`Claim verification failed: ${uri}`, e) + reject(e) + } + }) + }) + + return Promise.all(promises).then((values) => { + return values + }) + } + + const uri = input + if (!fingerprint) { fingerprint = null } - if (!opts) { - opts = {} - } const defaultOpts = { returnMatchesOnly: false, proxyPolicy: 'adaptive', doipProxyHostname: 'proxy.keyoxide.org', } - opts = mergeOptions(defaultOpts, opts) + opts = mergeOptions(defaultOpts, opts ? opts : {}) if (!validUrl.isUri(uri)) { throw new Error('Not a valid URI')