mirror of https://github.com/status-im/go-waku.git
fix(library): signature and pubkey empty string
This commit is contained in:
parent
caf6d01333
commit
3a7f2608b3
|
@ -335,6 +335,19 @@ func unmarshalPubkey(pub []byte) (ecdsa.PublicKey, error) {
|
||||||
return ecdsa.PublicKey{Curve: secp256k1.S256(), X: x, Y: y}, nil
|
return ecdsa.PublicKey{Curve: secp256k1.S256(), X: x, Y: y}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extractPubKeyAndSignature(payload *node.DecodedPayload) (pubkey string, signature string) {
|
||||||
|
pkBytes := crypto.FromECDSAPub(payload.PubKey)
|
||||||
|
if len(pkBytes) != 0 {
|
||||||
|
pubkey = hexutil.Encode(pkBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(payload.Signature) != 0 {
|
||||||
|
signature = hexutil.Encode(payload.Signature)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func DecodeSymmetric(messageJSON string, symmetricKey string) string {
|
func DecodeSymmetric(messageJSON string, symmetricKey string) string {
|
||||||
var msg pb.WakuMessage
|
var msg pb.WakuMessage
|
||||||
err := json.Unmarshal([]byte(messageJSON), &msg)
|
err := json.Unmarshal([]byte(messageJSON), &msg)
|
||||||
|
@ -362,14 +375,16 @@ func DecodeSymmetric(messageJSON string, symmetricKey string) string {
|
||||||
return MakeJSONResponse(err)
|
return MakeJSONResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pubkey, signature := extractPubKeyAndSignature(payload)
|
||||||
|
|
||||||
response := struct {
|
response := struct {
|
||||||
PubKey string `json:"pubkey"`
|
PubKey string `json:"pubkey,omitempty"`
|
||||||
Signature string `json:"signature"`
|
Signature string `json:"signature,omitempty"`
|
||||||
Data []byte `json:"data"`
|
Data []byte `json:"data"`
|
||||||
Padding []byte `json:"padding"`
|
Padding []byte `json:"padding"`
|
||||||
}{
|
}{
|
||||||
PubKey: hexutil.Encode(crypto.FromECDSAPub(payload.PubKey)),
|
PubKey: pubkey,
|
||||||
Signature: hexutil.Encode(payload.Signature),
|
Signature: signature,
|
||||||
Data: payload.Data,
|
Data: payload.Data,
|
||||||
Padding: payload.Padding,
|
Padding: payload.Padding,
|
||||||
}
|
}
|
||||||
|
@ -409,14 +424,16 @@ func DecodeAsymmetric(messageJSON string, privateKey string) string {
|
||||||
return MakeJSONResponse(err)
|
return MakeJSONResponse(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pubkey, signature := extractPubKeyAndSignature(payload)
|
||||||
|
|
||||||
response := struct {
|
response := struct {
|
||||||
PubKey string `json:"pubkey"`
|
PubKey string `json:"pubkey,omitempty"`
|
||||||
Signature string `json:"signature"`
|
Signature string `json:"signature,omitempty"`
|
||||||
Data []byte `json:"data"`
|
Data []byte `json:"data"`
|
||||||
Padding []byte `json:"padding"`
|
Padding []byte `json:"padding"`
|
||||||
}{
|
}{
|
||||||
PubKey: hexutil.Encode(crypto.FromECDSAPub(payload.PubKey)),
|
PubKey: pubkey,
|
||||||
Signature: hexutil.Encode(payload.Signature),
|
Signature: signature,
|
||||||
Data: payload.Data,
|
Data: payload.Data,
|
||||||
Padding: payload.Padding,
|
Padding: payload.Padding,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue