@unicitylabs/sphere-sdk 0.17.2-dev.3 → 0.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connect/index.cjs +1 -1
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +1 -1
- package/dist/connect/index.js.map +1 -1
- package/dist/core/index.cjs +21 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +21 -1
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/connect/index.cjs +1 -1
- package/dist/impl/browser/connect/index.cjs.map +1 -1
- package/dist/impl/browser/connect/index.js +1 -1
- package/dist/impl/browser/connect/index.js.map +1 -1
- package/dist/index.cjs +21 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4558,6 +4558,26 @@ var GroupVisibility = {
|
|
|
4558
4558
|
PRIVATE: "PRIVATE"
|
|
4559
4559
|
};
|
|
4560
4560
|
|
|
4561
|
+
// modules/groupchat/group-id.ts
|
|
4562
|
+
var MAX_SLUG_LENGTH = 24;
|
|
4563
|
+
var RANDOM_BYTES = 8;
|
|
4564
|
+
function groupIdSlug(name) {
|
|
4565
|
+
const slug = name.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/['\u2019]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4566
|
+
if (slug.length <= MAX_SLUG_LENGTH) return slug;
|
|
4567
|
+
const head = slug.slice(0, MAX_SLUG_LENGTH + 1);
|
|
4568
|
+
const hyphen = head.lastIndexOf("-");
|
|
4569
|
+
return hyphen > 0 ? head.slice(0, hyphen) : slug.slice(0, MAX_SLUG_LENGTH);
|
|
4570
|
+
}
|
|
4571
|
+
function newGroupId(name) {
|
|
4572
|
+
const crypto2 = globalThis.crypto;
|
|
4573
|
+
if (typeof crypto2?.getRandomValues !== "function") {
|
|
4574
|
+
throw new SphereError("Creating a group requires crypto.getRandomValues", "INVALID_CONFIG");
|
|
4575
|
+
}
|
|
4576
|
+
const bytes = crypto2.getRandomValues(new Uint8Array(RANDOM_BYTES));
|
|
4577
|
+
const random = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4578
|
+
return `${groupIdSlug(name) || "group"}-${random}`;
|
|
4579
|
+
}
|
|
4580
|
+
|
|
4561
4581
|
// modules/groupchat/GroupChatModule.ts
|
|
4562
4582
|
function createNip29Filter(data) {
|
|
4563
4583
|
return new Filter3(data);
|
|
@@ -5169,9 +5189,9 @@ var GroupChatModule = class {
|
|
|
5169
5189
|
if (!this.client) return null;
|
|
5170
5190
|
const creatorPubkey = this.getMyPublicKey();
|
|
5171
5191
|
if (!creatorPubkey) return null;
|
|
5172
|
-
const proposedGroupId = options.name.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 20) || this.randomId();
|
|
5173
5192
|
try {
|
|
5174
5193
|
const isPrivate = options.visibility === GroupVisibility.PRIVATE;
|
|
5194
|
+
const proposedGroupId = newGroupId(options.name);
|
|
5175
5195
|
const eventId = await this.client.createAndPublishEvent({
|
|
5176
5196
|
kind: NIP29_KINDS.CREATE_GROUP,
|
|
5177
5197
|
tags: [["h", proposedGroupId]],
|