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

VerificationKey toJson and fromJson are doing different encodings #1868

Open
rpanic opened this issue Oct 16, 2024 · 4 comments
Open

VerificationKey toJson and fromJson are doing different encodings #1868

rpanic opened this issue Oct 16, 2024 · 4 comments

Comments

@rpanic
Copy link
Contributor

rpanic commented Oct 16, 2024

The following code throws an error

const json = VerificationKey.toJSON(vk);
const decoded = VerificationKey.fromJSON(json);

The reason for this is that toJSON returns only the data field as a string and omits the hash, but fromJSON doesn't account for that

@mitschabaude
Copy link
Collaborator

I wonder why we did toJSON() that way, can't think of a good reason 🤔
The transaction types include both the hash and data for verification keys.

@mitschabaude
Copy link
Collaborator

I think you can probably just change .toJSON() to include the hash

@rpanic
Copy link
Contributor Author

rpanic commented Oct 16, 2024

I assume its because the hash is just a pure computation away from the data itself. So one could implement fromJson in a way that computes that hash out of the data.
I can create a PR if you want, but on my side I've fixed it by just doing manual serialization including the hash

@45930
Copy link
Contributor

45930 commented Oct 16, 2024

@rpanic I will give you a gold star if you open the PR yourself :). I really appreciate your contributions!

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

No branches or pull requests

3 participants