@dorafactory/maci-sdk 0.0.35 → 0.0.36
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/dist/index.d.ts +14 -2234
- package/dist/index.js +748 -348
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +722 -350
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +118 -0
- package/dist/libs/contract/config.d.ts +29 -0
- package/dist/libs/contract/contract.d.ts +57 -0
- package/dist/libs/contract/index.d.ts +1 -0
- package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
- package/dist/libs/contract/ts/AMaci.types.d.ts +221 -0
- package/dist/libs/contract/ts/Maci.client.d.ts +180 -0
- package/dist/libs/contract/ts/Maci.types.d.ts +226 -0
- package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
- package/dist/libs/contract/ts/OracleMaci.types.d.ts +263 -0
- package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
- package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
- package/dist/libs/contract/types.d.ts +39 -0
- package/dist/libs/contract/utils.d.ts +63 -0
- package/dist/libs/contract/vars.d.ts +63 -0
- package/dist/libs/crypto/babyjub.d.ts +73 -0
- package/dist/libs/crypto/bigintUtils.d.ts +6 -0
- package/dist/libs/crypto/constants.d.ts +3 -0
- package/dist/libs/crypto/hashing.d.ts +69 -0
- package/dist/libs/crypto/index.d.ts +9 -0
- package/dist/libs/crypto/keys.d.ts +74 -0
- package/dist/libs/crypto/sign.d.ts +9 -0
- package/dist/libs/crypto/tree.d.ts +23 -0
- package/dist/libs/crypto/types.d.ts +55 -0
- package/dist/libs/errors/index.d.ts +28 -0
- package/dist/libs/errors/types.d.ts +19 -0
- package/dist/libs/http/http.d.ts +16 -0
- package/dist/libs/http/index.d.ts +1 -0
- package/dist/libs/index.d.ts +7 -0
- package/dist/libs/indexer/index.d.ts +1 -0
- package/dist/libs/indexer/indexer.d.ts +152 -0
- package/dist/libs/indexer/types.d.ts +7 -0
- package/dist/libs/maci/index.d.ts +1 -0
- package/dist/libs/maci/maci.d.ts +182 -0
- package/dist/libs/maci/types.d.ts +6 -0
- package/dist/libs/oracle-certificate/index.d.ts +1 -0
- package/dist/libs/oracle-certificate/oracle-certificate.d.ts +9 -0
- package/dist/libs/oracle-certificate/types.d.ts +40 -0
- package/dist/libs/query/account.d.ts +7 -0
- package/dist/libs/query/circuit.d.ts +8 -0
- package/dist/libs/query/event.d.ts +7 -0
- package/dist/libs/query/index.d.ts +7 -0
- package/dist/libs/query/operator.d.ts +11 -0
- package/dist/libs/query/proof.d.ts +7 -0
- package/dist/libs/query/round.d.ts +18 -0
- package/dist/libs/query/transaction.d.ts +9 -0
- package/dist/maci.d.ts +190 -0
- package/dist/types/index.d.ts +383 -0
- package/dist/utils/index.d.ts +7 -0
- package/package.json +18 -24
- package/src/index.ts +1 -3
- package/src/libs/contract/contract.ts +14 -13
- package/src/libs/contract/types.ts +3 -3
- package/src/libs/crypto/babyjub.ts +132 -0
- package/src/libs/crypto/bigintUtils.ts +31 -0
- package/src/libs/crypto/constants.ts +22 -0
- package/src/libs/crypto/hashing.ts +167 -0
- package/src/libs/crypto/index.ts +9 -0
- package/src/libs/{circom/circomlib.ts → crypto/keys.ts} +104 -114
- package/src/libs/crypto/sign.ts +91 -0
- package/src/libs/crypto/tree.ts +176 -0
- package/src/libs/crypto/types.ts +101 -0
- package/src/libs/index.ts +1 -1
- package/src/libs/maci/maci.ts +28 -29
- package/src/maci.ts +132 -67
- package/src/types/index.ts +7 -0
- package/src/utils/index.ts +22 -22
- package/dist/browser.d.mts +0 -2233
- package/dist/browser.d.ts +0 -2233
- package/dist/browser.js +0 -31620
- package/dist/browser.js.map +0 -1
- package/dist/browser.mjs +0 -31631
- package/dist/browser.mjs.map +0 -1
- package/dist/index.d.mts +0 -2234
- package/src/browser.ts +0 -17
- package/src/libs/circom/index.ts +0 -98
- package/src/libs/circom/types.ts +0 -8
- package/src/polyfills/browser-polyfills.ts +0 -9
package/dist/index.js
CHANGED
|
@@ -30,10 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Circom: () => Circom,
|
|
34
33
|
Circuit: () => Circuit,
|
|
35
34
|
Contract: () => Contract,
|
|
36
35
|
Event: () => Event,
|
|
36
|
+
G1Point: () => G1Point,
|
|
37
|
+
G2Point: () => G2Point,
|
|
37
38
|
Http: () => Http,
|
|
38
39
|
Indexer: () => Indexer,
|
|
39
40
|
MACI: () => MACI,
|
|
@@ -41,28 +42,53 @@ __export(index_exports, {
|
|
|
41
42
|
MaciCircuitType: () => MaciCircuitType,
|
|
42
43
|
MaciClient: () => MaciClient2,
|
|
43
44
|
MaciRoundType: () => MaciRoundType,
|
|
45
|
+
NOTHING_UP_MY_SLEEVE: () => NOTHING_UP_MY_SLEEVE,
|
|
44
46
|
Operator: () => Operator,
|
|
45
47
|
OracleCertificate: () => OracleCertificate,
|
|
48
|
+
PAD_KEY_HASH: () => PAD_KEY_HASH,
|
|
46
49
|
Proof: () => Proof,
|
|
47
50
|
Round: () => Round,
|
|
48
|
-
|
|
51
|
+
SNARK_FIELD_SIZE: () => SNARK_FIELD_SIZE,
|
|
49
52
|
Transaction: () => Transaction,
|
|
53
|
+
Tree: () => Tree,
|
|
50
54
|
UserAccount: () => UserAccount,
|
|
51
55
|
batchGenMessage: () => batchGenMessage,
|
|
56
|
+
bigInt2Buffer: () => bigInt2Buffer,
|
|
52
57
|
circuits: () => circuits,
|
|
53
|
-
|
|
54
|
-
createBlakeHash: () => import_blake_hash2.default,
|
|
55
|
-
decompressPublicKey: () => decompressPublicKey,
|
|
58
|
+
formatPrivKeyForBabyJub: () => formatPrivKeyForBabyJub,
|
|
56
59
|
genAddKeyProof: () => genAddKeyProof,
|
|
57
60
|
genEcdhSharedKey: () => genEcdhSharedKey,
|
|
58
61
|
genKeypair: () => genKeypair,
|
|
62
|
+
genKeypairFromSign: () => genKeypairFromSign,
|
|
63
|
+
genKeypairFromSignature: () => genKeypairFromSignature,
|
|
59
64
|
genMessageFactory: () => genMessageFactory,
|
|
65
|
+
genPrivKey: () => genPrivKey,
|
|
66
|
+
genPubKey: () => genPubKey,
|
|
67
|
+
genRandomBabyJubValue: () => genRandomBabyJubValue,
|
|
68
|
+
genRandomSalt: () => genRandomSalt,
|
|
60
69
|
getDefaultParams: () => getDefaultParams,
|
|
70
|
+
hash12: () => hash12,
|
|
71
|
+
hash2: () => hash2,
|
|
72
|
+
hash3: () => hash3,
|
|
73
|
+
hash4: () => hash4,
|
|
74
|
+
hash5: () => hash5,
|
|
75
|
+
hashLeanIMT: () => hashLeanIMT,
|
|
76
|
+
hashLeftRight: () => hashLeftRight,
|
|
77
|
+
hashN: () => hashN,
|
|
78
|
+
hashOne: () => hashOne,
|
|
61
79
|
hexToDecimalString: () => hexToDecimalString,
|
|
62
80
|
isValidAddress: () => isValidAddress,
|
|
81
|
+
packPubKey: () => packPubKey,
|
|
82
|
+
poseidon: () => poseidon,
|
|
83
|
+
poseidonT3: () => poseidonT3,
|
|
84
|
+
poseidonT4: () => poseidonT4,
|
|
85
|
+
poseidonT5: () => poseidonT5,
|
|
86
|
+
poseidonT6: () => poseidonT6,
|
|
63
87
|
privateKeyFromTxt: () => privateKeyFromTxt,
|
|
88
|
+
sha256Hash: () => sha256Hash,
|
|
89
|
+
signMessage: () => signMessage2,
|
|
64
90
|
stringizing: () => stringizing,
|
|
65
|
-
|
|
91
|
+
unpackPubKey: () => unpackPubKey,
|
|
66
92
|
validator_operator_set: () => validator_operator_set
|
|
67
93
|
});
|
|
68
94
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -602,30 +628,6 @@ function hexToDecimalString(hexString) {
|
|
|
602
628
|
const decimalString = BigInt("0x" + hexString).toString(10);
|
|
603
629
|
return decimalString;
|
|
604
630
|
}
|
|
605
|
-
function padWithZerosIfNeeded(inputString) {
|
|
606
|
-
if (inputString.length === 64) {
|
|
607
|
-
return inputString;
|
|
608
|
-
} else if (inputString.length < 64) {
|
|
609
|
-
const zerosToAdd = 64 - inputString.length;
|
|
610
|
-
const zeroPadding = "0".repeat(zerosToAdd);
|
|
611
|
-
return zeroPadding + inputString;
|
|
612
|
-
}
|
|
613
|
-
throw new Error("Invalid input string length");
|
|
614
|
-
}
|
|
615
|
-
function decompressPublicKey(compressedPubkey) {
|
|
616
|
-
const x = compressedPubkey.slice(0, 64);
|
|
617
|
-
const y = compressedPubkey.slice(64);
|
|
618
|
-
return {
|
|
619
|
-
x: hexToDecimalString(x),
|
|
620
|
-
y: hexToDecimalString(y)
|
|
621
|
-
};
|
|
622
|
-
}
|
|
623
|
-
function compressPublicKey(decompressedPubkey) {
|
|
624
|
-
const x = decompressedPubkey[0];
|
|
625
|
-
const y = decompressedPubkey[1];
|
|
626
|
-
const compressedPubkey = padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
|
|
627
|
-
return compressedPubkey;
|
|
628
|
-
}
|
|
629
631
|
|
|
630
632
|
// src/libs/query/operator.ts
|
|
631
633
|
var Operator = class {
|
|
@@ -1191,9 +1193,9 @@ var Round = class {
|
|
|
1191
1193
|
}
|
|
1192
1194
|
}
|
|
1193
1195
|
const results = JSON.parse(response.data.round.results);
|
|
1194
|
-
const votes = results.map((
|
|
1195
|
-
v: Number(
|
|
1196
|
-
v2: Number(
|
|
1196
|
+
const votes = results.map((r2) => ({
|
|
1197
|
+
v: Number(r2.slice(0, -24)),
|
|
1198
|
+
v2: Number(r2.slice(-24))
|
|
1197
1199
|
}));
|
|
1198
1200
|
const totalVotes = votes.reduce(
|
|
1199
1201
|
(s, c) => ({
|
|
@@ -4257,6 +4259,579 @@ function getAMaciRoundCircuitFee(maxVoter, maxOption) {
|
|
|
4257
4259
|
return requiredFee;
|
|
4258
4260
|
}
|
|
4259
4261
|
|
|
4262
|
+
// src/libs/crypto/keys.ts
|
|
4263
|
+
var import_crypto2 = require("crypto");
|
|
4264
|
+
|
|
4265
|
+
// src/libs/crypto/bigintUtils.ts
|
|
4266
|
+
var stringizing = (o, path = []) => {
|
|
4267
|
+
if (path.includes(o)) {
|
|
4268
|
+
throw new Error("loop nesting!");
|
|
4269
|
+
}
|
|
4270
|
+
const newPath = [...path, o];
|
|
4271
|
+
if (Array.isArray(o)) {
|
|
4272
|
+
return o.map((item) => stringizing(item, newPath));
|
|
4273
|
+
} else if (typeof o === "object") {
|
|
4274
|
+
const output = {};
|
|
4275
|
+
for (const key in o) {
|
|
4276
|
+
output[key] = stringizing(o[key], newPath);
|
|
4277
|
+
}
|
|
4278
|
+
return output;
|
|
4279
|
+
} else {
|
|
4280
|
+
return o.toString();
|
|
4281
|
+
}
|
|
4282
|
+
};
|
|
4283
|
+
var bigInt2Buffer = (i) => {
|
|
4284
|
+
let hex = i.toString(16);
|
|
4285
|
+
if (hex.length % 2 === 1) {
|
|
4286
|
+
hex = "0" + hex;
|
|
4287
|
+
}
|
|
4288
|
+
return Buffer.from(hex, "hex");
|
|
4289
|
+
};
|
|
4290
|
+
|
|
4291
|
+
// src/libs/crypto/keys.ts
|
|
4292
|
+
var import_poseidon_cipher2 = require("@zk-kit/poseidon-cipher");
|
|
4293
|
+
var BabyJub = __toESM(require("@zk-kit/baby-jubjub"));
|
|
4294
|
+
var import_eddsa_poseidon = require("@zk-kit/eddsa-poseidon");
|
|
4295
|
+
var import_ethers3 = require("ethers");
|
|
4296
|
+
var import_baby_jubjub2 = require("@zk-kit/baby-jubjub");
|
|
4297
|
+
var import_eddsa_poseidon2 = require("@zk-kit/eddsa-poseidon");
|
|
4298
|
+
|
|
4299
|
+
// src/libs/crypto/babyjub.ts
|
|
4300
|
+
var import_assert2 = __toESM(require("assert"));
|
|
4301
|
+
var import_crypto = require("crypto");
|
|
4302
|
+
|
|
4303
|
+
// src/libs/crypto/constants.ts
|
|
4304
|
+
var import_baby_jubjub = require("@zk-kit/baby-jubjub");
|
|
4305
|
+
var import_ethers = require("ethers");
|
|
4306
|
+
var import_assert = __toESM(require("assert"));
|
|
4307
|
+
var SNARK_FIELD_SIZE = import_baby_jubjub.r;
|
|
4308
|
+
var NOTHING_UP_MY_SLEEVE = BigInt((0, import_ethers.keccak256)((0, import_ethers.toUtf8Bytes)("Maci"))) % SNARK_FIELD_SIZE;
|
|
4309
|
+
(0, import_assert.default)(
|
|
4310
|
+
NOTHING_UP_MY_SLEEVE === BigInt(
|
|
4311
|
+
"8370432830353022751713833565135785980866757267633941821328460903436894336785"
|
|
4312
|
+
)
|
|
4313
|
+
);
|
|
4314
|
+
var PAD_KEY_HASH = BigInt(
|
|
4315
|
+
"1309255631273308531193241901289907343161346846555918942743921933037802809814"
|
|
4316
|
+
);
|
|
4317
|
+
|
|
4318
|
+
// src/libs/crypto/babyjub.ts
|
|
4319
|
+
var G1Point = class {
|
|
4320
|
+
/**
|
|
4321
|
+
* Create a new instance of G1Point
|
|
4322
|
+
* @param x the x coordinate
|
|
4323
|
+
* @param y the y coordinate
|
|
4324
|
+
*/
|
|
4325
|
+
constructor(x, y) {
|
|
4326
|
+
(0, import_assert2.default)(x < SNARK_FIELD_SIZE && x >= 0, "G1Point x out of range");
|
|
4327
|
+
(0, import_assert2.default)(y < SNARK_FIELD_SIZE && y >= 0, "G1Point y out of range");
|
|
4328
|
+
this.x = x;
|
|
4329
|
+
this.y = y;
|
|
4330
|
+
}
|
|
4331
|
+
/**
|
|
4332
|
+
* Check whether two points are equal
|
|
4333
|
+
* @param pt the point to compare with
|
|
4334
|
+
* @returns whether they are equal or not
|
|
4335
|
+
*/
|
|
4336
|
+
equals(pt) {
|
|
4337
|
+
return this.x === pt.x && this.y === pt.y;
|
|
4338
|
+
}
|
|
4339
|
+
/**
|
|
4340
|
+
* Return the point as a contract param in the form of an object
|
|
4341
|
+
* @returns the point as a contract param
|
|
4342
|
+
*/
|
|
4343
|
+
asContractParam() {
|
|
4344
|
+
return {
|
|
4345
|
+
x: this.x.toString(),
|
|
4346
|
+
y: this.y.toString()
|
|
4347
|
+
};
|
|
4348
|
+
}
|
|
4349
|
+
};
|
|
4350
|
+
var G2Point = class {
|
|
4351
|
+
/**
|
|
4352
|
+
* Create a new instance of G2Point
|
|
4353
|
+
* @param x the x coordinate
|
|
4354
|
+
* @param y the y coordinate
|
|
4355
|
+
*/
|
|
4356
|
+
constructor(x, y) {
|
|
4357
|
+
this.checkPointsRange(x, "x");
|
|
4358
|
+
this.checkPointsRange(y, "y");
|
|
4359
|
+
this.x = x;
|
|
4360
|
+
this.y = y;
|
|
4361
|
+
}
|
|
4362
|
+
/**
|
|
4363
|
+
* Check whether two points are equal
|
|
4364
|
+
* @param pt the point to compare with
|
|
4365
|
+
* @returns whether they are equal or not
|
|
4366
|
+
*/
|
|
4367
|
+
equals(pt) {
|
|
4368
|
+
return this.x[0] === pt.x[0] && this.x[1] === pt.x[1] && this.y[0] === pt.y[0] && this.y[1] === pt.y[1];
|
|
4369
|
+
}
|
|
4370
|
+
/**
|
|
4371
|
+
* Return the point as a contract param in the form of an object
|
|
4372
|
+
* @returns the point as a contract param
|
|
4373
|
+
*/
|
|
4374
|
+
asContractParam() {
|
|
4375
|
+
return {
|
|
4376
|
+
x: this.x.map((n) => n.toString()),
|
|
4377
|
+
y: this.y.map((n) => n.toString())
|
|
4378
|
+
};
|
|
4379
|
+
}
|
|
4380
|
+
/**
|
|
4381
|
+
* Check whether the points are in range
|
|
4382
|
+
* @param x the x coordinate
|
|
4383
|
+
* @param type the type of the coordinate
|
|
4384
|
+
*/
|
|
4385
|
+
checkPointsRange(x, type) {
|
|
4386
|
+
(0, import_assert2.default)(
|
|
4387
|
+
x.every((n) => n < SNARK_FIELD_SIZE && n >= 0),
|
|
4388
|
+
`G2Point ${type} out of range`
|
|
4389
|
+
);
|
|
4390
|
+
}
|
|
4391
|
+
};
|
|
4392
|
+
var genRandomBabyJubValue = () => {
|
|
4393
|
+
const min = BigInt("6350874878119819312338956282401532410528162663560392320966563075034087161851");
|
|
4394
|
+
let privKey = SNARK_FIELD_SIZE;
|
|
4395
|
+
do {
|
|
4396
|
+
const rand = BigInt(`0x${(0, import_crypto.randomBytes)(32).toString("hex")}`);
|
|
4397
|
+
if (rand >= min) {
|
|
4398
|
+
privKey = rand % SNARK_FIELD_SIZE;
|
|
4399
|
+
}
|
|
4400
|
+
} while (privKey >= SNARK_FIELD_SIZE);
|
|
4401
|
+
return privKey;
|
|
4402
|
+
};
|
|
4403
|
+
|
|
4404
|
+
// src/libs/crypto/hashing.ts
|
|
4405
|
+
var import_poseidon_cipher = require("@zk-kit/poseidon-cipher");
|
|
4406
|
+
var import_ethers2 = require("ethers");
|
|
4407
|
+
var import_assert3 = __toESM(require("assert"));
|
|
4408
|
+
var sha256Hash = (input) => {
|
|
4409
|
+
const types = [];
|
|
4410
|
+
input.forEach(() => {
|
|
4411
|
+
types.push("uint256");
|
|
4412
|
+
});
|
|
4413
|
+
return BigInt(
|
|
4414
|
+
(0, import_ethers2.solidityPackedSha256)(
|
|
4415
|
+
types,
|
|
4416
|
+
input.map((x) => x.toString())
|
|
4417
|
+
)
|
|
4418
|
+
) % SNARK_FIELD_SIZE;
|
|
4419
|
+
};
|
|
4420
|
+
var poseidon = (inputs) => (0, import_poseidon_cipher.poseidonPerm)([BigInt(0), ...inputs.map((x) => BigInt(x))])[0];
|
|
4421
|
+
var poseidonT3 = (inputs) => {
|
|
4422
|
+
(0, import_assert3.default)(inputs.length === 2);
|
|
4423
|
+
return poseidon(inputs);
|
|
4424
|
+
};
|
|
4425
|
+
var poseidonT4 = (inputs) => {
|
|
4426
|
+
(0, import_assert3.default)(inputs.length === 3);
|
|
4427
|
+
return poseidon(inputs);
|
|
4428
|
+
};
|
|
4429
|
+
var poseidonT5 = (inputs) => {
|
|
4430
|
+
(0, import_assert3.default)(inputs.length === 4);
|
|
4431
|
+
return poseidon(inputs);
|
|
4432
|
+
};
|
|
4433
|
+
var poseidonT6 = (inputs) => {
|
|
4434
|
+
(0, import_assert3.default)(inputs.length === 5);
|
|
4435
|
+
return poseidon(inputs);
|
|
4436
|
+
};
|
|
4437
|
+
var hashLeftRight = (left, right) => poseidonT3([left, right]);
|
|
4438
|
+
var funcs = {
|
|
4439
|
+
2: poseidonT3,
|
|
4440
|
+
3: poseidonT4,
|
|
4441
|
+
4: poseidonT5,
|
|
4442
|
+
5: poseidonT6
|
|
4443
|
+
};
|
|
4444
|
+
var hashN = (numElements, elements) => {
|
|
4445
|
+
const elementLength = elements.length;
|
|
4446
|
+
if (elements.length > numElements) {
|
|
4447
|
+
throw new TypeError(
|
|
4448
|
+
`the length of the elements array should be at most ${numElements}; got ${elements.length}`
|
|
4449
|
+
);
|
|
4450
|
+
}
|
|
4451
|
+
const elementsPadded = elements.slice();
|
|
4452
|
+
if (elementLength < numElements) {
|
|
4453
|
+
for (let i = elementLength; i < numElements; i += 1) {
|
|
4454
|
+
elementsPadded.push(BigInt(0));
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
return funcs[numElements](elementsPadded);
|
|
4458
|
+
};
|
|
4459
|
+
var hashLeanIMT = (a, b) => hashN(2, [a, b]);
|
|
4460
|
+
var hash2 = (elements) => hashN(2, elements);
|
|
4461
|
+
var hash3 = (elements) => hashN(3, elements);
|
|
4462
|
+
var hash4 = (elements) => hashN(4, elements);
|
|
4463
|
+
var hash5 = (elements) => hashN(5, elements);
|
|
4464
|
+
var hash12 = (elements) => {
|
|
4465
|
+
const max = 12;
|
|
4466
|
+
const elementLength = elements.length;
|
|
4467
|
+
if (elementLength > max) {
|
|
4468
|
+
throw new TypeError(
|
|
4469
|
+
`the length of the elements array should be at most ${max}; got ${elements.length}`
|
|
4470
|
+
);
|
|
4471
|
+
}
|
|
4472
|
+
const elementsPadded = elements.slice();
|
|
4473
|
+
if (elementLength < max) {
|
|
4474
|
+
for (let i = elementLength; i < max; i += 1) {
|
|
4475
|
+
elementsPadded.push(BigInt(0));
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
return poseidonT5([
|
|
4479
|
+
poseidonT6(elementsPadded.slice(0, 5)),
|
|
4480
|
+
poseidonT6(elementsPadded.slice(5, 10)),
|
|
4481
|
+
elementsPadded[10],
|
|
4482
|
+
elementsPadded[11]
|
|
4483
|
+
]);
|
|
4484
|
+
};
|
|
4485
|
+
var hashOne = (preImage) => poseidonT3([preImage, BigInt(0)]);
|
|
4486
|
+
|
|
4487
|
+
// src/libs/crypto/tree.ts
|
|
4488
|
+
var Tree = class _Tree {
|
|
4489
|
+
constructor(degree, depth, zero) {
|
|
4490
|
+
this.DEPTH = depth;
|
|
4491
|
+
this.HEIGHT = depth + 1;
|
|
4492
|
+
this.DEGREE = degree;
|
|
4493
|
+
this.LEAVES_COUNT = degree ** depth;
|
|
4494
|
+
this.LEAVES_IDX_0 = (degree ** depth - 1) / (degree - 1);
|
|
4495
|
+
this.NODES_COUNT = (degree ** (depth + 1) - 1) / (degree - 1);
|
|
4496
|
+
this.initZero(zero);
|
|
4497
|
+
this.initNodes();
|
|
4498
|
+
}
|
|
4499
|
+
get root() {
|
|
4500
|
+
return this.nodes[0];
|
|
4501
|
+
}
|
|
4502
|
+
async initZero(zero) {
|
|
4503
|
+
this.zeros = new Array(this.HEIGHT);
|
|
4504
|
+
this.zeros[0] = zero;
|
|
4505
|
+
for (let i = 1; i < this.zeros.length; i++) {
|
|
4506
|
+
this.zeros[i] = await poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
|
|
4507
|
+
}
|
|
4508
|
+
}
|
|
4509
|
+
async initNodes() {
|
|
4510
|
+
const DEGREE = this.DEGREE;
|
|
4511
|
+
this.nodes = new Array(this.NODES_COUNT);
|
|
4512
|
+
for (let d = this.DEPTH; d >= 0; d--) {
|
|
4513
|
+
const size = DEGREE ** d;
|
|
4514
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
4515
|
+
const zero = this.zeros[this.DEPTH - d];
|
|
4516
|
+
for (let i = 0; i < size; i++) {
|
|
4517
|
+
this.nodes[idx0 + i] = zero;
|
|
4518
|
+
}
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
initLeaves(leaves) {
|
|
4522
|
+
const DEGREE = this.DEGREE;
|
|
4523
|
+
for (let i = 0; i < leaves.length; i++) {
|
|
4524
|
+
if (i >= this.LEAVES_COUNT) {
|
|
4525
|
+
console.error("OVERFLOW");
|
|
4526
|
+
break;
|
|
4527
|
+
}
|
|
4528
|
+
this.nodes[this.LEAVES_IDX_0 + i] = BigInt(leaves[i]);
|
|
4529
|
+
}
|
|
4530
|
+
for (let d = this.DEPTH - 1; d >= 0; d--) {
|
|
4531
|
+
const size = DEGREE ** d;
|
|
4532
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
4533
|
+
for (let i = 0; i < size / DEGREE; i++) {
|
|
4534
|
+
const start = (idx0 + i) * DEGREE + 1;
|
|
4535
|
+
const children = this.nodes.slice(start, start + DEGREE);
|
|
4536
|
+
this.nodes[idx0 + i] = poseidon(children);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
leaf(leafIdx) {
|
|
4541
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
4542
|
+
throw new Error("wrong leaf index");
|
|
4543
|
+
}
|
|
4544
|
+
const nodeIdx = this.LEAVES_IDX_0 + leafIdx;
|
|
4545
|
+
return this.nodes[nodeIdx];
|
|
4546
|
+
}
|
|
4547
|
+
leaves() {
|
|
4548
|
+
return this.nodes.slice(this.LEAVES_IDX_0);
|
|
4549
|
+
}
|
|
4550
|
+
updateLeaf(leafIdx, leaf) {
|
|
4551
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
4552
|
+
throw new Error("wrong leaf index");
|
|
4553
|
+
}
|
|
4554
|
+
const nodeIdx = this.LEAVES_IDX_0 + leafIdx;
|
|
4555
|
+
this.nodes[nodeIdx] = leaf;
|
|
4556
|
+
this._update(nodeIdx);
|
|
4557
|
+
}
|
|
4558
|
+
pathIdxOf(leafIdx) {
|
|
4559
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
4560
|
+
throw new Error("wrong leaf index");
|
|
4561
|
+
}
|
|
4562
|
+
let idx = this.LEAVES_IDX_0 + leafIdx;
|
|
4563
|
+
const pathIdx = [];
|
|
4564
|
+
for (let i = 0; i < this.DEPTH; i++) {
|
|
4565
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
4566
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
4567
|
+
pathIdx.push(idx - childrenIdx0);
|
|
4568
|
+
idx = parentIdx;
|
|
4569
|
+
}
|
|
4570
|
+
return pathIdx;
|
|
4571
|
+
}
|
|
4572
|
+
pathElementOf(leafIdx) {
|
|
4573
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
4574
|
+
throw new Error("wrong leaf index");
|
|
4575
|
+
}
|
|
4576
|
+
let idx = this.LEAVES_IDX_0 + leafIdx;
|
|
4577
|
+
const pathElement = [];
|
|
4578
|
+
for (let h = 0; h < this.DEPTH; h++) {
|
|
4579
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
4580
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
4581
|
+
const el = [];
|
|
4582
|
+
for (let i = childrenIdx0; i < childrenIdx0 + this.DEGREE; i++) {
|
|
4583
|
+
if (i === idx) continue;
|
|
4584
|
+
el.push(this.nodes[i]);
|
|
4585
|
+
}
|
|
4586
|
+
pathElement.push(el);
|
|
4587
|
+
idx = parentIdx;
|
|
4588
|
+
}
|
|
4589
|
+
return pathElement;
|
|
4590
|
+
}
|
|
4591
|
+
subTree(length) {
|
|
4592
|
+
const subTree = new _Tree(this.DEGREE, this.DEPTH, this.zeros[0]);
|
|
4593
|
+
const nodes = [...this.nodes];
|
|
4594
|
+
const DEGREE = this.DEGREE;
|
|
4595
|
+
let tail = length;
|
|
4596
|
+
for (let d = this.DEPTH; d >= 0; d--) {
|
|
4597
|
+
const size = DEGREE ** d;
|
|
4598
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
4599
|
+
const zero = this.zeros[this.DEPTH - d];
|
|
4600
|
+
for (let i = tail; i < size; i++) {
|
|
4601
|
+
nodes[idx0 + i] = zero;
|
|
4602
|
+
}
|
|
4603
|
+
tail = Math.ceil(tail / DEGREE);
|
|
4604
|
+
}
|
|
4605
|
+
subTree.nodes = nodes;
|
|
4606
|
+
subTree._update(this.LEAVES_IDX_0 + length - 1);
|
|
4607
|
+
return subTree;
|
|
4608
|
+
}
|
|
4609
|
+
async _update(nodeIdx) {
|
|
4610
|
+
let idx = nodeIdx;
|
|
4611
|
+
while (idx > 0) {
|
|
4612
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
4613
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
4614
|
+
this.nodes[parentIdx] = await poseidon(
|
|
4615
|
+
this.nodes.slice(childrenIdx0, childrenIdx0 + this.DEGREE)
|
|
4616
|
+
);
|
|
4617
|
+
idx = parentIdx;
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
};
|
|
4621
|
+
var tree_default = Tree;
|
|
4622
|
+
|
|
4623
|
+
// src/libs/crypto/keys.ts
|
|
4624
|
+
var SNARK_FIELD_SIZE2 = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
4625
|
+
var genPrivKey = () => BigInt(`0x${(0, import_crypto2.randomBytes)(32).toString("hex")}`);
|
|
4626
|
+
var genRandomSalt = () => genRandomBabyJubValue();
|
|
4627
|
+
var formatPrivKeyForBabyJub = (privKey) => BigInt((0, import_eddsa_poseidon.deriveSecretScalar)(bigInt2Buffer(privKey)));
|
|
4628
|
+
var packPubKey = (pubKey) => BigInt((0, import_eddsa_poseidon2.packPublicKey)(pubKey));
|
|
4629
|
+
var unpackPubKey = (packed) => {
|
|
4630
|
+
const pubKey = (0, import_eddsa_poseidon2.unpackPublicKey)(packed);
|
|
4631
|
+
return pubKey.map((x) => BigInt(x));
|
|
4632
|
+
};
|
|
4633
|
+
var genPubKey = (privKey) => {
|
|
4634
|
+
const key = (0, import_eddsa_poseidon.derivePublicKey)(bigInt2Buffer(privKey));
|
|
4635
|
+
return [BigInt(key[0]), BigInt(key[1])];
|
|
4636
|
+
};
|
|
4637
|
+
var genKeypair = (pkey) => {
|
|
4638
|
+
const privKey = pkey ? pkey % SNARK_FIELD_SIZE2 : genPrivKey();
|
|
4639
|
+
const pubKey = genPubKey(privKey);
|
|
4640
|
+
const formatedPrivKey = formatPrivKeyForBabyJub(privKey);
|
|
4641
|
+
const keypair = { privKey, pubKey, formatedPrivKey };
|
|
4642
|
+
return keypair;
|
|
4643
|
+
};
|
|
4644
|
+
var genEcdhSharedKey = (privKey, pubKey) => (0, import_baby_jubjub2.mulPointEscalar)(pubKey, formatPrivKeyForBabyJub(privKey));
|
|
4645
|
+
var genMessageFactory = (stateIdx, signPriKey, signPubKey, coordPubKey) => (encPriKey, nonce, voIdx, newVotes, isLastCmd, salt) => {
|
|
4646
|
+
if (!salt) {
|
|
4647
|
+
salt = BigInt("0x" + (0, import_crypto2.randomBytes)(7).toString("hex"));
|
|
4648
|
+
}
|
|
4649
|
+
const packaged = BigInt(nonce) + (BigInt(stateIdx) << 32n) + (BigInt(voIdx) << 64n) + (BigInt(newVotes) << 96n) + (BigInt(salt) << 192n);
|
|
4650
|
+
let newPubKey = [...signPubKey];
|
|
4651
|
+
if (isLastCmd) {
|
|
4652
|
+
newPubKey = [0n, 0n];
|
|
4653
|
+
}
|
|
4654
|
+
const hash = poseidon([packaged, ...newPubKey]);
|
|
4655
|
+
const signature = (0, import_eddsa_poseidon.signMessage)(bigInt2Buffer(signPriKey), hash);
|
|
4656
|
+
const command = [packaged, ...newPubKey, ...signature.R8, signature.S];
|
|
4657
|
+
const message = (0, import_poseidon_cipher2.poseidonEncrypt)(
|
|
4658
|
+
command,
|
|
4659
|
+
genEcdhSharedKey(encPriKey, coordPubKey),
|
|
4660
|
+
0n
|
|
4661
|
+
);
|
|
4662
|
+
return message;
|
|
4663
|
+
};
|
|
4664
|
+
var batchGenMessage = (stateIdx, keypair, coordPubKey, plan) => {
|
|
4665
|
+
const genMessage = genMessageFactory(
|
|
4666
|
+
stateIdx,
|
|
4667
|
+
BigInt(keypair.privKey),
|
|
4668
|
+
keypair.pubKey,
|
|
4669
|
+
coordPubKey
|
|
4670
|
+
);
|
|
4671
|
+
const payload = [];
|
|
4672
|
+
for (let i = plan.length - 1; i >= 0; i--) {
|
|
4673
|
+
const p = plan[i];
|
|
4674
|
+
const encAccount = genKeypair();
|
|
4675
|
+
const msg = genMessage(
|
|
4676
|
+
BigInt(encAccount.privKey),
|
|
4677
|
+
i + 1,
|
|
4678
|
+
p[0],
|
|
4679
|
+
p[1],
|
|
4680
|
+
i === plan.length - 1
|
|
4681
|
+
);
|
|
4682
|
+
payload.push({
|
|
4683
|
+
msg,
|
|
4684
|
+
encPubkeys: encAccount.pubKey
|
|
4685
|
+
});
|
|
4686
|
+
}
|
|
4687
|
+
return payload;
|
|
4688
|
+
};
|
|
4689
|
+
var privateKeyFromTxt = (txt) => {
|
|
4690
|
+
if (typeof txt !== "string") {
|
|
4691
|
+
return;
|
|
4692
|
+
}
|
|
4693
|
+
const key = txt.split("\n")[1] || "";
|
|
4694
|
+
if (key.length !== 512) {
|
|
4695
|
+
return;
|
|
4696
|
+
}
|
|
4697
|
+
const keys = key.match(/[0-9a-f]{128}/g);
|
|
4698
|
+
if (!keys || keys.length !== 4) {
|
|
4699
|
+
return;
|
|
4700
|
+
}
|
|
4701
|
+
const priKey = poseidon(keys.map((k) => BigInt("0x" + k)));
|
|
4702
|
+
return genKeypair(priKey % SNARK_FIELD_SIZE2);
|
|
4703
|
+
};
|
|
4704
|
+
var rerandomize = (pubKey, ciphertext, randomVal = genRandomSalt()) => {
|
|
4705
|
+
const d1 = BabyJub.addPoint(
|
|
4706
|
+
BabyJub.mulPointEscalar(BabyJub.Base8, randomVal),
|
|
4707
|
+
ciphertext.c1
|
|
4708
|
+
);
|
|
4709
|
+
const d2 = BabyJub.addPoint(
|
|
4710
|
+
BabyJub.mulPointEscalar(pubKey, randomVal),
|
|
4711
|
+
ciphertext.c2
|
|
4712
|
+
);
|
|
4713
|
+
return {
|
|
4714
|
+
d1,
|
|
4715
|
+
d2
|
|
4716
|
+
};
|
|
4717
|
+
};
|
|
4718
|
+
var genAddKeyProof = async (depth, {
|
|
4719
|
+
coordPubKey,
|
|
4720
|
+
oldKey,
|
|
4721
|
+
deactivates
|
|
4722
|
+
}) => {
|
|
4723
|
+
const sharedKeyHash = poseidon(genEcdhSharedKey(oldKey.privKey, coordPubKey));
|
|
4724
|
+
const randomVal = genRandomSalt();
|
|
4725
|
+
const deactivateIdx = deactivates.findIndex((d) => d[4] === sharedKeyHash);
|
|
4726
|
+
if (deactivateIdx < 0) {
|
|
4727
|
+
return null;
|
|
4728
|
+
}
|
|
4729
|
+
const deactivateLeaf = deactivates[deactivateIdx];
|
|
4730
|
+
const c1 = [deactivateLeaf[0], deactivateLeaf[1]];
|
|
4731
|
+
const c2 = [deactivateLeaf[2], deactivateLeaf[3]];
|
|
4732
|
+
const { d1, d2 } = rerandomize(coordPubKey, { c1, c2 }, randomVal);
|
|
4733
|
+
const nullifier = poseidon([
|
|
4734
|
+
BigInt(oldKey.formatedPrivKey),
|
|
4735
|
+
1444992409218394441042n
|
|
4736
|
+
]);
|
|
4737
|
+
const tree = new tree_default(5, depth, 0n);
|
|
4738
|
+
const leaves = deactivates.map((d) => poseidon(d));
|
|
4739
|
+
tree.initLeaves(leaves);
|
|
4740
|
+
const deactivateRoot = tree.root;
|
|
4741
|
+
const deactivateLeafPathElements = tree.pathElementOf(deactivateIdx);
|
|
4742
|
+
const inputHash = BigInt(
|
|
4743
|
+
(0, import_ethers3.solidityPackedSha256)(
|
|
4744
|
+
new Array(7).fill("uint256"),
|
|
4745
|
+
stringizing([
|
|
4746
|
+
deactivateRoot,
|
|
4747
|
+
poseidon(coordPubKey),
|
|
4748
|
+
nullifier,
|
|
4749
|
+
d1[0],
|
|
4750
|
+
d1[1],
|
|
4751
|
+
d2[0],
|
|
4752
|
+
d2[1]
|
|
4753
|
+
])
|
|
4754
|
+
)
|
|
4755
|
+
) % SNARK_FIELD_SIZE2;
|
|
4756
|
+
const input = {
|
|
4757
|
+
inputHash,
|
|
4758
|
+
coordPubKey,
|
|
4759
|
+
deactivateRoot,
|
|
4760
|
+
deactivateIndex: deactivateIdx,
|
|
4761
|
+
deactivateLeaf: poseidon(deactivateLeaf),
|
|
4762
|
+
c1,
|
|
4763
|
+
c2,
|
|
4764
|
+
randomVal,
|
|
4765
|
+
d1,
|
|
4766
|
+
d2,
|
|
4767
|
+
deactivateLeafPathElements,
|
|
4768
|
+
nullifier,
|
|
4769
|
+
oldPrivateKey: oldKey.formatedPrivKey
|
|
4770
|
+
};
|
|
4771
|
+
return input;
|
|
4772
|
+
};
|
|
4773
|
+
|
|
4774
|
+
// src/libs/crypto/sign.ts
|
|
4775
|
+
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
4776
|
+
async function signMessage2(signer, address, message, network) {
|
|
4777
|
+
const accounts = await signer.getAccounts();
|
|
4778
|
+
const account = accounts.find((acc) => acc.address === address);
|
|
4779
|
+
const chainId = getDefaultParams(network).chainId;
|
|
4780
|
+
if (!account) {
|
|
4781
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
4782
|
+
}
|
|
4783
|
+
if ((0, import_proto_signing.isOfflineDirectSigner)(signer)) {
|
|
4784
|
+
const signDoc = {
|
|
4785
|
+
bodyBytes: new TextEncoder().encode(message),
|
|
4786
|
+
authInfoBytes: new Uint8Array(),
|
|
4787
|
+
chainId,
|
|
4788
|
+
accountNumber: BigInt(0)
|
|
4789
|
+
};
|
|
4790
|
+
const { signature } = await signer.signDirect(address, signDoc);
|
|
4791
|
+
return {
|
|
4792
|
+
signature: signature.signature,
|
|
4793
|
+
pubkey: account.pubkey
|
|
4794
|
+
};
|
|
4795
|
+
} else {
|
|
4796
|
+
const signDoc = {
|
|
4797
|
+
chain_id: chainId,
|
|
4798
|
+
account_number: "0",
|
|
4799
|
+
sequence: "0",
|
|
4800
|
+
fee: {
|
|
4801
|
+
gas: "0",
|
|
4802
|
+
amount: []
|
|
4803
|
+
},
|
|
4804
|
+
msgs: [],
|
|
4805
|
+
memo: message
|
|
4806
|
+
};
|
|
4807
|
+
const { signature } = await signer.signAmino(address, signDoc);
|
|
4808
|
+
return {
|
|
4809
|
+
signature: signature.signature,
|
|
4810
|
+
pubkey: account.pubkey
|
|
4811
|
+
};
|
|
4812
|
+
}
|
|
4813
|
+
}
|
|
4814
|
+
async function genKeypairFromSignature(signature) {
|
|
4815
|
+
const sign = BigInt("0x" + Buffer.from(signature, "base64").toString("hex"));
|
|
4816
|
+
return genKeypair(sign);
|
|
4817
|
+
}
|
|
4818
|
+
async function genKeypairFromSign({
|
|
4819
|
+
signer,
|
|
4820
|
+
address,
|
|
4821
|
+
network
|
|
4822
|
+
}) {
|
|
4823
|
+
if (!address) {
|
|
4824
|
+
[{ address }] = await signer.getAccounts();
|
|
4825
|
+
}
|
|
4826
|
+
const sig = await signMessage2(
|
|
4827
|
+
signer,
|
|
4828
|
+
address,
|
|
4829
|
+
"Generate_MACI_Private_Key",
|
|
4830
|
+
network
|
|
4831
|
+
);
|
|
4832
|
+
return genKeypairFromSignature(sig.signature);
|
|
4833
|
+
}
|
|
4834
|
+
|
|
4260
4835
|
// src/libs/contract/contract.ts
|
|
4261
4836
|
var Contract = class {
|
|
4262
4837
|
constructor({
|
|
@@ -4356,7 +4931,9 @@ var Contract = class {
|
|
|
4356
4931
|
const end_time = (endVoting.getTime() * 10 ** 6).toString();
|
|
4357
4932
|
const [{ address }] = await signer.getAccounts();
|
|
4358
4933
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
4359
|
-
const
|
|
4934
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
4935
|
+
BigInt(operatorPubkey)
|
|
4936
|
+
);
|
|
4360
4937
|
const {
|
|
4361
4938
|
parameters,
|
|
4362
4939
|
groth16ProcessVkey,
|
|
@@ -4383,8 +4960,8 @@ var Contract = class {
|
|
|
4383
4960
|
},
|
|
4384
4961
|
parameters,
|
|
4385
4962
|
coordinator: {
|
|
4386
|
-
x: operatorPubkeyX,
|
|
4387
|
-
y: operatorPubkeyY
|
|
4963
|
+
x: operatorPubkeyX.toString(),
|
|
4964
|
+
y: operatorPubkeyY.toString()
|
|
4388
4965
|
},
|
|
4389
4966
|
groth16_process_vkey: groth16ProcessVkey,
|
|
4390
4967
|
groth16_tally_vkey: groth16TallyVkey,
|
|
@@ -4419,7 +4996,9 @@ var Contract = class {
|
|
|
4419
4996
|
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
4420
4997
|
const [{ address }] = await signer.getAccounts();
|
|
4421
4998
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
4422
|
-
const
|
|
4999
|
+
const [operatorPubkeyX, operatorPubkeyY] = unpackPubKey(
|
|
5000
|
+
BigInt(operatorPubkey)
|
|
5001
|
+
);
|
|
4423
5002
|
const { maciVoteType, maciCertSystem } = getContractParams(
|
|
4424
5003
|
"2" /* ORACLE_MACI */,
|
|
4425
5004
|
circuitType,
|
|
@@ -4437,8 +5016,8 @@ var Contract = class {
|
|
|
4437
5016
|
end_time
|
|
4438
5017
|
},
|
|
4439
5018
|
coordinator: {
|
|
4440
|
-
x: operatorPubkeyX,
|
|
4441
|
-
y: operatorPubkeyY
|
|
5019
|
+
x: operatorPubkeyX.toString(),
|
|
5020
|
+
y: operatorPubkeyY.toString()
|
|
4442
5021
|
},
|
|
4443
5022
|
vote_option_map: voteOptionMap,
|
|
4444
5023
|
whitelist_backend_pubkey: this.whitelistBackendPubkey,
|
|
@@ -4561,272 +5140,6 @@ var OracleCertificate = class {
|
|
|
4561
5140
|
}
|
|
4562
5141
|
};
|
|
4563
5142
|
|
|
4564
|
-
// src/libs/circom/index.ts
|
|
4565
|
-
var import_proto_signing = require("@cosmjs/proto-signing");
|
|
4566
|
-
|
|
4567
|
-
// src/libs/circom/circomlib.ts
|
|
4568
|
-
var import_crypto = require("crypto");
|
|
4569
|
-
var import_circomlib = require("@dorafactory/circomlib");
|
|
4570
|
-
var import_ffjavascript = require("ffjavascript");
|
|
4571
|
-
var import_blake_hash = __toESM(require("blake-hash"));
|
|
4572
|
-
var import_ethers = require("ethers");
|
|
4573
|
-
var SNARK_FIELD_SIZE = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
4574
|
-
var bigInt2Buffer = (i) => {
|
|
4575
|
-
let hex = i.toString(16);
|
|
4576
|
-
if (hex.length % 2 === 1) {
|
|
4577
|
-
hex = "0" + hex;
|
|
4578
|
-
}
|
|
4579
|
-
return Buffer.from(hex, "hex");
|
|
4580
|
-
};
|
|
4581
|
-
var genRandomKey = () => {
|
|
4582
|
-
const min = 6350874878119819312338956282401532410528162663560392320966563075034087161851n;
|
|
4583
|
-
let rand;
|
|
4584
|
-
while (true) {
|
|
4585
|
-
rand = BigInt("0x" + (0, import_crypto.randomBytes)(32).toString("hex"));
|
|
4586
|
-
if (rand >= min) {
|
|
4587
|
-
break;
|
|
4588
|
-
}
|
|
4589
|
-
}
|
|
4590
|
-
const privKey = rand % SNARK_FIELD_SIZE;
|
|
4591
|
-
return privKey;
|
|
4592
|
-
};
|
|
4593
|
-
var genPubKey = (privKey) => {
|
|
4594
|
-
return import_circomlib.eddsa.prv2pub(bigInt2Buffer(privKey));
|
|
4595
|
-
};
|
|
4596
|
-
var stringizing = (o, path = []) => {
|
|
4597
|
-
if (path.includes(o)) {
|
|
4598
|
-
throw new Error("loop nesting!");
|
|
4599
|
-
}
|
|
4600
|
-
const newPath = [...path, o];
|
|
4601
|
-
if (Array.isArray(o)) {
|
|
4602
|
-
return o.map((item) => stringizing(item, newPath));
|
|
4603
|
-
} else if (typeof o === "object") {
|
|
4604
|
-
const output = {};
|
|
4605
|
-
for (const key in o) {
|
|
4606
|
-
output[key] = stringizing(o[key], newPath);
|
|
4607
|
-
}
|
|
4608
|
-
return output;
|
|
4609
|
-
} else {
|
|
4610
|
-
return o.toString();
|
|
4611
|
-
}
|
|
4612
|
-
};
|
|
4613
|
-
var genKeypair = (pkey) => {
|
|
4614
|
-
const privKey = pkey ? pkey % SNARK_FIELD_SIZE : genRandomKey();
|
|
4615
|
-
const pubKey = genPubKey(privKey);
|
|
4616
|
-
const formatedPrivKey = formatPrivKeyForBabyJub(privKey);
|
|
4617
|
-
return { privKey, pubKey, formatedPrivKey };
|
|
4618
|
-
};
|
|
4619
|
-
var formatPrivKeyForBabyJub = (privKey) => {
|
|
4620
|
-
const sBuff = import_circomlib.eddsa.pruneBuffer(
|
|
4621
|
-
(0, import_blake_hash.default)("blake512").update(bigInt2Buffer(privKey)).digest().slice(0, 32)
|
|
4622
|
-
);
|
|
4623
|
-
const s = import_ffjavascript.utils.leBuff2int(sBuff);
|
|
4624
|
-
return import_ffjavascript.Scalar.shr(s, 3);
|
|
4625
|
-
};
|
|
4626
|
-
var genEcdhSharedKey = (privKey, pubKey) => {
|
|
4627
|
-
const sharedKey = import_circomlib.babyJub.mulPointEscalar(
|
|
4628
|
-
pubKey,
|
|
4629
|
-
formatPrivKeyForBabyJub(privKey)
|
|
4630
|
-
);
|
|
4631
|
-
if (sharedKey[0] === 0n) {
|
|
4632
|
-
return [0n, 1n];
|
|
4633
|
-
} else {
|
|
4634
|
-
return sharedKey;
|
|
4635
|
-
}
|
|
4636
|
-
};
|
|
4637
|
-
var genMessageFactory = (stateIdx, signPriKey, signPubKey, coordPubKey) => (encPriKey, nonce, voIdx, newVotes, isLastCmd, salt) => {
|
|
4638
|
-
if (!salt) {
|
|
4639
|
-
salt = BigInt("0x" + (0, import_crypto.randomBytes)(7).toString("hex"));
|
|
4640
|
-
}
|
|
4641
|
-
const packaged = BigInt(nonce) + (BigInt(stateIdx) << 32n) + (BigInt(voIdx) << 64n) + (BigInt(newVotes) << 96n) + (BigInt(salt) << 192n);
|
|
4642
|
-
let newPubKey = [...signPubKey];
|
|
4643
|
-
if (isLastCmd) {
|
|
4644
|
-
newPubKey = [0n, 0n];
|
|
4645
|
-
}
|
|
4646
|
-
const hash = (0, import_circomlib.poseidon)([packaged, ...newPubKey]);
|
|
4647
|
-
const signature = import_circomlib.eddsa.signPoseidon(bigInt2Buffer(signPriKey), hash);
|
|
4648
|
-
const command = [packaged, ...newPubKey, ...signature.R8, signature.S];
|
|
4649
|
-
const message = (0, import_circomlib.poseidonEncrypt)(
|
|
4650
|
-
command,
|
|
4651
|
-
genEcdhSharedKey(encPriKey, coordPubKey),
|
|
4652
|
-
0n
|
|
4653
|
-
);
|
|
4654
|
-
return message;
|
|
4655
|
-
};
|
|
4656
|
-
var batchGenMessage = (stateIdx, account, coordPubKey, plan) => {
|
|
4657
|
-
const genMessage = genMessageFactory(
|
|
4658
|
-
stateIdx,
|
|
4659
|
-
account.privKey,
|
|
4660
|
-
account.pubKey,
|
|
4661
|
-
coordPubKey
|
|
4662
|
-
);
|
|
4663
|
-
const payload = [];
|
|
4664
|
-
for (let i = plan.length - 1; i >= 0; i--) {
|
|
4665
|
-
const p = plan[i];
|
|
4666
|
-
const encAccount = genKeypair();
|
|
4667
|
-
const msg = genMessage(
|
|
4668
|
-
encAccount.privKey,
|
|
4669
|
-
i + 1,
|
|
4670
|
-
p[0],
|
|
4671
|
-
p[1],
|
|
4672
|
-
i === plan.length - 1
|
|
4673
|
-
);
|
|
4674
|
-
payload.push({
|
|
4675
|
-
msg,
|
|
4676
|
-
encPubkeys: encAccount.pubKey
|
|
4677
|
-
});
|
|
4678
|
-
}
|
|
4679
|
-
return payload;
|
|
4680
|
-
};
|
|
4681
|
-
var privateKeyFromTxt = (txt) => {
|
|
4682
|
-
if (typeof txt !== "string") {
|
|
4683
|
-
return;
|
|
4684
|
-
}
|
|
4685
|
-
const key = txt.split("\n")[1] || "";
|
|
4686
|
-
if (key.length !== 512) {
|
|
4687
|
-
return;
|
|
4688
|
-
}
|
|
4689
|
-
const keys = key.match(/[0-9a-f]{128}/g);
|
|
4690
|
-
if (!keys || keys.length !== 4) {
|
|
4691
|
-
return;
|
|
4692
|
-
}
|
|
4693
|
-
const priKey = (0, import_circomlib.poseidon)(keys.map((k) => BigInt("0x" + k)));
|
|
4694
|
-
return genKeypair(priKey % SNARK_FIELD_SIZE);
|
|
4695
|
-
};
|
|
4696
|
-
var rerandomize = (pubKey, ciphertext, randomVal = genRandomKey()) => {
|
|
4697
|
-
const d1 = import_circomlib.babyJub.addPoint(
|
|
4698
|
-
import_circomlib.babyJub.mulPointEscalar(import_circomlib.babyJub.Base8, randomVal),
|
|
4699
|
-
ciphertext.c1
|
|
4700
|
-
);
|
|
4701
|
-
const d2 = import_circomlib.babyJub.addPoint(
|
|
4702
|
-
import_circomlib.babyJub.mulPointEscalar(pubKey, randomVal),
|
|
4703
|
-
ciphertext.c2
|
|
4704
|
-
);
|
|
4705
|
-
return {
|
|
4706
|
-
d1,
|
|
4707
|
-
d2
|
|
4708
|
-
};
|
|
4709
|
-
};
|
|
4710
|
-
var genAddKeyProof = async (depth, {
|
|
4711
|
-
coordPubKey,
|
|
4712
|
-
oldKey,
|
|
4713
|
-
deactivates
|
|
4714
|
-
}) => {
|
|
4715
|
-
const sharedKeyHash = (0, import_circomlib.poseidon)(genEcdhSharedKey(oldKey.privKey, coordPubKey));
|
|
4716
|
-
const randomVal = genRandomKey();
|
|
4717
|
-
const deactivateIdx = deactivates.findIndex((d) => d[4] === sharedKeyHash);
|
|
4718
|
-
if (deactivateIdx < 0) {
|
|
4719
|
-
return null;
|
|
4720
|
-
}
|
|
4721
|
-
const deactivateLeaf = deactivates[deactivateIdx];
|
|
4722
|
-
const c1 = [deactivateLeaf[0], deactivateLeaf[1]];
|
|
4723
|
-
const c2 = [deactivateLeaf[2], deactivateLeaf[3]];
|
|
4724
|
-
const { d1, d2 } = rerandomize(coordPubKey, { c1, c2 }, randomVal);
|
|
4725
|
-
const nullifier = (0, import_circomlib.poseidon)([oldKey.formatedPrivKey, 1444992409218394441042n]);
|
|
4726
|
-
const tree = new import_circomlib.Tree(5, depth, 0n);
|
|
4727
|
-
const leaves = deactivates.map((d) => (0, import_circomlib.poseidon)(d));
|
|
4728
|
-
tree.initLeaves(leaves);
|
|
4729
|
-
const deactivateRoot = tree.root;
|
|
4730
|
-
const deactivateLeafPathElements = tree.pathElementOf(deactivateIdx);
|
|
4731
|
-
const inputHash = BigInt(
|
|
4732
|
-
(0, import_ethers.solidityPackedSha256)(
|
|
4733
|
-
new Array(7).fill("uint256"),
|
|
4734
|
-
stringizing([
|
|
4735
|
-
deactivateRoot,
|
|
4736
|
-
(0, import_circomlib.poseidon)(coordPubKey),
|
|
4737
|
-
nullifier,
|
|
4738
|
-
d1[0],
|
|
4739
|
-
d1[1],
|
|
4740
|
-
d2[0],
|
|
4741
|
-
d2[1]
|
|
4742
|
-
])
|
|
4743
|
-
)
|
|
4744
|
-
) % SNARK_FIELD_SIZE;
|
|
4745
|
-
const input = {
|
|
4746
|
-
inputHash,
|
|
4747
|
-
coordPubKey,
|
|
4748
|
-
deactivateRoot,
|
|
4749
|
-
deactivateIndex: deactivateIdx,
|
|
4750
|
-
deactivateLeaf: (0, import_circomlib.poseidon)(deactivateLeaf),
|
|
4751
|
-
c1,
|
|
4752
|
-
c2,
|
|
4753
|
-
randomVal,
|
|
4754
|
-
d1,
|
|
4755
|
-
d2,
|
|
4756
|
-
deactivateLeafPathElements,
|
|
4757
|
-
nullifier,
|
|
4758
|
-
oldPrivateKey: oldKey.formatedPrivKey
|
|
4759
|
-
};
|
|
4760
|
-
return input;
|
|
4761
|
-
};
|
|
4762
|
-
|
|
4763
|
-
// src/libs/circom/index.ts
|
|
4764
|
-
var Circom = class {
|
|
4765
|
-
constructor({ network }) {
|
|
4766
|
-
this.network = network;
|
|
4767
|
-
this.chainId = getDefaultParams(network).chainId;
|
|
4768
|
-
}
|
|
4769
|
-
async signMessage(signer, address, message) {
|
|
4770
|
-
if (typeof window !== "undefined" && window.keplr) {
|
|
4771
|
-
const sig = await window.keplr.signArbitrary(
|
|
4772
|
-
this.chainId,
|
|
4773
|
-
address,
|
|
4774
|
-
message
|
|
4775
|
-
);
|
|
4776
|
-
return {
|
|
4777
|
-
signature: sig.signature,
|
|
4778
|
-
pubkey: sig.pub_key.value
|
|
4779
|
-
};
|
|
4780
|
-
}
|
|
4781
|
-
const accounts = await signer.getAccounts();
|
|
4782
|
-
const account = accounts.find((acc) => acc.address === address);
|
|
4783
|
-
if (!account) {
|
|
4784
|
-
throw new Error(`Address ${address} not found in wallet`);
|
|
4785
|
-
}
|
|
4786
|
-
if ((0, import_proto_signing.isOfflineDirectSigner)(signer)) {
|
|
4787
|
-
const signDoc = {
|
|
4788
|
-
bodyBytes: new TextEncoder().encode(message),
|
|
4789
|
-
authInfoBytes: new Uint8Array(),
|
|
4790
|
-
chainId: this.chainId,
|
|
4791
|
-
accountNumber: BigInt(0)
|
|
4792
|
-
};
|
|
4793
|
-
const { signature } = await signer.signDirect(address, signDoc);
|
|
4794
|
-
return {
|
|
4795
|
-
signature: signature.signature,
|
|
4796
|
-
pubkey: account.pubkey
|
|
4797
|
-
};
|
|
4798
|
-
} else {
|
|
4799
|
-
const signDoc = {
|
|
4800
|
-
chain_id: this.chainId,
|
|
4801
|
-
account_number: "0",
|
|
4802
|
-
sequence: "0",
|
|
4803
|
-
fee: {
|
|
4804
|
-
gas: "0",
|
|
4805
|
-
amount: []
|
|
4806
|
-
},
|
|
4807
|
-
msgs: [],
|
|
4808
|
-
memo: message
|
|
4809
|
-
};
|
|
4810
|
-
const { signature } = await signer.signAmino(address, signDoc);
|
|
4811
|
-
return {
|
|
4812
|
-
signature: signature.signature,
|
|
4813
|
-
pubkey: account.pubkey
|
|
4814
|
-
};
|
|
4815
|
-
}
|
|
4816
|
-
}
|
|
4817
|
-
async genKeypairFromSign(signer, address) {
|
|
4818
|
-
const sig = await this.signMessage(
|
|
4819
|
-
signer,
|
|
4820
|
-
address,
|
|
4821
|
-
"Generate_MACI_Private_Key"
|
|
4822
|
-
);
|
|
4823
|
-
const sign = BigInt(
|
|
4824
|
-
"0x" + Buffer.from(sig.signature, "base64").toString("hex")
|
|
4825
|
-
);
|
|
4826
|
-
return genKeypair(sign);
|
|
4827
|
-
}
|
|
4828
|
-
};
|
|
4829
|
-
|
|
4830
5143
|
// src/libs/maci/maci.ts
|
|
4831
5144
|
var import_stargate2 = require("@cosmjs/stargate");
|
|
4832
5145
|
var import_tx = require("cosmjs-types/cosmwasm/wasm/v1/tx.js");
|
|
@@ -4835,15 +5148,15 @@ function isErrorResponse(response) {
|
|
|
4835
5148
|
}
|
|
4836
5149
|
var MACI = class {
|
|
4837
5150
|
constructor({
|
|
4838
|
-
circom,
|
|
4839
5151
|
contract,
|
|
4840
5152
|
indexer,
|
|
4841
|
-
oracleCertificate
|
|
5153
|
+
oracleCertificate,
|
|
5154
|
+
maciKeypair
|
|
4842
5155
|
}) {
|
|
4843
|
-
this.circom = circom;
|
|
4844
5156
|
this.contract = contract;
|
|
4845
5157
|
this.indexer = indexer;
|
|
4846
5158
|
this.oracleCertificate = oracleCertificate;
|
|
5159
|
+
this.maciKeypair = maciKeypair;
|
|
4847
5160
|
}
|
|
4848
5161
|
async getStateIdxInc({
|
|
4849
5162
|
signer,
|
|
@@ -4961,8 +5274,8 @@ var MACI = class {
|
|
|
4961
5274
|
contractAddress
|
|
4962
5275
|
});
|
|
4963
5276
|
const balance = await client.whiteBalanceOf({
|
|
4964
|
-
amount:
|
|
4965
|
-
certificate,
|
|
5277
|
+
amount: certificate.amount,
|
|
5278
|
+
certificate: certificate.signature,
|
|
4966
5279
|
sender: address
|
|
4967
5280
|
});
|
|
4968
5281
|
return balance;
|
|
@@ -5133,7 +5446,7 @@ var MACI = class {
|
|
|
5133
5446
|
signer,
|
|
5134
5447
|
address,
|
|
5135
5448
|
contractAddress,
|
|
5136
|
-
|
|
5449
|
+
maciKeypair,
|
|
5137
5450
|
oracleCertificate,
|
|
5138
5451
|
gasStation = false
|
|
5139
5452
|
}) {
|
|
@@ -5141,8 +5454,8 @@ var MACI = class {
|
|
|
5141
5454
|
if (!address) {
|
|
5142
5455
|
address = (await signer.getAccounts())[0].address;
|
|
5143
5456
|
}
|
|
5144
|
-
if (
|
|
5145
|
-
|
|
5457
|
+
if (maciKeypair === void 0) {
|
|
5458
|
+
maciKeypair = this.maciKeypair;
|
|
5146
5459
|
}
|
|
5147
5460
|
const client = await this.contract.contractClient({
|
|
5148
5461
|
signer
|
|
@@ -5151,7 +5464,7 @@ var MACI = class {
|
|
|
5151
5464
|
return await this.signupOracle({
|
|
5152
5465
|
client,
|
|
5153
5466
|
address,
|
|
5154
|
-
pubKey:
|
|
5467
|
+
pubKey: maciKeypair.pubKey,
|
|
5155
5468
|
contractAddress,
|
|
5156
5469
|
oracleCertificate,
|
|
5157
5470
|
gasStation
|
|
@@ -5160,7 +5473,7 @@ var MACI = class {
|
|
|
5160
5473
|
return await this.signupSimple({
|
|
5161
5474
|
client,
|
|
5162
5475
|
address,
|
|
5163
|
-
pubKey:
|
|
5476
|
+
pubKey: maciKeypair.pubKey,
|
|
5164
5477
|
contractAddress,
|
|
5165
5478
|
gasStation
|
|
5166
5479
|
});
|
|
@@ -5198,7 +5511,7 @@ var MACI = class {
|
|
|
5198
5511
|
contractAddress,
|
|
5199
5512
|
selectedOptions,
|
|
5200
5513
|
operatorCoordPubKey,
|
|
5201
|
-
|
|
5514
|
+
maciKeypair,
|
|
5202
5515
|
gasStation = false
|
|
5203
5516
|
}) {
|
|
5204
5517
|
if (stateIdx === -1) {
|
|
@@ -5218,15 +5531,15 @@ var MACI = class {
|
|
|
5218
5531
|
if (!address) {
|
|
5219
5532
|
address = (await signer.getAccounts())[0].address;
|
|
5220
5533
|
}
|
|
5221
|
-
if (
|
|
5222
|
-
|
|
5534
|
+
if (maciKeypair === void 0) {
|
|
5535
|
+
maciKeypair = this.maciKeypair;
|
|
5223
5536
|
}
|
|
5224
5537
|
const plan = options.map((o) => {
|
|
5225
5538
|
return [o.idx, o.vc];
|
|
5226
5539
|
});
|
|
5227
5540
|
const payload = batchGenMessage(
|
|
5228
5541
|
stateIdx,
|
|
5229
|
-
|
|
5542
|
+
maciKeypair,
|
|
5230
5543
|
operatorCoordPubKey,
|
|
5231
5544
|
plan
|
|
5232
5545
|
);
|
|
@@ -5521,6 +5834,7 @@ var MaciClient2 = class {
|
|
|
5521
5834
|
* @param {ClientParams} params - The parameters for the Maci Client instance.
|
|
5522
5835
|
*/
|
|
5523
5836
|
constructor({
|
|
5837
|
+
signer,
|
|
5524
5838
|
network,
|
|
5525
5839
|
rpcEndpoint,
|
|
5526
5840
|
restEndpoint,
|
|
@@ -5532,8 +5846,11 @@ var MaciClient2 = class {
|
|
|
5532
5846
|
defaultOptions,
|
|
5533
5847
|
feegrantOperator,
|
|
5534
5848
|
whitelistBackendPubkey,
|
|
5535
|
-
certificateApiEndpoint
|
|
5849
|
+
certificateApiEndpoint,
|
|
5850
|
+
maciKeypair
|
|
5536
5851
|
}) {
|
|
5852
|
+
this.signer = signer;
|
|
5853
|
+
this.network = network;
|
|
5537
5854
|
const defaultParams = getDefaultParams(network);
|
|
5538
5855
|
this.rpcEndpoint = rpcEndpoint || defaultParams.rpcEndpoint;
|
|
5539
5856
|
this.restEndpoint = restEndpoint || defaultParams.restEndpoint;
|
|
@@ -5544,6 +5861,7 @@ var MaciClient2 = class {
|
|
|
5544
5861
|
this.oracleCodeId = oracleCodeId || defaultParams.oracleCodeId;
|
|
5545
5862
|
this.feegrantOperator = feegrantOperator || defaultParams.oracleFeegrantOperator;
|
|
5546
5863
|
this.whitelistBackendPubkey = whitelistBackendPubkey || defaultParams.oracleWhitelistBackendPubkey;
|
|
5864
|
+
this.maciKeypair = maciKeypair ?? genKeypair();
|
|
5547
5865
|
this.http = new Http(
|
|
5548
5866
|
this.apiEndpoint,
|
|
5549
5867
|
this.restEndpoint,
|
|
@@ -5564,22 +5882,41 @@ var MaciClient2 = class {
|
|
|
5564
5882
|
feegrantOperator: this.feegrantOperator,
|
|
5565
5883
|
whitelistBackendPubkey: this.whitelistBackendPubkey
|
|
5566
5884
|
});
|
|
5567
|
-
this.circom = new Circom({ network });
|
|
5568
5885
|
this.oracleCertificate = new OracleCertificate({
|
|
5569
5886
|
certificateApiEndpoint: this.certificateApiEndpoint,
|
|
5570
5887
|
http: this.http
|
|
5571
5888
|
});
|
|
5572
5889
|
this.maci = new MACI({
|
|
5573
|
-
circom: this.circom,
|
|
5574
5890
|
contract: this.contract,
|
|
5575
5891
|
indexer: this.indexer,
|
|
5576
|
-
oracleCertificate: this.oracleCertificate
|
|
5892
|
+
oracleCertificate: this.oracleCertificate,
|
|
5893
|
+
maciKeypair: this.maciKeypair
|
|
5577
5894
|
});
|
|
5578
5895
|
}
|
|
5896
|
+
getSigner(signer) {
|
|
5897
|
+
return signer || this.signer;
|
|
5898
|
+
}
|
|
5899
|
+
getMaciKeypair() {
|
|
5900
|
+
return this.maciKeypair;
|
|
5901
|
+
}
|
|
5902
|
+
getMaciPubkey() {
|
|
5903
|
+
return this.packMaciPubkey(this.maciKeypair.pubKey);
|
|
5904
|
+
}
|
|
5905
|
+
packMaciPubkey(pubkey) {
|
|
5906
|
+
return packPubKey(pubkey || this.maciKeypair.pubKey);
|
|
5907
|
+
}
|
|
5908
|
+
unpackMaciPubkey(pubkey) {
|
|
5909
|
+
return unpackPubKey(BigInt(pubkey));
|
|
5910
|
+
}
|
|
5911
|
+
async getAddress(signer) {
|
|
5912
|
+
const [{ address }] = await this.getSigner(signer).getAccounts();
|
|
5913
|
+
return address;
|
|
5914
|
+
}
|
|
5579
5915
|
async oracleMaciClient({
|
|
5580
5916
|
signer,
|
|
5581
5917
|
contractAddress
|
|
5582
5918
|
}) {
|
|
5919
|
+
signer = this.getSigner(signer);
|
|
5583
5920
|
return await this.contract.oracleMaciClient({
|
|
5584
5921
|
signer,
|
|
5585
5922
|
contractAddress
|
|
@@ -5589,28 +5926,50 @@ var MaciClient2 = class {
|
|
|
5589
5926
|
signer,
|
|
5590
5927
|
contractAddress
|
|
5591
5928
|
}) {
|
|
5929
|
+
signer = this.getSigner(signer);
|
|
5592
5930
|
return await this.contract.registryClient({ signer, contractAddress });
|
|
5593
5931
|
}
|
|
5594
5932
|
async maciClient({
|
|
5595
5933
|
signer,
|
|
5596
5934
|
contractAddress
|
|
5597
5935
|
}) {
|
|
5936
|
+
signer = this.getSigner(signer);
|
|
5598
5937
|
return await this.contract.maciClient({ signer, contractAddress });
|
|
5599
5938
|
}
|
|
5600
5939
|
async amaciClient({
|
|
5601
5940
|
signer,
|
|
5602
5941
|
contractAddress
|
|
5603
5942
|
}) {
|
|
5943
|
+
signer = this.getSigner(signer);
|
|
5604
5944
|
return await this.contract.amaciClient({ signer, contractAddress });
|
|
5605
5945
|
}
|
|
5606
5946
|
async createAMaciRound(params) {
|
|
5607
|
-
return await this.contract.createAMaciRound(
|
|
5947
|
+
return await this.contract.createAMaciRound({
|
|
5948
|
+
signer: this.getSigner(),
|
|
5949
|
+
...params
|
|
5950
|
+
});
|
|
5608
5951
|
}
|
|
5609
5952
|
async createMaciRound(params) {
|
|
5610
|
-
return await this.contract.createMaciRound(
|
|
5953
|
+
return await this.contract.createMaciRound({
|
|
5954
|
+
signer: this.getSigner(),
|
|
5955
|
+
...params
|
|
5956
|
+
});
|
|
5611
5957
|
}
|
|
5612
5958
|
async createOracleMaciRound(params) {
|
|
5613
|
-
return await this.contract.createOracleMaciRound(
|
|
5959
|
+
return await this.contract.createOracleMaciRound({
|
|
5960
|
+
signer: this.getSigner(),
|
|
5961
|
+
...params
|
|
5962
|
+
});
|
|
5963
|
+
}
|
|
5964
|
+
async genKeypairFromSign({
|
|
5965
|
+
signer,
|
|
5966
|
+
address
|
|
5967
|
+
} = {}) {
|
|
5968
|
+
return await genKeypairFromSign({
|
|
5969
|
+
signer: this.getSigner(signer),
|
|
5970
|
+
address,
|
|
5971
|
+
network: this.network
|
|
5972
|
+
});
|
|
5614
5973
|
}
|
|
5615
5974
|
async getStateIdxInc({
|
|
5616
5975
|
signer,
|
|
@@ -5618,7 +5977,7 @@ var MaciClient2 = class {
|
|
|
5618
5977
|
contractAddress
|
|
5619
5978
|
}) {
|
|
5620
5979
|
return await this.maci.getStateIdxInc({
|
|
5621
|
-
signer,
|
|
5980
|
+
signer: this.getSigner(signer),
|
|
5622
5981
|
address,
|
|
5623
5982
|
contractAddress
|
|
5624
5983
|
});
|
|
@@ -5629,7 +5988,7 @@ var MaciClient2 = class {
|
|
|
5629
5988
|
contractAddress
|
|
5630
5989
|
}) {
|
|
5631
5990
|
return await this.maci.getVoiceCreditBalance({
|
|
5632
|
-
signer,
|
|
5991
|
+
signer: this.getSigner(signer),
|
|
5633
5992
|
stateIdx,
|
|
5634
5993
|
contractAddress
|
|
5635
5994
|
});
|
|
@@ -5644,18 +6003,22 @@ var MaciClient2 = class {
|
|
|
5644
6003
|
});
|
|
5645
6004
|
}
|
|
5646
6005
|
async feegrantAllowance({
|
|
6006
|
+
signer,
|
|
5647
6007
|
address,
|
|
5648
6008
|
contractAddress
|
|
5649
6009
|
}) {
|
|
6010
|
+
address = await this.getAddress(signer);
|
|
5650
6011
|
return await this.maci.feegrantAllowance({
|
|
5651
6012
|
address,
|
|
5652
6013
|
contractAddress
|
|
5653
6014
|
});
|
|
5654
6015
|
}
|
|
5655
6016
|
async hasFeegrant({
|
|
6017
|
+
signer,
|
|
5656
6018
|
address,
|
|
5657
6019
|
contractAddress
|
|
5658
6020
|
}) {
|
|
6021
|
+
address = await this.getAddress(signer);
|
|
5659
6022
|
return await this.maci.hasFeegrant({
|
|
5660
6023
|
address,
|
|
5661
6024
|
contractAddress
|
|
@@ -5668,6 +6031,10 @@ var MaciClient2 = class {
|
|
|
5668
6031
|
certificate,
|
|
5669
6032
|
mode = "maci"
|
|
5670
6033
|
}) {
|
|
6034
|
+
signer = this.getSigner(signer);
|
|
6035
|
+
if (!address) {
|
|
6036
|
+
address = await this.getAddress(signer);
|
|
6037
|
+
}
|
|
5671
6038
|
return await this.maci.queryWhitelistBalanceOf({
|
|
5672
6039
|
signer,
|
|
5673
6040
|
address,
|
|
@@ -5681,6 +6048,10 @@ var MaciClient2 = class {
|
|
|
5681
6048
|
address,
|
|
5682
6049
|
contractAddress
|
|
5683
6050
|
}) {
|
|
6051
|
+
signer = this.getSigner(signer);
|
|
6052
|
+
if (!address) {
|
|
6053
|
+
address = await this.getAddress(signer);
|
|
6054
|
+
}
|
|
5684
6055
|
return await this.maci.isWhitelisted({
|
|
5685
6056
|
signer,
|
|
5686
6057
|
address,
|
|
@@ -5692,7 +6063,7 @@ var MaciClient2 = class {
|
|
|
5692
6063
|
contractAddress
|
|
5693
6064
|
}) {
|
|
5694
6065
|
return await this.maci.getOracleWhitelistConfig({
|
|
5695
|
-
signer,
|
|
6066
|
+
signer: this.getSigner(signer),
|
|
5696
6067
|
contractAddress
|
|
5697
6068
|
});
|
|
5698
6069
|
}
|
|
@@ -5740,7 +6111,7 @@ var MaciClient2 = class {
|
|
|
5740
6111
|
contractAddress
|
|
5741
6112
|
}) {
|
|
5742
6113
|
return await this.maci.requestOracleCertificate({
|
|
5743
|
-
signer,
|
|
6114
|
+
signer: this.getSigner(signer),
|
|
5744
6115
|
ecosystem,
|
|
5745
6116
|
address,
|
|
5746
6117
|
contractAddress
|
|
@@ -5750,15 +6121,15 @@ var MaciClient2 = class {
|
|
|
5750
6121
|
signer,
|
|
5751
6122
|
address,
|
|
5752
6123
|
contractAddress,
|
|
5753
|
-
|
|
6124
|
+
maciKeypair,
|
|
5754
6125
|
oracleCertificate,
|
|
5755
6126
|
gasStation = false
|
|
5756
6127
|
}) {
|
|
5757
6128
|
return await this.maci.signup({
|
|
5758
|
-
signer,
|
|
6129
|
+
signer: this.getSigner(signer),
|
|
5759
6130
|
address,
|
|
5760
6131
|
contractAddress,
|
|
5761
|
-
|
|
6132
|
+
maciKeypair,
|
|
5762
6133
|
oracleCertificate,
|
|
5763
6134
|
gasStation
|
|
5764
6135
|
});
|
|
@@ -5770,17 +6141,17 @@ var MaciClient2 = class {
|
|
|
5770
6141
|
contractAddress,
|
|
5771
6142
|
selectedOptions,
|
|
5772
6143
|
operatorCoordPubKey,
|
|
5773
|
-
|
|
6144
|
+
maciKeypair,
|
|
5774
6145
|
gasStation = false
|
|
5775
6146
|
}) {
|
|
5776
6147
|
return await this.maci.vote({
|
|
5777
|
-
signer,
|
|
6148
|
+
signer: this.getSigner(signer),
|
|
5778
6149
|
address,
|
|
5779
6150
|
stateIdx,
|
|
5780
6151
|
contractAddress,
|
|
5781
6152
|
selectedOptions,
|
|
5782
6153
|
operatorCoordPubKey,
|
|
5783
|
-
|
|
6154
|
+
maciKeypair,
|
|
5784
6155
|
gasStation
|
|
5785
6156
|
});
|
|
5786
6157
|
}
|
|
@@ -5788,6 +6159,7 @@ var MaciClient2 = class {
|
|
|
5788
6159
|
signer,
|
|
5789
6160
|
contractAddress
|
|
5790
6161
|
}) {
|
|
6162
|
+
signer = this.getSigner(signer);
|
|
5791
6163
|
return await this.maci.claimAMaciRound({
|
|
5792
6164
|
signer,
|
|
5793
6165
|
contractAddress
|
|
@@ -5802,8 +6174,11 @@ var MaciClient2 = class {
|
|
|
5802
6174
|
address,
|
|
5803
6175
|
amount
|
|
5804
6176
|
}) {
|
|
6177
|
+
if (!address) {
|
|
6178
|
+
address = await this.getAddress(signer);
|
|
6179
|
+
}
|
|
5805
6180
|
return await this.maci.batchGrantWithBond({
|
|
5806
|
-
signer,
|
|
6181
|
+
signer: this.getSigner(signer),
|
|
5807
6182
|
contractAddress,
|
|
5808
6183
|
address,
|
|
5809
6184
|
amount
|
|
@@ -5814,23 +6189,23 @@ var MaciClient2 = class {
|
|
|
5814
6189
|
contractAddress,
|
|
5815
6190
|
address
|
|
5816
6191
|
}) {
|
|
6192
|
+
if (!address) {
|
|
6193
|
+
address = await this.getAddress(signer);
|
|
6194
|
+
}
|
|
5817
6195
|
return await this.maci.batchRevokeWithdraw({
|
|
5818
|
-
signer,
|
|
6196
|
+
signer: this.getSigner(signer),
|
|
5819
6197
|
contractAddress,
|
|
5820
6198
|
address
|
|
5821
6199
|
});
|
|
5822
6200
|
}
|
|
5823
6201
|
};
|
|
5824
|
-
|
|
5825
|
-
// src/index.ts
|
|
5826
|
-
var import_ffjavascript2 = require("ffjavascript");
|
|
5827
|
-
var import_blake_hash2 = __toESM(require("blake-hash"));
|
|
5828
6202
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5829
6203
|
0 && (module.exports = {
|
|
5830
|
-
Circom,
|
|
5831
6204
|
Circuit,
|
|
5832
6205
|
Contract,
|
|
5833
6206
|
Event,
|
|
6207
|
+
G1Point,
|
|
6208
|
+
G2Point,
|
|
5834
6209
|
Http,
|
|
5835
6210
|
Indexer,
|
|
5836
6211
|
MACI,
|
|
@@ -5838,28 +6213,53 @@ var import_blake_hash2 = __toESM(require("blake-hash"));
|
|
|
5838
6213
|
MaciCircuitType,
|
|
5839
6214
|
MaciClient,
|
|
5840
6215
|
MaciRoundType,
|
|
6216
|
+
NOTHING_UP_MY_SLEEVE,
|
|
5841
6217
|
Operator,
|
|
5842
6218
|
OracleCertificate,
|
|
6219
|
+
PAD_KEY_HASH,
|
|
5843
6220
|
Proof,
|
|
5844
6221
|
Round,
|
|
5845
|
-
|
|
6222
|
+
SNARK_FIELD_SIZE,
|
|
5846
6223
|
Transaction,
|
|
6224
|
+
Tree,
|
|
5847
6225
|
UserAccount,
|
|
5848
6226
|
batchGenMessage,
|
|
6227
|
+
bigInt2Buffer,
|
|
5849
6228
|
circuits,
|
|
5850
|
-
|
|
5851
|
-
createBlakeHash,
|
|
5852
|
-
decompressPublicKey,
|
|
6229
|
+
formatPrivKeyForBabyJub,
|
|
5853
6230
|
genAddKeyProof,
|
|
5854
6231
|
genEcdhSharedKey,
|
|
5855
6232
|
genKeypair,
|
|
6233
|
+
genKeypairFromSign,
|
|
6234
|
+
genKeypairFromSignature,
|
|
5856
6235
|
genMessageFactory,
|
|
6236
|
+
genPrivKey,
|
|
6237
|
+
genPubKey,
|
|
6238
|
+
genRandomBabyJubValue,
|
|
6239
|
+
genRandomSalt,
|
|
5857
6240
|
getDefaultParams,
|
|
6241
|
+
hash12,
|
|
6242
|
+
hash2,
|
|
6243
|
+
hash3,
|
|
6244
|
+
hash4,
|
|
6245
|
+
hash5,
|
|
6246
|
+
hashLeanIMT,
|
|
6247
|
+
hashLeftRight,
|
|
6248
|
+
hashN,
|
|
6249
|
+
hashOne,
|
|
5858
6250
|
hexToDecimalString,
|
|
5859
6251
|
isValidAddress,
|
|
6252
|
+
packPubKey,
|
|
6253
|
+
poseidon,
|
|
6254
|
+
poseidonT3,
|
|
6255
|
+
poseidonT4,
|
|
6256
|
+
poseidonT5,
|
|
6257
|
+
poseidonT6,
|
|
5860
6258
|
privateKeyFromTxt,
|
|
6259
|
+
sha256Hash,
|
|
6260
|
+
signMessage,
|
|
5861
6261
|
stringizing,
|
|
5862
|
-
|
|
6262
|
+
unpackPubKey,
|
|
5863
6263
|
validator_operator_set
|
|
5864
6264
|
});
|
|
5865
6265
|
//# sourceMappingURL=index.js.map
|