-
Notifications
You must be signed in to change notification settings - Fork 362
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
feat: Add EIP-712 management in prepareMessageToSign #892
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 909fef0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Screenshots: ✅
There are no changes in the screenshots for this PR. If this is expected, you are good to go. |
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.
No strong opinion on this rework overall
libs/ledger-live-common/src/families/ethereum/hw-signMessage.test.ts
Outdated
Show resolved
Hide resolved
There seem to be an issue with the update in
|
Codecov Report
@@ Coverage Diff @@
## develop #892 +/- ##
===========================================
+ Coverage 47.82% 47.86% +0.03%
===========================================
Files 650 650
Lines 29114 29146 +32
Branches 7529 7541 +12
===========================================
+ Hits 13925 13951 +26
- Misses 15131 15137 +6
Partials 58 58
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Fixed in 75cb580 |
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.
Is there anything to be done on mobile side as well?
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
…o avoid confusion Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
0a77f64
to
77aa652
Compare
Signed-off-by: Stéphane Prohaszka <[email protected]>
Signed-off-by: Stéphane Prohaszka <[email protected]>
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.
Just a few optional comments, otherwise LGTM 🚀
import hwSignMessage from "./hw-signMessage"; | ||
import { EIP712Message } from "@ledgerhq/hw-app-eth/lib/modules/EIP712"; | ||
import testEIP712Message from "@ledgerhq/hw-app-eth/tests/sample-messages/0.json"; | ||
import ethSignMessage, { prepareMessageToSign } from "./hw-signMessage"; |
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 guess here we can just
import { signMessage, prepareMessageToSign } from "./hw-signMessage";
And replace all hwSignMessage
by signMessage
?
let parsedMessage = message; | ||
if (typeof message === "string") { | ||
parsedMessage = tryConvertToJSON(message); | ||
} |
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.
Is this condition necessary ? JSON.parse({})
should throw and be catched and return the original message, so we might be able to update the typings of tryConvertToJSON
to allow for more "all-in-one" behaviour ?
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.
message
can be of the type string
or EIP712Message
. In the latter case, we can't and don't want to try to convert it into a JSON.
I added typing info in the method to be clearer.
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 I meant was to potentially change tryConvertToJSON
into something like this:
function tryConvertToEIP712(message: string | Record<string, any>): string | EIP712Message {
const maybeParsedMessage = (() => {
try {
return JSON.parse(message as string) as Record<string, any>;
} catch {
return message;
}
})();
return isEIP712Message(maybeParsedMessage)
? maybeParsedMessage
: message.toString();
}
So:
- if message is a random
string
it would throw on parse and return message as astring
- if message is a stringified random
object
it would fail onisEIP712Message
and return message as astring
- if message is an
EIP712
stringified object it would returnmaybeParsedMessage
as anEIP712Message
- if message is an
EIP712Message
it would throw on parse, succeed onisEIP712Message
and returnmaybeParsedMessage
as anEIP712Message
Only other adjustement to make would to add a type guard toisEIP712Message
that themessage
param is an object first.
But again, I'm nit picking here, and it's just another abstraction, nothing major, feel free to ignore. 👍
Signed-off-by: Stéphane Prohaszka <[email protected]>
Works well with wallet-connect and same for EIP 191 messages |
Signed-off-by: Stéphane Prohaszka [email protected]
📝 Description
Add EIP-712 support on WebPlatformPlayer.
Rework some unused properties in
TypesMessageData
and update impacted WalletConnect current implementation.❓ Context
common
ledgerjs-eth
✅ Checklist
📸 Demo
🚀 Expectations to reach
The goal, beside Platform capacity to manage EIP-712 call, is to remove unused code and keep eth logic inside dedicated modules (i.e.
ledgerjs/package/hw-app/eth
andcommon/families/etherereum
).Also, leverage as much as possible type to use typescript validation build system to check for unwanted behavior.
It can be tested by running LLD with
EXPERIMENTAL_EIP712=1
and using the ethereum app available on provider 3