@prosopo/provider 0.1.15 → 0.1.17
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/coverage/tmp/coverage-14066-1690288461446-0.json +1 -0
- package/dist/api/admin.d.ts +2 -0
- package/dist/api/admin.d.ts.map +1 -0
- package/dist/api/admin.js +58 -0
- package/dist/api/admin.js.map +1 -0
- package/dist/{api.d.ts → api/captcha.d.ts} +1 -1
- package/dist/api/captcha.d.ts.map +1 -0
- package/dist/{api.js → api/captcha.js} +53 -34
- package/dist/api/captcha.js.map +1 -0
- package/dist/batch/commitments.d.ts +5 -6
- package/dist/batch/commitments.d.ts.map +1 -1
- package/dist/batch/commitments.js +57 -58
- package/dist/batch/commitments.js.map +1 -1
- package/dist/batch/index.d.ts +1 -1
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js +14 -4
- package/dist/batch/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -8
- package/dist/index.js.map +1 -1
- package/dist/scheduler.d.ts +2 -1
- package/dist/scheduler.d.ts.map +1 -1
- package/dist/scheduler.js +26 -12
- package/dist/scheduler.js.map +1 -1
- package/dist/tasks/calculateSolutions.d.ts +10 -0
- package/dist/tasks/calculateSolutions.d.ts.map +1 -0
- package/dist/tasks/calculateSolutions.js +90 -0
- package/dist/tasks/calculateSolutions.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -1
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/index.js +3 -5
- package/dist/tasks/index.js.map +1 -1
- package/dist/tasks/tasks.d.ts +8 -8
- package/dist/tasks/tasks.d.ts.map +1 -1
- package/dist/tasks/tasks.js +81 -116
- package/dist/tasks/tasks.js.map +1 -1
- package/dist/util.d.ts +9 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +47 -29
- package/dist/util.js.map +1 -1
- package/package.json +68 -69
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/api/admin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// import { Keyring } from '@polkadot/keyring'
|
|
2
|
+
// import { ProviderEnvironment } from '@prosopo/types-env'
|
|
3
|
+
// import express, { Router } from 'express'
|
|
4
|
+
// import jwt from 'jsonwebtoken'
|
|
5
|
+
export {};
|
|
6
|
+
// /**
|
|
7
|
+
// * Admin router with auth, temp example
|
|
8
|
+
// *
|
|
9
|
+
// * @return {Router} - router stuff
|
|
10
|
+
// * @param {Environment} env - env stuff
|
|
11
|
+
// */
|
|
12
|
+
// export function adminRouter(env: ProviderEnvironment): Router {
|
|
13
|
+
// const keyring = new Keyring({ type: 'sr25519' })
|
|
14
|
+
// const router = express.Router()
|
|
15
|
+
// // Middleware to verify auth token
|
|
16
|
+
// const authMiddleware = (req, res, next) => {
|
|
17
|
+
// const authHeader = req.headers.authorization
|
|
18
|
+
// if (authHeader) {
|
|
19
|
+
// const token = authHeader.split(' ')[1]
|
|
20
|
+
// // Verify token using the public key
|
|
21
|
+
// jwt.verify(token, env.config.account.address, (err, user) => {
|
|
22
|
+
// if (err) {
|
|
23
|
+
// return res.sendStatus(403)
|
|
24
|
+
// }
|
|
25
|
+
// req.user = user
|
|
26
|
+
// next()
|
|
27
|
+
// })
|
|
28
|
+
// } else {
|
|
29
|
+
// res.sendStatus(401)
|
|
30
|
+
// }
|
|
31
|
+
// }
|
|
32
|
+
// // Endpoint to authenticate user using Polkadot network for signing messages
|
|
33
|
+
// router.post('/auth', async (req, res) => {
|
|
34
|
+
// const { message, signature } = req.body
|
|
35
|
+
// try {
|
|
36
|
+
// const address = env.config.account.address
|
|
37
|
+
// const pair = keyring.addFromAddress(env.config.account.address)
|
|
38
|
+
// const isValid = pair.verify(message, signature, address)
|
|
39
|
+
// if (isValid) {
|
|
40
|
+
// const user = { address }
|
|
41
|
+
// // temp jwt, need to verify usage with correct imports and types
|
|
42
|
+
// const accessToken = jwt.sign(user, env.config.account.secret, { expiresIn: '1h' })
|
|
43
|
+
// return res.json({ accessToken })
|
|
44
|
+
// } else {
|
|
45
|
+
// return res.status(401).json({ message: 'bad auth' })
|
|
46
|
+
// }
|
|
47
|
+
// } catch (err) {
|
|
48
|
+
// // todo needs proper prosopo error handling
|
|
49
|
+
// return res.status(500).json({ message: 'An error occurred' })
|
|
50
|
+
// }
|
|
51
|
+
// })
|
|
52
|
+
// // Secure endpoint which requires auth token to access
|
|
53
|
+
// router.get('/secure', authMiddleware, (req, res) => {
|
|
54
|
+
// res.json({ message: 'correct auth' })
|
|
55
|
+
// })
|
|
56
|
+
// return router
|
|
57
|
+
// }
|
|
58
|
+
//# sourceMappingURL=admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/api/admin.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,2DAA2D;AAC3D,4CAA4C;AAC5C,iCAAiC;;AAEjC,MAAM;AACN,0CAA0C;AAC1C,KAAK;AACL,qCAAqC;AACrC,0CAA0C;AAC1C,MAAM;AACN,kEAAkE;AAClE,uDAAuD;AAEvD,sCAAsC;AAEtC,yCAAyC;AACzC,mDAAmD;AACnD,uDAAuD;AAEvD,4BAA4B;AAC5B,qDAAqD;AAErD,mDAAmD;AACnD,6EAA6E;AAC7E,6BAA6B;AAC7B,iDAAiD;AACjD,oBAAoB;AAEpB,kCAAkC;AAClC,yBAAyB;AACzB,iBAAiB;AACjB,mBAAmB;AACnB,kCAAkC;AAClC,YAAY;AACZ,QAAQ;AAER,mFAAmF;AACnF,iDAAiD;AACjD,kDAAkD;AAElD,gBAAgB;AAChB,yDAAyD;AACzD,8EAA8E;AAC9E,uEAAuE;AAEvE,6BAA6B;AAC7B,2CAA2C;AAE3C,mFAAmF;AACnF,qGAAqG;AAErG,mDAAmD;AACnD,uBAAuB;AACvB,uEAAuE;AACvE,gBAAgB;AAChB,0BAA0B;AAC1B,0DAA0D;AAC1D,4EAA4E;AAC5E,YAAY;AACZ,SAAS;AAET,6DAA6D;AAC7D,4DAA4D;AAC5D,gDAAgD;AAChD,SAAS;AAET,oBAAoB;AACpB,IAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/api/captcha.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAMxD,OAAgB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAEzC;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,mBAAmB,GAAG,MAAM,CAyI9D"}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prosopoRouter = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
// Copyright 2021-2022 Prosopo (UK) Ltd.
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
6
2
|
//
|
|
7
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -15,23 +11,23 @@ const tslib_1 = require("tslib");
|
|
|
15
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
12
|
// See the License for the specific language governing permissions and
|
|
17
13
|
// limitations under the License.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
import { ApiParams, ApiPaths, CaptchaSolutionBody, CaptchaStatus, VerifySolutionBody, } from '@prosopo/types';
|
|
15
|
+
import { CaptchaRequestBody } from '@prosopo/types';
|
|
16
|
+
import { ProsopoApiError } from '@prosopo/common';
|
|
17
|
+
import { Tasks } from '../tasks/tasks.js';
|
|
18
|
+
import { parseBlockNumber } from '../util.js';
|
|
19
|
+
import { parseCaptchaAssets } from '@prosopo/datasets';
|
|
20
|
+
import { validateAddress } from '@polkadot/util-crypto';
|
|
21
|
+
import express from 'express';
|
|
26
22
|
/**
|
|
27
23
|
* Returns a router connected to the database which can interact with the Proposo protocol
|
|
28
24
|
*
|
|
29
25
|
* @return {Router} - A middleware router that can interact with the Prosopo protocol
|
|
30
26
|
* @param {Environment} env - The Prosopo environment
|
|
31
27
|
*/
|
|
32
|
-
function prosopoRouter(env) {
|
|
33
|
-
const router =
|
|
34
|
-
const tasks = new
|
|
28
|
+
export function prosopoRouter(env) {
|
|
29
|
+
const router = express.Router();
|
|
30
|
+
const tasks = new Tasks(env);
|
|
35
31
|
/**
|
|
36
32
|
* Provides a Captcha puzzle to a Dapp User
|
|
37
33
|
* @param {string} datasetId - Provider datasetId
|
|
@@ -39,24 +35,24 @@ function prosopoRouter(env) {
|
|
|
39
35
|
* @param {string} blockNumber - Block number
|
|
40
36
|
* @return {Captcha} - The Captcha data
|
|
41
37
|
*/
|
|
42
|
-
router.get(`${
|
|
38
|
+
router.get(`${ApiPaths.GetCaptchaChallenge}/:${ApiParams.datasetId}/:${ApiParams.user}/:${ApiParams.dapp}/:${ApiParams.blockNumber}`, async (req, res, next) => {
|
|
43
39
|
try {
|
|
44
|
-
const { blockNumber, datasetId, user, dapp } =
|
|
45
|
-
|
|
46
|
-
const blockNumberParsed =
|
|
40
|
+
const { blockNumber, datasetId, user, dapp } = CaptchaRequestBody.parse(req.params);
|
|
41
|
+
validateAddress(user, false, env.api.registry.chainSS58);
|
|
42
|
+
const blockNumberParsed = parseBlockNumber(blockNumber);
|
|
47
43
|
await tasks.validateProviderWasRandomlyChosen(user, dapp, datasetId, blockNumberParsed);
|
|
48
44
|
const taskData = await tasks.getRandomCaptchasAndRequestHash(datasetId, user);
|
|
49
45
|
taskData.captchas = taskData.captchas.map((cwp) => ({
|
|
50
46
|
...cwp,
|
|
51
47
|
captcha: {
|
|
52
48
|
...cwp.captcha,
|
|
53
|
-
items: cwp.captcha.items.map((item) =>
|
|
49
|
+
items: cwp.captcha.items.map((item) => parseCaptchaAssets(item, env.assetsResolver)),
|
|
54
50
|
},
|
|
55
51
|
}));
|
|
56
52
|
return res.json(taskData);
|
|
57
53
|
}
|
|
58
54
|
catch (err) {
|
|
59
|
-
return next(new
|
|
55
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
60
56
|
}
|
|
61
57
|
});
|
|
62
58
|
/**
|
|
@@ -67,23 +63,23 @@ function prosopoRouter(env) {
|
|
|
67
63
|
* @param {Captcha[]} captchas - The Captcha solutions
|
|
68
64
|
* @return {DappUserSolutionResult} - The Captcha solution result and proof
|
|
69
65
|
*/
|
|
70
|
-
router.post(
|
|
66
|
+
router.post(ApiPaths.SubmitCaptchaSolution, async (req, res, next) => {
|
|
71
67
|
let parsed;
|
|
72
68
|
try {
|
|
73
|
-
parsed =
|
|
69
|
+
parsed = CaptchaSolutionBody.parse(req.body);
|
|
74
70
|
}
|
|
75
71
|
catch (err) {
|
|
76
|
-
return next(new
|
|
72
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
77
73
|
}
|
|
78
74
|
try {
|
|
79
|
-
const result = await tasks.dappUserSolution(parsed[
|
|
75
|
+
const result = await tasks.dappUserSolution(parsed[ApiParams.user], parsed[ApiParams.dapp], parsed[ApiParams.requestHash], parsed[ApiParams.captchas], parsed[ApiParams.signature]);
|
|
80
76
|
return res.json({
|
|
81
77
|
status: req.i18n.t(result.solutionApproved ? 'API.CAPTCHA_PASSED' : 'API.CAPTCHA_FAILED'),
|
|
82
78
|
...result,
|
|
83
79
|
});
|
|
84
80
|
}
|
|
85
81
|
catch (err) {
|
|
86
|
-
return next(new
|
|
82
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
87
83
|
}
|
|
88
84
|
});
|
|
89
85
|
/**
|
|
@@ -92,13 +88,13 @@ function prosopoRouter(env) {
|
|
|
92
88
|
* @param {string} userAccount - Dapp User id
|
|
93
89
|
* @param {string} commitmentId - The captcha solution to look up
|
|
94
90
|
*/
|
|
95
|
-
router.post(
|
|
91
|
+
router.post(ApiPaths.VerifyCaptchaSolution, async (req, res, next) => {
|
|
96
92
|
let parsed;
|
|
97
93
|
try {
|
|
98
|
-
parsed =
|
|
94
|
+
parsed = VerifySolutionBody.parse(req.body);
|
|
99
95
|
}
|
|
100
96
|
catch (err) {
|
|
101
|
-
return next(new
|
|
97
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
102
98
|
}
|
|
103
99
|
try {
|
|
104
100
|
let solution;
|
|
@@ -111,7 +107,7 @@ function prosopoRouter(env) {
|
|
|
111
107
|
}
|
|
112
108
|
if (solution) {
|
|
113
109
|
let approved = false;
|
|
114
|
-
if (solution.status ===
|
|
110
|
+
if (solution.status === CaptchaStatus.approved) {
|
|
115
111
|
statusMessage = 'API.USER_VERIFIED';
|
|
116
112
|
approved = true;
|
|
117
113
|
}
|
|
@@ -127,10 +123,33 @@ function prosopoRouter(env) {
|
|
|
127
123
|
});
|
|
128
124
|
}
|
|
129
125
|
catch (err) {
|
|
130
|
-
return next(new
|
|
126
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
/**
|
|
130
|
+
* Verifies that the provider is running and registered in the contract
|
|
131
|
+
*/
|
|
132
|
+
router.get(ApiPaths.GetProviderStatus, async (req, res, next) => {
|
|
133
|
+
try {
|
|
134
|
+
const status = await tasks.providerStatus();
|
|
135
|
+
return res.json({ status });
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Gets public details of the provider
|
|
143
|
+
*/
|
|
144
|
+
router.get(ApiPaths.GetProviderDetails, async (req, res, next) => {
|
|
145
|
+
try {
|
|
146
|
+
const details = await tasks.getProviderDetails();
|
|
147
|
+
return res.json(details);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
return next(new ProsopoApiError(err, undefined, 400));
|
|
131
151
|
}
|
|
132
152
|
});
|
|
133
153
|
return router;
|
|
134
154
|
}
|
|
135
|
-
|
|
136
|
-
//# sourceMappingURL=api.js.map
|
|
155
|
+
//# sourceMappingURL=captcha.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.js","sourceRoot":"","sources":["../../src/api/captcha.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,OAAO,EACH,SAAS,EACT,QAAQ,EACR,mBAAmB,EACnB,aAAa,EAGb,kBAAkB,GACrB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,OAAmB,MAAM,SAAS,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAwB;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAA;IAC/B,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;IAE5B;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,CACN,GAAG,QAAQ,CAAC,mBAAmB,KAA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AAM,MAAM,GAAG,MAAM,KAAK,CAAC,cAAc,EAAE,CAAA;YAC3C,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;SAC9B;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAA;SACxD;IACL,CAAC,CAAC,CAAA;IAEF;;OAEG;IACH,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAC7D,IAAI;YACA,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,kBAAkB,EAAE,CAAA;YAChD,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;SAC3B;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,IAAI,CAAC,IAAI,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,CAAA;SACxD;IACL,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACjB,CAAC"}
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import { ArgumentTypes, Commit } from '@prosopo/types';
|
|
2
|
+
import { ArgumentTypes, BatchCommitConfig, Commit, ExtrinsicBatch } from '@prosopo/types';
|
|
3
3
|
import { BN } from '@polkadot/util';
|
|
4
|
-
import { BatchCommitConfig, ExtrinsicBatch } from '@prosopo/types';
|
|
5
4
|
import { Database, UserCommitmentRecord } from '@prosopo/types-database';
|
|
6
5
|
import { Logger } from '@prosopo/common';
|
|
7
6
|
import { ProsopoCaptchaContract } from '@prosopo/contract';
|
|
8
7
|
import { WeightV2 } from '@polkadot/types/interfaces';
|
|
9
|
-
export declare class
|
|
8
|
+
export declare class BatchCommitmentsTask {
|
|
10
9
|
contract: ProsopoCaptchaContract;
|
|
11
10
|
db: Database;
|
|
12
11
|
batchCommitConfig: BatchCommitConfig;
|
|
13
12
|
logger: Logger;
|
|
14
13
|
private nonce;
|
|
15
|
-
constructor(batchCommitConfig: BatchCommitConfig, contractApi: ProsopoCaptchaContract, db: Database,
|
|
16
|
-
|
|
14
|
+
constructor(batchCommitConfig: BatchCommitConfig, contractApi: ProsopoCaptchaContract, db: Database, startNonce: bigint, logger: Logger);
|
|
15
|
+
run(): Promise<void>;
|
|
17
16
|
createExtrinsics(commitments: UserCommitmentRecord[]): Promise<ExtrinsicBatch>;
|
|
18
17
|
extrinsicTooHigh(totalRefTime: BN, totalProofSize: BN, maxBlockWeight: WeightV2): boolean;
|
|
19
18
|
batchIntervalExceeded(): Promise<boolean>;
|
|
20
19
|
getCommitments(): Promise<UserCommitmentRecord[]>;
|
|
21
|
-
|
|
20
|
+
flagBatchedCommitments(commitmentIds: ArgumentTypes.Hash[]): Promise<void>;
|
|
22
21
|
convertCommit(commitment: UserCommitmentRecord): Commit;
|
|
23
22
|
}
|
|
24
23
|
//# sourceMappingURL=commitments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commitments.d.ts","sourceRoot":"","sources":["../../src/batch/commitments.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"commitments.d.ts","sourceRoot":"","sources":["../../src/batch/commitments.ts"],"names":[],"mappings":";AAcA,OAAO,EACH,aAAa,EACb,iBAAiB,EACjB,MAAM,EACN,cAAc,EAGjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,sBAAsB,EAA0D,MAAM,mBAAmB,CAAA;AAElH,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAOrD,qBAAa,oBAAoB;IAC7B,QAAQ,EAAE,sBAAsB,CAAA;IAChC,EAAE,EAAE,QAAQ,CAAA;IACZ,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,KAAK,CAAQ;gBAEjB,iBAAiB,EAAE,iBAAiB,EACpC,WAAW,EAAE,sBAAsB,EACnC,EAAE,EAAE,QAAQ,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM;IAQZ,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAsDpB,gBAAgB,CAAC,WAAW,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAkFpF,gBAAgB,CAAC,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,cAAc,EAAE,QAAQ,GAAG,OAAO;IAOnF,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC;IAMzC,cAAc,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAKjD,sBAAsB,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhF,aAAa,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM;CAY1D"}
|
|
@@ -1,74 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
8
|
-
const BN_TEN_THOUSAND = new util_1.BN(10_000);
|
|
1
|
+
import { ScheduledTaskNames, ScheduledTaskStatus, } from '@prosopo/types';
|
|
2
|
+
import { BN } from '@polkadot/util';
|
|
3
|
+
import { ProsopoContractError, batch, encodeStringArgs, oneUnit } from '@prosopo/contract';
|
|
4
|
+
import { checkIfTaskIsRunning } from '../util.js';
|
|
5
|
+
import { randomAsHex } from '@polkadot/util-crypto';
|
|
6
|
+
const BN_TEN_THOUSAND = new BN(10_000);
|
|
9
7
|
const CONTRACT_METHOD_NAME = 'providerCommitMany';
|
|
10
|
-
class
|
|
8
|
+
export class BatchCommitmentsTask {
|
|
11
9
|
contract;
|
|
12
10
|
db;
|
|
13
11
|
batchCommitConfig;
|
|
14
12
|
logger;
|
|
15
13
|
nonce;
|
|
16
|
-
constructor(batchCommitConfig, contractApi, db,
|
|
14
|
+
constructor(batchCommitConfig, contractApi, db, startNonce, logger) {
|
|
17
15
|
this.contract = contractApi;
|
|
18
16
|
this.db = db;
|
|
19
17
|
this.batchCommitConfig = batchCommitConfig;
|
|
20
18
|
this.logger = logger;
|
|
21
19
|
this.nonce = startNonce;
|
|
22
20
|
}
|
|
23
|
-
async
|
|
21
|
+
async run() {
|
|
24
22
|
// create a task id
|
|
25
|
-
const taskId =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
//
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
const taskId = randomAsHex(32);
|
|
24
|
+
const taskRunning = await checkIfTaskIsRunning(ScheduledTaskNames.BatchCommitment, this.db);
|
|
25
|
+
// taskRunning and intervalExceeded checks separated over multiple lines to avoid race conditions between providers
|
|
26
|
+
if (!taskRunning) {
|
|
27
|
+
const intervalExceeded = await this.batchIntervalExceeded();
|
|
28
|
+
if (intervalExceeded) {
|
|
29
|
+
try {
|
|
30
|
+
// update last commit time
|
|
31
|
+
await this.db.storeScheduledTaskStatus(taskId, ScheduledTaskNames.BatchCommitment, ScheduledTaskStatus.Running);
|
|
32
|
+
//get commitments
|
|
33
|
+
const commitments = await this.getCommitments();
|
|
34
|
+
if (commitments.length > 0) {
|
|
35
|
+
this.logger.info(`Found ${commitments.length} commitments to commit`);
|
|
36
|
+
// get the extrinsics that are to be batched and an id associated with each one
|
|
37
|
+
const { extrinsics, ids: commitmentIds } = await this.createExtrinsics(commitments);
|
|
38
|
+
// commit and get the Ids of the commitments that were committed on-chain
|
|
39
|
+
await batch(this.contract.contract, this.contract.pair, extrinsics, this.logger);
|
|
40
|
+
// flag commitments as batched
|
|
41
|
+
await this.flagBatchedCommitments(commitmentIds);
|
|
42
|
+
// update last commit time and store the commitmentIds that were batched
|
|
43
|
+
await this.db.storeScheduledTaskStatus(taskId, ScheduledTaskNames.BatchCommitment, ScheduledTaskStatus.Completed, {
|
|
44
|
+
data: {
|
|
45
|
+
commitmentIds: commitments
|
|
46
|
+
.filter((commitment) => commitmentIds.indexOf(commitment.id) > -1)
|
|
47
|
+
.map((c) => c.id),
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
this.logger.error(e);
|
|
54
|
+
await this.db.storeScheduledTaskStatus(taskId, ScheduledTaskNames.BatchCommitment, ScheduledTaskStatus.Failed, {
|
|
55
|
+
error: JSON.stringify(e && e.message ? e.message : e),
|
|
47
56
|
});
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
this.logger.error(e);
|
|
52
|
-
await this.db.storeScheduledTaskStatus(taskId, types_1.ScheduledTaskNames.BatchCommitment, types_1.ScheduledTaskStatus.Failed, {
|
|
53
|
-
error: JSON.stringify(e && e.message ? e.message : e),
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
async createExtrinsics(commitments) {
|
|
59
62
|
const txs = [];
|
|
60
63
|
const fragment = this.contract.abi.findMessage(CONTRACT_METHOD_NAME);
|
|
61
64
|
const batchedCommitmentIds = [];
|
|
62
|
-
let totalRefTime = new
|
|
63
|
-
let totalProofSize = new
|
|
64
|
-
let totalFee = new
|
|
65
|
+
let totalRefTime = new BN(0);
|
|
66
|
+
let totalProofSize = new BN(0);
|
|
67
|
+
let totalFee = new BN(0);
|
|
65
68
|
const maxBlockWeight = this.contract.api.consts.system.blockWeights.maxBlock;
|
|
66
69
|
const commitmentArray = [];
|
|
67
70
|
let extrinsic;
|
|
68
71
|
for (const commitment of commitments) {
|
|
69
72
|
const commit = this.convertCommit(commitment);
|
|
70
73
|
commitmentArray.push(commit);
|
|
71
|
-
const encodedArgs =
|
|
74
|
+
const encodedArgs = encodeStringArgs(this.contract.abi, fragment, [commitmentArray]);
|
|
72
75
|
// TODO can we get storage deposit from the provided query method?
|
|
73
76
|
// https://matrix.to/#/!utTuYglskDvqRRMQta:matrix.org/$tELySFxCORlHCHveOknGJBx-MdVe-SxFN8_BsYvcDmI?via=matrix.org&via=t2bot.io&via=cardinal.ems.host
|
|
74
77
|
// const response = await this.contract.query.providerCommitMany(commitmentArray)
|
|
@@ -82,7 +85,7 @@ class BatchCommitments {
|
|
|
82
85
|
}
|
|
83
86
|
catch (e) {
|
|
84
87
|
// TODO https://github.com/polkadot-js/api/issues/5504
|
|
85
|
-
paymentInfo = new
|
|
88
|
+
paymentInfo = new BN(0);
|
|
86
89
|
}
|
|
87
90
|
//totalEncodedLength += extrinsic.encodedLength
|
|
88
91
|
totalRefTime = totalRefTime.add(this.contract.api.registry.createType('WeightV2', options.gasLimit).refTime.toBn());
|
|
@@ -91,9 +94,9 @@ class BatchCommitments {
|
|
|
91
94
|
const extrinsicTooHigh = this.extrinsicTooHigh(totalRefTime, totalProofSize, maxBlockWeight);
|
|
92
95
|
this.logger.debug('Free balance', '`', (await this.contract.api.query.system.account(this.contract.pair.address)).data.free
|
|
93
96
|
.toBn()
|
|
94
|
-
.div(
|
|
97
|
+
.div(oneUnit(this.contract.api))
|
|
95
98
|
.toString(), '`', 'UNIT');
|
|
96
|
-
this.logger.debug('Total Fee `', totalFee.div(
|
|
99
|
+
this.logger.debug('Total Fee `', totalFee.div(oneUnit(this.contract.api)).toString(), '`', 'UNIT');
|
|
97
100
|
const feeTooHigh = totalFee.gt((await this.contract.api.query.system.account(this.contract.pair.address)).data.free.toBn());
|
|
98
101
|
// Check if we have a maximum number of transactions that we can successfully submit in a block or if the
|
|
99
102
|
// total fee is more than the provider has left in their account
|
|
@@ -107,7 +110,7 @@ class BatchCommitments {
|
|
|
107
110
|
}
|
|
108
111
|
}
|
|
109
112
|
if (!extrinsic) {
|
|
110
|
-
throw new
|
|
113
|
+
throw new ProsopoContractError('No extrinsics created');
|
|
111
114
|
}
|
|
112
115
|
txs.push(extrinsic);
|
|
113
116
|
this.logger.info(`${txs.length} transactions will be batched`);
|
|
@@ -125,26 +128,22 @@ class BatchCommitments {
|
|
|
125
128
|
return Date.now() - lastTime.getSeconds() > this.batchCommitConfig.interval;
|
|
126
129
|
}
|
|
127
130
|
async getCommitments() {
|
|
128
|
-
// get commitments that have
|
|
129
|
-
return await this.db.
|
|
131
|
+
// get commitments that have not yet been batched on-chain
|
|
132
|
+
return await this.db.getUnbatchedDappUserCommitments();
|
|
130
133
|
}
|
|
131
|
-
async
|
|
132
|
-
|
|
133
|
-
const removeCommitmentsResult = await this.db.removeProcessedDappUserCommitments(commitmentIds);
|
|
134
|
-
this.logger.info('Deleted user solutions', removeSolutionsResult);
|
|
135
|
-
this.logger.info('Deleted user commitments', removeCommitmentsResult);
|
|
134
|
+
async flagBatchedCommitments(commitmentIds) {
|
|
135
|
+
await this.db.flagBatchedDappUserCommitments(commitmentIds);
|
|
136
136
|
}
|
|
137
137
|
convertCommit(commitment) {
|
|
138
|
-
const { processed, userSignature, requestedAt, completedAt, ...commit } = commitment;
|
|
138
|
+
const { batched, processed, userSignature, requestedAt, completedAt, ...commit } = commitment;
|
|
139
139
|
return {
|
|
140
140
|
...commit,
|
|
141
141
|
userSignaturePart1: userSignature.slice(0, userSignature.length / 2),
|
|
142
142
|
userSignaturePart2: userSignature.slice(userSignature.length / 2),
|
|
143
143
|
// to satisfy typescript
|
|
144
|
-
requestedAt: new
|
|
145
|
-
completedAt: new
|
|
144
|
+
requestedAt: new BN(requestedAt).toNumber(),
|
|
145
|
+
completedAt: new BN(completedAt).toNumber(),
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
exports.BatchCommitments = BatchCommitments;
|
|
150
149
|
//# sourceMappingURL=commitments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commitments.js","sourceRoot":"","sources":["../../src/batch/commitments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commitments.js","sourceRoot":"","sources":["../../src/batch/commitments.ts"],"names":[],"mappings":"AAcA,OAAO,EAKH,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAGnC,OAAO,EAA0B,oBAAoB,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAGlH,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,MAAM,eAAe,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,CAAA;AACtC,MAAM,oBAAoB,GAAG,oBAAoB,CAAA;AAEjD,MAAM,OAAO,oBAAoB;IAC7B,QAAQ,CAAwB;IAChC,EAAE,CAAU;IACZ,iBAAiB,CAAmB;IACpC,MAAM,CAAQ;IACN,KAAK,CAAQ;IACrB,YACI,iBAAoC,EACpC,WAAmC,EACnC,EAAY,EACZ,UAAkB,EAClB,MAAc;QAEd,IAAI,CAAC,QAAQ,GAAG,WAAW,CAAA;QAC3B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAA;QACZ,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,UAAU,CAAA;IAC3B,CAAC;IACD,KAAK,CAAC,GAAG;QACL,mBAAmB;QACn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AA+B,EAAE,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,aAAmC;QAC5D,MAAM,IAAI,CAAC,EAAE,CAAC,8BAA8B,CAAC,aAAa,CAAC,CAAA;IAC/D,CAAC;IAED,aAAa,CAAC,UAAgC;QAC1C,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,MAAM,EAAE,GAAG,UAAU,CAAA;QAE7F,OAAO;YACH,GAAG,MAAM;YACT,kBAAkB,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACpE,kBAAkB,EAAE,aAAa,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACjE,wBAAwB;YACxB,WAAW,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;YAC3C,WAAW,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;SAC9C,CAAA;IACL,CAAC;CACJ"}
|
package/dist/batch/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './commitments';
|
|
1
|
+
export * from './commitments.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/batch/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/batch/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAA"}
|
package/dist/batch/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// Copyright 2021-2023 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 * from './commitments.js';
|
|
5
15
|
//# sourceMappingURL=index.js.map
|
package/dist/batch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/batch/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/batch/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,kBAAkB,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './tasks';
|
|
2
|
-
export * from './util';
|
|
3
|
-
export * from './batch';
|
|
4
|
-
export * from './api';
|
|
1
|
+
export * from './tasks/index.js';
|
|
2
|
+
export * from './util.js';
|
|
3
|
+
export * from './batch/index.js';
|
|
4
|
+
export * from './api/captcha.js';
|
|
5
5
|
//# 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,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
// Copyright 2021-2022 Prosopo (UK) Ltd.
|
|
1
|
+
// Copyright 2021-2023 Prosopo (UK) Ltd.
|
|
5
2
|
//
|
|
6
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -14,8 +11,8 @@ const tslib_1 = require("tslib");
|
|
|
14
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
12
|
// See the License for the specific language governing permissions and
|
|
16
13
|
// limitations under the License.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
export * from './tasks/index.js';
|
|
15
|
+
export * from './util.js';
|
|
16
|
+
export * from './batch/index.js';
|
|
17
|
+
export * from './api/captcha.js';
|
|
21
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,EAAE;AACF,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
|
package/dist/scheduler.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KeyringPair } from '@polkadot/keyring/types';
|
|
2
2
|
import { ProsopoConfig } from '@prosopo/types';
|
|
3
|
-
export
|
|
3
|
+
export declare function calculateSolutionsScheduler(pair: KeyringPair, config: ProsopoConfig): Promise<void>;
|
|
4
|
+
export declare function batchCommitScheduler(pair: KeyringPair, config: ProsopoConfig): Promise<void>;
|
|
4
5
|
//# sourceMappingURL=scheduler.d.ts.map
|
package/dist/scheduler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAI9C,
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAI9C,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,iBAYzF;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,iBAelF"}
|