wallet

package
v0.0.0-...-8a10f5f Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MPL-2.0 Imports: 62 Imported by: 1

README

Wallet Microservice

Purpose

To provide BAT-Wallet API.

to run

go run ../main.go serve wallet rest

Custodian Linking Toggle

We have the ability to turn off/on individually custodial linking capabilities for rewards wallets. The following response can be expected for each of the custodian linking endpoints if we have administratively turned off linking capabilities.

Uphold Linking Toggle
POST /v3/wallet/uphold/<payment_id>/claim
...

HTTP2/0 400 Bad Request
{
    "message": "Error validating Connecting Brave Rewards to Uphold is temporarily unavailable.  Please try again later",
    "code": 400,
    "data": {
        "validationErrors": null
    }
}
Gemini Linking Toggle
POST /v3/wallet/gemini/<payment_id>/claim
...

HTTP2/0 400 Bad Request
{
    "message": "Error validating Connecting Brave Rewards to Gemini is temporarily unavailable.  Please try again later",
    "code": 400,
    "data": {
        "validationErrors": null
    }
}
Bitflyer Linking Toggle
POST /v3/wallet/bitflyer/<payment_id>/claim
...

HTTP2/0 400 Bad Request
{
    "message": "Error validating Connecting Brave Rewards to Bitflyer is temporarily unavailable.  Please try again later",
    "code": 400,
    "data": {
        "validationErrors": null
    }
}

Documentation

Overview

Package wallet is a generated GoMock package.

Index

Constants

View Source
const (
	// InvalidCurrency - wallet currency is invalid
	InvalidCurrency = "invalid"
	// BATCurrency - wallet currency is BAT
	BATCurrency = "BAT"
	// BTCCurrency - wallet currency is BTC
	BTCCurrency = "BTC"
	// ETHCurrency - wallet currency is ETH
	ETHCurrency = "ETH"
	// LTCCurrency - wallet currency is LTC
	LTCCurrency = "LTC"

	//UpholdProvider - provider label for uphold wallets
	UpholdProvider = "uphold"
	//BraveProvider - provider label for brave wallets
	BraveProvider = "brave"
)

Variables

View Source
var (
	// ErrTooManyCardsLinked denotes when more than 3 cards have been linked to a single wallet
	ErrTooManyCardsLinked = errors.New("unable to add too many wallets to a single user")
	// ErrNoReputationClient is returned when no reputation client is in the ctx.
	ErrNoReputationClient = errors.New("wallet: no reputation client")
)
View Source
var (
	// ErrUnusualActivity - error for wallets with unusual activity
	ErrUnusualActivity = errors.New("unusual activity")
	// ErrGeoResetDifferent - error for wallets with reset geo
	ErrGeoResetDifferent = errors.New("geo reset is different")
)
View Source
var (
	// ErrMissingSignedCreationRequest - required parameter missing from request
	ErrMissingSignedCreationRequest = errors.New("missing signed creation request")
	// ErrMissingSignedLinkingRequest - required parameter missing from request
	ErrMissingSignedLinkingRequest = errors.New("missing signed linking request")
	// ErrInvalidJSON - the input json is invalid
	ErrInvalidJSON = errors.New("invalid json")
	// ErrMissingLinkingInfo - required parameter missing from request
	ErrMissingLinkingInfo    = errors.New("missing linking information")
	ErrZebPayInvalidVrfToken = errors.New("failed to validate 'linking_info': must not be empty")
)
View Source
var (
	// ClaimNamespace uuidv5 namespace for provider linking - exported for tests
	ClaimNamespace = uuid.Must(uuid.FromString("c39b298b-b625-42e9-a463-69c7726e5ddc"))
)
View Source
var VerifiedWalletEnable = isVerifiedWalletEnable()

VerifiedWalletEnable enable verified wallet call

Functions

func CreateBraveWalletV3

func CreateBraveWalletV3(w http.ResponseWriter, r *http.Request) *handlers.AppError

CreateBraveWalletV3 - produces an http handler for the service s which handles creation of brave wallets

func CreateChallenge

func CreateChallenge(s *Service) handlers.AppHandler

func CreateUpholdWalletV3

func CreateUpholdWalletV3(w http.ResponseWriter, r *http.Request) *handlers.AppError

CreateUpholdWalletV3 produces a http handler for the service which handles creation of uphold wallets.

func CreateWalletV4

func CreateWalletV4(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

CreateWalletV4 creates a brave rewards wallet. This endpoint takes a geo country as part of the request that must be ISO3166Alpha2 format.

func DisconnectCustodianLinkV3

func DisconnectCustodianLinkV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

DisconnectCustodianLinkV3 - produces an http handler for the service s which handles disconnect state for a deposit account linking

func GetLinkingInfoV3

func GetLinkingInfoV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

GetLinkingInfoV3 - get linking metadata

func GetUpholdWalletBalanceV3

func GetUpholdWalletBalanceV3(w http.ResponseWriter, r *http.Request) *handlers.AppError

GetUpholdWalletBalanceV3 - produces an http handler for the service s which handles balance inquiries of uphold wallets

func GetUpholdWalletBalanceV4

func GetUpholdWalletBalanceV4(w http.ResponseWriter, r *http.Request) *handlers.AppError

GetUpholdWalletBalanceV4 produces an http handler for the service s which handles balance inquiries of uphold wallets

func GetWalletV3

func GetWalletV3(w http.ResponseWriter, r *http.Request) *handlers.AppError

GetWalletV3 returns a rewards wallet for the given paymentID.

func GetWalletV4

func GetWalletV4(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

func HandleErrorsZebPay

func HandleErrorsZebPay(err error) *handlers.AppError

HandleErrorsZebPay returns an AppError for the given err.

func LinkBitFlyerDepositAccountV3

func LinkBitFlyerDepositAccountV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

LinkBitFlyerDepositAccountV3 - produces an http handler for the service s which handles deposit account linking of uphold wallets

func LinkGeminiDepositAccountV3

func LinkGeminiDepositAccountV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

LinkGeminiDepositAccountV3 returns an HTTP handler which is responsible for linking a Gemini wallet. This endpoint expects a walletID as part of the URL and takes a verification token which encodes the linking information as well as a recipientID. The recipientID is synonymous with a wallets depositID.

func LinkSolanaAddress

func LinkSolanaAddress(s *Service) handlers.AppHandler

func LinkUpholdDepositAccountV3

func LinkUpholdDepositAccountV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

LinkUpholdDepositAccountV3 - produces an http handler for the service s which handles deposit account linking of uphold wallets

func LinkZebPayDepositAccountV3

func LinkZebPayDepositAccountV3(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

LinkZebPayDepositAccountV3 returns a handler which handles deposit account linking of zebpay wallets.

func NewDAppCorsMw

func NewDAppCorsMw(origins []string) func(next http.Handler) http.Handler

func NewPostgres

func NewPostgres() (Datastore, ReadOnlyDatastore, error)

NewPostgres creates postgres connections

func RecoverWalletV3

func RecoverWalletV3(w http.ResponseWriter, r *http.Request) *handlers.AppError

RecoverWalletV3 - produces an http handler for the service s which handles recovering of brave wallets

func RegisterRoutes

func RegisterRoutes(ctx context.Context, s *Service, r *chi.Mux, metricsMw middleware.InstrumentHandlerDef, dAppCorsMw func(next http.Handler) http.Handler) *chi.Mux

RegisterRoutes - register the wallet api routes given a chi.Mux

func ResponseV3ToInfo

func ResponseV3ToInfo(resp ResponseV3) *walletutils.Info

ResponseV3ToInfo converts a response v3 to wallet info

func UpdateWalletV4

func UpdateWalletV4(s *Service) func(w http.ResponseWriter, r *http.Request) *handlers.AppError

UpdateWalletV4 updates a brave rewards wallet. This endpoint takes a geo country as part of the request that must be ISO3166Alpha2 format.

Types

type BalanceResponseV3

type BalanceResponseV3 struct {
	Total       float64 `json:"total"`
	Spendable   float64 `json:"spendable"`
	Confirmed   float64 `json:"confirmed"`
	Unconfirmed float64 `json:"unconfirmed"`
}

BalanceResponseV3 - wallet creation response

type BitFlyerLinkingInfo

type BitFlyerLinkingInfo struct {
	DepositID         string    `json:"deposit_id"`
	RequestID         string    `json:"request_id"`
	AccountHash       string    `json:"account_hash"`
	ExternalAccountID string    `json:"external_account_id"`
	Timestamp         time.Time `json:"timestamp"`
}

BitFlyerLinkingInfo - jwt structure of the linking info

type BitFlyerLinkingRequest

type BitFlyerLinkingRequest struct {
	LinkingInfo string `json:"linkingInfo"`
	DepositID   string `json:"-"`
	AccountHash string `json:"-"`
}

BitFlyerLinkingRequest - the structure for a brave provider wallet creation request

func (*BitFlyerLinkingRequest) Decode

func (blr *BitFlyerLinkingRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*BitFlyerLinkingRequest) HandleErrors

func (blr *BitFlyerLinkingRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*BitFlyerLinkingRequest) Validate

func (blr *BitFlyerLinkingRequest) Validate(ctx context.Context) error

Validate - implementation of validatable interface

type BraveCreationRequest

type BraveCreationRequest struct{}

BraveCreationRequest - the structure for a brave provider wallet creation request

func (*BraveCreationRequest) Decode

func (bcr *BraveCreationRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*BraveCreationRequest) HandleErrors

func (bcr *BraveCreationRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*BraveCreationRequest) Validate

func (bcr *BraveCreationRequest) Validate(ctx context.Context) error

Validate - implementation of validatable interface

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config defines a GeoCountryValidator configuration.

type CustodianLink struct {
	WalletID       *uuid.UUID `json:"wallet_id" db:"wallet_id" valid:"uuidv4"`
	Custodian      string     `json:"custodian" db:"custodian" valid:"in(uphold,brave,gemini,bitflyer)"`
	CreatedAt      time.Time  `json:"created_at" db:"created_at" valid:"-"`
	UpdatedAt      *time.Time `json:"updated_at" db:"updated_at" valid:"-"`
	LinkedAt       time.Time  `json:"linked_at" db:"linked_at" valid:"-"`
	DisconnectedAt *time.Time `json:"disconnected_at" db:"disconnected_at" valid:"-"`
	LinkingID      *uuid.UUID `json:"linking_id" db:"linking_id" valid:"uuid"`
	UnlinkedAt     *time.Time `json:"unlinked_at" db:"unlinked_at" valid:"-"`
}

CustodianLink representation a wallet_custodian record.

func NewSolanaCustodialLink(walletID uuid.UUID, depositDestination string) *CustodianLink

func (*CustodianLink) GetLinkingIDString

func (cl *CustodianLink) GetLinkingIDString() string

GetLinkingIDString - get string version of the LinkingID

func (*CustodianLink) GetWalletIDString

func (cl *CustodianLink) GetWalletIDString() string

GetWalletIDString - get string version of the WalletID

type CustodianName

type CustodianName string

CustodianName - input validation for custodian name

func (*CustodianName) Decode

func (cn *CustodianName) Decode(ctx context.Context, v []byte) error

Decode - implement the decodable interface for this input

func (*CustodianName) String

func (cn *CustodianName) String() string

String - implement the stringer interface for this input

func (*CustodianName) Validate

func (cn *CustodianName) Validate(ctx context.Context) error

Validate - implement the validatable interface for this input

type DAppConfig

type DAppConfig struct {
	AllowedOrigins []string
}

type Datastore

type Datastore interface {
	datastore.Datastore
	LinkWallet(ctx context.Context, id string, providerID string, providerLinkingID uuid.UUID, depositProvider string) error
	GetLinkingLimitInfo(ctx context.Context, providerLinkingID string) (map[string]LinkingInfo, error)
	HasPriorLinking(ctx context.Context, walletID uuid.UUID, providerLinkingID uuid.UUID) (bool, error)
	// GetLinkingsByProviderLinkingID gets the wallet linking info by provider linking id
	GetLinkingsByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) ([]LinkingMetadata, error)
	// GetByProviderLinkingID gets the wallet by provider linking id
	GetByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (*[]walletutils.Info, error)
	// GetWallet by ID
	GetWallet(ctx context.Context, ID uuid.UUID) (*walletutils.Info, error)
	// GetWalletByPublicKey by ID
	GetWalletByPublicKey(context.Context, string) (*walletutils.Info, error)
	// InsertWallet inserts the given wallet
	InsertWallet(ctx context.Context, wallet *walletutils.Info) error
	// InsertWalletTx inserts the given wallet as part of provided sql.Tx transaction.
	InsertWalletTx(ctx context.Context, tx *sqlx.Tx, wallet *walletutils.Info) error
	// InsertBitFlyerRequestID - attempt an insert on a request id
	InsertBitFlyerRequestID(ctx context.Context, requestID string) error
	// UpsertWallet UpsertWallets inserts a wallet if it does not already exist
	UpsertWallet(ctx context.Context, wallet *walletutils.Info) error
	// ConnectCustodialWallet - connect the wallet's custodial verified wallet.
	ConnectCustodialWallet(ctx context.Context, cl *CustodianLink, depositDest string) error
	// DisconnectCustodialWallet - disconnect the wallet's custodial id
	DisconnectCustodialWallet(ctx context.Context, walletID uuid.UUID) error
	// GetCustodianLinkByWalletID retrieves the currently linked wallet custodian by walletID.
	GetCustodianLinkByWalletID(ctx context.Context, ID uuid.UUID) (*CustodianLink, error)
	// GetCustodianLinkCount - get the wallet custodian link count across all wallets
	GetCustodianLinkCount(ctx context.Context, linkingID uuid.UUID, custodian string) (int, int, error)
	// InsertVerifiedWalletOutboxTx inserts a verifiedWalletOutbox for processing.
	InsertVerifiedWalletOutboxTx(ctx context.Context, tx *sqlx.Tx, paymentID uuid.UUID, verifiedWallet bool) error
	// SendVerifiedWalletOutbox sends requests to reputation service.
	SendVerifiedWalletOutbox(ctx context.Context, client reputation.Client, retry backoff.RetryFunc) (bool, error)
}

Datastore holds the interface for the wallet datastore

func NewWritablePostgres

func NewWritablePostgres(databaseURL string, performMigration bool, migrationTrack string, dbStatsPrefix ...string) (Datastore, error)

NewWritablePostgres creates a new Postgres Datastore

type DatastoreWithPrometheus

type DatastoreWithPrometheus struct {
	// contains filtered or unexported fields
}

DatastoreWithPrometheus implements Datastore interface with all methods wrapped with Prometheus metrics

func NewDatastoreWithPrometheus

func NewDatastoreWithPrometheus(base Datastore, instanceName string) DatastoreWithPrometheus

NewDatastoreWithPrometheus returns an instance of the Datastore decorated with prometheus summary metric

func (DatastoreWithPrometheus) BeginTx

func (_d DatastoreWithPrometheus) BeginTx() (tp1 *sqlx.Tx, err error)

BeginTx implements Datastore

func (DatastoreWithPrometheus) ConnectCustodialWallet

func (_d DatastoreWithPrometheus) ConnectCustodialWallet(ctx context.Context, cl *CustodianLink, depositDest string) (err error)

ConnectCustodialWallet implements Datastore

func (DatastoreWithPrometheus) DisconnectCustodialWallet

func (_d DatastoreWithPrometheus) DisconnectCustodialWallet(ctx context.Context, walletID uuid.UUID) (err error)

DisconnectCustodialWallet implements Datastore

func (DatastoreWithPrometheus) GetByProviderLinkingID

func (_d DatastoreWithPrometheus) GetByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (iap1 *[]walletutils.Info, err error)

GetByProviderLinkingID implements Datastore

func (DatastoreWithPrometheus) GetCustodianLinkByWalletID

func (_d DatastoreWithPrometheus) GetCustodianLinkByWalletID(ctx context.Context, ID uuid.UUID) (cp1 *CustodianLink, err error)

GetCustodianLinkByWalletID implements Datastore

func (DatastoreWithPrometheus) GetCustodianLinkCount

func (_d DatastoreWithPrometheus) GetCustodianLinkCount(ctx context.Context, linkingID uuid.UUID, custodian string) (i1 int, i2 int, err error)

GetCustodianLinkCount implements Datastore

func (DatastoreWithPrometheus) GetLinkingLimitInfo

func (_d DatastoreWithPrometheus) GetLinkingLimitInfo(ctx context.Context, providerLinkingID string) (m1 map[string]LinkingInfo, err error)

GetLinkingLimitInfo implements Datastore

func (DatastoreWithPrometheus) GetLinkingsByProviderLinkingID

func (_d DatastoreWithPrometheus) GetLinkingsByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (la1 []LinkingMetadata, err error)

GetLinkingsByProviderLinkingID implements Datastore

func (DatastoreWithPrometheus) GetWallet

func (_d DatastoreWithPrometheus) GetWallet(ctx context.Context, ID uuid.UUID) (ip1 *walletutils.Info, err error)

GetWallet implements Datastore

func (DatastoreWithPrometheus) GetWalletByPublicKey

func (_d DatastoreWithPrometheus) GetWalletByPublicKey(ctx context.Context, s1 string) (ip1 *walletutils.Info, err error)

GetWalletByPublicKey implements Datastore

func (DatastoreWithPrometheus) HasPriorLinking

func (_d DatastoreWithPrometheus) HasPriorLinking(ctx context.Context, walletID uuid.UUID, providerLinkingID uuid.UUID) (b1 bool, err error)

HasPriorLinking implements Datastore

func (DatastoreWithPrometheus) InsertBitFlyerRequestID

func (_d DatastoreWithPrometheus) InsertBitFlyerRequestID(ctx context.Context, requestID string) (err error)

InsertBitFlyerRequestID implements Datastore

func (DatastoreWithPrometheus) InsertVerifiedWalletOutboxTx

func (_d DatastoreWithPrometheus) InsertVerifiedWalletOutboxTx(ctx context.Context, tx *sqlx.Tx, paymentID uuid.UUID, verifiedWallet bool) (err error)

InsertVerifiedWalletOutboxTx implements Datastore

func (DatastoreWithPrometheus) InsertWallet

func (_d DatastoreWithPrometheus) InsertWallet(ctx context.Context, wallet *walletutils.Info) (err error)

InsertWallet implements Datastore

func (DatastoreWithPrometheus) InsertWalletTx

func (_d DatastoreWithPrometheus) InsertWalletTx(ctx context.Context, tx *sqlx.Tx, wallet *walletutils.Info) (err error)

InsertWalletTx implements Datastore

func (DatastoreWithPrometheus) LinkWallet

func (_d DatastoreWithPrometheus) LinkWallet(ctx context.Context, id string, providerID string, providerLinkingID uuid.UUID, depositProvider string) (err error)

LinkWallet implements Datastore

func (DatastoreWithPrometheus) Migrate

func (_d DatastoreWithPrometheus) Migrate(p1 ...uint) (err error)

Migrate implements Datastore

func (DatastoreWithPrometheus) NewMigrate

func (_d DatastoreWithPrometheus) NewMigrate() (mp1 *migrate.Migrate, err error)

NewMigrate implements Datastore

func (DatastoreWithPrometheus) RawDB

func (_d DatastoreWithPrometheus) RawDB() (dp1 *sqlx.DB)

RawDB implements Datastore

func (DatastoreWithPrometheus) RollbackTx

func (_d DatastoreWithPrometheus) RollbackTx(tx *sqlx.Tx)

RollbackTx implements Datastore

func (DatastoreWithPrometheus) RollbackTxAndHandle

func (_d DatastoreWithPrometheus) RollbackTxAndHandle(tx *sqlx.Tx) (err error)

RollbackTxAndHandle implements Datastore

func (DatastoreWithPrometheus) SendVerifiedWalletOutbox

func (_d DatastoreWithPrometheus) SendVerifiedWalletOutbox(ctx context.Context, client reputation.Client, retry backoff.RetryFunc) (b1 bool, err error)

SendVerifiedWalletOutbox implements Datastore

func (DatastoreWithPrometheus) UpsertWallet

func (_d DatastoreWithPrometheus) UpsertWallet(ctx context.Context, wallet *walletutils.Info) (err error)

UpsertWallet implements Datastore

type DecodeEd25519Keystore

type DecodeEd25519Keystore struct{}

DecodeEd25519Keystore is a keystore that "looks up" a verifier by attempting to decode the keyID as a base64 encoded ed25519 public key

func (*DecodeEd25519Keystore) LookupVerifier

LookupVerifier by decoding keyID

type DepositAccountProviderDetailsV3

type DepositAccountProviderDetailsV3 struct {
	Name             *string `json:"name"`
	ID               *string `json:"id"`
	LinkingID        string  `json:"linkingId,omitempty"`
	AnonymousAddress string  `json:"anonymousAddress,omitempty"`
}

DepositAccountProviderDetailsV3 - details about the provider

type GeminiLinkingRequest

type GeminiLinkingRequest struct {
	VerificationToken string `json:"linking_info"`
	DepositID         string `json:"recipient_id"`
}

GeminiLinkingRequest holds info needed to link gemini account

func (*GeminiLinkingRequest) Decode

func (glr *GeminiLinkingRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*GeminiLinkingRequest) HandleErrors

func (glr *GeminiLinkingRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*GeminiLinkingRequest) Validate

func (glr *GeminiLinkingRequest) Validate(ctx context.Context) error

Validate - implementation of validatable interface

type GeoCountryValidator

type GeoCountryValidator struct {
	// contains filtered or unexported fields
}

GeoCountryValidator defines a GeoCountryValidator.

func NewGeoCountryValidator

func NewGeoCountryValidator(s3 appaws.S3GetObjectAPI, config Config) *GeoCountryValidator

NewGeoCountryValidator creates a new instance of NewGeoCountryValidator.

func (GeoCountryValidator) Validate

func (g GeoCountryValidator) Validate(ctx context.Context, geoCountry string) (bool, error)

Validate is an implementation of the Validate interface and returns true is a given geo country is valid.

type GeoValidator

type GeoValidator interface {
	Validate(ctx context.Context, geolocation string) (bool, error)
}

GeoValidator - interface describing validation of geolocation

type LinkBraveDepositAccountRequest

type LinkBraveDepositAccountRequest struct {
	DepositDestination string `json:"depositDestination"`
}

LinkBraveDepositAccountRequest - the structure for a linking request for uphold deposit account

func (*LinkBraveDepositAccountRequest) Decode

func (lbdar *LinkBraveDepositAccountRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*LinkBraveDepositAccountRequest) HandleErrors

func (lbdar *LinkBraveDepositAccountRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*LinkBraveDepositAccountRequest) Validate

func (lbdar *LinkBraveDepositAccountRequest) Validate(ctx context.Context) error

Validate - implementation of validatable interface

type LinkDepositAccountResponse

type LinkDepositAccountResponse struct {
	GeoCountry string `json:"geoCountry"`
}

LinkDepositAccountResponse is the response returned by the linking endpoints.

type LinkUpholdDepositAccountRequest

type LinkUpholdDepositAccountRequest struct {
	SignedLinkingRequest string `json:"signedLinkingRequest"`
	AnonymousAddress     string `json:"anonymousAddress"`
}

LinkUpholdDepositAccountRequest - the structure for a linking request for uphold deposit account

func (*LinkUpholdDepositAccountRequest) Decode

func (ludar *LinkUpholdDepositAccountRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*LinkUpholdDepositAccountRequest) HandleErrors

func (ludar *LinkUpholdDepositAccountRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*LinkUpholdDepositAccountRequest) Validate

Validate - implementation of validatable interface

type LinkingInfo

type LinkingInfo struct {
	LinkingID              *uuid.UUID        `json:"-"`
	NextAvailableUnlinking *time.Time        `json:"nextAvailableUnlinking,omitempty"`
	WalletsLinked          int               `json:"walletsLinked"`
	OpenLinkingSlots       int               `json:"openLinkingSlots"`
	OtherWalletsLinked     []LinkingMetadata `json:"otherWalletsLinked,omitempty"`
}

LinkingInfo - a structure for wallet linking information

type LinkingMetadata

type LinkingMetadata struct {
	WalletID       uuid.UUID  `json:"id" db:"wallet_id"`
	DisconnectedAt *time.Time `json:"disconnectedAt,omitempty" db:"disconnected_at"`
	LastLinkedAt   *time.Time `json:"lastLinkedAt,omitempty" db:"linked_at"`
	FirstLinkedAt  *time.Time `json:"firstLinkedAt,omitempty" db:"created_at"`
	UnLinkedAt     *time.Time `json:"unlinkedAt,omitempty" db:"unlinked_at"`
	Active         bool       `json:"active" db:"active"`
}

LinkingMetadata - show more details in linking info about the linkages

type MockGeoValidator

type MockGeoValidator struct {
	// contains filtered or unexported fields
}

MockGeoValidator is a mock of GeoValidator interface.

func NewMockGeoValidator

func NewMockGeoValidator(ctrl *gomock.Controller) *MockGeoValidator

NewMockGeoValidator creates a new mock instance.

func (*MockGeoValidator) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockGeoValidator) Validate

func (m *MockGeoValidator) Validate(ctx context.Context, geolocation string) (bool, error)

Validate mocks base method.

type MockGeoValidatorMockRecorder

type MockGeoValidatorMockRecorder struct {
	// contains filtered or unexported fields
}

MockGeoValidatorMockRecorder is the mock recorder for MockGeoValidator.

func (*MockGeoValidatorMockRecorder) Validate

func (mr *MockGeoValidatorMockRecorder) Validate(ctx, geolocation interface{}) *gomock.Call

Validate indicates an expected call of Validate.

type MockmetricSvc

type MockmetricSvc struct {
	// contains filtered or unexported fields
}

MockmetricSvc is a mock of metricSvc interface.

func NewMockmetricSvc

func NewMockmetricSvc(ctrl *gomock.Controller) *MockmetricSvc

NewMockmetricSvc creates a new mock instance.

func (*MockmetricSvc) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockmetricSvc) LinkFailureZP

func (m *MockmetricSvc) LinkFailureZP(cc string)

LinkFailureZP mocks base method.

func (*MockmetricSvc) LinkSuccessZP

func (m *MockmetricSvc) LinkSuccessZP(cc string)

LinkSuccessZP mocks base method.

type MockmetricSvcMockRecorder

type MockmetricSvcMockRecorder struct {
	// contains filtered or unexported fields
}

MockmetricSvcMockRecorder is the mock recorder for MockmetricSvc.

func (*MockmetricSvcMockRecorder) LinkFailureZP

func (mr *MockmetricSvcMockRecorder) LinkFailureZP(cc interface{}) *gomock.Call

LinkFailureZP indicates an expected call of LinkFailureZP.

func (*MockmetricSvcMockRecorder) LinkSuccessZP

func (mr *MockmetricSvcMockRecorder) LinkSuccessZP(cc interface{}) *gomock.Call

LinkSuccessZP indicates an expected call of LinkSuccessZP.

type Postgres

type Postgres struct {
	datastore.Postgres
}

Postgres is a Datastore wrapper around a postgres database

func (*Postgres) ConnectCustodialWallet

func (pg *Postgres) ConnectCustodialWallet(ctx context.Context, cl *CustodianLink, depositDest string) error

ConnectCustodialWallet - create a record of a custodian wallet

