-
Notifications
You must be signed in to change notification settings - Fork 34
Custom registration #457
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
Merged
Merged
Custom registration #457
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f195243
Custom registration
Kolezhniuk 910759d
Fix lint
Kolezhniuk 17766a6
Remove implicit flow. Fix test
Kolezhniuk 357f743
Move chain id to core
Kolezhniuk b20901f
Update registration methods & test
Kolezhniuk 4351306
Fix comments
Kolezhniuk 274faf0
Fix comments
Kolezhniuk 87ce330
Fix comments after discussion
Kolezhniuk 7d55e56
Fix comments
Kolezhniuk a166dfb
Fix error messages
Kolezhniuk 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 hidden or 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,69 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/iden3/go-iden3-core/v2/w3c" | ||
) | ||
|
||
// ChainID is alias for int32 that represents ChainID | ||
type ChainID int32 | ||
|
||
// ChainIDs Object containing chain IDs for various blockchains and networks. | ||
var chainIDs = map[string]ChainID{ | ||
"eth:main": 1, | ||
"eth:goerli": 5, | ||
"eth:sepolia": 11155111, | ||
"polygon:main": 137, | ||
"polygon:mumbai": 80001, | ||
"zkevm:main": 1101, | ||
"zkevm:test": 1442, | ||
} | ||
|
||
// ChainIDfromDID returns chain name from w3c.DID | ||
func ChainIDfromDID(did w3c.DID) (ChainID, error) { | ||
|
||
id, err := IDFromDID(did) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
blockchain, err := BlockchainFromID(id) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
networkID, err := NetworkIDFromID(id) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
chainID, ok := chainIDs[fmt.Sprintf("%s:%s", blockchain, networkID)] | ||
if !ok { | ||
return 0, fmt.Errorf("chainID not found for %s:%s", blockchain, networkID) | ||
} | ||
|
||
return chainID, nil | ||
} | ||
|
||
// RegisterChainID registers chainID for blockchain and network | ||
func RegisterChainID(blockchain Blockchain, network NetworkID, chainID int) error { | ||
k := fmt.Sprintf("%s:%s", blockchain, network) | ||
existingChainID, ok := chainIDs[k] | ||
if ok && existingChainID != ChainID(chainID) { | ||
return fmt.Errorf("chainID '%s:%s' already registered with value %d", blockchain, network, existingChainID) | ||
} | ||
chainIDs[k] = ChainID(chainID) | ||
|
||
return nil | ||
} | ||
|
||
// GetChainID returns chainID for blockchain and network | ||
func GetChainID(blockchain Blockchain, network NetworkID) (ChainID, error) { | ||
k := fmt.Sprintf("%s:%s", blockchain, network) | ||
if _, ok := chainIDs[k]; !ok { | ||
return 0, fmt.Errorf("chainID not registered for %s:%s", blockchain, network) | ||
} | ||
|
||
return chainIDs[k], nil | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.