Skip to content

Commit

Permalink
add farcaster input generation
Browse files Browse the repository at this point in the history
  • Loading branch information
backmeupplz committed Sep 6, 2022
1 parent ef08a98 commit 46b3911
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 26 deletions.
2 changes: 1 addition & 1 deletion inputs/input-balance.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"messageAddress":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69],"pubKeyXAddress":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYAddress":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xAddress":"4677520192386416804963704338597519172003223772076188972505857784152427584708","R8yAddress":"14406396458018496497613935150682222860140520691729272542410460462597253078969","SAddress":"1315742568280436810592821099657746630251532633708787205158657373340001661022","MAddress":"13212816873189175504493684927098539753530031124875322194132256436282521565993","balance":"0x6b87c4e204970e6","threshold":"0x1","messageToken":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69,111,119,110,115,48,120,55,50,50,66,48,54,55,54,70,52,53,55,97,70,101,49,51,101,52,55,57,101,66,50,97,56,65,52,68,101,56,56,66,65,49,53,66,50,99,54,103],"pubKeyXToken":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYToken":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xToken":"10378672807010021053752775560521565036084291032757638995106228305977964368983","R8yToken":"6250041159475330228917392943246508180909119552731282039666974587477562476404","SToken":"1779058063762819078226233234985670173128914491032484240909675976881746011625","MToken":"12456080624582143469089645829478564458865643630206539977874934953790857334143","r2":"0x491148fd5626c39d7cb3c6bd60d04b0975656f026d38798ed8e6660c7215dd12","s2":"0x31032ba2c57a838e42024d9f2e381829313b22f676a4cd7ef831b2748943d24a"}
{"messageAddress":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69],"pubKeyXAddress":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYAddress":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xAddress":"4677520192386416804963704338597519172003223772076188972505857784152427584708","R8yAddress":"14406396458018496497613935150682222860140520691729272542410460462597253078969","SAddress":"1315742568280436810592821099657746630251532633708787205158657373340001661022","MAddress":"13212816873189175504493684927098539753530031124875322194132256436282521565993","balance":"0x6b87c4e204970e6","threshold":"0x1","messageToken":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69,111,119,110,115,48,120,55,50,50,66,48,54,55,54,70,52,53,55,97,70,101,49,51,101,52,55,57,101,66,50,97,56,65,52,68,101,56,56,66,65,49,53,66,50,99,54,103],"pubKeyXToken":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYToken":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xToken":"10378672807010021053752775560521565036084291032757638995106228305977964368983","R8yToken":"6250041159475330228917392943246508180909119552731282039666974587477562476404","SToken":"1779058063762819078226233234985670173128914491032484240909675976881746011625","MToken":"12456080624582143469089645829478564458865643630206539977874934953790857334143","r2":"0x73abe463b4d6863eae6b3755e59b98ea241b657f8aa32d71617acacbad85804e","s2":"0x384938d7e2c09a50f70fa1e3519c18bb3bb20874ec338b23a1ba67c00ef46cad"}
2 changes: 1 addition & 1 deletion inputs/input-email.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"message":[98,105,103,119,104,97,108,101,108,97,98,115,46,99,111,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"pubKeyX":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyY":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8x":"15298606526480864584355910095334162775602999800896032883635014999175499989355","R8y":"10740611045853572746142064534257693773300226817620379210695421925811006659780","S":"1951774407546037671953995624213462928595262386347037775045967177714957872170","M":"16326699391730603227158046697851865060679964588080600882713030572574027071981","r2":"0x58a448ec6c63bf472c542954acdc8fbde23cb62ee13f3e681d09999335ebd84f","s2":"0x55d8db6cf1cccf5bd4081ffb0648d996f8fae72283f206fb81d3a7fdb51a9df1"}
{"message":[98,105,103,119,104,97,108,101,108,97,98,115,46,99,111,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"pubKeyX":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyY":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8x":"15298606526480864584355910095334162775602999800896032883635014999175499989355","R8y":"10740611045853572746142064534257693773300226817620379210695421925811006659780","S":"1951774407546037671953995624213462928595262386347037775045967177714957872170","M":"16326699391730603227158046697851865060679964588080600882713030572574027071981","r2":"0xe6fdc83b10d32b68bc1fccaada2c1654923ce481fd7e04b7372c30acf89df0c2","s2":"0x12dd4f98869d96fcb1d5ce7a8f38a9f436d471de49e18111093db5e6dd70b10d"}
1 change: 1 addition & 0 deletions inputs/input-farcaster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"messageAddress":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69],"pubKeyXAddress":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYAddress":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xAddress":"4677520192386416804963704338597519172003223772076188972505857784152427584708","R8yAddress":"14406396458018496497613935150682222860140520691729272542410460462597253078969","SAddress":"1315742568280436810592821099657746630251532633708787205158657373340001661022","MAddress":"13212816873189175504493684927098539753530031124875322194132256436282521565993","messageFarcaster":[48,120,98,102,55,52,52,56,51,68,66,57,49,52,49,57,50,98,98,48,97,57,53,55,55,102,51,100,56,70,98,50,57,97,54,100,52,99,48,56,101,69,111,119,110,115,102,97,114,99,97,115,116,101,114],"pubKeyXFarcaster":"4877328357478890623967823018480272757589824716691017530689013849938564609461","pubKeyYFarcaster":"19319156333180214350448676801453385628019589905553133160599925263402925020311","R8xFarcaster":"6585510933468131423280002769115183546246417350915169184277788803792252015680","R8yFarcaster":"17134142612855692517379207539984176363394683611078444554948355207578416391573","SFarcaster":"1125705441173722017966028919668186813081388133481470488456740500715041671634","MFarcaster":"3395803646125877080015837861353188864795051572112645264453365620432846980601","r2":"0xca1dccbf44d82f27e384bb6d65ba4aece0c36431c4fc704cb6043163d71fe320","s2":"0x53036677f4780ca18a6726264e01782a43b40df3e5badabd175c0d09161fdb4d"}
Binary file added pot/FarcasterChecker_0000.zkey
Binary file not shown.
40 changes: 16 additions & 24 deletions scripts/generate-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,27 @@ import { writeFileSync } from 'fs'
import eddsaPrivateKeyBytes from '../utils/eddsaPrivateKeyBytes'
import getBalanceInputs from '../utils/getBalanceInputs'
import getEmailInputs from '../utils/getEmailInputs'