func (*Postgres) DisconnectCustodialWallet

func (pg *Postgres) DisconnectCustodialWallet(ctx context.Context, walletID uuid.UUID) error

DisconnectCustodialWallet - disconnect the wallet's custodial id

func (*Postgres) GetByProviderLinkingID

func (pg *Postgres) GetByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (*[]walletutils.Info, error)

GetByProviderLinkingID gets a wallet by a provider address

func (*Postgres) GetCustodianLinkByWalletID

func (pg *Postgres) GetCustodianLinkByWalletID(ctx context.Context, ID uuid.UUID) (*CustodianLink, error)

GetCustodianLinkByWalletID retrieves the currently linked wallet custodian by walletID.

func (*Postgres) GetCustodianLinkCount

func (pg *Postgres) GetCustodianLinkCount(ctx context.Context, linkingID uuid.UUID, custodian string) (int, int, error)

GetCustodianLinkCount - get the wallet custodian link count across all wallets

func (*Postgres) GetLinkingLimitInfo

func (pg *Postgres) GetLinkingLimitInfo(ctx context.Context, providerLinkingID string) (map[string]LinkingInfo, error)

GetLinkingLimitInfo - get some basic info about linking limit

func (*Postgres) GetLinkingsByProviderLinkingID

func (pg *Postgres) GetLinkingsByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) ([]LinkingMetadata, error)

