@zohocorporation/vault-cli 1.1.2

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.
Files changed (102) hide show
  1. package/README.md +16 -0
  2. package/out/commands/add/add.const.js +6 -0
  3. package/out/commands/add/add.types.js +2 -0
  4. package/out/commands/add/add.util.js +35 -0
  5. package/out/commands/download/download.const.js +6 -0
  6. package/out/commands/download/download.types.js +2 -0
  7. package/out/commands/download/download.utils.js +35 -0
  8. package/out/commands/generate-password/generate-password.const.js +12 -0
  9. package/out/commands/generate-password/generate-password.types.js +2 -0
  10. package/out/commands/generate-password/generate-password.utils.js +58 -0
  11. package/out/commands/generate-template/generate-template.const.js +7 -0
  12. package/out/commands/generate-template/generate-template.types.js +2 -0
  13. package/out/commands/generate-template/generate-template.util.js +37 -0
  14. package/out/commands/get/get.const.js +8 -0
  15. package/out/commands/get/get.types.js +2 -0
  16. package/out/commands/get/get.utils.js +45 -0
  17. package/out/commands/get-default/get-default.const.js +5 -0
  18. package/out/commands/get-default/get-default.types.js +2 -0
  19. package/out/commands/get-default/get-default.utils.js +33 -0
  20. package/out/commands/list/list.const.js +7 -0
  21. package/out/commands/list/list.types.js +2 -0
  22. package/out/commands/list/list.utils.js +43 -0
  23. package/out/commands/lock/lock.action.js +13 -0
  24. package/out/commands/lock/lock.js +10 -0
  25. package/out/commands/lock/lock.utils.js +52 -0
  26. package/out/commands/login/login.action.js +22 -0
  27. package/out/commands/login/login.const.js +10 -0
  28. package/out/commands/login/login.help.js +12 -0
  29. package/out/commands/login/login.js +17 -0
  30. package/out/commands/login/login.types.js +5 -0
  31. package/out/commands/login/login.utils.js +307 -0
  32. package/out/commands/reset/reset.action.js +28 -0
  33. package/out/commands/reset/reset.help.js +8 -0
  34. package/out/commands/reset/reset.js +14 -0
  35. package/out/commands/reset/reset.utils.js +2 -0
  36. package/out/commands/search/search.action.js +30 -0
  37. package/out/commands/search/search.constants.js +14 -0
  38. package/out/commands/search/search.help.js +6 -0
  39. package/out/commands/search/search.js +26 -0
  40. package/out/commands/search/search.types.js +16 -0
  41. package/out/commands/search/search.utils.js +61 -0
  42. package/out/commands/set-default/set-default.const.js +6 -0
  43. package/out/commands/set-default/set-default.types.js +2 -0
  44. package/out/commands/set-default/set-default.utils.js +39 -0
  45. package/out/commands/unlock/unlock.action.js +23 -0
  46. package/out/commands/unlock/unlock.help.js +2 -0
  47. package/out/commands/unlock/unlock.js +12 -0
  48. package/out/commands/unlock/unlock.type.js +2 -0
  49. package/out/commands/unlock/unlock.utils.js +133 -0
  50. package/out/js/I18n/index.js +80 -0
  51. package/out/js/I18n/resources/CLI_I18N_en.js +173 -0
  52. package/out/js/I18n/resources/CLI_I18N_es.js +3 -0
  53. package/out/js/I18n/resources/CLI_I18N_fr.js +3 -0
  54. package/out/js/I18n/resources/CLI_I18N_nl.js +3 -0
  55. package/out/js/I18n/resources/CLI_I18N_pt.js +3 -0
  56. package/out/js/I18n/resources/CLI_I18N_zh.js +3 -0
  57. package/out/js/crypto/aes.js +225 -0
  58. package/out/js/crypto/index.js +139 -0
  59. package/out/js/crypto/rsa.js +1945 -0
  60. package/out/js/crypto/zohovault.js +671 -0
  61. package/out/js/logger/index.js +10 -0
  62. package/out/old/Add.js +590 -0
  63. package/out/old/Default.js +209 -0
  64. package/out/old/Download.js +69 -0
  65. package/out/old/Generate.js +171 -0
  66. package/out/old/Get.js +225 -0
  67. package/out/old/List.js +197 -0
  68. package/out/old/Login.js +287 -0
  69. package/out/old/Logout.js +21 -0
  70. package/out/old/PasswordGenerator.js +718 -0
  71. package/out/old/PasswordPolicies.js +21 -0
  72. package/out/old/PasswordTypes.js +33 -0
  73. package/out/old/Update.js +682 -0
  74. package/out/old/cmd/addcmd.js +59 -0
  75. package/out/old/cmd/downloadcmd.js +76 -0
  76. package/out/old/cmd/generate-passwordcmd.js +127 -0
  77. package/out/old/cmd/generate-templatecmd.js +59 -0
  78. package/out/old/cmd/get-defaultcmd.js +48 -0
  79. package/out/old/cmd/getcmd.js +57 -0
  80. package/out/old/cmd/listcmd.js +54 -0
  81. package/out/old/cmd/logoutcmd.js +31 -0
  82. package/out/old/cmd/set-default.js +75 -0
  83. package/out/old/cmd/updatecmd.js +44 -0
  84. package/out/old/index.js +580 -0
  85. package/out/util/configuration.util.js +103 -0
  86. package/out/util/consts.util.js +97 -0
  87. package/out/util/dbutils/db.types.js +2 -0
  88. package/out/util/dbutils/db.utils.js +164 -0
  89. package/out/util/dbutils/dbtable.utils.js +19 -0
  90. package/out/util/dev.utils.js +14 -0
  91. package/out/util/encryptionutil/encryption.uitl.js +108 -0
  92. package/out/util/index.util.js +341 -0
  93. package/out/util/keyringutil/keyring.util.js +57 -0
  94. package/out/util/loader/loader.interface.js +2 -0
  95. package/out/util/loader/transfer.loader.js +28 -0
  96. package/out/util/login.util.js +352 -0
  97. package/out/util/passwordtypes.util.js +91 -0
  98. package/out/util/print.util.js +4 -0
  99. package/out/util/search.util.js +359 -0
  100. package/out/util/types.util.js +7 -0
  101. package/out/zv.js +41 -0
  102. package/package.json +96 -0
