P2pk receive wallet #1466

Open
lescuer97 wants to merge 12 commits from lescuer97/p2pk_receive_wallet into main
lescuer97 commented 2025-12-27 10:17:59 +00:00 (Migrated from github.com)

Description

Add public key generation with counter for wallet.


Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

### Description Add public key generation with counter for wallet. ----- ### 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 --> ----- ### 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 #### ADDED #### REMOVED #### FIXED ---- ### Checklist * [ ] I followed the [code style guidelines](https://github.com/cashubtc/cdk/blob/main/CODE_STYLE.md) * [ ] I ran `just final-check` before committing
thesimplekid (Migrated from github.com) reviewed 2025-12-27 10:17:59 +00:00
thesimplekid commented 2025-12-27 22:17:06 +00:00 (Migrated from github.com)

This replaces this right? https://github.com/cashubtc/cdk/pull/1053

This replaces this right? https://github.com/cashubtc/cdk/pull/1053
thesimplekid (Migrated from github.com) reviewed 2025-12-27 22:19:14 +00:00
thesimplekid (Migrated from github.com) commented 2025-12-27 22:19:00 +00:00

I think we need to have a discussion and have some guidelines on when we should add new fns to the db traits and when we should take advantage of the KVStore. I think there is a balance between over using the store and making our db traits too complicated.

I think we need to have a discussion and have some guidelines on when we should add new fns to the db traits and when we should take advantage of the KVStore. I think there is a balance between over using the store and making our db traits too complicated.
lescuer97 commented 2025-12-29 09:17:59 +00:00 (Migrated from github.com)

This replaces this right? #1053

yes

> This replaces this right? #1053 yes
lescuer97 (Migrated from github.com) reviewed 2025-12-29 09:37:14 +00:00
lescuer97 (Migrated from github.com) commented 2025-12-29 09:37:14 +00:00

I think we need to have a discussion and have some guidelines on when we should add new fns to the db traits and when we should take advantage of the KVStore. I think there is a balance between over using the store and making our db traits too complicated.

could you explain the difference between KVStore and the traits? what do you think it should be the parameters on choosing one or the other?

> I think we need to have a discussion and have some guidelines on when we should add new fns to the db traits and when we should take advantage of the KVStore. I think there is a balance between over using the store and making our db traits too complicated. could you explain the difference between KVStore and the traits? what do you think it should be the parameters on choosing one or the other?
thesimplekid (Migrated from github.com) reviewed 2025-12-29 20:12:00 +00:00
thesimplekid (Migrated from github.com) commented 2025-12-29 20:12:00 +00:00

The kvstore is general so we can just store arbitrary data in it without having to add fns on the trait. With the drawback of a different migration pattern and less structured data. So I'm not necessarily saying we should do it here but there is a discussion worth having about when to use the Kv and when to add new fns and db tables.

The kvstore is general so we can just store arbitrary data in it without having to add fns on the trait. With the drawback of a different migration pattern and less structured data. So I'm not necessarily saying we should do it here but there is a discussion worth having about when to use the Kv and when to add new fns and db tables.
lescuer97 (Migrated from github.com) reviewed 2025-12-30 22:09:18 +00:00
lescuer97 (Migrated from github.com) commented 2025-12-30 22:09:18 +00:00

yeah, I understand. I would use the KVstore when you have data that is clearly independent. EX: Information about a specific npub that you sent money to comes up in my mind

yeah, I understand. I would use the KVstore when you have data that is clearly independent. EX: Information about a specific npub that you sent money to comes up in my mind
lescuer97 commented 2025-12-30 22:21:39 +00:00 (Migrated from github.com)

@thesimplekid @crodas I think this is know in a decent state. I know I'm lacking tests. I want to get your opinion on the implementation before I do that.

@thesimplekid @crodas I think this is know in a decent state. I know I'm lacking tests. I want to get your opinion on the implementation before I do that.
thesimplekid (Migrated from github.com) requested changes 2025-12-31 11:21:08 +00:00
thesimplekid (Migrated from github.com) commented 2025-12-31 10:54:39 +00:00

