Skip to content

Commit

Permalink
Update interface to split sign/sign-direct
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst committed Nov 9, 2023
1 parent df2f89e commit f06d0f7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 32 deletions.
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ mocks-$(strip $(1))-$(strip $(2)): ${MOCKERY}
${MOCKERY} --case underscore --dir $(1) --name $(2) --outpkg $(3) --output mocks/$(strip $(3))
endef

$(eval $(call makemock, pkg/ethsigner, Wallet, ethsignermocks))
$(eval $(call makemock, pkg/secp256k1, Signer, secp256k1mocks))
$(eval $(call makemock, internal/rpcserver, Server, rpcservermocks))
$(eval $(call makemock, pkg/rpcbackend, Backend, rpcbackendmocks))
$(eval $(call makemock, pkg/ethsigner, Wallet, ethsignermocks))
$(eval $(call makemock, pkg/secp256k1, Signer, secp256k1mocks))
$(eval $(call makemock, pkg/secp256k1, SignerDirect, secp256k1mocks))
$(eval $(call makemock, internal/rpcserver, Server, rpcservermocks))
$(eval $(call makemock, pkg/rpcbackend, Backend, rpcbackendmocks))

firefly-signer: ${GOFILES}
$(VGO) build -o ./firefly-signer -ldflags "-X main.buildDate=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` -X main.buildVersion=$(BUILD_VERSION)" -tags=prod -tags=prod -v ./ffsigner
Expand Down
26 changes: 0 additions & 26 deletions mocks/secp256k1mocks/signer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions mocks/secp256k1mocks/signer_direct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/ethsigner/typed_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type EIP712Result struct {
S ethtypes.HexBytes0xPrefix `ffstruct:"EIP712Result" json:"s"`
}

func SignTypedDataV4(ctx context.Context, signer secp256k1.Signer, payload *eip712.TypedData) (*EIP712Result, error) {
func SignTypedDataV4(ctx context.Context, signer secp256k1.SignerDirect, payload *eip712.TypedData) (*EIP712Result, error) {
encodedData, err := eip712.EncodeTypedDataV4(ctx, payload)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/ethsigner/typed_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestSignTypedDataV4SignFail(t *testing.T) {
PrimaryType: eip712.EIP712Domain,
}

msn := &secp256k1mocks.Signer{}
msn := &secp256k1mocks.SignerDirect{}
msn.On("SignDirect", mock.Anything).Return(nil, fmt.Errorf("pop"))

ctx := context.Background()
Expand Down
3 changes: 3 additions & 0 deletions pkg/secp256k1/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type SignatureData struct {
// Signer is the low level common interface that can be implemented by any module which provides signature capability
type Signer interface {
Sign(message []byte) (*SignatureData, error)
}

type SignerDirect interface {
SignDirect(message []byte) (*SignatureData, error)
}

Expand Down

0 comments on commit f06d0f7

Please sign in to comment.