tinyrelayfile
tinyrelay/scripts/conformance/setup.ts/

scripts/conformance/setup.ts raw
1// Global setup: provision the tenant under test with the tiny CLI so the
2// conformance suite writes as its owner. Set TINY_PREPROVISIONED=1 to skip.
3import { execFileSync } from "node:child_process";
4import { getPublicKey } from "nostr-tools/pure";
5import { sha256 } from "@noble/hashes/sha2.js";
6import { hexToBytes } from "@noble/hashes/utils.js";
7
8const relayURL = process.env.RELAY_URL ?? "ws://127.0.0.1:7447";
9const httpURL = relayURL.replace(/^ws/, "http").replace(/\/$/, "") + "/";
10const owner = process.env.CLAIM_SK
11 ? hexToBytes(process.env.CLAIM_SK)
12 : sha256(new TextEncoder().encode("tiny conformance owner"));
13
14function provision() {
15 const bin = process.env.TINY_BIN ?? "tiny";
16 const name = process.env.TINY_TENANT ?? new URL(httpURL).hostname.split(".")[0];
17 const template = process.env.TINY_TEMPLATE ?? "default";
18 const args = ["tenant", "create", "--name", name, "--owner", getPublicKey(owner), "--template", template];
19 if (process.env.TINY_DATA_DIR) args.push("--data-dir", process.env.TINY_DATA_DIR);
20 execFileSync(bin, args, { stdio: "inherit" });
21}
22
23export default async function setup() {
24 if (process.env.TINY_PREPROVISIONED !== "1") provision();
25 const response = await fetch(httpURL, { headers: { accept: "application/nostr+json" } });
26 if (!response.ok) throw new Error(`relay did not become ready at ${httpURL}: ${response.status}`);
27 console.log(`conformance tenant ready at ${relayURL} as ${getPublicKey(owner)}`);
28}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs