Hmac fix, maybe.

This commit is contained in:
Kalzu Rekku
2026-04-18 20:56:28 +03:00
parent 4e7c62987a
commit c51a623658

View File

@@ -88,13 +88,27 @@ func SignPayload(data interface{}) string {
if psk == "" {
return ""
}
bytes, err := json.Marshal(data)
// First marshal the struct to JSON
raw, err := json.Marshal(data)
if err != nil {
return ""
}
// Round-trip through a generic interface so json.Marshal
// will sort map keys alphabetically, matching the Python
// manager's json.dumps(sort_keys=True) canonicalization.
var canonical interface{}
if err := json.Unmarshal(raw, &canonical); err != nil {
return ""
}
sorted, err := json.Marshal(canonical)
if err != nil {
return ""
}
h := hmac.New(sha256.New, []byte(psk))
h.Write(bytes)
h.Write(sorted)
return hex.EncodeToString(h.Sum(nil))
}