Make anonymous vote possible! ทำให้การโหวตลับเกิดขึ้นได้จริง!
A major part of this project is the client-side implementation of kevinejohn's rsablind.js.
ส่วนสำคัญของโปรเจคนี้ เป็นการแปลงโค้ดจาก kevinejohn's rsablind.js เพื่อให้ทำงานได้บน client-side
- include the
forge.jsdependency on your page.
เพิ่ม forge.js ไปยังหน้าเว็บ
<script src="https://cdnjs.cloudflare.com/ajax/libs/forge/0.10.0/forge.min.js"></script>- include the
BlindSignature.json your page.
เพิ่ม BlindSignature.js ไปยังหน้าเว็บ
<script src="./path/to/BlindSignature.js"></script>- The Signer prepares a key pair, then gives the
publicKeyPemto the Author.
Signer เตรียม key pair จากนั้นส่ง publicKeyPem ให้กับ Author
const keypair = forge.pki.rsa.generateKeyPair(2048);
const publicKeyPem = forge.pki.publicKeyToPem(keypair.publicKey);
const privateKeyPem = forge.pki.privateKeyToPem(keypair.privateKey);- The Author prepares a blinded ballot and sends the
blindedMessageto the Signer.
Author ทำการสร้างบัตรเลือกตั้ง และปกปิดเนื้อหาในบัตรเลือกตั้ง จากนั้นส่ง blindedMessage ที่ได้ ให้กับ Signer
const Author = new BlindSignature.author(publicKeyPem);
const message = JSON.stringify({
wallet_address: '0x000000...00000', // Ethereum address, for example
vote: 1
});
const blindedMessage = Author.blind(message);
console.log(blindedMessage);- The Signer signs the blinded ballot and sends the
blindSignatureback to the Author.
Signer เซ็นรับรองบัตรเลือกตั้งที่ปกปิดอยู่ แล้วส่ง blindSignature กลับไปให้ Author
const Signer = new BlindSignature.signer(privateKeyPem);
const blindSignature = Signer.sign(blindedMessage);
console.log(blindSignature);- The Author unblinds the
blindSignatureto obtain thefinalSignatureand assembles theballot. The Author sends the ballot to Taller over the anonymous channel, for example, the Ethereum Network smart contract with an anonymous wallet.
Author เปิดเผย blindSignature ได้รับ finalSignature จากนั้นนำไปประกอบรวมกันเป็น ballot ซึ่งคือบัตรเลือกตั้งที่สมบูรณ์ จากนั้น Author ส่ง ballot ไปยังระบบนับคะแนนเลือกตั้งผ่านช่องทางนิรนาม เช่น ส่งไปยัง Smart Contract บน Ethereum Network ด้วยกระเป๋านิรนาม
const finalSignature = Author.unblind(blindSignature);
const ballot = {
body: message,
signature: finalSignature
};
console.log(ballot);The Author can also verify the signature using the public key (the public key has been registered in step #2).
Author ตรวจสอบความถูกต้องของลายเซ็นได้ ด้วย public key (public key ได้มาแล้วจากขั้นตอนที่ 2)
const verifyResult = Author.verify();
console.log(verifyResult);or หรือ
const signatureBigInt = new forge.jsbn.BigInteger(finalSignature.replace('0x', ''), 16);
const verifyResult = BlindSignature.verifyWithPublicKey(signatureBigInt, keypair.publicKey, message);
console.log(verifyResult);- The Signer verifies the signature by comparing it with the original message they have never seen, using the private key (the private key has been registered in step #3).
Signer ก็ตรวจสอบความถูกต้องของลายเซ็นได้เช่นกัน ด้วย private key แม้ว่าจะไม่เคยเห็นเนื้อหาฉบับจริงเลยก็ตาม (private key ได้มาแล้วจากขั้นตอนที่ 3)
const verifyResult2 = Signer.verify(ballot.signature, ballot.body);
console.log(verifyResult2);or หรือ
const signatureBigInt = new forge.jsbn.BigInteger(finalSignature.replace('0x', ''), 16);
const verifyResult2 = BlindSignature.verifyWithPrivateKey(signatureBigInt, keypair.privateKey, message);
console.log(verifyResult2);- If you are dealing with DomeCloud's e-election smart contract. you'll need the following variables:
ถ้านำไปใช้งานร่วมกับ DomeCloud's e-election smart contract ต้องใช้ตัวแปรเหล่านี้ด้วย
const N_factor = Signer.N_factor();
const ballotBody = BlindSignature.ascii2hex(message);
const ballotSignature = finalSignature; // from step #4 -> Author.unblind(blindSignature)
To make the vote anonymous, the voter (the Author) must create a new wallet every time and submit the ballot to the smart contract using EIP-2771. With EIP-2771, voters do not need to pay transaction gas, so there is no way to track down the origin of the gas and the voter's identity.
เพื่อให้การโหวตเป็นโหวตลับ ผู้โหวต (Author) ต้องสร้างกระเป๋าใหม่ทุกครั้งและส่งข้อมูลไปยัง smart contract ด้วยมาตรฐาน EIP-2771 ซึ่งเป็นเทคนิคการส่งธุรกรรมโดยไม่ต้องจ่ายค่า gas การไม่ต้องจ่าย gas ทำให้ไม่ต้องจัดเตรียม gas ซึ่งอาจเป็นช่องทางที่ใช้ติดตามตัวได้ ทำให้สูญเสียความนิรนาม
MIT

