@bitsocial/spam-blocker-challenge 0.0.0
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/LICENSE +674 -0
- package/README.md +49 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +7 -0
- package/dist/pkc-js-signer.d.ts +4 -0
- package/dist/pkc-js-signer.d.ts.map +1 -0
- package/dist/plebbit-js-signer.d.ts +4 -0
- package/dist/plebbit-js-signer.d.ts.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.d.ts.map +1 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @bitsocial/spam-blocker-challenge
|
|
2
|
+
|
|
3
|
+
A Bitsocial challenge plugin that protects communities from spam by evaluating publication risk scores and optionally presenting an interactive challenge to users.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the challenge using the Bitsocial CLI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bitsocial challenge install @bitsocial/spam-blocker-challenge
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configuration
|
|
14
|
+
|
|
15
|
+
Configure the challenge for your community using the CLI:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bitsocial community edit
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then add or edit the `challenges` array in your community settings to include the spam blocker challenge with your desired options.
|
|
22
|
+
|
|
23
|
+
## Options
|
|
24
|
+
|
|
25
|
+
| Option | Default | Description |
|
|
26
|
+
| --------------------- | ------------------------------------------ | --------------------------------------------------------------------------- |
|
|
27
|
+
| `serverUrl` | `https://spamblocker.bitsocial.net/api/v1` | URL of the Bitsocial spam blocker server |
|
|
28
|
+
| `autoAcceptThreshold` | `0.2` | Auto-accept publications with a risk score below this value |
|
|
29
|
+
| `autoRejectThreshold` | `0.8` | Auto-reject publications with a risk score above this value |
|
|
30
|
+
| `countryBlacklist` | _(empty)_ | Comma-separated ISO 3166-1 alpha-2 country codes to block (e.g. `RU,CN,KP`) |
|
|
31
|
+
| `maxIpRisk` | `1.0` | Reject if IP risk score exceeds this threshold (estimation only) |
|
|
32
|
+
| `blockVpn` | `false` | Reject publications from VPN IPs (estimation only) |
|
|
33
|
+
| `blockProxy` | `false` | Reject publications from proxy IPs (estimation only) |
|
|
34
|
+
| `blockTor` | `false` | Reject publications from Tor exit nodes (estimation only) |
|
|
35
|
+
| `blockDatacenter` | `false` | Reject publications from datacenter IPs (estimation only) |
|
|
36
|
+
|
|
37
|
+
## How It Works
|
|
38
|
+
|
|
39
|
+
1. When a user publishes to a community, the challenge sends the publication to the spam blocker server's `/evaluate` endpoint.
|
|
40
|
+
2. The server returns a **risk score** between 0 and 1.
|
|
41
|
+
3. Based on the configured thresholds:
|
|
42
|
+
- **Below `autoAcceptThreshold`**: The publication is automatically accepted.
|
|
43
|
+
- **Above `autoRejectThreshold`**: The publication is automatically rejected.
|
|
44
|
+
- **Between thresholds**: The user is presented with an interactive challenge (iframe). Upon completion, the server's `/challenge/verify` endpoint confirms whether the user passed.
|
|
45
|
+
4. After challenge verification, additional IP-based policies (country, VPN, proxy, Tor, datacenter blocking) are applied if configured.
|
|
46
|
+
|
|
47
|
+
## License
|
|
48
|
+
|
|
49
|
+
`@bitsocial/spam-blocker-challenge` is licensed under `GPL-3.0-or-later`. See [`LICENSE`](./LICENSE).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ChallengeFileInput, GetChallengeArgs } from "@pkcprotocol/pkc-js/dist/node/community/types.js";
|
|
2
|
+
declare function ChallengeFileFactory(_communityChallengeSettings: GetChallengeArgs["challengeSettings"]): ChallengeFileInput;
|
|
3
|
+
export default ChallengeFileFactory;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,kBAAkB,EAGlB,gBAAgB,EACnB,MAAM,kDAAkD,CAAC;AAoW1D,iBAAS,oBAAoB,CAAC,2BAA2B,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,kBAAkB,CAEpH;AAED,eAAe,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
// src/pkc-js-signer.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { pathToFileURL } from "url";
|
|
5
|
+
import * as ed from "@noble/ed25519";
|
|
6
|
+
import { fromString as uint8ArrayFromString } from "uint8arrays/from-string";
|
|
7
|
+
var require2 = createRequire(import.meta.url);
|
|
8
|
+
var pkcEntry = require2.resolve("@pkcprotocol/pkc-js");
|
|
9
|
+
var pkcRoot = path.resolve(path.dirname(pkcEntry), "..", "..");
|
|
10
|
+
var signerUtilUrl = pathToFileURL(path.join(pkcRoot, "dist/node/signer/util.js")).href;
|
|
11
|
+
var [{ getPublicKeyFromPrivateKey }] = await Promise.all([import(signerUtilUrl)]);
|
|
12
|
+
var signBufferEd25519 = async (bufferToSign, privateKeyBase64) => {
|
|
13
|
+
const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, "base64");
|
|
14
|
+
return ed.sign(bufferToSign, privateKeyBuffer);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// ../shared/dist/types.js
|
|
18
|
+
import countries from "i18n-iso-countries";
|
|
19
|
+
import { z } from "zod";
|
|
20
|
+
var ISO_COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;
|
|
21
|
+
var isIsoCountryCode = (value) => ISO_COUNTRY_CODE_REGEX.test(value) && countries.isValid(value);
|
|
22
|
+
var isHttpUrl = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
const url = new URL(value);
|
|
25
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var UnitIntervalSchema = z.number().finite().min(0).max(1);
|
|
31
|
+
var UnixTimestampSchema = z.number().finite().int().nonnegative();
|
|
32
|
+
var IsoCountryCodeSchema = z.string().trim().transform((value) => value.toUpperCase()).refine((value) => isIsoCountryCode(value), {
|
|
33
|
+
message: "Unknown ISO 3166-1 alpha-2 country code"
|
|
34
|
+
});
|
|
35
|
+
var EvaluateResponseSchema = z.object({
|
|
36
|
+
riskScore: UnitIntervalSchema,
|
|
37
|
+
explanation: z.string().optional(),
|
|
38
|
+
sessionId: z.string(),
|
|
39
|
+
challengeUrl: z.url().refine((value) => isHttpUrl(value), {
|
|
40
|
+
message: "challengeUrl must be a valid HTTP/HTTPS URL"
|
|
41
|
+
}),
|
|
42
|
+
challengeExpiresAt: UnixTimestampSchema.optional()
|
|
43
|
+
});
|
|
44
|
+
var VerifyResponseSchema = z.object({
|
|
45
|
+
success: z.boolean(),
|
|
46
|
+
error: z.string().optional(),
|
|
47
|
+
ipRisk: UnitIntervalSchema.optional(),
|
|
48
|
+
ipAddressCountry: IsoCountryCodeSchema.optional(),
|
|
49
|
+
challengeType: z.string().optional(),
|
|
50
|
+
ipTypeEstimation: z.string().optional()
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// src/schema.ts
|
|
54
|
+
import { z as z2 } from "zod";
|
|
55
|
+
var normalizeServerUrl = (url) => url.replace(/\/+$/, "");
|
|
56
|
+
var isHttpUrl2 = (value) => {
|
|
57
|
+
try {
|
|
58
|
+
const parsed = new URL(value);
|
|
59
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var createOptionsSchema = (optionInputs2) => {
|
|
65
|
+
const optionDefaults = optionInputs2.reduce(
|
|
66
|
+
(acc, input) => {
|
|
67
|
+
acc[input.option] = input.default;
|
|
68
|
+
return acc;
|
|
69
|
+
},
|
|
70
|
+
{}
|
|
71
|
+
);
|
|
72
|
+
const getOptionDefault = (option) => optionDefaults[option];
|
|
73
|
+
const resolveOptionString = (value, option) => {
|
|
74
|
+
if (typeof value === "string") {
|
|
75
|
+
const trimmed = value.trim();
|
|
76
|
+
return trimmed ? trimmed : getOptionDefault(option);
|
|
77
|
+
}
|
|
78
|
+
if (value === void 0 || value === null) {
|
|
79
|
+
return getOptionDefault(option);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
};
|
|
83
|
+
const normalizeServerUrlInput = (value) => {
|
|
84
|
+
const resolved = resolveOptionString(value, "serverUrl");
|
|
85
|
+
if (typeof resolved === "string") {
|
|
86
|
+
return normalizeServerUrl(resolved);
|
|
87
|
+
}
|
|
88
|
+
return resolved;
|
|
89
|
+
};
|
|
90
|
+
const numberOptionSchema = (option) => z2.preprocess(
|
|
91
|
+
(value) => resolveOptionString(value, option),
|
|
92
|
+
z2.string().transform((value, ctx) => {
|
|
93
|
+
const parsed = Number(value);
|
|
94
|
+
if (!Number.isFinite(parsed)) {
|
|
95
|
+
ctx.addIssue({
|
|
96
|
+
code: z2.ZodIssueCode.custom,
|
|
97
|
+
message: `Invalid ${option} option '${value}'`
|
|
98
|
+
});
|
|
99
|
+
return z2.NEVER;
|
|
100
|
+
}
|
|
101
|
+
return parsed;
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
const booleanOptionSchema = (option) => z2.preprocess(
|
|
105
|
+
(value) => {
|
|
106
|
+
const resolved = resolveOptionString(value, option);
|
|
107
|
+
if (typeof resolved === "string") {
|
|
108
|
+
return resolved.trim().toLowerCase();
|
|
109
|
+
}
|
|
110
|
+
return resolved;
|
|
111
|
+
},
|
|
112
|
+
z2.enum(["true", "false"]).transform((value) => value === "true")
|
|
113
|
+
);
|
|
114
|
+
const countryBlacklistSchema = z2.preprocess(
|
|
115
|
+
(value) => resolveOptionString(value, "countryBlacklist"),
|
|
116
|
+
z2.string().transform((value, ctx) => {
|
|
117
|
+
if (!value) return /* @__PURE__ */ new Set();
|
|
118
|
+
const entries = value.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
119
|
+
const codes = /* @__PURE__ */ new Set();
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
const parsed = IsoCountryCodeSchema.safeParse(entry);
|
|
122
|
+
if (!parsed.success) {
|
|
123
|
+
ctx.addIssue({
|
|
124
|
+
code: z2.ZodIssueCode.custom,
|
|
125
|
+
message: `Unknown ISO 3166-1 alpha-2 country code '${entry}' in countryBlacklist`
|
|
126
|
+
});
|
|
127
|
+
return z2.NEVER;
|
|
128
|
+
}
|
|
129
|
+
codes.add(parsed.data);
|
|
130
|
+
}
|
|
131
|
+
return codes;
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
const schema = z2.preprocess(
|
|
135
|
+
(value) => value && typeof value === "object" ? value : {},
|
|
136
|
+
z2.object({
|
|
137
|
+
serverUrl: z2.preprocess(
|
|
138
|
+
normalizeServerUrlInput,
|
|
139
|
+
z2.url().refine(isHttpUrl2, {
|
|
140
|
+
message: "Server URL must use http or https"
|
|
141
|
+
})
|
|
142
|
+
),
|
|
143
|
+
autoAcceptThreshold: numberOptionSchema("autoAcceptThreshold").refine((value) => value >= 0 && value <= 1, {
|
|
144
|
+
message: "autoAcceptThreshold must be between 0 and 1"
|
|
145
|
+
}),
|
|
146
|
+
autoRejectThreshold: numberOptionSchema("autoRejectThreshold").refine((value) => value >= 0 && value <= 1, {
|
|
147
|
+
message: "autoRejectThreshold must be between 0 and 1"
|
|
148
|
+
}),
|
|
149
|
+
countryBlacklist: countryBlacklistSchema,
|
|
150
|
+
maxIpRisk: numberOptionSchema("maxIpRisk").refine((value) => value >= 0 && value <= 1, {
|
|
151
|
+
message: "maxIpRisk must be between 0 and 1"
|
|
152
|
+
}),
|
|
153
|
+
blockVpn: booleanOptionSchema("blockVpn"),
|
|
154
|
+
blockProxy: booleanOptionSchema("blockProxy"),
|
|
155
|
+
blockTor: booleanOptionSchema("blockTor"),
|
|
156
|
+
blockDatacenter: booleanOptionSchema("blockDatacenter")
|
|
157
|
+
}).superRefine((data, ctx) => {
|
|
158
|
+
if (data.autoAcceptThreshold > data.autoRejectThreshold) {
|
|
159
|
+
ctx.addIssue({
|
|
160
|
+
code: z2.ZodIssueCode.custom,
|
|
161
|
+
message: "autoAcceptThreshold must be less than or equal to autoRejectThreshold",
|
|
162
|
+
path: ["autoAcceptThreshold"]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
return schema;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/index.ts
|
|
171
|
+
import * as cborg from "cborg";
|
|
172
|
+
import { fromString as uint8ArrayFromString2 } from "uint8arrays/from-string";
|
|
173
|
+
import Logger from "@pkc/pkc-logger";
|
|
174
|
+
var log = Logger("bitsocial:community:challenge:spam-blocker");
|
|
175
|
+
var LEGACY_RUNTIME_COMMUNITY_KEY = String.fromCharCode(115, 117, 98, 112, 108, 101, 98, 98, 105, 116);
|
|
176
|
+
var DEFAULT_SERVER_URL = "https://spamblocker.bitsocial.net/api/v1";
|
|
177
|
+
var optionInputs = [
|
|
178
|
+
{
|
|
179
|
+
option: "serverUrl",
|
|
180
|
+
label: "Server URL",
|
|
181
|
+
default: DEFAULT_SERVER_URL,
|
|
182
|
+
description: "URL of the Bitsocial Spam Blocker server",
|
|
183
|
+
placeholder: "https://spamblocker.bitsocial.net/api/v1"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
option: "autoAcceptThreshold",
|
|
187
|
+
label: "Auto-Accept Threshold",
|
|
188
|
+
default: "0.2",
|
|
189
|
+
description: "Auto-accept publications below this risk score",
|
|
190
|
+
placeholder: "0.2"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
option: "autoRejectThreshold",
|
|
194
|
+
label: "Auto-Reject Threshold",
|
|
195
|
+
default: "0.8",
|
|
196
|
+
description: "Auto-reject publications above this risk score",
|
|
197
|
+
placeholder: "0.8"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
option: "countryBlacklist",
|
|
201
|
+
label: "Country Blacklist",
|
|
202
|
+
default: "",
|
|
203
|
+
description: "Comma-separated ISO 3166-1 alpha-2 country codes to block",
|
|
204
|
+
placeholder: "RU,CN,KP,US"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
option: "maxIpRisk",
|
|
208
|
+
label: "Max IP Risk",
|
|
209
|
+
default: "1.0",
|
|
210
|
+
description: "Reject if ipRisk from /verify exceeds this threshold (estimation only, not 100% accurate)",
|
|
211
|
+
placeholder: "1.0"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
option: "blockVpn",
|
|
215
|
+
label: "Block VPN",
|
|
216
|
+
default: "false",
|
|
217
|
+
description: "Reject publications from VPN IPs (estimation only, not 100% accurate)",
|
|
218
|
+
placeholder: "true"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
option: "blockProxy",
|
|
222
|
+
label: "Block Proxy",
|
|
223
|
+
default: "false",
|
|
224
|
+
description: "Reject publications from proxy IPs (estimation only, not 100% accurate)",
|
|
225
|
+
placeholder: "true"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
option: "blockTor",
|
|
229
|
+
label: "Block Tor",
|
|
230
|
+
default: "false",
|
|
231
|
+
description: "Reject publications from Tor exit nodes (estimation only, not 100% accurate)",
|
|
232
|
+
placeholder: "true"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
option: "blockDatacenter",
|
|
236
|
+
label: "Block Datacenter",
|
|
237
|
+
default: "false",
|
|
238
|
+
description: "Reject publications from datacenter IPs (estimation only, not 100% accurate)",
|
|
239
|
+
placeholder: "true"
|
|
240
|
+
}
|
|
241
|
+
];
|
|
242
|
+
var OptionsSchema = createOptionsSchema(optionInputs);
|
|
243
|
+
var type = "url/iframe";
|
|
244
|
+
var description = "Validate publications using Bitsocial Spam Blocker.";
|
|
245
|
+
var isRuntimeCommunity = (value) => typeof value === "object" && value !== null && ("signer" in value || "address" in value);
|
|
246
|
+
var getRuntimeCommunity = (args) => {
|
|
247
|
+
if (isRuntimeCommunity(args.community)) {
|
|
248
|
+
return args.community;
|
|
249
|
+
}
|
|
250
|
+
const legacyRuntimeCommunity = args[LEGACY_RUNTIME_COMMUNITY_KEY];
|
|
251
|
+
if (isRuntimeCommunity(legacyRuntimeCommunity)) {
|
|
252
|
+
return legacyRuntimeCommunity;
|
|
253
|
+
}
|
|
254
|
+
return void 0;
|
|
255
|
+
};
|
|
256
|
+
var parseOptions = (settings) => {
|
|
257
|
+
const parsed = OptionsSchema.safeParse(settings?.options);
|
|
258
|
+
if (!parsed.success) {
|
|
259
|
+
const message = parsed.error.issues.map((issue) => issue.message).join("; ");
|
|
260
|
+
throw new Error(`Invalid challenge options: ${message}`);
|
|
261
|
+
}
|
|
262
|
+
return parsed.data;
|
|
263
|
+
};
|
|
264
|
+
var createRequestSignature = async (propsToSign, signer) => {
|
|
265
|
+
if (!signer.privateKey || !signer.publicKey || !signer.type) {
|
|
266
|
+
throw new Error("Community signer is missing required fields");
|
|
267
|
+
}
|
|
268
|
+
const encoded = cborg.encode(propsToSign);
|
|
269
|
+
const signatureBuffer = await signBufferEd25519(encoded, signer.privateKey);
|
|
270
|
+
return {
|
|
271
|
+
signature: signatureBuffer,
|
|
272
|
+
// Uint8Array, not base64
|
|
273
|
+
publicKey: uint8ArrayFromString2(signer.publicKey, "base64"),
|
|
274
|
+
// Uint8Array
|
|
275
|
+
type: signer.type,
|
|
276
|
+
signedPropertyNames: Object.keys(propsToSign)
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
var postCbor = async (url, body) => {
|
|
280
|
+
const encoded = cborg.encode(body);
|
|
281
|
+
log.trace(`POST ${url} request body (CBOR, %d bytes)`, encoded.length);
|
|
282
|
+
const response = await fetch(url, {
|
|
283
|
+
method: "POST",
|
|
284
|
+
headers: {
|
|
285
|
+
"content-type": "application/cbor",
|
|
286
|
+
accept: "application/json",
|
|
287
|
+
"ngrok-skip-browser-warning": "true"
|
|
288
|
+
},
|
|
289
|
+
body: Buffer.from(encoded)
|
|
290
|
+
});
|
|
291
|
+
let responseBody;
|
|
292
|
+
try {
|
|
293
|
+
responseBody = await response.json();
|
|
294
|
+
} catch {
|
|
295
|
+
responseBody = void 0;
|
|
296
|
+
}
|
|
297
|
+
log.trace(`POST ${url} response status: ${response.status}, body: %o`, responseBody);
|
|
298
|
+
if (!response.ok) {
|
|
299
|
+
const details = responseBody !== void 0 ? `: ${JSON.stringify(responseBody)}` : "";
|
|
300
|
+
log.error(`POST ${url} failed with status ${response.status}${details}`);
|
|
301
|
+
throw new Error(`Bitsocial Spam Blocker server error (${response.status})${details}`);
|
|
302
|
+
}
|
|
303
|
+
if (responseBody === void 0) {
|
|
304
|
+
log.error(`POST ${url} returned invalid JSON`);
|
|
305
|
+
throw new Error("Invalid JSON response from Bitsocial Spam Blocker server");
|
|
306
|
+
}
|
|
307
|
+
return responseBody;
|
|
308
|
+
};
|
|
309
|
+
var parseWithSchema = (schema, data, context) => {
|
|
310
|
+
try {
|
|
311
|
+
return schema.parse(data);
|
|
312
|
+
} catch (error) {
|
|
313
|
+
const message = error instanceof Error ? error.message : "";
|
|
314
|
+
const suffix = message ? `: ${message}` : "";
|
|
315
|
+
throw new Error(`Invalid ${context} response from Bitsocial Spam Blocker server${suffix}`);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var formatRiskScore = (riskScore) => {
|
|
319
|
+
if (!Number.isFinite(riskScore)) return String(riskScore);
|
|
320
|
+
return riskScore.toFixed(2);
|
|
321
|
+
};
|
|
322
|
+
var getPostChallengeRejection = (verifyResponse, options) => {
|
|
323
|
+
if (typeof verifyResponse.ipRisk === "number" && verifyResponse.ipRisk > options.maxIpRisk) {
|
|
324
|
+
return `Rejected by IP risk policy (ipRisk ${formatRiskScore(verifyResponse.ipRisk)}).`;
|
|
325
|
+
}
|
|
326
|
+
if (typeof verifyResponse.ipAddressCountry === "string") {
|
|
327
|
+
const country = verifyResponse.ipAddressCountry.trim().toUpperCase();
|
|
328
|
+
if (country && options.countryBlacklist.has(country)) {
|
|
329
|
+
return `Rejected by country policy (${country}).`;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (typeof verifyResponse.ipTypeEstimation === "string") {
|
|
333
|
+
const ipType = verifyResponse.ipTypeEstimation.trim().toLowerCase();
|
|
334
|
+
if (ipType === "vpn" && options.blockVpn) {
|
|
335
|
+
return "Rejected by IP policy (VPN).";
|
|
336
|
+
}
|
|
337
|
+
if (ipType === "proxy" && options.blockProxy) {
|
|
338
|
+
return "Rejected by IP policy (proxy).";
|
|
339
|
+
}
|
|
340
|
+
if (ipType === "tor" && options.blockTor) {
|
|
341
|
+
return "Rejected by IP policy (Tor).";
|
|
342
|
+
}
|
|
343
|
+
if (ipType === "datacenter" && options.blockDatacenter) {
|
|
344
|
+
return "Rejected by IP policy (datacenter).";
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return void 0;
|
|
348
|
+
};
|
|
349
|
+
var getChallenge = async (args) => {
|
|
350
|
+
const { challengeSettings, challengeRequestMessage } = args;
|
|
351
|
+
const runtimeCommunity = getRuntimeCommunity(args);
|
|
352
|
+
log("getChallenge called for community %s", runtimeCommunity?.address);
|
|
353
|
+
log.trace("getChallenge arg keys: %o", Reflect.ownKeys(args));
|
|
354
|
+
log.trace(
|
|
355
|
+
"runtime community lookup: hasCommunity=%s hasLegacy=%s legacyType=%s",
|
|
356
|
+
"community" in args,
|
|
357
|
+
LEGACY_RUNTIME_COMMUNITY_KEY in args,
|
|
358
|
+
typeof args[LEGACY_RUNTIME_COMMUNITY_KEY]
|
|
359
|
+
);
|
|
360
|
+
log.trace("getChallenge args: challengeSettings=%o, challengeRequestMessage=%o", challengeSettings, challengeRequestMessage);
|
|
361
|
+
const options = parseOptions(challengeSettings);
|
|
362
|
+
log(
|
|
363
|
+
"Parsed options: serverUrl=%s, autoAcceptThreshold=%s, autoRejectThreshold=%s",
|
|
364
|
+
options.serverUrl,
|
|
365
|
+
options.autoAcceptThreshold,
|
|
366
|
+
options.autoRejectThreshold
|
|
367
|
+
);
|
|
368
|
+
const signer = runtimeCommunity?.signer;
|
|
369
|
+
if (!signer) {
|
|
370
|
+
log.error("Community signer is missing");
|
|
371
|
+
return { success: false, error: "Community signer is required to call Bitsocial Spam Blocker" };
|
|
372
|
+
}
|
|
373
|
+
log.trace("Signer publicKey: %s", signer.publicKey);
|
|
374
|
+
const evaluateTimestamp = Math.floor(Date.now() / 1e3);
|
|
375
|
+
const evaluatePropsToSign = {
|
|
376
|
+
challengeRequest: challengeRequestMessage,
|
|
377
|
+
timestamp: evaluateTimestamp
|
|
378
|
+
};
|
|
379
|
+
log("Calling /evaluate endpoint at %s", `${options.serverUrl}/evaluate`);
|
|
380
|
+
const evaluateSignature = await createRequestSignature(evaluatePropsToSign, signer);
|
|
381
|
+
let evaluateResponse;
|
|
382
|
+
try {
|
|
383
|
+
evaluateResponse = parseWithSchema(
|
|
384
|
+
EvaluateResponseSchema,
|
|
385
|
+
await postCbor(`${options.serverUrl}/evaluate`, {
|
|
386
|
+
...evaluatePropsToSign,
|
|
387
|
+
signature: evaluateSignature
|
|
388
|
+
}),
|
|
389
|
+
"evaluate"
|
|
390
|
+
);
|
|
391
|
+
} catch (error) {
|
|
392
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
393
|
+
log.error("Failed to evaluate publication: %s", message);
|
|
394
|
+
return { success: false, error: message };
|
|
395
|
+
}
|
|
396
|
+
const riskScore = evaluateResponse.riskScore;
|
|
397
|
+
log(
|
|
398
|
+
"Evaluate response: riskScore=%s, sessionId=%s, explanation=%s",
|
|
399
|
+
formatRiskScore(riskScore),
|
|
400
|
+
evaluateResponse.sessionId,
|
|
401
|
+
evaluateResponse.explanation
|
|
402
|
+
);
|
|
403
|
+
if (riskScore < options.autoAcceptThreshold) {
|
|
404
|
+
log("Auto-accepting publication (riskScore %s < autoAcceptThreshold %s)", formatRiskScore(riskScore), options.autoAcceptThreshold);
|
|
405
|
+
return { success: true };
|
|
406
|
+
}
|
|
407
|
+
if (riskScore >= options.autoRejectThreshold) {
|
|
408
|
+
const explanation = evaluateResponse.explanation ? ` ${evaluateResponse.explanation}` : "";
|
|
409
|
+
log("Auto-rejecting publication (riskScore %s >= autoRejectThreshold %s)", formatRiskScore(riskScore), options.autoRejectThreshold);
|
|
410
|
+
return {
|
|
411
|
+
success: false,
|
|
412
|
+
// TODO find a better error message
|
|
413
|
+
error: `Rejected by Bitsocial Spam Blocker (riskScore ${formatRiskScore(riskScore)}).${explanation}`
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
const sessionId = evaluateResponse.sessionId;
|
|
417
|
+
const challengeUrl = evaluateResponse.challengeUrl;
|
|
418
|
+
log("Returning challenge to user: sessionId=%s, challengeUrl=%s", sessionId, challengeUrl);
|
|
419
|
+
const verify = async (_answer) => {
|
|
420
|
+
log("verify called for sessionId=%s", sessionId);
|
|
421
|
+
const verifyTimestamp = Math.floor(Date.now() / 1e3);
|
|
422
|
+
const verifyPropsToSign = { sessionId, timestamp: verifyTimestamp };
|
|
423
|
+
log("Calling /challenge/verify endpoint at %s", `${options.serverUrl}/challenge/verify`);
|
|
424
|
+
const verifySignature = await createRequestSignature(verifyPropsToSign, signer);
|
|
425
|
+
let verifyResponse;
|
|
426
|
+
try {
|
|
427
|
+
verifyResponse = parseWithSchema(
|
|
428
|
+
VerifyResponseSchema,
|
|
429
|
+
await postCbor(`${options.serverUrl}/challenge/verify`, {
|
|
430
|
+
...verifyPropsToSign,
|
|
431
|
+
signature: verifySignature
|
|
432
|
+
}),
|
|
433
|
+
"verify"
|
|
434
|
+
);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
437
|
+
log.error("Failed to verify challenge: %s", message);
|
|
438
|
+
return { success: false, error: message };
|
|
439
|
+
}
|
|
440
|
+
log(
|
|
441
|
+
"Verify response: success=%s, error=%s, ipRisk=%s, ipAddressCountry=%s, ipTypeEstimation=%s",
|
|
442
|
+
verifyResponse.success,
|
|
443
|
+
verifyResponse.error,
|
|
444
|
+
verifyResponse.ipRisk,
|
|
445
|
+
verifyResponse.ipAddressCountry,
|
|
446
|
+
verifyResponse.ipTypeEstimation
|
|
447
|
+
);
|
|
448
|
+
if (!verifyResponse.success) {
|
|
449
|
+
log("Challenge verification failed: %s", verifyResponse.error || "unknown error");
|
|
450
|
+
return {
|
|
451
|
+
success: false,
|
|
452
|
+
// TODO find a better error message
|
|
453
|
+
error: verifyResponse.error || "Challenge verification failed."
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
const postChallengeRejection = getPostChallengeRejection(verifyResponse, options);
|
|
457
|
+
if (postChallengeRejection) {
|
|
458
|
+
log("Post-challenge rejection: %s", postChallengeRejection);
|
|
459
|
+
return { success: false, error: postChallengeRejection };
|
|
460
|
+
}
|
|
461
|
+
log("Challenge verification succeeded for sessionId=%s", sessionId);
|
|
462
|
+
return { success: true };
|
|
463
|
+
};
|
|
464
|
+
return { challenge: challengeUrl, verify, type };
|
|
465
|
+
};
|
|
466
|
+
function ChallengeFileFactory(_communityChallengeSettings) {
|
|
467
|
+
return { getChallenge, optionInputs, type, description };
|
|
468
|
+
}
|
|
469
|
+
var index_default = ChallengeFileFactory;
|
|
470
|
+
export {
|
|
471
|
+
index_default as default
|
|
472
|
+
};
|
|
473
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/pkc-js-signer.ts", "../../shared/src/types.ts", "../src/schema.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import path from \"path\";\nimport { createRequire } from \"module\";\nimport { pathToFileURL } from \"url\";\nimport * as ed from \"@noble/ed25519\";\nimport { fromString as uint8ArrayFromString } from \"uint8arrays/from-string\";\n\nconst require = createRequire(import.meta.url);\nconst pkcEntry = require.resolve(\"@pkcprotocol/pkc-js\");\nconst pkcRoot = path.resolve(path.dirname(pkcEntry), \"..\", \"..\");\n\nconst signerUtilUrl = pathToFileURL(path.join(pkcRoot, \"dist/node/signer/util.js\")).href;\n\nconst [{ getPublicKeyFromPrivateKey }] = await Promise.all([import(signerUtilUrl)]);\n\nexport const signBufferEd25519 = async (bufferToSign: Uint8Array, privateKeyBase64: string) => {\n const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, \"base64\");\n return ed.sign(bufferToSign, privateKeyBuffer);\n};\n\nexport { getPublicKeyFromPrivateKey };\n", "import countries from \"i18n-iso-countries\";\nimport { z } from \"zod\";\n\nconst ISO_COUNTRY_CODE_REGEX = /^[A-Z]{2}$/;\n\nconst isIsoCountryCode = (value: string) => ISO_COUNTRY_CODE_REGEX.test(value) && countries.isValid(value);\n\nconst isHttpUrl = (value: string) => {\n try {\n const url = new URL(value);\n return url.protocol === \"http:\" || url.protocol === \"https:\";\n } catch {\n return false;\n }\n};\n\nconst UnitIntervalSchema = z.number().finite().min(0).max(1);\n\nconst UnixTimestampSchema = z.number().finite().int().nonnegative();\n\nexport const IsoCountryCodeSchema = z\n .string()\n .trim()\n .transform((value) => value.toUpperCase())\n .refine((value) => isIsoCountryCode(value), {\n message: \"Unknown ISO 3166-1 alpha-2 country code\"\n });\n\nexport const EvaluateResponseSchema = z.object({\n riskScore: UnitIntervalSchema,\n explanation: z.string().optional(),\n sessionId: z.string(),\n challengeUrl: z.url().refine((value) => isHttpUrl(value), {\n message: \"challengeUrl must be a valid HTTP/HTTPS URL\"\n }),\n challengeExpiresAt: UnixTimestampSchema.optional()\n});\n\nexport const VerifyResponseSchema = z.object({\n success: z.boolean(),\n error: z.string().optional(),\n ipRisk: UnitIntervalSchema.optional(),\n ipAddressCountry: IsoCountryCodeSchema.optional(),\n challengeType: z.string().optional(),\n ipTypeEstimation: z.string().optional()\n});\n\nexport type EvaluateResponse = z.infer<typeof EvaluateResponseSchema>;\nexport type VerifyResponse = z.infer<typeof VerifyResponseSchema>;\n", "import { IsoCountryCodeSchema } from \"@bitsocial/spam-blocker-shared\";\nimport { z } from \"zod\";\n\nexport type ParsedOptions = {\n serverUrl: string;\n autoAcceptThreshold: number;\n autoRejectThreshold: number;\n countryBlacklist: Set<string>;\n maxIpRisk: number;\n blockVpn: boolean;\n blockProxy: boolean;\n blockTor: boolean;\n blockDatacenter: boolean;\n};\n\ntype OptionName = keyof ParsedOptions;\n\ntype OptionInput = {\n option: OptionName;\n default: string;\n};\n\nconst normalizeServerUrl = (url: string) => url.replace(/\\/+$/, \"\");\n\nconst isHttpUrl = (value: string) => {\n try {\n const parsed = new URL(value);\n return parsed.protocol === \"http:\" || parsed.protocol === \"https:\";\n } catch {\n return false;\n }\n};\n\nexport const createOptionsSchema = (optionInputs: ReadonlyArray<OptionInput>) => {\n const optionDefaults = optionInputs.reduce(\n (acc, input) => {\n acc[input.option] = input.default;\n return acc;\n },\n {} as Record<OptionName, string>\n );\n\n const getOptionDefault = (option: OptionName) => optionDefaults[option];\n\n const resolveOptionString = (value: unknown, option: OptionName) => {\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n return trimmed ? trimmed : getOptionDefault(option);\n }\n if (value === undefined || value === null) {\n return getOptionDefault(option);\n }\n return value;\n };\n\n const normalizeServerUrlInput = (value: unknown) => {\n const resolved = resolveOptionString(value, \"serverUrl\");\n if (typeof resolved === \"string\") {\n return normalizeServerUrl(resolved);\n }\n return resolved;\n };\n\n const numberOptionSchema = (option: OptionName) =>\n z.preprocess(\n (value) => resolveOptionString(value, option),\n z.string().transform((value, ctx) => {\n const parsed = Number(value);\n if (!Number.isFinite(parsed)) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Invalid ${option} option '${value}'`\n });\n return z.NEVER;\n }\n return parsed;\n })\n );\n\n const booleanOptionSchema = (option: OptionName) =>\n z.preprocess(\n (value) => {\n const resolved = resolveOptionString(value, option);\n if (typeof resolved === \"string\") {\n return resolved.trim().toLowerCase();\n }\n return resolved;\n },\n z.enum([\"true\", \"false\"]).transform((value) => value === \"true\")\n );\n\n const countryBlacklistSchema = z.preprocess(\n (value) => resolveOptionString(value, \"countryBlacklist\"),\n z.string().transform((value, ctx) => {\n if (!value) return new Set<string>();\n const entries = value\n .split(\",\")\n .map((entry) => entry.trim())\n .filter(Boolean);\n const codes = new Set<string>();\n for (const entry of entries) {\n const parsed = IsoCountryCodeSchema.safeParse(entry);\n if (!parsed.success) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: `Unknown ISO 3166-1 alpha-2 country code '${entry}' in countryBlacklist`\n });\n return z.NEVER;\n }\n codes.add(parsed.data);\n }\n return codes;\n })\n );\n\n const schema: z.ZodType<ParsedOptions> = z.preprocess(\n (value) => (value && typeof value === \"object\" ? value : {}),\n z\n .object({\n serverUrl: z.preprocess(\n normalizeServerUrlInput,\n z.url().refine(isHttpUrl, {\n message: \"Server URL must use http or https\"\n })\n ),\n autoAcceptThreshold: numberOptionSchema(\"autoAcceptThreshold\").refine((value) => value >= 0 && value <= 1, {\n message: \"autoAcceptThreshold must be between 0 and 1\"\n }),\n autoRejectThreshold: numberOptionSchema(\"autoRejectThreshold\").refine((value) => value >= 0 && value <= 1, {\n message: \"autoRejectThreshold must be between 0 and 1\"\n }),\n countryBlacklist: countryBlacklistSchema,\n maxIpRisk: numberOptionSchema(\"maxIpRisk\").refine((value) => value >= 0 && value <= 1, {\n message: \"maxIpRisk must be between 0 and 1\"\n }),\n blockVpn: booleanOptionSchema(\"blockVpn\"),\n blockProxy: booleanOptionSchema(\"blockProxy\"),\n blockTor: booleanOptionSchema(\"blockTor\"),\n blockDatacenter: booleanOptionSchema(\"blockDatacenter\")\n })\n .superRefine((data, ctx) => {\n if (data.autoAcceptThreshold > data.autoRejectThreshold) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n message: \"autoAcceptThreshold must be less than or equal to autoRejectThreshold\",\n path: [\"autoAcceptThreshold\"]\n });\n }\n })\n );\n\n return schema;\n};\n", "import type {\n ChallengeFileInput,\n ChallengeInput,\n ChallengeResultInput,\n GetChallengeArgs\n} from \"@pkcprotocol/pkc-js/dist/node/community/types.js\";\nimport { signBufferEd25519 } from \"./pkc-js-signer.js\";\nimport type { EvaluateResponse, VerifyResponse } from \"@bitsocial/spam-blocker-shared\";\nimport { EvaluateResponseSchema, VerifyResponseSchema } from \"@bitsocial/spam-blocker-shared\";\nimport { createOptionsSchema, type ParsedOptions } from \"./schema.js\";\nimport * as cborg from \"cborg\";\nimport { fromString as uint8ArrayFromString } from \"uint8arrays/from-string\";\nimport Logger from \"@pkc/pkc-logger\";\n\nconst log = Logger(\"bitsocial:community:challenge:spam-blocker\");\nconst LEGACY_RUNTIME_COMMUNITY_KEY = String.fromCharCode(115, 117, 98, 112, 108, 101, 98, 98, 105, 116);\n\nconst DEFAULT_SERVER_URL = \"https://spamblocker.bitsocial.net/api/v1\";\n\nconst optionInputs = [\n {\n option: \"serverUrl\",\n label: \"Server URL\",\n default: DEFAULT_SERVER_URL,\n description: \"URL of the Bitsocial Spam Blocker server\",\n placeholder: \"https://spamblocker.bitsocial.net/api/v1\"\n },\n {\n option: \"autoAcceptThreshold\",\n label: \"Auto-Accept Threshold\",\n default: \"0.2\",\n description: \"Auto-accept publications below this risk score\",\n placeholder: \"0.2\"\n },\n {\n option: \"autoRejectThreshold\",\n label: \"Auto-Reject Threshold\",\n default: \"0.8\",\n description: \"Auto-reject publications above this risk score\",\n placeholder: \"0.8\"\n },\n {\n option: \"countryBlacklist\",\n label: \"Country Blacklist\",\n default: \"\",\n description: \"Comma-separated ISO 3166-1 alpha-2 country codes to block\",\n placeholder: \"RU,CN,KP,US\"\n },\n {\n option: \"maxIpRisk\",\n label: \"Max IP Risk\",\n default: \"1.0\",\n description: \"Reject if ipRisk from /verify exceeds this threshold (estimation only, not 100% accurate)\",\n placeholder: \"1.0\"\n },\n {\n option: \"blockVpn\",\n label: \"Block VPN\",\n default: \"false\",\n description: \"Reject publications from VPN IPs (estimation only, not 100% accurate)\",\n placeholder: \"true\"\n },\n {\n option: \"blockProxy\",\n label: \"Block Proxy\",\n default: \"false\",\n description: \"Reject publications from proxy IPs (estimation only, not 100% accurate)\",\n placeholder: \"true\"\n },\n {\n option: \"blockTor\",\n label: \"Block Tor\",\n default: \"false\",\n description: \"Reject publications from Tor exit nodes (estimation only, not 100% accurate)\",\n placeholder: \"true\"\n },\n {\n option: \"blockDatacenter\",\n label: \"Block Datacenter\",\n default: \"false\",\n description: \"Reject publications from datacenter IPs (estimation only, not 100% accurate)\",\n placeholder: \"true\"\n }\n] as const satisfies NonNullable<ChallengeFileInput[\"optionInputs\"]>;\n\nconst OptionsSchema = createOptionsSchema(optionInputs);\n\nconst type: ChallengeInput[\"type\"] = \"url/iframe\";\n\nconst description: ChallengeFileInput[\"description\"] = \"Validate publications using Bitsocial Spam Blocker.\";\n\ntype RuntimeSigner = {\n privateKey?: string;\n publicKey?: string;\n type?: string;\n};\n\ntype RuntimeCommunity = {\n address?: string;\n signer?: RuntimeSigner;\n};\n\nconst isRuntimeCommunity = (value: unknown): value is RuntimeCommunity =>\n typeof value === \"object\" && value !== null && (\"signer\" in value || \"address\" in value);\n\nconst getRuntimeCommunity = (args: GetChallengeArgs): RuntimeCommunity | undefined => {\n if (isRuntimeCommunity(args.community)) {\n return args.community;\n }\n\n const legacyRuntimeCommunity = (args as Record<string, unknown>)[LEGACY_RUNTIME_COMMUNITY_KEY];\n if (isRuntimeCommunity(legacyRuntimeCommunity)) {\n return legacyRuntimeCommunity;\n }\n\n return undefined;\n};\n\nconst parseOptions = (settings: GetChallengeArgs[\"challengeSettings\"]): ParsedOptions => {\n const parsed = OptionsSchema.safeParse(settings?.options);\n if (!parsed.success) {\n const message = parsed.error.issues.map((issue) => issue.message).join(\"; \");\n throw new Error(`Invalid challenge options: ${message}`);\n }\n return parsed.data;\n};\n\nconst createRequestSignature = async (\n propsToSign: Record<string, unknown>,\n signer: { privateKey?: string; publicKey?: string; type?: string }\n) => {\n if (!signer.privateKey || !signer.publicKey || !signer.type) {\n throw new Error(\"Community signer is missing required fields\");\n }\n // Sign the CBOR-encoded payload directly\n const encoded = cborg.encode(propsToSign);\n const signatureBuffer = await signBufferEd25519(encoded, signer.privateKey);\n return {\n signature: signatureBuffer, // Uint8Array, not base64\n publicKey: uint8ArrayFromString(signer.publicKey, \"base64\"), // Uint8Array\n type: signer.type,\n signedPropertyNames: Object.keys(propsToSign)\n };\n};\n\nconst postCbor = async (url: string, body: unknown): Promise<unknown> => {\n const encoded = cborg.encode(body);\n log.trace(`POST ${url} request body (CBOR, %d bytes)`, encoded.length);\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/cbor\",\n accept: \"application/json\",\n \"ngrok-skip-browser-warning\": \"true\"\n },\n body: Buffer.from(encoded)\n });\n\n let responseBody: unknown;\n try {\n responseBody = (await response.json()) as unknown;\n } catch {\n responseBody = undefined;\n }\n\n log.trace(`POST ${url} response status: ${response.status}, body: %o`, responseBody);\n\n if (!response.ok) {\n const details = responseBody !== undefined ? `: ${JSON.stringify(responseBody)}` : \"\";\n log.error(`POST ${url} failed with status ${response.status}${details}`);\n throw new Error(`Bitsocial Spam Blocker server error (${response.status})${details}`);\n }\n\n if (responseBody === undefined) {\n log.error(`POST ${url} returned invalid JSON`);\n throw new Error(\"Invalid JSON response from Bitsocial Spam Blocker server\");\n }\n\n return responseBody;\n};\n\nconst parseWithSchema = <T>(schema: { parse: (data: unknown) => T }, data: unknown, context: string): T => {\n try {\n return schema.parse(data);\n } catch (error) {\n const message = error instanceof Error ? error.message : \"\";\n const suffix = message ? `: ${message}` : \"\";\n throw new Error(`Invalid ${context} response from Bitsocial Spam Blocker server${suffix}`);\n }\n};\n\nconst formatRiskScore = (riskScore: number) => {\n if (!Number.isFinite(riskScore)) return String(riskScore);\n return riskScore.toFixed(2);\n};\n\nconst getPostChallengeRejection = (verifyResponse: VerifyResponse, options: ParsedOptions) => {\n if (typeof verifyResponse.ipRisk === \"number\" && verifyResponse.ipRisk > options.maxIpRisk) {\n return `Rejected by IP risk policy (ipRisk ${formatRiskScore(verifyResponse.ipRisk)}).`;\n }\n\n if (typeof verifyResponse.ipAddressCountry === \"string\") {\n const country = verifyResponse.ipAddressCountry.trim().toUpperCase();\n if (country && options.countryBlacklist.has(country)) {\n return `Rejected by country policy (${country}).`;\n }\n }\n\n if (typeof verifyResponse.ipTypeEstimation === \"string\") {\n const ipType = verifyResponse.ipTypeEstimation.trim().toLowerCase();\n if (ipType === \"vpn\" && options.blockVpn) {\n return \"Rejected by IP policy (VPN).\";\n }\n if (ipType === \"proxy\" && options.blockProxy) {\n return \"Rejected by IP policy (proxy).\";\n }\n if (ipType === \"tor\" && options.blockTor) {\n return \"Rejected by IP policy (Tor).\";\n }\n if (ipType === \"datacenter\" && options.blockDatacenter) {\n return \"Rejected by IP policy (datacenter).\";\n }\n }\n\n return undefined;\n};\n\nconst getChallenge = async (args: GetChallengeArgs): Promise<ChallengeInput | ChallengeResultInput> => {\n const { challengeSettings, challengeRequestMessage } = args;\n const runtimeCommunity = getRuntimeCommunity(args);\n log(\"getChallenge called for community %s\", runtimeCommunity?.address);\n log.trace(\"getChallenge arg keys: %o\", Reflect.ownKeys(args));\n log.trace(\n \"runtime community lookup: hasCommunity=%s hasLegacy=%s legacyType=%s\",\n \"community\" in args,\n LEGACY_RUNTIME_COMMUNITY_KEY in (args as object),\n typeof (args as Record<string, unknown>)[LEGACY_RUNTIME_COMMUNITY_KEY]\n );\n log.trace(\"getChallenge args: challengeSettings=%o, challengeRequestMessage=%o\", challengeSettings, challengeRequestMessage);\n\n const options = parseOptions(challengeSettings);\n log(\n \"Parsed options: serverUrl=%s, autoAcceptThreshold=%s, autoRejectThreshold=%s\",\n options.serverUrl,\n options.autoAcceptThreshold,\n options.autoRejectThreshold\n );\n\n const signer = runtimeCommunity?.signer;\n\n if (!signer) {\n log.error(\"Community signer is missing\");\n return { success: false, error: \"Community signer is required to call Bitsocial Spam Blocker\" };\n }\n log.trace(\"Signer publicKey: %s\", signer.publicKey);\n\n const evaluateTimestamp = Math.floor(Date.now() / 1000);\n const evaluatePropsToSign = {\n challengeRequest: challengeRequestMessage,\n timestamp: evaluateTimestamp\n };\n log(\"Calling /evaluate endpoint at %s\", `${options.serverUrl}/evaluate`);\n const evaluateSignature = await createRequestSignature(evaluatePropsToSign, signer);\n\n let evaluateResponse: EvaluateResponse;\n try {\n evaluateResponse = parseWithSchema<EvaluateResponse>(\n EvaluateResponseSchema,\n await postCbor(`${options.serverUrl}/evaluate`, {\n ...evaluatePropsToSign,\n signature: evaluateSignature\n }),\n \"evaluate\"\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Unknown error\";\n log.error(\"Failed to evaluate publication: %s\", message);\n return { success: false, error: message };\n }\n const riskScore = evaluateResponse.riskScore;\n log(\n \"Evaluate response: riskScore=%s, sessionId=%s, explanation=%s\",\n formatRiskScore(riskScore),\n evaluateResponse.sessionId,\n evaluateResponse.explanation\n );\n\n if (riskScore < options.autoAcceptThreshold) {\n log(\"Auto-accepting publication (riskScore %s < autoAcceptThreshold %s)\", formatRiskScore(riskScore), options.autoAcceptThreshold);\n return { success: true };\n }\n\n if (riskScore >= options.autoRejectThreshold) {\n const explanation = evaluateResponse.explanation ? ` ${evaluateResponse.explanation}` : \"\";\n log(\"Auto-rejecting publication (riskScore %s >= autoRejectThreshold %s)\", formatRiskScore(riskScore), options.autoRejectThreshold);\n return {\n success: false,\n // TODO find a better error message\n error: `Rejected by Bitsocial Spam Blocker (riskScore ${formatRiskScore(riskScore)}).${explanation}`\n };\n }\n\n const sessionId = evaluateResponse.sessionId;\n const challengeUrl = evaluateResponse.challengeUrl;\n log(\"Returning challenge to user: sessionId=%s, challengeUrl=%s\", sessionId, challengeUrl);\n\n // Server tracks challenge completion state - no token needed from user\n const verify = async (_answer: string): Promise<ChallengeResultInput> => {\n log(\"verify called for sessionId=%s\", sessionId);\n\n const verifyTimestamp = Math.floor(Date.now() / 1000);\n const verifyPropsToSign = { sessionId, timestamp: verifyTimestamp };\n log(\"Calling /challenge/verify endpoint at %s\", `${options.serverUrl}/challenge/verify`);\n const verifySignature = await createRequestSignature(verifyPropsToSign, signer);\n\n let verifyResponse: VerifyResponse;\n try {\n verifyResponse = parseWithSchema<VerifyResponse>(\n VerifyResponseSchema,\n await postCbor(`${options.serverUrl}/challenge/verify`, {\n ...verifyPropsToSign,\n signature: verifySignature\n }),\n \"verify\"\n );\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Unknown error\";\n log.error(\"Failed to verify challenge: %s\", message);\n return { success: false, error: message };\n }\n log(\n \"Verify response: success=%s, error=%s, ipRisk=%s, ipAddressCountry=%s, ipTypeEstimation=%s\",\n verifyResponse.success,\n verifyResponse.error,\n verifyResponse.ipRisk,\n verifyResponse.ipAddressCountry,\n verifyResponse.ipTypeEstimation\n );\n\n if (!verifyResponse.success) {\n log(\"Challenge verification failed: %s\", verifyResponse.error || \"unknown error\");\n return {\n success: false,\n // TODO find a better error message\n error: verifyResponse.error || \"Challenge verification failed.\"\n };\n }\n\n const postChallengeRejection = getPostChallengeRejection(verifyResponse, options);\n if (postChallengeRejection) {\n log(\"Post-challenge rejection: %s\", postChallengeRejection);\n return { success: false, error: postChallengeRejection };\n }\n\n log(\"Challenge verification succeeded for sessionId=%s\", sessionId);\n return { success: true };\n };\n\n return { challenge: challengeUrl, verify, type };\n};\n\nfunction ChallengeFileFactory(_communityChallengeSettings: GetChallengeArgs[\"challengeSettings\"]): ChallengeFileInput {\n return { getChallenge, optionInputs, type, description };\n}\n\nexport default ChallengeFileFactory;\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,YAAY,QAAQ;AACpB,SAAS,cAAc,4BAA4B;AAEnD,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,WAAWA,SAA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CAAC;AAAA,QACD;AAAA,MACJ;AAAA,IACJ,SAAS,OAAO;AACZ,YAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;AACzD,UAAI,MAAM,kCAAkC,OAAO;AACnD,aAAO,EAAE,SAAS,OAAO,OAAO,QAAQ;AAAA,IAC5C;AACA;AAAA,MACI;AAAA,MACA,eAAe;AAAA,MACf,eAAe;AAAA,MACf,eAAe;AAAA,MACf,eAAe;AAAA,MACf,eAAe;AAAA,IACnB;AAEA,QAAI,CAAC,eAAe,SAAS;AACzB,UAAI,qCAAqC,eAAe,SAAS,eAAe;AAChF,aAAO;AAAA,QACH,SAAS;AAAA;AAAA,QAET,OAAO,eAAe,SAAS;AAAA,MACnC;AAAA,IACJ;AAEA,UAAM,yBAAyB,0BAA0B,gBAAgB,OAAO;AAChF,QAAI,wBAAwB;AACxB,UAAI,gCAAgC,sBAAsB;AAC1D,aAAO,EAAE,SAAS,OAAO,OAAO,uBAAuB;AAAA,IAC3D;AAEA,QAAI,qDAAqD,SAAS;AAClE,WAAO,EAAE,SAAS,KAAK;AAAA,EAC3B;AAEA,SAAO,EAAE,WAAW,cAAc,QAAQ,KAAK;AACnD;AAEA,SAAS,qBAAqB,6BAAwF;AAClH,SAAO,EAAE,cAAc,cAAc,MAAM,YAAY;AAC3D;AAEA,IAAO,gBAAQ;",
|
|
6
|
+
"names": ["require", "z", "isHttpUrl", "optionInputs", "uint8ArrayFromString"]
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pkc-js-signer.d.ts","sourceRoot":"","sources":["../src/pkc-js-signer.ts"],"names":[],"mappings":"AAYA,QAAA,MAAS,0BAA0B,KAAgD,CAAC;AAEpF,eAAO,MAAM,iBAAiB,GAAU,cAAc,UAAU,EAAE,kBAAkB,MAAM,yCAGzF,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plebbit-js-signer.d.ts","sourceRoot":"","sources":["../src/plebbit-js-signer.ts"],"names":[],"mappings":"AAYA,QAAA,MAAS,0BAA0B,KAAgD,CAAC;AAEpF,eAAO,MAAM,iBAAiB,GAAU,cAAc,UAAU,EAAE,kBAAkB,MAAM,yCAGzF,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export type ParsedOptions = {
|
|
3
|
+
serverUrl: string;
|
|
4
|
+
autoAcceptThreshold: number;
|
|
5
|
+
autoRejectThreshold: number;
|
|
6
|
+
countryBlacklist: Set<string>;
|
|
7
|
+
maxIpRisk: number;
|
|
8
|
+
blockVpn: boolean;
|
|
9
|
+
blockProxy: boolean;
|
|
10
|
+
blockTor: boolean;
|
|
11
|
+
blockDatacenter: boolean;
|
|
12
|
+
};
|
|
13
|
+
type OptionName = keyof ParsedOptions;
|
|
14
|
+
type OptionInput = {
|
|
15
|
+
option: OptionName;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const createOptionsSchema: (optionInputs: ReadonlyArray<OptionInput>) => z.ZodType<ParsedOptions, unknown, z.core.$ZodTypeInternals<ParsedOptions, unknown>>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,MAAM,aAAa,GAAG;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,aAAa,CAAC;AAEtC,KAAK,WAAW,GAAG;IACf,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAaF,eAAO,MAAM,mBAAmB,GAAI,cAAc,aAAa,CAAC,WAAW,CAAC,wFAuH3E,CAAC"}
|