models

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceDirectorySync = "gds"
	SourceUserEntry     = "user"
	SourcePeer          = "peer"
	ProtocolTRISA       = "trisa"
	ProtocolTRP         = "trp"
)
View Source
const (
	SourceUnknown       = "unknown"
	SourceLocal         = "local"
	SourceRemote        = "remote"
	StatusUnspecified   = "unspecified"
	StatusDraft         = "draft"
	StatusPending       = "pending"
	StatusReview        = "review"
	StatusRepair        = "repair"
	StatusAccepted      = "accepted"
	StatusCompleted     = "completed"
	StatusRejected      = "rejected"
	DirectionOut        = "out"
	DirectionOutgoing   = DirectionOut
	DirectionIn         = "in"
	DirectionIncoming   = DirectionIn
	DirectionAny        = "any"
	CounterpartyUnknown = "unknown"
	VirtualAssetUnknown = "UNK"
)
View Source
const DefaultPageSize = uint32(50)

Variables

This section is empty.

Functions

func ValidStatus

func ValidStatus(status string) bool

Types

type APIKey

type APIKey struct {
	Model
	Description sql.NullString
	ClientID    string
	Secret      string
	LastSeen    sql.NullTime
	// contains filtered or unexported fields
}

func (*APIKey) Params

func (k *APIKey) Params() []any

func (APIKey) Permissions

func (k APIKey) Permissions() []string

func (*APIKey) Scan

func (k *APIKey) Scan(scanner Scanner) error

func (*APIKey) ScanSummary

func (k *APIKey) ScanSummary(scanner Scanner) error

func (*APIKey) SetPermissions

func (k *APIKey) SetPermissions(permissions []string)

type APIKeyPage

type APIKeyPage struct {
	APIKeys []*APIKey `json:"api_keys"`
	Page    *PageInfo `json:"page"`
}

type Account

type Account struct {
	Model
	CustomerID    sql.NullString  // Account ID of internal user record (optional)
	FirstName     sql.NullString  // First name (forename) of user
	LastName      sql.NullString  // Last name (surname) of user
	TravelAddress sql.NullString  // Generated TravelAddress for this user
	IVMSRecord    *ivms101.Person // IVMS101 record for the account
	// contains filtered or unexported fields
}

Account holds information about a user account for the local VASP including identifying information to link the account to the user record and IVMS101 data. Accounts automatically generate a TravelAddress for creating travel rule transactions with the specified VASPs. Accounts can also be associated with one or more wallet addresses for specific crypto currencies and networks.

func (*Account) CryptoAddresses

func (a *Account) CryptoAddresses() ([]*CryptoAddress, error)

Returns associated crypto addresses if they are cached on the account model, returns an ErrMissingAssociation error if they are not cached.

func (*Account) Params

func (a *Account) Params() []any

Get the complete named params of the account from the model.

func (*Account) Scan

func (a *Account) Scan(scanner Scanner) error

Scan a complete SELECT into the account model.

func (*Account) ScanSummary

func (a *Account) ScanSummary(scanner Scanner) error

ScanSummary scans only the summary information into the account model.

func (*Account) SetCryptoAddresses

func (a *Account) SetCryptoAddresses(addresses []*CryptoAddress)

Used by store implementations to cache associated crypto addresses on the account.

type AccountsPage

type AccountsPage struct {
	Accounts []*Account `json:"accounts"`
	Page     *PageInfo  `json:"page"`
}

type Counterparty

type Counterparty struct {
	Model
	Source              string               // either directory or locally created
	DirectoryID         sql.NullString       // the directory ID associated with the counterparty (directory only)
	RegisteredDirectory sql.NullString       // the registered directory of the counterparty (directory only)
	Protocol            string               // either TRISA or TRP; the protocol to use to send travel rule information
	CommonName          string               // common name - a unique name to identify the endpoint
	Endpoint            string               // the full endpoint to connect to the counterparty on
	Name                string               // the counterparty's legal entity name
	Website             sql.NullString       // website with more information about the counterparty
	Country             sql.NullString       // country the counterparty is associated with
	BusinessCategory    sql.NullString       // the business category of the counterparty
	VASPCategories      VASPCategories       // the categories of how the VASP handles crypto assets
	VerifiedOn          sql.NullTime         // the datetime the VASP was verified in the directory (directory only)
	IVMSRecord          *ivms101.LegalPerson // IVMS101 record for the counterparty
}

