Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add progress #80

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/helpers/createPasswordProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import createPasswordInput from 'helpers/createPasswordInput'
import generatePasswordProof from 'helpers/generatePasswordProof'

export default async function createPasswordProof(
params: CreatePasswordProofParams
params: CreatePasswordProofParams,
logger: (message: string) => void
) {
const input = await createPasswordInput(params)
const proof = await generatePasswordProof(input)
const proof = await generatePasswordProof(input, logger)

return proof
}
8 changes: 6 additions & 2 deletions src/helpers/generateAttestationProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import GeneratorError from 'helpers/GeneratorError'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const snarkjs: any

export default function generateAttestationProof(input: unknown) {
export default function generateAttestationProof(
input: unknown,
debug: (message: string) => void
) {
try {
return snarkjs.groth16.fullProve(
input,
'zk/AttestationChecker.wasm',
'zk/AttestationChecker_final.zkey'
'zk/AttestationChecker_final.zkey',
{ debug }
)
} catch (e) {
throw new GeneratorError('The verifier failed to validate the invite', {
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/generatePasswordProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import GeneratorError from 'helpers/GeneratorError'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const snarkjs: any

export default function generatePasswordProof(input: unknown) {
export default function generatePasswordProof(
input: unknown,
debug: (message: string) => void
) {
try {
return snarkjs.groth16.fullProve(
input,
'zk/PasswordChecker.wasm',
'zk/PasswordChecker_final.zkey'
'zk/PasswordChecker_final.zkey',
{ debug }
)
} catch (e) {
throw new GeneratorError(
Expand Down
36 changes: 36 additions & 0 deletions src/helpers/getProofProgress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const messages = [
'Reading Wtns',
'Reading Coeffs',
'Building ABC',
'QAP AB',
'QAP C',
'IFFT_A: fft 14 mix start',
'IFFT_A: fft 14 mix end',
'IFFT_A: fft 14 join',
'FFT_A: fft 14 mix start',
'FFT_A: fft 14 mix end',
'FFT_A: fft 14 join',
'IFFT_B: fft 14 mix start',
'IFFT_B: fft 14 mix end',
'IFFT_B: fft 14 join',
'FFT_B: fft 14 mix start',
'FFT_B: fft 14 mix end',
'FFT_B: fft 14 join',
'IFFT_C: fft 14 mix start',
'IFFT_C: fft 14 mix end',
'IFFT_C: fft 14 join',
'FFT_C: fft 14 mix start',
'FFT_C: fft 14 mix end',
'FFT_C: fft 14 join',
'Reading A Points',
'Reading B1 Points',
'Reading B2 Points',
'Reading C Points',
'Reading H Points',
]

export default function getProofProgress(log: string) {
const position = messages.findIndex((message) => log.startsWith(message))
if (position === -1) return null
return (position * 100) / messages.length
}
6 changes: 5 additions & 1 deletion src/helpers/onCreateAttestationProofMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ProofResultStatus from 'models/ProofResultStatus'
import createAttestationInput from 'helpers/createAttestationInput'
import generateAttestationProof from 'helpers/generateAttestationProof'
import isValidAttestationProofMessage from 'helpers/isValidAttestationProofMessage'
import onProofProgress from 'helpers/onProofProgress'
import postWebViewMessage from 'helpers/postWebViewMessage'

export default async function onCreateAttestationProofMessage(
Expand Down Expand Up @@ -37,7 +38,10 @@ export default async function onCreateAttestationProofMessage(
type: Messages.GetProofStatus,
})

const attestationProof = await generateAttestationProof(input)
const attestationProof = await generateAttestationProof(
input,
onProofProgress(message.id)
)

postWebViewMessage({
data: {
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/onCreatePasswordProofMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import Message from 'models/Message'
import Messages from 'models/Messages'
import createPasswordProof from 'helpers/createPasswordProof'
import isValidPasswordProofMessage from 'helpers/isValidPasswordProofMessage'
import onProofProgress from 'helpers/onProofProgress'
import postWebViewMessage from 'helpers/postWebViewMessage'

export default async function onPasswordProofMessage(message: Message) {
try {
if (!isValidPasswordProofMessage(message.params))
throw new GeneratorError('Invalid data for password proof!')

const data = await createPasswordProof(message.params)
const data = await createPasswordProof(
message.params,
onProofProgress(message.id)
)

postWebViewMessage({
data,
Expand Down
18 changes: 18 additions & 0 deletions src/helpers/onProofProgress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Messages from 'models/Messages'
import ProofResultStatus from 'models/ProofResultStatus'
import getProofProgress from 'helpers/getProofProgress'
import postWebViewMessage from 'helpers/postWebViewMessage'

export default function onProofProgress(id: string) {
return (info: string) => {
postWebViewMessage({
data: {
info,
percent: getProofProgress(info),
status: ProofResultStatus.ProofGeneration,
},
id,
type: Messages.GetProofStatus,
})
}
}