-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeygen.ts
37 lines (28 loc) · 970 Bytes
/
keygen.ts
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
import { decode } from "https://denopkg.com/chiefbiiko/std-encoding/mod.ts";
import { generateKeyPair, KeyPair } from "./mod.ts";
function main(): void {
let keyPair: KeyPair;
let secretKey: string;
let stringKeyPair: string;
try {
keyPair = generateKeyPair();
const publicKey: string = decode(keyPair.publicKey, "base64url");
const kid: string = decode(keyPair.kid, "base64url");
const stringPeerPublicKey: string = JSON.stringify(
{ publicKey, kid, name: Deno.args[1] },
null,
2,
);
secretKey = decode(keyPair.secretKey, "base64url");
stringKeyPair = JSON.stringify({ secretKey, publicKey, kid }, null, 2);
console.log(`key pair\n${stringKeyPair}`);
console.log(`peer public key\n${stringPeerPublicKey}`);
} catch (err) {
console.error(err.stack);
} finally {
keyPair.secretKey.fill(0x00, 0, keyPair.secretKey.byteLength);
secretKey = null;
stringKeyPair = null;
}
}
main();