diff --git a/endpoints/keybase.ts b/endpoints/keybase.ts new file mode 100644 index 0000000..89e46c6 --- /dev/null +++ b/endpoints/keybase.ts @@ -0,0 +1,45 @@ +import got from '../libs/got' +import { + badgenServe, + BadgenServeMeta as Meta, + BadgenServeHandlers as Handlers, + BadgenServeHandlerArgs as Args +} from '../libs/badgen-serve' + +export const meta: Meta = { + title: 'Keybase', + examples: { + '/keybase/pgp/lukechilds': 'pgp key', + } +} + +export const handlers: Handlers = { + '/keybase/:topic/:username': handler +} + +export default badgenServe(handlers) + +async function handler ({ topic, username }: Args) { + const endpoint = `https://keybase.io/_/api/1.0/user/lookup.json` + const { body } = await got(endpoint, { + query: { + usernames: username, + fields: 'public_keys' + } + }) + + const fingerprint = body.them[0].public_keys.primary.key_fingerprint + + switch (topic) { + case 'pgp': + return { + subject: 'PGP', + status: convertFingerprintTo64bit(fingerprint), + color: 'blue' + } + } +} + +const convertFingerprintTo64bit = fingerprint => { + return fingerprint.slice(-16).toUpperCase().match(/.{4}/g).join(' ') +} diff --git a/libs/examples.ts b/libs/examples.ts index faa6d83..3403477 100644 --- a/libs/examples.ts +++ b/libs/examples.ts @@ -38,8 +38,9 @@ export const liveBadgeList = [ 'xo', 'badgesize', 'jsdelivr', - 'opencollective' // utilities + 'opencollective', + 'keybase', ] export async function loadExamples () {