doipjs/src/utils.js

32 lines
745 B
JavaScript
Raw Normal View History

const generateProxyURL = (type, url, opts) => {
2020-11-07 18:07:02 -07:00
if (!opts || !opts.doipProxyHostname) {
return null
}
2020-11-08 04:22:36 -07:00
let addParam = ''
if (type == 'xmpp') {
addParam += '/DESC'
}
2020-11-07 18:07:02 -07:00
return `https://${
opts.doipProxyHostname
2020-11-08 04:22:36 -07:00
}/api/1/get/${type}/${encodeURIComponent(url)}${addParam}`
2020-11-03 19:01:02 -07:00
}
2020-10-24 16:39:43 -06:00
const generateClaim = (fingerprint, format) => {
switch (format) {
2020-10-24 16:31:14 -06:00
case 'uri':
2020-10-24 16:39:43 -06:00
return `openpgp4fpr:${fingerprint}`
2020-11-07 18:07:02 -07:00
break
2020-10-24 16:31:14 -06:00
case 'message':
2020-10-24 16:39:43 -06:00
return `[Verifying my OpenPGP key: openpgp4fpr:${fingerprint}]`
2020-11-07 18:07:02 -07:00
break
2020-10-24 16:31:14 -06:00
case 'fingerprint':
2020-10-24 16:39:43 -06:00
return fingerprint
2020-11-07 18:07:02 -07:00
break
2020-10-24 16:31:14 -06:00
default:
throw new Error('No valid claim format')
}
}
2020-11-03 19:01:02 -07:00
exports.generateProxyURL = generateProxyURL
2020-10-24 16:31:14 -06:00
exports.generateClaim = generateClaim