@nostrify/policies 0.36.5 → 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 (133) hide show
  1. package/.turbo/turbo-build.log +24 -2
  2. package/.turbo/turbo-setup.log +22 -0
  3. package/.turbo/turbo-test.log +53 -0
  4. package/AntiDuplicationPolicy.test.ts +54 -41
  5. package/AntiDuplicationPolicy.ts +7 -3
  6. package/AnyPolicy.test.ts +15 -14
  7. package/AnyPolicy.ts +5 -2
  8. package/AuthorPolicy.test.ts +8 -7
  9. package/AuthorPolicy.ts +9 -3
  10. package/CHANGELOG.md +18 -0
  11. package/DomainPolicy.test.ts +130 -77
  12. package/DomainPolicy.ts +3 -3
  13. package/FiltersPolicy.test.ts +14 -7
  14. package/FiltersPolicy.ts +5 -2
  15. package/HashtagPolicy.test.ts +25 -14
  16. package/HashtagPolicy.ts +5 -2
  17. package/HellthreadPolicy.test.ts +10 -9
  18. package/HellthreadPolicy.ts +6 -3
  19. package/InvertPolicy.test.ts +10 -9
  20. package/InvertPolicy.ts +8 -2
  21. package/KeywordPolicy.test.ts +18 -12
  22. package/KeywordPolicy.ts +5 -2
  23. package/NoOpPolicy.test.ts +8 -7
  24. package/NoOpPolicy.ts +1 -1
  25. package/OpenAIPolicy.test.ts +22 -9
  26. package/OpenAIPolicy.ts +5 -2
  27. package/PipePolicy.test.ts +18 -17
  28. package/PipePolicy.ts +5 -2
  29. package/PowPolicy.test.ts +14 -13
  30. package/PowPolicy.ts +6 -3
  31. package/PubkeyBanPolicy.test.ts +15 -8
  32. package/PubkeyBanPolicy.ts +5 -2
  33. package/ReadOnlyPolicy.test.ts +9 -8
  34. package/ReadOnlyPolicy.ts +1 -1
  35. package/RegexPolicy.test.ts +19 -10
  36. package/RegexPolicy.ts +5 -2
  37. package/ReplyBotPolicy.test.ts +43 -27
  38. package/ReplyBotPolicy.ts +6 -3
  39. package/SizePolicy.test.ts +9 -8
  40. package/SizePolicy.ts +6 -2
  41. package/WhitelistPolicy.test.ts +15 -8
  42. package/WhitelistPolicy.ts +6 -2
  43. package/WoTPolicy.test.ts +48 -22
  44. package/WoTPolicy.ts +5 -2
  45. package/mod.ts +20 -20
  46. package/package.json +8 -6
  47. package/tsconfig.json +3 -1
  48. package/.turbo/daemon/7bb8240f68f7ad88-turbo.log.2025-07-29 +0 -0
  49. package/dist/AntiDuplicationPolicy.d.ts +0 -43
  50. package/dist/AntiDuplicationPolicy.d.ts.map +0 -1
  51. package/dist/AntiDuplicationPolicy.js +0 -59
  52. package/dist/AntiDuplicationPolicy.js.map +0 -1
  53. package/dist/AnyPolicy.d.ts +0 -8
  54. package/dist/AnyPolicy.d.ts.map +0 -1
  55. package/dist/AnyPolicy.js +0 -19
  56. package/dist/AnyPolicy.js.map +0 -1
  57. package/dist/AuthorPolicy.d.ts +0 -9
  58. package/dist/AuthorPolicy.d.ts.map +0 -1
  59. package/dist/AuthorPolicy.js +0 -23
  60. package/dist/AuthorPolicy.js.map +0 -1
  61. package/dist/DomainPolicy.d.ts +0 -21
  62. package/dist/DomainPolicy.d.ts.map +0 -1
  63. package/dist/DomainPolicy.js +0 -64
  64. package/dist/DomainPolicy.js.map +0 -1
  65. package/dist/FiltersPolicy.d.ts +0 -18
  66. package/dist/FiltersPolicy.d.ts.map +0 -1
  67. package/dist/FiltersPolicy.js +0 -26
  68. package/dist/FiltersPolicy.js.map +0 -1
  69. package/dist/HashtagPolicy.d.ts +0 -16
  70. package/dist/HashtagPolicy.d.ts.map +0 -1
  71. package/dist/HashtagPolicy.js +0 -25
  72. package/dist/HashtagPolicy.js.map +0 -1
  73. package/dist/HellthreadPolicy.d.ts +0 -14
  74. package/dist/HellthreadPolicy.d.ts.map +0 -1
  75. package/dist/HellthreadPolicy.js +0 -19
  76. package/dist/HellthreadPolicy.js.map +0 -1
  77. package/dist/InvertPolicy.d.ts +0 -9
  78. package/dist/InvertPolicy.d.ts.map +0 -1
  79. package/dist/InvertPolicy.js +0 -20
  80. package/dist/InvertPolicy.js.map +0 -1
  81. package/dist/KeywordPolicy.d.ts +0 -16
  82. package/dist/KeywordPolicy.d.ts.map +0 -1
  83. package/dist/KeywordPolicy.js +0 -25
  84. package/dist/KeywordPolicy.js.map +0 -1
  85. package/dist/NoOpPolicy.d.ts +0 -6
  86. package/dist/NoOpPolicy.d.ts.map +0 -1
  87. package/dist/NoOpPolicy.js +0 -8
  88. package/dist/NoOpPolicy.js.map +0 -1
  89. package/dist/OpenAIPolicy.d.ts +0 -80
  90. package/dist/OpenAIPolicy.d.ts.map +0 -1
  91. package/dist/OpenAIPolicy.js +0 -58
  92. package/dist/OpenAIPolicy.js.map +0 -1
  93. package/dist/PipePolicy.d.ts +0 -26
  94. package/dist/PipePolicy.d.ts.map +0 -1
  95. package/dist/PipePolicy.js +0 -35
  96. package/dist/PipePolicy.js.map +0 -1
  97. package/dist/PowPolicy.d.ts +0 -21
  98. package/dist/PowPolicy.d.ts.map +0 -1
  99. package/dist/PowPolicy.js +0 -32
  100. package/dist/PowPolicy.js.map +0 -1
  101. package/dist/PubkeyBanPolicy.d.ts +0 -15
  102. package/dist/PubkeyBanPolicy.d.ts.map +0 -1
  103. package/dist/PubkeyBanPolicy.js +0 -24
  104. package/dist/PubkeyBanPolicy.js.map +0 -1
  105. package/dist/ReadOnlyPolicy.d.ts +0 -6
  106. package/dist/ReadOnlyPolicy.d.ts.map +0 -1
  107. package/dist/ReadOnlyPolicy.js +0 -8
  108. package/dist/ReadOnlyPolicy.js.map +0 -1
  109. package/dist/RegexPolicy.d.ts +0 -15
  110. package/dist/RegexPolicy.d.ts.map +0 -1
  111. package/dist/RegexPolicy.js +0 -22
  112. package/dist/RegexPolicy.js.map +0 -1
  113. package/dist/ReplyBotPolicy.d.ts +0 -25
  114. package/dist/ReplyBotPolicy.d.ts.map +0 -1
  115. package/dist/ReplyBotPolicy.js +0 -41
  116. package/dist/ReplyBotPolicy.js.map +0 -1
  117. package/dist/SizePolicy.d.ts +0 -23
  118. package/dist/SizePolicy.d.ts.map +0 -1
  119. package/dist/SizePolicy.js +0 -27
  120. package/dist/SizePolicy.js.map +0 -1
  121. package/dist/WhitelistPolicy.d.ts +0 -16
  122. package/dist/WhitelistPolicy.d.ts.map +0 -1
  123. package/dist/WhitelistPolicy.js +0 -31
  124. package/dist/WhitelistPolicy.js.map +0 -1
  125. package/dist/WoTPolicy.d.ts +0 -26
  126. package/dist/WoTPolicy.d.ts.map +0 -1
  127. package/dist/WoTPolicy.js +0 -38
  128. package/dist/WoTPolicy.js.map +0 -1
  129. package/dist/mod.d.ts +0 -21
  130. package/dist/mod.d.ts.map +0 -1
  131. package/dist/mod.js +0 -21
  132. package/dist/mod.js.map +0 -1
  133. package/dist/tsconfig.tsbuildinfo +0 -1
