From 8c0b16af501a028632844d532d207d40cd059492 Mon Sep 17 00:00:00 2001 From: Cedric Cordenier Date: Fri, 23 Jan 2026 14:57:02 +0000 Subject: [PATCH 1/2] Move chaintype package to common --- pkg/chaintype/chaintype.go | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 pkg/chaintype/chaintype.go diff --git a/pkg/chaintype/chaintype.go b/pkg/chaintype/chaintype.go new file mode 100644 index 000000000..1cb8de595 --- /dev/null +++ b/pkg/chaintype/chaintype.go @@ -0,0 +1,120 @@ +package chaintype + +import ( + "fmt" + "slices" + "strings" + + "github.com/pkg/errors" +) + +// ChainType denotes the chain or network to work with +type ChainType string + +const ( + // EVM for Ethereum or other chains supporting the EVM + EVM ChainType = "evm" + // Cosmos for the Cosmos chain + Cosmos ChainType = "cosmos" + // Solana for the Solana chain + Solana ChainType = "solana" + // StarkNet for the StarkNet chain + StarkNet ChainType = "starknet" + // Aptos for the Aptos chain + Aptos ChainType = "aptos" + // Tron for the Tron chain + Tron ChainType = "tron" + // TON for the TON chain + TON ChainType = "ton" + // Sui for the Sui chain + Sui ChainType = "sui" + // Offchain is used by the MultichainKeyringAdapter when we are signing for offchain (eg. for DKG). + Offchain ChainType = "offchain" +) + +type ChainTypes []ChainType + +func (c ChainTypes) String() (out string) { + var sb strings.Builder + for i, chain := range c { + if i != 0 { + sb.WriteString(", ") + } + sb.WriteString(string(chain)) + } + return sb.String() +} + +func NewChainType(typ uint8) (ChainType, error) { + switch typ { + case 1: + return EVM, nil + case 2: + return Solana, nil + case 3: + return Cosmos, nil + case 4: + return StarkNet, nil + case 5: + return Aptos, nil + case 6: + return Tron, nil + case 7: + return TON, nil + case 8: + return Sui, nil + case 9: + return Offchain, nil + default: + return "", fmt.Errorf("unexpected chaintype.ChainType: %#v", typ) + } +} + +func (c ChainType) Type() (uint8, error) { + switch c { + case EVM: + return 1, nil + case Solana: + return 2, nil + case Cosmos: + return 3, nil + case StarkNet: + return 4, nil + case Aptos: + return 5, nil + case Tron: + return 6, nil + case TON: + return 7, nil + case Sui: + return 8, nil + case Offchain: + return 8, nil + default: + return 0, fmt.Errorf("unexpected chaintype.ChainType: %#v", c) + } +} + +// SupportedChainTypes contain all chains that are supported +var SupportedChainTypes = ChainTypes{EVM, Cosmos, Solana, StarkNet, Aptos, Tron, TON, Sui} + +// ErrInvalidChainType is an error to indicate an unsupported chain type +var ErrInvalidChainType error + +func init() { + supported := make([]string, 0, len(SupportedChainTypes)) + for _, chainType := range SupportedChainTypes { + supported = append(supported, fmt.Sprintf(`"%s"`, chainType)) + } + ErrInvalidChainType = fmt.Errorf("valid types include: [%s]", strings.Join(supported, ", ")) +} + +// IsSupportedChainType checks to see if the chain is supported +func IsSupportedChainType(chainType ChainType) bool { + return slices.Contains(SupportedChainTypes, chainType) +} + +// NewErrInvalidChainType returns an error wrapping ErrInvalidChainType for an unsupported chain +func NewErrInvalidChainType(chainType ChainType) error { + return errors.Wrapf(ErrInvalidChainType, `unknown chain type "%s"`, chainType) +} From 1bcf679a6e2973b9c02abdc5fc4c1017de391df4 Mon Sep 17 00:00:00 2001 From: Cedric Cordenier Date: Fri, 23 Jan 2026 14:59:23 +0000 Subject: [PATCH 2/2] Fix bug in original implementation --- go.mod | 2 +- pkg/chaintype/chaintype.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index c18f98adb..bbf85aab5 100644 --- a/go.mod +++ b/go.mod @@ -36,6 +36,7 @@ require ( github.com/mr-tron/base58 v1.2.0 github.com/pelletier/go-toml v1.9.5 github.com/pelletier/go-toml/v2 v2.2.4 + github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.22.0 github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 github.com/scylladb/go-reflectx v1.0.1 @@ -131,7 +132,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/oklog/run v1.2.0 // indirect github.com/pierrec/lz4/v4 v4.1.22 // indirect - github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.65.0 // indirect diff --git a/pkg/chaintype/chaintype.go b/pkg/chaintype/chaintype.go index 1cb8de595..326ea5ada 100644 --- a/pkg/chaintype/chaintype.go +++ b/pkg/chaintype/chaintype.go @@ -89,7 +89,7 @@ func (c ChainType) Type() (uint8, error) { case Sui: return 8, nil case Offchain: - return 8, nil + return 9, nil default: return 0, fmt.Errorf("unexpected chaintype.ChainType: %#v", c) }