@lindorm/aes 0.6.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +126 -231
- package/__tests__/esm-smoke.test.ts +2 -1
- package/__tests__/fixtures/keys.ts +4 -4
- package/__tests__/helpers/index.ts +2 -2
- package/__tests__/helpers/jwe-adapter.ts +2 -2
- package/__tests__/jose-jwe.test.ts +9 -8
- package/__tests__/noble-ciphers.test.ts +6 -5
- package/dist/classes/AesKit.d.ts +4 -4
- package/dist/classes/AesKit.d.ts.map +1 -1
- package/dist/classes/AesKit.js +29 -33
- package/dist/classes/AesKit.js.map +1 -1
- package/dist/classes/index.d.ts +1 -1
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +1 -17
- package/dist/classes/index.js.map +1 -1
- package/dist/errors/AesError.js +2 -6
- package/dist/errors/AesError.js.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -17
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -22
- package/dist/index.js.map +1 -1
- package/dist/interfaces/AesKit.d.ts +3 -3
- package/dist/interfaces/AesKit.d.ts.map +1 -1
- package/dist/interfaces/AesKit.js +1 -2
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js +1 -17
- package/dist/interfaces/index.js.map +1 -1
- package/dist/internal/constants/version.js +3 -6
- package/dist/internal/constants/version.js.map +1 -1
- package/dist/internal/types/aes-data.d.ts +4 -4
- package/dist/internal/types/aes-data.d.ts.map +1 -1
- package/dist/internal/types/aes-data.js +1 -2
- package/dist/internal/types/aes-key-derivation.js +1 -2
- package/dist/internal/types/auth-tag.d.ts +2 -2
- package/dist/internal/types/auth-tag.d.ts.map +1 -1
- package/dist/internal/types/auth-tag.js +1 -2
- package/dist/internal/types/auth-tag.js.map +1 -1
- package/dist/internal/types/content-encryption-key.d.ts +2 -2
- package/dist/internal/types/content-encryption-key.d.ts.map +1 -1
- package/dist/internal/types/content-encryption-key.js +1 -2
- package/dist/internal/types/key-wrap.d.ts +1 -1
- package/dist/internal/types/key-wrap.d.ts.map +1 -1
- package/dist/internal/types/key-wrap.js +1 -2
- package/dist/internal/types/prepared-encryption.d.ts +3 -3
- package/dist/internal/types/prepared-encryption.d.ts.map +1 -1
- package/dist/internal/types/prepared-encryption.js +1 -2
- package/dist/internal/utils/aes-header.d.ts +3 -3
- package/dist/internal/utils/aes-header.d.ts.map +1 -1
- package/dist/internal/utils/aes-header.js +22 -30
- package/dist/internal/utils/aes-header.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-aes-encryption.d.ts +2 -2
- package/dist/internal/utils/calculate/calculate-aes-encryption.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-aes-encryption.js +4 -8
- package/dist/internal/utils/calculate/calculate-aes-encryption.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-content-encryption-key-size.d.ts +2 -2
- package/dist/internal/utils/calculate/calculate-content-encryption-key-size.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-content-encryption-key-size.js +4 -8
- package/dist/internal/utils/calculate/calculate-content-encryption-key-size.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-key-wrap-encryption.d.ts +1 -1
- package/dist/internal/utils/calculate/calculate-key-wrap-encryption.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-key-wrap-encryption.js +3 -7
- package/dist/internal/utils/calculate/calculate-key-wrap-encryption.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-key-wrap-size.d.ts +2 -2
- package/dist/internal/utils/calculate/calculate-key-wrap-size.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-key-wrap-size.js +3 -7
- package/dist/internal/utils/calculate/calculate-key-wrap-size.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-pbkdf-hash.d.ts +2 -2
- package/dist/internal/utils/calculate/calculate-pbkdf-hash.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-pbkdf-hash.js +3 -7
- package/dist/internal/utils/calculate/calculate-pbkdf-hash.js.map +1 -1
- package/dist/internal/utils/calculate/calculate-rsa-oaep-hash.d.ts +2 -2
- package/dist/internal/utils/calculate/calculate-rsa-oaep-hash.d.ts.map +1 -1
- package/dist/internal/utils/calculate/calculate-rsa-oaep-hash.js +3 -7
- package/dist/internal/utils/calculate/calculate-rsa-oaep-hash.js.map +1 -1
- package/dist/internal/utils/content.d.ts +1 -1
- package/dist/internal/utils/content.d.ts.map +1 -1
- package/dist/internal/utils/content.js +11 -17
- package/dist/internal/utils/content.js.map +1 -1
- package/dist/internal/utils/data/auth-tag-hmac.d.ts +1 -1
- package/dist/internal/utils/data/auth-tag-hmac.d.ts.map +1 -1
- package/dist/internal/utils/data/auth-tag-hmac.js +9 -14
- package/dist/internal/utils/data/auth-tag-hmac.js.map +1 -1
- package/dist/internal/utils/data/auth-tag.d.ts +1 -1
- package/dist/internal/utils/data/auth-tag.d.ts.map +1 -1
- package/dist/internal/utils/data/auth-tag.js +9 -14
- package/dist/internal/utils/data/auth-tag.js.map +1 -1
- package/dist/internal/utils/data/get-initialisation-vector.d.ts +1 -1
- package/dist/internal/utils/data/get-initialisation-vector.d.ts.map +1 -1
- package/dist/internal/utils/data/get-initialisation-vector.js +6 -10
- package/dist/internal/utils/data/get-initialisation-vector.js.map +1 -1
- package/dist/internal/utils/data/split-content-encryption-key.d.ts +1 -1
- package/dist/internal/utils/data/split-content-encryption-key.d.ts.map +1 -1
- package/dist/internal/utils/data/split-content-encryption-key.js +4 -8
- package/dist/internal/utils/data/split-content-encryption-key.js.map +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman-key-wrap.d.ts +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman-key-wrap.d.ts.map +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman-key-wrap.js +20 -25
- package/dist/internal/utils/diffie-hellman/diffie-hellman-key-wrap.js.map +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman.d.ts +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman.d.ts.map +1 -1
- package/dist/internal/utils/diffie-hellman/diffie-hellman.js +16 -21
- package/dist/internal/utils/diffie-hellman/diffie-hellman.js.map +1 -1
- package/dist/internal/utils/diffie-hellman/shared-secret.d.ts +3 -3
- package/dist/internal/utils/diffie-hellman/shared-secret.d.ts.map +1 -1
- package/dist/internal/utils/diffie-hellman/shared-secret.js +22 -27
- package/dist/internal/utils/diffie-hellman/shared-secret.js.map +1 -1
- package/dist/internal/utils/encoded-aes.d.ts +2 -2
- package/dist/internal/utils/encoded-aes.d.ts.map +1 -1
- package/dist/internal/utils/encoded-aes.js +18 -23
- package/dist/internal/utils/encoded-aes.js.map +1 -1
- package/dist/internal/utils/encrypt-content.d.ts +1 -1
- package/dist/internal/utils/encrypt-content.d.ts.map +1 -1
- package/dist/internal/utils/encrypt-content.js +14 -18
- package/dist/internal/utils/encrypt-content.js.map +1 -1
- package/dist/internal/utils/encrypt-encoded.d.ts +2 -2
- package/dist/internal/utils/encrypt-encoded.d.ts.map +1 -1
- package/dist/internal/utils/encrypt-encoded.js +15 -19
- package/dist/internal/utils/encrypt-encoded.js.map +1 -1
- package/dist/internal/utils/encrypt-serialised.d.ts +3 -3
- package/dist/internal/utils/encrypt-serialised.d.ts.map +1 -1
- package/dist/internal/utils/encrypt-serialised.js +20 -24
- package/dist/internal/utils/encrypt-serialised.js.map +1 -1
- package/dist/internal/utils/encrypt-tokenised.d.ts +2 -2
- package/dist/internal/utils/encrypt-tokenised.d.ts.map +1 -1
- package/dist/internal/utils/encrypt-tokenised.js +18 -22
- package/dist/internal/utils/encrypt-tokenised.js.map +1 -1
- package/dist/internal/utils/encryption.d.ts +3 -3
- package/dist/internal/utils/encryption.d.ts.map +1 -1
- package/dist/internal/utils/encryption.js +22 -27
- package/dist/internal/utils/encryption.js.map +1 -1
- package/dist/internal/utils/get-key/get-decryption-key.d.ts +1 -1
- package/dist/internal/utils/get-key/get-decryption-key.d.ts.map +1 -1
- package/dist/internal/utils/get-key/get-decryption-key.js +11 -15
- package/dist/internal/utils/get-key/get-decryption-key.js.map +1 -1
- package/dist/internal/utils/get-key/get-encryption-key.d.ts +1 -1
- package/dist/internal/utils/get-key/get-encryption-key.d.ts.map +1 -1
- package/dist/internal/utils/get-key/get-encryption-key.js +11 -15
- package/dist/internal/utils/get-key/get-encryption-key.js.map +1 -1
- package/dist/internal/utils/key-derivation/concat-kdf.d.ts +1 -1
- package/dist/internal/utils/key-derivation/concat-kdf.d.ts.map +1 -1
- package/dist/internal/utils/key-derivation/concat-kdf.js +3 -7
- package/dist/internal/utils/key-derivation/concat-kdf.js.map +1 -1
- package/dist/internal/utils/key-derivation/pbkdf.d.ts +1 -1
- package/dist/internal/utils/key-derivation/pbkdf.d.ts.map +1 -1
- package/dist/internal/utils/key-derivation/pbkdf.js +7 -11
- package/dist/internal/utils/key-derivation/pbkdf.js.map +1 -1
- package/dist/internal/utils/key-types/get-ec-keys.d.ts +1 -1
- package/dist/internal/utils/key-types/get-ec-keys.d.ts.map +1 -1
- package/dist/internal/utils/key-types/get-ec-keys.js +11 -16
- package/dist/internal/utils/key-types/get-ec-keys.js.map +1 -1
- package/dist/internal/utils/key-types/get-oct-keys.d.ts +1 -1
- package/dist/internal/utils/key-types/get-oct-keys.d.ts.map +1 -1
- package/dist/internal/utils/key-types/get-oct-keys.js +14 -19
- package/dist/internal/utils/key-types/get-oct-keys.js.map +1 -1
- package/dist/internal/utils/key-types/get-okp-keys.d.ts +1 -1
- package/dist/internal/utils/key-types/get-okp-keys.d.ts.map +1 -1
- package/dist/internal/utils/key-types/get-okp-keys.js +11 -16
- package/dist/internal/utils/key-types/get-okp-keys.js.map +1 -1
- package/dist/internal/utils/key-types/get-rsa-keys.d.ts +1 -1
- package/dist/internal/utils/key-types/get-rsa-keys.d.ts.map +1 -1
- package/dist/internal/utils/key-types/get-rsa-keys.js +24 -29
- package/dist/internal/utils/key-types/get-rsa-keys.js.map +1 -1
- package/dist/internal/utils/key-wrap/ecb-key-wrap.d.ts +1 -1
- package/dist/internal/utils/key-wrap/ecb-key-wrap.d.ts.map +1 -1
- package/dist/internal/utils/key-wrap/ecb-key-wrap.js +12 -17
- package/dist/internal/utils/key-wrap/ecb-key-wrap.js.map +1 -1
- package/dist/internal/utils/key-wrap/gcm-key-wrap.d.ts +1 -1
- package/dist/internal/utils/key-wrap/gcm-key-wrap.d.ts.map +1 -1
- package/dist/internal/utils/key-wrap/gcm-key-wrap.js +14 -19
- package/dist/internal/utils/key-wrap/gcm-key-wrap.js.map +1 -1
- package/dist/internal/utils/key-wrap/key-wrap.d.ts +1 -1
- package/dist/internal/utils/key-wrap/key-wrap.d.ts.map +1 -1
- package/dist/internal/utils/key-wrap/key-wrap.js +11 -16
- package/dist/internal/utils/key-wrap/key-wrap.js.map +1 -1
- package/dist/internal/utils/oct/get-oct-dir-keys.d.ts +1 -1
- package/dist/internal/utils/oct/get-oct-dir-keys.d.ts.map +1 -1
- package/dist/internal/utils/oct/get-oct-dir-keys.js +13 -18
- package/dist/internal/utils/oct/get-oct-dir-keys.js.map +1 -1
- package/dist/internal/utils/oct/get-oct-key-key-wrap.d.ts +1 -1
- package/dist/internal/utils/oct/get-oct-key-key-wrap.d.ts.map +1 -1
- package/dist/internal/utils/oct/get-oct-key-key-wrap.js +19 -24
- package/dist/internal/utils/oct/get-oct-key-key-wrap.js.map +1 -1
- package/dist/internal/utils/oct/get-oct-pbkdf-key-wrap-keys.d.ts +1 -1
- package/dist/internal/utils/oct/get-oct-pbkdf-key-wrap-keys.d.ts.map +1 -1
- package/dist/internal/utils/oct/get-oct-pbkdf-key-wrap-keys.js +25 -30
- package/dist/internal/utils/oct/get-oct-pbkdf-key-wrap-keys.js.map +1 -1
- package/dist/internal/utils/prepare-encryption.d.ts +1 -1
- package/dist/internal/utils/prepare-encryption.d.ts.map +1 -1
- package/dist/internal/utils/prepare-encryption.js +5 -9
- package/dist/internal/utils/prepare-encryption.js.map +1 -1
- package/dist/internal/utils/serialised-aes.d.ts +2 -2
- package/dist/internal/utils/serialised-aes.d.ts.map +1 -1
- package/dist/internal/utils/serialised-aes.js +19 -24
- package/dist/internal/utils/serialised-aes.js.map +1 -1
- package/dist/internal/utils/tokenised-aes.d.ts +2 -2
- package/dist/internal/utils/tokenised-aes.d.ts.map +1 -1
- package/dist/internal/utils/tokenised-aes.js +22 -27
- package/dist/internal/utils/tokenised-aes.js.map +1 -1
- package/dist/internal/utils/validate-version.js +8 -12
- package/dist/internal/utils/validate-version.js.map +1 -1
- package/dist/mocks/create-mock-aes-kit.d.ts +4 -0
- package/dist/mocks/create-mock-aes-kit.d.ts.map +1 -0
- package/dist/mocks/create-mock-aes-kit.js +81 -0
- package/dist/mocks/create-mock-aes-kit.js.map +1 -0
- package/dist/mocks/jest.d.ts +5 -0
- package/dist/mocks/jest.d.ts.map +1 -0
- package/dist/mocks/jest.js +4 -0
- package/dist/mocks/jest.js.map +1 -0
- package/dist/mocks/vitest.d.ts +6 -0
- package/dist/mocks/vitest.d.ts.map +1 -0
- package/dist/mocks/vitest.js +5 -0
- package/dist/mocks/vitest.js.map +1 -0
- package/dist/types/aes-decryption-data.d.ts +3 -3
- package/dist/types/aes-decryption-data.d.ts.map +1 -1
- package/dist/types/aes-decryption-data.js +1 -2
- package/dist/types/aes-encryption-data.d.ts +3 -3
- package/dist/types/aes-encryption-data.d.ts.map +1 -1
- package/dist/types/aes-encryption-data.js +1 -2
- package/dist/types/aes-kit.d.ts +1 -1
- package/dist/types/aes-kit.d.ts.map +1 -1
- package/dist/types/aes-kit.js +1 -2
- package/dist/types/content.d.ts +1 -1
- package/dist/types/content.d.ts.map +1 -1
- package/dist/types/content.js +1 -2
- package/dist/types/curve.js +1 -2
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -22
- package/dist/types/index.js.map +1 -1
- package/dist/types/types.d.ts +1 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +1 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -18
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-aes.d.ts +1 -1
- package/dist/utils/is-aes.d.ts.map +1 -1
- package/dist/utils/is-aes.js +4 -10
- package/dist/utils/is-aes.js.map +1 -1
- package/dist/utils/parse-aes.d.ts +1 -1
- package/dist/utils/parse-aes.d.ts.map +1 -1
- package/dist/utils/parse-aes.js +15 -19
- package/dist/utils/parse-aes.js.map +1 -1
- package/package.json +19 -26
- package/vitest.config.mjs +6 -0
- package/dist/mocks/index.d.ts +0 -2
- package/dist/mocks/index.d.ts.map +0 -1
- package/dist/mocks/index.js +0 -6
- package/dist/mocks/index.js.map +0 -1
- package/dist/mocks/mock-aes-kit.d.ts +0 -4
- package/dist/mocks/mock-aes-kit.d.ts.map +0 -1
- package/dist/mocks/mock-aes-kit.js +0 -74
- package/dist/mocks/mock-aes-kit.js.map +0 -1
- package/jest.config.interop.mjs +0 -24
- package/tsconfig.interop.json +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.7.0](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.6.5...@lindorm/aes@0.7.0) (2026-05-02)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **aes:** mark type-only imports in **tests** ([23ade84](https://github.com/lindorm-io/monorepo/commit/23ade8444b945be2eed225f1c8587b60a32d530a))
|
|
11
|
+
- **aes:** use IKryptos interface for fixture helper return type ([42d1a28](https://github.com/lindorm-io/monorepo/commit/42d1a287d69977b6f2f39782910a5d45dffdbfdb))
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- migrate 20 packages from jest to vitest ([d8bfda8](https://github.com/lindorm-io/monorepo/commit/d8bfda8854dc1cb9537ba0b3e47ec4e4c7bded08))
|
|
16
|
+
|
|
17
|
+
## [0.6.5](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.6.4...@lindorm/aes@0.6.5) (2026-04-19)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @lindorm/aes
|
|
20
|
+
|
|
6
21
|
## [0.6.4](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.6.3...@lindorm/aes@0.6.4) (2026-04-15)
|
|
7
22
|
|
|
8
23
|
**Note:** Version bump only for package @lindorm/aes
|
package/README.md
CHANGED
|
@@ -1,43 +1,32 @@
|
|
|
1
1
|
# @lindorm/aes
|
|
2
2
|
|
|
3
|
-
High-level
|
|
4
|
-
TypeScript support. `@lindorm/aes` wraps key derivation, key wrapping, and
|
|
5
|
-
authenticated content encryption behind a single `AesKit` class — so you can
|
|
6
|
-
encrypt any data type in one call and get back a string, a structured record, or
|
|
7
|
-
a compact token.
|
|
3
|
+
High-level AES encryption and decryption for Node.js with first-class TypeScript support. `@lindorm/aes` wraps key derivation, key wrapping, and authenticated content encryption behind a single `AesKit` class — encrypt any supported value in one call and get back a string, a structured record, or a compact token.
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
## Features
|
|
10
6
|
|
|
11
|
-
- `AesKit` — encrypt / decrypt / verify / assert in four output formats
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
- Automatic content-type detection
|
|
15
|
-
- Unified header model with
|
|
16
|
-
- Static helpers for format detection and parsing
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
- `AesKit` — `encrypt` / `decrypt` / `verify` / `assert` in four output formats: `encoded`, `record`, `serialised`, `tokenised`
|
|
8
|
+
- Content encryption with `A128GCM`, `A192GCM`, `A256GCM`, `A128CBC-HS256`, `A192CBC-HS384`, `A256CBC-HS512`
|
|
9
|
+
- Key management for the ECDH-ES family, RSA-OAEP family, AES-KW, AES-GCM-KW, PBES2, and `dir`
|
|
10
|
+
- Automatic content-type detection for strings, `Buffer`, objects, arrays, numbers, and booleans — original type is preserved on decrypt
|
|
11
|
+
- Unified header model with format-derived AAD across the string and serialised formats
|
|
12
|
+
- Static helpers for content-type detection, format detection, and parsing
|
|
13
|
+
- Two-step `prepareEncryption()` flow for advanced JWE-style encryption
|
|
14
|
+
- ESM-only
|
|
19
15
|
|
|
20
16
|
## Installation
|
|
21
17
|
|
|
22
18
|
```bash
|
|
23
19
|
npm install @lindorm/aes
|
|
24
|
-
# or
|
|
25
|
-
yarn add @lindorm/aes
|
|
26
20
|
```
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
---
|
|
22
|
+
This package is ESM-only and is published as `"type": "module"`. All examples use `import`.
|
|
31
23
|
|
|
32
24
|
## Quick start
|
|
33
25
|
|
|
34
|
-
### Encrypt and decrypt
|
|
35
|
-
|
|
36
26
|
```ts
|
|
37
27
|
import { AesKit } from "@lindorm/aes";
|
|
38
28
|
import { KryptosKit } from "@lindorm/kryptos";
|
|
39
29
|
|
|
40
|
-
// Generate an encryption key — Kryptos defaults to A256GCM content encryption
|
|
41
30
|
const kryptos = KryptosKit.generate.enc.oct({ algorithm: "A256KW" });
|
|
42
31
|
const aes = new AesKit({ kryptos });
|
|
43
32
|
|
|
@@ -45,34 +34,27 @@ const encrypted = aes.encrypt("Hello World"); // base64url string
|
|
|
45
34
|
const decrypted = aes.decrypt(encrypted); // "Hello World"
|
|
46
35
|
```
|
|
47
36
|
|
|
48
|
-
###
|
|
37
|
+
### Output formats
|
|
49
38
|
|
|
50
|
-
|
|
51
|
-
// Encoded — single base64url string (default)
|
|
52
|
-
const encoded = aes.encrypt("secret");
|
|
39
|
+
`encrypt` returns a different shape depending on the `mode` argument:
|
|
53
40
|
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
const json = JSON.stringify(serialised);
|
|
60
|
-
|
|
61
|
-
// Tokenised — human-readable $-delimited string
|
|
62
|
-
const token = aes.encrypt("secret", "tokenised");
|
|
63
|
-
// "aes:<base64url(header)>$<iv>$<tag>$<ciphertext>"
|
|
41
|
+
```ts
|
|
42
|
+
const encoded = aes.encrypt("secret"); // string (default: "encoded")
|
|
43
|
+
const record = aes.encrypt("secret", "record"); // AesEncryptionRecord
|
|
44
|
+
const serialised = aes.encrypt("secret", "serialised"); // SerialisedAesEncryption
|
|
45
|
+
const tokenised = aes.encrypt("secret", "tokenised"); // "aes:<header>$..."
|
|
64
46
|
```
|
|
65
47
|
|
|
66
48
|
All four formats are accepted by `decrypt`, `verify`, and `assert`:
|
|
67
49
|
|
|
68
50
|
```ts
|
|
69
|
-
aes.decrypt(encoded);
|
|
70
|
-
aes.decrypt(record);
|
|
71
|
-
aes.decrypt(
|
|
72
|
-
aes.decrypt(
|
|
51
|
+
aes.decrypt(encoded);
|
|
52
|
+
aes.decrypt(record);
|
|
53
|
+
aes.decrypt(serialised);
|
|
54
|
+
aes.decrypt(tokenised);
|
|
73
55
|
```
|
|
74
56
|
|
|
75
|
-
### Encrypt any content
|
|
57
|
+
### Encrypt any supported content
|
|
76
58
|
|
|
77
59
|
```ts
|
|
78
60
|
aes.encrypt("plain text"); // string
|
|
@@ -80,9 +62,9 @@ aes.encrypt(Buffer.from("binary")); // Buffer
|
|
|
80
62
|
aes.encrypt({ user: "alice", role: "admin" }); // object
|
|
81
63
|
aes.encrypt([1, 2, 3]); // array
|
|
82
64
|
aes.encrypt(42); // number
|
|
65
|
+
aes.encrypt(true); // boolean
|
|
83
66
|
|
|
84
|
-
|
|
85
|
-
const obj = aes.decrypt<{ user: string }>(cipher); // { user: "alice", ... }
|
|
67
|
+
const obj = aes.decrypt<{ user: string }>(cipher); // typed return
|
|
86
68
|
```
|
|
87
69
|
|
|
88
70
|
### Verify and assert
|
|
@@ -91,7 +73,7 @@ const obj = aes.decrypt<{ user: string }>(cipher); // { user: "alice", ... }
|
|
|
91
73
|
const cipher = aes.encrypt("secret");
|
|
92
74
|
|
|
93
75
|
aes.verify("secret", cipher); // true
|
|
94
|
-
aes.verify("wrong", cipher); // false
|
|
76
|
+
aes.verify("wrong", cipher); // false — never throws
|
|
95
77
|
|
|
96
78
|
aes.assert("secret", cipher); // void — passes silently
|
|
97
79
|
aes.assert("wrong", cipher); // throws AesError("Invalid AES cipher")
|
|
@@ -99,92 +81,47 @@ aes.assert("wrong", cipher); // throws AesError("Invalid AES cipher")
|
|
|
99
81
|
|
|
100
82
|
### Additional Authenticated Data (AAD)
|
|
101
83
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
84
|
+
The `encoded`, `serialised`, and `tokenised` formats automatically derive AAD from their base64url-encoded header — metadata integrity is bound to the ciphertext for free.
|
|
85
|
+
|
|
86
|
+
For raw `record`-mode payloads with no header, you can supply AAD on decrypt through `options.aad`:
|
|
105
87
|
|
|
106
88
|
```ts
|
|
89
|
+
const record = aes.encrypt("payload", "record");
|
|
107
90
|
const aad = Buffer.from("request-id:abc-123");
|
|
108
91
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
aes.decrypt(cipher, { aad }); // "payload"
|
|
112
|
-
aes.decrypt(cipher); // throws — AAD mismatch
|
|
113
|
-
aes.decrypt(cipher, { aad: Buffer.from("wrong") }); // throws
|
|
92
|
+
aes.decrypt({ ...record, aad }); // pass AAD through the record
|
|
93
|
+
aes.decrypt(record, { aad }); // or via the options argument
|
|
114
94
|
```
|
|
115
95
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
## Supported algorithms
|
|
119
|
-
|
|
120
|
-
### Content encryption
|
|
121
|
-
|
|
122
|
-
| Encryption | Mode | Key bits | Auth |
|
|
123
|
-
| --------------- | ---- | -------- | --------------------------- |
|
|
124
|
-
| `A128GCM` | GCM | 128 | built-in auth tag |
|
|
125
|
-
| `A192GCM` | GCM | 192 | built-in auth tag |
|
|
126
|
-
| `A256GCM` | GCM | 256 | built-in auth tag (default) |
|
|
127
|
-
| `A128CBC-HS256` | CBC | 128 | HMAC-SHA256 |
|
|
128
|
-
| `A192CBC-HS384` | CBC | 192 | HMAC-SHA384 |
|
|
129
|
-
| `A256CBC-HS512` | CBC | 256 | HMAC-SHA512 |
|
|
130
|
-
|
|
131
|
-
### Key algorithms
|
|
132
|
-
|
|
133
|
-
| Key type | Algorithms |
|
|
134
|
-
| --------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
135
|
-
| EC | `ECDH-ES`, `ECDH-ES+A128KW`, `ECDH-ES+A192KW`, `ECDH-ES+A256KW`, `ECDH-ES+A128GCMKW`, `ECDH-ES+A192GCMKW`, `ECDH-ES+A256GCMKW` |
|
|
136
|
-
| OKP | `ECDH-ES`, `ECDH-ES+A128KW`, `ECDH-ES+A192KW`, `ECDH-ES+A256KW`, `ECDH-ES+A128GCMKW`, `ECDH-ES+A192GCMKW`, `ECDH-ES+A256GCMKW` |
|
|
137
|
-
| RSA | `RSA-OAEP-256`, `RSA-OAEP-384`, `RSA-OAEP-512` |
|
|
138
|
-
| oct (symmetric) | `A128KW`, `A192KW`, `A256KW`, `A128GCMKW`, `A192GCMKW`, `A256GCMKW`, `dir` |
|
|
139
|
-
| oct (password) | `PBES2-HS256+A128KW`, `PBES2-HS384+A192KW`, `PBES2-HS512+A256KW` |
|
|
140
|
-
|
|
141
|
-
Every key algorithm can be combined with every content encryption — giving you
|
|
142
|
-
28+ working combinations.
|
|
143
|
-
|
|
144
|
-
---
|
|
96
|
+
To encrypt with caller-controlled AAD use the two-step `prepareEncryption()` flow described in the API reference.
|
|
145
97
|
|
|
146
98
|
## API reference
|
|
147
99
|
|
|
148
100
|
### `new AesKit(options)`
|
|
149
101
|
|
|
150
102
|
```ts
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const aes = new AesKit({ kryptos });
|
|
154
|
-
|
|
155
|
-
aes.kryptos; // the IKryptos instance (public readonly)
|
|
103
|
+
new AesKit({ kryptos, encryption });
|
|
156
104
|
```
|
|
157
105
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
106
|
+
| Option | Type | Description |
|
|
107
|
+
| ------------ | -------------------- | --------------------------------------------------------------------------------- |
|
|
108
|
+
| `kryptos` | `IKryptos` | Required. The `@lindorm/kryptos` key instance used for key derivation / wrapping. |
|
|
109
|
+
| `encryption` | `KryptosEncryption?` | Optional. Falls back to `kryptos.encryption`, then to `"A256GCM"`. |
|
|
161
110
|
|
|
162
|
-
|
|
163
|
-
const imported = KryptosKit.from.jwk(externalJwk);
|
|
164
|
-
const aes = new AesKit({ kryptos: imported, encryption: "A128GCM" });
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
### `aes.encrypt(data, mode?, options?)`
|
|
111
|
+
`aes.kryptos` is exposed as a public readonly property.
|
|
168
112
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
| Mode | Return type | Description |
|
|
172
|
-
| --------------------- | ------------------------- | ----------------------------------------- |
|
|
173
|
-
| `"encoded"` (default) | `string` | Base64url-encoded binary blob |
|
|
174
|
-
| `"record"` | `AesEncryptionRecord` | Object with raw `Buffer` values |
|
|
175
|
-
| `"serialised"` | `SerialisedAesEncryption` | Object with base64url strings (JSON-safe) |
|
|
176
|
-
| `"tokenised"` | `string` | `$`-delimited human-readable token |
|
|
113
|
+
### `aes.encrypt(data, mode?)`
|
|
177
114
|
|
|
178
115
|
```ts
|
|
179
|
-
encrypt(data: AesContent, mode?: "encoded"
|
|
180
|
-
encrypt(data: AesContent, mode: "record"
|
|
181
|
-
encrypt(data: AesContent, mode: "serialised"
|
|
182
|
-
encrypt(data: AesContent, mode: "tokenised"
|
|
116
|
+
encrypt(data: AesContent, mode?: "encoded"): string;
|
|
117
|
+
encrypt(data: AesContent, mode: "record"): AesEncryptionRecord;
|
|
118
|
+
encrypt(data: AesContent, mode: "serialised"): SerialisedAesEncryption;
|
|
119
|
+
encrypt(data: AesContent, mode: "tokenised"): string;
|
|
183
120
|
```
|
|
184
121
|
|
|
185
|
-
|
|
122
|
+
Encrypts and returns one of four shapes. `mode` defaults to `"encoded"`.
|
|
186
123
|
|
|
187
|
-
|
|
124
|
+
### `aes.decrypt<T>(data, options?)`
|
|
188
125
|
|
|
189
126
|
```ts
|
|
190
127
|
decrypt<T extends AesContent = string>(
|
|
@@ -193,14 +130,10 @@ decrypt<T extends AesContent = string>(
|
|
|
193
130
|
): T;
|
|
194
131
|
```
|
|
195
132
|
|
|
196
|
-
|
|
197
|
-
serialised object all work transparently.
|
|
133
|
+
Auto-detects the input format. AAD is taken from the parsed input when present and otherwise from `options.aad`.
|
|
198
134
|
|
|
199
135
|
### `aes.verify(input, data, options?)`
|
|
200
136
|
|
|
201
|
-
Returns `true` if decrypted data deeply equals `input`, `false` otherwise.
|
|
202
|
-
Never throws.
|
|
203
|
-
|
|
204
137
|
```ts
|
|
205
138
|
verify(
|
|
206
139
|
input: AesContent,
|
|
@@ -209,10 +142,9 @@ verify(
|
|
|
209
142
|
): boolean;
|
|
210
143
|
```
|
|
211
144
|
|
|
212
|
-
|
|
145
|
+
Returns `true` if the decrypted payload deeply equals `input`, `false` otherwise. Never throws.
|
|
213
146
|
|
|
214
|
-
|
|
215
|
-
`input`.
|
|
147
|
+
### `aes.assert(input, data, options?)`
|
|
216
148
|
|
|
217
149
|
```ts
|
|
218
150
|
assert(
|
|
@@ -222,45 +154,57 @@ assert(
|
|
|
222
154
|
): void;
|
|
223
155
|
```
|
|
224
156
|
|
|
157
|
+
Throws `AesError("Invalid AES cipher")` when the decrypted payload does not match `input`.
|
|
158
|
+
|
|
225
159
|
### `aes.prepareEncryption()`
|
|
226
160
|
|
|
227
|
-
Two-step
|
|
228
|
-
`encrypt()` closure that can be called later with the plaintext.
|
|
161
|
+
Two-step encryption flow that splits key management from content encryption. Returns header parameters, the wrapped CEK (when applicable), and an `encrypt` closure that accepts plaintext (and optional `aad`).
|
|
229
162
|
|
|
230
163
|
```ts
|
|
231
164
|
const prepared = aes.prepareEncryption();
|
|
232
165
|
|
|
233
|
-
|
|
234
|
-
//
|
|
235
|
-
|
|
166
|
+
const result = prepared.encrypt("payload", { aad: Buffer.from("ctx") });
|
|
167
|
+
// result: { authTag, content, contentType, initialisationVector }
|
|
168
|
+
|
|
169
|
+
// prepared.headerParams: { publicEncryptionJwk?, pbkdfIterations?, pbkdfSalt?,
|
|
170
|
+
// publicEncryptionIv?, publicEncryptionTag? }
|
|
171
|
+
// prepared.publicEncryptionKey: Buffer | undefined
|
|
236
172
|
```
|
|
237
173
|
|
|
238
174
|
### Static methods
|
|
239
175
|
|
|
240
176
|
```ts
|
|
241
|
-
// Detect content type of any input
|
|
242
177
|
AesKit.contentType("hello"); // "text/plain"
|
|
243
|
-
AesKit.contentType(Buffer.from("")); // "application/octet-stream"
|
|
178
|
+
AesKit.contentType(Buffer.from("data")); // "application/octet-stream"
|
|
244
179
|
AesKit.contentType({ a: 1 }); // "application/json"
|
|
245
180
|
|
|
246
|
-
//
|
|
247
|
-
AesKit.isAesTokenised("aes:eyJhbGci...$...$...$..."); // true
|
|
181
|
+
AesKit.isAesTokenised("aes:..."); // true
|
|
248
182
|
AesKit.isAesTokenised("base64string"); // false
|
|
249
183
|
|
|
250
|
-
//
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const record3 = AesKit.parse(serialisedObject);
|
|
184
|
+
AesKit.parse(encodedString); // ParsedAesDecryptionRecord
|
|
185
|
+
AesKit.parse(serialisedObject); // ParsedAesDecryptionRecord
|
|
186
|
+
AesKit.parse(decryptionRecord); // AesDecryptionRecord (returned as-is)
|
|
254
187
|
```
|
|
255
188
|
|
|
256
|
-
|
|
189
|
+
### Top-level utilities
|
|
257
190
|
|
|
258
|
-
|
|
191
|
+
```ts
|
|
192
|
+
import {
|
|
193
|
+
isAesBufferData,
|
|
194
|
+
isAesSerialisedData,
|
|
195
|
+
isAesTokenised,
|
|
196
|
+
parseAes,
|
|
197
|
+
} from "@lindorm/aes";
|
|
259
198
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
199
|
+
isAesBufferData(value); // value is AesDecryptionRecord
|
|
200
|
+
isAesSerialisedData(value); // value is SerialisedAesDecryption
|
|
201
|
+
isAesTokenised(value); // value starts with "aes:"
|
|
202
|
+
parseAes(input); // any → AesDecryptionRecord
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## Format reference
|
|
206
|
+
|
|
207
|
+
All output formats share a unified header — a JSON object containing the algorithm, encryption, content type, key id, version, and any key-exchange parameters.
|
|
264
208
|
|
|
265
209
|
### Header structure
|
|
266
210
|
|
|
@@ -271,81 +215,52 @@ type AesHeader = {
|
|
|
271
215
|
enc: KryptosEncryption; // content encryption
|
|
272
216
|
epk?: PublicEncryptionJwk; // ephemeral public key (ECDH)
|
|
273
217
|
iv?: string; // public encryption IV (base64url, GCMKW)
|
|
274
|
-
kid: string; // key
|
|
275
|
-
p2c?: number; // PBKDF2
|
|
218
|
+
kid: string; // key id
|
|
219
|
+
p2c?: number; // PBKDF2 iteration count
|
|
276
220
|
p2s?: string; // PBKDF2 salt (base64url)
|
|
277
221
|
tag?: string; // public encryption tag (base64url, GCMKW)
|
|
278
|
-
v: string; // format version
|
|
222
|
+
v: string; // format version
|
|
279
223
|
};
|
|
280
224
|
```
|
|
281
225
|
|
|
282
226
|
### Encoded
|
|
283
227
|
|
|
284
|
-
A single base64url string
|
|
228
|
+
A single base64url string. Binary layout:
|
|
285
229
|
|
|
286
230
|
```
|
|
287
231
|
[2B header length][header JSON][2B CEK length][CEK][IV][Tag][Ciphertext]
|
|
288
232
|
```
|
|
289
233
|
|
|
290
|
-
IV and tag sizes
|
|
291
|
-
tag for GCM).
|
|
234
|
+
IV and tag sizes follow the encryption algorithm.
|
|
292
235
|
|
|
293
236
|
### Serialised
|
|
294
237
|
|
|
295
|
-
|
|
238
|
+
JSON-safe object with base64url-encoded fields:
|
|
296
239
|
|
|
297
240
|
```ts
|
|
298
|
-
{
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
v: string;
|
|
305
|
-
}
|
|
241
|
+
type SerialisedAesEncryption = {
|
|
242
|
+
cek: string | undefined;
|
|
243
|
+
ciphertext: string;
|
|
244
|
+
header: string; // base64url(JSON(header))
|
|
245
|
+
iv: string;
|
|
246
|
+
tag: string;
|
|
247
|
+
v: string;
|
|
248
|
+
};
|
|
306
249
|
```
|
|
307
250
|
|
|
308
251
|
### Tokenised
|
|
309
252
|
|
|
310
|
-
A
|
|
253
|
+
A `$`-delimited string prefixed with `aes:`:
|
|
311
254
|
|
|
312
255
|
```
|
|
313
256
|
aes:<header>$[<cek>$]<iv>$<tag>$<ciphertext>
|
|
314
257
|
```
|
|
315
258
|
|
|
316
|
-
All segments are base64url-encoded. The CEK segment is
|
|
317
|
-
algorithms and omitted for `dir` and `ECDH-ES`.
|
|
259
|
+
All segments are base64url-encoded. The CEK segment is omitted for `dir` and `ECDH-ES`.
|
|
318
260
|
|
|
319
261
|
### Record
|
|
320
262
|
|
|
321
|
-
A plain object with raw `Buffer` values for
|
|
322
|
-
`content`, `initialisationVector`, etc.). Useful when you need programmatic
|
|
323
|
-
access to individual encryption components.
|
|
324
|
-
|
|
325
|
-
---
|
|
326
|
-
|
|
327
|
-
## Type definitions
|
|
328
|
-
|
|
329
|
-
### Core types
|
|
330
|
-
|
|
331
|
-
```ts
|
|
332
|
-
type AesContent = Array<any> | Buffer | Dict | number | string;
|
|
333
|
-
|
|
334
|
-
type AesContentType = "application/json" | "application/octet-stream" | "text/plain";
|
|
335
|
-
|
|
336
|
-
type AesEncryptionMode = "encoded" | "record" | "serialised" | "tokenised";
|
|
337
|
-
|
|
338
|
-
type AesKitOptions = {
|
|
339
|
-
encryption?: KryptosEncryption;
|
|
340
|
-
kryptos: IKryptos;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
type AesOperationOptions = {
|
|
344
|
-
aad?: Buffer;
|
|
345
|
-
};
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
### Encryption record
|
|
263
|
+
A plain object with raw `Buffer` values for binary fields. Useful when you need programmatic access to individual encryption components.
|
|
349
264
|
|
|
350
265
|
```ts
|
|
351
266
|
type AesEncryptionRecord = {
|
|
@@ -366,56 +281,29 @@ type AesEncryptionRecord = {
|
|
|
366
281
|
};
|
|
367
282
|
```
|
|
368
283
|
|
|
369
|
-
|
|
284
|
+
`AesDecryptionRecord` mirrors `AesEncryptionRecord` plus an optional `aad?: Buffer`. `ParsedAesDecryptionRecord` is the variant returned by string / serialised parsers and guarantees `aad: Buffer` is set.
|
|
370
285
|
|
|
371
|
-
|
|
372
|
-
type SerialisedAesEncryption = {
|
|
373
|
-
cek: string | undefined;
|
|
374
|
-
ciphertext: string;
|
|
375
|
-
header: string;
|
|
376
|
-
iv: string;
|
|
377
|
-
tag: string;
|
|
378
|
-
v: string;
|
|
379
|
-
};
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
### Decryption records
|
|
383
|
-
|
|
384
|
-
`AesDecryptionRecord` mirrors `AesEncryptionRecord` with most fields optional —
|
|
385
|
-
only `content`, `encryption`, and `initialisationVector` are required.
|
|
386
|
-
|
|
387
|
-
`SerialisedAesDecryption` mirrors `SerialisedAesEncryption` with `cek` optional.
|
|
286
|
+
`SerialisedAesDecryption` mirrors `SerialisedAesEncryption` with `cek?: string` optional.
|
|
388
287
|
|
|
389
|
-
|
|
390
|
-
parsed fields are guaranteed non-optional.
|
|
391
|
-
|
|
392
|
-
---
|
|
393
|
-
|
|
394
|
-
## Utility functions
|
|
288
|
+
## Type reference
|
|
395
289
|
|
|
396
290
|
```ts
|
|
397
|
-
|
|
398
|
-
isAesBufferData,
|
|
399
|
-
isAesSerialisedData,
|
|
400
|
-
isAesTokenised,
|
|
401
|
-
parseAes,
|
|
402
|
-
} from "@lindorm/aes";
|
|
291
|
+
type AesContent = Array<any> | boolean | Buffer | Dict | number | string;
|
|
403
292
|
|
|
404
|
-
|
|
405
|
-
isAesBufferData(data); // data is AesDecryptionRecord
|
|
293
|
+
type AesContentType = "application/json" | "application/octet-stream" | "text/plain";
|
|
406
294
|
|
|
407
|
-
|
|
408
|
-
isAesSerialisedData(data); // data is SerialisedAesDecryption
|
|
295
|
+
type AesEncryptionMode = "encoded" | "record" | "serialised" | "tokenised";
|
|
409
296
|
|
|
410
|
-
|
|
411
|
-
|
|
297
|
+
type AesKitOptions = {
|
|
298
|
+
encryption?: KryptosEncryption;
|
|
299
|
+
kryptos: IKryptos;
|
|
300
|
+
};
|
|
412
301
|
|
|
413
|
-
|
|
414
|
-
|
|
302
|
+
type AesOperationOptions = {
|
|
303
|
+
aad?: Buffer;
|
|
304
|
+
};
|
|
415
305
|
```
|
|
416
306
|
|
|
417
|
-
---
|
|
418
|
-
|
|
419
307
|
## Error handling
|
|
420
308
|
|
|
421
309
|
```ts
|
|
@@ -425,27 +313,34 @@ try {
|
|
|
425
313
|
aes.decrypt(corruptedData);
|
|
426
314
|
} catch (error) {
|
|
427
315
|
if (error instanceof AesError) {
|
|
428
|
-
|
|
316
|
+
// ...
|
|
429
317
|
}
|
|
430
318
|
}
|
|
431
319
|
```
|
|
432
320
|
|
|
433
|
-
`AesError` extends `LindormError
|
|
434
|
-
|
|
435
|
-
---
|
|
321
|
+
`AesError` extends `LindormError`.
|
|
436
322
|
|
|
437
323
|
## Testing helpers
|
|
438
324
|
|
|
439
|
-
|
|
325
|
+
`@lindorm/aes` ships separate mock entrypoints for Jest and Vitest. Both export `createMockAesKit()`, which returns an `IAesKit` whose methods are spies backed by the corresponding test framework.
|
|
440
326
|
|
|
441
327
|
```ts
|
|
442
|
-
|
|
328
|
+
// vitest
|
|
329
|
+
import { createMockAesKit } from "@lindorm/aes/mocks/vitest";
|
|
330
|
+
|
|
331
|
+
const aes = createMockAesKit();
|
|
332
|
+
aes.encrypt("hello"); // spied — has a default base64url encode implementation
|
|
333
|
+
aes.decrypt(token); // spied — base64url decode (handles "aes:" prefix)
|
|
334
|
+
aes.verify(input, data); // spied — returns true by default
|
|
335
|
+
aes.assert(input, data); // spied — no-op by default
|
|
336
|
+
```
|
|
443
337
|
|
|
444
|
-
|
|
445
|
-
//
|
|
338
|
+
```ts
|
|
339
|
+
// jest
|
|
340
|
+
import { createMockAesKit } from "@lindorm/aes/mocks/jest";
|
|
446
341
|
```
|
|
447
342
|
|
|
448
|
-
|
|
343
|
+
The mock includes a `kryptos` instance built from the corresponding `@lindorm/kryptos` mock.
|
|
449
344
|
|
|
450
345
|
## License
|
|
451
346
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { gcm, cbc, aeskw } from "@noble/ciphers/aes";
|
|
1
|
+
import { gcm, cbc, aeskw } from "@noble/ciphers/aes.js";
|
|
2
2
|
import { FlattenedEncrypt, flattenedDecrypt } from "jose";
|
|
3
|
+
import { describe, expect, test } from "vitest";
|
|
3
4
|
|
|
4
5
|
describe("ESM import smoke test", () => {
|
|
5
6
|
test("should import @noble/ciphers", () => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
KryptosAlgorithm,
|
|
5
|
-
KryptosEncryption,
|
|
3
|
+
type IKryptos,
|
|
4
|
+
type KryptosAlgorithm,
|
|
5
|
+
type KryptosEncryption,
|
|
6
6
|
KryptosKit,
|
|
7
7
|
} from "@lindorm/kryptos";
|
|
8
8
|
|
|
@@ -49,7 +49,7 @@ export const createOctKryptos = (
|
|
|
49
49
|
raw: Buffer,
|
|
50
50
|
algorithm: KryptosAlgorithm,
|
|
51
51
|
encryption?: KryptosEncryption,
|
|
52
|
-
):
|
|
52
|
+
): IKryptos =>
|
|
53
53
|
KryptosKit.from.der({
|
|
54
54
|
id: randomUUID(),
|
|
55
55
|
algorithm,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./buffer-utils";
|
|
2
|
-
export * from "./jwe-adapter";
|
|
1
|
+
export * from "./buffer-utils.js";
|
|
2
|
+
export * from "./jwe-adapter.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FlattenedJWE } from "jose";
|
|
2
|
-
import type { AesDecryptionRecord } from "../../src/types/aes-decryption-data";
|
|
3
|
-
import type { AesEncryptionRecord } from "../../src/types/aes-encryption-data";
|
|
2
|
+
import type { AesDecryptionRecord } from "../../src/types/aes-decryption-data.js";
|
|
3
|
+
import type { AesEncryptionRecord } from "../../src/types/aes-encryption-data.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Build a JWE protected header JSON string, its base64url encoding,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createCipheriv, CipherGCM, randomBytes } from "crypto";
|
|
1
|
+
import { createCipheriv, type CipherGCM, randomBytes } from "crypto";
|
|
2
2
|
import { FlattenedEncrypt, flattenedDecrypt } from "jose";
|
|
3
|
-
import { encryptAes, decryptAes } from "../src/utils/
|
|
4
|
-
import { createHmacAuthTag } from "../src/utils/
|
|
5
|
-
import { splitContentEncryptionKey } from "../src/utils/
|
|
6
|
-
import { toUint8Array } from "./helpers/buffer-utils";
|
|
3
|
+
import { encryptAes, decryptAes } from "../src/internal/utils/encryption.js";
|
|
4
|
+
import { createHmacAuthTag } from "../src/internal/utils/data/auth-tag-hmac.js";
|
|
5
|
+
import { splitContentEncryptionKey } from "../src/internal/utils/data/split-content-encryption-key.js";
|
|
6
|
+
import { toUint8Array } from "./helpers/buffer-utils.js";
|
|
7
7
|
import {
|
|
8
8
|
buildProtectedHeader,
|
|
9
9
|
toFlattenedJWE,
|
|
10
10
|
fromFlattenedJWE,
|
|
11
|
-
} from "./helpers/jwe-adapter";
|
|
11
|
+
} from "./helpers/jwe-adapter.js";
|
|
12
12
|
import {
|
|
13
13
|
RAW_KEY_128,
|
|
14
14
|
RAW_KEY_192,
|
|
@@ -20,7 +20,8 @@ import {
|
|
|
20
20
|
KEK_192,
|
|
21
21
|
KEK_256,
|
|
22
22
|
createOctKryptos,
|
|
23
|
-
} from "./fixtures/keys";
|
|
23
|
+
} from "./fixtures/keys.js";
|
|
24
|
+
import { describe, expect, test } from "vitest";
|
|
24
25
|
|
|
25
26
|
const PLAINTEXT = "hello jose interop";
|
|
26
27
|
const PLAINTEXT_BYTES = new TextEncoder().encode(PLAINTEXT);
|
|
@@ -286,7 +287,7 @@ describe("jose JWE interop: A*GCMKW + AES-GCM", () => {
|
|
|
286
287
|
// We can recover the CEK by unwrapping the encrypted_key.
|
|
287
288
|
const unwrapKryptos = createOctKryptos(kek, alg, enc);
|
|
288
289
|
const { contentEncryptionKey } = (
|
|
289
|
-
await import("../src/utils/
|
|
290
|
+
await import("../src/internal/utils/key-wrap/gcm-key-wrap.js")
|
|
290
291
|
).gcmKeyUnwrap({
|
|
291
292
|
keyEncryptionKey: kek,
|
|
292
293
|
kryptos: unwrapKryptos,
|