-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
40 lines (32 loc) · 833 Bytes
/
context.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 http
import (
"context"
"fmt"
"github.com/gorilla/mux"
"github.com/lugondev/tx-builder/pkg/utils"
"github.com/lugondev/wallet-signer-manager/pkg/common"
"net/http"
"strings"
)
type ctxKeyType string
const storeNameCtxKey ctxKeyType = "storeName"
func WithStoreName(ctx context.Context, name string) context.Context {
return context.WithValue(ctx, storeNameCtxKey, name)
}
func StoreNameFromContext(ctx context.Context) string {
name, ok := ctx.Value(storeNameCtxKey).(string)
if ok {
return name
}
return ""
}
func generateRandomKeyID() string {
return fmt.Sprintf("%s%s", "signer", common.RandString(15))
}
func getPubkey(request *http.Request) string {
pubkey, err := utils.ParseHexToCompressedPublicKey(mux.Vars(request)["pubkey"])
if err != nil {
return ""
}
return strings.ToLower(pubkey)
}