proto

package
v0.52.6 Latest Latest
Warning

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

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

Documentation

Overview

sequence-guard v0.4.0 d6b4a3c89539b494875af543fff459df65bb7b9e -- Code generated by webrpc-gen@v0.22.0 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 GuardPathPrefix = "/rpc/Guard/"
View Source
const WebrpcHeader = "Webrpc"
View Source
const WebrpcHeaderValue = "webrpc@v0.22.0;gen-golang@v0.17.0;sequence-guard@v0.4.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}
)

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) error
	ResetPIN(ctx context.Context, timestamp uint64, signature string) 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) (string, error)
	CommitTOTP(ctx context.Context, token string) ([]*RecoveryCode, error)
	ResetTOTP(ctx context.Context, timestamp uint64, signature string) 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) ([]*RecoveryCode, error)
	ResetRecoveryCodes(ctx context.Context, timestamp uint64, signature string) ([]*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) error
	ResetPIN(ctx context.Context, timestamp uint64, signature string) 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) (string, error)
	CommitTOTP(ctx context.Context, token string) ([]*RecoveryCode, error)
	ResetTOTP(ctx context.Context, timestamp uint64, signature string) 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) ([]*RecoveryCode, error)
	ResetRecoveryCodes(ctx context.Context, timestamp uint64, signature string) ([]*RecoveryCode, error)
}

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 OwnershipProof

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

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"`
}

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