Refactor: move spending conditions implementation to nut10 module #1714

Open
TheMhv wants to merge 9 commits from TheMhv/refact/spending_conditions into main
TheMhv commented 2026-03-07 02:35:03 +00:00 (Migrated from github.com)

Description

This PR moves the spending conditions implementation to the module that corresponds to the correct NUT specification.

While reviewing the code, I noticed that the SpendingConditions implementation is currently located in nuts/nut11/mod.rs. However, spending conditions are defined in NUT-10, not NUT-11. Keeping this implementation under nut11 can make the module structure slightly confusing for contributors trying to map code to the corresponding NUT specifications.

This change relocates the relevant implementation to the nut10 module so the code structure better reflects the specification layout.


Notes to the reviewers

  • Create a folder nut10/ for module of NUT-10
  • Move SpendingConditions and Conditions from nut11/mod.rs to nut10/spending_conditions.rs
  • Move all NUT-10 related errors to nut10/error.rs
  • Move Secret implementation to nut10/secret.rs
  • Move SpendingConditions::new_p2pk, extract_signatures_from_witness and verify_sig_all_p2pk functions to nut11/mod.rs
  • Move SpendingConditions::new_htlc, SpendingConditions::new_htlc_hash, verify_htlc_preimage and verify_sig_all_htlc to nut14/mod.rs
  • Move Tag and TagKind to nut10/tag.rs

Suggested CHANGELOG Updates

CHANGED

  • NUT-10 Spending Conditions

ADDED

REMOVED

FIXED


Checklist

### Description <!-- Describe the purpose of this PR, what's being adding and/or fixed --> This PR moves the spending conditions implementation to the module that corresponds to the correct NUT specification. While reviewing the code, I noticed that the `SpendingConditions` implementation is currently located in `nuts/nut11/mod.rs`. However, spending conditions are defined in [**NUT-10**](https://github.com/cashubtc/nuts/blob/main/10.md), not [**NUT-11**](https://github.com/cashubtc/nuts/blob/main/11.md). Keeping this implementation under `nut11` can make the module structure slightly confusing for contributors trying to map code to the corresponding NUT specifications. This change relocates the relevant implementation to the `nut10` module so the code structure better reflects the specification layout. ----- ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> - Create a folder `nut10/` for module of NUT-10 - Move **SpendingConditions** and **Conditions** from `nut11/mod.rs` to `nut10/spending_conditions.rs` - Move all NUT-10 related errors to `nut10/error.rs` - Move **Secret** implementation to `nut10/secret.rs` - Move `SpendingConditions::new_p2pk`, `extract_signatures_from_witness` and `verify_sig_all_p2pk` functions to `nut11/mod.rs` - Move `SpendingConditions::new_htlc`, `SpendingConditions::new_htlc_hash`, `verify_htlc_preimage` and `verify_sig_all_htlc` to `nut14/mod.rs` - Move `Tag` and `TagKind` to `nut10/tag.rs` ----- ### Suggested [CHANGELOG](https://github.com/cashubtc/cdk/blob/main/CHANGELOG.md) Updates <!-- Please do not edit the actual changelog but note what you changed here. --> #### CHANGED - NUT-10 Spending Conditions #### ADDED #### REMOVED #### FIXED - https://github.com/cashubtc/cdk/issues/1705 ---- ### Checklist * [x] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md) * [x] I ran `just final-check` before committing
thesimplekid (Migrated from github.com) reviewed 2026-03-07 02:35:03 +00:00
TheMhv commented 2026-03-09 16:49:46 +00:00 (Migrated from github.com)

I could further separate and modularize the Spending Conditions code, but that's not the purpose of this PR. What do you think about discussing this?

I could further separate and modularize the Spending Conditions code, but that's not the purpose of this PR. What do you think about discussing this?
KvngMikey (Migrated from github.com) reviewed 2026-03-09 18:15:32 +00:00
@ -0,0 +1,45 @@
//! Error types for NUT-10: Spending Conditions
KvngMikey (Migrated from github.com) commented 2026-03-09 18:15:32 +00:00

cosmetic verbiage update here
spend conditions not met, you currently have spend conditions not meet

cosmetic verbiage update here `spend conditions not met`, you currently have `spend conditions not meet`
KvngMikey (Migrated from github.com) reviewed 2026-03-09 18:19:08 +00:00
KvngMikey (Migrated from github.com) commented 2026-03-09 18:19:08 +00:00

just same verbiage change here

just same verbiage change here
KvngMikey (Migrated from github.com) approved these changes 2026-03-09 18:30:21 +00:00
thesimplekid (Migrated from github.com) requested changes 2026-03-11 12:50:34 +00:00
thesimplekid (Migrated from github.com) left a comment

This moves some this to a better place but leaves other fns not in the files of their nut.