GetLinkingsByProviderLinkingID gets wallet linkings by a provider address

func (*Postgres) GetWallet

func (pg *Postgres) GetWallet(ctx context.Context, ID uuid.UUID) (*walletutils.Info, error)

GetWallet retrieves a wallet by its walletID, if no wallet is found then nil is returned.

func (*Postgres) GetWalletByPublicKey

func (pg *Postgres) GetWalletByPublicKey(ctx context.Context, pk string) (*walletutils.Info, error)

GetWalletByPublicKey gets a wallet by a public key

func (*Postgres) HasPriorLinking

func (pg *Postgres) HasPriorLinking(ctx context.Context, walletID uuid.UUID, providerLinkingID uuid.UUID) (bool, error)

HasPriorLinking - check if this wallet id has been linked to this provider linking id in the past

func (*Postgres) InsertBitFlyerRequestID

func (pg *Postgres) InsertBitFlyerRequestID(ctx context.Context, requestID string) error

InsertBitFlyerRequestID - attempts to insert a request id

func (*Postgres) InsertVerifiedWalletOutboxTx

func (pg *Postgres) InsertVerifiedWalletOutboxTx(ctx context.Context, tx *sqlx.Tx, walletID uuid.UUID, verifiedWallet bool) error

InsertVerifiedWalletOutboxTx inserts a verifiedWalletOutbox for processing.

