Skip to content

Commit

Permalink
Supports hex and base58 encoded signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode committed Mar 3, 2025
1 parent 33c0a58 commit 1b9e75c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions common/utils/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"

sutils "github.com/CESSProject/cess-go-sdk/utils"
"github.com/mr-tron/base58"
"github.com/vedhavyas/go-subkey/v2/sr25519"
)

Expand All @@ -38,7 +39,38 @@ func VerifySR25519WithPubkey(account, msg, signature string) ([]byte, bool, erro
if err != nil {
return pk, false, err
}

ok := public.Verify([]byte(msg), []byte(signature))
if ok {
return pk, true, nil
}

if strings.HasPrefix(signature, "0x") {
sign, err := hex.DecodeString(signature[2:])
if err == nil {
ok = public.Verify([]byte(msg), sign)
if ok {
return pk, true, nil
}
}
}

sign, err := hex.DecodeString(signature)
if err == nil {
ok = public.Verify([]byte(msg), sign)
if ok {
return pk, true, nil
}
}

sign, err = base58.Decode(signature)
if err == nil {
ok = public.Verify([]byte(msg), sign)
if ok {
return pk, true, nil
}
}

return pk, ok, err
}

Expand Down
2 changes: 1 addition & 1 deletion configs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
// Name space
NameSpace = Name
// version
Version = Name + " " + "v0.4.1 2502141654-1739523271185"
Version = Name + " " + "v0.4.2 2503031110-1740971392384"
// description
Description = "Object storage service based on CESS network"
)

0 comments on commit 1b9e75c

Please sign in to comment.