Skip to content

Commit

Permalink
fix: secp256r1 json missing quotes (backport cosmos#20060) (cosmos#20070
Browse files Browse the repository at this point in the history
)

Co-authored-by: Facundo Medica <[email protected]>
  • Loading branch information
2 people authored and MSalopek committed Apr 17, 2024
1 parent dc17934 commit fbeaf8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crypto/keys/secp256r1/privkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ func (sk ecdsaSK) Marshal() ([]byte, error) {
// MarshalJSON implements customProtobufType.
func (sk ecdsaSK) MarshalJSON() ([]byte, error) {
b64 := base64.StdEncoding.EncodeToString(sk.PrivKey.Bytes())
return []byte(b64), nil
return []byte("\"" + b64 + "\""), nil
}

// UnmarshalJSON implements customProtobufType.
func (sk *ecdsaSK) UnmarshalJSON(data []byte) error {
bz, err := base64.StdEncoding.DecodeString(string(data))
bz, err := base64.StdEncoding.DecodeString(string(data[1 : len(data)-1]))
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions crypto/keys/secp256r1/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ func (pk ecdsaPK) Marshal() ([]byte, error) {
// MarshalJSON implements customProtobufType.
func (pk ecdsaPK) MarshalJSON() ([]byte, error) {
b64 := base64.StdEncoding.EncodeToString(pk.PubKey.Bytes())
return []byte(b64), nil
return []byte("\"" + b64 + "\""), nil
}

// UnmarshalJSON implements customProtobufType.
func (pk *ecdsaPK) UnmarshalJSON(data []byte) error {
bz, err := base64.StdEncoding.DecodeString(string(data))
// the string is quoted so we need to remove them
bz, err := base64.StdEncoding.DecodeString(string(data[1 : len(data)-1]))
if err != nil {
return err
}
Expand Down

0 comments on commit fbeaf8f

Please sign in to comment.