@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,28 +1,27 @@
1
-
2
- > @nostrify/policies@0.36.5 build /home/sid/repos/nostrify/packages/policies
3
- > tsc -p tsconfig.json && node ../../esbuild.config.js --package ./
4
-
5
-
6
- dist/DomainPolicy.js 2.1kb
7
- dist/ReplyBotPolicy.js 1.4kb
8
- dist/mod.js 1.3kb
9
- dist/AntiDuplicationPolicy.js 1.2kb
10
- dist/WoTPolicy.js 1.0kb
11
- dist/OpenAIPolicy.js 985b
12
- dist/PowPolicy.js 667b
13
- dist/AuthorPolicy.js 640b
14
- dist/HellthreadPolicy.js 494b
15
- dist/WhitelistPolicy.js 490b
16
- dist/SizePolicy.js 453b
17
- dist/HashtagPolicy.js 425b
18
- dist/AnyPolicy.js 412b
19
- dist/KeywordPolicy.js 411b
20
- dist/FiltersPolicy.js 410b
21
- dist/InvertPolicy.js 385b
22
- dist/PipePolicy.js 383b
23
- dist/PubkeyBanPolicy.js 367b
24
- dist/RegexPolicy.js 332b
25
- dist/ReadOnlyPolicy.js 187b
26
- ...and 1 more output file...
27
-
28
- ⚡ Done in 51ms
1
+
2
+
3
+ > @nostrify/policies@0.36.6 build /home/sid/repos/nostrify/packages/policies
4
+ > tsc -p tsconfig.json && node ../../esbuild.config.js --package ./
5
+
6
+
7
+ dist/DomainPolicy.js 2.1kb
8
+ dist/ReplyBotPolicy.js 1.4kb
9
+ dist/mod.js 1.3kb
10
+ dist/AntiDuplicationPolicy.js 1.2kb
11
+ dist/WoTPolicy.js 1.0kb
12
+ dist/OpenAIPolicy.js 985b 
13
+ dist/PowPolicy.js 667b 
14
+ dist/AuthorPolicy.js 640b 
15
+ dist/HellthreadPolicy.js 494b 
16
+ dist/WhitelistPolicy.js 490b 
17
+ dist/SizePolicy.js 453b 
18
+ dist/HashtagPolicy.js 425b 
19
+ dist/AnyPolicy.js 412b 
20
+ dist/KeywordPolicy.js 411b 
21
+ dist/FiltersPolicy.js 410b 
22
+ dist/InvertPolicy.js 385b 
23
+ dist/PipePolicy.js 383b 
24
+ dist/PubkeyBanPolicy.js 367b 
25
+ ...and 3 more output files...
26
+
27
+ ⚡ Done in 23ms
@@ -1,4 +1,53 @@
1
-
2
- > @nostrify/policies@0.36.5 test /home/sid/repos/nostrify/packages/policies
3
- > node --test "**/*.test.ts"
4
-
1
+
2
+
3
+ > @nostrify/policies@0.36.6 test /home/sid/repos/nostrify/packages/policies
4
+ > node --test --test-concurrency=1 "**/*.test.ts"
5
+
6
+ ✔ AntiDuplicationPolicy (319.690432ms)
7
+ ✔ AntiDuplicationPolicy with deobfuscate (44.807015ms)
8
+ ✔ accepts when all policies accept (64.674178ms)
9
+ ✔ accepts when some policies reject (8.399958ms)
10
+ ✔ rejects when all policies reject (5.373917ms)
11
+ ✔ AuthorPolicy (48.081135ms)
12
+ ✔ DomainPolicy allows events from authors with a valid nip05 (46.436288ms)
13
+ ✔ DomainPolicy rejects events from authors without a kind 0 (4.13101ms)
14
+ ✔ DomainPolicy rejects events from authors with a missing nip05 (9.361192ms)
15
+ ✔ DomainPolicy rejects events from authors with a malformed nip05 (11.704458ms)
16
+ ✔ DomainPolicy rejects events from authors with an invalid nip05 (9.725418ms)
17
+ ✔ DomainPolicy rejects events from authors with a blacklisted nip05 domain (12.135733ms)
18
+ ✔ DomainPolicy rejects events from authors who aren't on a whitelisted domain (8.181353ms)
19
+ ✔ DomainPolicy allows events from authors who are on a whitelisted domain (9.511213ms)
20
+ ✔ DomainPolicy rejects events from authors with a subdomain of a blacklisted domain (8.78339ms)
21
+ ✔ DomainPolicy rejects events from authors with a deeply nested subdomain of a blacklisted domain (8.255036ms)
22
+ ✔ DomainPolicy allows events from authors with similar but not subdomain of blacklisted domain (8.391158ms)
23
+ ✔ FiltersPolicy (47.201126ms)
24
+ ✔ HashtagPolicy (57.834978ms)
25
+ ✔ HellthreadPolicy (47.231857ms)
26
+ ✔ InvertPolicy (39.831057ms)
27
+ ✔ KeywordPolicy (52.182532ms)
28
+ ✔ NoOpPolicy (38.95077ms)
29
+ ✔ rejects flagged events (95.404554ms)
30
+ ✔ accepts unflagged events (58.128733ms)
31
+ ✔ passes events through multiple policies (38.444137ms)
32
+ ✔ short-circuits on the first reject (5.71684ms)
33
+ ✔ accepts when all policies accept (4.445368ms)
34
+ ✔ blocks events without a nonce (37.656948ms)
35
+ ✔ accepts event with sufficient POW (0.213227ms)
36
+ ✔ PubkeyBanPolicy (52.882068ms)
37
+ ✔ ReadOnlyPolicy (37.273237ms)
38
+ ✔ RegexPolicy (42.23802ms)
39
+ ✔ ReplyBotPolicy blocks replies within the same second (44.754564ms)
40
+ ✔ ReplyBotPolicy allows replies after 1 second (9.42384ms)
41
+ ✔ ReplyBotPolicy allows replies within the same second from users who are tagged (11.768783ms)
42
+ ✔ SizePolicy (47.893399ms)
43
+ ✔ WhitelistPolicy (48.551241ms)
44
+ ✔ WoTPolicy (74.334084ms)
45
+ ✔ WoTPolicy constructor with error store (0.898097ms)
46
+ ℹ tests 40
47
+ ℹ suites 0
48
+ ℹ pass 40
49
+ ℹ fail 0
50
+ ℹ cancelled 0
51
+ ℹ skipped 0
52
+ ℹ todo 0
53
+ ℹ duration_ms 5386.054741
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.36.7
4
+
5
+ ### Patch Changes
6
+
7
+ - tests should pass now
8
+ - Updated dependencies
9
+ - @nostrify/nostrify@0.46.9
10
+ - @nostrify/types@0.36.5
11
+
3
12
  ## 0.36.6
