identity commitment compatibility

This commit is contained in:
Andrija Novakovic
2021-10-10 11:45:48 +02:00
parent 299ded71d5
commit 4aec18497a
5 changed files with 20 additions and 275 deletions

View File

@@ -1,268 +0,0 @@
"use strict";
// // import { verifySignature } from 'libsemaphore';
// import * as crypto from 'crypto';
// import * as circomlib from 'circomlib';
// import * as ethers from 'ethers';
// const { groth16 } = require('snarkjs');
// import * as bigintConversion from 'bigint-conversion';
// const Tree = require('incrementalquintree/build/IncrementalQuinTree');
// const utils = require("ffjavascript").utils;
// const SNARK_FIELD_SIZE: BigInt = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
// type EddsaPrivateKey = Buffer;
// type EddsaPublicKey = bigint[];
// type CommitmentDTO = (identity: Identity) => bigint[];
// type Hasher = (inputs: bigint[]) => bigint;
// interface Identity {
// keypair: EddsaKeyPair,
// identityNullifier: bigint,
// identityTrapdoor: bigint,
// }
// interface EddsaKeyPair {
// pubKey: EddsaPublicKey,
// privKey: EddsaPrivateKey,
// }
// type IncrementalQuinTree = any;
// interface IProof {
// proof: any,
// publicSignals: any,
// }
// interface EdDSASignature {
// R8: BigInt[],
// S: BigInt,
// }
// interface IWitnessData {
// fullProof: IProof,
// root: BigInt,
// }
// // BEGIN HASHERS
// const poseidonHash = (inputs: bigint[]): bigint => {
// return circomlib.poseidon(inputs)
// }
// const pedersenHash = (inputs: Array<bigint>): bigint => {
// const p = circomlib.babyJub.unpackPoint(
// circomlib.pedersenHash.hash(
// Buffer.concat(
// inputs.map((x) => Buffer.from(utils.leInt2Buff(x, 32)))
// )
// )
// )
// return BigInt(p[0])
// }
// const hashers: {
// [name: string]: Hasher
// } = {
// 'poseidon': poseidonHash,
// 'pedersen': pedersenHash,
// };
// // END HASHERS
// const toOrdinaryCommitment = (identity: Identity): bigint[] => {
// return [
// circomlib.babyJub.mulPointEscalar(identity.keypair.pubKey, 8)[0],
// identity.identityNullifier,
// identity.identityTrapdoor,
// ]
// }
// const toFastSemaphoreCommitment = (identity: Identity): bigint[] => {
// return [
// identity.identityNullifier,
// identity.identityTrapdoor
// ]
// }
// const commitmentDtos: {
// [name: string]: CommitmentDTO
// } = {
// 'ordinary': toOrdinaryCommitment,
// 'fast': toFastSemaphoreCommitment
// }
// //BEGIN IDENTITY
// const genRandomBuffer = (numBytes: number = 32): Buffer => {
// return crypto.randomBytes(numBytes)
// }
// const genPubKey = (privKey: EddsaPrivateKey): EddsaPublicKey => {
// return circomlib.eddsa.prv2pub(privKey)
// }
// const genEddsaKeyPair = (privKey: Buffer = genRandomBuffer()): EddsaKeyPair => {
// const pubKey = genPubKey(privKey)
// return { pubKey, privKey }
// }
// const genIdentity = (
// privKey: Buffer = genRandomBuffer(32),
// ): Identity => {
// return {
// keypair: genEddsaKeyPair(privKey),
// identityNullifier: bigintConversion.bufToBigint(genRandomBuffer(31)),
// identityTrapdoor: bigintConversion.bufToBigint(genRandomBuffer(31)),
// }
// }
// const serialiseIdentity = (
// identity: Identity,
// ): string => {
// const data = [
// identity.keypair.privKey.toString('hex'),
// identity.identityNullifier.toString(16),
// identity.identityTrapdoor.toString(16),
// ]
// return JSON.stringify(data)
// }
// const unSerialiseIdentity = (serialisedIdentity: string): Identity => {
// const data = JSON.parse(serialisedIdentity)
// return {
// keypair: genEddsaKeyPair(Buffer.from(data[0], 'hex')),
// identityNullifier: bigintConversion.hexToBigint(data[1]),
// identityTrapdoor: bigintConversion.hexToBigint(data[2]),
// }
// }
// const genIdentityCommitment = (identity: Identity, hasher: string, type: string): BigInt => {
// const hash: Hasher = hashers[hasher];
// if (!hash) throw new Error(`${hasher} hasher function not supported, did you mean pedersen or poseidon`);
// const dto: CommitmentDTO = commitmentDtos[type];
// if (!dto) throw new Error(`${type} of semaphore identity commitment not supported, did you mean ordinary or fast`)
// const data: bigint[] = dto(identity);
// return hash(data);
// }
// //END IDENTITY
// /*
// * Each external nullifier must be at most 29 bytes large. This function
// * keccak-256-hashes a given `plaintext`, takes the last 29 bytes, and pads it
// * (from the start) with 0s, and returns the resulting hex string.
// * @param plaintext The plaintext to hash
// * @return plaintext The 0-padded 29-byte external nullifier
// */
// const genExternalNullifier = (plaintext: string): string => {
// const _cutOrExpandHexToBytes = (hexStr: string, bytes: number): string => {
// const len = bytes * 2
// const h = hexStr.slice(2, len + 2)
// return '0x' + h.padStart(len, '0')
// }
// const hashed = ethers.utils.solidityKeccak256(['string'], [plaintext])
// return _cutOrExpandHexToBytes(
// '0x' + hashed.slice(8),
// 32,
// )
// }
// const genSignalHash = (signal: string): BigInt => {
// const converted = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(signal));
// return BigInt(ethers.utils.solidityKeccak256(['bytes'], [converted])) >> BigInt(8);
// }
// const genMsg = (externalNullifier: string, signalHash: BigInt): string => {
// return circomlib.mimcsponge.multiHash([
// externalNullifier,
// signalHash,
// ]);
// }
// const genNullifierHash = (externalNullifier: string | bigint, identityNullifier: string | bigint, nLevels: number): BigInt => {
// return circomlib.poseidon([BigInt(externalNullifier), BigInt(identityNullifier), BigInt(nLevels)]);
// }
// const genProof_fastSemaphore = async (identity: Identity, signalHash: BigInt,
// identityCommitments: Array<BigInt>, externalNullifier: string, depth: number, zeroValue: BigInt,
// leavesPerNode: number, wasmFilePath: string, finalZkeyPath: string): Promise<IWitnessData> => {
// const tree: IncrementalQuinTree = new Tree.IncrementalQuinTree(depth, zeroValue, leavesPerNode, poseidonHash);
// const identityCommitment: BigInt = genIdentityCommitment(identity, 'poseidon', 'fast');
// const leafIndex = identityCommitments.indexOf(identityCommitment);
// for(const identityCommitment of identityCommitments) {
// tree.insert(identityCommitment);
// }
// const proof = tree.genMerklePath(leafIndex);
// const grothInput: any = {
// identity_pk: identity.keypair.pubKey,
// identity_nullifier: identity.identityNullifier,
// identity_trapdoor: identity.identityTrapdoor,
// identity_path_index: proof.indices,
// path_elements: proof.pathElements,
// external_nullifier: externalNullifier,
// signal_hash: signalHash,
// }
// const fullProof: IProof = await groth16.fullProve(grothInput, wasmFilePath, finalZkeyPath);
// const root: BigInt = tree.root;
// return {
// fullProof,
// root
// }
// }
// const genProof = async (identity: Identity, signature: EdDSASignature, signalHash: BigInt,
// identityCommitments: Array<BigInt>, externalNullifier: string, depth: number, zeroValue: BigInt,
// leavesPerNode: number, wasmFilePath: string, finalZkeyPath: string): Promise<IWitnessData> => {
// const tree: IncrementalQuinTree = new Tree.IncrementalQuinTree(depth, zeroValue, leavesPerNode, poseidonHash);
// const identityCommitment: BigInt = genIdentityCommitment(identity, 'poseidon', 'ordinary');
// const leafIndex = identityCommitments.indexOf(identityCommitment);
// for(const identityCommitment of identityCommitments) {
// tree.insert(identityCommitment);
// }
// const proof = tree.genMerklePath(leafIndex);
// const grothInput: any = {
// identity_pk: identity.keypair.pubKey,
// identity_nullifier: identity.identityNullifier,
// identity_trapdoor: identity.identityTrapdoor,
// fake_zero: 0,
// auth_sig_s: signature.S,
// identity_path_index: proof.indices,
// path_elements: proof.pathElements,
// auth_sig_r: signature.R8,
// signal_hash: signalHash,
// external_nullifier: externalNullifier,
// }
// const fullProof: IProof = await groth16.fullProve(grothInput, wasmFilePath, finalZkeyPath);
// const root: BigInt = tree.root;
// return {
// fullProof,
// root
// }
// }
// const packToSolidityProof = (fullProof: IProof) => {
// const { proof, publicSignals } = fullProof;
// return {
// a: proof.pi_a.slice(0, 2),
// b: proof.pi_b
// .map((x:any) => x.reverse())
// .slice(0, 2),
// c: proof.pi_c.slice(0, 2),
// inputs: publicSignals.map((x:any) => {
// x = BigInt(x);
// return x.mod(SNARK_FIELD_SIZE).toString()
// })
// };
// }
// const verifyProof = (vKey: string, fullProof: IProof): Promise<boolean> => {
// const { proof, publicSignals } = fullProof;
// return groth16.verify(vKey, publicSignals, proof)
// }
// const createTree = (depth: number, zeroValue: number | BigInt, leavesPerNode: number): IncrementalQuinTree => {
// return new Tree.IncrementalQuinTree(depth, zeroValue, leavesPerNode, poseidonHash);
// }
// // SIGNATURE
// const signMsg = (
// privKey: EddsaPrivateKey,
// msg: bigint | string,
// ): EdDSASignature => {
// return circomlib.eddsa.signMiMCSponge(privKey, msg)
// }
// const verifySignature = (
// msg: bigint,
// signature: EdDSASignature,
// pubKey: EddsaPublicKey,
// ): boolean => {
// return circomlib.eddsa.verifyMiMCSponge(msg, signature, pubKey)
// }
// export {
// Identity,
// IncrementalQuinTree,
// EdDSASignature,
// IProof,
// IWitnessData,
// signMsg,
// genExternalNullifier,
// genIdentity,
// genIdentityCommitment,
// verifySignature,
// genSignalHash,
// genNullifierHash,
// genMsg,
// genProof,
// genProof_fastSemaphore,
// packToSolidityProof,
// verifyProof,
// createTree,
// serialiseIdentity,
// unSerialiseIdentity
// }
//# sourceMappingURL=backup-with-no-classes.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"backup-with-no-classes.js","sourceRoot":"","sources":["../src/backup-with-no-classes.ts"],"names":[],"mappings":";AAAA,qDAAqD;AACrD,oCAAoC;AACpC,0CAA0C;AAC1C,oCAAoC;AACpC,0CAA0C;AAC1C,yDAAyD;AACzD,yEAAyE;AACzE,+CAA+C;AAE/C,4HAA4H;AAE5H,iCAAiC;AACjC,kCAAkC;AAElC,yDAAyD;AACzD,8CAA8C;AAE9C,uBAAuB;AACvB,6BAA6B;AAC7B,iCAAiC;AACjC,gCAAgC;AAChC,IAAI;AAEJ,2BAA2B;AAC3B,8BAA8B;AAC9B,gCAAgC;AAChC,IAAI;AAEJ,kCAAkC;AAElC,qBAAqB;AACrB,mBAAmB;AACnB,0BAA0B;AAC1B,IAAI;AAEJ,6BAA6B;AAC7B,oBAAoB;AACpB,iBAAiB;AACjB,IAAI;AAEJ,2BAA2B;AAC3B,0BAA0B;AAC1B,oBAAoB;AACpB,IAAI;AAEJ,mBAAmB;AAEnB,uDAAuD;AACvD,wCAAwC;AACxC,IAAI;AAEJ,4DAA4D;AAC5D,+CAA+C;AAC/C,uCAAuC;AACvC,6BAA6B;AAC7B,0EAA0E;AAC1E,gBAAgB;AAChB,YAAY;AACZ,QAAQ;AACR,0BAA0B;AAC1B,IAAI;AAEJ,mBAAmB;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AC/E,kDAAkD;AAClD,wDAAwD;AACxD,IAAI;AAEJ,kHAAkH;AAClH,0FAA0F;AAC1F,IAAI;AAEJ,eAAe;AACf,oBAAoB;AACpB,gCAAgC;AAChC,4BAA4B;AAC5B,yBAAyB;AAEzB,0DAA0D;AAC1D,IAAI;AAEJ,4BAA4B;AAC5B,mBAAmB;AACnB,iCAAiC;AACjC,8BAA8B;AAC9B,kBAAkB;AAElB,sEAAsE;AACtE,IAAI;AAEJ,WAAW;AACX,gBAAgB;AAChB,2BAA2B;AAC3B,sBAAsB;AACtB,cAAc;AACd,oBAAoB;AACpB,eAAe;AACf,4BAA4B;AAC5B,mBAAmB;AACnB,6BAA6B;AAC7B,uBAAuB;AACvB,qBAAqB;AACrB,wBAAwB;AACxB,cAAc;AACd,gBAAgB;AAChB,8BAA8B;AAC9B,2BAA2B;AAC3B,mBAAmB;AACnB,kBAAkB;AAClB,yBAAyB;AACzB,0BAA0B;AAC1B,IAAI"}

