@maci-protocol/domainobjs 0.0.0-ci.f4bc8a6 → 0.0.0-ci.f94d0a4
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/build/ts/commands/PCommand.d.ts +7 -7
- package/build/ts/commands/PCommand.d.ts.map +1 -1
- package/build/ts/commands/PCommand.js +13 -13
- package/build/ts/commands/PCommand.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 +1 -1
- package/build/ts/constants.js.map +1 -1
- package/build/ts/index.d.ts +2 -2
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +3 -3
- package/build/ts/index.js.map +1 -1
- package/build/ts/keyPair.d.ts +10 -10
- package/build/ts/keyPair.d.ts.map +1 -1
- package/build/ts/keyPair.js +19 -19
- 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 +7 -7
- package/build/ts/privateKey.d.ts.map +1 -1
- package/build/ts/privateKey.js +11 -11
- package/build/ts/privateKey.js.map +1 -1
- package/build/ts/publicKey.d.ts +9 -9
- package/build/ts/publicKey.d.ts.map +1 -1
- package/build/ts/publicKey.js +14 -14
- package/build/ts/publicKey.js.map +1 -1
- package/build/ts/stateLeaf.d.ts +7 -9
- package/build/ts/stateLeaf.d.ts.map +1 -1
- package/build/ts/stateLeaf.js +20 -24
- package/build/ts/stateLeaf.js.map +1 -1
- package/build/ts/types.d.ts +8 -10
- package/build/ts/types.d.ts.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
package/build/ts/publicKey.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PublicKey as RawPubKey } from "@maci-protocol/crypto";
|
|
2
2
|
import type { IJsonPublicKey, IG1ContractParams } from "./types";
|
|
3
3
|
export declare const SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
4
4
|
/**
|
|
@@ -9,7 +9,7 @@ export declare const SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
|
9
9
|
* A raw MACI public key can be thought as a pair of
|
|
10
10
|
* BigIntegers (x, y) representing a point on the baby jubjub curve
|
|
11
11
|
*/
|
|
12
|
-
export declare class
|
|
12
|
+
export declare class PublicKey {
|
|
13
13
|
rawPubKey: RawPubKey;
|
|
14
14
|
/**
|
|
15
15
|
* Create a new instance of a public key
|
|
@@ -26,7 +26,7 @@ export declare class PubKey {
|
|
|
26
26
|
* Create a copy of the public key
|
|
27
27
|
* @returns a copy of the public key
|
|
28
28
|
*/
|
|
29
|
-
copy: () =>
|
|
29
|
+
copy: () => PublicKey;
|
|
30
30
|
/**
|
|
31
31
|
* Return this public key as smart contract parameters
|
|
32
32
|
* @returns the public key as smart contract parameters
|
|
@@ -57,13 +57,13 @@ export declare class PubKey {
|
|
|
57
57
|
* @param p the public key to compare with
|
|
58
58
|
* @returns whether they match
|
|
59
59
|
*/
|
|
60
|
-
equals: (p:
|
|
60
|
+
equals: (p: PublicKey) => boolean;
|
|
61
61
|
/**
|
|
62
62
|
* Deserialize a serialized public key
|
|
63
63
|
* @param s the serialized public key
|
|
64
64
|
* @returns the deserialized public key
|
|
65
65
|
*/
|
|
66
|
-
static deserialize: (s: string) =>
|
|
66
|
+
static deserialize: (s: string) => PublicKey;
|
|
67
67
|
/**
|
|
68
68
|
* Check whether a serialized public key is serialized correctly
|
|
69
69
|
* @param s the serialized public key
|
|
@@ -75,15 +75,15 @@ export declare class PubKey {
|
|
|
75
75
|
*/
|
|
76
76
|
toJSON(): IJsonPublicKey;
|
|
77
77
|
/**
|
|
78
|
-
* Deserialize a JSON object into a
|
|
78
|
+
* Deserialize a JSON object into a PublicKey instance
|
|
79
79
|
* @param json - the json object
|
|
80
|
-
* @returns
|
|
80
|
+
* @returns PublicKey
|
|
81
81
|
*/
|
|
82
|
-
static fromJSON(json: IJsonPublicKey):
|
|
82
|
+
static fromJSON(json: IJsonPublicKey): PublicKey;
|
|
83
83
|
/**
|
|
84
84
|
* Generate a default pad key
|
|
85
85
|
* @returns a default pad key
|
|
86
86
|
*/
|
|
87
|
-
static genPadKey():
|
|
87
|
+
static genPadKey(): PublicKey;
|
|
88
88
|
}
|
|
89
89
|
//# sourceMappingURL=publicKey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicKey.d.ts","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,
|
|
1
|
+
{"version":3,"file":"publicKey.d.ts","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,SAAS,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAItH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;;;;;OASG;gBACS,SAAS,EAAE,SAAS,EAAE,YAAY,UAAQ;IAOtD;;;OAGG;IACH,IAAI,QAAO,SAAS,CAAgG;IAEpH;;;OAGG;IACH,eAAe,QAAO,iBAAiB,CAOrC;IAEF;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAA4C;IAE1E;;;OAGG;IACH,OAAO,QAAO,MAAM,EAAE,CAA2C;IAEjE;;;OAGG;IACH,SAAS,QAAO,MAAM,CAQpB;IAEF;;;OAGG;IACH,IAAI,QAAO,MAAM,CAAwD;IAEzE;;;;OAIG;IACH,MAAM,GAAI,GAAG,SAAS,KAAG,OAAO,CAAiF;IAEjH;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,GAAG,MAAM,KAAG,SAAS,CAGzC;IAEF;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,GAAI,GAAG,MAAM,KAAG,OAAO,CASnD;IAEF;;OAEG;IACH,MAAM,IAAI,cAAc;IAMxB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS;IAIhD;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,SAAS;CAY9B"}
|
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,
|
|
@@ -31,7 +31,7 @@ class PubKey {
|
|
|
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.rawPubKey[0].toString()), BigInt(this.rawPubKey[1].toString())]);
|
|
35
35
|
/**
|
|
36
36
|
* Return this public key as smart contract parameters
|
|
37
37
|
* @returns the public key as smart contract parameters
|
|
@@ -76,7 +76,7 @@ class PubKey {
|
|
|
76
76
|
*/
|
|
77
77
|
this.equals = (p) => this.rawPubKey[0] === p.rawPubKey[0] && this.rawPubKey[1] === p.rawPubKey[1];
|
|
78
78
|
if (!allowInvalid) {
|
|
79
|
-
(0, assert_1.default)((0, crypto_1.inCurve)(rawPubKey), "
|
|
79
|
+
(0, assert_1.default)((0, crypto_1.inCurve)(rawPubKey), "PublicKey not on curve");
|
|
80
80
|
}
|
|
81
81
|
this.rawPubKey = rawPubKey;
|
|
82
82
|
}
|
|
@@ -85,16 +85,16 @@ class PubKey {
|
|
|
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
100
|
* Generate a default pad key
|
|
@@ -107,31 +107,31 @@ class PubKey {
|
|
|
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.unpackPubKey)(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.isValidSerializedPubKey = (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
|
+
{"version":3,"file":"publicKey.js","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAsH;AAEtH,oDAA4B;AAIf,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAa,SAAS;IAGpB;;;;;;;;;OASG;IACH,YAAY,SAAoB,EAAE,YAAY,GAAG,KAAK;QAOtD;;;WAGG;QACH,SAAI,GAAG,GAAc,EAAE,CAAC,IAAI,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC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,CAAC,CAAC,CAAC;QACzB,OAAO,aAAa,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,AAT6B,CAS5B"}
|
package/build/ts/stateLeaf.d.ts
CHANGED
|
@@ -1,20 +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
|
-
timestamp: bigint;
|
|
11
10
|
/**
|
|
12
11
|
* Create a new instance of a state leaf
|
|
13
|
-
* @param
|
|
12
|
+
* @param publicKey the public key of the user signin up
|
|
14
13
|
* @param voiceCreditBalance the voice credit balance of the user
|
|
15
|
-
* @param timestamp the timestamp of when the user signed-up
|
|
16
14
|
*/
|
|
17
|
-
constructor(
|
|
15
|
+
constructor(publicKey: PublicKey, voiceCreditBalance: bigint);
|
|
18
16
|
/**
|
|
19
17
|
* Crate a deep copy of the object
|
|
20
18
|
* @returns a copy of the state leaf
|
|
@@ -52,14 +50,14 @@ export declare class StateLeaf implements IStateLeaf {
|
|
|
52
50
|
asContractParam(): IStateLeafContractParams;
|
|
53
51
|
/**
|
|
54
52
|
* Check if two state leaves are equal
|
|
55
|
-
* @param
|
|
53
|
+
* @param leaf the state leaf to compare with
|
|
56
54
|
* @returns whether they are equal or not
|
|
57
55
|
*/
|
|
58
|
-
equals(
|
|
56
|
+
equals(leaf: StateLeaf): boolean;
|
|
59
57
|
/**
|
|
60
58
|
* Serialize the state leaf
|
|
61
59
|
* @notice serialize the public key
|
|
62
|
-
* @notice convert the voice credit balance
|
|
60
|
+
* @notice convert the voice credit balance to a hex string
|
|
63
61
|
* @returns
|
|
64
62
|
*/
|
|
65
63
|
serialize: () => string;
|
|
@@ -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,YAAY,IAAI,SAAS;IAkBhC;;;OAGG;IACH,MAAM,CAAC,aAAa,IAAI,SAAS;IAKjC;;;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,16 +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
|
-
* @param timestamp the timestamp of when the user signed-up
|
|
17
16
|
*/
|
|
18
|
-
constructor(
|
|
17
|
+
constructor(publicKey, voiceCreditBalance) {
|
|
19
18
|
/**
|
|
20
19
|
* Return this state leaf as an array of bigints
|
|
21
20
|
* @returns the state leaf as an array of bigints
|
|
22
21
|
*/
|
|
23
|
-
this.asArray = () => [...this.
|
|
22
|
+
this.asArray = () => [...this.publicKey.asArray(), this.voiceCreditBalance];
|
|
24
23
|
/**
|
|
25
24
|
* Return this state leaf as an array of bigints
|
|
26
25
|
* @returns the state leaf as an array of bigints
|
|
@@ -30,27 +29,26 @@ class StateLeaf {
|
|
|
30
29
|
* Hash this state leaf (first convert as array)
|
|
31
30
|
* @returns the has of the state leaf elements
|
|
32
31
|
*/
|
|
33
|
-
this.hash = () => (0, crypto_1.
|
|
32
|
+
this.hash = () => (0, crypto_1.hash3)(this.asArray());
|
|
34
33
|
/**
|
|
35
34
|
* Serialize the state leaf
|
|
36
35
|
* @notice serialize the public key
|
|
37
|
-
* @notice convert the voice credit balance
|
|
36
|
+
* @notice convert the voice credit balance to a hex string
|
|
38
37
|
* @returns
|
|
39
38
|
*/
|
|
40
39
|
this.serialize = () => {
|
|
41
|
-
const
|
|
42
|
-
return Buffer.from(JSON.stringify(
|
|
40
|
+
const data = [this.publicKey.serialize(), this.voiceCreditBalance.toString(16)];
|
|
41
|
+
return Buffer.from(JSON.stringify(data, null, 0), "utf8").toString("base64url");
|
|
43
42
|
};
|
|
44
|
-
this.
|
|
43
|
+
this.publicKey = publicKey;
|
|
45
44
|
this.voiceCreditBalance = voiceCreditBalance;
|
|
46
|
-
this.timestamp = timestamp;
|
|
47
45
|
}
|
|
48
46
|
/**
|
|
49
47
|
* Crate a deep copy of the object
|
|
50
48
|
* @returns a copy of the state leaf
|
|
51
49
|
*/
|
|
52
50
|
copy() {
|
|
53
|
-
return new StateLeaf(this.
|
|
51
|
+
return new StateLeaf(this.publicKey.copy(), BigInt(this.voiceCreditBalance.toString()));
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
56
54
|
* Generate a blank state leaf
|
|
@@ -64,11 +62,11 @@ class StateLeaf {
|
|
|
64
62
|
// public key. See:
|
|
65
63
|
// https://github.com/iden3/circomlib/blob/d5ed1c3ce4ca137a6b3ca48bec4ac12c1b38957a/src/pedersen_printbases.js
|
|
66
64
|
// Its hash should equal
|
|
67
|
-
//
|
|
68
|
-
return new StateLeaf(new publicKey_1.
|
|
65
|
+
// 11672248758340751985123309654953904206381780234474872690580702076708041504880.
|
|
66
|
+
return new StateLeaf(new publicKey_1.PublicKey([
|
|
69
67
|
BigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),
|
|
70
68
|
BigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317"),
|
|
71
|
-
]), BigInt(0)
|
|
69
|
+
]), BigInt(0));
|
|
72
70
|
}
|
|
73
71
|
/**
|
|
74
72
|
* Generate a random leaf (random salt and random key pair)
|
|
@@ -76,7 +74,7 @@ class StateLeaf {
|
|
|
76
74
|
*/
|
|
77
75
|
static genRandomLeaf() {
|
|
78
76
|
const keypair = new keyPair_1.Keypair();
|
|
79
|
-
return new StateLeaf(keypair.
|
|
77
|
+
return new StateLeaf(keypair.publicKey, (0, crypto_1.genRandomSalt)());
|
|
80
78
|
}
|
|
81
79
|
/**
|
|
82
80
|
* Return this state leaf as a contract param
|
|
@@ -84,27 +82,25 @@ class StateLeaf {
|
|
|
84
82
|
*/
|
|
85
83
|
asContractParam() {
|
|
86
84
|
return {
|
|
87
|
-
|
|
85
|
+
publicKey: this.publicKey.asContractParam(),
|
|
88
86
|
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
89
|
-
timestamp: this.timestamp.toString(),
|
|
90
87
|
};
|
|
91
88
|
}
|
|
92
89
|
/**
|
|
93
90
|
* Check if two state leaves are equal
|
|
94
|
-
* @param
|
|
91
|
+
* @param leaf the state leaf to compare with
|
|
95
92
|
* @returns whether they are equal or not
|
|
96
93
|
*/
|
|
97
|
-
equals(
|
|
98
|
-
return
|
|
94
|
+
equals(leaf) {
|
|
95
|
+
return this.publicKey.equals(leaf.publicKey) && this.voiceCreditBalance === leaf.voiceCreditBalance;
|
|
99
96
|
}
|
|
100
97
|
/**
|
|
101
98
|
* Serialize to a JSON object
|
|
102
99
|
*/
|
|
103
100
|
toJSON() {
|
|
104
101
|
return {
|
|
105
|
-
|
|
102
|
+
publicKey: this.publicKey.serialize(),
|
|
106
103
|
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
107
|
-
timestamp: this.timestamp.toString(),
|
|
108
104
|
};
|
|
109
105
|
}
|
|
110
106
|
/**
|
|
@@ -113,7 +109,7 @@ class StateLeaf {
|
|
|
113
109
|
* @returns the deserialized object as a StateLeaf instance
|
|
114
110
|
*/
|
|
115
111
|
static fromJSON(json) {
|
|
116
|
-
return new StateLeaf(publicKey_1.
|
|
112
|
+
return new StateLeaf(publicKey_1.PublicKey.deserialize(json.publicKey), BigInt(json.voiceCreditBalance));
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
115
|
exports.StateLeaf = StateLeaf;
|
|
@@ -125,6 +121,6 @@ exports.StateLeaf = StateLeaf;
|
|
|
125
121
|
StateLeaf.deserialize = (serialized) => {
|
|
126
122
|
const base64 = serialized.replace(/-/g, "+").replace(/_/g, "/");
|
|
127
123
|
const json = JSON.parse(Buffer.from(base64, "base64").toString("utf8"));
|
|
128
|
-
return new StateLeaf(publicKey_1.
|
|
124
|
+
return new StateLeaf(publicKey_1.PublicKey.deserialize(json[0]), BigInt(`0x${json[1]}`));
|
|
129
125
|
};
|
|
130
126
|
//# sourceMappingURL=stateLeaf.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stateLeaf.js","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":";;;AAAA,kDAA6D;AAI7D,uCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"stateLeaf.js","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":";;;AAAA,kDAA6D;AAI7D,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,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IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAoB;QAClC,OAAO,IAAI,SAAS,CAAC,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,15 +22,14 @@ 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
|
-
timestamp: string;
|
|
34
33
|
}
|
|
35
34
|
export type BigNumberish = number | string | bigint;
|
|
36
35
|
export interface IG1ContractParams {
|
|
@@ -60,9 +59,8 @@ export interface IVkObjectParams {
|
|
|
60
59
|
IC: BigNumberish[][];
|
|
61
60
|
}
|
|
62
61
|
export interface IStateLeafContractParams {
|
|
63
|
-
|
|
62
|
+
publicKey: IG1ContractParams;
|
|
64
63
|
voiceCreditBalance: BigNumberish;
|
|
65
|
-
timestamp: BigNumberish;
|
|
66
64
|
}
|
|
67
65
|
export interface IMessageContractParams {
|
|
68
66
|
data: BigNumberish[];
|
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,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