forked from fox-one/mixin-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpin.go
40 lines (30 loc) · 765 Bytes
/
pin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package mixin
import (
"context"
"fmt"
"regexp"
)
func (c *Client) VerifyPin(ctx context.Context, pin string) error {
body := map[string]interface{}{
"pin": c.EncryptPin(pin),
}
return c.Post(ctx, "/pin/verify", body, nil)
}
func (c *Client) ModifyPin(ctx context.Context, pin, newPin string) error {
body := map[string]interface{}{}
if pin != "" {
body["old_pin"] = c.EncryptPin(pin)
}
body["pin"] = c.EncryptPin(newPin)
return c.Post(ctx, "/pin/update", body, nil)
}
var (
pinRegex = regexp.MustCompile(`^\d{6}$`)
)
// ValidatePinPattern validate the pin with pinRegex
func ValidatePinPattern(pin string) error {
if !pinRegex.MatchString(pin) {
return fmt.Errorf("pin must match regex pattern %q", pinRegex.String())
}
return nil
}