mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-07 05:13:01 +00:00
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]>
This commit is contained in:
1 parent
b52a1b3fea
commit
df99bdb65f
4 files changed
+147
-7
No files matched your search
+14
-2
@@ -540,8 +540,8 @@ export async function splitAndZap(
|
||||
}
|
||||
|
||||
const platformFee = clampPercent(getOverridePlatformFee());
|
||||
const platformShare = Math.floor((amount * platformFee) / 100);
|
||||
const creatorShare = amount - platformShare;
|
||||
let platformShare = Math.floor((amount * platformFee) / 100);
|
||||
let creatorShare = amount - platformShare;
|
||||
|
||||
let platformAddress = null;
|
||||
if (platformShare > 0) {
|
||||
@@ -551,6 +551,18 @@ export async function splitAndZap(
|
||||
if (!platformAddress) {
|
||||
throw new Error("Platform Lightning address is unavailable.");
|
||||
}
|
||||
|
||||
// When the platform fee would be paid to the very same Lightning address as
|
||||
// the creator (e.g. the creator is the platform operator), splitting just
|
||||
// sends two invoices to one wallet — extra routing fees and a confusing
|
||||
// duplicate receipt for the same total. Collapse to a single full-amount
|
||||
// payment to the creator; the recipient is unchanged and ends up with the
|
||||
// same sats.
|
||||
if (platformAddress.toLowerCase() === creatorAddress.toLowerCase()) {
|
||||
creatorShare = amount;
|
||||
platformShare = 0;
|
||||
platformAddress = null;
|
||||
}
|
||||
}
|
||||
|
||||
const receipts = [];
|
||||
|
||||
Reference in new issue
Block a user