53 Commits
Author SHA1 Message Date
thePR0M3TH3ANandClaude Opus 4.8 96228a451b zaps: fix zap totals counting zero — coordinate used kind 0 instead of 30078
The zap write path (zapSplit.js derivePointerTag) built the `a` coordinate
tag straight from `videoEvent.kind`. bitvid's internal video objects don't
always carry the Nostr kind — it can be 0 or undefined — and the inline
builder only rejected non-finite kinds, so a kind-0 object produced a
`0:pubkey:d` coordinate (Number.isFinite(0) === true). This flowed into both
the kind-9734 zap request and the kind-30081 bitvid tally.

The read side (zapTotals / mostZappedFeed) fetches totals by querying
`30078:pubkey:d` via buildVideoAddressPointer, which defaults invalid/zero
kinds to 30078. So the writer emitted `0:...` while the reader queried
`30078:...` — they never matched and every zap counted as zero, even after
a cache clear + refresh. Confirmed against live relays: 4 published bitvid
tallies all carried `0:...` coordinates while the real video events are
kind 30078.

Fix: derivePointerTag now delegates to the same canonical
buildVideoAddressPointer the reader uses, keeping writer and reader
coordinates in lockstep. Adds a regression test driving splitAndZap with
kind 0 / undefined / non-numeric video objects, asserting the zap request's
`a` tag defaults to `30078:pubkey:d`.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-05 09:18:38 -04:00
thePR0M3TH3ANandClaude Fable 5 5a7481e30e zaps: reliable coinos platform address + fix NWC double-pay on timeout
Two things:

1. Platform fee address → [email protected] (verified live:
   allowsNostr + nostrPubkey, 1-sat min, working callback). coinos is
   Nostr-native and PUBLISHES zap receipts, unlike strike.me whose flaky LNURL
   + never-published receipts caused the platform-share pay timeouts and the
   missing zap tallies. The 30% platform fee is unchanged — only the rail.

2. Double-pay guard (bug found while diagnosing): on a `pay_invoice` timeout,
   nwcClient's nip44->nip04 encryption-fallback resent the request — but a
   timeout is ambiguous (the wallet may already be paying), so the resend
   could DOUBLE-SPEND. shouldRetryWithFallback now refuses to auto-resend any
   spending method (pay_invoice/pay_keysend/multi_pay_*) on timeout; read-only
   methods and explicit unsupported-encryption rejections (wallet never paid)
   stay retryable. The manual "Send again" retry is the safe path for a real
   payment timeout.

