mirror of
https://github.com/aljazceru/cdk.git
synced 2026-02-08 14:45:47 +01:00
4b04d10383d1beb733710b139f409ed5e0c3cfe8
* fix(cdk): prevent duplicate blinded message processing with database constraints Add unique constraints on blinded_message column in both PostgreSQL and SQLite databases, and implement application-level checks to prevent duplicate blinded messages from being processed. Also ensure proper cleanup of melt requests after successful processing. * feat: db tests for unique * refactor(cdk-sql): consolidate blinded messages into blind signature table Migrate from separate blinded_messages table to unified blind_signature table. Add signed_time column and make c column nullable to track both pending blind messages (c=NULL) and completed signatures. Update insert/update logic to handle upsert scenarios for blind signature completion. * refactor(cdk-sql): remove unique constraint migration and filter queries for signed messages Remove database-level unique constraint on blinded_message and instead filter queries to only consider messages with signatures (c IS NOT NULL * refactor(database): improve blinded message duplicate detection using database constraints Replace manual duplicate checking with database constraint handling for better reliability and simplified code flow in melt request processing. * refactor(cdk-sql): optimize blind signature processing with batch queries Replace individual queries per blinded message with single batch query and HashMap lookup to eliminate N+1 query performance issue. * fix: signed time to swap sigs * refactor(cdk): split blinded message handling and improve duplicate detection - Split add_melt_request_and_blinded_messages into separate methods - Add blinded messages to database before signing in swap operations - Improve duplicate output detection with proper error handling - Make add_blinded_messages method accept optional quote_id for flexibility * refactor(cdk): add BlindedMessageWriter for improved transaction rollback - Add BlindedMessageWriter component for managing blinded message state - Implement proper rollback mechanisms in swap operations - Add delete_blinded_messages database interface for cleanup - Improve error handling with better state management
Warning
This project is in early development, it does however work with real sats! Always use amounts you don't mind losing.
Cashu Development Kit
CDK is a collection of rust crates for Cashu wallets and mints written in Rust.
ALPHA This library is in early development, the api will change and should be used with caution.
Project structure
The project is split up into several crates in the crates/ directory:
- Libraries:
- cdk: Rust implementation of Cashu protocol.
- cdk-sqlite: SQLite Storage backend.
- cdk-postgres: PostgreSQL Storage backend.
- cdk-redb: Redb Storage backend.
- cdk-axum: Axum webserver for mint.
- cdk-cln: CLN Lightning backend for mint.
- cdk-lnd: Lnd Lightning backend for mint.
- cdk-lnbits: LNbits Lightning backend for mint. Note: Only LNBits v1 API is supported.
- cdk-ldk-node: LDK Node Lightning backend for mint.
- cdk-fake-wallet: Fake Lightning backend for mint. To be used only for testing, quotes are automatically filled.
- cdk-mint-rpc: Mint management gRPC server and cli.
- Binaries:
- cdk-cli: Cashu wallet CLI.
- cdk-mintd: Cashu Mint Binary.
- cdk-mint-cli: Cashu Mint management gRPC client cli.
Development
For a guide to settings up a development environment see DEVELOPMENT.md
Implemented NUTs:
Mandatory
| NUT # | Description |
|---|---|
| 00 | Cryptography and Models |
| 01 | Mint public keys |
| 02 | Keysets and fees |
| 03 | Swapping tokens |
| 04 | Minting tokens |
| 05 | Melting tokens |
| 06 | Mint info |
Optional
| # | Description | Status |
|---|---|---|
| 07 | Token state check | ✔️ |
| 08 | Overpaid Lightning fees | ✔️ |
| 09 | Signature restore | ✔️ |
| 10 | Spending conditions | ✔️ |
| 11 | Pay-To-Pubkey (P2PK) | ✔️ |
| 12 | DLEQ proofs | ✔️ |
| 13 | Deterministic secrets | ✔️ |
| 14 | Hashed Timelock Contracts (HTLCs) | ✔️ |
| 15 | Partial multi-path payments (MPP) | ✔️ |
| 16 | Animated QR codes | ❌ |
| 17 | WebSocket subscriptions | ✔️ |
| 18 | Payment Requests | ✔️ |
| 19 | Cached responses | ✔️ |
| 20 | Signature on Mint Quote | ✔️ |
| 21 | Clear Authentication | ✔️ |
| 22 | Blind Authentication | ✔️ |
| 23 | Payment Method: BOLT11 | ✔️ |
| 25 | Payment Method: BOLT12 | ✔️ |
License
Code is under the MIT License
Contribution
All contributions are welcome.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.
Please see the development guide.
Languages
Rust
97.1%
Shell
2.1%
Just
0.5%
Nix
0.2%