package/SizePolicy.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
1
+ import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
2
 
3
3
  /** Policy options for `SizePolicy`. */
4
4
  interface SizePolicyOpts {
@@ -17,7 +17,11 @@ interface SizePolicyOpts {
17
17
  * ```
18
18
  */
19
19
  export class SizePolicy implements NPolicy {
20
- constructor(private opts: SizePolicyOpts = {}) {}
20
+ private opts: SizePolicyOpts;
21
+
22
+ constructor(opts: SizePolicyOpts = {}) {
23
+ this.opts = opts;
24
+ }
21
25
 
22
26
  // deno-lint-ignore require-await
23
27
  async call(event: NostrEvent): Promise<NostrRelayOK> {
@@ -1,17 +1,24 @@
1
- import { assertEquals } from '@std/assert';
2
- import { finalizeEvent, generateSecretKey } from 'nostr-tools';
1
+ import { test } from "node:test";
2
+ import { deepStrictEqual } from "node:assert";
3
+ import { finalizeEvent, generateSecretKey } from "nostr-tools";
3
4
 
4
- import { WhitelistPolicy } from './WhitelistPolicy.ts';
5
+ import { WhitelistPolicy } from "./WhitelistPolicy.ts";
5
6
 
6
- Deno.test('WhitelistPolicy', async () => {
7
+ await test("WhitelistPolicy", async () => {
7
8
  const [event1, event2, event3] = new Array(3).fill(0).map(() => {
8
9
  return finalizeEvent(
9
- { kind: 1, content: '', tags: [], created_at: 0 },
10
+ { kind: 1, content: "", tags: [], created_at: 0 },
10
11
  generateSecretKey(),
11
12
  );
12
13
  });
13
14
 
14
- assertEquals((await new WhitelistPolicy([]).call(event1))[2], false);
15
- assertEquals((await new WhitelistPolicy([event2.pubkey, event1.pubkey]).call(event3))[2], false);
16
- assertEquals((await new WhitelistPolicy([event2.pubkey, event1.pubkey]).call(event2))[2], true);
15
+ deepStrictEqual((await new WhitelistPolicy([]).call(event1))[2], false);
16
+ deepStrictEqual(
17
+ (await new WhitelistPolicy([event2.pubkey, event1.pubkey]).call(event3))[2],
18
+ false,
19
+ );
20
+ deepStrictEqual(
21
+ (await new WhitelistPolicy([event2.pubkey, event1.pubkey]).call(event2))[2],
22
+ true,
23
+ );
17
24
  });
@@ -1,4 +1,4 @@
1
- import { NostrEvent, NostrRelayInfo, NostrRelayOK, NPolicy } from '@nostrify/types';
1
+ import type { NostrEvent, NostrRelayInfo, NostrRelayOK, NPolicy } from '@nostrify/types';
2
2
 
3
3
  /**
4
4
  * Allows only the listed pubkeys to post. All other events are rejected.
@@ -9,7 +9,11 @@ import { NostrEvent, NostrRelayInfo, NostrRelayOK, NPolicy } from '@nostrify/typ
9
9
  * ```
10
10
  */
11
11
  export class WhitelistPolicy implements NPolicy {
12
- constructor(private pubkeys: Iterable<string>) {}
12
+ private pubkeys: Iterable<string>;
13
+
14
+ constructor(pubkeys: Iterable<string>) {
15
+ this.pubkeys = pubkeys;
16
+ }
13
17
 
14
18
  // deno-lint-ignore require-await
15
19
  async call({ id, pubkey }: NostrEvent): Promise<NostrRelayOK> {
package/WoTPolicy.test.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { ErrorRelay, genEvent, MockRelay } from '@nostrify/nostrify/test';
2
- import { assert, assertFalse } from '@std/assert';
3
- import { generateSecretKey, getPublicKey } from 'nostr-tools';
1
+ import { test } from "node:test";
2
+ import { ErrorRelay, genEvent, MockRelay } from "@nostrify/nostrify/test";
3
+ import { ok } from "node:assert";
4
+ import { generateSecretKey, getPublicKey } from "nostr-tools";
4
5
 
5
- import { WoTPolicy } from './WoTPolicy.ts';
6
+ import { WoTPolicy } from "./WoTPolicy.ts";
6
7
 
7
8
  function keygen(): { pubkey: string; seckey: Uint8Array } {
8
9
  const seckey = generateSecretKey();
@@ -10,26 +11,51 @@ function keygen(): { pubkey: string; seckey: Uint8Array } {
10
11
  return { pubkey, seckey };
11
12
  }
12
13
 
13
- Deno.test('WoTPolicy', async () => {
14
+ await test("WoTPolicy", async () => {
14
15
  const store = new MockRelay();
15
- const [alex, patrick, fiatjaf, replyguy] = [keygen(), keygen(), keygen(), keygen()];
16
-
17
- await store.event(genEvent({ kind: 3, tags: [['p', patrick.pubkey]] }, alex.seckey));
18
- await store.event(genEvent({ kind: 3, tags: [['p', fiatjaf.pubkey]] }, patrick.seckey));
19
- await store.event(genEvent({ kind: 3, tags: [['p', patrick.pubkey]] }, fiatjaf.seckey));
20
-
21
- const policy = new WoTPolicy({ store, pubkeys: [alex.pubkey], depth: 2 });
22
-
23
- assert((await policy.call(genEvent({}, alex.seckey)))[2]);
24
- assert((await policy.call(genEvent({}, patrick.seckey)))[2]);
25
- assert((await policy.call(genEvent({}, fiatjaf.seckey)))[2]);
26
- assertFalse((await policy.call(genEvent({}, replyguy.seckey)))[2]);
16
+ try {
17
+ const [alex, patrick, fiatjaf, replyguy] = [
18
+ keygen(),
19
+ keygen(),
20
+ keygen(),
21
+ keygen(),
22
+ ];
23
+
24
+ await store.event(
25
+ genEvent({ kind: 3, tags: [["p", patrick.pubkey]] }, alex.seckey),
26
+ );
27
+ await store.event(
28
+ genEvent({ kind: 3, tags: [["p", fiatjaf.pubkey]] }, patrick.seckey),
29
+ );
30
+ await store.event(
31
+ genEvent({ kind: 3, tags: [["p", patrick.pubkey]] }, fiatjaf.seckey),
32
+ );
33
+
34
+ const policy = new WoTPolicy({ store, pubkeys: [alex.pubkey], depth: 2 });
35
+
36
+ ok((await policy.call(genEvent({}, alex.seckey)))[2]);
37
+ ok((await policy.call(genEvent({}, patrick.seckey)))[2]);
38
+ ok((await policy.call(genEvent({}, fiatjaf.seckey)))[2]);
39
+ ok(!(await policy.call(genEvent({}, replyguy.seckey)))[2]);
40
+ } finally {
41
+ await store.close();
42
+ }
27
43
  });
28
44
 
29
- Deno.test('WoTPolicy constructor with error store', () => {
45
+ await test("WoTPolicy constructor with error store", async () => {
30
46
  const store = new ErrorRelay();
31
- const alex = keygen();
32
-
33
- // Ensure this doesn't result in an unhandled promise rejection.
34
- new WoTPolicy({ store, pubkeys: [alex.pubkey], depth: 1 });
47
+ try {
48
+ const alex = keygen();
49
+
50
+ // Ensure this doesn't result in an unhandled promise rejection.
51
+ new WoTPolicy({ store, pubkeys: [alex.pubkey], depth: 1 });
52
+ } catch {
53
+ // Expected, ErrorRelay throws errors intentionally
54
+ } finally {
55
+ try {
56
+ await store.close();
57
+ } catch {
58
+ // Expected, ErrorRelay.close() throws an error intentionally
59
+ }
60
+ }
35
61
  });
package/WoTPolicy.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
1
+ import type { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
2
2
 
3
3
  /** Options for the `WoTPolicy`. */
4
4
  interface WoTPolicyOpts {
@@ -18,8 +18,11 @@ interface WoTPolicyOpts {
18
18
  /** Whitelist pubkeys the given user follows, people those users follow, etc. up to `depth`. */
19
19
  export class WoTPolicy implements NPolicy {
20
20
  private pubkeys: Promise<Set<string>> | undefined;
21
+ private opts: WoTPolicyOpts;
21
22
 
22
- constructor(private opts: WoTPolicyOpts) {}
23
+ constructor(opts: WoTPolicyOpts) {
24
+ this.opts = opts;
25
+ }
23
26
 
24
27
  async call(event: NostrEvent): Promise<NostrRelayOK> {
25
28
  this.pubkeys ??= this.getPubkeys();
package/mod.ts CHANGED
@@ -1,20 +1,20 @@
1
- export { AntiDuplicationPolicy } from './AntiDuplicationPolicy.js';
2
- export { AnyPolicy } from './AnyPolicy.js';
3
- export { AuthorPolicy } from './AuthorPolicy.js';
4
- export { DomainPolicy } from './DomainPolicy.js';
5
- export { FiltersPolicy } from './FiltersPolicy.js';
6
- export { HashtagPolicy } from './HashtagPolicy.js';
7
- export { HellthreadPolicy } from './HellthreadPolicy.js';
8
- export { InvertPolicy } from './InvertPolicy.js';
9
- export { KeywordPolicy } from './KeywordPolicy.js';
10
- export { NoOpPolicy } from './NoOpPolicy.js';
11
- export { OpenAIPolicy } from './OpenAIPolicy.js';
12
- export { PipePolicy } from './PipePolicy.js';
13
- export { PowPolicy } from './PowPolicy.js';
14
- export { PubkeyBanPolicy } from './PubkeyBanPolicy.js';
15
- export { ReadOnlyPolicy } from './ReadOnlyPolicy.js';
16
- export { RegexPolicy } from './RegexPolicy.js';
17
- export { ReplyBotPolicy } from './ReplyBotPolicy.js';
18
- export { SizePolicy } from './SizePolicy.js';
19
- export { WhitelistPolicy } from './WhitelistPolicy.js';
20
- export { WoTPolicy } from './WoTPolicy.js';
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';
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@nostrify/policies",
3
- "version": "0.36.5",
3
+ "version": "0.36.7",
4
4
  "exports": {
5
- ".": "./dist/mod.js"
5
+ ".": "./dist/mod.ts"
6
6
  },
7
- "main": "dist/mod.js",
7
+ "main": "./mod.ts",
8
8
  "types": "dist/mod.d.ts",
9
9
  "type": "module",
10
10
  "dependencies": {
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.7",
15
- "@nostrify/types": "0.36.3"
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"
21
+ "build": "npx tsc -p tsconfig.json && node ../../esbuild.config.js --package ./",
22
+ "setup": "pnpm i",
23
+ "test": "node --test --test-concurrency=1 \"**/*.test.ts\""
22
24
  }
23
25
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "include": [
4
- "./**/*.ts"
4
+ "./**/*.ts",
5
+ "!./**/*.test.ts",
6
+ "!./**/*.bench.ts"
5
7
  ],
6
8
  "exclude": [
7
9
  "./dist",
@@ -1,43 +0,0 @@
1
- import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
2
- import { 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,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,EAAE,EAAS,MAAM,UAAU,CAAC;AAErC,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;IACvC,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,yBAAyB;IAE7C,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IA4BpD;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ;CASxB"}
@@ -1,59 +0,0 @@
1
- /**
2
- * Prevent messages with the exact same content from being submitted repeatedly.
3
- *
4
- * 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.
5
- * 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.
6
- *
7
- * ```ts
8
- * // Open a Deno.KV instance.
9
- * const kv = await Deno.openKv();
10
- *
11
- * // Prevent the same message from being posted within 60 seconds.
12
- * new AntiDuplicationPolicy({ kv, expireIn: 60000 });
13
- *
14
- * // Only enforce the policy on messages with at least 50 characters.
15
- * new AntiDuplicationPolicy({ kv, expireIn: 60000, minLength: 50 });
16
- * ```
17
- */
18
- export class AntiDuplicationPolicy {
19
- opts;
20
- constructor(opts) {
21
- this.opts = opts;
22
- }
23
- async call(event) {
24
- const { id, kind } = event;
25
- const { kv, expireIn = 60000, minLength = 50, deobfuscate } = this.opts;
26
- const content = deobfuscate?.(event) ?? event.content;
27
- if (kind === 1 && content.length >= minLength) {
28
- const hash = AntiDuplicationPolicy.hashCode(content);
29
- const key = ['nostrify', 'policies', 'antiduplication', hash];
30
- const { value } = await kv.get(key);
31
- if (value) {
32
- await kv.set(key, true, { expireIn });
33
- return [
34
- 'OK',
35
- id,
36
- false,
37
- 'blocked: the same message has been repeated too many times',
38
- ];
39
- }
40
- await kv.set(key, true, { expireIn });
41
- }
42
- return ['OK', id, true, ''];
43
- }
44
- /**
45
- * Get a "good enough" unique identifier for this content.
46
- * This algorithm was chosen because it's very fast with a low chance of collisions.
47
- * https://stackoverflow.com/a/8831937
48
- */
49
- static hashCode(str) {
50
- let hash = 0;
51
- for (let i = 0, len = str.length; i < len; i++) {
52
- const chr = str.charCodeAt(i);
53
- hash = (hash << 5) - hash + chr;
54
- hash |= 0; // Convert to 32bit integer
55
- }
56
- return hash;
57
- }
58
- }
59
- //# sourceMappingURL=AntiDuplicationPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AntiDuplicationPolicy.js","sourceRoot":"","sources":["../AntiDuplicationPolicy.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,qBAAqB;IACZ;IAApB,YAAoB,IAA+B;QAA/B,SAAI,GAAJ,IAAI,CAA2B;IAAG,CAAC;IAEvD,KAAK,CAAC,IAAI,CAAC,KAAiB;QAC1B,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QAC3B,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,KAAK,EAAE,SAAS,GAAG,EAAE,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QAExE,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC;QAEtD,IAAI,IAAI,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC9C,MAAM,IAAI,GAAG,qBAAqB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACrD,MAAM,GAAG,GAAU,CAAC,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC;YAErE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAEpC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACtC,OAAO;oBACL,IAAI;oBACJ,EAAE;oBACF,KAAK;oBACL,4DAA4D;iBAC7D,CAAC;YACJ,CAAC;YAED,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACK,MAAM,CAAC,QAAQ,CAAC,GAAW;QACjC,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC/C,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;YAChC,IAAI,IAAI,CAAC,CAAC,CAAC,2BAA2B;QACxC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -1,8 +0,0 @@
1
- import { 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,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEpE,yEAAyE;AACzE,qBAAa,SAAU,YAAW,OAAO;IAC3B,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,OAAO,EAAE;IAEjC,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAc3E"}
package/dist/AnyPolicy.js DELETED
@@ -1,19 +0,0 @@
1
- /** Similar to `PipePolicy`, but passes if at least one policy passes. */
2
- export class AnyPolicy {
3
- policies;
4
- constructor(policies) {
5
- this.policies = policies;
6
- }
7
- async call(event, signal) {
8
- let result = ['OK', event.id, false, 'blocked: no policy passed'];
9
- for (const policy of this.policies) {
10
- result = await policy.call(event, signal);
11
- const ok = result[2];
12
- if (ok) {
13
- return result;
14
- }
15
- }
16
- return result;
17
- }
18
- }
19
- //# sourceMappingURL=AnyPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnyPolicy.js","sourceRoot":"","sources":["../AnyPolicy.ts"],"names":[],"mappings":"AAEA,yEAAyE;AACzE,MAAM,OAAO,SAAS;IACA;IAApB,YAAoB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IAAG,CAAC;IAE3C,KAAK,CAAC,IAAI,CAAC,KAAiB,EAAE,MAAoB;QAChD,IAAI,MAAM,GAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,2BAA2B,CAAC,CAAC;QAEhF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnC,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAE1C,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACrB,IAAI,EAAE,EAAE,CAAC;gBACP,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -1,9 +0,0 @@
1
- import { 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,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE5E,wGAAwG;AACxG,qBAAa,YAAa,YAAW,OAAO;IAC9B,OAAO,CAAC,KAAK;IAAU,OAAO,CAAC,MAAM,CAAC;gBAA9B,KAAK,EAAE,MAAM,EAAU,MAAM,CAAC,EAAE,OAAO;IAErD,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAgB3E"}
@@ -1,23 +0,0 @@
1
- /** Rejects events by authors without a kind 0, then optionally applies another policy to the kind 0. */
2
- export class AuthorPolicy {
3
- store;
4
- policy;
5
- constructor(store, policy) {
6
- this.store = store;
7
- this.policy = policy;
8
- }
9
- async call(event, signal) {
10
- const author = event.kind === 0 ? event : await this.store
11
- .query([{ kinds: [0], authors: [event.pubkey], limit: 1 }], { signal })
12
- .then(([event]) => event);
13
- if (!author) {
14
- return ['OK', event.id, false, 'blocked: author is missing a kind 0 event'];
15
- }
16
- if (this.policy) {
17
- const [, , ok, reason] = await this.policy.call(author, signal);
18
- return ['OK', event.id, ok, reason];
19
- }
20
- return ['OK', event.id, true, ''];
21
- }
22
- }
23
- //# sourceMappingURL=AuthorPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AuthorPolicy.js","sourceRoot":"","sources":["../AuthorPolicy.ts"],"names":[],"mappings":"AAEA,wGAAwG;AACxG,MAAM,OAAO,YAAY;IACH;IAAuB;IAA3C,YAAoB,KAAa,EAAU,MAAgB;QAAvC,UAAK,GAAL,KAAK,CAAQ;QAAU,WAAM,GAAN,MAAM,CAAU;IAAG,CAAC;IAE/D,KAAK,CAAC,IAAI,CAAC,KAAiB,EAAE,MAAoB;QAChD,MAAM,MAAM,GAA2B,KAAK,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,KAAK;aAC/E,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;aACtE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC;QAE5B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,2CAA2C,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,CAAC,EAAE,AAAD,EAAG,EAAE,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;YAChE,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;CACF"}
@@ -1,21 +0,0 @@
1
- import { NPolicy, NProfilePointer, NStore } from '@nostrify/types';
2
- import { AuthorPolicy } from './AuthorPolicy.js';
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,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEnE,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,64 +0,0 @@
1
- import { NIP05, NSchema as n } from '@nostrify/nostrify';
2
- import { AuthorPolicy } from './AuthorPolicy.js';
3
- /** Ban events unless their author has a valid NIP-05 name. Domains can also be whitelisted or blacklisted. */
4
- export class DomainPolicy extends AuthorPolicy {
5
- constructor(store, opts = {}) {
6
- super(store, {
7
- async call(event, signal) {
8
- const { blacklist = [], whitelist, lookup = DomainPolicy.lookup } = opts;
9
- const metadata = n.json().pipe(n.metadata()).safeParse(event.content);
10
- if (!metadata.success) {
11
- return ['OK', event.id, false, 'blocked: invalid kind 0 metadata'];
12
- }
13
- const { nip05 } = metadata.data;
14
- if (!nip05) {
15
- return ['OK', event.id, false, 'blocked: missing nip05'];
16
- }
17
- const domain = nip05.split('@').pop();
18
- if (!domain) {
19
- return ['OK', event.id, false, 'blocked: invalid nip05'];
20
- }
21
- if (DomainPolicy.isDomainBlacklisted(domain, blacklist)) {
22
- return ['OK', event.id, false, 'blocked: blacklisted nip05 domain'];
23
- }
24
- try {
25
- const { pubkey } = await lookup(nip05, signal);
26
- if (pubkey !== event.pubkey) {
27
- return ['OK', event.id, false, 'blocked: mismatched nip05 pubkey'];
28
- }
29
- if (whitelist && !whitelist.includes(domain)) {
30
- return [
31
- 'OK',
32
- event.id,
33
- false,
34
- 'blocked: nip05 domain not in whitelist',
35
- ];
36
- }
37
- return ['OK', event.id, true, ''];
38
- }
39
- catch {
40
- return ['OK', event.id, false, 'blocked: failed to lookup nip05'];
41
- }
42
- },
43
- });
44
- }
45
- /** Check if a domain is blacklisted, including subdomains of blacklisted domains. */
46
- static isDomainBlacklisted(domain, blacklist) {
47
- // Check for exact match
48
- if (blacklist.includes(domain)) {
49
- return true;
50
- }
51
- // Check if domain is a subdomain of any blacklisted domain
52
- for (const blacklistedDomain of blacklist) {
53
- if (domain.endsWith('.' + blacklistedDomain)) {
54
- return true;
55
- }
56
- }
57
- return false;
58
- }
59
- /** Default NIP-05 lookup method if one isn't provided by the caller. */
60
- static lookup(nip05, signal) {
61
- return NIP05.lookup(nip05, { signal });
62
- }
63
- }
64
- //# sourceMappingURL=DomainPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DomainPolicy.js","sourceRoot":"","sources":["../DomainPolicy.ts"],"names":[],"mappings":"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"}
@@ -1,18 +0,0 @@
1
- import { 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,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEjF;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC/B,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,WAAW,EAAE;IAGpC,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAOrD"}
@@ -1,26 +0,0 @@
1
- import { matchFilters } from 'nostr-tools';
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 class FiltersPolicy {
14
- filters;
15
- constructor(filters) {
16
- this.filters = filters;
17
- }
18
- // deno-lint-ignore require-await
19
- async call(event) {
20
- if (matchFilters(this.filters, event)) {
21
- return ['OK', event.id, true, ''];
22
- }
23
- return ['OK', event.id, false, "blocked: the event doesn't match the allowed filters"];
24
- }
25
- }
26
- //# sourceMappingURL=FiltersPolicy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FiltersPolicy.js","sourceRoot":"","sources":["../FiltersPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,OAAsB;QAAtB,YAAO,GAAP,OAAO,CAAe;IAAG,CAAC;IAE9C,iCAAiC;IACjC,KAAK,CAAC,IAAI,CAAC,KAAiB;QAC1B,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACpC,CAAC;QAED,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,sDAAsD,CAAC,CAAC;IACzF,CAAC;CACF"}
@@ -1,16 +0,0 @@
1
- import { 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,EAAE,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEpE;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC/B,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,MAAM,EAAE;IAGhC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;CAS5D"}