@lindorm/aegis 0.3.0 → 0.3.2

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 (3) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +261 -0
  3. package/package.json +11 -11
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.3.2](https://github.com/lindorm-io/monorepo/compare/@lindorm/aegis@0.3.1...@lindorm/aegis@0.3.2) (2025-07-02)
7
+
8
+ **Note:** Version bump only for package @lindorm/aegis
9
+
10
+ ## [0.3.1](https://github.com/lindorm-io/monorepo/compare/@lindorm/aegis@0.3.0...@lindorm/aegis@0.3.1) (2025-06-24)
11
+
12
+ **Note:** Version bump only for package @lindorm/aegis
13
+
6
14
  # [0.3.0](https://github.com/lindorm-io/monorepo/compare/@lindorm/aegis@0.2.6...@lindorm/aegis@0.3.0) (2025-06-17)
7
15
 
8
16
  ### Bug Fixes
package/README.md CHANGED
@@ -1 +1,262 @@
1
1
  # @lindorm/aegis
2
+
3
+ A comprehensive TypeScript library for JWT, JWE, JWS, CBOR Web Token (CWT), COSE Sign (CWS), and COSE Encrypt (CWE) operations with cryptographic key management integration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @lindorm/aegis
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **JWT Operations**: Sign and verify JSON Web Tokens
14
+ - **JWE Operations**: Encrypt and decrypt JSON Web Encryption
15
+ - **JWS Operations**: Sign and verify JSON Web Signatures
16
+ - **CWT Operations**: Sign and verify CBOR Web Tokens
17
+ - **CWS Operations**: Sign and verify COSE Sign messages
18
+ - **CWE Operations**: Encrypt and decrypt COSE Encrypt messages
19
+ - **AES Operations**: AES encryption and decryption with multiple output formats
20
+ - **Static Token Analysis**: Decode, parse, and validate tokens without verification
21
+ - **Universal Verification**: Automatically detect and verify any supported token type
22
+
23
+ ## Basic Usage
24
+
25
+ ### Setup
26
+
27
+ ```typescript
28
+ import { Aegis } from '@lindorm/aegis';
29
+ import { Amphora } from '@lindorm/amphora';
30
+ import { Logger } from '@lindorm/logger';
31
+
32
+ const logger = new Logger();
33
+ const amphora = new Amphora({ domain: 'https://example.com', logger });
34
+
35
+ const aegis = new Aegis({
36
+ amphora,
37
+ logger,
38
+ issuer: 'https://example.com', // Optional: defaults to amphora.domain
39
+ clockTolerance: 30000, // Optional: 30 seconds tolerance for time-based claims
40
+ });
41
+
42
+ // Setup and add keys to amphora
43
+ await amphora.setup();
44
+ // amphora.add(kryptosKey);
45
+ ```
46
+
47
+ ### JWT Operations
48
+
49
+ ```typescript
50
+ // Sign a JWT
51
+ const signedJwt = await aegis.jwt.sign({
52
+ expires: '1h',
53
+ subject: 'user123',
54
+ tokenType: 'access_token',
55
+ claims: { name: 'John Doe', admin: true },
56
+ audience: ['https://api.example.com'],
57
+ scope: ['read', 'write']
58
+ });
59
+
60
+ // Verify a JWT
61
+ const parsedJwt = await aegis.jwt.verify(signedJwt.token, {
62
+ audience: 'https://api.example.com',
63
+ scope: ['read']
64
+ });
65
+ ```
66
+
67
+ ### JWE Operations
68
+
69
+ ```typescript
70
+ // Encrypt data with JWE
71
+ const encryptedJwe = await aegis.jwe.encrypt('sensitive data', {
72
+ objectId: 'message-123'
73
+ });
74
+
75
+ // Decrypt JWE
76
+ const decryptedJwe = await aegis.jwe.decrypt(encryptedJwe.token);
77
+ console.log(decryptedJwe.payload); // 'sensitive data'
78
+ ```
79
+
80
+ ### JWS Operations
81
+
82
+ ```typescript
83
+ // Sign arbitrary data with JWS
84
+ const signedJws = await aegis.jws.sign('Hello World', {
85
+ objectId: 'message-456'
86
+ });
87
+
88
+ // Verify JWS
89
+ const parsedJws = await aegis.jws.verify(signedJws.token);
90
+ console.log(parsedJws.payload); // 'Hello World'
91
+ ```
92
+
93
+ ### CBOR Web Token (CWT) Operations
94
+
95
+ ```typescript
96
+ // Sign a CWT (CBOR Web Token)
97
+ const signedCwt = await aegis.cwt.sign({
98
+ expires: '2h',
99
+ subject: 'user123',
100
+ tokenType: 'access_token',
101
+ audience: ['api.example.com']
102
+ });
103
+
104
+ // Verify CWT
105
+ const parsedCwt = await aegis.cwt.verify(signedCwt.token);
106
+ ```
107
+
108
+ ### COSE Operations
109
+
110
+ ```typescript
111
+ // COSE Encrypt (CWE)
112
+ const encryptedCwe = await aegis.cwe.encrypt('secret message', {
113
+ objectId: 'message-123'
114
+ });
115
+
116
+ const decryptedCwe = await aegis.cwe.decrypt(encryptedCwe.token);
117
+ console.log(decryptedCwe.payload); // 'secret message'
118
+
119
+ // COSE Sign (CWS)
120
+ const signedCws = await aegis.cws.sign('important info', {
121
+ objectId: 'message-789'
122
+ });
123
+ const parsedCws = await aegis.cws.verify(signedCws.token);
124
+ console.log(parsedCws.payload); // 'important info'
125
+ ```
126
+
127
+ ### AES Operations
128
+
129
+ ```typescript
130
+ // AES encryption with different output formats
131
+ const encoded = await aegis.aes.encrypt('data'); // Returns base64 encoded string
132
+ const record = await aegis.aes.encrypt('data', 'record'); // Returns AesEncryptionRecord
133
+ const serialised = await aegis.aes.encrypt('data', 'serialised'); // Returns SerialisedAesEncryption
134
+
135
+ // AES decryption (accepts any format)
136
+ const decrypted = await aegis.aes.decrypt(encoded);
137
+ ```
138
+
139
+ ### Universal Token Verification
140
+
141
+ ```typescript
142
+ // Automatically detect and verify any supported token type
143
+ const result = await aegis.verify(anyTokenString, {
144
+ // Optional verification options (same as JWT/CWT verify options)
145
+ audience: 'https://api.example.com'
146
+ });
147
+
148
+ // Works with JWT, JWE, JWS, CWT, CWE, or CWS tokens
149
+ // JWE and CWE are automatically decrypted and their inner payload is verified
150
+ ```
151
+
152
+ ## Static Methods
153
+
154
+ Aegis provides static methods for token analysis without requiring cryptographic verification:
155
+
156
+ ```typescript
157
+ // Check token type
158
+ const isJwt = Aegis.isJwt(token);
159
+ const isJwe = Aegis.isJwe(token);
160
+ const isCwt = Aegis.isCwt(token);
161
+
162
+ // Decode tokens (header + payload, no verification)
163
+ const decoded = Aegis.decode(token);
164
+
165
+ // Parse tokens (decode + basic validation, no signature verification)
166
+ const parsed = Aegis.parse(token);
167
+
168
+ // Extract header information
169
+ const header = Aegis.header(token);
170
+ ```
171
+
172
+ ## Configuration Options
173
+
174
+ ### AegisOptions
175
+
176
+ ```typescript
177
+ interface AegisOptions {
178
+ amphora: IAmphora; // Key storage and management
179
+ logger: ILogger; // Logger instance
180
+ issuer?: string; // Token issuer (defaults to amphora.domain)
181
+ clockTolerance?: number; // Time tolerance in milliseconds (default: 0)
182
+ encAlgorithm?: KryptosEncAlgorithm; // Default encryption algorithm
183
+ encryption?: KryptosEncryption; // Default encryption method (default: 'A256GCM')
184
+ sigAlgorithm?: KryptosSigAlgorithm; // Default signing algorithm
185
+ }
186
+ ```
187
+
188
+ ### Signing Options
189
+
190
+ ```typescript
191
+ interface SignJwtContent {
192
+ expires: string; // Required: Expiration time ('1h', '30m', etc.)
193
+ subject: string; // Required: Token subject
194
+ tokenType: string; // Required: Type of token
195
+ audience?: string[]; // Token audiences
196
+ scope?: string[]; // OAuth scopes
197
+ claims?: Record<string, any>; // Additional claims
198
+ permissions?: string[]; // User permissions
199
+ roles?: string[]; // User roles
200
+ // ... many other optional fields
201
+ }
202
+
203
+ interface SignJwtOptions {
204
+ objectId?: string; // Object identifier
205
+ tokenId?: string; // Token identifier
206
+ issuedAt?: Date; // Issue time (defaults to now)
207
+ // ... other header options
208
+ }
209
+ ```
210
+
211
+ ### Verification Options
212
+
213
+ ```typescript
214
+ interface VerifyJwtOptions {
215
+ audience?: string | string[] | Operators; // Required audience(s)
216
+ scope?: string | string[] | Operators; // Required scope(s)
217
+ subject?: string | string[] | Operators; // Expected subject(s)
218
+ issuer?: string | Operators; // Expected issuer
219
+ tokenType?: string | Operators; // Expected token type
220
+ clientId?: string | string[] | Operators; // Expected client ID
221
+ permissions?: string | string[] | Operators; // Required permissions
222
+ roles?: string | string[] | Operators; // Required roles
223
+ // ... many other optional verification fields with Operators support
224
+ }
225
+ ```
226
+
227
+ ## Error Handling
228
+
229
+ The package provides specific error types for different scenarios:
230
+
231
+ ```typescript
232
+ import {
233
+ AegisError,
234
+ JwtError,
235
+ JweError,
236
+ JwsError,
237
+ CwtError,
238
+ CoseEncryptError,
239
+ CoseSignError
240
+ } from '@lindorm/aegis';
241
+
242
+ try {
243
+ const result = await aegis.jwt.verify(token);
244
+ } catch (error) {
245
+ if (error instanceof JwtError) {
246
+ console.log('JWT-specific error:', error.message);
247
+ } else if (error instanceof AegisError) {
248
+ console.log('General Aegis error:', error.message);
249
+ }
250
+ }
251
+ ```
252
+
253
+ ## Key Management Integration
254
+
255
+ Aegis integrates with `@lindorm/amphora` for cryptographic key management and `@lindorm/kryptos` for key operations. Keys must be properly configured in the amphora instance with appropriate purposes and operations:
256
+
257
+ - **Encryption keys**: Purpose `enc`, operations `['encrypt', 'deriveKey', 'wrapKey', 'decrypt', 'unwrapKey']`
258
+ - **Signing keys**: Purpose `sig`, operations `['sign', 'verify']`
259
+
260
+ ## License
261
+
262
+ AGPL-3.0-or-later
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lindorm/aegis",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "author": "Jonn Nilsson",
6
6
  "repository": {
@@ -29,25 +29,25 @@
29
29
  "update:auto": "ncu -u"
30
30
  },
31
31
  "dependencies": {
32
- "@lindorm/aes": "^0.5.0",
32
+ "@lindorm/aes": "^0.5.1",
33
33
  "@lindorm/b64": "^0.1.6",
34
34
  "@lindorm/date": "^0.3.0",
35
- "@lindorm/ec": "^0.2.0",
36
- "@lindorm/errors": "^0.1.8",
35
+ "@lindorm/ec": "^0.2.1",
36
+ "@lindorm/errors": "^0.1.9",
37
37
  "@lindorm/is": "^0.1.8",
38
- "@lindorm/kryptos": "^0.4.0",
39
- "@lindorm/oct": "^0.2.0",
40
- "@lindorm/okp": "^0.2.0",
41
- "@lindorm/rsa": "^0.2.0",
38
+ "@lindorm/kryptos": "^0.4.1",
39
+ "@lindorm/oct": "^0.2.1",
40
+ "@lindorm/okp": "^0.2.1",
41
+ "@lindorm/rsa": "^0.2.1",
42
42
  "@lindorm/utils": "^0.5.0",
43
43
  "cbor": "^10.0.3"
44
44
  },
45
45
  "devDependencies": {
46
- "@lindorm/amphora": "^0.2.0",
47
- "@lindorm/logger": "^0.3.0",
46
+ "@lindorm/amphora": "^0.2.2",
47
+ "@lindorm/logger": "^0.3.1",
48
48
  "@lindorm/types": "^0.3.0",
49
49
  "@types/jsonwebtoken": "^9.0.6",
50
50
  "jsonwebtoken": "^9.0.2"
51
51
  },
52
- "gitHead": "c1800f039a816f7ebce30379f8dce9c53ea9f5d1"
52
+ "gitHead": "e66150efb6d7a4688bcece59481ab98d54865af3"
53
53
  }