@sharadox/protection-web-library 0.0.0-stage → 0.1.0-development.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENCA.md +76 -0
- package/LICENSE.md +76 -0
- package/NOTICE.md +3 -0
- package/README.md +129 -2
- package/distribution/adaptive-difficulty/index.d.ts +11 -0
- package/distribution/adaptive-difficulty/index.d.ts.map +1 -0
- package/distribution/adaptive-difficulty/index.js +12 -0
- package/distribution/adaptive-difficulty/index.js.map +1 -0
- package/distribution/adaptive-difficulty/type.d.ts +6 -0
- package/distribution/adaptive-difficulty/type.d.ts.map +1 -0
- package/distribution/adaptive-difficulty/type.js +2 -0
- package/distribution/adaptive-difficulty/type.js.map +1 -0
- package/distribution/address-group/index.d.ts +11 -0
- package/distribution/address-group/index.d.ts.map +1 -0
- package/distribution/address-group/index.js +33 -0
- package/distribution/address-group/index.js.map +1 -0
- package/distribution/leading-zero-bits/index.d.ts +8 -0
- package/distribution/leading-zero-bits/index.d.ts.map +1 -0
- package/distribution/leading-zero-bits/index.js +18 -0
- package/distribution/leading-zero-bits/index.js.map +1 -0
- package/distribution/proof-of-work/index.d.ts +20 -0
- package/distribution/proof-of-work/index.d.ts.map +1 -0
- package/distribution/proof-of-work/index.js +49 -0
- package/distribution/proof-of-work/index.js.map +1 -0
- package/distribution/proof-of-work/type.d.ts +37 -0
- package/distribution/proof-of-work/type.d.ts.map +1 -0
- package/distribution/proof-of-work/type.js +2 -0
- package/distribution/proof-of-work/type.js.map +1 -0
- package/distribution/proof-of-work-solver/index.d.ts +12 -0
- package/distribution/proof-of-work-solver/index.d.ts.map +1 -0
- package/distribution/proof-of-work-solver/index.js +23 -0
- package/distribution/proof-of-work-solver/index.js.map +1 -0
- package/distribution/protection-database/type.d.ts +30 -0
- package/distribution/protection-database/type.d.ts.map +1 -0
- package/distribution/protection-database/type.js +2 -0
- package/distribution/protection-database/type.js.map +1 -0
- package/distribution/protection-migration/index.d.ts +18 -0
- package/distribution/protection-migration/index.d.ts.map +1 -0
- package/distribution/protection-migration/index.js +66 -0
- package/distribution/protection-migration/index.js.map +1 -0
- package/distribution/rate-limit/index.d.ts +18 -0
- package/distribution/rate-limit/index.d.ts.map +1 -0
- package/distribution/rate-limit/index.js +68 -0
- package/distribution/rate-limit/index.js.map +1 -0
- package/distribution/rate-limit/type.d.ts +22 -0
- package/distribution/rate-limit/type.d.ts.map +1 -0
- package/distribution/rate-limit/type.js +2 -0
- package/distribution/rate-limit/type.js.map +1 -0
- package/distribution/rate-limit-prune/index.d.ts +14 -0
- package/distribution/rate-limit-prune/index.d.ts.map +1 -0
- package/distribution/rate-limit-prune/index.js +13 -0
- package/distribution/rate-limit-prune/index.js.map +1 -0
- package/distribution/sha-256/index.d.ts +10 -0
- package/distribution/sha-256/index.d.ts.map +1 -0
- package/distribution/sha-256/index.js +71 -0
- package/distribution/sha-256/index.js.map +1 -0
- package/distribution/solution-redemption/index.d.ts +19 -0
- package/distribution/solution-redemption/index.d.ts.map +1 -0
- package/distribution/solution-redemption/index.js +22 -0
- package/distribution/solution-redemption/index.js.map +1 -0
- package/distribution/spending-cap/index.d.ts +14 -0
- package/distribution/spending-cap/index.d.ts.map +1 -0
- package/distribution/spending-cap/index.js +38 -0
- package/distribution/spending-cap/index.js.map +1 -0
- package/distribution/spending-cap/type.d.ts +21 -0
- package/distribution/spending-cap/type.d.ts.map +1 -0
- package/distribution/spending-cap/type.js +2 -0
- package/distribution/spending-cap/type.js.map +1 -0
- package/distribution/token-bucket/index.d.ts +12 -0
- package/distribution/token-bucket/index.d.ts.map +1 -0
- package/distribution/token-bucket/index.js +23 -0
- package/distribution/token-bucket/index.js.map +1 -0
- package/distribution/token-bucket/type.d.ts +17 -0
- package/distribution/token-bucket/type.d.ts.map +1 -0
- package/distribution/token-bucket/type.js +2 -0
- package/distribution/token-bucket/type.js.map +1 -0
- package/distribution/used-challenge-prune/index.d.ts +13 -0
- package/distribution/used-challenge-prune/index.d.ts.map +1 -0
- package/distribution/used-challenge-prune/index.js +12 -0
- package/distribution/used-challenge-prune/index.js.map +1 -0
- package/package.json +88 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** How many actions a key may take: `capacity` at once, then `refillPerSecond` more each second. */
|
|
2
|
+
export interface TokenBucketRule {
|
|
3
|
+
capacity: number;
|
|
4
|
+
refillPerSecond: number;
|
|
5
|
+
}
|
|
6
|
+
/** What is remembered per key: tokens left and when (milliseconds since 1970). */
|
|
7
|
+
export interface TokenBucket {
|
|
8
|
+
tokens: number;
|
|
9
|
+
updatedAt: number;
|
|
10
|
+
}
|
|
11
|
+
/** Whether the action may go ahead, the bucket to store, and how long to wait when it may not. */
|
|
12
|
+
export interface TokenBucketResult {
|
|
13
|
+
allowed: boolean;
|
|
14
|
+
bucket: TokenBucket;
|
|
15
|
+
retryAfterSeconds: number;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../source/token-bucket/type.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,kGAAkG;AAClG,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../source/token-bucket/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { ProtectionDatabase } from "@sharadox/protection-web-library/protection-database/type";
|
|
3
|
+
/**
|
|
4
|
+
* Forgets used challenges that have expired (their solutions are refused as expired anyway), from a daily job.
|
|
5
|
+
* Returns how many were deleted.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* await pruneUsedChallenges(database);
|
|
9
|
+
*/
|
|
10
|
+
export declare function pruneUsedChallenges(database: Kysely<ProtectionDatabase>, { now }?: {
|
|
11
|
+
now?: number;
|
|
12
|
+
}): Promise<number>;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/used-challenge-prune/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAC;AAEpG;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,CAAC,kBAAkB,CAAC,EACpC,EAAE,GAAgB,EAAE,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAC1C,OAAO,CAAC,MAAM,CAAC,CAGjB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forgets used challenges that have expired (their solutions are refused as expired anyway), from a daily job.
|
|
3
|
+
* Returns how many were deleted.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* await pruneUsedChallenges(database);
|
|
7
|
+
*/
|
|
8
|
+
export async function pruneUsedChallenges(database, { now = Date.now() } = {}) {
|
|
9
|
+
const result = await database.deleteFrom("used_challenge").where("expires_at", "<", new Date(now)).executeTakeFirst();
|
|
10
|
+
return Number(result.numDeletedRows);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/used-challenge-prune/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAoC,EACpC,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,KAAuB,EAAE;IAE3C,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,YAAY,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC;IACtH,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/protection-web-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0-development.12",
|
|
4
|
+
"description": "Protection for web forms and APIs: layered rate limits, proof-of-work challenges and spending caps.",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "SEE LICENSE IN LICENCA.md",
|
|
7
|
+
"author": "Sharadox <contact@sharadox.com>",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./*/type": {
|
|
11
|
+
"sharadox-source": "./source/*/type.ts",
|
|
12
|
+
"types": "./distribution/*/type.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./*": {
|
|
15
|
+
"sharadox-source": [
|
|
16
|
+
"./source/*/index.ts"
|
|
17
|
+
],
|
|
18
|
+
"types": "./distribution/*/index.d.ts",
|
|
19
|
+
"default": "./distribution/*/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"distribution",
|
|
24
|
+
"LICENCA.md",
|
|
25
|
+
"LICENSE.md",
|
|
26
|
+
"NOTICE.md"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=26"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"lint-staged": {
|
|
36
|
+
"*.{ts,js,mjs,cjs}": [
|
|
37
|
+
"prettier --write",
|
|
38
|
+
"eslint --fix --max-warnings=0"
|
|
39
|
+
],
|
|
40
|
+
"*.{json,md,yml,yaml}": "prettier --write"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@sharadox/database-web-library": "0.1.0-development.9",
|
|
44
|
+
"@sharadox/web-library": "^0.11.1",
|
|
45
|
+
"kysely": "^0.28.19"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@electric-sql/pglite": "0.5.16",
|
|
49
|
+
"@sharadox/es-lint-configuration-web-library": "^0.1.3",
|
|
50
|
+
"@sharadox/library-build-web-library": "^0.2.1",
|
|
51
|
+
"@sharadox/prettier-configuration-web-library": "^0.1.2",
|
|
52
|
+
"@sharadox/turborepo-configuration-web-library": "^0.1.4",
|
|
53
|
+
"@sharadox/type-script-configuration-web-library": "^0.2.3",
|
|
54
|
+
"@sharadox/vitest-configuration-web-library": "^0.2.1",
|
|
55
|
+
"@types/node": "^26.6.6",
|
|
56
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
57
|
+
"eslint": "9.39.5",
|
|
58
|
+
"happy-dom": "^21.0.4",
|
|
59
|
+
"husky": "^9.1.7",
|
|
60
|
+
"lint-staged": "^17.6.2",
|
|
61
|
+
"prettier": "^3.10.1",
|
|
62
|
+
"turbo": "^2.11.13",
|
|
63
|
+
"typedoc": "^0.28.20",
|
|
64
|
+
"typescript": "6.0.3",
|
|
65
|
+
"vitest": "^5.1.1"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "git+https://github.com/Sharadox/protection-web-library.git"
|
|
70
|
+
},
|
|
71
|
+
"homepage": "https://github.com/Sharadox/protection-web-library#readme",
|
|
72
|
+
"keywords": [
|
|
73
|
+
"rate-limit",
|
|
74
|
+
"proof-of-work",
|
|
75
|
+
"abuse",
|
|
76
|
+
"denial-of-wallet",
|
|
77
|
+
"security",
|
|
78
|
+
"forms"
|
|
79
|
+
],
|
|
80
|
+
"scripts": {
|
|
81
|
+
"build": "library-build",
|
|
82
|
+
"lint": "eslint --max-warnings=0 .",
|
|
83
|
+
"format": "prettier --write .",
|
|
84
|
+
"format:check": "prettier --check .",
|
|
85
|
+
"type-check": "tsc --noEmit",
|
|
86
|
+
"test:unit": "vitest run --coverage",
|
|
87
|
+
"test:benchmark": "vitest bench --run --passWithNoTests",
|
|
88
|
+
"documentation": "typedoc",
|
|
89
|
+
"verify": "turbo run format:check lint type-check test:unit test:benchmark build"
|
|
90
|
+
}
|
|
6
91
|
}
|