@zkim-platform/file-format 1.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/CHANGELOG.md ADDED
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-01-09
9
+
10
+ ### Added
11
+ - **Initial Release - v1.0.0:**
12
+ - Secure file format using NIST-standardized post-quantum cryptography
13
+ - Magic bytes: `"ZKIM"` (4 bytes)
14
+ - Version: `1` (2 bytes)
15
+ - Signature type: `1` (ML-DSA-65, 3,309 bytes, FIPS 204)
16
+ - **Post-Quantum Cryptography:**
17
+ - ML-DSA-65 (FIPS 204) for digital signatures (3,309 bytes)
18
+ - ML-KEM-768 (FIPS 203) for key encapsulation mechanism and key derivation
19
+ - NIST-standardized algorithms for long-term security
20
+ - **ML-KEM-768 Key Derivation**: Platform and user layer keys are derived from ML-KEM-768 shared secrets using BLAKE3. Content layer keys are cryptographically random for per-file perfect forward secrecy.
21
+ - **Self-Encryption Helpers**: `zkimSelfEncrypt()` and `zkimSelfDecrypt()` helper functions for ML-KEM-768 self-encryption pattern
22
+ - **KEM Ciphertext in Wire Format**: Wire format includes ML-KEM-768 ciphertext (1,088 bytes) for key exchange
23
+ - **Key Storage Infrastructure**: ML-KEM-768 secret keys are stored encrypted with user keys
24
+ - **Enhanced Security:**
25
+ - Post-quantum resistant signatures and key exchange
26
+ - Future-proof cryptography for store-now-decrypt-later scenarios
27
+ - Explicit threat model documentation
28
+ - **Core Features:**
29
+ - Three-layer encryption with XChaCha20-Poly1305 (platform, user, content layers)
30
+ - Privacy-preserving searchable encryption using OPRF-based trapdoors
31
+ - Integrity validation with BLAKE3 hashing and ML-DSA-65 signatures
32
+ - Error detection and recovery mechanisms for corrupted files
33
+ - Optional GZIP/Brotli compression for efficient storage
34
+ - Performance monitoring and optimization
35
+ - Constant-time security operations to prevent timing attacks
36
+ - **Documentation:**
37
+ - README with essential information
38
+ - Comprehensive GitHub Wiki with 9 detailed pages:
39
+ - Getting Started guide
40
+ - Storage Integration guide (critical for custom backends)
41
+ - Complete API Reference
42
+ - Code Examples and patterns
43
+ - Security documentation (post-quantum details)
44
+ - Architecture specification
45
+ - Troubleshooting guide
46
+ - Contributing guidelines
47
+ - **Build Attestation:**
48
+ - npm Provenance support (SLSA Level 2)
49
+ - Verifiable build information on npm package page
50
+ - Public ledger transparency log entries
51
+
52
+ ### Changed
53
+ - Updated package name to `@zkim-platform/file-format` to match npm organization scope
54
+ - Updated all code examples and documentation to use correct package name
55
+
56
+ ### Fixed
57
+ - Fixed install command in documentation (`npm install @zkim-platform/file-format`)
58
+ - Fixed build status badge URL format for GitHub Actions
59
+ - Updated all source file comments and JSDoc to reference correct package name
60
+ - Fixed platform key usage - now included in encryption key derivation for tenant isolation
61
+
62
+ ### Security
63
+ - **Post-Quantum Security:**
64
+ - ML-DSA-65 signatures (FIPS 204) for long-term authenticity
65
+ - ML-KEM-768 key exchange (FIPS 203) for post-quantum key encapsulation
66
+ - ML-KEM-768 key derivation for platform and user layer keys (post-quantum secure)
67
+ - Content layer keys are cryptographically random (per-file perfect forward secrecy)
68
+ - BLAKE3 hashing (256-bit output) for integrity verification and key derivation
69
+ - XChaCha20-Poly1305 symmetric encryption (AEAD) with ML-KEM-768 derived keys
70
+ - **Post-Quantum Key Derivation**: Platform and user layer encryption keys are derived from ML-KEM-768 shared secrets, ensuring post-quantum security for key derivation. Content layer keys are random for perfect forward secrecy.
71
+ - **Self-Encryption Pattern**: ML-KEM-768 self-encryption pattern for data encrypted by and for the same user/device
72
+ - **Key Derivation Pattern**:
73
+ - Platform key: `blake3([sharedSecret, ...platformKey], { dkLen: 32 })`
74
+ - User key: `blake3([sharedSecret, ...userKey], { dkLen: 32 })`
75
+ - Content key: Cryptographically random (per-file perfect forward secrecy)
76
+ - **Note:** This package uses NIST-standardized algorithms (FIPS 203/204) but is not FIPS 140-3 validated by an accredited laboratory.
77
+
78
+ ### Technical Details
79
+ - **Dependencies:**
80
+ - libsodium-wrappers-sumo ^0.7.15 - Cryptographic operations (XChaCha20-Poly1305)
81
+ - @noble/hashes ^2.0.1 - BLAKE3 hashing and key derivation
82
+ - @noble/post-quantum ^0.2.1 - ML-DSA-65 and ML-KEM-768
83
+ - @noble/curves ^2.0.1 - Ristretto255 for searchable encryption
84
+ - **Algorithm Suite**: `ALG_SUITE_ID = 0x01` represents post-quantum secure suite (ML-KEM-768 for key exchange, ML-DSA-65 for signatures, XChaCha20-Poly1305 for symmetric encryption with post-quantum key derivation, BLAKE3 for hashing)
85
+ - **Default Encryption Type**: `"ML-KEM-768+XChaCha20-Poly1305"` (post-quantum key derivation)
86
+ - **KEM Ciphertext Size**: 1,088 bytes (ML-KEM-768 standard)
87
+ - **Wire Format**: Includes KEM ciphertext for ML-KEM-768 key exchange
88
+ - **Backward Compatibility**: Maintained for legacy data formats without ML-KEM-768 components
89
+ - **Platform Support:**
90
+ - Node.js 18+ with ES Modules
91
+ - Modern browsers with TypedArray and WebAssembly support
92
+ - Browser builds rely on WebAssembly-backed libsodium (via `libsodium-wrappers-sumo`)
93
+ - **Build:**
94
+ - TypeScript 5.9+ with strict mode
95
+ - ESM and CommonJS dual package support
96
+ - Source maps and declaration files included
97
+ - npm Provenance attestation enabled
98
+
99
+ ---
100
+
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ZKIM Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @zkim-platform/file-format
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@zkim-platform/file-format)
4
+ ![npm downloads](https://img.shields.io/npm/dm/@zkim-platform/file-format)
5
+ ![License](https://img.shields.io/badge/license-MIT-blue)
6
+ ![TypeScript](https://img.shields.io/badge/TypeScript-5.9-blue)
7
+ ![Node.js](https://img.shields.io/badge/Node.js-18%2B-green)
8
+ ![Test Coverage](https://img.shields.io/badge/coverage-92%25-brightgreen)
9
+ ![Build Status](https://github.com/zkdotim/zkim-file-format/actions/workflows/ci.yml/badge.svg?branch=main)
10
+
11
+ Post-quantum secure file format using ML-KEM-768 (FIPS 203) for key exchange and ML-DSA-65 (FIPS 204) for signatures, with XChaCha20-Poly1305 symmetric encryption protected by post-quantum key derivation. Three-layer encryption with privacy-preserving search capabilities. Platform and user layer keys are derived from ML-KEM-768 shared secrets using BLAKE3. Content layer keys are cryptographically random for per-file perfect forward secrecy.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @zkim-platform/file-format
17
+ ```
18
+
19
+ ### Requirements
20
+
21
+ - Node.js 18+ (for Node.js environments)
22
+ - Modern browser with TypedArray and ES2020+ support (for browser environments)
23
+ - Browser builds rely on WebAssembly-backed libsodium (via `libsodium-wrappers-sumo`)
24
+ - TypeScript 5.0+ (recommended for type safety)
25
+
26
+ ## Quick Start
27
+
28
+ ```typescript
29
+ import { ZKIMFileService, InMemoryStorage } from "@zkim-platform/file-format";
30
+ import sodium from "libsodium-wrappers-sumo";
31
+
32
+ async function main() {
33
+ await sodium.ready;
34
+
35
+ // ⚠️ NOTE: This example uses random keys for simplicity.
36
+ // In production, derive keys from actual user authentication.
37
+ // See Authentication Integration guide for proper key derivation.
38
+
39
+ // Platform key (store securely, same for all users)
40
+ const platformKey = sodium.randombytes_buf(32);
41
+
42
+ // User key (in production, derive from user authentication)
43
+ // Example: const userKey = await deriveKeyFromWallet(walletAddress, signature);
44
+ const userKey = sodium.randombytes_buf(32);
45
+ const userId = "example-user";
46
+
47
+ // Create storage backend
48
+ const storage = new InMemoryStorage();
49
+
50
+ // Initialize the file service
51
+ const fileService = new ZKIMFileService(
52
+ {
53
+ enableCompression: true,
54
+ enableSearchableEncryption: false,
55
+ enableIntegrityValidation: true,
56
+ },
57
+ undefined,
58
+ storage
59
+ );
60
+
61
+ await fileService.initialize();
62
+
63
+ try {
64
+ // Create encrypted ZKIM file
65
+ const testData = new TextEncoder().encode("Hello, ZKIM File Format!");
66
+ const result = await fileService.createZkimFile(
67
+ testData,
68
+ userId,
69
+ platformKey,
70
+ userKey,
71
+ {
72
+ fileName: "example.txt",
73
+ mimeType: "text/plain",
74
+ }
75
+ );
76
+
77
+ if (result.success && result.file) {
78
+ console.log("File created:", result.file.header.fileId);
79
+ }
80
+ } catch (error) {
81
+ console.error("Failed to create file:", error);
82
+ }
83
+
84
+ await fileService.cleanup();
85
+ }
86
+
87
+ main().catch(console.error);
88
+ ```
89
+
90
+ ## Who is this for?
91
+
92
+ - Developers building secure file storage or sharing systems
93
+ - Applications requiring long-term confidentiality (store-now-decrypt-later resistance)
94
+ - Projects that need post-quantum signatures and crypto agility
95
+ - Teams concerned about supply-chain security and provenance
96
+
97
+ ## Documentation
98
+
99
+ 📖 **[Full Documentation → Wiki](https://github.com/zkdotim/zkim-file-format/wiki)**
100
+
101
+ - [Getting Started](https://github.com/zkdotim/zkim-file-format/wiki/Getting-Started)
102
+ - [Authentication Integration](https://github.com/zkdotim/zkim-file-format/wiki/Authentication-Integration) ⭐ **CRITICAL**
103
+ - [Storage Integration](https://github.com/zkdotim/zkim-file-format/wiki/Storage-Integration) ⭐ **CRITICAL**
104
+ - [API Reference](https://github.com/zkdotim/zkim-file-format/wiki/API-Reference)
105
+ - [Examples](https://github.com/zkdotim/zkim-file-format/wiki/Examples)
106
+ - [Security & Post-Quantum](https://github.com/zkdotim/zkim-file-format/wiki/Security)
107
+ - [Architecture](https://github.com/zkdotim/zkim-file-format/wiki/Architecture)
108
+ - [Troubleshooting](https://github.com/zkdotim/zkim-file-format/wiki/Troubleshooting)
109
+
110
+ ## Features
111
+
112
+ - 🔐 **Three-Layer Encryption**: XChaCha20-Poly1305 with platform, user, and content layers
113
+ - 🔍 **Privacy-Preserving Search**: OPRF-based trapdoors with rotation
114
+ - ✅ **Post-Quantum Signatures**: ML-DSA-65 (FIPS 204) for long-term authenticity
115
+ - 📦 **Compression**: Optional GZIP/Brotli compression
116
+ - 🛡️ **Integrity Validation**: BLAKE3-based content hashing and integrity verification
117
+ - 🌐 **Cross-Platform**: Works in browser and Node.js environments
118
+
119
+ **⚠️ FIPS Validation Disclaimer:** This package uses NIST-standardized algorithms (FIPS 203/204) but is **NOT FIPS 140-3 validated** by an accredited laboratory. The implementation follows NIST specifications but is not certified for government use requiring FIPS validation. See [Security Documentation](https://github.com/zkdotim/zkim-file-format/wiki/Security) for details.
120
+
121
+ ## Key Technologies
122
+
123
+ - **Encryption**: XChaCha20-Poly1305 (AEAD) via libsodium
124
+ - **Hashing**: BLAKE3 (256-bit output) via @noble/hashes
125
+ - **Signatures**: ML-DSA-65 (FIPS 204, post-quantum) via @noble/post-quantum
126
+ - **Key Exchange**: ML-KEM-768 (FIPS 203, post-quantum) via @noble/post-quantum
127
+ - **Searchable Encryption**: OPRF (Oblivious Pseudorandom Function) via @noble/curves
128
+
129
+ ## Design Philosophy
130
+
131
+ - **Post-quantum by default** - Future-proof cryptography from day one
132
+ - **Crypto agility** - Algorithm choices are explicit and configurable
133
+ - **Explicit threat models** - Security assumptions are documented
134
+ - **Auditability over obscurity** - Open design and verifiable builds
135
+
136
+ ## License
137
+
138
+ MIT License - see [LICENSE](./LICENSE) for details.
139
+
140
+ ---
141
+
142
+ ## Provenance
143
+
144
+ This package is published with **npm Provenance** (build attestation) to ensure authenticity and integrity.
145
+
146
+ **What is Provenance?**
147
+ Provenance provides verifiable information about how and where this package was built:
148
+ - ✅ **Built and signed on:** GitHub Actions
149
+ - ✅ **Source Commit:** Links to exact GitHub commit
150
+ - ✅ **Build File:** Links to GitHub Actions workflow
151
+ - ✅ **Public Ledger:** Transparency log entry (immutable record)
152
+
153
+ **Why it matters:**
154
+ - Verifies package authenticity
155
+ - Shows exact source code used
156
+ - Provides build environment details
157
+ - Creates immutable audit trail
158
+ - Enhances supply chain security
159
+
160
+ **View Provenance:**
161
+ Visit the package page on npm and scroll to the "Provenance" section at the bottom to see:
162
+ - Build environment details
163
+ - Source commit link
164
+ - Build workflow file
165
+ - Public ledger entry
166
+
167
+ **Verify locally:**
168
+ ```bash
169
+ npm audit signatures
170
+ ```
171
+
172
+ For more information, see [npm Provenance Documentation](https://docs.npmjs.com/generating-provenance-statements/).
173
+
174
+ ---
175
+
176
+ **Made with ❤️ by the ZKIM Team**