@maci-protocol/domainobjs 0.0.0-ci.f9da2fc → 0.0.0-ci.fc91dc9
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 +6 -6
- package/build/ts/ballot.d.ts.map +1 -1
- package/build/ts/ballot.js +12 -12
- package/build/ts/ballot.js.map +1 -1
- 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 +20 -20
- 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 +3 -3
- 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 +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 +14 -14
- package/build/ts/publicKey.d.ts.map +1 -1
- package/build/ts/publicKey.js +24 -24
- 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 +10 -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/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../ts/message.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../ts/message.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,qBAAa,OAAO;IAClB,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,MAAM,CAAC,WAAW,SAAM;IAExB;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE;IAK1B;;;OAGG;IACH,OAAO,CAAC,OAAO,CAA6B;IAE5C;;;OAGG;IACH,eAAe,QAAO,sBAAsB,CAEzC;IAEH;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAmB;IAEjD;;;;OAIG;IACH,IAAI,GAAI,qBAAqB,SAAS,KAAG,MAAM,CAAuD;IAEtG;;;OAGG;IACH,IAAI,QAAO,OAAO,CAAoE;IAEtF;;;;OAIG;IACH,MAAM,GAAI,GAAG,OAAO,KAAG,OAAO,CAM5B;IAEF;;OAEG;IACH,MAAM,IAAI,sBAAsB;IAIhC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO;CAGvD"}
|
package/build/ts/message.js
CHANGED
|
@@ -35,10 +35,10 @@ class Message {
|
|
|
35
35
|
this.asCircuitInputs = () => this.asArray();
|
|
36
36
|
/**
|
|
37
37
|
* Hash the message data and a public key
|
|
38
|
-
* @param
|
|
38
|
+
* @param encryptionPublicKey the public key that is used to encrypt this message
|
|
39
39
|
* @returns the hash of the message data and the public key
|
|
40
40
|
*/
|
|
41
|
-
this.hash = (
|
|
41
|
+
this.hash = (encryptionPublicKey) => (0, crypto_1.hash12)([...this.data, ...encryptionPublicKey.raw]);
|
|
42
42
|
/**
|
|
43
43
|
* Create a copy of the message
|
|
44
44
|
* @returns a copy of the message
|
package/build/ts/message.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../ts/message.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA+C;AAE/C,oDAA4B;AAK5B;;GAEG;AACH,MAAa,OAAO;IAKlB;;;;OAIG;IACH,YAAY,IAAc;QAK1B;;;WAGG;QACK,YAAO,GAAG,GAAa,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;QAE5C;;;WAGG;QACH,oBAAe,GAAG,GAA2B,EAAE,CAAC,CAAC;YAC/C,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;SACjD,CAAC,CAAC;QAEH;;;WAGG;QACH,oBAAe,GAAG,GAAa,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAEjD;;;;WAIG;QACH,SAAI,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../ts/message.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA+C;AAE/C,oDAA4B;AAK5B;;GAEG;AACH,MAAa,OAAO;IAKlB;;;;OAIG;IACH,YAAY,IAAc;QAK1B;;;WAGG;QACK,YAAO,GAAG,GAAa,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;QAE5C;;;WAGG;QACH,oBAAe,GAAG,GAA2B,EAAE,CAAC,CAAC;YAC/C,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,QA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AC;IACtD,CAAC;;AA3EH,0BA4EC;AAzEQ,mBAAW,GAAG,EAAE,AAAL,CAAM"}
|
package/build/ts/privateKey.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PrivateKey as RawPrivateKey } from "@maci-protocol/crypto";
|
|
2
2
|
import type { IJsonPrivateKey } from "./types";
|
|
3
3
|
export declare const SERIALIZED_PRIV_KEY_PREFIX = "macisk.";
|
|
4
4
|
/**
|
|
5
|
-
* @notice
|
|
5
|
+
* @notice PrivateKey is a TS Class representing a MACI PrivateKey
|
|
6
6
|
* which is a seed to be used to generate a public key (point on the curve)
|
|
7
7
|
* This is a MACI private key, which is not to be
|
|
8
8
|
* confused with an Ethereum private key.
|
|
9
9
|
* A serialized MACI private key is prefixed by 'macisk.'
|
|
10
10
|
*/
|
|
11
|
-
export declare class
|
|
12
|
-
|
|
11
|
+
export declare class PrivateKey {
|
|
12
|
+
raw: RawPrivateKey;
|
|
13
13
|
/**
|
|
14
14
|
* Generate a new Private key object
|
|
15
|
-
* @param
|
|
15
|
+
* @param raw the raw private key (a bigint)
|
|
16
16
|
*/
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(raw: RawPrivateKey);
|
|
18
18
|
/**
|
|
19
19
|
* Create a copy of this Private key
|
|
20
20
|
* @returns a copy of the Private key
|
|
21
21
|
*/
|
|
22
|
-
copy: () =>
|
|
22
|
+
copy: () => PrivateKey;
|
|
23
23
|
/**
|
|
24
24
|
* Return this Private key as a circuit input
|
|
25
25
|
* @returns the Private key as a circuit input
|
|
@@ -35,13 +35,13 @@ export declare class PrivKey {
|
|
|
35
35
|
* @param s the serialized private key
|
|
36
36
|
* @returns the deserialized private key
|
|
37
37
|
*/
|
|
38
|
-
static deserialize: (s: string) =>
|
|
38
|
+
static deserialize: (s: string) => PrivateKey;
|
|
39
39
|
/**
|
|
40
40
|
* Check if the serialized private key is valid
|
|
41
|
-
* @param
|
|
41
|
+
* @param serialized the serialized private key
|
|
42
42
|
* @returns whether it is a valid serialized private key
|
|
43
43
|
*/
|
|
44
|
-
static
|
|
44
|
+
static isValidSerialized: (serialized: string) => boolean;
|
|
45
45
|
/**
|
|
46
46
|
* Serialize this object
|
|
47
47
|
*/
|
|
@@ -49,8 +49,8 @@ export declare class PrivKey {
|
|
|
49
49
|
/**
|
|
50
50
|
* Deserialize this object from a JSON object
|
|
51
51
|
* @param json - the json object
|
|
52
|
-
* @returns the deserialized object as a
|
|
52
|
+
* @returns the deserialized object as a PrivateKey instance
|
|
53
53
|
*/
|
|
54
|
-
static fromJSON(json: IJsonPrivateKey):
|
|
54
|
+
static fromJSON(json: IJsonPrivateKey): PrivateKey;
|
|
55
55
|
}
|
|
56
56
|
//# sourceMappingURL=privateKey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"privateKey.d.ts","sourceRoot":"","sources":["../../ts/privateKey.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"privateKey.d.ts","sourceRoot":"","sources":["../../ts/privateKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,UAAU,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAErG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,eAAO,MAAM,0BAA0B,YAAY,CAAC;AAEpD;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,GAAG,EAAE,aAAa,CAAC;IAEnB;;;OAGG;gBACS,GAAG,EAAE,aAAa;IAI9B;;;OAGG;IACH,IAAI,QAAO,UAAU,CAAgD;IAErE;;;OAGG;IACH,eAAe,QAAO,MAAM,CAAoD;IAEhF;;;OAGG;IACH,SAAS,QAAO,MAAM,CAOpB;IAEF;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,GAAG,MAAM,KAAG,UAAU,CAG1C;IAEF;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,GAAI,YAAY,MAAM,KAAG,OAAO,CAKtD;IAEF;;OAEG;IACH,MAAM,IAAI,eAAe;IAMzB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,UAAU;CAGnD"}
|
package/build/ts/privateKey.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PrivateKey = exports.SERIALIZED_PRIV_KEY_PREFIX = void 0;
|
|
4
4
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
5
5
|
exports.SERIALIZED_PRIV_KEY_PREFIX = "macisk.";
|
|
6
6
|
/**
|
|
7
|
-
* @notice
|
|
7
|
+
* @notice PrivateKey is a TS Class representing a MACI PrivateKey
|
|
8
8
|
* which is a seed to be used to generate a public key (point on the curve)
|
|
9
9
|
* This is a MACI private key, which is not to be
|
|
10
10
|
* confused with an Ethereum private key.
|
|
11
11
|
* A serialized MACI private key is prefixed by 'macisk.'
|
|
12
12
|
*/
|
|
13
|
-
class
|
|
13
|
+
class PrivateKey {
|
|
14
14
|
/**
|
|
15
15
|
* Generate a new Private key object
|
|
16
|
-
* @param
|
|
16
|
+
* @param raw the raw private key (a bigint)
|
|
17
17
|
*/
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(raw) {
|
|
19
19
|
/**
|
|
20
20
|
* Create a copy of this Private key
|
|
21
21
|
* @returns a copy of the Private key
|
|
22
22
|
*/
|
|
23
|
-
this.copy = () => new
|
|
23
|
+
this.copy = () => new PrivateKey(BigInt(this.raw.toString()));
|
|
24
24
|
/**
|
|
25
25
|
* Return this Private key as a circuit input
|
|
26
26
|
* @returns the Private key as a circuit input
|
|
27
27
|
*/
|
|
28
|
-
this.asCircuitInputs = () => (0, crypto_1.
|
|
28
|
+
this.asCircuitInputs = () => (0, crypto_1.formatPrivateKeyForBabyJub)(this.raw).toString();
|
|
29
29
|
/**
|
|
30
30
|
* Serialize the private key
|
|
31
31
|
* @returns the serialized private key
|
|
32
32
|
*/
|
|
33
33
|
this.serialize = () => {
|
|
34
|
-
let x = this.
|
|
34
|
+
let x = this.raw.toString(16);
|
|
35
35
|
if (x.length % 2 !== 0) {
|
|
36
36
|
x = `0${x}`;
|
|
37
37
|
}
|
|
38
38
|
return `${exports.SERIALIZED_PRIV_KEY_PREFIX}${x.padStart(64, "0")}`;
|
|
39
39
|
};
|
|
40
|
-
this.
|
|
40
|
+
this.raw = raw;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Serialize this object
|
|
44
44
|
*/
|
|
45
45
|
toJSON() {
|
|
46
46
|
return {
|
|
47
|
-
|
|
47
|
+
privateKey: this.serialize(),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Deserialize this object from a JSON object
|
|
52
52
|
* @param json - the json object
|
|
53
|
-
* @returns the deserialized object as a
|
|
53
|
+
* @returns the deserialized object as a PrivateKey instance
|
|
54
54
|
*/
|
|
55
55
|
static fromJSON(json) {
|
|
56
|
-
return
|
|
56
|
+
return PrivateKey.deserialize(json.privateKey);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
exports.
|
|
59
|
+
exports.PrivateKey = PrivateKey;
|
|
60
60
|
/**
|
|
61
61
|
* Deserialize the private key
|
|
62
62
|
* @param s the serialized private key
|
|
63
63
|
* @returns the deserialized private key
|
|
64
64
|
*/
|
|
65
|
-
|
|
65
|
+
PrivateKey.deserialize = (s) => {
|
|
66
66
|
const x = s.slice(exports.SERIALIZED_PRIV_KEY_PREFIX.length);
|
|
67
|
-
return new
|
|
67
|
+
return new PrivateKey(BigInt(`0x${x}`));
|
|
68
68
|
};
|
|
69
69
|
/**
|
|
70
70
|
* Check if the serialized private key is valid
|
|
71
|
-
* @param
|
|
71
|
+
* @param serialized the serialized private key
|
|
72
72
|
* @returns whether it is a valid serialized private key
|
|
73
73
|
*/
|
|
74
|
-
|
|
75
|
-
const correctPrefix =
|
|
76
|
-
const
|
|
77
|
-
return correctPrefix &&
|
|
74
|
+
PrivateKey.isValidSerialized = (serialized) => {
|
|
75
|
+
const correctPrefix = serialized.startsWith(exports.SERIALIZED_PRIV_KEY_PREFIX);
|
|
76
|
+
const body = serialized.slice(exports.SERIALIZED_PRIV_KEY_PREFIX.length);
|
|
77
|
+
return correctPrefix && body.length === 64;
|
|
78
78
|
};
|
|
79
79
|
//# sourceMappingURL=privateKey.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"privateKey.js","sourceRoot":"","sources":["../../ts/privateKey.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"privateKey.js","sourceRoot":"","sources":["../../ts/privateKey.ts"],"names":[],"mappings":";;;AAAA,kDAAqG;AAIxF,QAAA,0BAA0B,GAAG,SAAS,CAAC;AAEpD;;;;;;GAMG;AACH,MAAa,UAAU;IAGrB;;;OAGG;IACH,YAAY,GAAkB;QAI9B;;;WAGG;QACH,SAAI,GAAG,GAAe,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QAErE;;;WAGG;QACH,oBAAe,GAAG,GAAW,EAAE,CAAC,IAAA,mCAA0B,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;QAEhF;;;WAGG;QACH,cAAS,GAAG,GAAW,EAAE;YACvB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;YACd,CAAC;YAED,OAAO,GAAG,kCAA0B,GAAG,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/D,CAAC,CAAC;QA1BA,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAiDD;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE;SAC7B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAqB;QACnC,OAAO,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACjD,CAAC;;AA1EH,gCA2EC;AAvCC;;;;GAIG;AACI,sBAAW,GAAG,CAAC,CAAS,EAAc,EAAE;IAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,kCAA0B,CAAC,MAAM,CAAC,CAAC;IACrD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1C,CAAC,AAHiB,CAGhB;AAEF;;;;GAIG;AACI,4BAAiB,GAAG,CAAC,UAAkB,EAAW,EAAE;IACzD,MAAM,aAAa,GAAG,UAAU,CAAC,UAAU,CAAC,kCAA0B,CAAC,CAAC;IACxE,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,kCAA0B,CAAC,MAAM,CAAC,CAAC;IAEjE,OAAO,aAAa,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC;AAC7C,CAAC,AALuB,CAKtB"}
|
package/build/ts/publicKey.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PublicKey as RawPublicKey } 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,8 +9,8 @@ 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
|
|
13
|
-
|
|
12
|
+
export declare class PublicKey {
|
|
13
|
+
raw: RawPublicKey;
|
|
14
14
|
/**
|
|
15
15
|
* Create a new instance of a public key
|
|
16
16
|
* @dev You might want to allow an invalid raw key,
|
|
@@ -18,15 +18,15 @@ export declare class PubKey {
|
|
|
18
18
|
* will be random, and likely not be a point on the curve.
|
|
19
19
|
* However we need to match keys to the circuit which does
|
|
20
20
|
* not perform such checks
|
|
21
|
-
* @param
|
|
21
|
+
* @param raw the raw public key
|
|
22
22
|
* @param allowInvalid whether to allow invalid public keys
|
|
23
23
|
*/
|
|
24
|
-
constructor(
|
|
24
|
+
constructor(raw: RawPublicKey, allowInvalid?: boolean);
|
|
25
25
|
/**
|
|
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
|
|
@@ -54,36 +54,36 @@ export declare class PubKey {
|
|
|
54
54
|
hash: () => bigint;
|
|
55
55
|
/**
|
|
56
56
|
* Check whether this public key equals to another public key
|
|
57
|
-
* @param
|
|
57
|
+
* @param key the public key to compare with
|
|
58
58
|
* @returns whether they match
|
|
59
59
|
*/
|
|
60
|
-
equals: (
|
|
60
|
+
equals: (key: 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
|
|
70
70
|
* @returns whether the serialized public key is valid
|
|
71
71
|
*/
|
|
72
|
-
static
|
|
72
|
+
static isValidSerialized: (s: string) => boolean;
|
|
73
73
|
/**
|
|
74
74
|
* Serialize this object
|
|
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,
|
|
1
|
+
{"version":3,"file":"publicKey.d.ts","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,IAAI,YAAY,EAC/B,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB,GAAG,EAAE,YAAY,CAAC;IAElB;;;;;;;;;OASG;gBACS,GAAG,EAAE,YAAY,EAAE,YAAY,UAAQ;IAOnD;;;OAGG;IACH,IAAI,QAAO,SAAS,CAAoF;IAExG;;;OAGG;IACH,eAAe,QAAO,iBAAiB,CAOrC;IAEF;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAsC;IAEpE;;;OAGG;IACH,OAAO,QAAO,MAAM,EAAE,CAA+B;IAErD;;;OAGG;IACH,SAAS,QAAO,MAAM,CAQpB;IAEF;;;OAGG;IACH,IAAI,QAAO,MAAM,CAA4C;IAE7D;;;;OAIG;IACH,MAAM,GAAI,KAAK,SAAS,KAAG,OAAO,CAA6D;IAE/F;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,GAAG,MAAM,KAAG,SAAS,CAGzC;IAEF;;;;OAIG;IACH,MAAM,CAAC,iBAAiB,GAAI,GAAG,MAAM,KAAG,OAAO,CAS7C;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,
|
|
@@ -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,33 +68,33 @@ 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
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.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
|
+
{"version":3,"file":"publicKey.js","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":";;;;;;AAAA,kDAM+B;AAE/B,oDAA4B;AAIf,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAa,SAAS;IAGpB;;;;;;;;;OASG;IACH,YAAY,GAAiB,EAAE,YAA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AE,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
|
|
@@ -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.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,CAA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