@cooperation/vc-storage 1.0.43 → 1.0.44

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.
@@ -1,9 +1,25 @@
1
- import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020';
2
- import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020';
3
- import * as dbVc from '@digitalbazaar/vc';
1
+ import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';
2
+ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020';
3
+ import * as dbVc from '@digitalcredentials/vc';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
- import { extractKeyPairFromCredential, generateDIDSchema, generateUnsignedEmployment, generateUnsignedPerformanceReview, generateUnsignedRecommendation, generateUnsignedVC, generateUnsignedVolunteering, } from '../utils/credential.js';
6
- import { customDocumentLoader } from '../utils/digitalbazaar.js';
5
+ import { extractKeyPairFromCredential, generateDIDSchema, generateUnsignedEmployment, generateUnsignedPerformanceReview, generateUnsignedRecommendation, generateUnsignedSkillClaim, generateUnsignedVC, generateUnsignedVolunteering, } from '../utils/credential.js';
6
+ import { securityLoader } from '@digitalcredentials/security-document-loader';
7
+ import hrContext from 'hr-context';
8
+ // Add hr-context for SkillClaimCredential; patch socCode (@type→@container)
9
+ const hrCtxData = JSON.parse(JSON.stringify(hrContext.CONTEXT_V1));
10
+ if (hrCtxData?.['@context']?.socCode) {
11
+ delete hrCtxData['@context'].socCode['@type'];
12
+ hrCtxData['@context'].socCode['@container'] = '@set';
13
+ }
14
+ const loader = securityLoader();
15
+ loader.addStatic(hrContext.CONTEXT_URL_V1, hrCtxData);
16
+ loader.addStatic('https://w3id.org/hr/v1', hrCtxData);
17
+ const builtLoader = loader.build();
18
+ /** Document loader compatible with @digitalcredentials/vc */
19
+ export const documentLoader = async (url) => {
20
+ const r = await builtLoader(url);
21
+ return { contextUrl: r.contextUrl ?? null, documentUrl: r.documentUrl ?? url, document: r.document };
22
+ };
7
23
  import { saveToGoogleDrive } from '../utils/google.js';
8
24
  function delay(ms) {
9
25
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -191,7 +207,7 @@ export class CredentialEngine {
191
207
  throw new Error(`Unsupported credential type: ${type}`);
192
208
  }
193
209
  const suite = new Ed25519Signature2020({ key: keyPair, verificationMethod: keyPair.id });
194
- return dbVc.issue({ credential, suite, documentLoader: customDocumentLoader });
210
+ return dbVc.issue({ credential, suite, documentLoader });
195
211
  }
