atproto utils for zig
Something went wrong. Try again.
12345678910111213141516171819202122232425262728//! parse and validate atproto identifiers: at:// URIs, DIDs, handles.//!//! run: zig build example-parse-identifiers
const std = @import("std");const zat = @import("zat");
pub fn main() void { // an at:// URI addresses a record: authority / collection / rkey. // this one points at a post by jcsalterego.bsky.social. const at_uri = "at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3mpk2wua4jc2x"; const uri = zat.AtUri.parse(at_uri).?; std.debug.print("{s:<14}{s}\n", .{ "authority:", uri.authority() }); std.debug.print("{s:<14}{s}\n", .{ "collection:", uri.collection().? }); std.debug.print("{s:<14}{s}\n", .{ "rkey:", uri.rkey().? });
const did = zat.Did.parse("did:plc:vc7f4oafdgxsihk4cry2xpze").?; std.debug.print("{s:<14}{t}\n", .{ "did method:", did.method() });
// Handle.parse returns null for invalid input std.debug.print("{s:<14}{s}\n", .{ "bsky.app:", validity("bsky.app") }); std.debug.print("{s:<14}{s}\n", .{ "not a handle:", validity("not a handle") });}
fn validity(handle: []const u8) []const u8 { return if (zat.Handle.parse(handle) != null) "valid" else "invalid";}