@maci-protocol/domainobjs 0.0.0-ci.a577366 → 0.0.0-ci.a73cfa9
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/LICENSE +1 -2
- package/build/ts/ballot.d.ts +8 -7
- package/build/ts/ballot.d.ts.map +1 -1
- package/build/ts/ballot.js +19 -19
- package/build/ts/ballot.js.map +1 -1
- package/build/ts/commands/{PCommand.d.ts → VoteCommand.d.ts} +18 -18
- package/build/ts/commands/VoteCommand.d.ts.map +1 -0
- package/build/ts/commands/{PCommand.js → VoteCommand.js} +30 -30
- package/build/ts/commands/VoteCommand.js.map +1 -0
- package/build/ts/commands/index.d.ts +1 -1
- package/build/ts/commands/index.d.ts.map +1 -1
- package/build/ts/commands/index.js +3 -3
- package/build/ts/commands/index.js.map +1 -1
- package/build/ts/commands/types.d.ts +1 -1
- package/build/ts/commands/types.d.ts.map +1 -1
- package/build/ts/constants.d.ts +2 -2
- package/build/ts/constants.d.ts.map +1 -1
- package/build/ts/constants.js +2 -2
- package/build/ts/constants.js.map +1 -1
- package/build/ts/index.d.ts +5 -4
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +7 -5
- package/build/ts/index.js.map +1 -1
- package/build/ts/keyPair.d.ts +11 -11
- package/build/ts/keyPair.d.ts.map +1 -1
- package/build/ts/keyPair.js +21 -22
- package/build/ts/keyPair.js.map +1 -1
- package/build/ts/message.d.ts +3 -3
- package/build/ts/message.d.ts.map +1 -1
- package/build/ts/message.js +2 -2
- package/build/ts/message.js.map +1 -1
- package/build/ts/privateKey.d.ts +12 -12
- package/build/ts/privateKey.d.ts.map +1 -1
- package/build/ts/privateKey.js +20 -20
- package/build/ts/privateKey.js.map +1 -1
- package/build/ts/publicKey.d.ts +16 -16
- package/build/ts/publicKey.d.ts.map +1 -1
- package/build/ts/publicKey.js +27 -27
- package/build/ts/publicKey.js.map +1 -1
- package/build/ts/stateLeaf.d.ts +6 -6
- package/build/ts/stateLeaf.d.ts.map +1 -1
- package/build/ts/stateLeaf.js +15 -15
- package/build/ts/stateLeaf.js.map +1 -1
- package/build/ts/types.d.ts +27 -10
- package/build/ts/types.d.ts.map +1 -1
- package/build/ts/verifyingKey.d.ts +7 -7
- package/build/ts/verifyingKey.d.ts.map +1 -1
- package/build/ts/verifyingKey.js +9 -9
- package/build/ts/verifyingKey.js.map +1 -1
- package/build/ts/voteCounts.d.ts +63 -0
- package/build/ts/voteCounts.d.ts.map +1 -0
- package/build/ts/voteCounts.js +110 -0
- package/build/ts/voteCounts.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/build/ts/commands/PCommand.d.ts.map +0 -1
- package/build/ts/commands/PCommand.js.map +0 -1
package/build/ts/stateLeaf.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { IJsonStateLeaf, IStateLeaf, IStateLeafContractParams } from "./types";
|
|
2
|
-
import {
|
|
2
|
+
import { PublicKey } from "./publicKey";
|
|
3
3
|
/**
|
|
4
4
|
* @notice A leaf in the state tree, which maps
|
|
5
5
|
* public keys to voice credit balances
|
|
6
6
|
*/
|
|
7
7
|
export declare class StateLeaf implements IStateLeaf {
|
|
8
|
-
|
|
8
|
+
publicKey: PublicKey;
|
|
9
9
|
voiceCreditBalance: bigint;
|
|
10
10
|
/**
|
|
11
11
|
* Create a new instance of a state leaf
|
|
12
|
-
* @param
|
|
12
|
+
* @param publicKey the public key of the user signin up
|
|
13
13
|
* @param voiceCreditBalance the voice credit balance of the user
|
|
14
14
|
*/
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(publicKey: PublicKey, voiceCreditBalance: bigint);
|
|
16
16
|
/**
|
|
17
17
|
* Crate a deep copy of the object
|
|
18
18
|
* @returns a copy of the state leaf
|
|
@@ -22,12 +22,12 @@ export declare class StateLeaf implements IStateLeaf {
|
|
|
22
22
|
* Generate a blank state leaf
|
|
23
23
|
* @returns a blank state leaf
|
|
24
24
|
*/
|
|
25
|
-
static
|
|
25
|
+
static generateBlank(): StateLeaf;
|
|
26
26
|
/**
|
|
27
27
|
* Generate a random leaf (random salt and random key pair)
|
|
28
28
|
* @returns a random state leaf
|
|
29
29
|
*/
|
|
30
|
-
static
|
|
30
|
+
static generateRandom(): StateLeaf;
|
|
31
31
|
/**
|
|
32
32
|
* Return this state leaf as an array of bigints
|
|
33
33
|
* @returns the state leaf as an array of bigints
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateLeaf.d.ts","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGpF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stateLeaf.d.ts","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGpF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;GAGG;AACH,qBAAa,SAAU,YAAW,UAAU;IAC1C,SAAS,EAAE,SAAS,CAAC;IAErB,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;;;OAIG;gBACS,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM;IAK5D;;;OAGG;IACH,IAAI,IAAI,SAAS;IAIjB;;;OAGG;IACH,MAAM,CAAC,aAAa,IAAI,SAAS;IAkBjC;;;OAGG;IACH,MAAM,CAAC,cAAc,IAAI,SAAS;IAKlC;;;OAGG;IACH,OAAO,CAAC,OAAO,CAA0E;IAEzF;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAmB;IAEjD;;;OAGG;IACH,IAAI,QAAO,MAAM,CAA0B;IAE3C;;;OAGG;IACH,eAAe,IAAI,wBAAwB;IAO3C;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO;IAIhC;;;;;OAKG;IACH,SAAS,QAAO,MAAM,CAIpB;IAEF;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,YAAY,MAAM,KAAG,SAAS,CAKlD;IAEF;;OAEG;IACH,MAAM,IAAI,cAAc;IAOxB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS;CAGjD"}
|
package/build/ts/stateLeaf.js
CHANGED
|
@@ -11,15 +11,15 @@ const publicKey_1 = require("./publicKey");
|
|
|
11
11
|
class StateLeaf {
|
|
12
12
|
/**
|
|
13
13
|
* Create a new instance of a state leaf
|
|
14
|
-
* @param
|
|
14
|
+
* @param publicKey the public key of the user signin up
|
|
15
15
|
* @param voiceCreditBalance the voice credit balance of the user
|
|
16
16
|
*/
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(publicKey, voiceCreditBalance) {
|
|
18
18
|
/**
|
|
19
19
|
* Return this state leaf as an array of bigints
|
|
20
20
|
* @returns the state leaf as an array of bigints
|
|
21
21
|
*/
|
|
22
|
-
this.asArray = () => [...this.
|
|
22
|
+
this.asArray = () => [...this.publicKey.asArray(), this.voiceCreditBalance];
|
|
23
23
|
/**
|
|
24
24
|
* Return this state leaf as an array of bigints
|
|
25
25
|
* @returns the state leaf as an array of bigints
|
|
@@ -37,10 +37,10 @@ class StateLeaf {
|
|
|
37
37
|
* @returns
|
|
38
38
|
*/
|
|
39
39
|
this.serialize = () => {
|
|
40
|
-
const data = [this.
|
|
40
|
+
const data = [this.publicKey.serialize(), this.voiceCreditBalance.toString(16)];
|
|
41
41
|
return Buffer.from(JSON.stringify(data, null, 0), "utf8").toString("base64url");
|
|
42
42
|
};
|
|
43
|
-
this.
|
|
43
|
+
this.publicKey = publicKey;
|
|
44
44
|
this.voiceCreditBalance = voiceCreditBalance;
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -48,13 +48,13 @@ class StateLeaf {
|
|
|
48
48
|
* @returns a copy of the state leaf
|
|
49
49
|
*/
|
|
50
50
|
copy() {
|
|
51
|
-
return new StateLeaf(this.
|
|
51
|
+
return new StateLeaf(this.publicKey.copy(), BigInt(this.voiceCreditBalance.toString()));
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Generate a blank state leaf
|
|
55
55
|
* @returns a blank state leaf
|
|
56
56
|
*/
|
|
57
|
-
static
|
|
57
|
+
static generateBlank() {
|
|
58
58
|
// The public key for a blank state leaf is the first Pedersen base
|
|
59
59
|
// point from iden3's circomlib implementation of the Pedersen hash.
|
|
60
60
|
// Since it is generated using a hash-to-curve function, we are
|
|
@@ -63,7 +63,7 @@ class StateLeaf {
|
|
|
63
63
|
// https://github.com/iden3/circomlib/blob/d5ed1c3ce4ca137a6b3ca48bec4ac12c1b38957a/src/pedersen_printbases.js
|
|
64
64
|
// Its hash should equal
|
|
65
65
|
// 11672248758340751985123309654953904206381780234474872690580702076708041504880.
|
|
66
|
-
return new StateLeaf(new publicKey_1.
|
|
66
|
+
return new StateLeaf(new publicKey_1.PublicKey([
|
|
67
67
|
BigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),
|
|
68
68
|
BigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317"),
|
|
69
69
|
]), BigInt(0));
|
|
@@ -72,9 +72,9 @@ class StateLeaf {
|
|
|
72
72
|
* Generate a random leaf (random salt and random key pair)
|
|
73
73
|
* @returns a random state leaf
|
|
74
74
|
*/
|
|
75
|
-
static
|
|
75
|
+
static generateRandom() {
|
|
76
76
|
const keypair = new keyPair_1.Keypair();
|
|
77
|
-
return new StateLeaf(keypair.
|
|
77
|
+
return new StateLeaf(keypair.publicKey, (0, crypto_1.generateRandomSalt)());
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Return this state leaf as a contract param
|
|
@@ -82,7 +82,7 @@ class StateLeaf {
|
|
|
82
82
|
*/
|
|
83
83
|
asContractParam() {
|
|
84
84
|
return {
|
|
85
|
-
|
|
85
|
+
publicKey: this.publicKey.asContractParam(),
|
|
86
86
|
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
87
87
|
};
|
|
88
88
|
}
|
|
@@ -92,14 +92,14 @@ class StateLeaf {
|
|
|
92
92
|
* @returns whether they are equal or not
|
|
93
93
|
*/
|
|
94
94
|
equals(leaf) {
|
|
95
|
-
return this.
|
|
95
|
+
return this.publicKey.equals(leaf.publicKey) && this.voiceCreditBalance === leaf.voiceCreditBalance;
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
98
98
|
* Serialize to a JSON object
|
|
99
99
|
*/
|
|
100
100
|
toJSON() {
|
|
101
101
|
return {
|
|
102
|
-
|
|
102
|
+
publicKey: this.publicKey.serialize(),
|
|
103
103
|
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
104
104
|
};
|
|
105
105
|
}
|
|
@@ -109,7 +109,7 @@ class StateLeaf {
|
|
|
109
109
|
* @returns the deserialized object as a StateLeaf instance
|
|
110
110
|
*/
|
|
111
111
|
static fromJSON(json) {
|
|
112
|
-
return new StateLeaf(publicKey_1.
|
|
112
|
+
return new StateLeaf(publicKey_1.PublicKey.deserialize(json.publicKey), BigInt(json.voiceCreditBalance));
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
exports.StateLeaf = StateLeaf;
|
|
@@ -121,6 +121,6 @@ exports.StateLeaf = StateLeaf;
|
|
|
121
121
|
StateLeaf.deserialize = (serialized) => {
|
|
122
122
|
const base64 = serialized.replace(/-/g, "+").replace(/_/g, "/");
|
|
123
123
|
const json = JSON.parse(Buffer.from(base64, "base64").toString("utf8"));
|
|
124
|
-
return new StateLeaf(publicKey_1.
|
|
124
|
+
return new StateLeaf(publicKey_1.PublicKey.deserialize(json[0]), BigInt(`0x${json[1]}`));
|
|
125
125
|
};
|
|
126
126
|
//# sourceMappingURL=stateLeaf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateLeaf.js","sourceRoot":"","sources":["../../ts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H,8BAsIC;AA9BC;;;;GAIG;AACI,qBAAW,GAAG,CAAC,UAAkB,EAAa,EAAE;IACrD,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAqB,CAAC;IAE5F,OAAO,IAAI,SAAS,CAAC,qBAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC,AALiB,CAKhB"}
|
package/build/ts/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PublicKey } from "./publicKey";
|
|
2
2
|
import type { G1Point, G2Point } from "@maci-protocol/crypto";
|
|
3
3
|
/**
|
|
4
4
|
* @notice An interface representing a zk-SNARK proof
|
|
@@ -12,7 +12,7 @@ export interface Proof {
|
|
|
12
12
|
* @notice An interface representing a MACI state leaf
|
|
13
13
|
*/
|
|
14
14
|
export interface IStateLeaf {
|
|
15
|
-
|
|
15
|
+
publicKey: PublicKey;
|
|
16
16
|
voiceCreditBalance: bigint;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
@@ -22,13 +22,13 @@ export interface VoteOptionTreeLeaf {
|
|
|
22
22
|
votes: bigint;
|
|
23
23
|
}
|
|
24
24
|
export interface IJsonKeyPair {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
privateKey: string;
|
|
26
|
+
publicKey: string;
|
|
27
27
|
}
|
|
28
|
-
export type IJsonPrivateKey = Pick<IJsonKeyPair, "
|
|
29
|
-
export type IJsonPublicKey = Pick<IJsonKeyPair, "
|
|
28
|
+
export type IJsonPrivateKey = Pick<IJsonKeyPair, "privateKey">;
|
|
29
|
+
export type IJsonPublicKey = Pick<IJsonKeyPair, "publicKey">;
|
|
30
30
|
export interface IJsonStateLeaf {
|
|
31
|
-
|
|
31
|
+
publicKey: string;
|
|
32
32
|
voiceCreditBalance: string;
|
|
33
33
|
}
|
|
34
34
|
export type BigNumberish = number | string | bigint;
|
|
@@ -40,14 +40,14 @@ export interface IG2ContractParams {
|
|
|
40
40
|
x: BigNumberish[];
|
|
41
41
|
y: BigNumberish[];
|
|
42
42
|
}
|
|
43
|
-
export interface
|
|
43
|
+
export interface IVerifyingKeyContractParams {
|
|
44
44
|
alpha1: IG1ContractParams;
|
|
45
45
|
beta2: IG2ContractParams;
|
|
46
46
|
gamma2: IG2ContractParams;
|
|
47
47
|
delta2: IG2ContractParams;
|
|
48
48
|
ic: IG1ContractParams[];
|
|
49
49
|
}
|
|
50
|
-
export interface
|
|
50
|
+
export interface IVerifyingKeyObjectParams {
|
|
51
51
|
protocol: BigNumberish;
|
|
52
52
|
curve: BigNumberish;
|
|
53
53
|
nPublic: BigNumberish;
|
|
@@ -59,7 +59,7 @@ export interface IVkObjectParams {
|
|
|
59
59
|
IC: BigNumberish[][];
|
|
60
60
|
}
|
|
61
61
|
export interface IStateLeafContractParams {
|
|
62
|
-
|
|
62
|
+
publicKey: IG1ContractParams;
|
|
63
63
|
voiceCreditBalance: BigNumberish;
|
|
64
64
|
}
|
|
65
65
|
export interface IMessageContractParams {
|
|
@@ -70,4 +70,21 @@ export interface IJsonBallot {
|
|
|
70
70
|
nonce: BigNumberish;
|
|
71
71
|
voteOptionTreeDepth: BigNumberish;
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* A JSON representation of the vote counts
|
|
75
|
+
*/
|
|
76
|
+
export interface IJsonVoteCounts {
|
|
77
|
+
/**
|
|
78
|
+
* The vote counts for each vote option in the poll
|
|
79
|
+
*/
|
|
80
|
+
counts: BigNumberish[];
|
|
81
|
+
/**
|
|
82
|
+
* The nonce for the vote counts
|
|
83
|
+
*/
|
|
84
|
+
nonce: BigNumberish;
|
|
85
|
+
/**
|
|
86
|
+
* The depth of the merkle tree holding the vote options
|
|
87
|
+
*/
|
|
88
|
+
voteOptionTreeDepth: BigNumberish;
|
|
89
|
+
}
|
|
73
90
|
//# sourceMappingURL=types.d.ts.map
|
package/build/ts/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../ts/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;IACX,CAAC,EAAE,OAAO,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,SAAS,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;AAE7D,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,YAAY,GAAG,MA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AAC;IAEpB;;OAEG;IACH,mBAAmB,EAAE,YAAY,CAAC;CACnC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { G1Point, G2Point } from "@maci-protocol/crypto";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IVerifyingKeyContractParams, IVerifyingKeyObjectParams } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* @notice A TS Class representing a zk-SNARK VerifyingKey
|
|
5
5
|
*/
|
|
@@ -23,19 +23,19 @@ export declare class VerifyingKey {
|
|
|
23
23
|
* to the smart contract
|
|
24
24
|
* @returns the object representation of this
|
|
25
25
|
*/
|
|
26
|
-
asContractParam():
|
|
26
|
+
asContractParam(): IVerifyingKeyContractParams;
|
|
27
27
|
/**
|
|
28
|
-
* Create a new verifying key from a contract representation of the
|
|
28
|
+
* Create a new verifying key from a contract representation of the verifying key
|
|
29
29
|
* @param data the object representation
|
|
30
30
|
* @returns a new VerifyingKey
|
|
31
31
|
*/
|
|
32
|
-
static fromContract(data:
|
|
32
|
+
static fromContract(data: IVerifyingKeyContractParams): VerifyingKey;
|
|
33
33
|
/**
|
|
34
34
|
* Check whether this is equal to another verifying key
|
|
35
|
-
* @param
|
|
35
|
+
* @param verifyingKey the other verifying key
|
|
36
36
|
* @returns whether this is equal to the other verifying key
|
|
37
37
|
*/
|
|
38
|
-
equals(
|
|
38
|
+
equals(verifyingKey: VerifyingKey): boolean;
|
|
39
39
|
/**
|
|
40
40
|
* Produce a copy of this verifying key
|
|
41
41
|
* @returns the copy
|
|
@@ -52,6 +52,6 @@ export declare class VerifyingKey {
|
|
|
52
52
|
* @param data the object representation
|
|
53
53
|
* @returns the VerifyingKey
|
|
54
54
|
*/
|
|
55
|
-
static fromObj: (data:
|
|
55
|
+
static fromObj: (data: IVerifyingKeyObjectParams) => VerifyingKey;
|
|
56
56
|
}
|
|
57
57
|
//# sourceMappingURL=verifyingKey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyingKey.d.ts","sourceRoot":"","sources":["../../ts/verifyingKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"verifyingKey.d.ts","sourceRoot":"","sources":["../../ts/verifyingKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEtF;;GAEG;AACH,qBAAa,YAAY;IACvB,MAAM,EAAE,OAAO,CAAC;IAEhB,KAAK,EAAE,OAAO,CAAC;IAEf,MAAM,EAAE,OAAO,CAAC;IAEhB,MAAM,EAAE,OAAO,CAAC;IAEhB,EAAE,EAAE,OAAO,EAAE,CAAC;IAEd;;;;;;;OAOG;gBACS,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE;IAQ5F;;;;OAIG;IACH,eAAe,IAAI,2BAA2B;IAU9C;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,2BAA2B,GAAG,YAAY;IAapE;;;;OAIG;IACH,MAAM,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO;IAiB3C;;;OAGG;IACH,IAAI,IAAI,YAAY;IAgBpB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,GAAI,MAAM,MAAM,KAAG,YAAY,CAG5C;IAEF;;;;OAIG;IACH,MAAM,CAAC,OAAO,GAAI,MAAM,yBAAyB,KAAG,YAAY,CAiB9D;CACH"}
|
package/build/ts/verifyingKey.js
CHANGED
|
@@ -36,7 +36,7 @@ class VerifyingKey {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* Create a new verifying key from a contract representation of the
|
|
39
|
+
* Create a new verifying key from a contract representation of the verifying key
|
|
40
40
|
* @param data the object representation
|
|
41
41
|
* @returns a new VerifyingKey
|
|
42
42
|
*/
|
|
@@ -46,19 +46,19 @@ class VerifyingKey {
|
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Check whether this is equal to another verifying key
|
|
49
|
-
* @param
|
|
49
|
+
* @param verifyingKey the other verifying key
|
|
50
50
|
* @returns whether this is equal to the other verifying key
|
|
51
51
|
*/
|
|
52
|
-
equals(
|
|
52
|
+
equals(verifyingKey) {
|
|
53
53
|
// Immediately return false if the length doesn't match
|
|
54
|
-
if (this.ic.length !==
|
|
54
|
+
if (this.ic.length !== verifyingKey.ic.length) {
|
|
55
55
|
return false;
|
|
56
56
|
}
|
|
57
|
-
const icEqual = this.ic.every((ic, index) => ic.equals(
|
|
58
|
-
return (this.alpha1.equals(
|
|
59
|
-
this.beta2.equals(
|
|
60
|
-
this.gamma2.equals(
|
|
61
|
-
this.delta2.equals(
|
|
57
|
+
const icEqual = this.ic.every((ic, index) => ic.equals(verifyingKey.ic[index]));
|
|
58
|
+
return (this.alpha1.equals(verifyingKey.alpha1) &&
|
|
59
|
+
this.beta2.equals(verifyingKey.beta2) &&
|
|
60
|
+
this.gamma2.equals(verifyingKey.gamma2) &&
|
|
61
|
+
this.delta2.equals(verifyingKey.delta2) &&
|
|
62
62
|
icEqual);
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyingKey.js","sourceRoot":"","sources":["../../ts/verifyingKey.ts"],"names":[],"mappings":";;;AAAA,kDAAyD;AAIzD;;GAEG;AACH,MAAa,YAAY;IAWvB;;;;;;;OAOG;IACH,YAAY,MAAe,EAAE,KAAc,EAAE,MAAe,EAAE,MAAe,EAAE,EAAa;QAC1F,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IA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E,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC9D,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC/D,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,gBAAO,CACxB,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC9D,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC/D,CAAC;IACF,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtE,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;AAC7D,CAAC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { IJsonVoteCounts } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A VoteCounts represents a User's vote counts in a Poll, as well as their next valid
|
|
4
|
+
* nonce.
|
|
5
|
+
*/
|
|
6
|
+
export declare class VoteCounts {
|
|
7
|
+
counts: bigint[];
|
|
8
|
+
nonce: bigint;
|
|
9
|
+
voteOptionTreeDepth: number;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new VoteCounts instance
|
|
12
|
+
* @param totalVoteOptions How many vote options are available in the poll
|
|
13
|
+
* @param voteOptionTreeDepth The depth of the merkle tree holding the vote options
|
|
14
|
+
*/
|
|
15
|
+
constructor(totalVoteOptions: number, voteOptionTreeDepth: number);
|
|
16
|
+
/**
|
|
17
|
+
* Generate a blank VoteCounts object
|
|
18
|
+
* @param totalVoteOptions How many vote options are available
|
|
19
|
+
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
20
|
+
* @returns a Blank VoteCounts object
|
|
21
|
+
*/
|
|
22
|
+
static generateBlank(totalVoteOptions: number, voteOptionTreeDepth: number): VoteCounts;
|
|
23
|
+
/**
|
|
24
|
+
* Generate an hash of this vote counts
|
|
25
|
+
* @returns The hash of the vote counts
|
|
26
|
+
*/
|
|
27
|
+
hash: () => bigint;
|
|
28
|
+
/**
|
|
29
|
+
* Convert in a format suitable for the circuit
|
|
30
|
+
* @returns the vote counts as a BigInt array
|
|
31
|
+
*/
|
|
32
|
+
asCircuitInputs: () => bigint[];
|
|
33
|
+
/**
|
|
34
|
+
* Convert in a an array of bigints
|
|
35
|
+
* @notice this is the nonce and the root of the vote option tree
|
|
36
|
+
* @returns the vote counts as a bigint array
|
|
37
|
+
*/
|
|
38
|
+
asArray: () => bigint[];
|
|
39
|
+
/**
|
|
40
|
+
* Create a deep clone of this VoteCounts
|
|
41
|
+
* @returns a copy of the vote counts
|
|
42
|
+
*/
|
|
43
|
+
copy: () => VoteCounts;
|
|
44
|
+
/**
|
|
45
|
+
* Check if two vote counts are equal (same counts and same nonce)
|
|
46
|
+
* @param voteCounts - The vote counts to compare with
|
|
47
|
+
* @returns whether the two vote counts are equal
|
|
48
|
+
*/
|
|
49
|
+
equals(voteCounts: VoteCounts): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Serialize to a JSON object
|
|
52
|
+
*
|
|
53
|
+
* @returns the JSON representation of the vote counts
|
|
54
|
+
*/
|
|
55
|
+
toJSON(): IJsonVoteCounts;
|
|
56
|
+
/**
|
|
57
|
+
* Deserialize into a VoteCounts instance
|
|
58
|
+
* @param json - the json representation
|
|
59
|
+
* @returns the deserialized object as a VoteCounts instance
|
|
60
|
+
*/
|
|
61
|
+
static fromJSON(json: IJsonVoteCounts): VoteCounts;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=voteCounts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voteCounts.d.ts","sourceRoot":"","sources":["../../ts/voteCounts.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;GAGG;AACH,qBAAa,UAAU;IACrB,MAAM,EAAE,MAAM,EAAE,CAAM;IAEtB,KAAK,SAAM;IAEX,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;gBACS,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM;IAWjE;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,UAAU;IAIvF;;;OAGG;IACH,IAAI,QAAO,MAAM,CAIf;IAEF;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAmB;IAEjD;;;;OAIG;IACH,OAAO,QAAO,MAAM,EAAE,CAWpB;IAEF;;;OAGG;IACH,IAAI,QAAO,UAAU,CAOnB;IAEF;;;;OAIG;IACH,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO;IAMvC;;;;OAIG;IACH,MAAM,IAAI,eAAe;IAQzB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU;CAOnD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.VoteCounts = void 0;
|
|
7
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
/**
|
|
10
|
+
* A VoteCounts represents a User's vote counts in a Poll, as well as their next valid
|
|
11
|
+
* nonce.
|
|
12
|
+
*/
|
|
13
|
+
class VoteCounts {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new VoteCounts instance
|
|
16
|
+
* @param totalVoteOptions How many vote options are available in the poll
|
|
17
|
+
* @param voteOptionTreeDepth The depth of the merkle tree holding the vote options
|
|
18
|
+
*/
|
|
19
|
+
constructor(totalVoteOptions, voteOptionTreeDepth) {
|
|
20
|
+
this.counts = [];
|
|
21
|
+
this.nonce = 0n;
|
|
22
|
+
/**
|
|
23
|
+
* Generate an hash of this vote counts
|
|
24
|
+
* @returns The hash of the vote counts
|
|
25
|
+
*/
|
|
26
|
+
this.hash = () => {
|
|
27
|
+
const [nonce, root] = this.asArray();
|
|
28
|
+
return (0, crypto_1.hashLeftRight)(nonce, root);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Convert in a format suitable for the circuit
|
|
32
|
+
* @returns the vote counts as a BigInt array
|
|
33
|
+
*/
|
|
34
|
+
this.asCircuitInputs = () => this.asArray();
|
|
35
|
+
/**
|
|
36
|
+
* Convert in a an array of bigints
|
|
37
|
+
* @notice this is the nonce and the root of the vote option tree
|
|
38
|
+
* @returns the vote counts as a bigint array
|
|
39
|
+
*/
|
|
40
|
+
this.asArray = () => {
|
|
41
|
+
const lastIndex = this.counts.length - 1;
|
|
42
|
+
const foundIndex = this.counts.findIndex((_, index) => this.counts[lastIndex - index] !== 0n);
|
|
43
|
+
const lastIndexToInsert = foundIndex >= 0 ? lastIndex - foundIndex : -1;
|
|
44
|
+
const voteCountsTree = new crypto_1.IncrementalQuinTree(this.voteOptionTreeDepth, 0n, 5, crypto_1.hash5);
|
|
45
|
+
for (let i = 0; i <= lastIndexToInsert; i += 1) {
|
|
46
|
+
voteCountsTree.insert(this.counts[i]);
|
|
47
|
+
}
|
|
48
|
+
return [this.nonce, voteCountsTree.root];
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Create a deep clone of this VoteCounts
|
|
52
|
+
* @returns a copy of the vote counts
|
|
53
|
+
*/
|
|
54
|
+
this.copy = () => {
|
|
55
|
+
const voteCounts = new VoteCounts(this.counts.length, this.voteOptionTreeDepth);
|
|
56
|
+
voteCounts.counts = this.counts.map((x) => BigInt(x.toString()));
|
|
57
|
+
voteCounts.nonce = BigInt(this.nonce.toString());
|
|
58
|
+
return voteCounts;
|
|
59
|
+
};
|
|
60
|
+
(0, assert_1.default)(5 ** voteOptionTreeDepth >= totalVoteOptions);
|
|
61
|
+
(0, assert_1.default)(totalVoteOptions >= 0);
|
|
62
|
+
this.voteOptionTreeDepth = voteOptionTreeDepth;
|
|
63
|
+
for (let i = 0; i < totalVoteOptions; i += 1) {
|
|
64
|
+
this.counts.push(0n);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate a blank VoteCounts object
|
|
69
|
+
* @param totalVoteOptions How many vote options are available
|
|
70
|
+
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
71
|
+
* @returns a Blank VoteCounts object
|
|
72
|
+
*/
|
|
73
|
+
static generateBlank(totalVoteOptions, voteOptionTreeDepth) {
|
|
74
|
+
return new VoteCounts(totalVoteOptions, voteOptionTreeDepth);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check if two vote counts are equal (same counts and same nonce)
|
|
78
|
+
* @param voteCounts - The vote counts to compare with
|
|
79
|
+
* @returns whether the two vote counts are equal
|
|
80
|
+
*/
|
|
81
|
+
equals(voteCounts) {
|
|
82
|
+
const isEqualVotes = this.counts.every((vote, index) => vote === voteCounts.counts[index]);
|
|
83
|
+
return isEqualVotes ? voteCounts.nonce === this.nonce && this.counts.length === voteCounts.counts.length : false;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Serialize to a JSON object
|
|
87
|
+
*
|
|
88
|
+
* @returns the JSON representation of the vote counts
|
|
89
|
+
*/
|
|
90
|
+
toJSON() {
|
|
91
|
+
return {
|
|
92
|
+
counts: this.counts.map((x) => x.toString()),
|
|
93
|
+
nonce: this.nonce.toString(),
|
|
94
|
+
voteOptionTreeDepth: this.voteOptionTreeDepth.toString(),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Deserialize into a VoteCounts instance
|
|
99
|
+
* @param json - the json representation
|
|
100
|
+
* @returns the deserialized object as a VoteCounts instance
|
|
101
|
+
*/
|
|
102
|
+
static fromJSON(json) {
|
|
103
|
+
const voteCounts = new VoteCounts(json.counts.length, Number.parseInt(json.voteOptionTreeDepth.toString(), 10));
|
|
104
|
+
voteCounts.counts = json.counts.map((x) => BigInt(x));
|
|
105
|
+
voteCounts.nonce = BigInt(json.nonce);
|
|
106
|
+
return voteCounts;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.VoteCounts = VoteCounts;
|
|
110
|
+
//# sourceMappingURL=voteCounts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voteCounts.js","sourceRoot":"","sources":["../../ts/voteCounts.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAkF;AAElF,oDAA4B;AAI5B;;;GAGG;AACH,MAAa,UAAU;IAOrB;;;;OAIG;IACH,YAAY,gBAAwB,EAAE,mBAA2B;QAXjE,WAAM,GAAa,EAAE,CAAC;QAEtB,UAAK,GAAG,EAAE,CAAC;QA8BX;;;WAGG;QACH,SAAI,GAAG,GAAW,EAAE;YAClB,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAErC,OAAO,IAAA,sBAAa,EAAC,KAAK,EAAE,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