We shouldn't need this should be able to get what we need from cdk

We shouldn't need this should be able to get what we need from cdk
@ -0,0 +1,70 @@
use std::str::FromStr;
thesimplekid (Migrated from github.com) commented 2025-12-31 10:53:57 +00:00

Lets remove the emojis

Lets remove the emojis
thesimplekid (Migrated from github.com) commented 2025-12-31 10:56:02 +00:00

This should need doc comments not sure why clippy hasn't caught it

This should need doc comments not sure why clippy hasn't caught it
thesimplekid (Migrated from github.com) commented 2025-12-31 10:56:28 +00:00

Out of date

Out of date
thesimplekid (Migrated from github.com) commented 2025-12-31 10:56:51 +00:00

out of date

out of date
thesimplekid (Migrated from github.com) commented 2025-12-31 11:13:59 +00:00

Outdated

Outdated
thesimplekid (Migrated from github.com) commented 2025-12-31 11:17:09 +00:00

Think we should rename this get private key?

Think we should rename this get private key?
thesimplekid (Migrated from github.com) commented 2025-12-31 11:17:55 +00:00

These fns should also have doc comments

These fns should also have doc comments
thesimplekid (Migrated from github.com) commented 2025-12-31 11:21:00 +00:00

I wonder if we should have a fn to get the most recent pubkey especially with p2bk the user might want to just reuse the pubkey.

I wonder if we should have a fn to get the most recent pubkey especially with p2bk the user might want to just reuse the pubkey.
lescuer97 (Migrated from github.com) reviewed 2026-01-01 10:07:19 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 10:07:18 +00:00

this does not give a private key, so no

this does not give a private key, so no
lescuer97 (Migrated from github.com) reviewed 2026-01-01 10:07:57 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 10:07:57 +00:00

I don't think it's a bad idea.

I don't think it's a bad idea.
lescuer97 (Migrated from github.com) reviewed 2026-01-01 11:57:45 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 11:57:45 +00:00

I made a function for getting the latest public key

I made a function for getting the latest public key
lescuer97 (Migrated from github.com) reviewed 2026-01-01 11:58:18 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 11:58:18 +00:00

I don't expose right now a way to get the secret key. this is a private method.

I'll take suggestions on naming

I don't expose right now a way to get the secret key. this is a private method. I'll take suggestions on naming
thesimplekid (Migrated from github.com) reviewed 2026-01-01 12:21:05 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-01 12:21:05 +00:00

this does not give a private key, so no

get_public_key i meant

> this does not give a private key, so no get_public_key i meant
thesimplekid (Migrated from github.com) reviewed 2026-01-01 19:22:28 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-01 19:16:31 +00:00

We need to set the time here. we can use unix_time()

We need to set the time here. we can use `unix_time()`
thesimplekid (Migrated from github.com) commented 2026-01-01 19:21:52 +00:00

We don't error if we do not have the required keys to sign. If we cannot get enough sigs for a proof we should not send it to the mint.

We don't error if we do not have the required keys to sign. If we cannot get enough sigs for a proof we should not send it to the mint.
lescuer97 (Migrated from github.com) reviewed 2026-01-01 22:09:36 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 22:09:36 +00:00

changed the named functions plus added missing ones to ffi

changed the named functions plus added missing ones to ffi
lescuer97 (Migrated from github.com) reviewed 2026-01-01 22:13:36 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-01 22:13:36 +00:00

I added an enough_signatures function to the Proof struct that will check. Needed to add a new error to the Nut 10 file.

I'm getting a typo error from a meeting agenda. I assume this is a mistake

I added an `enough_signatures` function to the Proof struct that will check. Needed to add a new error to the Nut 10 file. I'm getting a typo error from a `meeting agenda`. I assume this is a mistake
thesimplekid (Migrated from github.com) reviewed 2026-01-06 13:45:26 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-06 13:45:26 +00:00

I'm getting a typo error from a meeting agenda. I assume this is a mistake

Rebase will solve this

