feat added Shamir Reocvery

This commit is contained in:
2023-08-15 13:13:57 -04:00
parent 3aa7c668af
commit eba1eb60ff
4 changed files with 74 additions and 36 deletions

73
package-lock.json generated
View File

@@ -18,6 +18,7 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-basic-auth": "^1.2.1",
"ffjavascript": "^0.2.60",
"helmet": "^7.0.0",
"mongodb": "^5.7.0",
"poseidon-lite": "^0.2.0",
@@ -3130,11 +3131,6 @@
"web-worker": "^1.2.0"
}
},
"node_modules/circom_runtime/node_modules/wasmbuilder": {
"version": "0.0.16",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.16.tgz",
"integrity": "sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA=="
},
"node_modules/circom_runtime/node_modules/wasmcurves": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.0.tgz",
@@ -4164,13 +4160,12 @@
}
},
"node_modules/ffjavascript": {
"version": "0.2.55",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.55.tgz",
"integrity": "sha512-8X0FCIPOWiK6DTWh3pnE3O6D6nIQsirStAXpWMzRDnoDX7SEnDX4I28aVhwjL7L35XS1vy2AU7zc0UCGYxdLjw==",
"version": "0.2.60",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.60.tgz",
"integrity": "sha512-T/9bnEL5xAZRDbQoEMf+pM9nrhK+C3JyZNmqiWub26EQorW7Jt+jR54gpqDhceA4Nj0YctPQwYnl8xa52/A26A==",
"dependencies": {
"big-integer": "^1.6.48",
"wasmbuilder": "^0.0.12",
"wasmcurves": "0.1.0",
"wasmbuilder": "0.0.16",
"wasmcurves": "0.2.2",
"web-worker": "^1.2.0"
}
},
@@ -6578,11 +6573,6 @@
"web-worker": "^1.2.0"
}
},
"node_modules/r1csfile/node_modules/wasmbuilder": {
"version": "0.0.16",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.16.tgz",
"integrity": "sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA=="
},
"node_modules/r1csfile/node_modules/wasmcurves": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.0.tgz",
@@ -6762,11 +6752,39 @@
"snarkjs": "^0.7.0"
}
},
"node_modules/rlnjs/node_modules/ffjavascript": {
"version": "0.2.55",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.55.tgz",
"integrity": "sha512-8X0FCIPOWiK6DTWh3pnE3O6D6nIQsirStAXpWMzRDnoDX7SEnDX4I28aVhwjL7L35XS1vy2AU7zc0UCGYxdLjw==",
"dependencies": {
"big-integer": "^1.6.48",
"wasmbuilder": "^0.0.12",
"wasmcurves": "0.1.0",
"web-worker": "^1.2.0"
}
},
"node_modules/rlnjs/node_modules/poseidon-lite": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/poseidon-lite/-/poseidon-lite-0.0.2.tgz",
"integrity": "sha512-bGdDPTOQkJbBjbtSEWc3gY+YhqlGTxGlZ8041F8TGGg5QyGGp1Cfs4b8AEnFFjHbkPg6WdWXUgEjU1GKOKWAPw=="
},
"node_modules/rlnjs/node_modules/wasmbuilder": {
"version": "0.0.12",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.12.tgz",
"integrity": "sha512-dTMpBgrnLOXrN58i2zakn2ScynsBhq9LfyQIsPz4CyxRF9k1GAORniuqn3xmE9NnI1l7g3iiVCkoB2Cl0/oG8w==",
"dependencies": {
"big-integer": "^1.6.48"
}
},
"node_modules/rlnjs/node_modules/wasmcurves": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.1.0.tgz",
"integrity": "sha512-kIlcgbVUAv2uQ6lGsepGz/m5V40+Z6rvTBkqCYn3Y2+OcXst+UaP4filJYLh/xDxjJl62FFjZZeAnpeli1Y5/Q==",
"dependencies": {
"big-integer": "^1.6.42",
"blakejs": "^1.1.0"
}
},
"node_modules/rollup": {
"version": "3.26.2",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-3.26.2.tgz",
@@ -7105,11 +7123,6 @@
"web-worker": "^1.2.0"
}
},
"node_modules/snarkjs/node_modules/wasmbuilder": {
"version": "0.0.16",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.16.tgz",
"integrity": "sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA=="
},
"node_modules/snarkjs/node_modules/wasmcurves": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.1.tgz",
@@ -7857,20 +7870,16 @@
}
},
"node_modules/wasmbuilder": {
"version": "0.0.12",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.12.tgz",
"integrity": "sha512-dTMpBgrnLOXrN58i2zakn2ScynsBhq9LfyQIsPz4CyxRF9k1GAORniuqn3xmE9NnI1l7g3iiVCkoB2Cl0/oG8w==",
"dependencies": {
"big-integer": "^1.6.48"
}
"version": "0.0.16",
"resolved": "https://registry.npmjs.org/wasmbuilder/-/wasmbuilder-0.0.16.tgz",
"integrity": "sha512-Qx3lEFqaVvp1cEYW7Bfi+ebRJrOiwz2Ieu7ZG2l7YyeSJIok/reEQCQCuicj/Y32ITIJuGIM9xZQppGx5LrQdA=="
},
"node_modules/wasmcurves": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.1.0.tgz",
"integrity": "sha512-kIlcgbVUAv2uQ6lGsepGz/m5V40+Z6rvTBkqCYn3Y2+OcXst+UaP4filJYLh/xDxjJl62FFjZZeAnpeli1Y5/Q==",
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.2.2.tgz",
"integrity": "sha512-JRY908NkmKjFl4ytnTu5ED6AwPD+8VJ9oc94kdq7h5bIwbj0L4TDJ69mG+2aLs2SoCmGfqIesMWTEJjtYsoQXQ==",
"dependencies": {
"big-integer": "^1.6.42",
"blakejs": "^1.1.0"
"wasmbuilder": "0.0.16"
}
},
"node_modules/web-worker": {

View File

@@ -32,6 +32,7 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-basic-auth": "^1.2.1",
"ffjavascript": "^0.2.60",
"helmet": "^7.0.0",
"mongodb": "^5.7.0",
"poseidon-lite": "^0.2.0",
@@ -64,4 +65,4 @@
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
}

View File

@@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { ZqField } from 'ffjavascript';
/*
This is the "Baby Jubjub" curve described here:
https://iden3-docs.readthedocs.io/en/latest/_downloads/33717d75ab84e11313cc0d8a090b636f/Baby-Jubjub.pdf
*/
const SNARK_FIELD_SIZE = BigInt(
'21888242871839275222246405745257275088548364400416034343698204186575808495617'
);
// Creates the finite field
const Fq = new ZqField(SNARK_FIELD_SIZE);
/**
* Recovers secret from two shares
* @param x1 signal hash of first message
* @param x2 signal hash of second message
* @param y1 yshare of first message
* @param y2 yshare of second message
* @returns identity secret
*/
export function shamirRecovery(x1: bigint, x2: bigint, y1: bigint, y2: bigint): bigint {
const slope = Fq.div(Fq.sub(y2, y1), Fq.sub(x2, x1));
const privateKey = Fq.sub(y1, Fq.mul(slope, x1));
return Fq.normalize(privateKey);
}

View File

@@ -25,9 +25,6 @@ async function verifyProof(msg: MessageI, room: RoomI, epochErrorRange = 5): Pro
return false;
}
// Check that the internal nullifier doesn't have collisions
// TODO! INTERNAL NULLIFIER (RLNjs cache)
// Check that the message hash is correct
if (msgHash !== msg.proof.snarkProof.publicSignals.x) {
console.warn(