@learncard/credential-library 1.0.2

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.
Files changed (93) hide show
  1. package/README.md +260 -0
  2. package/dist/__tests__/issuance.test.d.ts +2 -0
  3. package/dist/__tests__/issuance.test.d.ts.map +1 -0
  4. package/dist/__tests__/registry.test.d.ts +2 -0
  5. package/dist/__tests__/registry.test.d.ts.map +1 -0
  6. package/dist/credential-library.cjs.development.js +11095 -0
  7. package/dist/credential-library.cjs.development.js.map +7 -0
  8. package/dist/credential-library.cjs.production.min.js +2 -0
  9. package/dist/credential-library.cjs.production.min.js.map +7 -0
  10. package/dist/credential-library.esm.js +11074 -0
  11. package/dist/credential-library.esm.js.map +7 -0
  12. package/dist/fixtures/boost/basic.d.ts +3 -0
  13. package/dist/fixtures/boost/basic.d.ts.map +1 -0
  14. package/dist/fixtures/boost/boost-id.d.ts +3 -0
  15. package/dist/fixtures/boost/boost-id.d.ts.map +1 -0
  16. package/dist/fixtures/boost/community-award.d.ts +3 -0
  17. package/dist/fixtures/boost/community-award.d.ts.map +1 -0
  18. package/dist/fixtures/boost/delegate.d.ts +3 -0
  19. package/dist/fixtures/boost/delegate.d.ts.map +1 -0
  20. package/dist/fixtures/boost/with-skills.d.ts +3 -0
  21. package/dist/fixtures/boost/with-skills.d.ts.map +1 -0
  22. package/dist/fixtures/clr/great-plains-full.d.ts +3 -0
  23. package/dist/fixtures/clr/great-plains-full.d.ts.map +1 -0
  24. package/dist/fixtures/clr/minimal.d.ts +3 -0
  25. package/dist/fixtures/clr/minimal.d.ts.map +1 -0
  26. package/dist/fixtures/clr/multi-achievement.d.ts +3 -0
  27. package/dist/fixtures/clr/multi-achievement.d.ts.map +1 -0
  28. package/dist/fixtures/clr/nd-student-transcript.d.ts +3 -0
  29. package/dist/fixtures/clr/nd-student-transcript.d.ts.map +1 -0
  30. package/dist/fixtures/clr/university-transcript.d.ts +3 -0
  31. package/dist/fixtures/clr/university-transcript.d.ts.map +1 -0
  32. package/dist/fixtures/index.d.ts +39 -0
  33. package/dist/fixtures/index.d.ts.map +1 -0
  34. package/dist/fixtures/invalid/empty-type.d.ts +3 -0
  35. package/dist/fixtures/invalid/empty-type.d.ts.map +1 -0
  36. package/dist/fixtures/invalid/missing-context.d.ts +3 -0
  37. package/dist/fixtures/invalid/missing-context.d.ts.map +1 -0
  38. package/dist/fixtures/invalid/missing-issuer.d.ts +3 -0
  39. package/dist/fixtures/invalid/missing-issuer.d.ts.map +1 -0
  40. package/dist/fixtures/obv3/1edtech-full.d.ts +3 -0
  41. package/dist/fixtures/obv3/1edtech-full.d.ts.map +1 -0
  42. package/dist/fixtures/obv3/course-completion.d.ts +3 -0
  43. package/dist/fixtures/obv3/course-completion.d.ts.map +1 -0
  44. package/dist/fixtures/obv3/endorsement.d.ts +3 -0
  45. package/dist/fixtures/obv3/endorsement.d.ts.map +1 -0
  46. package/dist/fixtures/obv3/full-badge.d.ts +3 -0
  47. package/dist/fixtures/obv3/full-badge.d.ts.map +1 -0
  48. package/dist/fixtures/obv3/k12-diploma.d.ts +3 -0
  49. package/dist/fixtures/obv3/k12-diploma.d.ts.map +1 -0
  50. package/dist/fixtures/obv3/micro-credential.d.ts +3 -0
  51. package/dist/fixtures/obv3/micro-credential.d.ts.map +1 -0
  52. package/dist/fixtures/obv3/minimal-badge.d.ts +3 -0
  53. package/dist/fixtures/obv3/minimal-badge.d.ts.map +1 -0
  54. package/dist/fixtures/obv3/plugfest-jff2.d.ts +3 -0
  55. package/dist/fixtures/obv3/plugfest-jff2.d.ts.map +1 -0
  56. package/dist/fixtures/obv3/professional-cert.d.ts +3 -0
  57. package/dist/fixtures/obv3/professional-cert.d.ts.map +1 -0
  58. package/dist/fixtures/obv3/with-alignment.d.ts +3 -0
  59. package/dist/fixtures/obv3/with-alignment.d.ts.map +1 -0
  60. package/dist/fixtures/obv3/with-endorsement.d.ts +3 -0
  61. package/dist/fixtures/obv3/with-endorsement.d.ts.map +1 -0
  62. package/dist/fixtures/vc-v1/alumni-credential.d.ts +3 -0
  63. package/dist/fixtures/vc-v1/alumni-credential.d.ts.map +1 -0
  64. package/dist/fixtures/vc-v1/basic.d.ts +3 -0
  65. package/dist/fixtures/vc-v1/basic.d.ts.map +1 -0
  66. package/dist/fixtures/vc-v1/with-status.d.ts +3 -0
  67. package/dist/fixtures/vc-v1/with-status.d.ts.map +1 -0
  68. package/dist/fixtures/vc-v2/basic.d.ts +3 -0
  69. package/dist/fixtures/vc-v2/basic.d.ts.map +1 -0
  70. package/dist/fixtures/vc-v2/digital-id.d.ts +3 -0
  71. package/dist/fixtures/vc-v2/digital-id.d.ts.map +1 -0
  72. package/dist/fixtures/vc-v2/education-degree.d.ts +3 -0
  73. package/dist/fixtures/vc-v2/education-degree.d.ts.map +1 -0
  74. package/dist/fixtures/vc-v2/employment-credential.d.ts +3 -0
  75. package/dist/fixtures/vc-v2/employment-credential.d.ts.map +1 -0
  76. package/dist/fixtures/vc-v2/license-credential.d.ts +3 -0
  77. package/dist/fixtures/vc-v2/license-credential.d.ts.map +1 -0
  78. package/dist/fixtures/vc-v2/membership-credential.d.ts +3 -0
  79. package/dist/fixtures/vc-v2/membership-credential.d.ts.map +1 -0
  80. package/dist/fixtures/vc-v2/multiple-subjects.d.ts +3 -0
  81. package/dist/fixtures/vc-v2/multiple-subjects.d.ts.map +1 -0
  82. package/dist/fixtures/vc-v2/with-evidence.d.ts +3 -0
  83. package/dist/fixtures/vc-v2/with-evidence.d.ts.map +1 -0
  84. package/dist/index.d.ts +8 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +7 -0
  87. package/dist/prepare.d.ts +49 -0
  88. package/dist/prepare.d.ts.map +1 -0
  89. package/dist/registry.d.ts +23 -0
  90. package/dist/registry.d.ts.map +1 -0
  91. package/dist/types.d.ts +58 -0
  92. package/dist/types.d.ts.map +1 -0
  93. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,260 @@
