2023-03-23 11:44:15 +00:00
|
|
|
package pairing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
"crypto/tls"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SenderConfig struct {
|
|
|
|
// SenderConfig.KeystorePath must end with keyUID
|
2023-03-29 15:51:01 +00:00
|
|
|
KeystorePath string `json:"keystorePath" validate:"required,keystorepath"`
|
2023-03-23 11:44:15 +00:00
|
|
|
// DeviceType SendPairInstallation need this information
|
2023-03-29 15:51:01 +00:00
|
|
|
DeviceType string `json:"deviceType" validate:"required"`
|
2023-03-23 11:44:15 +00:00
|
|
|
|
2023-06-09 13:15:28 +00:00
|
|
|
KeyUID string `json:"keyUID" validate:"required,keyuid"`
|
|
|
|
Password string `json:"password" validate:"required"`
|
|
|
|
ChatKey string `json:"chatKey"` // set only in case of a Keycard user, otherwise empty
|
|
|
|
KeycardPairings string `json:"keycardPairings"`
|
2023-03-23 11:44:15 +00:00
|
|
|
|
|
|
|
DB *multiaccounts.Database `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReceiverConfig struct {
|
2023-03-29 15:51:01 +00:00
|
|
|
// nodeConfig is required, but we'll validate it separately
|
2023-03-23 11:44:15 +00:00
|
|
|
NodeConfig *params.NodeConfig `json:"nodeConfig"`
|
|
|
|
|
|
|
|
// ReceiverConfig.KeystorePath must not end with keyUID (because keyUID is not known yet)
|
2023-03-29 15:51:01 +00:00
|
|
|
KeystorePath string `json:"keystorePath" validate:"required,not_end_keyuid"`
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
// DeviceType SendPairInstallation need this information
|
2023-03-29 15:51:01 +00:00
|
|
|
DeviceType string `json:"deviceType" validate:"required"`
|
|
|
|
KDFIterations int `json:"kdfIterations" validate:"gte=0"`
|
|
|
|
|
2023-03-23 11:44:15 +00:00
|
|
|
// SettingCurrentNetwork corresponding to field current_network from table settings, so that we can override current network from sender
|
2023-03-29 15:51:01 +00:00
|
|
|
SettingCurrentNetwork string `json:"settingCurrentNetwork" validate:"required"`
|
2023-03-23 11:44:15 +00:00
|
|
|
|
|
|
|
DB *multiaccounts.Database `json:"-"`
|
|
|
|
LoggedInKeyUID string `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServerConfig struct {
|
|
|
|
// Timeout the number of milliseconds after which the pairing server will automatically terminate
|
2023-03-29 15:51:01 +00:00
|
|
|
Timeout uint `json:"timeout" validate:"omitempty,gte=0"`
|
2023-03-23 11:44:15 +00:00
|
|
|
|
|
|
|
// Connection fields, not json (un)marshalled
|
|
|
|
// Required for the server, but MUST NOT come from client
|
|
|
|
|
|
|
|
PK *ecdsa.PublicKey `json:"-"`
|
|
|
|
EK []byte `json:"-"`
|
|
|
|
Cert *tls.Certificate `json:"-"`
|
|
|
|
Hostname string `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ClientConfig struct{}
|
|
|
|
|
|
|
|
type SenderServerConfig struct {
|
2023-03-29 15:51:01 +00:00
|
|
|
SenderConfig *SenderConfig `json:"senderConfig" validate:"required"`
|
|
|
|
ServerConfig *ServerConfig `json:"serverConfig" validate:"omitempty,dive"`
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SenderClientConfig struct {
|
2023-03-29 15:51:01 +00:00
|
|
|
SenderConfig *SenderConfig `json:"senderConfig" validate:"required"`
|
2023-03-23 11:44:15 +00:00
|
|
|
ClientConfig *ClientConfig `json:"clientConfig"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReceiverClientConfig struct {
|
2023-03-29 15:51:01 +00:00
|
|
|
ReceiverConfig *ReceiverConfig `json:"receiverConfig" validate:"required"`
|
2023-03-23 11:44:15 +00:00
|
|
|
ClientConfig *ClientConfig `json:"clientConfig"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReceiverServerConfig struct {
|
2023-03-29 15:51:01 +00:00
|
|
|
ReceiverConfig *ReceiverConfig `json:"receiverConfig" validate:"required"`
|
|
|
|
ServerConfig *ServerConfig `json:"serverConfig" validate:"omitempty,dive"`
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSenderServerConfig() *SenderServerConfig {
|
|
|
|
return &SenderServerConfig{
|
|
|
|
SenderConfig: new(SenderConfig),
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSenderClientConfig() *SenderClientConfig {
|
|
|
|
return &SenderClientConfig{
|
|
|
|
SenderConfig: new(SenderConfig),
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewReceiverClientConfig() *ReceiverClientConfig {
|
|
|
|
return &ReceiverClientConfig{
|
|
|
|
ReceiverConfig: new(ReceiverConfig),
|
|
|
|
ClientConfig: new(ClientConfig),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewReceiverServerConfig() *ReceiverServerConfig {
|
|
|
|
return &ReceiverServerConfig{
|
|
|
|
ReceiverConfig: new(ReceiverConfig),
|
|
|
|
ServerConfig: new(ServerConfig),
|
|
|
|
}
|
|
|
|
}
|