feat: update publickey.ts

This commit is contained in:
2025-01-19 16:34:32 +08:00
parent 86d2b0b3f6
commit 05f64ab761
2 changed files with 14 additions and 13 deletions

View File

@@ -35,12 +35,12 @@
},
"publickey.ts": {
"script_name": "publickey.ts",
"script_length": 1572,
"script_sha256": "83947c19952ef8f69f50354b809bc584e4ff702a663364c9572db8a0bb32cc8e",
"script_length": 1720,
"script_sha256": "05096a661ceb9fe417fe0628c69ab5276a92057c12507358fa0e0539ee22c455",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/publickey.ts",
"single_script_file": true,
"publish_time": 1737272626140,
"update_time": 1737272626140
"update_time": 1737275658224
},
"sigstore-verify.ts": {
"script_name": "sigstore-verify.ts",

View File

@@ -1,10 +1,12 @@
#!/usr/bin/env -S deno run --allow-env
#!/usr/bin/env -S deno run --allow-env --allow-import
// Reference:
// - https://docs.deno.com/examples/command_line_arguments/
// - https://docs.deno.com/api/node/crypto/~/X509Certificate#property_issuercertificate
// - https://docs.deno.com/api/node/crypto/~/createPublicKey
import {log} from "https://hatter.ink/script/fetch/library/deno-commons-mod.ts?202501191623";
const { X509Certificate, createPublicKey } = await import("node:crypto");
if (Deno.args.length === 0) {
@@ -23,12 +25,11 @@ if (Deno.args.length === 0) {
// deno-lint-ignore no-explicit-any
function printPublicKey(publicKey: any) {
console.log('JWK:');
const exportedJwk = publicKey.export({ format: "jwk" });
console.log(JSON.stringify(exportedJwk, null, 4));
console.log();
console.log("PEM:");
console.log(publicKey.export({format: "pem", type: "spki"}));
const exportedJwkJson = JSON.stringify(exportedJwk, null, 4);
const exportedPem = publicKey.export({ format: "pem", type: "spki" });
log.success(`JWK\n${exportedJwkJson}`);
log.success(`PEM:\n${exportedPem}`);
}
const firstArgument = Deno.args[0];
@@ -47,6 +48,6 @@ try {
// IGNORE
}
console.error(`Parse certificate or public key failed: ${e}`);
log.error(`Parse certificate or public key failed: ${e}`);
Deno.exit(1);
}