coinbase

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package coinbase provides a client for Coinbase Developer Platform APIs, scoped to the surfaces this repo currently consumes (Onramp order status). Authentication uses CDP API keys signed with Ed25519 (EdDSA), regenerated per request — see auth.go.

Index

Constants

View Source
const (

	// DefaultHost is the host serving the Onramp API. Override via
	// Client.Host for staging or to pin to a different region.
	DefaultHost = "api.cdp.coinbase.com"
)

Variables

View Source
var ErrOrderNotFound = errors.New("coinbase order not found")

ErrOrderNotFound is returned when the requested order ID isn't present in the authenticated CDP project.

Functions

This section is empty.

Types

type Amount

type Amount struct {
	Value    string // Decimal string — preserve precision
	Currency string
}

Amount mirrors Coinbase's value/currency object.

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator mints per-request CDP JWTs. Construct one per process and share it — there is no per-request state.

func NewAuthenticator

func NewAuthenticator(keyID string, privateKey ed25519.PrivateKey) (*Authenticator, error)

NewAuthenticator constructs an Authenticator from a CDP key ID and an Ed25519 private key. The private key must be a 64-byte ed25519 seed+public key (the form returned by ed25519.GenerateKey / ed25519.NewKeyFromSeed).

func (*Authenticator) JWT

func (a *Authenticator) JWT(method, host, path string) (string, error)

JWT returns a freshly signed bearer token for the given request. The host must not include a scheme (e.g. "api.developer.coinbase.com"), and path must include the leading slash. Per CDP's spec the `uri` claim binds the JWT to a single METHOD+HOST+PATH combination, so reuse across requests will fail.

type Client

type Client struct {

	// Host is the API host (no scheme, no trailing slash). Defaults to
	// DefaultHost. The same host is used for the JWT `uri` claim, so changing
	// it must match the actual server.
	Host string
	// contains filtered or unexported fields
}

Client talks to the Coinbase Developer Platform Onramp API. Construct via NewClient and share across goroutines — http.Client and the Authenticator are both safe for concurrent use.

func NewClient

func NewClient(auth *Authenticator) *Client

func (*Client) GetOrder

func (c *Client) GetOrder(ctx context.Context, orderID string) (*Order, error)

GetOrder returns the Onramp order with the given order ID. Returns ErrOrderNotFound if the order isn't present in the authenticated CDP project.

type Fee

type Fee struct {
	Type   FeeType
	Amount Amount
}

type FeeType

type FeeType string
const (
	FeeTypeNetwork  FeeType = "FEE_TYPE_NETWORK"
	FeeTypeExchange FeeType = "FEE_TYPE_EXCHANGE"
)

type Order

type Order struct {
	OrderID            string // UUID assigned by Coinbase
	Status             OrderStatus
	PaymentTotal       Amount // Total charged to the buyer, including fees
	PaymentSubtotal    Amount // Charge before fees
	PaymentMethod      PaymentMethod
	PurchaseAmount     Amount // Amount of the purchased asset delivered
	Fees               []Fee
	ExchangeRate       string
	DestinationAddress string
	DestinationNetwork string
	TxHash             string // Empty until on-chain settlement
	PartnerUserRef     string // Stable per-user reference supplied by us at widget init
	CreatedAt          time.Time
	UpdatedAt          time.Time
}

Order is a Coinbase Onramp order as returned by the v2 API.

type OrderStatus

type OrderStatus string
const (
	OrderStatusUnknown        OrderStatus = ""
	OrderStatusPendingAuth    OrderStatus = "ONRAMP_ORDER_STATUS_PENDING_AUTH"
	OrderStatusPendingPayment OrderStatus = "ONRAMP_ORDER_STATUS_PENDING_PAYMENT"
	OrderStatusProcessing     OrderStatus = "ONRAMP_ORDER_STATUS_PROCESSING"
	OrderStatusCompleted      OrderStatus = "ONRAMP_ORDER_STATUS_COMPLETED"
	OrderStatusFailed         OrderStatus = "ONRAMP_ORDER_STATUS_FAILED"
)

type PaymentMethod

type PaymentMethod string
const (
	PaymentMethodApplePay  PaymentMethod = "GUEST_CHECKOUT_APPLE_PAY"
	PaymentMethodGooglePay PaymentMethod = "GUEST_CHECKOUT_GOOGLE_PAY"
)

Jump to

Keyboard shortcuts

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