Skip to content

Commit

Permalink
feat(core): support pubkey json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dnut committed Dec 19, 2024
1 parent 05ffe86 commit b418ce5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/core/pubkey.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const std = @import("std");
const sig = @import("../sig.zig");

const Allocator = std.mem.Allocator;
const ParseOptions = std.json.ParseOptions;

pub const Pubkey = extern struct {
data: [size]u8,
const Self = @This();
Expand Down Expand Up @@ -54,6 +57,13 @@ pub const Pubkey = extern struct {
) !void {
return base58.format(self.data, writer);
}

pub fn jsonParse(_: Allocator, source: anytype, _: ParseOptions) !Pubkey {
return switch (try source.next()) {
.string => |s| .{ .data = base58.decode(s) catch return error.UnexpectedToken },
else => error.UnexpectedToken,
};
}
};

const Error = error{ InvalidBytesLength, InvalidEncodedLength, InvalidEncodedValue };

0 comments on commit b418ce5

Please sign in to comment.