@dorafactory/maci-sdk 0.0.2 → 0.0.4
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/README.md +113 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +38 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -14
- package/dist/index.mjs.map +1 -1
- package/dist/libs/contract/utils.d.ts +0 -9
- package/dist/utils/index.d.ts +16 -0
- package/package.json +1 -11
- package/src/index.ts +1 -0
- package/src/libs/contract/contract.ts +4 -3
- package/src/libs/contract/utils.ts +0 -25
- package/src/utils/index.ts +43 -27
package/dist/index.mjs
CHANGED
|
@@ -516,6 +516,34 @@ function verifyIsBech32(address) {
|
|
|
516
516
|
function isValidAddress(address) {
|
|
517
517
|
return address.startsWith("dora") && verifyIsBech32(address) === void 0;
|
|
518
518
|
}
|
|
519
|
+
function hexToDecimalString(hexString) {
|
|
520
|
+
const decimalString = BigInt("0x" + hexString).toString(10);
|
|
521
|
+
return decimalString;
|
|
522
|
+
}
|
|
523
|
+
function padWithZerosIfNeeded(inputString) {
|
|
524
|
+
if (inputString.length === 64) {
|
|
525
|
+
return inputString;
|
|
526
|
+
} else if (inputString.length < 64) {
|
|
527
|
+
const zerosToAdd = 64 - inputString.length;
|
|
528
|
+
const zeroPadding = "0".repeat(zerosToAdd);
|
|
529
|
+
return zeroPadding + inputString;
|
|
530
|
+
}
|
|
531
|
+
throw new Error("Invalid input string length");
|
|
532
|
+
}
|
|
533
|
+
function decompressPublicKey(compressedPubkey) {
|
|
534
|
+
const x = compressedPubkey.slice(0, 64);
|
|
535
|
+
const y = compressedPubkey.slice(64);
|
|
536
|
+
return {
|
|
537
|
+
x: hexToDecimalString(x),
|
|
538
|
+
y: hexToDecimalString(y)
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function compressPublicKey(decompressedPubkey) {
|
|
542
|
+
const x = decompressedPubkey[0];
|
|
543
|
+
const y = decompressedPubkey[1];
|
|
544
|
+
const compressedPubkey = padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
|
|
545
|
+
return compressedPubkey;
|
|
546
|
+
}
|
|
519
547
|
|
|
520
548
|
// src/libs/query/operator.ts
|
|
521
549
|
var Operator = class {
|
|
@@ -3633,18 +3661,6 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
3633
3661
|
};
|
|
3634
3662
|
}
|
|
3635
3663
|
}
|
|
3636
|
-
function hexToDecimalString(hexString) {
|
|
3637
|
-
const decimalString = BigInt("0x" + hexString).toString(10);
|
|
3638
|
-
return decimalString;
|
|
3639
|
-
}
|
|
3640
|
-
function parsePubkey(publickKey) {
|
|
3641
|
-
const x = publickKey.slice(0, 64);
|
|
3642
|
-
const y = publickKey.slice(64);
|
|
3643
|
-
return {
|
|
3644
|
-
x: hexToDecimalString(x),
|
|
3645
|
-
y: hexToDecimalString(y)
|
|
3646
|
-
};
|
|
3647
|
-
}
|
|
3648
3664
|
|
|
3649
3665
|
// src/libs/contract/contract.ts
|
|
3650
3666
|
var Contract = class {
|
|
@@ -3733,7 +3749,7 @@ var Contract = class {
|
|
|
3733
3749
|
const end_time = (endVoting.getTime() * 10 ** 6).toString();
|
|
3734
3750
|
const [{ address }] = await signer.getAccounts();
|
|
3735
3751
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
3736
|
-
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
3752
|
+
const { x: operatorPubkeyX, y: operatorPubkeyY } = decompressPublicKey(operatorPubkey);
|
|
3737
3753
|
const {
|
|
3738
3754
|
parameters,
|
|
3739
3755
|
groth16ProcessVkey,
|
|
@@ -3799,7 +3815,7 @@ var Contract = class {
|
|
|
3799
3815
|
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
3800
3816
|
const [{ address }] = await signer.getAccounts();
|
|
3801
3817
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
3802
|
-
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
3818
|
+
const { x: operatorPubkeyX, y: operatorPubkeyY } = decompressPublicKey(operatorPubkey);
|
|
3803
3819
|
const {
|
|
3804
3820
|
parameters,
|
|
3805
3821
|
groth16ProcessVkey,
|
|
@@ -4138,7 +4154,11 @@ export {
|
|
|
4138
4154
|
Round,
|
|
4139
4155
|
Transaction,
|
|
4140
4156
|
circuits,
|
|
4157
|
+
compressPublicKey,
|
|
4158
|
+
decompressPublicKey,
|
|
4141
4159
|
getDefaultParams,
|
|
4160
|
+
hexToDecimalString,
|
|
4161
|
+
isValidAddress,
|
|
4142
4162
|
validator_operator_set
|
|
4143
4163
|
};
|
|
4144
4164
|
//# sourceMappingURL=index.mjs.map
|