@nostrify/policies 0.36.6 → 0.36.7

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.
Files changed (69) hide show
  1. package/.turbo/turbo-build.log +27 -28
  2. package/.turbo/turbo-test.log +53 -4
  3. package/CHANGELOG.md +9 -0
  4. package/package.json +4 -4
  5. package/dist/AntiDuplicationPolicy.d.ts +0 -43
  6. package/dist/AntiDuplicationPolicy.d.ts.map +0 -1
  7. package/dist/AntiDuplicationPolicy.js +0 -44
  8. package/dist/AnyPolicy.d.ts +0 -8
  9. package/dist/AnyPolicy.d.ts.map +0 -1
  10. package/dist/AnyPolicy.js +0 -20
  11. package/dist/AuthorPolicy.d.ts +0 -9
  12. package/dist/AuthorPolicy.d.ts.map +0 -1
  13. package/dist/AuthorPolicy.js +0 -22
  14. package/dist/DomainPolicy.d.ts +0 -21
  15. package/dist/DomainPolicy.d.ts.map +0 -1
  16. package/dist/DomainPolicy.js +0 -62
  17. package/dist/FiltersPolicy.d.ts +0 -18
  18. package/dist/FiltersPolicy.d.ts.map +0 -1
  19. package/dist/FiltersPolicy.js +0 -17
  20. package/dist/HashtagPolicy.d.ts +0 -16
  21. package/dist/HashtagPolicy.d.ts.map +0 -1
  22. package/dist/HashtagPolicy.js +0 -18
  23. package/dist/HellthreadPolicy.d.ts +0 -14
  24. package/dist/HellthreadPolicy.d.ts.map +0 -1
  25. package/dist/HellthreadPolicy.js +0 -20
  26. package/dist/InvertPolicy.d.ts +0 -9
  27. package/dist/InvertPolicy.d.ts.map +0 -1
  28. package/dist/InvertPolicy.js +0 -20
  29. package/dist/KeywordPolicy.d.ts +0 -16
  30. package/dist/KeywordPolicy.d.ts.map +0 -1
  31. package/dist/KeywordPolicy.js +0 -18
  32. package/dist/NoOpPolicy.d.ts +0 -6
  33. package/dist/NoOpPolicy.d.ts.map +0 -1
  34. package/dist/NoOpPolicy.js +0 -9
  35. package/dist/OpenAIPolicy.d.ts +0 -80
  36. package/dist/OpenAIPolicy.d.ts.map +0 -1
  37. package/dist/OpenAIPolicy.js +0 -38
  38. package/dist/PipePolicy.d.ts +0 -26
  39. package/dist/PipePolicy.d.ts.map +0 -1
  40. package/dist/PipePolicy.js +0 -18
  41. package/dist/PowPolicy.d.ts +0 -21
  42. package/dist/PowPolicy.d.ts.map +0 -1
  43. package/dist/PowPolicy.js +0 -27
  44. package/dist/PubkeyBanPolicy.d.ts +0 -15
  45. package/dist/PubkeyBanPolicy.d.ts.map +0 -1
  46. package/dist/PubkeyBanPolicy.js +0 -18
  47. package/dist/ReadOnlyPolicy.d.ts +0 -6
  48. package/dist/ReadOnlyPolicy.d.ts.map +0 -1
  49. package/dist/ReadOnlyPolicy.js +0 -9
  50. package/dist/RegexPolicy.d.ts +0 -15
  51. package/dist/RegexPolicy.d.ts.map +0 -1
  52. package/dist/RegexPolicy.js +0 -16
  53. package/dist/ReplyBotPolicy.d.ts +0 -25
  54. package/dist/ReplyBotPolicy.d.ts.map +0 -1
  55. package/dist/ReplyBotPolicy.js +0 -42
  56. package/dist/SizePolicy.d.ts +0 -23
  57. package/dist/SizePolicy.d.ts.map +0 -1
  58. package/dist/SizePolicy.js +0 -19
  59. package/dist/WhitelistPolicy.d.ts +0 -16
  60. package/dist/WhitelistPolicy.d.ts.map +0 -1
  61. package/dist/WhitelistPolicy.js +0 -25
  62. package/dist/WoTPolicy.d.ts +0 -26
  63. package/dist/WoTPolicy.d.ts.map +0 -1
  64. package/dist/WoTPolicy.js +0 -39
  65. package/dist/mod.d.ts +0 -21
  66. package/dist/mod.d.ts.map +0 -1
  67. package/dist/mod.js +0 -42
  68. package/dist/mod.js.map +0 -7
  69. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,80 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * OpenAI moderation result.
