doipjs/src/index.js

43 lines
891 B
JavaScript
Raw Normal View History

2020-10-24 03:19:35 -06:00
const validUrl = require('valid-url')
const { serviceprovidersList, serviceproviders } = require('./serviceproviders')
const matchSp = (uri) => {
let matches = [], sp
serviceprovidersList.forEach((spName, i) => {
sp = serviceproviders[spName]
if (sp.reURI.test(uri)) {
matches.push(sp.processURI(uri))
}
})
return matches
}
2020-10-23 14:35:53 -06:00
2020-10-24 03:19:35 -06:00
const verify = (uri, fingerprint, opts) => {
if (!validUrl.isUri(uri)) {
2020-10-24 03:19:35 -06:00
throw new Error('The provided URI was not valid')
}
const spMatches = matchSp(uri)
if (opts.returnMatchesOnly) {
return spMatches
}
// let claimHasBeenVerified = false
// let iSp = 0, sp
// while (!claimHasBeenVerified) {
//
// if (!sp.reURI.test(uri)) {
// continue;
// }
//
// iSP++
// }
2020-10-23 14:35:53 -06:00
}
2020-10-23 17:25:01 -06:00
exports.verify = verify
exports.serviceproviders = serviceproviders
2020-10-24 03:19:35 -06:00
exports.serviceprovidersList = serviceprovidersList