@maci-protocol/coordinator 0.0.0-ci.533e19d
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/CHANGELOG.md +51 -0
- package/LICENSE +22 -0
- package/README.md +42 -0
- package/build/hardhat.config.cjs +31 -0
- package/build/hardhat.config.cjs.map +1 -0
- package/build/hardhat.config.d.cts +24 -0
- package/build/hardhat.config.d.cts.map +1 -0
- package/build/scripts/generateKeypair.d.ts +2 -0
- package/build/scripts/generateKeypair.d.ts.map +1 -0
- package/build/scripts/generateKeypair.js +25 -0
- package/build/scripts/generateKeypair.js.map +1 -0
- package/build/scripts/generateMaciKeyPair.d.ts +2 -0
- package/build/scripts/generateMaciKeyPair.d.ts.map +1 -0
- package/build/scripts/generateMaciKeyPair.js +3 -0
- package/build/scripts/generateMaciKeyPair.js.map +1 -0
- package/build/scripts/getAuthHeader.d.ts +2 -0
- package/build/scripts/getAuthHeader.d.ts.map +1 -0
- package/build/scripts/getAuthHeader.js +31 -0
- package/build/scripts/getAuthHeader.js.map +1 -0
- package/build/tests/constants.d.ts +8 -0
- package/build/tests/constants.d.ts.map +1 -0
- package/build/tests/constants.js +10 -0
- package/build/tests/constants.js.map +1 -0
- package/build/tests/e2e.aa.test.d.ts +2 -0
- package/build/tests/e2e.aa.test.d.ts.map +1 -0
- package/build/tests/e2e.aa.test.js +103 -0
- package/build/tests/e2e.aa.test.js.map +1 -0
- package/build/tests/e2e.deploy.test.d.ts +2 -0
- package/build/tests/e2e.deploy.test.d.ts.map +1 -0
- package/build/tests/e2e.deploy.test.js +234 -0
- package/build/tests/e2e.deploy.test.js.map +1 -0
- package/build/tests/utils.d.ts +14 -0
- package/build/tests/utils.d.ts.map +1 -0
- package/build/tests/utils.js +44 -0
- package/build/tests/utils.js.map +1 -0
- package/build/ts/app.module.d.ts +3 -0
- package/build/ts/app.module.d.ts.map +1 -0
- package/build/ts/app.module.js +36 -0
- package/build/ts/app.module.js.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts +44 -0
- package/build/ts/auth/AccountSignatureGuard.service.d.ts.map +1 -0
- package/build/ts/auth/AccountSignatureGuard.service.js +96 -0
- package/build/ts/auth/AccountSignatureGuard.service.js.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts +2 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.d.ts.map +1 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js +113 -0
- package/build/ts/auth/__tests__/AccountSignatureGuard.test.js.map +1 -0
- package/build/ts/common/__tests__/common.test.d.ts +2 -0
- package/build/ts/common/__tests__/common.test.d.ts.map +1 -0
- package/build/ts/common/__tests__/common.test.js +79 -0
- package/build/ts/common/__tests__/common.test.js.map +1 -0
- package/build/ts/common/accountAbstraction.d.ts +55 -0
- package/build/ts/common/accountAbstraction.d.ts.map +1 -0
- package/build/ts/common/accountAbstraction.js +110 -0
- package/build/ts/common/accountAbstraction.js.map +1 -0
- package/build/ts/common/errors.d.ts +33 -0
- package/build/ts/common/errors.d.ts.map +1 -0
- package/build/ts/common/errors.js +34 -0
- package/build/ts/common/errors.js.map +1 -0
- package/build/ts/common/index.d.ts +4 -0
- package/build/ts/common/index.d.ts.map +1 -0
- package/build/ts/common/index.js +4 -0
- package/build/ts/common/index.js.map +1 -0
- package/build/ts/common/networks.d.ts +29 -0
- package/build/ts/common/networks.d.ts.map +1 -0
- package/build/ts/common/networks.js +70 -0
- package/build/ts/common/networks.js.map +1 -0
- package/build/ts/common/types.d.ts +9 -0
- package/build/ts/common/types.d.ts.map +1 -0
- package/build/ts/common/types.js +2 -0
- package/build/ts/common/types.js.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts +2 -0
- package/build/ts/crypto/__tests__/crypto.service.test.d.ts.map +1 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js +26 -0
- package/build/ts/crypto/__tests__/crypto.service.test.js.map +1 -0
- package/build/ts/crypto/crypto.module.d.ts +3 -0
- package/build/ts/crypto/crypto.module.d.ts.map +1 -0
- package/build/ts/crypto/crypto.module.js +18 -0
- package/build/ts/crypto/crypto.module.js.map +1 -0
- package/build/ts/crypto/crypto.service.d.ts +31 -0
- package/build/ts/crypto/crypto.service.d.ts.map +1 -0
- package/build/ts/crypto/crypto.service.js +68 -0
- package/build/ts/crypto/crypto.service.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js +84 -0
- package/build/ts/deployer/__tests__/deployer.controller.test.js.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts +2 -0
- package/build/ts/deployer/__tests__/deployer.service.test.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js +425 -0
- package/build/ts/deployer/__tests__/deployer.service.test.js.map +1 -0
- package/build/ts/deployer/__tests__/utils.d.ts +36 -0
- package/build/ts/deployer/__tests__/utils.d.ts.map +1 -0
- package/build/ts/deployer/__tests__/utils.js +96 -0
- package/build/ts/deployer/__tests__/utils.js.map +1 -0
- package/build/ts/deployer/constants.d.ts +13 -0
- package/build/ts/deployer/constants.d.ts.map +1 -0
- package/build/ts/deployer/constants.js +13 -0
- package/build/ts/deployer/constants.js.map +1 -0
- package/build/ts/deployer/deployer.controller.d.ts +34 -0
- package/build/ts/deployer/deployer.controller.d.ts.map +1 -0
- package/build/ts/deployer/deployer.controller.js +89 -0
- package/build/ts/deployer/deployer.controller.js.map +1 -0
- package/build/ts/deployer/deployer.module.d.ts +3 -0
- package/build/ts/deployer/deployer.module.d.ts.map +1 -0
- package/build/ts/deployer/deployer.module.js +23 -0
- package/build/ts/deployer/deployer.module.js.map +1 -0
- package/build/ts/deployer/deployer.service.d.ts +112 -0
- package/build/ts/deployer/deployer.service.d.ts.map +1 -0
- package/build/ts/deployer/deployer.service.js +614 -0
- package/build/ts/deployer/deployer.service.js.map +1 -0
- package/build/ts/deployer/dto.d.ts +46 -0
- package/build/ts/deployer/dto.d.ts.map +1 -0
- package/build/ts/deployer/dto.js +117 -0
- package/build/ts/deployer/dto.js.map +1 -0
- package/build/ts/deployer/types.d.ts +293 -0
- package/build/ts/deployer/types.d.ts.map +1 -0
- package/build/ts/deployer/types.js +2 -0
- package/build/ts/deployer/types.js.map +1 -0
- package/build/ts/deployer/utils.d.ts +8 -0
- package/build/ts/deployer/utils.d.ts.map +1 -0
- package/build/ts/deployer/utils.js +9 -0
- package/build/ts/deployer/utils.js.map +1 -0
- package/build/ts/file/__tests__/file.service.test.d.ts +2 -0
- package/build/ts/file/__tests__/file.service.test.d.ts.map +1 -0
- package/build/ts/file/__tests__/file.service.test.js +76 -0
- package/build/ts/file/__tests__/file.service.test.js.map +1 -0
- package/build/ts/file/file.module.d.ts +3 -0
- package/build/ts/file/file.module.d.ts.map +1 -0
- package/build/ts/file/file.module.js +18 -0
- package/build/ts/file/file.module.js.map +1 -0
- package/build/ts/file/file.service.d.ts +62 -0
- package/build/ts/file/file.service.d.ts.map +1 -0
- package/build/ts/file/file.service.js +115 -0
- package/build/ts/file/file.service.js.map +1 -0
- package/build/ts/file/types.d.ts +36 -0
- package/build/ts/file/types.d.ts.map +1 -0
- package/build/ts/file/types.js +2 -0
- package/build/ts/file/types.js.map +1 -0
- package/build/ts/jest/setup.d.ts +8 -0
- package/build/ts/jest/setup.d.ts.map +1 -0
- package/build/ts/jest/setup.js +2 -0
- package/build/ts/jest/setup.js.map +1 -0
- package/build/ts/jest/transform.d.ts +8 -0
- package/build/ts/jest/transform.d.ts.map +1 -0
- package/build/ts/jest/transform.js +10 -0
- package/build/ts/jest/transform.js.map +1 -0
- package/build/ts/main.d.ts +2 -0
- package/build/ts/main.d.ts.map +1 -0
- package/build/ts/main.js +46 -0
- package/build/ts/main.js.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.controller.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.controller.test.js +89 -0
- package/build/ts/proof/__tests__/proof.controller.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.gateway.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js +61 -0
- package/build/ts/proof/__tests__/proof.gateway.test.js.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts +2 -0
- package/build/ts/proof/__tests__/proof.service.test.d.ts.map +1 -0
- package/build/ts/proof/__tests__/proof.service.test.js +128 -0
- package/build/ts/proof/__tests__/proof.service.test.js.map +1 -0
- package/build/ts/proof/dto.d.ts +73 -0
- package/build/ts/proof/dto.d.ts.map +1 -0
- package/build/ts/proof/dto.js +255 -0
- package/build/ts/proof/dto.js.map +1 -0
- package/build/ts/proof/proof.controller.d.ts +46 -0
- package/build/ts/proof/proof.controller.d.ts.map +1 -0
- package/build/ts/proof/proof.controller.js +135 -0
- package/build/ts/proof/proof.controller.js.map +1 -0
- package/build/ts/proof/proof.gateway.d.ts +35 -0
- package/build/ts/proof/proof.gateway.d.ts.map +1 -0
- package/build/ts/proof/proof.gateway.js +93 -0
- package/build/ts/proof/proof.gateway.js.map +1 -0
- package/build/ts/proof/proof.module.d.ts +3 -0
- package/build/ts/proof/proof.module.d.ts.map +1 -0
- package/build/ts/proof/proof.module.js +24 -0
- package/build/ts/proof/proof.module.js.map +1 -0
- package/build/ts/proof/proof.service.d.ts +54 -0
- package/build/ts/proof/proof.service.d.ts.map +1 -0
- package/build/ts/proof/proof.service.js +246 -0
- package/build/ts/proof/proof.service.js.map +1 -0
- package/build/ts/proof/types.d.ts +140 -0
- package/build/ts/proof/types.d.ts.map +1 -0
- package/build/ts/proof/types.js +11 -0
- package/build/ts/proof/types.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js +44 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.controller.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts +2 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js +61 -0
- package/build/ts/sessionKeys/__tests__/sessionKeys.service.test.js.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts +25 -0
- package/build/ts/sessionKeys/__tests__/utils.d.ts.map +1 -0
- package/build/ts/sessionKeys/__tests__/utils.js +64 -0
- package/build/ts/sessionKeys/__tests__/utils.js.map +1 -0
- package/build/ts/sessionKeys/dto.d.ts +11 -0
- package/build/ts/sessionKeys/dto.d.ts.map +1 -0
- package/build/ts/sessionKeys/dto.js +29 -0
- package/build/ts/sessionKeys/dto.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts +26 -0
- package/build/ts/sessionKeys/sessionKeys.controller.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js +74 -0
- package/build/ts/sessionKeys/sessionKeys.controller.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts +3 -0
- package/build/ts/sessionKeys/sessionKeys.module.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.module.js +23 -0
- package/build/ts/sessionKeys/sessionKeys.module.js.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts +50 -0
- package/build/ts/sessionKeys/sessionKeys.service.d.ts.map +1 -0
- package/build/ts/sessionKeys/sessionKeys.service.js +104 -0
- package/build/ts/sessionKeys/sessionKeys.service.js.map +1 -0
- package/build/ts/sessionKeys/types.d.ts +11 -0
- package/build/ts/sessionKeys/types.d.ts.map +1 -0
- package/build/ts/sessionKeys/types.js +2 -0
- package/build/ts/sessionKeys/types.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js +50 -0
- package/build/ts/subgraph/__tests__/subgraph.controller.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js +83 -0
- package/build/ts/subgraph/__tests__/subgraph.gateway.test.js.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts +2 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.d.ts.map +1 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js +58 -0
- package/build/ts/subgraph/__tests__/subgraph.service.test.js.map +1 -0
- package/build/ts/subgraph/dto.d.ts +27 -0
- package/build/ts/subgraph/dto.d.ts.map +1 -0
- package/build/ts/subgraph/dto.js +83 -0
- package/build/ts/subgraph/dto.js.map +1 -0
- package/build/ts/subgraph/subgraph.controller.d.ts +24 -0
- package/build/ts/subgraph/subgraph.controller.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.controller.js +66 -0
- package/build/ts/subgraph/subgraph.controller.js.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts +35 -0
- package/build/ts/subgraph/subgraph.gateway.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.gateway.js +93 -0
- package/build/ts/subgraph/subgraph.gateway.js.map +1 -0
- package/build/ts/subgraph/subgraph.module.d.ts +3 -0
- package/build/ts/subgraph/subgraph.module.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.module.js +23 -0
- package/build/ts/subgraph/subgraph.module.js.map +1 -0
- package/build/ts/subgraph/subgraph.service.d.ts +20 -0
- package/build/ts/subgraph/subgraph.service.d.ts.map +1 -0
- package/build/ts/subgraph/subgraph.service.js +106 -0
- package/build/ts/subgraph/subgraph.service.js.map +1 -0
- package/build/ts/subgraph/types.d.ts +93 -0
- package/build/ts/subgraph/types.d.ts.map +1 -0
- package/build/ts/subgraph/types.js +24 -0
- package/build/ts/subgraph/types.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { IGetPrivateKeyData, IGetPublicKeyData, IGetZkeyFilePathsData } from "./types";
|
|
2
|
+
import type { Hex } from "viem";
|
|
3
|
+
/**
|
|
4
|
+
* FileService is responsible for working with local files like:
|
|
5
|
+
* 1. RSA public/private keys
|
|
6
|
+
* 2. Zkey files
|
|
7
|
+
*/
|
|
8
|
+
export declare class FileService {
|
|
9
|
+
/**
|
|
10
|
+
* Logger
|
|
11
|
+
*/
|
|
12
|
+
private readonly logger;
|
|
13
|
+
/**
|
|
14
|
+
* Json file database instance
|
|
15
|
+
*/
|
|
16
|
+
private db;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize service
|
|
19
|
+
*/
|
|
20
|
+
constructor();
|
|
21
|
+
/**
|
|
22
|
+
* Store session key
|
|
23
|
+
*
|
|
24
|
+
* @param sessionKey - session key
|
|
25
|
+
* @param address - key address
|
|
26
|
+
*/
|
|
27
|
+
storeSessionKey(sessionKey: Hex, address: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Delete session key
|
|
30
|
+
*
|
|
31
|
+
* @param address - key address
|
|
32
|
+
*/
|
|
33
|
+
deleteSessionKey(address: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get session key
|
|
36
|
+
*
|
|
37
|
+
* @param address - key name
|
|
38
|
+
* @returns session key
|
|
39
|
+
*/
|
|
40
|
+
getSessionKey(address: string): Hex | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Get RSA private key for coordinator service
|
|
43
|
+
*
|
|
44
|
+
* @returns serialized RSA public key
|
|
45
|
+
*/
|
|
46
|
+
getPublicKey(): Promise<IGetPublicKeyData>;
|
|
47
|
+
/**
|
|
48
|
+
* Get RSA private key for coordinator service
|
|
49
|
+
*
|
|
50
|
+
* @returns serialized RSA private key
|
|
51
|
+
*/
|
|
52
|
+
getPrivateKey(): Promise<IGetPrivateKeyData>;
|
|
53
|
+
/**
|
|
54
|
+
* Get zkey, wasm and witgen filepaths for zkey set
|
|
55
|
+
*
|
|
56
|
+
* @param name - zkey set name
|
|
57
|
+
* @param useQuadraticVoting - whether to use Qv or NonQv
|
|
58
|
+
* @returns zkey and wasm filepaths
|
|
59
|
+
*/
|
|
60
|
+
getZkeyFilePaths(name: string, useQuadraticVoting: boolean): IGetZkeyFilePathsData;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=file.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.service.d.ts","sourceRoot":"","sources":["../../../ts/file/file.service.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAUhC;;;;GAIG;AACH,qBACa,WAAW;IACtB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;OAEG;IACH,OAAO,CAAC,EAAE,CAA0B;IAEpC;;OAEG;;IAMH;;;;;OAKG;IACH,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIvD;;;;OAIG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIvC;;;;;OAKG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS;IAI/C;;;;OAIG;IACG,YAAY,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAMhD;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAMlD;;;;;;OAMG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,qBAAqB;CAuBnF"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var FileService_1;
|
|
11
|
+
import { Injectable, Logger } from "@nestjs/common";
|
|
12
|
+
import low from "lowdb";
|
|
13
|
+
import FileSync from "lowdb/adapters/FileSync";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
16
|
+
import { ErrorCodes } from "../common";
|
|
17
|
+
/**
|
|
18
|
+
* FileService is responsible for working with local files like:
|
|
19
|
+
* 1. RSA public/private keys
|
|
20
|
+
* 2. Zkey files
|
|
21
|
+
*/
|
|
22
|
+
let FileService = FileService_1 = class FileService {
|
|
23
|
+
/**
|
|
24
|
+
* Logger
|
|
25
|
+
*/
|
|
26
|
+
logger;
|
|
27
|
+
/**
|
|
28
|
+
* Json file database instance
|
|
29
|
+
*/
|
|
30
|
+
db;
|
|
31
|
+
/**
|
|
32
|
+
* Initialize service
|
|
33
|
+
*/
|
|
34
|
+
constructor() {
|
|
35
|
+
this.logger = new Logger(FileService_1.name);
|
|
36
|
+
this.db = low(new FileSync(path.resolve(process.cwd(), "./session-keys.json")));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Store session key
|
|
40
|
+
*
|
|
41
|
+
* @param sessionKey - session key
|
|
42
|
+
* @param address - key address
|
|
43
|
+
*/
|
|
44
|
+
storeSessionKey(sessionKey, address) {
|
|
45
|
+
this.db.set(address, sessionKey).write();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Delete session key
|
|
49
|
+
*
|
|
50
|
+
* @param address - key address
|
|
51
|
+
*/
|
|
52
|
+
deleteSessionKey(address) {
|
|
53
|
+
this.db.unset(address).write();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get session key
|
|
57
|
+
*
|
|
58
|
+
* @param address - key name
|
|
59
|
+
* @returns session key
|
|
60
|
+
*/
|
|
61
|
+
getSessionKey(address) {
|
|
62
|
+
return this.db.get(address).value();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get RSA private key for coordinator service
|
|
66
|
+
*
|
|
67
|
+
* @returns serialized RSA public key
|
|
68
|
+
*/
|
|
69
|
+
async getPublicKey() {
|
|
70
|
+
const publicKey = await fs.promises.readFile(path.resolve(process.env.COORDINATOR_PUBLIC_KEY_PATH));
|
|
71
|
+
return { publicKey: publicKey.toString() };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get RSA private key for coordinator service
|
|
75
|
+
*
|
|
76
|
+
* @returns serialized RSA private key
|
|
77
|
+
*/
|
|
78
|
+
async getPrivateKey() {
|
|
79
|
+
const privateKey = await fs.promises.readFile(path.resolve(process.env.COORDINATOR_PRIVATE_KEY_PATH));
|
|
80
|
+
return { privateKey: privateKey.toString() };
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get zkey, wasm and witgen filepaths for zkey set
|
|
84
|
+
*
|
|
85
|
+
* @param name - zkey set name
|
|
86
|
+
* @param useQuadraticVoting - whether to use Qv or NonQv
|
|
87
|
+
* @returns zkey and wasm filepaths
|
|
88
|
+
*/
|
|
89
|
+
getZkeyFilePaths(name, useQuadraticVoting) {
|
|
90
|
+
const root = path.resolve(process.env.COORDINATOR_ZKEY_PATH);
|
|
91
|
+
const index = name.indexOf("_");
|
|
92
|
+
const type = name.slice(0, index);
|
|
93
|
+
const params = name.slice(index + 1);
|
|
94
|
+
const mode = useQuadraticVoting ? "" : "NonQv";
|
|
95
|
+
const filename = `${type}${mode}_${params}`;
|
|
96
|
+
const zkey = path.resolve(root, `${filename}/${filename}.0.zkey`);
|
|
97
|
+
const wasm = path.resolve(root, `${filename}/${filename}_js/${filename}.wasm`);
|
|
98
|
+
const witgen = path.resolve(root, `${filename}/${filename}_cpp/${filename}`);
|
|
99
|
+
if (!fs.existsSync(zkey) || (!fs.existsSync(wasm) && !fs.existsSync(witgen))) {
|
|
100
|
+
this.logger.error(`Error: ${ErrorCodes.FILE_NOT_FOUND}, zkey: ${zkey}, wasm: ${wasm}, witgen: ${witgen}`);
|
|
101
|
+
throw new Error(ErrorCodes.FILE_NOT_FOUND.toString());
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
zkey,
|
|
105
|
+
wasm,
|
|
106
|
+
witgen,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
FileService = FileService_1 = __decorate([
|
|
111
|
+
Injectable(),
|
|
112
|
+
__metadata("design:paramtypes", [])
|
|
113
|
+
], FileService);
|
|
114
|
+
export { FileService };
|
|
115
|
+
//# sourceMappingURL=file.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.service.js","sourceRoot":"","sources":["../../../ts/file/file.service.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,GAAG,MAAM,OAAO,CAAC;AACxB,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAKxB,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAQvC;;;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,MAAM,EAAE,CAAC,CAAC;YAC1G,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,OAAO;YACL,IAAI;YACJ,IAAI;YACJ,MAAM;SACP,CAAC;IACJ,CAAC;CACF,CAAA;AApGY,WAAW;IADvB,UAAU,EAAE;;GACA,WAAW,CAoGvB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface that represents public key return data
|
|
3
|
+
*/
|
|
4
|
+
export interface IGetPublicKeyData {
|
|
5
|
+
/**
|
|
6
|
+
* RSA public key
|
|
7
|
+
*/
|
|
8
|
+
publicKey: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface that represents private key return data
|
|
12
|
+
*/
|
|
13
|
+
export interface IGetPrivateKeyData {
|
|
14
|
+
/**
|
|
15
|
+
* RSA private key
|
|
16
|
+
*/
|
|
17
|
+
privateKey: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Interface that represents zkey file paths return data
|
|
21
|
+
*/
|
|
22
|
+
export interface IGetZkeyFilePathsData {
|
|
23
|
+
/**
|
|
24
|
+
* Zkey filepath
|
|
25
|
+
*/
|
|
26
|
+
zkey: string;
|
|
27
|
+
/**
|
|
28
|
+
* Wasm filepath
|
|
29
|
+
*/
|
|
30
|
+
wasm: string;
|
|
31
|
+
/**
|
|
32
|
+
* Witgen filepath
|
|
33
|
+
*/
|
|
34
|
+
witgen: string;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/file/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../ts/file/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HardhatEthersHelpers } from "@nomicfoundation/hardhat-ethers/types";
|
|
2
|
+
import type { ethers } from "ethers";
|
|
3
|
+
declare module "hardhat/types/runtime" {
|
|
4
|
+
interface HardhatRuntimeEnvironment {
|
|
5
|
+
ethers: typeof ethers & HardhatEthersHelpers;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../../ts/jest/setup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,QAAQ,uBAAuB,CAAC;IACrC,UAAU,yBAAyB;QAEjC,MAAM,EAAE,OAAO,MAAM,GAAG,oBAAoB,CAAC;KAC9C;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../../ts/jest/setup.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../ts/jest/transform.js"],"names":[],"mappings":"AAEA;;EAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../ts/jest/transform.js"],"names":[],"mappings":"AAAA,oBAAoB;AAEpB,MAAM,UAAU,OAAO,CAAC,UAAU;IAChC,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,qBAAqB,EAAE,EAAE,CAAC;KACpD,CAAC;AACJ,CAAC;AAED,eAAe;IACb,OAAO;CACR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../ts/main.ts"],"names":[],"mappings":""}
|
package/build/ts/main.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ValidationPipe } from "@nestjs/common";
|
|
2
|
+
import { NestFactory } from "@nestjs/core";
|
|
3
|
+
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
|
|
4
|
+
import dotenv from "dotenv";
|
|
5
|
+
import helmet from "helmet";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import url from "url";
|
|
8
|
+
/* eslint-disable no-underscore-dangle */
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
10
|
+
const __filename = url.fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
/* eslint-enable no-underscore-dangle */
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-shadow */
|
|
14
|
+
dotenv.config({
|
|
15
|
+
path: [path.resolve(__dirname, "../.env"), path.resolve(__dirname, "../.env.example")],
|
|
16
|
+
});
|
|
17
|
+
async function bootstrap() {
|
|
18
|
+
const { AppModule } = await import("./app.module.js");
|
|
19
|
+
const app = await NestFactory.create(AppModule, {
|
|
20
|
+
logger: ["log", "fatal", "error", "warn"],
|
|
21
|
+
});
|
|
22
|
+
app.useGlobalPipes(new ValidationPipe({ transform: true }));
|
|
23
|
+
app.use(helmet({
|
|
24
|
+
contentSecurityPolicy: {
|
|
25
|
+
directives: {
|
|
26
|
+
defaultSrc: [`'self'`],
|
|
27
|
+
styleSrc: [`'self'`, `'unsafe-inline'`],
|
|
28
|
+
imgSrc: [`'self'`, "data:", "validator.swagger.io"],
|
|
29
|
+
scriptSrc: [`'self'`, `https: 'unsafe-inline'`],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
app.enableCors({ origin: process.env.COORDINATOR_ALLOWED_ORIGINS?.split(",") });
|
|
34
|
+
const config = new DocumentBuilder()
|
|
35
|
+
.setTitle("Coordinator service")
|
|
36
|
+
.setDescription("Coordinator service API methods")
|
|
37
|
+
.setVersion("1.0")
|
|
38
|
+
.addTag("coordinator")
|
|
39
|
+
.addBearerAuth()
|
|
40
|
+
.build();
|
|
41
|
+
const document = SwaggerModule.createDocument(app, config);
|
|
42
|
+
SwaggerModule.setup("api", app, document);
|
|
43
|
+
await app.listen(process.env.COORDINATOR_PORT || 3000);
|
|
44
|
+
}
|
|
45
|
+
bootstrap();
|
|
46
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../ts/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,yCAAyC;AACzC,iDAAiD;AACjD,MAAM,UAAU,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACtD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC3C,wCAAwC;AACxC,iDAAiD;AAEjD,MAAM,CAAC,MAAM,CAA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AM,CAAC,CAAC;IAC3D,aAAa,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;IAE1C,MAAM,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,IAAI,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.controller.test.d.ts","sourceRoot":"","sources":["../../../../ts/proof/__tests__/proof.controller.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { HttpException, HttpStatus } from "@nestjs/common";
|
|
2
|
+
import { Test } from "@nestjs/testing";
|
|
3
|
+
import { ESupportedNetworks } from "../../common";
|
|
4
|
+
import { FileService } from "../../file/file.service";
|
|
5
|
+
import { ProofController } from "../proof.controller";
|
|
6
|
+
import { ProofGeneratorService } from "../proof.service";
|
|
7
|
+
describe("ProofController", () => {
|
|
8
|
+
let proofController;
|
|
9
|
+
const defaultProofGeneratorArgs = {
|
|
10
|
+
poll: 0,
|
|
11
|
+
maciContractAddress: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
12
|
+
tallyContractAddress: "0x6F1216D1BFe15c98520CA1434FC1d9D57AC95321",
|
|
13
|
+
useQuadraticVoting: false,
|
|
14
|
+
encryptedCoordinatorPrivateKey: "siO9W/g7jNVXs9tOUv/pffrcqYdMlgdXw7nSSlqM1q1UvHGSSbhtLJpeT+nJKW7/+xrBTgI0wB866DSkg8Rgr8zD+POUMiKPrGqAO/XhrcmRDL+COURFNDRh9WGeAua6hdiNoufQYvXPl1iWyIYidSDbfmC2wR6F9vVkhg/6KDZyw8Wlr6LUh0RYT+hUHEwwGbz7MeqZJcJQSTpECPF5pnk8NTHL2W/XThaewB4n4HYqjDUbYLmBDLYWsDDMgoPo709a309rTq3uEe0YBgVF8g9aGxucTDhz+/LYYzqaeSxclUwen9Z4BGZjiDSPBZfooOEQEEwIJlViQ2kl1VeOKAmkiWEUVfItivmNbC/PNZchklmfFsGpiu4DT9UU9YVBN2OTcFYHHsslcaqrR7SuesqjluaGjG46oYEmfQlkZ4gXhavdWXw2ant+Tv6HRo4trqjoD1e3jUkN6gJMWomxOeRBTg0czBZlz/IwUtTpBHcKhi3EqGQo8OuQtWww+Ts7ySmeoONuovYUsIAppNuOubfUxvFJoTr2vKbWNAiYetw09kddkjmBe+S8A5PUiFOi262mfc7g5wJwPPP7wpTBY0Fya+2BCPzXqRLMOtNI+1tW3/UQLZYvEY8J0TxmhoAGZaRn8FKaosatRxDZTQS6QUNmKxpmUspkRKzTXN5lznM=",
|
|
15
|
+
};
|
|
16
|
+
const defaultMergeArgs = {
|
|
17
|
+
maciContractAddress: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
18
|
+
pollId: 0,
|
|
19
|
+
sessionKeyAddress: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
20
|
+
approval: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
21
|
+
chain: ESupportedNetworks.LOCALHOST,
|
|
22
|
+
};
|
|
23
|
+
const defaultProofGeneratorData = {
|
|
24
|
+
tallyProofs: [],
|
|
25
|
+
processProofs: [],
|
|
26
|
+
tallyData: {},
|
|
27
|
+
};
|
|
28
|
+
const defaultPublicKeyData = {
|
|
29
|
+
publicKey: "key",
|
|
30
|
+
};
|
|
31
|
+
const mockGeneratorService = {
|
|
32
|
+
generate: jest.fn(),
|
|
33
|
+
merge: jest.fn(),
|
|
34
|
+
};
|
|
35
|
+
const mockFileService = {
|
|
36
|
+
getPublicKey: jest.fn(),
|
|
37
|
+
};
|
|
38
|
+
beforeEach(async () => {
|
|
39
|
+
const app = await Test.createTestingModule({
|
|
40
|
+
controllers: [ProofController],
|
|
41
|
+
})
|
|
42
|
+
.useMocker((token) => {
|
|
43
|
+
if (token === ProofGeneratorService) {
|
|
44
|
+
mockGeneratorService.generate.mockResolvedValue(defaultProofGeneratorData);
|
|
45
|
+
mockGeneratorService.merge.mockResolvedValue(true);
|
|
46
|
+
return mockGeneratorService;
|
|
47
|
+
}
|
|
48
|
+
if (token === FileService) {
|
|
49
|
+
mockFileService.getPublicKey.mockResolvedValue(defaultPublicKeyData);
|
|
50
|
+
return mockFileService;
|
|
51
|
+
}
|
|
52
|
+
return jest.fn();
|
|
53
|
+
})
|
|
54
|
+
.compile();
|
|
55
|
+
proofController = app.get(ProofController);
|
|
56
|
+
});
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
jest.clearAllMocks();
|
|
59
|
+
});
|
|
60
|
+
describe("v1/proof/generate", () => {
|
|
61
|
+
test("should return generated proof data", async () => {
|
|
62
|
+
const data = await proofController.generate(defaultProofGeneratorArgs);
|
|
63
|
+
expect(data).toStrictEqual(defaultProofGeneratorData);
|
|
64
|
+
});
|
|
65
|
+
test("should throw an error if proof generation is failed", async () => {
|
|
66
|
+
const error = new Error("error");
|
|
67
|
+
mockGeneratorService.generate.mockRejectedValue(error);
|
|
68
|
+
await expect(proofController.generate(defaultProofGeneratorArgs)).rejects.toThrow(new HttpException(error.message, HttpStatus.BAD_REQUEST));
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("v1/proof/merge", () => {
|
|
72
|
+
test("should return true when there are no errors", async () => {
|
|
73
|
+
const data = await proofController.merge(defaultMergeArgs);
|
|
74
|
+
expect(data).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
describe("v1/proof/publicKey", () => {
|
|
78
|
+
test("should return public key properly", async () => {
|
|
79
|
+
const data = await proofController.getPublicKey();
|
|
80
|
+
expect(data).toStrictEqual(defaultPublicKeyData);
|
|
81
|
+
});
|
|
82
|
+
test("should throw an error if file service throws an error", async () => {
|
|
83
|
+
const error = new Error("error");
|
|
84
|
+
mockFileService.getPublicKey.mockRejectedValue(error);
|
|
85
|
+
await expect(proofController.getPublicKey()).rejects.toThrow(new HttpException(error.message, HttpStatus.BAD_REQUEST));
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
//# sourceMappingURL=proof.controller.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.controller.test.js","sourceRoot":"","sources":["../../../../ts/proof/__tests__/proof.controller.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAMvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,IAAI,eAAgC,CAAC;IAErC,MAAM,yBAAyB,GAAkB;QAC/C,IAAI,EAAE,CAAC;QACP,mBAAmB,EAAE,4CAA4C;QACjE,oBAAoB,EAAE,4CAA4C;QAClE,kBAAkB,EAAE,KAAK;QACzB,8BAA8B,EAC5B,8qBAA8qB;KACjrB,CAAC;IAEF,MAAM,gBAAgB,GAAe;QACnC,mBAAmB,EAAE,4CAA4C;QACjE,MAAM,EAAE,CAAC;QACT,iBAAiB,EAAE,4CAA4C;QAC/D,QAAQ,EAAE,4CAA4C;QACtD,KAAK,EAAE,kBAAkB,CAAC,SAAS;KACpC,CAAC;IAEF,MAAM,yBAAyB,GAAkB;QAC/C,WAAW,EAAE,EAAE;QACf,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAgB;KAC5B,CAAC;IAEF,MAAM,oBAAoB,GAAsB;QAC9C,SAAS,EAAE,KAAK;KACjB,CAAC;IAEF,MAAM,oBAAoB,GAAG;QAC3B,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE;QACnB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CAAC,CACzD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.gateway.test.d.ts","sourceRoot":"","sources":["../../../../ts/proof/__tests__/proof.gateway.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Test } from "@nestjs/testing";
|
|
2
|
+
import { ProofGateway } from "../proof.gateway";
|
|
3
|
+
import { ProofGeneratorService } from "../proof.service";
|
|
4
|
+
import { EProofGenerationEvents } from "../types";
|
|
5
|
+
describe("ProofGateway", () => {
|
|
6
|
+
let gateway;
|
|
7
|
+
const defaultProofGeneratorArgs = {
|
|
8
|
+
poll: 0,
|
|
9
|
+
maciContractAddress: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
10
|
+
tallyContractAddress: "0x6F1216D1BFe15c98520CA1434FC1d9D57AC95321",
|
|
11
|
+
useQuadraticVoting: false,
|
|
12
|
+
encryptedCoordinatorPrivateKey: "siO9W/g7jNVXs9tOUv/pffrcqYdMlgdXw7nSSlqM1q1UvHGSSbhtLJpeT+nJKW7/+xrBTgI0wB866DSkg8Rgr8zD+POUMiKPrGqAO/XhrcmRDL+COURFNDRh9WGeAua6hdiNoufQYvXPl1iWyIYidSDbfmC2wR6F9vVkhg/6KDZyw8Wlr6LUh0RYT+hUHEwwGbz7MeqZJcJQSTpECPF5pnk8NTHL2W/XThaewB4n4HYqjDUbYLmBDLYWsDDMgoPo709a309rTq3uEe0YBgVF8g9aGxucTDhz+/LYYzqaeSxclUwen9Z4BGZjiDSPBZfooOEQEEwIJlViQ2kl1VeOKAmkiWEUVfItivmNbC/PNZchklmfFsGpiu4DT9UU9YVBN2OTcFYHHsslcaqrR7SuesqjluaGjG46oYEmfQlkZ4gXhavdWXw2ant+Tv6HRo4trqjoD1e3jUkN6gJMWomxOeRBTg0czBZlz/IwUtTpBHcKhi3EqGQo8OuQtWww+Ts7ySmeoONuovYUsIAppNuOubfUxvFJoTr2vKbWNAiYetw09kddkjmBe+S8A5PUiFOi262mfc7g5wJwPPP7wpTBY0Fya+2BCPzXqRLMOtNI+1tW3/UQLZYvEY8J0TxmhoAGZaRn8FKaosatRxDZTQS6QUNmKxpmUspkRKzTXN5lznM=",
|
|
13
|
+
};
|
|
14
|
+
const defaultProofGeneratorData = {
|
|
15
|
+
tallyProofs: [],
|
|
16
|
+
processProofs: [],
|
|
17
|
+
tallyData: {},
|
|
18
|
+
};
|
|
19
|
+
const mockGeneratorService = {
|
|
20
|
+
generate: jest.fn(),
|
|
21
|
+
};
|
|
22
|
+
const mockEmit = jest.fn();
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
const testModule = await Test.createTestingModule({ providers: [ProofGateway] })
|
|
25
|
+
.useMocker((token) => {
|
|
26
|
+
if (token === ProofGeneratorService) {
|
|
27
|
+
mockGeneratorService.generate.mockImplementation((_, options) => {
|
|
28
|
+
options?.onBatchComplete?.({ current: 1, total: 2, proofs: defaultProofGeneratorData.processProofs });
|
|
29
|
+
options?.onComplete?.(defaultProofGeneratorData.processProofs.concat(defaultProofGeneratorData.tallyProofs), defaultProofGeneratorData.tallyData);
|
|
30
|
+
options?.onFail?.(new Error("error"));
|
|
31
|
+
});
|
|
32
|
+
return mockGeneratorService;
|
|
33
|
+
}
|
|
34
|
+
return jest.fn();
|
|
35
|
+
})
|
|
36
|
+
.compile();
|
|
37
|
+
gateway = testModule.get(ProofGateway);
|
|
38
|
+
gateway.server = { emit: mockEmit };
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
jest.clearAllMocks();
|
|
42
|
+
});
|
|
43
|
+
test("should be defined", () => {
|
|
44
|
+
expect(gateway).toBeDefined();
|
|
45
|
+
});
|
|
46
|
+
test("should start proof generation properly", async () => {
|
|
47
|
+
await gateway.generate(defaultProofGeneratorArgs);
|
|
48
|
+
expect(mockEmit).toHaveBeenCalledTimes(3);
|
|
49
|
+
expect(mockEmit).toHaveBeenNthCalledWith(1, EProofGenerationEvents.PROGRESS, {
|
|
50
|
+
current: 1,
|
|
51
|
+
total: 2,
|
|
52
|
+
proofs: defaultProofGeneratorData.processProofs,
|
|
53
|
+
});
|
|
54
|
+
expect(mockEmit).toHaveBeenNthCalledWith(2, EProofGenerationEvents.FINISH, {
|
|
55
|
+
proofs: defaultProofGeneratorData.processProofs.concat(defaultProofGeneratorData.tallyProofs),
|
|
56
|
+
tallyData: defaultProofGeneratorData.tallyData,
|
|
57
|
+
});
|
|
58
|
+
expect(mockEmit).toHaveBeenNthCalledWith(3, EProofGenerationEvents.ERROR, { message: "error" });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=proof.gateway.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof.gateway.test.js","sourceRoot":"","sources":["../../../../ts/proof/__tests__/proof.gateway.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAMvC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,IAAI,OAAqB,CAAC;IAE1B,MAAM,yBAAyB,GAAkB;QAC/C,IAAI,EAAE,CAAC;QACP,mBAAmB,EAAE,4CAA4C;QACjE,oBAAoB,EAAE,4CAA4C;QAClE,kBAAkB,EAAE,KAAK;QACzB,8BAA8B,EAC5B,8qBAA8qB;KACjrB,CAAC;IAEF,MAAM,yBAAyB,GAAkB;QAC/C,WAAW,EAAE,EAAE;QACf,aAAa,EAAE,EAAE;QACjB,SAAS,EAAE,EAAgB;KAC5B,CAAC;IAEF,MAAM,oBAAoB,GAAG;QAC3B,QAAQ,E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