@maci-protocol/domainobjs 0.0.0-ci.f9da2fc → 0.0.0-ci.fc91dc9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -2
- package/build/ts/ballot.d.ts +6 -6
- package/build/ts/ballot.d.ts.map +1 -1
- package/build/ts/ballot.js +12 -12
- package/build/ts/ballot.js.map +1 -1
- package/build/ts/commands/PCommand.d.ts +7 -7
- package/build/ts/commands/PCommand.d.ts.map +1 -1
- package/build/ts/commands/PCommand.js +20 -20
- package/build/ts/commands/PCommand.js.map +1 -1
- package/build/ts/commands/types.d.ts +1 -1
- package/build/ts/commands/types.d.ts.map +1 -1
- package/build/ts/constants.d.ts +2 -2
- package/build/ts/constants.d.ts.map +1 -1
- package/build/ts/constants.js +1 -1
- package/build/ts/constants.js.map +1 -1
- package/build/ts/index.d.ts +3 -3
- package/build/ts/index.d.ts.map +1 -1
- package/build/ts/index.js +3 -3
- package/build/ts/index.js.map +1 -1
- package/build/ts/keyPair.d.ts +10 -10
- package/build/ts/keyPair.d.ts.map +1 -1
- package/build/ts/keyPair.js +21 -22
- package/build/ts/keyPair.js.map +1 -1
- package/build/ts/message.d.ts +3 -3
- package/build/ts/message.d.ts.map +1 -1
- package/build/ts/message.js +2 -2
- package/build/ts/message.js.map +1 -1
- package/build/ts/privateKey.d.ts +12 -12
- package/build/ts/privateKey.d.ts.map +1 -1
- package/build/ts/privateKey.js +20 -20
- package/build/ts/privateKey.js.map +1 -1
- package/build/ts/publicKey.d.ts +14 -14
- package/build/ts/publicKey.d.ts.map +1 -1
- package/build/ts/publicKey.js +24 -24
- package/build/ts/publicKey.js.map +1 -1
- package/build/ts/stateLeaf.d.ts +4 -4
- package/build/ts/stateLeaf.d.ts.map +1 -1
- package/build/ts/stateLeaf.js +13 -13
- package/build/ts/stateLeaf.js.map +1 -1
- package/build/ts/types.d.ts +10 -10
- package/build/ts/types.d.ts.map +1 -1
- package/build/ts/verifyingKey.d.ts +7 -7
- package/build/ts/verifyingKey.d.ts.map +1 -1
- package/build/ts/verifyingKey.js +9 -9
- package/build/ts/verifyingKey.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
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,CAUpB;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
|
/**
|
|
@@ -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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C;QACpC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,cAAc,CAAC,gBAAwB,EAAE,mBAA2B;QACzE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,CAAC;QACjE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YAC1C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YAC5B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE;SACzD,CAAC;IACJ,CAAC;IAED;;;;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;AAxHD,wBAwHC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
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
7
|
command: PCommand;
|
|
8
8
|
signature: Signature;
|
|
@@ -13,7 +13,7 @@ export interface IDecryptMessage {
|
|
|
13
13
|
*/
|
|
14
14
|
export declare class PCommand {
|
|
15
15
|
stateIndex: bigint;
|
|
16
|
-
|
|
16
|
+
newPublicKey: PublicKey;
|
|
17
17
|
voteOptionIndex: bigint;
|
|
18
18
|
newVoteWeight: bigint;
|
|
19
19
|
nonce: bigint;
|
|
@@ -22,14 +22,14 @@ export declare class PCommand {
|
|
|
22
22
|
/**
|
|
23
23
|
* Create a new PCommand
|
|
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
34
|
* Create a deep clone of this PCommand
|
|
35
35
|
* @returns a copy of the PCommand
|
|
@@ -48,13 +48,13 @@ export declare class PCommand {
|
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PCommand.d.ts","sourceRoot":"","sources":["../../../ts/commands/PCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EAEd,KAAK,aAAa,EAGnB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"PCommand.d.ts","sourceRoot":"","sources":["../../../ts/commands/PCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,SAAS,EAEd,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,QAAQ,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,QAAQ;IACnB,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,QAAQ,OAAK,CAAC,CASZ;IAEpB;;;;;OAKG;IACH,OAAO,QAAO,MAAM,EAAE,CAcpB;IAEF,eAAe,QAAO,MAAM,EAAE,CAAmB;IAKjD,MAAM,GAAI,SAAS,QAAQ,KAAG,OAAO,CAOR;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,QAAQ;CAa/C"}
|
|
@@ -16,19 +16,19 @@ class PCommand {
|
|
|
16
16
|
/**
|
|
17
17
|
* Create a new PCommand
|
|
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
28
|
* Create a deep clone of this PCommand
|
|
29
29
|
* @returns a copy of the PCommand
|
|
30
30
|
*/
|
|
31
|
-
this.copy = () => new PCommand(BigInt(this.stateIndex.toString()), this.
|
|
31
|
+
this.copy = () => new PCommand(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(),
|
|
@@ -120,7 +120,7 @@ class PCommand {
|
|
|
120
120
|
* @returns a PCommand instance
|
|
121
121
|
*/
|
|
122
122
|
static fromJSON(json) {
|
|
123
|
-
const command = new PCommand(BigInt(json.stateIndex), publicKey_1.
|
|
123
|
+
const command = new PCommand(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
|
}
|
|
@@ -137,7 +137,7 @@ PCommand.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,22 +146,22 @@ 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 PCommand(stateIndex,
|
|
164
|
+
const command = new PCommand(stateIndex, newPublicKey, voteOptionIndex, newVoteWeight, nonce, pollId, salt);
|
|
165
165
|
const signature = {
|
|
166
166
|
R8: [decrypted[4], decrypted[5]],
|
|
167
167
|
S: decrypted[6],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PCommand.js","sourceRoot":"","sources":["../../../ts/commands/PCommand.ts"],"names":[],"mappings":";;;;;;AAAA,kDAY+B;AAE/B,oDAA4B;AAK5B,wCAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"PCommand.js","sourceRoot":"","sources":["../../../ts/commands/PCommand.ts"],"names":[],"mappings":";;;;;;AAAA,kDAY+B;AAE/B,oDAA4B;AAK5B,wCAAqC;AACrC,4CAAyC;AAOzC;;;GAGG;AACH,MAAa,QAAQ;IAenB;;;;;;;;;OASG;IACH,YACE,UAAkB,EAClB,YAAuB,EACvB,eAAuB,EACvB,aAAqB,EACrB,KAAa,EACb,MAAc,EACd,OAAe,IAAA,2BAAkB,GAAE;QAkBrC;;;WAGG;QACH,SAAI,GAAG,GAA0B,EAAE,CACjC,IAAI,QAAQ,CACV,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,EAClC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EACxB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,CAAC,EACvC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,EACrC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,EAC7B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,EAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CACb,CAAC;QAEpB;;;;;WAKG;QACH,YAAO,GAAG,GAAa,EAAE;YACvB,+BAA+B;YAC/B,MAAM,MAAM,GACV,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;gBACvB,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC5C,CAAC,MAAM,CAAC,IAAI,CA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C,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACvE,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;IAE1B,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAE5G,MAAM,SAAS,GAAG;QAChB,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":"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,
|
|
8
|
+
export type { Proof, IStateLeaf, VoteOptionTreeLeaf, IJsonKeyPair, IJsonPrivateKey, IJsonPublicKey, IJsonStateLeaf, IG1ContractParams, IG2ContractParams, IVerifyingKeyContractParams, IVerifyingKeyObjectParams, IStateLeafContractParams, IMessageContractParams, IJsonBallot, } from "./types";
|
|
9
9
|
export { type IJsonTCommand, type IJsonPCommand, PCommand } 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,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9E,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.PCommand = exports.padKey = exports.blankStateLeafHash = exports.blankStateLeaf = exports.StateLeaf = exports.Keypair = exports.SERIALIZED_PUB_KEY_PREFIX = exports.
|
|
3
|
+
exports.VerifyingKey = exports.PCommand = 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; } });
|
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,uCAA8E;AAA7B,oGAAA,QAAQ,OAAA;AAEzD,+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"}
|
package/build/ts/keyPair.js
CHANGED
|
@@ -17,33 +17,33 @@ const publicKey_1 = require("./publicKey");
|
|
|
17
17
|
class Keypair {
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of a Keypair
|
|
20
|
-
* @param
|
|
21
|
-
* @notice if no
|
|
20
|
+
* @param privateKey the private key (optional)
|
|
21
|
+
* @notice if no privateKey is passed, it will automatically generate a new private key
|
|
22
22
|
*/
|
|
23
|
-
constructor(
|
|
23
|
+
constructor(privateKey) {
|
|
24
24
|
/**
|
|
25
25
|
* Create a deep clone of this Keypair
|
|
26
26
|
* @returns a copy of the Keypair
|
|
27
27
|
*/
|
|
28
|
-
this.copy = () => new Keypair(this.
|
|
29
|
-
if (
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
28
|
+
this.copy = () => new Keypair(this.privateKey.copy());
|
|
29
|
+
if (privateKey) {
|
|
30
|
+
this.privateKey = privateKey;
|
|
31
|
+
this.publicKey = new publicKey_1.PublicKey((0, crypto_1.generatePublicKey)(privateKey.raw));
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
const
|
|
35
|
-
this.
|
|
36
|
-
this.
|
|
34
|
+
const rawKeypair = (0, crypto_1.generateKeypair)();
|
|
35
|
+
this.privateKey = new privateKey_1.PrivateKey(rawKeypair.privateKey);
|
|
36
|
+
this.publicKey = new publicKey_1.PublicKey(rawKeypair.publicKey);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Generate a shared key
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
41
|
+
* @param privateKey
|
|
42
|
+
* @param publicKey
|
|
43
43
|
* @returns
|
|
44
44
|
*/
|
|
45
|
-
static
|
|
46
|
-
return (0, crypto_1.
|
|
45
|
+
static generateEcdhSharedKey(privateKey, publicKey) {
|
|
46
|
+
return (0, crypto_1.generateEcdhSharedKey)(privateKey.raw, publicKey.raw);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Check whether two Keypairs are equal
|
|
@@ -51,22 +51,21 @@ class Keypair {
|
|
|
51
51
|
* @returns whether they are equal or not
|
|
52
52
|
*/
|
|
53
53
|
equals(keypair) {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
this.pubKey.rawPubKey[1] === keypair.pubKey.rawPubKey[1];
|
|
54
|
+
const equalPrivateKey = this.privateKey.raw === keypair.privateKey.raw;
|
|
55
|
+
const equalPublic = this.publicKey.raw[0] === keypair.publicKey.raw[0] && this.publicKey.raw[1] === keypair.publicKey.raw[1];
|
|
57
56
|
// If this assertion fails, something is very wrong and this function
|
|
58
57
|
// should not return anything
|
|
59
58
|
// eslint-disable-next-line no-bitwise
|
|
60
|
-
(0, assert_1.default)(!(+
|
|
61
|
-
return
|
|
59
|
+
(0, assert_1.default)(!(+equalPrivateKey ^ +equalPublic));
|
|
60
|
+
return equalPrivateKey;
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
63
|
* Serialize into a JSON object
|
|
65
64
|
*/
|
|
66
65
|
toJSON() {
|
|
67
66
|
return {
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
privateKey: this.privateKey.serialize(),
|
|
68
|
+
publicKey: this.publicKey.serialize(),
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
/**
|
|
@@ -75,7 +74,7 @@ class Keypair {
|
|
|
75
74
|
* @returns a keypair instance
|
|
76
75
|
*/
|
|
77
76
|
static fromJSON(json) {
|
|
78
|
-
return new Keypair(privateKey_1.
|
|
77
|
+
return new Keypair(privateKey_1.PrivateKey.deserialize(json.privateKey));
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
exports.Keypair = Keypair;
|
package/build/ts/keyPair.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyPair.js","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"keyPair.js","sourceRoot":"","sources":["../../ts/keyPair.ts"],"names":[],"mapp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QAE3G,qEAAqE;QACrE,6BAA6B;QAC7B,sCAAsC;QACtC,IAAA,gBAAM,EAAC,CAAC,CAAC,CAAC,eAAe,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC;QAE3C,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE;SACtC,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,IAAkB;QAChC,OAAO,IAAI,OAAO,CAAC,uBAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC9D,CAAC;CACF;AAzED,0BAyEC"}
|
package/build/ts/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PublicKey } from "./publicKey";
|
|
2
2
|
import type { IMessageContractParams } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* @notice An encrypted command and signature.
|
|
@@ -29,10 +29,10 @@ export declare class Message {
|
|
|
29
29
|
asCircuitInputs: () => bigint[];
|
|
30
30
|
/**
|
|
31
31
|
* Hash the message data and a public key
|
|
32
|
-
* @param
|
|
32
|
+
* @param encryptionPublicKey the public key that is used to encrypt this message
|
|
33
33
|
* @returns the hash of the message data and the public key
|
|
34
34
|
*/
|
|
35
|
-
hash: (
|
|
35
|
+
hash: (encryptionPublicKey: PublicKey) => bigint;
|
|
36
36
|
/**
|
|
37
37
|
* Create a copy of the message
|
|
38
38
|
* @returns a copy of the message
|