postman

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 24 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")
	ErrNoContacts         = errors.New("no contacts are associated with counterparty, cannot send sunrise messages")
	ErrNoMessages         = errors.New("no messages sent with the sunrise packet, cannot create sunrise pending ")
)

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 (
	DirectionUnknown Direction = iota
	DirectionIncoming
	DirectionOutgoing
)

func (Direction) String added in v0.28.0

func (d Direction) String() string

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 outgoing 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
	// contains filtered or unexported fields
}

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) (packet *Packet, err error)

func Send

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

func SendReject

func SendReject(envelopeID uuid.UUID, reject *api.Error) (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) RefreshTransaction

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

func (*Packet) Remote added in v0.28.0

func (p *Packet) Remote() sql.NullString

Returns the remote information for storage in the database using the underlying resolver if available, otherwise a NULL string is returned.

func (*Packet) Reply

func (p *Packet) Reply() Direction

Returns the direction of the reply.

func (*Packet) Request

func (p *Packet) Request() Direction

Returns the direction of the request.

func (*Packet) ResolveCounterparty

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

If a resolver is set, then we can resolve the remote information from the Peer, otherwise this method is a no-op and returns no error.

type ResolveRemote added in v0.28.0

type ResolveRemote interface {
	Remote() sql.NullString
	ResolveCounterparty() error
}

type SunrisePacket added in v0.28.0

type SunrisePacket struct {
	Packet
	Messages []*generic.SunriseMessage
	// contains filtered or unexported fields
}

func ReceiveSunriseAccept added in v0.28.0

func ReceiveSunriseAccept(envelopeID uuid.UUID, payload *trisa.Payload) (packet *SunrisePacket, err error)

func ReceiveSunriseReject added in v0.28.0

func ReceiveSunriseReject(envelopeID uuid.UUID, reject *trisa.Error) (packet *SunrisePacket, err error)

func SendSunrise added in v0.28.0

func SendSunrise(envelopeID uuid.UUID, payload *trisa.Payload) (packet *SunrisePacket, err error)

Initiates a Sunrise packet for handling interactions between secure envelopes and sending messages via email to compliance contacts that they have a new compliance message for review.

func (*SunrisePacket) Contacts added in v0.28.0

func (s *SunrisePacket) Contacts() (contacts []*models.Contact, err error)

Returns the email contacts of the compliance officers associated with the counterparty.

func (*SunrisePacket) Create added in v0.28.0

func (s *SunrisePacket) Create(storageKey keys.PublicKey) (err error)

This method creates the pending message to represent the "incoming" response; e.g. a record of the email messages that were sent and then encrypts both the outgoing and incoming messages using the storage key before saving the envelopes in the database. Finally, this method updates the transaction state and refreshes the local transaction so that the information is visible to the API.

func (*SunrisePacket) Pending added in v0.28.0

func (s *SunrisePacket) Pending() (err error)

Creates the "reply" pending message for the sunrise messages that were sent.

func (*SunrisePacket) Save added in v0.28.0

func (s *SunrisePacket) Save(storageKey keys.PublicKey) (err error)

Saves an already created sunrise message. Unlike create, this method does not add the counterparty and does not default to sending an outgoing message. It expects that both the incoming and the outgoing messages have already been created.

func (*SunrisePacket) Seal added in v0.28.0

func (s *SunrisePacket) Seal(storageKey keys.PublicKey) (err error)

Encrypts the the "incoming" sunrise message for secure storage in the database with the specifrified storage key. and also passes this key to the "outgoing" secure envelope for secure encryption when that envlepe is turned into a model.

func (*SunrisePacket) SendEmail added in v0.28.0

func (s *SunrisePacket) SendEmail(contact *models.Contact, invite emails.SunriseInviteData) (err error)

Send a sunrise invitation email to the contact and create a verification token.

func (*SunrisePacket) UpdateCounterparty added in v0.28.0

func (s *SunrisePacket) UpdateCounterparty(vasp *ivms101.LegalPerson) (err error)

Updates counterparty from the accept payload modifying the model with the data that is in the BeneficiaryVASP information.

type TRISAPacket added in v0.28.0

type TRISAPacket struct {
	Packet
	Peer     peers.Peer  // The remote peer the transfer is being conducted with
	PeerInfo *peers.Info // The peer info for finding the counterparty
}

func ReceiveTRISA added in v0.28.0

func ReceiveTRISA(in *api.SecureEnvelope, peer peers.Peer) (packet *TRISAPacket, err error)

func SendTRISA added in v0.28.0

func SendTRISA(envelopeID uuid.UUID, payload *api.Payload, transferState api.TransferState) (packet *TRISAPacket, err error)

func SendTRISAReject added in v0.28.0

func SendTRISAReject(envelopeID uuid.UUID, reject *api.Error) (packet *TRISAPacket, err error)

func (*TRISAPacket) Error added in v0.28.0

func (p *TRISAPacket) 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 (*TRISAPacket) Receive added in v0.28.0

func (p *TRISAPacket) 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 (*TRISAPacket) Reject added in v0.28.0

func (p *TRISAPacket) 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 (*TRISAPacket) Remote added in v0.28.0

func (p *TRISAPacket) Remote() sql.NullString

func (*TRISAPacket) ResolveCounterparty added in v0.28.0

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

func (*TRISAPacket) Send added in v0.28.0

func (p *TRISAPacket) 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