-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.js
More file actions
27 lines (21 loc) · 801 Bytes
/
decrypt.js
File metadata and controls
27 lines (21 loc) · 801 Bytes
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
async function retrieveAndDecryptAPIKey(fileURL) {
const storage = new ChainSafeStorage({
token: 'YOUR_CHAINSAFE_TOKEN', // Replace with your ChainSafe API token
});
const file = await storage.get(fileURL);
const encryptedKey = JSON.parse(file);
const litNodeClient = new LitJsSdk.LitNodeClient();
await litNodeClient.connect();
const authSig = await LitJsSdk.checkAndSignAuthMessage({ chain: 'ethereum' });
const { symmetricKey } = await litNodeClient.getEncryptionKey({
accessControlConditions,
toDecrypt: encryptedKey.encryptedSymmetricKey,
chain: 'ethereum',
authSig,
});
const decryptedString = await LitJsSdk.decryptString(
LitJsSdk.uint8arrayFromString(encryptedKey.encryptedString, 'base64'),
symmetricKey
);
return decryptedString;
}