@prosopo/provider 0.1.17 → 0.1.18

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.
Files changed (42) hide show
  1. package/package.json +11 -11
  2. package/coverage/tmp/coverage-14066-1690288461446-0.json +0 -1
  3. package/dist/api/admin.d.ts +0 -2
  4. package/dist/api/admin.d.ts.map +0 -1
  5. package/dist/api/admin.js +0 -58
  6. package/dist/api/admin.js.map +0 -1
  7. package/dist/api/captcha.d.ts +0 -10
  8. package/dist/api/captcha.d.ts.map +0 -1
  9. package/dist/api/captcha.js +0 -155
  10. package/dist/api/captcha.js.map +0 -1
  11. package/dist/batch/commitments.d.ts +0 -23
  12. package/dist/batch/commitments.d.ts.map +0 -1
  13. package/dist/batch/commitments.js +0 -149
  14. package/dist/batch/commitments.js.map +0 -1
  15. package/dist/batch/index.d.ts +0 -2
  16. package/dist/batch/index.d.ts.map +0 -1
  17. package/dist/batch/index.js +0 -15
  18. package/dist/batch/index.js.map +0 -1
  19. package/dist/index.d.ts +0 -5
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/index.js +0 -18
  22. package/dist/index.js.map +0 -1
  23. package/dist/scheduler.d.ts +0 -5
  24. package/dist/scheduler.d.ts.map +0 -1
  25. package/dist/scheduler.js +0 -48
  26. package/dist/scheduler.js.map +0 -1
  27. package/dist/tasks/calculateSolutions.d.ts +0 -10
  28. package/dist/tasks/calculateSolutions.d.ts.map +0 -1
  29. package/dist/tasks/calculateSolutions.js +0 -90
  30. package/dist/tasks/calculateSolutions.js.map +0 -1
  31. package/dist/tasks/index.d.ts +0 -3
  32. package/dist/tasks/index.d.ts.map +0 -1
  33. package/dist/tasks/index.js +0 -16
  34. package/dist/tasks/index.js.map +0 -1
  35. package/dist/tasks/tasks.d.ts +0 -108
  36. package/dist/tasks/tasks.d.ts.map +0 -1
  37. package/dist/tasks/tasks.js +0 -370
  38. package/dist/tasks/tasks.js.map +0 -1
  39. package/dist/util.d.ts +0 -28
  40. package/dist/util.d.ts.map +0 -1
  41. package/dist/util.js +0 -110
  42. package/dist/util.js.map +0 -1
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=admin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/api/admin.ts"],"names":[],"mappings":""}
package/dist/api/admin.js DELETED
@@ -1,58 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,10 +0,0 @@
1
- import { ProviderEnvironment } from '@prosopo/types-env';
2
- import { Router } from 'express';
3
- /**
4
- * Returns a router connected to the database which can interact with the Proposo protocol
5
- *
6
- * @return {Router} - A middleware router that can interact with the Prosopo protocol
7
- * @param {Environment} env - The Prosopo environment
8
- */
9
- export declare function prosopoRouter(env: ProviderEnvironment): Router;
10
- //# sourceMappingURL=captcha.d.ts.map
@@ -1 +0,0 @@
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,155 +0,0 @@
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
- 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';
22
- /**
23
- * Returns a router connected to the database which can interact with the Proposo protocol
24
- *
25
- * @return {Router} - A middleware router that can interact with the Prosopo protocol
26
- * @param {Environment} env - The Prosopo environment
27
- */
28
- export function prosopoRouter(env) {
29
- const router = express.Router();
30
- const tasks = new Tasks(env);
31
- /**
32
- * Provides a Captcha puzzle to a Dapp User
33
- * @param {string} datasetId - Provider datasetId
34
- * @param {string} userAccount - Dapp User AccountId
35
- * @param {string} blockNumber - Block number
36
- * @return {Captcha} - The Captcha data
37
- */
38
- router.get(`${ApiPaths.GetCaptchaChallenge}/:${ApiParams.datasetId}/:${ApiParams.user}/:${ApiParams.dapp}/:${ApiParams.blockNumber}`, async (req, res, next) => {
39
- try {
40
- const { blockNumber, datasetId, user, dapp } = CaptchaRequestBody.parse(req.params);
41
- validateAddress(user, false, env.api.registry.chainSS58);
42
- const blockNumberParsed = parseBlockNumber(blockNumber);
43
- await tasks.validateProviderWasRandomlyChosen(user, dapp, datasetId, blockNumberParsed);
44
- const taskData = await tasks.getRandomCaptchasAndRequestHash(datasetId, user);
45
- taskData.captchas = taskData.captchas.map((cwp) => ({
46
- ...cwp,
47
- captcha: {
48
- ...cwp.captcha,
49
- items: cwp.captcha.items.map((item) => parseCaptchaAssets(item, env.assetsResolver)),
50
- },
51
- }));
52
- return res.json(taskData);
53
- }
54
- catch (err) {
55
- return next(new ProsopoApiError(err, undefined, 400));
56
- }
57
- });
58
- /**
59
- * Receives solved CAPTCHA challenges, store to database, and check against solution commitment
60
- *
61
- * @param {string} userAccount - Dapp User id
62
- * @param {string} dappAccount - Dapp Contract AccountId
63
- * @param {Captcha[]} captchas - The Captcha solutions
64
- * @return {DappUserSolutionResult} - The Captcha solution result and proof
65
- */
66
- router.post(ApiPaths.SubmitCaptchaSolution, async (req, res, next) => {
67
- let parsed;
68
- try {
69
- parsed = CaptchaSolutionBody.parse(req.body);
70
- }
71
- catch (err) {
72
- return next(new ProsopoApiError(err, undefined, 400));
73
- }
74
- try {
75
- const result = await tasks.dappUserSolution(parsed[ApiParams.user], parsed[ApiParams.dapp], parsed[ApiParams.requestHash], parsed[ApiParams.captchas], parsed[ApiParams.signature]);
76
- return res.json({
77
- status: req.i18n.t(result.solutionApproved ? 'API.CAPTCHA_PASSED' : 'API.CAPTCHA_FAILED'),
78
- ...result,
79
- });
80
- }
81
- catch (err) {
82
- return next(new ProsopoApiError(err, undefined, 400));
83
- }
84
- });
85
- /**
86
- * Verifies a user's solution as being approved or not
87
- *
88
- * @param {string} userAccount - Dapp User id
89
- * @param {string} commitmentId - The captcha solution to look up
90
- */
91
- router.post(ApiPaths.VerifyCaptchaSolution, async (req, res, next) => {
92
- let parsed;
93
- try {
94
- parsed = VerifySolutionBody.parse(req.body);
95
- }
96
- catch (err) {
97
- return next(new ProsopoApiError(err, undefined, 400));
98
- }
99
- try {
100
- let solution;
101
- let statusMessage = 'API.USER_NOT_VERIFIED';
102
- if (!parsed.commitmentId) {
103
- solution = await tasks.getDappUserCommitmentByAccount(parsed.user);
104
- }
105
- else {
106
- solution = await tasks.getDappUserCommitmentById(parsed.commitmentId);
107
- }
108
- if (solution) {
109
- let approved = false;
110
- if (solution.status === CaptchaStatus.approved) {
111
- statusMessage = 'API.USER_VERIFIED';
112
- approved = true;
113
- }
114
- return res.json({
115
- status: req.t(statusMessage),
116
- solutionApproved: approved,
117
- commitmentId: solution.id,
118
- });
119
- }
120
- return res.json({
121
- status: req.t(statusMessage),
122
- solutionApproved: false,
123
- });
124
- }
125
- catch (err) {
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));
151
- }
152
- });
153
- return router;
154
- }
155
- //# sourceMappingURL=captcha.js.map
@@ -1 +0,0 @@
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,EA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AM,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,23 +0,0 @@
1
- /// <reference types="bn.js" />
2
- import { ArgumentTypes, BatchCommitConfig, Commit, ExtrinsicBatch } from '@prosopo/types';
3
- import { BN } from '@polkadot/util';
4
- import { Database, UserCommitmentRecord } from '@prosopo/types-database';
5
- import { Logger } from '@prosopo/common';
6
- import { ProsopoCaptchaContract } from '@prosopo/contract';
7
- import { WeightV2 } from '@polkadot/types/interfaces';
8
- export declare class BatchCommitmentsTask {
9
- contract: ProsopoCaptchaContract;
10
- db: Database;
11
- batchCommitConfig: BatchCommitConfig;
12
- logger: Logger;
13
- private nonce;
14
- constructor(batchCommitConfig: BatchCommitConfig, contractApi: ProsopoCaptchaContract, db: Database, startNonce: bigint, logger: Logger);
15
- run(): Promise<void>;
16
- createExtrinsics(commitments: UserCommitmentRecord[]): Promise<ExtrinsicBatch>;
17
- extrinsicTooHigh(totalRefTime: BN, totalProofSize: BN, maxBlockWeight: WeightV2): boolean;
18
- batchIntervalExceeded(): Promise<boolean>;
19
- getCommitments(): Promise<UserCommitmentRecord[]>;
20
- flagBatchedCommitments(commitmentIds: ArgumentTypes.Hash[]): Promise<void>;
21
- convertCommit(commitment: UserCommitmentRecord): Commit;
22
- }
23
- //# sourceMappingURL=commitments.d.ts.map
@@ -1 +0,0 @@
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,149 +0,0 @@
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);
7
- const CONTRACT_METHOD_NAME = 'providerCommitMany';
8
- export class BatchCommitmentsTask {
9
- contract;
10
- db;
11
- batchCommitConfig;
12
- logger;
13
- nonce;
14
- constructor(batchCommitConfig, contractApi, db, startNonce, logger) {
15
- this.contract = contractApi;
16
- this.db = db;
17
- this.batchCommitConfig = batchCommitConfig;
18
- this.logger = logger;
19
- this.nonce = startNonce;
20
- }
21
- async run() {
22
- // create a task id
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),
56
- });
57
- }
58
- }
59
- }
60
- }
61
- async createExtrinsics(commitments) {
62
- const txs = [];
63
- const fragment = this.contract.abi.findMessage(CONTRACT_METHOD_NAME);
64
- const batchedCommitmentIds = [];
65
- let totalRefTime = new BN(0);
66
- let totalProofSize = new BN(0);
67
- let totalFee = new BN(0);
68
- const maxBlockWeight = this.contract.api.consts.system.blockWeights.maxBlock;
69
- const commitmentArray = [];
70
- let extrinsic;
71
- for (const commitment of commitments) {
72
- const commit = this.convertCommit(commitment);
73
- commitmentArray.push(commit);
74
- const encodedArgs = encodeStringArgs(this.contract.abi, fragment, [commitmentArray]);
75
- // TODO can we get storage deposit from the provided query method?
76
- // https://matrix.to/#/!utTuYglskDvqRRMQta:matrix.org/$tELySFxCORlHCHveOknGJBx-MdVe-SxFN8_BsYvcDmI?via=matrix.org&via=t2bot.io&via=cardinal.ems.host
77
- // const response = await this.contract.query.providerCommitMany(commitmentArray)
78
- const buildExtrinsicResult = await this.contract.getExtrinsicAndGasEstimates('providerCommitMany', encodedArgs);
79
- extrinsic = buildExtrinsicResult.extrinsic;
80
- const { options, storageDeposit } = buildExtrinsicResult;
81
- let paymentInfo;
82
- try {
83
- paymentInfo = (await extrinsic.paymentInfo(this.contract.pair)).partialFee.toBn();
84
- this.logger.debug(`${CONTRACT_METHOD_NAME} paymentInfo:`, paymentInfo.toNumber());
85
- }
86
- catch (e) {
87
- // TODO https://github.com/polkadot-js/api/issues/5504
88
- paymentInfo = new BN(0);
89
- }
90
- //totalEncodedLength += extrinsic.encodedLength
91
- totalRefTime = totalRefTime.add(this.contract.api.registry.createType('WeightV2', options.gasLimit).refTime.toBn());
92
- totalProofSize = totalProofSize.add(this.contract.api.registry.createType('WeightV2', options.gasLimit).proofSize.toBn());
93
- totalFee = totalFee.add(paymentInfo.add(storageDeposit.asCharge.toBn()));
94
- const extrinsicTooHigh = this.extrinsicTooHigh(totalRefTime, totalProofSize, maxBlockWeight);
95
- this.logger.debug('Free balance', '`', (await this.contract.api.query.system.account(this.contract.pair.address)).data.free
96
- .toBn()
97
- .div(oneUnit(this.contract.api))
98
- .toString(), '`', 'UNIT');
99
- this.logger.debug('Total Fee `', totalFee.div(oneUnit(this.contract.api)).toString(), '`', 'UNIT');
100
- const feeTooHigh = totalFee.gt((await this.contract.api.query.system.account(this.contract.pair.address)).data.free.toBn());
101
- // Check if we have a maximum number of transactions that we can successfully submit in a block or if the
102
- // total fee is more than the provider has left in their account
103
- if (extrinsicTooHigh || feeTooHigh) {
104
- const msg = extrinsicTooHigh ? 'Max batch extrinsic percentage reached' : 'Fee too high';
105
- this.logger.warn(msg);
106
- break;
107
- }
108
- else {
109
- batchedCommitmentIds.push(commitment.id);
110
- }
111
- }
112
- if (!extrinsic) {
113
- throw new ProsopoContractError('No extrinsics created');
114
- }
115
- txs.push(extrinsic);
116
- this.logger.info(`${txs.length} transactions will be batched`);
117
- this.logger.debug('totalRefTime:', totalRefTime.toString());
118
- this.logger.debug('totalProofSize:', totalProofSize.toString());
119
- return { extrinsics: txs, ids: batchedCommitmentIds, totalFee, totalRefTime, totalProofSize };
120
- }
121
- extrinsicTooHigh(totalRefTime, totalProofSize, maxBlockWeight) {
122
- return (totalRefTime.mul(BN_TEN_THOUSAND).div(maxBlockWeight.refTime.toBn()).toNumber() / 100 >
123
- this.batchCommitConfig.maxBatchExtrinsicPercentage);
124
- }
125
- async batchIntervalExceeded() {
126
- //if time since last commit > batchCommitInterval
127
- const lastTime = await this.db.getLastBatchCommitTime();
128
- return Date.now() - lastTime.getSeconds() > this.batchCommitConfig.interval;
129
- }
130
- async getCommitments() {
131
- // get commitments that have not yet been batched on-chain
132
- return await this.db.getUnbatchedDappUserCommitments();
133
- }
134
- async flagBatchedCommitments(commitmentIds) {
135
- await this.db.flagBatchedDappUserCommitments(commitmentIds);
136
- }
137
- convertCommit(commitment) {
138
- const { batched, processed, userSignature, requestedAt, completedAt, ...commit } = commitment;
139
- return {
140
- ...commit,
141
- userSignaturePart1: userSignature.slice(0, userSignature.length / 2),
142
- userSignaturePart2: userSignature.slice(userSignature.length / 2),
143
- // to satisfy typescript
144
- requestedAt: new BN(requestedAt).toNumber(),
145
- completedAt: new BN(completedAt).toNumber(),
146
- };
147
- }
148
- }
149
- //# sourceMappingURL=commitments.js.map
@@ -1 +0,0 @@
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;QACnB,MAAM,MAAM,GAAG,WAAW,CAAC,EAAE,CAAC,CAAA;QAC9B,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAA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,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"}
@@ -1,2 +0,0 @@
1
- export * from './commitments.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/batch/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAA"}
@@ -1,15 +0,0 @@
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';
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- export * from './tasks/index.js';
2
- export * from './util.js';
3
- export * from './batch/index.js';
4
- export * from './api/captcha.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,18 +0,0 @@
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 './tasks/index.js';
15
- export * from './util.js';
16
- export * from './batch/index.js';
17
- export * from './api/captcha.js';
18
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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"}
@@ -1,5 +0,0 @@
1
- import { KeyringPair } from '@polkadot/keyring/types';
2
- import { ProsopoConfig } from '@prosopo/types';
3
- export declare function calculateSolutionsScheduler(pair: KeyringPair, config: ProsopoConfig): Promise<void>;
4
- export declare function batchCommitScheduler(pair: KeyringPair, config: ProsopoConfig): Promise<void>;
5
- //# sourceMappingURL=scheduler.d.ts.map
@@ -1 +0,0 @@
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"}
package/dist/scheduler.js DELETED
@@ -1,48 +0,0 @@
1
- // Copyright 2021-2022 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
- // [object Object]
15
- // SPDX-License-Identifier: Apache-2.0
16
- import { BatchCommitmentsTask } from './batch/commitments.js';
17
- import { CalculateSolutionsTask } from './tasks/calculateSolutions.js';
18
- import { CronJob } from 'cron';
19
- import { ProsopoEnvError } from '@prosopo/common';
20
- import { ProviderEnvironment } from '@prosopo/env';
21
- export async function calculateSolutionsScheduler(pair, config) {
22
- const env = new ProviderEnvironment(pair, config);
23
- await env.isReady();
24
- const tasks = new CalculateSolutionsTask(env);
25
- const job = new CronJob(process.argv[2], () => {
26
- env.logger.debug('CalculateSolutionsTask....');
27
- tasks.run().catch((err) => {
28
- env.logger.error(err);
29
- });
30
- });
31
- job.start();
32
- }
33
- export async function batchCommitScheduler(pair, config) {
34
- const env = new ProviderEnvironment(pair, config);
35
- await env.isReady();
36
- if (env.db === undefined) {
37
- throw new ProsopoEnvError('DATABASE.DATABASE_UNDEFINED');
38
- }
39
- const tasks = new BatchCommitmentsTask(config.batchCommit, env.contractInterface, env.db, 0n, env.logger);
40
- const job = new CronJob(process.argv[2], () => {
41
- env.logger.debug('BatchCommitmentsTask....');
42
- tasks.run().catch((err) => {
43
- env.logger.error(err);
44
- });
45
- });
46
- job.start();
47
- }
48
- //# sourceMappingURL=scheduler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.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,kBAAkB;AAClB,sCAAsC;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,IAAiB,EAAE,MAAqB;IACtF,MAAM,GAAG,GAAG,IAAI,mBAAm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AAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACzB,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;IAEF,GAAG,CAAC,KAAK,EAAE,CAAA;AACf,CAAC"}
@@ -1,10 +0,0 @@
1
- import { ProviderEnvironment } from '@prosopo/types-env';
2
- import { Tasks } from './tasks.js';
3
- export declare class CalculateSolutionsTask extends Tasks {
4
- constructor(env: ProviderEnvironment);
5
- /**
6
- * Apply new captcha solutions to captcha dataset and recalculate merkle tree
7
- */
8
- run(): Promise<number>;
9
- }
10
- //# sourceMappingURL=calculateSolutions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calculateSolutions.d.ts","sourceRoot":"","sources":["../../src/tasks/calculateSolutions.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAGlC,qBAAa,sBAAuB,SAAQ,KAAK;gBACjC,GAAG,EAAE,mBAAmB;IAKpC;;OAEG;IACG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;CAmE/B"}