55- ✅ Salt for hashing
66- ✅ Update last used timestamp
77- ✅ Key tags/labels
8+ - ✅ Rate limiting
89
910## Recommended Additions
1011
11- ### 1. Rate Limiting Helper
12- ``` typescript
13- interface RateLimitConfig {
14- maxRequests: number
15- windowMs: number
16- }
17-
18- // Usage:
19- const rateLimiter = keys .createRateLimiter ({
20- maxRequests: 100 ,
21- windowMs: 60000 , // 1 minute
22- })
23-
24- await rateLimiter .check (apiKeyRecord )
25- ```
26-
27- ### 2. Key Rotation
12+ ### 1. Key Rotation
2813``` typescript
2914// Rotate a key (create new, mark old as rotating)
3015const { newKey, oldRecord } = await keys .rotate (oldKeyId , {
3116 gracePeriodMs: 86400000 , // 24 hours
3217})
3318```
3419
35- ### 3 . Usage Analytics
20+ ### 2 . Usage Analytics
3621``` typescript
3722// Track key usage
3823await keys .trackUsage (keyId , {
@@ -45,7 +30,7 @@ await keys.trackUsage(keyId, {
4530const stats = await keys .getUsageStats (keyId )
4631```
4732
48- ### 4 . Webhook Events
33+ ### 3 . Webhook Events
4934``` typescript
5035keys .on (' key.created' , async (event ) => {
5136 await sendWebhook (event .ownerId , ' key_created' , event .data )
@@ -60,7 +45,7 @@ keys.on('key.expired', async (event) => {
6045})
6146```
6247
63- ### 5 . IP Whitelisting
48+ ### 4 . IP Whitelisting
6449``` typescript
6550await keys .create ({
6651 ownerId: ' user_123' ,
@@ -70,7 +55,7 @@ await keys.create({
7055await keys .verify (key , { ipAddress: req .ip })
7156```
7257
73- ### 6 . Request Signing
58+ ### 5 . Request Signing
7459``` typescript
7560// HMAC-based request signing
7661const signature = keys .sign (request , apiKey )
@@ -79,7 +64,7 @@ const signature = keys.sign(request, apiKey)
7964const isValid = await keys .verifySignature (request , signature , keyId )
8065```
8166
82- ### 7 . Bulk Operations
67+ ### 6 . Bulk Operations
8368``` typescript
8469// Bulk create
8570const results = await keys .createBulk ([
@@ -91,7 +76,7 @@ const results = await keys.createBulk([
9176await keys .revokeBulk ([' key_1' , ' key_2' , ' key_3' ])
9277```
9378
94- ### 8 . Key Templates
79+ ### 7 . Key Templates
9580``` typescript
9681// Define reusable templates
9782keys .defineTemplate (' readonly' , {
@@ -104,7 +89,7 @@ const { key } = await keys.createFromTemplate('readonly', {
10489})
10590```
10691
107- ### 9 . Audit Logging
92+ ### 8 . Audit Logging
10893``` typescript
10994interface AuditLog {
11095 action: ' created' | ' verified' | ' revoked' | ' updated'
@@ -124,20 +109,20 @@ const logs = await keys.getAuditLogs({
124109## Priority Recommendations
125110
126111** High Priority:**
127- 1 . Rate limiting (security)
128- 2 . Update last used timestamp (already added)
129- 3 . Audit logging (compliance)
112+ - Rate limiting (security)
113+ - Update last used timestamp (already added)
114+ - Audit logging (compliance)
130115
131116** Medium Priority:**
132- 4 . Key rotation (security best practice)
133- 5 . IP whitelisting (additional security layer)
134- 6 . Usage analytics (insights)
117+ - Key rotation (security best practice)
118+ - IP whitelisting (additional security layer)
119+ - Usage analytics (insights)
135120
136121** Low Priority:**
137- 7 . Webhook events (automation)
138- 8 . Request signing (advanced security)
139- 9 . Key templates (convenience)
140- 10 . Bulk operations (efficiency)
122+ - Webhook events (automation)
123+ - Request signing (advanced security)
124+ - Key templates (convenience)
125+ - Bulk operations (efficiency)
141126
142127## Implementation Notes
143128
0 commit comments