> I'm getting a typo error from a meeting agenda. I assume this is a mistake Rebase will solve this
thesimplekid (Migrated from github.com) reviewed 2026-01-08 22:19:23 +00:00
thesimplekid (Migrated from github.com) left a comment

Thanks just a few comments.

Thanks just a few comments.
thesimplekid (Migrated from github.com) commented 2026-01-08 22:02:51 +00:00

We already have a verify_p2pk() fn that we use for the mint. I think we can just reuse that and remove this fn?

We already have a `verify_p2pk()` fn that we use for the mint. I think we can just reuse that and remove this fn?
@ -0,0 +1,70 @@
use std::str::FromStr;
thesimplekid (Migrated from github.com) commented 2026-01-08 21:57:35 +00:00

There is a get_latest_pubke fn on the MultiMintWallet we should use that if the latest arg is passed.

There is a `get_latest_pubke` fn on the MultiMintWallet we should use that if the latest arg is passed.
thesimplekid (Migrated from github.com) commented 2026-01-08 21:59:28 +00:00

We don't need the Ok import here.

We don't need the `Ok` import here.
@ -0,0 +62,4 @@
println!("\npublic not found!\n");
}
println!("\npublic keys found:\n");
for public_key in list_public_keys {
thesimplekid (Migrated from github.com) commented 2026-01-08 22:00:21 +00:00

We should check if the list is empty here and print no keys found if so.

We should check if the list is empty here and print no keys found if so.
thesimplekid (Migrated from github.com) commented 2026-01-08 20:46:33 +00:00
```suggestion ```
thesimplekid (Migrated from github.com) commented 2026-01-08 21:46:16 +00:00

This is missing the created time.

We should add some db tests for the new functions that would have caught this.

This is missing the created time. We should add some db tests for the new functions that would have caught this.
thesimplekid (Migrated from github.com) commented 2026-01-08 22:13:30 +00:00

We should have a purpose identifier. We could reuse the cashu purpose of 129372' and then use 1 for the next where on secrets we use 0.

We should have a purpose identifier. We could reuse the cashu purpose of 129372' and then use 1 for the next where on secrets we use 0.
thesimplekid (Migrated from github.com) commented 2026-01-08 22:15:02 +00:00

Why is this only here on the multi-mint wallet. Shouldn't it be on the Wallet and then the Multi-mint wallet can call that. Generally this is how we use the multi-mint wallet where it is just a dumb wrapper around the Wallet.

Why is this only here on the multi-mint wallet. Shouldn't it be on the `Wallet` and then the Multi-mint wallet can call that. Generally this is how we use the multi-mint wallet where it is just a dumb wrapper around the Wallet.
thesimplekid (Migrated from github.com) commented 2026-01-08 22:19:20 +00:00

These fns should be on the Wallet as well. The `Wallet~ needs to be able to usable without the multi mint wallet.

These fns should be on the `Wallet` as well. The `Wallet~ needs to be able to usable without the multi mint wallet.
thesimplekid (Migrated from github.com) reviewed 2026-01-09 10:00:48 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-09 10:00:43 +00:00

I thought about this a bit more and we should not reuse the cashu purpose. We should only use that where its spec'd in the nuts which this is not.

I thought about this a bit more and we should not reuse the cashu purpose. We should only use that where its spec'd in the nuts which this is not.
lescuer97 (Migrated from github.com) reviewed 2026-01-09 10:32:38 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-09 10:32:38 +00:00

yeah, I had a default param in the migration, that is why I had not caught it. I will add some tests

yeah, I had a default param in the migration, that is why I had not caught it. I will add some tests
lescuer97 (Migrated from github.com) reviewed 2026-01-09 10:33:10 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-09 10:33:10 +00:00

I used the new 1 as we said with the cashu purpose.

I used the new 1 as we said with the cashu purpose.
thesimplekid (Migrated from github.com) reviewed 2026-01-09 10:43:24 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-09 10:43:24 +00:00

I used the new 1 as we said with the cashu purpose.

I think was a bad idea from me. What if something else gets added to the spec using that purpose, we would then conflict.

> I used the new 1 as we said with the cashu purpose. I think was a bad idea from me. What if something else gets added to the spec using that purpose, we would then conflict.
lescuer97 (Migrated from github.com) reviewed 2026-01-09 10:58:06 +00:00
lescuer97 (Migrated from github.com) commented 2026-01-09 10:58:06 +00:00

I might have a miss understanding on how this works. I didn't want to put the functions inside the Wallet mostly because it would mean that the keys are dependent of each mint.
Should I just allow for both?

I might have a miss understanding on how this works. I didn't want to put the functions inside the Wallet mostly because it would mean that the keys are dependent of each mint. Should I just allow for both?
thesimplekid (Migrated from github.com) reviewed 2026-01-09 11:30:16 +00:00
thesimplekid (Migrated from github.com) commented 2026-01-09 11:30:16 +00:00

The keys won't really rely on the wallet since there is nothing in the derivation path linking them to a mint. But yeah we need the fns on the Wallet so can just make this on both the Wallet and MultimintWallet. The logic can be in a shared helper fn.

The keys won't really rely on the wallet since there is nothing in the derivation path linking them to a mint. But yeah we need the fns on the `Wallet` so can just make this on both the `Wallet` and `MultimintWallet`. The logic can be in a shared helper fn.
lescuer97 commented 2026-01-14 13:08:44 +00:00 (Migrated from github.com)

@thesimplekid rebased

@thesimplekid rebased
thesimplekid commented 2026-01-15 10:02:22 +00:00 (Migrated from github.com)

ACK 4093b6c014de5612b2d2497d909d74ef47c3b8bc

ACK 4093b6c014de5612b2d2497d909d74ef47c3b8bc
thesimplekid (Migrated from github.com) approved these changes 2026-01-15 17:54:27 +00:00
thesimplekid (Migrated from github.com) requested changes 2026-01-15 17:56:11 +00:00
@ -0,0 +33,4 @@
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_normal_idx(last_derivation_index)?,
]);
thesimplekid (Migrated from github.com) commented 2026-01-15 17:56:07 +00:00

