postman

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Postman providers helper functionality for managing TRISA and TRP transfers and sorting them and storing them in the database. This package is intended to unify the functionality across the TRISA node, the TRP node, and the Web API/UI.

On every single travel rule transaction, no matter if it's TRISA or TRP, no matter if it's sent from the node or received into the node, whether or not it's a new transaction or an update to an old transaction the following things must happen:

1. The message(s) must be validated 2. The transfer packet must be associated with a transaction 3. The transaction status must be updated, and potentially other parts of the transaction 4. The counterparty must be identified 5. Error envelopes have to be handled correctly 6. The keys for the envelope must be loaded for decryption 7. Sealed envelopes need to be decrypted 8. HMAC signatures need to be checked 9. The outgoing envelope must be resealed with internal keys 10. The envelopes and all changes must be saved to the database 11. The audit log must be updated

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoCounterpartyInfo = errors.New("no counterparty info available on packet")
	ErrNoUnsealingKey     = errors.New("cannot open incoming envelope without unsealing key")
	ErrNoSealingKey       = errors.New("cannot seal outgoing envelope without sealing key")
)

Functions

func FindAccount

func FindAccount(person any) (account string)

func FindName

func FindName(persons ...*ivms101.Person) (name string)

func TransactionFromPayload

func TransactionFromPayload(in *api.Payload) *models.Transaction

Types

type Direction

type Direction uint8
const (
	Unknown Direction = iota
	DirectionIncoming
	DirectionOutgoing
)

type Incoming

type Incoming struct {
	Envelope     *envelope.Envelope
	UnsealingKey keys.PrivateKey
	// contains filtered or unexported fields
}

Incoming messages are received from the remote; they can be replies to transfers initiated by the local node or they can be incoming messages that require a reply from the local node (e.g. received by the TRISA or TRP servers).

Incoming messages imply that they are sealed for decryption by the local host.

func (*Incoming) Model

func (i *Incoming) Model() *models.SecureEnvelope

Creates a secure envelope model to store in the database with all of the information that is in the envelope and in the packet. Note that the PeerInfo is expected to be on the packet; and if this is an incoming reply to an outgoing transaction, the outgoing model must already have been created and have an ID.

TODO: we need to store public key information about the key that was actually used to decrypt the model, so that we can decrypt the model in the future.

func (*Incoming) Open

func (i *Incoming) Open() (reject *trisa.Error, err error)

Opens the incoming envelope, unsealing and decrypting it for handling.

func (*Incoming) Proto

func (i *Incoming) Proto() *trisa.SecureEnvelope

Returns the original protocol buffers that was wrapped by the incoming message.

func (*Incoming) PublicKeySignature

func (i *Incoming) PublicKeySignature() string

Returns the public key signature from the original message.

func (*Incoming) StatusFromTransferState

func (i *Incoming) StatusFromTransferState() string

StatusFromTransferState determines what the status should be based on the incoming message transfer state. For example, if the incoming transfer state is accepted, then the Transfer can be marked as completed.

func (*Incoming) TransferState added in v0.24.0

func (i *Incoming) TransferState() trisa.TransferState

Returns the original transfer state on the envelope.

func (*Incoming) UpdateTransaction

func (i *Incoming) UpdateTransaction() (err error)

Updates the transaction info and status based on the incoming envelope.

func (*Incoming) WebhookRequest added in v0.24.0

func (i *Incoming) WebhookRequest() *webhook.Request

Creates a webhook callback request from the incoming envelope. Note that the packet must have the counterparty set and that the envelope UUID has been validated.

type Outgoing

type Outgoing struct {
	Envelope   *envelope.Envelope
	StorageKey keys.PublicKey
	SealingKey keys.PublicKey
	// contains filtered or unexported fields
}

Outgoing messages are sent to the remote party, either replies to transfers coming into the TRISA or TRP server or original messages if the transfer is initiated by a user or the API.

Outgoing messages imply that they need to be resealed for decryption by the local host.

func (*Outgoing) Model

