2020-10-24 03:19:35 -06:00
|
|
|
const validUrl = require('valid-url')
|
2020-10-24 03:45:30 -06:00
|
|
|
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) => {
|
2020-10-24 03:45:30 -06:00
|
|
|
if (!validUrl.isUri(uri)) {
|
2020-10-24 03:19:35 -06:00
|
|
|
throw new Error('The provided URI was not valid')
|
|
|
|
}
|
2020-10-24 03:45:30 -06:00
|
|
|
|
|
|
|
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
|
2020-10-24 03:45:30 -06:00
|
|
|
exports.serviceproviders = serviceproviders
|
2020-10-24 03:19:35 -06:00
|
|
|
exports.serviceprovidersList = serviceprovidersList
|