@@ -0,0 +1,97 @@
1
+ import os from 'os';
2
+ export var ACCOUNT_ENDPOINTS;
3
+ (function (ACCOUNT_ENDPOINTS) {
4
+ ACCOUNT_ENDPOINTS["URL_DEVICE_CODE"] = "/oauth/v3/device/code";
5
+ ACCOUNT_ENDPOINTS["URL_DEVICE_TOKEN"] = "/oauth/v3/device/token";
6
+ ACCOUNT_ENDPOINTS["URL_GENERATE_TOKEN"] = "/oauth/v2/token";
7
+ })(ACCOUNT_ENDPOINTS || (ACCOUNT_ENDPOINTS = {}));
8
+ export var VAULT_ENDPOINTS;
9
+ (function (VAULT_ENDPOINTS) {
10
+ VAULT_ENDPOINTS["URL_LOGIN"] = "/api/json/login";
11
+ VAULT_ENDPOINTS["URL_SEARCH_SECRETS"] = "/api/rest/json/v1/secrets/searchSecret";
12
+ VAULT_ENDPOINTS["URL_SECRET_TYPES"] = "/api/rest/json/v1/secrettypes";
13
+ VAULT_ENDPOINTS["URL_ORG_KEY"] = "/api/rest/json/v1/user/orgkey";
14
+ VAULT_ENDPOINTS["URL_SECRETS"] = "/api/rest/json/v1/secrets";
15
+ VAULT_ENDPOINTS["URL_V2_SECRETS"] = "/api/rest/json/v2/secrets";
16
+ VAULT_ENDPOINTS["URL_PASSWORD_POLICIES"] = "/api/rest/json/v1/passwordPolicies";
17
+ VAULT_ENDPOINTS["URL_DOWNLOAD_FILE"] = "/api/rest/json/v1/secrets/downloadfile";
18
+ VAULT_ENDPOINTS["URL_OLD_SECRETS"] = "/api/json/secrets";
19
+ VAULT_ENDPOINTS["URL_SETTINGS_FOR_I18N"] = "/api/rest/json/v1/settings";
20
+ VAULT_ENDPOINTS["URL_FOLDER"] = "/api/rest/json/v1/chambers";
21
+ VAULT_ENDPOINTS["URL_LICENSE"] = "/api/rest/json/v1/license";
22
+ VAULT_ENDPOINTS["USER_CONFIG"] = "/api/rest/json/v1/user/config"; //No I18N
23
+ })(VAULT_ENDPOINTS || (VAULT_ENDPOINTS = {}));
24
+ export const KEYRING_SERVICE = 'zv-node';
25
+ export const KEYRING_ACCOUNT = 'zv-cli';
26
+ export var CREDENTIALS;
27
+ (function (CREDENTIALS) {
28
+ CREDENTIALS["CLIENT_ID"] = "1004.TY5ZEKIP84H0627578LGYY18TZLB2H";
29
+ CREDENTIALS["CLIENT_SECRET"] = "35d15c880d053987150acfc0b88710996a981c0cfa"; //"4a33687c70d09f4ccd36da75fe7bdfbf3a4dd95e49"
30
+ })(CREDENTIALS || (CREDENTIALS = {}));
31
+ export var OS;
32
+ (function (OS) {
33
+ OS["WINDOWS"] = "windows";
34
+ OS["MAC"] = "mac";
35
+ OS["LINUX"] = "linux";
36
+ })(OS || (OS = {}));
37
+ export var ACCOUNTS_URL;
38
+ (function (ACCOUNTS_URL) {
39
+ ACCOUNTS_URL["AU"] = "https://accounts.zoho.com.au";
40
+ ACCOUNTS_URL["EU"] = "https://accounts.zoho.eu";
41
+ ACCOUNTS_URL["IN"] = "https://accounts.zoho.in";
42
+ ACCOUNTS_URL["CN"] = "https://accounts.zoho.com.cn";
43
+ ACCOUNTS_URL["GEN"] = "https://accounts.zoho.com";
44
+ })(ACCOUNTS_URL || (ACCOUNTS_URL = {}));
45
+ export var VAULT_URL;
46
+ (function (VAULT_URL) {
47
+ VAULT_URL["AU"] = "https://vault.zoho.com.au";
48
+ VAULT_URL["EU"] = "https://vault.zoho.eu";
49
+ VAULT_URL["IN"] = "https://vault.zoho.in";
50
+ VAULT_URL["CN"] = "https://vault.zoho.com.cn";
51
+ VAULT_URL["GEN"] = "https://vault.zoho.com";
52
+ })(VAULT_URL || (VAULT_URL = {}));
53
+ export var DC;
54
+ (function (DC) {
55
+ DC["US"] = "us";
56
+ DC["EU"] = "eu";
57
+ DC["AU"] = "au";
58
+ DC["IN"] = "in";
59
+ DC["CN"] = "com.cn";
60
+ })(DC || (DC = {}));
61
+ export var OPERATION;
62
+ (function (OPERATION) {
63
+ OPERATION["GET_SECRET_FILES"] = "GET_SECRET_FILES";
64
+ OPERATION["GET_LOGIN"] = "GET_LOGIN";
65
+ })(OPERATION || (OPERATION = {}));
66
+ export var SHARING;
67
+ (function (SHARING) {
68
+ SHARING["MANAGE"] = "MANAGE";
69
+ SHARING["AUTOLOGIN"] = "AUTOLOGIN";
70
+ SHARING["VIEW"] = "VIEW";
71
+ SHARING["MODIFY"] = "MODIFY";
72
+ })(SHARING || (SHARING = {}));
73
+ export const DB_PATH = os.homedir() + '/.config/zv';
74
+ export const DB_NAME = 'zv.db';
75
+ export var MODE;
76
+ (function (MODE) {
77
+ MODE["DEVELOPMENT"] = "development";
78
+ MODE["PRODUCTION"] = "production";
79
+ })(MODE || (MODE = {}));
80
+ export var OPTIONS;
81
+ (function (OPTIONS) {
82
+ OPTIONS["LOGIN"] = "login";
83
+ OPTIONS["UNLOCK"] = "unlock";
84
+ OPTIONS["LOCK"] = "lock";
85
+ OPTIONS["SEARCH"] = "search";
86
+ OPTIONS["LIST"] = "list";
87
+ OPTIONS["GET"] = "get";
88
+ OPTIONS["ADD"] = "add";
89
+ OPTIONS["GENERATE_TEMPLATE"] = "generate-template";
90
+ OPTIONS["UPDATE"] = "update";
91
+ OPTIONS["DOWNLOAD"] = "download";
92
+ OPTIONS["GENERATE_PASSWORD"] = "generate-password";
93
+ OPTIONS["LOGOUT"] = "logout";
94
+ OPTIONS["GET_DEFAULT"] = "get-default";
95
+ OPTIONS["SET_DEFAULT"] = "set-default";
96
+ })(OPTIONS || (OPTIONS = {}));
97
+ //# sourceMappingURL=consts.util.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=db.types.js.map
@@ -0,0 +1,164 @@
1
+ import { DB_NAME, DB_PATH } from "../consts.util.js";
2
+ import Database from "better-sqlite3";
3
+ import fs from "node:fs";
4
+ import { createTable } from "./dbtable.utils.js";
5
+ import { decryptString } from "../encryptionutil/encryption.uitl.js";
6
+ import { generateWorkspaceHash } from "../../commands/login/login.utils.js";
7
+ import Vault from "../../js/crypto/index.js";
8
+ import { exit } from "node:process";
9
+ import { encryptString } from "../encryptionutil/encryption.uitl.js";
10
+ import { Logger } from "../../js/logger/index.js";
11
+ export const getZvDB = () => {
12
+ if (!fs.existsSync(DB_PATH)) {
13
+ fs.mkdirSync(DB_PATH, { recursive: true });
14
+ }
15
+ const db = new Database(DB_PATH + '/' + DB_NAME);
16
+ createTable(db);
17
+ return db;
18
+ };
19
+ export const insertToTable = (db, configObj) => {
20
+ try {
21
+ const { workspace, credentials, language, createdtime, dc, hasmasterkey, defaults, zuid } = configObj;
22
+ db.prepare('REPLACE INTO zv_config (workspace, credentials, language, createdtime, dc, hasmasterkey, defaults, zuid) VALUES (?, ?, ?, ?, ?, ?, ?, ?)')
23
+ .bind(workspace, credentials, language, createdtime, dc, hasmasterkey, defaults, zuid)
24
+ .run();
25
+ return true;
26
+ }
27
+ catch (err) {
28
+ Logger.error(err);
29
+ throw new Error("error while inserting into table zv_config");
30
+ }
31
+ };
32
+ export const insertToDB = (data) => {
33
+ return new Promise(async (resolve, reject) => {
34
+ try {
35
+ const { workspace, language, createdtime, credentials, dc, hasmasterkey, defaults, zuid } = data;
36
+ const lang = await encryptString(language);
37
+ const cretime = await encryptString(createdtime);
38
+ const dcEnc = await encryptString(dc);
39
+ const haskey = hasmasterkey.toString();
40
+ const cred = await encryptString(JSON.stringify(credentials));
41
+ const def = await encryptString(Vault.Base64_encode(JSON.stringify(defaults)));
42
+ const zuidEnc = await encryptString(zuid);
43
+ const obj = {
44
+ workspace,
45
+ credentials: cred,
46
+ language: lang,
47
+ createdtime: cretime,
48
+ dc: dcEnc,
49
+ hasmasterkey: haskey,
50
+ defaults: def,
51
+ zuid: zuidEnc
52
+ };
53
+ const db = getZvDB();
54
+ insertToTable(db, obj);
55
+ resolve(true);
56
+ }
57
+ catch (err) {
58
+ Logger.error(err);
59
+ reject(new Error("error while inserting data to DB"));
60
+ }
61
+ });
62
+ };
63
+ export const getCredentials = (pathHash) => {
64
+ const db = getZvDB();
65
+ try {
66
+ const data = db.prepare(`SELECT * FROM zv_config WHERE workspace = ?`).get(pathHash);
67
+ return data;
68
+ }
69
+ catch (err) {
70
+ new Error("Error while getting credentials");
71
+ }
72
+ return null;
73
+ };
74
+ export const updateTable = (pathHash, defaults) => {
75
+ const db = getZvDB();
76
+ return new Promise((resolve, reject) => {
77
+ try {
78
+ const countStmt = db.prepare(`SELECT COUNT (*) AS count FROM zv_config where workspace = ?`);
79
+ const res = countStmt.get(pathHash);
80
+ const { count } = res;
81
+ if (count === 1) {
82
+ const updateStmt = db.prepare(`UPDATE zv_config SET defaults = ? WHERE workspace = ?`);
83
+ updateStmt.run(defaults, pathHash);
84
+ }
85
+ resolve(true);
86
+ }
87
+ catch (err) {
88
+ Logger.error(err);
89
+ reject("Error while updating defaults.");
90
+ }
91
+ });
92
+ };
93
+ export const deleteCredentials = (db) => {
94
+ return new Promise((resolve, reject) => {
95
+ try {
96
+ const workspaceHash = generateWorkspaceHash();
97
+ db.prepare(`DELETE FROM zv_config WHERE workspace = ?`).bind(workspaceHash).run();
98
+ resolve(true);
99
+ }
100
+ catch (err) {
101
+ Logger.error(err);
102
+ reject("Error while removing user");
103
+ }
104
+ });
105
+ };
106
+ export const reset = () => {
107
+ const db = getZvDB();
108
+ return new Promise((resolve, reject) => {
109
+ try {
110
+ db.prepare(`DROP TABLE IF EXISTS zv_config`).run();
111
+ resolve(true);
112
+ }
113
+ catch (err) {
114
+ Logger.error(err);
115
+ reject("Error while dropping table");
116
+ }
117
+ });
118
+ };
119
+ export const decryptUserConfig = async (data) => {
120
+ return new Promise(async (resolve, reject) => {
121
+ try {
122
+ const { credentials, language, createdtime, dc, hasmasterkey, defaults, zuid } = data;
123
+ const decryptedCredentials = JSON.parse(await decryptString(credentials));
124
+ const decryptedLanguage = await decryptString(language);
125
+ const decryptedCreatedTime = await decryptString(createdtime);
126
+ const decryptedDC = await decryptString(dc);
127
+ const modifiedHasmasterkey = (hasmasterkey === "true");
128
+ const def = JSON.parse(Vault.Base64_decode(await decryptString(defaults)));
129
+ const decryptedZuid = await decryptString(zuid);
130
+ const res = {
131
+ ...data,
132
+ credentials: decryptedCredentials,
133
+ language: decryptedLanguage,
134
+ createdtime: decryptedCreatedTime,
135
+ dc: decryptedDC,
136
+ hasmasterkey: modifiedHasmasterkey,
137
+ defaults: def,
138
+ zuid: decryptedZuid
139
+ };
140
+ resolve(res);
141
+ }
142
+ catch (err) {
143
+ Logger.error(err);
144
+ console.log("Credentials not found try logging in again");
145
+ exit(0);
146
+ }
147
+ });
148
+ };
149
+ export const getDecryptedCredentials = (pathHash) => {
150
+ return new Promise(async (resolve, reject) => {
151
+ try {
152
+ const data = getCredentials(pathHash);
153
+ if (!data) {
154
+ resolve(undefined);
155
+ }
156
+ resolve(await decryptUserConfig(data));
157
+ }
158
+ catch (err) {
159
+ Logger.error(err);
160
+ reject(new Error("Error while decrypting credentials"));
161
+ }
162
+ });
163
+ };
164
+ //# sourceMappingURL=db.utils.js.map
@@ -0,0 +1,19 @@
1
+ export const createTable = (db) => {
2
+ try {
3
+ db.prepare(`CREATE TABLE IF NOT EXISTS zv_config(
4
+ workspace VARCHAR PRIMARY KEY,
5
+ credentials VARCHAR,
6
+ language VARCHAR,
7
+ createdtime VARCHAR,
8
+ dc VARCHAR,
9
+ hasmasterkey VARCHAR,
10
+ defaults VARCHAR,
11
+ zuid VARCHAR
12
+ )`).run();
13
+ return true;
14
+ }
15
+ catch (err) {
16
+ throw new Error("Error while creating table");
17
+ }
18
+ };
19
+ //# sourceMappingURL=dbtable.utils.js.map
@@ -0,0 +1,14 @@
1
+ import { MODE } from "./consts.util.js";
2
+ export const getConfig = () => {
3
+ if (process.env.MODE === MODE.DEVELOPMENT) {
4
+ return {
5
+ MODE: process.env.MODE,
6
+ ACCOUNTS_URL: process.env.ACCOUNTS_URL,
7
+ VAULT_URL: process.env.VAULT_URL,
8
+ CLIENT_ID: process.env.CLIENT_ID,
9
+ CLIENT_SECRET: process.env.CLIENT_SECRET
10
+ };
11
+ }
12
+ return { MODE: MODE.PRODUCTION, ACCOUNTS_URL: '', VAULT_URL: '', CLIENT_ID: '', CLIENT_SECRET: '' };
13
+ };
14
+ //# sourceMappingURL=dev.utils.js.map
@@ -0,0 +1,108 @@
1
+ import webcrypto from "node:crypto";
2
+ import { readFromKeyring, writeToKeyring } from "../keyringutil/keyring.util.js";
3
+ import { reset } from "../dbutils/db.utils.js";
4
+ import { Logger } from "../../js/logger/index.js";
5
+ import { KEYRING_SERVICE, KEYRING_ACCOUNT } from "../consts.util.js";
6
+ const { subtle } = webcrypto;
7
+ const generateAESKeyAndIV = async () => {
8
+ try {
9
+ const key = await subtle.generateKey({
10
+ name: 'AES-GCM',
11
+ length: 256
12
+ }, true, ['encrypt', 'decrypt']);
13
+ const webkey = await subtle.exportKey('jwk', key);
14
+ const iv = Array.from(webcrypto.getRandomValues(new Uint8Array(12)));
15
+ return { webkey, iv };
16
+ }
17
+ catch (err) {
18
+ Logger.error(err);
19
+ // console.log("Error while generating AES key and IV");
20
+ }
21
+ };
22
+ export const getEncryptionKey = async () => {
23
+ try {
24
+ let res = await readFromKeyring(KEYRING_SERVICE, KEYRING_ACCOUNT);
25
+ if (!res) {
26
+ await reset();
27
+ const keyData = await generateAESKeyAndIV();
28
+ await writeToKeyring(JSON.stringify(keyData), KEYRING_SERVICE, KEYRING_ACCOUNT);
29
+ res = await readFromKeyring(KEYRING_SERVICE, KEYRING_ACCOUNT);
30
+ }
31
+ return JSON.parse(res);
32
+ }
33
+ catch (err) {
34
+ Logger.error(err);
35
+ // console.log("Error while getting encryption key.");
36
+ }
37
+ };
38
+ export const getFormattedCredentials = async () => {
39
+ try {
40
+ const encryptionCredentials = await getEncryptionKey();
41
+ const { webkey, iv: ivBuffer } = encryptionCredentials;
42
+ const key = await subtle.importKey('jwk', webkey, 'AES-GCM', true, ['encrypt', 'decrypt']);
43
+ const iv = new Uint8Array(ivBuffer).slice(0, 12);
44
+ return { key, iv };
45
+ }
46
+ catch (err) {
47
+ Logger.error(err);
48
+ // console.log("Error while getting formatted credentials");
49
+ }
50
+ };
51
+ export const encryptString = async (plainText) => {
52
+ try {
53
+ const en = new TextEncoder();
54
+ const encodedText = en.encode(plainText);
55
+ const formattedCredentials = await getFormattedCredentials();
56
+ if (!formattedCredentials) {
57
+ throw new Error();
58
+ }
59
+ const { key, iv } = await getFormattedCredentials();
60
+ const cipherText = await subtle.encrypt({
61
+ name: 'AES-GCM',
62
+ iv
63
+ }, key, encodedText);
64
+ return Buffer.from(cipherText).toString('base64');
65
+ }
66
+ catch (err) {
67
+ Logger.error(err);
68
+ // console.log("Error while encrypting string");
69
+ }
70
+ };
71
+ export const str2ab = (str) => {
72
+ try {
73
+ let binaryString = Buffer.from(str, 'base64').toString('binary');
74
+ let buf = new ArrayBuffer(binaryString.length); // 2 bytes for each char
75
+ let bufView = new Uint8Array(buf);
76
+ for (let i = 0, strLen = binaryString.length; i < strLen; i++) {
77
+ bufView[i] = binaryString.charCodeAt(i);
78
+ }
79
+ return buf;
80
+ }
81
+ catch (err) {
82
+ Logger.error(err);
83
+ // console.log("Error while converting string to arraybuffer")
84
+ }
85
+ };
86
+ export const decryptString = async (cipherText) => {
87
+ try {
88
+ const dc = new TextDecoder();
89
+ let formattedCredentials = await getFormattedCredentials();
90
+ if (!formattedCredentials) {
91
+ throw new Error();
92
+ }
93
+ const { key, iv } = formattedCredentials;
94
+ const cipherTextBuffer = str2ab(cipherText);
95
+ if (!cipherTextBuffer) {
96
+ throw new Error();
97
+ }
98
+ const plainTextBuffer = await subtle.decrypt({
99
+ name: 'AES-GCM',
100
+ iv: iv
101
+ }, key, cipherTextBuffer);
102
+ return dc.decode(plainTextBuffer);
103
+ }
104
+ catch (err) {
105
+ Logger.error(err);
106
+ }
107
+ };
108
+ //# sourceMappingURL=encryption.uitl.js.map