@cooperation/vc-storage 1.0.33 → 1.0.40

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @cooperation/vc-storage
2
2
 
3
- **Version**: 1.0.0
3
+ **Version**: 1.0.35
4
4
 
5
5
  ## Overview
6
6
 
package/app.config.js ADDED
@@ -0,0 +1 @@
1
+ export const WAS_BASE_URL = 'http://localhost:4444';
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './models/GoogleDriveStorage.js';
2
2
  export * from './models/CredentialEngine.js';
3
3
  export * from './utils/google.js';
4
- export * from './utils/presentation.js';
5
4
  export * from './models/Resume.js';
6
5
  export * from './models/ResumeVC.js';
6
+ export * from './models/WASStorage.js';
7
+ export * from './utils/createWASSpace.js';
8
+ export * from './utils/getOrCreateAppDID.js';
@@ -2,7 +2,7 @@ import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-
2
2
  import { Ed25519Signature2020 } from '@digitalbazaar/ed25519-signature-2020';
3
3
  import * as dbVc from '@digitalbazaar/vc';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
- import { extractKeyPairFromCredential, generateDIDSchema, generateUnsignedRecommendation, generateUnsignedVC, } from '../utils/credential.js';
5
+ import { extractKeyPairFromCredential, generateDIDSchema, generateUnsignedEmployment, generateUnsignedPerformanceReview, generateUnsignedRecommendation, generateUnsignedVC, generateUnsignedVolunteering, } from '../utils/credential.js';
6
6
  import { customDocumentLoader } from '../utils/digitalbazaar.js';
7
7
  import { saveToGoogleDrive } from '../utils/google.js';
8
8
  function delay(ms) {
@@ -126,7 +126,7 @@ export class CredentialEngine {
126
126
  }
127
127
  /**
128
128
  * Sign a Verifiable Credential (VC)
129
- * @param {'VC' | 'RECOMMENDATION'} type - The signature type.
129
+ * @param {'VC' | 'RECOMMENDATION' | 'EMPLOYMENT' | 'VOLUNTEERING' | 'PERFORMANCE_REVIEW'} type - The signature type.
130
130
  * @param {string} issuerId - The ID of the issuer [currently we put it as the did id]
131
131
  * @param {KeyPair} keyPair - The key pair to use for signing.
132
132
  * @param {FormDataI | RecommendationFormDataI} formData - The form data to include in the VC.
@@ -135,28 +135,39 @@ export class CredentialEngine {
135
135
  * @throws Will throw an error if VC signing fails.
136
136
  */
137
137
  async signVC({ data, type, keyPair, issuerId, vcFileId }) {
138
- let credential = generateUnsignedVC({ formData: data, issuerDid: issuerId });
139
- if (type == 'RECOMMENDATION' && vcFileId) {
140
- console.log('WOW');
141
- credential = generateUnsignedRecommendation({
142
- vcId: vcFileId,
143
- recommendation: data,
144
- issuerDid: issuerId,
145
- });
146
- }
147
- try {
148
- console.log('🚀 ~ CredentialEngine ~ signVC ~ credential:', credential);
149
- if (!credential)
150
- throw new Error('Invalid credential type');
151
- const suite = new Ed25519Signature2020({ key: keyPair, verificationMethod: keyPair.id });
152
- console.log('before');
153
- const signedVC = await dbVc.issue({ credential, suite, documentLoader: customDocumentLoader });
154
- return signedVC;
155
- }
156
- catch (error) {
157
- console.error('Error signing VC:', error);
158
- throw error;
138
+ let credential;
139
+ switch (type) {
140
+ case 'VC':
141
+ credential = generateUnsignedVC({ formData: data, issuerDid: issuerId });
142
+ break;
143
+ case 'RECOMMENDATION':
144
+ if (!vcFileId)
145
+ throw new Error('vcFileId is required for recommendation');
146
+ credential = generateUnsignedRecommendation({ vcId: vcFileId, recommendation: data, issuerDid: issuerId });
147
+ break;
148
+ case 'EMPLOYMENT':
149
+ credential = generateUnsignedEmployment({ formData: data, issuerDid: issuerId });
150
+ break;
151
+ case 'VOLUNTEERING':
152
+ credential = generateUnsignedVolunteering({ formData: data, issuerDid: issuerId });
153
+ break;
154
+ case 'PERFORMANCE_REVIEW':
155
+ credential = generateUnsignedPerformanceReview({ formData: data, issuerDid: issuerId });
156
+ break;
157
+ default:
158
+ throw new Error(`Unsupported credential type: ${type}`);
159
159
  }
160
+ const suite = new Ed25519Signature2020({ key: keyPair, verificationMethod: keyPair.id });
161
+ return dbVc.issue({ credential, suite, documentLoader: customDocumentLoader });
162
+ }
163
+ async signEmploymentCredential(data, keyPair, issuerId) {
164
+ return this.signVC({ data, type: 'EMPLOYMENT', keyPair, issuerId });
165
+ }
166
+ async signVolunteeringCredential(data, keyPair, issuerId) {
167
+ return this.signVC({ data, type: 'VOLUNTEERING', keyPair, issuerId });
168
+ }
169
+ async signPerformanceReviewCredential(data, keyPair, issuerId) {
170
+ return this.signVC({ data, type: 'PERFORMANCE_REVIEW', keyPair, issuerId });
160
171
  }
161
172
  /**
162
173
  * Verify a Verifiable Credential (VC)
@@ -258,7 +269,7 @@ export class CredentialEngine {
258
269
  throw new Error('SEED environment variable not set. Cannot generate or use any DID.');
259
270
  }
260
271
  // Use deterministic keys from environment seed
261
- const { getDidFromEnvSeed } = await import('../utils/decodedSeed');
272
+ const { getDidFromEnvSeed } = await import('../utils/decodedSeed.js');
262
273
  const result = await getDidFromEnvSeed(encodedSeed);
263
274
  keyPair = result.keyPair;
264
275
  didDocument = result.didDocument;