@bitsocial/spam-blocker-challenge 0.1.3 → 0.1.5
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/README.md +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -39
- package/dist/index.js.map +2 -2
- package/dist/pkc-js-signer.d.ts.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A Bitsocial challenge plugin that protects communities from spam by evaluating p
|
|
|
4
4
|
|
|
5
5
|
## Using Spam Blocker In Your Community
|
|
6
6
|
|
|
7
|
-
Community owners add the spam blocker challenge to their community settings. When enabled, user-generated publications
|
|
7
|
+
Community owners add the spam blocker challenge to their community settings. When enabled, user-generated publications return a consent-gated iframe URL. The Bitsocial Spam Blocker server evaluates the publication only after the user opens that iframe. Low-risk publications complete immediately after evaluation, high-risk publications are rejected, and medium-risk publications continue into an interactive iframe challenge. Community-level actions (`commentEdit`, `commentModeration`, and `communityEdit`) are accepted locally because they do not require spam detection.
|
|
8
8
|
|
|
9
9
|
First install the challenge on the Bitsocial server:
|
|
10
10
|
|
|
@@ -49,8 +49,8 @@ Then add or edit the `challenges` array in your community settings to include th
|
|
|
49
49
|
| Option | Default | Description |
|
|
50
50
|
| --------------------- | ------------------------------------------ | --------------------------------------------------------------------------- |
|
|
51
51
|
| `serverUrl` | `https://spamblocker.bitsocial.net/api/v1` | URL of the Bitsocial spam blocker server |
|
|
52
|
-
| `autoAcceptThreshold` | `0.2` |
|
|
53
|
-
| `autoRejectThreshold` | `0.8` |
|
|
52
|
+
| `autoAcceptThreshold` | `0.2` | Complete verification after iframe evaluation when risk is below this value |
|
|
53
|
+
| `autoRejectThreshold` | `0.8` | Reject after iframe evaluation when risk is above this value |
|
|
54
54
|
| `countryBlacklist` | _(empty)_ | Comma-separated ISO 3166-1 alpha-2 country codes to block (e.g. `RU,CN,KP`) |
|
|
55
55
|
| `maxIpRisk` | `1.0` | Reject if IP risk score exceeds this threshold (estimation only) |
|
|
56
56
|
| `blockVpn` | `false` | Reject publications from VPN IPs (estimation only) |
|
|
@@ -60,14 +60,15 @@ Then add or edit the `challenges` array in your community settings to include th
|
|
|
60
60
|
|
|
61
61
|
## How It Works
|
|
62
62
|
|
|
63
|
-
1. When a user publishes a post, reply, or vote to a community, the challenge
|
|
64
|
-
2. The
|
|
65
|
-
3.
|
|
66
|
-
|
|
67
|
-
- **
|
|
68
|
-
- **
|
|
69
|
-
|
|
70
|
-
5.
|
|
63
|
+
1. When a user publishes a post, reply, or vote to a community, the challenge signs the publication locally and returns a lazy iframe URL. `getChallenge()` does not call `/evaluate`.
|
|
64
|
+
2. The Bitsocial client asks the user before opening the spam blocker iframe.
|
|
65
|
+
3. After the user opens the iframe, the iframe sends the signed payload to `/evaluate`. This is the first spam blocker server evaluation request for the publication.
|
|
66
|
+
4. The server returns a **risk score** between 0 and 1:
|
|
67
|
+
- **Below `autoAcceptThreshold`**: Verification completes immediately.
|
|
68
|
+
- **Above `autoRejectThreshold`**: Verification fails immediately.
|
|
69
|
+
- **Between thresholds**: The iframe presents OAuth and/or CAPTCHA verification.
|
|
70
|
+
5. After challenge verification, the server's `/challenge/verify` endpoint confirms whether the user passed. Additional IP-based policies (country, VPN, proxy, Tor, datacenter blocking) are applied if configured.
|
|
71
|
+
6. Community-level actions (`commentEdit`, `commentModeration`, and `communityEdit`) are accepted without calling `/evaluate`.
|
|
71
72
|
|
|
72
73
|
## License
|
|
73
74
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAyV1D,iBAAS,oBAAoB,CAAC,2BAA2B,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,GAAG,kBAAkB,CAEpH;eAEc,oBAAoB"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,18 @@ var UnixTimestampSchema = z.number().finite().int().nonnegative();
|
|
|
25
25
|
var IsoCountryCodeSchema = z.string().trim().transform((value) => value.toUpperCase()).refine((value) => isIsoCountryCode(value), {
|
|
26
26
|
message: "Unknown ISO 3166-1 alpha-2 country code"
|
|
27
27
|
});
|
|
28
|
+
var EvaluationOptionsSchema = z.object({
|
|
29
|
+
autoAcceptThreshold: UnitIntervalSchema.optional(),
|
|
30
|
+
autoRejectThreshold: UnitIntervalSchema.optional()
|
|
31
|
+
}).strict().superRefine((value, ctx) => {
|
|
32
|
+
if (value.autoAcceptThreshold !== void 0 && value.autoRejectThreshold !== void 0 && value.autoAcceptThreshold > value.autoRejectThreshold) {
|
|
33
|
+
ctx.addIssue({
|
|
34
|
+
code: z.ZodIssueCode.custom,
|
|
35
|
+
message: "autoAcceptThreshold must be less than or equal to autoRejectThreshold",
|
|
36
|
+
path: ["autoAcceptThreshold"]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
28
40
|
var EvaluateResponseSchema = z.object({
|
|
29
41
|
riskScore: UnitIntervalSchema,
|
|
30
42
|
explanation: z.string().optional(),
|
|
@@ -163,6 +175,7 @@ var createOptionsSchema = (optionInputs2) => {
|
|
|
163
175
|
// src/index.ts
|
|
164
176
|
import * as cborg from "cborg";
|
|
165
177
|
import { fromString as uint8ArrayFromString2 } from "uint8arrays/from-string";
|
|
178
|
+
import { randomUUID } from "node:crypto";
|
|
166
179
|
import Logger from "@pkcprotocol/pkc-logger";
|
|
167
180
|
var log = Logger("bitsocial:community:challenge:spam-blocker");
|
|
168
181
|
var LEGACY_RUNTIME_COMMUNITY_KEY = String.fromCharCode(115, 117, 98, 112, 108, 101, 98, 98, 105, 116);
|
|
@@ -310,6 +323,8 @@ var parseWithSchema = (schema, data, context) => {
|
|
|
310
323
|
throw new Error(`Invalid ${context} response from Bitsocial Spam Blocker server${suffix}`);
|
|
311
324
|
}
|
|
312
325
|
};
|
|
326
|
+
var toBase64Url = (bytes) => Buffer.from(bytes).toString("base64url");
|
|
327
|
+
var createLazyChallengeUrl = ({ serverUrl, sessionId, payload }) => `${serverUrl}/iframe/${encodeURIComponent(sessionId)}/lazy#payload=${toBase64Url(cborg.encode(payload))}`;
|
|
313
328
|
var formatRiskScore = (riskScore) => {
|
|
314
329
|
if (!Number.isFinite(riskScore)) return String(riskScore);
|
|
315
330
|
return riskScore.toFixed(2);
|
|
@@ -370,51 +385,28 @@ var getChallenge = async (args) => {
|
|
|
370
385
|
return { success: false, error: "Community signer is required to call Bitsocial Spam Blocker" };
|
|
371
386
|
}
|
|
372
387
|
log.trace("Signer publicKey: %s", signer.publicKey);
|
|
388
|
+
const sessionId = randomUUID();
|
|
373
389
|
const evaluateTimestamp = Math.floor(Date.now() / 1e3);
|
|
390
|
+
const evaluationOptions = {
|
|
391
|
+
autoAcceptThreshold: options.autoAcceptThreshold,
|
|
392
|
+
autoRejectThreshold: options.autoRejectThreshold
|
|
393
|
+
};
|
|
374
394
|
const evaluatePropsToSign = {
|
|
375
395
|
challengeRequest: challengeRequestMessage,
|
|
396
|
+
sessionId,
|
|
397
|
+
evaluationOptions,
|
|
376
398
|
timestamp: evaluateTimestamp
|
|
377
399
|
};
|
|
378
|
-
log("Calling /evaluate endpoint at %s", `${options.serverUrl}/evaluate`);
|
|
379
400
|
const evaluateSignature = await createRequestSignature(evaluatePropsToSign, signer);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
);
|
|
390
|
-
} catch (error) {
|
|
391
|
-
const message = error instanceof Error ? error.message : "Unknown error";
|
|
392
|
-
log.error("Failed to evaluate publication: %s", message);
|
|
393
|
-
return { success: false, error: message };
|
|
394
|
-
}
|
|
395
|
-
const riskScore = evaluateResponse.riskScore;
|
|
396
|
-
log(
|
|
397
|
-
"Evaluate response: riskScore=%s, sessionId=%s, explanation=%s",
|
|
398
|
-
formatRiskScore(riskScore),
|
|
399
|
-
evaluateResponse.sessionId,
|
|
400
|
-
evaluateResponse.explanation
|
|
401
|
-
);
|
|
402
|
-
if (riskScore < options.autoAcceptThreshold) {
|
|
403
|
-
log("Auto-accepting publication (riskScore %s < autoAcceptThreshold %s)", formatRiskScore(riskScore), options.autoAcceptThreshold);
|
|
404
|
-
return { success: true };
|
|
405
|
-
}
|
|
406
|
-
if (riskScore >= options.autoRejectThreshold) {
|
|
407
|
-
const explanation = evaluateResponse.explanation ? ` ${evaluateResponse.explanation}` : "";
|
|
408
|
-
log("Auto-rejecting publication (riskScore %s >= autoRejectThreshold %s)", formatRiskScore(riskScore), options.autoRejectThreshold);
|
|
409
|
-
return {
|
|
410
|
-
success: false,
|
|
411
|
-
// TODO find a better error message
|
|
412
|
-
error: `Rejected by Bitsocial Spam Blocker (riskScore ${formatRiskScore(riskScore)}).${explanation}`
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
const sessionId = evaluateResponse.sessionId;
|
|
416
|
-
const challengeUrl = evaluateResponse.challengeUrl;
|
|
417
|
-
log("Returning challenge to user: sessionId=%s, challengeUrl=%s", sessionId, challengeUrl);
|
|
401
|
+
const challengeUrl = createLazyChallengeUrl({
|
|
402
|
+
serverUrl: options.serverUrl,
|
|
403
|
+
sessionId,
|
|
404
|
+
payload: {
|
|
405
|
+
...evaluatePropsToSign,
|
|
406
|
+
signature: evaluateSignature
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
log("Returning lazy challenge to user: sessionId=%s, challengeUrl=%s", sessionId, challengeUrl);
|
|
418
410
|
const verify = async (_answer) => {
|
|
419
411
|
log("verify called for sessionId=%s", sessionId);
|
|
420
412
|
const verifyTimestamp = Math.floor(Date.now() / 1e3);
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/pkc-js-signer.ts", "../../shared/src/types.ts", "../src/schema.ts", "../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as ed from \"@noble/ed25519\";\nimport { fromString as uint8ArrayFromString } from \"uint8arrays/from-string\";\nimport { toString as uint8ArrayToString } from \"uint8arrays/to-string\";\n\nexport const signBufferEd25519 = async (bufferToSign: Uint8Array, privateKeyBase64: string) => {\n const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, \"base64\");\n return ed.sign(bufferToSign, privateKeyBuffer);\n};\n\nexport const getPublicKeyFromPrivateKey = async (privateKeyBase64: string) => {\n const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, \"base64\");\n const publicKeyBuffer = await ed.getPublicKey(privateKeyBuffer);\n return uint8ArrayToString(publicKeyBuffer, \"base64\");\n};\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 \"@pkcprotocol/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 communityLevelActionKeys = [\"commentEdit\", \"commentModeration\", \"communityEdit\"] as const;\n\nconst isCommunityLevelActionRequest = (challengeRequestMessage: GetChallengeArgs[\"challengeRequestMessage\"]) =>\n communityLevelActionKeys.some((key) => Boolean(challengeRequestMessage[key]));\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 if (isCommunityLevelActionRequest(challengeRequestMessage)) {\n log(\"Auto-accepting community-level action without spam evaluation\");\n return { success: true };\n }\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,YAAY,QAAQ;AACpB,SAAS,cAAc,4BAA4B;AACnD,SAAS,YAAY,0BAA0B;AAExC,IAAM,oBAAoB,OAAO,cAA0B,qBAA6B;AAC3F,QAAM,mBAAmB,qBAAqB,kBAAkB,QAAQ;AACxE,SAAU,QAAK,cAAc,gBAAgB;AACjD;;;ACPA,OAAO,eAAe;AACtB,SAAS,SAAS;AAElB,IAAM,yBAAyB;AAE/B,IAAM,mBAAmB,CAAC,UAAkB,uBAAuB,KAAK,KAAK,KAAK,UAAU,QAAQ,KAAK;AAEzG,IAAM,YAAY,CAAC,UAAiB;AAChC,MAAI;AACA,UAAM,MAAM,IAAI,IAAI,KAAK;AACzB,WAAO,IAAI,aAAa,WAAW,IAAI,aAAa;EACxD,QAAQ;AACJ,WAAO;EACX;AACJ;AAEA,IAAM,qBAAqB,EAAE,OAAM,EAAG,OAAM,EAAG,IAAI,CAAC,EAAE,IAAI,CAAC;AAE3D,IAAM,sBAAsB,EAAE,OAAM,EAAG,OAAM,EAAG,IAAG,EAAG,YAAW;AAE1D,IAAM,uBAAuB,EAC/B,OAAM,EACN,KAAI,EACJ,UAAU,CAAC,UAAU,MAAM,YAAW,CAAE,EACxC,OAAO,CAAC,UAAU,iBAAiB,KAAK,GAAG;EACxC,SAAS;CACZ;AAEE,IAAM,yBAAyB,EAAE,OAAO;EAC3C,WAAW;EACX,aAAa,EAAE,OAAM,EAAG,SAAQ;EAChC,WAAW,EAAE,OAAM;EACnB,cAA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esContent": ["import * as ed from \"@noble/ed25519\";\nimport { fromString as uint8ArrayFromString } from \"uint8arrays/from-string\";\nimport { toString as uint8ArrayToString } from \"uint8arrays/to-string\";\n\nexport const signBufferEd25519 = async (bufferToSign: Uint8Array, privateKeyBase64: string) => {\n const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, \"base64\");\n return ed.sign(bufferToSign, privateKeyBuffer);\n};\n\nexport const getPublicKeyFromPrivateKey = async (privateKeyBase64: string) => {\n const privateKeyBuffer = uint8ArrayFromString(privateKeyBase64, \"base64\");\n const publicKeyBuffer = await ed.getPublicKey(privateKeyBuffer);\n return uint8ArrayToString(publicKeyBuffer, \"base64\");\n};\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 EvaluationOptionsSchema = z\n .object({\n autoAcceptThreshold: UnitIntervalSchema.optional(),\n autoRejectThreshold: UnitIntervalSchema.optional()\n })\n .strict()\n .superRefine((value, ctx) => {\n if (\n value.autoAcceptThreshold !== undefined &&\n value.autoRejectThreshold !== undefined &&\n value.autoAcceptThreshold > value.autoRejectThreshold\n ) {\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\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 EvaluationOptions = z.infer<typeof EvaluationOptionsSchema>;\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 { EvaluationOptions, VerifyResponse } from \"@bitsocial/spam-blocker-shared\";\nimport { 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 { randomUUID } from \"node:crypto\";\nimport Logger from \"@pkcprotocol/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 communityLevelActionKeys = [\"commentEdit\", \"commentModeration\", \"communityEdit\"] as const;\n\nconst isCommunityLevelActionRequest = (challengeRequestMessage: GetChallengeArgs[\"challengeRequestMessage\"]) =>\n communityLevelActionKeys.some((key) => Boolean(challengeRequestMessage[key]));\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 toBase64Url = (bytes: Uint8Array) => Buffer.from(bytes).toString(\"base64url\");\n\nconst createLazyChallengeUrl = ({ serverUrl, sessionId, payload }: { serverUrl: string; sessionId: string; payload: unknown }) =>\n `${serverUrl}/iframe/${encodeURIComponent(sessionId)}/lazy#payload=${toBase64Url(cborg.encode(payload))}`;\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 if (isCommunityLevelActionRequest(challengeRequestMessage)) {\n log(\"Auto-accepting community-level action without spam evaluation\");\n return { success: true };\n }\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 sessionId = randomUUID();\n const evaluateTimestamp = Math.floor(Date.now() / 1000);\n const evaluationOptions: EvaluationOptions = {\n autoAcceptThreshold: options.autoAcceptThreshold,\n autoRejectThreshold: options.autoRejectThreshold\n };\n const evaluatePropsToSign = {\n challengeRequest: challengeRequestMessage,\n sessionId,\n evaluationOptions,\n timestamp: evaluateTimestamp\n };\n const evaluateSignature = await createRequestSignature(evaluatePropsToSign, signer);\n const challengeUrl = createLazyChallengeUrl({\n serverUrl: options.serverUrl,\n sessionId,\n payload: {\n ...evaluatePropsToSign,\n signature: evaluateSignature\n }\n });\n log(\"Returning lazy 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\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;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
6
|
"names": ["z", "isHttpUrl", "optionInputs", "uint8ArrayFromString"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pkc-js-signer.d.ts","sourceRoot":"","sources":["../src/pkc-js-signer.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"pkc-js-signer.d.ts","sourceRoot":"","sources":["../src/pkc-js-signer.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,iBAAwB,UAAU,oBAAoB,MAAM,yCAGzF,CAAC;AAEF,eAAO,MAAM,0BAA0B,qBAA4B,MAAM,oBAIxE,CAAC"}
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,iBAAkB,aAAa,CAAC,WAAW,CAAC,wFAuH3E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitsocial/spam-blocker-challenge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Bitsocial Spam Blocker challenge implementation for PKC",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitsocial",
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@pkcprotocol/pkc-js": "0.0.30",
|
|
56
56
|
"esbuild": "0.27.2",
|
|
57
|
-
"typescript": "
|
|
58
|
-
"vitest": "4.
|
|
57
|
+
"typescript": "7.0.2",
|
|
58
|
+
"vitest": "4.1.10"
|
|
59
59
|
},
|
|
60
|
-
"packageManager": "yarn@4.
|
|
60
|
+
"packageManager": "yarn@4.17.1"
|
|
61
61
|
}
|