@learncard/ler-rs-plugin 0.1.15 → 0.1.16

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/package.json CHANGED
@@ -1,57 +1,59 @@
1
1
  {
2
- "name": "@learncard/ler-rs-plugin",
3
- "version": "0.1.15",
4
- "description": "LER-RS plugin for LearnCard: create, package, and verify Learning & Employment Record Resumes",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/ler-rs-plugin.esm.js",
8
- "exports": {
9
- ".": {
10
- "import": {
11
- "types": "./dist/index.d.ts",
12
- "default": "./dist/ler-rs-plugin.esm.js"
13
- },
14
- "require": {
15
- "types": "./dist/index.d.cts",
16
- "default": "./dist/index.cjs"
17
- }
2
+ "name": "@learncard/ler-rs-plugin",
3
+ "version": "0.1.16",
4
+ "description": "LER-RS plugin for LearnCard: create, package, and verify Learning & Employment Record Resumes",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/ler-rs-plugin.esm.js",
8
+ "exports": {
9
+ ".": {
10
+ "development": "./src/index.ts",
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/ler-rs-plugin.esm.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src"
24
+ ],
25
+ "scripts": {
26
+ "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
27
+ "test": "jest --passWithNoTests",
28
+ "test:watch": "jest --watch",
29
+ "test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
30
+ },
31
+ "author": "Learning Economy Foundation (www.learningeconomy.io)",
32
+ "license": "MIT",
33
+ "homepage": "https://github.com/learningeconomy/LearnCard#readme",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/learningeconomy/LearnCard.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/learningeconomy/LearnCard/issues"
40
+ },
41
+ "devDependencies": {
42
+ "@types/jest": "^29.2.2",
43
+ "@types/node": "^17.0.31",
44
+ "aqu": "0.4.3",
45
+ "esbuild": "^0.14.38",
46
+ "esbuild-jest": "^0.5.0",
47
+ "esbuild-plugin-copy": "^1.3.0",
48
+ "jest": "^29.3.0",
49
+ "rimraf": "^3.0.2",
50
+ "shx": "^0.3.4",
51
+ "ts-jest": "^29.0.3"
52
+ },
53
+ "types": "./dist/index.d.ts",
54
+ "dependencies": {
55
+ "@learncard/core": "workspace:*",
56
+ "@learncard/types": "workspace:*",
57
+ "@learncard/vc-plugin": "workspace:*"
18
58
  }
19
- },
20
- "files": [
21
- "dist"
22
- ],
23
- "author": "Learning Economy Foundation (www.learningeconomy.io)",
24
- "license": "MIT",
25
- "homepage": "https://github.com/learningeconomy/LearnCard#readme",
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/learningeconomy/LearnCard.git"
29
- },
30
- "bugs": {
31
- "url": "https://github.com/learningeconomy/LearnCard/issues"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^29.2.2",
35
- "@types/node": "^17.0.31",
36
- "aqu": "0.4.3",
37
- "esbuild": "^0.14.38",
38
- "esbuild-jest": "^0.5.0",
39
- "esbuild-plugin-copy": "^1.3.0",
40
- "jest": "^29.3.0",
41
- "rimraf": "^3.0.2",
42
- "shx": "^0.3.4",
43
- "ts-jest": "^29.0.3"
44
- },
45
- "types": "./dist/index.d.ts",
46
- "dependencies": {
47
- "@learncard/core": "9.4.24",
48
- "@learncard/vc-plugin": "1.5.4",
49
- "@learncard/types": "5.17.4"
50
- },
51
- "scripts": {
52
- "build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.cjs && tsc --p tsconfig.json && shx cp ./dist/index.d.ts ./dist/index.d.cts",
53
- "test": "jest --passWithNoTests",
54
- "test:watch": "jest --watch",
55
- "test:coverage": "jest --silent --ci --coverage --coverageReporters=\"text\" --coverageReporters=\"text-summary\""
56
- }
57
- }
59
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { getLerRsPlugin } from './ler-rs';
2
+ export * from './types';
package/src/ler-rs.ts ADDED
@@ -0,0 +1,554 @@
1
+ import {
2
+ VC as VerifiableCredential,
3
+ UnsignedVC,
4
+ VP as VerifiablePresentation,
5
+ UnsignedVP,
6
+ } from '@learncard/types';
7
+ import {
8
+ LERRSDependentLearnCard,
9
+ LERRSPlugin,
10
+ CreateLerRecordParams,
11
+ CreateLerPresentationParams,
12
+ VerifyLerPresentationParams,
13
+ VerificationResult,
14
+ LerRsRecord,
15
+ LER_RS_CREDENTIAL_CONTEXT_V2,
16
+ LER_RS_TYPE_URI_V45,
17
+ LEGACY_LER_RS_TYPE_URI_V44,
18
+ LEGACY_LER_RS_TYPE_TOKEN,
19
+ TCP_WRAPPER_TYPE,
20
+ } from './types';
21
+
22
+ /**
23
+ * Normalizes verification containers from either:
24
+ * - `verifications: VC[]`
25
+ * - `verifiableCredential: VC`
26
+ */
27
+ const getItemVerifications = (item: {
28
+ verifiableCredential?: VerifiableCredential;
29
+ verifications?: VerifiableCredential[];
30
+ }): VerifiableCredential[] => {
31
+ if (item.verifications?.length) return item.verifications;
32
+ if (item.verifiableCredential) return [item.verifiableCredential];
33
+ return [];
34
+ };
35
+
36
+ /**
37
+ * Converts scalar-or-array values into a normalized array.
38
+ */
39
+ const toArray = <T>(maybe: T | T[] | undefined): T[] =>
40
+ maybe == null ? [] : Array.isArray(maybe) ? maybe : [maybe];
41
+
42
+ /**
43
+ * Inline LER-RS JSON-LD context used for signing stability.
44
+ *
45
+ * The published HR Open URL is schema-oriented and can trigger additional remote
46
+ * context resolution during expansion. Inlining this base context avoids network
47
+ * dependency at issue time while preserving deterministic term expansion.
48
+ */
49
+ const inlineLerRsContext = {
50
+ '@version': 1.1,
51
+ hrrec: 'http://schema.hropenstandards.org/recruiting/',
52
+ '@vocab': 'http://schema.hropenstandards.org/recruiting/',
53
+ };
54
+
55
+ /**
56
+ * Determines whether a VC represents a LER-RS credential (legacy and current forms).
57
+ *
58
+ * Checks:
59
+ * - VC `type` array/token values
60
+ * - `credentialSubject.type`
61
+ * - nested `credentialSubject.lerrsType.type`
62
+ */
63
+ const credentialHasLerRsType = (credential: VerifiableCredential): boolean => {
64
+ const typeList = Array.isArray(credential.type) ? credential.type : [credential.type];
65
+ if (
66
+ typeList.some(type =>
67
+ [LEGACY_LER_RS_TYPE_TOKEN, LEGACY_LER_RS_TYPE_URI_V44, LER_RS_TYPE_URI_V45].includes(
68
+ type
69
+ )
70
+ )
71
+ )
72
+ return true;
73
+
74
+ const credentialSubject = credential.credentialSubject as Record<string, unknown> | undefined;
75
+ if (!credentialSubject) return false;
76
+
77
+ const inlineType = credentialSubject.type;
78
+ if (
79
+ typeof inlineType === 'string' &&
80
+ [LEGACY_LER_RS_TYPE_URI_V44, LER_RS_TYPE_URI_V45].includes(inlineType)
81
+ )
82
+ return true;
83
+
84
+ const nestedType = (credentialSubject.lerrsType as Record<string, unknown> | undefined)?.type;
85
+ return (
86
+ typeof nestedType === 'string' &&
87
+ [LEGACY_LER_RS_TYPE_URI_V44, LER_RS_TYPE_URI_V45].includes(nestedType)
88
+ );
89
+ };
90
+
91
+ /**
92
+ * Maps application work history items to LER-RS `employmentHistories` shape.
93
+ */
94
+ const buildEmploymentHistories = (
95
+ items: NonNullable<CreateLerRecordParams['workHistory']>
96
+ ): LerRsRecord['employmentHistories'] => {
97
+ return items.map(item => {
98
+ const {
99
+ narrative,
100
+ descriptions,
101
+ verifiableCredential,
102
+ verifications,
103
+ position,
104
+ employer,
105
+ start,
106
+ end,
107
+ current,
108
+ ...rest
109
+ } = item;
110
+
111
+ const container: Record<string, unknown> = { ...rest };
112
+ if (typeof current === 'boolean') container.current = current;
113
+
114
+ if (employer) container.organization = { tradeName: employer };
115
+ if (position || start || end || typeof current === 'boolean') {
116
+ const ph: Record<string, unknown> = {};
117
+ if (position) ph.title = position;
118
+ if (start) ph.start = start;
119
+ if (end) ph.end = end;
120
+ if (typeof current === 'boolean') ph.current = current;
121
+ if (descriptions?.length) ph.descriptions = descriptions;
122
+ container.positionHistories = [ph];
123
+ }
124
+ if (narrative) container.narrative = narrative;
125
+ if (descriptions?.length && !container.positionHistories) container.descriptions = descriptions;
126
+
127
+ const containerVerifications = getItemVerifications({
128
+ verifiableCredential,
129
+ verifications,
130
+ });
131
+ return {
132
+ ...container,
133
+ ...(containerVerifications.length ? { verifications: containerVerifications } : {}),
134
+ };
135
+ });
136
+ };
137
+
138
+ /**
139
+ * Maps education source items into LER-RS `educationAndLearnings`.
140
+ */
141
+ const buildEducationAndLearnings = (
142
+ items: NonNullable<CreateLerRecordParams['educationHistory']>
143
+ ): LerRsRecord['educationAndLearnings'] => {
144
+ return items.map(item => {
145
+ const {
146
+ narrative,
147
+ descriptions,
148
+ verifiableCredential,
149
+ verifications,
150
+ institution,
151
+ start,
152
+ end,
153
+ current,
154
+ degree,
155
+ specializations,
156
+ ...rest
157
+ } = item;
158
+
159
+ const container: Record<string, unknown> = { ...rest };
160
+ if (institution) container.institution = { name: institution };
161
+ if (start) container.start = start;
162
+ if (end) container.end = end;
163
+ if (typeof current === 'boolean') container.current = current;
164
+ if (descriptions?.length) container.descriptions = descriptions;
165
+ if (degree || specializations) {
166
+ container.educationDegrees = [
167
+ {
168
+ ...(degree ? { name: degree } : {}),
169
+ ...(specializations
170
+ ? {
171
+ specializations: specializations.map(specialization => ({
172
+ name: specialization,
173
+ })),
174
+ }
175
+ : {}),
176
+ },
177
+ ];
178
+ }
179
+ if (narrative) container.narrative = narrative;
180
+
181
+ const containerVerifications = getItemVerifications({
182
+ verifiableCredential,
183
+ verifications,
184
+ });
185
+ return {
186
+ ...container,
187
+ ...(containerVerifications.length ? { verifications: containerVerifications } : {}),
188
+ };
189
+ });
190
+ };
191
+
192
+ /**
193
+ * Maps certification source items to LER-RS `certifications`.
194
+ */
195
+ const buildCertifications = (
196
+ items: NonNullable<CreateLerRecordParams['certifications']>
197
+ ): LerRsRecord['certifications'] => {
198
+ return items.map(item => {
199
+ const {
200
+ narrative,
201
+ descriptions,
202
+ start,
203
+ end,
204
+ effectiveTimePeriod,
205
+ verifiableCredential,
206
+ verifications,
207
+ ...rest
208
+ } = item;
209
+
210
+ const container: Record<string, unknown> = { ...rest };
211
+ if (narrative) container.narrative = narrative;
212
+ if (descriptions?.length) container.descriptions = descriptions;
213
+ if (effectiveTimePeriod || start || end) {
214
+ container.effectiveTimePeriod = {
215
+ ...(effectiveTimePeriod ?? {}),
216
+ ...(start ? { validFrom: start } : {}),
217
+ ...(end ? { validTo: end } : {}),
218
+ };
219
+ }
220
+
221
+ const containerVerifications = getItemVerifications({
222
+ verifiableCredential,
223
+ verifications,
224
+ });
225
+ return {
226
+ ...container,
227
+ ...(containerVerifications.length ? { verifications: containerVerifications } : {}),
228
+ };
229
+ });
230
+ };
231
+
232
+ /**
233
+ * Returns the LearnCard LER-RS plugin with methods for:
234
+ * - issuing LER-RS VCs
235
+ * - packaging/verifying LER presentations
236
+ * - issuing TCP wrapper VCs for resume packages
237
+ */
238
+ export const getLerRsPlugin = (initLearnCard: LERRSDependentLearnCard): LERRSPlugin => {
239
+ return {
240
+ name: 'LER-RS',
241
+ displayName: 'LER-RS',
242
+ description:
243
+ 'Create, package, and verify Learning & Employment Record Resume (LER-RS) credentials',
244
+ methods: {
245
+ /**
246
+ * Issues a signed LER-RS VC from normalized person/work/education/certification data.
247
+ *
248
+ * The method:
249
+ * 1. Builds a compliant LER-RS `credentialSubject`
250
+ * 2. Applies VC + LER-RS contexts
251
+ * 3. Signs via `invoke.issueCredential`
252
+ */
253
+ createLerRecord: async (_learnCard, params): Promise<VerifiableCredential> => {
254
+ const signer = params.learnCard ?? _learnCard;
255
+ const did = signer.id.did();
256
+ const issuedAt = new Date().toISOString();
257
+ const documentId = crypto.randomUUID();
258
+
259
+ const personSection: LerRsRecord['person'] = {
260
+ name: {
261
+ given: params.person.givenName,
262
+ family: params.person.familyName,
263
+ formattedName:
264
+ params.person.formattedName ??
265
+ `${params.person.givenName} ${params.person.familyName}`,
266
+ },
267
+ };
268
+
269
+ const hasAddress =
270
+ !!params.person.address?.formattedAddress ||
271
+ !!params.person.address?.line ||
272
+ !!params.person.address?.city ||
273
+ !!params.person.address?.postalCode ||
274
+ !!params.person.address?.countryCode;
275
+ const webEntries = (params.person.web || []).filter(entry => entry?.url);
276
+ const socialEntries = (params.person.social || []).filter(entry => entry?.uri);
277
+
278
+ const communication: LerRsRecord['communication'] | undefined =
279
+ params.person.email ||
280
+ params.person.phone ||
281
+ hasAddress ||
282
+ webEntries.length > 0 ||
283
+ socialEntries.length > 0
284
+ ? {
285
+ ...(params.person.email
286
+ ? { email: [{ address: params.person.email }] }
287
+ : {}),
288
+ ...(params.person.phone
289
+ ? { phone: [{ formattedNumber: params.person.phone }] }
290
+ : {}),
291
+ ...(webEntries.length
292
+ ? { web: webEntries.map(entry => ({ url: entry.url, name: entry.name })) }
293
+ : {}),
294
+ ...(socialEntries.length
295
+ ? {
296
+ social: socialEntries.map(entry => ({
297
+ uri: entry.uri,
298
+ ...(entry.name ? { name: entry.name } : {}),
299
+ })),
300
+ }
301
+ : {}),
302
+ ...(hasAddress
303
+ ? {
304
+ address: [
305
+ {
306
+ ...(params.person.address?.formattedAddress
307
+ ? {
308
+ formattedAddress:
309
+ params.person.address.formattedAddress,
310
+ }
311
+ : {}),
312
+ ...(params.person.address?.line
313
+ ? { line: params.person.address.line }
314
+ : {}),
315
+ ...(params.person.address?.city
316
+ ? { city: params.person.address.city }
317
+ : {}),
318
+ ...(params.person.address?.postalCode
319
+ ? { postalCode: params.person.address.postalCode }
320
+ : {}),
321
+ ...(params.person.address?.countryCode
322
+ ? {
323
+ countryCode:
324
+ params.person.address.countryCode,
325
+ }
326
+ : {}),
327
+ },
328
+ ],
329
+ }
330
+ : {}),
331
+ }
332
+ : undefined;
333
+
334
+ const lerRecord: LerRsRecord = {
335
+ type: LER_RS_TYPE_URI_V45,
336
+ documentId: { value: documentId },
337
+ person: personSection,
338
+ ...(communication ? { communication } : {}),
339
+ skills: (params.skills || []).map(s => ({ name: s })),
340
+ narratives: params.narratives,
341
+ employmentHistories: params.workHistory
342
+ ? buildEmploymentHistories(params.workHistory)
343
+ : undefined,
344
+ educationAndLearnings: params.educationHistory
345
+ ? buildEducationAndLearnings(params.educationHistory)
346
+ : undefined,
347
+ certifications: params.certifications
348
+ ? buildCertifications(params.certifications)
349
+ : undefined,
350
+ attachments: params.attachments,
351
+ };
352
+
353
+ const unsignedVC: UnsignedVC = {
354
+ '@context': [LER_RS_CREDENTIAL_CONTEXT_V2, inlineLerRsContext],
355
+ id: `urn:uuid:${documentId}`,
356
+ type: ['VerifiableCredential', LER_RS_TYPE_URI_V45],
357
+ issuer: did,
358
+ validFrom: issuedAt,
359
+ credentialSubject: {
360
+ id: params.person.id,
361
+ ...lerRecord,
362
+ },
363
+ };
364
+
365
+ return initLearnCard.invoke.issueCredential(unsignedVC, {
366
+ proofPurpose: 'assertionMethod',
367
+ });
368
+ },
369
+
370
+ /**
371
+ * Issues a VP containing at least one LER-RS credential.
372
+ *
373
+ * Throws if:
374
+ * - credentials list is empty
375
+ * - none of the credentials match LER-RS type checks
376
+ */
377
+ createLerPresentation: async (_learnCard, params): Promise<VerifiablePresentation> => {
378
+ const signer = params.learnCard ?? _learnCard;
379
+ const did = signer.id.did();
380
+
381
+ if (!params.credentials.length)
382
+ throw new Error(
383
+ 'createLerPresentation: credentials array must contain at least one credential'
384
+ );
385
+ const containsLer = params.credentials.some(credentialHasLerRsType);
386
+ if (!containsLer)
387
+ throw new Error(
388
+ 'createLerPresentation: credentials must include at least one LER-RS credential'
389
+ );
390
+
391
+ const vp: UnsignedVP = {
392
+ '@context': [LER_RS_CREDENTIAL_CONTEXT_V2],
393
+ type: ['VerifiablePresentation'],
394
+ holder: did,
395
+ verifiableCredential:
396
+ params.credentials.length === 1
397
+ ? params.credentials[0]
398
+ : params.credentials,
399
+ };
400
+
401
+ return initLearnCard.invoke.issuePresentation(vp, {
402
+ ...(params.domain ? { domain: params.domain } : {}),
403
+ ...(params.challenge ? { challenge: params.challenge } : {}),
404
+ });
405
+ },
406
+
407
+ /**
408
+ * Verifies a LER-focused VP and returns structured result details.
409
+ *
410
+ * Overall `verified` allows explicitly self-issued items when determining
411
+ * final status, while still surfacing per-credential verification results.
412
+ */
413
+ verifyLerPresentation: async (
414
+ _learnCard,
415
+ { presentation, domain, challenge }: VerifyLerPresentationParams
416
+ ): Promise<VerificationResult> => {
417
+ const presCheck = await initLearnCard.invoke.verifyPresentation(presentation, {
418
+ ...(domain ? { domain } : {}),
419
+ ...(challenge ? { challenge } : {}),
420
+ });
421
+
422
+ const presentationResult = {
423
+ verified: presCheck.errors.length === 0,
424
+ errors: presCheck.errors.length ? presCheck.errors : undefined,
425
+ };
426
+
427
+ const credentialResults: VerificationResult['credentialResults'] = [];
428
+
429
+ if (typeof presentation !== 'string') {
430
+ const holder = presentation.holder;
431
+ const vcs = toArray<VerifiableCredential>(
432
+ presentation.verifiableCredential as any
433
+ );
434
+
435
+ for (const credential of vcs) {
436
+ try {
437
+ const credCheck = await initLearnCard.invoke.verifyCredential(
438
+ credential
439
+ );
440
+ const issuerDid =
441
+ typeof credential.issuer === 'string'
442
+ ? credential.issuer
443
+ : credential.issuer?.id;
444
+ const isSelfIssued =
445
+ credentialHasLerRsType(credential) ||
446
+ (!!holder && !!issuerDid && issuerDid === holder);
447
+
448
+ credentialResults.push({
449
+ credential,
450
+ verified: credCheck.errors.length === 0,
451
+ isSelfIssued,
452
+ errors: credCheck.errors.length ? credCheck.errors : undefined,
453
+ });
454
+ } catch (err) {
455
+ credentialResults.push({
456
+ credential,
457
+ verified: false,
458
+ isSelfIssued: false,
459
+ errors: [
460
+ err instanceof Error
461
+ ? err.message
462
+ : 'Unknown error verifying credential',
463
+ ],
464
+ });
465
+ }
466
+ }
467
+ }
468
+
469
+ return {
470
+ verified:
471
+ presentationResult.verified &&
472
+ credentialResults.every(r => r.verified || r.isSelfIssued),
473
+ presentationResult,
474
+ credentialResults,
475
+ };
476
+ },
477
+
478
+ /**
479
+ * Issues a signed TrustedCareerProfile wrapper VC for resume package publishing.
480
+ *
481
+ * Includes:
482
+ * - public PDF URL
483
+ * - PDF SHA-256 hash
484
+ * - included credential references
485
+ * - generation timestamp
486
+ *
487
+ * Co-sign fields are intentionally stubbed for MVP and currently rejected.
488
+ */
489
+ createTcpWrapperVc: async (_learnCard, params): Promise<VerifiableCredential> => {
490
+ const signer = params.learnCard ?? _learnCard;
491
+ const did = signer.id.did();
492
+ const issuedAt = params.issuanceDate ?? new Date().toISOString();
493
+ const generatedAt = params.generatedAt ?? issuedAt;
494
+ const subjectDid = params.subjectDid ?? did;
495
+
496
+ if (params.enableCoSign) {
497
+ throw new Error('createTcpWrapperVc: co-signing is not enabled in MVP');
498
+ }
499
+
500
+ if (params.coSignerDid) {
501
+ throw new Error(
502
+ 'createTcpWrapperVc: coSignerDid is reserved for future co-sign support'
503
+ );
504
+ }
505
+
506
+ // NOTE: We inline the TCP context for local testing while the hosted
507
+ // context URL is not yet available in all environments.
508
+ const inlineTcpContext = {
509
+ '@version': 1.1,
510
+ id: '@id',
511
+ type: '@type',
512
+ TrustedCareerProfile: 'https://ctx.learncard.com/tcp#TrustedCareerProfile',
513
+ ResumePackage: 'https://ctx.learncard.com/tcp#ResumePackage',
514
+ pdfUrl: {
515
+ '@id': 'https://ctx.learncard.com/tcp#pdfUrl',
516
+ '@type': '@id',
517
+ },
518
+ pdfHash: 'https://ctx.learncard.com/tcp#pdfHash',
519
+ hashAlgorithm: 'https://ctx.learncard.com/tcp#hashAlgorithm',
520
+ includedCredentials: {
521
+ '@id': 'https://ctx.learncard.com/tcp#includedCredentials',
522
+ '@container': '@set',
523
+ },
524
+ category: 'https://ctx.learncard.com/tcp#category',
525
+ generatedAt: {
526
+ '@id': 'https://ctx.learncard.com/tcp#generatedAt',
527
+ '@type': 'http://www.w3.org/2001/XMLSchema#dateTime',
528
+ },
529
+ };
530
+
531
+ const unsignedVC: UnsignedVC = {
532
+ '@context': [LER_RS_CREDENTIAL_CONTEXT_V2, inlineTcpContext],
533
+ type: ['VerifiableCredential', TCP_WRAPPER_TYPE],
534
+ id: params.wrapperId,
535
+ issuer: did,
536
+ validFrom: issuedAt,
537
+ credentialSubject: {
538
+ id: subjectDid,
539
+ type: 'ResumePackage',
540
+ pdfUrl: params.pdfUrl,
541
+ pdfHash: params.pdfHash,
542
+ hashAlgorithm: 'SHA-256',
543
+ includedCredentials: params.includedCredentials,
544
+ generatedAt,
545
+ },
546
+ };
547
+
548
+ return initLearnCard.invoke.issueCredential(unsignedVC, {
549
+ proofPurpose: 'assertionMethod',
550
+ });
551
+ },
552
+ },
553
+ };
554
+ };
package/src/types.ts ADDED
@@ -0,0 +1,298 @@
1
+ import { Plugin, LearnCard } from '@learncard/core';
2
+ import {
3
+ VC as VerifiableCredential,
4
+ VP as VerifiablePresentation,
5
+ UnsignedVC,
6
+ UnsignedVP,
7
+ VerificationCheck,
8
+ } from '@learncard/types';
9
+ import type { VCPluginMethods, VCPluginDependentMethods } from '@learncard/vc-plugin';
10
+
11
+ /**
12
+ * Legacy W3C VC v1 context kept for interop with previously issued records.
13
+ */
14
+ export const LER_RS_CREDENTIAL_CONTEXT_V1 = 'https://www.w3.org/2018/credentials/v1';
15
+ /**
16
+ * Base W3C VC v2 context used by newly issued LER-RS credentials and presentations.
17
+ */
18
+ export const LER_RS_CREDENTIAL_CONTEXT_V2 = 'https://www.w3.org/ns/credentials/v2';
19
+ /**
20
+ * HR Open Standards VC wrapper context for LER-RS v4.5.
21
+ */
22
+ export const LER_RS_VC_CONTEXT_V45 =
23
+ 'http://schema.hropenstandards.org/4.5/recruiting/json/VerifiableCredentialLER-RSType.json';
24
+ /**
25
+ * Canonical LER-RS type URI for v4.5.
26
+ */
27
+ export const LER_RS_TYPE_URI_V45 =
28
+ 'http://schema.hropenstandards.org/4.5/recruiting/json/LER-RSType.json';
29
+ /**
30
+ * Legacy LER-RS type URI for v4.4 interop.
31
+ */
32
+ export const LEGACY_LER_RS_TYPE_URI_V44 =
33
+ 'http://schema.hropenstandards.org/4.4/recruiting/json/ler-rs/LER-RSType.json';
34
+ /**
35
+ * Legacy short type token used by older issuers.
36
+ */
37
+ export const LEGACY_LER_RS_TYPE_TOKEN = 'LERRS';
38
+ /**
39
+ * Hosted TCP JSON-LD context URL.
40
+ *
41
+ * Note: current local wrapper issuance can inline context during local testing.
42
+ */
43
+ export const TCP_CONTEXT_V1 = 'https://ctx.learncard.com/tcp/1.0.0.json';
44
+ /**
45
+ * LearnCard-defined wrapper VC type for TCP resume package artifacts.
46
+ *
47
+ * This is intentionally NOT a canonical HR Open Standards LER-RS type;
48
+ * it is a custom wrapper used to bind PDF URL/hash + included credential refs.
49
+ */
50
+ export const TCP_WRAPPER_TYPE = 'TrustedCareerProfile';
51
+
52
+ /**
53
+ * Identity details used to populate `credentialSubject.person`.
54
+ */
55
+ export interface PersonProfile {
56
+ /** Subject DID for the issued LER-RS record. */
57
+ id: string;
58
+ /** Given/first name. */
59
+ givenName: string;
60
+ /** Family/last name. */
61
+ familyName: string;
62
+ /** Optional display name override. */
63
+ formattedName?: string;
64
+ /** Optional contact email to include in communication block. */
65
+ email?: string;
66
+ /** Optional contact phone to include in communication block. */
67
+ phone?: string;
68
+ /** Optional physical/mailing address to include in communication block. */
69
+ address?: {
70
+ formattedAddress?: string;
71
+ line?: string;
72
+ city?: string;
73
+ postalCode?: string;
74
+ countryCode?: string;
75
+ };
76
+ /** Optional website URLs to include in communication block. */
77
+ web?: Array<{ url: string; name?: string }>;
78
+ /** Optional social profile URLs to include in communication block. */
79
+ social?: Array<{ uri: string; name?: string }>;
80
+ }
81
+
82
+ /**
83
+ * Skill item structure used inside generated LER-RS records.
84
+ */
85
+ export interface LerSkill {
86
+ name: string;
87
+ comments?: string[];
88
+ description?: string;
89
+ yearsOfExperience?: number;
90
+ endorsers?: Array<{
91
+ person?: { name?: { formattedName?: string } };
92
+ organization?: { name?: string };
93
+ }>;
94
+ }
95
+
96
+ /**
97
+ * Source work history entry. Can be self-asserted fields and/or third-party verification VCs.
98
+ */
99
+ export interface WorkHistoryItem {
100
+ narrative?: string;
101
+ descriptions?: string[];
102
+ verifiableCredential?: VerifiableCredential;
103
+ verifications?: VerifiableCredential[];
104
+ // Common self-asserted fields
105
+ position?: string;
106
+ employer?: string;
107
+ start?: string;
108
+ end?: string;
109
+ current?: boolean;
110
+ [key: string]: unknown;
111
+ }
112
+
113
+ /**
114
+ * Source education entry. Can include freeform fields and optional verification VCs.
115
+ */
116
+ export interface EducationHistoryItem {
117
+ narrative?: string;
118
+ descriptions?: string[];
119
+ verifiableCredential?: VerifiableCredential;
120
+ verifications?: VerifiableCredential[];
121
+ institution?: string;
122
+ start?: string;
123
+ end?: string;
124
+ current?: boolean;
125
+ degree?: string;
126
+ specializations?: string[];
127
+ [key: string]: unknown;
128
+ }
129
+
130
+ /**
131
+ * Source certification entry for `credentialSubject.certifications`.
132
+ */
133
+ export interface CertificationItem {
134
+ narrative?: string;
135
+ descriptions?: string[];
136
+ verifiableCredential?: VerifiableCredential;
137
+ verifications?: VerifiableCredential[];
138
+ name?: string;
139
+ issuingAuthority?: string | Record<string, unknown>;
140
+ status?: string;
141
+ start?: string;
142
+ end?: string;
143
+ effectiveTimePeriod?: { validFrom?: string; validTo?: string };
144
+ [key: string]: unknown;
145
+ }
146
+
147
+ /**
148
+ * Narrative section block supported by LER-RS schema.
149
+ */
150
+ export interface LerNarrative {
151
+ name: string;
152
+ texts: Array<{
153
+ name: string;
154
+ lines: string[];
155
+ }>;
156
+ }
157
+
158
+ /**
159
+ * Typed shape of the LER-RS object embedded into `credentialSubject`.
160
+ */
161
+ export interface LerRsRecord {
162
+ type: string;
163
+ documentId?: { value: string };
164
+ person: {
165
+ name: {
166
+ given: string;
167
+ family: string;
168
+ formattedName?: string;
169
+ };
170
+ };
171
+ communication?: {
172
+ email?: { address: string }[];
173
+ web?: { url: string; name?: string }[];
174
+ phone?: Array<Record<string, unknown>>;
175
+ address?: Array<Record<string, unknown>>;
176
+ social?: Array<Record<string, unknown>>;
177
+ };
178
+ skills?: LerSkill[];
179
+ narratives?: LerNarrative[];
180
+ educationAndLearnings?: Array<
181
+ { verifications?: VerifiableCredential[] } & Record<string, unknown>
182
+ >;
183
+ employmentHistories?: Array<
184
+ { verifications?: VerifiableCredential[] } & Record<string, unknown>
185
+ >;
186
+ licenses?: Array<{ verifications?: VerifiableCredential[] } & Record<string, unknown>>;
187
+ certifications?: Array<{ verifications?: VerifiableCredential[] } & Record<string, unknown>>;
188
+ employmentPreferences?: Array<Record<string, unknown>>;
189
+ positionPreferences?: Array<Record<string, unknown>>;
190
+ attachments?: Array<Record<string, unknown>>;
191
+ }
192
+
193
+ /**
194
+ * Parameters for issuing a signed LER-RS VC from normalized source data.
195
+ */
196
+ export interface CreateLerRecordParams {
197
+ learnCard: LearnCard<any, 'id', VCPluginMethods & VCPluginDependentMethods>;
198
+ person: PersonProfile;
199
+ workHistory?: WorkHistoryItem[];
200
+ educationHistory?: EducationHistoryItem[];
201
+ certifications?: CertificationItem[];
202
+ skills?: string[];
203
+ narratives?: LerNarrative[];
204
+ attachments?: Array<Record<string, unknown>>;
205
+ }
206
+
207
+ /**
208
+ * Parameters for issuing a VP that packages one or more credentials including at least one LER-RS credential.
209
+ */
210
+ export interface CreateLerPresentationParams {
211
+ learnCard: LearnCard<any, 'id', VCPluginMethods & VCPluginDependentMethods>;
212
+ credentials: VerifiableCredential[];
213
+ domain?: string;
214
+ challenge?: string;
215
+ }
216
+
217
+ /**
218
+ * Parameters for verifying a LER-focused VP and nested credentials.
219
+ */
220
+ export interface VerifyLerPresentationParams {
221
+ presentation: VerifiablePresentation | string;
222
+ domain?: string;
223
+ challenge?: string;
224
+ }
225
+
226
+ /**
227
+ * Credential reference stored in TCP wrapper VC.
228
+ */
229
+ export interface TcpIncludedCredentialRef {
230
+ /** Resolved VC id when available; falls back to URI if id is unavailable. */
231
+ id: string;
232
+ /** Category label used for UI grouping and downstream filtering. */
233
+ category: string;
234
+ }
235
+
236
+ /**
237
+ * Parameters for issuing TrustedCareerProfile wrapper VCs.
238
+ */
239
+ export interface CreateTcpWrapperVcParams {
240
+ learnCard: LearnCard<any, 'id', VCPluginMethods & VCPluginDependentMethods>;
241
+ wrapperId: string;
242
+ subjectDid?: string;
243
+ pdfUrl: string;
244
+ pdfHash: string;
245
+ includedCredentials: TcpIncludedCredentialRef[];
246
+ generatedAt?: string;
247
+ /** Timestamp used as the issued credential's `validFrom` value. */
248
+ issuanceDate?: string;
249
+ coSignerDid?: string;
250
+ enableCoSign?: boolean;
251
+ }
252
+
253
+ /**
254
+ * Structured verification output for LER presentation verification.
255
+ */
256
+ export interface VerificationResult {
257
+ verified: boolean; // Overall status
258
+ presentationResult: {
259
+ verified: boolean;
260
+ errors?: string[];
261
+ };
262
+ credentialResults: {
263
+ credential: VerifiableCredential;
264
+ verified: boolean;
265
+ isSelfIssued: boolean;
266
+ errors?: string[];
267
+ }[];
268
+ }
269
+
270
+ /**
271
+ * LearnCard dependency contract required by this plugin.
272
+ */
273
+ export type LERRSDependentLearnCard = LearnCard<
274
+ any,
275
+ 'id',
276
+ VCPluginMethods & VCPluginDependentMethods
277
+ >;
278
+
279
+ /**
280
+ * Public invoke methods exposed by the LER-RS plugin.
281
+ */
282
+ export type LERRSPluginMethods = {
283
+ createLerRecord: (params: CreateLerRecordParams) => Promise<VerifiableCredential>;
284
+ createLerPresentation: (params: CreateLerPresentationParams) => Promise<VerifiablePresentation>;
285
+ verifyLerPresentation: (params: VerifyLerPresentationParams) => Promise<VerificationResult>;
286
+ createTcpWrapperVc: (params: CreateTcpWrapperVcParams) => Promise<VerifiableCredential>;
287
+ };
288
+
289
+ /**
290
+ * Plugin type definition for registration in LearnCard.
291
+ */
292
+ export type LERRSPlugin = Plugin<
293
+ 'LER-RS',
294
+ never,
295
+ LERRSPluginMethods,
296
+ 'id',
297
+ VCPluginMethods & VCPluginDependentMethods
298
+ >;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Learning Economy Foundation <sdk@learningeconomy.io>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.