-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: main
Are you sure you want to change the base?
Keyset ID V2 #182
Conversation
keyset_id_bytes = b"".join([p.serialize() for p in sorted_keys.values()]) | ||
keyset_id_bytes += b"unit:sat" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
Thank you! Please:
|
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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.