-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathcloud-token-key-cmd.ts
More file actions
50 lines (49 loc) · 1.52 KB
/
cloud-token-key-cmd.ts
File metadata and controls
50 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { SuperThis } from "@fireproof/core-types-base";
import * as rt from "@fireproof/core-runtime";
import { command, flag, option, string } from "cmd-ts";
import { exportJWK } from "jose/key/export";
export function keyCmd(sthis: SuperThis) {
return command({
name: "cli-key-cmds",
description: "handle keys for cloud token generation",
version: "1.0.0",
args: {
generatePair: flag({
long: "generatePair",
short: "g",
}),
ourToJWK: option({
long: "ourToJWK",
short: "o",
defaultValue: () => "",
type: string,
}),
JWKToour: option({
long: "JWKToour",
short: "j",
defaultValue: () => "",
type: string,
}),
},
handler: async (args) => {
switch (true) {
case !!args.ourToJWK:
{
const key = await rt.sts.env2jwk(args.ourToJWK, "ES256", sthis).then((jwk) => jwk);
// eslint-disable-next-line no-console
console.log(JSON.stringify(await exportJWK(key)));
}
break;
case args.generatePair:
{
const key = await rt.sts.SessionTokenService.generateKeyPair("ES256", { extractable: true });
// eslint-disable-next-line no-console
console.log(`${rt.sts.envKeyDefaults.PUBLIC}=${key.strings.publicKey}`);
// eslint-disable-next-line no-console
console.log(`${rt.sts.envKeyDefaults.SECRET}=${key.strings.privateKey}`);
}
break;
}
},
});
}