-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverify.go
55 lines (46 loc) · 1.55 KB
/
verify.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package server
import (
"github.com/bitcoin-sv/go-paymail/errors"
"github.com/gin-gonic/gin"
"net/http"
"github.com/bitcoin-sv/go-paymail"
)
// verifyPubKey will return a response if the pubkey matches the paymail given
//
// Specs: https://bsvalias.org/05-verify-public-key-owner.html
func (c *Configuration) verifyPubKey(context *gin.Context) {
incomingPaymail := context.Param(PaymailAddressParamName)
incomingPubKey := context.Param(PubKeyParamName)
// Parse, sanitize and basic validation
alias, domain, address := paymail.SanitizePaymail(incomingPaymail)
if len(address) == 0 {
errors.ErrorResponse(context, errors.ErrInvalidPaymail, c.Logger)
return
} else if !c.IsAllowedDomain(domain) {
errors.ErrorResponse(context, errors.ErrDomainUnknown, c.Logger)
return
}
// Basic validation on pubkey
if len(incomingPubKey) != paymail.PubKeyLength {
errors.ErrorResponse(context, errors.ErrInvalidPubKey, c.Logger)
return
}
// Create the metadata struct
md := CreateMetadata(context.Request, alias, domain, "")
// Get from the data layer
foundPaymail, err := c.actions.GetPaymailByAlias(context.Request.Context(), alias, domain, md)
if err != nil {
errors.ErrorResponse(context, err, c.Logger)
return
} else if foundPaymail == nil {
errors.ErrorResponse(context, errors.ErrCouldNotFindPaymail, c.Logger)
return
}
verPayload := paymail.VerificationPayload{
BsvAlias: c.BSVAliasVersion,
Handle: address,
PubKey: foundPaymail.PubKey,
Match: foundPaymail.PubKey == incomingPubKey,
}
context.JSON(http.StatusOK, verPayload)
}