api

package
v2.6.1-automation-2023... Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MessageSignatureLen           = 65
	MessageSignatureHexEncodedLen = 2 + 2*MessageSignatureLen
	MessageIdMaxLen               = 128
	MessageMethodMaxLen           = 64
	MessageDonIdMaxLen            = 64
	MessageReceiverLen            = 2 + 2*20
)

Variables

This section is empty.

Functions

func ToHttpErrorCode

func ToHttpErrorCode(errorCode ErrorCode) int

See https://go.dev/src/net/http/status.go

Types

type Codec

type Codec interface {
	DecodeRequest(msgBytes []byte) (*Message, error)

	EncodeRequest(msg *Message) ([]byte, error)

	DecodeResponse(msgBytes []byte) (*Message, error)

	EncodeResponse(msg *Message) ([]byte, error)

	EncodeNewErrorResponse(id string, code int, message string, data []byte) ([]byte, error)
}

Codec implements (de)serialization of Message objects.

type ErrorCode

type ErrorCode int
const (
	NoError ErrorCode = iota
	UserMessageParseError
	UnsupportedDONIdError
	HandlerError
	RequestTimeoutError
	NodeReponseEncodingError
	FatalError
)

func (ErrorCode) String added in v2.6.0

func (e ErrorCode) String() string

type JsonRPCCodec

type JsonRPCCodec struct {
}

func (*JsonRPCCodec) DecodeRequest

func (*JsonRPCCodec) DecodeRequest(msgBytes []byte) (*Message, error)

func (*JsonRPCCodec) DecodeResponse

func (*JsonRPCCodec) DecodeResponse(msgBytes []byte) (*Message, error)

func (*JsonRPCCodec) EncodeNewErrorResponse

func (*JsonRPCCodec) EncodeNewErrorResponse(id string, code int, message string, data []byte) ([]byte, error)

func (*JsonRPCCodec) EncodeRequest

func (*JsonRPCCodec) EncodeRequest(msg *Message) ([]byte, error)

func (*JsonRPCCodec) EncodeResponse

func (*JsonRPCCodec) EncodeResponse(msg *Message) ([]byte, error)

type JsonRPCError

type JsonRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

JSON-RPC error can only be sent to users. It is not used for messages between Gateways and Nodes.

type JsonRPCRequest

type JsonRPCRequest struct {
	Version string   `json:"jsonrpc"`
	Id      string   `json:"id"`
	Method  string   `json:"method"`
	Params  *Message `json:"params,omitempty"`
}

Wrapping/unwrapping Message objects into JSON RPC ones folllowing https://www.jsonrpc.org/specification

type JsonRPCResponse

type JsonRPCResponse struct {
	Version string        `json:"jsonrpc"`
	Id      string        `json:"id"`
	Result  *Message      `json:"result,omitempty"`
	Error   *JsonRPCError `json:"error,omitempty"`
}

type Message

type Message struct {
	Signature string      `json:"signature"`
	Body      MessageBody `json:"body"`
}

* Top-level Message structure containing: * - universal fields identifying the request, the sender and the target DON/service * - product-specific payload * * Signature, Receiver and Sender are hex-encoded with a "0x" prefix.

func (*Message) ExtractSigner added in v2.4.0

func (m *Message) ExtractSigner() (signerAddress []byte, err error)

func (*Message) Sign

func (m *Message) Sign(privateKey *ecdsa.PrivateKey) error

Message signatures are over the following data:

  1. MessageId aligned to 128 bytes
  2. Method aligned to 64 bytes
  3. DonId aligned to 64 bytes
  4. Receiver (in hex) aligned to 42 bytes
  5. Payload (raw bytes before parsing)

func (*Message) Validate

func (m *Message) Validate() error

type MessageBody

type MessageBody struct {
	MessageId string `json:"message_id"`
	Method    string `json:"method"`
	DonId     string `json:"don_id"`
	Receiver  string `json:"receiver"`
	// Service-specific payload, decoded inside the Handler.
	Payload json.RawMessage `json:"payload,omitempty"`

	// Fields only used locally for convenience. Not serialized.
	Sender string `json:"-"`
}

Jump to

Keyboard shortcuts

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