-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1910af
commit 51e14c5
Showing
3 changed files
with
101 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
listener/internal/api/validation/DecodeAndValidateRequests.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package validation | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
|
||
"github.com/dappnode/validator-monitoring/listener/internal/api/types" | ||
"github.com/dappnode/validator-monitoring/listener/internal/logger" | ||
) | ||
|
||
func DecodeAndValidateRequests(requests []types.SignatureRequest) ([]types.SignatureRequestDecoded, error) { | ||
var validRequests []types.SignatureRequestDecoded | ||
for _, req := range requests { | ||
if req.Network == "" || req.Tag == "" || req.Signature == "" || req.Payload == "" || req.Pubkey == "" { | ||
logger.Debug("Skipping invalid signature from request, missing required fields") | ||
continue | ||
} | ||
if !IsValidPayloadFormat(req.Signature) { | ||
logger.Debug("Skipping invalid signature from request, invalid signature format: " + req.Signature) | ||
continue | ||
} | ||
decodedBytes, err := base64.StdEncoding.DecodeString(req.Payload) | ||
if err != nil { | ||
logger.Error("Failed to decode BASE64 payload from request: " + err.Error()) | ||
continue | ||
} | ||
var decodedPayload types.DecodedPayload | ||
if err := json.Unmarshal(decodedBytes, &decodedPayload); err != nil { | ||
logger.Error("Failed to decode JSON payload from request: " + err.Error()) | ||
continue | ||
} | ||
if decodedPayload.Platform == "dappnode" && decodedPayload.Timestamp != "" { | ||
validRequests = append(validRequests, types.SignatureRequestDecoded{ | ||
DecodedPayload: decodedPayload, | ||
Payload: req.Payload, | ||
Pubkey: req.Pubkey, | ||
Signature: req.Signature, | ||
Network: req.Network, | ||
Tag: req.Tag, | ||
}) | ||
} else { | ||
logger.Debug("Skipping invalid signature from request, invalid payload format") | ||
} | ||
} | ||
|
||
return validRequests, nil | ||
} |