Shouldn't we still have a purpose here even though we said we shouldnt reuse the cashu one?

Shouldn't we still have a purpose here even though we said we shouldnt reuse the cashu one?
lescuer97 (Migrated from github.com) reviewed 2026-01-16 13:43:26 +00:00
@ -0,0 +33,4 @@
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_normal_idx(last_derivation_index)?,
]);
lescuer97 (Migrated from github.com) commented 2026-01-16 13:43:26 +00:00

yeah we probably should

yeah we probably should
lescuer97 (Migrated from github.com) reviewed 2026-01-16 14:15:46 +00:00
@ -0,0 +33,4 @@
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_hardened_idx(0)?,
ChildNumber::from_normal_idx(last_derivation_index)?,
]);
lescuer97 (Migrated from github.com) commented 2026-01-16 14:15:45 +00:00

Added a purpose and solved conflicts

Added a purpose and solved conflicts
lescuer97 commented 2026-01-19 14:48:18 +00:00 (Migrated from github.com)
this commit: https://github.com/cashubtc/cdk/pull/1466/commits/57a072b4d6b3bc468cc7c8f9078929ebadce3359 changes the derivation to in accordance to https://github.com/cashubtc/nuts/pull/331. plus adds tests
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 lescuer97/p2pk_receive_wallet:lescuer97/p2pk_receive_wallet
git switch lescuer97/p2pk_receive_wallet

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 lescuer97/p2pk_receive_wallet
git switch lescuer97/p2pk_receive_wallet
git rebase main
git switch main
git merge --ff-only lescuer97/p2pk_receive_wallet
git switch lescuer97/p2pk_receive_wallet
git rebase main
git switch main
git merge --no-ff lescuer97/p2pk_receive_wallet
git switch main
git merge --squash lescuer97/p2pk_receive_wallet
git switch main
git merge --ff-only lescuer97/p2pk_receive_wallet
git switch main
git merge lescuer97/p2pk_receive_wallet
git push origin main
Sign in to join this conversation.
No reviewers
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!1466
No description provided.