@welshman/util 0.8.15 → 0.9.0-pre1
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/lib/src/Tools.d.ts +4 -0
- package/dist/lib/src/Tools.d.ts.map +1 -1
- package/dist/lib/src/Tools.js +4 -0
- package/dist/lib/src/Tools.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/util/src/Handles.d.ts +15 -0
- package/dist/util/src/Handles.d.ts.map +1 -0
- package/dist/util/src/Handles.js +25 -0
- package/dist/util/src/Handles.js.map +1 -0
- package/dist/util/src/Kinds.d.ts +4 -1
- package/dist/util/src/Kinds.d.ts.map +1 -1
- package/dist/util/src/Kinds.js +4 -1
- package/dist/util/src/Kinds.js.map +1 -1
- package/dist/util/src/Nip86.d.ts +8 -2
- package/dist/util/src/Nip86.d.ts.map +1 -1
- package/dist/util/src/Nip86.js +6 -0
- package/dist/util/src/Nip86.js.map +1 -1
- package/dist/util/src/Zaps.d.ts +31 -0
- package/dist/util/src/Zaps.d.ts.map +1 -1
- package/dist/util/src/Zaps.js +52 -3
- package/dist/util/src/Zaps.js.map +1 -1
- package/dist/util/src/index.d.ts +1 -5
- package/dist/util/src/index.d.ts.map +1 -1
- package/dist/util/src/index.js +1 -5
- package/dist/util/src/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/util/src/Encryptable.d.ts +0 -34
- package/dist/util/src/Encryptable.d.ts.map +0 -1
- package/dist/util/src/Encryptable.js +0 -52
- package/dist/util/src/Encryptable.js.map +0 -1
- package/dist/util/src/Handler.d.ts +0 -17
- package/dist/util/src/Handler.d.ts.map +0 -1
- package/dist/util/src/Handler.js +0 -33
- package/dist/util/src/Handler.js.map +0 -1
- package/dist/util/src/List.d.ts +0 -42
- package/dist/util/src/List.d.ts.map +0 -1
- package/dist/util/src/List.js +0 -86
- package/dist/util/src/List.js.map +0 -1
- package/dist/util/src/Profile.d.ts +0 -26
- package/dist/util/src/Profile.d.ts.map +0 -1
- package/dist/util/src/Profile.js +0 -50
- package/dist/util/src/Profile.js.map +0 -1
- package/dist/util/src/Room.d.ts +0 -63
- package/dist/util/src/Room.d.ts.map +0 -1
- package/dist/util/src/Room.js +0 -94
- package/dist/util/src/Room.js.map +0 -1
package/dist/util/src/Zaps.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { now, tryCatch, fetchJson, hexToBech32, fromPairs } from "@welshman/lib";
|
|
2
|
-
import {
|
|
1
|
+
import { now, tryCatch, fetchJson, hexToBech32, fromPairs, sum, allPass, nthEq, nth, } from "@welshman/lib";
|
|
2
|
+
import { ZAP_RECEIPT, ZAP_REQUEST } from "./Kinds.js";
|
|
3
3
|
import { getTagValue } from "./Tags.js";
|
|
4
4
|
import { makeEvent } from "./Events.js";
|
|
5
5
|
const DIVISORS = {
|
|
@@ -95,6 +95,55 @@ export const zapFromEvent = (response, zapper) => {
|
|
|
95
95
|
}
|
|
96
96
|
return zap;
|
|
97
97
|
};
|
|
98
|
+
const parseWeight = (weight) => {
|
|
99
|
+
const n = weight === undefined ? NaN : parseFloat(weight);
|
|
100
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Resolve an event's zap-split recipients per NIP-57 Appendix G:
|
|
104
|
+
*
|
|
105
|
+
* - With no `zap` tags the whole zap goes to the event's author.
|
|
106
|
+
* - If no recipient carries a weight, the zap is split equally (weight 1 each).
|
|
107
|
+
* - If weights are only partially present, unweighted recipients drop to weight
|
|
108
|
+
* 0 (i.e. they should not be zapped).
|
|
109
|
+
*
|
|
110
|
+
* Weight-0 recipients are still returned so callers have the full recipient set;
|
|
111
|
+
* they simply receive 0 from `splitZapAmount`.
|
|
112
|
+
*/
|
|
113
|
+
export const getZapSplits = (event) => {
|
|
114
|
+
const zapTags = event.tags.filter(allPass(nthEq(0, "zap"), nth(1)));
|
|
115
|
+
if (zapTags.length === 0) {
|
|
116
|
+
return [{ pubkey: event.pubkey, weight: 1 }];
|
|
117
|
+
}
|
|
118
|
+
const anyWeighted = zapTags.some(nth(3));
|
|
119
|
+
return zapTags.map(([, pubkey, relay, weight]) => ({
|
|
120
|
+
pubkey,
|
|
121
|
+
relay: relay || undefined,
|
|
122
|
+
weight: anyWeighted ? parseWeight(weight) : 1,
|
|
123
|
+
}));
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Divide `total` (in any integer unit, e.g. millisats) across an event's
|
|
127
|
+
* zap-split recipients proportionally to their weights. Any rounding remainder
|
|
128
|
+
* is handed to the highest-weighted recipient so the parts sum back to exactly
|
|
129
|
+
* `total`. If every weight is 0, nobody is zapped.
|
|
130
|
+
*/
|
|
131
|
+
export const splitZapAmount = (event, total) => {
|
|
132
|
+
const splits = getZapSplits(event);
|
|
133
|
+
const totalWeight = sum(splits.map(split => split.weight));
|
|
134
|
+
if (totalWeight === 0) {
|
|
135
|
+
return splits.map(split => ({ ...split, amount: 0 }));
|
|
136
|
+
}
|
|
137
|
+
const amounts = splits.map(split => Math.floor((total * split.weight) / totalWeight));
|
|
138
|
+
let maxIndex = 0;
|
|
139
|
+
splits.forEach((split, i) => {
|
|
140
|
+
if (split.weight > splits[maxIndex].weight) {
|
|
141
|
+
maxIndex = i;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
amounts[maxIndex] += total - sum(amounts);
|
|
145
|
+
return splits.map((split, i) => ({ ...split, amount: amounts[i] }));
|
|
146
|
+
};
|
|
98
147
|
export const makeZapRequest = ({ msats, zapper, pubkey, relays, content = "", eventId, anonymous, }) => {
|
|
99
148
|
const tags = [
|
|
100
149
|
["relays", ...relays],
|
|
@@ -122,7 +171,7 @@ export const getZapResponseFilter = ({ zapper, pubkey, eventId }) => {
|
|
|
122
171
|
throw new Error("Zapper did not have a nostr pubkey");
|
|
123
172
|
}
|
|
124
173
|
const filter = {
|
|
125
|
-
kinds: [
|
|
174
|
+
kinds: [ZAP_RECEIPT],
|
|
126
175
|
authors: [zapper.nostrPubkey],
|
|
127
176
|
since: now() - 30,
|
|
128
177
|
"#p": [pubkey],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Zaps.js","sourceRoot":"","sources":["../../../src/Zaps.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Zaps.js","sourceRoot":"","sources":["../../../src/Zaps.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,QAAQ,EACR,SAAS,EACT,WAAW,EACX,SAAS,EACT,GAAG,EACH,OAAO,EACP,KAAK,EACL,GAAG,GACJ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAC,WAAW,EAAE,WAAW,EAAC,MAAM,YAAY,CAAA;AACnD,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAA;AAGrC,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAErC,MAAM,QAAQ,GAAG;IACf,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IACd,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC;CAChB,CAAA;AAED,MAAM,aAAa,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAA;AAEnD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,GAAG,IAAI,CAAA;AAEpD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;AAEpE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE;IACjD,IAAI,OAAO,EAAE,KAAK,CAAA;IAClB,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC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
export * from "./Blossom.js";
|
|
3
|
-
export * from "./Encryptable.js";
|
|
4
3
|
export * from "./Events.js";
|
|
5
4
|
export * from "./Filters.js";
|
|
6
|
-
export * from "./
|
|
5
|
+
export * from "./Handles.js";
|
|
7
6
|
export * from "./Keys.js";
|
|
8
7
|
export * from "./Kinds.js";
|
|
9
8
|
export * from "./Links.js";
|
|
10
|
-
export * from "./List.js";
|
|
11
9
|
export * from "./Nip42.js";
|
|
12
10
|
export * from "./Nip86.js";
|
|
13
11
|
export * from "./Nip98.js";
|
|
14
12
|
export * from "./Pow.js";
|
|
15
|
-
export * from "./Profile.js";
|
|
16
13
|
export * from "./Pubkey.js";
|
|
17
14
|
export * from "./Relay.js";
|
|
18
|
-
export * from "./Room.js";
|
|
19
15
|
export * from "./Tags.js";
|
|
20
16
|
export * from "./Wallet.js";
|
|
21
17
|
export * from "./Zaps.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
package/dist/util/src/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
export * from "./Address.js";
|
|
2
2
|
export * from "./Blossom.js";
|
|
3
|
-
export * from "./Encryptable.js";
|
|
4
3
|
export * from "./Events.js";
|
|
5
4
|
export * from "./Filters.js";
|
|
6
|
-
export * from "./
|
|
5
|
+
export * from "./Handles.js";
|
|
7
6
|
export * from "./Keys.js";
|
|
8
7
|
export * from "./Kinds.js";
|
|
9
8
|
export * from "./Links.js";
|
|
10
|
-
export * from "./List.js";
|
|
11
9
|
export * from "./Nip42.js";
|
|
12
10
|
export * from "./Nip86.js";
|
|
13
11
|
export * from "./Nip98.js";
|
|
14
12
|
export * from "./Pow.js";
|
|
15
|
-
export * from "./Profile.js";
|
|
16
13
|
export * from "./Pubkey.js";
|
|
17
14
|
export * from "./Relay.js";
|
|
18
|
-
export * from "./Room.js";
|
|
19
15
|
export * from "./Tags.js";
|
|
20
16
|
export * from "./Wallet.js";
|
|
21
17
|
export * from "./Zaps.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@welshman/util",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-pre1",
|
|
4
4
|
"author": "hodlbod",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "A collection of nostr-related utilities.",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@noble/curves": "^1.9.7",
|
|
23
23
|
"nostr-tools": "^2.19.4",
|
|
24
|
-
"@welshman/lib": "0.
|
|
24
|
+
"@welshman/lib": "0.9.0-pre1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@noble/curves": "^1.9.7",
|
|
28
28
|
"nostr-tools": "^2.19.4",
|
|
29
29
|
"rimraf": "~6.0.0",
|
|
30
30
|
"typescript": "~5.8.0",
|
|
31
|
-
"@welshman/lib": "0.
|
|
31
|
+
"@welshman/lib": "0.9.0-pre1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "pnpm run clean && pnpm run compile --force",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { EventContent, TrustedEvent, EventTemplate } from "./Events.js";
|
|
2
|
-
export type Encrypt = (x: string) => Promise<string>;
|
|
3
|
-
export type EncryptableUpdates = Partial<EventContent>;
|
|
4
|
-
export type DecryptedEvent = TrustedEvent & {
|
|
5
|
-
plaintext: EncryptableUpdates;
|
|
6
|
-
};
|
|
7
|
-
export declare const asDecryptedEvent: (event: TrustedEvent, plaintext?: EncryptableUpdates) => DecryptedEvent;
|
|
8
|
-
/**
|
|
9
|
-
* Represents an encryptable event with optional updates.
|
|
10
|
-
*/
|
|
11
|
-
export declare class Encryptable<T extends EventTemplate> {
|
|
12
|
-
readonly event: Partial<T>;
|
|
13
|
-
readonly updates: EncryptableUpdates;
|
|
14
|
-
/**
|
|
15
|
-
* Creates an instance of Encryptable.
|
|
16
|
-
* @param event - An EventTemplate with optional tags and content.
|
|
17
|
-
* @param updates - Plaintext updates to be applied to the event content.
|
|
18
|
-
* @example
|
|
19
|
-
* Here's an example which enables updating a private mute list:
|
|
20
|
-
* ```
|
|
21
|
-
* const event = {kind: 10000, content: "", tags: []} // An event, only kind is required
|
|
22
|
-
* const encryptable = new Encryptable(event, {content: JSON.stringify([["e", "bad word"]])})
|
|
23
|
-
* const eventTemplate = await encryptable.reconcile(myEncryptFunction)
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
constructor(event: Partial<T>, updates: EncryptableUpdates);
|
|
27
|
-
/**
|
|
28
|
-
* Encrypts plaintext updates and merges them into the event template.
|
|
29
|
-
* @param encrypt - The encryption function to be used.
|
|
30
|
-
* @returns A promise that resolves to the reconciled and encrypted event.
|
|
31
|
-
*/
|
|
32
|
-
reconcile(encrypt: Encrypt): Promise<T>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=Encryptable.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Encryptable.d.ts","sourceRoot":"","sources":["../../../src/Encryptable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,aAAa,CAAA;AAE1E,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;AAEpD,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAA;AAEtD,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG;IAC1C,SAAS,EAAE,kBAAkB,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,YAAY,EAAE,YAAW,kBAAuB,KAC3D,cAAc,CAAA;AAE3C;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,aAAa;IAc5C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,kBAAkB;IAdtC;;;;;;;;;;;OAWG;gBAEQ,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,EACjB,OAAO,EAAE,kBAAkB;IAGtC;;;;OAIG;IACG,SAAS,CAAC,OAAO,EAAE,OAAO;CA4BjC"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const asDecryptedEvent = (event, plaintext = {}) => ({ ...event, plaintext });
|
|
2
|
-
/**
|
|
3
|
-
* Represents an encryptable event with optional updates.
|
|
4
|
-
*/
|
|
5
|
-
export class Encryptable {
|
|
6
|
-
event;
|
|
7
|
-
updates;
|
|
8
|
-
/**
|
|
9
|
-
* Creates an instance of Encryptable.
|
|
10
|
-
* @param event - An EventTemplate with optional tags and content.
|
|
11
|
-
* @param updates - Plaintext updates to be applied to the event content.
|
|
12
|
-
* @example
|
|
13
|
-
* Here's an example which enables updating a private mute list:
|
|
14
|
-
* ```
|
|
15
|
-
* const event = {kind: 10000, content: "", tags: []} // An event, only kind is required
|
|
16
|
-
* const encryptable = new Encryptable(event, {content: JSON.stringify([["e", "bad word"]])})
|
|
17
|
-
* const eventTemplate = await encryptable.reconcile(myEncryptFunction)
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
constructor(event, updates) {
|
|
21
|
-
this.event = event;
|
|
22
|
-
this.updates = updates;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Encrypts plaintext updates and merges them into the event template.
|
|
26
|
-
* @param encrypt - The encryption function to be used.
|
|
27
|
-
* @returns A promise that resolves to the reconciled and encrypted event.
|
|
28
|
-
*/
|
|
29
|
-
async reconcile(encrypt) {
|
|
30
|
-
const encryptContent = () => {
|
|
31
|
-
if (!this.updates.content)
|
|
32
|
-
return undefined;
|
|
33
|
-
return encrypt(this.updates.content);
|
|
34
|
-
};
|
|
35
|
-
const encryptTags = () => {
|
|
36
|
-
if (!this.updates.tags)
|
|
37
|
-
return undefined;
|
|
38
|
-
return Promise.all(this.updates.tags.map(async (tag) => {
|
|
39
|
-
tag[1] = await encrypt(tag[1]);
|
|
40
|
-
return tag;
|
|
41
|
-
}));
|
|
42
|
-
};
|
|
43
|
-
const [content, tags] = await Promise.all([encryptContent(), encryptTags()]);
|
|
44
|
-
// Updates are optional. If not provided, fall back to the event's content and tags.
|
|
45
|
-
return {
|
|
46
|
-
...this.event,
|
|
47
|
-
tags: tags || this.event.tags || [],
|
|
48
|
-
content: content || this.event.content || "",
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=Encryptable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Encryptable.js","sourceRoot":"","sources":["../../../src/Encryptable.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAmB,EAAE,YAAgC,EAAE,EAAE,EAAE,CAC1F,CAAC,EAAC,GAAG,KAAK,EAAE,SAAS,EAAC,CAAmB,CAAA;AAE3C;;GAEG;AACH,MAAM,OAAO,WAAW;IAcX;IACA;IAdX;;;;;;;;;;;OAWG;IACH,YACW,KAAiB,EACjB,OAA2B;QAD3B,UAAK,GAAL,KAAK,CAAY;QACjB,YAAO,GAAP,OAAO,CAAoB;IACnC,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,SAAS,CAAC,OAAgB;QAC9B,MAAM,cAAc,GAAG,GAAG,EAAE;YAC1B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;gBAAE,OAAO,SAAS,CAAA;YAE3C,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACtC,CAAC,CAAA;QAED,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YAExC,OAAO,OAAO,CAAC,GAAG,CAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAC,GAAG,EAAC,EAAE;gBAChC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE9B,OAAO,GAAG,CAAA;YACZ,CAAC,CAAC,CACH,CAAA;QACH,CAAC,CAAA;QAED,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;QAE5E,oFAAoF;QACpF,OAAO;YACL,GAAG,IAAI,CAAC,KAAK;YACb,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE;YACnC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE;SACxC,CAAA;IACR,CAAC;CACF"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TrustedEvent } from "./Events.js";
|
|
2
|
-
export type Handler = {
|
|
3
|
-
kind: number;
|
|
4
|
-
name: string;
|
|
5
|
-
about: string;
|
|
6
|
-
image: string;
|
|
7
|
-
identifier: string;
|
|
8
|
-
event: TrustedEvent;
|
|
9
|
-
website?: string;
|
|
10
|
-
lud16?: string;
|
|
11
|
-
nip05?: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const readHandlers: (event: TrustedEvent) => Handler[];
|
|
14
|
-
export declare const getHandlerKey: (handler: Handler) => string;
|
|
15
|
-
export declare const displayHandler: (handler?: Handler, fallback?: string) => string;
|
|
16
|
-
export declare const getHandlerAddress: (event: TrustedEvent) => string | undefined;
|
|
17
|
-
//# sourceMappingURL=Handler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.d.ts","sourceRoot":"","sources":["../../../src/Handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,aAAa,CAAA;AAE7C,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,YAAY,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,YAAY,cAuB/C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,OAAO,WAAmD,CAAA;AAEjG,eAAO,MAAM,cAAc,GAAI,UAAU,OAAO,EAAE,iBAAa,WAA8B,CAAA;AAE7F,eAAO,MAAM,iBAAiB,GAAI,OAAO,YAAY,uBAKpD,CAAA"}
|
package/dist/util/src/Handler.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { fromPairs, last, first, parseJson } from "@welshman/lib";
|
|
2
|
-
import { getAddress } from "./Address.js";
|
|
3
|
-
import { getAddressTags, getKindTagValues } from "./Tags.js";
|
|
4
|
-
export const readHandlers = (event) => {
|
|
5
|
-
const { d: identifier } = fromPairs(event.tags);
|
|
6
|
-
const meta = parseJson(event.content);
|
|
7
|
-
const normalizedMeta = {
|
|
8
|
-
name: meta?.name || meta?.display_name || "",
|
|
9
|
-
image: meta?.image || meta?.picture || "",
|
|
10
|
-
about: meta?.about || "",
|
|
11
|
-
website: meta?.website || "",
|
|
12
|
-
lud16: meta?.lud16 || "",
|
|
13
|
-
nip05: meta?.nip05 || "",
|
|
14
|
-
};
|
|
15
|
-
// If our meta is missing important stuff, don't bother showing it
|
|
16
|
-
if (!normalizedMeta.name || !normalizedMeta.image) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
return getKindTagValues(event.tags).map(kind => ({
|
|
20
|
-
...normalizedMeta,
|
|
21
|
-
kind,
|
|
22
|
-
identifier,
|
|
23
|
-
event,
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
26
|
-
export const getHandlerKey = (handler) => `${handler.kind}:${getAddress(handler.event)}`;
|
|
27
|
-
export const displayHandler = (handler, fallback = "") => handler?.name || fallback;
|
|
28
|
-
export const getHandlerAddress = (event) => {
|
|
29
|
-
const tags = getAddressTags(event.tags);
|
|
30
|
-
const tag = tags.find(t => last(t) === "web") || first(tags);
|
|
31
|
-
return tag?.[1];
|
|
32
|
-
};
|
|
33
|
-
//# sourceMappingURL=Handler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Handler.js","sourceRoot":"","sources":["../../../src/Handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAC,MAAM,eAAe,CAAA;AAC/D,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAA;AACvC,OAAO,EAAC,cAAc,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAA;AAe1D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAmB,EAAE,EAAE;IAClD,MAAM,EAAC,CAAC,EAAE,UAAU,EAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACrC,MAAM,cAAc,GAAG;QACrB,IAAI,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,YAAY,IAAI,EAAE;QAC5C,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,OAAO,IAAI,EAAE;QACzC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;QACxB,OAAO,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE;QAC5B,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;QACxB,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE;KACzB,CAAA;IAED,kEAAkE;IAClE,IAAI,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAClD,OAAO,EAAE,CAAA;IACX,CAAC;IAED,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,GAAG,cAAc;QACjB,IAAI;QACJ,UAAU;QACV,KAAK;KACN,CAAC,CAAc,CAAA;AAClB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAA;AAEjG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAiB,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,IAAI,QAAQ,CAAA;AAE7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAmB,EAAE,EAAE;IACvD,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAA;IAE5D,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAA"}
|
package/dist/util/src/List.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { RelayMode } from "./Relay.js";
|
|
2
|
-
import { Encryptable, DecryptedEvent } from "./Encryptable.js";
|
|
3
|
-
export type ListParams = {
|
|
4
|
-
kind: number;
|
|
5
|
-
};
|
|
6
|
-
export type List = ListParams & {
|
|
7
|
-
publicTags: string[][];
|
|
8
|
-
privateTags: string[][];
|
|
9
|
-
event?: DecryptedEvent;
|
|
10
|
-
};
|
|
11
|
-
export type PublishedList = Omit<List, "event"> & {
|
|
12
|
-
event: DecryptedEvent;
|
|
13
|
-
};
|
|
14
|
-
export declare const makeList: (list: ListParams & Partial<List>) => List;
|
|
15
|
-
export declare const readList: (event: DecryptedEvent) => PublishedList;
|
|
16
|
-
export declare const getListTags: (list: List | undefined) => string[][];
|
|
17
|
-
export declare const removeFromListByPredicate: (list: List, pred: (t: string[]) => boolean) => Encryptable<{
|
|
18
|
-
kind: number;
|
|
19
|
-
content: string;
|
|
20
|
-
tags: string[][];
|
|
21
|
-
}>;
|
|
22
|
-
export declare const removeFromList: (list: List, value: string) => Encryptable<{
|
|
23
|
-
kind: number;
|
|
24
|
-
content: string;
|
|
25
|
-
tags: string[][];
|
|
26
|
-
}>;
|
|
27
|
-
export declare const addToListPublicly: (list: List, ...tags: string[][]) => Encryptable<{
|
|
28
|
-
kind: number;
|
|
29
|
-
content: string;
|
|
30
|
-
tags: string[][];
|
|
31
|
-
}>;
|
|
32
|
-
export declare const addToListPrivately: (list: List, ...tags: string[][]) => Encryptable<import("./Events.js").EventTemplate>;
|
|
33
|
-
export declare const updateList: (list: List, { publicTags, privateTags }: {
|
|
34
|
-
publicTags?: string[][];
|
|
35
|
-
privateTags?: string[][];
|
|
36
|
-
}) => Encryptable<{
|
|
37
|
-
kind: number;
|
|
38
|
-
content: string;
|
|
39
|
-
tags: string[][];
|
|
40
|
-
}>;
|
|
41
|
-
export declare const getRelaysFromList: (list?: List, mode?: RelayMode) => string[];
|
|
42
|
-
//# sourceMappingURL=List.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../../src/List.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,SAAS,EAAoB,MAAM,YAAY,CAAA;AACnE,OAAO,EAAC,WAAW,EAAE,cAAc,EAAC,MAA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A"}
|
package/dist/util/src/List.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { parseJson, uniq, nthEq } from "@welshman/lib";
|
|
2
|
-
import { Address } from "./Address.js";
|
|
3
|
-
import { uniqTags, getRelayTags } from "./Tags.js";
|
|
4
|
-
import { isRelayUrl, normalizeRelayUrl } from "./Relay.js";
|
|
5
|
-
import { Encryptable } from "./Encryptable.js";
|
|
6
|
-
export const makeList = (list) => ({
|
|
7
|
-
publicTags: [],
|
|
8
|
-
privateTags: [],
|
|
9
|
-
...list,
|
|
10
|
-
});
|
|
11
|
-
const isValidTag = (tag) => {
|
|
12
|
-
if (tag[0] === "p")
|
|
13
|
-
return tag[1]?.length === 64;
|
|
14
|
-
if (tag[0] === "e")
|
|
15
|
-
return tag[1]?.length === 64;
|
|
16
|
-
if (tag[0] === "a")
|
|
17
|
-
return Address.isAddress(tag[1] || "");
|
|
18
|
-
if (tag[0] === "t")
|
|
19
|
-
return tag[1]?.length > 0;
|
|
20
|
-
if (tag[0] === "r")
|
|
21
|
-
return isRelayUrl(tag[1]);
|
|
22
|
-
if (tag[0] === "relay")
|
|
23
|
-
return isRelayUrl(tag[1]);
|
|
24
|
-
return true;
|
|
25
|
-
};
|
|
26
|
-
export const readList = (event) => {
|
|
27
|
-
const getTags = (tags) => (Array.isArray(tags) ? tags.filter(isValidTag) : []);
|
|
28
|
-
const privateTags = getTags(parseJson(event.plaintext?.content) || []);
|
|
29
|
-
const publicTags = getTags(event.tags);
|
|
30
|
-
return { event, kind: event.kind, publicTags, privateTags };
|
|
31
|
-
};
|
|
32
|
-
export const getListTags = (list) => [
|
|
33
|
-
...(list?.publicTags || []),
|
|
34
|
-
...(list?.privateTags || []),
|
|
35
|
-
];
|
|
36
|
-
export const removeFromListByPredicate = (list, pred) => {
|
|
37
|
-
const plaintext = {};
|
|
38
|
-
const template = {
|
|
39
|
-
kind: list.kind,
|
|
40
|
-
content: list.event?.content || "",
|
|
41
|
-
tags: list.publicTags.filter(t => !pred(t)),
|
|
42
|
-
};
|
|
43
|
-
// Avoid redundant encrypt calls if possible
|
|
44
|
-
if (list.privateTags.some(t => pred(t))) {
|
|
45
|
-
plaintext.content = JSON.stringify(list.privateTags.filter(t => !pred(t)));
|
|
46
|
-
}
|
|
47
|
-
return new Encryptable(template, plaintext);
|
|
48
|
-
};
|
|
49
|
-
export const removeFromList = (list, value) => removeFromListByPredicate(list, nthEq(1, value));
|
|
50
|
-
export const addToListPublicly = (list, ...tags) => {
|
|
51
|
-
const template = {
|
|
52
|
-
kind: list.kind,
|
|
53
|
-
content: list.event?.content || "",
|
|
54
|
-
tags: uniqTags([...list.publicTags, ...tags]),
|
|
55
|
-
};
|
|
56
|
-
return new Encryptable(template, {});
|
|
57
|
-
};
|
|
58
|
-
export const addToListPrivately = (list, ...tags) => {
|
|
59
|
-
const template = {
|
|
60
|
-
kind: list.kind,
|
|
61
|
-
tags: list.publicTags,
|
|
62
|
-
};
|
|
63
|
-
return new Encryptable(template, {
|
|
64
|
-
content: JSON.stringify(uniqTags([...list.privateTags, ...tags])),
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
export const updateList = (list, { publicTags, privateTags }) => {
|
|
68
|
-
const template = {
|
|
69
|
-
kind: list.kind,
|
|
70
|
-
content: list.event?.content || "",
|
|
71
|
-
tags: publicTags || list.publicTags,
|
|
72
|
-
};
|
|
73
|
-
const updates = {};
|
|
74
|
-
if (privateTags) {
|
|
75
|
-
updates.content = JSON.stringify(privateTags);
|
|
76
|
-
}
|
|
77
|
-
return new Encryptable(template, updates);
|
|
78
|
-
};
|
|
79
|
-
export const getRelaysFromList = (list, mode) => {
|
|
80
|
-
let tags = getRelayTags(getListTags(list));
|
|
81
|
-
if (mode) {
|
|
82
|
-
tags = tags.filter((t) => !t[2] || t[2] === mode);
|
|
83
|
-
}
|
|
84
|
-
return uniq(tags.map(t => normalizeRelayUrl(t[1])));
|
|
85
|
-
};
|
|
86
|
-
//# sourceMappingURL=List.js.map
|
|
@@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l?: string;
|
|
8
|
-
about?: string;
|
|
9
|
-
banner?: string;
|
|
10
|
-
picture?: string;
|
|
11
|
-
website?: string;
|
|
12
|
-
display_name?: string;
|
|
13
|
-
event?: TrustedEvent;
|
|
14
|
-
};
|
|
15
|
-
export type PublishedProfile = Omit<Profile, "event"> & {
|
|
16
|
-
event: TrustedEvent;
|
|
17
|
-
};
|
|
18
|
-
export declare const isPublishedProfile: (profile: Profile) => profile is PublishedProfile;
|
|
19
|
-
export declare const makeProfile: (profile?: Partial<Profile>) => Profile;
|
|
20
|
-
export declare const readProfile: (event: TrustedEvent) => PublishedProfile;
|
|
21
|
-
export declare const createProfile: ({ event, ...profile }: Profile) => EventTemplate;
|
|
22
|
-
export declare const editProfile: ({ event, ...profile }: PublishedProfile) => EventTemplate;
|
|
23
|
-
export declare const displayPubkey: (pubkey: string) => string;
|
|
24
|
-
export declare const displayProfile: (profile?: Profile, fallback?: string) => string;
|
|
25
|
-
export declare const profileHasName: (profile?: Profile) => boolean;
|
|
26
|
-
//# sourceMappingURL=Profile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Profile.d.ts","sourceRoot":"","sources":["../../../src/Profile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,aAAa,CAAA;AAIvD,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG;IACtD,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,OAAO,KAAG,OAAO,IAAI,gBACzC,CAAA;AAExB,eAAO,MAAM,WAAW,GAAI,UAAS,OAAO,CAAC,OAAO,CAAM,KAAG,OAkB5D,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,OAAO,YAAY,KAAG,gBAGhD,CAAA;AAEF,eAAO,MAAM,aAAa,GAAI,uBAAqB,OAAO,KAAG,aAI3D,CAAA;AAEF,eAAO,MAAM,WAAW,GAAI,uBAAqB,gBAAgB,KAAG,aAIlE,CAAA;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,WAI3C,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,UAAU,OAAO,EAAE,iBAAa,WAQ9D,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,UAAU,OAAO,YAAoD,CAAA"}
|
package/dist/util/src/Profile.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { npubEncode } from "nostr-tools/nip19";
|
|
2
|
-
import { ellipsize, parseJson } from "@welshman/lib";
|
|
3
|
-
import { getLnUrl } from "./Zaps.js";
|
|
4
|
-
import { PROFILE } from "./Kinds.js";
|
|
5
|
-
export const isPublishedProfile = (profile) => Boolean(profile.event);
|
|
6
|
-
export const makeProfile = (profile = {}) => {
|
|
7
|
-
if (typeof profile.lud06 === "string") {
|
|
8
|
-
const lnurl = getLnUrl(profile.lud06);
|
|
9
|
-
if (lnurl) {
|
|
10
|
-
profile = { ...profile, lnurl };
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (typeof profile.lud16 === "string") {
|
|
14
|
-
const lnurl = getLnUrl(profile.lud16);
|
|
15
|
-
if (lnurl) {
|
|
16
|
-
profile = { ...profile, lnurl };
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return profile;
|
|
20
|
-
};
|
|
21
|
-
export const readProfile = (event) => ({
|
|
22
|
-
...makeProfile(parseJson(event.content) || {}),
|
|
23
|
-
event,
|
|
24
|
-
});
|
|
25
|
-
export const createProfile = ({ event, ...profile }) => ({
|
|
26
|
-
kind: PROFILE,
|
|
27
|
-
content: JSON.stringify(profile),
|
|
28
|
-
tags: [],
|
|
29
|
-
});
|
|
30
|
-
export const editProfile = ({ event, ...profile }) => ({
|
|
31
|
-
kind: PROFILE,
|
|
32
|
-
content: JSON.stringify(profile),
|
|
33
|
-
tags: event.tags,
|
|
34
|
-
});
|
|
35
|
-
export const displayPubkey = (pubkey) => {
|
|
36
|
-
const d = npubEncode(pubkey);
|
|
37
|
-
return d.slice(0, 8) + "…" + d.slice(-5);
|
|
38
|
-
};
|
|
39
|
-
export const displayProfile = (profile, fallback = "") => {
|
|
40
|
-
const { display_name, name, event } = profile || {};
|
|
41
|
-
if (name)
|
|
42
|
-
return ellipsize(name, 60).trim();
|
|
43
|
-
if (display_name)
|
|
44
|
-
return ellipsize(display_name, 60).trim();
|
|
45
|
-
if (event)
|
|
46
|
-
return displayPubkey(event.pubkey).trim();
|
|
47
|
-
return fallback.trim();
|
|
48
|
-
};
|
|
49
|
-
export const profileHasName = (profile) => Boolean(profile?.name || profile?.display_name);
|
|
50
|
-
//# sourceMappingURL=Profile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Profile.js","sourceRoot":"","sources":["../../../src/Profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAC,SAAS,EAAE,SAAS,EAAC,MAAM,eAAe,CAAA;AAElD,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAClC,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAA;AAoBlC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAgB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,CAAC;IAChC,IAAI,EAAE,KAAK,CAAC,IAAI;CACjB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE;IAC9C,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;IAE5B,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAiB,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE;IACjE,MAAM,EAAC,YAAY,EAAE,IAAI,EAAE,KAAK,EAAC,GAAG,OAAO,IAAI,EAAE,CAAA;IAEjD,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IAC3C,IAAI,YAAY;QAAE,OAAO,SAAS,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;IAC3D,IAAI,KAAK;QAAE,OAAO,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IAEpD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAiB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,YAAY,CAAC,CAAA"}
|
package/dist/util/src/Room.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { TrustedEvent } from "./Events.js";
|
|
2
|
-
export type RoomMeta = {
|
|
3
|
-
h: string;
|
|
4
|
-
name?: string;
|
|
5
|
-
about?: string;
|
|
6
|
-
picture?: string;
|
|
7
|
-
pictureMeta?: string[];
|
|
8
|
-
isClosed?: boolean;
|
|
9
|
-
isHidden?: boolean;
|
|
10
|
-
isPrivate?: boolean;
|
|
11
|
-
isRestricted?: boolean;
|
|
12
|
-
livekit?: boolean;
|
|
13
|
-
event?: TrustedEvent;
|
|
14
|
-
};
|
|
15
|
-
export type PublishedRoomMeta = Omit<RoomMeta, "event"> & {
|
|
16
|
-
event: TrustedEvent;
|
|
17
|
-
};
|
|
18
|
-
export declare const generateH: () => string;
|
|
19
|
-
export declare const makeRoomMeta: (room?: Partial<RoomMeta>) => RoomMeta;
|
|
20
|
-
export declare const readRoomMeta: (event: TrustedEvent) => PublishedRoomMeta;
|
|
21
|
-
export declare const makeRoomCreateEvent: (room: RoomMeta) => {
|
|
22
|
-
kind: number;
|
|
23
|
-
content: string;
|
|
24
|
-
tags: string[][];
|
|
25
|
-
created_at: number;
|
|
26
|
-
};
|
|
27
|
-
export declare const makeRoomDeleteEvent: (room: RoomMeta) => {
|
|
28
|
-
kind: number;
|
|
29
|
-
content: string;
|
|
30
|
-
tags: string[][];
|
|
31
|
-
created_at: number;
|
|
32
|
-
};
|
|
33
|
-
export declare const makeRoomEditEvent: (room: RoomMeta) => {
|
|
34
|
-
kind: number;
|
|
35
|
-
content: string;
|
|
36
|
-
tags: string[][];
|
|
37
|
-
created_at: number;
|
|
38
|
-
};
|
|
39
|
-
export declare const makeRoomJoinEvent: (room: RoomMeta) => {
|
|
40
|
-
kind: number;
|
|
41
|
-
content: string;
|
|
42
|
-
tags: string[][];
|
|
43
|
-
created_at: number;
|
|
44
|
-
};
|
|
45
|
-
export declare const makeRoomLeaveEvent: (room: RoomMeta) => {
|
|
46
|
-
kind: number;
|
|
47
|
-
content: string;
|
|
48
|
-
tags: string[][];
|
|
49
|
-
created_at: number;
|
|
50
|
-
};
|
|
51
|
-
export declare const makeRoomAddMemberEvent: (room: RoomMeta, pubkey: string) => {
|
|
52
|
-
kind: number;
|
|
53
|
-
content: string;
|
|
54
|
-
tags: string[][];
|
|
55
|
-
created_at: number;
|
|
56
|
-
};
|
|
57
|
-
export declare const makeRoomRemoveMemberEvent: (room: RoomMeta, pubkey: string) => {
|
|
58
|
-
kind: number;
|
|
59
|
-
content: string;
|
|
60
|
-
tags: string[][];
|
|
61
|
-
created_at: number;
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=Room.d.ts.map
|