-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
69 lines (67 loc) · 2.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
62
63
64
65
66
67
68
69
import {
encryptFolder,
decryptFolder,
uploadToIpfs,
downloadFile,
} from "./utils/index.js";
/**
* Uploads a folder to IPFS and encrypts its contents using a password.
* @param {String} Web3Storagetoken A Web3 Storage token used for authentication.
* @param {String} folderPath The path to the folder that you want to upload and encrypt.
* @param {String} password The password to use for encryption.
* @returns {Promise<String>} CID of the uploaded folder.
* @example
* import { uploadEncryptionIpfs } from "ipfs-encrypted";
* const token = "my_web3_storage_token";
* const folderPath = "/path/to/folder";
* const password = "my_password";
*
* uploadEncryptionIpfs(token, folderPath, password)
* .then((cid) => console.log(`Folder uploaded and encrypted with CID ${cid}`))
* .catch((error) => console.error(`Error: ${error.message}`));
*/
export async function uploadEncryptionIpfs(
Web3Storagetoken,
folderPath,
password
) {
await encryptFolder(folderPath, password);
const cid = await uploadToIpfs(Web3Storagetoken, folderPath);
return cid;
}
/**
* Retrieves an encrypted folder from IPFS and decrypts its contents using a password.
* @param {String} Web3Storagetoken A Web3 Storage token used for authentication.
* @param {String} cid The CID of the encrypted folder on IPFS.
* @param {String} password The password to use for decryption.
* @param {String} downloadLocation Path of folder that content need to downloaded.
* @returns {Promise<String[]>}
* @example
* import { decryptFolderIpfs } from "ipfs-encrypted";
* const token = "my_web3_storage_token";
* const cid = "Qm1234abcd";
* const password = "my_password";
* const downloadLocation = "/path/to/folder";
*
* decryptFolderIpfs(token, cid, password, downloadLocation)
* .then((folderPath) =>
* console.log(`Folder decrypted and saved to ${folderPath}`)
* )
* .catch((error) => console.error(`Error: ${error.message}`));
*/
export async function decryptFolderIpfs(
Web3Storagetoken,
cid,
password,
downloadLocation
) {
await downloadFile(Web3Storagetoken, cid, downloadLocation);
const res = await decryptFolder(downloadLocation, password);
return res;
}
export {
encryptFolder,
decryptFolder,
uploadToIpfs,
downloadFile,
} from "./utils/index.js";