@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 +1 -1
- package/app.config.js +1 -0
- package/dist/index.js +3 -1
- package/dist/models/CredentialEngine.js +35 -24
- package/dist/models/GoogleDriveStorage.js +121 -273
- package/dist/models/Resume.js +16 -4
- package/dist/models/WASStorage.js +71 -0
- package/dist/scripts/test-was.js +61 -0
- package/dist/types/index.d.ts +3 -1
- package/dist/types/models/CredentialEngine.d.ts +7 -4
- package/dist/types/models/GoogleDriveStorage.d.ts +31 -55
- package/dist/types/models/Resume.d.ts +3 -2
- package/dist/types/models/WASStorage.d.ts +30 -0
- package/dist/types/scripts/test-was.d.ts +1 -0
- package/dist/types/utils/context.d.ts +73 -0
- package/dist/types/utils/createWASSpace.d.ts +9 -0
- package/dist/types/utils/credential.d.ts +171 -1
- package/dist/types/utils/getOrCreateAppDID.d.ts +11 -0
- package/dist/types/utils/google.d.ts +1 -1
- package/dist/utils/context.js +76 -0
- package/dist/utils/createWASSpace.js +27 -0
- package/dist/utils/credential.js +96 -0
- package/dist/utils/getOrCreateAppDID.js +22 -0
- package/dist/utils/google.js +1 -1
- package/package.json +6 -3
- package/dist/types/utils/presentation.d.ts +0 -10
- package/dist/utils/presentation.js +0 -45
package/README.md
CHANGED
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
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
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;
|