Documentation ¶
Index ¶
- Constants
- Variables
- func APIChecks(next http.Handler) http.Handler
- func NewRequest(info *TRPInfo, body io.Reader) (req *http.Request, err error)
- func TransferConfirmation(handler ConfirmationHandler) http.Handler
- func TransferInquiry(handler InquiryHandler) http.Handler
- type Approval
- type Asset
- type Client
- type Confirmation
- type ConfirmationHandler
- type Inquiry
- type InquiryHandler
- type InquiryResolution
- type SealedTRISAEnvelope
- type StatusError
- type TRPInfo
- type TransactionPayload
- type TravelRuleResponse
- type UnsealedTRISAEnvelope
Constants ¶
const ( APIVersionHeader = "api-version" APIExtensionsHeader = "api-extensions" RequestIdentifierHeader = "request-identifier" ContentTypeHeader = "content-type" )
OpenVASP Application Headers
const ( APIVersion = "3.1.0" ContentTypeValue = "application/json; charset=utf-8" ContentMediaType = "application/json" )
OpenVASP Application Header Values
const ( SealedTRISAExtension = "sealed_trisa_envelope" UnsealedTRISAExtension = "unsealed_trisa_envelope" )
TRISA extensions
const (
// Maximum size in bytes for a travel rule payload: 10MiB
MaxPayloadSize = 1.049e+7
)
Variables ¶
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") )
Functions ¶
func APIChecks ¶
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 ¶
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
Types ¶
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 Client ¶
Client is used to make HTTPS requests with mTLS configured to TRP servers.
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 ¶
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 ¶
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 ¶
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.
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 ¶
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.
Directories ¶
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. |