Commit 9a213c7
committed
feat: add keysets v2 client side implementation
Keysets v2: align with NUT-13 HMAC derivation (4-byte counter, single HMAC split); implement wallet-side short ID manager and token helpers; apply default final_expiry on rotation; keep mint agnostic of s_id
alignment
NUT-02/13 alignment:
- Keys API: include final_expiry in /v1/keys and /v1/keys/{id}
- Derivation: keyset ID v2 per spec (unit + optional final_expiry; SHA256; v=01)
- NUT-13 v2 secrets: switch to HMAC-SHA256 with 8-byte counter and type byte (00/01)
- Tests: update wallet v2 tests to HMAC-SHA256; derive seed from BIP-39 mnemonic; fix TokenV4 short ID expansion test to use KeysetManager directly; update API expectations for final_expiry
Remove mint_use_keysets_v2 flag; always generate v2 keyset IDs for new keysets. Keep optional default final_expiry via settings. Update keyset rotation/activation to use default expiry unconditionally. Update docs.
wallet: log debug when resolving short keyset id to full id (cache hit).
wallet: integrate v2 short keyset IDs directly in TokenV4 creation; deprecate WalletTokensV2 helper; tests: remove tokens_v2 dependency, assert short-ID serialization; secrets: NUT-13 v2 docstring to HMAC-SHA256; proofs: fix helper method refactor regression; cleanup
remove deprecated cashu/wallet/tokens_v2.py; short-ID handling now in WalletProofs._make_tokenv4
Summary of changes on keysets-v2
- Removed deprecated helper:
- cashu/wallet/tokens_v2.py deleted.
- Integrated short-ID handling into wallet TokenV4 creation:
- cashu/wallet/proofs.py: _make_tokenv4 now converts v2 full keyset IDs to short IDs during token creation via KeysetManager; ensured _get_proofs_mint_unit remains correct.
- Updated tests to remove tokens_v2 dependency:
- tests/wallet/test_wallet_keysets_v2.py: test_token_serialization_with_short_ids now uses WalletProofs to assert short-ID serialization.
- Docstring correction:
- cashu/wallet/secrets.py: NUT-13 v2 derivation is HMAC-SHA256 (not SHA512).
Remote
- Branch keysets-v2 is now ahead by 2 commits and pushed to origin.
format
move tests to v2 keyset id
fixed test_mint_api
more fixes
bump nutshell version to 0.18 => derive ID v1/v2 based on nutshell version of the keyset: if not specified the nutshell version is 0.18 and the keyset ID is v2
more fixes
Fix keyset version tests: update assertions for v1/v2 ID expectations
- Change test_keyset_0_15_0 and test_keyset_0_15_0_encrypted to expect V1_KEYSET_ID (version 0.15.0 uses v1 IDs)
- Update test_keyset_short_id to properly assert V1_KEYSET_ID for legacy keysets
- Simplify test_keyset_v2_deterministic to use version 0.18.0 which uses v2 IDs
- Remove redundant test_keyset_v1_v2_compatibility test (covered by other tests)
- Update test section header to 'KEYSET IDs NUT-02 TEST VECTORS'
Add comprehensive keyset ID test vectors and version behavior tests
New tests added:
1. test_keyset_versions_produce_correct_id_format: Tests that different
nutshell versions (0.11, 0.14, 0.15, 0.17, 0.18, 0.19) produce the
correct ID format (base64 for <0.15, v1 hex for 0.15-0.17, v2 hex for >=0.18)
2. test_keyset_id_v1_test_vectors: Implements NUT-02 test vectors for v1
keyset ID derivation with two test vectors (small 4-key keyset and
large 64-key keyset)
3. test_keyset_id_v2_test_vectors: Implements NUT-02 test vectors for v2
keyset ID derivation with three test vectors testing different
combinations of keyset sizes, units, and final_expiry values
These tests ensure compatibility with the NUT specifications and verify
that the keyset ID derivation algorithms produce stable, interoperable
results across different implementations.
Test vectors source: https://github.com/cashubtc/nuts/pull/182/files
Fix test_keyset_version_detection for v1 vs v2 ID distinction
Corrected the test to properly distinguish between v1 and v2 keyset IDs:
- V1 IDs (version 0.15-0.17) start with '00' and are NOT detected as v2
- V2 IDs (version 0.18+) start with '01' and ARE detected as v2
This test was incorrectly expecting a v1 keyset (version 0.15.0) to be
identified as v2.
more fixes
Add v2 short keyset ID expansion support for token redemption
Fix for TokenV3 and TokenV4 redemption with v2 short keyset IDs:
- Added _expand_short_keyset_ids() method to WalletProofs class
- Expands v2 short IDs (16 chars, '01' + 7 bytes) to full IDs (66 chars)
- Uses KeysetManager to map short->full IDs from loaded keysets
- Handles expansion failures gracefully with warning logging
- Updated redeem_TokenV3() and redeem_TokenV4() in helpers.py
- Calls _expand_short_keyset_ids() after load_mint() to ensure
all keyset IDs in proofs are expanded before redemption
- Added comprehensive test: test_proof_short_id_expansion()
- Verifies short ID expansion works correctly
- Tests that proofs with v2 short IDs get expanded to full IDs
- Fixed existing tests in test_wallet_keysets_v2.py
- Removed incorrect 'await' calls on synchronous KeysetManager methods
- Fixed test_token_v4_short_keyset_expansion to use proper v2 short ID
- Fixed test_nut13_spec_compliance to use actual V2_KEYSET_ID constant
- Updated test_wallet_cli.py token to use v2 short keyset IDs
This ensures wallets can properly handle TokenV3/V4 tokens containing
v2 short keyset IDs, which are used to reduce token size.
feat: improve v2 keyset ID handling and fee calculation
- Add short-to-full keyset ID expansion in wallet helpers
- Enhance KeysetManager with better documentation and type hints
- Fix fee calculation to handle short keyset IDs gracefully
- Add keyset ID expansion before proof redemption in CLI
- Update tests to reflect new keyset ID handling behavior
- Add fallback logic for missing keysets in fee calculations
format
fixes
base64 keysets detection1 parent a5f950a commit 9a213c7
File tree
23 files changed
+2231
-1005
lines changed- cashu
- core
- crypto
- mint
- wallet
- tests
- mint
- wallet
23 files changed
+2231
-1005
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
805 | 806 | | |
806 | 807 | | |
807 | 808 | | |
| 809 | + | |
808 | 810 | | |
809 | 811 | | |
810 | 812 | | |
| |||
826 | 828 | | |
827 | 829 | | |
828 | 830 | | |
| 831 | + | |
829 | 832 | | |
830 | 833 | | |
831 | 834 | | |
| |||
861 | 864 | | |
862 | 865 | | |
863 | 866 | | |
| 867 | + | |
864 | 868 | | |
865 | 869 | | |
866 | 870 | | |
| |||
915 | 919 | | |
916 | 920 | | |
917 | 921 | | |
| 922 | + | |
918 | 923 | | |
919 | 924 | | |
920 | 925 | | |
| |||
958 | 963 | | |
959 | 964 | | |
960 | 965 | | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
961 | 979 | | |
962 | 980 | | |
963 | 981 | | |
964 | 982 | | |
965 | 983 | | |
966 | | - | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
967 | 993 | | |
968 | 994 | | |
969 | 995 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | | - | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
64 | 175 | | |
65 | 176 | | |
66 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | 94 | | |
96 | 95 | | |
97 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
691 | | - | |
692 | | - | |
| 691 | + | |
| 692 | + | |
693 | 693 | | |
694 | 694 | | |
695 | 695 | | |
| |||
710 | 710 | | |
711 | 711 | | |
712 | 712 | | |
| 713 | + | |
713 | 714 | | |
714 | 715 | | |
715 | 716 | | |
| |||
822 | 823 | | |
823 | 824 | | |
824 | 825 | | |
825 | | - | |
| 826 | + | |
826 | 827 | | |
827 | 828 | | |
828 | 829 | | |
| |||
843 | 844 | | |
844 | 845 | | |
845 | 846 | | |
| 847 | + | |
846 | 848 | | |
847 | 849 | | |
848 | 850 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
| 170 | + | |
169 | 171 | | |
170 | 172 | | |
171 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
968 | 968 | | |
969 | 969 | | |
970 | 970 | | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | 124 | | |
| |||
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
46 | 53 | | |
47 | 54 | | |
48 | 55 | | |
| |||
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
61 | 73 | | |
62 | 74 | | |
63 | 75 | | |
| |||
70 | 82 | | |
71 | 83 | | |
72 | 84 | | |
73 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
74 | 94 | | |
75 | 95 | | |
76 | 96 | | |
| |||
0 commit comments