-
Notifications
You must be signed in to change notification settings - Fork 1
/
offer-vc.ts
70 lines (65 loc) · 2.01 KB
/
offer-vc.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
import { createWallet } from '@affinidi/wallet-node-sdk'
const main = async () => {
const walletFactory = createWallet('AffinityCore')
const accessApiKey = '<your key>'
const options = {
env: 'prod',
accessApiKey,
}
const issuerWallet = await walletFactory.createWallet(options, 'P@55word!!!')
const holderWallet = await walletFactory.createWallet(options, 'P@55word!!!')
//create offer by issuer
const offeredCredentials = [
{
type: 'ContentLike',
renderInfo:{},
}]
const callbackUrl = 'https://vp-service.com/callback'
const credentialOfferRequestToken = await issuerWallet.generateCredentialOfferRequestToken(
offeredCredentials,
{
callbackUrl,
},
)
// create response by holder
const credentialOfferResponseToken = await holderWallet.createCredentialOfferResponseToken(
credentialOfferRequestToken,
)
// issuer verify response
const result = await issuerWallet.verifyCredentialOfferResponseToken(
credentialOfferResponseToken,
credentialOfferRequestToken,
)
// issue VC based on response
const jsonSchema = 'https://schema.affinidi.com/ContentLikeV1-0.json'
const jsonContext = 'https://schema.affinidi.com/ContentLikeV1-0.jsonld'
const id = `claimId:${(Math.random() + 1).toString(36).substring(2)}`
const unsignedVC = {
'@context': ['https://www.w3.org/2018/credentials/v1', jsonContext],
id,
type: ['VerifiableCredential', 'ContentLike'],
holder: {
id: 'placeholder'
},
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 signedCredentials = await issuerWallet.signCredentials(
credentialOfferResponseToken,
[unsignedVC],
)
}
main().catch(console.error)