antispam

package
v1.10.14 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Guard

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

Guard is an antispam guard that checks whether operations of interest are allowed to be performed.

Note: Implementation assumes distributed locking has already occurred for all methods.

func NewGuard

func NewGuard(
	data code_data.Provider,
	deviceVerifier device.Verifier,
	maxmind *maxminddb.Reader,
	opts ...Option,
) *Guard

func (*Guard) AllowCheckSmsVerificationCode

func (g *Guard) AllowCheckSmsVerificationCode(ctx context.Context, phoneNumber string) (bool, error)

AllowCheckSmsVerificationCode determines whether a phone number is allowed to check a SMS verification code.

func (*Guard) AllowEstablishNewRelationship

func (g *Guard) AllowEstablishNewRelationship(ctx context.Context, owner *common.Account, relationshipTo string) (bool, error)

AllowEstablishNewRelationship determines whether a phone-verified owner account is allowed to establish a new relationship

func (*Guard) AllowLinkAccount

func (g *Guard) AllowLinkAccount(ctx context.Context, ownerAccount *common.Account, phoneNumber string) (bool, error)

AllowLinkAccount determines whether an identity is allowed to link to an account.

todo: this needs tests

func (*Guard) AllowNewPhoneVerification

func (g *Guard) AllowNewPhoneVerification(ctx context.Context, phoneNumber string, deviceToken *string) (bool, Reason, error)

AllowNewPhoneVerification determines whether a phone is allowed to start a new verification flow.

func (*Guard) AllowOpenAccounts

func (g *Guard) AllowOpenAccounts(ctx context.Context, owner *common.Account, deviceToken *string) (bool, Reason, func() error, error)

AllowOpenAccounts determines whether a phone-verified owner account can create a Code account via an open accounts intent. The objective here is to limit attacks against our Subsidizer's SOL balance.

func (*Guard) AllowReceivePayments

func (g *Guard) AllowReceivePayments(ctx context.Context, owner *common.Account, isPublic bool) (bool, error)

AllowReceivePayments determines whether a phone-verified owner account is allowed to make a public/private receive payments intent. The objective is to limit pressure on the scheduling layer.

func (*Guard) AllowReferralBonus

func (g *Guard) AllowReferralBonus(
	ctx context.Context,
	referrerOwner,
	onboardedOwner,
	airdropperOwner *common.Account,
	quarksGivenByReferrer uint64,
	exchangedIn currency.Code,
	nativeAmount float64,
) (bool, error)

AllowReferralBonus determines whether a phone-verified owner account can receive a referral bonus. The objective here is to limit attacks against our airdropper's Kin balance.

todo: This needs tests

func (*Guard) AllowSendPayment

func (g *Guard) AllowSendPayment(ctx context.Context, owner *common.Account, isPublic bool, destination *common.Account) (bool, error)

AllowSendPayment determines whether a phone-verified owner account is allowed to make a send public/private payment intent. The objective is to limit pressure on the scheduling layer.

func (*Guard) AllowSendSmsVerificationCode

func (g *Guard) AllowSendSmsVerificationCode(ctx context.Context, phoneNumber string) (bool, error)

AllowSendSmsVerificationCode determines whether a phone number can be sent a verification code over SMS.

func (*Guard) AllowSwap added in v1.3.0

func (g *Guard) AllowSwap(ctx context.Context, owner *common.Account) (bool, error)

AllowSwap determines whether a phone-verified owner account can perform a swap. The objective here is to limit attacks against our Swap Subsidizer's SOL balance.

todo: needs tests

func (*Guard) AllowWelcomeBonus

func (g *Guard) AllowWelcomeBonus(ctx context.Context, owner *common.Account) (bool, error)

AllowWelcomeBonus determines whether a phone-verified owner account can receive the welcome bonus. The objective here is to limit attacks against our airdropper's Kin balance.

todo: This needs tests

type Option

type Option func(c *conf)

Option configures a Guard with an overrided configuration value

