@maci-protocol/domainobjs 0.0.0-ci.1e276ed
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 +183 -0
- package/LICENSE +22 -0
- package/README.md +78 -0
- package/build/ts/ballot.d.ts +68 -0
- package/build/ts/ballot.d.ts.map +1 -0
- package/build/ts/ballot.js +120 -0
- package/build/ts/ballot.js.map +1 -0
- package/build/ts/commands/PCommand.d.ts +89 -0
- package/build/ts/commands/PCommand.d.ts.map +1 -0
- package/build/ts/commands/PCommand.js +171 -0
- package/build/ts/commands/PCommand.js.map +1 -0
- package/build/ts/commands/index.d.ts +3 -0
- package/build/ts/commands/index.d.ts.map +1 -0
- package/build/ts/commands/index.js +6 -0
- package/build/ts/commands/index.js.map +1 -0
- package/build/ts/commands/types.d.ts +21 -0
- package/build/ts/commands/types.d.ts.map +1 -0
- package/build/ts/commands/types.js +3 -0
- package/build/ts/commands/types.js.map +1 -0
- package/build/ts/constants.d.ts +6 -0
- package/build/ts/constants.d.ts.map +1 -0
- package/build/ts/constants.js +9 -0
- package/build/ts/constants.js.map +1 -0
- package/build/ts/index.d.ts +11 -0
- package/build/ts/index.d.ts.map +1 -0
- package/build/ts/index.js +26 -0
- package/build/ts/index.js.map +1 -0
- package/build/ts/keyPair.d.ts +49 -0
- package/build/ts/keyPair.d.ts.map +1 -0
- package/build/ts/keyPair.js +82 -0
- package/build/ts/keyPair.js.map +1 -0
- package/build/ts/message.d.ts +58 -0
- package/build/ts/message.d.ts.map +1 -0
- package/build/ts/message.js +78 -0
- package/build/ts/message.js.map +1 -0
- package/build/ts/privateKey.d.ts +56 -0
- package/build/ts/privateKey.d.ts.map +1 -0
- package/build/ts/privateKey.js +79 -0
- package/build/ts/privateKey.js.map +1 -0
- package/build/ts/publicKey.d.ts +89 -0
- package/build/ts/publicKey.d.ts.map +1 -0
- package/build/ts/publicKey.js +141 -0
- package/build/ts/publicKey.js.map +1 -0
- package/build/ts/stateLeaf.d.ts +83 -0
- package/build/ts/stateLeaf.d.ts.map +1 -0
- package/build/ts/stateLeaf.js +130 -0
- package/build/ts/stateLeaf.js.map +1 -0
- package/build/ts/types.d.ts +75 -0
- package/build/ts/types.d.ts.map +1 -0
- package/build/ts/types.js +3 -0
- package/build/ts/types.js.map +1 -0
- package/build/ts/verifyingKey.d.ts +57 -0
- package/build/ts/verifyingKey.d.ts.map +1 -0
- package/build/ts/verifyingKey.js +96 -0
- package/build/ts/verifyingKey.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type PrivKey as RawPrivKey } from "@maci-protocol/crypto";
|
|
2
|
+
import type { IJsonPrivateKey } from "./types";
|
|
3
|
+
export declare const SERIALIZED_PRIV_KEY_PREFIX = "macisk.";
|
|
4
|
+
/**
|
|
5
|
+
* @notice PrivKey is a TS Class representing a MACI PrivateKey
|
|
6
|
+
* which is a seed to be used to generate a public key (point on the curve)
|
|
7
|
+
* This is a MACI private key, which is not to be
|
|
8
|
+
* confused with an Ethereum private key.
|
|
9
|
+
* A serialized MACI private key is prefixed by 'macisk.'
|
|
10
|
+
*/
|
|
11
|
+
export declare class PrivKey {
|
|
12
|
+
rawPrivKey: RawPrivKey;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a new Private key object
|
|
15
|
+
* @param rawPrivKey the raw private key (a bigint)
|
|
16
|
+
*/
|
|
17
|
+
constructor(rawPrivKey: RawPrivKey);
|
|
18
|
+
/**
|
|
19
|
+
* Create a copy of this Private key
|
|
20
|
+
* @returns a copy of the Private key
|
|
21
|
+
*/
|
|
22
|
+
copy: () => PrivKey;
|
|
23
|
+
/**
|
|
24
|
+
* Return this Private key as a circuit input
|
|
25
|
+
* @returns the Private key as a circuit input
|
|
26
|
+
*/
|
|
27
|
+
asCircuitInputs: () => string;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize the private key
|
|
30
|
+
* @returns the serialized private key
|
|
31
|
+
*/
|
|
32
|
+
serialize: () => string;
|
|
33
|
+
/**
|
|
34
|
+
* Deserialize the private key
|
|
35
|
+
* @param s the serialized private key
|
|
36
|
+
* @returns the deserialized private key
|
|
37
|
+
*/
|
|
38
|
+
static deserialize: (s: string) => PrivKey;
|
|
39
|
+
/**
|
|
40
|
+
* Check if the serialized private key is valid
|
|
41
|
+
* @param s the serialized private key
|
|
42
|
+
* @returns whether it is a valid serialized private key
|
|
43
|
+
*/
|
|
44
|
+
static isValidSerializedPrivKey: (s: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Serialize this object
|
|
47
|
+
*/
|
|
48
|
+
toJSON(): IJsonPrivateKey;
|
|
49
|
+
/**
|
|
50
|
+
* Deserialize this object from a JSON object
|
|
51
|
+
* @param json - the json object
|
|
52
|
+
* @returns the deserialized object as a PrivKey instance
|
|
53
|
+
*/
|
|
54
|
+
static fromJSON(json: IJsonPrivateKey): PrivKey;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=privateKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privateKey.d.ts","sourceRoot":"","sources":["../../ts/privateKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,OAAO,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE5F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,eAAO,MAAM,0BAA0B,YAAY,CAAC;AAEpD;;;;;;GAMG;AACH,qBAAa,OAAO;IAClB,UAAU,EAAE,UAAU,CAAC;IAEvB;;;OAGG;gBACS,UAAU,EAAE,UAAU;IAIlC;;;OAGG;IACH,IAAI,QAAO,OAAO,CAAoD;IAEtE;;;OAGG;IACH,eAAe,QAAO,MAAM,CAAwD;IAEpF;;;OAGG;IACH,SAAS,QAAO,MAAM,CAOpB;IAEF;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,GAAG,MAAM,KAAG,OAAO,CAGvC;IAEF;;;;OAIG;IACH,MAAM,CAAC,wBAAwB,GAAI,GAAG,MAAM,KAAG,OAAO,CAKpD;IAEF;;OAEG;IACH,MAAM,IAAI,eAAe;IAMzB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO;CAGhD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrivKey = exports.SERIALIZED_PRIV_KEY_PREFIX = void 0;
|
|
4
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
5
|
+
exports.SERIALIZED_PRIV_KEY_PREFIX = "macisk.";
|
|
6
|
+
/**
|
|
7
|
+
* @notice PrivKey is a TS Class representing a MACI PrivateKey
|
|
8
|
+
* which is a seed to be used to generate a public key (point on the curve)
|
|
9
|
+
* This is a MACI private key, which is not to be
|
|
10
|
+
* confused with an Ethereum private key.
|
|
11
|
+
* A serialized MACI private key is prefixed by 'macisk.'
|
|
12
|
+
*/
|
|
13
|
+
class PrivKey {
|
|
14
|
+
/**
|
|
15
|
+
* Generate a new Private key object
|
|
16
|
+
* @param rawPrivKey the raw private key (a bigint)
|
|
17
|
+
*/
|
|
18
|
+
constructor(rawPrivKey) {
|
|
19
|
+
/**
|
|
20
|
+
* Create a copy of this Private key
|
|
21
|
+
* @returns a copy of the Private key
|
|
22
|
+
*/
|
|
23
|
+
this.copy = () => new PrivKey(BigInt(this.rawPrivKey.toString()));
|
|
24
|
+
/**
|
|
25
|
+
* Return this Private key as a circuit input
|
|
26
|
+
* @returns the Private key as a circuit input
|
|
27
|
+
*/
|
|
28
|
+
this.asCircuitInputs = () => (0, crypto_1.formatPrivKeyForBabyJub)(this.rawPrivKey).toString();
|
|
29
|
+
/**
|
|
30
|
+
* Serialize the private key
|
|
31
|
+
* @returns the serialized private key
|
|
32
|
+
*/
|
|
33
|
+
this.serialize = () => {
|
|
34
|
+
let x = this.rawPrivKey.toString(16);
|
|
35
|
+
if (x.length % 2 !== 0) {
|
|
36
|
+
x = `0${x}`;
|
|
37
|
+
}
|
|
38
|
+
return `${exports.SERIALIZED_PRIV_KEY_PREFIX}${x.padStart(64, "0")}`;
|
|
39
|
+
};
|
|
40
|
+
this.rawPrivKey = rawPrivKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serialize this object
|
|
44
|
+
*/
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
privKey: this.serialize(),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Deserialize this object from a JSON object
|
|
52
|
+
* @param json - the json object
|
|
53
|
+
* @returns the deserialized object as a PrivKey instance
|
|
54
|
+
*/
|
|
55
|
+
static fromJSON(json) {
|
|
56
|
+
return PrivKey.deserialize(json.privKey);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.PrivKey = PrivKey;
|
|
60
|
+
/**
|
|
61
|
+
* Deserialize the private key
|
|
62
|
+
* @param s the serialized private key
|
|
63
|
+
* @returns the deserialized private key
|
|
64
|
+
*/
|
|
65
|
+
PrivKey.deserialize = (s) => {
|
|
66
|
+
const x = s.slice(exports.SERIALIZED_PRIV_KEY_PREFIX.length);
|
|
67
|
+
return new PrivKey(BigInt(`0x${x}`));
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Check if the serialized private key is valid
|
|
71
|
+
* @param s the serialized private key
|
|
72
|
+
* @returns whether it is a valid serialized private key
|
|
73
|
+
*/
|
|
74
|
+
PrivKey.isValidSerializedPrivKey = (s) => {
|
|
75
|
+
const correctPrefix = s.startsWith(exports.SERIALIZED_PRIV_KEY_PREFIX);
|
|
76
|
+
const x = s.slice(exports.SERIALIZED_PRIV_KEY_PREFIX.length);
|
|
77
|
+
return correctPrefix && x.length === 64;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=privateKey.js.map
|
|
@@ -0,0 +1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AK,CAAC,kCAA0B,CAAC,MAAM,CAAC,CAAC;IACrD,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACvC,CAAC,AAHiB,CAGhB;AAEF;;;;GAIG;AACI,gCAAwB,GAAG,CAAC,CAAS,EAAW,EAAE;IACvD,MAAM,aAAa,GAAG,CAAC,CAAC,UAAU,CAAC,kCAA0B,CAAC,CAAC;IAC/D,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,kCAA0B,CAAC,MAAM,CAAC,CAAC;IAErD,OAAO,aAAa,IAAI,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC;AAC1C,CAAC,AAL8B,CAK7B"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type PubKey as RawPubKey } from "@maci-protocol/crypto";
|
|
2
|
+
import type { IJsonPublicKey, IG1ContractParams } from "./types";
|
|
3
|
+
export declare const SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
4
|
+
/**
|
|
5
|
+
* @notice A class representing a public key
|
|
6
|
+
* This is a MACI public key, which is not to be
|
|
7
|
+
* confused with an Ethereum public key.
|
|
8
|
+
* A serialized MACI public key is prefixed by 'macipk.'
|
|
9
|
+
* A raw MACI public key can be thought as a pair of
|
|
10
|
+
* BigIntegers (x, y) representing a point on the baby jubjub curve
|
|
11
|
+
*/
|
|
12
|
+
export declare class PubKey {
|
|
13
|
+
rawPubKey: RawPubKey;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of a public key
|
|
16
|
+
* @dev You might want to allow an invalid raw key,
|
|
17
|
+
* as when decrypting invalid messages, the public key data
|
|
18
|
+
* will be random, and likely not be a point on the curve.
|
|
19
|
+
* However we need to match keys to the circuit which does
|
|
20
|
+
* not perform such checks
|
|
21
|
+
* @param rawPubKey the raw public key
|
|
22
|
+
* @param allowInvalid whether to allow invalid public keys
|
|
23
|
+
*/
|
|
24
|
+
constructor(rawPubKey: RawPubKey, allowInvalid?: boolean);
|
|
25
|
+
/**
|
|
26
|
+
* Create a copy of the public key
|
|
27
|
+
* @returns a copy of the public key
|
|
28
|
+
*/
|
|
29
|
+
copy: () => PubKey;
|
|
30
|
+
/**
|
|
31
|
+
* Return this public key as smart contract parameters
|
|
32
|
+
* @returns the public key as smart contract parameters
|
|
33
|
+
*/
|
|
34
|
+
asContractParam: () => IG1ContractParams;
|
|
35
|
+
/**
|
|
36
|
+
* Return this public key as circuit inputs
|
|
37
|
+
* @returns an array of strings
|
|
38
|
+
*/
|
|
39
|
+
asCircuitInputs: () => string[];
|
|
40
|
+
/**
|
|
41
|
+
* Return this public key as an array of bigints
|
|
42
|
+
* @returns the public key as an array of bigints
|
|
43
|
+
*/
|
|
44
|
+
asArray: () => bigint[];
|
|
45
|
+
/**
|
|
46
|
+
* Generate a serialized public key from this public key object
|
|
47
|
+
* @returns the string representation of a serialized public key
|
|
48
|
+
*/
|
|
49
|
+
serialize: () => string;
|
|
50
|
+
/**
|
|
51
|
+
* Hash the two baby jubjub coordinates
|
|
52
|
+
* @returns the hash of this public key
|
|
53
|
+
*/
|
|
54
|
+
hash: () => bigint;
|
|
55
|
+
/**
|
|
56
|
+
* Check whether this public key equals to another public key
|
|
57
|
+
* @param p the public key to compare with
|
|
58
|
+
* @returns whether they match
|
|
59
|
+
*/
|
|
60
|
+
equals: (p: PubKey) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Deserialize a serialized public key
|
|
63
|
+
* @param s the serialized public key
|
|
64
|
+
* @returns the deserialized public key
|
|
65
|
+
*/
|
|
66
|
+
static deserialize: (s: string) => PubKey;
|
|
67
|
+
/**
|
|
68
|
+
* Check whether a serialized public key is serialized correctly
|
|
69
|
+
* @param s the serialized public key
|
|
70
|
+
* @returns whether the serialized public key is valid
|
|
71
|
+
*/
|
|
72
|
+
static isValidSerializedPubKey: (s: string) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Serialize this object
|
|
75
|
+
*/
|
|
76
|
+
toJSON(): IJsonPublicKey;
|
|
77
|
+
/**
|
|
78
|
+
* Deserialize a JSON object into a PubKey instance
|
|
79
|
+
* @param json - the json object
|
|
80
|
+
* @returns PubKey
|
|
81
|
+
*/
|
|
82
|
+
static fromJSON(json: IJsonPublicKey): PubKey;
|
|
83
|
+
/**
|
|
84
|
+
* Generate a default pad key
|
|
85
|
+
* @returns a default pad key
|
|
86
|
+
*/
|
|
87
|
+
static genPadKey(): PubKey;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=publicKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicKey.d.ts","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoD,KAAK,MAAM,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAInH,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD;;;;;;;GAOG;AACH,qBAAa,MAAM;IACjB,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;;;;;OASG;gBACS,SAAS,EAAE,SAAS,EAAE,YAAY,UAAQ;IAOtD;;;OAGG;IACH,IAAI,QAAO,MAAM,CAA6F;IAE9G;;;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,MAAM,KAAG,OAAO,CAAiF;IAE9G;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,GAAG,MAAM,KAAG,MAAM,CAGtC;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,MAAM;IAI7C;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,MAAM;CAY3B"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PubKey = exports.SERIALIZED_PUB_KEY_PREFIX = void 0;
|
|
7
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
exports.SERIALIZED_PUB_KEY_PREFIX = "macipk.";
|
|
10
|
+
/**
|
|
11
|
+
* @notice A class representing a public key
|
|
12
|
+
* This is a MACI public key, which is not to be
|
|
13
|
+
* confused with an Ethereum public key.
|
|
14
|
+
* A serialized MACI public key is prefixed by 'macipk.'
|
|
15
|
+
* A raw MACI public key can be thought as a pair of
|
|
16
|
+
* BigIntegers (x, y) representing a point on the baby jubjub curve
|
|
17
|
+
*/
|
|
18
|
+
class PubKey {
|
|
19
|
+
/**
|
|
20
|
+
* Create a new instance of a public key
|
|
21
|
+
* @dev You might want to allow an invalid raw key,
|
|
22
|
+
* as when decrypting invalid messages, the public key data
|
|
23
|
+
* will be random, and likely not be a point on the curve.
|
|
24
|
+
* However we need to match keys to the circuit which does
|
|
25
|
+
* not perform such checks
|
|
26
|
+
* @param rawPubKey the raw public key
|
|
27
|
+
* @param allowInvalid whether to allow invalid public keys
|
|
28
|
+
*/
|
|
29
|
+
constructor(rawPubKey, allowInvalid = false) {
|
|
30
|
+
/**
|
|
31
|
+
* Create a copy of the public key
|
|
32
|
+
* @returns a copy of the public key
|
|
33
|
+
*/
|
|
34
|
+
this.copy = () => new PubKey([BigInt(this.rawPubKey[0].toString()), BigInt(this.rawPubKey[1].toString())]);
|
|
35
|
+
/**
|
|
36
|
+
* Return this public key as smart contract parameters
|
|
37
|
+
* @returns the public key as smart contract parameters
|
|
38
|
+
*/
|
|
39
|
+
this.asContractParam = () => {
|
|
40
|
+
const [x, y] = this.rawPubKey;
|
|
41
|
+
return {
|
|
42
|
+
x: x.toString(),
|
|
43
|
+
y: y.toString(),
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Return this public key as circuit inputs
|
|
48
|
+
* @returns an array of strings
|
|
49
|
+
*/
|
|
50
|
+
this.asCircuitInputs = () => this.rawPubKey.map((x) => x.toString());
|
|
51
|
+
/**
|
|
52
|
+
* Return this public key as an array of bigints
|
|
53
|
+
* @returns the public key as an array of bigints
|
|
54
|
+
*/
|
|
55
|
+
this.asArray = () => [this.rawPubKey[0], this.rawPubKey[1]];
|
|
56
|
+
/**
|
|
57
|
+
* Generate a serialized public key from this public key object
|
|
58
|
+
* @returns the string representation of a serialized public key
|
|
59
|
+
*/
|
|
60
|
+
this.serialize = () => {
|
|
61
|
+
const packed = (0, crypto_1.packPubKey)(this.rawPubKey).toString(16);
|
|
62
|
+
if (packed.length % 2 !== 0) {
|
|
63
|
+
return `${exports.SERIALIZED_PUB_KEY_PREFIX}0${packed}`;
|
|
64
|
+
}
|
|
65
|
+
return `${exports.SERIALIZED_PUB_KEY_PREFIX}${packed}`;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Hash the two baby jubjub coordinates
|
|
69
|
+
* @returns the hash of this public key
|
|
70
|
+
*/
|
|
71
|
+
this.hash = () => (0, crypto_1.hashLeftRight)(this.rawPubKey[0], this.rawPubKey[1]);
|
|
72
|
+
/**
|
|
73
|
+
* Check whether this public key equals to another public key
|
|
74
|
+
* @param p the public key to compare with
|
|
75
|
+
* @returns whether they match
|
|
76
|
+
*/
|
|
77
|
+
this.equals = (p) => this.rawPubKey[0] === p.rawPubKey[0] && this.rawPubKey[1] === p.rawPubKey[1];
|
|
78
|
+
if (!allowInvalid) {
|
|
79
|
+
(0, assert_1.default)((0, crypto_1.inCurve)(rawPubKey), "PubKey not on curve");
|
|
80
|
+
}
|
|
81
|
+
this.rawPubKey = rawPubKey;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Serialize this object
|
|
85
|
+
*/
|
|
86
|
+
toJSON() {
|
|
87
|
+
return {
|
|
88
|
+
pubKey: this.serialize(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Deserialize a JSON object into a PubKey instance
|
|
93
|
+
* @param json - the json object
|
|
94
|
+
* @returns PubKey
|
|
95
|
+
*/
|
|
96
|
+
static fromJSON(json) {
|
|
97
|
+
return PubKey.deserialize(json.pubKey);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Generate a default pad key
|
|
101
|
+
* @returns a default pad key
|
|
102
|
+
*/
|
|
103
|
+
static genPadKey() {
|
|
104
|
+
// This public key is the first Pedersen base
|
|
105
|
+
// point from iden3's circomlib implementation of the Pedersen hash.
|
|
106
|
+
// Since it is generated using a hash-to-curve function, we are
|
|
107
|
+
// confident that no-one knows the private key associated with this
|
|
108
|
+
// public key. See:
|
|
109
|
+
// https://github.com/iden3/circomlib/blob/d5ed1c3ce4ca137a6b3ca48bec4ac12c1b38957a/src/pedersen_printbases.js
|
|
110
|
+
return new PubKey([
|
|
111
|
+
BigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),
|
|
112
|
+
BigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317"),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.PubKey = PubKey;
|
|
117
|
+
/**
|
|
118
|
+
* Deserialize a serialized public key
|
|
119
|
+
* @param s the serialized public key
|
|
120
|
+
* @returns the deserialized public key
|
|
121
|
+
*/
|
|
122
|
+
PubKey.deserialize = (s) => {
|
|
123
|
+
const len = exports.SERIALIZED_PUB_KEY_PREFIX.length;
|
|
124
|
+
return new PubKey((0, crypto_1.unpackPubKey)(BigInt(`0x${s.slice(len).toString()}`)));
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Check whether a serialized public key is serialized correctly
|
|
128
|
+
* @param s the serialized public key
|
|
129
|
+
* @returns whether the serialized public key is valid
|
|
130
|
+
*/
|
|
131
|
+
PubKey.isValidSerializedPubKey = (s) => {
|
|
132
|
+
const correctPrefix = s.startsWith(exports.SERIALIZED_PUB_KEY_PREFIX);
|
|
133
|
+
try {
|
|
134
|
+
PubKey.deserialize(s);
|
|
135
|
+
return correctPrefix;
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=publicKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicKey.js","sourceRoot":"","sources":["../../ts/publicKey.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAmH;AAEnH,oDAA4B;AAIf,QAAA,yBAAyB,GAAG,SAAS,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAa,MAAM;IAGjB;;;;;;;;;OASG;IACH,YAAY,SAAoB,EAAE,YAAY,GAAG,KAAK;QAOtD;;;WAGG;QACH,SAAI,GAAG,GAAW,EAAE,CAAC,IAAI,MAAM,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,CAAC,CAAC,CAAC;QAE9G;;;WAGG;QACH,oBAAe,GAAG,GAAsB,EAAE;YACxC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;YAE9B,OAAO;gBACL,CAAC,EAAE,CAAC,CAAC,QAAQ,E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Leaf, IStateLeafContractParams } from "./types";
|
|
2
|
+
import { PubKey } from "./publicKey";
|
|
3
|
+
/**
|
|
4
|
+
* @notice A leaf in the state tree, which maps
|
|
5
|
+
* public keys to voice credit balances
|
|
6
|
+
*/
|
|
7
|
+
export declare class StateLeaf implements IStateLeaf {
|
|
8
|
+
pubKey: PubKey;
|
|
9
|
+
voiceCreditBalance: bigint;
|
|
10
|
+
timestamp: bigint;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new instance of a state leaf
|
|
13
|
+
* @param pubKey the public key of the user signin up
|
|
14
|
+
* @param voiceCreditBalance the voice credit balance of the user
|
|
15
|
+
* @param timestamp the timestamp of when the user signed-up
|
|
16
|
+
*/
|
|
17
|
+
constructor(pubKey: PubKey, voiceCreditBalance: bigint, timestamp: bigint);
|
|
18
|
+
/**
|
|
19
|
+
* Crate a deep copy of the object
|
|
20
|
+
* @returns a copy of the state leaf
|
|
21
|
+
*/
|
|
22
|
+
copy(): StateLeaf;
|
|
23
|
+
/**
|
|
24
|
+
* Generate a blank state leaf
|
|
25
|
+
* @returns a blank state leaf
|
|
26
|
+
*/
|
|
27
|
+
static genBlankLeaf(): StateLeaf;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a random leaf (random salt and random key pair)
|
|
30
|
+
* @returns a random state leaf
|
|
31
|
+
*/
|
|
32
|
+
static genRandomLeaf(): StateLeaf;
|
|
33
|
+
/**
|
|
34
|
+
* Return this state leaf as an array of bigints
|
|
35
|
+
* @returns the state leaf as an array of bigints
|
|
36
|
+
*/
|
|
37
|
+
private asArray;
|
|
38
|
+
/**
|
|
39
|
+
* Return this state leaf as an array of bigints
|
|
40
|
+
* @returns the state leaf as an array of bigints
|
|
41
|
+
*/
|
|
42
|
+
asCircuitInputs: () => bigint[];
|
|
43
|
+
/**
|
|
44
|
+
* Hash this state leaf (first convert as array)
|
|
45
|
+
* @returns the has of the state leaf elements
|
|
46
|
+
*/
|
|
47
|
+
hash: () => bigint;
|
|
48
|
+
/**
|
|
49
|
+
* Return this state leaf as a contract param
|
|
50
|
+
* @returns the state leaf as a contract param (object)
|
|
51
|
+
*/
|
|
52
|
+
asContractParam(): IStateLeafContractParams;
|
|
53
|
+
/**
|
|
54
|
+
* Check if two state leaves are equal
|
|
55
|
+
* @param s the state leaf to compare with
|
|
56
|
+
* @returns whether they are equal or not
|
|
57
|
+
*/
|
|
58
|
+
equals(s: StateLeaf): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Serialize the state leaf
|
|
61
|
+
* @notice serialize the public key
|
|
62
|
+
* @notice convert the voice credit balance and timestamp to a hex string
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
serialize: () => string;
|
|
66
|
+
/**
|
|
67
|
+
* Deserialize the state leaf
|
|
68
|
+
* @param serialized the serialized state leaf
|
|
69
|
+
* @returns a deserialized state leaf
|
|
70
|
+
*/
|
|
71
|
+
static deserialize: (serialized: string) => StateLeaf;
|
|
72
|
+
/**
|
|
73
|
+
* Serialize to a JSON object
|
|
74
|
+
*/
|
|
75
|
+
toJSON(): IJsonStateLeaf;
|
|
76
|
+
/**
|
|
77
|
+
* Deserialize into a StateLeaf instance
|
|
78
|
+
* @param json - the json representation
|
|
79
|
+
* @returns the deserialized object as a StateLeaf instance
|
|
80
|
+
*/
|
|
81
|
+
static fromJSON(json: IJsonStateLeaf): StateLeaf;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=stateLeaf.d.ts.map
|
|
@@ -0,0 +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,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;GAGG;AACH,qBAAa,SAAU,YAAW,UAAU;IAC1C,MAAM,EAAE,MAAM,CAAC;IAEf,kBAAkB,EAAE,MAAM,CAAC;IAE3B,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAMzE;;;OAGG;IACH,IAAI,IAAI,SAAS;IAQjB;;;OAGG;IACH,MAAM,CAAC,YAAY,IAAI,SAAS;IAmBhC;;;OAGG;IACH,MAAM,CAAC,aAAa,IAAI,SAAS;IAKjC;;;OAGG;IACH,OAAO,CAAC,OAAO,CAAuF;IAEtG;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAmB;IAEjD;;;OAGG;IACH,IAAI,QAAO,MAAM,CAA0B;IAE3C;;;OAGG;IACH,eAAe,IAAI,wBAAwB;IAQ3C;;;;OAIG;IACH,MAAM,CAAC,CAAC,EAAE,SAAS,GAAG,OAAO;IAM7B;;;;;OAKG;IACH,SAAS,QAAO,MAAM,CAIpB;IAEF;;;;OAIG;IACH,MAAM,CAAC,WAAW,GAAI,YAAY,MAAM,KAAG,SAAS,CAKlD;IAEF;;OAEG;IACH,MAAM,IAAI,cAAc;IAQxB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,SAAS;CAGjD"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StateLeaf = void 0;
|
|
4
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
5
|
+
const keyPair_1 = require("./keyPair");
|
|
6
|
+
const publicKey_1 = require("./publicKey");
|
|
7
|
+
/**
|
|
8
|
+
* @notice A leaf in the state tree, which maps
|
|
9
|
+
* public keys to voice credit balances
|
|
10
|
+
*/
|
|
11
|
+
class StateLeaf {
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of a state leaf
|
|
14
|
+
* @param pubKey the public key of the user signin up
|
|
15
|
+
* @param voiceCreditBalance the voice credit balance of the user
|
|
16
|
+
* @param timestamp the timestamp of when the user signed-up
|
|
17
|
+
*/
|
|
18
|
+
constructor(pubKey, voiceCreditBalance, timestamp) {
|
|
19
|
+
/**
|
|
20
|
+
* Return this state leaf as an array of bigints
|
|
21
|
+
* @returns the state leaf as an array of bigints
|
|
22
|
+
*/
|
|
23
|
+
this.asArray = () => [...this.pubKey.asArray(), this.voiceCreditBalance, this.timestamp];
|
|
24
|
+
/**
|
|
25
|
+
* Return this state leaf as an array of bigints
|
|
26
|
+
* @returns the state leaf as an array of bigints
|
|
27
|
+
*/
|
|
28
|
+
this.asCircuitInputs = () => this.asArray();
|
|
29
|
+
/**
|
|
30
|
+
* Hash this state leaf (first convert as array)
|
|
31
|
+
* @returns the has of the state leaf elements
|
|
32
|
+
*/
|
|
33
|
+
this.hash = () => (0, crypto_1.hash4)(this.asArray());
|
|
34
|
+
/**
|
|
35
|
+
* Serialize the state leaf
|
|
36
|
+
* @notice serialize the public key
|
|
37
|
+
* @notice convert the voice credit balance and timestamp to a hex string
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
this.serialize = () => {
|
|
41
|
+
const j = [this.pubKey.serialize(), this.voiceCreditBalance.toString(16), this.timestamp.toString(16)];
|
|
42
|
+
return Buffer.from(JSON.stringify(j, null, 0), "utf8").toString("base64url");
|
|
43
|
+
};
|
|
44
|
+
this.pubKey = pubKey;
|
|
45
|
+
this.voiceCreditBalance = voiceCreditBalance;
|
|
46
|
+
this.timestamp = timestamp;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Crate a deep copy of the object
|
|
50
|
+
* @returns a copy of the state leaf
|
|
51
|
+
*/
|
|
52
|
+
copy() {
|
|
53
|
+
return new StateLeaf(this.pubKey.copy(), BigInt(this.voiceCreditBalance.toString()), BigInt(this.timestamp.toString()));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate a blank state leaf
|
|
57
|
+
* @returns a blank state leaf
|
|
58
|
+
*/
|
|
59
|
+
static genBlankLeaf() {
|
|
60
|
+
// The public key for a blank state leaf is the first Pedersen base
|
|
61
|
+
// point from iden3's circomlib implementation of the Pedersen hash.
|
|
62
|
+
// Since it is generated using a hash-to-curve function, we are
|
|
63
|
+
// confident that no-one knows the private key associated with this
|
|
64
|
+
// public key. See:
|
|
65
|
+
// https://github.com/iden3/circomlib/blob/d5ed1c3ce4ca137a6b3ca48bec4ac12c1b38957a/src/pedersen_printbases.js
|
|
66
|
+
// Its hash should equal
|
|
67
|
+
// 6769006970205099520508948723718471724660867171122235270773600567925038008762.
|
|
68
|
+
return new StateLeaf(new publicKey_1.PubKey([
|
|
69
|
+
BigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),
|
|
70
|
+
BigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317"),
|
|
71
|
+
]), BigInt(0), BigInt(0));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Generate a random leaf (random salt and random key pair)
|
|
75
|
+
* @returns a random state leaf
|
|
76
|
+
*/
|
|
77
|
+
static genRandomLeaf() {
|
|
78
|
+
const keypair = new keyPair_1.Keypair();
|
|
79
|
+
return new StateLeaf(keypair.pubKey, (0, crypto_1.genRandomSalt)(), BigInt(0));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Return this state leaf as a contract param
|
|
83
|
+
* @returns the state leaf as a contract param (object)
|
|
84
|
+
*/
|
|
85
|
+
asContractParam() {
|
|
86
|
+
return {
|
|
87
|
+
pubKey: this.pubKey.asContractParam(),
|
|
88
|
+
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
89
|
+
timestamp: this.timestamp.toString(),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if two state leaves are equal
|
|
94
|
+
* @param s the state leaf to compare with
|
|
95
|
+
* @returns whether they are equal or not
|
|
96
|
+
*/
|
|
97
|
+
equals(s) {
|
|
98
|
+
return (this.pubKey.equals(s.pubKey) && this.voiceCreditBalance === s.voiceCreditBalance && this.timestamp === s.timestamp);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Serialize to a JSON object
|
|
102
|
+
*/
|
|
103
|
+
toJSON() {
|
|
104
|
+
return {
|
|
105
|
+
pubKey: this.pubKey.serialize(),
|
|
106
|
+
voiceCreditBalance: this.voiceCreditBalance.toString(),
|
|
107
|
+
timestamp: this.timestamp.toString(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Deserialize into a StateLeaf instance
|
|
112
|
+
* @param json - the json representation
|
|
113
|
+
* @returns the deserialized object as a StateLeaf instance
|
|
114
|
+
*/
|
|
115
|
+
static fromJSON(json) {
|
|
116
|
+
return new StateLeaf(publicKey_1.PubKey.deserialize(json.pubKey), BigInt(json.voiceCreditBalance), BigInt(json.timestamp));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.StateLeaf = StateLeaf;
|
|
120
|
+
/**
|
|
121
|
+
* Deserialize the state leaf
|
|
122
|
+
* @param serialized the serialized state leaf
|
|
123
|
+
* @returns a deserialized state leaf
|
|
124
|
+
*/
|
|
125
|
+
StateLeaf.deserialize = (serialized) => {
|
|
126
|
+
const base64 = serialized.replace(/-/g, "+").replace(/_/g, "/");
|
|
127
|
+
const json = JSON.parse(Buffer.from(base64, "base64").toString("utf8"));
|
|
128
|
+
return new StateLeaf(publicKey_1.PubKey.deserialize(json[0]), BigInt(`0x${json[1]}`), BigInt(`0x${json[2]}`));
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=stateLeaf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stateLeaf.js","sourceRoot":"","sources":["../../ts/stateLeaf.ts"],"names":[],"mappings":";;;AAAA,kDAA6D;AAI7D,uCAAoC;AACpC,2CAAqC;AAErC;;;GAGG;AACH,MAAa,SAAS;IAOpB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,kBAA0B,EAAE,SAAiB;QAkDz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