feat: Add TDF-JSON and TDF-CBOR format support#37
Merged
arkavo-com merged 7 commits intomainfrom Jan 18, 2026
Merged
Conversation
Implement TDF-JSON and TDF-CBOR inline payload formats per specifications: - https://github.com/arkavo-org/specifications/blob/main/tdf-json/draft-00.md - https://github.com/arkavo-org/specifications/blob/main/tdf-cbor/draft-00.md TDF-JSON Format: - TDFJSONFormat.swift: Envelope, manifest, and payload types - TDFJSONContainer.swift: Container, builder, loader, decryptor - Base64-encoded inline payloads for JSON transmission TDF-CBOR Format: - TDFCBORFormat.swift: Envelope with integer keys per spec section 3.1 - TDFCBORContainer.swift: Container, builder, loader, decryptor - Binary payloads (no base64 encoding) - SwiftCBOR dependency for CBOR serialization - Self-describe CBOR tag (55799) magic bytes Format Detection: - TDFFormatDetector.swift: Auto-detect format from magic bytes - Support for .archive, .nano, .json, .cbor format kinds CLI Integration: - Add json/cbor formats to CLIDataFormat enum - Add encrypt/decrypt commands for both formats - Update verify command to use TDFFormatDetector - Add supports command for json/cbor features Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Switch from RSA-2048 OAEP to ECIES (ECDH + HKDF + AES-GCM) key wrapping for TDF-JSON and TDF-CBOR formats by default. Changes: - TDFJSONContainer: Use wrapSymmetricKeyWithEC instead of wrapSymmetricKeyWithRSA - TDFCBORContainer: Use wrapSymmetricKeyWithEC instead of wrapSymmetricKeyWithRSA - Both now include ephemeralPublicKey in the key access object Benefits: - ~33% smaller key wrapping data (230 vs 344 base64 chars) - 6-7% smaller total file size - Modern elliptic curve cryptography - Cross-SDK compatible with Rust implementation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change ephemeral public key encoding from PEM (uncompressed, ~140 bytes) to base64 SEC1 compressed format (44 bytes for P-256). Savings: - P-256: 65 bytes uncompressed → 33 bytes compressed (50% reduction) - Total file size: ~100 bytes smaller per TDF The unwrap function now supports both formats for backwards compatibility: - Base64 SEC1 compressed (new default) - PEM format (legacy) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ings) Update TDF-CBOR payload encoding to use integer keys and enum values per spec section 1.5 for maximum size efficiency. Changes: - Add TDFCBORPayloadKey enum with integer key constants (1-6) - Add TDFCBOREnums with payload type/protocol enum values - Update toCBORData() to encode payload with integer keys and enums - Update fromCBORData() to decode both integer (new) and string (legacy) formats Payload encoding changes: - Key 1 (type): 0=inline, 1=reference (was string "inline") - Key 2 (protocol): 0=binary, 1=binary-chunked (was string "binary") - Key 3 (mimeType): string (unchanged) - Key 4 (isEncrypted): bool (unchanged) - Key 6 (value): bstr (unchanged) Size savings: ~52 bytes per TDF document from enum optimization. Reading supports both formats for cross-SDK compatibility. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add deprecation notices to NanoTDF struct and createNanoTDFv12 function - Add deprecation notice to NanoTDFCollectionBuilder - Fix TDFCBORFormat.swift for native manifest encoding compatibility - Add NanoTDF to TDF-CBOR migration guide at docs/NANOTDF_MIGRATION.md The migration guide documents: - Why TDF-CBOR is preferred (standard format, full manifest, assertions) - Step-by-step migration from NanoTDF to TDF-CBOR API - CLI migration examples - Size comparison between formats Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix array bounds access in error message (KASRewrapClient.swift:706) - Extract shared decryption logic to TDFCrypto.decryptCombinedPayload() - Add assertions CBOR encoding/decoding support - Fix swiftformat lint issues across all modified files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add explanatory comments to empty init() functions (builder pattern) - Fix ternary operators returning same value on both branches - Add missing encryptionTypeRemote enum value - Simplify single-option enum selections (protocol=kas, algorithm=AES-256-GCM) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
Implement TDF-JSON and TDF-CBOR inline payload formats per specifications:
TDF-JSON Format
TDFJSONFormat.swift: Envelope, manifest, and payload types with Codable conformanceTDFJSONContainer.swift: Container, builder, loader, decryptorTDF-CBOR Format
TDFCBORFormat.swift: Envelope with integer keys per spec section 3.1TDFCBORContainer.swift: Container, builder, loader, decryptorFormat Detection
TDFFormatDetector.swift: Auto-detect format from magic bytes.archive,.nano,.json,.cborformat kindsCLI Integration
json/cborformats toCLIDataFormatenumTDFFormatDetectorsupportscommand for json/cbor featuresDependencies
Test plan
swift buildpassesencrypt/decryptfor json and cbor formatsCross-SDK Test Results
File Size Comparison (20 byte input):
CBOR is 10-40% smaller than JSON depending on implementation.
Usage Examples
🤖 Generated with Claude Code