From ca09d56fe4a03a3f376c9458ecb46ab292928196 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 19 Sep 2025 00:03:05 +0800 Subject: [PATCH] feat: add random --- script-meta-v2.json | 9 +++++++++ single-scripts/random.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 single-scripts/random.ts diff --git a/script-meta-v2.json b/script-meta-v2.json index 9988336..bf3eb8c 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -87,6 +87,15 @@ "publish_time": 1737272626140, "update_time": 1750472965159 }, + "random.ts": { + "script_name": "random.ts", + "script_length": 780, + "script_sha256": "71a282b63f97e0f6d0c5dd93bf1e71a395233e73ece741ec59b5f559ce9e82b1", + "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/random.ts", + "single_script_file": true, + "publish_time": 1758211365931, + "update_time": 1758211365931 + }, "sigstore-verify.ts": { "script_name": "sigstore-verify.ts", "script_length": 3676, diff --git a/single-scripts/random.ts b/single-scripts/random.ts new file mode 100755 index 0000000..2a91a47 --- /dev/null +++ b/single-scripts/random.ts @@ -0,0 +1,31 @@ +#!/usr/bin/env runts -- --allow-read + +import { parseArgs } from "jsr:@std/cli/parse-args"; + +const flags = parseArgs(Deno.args, { + boolean: ["help"], + string: ["length"], +}); + +if (flags.help) { + console.log("random.ts [--post-message] [--length ]"); + Deno.exit(0); +} + +const len = parseInt(flags.length || "12", 10); + +const buffer = new Uint8Array(len); +const file = await Deno.open("/dev/random", { read: true }); +try { + const nread = await file.read(buffer); + if (nread == null) { + throw "Read from /dev/random failed"; + } +} finally { + file.close(); +} + +Deno.stdout.write(buffer); + +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250919T000056+08:00.MEUCIQD0uwOh8xr+8Oog7x6s +// cUutQYrO4oFkS+SU1mZogTFuwAIgE7PWbiDvzAKFUSCc0byrdwWkXrcJp+7CDWr3+e83Zy4=