Skip to content

Commit b110d8a

Browse files
committed
chore: make prettier happy
1 parent dcc5b78 commit b110d8a

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,4 @@ contract PrivateTaxCalculation {
205205

206206
# References
207207

208-
https://github.com/jahali6128/paillier-solidity
208+
https://github.com/jahali6128/paillier-solidity

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
"bigint-conversion": "^2.4.3",
2525
"paillier-bigint": "^3.4.3"
2626
}
27-
}
27+
}

test/Paillier.ts

+59-59
Original file line numberDiff line numberDiff line change
@@ -5,81 +5,81 @@ import { expect } from "chai";
55

66
// Public key
77
interface PublicKey {
8-
value: string;
8+
value: string;
99
}
1010

1111
// Ciphertext
1212
interface Ciphertext {
13-
value: string;
13+
value: string;
1414
}
1515

1616
describe("Paillier", function () {
17-
it("should add 2 ciphertexts", async function () {
18-
const Paillier = await ethers.deployContract("Paillier");
17+
it("should add 2 ciphertexts", async function () {
18+
const Paillier = await ethers.deployContract("Paillier");
1919

20-
const { publicKey, privateKey } =
21-
await paillierBigint.generateRandomKeys(256);
22-
const a: bigint = BigInt(1);
23-
const b: bigint = BigInt(2);
24-
const enc_a: Ciphertext = {
25-
value: ethers.toBeHex(publicKey.encrypt(a)),
26-
};
27-
const enc_b: Ciphertext = {
28-
value: ethers.toBeHex(publicKey.encrypt(b)),
29-
};
20+
const { publicKey, privateKey } =
21+
await paillierBigint.generateRandomKeys(256);
22+
const a: bigint = BigInt(1);
23+
const b: bigint = BigInt(2);
24+
const enc_a: Ciphertext = {
25+
value: ethers.toBeHex(publicKey.encrypt(a)),
26+
};
27+
const enc_b: Ciphertext = {
28+
value: ethers.toBeHex(publicKey.encrypt(b)),
29+
};
3030

31-
// Public key
32-
const pub_n: PublicKey = {
33-
value: ethers.toBeHex(publicKey.n),
34-
};
31+
// Public key
32+
const pub_n: PublicKey = {
33+
value: ethers.toBeHex(publicKey.n),
34+
};
3535

36-
// bit length will differ to what has been stated in this script.
37-
// if using 256-bit key, bit_length will be 264 as "0x" prefix may have been factored in
38-
// Now lets deploy the contract and test the addition
39-
const enc_sum = await Paillier.add(enc_a, enc_b, pub_n);
40-
const enc_sum_int = bigIntConversion.hexToBigint(enc_sum[0]);
36+
// bit length will differ to what has been stated in this script.
37+
// if using 256-bit key, bit_length will be 264 as "0x" prefix may have been factored in
38+
// Now lets deploy the contract and test the addition
39+
const enc_sum = await Paillier.add(enc_a, enc_b, pub_n);
40+
const enc_sum_int = bigIntConversion.hexToBigint(enc_sum[0]);
4141

42-
// Conversion to int for convenience
43-
const dec_sum = Number(privateKey.decrypt(enc_sum_int));
44-
console.log("Decrypted Sum:", dec_sum);
42+
// Conversion to int for convenience
43+
const dec_sum = Number(privateKey.decrypt(enc_sum_int));
44+
console.log("Decrypted Sum:", dec_sum);
4545

46-
// We want dec_sum to equal 3
47-
expect(dec_sum).to.equal(3);
48-
});
46+
// We want dec_sum to equal 3
47+
expect(dec_sum).to.equal(3);
48+
});
4949

50-
it("should encrypt zero", async function () {
51-
const { publicKey, privateKey } =
52-
await paillierBigint.generateRandomKeys(256);
53-
const Paillier = await ethers.deployContract("Paillier");
54-
// Arbitary random number - 1000000
55-
const rand = ethers.toBeHex(Math.floor(Math.random() * 1000000));
50+
it("should encrypt zero", async function () {
51+
const { publicKey, privateKey } =
52+
await paillierBigint.generateRandomKeys(256);
53+
const Paillier = await ethers.deployContract("Paillier");
54+
// Arbitary random number - 1000000
55+
const rand = ethers.toBeHex(Math.floor(Math.random() * 1000000));
5656

57-
// Public key
58-
const pub_n = { value: ethers.toBeHex(publicKey.n) };
59-
const enc_zero = await Paillier.encryptZero(rand, pub_n);
60-
const enc_zero_int = bigIntConversion.hexToBigint(enc_zero[0]);
61-
const dec_zero = Number(privateKey.decrypt(enc_zero_int));
62-
expect(dec_zero).to.equal(0);
63-
});
57+
// Public key
58+
const pub_n = { value: ethers.toBeHex(publicKey.n) };
59+
const enc_zero = await Paillier.encryptZero(rand, pub_n);
60+
const enc_zero_int = bigIntConversion.hexToBigint(enc_zero[0]);
61+
const dec_zero = Number(privateKey.decrypt(enc_zero_int));
62+
expect(dec_zero).to.equal(0);
63+
});
6464

65-
it("should multiply encrypted value by a scalar", async function () {
66-
const { publicKey, privateKey } =
67-
await paillierBigint.generateRandomKeys(256);
68-
const [owner] = await ethers.getSigners();
69-
const Paillier = await ethers.deployContract("Paillier");
70-
const a: bigint = BigInt(2);
71-
const b: bigint = BigInt(5);
72-
const enc_a = { value: ethers.toBeHex(publicKey.encrypt(a)) };
65+
it("should multiply encrypted value by a scalar", async function () {
66+
const { publicKey, privateKey } =
67+
await paillierBigint.generateRandomKeys(256);
68+
const [owner] = await ethers.getSigners();
69+
const Paillier = await ethers.deployContract("Paillier");
70+
const a: bigint = BigInt(2);
71+
const b: bigint = BigInt(5);
72+
const enc_a = { value: ethers.toBeHex(publicKey.encrypt(a)) };
7373

74-
// Public key
75-
const pub_n = { value: ethers.toBeHex(publicKey.n) };
76-
const enc_scalar = await Paillier.mul(enc_a, b, pub_n);
74+
// Public key
75+
const pub_n = { value: ethers.toBeHex(publicKey.n) };
76+
const enc_scalar = await Paillier.mul(enc_a, b, pub_n);
7777

78-
// returns tuple so get first index
79-
const enc_scalar_int = bigIntConversion.hexToBigint(enc_scalar[0]);
78+
// returns tuple so get first index
79+
const enc_scalar_int = bigIntConversion.hexToBigint(enc_scalar[0]);
8080

81-
const dec_scalar = Number(privateKey.decrypt(enc_scalar_int));
82-
console.log("Decrypted Scalar:", dec_scalar);
83-
expect(dec_scalar).to.equal(10);
84-
});
81+
const dec_scalar = Number(privateKey.decrypt(enc_scalar_int));
82+
console.log("Decrypted Scalar:", dec_scalar);
83+
expect(dec_scalar).to.equal(10);
84+
});
8585
});

0 commit comments

Comments
 (0)