Tests: tests/nwc-pay-timeout-no-double-spend.test.mjs (4). Lint + build green.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-04 23:54:16 -04:00
thePR0M3TH3ANandClaude Fable 5 41e533e675 zaps: publish preimage-verified tallies on successful zap (#47)
Third slice of docs/zap-tally-plan.md §5.3-5.5 — the publish side:

- zapSplit.js: surface receipt.preimage (NWC pay_invoice result.preimage).
- zapController.js: onZapSuccess now forwards per-share proof
  {recipientType, amountSats, bolt11, preimage, zapRequest} for every settled
  share with a preimage.
- zapTallyPublisher.js (new): buildTallyFromShare (pure — builds the addressable
  tally from a share's bolt11/preimage/zap-request, d=payment_hash, pointers
  from the zap request) + publishZapTallies (best-effort, flag-gated, never
  throws).
- ModalManager.js: onZapSuccess keeps the instant optimistic bump AND publishes
  the tallies via nostrClient.signAndPublishEvent to write relays (an
  all-timeout publish is a soft success per #49). A publish failure is
  non-fatal — the durable local ledger still shows the sender their zap.

With the counting slice (025ab348), a sent zap now: shows instantly (ledger),
publishes a verified tally, and every bitvid client counts it — surviving the
recipient never publishing a 9735. Tests: tests/zap-tally-publisher.test.mjs
(5). Lint + build green.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-04 23:38:44 -04:00
thePR0M3TH3ANandClaude Fable 5 a6b2996f4e zaps: foundation for the bitvid-native zap tally (#47) — schema + verify
First slice of docs/zap-tally-plan.md (decisions D1-D5 resolved in the doc):

- ZAP_TALLY_KIND = 30081 (addressable, d=payment_hash → one canonical event
  per real payment) + NOTE_TYPES.ZAP_TALLY schema + buildZapTallyEvent
  (nostrEventSchemas.js). Video + profile pointers.
- FEATURE_ZAP_TALLY flag (constants.js), default ON per D4.
- zapReceiptValidator.js: extractBolt11Fields (payment_hash + description_hash
  from the existing bech32 walker), verifyPaymentPreimage
  (sha256(preimage)==payment_hash), verifyBitvidZapTally — the security core:
  proves the invoice was paid AND bound to this zap request (description-hash
  binding blocks reusing a leaked preimage for another video). Amount is
  bolt11-derived, never the tag; pointers come from the embedded zap request.
- Schema-doc row for kind 30081.

Tests: tests/zap-tally-verify.test.mjs (8) — preimage check, bech32 field
round-trip, valid/bad-preimage/replay/zero-sats decisions, builder tag shape
(video + profile). Lint + build green.

No publishing or counting wired yet — next slices per the plan checklist.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-04 23:32:12 -04:00
thePR0M3TH3ANandClaude Fable 5 ad62205afd zaps: retry transient LNURL failures once before failing the zap
Verified live against strike.me: the SAME lnurlp endpoint returned
{status:"ERROR","reason":"Could not get user information"} on one request
and a valid callback moments later — the address was fine, the server
blipped. fetchPayServiceData now retries once (600ms) on the transient
classes (fetch rejection, non-OK HTTP, non-JSON body, ERROR-status body);
shape-invalid payloads still fail immediately, and a persistent error
surfaces the server's reason after the single retry.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-04 09:02:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 df99bdb65f fix(zap): collapse split when creator == platform; close #3 audit
Finishes the remaining #3 zap audit items.

- zapSplit: when the platform fee would pay the SAME Lightning address as the
  creator (e.g. the creator is the platform operator), collapse to a single
  full-amount payment instead of sending two invoices to one wallet — avoids an
  extra routing fee and a confusing duplicate receipt for the same total.
- Audited split correctness: floor(amount*fee/100) with the creator taking the
  remainder loses no sats; a sub-1-sat fee rounds to 0 and the whole zap goes to
  the creator (no zero-amount platform send); fee is clamped 0–100 and a junk
  override falls back to the default. The earlier "fee landed in my own wallet"
  report is expected behavior (sender is the platform operator, or a self-zap),
  not a bug.
- Cheat-resistant tests: testCreatorEqualsPlatformCollapsesToOnePayment and
  testSplitRoundingPreservesEverySat in tests/zap-split.test.mjs.
- Receipt validation (9735) and NWC budget/retry UX confirmed already solid;
  audit plan + TODO #3 closed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-25 08:56:00 -04:00
thePR0M3TH3ANandClaude Opus 4.8 f7f246835a zap/wallet: flag non-zappable Lightning addresses; per-item settings restore
A static client can't fetch LNURL hosts that omit CORS headers, so zaps to
those creators fail. Add a browser-side reachability probe
(checkLightningAddressZappable) and surface it on both sides: the creator
is warned at wallet-connect time if their own address isn't browser-
zappable, and the zapper sees a heads-up when opening a non-reachable
creator's zap dialog.

Also fix encrypted settings restore: the "already offered" flag was
per-pubkey, so once storage was offered the wallet note was never offered
later. Track it per-item so the wallet is offered independently.
Zappability check extracted to walletZappabilityCheck.js for the size cap.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-23 14:53:51 -04:00
thePR0M3TH3ANandClaude Opus 4.8 c5589a1514 zap: fix NWC connection, dialog UX, and receipt reporting/discovery
- NWC connection was fully broken: parseNwcUri passed a hex secret to
  nostr-tools getPublicKey (needs Uint8Array) and threw. Convert hex->bytes.
- A successful zap was shown as a red error when the kind-9735 receipt
  couldn't be validated. The NWC preimage already proves payment, so a
  paid-but-unconfirmed share is now a success-with-note, not a failure.
- Receipt discovery: query by the reliably-indexed #e/#a/#p tags instead of
  #bolt11 (which most relays don't index), and poll a few times since the
  receipt is published shortly after payment.
- In-flight "Sending..." status no longer mis-toned as a warning; success
  path fully resets the form; an in-flight-open click no longer cancels the
  open (which made the popover need many clicks); fee fallback verified
  no-bypass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-23 14:53:38 -04:00
thePR0M3TH3ANandClaude Opus 4.8 dd1ce113c1 zap: graceful error when a recipient's Lightning endpoint is unreachable
Sending a zap to a creator whose LNURL endpoint is down or doesn't send
CORS headers (e.g. unitypay.cash/.well-known/lnurlp/<name>) made the browser
fetch reject with a raw "Failed to fetch", which bubbled up as the zap's
error toast — the "clunky errors" reported during the zap audit.

fetchPayServiceData now catches the network/CORS rejection and throws a
clear, coded error ("Couldn't reach this recipient's Lightning address. It
may be offline or blocking browser requests."), preserving the original as
`cause`. Non-OK HTTP and valid responses are unchanged.

Part of the zap audit (TODO #3). Also recorded: the video-modal popover
mis-positioning (3a) and that the deeper CORS issue (static client can't
fetch CORS-less LNURL hosts) may need a proxy — tracked separately.

Tests + mutation-verified. 1274 pass (known UploadModal flake).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-22 22:22:18 -04:00
thePR0M3TH3ANandClaude Opus 4.8 0ec9db70e8 fix(zap): receipt validation works with nostr-tools 2.x SimplePool
After a successful split zap, validation errored: "Unable to initialize a relay
pool for receipt validation." The validator built a fresh `new SimplePool()` and
required `pool.list()`, but nostr-tools 2.x removed SimplePool.list() (the rest of
the app only has it because js/nostr/toolkit.js shims it). So validation always
failed even though the payment went through.

Fix: resolveReceiptListPool() applies the app's legacy .list shim
(shimLegacySimplePoolMethods) to the freshly created pool, and the gate now
accepts a listEvents override instead of hard-requiring pool.list.

tests/zap-receipt-pool.test.mjs: 2.x pool gets .list shimmed; createPool override
shimmed; listEvents override leaves the pool as-is; null when neither available.
Mutation-verified (removing the shim fails it).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-21 22:11:46 -04:00
google-labs-jules[bot]andPR0M3TH3AN c47392aba6 Refactor numeric constants to centralized module
- Introduce `js/constants.js` with semantic time constants (e.g., `ONE_MINUTE_MS`, `STANDARD_TIMEOUT_MS`) and feature-specific TTLs.
- Export `KIND_MUTE_LIST` from `js/nostrEventSchemas.js` to standardize NIP-51 mute list kind usage.
- Refactor `js/state/cache.js`, `js/nostr/cachePolicies.js`, `js/channelProfile.js`, and various services to use centralized constants instead of hardcoded magic numbers.
- Update `js/nostr/relayConstants.js` to derive values from the shared time constants.
- Replace duplicate definitions of timeouts and retry delays across the codebase.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-11 03:27:26 +00:00
google-labs-jules[bot]andPR0M3TH3AN a084bb59de refactor: deduplicate HEX64_REGEX to js/utils/hex.js
Moves the repeatedly defined HEX64_REGEX constant to a shared utility
module to improve maintainability and consistency. Updates all consumers
to import from the new location.

Signed-off-by: Jules <[email protected]>

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-07 21:52:51 +00:00
google-labs-jules[bot] 4a0b81ad98 chore(ai): remove dead code (unused exports & deps) 2026-01-24 20:28:53 +00:00
thePR0M3TH3AN d082df8e41 Add DM zap composer and zap request support 2026-01-19 11:29:55 -05:00
google-labs-jules[bot] 270d55cc7c 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.
2026-01-07 13:39:52 +00:00
thePR0M3TH3AN 3996986e63 Remove nostr shim and retarget imports 2026-01-06 15:32:21 -05:00
thePR0M3TH3AN 931fa1398f Bundle crypto helpers for zap validator 2025-10-29 16:20:41 -04:00
thePR0M3TH3AN 0724307202 Add zap receipt validation for zap receipts 2025-10-29 15:48:54 -04:00
thePR0M3TH3AN c5460e38c9 Add lnurl param to invoice callback and update tests 2025-10-29 14:37:51 -04:00
thePR0M3TH3AN 0049528b46 Ensure zap requests carry bech32 LNURL tags 2025-10-29 14:18:27 -04:00
thePR0M3TH3AN c8a3bff57d Add relay metadata to zap requests 2025-10-29 14:06:02 -04:00
thePR0M3TH3AN 6f2e865a04 Align zap receipt success status 2025-10-29 09:05:13 -04:00
thePR0M3TH3AN 98ea36bd93 Add wallet budget enforcement for NWC payments 2025-10-29 06:52:30 -04:00
thePR0M3TH3AN 5d4baa3b56 Handle zap share payment failures gracefully 2025-10-27 21:52:23 -04:00
thePR0M3TH3AN cf66baa745 Merge pull request #983 from PR0M3TH3AN/codex/update-zap-error-handlers-for-wallet-allowance
Handle wallet zap allowance exhaustion messaging
2025-10-27 21:42:06 -04:00
thePR0M3TH3AN 8879c3a46d Handle zap allowance exhaustion 2025-10-27 21:41:44 -04:00
thePR0M3TH3AN 37bec3c5e2 Retry NWC requests with nip04 after nip44 timeouts 2025-10-27 21:34:57 -04:00
thePR0M3TH3AN 011d69482a Prefer nip04 encryption fallback for implicit wallets 2025-10-27 20:35:14 -04:00
thePR0M3TH3AN 18ffde2147 Include LNURL hint in NWC zap payments 2025-10-27 20:14:28 -04:00
thePR0M3TH3AN bfcef3c5d7 Remove spinner from login-required zap notification 2025-10-19 14:27:18 -04:00
thePR0M3TH3AN 0a876314c1 Adjust login-required zap notification behavior 2025-10-19 14:09:36 -04:00
thePR0M3TH3AN ead06ba8e0 Ensure zap login notification renders without pre-mounted portal 2025-10-19 13:11:50 -04:00
thePR0M3TH3AN f1032fac2b Ensure zap login notice always shows 2025-10-18 20:16:25 -04:00
thePR0M3TH3AN 72033a900b Fix zap login notification handling 2025-10-18 20:04:58 -04:00
thePR0M3TH3AN 841f1dd7f5 Ensure zap login prompts use notification status portal 2025-10-18 19:44:01 -04:00
thePR0M3TH3AN 0a2a2c4e78 Fix syntax errors blocking app bootstrap 2025-10-15 15:08:55 -04:00
thePR0M3TH3AN 7ae07b1369 refactor: migrate console usage to shared loggers 2025-10-15 14:37:25 -04:00
thePR0M3TH3AN d705cf176b Revert "Refactor logging to centralized logger" 2025-10-15 11:14:10 -04:00
thePR0M3TH3AN 37ba57aa37 Refactor logging to centralized logger 2025-10-15 11:11:14 -04:00
thePR0M3TH3AN f80ebef5c3 Defer nostr-tools access until bootstrap 2025-10-06 10:17:11 -04:00
thePR0M3TH3AN 1c805b053e Wait for nostr pool before platform lookup 2025-10-05 22:37:23 -04:00
thePR0M3TH3AN b773e1ec21 Fix zap fee parsing for split calculations 2025-10-05 22:03:07 -04:00
thePR0M3TH3AN c0ffde6462 Handle string zap platform fee inputs 2025-10-05 21:48:39 -04:00
thePR0M3TH3AN aa4e86758a Fix NWC encryption fallback handling 2025-10-05 20:49:56 -04:00
thePR0M3TH3AN e76107c8b2 Handle multi-relay NWC URIs 2025-10-05 19:49:22 -04:00
thePR0M3TH3AN 1e42b2af56 Convert NWC payment amounts to msats 2025-10-05 19:33:58 -04:00
thePR0M3TH3AN 1f0fb6ac87 Support NIP-47 encryption negotiation 2025-10-05 19:22:24 -04:00
thePR0M3TH3AN f2c7520a40 Handle NWC responses without e-tag IDs 2025-10-05 19:08:43 -04:00
thePR0M3TH3AN ad4f56a1d4 Ensure NostrTools nip04 helper persists 2025-10-05 08:44:23 -04:00
thePR0M3TH3AN 80438555f5 Improve zap failure diagnostics 2025-10-05 02:34:52 -04:00