lib/reticulum/src/identity/rotating.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const std = @import("std");
 2 const reticulum = @import("../root.zig");
 3 
 4 const X25519 = std.crypto.dh.X25519;
 5 
 6 pub const Rotating = struct {
 7     /// Returns the X25519 public bytes for a rotating private key so a
 8     /// destination can publish them, following Reticulum@1.5.0
 9     /// RNS/Identity.py:400-401.
10     pub fn publicBytes(private: [32]u8) [32]u8 {
11         return X25519.recoverPublicKey(private) catch unreachable;
12     }
13 
14     /// Returns the first 10 bytes of the SHA-256 digest of a rotating public
15     /// key, which names it so a receiver says which key opened a message,
16     /// following Reticulum@1.5.0 RNS/Identity.py:396-397.
17     pub fn id(public: [32]u8) [reticulum.hash.name_bytes]u8 {
18         return reticulum.hash.name(&public);
19     }
20 };