Run prettier

This commit is contained in:
Yarmo Mackenbach 2021-04-19 11:44:30 +02:00
parent 5b35051c7a
commit 802ebb2f4c
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
32 changed files with 349 additions and 286 deletions

View file

@ -1,5 +1,4 @@
--- ---
kind: pipeline kind: pipeline
name: build-stable-proxy-container name: build-stable-proxy-container
@ -32,7 +31,6 @@ trigger:
- tag - tag
--- ---
kind: pipeline kind: pipeline
name: build-dev-proxy-container name: build-dev-proxy-container

View file

@ -131,7 +131,9 @@ class Claim {
*/ */
set uri(uri) { set uri(uri) {
if (this.state !== E.ClaimState.INIT) { if (this.state !== E.ClaimState.INIT) {
throw new Error('Cannot change the URI, this claim has already been matched') throw new Error(
'Cannot change the URI, this claim has already been matched'
)
} }
// Verify validity of URI // Verify validity of URI
if (uri && !validUrl.isUri(uri)) { if (uri && !validUrl.isUri(uri)) {
@ -150,7 +152,9 @@ class Claim {
*/ */
set fingerprint(fingerprint) { set fingerprint(fingerprint) {
if (this.state === E.ClaimState.VERIFIED) { if (this.state === E.ClaimState.VERIFIED) {
throw new Error('Cannot change the fingerprint, this claim has already been verified') throw new Error(
'Cannot change the fingerprint, this claim has already been verified'
)
} }
this.fingerprint = fingerprint this.fingerprint = fingerprint
} }
@ -161,7 +165,7 @@ class Claim {
* @param anything - Anything will throw an error * @param anything - Anything will throw an error
*/ */
set state(anything) { set state(anything) {
throw new Error('Cannot change a claim\'s state') throw new Error("Cannot change a claim's state")
} }
/** /**
@ -170,7 +174,7 @@ class Claim {
* @param anything - Anything will throw an error * @param anything - Anything will throw an error
*/ */
set dataMatches(anything) { set dataMatches(anything) {
throw new Error('Cannot change a claim\'s dataMatches') throw new Error("Cannot change a claim's dataMatches")
} }
/** /**
@ -179,7 +183,7 @@ class Claim {
* @param anything - Anything will throw an error * @param anything - Anything will throw an error
*/ */
set verification(anything) { set verification(anything) {
throw new Error('Cannot change a claim\'s verification data') throw new Error("Cannot change a claim's verification data")
} }
/** /**
@ -210,9 +214,7 @@ class Claim {
this.dataMatches.push(candidate) this.dataMatches.push(candidate)
} else { } else {
// Set a single candidate and stop // Set a single candidate and stop
this.dataMatches = [ this.dataMatches = [candidate]
candidate
]
return false return false
} }
@ -262,7 +264,11 @@ class Claim {
if (proofData) { if (proofData) {
// Run the verification process // Run the verification process
verificationResult = verifications.run(proofData.result, claimData, this.fingerprint) verificationResult = verifications.run(
proofData.result,
claimData,
this.fingerprint
)
verificationResult.proof = { verificationResult.proof = {
fetcher: proofData.fetcher, fetcher: proofData.fetcher,
viaProxy: proofData.viaProxy, viaProxy: proofData.viaProxy,
@ -285,9 +291,7 @@ class Claim {
if (verificationResult.completed) { if (verificationResult.completed) {
// Store the result, keep a single match and stop verifying // Store the result, keep a single match and stop verifying
this.verification = verificationResult this.verification = verificationResult
this.dataMatches = [ this.dataMatches = [claimData]
claimData
]
index = this.dataMatches.length index = this.dataMatches.length
} }
} }

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://dev.to/api/articles/${match[1]}/${match[2]}`, url: `https://dev.to/api/articles/${match[1]}/${match[2]}`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://${match[1]}/u/${match[2]}.json`, url: `https://${match[1]}/u/${match[2]}.json`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -42,8 +42,8 @@ const processURI = (uri) => {
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
data: { data: {
domain: match[1], domain: match[1],
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.URI, format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: uri, url: uri,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.FINGERPRINT, format: E.ClaimFormat.FINGERPRINT,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://${match[1]}/api/v1/repos/${match[2]}/gitea_proof`, url: `https://${match[1]}/api/v1/repos/${match[2]}/gitea_proof`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://api.github.com/gists/${match[2]}`, url: `https://api.github.com/gists/${match[2]}`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
domain: match[1], domain: match[1],
username: match[2], username: match[2],
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`, url: `https://hacker-news.firebaseio.com/v0/user/${match[1]}.json`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.URI, format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
domain: match[1], domain: match[1],
nick: match[2], nick: match[2],
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.URI, format: E.ClaimFormat.URI,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://liberapay.com/${match[1]}/public.json`, url: `https://liberapay.com/${match[1]}/public.json`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://lobste.rs/u/${match[1]}.json`, url: `https://lobste.rs/u/${match[1]}.json`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: uri, url: uri,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.FINGERPRINT, format: E.ClaimFormat.FINGERPRINT,

View file

@ -57,8 +57,8 @@ const processURI = (uri) => {
data: { data: {
eventId: params['org.keyoxide.e'], eventId: params['org.keyoxide.e'],
roomId: params['org.keyoxide.r'], roomId: params['org.keyoxide.r'],
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `${uri}/api/config`, url: `${uri}/api/config`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.FINGERPRINT, format: E.ClaimFormat.FINGERPRINT,

View file

@ -43,8 +43,8 @@ const processURI = (uri) => {
data: { data: {
url: `https://www.reddit.com/user/${match[1]}/comments/${match[2]}.json`, url: `https://www.reddit.com/user/${match[1]}/comments/${match[2]}.json`,
format: E.ProofFormat.JSON, format: E.ProofFormat.JSON,
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -42,8 +42,8 @@ const processURI = (uri) => {
format: E.ProofFormat.TEXT, format: E.ProofFormat.TEXT,
data: { data: {
tweetId: match[2], tweetId: match[2],
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -42,9 +42,9 @@ const processURI = (uri) => {
format: E.ProofFormat.TEXT, format: E.ProofFormat.TEXT,
data: { data: {
id: `${match[1]}@${match[2]}`, id: `${match[1]}@${match[2]}`,
field: 'note' field: 'note',
} },
} },
}, },
claim: { claim: {
format: E.ClaimFormat.MESSAGE, format: E.ClaimFormat.MESSAGE,

View file

@ -18,25 +18,25 @@ const E = require('./enums')
const opts = { const opts = {
proxy: { proxy: {
hostname: null, hostname: null,
policy: E.ProxyPolicy.NEVER policy: E.ProxyPolicy.NEVER,
}, },
claims: { claims: {
irc: { irc: {
nick: null nick: null,
}, },
matrix: { matrix: {
instance: null, instance: null,
accessToken: null accessToken: null,
}, },
xmpp: { xmpp: {
service: null, service: null,
username: null, username: null,
password: null password: null,
}, },
twitter: { twitter: {
bearerToken: null bearerToken: null,
},
}, },
}
} }
exports.opts = opts exports.opts = opts

View file

@ -63,7 +63,7 @@ const VerificationStatus = {
INIT: 0, INIT: 0,
INPROGRESS: 1, INPROGRESS: 1,
FAILED: 2, FAILED: 2,
COMPLETED: 3 COMPLETED: 3,
} }
Object.freeze(VerificationStatus) Object.freeze(VerificationStatus)

View file

@ -38,7 +38,9 @@ module.exports.fn = async (data, opts) => {
} }
const urlProject = `https://${data.domain}/api/v4/users/${user.id}/projects` const urlProject = `https://${data.domain}/api/v4/users/${user.id}/projects`
const resProject = await req(urlProject, null, { Accept: 'application/json' }) const resProject = await req(urlProject, null, {
Accept: 'application/json',
})
const jsonProject = await resProject.json() const jsonProject = await resProject.json()
const project = jsonProject.find((proj) => proj.path === 'gitlab_proof') const project = jsonProject.find((proj) => proj.path === 'gitlab_proof')

View file

@ -32,7 +32,9 @@ module.exports.fn = async (data, opts) => {
try { try {
validator.isAscii(opts.claims.twitter.bearerToken) validator.isAscii(opts.claims.twitter.bearerToken)
} catch (err) { } catch (err) {
throw new Error(`Twitter fetcher was not set up properly (${err.message})`) throw new Error(
`Twitter fetcher was not set up properly (${err.message})`
)
} }
bentReq( bentReq(

View file

@ -206,8 +206,8 @@ const process = (publicKey) => {
key: { key: {
data: publicKey, data: publicKey,
fetchMethod: null, fetchMethod: null,
uri: null uri: null,
} },
}) })
}) })
} }

View file

@ -49,7 +49,9 @@ const handleBrowserRequests = (data, opts) => {
break break
case E.ProofAccess.NOCORS: case E.ProofAccess.NOCORS:
case E.ProofAccess.SERVER: case E.ProofAccess.SERVER:
throw new Error('Impossible to fetch proof (bad combination of service access and proxy policy)') throw new Error(
'Impossible to fetch proof (bad combination of service access and proxy policy)'
)
break break
default: default:
throw new Error('Invalid proof access value') throw new Error('Invalid proof access value')
@ -69,7 +71,9 @@ const handleBrowserRequests = (data, opts) => {
return createFallbackRequestPromise(data, opts) return createFallbackRequestPromise(data, opts)
break break
case E.ProofAccess.SERVER: case E.ProofAccess.SERVER:
throw new Error('Impossible to fetch proof (bad combination of service access and proxy policy)') throw new Error(
'Impossible to fetch proof (bad combination of service access and proxy policy)'
)
break break
default: default:
throw new Error('Invalid proof access value') throw new Error('Invalid proof access value')
@ -105,16 +109,17 @@ const handleNodeRequests = (data, opts) => {
const createDefaultRequestPromise = (data, opts) => { const createDefaultRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fetcher[data.proof.request.fetcher].fn(data.proof.request.data, opts) fetcher[data.proof.request.fetcher]
.then(res => { .fn(data.proof.request.data, opts)
.then((res) => {
return resolve({ return resolve({
fetcher: data.proof.request.fetcher, fetcher: data.proof.request.fetcher,
data: data, data: data,
viaProxy: false, viaProxy: false,
result: res result: res,
}) })
}) })
.catch(err => { .catch((err) => {
return reject(err) return reject(err)
}) })
}) })
@ -124,7 +129,11 @@ const createProxyRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let proxyUrl let proxyUrl
try { try {
proxyUrl = utils.generateProxyURL(data.proof.request.fetcher, data.proof.request.data, opts); proxyUrl = utils.generateProxyURL(
data.proof.request.fetcher,
data.proof.request.data,
opts
)
} catch (err) { } catch (err) {
reject(err) reject(err)
} }
@ -132,18 +141,19 @@ const createProxyRequestPromise = (data, opts) => {
const requestData = { const requestData = {
url: proxyUrl, url: proxyUrl,
format: data.proof.request.format, format: data.proof.request.format,
fetcherTimeout: fetcher[data.proof.request.fetcher].timeout fetcherTimeout: fetcher[data.proof.request.fetcher].timeout,
} }
fetcher.http.fn(requestData, opts) fetcher.http
.then(res => { .fn(requestData, opts)
.then((res) => {
return resolve({ return resolve({
fetcher: 'http', fetcher: 'http',
data: data, data: data,
viaProxy: true, viaProxy: true,
result: res result: res,
}) })
}) })
.catch(err => { .catch((err) => {
return reject(err) return reject(err)
}) })
}) })
@ -152,15 +162,15 @@ const createProxyRequestPromise = (data, opts) => {
const createFallbackRequestPromise = (data, opts) => { const createFallbackRequestPromise = (data, opts) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
createDefaultRequestPromise(data, opts) createDefaultRequestPromise(data, opts)
.then(res => { .then((res) => {
return resolve(res) return resolve(res)
}) })
.catch(err1 => { .catch((err1) => {
createProxyRequestPromise(data, opts) createProxyRequestPromise(data, opts)
.then(res => { .then((res) => {
return resolve(res) return resolve(res)
}) })
.catch(err2 => { .catch((err2) => {
return reject([err1, err2]) return reject([err1, err2])
}) })
}) })

View file

@ -21,7 +21,7 @@ const validUrl = require('valid-url')
const jsdom = require('jsdom') const jsdom = require('jsdom')
const { client, xml } = require('@xmpp/client') const { client, xml } = require('@xmpp/client')
const debug = require('@xmpp/debug') const debug = require('@xmpp/debug')
const irc = require("irc-upd") const irc = require('irc-upd')
require('dotenv').config() require('dotenv').config()
const xmpp_service = process.env.XMPP_SERVICE || null const xmpp_service = process.env.XMPP_SERVICE || null
@ -218,12 +218,15 @@ router.get('/get/xmpp/:xmppid/:xmppdata', async (req, res) => {
break break
default: default:
vcard = dom.window.document.querySelector(req.params.xmppdata).textContent vcard = dom.window.document.querySelector(req.params.xmppdata)
.textContent
break break
} }
return res.status(200).json(vcard) return res.status(200).json(vcard)
} catch (error) { } catch (error) {
return res.status(400).json({ message: 'Request could not be fulfilled', error: error }) return res
.status(400)
.json({ message: 'Request could not be fulfilled', error: error })
} }
}) })
@ -232,10 +235,14 @@ router.get('/get/twitter/:tweetid', async (req, res) => {
return res.status(500).json('Twitter not enabled on server') return res.status(500).json('Twitter not enabled on server')
} }
bentReq(`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`, null, { bentReq(
`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`,
null,
{
Accept: 'application/json', Accept: 'application/json',
Authorization: `Bearer ${twitter_bearer_token}` Authorization: `Bearer ${twitter_bearer_token}`,
}) }
)
.then(async (data) => { .then(async (data) => {
return await data.json() return await data.json()
}) })
@ -243,7 +250,13 @@ router.get('/get/twitter/:tweetid', async (req, res) => {
return res.status(200).json({ data: data, message: 'Success', error: {} }) return res.status(200).json({ data: data, message: 'Success', error: {} })
}) })
.catch((error) => { .catch((error) => {
return res.status(error.statusCode || 400).json({ data: [], message: 'Request could not be fulfilled', error: error }) return res
.status(error.statusCode || 400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
}) })
}) })
@ -255,7 +268,7 @@ router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
const url = `https://${matrix_instance}/_matrix/client/r0/rooms/${req.params.matrixroomid}/event/${req.params.matrixeventid}?access_token=${matrix_access_token}` const url = `https://${matrix_instance}/_matrix/client/r0/rooms/${req.params.matrixroomid}/event/${req.params.matrixeventid}?access_token=${matrix_access_token}`
bentReq(url, null, { bentReq(url, null, {
Accept: 'application/json' Accept: 'application/json',
}) })
.then(async (data) => { .then(async (data) => {
return await data.json() return await data.json()
@ -264,7 +277,13 @@ router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
return res.status(200).json({ data: data, message: 'Success', error: {} }) return res.status(200).json({ data: data, message: 'Success', error: {} })
}) })
.catch((error) => { .catch((error) => {
return res.status(error.statusCode || 400).json({ data: [], message: 'Request could not be fulfilled', error: error }) return res
.status(error.statusCode || 400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
}) })
}) })
@ -289,15 +308,23 @@ router.get('/get/irc/:ircserver/:ircnick', async (req, res) => {
client.addListener('notice', (nick, to, text, message) => { client.addListener('notice', (nick, to, text, message) => {
if (reKey.test(text)) { if (reKey.test(text)) {
const match = text.match(reKey) const match = text.match(reKey)
keys.push(match[1]); keys.push(match[1])
} }
if (reEnd.test(text)) { if (reEnd.test(text)) {
client.disconnect() client.disconnect()
return res.status(200).json({ data: keys, message: 'Success', error: {} }) return res
.status(200)
.json({ data: keys, message: 'Success', error: {} })
} }
}) })
} catch (error) { } catch (error) {
return res.status(400).json({ data: [], message: 'Request could not be fulfilled', error: error }) return res
.status(400)
.json({
data: [],
message: 'Request could not be fulfilled',
error: error,
})
} }
}) })

View file

@ -45,7 +45,8 @@ router.get('/', async (req, res) => {
}) })
// HTTP route // HTTP route
router.get('/get/http', router.get(
'/get/http',
query('url').isURL(), query('url').isURL(),
query('format').isIn([E.ProofFormat.JSON, E.ProofFormat.TEXT]), query('format').isIn([E.ProofFormat.JSON, E.ProofFormat.TEXT]),
(req, res) => { (req, res) => {
@ -54,35 +55,34 @@ router.get('/get/http',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.http
.http.fn(req.query, opts) .fn(req.query, opts)
.then(result => { .then((result) => {
switch (req.query.format) { switch (req.query.format) {
case E.ProofFormat.JSON: case E.ProofFormat.JSON:
return res.status(200).json(result) return res.status(200).json(result)
break; break
case E.ProofFormat.TEXT: case E.ProofFormat.TEXT:
return res.status(200).send(result) return res.status(200).send(result)
break; break
} }
}) })
.catch(err => { .catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err }) return res.status(400).json({ errors: err.message ? err.message : err })
}) })
}) }
)
// DNS route // DNS route
router.get('/get/dns', router.get('/get/dns', query('domain').isFQDN(), (req, res) => {
query('domain').isFQDN(),
(req, res) => {
const errors = validationResult(req) const errors = validationResult(req)
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.dns
.dns.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
@ -92,11 +92,25 @@ router.get('/get/dns',
}) })
// XMPP route // XMPP route
router.get('/get/xmpp', router.get(
'/get/xmpp',
query('id').isEmail(), query('id').isEmail(),
query('field').isIn(['fn','number','userid','url','bday','nickname','note','desc']), query('field').isIn([
'fn',
'number',
'userid',
'url',
'bday',
'nickname',
'note',
'desc',
]),
async (req, res) => { async (req, res) => {
if (!opts.claims.xmpp.service || !opts.claims.xmpp.username || !opts.claims.xmpp.password) { if (
!opts.claims.xmpp.service ||
!opts.claims.xmpp.username ||
!opts.claims.xmpp.password
) {
return res.status(501).json({ errors: 'XMPP not enabled on server' }) return res.status(501).json({ errors: 'XMPP not enabled on server' })
} }
const errors = validationResult(req) const errors = validationResult(req)
@ -104,20 +118,19 @@ router.get('/get/xmpp',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.xmpp
.xmpp.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
.catch((err) => { .catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err }) return res.status(400).json({ errors: err.message ? err.message : err })
}) })
}) }
)
// Twitter route // Twitter route
router.get('/get/twitter', router.get('/get/twitter', query('tweetId').isInt(), async (req, res) => {
query('tweetId').isInt(),
async (req, res) => {
if (!opts.claims.twitter.bearerToken) { if (!opts.claims.twitter.bearerToken) {
return res.status(501).json({ errors: 'Twitter not enabled on server' }) return res.status(501).json({ errors: 'Twitter not enabled on server' })
} }
@ -126,8 +139,8 @@ router.get('/get/twitter',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.twitter
.twitter.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
@ -137,7 +150,8 @@ router.get('/get/twitter',
}) })
// Matrix route // Matrix route
router.get('/get/matrix', router.get(
'/get/matrix',
query('roomId').isString(), query('roomId').isString(),
query('eventId').isString(), query('eventId').isString(),
async (req, res) => { async (req, res) => {
@ -149,20 +163,19 @@ router.get('/get/matrix',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.matrix
.matrix.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
.catch((err) => { .catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err }) return res.status(400).json({ errors: err.message ? err.message : err })
}) })
}) }
)
// IRC route // IRC route
router.get('/get/irc', router.get('/get/irc', query('nick').isString(), async (req, res) => {
query('nick').isString(),
async (req, res) => {
if (!opts.claims.irc.nick) { if (!opts.claims.irc.nick) {
return res.status(501).json({ errors: 'IRC not enabled on server' }) return res.status(501).json({ errors: 'IRC not enabled on server' })
} }
@ -171,8 +184,8 @@ router.get('/get/irc',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.irc
.irc.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
@ -182,7 +195,8 @@ router.get('/get/irc',
}) })
// Gitlab route // Gitlab route
router.get('/get/gitlab', router.get(
'/get/gitlab',
query('domain').isFQDN(), query('domain').isFQDN(),
query('username').isString(), query('username').isString(),
async (req, res) => { async (req, res) => {
@ -191,14 +205,15 @@ router.get('/get/gitlab',
return res.status(400).json({ errors: errors.array() }) return res.status(400).json({ errors: errors.array() })
} }
fetcher fetcher.gitlab
.gitlab.fn(req.query, opts) .fn(req.query, opts)
.then((data) => { .then((data) => {
return res.status(200).send(data) return res.status(200).send(data)
}) })
.catch((err) => { .catch((err) => {
return res.status(400).json({ errors: err.message ? err.message : err }) return res.status(400).json({ errors: err.message ? err.message : err })
}) })
}) }
)
module.exports = router module.exports = router

View file

@ -28,7 +28,9 @@ app.get('/', (req, res) => {
return res.status(200).json({ message: 'Available endpoints: /api' }) return res.status(200).json({ message: 'Available endpoints: /api' })
}) })
app.get('/api', (req, res) => { app.get('/api', (req, res) => {
return res.status(200).json({ message: 'Available API versions: /api/1, /api/2' }) return res
.status(200)
.json({ message: 'Available API versions: /api/1, /api/2' })
}) })
app.all('*', (req, res) => { app.all('*', (req, res) => {
return res.status(404).json({ message: 'API endpoint not found' }) return res.status(404).json({ message: 'API endpoint not found' })

View file

@ -22,10 +22,12 @@ const process = (signature) => {
let sigData, let sigData,
result = { result = {
fingerprint: null, fingerprint: null,
users: [{ users: [
{
userData: {}, userData: {},
claims: [], claims: [],
}], },
],
primaryUserIndex: null, primaryUserIndex: null,
key: { key: {
data: null, data: null,
@ -88,7 +90,9 @@ const process = (signature) => {
if (!result.key.data) { if (!result.key.data) {
try { try {
const match = preferredKeyServer.match(/^(.*\:\/\/)?([^/]*)(?:\/)?$/i) const match = preferredKeyServer.match(/^(.*\:\/\/)?([^/]*)(?:\/)?$/i)
result.key.uri = `hkp:${match[2]}:${issuerKeyId ? issuerKeyId : signersUserId}` result.key.uri = `hkp:${match[2]}:${
issuerKeyId ? issuerKeyId : signersUserId
}`
result.key.data = await keys.fetch.uri(result.key.uri) result.key.data = await keys.fetch.uri(result.key.uri)
result.key.fetchMethod = 'hkp' result.key.fetchMethod = 'hkp'
} catch (e) { } catch (e) {
@ -99,7 +103,7 @@ const process = (signature) => {
result.fingerprint = result.key.data.keyPacket.getFingerprint() result.fingerprint = result.key.data.keyPacket.getFingerprint()
result.users[0].claims.forEach(claim => { result.users[0].claims.forEach((claim) => {
claim.fingerprint = result.fingerprint claim.fingerprint = result.fingerprint
}) })
@ -107,7 +111,7 @@ const process = (signature) => {
let userData let userData
if (signersUserId) { if (signersUserId) {
result.key.data.users.forEach(user => { result.key.data.users.forEach((user) => {
if (user.userId.email == signersUserId) { if (user.userId.email == signersUserId) {
userData = user userData = user
} }

View file

@ -25,13 +25,13 @@ const generateProxyURL = (type, data, opts) => {
let queryStrings = [] let queryStrings = []
Object.keys(data).forEach(key => { Object.keys(data).forEach((key) => {
queryStrings.push(`${key}=${encodeURIComponent(data[key])}`) queryStrings.push(`${key}=${encodeURIComponent(data[key])}`)
}) })
return `http://${ return `http://${opts.proxy.hostname}/api/2/get/${type}?${queryStrings.join(
opts.proxy.hostname '&'
}/api/2/get/${type}?${queryStrings.join('&')}` )}`
} }
const generateClaim = (fingerprint, format) => { const generateClaim = (fingerprint, format) => {

View file

@ -16,12 +16,7 @@ limitations under the License.
const utils = require('./utils') const utils = require('./utils')
const E = require('./enums') const E = require('./enums')
const runJSON = ( const runJSON = (proofData, checkPath, checkClaim, checkRelation) => {
proofData,
checkPath,
checkClaim,
checkRelation
) => {
let re let re
if (!proofData) { if (!proofData) {
@ -31,7 +26,9 @@ const runJSON = (
if (Array.isArray(proofData)) { if (Array.isArray(proofData)) {
let result = false let result = false
proofData.forEach((item, i) => { proofData.forEach((item, i) => {
if (result) { return } if (result) {
return
}
result = runJSON(item, checkPath, checkClaim, checkRelation) result = runJSON(item, checkPath, checkClaim, checkRelation)
}) })
return result return result
@ -46,8 +43,10 @@ const runJSON = (
break break
case E.ClaimRelation.EQUALS: case E.ClaimRelation.EQUALS:
return proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() == return (
proofData.replace(/\r?\n|\r|\\/g, '').toLowerCase() ==
checkClaim.toLowerCase() checkClaim.toLowerCase()
)
break break
case E.ClaimRelation.ONEOF: case E.ClaimRelation.ONEOF: