Skip to content

Commit

Permalink
added option to disable kyc steps 1 and 2 based on device
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-ares committed Nov 22, 2023
1 parent 71e6e93 commit de89fab
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/goccy/go-json v0.10.2
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.184.0
github.com/ice-blockchain/eskimo v1.185.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.125.0
github.com/imroc/req/v3 v3.42.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ice-blockchain/eskimo v1.184.0 h1:TvSthb7/tiaTUE34+ejDWmIDytNHE1gsHIrVCPrGQcw=
github.com/ice-blockchain/eskimo v1.184.0/go.mod h1:wjt+BudjNYu6y2wRwUK8HKgPPPTi77WLRUG2Sp4ZCZM=
github.com/ice-blockchain/eskimo v1.185.0 h1:+qXOktkEnlDmE0wOiLZC6Tcp5wp4eJdbCZeHSsaY4uA=
github.com/ice-blockchain/eskimo v1.185.0/go.mod h1:wjt+BudjNYu6y2wRwUK8HKgPPPTi77WLRUG2Sp4ZCZM=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.125.0 h1:pk/SVyztstUF19+JDCufJRMXJeNpchVA4O26xp47l3Y=
Expand Down
3 changes: 2 additions & 1 deletion tokenomics/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ type (

kycConfigJSON struct {
FaceAuth struct {
Enabled bool `json:"enabled"`
DisabledVersions []string `json:"disabledVersions"`
Enabled bool `json:"enabled"`
} `json:"face-auth"`
WebFaceAuth struct {
Enabled bool `json:"enabled"`
Expand Down
36 changes: 30 additions & 6 deletions tokenomics/kyc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *repository) syncKYCConfigJSON(ctx context.Context) error {
if err = json.UnmarshalContext(ctx, data, &kycConfig); err != nil {
return errors.Wrapf(err, "failed to unmarshal into %#v, data: %v", kycConfig, string(data))
}
if kycConfig == (kycConfigJSON{}) {
if !kycConfig.FaceAuth.Enabled && len(kycConfig.FaceAuth.DisabledVersions) == 0 && !kycConfig.WebFaceAuth.Enabled {
if body := string(data); !strings.Contains(body, "face-auth") && !strings.Contains(body, "web-face-auth") {
return errors.Errorf("there's something wrong with the KYCConfigJSON body: %v", body)
}
Expand All @@ -103,7 +103,7 @@ func (r *repository) validateKYC(ctx context.Context, state *getCurrentMiningSes
if err := r.overrideKYCStateWithEskimoKYCState(ctx, state.UserID, &state.KYCState); err != nil {
return errors.Wrapf(err, "failed to overrideKYCStateWithEskimoKYCState for %#v", state)
}
if state.KYCStepBlocked > 0 && r.isKYCEnabled(ctx, users.FacialRecognitionKYCStep) {
if state.KYCStepBlocked > 0 && r.isKYCEnabled(ctx, state.LatestDevice, users.FacialRecognitionKYCStep) {
return terror.New(ErrMiningDisabled, map[string]any{
"kycStepBlocked": state.KYCStepBlocked,
})
Expand All @@ -115,13 +115,13 @@ func (r *repository) validateKYC(ctx context.Context, state *getCurrentMiningSes
isAfterFirstWindow = time.Now().Sub(*r.livenessLoadDistributionStartDate.Time) > r.cfg.KYC.LivenessDelay
isReservedForToday = r.cfg.KYC.LivenessDelay <= r.cfg.MiningSessionDuration.Max || isAfterFirstWindow || int64((time.Now().Sub(*r.livenessLoadDistributionStartDate.Time)%r.cfg.KYC.LivenessDelay)/r.cfg.MiningSessionDuration.Max) == state.ID%int64(r.cfg.KYC.LivenessDelay/r.cfg.MiningSessionDuration.Max) //nolint:lll // .
)
if atLeastOneMiningStarted && isReservedForToday && r.isKYCEnabled(ctx, users.FacialRecognitionKYCStep) {
if atLeastOneMiningStarted && isReservedForToday && r.isKYCEnabled(ctx, state.LatestDevice, users.FacialRecognitionKYCStep) {
return terror.New(ErrKYCRequired, map[string]any{
"kycSteps": []users.KYCStep{users.FacialRecognitionKYCStep, users.LivenessDetectionKYCStep},
})
}
case users.FacialRecognitionKYCStep:
if r.isKYCEnabled(ctx, users.LivenessDetectionKYCStep) {
if r.isKYCEnabled(ctx, state.LatestDevice, users.LivenessDetectionKYCStep) {
return terror.New(ErrKYCRequired, map[string]any{
"kycSteps": []users.KYCStep{users.LivenessDetectionKYCStep},
})
Expand All @@ -133,7 +133,7 @@ func (r *repository) validateKYC(ctx context.Context, state *getCurrentMiningSes
isNetworkDelayAdjusted = timeSinceLivenessLastFinished >= r.cfg.MiningSessionDuration.Min
isReservedForToday = r.cfg.KYC.LivenessDelay > r.cfg.MiningSessionDuration.Max && int64((time.Now().Sub(*r.livenessLoadDistributionStartDate.Time)%r.cfg.KYC.LivenessDelay)/r.cfg.MiningSessionDuration.Max) == state.ID%int64(r.cfg.KYC.LivenessDelay/r.cfg.MiningSessionDuration.Max) //nolint:lll // .
)
if isNetworkDelayAdjusted && (isAfterDelay || isReservedForToday) && r.isKYCEnabled(ctx, users.LivenessDetectionKYCStep) {
if isNetworkDelayAdjusted && (isAfterDelay || isReservedForToday) && r.isKYCEnabled(ctx, state.LatestDevice, users.LivenessDetectionKYCStep) {
return terror.New(ErrKYCRequired, map[string]any{
"kycSteps": []users.KYCStep{users.LivenessDetectionKYCStep},
})
Expand All @@ -143,7 +143,7 @@ func (r *repository) validateKYC(ctx context.Context, state *getCurrentMiningSes
return nil
}

func (r *repository) isKYCEnabled(ctx context.Context, _ users.KYCStep) bool {
func (r *repository) isKYCEnabled(ctx context.Context, latestDevice string, _ users.KYCStep) bool {
var (
kycConfig = r.cfg.kycConfigJSON.Load()
isWeb = isWebClientType(ctx)
Expand All @@ -157,6 +157,30 @@ func (r *repository) isKYCEnabled(ctx context.Context, _ users.KYCStep) bool {
return false
}

if !isWeb && kycConfig.FaceAuth.Enabled && !r.isFaceAuthEnabledForDevice(latestDevice) {
return false
}

return true
}

func (r *repository) isFaceAuthEnabledForDevice(device string) bool {
if device == "" {
return true
}
var disableFaceAuthFor []string
if cfgVal := r.cfg.kycConfigJSON.Load(); cfgVal != nil {
disableFaceAuthFor = cfgVal.FaceAuth.DisabledVersions
}
if len(disableFaceAuthFor) == 0 {
return true
}
for _, disabled := range disableFaceAuthFor {
if strings.EqualFold(device, disabled) {
return false
}
}

return true
}

Expand Down
1 change: 1 addition & 0 deletions tokenomics/mining_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type (
getCurrentMiningSession struct {
KYCState
StartOrExtendMiningSession
model.LatestDeviceField
model.UserIDField
model.SlashingRateSoloField
model.SlashingRateT0Field
Expand Down

0 comments on commit de89fab

Please sign in to comment.