-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpki.go
44 lines (36 loc) · 1.19 KB
/
pki.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
package server
import (
"github.com/bitcoin-sv/go-paymail/errors"
"github.com/gin-gonic/gin"
"net/http"
"github.com/bitcoin-sv/go-paymail"
)
// showPKI will return the public key information for the corresponding paymail address
//
// Specs: http://bsvalias.org/03-public-key-infrastructure.html
func (c *Configuration) showPKI(context *gin.Context) {
incomingPaymail := context.Param(PaymailAddressParamName)
alias, domain, address := paymail.SanitizePaymail(incomingPaymail)
if len(address) == 0 {
errors.ErrorResponse(context, errors.ErrDomainUnknown, c.Logger)
return
} else if !c.IsAllowedDomain(domain) {
errors.ErrorResponse(context, errors.ErrDomainUnknown, c.Logger)
return
}
md := CreateMetadata(context.Request, alias, domain, "")
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
}
pkiPayload := paymail.PKIPayload{
BsvAlias: c.BSVAliasVersion,
Handle: address,
PubKey: foundPaymail.PubKey,
}
context.JSON(http.StatusOK, pkiPayload)
}