@maci-protocol/domainobjs 0.0.0-ci.bab2f09 → 0.0.0-ci.bd42e06
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 +15 -15
- package/build/ts/ballot.js.map +1 -1
- package/build/ts/commands/{PCommand.d.ts → VoteCommand.d.ts} +18 -18
- package/build/ts/commands/VoteCommand.d.ts.map +1 -0
- package/build/ts/commands/{PCommand.js → VoteCommand.js} +30 -30
- package/build/ts/commands/VoteCommand.js.map +1 -0
- package/build/ts/commands/index.d.ts +1 -1
- package/build/ts/commands/index.d.ts.map +1 -1
- package/build/ts/commands/index.js +3 -3
- package/build/ts/commands/index.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 +4 -4
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +4 -4
- 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 +7 -9
- package/build/ts/stateLeaf.d.ts.map +1 -1
- package/build/ts/stateLeaf.js +20 -24
- package/build/ts/stateLeaf.js.map +1 -1
- package/build/ts/types.d.ts +10 -12
- 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
- package/build/ts/commands/PCommand.d.ts.map +0 -1
- package/build/ts/commands/PCommand.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
4
|
-
Cory Dickson, Han Jian, Chih-Cheng Liang, and Koh Wei Jie
|
|
3
|
+
Copyright (c) 2025 Ethereum Foundation
|
|
5
4
|
|
|
6
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/build/ts/ballot.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare class Ballot {
|
|
|
9
9
|
voteOptionTreeDepth: number;
|
|
10
10
|
/**
|
|
11
11
|
* Create a new Ballot instance
|
|
12
|
-
* @param
|
|
12
|
+
* @param _totalVoteOptions How many vote options are available in the poll
|
|
13
13
|
* @param _voteOptionTreeDepth The depth of the merkle tree holding the vote options
|
|
14
14
|
*/
|
|
15
|
-
constructor(
|
|
15
|
+
constructor(_totalVoteOptions: number, _voteOptionTreeDepth: number);
|
|
16
16
|
/**
|
|
17
17
|
* Generate an hash of this ballot
|
|
18
18
|
* @returns The hash of the ballot
|
|
@@ -42,18 +42,18 @@ export declare class Ballot {
|
|
|
42
42
|
equals(b: Ballot): boolean;
|
|
43
43
|
/**
|
|
44
44
|
* Generate a random ballot
|
|
45
|
-
* @param
|
|
45
|
+
* @param totalVoteOptions How many vote options are available
|
|
46
46
|
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
47
47
|
* @returns a random Ballot
|
|
48
48
|
*/
|
|
49
|
-
static genRandomBallot(
|
|
49
|
+
static genRandomBallot(totalVoteOptions: number, voteOptionTreeDepth: number): Ballot;
|
|
50
50
|
/**
|
|
51
51
|
* Generate a blank ballot
|
|
52
|
-
* @param
|
|
52
|
+
* @param totalVoteOptions How many vote options are available
|
|
53
53
|
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
54
54
|
* @returns a Blank Ballot object
|
|
55
55
|
*/
|
|
56
|
-
static genBlankBallot(
|
|
56
|
+
static genBlankBallot(totalVoteOptions: number, voteOptionTreeDepth: number): Ballot;
|
|
57
57
|
/**
|
|
58
58
|
* Serialize to a JSON object
|
|
59
59
|
*/
|
package/build/ts/ballot.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ballot.d.ts","sourceRoot":"","sources":["../../ts/ballot.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,qBAAa,MAAM;IACjB,KAAK,EAAE,MAAM,EAAE,CAAM;IAErB,KAAK,SAAa;IAElB,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;gBACS,
|
|
1
|
+
{"version":3,"file":"ballot.d.ts","sourceRoot":"","sources":["../../ts/ballot.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;GAGG;AACH,qBAAa,MAAM;IACjB,KAAK,EAAE,MAAM,EAAE,CAAM;IAErB,KAAK,SAAa;IAElB,mBAAmB,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;gBACS,iBAAiB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM;IASnE;;;OAGG;IACH,IAAI,QAAO,MAAM,CAGf;IAEF;;;OAGG;IACH,eAAe,QAAO,MAAM,EAAE,CAAmB;IAEjD;;;;OAIG;IACH,OAAO,QAAO,MAAM,EAAE,CAWpB;IAEF;;;OAGG;IACH,IAAI,QAAO,MAAM,CAMf;IAEF;;;;OAIG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;IAK1B;;;;;OAKG;IACH,MAAM,CAAC,eAAe,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,MAAM;IAMrF;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAG,MAAM;IAKpF;;OAEG;IACH,MAAM,IAAI,WAAW;IAQrB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM;CAM3C"}
|
package/build/ts/ballot.js
CHANGED
|
@@ -13,10 +13,10 @@ const assert_1 = __importDefault(require("assert"));
|
|
|
13
13
|
class Ballot {
|
|
14
14
|
/**
|
|
15
15
|
* Create a new Ballot instance
|
|
16
|
-
* @param
|
|
16
|
+
* @param _totalVoteOptions How many vote options are available in the poll
|
|
17
17
|
* @param _voteOptionTreeDepth The depth of the merkle tree holding the vote options
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(_totalVoteOptions, _voteOptionTreeDepth) {
|
|
20
20
|
this.votes = [];
|
|
21
21
|
this.nonce = BigInt(0);
|
|
22
22
|
/**
|
|
@@ -41,11 +41,11 @@ class Ballot {
|
|
|
41
41
|
const lastIndex = this.votes.length - 1;
|
|
42
42
|
const foundIndex = this.votes.findIndex((_, index) => this.votes[lastIndex - index] !== BigInt(0));
|
|
43
43
|
const lastIndexToInsert = foundIndex < 0 ? -1 : lastIndex - foundIndex;
|
|
44
|
-
const
|
|
44
|
+
const voteTree = new crypto_1.IncrementalQuinTree(this.voteOptionTreeDepth, BigInt(0), 5, crypto_1.hash5);
|
|
45
45
|
for (let i = 0; i <= lastIndexToInsert; i += 1) {
|
|
46
|
-
|
|
46
|
+
voteTree.insert(this.votes[i]);
|
|
47
47
|
}
|
|
48
|
-
return [this.nonce,
|
|
48
|
+
return [this.nonce, voteTree.root];
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
51
51
|
* Create a deep clone of this Ballot
|
|
@@ -58,9 +58,9 @@ class Ballot {
|
|
|
58
58
|
return b;
|
|
59
59
|
};
|
|
60
60
|
this.voteOptionTreeDepth = _voteOptionTreeDepth;
|
|
61
|
-
(0, assert_1.default)(5 ** _voteOptionTreeDepth >=
|
|
62
|
-
(0, assert_1.default)(
|
|
63
|
-
for (let i = 0; i <
|
|
61
|
+
(0, assert_1.default)(5 ** _voteOptionTreeDepth >= _totalVoteOptions);
|
|
62
|
+
(0, assert_1.default)(_totalVoteOptions >= 0);
|
|
63
|
+
for (let i = 0; i < _totalVoteOptions; i += 1) {
|
|
64
64
|
this.votes.push(BigInt(0));
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -75,23 +75,23 @@ class Ballot {
|
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Generate a random ballot
|
|
78
|
-
* @param
|
|
78
|
+
* @param totalVoteOptions How many vote options are available
|
|
79
79
|
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
80
80
|
* @returns a random Ballot
|
|
81
81
|
*/
|
|
82
|
-
static genRandomBallot(
|
|
83
|
-
const ballot = new Ballot(
|
|
84
|
-
ballot.nonce = (0, crypto_1.
|
|
82
|
+
static genRandomBallot(totalVoteOptions, voteOptionTreeDepth) {
|
|
83
|
+
const ballot = new Ballot(totalVoteOptions, voteOptionTreeDepth);
|
|
84
|
+
ballot.nonce = (0, crypto_1.generateRandomSalt)();
|
|
85
85
|
return ballot;
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Generate a blank ballot
|
|
89
|
-
* @param
|
|
89
|
+
* @param totalVoteOptions How many vote options are available
|
|
90
90
|
* @param voteOptionTreeDepth How deep is the merkle tree holding the vote options
|
|
91
91
|
* @returns a Blank Ballot object
|
|
92
92
|
*/
|
|
93
|
-
static genBlankBallot(
|
|
94
|
-
const ballot = new Ballot(
|
|
93
|
+
static genBlankBallot(totalVoteOptions, voteOptionTreeDepth) {
|
|
94
|
+
const ballot = new Ballot(totalVoteOptions, voteOptionTreeDepth);
|
|
95
95
|
return ballot;
|
|
96
96
|
}
|
|
97
97
|
/**
|
package/build/ts/ballot.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ballot.js","sourceRoot":"","sources":["../../ts/ballot.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ballot.js","sourceRoot":"","sources":["../../ts/ballot.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAsG;AAEtG,oDAA4B;AAI5B;;;GAGG;AACH,MAAa,MAAM;IAOjB;;;;OAIG;IACH,YAAY,iBAAyB,EAAE,oBAA4B;QAXnE,UAAK,GAAa,EAAE,CAAC;QAErB,UAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAkBlB;;;WAGG;QACH,SAAI,GAAG,GAAW,EAAE;YAClB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAO,IAAA,sBAAa,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,CAAC,CAAC;QAEF;;;WAGG;QACH,oBAAe,GAAG,GAAa,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAEjD;;;;WAIG;QACH,YAAO,GAAG,GAAa,EAAE;YACvB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;YACxC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,C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;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAiB;QAC/B,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QACvG,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAzHD,wBAyHC"}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
import { type Signature, type EcdhSharedKey } from "@maci-protocol/crypto";
|
|
2
2
|
import type { IJsonPCommand } from "./types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { PrivateKey } from "../privateKey";
|
|
4
4
|
import { Message } from "../message";
|
|
5
|
-
import {
|
|
5
|
+
import { PublicKey } from "../publicKey";
|
|
6
6
|
export interface IDecryptMessage {
|
|
7
|
-
command:
|
|
7
|
+
command: VoteCommand;
|
|
8
8
|
signature: Signature;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* @notice Unencrypted data whose fields include the user's public key, vote etc.
|
|
12
12
|
* This represents a Vote command.
|
|
13
13
|
*/
|
|
14
|
-
export declare class
|
|
14
|
+
export declare class VoteCommand {
|
|
15
15
|
stateIndex: bigint;
|
|
16
|
-
|
|
16
|
+
newPublicKey: PublicKey;
|
|
17
17
|
voteOptionIndex: bigint;
|
|
18
18
|
newVoteWeight: bigint;
|
|
19
19
|
nonce: bigint;
|
|
20
20
|
pollId: bigint;
|
|
21
21
|
salt: bigint;
|
|
22
22
|
/**
|
|
23
|
-
* Create a new
|
|
23
|
+
* Create a new VoteCommand
|
|
24
24
|
* @param stateIndex the state index of the user
|
|
25
|
-
* @param
|
|
25
|
+
* @param newPublicKey the new public key of the user
|
|
26
26
|
* @param voteOptionIndex the index of the vote option
|
|
27
27
|
* @param newVoteWeight the new vote weight of the user
|
|
28
28
|
* @param nonce the nonce of the message
|
|
29
29
|
* @param pollId the poll ID
|
|
30
30
|
* @param salt the salt of the message
|
|
31
31
|
*/
|
|
32
|
-
constructor(stateIndex: bigint,
|
|
32
|
+
constructor(stateIndex: bigint, newPublicKey: PublicKey, voteOptionIndex: bigint, newVoteWeight: bigint, nonce: bigint, pollId: bigint, salt?: bigint);
|
|
33
33
|
/**
|
|
34
|
-
* Create a deep clone of this
|
|
35
|
-
* @returns a copy of the
|
|
34
|
+
* Create a deep clone of this VoteCommand
|
|
35
|
+
* @returns a copy of the VoteCommand
|
|
36
36
|
*/
|
|
37
|
-
copy: <T extends
|
|
37
|
+
copy: <T extends VoteCommand>() => T;
|
|
38
38
|
/**
|
|
39
39
|
* @notice Returns this Command as an array. Note that 5 of the Command's fields
|
|
40
40
|
* are packed into a single 250-bit value. This allows Messages to be
|
|
@@ -43,18 +43,18 @@ export declare class PCommand {
|
|
|
43
43
|
*/
|
|
44
44
|
asArray: () => bigint[];
|
|
45
45
|
asCircuitInputs: () => bigint[];
|
|
46
|
-
equals: (command:
|
|
46
|
+
equals: (command: VoteCommand) => boolean;
|
|
47
47
|
hash: () => bigint;
|
|
48
48
|
/**
|
|
49
49
|
* @notice Signs this command and returns a Signature.
|
|
50
50
|
*/
|
|
51
|
-
sign: (
|
|
51
|
+
sign: (privateKey: PrivateKey) => Signature;
|
|
52
52
|
/**
|
|
53
53
|
* @notice Returns true if the given signature is a correct signature of this
|
|
54
54
|
* command and signed by the private key associated with the given public
|
|
55
55
|
* key.
|
|
56
56
|
*/
|
|
57
|
-
verifySignature: (signature: Signature,
|
|
57
|
+
verifySignature: (signature: Signature, publicKey: PublicKey) => boolean;
|
|
58
58
|
/**
|
|
59
59
|
* @notice Encrypts this command along with a signature to produce a Message.
|
|
60
60
|
* To save gas, we can constrain the following values to 50 bits and pack
|
|
@@ -80,10 +80,10 @@ export declare class PCommand {
|
|
|
80
80
|
*/
|
|
81
81
|
toJSON(): IJsonPCommand;
|
|
82
82
|
/**
|
|
83
|
-
* Deserialize into a
|
|
83
|
+
* Deserialize into a VoteCommand instance
|
|
84
84
|
* @param json
|
|
85
|
-
* @returns a
|
|
85
|
+
* @returns a VoteCommand instance
|
|
86
86
|
*/
|
|
87
|
-
static fromJSON(json: IJsonPCommand):
|
|
87
|
+
static fromJSON(json: IJsonPCommand): VoteCommand;
|
|
88
88
|
}
|
|
89
|
-
//# sourceMappingURL=
|
|
89
|
+
//# sourceMappingURL=VoteCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoteCommand.d.ts","sourceRoot":"","sources":["../../../ts/commands/VoteCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,aAAa,EAGnB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,WAAW;IACtB,UAAU,EAAE,MAAM,CAAC;IAEnB,YAAY,EAAE,SAAS,CAAC;IAExB,eAAe,EAAE,MAAM,CAAC;IAExB,aAAa,EAAE,MAAM,CAAC;IAEtB,KAAK,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;;;OASG;gBAED,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAA6B;IAkBrC;;;OAGG;IACH,IAAI,GAAI,CAAC,SAAS,WAAW,OAAK,CAAC,CASf;IAEpB;;;;;OAKG;IACH,OAAO,QAAO,MAAM,EAAE,CAcpB;IAEF,eAAe,QAAO,MAAM,EAAE,CAAmB;IAKjD,MAAM,GAAI,SAAS,WAAW,KAAG,OAAO,CAOX;IAE7B,IAAI,QAAO,MAAM,CAA0B;IAE3C;;OAEG;IACH,IAAI,GAAI,YAAY,UAAU,KAAG,SAAS,CAAiD;IAE3F;;;;OAIG;IACH,eAAe,GAAI,WAAW,SAAS,EAAE,WAAW,SAAS,KAAG,OAAO,CACd;IAEzD;;;;;;;;;OASG;IACH,OAAO,GAAI,WAAW,SAAS,EAAE,WAAW,aAAa,KAAG,OAAO,CAUjE;IAEF;;;;;;;OAOG;IACH,MAAM,CAAC,OAAO,GAAI,SAAS,OAAO,EAAE,WAAW,aAAa,EAAE,eAAa,KAAG,eAAe,CAyC3F;IAEF;;OAEG;IACH,MAAM,IAAI,aAAa;IAYvB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW;CAalD"}
|
|
@@ -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.VoteCommand = void 0;
|
|
7
7
|
const crypto_1 = require("@maci-protocol/crypto");
|
|
8
8
|
const assert_1 = __importDefault(require("assert"));
|
|
9
9
|
const message_1 = require("../message");
|
|
@@ -12,23 +12,23 @@ const publicKey_1 = require("../publicKey");
|
|
|
12
12
|
* @notice Unencrypted data whose fields include the user's public key, vote etc.
|
|
13
13
|
* This represents a Vote command.
|
|
14
14
|
*/
|
|
15
|
-
class
|
|
15
|
+
class VoteCommand {
|
|
16
16
|
/**
|
|
17
|
-
* Create a new
|
|
17
|
+
* Create a new VoteCommand
|
|
18
18
|
* @param stateIndex the state index of the user
|
|
19
|
-
* @param
|
|
19
|
+
* @param newPublicKey the new public key of the user
|
|
20
20
|
* @param voteOptionIndex the index of the vote option
|
|
21
21
|
* @param newVoteWeight the new vote weight of the user
|
|
22
22
|
* @param nonce the nonce of the message
|
|
23
23
|
* @param pollId the poll ID
|
|
24
24
|
* @param salt the salt of the message
|
|
25
25
|
*/
|
|
26
|
-
constructor(stateIndex,
|
|
26
|
+
constructor(stateIndex, newPublicKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt = (0, crypto_1.generateRandomSalt)()) {
|
|
27
27
|
/**
|
|
28
|
-
* Create a deep clone of this
|
|
29
|
-
* @returns a copy of the
|
|
28
|
+
* Create a deep clone of this VoteCommand
|
|
29
|
+
* @returns a copy of the VoteCommand
|
|
30
30
|
*/
|
|
31
|
-
this.copy = () => new
|
|
31
|
+
this.copy = () => new VoteCommand(BigInt(this.stateIndex.toString()), this.newPublicKey.copy(), BigInt(this.voteOptionIndex.toString()), BigInt(this.newVoteWeight.toString()), BigInt(this.nonce.toString()), BigInt(this.pollId.toString()), BigInt(this.salt.toString()));
|
|
32
32
|
/**
|
|
33
33
|
* @notice Returns this Command as an array. Note that 5 of the Command's fields
|
|
34
34
|
* are packed into a single 250-bit value. This allows Messages to be
|
|
@@ -43,7 +43,7 @@ class PCommand {
|
|
|
43
43
|
(BigInt(this.nonce) << BigInt(150)) +
|
|
44
44
|
(BigInt(this.pollId) << BigInt(200));
|
|
45
45
|
/* eslint-enable no-bitwise */
|
|
46
|
-
const command = [params, ...this.
|
|
46
|
+
const command = [params, ...this.newPublicKey.asArray(), this.salt];
|
|
47
47
|
(0, assert_1.default)(command.length === 4);
|
|
48
48
|
return command;
|
|
49
49
|
};
|
|
@@ -52,7 +52,7 @@ class PCommand {
|
|
|
52
52
|
* Check whether this command has deep equivalence to another command
|
|
53
53
|
*/
|
|
54
54
|
this.equals = (command) => this.stateIndex === command.stateIndex &&
|
|
55
|
-
this.
|
|
55
|
+
this.newPublicKey.equals(command.newPublicKey) &&
|
|
56
56
|
this.voteOptionIndex === command.voteOptionIndex &&
|
|
57
57
|
this.newVoteWeight === command.newVoteWeight &&
|
|
58
58
|
this.nonce === command.nonce &&
|
|
@@ -62,13 +62,13 @@ class PCommand {
|
|
|
62
62
|
/**
|
|
63
63
|
* @notice Signs this command and returns a Signature.
|
|
64
64
|
*/
|
|
65
|
-
this.sign = (
|
|
65
|
+
this.sign = (privateKey) => (0, crypto_1.sign)(privateKey.raw.toString(), this.hash());
|
|
66
66
|
/**
|
|
67
67
|
* @notice Returns true if the given signature is a correct signature of this
|
|
68
68
|
* command and signed by the private key associated with the given public
|
|
69
69
|
* key.
|
|
70
70
|
*/
|
|
71
|
-
this.verifySignature = (signature,
|
|
71
|
+
this.verifySignature = (signature, publicKey) => (0, crypto_1.verifySignature)(this.hash(), signature, publicKey.raw);
|
|
72
72
|
/**
|
|
73
73
|
* @notice Encrypts this command along with a signature to produce a Message.
|
|
74
74
|
* To save gas, we can constrain the following values to 50 bits and pack
|
|
@@ -93,7 +93,7 @@ class PCommand {
|
|
|
93
93
|
(0, assert_1.default)(limit50Bits >= nonce);
|
|
94
94
|
(0, assert_1.default)(limit50Bits >= pollId);
|
|
95
95
|
this.stateIndex = stateIndex;
|
|
96
|
-
this.
|
|
96
|
+
this.newPublicKey = newPublicKey;
|
|
97
97
|
this.voteOptionIndex = voteOptionIndex;
|
|
98
98
|
this.newVoteWeight = newVoteWeight;
|
|
99
99
|
this.nonce = nonce;
|
|
@@ -106,7 +106,7 @@ class PCommand {
|
|
|
106
106
|
toJSON() {
|
|
107
107
|
return {
|
|
108
108
|
stateIndex: this.stateIndex.toString(),
|
|
109
|
-
|
|
109
|
+
newPublicKey: this.newPublicKey.serialize(),
|
|
110
110
|
voteOptionIndex: this.voteOptionIndex.toString(),
|
|
111
111
|
newVoteWeight: this.newVoteWeight.toString(),
|
|
112
112
|
nonce: this.nonce.toString(),
|
|
@@ -115,16 +115,16 @@ class PCommand {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
/**
|
|
118
|
-
* Deserialize into a
|
|
118
|
+
* Deserialize into a VoteCommand instance
|
|
119
119
|
* @param json
|
|
120
|
-
* @returns a
|
|
120
|
+
* @returns a VoteCommand instance
|
|
121
121
|
*/
|
|
122
122
|
static fromJSON(json) {
|
|
123
|
-
const command = new
|
|
123
|
+
const command = new VoteCommand(BigInt(json.stateIndex), publicKey_1.PublicKey.deserialize(json.newPublicKey), BigInt(json.voteOptionIndex), BigInt(json.newVoteWeight), BigInt(json.nonce), BigInt(json.pollId), BigInt(json.salt));
|
|
124
124
|
return command;
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
exports.
|
|
127
|
+
exports.VoteCommand = VoteCommand;
|
|
128
128
|
/**
|
|
129
129
|
* Decrypts a Message to produce a Command.
|
|
130
130
|
* @dev You can force decrypt the message by setting `force` to true.
|
|
@@ -133,11 +133,11 @@ exports.PCommand = PCommand;
|
|
|
133
133
|
* @param sharedKey - the shared key to use for decryption
|
|
134
134
|
* @param force - whether to force decryption or not
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
VoteCommand.decrypt = (message, sharedKey, force = false) => {
|
|
137
137
|
const decrypted = force
|
|
138
138
|
? (0, crypto_1.poseidonDecryptWithoutCheck)(message.data, sharedKey, BigInt(0), 7)
|
|
139
139
|
: (0, crypto_1.poseidonDecrypt)(message.data, sharedKey, BigInt(0), 7);
|
|
140
|
-
const
|
|
140
|
+
const data = BigInt(decrypted[0].toString());
|
|
141
141
|
// Returns the value of the 50 bits at position `pos` in `val`
|
|
142
142
|
// create 50 '1' bits
|
|
143
143
|
// shift left by pos
|
|
@@ -146,26 +146,26 @@ PCommand.decrypt = (message, sharedKey, force = false) => {
|
|
|
146
146
|
const extract = (val, pos) =>
|
|
147
147
|
// eslint-disable-next-line no-bitwise
|
|
148
148
|
BigInt((((BigInt(1) << BigInt(50)) - BigInt(1)) << BigInt(pos)) & val) >> BigInt(pos);
|
|
149
|
-
//
|
|
149
|
+
// data is a packed value
|
|
150
150
|
// bits 0 - 50: stateIndex
|
|
151
151
|
// bits 51 - 100: voteOptionIndex
|
|
152
152
|
// bits 101 - 150: newVoteWeight
|
|
153
153
|
// bits 151 - 200: nonce
|
|
154
154
|
// bits 201 - 250: pollId
|
|
155
|
-
const stateIndex = extract(
|
|
156
|
-
const voteOptionIndex = extract(
|
|
157
|
-
const newVoteWeight = extract(
|
|
158
|
-
const nonce = extract(
|
|
159
|
-
const pollId = extract(
|
|
155
|
+
const stateIndex = extract(data, 0);
|
|
156
|
+
const voteOptionIndex = extract(data, 50);
|
|
157
|
+
const newVoteWeight = extract(data, 100);
|
|
158
|
+
const nonce = extract(data, 150);
|
|
159
|
+
const pollId = extract(data, 200);
|
|
160
160
|
// create new public key but allow it to be invalid (as when passing an mismatched
|
|
161
|
-
//
|
|
162
|
-
const
|
|
161
|
+
// encryptionPublicKey, a message will not decrypt resulting in potentially invalid public keys)
|
|
162
|
+
const newPublicKey = new publicKey_1.PublicKey([decrypted[1], decrypted[2]], true);
|
|
163
163
|
const salt = decrypted[3];
|
|
164
|
-
const command = new
|
|
164
|
+
const command = new VoteCommand(stateIndex, newPublicKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt);
|
|
165
165
|
const signature = {
|
|
166
166
|
R8: [decrypted[4], decrypted[5]],
|
|
167
167
|
S: decrypted[6],
|
|
168
168
|
};
|
|
169
169
|
return { command, signature };
|
|
170
170
|
};
|
|
171
|
-
//# sourceMappingURL=
|
|
171
|
+
//# sourceMappingURL=VoteCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VoteCommand.js","sourceRoot":"","sources":["../../../ts/commands/VoteC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AChB,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAU;QACzC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;KAChB,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC,AAzCa,CAyCZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
3
|
+
exports.VoteCommand = void 0;
|
|
4
|
+
var VoteCommand_1 = require("./VoteCommand");
|
|
5
|
+
Object.defineProperty(exports, "VoteCommand", { enumerable: true, get: function () { return VoteCommand_1.VoteCommand; } });
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/commands/index.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
|
|
@@ -1 +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,
|
|
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,YAAY,EAAE,MAAM,CAAC;IACrB,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"}
|
package/build/ts/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKey } from "./publicKey";
|
|
2
2
|
import { StateLeaf } from "./stateLeaf";
|
|
3
3
|
export declare const blankStateLeaf: StateLeaf;
|
|
4
4
|
export declare const blankStateLeafHash: bigint;
|
|
5
|
-
export declare const padKey:
|
|
5
|
+
export declare const padKey: PublicKey;
|
|
6
6
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,eAAO,MAAM,cAAc,WAA2B,CAAC;AACvD,eAAO,MAAM,kBAAkB,QAAwB,CAAC;AACxD,eAAO,MAAM,MAAM,WAAwB,CAAC"}
|
package/build/ts/constants.js
CHANGED
|
@@ -5,5 +5,5 @@ const publicKey_1 = require("./publicKey");
|
|
|
5
5
|
const stateLeaf_1 = require("./stateLeaf");
|
|
6
6
|
exports.blankStateLeaf = stateLeaf_1.StateLeaf.genBlankLeaf();
|
|
7
7
|
exports.blankStateLeafHash = exports.blankStateLeaf.hash();
|
|
8
|
-
exports.padKey = publicKey_1.
|
|
8
|
+
exports.padKey = publicKey_1.PublicKey.genPadKey();
|
|
9
9
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../ts/constants.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,2CAAwC;AAE3B,QAAA,cAAc,GAAG,qBAAS,CAAC,YAAY,EAAE,CAAC;AAC1C,QAAA,kBAAkB,GAAG,sBAAc,CAAC,IAAI,EAAE,CAAC;AAC3C,QAAA,MAAM,GAAG,qBAAS,CAAC,SAAS,EAAE,CAAC"}
|
package/build/ts/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { Ballot } from "./ballot";
|
|
2
2
|
export { Message } from "./message";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
3
|
+
export { PrivateKey, SERIALIZED_PRIV_KEY_PREFIX } from "./privateKey";
|
|
4
|
+
export { PublicKey, SERIALIZED_PUB_KEY_PREFIX } from "./publicKey";
|
|
5
5
|
export { Keypair } from "./keyPair";
|
|
6
6
|
export { StateLeaf } from "./stateLeaf";
|
|
7
7
|
export { blankStateLeaf, blankStateLeafHash, padKey } from "./constants";
|
|
8
|
-
export type { Proof, IStateLeaf, VoteOptionTreeLeaf, IJsonKeyPair, IJsonPrivateKey, IJsonPublicKey, IJsonStateLeaf, IG1ContractParams, IG2ContractParams,
|
|
9
|
-
export { type IJsonTCommand, type IJsonPCommand,
|
|
8
|
+
export type { Proof, IStateLeaf, VoteOptionTreeLeaf, IJsonKeyPair, IJsonPrivateKey, IJsonPublicKey, IJsonStateLeaf, IG1ContractParams, IG2ContractParams, IVerifyingKeyContractParams, IVerifyingKeyObjectParams, IStateLeafContractParams, IMessageContractParams, IJsonBallot, } from "./types";
|
|
9
|
+
export { type IJsonTCommand, type IJsonPCommand, VoteCommand } from "./commands";
|
|
10
10
|
export { VerifyingKey } from "./verifyingKey";
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/build/ts/index.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,UAAU,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAEnE,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,2BAA2B,EAC3B,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,WAAW,GACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/build/ts/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VerifyingKey = exports.
|
|
3
|
+
exports.VerifyingKey = exports.VoteCommand = exports.padKey = exports.blankStateLeafHash = exports.blankStateLeaf = exports.StateLeaf = exports.Keypair = exports.SERIALIZED_PUB_KEY_PREFIX = exports.PublicKey = exports.SERIALIZED_PRIV_KEY_PREFIX = exports.PrivateKey = exports.Message = exports.Ballot = void 0;
|
|
4
4
|
var ballot_1 = require("./ballot");
|
|
5
5
|
Object.defineProperty(exports, "Ballot", { enumerable: true, get: function () { return ballot_1.Ballot; } });
|
|
6
6
|
var message_1 = require("./message");
|
|
7
7
|
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.Message; } });
|
|
8
8
|
var privateKey_1 = require("./privateKey");
|
|
9
|
-
Object.defineProperty(exports, "
|
|
9
|
+
Object.defineProperty(exports, "PrivateKey", { enumerable: true, get: function () { return privateKey_1.PrivateKey; } });
|
|
10
10
|
Object.defineProperty(exports, "SERIALIZED_PRIV_KEY_PREFIX", { enumerable: true, get: function () { return privateKey_1.SERIALIZED_PRIV_KEY_PREFIX; } });
|
|
11
11
|
var publicKey_1 = require("./publicKey");
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "PublicKey", { enumerable: true, get: function () { return publicKey_1.PublicKey; } });
|
|
13
13
|
Object.defineProperty(exports, "SERIALIZED_PUB_KEY_PREFIX", { enumerable: true, get: function () { return publicKey_1.SERIALIZED_PUB_KEY_PREFIX; } });
|
|
14
14
|
var keyPair_1 = require("./keyPair");
|
|
15
15
|
Object.defineProperty(exports, "Keypair", { enumerable: true, get: function () { return keyPair_1.Keypair; } });
|
|
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "blankStateLeaf", { enumerable: true, get: functi
|
|
|
20
20
|
Object.defineProperty(exports, "blankStateLeafHash", { enumerable: true, get: function () { return constants_1.blankStateLeafHash; } });
|
|
21
21
|
Object.defineProperty(exports, "padKey", { enumerable: true, get: function () { return constants_1.padKey; } });
|
|
22
22
|
var commands_1 = require("./commands");
|
|
23
|
-
Object.defineProperty(exports, "
|
|
23
|
+
Object.defineProperty(exports, "VoteCommand", { enumerable: true, get: function () { return commands_1.VoteCommand; } });
|
|
24
24
|
var verifyingKey_1 = require("./verifyingKey");
|
|
25
25
|
Object.defineProperty(exports, "VerifyingKey", { enumerable: true, get: function () { return verifyingKey_1.VerifyingKey; } });
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/build/ts/index.js.map
CHANGED
|
@@ -1 +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,
|
|
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,2CAAsE;AAA7D,wGAAA,UAAU,OAAA;AAAE,wHAAA,0BAA0B,OAAA;AAE/C,yCAAmE;AAA1D,sGAAA,SAAS,OAAA;AAAE,sHAAA,yBAAyB,OAAA;AAE7C,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,uCAAiF;AAAhC,uGAAA,WAAW,OAAA;AAE5D,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
|
package/build/ts/keyPair.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EcdhSharedKey } from "@maci-protocol/crypto";
|
|
2
2
|
import type { IJsonKeyPair } from "./types";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { PrivateKey } from "./privateKey";
|
|
4
|
+
import { PublicKey } from "./publicKey";
|
|
5
5
|
/**
|
|
6
6
|
* @notice A KeyPair is a pair of public and private keys
|
|
7
7
|
* This is a MACI keypair, which is not to be
|
|
@@ -9,14 +9,14 @@ import { PubKey } from "./publicKey";
|
|
|
9
9
|
* A MACI keypair is comprised of a MACI public key and a MACI private key
|
|
10
10
|
*/
|
|
11
11
|
export declare class Keypair {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
privateKey: PrivateKey;
|
|
13
|
+
publicKey: PublicKey;
|
|
14
14
|
/**
|
|
15
15
|
* Create a new instance of a Keypair
|
|
16
|
-
* @param
|
|
17
|
-
* @notice if no
|
|
16
|
+
* @param privateKey the private key (optional)
|
|
17
|
+
* @notice if no privateKey is passed, it will automatically generate a new private key
|
|
18
18
|
*/
|
|
19
|
-
constructor(
|
|
19
|
+
constructor(privateKey?: PrivateKey);
|
|
20
20
|
/**
|
|
21
21
|
* Create a deep clone of this Keypair
|
|
22
22
|
* @returns a copy of the Keypair
|
|
@@ -24,11 +24,11 @@ export declare class Keypair {
|
|
|
24
24
|
copy: () => Keypair;
|
|
25
25
|
/**
|
|
26
26
|
* Generate a shared key
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
27
|
+
* @param privateKey
|
|
28
|
+
* @param publicKey
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
static
|
|
31
|
+
static generateEcdhSharedKey(privateKey: PrivateKey, publicKey: PublicKey): EcdhSharedKey;
|
|
32
32
|
/**
|
|
33
33
|
* Check whether two Keypairs are equal
|
|
34
34
|
* @param keypair the keypair to compare with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyPair.d.ts","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"keyPair.d.ts","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6D,MAAM,uBAAuB,CAAC;AAIjH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;;;;GAKG;AACH,qBAAa,OAAO;IAClB,UAAU,EAAE,UAAU,CAAC;IAEvB,SAAS,EAAE,SAAS,CAAC;IAErB;;;;OAIG;gBACS,UAAU,CAAC,EAAE,UAAU;IAWnC;;;OAGG;IACH,IAAI,QAAO,OAAO,CAAwC;IAE1D;;;;;OAKG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,aAAa;IAIzF;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAajC;;OAEG;IACH,MAAM,IAAI,YAAY;IAOtB;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;CAG7C"}
|