Repository navigation
feat: support LUD-24 pinLimit for NFC card payments - #260
Open
AxelHamburch wants to merge 1 commit into
Open
AxelHamburch wants to merge 1 commit into
AxelHamburch wants to merge 1 commit into
Conversation
When a withdrawRequest carries pinLimit and the invoice amount reaches it, TPoS asks for a 4-digit PIN instead of calling the callback without one. The single-use card link is not re-fetched: callback/k1 are kept server side in a short-lived pending entry referenced by a token. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TPoS can now pay with NFC cards whose LNURL-withdraw service requires a PIN
for larger amounts (LUD-24, optional
pinLimitfield in thewithdrawRequest).Before this change, TPoS always called the withdraw callback with only
k1andpr. For a card with a PIN limit, the service answeredPIN required.and thecustomer could not pay. With this PR the customer is asked for the PIN on the
TPoS screen.
Services that do not send
pinLimit(and amounts below the limit) behaveexactly as before.
Background
pinLimit(in msat) to the LUD-03withdrawRequest.If the invoice amount is
>= pinLimit, the wallet/terminal must collect a4-digit PIN and send it as
pin=in the callback. Without it the servicerejects the request.
otherwise be spent without the owner knowing.
lnbits/boltcards#67 and
lnbits/boltcards#68.
not support it simply cannot complete such a payment, which is intended by
the spec.
How it works
withdrawRequest(server side, as before).pinLimitis present, TPoS decodes the invoice (including tip) andcompares its amount with
pinLimit.pin_requiredand a one-timepin_tokento the frontend.k1,prandpin.Invalid PIN): dialog stays open, showsWrong PIN (2 attempts left), then(1 attempt left).Card blocked: too many incorrect PIN attemptsor any other error:dialog closes and the error is shown, as for other NFC errors.
payment websocket/checker.
Why a server side pending entry?
The card link is single use (the SUN counter is consumed by the first GET), so
the
withdrawRequestcannot be fetched again after the PIN was entered.TPoS therefore keeps
callback,k1and the invoice for up to 2 minutes inmemory, referenced by a random token. The client never sends a callback URL,
so it cannot be used to make the server call arbitrary URLs (no SSRF). A wrong
PIN refreshes the 2 minute window, the entry is removed on success, on any
other error and when it expires. The store is limited to 100 entries.
The Boltcards service keeps the hit valid after a wrong PIN, so retrying the
callback with the same
k1works. The "3 wrong PINs" limit is enforced by theservice. TPoS only displays the attempts left for the dialog that is currently
open and cannot know the card's total count.
Changes
views_payments.pyapi_tpos_pay_invoice: readspinLimit, decodes the invoice withbolt11and returnspin_required+pin_tokenwhen needed.Callback logic moved into small helpers
(
_call_withdraw_callback,_callback_result).POST /api/v1/tposs/{tpos_id}/invoices/pay-pin.pinLimitrequest with a non-HTTPS callback is rejected(LUD-24 requires HTTPS).
models.py:PayLnurlWPin(pin_token,pinvalidated as exactly 4 digits).static/components/pin-dialog.js: newtpos-pin-dialogcomponent(masked input, touch friendly keypad, amount shown on the same screen as
required by LUD-24).
static/js/tpos.js,templates/tpos/dialogs.html,templates/tpos/tpos.html:PIN dialog state and wiring; the NFC error notification was extracted into
notifyNfcErrorand reused.No database migration, no new dependency (
bolt11ships with LNbits).ATM mode is not affected (it uses
payLink).Testing
Try it yourself
A public test server with the full functionality (Boltcards PRs #67 and #68
plus this PR in TPoS) is available at https://21mio.space/:
invitation code
pinLimit.and tap the card.
Manual test
Manually tested on a production-like LNbits server with the Boltcards
extension (PRs #67 / #68) and a Bolt Card with a PIN limit:
pinLimit: payment works without PIN, as before.pinLimit: PIN dialog appears, correct PIN pays.pinLimit/ other LNURL-withdraw services: unchanged.Automated:
tests/test_api.py: below the limit (no PIN sent), PIN flow with retry andsuccess, single-use token, blocked card, input validation (non 4-digit PIN,
unknown token).
node tests/check_static_load.jspasses.Screenshots
TPoS (this PR) and the Boltcards extension (PIN settings, blocked card):
1. Invoice, waiting for the card
2. Amount ≥ pinLimit: PIN dialog
3. Correct PIN: invoice paid
4. Wrong PIN: 2 attempts left
5. Wrong PIN: 1 attempt left
6. Third wrong PIN: card blocked
7. Next tap: card is disabled
Boltcards: PIN limit and PIN
Boltcards: blocked card (disabled)
Boltcards: re-enable the card
Notes for reviewers
multiple workers, the PIN request could land on a different worker and the
user would be asked to tap the card again (
pin_expired). Persisting it inthe DB is possible if you prefer that.
verification and blocking stay entirely with the service.