This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample.js
41 lines (32 loc) · 1.59 KB
/
sample.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const axios = require('axios')
const zkp = require('./zkp')
const kycProviderUrl = 'http://localhost:8000'
const verifierUrl = 'http://localhost:8001'
const validCase = async () => {
console.log('===== VALID CASE =====')
console.log('Retrieving proving kit from kyc provider...\n')
const { data: { provingKit, signature, secret } } = await axios.get(`${kycProviderUrl}/proving-kit`)
console.log(`Proving kit details:\n${JSON.stringify(provingKit, null, 4)}\n`)
console.log('Generating proof...\n')
const proof = zkp.genIntegerProof(21, 18, secret)
console.log(`Proof generated: ${proof}\n`)
console.log('Verifying proof with store...\n')
const { data: verified } = await axios.get(`${verifierUrl}/verify?signature=${signature}&proof=${proof}&provingKit=${JSON.stringify(provingKit)}`)
console.log(`Valid proof: ${verified}\n`)
}
const invalidCase = async () => {
console.log('===== INVALID CASE =====')
console.log('Retrieving proving kit from kyc provider...\n')
const { data: { provingKit, signature, secret } } = await axios.get(`${kycProviderUrl}/proving-kit`)
console.log(`Proving kit details:\n${JSON.stringify(provingKit, null, 4)}\n`)
console.log('Generating proof...\n')
const proof = zkp.genIntegerProof(17, 18, secret)
console.log(`Proof generated: ${proof}\n`)
console.log('Verifying proof with store...\n')
const { data: verified } = await axios.get(`${verifierUrl}/verify?signature=${signature}&proof=${proof}&provingKit=${JSON.stringify(provingKit)}`)
console.log(`Valid proof: ${verified}\n`)
}
;(async () => {
await validCase()
await invalidCase()
})()