Skip to content
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

Merged
merged 7 commits into from
Feb 21, 2023
Merged

PRO-1036: EIP1271 Module #1

merged 7 commits into from
Feb 21, 2023

Conversation

Yash-Chaubal
Copy link
Contributor

@Yash-Chaubal Yash-Chaubal commented Feb 20, 2023

This module exports two functions: isValidEip1271Signature and isValidEip1271SignatureForAllNetworks - 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

@linear
Copy link

linear bot commented Feb 20, 2023

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

Copy link
Member

@arddluma arddluma left a 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!

@@ -0,0 +1,87 @@
import { NetworkNames } from "etherspot";
Copy link
Member

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 ?

[CHAIN_ID.XDAI]: {
id: CHAIN_ID.XDAI,
name: NetworkNames.Xdai,
rpcUrl: "https://rpc.gnosischain.com/" + process.env.REACT_APP_INFURA_KEY,
Copy link
Member

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 ^


type ISupportedNetworks = Record<CHAIN_ID, INetworkData>;

export const supportedNetworks: ISupportedNetworks = {
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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",
Copy link
Member

Choose a reason for hiding this comment

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

Do we need axios ?

Copy link
Member

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.

@@ -0,0 +1,36 @@
export declare const abiEip1271Json: {
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 re @arddluma comment

@ch4r10t33r
Copy link
Member

@Yash-Chaubal Please can you add a README.md explaining how the module should be used? A simple example will help. Thanks.

Copy link
Contributor

@poocart poocart left a 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

Comment on lines 80 to 81
// const validArr = await isValidEip1271SignatureForAllNetworks(walletAddress, hash, signature);
// return validArr.filter((item) => !!item.valid).length > 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// const validArr = await isValidEip1271SignatureForAllNetworks(walletAddress, hash, signature);
// return validArr.filter((item) => !!item.valid).length > 0;

@@ -0,0 +1,118 @@
export enum NetworkNames {
Copy link
Contributor

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 ?? "",
Copy link
Contributor

@poocart poocart Feb 20, 2023

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

Comment on lines 83 to 84
const valid = await checkSignature(walletAddress, hash, signature, provider);
return !!valid;
Copy link
Contributor

Choose a reason for hiding this comment

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

checkSignature returns bool already

Suggested change
const valid = await checkSignature(walletAddress, hash, signature, provider);
return !!valid;
return checkSignature(walletAddress, hash, signature, provider);

const isCaseInsensitiveMatch = (val1: string, val2: string) => val1.toLowerCase() === val2.toLowerCase();

const createProvider = (rpcUrl: string) => {
const isWss = rpcUrl.substring(0, 3) === "wss";
Copy link
Contributor

@poocart poocart Feb 20, 2023

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

Suggested change
const isWss = rpcUrl.substring(0, 3) === "wss";
const isWss = rpcUrl.startsWith("ws");

signature: string
): Promise<boolean> => {
const validArr = await isValidEip1271SignatureForAllNetworks(rpcUrls, walletAddress, hash, signature);
return validArr.filter((item) => !!item.valid).length > 0;
Copy link
Contributor

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

Suggested change
return validArr.filter((item) => !!item.valid).length > 0;
return validArr.some((item) => !!item.valid);

Copy link
Contributor

@poocart poocart left a 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:

  1. compilation should happen inside publish pipeline therefore compiled files removed? cc @arddluma
  2. same typed abi for eip1271 sits in two places: constants and utils, make sure leave single

otherwise lgtm and well done! 🚀

Copy link
Member

@arddluma arddluma left a 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

@Yash-Chaubal Yash-Chaubal merged commit 0f2d91d into master Feb 21, 2023
@Yash-Chaubal Yash-Chaubal deleted the PRO-1036-eip1271_module branch February 21, 2023 10:51
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants