agentic

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package agentic reads the local agentic-wallet config and signs requests as that wallet.

Requests authenticate with the wallet's own HMAC secret rather than the user's bearer token. The signature proves possession of one specific wallet's secret, so a caller can only ever read the wallet it actually holds, and no endpoint has to accept "tell me about wallet X" from an account that merely has access to the platform.

Index

Constants

View Source
const (
	HeaderSubOrg    = "X-KH-Sub-Org"
	HeaderTimestamp = "X-KH-Timestamp"
	HeaderSignature = "X-KH-Signature"
)

Header names carrying the signature. The platform also accepts an optional X-KH-Key-Version to pin secret selection during rotation; it is deliberately not sent, so an unpinned request is verified against every active secret and keeps working through the rotation grace window.

View Source
const ConfigName = "wallet.json"

ConfigName is the file `kh wallet add` writes, mode 0600.

Variables

View Source
var ErrIncompleteConfig = errors.New("agentic wallet config is incomplete")

ErrIncompleteConfig reports a config file that is present but missing a field needed to use it. Distinct from ErrNotConfigured so a caller can say "the file is there and broken" rather than sending someone to re-run the command that already wrote it.

View Source
var ErrNotConfigured = errors.New("no agentic wallet configured")

ErrNotConfigured reports that no agentic wallet exists on this machine. It is a normal state, not a failure: most installs never provision one.

Functions

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the location of the agentic wallet config.

func Sign

func Sign(secret, method, path, subOrgID, body string, timestamp int64) string

Sign returns the hex HMAC-SHA256 over `method\npath\nsubOrgId\nsha256_hex(body)\ntimestamp`, the format the platform verifies. path is the URL pathname only, with no host or query. A GET signs over an empty body.

func SignRequest

func SignRequest(req *http.Request, cfg Config, body string, now time.Time)

SignRequest attaches the signature headers to req.

The signed path is taken from req.URL, never from a caller-supplied constant. The platform signs the pathname it actually received, so a host configured with a path prefix would otherwise produce a signature over a different string and come back 401, which reads as a rotated secret rather than a configuration problem.

body must be the exact bytes sent; a GET signs over an empty string.

Types

type Config

type Config struct {
	SubOrgID      string `json:"subOrgId"`
	WalletAddress string `json:"walletAddress"`
	HMACSecret    string `json:"hmacSecret"`
}

Config is the on-disk agentic wallet. HMACSecret must never be printed or logged; it is the wallet's only credential.

func Load

func Load() (Config, error)

Load reads the agentic wallet config, returning ErrNotConfigured when the file is absent.

func (Config) String

func (c Config) String() string

String renders the config without its secret, so a Config reaching a log line or an error through %v or %s cannot leak the credential. Load is the only thing that reads the secret out; nothing else should print a Config.

Jump to

Keyboard shortcuts

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