async function generateEmailInput() {
const inputs = await getEmailInputs()
// Writing inputs
writeFileSync(
resolve(cwd(), 'inputs/input-email.json'),
JSON.stringify(inputs),
'utf-8'
)
console.log('Generated input-email.json!')
}

async function generateBalanceInput() {
const inputs = await getBalanceInputs()
// Writing inputs
writeFileSync(
resolve(cwd(), 'inputs/input-balance.json'),
JSON.stringify(inputs),
'utf-8'
)
console.log('Generated input-balance.json!')
}
import getFarcasterInputs from '../utils/getFarcasterInputs'

void (async () => {
console.log('EdDSA private key', utils.hexlify(eddsaPrivateKeyBytes))
console.log(
'EdDSA public key',
BigNumber.from(await ed.getPublicKey(eddsaPrivateKeyBytes)).toString()
)
await generateEmailInput()
await generateBalanceInput()
const inputs = {
email: getEmailInputs,
balance: getBalanceInputs,
farcaster: getFarcasterInputs,
}
for (const [name, fn] of Object.entries(inputs)) {
const inputs = await fn()
// Writing inputs
writeFileSync(
resolve(cwd(), 'inputs', `input-${name}.json`),
JSON.stringify(inputs),
'utf-8'
)
console.log(`Generated input-${name}.json!`)
}
})()
32 changes: 32 additions & 0 deletions utils/getFarcasterInputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { buildBabyjub, buildMimc7 } from 'circomlibjs'
import { utils } from 'ethers'
import eddsaSign from './eddsaSign'
import getSignatureInputs from './getSignatureInputs'

async function inputsForMessage(message: string, suffix: string) {
const babyJub = await buildBabyjub()
const F = babyJub.F
const messageBytes = utils.toUtf8Bytes(message)
const mimc7 = await buildMimc7()
const M = mimc7.multiHash(messageBytes)
const { publicKey, signature } = await eddsaSign(M)
return {
[`message${suffix}`]: Array.from(messageBytes),
[`pubKeyX${suffix}`]: F.toObject(publicKey[0]).toString(),
[`pubKeyY${suffix}`]: F.toObject(publicKey[1]).toString(),
[`R8x${suffix}`]: F.toObject(signature.R8[0]).toString(),
[`R8y${suffix}`]: F.toObject(signature.R8[1]).toString(),
[`S${suffix}`]: signature.S.toString(),
[`M${suffix}`]: F.toObject(M).toString(),
}
}

export default async function (
ownerAddress = '0xbf74483DB914192bb0a9577f3d8Fb29a6d4c08eE'
) {
return {
...(await inputsForMessage(ownerAddress, 'Address')),
...(await inputsForMessage(`${ownerAddress}ownsfarcaster`, 'Farcaster')),
...(await getSignatureInputs()),
}
}

0 comments on commit 46b3911

Please sign in to comment.