How yeeztech/meta-encryptor works
Project type and purpose
• This is an open-source JavaScript/TypeScript library for local client-side (Node/browser) stream encryption and decryption, with support for resumable (breakpoint-resume) file transfers.
• It exposes:
• A crypto API (key generation, pub/priv operations, file metadata generators)
• A streaming API (Sealer, Unsealer, SealedFileStream)
• A resumable-transfer API (RecoverableReadStream, RecoverableWriteStream, PipelineContext).
File structure
Top-level:
• src/ → implementation modules
– DataProvider.js, utils.js, header_util.js, limits.js, blockfile.js, ypccrypto.js, ypcntobject.js
– Streaming transforms: Sealer.js, Unsealer.js, SealedFileStream.js, SealedFileUtil.js
– Recoverable streams: Recoverable.js, PipelineContext.js
– submodule: node-aes-cmac/… (AES-CMAC implementation)
• test/ → unit tests for each module, plus a small HTTP file-fetcher/server for stream tests
• config files: rollup.config.js, babel.config.cjs, webpack.config.js, jest.config.cjs, tsconfig.json
README for insights
• Describes use cases: encrypt local data before upload, decrypt after download, generate/forward keys, support large-file resume encryption & decryption.
• Lists public APIs and usage patterns, showing data flows through Node.js streams with pipe().
Main components and their relationships
A. Crypto Subsystem
• Key generator & public/private operations
• File metadata: file-name & JSON content creation
• Hashing & signing functions (dataHashOfSealedFile, signedDataHash, forwardSkey)
B. Streaming Subsystem
• Sealer (Transform): consumes Buffer or string → adds header, encrypts payload → outputs sealed file stream
• Unsealer (Transform): consumes sealed stream → decrypts → strips header → emits original data
• SealedFileStream (Readable): reads sealed files, exposes header + encrypted blocks
• SealedFileUtil: header parsing, version checks, hash extraction
C. Recoverable Transfer Subsystem
• PipelineContext (abstract): interface for saving/loading transfer state
• PipelineContextInFile: file-backed implementation
• RecoverableReadStream / RecoverableWriteStream (Readable/Writable): track bytes, on restart resume at last-saved offset
• Integration: RecoverableReadStream → Unsealer → RecoverableWriteStream for resume-able decryption
D. Utility Modules & Sub-Algorithms
• node-aes-cmac: pure-JS AES-CMAC implementation used by both crypto and streaming subsystems
• DataProvider: likely key-pair or external data feeder for streaming
• limits.js: defines block sizes, version constants
• Data flow through streams: file source → [RecoverableReadStream] → [Sealer] → write to disk
• Recovery: context load/save ↔ PipelineContextInFile
• Decryption flow: sealed file → [SealedFileStream] → [RecoverableReadStream] → [Unsealer] → [RecoverableWriteStream] → output
Architectural patterns & design principles
• Modular subsystem separation: crypto primitives vs. streaming transforms vs. resumption logic
• Node.js “pipeable” Transform streams pattern
• Single-Responsibility: each class handles one aspect (header parsing, context persistence, AES-CMAC, encryption)
• Dependency Injection: Sealer/Unsealer accept keyPair + optional context + progress handler
Elements
• Crypto primitives (green)
• Stream transforms (blue)
• Context managers (yellow)
• I/O sources/sinks (grey)
• Annotations for key interactions, e.g., “header added/read here,” “state save/load”.