@lockerpm/desktop-service 1.0.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.
Files changed (158) hide show
  1. package/README.md +98 -0
  2. package/lib/cjs/abstractions/api.service.js +2 -0
  3. package/lib/cjs/abstractions/crypto.service.js +147 -0
  4. package/lib/cjs/abstractions/errors.js +99 -0
  5. package/lib/cjs/abstractions/event.service.js +2 -0
  6. package/lib/cjs/abstractions/index.js +2 -0
  7. package/lib/cjs/abstractions/socket.service.js +11 -0
  8. package/lib/cjs/abstractions/storage.service.js +2 -0
  9. package/lib/cjs/index.js +243 -0
  10. package/lib/cjs/misc/config.js +15 -0
  11. package/lib/cjs/misc/utils.js +37 -0
  12. package/lib/cjs/proto/google/api/annotations.js +2 -0
  13. package/lib/cjs/proto/google/api/http.js +477 -0
  14. package/lib/cjs/proto/google/protobuf/descriptor.js +4873 -0
  15. package/lib/cjs/proto/locker-service-grpc.js +1915 -0
  16. package/lib/cjs/services/api.service.js +182 -0
  17. package/lib/cjs/services/cache.service.js +50 -0
  18. package/lib/cjs/services/core-crypto.service.js +193 -0
  19. package/lib/cjs/services/crypto.service.js +101 -0
  20. package/lib/cjs/services/event.service.js +31 -0
  21. package/lib/cjs/services/fido.service.js +136 -0
  22. package/lib/cjs/services/grpc.service.js +130 -0
  23. package/lib/cjs/services/log.service.js +30 -0
  24. package/lib/cjs/services/pairing.service.js +122 -0
  25. package/lib/cjs/services/socket.service.js +280 -0
  26. package/lib/cjs/services/user.service.js +134 -0
  27. package/lib/cjs/types/abstractions/api.service.d.ts +40 -0
  28. package/lib/cjs/types/abstractions/api.service.d.ts.map +1 -0
  29. package/lib/cjs/types/abstractions/crypto.service.d.ts +46 -0
  30. package/lib/cjs/types/abstractions/crypto.service.d.ts.map +1 -0
  31. package/lib/cjs/types/abstractions/errors.d.ts +73 -0
  32. package/lib/cjs/types/abstractions/errors.d.ts.map +1 -0
  33. package/lib/cjs/types/abstractions/event.service.d.ts +23 -0
  34. package/lib/cjs/types/abstractions/event.service.d.ts.map +1 -0
  35. package/lib/cjs/types/abstractions/index.d.ts +56 -0
  36. package/lib/cjs/types/abstractions/index.d.ts.map +1 -0
  37. package/lib/cjs/types/abstractions/socket.service.d.ts +52 -0
  38. package/lib/cjs/types/abstractions/socket.service.d.ts.map +1 -0
  39. package/lib/cjs/types/abstractions/storage.service.d.ts +6 -0
  40. package/lib/cjs/types/abstractions/storage.service.d.ts.map +1 -0
  41. package/lib/cjs/types/index.d.ts +164 -0
  42. package/lib/cjs/types/index.d.ts.map +1 -0
  43. package/lib/cjs/types/misc/config.d.ts +6 -0
  44. package/lib/cjs/types/misc/config.d.ts.map +1 -0
  45. package/lib/cjs/types/misc/utils.d.ts +21 -0
  46. package/lib/cjs/types/misc/utils.d.ts.map +1 -0
  47. package/lib/cjs/types/proto/google/api/annotations.d.ts +2 -0
  48. package/lib/cjs/types/proto/google/api/annotations.d.ts.map +1 -0
  49. package/lib/cjs/types/proto/google/api/http.d.ts +195 -0
  50. package/lib/cjs/types/proto/google/api/http.d.ts.map +1 -0
  51. package/lib/cjs/types/proto/google/protobuf/descriptor.d.ts +3409 -0
  52. package/lib/cjs/types/proto/google/protobuf/descriptor.d.ts.map +1 -0
  53. package/lib/cjs/types/proto/locker-service-grpc.d.ts +622 -0
  54. package/lib/cjs/types/proto/locker-service-grpc.d.ts.map +1 -0
  55. package/lib/cjs/types/services/api.service.d.ts +37 -0
  56. package/lib/cjs/types/services/api.service.d.ts.map +1 -0
  57. package/lib/cjs/types/services/cache.service.d.ts +10 -0
  58. package/lib/cjs/types/services/cache.service.d.ts.map +1 -0
  59. package/lib/cjs/types/services/core-crypto.service.d.ts +17 -0
  60. package/lib/cjs/types/services/core-crypto.service.d.ts.map +1 -0
  61. package/lib/cjs/types/services/crypto.service.d.ts +23 -0
  62. package/lib/cjs/types/services/crypto.service.d.ts.map +1 -0
  63. package/lib/cjs/types/services/event.service.d.ts +14 -0
  64. package/lib/cjs/types/services/event.service.d.ts.map +1 -0
  65. package/lib/cjs/types/services/fido.service.d.ts +40 -0
  66. package/lib/cjs/types/services/fido.service.d.ts.map +1 -0
  67. package/lib/cjs/types/services/grpc.service.d.ts +34 -0
  68. package/lib/cjs/types/services/grpc.service.d.ts.map +1 -0
  69. package/lib/cjs/types/services/log.service.d.ts +13 -0
  70. package/lib/cjs/types/services/log.service.d.ts.map +1 -0
  71. package/lib/cjs/types/services/pairing.service.d.ts +37 -0
  72. package/lib/cjs/types/services/pairing.service.d.ts.map +1 -0
  73. package/lib/cjs/types/services/socket.service.d.ts +39 -0
  74. package/lib/cjs/types/services/socket.service.d.ts.map +1 -0
  75. package/lib/cjs/types/services/user.service.d.ts +32 -0
  76. package/lib/cjs/types/services/user.service.d.ts.map +1 -0
  77. package/lib/cjs/types/usecases/fido.d.ts +54 -0
  78. package/lib/cjs/types/usecases/fido.d.ts.map +1 -0
  79. package/lib/cjs/usecases/fido.js +227 -0
  80. package/lib/esm/abstractions/api.service.js +2 -0
  81. package/lib/esm/abstractions/crypto.service.js +165 -0
  82. package/lib/esm/abstractions/errors.js +100 -0
  83. package/lib/esm/abstractions/event.service.js +2 -0
  84. package/lib/esm/abstractions/index.js +2 -0
  85. package/lib/esm/abstractions/socket.service.js +11 -0
  86. package/lib/esm/abstractions/storage.service.js +2 -0
  87. package/lib/esm/index.mjs +227 -0
  88. package/lib/esm/misc/config.js +15 -0
  89. package/lib/esm/misc/utils.js +37 -0
  90. package/lib/esm/proto/google/api/annotations.js +2 -0
  91. package/lib/esm/proto/google/api/http.js +468 -0
  92. package/lib/esm/proto/google/protobuf/descriptor.js +4830 -0
  93. package/lib/esm/proto/locker-service-grpc.js +1892 -0
  94. package/lib/esm/services/api.service.js +177 -0
  95. package/lib/esm/services/cache.service.js +52 -0
  96. package/lib/esm/services/core-crypto.service.js +164 -0
  97. package/lib/esm/services/crypto.service.js +83 -0
  98. package/lib/esm/services/event.service.js +33 -0
  99. package/lib/esm/services/fido.service.js +139 -0
  100. package/lib/esm/services/grpc.service.js +119 -0
  101. package/lib/esm/services/log.service.js +31 -0
  102. package/lib/esm/services/pairing.service.js +107 -0
  103. package/lib/esm/services/socket.service.js +265 -0
  104. package/lib/esm/services/user.service.js +116 -0
  105. package/lib/esm/types/abstractions/api.service.d.ts +40 -0
  106. package/lib/esm/types/abstractions/api.service.d.ts.map +1 -0
  107. package/lib/esm/types/abstractions/crypto.service.d.ts +46 -0
  108. package/lib/esm/types/abstractions/crypto.service.d.ts.map +1 -0
  109. package/lib/esm/types/abstractions/errors.d.ts +73 -0
  110. package/lib/esm/types/abstractions/errors.d.ts.map +1 -0
  111. package/lib/esm/types/abstractions/event.service.d.ts +23 -0
  112. package/lib/esm/types/abstractions/event.service.d.ts.map +1 -0
  113. package/lib/esm/types/abstractions/index.d.ts +56 -0
  114. package/lib/esm/types/abstractions/index.d.ts.map +1 -0
  115. package/lib/esm/types/abstractions/socket.service.d.ts +52 -0
  116. package/lib/esm/types/abstractions/socket.service.d.ts.map +1 -0
  117. package/lib/esm/types/abstractions/storage.service.d.ts +6 -0
  118. package/lib/esm/types/abstractions/storage.service.d.ts.map +1 -0
  119. package/lib/esm/types/index.d.ts +164 -0
  120. package/lib/esm/types/index.d.ts.map +1 -0
  121. package/lib/esm/types/misc/config.d.ts +6 -0
  122. package/lib/esm/types/misc/config.d.ts.map +1 -0
  123. package/lib/esm/types/misc/utils.d.ts +21 -0
  124. package/lib/esm/types/misc/utils.d.ts.map +1 -0
  125. package/lib/esm/types/proto/google/api/annotations.d.ts +2 -0
  126. package/lib/esm/types/proto/google/api/annotations.d.ts.map +1 -0
  127. package/lib/esm/types/proto/google/api/http.d.ts +195 -0
  128. package/lib/esm/types/proto/google/api/http.d.ts.map +1 -0
  129. package/lib/esm/types/proto/google/protobuf/descriptor.d.ts +3409 -0
  130. package/lib/esm/types/proto/google/protobuf/descriptor.d.ts.map +1 -0
  131. package/lib/esm/types/proto/locker-service-grpc.d.ts +622 -0
  132. package/lib/esm/types/proto/locker-service-grpc.d.ts.map +1 -0
  133. package/lib/esm/types/services/api.service.d.ts +37 -0
  134. package/lib/esm/types/services/api.service.d.ts.map +1 -0
  135. package/lib/esm/types/services/cache.service.d.ts +10 -0
  136. package/lib/esm/types/services/cache.service.d.ts.map +1 -0
  137. package/lib/esm/types/services/core-crypto.service.d.ts +17 -0
  138. package/lib/esm/types/services/core-crypto.service.d.ts.map +1 -0
  139. package/lib/esm/types/services/crypto.service.d.ts +23 -0
  140. package/lib/esm/types/services/crypto.service.d.ts.map +1 -0
  141. package/lib/esm/types/services/event.service.d.ts +14 -0
  142. package/lib/esm/types/services/event.service.d.ts.map +1 -0
  143. package/lib/esm/types/services/fido.service.d.ts +40 -0
  144. package/lib/esm/types/services/fido.service.d.ts.map +1 -0
  145. package/lib/esm/types/services/grpc.service.d.ts +34 -0
  146. package/lib/esm/types/services/grpc.service.d.ts.map +1 -0
  147. package/lib/esm/types/services/log.service.d.ts +13 -0
  148. package/lib/esm/types/services/log.service.d.ts.map +1 -0
  149. package/lib/esm/types/services/pairing.service.d.ts +37 -0
  150. package/lib/esm/types/services/pairing.service.d.ts.map +1 -0
  151. package/lib/esm/types/services/socket.service.d.ts +39 -0
  152. package/lib/esm/types/services/socket.service.d.ts.map +1 -0
  153. package/lib/esm/types/services/user.service.d.ts +32 -0
  154. package/lib/esm/types/services/user.service.d.ts.map +1 -0
  155. package/lib/esm/types/usecases/fido.d.ts +54 -0
  156. package/lib/esm/types/usecases/fido.d.ts.map +1 -0
  157. package/lib/esm/usecases/fido.js +201 -0
  158. package/package.json +55 -0
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EncryptedObject = exports.EncString = exports.SymmetricCryptoKey = exports.EncryptionType = exports.KdfType = exports.AES = exports.ECDH = void 0;
5
+ const utils_1 = require("../misc/utils");
6
+ exports.ECDH = {
7
+ name: 'ECDH',
8
+ namedCurve: 'P-384',
9
+ };
10
+ exports.AES = {
11
+ name: 'AES-CBC',
12
+ };
13
+ // -------------- CORE --------------
14
+ var KdfType;
15
+ (function (KdfType) {
16
+ KdfType[KdfType["PBKDF2_SHA256"] = 0] = "PBKDF2_SHA256";
17
+ })(KdfType || (exports.KdfType = KdfType = {}));
18
+ var EncryptionType;
19
+ (function (EncryptionType) {
20
+ EncryptionType[EncryptionType["AesCbc256_B64"] = 0] = "AesCbc256_B64";
21
+ EncryptionType[EncryptionType["AesCbc128_HmacSha256_B64"] = 1] = "AesCbc128_HmacSha256_B64";
22
+ EncryptionType[EncryptionType["AesCbc256_HmacSha256_B64"] = 2] = "AesCbc256_HmacSha256_B64";
23
+ EncryptionType[EncryptionType["Rsa2048_OaepSha256_B64"] = 3] = "Rsa2048_OaepSha256_B64";
24
+ EncryptionType[EncryptionType["Rsa2048_OaepSha1_B64"] = 4] = "Rsa2048_OaepSha1_B64";
25
+ EncryptionType[EncryptionType["Rsa2048_OaepSha256_HmacSha256_B64"] = 5] = "Rsa2048_OaepSha256_HmacSha256_B64";
26
+ EncryptionType[EncryptionType["Rsa2048_OaepSha1_HmacSha256_B64"] = 6] = "Rsa2048_OaepSha1_HmacSha256_B64";
27
+ })(EncryptionType || (exports.EncryptionType = EncryptionType = {}));
28
+ class SymmetricCryptoKey {
29
+ key;
30
+ encKey;
31
+ macKey;
32
+ encType;
33
+ keyB64;
34
+ encKeyB64;
35
+ macKeyB64;
36
+ meta;
37
+ constructor(key, encType) {
38
+ if (key == null) {
39
+ throw new Error('Must provide key');
40
+ }
41
+ if (encType == null) {
42
+ if (key.byteLength === 32) {
43
+ encType = EncryptionType.AesCbc256_B64;
44
+ }
45
+ else if (key.byteLength === 64) {
46
+ encType = EncryptionType.AesCbc256_HmacSha256_B64;
47
+ }
48
+ else {
49
+ throw new Error('Unable to determine encType.');
50
+ }
51
+ }
52
+ this.key = key;
53
+ this.encType = encType;
54
+ if (encType === EncryptionType.AesCbc256_B64 && key.byteLength === 32) {
55
+ this.encKey = key;
56
+ this.macKey = undefined;
57
+ }
58
+ else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && key.byteLength === 32) {
59
+ this.encKey = key.slice(0, 16);
60
+ this.macKey = key.slice(16, 32);
61
+ }
62
+ else if (encType === EncryptionType.AesCbc256_HmacSha256_B64 && key.byteLength === 64) {
63
+ this.encKey = key.slice(0, 32);
64
+ this.macKey = key.slice(32, 64);
65
+ }
66
+ else {
67
+ throw new Error('Unsupported encType/key length.');
68
+ }
69
+ if (this.key != null) {
70
+ this.keyB64 = utils_1.Utils.fromBufferToB64(this.key);
71
+ }
72
+ if (this.encKey != null) {
73
+ this.encKeyB64 = utils_1.Utils.fromBufferToB64(this.encKey);
74
+ }
75
+ if (this.macKey != null) {
76
+ this.macKeyB64 = utils_1.Utils.fromBufferToB64(this.macKey);
77
+ }
78
+ }
79
+ }
80
+ exports.SymmetricCryptoKey = SymmetricCryptoKey;
81
+ class EncString {
82
+ encryptedString;
83
+ encryptionType;
84
+ decryptedValue;
85
+ data;
86
+ iv;
87
+ mac;
88
+ constructor(encryptedStringOrType, data, iv, mac) {
89
+ if (data != null) {
90
+ // data and header
91
+ const encType = encryptedStringOrType;
92
+ if (iv != null) {
93
+ this.encryptedString = encType + '.' + iv + '|' + data;
94
+ }
95
+ else {
96
+ this.encryptedString = encType + '.' + data;
97
+ }
98
+ // mac
99
+ if (mac != null) {
100
+ this.encryptedString += '|' + mac;
101
+ }
102
+ this.encryptionType = encType;
103
+ this.data = data;
104
+ this.iv = iv;
105
+ this.mac = mac;
106
+ return;
107
+ }
108
+ this.encryptedString = encryptedStringOrType;
109
+ if (!this.encryptedString) {
110
+ return;
111
+ }
112
+ const headerPieces = this.encryptedString.split('.');
113
+ let encPieces = null;
114
+ if (headerPieces.length === 2) {
115
+ try {
116
+ this.encryptionType = parseInt(headerPieces[0]);
117
+ encPieces = headerPieces[1].split('|');
118
+ }
119
+ catch (e) {
120
+ return;
121
+ }
122
+ }
123
+ else {
124
+ encPieces = this.encryptedString.split('|');
125
+ this.encryptionType =
126
+ encPieces.length === 3
127
+ ? EncryptionType.AesCbc128_HmacSha256_B64
128
+ : EncryptionType.AesCbc256_B64;
129
+ }
130
+ switch (this.encryptionType) {
131
+ case EncryptionType.AesCbc128_HmacSha256_B64:
132
+ case EncryptionType.AesCbc256_HmacSha256_B64:
133
+ if (encPieces.length !== 3) {
134
+ return;
135
+ }
136
+ this.iv = encPieces[0];
137
+ this.data = encPieces[1];
138
+ this.mac = encPieces[2];
139
+ break;
140
+ case EncryptionType.AesCbc256_B64:
141
+ if (encPieces.length !== 2) {
142
+ return;
143
+ }
144
+ this.iv = encPieces[0];
145
+ this.data = encPieces[1];
146
+ break;
147
+ case EncryptionType.Rsa2048_OaepSha256_B64:
148
+ case EncryptionType.Rsa2048_OaepSha1_B64:
149
+ if (encPieces.length !== 1) {
150
+ return;
151
+ }
152
+ this.data = encPieces[0];
153
+ break;
154
+ default:
155
+ }
156
+ }
157
+ }
158
+ exports.EncString = EncString;
159
+ class EncryptedObject {
160
+ iv;
161
+ data;
162
+ mac;
163
+ key;
164
+ }
165
+ exports.EncryptedObject = EncryptedObject;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERRORS = exports.ServiceError = void 0;
4
+ class ServiceError extends Error {
5
+ code;
6
+ message;
7
+ rawError;
8
+ constructor(code, rawError) {
9
+ super(rawError);
10
+ this.rawError = rawError;
11
+ this.code = code;
12
+ const rawMessage = rawError?.response?.data?.message ||
13
+ rawError?.message ||
14
+ rawError?.toString() ||
15
+ 'Unknown error';
16
+ this.message = code === '0000' ? rawMessage : exports.ERRORS[code].message;
17
+ }
18
+ static fromError(rawError) {
19
+ const message = rawError?.response?.data?.message ||
20
+ rawError?.message ||
21
+ rawError?.toString() ||
22
+ 'Unknown error';
23
+ const error = ERRORS_LIST.filter((e) => !!e.signatures).find((e) => e.signatures?.some((signature) => message.toLowerCase().includes(signature)));
24
+ if (error) {
25
+ return new ServiceError(error.code, rawError);
26
+ }
27
+ return new ServiceError('0000', rawError);
28
+ }
29
+ }
30
+ exports.ServiceError = ServiceError;
31
+ exports.ERRORS = {
32
+ '0000': {
33
+ message: 'Unspecified error',
34
+ },
35
+ // API
36
+ '1000': {
37
+ message: 'API error',
38
+ },
39
+ '1001': {
40
+ message: 'API token not found',
41
+ },
42
+ '1002': {
43
+ message: 'Passwordless is not enabled',
44
+ },
45
+ // FIDO
46
+ '2001': {
47
+ message: 'Cannot connect to fido key',
48
+ },
49
+ '2002': {
50
+ message: 'Cannot create credential, key return empty secret',
51
+ },
52
+ '2003': {
53
+ message: 'Invalid PIN',
54
+ signatures: ['pin invalid'],
55
+ },
56
+ '2004': {
57
+ message: 'Cannot find relying party',
58
+ signatures: ['no rp'],
59
+ },
60
+ '2005': {
61
+ message: 'Cannot find any valid credential in this key',
62
+ },
63
+ '2006': {
64
+ message: 'Cannot find the required credential in this key',
65
+ signatures: ['no credentials'],
66
+ },
67
+ '2007': {
68
+ message: 'Cannot use fingerprint, please use PIN instead',
69
+ signatures: ['unsupported option', 'pin required'],
70
+ },
71
+ '2008': {
72
+ message: 'PIN validation failed to many times, key is blocked',
73
+ signatures: ['pin auth blocked'],
74
+ },
75
+ '2009': {
76
+ message: 'Failed to verify fingerprint',
77
+ signatures: ['keep alive cancel'],
78
+ },
79
+ '2010': {
80
+ message: 'List credentials is not supported on this key',
81
+ signatures: ['failed to get relying party info: invalid command'],
82
+ },
83
+ '2011': {
84
+ message: 'FIDO action timed out',
85
+ signatures: ['failed to get assertion: action timed out'],
86
+ },
87
+ // PAIRING
88
+ '3001': {
89
+ message: 'Client is not confirmed',
90
+ },
91
+ // SOCKET
92
+ '4001': {
93
+ message: 'Client not found',
94
+ },
95
+ '4002': {
96
+ message: 'Cannot broadcast secure message',
97
+ },
98
+ }; // as { [code: string]: { message: string; signatures?: string[] } }
99
+ // @ts-ignore
100
+ const ERRORS_LIST = Object.keys(exports.ERRORS).map((code) => ({ code, ...exports.ERRORS[code] }));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildOutgoingSocketMessage = void 0;
4
+ function buildOutgoingSocketMessage(message, data, secure) {
5
+ return {
6
+ message,
7
+ data,
8
+ secure,
9
+ };
10
+ }
11
+ exports.buildOutgoingSocketMessage = buildOutgoingSocketMessage;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DesktopService = exports.ServiceErrors = void 0;
4
+ const socket_service_1 = require("./abstractions/socket.service");
5
+ const api_service_1 = require("./services/api.service");
6
+ const user_service_1 = require("./services/user.service");
7
+ const crypto_service_1 = require("./services/crypto.service");
8
+ const event_service_1 = require("./services/event.service");
9
+ const fido_service_1 = require("./services/fido.service");
10
+ const grpc_service_1 = require("./services/grpc.service");
11
+ const log_service_1 = require("./services/log.service");
12
+ const pairing_service_1 = require("./services/pairing.service");
13
+ const socket_service_2 = require("./services/socket.service");
14
+ const errors_1 = require("./abstractions/errors");
15
+ const fido_1 = require("./usecases/fido");
16
+ const cache_service_1 = require("./services/cache.service");
17
+ exports.ServiceErrors = errors_1.ERRORS;
18
+ class DesktopService {
19
+ apiService;
20
+ fidoService;
21
+ logService;
22
+ pairingService;
23
+ socketService;
24
+ userService;
25
+ grpcService;
26
+ cacheService;
27
+ eventService;
28
+ storageService;
29
+ cryptoService;
30
+ _interval = null;
31
+ // Constructor
32
+ constructor(params) {
33
+ const { baseApiUrl, logLevel, storageService, ssl, unsafe, apiHeaders, serviceAlias, socketSsl, } = params;
34
+ this.cryptoService = new crypto_service_1.CryptoService();
35
+ this.storageService = storageService;
36
+ this.logService = new log_service_1.LogService(logLevel);
37
+ this.eventService = new event_service_1.EventService(this.logService);
38
+ this.apiService = new api_service_1.ApiService({
39
+ baseUrl: baseApiUrl,
40
+ logger: this.logService,
41
+ headers: apiHeaders,
42
+ });
43
+ this.grpcService = new grpc_service_1.GRPCService({
44
+ logger: this.logService,
45
+ cryptoService: this.cryptoService,
46
+ apiService: this.apiService,
47
+ }, {
48
+ ssl,
49
+ unsafe,
50
+ serviceAlias: serviceAlias || '',
51
+ });
52
+ this.fidoService = new fido_service_1.FidoService(this.logService, this.eventService, this.grpcService);
53
+ this.pairingService = new pairing_service_1.PairingService({
54
+ cryptoService: this.cryptoService,
55
+ eventService: this.eventService,
56
+ storageService: this.storageService,
57
+ logger: this.logService,
58
+ grpcService: this.grpcService,
59
+ });
60
+ this.userService = new user_service_1.UserService({
61
+ logger: this.logService,
62
+ storageService: this.storageService,
63
+ grpcService: this.grpcService,
64
+ });
65
+ this.socketService = new socket_service_2.SocketService({
66
+ logger: this.logService,
67
+ pairingService: this.pairingService,
68
+ userService: this.userService,
69
+ eventService: this.eventService,
70
+ ssl: socketSsl,
71
+ serviceAlias: serviceAlias || '',
72
+ });
73
+ this.cacheService = new cache_service_1.CacheService(this.logService, this.grpcService);
74
+ this.waitUntilReady();
75
+ }
76
+ // ---------------------- READY STATE ----------------------
77
+ get isReady() {
78
+ const requiredService = [
79
+ this.grpcService,
80
+ this.userService,
81
+ this.pairingService,
82
+ this.socketService,
83
+ ];
84
+ return requiredService.reduce((isReady, service) => isReady && service.isReady, true);
85
+ }
86
+ waitUntilReady() {
87
+ return new Promise((resolve) => {
88
+ const step = 500;
89
+ const timeout = 5000;
90
+ let counter = 0;
91
+ if (this._interval) {
92
+ clearInterval(this._interval);
93
+ }
94
+ this._interval = setInterval(() => {
95
+ if (this.isReady) {
96
+ this.eventService.emit('serviceReady', undefined);
97
+ clearInterval(this._interval);
98
+ resolve(true);
99
+ return;
100
+ }
101
+ counter += step;
102
+ if (counter >= timeout) {
103
+ this.logService.error(`Service not ready after ${timeout} ms`);
104
+ clearInterval(this._interval);
105
+ resolve(false);
106
+ }
107
+ }, step);
108
+ });
109
+ }
110
+ resetSocket() {
111
+ return this.socketService.initSocket();
112
+ }
113
+ resetGRPC() {
114
+ return this.grpcService.initConnection();
115
+ }
116
+ // ---------------------- FIDO ----------------------
117
+ setApiToken(token) {
118
+ this.apiService.setToken(token);
119
+ }
120
+ getFidoDeviceList() {
121
+ return this.fidoService.getDeviceList();
122
+ }
123
+ setNewPasswordless(params) {
124
+ return (0, fido_1.setNewPasswordless)(params, {
125
+ apiService: this.apiService,
126
+ fidoService: this.fidoService,
127
+ });
128
+ }
129
+ deletePasswordless() {
130
+ return this.apiService.deletePasswordlessCredential();
131
+ }
132
+ setBackupPasswordless(params) {
133
+ return (0, fido_1.setBackupPasswordless)(params, {
134
+ apiService: this.apiService,
135
+ fidoService: this.fidoService,
136
+ cryptoService: this.cryptoService,
137
+ });
138
+ }
139
+ async listAllPasswordless(email) {
140
+ const [mainKey, backupKeys] = await Promise.all([
141
+ this.apiService.getPasswordlessCredentials(email),
142
+ this.apiService.listBackupPasswordlessCredentials(),
143
+ ]);
144
+ const res = [...backupKeys];
145
+ if (mainKey.credential_id) {
146
+ res.push({
147
+ id: 'primary',
148
+ name: mainKey.name || '',
149
+ creation_date: mainKey.creation_date,
150
+ last_use_date: mainKey.last_use_date,
151
+ master_password_hash: '',
152
+ key: '',
153
+ fd_credential_id: mainKey.credential_id,
154
+ fd_random: mainKey.random || '',
155
+ isPrimary: true,
156
+ type: mainKey.type,
157
+ });
158
+ }
159
+ return res;
160
+ }
161
+ async listBackupPasswordless() {
162
+ return this.apiService.listBackupPasswordlessCredentials();
163
+ }
164
+ async deleteBackupPasswordless(id) {
165
+ return this.apiService.deleteBackupPasswordlessCredential(id);
166
+ }
167
+ getPasswordless(params) {
168
+ return (0, fido_1.getPasswordless)(params, {
169
+ apiService: this.apiService,
170
+ fidoService: this.fidoService,
171
+ logService: this.logService,
172
+ });
173
+ }
174
+ // ---------------------- PAIRING ----------------------
175
+ async confirmPairingClient(clientId, clientType) {
176
+ await this.pairingService.confirmPairingClient(clientId, clientType === 'extension');
177
+ this.socketService.sendMessageToClient(clientId, (0, socket_service_1.buildOutgoingSocketMessage)('pairingConfirmed', undefined));
178
+ }
179
+ async resetPairingCode(clientId) {
180
+ this.socketService.sendMessageToClient(clientId, (0, socket_service_1.buildOutgoingSocketMessage)('resetPairing', undefined));
181
+ }
182
+ async sendCustomMessage(data) {
183
+ this.socketService.broadcastMessageToAll((0, socket_service_1.buildOutgoingSocketMessage)('customMessage', data));
184
+ }
185
+ getCacheData() {
186
+ return this.cacheService.getCache();
187
+ }
188
+ setCacheData(data) {
189
+ return this.cacheService.setCache(data);
190
+ }
191
+ // ---------------------- USER ----------------------
192
+ getCurrentUser() {
193
+ return this.userService.getCurrentUser();
194
+ }
195
+ async login(params) {
196
+ await this.userService.login(params);
197
+ this.socketService.broadcastMessageToAll((0, socket_service_1.buildOutgoingSocketMessage)('userLogin', { email: params.email }));
198
+ }
199
+ async logout() {
200
+ const currentUser = { ...this.userService.currentUser };
201
+ if (currentUser?.email) {
202
+ await this.userService.logout();
203
+ this.socketService.broadcastMessageToAll((0, socket_service_1.buildOutgoingSocketMessage)('userLogout', { email: currentUser.email }));
204
+ }
205
+ }
206
+ async lock() {
207
+ const currentUser = { ...this.userService.currentUser };
208
+ if (currentUser?.email) {
209
+ await this.userService.lock();
210
+ this.socketService.broadcastMessageToAll((0, socket_service_1.buildOutgoingSocketMessage)('userLock', { email: currentUser.email }));
211
+ }
212
+ }
213
+ // ---------------------- EVENTS ----------------------
214
+ on(event, handler) {
215
+ return this.eventService.on(event, handler);
216
+ }
217
+ once(event, handler) {
218
+ return this.eventService.once(event, handler);
219
+ }
220
+ removeListener(event, handler) {
221
+ this.eventService.removeListener(event, handler);
222
+ }
223
+ removeAllListeners() {
224
+ this.eventService.removeAllListeners();
225
+ }
226
+ }
227
+ exports.DesktopService = DesktopService;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRPC_PING_TIMEOUT = exports.GRPC_CONNECTION_TIMEOUT = exports.WEBSOCKET_SSL_PORTS = exports.WEBSOCKET_PORTS = exports.HTTP_PORTS = void 0;
4
+ exports.HTTP_PORTS = [
5
+ 14411, 14110, 15611, 14412, 16311, 14514, 14515, 14413, 14401, 14100, 15601, 14402, 16301, 14504,
6
+ 14505, 14403,
7
+ ];
8
+ exports.WEBSOCKET_PORTS = [
9
+ 10040, 10124, 10978, 11307, 11792, 21792, 10041, 10125, 10979, 11308, 11793, 21793,
10
+ ];
11
+ exports.WEBSOCKET_SSL_PORTS = [
12
+ 20040, 20124, 20978, 21307, 21792, 22792, 20041, 20125, 20979, 21308, 21793, 22793,
13
+ ];
14
+ exports.GRPC_CONNECTION_TIMEOUT = 1500;
15
+ exports.GRPC_PING_TIMEOUT = 1000;
@@ -0,0 +1,37 @@
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.Utils = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ class Utils {
9
+ static fromHexToArray(str) {
10
+ return new Uint8Array(Buffer.from(str, 'hex'));
11
+ }
12
+ static fromBufferToHex(buffer) {
13
+ return Buffer.from(buffer).toString('hex');
14
+ }
15
+ static fromBufferToB64(buffer) {
16
+ return Buffer.from(buffer).toString('base64');
17
+ }
18
+ static fromUtf8ToArray(str) {
19
+ return new Uint8Array(Buffer.from(str, 'utf8'));
20
+ }
21
+ static fromB64ToArray(str) {
22
+ return new Uint8Array(Buffer.from(str, 'base64'));
23
+ }
24
+ static getCurrentOS() {
25
+ const platform = os_1.default.platform();
26
+ const arc = os_1.default.arch();
27
+ let _os = 'linux';
28
+ if (platform === 'darwin') {
29
+ _os = arc === 'x64' ? 'mac-x64' : 'mac-arm64';
30
+ }
31
+ if (platform === 'win32') {
32
+ _os = 'windows';
33
+ }
34
+ return _os;
35
+ }
36
+ }
37
+ exports.Utils = Utils;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });