diff --git a/src/connection/connection.js b/src/connection/connection.js index f802e1f..5b9a19c 100644 --- a/src/connection/connection.js +++ b/src/connection/connection.js @@ -1769,6 +1769,13 @@ class Connection extends EventEmitter { }); } + /** + * Set the flood scope to use by provided a 16-byte transport key. + * Passing an empty list will clear the scope. + * You can use `const transportKey = await TransportKeyUtil.getHashtagRegionKey("#region");` to easily generate keys + * @param transportKey Uint8Array 16-byte transport key, can be derived from first 16 bytes of sha256("#region") + * @returns {Promise} + */ setFloodScope(transportKey) { return new Promise(async (resolve, reject) => { try { diff --git a/src/transport_key_util.js b/src/transport_key_util.js new file mode 100644 index 0000000..56ae4cf --- /dev/null +++ b/src/transport_key_util.js @@ -0,0 +1,19 @@ +class TransportKeyUtil { + + static async getHashtagRegionKey(regionName) { + + // public hashtag regions must start with # + if(!regionName.startsWith("#")){ + regionName = `#${regionName}`; + } + + // Hash the message using SHA-256 + const bytes = new TextEncoder().encode(regionName); + const hash = await crypto.subtle.digest("SHA-256", bytes); + return new Uint8Array(hash); + + } + +} + +export default TransportKeyUtil;