-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
signTypedData for arrays #54
Conversation
index.js
Outdated
encodedValues.push(value) | ||
const encodeField = (name, type, value) => { | ||
if(value === undefined) | ||
throw new Error(`missing value for field ${name} of type ${type}`) |
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've decided to turn missing values into an error. I'm not sure if it is proper to do so, or if values may be optional and skipped (how the implementation was before). If a decision is made on this, maybe a test case should be added to reflect that decision?
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.
This is probably worth asking on the EIP's discussion, to gauge for strong opinions.
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.
Type dependencies were not correctly being discovered for types that have arrays of structs. Previously, the test suite passed only because the That issue is also addressed in e0d30b1 |
This is looking good, and so I'm really just trying to find the basic diligence we should exercise to merge. Another thing that came to mind is that this adds specificity to an existing EIP, and so it seems to merit submitting either a new EIP that depends on EIP-712 (with the official discussion directed at your magicians link), or an addition to EIP-712. |
Thanks for your support! I gave this some thought and added some of my thoughts to the thread. Hopefully I will find the time to write a patch to the EIP or an EIP extension, but this can sit here as long as it needs to. |
What if we just merge this as |
Hey Dan, I've been pretty busy with other stuff, so I haven't had time to properly make a PR for EIP-712 yet. I think using |
The thing is, changes to EIP-712 are not really binding nor are they easy to coordinate with wallet devs. the |
Alright, I've decided to place the new implementation behind a I've decided to have the internal |
Wait, I did remember sort of remembering this, but doesn't the current EIP-712 draft actually cover the cases that are mentioned wrt arrays and recursive stuff? I think this implementation actually diverges from the current EIP 712. Anyway, for that reason, I'd appreciate it if you could pause on this PR while I try to sort this out. For reference:
EDIT: Nevermind. I was concerned about nested structs not having their
I guess maybe the standard could use some clarification on some cases. I'll open a PR there still. |
I've added this into my EIP edit, which is not accounted for in this PR yet (this PR will error on those inputs instead, but recursive structures are part of the EIP spec):
|
I'll pause, but on the upside, diverging is a great reason to have your own namespace :) Also a great reason to draft a fresh EIP for that namespace... ;) |
Haha, that might be true, but AFAIK I haven't broken compatibility with existing specified behavior, I've just specified more specific behavior. Also, in the process, I've come across this case I had not considered previously:
|
Oh that's great, because recursive types are a requirement for one of my favorite things that has yet to be built. Could you include a test demonstrating recursive use of this API? After that, I think this looks good to merge if you agree. |
I've changed the implementation and included a tree as a test vector. I think this is fine to merge if you're ready. |
Published to npm as |
Hey, do you know if your contribution here fixed #56? |
Off the cuff, I'd guess that this PR doesn't affect that issue, as the message in that format should be hashed the same way in both v3 and v4. It could be an implementation detail though... |
Is there an example somewhere that shows how to verify structs with arrays in a smart contract? The example provided in the blog post only covers structs with non-array data types. |
Unfortunately, as far as I can tell, there isn't an example anywhere of doing this in Solidity. Actually, the signing demo page seems to be broken for me, as I don't even see the source that you're supposed to copy into Remix there... |
This builds on @bitpshr's previous work on signTypedData, adding support for the following:
Arrays of atomic types have been encoded as a hash of its contents, where its contents are word-aligned according to the type.
Arrays of dynamic types have been encoded as a hash of each element's hash.
Arrays of structs retain their encoding as a hash of its contents' concatenated hashStructs.
Arrays of arrays are encoded recursively, as a hash of the contained arrays' hash encodings concatenated.