mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2025-01-10 14:39:28 -07:00
Add handling of proof data
This commit is contained in:
parent
6e966f4df5
commit
118bfc1c0f
1 changed files with 15 additions and 5 deletions
20
src/index.js
20
src/index.js
|
@ -17,15 +17,17 @@ const validUrl = require('valid-url')
|
||||||
const bent = require('bent')
|
const bent = require('bent')
|
||||||
const req = bent('GET')
|
const req = bent('GET')
|
||||||
const serviceproviders = require('./serviceproviders')
|
const serviceproviders = require('./serviceproviders')
|
||||||
|
const claimVerification = require('./claimVerification')
|
||||||
|
|
||||||
const verify = async (uri, fingerprint, opts) => {
|
const verify = async (uri, fingerprint, opts) => {
|
||||||
if (!opts) { opts = {} }
|
if (!opts) { opts = {} }
|
||||||
|
if (!fingerprint) { fingerprint = null }
|
||||||
|
|
||||||
if (!validUrl.isUri(uri)) {
|
if (!validUrl.isUri(uri)) {
|
||||||
throw new Error('Not a valid URI')
|
throw new Error('Not a valid URI')
|
||||||
}
|
}
|
||||||
|
|
||||||
const spMatches = serviceproviders.match(uri)
|
const spMatches = serviceproviders.match(uri, fingerprint)
|
||||||
|
|
||||||
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
|
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
|
||||||
return spMatches
|
return spMatches
|
||||||
|
@ -33,14 +35,15 @@ const verify = async (uri, fingerprint, opts) => {
|
||||||
|
|
||||||
let claimHasBeenVerified = false, sp, iSp = 0, res, proofData
|
let claimHasBeenVerified = false, sp, iSp = 0, res, proofData
|
||||||
while (!claimHasBeenVerified && iSp < spMatches.length) {
|
while (!claimHasBeenVerified && iSp < spMatches.length) {
|
||||||
sp = spMatches[iSp]
|
spData = spMatches[iSp]
|
||||||
|
spData.claim.fingerprint = fingerprint
|
||||||
|
|
||||||
res = null
|
res = null
|
||||||
|
|
||||||
if (!sp.proof.useProxy || 'forceDirectRequest' in opts && opts.forceDirectRequest) {
|
if (!spData.proof.useProxy || 'forceDirectRequest' in opts && opts.forceDirectRequest) {
|
||||||
res = await req(sp.proof.fetch ? sp.proof.fetch : sp.proof.uri)
|
res = await req(spData.proof.fetch ? spData.proof.fetch : spData.proof.uri)
|
||||||
|
|
||||||
switch (sp.proof.format) {
|
switch (spData.proof.format) {
|
||||||
case 'json':
|
case 'json':
|
||||||
proofData = await res.json()
|
proofData = await res.json()
|
||||||
break
|
break
|
||||||
|
@ -53,8 +56,15 @@ const verify = async (uri, fingerprint, opts) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
claimHasBeenVerified = claimVerification.run(proofData, spData)
|
||||||
|
|
||||||
iSp++
|
iSp++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
isVerified: claimHasBeenVerified,
|
||||||
|
verificationData: spData
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.verify = verify
|
exports.verify = verify
|
||||||
|
|
Loading…
Reference in a new issue