Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyset ID V2 #182

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Keyset ID V2 #182

wants to merge 4 commits into from

Conversation

davidcaseria
Copy link

@davidcaseria davidcaseria commented Oct 30, 2024

This PR introduces a new keyset ID version that commits to the keyset's unit and avoids keyset ambiguity between mints. Keyset IDs are now 33 bytes, with a one-byte version prefix before a 32-byte SHA256 hash.

Tokens maintain the same length by abbreviating the 33-byte keyset ID to the first 8 bytes: a one-byte version prefix before the first 7 bytes of the 32-byte SHA256 hash. While unlikely in practice, implementors should ensure that token keyset IDs are unambiguous to the mint when serializing.

Wallets will be responsible for expanding the abbreviated keyset ID to the full-length keyset ID.

It is now recommended to store the entire 33-byte keyset ID in a wallet's proof database.

Comment on lines +80 to +81
keyset_id_bytes = b"".join([p.serialize() for p in sorted_keys.values()])
keyset_id_bytes += b"unit:sat"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering ... since we already depend for CBOR (for Token v4), maybe we can use CBOR here too instead of this custom serialization?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the structure of the CBOR be?

02.md Outdated Show resolved Hide resolved
@callebtc
Copy link
Contributor

Thank you!

Please:

  • add a verbose description in the PR what this is about
  • we should keep at least 7 bytes, as others have mentioned
  • this PR seems to replace the old keyset ID instead of adding a new version. Everything would break. We should instead add a new additional version.

@davidcaseria davidcaseria marked this pull request as ready for review November 1, 2024 19:34
@davidcaseria davidcaseria changed the title Define Keyset ID V2 Keyset ID V2 Nov 1, 2024
02.md Outdated Show resolved Hide resolved
def derive_keyset_id(keys: Dict[int, PublicKey]) -> str:
sorted_keys = dict(sorted(keys.items()))
keyset_id_bytes = b"".join([p.serialize() for p in sorted_keys.values()])
keyset_id_bytes += b"unit:sat"
Copy link
Contributor

@ok300 ok300 Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once optimization could be to change b"unit:sat" -> b"u:sat" or even just b"sat".
(Edit: nevermind that, it will all be hashed in the end, so reducing the length of what's inside won't matter)

Might also be worth specifying the unit should be lowercased first.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have specified the units as case-insensitive yet. We should probably also do that if we include this change, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants