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

feat: support custom app secret in the setup() call + EVM signTypedData fixes #563

Closed
wants to merge 3 commits into from

Conversation

refi93
Copy link

@refi93 refi93 commented Jul 11, 2024

Motivation: We'd like to be able to use the setup method with the same flow that Metamask/Rabby wallets do (i.e. redirection through lattice connector which takes care of the pairing instead of custom logic within the wallet app) and for that we need to create the same app secret which is however not the case for the implementation of the setup() method (notice the different order of parameters passed to the hashing function which generates the app secret) :

Metamask/Rabby app secret: https://github.com/GridPlus/eth-lattice-keyring/blob/c22352bd35c895d25700f19d50ff932d680ec66a/index.js#L683-L686

gridplus-sdk setup implementation:

gridplus-sdk/src/util.ts

Lines 666 to 670 in 68a8242

const preImage = Buffer.concat([
deviceIdBuffer,
passwordBuffer,
appNameBuffer,
]);

This PR solves our problem by exposing an optional appSecret parameter which allows to override the default appSecret generated in the setup() call

additionally, this PR addresses an issue we came across with bignumber.js being possibly encoded correctly, which happened if package manager chose to supply a different version of bignumber.js to gridplus-sdk vs the borc lib which is internally used to encode payloads. This should be prevented by making sure the version of bignumber.js required by gridplus-sdk matches exactly the one required by borc

@refi93 refi93 force-pushed the setup-custom-app-secret branch 4 times, most recently from ce3b76a to df9cef6 Compare July 23, 2024 12:44
@refi93 refi93 changed the title feat: support custom app secret in the setup() call feat: support custom app secret in the setup() call + EVM signTypedData fixes Jul 23, 2024
@@ -76,7 +76,7 @@ const validateEthereumMsgResponse = function (res, req) {
const digest = prehash ? prehash : encoded;
const chainId = parseInt(input.payload.domain.chainId, 16);
// Get recovery param with a `v` value of [27,28] by setting `useEIP155=false`
return addRecoveryParam(digest, sig, signer, { chainId });
return addRecoveryParam(digest, sig, signer, { chainId, useEIP155: false });
Copy link
Author

@refi93 refi93 Jul 23, 2024

Choose a reason for hiding this comment

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

as far as I checked on metamask demo app, metamask apparently still returns a non-EIP155 signature of typed data V4 and if I didn't disable EIP155, the signature failed verification in the demo dapp: https://metamask.github.io/test-dapp/

@refi93 refi93 force-pushed the setup-custom-app-secret branch from 31badec to 5b775de Compare July 23, 2024 13:13
@refi93 refi93 force-pushed the setup-custom-app-secret branch from 5b775de to 2ee4dc2 Compare July 23, 2024 13:13
@refi93 refi93 force-pushed the setup-custom-app-secret branch from 2ee4dc2 to 4baf1da Compare July 23, 2024 13:16
@netbonus
Copy link
Contributor

this change was made in #577 with more helpful features for bridging the gap between the two interfaces

@netbonus netbonus closed this Oct 18, 2024
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.

2 participants