···
ApiResponse, Object, OpenApi, OpenApiService, param::Query, payload::Json, types::Example,
28
+
fn example_handle() -> String {
29
+
"bad-example.com".to_string()
fn example_did() -> String {
"did:plc:hdhoaan3xa3jiuq4fg4mefid".to_string()
···
48
+
fn example_pds() -> String {
49
+
"https://porcini.us-east.host.bsky.network".to_string()
51
+
fn example_signing_key() -> String {
52
+
"zQ3shpq1g134o7HGDb86CtQFxnHqzx5pZWknrVX2Waum3fF6j".to_string()
···
70
-
fn bad_request_handler(err: poem::Error) -> GetRecordResponse {
79
+
fn bad_request_handler_get_record(err: poem::Error) -> GetRecordResponse {
GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject {
81
+
error: "InvalidRequest".to_string(),
82
+
message: format!("Bad request, here's some info that maybe should not be exposed: {err}"),
86
+
fn bad_request_handler_resolve_mini(err: poem::Error) -> ResolveMiniIDResponse {
87
+
ResolveMiniIDResponse::BadRequest(Json(XrpcErrorResponseObject {
error: "InvalidRequest".to_string(),
message: format!("Bad request, here's some info that maybe should not be exposed: {err}"),
···
111
-
#[oai(bad_request_handler = "bad_request_handler")]
127
+
#[oai(bad_request_handler = "bad_request_handler_get_record")]
···
147
+
#[oai(example = true)]
148
+
struct MiniDocResponseObject {
149
+
/// DID, bi-directionally verified if a handle was provided in the query.
151
+
/// The validated handle of the account or `handle.invalid` if the handle
152
+
/// did not bi-directionally match the DID document.
154
+
/// The identity's PDS URL
156
+
/// The atproto signing key publicKeyMultibase
158
+
/// Legacy key encoding not supported. the key is returned directly; `id`,
159
+
/// `type`, and `controller` are omitted.
160
+
signing_key: String,
162
+
impl Example for MiniDocResponseObject {
163
+
fn example() -> Self {
165
+
did: example_did(),
166
+
handle: example_handle(),
167
+
pds: example_pds(),
168
+
signing_key: example_signing_key(),
173
+
#[derive(ApiResponse)]
174
+
#[oai(bad_request_handler = "bad_request_handler_resolve_mini")]
175
+
enum ResolveMiniIDResponse {
176
+
/// Identity resolved
177
+
#[oai(status = 200)]
178
+
Ok(Json<MiniDocResponseObject>),
179
+
/// Bad request or identity not resolved
180
+
#[oai(status = 400)]
181
+
BadRequest(XrpcError),
cache: HybridCache<String, CachedRecord>,
···
280
+
/// com.bad-example.identity.resolveMiniDoc
282
+
/// Like [com.atproto.identity.resolveIdentity](https://docs.bsky.app/docs/api/com-atproto-identity-resolve-identity)
283
+
/// but instead of the full `didDoc` it returns an atproto-relevant subset.
284
+
#[oai(path = "/com.bad-example.identity.resolveMiniDoc", method = "get")]
285
+
async fn resolve_mini_id(
287
+
/// Handle or DID to resolve
288
+
#[oai(example = "example_handle")]
289
+
Query(identifier): Query<String>,
290
+
) -> ResolveMiniIDResponse {
291
+
let invalid = |reason: &'static str| {
292
+
ResolveMiniIDResponse::BadRequest(xrpc_error("InvalidRequest", reason))
295
+
let mut unverified_handle = None;
296
+
let did = match Did::new(identifier.clone()) {
299
+
let Ok(alleged_handle) = Handle::new(identifier) else {
300
+
return invalid("identifier was not a valid DID or handle");
302
+
if let Ok(res) = self.identity.handle_to_did(alleged_handle.clone()).await {
303
+
if let Some(did) = res {
305
+
unverified_handle = Some(alleged_handle);
308
+
return invalid("Could not resolve handle identifier to a DID");
311
+
// TODO: ServerError not BadRequest
312
+
return invalid("errored while trying to resolve handle to DID");
316
+
let Ok(partial_doc) = self.identity.did_to_partial_mini_doc(&did).await else {
317
+
return invalid("failed to get DID doc");
319
+
let Some(partial_doc) = partial_doc else {
320
+
return invalid("failed to find DID doc");
323
+
// ok so here's where we're at:
325
+
// ✅ we have a partial doc
326
+
// 🔶 if we have a handle, it's from the `identifier` (user-input)
327
+
// -> then we just need to compare to the partial doc to confirm
328
+
// -> else we need to resolve the DID doc's to a handle and check
329
+
let handle = if let Some(h) = unverified_handle {
330
+
if h == partial_doc.unverified_handle {
333
+
"handle.invalid".to_string()
336
+
let Ok(handle_did) = self
338
+
.handle_to_did(partial_doc.unverified_handle.clone())
341
+
return invalid("failed to get did doc's handle");
343
+
let Some(handle_did) = handle_did else {
344
+
return invalid("failed to resolve did doc's handle");
346
+
if handle_did == did {
347
+
partial_doc.unverified_handle.to_string()
349
+
"handle.invalid".to_string()
353
+
ResolveMiniIDResponse::Ok(Json(MiniDocResponseObject {
354
+
did: did.to_string(),
356
+
pds: partial_doc.pds,
357
+
signing_key: partial_doc.signing_key,
async fn get_record_impl(