-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add frame voting support to SDK #354
Comments
The way we create census keys has changed to include the Farcaster ID (FID). Here is the Go reference implementation func NewFarcasterVoterID(publicKey []byte, fid uint64) []byte {
fidBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(fidBytes, fid)
hashedPubKey := keccack(append(publicKey, fidBytes...))
return hashedPubKey[:20]
} And here the proposed implementation made by chatGPT import { keccak256 } from 'js-sha3';
/**
* Generate a Farcaster Voter ID based on the public key and fid.
*
* @param {Uint8Array} publicKey - The public key as a byte array.
* @param {number} fid - The fid as a number.
* @returns {Uint8Array} - The first 20 bytes of the keccak256 hash of the combined input.
*/
function newFarcasterVoterID(publicKey: Uint8Array, fid: number): Uint8Array {
// Create an 8-byte array to hold the little-endian representation of fid
const fidBytes = new Uint8Array(8);
// Convert fid to a little-endian byte array
for (let i = 0; i < 8; i++) {
fidBytes[i] = fid & 0xff; // Get the least significant byte of fid
fid = fid >> 8; // Shift fid right by 8 bits to process the next byte
}
// Create a new array to hold the combined publicKey and fidBytes
const combined = new Uint8Array(publicKey.length + fidBytes.length);
// Copy publicKey into the combined array
combined.set(publicKey);
// Copy fidBytes into the combined array, starting after the publicKey
combined.set(fidBytes, publicKey.length);
// Hash the combined array using keccak256 and convert the result to an ArrayBuffer
const hashedPubKey = keccak256.arrayBuffer(combined);
// Return the first 20 bytes of the hashed public key
return new Uint8Array(hashedPubKey).slice(0, 20);
} Here some test data
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New protobuf models
There is a new protobuf Proof model:
signedFrameMessageBody
This is a byte buffer that comes from the farcaster frame Specification
When a user interacts with a Frame backend, the backend receives the following JSON object:
The messageBytes is signed by the user publicKey. So in the Vochain we can extract it and check the publicKey is on the census.
censusProof
This is a standard OFF_CHAIN_TREE_WEIGHTED arbo based census proof (the same we use for standard voting). This proof is used to verify the pubKey extracted from the farcaster message is actually on the census.
publicKey
This is the publicKey extracted from the farcaster message, to facilitate the Vochain vote verification
The Arbo census
This is a standard census, but since the publicKeys of Farcaster are not Ethereum addresses but ed25519 public keys, we introduce a way to create farcaster addresses, this is:
keccack256(publicKey)[:20]
.So the census3 or other census based services need to implement these kind of addresses. Usually a pure farcaster census would be then:
Restrictions
Expected implementation on the SDK
The SDK could just facilitate create farcaster elections and help build and send farcaster votes. Meaning that we might skip the farcaster frame specific details, such as the Message Frame JSON or the Farcaster Protobuf model.
There are many libraries around that allow deserialize the farcaster message and extract the public key, we can just ask the user of the SDK to introduce such data.
The SDK should allow the user to create farcaster based elections (specifying the census) #359
The SDK should allow creating a vote given:
Then the SDK would transform the button index into a valid vote package (i.e
[1]
for button=1)Create the vote transaction and send it to the Vochain.
Testing
For the tests, we can use hardcoded examples for publicKeys and signedMessages as the ones provided here https://github.com/vocdoni/vocdoni-node/blob/main/test/farcaster_test.go#L291
The text was updated successfully, but these errors were encountered: