@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.cjs
CHANGED
|
@@ -4696,6 +4696,26 @@ var GroupVisibility = {
|
|
|
4696
4696
|
PRIVATE: "PRIVATE"
|
|
4697
4697
|
};
|
|
4698
4698
|
|
|
4699
|
+
// modules/groupchat/group-id.ts
|
|
4700
|
+
var MAX_SLUG_LENGTH = 24;
|
|
4701
|
+
var RANDOM_BYTES = 8;
|
|
4702
|
+
function groupIdSlug(name) {
|
|
4703
|
+
const slug = name.normalize("NFKD").replace(/\p{M}/gu, "").toLowerCase().replace(/['\u2019]/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
4704
|
+
if (slug.length <= MAX_SLUG_LENGTH) return slug;
|
|
4705
|
+
const head = slug.slice(0, MAX_SLUG_LENGTH + 1);
|
|
4706
|
+
const hyphen = head.lastIndexOf("-");
|
|
4707
|
+
return hyphen > 0 ? head.slice(0, hyphen) : slug.slice(0, MAX_SLUG_LENGTH);
|
|
4708
|
+
}
|
|
4709
|
+
function newGroupId(name) {
|
|
4710
|
+
const crypto2 = globalThis.crypto;
|
|
4711
|
+
if (typeof crypto2?.getRandomValues !== "function") {
|
|
4712
|
+
throw new SphereError("Creating a group requires crypto.getRandomValues", "INVALID_CONFIG");
|
|
4713
|
+
}
|
|
4714
|
+
const bytes = crypto2.getRandomValues(new Uint8Array(RANDOM_BYTES));
|
|
4715
|
+
const random = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
4716
|
+
return `${groupIdSlug(name) || "group"}-${random}`;
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4699
4719
|
// modules/groupchat/GroupChatModule.ts
|
|
4700
4720
|
function createNip29Filter(data) {
|
|
4701
4721
|
return new import_nostr_js_sdk3.Filter(data);
|
|
@@ -5307,9 +5327,9 @@ var GroupChatModule = class {
|
|
|
5307
5327
|
if (!this.client) return null;
|
|
5308
5328
|
const creatorPubkey = this.getMyPublicKey();
|
|
5309
5329
|
if (!creatorPubkey) return null;
|
|
5310
|
-
const proposedGroupId = options.name.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 20) || this.randomId();
|
|
5311
5330
|
try {
|
|
5312
5331
|
const isPrivate = options.visibility === GroupVisibility.PRIVATE;
|
|
5332
|
+
const proposedGroupId = newGroupId(options.name);
|
|
5313
5333
|
const eventId = await this.client.createAndPublishEvent({
|
|
5314
5334
|
kind: NIP29_KINDS.CREATE_GROUP,
|
|
5315
5335
|
tags: [["h", proposedGroupId]],
|