Skip to content

Commit

Permalink
feat: add support for keybase.io
Browse files Browse the repository at this point in the history
close #21, fix #21

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
  • Loading branch information
Certseeds committed Aug 6, 2023
1 parent 76a2e87 commit d051d72
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
40 changes: 40 additions & 0 deletions src/components/linkes/keybase.io.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interface keybase_io_key {
key_id?: string,
raw_key?: string,
}

const getKeybaseKey: (username: string) => Promise<string> = async (username: string) => {
if ((username?.length ?? 0) > 0) {
const url = `https://keybase.io/_/api/1.0/user/lookup.json?username=${username}&fields=public_keys`
const ownKey = await fetch(url, {
method: 'get',
headers: { 'Accept': 'application/json', },
}).then(body => body.json())
.then(json => {
const value = getBundleKey(json);
return value.raw_key
}) ?? '';
return ownKey;
}
return '';
}

const getBundleKey: (keys: any) => keybase_io_key = (keys: any) => {
// keys is a {}, not []
if (0 === (Object.keys(keys).length ?? 0)) {
return {};
} else if (keys["status"]["code"] !== 0 || keys["status"]["name"] !== "OK") {
console.log("keybase.io api error");
return {};
}
const primary = keys["them"]["public_keys"]["primary"];
console.log(`mtime: ${primary["mtime"]}, ctime: ${primary["ctime"]}, etime: ${primary["etime"]}`);// TODO, what is those means?
return {
key_id: primary["kid"],
raw_key: primary["bundle"],

}
};

export type { keybase_io_key };
export { getKeybaseKey, getBundleKey };
9 changes: 6 additions & 3 deletions src/components/linktokey.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { getGithubKey } from '@/components/linkes/github';
import { getKeybaseKey } from './linkes/keybase.io';


const fetchKeyByUrl: (prefix: string, path: string) => Promise<string> = async (prefix: string, path: string) => {
if (prefix === 'github') {
return await getGithubKey(path);
} else if (prefix.length === 0) {
if (prefix.length === 0) {
const defaultKey = await fetch('https://blog.certseeds.com/public.key', {
method: 'get',
}).then(body => body.text())
return defaultKey
} else if (prefix === 'github') {
return await getGithubKey(path);
} else if (prefix === 'keybase.io') {
return await getKeybaseKey(path);
} else if (prefix === 'raw') {
console.log('please ensure the cors rules allow this page')
if (!path.startsWith('https')) {
Expand Down

0 comments on commit d051d72

Please sign in to comment.