@maci-protocol/domainobjs 0.0.0-ci.f9da2fc → 0.0.0-ci.fb960ed
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 +4 -4
- package/build/ts/stateLeaf.d.ts.map +1 -1
- package/build/ts/stateLeaf.js +13 -13
- package/build/ts/stateLeaf.js.map +1 -1
- package/build/ts/types.d.ts +8 -8
- package/build/ts/types.d.ts.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
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,CA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AC,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,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
|
|
@@ -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,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,7 +48,7 @@ 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
|
|
@@ -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));
|
|
@@ -74,7 +74,7 @@ class StateLeaf {
|
|
|
74
74
|
*/
|
|
75
75
|
static genRandomLeaf() {
|
|
76
76
|
const keypair = new keyPair_1.Keypair();
|
|
77
|
-
return new StateLeaf(keypair.
|
|
77
|
+
return new StateLeaf(keypair.publicKey, (0, crypto_1.genRandomSalt)());
|
|
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,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,SA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,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE;SACvD,CAAC;IACJ,CAAC;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,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;
|
|
@@ -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 {
|
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,MA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