@cooperation/vc-storage 1.0.0 β†’ 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -1,136 +1,109 @@
1
- # Trust Storage Library
1
+ # @cooperation/vc-storage
2
2
 
3
- Store your files using up to three strategies. Currently, we offer the GoogleDriveStorage class, which is designed for storing files in Google Drive. Stay tuned for additional methods coming soon 😊
3
+ **Version**: 1.0.0
4
4
 
5
- ## Installation
6
-
7
- To install the Trust Storage library, you can use either npm or yarn. Run one of the following commands in your project directory:
8
-
9
- ```bash
10
- npm install trust_storage
11
- ```
12
-
13
- or
14
-
15
- ```bash
16
- yarn add trust_storage
17
- ```
18
-
19
- ## Usage
20
-
21
- To use the `GoogleDriveStorage` class in your application, you need to pass an access token that has appropriate permissions for Google Drive operations. You can generate an access token by following these steps:
22
-
23
- 1. Visit the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/).
24
- 2. Enter the scope: `https://www.googleapis.com/auth/drive`.
25
- 3. Copy the accessToken and pass it to the `GoogleDriveStorage` class.
26
-
27
- The `GoogleDriveStorage` class includes two methods:
28
-
29
- - `createFolder()`: It is designed to create a new folder in Google Drive.
30
- - `uploadFile()`: Ensure that the necessary folder has been created or identified where the file will be stored.
31
-
32
- ## Notes
33
-
34
- - This library is a demonstration tool for uploading files to Google Drive.
35
-
36
- ### Your First Code Contribution
37
-
38
- 1. Clone the repository.
39
- 2. Run yarn or npm install to install dependencies.
40
- 3. Create a new branch for your feature or bugfix.
41
- 4. Make your changes.
42
- 5. Commit your changes and push your branch to your fork.
43
- 6. Open a pull request.
44
-
45
- ### Pull Requests
46
-
47
- When you're ready to submit your pull request:
48
-
49
- 1. Ensure your work is aligned with the project's coding standards.
50
- 2. Fill out the pull request template.
51
- 3. Include a clear and detailed description of the changes.
52
- 4. Link any related issues.
53
- 5. Wait for review and address any feedback.
54
-
55
- ## Development Workflow
56
-
57
- ### Setup
5
+ ## Overview
58
6
 
59
- 1. Clone the repository:
60
- ```bash
61
- git clone https://github.com/yourusername/your-repo-name.git
62
- ```
63
- 2. Navigate to the project directory:
64
- ```bash
65
- cd your-repo-name
66
- ```
67
- 3. Install dependencies:
68
- ```bash
69
- npm install
70
- ```
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.
71
8
 
72
- Certainly! Here is the provided text rewritten in `.md` format:
9
+ ## Features
73
10
 
74
- ````markdown
75
- ## Publishing Flow
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).
76
17
 
