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 pathexampleSingle.ts
More file actions
88 lines (74 loc) · 2.9 KB
/
Copy pathexampleSingle.ts
File metadata and controls
88 lines (74 loc) · 2.9 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
/* eslint-disable no-console */
import { testEnv1, mnemonic } from './exampleConfig'
import actorProcess from './offchain/1_actorProcess'
import issuanceProcess from './offchain/2_issuanceProcess'
import verificationProcessSingle from './offchain/3_verificationProcessSingle'
import teardown from './offchain/4_teardown'
const { pubKey, privKey, disclosedAttributes, claim } = testEnv1
// all processes from attestation, to possibly revocation and final verification
async function completeProcessSingle(
expectedVerificationOutcome: boolean,
doRevocation = false,
reqUpdatedAfter?: Date
): Promise<boolean> {
console.group()
// create claimer and attester entities
// eslint-disable-next-line prefer-const
let { claimer, attester, accumulator } = await actorProcess({
claimerMnemonic: mnemonic,
claimerMnemonicPw: 'password',
attesterPubKey: pubKey,
attesterPrivKey: privKey,
})
// issue credential
const { credential, witness } = await issuanceProcess({
attester,
claimer,
accumulator,
claim,
})
// (optionally) revoke credentials
if (doRevocation) {
accumulator = await attester.revokeAttestation({
accumulator,
witnesses: [witness],
})
}
// verify credential with revocation check
const { verified } = await verificationProcessSingle({
claimer,
attester,
credential,
requestedAttributes: disclosedAttributes,
reqUpdatedAfter, // require that the witness is not older than the provided date or updated to the latest accumulator
accumulator,
})
// check outcome
const achievedExpectedOutcome = expectedVerificationOutcome === verified
console.groupEnd()
console.log(`Expected outcome achieved? ${achievedExpectedOutcome}`)
return achievedExpectedOutcome
}
// all calls of completeProcessSingle should return true
async function completeProcessSingleExamples(): 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 completeProcessSingle(true, false, undefined))
// without revocation but required dates in future => should verify
outcomes.push(await completeProcessSingle(true, false, future))
// with revocation and required date in future => should not verify
outcomes.push(await completeProcessSingle(false, true, future))
// with revocation but required date in past => should verify
outcomes.push(await completeProcessSingle(true, true, past))
// with revocation but revocation not required in verification
outcomes.push(await completeProcessSingle(true, true, undefined))
// check whether outcome is true fall our instances and close wasm
return teardown('offchain', outcomes)
}
completeProcessSingleExamples()