cesar
pushed to feature/fetch_mint_info-with-cache at cesar/cdk
9778bc3e31 Update Wallet::fetch_mint_info
Make `fetch_mint_info` fetch the mint_info through the mint metadata cache
instead of calling the Mint Connector directly.
This will make sure to persist the data correctly in other instances and the
database
836a50aaa3 fix: require 0 signatures for HTLC with no pubkeys specified (#1275)
* fix: require 0 signatures for HTLC with no pubkeys specified
Prior to this fix, HTLC verification incorrectly required 1 signature even
when no pubkeys were specified in the spending conditions. This caused
valid preimage-only HTLCs to fail verification.
The issue occurred in get_pubkeys_and_required_sigs() for HTLC secrets
before locktime:
- Line 179: pubkeys defaults to empty vector [] when not specified
- Line 180: required_sigs defaulted to 1 unconditionally
- Result: impossible condition requiring 1 signature from 0 pubkeys
* refactor(cashu): replace tuple with SpendingRequirements struct in nut10
Introduce SpendingRequirements struct to replace tuple return type in
get_pubkeys_and_required_sigs function. This improves code clarity by
using named fields (preimage_needed, pubkeys, required_sigs) instead
of positional tuple elements across nut10, nut11, and nut14 modules
9eaa6f1c02 feat: update NUT-11 SIG_ALL message aggregation per spec
Implements changes from cashubtc/nuts#302 which updates the SIG_ALL message aggregation scheme for spending condition verification.
SIG_ALL Message Changes:
- Update message format to: secret || C || amount || B_
- Initially added keyset_id to outputs (amount || keyset_id || B_)
- Removed keyset_id per final spec (amount || B_)
- Applied to both swap (NUT-03) and melt (NUT-05) operations
Architecture Improvements:
- Introduce NUT-10 SpendingConditionVerification trait for unified
verification logic across swap and melt operations
- Refactor NUT-11 (P2PK) and NUT-14 (HTLC) verification to share
common code paths
- Add helper functions for pubkey/signature extraction with proper
locktime handling
- Improve error handling with specific error types (PreimageNotSupportedInP2PK,
SpendConditionsNotMet)
- Deprecate old verify_sig_all methods in favor of unified trait
Test Coverage:
- Add comprehensive test vectors for P2PK + SIG_ALL combinations
- Add comprehensive test vectors for HTLC + SIG_ALL combinations
- Add test helpers for spending condition verification
- Cover multisig, locktime, refund keys, and mixed scenarios
- Test vectors aligned with other implementations (nutshell, cashu-ts)
---------
Co-authored-by: Sats And Sports <sats.and.sports@gmail.com>
Co-authored-by: thesimplekid <tsk@thesimplekid.com>
e5882dc2eb test: add mutation testing infrastructure and security-critical coverage (#1210)
Mutation testing validates test quality by introducing code changes and
checking if tests catch them. This is critical for security code where
missing negative tests could allow bypasses.
**Infrastructure:**
- `.cargo/mutants.toml` - Configuration with timeout exclusions
- `justfile` commands - `mutants-quick`, `mutants-check`, `mutants-diff`
- GitHub Actions - Weekly mutation testing with issue creation
**Security-Critical Tests:**
- NUT12 (DLEQ): 5 tests ensuring signature verification (prevents token forgery)
- NUT14 (HTLC): 6 tests ensuring spending conditions (prevents unauthorized spending)
- Amount operations: Tests for subtraction, checked_add, try_sum (prevents infinite loops)
- Mutations Caught: 301 → 308 (+7, +2.3%)
- Mutations Missed: 281 → 274 (-7, -2.5%)
- Mutation Coverage: 35.5% → 36.4% (+0.9%)
- All critical verification functions: 100% coverage
2f9100ea4f Metadata follow up (#1268)
* feat: cache_ttl as RwLock instead of Mutex
This is a read heavy workflow that is not held across await points.
So we can use a RwLock instead of Mutex.
* refactor: remove TTL check from load_from_mint for guaranteed fresh fetches
Remove TTL parameter and check from load_from_mint() to ensure it always
fetches fresh metadata from the mint as documented. The method now truly
forces a refresh, while load() continues to handle TTL-based caching.
4 days ago