func (*Postgres) InsertWallet

func (pg *Postgres) InsertWallet(ctx context.Context, wallet *walletutils.Info) error

InsertWallet inserts the given wallet

func (*Postgres) InsertWalletTx

func (pg *Postgres) InsertWalletTx(ctx context.Context, tx *sqlx.Tx, wallet *walletutils.Info) error

InsertWalletTx inserts the given wallet

func (*Postgres) LinkWallet

func (pg *Postgres) LinkWallet(ctx context.Context, id string, userDepositDestination string, providerLinkingID uuid.UUID, depositProvider string) error

LinkWallet links a rewards wallet to the given deposit provider.

func (*Postgres) SendVerifiedWalletOutbox

func (pg *Postgres) SendVerifiedWalletOutbox(ctx context.Context, client reputation.Client, retry backoff.RetryFunc) (bool, error)

SendVerifiedWalletOutbox sends requests to reputation service.

func (*Postgres) UpsertWallet

func (pg *Postgres) UpsertWallet(ctx context.Context, wallet *walletutils.Info) error

UpsertWallet upserts the given wallet

type ProviderDetailsV3

type ProviderDetailsV3 struct {
	ID               string `json:"id"`
	Name             string `json:"name"`
	LinkingID        string `json:"linkingId,omitempty"`
	AnonymousAddress string `json:"anonymousAddress,omitempty"`
}

ProviderDetailsV3 - details about the provider

type ReadOnlyDatastore

type ReadOnlyDatastore interface {
	datastore.Datastore
	HasPriorLinking(ctx context.Context, walletID uuid.UUID, providerLinkingID uuid.UUID) (bool, error)
	// GetLinkingsByProviderLinkingID gets the wallet linking info by provider linking id
	GetLinkingsByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) ([]LinkingMetadata, error)
	// GetByProviderLinkingID gets a wallet by provider linking id
	GetByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (*[]walletutils.Info, error)
	// GetWallet by ID
	GetWallet(ctx context.Context, ID uuid.UUID) (*walletutils.Info, error)
	// GetWalletByPublicKey retrieves a wallet by its public key.
	GetWalletByPublicKey(context.Context, string) (*walletutils.Info, error)
	// GetCustodianLinkCount - get the wallet custodian link count across all wallets
	GetCustodianLinkCount(ctx context.Context, linkingID uuid.UUID, custodian string) (int, int, error)
}

