@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/core/index.js
CHANGED
|
@@ -4539,6 +4539,26 @@ var GroupVisibility = {
|
|
|
4539
4539
|
PRIVATE: "PRIVATE"
|
|
4540
4540
|
};
|
|
4541
4541
|
|
|
4542
|
+
// modules/groupchat/group-id.ts
|
|
4543
|
+
var MAX_SLUG_LENGTH = 24;
|
|
4544
|
+
var RANDOM_BYTES = 8;
|
|
4545
|
+
function groupIdSlug(name) {
|
|
4546
|
+
const slug = name.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/['\u2019]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4547
|
+
if (slug.length <= MAX_SLUG_LENGTH) return slug;
|
|
4548
|
+
const head = slug.slice(0, MAX_SLUG_LENGTH + 1);
|
|
4549
|
+
const hyphen = head.lastIndexOf("-");
|
|
4550
|
+
return hyphen > 0 ? head.slice(0, hyphen) : slug.slice(0, MAX_SLUG_LENGTH);
|
|
4551
|
+
}
|
|
4552
|
+
function newGroupId(name) {
|
|
4553
|
+
const crypto2 = globalThis.crypto;
|
|
4554
|
+
if (typeof crypto2?.getRandomValues !== "function") {
|
|
4555
|
+
throw new SphereError("Creating a group requires crypto.getRandomValues", "INVALID_CONFIG");
|
|
4556
|
+
}
|
|
4557
|
+
const bytes = crypto2.getRandomValues(new Uint8Array(RANDOM_BYTES));
|
|
4558
|
+
const random = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4559
|
+
return `${groupIdSlug(name) || "group"}-${random}`;
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4542
4562
|
// modules/groupchat/GroupChatModule.ts
|
|
4543
4563
|
function createNip29Filter(data) {
|
|
4544
4564
|
return new Filter3(data);
|
|
@@ -5150,9 +5170,9 @@ var GroupChatModule = class {
|
|
|
5150
5170
|
if (!this.client) return null;
|
|
5151
5171
|
const creatorPubkey = this.getMyPublicKey();
|
|
5152
5172
|
if (!creatorPubkey) return null;
|
|
5153
|
-
const proposedGroupId = options.name.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 20) || this.randomId();
|
|
5154
5173
|
try {
|
|
5155
5174
|
const isPrivate = options.visibility === GroupVisibility.PRIVATE;
|
|
5175
|
+
const proposedGroupId = newGroupId(options.name);
|
|
5156
5176
|
const eventId = await this.client.createAndPublishEvent({
|
|
5157
5177
|
kind: NIP29_KINDS.CREATE_GROUP,
|
|
5158
5178
|
tags: [["h", proposedGroupId]],
|