4
- *
5
- * https://platform.openai.com/docs/api-reference/moderations/create
6
- */
7
- interface OpenAIModerationResult {
8
- id: string;
9
- model: string;
10
- results: {
11
- categories: {
12
- 'hate': boolean;
13
- 'hate/threatening': boolean;
14
- 'self-harm': boolean;
15
- 'sexual': boolean;
16
- 'sexual/minors': boolean;
17
- 'violence': boolean;
18
- 'violence/graphic': boolean;
19
- };
20
- category_scores: {
21
- 'hate': number;
22
- 'hate/threatening': number;
23
- 'self-harm': number;
24
- 'sexual': number;
25
- 'sexual/minors': number;
26
- 'violence': number;
27
- 'violence/graphic': number;
28
- };
29
- flagged: boolean;
30
- }[];
31
- }
32
- /** Policy options for `OpenAIPolicy`. */
33
- interface OpenAIPolicyOpts {
34
- /**
35
- * Callback for fine control over the policy. It contains the event and the OpenAI moderation data.
36
- * Implementations should return `true` to **reject** the content, and `false` to accept.
37
- */
38
- handler?(event: NostrEvent, result: OpenAIModerationResult): boolean;
39
- /** Custom endpoint to use instead of `https://api.openai.com/v1/moderations`. */
40
- endpoint?: string;
41
- /** Custom fetch implementation. */
42
- fetch?: typeof fetch;
43
- /** Which event kinds to apply the policy to. */
44
- kinds?: number[];
45
- /** OpenAI API key for making the requests. */
46
- apiKey: string;
47
- }
48
- /**
49
- * Passes event content to OpenAI and then rejects flagged events.
50
- *
51
- * By default, this policy will reject kind 1 events that OpenAI flags.
52
- * It's possible to pass a custom handler for more control. An OpenAI API key is required.
53
- *
54
- * ```ts
55
- * // Default handler. It's so strict it's suitable for children.
56
- * new OpenAIPolicy({ apiKey: Deno.env.get('OPENAI_API_KEY') });
57
- *
58
- * // With a custom handler.
59
- * new OpenAIPolicy({
60
- * apiKey: Deno.env.get('OPENAI_API_KEY'),
61
- * handler(event, data) {
62
- * // Loop each result.
63
- * return data.results.some((result) => {
64
- * if (result.flagged) {
65
- * const { sexual, violence } = result.categories;
66
- * // Reject only events flagged as sexual and violent.
67
- * return sexual && violence;
68
- * }
69
- * });
70
- * },
71
- * });
72
- * ```
73
- */
74
- export declare class OpenAIPolicy implements NPolicy {
75
- private opts;
76
- constructor(opts: OpenAIPolicyOpts);
77
- call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK>;
78
- }
79
- export {};
80
- //# sourceMappingURL=OpenAIPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OpenAIPolicy.d.ts","sourceRoot":"","sources":["../OpenAIPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;GAIG;AACH,UAAU,sBAAsB;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE;QACP,UAAU,EAAE;YACV,MAAM,EAAE,OAAO,CAAC;YAChB,kBAAkB,EAAE,OAAO,CAAC;YAC5B,WAAW,EAAE,OAAO,CAAC;YACrB,QAAQ,EAAE,OAAO,CAAC;YAClB,eAAe,EAAE,OAAO,CAAC;YACzB,UAAU,EAAE,OAAO,CAAC;YACpB,kBAAkB,EAAE,OAAO,CAAC;SAC7B,CAAC;QACF,eAAe,EAAE;YACf,MAAM,EAAE,MAAM,CAAC;YACf,kBAAkB,EAAE,MAAM,CAAC;YAC3B,WAAW,EAAE,MAAM,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC;YACjB,eAAe,EAAE,MAAM,CAAC;YACxB,UAAU,EAAE,MAAM,CAAC;YACnB,kBAAkB,EAAE,MAAM,CAAC;SAC5B,CAAC;QACF,OAAO,EAAE,OAAO,CAAC;KAClB,EAAE,CAAC;CACL;AAED,yCAAyC;AACzC,UAAU,gBAAgB;IACxB;;;OAGG;IACH,OAAO,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC;IACrE,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,YAAa,YAAW,OAAO;IAC1C,OAAO,CAAC,IAAI,CAAmB;gBACnB,IAAI,EAAE,gBAAgB;IAI5B,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAiC3E"}
@@ -1,38 +0,0 @@
1
- class OpenAIPolicy {
2
- opts;
3
- constructor(opts) {
4
- this.opts = opts;
5
- }
6
- async call(event, signal) {
7
- const {
8
- handler = (_, { results }) => results.some((r) => r.flagged),
9
- endpoint = "https://api.openai.com/v1/moderations",
10
- kinds = [1, 30023],
11
- apiKey
12
- } = this.opts;
13
- if (kinds.includes(event.kind)) {
14
- try {
15
- const resp = await fetch(endpoint, {
16
- headers: {
17
- "Content-Type": "application/json",
18
- "Authorization": `Bearer ${apiKey}`
19
- },
20
- body: JSON.stringify({
21
- input: event.content
22
- }),
23
- signal
24
- });
25
- const result = await resp.json();
26
- if (handler(event, result)) {
27
- return ["OK", event.id, false, "blocked: content flagged by AI"];
28
- }
29
- } catch (_) {
30
- return ["OK", event.id, false, "blocked: error analyzing content"];
31
- }
32
- }
33
- return ["OK", event.id, true, ""];
34
- }
35
- }
36
- export {
37
- OpenAIPolicy
38
- };
@@ -1,26 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Processes events through multiple policies.
4
- *
5
- * If any policy rejects, the pipeline will stop and return the rejected message.
6
- *
7
- * ```ts
8
- * const policy = new PipePolicy([
9
- * new NoOpPolicy(),
10
- * new FiltersPolicy([{ kinds: [0, 1, 3, 5, 7, 1984, 9734, 9735, 10002] }]),
11
- * new KeywordPolicy(['https://t.me/']),
12
- * new RegexPolicy(/(🟠|🔥|😳)ChtaGPT/i),
13
- * new PubkeyBanPolicy(['e810fafa1e89cdf80cced8e013938e87e21b699b24c8570537be92aec4b12c18']),
14
- * new HellthreadPolicy({ limit: 100 }),
15
- * new AntiDuplicationPolicy({ kv: await Deno.openKv(), expireIn: 60000, minLength: 50 }),
16
- * ]);
17
- *
18
- * const [_, eventId, ok, reason] = await policy.call(event);
19
- * ```
20
- */
21
- export declare class PipePolicy implements NPolicy {
22
- private policies;
23
- constructor(policies: NPolicy[]);
24
- call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK>;
25
- }
26
- //# sourceMappingURL=PipePolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PipePolicy.d.ts","sourceRoot":"","sources":["../PipePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,UAAW,YAAW,OAAO;IACxC,OAAO,CAAC,QAAQ,CAAiB;gBACrB,QAAQ,EAAE,OAAO,EAAE;IAIzB,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAW3E"}
@@ -1,18 +0,0 @@
1
- class PipePolicy {
2
- policies = [];
3
- constructor(policies) {
4
- this.policies = policies;
5
- }
6
- async call(event, signal) {
7
- for (const policy of this.policies) {
8
- const [_, eventId, ok, reason] = await policy.call(event, signal);
9
- if (!ok) {
10
- return [_, eventId, ok, reason];
11
- }
12
- }
13
- return ["OK", event.id, true, ""];
14
- }
15
- }
16
- export {
17
- PipePolicy
18
- };
@@ -1,21 +0,0 @@
1
- import type { NostrEvent, NostrRelayInfo, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Policy options for `PowPolicy`. */
3
- interface PowPolicyOpts {
4
- /** Events will be rejected if their `id` does not contain at least this many leading 0 bits. Default: `1` */
5
- difficulty?: number;
6
- }
7
- /**
8
- * Reject events which don't meet Proof-of-Work ([NIP-13](https://github.com/nostr-protocol/nips/blob/master/13.md)) criteria.
9
- *
10
- * ```ts
11
- * new PowPolicy({ difficulty: 20 });
12
- * ```
13
- */
14
- export declare class PowPolicy implements NPolicy {
15
- private opts;
16
- constructor(opts?: PowPolicyOpts);
17
- call({ id, tags }: NostrEvent): Promise<NostrRelayOK>;
18
- get info(): NostrRelayInfo;
19
- }
20
- export {};
21
- //# sourceMappingURL=PowPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PowPolicy.d.ts","sourceRoot":"","sources":["../PowPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAGzF,sCAAsC;AACtC,UAAU,aAAa;IACrB,6GAA6G;IAC7G,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,qBAAa,SAAU,YAAW,OAAO;IACvC,OAAO,CAAC,IAAI,CAAgB;gBAChB,IAAI,GAAE,aAAkB;IAK9B,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAa3D,IAAI,IAAI,IAAI,cAAc,CAMzB;CACF"}
package/dist/PowPolicy.js DELETED
@@ -1,27 +0,0 @@
1
- import { nip13 } from "nostr-tools";
2
- class PowPolicy {
3
- opts;
4
- constructor(opts = {}) {
5
- this.opts = opts;
6
- }
7
- // deno-lint-ignore require-await
8
- async call({ id, tags }) {
9
- const { difficulty = 1 } = this.opts;
10
- const pow = nip13.getPow(id);
11
- const nonce = tags.find(([name]) => name === "nonce");
12
- if (pow >= difficulty && nonce && Number(nonce[2]) >= difficulty) {
13
- return ["OK", id, true, ""];
14
- }
15
- return ["OK", id, false, `pow: insufficient proof-of-work (difficulty ${difficulty})`];
16
- }
17
- get info() {
18
- return {
19
- limitation: {
20
- min_pow_difficulty: this.opts.difficulty
21
- }
22
- };
23
- }
24
- }
25
- export {
26
- PowPolicy
27
- };
@@ -1,15 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Ban events from individual pubkeys.
4
- *
5
- * ```ts
6
- * // Ban a specific pubkey.
7
- * new PubkeyBanPolicy(['e810fafa1e89cdf80cced8e013938e87e21b699b24c8570537be92aec4b12c18']);
8
- * ```
9
- */
10
- export declare class PubkeyBanPolicy implements NPolicy {
11
- private pubkeys;
12
- constructor(pubkeys: Iterable<string>);
13
- call({ id, pubkey }: NostrEvent): Promise<NostrRelayOK>;
14
- }
15
- //# sourceMappingURL=PubkeyBanPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PubkeyBanPolicy.d.ts","sourceRoot":"","sources":["../PubkeyBanPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,OAAO,CAAmB;gBACtB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;IAK/B,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAS9D"}
@@ -1,18 +0,0 @@
1
- class PubkeyBanPolicy {
2
- pubkeys;
3
- constructor(pubkeys) {
4
- this.pubkeys = pubkeys;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, pubkey }) {
8
- for (const p of this.pubkeys) {
9
- if (p === pubkey) {
10
- return ["OK", id, false, "blocked: pubkey is banned"];
11
- }
12
- }
13
- return ["OK", id, true, ""];
14
- }
15
- }
16
- export {
17
- PubkeyBanPolicy
18
- };
@@ -1,6 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** This policy rejects all messages. */
3
- export declare class ReadOnlyPolicy implements NPolicy {
4
- call(event: NostrEvent): Promise<NostrRelayOK>;
5
- }
6
- //# sourceMappingURL=ReadOnlyPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReadOnlyPolicy.d.ts","sourceRoot":"","sources":["../ReadOnlyPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,wCAAwC;AACxC,qBAAa,cAAe,YAAW,OAAO;IAEtC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAGrD"}
@@ -1,9 +0,0 @@
1
- class ReadOnlyPolicy {
2
- // deno-lint-ignore require-await
3
- async call(event) {
4
- return ["OK", event.id, false, "blocked: the relay is read-only"];
5
- }
6
- }
7
- export {
8
- ReadOnlyPolicy
9
- };
@@ -1,15 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Reject events whose content matches the regex.
4
- *
5
- * ```ts
6
- * // Ban events matching a regex.
7
- * new RegexPolicy(/(🟠|🔥|😳)ChtaGPT/i);
8
- * ```
9
- */
10
- export declare class RegexPolicy implements NPolicy {
11
- private regex;
12
- constructor(regex: RegExp);
13
- call({ id, content }: NostrEvent): Promise<NostrRelayOK>;
14
- }
15
- //# sourceMappingURL=RegexPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RegexPolicy.d.ts","sourceRoot":"","sources":["../RegexPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,OAAO;IACzC,OAAO,CAAC,KAAK,CAAS;gBACV,KAAK,EAAE,MAAM;IAKnB,IAAI,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAO/D"}
@@ -1,16 +0,0 @@
1
- class RegexPolicy {
2
- regex;
3
- constructor(regex) {
4
- this.regex = regex;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, content }) {
8
- if (this.regex.test(content)) {
9
- return ["OK", id, false, "blocked: text matches a banned expression"];
10
- }
11
- return ["OK", id, true, ""];
12
- }
13
- }
14
- export {
15
- RegexPolicy
16
- };
@@ -1,25 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
2
- /** Options for the ReplyBotPolicy. */
3
- export interface ReplyBotPolicyOpts {
4
- /** The store to use for fetching events. */
5
- store: NStore;
6
- /** The minimum time in seconds between two posts. */
7
- threshold?: number;
8
- /** The kinds of events to apply the policy to. */
9
- kinds?: number[];
10
- }
11
- /** Block events that reply too quickly to another event. */
12
- export declare class ReplyBotPolicy implements NPolicy {
13
- private opts;
14
- constructor(opts: ReplyBotPolicyOpts);
15
- call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK>;
16
- /** Tag is a NIP-10 root tag. */
17
- private static isRootTag;
18
- /** Tag is a NIP-10 reply tag. */
19
- private static isReplyTag;
20
- /** Tag is an "e" tag without a NIP-10 marker. */
21
- private static isLegacyReplyTag;
22
- /** Get the "e" tag for the event being replied to, first according to the NIPs then falling back to the legacy way. */
23
- private static findReplyTag;
24
- }
25
- //# sourceMappingURL=ReplyBotPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ReplyBotPolicy.d.ts","sourceRoot":"","sources":["../ReplyBotPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjF,sCAAsC;AACtC,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,4DAA4D;AAC5D,qBAAa,cAAe,YAAW,OAAO;IAC5C,OAAO,CAAC,IAAI,CAAqB;gBACrB,IAAI,EAAE,kBAAkB;IAI9B,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAuB1E,gCAAgC;IAChC,OAAO,CAAC,MAAM,CAAC,SAAS;IAIxB,iCAAiC;IACjC,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB,iDAAiD;IACjD,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B,uHAAuH;IACvH,OAAO,CAAC,MAAM,CAAC,YAAY;CAG5B"}
@@ -1,42 +0,0 @@
1
- class ReplyBotPolicy {
2
- opts;
3
- constructor(opts) {
4
- this.opts = opts;
5
- }
6
- async call(event, signal) {
7
- const { store, threshold = 1, kinds = [1] } = this.opts;
8
- if (kinds.includes(event.kind)) {
9
- const [, replyToId] = ReplyBotPolicy.findReplyTag(event.tags) ?? [];
10
- if (replyToId) {
11
- const [prevEvent] = await store.query([{ ids: [replyToId] }], { signal });
12
- if (prevEvent) {
13
- const diff = event.created_at - prevEvent.created_at;
14
- const pTag = prevEvent.tags.find(([name, value]) => name === "p" && value === event.pubkey);
15
- if (diff <= threshold && !pTag) {
16
- return ["OK", event.id, false, "rate-limited: replied too quickly"];
17
- }
18
- }
19
- }
20
- }
21
- return ["OK", event.id, true, ""];
22
- }
23
- /** Tag is a NIP-10 root tag. */
24
- static isRootTag(tag) {
25
- return tag[0] === "e" && tag[3] === "root";
26
- }
27
- /** Tag is a NIP-10 reply tag. */
28
- static isReplyTag(tag) {
29
- return tag[0] === "e" && tag[3] === "reply";
30
- }
31
- /** Tag is an "e" tag without a NIP-10 marker. */
32
- static isLegacyReplyTag(tag) {
33
- return tag[0] === "e" && !tag[3];
34
- }
35
- /** Get the "e" tag for the event being replied to, first according to the NIPs then falling back to the legacy way. */
36
- static findReplyTag(tags) {
37
- return tags.find(this.isReplyTag) || tags.find(this.isRootTag) || tags.findLast(this.isLegacyReplyTag);
38
- }
39
- }
40
- export {
41
- ReplyBotPolicy
42
- };
@@ -1,23 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Policy options for `SizePolicy`. */
3
- interface SizePolicyOpts {
4
- /** Maximum size of the message content in bytes. Default: 8192 (8KB) */
5
- maxBytes?: number;
6
- }
7
- /**
8
- * Reject events larger than a specified size in bytes.
9
- *
10
- * ```ts
11
- * // Reject events larger than the default size (8KB) .
12
- * new SizePolicy();
13
- * // Reject events larger than a custom size (15KB).
14
- * new SizePolicy({ maxBytes: 15 * 1024 });
15
- * ```
16
- */
17
- export declare class SizePolicy implements NPolicy {
18
- private opts;
19
- constructor(opts?: SizePolicyOpts);
20
- call(event: NostrEvent): Promise<NostrRelayOK>;
21
- }
22
- export {};
23
- //# sourceMappingURL=SizePolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SizePolicy.d.ts","sourceRoot":"","sources":["../SizePolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,uCAAuC;AACvC,UAAU,cAAc;IACtB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,qBAAa,UAAW,YAAW,OAAO;IACxC,OAAO,CAAC,IAAI,CAAiB;gBAEjB,IAAI,GAAE,cAAmB;IAK/B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAYrD"}
@@ -1,19 +0,0 @@
1
- class SizePolicy {
2
- opts;
3
- constructor(opts = {}) {
4
- this.opts = opts;
5
- }
6
- // deno-lint-ignore require-await
7
- async call(event) {
8
- const { maxBytes = 8 * 1024 } = this.opts;
9
- const json = JSON.stringify(event);
10
- const size = new TextEncoder().encode(json).length;
11
- if (size > maxBytes) {
12
- return ["OK", event.id, false, `blocked: event is too large`];
13
- }
14
- return ["OK", event.id, true, ""];
15
- }
16
- }
17
- export {
18
- SizePolicy
19
- };
@@ -1,16 +0,0 @@
1
- import type { NostrEvent, NostrRelayInfo, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Allows only the listed pubkeys to post. All other events are rejected.
4
- *
5
- * ```ts
6
- * // Only the given pubkey may post.
7
- * new WhitelistPolicy(['e810fafa1e89cdf80cced8e013938e87e21b699b24c8570537be92aec4b12c18']);
8
- * ```
9
- */
10
- export declare class WhitelistPolicy implements NPolicy {
11
- private pubkeys;
12
- constructor(pubkeys: Iterable<string>);
13
- call({ id, pubkey }: NostrEvent): Promise<NostrRelayOK>;
14
- get info(): NostrRelayInfo;
15
- }
16
- //# sourceMappingURL=WhitelistPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WhitelistPolicy.d.ts","sourceRoot":"","sources":["../WhitelistPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzF;;;;;;;GAOG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,OAAO,CAAmB;gBAEtB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;IAK/B,IAAI,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAU7D,IAAI,IAAI,IAAI,cAAc,CAMzB;CACF"}
@@ -1,25 +0,0 @@
1
- class WhitelistPolicy {
2
- pubkeys;
3
- constructor(pubkeys) {
4
- this.pubkeys = pubkeys;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, pubkey }) {
8
- for (const p of this.pubkeys) {
9
- if (p === pubkey) {
10
- return ["OK", id, true, ""];
11
- }
12
- }
13
- return ["OK", id, false, "blocked: only certain pubkeys are allowed to post"];
14
- }
15
- get info() {
16
- return {
17
- limitation: {
18
- restricted_writes: true
19
- }
20
- };
21
- }
22
- }
23
- export {
24
- WhitelistPolicy
25
- };
@@ -1,26 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
2
- /** Options for the `WoTPolicy`. */
3
- interface WoTPolicyOpts {
4
- /** Store to get kind 3 follow lists from. */
5
- store: NStore;
6
- /** Initial set of trusted pubkeys to query follow lists for. */
7
- pubkeys: Iterable<string>;
8
- /**
9
- * How many levels of follow lists to query.
10
- * `0` will just whitelist the given `pubkeys` without checking their follow lists.
11
- * `1` will query their follows,
12
- * `2` will query their follows follows, etc.
13
- */
14
- depth: number;
15
- }
16
- /** Whitelist pubkeys the given user follows, people those users follow, etc. up to `depth`. */
17
- export declare class WoTPolicy implements NPolicy {
18
- private pubkeys;
19
- private opts;
20
- constructor(opts: WoTPolicyOpts);
21
- call(event: NostrEvent): Promise<NostrRelayOK>;
22
- /** Retrieve the complete set of pubkeys to whitelist. */
23
- private getPubkeys;
24
- }
25
- export {};
26
- //# sourceMappingURL=WoTPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WoTPolicy.d.ts","sourceRoot":"","sources":["../WoTPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjF,mCAAmC;AACnC,UAAU,aAAa;IACrB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1B;;;;;OAKG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,+FAA+F;AAC/F,qBAAa,SAAU,YAAW,OAAO;IACvC,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,IAAI,CAAgB;gBAEhB,IAAI,EAAE,aAAa;IAIzB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAWpD,yDAAyD;YAC3C,UAAU;CAyBzB"}
package/dist/WoTPolicy.js DELETED
@@ -1,39 +0,0 @@
1
- class WoTPolicy {
2
- pubkeys;
3
- opts;
4
- constructor(opts) {
5
- this.opts = opts;
6
- }
7
- async call(event) {
8
- this.pubkeys ??= this.getPubkeys();
9
- const pubkeys = await this.pubkeys;
10
- if (pubkeys.has(event.pubkey)) {
11
- return ["OK", event.id, true, ""];
12
- }
13
- return ["OK", event.id, false, "blocked: only certain pubkeys are allowed to post"];
14
- }
15
- /** Retrieve the complete set of pubkeys to whitelist. */
16
- async getPubkeys() {
17
- const { store, depth } = this.opts;
18
- const pubkeys = /* @__PURE__ */ new Set([...this.opts.pubkeys]);
19
- const authors = new Set(pubkeys);
20
- for (let i = 0; i < depth; i++) {
21
- const events = await store.query([{ kinds: [3], authors: [...authors] }]);
22
- authors.clear();
23
- for (const event of events) {
24
- for (const [name, value] of event.tags) {
25
- if (name === "p") {
26
- if (!pubkeys.has(value)) {
27
- authors.add(value);
28
- }
29
- pubkeys.add(value);
30
- }
31
- }
32
- }
33
- }
34
- return pubkeys;
35
- }
36
- }
37
- export {
38
- WoTPolicy
39
- };
package/dist/mod.d.ts DELETED
@@ -1,21 +0,0 @@
1
- export { AntiDuplicationPolicy } from './AntiDuplicationPolicy.ts';
2
- export { AnyPolicy } from './AnyPolicy.ts';
3
- export { AuthorPolicy } from './AuthorPolicy.ts';
4
- export { DomainPolicy } from './DomainPolicy.ts';
5
- export { FiltersPolicy } from './FiltersPolicy.ts';
6
- export { HashtagPolicy } from './HashtagPolicy.ts';
7
- export { HellthreadPolicy } from './HellthreadPolicy.ts';
8
- export { InvertPolicy } from './InvertPolicy.ts';
9
- export { KeywordPolicy } from './KeywordPolicy.ts';
10
- export { NoOpPolicy } from './NoOpPolicy.ts';
11
- export { OpenAIPolicy } from './OpenAIPolicy.ts';
12
- export { PipePolicy } from './PipePolicy.ts';
13
- export { PowPolicy } from './PowPolicy.ts';
14
- export { PubkeyBanPolicy } from './PubkeyBanPolicy.ts';
15
- export { ReadOnlyPolicy } from './ReadOnlyPolicy.ts';
16
- export { RegexPolicy } from './RegexPolicy.ts';
17
- export { ReplyBotPolicy } from './ReplyBotPolicy.ts';
18
- export { SizePolicy } from './SizePolicy.ts';
19
- export { WhitelistPolicy } from './WhitelistPolicy.ts';
20
- export { WoTPolicy } from './WoTPolicy.ts';
21
- //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../mod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/mod.js DELETED
@@ -1,42 +0,0 @@
1
- import { AntiDuplicationPolicy } from "./AntiDuplicationPolicy.js";
2
- import { AnyPolicy } from "./AnyPolicy.js";
3
- import { AuthorPolicy } from "./AuthorPolicy.js";
4
- import { DomainPolicy } from "./DomainPolicy.js";
5
- import { FiltersPolicy } from "./FiltersPolicy.js";
6
- import { HashtagPolicy } from "./HashtagPolicy.js";
7
- import { HellthreadPolicy } from "./HellthreadPolicy.js";
8
- import { InvertPolicy } from "./InvertPolicy.js";
9
- import { KeywordPolicy } from "./KeywordPolicy.js";
10
- import { NoOpPolicy } from "./NoOpPolicy.js";
11
- import { OpenAIPolicy } from "./OpenAIPolicy.js";
12
- import { PipePolicy } from "./PipePolicy.js";
13
- import { PowPolicy } from "./PowPolicy.js";
14
- import { PubkeyBanPolicy } from "./PubkeyBanPolicy.js";
15
- import { ReadOnlyPolicy } from "./ReadOnlyPolicy.js";
16
- import { RegexPolicy } from "./RegexPolicy.js";
17
- import { ReplyBotPolicy } from "./ReplyBotPolicy.js";
18
- import { SizePolicy } from "./SizePolicy.js";
19
- import { WhitelistPolicy } from "./WhitelistPolicy.js";
20
- import { WoTPolicy } from "./WoTPolicy.js";
21
- export {
22
- AntiDuplicationPolicy,
23
- AnyPolicy,
24
- AuthorPolicy,
25
- DomainPolicy,
26
- FiltersPolicy,
27
- HashtagPolicy,
28
- HellthreadPolicy,
29
- InvertPolicy,
30
- KeywordPolicy,
31
- NoOpPolicy,
32
- OpenAIPolicy,
33
- PipePolicy,
34
- PowPolicy,
35
- PubkeyBanPolicy,
36
- ReadOnlyPolicy,
37
- RegexPolicy,
38
- ReplyBotPolicy,
39
- SizePolicy,
40
- WhitelistPolicy,
41
- WoTPolicy
42
- };
package/dist/mod.js.map DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../mod.ts"],
4
- "sourcesContent": ["export { AntiDuplicationPolicy } from './AntiDuplicationPolicy.ts';\nexport { AnyPolicy } from './AnyPolicy.ts';\nexport { AuthorPolicy } from './AuthorPolicy.ts';\nexport { DomainPolicy } from './DomainPolicy.ts';\nexport { FiltersPolicy } from './FiltersPolicy.ts';\nexport { HashtagPolicy } from './HashtagPolicy.ts';\nexport { HellthreadPolicy } from './HellthreadPolicy.ts';\nexport { InvertPolicy } from './InvertPolicy.ts';\nexport { KeywordPolicy } from './KeywordPolicy.ts';\nexport { NoOpPolicy } from './NoOpPolicy.ts';\nexport { OpenAIPolicy } from './OpenAIPolicy.ts';\nexport { PipePolicy } from './PipePolicy.ts';\nexport { PowPolicy } from './PowPolicy.ts';\nexport { PubkeyBanPolicy } from './PubkeyBanPolicy.ts';\nexport { ReadOnlyPolicy } from './ReadOnlyPolicy.ts';\nexport { RegexPolicy } from './RegexPolicy.ts';\nexport { ReplyBotPolicy } from './ReplyBotPolicy.ts';\nexport { SizePolicy } from './SizePolicy.ts';\nexport { WhitelistPolicy } from './WhitelistPolicy.ts';\nexport { WoTPolicy } from './WoTPolicy.ts';\n"],
5
- "mappings": ";AAAA,SAAS,6BAA6B;AACtC,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;",
6
- "names": []
7
- }