Compare commits
10 Commits
980b410957
...
433459d808
Author | SHA1 | Date | |
---|---|---|---|
|
433459d808 | ||
|
7b188170eb | ||
|
d1e726b612 | ||
|
bc81d25f18 | ||
|
6f77ec418b | ||
|
33ef127ca7 | ||
|
0c646c8dcc | ||
|
8a75bc4441 | ||
|
2b6d6b9520 | ||
|
7362216da8 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/npm
|
59
README.md
59
README.md
@ -65,9 +65,40 @@ That's it! 🎉 Now you should check strfry logs to ensure everything is working
|
||||
|
||||
## Available policies
|
||||
|
||||
For complete documentation of policies, see:
|
||||
For complete documentation of policies, see: https://doc.deno.land/https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts
|
||||
|
||||
- https://doc.deno.land/https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts
|
||||
| Policy | Description | Example Options |
|
||||
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
|
||||
| `antiDuplicationPolicy` | Prevent messages with the exact same content from being submitted repeatedly. | `{ ttl: 60000, minLength: 50}` |
|
||||
| `filterPolicy` | Reject all events which don't match the filter. | `{ kinds: [0, 1, 3, 5, 6, 7] }` |
|
||||
| `hellthreadPolicy` | Reject messages that tag too many participants. | `{ limit: 15 }` |
|
||||
| `keywordPolicy` | Reject events containing any of the strings in its content. | `['moo', 'oink', 'honk']` |
|
||||
| `noopPolicy` | Minimal sample policy for demonstration purposes. Allows all events through. | |
|
||||
| `openaiPolicy` | Passes event content to OpenAI and then rejects flagged events. | `{ apiKey: '123...' }` |
|
||||
| `powPolicy` | Reject events which don't meet Proof-of-Work ([NIP-13](https://github.com/nostr-protocol/nips/blob/master/13.md)) criteria. | `{ difficulty: 20 }` |
|
||||
| `pubkeyBanPolicy` | Ban individual pubkeys from publishing events to the relay. | `['e810...', 'fafa...', '1e89...']` |
|
||||
| `rateLimitPolicy` | Rate-limits users by their IP address. | `{ max: 10, interval: 60000 }` |
|
||||
| `readOnlyPolicy` | This policy rejects all messages. | |
|
||||
| `regexPolicy` | Reject events whose content matches the regex. | `/(🟠\|🔥\|😳)ChtaGPT/i` |
|
||||
| `whitelistPolicy` | Allows only the listed pubkeys to post to the relay. All other events are rejected. | `['e810...', 'fafa...', '1e89...']` |
|
||||
|
||||
## Upgrading strfry-policies
|
||||
|
||||
When writing your script, it's a good idea to import the module with a permalink, eg:
|
||||
|
||||
```diff
|
||||
- import * as strfry from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||
+ import * as strfry from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/33ef127ca7599d9d7016786cbe2de34c9536078c/mod.ts';
|
||||
```
|
||||
|
||||
You can also import from a tag:
|
||||
|
||||
```diff
|
||||
- import * as strfry from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts';
|
||||
+ import * as strfry from 'https://gitlab.com/soapbox-pub/strfry-policies/-/raw/v0.1.0/mod.ts';
|
||||
```
|
||||
|
||||
Therefore, to upgrade to a newer version of strfry-policies, you can simply change the import URL.
|
||||
|
||||
## Writing your own policies
|
||||
|
||||
@ -179,6 +210,14 @@ Then, in the pipeline:
|
||||
|
||||
- You should not use `console.log` anywhere in your policies, as strfry expects stdout to be the strfry output message.
|
||||
|
||||
## Usage with Node.js
|
||||
|
||||
We highly recommend running this library with Deno, but for those looking to incorporate it into an existing Node.js project, an NPM version is provided:
|
||||
|
||||
- https://www.npmjs.com/package/strfry-policies
|
||||
|
||||
This version is built with [dnt](https://github.com/denoland/dnt) which provides Node.js shims for Deno features. Some policies that rely on sqlite may not work, but core fuctionality and TypeScript types work fine, so it can be used as a framework to build other policies.
|
||||
|
||||
## Filtering jsonl events with your policy
|
||||
|
||||
It is not currently possible to retroactively filter events on your strfry relay. You can however export the events with `strfry export`, filter them locally, and then import them into a fresh database. You can also use this command to filter Nostr events from any source, not just strfry.
|
||||
@ -199,6 +238,22 @@ Accepted messages will be written to stdout, while rejected messages will be ski
|
||||
|
||||
The command wraps each event in a strfry message of type `new`, with an `IP4` source of `127.0.0.1`, and a timestamp of the current UTC time. Therefore you may want to avoid certain policies such as the `rateLimitPolicy` that don't makes sense in this context.
|
||||
|
||||
## FAQ
|
||||
|
||||
### Why Deno?
|
||||
|
||||
Deno was developed by the creator of Node.js to solve various problems with Node. It implements web standard APIs such as SubtleCrypto and Fetch so your code is compatible with web browsers. It is also significantly faster in benchmarks.
|
||||
|
||||
### Can I integrate this into another project?
|
||||
|
||||
If you're building your own relay, make it compatible with [strfry plugins](https://github.com/hoytech/strfry/blob/master/docs/plugins.md). strfry plugins utilize stdin and stdout of the operating system, so the relay can be written in any programming language and it will be able to utilize plugins written in any programming language.
|
||||
|
||||
If you're writing software that deals with Nostr events in JavaScript or TypeScript, you can import this library and use its functions directly.
|
||||
|
||||
### Is performance good?
|
||||
|
||||
It depends on which policies you use, but the short answer is "yes." Even policies that rely on sqlite (such as `rateLimitPolicy` and `antiDuplicationPolicy`) perform well. You should place those policies at the end of your pipeline so that synchronous policies have the chance to reject sooner. You can also mount a tmpfs volume and pass a `databaseUrl` option into those policies to serve their database from memory.
|
||||
|
||||
## License
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
14
deno.json
14
deno.json
@ -1,11 +1,18 @@
|
||||
{
|
||||
"tasks": {
|
||||
"test": "deno test --allow-read --allow-write",
|
||||
"filter": "deno run -A scripts/filter.ts"
|
||||
"filter": "deno run -A scripts/filter.ts",
|
||||
"npm": "deno run -A scripts/npm.ts"
|
||||
},
|
||||
"test": {
|
||||
"files": {
|
||||
"exclude": ["npm/"]
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"files": {
|
||||
"include": ["."]
|
||||
"include": ["."],
|
||||
"exclude": ["npm/"]
|
||||
},
|
||||
"rules": {
|
||||
"tags": ["recommended"],
|
||||
@ -14,7 +21,8 @@
|
||||
},
|
||||
"fmt": {
|
||||
"files": {
|
||||
"include": ["."]
|
||||
"include": ["."],
|
||||
"exclude": ["npm/"]
|
||||
},
|
||||
"options": {
|
||||
"useTabs": false,
|
||||
|
123
deno.lock
123
deno.lock
@ -143,18 +143,18 @@
|
||||
"https://deno.land/std@0.181.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7",
|
||||
"https://deno.land/std@0.181.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f",
|
||||
"https://deno.land/std@0.181.0/types.d.ts": "dbaeb2c4d7c526db9828fc8df89d8aecf53b9ced72e0c4568f97ddd8cda616a4",
|
||||
"https://deno.land/std@0.86.0/async/deferred.ts": "f89ed49ba5e1dd0227c6bd5b23f017be46c3f92e4f0338dda08ff5aa54b9f6c9",
|
||||
"https://deno.land/std@0.86.0/async/delay.ts": "9de1d8d07d1927767ab7f82434b883f3d8294fb19cad819691a2ad81a728cf3d",
|
||||
"https://deno.land/std@0.86.0/async/mod.ts": "253b41c658d768613eacfb11caa0a9ca7148442f932018a45576f7f27554c853",
|
||||
"https://deno.land/std@0.86.0/async/mux_async_iterator.ts": "b9091909db04cdb0af6f7807677372f64c1488de6c4bd86004511b064bf230d6",
|
||||
"https://deno.land/std@0.86.0/async/pool.ts": "876f9e6815366cd017a3b4fbb9e9ae40310b1b6972f1bd541c94358bc11fb7e5",
|
||||
"https://deno.land/std@0.86.0/encoding/base64.ts": "eecae390f1f1d1cae6f6c6d732ede5276bf4b9cd29b1d281678c054dc5cc009e",
|
||||
"https://deno.land/std@0.86.0/encoding/hex.ts": "f952e0727bddb3b2fd2e6889d104eacbd62e92091f540ebd6459317a61932d9b",
|
||||
"https://deno.land/std@0.86.0/fmt/colors.ts": "d253f2367e5feebcf0f49676533949c09ea07a2d95fb74958f6f5c1c22fbec49",
|
||||
"https://deno.land/std@0.86.0/node/_utils.ts": "067c386d676432e9418808851e8de72df7774f009a652904f62358b4c94504cf",
|
||||
"https://deno.land/std@0.86.0/node/buffer.ts": "e98af24a3210d8fc3f022b6eb26d6e5bdf98fb0e02931e5983d20db9fed1b590",
|
||||
"https://deno.land/std@0.86.0/testing/_diff.ts": "961eaf6d9f5b0a8556c9d835bbc6fa74f5addd7d3b02728ba7936ff93364f7a3",
|
||||
"https://deno.land/std@0.86.0/testing/asserts.ts": "de942b2e1cb6dac1c1c4a7b698be017337e2e2cc2252ae0a6d215c5befde1e82",
|
||||
"https://deno.land/std@0.88.0/async/deferred.ts": "f89ed49ba5e1dd0227c6bd5b23f017be46c3f92e4f0338dda08ff5aa54b9f6c9",
|
||||
"https://deno.land/std@0.88.0/async/delay.ts": "9de1d8d07d1927767ab7f82434b883f3d8294fb19cad819691a2ad81a728cf3d",
|
||||
"https://deno.land/std@0.88.0/async/mod.ts": "253b41c658d768613eacfb11caa0a9ca7148442f932018a45576f7f27554c853",
|
||||
"https://deno.land/std@0.88.0/async/mux_async_iterator.ts": "b9091909db04cdb0af6f7807677372f64c1488de6c4bd86004511b064bf230d6",
|
||||
"https://deno.land/std@0.88.0/async/pool.ts": "876f9e6815366cd017a3b4fbb9e9ae40310b1b6972f1bd541c94358bc11fb7e5",
|
||||
"https://deno.land/std@0.88.0/encoding/base64.ts": "eecae390f1f1d1cae6f6c6d732ede5276bf4b9cd29b1d281678c054dc5cc009e",
|
||||
"https://deno.land/std@0.88.0/encoding/hex.ts": "f952e0727bddb3b2fd2e6889d104eacbd62e92091f540ebd6459317a61932d9b",
|
||||
"https://deno.land/std@0.88.0/fmt/colors.ts": "db22b314a2ae9430ae7460ce005e0a7130e23ae1c999157e3bb77cf55800f7e4",
|
||||
"https://deno.land/std@0.88.0/node/_utils.ts": "067c386d676432e9418808851e8de72df7774f009a652904f62358b4c94504cf",
|
||||
"https://deno.land/std@0.88.0/node/buffer.ts": "e98af24a3210d8fc3f022b6eb26d6e5bdf98fb0e02931e5983d20db9fed1b590",
|
||||
"https://deno.land/std@0.88.0/testing/_diff.ts": "961eaf6d9f5b0a8556c9d835bbc6fa74f5addd7d3b02728ba7936ff93364f7a3",
|
||||
"https://deno.land/std@0.88.0/testing/asserts.ts": "7fae8128125106ddf8e4b3ac84cc3b5fb2378e3fbf8ba38947ebe24faa002ce2",
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mock-fetch.error.ts": "c75e83b959d0b4b18bc5434c15dc5ab40a37fe6069cb51d7607a22391a7b22af",
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mock-fetch.ts": "bc06fb96910aea4c042b7c7387887fecd70f272b7230de0262711c878066111c",
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mock-fetch.type.ts": "c03dc0cb93b4e68496813e9c0a322e3e2a08d16fb78f9b7196a5328cbc0ed771",
|
||||
@ -162,54 +162,55 @@
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mock-scope.ts": "f7235b1efa7371b0698f0b5122eb82d042063411429585e4cdf740f2ae60af94",
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mock-utils.ts": "3a7b12704a75eee2e9721221c3da80bd70ab4f00fdbd1b786fb240f1be20b497",
|
||||
"https://deno.land/x/deno_mock_fetch@1.0.1/mod.ts": "7ea9e35228454b578ff47d42602eba53de0174ffa4ca5567308b11384b55ddd7",
|
||||
"https://deno.land/x/keydb@1.0.0/adapter.ts": "7492c993a6bd5ea033a3423e6383faa34bafd78292cfa344955e263d650112bc",
|
||||
"https://deno.land/x/keydb@1.0.0/jsonb.ts": "05fa1b45f43ea5e755a2271ef3dbeb3e4c64da7053c0c6c53e9d994fa98d9b72",
|
||||
"https://deno.land/x/keydb@1.0.0/keydb.ts": "616c4c866c9e11c29d5654d367468ed51b689565043f53fdeb5eb66f25138156",
|
||||
"https://deno.land/x/keydb@1.0.0/memory.ts": "f0ab6faf293c4ad3539fd3cf89c764d7f34d39d24e471ea59eebb5d1f5a510dc",
|
||||
"https://deno.land/x/keydb@1.0.0/sqlite.ts": "a16e0242077a0bd1bf027f5e5440778c237d5ff2e278aeebb2245c407a4e3b43",
|
||||
"https://deno.land/x/module_cache@0.0.1/mod.ts": "542ea337ec9c5ef4013a2c49a42d9faa9d161898c33629594ee526d883bc2cc6",
|
||||
"https://deno.land/x/sqlite@v2.3.2/build/sqlite.js": "24d7663da39aff93cb7a1c9fef28346d7c457ba30bba7fccfb211a94b4823c29",
|
||||
"https://deno.land/x/sqlite@v2.3.2/build/vfs.js": "ce3b69b82a1723cad2bf06dfee774f461bcc49502a20ec8b99198ceff46cd046",
|
||||
"https://deno.land/x/sqlite@v2.3.2/mod.ts": "1fc2fdc6aca3ffa8b3f4893c2858871e1bb24ab833d1ed732eba911ad44fb495",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/constants.ts": "6032b1a8b2e6ed186460385b83750deb8e9b7b8c6ff100e450605c814585186e",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/db.ts": "f5269a3014907b6758f99c6ac08b6dc1b448415703e745fb57ea3d3f8adb2a97",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/error.ts": "c305a89b28ab5b56e425074849c6544d23e855b92670935d9e965ee68f9a6a9e",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/row_objects.ts": "cf7ad165bb14c0fd346c46a7f3ea08043ace747d1abae3787bbe4b36be11b09c",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/rows.ts": "1b05730096f8df626bfc9d1597a776cc5ac7d989910a20711fa28c7a8daebb0e",
|
||||
"https://deno.land/x/sqlite@v2.3.2/src/wasm.ts": "9747b8c4de5542f2359a35461317f08a244fe8a0933c7e279caad27a0190e6bf",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/_assert.js": "4ae82ea34135ea09f5f727201f345d5c1c2999cee74a7169e1f7954409c22fc3",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/crypto.js": "62e1119c9426fbf642bad03c7b934768c7c6de757c8a3d263f5c46f63b9c51c5",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/hmac.js": "5f10dadb16e809c7533f592b038b05cf2895bc471406a47e5088fccf13615e76",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/pbkdf2.js": "8a47e018fe56ad64cd488ae20558f8a0fc32dbb34bb642365fc10a38d642f733",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/ripemd160.js": "f64586d2f13dbe832fa0f814ca7e1c49e09e73e4cb71f074049bac546ae88eff",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/sha256.js": "a9b2c46d0b81b6a45a27eeb72f15fce97493bcbbc0aef665b7ae7e130035d033",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/sha512.js": "b6821abe4715bff7abfbe04c52f67285ee3ce49cdd463eaf7d87ad635e5ce12a",
|
||||
"https://esm.sh/v114/@noble/hashes@1.2.0/deno/utils.js": "38e315b8dec2c6a5907e34470fef47a459bb562d25821a169763ec43605e3bf1",
|
||||
"https://esm.sh/v114/@noble/secp256k1@1.7.0/deno/secp256k1.mjs": "058a16e83628f6e0d048055f07ddd9400599ad21812a3db314406ef73c591d5e",
|
||||
"https://esm.sh/v114/@noble/secp256k1@1.7.1/deno/secp256k1.mjs": "9616385c64e9ad73da07cbe7342e22f28d16092f632681e5bc19b6f403f7a28d",
|
||||
"https://esm.sh/v114/@scure/base@1.1.1/deno/base.mjs": "c9be265179789182c8a9f719bfce436c09b512a42afa09c3c66d91a9f7d8659e",
|
||||
"https://esm.sh/v114/@scure/bip32@1.1.4/deno/bip32.mjs": "cd928251a5fb5a78e9e65d73fe5ee34dfd00ea7228a5dcd5e4e143a168314fa2",
|
||||
"https://esm.sh/v114/@scure/bip39@1.1.1/deno/bip39.mjs": "ee547a6c3207b6fac81c2cb5d8945994f24bca8bebe2125789e47a9a3846137d",
|
||||
"https://esm.sh/v114/@scure/bip39@1.1.1/deno/wordlists/english.js.js": "d3994c41068f581e6fb3427f53a40dcd4a7309c570b651579339c2b5a33cba5d",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4": "382bc56bde0377c59da1ef58a2fa9d8bdcc92dbf10ef6a50d9253a30efdb9d96",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/deno/nostr-tools.mjs": "5140a23c793227df205f4fe1a388c554530de0e90cf6d43842a28dad6744cd13",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/event.d.ts": "4f9481476116fe98cf7667b2e1b8a8efecde076fb0e5e8c3890ad89c7e1db9d5",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/fakejson.d.ts": "7f56a105c7db5ba6b525c278a4c2e2a4e9bd67fa954e9bc523705f266a39eb53",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/filter.d.ts": "308d8b36f5405af5a34174500d95d30253f70308e21767e1eddbab912f58480f",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/index.d.ts": "4801be2f5314db4c9899dc04dbd0b91f1e02057f1fe624dfe22913111256dc46",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/keys.d.ts": "a95ae8881851ae3e38125606ea1710dc0c684232db18fbfab632d274b58ef04a",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip04.d.ts": "1d7576fda27eba5279dd28cffe2be414335fd2dffb894efd77b61fd30fe89cbd",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip05.d.ts": "f181522bd2d2247f8634a0175579bcc47eec67fdc3a0703328fff1bd1f164e39",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip06.d.ts": "e2cf12b2fa49e0fe1a8f251b5ff8b3bba8d98d26c0c591e3a0e39cf3120ead1e",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip10.d.ts": "2e98303abee5d02b0319c6abd01e3aa54d1337711155f0feb43752a465052e87",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip13.d.ts": "b319fee85d1048d8ad3f19475bf45d300d474cc658075d191b1a0f419ba8a7da",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip19.d.ts": "8baed9c741f2935c7ae61af63cfc14ecf5e8228088dc8b51601a63a237f06a82",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip26.d.ts": "e3dd5da8f9afe76e87dd1aa67f976fd2c0fab09253d02d669d0969b9f434d048",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip39.d.ts": "f508df907affd5310fdd509124e3092be35a039a04c8f06aa367d13782f23416",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/nip57.d.ts": "a7434735da9b5073aa533f88241516d74f6a37da81b097277e8ad90233c50bfc",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/pool.d.ts": "ff40f2acad2252493c04a3a6bf200e44bfc71ad0c3e6eb368475c4ce9c3572b6",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/references.d.ts": "b2e39f5c439380a1dc8e578b471ba3992f33e3936aa0eecf625734c7ba669098",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/relay.d.ts": "9bc6f2897a95ec12d128e94b2e7d6161d30a6bfe8d4350e217fbf4b710988db3",
|
||||
"https://esm.sh/v114/nostr-tools@1.8.4/lib/utils.d.ts": "6f37b09db0dce09f17ff7b70b921b9bb809bcb18c3bc058cb914afdf3c0e774e"
|
||||
"https://deno.land/x/module_cache@0.0.3/mod.ts": "c5e724477146e68b7a4d7ba440cd18f2ef4b28e4244ce48358c79efe98e3cd24",
|
||||
"https://deno.land/x/sqlite@v3.7.1/build/sqlite.d.ts": "d724a21a588a0e19ae46a3476349fe5d75e896735e7362ea8cf997ffad35d0f9",
|
||||
"https://deno.land/x/sqlite@v3.7.1/build/sqlite.js": "c59f109f100c2bae0b9342f04e0d400583e2e3211d08bb71095177a4109ee5bf",
|
||||
"https://deno.land/x/sqlite@v3.7.1/build/vfs.js": "08533cc78fb29b9d9bd62f6bb93e5ef333407013fed185776808f11223ba0e70",
|
||||
"https://deno.land/x/sqlite@v3.7.1/mod.ts": "e09fc79d8065fe222578114b109b1fd60077bff1bb75448532077f784f4d6a83",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/constants.ts": "90f3be047ec0a89bcb5d6fc30db121685fc82cb00b1c476124ff47a4b0472aa9",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/db.ts": "59c6c2b5c4127132558bb8c610eadd811822f1a5d7f9c509704179ca192f94e0",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/error.ts": "f7a15cb00d7c3797da1aefee3cf86d23e0ae92e73f0ba3165496c3816ab9503a",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/function.ts": "e4c83b8ec64bf88bafad2407376b0c6a3b54e777593c70336fb40d43a79865f2",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/query.ts": "d58abda928f6582d77bad685ecf551b1be8a15e8e38403e293ec38522e030cad",
|
||||
"https://deno.land/x/sqlite@v3.7.1/src/wasm.ts": "e79d0baa6e42423257fb3c7cc98091c54399254867e0f34a09b5bdef37bd9487",
|
||||
"https://esm.sh/nostr-tools@1.8.4?pin=v115": "c9ef0cc26d02a4652d9f928e1c44d26493a73126d10f3db3e6ae49fe460f1b1f",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/_assert.js": "4ae82ea34135ea09f5f727201f345d5c1c2999cee74a7169e1f7954409c22fc3",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/crypto.js": "62e1119c9426fbf642bad03c7b934768c7c6de757c8a3d263f5c46f63b9c51c5",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/hmac.js": "b1710485346063845161d5a12c7bb2fe3d8590cd029275a71d5ac811cf635dd2",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/pbkdf2.js": "1d9fe7bc0603ceb01cdcd4ceb97933d0ddfc3a87f5d62f178821f5fda684596e",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/ripemd160.js": "1cdc8771c9e92bceb2f2e64d4433bf6649632830565b01f7542671f473d8772f",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/sha256.js": "6c6206c1161ddfbabf68caa2171bc993a5bd1673ae6c7c196c27351b29a2220f",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/sha512.js": "64c3372f99e94da435cb52ec4cd8f4aae3ef8eb670c0a764e2a3a18c8772406e",
|
||||
"https://esm.sh/v115/@noble/hashes@1.2.0/deno/utils.js": "af93603c58644b29ca99693511033a989099b3bde64fbf6f6b955f0affbdd3de",
|
||||
"https://esm.sh/v115/@noble/secp256k1@1.7.0/deno/secp256k1.mjs": "058a16e83628f6e0d048055f07ddd9400599ad21812a3db314406ef73c591d5e",
|
||||
"https://esm.sh/v115/@noble/secp256k1@1.7.1/deno/secp256k1.mjs": "9616385c64e9ad73da07cbe7342e22f28d16092f632681e5bc19b6f403f7a28d",
|
||||
"https://esm.sh/v115/@scure/base@1.1.1/deno/base.mjs": "c9be265179789182c8a9f719bfce436c09b512a42afa09c3c66d91a9f7d8659e",
|
||||
"https://esm.sh/v115/@scure/bip32@1.1.4/deno/bip32.mjs": "4c3bd36e105190337202f235184eff0048160348ed003ea20e2273205c84ebc5",
|
||||
"https://esm.sh/v115/@scure/bip39@1.1.1/deno/bip39.mjs": "92104c920e3e594af128fb76b0e457a663f24198d1038a08096195039f22d1a1",
|
||||
"https://esm.sh/v115/@scure/bip39@1.1.1/deno/wordlists/english.js": "047776f3a57c8741b54fa829f17a27df84a4eb27c47127d58dc702522c8e0c09",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/deno/nostr-tools.mjs": "3721eef72438d62736d2923d198d18077eb3c003d47eab1a6fca098cac016216",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/event.d.ts": "4f9481476116fe98cf7667b2e1b8a8efecde076fb0e5e8c3890ad89c7e1db9d5",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/fakejson.d.ts": "7f56a105c7db5ba6b525c278a4c2e2a4e9bd67fa954e9bc523705f266a39eb53",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/filter.d.ts": "308d8b36f5405af5a34174500d95d30253f70308e21767e1eddbab912f58480f",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/index.d.ts": "4801be2f5314db4c9899dc04dbd0b91f1e02057f1fe624dfe22913111256dc46",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/keys.d.ts": "a95ae8881851ae3e38125606ea1710dc0c684232db18fbfab632d274b58ef04a",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip04.d.ts": "1d7576fda27eba5279dd28cffe2be414335fd2dffb894efd77b61fd30fe89cbd",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip05.d.ts": "f181522bd2d2247f8634a0175579bcc47eec67fdc3a0703328fff1bd1f164e39",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip06.d.ts": "e2cf12b2fa49e0fe1a8f251b5ff8b3bba8d98d26c0c591e3a0e39cf3120ead1e",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip10.d.ts": "2e98303abee5d02b0319c6abd01e3aa54d1337711155f0feb43752a465052e87",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip13.d.ts": "b319fee85d1048d8ad3f19475bf45d300d474cc658075d191b1a0f419ba8a7da",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip19.d.ts": "8baed9c741f2935c7ae61af63cfc14ecf5e8228088dc8b51601a63a237f06a82",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip26.d.ts": "e3dd5da8f9afe76e87dd1aa67f976fd2c0fab09253d02d669d0969b9f434d048",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip39.d.ts": "f508df907affd5310fdd509124e3092be35a039a04c8f06aa367d13782f23416",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/nip57.d.ts": "a7434735da9b5073aa533f88241516d74f6a37da81b097277e8ad90233c50bfc",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/pool.d.ts": "ff40f2acad2252493c04a3a6bf200e44bfc71ad0c3e6eb368475c4ce9c3572b6",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/references.d.ts": "b2e39f5c439380a1dc8e578b471ba3992f33e3936aa0eecf625734c7ba669098",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/relay.d.ts": "9bc6f2897a95ec12d128e94b2e7d6161d30a6bfe8d4350e217fbf4b710988db3",
|
||||
"https://esm.sh/v115/nostr-tools@1.8.4/lib/utils.d.ts": "6f37b09db0dce09f17ff7b70b921b9bb809bcb18c3bc058cb914afdf3c0e774e",
|
||||
"https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/adapter.ts": "32e5182648011b188952ada0528f564b374260449ec3b06237f36225d4d19510",
|
||||
"https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/jsonb.ts": "1b540f8bd0b43fe847cd3e2a852d2f53e610cd77b81c11d175ebe91a3f110be8",
|
||||
"https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/keydb.ts": "616c4c866c9e11c29d5654d367468ed51b689565043f53fdeb5eb66f25138156",
|
||||
"https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/memory.ts": "f0ab6faf293c4ad3539fd3cf89c764d7f34d39d24e471ea59eebb5d1f5a510dc",
|
||||
"https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/sqlite.ts": "c8f172cfea9425cb16e844622375c9578db508de7d710ad3987cf6cd6bff197a"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { build, emptyDir } from "https://deno.land/x/dnt@0.34.0/mod.ts";
|
||||
import { build, emptyDir } from 'https://deno.land/x/dnt@0.34.0/mod.ts';
|
||||
|
||||
await emptyDir('./npm');
|
||||
|
||||
@ -6,13 +6,13 @@ await build({
|
||||
entryPoints: ['./mod.ts'],
|
||||
outDir: './npm',
|
||||
shims: {
|
||||
// see JS docs for overview and more options
|
||||
deno: true,
|
||||
undici: true,
|
||||
},
|
||||
package: {
|
||||
name: 'strfry-policies',
|
||||
version: Deno.args[0],
|
||||
description: 'Your package.',
|
||||
description: 'Configurable policies for the strfry Nostr relay.',
|
||||
license: 'Unlicense',
|
||||
repository: {
|
||||
type: 'git',
|
||||
@ -22,8 +22,10 @@ await build({
|
||||
url: 'https://gitlab.com/soapbox-pub/strfry-policies/-/issues',
|
||||
},
|
||||
},
|
||||
typeCheck: false,
|
||||
test: false,
|
||||
scriptModule: false,
|
||||
postBuild() {
|
||||
// steps to run after building and before running the tests
|
||||
Deno.copyFileSync('LICENSE', 'npm/LICENSE');
|
||||
Deno.copyFileSync('README.md', 'npm/README.md');
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
export { readLines } from 'https://deno.land/std@0.181.0/io/mod.ts';
|
||||
export { assert, assertEquals } from 'https://deno.land/std@0.181.0/testing/asserts.ts';
|
||||
export { Keydb } from 'https://deno.land/x/keydb@1.0.0/sqlite.ts';
|
||||
export { type Filter, matchFilter, nip13 } from 'https://esm.sh/v114/nostr-tools@1.8.4';
|
||||
export { Keydb } from 'https://raw.githubusercontent.com/alexgleason/Keydb/1bda308df9e589339532daf31f1717ef7a59d2af/sqlite.ts';
|
||||
export { type Filter, matchFilter, nip13 } from 'https://esm.sh/nostr-tools@1.8.4?pin=v115';
|
||||
|
@ -6,20 +6,19 @@ import antiDuplicationPolicy from './anti-duplication-policy.ts';
|
||||
Deno.test({
|
||||
name: 'blocks events that post the same content too quickly',
|
||||
fn: async () => {
|
||||
const opts = { databaseUrl: undefined };
|
||||
const content = 'Spicy peppermint apricot mediterranean ginger carrot spiced juice edamame hummus';
|
||||
|
||||
const msg1 = buildInputMessage({ event: buildEvent({ content }) });
|
||||
|
||||
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'shadowReject');
|
||||
assertEquals((await antiDuplicationPolicy(msg1, opts)).action, 'shadowReject');
|
||||
assertEquals((await antiDuplicationPolicy(msg1)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg1)).action, 'shadowReject');
|
||||
assertEquals((await antiDuplicationPolicy(msg1)).action, 'shadowReject');
|
||||
|
||||
const msg2 = buildInputMessage({ event: buildEvent({ content: 'a' }) });
|
||||
|
||||
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg2, opts)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg2)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg2)).action, 'accept');
|
||||
assertEquals((await antiDuplicationPolicy(msg2)).action, 'accept');
|
||||
},
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ import { Policy } from '../types.ts';
|
||||
* @example
|
||||
* ```ts
|
||||
* // Only allow kind 1, 3, 5, and 7 events.
|
||||
* filterPolicy(msg, { kinds: [0, 1, 3, 5, 7] });
|
||||
* filterPolicy(msg, { kinds: [0, 1, 3, 5, 6, 7] });
|
||||
* ```
|
||||
*/
|
||||
const filterPolicy: Policy<Filter> = ({ event }, filter = {}) => {
|
||||
|
@ -8,7 +8,14 @@ interface POW {
|
||||
difficulty?: number;
|
||||
}
|
||||
|
||||
/** Reject events which don't meet Proof-of-Work ([NIP-13](https://github.com/nostr-protocol/nips/blob/master/13.md)) criteria. */
|
||||
/**
|
||||
* Reject events which don't meet Proof-of-Work ([NIP-13](https://github.com/nostr-protocol/nips/blob/master/13.md)) criteria.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* powPolicy(msg, { difficulty: 20 });
|
||||
* ```
|
||||
*/
|
||||
const powPolicy: Policy<POW> = ({ event }, opts = {}) => {
|
||||
const { difficulty = 1 } = opts;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user