envware 1.0.10
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.
- package/README.md +98 -0
- package/dist/app.controller.d.ts +6 -0
- package/dist/app.controller.js +35 -0
- package/dist/app.controller.js.map +1 -0
- package/dist/app.module.d.ts +2 -0
- package/dist/app.module.js +40 -0
- package/dist/app.module.js.map +1 -0
- package/dist/app.service.d.ts +3 -0
- package/dist/app.service.js +20 -0
- package/dist/app.service.js.map +1 -0
- package/dist/commands/accept.command.d.ts +11 -0
- package/dist/commands/accept.command.js +74 -0
- package/dist/commands/accept.command.js.map +1 -0
- package/dist/commands/login.command.d.ts +9 -0
- package/dist/commands/login.command.js +61 -0
- package/dist/commands/login.command.js.map +1 -0
- package/dist/commands/project.command.d.ts +12 -0
- package/dist/commands/project.command.js +121 -0
- package/dist/commands/project.command.js.map +1 -0
- package/dist/commands/pull.command.d.ts +16 -0
- package/dist/commands/pull.command.js +120 -0
- package/dist/commands/pull.command.js.map +1 -0
- package/dist/commands/push.command.d.ts +16 -0
- package/dist/commands/push.command.js +153 -0
- package/dist/commands/push.command.js.map +1 -0
- package/dist/commands/share.command.d.ts +16 -0
- package/dist/commands/share.command.js +125 -0
- package/dist/commands/share.command.js.map +1 -0
- package/dist/commands/signup.command.d.ts +9 -0
- package/dist/commands/signup.command.js +61 -0
- package/dist/commands/signup.command.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.js +17 -0
- package/dist/main.js.map +1 -0
- package/dist/services/api.service.d.ts +8 -0
- package/dist/services/api.service.js +53 -0
- package/dist/services/api.service.js.map +1 -0
- package/dist/services/config.service.d.ts +11 -0
- package/dist/services/config.service.js +130 -0
- package/dist/services/config.service.js.map +1 -0
- package/dist/services/encryption.service.d.ts +20 -0
- package/dist/services/encryption.service.js +178 -0
- package/dist/services/encryption.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.ConfigService = void 0;
|
|
43
|
+
const common_1 = require("@nestjs/common");
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const os = __importStar(require("os"));
|
|
47
|
+
let ConfigService = class ConfigService {
|
|
48
|
+
homeConfigPath = path.join(os.homedir(), '.envware.json');
|
|
49
|
+
localConfigPath = path.join(process.cwd(), '.envware.json');
|
|
50
|
+
projectConfigPath = path.join(process.cwd(), '.envware');
|
|
51
|
+
getConfigPath() {
|
|
52
|
+
if (fs.existsSync(this.localConfigPath)) {
|
|
53
|
+
return this.localConfigPath;
|
|
54
|
+
}
|
|
55
|
+
return this.homeConfigPath;
|
|
56
|
+
}
|
|
57
|
+
get(key) {
|
|
58
|
+
const configPath = this.getConfigPath();
|
|
59
|
+
if (!fs.existsSync(configPath))
|
|
60
|
+
return null;
|
|
61
|
+
try {
|
|
62
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
63
|
+
return config[key] || null;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
set(key, value) {
|
|
70
|
+
const configPath = this.getConfigPath();
|
|
71
|
+
let config = {};
|
|
72
|
+
if (fs.existsSync(configPath)) {
|
|
73
|
+
try {
|
|
74
|
+
config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
config = {};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
config[key] = value;
|
|
81
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
82
|
+
}
|
|
83
|
+
delete(key) {
|
|
84
|
+
const configPath = this.getConfigPath();
|
|
85
|
+
if (!fs.existsSync(configPath))
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
89
|
+
delete config[key];
|
|
90
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
getLocalProject() {
|
|
96
|
+
if (!fs.existsSync(this.projectConfigPath))
|
|
97
|
+
return null;
|
|
98
|
+
try {
|
|
99
|
+
const content = fs.readFileSync(this.projectConfigPath, 'utf8');
|
|
100
|
+
const match = content.match(/PROJECT_ID=(.*)/);
|
|
101
|
+
return match ? match[1].trim() : null;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
setLocalProject(projectId) {
|
|
108
|
+
try {
|
|
109
|
+
let content = '';
|
|
110
|
+
if (fs.existsSync(this.projectConfigPath)) {
|
|
111
|
+
content = fs.readFileSync(this.projectConfigPath, 'utf8');
|
|
112
|
+
}
|
|
113
|
+
if (content.includes('PROJECT_ID=')) {
|
|
114
|
+
content = content.replace(/PROJECT_ID=.*/, `PROJECT_ID=${projectId}`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
content += (content ? '\n' : '') + `PROJECT_ID=${projectId}`;
|
|
118
|
+
}
|
|
119
|
+
fs.writeFileSync(this.projectConfigPath, content);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('Failed to save .envware:', error.message);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.ConfigService = ConfigService;
|
|
127
|
+
exports.ConfigService = ConfigService = __decorate([
|
|
128
|
+
(0, common_1.Injectable)()
|
|
129
|
+
], ConfigService);
|
|
130
|
+
//# sourceMappingURL=config.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.service.js","sourceRoot":"","sources":["../../src/services/config.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AAGlB,IAAM,aAAa,GAAnB,MAAM,aAAa;IACP,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;IAC1D,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;IAC5D,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IAElE,aAAa;QACnB,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,eAAe,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,GAAG,CAAC,GAAW;QACb,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACxC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YAAE,OAAO,IAAI,CAAC;QAC5C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAG5D,CAAC;YACF,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,KA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
generateProjectKey(): string;
|
|
6
|
+
encryptProjectKey(projectKey: string, publicKey: string): string;
|
|
7
|
+
decryptProjectKey(encryptedProjectKey: string): string;
|
|
8
|
+
encrypt(text: string, projectKey: string): {
|
|
9
|
+
value: string;
|
|
10
|
+
iv: string;
|
|
11
|
+
tag: string;
|
|
12
|
+
};
|
|
13
|
+
decrypt(encryptedData: {
|
|
14
|
+
value: string;
|
|
15
|
+
iv: string;
|
|
16
|
+
tag: string;
|
|
17
|
+
}, projectKey: string): string;
|
|
18
|
+
encryptSymmetric(data: string, secret: string): string;
|
|
19
|
+
decryptSymmetric(encryptedJson: string, secret: string): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.EncryptionService = void 0;
|
|
43
|
+
const common_1 = require("@nestjs/common");
|
|
44
|
+
const crypto = __importStar(require("crypto"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const os = __importStar(require("os"));
|
|
48
|
+
const child_process_1 = require("child_process");
|
|
49
|
+
let EncryptionService = class EncryptionService {
|
|
50
|
+
getSshPath() {
|
|
51
|
+
const customPath = process.env.ENVWARE_SSH_KEY;
|
|
52
|
+
if (customPath)
|
|
53
|
+
return customPath;
|
|
54
|
+
const possibleKeys = ['id_ed25519', 'id_rsa', 'id_ecdsa'];
|
|
55
|
+
for (const key of possibleKeys) {
|
|
56
|
+
const fullPath = path.join(os.homedir(), '.ssh', key);
|
|
57
|
+
if (fs.existsSync(fullPath))
|
|
58
|
+
return fullPath;
|
|
59
|
+
}
|
|
60
|
+
return path.join(os.homedir(), '.ssh', 'id_rsa');
|
|
61
|
+
}
|
|
62
|
+
getPublicKeyPath() {
|
|
63
|
+
const customPath = process.env.ENVWARE_SSH_PUBKEY;
|
|
64
|
+
if (customPath)
|
|
65
|
+
return customPath;
|
|
66
|
+
const possibleKeys = ['id_ed25519.pub', 'id_rsa.pub', 'id_ecdsa.pub'];
|
|
67
|
+
for (const key of possibleKeys) {
|
|
68
|
+
const fullPath = path.join(os.homedir(), '.ssh', key);
|
|
69
|
+
if (fs.existsSync(fullPath))
|
|
70
|
+
return fullPath;
|
|
71
|
+
}
|
|
72
|
+
return path.join(os.homedir(), '.ssh', 'id_rsa.pub');
|
|
73
|
+
}
|
|
74
|
+
getPublicKey() {
|
|
75
|
+
const pubKeyPath = this.getPublicKeyPath();
|
|
76
|
+
if (!fs.existsSync(pubKeyPath)) {
|
|
77
|
+
throw new Error(`SSH Public Key not found at ${pubKeyPath}. Please ensure you have an SSH key pair or set ENVWARE_SSH_PUBKEY.`);
|
|
78
|
+
}
|
|
79
|
+
return fs.readFileSync(pubKeyPath, 'utf8').trim();
|
|
80
|
+
}
|
|
81
|
+
generateProjectKey() {
|
|
82
|
+
return crypto.randomBytes(32).toString('hex');
|
|
83
|
+
}
|
|
84
|
+
encryptProjectKey(projectKey, publicKey) {
|
|
85
|
+
try {
|
|
86
|
+
const buffer = Buffer.from(projectKey, 'utf8');
|
|
87
|
+
let keyToUse = publicKey;
|
|
88
|
+
if (publicKey.startsWith('ssh-') || publicKey.startsWith('ecdsa-')) {
|
|
89
|
+
try {
|
|
90
|
+
return crypto.createPublicKey(publicKey).export({ type: 'spki', format: 'pem' }).toString();
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
try {
|
|
94
|
+
const tempPath = path.join(os.tmpdir(), `envware-key-${Date.now()}`);
|
|
95
|
+
fs.writeFileSync(tempPath, publicKey);
|
|
96
|
+
const converted = (0, child_process_1.execSync)(`ssh-keygen -f "${tempPath}" -e -m PKCS8`).toString();
|
|
97
|
+
fs.unlinkSync(tempPath);
|
|
98
|
+
return converted;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
console.warn('SSH key conversion failed, attempting direct load...');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const key = crypto.createPublicKey(keyToUse);
|
|
106
|
+
const encrypted = crypto.publicEncrypt(key, buffer);
|
|
107
|
+
return encrypted.toString('base64');
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
111
|
+
throw new Error(`Failed to encrypt Project Key with Public Key: ${message}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
decryptProjectKey(encryptedProjectKey) {
|
|
115
|
+
const sshPath = this.getSshPath();
|
|
116
|
+
if (!fs.existsSync(sshPath)) {
|
|
117
|
+
throw new Error(`SSH Private Key not found at ${sshPath}. Set ENVWARE_SSH_KEY if using a custom path.`);
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const privateKey = fs.readFileSync(sshPath, 'utf8');
|
|
121
|
+
const buffer = Buffer.from(encryptedProjectKey, 'base64');
|
|
122
|
+
const decrypted = crypto.privateDecrypt(privateKey, buffer);
|
|
123
|
+
return decrypted.toString('utf8');
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
127
|
+
throw new Error(`Failed to decrypt Project Key with Private Key: ${message}. Ensure your private key matches the public key uploaded to the server.`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
encrypt(text, projectKey) {
|
|
131
|
+
const iv = crypto.randomBytes(12);
|
|
132
|
+
const key = crypto.scryptSync(projectKey, 'envware-salt', 32);
|
|
133
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
134
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
135
|
+
encrypted += cipher.final('hex');
|
|
136
|
+
const tag = cipher.getAuthTag().toString('hex');
|
|
137
|
+
return {
|
|
138
|
+
value: encrypted,
|
|
139
|
+
iv: iv.toString('hex'),
|
|
140
|
+
tag: tag,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
decrypt(encryptedData, projectKey) {
|
|
144
|
+
const key = crypto.scryptSync(projectKey, 'envware-salt', 32);
|
|
145
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, Buffer.from(encryptedData.iv, 'hex'));
|
|
146
|
+
decipher.setAuthTag(Buffer.from(encryptedData.tag, 'hex'));
|
|
147
|
+
let decrypted = decipher.update(encryptedData.value, 'hex', 'utf8');
|
|
148
|
+
decrypted += decipher.final('utf8');
|
|
149
|
+
return decrypted;
|
|
150
|
+
}
|
|
151
|
+
encryptSymmetric(data, secret) {
|
|
152
|
+
const iv = crypto.randomBytes(16);
|
|
153
|
+
const key = crypto.scryptSync(secret, 'envware-invite-salt', 32);
|
|
154
|
+
const cipher = crypto.createCipheriv('aes-256-gcm', key, iv);
|
|
155
|
+
let encrypted = cipher.update(data, 'utf8', 'hex');
|
|
156
|
+
encrypted += cipher.final('hex');
|
|
157
|
+
const tag = cipher.getAuthTag();
|
|
158
|
+
return JSON.stringify({
|
|
159
|
+
value: encrypted,
|
|
160
|
+
iv: iv.toString('hex'),
|
|
161
|
+
tag: tag.toString('hex'),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
decryptSymmetric(encryptedJson, secret) {
|
|
165
|
+
const { value, iv, tag } = JSON.parse(encryptedJson);
|
|
166
|
+
const key = crypto.scryptSync(secret, 'envware-invite-salt', 32);
|
|
167
|
+
const decipher = crypto.createDecipheriv('aes-256-gcm', key, Buffer.from(iv, 'hex'));
|
|
168
|
+
decipher.setAuthTag(Buffer.from(tag, 'hex'));
|
|
169
|
+
let decrypted = decipher.update(value, 'hex', 'utf8');
|
|
170
|
+
decrypted += decipher.final('utf8');
|
|
171
|
+
return decrypted;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
exports.EncryptionService = EncryptionService;
|
|
175
|
+
exports.EncryptionService = EncryptionService = __decorate([
|
|
176
|
+
(0, common_1.Injectable)()
|
|
177
|
+
], EncryptionService);
|
|
178
|
+
//# sourceMappingURL=encryption.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.service.js","sourceRoot":"","sources":["../../src/services/encryption.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,+CAAiC;AACjC,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,iDAAyC;AAGlC,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IACpB,UAAU;QAChB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC/C,IAAI,UAAU;YAAE,OAAO,UAAU,CAAC;QAElC,MAAM,YAAY,GAAG,CAAC,YAAY,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QAC1D,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;YAC/B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YACtD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,OAAO,QAAQ,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC;IAEO,gBAAgB;QACtB,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAClD,IAAI,UAAU;YAAE,OAAO,UAAU,CAAC;QAElC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;QACtE,KAAK,MAAM,GAAG,IAAI,YA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