-
Notifications
You must be signed in to change notification settings - Fork 221
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
EIP-3770 #178
Merged
Merged
EIP-3770 #178
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1cc83a1
Add safe-core-sdk-utils package
germartinez 4975cd8
Update README files
germartinez e610d7e
Add eip-3770 network list
germartinez 8bb2e61
Add support for eip-3770
germartinez 9396bc8
Add tests for eip-3770
germartinez 4edf32e
Update EthAdapters
germartinez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021-2022 Gnosis Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Safe Core SDK Utils | ||
|
||
[![NPM Version](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils.svg)](https://badge.fury.io/js/%40gnosis.pm%2Fsafe-core-sdk-utils) | ||
[![GitHub Release](https://img.shields.io/github/release/gnosis/safe-core-sdk.svg?style=flat)](https://github.com/gnosis/safe-core-sdk/releases) | ||
[![GitHub](https://img.shields.io/github/license/gnosis/safe-core-sdk)](https://github.com/gnosis/safe-core-sdk/blob/main/LICENSE.md) | ||
|
||
Utilities for the [Safe Core SDK](https://github.com/gnosis/safe-core-sdk) monorepo. | ||
|
||
## Table of contents | ||
* [Installation](#installation) | ||
* [Build](#build) | ||
|
||
## <a name="installation">Installation</a> | ||
|
||
Install the package with yarn or npm: | ||
|
||
```bash | ||
yarn install | ||
npm install | ||
``` | ||
|
||
## <a name="build">Build</a> | ||
|
||
Build the package with yarn or npm: | ||
|
||
```bash | ||
yarn build | ||
npm build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "@gnosis.pm/safe-core-sdk-utils", | ||
"version": "1.0.0", | ||
"description": "Safe Core SDK Utilities", | ||
"main": "dist/src/index.js", | ||
"typings": "dist/src/index.d.ts", | ||
"keywords": [ | ||
"Ethereum", | ||
"Gnosis", | ||
"Safe", | ||
"SDK" | ||
], | ||
"scripts": { | ||
"unbuild": "rimraf dist *.tsbuildinfo", | ||
"build": "rimraf dist && tsc", | ||
"test": "nyc mocha -r ts-node/register tests/**/*.test.ts", | ||
"format": "prettier --write \"{src,tests}/**/*.ts\"", | ||
"lint": "tslint -p tsconfig.json" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/gnosis/safe-core-sdk.git" | ||
}, | ||
"author": "Gnosis (https://gnosis.io)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/gnosis/safe-core-sdk/issues" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"homepage": "https://github.com/gnosis/safe-core-sdk#readme", | ||
"devDependencies": { | ||
"@types/chai": "^4.3.0", | ||
"@types/chai-as-promised": "^7.1.4", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^17.0.13", | ||
"@typescript-eslint/eslint-plugin": "^5.10.1", | ||
"@typescript-eslint/parser": "^5.10.1", | ||
"chai": "^4.3.6", | ||
"chai-as-promised": "^7.1.1", | ||
"eslint": "^8.7.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"mocha": "^9.2.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.5.1", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.5" | ||
}, | ||
"dependencies": { | ||
"@gnosis.pm/safe-core-sdk-types": "^1.0.0", | ||
"web3-utils": "^1.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
interface NetworkShortName { | ||
shortName: string | ||
chainId: number | ||
} | ||
|
||
export const networks: NetworkShortName[] = [ | ||
{ shortName: 'eth', chainId: 1 }, | ||
{ shortName: 'rop', chainId: 3 }, | ||
{ shortName: 'rin', chainId: 4 }, | ||
{ shortName: 'gor', chainId: 5 }, | ||
{ shortName: 'oeth', chainId: 10 }, | ||
{ shortName: 'meta', chainId: 11 }, | ||
{ shortName: 'kal', chainId: 12 }, | ||
{ shortName: 'boba-rinkeby', chainId: 28 }, | ||
{ shortName: 'kov', chainId: 42 }, | ||
{ shortName: 'bnb', chainId: 56 }, | ||
{ shortName: 'okov', chainId: 69 }, | ||
{ shortName: 'gno', chainId: 100 }, | ||
{ shortName: 'fuse', chainId: 122 }, | ||
{ shortName: 'spark', chainId: 123 }, | ||
{ shortName: 'matic', chainId: 137 }, | ||
{ shortName: 'ewt', chainId: 246 }, | ||
{ shortName: 'boba', chainId: 288 }, | ||
{ shortName: 'metis-stardust', chainId: 588 }, | ||
{ shortName: 'metis-andromeda', chainId: 1088 }, | ||
{ shortName: 'mbeam', chainId: 1284 }, | ||
{ shortName: 'mriver', chainId: 1285 }, | ||
{ shortName: 'mbase', chainId: 1287 }, | ||
{ shortName: 'tftm', chainId: 4002 }, | ||
{ shortName: 'arb1', chainId: 42161 }, | ||
{ shortName: 'celo', chainId: 42220 }, | ||
{ shortName: 'avax', chainId: 43114 }, | ||
{ shortName: 'vt', chainId: 73799 }, | ||
{ shortName: 'maticmum', chainId: 80001 }, | ||
{ shortName: 'olympus', chainId: 333999 }, | ||
{ shortName: 'aurora', chainId: 1313161554 }, | ||
{ shortName: 'aurora-testnet', chainId: 1313161555 } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Eip3770Address } from '@gnosis.pm/safe-core-sdk-types' | ||
import { isAddress, isHexStrict } from 'web3-utils' | ||
import { networks } from './config' | ||
|
||
export function parseEip3770Address(fullAddress: string): Eip3770Address { | ||
const parts = fullAddress.split(':') | ||
const address = parts.length > 1 ? parts[1] : parts[0] | ||
const prefix = parts.length > 1 ? parts[0] : '' | ||
return { prefix, address } | ||
} | ||
|
||
export function getEip3770NetworkPrefixFromChainId(chainId: number): string { | ||
const network = networks.find((network) => chainId === network.chainId) | ||
if (!network) { | ||
throw new Error('No network prefix supported for the current chainId') | ||
} | ||
return network.shortName | ||
} | ||
|
||
export function isValidEip3770NetworkPrefix(prefix: string): boolean { | ||
return networks.some(({ shortName }) => shortName === prefix) | ||
} | ||
|
||
export function validateEip3770NetworkPrefix(prefix: string, currentChainId: number): void { | ||
const isCurrentNetworkPrefix = prefix === getEip3770NetworkPrefixFromChainId(currentChainId) | ||
if (prefix && (!isValidEip3770NetworkPrefix(prefix) || !isCurrentNetworkPrefix)) { | ||
throw new Error('The network prefix must match the current network') | ||
} | ||
} | ||
|
||
export function validateEthereumAddress(address: string): void { | ||
const isValidAddress = isHexStrict(address) && isAddress(address) | ||
if (!isValidAddress) { | ||
throw new Error(`Invalid Ethereum address ${address}`) | ||
} | ||
} | ||
|
||
export function validateEip3770Address( | ||
fullAddress: string, | ||
currentChainId: number | ||
): Eip3770Address { | ||
const { address, prefix } = parseEip3770Address(fullAddress) | ||
validateEthereumAddress(address) | ||
validateEip3770NetworkPrefix(prefix, currentChainId) | ||
return { address, prefix } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './eip-3770' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are these related to contracts we currently have deployed?
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.
Yes, I took them from
safe-deployments