1
+ # @learncard/credential-library
2
+
3
+ A comprehensive, queryable library of Verifiable Credential fixtures for testing, development, and regression prevention across the VC ecosystem.
4
+
5
+ ## Why?
6
+
7
+ The Verifiable Credential standard is infinitely customizable and always evolving. LearnCard adds enhanced support for specific schemas (OBv3, CLR v2, Boosts, etc.), and testing all flows (claiming, viewing, sharing, verifying) requires a diverse set of credential examples.
8
+
9
+ This package provides:
10
+
11
+ - **Real and synthetic credential fixtures** spanning VC v1, v2, OBv3, CLR v2, and LearnCard Boosts
12
+ - **Rich metadata** per fixture: spec, profile, features exercised, source, validity
13
+ - **Queryable API** to filter fixtures by any combination of metadata
14
+ - **Fixture preparation** for real issuance — patch in DIDs, timestamps, and fresh UUIDs
15
+ - **Self-validating test suite** that ensures every fixture passes its declared Zod validator
16
+ - **Issuance integration tests** that verify every valid fixture can be issued by a real LearnCard wallet
17
+ - **Intentionally invalid fixtures** for negative testing
18
+ - **One-file-per-fixture** pattern that makes it trivial to add new credentials
19
+
20
+ ## Quick Start
21
+
22
+ ### Querying Fixtures
23
+
24
+ ```typescript
25
+ import {
26
+ getAllFixtures,
27
+ getFixtures,
28
+ getFixture,
29
+ findFixture,
30
+ getValidFixtures,
31
+ getInvalidFixtures,
32
+ getUnsignedFixtures,
33
+ getSignedFixtures,
34
+ getStats,
35
+ } from '@learncard/credential-library';
36
+
37
+ // All fixtures
38
+ const all = getAllFixtures();
39
+
40
+ // Only OBv3 badges
41
+ const badges = getFixtures({ spec: 'obv3', profile: 'badge' });
42
+
43
+ // Fixtures with evidence AND alignment
44
+ const rich = getFixtures({ features: ['evidence', 'alignment'] });
45
+
46
+ // Fixtures with ANY of these features
47
+ const interesting = getFixtures({ featuresAny: ['skills', 'endorsement', 'nested-credentials'] });
48
+
49
+ // One specific fixture (throws if not found)
50
+ const jff = getFixture('obv3/plugfest-jff2');
51
+
52
+ // One specific fixture (returns undefined if not found)
53
+ const maybe = findFixture('obv3/does-not-exist');
54
+
55
+ // Only valid / only invalid
56
+ const valid = getValidFixtures();
57
+ const invalid = getInvalidFixtures();
58
+
59
+ // Stats breakdown
60
+ const stats = getStats();
61
+ // => { total, bySpec, byProfile, byValidity, signed, unsigned }
62
+ ```
63
+
64
+ ### Issuing Fixtures with a LearnCard Wallet
65
+
66
+ ```typescript
67
+ import { getFixture, prepareFixture, prepareFixtureById } from '@learncard/credential-library';
68
+ import { initLearnCard } from '@learncard/init';
69
+
70
+ const wallet = await initLearnCard({ seed: '...' });
71
+ const issuerDid = wallet.id.did();
72
+
73
+ // Option A: get fixture, then prepare
74
+ const fixture = getFixture('obv3/full-badge');
75
+ const unsigned = prepareFixture(fixture, {
76
+ issuerDid,
77
+ subjectDid: 'did:example:recipient',
78
+ });
79
+
80
+ // Option B: one-liner with prepareFixtureById
81
+ const unsigned2 = prepareFixtureById('boost/basic', { issuerDid });
82
+
83
+ // Issue the credential
84
+ const signed = await wallet.invoke.issueCredential(unsigned);
85
+ ```
86
+
87
+ `prepareFixture` deep-clones the fixture and patches:
88
+
89
+ - **Issuer DID** — replaces the placeholder issuer with your wallet's DID
90
+ - **Subject DID** — optionally replaces the subject DID
91
+ - **Fresh UUIDs** — regenerates all `urn:uuid:` ids (disable with `freshIds: false`)
92
+ - **Timestamps** — sets `validFrom`/`issuanceDate` to now (or a custom value)
93
+
94
+ ## Query API Reference
95
+
96
+ | Function | Description |
97
+ |----------|-------------|
98
+ | `getAllFixtures()` | Returns all registered fixtures |
99
+ | `getFixture(id)` | Returns a fixture by ID (throws if not found) |
100
+ | `findFixture(id)` | Returns a fixture by ID (returns `undefined` if not found) |
101
+ | `getFixtures(filter)` | Returns fixtures matching the filter |
102
+ | `getValidFixtures(filter?)` | Shorthand for `getFixtures({ ...filter, validity: 'valid' })` |
103
+ | `getInvalidFixtures(filter?)` | Shorthand for `getFixtures({ ...filter, validity: ['invalid', 'tampered'] })` |
104
+ | `getUnsignedFixtures(filter?)` | Returns only unsigned fixtures |
105
+ | `getSignedFixtures(filter?)` | Returns only signed fixtures |
106
+ | `getStats()` | Returns counts grouped by spec, profile, validity, and signed status |
107
+ | `prepareFixture(fixture, options)` | Clones a fixture and patches DIDs, UUIDs, and timestamps |
108
+ | `prepareFixtureById(id, options)` | Combines `getFixture` + `prepareFixture` |
109
+
110
+ ### FixtureFilter
111
+
112
+ All filter fields are optional. Array fields accept a single value or an array.
113
+
114
+ | Field | Type | Behavior |
115
+ |-------|------|----------|
116
+ | `spec` | `CredentialSpec \| CredentialSpec[]` | Match any of the given specs |
117
+ | `profile` | `CredentialProfile \| CredentialProfile[]` | Match any of the given profiles |
118
+ | `features` | `CredentialFeature[]` | Must have **all** of these features |
119
+ | `featuresAny` | `CredentialFeature[]` | Must have **any** of these features |
120
+ | `signed` | `boolean` | Filter by signed status |
121
+ | `validity` | `FixtureValidity \| FixtureValidity[]` | Match any of the given validities |
122
+ | `source` | `FixtureSource \| FixtureSource[]` | Match any of the given sources |
123
+ | `tags` | `string[]` | Must have **all** of these tags |
124
+
125
+ ## Adding a Fixture
126
+
127
+ ### Option 1: Create a file manually
128
+
129
+ 1. Create a file in `src/fixtures/<spec-dir>/my-fixture.ts`:
130
+
131
+ ```typescript
132
+ import type { CredentialFixture } from '../../types';
133
+
134
+ export const myFixture: CredentialFixture = {
135
+ id: 'vc-v2/my-fixture',
136
+ name: 'My New Fixture',
137
+ description: 'What this fixture tests or demonstrates',
138
+ spec: 'vc-v2',
139
+ profile: 'generic',
140
+ features: [],
141
+ source: 'synthetic',
142
+ signed: false,
143
+ validity: 'valid',
144
+ credential: {
145
+ '@context': ['https://www.w3.org/ns/credentials/v2'],
146
+ type: ['VerifiableCredential'],
147
+ issuer: 'did:example:issuer',
148
+ validFrom: '2024-01-01T00:00:00Z',
149
+ credentialSubject: { id: 'did:example:subject' },
150
+ },
151
+ };
152
+ ```
153
+
154
+ 2. Add the import and registration in `src/fixtures/index.ts`
155
+
156
+ 3. Run `pnpm test` — both the self-validating and issuance suites will check your fixture automatically
157
+
158
+ ### Option 2: Use the Credential Viewer UI
159
+
160
+ The `examples/credential-viewer` app has a **New Fixture** button that provides a form with:
161
+
162
+ - JSON editor with metadata auto-inference
163
+ - JSON file upload
164
+ - Test Issue button (requires wallet connection)
165
+ - Saves the `.ts` file and updates the index automatically
166
+
167
+ See the [Credential Viewer README](../../examples/credential-viewer/README.md) for details.
168
+
169
+ ## Fixture Metadata
170
+
171
+ | Field | Type | Description |
172
+ |-------|------|-------------|
173
+ | `id` | `string` | Unique identifier, e.g. `obv3/minimal-badge` |
174
+ | `name` | `string` | Human-readable name |
175
+ | `description` | `string` | What this fixture tests/demonstrates |
176
+ | `spec` | `CredentialSpec` | `vc-v1`, `vc-v2`, `obv3`, `clr-v2`, `europass`, `custom` |
177
+ | `profile` | `CredentialProfile` | `badge`, `diploma`, `certificate`, `id`, `membership`, `license`, `micro-credential`, `course`, `degree`, `boost`, `boost-id`, `delegate`, `endorsement`, `learner-record`, `generic` |
178
+ | `features` | `CredentialFeature[]` | Features exercised: `evidence`, `alignment`, `endorsement`, `expiration`, `status`, `multiple-subjects`, `image`, `results`, `skills`, `display`, `associations`, `nested-credentials`, etc. |
179
+ | `source` | `FixtureSource` | `spec-example`, `plugfest`, `real-world`, `synthetic` |
180
+ | `signed` | `boolean` | Whether the credential has a proof |
181
+ | `validity` | `FixtureValidity` | `valid`, `invalid`, or `tampered` |
182
+ | `validator` | `z.ZodType?` | Optional Zod validator from `@learncard/types` |
183
+ | `tags` | `string[]?` | Additional free-form tags for ad-hoc filtering |
184
+
185
+ ## Available Fixtures
186
+
187
+ ### VC v1 (3)
188
+ - `vc-v1/basic` — Minimal VCDM v1 credential
189
+ - `vc-v1/with-status` — With StatusList2021 credential status
190
+ - `vc-v1/alumni-credential` — University alumni credential
191
+
192
+ ### VC v2 (8)
193
+ - `vc-v2/basic` — Minimal VCDM v2 credential
194
+ - `vc-v2/with-evidence` — With evidence array
195
+ - `vc-v2/multiple-subjects` — With multiple credential subjects
196
+ - `vc-v2/employment-credential` — Employment verification credential
197
+ - `vc-v2/education-degree` — University bachelor degree credential
198
+ - `vc-v2/digital-id` — Government digital identity credential
199
+ - `vc-v2/membership-credential` — Professional association membership
200
+ - `vc-v2/license-credential` — Professional nursing license
201
+
202
+ ### Open Badges v3 (11)
203
+ - `obv3/minimal-badge` — Minimal OBv3 achievement credential
204
+ - `obv3/full-badge` — Full-featured badge with image, evidence, alignment, results, expiration
205
+ - `obv3/with-alignment` — With competency framework alignments
206
+ - `obv3/with-endorsement` — With embedded endorsement credential
207
+ - `obv3/plugfest-jff2` — JFF PlugFest 2 interoperability badge
208
+ - `obv3/1edtech-full` — 1EdTech complete OpenBadgeCredential (spec reference)
209
+ - `obv3/professional-cert` — AWS Solutions Architect professional certification
210
+ - `obv3/micro-credential` — Data Science Fundamentals micro-credential
211
+ - `obv3/course-completion` — Introduction to Machine Learning course completion
212
+ - `obv3/k12-diploma` — High school diploma
213
+ - `obv3/endorsement-credential` — Program accreditation endorsement
214
+
215
+ ### CLR v2 (4)
216
+ - `clr/minimal` — Minimal Comprehensive Learner Record
217
+ - `clr/multi-achievement` — Multiple achievements with associations
218
+ - `clr/nd-student-transcript` — North Dakota student transcript (nested VCs, real-world structure)
219
+ - `clr/university-transcript` — University academic transcript (6 nested course VCs)
220
+
221
+ ### LearnCard Boosts (5)
222
+ - `boost/basic` — Basic BoostCredential with display
223
+ - `boost/boost-id` — BoostID membership card
224
+ - `boost/with-skills` — Boost with skills, evidence, and alignment
225
+ - `boost/community-award` — Community leadership award boost
226
+ - `boost/delegate` — Organization delegate credential
227
+
228
+ ### Invalid / Negative Tests (3)
229
+ - `invalid/missing-context` — No @context
230
+ - `invalid/empty-type` — Empty type array
231
+ - `invalid/missing-issuer` — No issuer field
232
+
233
+ ## Tests
234
+
235
+ ```bash
236
+ pnpm test
237
+ ```
238
+
239
+ Two test suites run automatically:
240
+
241
+ - **`registry.test.ts`** — Validates every fixture against its Zod validator, checks metadata consistency, and tests the query/filter API
242
+ - **`issuance.test.ts`** — Creates a real LearnCard wallet instance and calls `issueCredential()` on every valid fixture, verifying that each produces a signed VC with a proof
243
+
244
+ ### Bundle Size & Production Use
245
+
246
+ This package is designed for **testing, development, and CI** — not for inclusion in production application bundles. The fixture data is intentionally large and comprehensive.
247
+
248
+ - The package declares `"sideEffects": false` so bundlers can tree-shake unused fixtures
249
+ - The credential-viewer (`examples/credential-viewer/`) is `private: true` and not published
250
+ - If you only need a few fixtures in a test file, import them directly: `import { obv3MinimalBadge } from '@learncard/credential-library'`
251
+ - Avoid importing the full library in production application code paths
252
+
253
+ ### JSON-LD Context Notes
254
+
255
+ All valid fixtures use `@context` URLs that are either statically cached in DidKit or fetchable via `allowRemoteContexts`. If you add a fixture with custom terms, make sure they are defined in one of the included contexts. Common choices:
256
+
257
+ - `https://www.w3.org/2018/credentials/examples/v1` — Example terms for VC v1 (`degree`, `alumniOf`, etc.)
258
+ - `https://www.w3.org/ns/credentials/examples/v2` — Example terms for VC v2 (`degree`, `role`, etc.)
259
+ - `https://purl.imsglobal.org/spec/ob/v3p0/context-3.0.3.json` — OBv3 terms (cached in DidKit)
260
+ - `https://purl.imsglobal.org/spec/clr/v2p0/context.json` — CLR v2 terms (cached in DidKit)
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=issuance.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issuance.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/issuance.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=registry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/registry.test.ts"],"names":[],"mappings":""}