+
+
+# besolve — resolve a bluesky/atproto handle to a `did:plc`
+
+Small shell script to hit the bsky api (this endpoint does not require
+auth) to resolve atproto handles to `did:plc` identifiers.
+
+``` bash
+./besolve.sh
+```
+
+ Usage: ./besolve.sh <handle>
+
+``` bash
+./besolve.sh hrbrmstr.dev
+```
+
+ did:plc:hgyzg2hn6zxpqokmp5c2xrdo
+
+``` bash
+./besolve.sh @hrbrmstr.dev
+```
+
+ did:plc:hgyzg2hn6zxpqokmp5c2xrdo
+---
+format: gfm
+engine: knitr
+---
+
+# besolve — resolve a bluesky/atproto handle to a `did:plc`
+
+Small Bash script to hit the bsky api (this endpoint does not require auth) to resolve atproto handles to `did:plc` identifiers.
+
+```{bash, error=TRUE}
+./besolve.sh
+```
+
+```{bash}
+./besolve.sh hrbrmstr.dev
+```
+
+```{bash}
+./besolve.sh @hrbrmstr.dev
+```
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+# Function to resolve Bluesky handle to DID:PLC
+resolve_bluesky_handle() {
+ local handle="${1:-}"
+
+ # Remove leading '@' if present
+ handle=$(echo "${handle}" | sed -e 's/^@//')
+
+ # Check if curl is installed
+ if ! command -v curl &>/dev/null; then
+ echo "Error: curl is not installed."
+ return 1
+ fi
+
+ # Check if jq is installed
+ if ! command -v jq &>/dev/null; then
+ echo "Error: jq is not installed."
+ return 1
+ fi
+
+ api_url="https://bsky.social/xrpc/com.atproto.identity.resolveHandle"
+ response=$(curl --silent --header "Accept: application/json" "${api_url}?handle=${handle}")
+
+ # Check if the curl command was successful
+ if [[ $? -ne 0 ]]; then
+ echo "Error: Failed to fetch data from Bluesky API."
+ return 1
+ fi
+
+ # Extract the DID from the response
+ did=$(echo "${response}" | jq -r '.did')
+
+ # Check if jq command was successful
+ if [[ $? -ne 0 ]]; then
+ echo "Error: Failed to parse JSON response."
+ return 1
+ fi
+
+ # Check if DID is empty
+ if [[ -z "${did}" ]]; then
+ echo "Error: DID not found in the response."
+ return 1
+ fi
+
+ echo "${did}"
+}
+
+# Check if exactly one argument is provided
+if [[ $# -ne 1 ]]; then
+ echo "Usage: $0 <handle>"
+ exit 1
+fi
+
+resolve_bluesky_handle "${1}"