ap2

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMandateRequired              = errors.New("mandate_required")
	ErrMandateInvalidSignature      = errors.New("mandate_invalid_signature")
	ErrMandateExpired               = errors.New("mandate_expired")
	ErrMandateScopeMismatch         = errors.New("mandate_scope_mismatch")
	ErrMerchantAuthorizationInvalid = errors.New("merchant_authorization_invalid")
	ErrAgentMissingKey              = errors.New("agent_missing_key")
	ErrMandateMalformed             = errors.New("mandate_malformed")
)

UCP / AP2 error codes, surfaced verbatim (the Error string IS the code).

Functions

func AP2PublicJWKS

func AP2PublicJWKS() ([]map[string]interface{}, error)

AP2PublicJWKS returns every currently-usable public key for JWKS output.

func AP2VerificationKey

func AP2VerificationKey(kid string) (*ecdsa.PublicKey, bool)

AP2VerificationKey resolves one of this tenant's own public keys by kid, including a recently-retired one still inside the rotation overlap. Used to check a merchant_authorization this store produced.

func ActiveAP2SigningKey

func ActiveAP2SigningKey() (kid string, priv *ecdsa.PrivateKey, err error)

ActiveAP2SigningKey returns the current signing key, generating the very first one on demand. The returned kid is what goes in the JWS header.

func LooksLikeMandateJWT

func LooksLikeMandateJWT(token string) bool

LooksLikeMandateJWT reports whether a payment credential token is itself a (SD-)JWT that must be verified, as opposed to an opaque gateway token that is simply forwarded to the charger.

func MerchantAuthorizationJWS

func MerchantAuthorizationJWS(checkout map[string]interface{}) (string, error)

MerchantAuthorizationJWS returns the detached-JWS ap2.merchant_authorization for a checkout object: "<b64url header>..<b64url signature>", the JCS canonical form of the checkout WITH ITS ap2 FIELD REMOVED transmitted separately as the response body itself (RFC 7515 Appendix F).

func RotateAP2SigningKey

func RotateAP2SigningKey() (newKid string, err error)

RotateAP2SigningKey retires every currently-active key (keeping it verifiable for the overlap window) and mints a fresh active one.

func SetStore

func SetStore(get func(key string) string, set func(key, value string) error)

func VerifyMerchantAuthorizationJWS

func VerifyMerchantAuthorizationJWS(checkout map[string]interface{}, detached string) error

VerifyMerchantAuthorizationJWS checks a detached merchant_authorization against this tenant's own JWKS over the JCS form of the given checkout (ap2 field excluded). Used to re-check the authorization a checkout mandate embeds, and by tools/ap2verify.

func VerifyPaymentMandate

func VerifyPaymentMandate(token, checkoutJWT string, opts MandateVerifyOpts) error

VerifyPaymentMandate verifies a payment mandate token and that it is bound to the given checkout JWT (sha-256 of the compact checkout JWT), per the UCP AP2 Mandates Extension. A token that is not a JWT is treated as an opaque gateway token by the caller and never reaches here.

Types

type AP2KeySummary

type AP2KeySummary struct {
	Kid       string     `json:"kid"`
	CreatedAt time.Time  `json:"created_at"`
	RetiredAt *time.Time `json:"retired_at,omitempty"`
	Active    bool       `json:"active"`
}

AP2KeySummary is the read-only view the controller dashboard shows.

func AP2KeySummaries

func AP2KeySummaries() ([]AP2KeySummary, error)

type MandateResult

type MandateResult struct {
	Claims    map[string]interface{}
	IssuerJWT string
	HolderJWK map[string]interface{}
	KeySource string
}

func VerifyCheckoutMandate

func VerifyCheckoutMandate(sdjwt string, opts MandateVerifyOpts) (*MandateResult, error)

VerifyCheckoutMandate verifies an SD-JWT+kb checkout mandate. It does NOT do the AP2 terms match against the live cart - the caller does that with the returned Claims, because only the caller has the recomputed checkout.

type MandateVerifyOpts

type MandateVerifyOpts struct {
	ExpectedAudience string
	PlatformKeys     []map[string]interface{}
	AllowUnpinnedKey bool
	Now              time.Time
	NonceSeen        func(nonce string) (bool, error)
	RememberNonce    func(nonce string) error
}

Jump to

Keyboard shortcuts

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