@verii/batch-issuer 0.0.0-stage → 1.3.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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +296 -2
- package/package.json +50 -3
- package/src/cli.js +190 -0
- package/src/clients/hub-client.js +181 -0
- package/src/clients/init-client.js +40 -0
- package/src/clients/registrar-client.js +37 -0
- package/src/commands/check-rules.js +187 -0
- package/src/commands/exit-codes.js +30 -0
- package/src/commands/load.js +175 -0
- package/src/csv/load-csv.js +113 -0
- package/src/index.js +28 -0
- package/src/load/load-batch.js +313 -0
- package/src/report/count.js +24 -0
- package/src/report/describe-error.js +37 -0
- package/src/report/format-load-report.js +134 -0
- package/src/report/format-report.js +100 -0
- package/src/spec/load-spec.js +193 -0
- package/src/spec/spec-schema.js +109 -0
- package/src/state/state-file.js +212 -0
- package/src/templates/render-template.js +159 -0
- package/src/validation/check-credential-subjects.js +129 -0
- package/src/validation/check-rows.js +193 -0
- package/src/validation/check-service.js +127 -0
- package/src/validation/find-duplicates.js +147 -0
- package/src/validation/match-existing-depots.js +142 -0
- package/src/validation/reasons.js +21 -0
- package/src/validation/validate-batch.js +105 -0
- package/src/values/auth-values.js +130 -0
- package/src/values/convert-value.js +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright 2023 Velocity Team Authors
|
package/README.md
CHANGED
|
@@ -1,3 +1,297 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @verii/batch-issuer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`batch-issuer` loads Credentialing Hub depots and credentials from a CSV file, a YAML spec and JSON Handlebars templates, for batch issuing through an issuer service's shared issue link. It validates the whole batch before anything is written, and reports every error. A load records what it creates in a state file, so a load that stops partway can be run again.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
### `validate`
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
batch-issuer validate <spec> <csv> --endpoint <hub url> --network <network> --registrar <registrar url> [options]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Validates the batch against its spec, the registrar and the Hub, and prints every error with its row, column and reason. Nothing is written to the Hub. It's the same as `load --dryrun`.
|
|
14
|
+
|
|
15
|
+
| Option | |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `-e, --endpoint <url>` | The Credentialing Hub's base URL. Required |
|
|
18
|
+
| `-a, --auth-token <token>` | An operator API token. Required, unless `BATCH_ISSUER_AUTH_TOKEN` is set |
|
|
19
|
+
| `--network <name>` | The Velocity network of the Hub, such as `devnet`, `testnet` or `mainnet`. Required. The state file is tied to it, so a state file from a load into another network is refused. It's compared in lower case, and any name is accepted |
|
|
20
|
+
| `-r, --registrar <url>` | The registrar's base URL, for credential type schemas. Required when the spec has credentials |
|
|
21
|
+
| `--default-country <code>` | The country of phone numbers written without a country code, such as `US` |
|
|
22
|
+
| `--var <name=value>` | A value that overrides the CSV column of the same name, in every row. Repeatable |
|
|
23
|
+
| `--no-reuse` | Treat rows whose auth values already belong to a depot as errors. A depot that the state file records, because an earlier load of the batch created it, isn't a reuse |
|
|
24
|
+
| `--state <file>` | The batch's state file. Defaults to the CSV's name with `.state.jsonl` in the CSV's directory, such as `holders.state.jsonl` for `holders.csv`. See [Reruns and the state file](#reruns-and-the-state-file) |
|
|
25
|
+
| `--json` | Print the report as JSON |
|
|
26
|
+
|
|
27
|
+
### `load`
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
batch-issuer load <spec> <csv> --endpoint <hub url> --network <network> --registrar <registrar url> [options]
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Validates the batch as `validate` does, then creates its depots and credentials in the Hub, and writes each row's issue link to a CSV file for mail merge. See [What `load` does](#what-load-does).
|
|
34
|
+
|
|
35
|
+
It takes the same arguments and options as `validate`, and these:
|
|
36
|
+
|
|
37
|
+
| Option | |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `--dryrun` | Stop after validating. `load --dryrun` is `validate` |
|
|
40
|
+
| `--resolve-deferred` | Resolve the deferred credentials of each reused depot that receives credentials, so a wallet waiting for them is told |
|
|
41
|
+
| `-o, --output <file>` | The links file. Defaults to the CSV's name with `.links.csv` in the CSV's directory, such as `holders.links.csv` for `holders.csv`. See [The links file](#the-links-file) |
|
|
42
|
+
|
|
43
|
+
### `check-rules`
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
batch-issuer check-rules <spec> --sample <credential> [<credential> ...] --endpoint <hub url>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Reads the `verifiablePresentationAuthRules` of the spec's issuer service from the Hub, and shows what each rule reads from sample credentials: what each of its claims path pointers selects, and the normalized values the Hub would match depots against. It uses the Hub's rule evaluation (`selectClaims` and `ruleValues` from `@verii/credentialing-hub-operator-api`). A rule reads only the samples of its `type`.
|
|
50
|
+
|
|
51
|
+
A sample is a JSON credential, or a file holding a JWT. A JWT is decoded as the Hub decodes a presented credential, so a VC 1.1 JWT's rules read the credential it carries, with `credentialSubject.id` taken from `sub`. Its signature isn't checked.
|
|
52
|
+
|
|
53
|
+
It takes the same `--endpoint`, `--auth-token` and `--json` options as `validate`.
|
|
54
|
+
|
|
55
|
+
### The operator token
|
|
56
|
+
|
|
57
|
+
Pass the token in `BATCH_ISSUER_AUTH_TOKEN` rather than with `--auth-token`, which leaves it in the shell history:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
export BATCH_ISSUER_AUTH_TOKEN=...
|
|
61
|
+
batch-issuer validate spec.yaml holders.csv --endpoint https://hub.example.com --network testnet --registrar https://registrar.example.com
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The token is never printed or written, including in error messages, the links file and the state file.
|
|
65
|
+
|
|
66
|
+
### Exit codes
|
|
67
|
+
|
|
68
|
+
| Code | `validate` | `load` | `check-rules` |
|
|
69
|
+
| --- | --- | --- | --- |
|
|
70
|
+
| 0 | The batch is valid | The batch is loaded | Every rule reads a value from the samples |
|
|
71
|
+
| 1 | The batch has errors | The batch has errors, and nothing was written | A rule reads nothing from the samples |
|
|
72
|
+
| 2 | It couldn't validate: bad options, a spec or CSV file that can't be read, a state file of another batch, or a Hub or registrar error. A Hub response without what it should hold, such as a proxy's HTML page, is an error | It couldn't validate, as for `validate`, or a write failed partway, or a wallet message failed when it resolved deferred credentials. The state file records what was written, and rerunning the same command continues the load and retries the messages | It couldn't check: bad options or spec, a sample that can't be read, or a Hub error |
|
|
73
|
+
|
|
74
|
+
## The spec
|
|
75
|
+
|
|
76
|
+
```yaml
|
|
77
|
+
tenantId: 6512a1b2c3d4e5f6a7b8c9d0
|
|
78
|
+
serviceId: 6512a1b2c3d4e5f6a7b8c9d1
|
|
79
|
+
depot:
|
|
80
|
+
userReference: "{{employeeId}}"
|
|
81
|
+
authValues: # position = the rule's valueIndex
|
|
82
|
+
- column: email # rule 0: EmailV1.0, credentialSubject.email
|
|
83
|
+
expectedCredentialTypes: [OpenBadgeCredential]
|
|
84
|
+
deferredCredentials: false
|
|
85
|
+
columns: # optional, for typed values (default string)
|
|
86
|
+
creditsEarned: number
|
|
87
|
+
credentials: # optional: a load can create depots only
|
|
88
|
+
- template: ./open-badge.template.json
|
|
89
|
+
credentialReference: "{{employeeId}}-ivie-2026"
|
|
90
|
+
tags: [batch-2026-11]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| Field | |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `tenantId`, `serviceId` | The tenant and its issuer service. Required |
|
|
96
|
+
| `depot.userReference` | A Handlebars template of each depot's `userReference`. Required |
|
|
97
|
+
| `depot.authValues` | The CSV column of each of the service's auth rules, in `valueIndex` order: exactly one entry per rule. Leave it out for a `preauth` service |
|
|
98
|
+
| `depot.expectedCredentialTypes` | The credential types the depots may receive. Each template's type must be one of them |
|
|
99
|
+
| `depot.deferredCredentials` | Whether the depots' credentials may come later |
|
|
100
|
+
| `columns` | The type of each typed column: `string`, `number` or `boolean`. Other columns are strings |
|
|
101
|
+
| `credentials` | The credentials of each row. Without them, the spec loads depots only, and it needs `depot.deferredCredentials: true`, so a holder who opens the link before their credentials exist waits for them |
|
|
102
|
+
| `credentials[].template` | A JSON template of the credential's `content`, relative to the spec file |
|
|
103
|
+
| `credentials[].credentialReference` | A Handlebars template of the credential's `credentialReference`. It must be unique in the batch |
|
|
104
|
+
| `credentials[].tags` | Handlebars templates of the credential's tags |
|
|
105
|
+
|
|
106
|
+
The spec is checked against a JSON schema first, and nothing else is checked until it's valid.
|
|
107
|
+
|
|
108
|
+
## The CSV
|
|
109
|
+
|
|
110
|
+
The first line is the header. A byte order mark is stripped, header names are trimmed, and blank lines are skipped. Errors give rows as a spreadsheet numbers them, so the first row after the header is row 2.
|
|
111
|
+
|
|
112
|
+
Quoting is strict. A cell with a comma, a quote or a line break must be quoted, with each quote inside it doubled: `"Ng ""CJ"""`. A quote that is never closed would take the rest of the file into one cell, so it's an error at the row where the quote opens. A quote inside an unquoted cell is an error too. A CSV that doesn't parse stops validation before the Hub is called.
|
|
113
|
+
|
|
114
|
+
## Templates
|
|
115
|
+
|
|
116
|
+
A template is a credential's JSON `content`, with `type` and `credentialSubject`, whose strings are Handlebars templates:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"type": ["OpenBadgeCredential", "VerifiableCredential"],
|
|
121
|
+
"credentialSubject": {
|
|
122
|
+
"type": "AchievementSubject",
|
|
123
|
+
"creditsEarned": "{{creditsEarned}}",
|
|
124
|
+
"achievement": {
|
|
125
|
+
"name": "Influenza Vaccine Immunization Education (IVIE)",
|
|
126
|
+
"description": "Awarded to {{firstName}} {{lastName}}"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- **Value by value.** Each string is rendered on its own, and the JSON is never rebuilt from text. A CSV value only ever becomes part of a string, so a value with quotes or braces can't change the credential's structure. Keys, numbers, booleans and nulls are kept as they are.
|
|
133
|
+
- **Strict placeholders.** A column used in a placeholder, such as `{{name}}`, must be present: a row without it is an error, not an empty string. An empty cell renders as an empty string. A block helper's parameter isn't checked: `#if`, `#unless`, `#each` and `#with` read a missing column as falsy. So `{{#if middleName}} {{middleName}}{{/if}}` makes `middleName` optional, but a misspelled column there silently takes the other branch.
|
|
134
|
+
- **Not escaped.** Values aren't HTML-escaped: `{{name}}` and `{{{name}}}` are the same.
|
|
135
|
+
- **Typed values.** A string that is exactly `{{column}}`, or `{{[a column]}}`, takes the column's type from `columns`, so `"{{creditsEarned}}"` renders as the number `1.5`. Inside a longer string, a value stays text.
|
|
136
|
+
- **Overrides.** `--var name=value` overrides the CSV column `name` in every row, or provides it when the CSV has no such column.
|
|
137
|
+
- **Types.** The template's `type` must be a literal, not a Handlebars template.
|
|
138
|
+
|
|
139
|
+
`userReference`, `credentialReference` and tags are always strings, so they don't use `columns`.
|
|
140
|
+
|
|
141
|
+
Numbers are decimal, such as `12`, `-1.5` or `1e3`. Booleans are `true` or `false`, in any case.
|
|
142
|
+
|
|
143
|
+
## What `validate` checks
|
|
144
|
+
|
|
145
|
+
Every error is collected, and the command fails when there's any. `load` checks the same before it writes anything.
|
|
146
|
+
|
|
147
|
+
1. **The spec against the service,** from `issuer-services/get`:
|
|
148
|
+
- the service is an internal `verifiable_presentation` service, or `preauth`, and isn't deactivated;
|
|
149
|
+
- `depot.authValues` maps exactly the rules' `valueIndex` 0 to n−1;
|
|
150
|
+
- each template's type is in `depot.expectedCredentialTypes`, when it's set.
|
|
151
|
+
2. **Each row against the spec:**
|
|
152
|
+
- the columns the spec uses in placeholders are present. A block helper's parameter isn't checked, as [Templates](#templates) says. A column the CSV doesn't have at all is one error, not one per row;
|
|
153
|
+
- auth values are non-blank once trimmed, and convert to their rule's `valueType`;
|
|
154
|
+
- phone values, for a rule of type `PhoneV1.0` or with `valueFormat: e164`, are normalized to E.164 (`+15556192191`) with `libphonenumber-js`, using `--default-country` for numbers without a country code. A number that can't be normalized is an error;
|
|
155
|
+
- email values, for a rule of type `EmailV1.0` or with `valueFormat: email`, are email addresses, by the same check as the Hub's `email` format;
|
|
156
|
+
- no two rows have the same auth values, compared as the Hub matches them: normalized with `buildAuthMatchValues`, and by type, so `"12345"` and `12345` differ. Each duplicate row gets an error that counts the other rows and lists at most 10 of them, such as `has the same auth values as 49,999 other rows: 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 and 49,989 more`;
|
|
157
|
+
- the templates render;
|
|
158
|
+
- each `credentialReference` is unique in the batch. Each duplicate credential's error counts the uses and rows and lists at most 10 rows;
|
|
159
|
+
- each depot and credential passes the operator API's validator (`initOperatorApiValidator`), as the Hub validates `depots/create` and `credentials/create`.
|
|
160
|
+
3. **Each credential against its type:** the `credentialSubject` is checked against the type's JSON schema from the registrar, which `credentials/create` loads the same way. Every schema error is reported, not only the first.
|
|
161
|
+
4. **The batch against the Hub:** one `POST depots/get` with the rows' auth values, at most 1000 tuples per request. The depots it returns are matched to rows by normalizing their `authValues` with `buildAuthMatchValues`. For a match:
|
|
162
|
+
- the same `userReference` is a returning holder, whose depot gets the row's credentials. The row's credential types must be in the depot's `expectedCredentialTypes`, when it has any. A depot-only row has no credentials, so the spec's `depot.expectedCredentialTypes`, which a later load adds, must be in them instead. In a depot-only load, the depot must also have `deferredCredentials: true`, as the load's new depots do: the setting can't be changed, and the holder would otherwise get an empty offer. With `--no-reuse`, it's an error, unless the state file records the depot because an earlier load of the batch created it;
|
|
163
|
+
- a different `userReference` is always an error: two people share an email, or an email was reassigned;
|
|
164
|
+
- auth values that belong to more than one depot are an error.
|
|
165
|
+
|
|
166
|
+
A `preauth` service's depots can't be found by auth values, so every row gets a new depot.
|
|
167
|
+
|
|
168
|
+
Then the state file must belong to the batch, as [Reruns and the state file](#reruns-and-the-state-file) says.
|
|
169
|
+
|
|
170
|
+
## What `load` does
|
|
171
|
+
|
|
172
|
+
1. **Validates** the batch, as `validate` does. Any error stops the load before anything is written, with the same report, and exits with 1. `--dryrun` stops here.
|
|
173
|
+
2. **Depots:** `depots/create` for each row without a depot, one at a time, so two creates for the same holder can't race. A row that validation matched to an existing depot uses it. A 409 means that another client created a depot with the row's auth values after validation: the load stops and reports the row.
|
|
174
|
+
3. **Credentials:** `credentials/create-many`, in requests of at most 100 credentials, each to its row's depot, new or reused. The Hub takes up to 1000 per request (`CREDENTIALS_CREATE_MANY_MAX_ITEMS`), but it limits a request's body to 8 MiB, which 1000 large credentials can exceed. When the Hub refuses a request with a 400, the load reports each invalid credential with its row and template, and stops. The Hub checks every credential of a request before it creates any, so a refused request creates nothing, but the requests before it did.
|
|
175
|
+
4. **Deferred credentials:** with `--resolve-deferred`, `depots/resolve-deferred-credentials` for each reused depot that has `deferredCredentials: true` and received credentials from the batch. A wallet that's waiting on the depot is told its credentials are ready. The depots the batch creates aren't resolved: their holders haven't had a link yet. The Hub answers with the wallet message's status: `sent`, `skipped_no_messaging_settings`, `skipped_no_waiting_exchange` or `failed`. A depot whose message `failed` isn't recorded as resolved: the load goes on, then reports each one with its row, its depot and the Hub's error, and exits with 2. A rerun resolves it again.
|
|
176
|
+
5. **Links,** written to [the links file](#the-links-file):
|
|
177
|
+
- a service with internal `verifiable_presentation` auth: the shared link, from `issue-links/refresh` without a `depotId`. It's printed, and every row gets it;
|
|
178
|
+
- a `preauth` service: each depot the batch created gets its own link, from `issue-links/refresh` with its `depotId`. Reused depots are never refreshed, because a refresh replaces the depot's pre-authorized code (`refreshPreauthCode`) and breaks the links already sent. A service with both kinds of auth gives a reused depot's row the shared link instead.
|
|
179
|
+
|
|
180
|
+
The state file records each depot, credential, resolved depot and `preauth` link as soon as the Hub confirms it. A depot whose wallet message failed isn't recorded as resolved.
|
|
181
|
+
|
|
182
|
+
## The links file
|
|
183
|
+
|
|
184
|
+
`--output`, by default `holders.links.csv` beside `holders.csv`, has a line for each row that has a link, for mail merge:
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
row,userReference,redirectUrl
|
|
188
|
+
2,E1001,https://hub.example.com/app-redirect?...
|
|
189
|
+
3,E1002,https://hub.example.com/app-redirect?...
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`row` is the row's number in the CSV. Each run writes the whole file again. It can hold links that claim credentials, as [Keep the files private](#keep-the-files-private) says.
|
|
193
|
+
|
|
194
|
+
## Reruns and the state file
|
|
195
|
+
|
|
196
|
+
A load can fail partway after validation passes, for example on a network error. The Hub has no all-or-nothing endpoint, so the load records what it creates in a state file, and a rerun of the same command skips what's done.
|
|
197
|
+
|
|
198
|
+
`--state`, by default `holders.state.jsonl` beside `holders.csv`, records:
|
|
199
|
+
- the batch: its `--network`, `tenantId` and `serviceId`, and a hash of the spec file, its templates, the CSV, and the `--var` and `--default-country` values. The network tells apart loads into Hubs on different networks that hold the same tenant and service ids, such as a testnet Hub restored from a mainnet snapshot;
|
|
200
|
+
- each depot the batch created, with its row;
|
|
201
|
+
- each credential it created, with its row, `credentialReference`, id and depot;
|
|
202
|
+
- each depot whose deferred credentials it resolved, and each `preauth` link, with its row.
|
|
203
|
+
|
|
204
|
+
It's [JSON Lines](https://jsonlines.org). The load creates it with the batch's line, and appends a line as soon as the Hub confirms each depot, each `create-many` request, each resolved depot and each link:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
{"batch":{"network":"testnet","tenantId":"6512a1b2c3d4e5f6a7b8c9d0","serviceId":"6512a1b2c3d4e5f6a7b8c9d1","hash":"9f2c…"}}
|
|
208
|
+
{"depots":[{"row":3,"id":"6512a1b2c3d4e5f6a7b8c9e1"}]}
|
|
209
|
+
{"credentials":[{"row":2,"credentialReference":"E1001-ivie-2026","id":"…","depotId":"…"},…]}
|
|
210
|
+
{"resolvedDepots":["6512a1b2c3d4e5f6a7b8c9e0"]}
|
|
211
|
+
{"links":[{"row":3,"redirectUrl":"https://…"}]}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
A crash while a line is written can leave the last line unfinished. A last line that isn't JSON is ignored, so its record counts as not done, and the next load cuts it off before it appends. Any other line that isn't JSON is an error that names the file and the line.
|
|
215
|
+
|
|
216
|
+
A rerun:
|
|
217
|
+
- finds the depots again: by their auth values for a `verifiable_presentation` service, through validation's step 4, and from the state file, by row, for a `preauth` service, whose depots have no auth values. A depot the state file records counts as skipped, not reused, and `--no-reuse` accepts it;
|
|
218
|
+
- skips the credentials the state file records, by `credentialReference`;
|
|
219
|
+
- doesn't refresh a link again, or resolve a depot again unless its wallet message failed.
|
|
220
|
+
|
|
221
|
+
A rerun of a finished load creates nothing, and writes the same links file.
|
|
222
|
+
|
|
223
|
+
A state file belongs to one batch, and any change to the spec, its templates, the CSV, `--network`, `--var` or `--default-country` makes a different batch. `validate`, `load --dryrun` and `load` refuse the state file of another batch, and exit with 2. To load a new batch whose CSV has the same name, pass another `--state`, or move the old state file away.
|
|
224
|
+
|
|
225
|
+
### Keep the files private
|
|
226
|
+
|
|
227
|
+
The state file and the links file can hold links that claim credentials: a `preauth` link carries the depot's pre-authorized code, so anyone who has it can claim that holder's credentials. The load creates both files readable and writable by their owner only (mode `0600`). Keep them private, and delete them when the batch is done. A `verifiable_presentation` service's shared link is the same for every holder, and isn't a secret in the same way, but the files are still private.
|
|
228
|
+
|
|
229
|
+
### What a rerun can't tell
|
|
230
|
+
|
|
231
|
+
The Hub doesn't require a `credentialReference` to be unique (#1244), so the state file is the only guard against creating a credential twice:
|
|
232
|
+
- **A request that fails without a response,** such as a timeout or a dropped connection, may still have been carried out. A `create-many` request's credentials are then missing from the state file, and a rerun creates them again. A depot created that way is found again by its auth values for a `verifiable_presentation` service, as a reused depot, which `--no-reuse` refuses, but a `preauth` service's depot is created again.
|
|
233
|
+
- **A refused `create-many` request** created nothing. A rerun sends it again, which only helps once the cause is fixed in the Hub or the registrar, for example a credential type that the Hub's registrar doesn't know yet. A fix in the spec, a template or the CSV makes it a different batch, which the state file refuses.
|
|
234
|
+
- **A lost or deleted state file** makes a rerun create every credential again. The depots of a `verifiable_presentation` service are found again by their auth values, and reused.
|
|
235
|
+
|
|
236
|
+
## Output
|
|
237
|
+
|
|
238
|
+
The report lists the errors without a row first, then each row's errors:
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
Row 3:
|
|
242
|
+
- email: "adam" is not an email address
|
|
243
|
+
- creditsEarned: "two" is not a number (template ./open-badge.template.json)
|
|
244
|
+
|
|
245
|
+
The batch is not valid: 2 errors. Nothing was written to the Hub.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
A valid batch is summarized:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
The batch is valid: 3 rows, 2 new depots, 1 existing depot, 3 credentials. Nothing was written to the Hub.
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
With `--json`, the report is `{ valid, errors, summary }`. Each error has a `reason`, and a `row`, `column` and `template` when they apply. `summary` is missing when the spec has errors.
|
|
255
|
+
|
|
256
|
+
`load` prints the summary when the batch is valid, and what it did when it's done:
|
|
257
|
+
|
|
258
|
+
```
|
|
259
|
+
The batch is valid: 3 rows, 2 new depots, 1 existing depot, 3 credentials.
|
|
260
|
+
Depots: 2 created, 1 reused, 0 skipped.
|
|
261
|
+
Credentials: 3 created, 0 skipped.
|
|
262
|
+
Issue link: https://hub.example.com/app-redirect?...
|
|
263
|
+
Links: holders.links.csv
|
|
264
|
+
State: holders.state.jsonl
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Created is what this run created, reused the depots that already existed, and skipped what an earlier run of the batch created. With `--resolve-deferred`, a line counts the depots whose deferred credentials it resolved. The issue link is the shared link of a `verifiable_presentation` service.
|
|
268
|
+
|
|
269
|
+
When a wallet message fails, the load finishes, prints that report, then prints the failed messages on stderr, and exits with 2:
|
|
270
|
+
|
|
271
|
+
```
|
|
272
|
+
Row 2:
|
|
273
|
+
- the wallet message about depot 6512a1b2c3d4e5f6a7b8c9e0 failed: connect ECONNREFUSED 203.0.113.7:443
|
|
274
|
+
|
|
275
|
+
Error: the waiting wallets of 1 depot weren't told that their deferred credentials are ready. Rerun the same command to retry.
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
A load that stops prints, on stderr, the rows the Hub refused, if any, the error, and how far the batch got:
|
|
279
|
+
|
|
280
|
+
```
|
|
281
|
+
Row 3:
|
|
282
|
+
- email: the auth values belong to depot 6512a1b2c3d4e5f6a7b8c9ff, which another client created after validation
|
|
283
|
+
|
|
284
|
+
Error: depots/create refused a depot
|
|
285
|
+
The load stopped after creating 1 of 3 depots and 0 of 3 credentials. holders.state.jsonl records what was created. Rerun the same command to continue.
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
With `--json`, `load` prints `{ valid, errors, summary, load }`, where `load` has the counts `depots: { created, reused, skipped }` and `credentials: { created, skipped }`, `resolvedDepots` with `--resolve-deferred`, the shared `link`, the `output` and `state` files, and `failedNotifications`: the wallet messages that failed, each with its `row`, `depotId` and the Hub's `error`. When the load stops, `load` has an `error` with its `message` and the refused rows' `errors`, and no `link`, `output` or `failedNotifications`.
|
|
289
|
+
|
|
290
|
+
## Example
|
|
291
|
+
|
|
292
|
+
`test/fixtures` has a spec, a CSV and an Open Badge template:
|
|
293
|
+
|
|
294
|
+
```sh
|
|
295
|
+
batch-issuer validate test/fixtures/spec.yaml test/fixtures/holders.csv \
|
|
296
|
+
--endpoint https://hub.example.com --network testnet --registrar https://registrar.example.com
|
|
297
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verii/batch-issuer",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Loads Credentialing Hub depots and credentials from a CSV file, a YAML spec and JSON Handlebars templates",
|
|
5
|
+
"repository": "https://github.com/LFDT-Verii/core",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"batch-issuer": "src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"author": "Andres Olave",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"ajv": "8.20.0",
|
|
17
|
+
"ajv-formats": "3.0.1",
|
|
18
|
+
"commander": "~15.0.0",
|
|
19
|
+
"csv-parse": "^7.0.3",
|
|
20
|
+
"csv-stringify": "^6.9.0",
|
|
21
|
+
"handlebars": "^4.7.10",
|
|
22
|
+
"libphonenumber-js": "^1.13.15",
|
|
23
|
+
"lodash": "^4.18.1",
|
|
24
|
+
"yaml": "^2.9.1",
|
|
25
|
+
"@verii/common-fetchers": "1.3.0",
|
|
26
|
+
"@verii/common-functions": "1.3.0",
|
|
27
|
+
"@verii/credentialing-hub-operator-api": "1.3.0",
|
|
28
|
+
"@verii/validation": "1.3.0",
|
|
29
|
+
"@verii/vc-checks": "1.3.0",
|
|
30
|
+
"@verii/jwt": "1.3.0",
|
|
31
|
+
"@verii/http-client": "1.3.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"eslint": "9.39.5",
|
|
35
|
+
"eslint-config-airbnb-extended": "3.3.0",
|
|
36
|
+
"eslint-config-prettier": "10.1.8",
|
|
37
|
+
"eslint-plugin-better-mutation": "2.1.0",
|
|
38
|
+
"eslint-plugin-import": "2.32.0",
|
|
39
|
+
"eslint-plugin-prefer-arrow-functions": "3.10.2",
|
|
40
|
+
"eslint-plugin-prettier": "5.5.7",
|
|
41
|
+
"eslint-watch": "8.0.0",
|
|
42
|
+
"expect": "30.5.2",
|
|
43
|
+
"nock": "15.0.5",
|
|
44
|
+
"prettier": "3.9.10"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "cross-env NODE_ENV=test node --test --test-concurrency=1 --experimental-test-module-mocks --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout 'test/**/*.test.js'",
|
|
48
|
+
"test:ci": "cross-env NODE_ENV=test node --test --test-concurrency=1 --experimental-test-module-mocks --experimental-test-coverage --test-coverage-include='src/**' --test-reporter=spec --test-reporter=junit --test-reporter-destination=stdout --test-reporter-destination=test-results.junit.xml --test-reporter=lcov --test-reporter-destination=lcov.info 'test/**/*.test.js'",
|
|
49
|
+
"lint": "eslint .",
|
|
50
|
+
"lint:ci": "eslint . --format json >> eslint-results.json",
|
|
51
|
+
"lint:fix": "eslint --fix ."
|
|
52
|
+
}
|
|
6
53
|
}
|