From 6befcf63d642c2e37b66bac560a74c8e68b1be4e Mon Sep 17 00:00:00 2001 From: Gautam Botrel Date: Wed, 6 Dec 2023 15:52:35 -0600 Subject: [PATCH] feat: added ecc.IDFromString() method --- ecc/ecc.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ecc/ecc.go b/ecc/ecc.go index 5fa1bd961..a9c4b6dfb 100644 --- a/ecc/ecc.go +++ b/ecc/ecc.go @@ -27,6 +27,7 @@ limitations under the License. package ecc import ( + "errors" "math/big" "strings" @@ -57,6 +58,15 @@ func Implemented() []ID { return []ID{BN254, BLS12_377, BLS12_381, BW6_761, BLS24_315, BW6_633, BLS12_378, BW6_756, BLS24_317, STARK_CURVE, SECP256K1} } +func IDFromString(s string) (ID, error) { + for _, id := range Implemented() { + if strings.ToLower(s) == id.String() { + return id, nil + } + } + return UNKNOWN, errors.New("unknown curve ID") +} + func (id ID) String() string { cfg := id.config() return strings.ToLower(cfg.EnumID)