-
Notifications
You must be signed in to change notification settings - Fork 10
/
gateway.go
52 lines (43 loc) · 1.82 KB
/
gateway.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
package gateway
import (
"context"
"github.com/kwilteam/kwil-db/core/crypto/auth"
jsonrpc "github.com/kwilteam/kwil-db/core/rpc/json"
"github.com/kwilteam/kwil-db/core/types"
)
// Client is the interface for the Kwil gateway client.
type Client interface {
// Authn sends an authentication request to the gateway.
// It will set a cookie in the client if successful.
Authn(ctx context.Context, req *AuthnRequest) error
// GetAuthnParameter returns the parameters that will be used to compose the
// authentication message that will be signed by the client.
GetAuthnParameter(ctx context.Context) (*AuthnParameterResponse, error)
}
// AuthnRequest is a request for authentication from the kgw.
type AuthnRequest struct {
Nonce string `json:"nonce"` // identifier for authn session
Sender types.HexBytes `json:"sender"` // sender public key
Signature *auth.Signature `json:"signature"`
}
type AuthnResponse struct{}
type AuthnParameterRequest struct{}
// AuthnParameterResponse defines the result when request for gateway(KGW)
// authentication. It's the parameters that will be used to compose the
// message(SIWE like) to sign.
type AuthnParameterResponse struct {
Nonce string `json:"nonce"`
Statement string `json:"statement"` // optional
IssueAt string `json:"issue_at"`
ExpirationTime string `json:"expiration_time"`
// client can use those to precheck before signing
ChainID string `json:"chain_id"` // the chain id of the gateway
Domain string `json:"domain"` // the domain of the gateway
Version string `json:"version"` // the authn version used by the gateway
URI string `json:"uri"` // the endpoint used for authn
}
const (
MethodAuthn jsonrpc.Method = "kgw.authn"
MethodAuthnParam jsonrpc.Method = "kgw.authn_param"
//MethodLogout jsonrpc.Method = "kgw.logout"
)