HashVerifier
Computes and verifies hashes for sync verification. Implements spec Section 15 (Hash Verification).
public static class HashVerifier
Methods
ComputeBatchHash(IEnumerable<SyncLogEntry>)
public static string ComputeBatchHash(IEnumerable<SyncLogEntry> changes)
Computes SHA-256 hash for a batch of changes. Format: "{version}:{table_name}:{pk_value}:{operation}:{payload}\n"
Parameters:
| Name | Type | Description |
|---|---|---|
changes |
SyncLogEntry> |
Returns: String
ComputeDatabaseHash(IEnumerable<string>, Func<string, IEnumerable<Dictionary<string, object?>>>)
public static string ComputeDatabaseHash(IEnumerable<string> tables, Func<string, IEnumerable<Dictionary<string, object?>>> getTableRows)
Computes full database hash for all tracked tables. Tables are processed alphabetically, rows ordered by PK.
Parameters:
| Name | Type | Description |
|---|---|---|
tables |
String> |
|
getTableRows |
Object>>> |
Returns: String
VerifyHash(string, string)
public static Result<bool, SyncError> VerifyHash(string expected, string actual)
Verifies that two hashes match.
Parameters:
| Name | Type | Description |
|---|---|---|
expected |
String |
|
actual |
String |
Returns: SyncError>
ToCanonicalJson(Dictionary<string, object?>)
public static string ToCanonicalJson(Dictionary<string, object?> data)
Converts a dictionary to canonical JSON per spec Section 15.2. Keys sorted alphabetically, no whitespace, minimal escaping.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object> |
Returns: String
ParseJson(string?)
public static Dictionary<string, object?> ParseJson(string? json)
Parses a JSON string to a dictionary for hashing.
Parameters:
| Name | Type | Description |
|---|---|---|
json |
String |
Returns: Object>