feat(api): add account workspaces and signed content events
This commit is contained in:
1 parent
937b774a93
commit
7b8d61d1ba
63 files changed
+5407
-370
No files matched your search
@@ -67,6 +67,37 @@ public class VectorTests
|
||||
Assert.Equal(H(item.GetProperty("k_item")), ItemKey(H(item.GetProperty("item_id"))));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SignatureFramingAndEcdsaMatchTheVectors()
|
||||
{
|
||||
var vector = V.GetProperty("signatures");
|
||||
static byte[] B64Url(string value) => Convert.FromBase64String(value.Replace('-', '+').Replace('_', '/') + new string('=', (4 - value.Length % 4) % 4));
|
||||
var x = B64Url(vector.GetProperty("x").GetString()!);
|
||||
var y = B64Url(vector.GetProperty("y").GetString()!);
|
||||
var payload = H(vector.GetProperty("payload"));
|
||||
var kind = vector.GetProperty("kind").GetString()!;
|
||||
var signature = H(vector.GetProperty("signature"));
|
||||
Assert.Equal(H(vector.GetProperty("message")), SignatureCodec.BuildMessage(kind, payload));
|
||||
Assert.True(SignatureCodec.VerifyP256(x, y, kind, payload, signature));
|
||||
Assert.False(SignatureCodec.VerifyP256(x, y, "chat.edit", payload, signature));
|
||||
payload[0] ^= 1;
|
||||
Assert.False(SignatureCodec.VerifyP256(x, y, kind, payload, signature));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ContentEventPayloadAndFrameManifestMatchTheVectors()
|
||||
{
|
||||
var vector = V.GetProperty("content_event");
|
||||
var digests = vector.GetProperty("frame_digests").EnumerateArray().Select(H).ToList();
|
||||
var manifest = SignatureCodec.FrameManifestHash(digests);
|
||||
Assert.Equal(H(vector.GetProperty("manifest_hash")), manifest);
|
||||
byte[] id(string property) => H(vector.GetProperty(property));
|
||||
Assert.Equal(H(vector.GetProperty("payload")), SignatureCodec.ContentEventPayload(
|
||||
id("space_id"), vector.GetProperty("channel_id").GetString()!, vector.GetProperty("username").GetString()!,
|
||||
vector.GetProperty("device_id").GetString()!, id("event_id"), vector.GetProperty("kind").GetString()!, CryptoDomain.Chat,
|
||||
vector.GetProperty("epoch").GetInt32(), id("item_id"), vector.GetProperty("frame_count").GetInt32(), manifest, id("target_item_id")));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServerTokenHashMatchesTheStoredHashes()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user