-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate-revocable-credential.ts
More file actions
65 lines (56 loc) · 2.08 KB
/
create-revocable-credential.ts
File metadata and controls
65 lines (56 loc) · 2.08 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
import { createWallet } from '@affinidi/wallet-node-sdk'
import { Affinity } from '@affinidi/common'
// @ts-ignore
import platformCryptographyTools from '@affinidi/wallet-node-sdk/dist/PlatformCryptographyTools'
// @ts-ignore
const walletFactory = createWallet('AffinityCore')
const main = async () => {
const accessApiKey = '<key>'
const options = {
env: 'prod' as 'dev' | 'staging' | 'prod',
accessApiKey
}
const password = 'DemoP@ssw0rd!!'
const walletIssuer = await walletFactory.createWallet(options, password)
const walletHolder = await walletFactory.createWallet(options, password)
const id = `claimId:${(Math.random() + 1).toString(36).substring(2)}`
// https://ui.schema.affinidi.com/schemas/ContentLikeV1-0
const jsonSchema = 'https://schema.affinidi.com/ContentLikeV1-0.json'
const jsonContext = 'https://schema.affinidi.com/ContentLikeV1-0.jsonld'
const unsignedVC = {
'@context': ['https://www.w3.org/2018/credentials/v1', jsonContext],
id,
type: ['VerifiableCredential', 'ContentLike'],
holder: {
id: walletHolder.did
},
credentialSubject: {
data: {
'@type': ['VerifiableCredential', 'ContentLike'],
url: 'https://www.youtube.com/watch?v=owbkzvLhblk',
date: new Date().toISOString(),
like: true,
score: 10
},
},
credentialSchema: {
id: jsonSchema,
type: 'JsonSchemaValidator2018',
},
issuanceDate: new Date().toISOString(),
expirationDate: '2065-09-10T00:00:00.000Z',
}
const rvc = await walletIssuer.buildRevocationListStatus(unsignedVC)
const signedRevocableVC = await walletIssuer.signUnsignedCredential(rvc)
const verifier = new Affinity({
registryUrl: `https://affinity-registry.${options.env}.affinity-project.org`,
apiKey: accessApiKey
}, platformCryptographyTools)
console.log(signedRevocableVC)
const vr = await verifier.validateCredential(signedRevocableVC)
console.log(vr)
await walletIssuer.revokeCredential(id , ' dont like any more ')
const vrRevoked = await verifier.validateCredential(signedRevocableVC)
console.log(vrRevoked)
}
main().catch(console.error)