-
Notifications
You must be signed in to change notification settings - Fork 18
/
index.js
28 lines (26 loc) · 948 Bytes
/
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
import { EThree } from '@virgilsecurity/e3kit-browser';
const getToken = async () => {
const myIdentity = 'my-identity';
const response = await fetch(`${process.env.API_URL}/virgil-jwt?identity=${myIdentity}`);
const { virgil_jwt: virgilJwt } = await response.json();
return virgilJwt;
};
(async () => {
let message;
try {
const sdk = await EThree.initialize(getToken, {
apiUrl: process.env.VIRGIL_API_URL,
});
await sdk.register();
await sdk.backupPrivateKey('pa$$w0rd');
const encryptedMessage = await sdk.encrypt('Success');
message = await sdk.decrypt(encryptedMessage);
} catch (error) {
message = error.toString();
} finally {
const paragraph = document.createElement('p');
const textNode = document.createTextNode(message);
paragraph.appendChild(textNode);
document.body.appendChild(paragraph);
}
})();