196
212
  async signEmploymentCredential(data, keyPair, issuerId) {
197
213
  return this.signVC({ data, type: 'EMPLOYMENT', keyPair, issuerId });
@@ -202,6 +218,18 @@ export class CredentialEngine {
202
218
  async signPerformanceReviewCredential(data, keyPair, issuerId) {
203
219
  return this.signVC({ data, type: 'PERFORMANCE_REVIEW', keyPair, issuerId });
204
220
  }
221
+ /**
222
+ * Sign a SkillClaimCredential using the HR Context data model.
223
+ * @param {SkillClaimFormDataI} data - The skill claim form data.
224
+ * @param {KeyPair} keyPair - The key pair to use for signing.
225
+ * @param {string} issuerId - The issuer DID.
226
+ * @returns {Promise<any>} The signed SkillClaimCredential.
227
+ */
228
+ async signSkillClaimVC(data, keyPair, issuerId) {
229
+ const credential = generateUnsignedSkillClaim({ formData: data, issuerDid: issuerId });
230
+ const suite = new Ed25519Signature2020({ key: keyPair, verificationMethod: keyPair.id });
231
+ return dbVc.issue({ credential, suite, documentLoader });
232
+ }
205
233
  /**
206
234
  * Verify a Verifiable Credential (VC)
207
235
  * @param {object} credential - The Verifiable Credential to verify.
@@ -218,10 +246,10 @@ export class CredentialEngine {
218
246
  const result = await dbVc.verifyCredential({
219
247
  credential,
220
248
  suite,
221
- documentLoader: customDocumentLoader,
249
+ documentLoader,
222
250
  });
223
251
  console.log(JSON.stringify(result));
224
- return result;
252
+ return result.verified;
225
253
  }
226
254
  catch (error) {
227
255
  console.error('Verification failed:', error);
@@ -273,7 +301,7 @@ export class CredentialEngine {
273
301
  const signedVP = await dbVc.signPresentation({
274
302
  presentation,
275
303
  suite,
276
- documentLoader: customDocumentLoader,
304
+ documentLoader,
277
305
  challenge: '', // Provide the challenge if required
278
306
  });
279
307
  return signedVP;
@@ -347,7 +375,7 @@ export class CredentialEngine {
347
375
  const signedVC = await dbVc.issue({
348
376
  credential: unsignedCredential,
349
377
  suite,
350
- documentLoader: customDocumentLoader,
378
+ documentLoader,
351
379
  });
352
380
  const rootFolders = await this.storage.findFolders();
353
381
  // Find or create Credentials folder
@@ -1,8 +1,8 @@
1
- import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020';
2
- import { customDocumentLoader } from '../utils/digitalbazaar.js';
1
+ import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020';
2
+ import { documentLoader } from './CredentialEngine.js';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
- import * as dbVc from '@digitalbazaar/vc';
5
- import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020';
4
+ import * as dbVc from '@digitalcredentials/vc';
5
+ import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';
6
6
  import { generateDIDSchema } from '../utils/credential.js';
7
7
  import { inlineResumeContext } from '../utils/context.js';
8
8
  export class ResumeVC {
@@ -20,7 +20,7 @@ export class ResumeVC {
20
20
  const signedProfessionalSummaryVC = await dbVc.issue({
21
21
  credential: professionalSummaryVC,
22
22
  suite,
23
- documentLoader: customDocumentLoader,
23
+ documentLoader,
24
24
  });
25
25
  // Replace the unsigned professional summary with the signed one
26
26
  unsignedCredential.credentialSubject.professionalSummary = signedProfessionalSummaryVC;
@@ -28,7 +28,7 @@ export class ResumeVC {
28
28
  const signedResumeVC = await dbVc.issue({
29
29
  credential: unsignedCredential,
30
30
  suite,
31
- documentLoader: customDocumentLoader,
31
+ documentLoader,
32
32
  });
33
33
  console.log('Signed Resume VC:', signedResumeVC);
34
34
  return signedResumeVC;
@@ -205,7 +205,6 @@ export class ResumeVC {
205
205
  const a = address || keyPair.publicKeyMultibase;
206
206
  keyPair.controller = `did:key:${a}`;
207
207
  keyPair.id = `${keyPair.controller}#${a}`;
208
- keyPair.revoked = false;
209
208
  // The `signer` is already provided by the `Ed25519VerificationKey2020` instance
210
209
  return keyPair;
211
210
  };
@@ -1,5 +1,12 @@
1
+ /** Document loader compatible with @digitalcredentials/vc */
2
+ export declare const documentLoader: (url: string) => Promise<{
3
+ contextUrl: string;
4
+ documentUrl: string;
5
+ document: any;
6
+ }>;
1
7
  import type { IVerifiableCredential } from '@digitalcredentials/ssi';
2
8
  import { DidDocument, KeyPair, FormDataI, RecommendationFormDataI, EmploymentFormDataI, PerformanceReviewFormDataI, VolunteeringFormDataI } from '../../types';
9
+ import type { ISkillClaimCredential } from 'hr-context';
3
10
  import { GoogleDriveStorage } from './GoogleDriveStorage.js';
4
11
  interface SignPropsI {
5
12
  data: FormDataI | RecommendationFormDataI | EmploymentFormDataI | VolunteeringFormDataI | PerformanceReviewFormDataI;
@@ -68,6 +75,14 @@ export declare class CredentialEngine {
68
75
  signEmploymentCredential(data: EmploymentFormDataI, keyPair: KeyPair, issuerId: string): Promise<any>;
69
76
  signVolunteeringCredential(data: VolunteeringFormDataI, keyPair: KeyPair, issuerId: string): Promise<any>;
70
77
  signPerformanceReviewCredential(data: PerformanceReviewFormDataI, keyPair: KeyPair, issuerId: string): Promise<any>;
78
+ /**
79
+ * Sign a SkillClaimCredential using the HR Context data model.
80
+ * @param {SkillClaimFormDataI} data - The skill claim form data.
81
+ * @param {KeyPair} keyPair - The key pair to use for signing.
82
+ * @param {string} issuerId - The issuer DID.
83
+ * @returns {Promise<any>} The signed SkillClaimCredential.
84
+ */
85
+ signSkillClaimVC(data: ISkillClaimCredential, keyPair: KeyPair, issuerId: string): Promise<any>;
71
86
  /**
72
87
  * Verify a Verifiable Credential (VC)
73
88
  * @param {object} credential - The Verifiable Credential to verify.
@@ -80,13 +95,13 @@ export declare class CredentialEngine {
80
95
  * @param verifiableCredential
81
96
  * @returns
82
97
  */
83
- createPresentation(verifiableCredential: IVerifiableCredential[]): Promise<any>;
98
+ createPresentation(verifiableCredential: IVerifiableCredential[]): Promise<object>;
84
99
  /**
85
100
  * Sign a Verifiable Presentation (VP)
86
101
  * @param presentation
87
102
  * @returns
88
103
  */
89
- signPresentation(presentation: any): Promise<any>;
104
+ signPresentation(presentation: any): Promise<object>;
90
105
  /**
91
106
  * Generate and sign an email Verifiable Credential (VC)
92
107
  * @param {string} email - The email address to create the VC for
@@ -1,3 +1,4 @@
1
+ import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';
1
2
  export declare class ResumeVC {
2
3
  sign({ formData, issuerDid, keyPair }: {
3
4
  formData: any;
@@ -20,7 +21,7 @@ export declare class ResumeVC {
20
21
  formData: any;
21
22
  issuerDid: string;
22
23
  }): any;
23
- generateKeyPair: (address?: string) => Promise<any>;
24
+ generateKeyPair: (address?: string) => Promise<Ed25519VerificationKey2020>;
24
25
  /**
25
26
  * Create a new DID with Digital Bazaar's Ed25519VerificationKey2020 key pair.
26
27
  * @returns {Promise<{didDocument: object, keyPair: object}>} The created DID document and key pair.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Ed25519 signer compatible with @wallet.storage/fetch-client.
3
+ * Uses @digitalcredentials packages instead of @digitalbazaar.
4
+ */
5
+ import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020';
6
+ export declare class Ed25519Signer {
7
+ private readonly keyPair;
8
+ private readonly verificationMethod;
9
+ readonly algorithm = "Ed25519";
10
+ constructor(keyPair: Ed25519VerificationKey2020, verificationMethod: {
11
+ id: string;
12
+ type: string;
13
+ controller: string;
14
+ publicKeyMultibase: string;
15
+ });
16
+ static generate(): Promise<Ed25519Signer>;
17
+ static fromJSON(json: string): Promise<Ed25519Signer>;
18
+ get controller(): string;
19
+ get id(): string;
20
+ get publicKeyMultibase(): string;
21
+ sign({ data }: {
22
+ data: Uint8Array;
23
+ }): Promise<Uint8Array>;
24
+ toJSON(): object;
25
+ }