zat.dev/zds
atproto pds · mirror of https://tangled.org/zat.dev/zds
zds 0.25.1 Latest 2 packages, all images
0
0
const std = @import("std");
const zds = @import("zds");
const Io = std.Io;
var app_threaded_io: Io.Threaded = undefined;
pub const std_options_debug_threaded_io: ?*Io.Threaded = &app_threaded_io;
pub fn main(init: std.process.Init) !void {
const allocator = std.heap.smp_allocator;
app_threaded_io = Io.Threaded.init(allocator, .{});
const io = app_threaded_io.io();
var args = std.process.Args.Iterator.init(init.minimal.args);
_ = args.next();
const authorization = args.next() orelse return usage();
var keypair = try zds.zat.Keypair.fromSecretKey(.p256, @splat(0x42));
if (std.mem.eql(u8, authorization, "kid")) {
std.debug.print("{s}\n", .{try keypair.did(allocator)});
return;
}
if (std.mem.eql(u8, authorization, "accept-signature")) {
const kind = args.next() orelse return usage();
const profile: zds.zat.space.mac.Profile = if (std.mem.eql(u8, kind, "commit")) .commit else if (std.mem.eql(u8, kind, "record")) .record else return usage();
const author_kem_key = args.next() orelse return usage();
const encapsulated = try zds.zat.space.encapsulate(io, allocator, author_kem_key);
std.debug.print("{s}: {s}\nshared-secret: {s}\n", .{
zds.zat.space.mac.request_header,
try zds.zat.space.mac.formatMacRequest(allocator, profile, encapsulated.key_share),
std.fmt.bytesToHex(encapsulated.shared_secret, .lower),
});
return;
}
const audience = args.next() orelse return usage();
const signed = try zds.zat.space.signCredentialUse(allocator, &keypair, authorization, audience);
std.debug.print("signature-input: {s}\nsignature: {s}\natproto-space-audience: {s}\n", .{ signed.signature_input, signed.signature, audience });
}
fn usage() error{InvalidArguments} {
std.debug.print("usage: zds-space-signature kid | accept-signature commit|record AUTHOR_KEM_KEY | AUTHORIZATION AUDIENCE\n", .{});
return error.InvalidArguments;
}