summaryrefslogtreecommitdiff
path: root/front/src/logic/nostrill.ts
diff options
context:
space:
mode:
Diffstat (limited to 'front/src/logic/nostrill.ts')
-rw-r--r--front/src/logic/nostrill.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/front/src/logic/nostrill.ts b/front/src/logic/nostrill.ts
index bf9212d..bd5fc9c 100644
--- a/front/src/logic/nostrill.ts
+++ b/front/src/logic/nostrill.ts
@@ -1,6 +1,9 @@
import type { Event } from "@/types/nostr";
import type { Content, FC, Poast } from "@/types/trill";
import { engagementBunt, openLock } from "./bunts";
+import type { UserType } from "@/types/nostrill";
+import type { Result } from "@/types/ui";
+import { isValidPatp } from "urbit-ob";
export function eventsToFc(postEvents: Event[]): FC {
const fc = postEvents.reduce(
(acc: FC, event: Event) => {
@@ -66,6 +69,24 @@ export function eventToPoast(event: Event): Poast | null {
return poast;
}
+export function userToString(user: UserType): Result<string> {
+ if ("urbit" in user) {
+ const isValid = isValidPatp(user.urbit);
+ if (isValid) return { ok: user.urbit };
+ else return { error: "invalid @p" };
+ } else if ("nostr" in user) return { ok: user.nostr };
+ else return { error: "unknown user" };
+}
+export function isValidNostrPubkey(pubkey: string): boolean {
+ // TODO
+ if (pubkey.length !== 64) return false;
+ try {
+ BigInt("0x" + pubkey);
+ return true;
+ } catch (_e) {
+ return false;
+ }
+}
// NOTE common tags:
// imeta
// client