@cooperation/vc-storage 1.0.1 → 1.0.5
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/dist/index.js +2 -1
- package/dist/models/CredentialEngine.js +161 -134
- package/dist/models/GoogleDriveStorage.js +183 -61
- package/dist/types/index.d.ts +2 -1
- package/dist/types/models/CredentialEngine.d.ts +44 -20
- package/dist/types/models/GoogleDriveStorage.d.ts +61 -3
- package/dist/types/utils/credential.d.ts +23 -0
- package/dist/types/utils/digitalbazaar.d.ts +1 -0
- package/dist/types/utils/google.d.ts +14 -0
- package/dist/types/utils/presentation.d.ts +10 -0
- package/dist/types/utils/saveToGoogle.d.ts +4 -4
- package/dist/utils/credential.js +172 -0
- package/dist/utils/digitalbazaar.js +37 -0
- package/dist/utils/google.js +79 -0
- package/dist/utils/presentation.js +48 -0
- package/dist/utils/saveToGoogle.js +12 -0
- package/package.json +5 -2
- package/dist/models/CredentialVerefier.js +0 -36
- package/dist/types/models/CredentialVerefier.d.ts +0 -9
@@ -1,8 +1,25 @@
|
|
1
|
+
import { generateViewLink } from '../utils/google.js';
|
2
|
+
/**
|
3
|
+
* @class GoogleDriveStorage
|
4
|
+
* @description Class to interact with Google Drive API
|
5
|
+
* @param accessToken - Access token to authenticate with Google Drive API
|
6
|
+
* @method createFolder - Create a new folder in Google Drive
|
7
|
+
* @method save - Save data to Google Drive
|
8
|
+
* @method addCommentToFile - Add a comment to a file in Google Drive
|
9
|
+
* @method addCommenterRoleToFile - Add commenter role to a file in Google Drive
|
10
|
+
* @method retrieve - Retrieve a file from Google Drive
|
11
|
+
* @method findFolders - Find folders in Google Drive
|
12
|
+
* @method findLastFile - Find the last file in a folder
|
13
|
+
* @method getAllVCs - Get all verifiable credentials from Google Drive
|
14
|
+
* @method getAllSessions - Get all sessions from Google Drive
|
15
|
+
* @method delete - Delete a file from Google Drive
|
16
|
+
*/
|
1
17
|
export class GoogleDriveStorage {
|
2
18
|
accessToken;
|
3
19
|
constructor(accessToken) {
|
4
20
|
this.accessToken = accessToken;
|
5
21
|
}
|
22
|
+
// Method to fetch data from Google Drive API
|
6
23
|
async fetcher({ method, headers, body, url }) {
|
7
24
|
try {
|
8
25
|
const res = await fetch(url, {
|
@@ -13,18 +30,20 @@ export class GoogleDriveStorage {
|
|
13
30
|
}),
|
14
31
|
body,
|
15
32
|
});
|
33
|
+
// Check for errors in the response
|
16
34
|
const data = await res.json();
|
17
35
|
if (!res.ok) {
|
18
|
-
|
36
|
+
console.error('Error Response:', JSON.stringify(data));
|
37
|
+
throw new Error(data.error.message || 'Unknown error');
|
19
38
|
}
|
20
39
|
return data;
|
21
40
|
}
|
22
41
|
catch (error) {
|
23
|
-
console.error('Error fetching data:', error);
|
42
|
+
console.error('Error fetching data:', error.message);
|
24
43
|
throw error;
|
25
44
|
}
|
26
45
|
}
|
27
|
-
//
|
46
|
+
// Method to search for files in Google Drive by query
|
28
47
|
async searchFiles(query) {
|
29
48
|
const result = await this.fetcher({
|
30
49
|
method: 'GET',
|
@@ -50,28 +69,103 @@ export class GoogleDriveStorage {
|
|
50
69
|
}
|
51
70
|
async save(data, folderId) {
|
52
71
|
try {
|
72
|
+
// Define file metadata, ensure correct folder is assigned
|
53
73
|
const fileMetadata = {
|
54
74
|
name: data.fileName,
|
55
|
-
|
56
|
-
|
75
|
+
parents: [folderId], // Specify the folder ID
|
76
|
+
mimeType: 'application/json', // Use provided MIME type or default to JSON
|
57
77
|
};
|
78
|
+
let uploadUrl = 'https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart';
|
58
79
|
const formData = new FormData();
|
59
80
|
formData.append('metadata', new Blob([JSON.stringify(fileMetadata)], { type: 'application/json' }));
|
60
|
-
formData.append('file', data.body);
|
81
|
+
formData.append('file', new Blob([data.body], { type: fileMetadata.mimeType })); // Set file data and MIME type
|
61
82
|
const file = await this.fetcher({
|
62
83
|
method: 'POST',
|
63
84
|
headers: {},
|
64
85
|
body: formData,
|
65
|
-
url:
|
86
|
+
url: uploadUrl,
|
66
87
|
});
|
67
|
-
console.log('File uploaded:', file.id);
|
88
|
+
console.log('File uploaded successfully:', file.id);
|
68
89
|
return file;
|
69
90
|
}
|
70
91
|
catch (error) {
|
71
|
-
console.error('Error uploading file:', error);
|
92
|
+
console.error('Error uploading file:', error.message);
|
72
93
|
return null;
|
73
94
|
}
|
74
95
|
}
|
96
|
+
/**
|
97
|
+
* Add comment to VC
|
98
|
+
* @param fileId - th id of VC file
|
99
|
+
* @returns
|
100
|
+
*/
|
101
|
+
async addCommentToFile(vcFileId, recommendationFileId) {
|
102
|
+
if (!recommendationFileId || !vcFileId || !this.accessToken) {
|
103
|
+
throw new Error('Missing required parameters: fileId, commentText, or accessToken');
|
104
|
+
}
|
105
|
+
const url = `https://www.googleapis.com/drive/v3/files/${vcFileId}/comments?fields=id,content,createdTime`;
|
106
|
+
const body = {
|
107
|
+
content: generateViewLink(recommendationFileId),
|
108
|
+
};
|
109
|
+
try {
|
110
|
+
const response = await fetch(url, {
|
111
|
+
method: 'POST',
|
112
|
+
headers: {
|
113
|
+
Authorization: `Bearer ${this.accessToken}`,
|
114
|
+
'Content-Type': 'application/json',
|
115
|
+
},
|
116
|
+
body: JSON.stringify(body),
|
117
|
+
});
|
118
|
+
if (!response.ok) {
|
119
|
+
const errorDetails = await response.json();
|
120
|
+
throw new Error(`Failed to add comment: ${JSON.stringify(errorDetails)}`);
|
121
|
+
}
|
122
|
+
const result = await response.json();
|
123
|
+
console.log('Comment added successfully:', result);
|
124
|
+
return result;
|
125
|
+
}
|
126
|
+
catch (error) {
|
127
|
+
console.error('Error adding comment to file:', error);
|
128
|
+
throw error;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
/**
|
132
|
+
* Add commenter role to a file
|
133
|
+
* @param fileId
|
134
|
+
* @returns
|
135
|
+
*/
|
136
|
+
async addCommenterRoleToFile(fileId) {
|
137
|
+
const url = `https://www.googleapis.com/drive/v3/files/${fileId}/permissions`;
|
138
|
+
const body = {
|
139
|
+
role: 'commenter',
|
140
|
+
type: 'anyone',
|
141
|
+
};
|
142
|
+
try {
|
143
|
+
const response = await fetch(url, {
|
144
|
+
method: 'POST',
|
145
|
+
headers: {
|
146
|
+
Authorization: `Bearer ${this.accessToken}`,
|
147
|
+
'Content-Type': 'application/json',
|
148
|
+
},
|
149
|
+
body: JSON.stringify(body),
|
150
|
+
});
|
151
|
+
if (!response.ok) {
|
152
|
+
const errorDetails = await response.json();
|
153
|
+
throw new Error(`Failed to add permission: ${JSON.stringify(errorDetails)}`);
|
154
|
+
}
|
155
|
+
const result = await response.json();
|
156
|
+
console.log('Permission added successfully:', result);
|
157
|
+
return result;
|
158
|
+
}
|
159
|
+
catch (error) {
|
160
|
+
console.error('Error adding permission:', error.message);
|
161
|
+
throw error;
|
162
|
+
}
|
163
|
+
}
|
164
|
+
/**
|
165
|
+
* Get file from google drive by id
|
166
|
+
* @param id
|
167
|
+
* @returns file content
|
168
|
+
*/
|
75
169
|
async retrieve(id) {
|
76
170
|
try {
|
77
171
|
const file = await this.fetcher({
|
@@ -79,7 +173,6 @@ export class GoogleDriveStorage {
|
|
79
173
|
headers: {},
|
80
174
|
url: `https://www.googleapis.com/drive/v3/files/${id}?alt=media`,
|
81
175
|
});
|
82
|
-
console.log('File retrieved:', file);
|
83
176
|
return file;
|
84
177
|
}
|
85
178
|
catch (error) {
|
@@ -87,13 +180,23 @@ export class GoogleDriveStorage {
|
|
87
180
|
return null;
|
88
181
|
}
|
89
182
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
183
|
+
/**
|
184
|
+
* Get folder by folderId, if folderId == null you will have them all
|
185
|
+
* @param id [Optional]
|
186
|
+
* @returns
|
187
|
+
*/
|
188
|
+
findFolders = async (folderId) => {
|
189
|
+
const query = folderId
|
190
|
+
? `'${folderId}' in parents and mimeType='application/vnd.google-apps.folder'`
|
93
191
|
: `'root' in parents and mimeType='application/vnd.google-apps.folder'`;
|
94
192
|
const folders = await this.searchFiles(query);
|
95
193
|
return folders.filter((file) => file.mimeType === 'application/vnd.google-apps.folder');
|
96
194
|
};
|
195
|
+
/**
|
196
|
+
* Get the last file from folder by folderId
|
197
|
+
* @param folderId
|
198
|
+
* @returns last file content from folder by folderId
|
199
|
+
*/
|
97
200
|
findLastFile = async (folderId) => {
|
98
201
|
try {
|
99
202
|
const files = await this.searchFiles(`'${folderId}' in parents`);
|
@@ -110,11 +213,30 @@ export class GoogleDriveStorage {
|
|
110
213
|
content,
|
111
214
|
};
|
112
215
|
}));
|
216
|
+
// Find the latest file based on the timestamp in the file name
|
113
217
|
const latestFile = fileContents.reduce((latest, current) => {
|
114
|
-
|
115
|
-
const
|
218
|
+
// Check if the file name has the expected structure
|
219
|
+
const nameParts = current.name.split('_');
|
220
|
+
let currentTimestampStr;
|
221
|
+
if (nameParts.length === 3) {
|
222
|
+
// Structure with UUID: `${uuid}_${type}_${timestamp}.json`
|
223
|
+
currentTimestampStr = nameParts[2];
|
224
|
+
}
|
225
|
+
else if (nameParts.length === 2) {
|
226
|
+
// Structure without UUID: `${type}_${timestamp}.json`
|
227
|
+
currentTimestampStr = nameParts[1];
|
228
|
+
}
|
229
|
+
else {
|
230
|
+
// Log warning and skip this file if the structure is not as expected
|
231
|
+
console.warn(`Unexpected file name format: ${current.name}`);
|
232
|
+
return latest;
|
233
|
+
}
|
234
|
+
// Parse the timestamp from the file name
|
235
|
+
const latestTimestamp = latest ? parseInt(latest.name.split('_').pop().split('.')[0], 10) : 0;
|
236
|
+
const currentTimestamp = parseInt(currentTimestampStr.split('.')[0], 10);
|
116
237
|
return currentTimestamp > latestTimestamp ? current : latest;
|
117
238
|
}, null);
|
239
|
+
// Return the content of the latest file
|
118
240
|
return latestFile ? latestFile.content : null;
|
119
241
|
}
|
120
242
|
catch (error) {
|
@@ -122,75 +244,75 @@ export class GoogleDriveStorage {
|
|
122
244
|
return null;
|
123
245
|
}
|
124
246
|
};
|
125
|
-
async
|
126
|
-
const rootFolders = await this.findFolders();
|
127
|
-
const credentialsFolder = rootFolders.find((f) => f.name === 'Credentials');
|
128
|
-
if (!credentialsFolder)
|
129
|
-
return [];
|
130
|
-
const credentialsFolderId = credentialsFolder.id;
|
131
|
-
const subfolders = await this.findFolders(credentialsFolderId);
|
132
|
-
const signedVCFolder = subfolders.find((f) => f.name === 'VCs');
|
133
|
-
if (!signedVCFolder)
|
134
|
-
return [];
|
135
|
-
const claims = await this.fetcher({
|
136
|
-
method: 'GET',
|
137
|
-
headers: {},
|
138
|
-
url: `https://www.googleapis.com/drive/v3/files?q='${signedVCFolder.id}' in parents and trashed=false&fields=files(id,name,mimeType,parents)`,
|
139
|
-
});
|
140
|
-
return claims;
|
141
|
-
}
|
142
|
-
async getAllSessions() {
|
247
|
+
async getFileComments(fileId) {
|
143
248
|
try {
|
144
|
-
//
|
145
|
-
const
|
249
|
+
// Fetch comments on the file using Google Drive API
|
250
|
+
const commentsResponse = await this.fetcher({
|
146
251
|
method: 'GET',
|
147
252
|
headers: {},
|
148
|
-
url: `https://www.googleapis.com/drive/v3/files?
|
253
|
+
url: `https://www.googleapis.com/drive/v3/files/${fileId}/comments?fields=comments(content,author/displayName,createdTime)`,
|
149
254
|
});
|
150
|
-
|
151
|
-
//
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
255
|
+
// Return the comments data if available
|
256
|
+
return commentsResponse.comments || []; // Return an empty array if no comments
|
257
|
+
}
|
258
|
+
catch (error) {
|
259
|
+
console.error(`Failed to fetch comments for file ID: ${fileId}`, error);
|
260
|
+
return []; // Handle errors by returning an empty array or some error indication
|
261
|
+
}
|
262
|
+
}
|
263
|
+
/**
|
264
|
+
* Get all files content for the specified type ('KEYPAIRs' | 'VCs' | 'SESSIONs' | 'DIDs' | 'RECOMMENDATIONs')
|
265
|
+
* @param type
|
266
|
+
* @returns
|
267
|
+
*/
|
268
|
+
async getAllFilesByType(type) {
|
269
|
+
try {
|
270
|
+
// Step 1: Find all root folders
|
271
|
+
const rootFolders = await this.findFolders();
|
272
|
+
const credentialsFolder = rootFolders.find((f) => f.name === 'Credentials');
|
273
|
+
if (!credentialsFolder)
|
274
|
+
return [];
|
156
275
|
const credentialsFolderId = credentialsFolder.id;
|
157
|
-
// Find
|
158
|
-
const subfolders = await this.
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
const
|
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({
|
276
|
+
// Step 2: Find the subfolder corresponding to the specified type
|
277
|
+
const subfolders = await this.findFolders(credentialsFolderId);
|
278
|
+
const targetFolder = subfolders.find((f) => f.name === type);
|
279
|
+
if (!targetFolder)
|
280
|
+
return [];
|
281
|
+
// Step 3: Fetch all files in the specified folder
|
282
|
+
const filesResponse = await this.fetcher({
|
169
283
|
method: 'GET',
|
170
284
|
headers: {},
|
171
|
-
url: `https://www.googleapis.com/drive/v3/files?q='${
|
285
|
+
url: `https://www.googleapis.com/drive/v3/files?q='${targetFolder.id}' in parents and trashed=false&fields=files(id,name,mimeType,parents)`,
|
172
286
|
});
|
173
|
-
const
|
174
|
-
// Fetch the content of each
|
175
|
-
const
|
287
|
+
const files = filesResponse.files;
|
288
|
+
// Step 4: Fetch the content and comments of each file
|
289
|
+
const fileContents = await Promise.all(files.map(async (file) => {
|
176
290
|
// Fetch file content
|
177
291
|
const content = await this.fetcher({
|
178
292
|
method: 'GET',
|
179
293
|
headers: {},
|
180
294
|
url: `https://www.googleapis.com/drive/v3/files/${file.id}?alt=media`,
|
181
295
|
});
|
296
|
+
// Fetch file comments (if applicable)
|
297
|
+
const comments = await this.getFileComments(file.id);
|
182
298
|
return {
|
299
|
+
name: file.name,
|
183
300
|
content,
|
301
|
+
comments: comments.map((comment) => comment.content),
|
184
302
|
};
|
185
303
|
}));
|
186
|
-
|
187
|
-
return sessionContents; // Return the list of files with their content
|
304
|
+
return fileContents; // Return the list of files with their content and comments
|
188
305
|
}
|
189
306
|
catch (error) {
|
190
|
-
console.error(
|
307
|
+
console.error(`Error getting files of type ${type}:`, error);
|
191
308
|
return []; // Return an empty array on error
|
192
309
|
}
|
193
310
|
}
|
311
|
+
/**
|
312
|
+
* Delete file by id
|
313
|
+
* @param id
|
314
|
+
* @returns
|
315
|
+
*/
|
194
316
|
async delete(id) {
|
195
317
|
try {
|
196
318
|
const response = await this.fetcher({
|
package/dist/types/index.d.ts
CHANGED
@@ -1,12 +1,24 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { DidDocument, KeyPair, VerifiableCredential } from '../../types/credential.js';
|
2
|
+
/**
|
3
|
+
* Class representing the Credential Engine.
|
4
|
+
* @class CredentialEngine
|
5
|
+
* @param {string} accessToken - The access token for the user.
|
6
|
+
* @classdesc Credential Engine class to create DIDs and VCs.
|
7
|
+
* @method createDID - Create a new DID with Digital Bazaar's Ed25519VerificationKey2020 key pair.
|
8
|
+
* @method createWalletDID - Create a new DID with user metamask address as controller.
|
9
|
+
* @method signVC - Sign a Verifiable Credential (VC).
|
10
|
+
* @method verifyCredential - Verify a Verifiable Credential (VC).
|
11
|
+
* @method createPresentation - Create a Verifiable Presentation (VP).
|
12
|
+
* @method signPresentation - Sign a Verifiable Presentation (VP).
|
13
|
+
*/
|
3
14
|
export declare class CredentialEngine {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
private
|
15
|
+
private uuid;
|
16
|
+
private storage;
|
17
|
+
private keyPair;
|
18
|
+
constructor(accessToken: string);
|
19
|
+
private getKeyPair;
|
20
|
+
private generateKeyPair;
|
21
|
+
private verifyCreds;
|
10
22
|
/**
|
11
23
|
* Create a new DID with Digital Bazaar's Ed25519VerificationKey2020 key pair.
|
12
24
|
* @returns {Promise<{didDocument: object, keyPair: object}>} The created DID document and key pair.
|
@@ -26,20 +38,32 @@ export declare class CredentialEngine {
|
|
26
38
|
didDocument: DidDocument;
|
27
39
|
keyPair: KeyPair;
|
28
40
|
}>;
|
29
|
-
/**
|
30
|
-
* Create an unsigned Verifiable Credential (VC)
|
31
|
-
* @param {object} formData - The form data to include in the VC.
|
32
|
-
* @param {string} issuerDid - The DID of the issuer.
|
33
|
-
* @returns {Promise<object>} The created unsigned VC.
|
34
|
-
* @throws Will throw an error if unsigned VC creation fails.
|
35
|
-
*/
|
36
|
-
createUnsignedVC(formData: FormDataI, issuerDid: string): Promise<Credential>;
|
37
41
|
/**
|
38
42
|
* Sign a Verifiable Credential (VC)
|
39
|
-
* @param {
|
40
|
-
* @param {
|
41
|
-
* @
|
43
|
+
* @param {'VC' | 'RECOMMENDATION'} type - The signature type.
|
44
|
+
* @param {string} issuerId - The ID of the issuer [currently we put it as the did id]
|
45
|
+
* @param {KeyPair} keyPair - The key pair to use for signing.
|
46
|
+
* @returns {Promise<Credential>} The signed VC.
|
42
47
|
* @throws Will throw an error if VC signing fails.
|
43
48
|
*/
|
44
|
-
signVC(
|
49
|
+
signVC(formData: any, type: 'VC' | 'RECOMMENDATION', keyPair: KeyPair, issuerId: string): Promise<any>;
|
50
|
+
/**
|
51
|
+
* Verify a Verifiable Credential (VC)
|
52
|
+
* @param {object} credential - The Verifiable Credential to verify.
|
53
|
+
* @returns {Promise<boolean>} The verification result.
|
54
|
+
* @throws Will throw an error if VC verification fails.
|
55
|
+
*/
|
56
|
+
verifyCredential(credential: VerifiableCredential): Promise<boolean>;
|
57
|
+
/**
|
58
|
+
* Create a Verifiable Presentation (VP)
|
59
|
+
* @param verifiableCredential
|
60
|
+
* @returns
|
61
|
+
*/
|
62
|
+
createPresentation(verifiableCredential: VerifiableCredential[]): Promise<any>;
|
63
|
+
/**
|
64
|
+
* Sign a Verifiable Presentation (VP)
|
65
|
+
* @param presentation
|
66
|
+
* @returns
|
67
|
+
*/
|
68
|
+
signPresentation(presentation: any): Promise<any>;
|
45
69
|
}
|
@@ -1,4 +1,24 @@
|
|
1
1
|
import { DataToSaveI } from '../../types';
|
2
|
+
interface FileContent {
|
3
|
+
name: string;
|
4
|
+
content: any;
|
5
|
+
comments: string[];
|
6
|
+
}
|
7
|
+
/**
|
8
|
+
* @class GoogleDriveStorage
|
9
|
+
* @description Class to interact with Google Drive API
|
10
|
+
* @param accessToken - Access token to authenticate with Google Drive API
|
11
|
+
* @method createFolder - Create a new folder in Google Drive
|
12
|
+
* @method save - Save data to Google Drive
|
13
|
+
* @method addCommentToFile - Add a comment to a file in Google Drive
|
14
|
+
* @method addCommenterRoleToFile - Add commenter role to a file in Google Drive
|
15
|
+
* @method retrieve - Retrieve a file from Google Drive
|
16
|
+
* @method findFolders - Find folders in Google Drive
|
17
|
+
* @method findLastFile - Find the last file in a folder
|
18
|
+
* @method getAllVCs - Get all verifiable credentials from Google Drive
|
19
|
+
* @method getAllSessions - Get all sessions from Google Drive
|
20
|
+
* @method delete - Delete a file from Google Drive
|
21
|
+
*/
|
2
22
|
export declare class GoogleDriveStorage {
|
3
23
|
private accessToken;
|
4
24
|
constructor(accessToken: string);
|
@@ -8,10 +28,48 @@ export declare class GoogleDriveStorage {
|
|
8
28
|
save(data: DataToSaveI, folderId: string): Promise<{
|
9
29
|
id: string;
|
10
30
|
} | null>;
|
31
|
+
/**
|
32
|
+
* Add comment to VC
|
33
|
+
* @param fileId - th id of VC file
|
34
|
+
* @returns
|
35
|
+
*/
|
36
|
+
addCommentToFile(vcFileId: string, recommendationFileId: string): Promise<any>;
|
37
|
+
/**
|
38
|
+
* Add commenter role to a file
|
39
|
+
* @param fileId
|
40
|
+
* @returns
|
41
|
+
*/
|
42
|
+
addCommenterRoleToFile(fileId: string): Promise<any>;
|
43
|
+
/**
|
44
|
+
* Get file from google drive by id
|
45
|
+
* @param id
|
46
|
+
* @returns file content
|
47
|
+
*/
|
11
48
|
retrieve(id: string): Promise<any>;
|
12
|
-
|
49
|
+
/**
|
50
|
+
* Get folder by folderId, if folderId == null you will have them all
|
51
|
+
* @param id [Optional]
|
52
|
+
* @returns
|
53
|
+
*/
|
54
|
+
findFolders: (folderId?: string) => Promise<any[]>;
|
55
|
+
/**
|
56
|
+
* Get the last file from folder by folderId
|
57
|
+
* @param folderId
|
58
|
+
* @returns last file content from folder by folderId
|
59
|
+
*/
|
13
60
|
findLastFile: (folderId: string) => Promise<any>;
|
14
|
-
|
15
|
-
|
61
|
+
getFileComments(fileId: string): Promise<any>;
|
62
|
+
/**
|
63
|
+
* Get all files content for the specified type ('KEYPAIRs' | 'VCs' | 'SESSIONs' | 'DIDs' | 'RECOMMENDATIONs')
|
64
|
+
* @param type
|
65
|
+
* @returns
|
66
|
+
*/
|
67
|
+
getAllFilesByType(type: 'KEYPAIRs' | 'VCs' | 'SESSIONs' | 'DIDs' | 'RECOMMENDATIONs'): Promise<FileContent[]>;
|
68
|
+
/**
|
69
|
+
* Delete file by id
|
70
|
+
* @param id
|
71
|
+
* @returns
|
72
|
+
*/
|
16
73
|
delete(id: string): Promise<any>;
|
17
74
|
}
|
75
|
+
export {};
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { KeyPair, DidDocument, FormDataI, RecommendationCredential, Credential, RecommendationFormDataI, VerifiableCredential } from '../../types/credential';
|
2
|
+
/**
|
3
|
+
* Create a DID document using the provided key pair.
|
4
|
+
* @param {object} keyPair - The key pair used to create the DID document.
|
5
|
+
* @returns {Promise<object>} The created DID document.
|
6
|
+
*/
|
7
|
+
export declare const generateDIDSchema: (keyPair: KeyPair) => Promise<DidDocument>;
|
8
|
+
/**
|
9
|
+
* Generate an unsigned Verifiable Credential (VC)
|
10
|
+
* @param {object} formData - The form data to include in the VC.
|
11
|
+
* @param {string} issuerDid - The DID of the issuer.
|
12
|
+
* @param {string} vcId - The ID of the credential generated by uuidv4()
|
13
|
+
* @returns {Promise<object>} The created unsigned VC.
|
14
|
+
* @throws Will throw an error if unsigned VC creation fails.
|
15
|
+
*/
|
16
|
+
export declare function generateUnsignedVC(formData: FormDataI, issuerDid: string, vcId: string): Credential;
|
17
|
+
export declare function generateUnsignedRecommendation(recommendation: RecommendationFormDataI, issuerDid: string): RecommendationCredential;
|
18
|
+
/**
|
19
|
+
* Extracts the keypair from a Verifiable Credential
|
20
|
+
* @param {Object} credential - The signed Verifiable Credential
|
21
|
+
* @returns {Ed25519VerificationKey2020} keyPair - The generated keypair object
|
22
|
+
*/
|
23
|
+
export declare function extractKeyPairFromCredential(credential: VerifiableCredential): Promise<KeyPair>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const customDocumentLoader: (url: any) => Promise<any>;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { GoogleDriveStorage } from '../models/GoogleDriveStorage.js';
|
2
|
+
/**
|
3
|
+
* keyFile name = {uuid}-type-timestamp // we need that
|
4
|
+
* vc.id = urn-uuid-{uuid} // we got that
|
5
|
+
* Save data to Google Drive in the specified folder type.
|
6
|
+
* @param {object} data - The data to save.
|
7
|
+
* @param {'VC' | 'DID' | 'SESSION' | 'RECOMMENDATION' | 'KEYPAIR'} type - The type of data being saved.
|
8
|
+
* @returns {Promise<object>} - The file object saved to Google Drive.
|
9
|
+
* @param {string} uuid - Optional unique identifier for the VC.
|
10
|
+
* @throws Will throw an error if the save operation fails.
|
11
|
+
*/
|
12
|
+
export declare function saveToGoogleDrive(storage: GoogleDriveStorage, data: any, type: 'VC' | 'DID' | 'SESSION' | 'RECOMMENDATION' | 'KEYPAIR', uuid?: string): Promise<object>;
|
13
|
+
export declare function generateViewLink(fileId: string): string;
|
14
|
+
export declare function extractGoogleDriveFileId(url: string): string | null;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* Create and sign a Verifiable Presentation (VP) from a given Verifiable Credential (VC) file and any associated recommendations.
|
3
|
+
* @param {string} accessTokens - The access tokens for the user.
|
4
|
+
* @param {string} vcFileId - The ID of the Verifiable Credential (VC) file in Google Drive.
|
5
|
+
* @returns {Promise<{ signedPresentation: object } | null>} - The signed Verifiable Presentation (VP) or null if an error occurs.
|
6
|
+
* @throws Will throw an error if the VC is not found, a matching key pair cannot be located, or any part of the signing process fails.
|
7
|
+
*/
|
8
|
+
export declare const createAndSignVerifiablePresentation: (accessTokens: string, vcFileId: string) => Promise<{
|
9
|
+
signedPresentation: object;
|
10
|
+
} | null>;
|
@@ -1,10 +1,10 @@
|
|
1
|
+
import { GoogleDriveStorage } from '../models/GoogleDriveStorage.js';
|
1
2
|
/**
|
2
3
|
* Save data to Google Drive in the specified folder type.
|
3
4
|
* @param {object} data - The data to save.
|
4
5
|
* @param {'VC' | 'DID' | 'UnsignedVC'} type - The type of data being saved.
|
6
|
+
* @returns {Promise<object>} - The file object saved to Google Drive.
|
5
7
|
* @throws Will throw an error if the save operation fails.
|
6
8
|
*/
|
7
|
-
|
8
|
-
export declare function
|
9
|
-
id: string;
|
10
|
-
}>;
|
9
|
+
export declare function saveToGoogleDrive(storage: GoogleDriveStorage, data: any, type: 'VC' | 'DID' | 'SESSION' | 'RECOMMENDATION'): Promise<object>;
|
10
|
+
export declare function generateViewLink(fileId: string): string;
|