Skip to content

Commit

Permalink
Merge pull request #2 from Miguelo981/dev
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
Miguelo981 authored Dec 1, 2022
2 parents e4e0e5c + b7512e6 commit 1f8526f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ req.user = await User.findOne({ decoded.Address });
```

---
...

## API

### Descrypt(signer, options)
Expand Down
22 changes: 11 additions & 11 deletions verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

type SignedParams struct {
Domain string
}
}

func SplitSections (lines []string) [][]string {
func SplitSections(lines []string) [][]string {
var sections [][]string
sectionNumber := 0
for i, _ := range lines {
for i, _ := range lines {
line := lines[i]
sections = append(sections, []string{line})
//sections[sectionNumber].push(line)
Expand All @@ -28,7 +28,7 @@ func SplitSections (lines []string) [][]string {

func GetDomain(sections [][]string) string {
if strings.Contains(sections[0][0], "wants you to sign in with your Ethereum account") {
return strings.ReplaceAll(strings.ReplaceAll(sections[0][0], " wants you to sign in with your Ethereum account.",""), " ", "")
return strings.ReplaceAll(strings.ReplaceAll(sections[0][0], " wants you to sign in with your Ethereum account.", ""), " ", "")
}

return ""
Expand All @@ -55,7 +55,7 @@ func ParseBody(lines []string) map[string]string {
for _, v := range lines {
keyValues := strings.Split(v, ":")
newKey := strings.ToLower(strings.Replace(keyValues[0], " ", "-", -1))
parsedBody[newKey] = strings.Replace(v, keyValues[0] + ": ", "", 1)
parsedBody[newKey] = strings.Replace(v, keyValues[0]+": ", "", 1)
}

domain := GetDomain(sections)
Expand All @@ -72,7 +72,7 @@ func ParseBody(lines []string) map[string]string {
return parsedBody
}

func Verify(token string, params SignedParams) (*DecryptedToken, error) {
func Verify(token string, params SignedParams) (*DecryptedToken, error) {
decryptedToken, err := Decrypt(token)
if err != nil {
return nil, err
Expand All @@ -87,13 +87,13 @@ func Verify(token string, params SignedParams) (*DecryptedToken, error) {

decryptedToken.Body = parsedBody

date, err := time.Parse(time.RFC3339Nano, parsedBody["expiration-time"])
if err == nil || date.After(time.Now()) {
date, _ := time.Parse(time.RFC3339Nano, parsedBody["expiration-time"])
if !time.Time.IsZero(date) && time.Now().After(date) {
return nil, errors.New("Token expired")
}

date, err = time.Parse(time.RFC3339Nano, parsedBody["not-before"])
if err == nil || parsedBody["not-before"] != "" && date.Before(time.Now()) {
date, _ = time.Parse(time.RFC3339Nano, parsedBody["not-before"])
if !time.Time.IsZero(date) && parsedBody["not-before"] != "" && time.Now().Before(date) {
return nil, errors.New("It's not yet time to use the token")
}

Expand All @@ -102,4 +102,4 @@ func Verify(token string, params SignedParams) (*DecryptedToken, error) {
}

return decryptedToken, nil
}
}

0 comments on commit 1f8526f

Please sign in to comment.