summary history branches tags files
commit:69d1687a545f3f0c3d17a25384925b96babe5083
author:hrbrmstr
committer:hrbrmstr
date:Thu Jul 18 06:04:20 2024 -0400
parents:
chore: initial commit
diff --git a/README.md b/README.md
line changes: +24/-0
index 0000000..f830a5c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,24 @@
+
+
+# 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

diff --git a/README.qmd b/README.qmd
line changes: +20/-0
index 0000000..77b54e5
--- /dev/null
+++ b/README.qmd
@@ -0,0 +1,20 @@
+---
+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
+```

diff --git a/besolve.sh b/besolve.sh
line changes: +57/-0
index 0000000..42e67fc
--- /dev/null
+++ b/besolve.sh
@@ -0,0 +1,57 @@
+#!/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}"