@@ -30,6 +30,14 @@ type LoginSchema struct {
3030 Token string `json:"token"`
3131}
3232
33+ type MessageWithoutProverProviderType struct {
34+ Challenge string `json:"challenge"`
35+ ProverVersion string `json:"prover_version"`
36+ ProverName string `json:"prover_name"`
37+ ProverTypes []ProverType `json:"prover_types"`
38+ VKs []string `json:"vks"`
39+ }
40+
3341// Message the login message struct
3442type Message struct {
3543 Challenge string `form:"challenge" json:"challenge" binding:"required"`
@@ -56,7 +64,7 @@ type LoginParameter struct {
5664// SignWithKey auth message with private key and set public key in auth message's Identity
5765func (a * LoginParameter ) SignWithKey (priv * ecdsa.PrivateKey ) error {
5866 // Hash identity content
59- hash , err := a .Message . Hash ( )
67+ hash , err := Hash ( a .Message )
6068 if err != nil {
6169 return err
6270 }
@@ -73,7 +81,14 @@ func (a *LoginParameter) SignWithKey(priv *ecdsa.PrivateKey) error {
7381
7482// Verify verifies the message of auth.
7583func (a * LoginParameter ) Verify () (bool , error ) {
76- hash , err := a .Message .Hash ()
84+ var hash []byte
85+ var err error
86+ if a .Message .ProverProviderType == ProverProviderTypeUndefined {
87+ // for backward compatibility, calculate hash without ProverProviderType
88+ hash , err = Hash (a .Message .ToMessageWithoutProverProviderType ())
89+ } else {
90+ hash , err = Hash (a .Message )
91+ }
7792 if err != nil {
7893 return false , err
7994 }
@@ -88,15 +103,14 @@ func (a *LoginParameter) Verify() (bool, error) {
88103 return isValid , nil
89104}
90105
91- // Hash returns the hash of the auth message, which should be the message used
92- // to construct the Signature.
93- func (i * Message ) Hash () ([]byte , error ) {
94- byt , err := rlp .EncodeToBytes (i )
95- if err != nil {
96- return nil , err
106+ func (m * Message ) ToMessageWithoutProverProviderType () MessageWithoutProverProviderType {
107+ return MessageWithoutProverProviderType {
108+ Challenge : m .Challenge ,
109+ ProverVersion : m .ProverVersion ,
110+ ProverName : m .ProverName ,
111+ ProverTypes : m .ProverTypes ,
112+ VKs : m .VKs ,
97113 }
98- hash := crypto .Keccak256Hash (byt )
99- return hash [:], nil
100114}
101115
102116// DecodeAndUnmarshalPubkey decodes a hex-encoded public key and unmarshal it into an ecdsa.PublicKey
@@ -114,3 +128,14 @@ func (i *Message) DecodeAndUnmarshalPubkey(pubKeyHex string) (*ecdsa.PublicKey,
114128 }
115129 return pubKey , nil
116130}
131+
132+ // Hash returns the hash of the auth message, which should be the message used
133+ // to construct the Signature.
134+ func Hash (i interface {}) ([]byte , error ) {
135+ byt , err := rlp .EncodeToBytes (i )
136+ if err != nil {
137+ return nil , err
138+ }
139+ hash := crypto .Keccak256Hash (byt )
140+ return hash [:], nil
141+ }
0 commit comments