@lindorm/aes 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/MERMAID.md +155 -0
  3. package/README.md +365 -199
  4. package/__tests__/INTEROP-RESULTS.md +66 -0
  5. package/__tests__/esm-smoke.test.ts +15 -0
  6. package/__tests__/fixtures/keys.ts +60 -0
  7. package/__tests__/helpers/buffer-utils.ts +11 -0
  8. package/__tests__/helpers/index.ts +2 -0
  9. package/__tests__/helpers/jwe-adapter.ts +117 -0
  10. package/__tests__/jose-jwe.test.ts +463 -0
  11. package/__tests__/noble-ciphers.test.ts +208 -0
  12. package/dist/classes/AesKit.d.ts +10 -8
  13. package/dist/classes/AesKit.d.ts.map +1 -1
  14. package/dist/classes/AesKit.js +73 -34
  15. package/dist/classes/AesKit.js.map +1 -1
  16. package/dist/constants/private/index.d.ts +0 -1
  17. package/dist/constants/private/index.d.ts.map +1 -1
  18. package/dist/constants/private/index.js +0 -1
  19. package/dist/constants/private/index.js.map +1 -1
  20. package/dist/constants/private/version.d.ts +3 -1
  21. package/dist/constants/private/version.d.ts.map +1 -1
  22. package/dist/constants/private/version.js +4 -2
  23. package/dist/constants/private/version.js.map +1 -1
  24. package/dist/interfaces/AesKit.d.ts +12 -7
  25. package/dist/interfaces/AesKit.d.ts.map +1 -1
  26. package/dist/mocks/mock-aes-kit.d.ts.map +1 -1
  27. package/dist/mocks/mock-aes-kit.js +12 -2
  28. package/dist/mocks/mock-aes-kit.js.map +1 -1
  29. package/dist/types/aes-decryption-data.d.ts +26 -17
  30. package/dist/types/aes-decryption-data.d.ts.map +1 -1
  31. package/dist/types/aes-encryption-data.d.ts +7 -17
  32. package/dist/types/aes-encryption-data.d.ts.map +1 -1
  33. package/dist/types/index.d.ts +1 -0
  34. package/dist/types/index.d.ts.map +1 -1
  35. package/dist/types/private/aes-data.d.ts.map +1 -1
  36. package/dist/types/private/aes-key-derivation.d.ts +1 -1
  37. package/dist/types/private/aes-key-derivation.d.ts.map +1 -1
  38. package/dist/types/private/auth-tag.d.ts +6 -3
  39. package/dist/types/private/auth-tag.d.ts.map +1 -1
  40. package/dist/types/private/content-encryption-key.d.ts +4 -2
  41. package/dist/types/private/content-encryption-key.d.ts.map +1 -1
  42. package/dist/types/private/index.d.ts +1 -1
  43. package/dist/types/private/index.d.ts.map +1 -1
  44. package/dist/types/private/index.js +1 -1
  45. package/dist/types/private/index.js.map +1 -1
  46. package/dist/types/private/prepared-encryption.d.ts +35 -0
  47. package/dist/types/private/prepared-encryption.d.ts.map +1 -0
  48. package/dist/types/private/{aes-string.js → prepared-encryption.js} +1 -1
  49. package/dist/types/private/prepared-encryption.js.map +1 -0
  50. package/dist/utils/is-aes.d.ts.map +1 -1
  51. package/dist/utils/is-aes.js +1 -5
  52. package/dist/utils/is-aes.js.map +1 -1
  53. package/dist/utils/parse-aes.js +3 -3
  54. package/dist/utils/parse-aes.js.map +1 -1
  55. package/dist/utils/private/aes-header.d.ts +42 -0
  56. package/dist/utils/private/aes-header.d.ts.map +1 -0
  57. package/dist/utils/private/aes-header.js +75 -0
  58. package/dist/utils/private/aes-header.js.map +1 -0
  59. package/dist/utils/private/calculate/calculate-content-encryption-key-size.js +3 -3
  60. package/dist/utils/private/calculate/calculate-key-wrap-encryption.d.ts.map +1 -1
  61. package/dist/utils/private/calculate/calculate-key-wrap-encryption.js +2 -1
  62. package/dist/utils/private/calculate/calculate-key-wrap-encryption.js.map +1 -1
  63. package/dist/utils/private/data/auth-tag-hmac.d.ts +2 -2
  64. package/dist/utils/private/data/auth-tag-hmac.d.ts.map +1 -1
  65. package/dist/utils/private/data/auth-tag-hmac.js +12 -4
  66. package/dist/utils/private/data/auth-tag-hmac.js.map +1 -1
  67. package/dist/utils/private/data/auth-tag.d.ts +2 -2
  68. package/dist/utils/private/data/auth-tag.d.ts.map +1 -1
  69. package/dist/utils/private/data/auth-tag.js +4 -2
  70. package/dist/utils/private/data/auth-tag.js.map +1 -1
  71. package/dist/utils/private/data/split-content-encryption-key.d.ts.map +1 -1
  72. package/dist/utils/private/data/split-content-encryption-key.js +6 -2
  73. package/dist/utils/private/data/split-content-encryption-key.js.map +1 -1
  74. package/dist/utils/private/diffie-hellman/diffie-hellman-key-wrap.d.ts +2 -2
  75. package/dist/utils/private/diffie-hellman/diffie-hellman-key-wrap.d.ts.map +1 -1
  76. package/dist/utils/private/diffie-hellman/diffie-hellman-key-wrap.js +12 -8
  77. package/dist/utils/private/diffie-hellman/diffie-hellman-key-wrap.js.map +1 -1
  78. package/dist/utils/private/diffie-hellman/diffie-hellman.d.ts +2 -2
  79. package/dist/utils/private/diffie-hellman/diffie-hellman.d.ts.map +1 -1
  80. package/dist/utils/private/diffie-hellman/diffie-hellman.js +12 -8
  81. package/dist/utils/private/diffie-hellman/diffie-hellman.js.map +1 -1
  82. package/dist/utils/private/diffie-hellman/shared-secret.d.ts.map +1 -1
  83. package/dist/utils/private/diffie-hellman/shared-secret.js +5 -1
  84. package/dist/utils/private/diffie-hellman/shared-secret.js.map +1 -1
  85. package/dist/utils/private/encoded-aes.d.ts +2 -2
  86. package/dist/utils/private/encoded-aes.d.ts.map +1 -1
  87. package/dist/utils/private/encoded-aes.js +86 -149
  88. package/dist/utils/private/encoded-aes.js.map +1 -1
  89. package/dist/utils/private/encrypt-content.d.ts +3 -0
  90. package/dist/utils/private/encrypt-content.d.ts.map +1 -0
  91. package/dist/utils/private/encrypt-content.js +35 -0
  92. package/dist/utils/private/encrypt-content.js.map +1 -0
  93. package/dist/utils/private/encrypt-encoded.d.ts +9 -0
  94. package/dist/utils/private/encrypt-encoded.d.ts.map +1 -0
  95. package/dist/utils/private/encrypt-encoded.js +53 -0
  96. package/dist/utils/private/encrypt-encoded.js.map +1 -0
  97. package/dist/utils/private/encrypt-serialised.d.ts +9 -0
  98. package/dist/utils/private/encrypt-serialised.d.ts.map +1 -0
  99. package/dist/utils/private/encrypt-serialised.js +48 -0
  100. package/dist/utils/private/encrypt-serialised.js.map +1 -0
  101. package/dist/utils/private/encrypt-tokenised.d.ts +9 -0
  102. package/dist/utils/private/encrypt-tokenised.d.ts.map +1 -0
  103. package/dist/utils/private/encrypt-tokenised.js +45 -0
  104. package/dist/utils/private/encrypt-tokenised.js.map +1 -0
  105. package/dist/utils/private/encryption.d.ts.map +1 -1
  106. package/dist/utils/private/encryption.js +27 -27
  107. package/dist/utils/private/encryption.js.map +1 -1
  108. package/dist/utils/private/index.d.ts +6 -0
  109. package/dist/utils/private/index.d.ts.map +1 -1
  110. package/dist/utils/private/index.js +6 -0
  111. package/dist/utils/private/index.js.map +1 -1
  112. package/dist/utils/private/key-derivation/concat-kdf.d.ts +14 -0
  113. package/dist/utils/private/key-derivation/concat-kdf.d.ts.map +1 -0
  114. package/dist/utils/private/key-derivation/concat-kdf.js +26 -0
  115. package/dist/utils/private/key-derivation/concat-kdf.js.map +1 -0
  116. package/dist/utils/private/key-derivation/index.d.ts +1 -1
  117. package/dist/utils/private/key-derivation/index.d.ts.map +1 -1
  118. package/dist/utils/private/key-derivation/index.js +1 -1
  119. package/dist/utils/private/key-derivation/index.js.map +1 -1
  120. package/dist/utils/private/key-derivation/pbkdf.d.ts +1 -0
  121. package/dist/utils/private/key-derivation/pbkdf.d.ts.map +1 -1
  122. package/dist/utils/private/key-derivation/pbkdf.js +13 -2
  123. package/dist/utils/private/key-derivation/pbkdf.js.map +1 -1
  124. package/dist/utils/private/key-wrap/ecb-key-wrap.d.ts.map +1 -1
  125. package/dist/utils/private/key-wrap/ecb-key-wrap.js +10 -3
  126. package/dist/utils/private/key-wrap/ecb-key-wrap.js.map +1 -1
  127. package/dist/utils/private/key-wrap/gcm-key-wrap.d.ts.map +1 -1
  128. package/dist/utils/private/key-wrap/gcm-key-wrap.js +6 -0
  129. package/dist/utils/private/key-wrap/gcm-key-wrap.js.map +1 -1
  130. package/dist/utils/private/oct/get-oct-key-key-wrap.d.ts +1 -1
  131. package/dist/utils/private/oct/get-oct-key-key-wrap.d.ts.map +1 -1
  132. package/dist/utils/private/oct/get-oct-key-key-wrap.js +7 -14
  133. package/dist/utils/private/oct/get-oct-key-key-wrap.js.map +1 -1
  134. package/dist/utils/private/oct/get-oct-pbkdf-key-wrap-keys.d.ts.map +1 -1
  135. package/dist/utils/private/oct/get-oct-pbkdf-key-wrap-keys.js +2 -0
  136. package/dist/utils/private/oct/get-oct-pbkdf-key-wrap-keys.js.map +1 -1
  137. package/dist/utils/private/prepare-encryption.d.ts +3 -0
  138. package/dist/utils/private/prepare-encryption.d.ts.map +1 -0
  139. package/dist/utils/private/prepare-encryption.js +27 -0
  140. package/dist/utils/private/prepare-encryption.js.map +1 -0
  141. package/dist/utils/private/serialised-aes.d.ts.map +1 -1
  142. package/dist/utils/private/serialised-aes.js +38 -46
  143. package/dist/utils/private/serialised-aes.js.map +1 -1
  144. package/dist/utils/private/tokenised-aes.d.ts +3 -3
  145. package/dist/utils/private/tokenised-aes.d.ts.map +1 -1
  146. package/dist/utils/private/tokenised-aes.js +73 -55
  147. package/dist/utils/private/tokenised-aes.js.map +1 -1
  148. package/dist/utils/private/validate-version.d.ts +2 -0
  149. package/dist/utils/private/validate-version.d.ts.map +1 -0
  150. package/dist/utils/private/validate-version.js +27 -0
  151. package/dist/utils/private/validate-version.js.map +1 -0
  152. package/jest.config.interop.mjs +24 -0
  153. package/package.json +16 -15
  154. package/tsconfig.interop.json +9 -0
  155. package/dist/constants/private/format.d.ts +0 -2
  156. package/dist/constants/private/format.d.ts.map +0 -1
  157. package/dist/constants/private/format.js +0 -5
  158. package/dist/constants/private/format.js.map +0 -1
  159. package/dist/types/private/aes-string.d.ts +0 -21
  160. package/dist/types/private/aes-string.d.ts.map +0 -1
  161. package/dist/types/private/aes-string.js.map +0 -1
  162. package/dist/utils/private/key-derivation/hkdf.d.ts +0 -13
  163. package/dist/utils/private/key-derivation/hkdf.d.ts.map +0 -1
  164. package/dist/utils/private/key-derivation/hkdf.js +0 -12
  165. package/dist/utils/private/key-derivation/hkdf.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,36 @@
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.6.0](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.5.5...@lindorm/aes@0.6.0) (2026-02-17)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **aes:** add buffer boundary validation in encoded string parser ([579e8f7](https://github.com/lindorm-io/monorepo/commit/579e8f7eb40570f978cd52d1f87f7f8570474d6d))
11
+ - **aes:** add GCM auth tag enforcement and key-wrap input validation ([1a8fd3c](https://github.com/lindorm-io/monorepo/commit/1a8fd3cb6f83cf59a3089a777fba4c8b7f1828fb))
12
+ - **aes:** add missing @lindorm/utils dependency ([6d0ee2a](https://github.com/lindorm-io/monorepo/commit/6d0ee2ae68f91fb9eb04529c96e05ff1d843dfd0))
13
+ - **aes:** make CBC HMAC auth tag compliant with RFC 7518 ([7877022](https://github.com/lindorm-io/monorepo/commit/7877022bebdf902ff13996b1032a991356f3760c))
14
+ - **aes:** make PBES2 salt compliant with RFC 7518 ([2693afa](https://github.com/lindorm-io/monorepo/commit/2693afa88db535aeaff7fd5537885dd3a45bc09a))
15
+ - **aes:** make verify/assert work with non-string content ([aa94c66](https://github.com/lindorm-io/monorepo/commit/aa94c66511326f70fdfc0245ce12953025aa4236))
16
+ - **aes:** remove unnecessary g flag from tokenised regex ([5a989b1](https://github.com/lindorm-io/monorepo/commit/5a989b1d96b025b3180339294e8ea072d215c7d3))
17
+ - **aes:** replace generic Error with AesError in all locations ([ff7a08d](https://github.com/lindorm-io/monorepo/commit/ff7a08d55e9b39755e059e31e99fb45b687bdde2))
18
+ - **aes:** use Concat KDF per RFC 7518 for ECDH-ES key agreement ([8e92b8f](https://github.com/lindorm-io/monorepo/commit/8e92b8f60ee46c99f0c66af244fd1e7648130a9c))
19
+ - **aes:** use crypto.randomInt for PBKDF2 iterations, fix RSA test fixture ([a5457aa](https://github.com/lindorm-io/monorepo/commit/a5457aa5973e4eab662dbc6e62c9470f7d6fabf2))
20
+ - **aes:** use oct keys directly for AES key wrap per RFC 7518 ([c65ca49](https://github.com/lindorm-io/monorepo/commit/c65ca49d758f21e868e96512a96fc8df0559947e))
21
+ - **aes:** use timingSafeEqual for ECB key unwrap integrity check ([dd27a65](https://github.com/lindorm-io/monorepo/commit/dd27a65c84eed068d6e9e5de34d0eaca6cda67fc))
22
+ - **aes:** use timingSafeEqual for HMAC auth tag verification ([757bef5](https://github.com/lindorm-io/monorepo/commit/757bef5657a6d1366c222c9205a8f4cfe563e77d))
23
+ - **lint:** add missing eslint-config-prettier and fix prettier formatting ([6899e39](https://github.com/lindorm-io/monorepo/commit/6899e39ad7700e373173b0a61b429b5536c13934))
24
+ - **lint:** resolve eslint warnings and errors ([210ef3c](https://github.com/lindorm-io/monorepo/commit/210ef3c91c82521c4cec57bc2256324ba9c3f45a))
25
+
26
+ ### Features
27
+
28
+ - **aes:** accept optional AAD parameter for authenticated encryption ([011b67f](https://github.com/lindorm-io/monorepo/commit/011b67fb8ba18a361e2c31fd0e78298a89f89cd2))
29
+ - **aes:** add prepareEncryption() for two-step JWE-compliant encryption ([56b3c54](https://github.com/lindorm-io/monorepo/commit/56b3c5435722b2b94f05d6483c7651ccdd5ea9dd))
30
+ - **aes:** rewrite formats with unified model and always-on AAD ([bc1da71](https://github.com/lindorm-io/monorepo/commit/bc1da719d5ee5ee151d9220e6e738a9431e036b6))
31
+
32
+ ## [0.5.5](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.5.4...@lindorm/aes@0.5.5) (2025-09-18)
33
+
34
+ **Note:** Version bump only for package @lindorm/aes
35
+
6
36
  ## [0.5.4](https://github.com/lindorm-io/monorepo/compare/@lindorm/aes@0.5.3...@lindorm/aes@0.5.4) (2025-07-19)
7
37
 
8
38
  **Note:** Version bump only for package @lindorm/aes
package/MERMAID.md ADDED
@@ -0,0 +1,155 @@
1
+ # Mermaid Diagram
2
+
3
+ ```mermaid
4
+
5
+ graph TB
6
+ subgraph "External Dependencies"
7
+ KRYPTOS["@lindorm/kryptos<br/>(Key Management)"]
8
+ B64["@lindorm/b64<br/>(Base64 Encoding)"]
9
+ IS["@lindorm/is<br/>(Type Guards)"]
10
+ ERRORS["@lindorm/errors<br/>(Error Handling)"]
11
+ end
12
+
13
+ subgraph "Public API"
14
+ AESKIT["AesKit Class<br/>Main Entry Point"]
15
+ PARSE["parseAes()<br/>Parse any format"]
16
+ ISAES["isAesTokenised()<br/>Type checking"]
17
+ end
18
+
19
+ subgraph "Encryption Flow"
20
+ ENCRYPT["encrypt(data, mode)"]
21
+ GET_ENC_KEY["getEncryptionKey()"]
22
+
23
+ subgraph "Key Type Routing"
24
+ EC_ENC["EC Keys<br/>(Elliptic Curve)"]
25
+ OKP_ENC["OKP Keys<br/>(Edwards Curve)"]
26
+ OCT_ENC["oct Keys<br/>(Symmetric)"]
27
+ RSA_ENC["RSA Keys"]
28
+ end
29
+
30
+ subgraph "Key Derivation Methods"
31
+ DIR["Direct Key<br/>(dir)"]
32
+ ECDH["ECDH-ES<br/>(Diffie-Hellman)"]
33
+ KEYWRAP["Key Wrap<br/>(AES-KW/GCM)"]
34
+ PBKDF["PBKDF2<br/>(Password-based)"]
35
+ end
36
+
37
+ CEK["Content Encryption Key<br/>(Split into encKey + hashKey)"]
38
+ AES_CIPHER["Node crypto.createCipheriv()<br/>(AES-128/192/256-CBC/GCM)"]
39
+ AUTH_TAG["Generate Auth Tag<br/>(GCM or HMAC)"]
40
+
41
+ subgraph "Output Modes"
42
+ ENCODED["Encoded<br/>(base64 string)"]
43
+ RECORD["Record<br/>(Buffer objects)"]
44
+ SERIALISED["Serialised<br/>(JSON-safe strings)"]
45
+ TOKENISED["Tokenised<br/>($enc$params$content$)"]
46
+ end
47
+ end
48
+
49
+ subgraph "Decryption Flow"
50
+ DECRYPT["decrypt(data)"]
51
+ PARSE_INPUT["Parse Input<br/>(parseAes)"]
52
+ GET_DEC_KEY["getDecryptionKey()"]
53
+
54
+ subgraph "Key Type Decryption"
55
+ EC_DEC["EC Keys"]
56
+ OKP_DEC["OKP Keys"]
57
+ OCT_DEC["oct Keys"]
58
+ RSA_DEC["RSA Keys"]
59
+ end
60
+
61
+ CEK_DEC["Content Encryption Key"]
62
+ AES_DECIPHER["Node crypto.createDecipheriv()"]
63
+ VERIFY_TAG["Verify Auth Tag"]
64
+ PARSE_CONTENT["Parse Content<br/>(by contentType)"]
65
+ end
66
+
67
+ subgraph "Data Types"
68
+ CONTENT["AesContent<br/>string | Buffer | object | array | number"]
69
+ CONTENT_TYPE["AesContentType<br/>text/plain | application/json | application/octet-stream"]
70
+ end
71
+
72
+ subgraph "Encryption Metadata"
73
+ RECORD_TYPE["AesEncryptionRecord<br/>• algorithm<br/>• encryption<br/>• keyId<br/>• content<br/>•
74
+ authTag<br/>• IV<br/>• contentType<br/>• pbkdfSalt/Iterations<br/>• publicEncryptionKey/Jwk"]
75
+ end
76
+
77
+ %% Main flow connections
78
+ AESKIT --> ENCRYPT
79
+ AESKIT --> DECRYPT
80
+ AESKIT --> KRYPTOS
81
+
82
+ ENCRYPT --> CONTENT
83
+ ENCRYPT --> GET_ENC_KEY
84
+ GET_ENC_KEY --> KRYPTOS
85
+
86
+ GET_ENC_KEY --> EC_ENC
87
+ GET_ENC_KEY --> OKP_ENC
88
+ GET_ENC_KEY --> OCT_ENC
89
+ GET_ENC_KEY --> RSA_ENC
90
+
91
+ EC_ENC --> ECDH
92
+ EC_ENC --> KEYWRAP
93
+ OKP_ENC --> ECDH
94
+ OKP_ENC --> KEYWRAP
95
+ OCT_ENC --> DIR
96
+ OCT_ENC --> KEYWRAP
97
+ OCT_ENC --> PBKDF
98
+ RSA_ENC --> KEYWRAP
99
+
100
+ ECDH --> CEK
101
+ KEYWRAP --> CEK
102
+ PBKDF --> CEK
103
+ DIR --> CEK
104
+
105
+ CEK --> AES_CIPHER
106
+ CONTENT --> AES_CIPHER
107
+ AES_CIPHER --> AUTH_TAG
108
+
109
+ AUTH_TAG --> RECORD_TYPE
110
+
111
+ RECORD_TYPE --> ENCODED
112
+ RECORD_TYPE --> RECORD
113
+ RECORD_TYPE --> SERIALISED
114
+ RECORD_TYPE --> TOKENISED
115
+
116
+ %% Decryption flow
117
+ DECRYPT --> PARSE_INPUT
118
+ PARSE_INPUT --> ENCODED
119
+ PARSE_INPUT --> RECORD
120
+ PARSE_INPUT --> SERIALISED
121
+ PARSE_INPUT --> TOKENISED
122
+
123
+ PARSE_INPUT --> GET_DEC_KEY
124
+ GET_DEC_KEY --> KRYPTOS
125
+
126
+ GET_DEC_KEY --> EC_DEC
127
+ GET_DEC_KEY --> OKP_DEC
128
+ GET_DEC_KEY --> OCT_DEC
129
+ GET_DEC_KEY --> RSA_DEC
130
+
131
+ EC_DEC --> CEK_DEC
132
+ OKP_DEC --> CEK_DEC
133
+ OCT_DEC --> CEK_DEC
134
+ RSA_DEC --> CEK_DEC
135
+
136
+ CEK_DEC --> AES_DECIPHER
137
+ RECORD_TYPE --> AES_DECIPHER
138
+ AES_DECIPHER --> VERIFY_TAG
139
+ VERIFY_TAG --> PARSE_CONTENT
140
+ PARSE_CONTENT --> CONTENT_TYPE
141
+
142
+ %% Utility connections
143
+ B64 --> ENCODED
144
+ B64 --> TOKENISED
145
+ B64 --> SERIALISED
146
+ IS --> PARSE_INPUT
147
+ ERRORS --> AESKIT
148
+
149
+ style AESKIT fill:#4a90e2,stroke:#2e5c8a,color:#fff
150
+ style ENCRYPT fill:#50c878,stroke:#2d7a4a,color:#fff
151
+ style DECRYPT fill:#e27d60,stroke:#a85a43,color:#fff
152
+ style KRYPTOS fill:#9b59b6,stroke:#6c3a8a,color:#fff
153
+ style CEK fill:#f39c12,stroke:#b87a0a,color:#fff
154
+ style CEK_DEC fill:#f39c12,stroke:#b87a0a,color:#fff
155
+ ```