@prosopo/server 1.0.1 → 2.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/dist/cjs/index.cjs +5 -1
- package/dist/cjs/server.cjs +49 -126
- package/dist/config.d.ts +2 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +6 -6
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +7 -22
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +32 -108
- package/dist/server.js.map +1 -1
- package/package.json +49 -53
- package/vite.cjs.config.ts +3 -3
- package/typedoc.config.js +0 -19
package/dist/cjs/index.cjs
CHANGED
|
@@ -4,7 +4,11 @@ const server = require("./server.cjs");
|
|
|
4
4
|
const config = require("./config.cjs");
|
|
5
5
|
const contract = require("@prosopo/contract");
|
|
6
6
|
const PublicProsopoServer = async (config2) => {
|
|
7
|
-
const pair = await contract.getPairAsync(
|
|
7
|
+
const pair = await contract.getPairAsync(
|
|
8
|
+
config2.networks[config2.defaultNetwork],
|
|
9
|
+
void 0,
|
|
10
|
+
config2.account.address
|
|
11
|
+
);
|
|
8
12
|
return new server.ProsopoServer(config2, pair);
|
|
9
13
|
};
|
|
10
14
|
exports.ProsopoServer = server.ProsopoServer;
|
package/dist/cjs/server.cjs
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Api = require("@polkadot/api/promise/Api");
|
|
4
|
-
const types = require("@prosopo/types");
|
|
5
3
|
const keyring = require("@polkadot/keyring");
|
|
6
|
-
const
|
|
7
|
-
const contract = require("@prosopo/contract");
|
|
4
|
+
const util$1 = require("@polkadot/util");
|
|
8
5
|
const api = require("@prosopo/api");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
6
|
+
const common = require("@prosopo/common");
|
|
7
|
+
const types = require("@prosopo/types");
|
|
11
8
|
const util = require("@prosopo/util");
|
|
12
|
-
const util$1 = require("@polkadot/util");
|
|
13
9
|
class ProsopoServer {
|
|
14
10
|
constructor(config, pair) {
|
|
15
11
|
this.config = config;
|
|
@@ -17,113 +13,24 @@ class ProsopoServer {
|
|
|
17
13
|
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
18
14
|
const networkName = types.NetworkNamesSchema.parse(this.config.defaultNetwork);
|
|
19
15
|
this.network = util.get(this.config.networks, networkName);
|
|
20
|
-
this.wsProvider = new ws.WsProvider(this.network.endpoint);
|
|
21
16
|
this.prosopoContractAddress = this.network.contract.address;
|
|
22
17
|
this.dappContractAddress = this.config.account.address;
|
|
23
18
|
this.contractName = this.network.contract.name;
|
|
24
|
-
this.logger = common.getLogger(
|
|
19
|
+
this.logger = common.getLogger(
|
|
20
|
+
this.config.logLevel,
|
|
21
|
+
"@prosopo/server"
|
|
22
|
+
);
|
|
25
23
|
this.keyring = new keyring.Keyring({
|
|
26
24
|
type: "sr25519"
|
|
27
25
|
// TODO get this from the chain
|
|
28
26
|
});
|
|
29
|
-
this.abi = JSON.parse(contractInfo.ContractAbi);
|
|
30
|
-
}
|
|
31
|
-
async getProviderApi(providerUrl) {
|
|
32
|
-
return new api.ProviderApi(this.network, providerUrl, this.getDappContractAddress());
|
|
33
27
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
async isReady() {
|
|
41
|
-
try {
|
|
42
|
-
this.api = await Api.ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
43
|
-
await this.getSigner();
|
|
44
|
-
await this.getContractApi();
|
|
45
|
-
} catch (error) {
|
|
46
|
-
throw new common.ProsopoEnvError("GENERAL.ENVIRONMENT_NOT_READY", { context: { error } });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
async getSigner() {
|
|
50
|
-
if (this.pair) {
|
|
51
|
-
if (!this.api) {
|
|
52
|
-
this.api = await Api.ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
53
|
-
}
|
|
54
|
-
await this.api.isReadyOrError;
|
|
55
|
-
try {
|
|
56
|
-
this.pair = this.keyring.addPair(this.pair);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw new common.ProsopoEnvError("CONTRACT.SIGNER_UNDEFINED", {
|
|
59
|
-
context: { failedFuncName: this.getSigner.name, error }
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
getApi() {
|
|
65
|
-
if (this.api === void 0) {
|
|
66
|
-
throw new common.ProsopoEnvError(new Error("api undefined"));
|
|
67
|
-
}
|
|
68
|
-
return this.api;
|
|
69
|
-
}
|
|
70
|
-
getContract() {
|
|
71
|
-
if (this.contract === void 0) {
|
|
72
|
-
throw new common.ProsopoEnvError(new Error("contract undefined"));
|
|
73
|
-
}
|
|
74
|
-
return this.contract;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Check if the provider was actually chosen at blockNumber.
|
|
78
|
-
* - If no blockNumber is provided, check the last `n` blocks where `n` is the number of blocks that fit in
|
|
79
|
-
* `maxVerifiedTime`.
|
|
80
|
-
* - If no `maxVerifiedTime` is provided, use the default of 1 minute.
|
|
81
|
-
* @param user
|
|
82
|
-
* @param dapp
|
|
83
|
-
* @param providerUrl
|
|
84
|
-
* @param blockNumber
|
|
85
|
-
* @returns
|
|
86
|
-
*/
|
|
87
|
-
async checkRandomProvider(user, dapp, providerUrl, blockNumber) {
|
|
88
|
-
const block = await this.getApi().rpc.chain.getBlockHash(blockNumber);
|
|
89
|
-
const getRandomProviderResponse = await this.getContract().queryAtBlock(
|
|
90
|
-
block,
|
|
91
|
-
"getRandomActiveProvider",
|
|
92
|
-
[user, dapp]
|
|
28
|
+
getProviderApi(providerUrl) {
|
|
29
|
+
return new api.ProviderApi(
|
|
30
|
+
this.network,
|
|
31
|
+
providerUrl,
|
|
32
|
+
this.dappContractAddress || ""
|
|
93
33
|
);
|
|
94
|
-
if (common.trimProviderUrl(getRandomProviderResponse.provider.url.toString()) === providerUrl) {
|
|
95
|
-
return getRandomProviderResponse.provider;
|
|
96
|
-
}
|
|
97
|
-
return void 0;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Verify the user with the contract. We check the contract to see if the user has completed a captcha in the
|
|
101
|
-
* past. If they have, we check the time since the last correct captcha is within the maxVerifiedTime and we check
|
|
102
|
-
* whether the user is marked as human within the contract.
|
|
103
|
-
* @param user
|
|
104
|
-
* @param maxVerifiedTime
|
|
105
|
-
*/
|
|
106
|
-
async verifyContract(user, maxVerifiedTime) {
|
|
107
|
-
try {
|
|
108
|
-
const contractApi = await this.getContractApi();
|
|
109
|
-
this.logger.info("Provider URL not provided. Verifying with contract.");
|
|
110
|
-
const correctCaptchaBlockNumber = (await contractApi.query.dappOperatorLastCorrectCaptcha(user)).value.unwrap().unwrap().before.valueOf();
|
|
111
|
-
const recent = await contract.verifyRecency(
|
|
112
|
-
(await this.getContractApi()).api,
|
|
113
|
-
correctCaptchaBlockNumber,
|
|
114
|
-
maxVerifiedTime
|
|
115
|
-
);
|
|
116
|
-
if (!recent) {
|
|
117
|
-
this.logger.info("User has not completed a captcha recently");
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
const isHuman = (await contractApi.query.dappOperatorIsHumanUser(user, this.config.solutionThreshold)).value.unwrap().unwrap();
|
|
121
|
-
this.logger.info("isHuman", isHuman);
|
|
122
|
-
return isHuman;
|
|
123
|
-
} catch (error) {
|
|
124
|
-
this.logger.error(error);
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
34
|
}
|
|
128
35
|
/**
|
|
129
36
|
* Verify the user with the provider URL passed in. If a challenge is provided, we use the challenge to verify the
|
|
@@ -132,26 +39,45 @@ class ProsopoServer {
|
|
|
132
39
|
* @param blockNumber
|
|
133
40
|
* @param timeouts
|
|
134
41
|
* @param providerUrl
|
|
42
|
+
* @param timestamp
|
|
135
43
|
* @param challenge
|
|
136
44
|
*/
|
|
137
|
-
async verifyProvider(token, blockNumber, timeouts, providerUrl, challenge) {
|
|
45
|
+
async verifyProvider(token, blockNumber, timeouts, providerUrl, timestamp, challenge) {
|
|
138
46
|
this.logger.info("Verifying with provider.");
|
|
139
47
|
const blockNumberString = blockNumber.toString();
|
|
140
48
|
const dappUserSignature = this.pair?.sign(blockNumberString);
|
|
141
49
|
if (!dappUserSignature) {
|
|
142
|
-
throw new common.ProsopoContractError("CAPTCHA.INVALID_BLOCK_NO", {
|
|
50
|
+
throw new common.ProsopoContractError("CAPTCHA.INVALID_BLOCK_NO", {
|
|
51
|
+
context: { error: "Block number not found" }
|
|
52
|
+
});
|
|
143
53
|
}
|
|
144
54
|
const signatureHex = util$1.u8aToHex(dappUserSignature);
|
|
145
55
|
const providerApi = await this.getProviderApi(providerUrl);
|
|
146
56
|
if (challenge) {
|
|
147
|
-
const
|
|
57
|
+
const powTimeout = this.config.timeouts.pow.cachedTimeout;
|
|
58
|
+
const recent2 = timestamp ? Date.now() - timestamp < powTimeout : false;
|
|
59
|
+
if (!recent2) {
|
|
60
|
+
this.logger.error("PoW captcha is not recent");
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const result2 = await providerApi.submitPowCaptchaVerify(
|
|
64
|
+
token,
|
|
65
|
+
signatureHex,
|
|
66
|
+
timeouts.pow.cachedTimeout
|
|
67
|
+
);
|
|
148
68
|
return result2.verified;
|
|
149
69
|
}
|
|
150
|
-
const
|
|
70
|
+
const imageTimeout = this.config.timeouts.image.cachedTimeout;
|
|
71
|
+
const recent = timestamp ? Date.now() - timestamp < imageTimeout : false;
|
|
151
72
|
if (!recent) {
|
|
73
|
+
this.logger.error("Image captcha is not recent");
|
|
152
74
|
return false;
|
|
153
75
|
}
|
|
154
|
-
const result = await providerApi.verifyDappUser(
|
|
76
|
+
const result = await providerApi.verifyDappUser(
|
|
77
|
+
token,
|
|
78
|
+
signatureHex,
|
|
79
|
+
timeouts.image.cachedTimeout
|
|
80
|
+
);
|
|
155
81
|
return result.verified;
|
|
156
82
|
}
|
|
157
83
|
/**
|
|
@@ -165,23 +91,20 @@ class ProsopoServer {
|
|
|
165
91
|
return false;
|
|
166
92
|
}
|
|
167
93
|
const payload = types.decodeProcaptchaOutput(token);
|
|
168
|
-
const {
|
|
169
|
-
if (providerUrl
|
|
170
|
-
return await this.verifyProvider(
|
|
171
|
-
|
|
172
|
-
|
|
94
|
+
const { providerUrl, blockNumber, challenge, timestamp } = types.ProcaptchaOutputSchema.parse(payload);
|
|
95
|
+
if (providerUrl) {
|
|
96
|
+
return await this.verifyProvider(
|
|
97
|
+
token,
|
|
98
|
+
blockNumber,
|
|
99
|
+
this.config.timeouts,
|
|
100
|
+
providerUrl,
|
|
101
|
+
Number(timestamp),
|
|
102
|
+
challenge
|
|
103
|
+
);
|
|
173
104
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
this.getApi(),
|
|
178
|
-
this.abi,
|
|
179
|
-
this.prosopoContractAddress,
|
|
180
|
-
this.contractName,
|
|
181
|
-
0,
|
|
182
|
-
this.pair
|
|
183
|
-
);
|
|
184
|
-
return this.contract;
|
|
105
|
+
throw new common.ProsopoApiError("API.BAD_REQUEST", {
|
|
106
|
+
context: { message: "No provider URL" }
|
|
107
|
+
});
|
|
185
108
|
}
|
|
186
109
|
}
|
|
187
110
|
exports.ProsopoServer = ProsopoServer;
|
package/dist/config.d.ts
CHANGED
|
@@ -24,11 +24,11 @@ export declare const getServerConfig: () => {
|
|
|
24
24
|
password?: string | undefined;
|
|
25
25
|
};
|
|
26
26
|
networks: Record<"development" | "rococo" | "shiden" | "astar", {
|
|
27
|
-
endpoint: string[];
|
|
28
27
|
contract: {
|
|
29
|
-
address: string;
|
|
30
28
|
name: string;
|
|
29
|
+
address: string;
|
|
31
30
|
};
|
|
31
|
+
endpoint: string[];
|
|
32
32
|
pairType: "sr25519" | "ed25519" | "ecdsa" | "ethereum";
|
|
33
33
|
ss58Format: number;
|
|
34
34
|
}>;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWzB,CAAC;AAEJ,eAAO,MAAM,YAAY,QAAO,MAQ/B,CAAC"}
|
package/dist/config.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { ProsopoServerConfigSchema } from
|
|
1
|
+
import { ProsopoServerConfigSchema } from "@prosopo/types";
|
|
2
2
|
export const getServerConfig = () => ProsopoServerConfigSchema.parse({
|
|
3
3
|
defaultEnvironment: process.env.PROSOPO_DEFAULT_ENVIRONMENT,
|
|
4
4
|
defaultNetwork: process.env.PROSOPO_DEFAULT_NETWORK,
|
|
5
5
|
serverUrl: getServerUrl(),
|
|
6
|
-
dappName: process.env.PROSOPO_DAPP_NAME ||
|
|
6
|
+
dappName: process.env.PROSOPO_DAPP_NAME || "client-example-server",
|
|
7
7
|
account: {
|
|
8
|
-
password:
|
|
9
|
-
address: process.env.PROSOPO_SITE_KEY ||
|
|
10
|
-
secret: process.env.PROSOPO_SITE_PRIVATE_KEY ||
|
|
8
|
+
password: "",
|
|
9
|
+
address: process.env.PROSOPO_SITE_KEY || "",
|
|
10
|
+
secret: process.env.PROSOPO_SITE_PRIVATE_KEY || "",
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
export const getServerUrl = () => {
|
|
@@ -17,6 +17,6 @@ export const getServerUrl = () => {
|
|
|
17
17
|
}
|
|
18
18
|
return `${process.env.PROSOPO_SERVER_URL}:${process.env.PROSOPO_SERVER_PORT || 9228}`;
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return "http://localhost:9228";
|
|
21
21
|
};
|
|
22
22
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,
|
|
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,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;IACnD,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;QACnC,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACjD,OAAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;SACtC;QACD,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,IAAI,EAAE,CAAC;KACtF;IACD,OAAO,uBAAuB,CAAC;AAChC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ProsopoServer } from
|
|
2
|
-
export { ProsopoServer } from
|
|
3
|
-
export { getServerConfig, getServerUrl } from
|
|
4
|
-
import { ProsopoServerConfigOutput } from
|
|
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
5
|
export declare const PublicProsopoServer: (config: ProsopoServerConfigOutput) => Promise<ProsopoServer>;
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
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,EAAE,aAAa,EAAE,MAAM,aAAa,
|
|
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,2BASjC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ProsopoServer } from
|
|
2
|
-
export { ProsopoServer } from
|
|
3
|
-
export { getServerConfig, getServerUrl } from
|
|
4
|
-
import { getPairAsync } from
|
|
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
5
|
export const PublicProsopoServer = async (config) => {
|
|
6
6
|
const pair = await getPairAsync(config.networks[config.defaultNetwork], undefined, config.account.address);
|
|
7
7
|
return new ProsopoServer(config, pair);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,
|
|
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,CAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,EACtC,SAAS,EACT,MAAM,CAAC,OAAO,CAAC,OAAO,CACtB,CAAC;IACF,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,36 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ProsopoCaptchaContract } from '@prosopo/contract';
|
|
7
|
-
import { ProviderApi } from '@prosopo/api';
|
|
8
|
-
import { WsProvider } from '@polkadot/rpc-provider/ws';
|
|
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 NetworkConfig, type ProcaptchaToken, type ProsopoServerConfigOutput } from "@prosopo/types";
|
|
9
6
|
export declare class ProsopoServer {
|
|
10
7
|
config: ProsopoServerConfigOutput;
|
|
11
|
-
contract: ProsopoCaptchaContract | undefined;
|
|
12
8
|
prosopoContractAddress: string;
|
|
13
9
|
dappContractAddress: string | undefined;
|
|
14
10
|
defaultEnvironment: string;
|
|
15
11
|
contractName: string;
|
|
16
|
-
abi: ContractAbi;
|
|
17
12
|
logger: Logger;
|
|
18
|
-
wsProvider: WsProvider;
|
|
19
13
|
keyring: Keyring;
|
|
20
14
|
pair: KeyringPair | undefined;
|
|
21
|
-
api: ApiPromise | undefined;
|
|
22
15
|
network: NetworkConfig;
|
|
23
16
|
constructor(config: ProsopoServerConfigOutput, pair?: KeyringPair);
|
|
24
|
-
getProviderApi(providerUrl: string):
|
|
25
|
-
|
|
26
|
-
isReady(): Promise<void>;
|
|
27
|
-
getSigner(): Promise<void>;
|
|
28
|
-
getApi(): ApiPromise;
|
|
29
|
-
getContract(): ProsopoCaptchaContract;
|
|
30
|
-
checkRandomProvider(user: string, dapp: string, providerUrl: string, blockNumber: number): Promise<import("@prosopo/captcha-contract/types-returns").Provider | undefined>;
|
|
31
|
-
verifyContract(user: string, maxVerifiedTime: number): Promise<boolean>;
|
|
32
|
-
verifyProvider(token: string, blockNumber: number, timeouts: CaptchaTimeoutOutput, providerUrl: string, challenge?: string): Promise<boolean>;
|
|
17
|
+
getProviderApi(providerUrl: string): ProviderApi;
|
|
18
|
+
verifyProvider(token: string, blockNumber: number, timeouts: CaptchaTimeoutOutput, providerUrl: string, timestamp: number, challenge?: string): Promise<boolean>;
|
|
33
19
|
isVerified(token: ProcaptchaToken): Promise<boolean>;
|
|
34
|
-
getContractApi(): Promise<ProsopoCaptchaContract>;
|
|
35
20
|
}
|
|
36
21
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
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,EAEL,KAAK,MAAM,EAKZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,oBAAoB,EAEzB,KAAK,aAAa,EAGlB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC/B,MAAM,gBAAgB,CAAC;AAIxB,qBAAa,aAAa;IACxB,MAAM,EAAE,yBAAyB,CAAC;IAClC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC;IAC9B,OAAO,EAAE,aAAa,CAAC;gBAEX,MAAM,EAAE,yBAAyB,EAAE,IAAI,CAAC,EAAE,WAAW;IAkBjE,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW;IAkBnC,cAAc,CACzB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,oBAAoB,EAC9B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM;IA8CP,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;CA0BlE"}
|
package/dist/server.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ContractAbi as abiJson } from '@prosopo/captcha-contract/contract-info';
|
|
9
|
-
import { decodeProcaptchaOutput } from '@prosopo/types';
|
|
10
|
-
import { get } from '@prosopo/util';
|
|
11
|
-
import { isHex, u8aToHex } from '@polkadot/util';
|
|
1
|
+
import { Keyring } from "@polkadot/keyring";
|
|
2
|
+
import { isHex, u8aToHex } from "@polkadot/util";
|
|
3
|
+
import { ProviderApi } from "@prosopo/api";
|
|
4
|
+
import { ProsopoApiError, ProsopoContractError, getLogger, } from "@prosopo/common";
|
|
5
|
+
import { NetworkNamesSchema, ProcaptchaOutputSchema, } from "@prosopo/types";
|
|
6
|
+
import { decodeProcaptchaOutput } from "@prosopo/types";
|
|
7
|
+
import { get } from "@prosopo/util";
|
|
12
8
|
export class ProsopoServer {
|
|
13
9
|
constructor(config, pair) {
|
|
14
10
|
this.config = config;
|
|
@@ -16,110 +12,42 @@ export class ProsopoServer {
|
|
|
16
12
|
this.defaultEnvironment = this.config.defaultEnvironment;
|
|
17
13
|
const networkName = NetworkNamesSchema.parse(this.config.defaultNetwork);
|
|
18
14
|
this.network = get(this.config.networks, networkName);
|
|
19
|
-
this.wsProvider = new WsProvider(this.network.endpoint);
|
|
20
15
|
this.prosopoContractAddress = this.network.contract.address;
|
|
21
16
|
this.dappContractAddress = this.config.account.address;
|
|
22
17
|
this.contractName = this.network.contract.name;
|
|
23
|
-
this.logger = getLogger(this.config.logLevel,
|
|
18
|
+
this.logger = getLogger(this.config.logLevel, "@prosopo/server");
|
|
24
19
|
this.keyring = new Keyring({
|
|
25
|
-
type:
|
|
20
|
+
type: "sr25519",
|
|
26
21
|
});
|
|
27
|
-
this.abi = JSON.parse(abiJson);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
|
-
return new ProviderApi(this.network, providerUrl, this.
|
|
23
|
+
getProviderApi(providerUrl) {
|
|
24
|
+
return new ProviderApi(this.network, providerUrl, this.dappContractAddress || "");
|
|
31
25
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return getZeroAddress(this.getApi()).toString();
|
|
35
|
-
}
|
|
36
|
-
return this.dappContractAddress;
|
|
37
|
-
}
|
|
38
|
-
async isReady() {
|
|
39
|
-
try {
|
|
40
|
-
this.api = await ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
41
|
-
await this.getSigner();
|
|
42
|
-
await this.getContractApi();
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
throw new ProsopoEnvError('GENERAL.ENVIRONMENT_NOT_READY', { context: { error } });
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
async getSigner() {
|
|
49
|
-
if (this.pair) {
|
|
50
|
-
if (!this.api) {
|
|
51
|
-
this.api = await ApiPromise.create({ provider: this.wsProvider, initWasm: false, noInitWarn: true });
|
|
52
|
-
}
|
|
53
|
-
await this.api.isReadyOrError;
|
|
54
|
-
try {
|
|
55
|
-
this.pair = this.keyring.addPair(this.pair);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
throw new ProsopoEnvError('CONTRACT.SIGNER_UNDEFINED', {
|
|
59
|
-
context: { failedFuncName: this.getSigner.name, error },
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
getApi() {
|
|
65
|
-
if (this.api === undefined) {
|
|
66
|
-
throw new ProsopoEnvError(new Error('api undefined'));
|
|
67
|
-
}
|
|
68
|
-
return this.api;
|
|
69
|
-
}
|
|
70
|
-
getContract() {
|
|
71
|
-
if (this.contract === undefined) {
|
|
72
|
-
throw new ProsopoEnvError(new Error('contract undefined'));
|
|
73
|
-
}
|
|
74
|
-
return this.contract;
|
|
75
|
-
}
|
|
76
|
-
async checkRandomProvider(user, dapp, providerUrl, blockNumber) {
|
|
77
|
-
const block = await this.getApi().rpc.chain.getBlockHash(blockNumber);
|
|
78
|
-
const getRandomProviderResponse = await this.getContract().queryAtBlock(block, 'getRandomActiveProvider', [user, dapp]);
|
|
79
|
-
if (trimProviderUrl(getRandomProviderResponse.provider.url.toString()) === providerUrl) {
|
|
80
|
-
return getRandomProviderResponse.provider;
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
async verifyContract(user, maxVerifiedTime) {
|
|
85
|
-
try {
|
|
86
|
-
const contractApi = await this.getContractApi();
|
|
87
|
-
this.logger.info('Provider URL not provided. Verifying with contract.');
|
|
88
|
-
const correctCaptchaBlockNumber = (await contractApi.query.dappOperatorLastCorrectCaptcha(user)).value
|
|
89
|
-
.unwrap()
|
|
90
|
-
.unwrap()
|
|
91
|
-
.before.valueOf();
|
|
92
|
-
const recent = await verifyRecency((await this.getContractApi()).api, correctCaptchaBlockNumber, maxVerifiedTime);
|
|
93
|
-
if (!recent) {
|
|
94
|
-
this.logger.info('User has not completed a captcha recently');
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
const isHuman = (await contractApi.query.dappOperatorIsHumanUser(user, this.config.solutionThreshold)).value
|
|
98
|
-
.unwrap()
|
|
99
|
-
.unwrap();
|
|
100
|
-
this.logger.info('isHuman', isHuman);
|
|
101
|
-
return isHuman;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
this.logger.error(error);
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
async verifyProvider(token, blockNumber, timeouts, providerUrl, challenge) {
|
|
109
|
-
this.logger.info('Verifying with provider.');
|
|
26
|
+
async verifyProvider(token, blockNumber, timeouts, providerUrl, timestamp, challenge) {
|
|
27
|
+
this.logger.info("Verifying with provider.");
|
|
110
28
|
const blockNumberString = blockNumber.toString();
|
|
111
29
|
const dappUserSignature = this.pair?.sign(blockNumberString);
|
|
112
30
|
if (!dappUserSignature) {
|
|
113
|
-
throw new ProsopoContractError(
|
|
31
|
+
throw new ProsopoContractError("CAPTCHA.INVALID_BLOCK_NO", {
|
|
32
|
+
context: { error: "Block number not found" },
|
|
33
|
+
});
|
|
114
34
|
}
|
|
115
35
|
const signatureHex = u8aToHex(dappUserSignature);
|
|
116
36
|
const providerApi = await this.getProviderApi(providerUrl);
|
|
117
37
|
if (challenge) {
|
|
38
|
+
const powTimeout = this.config.timeouts.pow.cachedTimeout;
|
|
39
|
+
const recent = timestamp ? Date.now() - timestamp < powTimeout : false;
|
|
40
|
+
if (!recent) {
|
|
41
|
+
this.logger.error("PoW captcha is not recent");
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
118
44
|
const result = await providerApi.submitPowCaptchaVerify(token, signatureHex, timeouts.pow.cachedTimeout);
|
|
119
45
|
return result.verified;
|
|
120
46
|
}
|
|
121
|
-
const
|
|
47
|
+
const imageTimeout = this.config.timeouts.image.cachedTimeout;
|
|
48
|
+
const recent = timestamp ? Date.now() - timestamp < imageTimeout : false;
|
|
122
49
|
if (!recent) {
|
|
50
|
+
this.logger.error("Image captcha is not recent");
|
|
123
51
|
return false;
|
|
124
52
|
}
|
|
125
53
|
const result = await providerApi.verifyDappUser(token, signatureHex, timeouts.image.cachedTimeout);
|
|
@@ -127,21 +55,17 @@ export class ProsopoServer {
|
|
|
127
55
|
}
|
|
128
56
|
async isVerified(token) {
|
|
129
57
|
if (!isHex(token)) {
|
|
130
|
-
this.logger.error(
|
|
58
|
+
this.logger.error("Invalid token - not hex", token);
|
|
131
59
|
return false;
|
|
132
60
|
}
|
|
133
61
|
const payload = decodeProcaptchaOutput(token);
|
|
134
|
-
const {
|
|
135
|
-
if (providerUrl
|
|
136
|
-
return await this.verifyProvider(token, blockNumber, this.config.timeouts, providerUrl, challenge);
|
|
62
|
+
const { providerUrl, blockNumber, challenge, timestamp } = ProcaptchaOutputSchema.parse(payload);
|
|
63
|
+
if (providerUrl) {
|
|
64
|
+
return await this.verifyProvider(token, blockNumber, this.config.timeouts, providerUrl, Number(timestamp), challenge);
|
|
137
65
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async getContractApi() {
|
|
143
|
-
this.contract = new ProsopoCaptchaContract(this.getApi(), this.abi, this.prosopoContractAddress, this.contractName, 0, this.pair);
|
|
144
|
-
return this.contract;
|
|
66
|
+
throw new ProsopoApiError("API.BAD_REQUEST", {
|
|
67
|
+
context: { message: "No provider URL" },
|
|
68
|
+
});
|
|
145
69
|
}
|
|
146
70
|
}
|
|
147
71
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAGL,eAAe,EACf,oBAAoB,EAEpB,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAIL,kBAAkB,EAClB,sBAAsB,GAGvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,MAAM,OAAO,aAAa;IAWxB,YAAY,MAAiC,EAAE,IAAkB;QAC/D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACr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|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"devDependencies": {
|
|
52
|
-
"tslib": "2.6.2",
|
|
53
|
-
"typescript": "5.1.6"
|
|
54
|
-
}
|
|
2
|
+
"name": "@prosopo/server",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "NodeJS package for server side communication with the prosopo captcha client",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20",
|
|
9
|
+
"npm": ">=9"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"No test specified\"",
|
|
19
|
+
"clean": "tsc --build --clean",
|
|
20
|
+
"build": "tsc --build --verbose",
|
|
21
|
+
"build:cjs": "npx vite --config vite.cjs.config.ts build"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/prosopo/captcha.git"
|
|
26
|
+
},
|
|
27
|
+
"author": "PROSOPO LIMITED",
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/prosopo/captcha/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/prosopo/captcha#readme",
|
|
33
|
+
"sideEffects": false,
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@polkadot/api": "10.13.1",
|
|
36
|
+
"@polkadot/keyring": "12.6.2",
|
|
37
|
+
"@polkadot/rpc-provider": "10.13.1",
|
|
38
|
+
"@polkadot/util": "12.6.2",
|
|
39
|
+
"@prosopo/api": "2.0.0",
|
|
40
|
+
"@prosopo/common": "2.0.0",
|
|
41
|
+
"@prosopo/contract": "2.0.0",
|
|
42
|
+
|
|
43
|
+
"@prosopo/util": "2.0.0",
|
|
44
|
+
"@prosopo/types": "2.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@prosopo/config": "2.0.0",
|
|
48
|
+
"tslib": "2.6.2",
|
|
49
|
+
"typescript": "5.1.6"
|
|
50
|
+
}
|
|
55
51
|
}
|
package/vite.cjs.config.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
// Copyright 2021-2024 Prosopo (UK) Ltd.
|
|
2
3
|
//
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -11,9 +12,8 @@
|
|
|
11
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
13
|
// See the License for the specific language governing permissions and
|
|
13
14
|
// limitations under the License.
|
|
14
|
-
import { ViteCommonJSConfig } from
|
|
15
|
-
import path from 'path'
|
|
15
|
+
import { ViteCommonJSConfig } from "@prosopo/config";
|
|
16
16
|
|
|
17
17
|
export default function () {
|
|
18
|
-
|
|
18
|
+
return ViteCommonJSConfig("server", path.resolve("./tsconfig.cjs.json"));
|
|
19
19
|
}
|
package/typedoc.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2024 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
export default {
|
|
15
|
-
entryPoints: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.js', 'src/**/*.jsx', 'src/**/*.json'],
|
|
16
|
-
includes: 'src',
|
|
17
|
-
extends: '../../typedoc.base.config.js',
|
|
18
|
-
readme: 'README.md',
|
|
19
|
-
}
|