|
1 | 1 | import { TAgent, IDIDManager, IIdentifier, IDataStore } from '../../packages/core/src'
|
2 | 2 | import { IDataStoreORM } from '../../packages/data-store/src'
|
3 | 3 | import { ICredentialIssuer } from '../../packages/credential-w3c/src'
|
| 4 | +import { decodeJWT } from 'did-jwt' |
4 | 5 |
|
5 | 6 | type ConfiguredAgent = TAgent<IDIDManager & ICredentialIssuer & IDataStore & IDataStoreORM>
|
6 | 7 |
|
@@ -69,6 +70,34 @@ export default (testContext: {
|
69 | 70 | expect(verifiableCredential).toHaveProperty('issuanceDate')
|
70 | 71 | expect(verifiableCredential['@context']).toEqual(['https://www.w3.org/2018/credentials/v1'])
|
71 | 72 | expect(verifiableCredential['type']).toEqual(['VerifiableCredential'])
|
| 73 | + |
| 74 | + const token = verifiableCredential.proof.jwt |
| 75 | + const { payload } = decodeJWT(token) |
| 76 | + expect(payload.vc.credentialSubject.id).not.toBeDefined() |
| 77 | + }) |
| 78 | + |
| 79 | + it('should create verifiable credential keeping original fields', async () => { |
| 80 | + expect.assertions(5) |
| 81 | + const verifiableCredential = await agent.createVerifiableCredential({ |
| 82 | + credential: { |
| 83 | + issuer: { id: identifier.did }, |
| 84 | + credentialSubject: { |
| 85 | + id: 'did:web:example.com', |
| 86 | + you: 'Rock', |
| 87 | + }, |
| 88 | + }, |
| 89 | + proofFormat: 'jwt', |
| 90 | + removeOriginalFields: false, |
| 91 | + }) |
| 92 | + |
| 93 | + expect(verifiableCredential).toHaveProperty('proof.jwt') |
| 94 | + expect(verifiableCredential).toHaveProperty('issuanceDate') |
| 95 | + expect(verifiableCredential['@context']).toEqual(['https://www.w3.org/2018/credentials/v1']) |
| 96 | + expect(verifiableCredential['type']).toEqual(['VerifiableCredential']) |
| 97 | + |
| 98 | + const token = verifiableCredential.proof.jwt |
| 99 | + const { payload } = decodeJWT(token) |
| 100 | + expect(payload.vc.credentialSubject.id).toEqual('did:web:example.com') |
72 | 101 | })
|
73 | 102 |
|
74 | 103 | it('should create verifiable presentation', async () => {
|
@@ -142,6 +171,41 @@ export default (testContext: {
|
142 | 171 |
|
143 | 172 | const verifiablePresentation2 = await agent.dataStoreGetVerifiablePresentation({ hash })
|
144 | 173 | expect(verifiablePresentation).toEqual(verifiablePresentation2)
|
| 174 | + |
| 175 | + const token = verifiablePresentation.proof.jwt |
| 176 | + const { payload } = decodeJWT(token) |
| 177 | + expect(payload.holder).not.toBeDefined() |
| 178 | + }) |
| 179 | + |
| 180 | + it('should create verifiable presentation (simple) keeping original fields', async () => { |
| 181 | + const verifiableCredential = await agent.createVerifiableCredential({ |
| 182 | + credential: { |
| 183 | + issuer: { id: identifier.did }, |
| 184 | + credentialSubject: { |
| 185 | + id: 'did:web:example.com', |
| 186 | + you: 'Rock', |
| 187 | + }, |
| 188 | + }, |
| 189 | + proofFormat: 'jwt', |
| 190 | + }) |
| 191 | + |
| 192 | + const verifiablePresentation = await agent.createVerifiablePresentation({ |
| 193 | + presentation: { |
| 194 | + holder: identifier.did, |
| 195 | + verifier: [], |
| 196 | + verifiableCredential: [verifiableCredential], |
| 197 | + }, |
| 198 | + proofFormat: 'jwt', |
| 199 | + removeOriginalFields: false, |
| 200 | + }) |
| 201 | + |
| 202 | + expect(verifiablePresentation).toHaveProperty('proof.jwt') |
| 203 | + expect(verifiablePresentation['@context']).toEqual(['https://www.w3.org/2018/credentials/v1']) |
| 204 | + expect(verifiablePresentation['type']).toEqual(['VerifiablePresentation']) |
| 205 | + |
| 206 | + const token = verifiablePresentation.proof.jwt |
| 207 | + const { payload } = decodeJWT(token) |
| 208 | + expect(payload.holder).toEqual(identifier.did) |
145 | 209 | })
|
146 | 210 |
|
147 | 211 | it('should query for credentials', async () => {
|
|
0 commit comments