@cooperation/vc-storage 1.0.34 → 1.0.41

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,109 +1,80 @@
1
1
  # @cooperation/vc-storage
2
2
 
3
- **Version**: 1.0.0
3
+ TypeScript utilities to work with storage backends used by Linked Claims: Google Drive and Wallet Aggregated Storage (WAS). Includes a simple factory to construct storage clients and helpers used by the authoring app.
4
4
 
5
- ## Overview
5
+ ## Installation
6
6
 
7
- `@cooperation/vc-storage` is a TypeScript library that allows you to sign and store Verifiable Credentials (VCs) in various storage strategies. This library provides flexibility and security by allowing you to choose where your VCs are stored, whether on cloud services like Google Drive, on your local device, or in your digital wallet. Support for Dropbox and wallet storage is currently under development.
7
+ ```bash
8
+ npm install @cooperation/vc-storage
9
+ ```
8
10
 
9
- ## Features
11
+ ## Exports (selected)
10
12
 
11
- - **Sign and Store VCs**: Securely sign your Verifiable Credentials and store them in your preferred storage medium.
12
- - **Google Drive Integration**: Seamlessly store your VCs on Google Drive.
13
- - **Local Device Storage**: Store your VCs directly on your device.
14
- - **Future Integrations**:
15
- - **Wallet Storage**: Integration for storing VCs directly in your digital wallet (under development).
16
- - **Dropbox Storage**: Integration for storing VCs in Dropbox (under development).
13
+ - GoogleDriveStorage
14
+ - LCWStorage (WAS via @wallet.storage/fetch-client)
15
+ - WASZcapStorage (WAS via zCap delegation)
16
+ - createStorage(kind, options)
17
+ - Misc models: CredentialEngine, Resume, ResumeVC, utils
17
18
 
18
- ## Installation
19
+ ## Storage factory
19
20
 
20
- You can install this package via npm:
21
+ ```ts
22
+ import { createStorage } from '@cooperation/vc-storage';
21
23
 
22
- ```bash
23
- npm install @cooperation/vc-storage
24
+ // Google Drive
25
+ const drive = createStorage('googleDrive', { accessToken });
26
+
27
+ // WAS (zCap-capability, delegated access)
28
+ const wasZ = createStorage('wasZcap', { appInstance, capability });
24
29
  ```
25
30
 
26
- ## Usage
27
-
28
- ### Basic Example
29
-
30
- Here’s how you can use the `@cooperation/vc-storage` library to sign and store your VCs:
31
-
32
- ```typescript
33
- import { saveToGoogleDrive, CredentialEngine, GoogleDriveStorage } from '@cooperation/vc-storage';
34
-
35
- const accessToken = 'your-google-drive-access-token';
36
- const credentialEngine = new CredentialEngine();
37
- const storage = new GoogleDriveStorage(accessToken);
38
-
39
- async function main(useWallet = false, walletAddress = '') {
40
- const formData = {
41
- expirationDate: '2025-12-31T23:59:59Z',
42
- fullName: 'John Doe',
43
- duration: '1 year',
44
- criteriaNarrative: 'This is a narrative',
45
- achievementDescription: 'This is an achievement',
46
- achievementName: 'Achievement Name',
47
- portfolio: [
48
- { name: 'Portfolio 1', url: 'https://example.com/portfolio1' },
49
- { name: 'Portfolio 2', url: 'https://example.com/portfolio2' },
50
- ],
51
- evidenceLink: 'https://example.com/evidence',
52
- evidenceDescription: 'This is an evidence description',
53
- credentialType: 'Credential Type',
54
- };
55
-
56
- let didDocument, keyPair;
57
-
58
- // Step 1: Create DID based on the selected method
59
- if (useWallet && walletAddress) {
60
- ({ didDocument, keyPair } = await credentialEngine.createWalletDID(walletAddress));
61
- } else {
62
- ({ didDocument, keyPair } = await credentialEngine.createDID());
63
- }
64
-
65
- await saveToGoogleDrive(storage, { ...didDocument, keyPair }, 'DID');
66
-
67
- const issuerDid = didDocument.id;
68
-
69
- // Step 2: Create an Unsigned VC
70
- const unsignedVC = await credentialEngine.createUnsignedVC(formData, issuerDid);
71
- await saveToGoogleDrive(storage, unsignedVC, 'UnsignedVC');
72
- console.log('Unsigned VC:', unsignedVC);
73
-
74
- // Step 3: Sign the VC
75
- try {
76
- const signedVC = await credentialEngine.signVC(unsignedVC, keyPair);
77
- await saveToGoogleDrive(storage, signedVC, 'VC');
78
- console.log('Signed VC:', signedVC);
79
- } catch (error) {
80
- console.error('Error during VC signing:', error);
81
- }
82
-
83
- // Retrieve all stored claims
84
- const claims = await storage.getAllClaims();
85
- console.log('Stored Claims:', claims);
86
- }
87
-
88
- // Example usage:
89
- // 1. For Google Drive storage with standard DID creation
90
- main().catch(console.error);
91
-
92
- // 2. For Google Drive storage with wallet-based DID creation
93
- // main(true, 'your-wallet-address').catch(console.error);
31
+ ## GoogleDriveStorage (highlights)
32
+
33
+ ```ts
34
+ import { GoogleDriveStorage } from '@cooperation/vc-storage';
35
+
36
+ const drive = new GoogleDriveStorage(accessToken);
37
+
38
+ // Upload binary (images/videos/pdfs)
39
+ await drive.uploadBinaryFile({ file }); // -> { id }
40
+
41
+ // Save JSON file to a specific folder
42
+ await drive.saveFile({ data: { fileName: 'VC', mimeType: 'application/json', body: JSON.stringify(vc) }, folderId });
43
+
44
+ // Retrieve file content
45
+ await drive.retrieve(fileId); // -> { id, data }
46
+
47
+ // Delete
48
+ await drive.delete(fileId);
49
+ ```
50
+
51
+ ## WASZcapStorage (WAS, zCap delegation)
52
+
53
+ Use when uploading from the browser with delegated capability (zCap).
54
+
55
+ ```ts
56
+ import { WASZcapStorage } from '@cooperation/vc-storage';
57
+
58
+ const was = new WASZcapStorage({ appInstance, capability });
59
+
60
+ // Blob upload (images, pdfs, or JSON-as-blob)
61
+ await was.upload({ key: file.name, file }); // -> id or url
62
+
63
+ // Optional read/delete
64
+ await was.read('key.json');
65
+ await was.delete('old-file.txt');
94
66
  ```
