-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.js
31 lines (28 loc) · 1.01 KB
/
encrypt.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
const { ethers } = require("ethers");
const { lighthouse } = require("@lighthouse-web3/sdk");
const { kavach } = require("@lighthouse-web3/kavach");
const { dotenv } = require("dotenv");
class EncryptedFile {
constructor(pathToFile, projectAccount) {
this.pathToFile = pathToFile;
this.projectAccount = projectAccount;
}
async uploadEncrypted() {
dotenv.config();
const apiKey = process.env.LIGHTHOUSE_API_KEY;
const privateKey = await this.projectAccount.getPrivateKey();
const publicKey = await this.projectAccount.getPublicKey();
const signer = new ethers.Wallet(privateKey);
const authMessage = await kavach.getAuthMessage(signer.address);
const signedMessage = await signer.signMessage(authMessage.message);
const { JWT, error } = await kavach.getJWT(signer.address, signedMessage);
const response = await lighthouse.uploadEncrypted(
this.pathToFile,
apiKey,
publicKey,
signedMessage
);
return response;
}
}
export default EncryptedFile;