Commit Graph

208 Commits

Author SHA1 Message Date
callebtc
cf4cbbe882 Mint: migration to clean up overly large witnesses (#817)
* add migration to clean up overly large witnesses

* bump to 0.18.1
2025-11-04 19:39:16 +01:00
lollerfirst
4a4b7f79f7 fix: unique ('PENDING', checking_ID) for melt quotes (#800)
* fix: only one melt_quote with shared checking_id is allowed to be in a pending state.

fix mypy

add comprehensive tests

remove SQL unique index

remove test db constraint

fix lock statement

remove `test_regtest_pay_mpp_incomplete_payment`

format

* remove `test_set_melt_quote_pending_with_outputs`

* client self-rug mitigation

* fix

* format

* DB level check: error if payment reference paid or pending

* fix test

* comments

* restore

* restore

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-10-28 11:47:23 +01:00
callebtc
184f8ba6ca Revert "extend and refactor nut11 sig_all message aggregation (#804)" (#810)
This reverts commit 7000e5c7ee.
2025-10-28 11:42:21 +01:00
callebtc
7000e5c7ee extend and refactor nut11 sig_all message aggregation (#804) 2025-10-28 11:41:44 +01:00
lollerfirst
f84028ca3f refactor: HTLC spending conditions (#803)
* refactor nut14

* format

* tests

* update tests

* more tests

* format

* adjust wallet tests -> 32 bytes preimages

* format
2025-10-21 16:37:51 +02:00
callebtc
9fed0f0f07 Fix duplicate blank outputs during melt (#795)
* wip blank outputs

* wip: working

* store ids for promises correctly

* tests

* fix migraiton

* revert

* fix tests

* fix auth server

* fix last tests

* retroactively change migration, initial and m017_foreign_keys_proof_tables, remove c_b and replace with c_ (same for b_)

* fix constraint

* oops

* msg stack fix

* fix test foreign key constraint

* fix postgres tests

* foreign key constraint test

* should fix psql error

* foreign key constraint sqlite

* rename to update_blinded_message_signature

* drop outputs and change columns from melt_quotes table

* switch migration order

* reorder migrations again

* fix migration

* add tests

* fix postgres migration too

* create signed_at column postgres

* foreign key constraingt promises table

* migration tool

* readme
2025-10-19 15:50:47 +02:00
callebtc
15ec97b9f7 add description to NUT-04 method options (#783)
* add description to NUT-04 method options

* add option
2025-09-09 22:30:42 +02:00
lollerfirst
3b4f5b56a0 fix: subscription re-init bug (#781)
* fix subscription re-initialization bug

* test for regression issue

* format

* Update cashu/mint/events/client.py

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-09-08 18:20:21 +02:00
lollerfirst
29571287b3 Mint Management gRPC Server (#723)
* settings

* fix name settings

* management rpc

* hook up the RPC server

* working

* format

* update build script fix import error

* remove accidental commit of vscode extension data

* working ✔

* \n

* add get mint quote get melt quote

* gRPC cli update quotes commands

* update mint melt quotes from cli

* comment under get cli command group

* keyset rotation not yet implemented

* try fix

* change back contact info default to be empty list

* fix import

* add server mTLS

* ll

* script for generating certificates

* rename settings

* move generation script

* do not save TTL expiry into Cache object, rather always load from settings.

* update lightning fees

* update auth limits

* auth rate limit cli

* optional arguemnts

* better error messages

* tests for db update mint/melt quotes

* start mint rpc tests

* add tos_url field to get-info grpc response

* format checks

* add types to click groups where it's needed

* tests on updating quotes

* fix tests

* skip updating mint quote state if on regtest

* test edge case

* unified test_add_remove_contact

* mark pytest-asyncio

* fix missing db argument

* hopefully no more silly errors

* fix test_db_update_mint_quote_state

* pass in the quote id string.

* add keyset rotation

* test for keyset rotation through gRPC command

* fix logger warning

* remove rotation test because it breaks other tests

* use different bolt11 invoices

* assert returned melt quote has quote

* is_postgres

* try different things

* skip if deprecated api

* format checks

* update .gitignore

* default location for certificates
2025-06-25 12:35:53 +02:00
Olindo Task
bbfb63b34e Add verbose request logging feature to wallet (#758)
* Add verbose request logging feature to wallet

* add verbose cli tests

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-06-24 22:31:40 +02:00
callebtc
fc0e3fe663 Mint: watchdog balance log and killswitch (#705)
* wip store balance

* store balances in watchdog worker

* move mint_auth_database setting

* auth db

* balances returned as Amount (instead of int)

* add test for balance change on invoice receive

* fix 1 test

* cancel tasks on shutdown

* watchdog can now abort

* remove wallet api server

* fix lndgrpc

* fix lnbits balance

* disable watchdog

* balance lnbits msat

* test db watcher with its own database connection

* init superclass only once

* wip: log balance in keysets table

* check max balance using new keyset balance

* fix test

* fix another test

* store fees in keysets

* format

* cleanup

* shorter

* add keyset migration to auth server

* fix fakewallet

* fix db tests

* fix postgres problems during migration 26 (mint)

* fix cln

* ledger

* working with pending

* super fast watchdog, errors

* test new pipeline

* delete walletapi

* delete unneeded files

* revert workflows
2025-05-11 20:29:13 +02:00
callebtc
38bdb9ce76 Tests: split wallet test from mint test pipeline (#748)
* split wallet test from mint test pipeline

* regtest mint and wallet

* fix

* fix

* move mint tests

* real invoice in regtest mpp
2025-05-11 14:14:49 +02:00
lollerfirst
619d06f0ab [PATCH] LND use_mission_control + exclude failing channels (#738)
* lnd_grpc multinut patch

* lndrest multinut patch

* mypy fixes

* fixes non escaped double quotes in error messages formats

* fix

* fix debug log with correct hops number

* correctly escape "hops"

* remove `ignored_pairs` constraint

* Apply suggestions from code review

change some error logs to debug

* add tests and some cleanup

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-05-10 15:45:15 +02:00
callebtc
2135b96706 Testing: check if pipeline gets stuck because of startup task (#745)
* lets check if this gets stuck with postgres or not

* check if it works if I add sleeps

* replace startup_ledger with await ledger._check_pending_proofs_and_melt_quotes() in tests

* fix typo to trigger tests again
2025-05-10 15:04:56 +02:00
callebtc
4869a280ca add new init test to mint (#743) 2025-05-09 22:06:27 +02:00
callebtc
dc1dccb5e8 Wallet: Fix cli mpp off (#741)
* fix

* tests
2025-05-08 18:01:11 +02:00
callebtc
7f962ce63e Wallet: add Wallet.get_melt_proof(), recover reserved state in failed Wallet.melt() (#730)
* manage state of proofs

* test set proofs unreserved

* melt recovers state on error

* fix wallet test

* fix tests

* fix another test

* get_mint_quote returns MintQuote

* fix tests

* refactor

* fix deprecated tests

* add new unset type
2025-04-25 13:12:45 +02:00
lollerfirst
213d5b1eee Mint Keyset Rotation (#734)
* move keysets methods into newly created `LedgerKeysets` + `maybe_update_derivation_path` on init

* keyset rotation

* fix error

* make format

* format

* test keyset rotation + fix bug

* format

* fix for multiple specified derivation paths

* specify return value
2025-04-25 11:37:49 +02:00
callebtc
7abfc68cfa SIG_ALL signature flag for P2PK (#735)
* n_sigs_refund working, tests added

* update requirements

* wip sigall

* wip

* sigall works

* add signatures for refund

* add mint p2pk tests

* add more p2pk tests

* fix tests

* sign htlc pubkeys as well

* fix htlc and add new test

* fix regtest

* fix new tests with deprecated

* remove asserts

* comments

* new wallet p2pk tests

* getting there

* add more tests

* fixes

* refactor htlc and p2pk validation

* reduce code

* melt with sigall

* fix htlcs

* fix deprecated api tests

* Update cashu/mint/conditions.py

Co-authored-by: lollerfirst <43107113+lollerfirst@users.noreply.github.com>

* refactor sigall validation

---------

Co-authored-by: lollerfirst <43107113+lollerfirst@users.noreply.github.com>
2025-04-25 11:37:19 +02:00
callebtc
e1220d2329 Cjbeery24/mint copy: Invoice checker background tasks (#722)
* #616: Removed blocking call from ledger startup. Instead added it to a background task that repeats every hour.

* make task interval configurable, remember task and cancel it on shutdown

* comments

* add sleep to tests because the background task is async

---------

Co-authored-by: Caleb Beery <cjbeery@gmail.com>
2025-04-10 21:25:18 +07:00
callebtc
bae4855915 NUT-04/05: add amount, unit, request to melt and mint quote responses (#719)
* add amount, unit, request to melt and mint responses

* make new fields optional to not break compat with old mints

* make new flags optional for backwards compat
2025-03-08 18:23:34 +00:00
Houdini
7b3f5d01d0 Allow arbitrary denominations in wallet minting (#684)
- Update `mint` method to use allowed amounts from the mint
- Add `get_allowed_amounts` method to fetch supported denominations
- Modify `test_mint_amounts_wrong_order` to expect new error message

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-03-06 20:15:14 +01:00
callebtc
9305905a85 Add LightningPaymentFailedError exception (#706)
* add error code

* fix test
2025-03-06 00:04:37 +01:00
lollerfirst
f72a3f260f [FIX] NUT-15 mpp amount in millisats (#703)
* fix lndrest

* fix clnrest

* fix clnrest and lndrest

* lnd grpc fix

* wallet

* convert amount to millisats in CLI pay invoice

* fix tests

* format

* fix kw arg in regtest test

* fix payment quote validation check

* clean comment

* avoid overwriting variable

* deprecated response with amount

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-03-05 23:47:03 +01:00
lollerfirst
0c40bbbc08 Balance Views Grouped By Keyset (#652)
* balance view per keyset + relative changes.
    Still lacking: settings changes

* import unit

* fix 0 balance

* settings

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-02-17 12:55:28 +01:00
callebtc
23a706d873 Set correct blink min fee (#701)
* min fee

* fix tests

* amount_split test
2025-02-13 15:53:26 +01:00
lollerfirst
ec3db81cee Update Error Codes (#702)
* add new error codes

* use the new errors in the code

* fix unsorted import

* fix test wallet
2025-02-13 15:35:06 +01:00
callebtc
a0ef44dba0 Blind authentication (#675)
* auth server

* cleaning up

* auth ledger class

* class variables -> instance variables

* annotations

* add models and api route

* custom amount and api prefix

* add auth db

* blind auth token working

* jwt working

* clean up

* JWT works

* using openid connect server

* use oauth server with password flow

* new realm

* add keycloak docker

* hopefully not garbage

* auth works

* auth kinda working

* fix cli

* auth works for send and receive

* pass auth_db to Wallet

* auth in info

* refactor

* fix supported

* cache mint info

* fix settings and endpoints

* add description to .env.example

* track changes for openid connect client

* store mint in db

* store credentials

* clean up v1_api.py

* load mint info into auth wallet

* fix first login

* authenticate if refresh token fails

* clear auth also middleware

* use regex

* add cli command

* pw works

* persist keyset amounts

* add errors.py

* do not start auth server if disabled in config

* upadte poetry

* disvoery url

* fix test

* support device code flow

* adopt latest spec changes

* fix code flow

* mint max bat dynamic

* mypy ignore

* fix test

* do not serialize amount in authproof

* all auth flows working

* fix tests

* submodule

* refactor

* test

* dont sleep

* test

* add wallet auth tests

* test differently

* test only keycloak for now

* fix creds

* daemon

* fix test

* install everything

* install jinja

* delete wallet for every test

* auth: use global rate limiter

* test auth rate limit

* keycloak hostname

* move keycloak test data

* reactivate all tests

* add readme

* load proofs

* remove unused code

* remove unused code

* implement change suggestions by ok300

* add error codes

* test errors
2025-01-29 22:48:51 -06:00
lollerfirst
e9952e59ed [FIX] Reject Internal MPP Melt Quote Requests (#697)
* fix

* fix the fix

* make sure the mpp is supported before testing

* adjust message

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2025-01-29 14:00:35 -06:00
callebtc
ad7c6b8e0b Issue NUT-08 overpaid Lightning fees for melt quote checks on startup (#688)
* startup: do not rollback unknown melt quote states

* fix: provide overpaid fees on startup

* fix: check if outputs in db

* fix test: expect melt quote pending if payment state is unknown

* fix up comment
2025-01-21 17:28:41 -06:00
lollerfirst
d98d166df1 Support NUT-XX (signatures on quotes) for mint and wallet side (#670)
* nut-19 sign mint quote

* ephemeral key for quote

* `mint` adjustments + crypto/nut19.py

* wip: mint side working

* fix import

* post-merge fixups

* more fixes

* make format

* move nut19 to nuts directory

* `key` -> `privkey` and `pubkey`

* make format

* mint_info method for nut-19 support

* fix tests imports

* fix signature missing positional argument + fix db migration format not correctly escaped + pass in NUT-19 keypair to `request_mint` `request_mint_with_callback`

* make format

* fix `get_invoice_status`

* rename to xx

* nutxx -> nut20

* mypy

* remove `mint_quote_signature_required` as per spec

* wip edits

* clean up

* fix tests

* fix deprecated api tests

* fix redis tests

* fix cache tests

* fix regtest mint external

* fix mint regtest

* add test without signature

* test pubkeys in quotes

* wip

* add compat

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-12-15 00:39:53 +01:00
lollerfirst
399c201552 NUT-19: Cached Requests and Responses (#624)
* fast-api-cache setup

* testing the cache

* fix

* still not working

* asynccontextmanager

* move test

* use redis & custom caching setup (like CDK)

* make format

* poetry lock

* fix format string + log when a cached response is found

* log when a cahced response is found

* fix tests

* poetry lock

* try tests on github

* use docker compose

* maybe we dont need docker

* fix types

* create_task instead of run

* how about we start postgres

* mint features

* format

* remove deprecated setex call

* use global expiry for all cached routes

* refactor feature map and set default to 1 week

* refactor feature construction

* Cache NUT-19

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-12-03 16:03:01 +03:00
lollerfirst
ed0d25dec7 [FIX] Wallet sort outputs before swapping (#648)
* sort proofs

* outputs-ordering

* mypy fix

* clean up

* test if output amounts are sorted

* clean up test

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-11-05 15:00:37 +01:00
callebtc
80ff0f1a7c Fix db lock tests (#665)
* skip db lock check in regtests

* revert?

* try this

* do not dispose conftests

* remove return

* test this

* try auto

* dispose stuff

* try uri=true

* remove the other flag

* move test

* reduce tests

* reduce more

* keep one

* skip on github?

* only skip in regtest

* trigger again

* restore cashu/mint/ledger.py
2024-11-05 13:47:31 +01:00
callebtc
05547e3710 Mint: Turn off locking by default (#662)
* turn off locking by default

* fix test
2024-11-04 10:52:33 +01:00
callebtc
e9d4689b4b Chore: update dev dependencies (#658)
* update dev dependencies

* test

* revert tests

* fix event loop scope

* ruff format

* add old test

* remove custom event loop

* default loop scope

* skip earlier

* trigger

* trigger again
2024-11-01 15:07:56 +01:00
callebtc
92627399a5 Wallet: store quotes (#657)
* wallet_quotes_wip

* fix quote in db

* fix subscription test

* clean up api

* fix api tests

* fix balance check
2024-11-01 13:27:27 +01:00
Damian
b8dd43deaa Mint: settle mint-melt on same mint with different units externally (#651)
* WIP settle different units externally

* mint melt externally different units

* deprecated route return only sat

* comment

---------

Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
2024-10-30 21:59:57 +01:00
callebtc
09d007ec88 Refactor conditions and fix HTLC multisig (#643)
* refactor conditions and fix htlc multisig

* restore db/write.py

* safer check for P2PK secrets for SIG_ALL

* comment cleanup
2024-10-22 14:02:45 +02:00
conduition
d12a8d1bde wait for uvicorn server to bind before running tests (#607)
* wait for uvicorn server to bind before running tests

Previously we had a simple `time.sleep(1)` call after `server.start()`
which was present to give the Mint's HTTP server time to spin up during
test runs. This meant that if the server took longer than 1s to start
on a dev's machine for any reason (even intermittently) then tests would
fail due to connection errors.

The fix is to use a simple repeated polling check which allows
the test runner to start only once the server is confirmed listening.

* fix linter errors

* prevent infinite loop

* specifically except httpx.ConnectError

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
2024-10-20 01:01:32 +02:00
callebtc
4490cc6fce Add get quote API to wallet + check proof states in batches (#637)
* add get quote api to wallet

* wrong string

* test before pushing

* fix tests for deprecated api only

* sigh
2024-10-08 18:12:10 +02:00
callebtc
307d2d7a98 Halt melt on exception (#635)
* halt melt for payment status exception

* refactor

* less log

* add fakewallet test throwing exceptions
2024-10-06 17:51:54 +02:00
Pavol Rusnak
75ffa39807 chore: modernize f-string usage (#627) 2024-10-04 14:11:00 +02:00
callebtc
b92999cb21 tests: add tests for event client manager (#632) 2024-10-04 13:11:23 +02:00
callebtc
700320a8c4 Fix: wallet include fees in swap outputs for inputs of successive melt (#630)
* wallet: add fees to outputs for melt that requires a split

* add test that requires a swap

* verify test fails, will revert

* revert true

* hopefully fix the tests

* fix default fee selection

* cleanup and renamings

* cleanup coinselect function, estimate fees

* fix test

* add comments

* weird error
2024-10-03 09:50:23 +02:00
callebtc
d8d3037cc5 WIP: New melt flow (#622)
* `PaymentResult`

* ledger: rely on PaymentResult instead of paid flag. Double check for payments marked pending.

* `None` is `PENDING`

* make format

* reflected changes API tests where `PaymentStatus` is used + reflected changes in lnbits

* reflect changes in blink backend and tests

* fix lnbits get_payment_status

* remove paid flag

* fix mypy

* remove more paid flags

* fix strike mypy

* green

* shorten all state checks

* fix

* fix some tests

* gimme 

* fix............

* fix lnbits

* fix error

* lightning refactor

* add more regtest tests

* add tests for pending state and failure

* shorten checks

* use match case for startup check - and remember modified checking_id from pay_invoice

* fix strike pending return

* new tests?

* refactor startup routine into get_melt_quote

* test with purge

* refactor blink

* cleanup responses

* blink: return checking_id on failure

* fix lndgrpc try except

* add more testing for melt branches

* speed things up a bit

* remove comments

* remove comments

* block pending melt quotes

* remove comments

---------

Co-authored-by: lollerfirst <lollerfirst@gmail.com>
2024-09-24 14:55:35 +02:00
Pavol Rusnak
870d75b205 feat: untangle MintMeltMethodSetting into MintMethodSetting and MeltMethodSetting (#617)
+ add description to MintMethodSetting
2024-09-22 15:57:17 +02:00
callebtc
637e4ba80c NUT-04: add description (#613)
* NUT-04: add description

* skip test for deprecated api

* fix for lndgrpc

* add test for cli

* add two random tests

* add max length to request model validator

* skip cli test with description for deprecated api

* add cli test for invoice command

* default value to None
2024-09-09 11:50:02 +02:00
callebtc
0287c02f97 sanitize mint URL before adding (#606) 2024-09-08 15:59:10 +02:00
lollerfirst
77ba356499 CLN multinut test fix (#602) 2024-07-30 16:30:01 +02:00