```// //This is a private wrapper library that does all the zkstuff const zkp = new (require('../lib/zkproof')).ZKProof("Ecdh"); const ff = require('ffjavascript'); const blake = require('blake-hash'); const jsCrypt = require('@iden3/js-crypto'); function toHex(number, length = 32) { const str = number instanceof Buffer ? number.toString('hex') : BigInt(number).toString(16) return '0x' + str.padStart(length * 2, '0') } console.log(blake) const skBuff1 = jsCrypt.Hex.decodeString('0001020304050607080900010203040506070809000102030405060708090001'); const skBuff2 = jsCrypt.Hex.decodeString('0005020304050607080900010203040506070809000102030405060708090002'); const privateKey1 = new jsCrypt.PrivateKey(skBuff1); const privateKey2 = new jsCrypt.PrivateKey(skBuff2); const pubKey1 = privateKey1.public(); const pubKey2 = privateKey2.public(); const formatPrivKeyForBabyJub = (privKey) => { const sBuff = jsCrypt.Eddsa.pruneBuffer( blake('blake512').update(privKey.hex(), 'hex').digest() ) const s = ff.Scalar.fromRprLE(sBuff, 0, 32) return ff.Scalar.shr(s, 3) } (async() => { var result1 = await zkp.generateProof({ privKey: toHex(formatPrivKeyForBabyJub(privateKey1)), pubKey: pubKey2.p.map(a => toHex(a)) }); var result2 = await zkp.generateProof({ privKey: toHex(formatPrivKeyForBabyJub(privateKey2)), pubKey: pubKey1.p.map(a => toHex(a)) }); console.log(result1.publicSignals, result2.publicSignals); console.log(result1.publicSignals[0] == result2.publicSignals[0]) console.log(result1.publicSignals[1] == result2.publicSignals[1]) })() ``` The circom circuit: ```// pragma circom 2.0.0; include "../node_modules/circomlib/circuits/bitify.circom"; include "../node_modules/circomlib/circuits/escalarmulany.circom"; template Ecdh() { // Note: the private key needs to be hashed and pruned first signal input privKey; signal input pubKey[2]; signal output sharedKey[2]; component privBits = Num2Bits(253); privBits.in <== privKey; component mulFix = EscalarMulAny(253); mulFix.p[0] <== pubKey[0]; mulFix.p[1] <== pubKey[1]; for (var i = 0; i < 253; i++) { mulFix.e[i] <== privBits.out[i]; } sharedKey[0] <== mulFix.out[0]; sharedKey[1] <== mulFix.out[1]; } component main{public [pubKey]} = Ecdh();