@prosopo/procaptcha 0.1.9 → 0.1.10
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/.eslintrc.js +28 -29
- package/.prettierrc.js +7 -0
- package/dist/api/AsyncFactory.d.ts.map +1 -1
- package/dist/api/AsyncFactory.js +2 -2
- package/dist/api/AsyncFactory.js.map +1 -1
- package/dist/api/Extension.d.ts +15 -0
- package/dist/api/Extension.d.ts.map +1 -0
- package/dist/api/Extension.js +9 -0
- package/dist/api/Extension.js.map +1 -0
- package/dist/api/ExtensionWeb2.d.ts +10 -25
- package/dist/api/ExtensionWeb2.d.ts.map +1 -1
- package/dist/api/ExtensionWeb2.js +79 -90
- package/dist/api/ExtensionWeb2.js.map +1 -1
- package/dist/api/ExtensionWeb3.d.ts +5 -52
- package/dist/api/ExtensionWeb3.d.ts.map +1 -1
- package/dist/api/ExtensionWeb3.js +24 -142
- package/dist/api/ExtensionWeb3.js.map +1 -1
- package/dist/api/HttpClientBase.d.ts +1 -1
- package/dist/api/HttpClientBase.d.ts.map +1 -1
- package/dist/api/HttpClientBase.js +2 -2
- package/dist/api/HttpClientBase.js.map +1 -1
- package/dist/api/ProsopoContract.d.ts +3 -3
- package/dist/api/ProsopoContract.d.ts.map +1 -1
- package/dist/api/ProsopoContract.js +25 -4
- package/dist/api/ProsopoContract.js.map +1 -1
- package/dist/api/ProsopoContractBase.d.ts +18 -20
- package/dist/api/ProsopoContractBase.d.ts.map +1 -1
- package/dist/api/ProsopoContractBase.js +34 -27
- package/dist/api/ProsopoContractBase.js.map +1 -1
- package/dist/api/errors.d.ts +13 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +28 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/handlers.d.ts +2 -2
- package/dist/api/handlers.d.ts.map +1 -1
- package/dist/api/handlers.js +2 -10
- package/dist/api/handlers.js.map +1 -1
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +0 -1
- package/dist/api/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modules/Manager.d.ts +13 -0
- package/dist/modules/Manager.d.ts.map +1 -0
- package/dist/modules/Manager.js +346 -0
- package/dist/modules/Manager.js.map +1 -0
- package/dist/modules/ProsopoCaptchaApi.d.ts +12 -14
- package/dist/modules/ProsopoCaptchaApi.d.ts.map +1 -1
- package/dist/modules/ProsopoCaptchaApi.js +36 -56
- package/dist/modules/ProsopoCaptchaApi.js.map +1 -1
- package/dist/modules/ProsopoCaptchaStateClient.d.ts +0 -17
- package/dist/modules/ProsopoCaptchaStateClient.d.ts.map +1 -1
- package/dist/modules/ProsopoCaptchaStateClient.js +0 -109
- package/dist/modules/ProsopoCaptchaStateClient.js.map +1 -1
- package/dist/modules/canvas.d.ts.map +1 -1
- package/dist/modules/canvas.js +84 -21
- package/dist/modules/canvas.js.map +1 -1
- package/dist/modules/index.d.ts +1 -6
- package/dist/modules/index.d.ts.map +1 -1
- package/dist/modules/index.js +1 -6
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/storage.d.ts +10 -0
- package/dist/modules/storage.d.ts.map +1 -1
- package/dist/modules/storage.js +17 -17
- package/dist/modules/storage.js.map +1 -1
- package/dist/types/api.d.ts +19 -21
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/client.d.ts +10 -60
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/contract.d.ts +1 -1
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/manager.d.ts +67 -0
- package/dist/types/manager.d.ts.map +1 -0
- package/dist/types/manager.js +3 -0
- package/dist/types/manager.js.map +1 -0
- package/dist/types/utils.d.ts +2 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/dist/types/utils.js +3 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +8 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +4 -3
- package/tsconfig.json +5 -2
- package/dist/api/AccountCreator.d.ts +0 -19
- package/dist/api/AccountCreator.d.ts.map +0 -1
- package/dist/api/AccountCreator.js +0 -88
- package/dist/api/AccountCreator.js.map +0 -1
- package/dist/api/ProviderApi.d.ts +0 -14
- package/dist/api/ProviderApi.d.ts.map +0 -1
- package/dist/api/ProviderApi.js +0 -53
- package/dist/api/ProviderApi.js.map +0 -1
- package/dist/modules/ProsopoCaptchaClient.d.ts +0 -26
- package/dist/modules/ProsopoCaptchaClient.d.ts.map +0 -1
- package/dist/modules/ProsopoCaptchaClient.js +0 -112
- package/dist/modules/ProsopoCaptchaClient.js.map +0 -1
- package/dist/modules/client.d.ts +0 -9
- package/dist/modules/client.d.ts.map +0 -1
- package/dist/modules/client.js +0 -40
- package/dist/modules/client.js.map +0 -1
- package/dist/modules/contract.d.ts +0 -7
- package/dist/modules/contract.d.ts.map +0 -1
- package/dist/modules/contract.js +0 -42
- package/dist/modules/contract.js.map +0 -1
- package/dist/modules/extension.d.ts +0 -4
- package/dist/modules/extension.d.ts.map +0 -1
- package/dist/modules/extension.js +0 -31
- package/dist/modules/extension.js.map +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Manager = exports.defaultState = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ProsopoContract_1 = tslib_1.__importDefault(require("../api/ProsopoContract"));
|
|
6
|
+
const rpc_provider_1 = require("@polkadot/rpc-provider");
|
|
7
|
+
const storage_1 = tslib_1.__importDefault(require("./storage"));
|
|
8
|
+
const api_1 = require("@prosopo/api");
|
|
9
|
+
const util_1 = require("@polkadot/util");
|
|
10
|
+
const ProsopoCaptchaApi_1 = tslib_1.__importDefault(require("./ProsopoCaptchaApi"));
|
|
11
|
+
const utils_1 = require("../utils/utils");
|
|
12
|
+
const ExtensionWeb2_1 = tslib_1.__importDefault(require("../api/ExtensionWeb2"));
|
|
13
|
+
const ExtensionWeb3_1 = tslib_1.__importDefault(require("../api/ExtensionWeb3"));
|
|
14
|
+
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
15
|
+
const defaultState = () => {
|
|
16
|
+
return {
|
|
17
|
+
// note order matters! see buildUpdateState. These fields are set in order, so disable modal first, then set loading to false, etc.
|
|
18
|
+
showModal: false,
|
|
19
|
+
loading: false,
|
|
20
|
+
challenge: undefined,
|
|
21
|
+
solutions: [],
|
|
22
|
+
index: -1,
|
|
23
|
+
isHuman: false,
|
|
24
|
+
captchaApi: undefined,
|
|
25
|
+
account: undefined,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.defaultState = defaultState;
|
|
29
|
+
const buildUpdateState = (state, onStateUpdate) => {
|
|
30
|
+
const updateCurrentState = (nextState) => {
|
|
31
|
+
// mutate the current state. Note that this is in order of properties in the nextState object.
|
|
32
|
+
// e.g. given {b: 2, c: 3, a: 1}, b will be set, then c, then a. This is because JS stores fields in insertion order by default, unless you override it with a class or such by changing the key enumeration order.
|
|
33
|
+
for (const key in nextState) {
|
|
34
|
+
state[key] = nextState[key];
|
|
35
|
+
}
|
|
36
|
+
// then call the update function for the frontend to do the same
|
|
37
|
+
onStateUpdate(nextState);
|
|
38
|
+
console.log('Procaptcha state update:', nextState, '\nResult:', state);
|
|
39
|
+
};
|
|
40
|
+
return updateCurrentState;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The state operator. This is used to mutate the state of Procaptcha during the captcha process. State updates are published via the onStateUpdate callback. This should be used by frontends, e.g. react, to maintain the state of Procaptcha across renders.
|
|
44
|
+
*/
|
|
45
|
+
const Manager = (configOptional, state, onStateUpdate, callbacks) => {
|
|
46
|
+
// events are emitted at various points during the captcha process. These each have default behaviours below which can be overridden by the frontend using callbacks.
|
|
47
|
+
const events = Object.assign({
|
|
48
|
+
onAccountNotFound: (address) => {
|
|
49
|
+
alert(`Account ${address} not found`);
|
|
50
|
+
},
|
|
51
|
+
onError: (error) => {
|
|
52
|
+
alert(error ? error.message : 'An error occurred');
|
|
53
|
+
},
|
|
54
|
+
onHuman: (output) => {
|
|
55
|
+
console.log('onHuman event triggered', output);
|
|
56
|
+
},
|
|
57
|
+
onExtensionNotFound: () => {
|
|
58
|
+
alert('No extension found');
|
|
59
|
+
},
|
|
60
|
+
}, callbacks);
|
|
61
|
+
// mapping of type of error to relevant event callback
|
|
62
|
+
const errorToEventMap = {
|
|
63
|
+
AccountNotFoundError: events.onAccountNotFound,
|
|
64
|
+
ExtensionNotFoundError: events.onExtensionNotFound,
|
|
65
|
+
Error: events.onError,
|
|
66
|
+
};
|
|
67
|
+
// get the state update mechanism
|
|
68
|
+
const updateState = buildUpdateState(state, onStateUpdate);
|
|
69
|
+
/**
|
|
70
|
+
* Build the config on demand, using the optional config passed in from the outside. State may override various config values depending on the state of the captcha process. E.g. if the process has been started using account "ABC" and then the user changes account to "DEF" via the optional config prop, the account in use will not change. This is because the captcha process has already been started using account "ABC".
|
|
71
|
+
* @returns the config for procaptcha
|
|
72
|
+
*/
|
|
73
|
+
const getConfig = () => {
|
|
74
|
+
const config = {
|
|
75
|
+
web2: false,
|
|
76
|
+
userAccountAddress: '',
|
|
77
|
+
...configOptional,
|
|
78
|
+
};
|
|
79
|
+
// overwrite the account in use with the one in state if it exists. Reduces likelihood of bugs where the user changes account in the middle of the captcha process.
|
|
80
|
+
if (state.account) {
|
|
81
|
+
config.userAccountAddress = state.account.account.address;
|
|
82
|
+
}
|
|
83
|
+
return config;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Called on start of user verification. This is when the user ticks the box to claim they are human.
|
|
87
|
+
*/
|
|
88
|
+
const start = async () => {
|
|
89
|
+
try {
|
|
90
|
+
if (state.loading) {
|
|
91
|
+
console.log('Procaptcha already loading');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (state.isHuman) {
|
|
95
|
+
console.log('already human');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
resetState();
|
|
99
|
+
// set the loading flag to true (allow UI to show some sort of loading / pending indicator while we get the captcha process going)
|
|
100
|
+
updateState({ loading: true });
|
|
101
|
+
// snapshot the config into the state
|
|
102
|
+
const config = getConfig();
|
|
103
|
+
console.log('Starting procaptcha using config:', config);
|
|
104
|
+
// allow UI to catch up with the loading state
|
|
105
|
+
await (0, utils_1.sleep)(100);
|
|
106
|
+
// check accounts / setup accounts
|
|
107
|
+
const account = await loadAccount();
|
|
108
|
+
// account has been found, check if account is already marked as human
|
|
109
|
+
// first, ask the smart contract
|
|
110
|
+
const contract = await loadContract();
|
|
111
|
+
// We don't need to show CAPTCHA challenges if the user is determined as human by the contract
|
|
112
|
+
const contractIsHuman = await contract.dappOperatorIsHumanUser(config.solutionThreshold);
|
|
113
|
+
if (contractIsHuman) {
|
|
114
|
+
updateState({ isHuman: true, loading: false });
|
|
115
|
+
events.onHuman({
|
|
116
|
+
userAccountAddress: account.account.address,
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// Check if there is a provider in local storage or get a random one from the contract
|
|
121
|
+
const providerUrlFromStorage = storage_1.default.getProviderUrl();
|
|
122
|
+
let providerApi;
|
|
123
|
+
if (providerUrlFromStorage) {
|
|
124
|
+
providerApi = await loadProviderApi(providerUrlFromStorage);
|
|
125
|
+
// if the provider was already in storage, the user may have already solved some captchas but they have not been put on chain yet
|
|
126
|
+
// so contact the provider to check if this is the case
|
|
127
|
+
try {
|
|
128
|
+
const verifyDappUserResponse = await providerApi.verifyDappUser(account.account.address);
|
|
129
|
+
if (verifyDappUserResponse.solutionApproved) {
|
|
130
|
+
updateState({ isHuman: true, loading: false });
|
|
131
|
+
events.onHuman({
|
|
132
|
+
providerUrl: providerUrlFromStorage,
|
|
133
|
+
userAccountAddress: account.account.address,
|
|
134
|
+
commitmentId: verifyDappUserResponse.commitmentId,
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
// if the provider is down, we should continue with the process of selecting a random provider
|
|
141
|
+
console.error('Error contacting provider from storage', providerUrlFromStorage);
|
|
142
|
+
// continue as if the provider was not in storage
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// get a random provider
|
|
146
|
+
const provider = await loadRandomProvider(contract);
|
|
147
|
+
console.log('provider', provider);
|
|
148
|
+
const providerUrl = provider.provider.serviceOrigin;
|
|
149
|
+
// get the provider api inst
|
|
150
|
+
providerApi = await loadProviderApi(providerUrl);
|
|
151
|
+
console.log('providerApi', providerApi);
|
|
152
|
+
// get the captcha challenge and begin the challenge
|
|
153
|
+
const captchaApi = await loadCaptchaApi(contract, provider, providerApi);
|
|
154
|
+
console.log('captchaApi', captchaApi);
|
|
155
|
+
const challenge = await captchaApi.getCaptchaChallenge();
|
|
156
|
+
if (challenge.captchas.length <= 0) {
|
|
157
|
+
throw new Error('No captchas returned from provider');
|
|
158
|
+
}
|
|
159
|
+
// update state with new challenge
|
|
160
|
+
updateState({
|
|
161
|
+
index: 0,
|
|
162
|
+
solutions: challenge.captchas.map(() => []),
|
|
163
|
+
challenge,
|
|
164
|
+
showModal: true,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.error(err);
|
|
169
|
+
// dispatch relevant error event
|
|
170
|
+
const event = errorToEventMap[err.constructor] || events.onError;
|
|
171
|
+
event(err);
|
|
172
|
+
// hit an error, disallow user's claim to be human
|
|
173
|
+
updateState({ isHuman: false, showModal: false, loading: false });
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const loadRandomProvider = async (contract) => {
|
|
177
|
+
const provider = await contract.getRandomProvider();
|
|
178
|
+
console.log('Got random provider', provider);
|
|
179
|
+
if (!provider || !provider.provider || !provider.provider.serviceOrigin) {
|
|
180
|
+
throw new Error('No provider found: ' + JSON.stringify(provider));
|
|
181
|
+
}
|
|
182
|
+
provider.provider.serviceOrigin = trimProviderUrl(provider.provider.serviceOrigin);
|
|
183
|
+
// record provider in localstorage for subsequent human checks (i.e. if the user has already solved some captchas but they have not been put on chain yet, contact the provider in the local storage to verify)
|
|
184
|
+
storage_1.default.setProviderUrl(provider.provider.serviceOrigin);
|
|
185
|
+
return provider;
|
|
186
|
+
};
|
|
187
|
+
const submit = async () => {
|
|
188
|
+
try {
|
|
189
|
+
console.log('submitting solutions');
|
|
190
|
+
if (!state.challenge) {
|
|
191
|
+
throw new Error('cannot submit, no challenge found');
|
|
192
|
+
}
|
|
193
|
+
// hide the modal, no further input required from user
|
|
194
|
+
updateState({ showModal: false });
|
|
195
|
+
const challenge = state.challenge;
|
|
196
|
+
const salt = (0, util_crypto_1.randomAsHex)();
|
|
197
|
+
// append solution to each captcha in the challenge
|
|
198
|
+
const captchaSolution = state.challenge.captchas.map((captcha, index) => {
|
|
199
|
+
const solution = state.solutions[index];
|
|
200
|
+
return {
|
|
201
|
+
captchaId: captcha.captcha.captchaId,
|
|
202
|
+
captchaContentId: captcha.captcha.captchaContentId,
|
|
203
|
+
salt,
|
|
204
|
+
solution,
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
const account = getAccount();
|
|
208
|
+
const signer = account.extension.signer;
|
|
209
|
+
if (!challenge.captchas[0].captcha.datasetId) {
|
|
210
|
+
throw new Error('No datasetId set for challenge');
|
|
211
|
+
}
|
|
212
|
+
const captchaApi = getCaptchaApi();
|
|
213
|
+
// send the commitment to the provider
|
|
214
|
+
const submission = await captchaApi.submitCaptchaSolution(signer, challenge.requestHash, challenge.captchas[0].captcha.datasetId, captchaSolution, salt);
|
|
215
|
+
// update the state with the result of the submission
|
|
216
|
+
updateState({
|
|
217
|
+
submission,
|
|
218
|
+
// mark as is human if solution has been approved
|
|
219
|
+
isHuman: submission[0].solutionApproved,
|
|
220
|
+
loading: false,
|
|
221
|
+
});
|
|
222
|
+
if (state.isHuman) {
|
|
223
|
+
events.onHuman({
|
|
224
|
+
providerUrl: captchaApi.provider.provider.serviceOrigin,
|
|
225
|
+
userAccountAddress: account.account.address,
|
|
226
|
+
commitmentId: submission[1],
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
// dispatch relevant error event
|
|
232
|
+
const event = errorToEventMap[err.constructor] || events.onError;
|
|
233
|
+
event(err);
|
|
234
|
+
// hit an error, disallow user's claim to be human
|
|
235
|
+
updateState({ isHuman: false, showModal: false, loading: false });
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
const cancel = async () => {
|
|
239
|
+
console.log('cancel');
|
|
240
|
+
// abandon the captcha process
|
|
241
|
+
resetState();
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* (De)Select an image from the solution for the current round. If the hash is already in the solutions list, it will be removed (deselected) and if not it will be added (selected).
|
|
245
|
+
* @param hash the hash of the image
|
|
246
|
+
*/
|
|
247
|
+
const select = (hash) => {
|
|
248
|
+
if (!state.challenge) {
|
|
249
|
+
throw new Error('cannot select, no challenge found');
|
|
250
|
+
}
|
|
251
|
+
if (state.index >= state.challenge.captchas.length || state.index < 0) {
|
|
252
|
+
throw new Error('cannot select, round index out of range');
|
|
253
|
+
}
|
|
254
|
+
const index = state.index;
|
|
255
|
+
const solutions = state.solutions;
|
|
256
|
+
const solution = solutions[index];
|
|
257
|
+
if (solution.includes(hash)) {
|
|
258
|
+
console.log('deselecting', hash);
|
|
259
|
+
// remove the hash from the solution
|
|
260
|
+
solution.splice(solution.indexOf(hash), 1);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
console.log('selecting', hash);
|
|
264
|
+
// add the hash to the solution
|
|
265
|
+
solution.push(hash);
|
|
266
|
+
}
|
|
267
|
+
updateState({ solutions });
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Proceed to the next round of the challenge.
|
|
271
|
+
*/
|
|
272
|
+
const nextRound = () => {
|
|
273
|
+
if (!state.challenge) {
|
|
274
|
+
throw new Error('cannot proceed to next round, no challenge found');
|
|
275
|
+
}
|
|
276
|
+
if (state.index + 1 >= state.challenge.captchas.length) {
|
|
277
|
+
throw new Error('cannot proceed to next round, already at last round');
|
|
278
|
+
}
|
|
279
|
+
console.log('proceeding to next round');
|
|
280
|
+
updateState({ index: state.index + 1 });
|
|
281
|
+
};
|
|
282
|
+
const loadCaptchaApi = async (contract, provider, providerApi) => {
|
|
283
|
+
const config = getConfig();
|
|
284
|
+
// setup the captcha api to carry out a challenge
|
|
285
|
+
const captchaApi = new ProsopoCaptchaApi_1.default(getAccount().account.address, contract, provider, providerApi, config.web2);
|
|
286
|
+
updateState({ captchaApi });
|
|
287
|
+
return getCaptchaApi();
|
|
288
|
+
};
|
|
289
|
+
const loadProviderApi = async (providerUrl) => {
|
|
290
|
+
const config = getConfig();
|
|
291
|
+
const providerApi = new api_1.ProviderApi(config.network, providerUrl);
|
|
292
|
+
return providerApi;
|
|
293
|
+
};
|
|
294
|
+
const resetState = () => {
|
|
295
|
+
updateState((0, exports.defaultState)());
|
|
296
|
+
};
|
|
297
|
+
const getCaptchaApi = () => {
|
|
298
|
+
if (!state.captchaApi) {
|
|
299
|
+
throw new Error('Captcha api not set');
|
|
300
|
+
}
|
|
301
|
+
return state.captchaApi;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Load the account using address specified in config, or generate new address if not found in local storage for web2 mode.
|
|
305
|
+
*/
|
|
306
|
+
const loadAccount = async () => {
|
|
307
|
+
const config = getConfig();
|
|
308
|
+
// check if account has been provided in config (doesn't matter in web2 mode)
|
|
309
|
+
if (!config.web2 && !config.userAccountAddress) {
|
|
310
|
+
throw new Error('Account address has not been set for web3 mode');
|
|
311
|
+
}
|
|
312
|
+
// check if account exists in extension
|
|
313
|
+
const ext = config.web2 ? new ExtensionWeb2_1.default() : new ExtensionWeb3_1.default();
|
|
314
|
+
const account = await ext.getAccount(config);
|
|
315
|
+
console.log('Using account:', account);
|
|
316
|
+
updateState({ account });
|
|
317
|
+
return getAccount();
|
|
318
|
+
};
|
|
319
|
+
const getAccount = () => {
|
|
320
|
+
if (!state.account) {
|
|
321
|
+
throw new Error('Account not loaded');
|
|
322
|
+
}
|
|
323
|
+
const account = state.account;
|
|
324
|
+
return account;
|
|
325
|
+
};
|
|
326
|
+
/**
|
|
327
|
+
* Load the contract instance using addresses from config.
|
|
328
|
+
*/
|
|
329
|
+
const loadContract = async () => {
|
|
330
|
+
const config = getConfig();
|
|
331
|
+
const contract = await ProsopoContract_1.default.create(config.network.prosopoContract.address, config.network.dappContract.address, getAccount().account.address, new rpc_provider_1.WsProvider(config.network.endpoint));
|
|
332
|
+
return contract;
|
|
333
|
+
};
|
|
334
|
+
return {
|
|
335
|
+
start,
|
|
336
|
+
cancel,
|
|
337
|
+
submit,
|
|
338
|
+
select,
|
|
339
|
+
nextRound,
|
|
340
|
+
};
|
|
341
|
+
};
|
|
342
|
+
exports.Manager = Manager;
|
|
343
|
+
const trimProviderUrl = (url) => {
|
|
344
|
+
return (0, util_1.hexToString)(url).replace(/\0/g, '');
|
|
345
|
+
};
|
|
346
|
+
//# sourceMappingURL=Manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.js","sourceRoot":"","sources":["../../src/modules/Manager.ts"],"names":[],"mappings":";;;;AAAA,qFAAoD;AACpD,yDAAmD;AACnD,gEAA+B;AAC/B,sCAA6F;AAC7F,yCAA4C;AAC5C,oFAAmD;AAWnD,0CAAsC;AACtC,iFAAgD;AAChD,iFAAgD;AAEhD,uDAAmD;AAE5C,MAAM,YAAY,GAAG,GAA6B,EAAE;IACvD,OAAO;QACH,mIAAmI;QACnI,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,SAAS;QACpB,SAAS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M,CAAC,OAAO,CAAC,QAAQ,CAAC,CAC1C,CAAA;QAED,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAA;IAED,OAAO;QACH,KAAK;QACL,MAAM;QACN,MAAM;QACN,MAAM;QACN,SAAS;KACZ,CAAA;AACL,CAAC,CAAA;AAzWY,QAAA,OAAO,WAyWnB;AAED,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,EAAE;IACpC,OAAO,IAAA,kBAAW,EAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC9C,CAAC,CAAA"}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { CaptchaSolution } from
|
|
2
|
-
import { Signer } from
|
|
3
|
-
import { GetCaptchaResponse, ProsopoRandomProviderResponse } from
|
|
4
|
-
import ProviderApi from
|
|
5
|
-
import ProsopoContract from
|
|
1
|
+
import { CaptchaSolution } from '@prosopo/datasets';
|
|
2
|
+
import { Signer } from '@polkadot/api/types';
|
|
3
|
+
import { GetCaptchaResponse, ProsopoRandomProviderResponse } from '../types/api';
|
|
4
|
+
import { ProviderApi } from '@prosopo/api';
|
|
5
|
+
import ProsopoContract from '../api/ProsopoContract';
|
|
6
6
|
import { TCaptchaSubmitResult } from '../types/client';
|
|
7
|
-
export declare type SubmitFunction = typeof ProsopoCaptchaApi.prototype.submitCaptchaSolutionWeb3 | typeof ProsopoCaptchaApi.prototype.submitCaptchaSolutionWeb2;
|
|
8
7
|
export declare class ProsopoCaptchaApi {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
userAccount: string;
|
|
9
|
+
contract: ProsopoContract;
|
|
10
|
+
provider: ProsopoRandomProviderResponse;
|
|
11
|
+
providerApi: ProviderApi;
|
|
12
|
+
private web2;
|
|
13
|
+
constructor(userAccount: string, contract: ProsopoContract, provider: ProsopoRandomProviderResponse, providerApi: ProviderApi, web2: boolean);
|
|
14
14
|
getCaptchaChallenge(): Promise<GetCaptchaResponse>;
|
|
15
15
|
verifyCaptchaChallengeContent(provider: ProsopoRandomProviderResponse, captchaChallenge: GetCaptchaResponse): void;
|
|
16
|
-
submitCaptchaSolution(signer: Signer, requestHash: string, datasetId: string, solutions: CaptchaSolution[]): Promise<TCaptchaSubmitResult>;
|
|
17
|
-
submitCaptchaSolutionWeb2(signer: Signer, requestHash: string, datasetId: string, solutions: CaptchaSolution[]): Promise<TCaptchaSubmitResult>;
|
|
18
|
-
submitCaptchaSolutionWeb3(signer: Signer, requestHash: string, datasetId: string, solutions: CaptchaSolution[]): Promise<TCaptchaSubmitResult>;
|
|
16
|
+
submitCaptchaSolution(signer: Signer, requestHash: string, datasetId: string, solutions: CaptchaSolution[], salt: string): Promise<TCaptchaSubmitResult>;
|
|
19
17
|
}
|
|
20
18
|
export default ProsopoCaptchaApi;
|
|
21
19
|
//# sourceMappingURL=ProsopoCaptchaApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProsopoCaptchaApi.d.ts","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProsopoCaptchaApi.d.ts","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":"AAeA,OAAO,EAAqB,eAAe,EAA0C,MAAM,mBAAmB,CAAA;AAC9G,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAA2B,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAA;AAGzG,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,eAAe,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAKtD,qBAAa,iBAAiB;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,eAAe,CAAA;IACzB,QAAQ,EAAE,6BAA6B,CAAA;IACvC,WAAW,EAAE,WAAW,CAAA;IACxB,OAAO,CAAC,IAAI,CAAS;gBAGjB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,6BAA6B,EACvC,WAAW,EAAE,WAAW,EACxB,IAAI,EAAE,OAAO;IASJ,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IASxD,6BAA6B,CAChC,QAAQ,EAAE,6BAA6B,EACvC,gBAAgB,EAAE,kBAAkB,GACrC,IAAI;IAuBM,qBAAqB,CAC9B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,eAAe,EAAE,EAC5B,IAAI,EAAE,MAAM,GACb,OAAO,CAAC,oBAAoB,CAAC;CAuDnC;AAED,eAAe,iBAAiB,CAAA"}
|
|
@@ -16,31 +16,26 @@ exports.ProsopoCaptchaApi = void 0;
|
|
|
16
16
|
//
|
|
17
17
|
// You should have received a copy of the GNU General Public License
|
|
18
18
|
// along with procaptcha. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
20
19
|
const datasets_1 = require("@prosopo/datasets");
|
|
21
20
|
const handlers_1 = require("../api/handlers");
|
|
22
|
-
const contract_1 = require("@prosopo/contract");
|
|
23
21
|
const datasets_2 = require("@prosopo/datasets");
|
|
22
|
+
const datasets_3 = require("@prosopo/datasets");
|
|
24
23
|
class ProsopoCaptchaApi {
|
|
24
|
+
userAccount;
|
|
25
25
|
contract;
|
|
26
26
|
provider;
|
|
27
27
|
providerApi;
|
|
28
|
-
|
|
29
|
-
constructor(contract, provider, providerApi, web2) {
|
|
28
|
+
web2;
|
|
29
|
+
constructor(userAccount, contract, provider, providerApi, web2) {
|
|
30
|
+
this.userAccount = userAccount;
|
|
30
31
|
this.contract = contract;
|
|
31
32
|
this.provider = provider;
|
|
32
33
|
this.providerApi = providerApi;
|
|
33
|
-
this.
|
|
34
|
+
this.web2 = web2;
|
|
34
35
|
}
|
|
35
36
|
async getCaptchaChallenge() {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
captchaChallenge = await this.providerApi.getCaptchaChallenge(this.provider);
|
|
39
|
-
this.verifyCaptchaChallengeContent(this.provider, captchaChallenge);
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
throw new contract_1.ProsopoEnvError(err);
|
|
43
|
-
}
|
|
37
|
+
const captchaChallenge = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
|
|
38
|
+
this.verifyCaptchaChallengeContent(this.provider, captchaChallenge);
|
|
44
39
|
return captchaChallenge;
|
|
45
40
|
}
|
|
46
41
|
verifyCaptchaChallengeContent(provider, captchaChallenge) {
|
|
@@ -49,70 +44,55 @@ class ProsopoCaptchaApi {
|
|
|
49
44
|
console.log(provider.provider);
|
|
50
45
|
console.log(provider.provider.datasetIdContent, captchaChallenge.captchas[0].proof[proofLength - 1][0]);
|
|
51
46
|
if (provider.provider.datasetIdContent !== captchaChallenge.captchas[0].proof[proofLength - 1][0]) {
|
|
52
|
-
throw new
|
|
47
|
+
throw new datasets_2.ProsopoEnvError('CAPTCHA.INVALID_DATASET_CONTENT_ID');
|
|
53
48
|
}
|
|
54
49
|
for (const captchaWithProof of captchaChallenge.captchas) {
|
|
50
|
+
//TODO calculate the captchaId from the captcha content
|
|
51
|
+
// if (!verifyCaptchaData(captchaWithProof.captcha, captchaWithProof.proof)) {
|
|
52
|
+
// throw new ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE')
|
|
53
|
+
// }
|
|
55
54
|
if (!(0, datasets_1.verifyProof)(captchaWithProof.captcha.captchaContentId, captchaWithProof.proof)) {
|
|
56
|
-
throw new
|
|
55
|
+
throw new datasets_2.ProsopoEnvError('CAPTCHA.INVALID_CAPTCHA_CHALLENGE');
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
console.log(
|
|
58
|
+
console.log('CAPTCHA.CHALLENGE_VERIFIED');
|
|
60
59
|
return;
|
|
61
60
|
}
|
|
62
|
-
async submitCaptchaSolution(signer, requestHash, datasetId, solutions) {
|
|
63
|
-
return this.submitCaptchaFn(signer, requestHash, datasetId, solutions);
|
|
64
|
-
}
|
|
65
|
-
async submitCaptchaSolutionWeb2(signer, requestHash, datasetId, solutions) {
|
|
66
|
-
const salt = (0, util_crypto_1.randomAsHex)();
|
|
67
|
-
const captchaSolutionsSalted = solutions.map((captcha) => ({
|
|
68
|
-
...captcha,
|
|
69
|
-
salt,
|
|
70
|
-
}));
|
|
71
|
-
let result;
|
|
72
|
-
try {
|
|
73
|
-
result = await this.providerApi.submitCaptchaSolution(captchaSolutionsSalted, requestHash, this.contract.getAccount().address, salt, undefined, undefined, true);
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
throw new handlers_1.ProsopoApiError(err);
|
|
77
|
-
}
|
|
78
|
-
return [result, undefined, undefined];
|
|
79
|
-
}
|
|
80
|
-
async submitCaptchaSolutionWeb3(signer, requestHash, datasetId, solutions) {
|
|
81
|
-
const salt = (0, util_crypto_1.randomAsHex)();
|
|
61
|
+
async submitCaptchaSolution(signer, requestHash, datasetId, solutions, salt) {
|
|
82
62
|
const tree = new datasets_1.CaptchaMerkleTree();
|
|
83
|
-
const
|
|
84
|
-
...captcha,
|
|
85
|
-
salt,
|
|
86
|
-
}));
|
|
87
|
-
const captchasHashed = captchaSolutionsSalted.map((captcha) => (0, datasets_2.computeCaptchaSolutionHash)(captcha));
|
|
63
|
+
const captchasHashed = solutions.map((captcha) => (0, datasets_3.computeCaptchaSolutionHash)(captcha));
|
|
88
64
|
tree.build(captchasHashed);
|
|
89
65
|
const commitmentId = tree.root.hash;
|
|
90
|
-
console.log(
|
|
66
|
+
console.log('solveCaptchaChallenge commitmentId', commitmentId);
|
|
91
67
|
// console.log("solveCaptchaChallenge USER ACCOUNT", this.contract.getAccount().address);
|
|
92
68
|
// console.log("solveCaptchaChallenge DAPP ACCOUNT", this.contract.getDappAddress());
|
|
93
69
|
// console.log("solveCaptchaChallenge CONTRACT ADDRESS", this.contract.getContract().address.toString());
|
|
94
|
-
let tx;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
70
|
+
let tx = undefined;
|
|
71
|
+
if (!this.web2) {
|
|
72
|
+
try {
|
|
73
|
+
tx = await this.contract.dappUserCommit(signer, datasetId, commitmentId, this.provider.providerId);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
throw new datasets_2.ProsopoEnvError(err);
|
|
77
|
+
}
|
|
100
78
|
}
|
|
101
79
|
let result;
|
|
102
80
|
try {
|
|
103
|
-
result = await this.providerApi.submitCaptchaSolution(
|
|
81
|
+
result = await this.providerApi.submitCaptchaSolution(solutions, requestHash, this.contract.userAccountAddress, salt, tx ? tx?.blockHash : undefined, tx ? tx?.txHash.toString() : undefined, this.web2);
|
|
104
82
|
}
|
|
105
83
|
catch (err) {
|
|
106
84
|
throw new handlers_1.ProsopoApiError(err);
|
|
107
85
|
}
|
|
108
|
-
let commitment;
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
86
|
+
let commitment = undefined;
|
|
87
|
+
if (!this.web2) {
|
|
88
|
+
try {
|
|
89
|
+
commitment = await this.contract.getCaptchaSolutionCommitment(commitmentId);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw new datasets_2.ProsopoEnvError(err);
|
|
93
|
+
}
|
|
114
94
|
}
|
|
115
|
-
return [result, tx, commitment];
|
|
95
|
+
return [result, commitmentId, tx, commitment];
|
|
116
96
|
}
|
|
117
97
|
}
|
|
118
98
|
exports.ProsopoCaptchaApi = ProsopoCaptchaApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProsopoCaptchaApi.js","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaApi.ts"],"names":[],"mappings":";;;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aAC9E;YAAC,OAAO,GAAG,EAAE;gBACV,MAAM,IAAI,0BAAe,CAAC,GAAG,CAAC,CAAA;aACjC;SACJ;QAED,OAAO,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,CAAC,CAAA;IACjD,CAAC;CACJ;AArHD,8CAqHC;AAED,kBAAe,iBAAiB,CAAA"}
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
import { ICaptchaStateReducer, TCaptchaSubmitResult } from "../types/client";
|
|
2
|
-
import { GetCaptchaResponse } from "../types/api";
|
|
3
|
-
import { ProsopoCaptchaClient } from "./ProsopoCaptchaClient";
|
|
4
|
-
import { CaptchaSolution } from '@prosopo/datasets';
|
|
5
|
-
export declare class ProsopoCaptchaStateClient {
|
|
6
|
-
context: ProsopoCaptchaClient;
|
|
7
|
-
manager: ICaptchaStateReducer;
|
|
8
|
-
constructor(context: ProsopoCaptchaClient, manager: ICaptchaStateReducer);
|
|
9
|
-
onLoadCaptcha(): Promise<void>;
|
|
10
|
-
onCancel(): void;
|
|
11
|
-
onSubmit(): Promise<void>;
|
|
12
|
-
onSolved(submitResult: TCaptchaSubmitResult): Promise<void>;
|
|
13
|
-
onChange(hash: string): void;
|
|
14
|
-
dismissCaptcha(): void;
|
|
15
|
-
parseSolution(captchaChallenge: GetCaptchaResponse, captchaSolution: string[][]): CaptchaSolution[];
|
|
16
|
-
}
|
|
17
|
-
export default ProsopoCaptchaStateClient;
|
|
18
1
|
//# sourceMappingURL=ProsopoCaptchaStateClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProsopoCaptchaStateClient.d.ts","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaStateClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ProsopoCaptchaStateClient.d.ts","sourceRoot":"","sources":["../../src/modules/ProsopoCaptchaStateClient.ts"],"names":[],"mappings":""}
|