Documentation ¶
Index ¶
- type Guard
- func (g *Guard) AllowCheckSmsVerificationCode(ctx context.Context, phoneNumber string) (bool, error)
- func (g *Guard) AllowEstablishNewRelationship(ctx context.Context, owner *common.Account, relationshipTo string) (bool, error)
- func (g *Guard) AllowLinkAccount(ctx context.Context, ownerAccount *common.Account, phoneNumber string) (bool, error)
- func (g *Guard) AllowNewPhoneVerification(ctx context.Context, phoneNumber string, deviceToken *string) (bool, Reason, error)
- func (g *Guard) AllowOpenAccounts(ctx context.Context, owner *common.Account, deviceToken *string) (bool, Reason, func() error, error)
- func (g *Guard) AllowReceivePayments(ctx context.Context, owner *common.Account, isPublic bool) (bool, error)
- func (g *Guard) AllowReferralBonus(ctx context.Context, ...) (bool, error)
- func (g *Guard) AllowSendPayment(ctx context.Context, owner *common.Account, isPublic bool, ...) (bool, error)
- func (g *Guard) AllowSendSmsVerificationCode(ctx context.Context, phoneNumber string) (bool, error)
- func (g *Guard) AllowSwap(ctx context.Context, owner *common.Account) (bool, error)
- func (g *Guard) AllowWelcomeBonus(ctx context.Context, owner *common.Account) (bool, error)
- type Option
- func WithAndroidDevs(phoneNumbers ...string) Option
- func WithDailyPaymentLimit(limit uint64) Option
- func WithFiveMinutePaymentLimit(limit uint64) Option
- func WithHourlyPaymentLimit(limit uint64) Option
- func WithMaxNewRelationshipsPerDay(limit uint64) Option
- func WithMaxReferralsPerDay(limit uint64) Option
- func WithMinReferralAmount(amount uint64) Option
- func WithPaymentRateLimit(d time.Duration) Option
- func WithPhoneVerificationInterval(d time.Duration) Option
- func WithPhoneVerificationsPerInterval(limit uint64) Option
- func WithRestrictedMobileCountryCodes(mccs ...int) Option
- func WithRestrictedMobileNetworkCodes(mncs ...int) Option
- func WithTimePerSmsVerificationCheck(d time.Duration) Option
- func WithTimePerSmsVerificationCodeSend(d time.Duration) Option
- type Reason
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 (*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 ¶
AllowSendSmsVerificationCode determines whether a phone number can be sent a verification code over SMS.
func (*Guard) AllowSwap ¶ added in v1.3.0
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
WithMaxNewRelationshipsPerDay overrides the default maximum number of new relationships a phone number can create per day.
func WithMaxReferralsPerDay ¶
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 ¶
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 ¶
WithPaymentRateLimit overrides the default payment rate limit. The value specifies the minimum time between payments per phone number.
func WithPhoneVerificationInterval ¶
WithPhoneVerificationInterval overrides the default phone verification interval. The value specifies the time window at which unique verifications are evaluated per phone number.
func WithPhoneVerificationsPerInterval ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.