@efsf/typescript 0.1.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/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # EFSF TypeScript SDK
2
+
3
+ TypeScript implementation of the Ephemeral-First Security Framework (EFSF).
4
+
5
+ ## Overview
6
+
7
+ EFSF is a security framework built on the principle that **data that no longer exists cannot be stolen**. This SDK provides:
8
+
9
+ - **Ephemeral Storage**: Data with automatic TTL-based expiration
10
+ - **Crypto-Shredding**: Encryption keys destroyed on expiration, making data permanently unrecoverable
11
+ - **Destruction Certificates**: Cryptographically signed proof of data destruction for compliance
12
+ - **Sealed Execution**: Contexts where all state is guaranteed to be destroyed on exit
13
+ - **Data Classification**: Enforced TTL policies based on data sensitivity
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @efsf/typescript
19
+ ```
20
+
21
+ For Redis backend support:
22
+
23
+ ```bash
24
+ npm install @efsf/typescript ioredis
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```typescript
30
+ import { EphemeralStore, DataClassification, sealed } from '@efsf/typescript';
31
+
32
+ // Create a store
33
+ const store = new EphemeralStore({
34
+ backend: 'memory://', // Use 'redis://localhost:6379' for production
35
+ defaultTTL: '1h',
36
+ attestation: true,
37
+ });
38
+
39
+ // Store sensitive data with TTL
40
+ const record = await store.put(
41
+ { user_id: '123', session_token: 'secret' },
42
+ {
43
+ ttl: '30m',
44
+ classification: DataClassification.TRANSIENT,
45
+ }
46
+ );
47
+
48
+ console.log(`Stored: ${record.id}, expires at ${record.expiresAt}`);
49
+
50
+ // Retrieve data
51
+ const data = await store.get(record.id);
52
+
53
+ // Destroy with certificate (crypto-shredding)
54
+ const certificate = await store.destroy(record.id);
55
+ console.log(`Destruction certificate: ${certificate.certificateId}`);
56
+
57
+ // Data is now permanently unrecoverable
58
+ ```
59
+
60
+ ## Data Classifications
61
+
62
+ | Classification | Default TTL | Max TTL | Use Case |
63
+ |---------------|-------------|---------|----------|
64
+ | `TRANSIENT` | 1 hour | 24 hours | Sessions, OTPs, tokens |
65
+ | `SHORT_LIVED` | 1 day | 7 days | Shopping carts, temp uploads |
66
+ | `RETENTION_BOUND` | 90 days | 7 years | Invoices, audit logs |
67
+ | `PERSISTENT` | None | None | Legal holds, archival |
68
+
69
+ ## Sealed Execution
70
+
71
+ For processing sensitive data with guaranteed cleanup:
72
+
73
+ ```typescript
74
+ import { sealed, SealedExecution } from '@efsf/typescript';
75
+
76
+ // Decorator style
77
+ const processPayment = sealed({ attestation: true })(
78
+ async (cardNumber: string, amount: number) => {
79
+ // All local state destroyed on return
80
+ return { success: true, masked: `****${cardNumber.slice(-4)}` };
81
+ }
82
+ );
83
+
84
+ const result = await processPayment('4111-1111-1111-1234', 99.99);
85
+ // result._destruction_certificate contains proof of cleanup
86
+
87
+ // Context manager style
88
+ const seal = new SealedExecution({ attestation: true });
89
+ await seal.run((ctx) => {
90
+ const sensitive = ctx.track(Buffer.from('secret'));
91
+ // Process sensitive data...
92
+ });
93
+ // seal.certificate contains destruction proof
94
+ ```
95
+
96
+ ## Storage Backends
97
+
98
+ ### Memory (Default)
99
+
100
+ For testing and development:
101
+
102
+ ```typescript
103
+ const store = new EphemeralStore({ backend: 'memory://' });
104
+ ```
105
+
106
+ ### Redis
107
+
108
+ For production with native TTL support:
109
+
110
+ ```typescript
111
+ const store = new EphemeralStore({ backend: 'redis://localhost:6379' });
112
+ ```
113
+
114
+ ## API Reference
115
+
116
+ ### EphemeralStore
117
+
118
+ ```typescript
119
+ const store = new EphemeralStore({
120
+ backend: 'memory://' | 'redis://host:port',
121
+ defaultTTL: '1h' | 3600000, // string or milliseconds
122
+ attestation: true, // enable destruction certificates
123
+ });
124
+
125
+ // Store data
126
+ const record = await store.put(data, {
127
+ ttl: '30m',
128
+ classification: DataClassification.TRANSIENT,
129
+ metadata: { source: 'api' },
130
+ });
131
+
132
+ // Retrieve data
133
+ const data = await store.get(record.id);
134
+
135
+ // Check existence and TTL
136
+ const exists = await store.exists(record.id);
137
+ const ttlMs = await store.ttl(record.id);
138
+
139
+ // Destroy with certificate
140
+ const certificate = await store.destroy(record.id);
141
+
142
+ // List certificates
143
+ const certs = store.listCertificates();
144
+
145
+ // Statistics
146
+ const stats = store.stats();
147
+
148
+ // Cleanup
149
+ await store.close();
150
+ ```
151
+
152
+ ### parseTTL
153
+
154
+ Parse human-readable TTL strings:
155
+
156
+ ```typescript
157
+ import { parseTTL } from '@efsf/typescript';
158
+
159
+ parseTTL('30s'); // 30000 (30 seconds)
160
+ parseTTL('5m'); // 300000 (5 minutes)
161
+ parseTTL('2h'); // 7200000 (2 hours)
162
+ parseTTL('7d'); // 604800000 (7 days)
163
+ ```
164
+
165
+ ### DestructionCertificate
166
+
167
+ Certificates provide compliance-ready proof:
168
+
169
+ ```typescript
170
+ {
171
+ certificate_id: "uuid",
172
+ version: "1.0",
173
+ resource: {
174
+ type: "ephemeral_data",
175
+ id: "record-id",
176
+ classification: "TRANSIENT",
177
+ metadata: {}
178
+ },
179
+ destruction: {
180
+ method: "crypto_shred",
181
+ timestamp: "2025-01-25T...",
182
+ verified_by: "efsf-local-authority"
183
+ },
184
+ chain_of_custody: {
185
+ created_at: "...",
186
+ access_count: 3,
187
+ hash_chain: ["hash1", "hash2", ...]
188
+ },
189
+ signature: "base64-ed25519-signature"
190
+ }
191
+ ```
192
+
193
+ ## Compliance
194
+
195
+ EFSF helps with:
196
+
197
+ - **GDPR Article 17**: Right to erasure with verifiable proof
198
+ - **GDPR Article 25**: Data protection by design
199
+ - **CCPA §1798.105**: Right to deletion with audit trail
200
+ - **HIPAA §164.530**: Retention and destruction documentation
201
+ - **SOX §802**: Record retention with destruction certificates
202
+
203
+ ## Security Notes
204
+
205
+ 1. **Memory Zeroing**: Best-effort in JavaScript due to GC. For true guarantees, use hardware TEEs (Intel SGX, AWS Nitro Enclaves).
206
+
207
+ 2. **Key Management**: DEKs stored in memory. For production, integrate with HSM or KMS.
208
+
209
+ 3. **Backend Security**: Use Redis with TLS and authentication in production.
210
+
211
+ ## Development
212
+
213
+ ```bash
214
+ # Install dependencies
215
+ npm install
216
+
217
+ # Run tests
218
+ npm test
219
+
220
+ # Run tests with coverage
221
+ npm run test:coverage
222
+
223
+ # Build
224
+ npm run build
225
+
226
+ # Type check
227
+ npm run typecheck
228
+
229
+ # Lint
230
+ npm run lint
231
+ ```
232
+
233
+ ## Examples
234
+
235
+ See the `examples/` directory:
236
+
237
+ - `basic-usage.ts` - Core SDK features
238
+ - `express-example.ts` - Web framework integration
239
+
240
+ ## License
241
+
242
+ Apache 2.0