@privateaim/kit 0.8.3 → 0.8.5

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 (36) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/crypto/asymmetric/constants.d.ts +5 -0
  3. package/dist/crypto/asymmetric/constants.d.ts.map +1 -0
  4. package/dist/crypto/asymmetric/helpers.d.ts +5 -0
  5. package/dist/crypto/asymmetric/helpers.d.ts.map +1 -0
  6. package/dist/crypto/asymmetric/index.d.ts +5 -0
  7. package/dist/crypto/asymmetric/index.d.ts.map +1 -0
  8. package/dist/crypto/asymmetric/module.d.ts +14 -0
  9. package/dist/crypto/asymmetric/module.d.ts.map +1 -0
  10. package/dist/crypto/asymmetric/types.d.ts +3 -0
  11. package/dist/crypto/asymmetric/types.d.ts.map +1 -0
  12. package/dist/crypto/index.d.ts +3 -0
  13. package/dist/crypto/index.d.ts.map +1 -0
  14. package/dist/crypto/symmetric/index.d.ts +3 -0
  15. package/dist/crypto/symmetric/index.d.ts.map +1 -0
  16. package/dist/crypto/symmetric/module.d.ts +10 -0
  17. package/dist/crypto/symmetric/module.d.ts.map +1 -0
  18. package/dist/crypto/symmetric/types.d.ts +3 -0
  19. package/dist/crypto/symmetric/types.d.ts.map +1 -0
  20. package/dist/index.cjs +434 -6
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.mjs +427 -7
  25. package/dist/index.mjs.map +1 -1
  26. package/package.json +3 -3
  27. package/src/crypto/asymmetric/constants.ts +12 -0
  28. package/src/crypto/asymmetric/helpers.ts +58 -0
  29. package/src/crypto/asymmetric/index.ts +11 -0
  30. package/src/crypto/asymmetric/module.ts +190 -0
  31. package/src/crypto/asymmetric/types.ts +9 -0
  32. package/src/crypto/index.ts +9 -0
  33. package/src/crypto/symmetric/index.ts +9 -0
  34. package/src/crypto/symmetric/module.ts +71 -0
  35. package/src/crypto/symmetric/types.ts +10 -0
  36. package/src/index.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.5](https://github.com/PrivateAIM/hub/compare/v0.8.4...v0.8.5) (2025-01-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * basic web crypto implementation (P.P. research-project) + node key-pair generation ([#912](https://github.com/PrivateAIM/hub/issues/912)) ([8cdb9d8](https://github.com/PrivateAIM/hub/commit/8cdb9d8ff140400426ccbd61f254a47fa0e3fab1))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** bump @authup/core-kit from 1.0.0-beta.22 to 1.0.0-beta.23 ([#896](https://github.com/PrivateAIM/hub/issues/896)) ([e0dcfed](https://github.com/PrivateAIM/hub/commit/e0dcfed47320bd53fadbca11a05ca677ed0ef7ff))
14
+ * **deps:** bump authup to v1.0.0-beta.24 ([#963](https://github.com/PrivateAIM/hub/issues/963)) ([90c40c0](https://github.com/PrivateAIM/hub/commit/90c40c0d55018557ee8bb381aad7e3cfbcd29b83))
15
+
16
+ ## [0.8.4](https://github.com/PrivateAIM/hub/compare/v0.8.3...v0.8.4) (2024-10-24)
17
+
18
+
19
+ ### Features
20
+
21
+ * bump authup & implement async policy & permission evaluation ([#807](https://github.com/PrivateAIM/hub/issues/807)) ([d065562](https://github.com/PrivateAIM/hub/commit/d065562585076e26553ad5a39f4a5789f7e18f24))
22
+ * bump authup & vuecs packages + refactored navigation ([c4db8d5](https://github.com/PrivateAIM/hub/commit/c4db8d51588b3d701815e2ba2f9b80e594f3663f))
23
+
3
24
  ## [0.8.3](https://github.com/PrivateAIM/hub/compare/v0.8.2...v0.8.3) (2024-09-19)
4
25
 
5
26
  ## [0.8.2](https://github.com/PrivateAIM/hub/compare/v0.8.1...v0.8.2) (2024-08-28)
@@ -0,0 +1,5 @@
1
+ export declare enum AsymmetricCryptoAlgorithmName {
2
+ RSA_OAEP = "RSA-OAEP",
3
+ ECDH = "ECDH"
4
+ }
5
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/crypto/asymmetric/constants.ts"],"names":[],"mappings":"AAOA,oBAAY,6BAA6B;IACrC,QAAQ,aAAa;IAErB,IAAI,SAAS;CAChB"}
@@ -0,0 +1,5 @@
1
+ import type { AsymmetricAlgorithmImportParams } from './types';
2
+ export declare function exportAsymmetricPublicKey(key: CryptoKey): Promise<string>;
3
+ export declare function exportAsymmetricPrivateKey(key: CryptoKey): Promise<string>;
4
+ export declare function importAsymmetricPublicKey(pem: string, params: AsymmetricAlgorithmImportParams): Promise<CryptoKey>;
5
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/crypto/asymmetric/helpers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAM/D,wBAAsB,yBAAyB,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAO/E;AAED,wBAAsB,0BAA0B,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAOhF;AAED,wBAAsB,yBAAyB,CAC3C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,+BAA+B,GACxC,OAAO,CAAC,SAAS,CAAC,CAuBpB"}
@@ -0,0 +1,5 @@
1
+ export * from './constants';
2
+ export * from './helpers';
3
+ export * from './module';
4
+ export * from './types';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/asymmetric/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { AsymmetricAlgorithmImportParams, AsymmetricAlgorithmParams } from './types';
2
+ export declare class CryptoAsymmetricAlgorithm {
3
+ readonly algorithm: AsymmetricAlgorithmParams;
4
+ protected keyPair: CryptoKeyPair | undefined;
5
+ constructor(algorithm: AsymmetricAlgorithmParams);
6
+ buildImportParams(): AsymmetricAlgorithmImportParams;
7
+ generateKeyPair(): Promise<CryptoKeyPair>;
8
+ useKeyPair(): Promise<CryptoKeyPair>;
9
+ exportPublicKey(): Promise<string>;
10
+ exportPrivateKey(): Promise<string>;
11
+ encrypt(data: Buffer, remoteKey?: CryptoKey): Promise<ArrayBuffer>;
12
+ decrypt(data: Buffer, remoteKey?: CryptoKey): Promise<ArrayBuffer>;
13
+ }
14
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/crypto/asymmetric/module.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,+BAA+B,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAG1F,qBAAa,yBAAyB;IAClC,SAAgB,SAAS,EAAE,yBAAyB,CAAC;IAErD,SAAS,CAAC,OAAO,EAAG,aAAa,GAAG,SAAS,CAAC;gBAElC,SAAS,EAAE,yBAAyB;IAWhD,iBAAiB,IAAK,+BAA+B;IAmB/C,eAAe,IAAK,OAAO,CAAC,aAAa,CAAC;IAwB1C,UAAU,IAAI,OAAO,CAAC,aAAa,CAAC;IAQpC,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAMlC,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAMnC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS;IAoD3C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,SAAS;CA+CpD"}
@@ -0,0 +1,3 @@
1
+ export type AsymmetricAlgorithmParams = RsaHashedKeyGenParams | EcKeyGenParams;
2
+ export type AsymmetricAlgorithmImportParams = RsaHashedImportParams | EcKeyImportParams;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/crypto/asymmetric/types.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,GAAG,cAAc,CAAC;AAC/E,MAAM,MAAM,+BAA+B,GAAG,qBAAqB,GAAG,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './asymmetric';
2
+ export * from './symmetric';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './module';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/crypto/symmetric/index.ts"],"names":[],"mappings":"AAOA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { SymmetricAlgorithmParams } from './types';
2
+ export declare class CryptoSymmetricAlgorithm {
3
+ protected algorithm: SymmetricAlgorithmParams;
4
+ constructor(algorithm: SymmetricAlgorithmParams);
5
+ generateKey(): Promise<CryptoKey>;
6
+ importKey(buffer: Buffer | ArrayBuffer): Promise<CryptoKey>;
7
+ encrypt(key: CryptoKey, iv: Buffer, data: Buffer): Promise<Buffer>;
8
+ decrypt(key: CryptoKey, data: Buffer): Promise<Buffer>;
9
+ }
10
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/crypto/symmetric/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAExD,qBAAa,wBAAwB;IACjC,SAAS,CAAC,SAAS,EAAG,wBAAwB,CAAC;gBAEnC,SAAS,EAAE,wBAAwB;IAIzC,WAAW,IAAK,OAAO,CAAC,SAAS,CAAC;IAWlC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAI,OAAO,CAAC,SAAS,CAAC;IAa5D,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAgBnE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;CAchE"}
@@ -0,0 +1,3 @@
1
+ import type { webcrypto } from 'crypto';
2
+ export type SymmetricAlgorithmParams = webcrypto.AesKeyGenParams;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/crypto/symmetric/types.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,wBAAwB,GAAG,SAAS,CAAC,eAAe,CAAC"}
package/dist/index.cjs CHANGED
@@ -2,13 +2,432 @@
2
2
 
3
3
  var nanoid = require('nanoid');
4
4
 
5
+ /*
6
+ * Copyright (c) 2024.
7
+ * Author Peter Placzek (tada5hi)
8
+ * For the full copyright and license information,
9
+ * view the LICENSE file that was distributed with this source code.
10
+ */ var AsymmetricCryptoAlgorithmName = /*#__PURE__*/ function(AsymmetricCryptoAlgorithmName) {
11
+ AsymmetricCryptoAlgorithmName["RSA_OAEP"] = "RSA-OAEP";
12
+ AsymmetricCryptoAlgorithmName["ECDH"] = "ECDH";
13
+ return AsymmetricCryptoAlgorithmName;
14
+ }({});
15
+
16
+ /*
17
+ * Copyright (c) 2024.
18
+ * Author Peter Placzek (tada5hi)
19
+ * For the full copyright and license information,
20
+ * view the LICENSE file that was distributed with this source code.
21
+ */ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
22
+ try {
23
+ var info = gen[key](arg);
24
+ var value = info.value;
25
+ } catch (error) {
26
+ reject(error);
27
+ return;
28
+ }
29
+ if (info.done) {
30
+ resolve(value);
31
+ } else {
32
+ Promise.resolve(value).then(_next, _throw);
33
+ }
34
+ }
35
+ function _async_to_generator$2(fn) {
36
+ return function() {
37
+ var self = this, args = arguments;
38
+ return new Promise(function(resolve, reject) {
39
+ var gen = fn.apply(self, args);
40
+ function _next(value) {
41
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
42
+ }
43
+ function _throw(err) {
44
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
45
+ }
46
+ _next(undefined);
47
+ });
48
+ };
49
+ }
50
+ function arrayBufferToBase64(arrayBuffer) {
51
+ return btoa(String.fromCharCode.apply(null, new Uint8Array(arrayBuffer)));
52
+ }
53
+ function exportAsymmetricPublicKey(key) {
54
+ return _exportAsymmetricPublicKey.apply(this, arguments);
55
+ }
56
+ function _exportAsymmetricPublicKey() {
57
+ _exportAsymmetricPublicKey = _async_to_generator$2(function*(key) {
58
+ const exported = yield crypto.subtle.exportKey('spki', key);
59
+ return `-----BEGIN PUBLIC KEY-----\n${arrayBufferToBase64(exported)}\n-----END PUBLIC KEY-----`;
60
+ });
61
+ return _exportAsymmetricPublicKey.apply(this, arguments);
62
+ }
63
+ function exportAsymmetricPrivateKey(key) {
64
+ return _exportAsymmetricPrivateKey.apply(this, arguments);
65
+ }
66
+ function _exportAsymmetricPrivateKey() {
67
+ _exportAsymmetricPrivateKey = _async_to_generator$2(function*(key) {
68
+ const exported = yield crypto.subtle.exportKey('pkcs8', key);
69
+ return `-----BEGIN PRIVATE KEY-----\n${arrayBufferToBase64(exported)}\n-----END PRIVATE KEY-----`;
70
+ });
71
+ return _exportAsymmetricPrivateKey.apply(this, arguments);
72
+ }
73
+ function importAsymmetricPublicKey(pem, params) {
74
+ return _importAsymmetricPublicKey.apply(this, arguments);
75
+ }
76
+ function _importAsymmetricPublicKey() {
77
+ _importAsymmetricPublicKey = _async_to_generator$2(function*(pem, params) {
78
+ const pemHeader = '-----BEGIN PUBLIC KEY-----';
79
+ const pemFooter = '-----END PUBLIC KEY-----';
80
+ const pemContents = pem.substring(pemHeader.length, pem.length - pemFooter.length);
81
+ const buffer = Buffer.from(pemContents, 'base64');
82
+ if (params.name === 'ECDH') {
83
+ return crypto.subtle.importKey('spki', buffer, params, true, [
84
+ 'deriveKey'
85
+ ]);
86
+ }
87
+ return crypto.subtle.importKey('spki', buffer, params, true, [
88
+ 'encrypt'
89
+ ]);
90
+ });
91
+ return _importAsymmetricPublicKey.apply(this, arguments);
92
+ }
93
+
94
+ /*
95
+ * Copyright (c) 2024.
96
+ * Author Peter Placzek (tada5hi)
97
+ * For the full copyright and license information,
98
+ * view the LICENSE file that was distributed with this source code.
99
+ */ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
100
+ try {
101
+ var info = gen[key](arg);
102
+ var value = info.value;
103
+ } catch (error) {
104
+ reject(error);
105
+ return;
106
+ }
107
+ if (info.done) {
108
+ resolve(value);
109
+ } else {
110
+ Promise.resolve(value).then(_next, _throw);
111
+ }
112
+ }
113
+ function _async_to_generator$1(fn) {
114
+ return function() {
115
+ var self = this, args = arguments;
116
+ return new Promise(function(resolve, reject) {
117
+ var gen = fn.apply(self, args);
118
+ function _next(value) {
119
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
120
+ }
121
+ function _throw(err) {
122
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
123
+ }
124
+ _next(undefined);
125
+ });
126
+ };
127
+ }
128
+ function _define_property$1(obj, key, value) {
129
+ if (key in obj) {
130
+ Object.defineProperty(obj, key, {
131
+ value: value,
132
+ enumerable: true,
133
+ configurable: true,
134
+ writable: true
135
+ });
136
+ } else {
137
+ obj[key] = value;
138
+ }
139
+ return obj;
140
+ }
141
+ function _object_spread(target) {
142
+ for(var i = 1; i < arguments.length; i++){
143
+ var source = arguments[i] != null ? arguments[i] : {};
144
+ var ownKeys = Object.keys(source);
145
+ if (typeof Object.getOwnPropertySymbols === "function") {
146
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
147
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
148
+ }));
149
+ }
150
+ ownKeys.forEach(function(key) {
151
+ _define_property$1(target, key, source[key]);
152
+ });
153
+ }
154
+ return target;
155
+ }
156
+ function ownKeys(object, enumerableOnly) {
157
+ var keys = Object.keys(object);
158
+ if (Object.getOwnPropertySymbols) {
159
+ var symbols = Object.getOwnPropertySymbols(object);
160
+ keys.push.apply(keys, symbols);
161
+ }
162
+ return keys;
163
+ }
164
+ function _object_spread_props(target, source) {
165
+ source = source != null ? source : {};
166
+ if (Object.getOwnPropertyDescriptors) {
167
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
168
+ } else {
169
+ ownKeys(Object(source)).forEach(function(key) {
170
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
171
+ });
172
+ }
173
+ return target;
174
+ }
175
+ class CryptoAsymmetricAlgorithm {
176
+ buildImportParams() {
177
+ if (this.algorithm.name === AsymmetricCryptoAlgorithmName.RSA_OAEP) {
178
+ return {
179
+ name: 'RSA-OAEP',
180
+ hash: 'SHA-256'
181
+ };
182
+ }
183
+ if (this.algorithm.name === AsymmetricCryptoAlgorithmName.ECDH) {
184
+ return {
185
+ name: 'ECDH',
186
+ namedCurve: this.algorithm.namedCurve,
187
+ hash: 'SHA-256'
188
+ };
189
+ }
190
+ throw new Error('Import params could not be created.');
191
+ }
192
+ generateKeyPair() {
193
+ var _this = this;
194
+ return _async_to_generator$1(function*() {
195
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.RSA_OAEP) {
196
+ _this.keyPair = yield crypto.subtle.generateKey(_this.algorithm, true, [
197
+ 'encrypt',
198
+ 'decrypt'
199
+ ]);
200
+ return _this.keyPair;
201
+ }
202
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.ECDH) {
203
+ _this.keyPair = yield crypto.subtle.generateKey(_this.algorithm, true, [
204
+ 'deriveKey'
205
+ ]);
206
+ return _this.keyPair;
207
+ }
208
+ throw new Error('The algorithm is not supported for key generation.');
209
+ })();
210
+ }
211
+ useKeyPair() {
212
+ var _this = this;
213
+ return _async_to_generator$1(function*() {
214
+ if (typeof _this.keyPair !== 'undefined') {
215
+ return _this.keyPair;
216
+ }
217
+ return _this.generateKeyPair();
218
+ })();
219
+ }
220
+ exportPublicKey() {
221
+ var _this = this;
222
+ return _async_to_generator$1(function*() {
223
+ const keyPair = yield _this.useKeyPair();
224
+ return exportAsymmetricPublicKey(keyPair.publicKey);
225
+ })();
226
+ }
227
+ exportPrivateKey() {
228
+ var _this = this;
229
+ return _async_to_generator$1(function*() {
230
+ const keyPair = yield _this.useKeyPair();
231
+ return exportAsymmetricPrivateKey(keyPair.privateKey);
232
+ })();
233
+ }
234
+ encrypt(data, remoteKey) {
235
+ var _this = this;
236
+ return _async_to_generator$1(function*() {
237
+ const keyPair = yield _this.useKeyPair();
238
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.RSA_OAEP) {
239
+ return crypto.subtle.encrypt({
240
+ name: 'RSA-OAEP'
241
+ }, remoteKey || keyPair.publicKey, data);
242
+ }
243
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.ECDH) {
244
+ if (typeof remoteKey === 'undefined') {
245
+ throw new Error('Remote public key is required.');
246
+ }
247
+ const array = new Uint8Array(16);
248
+ const iv = crypto.getRandomValues(array);
249
+ const key = yield crypto.subtle.deriveKey({
250
+ name: 'ECDH',
251
+ public: remoteKey
252
+ }, keyPair.privateKey, {
253
+ name: 'AES-GCM',
254
+ length: 256
255
+ }, true, [
256
+ 'encrypt'
257
+ ]);
258
+ const arrayBuffer = yield crypto.subtle.encrypt({
259
+ name: 'AES-GCM',
260
+ length: 256,
261
+ iv
262
+ }, key, data);
263
+ const buffer = Buffer.from(arrayBuffer);
264
+ return Buffer.concat([
265
+ iv,
266
+ buffer
267
+ ]);
268
+ }
269
+ throw new Error('Unsupported algorithm for encryption.');
270
+ })();
271
+ }
272
+ decrypt(data, remoteKey) {
273
+ var _this = this;
274
+ return _async_to_generator$1(function*() {
275
+ const keyPair = yield _this.useKeyPair();
276
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.RSA_OAEP) {
277
+ return crypto.subtle.decrypt({
278
+ name: 'RSA-OAEP'
279
+ }, keyPair.privateKey, data);
280
+ }
281
+ if (_this.algorithm.name === AsymmetricCryptoAlgorithmName.ECDH) {
282
+ if (typeof remoteKey === 'undefined') {
283
+ throw new Error('Remote public key is required.');
284
+ }
285
+ const iv = data.slice(0, 16);
286
+ const key = yield crypto.subtle.deriveKey({
287
+ name: 'ECDH',
288
+ public: remoteKey
289
+ }, keyPair.privateKey, {
290
+ name: 'AES-GCM',
291
+ length: 256
292
+ }, true, [
293
+ 'decrypt'
294
+ ]);
295
+ return crypto.subtle.decrypt({
296
+ name: 'AES-GCM',
297
+ length: 256,
298
+ iv
299
+ }, key, data.slice(16));
300
+ }
301
+ throw new Error('Unsupported algorithm for decryption.');
302
+ })();
303
+ }
304
+ constructor(algorithm){
305
+ _define_property$1(this, "algorithm", undefined);
306
+ _define_property$1(this, "keyPair", undefined);
307
+ if (algorithm.name === AsymmetricCryptoAlgorithmName.RSA_OAEP) {
308
+ algorithm = _object_spread_props(_object_spread({}, algorithm), {
309
+ publicExponent: new Uint8Array([
310
+ 1,
311
+ 0,
312
+ 1
313
+ ])
314
+ });
315
+ }
316
+ this.algorithm = algorithm;
317
+ }
318
+ }
319
+
320
+ /*
321
+ * Copyright (c) 2024.
322
+ * Author Peter Placzek (tada5hi)
323
+ * For the full copyright and license information,
324
+ * view the LICENSE file that was distributed with this source code.
325
+ */ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
326
+ try {
327
+ var info = gen[key](arg);
328
+ var value = info.value;
329
+ } catch (error) {
330
+ reject(error);
331
+ return;
332
+ }
333
+ if (info.done) {
334
+ resolve(value);
335
+ } else {
336
+ Promise.resolve(value).then(_next, _throw);
337
+ }
338
+ }
339
+ function _async_to_generator(fn) {
340
+ return function() {
341
+ var self = this, args = arguments;
342
+ return new Promise(function(resolve, reject) {
343
+ var gen = fn.apply(self, args);
344
+ function _next(value) {
345
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
346
+ }
347
+ function _throw(err) {
348
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
349
+ }
350
+ _next(undefined);
351
+ });
352
+ };
353
+ }
354
+ function _define_property(obj, key, value) {
355
+ if (key in obj) {
356
+ Object.defineProperty(obj, key, {
357
+ value: value,
358
+ enumerable: true,
359
+ configurable: true,
360
+ writable: true
361
+ });
362
+ } else {
363
+ obj[key] = value;
364
+ }
365
+ return obj;
366
+ }
367
+ class CryptoSymmetricAlgorithm {
368
+ generateKey() {
369
+ var _this = this;
370
+ return _async_to_generator(function*() {
371
+ return crypto.subtle.generateKey({
372
+ name: _this.algorithm.name,
373
+ length: 256
374
+ }, true, [
375
+ 'encrypt',
376
+ 'decrypt'
377
+ ]);
378
+ })();
379
+ }
380
+ importKey(buffer) {
381
+ var _this = this;
382
+ return _async_to_generator(function*() {
383
+ return crypto.subtle.importKey('raw', buffer, {
384
+ name: _this.algorithm.name,
385
+ length: 256
386
+ }, true, [
387
+ 'encrypt',
388
+ 'decrypt'
389
+ ]);
390
+ })();
391
+ }
392
+ encrypt(key, iv, data) {
393
+ var _this = this;
394
+ return _async_to_generator(function*() {
395
+ const arrayBuffer = yield crypto.subtle.encrypt({
396
+ name: _this.algorithm.name,
397
+ length: 256,
398
+ iv
399
+ }, key, data);
400
+ const buffer = Buffer.from(arrayBuffer);
401
+ return Buffer.concat([
402
+ iv,
403
+ buffer
404
+ ]);
405
+ })();
406
+ }
407
+ decrypt(key, data) {
408
+ var _this = this;
409
+ return _async_to_generator(function*() {
410
+ const iv = data.slice(0, 16);
411
+ const arrayBuffer = yield crypto.subtle.decrypt({
412
+ name: _this.algorithm.name,
413
+ length: 256,
414
+ iv
415
+ }, key, data.slice(16));
416
+ return Buffer.from(arrayBuffer);
417
+ })();
418
+ }
419
+ constructor(algorithm){
420
+ _define_property(this, "algorithm", undefined);
421
+ this.algorithm = algorithm;
422
+ }
423
+ }
424
+
5
425
  /*
6
426
  * Copyright (c) 2021-2024.
7
427
  * Author Peter Placzek (tada5hi)
8
428
  * For the full copyright and license information,
9
429
  * view the LICENSE file that was distributed with this source code.
10
- */ exports.PermissionName = void 0;
11
- (function(PermissionName) {
430
+ */ var PermissionName = /*#__PURE__*/ function(PermissionName) {
12
431
  PermissionName["BUCKET_CREATE"] = "bucket_create";
13
432
  PermissionName["BUCKET_UPDATE"] = "bucket_update";
14
433
  PermissionName["BUCKET_DELETE"] = "bucket_delete";
@@ -31,7 +450,8 @@ var nanoid = require('nanoid');
31
450
  PermissionName["MASTER_IMAGE_MANAGE"] = "master_image_manage";
32
451
  PermissionName["MASTER_IMAGE_GROUP_MANAGE"] = "master_image_group_manage";
33
452
  PermissionName["SERVICE_MANAGE"] = "service_manage";
34
- })(exports.PermissionName || (exports.PermissionName = {}));
453
+ return PermissionName;
454
+ }({});
35
455
 
