Resolve AT Protocol DIDs, handles, and schemas with intelligent caching for Laravel
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update README.md

+41 -15
+41 -15
README.md
··· 39 39 $handle = $document->getHandle(); // "user.bsky.social" 40 40 $pds = $document->getPdsEndpoint(); // "https://bsky.social" 41 41 42 - // Resolve a handle to its DID 43 - $did = Beacon::resolveHandle('user.bsky.social'); 42 + // Convert a handle to its DID 43 + $did = Beacon::handleToDid('user.bsky.social'); 44 44 // "did:plc:ewvi7nxzyoun6zhxrhs64oiz" 45 + 46 + // Resolve any identity (DID or handle) to a document 47 + $document = Beacon::resolveIdentity('alice.bsky.social'); 45 48 46 49 // Find someone's PDS endpoint 47 50 $pds = Beacon::resolvePds('alice.bsky.social'); ··· 83 86 84 87 ### Resolving Handles 85 88 86 - Convert human-readable handles to DIDs: 89 + Convert human-readable handles to DIDs or DID documents: 87 90 88 91 ```php 89 - $did = Beacon::resolveHandle('alice.bsky.social'); 92 + // Convert handle to DID string 93 + $did = Beacon::handleToDid('alice.bsky.social'); 90 94 // "did:plc:ewvi7nxzyoun6zhxrhs64oiz" 91 95 92 - // Get the full DID document 93 - $document = Beacon::resolveHandleToDid('alice.bsky.social'); 96 + // Resolve handle to full DID document 97 + $document = Beacon::resolveHandle('alice.bsky.social'); 98 + $handle = $document->getHandle(); 99 + $pds = $document->getPdsEndpoint(); 100 + ``` 101 + 102 + ### Resolving Identities 103 + 104 + Automatically detect and resolve either DIDs or handles: 105 + 106 + ```php 107 + // Works with DIDs 108 + $document = Beacon::resolveIdentity('did:plc:ewvi7nxzyoun6zhxrhs64oiz'); 109 + 110 + // Works with handles 111 + $document = Beacon::resolveIdentity('alice.bsky.social'); 112 + 113 + // Perfect for user input where type is unknown 114 + $actor = $request->input('actor'); // Could be DID or handle 115 + $document = Beacon::resolveIdentity($actor); 94 116 ``` 95 117 96 118 ### Finding PDS Endpoints ··· 133 155 134 156 ```php 135 157 $document = Beacon::resolveDid('did:plc:abc123', useCache: false); 136 - $did = Beacon::resolveHandle('alice.bsky.social', useCache: false); 158 + $did = Beacon::handleToDid('alice.bsky.social', useCache: false); 159 + $document = Beacon::resolveIdentity('alice.bsky.social', useCache: false); 137 160 $pds = Beacon::resolvePds('alice.bsky.social', useCache: false); 138 161 ``` 139 162 ··· 260 283 } 261 284 262 285 try { 263 - $did = Beacon::resolveHandle('invalid-handle'); 286 + $did = Beacon::handleToDid('invalid-handle'); 264 287 } catch (HandleResolutionException $e) { 265 288 // Handle handle resolution errors 266 289 } ··· 285 308 ```php 286 309 // Resolve multiple handles efficiently (caching kicks in) 287 310 $dids = collect(['alice.bsky.social', 'bob.bsky.social']) 288 - ->map(fn($handle) => Beacon::resolveHandle($handle)) 311 + ->map(fn($handle) => Beacon::handleToDid($handle)) 289 312 ->all(); 290 313 ``` 291 314 ··· 293 316 294 317 ```php 295 318 // Get complete identity information 296 - $document = Beacon::resolveHandleToDid($username); 319 + $document = Beacon::resolveIdentity($username); 297 320 298 321 $profile = [ 299 322 'did' => $document->id, ··· 309 332 use SocialDept\Beacon\Facades\Beacon; 310 333 311 334 // Validate user input before resolving 312 - $userInput = request()->input('identifier'); 335 + $actor = request()->input('actor'); 313 336 314 - if (Identity::isHandle($userInput)) { 315 - $did = Beacon::resolveHandle($userInput); 316 - } elseif (Identity::isDid($userInput)) { 317 - $document = Beacon::resolveDid($userInput); 337 + if (Identity::isHandle($actor) || Identity::isDid($actor)) { 338 + $document = Beacon::resolveIdentity($actor); 318 339 } else { 319 340 abort(422, 'Invalid handle or DID'); 341 + } 342 + 343 + // Or convert handle to DID 344 + if (Identity::isHandle($actor)) { 345 + $did = Beacon::handleToDid($actor); 320 346 } 321 347 ``` 322 348