func WithAndroidDevs added in v1.1.0

func WithAndroidDevs(phoneNumbers ...string) Option

WithAndroidDevs configures a set of open source Android devs that get to bypass certain antispam measures to enable testing. Android is currently behind the latest antispam system requirements, and will fail things like device attestation.

func WithDailyPaymentLimit

func WithDailyPaymentLimit(limit uint64) Option

WithDailyPaymentLimit overrides the default daily payment limit. The value specifies the maximum number of payments that can initiated per phone number per day.

func WithFiveMinutePaymentLimit

func WithFiveMinutePaymentLimit(limit uint64) Option

WithFiveMinutePaymentLimit overrides the default five minute payment limit. The value specifies the maximum number of payments that can initiated per phone number per five minutes.

func WithHourlyPaymentLimit

func WithHourlyPaymentLimit(limit uint64) Option

WithHourlyPaymentLimit overrides the default hourly payment limit. The value specifies the maximum number of payments that can initiated per phone number per hour.

func WithMaxNewRelationshipsPerDay

func WithMaxNewRelationshipsPerDay(limit uint64) Option

WithMaxNewRelationshipsPerDay overrides the default maximum number of new relationships a phone number can create per day.

func WithMaxReferralsPerDay

func WithMaxReferralsPerDay(limit uint64) Option

WithMaxReferralsPerDay overrides the default maximum referrals per day. The value specifies the maximum number of times a user can be given a referral bonus in a day.

func WithMinReferralAmount

func WithMinReferralAmount(amount uint64) Option

WithMinReferralAmount overrides the default minimum referral amount. The value specifies the minimum amount that must be given to a new user to consider a referral bonus.

func WithPaymentRateLimit

func WithPaymentRateLimit(d time.Duration) Option

WithPaymentRateLimit overrides the default payment rate limit. The value specifies the minimum time between payments per phone number.

func WithPhoneVerificationInterval

func WithPhoneVerificationInterval(d time.Duration) Option

WithPhoneVerificationInterval overrides the default phone verification interval. The value specifies the time window at which unique verifications are evaluated per phone number.

func WithPhoneVerificationsPerInterval

func WithPhoneVerificationsPerInterval(limit uint64) Option

WithPhoneVerificationsPerInterval overrides the default number of phone verifications in an interval. The value specifies the number of unique phone verifications that can happen within the configurable time window per phone number.

func WithRestrictedMobileCountryCodes

func WithRestrictedMobileCountryCodes(mccs ...int) Option

WithRestrictedMobileCountryCodes overrides the default set of restricted mobile country codes. The values specify the mobile country codes with restricted access to prevent spam waves from problematic regions.

func WithRestrictedMobileNetworkCodes

func WithRestrictedMobileNetworkCodes(mncs ...int) Option

WithRestrictedMobileNetworkCodes overrides the default set of restricted mobile network codes. The values specify the mobile network codes with restricted access to prevent attacks from fraudulent operators.

todo: Need to be careful with these. MNC may not be unique to a MCC. The ones provided here don't exist anywhere.

func WithTimePerSmsVerificationCheck

func WithTimePerSmsVerificationCheck(d time.Duration) Option

WithTimePerSmsVerificationCheck overrides the default time per SMS verifications codes checked. The value specifies the minimum time that must be waited to consecutively check SMS verification codes per phone number.

func WithTimePerSmsVerificationCodeSend

func WithTimePerSmsVerificationCodeSend(d time.Duration) Option

WithTimePerSmsVerificationCodeSend overrides the default time per SMS verifications codes sent. The value specifies the minimum time that must be waited to send consecutive SMS verification codes per phone number.

type Reason added in v1.10.10

type Reason int
const (
	ReasonUnspecified Reason = iota
	ReasonUnsupportedCountry
	ReasonUnsupportedDevice
	ReasonTooManyFreeAccountsForPhoneNumber
	ReasonTooManyFreeAccountsForDevice
)

Jump to

Keyboard shortcuts

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