-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,6 @@ tlsn-verifier/target | |
tlsn-verifier/*.txt | ||
tlsn_verify_outputs/*.txt | ||
|
||
tlsp-verifier/node_modules | ||
|
||
certs/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## TLSP Verifier | ||
|
||
```bash | ||
tsc | ||
// Usage: node index.js <proofJsonPath> <plaintext> <ciphertext> | ||
node index.js ./proof.json 6f2c2073656375726520776f726c642122f214bbb5707a792158ca27f865ba3411e8cc5006498d3b0eb0de9a7f4d1e7cc3ab1b7cb396b1fca6a42551cffe56d1 077819785017d1cf8f56c111a631a1e4 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"pi_a":[ | ||
"18545182628801057987322180929860160194427518281467181052705937744550551744186", | ||
"19813946850066265863623155441962579533949982611349566587513412386854710426700", | ||
"1" | ||
], | ||
"pi_b":[ | ||
["1686061860494429426805613182976845039352849418982687778747463660363828673703","9290420138266975333901557822131144079131850509669186724218628267179553393357"], | ||
["5759199333909836908049087436279210080126869174666078216915174560107012869292","3968458531947138909139570330355313366169116368946167774660423668984013328784"], | ||
["1","0"] | ||
], | ||
"pi_c":[ | ||
"20004827253731281773736566563258359423845347003715728002244523839101154631967", | ||
"19439621413090542545966536518110875107983445155158333769982822708623038179416", | ||
"1" | ||
], | ||
"protocol":"groth16", | ||
"curve":"bn128" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { verifyProof, makeLocalSnarkJsZkOperator } from '@reclaimprotocol/circom-symmetric-crypto'; | ||
import * as fs from 'fs/promises'; | ||
|
||
function hexToBuffer(hexString: string): Buffer { | ||
// Ensure the hex string has an even length (required for valid byte conversion) | ||
if (hexString.length % 2 !== 0) { | ||
throw new Error("Invalid hex string: length must be even"); | ||
} | ||
|
||
// Create a Buffer from the hex string | ||
const buffer = Buffer.from(hexString, 'hex'); | ||
|
||
return buffer; | ||
} | ||
|
||
|
||
async function verify() { | ||
const argv = process.argv.slice(2); | ||
if (argv.length < 3) { | ||
console.error('Usage: node script.js <proofJsonPath> <plaintext> <ciphertext>'); | ||
process.exit(1); | ||
} | ||
|
||
const [proofJsonPath, plaintextHex, ciphertextHex] = argv; | ||
console.log(proofJsonPath) | ||
|
||
try { | ||
const proofJson = await fs.readFile(proofJsonPath, 'utf8'); | ||
console.log(proofJson); // Log the raw string to check its format | ||
|
||
const plaintext = hexToBuffer(plaintextHex) | ||
const ciphertext = hexToBuffer(ciphertextHex) | ||
|
||
const algorithm = 'chacha20'; | ||
const operator = await makeLocalSnarkJsZkOperator(algorithm); | ||
|
||
// Will assert the proof is valid; otherwise, it will throw an error | ||
await verifyProof({ | ||
proof: { | ||
proofJson, | ||
plaintext, | ||
algorithm | ||
}, | ||
// The public inputs to the circuit | ||
publicInput: { ciphertext }, | ||
operator | ||
}); | ||
|
||
console.log('proof verified'); | ||
} catch (error) { | ||
console.error('Error during verification:', error); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
verify().then(() => console.log('Verification complete')).catch(err => { | ||
console.error('Verification failed:', err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "tlsp-verifier", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"author": "0xsachink", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@reclaimprotocol/circom-symmetric-crypto": "git+https://gitlab.reclaimprotocol.org/Reclaim/zk-symmetric-crypto", | ||
"snarkjs": "^0.7.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.2" | ||
} | ||
} |
Oops, something went wrong.