TODO: how to incorporate the TRIXO form into this model? TODO: make sure that we add contacts associated with this model.

func (*Counterparty) Params

func (c *Counterparty) Params() []any

Get complete named params of the counterparty from the model.

func (*Counterparty) Scan

func (c *Counterparty) Scan(scanner Scanner) error

Scan a complete SELECT into the counterparty model

func (*Counterparty) ScanSummary

func (c *Counterparty) ScanSummary(scanner Scanner) error

Scan a partial SELECT into the counterparty model

type CounterpartyPage

type CounterpartyPage struct {
	Counterparties []*Counterparty `json:"counterparties"`
	Page           *PageInfo       `json:"page"`
}

type CounterpartySourceInfo

type CounterpartySourceInfo struct {
	ID                  ulid.ULID
	Source              string         // either directory or locally created
	DirectoryID         sql.NullString // the directory ID associated with the counterparty (directory only)
	RegisteredDirectory sql.NullString // the registered directory of the counterparty (directory only)
	Protocol            string         // either TRISA or TRP; the protocol to use to send travel rule information
}

func (*CounterpartySourceInfo) Scan

func (c *CounterpartySourceInfo) Scan(scanner Scanner) error

type CryptoAddress

type CryptoAddress struct {
	Model
	AccountID     ulid.ULID      // Reference to account the crypto address belongs to
	CryptoAddress string         // The actual crypto address of the wallet
	Network       string         // The network associated with the crypto address in SIP0044 encoding
	AssetType     sql.NullString // The asset type with the crypto address (optional)
	Tag           sql.NullString // The memo or destination tag associated with the address (optional)
	TravelAddress sql.NullString // Generated TravelAddress for this wallet address
	// contains filtered or unexported fields
}

func (*CryptoAddress) Account

func (a *CryptoAddress) Account() (*Account, error)

Returns associated account if it is cached on the crypto address model, returns an ErrMissingAssociation error if they are not cached.

func (*CryptoAddress) Params

func (a *CryptoAddress) Params() []any

Get the complete named params of the crypto address from the model.

func (*CryptoAddress) Scan

func (a *CryptoAddress) Scan(scanner Scanner) error

Scans a complete SELECT into the CryptoAddress model

func (*CryptoAddress) SetAccount

func (a *CryptoAddress) SetAccount(account *Account)

Used by store implementations to cache associated account on the crypto address.

type CryptoAddressPage

type CryptoAddressPage struct {
	CryptoAddresses []*CryptoAddress `json:"crypto_addresses"`
	Page            *PageInfo        `json:"page"`
}

type EnvelopeStorage added in v0.14.0

type EnvelopeStorage interface {
	AddEnvelope(*SecureEnvelope) error
}

EnvelopeStorage is a subset of the PreparedTransaction interface that focuses on the database interactions with SecureEnvelopes. This sub-interface makes it easier to write tests, though in practice the PreparedTransaction is passed in for this.

type Model

type Model struct {
	ID       ulid.ULID `json:"id"`
	Created  time.Time `json:"created"`
	Modified time.Time `json:"modified"`
}

Model is the base model for all models stored in the database.

type PageInfo

type PageInfo struct {
	PageSize   uint32    `json:"page_size"`
	NextPageID ulid.ULID `json:"next_page_id"`
	PrevPageID ulid.ULID `json:"prev_page_id"`
}

func PageInfoFrom

func PageInfoFrom(in *PageInfo) (out *PageInfo)

type Permission

