@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 +61 -90
- package/app.config.js +1 -0
- package/dist/index.js +5 -1
- package/dist/models/CredentialEngine.js +7 -3
- package/dist/models/GoogleDriveStorage.js +121 -273
- package/dist/models/Resume.js +16 -4
- package/dist/models/StorageContext.js +15 -50
- package/dist/models/WASStorage.js +71 -0
- package/dist/models/WASZcapStorage.js +70 -0
- package/dist/scripts/test-was.js +61 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/CredentialEngine.d.ts +1 -1
- package/dist/types/models/GoogleDriveStorage.d.ts +31 -55
- package/dist/types/models/Resume.d.ts +3 -2
- package/dist/types/models/StorageContext.d.ts +16 -0
- package/dist/types/models/WASStorage.d.ts +30 -0
- package/dist/types/models/WASZcapStorage.d.ts +41 -0
- package/dist/types/scripts/test-was.d.ts +1 -0
- package/dist/types/utils/createWASSpace.d.ts +9 -0
- package/dist/types/utils/credential.d.ts +1 -1
- package/dist/types/utils/getOrCreateAppDID.d.ts +11 -0
- package/dist/types/utils/google.d.ts +1 -1
- package/dist/utils/createWASSpace.js +27 -0
- package/dist/utils/credential.js +7 -16
- package/dist/utils/getOrCreateAppDID.js +22 -0
- package/dist/utils/google.js +1 -1
- package/package.json +9 -3
- package/dist/types/utils/presentation.d.ts +0 -10
- package/dist/utils/presentation.js +0 -45
package/README.md
CHANGED
@@ -1,109 +1,80 @@
|
|
1
1
|
# @cooperation/vc-storage
|
2
2
|
|
3
|
-
|
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
|
-
##
|
5
|
+
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
```bash
|
8
|
+
npm install @cooperation/vc-storage
|
9
|
+
```
|
8
10
|
|
9
|
-
##
|
11
|
+
## Exports (selected)
|
10
12
|
|
11
|
-
-
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-
|
15
|
-
|
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
|
-
##
|
19
|
+
## Storage factory
|
19
20
|
|
20
|
-
|
21
|
+
```ts
|
22
|
+
import { createStorage } from '@cooperation/vc-storage';
|
21
23
|
|
22
|
-
|
23
|
-
|
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
|
-
##
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
68
|
+
## Choosing a backend
|
97
69
|
|
98
|
-
|
99
|
-
|
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
|
-
##
|
73
|
+
## Notes
|
104
74
|
|
105
|
-
|
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
|
-
|
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({
|
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;
|