* Add Keybase PGP badge * Return 'not found' if the key is not present * Change the default colour * Add more constraints to the schema * Render 64-bit fingerprints * Add example * Add a 'hex()' constraint to the fingerprint * Improve error handling * Add class 'KeybaseProfile' * Add unit tests for Keybase PGP * Add Keybase BTC * Add unit tests for Keybase BTC * Add Keybase ZEC * Add unit tests for Keybase ZEC * Add Keybase XLM * Add unit tests for Keybase XLM * Validate the BTC address using a regex Regex taken from https://mokagio.github.io/tech-journal/2014/11/21/regex-bitcoin.html. * Exclude 'not found' from addresses' value in unit tests * Remove useless keywords * Add the link to the Keybase API documentation * Move the colour into 'defaultBadgeData' * Remove the HTTP method 'GET' is already the default one. * Improve the error handling for Keybase BTC * Add more constraints to the Keybase BTC schema * Update one unit test for Keybase BTC * Fix the error handling for Keybase BTC * Add more unit tests for Keybase BTC * Improve the error handling for Keybase ZEC * Improve the error handling for Keybase PGP * Improve the error handling for Keybase XLM * Display a real username value in the examples * Include the status code in the schemas * Move the category to the base class The same category is used by all badges. * Add function 'transform' to the base class The function 'transform' is used to encapsulate the error handling logic as it is the same in each service.
90 lines
1.7 KiB
JavaScript
90 lines
1.7 KiB
JavaScript
'use strict'
|
|
|
|
const KeybaseProfile = require('./keybase-profile')
|
|
const Joi = require('joi')
|
|
const { nonNegativeInteger } = require('../validators')
|
|
|
|
const keyFingerprintSchema = Joi.object({
|
|
status: Joi.object({
|
|
code: nonNegativeInteger.required(),
|
|
}).required(),
|
|
them: Joi.array()
|
|
.items(
|
|
Joi.object({
|
|
public_keys: {
|
|
primary: {
|
|
key_fingerprint: Joi.string()
|
|
.hex()
|
|
.required(),
|
|
},
|
|
},
|
|
})
|
|
.required()
|
|
.allow(null)
|
|
)
|
|
.min(0)
|
|
.max(1),
|
|
}).required()
|
|
|
|
module.exports = class KeybasePGP extends KeybaseProfile {
|
|
static get apiVersion() {
|
|
return '1.0'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'keybase/pgp',
|
|
pattern: ':username',
|
|
}
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'pgp',
|
|
color: 'informational',
|
|
}
|
|
}
|
|
|
|
async handle({ username }) {
|
|
const options = {
|
|
form: {
|
|
usernames: username,
|
|
fields: 'public_keys',
|
|
},
|
|
}
|
|
|
|
const data = await this.fetch({
|
|
schema: keyFingerprintSchema,
|
|
options,
|
|
})
|
|
|
|
const { user } = this.transform({ data })
|
|
const primaryKey = user.public_keys.primary
|
|
|
|
if (primaryKey == null) {
|
|
return {
|
|
message: 'no key fingerprint found',
|
|
color: 'inactive',
|
|
}
|
|
}
|
|
|
|
return this.constructor.render({ fingerprint: primaryKey.key_fingerprint })
|
|
}
|
|
|
|
static render({ fingerprint }) {
|
|
return {
|
|
message: fingerprint.slice(-16).toUpperCase(),
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Keybase PGP',
|
|
namedParams: { username: 'skyplabs' },
|
|
staticPreview: this.render({ fingerprint: '1863145FD39EE07E' }),
|
|
},
|
|
]
|
|
}
|
|
}
|