ReadOnlyDatastore includes all database methods that can be made with a read only db connection

func NewReadOnlyPostgres

func NewReadOnlyPostgres(databaseURL string, performMigration bool, migrationTrack string, dbStatsPrefix ...string) (ReadOnlyDatastore, error)

NewReadOnlyPostgres creates a new Postgres RO Datastore

type ReadOnlyDatastoreWithPrometheus

type ReadOnlyDatastoreWithPrometheus struct {
	// contains filtered or unexported fields
}

ReadOnlyDatastoreWithPrometheus implements ReadOnlyDatastore interface with all methods wrapped with Prometheus metrics

func NewReadOnlyDatastoreWithPrometheus

func NewReadOnlyDatastoreWithPrometheus(base ReadOnlyDatastore, instanceName string) ReadOnlyDatastoreWithPrometheus

NewReadOnlyDatastoreWithPrometheus returns an instance of the ReadOnlyDatastore decorated with prometheus summary metric

func (ReadOnlyDatastoreWithPrometheus) BeginTx

func (_d ReadOnlyDatastoreWithPrometheus) BeginTx() (tp1 *sqlx.Tx, err error)

BeginTx implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) GetByProviderLinkingID

func (_d ReadOnlyDatastoreWithPrometheus) GetByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (iap1 *[]walletutils.Info, err error)

GetByProviderLinkingID implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) GetCustodianLinkCount

func (_d ReadOnlyDatastoreWithPrometheus) GetCustodianLinkCount(ctx context.Context, linkingID uuid.UUID, custodian string) (i1 int, i2 int, err error)

GetCustodianLinkCount implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) GetLinkingsByProviderLinkingID

func (_d ReadOnlyDatastoreWithPrometheus) GetLinkingsByProviderLinkingID(ctx context.Context, providerLinkingID uuid.UUID) (la1 []LinkingMetadata, err error)

GetLinkingsByProviderLinkingID implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) GetWallet

func (_d ReadOnlyDatastoreWithPrometheus) GetWallet(ctx context.Context, ID uuid.UUID) (ip1 *walletutils.Info, err error)

GetWallet implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) GetWalletByPublicKey

func (_d ReadOnlyDatastoreWithPrometheus) GetWalletByPublicKey(ctx context.Context, s1 string) (ip1 *walletutils.Info, err error)

GetWalletByPublicKey implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) HasPriorLinking

func (_d ReadOnlyDatastoreWithPrometheus) HasPriorLinking(ctx context.Context, walletID uuid.UUID, providerLinkingID uuid.UUID) (b1 bool, err error)

HasPriorLinking implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) Migrate

func (_d ReadOnlyDatastoreWithPrometheus) Migrate(p1 ...uint) (err error)

Migrate implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) NewMigrate

func (_d ReadOnlyDatastoreWithPrometheus) NewMigrate() (mp1 *migrate.Migrate, err error)

NewMigrate implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) RawDB

func (_d ReadOnlyDatastoreWithPrometheus) RawDB() (dp1 *sqlx.DB)

RawDB implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) RollbackTx

func (_d ReadOnlyDatastoreWithPrometheus) RollbackTx(tx *sqlx.Tx)

RollbackTx implements ReadOnlyDatastore

func (ReadOnlyDatastoreWithPrometheus) RollbackTxAndHandle

func (_d ReadOnlyDatastoreWithPrometheus) RollbackTxAndHandle(tx *sqlx.Tx) (err error)

RollbackTxAndHandle implements ReadOnlyDatastore

type ResponseV3

type ResponseV3 struct {
	PaymentID              string                           `json:"paymentId"`
	DepositAccountProvider *DepositAccountProviderDetailsV3 `json:"depositAccountProvider,omitempty"`
	WalletProvider         *ProviderDetailsV3               `json:"walletProvider,omitempty"`
	AltCurrency            string                           `json:"altcurrency"`
	PublicKey              string                           `json:"publicKey"`
}

ResponseV3 - wallet creation response

type ResponseV4

type ResponseV4 struct {
	PaymentID              string                           `json:"paymentId"`
	DepositAccountProvider *DepositAccountProviderDetailsV3 `json:"depositAccountProvider,omitempty"`
	WalletProvider         *ProviderDetailsV3               `json:"walletProvider,omitempty"`
	AltCurrency            string                           `json:"altcurrency"`
	PublicKey              string                           `json:"publicKey"`
	SelfCustodyAvailable   map[string]bool                  `json:"selfCustodyAvailable"`
}

ResponseV4 - wallet creation response

type Service

type Service struct {
	Datastore   Datastore
	RoDatastore ReadOnlyDatastore
	// contains filtered or unexported fields
}

Service contains datastore connections

func InitService

func InitService(
	datastore Datastore,
	roDatastore ReadOnlyDatastore,
	chlRepo challengeRepo,
	allowList allowListRepo,
	repClient reputation.Client,
	geminiClient gemini.Client,
	geoCountryValidator GeoValidator,
	retry backoff.RetryFunc,
	metric metricSvc,
	gemini geminiSvc,
	dappConf DAppConfig) (*Service, error)

InitService creates a new instances of the wallet service.

func SetupService

func SetupService(ctx context.Context) (context.Context, *Service)

SetupService - create a new wallet service

func (*Service) CreateChallenge

