diff --git a/Taskfile.yml b/Taskfile.yml index ccb3ed0f8..a0d7d98c7 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -168,7 +168,7 @@ tasks: test:unit: desc: Run unit tests cmds: - - go test $(go list ./... | grep -v /kwil-db\/test/) -count=1 + - go test $(go list ./... | grep -v /kwil-db\/test/) -tags=ext_test -count=1 test:unit:race: desc: Run unit tests with race diff --git a/cmd/kwil-cli/cmds/utils/message_test.go b/cmd/kwil-cli/cmds/utils/message_test.go index ae7f100e6..6702167ae 100644 --- a/cmd/kwil-cli/cmds/utils/message_test.go +++ b/cmd/kwil-cli/cmds/utils/message_test.go @@ -59,7 +59,7 @@ func getExampleTxQueryResponse() *types.TcTxQueryResponse { secp256k1EpSigBytes, _ := hex.DecodeString(secp256k1EpSigHex) secpSig := auth.Signature{ Signature: secp256k1EpSigBytes, - Type: auth.EthAuth, + Type: auth.EthPersonalSignAuth, } rawPayload := transactions.ActionExecution{ diff --git a/cmd/kwild/main.go b/cmd/kwild/main.go index 77cafed35..44092f10b 100644 --- a/cmd/kwild/main.go +++ b/cmd/kwild/main.go @@ -13,6 +13,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" + + _ "github.com/kwilteam/kwil-db/extensions/auth" ) var ( diff --git a/extensions/README.md b/extensions/README.md new file mode 100644 index 000000000..f9582f607 --- /dev/null +++ b/extensions/README.md @@ -0,0 +1,21 @@ +# Extensions + +Extensions are compile-time loaded pieces of code that impact core `kwild` functionality. Typically, extensions impact core consensus code, and therefore great care should be taken when implementing and choosing to use certain extensions. + +## Interfaces and Drivers + +Extensions can made by implementing a driver for one of many interfaces. These implementations should be registered using Go's `init()` function, which will register the driver when the package is loaded. This is conceptually similar to Go's `database/sql` package, where users can implement custom `database/sql/driver/Driver` implementations. + +## Build Tags + +To include an extension in a build, users should use [Go's build tags](). Users can specify what extensions they include by including their respective tags: + +### Tag Naming + +While you can give any name to your extension's tag, this repo adopts the best practice of prefixing the type of extension with the rest of the name. For example, if we were adding an extension that added standard RSA signatures for authentication, we might name the build tag `auth_rsa`. We could then include this by running: + +```bash +go build -tags auth_rsa +``` + +Additionally, the build tag `ext_test` is added if the extension should be included as a part of `kwild`'s automated testing. diff --git a/extensions/auth/auth.go b/extensions/auth/auth.go new file mode 100644 index 000000000..8832b06d1 --- /dev/null +++ b/extensions/auth/auth.go @@ -0,0 +1 @@ +package auth diff --git a/extensions/auth/ed25519_sha256.go b/extensions/auth/ed25519_sha256.go new file mode 100644 index 000000000..e21d9aae9 --- /dev/null +++ b/extensions/auth/ed25519_sha256.go @@ -0,0 +1,58 @@ +//go:build auth_ed25519_sha256 || ext_test + +package auth + +import ( + "crypto/ed25519" + "crypto/sha256" + "encoding/hex" + "fmt" + + "github.com/kwilteam/kwil-db/pkg/auth" + "github.com/kwilteam/kwil-db/pkg/crypto" +) + +func init() { + err := auth.RegisterAuthenticator(Ed25519Sha256Auth, Ed22519Sha256Authenticator{}) + if err != nil { + panic(err) + } +} + +const ( + // Ed25519Sha256Auth is the authenticator name + // the "nr" suffix is for NEAR, and provides backwards compatibility + Ed25519Sha256Auth = "ed25519_nr" + // ed25519SignatureLength is the expected length of a signature + ed25519SignatureLength = 64 +) + +// Ed22519Sha256Authenticator is an authenticator that applies the sha256 hash to the message +// before verifying the signature. This is a common standard in ecosystems like NEAR. +type Ed22519Sha256Authenticator struct{} + +var _ auth.Authenticator = Ed22519Sha256Authenticator{} + +// Address generates a NEAR implicit address from a public key +func (e Ed22519Sha256Authenticator) Address(publicKey []byte) (string, error) { + if len(publicKey) != ed25519.PublicKeySize { + return "", fmt.Errorf("invalid ed25519 public key size for generating near address: %d", len(publicKey)) + } + + return hex.EncodeToString(publicKey), nil +} + +// Verify verifies the signature against the given public key and data. +func (e Ed22519Sha256Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { + pubkey, err := crypto.Ed25519PublicKeyFromBytes(publicKey) + if err != nil { + return err + } + + if len(signature) != ed25519SignatureLength { + return fmt.Errorf("invalid signature length: expected %d, received %d", ed25519SignatureLength, len(signature)) + } + + hash := sha256.Sum256(msg) + return pubkey.Verify(signature, hash[:]) +} diff --git a/extensions/auth/ed25519_sha256_test.go b/extensions/auth/ed25519_sha256_test.go new file mode 100644 index 000000000..4deda4ec5 --- /dev/null +++ b/extensions/auth/ed25519_sha256_test.go @@ -0,0 +1,27 @@ +//go:build auth_ed25519_sha256 || ext_test + +package auth_test + +import ( + "encoding/hex" + "testing" + + "github.com/kwilteam/kwil-db/extensions/auth" + "github.com/stretchr/testify/require" +) + +func Test_Ed25519Sha256Near(t *testing.T) { + publicKey := "0aa611bf555596912bc6f9a9f169f8785918e7bab9924001895798ff13f05842" + signature := "089bcf52220dad77abc2cfcb1639bcb2944fdf64e0b173f40cd0d144bdbf7808f4eff3716eb3e98ed40be3ab126e1449d5f57efbe5626673059edc90e9cd9801" + message := []byte("foo") + pubKeyBts, err := hex.DecodeString(publicKey) + require.NoError(t, err, "error decode public key") + + signatureBts, err := hex.DecodeString(signature) + require.NoError(t, err, "error decode signature") + + authenticator := auth.Ed22519Sha256Authenticator{} + + err = authenticator.Verify(pubKeyBts, message, signatureBts) + require.NoError(t, err, "error verifying signature") +} diff --git a/pkg/auth/auth_test.go b/pkg/auth/auth_test.go index 04eb72769..b879ec736 100644 --- a/pkg/auth/auth_test.go +++ b/pkg/auth/auth_test.go @@ -33,22 +33,12 @@ func Test_Auth(t *testing.T) { signer: newEthSigner(secp256k1Key), address: "0xc89D42189f0450C2b2c3c61f58Ec5d628176A1E7", }, - { - name: "cometbft secp256k1", - signer: newCometBftSigner(secp256k1Key), - address: "6E741B9E60A1DFB6FE40B53069CFBD00A6C1FC88", - }, { name: "ed25519", signer: newEd25519Signer(ed25519Key), // ed25519 doesn't really have the concept of address, so it is just the hex public key address: "0aa611bf555596912bc6f9a9f169f8785918e7bab9924001895798ff13f05842", }, - { - name: "near", - signer: newNearSigner(ed25519Key), - address: "0aa611bf555596912bc6f9a9f169f8785918e7bab9924001895798ff13f05842", - }, } for _, tc := range testCases { @@ -78,15 +68,6 @@ func newEthSigner(pkey string) *auth.EthPersonalSigner { return &auth.EthPersonalSigner{Secp256k1PrivateKey: *secpKey} } -func newCometBftSigner(pkey string) *auth.CometBftSecp256k1Signer { - secpKey, err := crypto.Secp256k1PrivateKeyFromHex(pkey) - if err != nil { - panic(err) - } - - return &auth.CometBftSecp256k1Signer{Secp256k1PrivateKey: *secpKey} -} - func newEd25519Signer(pkey string) *auth.Ed25519Signer { edKey, err := crypto.Ed25519PrivateKeyFromHex(pkey) if err != nil { @@ -95,12 +76,3 @@ func newEd25519Signer(pkey string) *auth.Ed25519Signer { return &auth.Ed25519Signer{Ed25519PrivateKey: *edKey} } - -func newNearSigner(pkey string) *auth.NearSigner { - edKey, err := crypto.Ed25519PrivateKeyFromHex(pkey) - if err != nil { - panic(err) - } - - return &auth.NearSigner{Ed25519PrivateKey: *edKey} -} diff --git a/pkg/auth/defaults.go b/pkg/auth/defaults.go deleted file mode 100644 index 9159a8996..000000000 --- a/pkg/auth/defaults.go +++ /dev/null @@ -1,214 +0,0 @@ -package auth - -import ( - "crypto/sha256" - "encoding/hex" - "errors" - "fmt" - - ethAccount "github.com/ethereum/go-ethereum/accounts" - "github.com/kwilteam/kwil-db/pkg/crypto" - - "crypto/ed25519" - - cometCrypto "github.com/cometbft/cometbft/crypto" - ethCrypto "github.com/ethereum/go-ethereum/crypto" - "golang.org/x/crypto/ripemd160" //nolint: staticcheck // necessary for Bitcoin address format -) - -// init registers default authenticators -func init() { - if err := errors.Join( - RegisterAuthenticator(EthAuth, ethSecp256k1Authenticator{}), - RegisterAuthenticator(CometBftSecp256k1Auth, cometBftSecp256k1Authenticator{}), - RegisterAuthenticator(Ed25519Auth, ed25519Authenticator{}), - RegisterAuthenticator(NearAuth, nearAuthenticator{}), - ); err != nil { - panic(err) - } -} - -var ( - ErrInvalidSignatureLength = errors.New("invalid signature length") -) - -// newInvalidSignatureLength returns an error for invalid signature length. -// It includes the expected and received length. -func newInvalidSignatureLength(expected, received int) error { - return fmt.Errorf("%w: expected %d, received %d", ErrInvalidSignatureLength, expected, received) -} - -// constants for eth personal sign -const ( - // ethAuth is the authenticator name - EthAuth = "secp256k1_ep" - // ethPersonalSignSignatureLength is the expected length of a signature - ethPersonalSignSignatureLength = 65 -) - -// ethSecp256k1Authenticator is an authenticator for Ethereum secp256k1 keys -// It is provided as a default authenticator -type ethSecp256k1Authenticator struct{} - -var _ Authenticator = ethSecp256k1Authenticator{} - -// Address generates an ethereum address from a public key -func (e ethSecp256k1Authenticator) Address(publicKey []byte) (string, error) { - ethKey, err := ethCrypto.UnmarshalPubkey(publicKey) - if err != nil { - return "", err - } - - return ethCrypto.PubkeyToAddress(*ethKey).Hex(), nil -} - -// Verify verifies applies the Ethereum TextHash digest and verifies the signature -func (e ethSecp256k1Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { - pubkey, err := crypto.Secp256k1PublicKeyFromBytes(publicKey) - if err != nil { - return err - } - - // signature is 65 bytes, [R || S || V] format - if len(signature) != ethPersonalSignSignatureLength { - return newInvalidSignatureLength(ethPersonalSignSignatureLength, len(signature)) - } - hash := ethAccount.TextHash(msg) - - // trim off the recovery id - return pubkey.Verify(signature, hash) -} - -// cometBftSecp245k1 constants -const ( - // CometBftSecp256k1Auth is the authenticator name - CometBftSecp256k1Auth = "secp256k1_cmt" - // cometBftSecp256k1SignatureLength is the expected length of a signature - cometBftSecp256k1SignatureLength = 64 -) - -// cometBftSecp256k1Authenticator is an authenticator for CometBFT secp256k1 keys -type cometBftSecp256k1Authenticator struct{} - -var _ Authenticator = cometBftSecp256k1Authenticator{} - -// Address generates a CometBFT address from a public key -func (e cometBftSecp256k1Authenticator) Address(publicKey []byte) (string, error) { - compressed, err := getCompressed(publicKey) - if err != nil { - return "", err - } - - sha := sha256.Sum256(compressed[:]) - hasherRIPEMD160 := ripemd160.New() - _, err = hasherRIPEMD160.Write(sha[:]) - if err != nil { - return "", err - } - - return cometCrypto.Address(hasherRIPEMD160.Sum(nil)).String(), nil -} - -// Verify verifies applies a sha256 digest and verifies the signature -func (e cometBftSecp256k1Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { - pubkey, err := crypto.Secp256k1PublicKeyFromBytes(publicKey) - if err != nil { - return err - } - - if len(signature) != cometBftSecp256k1SignatureLength { - return newInvalidSignatureLength(cometBftSecp256k1SignatureLength, len(signature)) - } - - hash := sha256.Sum256(msg) - return pubkey.Verify(signature, hash[:]) -} - -// ed25519 constants -const ( - // Ed25519Auth is the authenticator name - Ed25519Auth = "ed25519" - // ed25519SignatureLength is the expected length of a signature - ed25519SignatureLength = 64 -) - -// ed25519Authenticator is an authenticator for ed25519 keys -type ed25519Authenticator struct{} - -var _ Authenticator = ed25519Authenticator{} - -// Address simply returns the public key as the address -func (e ed25519Authenticator) Address(publicKey []byte) (string, error) { - if len(publicKey) != ed25519.PublicKeySize { - return "", fmt.Errorf("invalid ed25519 public key size: %d", len(publicKey)) - } - - return hex.EncodeToString(publicKey), nil -} - -// Verify verifies the signature against the given public key and data. -func (e ed25519Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { - pubkey, err := crypto.Ed25519PublicKeyFromBytes(publicKey) - if err != nil { - return err - } - - if len(signature) != ed25519SignatureLength { - return newInvalidSignatureLength(ed25519SignatureLength, len(signature)) - } - - return pubkey.Verify(signature, msg) -} - -const ( - // NearAuth is the authenticator name - NearAuth = "ed25519_nr" - // Near uses the same signature length as ed25519 -) - -// nearAuthenticator is an authenticator for NEAR keys -type nearAuthenticator struct{} - -var _ Authenticator = nearAuthenticator{} - -// Address generates a NEAR address from a public key -func (e nearAuthenticator) Address(publicKey []byte) (string, error) { - if len(publicKey) != ed25519.PublicKeySize { - return "", fmt.Errorf("invalid ed25519 public key size for generating near address: %d", len(publicKey)) - } - - return hex.EncodeToString(publicKey), nil -} - -// Verify verifies the signature against the given public key and data. -func (e nearAuthenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { - pubkey, err := crypto.Ed25519PublicKeyFromBytes(publicKey) - if err != nil { - return err - } - - if len(signature) != ed25519SignatureLength { - return newInvalidSignatureLength(ed25519SignatureLength, len(signature)) - } - - hash := sha256.Sum256(msg) - return pubkey.Verify(signature, hash[:]) -} - -// getCompressed returns the compressed bytes of the secp256k1 public key. -// if it is already compressed, it returns the original bytes. -func getCompressed(pubkey []byte) ([]byte, error) { - switch len(pubkey) { - default: - return nil, fmt.Errorf("invalid secp256k1 public key size: %d", len(pubkey)) - case crypto.Secp256k1CompressedPublicKeySize: - return pubkey, nil - case crypto.Secp256k1UncompressedPublicKeySize: - ecdsaPubKey, err := ethCrypto.UnmarshalPubkey(pubkey) - if err != nil { - return nil, err - } - - return ethCrypto.CompressPubkey(ecdsaPubKey), nil - } -} diff --git a/pkg/auth/ed25519.go b/pkg/auth/ed25519.go new file mode 100644 index 000000000..16d190e55 --- /dev/null +++ b/pkg/auth/ed25519.go @@ -0,0 +1,54 @@ +package auth + +// ed25519 is a standard signature scheme that uses the ed25519 curve, and does not have a build tag + +import ( + "crypto/ed25519" + "encoding/hex" + "fmt" + + "github.com/kwilteam/kwil-db/pkg/crypto" +) + +func init() { + err := RegisterAuthenticator(Ed25519Auth, Ed25519Authenticator{}) + if err != nil { + panic(err) + } +} + +// ed25519 constants +const ( + // using Ed25519Auth for the authenticator name + + // ed25519SignatureLength is the expected length of a signature + ed25519SignatureLength = 64 +) + +// Ed25519Authenticator is an authenticator for ed25519 keys +type Ed25519Authenticator struct{} + +var _ Authenticator = Ed25519Authenticator{} + +// Address simply returns the public key as the address +func (e Ed25519Authenticator) Address(publicKey []byte) (string, error) { + if len(publicKey) != ed25519.PublicKeySize { + return "", fmt.Errorf("invalid ed25519 public key size: %d", len(publicKey)) + } + + return hex.EncodeToString(publicKey), nil +} + +// Verify verifies the signature against the given public key and data. +func (e Ed25519Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { + pubkey, err := crypto.Ed25519PublicKeyFromBytes(publicKey) + if err != nil { + return err + } + + if len(signature) != ed25519SignatureLength { + return fmt.Errorf("invalid signature length: expected %d, received %d", ed25519SignatureLength, len(signature)) + } + + return pubkey.Verify(signature, msg) +} diff --git a/pkg/auth/eth_personal_sign.go b/pkg/auth/eth_personal_sign.go new file mode 100644 index 000000000..9e607825c --- /dev/null +++ b/pkg/auth/eth_personal_sign.go @@ -0,0 +1,59 @@ +package auth + +// eth_personal_sign is a default signer, and does not include a build tag + +import ( + "fmt" + + "github.com/kwilteam/kwil-db/pkg/crypto" + + ethAccounts "github.com/ethereum/go-ethereum/accounts" + ethCrypto "github.com/ethereum/go-ethereum/crypto" +) + +func init() { + err := RegisterAuthenticator(EthPersonalSignAuth, EthSecp256k1Authenticator{}) + if err != nil { + panic(err) + } +} + +const ( + // using EthPersonalSignAuth for the authenticator name + + // ethPersonalSignSignatureLength is the expected length of a signature + ethPersonalSignSignatureLength = 65 +) + +// EthSecp256k1Authenticator is an authenticator for Ethereum secp256k1 keys +// It is provided as a default authenticator +type EthSecp256k1Authenticator struct{} + +var _ Authenticator = EthSecp256k1Authenticator{} + +// Address generates an ethereum address from a public key +func (e EthSecp256k1Authenticator) Address(publicKey []byte) (string, error) { + ethKey, err := ethCrypto.UnmarshalPubkey(publicKey) + if err != nil { + return "", err + } + + return ethCrypto.PubkeyToAddress(*ethKey).Hex(), nil +} + +// Verify verifies applies the Ethereum TextHash digest and verifies the signature +func (e EthSecp256k1Authenticator) Verify(publicKey []byte, msg []byte, signature []byte) error { + pubkey, err := crypto.Secp256k1PublicKeyFromBytes(publicKey) + if err != nil { + return err + } + + // signature is 65 bytes, [R || S || V] format + if len(signature) != ethPersonalSignSignatureLength { + return fmt.Errorf("invalid signature length: expected %d, received %d", ethPersonalSignSignatureLength, len(signature)) + } + hash := ethAccounts.TextHash(msg) + + // trim off the recovery id + return pubkey.Verify(signature, hash) +} diff --git a/pkg/auth/signer.go b/pkg/auth/signer.go index d643b3fb5..202272a4b 100644 --- a/pkg/auth/signer.go +++ b/pkg/auth/signer.go @@ -1,12 +1,15 @@ package auth import ( - "crypto/sha256" - ethAccount "github.com/ethereum/go-ethereum/accounts" "github.com/kwilteam/kwil-db/pkg/crypto" ) +const ( + EthPersonalSignAuth = "secp256k1_ep" + Ed25519Auth = "ed25519" +) + // Signature is a signature with a designated AuthType, which should // be used to determine how to verify the signature. // It seems a bit weird to have a field "Signature" inside a struct called "Signature", @@ -61,7 +64,7 @@ func (e *EthPersonalSigner) Sign(msg []byte) (*Signature, error) { return &Signature{ Signature: signatureBts, - Type: EthAuth, + Type: EthPersonalSignAuth, }, nil } @@ -70,35 +73,6 @@ func (e *EthPersonalSigner) PublicKey() []byte { return e.Secp256k1PrivateKey.PubKey().Bytes() } -// CometBftSecp256k1Signer is a signer that signs messages using the -// secp256k1 curve, using CometBFT's signature scheme. -type CometBftSecp256k1Signer struct { - crypto.Secp256k1PrivateKey -} - -var _ Signer = (*CometBftSecp256k1Signer)(nil) - -// Sign signs the given message(not hashed) according to cometbft's signature scheme. -// It use sha256 to hash the message. -// The signature is in [R || S] format, 64 bytes. -func (c *CometBftSecp256k1Signer) Sign(msg []byte) (*Signature, error) { - hash := sha256.Sum256(msg) - signatureBts, err := c.Secp256k1PrivateKey.Sign(hash[:]) - if err != nil { - return nil, err - } - - return &Signature{ - Signature: signatureBts, - Type: CometBftSecp256k1Auth, - }, nil -} - -// PublicKey returns the public key of the signer -func (e *CometBftSecp256k1Signer) PublicKey() []byte { - return e.Secp256k1PrivateKey.PubKey().Bytes() -} - // Ed25519Signer is a signer that signs messages using the // ed25519 curve, using the standard signature scheme. type Ed25519Signer struct { @@ -125,32 +99,3 @@ func (e *Ed25519Signer) Sign(msg []byte) (*Signature, error) { func (e *Ed25519Signer) PublicKey() []byte { return e.Ed25519PrivateKey.PubKey().Bytes() } - -// NearSigner is a signer that signs messages using the -// ed25519 curve, using the near signature scheme. -type NearSigner struct { - crypto.Ed25519PrivateKey -} - -var _ Signer = (*NearSigner)(nil) - -// Sign signs the given message(not hashed) according to Near's signature scheme. -// It first hash the message with sha256, then sign the hash. -// It returns 64 bytes signature. -func (n *NearSigner) Sign(msg []byte) (*Signature, error) { - hash := sha256.Sum256(msg) - signatureBts, err := n.Ed25519PrivateKey.Sign(hash[:]) - if err != nil { - return nil, err - } - - return &Signature{ - Signature: signatureBts, - Type: NearAuth, - }, nil -} - -// PublicKey returns the public key of the signer -func (e *NearSigner) PublicKey() []byte { - return e.Ed25519PrivateKey.PubKey().Bytes() -} diff --git a/pkg/engine/dataset/dataset_test.go b/pkg/engine/dataset/dataset_test.go index c95fd472d..599dab2a4 100644 --- a/pkg/engine/dataset/dataset_test.go +++ b/pkg/engine/dataset/dataset_test.go @@ -446,7 +446,7 @@ type testUserIdentifier struct { func (t *testUserIdentifier) Bytes() []byte { bts, err := (&types.User{ PublicKey: t.pk.PubKey().Bytes(), - AuthType: auth.EthAuth, + AuthType: auth.EthPersonalSignAuth, }).MarshalBinary() if err != nil { panic(err) diff --git a/pkg/engine/engine_test.go b/pkg/engine/engine_test.go index 0475c517c..348eb9faf 100644 --- a/pkg/engine/engine_test.go +++ b/pkg/engine/engine_test.go @@ -28,7 +28,7 @@ func newTestUser() *types.User { return &types.User{ PublicKey: pk.PubKey().Bytes(), - AuthType: auth.EthAuth, + AuthType: auth.EthPersonalSignAuth, } } diff --git a/pkg/engine/master/master_test.go b/pkg/engine/master/master_test.go index c16cd8e83..7b5813362 100644 --- a/pkg/engine/master/master_test.go +++ b/pkg/engine/master/master_test.go @@ -26,7 +26,7 @@ func Test_Master(t *testing.T) { ident := &types.User{ PublicKey: pk.PubKey().Bytes(), - AuthType: auth.EthAuth, + AuthType: auth.EthPersonalSignAuth, } pk2, err := crypto.Secp256k1PrivateKeyFromHex(testPrivateKey2) @@ -36,7 +36,7 @@ func Test_Master(t *testing.T) { ident2 := &types.User{ PublicKey: pk2.PubKey().Bytes(), - AuthType: auth.EthAuth, + AuthType: auth.EthPersonalSignAuth, } tests := []struct { diff --git a/pkg/transactions/message_test.go b/pkg/transactions/message_test.go index 9fdd4590a..0e1f47b3a 100644 --- a/pkg/transactions/message_test.go +++ b/pkg/transactions/message_test.go @@ -100,30 +100,9 @@ func TestCallMessage_Sign(t *testing.T) { expectPersonalSignConcatSigBytes, _ := hex.DecodeString(expectPersonalSignConcatSigHex) expectPersonalSignConcatSig := &auth.Signature{ Signature: expectPersonalSignConcatSigBytes, - Type: auth.EthAuth, + Type: auth.EthPersonalSignAuth, } - // TODO: add test case for cometbft - //cometbftSigner := crypto.NewCometbftSecp256k1Signer(secp256k1PrivateKey) - //expectCometbftConcatSigHex - - //expectEip721SigHex := "" - //// - // ed25519 - ed25519PvKeyHex := "7c67e60fce0c403ff40193a3128e5f3d8c2139aed36d76d7b5f1e70ec19c43f00aa611bf555596912bc6f9a9f169f8785918e7bab9924001895798ff13f05842" - ed25519PrivateKey, err := crypto.Ed25519PrivateKeyFromHex(ed25519PvKeyHex) - require.NoError(t, err, "error parse ed25519PvKeyHex") - - nearSigner := auth.NearSigner{Ed25519PrivateKey: *ed25519PrivateKey} - - expectNearConcatSigHex := "fd5def5115b229314006acbf0ec7eac5f39af3bea40b55423a9808203db5b0f717c17c641b82cba49d2bcb39436b3b788c839245402de78cd2a674692d4d4508" - expectNearConcatSigBytes, _ := hex.DecodeString(expectNearConcatSigHex) - expectNearConcatSig := &auth.Signature{ - Signature: expectNearConcatSigBytes, - Type: auth.NearAuth, - } - //// - callPayload := transactions.ActionCall{ DBID: "xf617af1ca774ebbd6d23e8fe12c56d41d25a22d81e88f67c6c6ee0d4", Action: "action0", @@ -159,14 +138,6 @@ func TestCallMessage_Sign(t *testing.T) { }, wantSig: expectPersonalSignConcatSig, }, - { - name: "near concat string", - args: args{ - mst: transactions.SignedMsgConcat, - signer: &nearSigner, - }, - wantSig: expectNearConcatSig, - }, } for _, tt := range tests { diff --git a/pkg/transactions/transaction_test.go b/pkg/transactions/transaction_test.go index 86097f064..4ada6c195 100644 --- a/pkg/transactions/transaction_test.go +++ b/pkg/transactions/transaction_test.go @@ -33,7 +33,7 @@ func Test_TransactionMarshal(t *testing.T) { tx := &transactions.Transaction{ Signature: &auth.Signature{ Signature: []byte("signature"), - Type: auth.CometBftSecp256k1Auth, + Type: auth.EthPersonalSignAuth, }, Body: &transactions.TransactionBody{ Payload: []byte("payload"), @@ -67,30 +67,9 @@ func TestTransaction_Sign(t *testing.T) { expectPersonalSignConcatSigBytes, _ := hex.DecodeString(expectPersonalSignConcatSigHex) expectPersonalSignConcatSig := &auth.Signature{ Signature: expectPersonalSignConcatSigBytes, - Type: auth.EthAuth, + Type: auth.EthPersonalSignAuth, } - // TODO: add test case for cometbft - //cometbftSigner := crypto.NewCometbftSecp256k1Signer(secp256k1PrivateKey) - //expectCometbftConcatSigHex - - //expectEip721SigHex := "" - //// - // ed25519 - ed25519PvKeyHex := "7c67e60fce0c403ff40193a3128e5f3d8c2139aed36d76d7b5f1e70ec19c43f00aa611bf555596912bc6f9a9f169f8785918e7bab9924001895798ff13f05842" - ed25519PrivateKey, err := crypto.Ed25519PrivateKeyFromHex(ed25519PvKeyHex) - require.NoError(t, err, "error parse ed25519PvKeyHex") - - nearSigner := auth.NearSigner{Ed25519PrivateKey: *ed25519PrivateKey} - - expectNearConcatSigHex := "b72f815bcb5a7126fe54cd8d77210209249b1c11087a4b4601c61814911fac7f4a921f1c37991408251a04891a5e10ecc1be4535124a3827f22660adbec0590c" - expectNearConcatSigBytes, _ := hex.DecodeString(expectNearConcatSigHex) - expectNearConcatSig := &auth.Signature{ - Signature: expectNearConcatSigBytes, - Type: auth.NearAuth, - } - //// - rawPayload := transactions.ActionExecution{ DBID: "xf617af1ca774ebbd6d23e8fe12c56d41d25a22d81e88f67c6c6ee0d4", Action: "create_user", @@ -128,15 +107,6 @@ func TestTransaction_Sign(t *testing.T) { }, wantSig: expectPersonalSignConcatSig, }, - { - name: "near concat string", - args: args{ - mst: transactions.SignedMsgConcat, - signer: &nearSigner, - }, - wantSig: expectNearConcatSig, - }, - //{}, // eth eip712 } for _, tt := range tests { t.Run(tt.name, func(t1 *testing.T) {