address

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package address implements Freizone's self-certifying account addressing scheme: a bech32m-derived identifier computed from the SHA-256 hash of an account's root Ed25519 public key.

Index

Constants

View Source
const CurrentVersion = 0

CurrentVersion is the version marker of an account address: SHA-256 root-key hash, bech32m checksum.

View Source
const (

	// PrefixLength is the number of leading characters of an id that a
	// server enforces unique among its own accounts (see docs/PROTOCOL.md's
	// id-prefix uniqueness note): the version marker plus 4 real characters
	// of entropy. Matches FormatForDisplay's first group size exactly.
	PrefixLength = 5
)
View Source
const VersionGroup = 1

VersionGroup is the version marker of a group id (SRV-01). A group id is derived exactly like an account id -- same hash, same truncation, same checksum, same normalization -- over the group's root key instead of an account's, and is told apart from an account id by this marker alone. That costs no new encoding logic and makes the two impossible to confuse.

Variables

This section is empty.

Functions

func DecodeBech32m

func DecodeBech32m(s string) (hrp string, data []int, err error)

DecodeBech32m decodes a bech32m string, verifies its checksum, and returns the human-readable part and the data values (with the checksum stripped).

func DeriveID

func DeriveID(rootPubKey ed25519.PublicKey) (string, error)

DeriveID computes the self-certifying account address for a root public key: bech32m(SHA-256(rootPubKey) truncated to 70 bits, prefixed with a 5-bit version marker), with no human-readable prefix or separator -- a plain 21-character string (15 payload + 6 checksum).

func DeriveIDVersion added in v0.12.0

func DeriveIDVersion(version int, rootPubKey ed25519.PublicKey) (string, error)

DeriveIDVersion is DeriveID with an explicit version marker, so the same derivation can mint both account ids (CurrentVersion) and group ids (VersionGroup).

func EncodeBech32m

func EncodeBech32m(hrp string, data []int) (string, error)

EncodeBech32m encodes hrp and a sequence of 5-bit values (0-31, without a checksum) into a full bech32m string "hrp1<data><checksum>".

func FormatForDisplay

func FormatForDisplay(id string) string

FormatForDisplay inserts hyphens every 5 characters for readability. It is purely cosmetic: the canonical form used in storage, URLs, and comparisons has no separators. 5 (not 4) is deliberate: the first char is always the version marker (see CurrentVersion), so a 5-char first group carries 4 real characters of entropy -- and happens to split the 15-char payload into exactly 3 even groups, leaving only the 6-char checksum tail uneven.

func Normalize

func Normalize(id string) (string, error)

Normalize strips cosmetic separators/whitespace, lowercases, and validates an address's length, character set, and checksum -- without needing the corresponding public key. It returns the canonical 21-character form.

func StripSeparators

func StripSeparators(id string) string

StripSeparators removes cosmetic dashes/whitespace and lowercases id, without validating its length or checksum. Shared by Normalize (which additionally enforces the full 21-character form) and any caller that also needs to recognize the shorter, unchecksummed PrefixLength form.

func ValidCharset

func ValidCharset(s string) bool

ValidCharset reports whether every character in s belongs to the bech32m charset -- useful for validating a short id-prefix, which (unlike a full id) carries no checksum of its own to catch typos.

func Verify

func Verify(id string, rootPubKey ed25519.PublicKey) (bool, error)

Verify reports whether id is the correct, self-certifying account address for rootPubKey.

func VerifyVersion added in v0.12.0

func VerifyVersion(version int, id string, rootPubKey ed25519.PublicKey) (bool, error)

VerifyVersion is Verify for an explicit version marker -- VersionGroup to check a group id against its group root key.

func VersionOf added in v0.12.0

func VersionOf(id string) (int, error)

VersionOf returns the version marker of an id: CurrentVersion for an account address, VersionGroup for a group id. The id is normalized (and so checksum-validated) first, since a marker read off an unvalidated string says nothing.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL