v1.1.1 Latest Latest

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 20 Imported by: 0




View Source
const (
	APIVersionHeader        = "api-version"
	APIExtensionsHeader     = "api-extensions"
	RequestIdentifierHeader = "request-identifier"
	ContentTypeHeader       = "content-type"

OpenVASP Application Headers

View Source
const (
	APIVersion       = "3.1.0"
	ContentTypeValue = "application/json; charset=utf-8"
	ContentMediaType = "application/json"

OpenVASP Application Header Values

View Source
const (
	SealedTRISAExtension   = "sealed_trisa_envelope"
	UnsealedTRISAExtension = "unsealed_trisa_envelope"

TRISA extensions

View Source
const (
	// Maximum size in bytes for a travel rule payload: 10MiB
	MaxPayloadSize = 1.049e+7


View Source
var (
	ErrNilEnvelope           = errors.New("envelope is nil")
	ErrUnknownState          = errors.New("envelope is in an unknown state")
	ErrInvalidState          = errors.New("envelope is invalid")
	ErrEnvelopeError         = errors.New("envelope has an error")
	ErrEmptyConfirmation     = errors.New("must specify either txid or canceled in confirmation")
	ErrAmbiguousConfirmation = errors.New("cannot specify both txid and canceled in confirmation")
	ErrUnknownTravelAddress  = errors.New("could not identify travel address scheme")


func APIChecks

func APIChecks(next http.Handler) http.Handler

APIChecks is middleware that asserts that the headers in the TRP request are correct and valid, ensuring that the core protocol is implemented correctly.

func NewRequest

func NewRequest(info *TRPInfo, body io.Reader) (req *http.Request, err error)

NewRequest generates a new TRP POST request from the specified info, using the Address to determine the endpoint and setting headers accordingly. If the APIVersion is omitted, the default APIVersion is used. If there is no request identifier, one is generated and added to the info struct.

func TransferConfirmation

func TransferConfirmation(handler ConfirmationHandler) http.Handler

func TransferInquiry

func TransferInquiry(handler InquiryHandler) http.Handler


type Approval

type Approval struct {
	Address  string `json:"address"`  // some payment address
	Callback string `json:"callback"` // some implementation defined URL for transfer confirmation

Approval is used to accept a TRP Transfer Inquiry.

type Asset

type Asset struct {
	DTI     string            `json:"dti,omitempty"`      // digital token identifier as per Digital Token Identifier Foundation
	SLIP044 slip0044.CoinType `json:"slip0044,omitempty"` // registered coin types defined by BIP-0044

type Client

type Client struct {

Client is used to make HTTPS requests with mTLS configured to TRP servers.

func NewClient

func NewClient() *Client

func (*Client) Confirmation

func (c *Client) Confirmation(confirm *Confirmation) (_ *TravelRuleResponse, err error)

Confirm posts a Travel Rule Confirmation to the counterparty as specified by the info in the confirmation request and returns the response from the client.

func (*Client) Inquiry

func (c *Client) Inquiry(inquiry *Inquiry) (_ *TravelRuleResponse, err error)

Inquiry posts a Travel Rule Inquiry to the counterparty as specified by the info in the inquiry request and returns the response from the client.

func (*Client) Post

func (c *Client) Post(info *TRPInfo, body io.Reader) (_ *TravelRuleResponse, err error)

Post a request to the specified Address, which can be a Travel Address, LNURL, or plain-text URL. The content type is automatically set to application/json and the body should read JSON data. Required OpenVASP headers are set by the TRPInfo struct. If the APIVersion is omitted, the default APIVersion is used, similarly if no request identifier is present, one is generated for the reuqest.

type Confirmation

type Confirmation struct {
	TRP      *TRPInfo `json:"-"`
	TXID     string   `json:"txid,omitempty"`     // some asset-specific tx identifier
	Canceled string   `json:"canceled,omitempty"` // human readable comment or null

Confirmation JSON data is sent in response to a TransferInquiry via a POST to the callback URl. Only one of txid or canceled should be specified. The txid should be specified only if the transaction has been broadcasted. Canceled is used to indicate that the transfer will not move forward with a human readable comment.

func (Confirmation) Validate

func (c Confirmation) Validate() error

type ConfirmationHandler

type ConfirmationHandler interface {
	OnConfirmation(*Confirmation) error

type Inquiry

type Inquiry struct {
	TRP        *TRPInfo                 `json:"-"`
	Asset      *Asset                   `json:"asset"`
	Amount     float64                  `json:"amount"`
	Callback   string                   `json:"callback"`
	IVMS101    *ivms101.IdentityPayload `json:"IVMS101"`
	Extensions map[string]interface{}   `json:"extensions,omitempty"`

Inquiry defines a Travel Rule Protocol payload that contains information about the transaction and the originator and beneficiary of the transaction.

func EnvelopeToPayload

func EnvelopeToPayload(env *envelope.Envelope) (*Inquiry, error)

Convert a TRISA envelope to a TRP payload. If the envelope is sealed, then this returns a payload with the SealedTRISAEnvelope extension. If the envelope is unsealed, then this returns a payload with the UnsealedTRISAEnvelope extension. If the envelope is in the clear then this returns a standard TRP payload with no TRISA extensions.

type InquiryHandler

type InquiryHandler interface {
	OnInquiry(*Inquiry) (*InquiryResolution, error)

type InquiryResolution

type InquiryResolution struct {
	Version  string    `json:"version,omitempty"`  // the API version of the request
	Approved *Approval `json:"approved,omitempty"` // payment address and callback
	Rejected string    `json:"rejected,omitempty"` // human readable comment (must be specified to reject)

InquiryResolution is used to approve or reject a TRP Transfer Inquiry either automatically in direct response to the inquiry request or via the callback URL specified in the request. One of "approved", "rejected", or "version" should be specified to ensure unambiguous results are returned to the caller.

type SealedTRISAEnvelope

type SealedTRISAEnvelope struct {
	Envelope string `json:"envelope"`

The SealedTRISAEnvelope extension is used to faciliate the TRISA protocol by providing a JSON serialized version of the secure envelope that contains the transaction.

type StatusError

type StatusError struct {
	Code    int    // HTTP Status Code to return
	Message string // Message to return, if empty, default status message is used

func (*StatusError) Error

func (e *StatusError) Error() string

type TRPInfo

type TRPInfo struct {
	Address           string   // Address can be a Travel Rule Address, LNURL, or URL
	APIVersion        string   // Defaults to the APIVersion of the package
	RequestIdentifier string   // A unique identifier representing the specific transfer
	APIExtensions     []string // The names of any extensions uses in the request

TRPInfo contains metadata information from the TRP API Headers.

func ParseTRPInfo

func ParseTRPInfo(r *http.Request) *TRPInfo

Parse TRPInfo from the headers of an HTTP request. If any headers are not present, then the info is populated with assumed fields or empty values as appropriate. TODO: parse the LNURL from the URL rather than passing the raw URL.

func (TRPInfo) GetURL

func (t TRPInfo) GetURL() (_ string, err error)

type TransactionPayload

type TransactionPayload struct {
	// Transaction ID on the blockchain or network.
	TxID string `json:"txid,omitempty"`

	// Crypto address of the originator and beneficiary.
	Originator  string `json:"originator,omitempty"`
	Beneficiary string `json:"beneficiary,omitempty"`

	// Amount and asset type of the transaction.
	Amount    float64 `json:"amount,omitempty"`
	AssetType string  `json:"asset_type,omitempty"`

	// The blockchain or network of the transaction.
	Network string `json:"network,omitempty"`

	// The RFC3339 timestamp of the transaction.
	Timestamp string `json:"timestamp,omitempty"`

	// Tags and extra JSON data about the transaction.
	Tag       string                 `json:"tag,omitempty"`
	ExtraJSON map[string]interface{} `json:"extra_json,omitempty"`

The TransactionPayload extension is used to provide information about the transaction on the blockchain or network so it can be linked to the identity information in the TRP payload.

type TravelRuleResponse

type TravelRuleResponse struct {
	// contains filtered or unexported fields

TravelRuleResponse embeds an http Response and makes provisions for parsing the response data back from the counterparty.

func (*TravelRuleResponse) Info

func (t *TravelRuleResponse) Info() *TRPInfo

Info returns the travel rule info from the headers of the response

func (*TravelRuleResponse) InquiryResolution

func (t *TravelRuleResponse) InquiryResolution() (*InquiryResolution, error)

InquiryResolution attempts to parse a travel rule response from the response body, closing the response body when it is complete. If the body has already been closed then an EOF error will be returned.

func (*TravelRuleResponse) StatusError

func (t *TravelRuleResponse) StatusError() *StatusError

If a 400 or 500 status code was received, the status error is returned.

type UnsealedTRISAEnvelope

type UnsealedTRISAEnvelope struct {
	// Transaction ID generated by the originator.
	Id string `json:"id"`

	// The encrypted payload containing the IVMS101 identity and generic transaction.
	Payload []byte `json:"payload"`

	// Encryption key used to encrypt the payload, in this struct the key is unencrypted.
	EncryptionKey       []byte `json:"encryption_key"`
	EncryptionAlgorithm string `json:"encryption_algorithm"`

	// HMAC of the payload to ensure integrity.
	HMAC          []byte `json:"hmac"`
	HMACSecret    []byte `json:"hmac_secret"`
	HMACAlgorithm string `json:"hmac_algorithm"`

The UnsealedTRISAEnvelope extension is used to provide an unsealed version of a secure envelope where the key is unencrypted, allowing any party to decrypt the payload and access the identity and transaction information.


Path Synopsis
Helper functions for encoding and decoding (LNURLs) which are used to specify which VASP controls a specific virtual asset address.
Helper functions for encoding and decoding (LNURLs) which are used to specify which VASP controls a specific virtual asset address.
Helper functions for encoding and decoding Travel Addresses, which are used to specify which VASP controls a specific virtual asset address.
Helper functions for encoding and decoding Travel Addresses, which are used to specify which VASP controls a specific virtual asset address.

Jump to

Keyboard shortcuts

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