@digitalbazaar/vc 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -6
- package/lib/CredentialIssuancePurpose.js +6 -7
- package/lib/contexts/index.js +17 -11
- package/lib/contexts/odrl.js +3 -3
- package/lib/contexts/vc-examples-v1.js +21 -2
- package/lib/documentLoader.js +4 -6
- package/lib/index.js +615 -3
- package/package.json +32 -46
- package/CHANGELOG.md +0 -92
- package/lib/vc.js +0 -579
package/README.md
CHANGED
|
@@ -48,7 +48,13 @@ the following:
|
|
|
48
48
|
|
|
49
49
|
## Install
|
|
50
50
|
|
|
51
|
-
- Node.js
|
|
51
|
+
- Browsers and Node.js 14+ are supported.
|
|
52
|
+
|
|
53
|
+
To install from NPM:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
npm install @digitalbazaar/vc
|
|
57
|
+
```
|
|
52
58
|
|
|
53
59
|
To install locally (for development):
|
|
54
60
|
|
|
@@ -106,7 +112,7 @@ const credential = {
|
|
|
106
112
|
}
|
|
107
113
|
};
|
|
108
114
|
|
|
109
|
-
const signedVC = await vc.issue({credential, suite});
|
|
115
|
+
const signedVC = await vc.issue({credential, suite, documentLoader});
|
|
110
116
|
console.log(JSON.stringify(signedVC, null, 2));
|
|
111
117
|
```
|
|
112
118
|
|
|
@@ -227,7 +233,7 @@ const vp = await vc.signPresentation({
|
|
|
227
233
|
const signedVC = await vc.issue({credential, suite, documentLoader});
|
|
228
234
|
|
|
229
235
|
// or
|
|
230
|
-
const result = await vc.
|
|
236
|
+
const result = await vc.verifyCredential({credential: signedVC, suite, documentLoader});
|
|
231
237
|
|
|
232
238
|
```
|
|
233
239
|
|
|
@@ -302,7 +308,7 @@ To verify a verifiable presentation:
|
|
|
302
308
|
// challenge has been received from the requesting party - see 'challenge'
|
|
303
309
|
// section below
|
|
304
310
|
|
|
305
|
-
const result = await vc.verify({presentation, challenge, suite});
|
|
311
|
+
const result = await vc.verify({presentation, challenge, suite, documentLoader});
|
|
306
312
|
// {valid: true}
|
|
307
313
|
```
|
|
308
314
|
|
|
@@ -312,7 +318,7 @@ flag:
|
|
|
312
318
|
|
|
313
319
|
```js
|
|
314
320
|
const result = await vc.verify({
|
|
315
|
-
presentation, suite, unsignedPresentation: true
|
|
321
|
+
presentation, suite, documentLoader, unsignedPresentation: true
|
|
316
322
|
});
|
|
317
323
|
// {valid: true}
|
|
318
324
|
```
|
|
@@ -345,7 +351,7 @@ Pre-requisites:
|
|
|
345
351
|
To verify a verifiable credential:
|
|
346
352
|
|
|
347
353
|
```js
|
|
348
|
-
const result = await vc.verifyCredential({credential, suite});
|
|
354
|
+
const result = await vc.verifyCredential({credential, suite, documentLoader});
|
|
349
355
|
// {valid: true}
|
|
350
356
|
```
|
|
351
357
|
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import jsonld from 'jsonld';
|
|
5
|
+
import jsigs from 'jsonld-signatures';
|
|
6
|
+
|
|
7
|
+
const {purposes: {AssertionProofPurpose}} = jsigs;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Creates a proof purpose that will validate whether or not the verification
|
|
10
11
|
* method in a proof was authorized by its declared controller for the
|
|
11
12
|
* proof's purpose.
|
|
12
13
|
*/
|
|
13
|
-
class CredentialIssuancePurpose extends AssertionProofPurpose {
|
|
14
|
+
export class CredentialIssuancePurpose extends AssertionProofPurpose {
|
|
14
15
|
/**
|
|
15
16
|
* @param {object} options - The options to use.
|
|
16
17
|
* @param {object} [options.controller] - The description of the controller,
|
|
@@ -77,5 +78,3 @@ class CredentialIssuancePurpose extends AssertionProofPurpose {
|
|
|
77
78
|
}
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
|
-
|
|
81
|
-
module.exports = CredentialIssuancePurpose;
|
package/lib/contexts/index.js
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import {
|
|
5
|
+
contexts as credentialContexts
|
|
6
|
+
} from 'credentials-context';
|
|
7
|
+
import {
|
|
8
|
+
CONTEXT as vcExamplesV1Context,
|
|
9
|
+
CONTEXT_URL as vcExamplesV1ContextUrl
|
|
10
|
+
} from './vc-examples-v1.js';
|
|
11
|
+
import {
|
|
12
|
+
CONTEXT as odrlContext,
|
|
13
|
+
CONTEXT_URL as odrlContextUrl
|
|
14
|
+
} from './odrl.js';
|
|
5
15
|
|
|
6
|
-
const
|
|
16
|
+
export const contexts = {};
|
|
7
17
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
require('./vc-examples-v1'),
|
|
11
|
-
'https://www.w3.org/ns/odrl.jsonld': require('./odrl')
|
|
12
|
-
};
|
|
18
|
+
contexts[vcExamplesV1ContextUrl] = vcExamplesV1Context;
|
|
19
|
+
contexts[odrlContextUrl] = odrlContext;
|
|
13
20
|
|
|
14
|
-
for(const
|
|
15
|
-
|
|
16
|
-
exportedContexts[contextUrl] = contexts.get(contextUrl);
|
|
21
|
+
for(const [url, context] of credentialContexts.entries()) {
|
|
22
|
+
contexts[url] = context;
|
|
17
23
|
}
|
package/lib/contexts/odrl.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
'use strict';
|
|
5
4
|
|
|
5
|
+
export const CONTEXT_URL = 'https://www.w3.org/ns/odrl.jsonld';
|
|
6
6
|
/* eslint-disable quote-props, key-spacing, max-len */
|
|
7
|
-
|
|
7
|
+
export const CONTEXT = {
|
|
8
8
|
'@context': {
|
|
9
9
|
'odrl': 'http://www.w3.org/ns/odrl/2/',
|
|
10
10
|
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
export const CONTEXT_URL = 'https://www.w3.org/2018/credentials/examples/v1';
|
|
5
6
|
/* eslint-disable quote-props */
|
|
6
|
-
|
|
7
|
+
export const CONTEXT = {
|
|
7
8
|
'@context': [
|
|
8
9
|
{
|
|
9
10
|
'@version': 1.1
|
|
@@ -16,26 +17,44 @@ module.exports = {
|
|
|
16
17
|
|
|
17
18
|
'3rdPartyCorrelation': 'ex:3rdPartyCorrelation',
|
|
18
19
|
'AllVerifiers': 'ex:AllVerifiers',
|
|
20
|
+
'AlumniCredential': 'ex:AlumniCredential',
|
|
19
21
|
'Archival': 'ex:Archival',
|
|
20
22
|
'BachelorDegree': 'ex:BachelorDegree',
|
|
21
23
|
'Child': 'ex:Child',
|
|
22
24
|
'CLCredentialDefinition2019': 'ex:CLCredentialDefinition2019',
|
|
23
25
|
'CLSignature2019': 'ex:CLSignature2019',
|
|
26
|
+
'DisputeCredential': 'ex:DisputeCredential',
|
|
24
27
|
'IssuerPolicy': 'ex:IssuerPolicy',
|
|
25
28
|
'HolderPolicy': 'ex:HolderPolicy',
|
|
26
29
|
'Mother': 'ex:Mother',
|
|
30
|
+
'PrescriptionCredential': 'ex:PrescriptionCredential',
|
|
27
31
|
'RelationshipCredential': 'ex:RelationshipCredential',
|
|
28
32
|
'UniversityDegreeCredential': 'ex:UniversityDegreeCredential',
|
|
29
33
|
'ZkpExampleSchema2018': 'ex:ZkpExampleSchema2018',
|
|
30
34
|
|
|
31
35
|
'alumniOf': {'@id': 'schema:alumniOf', '@type': 'rdf:HTML'},
|
|
36
|
+
'attributes': 'ex:attributes',
|
|
32
37
|
'child': {'@id': 'ex:child', '@type': '@id'},
|
|
38
|
+
'college': 'ex:college',
|
|
39
|
+
'currentStatus': 'ex:currentStatus',
|
|
33
40
|
'degree': 'ex:degree',
|
|
41
|
+
'degreeSchool': 'ex:degreeSchool',
|
|
42
|
+
'degreeType': 'ex:degreeType',
|
|
43
|
+
'familyName': 'schema:familyName',
|
|
44
|
+
'givenName': 'schema:givenName',
|
|
45
|
+
'issuerData': 'ex:issuerData',
|
|
34
46
|
'name': {'@id': 'schema:name', '@type': 'rdf:HTML'},
|
|
47
|
+
'nonRevocationProof': 'ex:nonRevocationProof',
|
|
35
48
|
'parent': {'@id': 'ex:parent', '@type': '@id'},
|
|
49
|
+
'prescription': 'ex:prescription',
|
|
50
|
+
'primaryProof': 'ex:primaryProof',
|
|
36
51
|
'referenceId': 'ex:referenceId',
|
|
37
52
|
'documentPresence': 'ex:documentPresence',
|
|
38
53
|
'evidenceDocument': 'ex:evidenceDocument',
|
|
54
|
+
'signature': 'ex:signature',
|
|
55
|
+
'signatureCorrectnessProof': 'ex:signatureCorrectnessProof',
|
|
56
|
+
'spouse': 'schema:spouse',
|
|
57
|
+
'statusReason': 'ex:statusReason',
|
|
39
58
|
'subjectPresence': 'ex:subjectPresence',
|
|
40
59
|
'verifier': {'@id': 'ex:verifier', '@type': '@id'},
|
|
41
60
|
}
|
package/lib/documentLoader.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Copyright (c) 2019-
|
|
2
|
+
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
|
-
'use strict';
|
|
5
|
-
|
|
6
4
|
// load locally embedded contexts
|
|
7
|
-
|
|
5
|
+
import {contexts} from './contexts/index.js';
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
export async function documentLoader(url) {
|
|
10
8
|
const context = contexts[url];
|
|
11
9
|
if(context !== undefined) {
|
|
12
10
|
return {
|
|
@@ -16,4 +14,4 @@ module.exports = async function documentLoader(url) {
|
|
|
16
14
|
};
|
|
17
15
|
}
|
|
18
16
|
throw new Error(`Document loader unable to load URL "${url}".`);
|
|
19
|
-
}
|
|
17
|
+
}
|