5
5
* @author David I. Lehn
6
6
*
7
7
* @license BSD 3-Clause License
8
- * Copyright (c) 2017-2021 Digital Bazaar, Inc.
8
+ * Copyright (c) 2017-2022 Digital Bazaar, Inc.
9
9
* All rights reserved.
10
10
*
11
11
* Redistribution and use in source and binary forms, with or without
@@ -53,6 +53,26 @@ const dateRegex = new RegExp('^(\\d{4})-(0[1-9]|1[0-2])-' +
53
53
'(\\.[0-9]+)?(Z|(\\+|-)([01][0-9]|2[0-3]):' +
54
54
'([0-5][0-9]))$' , 'i' ) ;
55
55
56
+ /**
57
+ * @typedef {object } LinkedDataSignature
58
+ */
59
+
60
+ /**
61
+ * @typedef {object } Presentation
62
+ */
63
+
64
+ /**
65
+ * @typedef {object } ProofPurpose
66
+ */
67
+
68
+ /**
69
+ * @typedef {object } VerifiableCredential
70
+ */
71
+
72
+ /**
73
+ * @typedef {object } VerifiablePresentation
74
+ */
75
+
56
76
module . exports = {
57
77
issue,
58
78
createPresentation,
@@ -93,8 +113,8 @@ module.exports = {
93
113
* @param {LinkedDataSignature } options.suite - Signature suite (with private
94
114
* key material), passed in to sign().
95
115
*
96
- * Either pass in a ProofPurpose, or a default one will be created:
97
- * @param { ProofPurpose } [options. purpose]
116
+ * @param { ProofPurpose } [options.purpose] - A ProofPurpose. If not specified,
117
+ * a default purpose will be created.
98
118
*
99
119
* Other optional params passed to `sign()`:
100
120
* @param {object } [options.documentLoader] - A document loader.
@@ -107,11 +127,11 @@ module.exports = {
107
127
* @returns {Promise<VerifiableCredential> } Resolves on completion.
108
128
*/
109
129
async function issue ( {
110
- credential, suite, expansionMap,
111
- purpose = new CredentialIssuancePurpose ( ) ,
112
- documentLoader = defaultDocumentLoader ,
113
- now = new Date ( ) . toISOString ( )
114
- } = { } ) {
130
+ credential, suite, expansionMap,
131
+ purpose = new CredentialIssuancePurpose ( ) ,
132
+ documentLoader = defaultDocumentLoader ,
133
+ now
134
+ } = { } ) {
115
135
// check to make sure the `suite` has required params
116
136
// Note: verificationMethod defaults to publicKey.id, in suite constructor
117
137
if ( ! suite ) {
@@ -149,8 +169,8 @@ async function issue({
149
169
* presentation, signed or unsigned, that may contain within it a
150
170
* verifiable credential.
151
171
*
152
- * @param {LinkedDataSignature|LinkedDataSignature[] } suite - One or more
153
- * signature suites that are supported by the caller's use case. This is
172
+ * @param {LinkedDataSignature|LinkedDataSignature[] } options. suite - One or
173
+ * more signature suites that are supported by the caller's use case. This is
154
174
* an explicit design decision -- the calling code must specify which
155
175
* signature types (ed25519, RSA, etc) are allowed.
156
176
* Although it is expected that the secure resolution/fetching of the public
@@ -168,11 +188,12 @@ async function issue({
168
188
*
169
189
* or a default purpose will be created with params:
170
190
* @param {string } [options.challenge] - Required if purpose is not passed in.
171
- * @param {string } [options.controller]
172
- * @param {string } [options.domain]
191
+ * @param {string } [options.controller] - Purpose controller.
192
+ * @param {string } [options.domain] - Purpose domain.
173
193
*
174
- * @param {Function } [options.documentLoader]
175
- * @param {Function } [options.checkStatus]
194
+ * @param {Function } [options.documentLoader] - Document loader function.
195
+ * @param {Function } [options.checkStatus] - Optional function for checking
196
+ * credential status if `credentialStatus` is present on the credential.
176
197
* @param {string|Date } [options.now] - A string representing date time in
177
198
* ISO 8601 format or an instance of Date. Defaults to current date time.
178
199
*
@@ -205,8 +226,8 @@ async function verify(options = {}) {
205
226
*
206
227
* @param {object } options.credential - Verifiable credential.
207
228
*
208
- * @param {LinkedDataSignature|LinkedDataSignature[] } suite - One or more
209
- * signature suites that are supported by the caller's use case. This is
229
+ * @param {LinkedDataSignature|LinkedDataSignature[] } options. suite - One or
230
+ * more signature suites that are supported by the caller's use case. This is
210
231
* an explicit design decision -- the calling code must specify which
211
232
* signature types (ed25519, RSA, etc) are allowed.
212
233
* Although it is expected that the secure resolution/fetching of the public
@@ -215,7 +236,7 @@ async function verify(options = {}) {
215
236
*
216
237
* @param {CredentialIssuancePurpose } [options.purpose] - Optional
217
238
* proof purpose (a default one will be created if not passed in).
218
- * @param {Function } [options.documentLoader]
239
+ * @param {Function } [options.documentLoader] - Document loader function.
219
240
* @param {Function } [options.checkStatus] - Optional function for checking
220
241
* credential status if `credentialStatus` is present on the credential.
221
242
* @param {string|Date } [options.now] - A string representing date time in
@@ -244,7 +265,7 @@ async function verifyCredential(options = {}) {
244
265
* Verifies a verifiable credential.
245
266
*
246
267
* @private
247
- * @param {object } [options={}]
268
+ * @param {object } [options={}] - Options hashmap.
248
269
*
249
270
* @param {object } options.credential - Verifiable credential.
250
271
* @param {LinkedDataSignature|LinkedDataSignature[] } options.suite - See the
@@ -254,8 +275,8 @@ async function verifyCredential(options = {}) {
254
275
*
255
276
* @throws {Error } If required parameters are missing (in `_checkCredential`).
256
277
*
257
- * @param {CredentialIssuancePurpose } [options.purpose]
258
- * @param {Function } [options.documentLoader]
278
+ * @param {CredentialIssuancePurpose } [options.purpose] - Issuance purpose.
279
+ * @param {Function } [options.documentLoader] - Document loader function.
259
280
* @param {Function } [options.checkStatus] - Optional function for checking
260
281
* credential status if `credentialStatus` is present on the credential.
261
282
*
@@ -348,15 +369,16 @@ function createPresentation({verifiableCredential, id, holder, now} = {}) {
348
369
* @param {object } [options={}] - Options to use.
349
370
*
350
371
* Required:
351
- * @param {Presentation } options.presentation
372
+ * @param {Presentation } options.presentation - Presentation to sign.
352
373
* @param {LinkedDataSignature } options.suite - passed in to sign()
353
374
*
354
375
* Either pass in a ProofPurpose, or a default one will be created with params:
355
- * @param {ProofPurpose } [options.purpose]
356
- * @param {string } [options.domain]
357
- * @param {string } options.challenge - Required.
376
+ * @param {ProofPurpose } [options.purpose] - A ProofPurpose. If not specified,
377
+ * a default purpose will be created with the domain and challenge options.
378
+ * @param {string } [options.domain] - Optional purpose domain.
379
+ * @param {string } options.challenge - Required challenge.
358
380
*
359
- * @param {Function } [options.documentLoader]
381
+ * @param {Function } [options.documentLoader] - Document loader function.
360
382
*
361
383
* @returns {Promise<{VerifiablePresentation}> } A VerifiablePresentation with
362
384
* a proof.
@@ -378,8 +400,9 @@ async function signPresentation(options = {}) {
378
400
* proof signature if it's present. Also verifies all the VerifiableCredentials
379
401
* that are present in the presentation, if any.
380
402
*
381
- * @param {object } [options={}]
382
- * @param {VerifiablePresentation } options.presentation
403
+ * @param {object } [options={}] - Options hashmap.
404
+ * @param {VerifiablePresentation } options.presentation - A
405
+ * VerifiablePresentation.
383
406
*
384
407
* @param {LinkedDataSignature|LinkedDataSignature[] } options.suite - See the
385
408
* definition in the `verify()` docstring, for this param.
@@ -390,15 +413,20 @@ async function signPresentation(options = {}) {
390
413
* unsigned presentation.
391
414
*
392
415
* Either pass in a proof purpose,
393
- * @param {AuthenticationProofPurpose } [options.presentationPurpose]
394
- *
395
- * or a default purpose will be created with params:
396
- * @param {string } [options.challenge] - Required if purpose is not passed in.
397
- * @param {string } [options.controller]
398
- * @param {string } [options.domain]
399
- *
400
- * @param {Function } [options.documentLoader]
401
- * @param {Function } [options.checkStatus]
416
+ * @param {AuthenticationProofPurpose } [options.presentationPurpose] - A
417
+ * ProofPurpose. If not specified, a default purpose will be created with
418
+ * the challenge, controller, and domain options.
419
+ *
420
+ * @param {string } [options.challenge] - A challenge. Required if purpose is
421
+ * not passed in.
422
+ * @param {string } [options.controller] - A controller. Required if purpose is
423
+ * not passed in.
424
+ * @param {string } [options.domain] - A domain. Required if purpose is not
425
+ * passed in.
426
+ *
427
+ * @param {Function } [options.documentLoader] - A document loader.
428
+ * @param {Function } [options.checkStatus] - Optional function for checking
429
+ * credential status if `credentialStatus` is present on the credential.
402
430
* @param {string|Date } [options.now] - A string representing date time in
403
431
* ISO 8601 format or an instance of Date. Defaults to current date time.
404
432
*
0 commit comments