pair

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pair encodes the {server, relay, token, server_static_pubkey} tuple a paired mobile device needs to connect through the relay back to this binary, and decodes strings produced by the same encoder. Pure functions; no I/O.

The encoded form is a single ASCII string suitable for embedding in a QR symbol or for a one-time paste-fallback display. The wire shape is the JSON serialization of Payload, then base64url-encoded with the URL-safe alphabet and no padding.

The Token field carries the plaintext bearer the mobile client will present back on subsequent connections. Hashing for storage happens elsewhere (internal/devices). Callers MUST NOT log Payload, Encode output, or Decode errors in any context that may persist user-visible output: the device-token is one-time-only and its visibility ends when the QR symbol is dismissed.

The ServerStaticPubkey field is the raw 32-byte X25519 public point of the binary's persistent Noise static keypair, base64-encoded with base64.StdEncoding (standard alphabet, with padding). This alphabet matches the on-disk encoding in internal/keys, so the same bytes have the same string form on disk and in the QR payload.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPayload = errors.New("pair: invalid payload")

ErrInvalidPayload is the sentinel returned (via wrap) for any input Decode rejects. Match with errors.Is; do not match on error strings. Decode error messages describe the failure category only and never include input bytes or decoded field values.

Functions

func Encode

func Encode(p Payload) string

Encode returns the wire-format string for p: JSON marshal, then base64url-encode (URL-safe alphabet, no padding). Encode does NOT validate p — empty fields produce an encoded string Decode will reject. Callers are expected to construct Payload from validated inputs (ServerID minted via identity.NewServerID, token via crypto/rand, relay URL from internal/config).

func Fingerprint added in v0.14.0

func Fingerprint(pubkey [32]byte) string

Fingerprint returns the verifying-string form of pubkey: BLAKE2s-256(pubkey) truncated to 8 bytes, formatted as colon- separated lowercase hex ("aa:bb:cc:dd:ee:ff:11:22"). Exactly 23 characters (8*2 hex digits + 7 colons).

The 8-byte / 64-bit width is load-bearing per docs/protocol-mobile.md § Security review. A 32-bit truncation is brute-forceable (~2^32 preimage search); do not narrow it.

func Render

func Render(p Payload, w io.Writer) error

Render writes a paired-device-friendly representation of p to w:

  1. A QR symbol of Encode(p), drawn with UTF-8 half-block characters (the densest terminal form that scans reliably).
  2. A blank line.
  3. The output of Encode(p) on its own line.
  4. The static-key fingerprint on its own line, formatted as "Static-key fp: aa:bb:... (verify this matches the fingerprint shown on your phone)". The fingerprint is Fingerprint(pubkey) applied to the base64-decoded p.ServerStaticPubkey; if that decoding fails or yields a wrong-length value (only reachable when the caller hand-builds a Payload that Decode would reject), Render emits "Static-key fp: <invalid>" instead of panicking.
  5. A one-line instruction telling the user to either scan the QR with the Pyrycode mobile app or paste the string above into the app's pairing screen.

Render returns the first error encountered while writing to w; on error, w may have received a prefix of the intended output but the error is propagated rather than swallowed. Render does not retry.

Render does not log, persist, or otherwise duplicate the rendered bytes — its output contains the plaintext device-token and is a one-time display surface (see docs/protocol-mobile.md § "Token leak via phone"). Callers MUST NOT log the writer's destination, MUST NOT capture this output into any context that is persisted (CI logs, telemetry, error reports), and MUST treat the calling goroutine's stdout as the only intended sink.

Types

type Payload

type Payload struct {
	Server             identity.ServerID `json:"server"`
	Relay              string            `json:"relay"`
	Token              string            `json:"token"`
	ServerStaticPubkey string            `json:"server_static_pubkey"`
}

Payload is the {server, relay, token, server_static_pubkey} tuple emitted by `pyry pair` and consumed by the paired mobile device.

Field order is fixed by the protocol-mobile.md appendix; do not reorder. All four fields are required; encoders SHOULD reject zero values upstream, decoders MUST (see Decode).

Relay is not parsed/validated by this package; semantic validation belongs to whichever caller dials the URL. Token is not length- or alphabet-checked here; minting contract belongs to the token issuer. ServerStaticPubkey is the base64.StdEncoding-encoded raw 32-byte X25519 public key; Decode rejects any other length.

func Decode

func Decode(s string) (Payload, error)

Decode parses a string produced by Encode back into a Payload.

Errors wrap ErrInvalidPayload (use errors.Is). The error text is a failure-category string only — never input bytes or decoded fields.

Decode returns ErrInvalidPayload-wrapped errors for:

  • input that is not valid base64url (URL-safe alphabet, no padding)
  • decoded bytes that are not a JSON object
  • JSON containing trailing bytes after the top-level object
  • server/relay/token/server_static_pubkey field missing or empty
  • server field not parseable by identity.ParseServerID
  • server_static_pubkey not valid base64.StdEncoding
  • server_static_pubkey decoding to a length other than 32 bytes

On any error the returned Payload is the zero value.

Jump to

Keyboard shortcuts

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