Help us shape the future of Go! Take the 2026 Go Developer Survey

privy

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Overview

Package privy implements Privy's OAuth device-grant wallet signing protocol.

Index

Constants

View Source
const DefaultAuthURL = "https://auth.privy.io"

Variables

View Source
var (
	ErrAuthorizationPending = errors.New("authorization pending")
	ErrSlowDown             = errors.New("authorization polling slowed")
	ErrExpiredToken         = errors.New("token expired")
	ErrAccessDenied         = errors.New("access denied")
	ErrUnauthorized         = errors.New("unauthorized")
)

Functions

func HexQuantity

func HexQuantity(v uint64) string

HexQuantity converts a nonnegative uint64 to an Ethereum JSON-RPC quantity.

Types

type Call

type Call struct {
	To    string
	Value string
	Data  string
}

Call is one entry of an atomic wallet_sendCalls batch.

type Client

type Client struct {
	AuthURL, AppID string
	HTTP           *http.Client
	Now            func() time.Time
}

func (*Client) Authenticate

func (c *Client) Authenticate(ctx context.Context, accessToken string) (*Session, error)

func (*Client) PollDeviceToken

func (c *Client) PollDeviceToken(ctx context.Context, da *DeviceAuthorization, sleep func(context.Context, time.Duration) error) (*Tokens, error)

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context, refreshToken string) (*Tokens, error)

func (*Client) RevokeGrant

func (c *Client) RevokeGrant(ctx context.Context, accessToken string) error

func (*Client) StartDeviceAuthorization

func (c *Client) StartDeviceAuthorization(ctx context.Context) (*DeviceAuthorization, error)

type DeviceAuthorization

type DeviceAuthorization struct {
	DeviceCode, UserCode, VerificationURI, VerificationURIComplete string
	ExpiresIn, Interval                                            int
}

type Error

type Error struct {
	Status                       int
	Code, Description, RequestID string
	RetryAfter                   string
}

Error contains only safe server metadata. RetryAfter is set for HTTP 429 responses.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

type Session

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

func (*Session) ExpiresAt

func (s *Session) ExpiresAt() time.Time

func (*Session) SendCalls

func (s *Session) SendCalls(ctx context.Context, walletID string, chainID uint64, calls []Call) (string, error)

SendCalls submits an atomic EIP-7702 batch (Privy upgrades the wallet to a Kernel account on first use). It returns Privy's transaction ID, not a chain hash. A successful response means the batch was broadcast; callers must never retry an ambiguous error.

func (*Session) SendTransaction

func (s *Session) SendTransaction(ctx context.Context, walletID string, tx Transaction) (string, error)

func (*Session) SignTypedData

func (s *Session) SignTypedData(ctx context.Context, walletID string, typedData TypedData) ([65]byte, error)

func (*Session) SignedRPC

func (s *Session) SignedRPC(ctx context.Context, walletID string, body any, out any) error

func (*Session) Wallets

func (s *Session) Wallets() []Wallet

type Tokens

type Tokens struct {
	AccessToken, RefreshToken string
	AccessExpiresAt           time.Time
}

type Transaction

type Transaction struct {
	To             string
	Value          string
	Data           string
	ChainID        uint64
	LegacyGasPrice string // when set, send a type-0 transaction
}

Transaction is a Privy OAuth eth_sendTransaction request. Privy signs and broadcasts the transaction; callers must never retry an ambiguous error. Shape follows Privy's published wallet RPC schema (EthereumSendTransactionRpcInput): a required top-level caip2 ("eip155:<chain>") plus params.transaction with chain_id. Verified live on Arbitrum with a funded agent wallet.

type TypedData

type TypedData struct {
	Domain      map[string]any          `json:"domain"`
	Types       map[string][]TypedField `json:"types"`
	PrimaryType string                  `json:"primary_type"`
	Message     map[string]any          `json:"message"`
}

func HyperliquidAgentTypedData

func HyperliquidAgentTypedData(source string, connectionID [32]byte) TypedData

type TypedField

type TypedField struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type Wallet

type Wallet struct {
	ID        string `json:"id"`
	Address   string `json:"address"`
	ChainType string `json:"chain_type"`
}

Jump to

Keyboard shortcuts

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