@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
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020';
|
2
|
+
const LOCAL_STORAGE_KEY = 'AppInstanceDID';
|
3
|
+
export async function getOrCreateAppInstanceDid() {
|
4
|
+
const stored = localStorage.getItem(LOCAL_STORAGE_KEY);
|
5
|
+
if (stored) {
|
6
|
+
const parsed = JSON.parse(stored);
|
7
|
+
const keyPair = await Ed25519VerificationKey2020.from(parsed);
|
8
|
+
return { did: keyPair.controller, keyPair };
|
9
|
+
}
|
10
|
+
const keyPair = await Ed25519VerificationKey2020.generate();
|
11
|
+
keyPair.controller = `did:key:${keyPair.publicKeyMultibase}`;
|
12
|
+
keyPair.id = `${keyPair.controller}#${keyPair.publicKeyMultibase}`;
|
13
|
+
keyPair.revoked = false;
|
14
|
+
const did = keyPair.controller;
|
15
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify({
|
16
|
+
controller: keyPair.controller,
|
17
|
+
id: keyPair.id,
|
18
|
+
publicKeyMultibase: keyPair.publicKeyMultibase,
|
19
|
+
privateKeyMultibase: keyPair.privateKeyMultibase,
|
20
|
+
}));
|
21
|
+
return { did, keyPair };
|
22
|
+
}
|
package/dist/utils/google.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export const getVCWithRecommendations = async ({ vcId, storage }) => {
|
2
2
|
try {
|
3
3
|
const vcFolderId = await storage.getFileParents(vcId);
|
4
|
-
const files = await storage.
|
4
|
+
const files = await storage.findFolderFiles(vcFolderId);
|
5
5
|
const relationsFile = files.find((f) => f.name === 'RELATIONS');
|
6
6
|
const relationsContent = await storage.retrieve(relationsFile.id);
|
7
7
|
const relationsData = relationsContent.data.body ? JSON.parse(relationsContent.data.body) : relationsContent.data;
|
package/package.json
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cooperation/vc-storage",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.41",
|
5
5
|
"description": "Sign and store your verifiable credentials.",
|
6
6
|
"main": "dist/index.js",
|
7
7
|
"types": "dist/types/index.d.ts",
|
8
8
|
"files": [
|
9
|
-
"dist"
|
9
|
+
"dist",
|
10
|
+
"app.config.js"
|
10
11
|
],
|
11
12
|
"scripts": {
|
12
13
|
"build": "tsc",
|
@@ -16,10 +17,15 @@
|
|
16
17
|
"author": "cooperation",
|
17
18
|
"license": "ISC",
|
18
19
|
"dependencies": {
|
20
|
+
"@did.coop/did-key-ed25519": "^0.0.13",
|
19
21
|
"@digitalbazaar/did-method-key": "^5.2.0",
|
20
22
|
"@digitalbazaar/ed25519-signature-2020": "^5.4.0",
|
21
23
|
"@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
|
22
24
|
"@digitalbazaar/vc": "^6.3.0",
|
25
|
+
"@wallet.storage/fetch-client": "^1.2.0",
|
26
|
+
"@digitalcredentials/ezcap": "^7.1.0",
|
27
|
+
"@digitalcredentials/ed25519-verification-key-2020": "^5.0.0-beta.2",
|
28
|
+
"@digitalcredentials/ed25519-signature-2020": "^5.0.0",
|
23
29
|
"add": "^2.0.6",
|
24
30
|
"bnid": "^3.0.0",
|
25
31
|
"crypto-js": "^4.2.0",
|
@@ -37,7 +43,7 @@
|
|
37
43
|
"@types/jest": "^29.5.14",
|
38
44
|
"@types/uuid": "^10.0.0",
|
39
45
|
"babel-jest": "^29.7.0",
|
40
|
-
"typescript": "^5.8.
|
46
|
+
"typescript": "^5.8.3",
|
41
47
|
"vitest": "^3.0.5"
|
42
48
|
}
|
43
49
|
}
|
@@ -1,10 +0,0 @@
|
|
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,45 +0,0 @@
|
|
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 const createAndSignVerifiablePresentation = async (accessTokens, vcFileId) => {
|
9
|
-
if (!accessTokens || !vcFileId) {
|
10
|
-
console.error('Invalid input: Access tokens and VC file ID are required.');
|
11
|
-
return null;
|
12
|
-
}
|
13
|
-
try {
|
14
|
-
// const storage = new GoogleDriveStorage(accessTokens);
|
15
|
-
// const engine = new CredentialEngine(accessTokens);
|
16
|
-
// // Fetch Verifiable Credential (VC)
|
17
|
-
// const verifiableCredential = await storage.retrieve(vcFileId);
|
18
|
-
// if (!verifiableCredential) {
|
19
|
-
// throw new Error('Verifiable Credential not found.');
|
20
|
-
// }
|
21
|
-
// // Fetch VC comments (potential recommendations)
|
22
|
-
// const verifiableCredentialComments = await storage.getFileComments(vcFileId);
|
23
|
-
// let recommendations: object[] = [];
|
24
|
-
// // Extract recommendations from comments if present
|
25
|
-
// if (verifiableCredentialComments.length > 0) {
|
26
|
-
// for (const comment of verifiableCredentialComments) {
|
27
|
-
// console.log('🚀 ~ createAndSignVerifiablePresentation ~ comment', comment);
|
28
|
-
// const recommendationFile = await storage.retrieve(extractGoogleDriveFileId(comment.content));
|
29
|
-
// console.log('🚀 ~ createAndSignVerifiablePresentation ~ recommendationFile', recommendationFile);
|
30
|
-
// if (recommendationFile) {
|
31
|
-
// recommendations.push(recommendationFile);
|
32
|
-
// }
|
33
|
-
// }
|
34
|
-
// }
|
35
|
-
// // Create Verifiable Presentation (VP) with the retrieved VC
|
36
|
-
// const presentation = await engine.createPresentation([verifiableCredential.data, ...recommendations]); //! do not edit the array order!!
|
37
|
-
// // Use the key pair to sign the presentation
|
38
|
-
// const signedPresentation = await engine.signPresentation(presentation);
|
39
|
-
// return {};
|
40
|
-
}
|
41
|
-
catch (error) {
|
42
|
-
console.error('Error during Verifiable Presentation creation and signing:', error);
|
43
|
-
return null;
|
44
|
-
}
|
45
|
-
};
|