@prosopo/server 2.1.6 → 2.1.8
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/package.json +6 -6
- package/dist/cjs/config.cjs +0 -25
- package/dist/cjs/index.cjs +0 -13
- package/dist/cjs/server.cjs +0 -107
- package/dist/config.d.ts +0 -39
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -21
- package/dist/config.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/server.d.ts +0 -18
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -75
- package/dist/server.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prosopo/server",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.8",
|
|
4
4
|
"description": "NodeJS package for server side communication with the prosopo captcha client",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@polkadot/keyring": "12.6.2",
|
|
36
36
|
"@polkadot/util": "12.6.2",
|
|
37
|
-
"@prosopo/api": "2.1.
|
|
38
|
-
"@prosopo/common": "2.1.
|
|
39
|
-
"@prosopo/contract": "2.1.
|
|
40
|
-
"@prosopo/types": "2.1.
|
|
37
|
+
"@prosopo/api": "2.1.8",
|
|
38
|
+
"@prosopo/common": "2.1.8",
|
|
39
|
+
"@prosopo/contract": "2.1.8",
|
|
40
|
+
"@prosopo/types": "2.1.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@prosopo/config": "2.1.
|
|
43
|
+
"@prosopo/config": "2.1.8",
|
|
44
44
|
"@vitest/coverage-v8": "2.1.1",
|
|
45
45
|
"concurrently": "9.0.1",
|
|
46
46
|
"npm-run-all": "4.1.5",
|
package/dist/cjs/config.cjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const types = require("@prosopo/types");
|
|
4
|
-
const getServerConfig = () => types.ProsopoServerConfigSchema.parse({
|
|
5
|
-
defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT,
|
|
6
|
-
// environmental variables
|
|
7
|
-
serverUrl: getServerUrl(),
|
|
8
|
-
dappName: process.env.PROSOPO_DAPP_NAME || "client-example-server",
|
|
9
|
-
account: {
|
|
10
|
-
password: "",
|
|
11
|
-
address: process.env.PROSOPO_SITE_KEY || "",
|
|
12
|
-
secret: process.env.PROSOPO_SITE_PRIVATE_KEY || ""
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
const getServerUrl = () => {
|
|
16
|
-
if (process.env.PROSOPO_SERVER_URL) {
|
|
17
|
-
if (process.env.PROSOPO_SERVER_URL.match(/:\d+/)) {
|
|
18
|
-
return process.env.PROSOPO_SERVER_URL;
|
|
19
|
-
}
|
|
20
|
-
return `${process.env.PROSOPO_SERVER_URL}:${process.env.PROSOPO_SERVER_PORT || 9228}`;
|
|
21
|
-
}
|
|
22
|
-
return "http://localhost:9228";
|
|
23
|
-
};
|
|
24
|
-
exports.getServerConfig = getServerConfig;
|
|
25
|
-
exports.getServerUrl = getServerUrl;
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const server = require("./server.cjs");
|
|
4
|
-
const config = require("./config.cjs");
|
|
5
|
-
const contract = require("@prosopo/contract");
|
|
6
|
-
const PublicProsopoServer = async (config2) => {
|
|
7
|
-
const pair = await contract.getPairAsync(void 0, config2.account.address);
|
|
8
|
-
return new server.ProsopoServer(config2, pair);
|
|
9
|
-
};
|
|
10
|
-
exports.ProsopoServer = server.ProsopoServer;
|
|
11
|
-
exports.getServerConfig = config.getServerConfig;
|
|
12
|
-
exports.getServerUrl = config.getServerUrl;
|
|
13
|
-
exports.PublicProsopoServer = PublicProsopoServer;
|
package/dist/cjs/server.cjs
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const keyring = require("@polkadot/keyring");
|
|
4
|
-
const util = require("@polkadot/util");
|
|
5
|
-
const api = require("@prosopo/api");
|
|
6
|
-
const common = require("@prosopo/common");
|
|
7
|
-
const types = require("@prosopo/types");
|
|
8
|
-
const i18n = require("i18next");
|
|
9
|
-
class ProsopoServer {
|
|
10
|
-
constructor(config, pair) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.pair = pair;
|
|
13
|
-
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
14
|
-
this.dappAccount = this.config.account.address;
|
|
15
|
-
this.logger = common.getLogger(
|
|
16
|
-
this.config.logLevel,
|
|
17
|
-
"@prosopo/server"
|
|
18
|
-
);
|
|
19
|
-
this.keyring = new keyring.Keyring({
|
|
20
|
-
type: "sr25519"
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
getProviderApi(providerUrl) {
|
|
24
|
-
return new api.ProviderApi(providerUrl, this.dappAccount || "");
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Verify the user with the provider URL passed in. If a challenge is provided, we use the challenge to verify the
|
|
28
|
-
* user. If not, we use the user, dapp, and optionally the commitmentID, to verify the user.
|
|
29
|
-
* @param token
|
|
30
|
-
* @param timeouts
|
|
31
|
-
* @param providerUrl
|
|
32
|
-
* @param timestamp
|
|
33
|
-
* @param challenge
|
|
34
|
-
*/
|
|
35
|
-
async verifyProvider(token, timeouts, providerUrl, timestamp, challenge) {
|
|
36
|
-
this.logger.info("Verifying with provider.");
|
|
37
|
-
const dappUserSignature = this.pair?.sign(timestamp.toString());
|
|
38
|
-
if (!dappUserSignature) {
|
|
39
|
-
throw new common.ProsopoContractError("CAPTCHA.INVALID_TIMESTAMP", {
|
|
40
|
-
context: { error: "Timestamp not found" }
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const signatureHex = util.u8aToHex(dappUserSignature);
|
|
44
|
-
const providerApi = this.getProviderApi(providerUrl);
|
|
45
|
-
if (challenge) {
|
|
46
|
-
const powTimeout = this.config.timeouts.pow.cachedTimeout;
|
|
47
|
-
const recent2 = timestamp ? Date.now() - timestamp < powTimeout : false;
|
|
48
|
-
if (!recent2) {
|
|
49
|
-
this.logger.error("PoW captcha is not recent");
|
|
50
|
-
return {
|
|
51
|
-
verified: false,
|
|
52
|
-
status: i18n.t("API.USER_NOT_VERIFIED_TIME_EXPIRED")
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
return await providerApi.submitPowCaptchaVerify(
|
|
56
|
-
token,
|
|
57
|
-
signatureHex,
|
|
58
|
-
timeouts.pow.cachedTimeout
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
const imageTimeout = this.config.timeouts.image.cachedTimeout;
|
|
62
|
-
const recent = timestamp ? Date.now() - timestamp < imageTimeout : false;
|
|
63
|
-
if (!recent) {
|
|
64
|
-
this.logger.error("Image captcha is not recent");
|
|
65
|
-
return {
|
|
66
|
-
verified: false,
|
|
67
|
-
status: i18n.t("API.USER_NOT_VERIFIED_TIME_EXPIRED")
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return await providerApi.verifyDappUser(
|
|
71
|
-
token,
|
|
72
|
-
signatureHex,
|
|
73
|
-
timeouts.image.cachedTimeout
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
*
|
|
78
|
-
* @returns
|
|
79
|
-
* @param token
|
|
80
|
-
*/
|
|
81
|
-
async isVerified(token) {
|
|
82
|
-
try {
|
|
83
|
-
const payload = types.decodeProcaptchaOutput(token);
|
|
84
|
-
const { providerUrl, challenge, timestamp } = types.ProcaptchaOutputSchema.parse(payload);
|
|
85
|
-
if (providerUrl) {
|
|
86
|
-
return await this.verifyProvider(
|
|
87
|
-
token,
|
|
88
|
-
this.config.timeouts,
|
|
89
|
-
providerUrl,
|
|
90
|
-
Number(timestamp),
|
|
91
|
-
challenge
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
this.logger.error("No provider URL found in user token");
|
|
95
|
-
return {
|
|
96
|
-
verified: false,
|
|
97
|
-
status: i18n.t("API.USER_NOT_VERIFIED")
|
|
98
|
-
};
|
|
99
|
-
} catch (err) {
|
|
100
|
-
this.logger.error({ err, token });
|
|
101
|
-
throw new common.ProsopoApiError("API.BAD_REQUEST", {
|
|
102
|
-
context: { code: 500, token }
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.ProsopoServer = ProsopoServer;
|
package/dist/config.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export declare const getServerConfig: () => {
|
|
2
|
-
timeouts: {
|
|
3
|
-
image: {
|
|
4
|
-
verifiedTimeout: number;
|
|
5
|
-
challengeTimeout: number;
|
|
6
|
-
solutionTimeout: number;
|
|
7
|
-
cachedTimeout: number;
|
|
8
|
-
};
|
|
9
|
-
pow: {
|
|
10
|
-
verifiedTimeout: number;
|
|
11
|
-
solutionTimeout: number;
|
|
12
|
-
cachedTimeout: number;
|
|
13
|
-
};
|
|
14
|
-
contract: {
|
|
15
|
-
maxVerifiedTime: number;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
logLevel: "error" | "trace" | "debug" | "info" | "warn" | "fatal" | "log";
|
|
19
|
-
defaultEnvironment: "development" | "staging" | "production";
|
|
20
|
-
account: {
|
|
21
|
-
secret?: string | undefined;
|
|
22
|
-
address?: string | undefined;
|
|
23
|
-
password?: string | undefined;
|
|
24
|
-
};
|
|
25
|
-
web2: boolean;
|
|
26
|
-
solutionThreshold: number;
|
|
27
|
-
dappName: string;
|
|
28
|
-
database?: Partial<Record<"development" | "staging" | "production", {
|
|
29
|
-
type: string;
|
|
30
|
-
endpoint: string;
|
|
31
|
-
dbname: string;
|
|
32
|
-
authSource: string;
|
|
33
|
-
}>> | undefined;
|
|
34
|
-
devOnlyWatchEvents?: boolean | undefined;
|
|
35
|
-
userAccountAddress?: string | undefined;
|
|
36
|
-
serverUrl?: string | undefined;
|
|
37
|
-
};
|
|
38
|
-
export declare const getServerUrl: () => string;
|
|
39
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;cAqBwghB,CAAC;eAAqC,CAAC;gBAAsC,CAAC;;;;;;;;;;;;;;CAX/mhB,CAAC;AAEJ,eAAO,MAAM,YAAY,QAAO,MAQ/B,CAAC"}
|
package/dist/config.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ProsopoServerConfigSchema } from "@prosopo/types";
|
|
2
|
-
export const getServerConfig = () => ProsopoServerConfigSchema.parse({
|
|
3
|
-
defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT,
|
|
4
|
-
serverUrl: getServerUrl(),
|
|
5
|
-
dappName: process.env.PROSOPO_DAPP_NAME || "client-example-server",
|
|
6
|
-
account: {
|
|
7
|
-
password: "",
|
|
8
|
-
address: process.env.PROSOPO_SITE_KEY || "",
|
|
9
|
-
secret: process.env.PROSOPO_SITE_PRIVATE_KEY || "",
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
export const getServerUrl = () => {
|
|
13
|
-
if (process.env.PROSOPO_SERVER_URL) {
|
|
14
|
-
if (process.env.PROSOPO_SERVER_URL.match(/:\d+/)) {
|
|
15
|
-
return process.env.PROSOPO_SERVER_URL;
|
|
16
|
-
}
|
|
17
|
-
return `${process.env.PROSOPO_SERVER_URL}:${process.env.PROSOPO_SERVER_PORT || 9228}`;
|
|
18
|
-
}
|
|
19
|
-
return "http://localhost:9228";
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,EAAE,CACnC,yBAAyB,CAAC,KAAK,CAAC;IAC/B,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B;IAC3D,SAAS,EAAE,YAAY,EAAE;IACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,uBAAuB;IAClE,OAAO,EAAE;QACR,QAAQ,EAAE,EAAE;QACZ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,EAAE;QAC3C,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,EAAE;KAClD;CACD,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,YAAY,GAAG,GAAW,EAAE;IACxC,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC;QACpC,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClD,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QACvC,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,IAAI,EAAE,CAAC;IACvF,CAAC;IACD,OAAO,uBAAuB,CAAC;AAChC,CAAC,CAAC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ProsopoServer } from "./server.js";
|
|
2
|
-
export { ProsopoServer } from "./server.js";
|
|
3
|
-
export { getServerConfig, getServerUrl } from "./config.js";
|
|
4
|
-
import type { ProsopoServerConfigOutput } from "@prosopo/types";
|
|
5
|
-
export declare const PublicProsopoServer: (config: ProsopoServerConfigOutput) => Promise<ProsopoServer>;
|
|
6
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,eAAO,MAAM,mBAAmB,WACvB,yBAAyB,2BAKjC,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ProsopoServer } from "./server.js";
|
|
2
|
-
export { ProsopoServer } from "./server.js";
|
|
3
|
-
export { getServerConfig, getServerUrl } from "./config.js";
|
|
4
|
-
import { getPairAsync } from "@prosopo/contract";
|
|
5
|
-
export const PublicProsopoServer = async (config) => {
|
|
6
|
-
const pair = await getPairAsync(undefined, config.account.address);
|
|
7
|
-
return new ProsopoServer(config, pair);
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EACvC,MAAiC,EAChC,EAAE;IAEH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
package/dist/server.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Keyring } from "@polkadot/keyring";
|
|
2
|
-
import type { KeyringPair } from "@polkadot/keyring/types";
|
|
3
|
-
import { ProviderApi } from "@prosopo/api";
|
|
4
|
-
import { type Logger } from "@prosopo/common";
|
|
5
|
-
import { type CaptchaTimeoutOutput, type ProcaptchaToken, type ProsopoServerConfigOutput, type VerificationResponse } from "@prosopo/types";
|
|
6
|
-
export declare class ProsopoServer {
|
|
7
|
-
config: ProsopoServerConfigOutput;
|
|
8
|
-
dappAccount: string | undefined;
|
|
9
|
-
defaultEnvironment: string;
|
|
10
|
-
logger: Logger;
|
|
11
|
-
keyring: Keyring;
|
|
12
|
-
pair: KeyringPair | undefined;
|
|
13
|
-
constructor(config: ProsopoServerConfigOutput, pair?: KeyringPair);
|
|
14
|
-
getProviderApi(providerUrl: string): ProviderApi;
|
|
15
|
-
verifyProvider(token: string, timeouts: CaptchaTimeoutOutput, providerUrl: string, timestamp: number, challenge?: string): Promise<VerificationResponse>;
|
|
16
|
-
isVerified(token: ProcaptchaToken): Promise<VerificationResponse>;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEN,KAAK,MAAM,EAIX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,KAAK,oBAAoB,EAEzB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,oBAAoB,EAEzB,MAAM,gBAAgB,CAAC;AAGxB,qBAAa,aAAa;IACzB,MAAM,EAAE,yBAAyB,CAAC;IAClC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;gBAElB,MAAM,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE,WAAW;IAcjE,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW;IAanC,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,oBAAoB,EAC9B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,oBAAoB,CAAC;IAgDnB,UAAU,CACtB,KAAK,EAAE,eAAe,GACpB,OAAO,CAAC,oBAAoB,CAAC;CA4BhC"}
|
package/dist/server.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Keyring } from "@polkadot/keyring";
|
|
2
|
-
import { u8aToHex } from "@polkadot/util";
|
|
3
|
-
import { ProviderApi } from "@prosopo/api";
|
|
4
|
-
import { ProsopoApiError, ProsopoContractError, getLogger, } from "@prosopo/common";
|
|
5
|
-
import { ProcaptchaOutputSchema, decodeProcaptchaOutput, } from "@prosopo/types";
|
|
6
|
-
import i18n from "i18next";
|
|
7
|
-
export class ProsopoServer {
|
|
8
|
-
constructor(config, pair) {
|
|
9
|
-
this.config = config;
|
|
10
|
-
this.pair = pair;
|
|
11
|
-
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
12
|
-
this.dappAccount = this.config.account.address;
|
|
13
|
-
this.logger = getLogger(this.config.logLevel, "@prosopo/server");
|
|
14
|
-
this.keyring = new Keyring({
|
|
15
|
-
type: "sr25519",
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
getProviderApi(providerUrl) {
|
|
19
|
-
return new ProviderApi(providerUrl, this.dappAccount || "");
|
|
20
|
-
}
|
|
21
|
-
async verifyProvider(token, timeouts, providerUrl, timestamp, challenge) {
|
|
22
|
-
this.logger.info("Verifying with provider.");
|
|
23
|
-
const dappUserSignature = this.pair?.sign(timestamp.toString());
|
|
24
|
-
if (!dappUserSignature) {
|
|
25
|
-
throw new ProsopoContractError("CAPTCHA.INVALID_TIMESTAMP", {
|
|
26
|
-
context: { error: "Timestamp not found" },
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
const signatureHex = u8aToHex(dappUserSignature);
|
|
30
|
-
const providerApi = this.getProviderApi(providerUrl);
|
|
31
|
-
if (challenge) {
|
|
32
|
-
const powTimeout = this.config.timeouts.pow.cachedTimeout;
|
|
33
|
-
const recent = timestamp ? Date.now() - timestamp < powTimeout : false;
|
|
34
|
-
if (!recent) {
|
|
35
|
-
this.logger.error("PoW captcha is not recent");
|
|
36
|
-
return {
|
|
37
|
-
verified: false,
|
|
38
|
-
status: i18n.t("API.USER_NOT_VERIFIED_TIME_EXPIRED"),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return await providerApi.submitPowCaptchaVerify(token, signatureHex, timeouts.pow.cachedTimeout);
|
|
42
|
-
}
|
|
43
|
-
const imageTimeout = this.config.timeouts.image.cachedTimeout;
|
|
44
|
-
const recent = timestamp ? Date.now() - timestamp < imageTimeout : false;
|
|
45
|
-
if (!recent) {
|
|
46
|
-
this.logger.error("Image captcha is not recent");
|
|
47
|
-
return {
|
|
48
|
-
verified: false,
|
|
49
|
-
status: i18n.t("API.USER_NOT_VERIFIED_TIME_EXPIRED"),
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return await providerApi.verifyDappUser(token, signatureHex, timeouts.image.cachedTimeout);
|
|
53
|
-
}
|
|
54
|
-
async isVerified(token) {
|
|
55
|
-
try {
|
|
56
|
-
const payload = decodeProcaptchaOutput(token);
|
|
57
|
-
const { providerUrl, challenge, timestamp } = ProcaptchaOutputSchema.parse(payload);
|
|
58
|
-
if (providerUrl) {
|
|
59
|
-
return await this.verifyProvider(token, this.config.timeouts, providerUrl, Number(timestamp), challenge);
|
|
60
|
-
}
|
|
61
|
-
this.logger.error("No provider URL found in user token");
|
|
62
|
-
return {
|
|
63
|
-
verified: false,
|
|
64
|
-
status: i18n.t("API.USER_NOT_VERIFIED"),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
this.logger.error({ err, token });
|
|
69
|
-
throw new ProsopoApiError("API.BAD_REQUEST", {
|
|
70
|
-
context: { code: 500, token },
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAGN,eAAe,EACf,oBAAoB,EACpB,SAAS,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEN,sBAAsB,EAItB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,MAAM,OAAO,aAAa;IAQzB,YA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