From 6fd278e5f4ba2a0183f0b524502261c3364afc7b Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Mon, 15 Jan 2024 09:51:38 +0100 Subject: [PATCH] Remove signing-service references --- guard/guard.go | 38 ------------- guard/guard_test.go | 131 -------------------------------------------- wallet.go | 64 ---------------------- 3 files changed, 233 deletions(-) delete mode 100644 guard/guard.go delete mode 100644 guard/guard_test.go diff --git a/guard/guard.go b/guard/guard.go deleted file mode 100644 index e9cb27de..00000000 --- a/guard/guard.go +++ /dev/null @@ -1,38 +0,0 @@ -package guard - -import ( - "context" - "fmt" - "math/big" - - "github.com/0xsequence/ethkit/go-ethereum/common" - "github.com/0xsequence/go-sequence/core" - "github.com/0xsequence/go-sequence/signing_service" -) - -type GuardSigningServiceParams struct { - signing_service.SigningServiceParams -} - -type GuardSigningService struct { - *signing_service.SigningService -} - -func NewGuardSigningService(params GuardSigningServiceParams) *GuardSigningService { - return &GuardSigningService{ - SigningService: signing_service.NewSigningService(params.SigningServiceParams), - } -} - -func (g *GuardSigningService) SignDigest(ctx context.Context, digest common.Hash, optChainID ...*big.Int) ([]byte, core.Signature[core.WalletConfig], error) { - signContext := signing_service.SignContextFromContext(ctx) - if signContext == nil { - return nil, nil, fmt.Errorf("guard: missing sign context") - } - - if len(signContext.Signature) <= 2 { - return nil, nil, core.ErrSigningFunctionNotReady - } - - return g.SigningService.SignDigest(ctx, digest, optChainID...) -} diff --git a/guard/guard_test.go b/guard/guard_test.go deleted file mode 100644 index 1eed129e..00000000 --- a/guard/guard_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package guard - -import ( - "context" - "errors" - "math/big" - "testing" - - "github.com/0xsequence/ethkit/go-ethereum/common" - "github.com/0xsequence/go-sequence" - "github.com/0xsequence/go-sequence/core" - "github.com/0xsequence/go-sequence/signing_service" - proto_signing_service "github.com/0xsequence/go-sequence/signing_service/proto" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" -) - -type MockSigningServiceClient struct { - mock.Mock -} - -func (m *MockSigningServiceClient) Ping(ctx context.Context) (bool, error) { - //TODO implement me - panic("implement me") -} - -func (m *MockSigningServiceClient) Version(ctx context.Context) (*proto_signing_service.Version, error) { - //TODO implement me - panic("implement me") -} - -func (m *MockSigningServiceClient) RuntimeStatus(ctx context.Context) (*proto_signing_service.RuntimeStatus, error) { - //TODO implement me - panic("implement me") -} - -func (m *MockSigningServiceClient) GetSignerConfig(ctx context.Context, signer string) (*proto_signing_service.WalletConfig, error) { - //TODO implement me - panic("implement me") -} - -func (m *MockSigningServiceClient) Sign(ctx context.Context, request *proto_signing_service.SignRequest) (string, error) { - //TODO implement me - panic("implement me") -} - -func (m *MockSigningServiceClient) SignWith(ctx context.Context, signer string, request *proto_signing_service.SignRequest) (string, error) { - args := m.Called(ctx, signer, request) - return args.String(0), args.Error(1) -} - -var _ proto_signing_service.SigningService = &MockSigningServiceClient{} - -func TestGuardSigningServiceSign(t *testing.T) { - mockSigningServiceClient := &MockSigningServiceClient{} - - guardSigningService := NewGuardSigningService(GuardSigningServiceParams{ - SigningServiceParams: signing_service.SigningServiceParams{ - SignerAddress: common.Address{}, - SignerWeight: 0, - Client: mockSigningServiceClient, - }, - }) - - mockSigningServiceClient.On("SignWith", mock.Anything, mock.Anything, mock.Anything).Return("0x01", nil) - - ctx := signing_service.ContextWithSignContext(context.Background(), &proto_signing_service.SignContext{ - Signature: "0x01", - }) - - msg := []byte("hello world") - digest := sequence.MessageDigest(msg) - - sigBytes, _, err := guardSigningService.SignDigest(ctx, digest, big.NewInt(1)) - require.NoError(t, err) - assert.NotEmpty(t, sigBytes) -} - -func TestGuardSigningServiceSignNoSignContext(t *testing.T) { - mockSigningServiceClient := &MockSigningServiceClient{} - - guardSigningService := NewGuardSigningService(GuardSigningServiceParams{ - SigningServiceParams: signing_service.SigningServiceParams{ - SignerAddress: common.Address{}, - SignerWeight: 0, - Client: mockSigningServiceClient, - }, - }) - - msg := []byte("hello world") - digest := sequence.MessageDigest(msg) - - sigBytes, sigTyped, err := guardSigningService.SignDigest(context.Background(), digest, big.NewInt(1)) - require.Error(t, err) - assert.Nil(t, sigBytes) - assert.Nil(t, sigTyped) -} - -func TestGuardSigningServiceSignNotFirst(t *testing.T) { - mockSigningServiceClient := &MockSigningServiceClient{} - - guardSigningService := NewGuardSigningService(GuardSigningServiceParams{ - SigningServiceParams: signing_service.SigningServiceParams{ - SignerAddress: common.Address{}, - SignerWeight: 0, - Client: mockSigningServiceClient, - }, - }) - - ctx := signing_service.ContextWithSignContext(context.Background(), &proto_signing_service.SignContext{}) - - msg := []byte("hello world") - digest := sequence.MessageDigest(msg) - - sigBytes, sigTyped, err := guardSigningService.SignDigest(ctx, digest, big.NewInt(1)) - require.Error(t, err) - require.True(t, errors.Is(err, core.ErrSigningFunctionNotReady)) - assert.Nil(t, sigBytes) - assert.Nil(t, sigTyped) - - ctx = signing_service.ContextWithSignContext(context.Background(), &proto_signing_service.SignContext{ - Signature: "0x", - }) - - sigBytes, sigTyped, err = guardSigningService.SignDigest(ctx, digest, big.NewInt(1)) - require.Error(t, err) - require.True(t, errors.Is(err, core.ErrSigningFunctionNotReady)) - assert.Nil(t, sigBytes) - assert.Nil(t, sigTyped) -} diff --git a/wallet.go b/wallet.go index fcb07860..c8fe3a1a 100644 --- a/wallet.go +++ b/wallet.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" - "github.com/0xsequence/ethkit" "github.com/0xsequence/ethkit/ethcoder" "github.com/0xsequence/ethkit/ethrpc" "github.com/0xsequence/ethkit/ethtxn" @@ -15,8 +14,6 @@ import ( v1 "github.com/0xsequence/go-sequence/core/v1" v2 "github.com/0xsequence/go-sequence/core/v2" "github.com/0xsequence/go-sequence/sessions/proto" - "github.com/0xsequence/go-sequence/signing_service" - proto_signing_service "github.com/0xsequence/go-sequence/signing_service/proto" ) type WalletOptions[C core.WalletConfig] struct { @@ -428,16 +425,6 @@ func (w *Wallet[C]) GetTransactionCount(optBlockNum ...*big.Int) (*big.Int, erro func (w *Wallet[C]) SignMessage(msg []byte) ([]byte, error) { ctx := context.Background() - - signContext := signing_service.SignContextFromContext(ctx) - if signContext == nil { - signContext = &proto_signing_service.SignContext{} - ctx = signing_service.ContextWithSignContext(ctx, signContext) - } - - signContext.WalletAddress = ethkit.ToPtr(w.address.Hex()) - signContext.Message = ethkit.ToPtr(string(msg)) - return w.SignDigest(ctx, MessageDigest(msg)) } @@ -463,17 +450,6 @@ func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChain chainID = w.chainID } - signContext := signing_service.SignContextFromContext(ctx) - if signContext == nil { - signContext = &proto_signing_service.SignContext{} - signContext.WalletAddress = ethkit.ToPtr(w.address.Hex()) - ctx = signing_service.ContextWithSignContext(ctx, signContext) - } - - signContext.PreImage = digest.Hex() - signContext.SigneeWalletAddress = w.address.Hex() - signContext.ChainId = chainID.Uint64() - subDigest, err := SubDigest(chainID, w.Address(), digest) if err != nil { return nil, fmt.Errorf("SignDigest, subDigestOf: %w", err) @@ -488,28 +464,6 @@ func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChain return 0, nil, core.ErrSigningNoSigner } - var signCtx = signing_service.SignContextFromContext(ctx) - if signCtx != nil { - signCtx = signing_service.SignContextCopy(signCtx) - ctx = signing_service.ContextWithSignContext(ctx, signCtx) - } - - // add the signature to the aux data if available - if len(signatures) != 0 { - if signCtx != nil { - signature := signatures[0] - sig, _, _ := w.buildSignature(ctx, func(ctx context.Context, signer common.Address, signatures []core.SignerSignature) (core.SignerSignatureType, []byte, error) { - if signer == signature.Signer { - return signature.Type, signature.Signature, nil - } else { - return 0, nil, core.ErrSigningNoSigner - } - }) - - signCtx.Signature = ethcoder.HexEncode(sig) - } - } - switch signerTyped := signer.(type) { // sequence.Wallet / Signing Service / Guard case DigestSigner: @@ -598,24 +552,6 @@ func (w *Wallet[C]) SignTransactions(ctx context.Context, txns Transactions) (*S return nil, err } - // Set SignContext - signContext := signing_service.SignContextFromContext(ctx) - if signContext == nil { - signContext = &proto_signing_service.SignContext{} - ctx = signing_service.ContextWithSignContext(ctx, signContext) - } - - signContext.Nonce = ethkit.ToPtr(nonce.Uint64()) - signContext.WalletAddress = ethkit.ToPtr(w.Address().Hex()) - signContext.ChainId = w.chainID.Uint64() - - encTxn, err := txns.EncodeRaw() - if err != nil { - return nil, err - } - - signContext.Transactions = ethkit.ToPtr(ethcoder.HexEncode(encTxn)) - // Sign the transactions sig, err := w.SignDigest(ctx, digest) if err != nil {