func (o *Outgoing) Model() *models.SecureEnvelope

Creates a secure envelope model to store in the database with all of the information that is is in the envelope and in the packet. Note that the PeerInfo is expected to be on the packet; and if this is an outgoing reply to an incoming transaction, the incoming model must already have been created and have an ID.

This method will Reseal the envelope if it is not an error envelope, encrypting it for local storage and requiring the StorageKey in order to reseal.

func (*Outgoing) Proto

func (o *Outgoing) Proto() *api.SecureEnvelope

Returns the protocol buffers of the prepared envelope (seal first!)

func (*Outgoing) PublicKeySignature

func (o *Outgoing) PublicKeySignature() string

Returns the public key signature from the sealing key to send to the remote.

func (*Outgoing) Seal

func (o *Outgoing) Seal() (reject *api.Error, err error)

Seals the outgoing envelope in preparation for sending or returning to remote.

func (*Outgoing) StatusFromTransferState

func (o *Outgoing) StatusFromTransferState() string

StatusFromTransferState determines what the status should be based on the outgoing message transfer state. For example, if the outgiong transfer state is pending, then the Transfer should be marked as needing review.

func (*Outgoing) UpdateTransaction

func (o *Outgoing) UpdateTransaction() (err error)

Updates the transaction info and status based on the outgoing envelope.

type Packet

type Packet struct {
	DB           models.PreparedTransaction // Database interaction methods
	In           *Incoming                  // The incoming message that needs to be decrypted
	Out          *Outgoing                  // The outgoing message that needs to be encrypted
	Log          zerolog.Logger             // The log context for more effective logging
	Counterparty *models.Counterparty       // The remote identified counterparty
	Transaction  *models.Transaction        // The associated transaction with the packet
	Peer         peers.Peer                 // The remote peer the transfer is being conducted with
	PeerInfo     *peers.Info                // The peer info for finding the counterparty
	User         *models.User               // The user that created the request, if any
	APIKey       *models.APIKey             // The api key that created the request, if any
	Request      Direction                  // Determines if the initial message was incoming or outgoing
	Reply        Direction                  // Determines if the reply was incoming or outgoing
}

Packets contain both an incoming and an outgoing message and are used to ensure that an entire tranfer packet can be correctly constructed for both envelopes.

func Receive

func Receive(in *api.SecureEnvelope, log zerolog.Logger, peer peers.Peer) (packet *Packet, err error)

func Send

func Send(payload *api.Payload, envelopeID uuid.UUID, transferState api.TransferState, log zerolog.Logger) (packet *Packet, err error)

func SendReject

func SendReject(reject *api.Error, envelopeID uuid.UUID, log zerolog.Logger) (packet *Packet, err error)

func (*Packet) EnvelopeID

func (p *Packet) EnvelopeID() string

Returns the envelopeID from the request envelope (e.g. the first envelope in the packet)

func (*Packet) Error

func (p *Packet) Error(reject *api.Error, opts ...envelope.Option) (err error)

Creates a TRISA error envelope from the TRISA error message and sets it as the outgoing message (e.g. in the case where an incoming message is being handled).

func (*Packet) Receive

func (p *Packet) Receive(in *api.SecureEnvelope) (err error)

Receive updates the incoming message with the specified secure envelope, e.g. in the case where the outgoing message has been sent and this is the reply that was received from the remote server.

func (*Packet) RefreshTransaction

func (p *Packet) RefreshTransaction() (err error)

func (*Packet) Reject

func (p *Packet) Reject(code api.Error_Code, message string, retry bool) error

Reject creates an outgoing message with a TRISA error that contains the specified TRISA rejection error, e.g. in the case where an incoming message is being handled.

func (*Packet) ResolveCounterparty

func (p *Packet) ResolveCounterparty() (err error)

func (*Packet) Send

func (p *Packet) Send(payload *api.Payload, state api.TransferState) (err error)

Creates a TRISA payload envelope to as the outgoing message in order to send a response back to the remote that initiated the transfer.

Jump to

Keyboard shortcuts

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