161 Commits

Author SHA1 Message Date
C
4e0132875f fix: add proof recovery mechanism for failed wallet operations (#1250)
* fix: add proof recovery mechanism for failed wallet operations

This commit introduces a new `try_proof_operation` helper that wraps wallet
operations (swap, melt) with automatic proof recovery in case of network or
mint failures. When an operation fails, the wallet now attempts to recover by
marking proofs as unspent and swapping them to prevent loss of funds.

Fixes #1180
2025-11-04 20:40:31 -05:00
tsk
d9e001bee6 refactor(cdk): implement saga pattern for melt operations (#1186)
Restructure melt flow into a multi-step saga with compensation-based rollback.
Remove ProofWriter in favor of explicit compensation actions for improved
reliability and clarity in handling partial failures during melt operations.

Breaks down monolithic change processing logic into smaller, focused methods:
- process_change_outputs: orchestrates full change workflow
- validate_change_outputs: checks for already-signed messages
- calculate_change_fee_and_amounts: fetches keyset configuration
- split_change_amount: splits change into denominations
- prepare_blinded_messages_with_amounts: pairs amounts with blinded messages
- store_change_signatures: handles TX2 database operations
2025-11-03 11:40:21 -05:00
David Caseria
344b81a694 Update FFI Database Objects to Records (#1149) 2025-10-24 13:24:06 -04:00
tsk
69650c2ef9 feat: swap tests (#1187) 2025-10-12 23:16:52 +01:00
C
cdd59359b9 Introduce a generic pubsub mod in cdk-common (#1098)
* pubsub: consolidate into Spec, adopt Arc<SubscriptionId>, and wire through  wallet/mint/WS/FFI

Refactor the pub/sub engine to a single Spec trait, move Event alongside it,
and propagate Arc-backed subscription IDs across the stack. This simplifies
generics, clarifies responsibilities, and preserves coalescing +
latest-on-subscribe semantics.

-   **Single source of truth:** `Spec` owns `Topic`, `Event`, `SubscriptionId`,
    `Context`, new_instance, and fetch_events.
-   **Lean & explicit API:** Remove Topic trait split;
    `Subscriber::send(Event)` carries sub-ID internally.
-   **Performance/ergonomics:** `Arc<SubscriptionId>` avoids heavy clones and
    makes channel/task hops trivial.

-   Introduce `pub_sub/typ.rs` with:
    -   trait `Spec`
    -   trait `Event` colocated with Spec.
-   Remove `pub_sub/event.rs` fold `Event` into `typ.rs`.
-   Make `Pubsub<S>` generic over `Spec` and store `Arc<S>`.
-   The subscriber holds `Arc<SubscriptionId>` and deduplicates the latest
    entry per subscription.
-   SubscriptionRequest: rename SubscriptionName → SubscriptionId; return
    `Arc<...>` from `subscription_name()`.
-   Remote consumer (Transport) now parameterized by `Spec`; control types
    updated:
    -   `StreamCtrl<S>`, `SubscribeMessage<S>`, internal caches keyed by
        `S::Topic`.
-   Mint/wallet:
    -   Mint: `MintPubSubSpec` (Context = `DynMintDatabase`),
        `PubSubManager(Pubsub<MintPubSubSpec>)`.
    -   Wallet: lightweight MintSubTopics Spec with `Context = ()`.
-   IDs go Arc end-to-end:
    -   cdk-axum WS maps `HashMap<Arc<SubId>, JoinHandle<()>>`, publisher sends
        `(Arc<SubId>, NotificationPayload)`.
    -   `subscription::{Params, WalletParams}` now use `Arc<...>`.
    -   cdk-ffi conversions & wallet glue updated.
    -   Integration tests updated for new types.

-   Coalescing unchanged: multiple local subs to the same topic are combined
    into a single remote sub.
-   Backfill via `Spec::fetch_events(topics, Subscriber)`; Subscriber enforces
    latest-only dedupe per subscription.

**Result:** a slimmer, more maintainable pub/sub core that’s easier to embed
across mint, wallet, transports, and FFI without sacrificing performance or
semantics.


---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-10-08 09:33:45 +01:00
benthecarman
144f1da6c5 Allow passing metadata to a melt (#1148) 2025-10-02 10:11:08 +01:00
asmo
cb2e534f81 feat: added postgres to ffi (#1117)
* feat: added postgres to ffi
2025-09-30 14:14:28 +01:00
lollerfirst
6d0003a4fc token: add spending-condition inspection helpers and token_secrets() (#1124)
* token: add Token::token_secrets() and spending-condition helpers

- New helpers on Token that do not require mint keysets:
  - spending_conditions()
  - p2pk_pubkeys()
  - p2pk_refund_pubkeys()
  - htlc_hashes()
  - locktimes()
- Introduce token_secrets() to unify V3/V4 proof traversal and avoid duplication
- Bypass short->long keyset-id mapping since only Secret is needed for conditions
- Use &Secret for TryFrom to fix compile error
2025-09-26 20:56:01 +01:00
thesimplekid
e07a9c8e1e feat(cdk): add WebSocket authentication support (#1116)
* feat(cdk): add WebSocket authentication support with comprehensive configuration

- Add WebSocket auth token injection for client connections
- Implement server-side WebSocket authentication verification
- Add configuration options for per-endpoint WebSocket auth types
- Include comprehensive documentation and example configuration
- Support clear, blind, and no-auth modes for WebSocket endpoin
2025-09-25 08:31:57 +01:00
C
0f0b78c0b0 Include supported amounts instead of assuming the power of 2 (#1055)
* Include supported amounts instead of assuming the power of 2

The mint's signatory defines the amounts and the wallet, and the mint, when
paying, should use them instead of assuming the supported amounts are
2^(0..32), which is not part of the spec.

* Introduce FeeAndAmount struct
2025-09-24 13:02:24 +01:00
thesimplekid
df2f9d1c2a Psgl auth db (#1095)
* feat(cdk-mintd): add dedicated auth database configuration support
2025-09-21 16:56:12 +01:00
thesimplekid
aeafab9a10 fix: config overwrite on start up (#1081)
* fix: config overwrite on start up
2025-09-20 16:49:37 +01:00
David Caseria
12164a0764 Fix Async FFI Constructors (#1085)
* Fix unused async in FFI

* Fix FFI async constructor

* Fix FFI MultiMintWallet async constructor
2025-09-18 20:42:00 +01:00
thesimplekid
5ee405de89 Store last pay index (#1077) 2025-09-16 14:08:43 +01:00
C
c3c8e87164 Add resolve_dns_txt to HttpTransport and MintConnector (#1068)
* Add `resolve_dns_txt` to HttpTransport and MintConnector

Fixes #1036

* Use `hickory_resolver` to resolve DNS entries

* Remote default implementation of methods

* Fix build for wasm
2025-09-16 09:01:34 +01:00
gudnuf
2c9333449a fix: replace std::time with instant for wasm (#1060) 2025-09-13 11:12:41 +01:00
thesimplekid
64a4fe5bca feat: remove unused ln_routers (#1059)
* feat: remove unused ln_routers

* feat: allow other routers to be nested
2025-09-10 09:54:00 +01:00
asmo
75a3e6d2c7 Prometheus crate (#883)
* feat: introduce `cdk-prometheus` crate with Prometheus server and CDK-specific metrics support
2025-09-09 13:26:03 +01:00
C
b5b8ee557c Fix race conditions in minting tests (#1043)
There was a race conditions between the database storing the mint quote and the
fake wallet paying the invoice of a yet not existing mint quote

Add a delay of seconds before paying all invoices

To recreate the slow conditions that would make our database slower than the
external Fakewallet in Linux

```
sudo tc qdisc add dev lo root netem delay 200ms 50ms
ionice -c3  nix develop -i -L .#stable --command just itest-payment-processor FAKEWALLET
```

To reset

```
sudo tc qdisc del dev lo root

```
2025-09-08 13:02:45 +01:00
C
655a4b9e1e Add suport for Bolt12 notifications for HTTP subscription (#1007)
* Add suport for Bolt12 notifications for HTTP subscription

This commit adds support for Mint Bolt12 Notifications for HTTP when Mint does
not support WebSocket or the wallet decides not to use it, and falls back to
HTTP.

This PR fixes #992
2025-09-02 09:12:54 +01:00
C
2131f89068 Abstract the HTTP Transport (#1012)
* Abstract the HTTP Transport

This PR allows replacing the HTTP transport layer with another library,
allowing wallet ffi to provide a better-suited HTTP library that would be used
instead of Reqwest.
2025-08-30 08:54:48 +01:00
lollerfirst
f1118b1c7b compatibility for migrating Nutshell Mints quote ids (#984) 2025-08-27 17:12:35 +01:00
C
218b39a670 Introduce Future Streams for Payments and Minting Proofs (#985)
* Introduce Future Streams for Payments and Minting Proofs

Introduce Future Streams (`ProofStream`, `PaymentStream`) for Payments and
Proofs, an easier to use interface, async friendly, to interact for the mint
waiting for payments of mints for Bolt11 and Bolt12.

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-08-26 11:57:15 +01:00
thesimplekid
9ab86fabfe Cdk ldk node (#904)
* feat: add LDK Node Lightning backend with comprehensive integration

- Add new cdk-ldk-node crate implementing Lightning backend using LDK Node
- Extend MintPayment trait with start/stop methods for processor lifecycle management
- Add LDK Node configuration support to cdk-mintd with chain source and gossip options
- Enhance mint startup/shutdown to properly manage payment processor lifecycle

---------

Co-authored-by: Erik <78821053+swedishfrenchpress@users.noreply.github.com>
2025-08-25 22:06:00 +01:00
thesimplekid
6f25620f06 feat: mintd db features (#977) 2025-08-21 22:41:46 +01:00
thesimplekid
4e13c1958f feat: mintd db features 2025-08-21 16:20:30 +01:00
thesimplekid
b6f7a75fba feat: cln as msats (#982)
* feat: cln as msats

* fix(logging): correct bolt12 payment amount units and reduce log noise

- Fix CLN bolt12 payment logging to display msats instead of sats
- Add tower_http filter to reduce integration test log verbosity
- Use correct payment amount variable in mint quote pubsub notifications
2025-08-21 16:13:06 +01:00
thesimplekid
5c5075af71 feat: refresh keysets (#974)
* feat: refresh keysets

* feat: rename get_mint_info to fetch_mint_info
2025-08-19 19:19:08 +01:00
thesimplekid
761ed82554 feat: log to file (#967) 2025-08-19 14:57:14 +01:00
thesimplekid
d3a3c30d99 feat(cdk): add Bolt12 mint quote subscription support (#976)
* feat(cdk): add Bolt12 mint quote subscription support

Extends subscription to handle Bolt12 payment method alongside existing Bolt11 support across wallet, mint, and CLI components.
2025-08-19 12:01:01 +01:00
C
28a01398fd Add PostgreSQL support for mint and wallet (#878)
* Add PostgreSQL support for mint and wallet

* Fixed bug to avoid empty calls `get_proofs_states`

* Fixed SQL bug

* Avoid redudant clone()

* Add more tests for the storage layer

* Minor enhacements

* Add a generic function to execute db operations

This function would log slow operations and log errors

* Provision a postgres db for tests

* Update deps for msrv

* Add postgres to pipeline

* feat: add psgl to example and docker

* feat: db url fmt

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-08-18 17:45:11 +01:00
thesimplekid
2e424e629f feat: uuid version (#891)
* feat: uuid version

* feat: rustls version
2025-08-18 16:25:24 +01:00
C
f8d58e419f Merge pull request #963 from crodas/feature/wait-for-invoice
Add `wait_for_payment` function in the wallet
2025-08-18 12:57:45 +01:00
thesimplekid
47c5bb7465 fix: fake mint multiple units 2025-08-13 13:59:32 +01:00
C
64f7b07855 Do not perform external calls during a database transaction. (#954)
The codebase was used to correctly perform signatory calls during a database
transaction, as the signatory was previously exclusively in process. However, a
few months ago, it was changed to be a trait that can be either local or
remote. Making external calls to services, adding latency, during an ongoing
database transaction is a bad idea because it will lock the rows until the
service call is finalized, which is unpredictable.

The issue is even worse in our pipeline where the SQLite storage driver is used
with the ":memory:" path, which forces the Database pool to have a size of 1.
Since our tests run in parallel, they would randomly fail.

This issue was failing in the CI, but the error was not making the pipeline
fail. This bug was fixed as well.
2025-08-13 12:25:59 +01:00
gudnuf
cceea654fe feat: enhance auth config (#922)
* feat: enhance auth config
2025-08-05 12:55:17 +01:00
lollerfirst
92eea181fd new secret derivation
Wallet holds `seed` instead of `xpriv`

fix doctest  errors

update examples

adjustments

fix doctests

fix all doctests

Update crates/cdk/src/wallet/multi_mint_wallet.rs

Co-authored-by: thesimplekid <tsk@thesimplekid.com>

fix

remove clone call
2025-08-02 19:36:20 +02:00
thesimplekid
3a3cd88ee9 Mintd lib (#914)
* feat(cdk-integration-tests): refactor regtest setup and mintd integration

- Replace shell-based regtest setup with Rust binary (start_regtest_mints)
- Add cdk-mintd crate to workspace and integration tests
- Improve environment variable handling for test configurations
- Update integration tests to use proper temp directory management
- Remove deprecated start_regtest.rs binary
- Enhance CLN client connection with retry logic
- Simplify regtest shell script (itests.sh) to use new binary
- Fix tracing filters and improve error handling in setup
- Update dependencies and configurations for integration tests

fix: killing

chore: comment tests for ci debugging

chore: compile

Revert "chore: comment tests for ci debugging"

This reverts commit bfc594c11cf37caeaa6445cb854ae5567d2da6bd.

* chore: sql cipher

* fix: removal of sqlite cipher

* fix: auth password

* refactor(cdk-mintd): improve database password handling and function signatures

- Pass database password as parameter instead of parsing CLI args in setup_database
- Update function signatures for run_mintd and run_mintd_with_shutdown to accept db_password
- Remove direct CLI parsing from database setup logic
- Fix auth database initialization to use correct type when sqlcipher feature enabled
2025-07-31 00:43:43 -04:00
David Caseria
6ebcbba0c4 refactor: update send functionality across wallet components (#925)
* refactor: update send functionality across wallet components

---------
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-07-30 23:37:41 -04:00
Cesar Rodas
349c773406 Introduce cdk-sql-common
The primary purpose of this new crate is to have a common and shared codebase
for all SQL storage systems. It would force us to write standard SQL using best
practices for all databases.

This crate has been extracted from #878
2025-07-29 11:31:23 -03:00
thesimplekid
7b2e31a3df Merge pull request #903 from thesimplekid/mint_start
feat(cdk): add mint lifecycle management with start/stop methods
2025-07-23 20:50:19 +01:00
thesimplekid
d2e9f1a626 Merge pull request #901 from thesimplekid/refresh_keys
feat: refactor wallet keyset management for better clarity
2025-07-23 20:49:42 +01:00
thesimplekid
6e0c3a3f7f feat(cdk): add mint lifecycle management with start/stop methods
- Add background service management with graceful shutdown handling
- Refactor invoice payment monitoring to use centralized task supervision
- Update cdk-mintd and integration tests to use new lifecycle methods
- Add comprehensive documentation and lifecycle tests
2025-07-23 13:38:20 +01:00
David Caseria
f018465aa6 Refactor MintBuilder (#887)
* Refactor MintBuilder
* Validate azp instead of aud for client id
2025-07-19 18:13:11 +02:00
thesimplekid
ae6c107809 feat: bolt12 2025-07-13 18:48:35 +01:00
thesimplekid
ea0b696db9 fix: cln mprocs logging 2025-07-08 11:33:21 +01:00
C
238b09d56a Split the database trait into read and transactions. (#826)
* Split the database trait into read and transactions.

The transaction traits will encapsulate all database changes and also expect
READ-and-lock operations to read and lock records from the database for
exclusive access, thereby avoiding race conditions.

The Transaction trait expects a `rollback` operation on Drop unless the
transaction has been committed.

* fix: melt quote duplicate error

This change stops a second melt quote from being created
if there is an existing valid melt quote for an invoice already.
If the first melt quote has expired then we allow for a new melt quote to be created.

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-06-28 12:07:47 +01:00
thesimplekid
f62992238a refactor: remove redb mint database 2025-06-21 10:32:26 +01:00
lollerfirst
c61fd3830a Keysets V2 (#702)
---------
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-06-19 15:36:16 +01:00
C
ade48cd8a9 Introduce a SignatoryManager service. (#509)
* WIP: Introduce a SignatoryManager service.

The SignatoryManager manager provides an API to interact with keysets, private
keys, and all key-related operations, offering segregation between the mint and
the most sensible part of the mind: the private keys.

Although the default signatory runs in memory, it is completely isolated from
the rest of the system and can only be communicated through the interface
offered by the signatory manager. Only messages can be sent from the mintd to
the Signatory trait through the Signatory Manager.

This pull request sets the foundation for eventually being able to run the
Signatory and all the key-related operations in a separate service, possibly in
a foreign service, to offload risks, as described in #476.

The Signatory manager is concurrent and deferred any mechanism needed to handle
concurrency to the Signatory trait.

* Fixed missing default feature for signatory

* Do not read keys from the DB

* Removed KeysDatabase Trait from MintDatabase

All Keys operations should be done through the signatory

* Make sure signatory has all the keys in memory

Drop also foreign constraints on sqlite

* Fix race condition

* Adding debug info to failing test

* Add `sleep` in test

* Fixed issue with active auth keyset

* Fixed dependency

* Move all keys and keysets to an ArcSwap.

Since the keys and keysets exist in RAM, most wrapping functions are infallible
and synchronous, improving performance and adding breaking API changes.

The signatory will provide this information on the boot and update when the
`rotate_keyset` is executed.

Todo: Implement a subscription key to reload the keys when the GRPC server
changes the keys. For the embedded mode, that makes no sense since there is a
single way to rotate keys, and that bit is already covered.

* Implementing https://github.com/cashubtc/nuts/pull/250

* Add CLI for cdk-signatory to spawn an external signatory

Add to the pipeline the external signatory

* Update tests

* Apply suggestions from code review

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: thesimplekid <tsk@thesimplekid.com>

* Minor change

* Update proto buf to use the newest format

* Rename binary

* Add instrumentations

* Add more comments

* Use a single database for the signatory

Store all keys, even auth keys, in a single database. Leave the MintAuthDatabse
trait implementation for the CDK but not the signagtory

This commit also moves the cli mod to its own file

* Update dep

* Add `test_mint_keyset_gen` test

---------

Co-authored-by: ok300 <106775972+ok300@users.noreply.github.com>
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-05-28 11:43:30 -04:00