zig pds
0

Configure Feed

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

Resolve external handles

+24 -5
+21 -5
src/atproto/identity.zig
··· 130 130 } 131 131 132 132 pub fn resolveHandle(request: *http.Server.Request) !void { 133 + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); 134 + defer arena.deinit(); 135 + const allocator = arena.allocator(); 136 + 133 137 var handle_buf: [256]u8 = undefined; 134 - const handle = http_api.queryParam(request.head.target, "handle", &handle_buf) orelse { 138 + const handle_param = http_api.queryParam(request.head.target, "handle", &handle_buf) orelse { 135 139 return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Missing handle"); 136 140 }; 141 + const handle = std.mem.trim(u8, handle_param, &std.ascii.whitespace); 142 + if (handle.len == 0) { 143 + return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Missing handle"); 144 + } 145 + 137 146 const did = if (store.resolveRepo(handle)) |account| 138 147 account.did 139 148 else if (std.ascii.eqlIgnoreCase(handle, "mod-authority.test")) 140 149 "did:plc:ar7c4by46qjdydhdevvrndac" 141 - else 142 - return http_api.xrpcError(request, .bad_request, "InvalidRequest", "Handle not found"); 150 + else did: { 151 + const parsed_handle = zat.Handle.parse(handle) orelse { 152 + return http_api.xrpcError(request, .bad_request, "InvalidHandle", "Invalid handle format"); 153 + }; 154 + var resolver = zat.HandleResolver.init(store.currentIo(), allocator); 155 + defer resolver.deinit(); 156 + break :did resolver.resolve(parsed_handle) catch { 157 + return http_api.xrpcError(request, .not_found, "HandleNotFound", "Unable to resolve handle"); 158 + }; 159 + }; 143 160 144 - var body_buf: [320]u8 = undefined; 145 - const body = try std.fmt.bufPrint(&body_buf, "{{\"did\":{f}}}", .{std.json.fmt(did, .{})}); 161 + const body = try std.fmt.allocPrint(allocator, "{{\"did\":{f}}}", .{std.json.fmt(did, .{})}); 146 162 return http_api.json(request, .ok, body); 147 163 } 148 164
+3
tools/smoke.sh
··· 46 46 sqlite3 "$db" "insert into accounts (did, handle, email, password_hash, activated_at, email_confirmed_at) values ('did:plc:smoketest', 'smoke.test', 'smoke@test.com', 'password', unixepoch(), unixepoch())" 47 47 sqlite3 "$db" "insert into oauth_requests (request_id, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method, login_hint, expires_at) values ('smoke-oauth', 'https://client.example/oauth-client.json', 'https://client.example/callback', 'repo:*?action=create blob:*/*', 'state', 'challenge', 'S256', 'smoke.test', unixepoch() + 600)" 48 48 49 + resolved=$(curl -fsS "$base/xrpc/com.atproto.identity.resolveHandle?handle=smoke.test") 50 + printf '%s' "$resolved" | grep -q '"did":"did:plc:smoketest"' 51 + 49 52 session=$(curl -fsS -X POST "$base/xrpc/com.atproto.server.createSession" \ 50 53 -H 'content-type: application/json' \ 51 54 --data '{"identifier":"smoke.test","password":"password"}')