func (service *Service) CreateChallenge(ctx context.Context, paymentID uuid.UUID) (model.Challenge, error)

func (*Service) CreateRewardsWallet

func (service *Service) CreateRewardsWallet(ctx context.Context, publicKey string, geoCountry string) (*walletutils.Info, error)

CreateRewardsWallet creates a brave rewards wallet and informs the reputation service. If either the local transaction or call to the reputation service fails then the wallet is not created.

func (service *Service) DisconnectCustodianLink(ctx context.Context, custodian string, walletID uuid.UUID) error

DisconnectCustodianLink - removes the link to the custodian wallet that is active

func (*Service) GetLinkingInfo

func (service *Service) GetLinkingInfo(ctx context.Context, providerLinkingID, custodianID string) (map[string]LinkingInfo, error)

GetLinkingInfo - Get data about the linking info

func (*Service) GetWallet

func (service *Service) GetWallet(ctx context.Context, ID uuid.UUID) (*walletutils.Info, error)

GetWallet - get a wallet by id

func (*Service) Jobs

func (service *Service) Jobs() []srv.Job

Jobs - Implement srv.JobService interface

func (*Service) LinkBitFlyerWallet

func (service *Service) LinkBitFlyerWallet(ctx context.Context, walletID uuid.UUID, depositID, accountHash string) (string, error)

LinkBitFlyerWallet links a wallet and transfers funds to newly linked wallet

func (*Service) LinkGeminiWallet

func (service *Service) LinkGeminiWallet(ctx context.Context, walletID uuid.UUID, verificationToken, depositID string) (string, error)

LinkGeminiWallet links a wallet to a Gemini account.

func (*Service) LinkSolanaAddress

func (service *Service) LinkSolanaAddress(ctx context.Context, paymentID uuid.UUID, req linkSolanaAddrRequest) error

func (*Service) LinkUpholdWallet

func (service *Service) LinkUpholdWallet(ctx context.Context, wallet uphold.Wallet, transaction string, _ *uuid.UUID) (string, error)

LinkUpholdWallet links an uphold.Wallet and transfers funds.

func (*Service) LinkZebPayWallet

func (service *Service) LinkZebPayWallet(ctx context.Context, walletID uuid.UUID, verificationToken string) (string, error)

LinkZebPayWallet links a wallet and transfers funds to newly linked wallet.

func (*Service) LookupVerifier

func (service *Service) LookupVerifier(ctx context.Context, keyID string) (context.Context, *httpsignature.Verifier, error)

LookupVerifier based on the HTTP signing keyID, which in our case is the walletID

func (*Service) ReadableDatastore

func (service *Service) ReadableDatastore() ReadOnlyDatastore

ReadableDatastore returns a read only datastore if available, otherwise a normal datastore

func (*Service) RefreshCustodianRegionsWorker

func (service *Service) RefreshCustodianRegionsWorker(ctx context.Context) (bool, error)

RefreshCustodianRegionsWorker - get the custodian regions from the merge param bucket

func (*Service) RunVerifiedWalletWorker

func (service *Service) RunVerifiedWalletWorker(ctx context.Context) (bool, error)

func (*Service) SubmitAnonCardTransaction

func (service *Service) SubmitAnonCardTransaction(
	ctx context.Context,
	walletID uuid.UUID,
	transaction string,
	destination string,
) (*walletutils.TransactionInfo, error)

SubmitAnonCardTransaction validates and submits a transaction on behalf of an anonymous card

func (*Service) SubmitCommitableAnonCardTransaction

func (service *Service) SubmitCommitableAnonCardTransaction(
	ctx context.Context,
	info *walletutils.Info,
	transaction string,
	destination string,
	confirm bool,
) (*walletutils.TransactionInfo, error)

SubmitCommitableAnonCardTransaction submits a transaction

type UpholdCreationRequest

type UpholdCreationRequest struct {
	SignedCreationRequest string `json:"signedCreationRequest"`
	PublicKey             string `json:"-"`
}

UpholdCreationRequest - the structure for a brave provider wallet creation request

func (*UpholdCreationRequest) Decode

func (ucr *UpholdCreationRequest) Decode(ctx context.Context, v []byte) error

Decode - implementation of decodable interface

func (*UpholdCreationRequest) HandleErrors

func (ucr *UpholdCreationRequest) HandleErrors(err error) *handlers.AppError

HandleErrors - handle any errors from this request

func (*UpholdCreationRequest) Validate

func (ucr *UpholdCreationRequest) Validate(ctx context.Context) error

Validate - implementation of validatable interface

type V4Request

type V4Request struct {
	GeoCountry string `json:"geoCountry"`
}

V4Request contains the fields for making v4 wallet requests.

type V4Response

type V4Response struct {
	PaymentID string `json:"paymentId"`
}

V4Response contains the fields for v4 wallet responses.

type ZebPayLinkingRequest

type ZebPayLinkingRequest struct {
	VerificationToken string `json:"linking_info"`
}

ZebPayLinkingRequest holds info needed to link zebpay account.

func (*ZebPayLinkingRequest) Decode

func (r *ZebPayLinkingRequest) Decode(ctx context.Context, v []byte) error

Decode implements DecodeValidate interface.

func (*ZebPayLinkingRequest) Validate

func (r *ZebPayLinkingRequest) Validate(ctx context.Context) error

Validate implements DecodeValidate interface.

Directories

Path Synopsis
Package wallettest provides utilities for testing wallets.
Package wallettest provides utilities for testing wallets.

Jump to

Keyboard shortcuts

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