guard

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

sequence-guard v0.5.0 29ecf507c86c5d53ab537783a32c1e8edf15d37f -- Code generated by webrpc-gen@v0.25.3 with golang generator. DO NOT EDIT.

webrpc-gen -schema=guard.ridl -target=golang -pkg=proto -client -out=./clients/guard.gen.go

Index

Constants

View Source
const DefaultGuardServiceURL = "https://guard.sequence.app"
View Source
const GuardPathPrefix = "/rpc/Guard/"
View Source
const WebrpcHeader = "Webrpc"
View Source
const WebrpcHeaderValue = "webrpc@v0.25.3;gen-golang@v0.18.4;sequence-guard@v0.5.0"

Variables

View Source
var (
	HTTPClientRequestHeadersCtxKey = &contextKey{"HTTPClientRequestHeaders"}
	HTTPRequestCtxKey              = &contextKey{"HTTPRequest"}

	ServiceNameCtxKey = &contextKey{"ServiceName"}

	MethodNameCtxKey = &contextKey{"MethodName"}
)
View Source
var (
	ErrWebrpcEndpoint           = WebRPCError{Code: 0, Name: "WebrpcEndpoint", Message: "endpoint error", HTTPStatus: 400}
	ErrWebrpcRequestFailed      = WebRPCError{Code: -1, Name: "WebrpcRequestFailed", Message: "request failed", HTTPStatus: 400}
	ErrWebrpcBadRoute           = WebRPCError{Code: -2, Name: "WebrpcBadRoute", Message: "bad route", HTTPStatus: 404}
	ErrWebrpcBadMethod          = WebRPCError{Code: -3, Name: "WebrpcBadMethod", Message: "bad method", HTTPStatus: 405}
	ErrWebrpcBadRequest         = WebRPCError{Code: -4, Name: "WebrpcBadRequest", Message: "bad request", HTTPStatus: 400}
	ErrWebrpcBadResponse        = WebRPCError{Code: -5, Name: "WebrpcBadResponse", Message: "bad response", HTTPStatus: 500}
	ErrWebrpcServerPanic        = WebRPCError{Code: -6, Name: "WebrpcServerPanic", Message: "server panic", HTTPStatus: 500}
	ErrWebrpcInternalError      = WebRPCError{Code: -7, Name: "WebrpcInternalError", Message: "internal error", HTTPStatus: 500}
	ErrWebrpcClientDisconnected = WebRPCError{Code: -8, Name: "WebrpcClientDisconnected", Message: "client disconnected", HTTPStatus: 400}
	ErrWebrpcStreamLost         = WebRPCError{Code: -9, Name: "WebrpcStreamLost", Message: "stream lost", HTTPStatus: 400}
	ErrWebrpcStreamFinished     = WebRPCError{Code: -10, Name: "WebrpcStreamFinished", Message: "stream finished", HTTPStatus: 200}
)

Webrpc errors

View Source
var (
	ErrUnauthorized     = WebRPCError{Code: 1000, Name: "Unauthorized", Message: "Unauthorized access", HTTPStatus: 401}
	ErrPermissionDenied = WebRPCError{Code: 1001, Name: "PermissionDenied", Message: "Permission denied", HTTPStatus: 403}
	ErrSessionExpired   = WebRPCError{Code: 1002, Name: "SessionExpired", Message: "Session expired", HTTPStatus: 403}
	ErrMethodNotFound   = WebRPCError{Code: 1003, Name: "MethodNotFound", Message: "Method not found", HTTPStatus: 404}
	ErrRequestConflict  = WebRPCError{Code: 1004, Name: "RequestConflict", Message: "Conflict with target resource", HTTPStatus: 409}
	ErrAborted          = WebRPCError{Code: 1005, Name: "Aborted", Message: "Request aborted", HTTPStatus: 400}
	ErrGeoblocked       = WebRPCError{Code: 1006, Name: "Geoblocked", Message: "Geoblocked region", HTTPStatus: 451}
	ErrRateLimited      = WebRPCError{Code: 1007, Name: "RateLimited", Message: "Rate-limited. Please slow down.", HTTPStatus: 429}
	ErrInvalidArgument  = WebRPCError{Code: 2001, Name: "InvalidArgument", Message: "Invalid argument", HTTPStatus: 400}
	ErrUnavailable      = WebRPCError{Code: 2002, Name: "Unavailable", Message: "Unavailable resource", HTTPStatus: 400}
	ErrQueryFailed      = WebRPCError{Code: 2003, Name: "QueryFailed", Message: "Query failed", HTTPStatus: 400}
	ErrValidationFailed = WebRPCError{Code: 2004, Name: "ValidationFailed", Message: "Validation Failed", HTTPStatus: 422}
	ErrNotFound         = WebRPCError{Code: 3000, Name: "NotFound", Message: "Resource not found", HTTPStatus: 400}
	ErrRequiresTOTP     = WebRPCError{Code: 6600, Name: "RequiresTOTP", Message: "TOTP is required", HTTPStatus: 403}
	ErrRequiresPIN      = WebRPCError{Code: 6601, Name: "RequiresPIN", Message: "PIN is required", HTTPStatus: 403}
)

