-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
PRO-1036: EIP1271 Module #1
Conversation
PRO-1036 Etherspot npm package to inject EIP1271 support
A ticket to implement poocart's idea of a library which will allow any dapp to add support for EIP1271. More information is available here: https://pillarwallet.slack.com/archives/CEGHL682H/p1675249312222659 |
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.
Good job 🚀 ! Left some comments there. If you don't mind could you please add a readme how to use module ? ty!
src/constants/chain-constants.ts
Outdated
@@ -0,0 +1,87 @@ | |||
import { NetworkNames } from "etherspot"; |
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.
Can we just import NetworkNames module instead of install etherspot cuz it is a bit heavy ?
src/constants/chain-constants.ts
Outdated
[CHAIN_ID.XDAI]: { | ||
id: CHAIN_ID.XDAI, | ||
name: NetworkNames.Xdai, | ||
rpcUrl: "https://rpc.gnosischain.com/" + process.env.REACT_APP_INFURA_KEY, |
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.
There is no need for Infura key in this case ^
src/constants/chain-constants.ts
Outdated
|
||
type ISupportedNetworks = Record<CHAIN_ID, INetworkData>; | ||
|
||
export const supportedNetworks: ISupportedNetworks = { |
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 fun until one of the RPC doesn't work ?! Can't the dApp use the existing connect provider? We shouldn't hardcode RPC like this.
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.
we do it same way in contracts (https://github.com/etherspot/etherspot-contracts/blob/master/extensions/constants.ts), but we probably should add an option to pass your own rpc urls
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.
we do it same way in contracts (https://github.com/etherspot/etherspot-contracts/blob/master/extensions/constants.ts), but we probably should add an option to pass your own rpc urls
I agree. The RPC URL must be passed as a parameter to the module.
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.
Got it, I remembered one of the specifications was that we wanted to cycle through each network to see if the sig was valid, so this was the only way I saw a way to do so.
I can change it so that the users themselves provider the rpc/provider, but then there won't really be a way for us to check valid sigs for each network within the module itself (without the user sending us an array of rpcs by network name, but that doesn't seem very user friendly)
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.
@ch4r10t33r @arddluma I've added a new param to accept a provider from the user. If we're happy with this, and have no need to cycle through networks to check if its valid for all, then I'll remove the unneeded code.
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.
@ch4r10t33r @arddluma I've added a new param to accept a provider from the user. If we're happy with this, and have no need to cycle through networks to check if its valid for all, then I'll remove the unneeded code.
If we do this it will be single chain... Would be better to have it multichain instead.
Let's stick with this approach if possible please 🙏
@ch4r10t33r Thoughts?
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.
Well, in theory, this module has to be used specifically for a chain, no? If you wish to initialize for several chains at once, then we have to pass chainId as the key and the rpc-url as value?
package.json
Outdated
}, | ||
"dependencies": { | ||
"@rollup/plugin-json": "^6.0.0", | ||
"axios": "^0.27.2", |
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.
Do we need axios ?
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 would also use specific versions of the dependencies, instead of a generic.
constants/abi.d.ts
Outdated
@@ -0,0 +1,36 @@ | |||
export declare const abiEip1271Json: { |
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.
Do we need this file at all ? I guess it is already in src/contants/abi.ts
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 think that's one of the auto-generated files, but I'll see what deleting it does
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.
+1 re @arddluma comment
@Yash-Chaubal Please can you add a README.md explaining how the module should be used? A simple example will help. Thanks. |
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.
general comment – I think the lib files compilation should happen inside publish pipeline and currently compiled files shouldn't be committed
cc @arddluma
src/utils/verify-signature.ts
Outdated
// const validArr = await isValidEip1271SignatureForAllNetworks(walletAddress, hash, signature); | ||
// return validArr.filter((item) => !!item.valid).length > 0; |
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.
// const validArr = await isValidEip1271SignatureForAllNetworks(walletAddress, hash, signature); | |
// return validArr.filter((item) => !!item.valid).length > 0; |
src/constants/chain-constants.ts
Outdated
@@ -0,0 +1,118 @@ | |||
export enum NetworkNames { |
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.
these can be taken from Etherspot SDK, there's constant for that named under same name
rollup.config.js
Outdated
exclude: ["./example/**", "./src/test/**"], | ||
}), | ||
replace({ | ||
__ETHERSPOT_PROJECT_KEY__: process.env.ETHERSPOT_PROJECT_KEY ?? "", |
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 not needed, we're not using Etherspot SDK anywhere here for it's API access
src/utils/verify-signature.ts
Outdated
const valid = await checkSignature(walletAddress, hash, signature, provider); | ||
return !!valid; |
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.
checkSignature
returns bool already
const valid = await checkSignature(walletAddress, hash, signature, provider); | |
return !!valid; | |
return checkSignature(walletAddress, hash, signature, provider); |
src/utils/verify-signature.ts
Outdated
const isCaseInsensitiveMatch = (val1: string, val2: string) => val1.toLowerCase() === val2.toLowerCase(); | ||
|
||
const createProvider = (rpcUrl: string) => { | ||
const isWss = rpcUrl.substring(0, 3) === "wss"; |
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 an easier suggestion, also wss
to ws
just in case it's insecure sockets
const isWss = rpcUrl.substring(0, 3) === "wss"; | |
const isWss = rpcUrl.startsWith("ws"); |
src/utils/verify-signature.ts
Outdated
signature: string | ||
): Promise<boolean> => { | ||
const validArr = await isValidEip1271SignatureForAllNetworks(rpcUrls, walletAddress, hash, signature); | ||
return validArr.filter((item) => !!item.valid).length > 0; |
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.
easier approach, returns on first match
return validArr.filter((item) => !!item.valid).length > 0; | |
return validArr.some((item) => !!item.valid); |
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.
generally just couple things:
- compilation should happen inside publish pipeline therefore compiled files removed? cc @arddluma
- same typed abi for eip1271 sits in two places: constants and utils, make sure leave single
otherwise lgtm and well done! 🚀
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.
LGTM well done 💯 !
As masta @poocart said, we need to remove compiled files such as index.js
and index.js.map
This module exports two functions:
isValidEip1271Signature
andisValidEip1271SignatureForAllNetworks
- the first one returns true/false, the latter returns an array containing the results for each network.Important code located in
src/utils
+src/constants