This repository has been archived by the owner on Jan 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path3_verificationProcessCombined.ts
89 lines (83 loc) · 2.77 KB
/
3_verificationProcessCombined.ts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* eslint-disable no-console */
import Claimer from '../../../src/claim/Claimer'
import AttesterChain from '../../../src/attestation/Attester.chain'
import { IPresentationRequest } from '../../../src/types/Verification'
import Verifier from '../../../src/verification/Verifier'
import Credential from '../../../src/claim/Credential'
import connect from '../../../src/blockchainApiConnection/BlockchainApiConnection'
// runs a complete verification process on a credential
export async function verificationProcessCombinedChain({
claimer,
attesters,
credentials,
requestedAttributesArr,
reqUpdatedAfter,
reqNonRevocationProofArr,
}: {
claimer: Claimer
attesters: AttesterChain[]
credentials: Credential[]
requestedAttributesArr: string[][]
reqUpdatedAfter: Date[]
reqNonRevocationProofArr: boolean[]
}): Promise<{
verified: boolean
verifiedClaims: Array<Record<string, unknown>>
}> {
if (
attesters.length !== credentials.length ||
credentials.length !== requestedAttributesArr.length ||
requestedAttributesArr.length !== reqUpdatedAfter.length ||
reqUpdatedAfter.length !== reqNonRevocationProofArr.length ||
reqNonRevocationProofArr.length !== attesters.length
) {
throw new Error(
'Input array lengths do not match up in "verificationProcessCombinedChain"'
)
}
console.group()
const attesterPubKeys = attesters.map((attester) => attester.publicKey)
const blockchain = await connect()
const accumulators = await Promise.all(
attesters.map((attester) => {
return blockchain.getLatestAccumulator(attester.address)
})
)
// verifier requests presentation for each credential and combines request by calling `finalise`
// build combined requests
const requests: IPresentationRequest[] = requestedAttributesArr.map(
(requestedAttributes, idx) => ({
requestedAttributes,
reqNonRevocationProof: reqNonRevocationProofArr[idx],
reqUpdatedAfter: reqUpdatedAfter[idx],
})
)
// request combined presentation
const {
message: combinedPresentationReq,
session: combinedSession,
} = await Verifier.requestCombinedPresentation(requests)
// claimer builds combined presentation
const proof = await claimer.buildCombinedPresentation({
credentials,
combinedPresentationReq,
attesterPubKeys,
})
// verifier checks each claim and returns true if all claims could be verified
const {
verified,
claims: verifiedClaims,
} = await Verifier.verifyCombinedPresentation({
proof,
attesterPubKeys,
verifierSession: combinedSession,
latestAccumulators: accumulators,
})
console.log(`Claim could ${verified ? 'be verified' : 'not be verified'}`)
console.groupEnd()
return {
verified,
verifiedClaims,
}
}
export default verificationProcessCombinedChain