@arcblock/vc 1.18.166 → 1.19.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/lib/index.js +53 -48
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -33,9 +33,9 @@ const proofTypes = {
|
|
|
33
33
|
* @param {Date} params.expirationDate
|
|
34
34
|
* @param {String} params.endpoint - Status endpoint url
|
|
35
35
|
* @param {String} params.endpointScope - Endpoint scope, either be public or private
|
|
36
|
-
* @returns {object}
|
|
36
|
+
* @returns {Promise<object>}
|
|
37
37
|
*/
|
|
38
|
-
function create({
|
|
38
|
+
async function create({
|
|
39
39
|
type,
|
|
40
40
|
subject,
|
|
41
41
|
issuer,
|
|
@@ -124,7 +124,7 @@ function create({
|
|
|
124
124
|
|
|
125
125
|
debug('create', result);
|
|
126
126
|
|
|
127
|
-
if (verify({ vc: result, ownerDid: subject.id, trustedIssuers: [issuerDid] })) {
|
|
127
|
+
if (await verify({ vc: result, ownerDid: subject.id, trustedIssuers: [issuerDid] })) {
|
|
128
128
|
return result;
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -142,9 +142,9 @@ function create({
|
|
|
142
142
|
* @param {string} ownerDid - vc holder/owner did
|
|
143
143
|
* @param {Array} trustedIssuers - list of issuer did
|
|
144
144
|
* @throws {Error}
|
|
145
|
-
* @returns {boolean}
|
|
145
|
+
* @returns {Promise<boolean>}
|
|
146
146
|
*/
|
|
147
|
-
function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
|
|
147
|
+
async function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
|
|
148
148
|
// Integrity check
|
|
149
149
|
if (!vc) {
|
|
150
150
|
throw new Error('Empty verifiable credential object');
|
|
@@ -196,7 +196,7 @@ function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
|
|
|
196
196
|
delete clone.signature;
|
|
197
197
|
|
|
198
198
|
// Verify signature
|
|
199
|
-
if (issuer.verify(stringify(clone), fromBase64(signature)) !== true) {
|
|
199
|
+
if ((await issuer.verify(stringify(clone), fromBase64(signature))) !== true) {
|
|
200
200
|
throw Error('Verifiable credential signature not valid');
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -216,9 +216,9 @@ function verify({ vc, ownerDid, trustedIssuers, ignoreExpired = false }) {
|
|
|
216
216
|
* @param {Array} trustedIssuers - list of issuer did
|
|
217
217
|
* @param {String} challenge - Random byte you want
|
|
218
218
|
* @throws {Error}
|
|
219
|
-
* @returns {boolean}
|
|
219
|
+
* @returns {Promise<boolean>}
|
|
220
220
|
*/
|
|
221
|
-
function verifyPresentation({ presentation, trustedIssuers, challenge, ignoreExpired = false }) {
|
|
221
|
+
async function verifyPresentation({ presentation, trustedIssuers, challenge, ignoreExpired = false }) {
|
|
222
222
|
if (!presentation.challenge || challenge !== presentation.challenge) {
|
|
223
223
|
throw Error('Invalid challenge included on vc presentation');
|
|
224
224
|
}
|
|
@@ -231,22 +231,24 @@ function verifyPresentation({ presentation, trustedIssuers, challenge, ignoreExp
|
|
|
231
231
|
const clone = cloneDeep(presentation);
|
|
232
232
|
delete clone.proof;
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
await Promise.all(
|
|
235
|
+
vcList.map(async (vcStr) => {
|
|
236
|
+
const vcObj = JSON.parse(vcStr);
|
|
237
|
+
const proof = proofList.find((x) => isFromPublicKey(vcObj.credentialSubject.id, x.pk));
|
|
237
238
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
if (!proof) {
|
|
240
|
+
throw Error(`VC does not have corresponding proof: ${vcStr}`);
|
|
241
|
+
}
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
const signature = proof.jws;
|
|
244
|
+
const holder = fromPublicKey(fromBase58(proof.pk), toTypeInfo(vcObj.credentialSubject.id));
|
|
245
|
+
if ((await holder.verify(stringify(clone), fromBase64(signature))) !== true) {
|
|
246
|
+
throw Error('Presentation signature invalid');
|
|
247
|
+
}
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
await verify({ vc: vcObj, ownerDid: vcObj.credentialSubject.id, trustedIssuers, ignoreExpired });
|
|
250
|
+
})
|
|
251
|
+
);
|
|
250
252
|
|
|
251
253
|
return true;
|
|
252
254
|
}
|
|
@@ -292,37 +294,40 @@ function createCredentialList({ claims, issuer, issuanceDate }) {
|
|
|
292
294
|
});
|
|
293
295
|
}
|
|
294
296
|
|
|
295
|
-
|
|
297
|
+
// eslint-disable-next-line require-await
|
|
298
|
+
async function verifyCredentialList({ credentials, trustedIssuers }) {
|
|
296
299
|
if (!credentials || !Array.isArray(credentials)) {
|
|
297
300
|
throw new Error('Can not verify with empty credentials list');
|
|
298
301
|
}
|
|
299
302
|
|
|
300
|
-
return
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
303
|
+
return Promise.all(
|
|
304
|
+
credentials.map(async (x) => {
|
|
305
|
+
// Verify issuer
|
|
306
|
+
const issuers = Array.isArray(trustedIssuers) ? trustedIssuers : [trustedIssuers];
|
|
307
|
+
const issuerDid = issuers.find((d) => d === x.issuer.id);
|
|
308
|
+
if (!issuerDid) {
|
|
309
|
+
throw new Error('Credential not issued by trusted issuers');
|
|
310
|
+
}
|
|
311
|
+
if (!isFromPublicKey(issuerDid, x.issuer.pk)) {
|
|
312
|
+
throw new Error('Credential not issuer pk not match with issuer did');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Construct the issuer wallet
|
|
316
|
+
const issuer = fromPublicKey(x.issuer.pk, toTypeInfo(issuerDid));
|
|
317
|
+
|
|
318
|
+
// NOTE: we are ignoring other fields of the proof
|
|
319
|
+
const clone = cloneDeep(x);
|
|
320
|
+
const signature = clone.proof.jws;
|
|
321
|
+
delete clone.proof;
|
|
322
|
+
|
|
323
|
+
// Verify signature
|
|
324
|
+
if ((await issuer.verify(stringify(clone), fromBase64(signature))) !== true) {
|
|
325
|
+
throw Error('Status credential signature not valid');
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return x.claim;
|
|
329
|
+
})
|
|
330
|
+
);
|
|
326
331
|
}
|
|
327
332
|
|
|
328
333
|
module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/vc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"description": "Javascript lib to work with ArcBlock Verifiable Credentials",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcblock",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"url": "https://github.com/ArcBlock/blockchain/issues"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@arcblock/did": "1.
|
|
51
|
-
"@ocap/mcrypto": "1.
|
|
52
|
-
"@ocap/util": "1.
|
|
53
|
-
"@ocap/wallet": "1.
|
|
50
|
+
"@arcblock/did": "1.19.0",
|
|
51
|
+
"@ocap/mcrypto": "1.19.0",
|
|
52
|
+
"@ocap/util": "1.19.0",
|
|
53
|
+
"@ocap/wallet": "1.19.0",
|
|
54
54
|
"debug": "^4.3.6",
|
|
55
55
|
"is-absolute-url": "^3.0.3",
|
|
56
56
|
"json-stable-stringify": "^1.0.1",
|
|
57
57
|
"lodash": "^4.17.21"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1b6fac03988fb18507c8ef4c21de282762005f87"
|
|
60
60
|
}
|