-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from hypersign-protocol/caip-10-eth-chain-id-…
…list refactor: restricted CAIP-10 support for ethereum blockchain addresses to specific chains
- Loading branch information
Showing
7 changed files
with
198 additions
and
54 deletions.
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
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 |
---|---|---|
@@ -1,50 +1,35 @@ | ||
package verification | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hypersign-protocol/hid-node/x/ssi/types" | ||
) | ||
|
||
// Extracts the blockchain address from blockchainAccountId | ||
func getBlockchainAddress(blockchainAccountId string) string { | ||
blockchainAccountIdElements := strings.Split(blockchainAccountId, ":") | ||
blockchainAddress := blockchainAccountIdElements[len(blockchainAccountIdElements)-1] | ||
return blockchainAddress | ||
func getBlockchainAddress(blockchainAccountId string) (string, error) { | ||
bid, err := types.NewBlockchainId(blockchainAccountId) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return bid.BlockchainAddress, nil | ||
} | ||
|
||
// getChainIdFromBlockchainAccountId extracts chain from blockchainAccountId | ||
func getChainIdFromBlockchainAccountId(blockchainAccountId string) string { | ||
chainIdIdx := 1 | ||
// getChainIdFromBlockchainAccountId extracts chain-id from blockchainAccountId | ||
func getChainIdFromBlockchainAccountId(blockchainAccountId string) (string, error) { | ||
bid, err := types.NewBlockchainId(blockchainAccountId) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
blockchainAccountIdElements := strings.Split(blockchainAccountId, ":") | ||
blockchainChainId := blockchainAccountIdElements[chainIdIdx] | ||
return blockchainChainId | ||
return bid.ChainId, nil | ||
} | ||
|
||
// Extracts the CAIP-10 prefix from blockchainAccountId and returns the chain spec | ||
func getCAIP10Prefix(blockchainAccountId string) (string, error) { | ||
segments := strings.Split(blockchainAccountId, ":") | ||
|
||
// Validate blockchainAccountId | ||
if len(segments) != 3 { | ||
return "", fmt.Errorf( | ||
"invalid CAIP-10 format for blockchainAccountId '%v'. Please refer: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md", | ||
blockchainAccountId, | ||
) | ||
bid, err := types.NewBlockchainId(blockchainAccountId) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Prefix check | ||
if segments[0] == types.EthereumCAIP10Prefix { | ||
return types.EthereumCAIP10Prefix, nil | ||
} else if segments[0] == types.CosmosCAIP10Prefix { | ||
return types.CosmosCAIP10Prefix, nil | ||
} else { | ||
return "", fmt.Errorf( | ||
"unsupported CAIP-10 prefix in blockchainAccountId '%v'. Supported CAIP-10 prefixes: %v", | ||
blockchainAccountId, | ||
types.CAIP10PrefixForEcdsaSecp256k1RecoveryMethod2020, | ||
) | ||
} | ||
return bid.CAIP10Prefix, nil | ||
} |
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