lease

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 8 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 lease verifies a KeyGrant lease offline: a compact JWS, EdDSA over Ed25519, against the build's key set (the reference's shared crypto.ts verifyLease), and reads its claims as the reference reads them.

Index

Constants

View Source
const (
	Malformed    = "malformed"
	UnknownKey   = "unknown-key"
	BadSignature = "bad-signature"
	BadClaims    = "bad-claims"
	Expired      = "expired"
)

Why a lease did not verify.

View Source
const Issuer = "keygrant"

Issuer is the `iss` every lease carries.

View Source
const OpenMajor = 1_000_000

OpenMajor is the `major` claim of a key with no upper bound.

Variables

This section is empty.

Functions

func Grants

func Grants(ent Entitlements, code string) bool

Grants is whether ent grants code (grants): a flag that is true, a number that is not 0 (a negative counts), a text that is not empty. The code is matched exactly, case included.

func IsID

func IsID(s string) bool

IsID is whether s takes the form of a key id: 1 to 64 characters of the base64url alphabet.

func KeyID

func KeyID(jwk any) (string, error)

KeyID is a public key's id (keyId): the base64url, no padding, of the SHA-256 of {"crv":"Ed25519","kty":"OKP","x":"<x>"} with x written canonically. A kid member the JWK carries is not read.

func NamedKeyID

func NamedKeyID(header, start string) string

NamedKeyID is the key id a header names when it is, byte for byte, canonical base64url of <start><kid>"}, kid 1 to 64 characters of the base64url alphabet; "" for any other header. Matched as bytes, never parsed.

func PublicKeyBytes

func PublicKeyBytes(jwk any) ([]byte, error)

PublicKeyBytes is a public JWK's raw key, checked as every SDK checks one (publicKeyBytes): an object whose kty is "OKP" and crv "Ed25519"; no private d; use, when given, "sig"; key_ops, when given, a list naming "verify"; alg, when given, "EdDSA" or "Ed25519"; and an x that, its trailing "=" dropped, is canonical base64url of 32 bytes. No other member is read.

Types

type Claims

type Claims struct {
	Sub, Product, Aid string
	Fp                *string // the device's fingerprint claim, 1 to 128 UTF-16 units
	Fpk               *string // "machine" or "hostname"
	Model             string  // "perpetual", "subscription" or "trial"
	Lim               float64 // a positive whole number
	Major             float64 // a non-negative whole number, 0 when absent
	MinMajor          *float64
	UpgradeUntil      *float64 // seconds
	Ent               Entitlements
	Met               Meters  // nil when the lease has no `met`
	Iat, Exp          float64 // seconds
	Grace             *bool
	Test              *bool
}

Claims are a lease's claims as a verifier reads them (LeaseClaims). Numbers are doubles, as the reference reads JSON; an optional claim the lease does not carry is nil. Unknown claims are not kept.

func ParseClaims

func ParseClaims(v any) (*Claims, bool)

ParseClaims reads a payload's JSON value as LeaseClaims.parse does, or reports false for one that is not a lease's claims (bad-claims).

func (*Claims) IsTest

func (c *Claims) IsTest() bool

IsTest is whether the lease says it is a test licence's.

type Entitlement

type Entitlement struct {
	Kind   EntitlementKind
	Flag   bool
	Number float64
	Text   string
}

Entitlement is one entitlement's value: a flag, a number (a double, as JSON and JavaScript read one) or a text. Only the field its Kind names is set.

type EntitlementKind

type EntitlementKind int

EntitlementKind is what an entitlement's value is.

const (
	// Flag is a JSON boolean.
	Flag EntitlementKind = iota + 1
	// Number is a JSON number, read as a double.
	Number
	// Text is a JSON string.
	Text
)

type Entitlements

type Entitlements map[string]Entitlement

Entitlements are a lease's `ent`, by name. A Go map has no order; nothing in the SDK reads one, and any listing of them sorts the names.

func EntitlementsOf

func EntitlementsOf(raw any) Entitlements

EntitlementsOf is `ent` as a verifier reads it (entitlementsOf): an object's flag, number and text members, kept as they are; every other member (an object, a list, null) dropped; and none at all from anything but an object. Never a refusal.

type Key

type Key struct {
	Kid    string
	Public ed25519.PublicKey
}

Key is one public key of a key set, with its id (its RFC 7638 thumbprint).

func ImportKeys

func ImportKeys(jwks []any) ([]Key, error)

ImportKeys is a key set (importVerifyingKeys): each public JWK with its id, in the order given, a key given twice kept once. An empty set, or a JWK that is not an Ed25519 public key, is an error.

type Meter

type Meter struct {
	Left    int64
	Total   int64
	Offline int64
	Resets  bool
}

Meter is one meter as a lease signs it (`met`): what the key had left when it was signed, the uses it holds, the allowance each device may spend with no answer, and whether it comes back each billing period.

type Meters

type Meters map[string]Meter

Meters are a lease's `met`, by code.

func MetersOf

func MetersOf(raw any) Meters

MetersOf is `met` as a verifier reads it (metersOf): each member of an object that is an object whose left, total and offline are figures, resets true only for JSON true; every other member dropped; none at all from anything but an object. Never a refusal, and the server's caps are not enforced.

type Result

type Result struct {
	Valid  bool
	Reason string  // "" when valid
	Claims *Claims // the claims of a valid or an expired lease, else nil
}

Result is what verifying a lease says: valid with its claims, or why not, with the claims of a lease that merely expired.

func Verify

func Verify(token string, keys []Key, now int64) Result

Verify verifies a lease offline against a key set at now (ms), as verifyLease does: three parts; a canonical signature; the key the header names (only in the exact form the server writes it), or each key in turn when it names none; Ed25519 over header.payload as received; the claims; then expiry, exp * 1000 < now. The algorithm is the verifier's, never the token's.

Jump to

Keyboard shortcuts

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