@maci-protocol/domainobjs 0.0.0-ci.4c6d4e8 → 0.0.0-ci.4d0e3a3
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 +46 -0
- 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/publicKey.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.PublicKey = exports.SERIALIZED_PUB_KEY_PREFIX = void 0;
|
|
7
7
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
8
|
const assert_1 = __importDefault(require("assert"));
|
|
9
9
|
exports.SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
@@ -15,7 +15,7 @@ exports.SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
|
15
15
|
* A raw MACI public key can be thought as a pair of
|
|
16
16
|
* BigIntegers (x, y) representing a point on the baby jubjub curve
|
|
17
17
|
*/
|
|
18
|
-
class
|
|
18
|
+
class PublicKey {
|
|
19
19
|
/**
|
|
20
20
|
* Create a new instance of a public key
|
|
21
21
|
* @dev You might want to allow an invalid raw key,
|
|
@@ -23,21 +23,21 @@ class PubKey {
|
|
|
23
23
|
* will be random, and likely not be a point on the curve.
|
|
24
24
|
* However we need to match keys to the circuit which does
|
|
25
25
|
* not perform such checks
|
|
26
|
-
* @param
|
|
26
|
+
* @param raw the raw public key
|
|
27
27
|
* @param allowInvalid whether to allow invalid public keys
|
|
28
28
|
*/
|
|
29
|
-
constructor(
|
|
29
|
+
constructor(raw, allowInvalid = false) {
|
|
30
30
|
/**
|
|
31
31
|
* Create a copy of the public key
|
|
32
32
|
* @returns a copy of the public key
|
|
33
33
|
*/
|
|
34
|
-
this.copy = () => new
|
|
34
|
+
this.copy = () => new PublicKey([BigInt(this.raw[0].toString()), BigInt(this.raw[1].toString())]);
|
|
35
35
|
/**
|
|
36
36
|
* Return this public key as smart contract parameters
|
|
37
37
|
* @returns the public key as smart contract parameters
|
|
38
38
|
*/
|
|
39
39
|
this.asContractParam = () => {
|
|
40
|
-
const [x, y] = this.
|
|
40
|
+
const [x, y] = this.raw;
|
|
41
41
|
return {
|
|
42
42
|
x: x.toString(),
|
|
43
43
|
y: y.toString(),
|
|
@@ -47,18 +47,18 @@ class PubKey {
|
|
|
47
47
|
* Return this public key as circuit inputs
|
|
48
48
|
* @returns an array of strings
|
|
49
49
|
*/
|
|
50
|
-
this.asCircuitInputs = () => this.
|
|
50
|
+
this.asCircuitInputs = () => this.raw.map((x) => x.toString());
|
|
51
51
|
/**
|
|
52
52
|
* Return this public key as an array of bigints
|
|
53
53
|
* @returns the public key as an array of bigints
|
|
54
54
|
*/
|
|
55
|
-
this.asArray = () => [this.
|
|
55
|
+
this.asArray = () => [this.raw[0], this.raw[1]];
|
|
56
56
|
/**
|
|
57
57
|
* Generate a serialized public key from this public key object
|
|
58
58
|
* @returns the string representation of a serialized public key
|
|
59
59
|
*/
|
|
60
60
|
this.serialize = () => {
|
|
61
|
-
const packed = (0, crypto_1.
|
|
61
|
+
const packed = (0, crypto_1.packPublicKey)(this.raw).toString(16);
|
|
62
62
|
if (packed.length % 2 !== 0) {
|
|
63
63
|
return `${exports.SERIALIZED_PUB_KEY_PREFIX}0${packed}`;
|
|
64
64
|
}
|
|
@@ -68,70 +68,70 @@ class PubKey {
|
|
|
68
68
|
* Hash the two baby jubjub coordinates
|
|
69
69
|
* @returns the hash of this public key
|
|
70
70
|
*/
|
|
71
|
-
this.hash = () => (0, crypto_1.hashLeftRight)(this.
|
|
71
|
+
this.hash = () => (0, crypto_1.hashLeftRight)(this.raw[0], this.raw[1]);
|
|
72
72
|
/**
|
|
73
73
|
* Check whether this public key equals to another public key
|
|
74
|
-
* @param
|
|
74
|
+
* @param key the public key to compare with
|
|
75
75
|
* @returns whether they match
|
|
76
76
|
*/
|
|
77
|
-
this.equals = (
|
|
77
|
+
this.equals = (key) => this.raw[0] === key.raw[0] && this.raw[1] === key.raw[1];
|
|
78
78
|
if (!allowInvalid) {
|
|
79
|
-
(0, assert_1.default)((0, crypto_1.inCurve)(
|
|
79
|
+
(0, assert_1.default)((0, crypto_1.inCurve)(raw), "PublicKey not on curve");
|
|
80
80
|
}
|
|
81
|
-
this.
|
|
81
|
+
this.raw = raw;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Serialize this object
|
|
85
85
|
*/
|
|
86
86
|
toJSON() {
|
|
87
87
|
return {
|
|
88
|
-
|
|
88
|
+
publicKey: this.serialize(),
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
* Deserialize a JSON object into a
|
|
92
|
+
* Deserialize a JSON object into a PublicKey instance
|
|
93
93
|
* @param json - the json object
|
|
94
|
-
* @returns
|
|
94
|
+
* @returns PublicKey
|
|
95
95
|
*/
|
|
96
96
|
static fromJSON(json) {
|
|
97
|
-
return
|
|
97
|
+
return PublicKey.deserialize(json.publicKey);
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Generate a default
|
|
101
|
-
* @returns a default
|
|
100
|
+
* Generate a default padding key
|
|
101
|
+
* @returns a default padding key
|
|
102
102
|
*/
|
|
103
|
-
static
|
|
103
|
+
static generatePaddingKey() {
|
|
104
104
|
// This public key is the first Pedersen base
|
|
105
105
|
// point from iden3's circomlib implementation of the Pedersen hash.
|
|
106
106
|
// Since it is generated using a hash-to-curve function, we are
|
|
107
107
|
// confident that no-one knows the private key associated with this
|
|
108
108
|
// public key. See:
|
|
109
109
|
// https://github.com/iden3/circomlib/blob/d5ed1c3ce4ca137a6b3ca48bec4ac12c1b38957a/src/pedersen_printbases.js
|
|
110
|
-
return new
|
|
110
|
+
return new PublicKey([
|
|
111
111
|
BigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),
|
|
112
112
|
BigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317"),
|
|
113
113
|
]);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
exports.
|
|
116
|
+
exports.PublicKey = PublicKey;
|
|
117
117
|
/**
|
|
118
118
|
* Deserialize a serialized public key
|
|
119
119
|
* @param s the serialized public key
|
|
120
120
|
* @returns the deserialized public key
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
PublicKey.deserialize = (s) => {
|
|
123
123
|
const len = exports.SERIALIZED_PUB_KEY_PREFIX.length;
|
|
124
|
-
return new
|
|
124
|
+
return new PublicKey((0, crypto_1.unpackPublicKey)(BigInt(`0x${s.slice(len).toString()}`)));
|
|
125
125
|
};
|
|
126
126
|
/**
|
|
127
127
|
* Check whether a serialized public key is serialized correctly
|
|
128
128
|
* @param s the serialized public key
|
|
129
129
|
* @returns whether the serialized public key is valid
|
|
130
130
|
*/
|
|
131
|
-
|
|
131
|
+
PublicKey.isValidSerialized = (s) => {
|
|
132
132
|
const correctPrefix = s.startsWith(exports.SERIALIZED_PUB_KEY_PREFIX);
|
|
133
133
|
try {
|
|
134
|
-
|
|
134
|
+
PublicKey.deserialize(s);
|
|
135
135
|
return correctPrefix;
|
|
136
136
|
}
|
|
137
137
|
catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicKey.js","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"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5DC;;;;GAIG;AACI,qBAAW,GAAG,CAAC,CAAS,EAAa,EAAE;IAC5C,MAAM,GAAG,GAAG,iCAAyB,CAAC,MAAM,CAAC;IAC7C,OAAO,IAAI,SAAS,CAAC,IAAA,wBAAe,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AAChF,CAAC,AAHiB,CAGhB;AAEF;;;;GAIG;AACI,2BAAiB,GAAG,CAAC,CAAS,EAAW,EAAE;IAChD,MAAM,aAAa,GAAG,CAAC,CAAC,UAAU,CAAC,iCAAyB,CAAC,CAAC;IAE9D,IAAI,CAAC;QACH,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACzB,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,AATuB,CAStB"}
|
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/stateLeaf.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"stateLeaf.js","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":";;;AAAA,kDAAkE;AAIlE,uCAAoC;AACpC,2CAAwC;AAExC;;;GAGG;AACH,MAAa,SAAS;IAKpB;;;;OAIG;IACH,YAAY,SAAoB,EAAE,kBAA0B;QA4C5D;;;WAGG;QACK,YAAO,GAAG,GAAa,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAEzF;;;WAGG;QACH,oBAAe,GAAG,GAAa,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAEjD;;;WAGG;QACH,SAAI,GAAG,GAAW,EAAE,CAAC,IAAA,cAAK,EAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAsB3C;;;;;WAKG;QACH,cAAS,GAAG,GAAW,EAAE;YACvB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;YAEhF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAClF,CAAC,CAAC;QA3FA,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,C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AC,qBAAS,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAC/F,CAAC;;AArIH,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;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ACnC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,MAAM,EAAE,YAAY,EAAE,CAAC;IAEvB;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;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,EA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|
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"}
|