This repository was 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
Expand file tree
/
Copy pathexampleCombined.ts
More file actions
123 lines (109 loc) · 4.12 KB
/
Copy pathexampleCombined.ts
File metadata and controls
123 lines (109 loc) · 4.12 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* eslint-disable no-console */
import { testEnv1, testEnv2, mnemonic } from './exampleConfig'
import actorProcess from './offchain/1_actorProcess'
import issuanceProcess from './offchain/2_issuanceProcess'
import verificationProcessCombined from './offchain/3_verificationProcessCombined'
import Attester from '../../src/attestation/Attester'
import {
AttesterPublicKey,
AttesterPrivateKey,
} from '../../src/types/Attestation'
import teardown from './offchain/4_teardown'
const {
pubKey: pubKey1,
privKey: privKey1,
disclosedAttributes: disclosedAttributes1,
claim: claim1,
} = testEnv1
const {
pubKey: pubKey2,
privKey: privKey2,
claim: claim2,
disclosedAttributes: disclosedAttributes2,
} = testEnv2
// Do all processes from attestation, to possibly revocation and final verification
async function completeProcessCombined(
expectedVerificationOutcome: boolean,
doRevocation = false,
reqUpdatesAfter: [Date?, Date?]
): Promise<boolean> {
// create claimer and both attester entities
let {
// eslint-disable-next-line prefer-const
claimer,
// eslint-disable-next-line prefer-const
attester: attester1,
accumulator: accumulator1,
} = await actorProcess({
claimerMnemonic: mnemonic,
claimerMnemonicPw: 'password',
attesterPubKey: pubKey1,
attesterPrivKey: privKey1,
})
const attester2 = new Attester(
new AttesterPublicKey(pubKey2),
new AttesterPrivateKey(privKey2)
)
const accumulator2 = await attester2.createAccumulator()
// issue both credential
const { credential: credential1, witness: witness1 } = await issuanceProcess({
attester: attester1,
claimer,
accumulator: accumulator1,
claim: claim1,
})
const { credential: credential2 } = await issuanceProcess({
attester: attester2,
claimer,
accumulator: accumulator2,
claim: claim2,
})
// (optionally) revoke credentials, could revoke any or both to fail verification process
if (doRevocation) {
console.log('revoke attestation')
accumulator1 = await attester1.revokeAttestation({
accumulator: accumulator1,
witnesses: [witness1],
})
}
// verify credential with revocation check
const { verified } = await verificationProcessCombined({
claimer,
attesters: [attester1, attester2],
credentials: [credential1, credential2],
requestedAttributesArr: [disclosedAttributes1, disclosedAttributes2],
reqUpdatesAfter, // requires that witnesses are updates after specified date or using the latests available accumulator
accumulators: [accumulator1, accumulator2],
})
// check outcome
const achievedExpectedOutcome = expectedVerificationOutcome === verified
console.groupEnd()
console.log(`Expected outcome achieved? ${achievedExpectedOutcome}`)
return achievedExpectedOutcome
}
// all calls of completeProcessCombined should return true
async function completeProcessCombinedExamples(): Promise<void> {
// we accept every accumulator when requiring past in reqUpdatedAfter
const past = new Date()
// we only accept the newest accumulator
const future = new Date()
future.setDate(past.getDate() + 100)
// store outcomes here for CI check
const outcomes: boolean[] = []
// without credential revocation
outcomes.push(
await completeProcessCombined(true, false, [undefined, undefined])
)
// without credential revocation but required dates in future => should verify
outcomes.push(await completeProcessCombined(true, false, [future, undefined]))
outcomes.push(await completeProcessCombined(true, false, [undefined, future]))
// with revocation of 2nd credential and required date in future => should not verify
outcomes.push(await completeProcessCombined(false, true, [future, future]))
// with revocation of 2nd credential but required date in past => should verify
outcomes.push(await completeProcessCombined(true, true, [past, past]))
// with revocation (2nd) but revocation not required in verification
outcomes.push(await completeProcessCombined(true, true, [undefined, past]))
// check whether outcome is true fall our instances and close wasm
return teardown('offchain', outcomes)
}
completeProcessCombinedExamples()