11
dist/fast.js vendored
View File

@@ -60,11 +60,17 @@ var FastSemaphore = /** @class */ (function (_super) {
function FastSemaphore() {
return _super !== null && _super.apply(this, arguments) || this;
}
FastSemaphore.prototype.genSecret = function (identity) {
if (!this.commitmentHasher)
throw new Error('Hasher not set');
var secret = [identity.identityNullifier, identity.identityTrapdoor];
return this.commitmentHasher(secret);
};
FastSemaphore.prototype.genIdentityCommitment = function (identity) {
if (!this.commitmentHasher)
throw new Error('Hasher not set');
var data = [identity.identityNullifier, identity.identityTrapdoor];
return this.commitmentHasher(data);
var secret = [this.genSecret(identity)];
return this.commitmentHasher(secret);
};
FastSemaphore.prototype.genProofFromIdentityCommitments = function (identity, externalNullifier, signal, wasmFilePath, finalZkeyPath, identityCommitments, depth, zeroValue, leavesPerNode, shouldHash) {
if (shouldHash === void 0) { shouldHash = true; }
@@ -96,6 +102,7 @@ var FastSemaphore = /** @class */ (function (_super) {
};
//sometimes identityCommitments array can be to big so we must generate it on server and just use it on frontend
FastSemaphore.prototype.genProofFromBuiltTree = function (identity, merkleProof, externalNullifier, signal, wasmFilePath, finalZkeyPath, shouldHash) {
if (shouldHash === void 0) { shouldHash = true; }
return __awaiter(this, void 0, void 0, function () {
var grothInput;
return __generator(this, function (_a) {

2
dist/fast.js.map vendored
View File

@@ -1 +1 @@
{"version":3,"file":"fast.js","sourceRoot":"","sources":["../src/fast.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAQ,IAAA,OAAO,GAAK,OAAO,CAAC,SAAS,CAAC,QAAvB,CAAwB;AACvC,+BAAmC;AACnC,mCAAwC;AAExC,IAAM,IAAI,GAAG,OAAO,CAAC,+CAA+C,CAAC,CAAC;AAEtE;IAA4B,iCAAa;IAAzC;;IAqDA,CAAC;IApDG,6CAAqB,GAArB,UAAsB,QAAkB;QACpC,IAAG,CAAC,IAAI,CAAC,gBAAgB;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC7D,IAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,iBAAiB,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAEK,uDAA+B,GAArC,UAAsC,QAAkB,EACpD,iBAAkC,EAClC,MAAc,EACd,YAAoB,EACpB,aAAqB,EACrB,mBAAkC,EAClC,KAAa,EACb,SAAiB,EACjB,aAAqB,EACrB,UAA0B;QAA1B,2BAAA,EAAA,iBAA0B;;;;;;wBAGpB,IAAI,GAAwB,IAAI,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,qBAAY,CAAC,CAAC;wBACxG,kBAAkB,GAAW,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;wBAClE,SAAS,GAAG,mBAAmB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;wBAClE,IAAG,SAAS,KAAK,CAA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17 @@ import { Identity, IncrementalQuinTree, IProof, IWitnessData } from './types';
const Tree = require('incrementalquintree/build/IncrementalQuinTree');
class FastSemaphore extends BaseSemaphore {
genSecret(identity: Identity): bigint {
if(!this.commitmentHasher) throw new Error('Hasher not set');
const secret = [identity.identityNullifier, identity.identityTrapdoor];
return this.commitmentHasher(secret);
}
genIdentityCommitment(identity: Identity): bigint {
if(!this.commitmentHasher) throw new Error('Hasher not set');
const data = [identity.identityNullifier, identity.identityTrapdoor];
return this.commitmentHasher(data);
const secret = [this.genSecret(identity)];
return this.commitmentHasher(secret);
}
async genProofFromIdentityCommitments(identity: Identity,
@@ -43,7 +50,7 @@ class FastSemaphore extends BaseSemaphore {
//sometimes identityCommitments array can be to big so we must generate it on server and just use it on frontend
async genProofFromBuiltTree(identity: Identity, merkleProof: any, externalNullifier: string | bigint, signal: string,
wasmFilePath: string, finalZkeyPath: string, shouldHash: boolean): Promise<IProof> {
wasmFilePath: string, finalZkeyPath: string, shouldHash: boolean = true): Promise<IProof> {
const grothInput: any = {
identity_nullifier: identity.identityNullifier,