Added StartUpPairingClient and refactored client endpoints
This commit is contained in:
parent
9fda3a968e
commit
67088b1ab1
|
@ -893,21 +893,9 @@ func GetConnectionStringForBeingBootstrapped(configJSON string) string {
|
|||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
return cs
|
||||
}
|
||||
|
||||
// SetConnectionStringForBootstrappingAnotherDevice starts a server.Receiving server.PairingClient
|
||||
// Used when the device is Logged in and therefore has Account keys and the has a camera to read a QR code
|
||||
//
|
||||
// Example: A mobile (device with camera) sending account data to a desktop device (device without camera)
|
||||
func SetConnectionStringForBootstrappingAnotherDevice(cs, configJSON string) string {
|
||||
if configJSON != "" {
|
||||
return makeJSONResponse(fmt.Errorf("no config given, PairingPayloadSourceConfig is expected"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// GetConnectionStringForBootstrappingAnotherDevice starts a server.Sending server.PairingServer
|
||||
// then generates a server.ConnectionParams. Used when the device is Logged in and therefore has Account keys
|
||||
// and the device might not have a camera
|
||||
|
@ -923,18 +911,27 @@ func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string
|
|||
if err != nil {
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
||||
return cs
|
||||
}
|
||||
|
||||
// InputQRCodeForBeingBootstrapped starts a server.Sending server.PairingClient
|
||||
// InputConnectionStringForBootstrapping starts a server.PairingClient
|
||||
// The given server.ConnectionParams string will determine the server.Mode
|
||||
//
|
||||
// server.Mode = server.Sending
|
||||
// Used when the device is Logged in and therefore has Account keys and the has a camera to read a QR code
|
||||
//
|
||||
// Example: A mobile (device with camera) sending account data to a desktop device (device without camera)
|
||||
//
|
||||
// server.Mode = server.Receiving
|
||||
// Used when the device is Logged out or has no Account keys and has a camera to read a QR code
|
||||
//
|
||||
// Example: A mobile device (device with a camera) receiving account data from
|
||||
// a device with a screen (mobile or desktop devices)
|
||||
func InputQRCodeForBeingBootstrapped(cs, configJSON string) string {
|
||||
func InputConnectionStringForBootstrapping(cs, configJSON string) string {
|
||||
if configJSON != "" {
|
||||
return makeJSONResponse(fmt.Errorf("no config given, PairingPayloadSourceConfig is expected"))
|
||||
}
|
||||
|
||||
err := server.StartUpPairingClient(statusBackend.GetMultiaccountDB(), cs, configJSON)
|
||||
return makeJSONResponse(err)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/ecdsa"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
@ -13,6 +14,8 @@ import (
|
|||
"net/url"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
|
||||
"github.com/status-im/status-go/multiaccounts"
|
||||
)
|
||||
|
||||
type PairingClient struct {
|
||||
|
@ -161,3 +164,21 @@ func (c *PairingClient) getChallenge() error {
|
|||
c.serverChallenge, err = ioutil.ReadAll(resp.Body)
|
||||
return err
|
||||
}
|
||||
|
||||
func StartUpPairingClient(db *multiaccounts.Database, cs, configJSON string) error {
|
||||
var conf PairingPayloadSourceConfig
|
||||
err := json.Unmarshal([]byte(configJSON), &conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ccp := new(ConnectionParams)
|
||||
err = ccp.FromString(cs)
|
||||
|
||||
c, err := NewPairingClient(ccp, &PairingPayloadManagerConfig{db, conf})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.PairAccount()
|
||||
}
|
||||
|
|
|
@ -129,6 +129,7 @@ func (s *PairingServer) startSendingAccountData() error {
|
|||
return s.Start()
|
||||
}
|
||||
|
||||
// MakeFullPairingServer generates a fully configured and randomly seeded PairingServer
|
||||
func MakeFullPairingServer(db *multiaccounts.Database, mode Mode, storeConfig PairingPayloadSourceConfig) (*PairingServer, error) {
|
||||
tlsKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
if err != nil {
|
||||
|
@ -171,6 +172,8 @@ func MakeFullPairingServer(db *multiaccounts.Database, mode Mode, storeConfig Pa
|
|||
})
|
||||
}
|
||||
|
||||
// StartUpPairingServer generates a PairingServer, starts the pairing server in the correct mode
|
||||
// and returns the ConnectionParams string to allow a PairingClient to make a successful connection.
|
||||
func StartUpPairingServer(db *multiaccounts.Database, mode Mode, configJSON string) (string, error) {
|
||||
var conf PairingPayloadSourceConfig
|
||||
err := json.Unmarshal([]byte(configJSON), &conf)
|
||||
|
|
Loading…
Reference in New Issue