diff --git a/script-meta-v2.json b/script-meta-v2.json index 40f3e62..76d84af 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -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", diff --git a/single-scripts/publickey.ts b/single-scripts/publickey.ts index 1b12cc0..b992ccf 100755 --- a/single-scripts/publickey.ts +++ b/single-scripts/publickey.ts @@ -1,11 +1,13 @@ -#!/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 -const {X509Certificate, createPublicKey} = await import("node:crypto"); +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) { console.log("Usage: publickey.ts "); @@ -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 exportedJwk = publicKey.export({ format: "jwk" }); + 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]; @@ -40,13 +41,13 @@ try { // try jwk try { const key = JSON.parse(firstArgument); - const publicKey = createPublicKey({key, format: "jwk"}); + const publicKey = createPublicKey({ key, format: "jwk" }); printPublicKey(publicKey); Deno.exit(0); } catch (_e) { // IGNORE } - console.error(`Parse certificate or public key failed: ${e}`); + log.error(`Parse certificate or public key failed: ${e}`); Deno.exit(1); }