tokens

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tokens holds no state and imports only the standard library, so the browser build, which cannot take pkg/logic/common, runs the same code as the desktop. pkg/logic/common keeps the wallet, the session and the reveal loop.

Index

Constants

View Source
const (
	AckPaid       = 1 << 0 // the bridge took the anchor: the pair has priority
	AckContention = 1 << 1 // the bridge is busy: the free lane is being shared
)

The bits of the bridge's one ack byte.

View Source
const (
	CollectTick   = 3 * time.Second
	CollectWindow = 30 * time.Minute
)

The collect schedule. A payment usually lands within two minutes of the buy page opening, so the first two minutes poll at the tick; after that the person is likely still typing card details, or gone. CollectWindow ends it: past it the code still waits on the token service, and on the page Stripe returns to, for a paste.

View Source
const BuyURL = ServiceBase + "/buy"

BuyURL is the buy page without a claim: what a person can type or paste.

View Source
const MaxChainUnits = 1_000_000

MaxChainUnits bounds the units a code may carry.

View Source
const ServiceBase = "https://tokens.keibidrop.com" //nolint:gosec // G101: URL, not a credential

ServiceBase is the token service. Prices live on its buy page and in its pack table, never in a client.

View Source
const UnitBytes int64 = 10 << 20

UnitBytes is the bandwidth one chain step buys. PROTOCOL CONSTANT shared with the relay ledger, the bridge and the token service.

Variables

This section is empty.

Functions

func BuyURLFor

func BuyURLFor(base, claim string) string

BuyURLFor is the buy page that carries claim onto every payment link.

func ChainHash

func ChainHash(seed [32]byte, position int) [32]byte

ChainHash is the chain value at position: seed hashed position times. The anchor is the value at the chain's full length; spending reveals values toward the seed.

func ClaimSurface

func ClaimSurface(claim string) string

ClaimSurface is the surface a claim names, or "" for a bare ref. A bare ref is 22 base64url characters, which may contain '_' themselves, so only a claim longer than that has a surface.

func CollectDelay

func CollectDelay(age, tick time.Duration) time.Duration

CollectDelay is the wait before the next collect poll for a purchase opened age ago, on a schedule scaled by tick (CollectTick in production): the tick for two minutes, three ticks until ten, then ten ticks. An unpaid claim costs the token service about 130 polls over the window instead of 600.

func CollectURL

func CollectURL(base, claim string) string

CollectURL is where the purchase made under claim is picked up as JSON.

func DecodeCode

func DecodeCode(code string) (seed [32]byte, units int, err error)

DecodeCode validates a pasted "KDT1." code (seed, units, checksum).

func EncodeCode

func EncodeCode(seed [32]byte, units int) string

EncodeCode is the pasteable form of a chain.

func NewClaim

func NewClaim(surface string) (string, error)

NewClaim is a fresh one-shot purchase ref: the surface that started the purchase ("desktop", "web", "kd", "cli", "mcp"), an underscore, then 16 random bytes in base64url. The token service stores the claim with the purchase and Stripe shows it as the payment's client_reference_id, so every sale says where it was made. Both accept letters, digits, '-' and '_' only, and at most 200 characters; the surface is cut to lower-case letters and digits so the claim always fits. An empty surface gives the bare random ref that clients before 0.5.0 send.

func PayPreamble

func PayPreamble(anchor [32]byte, token [32]byte) []byte

PayPreamble assembles magic || ver || anchor || tier || token, the single write a funded native leg sends where a free one sends the bare token.

Types

This section is empty.

Jump to

Keyboard shortcuts

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