This commit is contained in:
zmeyer44 2023-10-18 16:29:05 -04:00
parent eecc3875fe
commit 98f7763d69
4 changed files with 13 additions and 15 deletions

View File

@ -3,7 +3,7 @@ import FormModal from "./FormModal";
import { z } from "zod";
import { useModal } from "@/app/_providers/modal/provider";
import { toast } from "sonner";
import { generateRandomString, randomId } from "@/lib/nostr";
import { generateRandomStringLength } from "@/lib/nostr";
import { satsToBtc } from "@/lib/utils";
import useCurrentUser from "@/lib/hooks/useCurrentUser";
import { useNDK } from "@/app/_providers/ndk";
@ -34,7 +34,7 @@ export default function CreateList() {
const { getSigner } = useSigner()!;
async function handleSubmit(data: CreateListType) {
setIsLoading(true);
const random = randomId();
const random = generateRandomStringLength(8);
const tags = [
["title", data.title],
["name", data.title],

View File

@ -7,7 +7,11 @@ import NDK, {
type NostrEvent,
NDKUser,
} from "@nostr-dev-kit/ndk";
import { generateRandomString, encryptMessage, randomId } from "@/lib/nostr";
import {
generateRandomString,
encryptMessage,
generateRandomStringLength,
} from "@/lib/nostr";
import { unixTimeNowInSeconds } from "@/lib/nostr/dates";
import { getTagsValues } from "@/lib/nostr/utils";
@ -155,7 +159,7 @@ export async function createList(
tags: [
["name", title],
["description", description ?? ""],
["d", randomId()],
["d", generateRandomStringLength(8)],
],
});
}

View File

@ -24,6 +24,7 @@ export async function sendZap(
) {
console.log("sendzap called", amount);
const event = await new NDKEvent(ndk, _event);
console.log("Event", event);
const pr = await event.zap(amount * 1000, comment);
if (!pr) {
console.log("No PR");

View File

@ -142,17 +142,10 @@ function create32ByteBuffer(inputString: string) {
const buffer = Buffer.from(hash, "hex");
return buffer;
}
export function randomId() {
// @ts-ignore
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11)
.replace(/[018]/g, (c: any) =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0]! & (15 >> (c / 4)))
).toString(16),
)
.slice(0, 8) as string;
}
export function generateRandomString() {
return crypto.randomBytes(32).toString("hex");
}
export function generateRandomStringLength(length: number) {
return crypto.randomBytes(length).toString("hex");
}