type Permission struct {
	ID          int64
	Title       string
	Description string
	Created     time.Time
	Modified    time.Time
}

func (*Permission) Params

func (p *Permission) Params() []any

func (*Permission) Scan

func (p *Permission) Scan(scanner Scanner) error

type PreparedTransaction

type PreparedTransaction interface {
	Created() bool                       // Returns true if the transaction was newly created, false if it already existed
	Fetch() (*Transaction, error)        // Fetches the current transaction record from the database
	Update(*Transaction) error           // Update the transaction with new information; e.g. data from decryption
	AddCounterparty(*Counterparty) error // Add counterparty by database ULID, counterparty name, or registered directory ID; if the counterparty doesn't exist, it is created
	AddEnvelope(*SecureEnvelope) error   // Associate a secure envelope with the prepared transaction
	Rollback() error                     // Rollback the prepared transaction and conclude it
	Commit() error                       // Commit the prepared transaction and conclude it
}

PreparedTransaction allows you to manage the creation/modification of a transaction w.r.t a secure envelope. It is unified in a single interface to allow backend stores that have database transactions to perform all operations in a single transaction without concurrency issues.

type Role

type Role struct {
	ID          int64
	Title       string
	Description string
	IsDefault   bool
	Created     time.Time
	Modified    time.Time
	// contains filtered or unexported fields
}

func (*Role) Params

func (r *Role) Params() []any

func (Role) Permissions

func (r Role) Permissions() ([]*Permission, error)

func (*Role) Scan

func (r *Role) Scan(scanner Scanner) error

func (*Role) SetPermissions

func (r *Role) SetPermissions(permissions []*Permission)

type Scanner

type Scanner interface {
	Scan(dest ...any) error
}

Scanner is an interface for *sql.Rows and *sql.Row so that models can implement how they scan fields into their struct without having to specify every field every time.

type SearchQuery added in v0.23.0

type SearchQuery struct {
	Query string
	Limit int
}

type SecureEnvelope

type SecureEnvelope struct {
	Model
	EnvelopeID    uuid.UUID           // Also a foreign key reference to the Transaction
	Direction     string              // Either "out" outgoing or "in" incoming
	Remote        sql.NullString      // The common name of the remote peer this message was going to or coming from
	ReplyTo       ulids.NullULID      // If this envelope is a response, a reference to the original request envelope
	IsError       bool                // If the envelope contains an error/rejection rather than a payload
	EncryptionKey []byte              // The encryption key, encrypted with the public key of the local node. Note this may differ from the value in the envelope for outgoing messages
	HMACSecret    []byte              // The hmac secret, encrypted with the public key of the local node. Note that this may differ from the value in the envelope for outgoing messages
	ValidHMAC     sql.NullBool        // If the hmac has been validated against the payload and non-repudiation properties are satisfied
	Timestamp     time.Time           // The timestamp of the envelope as defined by the envelope
	PublicKey     sql.NullString      // The signature of the public key that sealed the encryption key and hmac secret, may differ from the value in the envelope for ougoing envelopes.
	TransferState int32               // The transfer state of the secure envelope
	Envelope      *api.SecureEnvelope // The secure envelope protocol buffer stored as a BLOB
	// contains filtered or unexported fields
}

func FromEnvelope

func FromEnvelope(env *envelope.Envelope) *SecureEnvelope

FromEnvelope creates a SecureEnvelope model from a trisa wrapped secure envelope protocol buffer; this is primarily used for testing and should not be relied on for production work without testing and verification that the complete model is present.

func (*SecureEnvelope) Params

func (e *SecureEnvelope) Params() []any

func (*SecureEnvelope) Scan

func (e *SecureEnvelope) Scan(scanner Scanner) error

func (*SecureEnvelope) SetTransaction

func (e *SecureEnvelope) SetTransaction(tx *Transaction)

func (*SecureEnvelope) Transaction

func (e *SecureEnvelope) Transaction() (*Transaction, error)

type SecureEnvelopePage

