@cooperation/vc-storage 1.0.31 → 1.0.33
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/models/CredentialEngine.js +6 -1
- package/dist/models/GoogleDriveStorage.js +36 -0
- package/dist/tests/email.test.js +20 -1
- package/dist/types/models/CredentialEngine.d.ts +1 -1
- package/dist/types/models/GoogleDriveStorage.d.ts +9 -0
- package/dist/types/utils/decodedSeed.d.ts +1 -1
- package/dist/utils/decodedSeed.js +1 -2
- package/package.json +1 -1
- package/dist/tests/testEmailVC.js +0 -29
- package/dist/types/tests/testEmailVC.d.ts +0 -1
@@ -248,13 +248,18 @@ export class CredentialEngine {
|
|
248
248
|
try {
|
249
249
|
let keyPair;
|
250
250
|
let didDocument;
|
251
|
+
// Check if VC already exists
|
252
|
+
const existing = await this.storage.checkEmailExists(email);
|
253
|
+
if (existing) {
|
254
|
+
return { signedVC: existing.data, fileId: existing.id };
|
255
|
+
}
|
251
256
|
// Require SEED from environment
|
252
257
|
if (!encodedSeed) {
|
253
258
|
throw new Error('SEED environment variable not set. Cannot generate or use any DID.');
|
254
259
|
}
|
255
260
|
// Use deterministic keys from environment seed
|
256
261
|
const { getDidFromEnvSeed } = await import('../utils/decodedSeed');
|
257
|
-
const result = await getDidFromEnvSeed();
|
262
|
+
const result = await getDidFromEnvSeed(encodedSeed);
|
258
263
|
keyPair = result.keyPair;
|
259
264
|
didDocument = result.didDocument;
|
260
265
|
console.log('Using DID from environment seed:', didDocument.id);
|
@@ -641,4 +641,40 @@ export class GoogleDriveStorage {
|
|
641
641
|
return [];
|
642
642
|
}
|
643
643
|
}
|
644
|
+
/**
|
645
|
+
* Check if an email VC exists and return its content
|
646
|
+
* @param email - The email address to check
|
647
|
+
* @returns {Promise<{data: any, id: string} | null>} - The email VC content and ID if exists, null otherwise
|
648
|
+
*/
|
649
|
+
async checkEmailExists(email) {
|
650
|
+
try {
|
651
|
+
// Get root folders
|
652
|
+
const rootFolders = await this.findFolders();
|
653
|
+
// Find Credentials folder
|
654
|
+
const credentialsFolder = rootFolders.find((f) => f.name === 'Credentials');
|
655
|
+
if (!credentialsFolder) {
|
656
|
+
console.log('Credentials folder not found');
|
657
|
+
return null;
|
658
|
+
}
|
659
|
+
// Find EMAIL_VC subfolder
|
660
|
+
const subfolders = await this.findFolders(credentialsFolder.id);
|
661
|
+
const emailVcFolder = subfolders.find((f) => f.name === 'EMAIL_VC');
|
662
|
+
if (!emailVcFolder) {
|
663
|
+
console.log('EMAIL_VC folder not found');
|
664
|
+
return null;
|
665
|
+
}
|
666
|
+
// Search for file with exact email name (no extension)
|
667
|
+
const files = await this.searchFiles(`'${emailVcFolder.id}' in parents and name='${email}' and mimeType='application/json'`);
|
668
|
+
if (files.length === 0) {
|
669
|
+
return null;
|
670
|
+
}
|
671
|
+
// Get the content of the email VC
|
672
|
+
const emailVC = await this.retrieve(files[0].id);
|
673
|
+
return emailVC;
|
674
|
+
}
|
675
|
+
catch (error) {
|
676
|
+
console.error('Error checking email existence:', error);
|
677
|
+
return null;
|
678
|
+
}
|
679
|
+
}
|
644
680
|
}
|
package/dist/tests/email.test.js
CHANGED
@@ -11,8 +11,14 @@ async function testEmailVC() {
|
|
11
11
|
const testEmail = 'test@example.com';
|
12
12
|
console.log('Starting email VC generation test...');
|
13
13
|
console.log('Test email:', testEmail);
|
14
|
+
// First check if email VC exists
|
15
|
+
console.log('\nChecking if email VC exists...');
|
16
|
+
const existingVC = await storage.checkEmailExists(testEmail);
|
17
|
+
console.log('🚀 ~ testEmailVC ~ existingVC:', existingVC);
|
18
|
+
console.log('Existing VC check:', existingVC ? 'Found' : 'Not found');
|
19
|
+
const encodedSeed = 'z1AdiEjvNdC18HdruehySWKe4HnsXdUqCXMYPEs1fQ8cY2S'; // Replace with your actual encoded seed
|
14
20
|
// Generate and sign the email VC
|
15
|
-
const result = await engine.generateAndSignEmailVC(testEmail);
|
21
|
+
const result = await engine.generateAndSignEmailVC(testEmail, encodedSeed);
|
16
22
|
console.log('\nTest Results:');
|
17
23
|
console.log('-------------');
|
18
24
|
console.log('File ID:', result.fileId);
|
@@ -21,6 +27,19 @@ async function testEmailVC() {
|
|
21
27
|
console.log('\nRetrieving VC from storage...');
|
22
28
|
const retrievedVC = await storage.retrieve(result.fileId);
|
23
29
|
console.log('Retrieved VC:', retrievedVC ? 'Success' : 'Failed');
|
30
|
+
// Test checkEmailExists again after creation
|
31
|
+
console.log('\nChecking if email VC exists after creation...');
|
32
|
+
const newExistingVC = await storage.checkEmailExists(testEmail);
|
33
|
+
console.log('Existing VC check after creation:', newExistingVC ? 'Found' : 'Not found');
|
34
|
+
if (newExistingVC) {
|
35
|
+
console.log('VC Content:', JSON.stringify(newExistingVC.data, null, 2));
|
36
|
+
console.log('VC ID:', newExistingVC.id);
|
37
|
+
}
|
38
|
+
// Test with non-existent email
|
39
|
+
console.log('\nTesting with non-existent email...');
|
40
|
+
const nonExistentEmail = 'nonexistent@example.com';
|
41
|
+
const nonExistentVC = await storage.checkEmailExists(nonExistentEmail);
|
42
|
+
console.log('Non-existent email check:', nonExistentVC ? 'Found (unexpected)' : 'Not found (expected)');
|
24
43
|
console.log('\nTest completed successfully!');
|
25
44
|
}
|
26
45
|
catch (error) {
|
@@ -83,7 +83,7 @@ export declare class CredentialEngine {
|
|
83
83
|
* @param {string} email - The email address to create the VC for
|
84
84
|
* @returns {Promise<{signedVC: any, fileId: string}>} The signed VC and its Google Drive file ID
|
85
85
|
*/
|
86
|
-
generateAndSignEmailVC(email: string): Promise<{
|
86
|
+
generateAndSignEmailVC(email: string, encodedSeed: string): Promise<{
|
87
87
|
signedVC: any;
|
88
88
|
fileId: string;
|
89
89
|
}>;
|
@@ -90,5 +90,14 @@ export declare class GoogleDriveStorage {
|
|
90
90
|
update(fileId: string, data: any): Promise<any>;
|
91
91
|
getFileIdsFromAppDataFolder(): Promise<any>;
|
92
92
|
getAllFilesData(): Promise<any>;
|
93
|
+
/**
|
94
|
+
* Check if an email VC exists and return its content
|
95
|
+
* @param email - The email address to check
|
96
|
+
* @returns {Promise<{data: any, id: string} | null>} - The email VC content and ID if exists, null otherwise
|
97
|
+
*/
|
98
|
+
checkEmailExists(email: string): Promise<{
|
99
|
+
data: any;
|
100
|
+
id: string;
|
101
|
+
} | null>;
|
93
102
|
}
|
94
103
|
export {};
|
@@ -26,9 +26,8 @@ export async function decodeSeed(encodedSeed) {
|
|
26
26
|
throw error;
|
27
27
|
}
|
28
28
|
}
|
29
|
-
export const getDidFromEnvSeed = async () => {
|
29
|
+
export const getDidFromEnvSeed = async (encodedSeed) => {
|
30
30
|
// Get seed from environment variable
|
31
|
-
const encodedSeed = process.env.SEED;
|
32
31
|
if (!encodedSeed) {
|
33
32
|
throw new Error('SEED environment variable not set');
|
34
33
|
}
|
package/package.json
CHANGED
@@ -1,29 +0,0 @@
|
|
1
|
-
import { CredentialEngine } from '../models/CredentialEngine.js';
|
2
|
-
import { GoogleDriveStorage } from '../models/GoogleDriveStorage.js';
|
3
|
-
async function testEmailVC() {
|
4
|
-
try {
|
5
|
-
// Initialize storage and engine
|
6
|
-
const storage = new GoogleDriveStorage('YOUR_ACCESS_TOKEN'); // Replace with actual access token
|
7
|
-
const engine = new CredentialEngine(storage);
|
8
|
-
// Test email
|
9
|
-
const testEmail = 'test@example.com';
|
10
|
-
console.log('Starting email VC generation test...');
|
11
|
-
console.log('Test email:', testEmail);
|
12
|
-
// Generate and sign the email VC
|
13
|
-
const result = await engine.generateAndSignEmailVC(testEmail);
|
14
|
-
console.log('\nTest Results:');
|
15
|
-
console.log('-------------');
|
16
|
-
console.log('File ID:', result.fileId);
|
17
|
-
console.log('Signed VC:', JSON.stringify(result.signedVC, null, 2));
|
18
|
-
// Test retrieving the VC from storage
|
19
|
-
console.log('\nRetrieving VC from storage...');
|
20
|
-
const retrievedVC = await storage.retrieve(result.fileId);
|
21
|
-
console.log('Retrieved VC:', retrievedVC ? 'Success' : 'Failed');
|
22
|
-
console.log('\nTest completed successfully!');
|
23
|
-
}
|
24
|
-
catch (error) {
|
25
|
-
console.error('Test failed:', error);
|
26
|
-
}
|
27
|
-
}
|
28
|
-
// Run the test
|
29
|
-
testEmailVC().catch(console.error);
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|