|
1 | 1 | package authenticate
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "net/http"
|
5 | 6 | "os"
|
6 | 7 |
|
7 | 8 | "github.com/NetSepio/erebrus/api/v1/authenticate/challengeid"
|
8 | 9 | "github.com/NetSepio/erebrus/util/pkg/auth"
|
9 | 10 | "github.com/NetSepio/erebrus/util/pkg/claims"
|
10 |
| - "github.com/NetSepio/erebrus/util/pkg/cryptosign" |
| 11 | + "github.com/NetSepio/gateway/util/pkg/logwrapper" |
| 12 | + "github.com/TheLazarusNetwork/go-helpers/httpo" |
11 | 13 |
|
12 | 14 | "github.com/gin-gonic/gin"
|
13 | 15 | log "github.com/sirupsen/logrus"
|
@@ -38,27 +40,95 @@ func authenticate(c *gin.Context) {
|
38 | 40 | }
|
39 | 41 | userAuthEULA := os.Getenv("AUTH_EULA")
|
40 | 42 | message := userAuthEULA + req.ChallengeId
|
41 |
| - walletAddress, isCorrect, err := cryptosign.CheckSign(req.Signature, req.ChallengeId, message) |
| 43 | + // walletAddress, isCorrect, err := cryptosign.CheckSign(req.Signature, req.ChallengeId, message) |
42 | 44 |
|
43 |
| - if err == cryptosign.ErrFlowIdNotFound { |
44 |
| - log.WithFields(log.Fields{ |
45 |
| - "err": err, |
46 |
| - }).Error("FlowId Not Found") |
47 |
| - errResponse := ErrAuthenticate(err.Error()) |
48 |
| - c.JSON(http.StatusNotFound, errResponse) |
49 |
| - return |
50 |
| - } |
| 45 | + // if err == cryptosign.ErrChallangeIdNotFound { |
| 46 | + // log.WithFields(log.Fields{ |
| 47 | + // "err": err, |
| 48 | + // }).Error("FlowId Not Found") |
| 49 | + // errResponse := ErrAuthenticate(err.Error()) |
| 50 | + // c.JSON(http.StatusNotFound, errResponse) |
| 51 | + // return |
| 52 | + // } |
51 | 53 |
|
52 |
| - if err != nil { |
53 |
| - log.WithFields(log.Fields{ |
54 |
| - "err": err, |
55 |
| - }).Error("failed to CheckSignature") |
56 |
| - errResponse := ErrAuthenticate(err.Error()) |
57 |
| - c.JSON(http.StatusInternalServerError, errResponse) |
58 |
| - return |
| 54 | + // if err != nil { |
| 55 | + // log.WithFields(log.Fields{ |
| 56 | + // "err": err, |
| 57 | + // }).Error("failed to CheckSignature") |
| 58 | + // errResponse := ErrAuthenticate(err.Error()) |
| 59 | + // c.JSON(http.StatusInternalServerError, errResponse) |
| 60 | + // return |
| 61 | + // } |
| 62 | + |
| 63 | + var ( |
| 64 | + isCorrect bool |
| 65 | + // userId string |
| 66 | + walletAddr string |
| 67 | + ) |
| 68 | + |
| 69 | + switch req.ChainName { |
| 70 | + case "EVM", "PEAQ": |
| 71 | + userAuthEULA := userAuthEULA |
| 72 | + message := userAuthEULA + req.ChallengeId |
| 73 | + walletAddr, isCorrect, err = CheckSignEth(req.Signature, req.ChallengeId, message) |
| 74 | + |
| 75 | + if err == ErrChallangeIdNotFound { |
| 76 | + httpo.NewErrorResponse(http.StatusNotFound, "Challange Id not found") |
| 77 | + return |
| 78 | + } |
| 79 | + |
| 80 | + if err != nil { |
| 81 | + logwrapper.Errorf("failed to CheckSignature, error %v", err.Error()) |
| 82 | + httpo.NewErrorResponse(http.StatusInternalServerError, "Unexpected error occurred").SendD(c) |
| 83 | + return |
| 84 | + } |
| 85 | + |
| 86 | + case "APTOS": |
| 87 | + userAuthEULA := userAuthEULA |
| 88 | + message := fmt.Sprintf("APTOS\nmessage: %v\nnonce: %v", userAuthEULA, req.ChallengeId) |
| 89 | + walletAddr, isCorrect, err = CheckSign(req.Signature, req.ChallengeId, message, req.PubKey) |
| 90 | + |
| 91 | + if err == ErrChallangeIdNotFound { |
| 92 | + httpo.NewErrorResponse(http.StatusNotFound, "Challange Id not found") |
| 93 | + return |
| 94 | + } |
| 95 | + |
| 96 | + if err != nil { |
| 97 | + logwrapper.Errorf("failed to CheckSignature, error %v", err.Error()) |
| 98 | + httpo.NewErrorResponse(http.StatusInternalServerError, "Unexpected error occurred").SendD(c) |
| 99 | + return |
| 100 | + } |
| 101 | + |
| 102 | + case "SUI": |
| 103 | + walletAddr, isCorrect, err = CheckSignSui(req.Signature, req.ChallengeId) |
| 104 | + |
| 105 | + if err == ErrChallangeIdNotFound { |
| 106 | + httpo.NewErrorResponse(http.StatusNotFound, "Challange Id not found") |
| 107 | + return |
| 108 | + } |
| 109 | + |
| 110 | + if err != nil { |
| 111 | + logwrapper.Errorf("failed to CheckSignature, error %v", err.Error()) |
| 112 | + httpo.NewErrorResponse(http.StatusInternalServerError, "Unexpected error occurred").SendD(c) |
| 113 | + return |
| 114 | + } |
| 115 | + |
| 116 | + case "SOLANA": |
| 117 | + walletAddr, isCorrect, err = CheckSignSol(req.Signature, req.ChallengeId, message, req.PubKey) |
| 118 | + |
| 119 | + if err == ErrChallangeIdNotFound { |
| 120 | + httpo.NewErrorResponse(http.StatusNotFound, "Challange Id not found") |
| 121 | + return |
| 122 | + } |
| 123 | + |
| 124 | + if err != nil { |
| 125 | + logwrapper.Errorf("failed to CheckSignature, error %v", err.Error()) |
| 126 | + httpo.NewErrorResponse(http.StatusInternalServerError, "Unexpected error occurred").SendD(c) |
| 127 | + return |
| 128 | + } |
59 | 129 | }
|
60 | 130 | if isCorrect {
|
61 |
| - customClaims := claims.New(walletAddress) |
| 131 | + customClaims := claims.New(walletAddr) |
62 | 132 | pasetoToken, err := auth.GenerateTokenPaseto(customClaims)
|
63 | 133 | if err != nil {
|
64 | 134 | log.WithFields(log.Fields{
|
|
0 commit comments