🔄 Synchronize Biome linting rules between relay and frontend
🛠️ Apply identical Biome configuration from frontend to relay service 🧹 Ensure consistent code formatting and quality standards across components 📝 Maintain unified development experience throughout the project
This commit is contained in:
parent
4bd0839669
commit
a4134fa416
9 changed files with 273 additions and 195 deletions
47
utils.ts
47
utils.ts
|
@ -1,19 +1,19 @@
|
|||
import { exists } from "jsr:@std/fs";
|
||||
import * as nostrTools from "@nostr/tools";
|
||||
import * as nip06 from "@nostr/tools/nip06";
|
||||
import { decodeBase64, encodeBase64 } from "jsr:@std/encoding@0.224/base64";
|
||||
import { getEveFilePath } from "./utils/files.ts";
|
||||
import { decodeBase64, encodeBase64 } from 'jsr:@std/encoding@0.224/base64';
|
||||
import { exists } from 'jsr:@std/fs';
|
||||
import * as nostrTools from '@nostr/tools';
|
||||
import * as nip06 from '@nostr/tools/nip06';
|
||||
import {
|
||||
decryptUint8Array,
|
||||
encryptionKey,
|
||||
encryptUint8Array,
|
||||
} from "./utils/encryption.ts";
|
||||
encryptionKey,
|
||||
} from './utils/encryption.ts';
|
||||
import { getEveFilePath } from './utils/files.ts';
|
||||
|
||||
export function isLocalhost(req: Request): boolean {
|
||||
const url = new URL(req.url);
|
||||
const hostname = url.hostname;
|
||||
return (
|
||||
hostname === "127.0.0.1" || hostname === "::1" || hostname === "localhost"
|
||||
hostname === '127.0.0.1' || hostname === '::1' || hostname === 'localhost'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -39,11 +39,12 @@ export function randomTimeUpTo2DaysInThePast() {
|
|||
}
|
||||
|
||||
export async function getCCNPubkey(): Promise<string> {
|
||||
const ccnPubPath = await getEveFilePath("ccn.pub");
|
||||
const seedPath = await getEveFilePath("ccn.seed");
|
||||
const ccnPubPath = await getEveFilePath('ccn.pub');
|
||||
const seedPath = await getEveFilePath('ccn.seed');
|
||||
const doWeHaveKey = await exists(ccnPubPath);
|
||||
if (doWeHaveKey) return Deno.readTextFileSync(ccnPubPath);
|
||||
const ccnSeed = Deno.env.get("CCN_SEED") ||
|
||||
const ccnSeed =
|
||||
Deno.env.get('CCN_SEED') ||
|
||||
((await exists(seedPath))
|
||||
? Deno.readTextFileSync(seedPath)
|
||||
: nip06.generateSeedWords());
|
||||
|
@ -53,7 +54,7 @@ export async function getCCNPubkey(): Promise<string> {
|
|||
|
||||
Deno.writeTextFileSync(ccnPubPath, ccnPublicKey);
|
||||
Deno.writeTextFileSync(
|
||||
await getEveFilePath("ccn.priv"),
|
||||
await getEveFilePath('ccn.priv'),
|
||||
encodeBase64(encryptedPrivateKey),
|
||||
);
|
||||
Deno.writeTextFileSync(seedPath, ccnSeed);
|
||||
|
@ -63,7 +64,7 @@ export async function getCCNPubkey(): Promise<string> {
|
|||
|
||||
export async function getCCNPrivateKey(): Promise<Uint8Array> {
|
||||
const encryptedPrivateKey = Deno.readTextFileSync(
|
||||
await getEveFilePath("ccn.priv"),
|
||||
await getEveFilePath('ccn.priv'),
|
||||
);
|
||||
return decryptUint8Array(decodeBase64(encryptedPrivateKey), encryptionKey);
|
||||
}
|
||||
|
@ -77,21 +78,25 @@ export function isAddressableEvent(kind: number): boolean {
|
|||
}
|
||||
|
||||
export function isRegularEvent(kind: number): boolean {
|
||||
return (kind >= 1000 && kind < 10000) ||
|
||||
return (
|
||||
(kind >= 1000 && kind < 10000) ||
|
||||
(kind >= 4 && kind < 45) ||
|
||||
kind === 1 ||
|
||||
kind === 2;
|
||||
kind === 2
|
||||
);
|
||||
}
|
||||
|
||||
export function isCCNReplaceableEvent(kind: number): boolean {
|
||||
return (kind >= 60000 && kind < 65536);
|
||||
return kind >= 60000 && kind < 65536;
|
||||
}
|
||||
|
||||
export function parseATagQuery(
|
||||
aTagValue: string,
|
||||
): { kind: number; pubkey: string; dTag?: string } {
|
||||
const parts = aTagValue.split(":");
|
||||
if (parts.length < 2) return { kind: 0, pubkey: "" };
|
||||
export function parseATagQuery(aTagValue: string): {
|
||||
kind: number;
|
||||
pubkey: string;
|
||||
dTag?: string;
|
||||
} {
|
||||
const parts = aTagValue.split(':');
|
||||
if (parts.length < 2) return { kind: 0, pubkey: '' };
|
||||
|
||||
return {
|
||||
kind: Number.parseInt(parts[0], 10),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue