From af391da9df57fff321f04e18271a44db45a05681 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Sat, 29 Sep 2018 17:16:34 +0300 Subject: [PATCH] Added ecRecover method in the clef api --- signer/core/api.go | 3 ++- signer/core/auditlog.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/signer/core/api.go b/signer/core/api.go index 900392e822..a5c5900a10 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -52,6 +52,8 @@ type ExternalAPI interface { SignTransaction(ctx context.Context, args SendTxArgs, methodSelector *string) (*ethapi.SignTransactionResult, error) // SignData - request to sign the given data (plus prefix) SignData(ctx context.Context, contentType string, addr common.MixedcaseAddress, data hexutil.Bytes) (hexutil.Bytes, error) + // EcRecover - recover public key from given message and signature + EcRecover(ctx context.Context, contentType string, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error) // Export - request to export an account Export(ctx context.Context, addr common.Address) (json.RawMessage, error) // Import - request to import an account @@ -690,7 +692,6 @@ func SignDataPlain(data []byte) ([]byte, string) { // Determines the content type and then recovers the address associated with the given sig func (api *SignerAPI) EcRecover(ctx context.Context, contentType string, data, sig hexutil.Bytes) (common.Address, error) { - fmt.Println("Effing Muffins") mediaType, _, err := mime.ParseMediaType(contentType) if err != nil { return common.Address{}, err diff --git a/signer/core/auditlog.go b/signer/core/auditlog.go index a0fb1b0767..ac16b144d0 100644 --- a/signer/core/auditlog.go +++ b/signer/core/auditlog.go @@ -71,6 +71,14 @@ func (l *AuditLogger) SignData(ctx context.Context, contentType string, addr com return b, e } +func (l *AuditLogger) EcRecover(ctx context.Context, contentType string, data hexutil.Bytes, sig hexutil.Bytes) (common.Address, error) { + l.log.Info("EcRecover", "type", "request", "metadata", MetadataFromContext(ctx).String(), + "data", common.Bytes2Hex(data), "sig", common.Bytes2Hex(sig), "content-type", contentType) + b, e := l.api.EcRecover(ctx, contentType, data, sig) + l.log.Info("EcRecover", "type", "response", "address", b.String(), "error", e) + return b, e +} + func (l *AuditLogger) Export(ctx context.Context, addr common.Address) (json.RawMessage, error) { l.log.Info("Export", "type", "request", "metadata", MetadataFromContext(ctx).String(), "addr", addr.Hex())