Schema errors

View Source
var WebRPCServices = map[string][]string{
	"Guard": {
		"Ping",
		"Version",
		"RuntimeStatus",
		"GetSignerConfig",
		"Sign",
		"SignWith",
		"Patch",
		"AuthMethods",
		"SetPIN",
		"ResetPIN",
		"CreateTOTP",
		"CommitTOTP",
		"ResetTOTP",
		"Reset2FA",
		"RecoveryCodes",
		"ResetRecoveryCodes",
	},
}

Functions

func HTTPRequestHeaders

func HTTPRequestHeaders(ctx context.Context) (http.Header, bool)

func MethodCtx

func MethodCtx(ctx context.Context) (method, bool)

func MethodNameFromContext

func MethodNameFromContext(ctx context.Context) string

func RequestFromContext

func RequestFromContext(ctx context.Context) *http.Request

func ServiceNameFromContext

func ServiceNameFromContext(ctx context.Context) string

func WebRPCSchemaHash

func WebRPCSchemaHash() string

Schema hash generated from your RIDL schema

func WebRPCSchemaVersion

func WebRPCSchemaVersion() string

Schema version of your RIDL schema

func WebRPCVersion

func WebRPCVersion() string

WebRPC description and code-gen version

func WebrpcMethods

func WebrpcMethods() map[string]method

func WithHTTPRequestHeaders

func WithHTTPRequestHeaders(ctx context.Context, h http.Header) (context.Context, error)

Types

type AuthToken

type AuthToken struct {
	ID    string `json:"id"`
	Token string `json:"token"`
}

type Guard

type Guard interface {
	Ping(ctx context.Context) (bool, error)
	Version(ctx context.Context) (*Version, error)
	RuntimeStatus(ctx context.Context) (*RuntimeStatus, error)
	GetSignerConfig(ctx context.Context, signer string) (*WalletConfig, error)
	// Called by sequence.app when the user signs in, and signs messages/transactions/migrations.
	// Requires a valid 2FA token if enabled.
	Sign(ctx context.Context, request *SignRequest, token *AuthToken) (string, error)
	SignWith(ctx context.Context, signer string, request *SignRequest, token *AuthToken) (string, error)
	// Internal use only.
	// Only ever needs to be called once per chain.
	// Signs a preconfigured payload that the caller has no control over.
	Patch(ctx context.Context, signer string, chainId uint64, secret string) (interface{}, error)
	// Called by sequence.app when it needs to check the user's 2FA.
	// This happens during sign in, before signing messages and transactions, and when configuring 2FA.
	// Requires either a valid JWT or a signature by one of the wallet's signers.
	AuthMethods(ctx context.Context, proof *OwnershipProof) ([]string, bool, error)
	// Not currently called. Requires both a JWT and a wallet signature.
	SetPIN(ctx context.Context, pin string, timestamp uint64, signature string, chainId uint64) error
	// Not currently called. Requires both a JWT and a wallet signature.
	ResetPIN(ctx context.Context, timestamp uint64, signature string, chainId uint64) error
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	CreateTOTP(ctx context.Context, timestamp uint64, signature string, chainId uint64) (string, error)
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	CommitTOTP(ctx context.Context, token string) ([]*RecoveryCode, error)
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	ResetTOTP(ctx context.Context, timestamp uint64, signature string, chainId uint64) error
	// Called by sequence.app when the user uses a recovery code.
	// Requires either a valid JWT or a signature by one of the wallet's signers.
	Reset2FA(ctx context.Context, code string, proof *OwnershipProof) error
	// Called by sequence.app when the user is viewing their recovery codes.
	// Requires both a JWT and a wallet signature.
	RecoveryCodes(ctx context.Context, timestamp uint64, signature string, chainId uint64) ([]*RecoveryCode, error)
	// Called by sequence.app when the user is viewing their recovery codes.
	// Requires both a JWT and a wallet signature.
	ResetRecoveryCodes(ctx context.Context, timestamp uint64, signature string, chainId uint64) ([]*RecoveryCode, error)
}