type SecureEnvelopePage struct {
	Envelopes []*SecureEnvelope `json:"envelopes"`
	Page      *PageInfo         `json:"page"`
}

type Transaction

type Transaction struct {
	ID                 uuid.UUID      // Transaction IDs are UUIDs not ULIDs per the TRISA spec, this is also used for the envelope ID
	Source             string         // Either "local" meaning the transaction was created by the user, or "remote" meaning it is an incoming message
	Status             string         // Can be "unspecified", "started", "pending", "review", "repair", "accepted", "completed", or "rejected"
	Counterparty       string         // The name of the counterparty in the transaction
	CounterpartyID     ulids.NullULID // A reference to the counterparty in the database, if any
	Originator         sql.NullString // Full name of the originator natural person or account
	OriginatorAddress  sql.NullString // The crypto address of the originator
	Beneficiary        sql.NullString // Full name of the beneficiary natural person or account
	BeneficiaryAddress sql.NullString // The crypto address of the beneficiary
	VirtualAsset       string         // A representation of the network/asset type
	Amount             float64        // The amount of the transaction
	LastUpdate         sql.NullTime   // The last time a TRISA RPC occurred for this transaction
	Created            time.Time      // Timestamp the transaction was created
	Modified           time.Time      // Timestamp the transaction was last modified, including when a new secure envelope was received
	// contains filtered or unexported fields
}

func (*Transaction) NumEnvelopes

func (t *Transaction) NumEnvelopes() int64

func (*Transaction) Params

func (t *Transaction) Params() []any

func (*Transaction) Scan

func (t *Transaction) Scan(scanner Scanner) error

func (*Transaction) ScanWithCount

func (t *Transaction) ScanWithCount(scanner Scanner) error

func (*Transaction) SecureEnvelopes

func (t *Transaction) SecureEnvelopes() ([]*SecureEnvelope, error)

func (*Transaction) SetNumEnvelopes

func (t *Transaction) SetNumEnvelopes(count int64)

func (*Transaction) SetSecureEnvelopes

func (t *Transaction) SetSecureEnvelopes(envelopes []*SecureEnvelope)

func (*Transaction) Update

func (t *Transaction) Update(other *Transaction)

Update the transaction t with values from other if the field in other is non-zero; e.g. if a nullable field is valid or an empty string is empty. This method skips the ID and Modified fields.

type TransactionPage

type TransactionPage struct {
	Transactions []*Transaction `json:"transactions"`
	Page         *PageInfo      `json:"page"`
}

type TravelAddressFactory

type TravelAddressFactory func(any) (string, error)

Factory function that can create travel addresses from models or IDs. This function should be able to handle any model defined in this package or a ULID or UUID.

func NewTravelAddressFactory

func NewTravelAddressFactory(endpoint, protocol string) (TravelAddressFactory, error)

Create a travel address factory with the endpoint and protocol.

type User

type User struct {
	Model
	Name      sql.NullString
	Email     string
	Password  string
	RoleID    int64
	LastLogin sql.NullTime
	// contains filtered or unexported fields
}

func (*User) Params

func (u *User) Params() []any

func (User) Permissions

func (u User) Permissions() []string

func (User) Role

func (u User) Role() (*Role, error)

func (*User) Scan

func (u *User) Scan(scanner Scanner) error

func (*User) ScanSummary

func (u *User) ScanSummary(scanner Scanner) error

func (*User) SetPermissions

func (u *User) SetPermissions(permissions []string)

func (*User) SetRole

func (u *User) SetRole(role *Role)

type UserPage

type UserPage struct {
	Users []*User   `json:"users"`
	Page  *PageInfo `json:"page"`
}

type VASPCategories

type VASPCategories []string

VASPCategories allows the string list to be stored in the database as a JSON array.

func (*VASPCategories) Scan

func (c *VASPCategories) Scan(src interface{}) error

func (VASPCategories) Value

func (c VASPCategories) Value() (_ driver.Value, err error)

Jump to

Keyboard shortcuts

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