From d76e9a99620ac25a9fa636d1e8e03b35667282a0 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Tue, 13 Feb 2024 15:45:35 -0500 Subject: [PATCH] expose keypair as HTTP endpoint fixes: https://github.com/pinax-network/substreams-sink-webhook/issues/12 --- bin/cli.ts | 2 +- index.ts | 5 +++-- src/banner.ts | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/cli.ts b/bin/cli.ts index ad086c3..69a2014 100755 --- a/bin/cli.ts +++ b/bin/cli.ts @@ -31,7 +31,7 @@ command.action(action); program .command("keypair") - .description("Generate TweetNaCl keypair") + .description("Generate random Ed25519 private & public keys") .action(() => { const { publicKey, privateKey } = keyPair(); console.log(`PUBLIC_KEY=${publicKey}`); diff --git a/index.ts b/index.ts index cbd75a1..1d43303 100644 --- a/index.ts +++ b/index.ts @@ -5,9 +5,9 @@ import { postWebhook } from "./src/postWebhook.js"; import type { SessionInit } from "@substreams/core/proto"; import type { WebhookRunOptions } from "./bin/cli.js"; import { banner } from "./src/banner.js"; -import { toText } from "./src/http.js"; +import { toJSON, toText } from "./src/http.js"; import { ping } from "./src/ping.js"; -import { checkKey } from "./index.js"; +import { checkKey, keyPair } from "./src/auth/ed25519.js"; export * from "./src/auth/ed25519.js"; export * from "./src/schemas.js"; @@ -73,6 +73,7 @@ export async function action(options: WebhookRunOptions) { http.listen(options); http.server.on("request", (req, res) => { if (req.url === "/") return toText(res, banner()); + if (req.url === "/keypair") return toJSON(res, keyPair()); }); emitter.on("close", () => { diff --git a/src/banner.ts b/src/banner.ts index 3bf5ac0..fe81f50 100644 --- a/src/banner.ts +++ b/src/banner.ts @@ -12,6 +12,9 @@ export function banner() { ░░░╚═╝░░░╚═╝░░╚══════╝╚═════╝░╚═╝░░╚═╝░╚════╝░░╚════╝░╚═╝░░╚═╝╚═════╝░ `; - text += ` ${pkg.name} v${pkg.version}\n`; + text += ` ${pkg.name} v${pkg.version}\n\n`; + text += `HTTP routes\n`; + text += `GET /metrics\tPrometheus Metrics\n`; + text += `GET /keypair\tGenerate random Ed25519 private & public keys\n`; return text; }