Skip to content

Commit fc3bc3d

Browse files
Update comments to match upstream.
1 parent cb77190 commit fc3bc3d

File tree

1 file changed

+64
-36
lines changed

1 file changed

+64
-36
lines changed

lib/index.js

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @author David I. Lehn
66
*
77
* @license BSD 3-Clause License
8-
* Copyright (c) 2017-2021 Digital Bazaar, Inc.
8+
* Copyright (c) 2017-2022 Digital Bazaar, Inc.
99
* All rights reserved.
1010
*
1111
* 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])-' +
5353
'(\\.[0-9]+)?(Z|(\\+|-)([01][0-9]|2[0-3]):' +
5454
'([0-5][0-9]))$', 'i');
5555

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+
5676
module.exports = {
5777
issue,
5878
createPresentation,
@@ -93,8 +113,8 @@ module.exports = {
93113
* @param {LinkedDataSignature} options.suite - Signature suite (with private
94114
* key material), passed in to sign().
95115
*
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.
98118
*
99119
* Other optional params passed to `sign()`:
100120
* @param {object} [options.documentLoader] - A document loader.
@@ -107,11 +127,11 @@ module.exports = {
107127
* @returns {Promise<VerifiableCredential>} Resolves on completion.
108128
*/
109129
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+
} = {}) {
115135
// check to make sure the `suite` has required params
116136
// Note: verificationMethod defaults to publicKey.id, in suite constructor
117137
if(!suite) {
@@ -149,8 +169,8 @@ async function issue({
149169
* presentation, signed or unsigned, that may contain within it a
150170
* verifiable credential.
151171
*
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
154174
* an explicit design decision -- the calling code must specify which
155175
* signature types (ed25519, RSA, etc) are allowed.
156176
* Although it is expected that the secure resolution/fetching of the public
@@ -168,11 +188,12 @@ async function issue({
168188
*
169189
* or a default purpose will be created with params:
170190
* @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.
173193
*
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.
176197
* @param {string|Date} [options.now] - A string representing date time in
177198
* ISO 8601 format or an instance of Date. Defaults to current date time.
178199
*
@@ -205,8 +226,8 @@ async function verify(options = {}) {
205226
*
206227
* @param {object} options.credential - Verifiable credential.
207228
*
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
210231
* an explicit design decision -- the calling code must specify which
211232
* signature types (ed25519, RSA, etc) are allowed.
212233
* Although it is expected that the secure resolution/fetching of the public
@@ -215,7 +236,7 @@ async function verify(options = {}) {
215236
*
216237
* @param {CredentialIssuancePurpose} [options.purpose] - Optional
217238
* 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.
219240
* @param {Function} [options.checkStatus] - Optional function for checking
220241
* credential status if `credentialStatus` is present on the credential.
221242
* @param {string|Date} [options.now] - A string representing date time in
@@ -244,7 +265,7 @@ async function verifyCredential(options = {}) {
244265
* Verifies a verifiable credential.
245266
*
246267
* @private
247-
* @param {object} [options={}]
268+
* @param {object} [options={}] - Options hashmap.
248269
*
249270
* @param {object} options.credential - Verifiable credential.
250271
* @param {LinkedDataSignature|LinkedDataSignature[]} options.suite - See the
@@ -254,8 +275,8 @@ async function verifyCredential(options = {}) {
254275
*
255276
* @throws {Error} If required parameters are missing (in `_checkCredential`).
256277
*
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.
259280
* @param {Function} [options.checkStatus] - Optional function for checking
260281
* credential status if `credentialStatus` is present on the credential.
261282
*
@@ -348,15 +369,16 @@ function createPresentation({verifiableCredential, id, holder, now} = {}) {
348369
* @param {object} [options={}] - Options to use.
349370
*
350371
* Required:
351-
* @param {Presentation} options.presentation
372+
* @param {Presentation} options.presentation - Presentation to sign.
352373
* @param {LinkedDataSignature} options.suite - passed in to sign()
353374
*
354375
* 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.
358380
*
359-
* @param {Function} [options.documentLoader]
381+
* @param {Function} [options.documentLoader] - Document loader function.
360382
*
361383
* @returns {Promise<{VerifiablePresentation}>} A VerifiablePresentation with
362384
* a proof.
@@ -378,8 +400,9 @@ async function signPresentation(options = {}) {
378400
* proof signature if it's present. Also verifies all the VerifiableCredentials
379401
* that are present in the presentation, if any.
380402
*
381-
* @param {object} [options={}]
382-
* @param {VerifiablePresentation} options.presentation
403+
* @param {object} [options={}] - Options hashmap.
404+
* @param {VerifiablePresentation} options.presentation - A
405+
* VerifiablePresentation.
383406
*
384407
* @param {LinkedDataSignature|LinkedDataSignature[]} options.suite - See the
385408
* definition in the `verify()` docstring, for this param.
@@ -390,15 +413,20 @@ async function signPresentation(options = {}) {
390413
* unsigned presentation.
391414
*
392415
* 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.
402430
* @param {string|Date} [options.now] - A string representing date time in
403431
* ISO 8601 format or an instance of Date. Defaults to current date time.
404432
*

0 commit comments

Comments
 (0)