@venizia/ignis-helpers 0.4.7-2 → 0.4.7-3
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/dist/esm/core.d.ts +3 -0
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +6 -1
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.d.ts +22 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.js +10 -0
- package/dist/esm/modules/crypto/algorithms/abstract.algorithm.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.d.ts +7 -6
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +32 -38
- package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +9 -8
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +46 -41
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.engine.d.ts +32 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.js +76 -0
- package/dist/esm/modules/crypto/algorithms/aes.engine.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts +10 -17
- package/dist/esm/modules/crypto/algorithms/base.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js +51 -12
- package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts +37 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js +95 -0
- package/dist/esm/modules/crypto/algorithms/credential.algorithm.js.map +1 -0
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts +6 -2
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js +18 -5
- package/dist/esm/modules/crypto/algorithms/ecdh.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +2 -3
- package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/index.d.ts +1 -0
- package/dist/esm/modules/crypto/algorithms/index.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/index.js +1 -0
- package/dist/esm/modules/crypto/algorithms/index.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts +8 -7
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js +22 -25
- package/dist/esm/modules/crypto/algorithms/rsa.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/common/types.d.ts +3 -3
- package/dist/esm/modules/crypto/common/types.d.ts.map +1 -1
- package/dist/esm/modules/crypto/common/types.js.map +1 -1
- package/dist/esm/modules/uid/uuid/sha1.d.ts +1 -1
- package/dist/esm/modules/uid/uuid/sha1.js +1 -1
- package/dist/esm/modules/uid/uuid/sha1.js.map +1 -1
- package/package.json +2 -2
package/dist/esm/core.d.ts
CHANGED
|
@@ -30,6 +30,9 @@ export { ParseUtility } from './utilities/parse.utility.js';
|
|
|
30
30
|
export { PerformanceUtility } from './utilities/performance.utility.js';
|
|
31
31
|
export { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility.js';
|
|
32
32
|
export { ProjectRootRegistry } from './utilities/project-root.utility.js';
|
|
33
|
+
export { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm.js';
|
|
34
|
+
export { ECDH } from './modules/crypto/algorithms/ecdh.algorithm.js';
|
|
35
|
+
export type { ECDHAlgorithmType, IECDHEncryptedPayload, IECDHExtraOptions, } from './modules/crypto/algorithms/ecdh.algorithm.js';
|
|
33
36
|
export { AESAlgorithms } from './modules/crypto/algorithms/aes.constants.js';
|
|
34
37
|
export type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants.js';
|
|
35
38
|
export type { IPayloadCipher } from './modules/crypto/common/types.js';
|
package/dist/esm/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,YAAY,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAGzF,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,cAAc,qDAAqD,CAAC;AAIpE,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAG9B,cAAc,yDAAyD,CAAC;AACxE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qDAAqD,CAAC;AAC5F,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,E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YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAKvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAClE,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,4CAA4C,CAAC;AAKpD,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC;AAC1E,YAAY,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAClF,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,YAAY,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/esm/core.js
CHANGED
|
@@ -37,8 +37,13 @@ export { ParseUtility } from './utilities/parse.utility.js';
|
|
|
37
37
|
export { PerformanceUtility } from './utilities/performance.utility.js';
|
|
38
38
|
export { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility.js';
|
|
39
39
|
export { ProjectRootRegistry } from './utilities/project-root.utility.js';
|
|
40
|
+
// `ECDH` is the one crypto algorithm that is browser-pure: it runs over `crypto.subtle`, `btoa` and `atob`. It and its
|
|
41
|
+
// base class come by leaf path, never the algorithms barrel, which also carries `AES`, `LegacyAES` and `RSA`
|
|
42
|
+
// (server code: they use `Buffer`, and `AES` reads files with `node:fs`).
|
|
43
|
+
export { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm.js';
|
|
44
|
+
export { ECDH } from './modules/crypto/algorithms/ecdh.algorithm.js';
|
|
40
45
|
// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even
|
|
41
|
-
// though the concrete classes they describe (crypto algorithms, the ioredis-backed helper) are not
|
|
46
|
+
// though the concrete classes they describe (the other crypto algorithms, the ioredis-backed helper) are not
|
|
42
47
|
// themselves part of this pure surface.
|
|
43
48
|
export { AESAlgorithms } from './modules/crypto/algorithms/aes.constants.js';
|
|
44
49
|
//# sourceMappingURL=core.js.map
|
package/dist/esm/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,6FAA6F;AAC7F,8DAA8D;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,6HAA6H;AAC7H,iHAAiH;AACjH,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,cAAc,qDAAqD,CAAC;AACpE,qGAAqG;AACrG,4FAA4F;AAC5F,oBAAoB;AACpB,cAAc,qDAAqD,CAAC;AACpE,cAAc,4DAA4D,CAAC;AAC3E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,iGAAiG;AACjG,yFAAyF;AACzF,cAAc,yDAAyD,CAAC;AAExE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,0CAA0C,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAA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AAsB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAcrD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,gGAAgG;AAChG,6FAA6F;AAC7F,iGAAiG;AACjG,0DAA0D;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAEvE,uHAAuH;AACvH,6GAA6G;AAC7G,0EAA0E;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,gDAAgD,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AAOlE,+FAA+F;AAC/F,6GAA6G;AAC7G,wCAAwC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,2CAA2C,CAAC","sourcesContent":["export { BaseHelper } from './modules/base';\n// By name, never `export *` from `./modules/env`: that barrel also carries `Environment` and\n// `applicationEnvironment`, both of which read `process.env`.\nexport { EnvironmentNames } from './modules/env/names';\nexport * from './modules/error';\nexport { LogLevels } from './modules/logger/common/types';\nexport type { ILogger, ILoggerProvider, TLogLevel } from './modules/logger/common/types';\n// The one way to get a logger, the same in the browser and on the server: `LoggerFactory` imports nothing from node, and its\n// default provider is the console. An application chooses another with `LoggerFactory.use({ provider, level })`.\nexport { ConsoleLogger } from './modules/logger/base/console';\nexport { LoggerFactory } from './modules/logger/factory';\nexport * from './modules/network/http-request/fetcher/base-fetcher';\n// The node fetcher carries no node builtin - its one `querystring.stringify` is written out - so the\n// framework HTTP layer is reachable from a browser bundle, and a connector on HTTP need not\n// re-implement one.\nexport * from './modules/network/http-request/fetcher/node-fetcher';\nexport * from './modules/network/http-request/base-network-request.helper';\nexport * from './modules/pool';\nexport * from './modules/queue/internal/hf';\nexport * from './modules/temporal';\nexport * from './modules/uid';\n// The url guard, pure half only: `UrlPolicy` decides a url and a literal address with string and\n// number work. Its sibling `UrlIngest` reaches `node:dns` and stays out of this subpath.\nexport * from './modules/network/utilities/url-safety/common/constants';\nexport type { IUrlSafetyPolicy } from './modules/network/utilities/url-safety/common/types';\nexport * from './modules/network/utilities/url-safety/policy';\nexport * from './modules/network/utilities/query-string';\nexport { RetryBackoffStrategies, RetryJitterModes } from './modules/retry/common/constants';\nexport type { TRetryBackoffStrategy, TRetryJitterMode } from './modules/retry/common/constants';\nexport type { IRetryBackoffOptions, IRetryContext } from './modules/retry/common/types';\nexport { RetryHelper } from './modules/retry/helper';\nexport { SlugHelper } from './modules/slug/helper';\nexport { TreeBuilder } from './modules/tree/builder';\nexport type {\n IBuildOptions,\n IHeightWhereOptions,\n ILeavesOptions,\n INodeWithPath,\n IPrintOptions,\n ITreeNode,\n IWalkAsyncOptions,\n IWalkOptions,\n TNodePredicate,\n TOnVisit,\n TOnVisitAsync,\n} from './modules/tree/common/types';\nexport { TreeWalker } from './modules/tree/walk';\n\n// Pure value/type utilities that already live under the root barrel's `./utilities` re-export -\n// that barrel also carries node-only siblings (module.utility.ts, request.utility.ts), so it\n// cannot itself become a subpath. Named one at a time here instead of widening the barrel: every\n// symbol below is verified free of node builtins/globals.\nexport { BuildInfoRegistry } from './utilities/build-info.utility';\nexport type { IBuildInfo, TBuildInfoRecord } from './utilities/build-info.utility';\nexport { ParseUtility } from './utilities/parse.utility';\nexport { PerformanceUtility } from './utilities/performance.utility';\nexport { FormBodyUtility, RequestBodyErrors } from './utilities/form-body.utility';\nexport { ProjectRootRegistry } from './utilities/project-root.utility';\n\n// `ECDH` is the one crypto algorithm that is browser-pure: it runs over `crypto.subtle`, `btoa` and `atob`. It and its\n// base class come by leaf path, never the algorithms barrel, which also carries `AES`, `LegacyAES` and `RSA`\n// (server code: they use `Buffer`, and `AES` reads files with `node:fs`).\nexport { AbstractCryptoAlgorithm } from './modules/crypto/algorithms/abstract.algorithm';\nexport { ECDH } from './modules/crypto/algorithms/ecdh.algorithm';\nexport type {\n ECDHAlgorithmType,\n IECDHEncryptedPayload,\n IECDHExtraOptions,\n} from './modules/crypto/algorithms/ecdh.algorithm';\n\n// Type-only: erased at compile time, so re-exporting these carries no runtime/bundle cost even\n// though the concrete classes they describe (the other crypto algorithms, the ioredis-backed helper) are not\n// themselves part of this pure surface.\nexport { AESAlgorithms } from './modules/crypto/algorithms/aes.constants';\nexport type { AESAlgorithmType } from './modules/crypto/algorithms/aes.constants';\nexport type { IPayloadCipher } from './modules/crypto/common/types';\nexport type { IRedisHelper } from './modules/redis/common/interfaces';\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseHelper } from '../../base.js';
|
|
2
|
+
import type { ICryptoAlgorithm } from '../common/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The contract of a crypto algorithm class, with no runtime dependency beyond `BaseHelper`: no `node:*`, no
|
|
5
|
+
* key derivation. It lives in its own file so a browser-pure class (`ECDH`, over `crypto.subtle`) can extend it
|
|
6
|
+
* and ride `@venizia/ignis-helpers/core`. `BaseCryptoAlgorithm` (`base.algorithm.ts`, which needs
|
|
7
|
+
* `Buffer`) extends it for the server algorithms (`AES`, `LegacyAES`, `RSA`).
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class AbstractCryptoAlgorithm<AlgorithmType extends string, EncryptInputType = unknown, DecryptInputType = unknown, SecretKeyType = unknown, EncryptReturnType = unknown, DecryptReturnType = unknown, ExtraOptions = unknown> extends BaseHelper implements ICryptoAlgorithm<AlgorithmType, EncryptInputType, DecryptInputType, SecretKeyType, EncryptReturnType, DecryptReturnType, ExtraOptions> {
|
|
10
|
+
algorithm: AlgorithmType;
|
|
11
|
+
abstract encrypt(opts: {
|
|
12
|
+
message: EncryptInputType;
|
|
13
|
+
secret: SecretKeyType;
|
|
14
|
+
opts?: ExtraOptions;
|
|
15
|
+
}): EncryptReturnType;
|
|
16
|
+
abstract decrypt(opts: {
|
|
17
|
+
message: DecryptInputType;
|
|
18
|
+
secret: SecretKeyType;
|
|
19
|
+
opts?: ExtraOptions;
|
|
20
|
+
}): DecryptReturnType;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=abstract.algorithm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/abstract.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;;GAKG;AACH,8BAAsB,uBAAuB,CAC3C,aAAa,SAAS,MAAM,EAC5B,gBAAgB,GAAG,OAAO,EAC1B,gBAAgB,GAAG,OAAO,EAC1B,aAAa,GAAG,OAAO,EACvB,iBAAiB,GAAG,OAAO,EAC3B,iBAAiB,GAAG,OAAO,EAC3B,YAAY,GAAG,OAAO,CAEtB,SAAQ,UACR,YACE,gBAAgB,CACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,CACb;IAEH,SAAS,EAAE,aAAa,CAAC;IAEzB,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QACrB,OAAO,EAAE,gBAAgB,CAAC;QAC1B,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,CAAC,EAAE,YAAY,CAAC;KACrB,GAAG,iBAAiB;IAErB,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QACrB,OAAO,EAAE,gBAAgB,CAAC;QAC1B,MAAM,EAAE,aAAa,CAAC;QACtB,IAAI,CAAC,EAAE,YAAY,CAAC;KACrB,GAAG,iBAAiB;CACtB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseHelper } from '../../base.js';
|
|
2
|
+
/**
|
|
3
|
+
* The contract of a crypto algorithm class, with no runtime dependency beyond `BaseHelper`: no `node:*`, no
|
|
4
|
+
* key derivation. It lives in its own file so a browser-pure class (`ECDH`, over `crypto.subtle`) can extend it
|
|
5
|
+
* and ride `@venizia/ignis-helpers/core`. `BaseCryptoAlgorithm` (`base.algorithm.ts`, which needs
|
|
6
|
+
* `Buffer`) extends it for the server algorithms (`AES`, `LegacyAES`, `RSA`).
|
|
7
|
+
*/
|
|
8
|
+
export class AbstractCryptoAlgorithm extends BaseHelper {
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=abstract.algorithm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/abstract.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C;;;;;GAKG;AACH,MAAM,OAAgB,uBASpB,SAAQ,UAAU;CAyBnB","sourcesContent":["import { BaseHelper } from '@/modules/base';\nimport type { ICryptoAlgorithm } from '../common/types';\n\n/**\n * The contract of a crypto algorithm class, with no runtime dependency beyond `BaseHelper`: no `node:*`, no\n * key derivation. It lives in its own file so a browser-pure class (`ECDH`, over `crypto.subtle`) can extend it\n * and ride `@venizia/ignis-helpers/core`. `BaseCryptoAlgorithm` (`base.algorithm.ts`, which needs\n * `Buffer`) extends it for the server algorithms (`AES`, `LegacyAES`, `RSA`).\n */\nexport abstract class AbstractCryptoAlgorithm<\n AlgorithmType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n>\n extends BaseHelper\n implements\n ICryptoAlgorithm<\n AlgorithmType,\n EncryptInputType,\n DecryptInputType,\n SecretKeyType,\n EncryptReturnType,\n DecryptReturnType,\n ExtraOptions\n >\n{\n algorithm: AlgorithmType;\n\n abstract encrypt(opts: {\n message: EncryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): EncryptReturnType;\n\n abstract decrypt(opts: {\n message: DecryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): DecryptReturnType;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AESAlgorithmType } from './aes.constants.js';
|
|
2
2
|
import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
3
3
|
interface IAESExtraOptions {
|
|
4
4
|
iv?: Buffer;
|
|
@@ -10,8 +10,9 @@ interface IAESExtraOptions {
|
|
|
10
10
|
* Frozen back-compat format - keys come from `normalizeSecretKeyLegacy` (padEnd/truncate), never
|
|
11
11
|
* PBKDF2. `kdfSalt`/`kdfIterations` are deliberately absent from `IAESExtraOptions`: there is no
|
|
12
12
|
* salt to override, so the option would type-check and silently do nothing.
|
|
13
|
+
* `encrypt` and `decrypt` are async: the cipher runs over `crypto.subtle`.
|
|
13
14
|
*/
|
|
14
|
-
export declare class LegacyAES extends BaseCryptoAlgorithm<AESAlgorithmType, string, string, string, string
|
|
15
|
+
export declare class LegacyAES extends BaseCryptoAlgorithm<AESAlgorithmType, string, string, string, Promise<string>, Promise<string>, IAESExtraOptions> {
|
|
15
16
|
constructor(opts: {
|
|
16
17
|
algorithm: AESAlgorithmType;
|
|
17
18
|
});
|
|
@@ -20,20 +21,20 @@ export declare class LegacyAES extends BaseCryptoAlgorithm<AESAlgorithmType, str
|
|
|
20
21
|
message: string;
|
|
21
22
|
secret: string;
|
|
22
23
|
opts?: IAESExtraOptions;
|
|
23
|
-
}): string
|
|
24
|
+
}): Promise<string>;
|
|
24
25
|
encryptFile(opts: {
|
|
25
26
|
absolutePath: string;
|
|
26
27
|
secret: string;
|
|
27
|
-
}): string
|
|
28
|
+
}): Promise<string>;
|
|
28
29
|
decrypt(opts: {
|
|
29
30
|
message: string;
|
|
30
31
|
secret: string;
|
|
31
32
|
opts?: IAESExtraOptions;
|
|
32
|
-
}): string
|
|
33
|
+
}): Promise<string>;
|
|
33
34
|
decryptFile(opts: {
|
|
34
35
|
absolutePath: string;
|
|
35
36
|
secret: string;
|
|
36
|
-
}): string
|
|
37
|
+
}): Promise<string>;
|
|
37
38
|
private normalizeSecretKeyLegacy;
|
|
38
39
|
}
|
|
39
40
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-legacy.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aes-legacy.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAIvD,UAAU,gBAAgB;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,mBAAmB,CAChD,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,CAAC,MAAM,CAAC,EACf,OAAO,CAAC,MAAM,CAAC,EACf,gBAAgB,CACjB;gBACa,IAAI,EAAE;QAAE,SAAS,EAAE,gBAAgB,CAAA;KAAE;IAIjD,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,gBAAgB;IAI1C,OAAO,CAAC,IAAI,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;KACzB,GAAG,OAAO,CAAC,MAAM,CAAC;IAuCb,WAAW,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAY5E,OAAO,CAAC,IAAI,EAAE;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;KACzB,GAAG,OAAO,CAAC,MAAM,CAAC;IAqCb,WAAW,CAAC,IAAI,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAYlF,OAAO,CAAC,wBAAwB;CASjC"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ObjectUtility } from '@venizia/ignis-inversion';
|
|
2
|
-
import C from 'node:crypto';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
3
|
import { DEFAULT_PAD_END } from '../common/index.js';
|
|
4
|
+
import { AESAlgorithms } from './aes.constants.js';
|
|
5
|
+
import { AesEngine } from './aes.engine.js';
|
|
5
6
|
import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
6
7
|
const DEFAULT_LENGTH = 16;
|
|
7
8
|
/**
|
|
8
9
|
* Frozen back-compat format - keys come from `normalizeSecretKeyLegacy` (padEnd/truncate), never
|
|
9
10
|
* PBKDF2. `kdfSalt`/`kdfIterations` are deliberately absent from `IAESExtraOptions`: there is no
|
|
10
11
|
* salt to override, so the option would type-check and silently do nothing.
|
|
12
|
+
* `encrypt` and `decrypt` are async: the cipher runs over `crypto.subtle`.
|
|
11
13
|
*/
|
|
12
14
|
export class LegacyAES extends BaseCryptoAlgorithm {
|
|
13
15
|
constructor(opts) {
|
|
@@ -16,29 +18,25 @@ export class LegacyAES extends BaseCryptoAlgorithm {
|
|
|
16
18
|
static withAlgorithm(algorithm) {
|
|
17
19
|
return new LegacyAES({ algorithm });
|
|
18
20
|
}
|
|
19
|
-
encrypt(opts) {
|
|
21
|
+
async encrypt(opts) {
|
|
20
22
|
const { message, secret } = opts;
|
|
21
|
-
const { iv =
|
|
23
|
+
const { iv = Buffer.from(crypto.getRandomValues(new Uint8Array(DEFAULT_LENGTH))), inputEncoding = 'utf-8', outputEncoding = 'base64', doThrow = true, } = opts.opts ?? {};
|
|
22
24
|
try {
|
|
23
25
|
const secretKey = this.normalizeSecretKeyLegacy({
|
|
24
26
|
secret,
|
|
25
27
|
length: this.getAlgorithmKeySize(),
|
|
26
28
|
});
|
|
27
|
-
const
|
|
29
|
+
const { cipherText, authTag } = await AesEngine.seal({
|
|
30
|
+
algorithm: this.algorithm,
|
|
31
|
+
key: Buffer.from(secretKey),
|
|
32
|
+
iv,
|
|
33
|
+
plain: Buffer.from(message, inputEncoding),
|
|
34
|
+
});
|
|
28
35
|
const parts = [iv];
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
switch (this.algorithm) {
|
|
32
|
-
case 'aes-256-cbc': {
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
case 'aes-256-gcm': {
|
|
36
|
-
parts.push(cipher.getAuthTag());
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
36
|
+
if (authTag !== null) {
|
|
37
|
+
parts.push(authTag);
|
|
39
38
|
}
|
|
40
39
|
parts.push(cipherText);
|
|
41
|
-
parts.push(cipherFinal);
|
|
42
40
|
return Buffer.concat(parts).toString(outputEncoding);
|
|
43
41
|
}
|
|
44
42
|
catch (error) {
|
|
@@ -48,42 +46,39 @@ export class LegacyAES extends BaseCryptoAlgorithm {
|
|
|
48
46
|
return message;
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
|
-
encryptFile(opts) {
|
|
49
|
+
async encryptFile(opts) {
|
|
52
50
|
const { absolutePath, secret } = opts;
|
|
53
51
|
if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
|
|
54
52
|
return '';
|
|
55
53
|
}
|
|
56
54
|
const buffer = fs.readFileSync(absolutePath);
|
|
57
55
|
const fileContent = buffer?.toString('utf-8');
|
|
58
|
-
|
|
59
|
-
return encrypted;
|
|
56
|
+
return this.encrypt({ message: fileContent, secret });
|
|
60
57
|
}
|
|
61
|
-
decrypt(opts) {
|
|
58
|
+
async decrypt(opts) {
|
|
62
59
|
const { message, secret } = opts;
|
|
63
60
|
const { inputEncoding = 'base64', outputEncoding = 'utf-8', doThrow = true } = opts.opts ?? {};
|
|
64
61
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
Buffer.alloc(DEFAULT_LENGTH, 0);
|
|
62
|
+
const raw = Buffer.from(message, inputEncoding);
|
|
63
|
+
const iv = opts.opts?.iv ?? raw.subarray(0, DEFAULT_LENGTH);
|
|
68
64
|
let messageIndex = iv.length;
|
|
69
65
|
const secretKey = this.normalizeSecretKeyLegacy({
|
|
70
66
|
secret,
|
|
71
67
|
length: this.getAlgorithmKeySize(),
|
|
72
68
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
case 'aes-256-gcm': {
|
|
79
|
-
const authTag = Buffer.from(message, inputEncoding).subarray(iv.length, iv.length + DEFAULT_LENGTH);
|
|
80
|
-
messageIndex += authTag.length;
|
|
81
|
-
decipher.setAuthTag(authTag);
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
69
|
+
let authTag = null;
|
|
70
|
+
if (this.algorithm === AESAlgorithms.AES_256_GCM) {
|
|
71
|
+
authTag = raw.subarray(iv.length, iv.length + DEFAULT_LENGTH);
|
|
72
|
+
messageIndex += authTag.length;
|
|
84
73
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
74
|
+
const plain = await AesEngine.open({
|
|
75
|
+
algorithm: this.algorithm,
|
|
76
|
+
key: Buffer.from(secretKey),
|
|
77
|
+
iv,
|
|
78
|
+
cipherText: raw.subarray(messageIndex),
|
|
79
|
+
authTag,
|
|
80
|
+
});
|
|
81
|
+
return Buffer.from(plain).toString(outputEncoding);
|
|
87
82
|
}
|
|
88
83
|
catch (error) {
|
|
89
84
|
if (doThrow) {
|
|
@@ -92,15 +87,14 @@ export class LegacyAES extends BaseCryptoAlgorithm {
|
|
|
92
87
|
return message;
|
|
93
88
|
}
|
|
94
89
|
}
|
|
95
|
-
decryptFile(opts) {
|
|
90
|
+
async decryptFile(opts) {
|
|
96
91
|
const { absolutePath, secret } = opts;
|
|
97
92
|
if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
|
|
98
93
|
return '';
|
|
99
94
|
}
|
|
100
95
|
const buffer = fs.readFileSync(absolutePath);
|
|
101
96
|
const fileContent = buffer?.toString('utf-8');
|
|
102
|
-
|
|
103
|
-
return decrypted;
|
|
97
|
+
return this.decrypt({ message: fileContent, secret });
|
|
104
98
|
}
|
|
105
99
|
normalizeSecretKeyLegacy(opts) {
|
|
106
100
|
const { secret, length, padEnd = DEFAULT_PAD_END } = opts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes-legacy.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"aes-legacy.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,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ACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IAEO,wBAAwB,CAAC,IAAyD;QACxF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG,IAAI,CAAC;QAE1D,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport fs from 'node:fs';\nimport { DEFAULT_PAD_END } from '../common';\nimport { AESAlgorithms, type AESAlgorithmType } from './aes.constants';\nimport { AesEngine } from './aes.engine';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\n\ninterface IAESExtraOptions {\n iv?: Buffer;\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n}\n\n/**\n * Frozen back-compat format - keys come from `normalizeSecretKeyLegacy` (padEnd/truncate), never\n * PBKDF2. `kdfSalt`/`kdfIterations` are deliberately absent from `IAESExtraOptions`: there is no\n * salt to override, so the option would type-check and silently do nothing.\n * `encrypt` and `decrypt` are async: the cipher runs over `crypto.subtle`.\n */\nexport class LegacyAES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n string,\n Promise<string>,\n Promise<string>,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: LegacyAES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new LegacyAES({ algorithm });\n }\n\n async encrypt(opts: {\n message: string;\n secret: string;\n opts?: IAESExtraOptions;\n }): Promise<string> {\n const { message, secret } = opts;\n const {\n iv = Buffer.from(crypto.getRandomValues(new Uint8Array(DEFAULT_LENGTH))),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n } = opts.opts ?? {};\n\n try {\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n\n const { cipherText, authTag } = await AesEngine.seal({\n algorithm: this.algorithm,\n key: Buffer.from(secretKey),\n iv,\n plain: Buffer.from(message, inputEncoding),\n });\n\n const parts: Uint8Array[] = [iv];\n\n if (authTag !== null) {\n parts.push(authTag);\n }\n parts.push(cipherText);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n async encryptFile(opts: { absolutePath: string; secret: string }): Promise<string> {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n return this.encrypt({ message: fileContent, secret });\n }\n\n async decrypt(opts: {\n message: string;\n secret: string;\n opts?: IAESExtraOptions;\n }): Promise<string> {\n const { message, secret } = opts;\n const { inputEncoding = 'base64', outputEncoding = 'utf-8', doThrow = true } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n const iv = opts.opts?.iv ?? raw.subarray(0, DEFAULT_LENGTH);\n let messageIndex = iv.length;\n\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n\n let authTag: Uint8Array | null = null;\n if (this.algorithm === AESAlgorithms.AES_256_GCM) {\n authTag = raw.subarray(iv.length, iv.length + DEFAULT_LENGTH);\n messageIndex += authTag.length;\n }\n\n const plain = await AesEngine.open({\n algorithm: this.algorithm,\n key: Buffer.from(secretKey),\n iv,\n cipherText: raw.subarray(messageIndex),\n authTag,\n });\n return Buffer.from(plain).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n async decryptFile(opts: { absolutePath: string; secret: string }): Promise<string> {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n return this.decrypt({ message: fileContent, secret });\n }\n\n private normalizeSecretKeyLegacy(opts: { secret: string; length: number; padEnd?: string }) {\n const { secret, length, padEnd = DEFAULT_PAD_END } = opts;\n\n if (secret.length > length) {\n return secret.slice(0, length);\n }\n\n return secret.padEnd(length, padEnd);\n }\n}\n"]}
|
|
@@ -19,7 +19,8 @@ export interface IAESKeyringEntry {
|
|
|
19
19
|
}
|
|
20
20
|
export type TAESSecret = string | IAESKeyringEntry[];
|
|
21
21
|
export { AESAlgorithms, type AESAlgorithmType };
|
|
22
|
-
|
|
22
|
+
/** `encrypt` and `decrypt` are async: key derivation and the cipher run over `crypto.subtle`. */
|
|
23
|
+
export declare class AES extends BaseCryptoAlgorithm<AESAlgorithmType, string, string, TAESSecret, Promise<string>, Promise<string>, IAESExtraOptions> {
|
|
23
24
|
constructor(opts: {
|
|
24
25
|
algorithm: AESAlgorithmType;
|
|
25
26
|
});
|
|
@@ -28,33 +29,33 @@ export declare class AES extends BaseCryptoAlgorithm<AESAlgorithmType, string, s
|
|
|
28
29
|
secret: TAESSecret;
|
|
29
30
|
kdfSalt?: string;
|
|
30
31
|
kdfIterations?: number;
|
|
31
|
-
}): {
|
|
32
|
+
}): Promise<{
|
|
32
33
|
id: string;
|
|
33
34
|
key: Buffer;
|
|
34
|
-
}
|
|
35
|
+
}>;
|
|
35
36
|
protected resolveDecryptKey(opts: {
|
|
36
37
|
secret: TAESSecret;
|
|
37
38
|
id: string;
|
|
38
39
|
kdfSalt?: string;
|
|
39
40
|
kdfIterations?: number;
|
|
40
|
-
}): Buffer
|
|
41
|
+
}): Promise<Buffer>;
|
|
41
42
|
encrypt(opts: {
|
|
42
43
|
message: string;
|
|
43
44
|
secret: TAESSecret;
|
|
44
45
|
opts?: IAESExtraOptions;
|
|
45
|
-
}): string
|
|
46
|
+
}): Promise<string>;
|
|
46
47
|
encryptFile(opts: {
|
|
47
48
|
absolutePath: string;
|
|
48
49
|
secret: TAESSecret;
|
|
49
|
-
}): string
|
|
50
|
+
}): Promise<string>;
|
|
50
51
|
decrypt(opts: {
|
|
51
52
|
message: string;
|
|
52
53
|
secret: TAESSecret;
|
|
53
54
|
opts?: IAESDecryptOptions;
|
|
54
|
-
}): string
|
|
55
|
+
}): Promise<string>;
|
|
55
56
|
decryptFile(opts: {
|
|
56
57
|
absolutePath: string;
|
|
57
58
|
secret: TAESSecret;
|
|
58
|
-
}): string
|
|
59
|
+
}): Promise<string>;
|
|
59
60
|
}
|
|
60
61
|
//# sourceMappingURL=aes.algorithm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD,UAAU,kBAAkB;IAC1B,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8HAA8H;IAC9H,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0HAA0H;IAC1H,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sIAAsI;AACtI,UAAU,gBAAiB,SAAQ,kBAAkB;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEhD,qBAAa,GAAI,SAAQ,mBAAmB,CAC1C,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,UAAU,EACV,MAAM,
|
|
1
|
+
{"version":3,"file":"aes.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAKvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD,UAAU,kBAAkB;IAC1B,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8HAA8H;IAC9H,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0HAA0H;IAC1H,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,sIAAsI;AACtI,UAAU,gBAAiB,SAAQ,kBAAkB;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,gBAAgB,EAAE,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEhD,iGAAiG;AACjG,qBAAa,GAAI,SAAQ,mBAAmB,CAC1C,gBAAgB,EAChB,MAAM,EACN,MAAM,EACN,UAAU,EACV,OAAO,CAAC,MAAM,CAAC,EACf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gorithms } from './aes.constants.js';
|
|
2
2
|
import { ObjectUtility } from '@venizia/ignis-inversion';
|
|
3
|
-
import C from 'node:crypto';
|
|
4
3
|
import fs from 'node:fs';
|
|
5
4
|
import { getError } from '../../error/index.js';
|
|
5
|
+
import { AesEngine } from './aes.engine.js';
|
|
6
6
|
import { BaseCryptoAlgorithm } from './base.algorithm.js';
|
|
7
7
|
const DEFAULT_LENGTH = 16;
|
|
8
8
|
const CIPHERTEXT_VERSION = 0x01;
|
|
9
9
|
const DEFAULT_KEY_ID = '0';
|
|
10
10
|
export { AESAlgorithms };
|
|
11
|
+
/** `encrypt` and `decrypt` are async: key derivation and the cipher run over `crypto.subtle`. */
|
|
11
12
|
export class AES extends BaseCryptoAlgorithm {
|
|
12
13
|
constructor(opts) {
|
|
13
14
|
super({ scope: AES.name, ...opts });
|
|
@@ -15,13 +16,13 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
15
16
|
static withAlgorithm(algorithm) {
|
|
16
17
|
return new AES({ algorithm });
|
|
17
18
|
}
|
|
18
|
-
resolveEncryptKey(opts) {
|
|
19
|
+
async resolveEncryptKey(opts) {
|
|
19
20
|
const { secret, kdfSalt, kdfIterations } = opts;
|
|
20
21
|
const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };
|
|
21
22
|
if (!entry || ObjectUtility.isEmpty({ value: entry.secret })) {
|
|
22
23
|
throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });
|
|
23
24
|
}
|
|
24
|
-
const key = this.normalizeSecretKey({
|
|
25
|
+
const key = await this.normalizeSecretKey({
|
|
25
26
|
secret: entry.secret,
|
|
26
27
|
length: this.getAlgorithmKeySize(),
|
|
27
28
|
kdfSalt,
|
|
@@ -29,7 +30,7 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
29
30
|
});
|
|
30
31
|
return { id: entry.id, key };
|
|
31
32
|
}
|
|
32
|
-
resolveDecryptKey(opts) {
|
|
33
|
+
async resolveDecryptKey(opts) {
|
|
33
34
|
const { secret, id, kdfSalt, kdfIterations } = opts;
|
|
34
35
|
const length = this.getAlgorithmKeySize();
|
|
35
36
|
if (!Array.isArray(secret)) {
|
|
@@ -47,34 +48,41 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
47
48
|
message: `[AES][resolveDecryptKey] Keyring entry for key id "${id}" has an empty secret`,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
|
-
return this.normalizeSecretKey({
|
|
51
|
+
return this.normalizeSecretKey({
|
|
52
|
+
secret: entry.secret,
|
|
53
|
+
length,
|
|
54
|
+
kdfSalt,
|
|
55
|
+
kdfIterations,
|
|
56
|
+
});
|
|
51
57
|
}
|
|
52
|
-
encrypt(opts) {
|
|
58
|
+
async encrypt(opts) {
|
|
53
59
|
const { message, secret } = opts;
|
|
54
|
-
const { iv =
|
|
60
|
+
const { iv = Buffer.from(crypto.getRandomValues(new Uint8Array(DEFAULT_LENGTH))), inputEncoding = 'utf-8', outputEncoding = 'base64', doThrow = true, kdfSalt, kdfIterations, } = opts.opts ?? {};
|
|
55
61
|
try {
|
|
56
|
-
const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });
|
|
62
|
+
const { id, key } = await this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });
|
|
57
63
|
const idBuffer = Buffer.from(id, 'utf-8');
|
|
58
64
|
if (idBuffer.length > 0xff) {
|
|
59
65
|
throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });
|
|
60
66
|
}
|
|
61
|
-
|
|
67
|
+
// `decrypt` reads exactly DEFAULT_LENGTH bytes of IV from the envelope, so any other length would write a ciphertext nothing can read.
|
|
68
|
+
if (iv.length !== DEFAULT_LENGTH) {
|
|
69
|
+
throw getError({
|
|
70
|
+
message: `[AES][encrypt] The IV must be ${DEFAULT_LENGTH} bytes, got ${iv.length}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const { cipherText, authTag } = await AesEngine.seal({
|
|
74
|
+
algorithm: this.algorithm,
|
|
75
|
+
key,
|
|
76
|
+
iv,
|
|
77
|
+
plain: Buffer.from(message, inputEncoding),
|
|
78
|
+
});
|
|
62
79
|
// Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]
|
|
63
80
|
const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);
|
|
64
81
|
const parts = [header, idBuffer, iv];
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
switch (this.algorithm) {
|
|
68
|
-
case 'aes-256-cbc': {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
case 'aes-256-gcm': {
|
|
72
|
-
parts.push(cipher.getAuthTag());
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
82
|
+
if (authTag !== null) {
|
|
83
|
+
parts.push(authTag);
|
|
75
84
|
}
|
|
76
85
|
parts.push(cipherText);
|
|
77
|
-
parts.push(cipherFinal);
|
|
78
86
|
return Buffer.concat(parts).toString(outputEncoding);
|
|
79
87
|
}
|
|
80
88
|
catch (error) {
|
|
@@ -84,17 +92,16 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
84
92
|
return message;
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
|
-
encryptFile(opts) {
|
|
95
|
+
async encryptFile(opts) {
|
|
88
96
|
const { absolutePath, secret } = opts;
|
|
89
97
|
if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
|
|
90
98
|
return '';
|
|
91
99
|
}
|
|
92
100
|
const buffer = fs.readFileSync(absolutePath);
|
|
93
101
|
const fileContent = buffer?.toString('utf-8');
|
|
94
|
-
|
|
95
|
-
return encrypted;
|
|
102
|
+
return this.encrypt({ message: fileContent, secret });
|
|
96
103
|
}
|
|
97
|
-
decrypt(opts) {
|
|
104
|
+
async decrypt(opts) {
|
|
98
105
|
const { message, secret } = opts;
|
|
99
106
|
const { inputEncoding = 'base64', outputEncoding = 'utf-8', doThrow = true, kdfSalt, kdfIterations, } = opts.opts ?? {};
|
|
100
107
|
try {
|
|
@@ -109,21 +116,20 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
109
116
|
cursor += idLength;
|
|
110
117
|
const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);
|
|
111
118
|
cursor += DEFAULT_LENGTH;
|
|
112
|
-
const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
case 'aes-256-gcm': {
|
|
119
|
-
const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);
|
|
120
|
-
cursor += DEFAULT_LENGTH;
|
|
121
|
-
decipher.setAuthTag(authTag);
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
119
|
+
const key = await this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });
|
|
120
|
+
let authTag = null;
|
|
121
|
+
if (this.algorithm === AESAlgorithms.AES_256_GCM) {
|
|
122
|
+
authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);
|
|
123
|
+
cursor += DEFAULT_LENGTH;
|
|
124
124
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
125
|
+
const plain = await AesEngine.open({
|
|
126
|
+
algorithm: this.algorithm,
|
|
127
|
+
key,
|
|
128
|
+
iv,
|
|
129
|
+
cipherText: raw.subarray(cursor),
|
|
130
|
+
authTag,
|
|
131
|
+
});
|
|
132
|
+
return Buffer.from(plain).toString(outputEncoding);
|
|
127
133
|
}
|
|
128
134
|
catch (error) {
|
|
129
135
|
if (doThrow) {
|
|
@@ -132,15 +138,14 @@ export class AES extends BaseCryptoAlgorithm {
|
|
|
132
138
|
return message;
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
|
-
decryptFile(opts) {
|
|
141
|
+
async decryptFile(opts) {
|
|
136
142
|
const { absolutePath, secret } = opts;
|
|
137
143
|
if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
|
|
138
144
|
return '';
|
|
139
145
|
}
|
|
140
146
|
const buffer = fs.readFileSync(absolutePath);
|
|
141
147
|
const fileContent = buffer?.toString('utf-8');
|
|
142
|
-
|
|
143
|
-
return decrypted;
|
|
148
|
+
return this.decrypt({ message: fileContent, secret });
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
//# sourceMappingURL=aes.algorithm.js.map
|