type GuardClient

type GuardClient interface {
	Ping(ctx context.Context) (bool, error)
	Version(ctx context.Context) (*Version, error)
	RuntimeStatus(ctx context.Context) (*RuntimeStatus, error)
	GetSignerConfig(ctx context.Context, signer string) (*WalletConfig, error)
	// Called by sequence.app when the user signs in, and signs messages/transactions/migrations.
	// Requires a valid 2FA token if enabled.
	Sign(ctx context.Context, request *SignRequest, token *AuthToken) (string, error)
	SignWith(ctx context.Context, signer string, request *SignRequest, token *AuthToken) (string, error)
	// Internal use only.
	// Only ever needs to be called once per chain.
	// Signs a preconfigured payload that the caller has no control over.
	Patch(ctx context.Context, signer string, chainId uint64, secret string) (interface{}, error)
	// Called by sequence.app when it needs to check the user's 2FA.
	// This happens during sign in, before signing messages and transactions, and when configuring 2FA.
	// Requires either a valid JWT or a signature by one of the wallet's signers.
	AuthMethods(ctx context.Context, proof *OwnershipProof) ([]string, bool, error)
	// Not currently called. Requires both a JWT and a wallet signature.
	SetPIN(ctx context.Context, pin string, timestamp uint64, signature string, chainId uint64) error
	// Not currently called. Requires both a JWT and a wallet signature.
	ResetPIN(ctx context.Context, timestamp uint64, signature string, chainId uint64) error
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	CreateTOTP(ctx context.Context, timestamp uint64, signature string, chainId uint64) (string, error)
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	CommitTOTP(ctx context.Context, token string) ([]*RecoveryCode, error)
	// Called by sequence.app when the user configures their 2FA.
	// Requires both a JWT and a wallet signature.
	ResetTOTP(ctx context.Context, timestamp uint64, signature string, chainId uint64) error
	// Called by sequence.app when the user uses a recovery code.
	// Requires either a valid JWT or a signature by one of the wallet's signers.
	Reset2FA(ctx context.Context, code string, proof *OwnershipProof) error
	// Called by sequence.app when the user is viewing their recovery codes.
	// Requires both a JWT and a wallet signature.
	RecoveryCodes(ctx context.Context, timestamp uint64, signature string, chainId uint64) ([]*RecoveryCode, error)
	// Called by sequence.app when the user is viewing their recovery codes.
	// Requires both a JWT and a wallet signature.
	ResetRecoveryCodes(ctx context.Context, timestamp uint64, signature string, chainId uint64) ([]*RecoveryCode, error)
}

func NewClient added in v0.60.8

func NewClient(projectAccessKey string, clientOptions ...Options) GuardClient

NewClient creates a new Sequence Guard client instance. Please see https://sequence.build to get a `projectAccessKey`, which is your project's access key used to communicate with Sequence services.

NOTE: the `projectAccessKey` may be optional if you're using a JWT auth token passed in via the `clientOptions`.

func NewGuardClient

func NewGuardClient(addr string, client HTTPClient) GuardClient

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface used by generated clients to send HTTP requests. It is fulfilled by *(net/http).Client, which is sufficient for most users. Users can provide their own implementation for special retry policies.

type Options added in v0.60.8

type Options struct {
	// JWTAuthToken is an optional JWT token to authenticate with the guard service.
	JWTAuthToken string

	// GuardServiceURL is an optional custom URL for the Sequence Guard service.
	// If not provided, the default URL in `DefaultGuardServiceURL` will be used.
	GuardServiceURL string

	// HTTPClient is an optional custom HTTP client to use for communicating with the
	// guard service.
	HTTPClient HTTPClient
}

type OwnershipProof

type OwnershipProof struct {
	Wallet    prototyp.Hash `json:"wallet"`
	Timestamp uint64        `json:"timestamp"`
	Signer    prototyp.Hash `json:"signer"`
	Signature prototyp.Hash `json:"signature"`
	ChainId   uint64        `json:"chainId"`
}

