From 01cb37e82e566c74ea863de8096743efc21f6891 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Mon, 18 Nov 2024 11:06:00 -0500 Subject: [PATCH] refactor: move signer implementation to mpc package --- x/did/types/formatter.go | 1 - x/did/types/{ => mpc}/signer.go | 3 +- x/did/types/pubkey.go | 76 --------------------------------- 3 files changed, 1 insertion(+), 79 deletions(-) delete mode 100644 x/did/types/formatter.go rename x/did/types/{ => mpc}/signer.go (97%) delete mode 100644 x/did/types/pubkey.go diff --git a/x/did/types/formatter.go b/x/did/types/formatter.go deleted file mode 100644 index ab1254f4c..000000000 --- a/x/did/types/formatter.go +++ /dev/null @@ -1 +0,0 @@ -package types diff --git a/x/did/types/signer.go b/x/did/types/mpc/signer.go similarity index 97% rename from x/did/types/signer.go rename to x/did/types/mpc/signer.go index 87f4336a8..ad54e9c3b 100644 --- a/x/did/types/signer.go +++ b/x/did/types/mpc/signer.go @@ -1,4 +1,4 @@ -package types +package mpc import ( "context" @@ -25,6 +25,5 @@ func (s directHandler) GetSignBytes( ChainId: signerData.ChainID, AccountNumber: signerData.AccountNumber, } - return txDoc.Marshal() } diff --git a/x/did/types/pubkey.go b/x/did/types/pubkey.go deleted file mode 100644 index 97d17ee5f..000000000 --- a/x/did/types/pubkey.go +++ /dev/null @@ -1,76 +0,0 @@ -package types - -import ( - "strings" - - didv1 "github.com/onsonr/sonr/api/did/v1" -) - -type PubKeyI interface { - GetRole() string - GetKeyType() string - GetRawKey() *didv1.RawKey - GetJwk() *didv1.JSONWebKey -} - -// PubKey defines a generic pubkey. -type PublicKey interface { - VerifySignature(msg, sig []byte) bool -} - -type PubKeyG[T any] interface { - *T - PublicKey -} - -type pubKeyImpl struct { - decode func(b []byte) (PublicKey, error) - validate func(key PublicKey) error -} - -// func WithSecp256K1PubKey() Option { -// return WithPubKeyWithValidationFunc(func(pt *secp256k1.PubKey) error { -// _, err := dcrd_secp256k1.ParsePubKey(pt.Key) -// return err -// }) -// } -// -// func WithPubKey[T any, PT PubKeyG[T]]() Option { -// return WithPubKeyWithValidationFunc[T, PT](func(_ PT) error { -// return nil -// }) -// } -// -// func WithPubKeyWithValidationFunc[T any, PT PubKeyG[T]](validateFn func(PT) error) Option { -// pkImpl := pubKeyImpl{ -// decode: func(b []byte) (PublicKey, error) { -// key := PT(new(T)) -// err := gogoproto.Unmarshal(b, key) -// if err != nil { -// return nil, err -// } -// return key, nil -// }, -// validate: func(k PublicKey) error { -// concrete, ok := k.(PT) -// if !ok { -// return fmt.Errorf( -// "invalid pubkey type passed for validation, wanted: %T, got: %T", -// concrete, -// k, -// ) -// } -// return validateFn(concrete) -// }, -// } -// return func(a *Account) { -// a.supportedPubKeys[gogoproto.MessageName(PT(new(T)))] = pkImpl -// } -// } -func nameFromTypeURL(url string) string { - name := url - if i := strings.LastIndexByte(url, '/'); i >= 0 { - name = name[i+len("/"):] - } - return name -}