@maci-protocol/domainobjs 0.0.0-ci.26f28d6
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,171 @@
|
|
|
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.PCommand = void 0;
|
|
7
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const message_1 = require("../message");
|
|
10
|
+
const publicKey_1 = require("../publicKey");
|
|
11
|
+
/**
|
|
12
|
+
* @notice Unencrypted data whose fields include the user's public key, vote etc.
|
|
13
|
+
* This represents a Vote command.
|
|
14
|
+
*/
|
|
15
|
+
class PCommand {
|
|
16
|
+
/**
|
|
17
|
+
* Create a new PCommand
|
|
18
|
+
* @param stateIndex the state index of the user
|
|
19
|
+
* @param newPubKey the new public key of the user
|
|
20
|
+
* @param voteOptionIndex the index of the vote option
|
|
21
|
+
* @param newVoteWeight the new vote weight of the user
|
|
22
|
+
* @param nonce the nonce of the message
|
|
23
|
+
* @param pollId the poll ID
|
|
24
|
+
* @param salt the salt of the message
|
|
25
|
+
*/
|
|
26
|
+
constructor(stateIndex, newPubKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt = (0, crypto_1.genRandomSalt)()) {
|
|
27
|
+
/**
|
|
28
|
+
* Create a deep clone of this PCommand
|
|
29
|
+
* @returns a copy of the PCommand
|
|
30
|
+
*/
|
|
31
|
+
this.copy = () => new PCommand(BigInt(this.stateIndex.toString()), this.newPubKey.copy(), BigInt(this.voteOptionIndex.toString()), BigInt(this.newVoteWeight.toString()), BigInt(this.nonce.toString()), BigInt(this.pollId.toString()), BigInt(this.salt.toString()));
|
|
32
|
+
/**
|
|
33
|
+
* @notice Returns this Command as an array. Note that 5 of the Command's fields
|
|
34
|
+
* are packed into a single 250-bit value. This allows Messages to be
|
|
35
|
+
* smaller and thereby save gas when the user publishes a message.
|
|
36
|
+
* @returns bigint[] - the command as an array
|
|
37
|
+
*/
|
|
38
|
+
this.asArray = () => {
|
|
39
|
+
/* eslint-disable no-bitwise */
|
|
40
|
+
const params = BigInt(this.stateIndex) +
|
|
41
|
+
(BigInt(this.voteOptionIndex) << BigInt(50)) +
|
|
42
|
+
(BigInt(this.newVoteWeight) << BigInt(100)) +
|
|
43
|
+
(BigInt(this.nonce) << BigInt(150)) +
|
|
44
|
+
(BigInt(this.pollId) << BigInt(200));
|
|
45
|
+
/* eslint-enable no-bitwise */
|
|
46
|
+
const command = [params, ...this.newPubKey.asArray(), this.salt];
|
|
47
|
+
(0, assert_1.default)(command.length === 4);
|
|
48
|
+
return command;
|
|
49
|
+
};
|
|
50
|
+
this.asCircuitInputs = () => this.asArray();
|
|
51
|
+
/*
|
|
52
|
+
* Check whether this command has deep equivalence to another command
|
|
53
|
+
*/
|
|
54
|
+
this.equals = (command) => this.stateIndex === command.stateIndex &&
|
|
55
|
+
this.newPubKey.equals(command.newPubKey) &&
|
|
56
|
+
this.voteOptionIndex === command.voteOptionIndex &&
|
|
57
|
+
this.newVoteWeight === command.newVoteWeight &&
|
|
58
|
+
this.nonce === command.nonce &&
|
|
59
|
+
this.pollId === command.pollId &&
|
|
60
|
+
this.salt === command.salt;
|
|
61
|
+
this.hash = () => (0, crypto_1.hash4)(this.asArray());
|
|
62
|
+
/**
|
|
63
|
+
* @notice Signs this command and returns a Signature.
|
|
64
|
+
*/
|
|
65
|
+
this.sign = (privKey) => (0, crypto_1.sign)(privKey.rawPrivKey.toString(), this.hash());
|
|
66
|
+
/**
|
|
67
|
+
* @notice Returns true if the given signature is a correct signature of this
|
|
68
|
+
* command and signed by the private key associated with the given public
|
|
69
|
+
* key.
|
|
70
|
+
*/
|
|
71
|
+
this.verifySignature = (signature, pubKey) => (0, crypto_1.verifySignature)(this.hash(), signature, pubKey.rawPubKey);
|
|
72
|
+
/**
|
|
73
|
+
* @notice Encrypts this command along with a signature to produce a Message.
|
|
74
|
+
* To save gas, we can constrain the following values to 50 bits and pack
|
|
75
|
+
* them into a 250-bit value:
|
|
76
|
+
* 0. state index
|
|
77
|
+
* 3. vote option index
|
|
78
|
+
* 4. new vote weight
|
|
79
|
+
* 5. nonce
|
|
80
|
+
* 6. poll ID
|
|
81
|
+
*/
|
|
82
|
+
this.encrypt = (signature, sharedKey) => {
|
|
83
|
+
const plaintext = [...this.asArray(), BigInt(signature.R8[0]), BigInt(signature.R8[1]), BigInt(signature.S)];
|
|
84
|
+
(0, assert_1.default)(plaintext.length === 7);
|
|
85
|
+
const ciphertext = (0, crypto_1.poseidonEncrypt)(plaintext, sharedKey, BigInt(0));
|
|
86
|
+
const message = new message_1.Message(ciphertext);
|
|
87
|
+
return message;
|
|
88
|
+
};
|
|
89
|
+
const limit50Bits = BigInt(2 ** 50);
|
|
90
|
+
(0, assert_1.default)(limit50Bits >= stateIndex);
|
|
91
|
+
(0, assert_1.default)(limit50Bits >= voteOptionIndex);
|
|
92
|
+
(0, assert_1.default)(limit50Bits >= newVoteWeight);
|
|
93
|
+
(0, assert_1.default)(limit50Bits >= nonce);
|
|
94
|
+
(0, assert_1.default)(limit50Bits >= pollId);
|
|
95
|
+
this.stateIndex = stateIndex;
|
|
96
|
+
this.newPubKey = newPubKey;
|
|
97
|
+
this.voteOptionIndex = voteOptionIndex;
|
|
98
|
+
this.newVoteWeight = newVoteWeight;
|
|
99
|
+
this.nonce = nonce;
|
|
100
|
+
this.pollId = pollId;
|
|
101
|
+
this.salt = salt;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Serialize into a JSON object
|
|
105
|
+
*/
|
|
106
|
+
toJSON() {
|
|
107
|
+
return {
|
|
108
|
+
stateIndex: this.stateIndex.toString(),
|
|
109
|
+
newPubKey: this.newPubKey.serialize(),
|
|
110
|
+
voteOptionIndex: this.voteOptionIndex.toString(),
|
|
111
|
+
newVoteWeight: this.newVoteWeight.toString(),
|
|
112
|
+
nonce: this.nonce.toString(),
|
|
113
|
+
pollId: this.pollId.toString(),
|
|
114
|
+
salt: this.salt.toString(),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Deserialize into a PCommand instance
|
|
119
|
+
* @param json
|
|
120
|
+
* @returns a PCommand instance
|
|
121
|
+
*/
|
|
122
|
+
static fromJSON(json) {
|
|
123
|
+
const command = new PCommand(BigInt(json.stateIndex), publicKey_1.PubKey.deserialize(json.newPubKey), BigInt(json.voteOptionIndex), BigInt(json.newVoteWeight), BigInt(json.nonce), BigInt(json.pollId), BigInt(json.salt));
|
|
124
|
+
return command;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.PCommand = PCommand;
|
|
128
|
+
/**
|
|
129
|
+
* Decrypts a Message to produce a Command.
|
|
130
|
+
* @dev You can force decrypt the message by setting `force` to true.
|
|
131
|
+
* This is useful in case you don't want an invalid message to throw an error.
|
|
132
|
+
* @param message - the message to decrypt
|
|
133
|
+
* @param sharedKey - the shared key to use for decryption
|
|
134
|
+
* @param force - whether to force decryption or not
|
|
135
|
+
*/
|
|
136
|
+
PCommand.decrypt = (message, sharedKey, force = false) => {
|
|
137
|
+
const decrypted = force
|
|
138
|
+
? (0, crypto_1.poseidonDecryptWithoutCheck)(message.data, sharedKey, BigInt(0), 7)
|
|
139
|
+
: (0, crypto_1.poseidonDecrypt)(message.data, sharedKey, BigInt(0), 7);
|
|
140
|
+
const p = BigInt(decrypted[0].toString());
|
|
141
|
+
// Returns the value of the 50 bits at position `pos` in `val`
|
|
142
|
+
// create 50 '1' bits
|
|
143
|
+
// shift left by pos
|
|
144
|
+
// AND with val
|
|
145
|
+
// shift right by pos
|
|
146
|
+
const extract = (val, pos) =>
|
|
147
|
+
// eslint-disable-next-line no-bitwise
|
|
148
|
+
BigInt((((BigInt(1) << BigInt(50)) - BigInt(1)) << BigInt(pos)) & val) >> BigInt(pos);
|
|
149
|
+
// p is a packed value
|
|
150
|
+
// bits 0 - 50: stateIndex
|
|
151
|
+
// bits 51 - 100: voteOptionIndex
|
|
152
|
+
// bits 101 - 150: newVoteWeight
|
|
153
|
+
// bits 151 - 200: nonce
|
|
154
|
+
// bits 201 - 250: pollId
|
|
155
|
+
const stateIndex = extract(p, 0);
|
|
156
|
+
const voteOptionIndex = extract(p, 50);
|
|
157
|
+
const newVoteWeight = extract(p, 100);
|
|
158
|
+
const nonce = extract(p, 150);
|
|
159
|
+
const pollId = extract(p, 200);
|
|
160
|
+
// create new public key but allow it to be invalid (as when passing an mismatched
|
|
161
|
+
// encPubKey, a message will not decrypt resulting in potentially invalid public keys)
|
|
162
|
+
const newPubKey = new publicKey_1.PubKey([decrypted[1], decrypted[2]], true);
|
|
163
|
+
const salt = decrypted[3];
|
|
164
|
+
const command = new PCommand(stateIndex, newPubKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt);
|
|
165
|
+
const signature = {
|
|
166
|
+
R8: [decrypted[4], decrypted[5]],
|
|
167
|
+
S: decrypted[6],
|
|
168
|
+
};
|
|
169
|
+
return { command, signature };
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=PCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PCommand.js","sourceRoot":"","sources":["../../../ts/commands/PCommand.ts"],"names":[],"mappings":";;;;;;AAAA,kDAY+B;AAE/B,oDAA4B;AAK5B,wCAAqC;AACrC,4CAAsC;AAOtC;;;GAG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E,SAAS,CAAC,CAAC,CAAC;KAChB,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC,AAzCa,CAyCZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PCommand = void 0;
|
|
4
|
+
var PCommand_1 = require("./PCommand");
|
|
5
|
+
Object.defineProperty(exports, "PCommand", { enumerable: true, get: function () { return PCommand_1.PCommand; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":";;;AAAA,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @notice An interface representing a json T command
|
|
3
|
+
*/
|
|
4
|
+
export interface IJsonTCommand {
|
|
5
|
+
stateIndex: string;
|
|
6
|
+
amount: string;
|
|
7
|
+
pollId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @notice An interface representing a json P command
|
|
11
|
+
*/
|
|
12
|
+
export interface IJsonPCommand {
|
|
13
|
+
stateIndex: string;
|
|
14
|
+
newPubKey: string;
|
|
15
|
+
voteOptionIndex: string;
|
|
16
|
+
newVoteWeight: string;
|
|
17
|
+
nonce: string;
|
|
18
|
+
pollId: string;
|
|
19
|
+
salt: string;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../ts/commands/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../ts/commands/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,eAAO,MAAM,cAAc,WAA2B,CAAC;AACvD,eAAO,MAAM,kBAAkB,QAAwB,CAAC;AACxD,eAAO,MAAM,MAAM,QAAqB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.padKey = exports.blankStateLeafHash = exports.blankStateLeaf = void 0;
|
|
4
|
+
const publicKey_1 = require("./publicKey");
|
|
5
|
+
const stateLeaf_1 = require("./stateLeaf");
|
|
6
|
+
exports.blankStateLeaf = stateLeaf_1.StateLeaf.genBlankLeaf();
|
|
7
|
+
exports.blankStateLeafHash = exports.blankStateLeaf.hash();
|
|
8
|
+
exports.padKey = publicKey_1.PubKey.genPadKey();
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":";;;AAAA,2CAAqC;AACrC,2CAAwC;AAE3B,QAAA,cAAc,GAAG,qBAAS,CAAC,YAAY,EAAE,CAAC;AAC1C,QAAA,kBAAkB,GAAG,sBAAc,CAAC,IAAI,EAAE,CAAC;AAC3C,QAAA,MAAM,GAAG,kBAAM,CAAC,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Ballot } from "./ballot";
|
|
2
|
+
export { Message } from "./message";
|
|
3
|
+
export { PrivKey, SERIALIZED_PRIV_KEY_PREFIX } from "./privateKey";
|
|
4
|
+
export { PubKey, SERIALIZED_PUB_KEY_PREFIX } from "./publicKey";
|
|
5
|
+
export { Keypair } from "./keyPair";
|
|
6
|
+
export { StateLeaf } from "./stateLeaf";
|
|
7
|
+
export { blankStateLeaf, blankStateLeafHash, padKey } from "./constants";
|
|
8
|
+
export type { Proof, IStateLeaf, VoteOptionTreeLeaf, IJsonKeyPair, IJsonPrivateKey, IJsonPublicKey, IJsonStateLeaf, IG1ContractParams, IG2ContractParams, IVkContractParams, IVkObjectParams, IStateLeafContractParams, IMessageContractParams, IJsonBallot, } from "./types";
|
|
9
|
+
export { type IJsonTCommand, type IJsonPCommand, PCommand } from "./commands";
|
|
10
|
+
export { VerifyingKey } from "./verifyingKey";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../ts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzE,YAAY,EACV,KAAK,EACL,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VerifyingKey = exports.PCommand = exports.padKey = exports.blankStateLeafHash = exports.blankStateLeaf = exports.StateLeaf = exports.Keypair = exports.SERIALIZED_PUB_KEY_PREFIX = exports.PubKey = exports.SERIALIZED_PRIV_KEY_PREFIX = exports.PrivKey = exports.Message = exports.Ballot = void 0;
|
|
4
|
+
var ballot_1 = require("./ballot");
|
|
5
|
+
Object.defineProperty(exports, "Ballot", { enumerable: true, get: function () { return ballot_1.Ballot; } });
|
|
6
|
+
var message_1 = require("./message");
|
|
7
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.Message; } });
|
|
8
|
+
var privateKey_1 = require("./privateKey");
|
|
9
|
+
Object.defineProperty(exports, "PrivKey", { enumerable: true, get: function () { return privateKey_1.PrivKey; } });
|
|
10
|
+
Object.defineProperty(exports, "SERIALIZED_PRIV_KEY_PREFIX", { enumerable: true, get: function () { return privateKey_1.SERIALIZED_PRIV_KEY_PREFIX; } });
|
|
11
|
+
var publicKey_1 = require("./publicKey");
|
|
12
|
+
Object.defineProperty(exports, "PubKey", { enumerable: true, get: function () { return publicKey_1.PubKey; } });
|
|
13
|
+
Object.defineProperty(exports, "SERIALIZED_PUB_KEY_PREFIX", { enumerable: true, get: function () { return publicKey_1.SERIALIZED_PUB_KEY_PREFIX; } });
|
|
14
|
+
var keyPair_1 = require("./keyPair");
|
|
15
|
+
Object.defineProperty(exports, "Keypair", { enumerable: true, get: function () { return keyPair_1.Keypair; } });
|
|
16
|
+
var stateLeaf_1 = require("./stateLeaf");
|
|
17
|
+
Object.defineProperty(exports, "StateLeaf", { enumerable: true, get: function () { return stateLeaf_1.StateLeaf; } });
|
|
18
|
+
var constants_1 = require("./constants");
|
|
19
|
+
Object.defineProperty(exports, "blankStateLeaf", { enumerable: true, get: function () { return constants_1.blankStateLeaf; } });
|
|
20
|
+
Object.defineProperty(exports, "blankStateLeafHash", { enumerable: true, get: function () { return constants_1.blankStateLeafHash; } });
|
|
21
|
+
Object.defineProperty(exports, "padKey", { enumerable: true, get: function () { return constants_1.padKey; } });
|
|
22
|
+
var commands_1 = require("./commands");
|
|
23
|
+
Object.defineProperty(exports, "PCommand", { enumerable: true, get: function () { return commands_1.PCommand; } });
|
|
24
|
+
var verifyingKey_1 = require("./verifyingKey");
|
|
25
|
+
Object.defineProperty(exports, "VerifyingKey", { enumerable: true, get: function () { return verifyingKey_1.VerifyingKey; } });
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../ts/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAAzB,gGAAA,MAAM,OAAA;AAEf,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,2CAAmE;AAA1D,qGAAA,OAAO,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AAE5C,yCAAgE;AAAvD,mGAAA,MAAM,OAAA;AAAE,sHAAA,yBAAyB,OAAA;AAE1C,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAElB,yCAAyE;AAAhE,2GAAA,cAAc,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAAE,mGAAA,MAAM,OAAA;AAmBnD,uCAA8E;AAA7B,oGAAA,QAAQ,OAAA;AAEzD,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { EcdhSharedKey } from "@maci-protocol/crypto";
|
|
2
|
+
import type { IJsonKeyPair } from "./types";
|
|
3
|
+
import { PrivKey } from "./privateKey";
|
|
4
|
+
import { PubKey } from "./publicKey";
|
|
5
|
+
/**
|
|
6
|
+
* @notice A KeyPair is a pair of public and private keys
|
|
7
|
+
* This is a MACI keypair, which is not to be
|
|
8
|
+
* confused with an Ethereum public and private keypair.
|
|
9
|
+
* A MACI keypair is comprised of a MACI public key and a MACI private key
|
|
10
|
+
*/
|
|
11
|
+
export declare class Keypair {
|
|
12
|
+
privKey: PrivKey;
|
|
13
|
+
pubKey: PubKey;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of a Keypair
|
|
16
|
+
* @param privKey the private key (optional)
|
|
17
|
+
* @notice if no privKey is passed, it will automatically generate a new private key
|
|
18
|
+
*/
|
|
19
|
+
constructor(privKey?: PrivKey);
|
|
20
|
+
/**
|
|
21
|
+
* Create a deep clone of this Keypair
|
|
22
|
+
* @returns a copy of the Keypair
|
|
23
|
+
*/
|
|
24
|
+
copy: () => Keypair;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a shared key
|
|
27
|
+
* @param privKey
|
|
28
|
+
* @param pubKey
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
static genEcdhSharedKey(privKey: PrivKey, pubKey: PubKey): EcdhSharedKey;
|
|
32
|
+
/**
|
|
33
|
+
* Check whether two Keypairs are equal
|
|
34
|
+
* @param keypair the keypair to compare with
|
|
35
|
+
* @returns whether they are equal or not
|
|
36
|
+
*/
|
|
37
|
+
equals(keypair: Keypair): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Serialize into a JSON object
|
|
40
|
+
*/
|
|
41
|
+
toJSON(): IJsonKeyPair;
|
|
42
|
+
/**
|
|
43
|
+
* Deserialize into a Keypair instance
|
|
44
|
+
* @param json
|
|
45
|
+
* @returns a keypair instance
|
|
46
|
+
*/
|
|
47
|
+
static fromJSON(json: IJsonKeyPair): Keypair;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=keyPair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyPair.d.ts","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2C,MAAM,uBAAuB,CAAC;AAI/F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,OAAO,EAAE,OAAO,CAAC;IAEjB,MAAM,EAAE,MAAM,CAAC;IAEf;;;;OAIG;gBACS,OAAO,CAAC,EAAE,OAAO;IAW7B;;;OAGG;IACH,IAAI,QAAO,OAAO,CAAqC;IAEvD;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa;IAIxE;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAcjC;;OAEG;IACH,MAAM,IAAI,YAAY;IAOtB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;CAG7C"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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.Keypair = void 0;
|
|
7
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
const privateKey_1 = require("./privateKey");
|
|
10
|
+
const publicKey_1 = require("./publicKey");
|
|
11
|
+
/**
|
|
12
|
+
* @notice A KeyPair is a pair of public and private keys
|
|
13
|
+
* This is a MACI keypair, which is not to be
|
|
14
|
+
* confused with an Ethereum public and private keypair.
|
|
15
|
+
* A MACI keypair is comprised of a MACI public key and a MACI private key
|
|
16
|
+
*/
|
|
17
|
+
class Keypair {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of a Keypair
|
|
20
|
+
* @param privKey the private key (optional)
|
|
21
|
+
* @notice if no privKey is passed, it will automatically generate a new private key
|
|
22
|
+
*/
|
|
23
|
+
constructor(privKey) {
|
|
24
|
+
/**
|
|
25
|
+
* Create a deep clone of this Keypair
|
|
26
|
+
* @returns a copy of the Keypair
|
|
27
|
+
*/
|
|
28
|
+
this.copy = () => new Keypair(this.privKey.copy());
|
|
29
|
+
if (privKey) {
|
|
30
|
+
this.privKey = privKey;
|
|
31
|
+
this.pubKey = new publicKey_1.PubKey((0, crypto_1.genPubKey)(privKey.rawPrivKey));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const rawKeyPair = (0, crypto_1.genKeypair)();
|
|
35
|
+
this.privKey = new privateKey_1.PrivKey(rawKeyPair.privKey);
|
|
36
|
+
this.pubKey = new publicKey_1.PubKey(rawKeyPair.pubKey);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate a shared key
|
|
41
|
+
* @param privKey
|
|
42
|
+
* @param pubKey
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
static genEcdhSharedKey(privKey, pubKey) {
|
|
46
|
+
return (0, crypto_1.genEcdhSharedKey)(privKey.rawPrivKey, pubKey.rawPubKey);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check whether two Keypairs are equal
|
|
50
|
+
* @param keypair the keypair to compare with
|
|
51
|
+
* @returns whether they are equal or not
|
|
52
|
+
*/
|
|
53
|
+
equals(keypair) {
|
|
54
|
+
const equalPrivKey = this.privKey.rawPrivKey === keypair.privKey.rawPrivKey;
|
|
55
|
+
const equalPubKey = this.pubKey.rawPubKey[0] === keypair.pubKey.rawPubKey[0] &&
|
|
56
|
+
this.pubKey.rawPubKey[1] === keypair.pubKey.rawPubKey[1];
|
|
57
|
+
// If this assertion fails, something is very wrong and this function
|
|
58
|
+
// should not return anything
|
|
59
|
+
// eslint-disable-next-line no-bitwise
|
|
60
|
+
(0, assert_1.default)(!(+equalPrivKey ^ +equalPubKey));
|
|
61
|
+
return equalPrivKey;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Serialize into a JSON object
|
|
65
|
+
*/
|
|
66
|
+
toJSON() {
|
|
67
|
+
return {
|
|
68
|
+
privKey: this.privKey.serialize(),
|
|
69
|
+
pubKey: this.pubKey.serialize(),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Deserialize into a Keypair instance
|
|
74
|
+
* @param json
|
|
75
|
+
* @returns a keypair instance
|
|
76
|
+
*/
|
|
77
|
+
static fromJSON(json) {
|
|
78
|
+
return new Keypair(privateKey_1.PrivKey.deserialize(json.privKey));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.Keypair = Keypair;
|
|
82
|
+
//# sourceMappingURL=keyPair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyPair.js","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA+F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BAA6B;QAC7B,sCAAsC;QACtC,IAAA,gBAAM,EAAC,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QAExC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YACjC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;SAChC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAkB;QAChC,OAAO,IAAI,OAAO,CAAC,oBAAO,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACxD,CAAC;CACF;AA1ED,0BA0EC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PubKey } from "./publicKey";
|
|
2
|
+
import type { IMessageContractParams } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* @notice An encrypted command and signature.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Message {
|
|
7
|
+
data: bigint[];
|
|
8
|
+
static DATA_LENGTH: number;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new instance of a Message
|
|
11
|
+
* @param msgType the type of the message
|
|
12
|
+
* @param data the data of the message
|
|
13
|
+
*/
|
|
14
|
+
constructor(data: bigint[]);
|
|
15
|
+
/**
|
|
16
|
+
* Return the message as an array of bigints
|
|
17
|
+
* @returns the message as an array of bigints
|
|
18
|
+
*/
|
|
19
|
+
private asArray;
|
|
20
|
+
/**
|
|
21
|
+
* Return the message as a contract param
|
|
22
|
+
* @returns the message as a contract param
|
|
23
|
+
*/
|
|
24
|
+
asContractParam: () => IMessageContractParams;
|
|
25
|
+
/**
|
|
26
|
+
* Return the message as a circuit input
|
|
27
|
+
* @returns the message as a circuit input
|
|
28
|
+
*/
|
|
29
|
+
asCircuitInputs: () => bigint[];
|
|
30
|
+
/**
|
|
31
|
+
* Hash the message data and a public key
|
|
32
|
+
* @param encPubKey the public key that is used to encrypt this message
|
|
33
|
+
* @returns the hash of the message data and the public key
|
|
34
|
+
*/
|
|
35
|
+
hash: (encPubKey: PubKey) => bigint;
|
|
36
|
+
/**
|
|
37
|
+
* Create a copy of the message
|
|
38
|
+
* @returns a copy of the message
|
|
39
|
+
*/
|
|
40
|
+
copy: () => Message;
|
|
41
|
+
/**
|
|
42
|
+
* Check if two messages are equal
|
|
43
|
+
* @param m the message to compare with
|
|
44
|
+
* @returns the result of the comparison
|
|
45
|
+
*/
|
|
46
|
+
equals: (m: Message) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Serialize to a JSON object
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): IMessageContractParams;
|
|
51
|
+
/**
|
|
52
|
+
* Deserialize into a Message instance
|
|
53
|
+
* @param json - the json representation
|
|
54
|
+
* @returns the deserialized object as a Message instance
|
|
55
|
+
*/
|
|
56
|
+
static fromJSON(json: IMessageContractParams): Message;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../ts/message.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,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,WAAW,MAAM,KAAG,MAAM,CAAmD;IAErF;;;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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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.Message = void 0;
|
|
7
|
+
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
|
+
const assert_1 = __importDefault(require("assert"));
|
|
9
|
+
/**
|
|
10
|
+
* @notice An encrypted command and signature.
|
|
11
|
+
*/
|
|
12
|
+
class Message {
|
|
13
|
+
/**
|
|
14
|
+
* Create a new instance of a Message
|
|
15
|
+
* @param msgType the type of the message
|
|
16
|
+
* @param data the data of the message
|
|
17
|
+
*/
|
|
18
|
+
constructor(data) {
|
|
19
|
+
/**
|
|
20
|
+
* Return the message as an array of bigints
|
|
21
|
+
* @returns the message as an array of bigints
|
|
22
|
+
*/
|
|
23
|
+
this.asArray = () => this.data;
|
|
24
|
+
/**
|
|
25
|
+
* Return the message as a contract param
|
|
26
|
+
* @returns the message as a contract param
|
|
27
|
+
*/
|
|
28
|
+
this.asContractParam = () => ({
|
|
29
|
+
data: this.data.map((x) => x.toString()),
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Return the message as a circuit input
|
|
33
|
+
* @returns the message as a circuit input
|
|
34
|
+
*/
|
|
35
|
+
this.asCircuitInputs = () => this.asArray();
|
|
36
|
+
/**
|
|
37
|
+
* Hash the message data and a public key
|
|
38
|
+
* @param encPubKey the public key that is used to encrypt this message
|
|
39
|
+
* @returns the hash of the message data and the public key
|
|
40
|
+
*/
|
|
41
|
+
this.hash = (encPubKey) => (0, crypto_1.hash12)([...this.data, ...encPubKey.rawPubKey]);
|
|
42
|
+
/**
|
|
43
|
+
* Create a copy of the message
|
|
44
|
+
* @returns a copy of the message
|
|
45
|
+
*/
|
|
46
|
+
this.copy = () => new Message(this.data.map((x) => BigInt(x.toString())));
|
|
47
|
+
/**
|
|
48
|
+
* Check if two messages are equal
|
|
49
|
+
* @param m the message to compare with
|
|
50
|
+
* @returns the result of the comparison
|
|
51
|
+
*/
|
|
52
|
+
this.equals = (m) => {
|
|
53
|
+
if (this.data.length !== m.data.length) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return this.data.every((data, index) => data === m.data[index]);
|
|
57
|
+
};
|
|
58
|
+
(0, assert_1.default)(data.length === Message.DATA_LENGTH);
|
|
59
|
+
this.data = data;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Serialize to a JSON object
|
|
63
|
+
*/
|
|
64
|
+
toJSON() {
|
|
65
|
+
return this.asContractParam();
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Deserialize into a Message instance
|
|
69
|
+
* @param json - the json representation
|
|
70
|
+
* @returns the deserialized object as a Message instance
|
|
71
|
+
*/
|
|
72
|
+
static fromJSON(json) {
|
|
73
|
+
return new Message(json.data.map((x) => BigInt(x)));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Message = Message;
|
|
77
|
+
Message.DATA_LENGTH = 10;
|
|
78
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +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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