From 270d55cc7c027c5cb9b317ad014a0fb35a89eeca Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Jan 2026 13:39:52 +0000 Subject: [PATCH] Fix "NostrTools is required" error during zap signing This patch updates `js/payments/zapSplit.js` and `js/payments/nwcClient.js` to replace legacy manual event signing (which relied on `nostr-tools` v1 methods `getEventHash` and `signEvent` that are missing in v2) with the centralized `signEventWithPrivateKey` helper from `js/nostr/publishHelpers.js`. This ensures compatibility with the installed `nostr-tools` version and resolves the error preventing zaps. --- js/payments/nwcClient.js | 7 ++----- js/payments/zapSplit.js | 12 +++--------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/js/payments/nwcClient.js b/js/payments/nwcClient.js index 752d8250..451691ea 100644 --- a/js/payments/nwcClient.js +++ b/js/payments/nwcClient.js @@ -1,6 +1,7 @@ // js/payments/nwcClient.js import { nostrToolsReady } from "../nostrToolsBootstrap.js"; +import { signEventWithPrivateKey } from "../nostr/publishHelpers.js"; import { userLogger } from "../utils/logger.js"; import { isZapAllowanceExhaustedError } from "./zapSharedState.js"; @@ -1288,7 +1289,6 @@ export async function ensureWallet({ settings } = {}) { } async function encryptRequestPayload(context, payload) { - const tools = assertNostrTools(["getEventHash", "signEvent"]); const encryption = await ensureEncryption(context); const plaintext = JSON.stringify(payload); @@ -1307,10 +1307,7 @@ async function encryptRequestPayload(context, payload) { tags, }; - event.id = tools.getEventHash(event); - event.sig = tools.signEvent(event, context.secretKey); - - return event; + return signEventWithPrivateKey(event, context.secretKey); } function registerPendingRequest(eventId, payloadId, { resolve, reject, timeoutMs }) { diff --git a/js/payments/zapSplit.js b/js/payments/zapSplit.js index d9109855..8363c618 100644 --- a/js/payments/zapSplit.js +++ b/js/payments/zapSplit.js @@ -12,6 +12,7 @@ import { import { ensureWallet, sendPayment } from "./nwcClient.js"; import { getPlatformLightningAddress } from "./platformAddress.js"; import { RELAY_URLS } from "../nostr/toolkit.js"; +import { signEventWithPrivateKey } from "../nostr/publishHelpers.js"; import { userLogger } from "../utils/logger.js"; import { validateZapReceipt } from "./zapReceiptValidator.js"; import { @@ -346,11 +347,6 @@ function buildZapRequest({ comment, lnurl, }) { - const tools = getNostrTools(); - if (!tools?.getEventHash || !tools?.signEvent) { - throw new Error("NostrTools is required to sign zap requests."); - } - const tags = []; if (recipientPubkey) { tags.push(["p", recipientPubkey]); @@ -385,10 +381,8 @@ function buildZapRequest({ pubkey: wallet?.clientPubkey || "", }; - event.id = tools.getEventHash(event); - event.sig = tools.signEvent(event, wallet?.secretKey); - - return JSON.stringify(event); + const signedEvent = signEventWithPrivateKey(event, wallet?.secretKey); + return JSON.stringify(signedEvent); } function determineRecipientPubkey({ recipientType, metadata, videoEvent }) {