@lockerpm/desktop-service 1.1.5 → 2.1.0
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/lib/cjs/abstractions/crypto.service.js +1 -0
- package/lib/cjs/index.js +11 -0
- package/lib/cjs/services/api.service.js +36 -0
- package/lib/cjs/services/core-crypto.service.js +20 -3
- package/lib/cjs/services/crypto.service.js +6 -10
- package/lib/cjs/types/abstractions/api.service.d.ts +44 -1
- package/lib/cjs/types/abstractions/api.service.d.ts.map +1 -1
- package/lib/cjs/types/abstractions/crypto.service.d.ts +2 -1
- package/lib/cjs/types/abstractions/crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/abstractions/index.d.ts +33 -2
- package/lib/cjs/types/abstractions/index.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +34 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/proto/locker-service-grpc.d.ts +1 -0
- package/lib/cjs/types/proto/locker-service-grpc.d.ts.map +1 -1
- package/lib/cjs/types/services/api.service.d.ts +3 -1
- package/lib/cjs/types/services/api.service.d.ts.map +1 -1
- package/lib/cjs/types/services/core-crypto.service.d.ts +2 -1
- package/lib/cjs/types/services/core-crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/services/crypto.service.d.ts.map +1 -1
- package/lib/cjs/types/services/grpc.service.d.ts +1 -0
- package/lib/cjs/types/services/grpc.service.d.ts.map +1 -1
- package/lib/cjs/types/services/socket.service.d.ts +1 -0
- package/lib/cjs/types/services/socket.service.d.ts.map +1 -1
- package/lib/cjs/types/usecases/fido.d.ts +43 -3
- package/lib/cjs/types/usecases/fido.d.ts.map +1 -1
- package/lib/cjs/usecases/fido.js +124 -11
- package/lib/esm/abstractions/api.service.js +1 -2
- package/lib/esm/abstractions/crypto.service.js +14 -19
- package/lib/esm/abstractions/errors.js +4 -8
- package/lib/esm/abstractions/event.service.js +1 -2
- package/lib/esm/abstractions/index.js +1 -2
- package/lib/esm/abstractions/socket.service.js +1 -5
- package/lib/esm/abstractions/storage.service.js +1 -2
- package/lib/esm/index.mjs +45 -38
- package/lib/esm/misc/config.js +5 -8
- package/lib/esm/misc/utils.js +4 -11
- package/lib/esm/proto/google/api/annotations.js +1 -2
- package/lib/esm/proto/google/api/http.js +3 -29
- package/lib/esm/proto/google/protobuf/descriptor.js +3 -29
- package/lib/esm/proto/locker-service-grpc.js +4 -30
- package/lib/esm/services/api.service.js +61 -30
- package/lib/esm/services/cache.service.js +4 -8
- package/lib/esm/services/core-crypto.service.js +34 -26
- package/lib/esm/services/crypto.service.js +22 -33
- package/lib/esm/services/event.service.js +3 -10
- package/lib/esm/services/fido.service.js +9 -13
- package/lib/esm/services/grpc.service.js +18 -25
- package/lib/esm/services/log.service.js +3 -7
- package/lib/esm/services/pairing.service.js +8 -12
- package/lib/esm/services/socket.service.js +26 -33
- package/lib/esm/services/user.service.js +5 -9
- package/lib/esm/types/abstractions/api.service.d.ts +44 -1
- package/lib/esm/types/abstractions/api.service.d.ts.map +1 -1
- package/lib/esm/types/abstractions/crypto.service.d.ts +2 -1
- package/lib/esm/types/abstractions/crypto.service.d.ts.map +1 -1
- package/lib/esm/types/abstractions/index.d.ts +33 -2
- package/lib/esm/types/abstractions/index.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +34 -2
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/proto/locker-service-grpc.d.ts +1 -0
- package/lib/esm/types/proto/locker-service-grpc.d.ts.map +1 -1
- package/lib/esm/types/services/api.service.d.ts +3 -1
- package/lib/esm/types/services/api.service.d.ts.map +1 -1
- package/lib/esm/types/services/core-crypto.service.d.ts +2 -1
- package/lib/esm/types/services/core-crypto.service.d.ts.map +1 -1
- package/lib/esm/types/services/crypto.service.d.ts.map +1 -1
- package/lib/esm/types/services/grpc.service.d.ts +1 -0
- package/lib/esm/types/services/grpc.service.d.ts.map +1 -1
- package/lib/esm/types/services/socket.service.d.ts +1 -0
- package/lib/esm/types/services/socket.service.d.ts.map +1 -1
- package/lib/esm/types/usecases/fido.d.ts +43 -3
- package/lib/esm/types/usecases/fido.d.ts.map +1 -1
- package/lib/esm/usecases/fido.js +131 -29
- package/package.json +3 -1
package/lib/esm/misc/utils.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Utils = void 0;
|
|
7
|
-
const os_1 = __importDefault(require("os"));
|
|
8
|
-
class Utils {
|
|
1
|
+
import os from 'os';
|
|
2
|
+
export class Utils {
|
|
9
3
|
static fromHexToArray(str) {
|
|
10
4
|
return new Uint8Array(Buffer.from(str, 'hex'));
|
|
11
5
|
}
|
|
@@ -22,8 +16,8 @@ class Utils {
|
|
|
22
16
|
return new Uint8Array(Buffer.from(str, 'base64'));
|
|
23
17
|
}
|
|
24
18
|
static getCurrentOS() {
|
|
25
|
-
const platform =
|
|
26
|
-
const arc =
|
|
19
|
+
const platform = os.platform();
|
|
20
|
+
const arc = os.arch();
|
|
27
21
|
let _os = 'linux';
|
|
28
22
|
if (platform === 'darwin') {
|
|
29
23
|
_os = arc === 'x64' ? 'mac-x64' : 'mac-arm64';
|
|
@@ -34,4 +28,3 @@ class Utils {
|
|
|
34
28
|
return _os;
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
|
-
exports.Utils = Utils;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,36 +1,10 @@
|
|
|
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.google = void 0;
|
|
27
1
|
/**
|
|
28
2
|
* Generated by the protoc-gen-ts. DO NOT EDIT!
|
|
29
3
|
* compiler version: 4.24.4
|
|
30
4
|
* source: google/api/http.proto
|
|
31
5
|
* git: https://github.com/thesayyn/protoc-gen-ts */
|
|
32
|
-
|
|
33
|
-
var google;
|
|
6
|
+
import * as pb_1 from "google-protobuf";
|
|
7
|
+
export var google;
|
|
34
8
|
(function (google) {
|
|
35
9
|
var api;
|
|
36
10
|
(function (api) {
|
|
@@ -465,4 +439,4 @@ var google;
|
|
|
465
439
|
}
|
|
466
440
|
api.CustomHttpPattern = CustomHttpPattern;
|
|
467
441
|
})(api = google.api || (google.api = {}));
|
|
468
|
-
})(google || (
|
|
442
|
+
})(google || (google = {}));
|
|
@@ -1,37 +1,11 @@
|
|
|
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.google = void 0;
|
|
27
1
|
// @ts-nocheck
|
|
28
2
|
/**
|
|
29
3
|
* Generated by the protoc-gen-ts. DO NOT EDIT!
|
|
30
4
|
* compiler version: 4.24.4
|
|
31
5
|
* source: google/protobuf/descriptor.proto
|
|
32
6
|
* git: https://github.com/thesayyn/protoc-gen-ts */
|
|
33
|
-
|
|
34
|
-
var google;
|
|
7
|
+
import * as pb_1 from 'google-protobuf';
|
|
8
|
+
export var google;
|
|
35
9
|
(function (google) {
|
|
36
10
|
var protobuf;
|
|
37
11
|
(function (protobuf) {
|
|
@@ -4827,4 +4801,4 @@ var google;
|
|
|
4827
4801
|
})(Annotation = GeneratedCodeInfo.Annotation || (GeneratedCodeInfo.Annotation = {}));
|
|
4828
4802
|
})(GeneratedCodeInfo = protobuf.GeneratedCodeInfo || (protobuf.GeneratedCodeInfo = {}));
|
|
4829
4803
|
})(protobuf = google.protobuf || (google.protobuf = {}));
|
|
4830
|
-
})(google || (
|
|
4804
|
+
})(google || (google = {}));
|
|
@@ -1,32 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.locker_service_grpc = void 0;
|
|
27
|
-
const pb_1 = __importStar(require("google-protobuf"));
|
|
28
|
-
const grpc_1 = __importStar(require("@grpc/grpc-js"));
|
|
29
|
-
var locker_service_grpc;
|
|
1
|
+
import * as pb_1 from "google-protobuf";
|
|
2
|
+
import * as grpc_1 from "@grpc/grpc-js";
|
|
3
|
+
export var locker_service_grpc;
|
|
30
4
|
(function (locker_service_grpc) {
|
|
31
5
|
class UpdateRequest extends pb_1.Message {
|
|
32
6
|
#one_of_decls = [];
|
|
@@ -1909,4 +1883,4 @@ var locker_service_grpc;
|
|
|
1909
1883
|
};
|
|
1910
1884
|
}
|
|
1911
1885
|
locker_service_grpc.LockerServiceClient = LockerServiceClient;
|
|
1912
|
-
})(locker_service_grpc || (
|
|
1886
|
+
})(locker_service_grpc || (locker_service_grpc = {}));
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ApiService = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const errors_1 = require("../abstractions/errors");
|
|
9
|
-
class ApiService {
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { ServiceError } from '../abstractions/errors';
|
|
3
|
+
export class ApiService {
|
|
10
4
|
baseUrl;
|
|
11
5
|
token;
|
|
12
6
|
headers;
|
|
@@ -25,7 +19,7 @@ class ApiService {
|
|
|
25
19
|
async getPasswordlessCredentials(email) {
|
|
26
20
|
try {
|
|
27
21
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
28
|
-
const res = await
|
|
22
|
+
const res = await axios.get(url, {
|
|
29
23
|
params: {
|
|
30
24
|
email,
|
|
31
25
|
},
|
|
@@ -37,16 +31,16 @@ class ApiService {
|
|
|
37
31
|
}
|
|
38
32
|
catch (error) {
|
|
39
33
|
if (error.response?.status === 404) {
|
|
40
|
-
throw new
|
|
34
|
+
throw new ServiceError('1002', error);
|
|
41
35
|
}
|
|
42
|
-
throw new
|
|
36
|
+
throw new ServiceError('1000', error);
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
// TODO: if service is only built by CyStack, then this base API must be fixed
|
|
46
40
|
async getReleases(os) {
|
|
47
41
|
try {
|
|
48
42
|
const url = `${this.baseUrl}/cystack_platform/pm/releases`;
|
|
49
|
-
const res = await
|
|
43
|
+
const res = await axios.get(url, {
|
|
50
44
|
params: {
|
|
51
45
|
client_id: 'desktop',
|
|
52
46
|
os,
|
|
@@ -58,18 +52,39 @@ class ApiService {
|
|
|
58
52
|
return data;
|
|
59
53
|
}
|
|
60
54
|
catch (error) {
|
|
61
|
-
throw new
|
|
55
|
+
throw new ServiceError('1000', error);
|
|
62
56
|
}
|
|
63
57
|
}
|
|
64
58
|
// -------------------------------- AUTH --------------------------------
|
|
59
|
+
async getPreloginInfo() {
|
|
60
|
+
if (!this.token) {
|
|
61
|
+
throw new ServiceError('1001');
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const url = `${this.baseUrl}/cystack_platform/pm/users/me/prelogin`;
|
|
65
|
+
const res = await axios.get(url, {
|
|
66
|
+
headers: {
|
|
67
|
+
Authorization: `Bearer ${this.token}`,
|
|
68
|
+
...this.headers,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
const data = res.data;
|
|
72
|
+
this.logDebug({ url, method: 'GET', data });
|
|
73
|
+
return data;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw new ServiceError('1000', error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ---------------- PASSWORDLESS CREDENTIAL ----------------
|
|
65
80
|
async setPasswordlessCredential(params) {
|
|
66
81
|
if (!this.token) {
|
|
67
|
-
throw new
|
|
82
|
+
throw new ServiceError('1001');
|
|
68
83
|
}
|
|
69
84
|
try {
|
|
70
85
|
const { credentialId, name, type, random } = params;
|
|
71
86
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
72
|
-
const res = await
|
|
87
|
+
const res = await axios.post(url, {
|
|
73
88
|
credential_id: credentialId,
|
|
74
89
|
name,
|
|
75
90
|
type,
|
|
@@ -85,16 +100,16 @@ class ApiService {
|
|
|
85
100
|
return data;
|
|
86
101
|
}
|
|
87
102
|
catch (error) {
|
|
88
|
-
throw new
|
|
103
|
+
throw new ServiceError('1000', error);
|
|
89
104
|
}
|
|
90
105
|
}
|
|
91
106
|
async deletePasswordlessCredential() {
|
|
92
107
|
if (!this.token) {
|
|
93
|
-
throw new
|
|
108
|
+
throw new ServiceError('1001');
|
|
94
109
|
}
|
|
95
110
|
try {
|
|
96
111
|
const url = `${this.baseUrl}/cystack_platform/pm/passwordless/credential`;
|
|
97
|
-
await
|
|
112
|
+
await axios.delete(url, {
|
|
98
113
|
headers: {
|
|
99
114
|
Authorization: `Bearer ${this.token}`,
|
|
100
115
|
...this.headers,
|
|
@@ -107,17 +122,17 @@ class ApiService {
|
|
|
107
122
|
});
|
|
108
123
|
}
|
|
109
124
|
catch (error) {
|
|
110
|
-
throw new
|
|
125
|
+
throw new ServiceError('1000', error);
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
// ---------------- BACKUP KEYS ----------------
|
|
114
129
|
async listBackupPasswordlessCredentials() {
|
|
115
130
|
if (!this.token) {
|
|
116
|
-
throw new
|
|
131
|
+
throw new ServiceError('1001');
|
|
117
132
|
}
|
|
118
133
|
try {
|
|
119
134
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
|
|
120
|
-
const res = await
|
|
135
|
+
const res = await axios.get(url, {
|
|
121
136
|
params: {
|
|
122
137
|
paging: 0,
|
|
123
138
|
},
|
|
@@ -131,16 +146,16 @@ class ApiService {
|
|
|
131
146
|
return data;
|
|
132
147
|
}
|
|
133
148
|
catch (error) {
|
|
134
|
-
throw new
|
|
149
|
+
throw new ServiceError('1000', error);
|
|
135
150
|
}
|
|
136
151
|
}
|
|
137
152
|
async setBackupPasswordlessCredential(payload) {
|
|
138
153
|
if (!this.token) {
|
|
139
|
-
throw new
|
|
154
|
+
throw new ServiceError('1001');
|
|
140
155
|
}
|
|
141
156
|
try {
|
|
142
157
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials`;
|
|
143
|
-
const res = await
|
|
158
|
+
const res = await axios.post(url, payload, {
|
|
144
159
|
headers: {
|
|
145
160
|
Authorization: `Bearer ${this.token}`,
|
|
146
161
|
...this.headers,
|
|
@@ -150,16 +165,33 @@ class ApiService {
|
|
|
150
165
|
return res.data;
|
|
151
166
|
}
|
|
152
167
|
catch (error) {
|
|
153
|
-
throw new
|
|
168
|
+
throw new ServiceError('1000', error);
|
|
154
169
|
}
|
|
155
170
|
}
|
|
156
171
|
async deleteBackupPasswordlessCredential(id) {
|
|
157
172
|
if (!this.token) {
|
|
158
|
-
throw new
|
|
173
|
+
throw new ServiceError('1001');
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
|
|
177
|
+
await axios.delete(url, {
|
|
178
|
+
headers: {
|
|
179
|
+
Authorization: `Bearer ${this.token}`,
|
|
180
|
+
...this.headers,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
throw new ServiceError('1000', error);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async remakeBackupPasswordlessCredential(id, payload) {
|
|
189
|
+
if (!this.token) {
|
|
190
|
+
throw new ServiceError('1001');
|
|
159
191
|
}
|
|
160
192
|
try {
|
|
161
193
|
const url = `${this.baseUrl}/cystack_platform/pm/users/backup_credentials/${id}`;
|
|
162
|
-
await
|
|
194
|
+
await axios.put(url, payload, {
|
|
163
195
|
headers: {
|
|
164
196
|
Authorization: `Bearer ${this.token}`,
|
|
165
197
|
...this.headers,
|
|
@@ -167,7 +199,7 @@ class ApiService {
|
|
|
167
199
|
});
|
|
168
200
|
}
|
|
169
201
|
catch (error) {
|
|
170
|
-
throw new
|
|
202
|
+
throw new ServiceError('1000', error);
|
|
171
203
|
}
|
|
172
204
|
}
|
|
173
205
|
// ---------------- PRIVATE METHODS ----------------
|
|
@@ -176,4 +208,3 @@ class ApiService {
|
|
|
176
208
|
this.logger.debug(`API call ${method} ${url}\nwith ${JSON.stringify(payload)} \nreturn ${JSON.stringify(data)}`);
|
|
177
209
|
}
|
|
178
210
|
}
|
|
179
|
-
exports.ApiService = ApiService;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CacheService = void 0;
|
|
4
|
-
const locker_service_grpc_1 = require("../proto/locker-service-grpc");
|
|
1
|
+
import { locker_service_grpc } from '../proto/locker-service-grpc';
|
|
5
2
|
var CacheMessage;
|
|
6
3
|
(function (CacheMessage) {
|
|
7
4
|
CacheMessage["GET_CACHE"] = "getCache";
|
|
8
5
|
CacheMessage["SET_CACHE"] = "setCache";
|
|
9
6
|
})(CacheMessage || (CacheMessage = {}));
|
|
10
|
-
class CacheService {
|
|
7
|
+
export class CacheService {
|
|
11
8
|
logger;
|
|
12
9
|
grpc;
|
|
13
10
|
constructor(logger, grpcService) {
|
|
@@ -15,7 +12,7 @@ class CacheService {
|
|
|
15
12
|
this.grpc = grpcService;
|
|
16
13
|
}
|
|
17
14
|
getCache() {
|
|
18
|
-
const req = new
|
|
15
|
+
const req = new locker_service_grpc.CacheRequest();
|
|
19
16
|
req.message = CacheMessage.GET_CACHE;
|
|
20
17
|
return new Promise((resolve, reject) => {
|
|
21
18
|
this.grpc.client.CacheChannel(req, (err, res) => {
|
|
@@ -33,7 +30,7 @@ class CacheService {
|
|
|
33
30
|
});
|
|
34
31
|
}
|
|
35
32
|
setCache(data) {
|
|
36
|
-
const req = new
|
|
33
|
+
const req = new locker_service_grpc.CacheRequest();
|
|
37
34
|
req.message = CacheMessage.SET_CACHE;
|
|
38
35
|
req.json = JSON.stringify(data);
|
|
39
36
|
return new Promise((resolve, reject) => {
|
|
@@ -48,4 +45,3 @@ class CacheService {
|
|
|
48
45
|
});
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.CacheService = CacheService;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.CoreCryptoService = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* Crypto core from Locker Vault
|
|
9
3
|
* */
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
import c from 'crypto';
|
|
5
|
+
import { KdfType, SymmetricCryptoKey, EncString, EncryptedObject, } from '../abstractions/crypto.service';
|
|
6
|
+
import { Utils } from '../misc/utils';
|
|
7
|
+
import { argon2idAsync } from '@noble/hashes/argon2.js';
|
|
8
|
+
const crypto = c.webcrypto;
|
|
9
|
+
export class CoreCryptoService {
|
|
10
|
+
async makeKey(password, salt, kdf, kdfIterations, kdfMemory, kdfParallelism) {
|
|
16
11
|
let key;
|
|
17
|
-
if (
|
|
12
|
+
if (kdf === KdfType.ARGON2ID) {
|
|
13
|
+
key = await this.argon2id(password, salt, kdfIterations ?? 3, kdfMemory ?? 64 * 1024, kdfParallelism ?? 4, 32);
|
|
14
|
+
}
|
|
15
|
+
else if (!kdf || kdf === KdfType.PBKDF2_SHA256) {
|
|
18
16
|
if (!kdfIterations) {
|
|
19
17
|
kdfIterations = 5000;
|
|
20
18
|
}
|
|
@@ -26,14 +24,14 @@ class CoreCryptoService {
|
|
|
26
24
|
else {
|
|
27
25
|
throw new Error('Unknown Kdf.');
|
|
28
26
|
}
|
|
29
|
-
return new
|
|
27
|
+
return new SymmetricCryptoKey(key);
|
|
30
28
|
}
|
|
31
29
|
async hashPassword(password, key) {
|
|
32
30
|
if (!password || !key) {
|
|
33
31
|
throw new Error('Invalid parameters.');
|
|
34
32
|
}
|
|
35
33
|
const hash = await this.pbkdf2(key.key, password, 'sha256', 1);
|
|
36
|
-
return
|
|
34
|
+
return Utils.fromBufferToB64(hash);
|
|
37
35
|
}
|
|
38
36
|
async remakeEncKey(currentEncKey, key) {
|
|
39
37
|
let encKeyEnc;
|
|
@@ -47,7 +45,7 @@ class CoreCryptoService {
|
|
|
47
45
|
else {
|
|
48
46
|
throw new Error('Invalid key size.');
|
|
49
47
|
}
|
|
50
|
-
return [new
|
|
48
|
+
return [new SymmetricCryptoKey(currentEncKey), encKeyEnc];
|
|
51
49
|
}
|
|
52
50
|
// ---------------- PRIVATE METHODS -------------------
|
|
53
51
|
async pbkdf2(password, salt, algorithm, iterations) {
|
|
@@ -63,10 +61,21 @@ class CoreCryptoService {
|
|
|
63
61
|
const impKey = await crypto.subtle.importKey('raw', passwordBuf, { name: 'PBKDF2' }, false, ['deriveBits']);
|
|
64
62
|
return await crypto.subtle.deriveBits(pbkdf2Params, impKey, wcLen);
|
|
65
63
|
}
|
|
64
|
+
async argon2id(password, salt, iterations, memory, parallelism, outputByteSize) {
|
|
65
|
+
const nodePassword = new Uint8Array(this.toBuf(password));
|
|
66
|
+
const nodeSalt = new Uint8Array(this.toBuf(salt));
|
|
67
|
+
const res = await argon2idAsync(nodePassword, nodeSalt, {
|
|
68
|
+
t: iterations,
|
|
69
|
+
m: memory,
|
|
70
|
+
p: parallelism,
|
|
71
|
+
dkLen: outputByteSize,
|
|
72
|
+
});
|
|
73
|
+
return res.buffer;
|
|
74
|
+
}
|
|
66
75
|
toBuf(value) {
|
|
67
76
|
let buf;
|
|
68
77
|
if (typeof value === 'string') {
|
|
69
|
-
buf =
|
|
78
|
+
buf = Utils.fromUtf8ToArray(value).buffer;
|
|
70
79
|
}
|
|
71
80
|
else {
|
|
72
81
|
buf = value;
|
|
@@ -85,7 +94,7 @@ class CoreCryptoService {
|
|
|
85
94
|
const macKey = await this.hkdfExpand(key.key, 'mac', 32, 'sha256');
|
|
86
95
|
newKey.set(new Uint8Array(encKey));
|
|
87
96
|
newKey.set(new Uint8Array(macKey), 32);
|
|
88
|
-
return new
|
|
97
|
+
return new SymmetricCryptoKey(newKey.buffer);
|
|
89
98
|
}
|
|
90
99
|
async hkdfExpand(prk, info, outputByteSize, algorithm) {
|
|
91
100
|
const hashLen = algorithm === 'sha256' ? 32 : 64;
|
|
@@ -127,21 +136,21 @@ class CoreCryptoService {
|
|
|
127
136
|
async encrypt(plainValue, key) {
|
|
128
137
|
let plainBuf;
|
|
129
138
|
if (typeof plainValue === 'string') {
|
|
130
|
-
plainBuf =
|
|
139
|
+
plainBuf = Utils.fromUtf8ToArray(plainValue).buffer;
|
|
131
140
|
}
|
|
132
141
|
else {
|
|
133
142
|
plainBuf = plainValue;
|
|
134
143
|
}
|
|
135
144
|
const encObj = await this.aesEncrypt(plainBuf, key);
|
|
136
|
-
const iv =
|
|
137
|
-
const data =
|
|
138
|
-
const mac = encObj.mac ?
|
|
139
|
-
return new
|
|
145
|
+
const iv = Utils.fromBufferToB64(encObj.iv);
|
|
146
|
+
const data = Utils.fromBufferToB64(encObj.data);
|
|
147
|
+
const mac = encObj.mac ? Utils.fromBufferToB64(encObj.mac) : undefined;
|
|
148
|
+
return new EncString(encObj.key.encType, data, iv, mac);
|
|
140
149
|
}
|
|
141
150
|
async aesEncrypt(data, key) {
|
|
142
|
-
const obj = new
|
|
151
|
+
const obj = new EncryptedObject();
|
|
143
152
|
obj.key = key;
|
|
144
|
-
obj.iv = this.randomBytes(16);
|
|
153
|
+
obj.iv = this.randomBytes(16).buffer;
|
|
145
154
|
obj.data = await this._aesEncrypt(data, obj.iv, obj.key.encKey);
|
|
146
155
|
if (obj.key.macKey != null) {
|
|
147
156
|
const macData = new Uint8Array(obj.iv.byteLength + obj.data.byteLength);
|
|
@@ -161,4 +170,3 @@ class CoreCryptoService {
|
|
|
161
170
|
return await crypto.subtle.encrypt({ name: 'AES-CBC', iv }, impKey, data);
|
|
162
171
|
}
|
|
163
172
|
}
|
|
164
|
-
exports.CoreCryptoService = CoreCryptoService;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const crypto_service_1 = require("../abstractions/crypto.service");
|
|
10
|
-
const utils_1 = require("../misc/utils");
|
|
11
|
-
const core_crypto_service_1 = require("./core-crypto.service");
|
|
12
|
-
const crypto = crypto_1.default.webcrypto;
|
|
13
|
-
class CryptoService {
|
|
1
|
+
import c from 'crypto';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { AES, ECDH } from '../abstractions/crypto.service';
|
|
4
|
+
import { Utils } from '../misc/utils';
|
|
5
|
+
import { CoreCryptoService } from './core-crypto.service';
|
|
6
|
+
const crypto = c.webcrypto;
|
|
7
|
+
export class CryptoService {
|
|
14
8
|
core;
|
|
15
9
|
constructor() {
|
|
16
|
-
this.core = new
|
|
10
|
+
this.core = new CoreCryptoService();
|
|
17
11
|
}
|
|
18
12
|
async createECDHKeyPair() {
|
|
19
|
-
const keyPair = await crypto.subtle.generateKey(
|
|
13
|
+
const keyPair = await crypto.subtle.generateKey(ECDH, true, ['deriveKey', 'deriveBits']);
|
|
20
14
|
const rawPublicKey = await crypto.subtle.exportKey('raw', keyPair.publicKey);
|
|
21
15
|
return {
|
|
22
|
-
publicKey:
|
|
16
|
+
publicKey: Utils.fromBufferToHex(rawPublicKey),
|
|
23
17
|
privateKey: keyPair.privateKey,
|
|
24
18
|
};
|
|
25
19
|
}
|
|
@@ -27,39 +21,35 @@ class CryptoService {
|
|
|
27
21
|
const sharedSecret = await this.createECDHSharedSecret(theirPublicKey, ourPrivateKey);
|
|
28
22
|
const approveCode = new Uint8Array(sharedSecret, 0, 2).join('').padStart(6, '0').substring(0, 6);
|
|
29
23
|
return {
|
|
30
|
-
encKey:
|
|
24
|
+
encKey: Utils.fromBufferToHex(sharedSecret),
|
|
31
25
|
approveCode,
|
|
32
26
|
};
|
|
33
27
|
}
|
|
34
28
|
async aesEncrypt(data, key) {
|
|
35
29
|
const iv = this.getRandomValues(16);
|
|
36
30
|
const dataBuffer = new TextEncoder().encode(data);
|
|
37
|
-
const cryptoKey = await crypto.subtle.importKey('raw',
|
|
38
|
-
'encrypt',
|
|
39
|
-
]);
|
|
31
|
+
const cryptoKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(key).buffer, AES, false, ['encrypt']);
|
|
40
32
|
const encrypted = await crypto.subtle.encrypt({
|
|
41
|
-
name:
|
|
33
|
+
name: AES.name,
|
|
42
34
|
iv,
|
|
43
35
|
}, cryptoKey, dataBuffer);
|
|
44
|
-
return `${
|
|
36
|
+
return `${Utils.fromBufferToHex(iv.buffer)}.${Utils.fromBufferToHex(encrypted)}`;
|
|
45
37
|
}
|
|
46
38
|
async aesDecrypt(data, key) {
|
|
47
|
-
const cryptoKey = await crypto.subtle.importKey('raw',
|
|
48
|
-
'decrypt',
|
|
49
|
-
]);
|
|
39
|
+
const cryptoKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(key).buffer, AES, false, ['decrypt']);
|
|
50
40
|
const [iv, encString] = data.split('.');
|
|
51
41
|
const decrypted = await crypto.subtle.decrypt({
|
|
52
|
-
name:
|
|
53
|
-
iv:
|
|
54
|
-
}, cryptoKey,
|
|
42
|
+
name: AES.name,
|
|
43
|
+
iv: Utils.fromHexToArray(iv).buffer,
|
|
44
|
+
}, cryptoKey, Utils.fromHexToArray(encString).buffer);
|
|
55
45
|
const decryptedString = new TextDecoder().decode(decrypted);
|
|
56
46
|
return decryptedString;
|
|
57
47
|
}
|
|
58
48
|
getFileChecksum(path) {
|
|
59
49
|
return new Promise((resolve, reject) => {
|
|
60
50
|
try {
|
|
61
|
-
const file =
|
|
62
|
-
const checksum =
|
|
51
|
+
const file = fs.readFileSync(path);
|
|
52
|
+
const checksum = c.createHash('sha256').update(file).digest('hex');
|
|
63
53
|
resolve(checksum);
|
|
64
54
|
}
|
|
65
55
|
catch (error) {
|
|
@@ -72,12 +62,11 @@ class CryptoService {
|
|
|
72
62
|
}
|
|
73
63
|
// ---------------- PRIVATE METHODS -------------------
|
|
74
64
|
async createECDHSharedSecret(theirPublicKey, ourPrivateKey) {
|
|
75
|
-
const publicKey = await crypto.subtle.importKey('raw',
|
|
65
|
+
const publicKey = await crypto.subtle.importKey('raw', Utils.fromHexToArray(theirPublicKey).buffer, ECDH, false, []);
|
|
76
66
|
const secret = await crypto.subtle.deriveBits({
|
|
77
|
-
name:
|
|
67
|
+
name: ECDH.name,
|
|
78
68
|
public: publicKey,
|
|
79
69
|
}, ourPrivateKey, 256);
|
|
80
70
|
return secret;
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
|
-
exports.CryptoService = CryptoService;
|
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.EventService = void 0;
|
|
7
|
-
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
|
-
class EventService {
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
export class EventService {
|
|
9
3
|
events;
|
|
10
4
|
logger;
|
|
11
5
|
constructor(logger) {
|
|
12
|
-
this.events = new
|
|
6
|
+
this.events = new EventEmitter();
|
|
13
7
|
this.logger = logger;
|
|
14
8
|
}
|
|
15
9
|
emit(event, args) {
|
|
@@ -30,4 +24,3 @@ class EventService {
|
|
|
30
24
|
this.events.removeAllListeners();
|
|
31
25
|
}
|
|
32
26
|
}
|
|
33
|
-
exports.EventService = EventService;
|