feat(extensions): add split payments extension #16

Open
padreug wants to merge 1 commit from feature/splitpay into dev
Owner

Summary

Adds a split payments extension that automatically distributes a percentage of every incoming payment to one or more recipients. 518 lines of TypeScript.

Closes #13

Architecture

Dual-layer split design (see #13 comment):

  • Layer 1 (preferred): NIP-57 zap tags — Nostr-aware wallets split at the sender side, each recipient gets a direct zap. Extension does nothing.
  • Layer 2 (fallback): onPaymentReceived() catches non-Nostr payments (BOLT11, LNURL, CLINK) and splits internally.
  • Recursion guard: metadata.splitted = true prevents the two layers from double-splitting.

RPC Methods

Method Auth Description
splitpay.setTargets User Configure split recipients and percentages (replaces all)
splitpay.getTargets Public List current split configuration
splitpay.clearTargets User Remove all targets
splitpay.getHistory Public View split payment audit trail (paginated)

Data Model

split_targets: recipient (pubkey/LNURL/Lightning Address), percent (0-100), alias, creator_pubkey

split_records: audit trail of every split — source payment hash, target, amount, outgoing payment hash, status (pending/success/failed), error

Validation

  • Total percentages must not exceed 100%
  • Each target must have a recipient and percent > 0
  • Atomic target replacement (delete all + insert all in transaction)

Files

src/extensions/splitpay/
├── index.ts                        # Extension entry, RPC registration
├── types.ts                        # Data types and request/response interfaces
├── migrations.ts                   # 2 migrations (targets + records tables)
└── managers/
    └── splitPayManager.ts          # Core logic: target CRUD + payment splitting

Test plan

  • TypeScript compiles
  • Set targets via RPC, verify stored
  • Receive payment → verify splits created and paid
  • Receive payment with splitted: true metadata → verify no re-split
  • Set targets exceeding 100% → verify rejection
  • Clear targets → verify no splits on next payment
  • Check history returns paginated records
## Summary Adds a split payments extension that automatically distributes a percentage of every incoming payment to one or more recipients. 518 lines of TypeScript. Closes #13 ## Architecture **Dual-layer split design** (see [#13 comment](https://git.atitlan.io/aiolabs/lightning-pub/issues/13#issuecomment-197)): - **Layer 1 (preferred)**: NIP-57 `zap` tags — Nostr-aware wallets split at the sender side, each recipient gets a direct zap. Extension does nothing. - **Layer 2 (fallback)**: `onPaymentReceived()` catches non-Nostr payments (BOLT11, LNURL, CLINK) and splits internally. - **Recursion guard**: `metadata.splitted = true` prevents the two layers from double-splitting. ## RPC Methods | Method | Auth | Description | |--------|------|-------------| | `splitpay.setTargets` | User | Configure split recipients and percentages (replaces all) | | `splitpay.getTargets` | Public | List current split configuration | | `splitpay.clearTargets` | User | Remove all targets | | `splitpay.getHistory` | Public | View split payment audit trail (paginated) | ## Data Model **split_targets**: recipient (pubkey/LNURL/Lightning Address), percent (0-100), alias, creator_pubkey **split_records**: audit trail of every split — source payment hash, target, amount, outgoing payment hash, status (pending/success/failed), error ## Validation - Total percentages must not exceed 100% - Each target must have a recipient and percent > 0 - Atomic target replacement (delete all + insert all in transaction) ## Files ``` src/extensions/splitpay/ ├── index.ts # Extension entry, RPC registration ├── types.ts # Data types and request/response interfaces ├── migrations.ts # 2 migrations (targets + records tables) └── managers/ └── splitPayManager.ts # Core logic: target CRUD + payment splitting ``` ## Test plan - [ ] TypeScript compiles - [ ] Set targets via RPC, verify stored - [ ] Receive payment → verify splits created and paid - [ ] Receive payment with `splitted: true` metadata → verify no re-split - [ ] Set targets exceeding 100% → verify rejection - [ ] Clear targets → verify no splits on next payment - [ ] Check history returns paginated records
padreug added 1 commit 2026-04-02 19:21:25 +00:00
feat(extensions): add split payments extension
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
aa58f88670
Automatically distributes a percentage of every incoming payment to
one or more recipients. Supports Nostr pubkeys, LNURL, and Lightning
Addresses as targets.

Dual-layer architecture:
- NIP-57 zap tags (preferred): Nostr wallets split at sender side
- Internal splits (fallback): onPaymentReceived for non-Nostr payments
- Recursion guard (metadata.splitted) prevents double-splitting

RPC methods:
- splitpay.setTargets: configure split recipients and percentages
- splitpay.getTargets: list current configuration
- splitpay.clearTargets: remove all targets
- splitpay.getHistory: view split payment audit trail

Closes #13

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Some checks failed
Docker Compose Actions Workflow / test (push) Has been cancelled
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/splitpay:feature/splitpay
git checkout feature/splitpay

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git checkout dev
git merge --no-ff feature/splitpay
git checkout feature/splitpay
git rebase dev
git checkout dev
git merge --ff-only feature/splitpay
git checkout feature/splitpay
git rebase dev
git checkout dev
git merge --no-ff feature/splitpay
git checkout dev
git merge --squash feature/splitpay
git checkout dev
git merge --ff-only feature/splitpay
git checkout dev
git merge feature/splitpay
git push origin dev
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: aiolabs/lightning-pub#16
No description provided.