1
0
Fork 1
mirror of https://codeberg.org/keyoxide/doipjs.git synced 2025-01-10 06:39:27 -07:00

WIP Handling of fetched data

This commit is contained in:
Yarmo Mackenbach 2020-10-24 18:43:41 +02:00
parent 55ee948111
commit 1b1d11c802

View file

@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const validUrl = require('valid-url')
const bent = require('bent')
const req = bent('GET')
const { serviceprovidersList, serviceproviders } = require('./serviceproviders')
const matchServiceproviders = (uri) => {
@ -29,7 +31,7 @@ const matchServiceproviders = (uri) => {
return matches
}
const verify = (uri, fingerprint, opts) => {
const verify = async (uri, fingerprint, opts) => {
if (!opts) { opts = {} }
if (!validUrl.isUri(uri)) {
@ -41,6 +43,31 @@ const verify = (uri, fingerprint, opts) => {
if ('returnMatchesOnly' in opts && opts.returnMatchesOnly) {
return spMatches
}
let claimHasBeenVerified = false, sp, iSp = 0, res, proofData
while (!claimHasBeenVerified && iSp < spMatches.length) {
sp = spMatches[iSp]
res = null
if (!sp.proof.useProxy || 'forceDirectRequest' in opts && opts.forceDirectRequest) {
res = await req(sp.proof.fetch ? sp.proof.fetch : sp.proof.uri)
switch (sp.proof.format) {
case 'json':
proofData = await res.json()
break
case 'text':
proofData = await res.text()
break
default:
throw new Error('No specified proof data format')
break
}
}
iSp++
}
}
exports.verify = verify