95
67
 
96
- ### Available Storage Strategies
68
+ ## Choosing a backend
97
69
 
98
- 1. **Google Drive**: Store your VCs on Google Drive.
99
- 2. **Local Device**: Store your VCs on your local device.
100
- 3. **Wallet Storage**: (Under Development) Store your VCs directly in your digital wallet.
101
- 4. **Dropbox**: (Under Development) Store your VCs in Dropbox.
70
+ - Use WASZcapStorage when you have a zCap capability and an appInstance Ed25519 keypair (delegated, least-privilege).
71
+ - Use GoogleDriveStorage for Drive workflows (e.g., storing VC artifacts/files in Drive).
102
72
 
103
- ## Contributing
73
+ ## Notes
104
74
 
105
- Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for any bugs or feature requests.
75
+ - WAS zCap requests are signed with Ed25519Signature2020 and require a valid `invocationSigner.id`.
76
+ - There is no implicit fallback between backends; handle errors per backend explicitly in your app.
106
77
 
107
78
  ## License
108
79
 
109
- This project is licensed under the ISC License.
80
+ ISC
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,10 @@
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 './models/WASZcapStorage.js';
8
+ export * from './models/StorageContext.js';
9
+ export * from './utils/createWASSpace.js';
10
+ export * from './utils/getOrCreateAppDID.js';
@@ -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.
@@ -143,7 +143,11 @@ export class CredentialEngine {
143
143
  case 'RECOMMENDATION':
144
144
  if (!vcFileId)
145
145
  throw new Error('vcFileId is required for recommendation');
146
- credential = generateUnsignedRecommendation({ vcId: vcFileId, recommendation: data, issuerDid: issuerId });
146
+ credential = generateUnsignedRecommendation({
147
+ vcId: vcFileId,
148
+ recommendation: data,
149
+ issuerDid: issuerId,
150
+ });
147
151
  break;
148
152
  case 'EMPLOYMENT':
149
153
  credential = generateUnsignedEmployment({ formData: data, issuerDid: issuerId });
@@ -269,7 +273,7 @@ export class CredentialEngine {
269
273
  throw new Error('SEED environment variable not set. Cannot generate or use any DID.');
270
274
  }
271
275
  // Use deterministic keys from environment seed
272
- const { getDidFromEnvSeed } = await import('../utils/decodedSeed');
276
+ const { getDidFromEnvSeed } = await import('../utils/decodedSeed.js');
273
277
  const result = await getDidFromEnvSeed(encodedSeed);
274
278
  keyPair = result.keyPair;
275
279
  didDocument = result.didDocument;