36
456
  /*
37
457
  * Copyright (c) 2024.
@@ -186,20 +606,28 @@ const registryRobotSecretRegex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d).{8,}$/;
186
606
  * Author Peter Placzek (tada5hi)
187
607
  * For the full copyright and license information,
188
608
  * view the LICENSE file that was distributed with this source code.
189
- */ exports.EnvironmentName = void 0;
190
- (function(EnvironmentName) {
609
+ */ var EnvironmentName = /*#__PURE__*/ function(EnvironmentName) {
191
610
  EnvironmentName["TEST"] = "test";
192
611
  EnvironmentName["DEVELOPMENT"] = "development";
193
612
  EnvironmentName["PRODUCTION"] = "production";
194
- })(exports.EnvironmentName || (exports.EnvironmentName = {}));
613
+ return EnvironmentName;
614
+ }({});
195
615
 
616
+ exports.AsymmetricCryptoAlgorithmName = AsymmetricCryptoAlgorithmName;
617
+ exports.CryptoAsymmetricAlgorithm = CryptoAsymmetricAlgorithm;
618
+ exports.CryptoSymmetricAlgorithm = CryptoSymmetricAlgorithm;
619
+ exports.EnvironmentName = EnvironmentName;
620
+ exports.PermissionName = PermissionName;
196
621
  exports.alphaNumHyphenUnderscoreRegex = alphaNumHyphenUnderscoreRegex;
197
622
  exports.createNanoID = createNanoID;
198
623
  exports.deleteUndefinedObjectProperties = deleteUndefinedObjectProperties;
199
624
  exports.detectProxyConnectionConfig = detectProxyConnectionConfig;
625
+ exports.exportAsymmetricPrivateKey = exportAsymmetricPrivateKey;
626
+ exports.exportAsymmetricPublicKey = exportAsymmetricPublicKey;
200
627
  exports.getHostNameFromString = getHostNameFromString;
201
628
  exports.hasOwnProperty = hasOwnProperty;
202
629
  exports.hexToUTF8 = hexToUTF8;
630
+ exports.importAsymmetricPublicKey = importAsymmetricPublicKey;
203
631
  exports.isBool = isBool;
204
632
  exports.isBoolFalse = isBoolFalse;
205
633
  exports.isBoolTrue = isBoolTrue;