77
- If you want to publish a new version of the package, please follow these steps:
78
-
79
- ### Request Access
80
-
81
- Ask for access to publish the package in the Slack. Mention the version and any significant changes.
82
-
83
- ### Update Version
84
-
85
- Ensure you update the version in `package.json` according to [Semantic Versioning](https://semver.org/). You can do this manually or using the npm command:
86
-
87
- ```bash
88
- npm version [patch|minor|major]
89
- ```
90
- ````
91
-
92
- ### Ensure Tests Pass
93
-
94
- Run all tests to make sure they are passing:
95
-
96
- ```bash
97
- npm test
98
- ```
99
-
100
- ### Build the Project
18
+ ## Installation
101
19
 
102
- Build the project to ensure all changes are compiled:
20
+ You can install this package via npm:
103
21
 
104
22
  ```bash
105
- npm run build
23
+ npm install @cooperation/vc-storage
106
24
  ```
107
25
 
108
- ### Commit and Push
109
-
110
- Commit and push your changes to the main branch:
26
+ ## Usage
111
27
 
112
- ```bash
113
- git add .
114
- git commit -m "Prepare for release vX.Y.Z"
115
- git push origin main
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);
116
94
  ```
117
95
 
118
- ### Login to npm
96
+ ### Available Storage Strategies
119
97
 
120
- If you are not already logged in, log in to npm using your credentials:
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.
121
102
 
122
- ```bash
123
- npm login
124
- ```
125
-
126
- ### Publish the Package
127
-
128
- Once you have access and everything is set, publish the package:
103
+ ## Contributing
129
104
 
130
- ```bash
131
- npm publish
132
- ```
105
+ Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for any bugs or feature requests.
133
106
 
134
- ### Notify Team
107
+ ## License
135
108
 
136
- Inform the team in the Slack channel that the new version has been published.
109
+ This project is licensed under the ISC License.
@@ -140,21 +140,56 @@ export class GoogleDriveStorage {
140
140
  return claims;
141
141
  }
142
142
  async getAllSessions() {
143
- const rootFolders = await this.findFolders();
144
- const credentialsFolder = rootFolders.find((f) => f.name === 'Credentials');
145
- if (!credentialsFolder)
146
- return [];
147
- const credentialsFolderId = credentialsFolder.id;
148
- const subfolders = await this.findFolders(credentialsFolderId);
149
- const sessionsFolder = subfolders.find((f) => f.name === 'Sessions');
150
- if (!sessionsFolder)
151
- return [];
152
- const sessions = await this.fetcher({
153
- method: 'GET',
154
- headers: {},
155
- url: `https://www.googleapis.com/drive/v3/files?q='${sessionsFolder.id}' in parents and trashed=false&fields=files(id,name,mimeType,parents)`,
156
- });
157
- return sessions;
143
+ try {
144
+ // Find all root folders
145
+ const rootFolders = await this.fetcher({
146
+ method: 'GET',
147
+ headers: {},
148
+ url: `https://www.googleapis.com/drive/v3/files?q='root' in parents and mimeType='application/vnd.google-apps.folder'&trashed=false&fields=files(id,name)`,
149
+ });
150
+ console.log('πŸš€ ~ GoogleDriveStorage ~ getAllSessions ~ rootFolders:', rootFolders);
151
+ // Find the "Credentials" folder
152
+ const credentialsFolder = rootFolders.files.find((f) => f.name === 'Credentials');
153
+ if (!credentialsFolder) {
154
+ return []; // Return an empty array if "Credentials" folder is not found
155
+ }
156
+ const credentialsFolderId = credentialsFolder.id;
157
+ // Find subfolders within the "Credentials" folder
158
+ const subfolders = await this.fetcher({
159
+ method: 'GET',
160
+ headers: {},
161
+ url: `https://www.googleapis.com/drive/v3/files?q='${credentialsFolderId}' in parents and mimeType='application/vnd.google-apps.folder'&trashed=false&fields=files(id,name)`,
162
+ });
163
+ const sessionsFolder = subfolders.files.find((f) => f.name === 'SESSIONs');
164
+ if (!sessionsFolder) {
165
+ return []; // Return an empty array if "SESSIONs" folder is not found
166
+ }
167
+ // Fetch all session files inside the "SESSIONs" folder
168
+ const sessions = await this.fetcher({
169
+ method: 'GET',
170
+ headers: {},
171
+ url: `https://www.googleapis.com/drive/v3/files?q='${sessionsFolder.id}' in parents and trashed=false&fields=files(id,name,mimeType,parents)`,
172
+ });
173
+ const sessionFiles = sessions.files;
174
+ // Fetch the content of each session file
175
+ const sessionContents = await Promise.all(sessionFiles.map(async (file) => {
176
+ // Fetch file content
177
+ const content = await this.fetcher({
178
+ method: 'GET',
179
+ headers: {},
180
+ url: `https://www.googleapis.com/drive/v3/files/${file.id}?alt=media`,
181
+ });
182
+ return {
183
+ content,
184
+ };
185
+ }));
186
+ console.log('πŸš€ ~ GoogleDriveStorage ~ getAllSessions ~ sessionContents:', sessionContents);
187
+ return sessionContents; // Return the list of files with their content
188
+ }
189
+ catch (error) {
190
+ console.error('Error getting session contents:', error);
191
+ return []; // Return an empty array on error
192
+ }
158
193
  }
159
194
  async delete(id) {
160
195
  try {
@@ -12,6 +12,6 @@ export declare class GoogleDriveStorage {
12
12
  findFolders: (id?: string) => Promise<any[]>;
13
13
  findLastFile: (folderId: string) => Promise<any>;
14
14
  getAllClaims(): Promise<any>;
15
- getAllSessions(): Promise<any>;
15
+ getAllSessions(): Promise<any[]>;
16
16
  delete(id: string): Promise<any>;
17
17
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cooperation/vc-storage",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "description": "Sign and store your verifiable credentials.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/types/index.d.ts",