diff --git a/common/version/version.go b/common/version/version.go index 2807605089..ab95352e44 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.4.39" +var tag = "v4.4.40" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/coordinator/internal/controller/api/auth.go b/coordinator/internal/controller/api/auth.go index 205807e676..dc4759524f 100644 --- a/coordinator/internal/controller/api/auth.go +++ b/coordinator/internal/controller/api/auth.go @@ -6,6 +6,7 @@ import ( jwt "github.com/appleboy/gin-jwt/v2" "github.com/gin-gonic/gin" + "github.com/scroll-tech/go-ethereum/log" "gorm.io/gorm" "scroll-tech/coordinator/internal/config" @@ -58,8 +59,19 @@ func (a *AuthController) PayloadFunc(data interface{}) jwt.MapClaims { return jwt.MapClaims{} } + publicKey := v.PublicKey + if publicKey == "" { + var err error + publicKey, err = v.RecoverPublicKeyFromSignature() + if err != nil { + // do not handle error here since already called v.Verify() beforehands so there should be no error + // add log just in case some error happens + log.Error("impossible path: failed to recover public key from signature", "error", err.Error()) + } + } + return jwt.MapClaims{ - types.PublicKey: v.PublicKey, + types.PublicKey: publicKey, types.ProverName: v.Message.ProverName, types.ProverVersion: v.Message.ProverVersion, } diff --git a/coordinator/internal/types/auth.go b/coordinator/internal/types/auth.go index faa980fa8a..97868ec36e 100644 --- a/coordinator/internal/types/auth.go +++ b/coordinator/internal/types/auth.go @@ -77,6 +77,22 @@ func (a *LoginParameter) Verify() (bool, error) { return isValid, nil } +// RecoverPublicKeyFromSignature get public key from signature. +// This method is for pre-darwin's compatible. +func (a *LoginParameter) RecoverPublicKeyFromSignature() (string, error) { + hash, err := a.Message.Hash() + if err != nil { + return "", err + } + sig := common.FromHex(a.Signature) + // recover public key + pk, err := crypto.SigToPub(hash, sig) + if err != nil { + return "", err + } + return common.Bytes2Hex(crypto.CompressPubkey(pk)), nil +} + // Hash returns the hash of the auth message, which should be the message used // to construct the Signature. func (i *Message) Hash() ([]byte, error) {