This moves some this to a better place but leaves other fns not in the files of their nut.
@ -0,0 +456,4 @@
assert_eq!(original_secret, deserialized_secret);
// Also verify that the conversion to crate::secret::Secret works
let cashu_secret = crate::secret::Secret::from_str(&serialized).unwrap();
thesimplekid (Migrated from github.com) commented 2026-03-11 12:49:01 +00:00

nut11?

nut11?
thesimplekid (Migrated from github.com) commented 2026-03-11 12:48:45 +00:00

Shouldn't these be in nut14

Shouldn't these be in nut14
@ -0,0 +1,105 @@
//! NUT-10 Secret Module
thesimplekid (Migrated from github.com) commented 2026-03-11 12:43:55 +00:00

This makes the kind and secret data public where it was not before. I think we should keep it private.

This makes the kind and secret data public where it was not before. I think we should keep it private.
@ -0,0 +1,341 @@
//! NUT-10: Spending Conditions
thesimplekid (Migrated from github.com) commented 2026-03-11 12:46:57 +00:00

Shouldn't these but in nut14?

Shouldn't these but in nut14?
thesimplekid (Migrated from github.com) commented 2026-03-11 12:47:06 +00:00

And this in nut11?

And this in nut11?
TheMhv (Migrated from github.com) reviewed 2026-03-11 13:25:30 +00:00
@ -0,0 +1,341 @@
//! NUT-10: Spending Conditions
TheMhv (Migrated from github.com) commented 2026-03-11 13:25:30 +00:00

Sure! But that will require more than a simple refactoring, going beyond the scope of this PR. We can separate this work into other PRs for better comprehension of each change.

~~Sure! But that will require more than a simple refactoring, going beyond the scope of this PR. We can separate this work into other PRs for better comprehension of each change.~~
TheMhv (Migrated from github.com) reviewed 2026-03-11 13:26:46 +00:00
@ -0,0 +1,341 @@
//! NUT-10: Spending Conditions
TheMhv (Migrated from github.com) commented 2026-03-11 13:26:46 +00:00
~~Same problem: https://github.com/cashubtc/cdk/pull/1714#discussion_r2918357575~~
thesimplekid (Migrated from github.com) reviewed 2026-03-13 16:17:32 +00:00
thesimplekid (Migrated from github.com) left a comment

Looks good. I think we should reduce the visibility of some of the helper fns we have so they are not in the public api. What do you think @crodas

Looks good. I think we should reduce the visibility of some of the helper fns we have so they are not in the public api. What do you think @crodas
@ -250,9 +227,110 @@ impl Proof {
}
thesimplekid (Migrated from github.com) commented 2026-03-13 15:51:27 +00:00

Since this is not intended to be called directly we can make it pub(crate).

Since this is not intended to be called directly we can make it pub(crate).
thesimplekid (Migrated from github.com) commented 2026-03-13 16:15:23 +00:00
pub(crate) fn extract_signatures_from_witness(
```suggestion pub(crate) fn extract_signatures_from_witness( ```
thesimplekid (Migrated from github.com) commented 2026-03-13 16:16:55 +00:00
pub(crate) fn valid_signatures(
```suggestion pub(crate) fn valid_signatures( ```
@ -1076,7 +599,7 @@ mod tests {
num_sigs_refund: None,
thesimplekid (Migrated from github.com) commented 2026-03-13 15:56:08 +00:00

These could be improved by using the Nut10Secret::new_p2pk() constructor

These could be improved by using the Nut10Secret::new_p2pk() constructor
@ -217,6 +236,154 @@ impl Proof {
}
thesimplekid (Migrated from github.com) commented 2026-03-13 15:51:55 +00:00

Since this is not intended to be called directly we can make it pub(crate).

Since this is not intended to be called directly we can make it pub(crate).
thesimplekid (Migrated from github.com) commented 2026-03-13 16:14:21 +00:00
fn verify_htlc_preimage(witness: &HTLCWitness, secret: &Secret) -> Result<(), Error> {
```suggestion fn verify_htlc_preimage(witness: &HTLCWitness, secret: &Secret) -> Result<(), Error> { ```
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin TheMhv/refact/spending_conditions:TheMhv/refact/spending_conditions
git switch TheMhv/refact/spending_conditions

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff TheMhv/refact/spending_conditions
git switch TheMhv/refact/spending_conditions
git rebase main
git switch main
git merge --ff-only TheMhv/refact/spending_conditions
git switch TheMhv/refact/spending_conditions
git rebase main
git switch main
git merge --no-ff TheMhv/refact/spending_conditions
git switch main
git merge --squash TheMhv/refact/spending_conditions
git switch main
git merge --ff-only TheMhv/refact/spending_conditions
git switch main
git merge TheMhv/refact/spending_conditions
git push origin main
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cashubtc/cdk!1714
No description provided.