4
13
 
5
14
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nostrify/policies",
3
- "version": "0.36.6",
3
+ "version": "0.36.7",
4
4
  "exports": {
5
5
  ".": "./dist/mod.ts"
6
6
  },
@@ -11,14 +11,14 @@
11
11
  "@deno/kv": "^0.10.0",
12
12
  "@types/node": "^24.1.0",
13
13
  "nostr-tools": "^2.13.0",
14
- "@nostrify/nostrify": "0.46.8",
15
- "@nostrify/types": "0.36.4"
14
+ "@nostrify/nostrify": "0.46.9",
15
+ "@nostrify/types": "0.36.5"
16
16
  },
17
17
  "publishConfig": {
18
18
  "access": "public"
19
19
  },
20
20
  "scripts": {
21
- "build": "tsc -p tsconfig.json && node ../../esbuild.config.js --package ./",
21
+ "build": "npx tsc -p tsconfig.json && node ../../esbuild.config.js --package ./",
22
22
  "setup": "pnpm i",
23
23
  "test": "node --test --test-concurrency=1 \"**/*.test.ts\""
24
24
  }
@@ -1,43 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- import type { Kv } from '@deno/kv';
3
- /** Policy options for `AntiDuplicationPolicy`. */
4
- interface AntiDuplicationPolicyOpts {
5
- /** Deno.Kv implementation to use. */
6
- kv: Pick<Kv, 'get' | 'set'>;
7
- /** Time in ms until a message with this content may be posted again. Default: `60000` (1 minute). */
8
- expireIn?: number;
9
- /** Note text under this limit will be skipped by the policy. Default: `50`. */
10
- minLength?: number;
11
- /** Normalize the event's content before a hash is taken, to prevent the attacker from making small changes. Should return the normalized content. */
12
- deobfuscate?(event: NostrEvent): string;
13
- }
14
- /**
15
- * Prevent messages with the exact same content from being submitted repeatedly.
16
- *
17
- * It stores a hashcode for each content in a Deno.Kv database and rate-limits them. Only messages that meet the minimum length criteria are selected.
18
- * Each time a matching message is submitted, the timer will reset, so spammers sending the same message will only ever get the first one through.
19
- *
20
- * ```ts
21
- * // Open a Deno.KV instance.
22
- * const kv = await Deno.openKv();
23
- *
24
- * // Prevent the same message from being posted within 60 seconds.
25
- * new AntiDuplicationPolicy({ kv, expireIn: 60000 });
26
- *
27
- * // Only enforce the policy on messages with at least 50 characters.
28
- * new AntiDuplicationPolicy({ kv, expireIn: 60000, minLength: 50 });
29
- * ```
30
- */
31
- export declare class AntiDuplicationPolicy implements NPolicy {
32
- private opts;
33
- constructor(opts: AntiDuplicationPolicyOpts);
34
- call(event: NostrEvent): Promise<NostrRelayOK>;
35
- /**
36
- * Get a "good enough" unique identifier for this content.
37
- * This algorithm was chosen because it's very fast with a low chance of collisions.
38
- * https://stackoverflow.com/a/8831937
39
- */
40
- private static hashCode;
41
- }
42
- export {};
43
- //# sourceMappingURL=AntiDuplicationPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AntiDuplicationPolicy.d.ts","sourceRoot":"","sources":["../AntiDuplicationPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAS,MAAM,UAAU,CAAC;AAE1C,kDAAkD;AAClD,UAAU,yBAAyB;IACjC,qCAAqC;IACrC,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,KAAK,GAAG,KAAK,CAAC,CAAC;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qJAAqJ;IACrJ,WAAW,CAAC,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,qBAAsB,YAAW,OAAO;IACnD,OAAO,CAAC,IAAI,CAA4B;gBAE5B,IAAI,EAAE,yBAAyB;IAIrC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IA4BpD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;CASxB"}
@@ -1,44 +0,0 @@
1
- class AntiDuplicationPolicy {
2
- opts;
3
- constructor(opts) {
4
- this.opts = opts;
5
- }
6
- async call(event) {
7
- const { id, kind } = event;
8
- const { kv, expireIn = 6e4, minLength = 50, deobfuscate } = this.opts;
9
- const content = deobfuscate?.(event) ?? event.content;
10
- if (kind === 1 && content.length >= minLength) {
11
- const hash = AntiDuplicationPolicy.hashCode(content);
12
- const key = ["nostrify", "policies", "antiduplication", hash];
13
- const { value } = await kv.get(key);
14
- if (value) {
15
- await kv.set(key, true, { expireIn });
16
- return [
17
- "OK",
18
- id,
19
- false,
20
- "blocked: the same message has been repeated too many times"
21
- ];
22
- }
23
- await kv.set(key, true, { expireIn });
24
- }
25
- return ["OK", id, true, ""];
26
- }
27
- /**
28
- * Get a "good enough" unique identifier for this content.
29
- * This algorithm was chosen because it's very fast with a low chance of collisions.
30
- * https://stackoverflow.com/a/8831937
31
- */
32
- static hashCode(str) {
33
- let hash = 0;
34
- for (let i = 0, len = str.length; i < len; i++) {
35
- const chr = str.charCodeAt(i);
36
- hash = (hash << 5) - hash + chr;
37
- hash |= 0;
38
- }
39
- return hash;
40
- }
41
- }
42
- export {
43
- AntiDuplicationPolicy
44
- };
@@ -1,8 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Similar to `PipePolicy`, but passes if at least one policy passes. */
3
- export declare class AnyPolicy implements NPolicy {
4
- private policies;
5
- constructor(policies: NPolicy[]);
6
- call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK>;
7
- }
8
- //# sourceMappingURL=AnyPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnyPolicy.d.ts","sourceRoot":"","sources":["../AnyPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,yEAAyE;AACzE,qBAAa,SAAU,YAAW,OAAO;IACvC,OAAO,CAAC,QAAQ,CAAY;gBAChB,QAAQ,EAAE,OAAO,EAAE;IAIzB,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAc3E"}
package/dist/AnyPolicy.js DELETED
@@ -1,20 +0,0 @@
1
- class AnyPolicy {
2
- policies;
3
- constructor(policies) {
4
- this.policies = policies;
5
- }
6
- async call(event, signal) {
7
- let result = ["OK", event.id, false, "blocked: no policy passed"];
8
- for (const policy of this.policies) {
9
- result = await policy.call(event, signal);
10
- const ok = result[2];
11
- if (ok) {
12
- return result;
13
- }
14
- }
15
- return result;
16
- }
17
- }
18
- export {
19
- AnyPolicy
20
- };
@@ -1,9 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
2
- /** Rejects events by authors without a kind 0, then optionally applies another policy to the kind 0. */
3
- export declare class AuthorPolicy implements NPolicy {
4
- private store;
5
- private policy?;
6
- constructor(store: NStore, policy?: NPolicy);
7
- call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK>;
8
- }
9
- //# sourceMappingURL=AuthorPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AuthorPolicy.d.ts","sourceRoot":"","sources":["../AuthorPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEjF,wGAAwG;AACxG,qBAAa,YAAa,YAAW,OAAO;IAC1C,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,MAAM,CAAC,CAAU;gBAEb,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAKrC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAgB3E"}
@@ -1,22 +0,0 @@
1
- class AuthorPolicy {
2
- store;
3
- policy;
4
- constructor(store, policy) {
5
- this.store = store;
6
- this.policy = policy;
7
- }
8
- async call(event, signal) {
9
- const author = event.kind === 0 ? event : await this.store.query([{ kinds: [0], authors: [event.pubkey], limit: 1 }], { signal }).then(([event2]) => event2);
10
- if (!author) {
11
- return ["OK", event.id, false, "blocked: author is missing a kind 0 event"];
12
- }
13
- if (this.policy) {
14
- const [, , ok, reason] = await this.policy.call(author, signal);
15
- return ["OK", event.id, ok, reason];
16
- }
17
- return ["OK", event.id, true, ""];
18
- }
19
- }
20
- export {
21
- AuthorPolicy
22
- };
@@ -1,21 +0,0 @@
1
- import type { NPolicy, NProfilePointer, NStore } from '@nostrify/types';
2
- import { AuthorPolicy } from './AuthorPolicy.ts';
3
- /** Options for `DomainPolicy`. */
4
- interface DomainPolicyOpts {
5
- /** Custom NIP-05 lookup function. */
6
- lookup?(nip05: string, signal?: AbortSignal): Promise<NProfilePointer>;
7
- /** List of domains to blacklist. Reject events from users with a NIP-05 matching any of these domains. */
8
- blacklist?: string[];
9
- /** List of domains to whitelist. If provided, only events from users with a valid NIP-05 on the given domains will be accepted. */
10
- whitelist?: string[];
11
- }
12
- /** Ban events unless their author has a valid NIP-05 name. Domains can also be whitelisted or blacklisted. */
13
- export declare class DomainPolicy extends AuthorPolicy implements NPolicy {
14
- constructor(store: NStore, opts?: DomainPolicyOpts);
15
- /** Check if a domain is blacklisted, including subdomains of blacklisted domains. */
16
- private static isDomainBlacklisted;
17
- /** Default NIP-05 lookup method if one isn't provided by the caller. */
18
- private static lookup;
19
- }
20
- export {};
21
- //# sourceMappingURL=DomainPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DomainPolicy.d.ts","sourceRoot":"","sources":["../DomainPolicy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAc,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,kCAAkC;AAClC,UAAU,gBAAgB;IACxB,qCAAqC;IACrC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACvE,0GAA0G;IAC1G,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,mIAAmI;IACnI,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,8GAA8G;AAC9G,qBAAa,YAAa,SAAQ,YAAa,YAAW,OAAO;gBACnD,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,gBAAqB;IAmDtD,qFAAqF;IACrF,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAmBlC,wEAAwE;IACxE,OAAO,CAAC,MAAM,CAAC,MAAM;CAMtB"}
@@ -1,62 +0,0 @@
1
- import { NIP05, NSchema as n } from "@nostrify/nostrify";
2
- import { AuthorPolicy } from "./AuthorPolicy.js";
3
- class DomainPolicy extends AuthorPolicy {
4
- constructor(store, opts = {}) {
5
- super(store, {
6
- async call(event, signal) {
7
- const { blacklist = [], whitelist, lookup = DomainPolicy.lookup } = opts;
8
- const metadata = n.json().pipe(n.metadata()).safeParse(event.content);
9
- if (!metadata.success) {
10
- return ["OK", event.id, false, "blocked: invalid kind 0 metadata"];
11
- }
12
- const { nip05 } = metadata.data;
13
- if (!nip05) {
14
- return ["OK", event.id, false, "blocked: missing nip05"];
15
- }
16
- const domain = nip05.split("@").pop();
17
- if (!domain) {
18
- return ["OK", event.id, false, "blocked: invalid nip05"];
19
- }
20
- if (DomainPolicy.isDomainBlacklisted(domain, blacklist)) {
21
- return ["OK", event.id, false, "blocked: blacklisted nip05 domain"];
22
- }
23
- try {
24
- const { pubkey } = await lookup(nip05, signal);
25
- if (pubkey !== event.pubkey) {
26
- return ["OK", event.id, false, "blocked: mismatched nip05 pubkey"];
27
- }
28
- if (whitelist && !whitelist.includes(domain)) {
29
- return [
30
- "OK",
31
- event.id,
32
- false,
33
- "blocked: nip05 domain not in whitelist"
34
- ];
35
- }
36
- return ["OK", event.id, true, ""];
37
- } catch {
38
- return ["OK", event.id, false, "blocked: failed to lookup nip05"];
39
- }
40
- }
41
- });
42
- }
43
- /** Check if a domain is blacklisted, including subdomains of blacklisted domains. */
44
- static isDomainBlacklisted(domain, blacklist) {
45
- if (blacklist.includes(domain)) {
46
- return true;
47
- }
48
- for (const blacklistedDomain of blacklist) {
49
- if (domain.endsWith("." + blacklistedDomain)) {
50
- return true;
51
- }
52
- }
53
- return false;
54
- }
55
- /** Default NIP-05 lookup method if one isn't provided by the caller. */
56
- static lookup(nip05, signal) {
57
- return NIP05.lookup(nip05, { signal });
58
- }
59
- }
60
- export {
61
- DomainPolicy
62
- };
@@ -1,18 +0,0 @@
1
- import type { NostrEvent, NostrFilter, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Reject events which don't match the filters.
4
- *
5
- * Only messages which **match** the filters are allowed, and all others are dropped.
6
- * The filter is a [NIP-01](https://github.com/nostr-protocol/nips/blob/master/01.md) relay filter.
7
- *
8
- * ```ts
9
- * // Only allow kind 1, 3, 5, and 7 events.
10
- * new FiltersPolicy([{ kinds: [0, 1, 3, 5, 6, 7] }]);
11
- * ```
12
- */
13
- export declare class FiltersPolicy implements NPolicy {
14
- private filters;
15
- constructor(filters: NostrFilter[]);
16
- call(event: NostrEvent): Promise<NostrRelayOK>;
17
- }
18
- //# sourceMappingURL=FiltersPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FiltersPolicy.d.ts","sourceRoot":"","sources":["../FiltersPolicy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEtF;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,OAAO,CAAgB;gBACnB,OAAO,EAAE,WAAW,EAAE;IAK5B,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAOrD"}
@@ -1,17 +0,0 @@
1
- import { matchFilters } from "nostr-tools";
2
- class FiltersPolicy {
3
- filters;
4
- constructor(filters) {
5
- this.filters = filters;
6
- }
7
- // deno-lint-ignore require-await
8
- async call(event) {
9
- if (matchFilters(this.filters, event)) {
10
- return ["OK", event.id, true, ""];
11
- }
12
- return ["OK", event.id, false, "blocked: the event doesn't match the allowed filters"];
13
- }
14
- }
15
- export {
16
- FiltersPolicy
17
- };
@@ -1,16 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Reject events containing any of the banned hashtags.
4
- *
5
- * @example
6
- * ```ts
7
- * // Reject events with banned hashtags.
8
- * HashtagPolicy(['nsfw']);
9
- * ```
10
- */
11
- export declare class HashtagPolicy implements NPolicy {
12
- private hashtags;
13
- constructor(hashtags: string[]);
14
- call({ id, tags }: NostrEvent): Promise<NostrRelayOK>;
15
- }
16
- //# sourceMappingURL=HashtagPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HashtagPolicy.d.ts","sourceRoot":"","sources":["../HashtagPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,QAAQ,CAAW;gBACf,QAAQ,EAAE,MAAM,EAAE;IAKxB,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAS5D"}
@@ -1,18 +0,0 @@
1
- class HashtagPolicy {
2
- hashtags;
3
- constructor(hashtags) {
4
- this.hashtags = hashtags;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, tags }) {
8
- for (const [name, value] of tags) {
9
- if (name === "t" && this.hashtags.includes(value.toLowerCase())) {
10
- return ["OK", id, false, "blocked: contains a banned hashtag"];
11
- }
12
- }
13
- return ["OK", id, true, ""];
14
- }
15
- }
16
- export {
17
- HashtagPolicy
18
- };
@@ -1,14 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Policy options for `HellthreadPolicy`. */
3
- interface HellthreadPolicyOpts {
4
- /** Total number of "p" tags a kind 1 note may have before it's rejected. Default: `100` */
5
- limit?: number;
6
- }
7
- /** Basic policy to demonstrate how policies work. Accepts all events. */
8
- export declare class HellthreadPolicy implements NPolicy {
9
- private opts;
10
- constructor(opts?: HellthreadPolicyOpts);
11
- call({ id, kind, tags }: NostrEvent): Promise<NostrRelayOK>;
12
- }
13
- export {};
14
- //# sourceMappingURL=HellthreadPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"HellthreadPolicy.d.ts","sourceRoot":"","sources":["../HellthreadPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,6CAA6C;AAC7C,UAAU,oBAAoB;IAC5B,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,yEAAyE;AACzE,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,OAAO,CAAC,IAAI,CAAuB;gBACvB,IAAI,GAAE,oBAAyB;IAKrC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAalE"}
@@ -1,20 +0,0 @@
1
- class HellthreadPolicy {
2
- opts;
3
- constructor(opts = {}) {
4
- this.opts = opts;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, kind, tags }) {
8
- const { limit = 100 } = this.opts;
9
- if (kind === 1) {
10
- const p = tags.filter((tag) => tag[0] === "p");
11
- if (p.length > limit) {
12
- return ["OK", id, false, `blocked: rejected due to ${p.length} "p" tags (${limit} is the limit).`];
13
- }
14
- }
15
- return ["OK", id, true, ""];
16
- }
17
- }
18
- export {
19
- HellthreadPolicy
20
- };
@@ -1,9 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Rejects if the policy passes, passes if the policy rejects. */
3
- export declare class InvertPolicy implements NPolicy {
4
- private policy;
5
- private reason;
6
- constructor(policy: NPolicy, reason: string);
7
- call(event: NostrEvent): Promise<NostrRelayOK>;
8
- }
9
- //# sourceMappingURL=InvertPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InvertPolicy.d.ts","sourceRoot":"","sources":["../InvertPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,kEAAkE;AAClE,qBAAa,YAAa,YAAW,OAAO;IAC1C,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;IAKrC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAUrD"}
@@ -1,20 +0,0 @@
1
- class InvertPolicy {
2
- policy;
3
- reason;
4
- constructor(policy, reason) {
5
- this.policy = policy;
6
- this.reason = reason;
7
- }
8
- async call(event) {
9
- const result = await this.policy.call(event);
10
- const ok = result[2];
11
- if (ok) {
12
- return ["OK", event.id, false, this.reason];
13
- } else {
14
- return ["OK", event.id, true, ""];
15
- }
16
- }
17
- }
18
- export {
19
- InvertPolicy
20
- };
@@ -1,16 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /**
3
- * Reject events containing any of the strings in its content.
4
- *
5
- * @example
6
- * ```ts
7
- * // Reject events with bad words.
8
- * KeywordPolicy(['moo', 'oink', 'honk']);
9
- * ```
10
- */
11
- export declare class KeywordPolicy implements NPolicy {
12
- private words;
13
- constructor(words: Iterable<string>);
14
- call({ id, content }: NostrEvent): Promise<NostrRelayOK>;
15
- }
16
- //# sourceMappingURL=KeywordPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"KeywordPolicy.d.ts","sourceRoot":"","sources":["../KeywordPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,KAAK,CAAmB;gBACpB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC;IAK7B,IAAI,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAS/D"}
@@ -1,18 +0,0 @@
1
- class KeywordPolicy {
2
- words;
3
- constructor(words) {
4
- this.words = words;
5
- }
6
- // deno-lint-ignore require-await
7
- async call({ id, content }) {
8
- for (const word of this.words) {
9
- if (content.toLowerCase().includes(word.toLowerCase())) {
10
- return ["OK", id, false, "blocked: contains a banned word or phrase"];
11
- }
12
- }
13
- return ["OK", id, true, ""];
14
- }
15
- }
16
- export {
17
- KeywordPolicy
18
- };
@@ -1,6 +0,0 @@
1
- import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- /** Basic policy to demonstrate how policies work. Accepts all events. */
3
- export declare class NoOpPolicy implements NPolicy {
4
- call(event: NostrEvent): Promise<NostrRelayOK>;
5
- }
6
- //# sourceMappingURL=NoOpPolicy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NoOpPolicy.d.ts","sourceRoot":"","sources":["../NoOpPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEzE,yEAAyE;AACzE,qBAAa,UAAW,YAAW,OAAO;IAElC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAGrD"}
@@ -1,9 +0,0 @@
1
- class NoOpPolicy {
2
- // deno-lint-ignore require-await
3
- async call(event) {
4
- return ["OK", event.id, true, ""];
5
- }
6
- }
7
- export {
8
- NoOpPolicy
9
- };