git » sdk » commit cac2be4

Allow seeding the caps hash if you know it

author Stephen Paul Weber
2025-06-24 17:41:36 UTC
committer Stephen Paul Weber
2025-06-24 17:41:36 UTC
parent 22583ed66164c8a0b5ca7ec5a4f3806867bc0a14

Allow seeding the caps hash if you know it

Computing it over and over can be expensive and we know the hash when
loading from DB.

snikket/Caps.hx +5 -1

diff --git a/snikket/Caps.hx b/snikket/Caps.hx
index 72829d5..234cb1f 100644
--- a/snikket/Caps.hx
+++ b/snikket/Caps.hx
@@ -2,6 +2,7 @@ package snikket;
 
 import haxe.crypto.Base64;
 import haxe.io.Bytes;
+import haxe.io.BytesData;
 using Lambda;
 
 import snikket.Hash;
@@ -44,10 +45,13 @@ class Caps {
 		return result;
 	}
 
-	public function new(node: String, identities: Array<Identity>, features: Array<String>) {
+	public function new(node: String, identities: Array<Identity>, features: Array<String>, ?ver: BytesData) {
 		this.node = node;
 		this.identities = identities;
 		this.features = features;
+		if (ver != null) {
+			_ver = new Hash("sha-1", ver);
+		}
 	}
 
 	public function isChannel(chatId: String) {