Your music, beautifully tracked. All yours. (coming soon) teal.fm
teal-fm atproto
at main 104 lines 3.0 kB view raw view rendered
1# How to Extract rkey from AT Protocol CAR Files 2 3The **rkey** (record key) is not stored inside the IPLD record data itself. Instead, it's found in **commit operations** that map collection paths to record CIDs. 4 5## AT Protocol Structure 6 7``` 8Repository Structure: 9├── Records (IPLD blocks) 10│ ├── bafyrei123... (actual play record data) 11│ ├── bafyrei456... (actual profile record data) 12│ └── bafyrei789... (actual post record data) 13└── Commits (IPLD blocks) 14 ├── bafycommit1... (operations mapping paths to CIDs) 15 └── bafycommit2... (more operations) 16``` 17 18## Example: Record IPLD (without rkey) 19 20```json 21{ 22 "$type": "fm.teal.alpha.feed.play", 23 "track_name": "Bohemian Rhapsody", 24 "artist_names": ["Queen"], 25 "duration": 355000, 26 "played_time": "2024-01-15T14:30:00Z" 27} 28``` 29 30**❌ No rkey here!** The record contains the data but not its key. 31 32## Example: Commit IPLD (with rkey mappings) 33 34```json 35{ 36 "ops": [ 37 { 38 "action": "create", 39 "path": "fm.teal.alpha.feed.play/3k2akjdlkjsf", // ← collection/rkey 40 "cid": "bafyrei123..." // ← points to the record above 41 }, 42 { 43 "action": "create", 44 "path": "fm.teal.alpha.actor.profile/self", 45 "cid": "bafyrei456..." 46 } 47 ], 48 "prev": "bafyrei...", 49 "rev": "3k2bkl...", 50 "time": "2024-01-15T14:35:00Z" 51} 52``` 53 54**✅ rkey is here!** Extract it from the `path` field: `"3k2akjdlkjsf"` 55 56## Extraction Algorithm 57 58```rust 59fn extract_rkeys_from_commits(commits: &[CommitInfo]) -> HashMap<String, String> { 60 let mut cid_to_rkey = HashMap::new(); 61 62 for commit in commits { 63 for operation in &commit.operations { 64 // Path format: "collection/rkey" 65 if let Some(rkey) = operation.path.split('/').last() { 66 if let Some(ref record_cid) = operation.record_cid { 67 cid_to_rkey.insert(record_cid.clone(), rkey.to_string()); 68 } 69 } 70 } 71 } 72 73 cid_to_rkey 74} 75``` 76 77## Complete Example 78 791. **Find commit blocks** in CAR file 802. **Extract operations** from commit IPLD 813. **Parse paths** like `"fm.teal.alpha.feed.play/3k2akjdlkjsf"` 824. **Map CID → rkey**: `bafyrei123... → 3k2akjdlkjsf` 835. **Use rkey** when processing records 84 85## Why This Matters 86 87The rkey is essential for: 88- **AT URI construction**: `at://did:plc:user123/fm.teal.alpha.feed.play/3k2akjdlkjsf` 89- **Record identity**: Uniquely identifies the record within the collection 90- **Data integrity**: Maintains proper AT Protocol addressing 91 92## CLI Usage 93 94```bash 95# Explore CAR file and show rkey extraction 96teal car explore --file archive.car --verbose 97 98# The verbose output will show: 99# 🔑 rkey Extraction Examples: 100# 1. bafyrei123... → rkey: 3k2akjdlkjsf 101# 2. bafyrei456... → rkey: self 102``` 103 104**Note**: Some CAR files may not contain commit operations with rkey mappings, especially if they're partial exports or contain only raw records without repository structure.