Skip to documentation
SLOP

tiny.reticulum.wire.proof

Reference tiny.reticulum wire proof

Defined in wire.

API (13)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

No direct callersNo direct callswireproof
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsprivate sourcelib.reticulum.src.node.inboundacceptProoftest sourcelib.reticulum.src.packet.proof.test_Reticulum...py:943-953 builds both proof lengthstest sourcelib.reticulum.src.packet.proof.test_Reticulum...py:485-520 validates built proof payl...private sourcelib.reticulum.src.properties.wire.DecoderTotalpropertytest sourcelib.reticulum.src.wire.proof.test_Reticulum@1...py:403-404 rejects other proof lengths+2 morewire.proofdecode
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callspacket.proofdestinationHashtest sourcelib.reticulum.src.wire.proof.test_Reticulum@1...py:381-384 truncates proof destinatio...wire.proofdestinationHash
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsprivate sourcelib.reticulum.src.node.testsignedProofFramepacket.proofbuildprivate sourcelib.reticulum.src.properties.link.Layoutspropertytest sourcelib.reticulum.src.wire.proof.test_Reticulum@1...py:403-404 splits and joins both proo...private sourcelib.reticulum.src.wire.testexpectLinkProofwire.proofencodedLengthwire.proofencode
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callswire.proofencodewire.proofencodedLength
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/reticulum/src/wire/proof.zig

zig
const std = @import("std");/// 32 bytes, the width of the packet hash a proof (the signed reply that tells/// a sender its packet arrived) signs, for sizing the hash, following/// Reticulum@1.5.0 RNS/Packet.py:403.pub const packet_hash_bytes: u16 = 32;/// 64 bytes, the width of the Ed25519 signature a proof carries, for sizing the/// signature, following Reticulum@1.5.0 RNS/Packet.py:403-404.pub const signature_bytes: u16 = 64;/// 96 bytes, a proof payload that carries the proved packet's hash ahead of the/// signature, for sizing or recognizing the longer of the two proof payloads,/// following Reticulum@1.5.0 RNS/Packet.py:403.pub const explicit_bytes: u16 = packet_hash_bytes + signature_bytes;/// 64 bytes, a proof payload that carries the signature alone, which the/// receiver matches against a packet it is already waiting on, for sizing or/// recognizing the shorter of the two proof payloads, following Reticulum@1.5.0/// RNS/Packet.py:404.pub const implicit_bytes: u16 = signature_bytes;pub const Explicit = struct {    packet_hash: [packet_hash_bytes]u8,    signature: [signature_bytes]u8,};pub const Implicit = struct {    signature: [signature_bytes]u8,};pub const Proof = union(enum) {    explicit: Explicit,    implicit: Implicit,};pub const DecodeError = error{InvalidLength};pub const EncodeError = error{OutputTooSmall};/// Splits a proof payload into its pieces, and its length decides the form: 96/// bytes give a hash and a signature, and 64 give a signature, following/// Reticulum@1.5.0 RNS/Packet.py:403-404. The call returns/// `error.InvalidLength` for every other length.pub fn decode(bytes: []const u8) DecodeError!Proof {    return switch (bytes.len) {        explicit_bytes => .{ .explicit = .{            .packet_hash = bytes[0..packet_hash_bytes].*,            .signature = bytes[packet_hash_bytes..explicit_bytes].*,        } },        implicit_bytes => .{ .implicit = .{            .signature = bytes[0..implicit_bytes].*,        } },        else => error.InvalidLength,    };}pub fn encodedLength(value: Proof) u16 {    return switch (value) {        .explicit => explicit_bytes,        .implicit => implicit_bytes,    };}/// Writes a built proof payload into `out` for sending and returns the bytes/// written, following Reticulum@1.5.0 RNS/Packet.py:403-404. The call returns/// `error.OutputTooSmall` when `out` is shorter than the payload.pub fn encode(value: Proof, out: []u8) EncodeError![]u8 {    const length: usize = encodedLength(value);    if (out.len < length) return error.OutputTooSmall;    switch (value) {        .explicit => |explicit| {            std.mem.copyForwards(u8, out[0..packet_hash_bytes], &explicit.packet_hash);            std.mem.copyForwards(                u8,                out[packet_hash_bytes..explicit_bytes],                &explicit.signature,            );        },        .implicit => |implicit| {            std.mem.copyForwards(u8, out[0..implicit_bytes], &implicit.signature);        },    }    return out[0..length];}/// Returns the first 16 bytes of a proved packet's hash as the destination for/// addressing the proof packet sent back, following Reticulum@1.5.0/// RNS/Packet.py:381-384.pub fn destinationHash(packet_hash: [packet_hash_bytes]u8) [16]u8 {    return packet_hash[0..16].*;}test "Reticulum@1.5.0 RNS/Packet.py:403-404 splits and joins both proof forms" {    var explicit_raw: [explicit_bytes]u8 = undefined;    for (&explicit_raw, 0..) |*byte, index| byte.* = @intCast(index);    const explicit = try decode(&explicit_raw);    var explicit_out: [explicit_bytes]u8 = undefined;    try std.testing.expectEqualSlices(u8, &explicit_raw, try encode(explicit, &explicit_out));    var implicit_raw: [implicit_bytes]u8 = undefined;    for (&implicit_raw, 0..) |*byte, index| byte.* = @intCast(index);    const implicit = try decode(&implicit_raw);    var implicit_out: [implicit_bytes]u8 = undefined;    try std.testing.expectEqualSlices(u8, &implicit_raw, try encode(implicit, &implicit_out));}test "Reticulum@1.5.0 RNS/Packet.py:381-384 truncates proof destinations" {    var packet_hash: [packet_hash_bytes]u8 = undefined;    for (&packet_hash, 0..) |*byte, index| byte.* = @intCast(index);    try std.testing.expectEqualSlices(u8, packet_hash[0..16], &destinationHash(packet_hash));}test "Reticulum@1.5.0 RNS/Packet.py:403-404 rejects other proof lengths" {    var bytes: [explicit_bytes + 1]u8 = @splat(0);    try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. implicit_bytes - 1]));    try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. implicit_bytes + 1]));    try std.testing.expectError(error.InvalidLength, decode(bytes[0 .. explicit_bytes - 1]));    try std.testing.expectError(error.InvalidLength, decode(&bytes));}

Source: lib/reticulum/src/wire/root.zig:53

zig
pub const proof = @import("proof.zig");

Complete caller list for wire.proof.decode

7 direct callers.

Audit

Definitions13
Public names14
Members7
Version26.7.0
Revisiondaab053ee433