From fe89e54a2a8db30a46dc9c9e3352e624cde0680e Mon Sep 17 00:00:00 2001
From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com>
Date: Sun, 5 Oct 2025 01:46:43 -0400
Subject: [PATCH] Ensure nip04 helper is available for zaps
---
index.html | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/index.html b/index.html
index a5b11fe7..57552031 100644
--- a/index.html
+++ b/index.html
@@ -215,11 +215,39 @@
? nostrTools.generatePrivateKey
: undefined;
- window.NostrTools = {
+ const hasWorkingNip04 = (candidate) =>
+ candidate &&
+ typeof candidate.encrypt === "function" &&
+ typeof candidate.decrypt === "function";
+
+ let resolvedNip04 = hasWorkingNip04(nostrTools?.nip04)
+ ? nostrTools.nip04
+ : null;
+
+ if (!resolvedNip04) {
+ try {
+ const fallbackModule = await import(
+ "https://esm.sh/nostr-tools@1.8.3?target=es2022&exports=nip04"
+ );
+ if (hasWorkingNip04(fallbackModule?.nip04)) {
+ resolvedNip04 = fallbackModule.nip04;
+ }
+ } catch (error) {
+ console.warn("[bitvid] Failed to load nostr nip04 helper", error);
+ }
+ }
+
+ const toolsBundle = {
...nostrTools,
generatePrivateKey: normalizedGeneratePrivateKey,
generateSecretKey: normalizedGenerateSecretKey,
};
+
+ if (resolvedNip04) {
+ toolsBundle.nip04 = resolvedNip04;
+ }
+
+ window.NostrTools = toolsBundle;