type PayloadType

type PayloadType string
const (
	PayloadType_Calls                    PayloadType = "Calls"
	PayloadType_Message                  PayloadType = "Message"
	PayloadType_ConfigUpdate             PayloadType = "ConfigUpdate"
	PayloadType_SessionImplicitAuthorize PayloadType = "SessionImplicitAuthorize"
)

func (*PayloadType) Is

func (x *PayloadType) Is(values ...PayloadType) bool

func (PayloadType) MarshalText

func (x PayloadType) MarshalText() ([]byte, error)

func (*PayloadType) UnmarshalText

func (x *PayloadType) UnmarshalText(b []byte) error

type RecoveryCode

type RecoveryCode struct {
	Code string `json:"code"`
	Used bool   `json:"used"`
}

type RuntimeStatus

type RuntimeStatus struct {
	// overall status, true/false
	HealthOK   bool      `json:"healthOK"`
	StartTime  time.Time `json:"startTime"`
	Uptime     uint64    `json:"uptime"`
	Ver        string    `json:"ver"`
	Branch     string    `json:"branch"`
	CommitHash string    `json:"commitHash"`
}

type SignRequest

type SignRequest struct {
	// TODO: make this a string/BigInt TODO: with webrpc v2, we can import BigInt type, etc.
	ChainId     uint64        `json:"chainId"`
	Msg         string        `json:"msg"`
	AuxData     *string       `json:"auxData"`
	Wallet      prototyp.Hash `json:"wallet"`
	PayloadType PayloadType   `json:"payloadType"`
	PayloadData string        `json:"payloadData"`
	Signatures  []*Signature  `json:"signatures"`
}

type Signature

type Signature struct {
	Address   prototyp.Hash `json:"address"`
	Type      SignatureType `json:"type"`
	ImageHash prototyp.Hash `json:"imageHash"`
	Data      prototyp.Hash `json:"data"`
}

type SignatureType

type SignatureType string
const (
	SignatureType_Hash    SignatureType = "Hash"
	SignatureType_Sapient SignatureType = "Sapient"
	SignatureType_EthSign SignatureType = "EthSign"
	SignatureType_Erc1271 SignatureType = "Erc1271"
)

func (*SignatureType) Is

func (x *SignatureType) Is(values ...SignatureType) bool

func (SignatureType) MarshalText

func (x SignatureType) MarshalText() ([]byte, error)

func (*SignatureType) UnmarshalText

func (x *SignatureType) UnmarshalText(b []byte) error

type Version

type Version struct {
	WebrpcVersion string `json:"webrpcVersion"`
	SchemaVersion string `json:"schemaVersion"`
	SchemaHash    string `json:"schemaHash"`
	AppVersion    string `json:"appVersion"`
}

type WalletConfig

type WalletConfig struct {
	Address string `json:"address"`
	Content string `json:"content"`
}

type WalletSigner

type WalletSigner struct {
	Address string `json:"address"`
	Weight  uint8  `json:"weight"`
}

type WebRPCError

type WebRPCError struct {
	Name       string `json:"error"`
	Code       int    `json:"code"`
	Message    string `json:"msg"`
	Cause      string `json:"cause,omitempty"`
	HTTPStatus int    `json:"status"`
	// contains filtered or unexported fields
}

func ErrorWithCause deprecated

func ErrorWithCause(rpcErr WebRPCError, cause error) WebRPCError

Deprecated: Use .WithCause() method on WebRPCError.

func (WebRPCError) Error

func (e WebRPCError) Error() string

func (WebRPCError) Is

func (e WebRPCError) Is(target error) bool

func (WebRPCError) Unwrap

func (e WebRPCError) Unwrap() error

func (WebRPCError) WithCause

func (e WebRPCError) WithCause(cause error) WebRPCError

func (WebRPCError) WithCausef

func (e WebRPCError) WithCausef(format string, args ...interface{}) WebRPCError

type WebrpcGenVersions

type WebrpcGenVersions struct {
	WebrpcGenVersion string
	CodeGenName      string
	CodeGenVersion   string
	SchemaName       string
	SchemaVersion    string
}

func VersionFromHeader

func VersionFromHeader(h http.Header) (*WebrpcGenVersions, error)

Jump to

Keyboard shortcuts

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