2019-02-01 17:02:52 +00:00
|
|
|
package statusgo
|
|
|
|
|
|
|
|
import (
|
2019-02-15 11:31:20 +00:00
|
|
|
"encoding/hex"
|
2019-02-01 17:02:52 +00:00
|
|
|
"encoding/json"
|
2019-03-04 14:33:48 +00:00
|
|
|
"errors"
|
2019-02-01 17:02:52 +00:00
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
|
|
|
|
2024-10-28 20:54:17 +00:00
|
|
|
"go.uber.org/zap"
|
2020-01-02 09:10:19 +00:00
|
|
|
validator "gopkg.in/go-playground/validator.v9"
|
|
|
|
|
2022-10-25 14:25:08 +00:00
|
|
|
"github.com/ethereum/go-ethereum/signer/core/apitypes"
|
2020-01-02 09:10:19 +00:00
|
|
|
|
2022-03-18 12:20:13 +00:00
|
|
|
"github.com/status-im/zxcvbn-go"
|
2022-03-23 14:19:19 +00:00
|
|
|
"github.com/status-im/zxcvbn-go/scoring"
|
2022-03-18 12:20:13 +00:00
|
|
|
|
2022-08-24 12:42:41 +00:00
|
|
|
abi_spec "github.com/status-im/status-go/abi-spec"
|
2024-02-19 12:53:01 +00:00
|
|
|
"github.com/status-im/status-go/account"
|
2019-02-01 17:02:52 +00:00
|
|
|
"github.com/status-im/status-go/api"
|
2020-06-23 10:47:17 +00:00
|
|
|
"github.com/status-im/status-go/api/multiformat"
|
2024-07-03 11:51:14 +00:00
|
|
|
"github.com/status-im/status-go/centralizedmetrics"
|
|
|
|
"github.com/status-im/status-go/centralizedmetrics/providers"
|
2022-10-25 09:32:26 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-03-04 14:33:48 +00:00
|
|
|
"github.com/status-im/status-go/exportlogs"
|
2022-08-07 07:35:54 +00:00
|
|
|
"github.com/status-im/status-go/extkeys"
|
2022-04-06 11:08:52 +00:00
|
|
|
"github.com/status-im/status-go/images"
|
2023-07-12 22:29:38 +00:00
|
|
|
"github.com/status-im/status-go/logutils"
|
2024-09-13 15:08:20 +00:00
|
|
|
"github.com/status-im/status-go/logutils/requestlog"
|
2024-11-19 09:31:29 +00:00
|
|
|
m_requests "github.com/status-im/status-go/mobile/requests"
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts"
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-03-23 18:47:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2019-02-01 17:02:52 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
|
|
|
"github.com/status-im/status-go/profiling"
|
2023-03-16 14:49:25 +00:00
|
|
|
"github.com/status-im/status-go/protocol"
|
2022-10-25 09:32:26 +00:00
|
|
|
"github.com/status-im/status-go/protocol/common"
|
2022-04-08 17:54:29 +00:00
|
|
|
identityUtils "github.com/status-im/status-go/protocol/identity"
|
2022-02-17 15:13:10 +00:00
|
|
|
"github.com/status-im/status-go/protocol/identity/alias"
|
2022-03-17 16:58:35 +00:00
|
|
|
"github.com/status-im/status-go/protocol/identity/colorhash"
|
|
|
|
"github.com/status-im/status-go/protocol/identity/emojihash"
|
2023-03-16 14:49:25 +00:00
|
|
|
"github.com/status-im/status-go/protocol/requests"
|
2022-02-23 14:34:16 +00:00
|
|
|
"github.com/status-im/status-go/server"
|
2023-01-06 12:21:14 +00:00
|
|
|
"github.com/status-im/status-go/server/pairing"
|
2023-06-02 03:05:51 +00:00
|
|
|
"github.com/status-im/status-go/server/pairing/preflight"
|
2019-02-01 17:02:52 +00:00
|
|
|
"github.com/status-im/status-go/services/personal"
|
2019-03-04 13:45:27 +00:00
|
|
|
"github.com/status-im/status-go/services/typeddata"
|
2024-11-05 21:28:24 +00:00
|
|
|
"github.com/status-im/status-go/services/wallet/wallettypes"
|
2019-02-01 17:02:52 +00:00
|
|
|
"github.com/status-im/status-go/signal"
|
2024-10-29 12:30:14 +00:00
|
|
|
|
|
|
|
"github.com/status-im/status-go/mobile/callog"
|
2019-02-01 17:02:52 +00:00
|
|
|
)
|
|
|
|
|
2024-10-29 12:30:14 +00:00
|
|
|
func call(fn any, params ...any) any {
|
2024-11-04 08:09:28 +00:00
|
|
|
return callog.Call(logutils.ZapLogger(), requestlog.GetRequestLogger(), fn, params...)
|
2024-10-29 12:30:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func callWithResponse(fn any, params ...any) string {
|
2024-11-04 08:09:28 +00:00
|
|
|
return callog.CallWithResponse(logutils.ZapLogger(), requestlog.GetRequestLogger(), fn, params...)
|
2024-10-29 12:30:14 +00:00
|
|
|
}
|
|
|
|
|
2024-07-03 11:51:14 +00:00
|
|
|
type InitializeApplicationResponse struct {
|
|
|
|
Accounts []multiaccounts.Account `json:"accounts"`
|
|
|
|
CentralizedMetricsInfo *centralizedmetrics.MetricsInfo `json:"centralizedMetricsInfo"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitializeApplication(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(initializeApplication, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initializeApplication(requestJSON string) string {
|
2024-07-03 11:51:14 +00:00
|
|
|
var request requests.InitializeApplication
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize metrics
|
|
|
|
providers.MixpanelAppID = request.MixpanelAppID
|
|
|
|
providers.MixpanelToken = request.MixpanelToken
|
|
|
|
|
2024-11-22 02:23:17 +00:00
|
|
|
statusBackend.StatusNode().SetMediaServerEnableTLS(request.MediaServerEnableTLS)
|
2024-07-03 11:51:14 +00:00
|
|
|
|
2024-11-22 02:23:17 +00:00
|
|
|
statusBackend.UpdateRootDataDir(request.DataDir)
|
2024-07-03 11:51:14 +00:00
|
|
|
err = statusBackend.OpenAccounts()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
accs, err := statusBackend.GetAccounts()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
centralizedMetricsInfo, err := statusBackend.CentralizedMetricsInfo()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
response := &InitializeApplicationResponse{
|
|
|
|
Accounts: accs,
|
|
|
|
CentralizedMetricsInfo: centralizedMetricsInfo,
|
|
|
|
}
|
|
|
|
data, err := json.Marshal(response)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2024-09-27 15:02:18 +00:00
|
|
|
// Deprecated: Use InitializeApplication instead.
|
2019-08-20 15:38:40 +00:00
|
|
|
func OpenAccounts(datadir string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(openAccounts, datadir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED: use InitializeApplication
|
|
|
|
// openAccounts opens database and returns accounts list.
|
|
|
|
func openAccounts(datadir string) string {
|
2019-08-20 15:38:40 +00:00
|
|
|
statusBackend.UpdateRootDataDir(datadir)
|
|
|
|
err := statusBackend.OpenAccounts()
|
2019-02-01 17:02:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2019-08-20 15:38:40 +00:00
|
|
|
accs, err := statusBackend.GetAccounts()
|
2019-02-01 17:02:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2019-08-20 15:38:40 +00:00
|
|
|
data, err := json.Marshal(accs)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
2019-02-01 17:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ExtractGroupMembershipSignatures(signaturePairsStr string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(extractGroupMembershipSignatures, signaturePairsStr)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExtractGroupMembershipSignatures extract public keys from tuples of content/signature.
|
|
|
|
func extractGroupMembershipSignatures(signaturePairsStr string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
var signaturePairs [][2]string
|
|
|
|
|
|
|
|
if err := json.Unmarshal([]byte(signaturePairsStr), &signaturePairs); err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
identities, err := statusBackend.ExtractGroupMembershipSignatures(signaturePairs)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(struct {
|
|
|
|
Identities []string `json:"identities"`
|
|
|
|
}{Identities: identities})
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
func SignGroupMembership(content string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(signGroupMembership, content)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// signGroupMembership signs a string containing group membership information.
|
|
|
|
func signGroupMembership(content string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
signature, err := statusBackend.SignGroupMembership(content)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(struct {
|
|
|
|
Signature string `json:"signature"`
|
|
|
|
}{Signature: signature})
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2021-04-29 19:22:10 +00:00
|
|
|
func GetNodeConfig() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(getNodeConfig)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getNodeConfig returns the current config of the Status node
|
|
|
|
func getNodeConfig() string {
|
2021-04-29 19:22:10 +00:00
|
|
|
conf, err := statusBackend.GetNodeConfig()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
respJSON, err := json.Marshal(conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(respJSON)
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:02:52 +00:00
|
|
|
func ValidateNodeConfig(configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(validateNodeConfig, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// validateNodeConfig validates config for the Status node.
|
|
|
|
func validateNodeConfig(configJSON string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
var resp APIDetailedResponse
|
|
|
|
|
|
|
|
_, err := params.NewConfigFromJSON(configJSON)
|
|
|
|
|
|
|
|
// Convert errors to APIDetailedResponse
|
|
|
|
switch err := err.(type) {
|
|
|
|
case validator.ValidationErrors:
|
|
|
|
resp = APIDetailedResponse{
|
|
|
|
Message: "validation: validation failed",
|
|
|
|
FieldErrors: make([]APIFieldError, len(err)),
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, ve := range err {
|
|
|
|
resp.FieldErrors[i] = APIFieldError{
|
|
|
|
Parameter: ve.Namespace(),
|
|
|
|
Errors: []APIError{
|
|
|
|
{
|
|
|
|
Message: fmt.Sprintf("field validation failed on the '%s' tag", ve.Tag()),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case error:
|
|
|
|
resp = APIDetailedResponse{
|
|
|
|
Message: fmt.Sprintf("validation: %s", err.Error()),
|
|
|
|
}
|
|
|
|
case nil:
|
|
|
|
resp = APIDetailedResponse{
|
|
|
|
Status: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
respJSON, err := json.Marshal(resp)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(respJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ResetChainData() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(resetChainData)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// resetChainData removes chain data from data directory.
|
|
|
|
func resetChainData() string {
|
2019-02-01 17:02:52 +00:00
|
|
|
api.RunAsync(statusBackend.ResetChainData)
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallRPC(inputJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(callRPC, inputJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// callRPC calls public APIs via RPC.
|
|
|
|
func callRPC(inputJSON string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
resp, err := statusBackend.CallRPC(inputJSON)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
|
|
|
func CallPrivateRPC(inputJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(callPrivateRPC, inputJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// callPrivateRPC calls both public and private APIs via RPC.
|
|
|
|
func callPrivateRPC(inputJSON string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
resp, err := statusBackend.CallPrivateRPC(inputJSON)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use VerifyAccountPasswordV2 instead
|
2019-02-01 17:02:52 +00:00
|
|
|
func VerifyAccountPassword(keyStoreDir, address, password string) string {
|
2024-11-19 09:31:29 +00:00
|
|
|
return verifyAccountPassword(keyStoreDir, address, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// verifyAccountPassword verifies account password.
|
|
|
|
func verifyAccountPassword(keyStoreDir, address, password string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
_, err := statusBackend.AccountManager().VerifyAccountPassword(keyStoreDir, address, password)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func VerifyAccountPasswordV2(requestJSON string) string {
|
|
|
|
return callWithResponse(verifyAccountPasswordV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyAccountPasswordV2(requestJSON string) string {
|
|
|
|
var request requests.VerifyAccountPassword
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = statusBackend.AccountManager().VerifyAccountPassword(request.KeyStoreDir, request.Address, request.Password)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:48:51 +00:00
|
|
|
func VerifyDatabasePasswordV2(requestJSON string) string {
|
|
|
|
return callWithResponse(verifyDatabasePasswordV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func verifyDatabasePasswordV2(requestJSON string) string {
|
|
|
|
var request requests.VerifyDatabasePassword
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.VerifyDatabasePassword(request.KeyUID, request.Password)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: use VerifyDatabasePasswordV2 instead
|
2021-07-20 11:48:10 +00:00
|
|
|
func VerifyDatabasePassword(keyUID, password string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return verifyDatabasePassword(keyUID, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// verifyDatabasePassword verifies database password.
|
|
|
|
func verifyDatabasePassword(keyUID, password string) string {
|
|
|
|
err := statusBackend.VerifyDatabasePassword(keyUID, password)
|
|
|
|
return makeJSONResponse(err)
|
2021-07-20 11:48:10 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 10:48:51 +00:00
|
|
|
func MigrateKeyStoreDirV2(requestJSON string) string {
|
|
|
|
return callWithResponse(migrateKeyStoreDirV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func migrateKeyStoreDirV2(requestJSON string) string {
|
|
|
|
var request requests.MigrateKeystoreDir
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.MigrateKeyStoreDir(request.Account, request.Password, request.OldDir, request.NewDir)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use MigrateKeyStoreDirV2 instead
|
2020-06-22 12:03:28 +00:00
|
|
|
func MigrateKeyStoreDir(accountData, password, oldDir, newDir string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return migrateKeyStoreDir(accountData, password, oldDir, newDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// migrateKeyStoreDir migrates key files to a new directory
|
|
|
|
func migrateKeyStoreDir(accountData, password, oldDir, newDir string) string {
|
2020-06-22 12:03:28 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.MigrateKeyStoreDir(account, password, oldDir, newDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2020-06-22 12:03:28 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
// login deprecated as Login and LoginWithConfig are deprecated
|
2021-12-21 14:27:18 +00:00
|
|
|
func login(accountData, password, configJSON string) error {
|
2019-08-20 15:38:40 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
2019-07-26 14:45:10 +00:00
|
|
|
if err != nil {
|
2021-12-21 14:27:18 +00:00
|
|
|
return err
|
2019-07-26 14:45:10 +00:00
|
|
|
}
|
2021-12-21 14:27:18 +00:00
|
|
|
|
|
|
|
var conf params.NodeConfig
|
|
|
|
if configJSON != "" {
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID))
|
2024-02-27 19:00:20 +00:00
|
|
|
err := statusBackend.UpdateNodeConfigFleet(account, password, &conf)
|
2024-02-27 16:15:11 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to update node config fleet", zap.String("key-uid", account.KeyUID), zap.Error(err))
|
2024-02-28 15:42:32 +00:00
|
|
|
return statusBackend.LoggedIn(account.KeyUID, err)
|
2024-02-27 16:15:11 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 11:14:27 +00:00
|
|
|
err = statusBackend.StartNodeWithAccount(account, password, &conf, nil)
|
2019-08-20 15:38:40 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", account.KeyUID), zap.Error(err))
|
2019-08-20 15:38:40 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID))
|
2019-08-20 15:38:40 +00:00
|
|
|
return nil
|
|
|
|
})
|
2021-12-21 14:27:18 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Login loads a key file (for a given address), tries to decrypt it using the password,
|
|
|
|
// to verify ownership if verified, purges all the previous identities from Whisper,
|
|
|
|
// and injects verified key as shh identity.
|
2024-09-13 15:08:20 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use LoginAccount instead.
|
2021-12-21 14:27:18 +00:00
|
|
|
func Login(accountData, password string) string {
|
|
|
|
err := login(accountData, password, "")
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
// LoginWithConfig loads a key file (for a given address), tries to decrypt it using the password,
|
2021-12-21 14:27:18 +00:00
|
|
|
// to verify ownership if verified, purges all the previous identities from Whisper,
|
2022-02-27 14:46:17 +00:00
|
|
|
// and injects verified key as shh identity. It then updates the accounts node db configuration
|
2021-12-21 14:27:18 +00:00
|
|
|
// mergin the values received in the configJSON parameter
|
2024-03-28 15:01:44 +00:00
|
|
|
//
|
|
|
|
// Deprecated: Use LoginAccount instead.
|
2021-12-21 14:27:18 +00:00
|
|
|
func LoginWithConfig(accountData, password, configJSON string) string {
|
|
|
|
err := login(accountData, password, configJSON)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2019-08-20 15:38:40 +00:00
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
2019-07-26 14:45:10 +00:00
|
|
|
|
2023-03-16 14:49:25 +00:00
|
|
|
func CreateAccountAndLogin(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(createAccountAndLogin, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func createAccountAndLogin(requestJSON string) string {
|
2023-03-16 14:49:25 +00:00
|
|
|
var request requests.CreateAccount
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
err = request.Validate(&requests.CreateAccountValidation{
|
|
|
|
AllowEmptyDisplayName: false,
|
|
|
|
})
|
2023-03-16 14:49:25 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("starting a node and creating config")
|
2023-10-10 16:12:38 +00:00
|
|
|
_, err := statusBackend.CreateAccountAndLogin(&request)
|
2023-03-16 14:49:25 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to create account", zap.Error(err))
|
2023-03-16 14:49:25 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node, and created account")
|
2023-03-16 14:49:25 +00:00
|
|
|
return nil
|
2023-03-21 17:02:04 +00:00
|
|
|
})
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2024-10-23 13:53:25 +00:00
|
|
|
func AcceptTerms() string {
|
|
|
|
return callWithResponse(acceptTerms)
|
|
|
|
}
|
|
|
|
|
|
|
|
func acceptTerms() string {
|
|
|
|
err := statusBackend.AcceptTerms()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2023-05-24 15:02:53 +00:00
|
|
|
func LoginAccount(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(loginAccount, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func loginAccount(requestJSON string) string {
|
2023-05-24 15:02:53 +00:00
|
|
|
var request requests.Login
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
api.RunAsync(func() error {
|
|
|
|
err := statusBackend.LoginAccount(&request)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("loginAccount failed", zap.Error(err))
|
2023-05-24 15:02:53 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("loginAccount started node")
|
2023-05-24 15:02:53 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2023-03-21 17:02:04 +00:00
|
|
|
func RestoreAccountAndLogin(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(restoreAccountAndLogin, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func restoreAccountAndLogin(requestJSON string) string {
|
2023-03-21 17:02:04 +00:00
|
|
|
var request requests.RestoreAccount
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("starting a node and restoring account")
|
2024-06-26 11:14:27 +00:00
|
|
|
|
|
|
|
if request.Keycard != nil {
|
|
|
|
_, err = statusBackend.RestoreKeycardAccountAndLogin(&request)
|
|
|
|
} else {
|
|
|
|
_, err = statusBackend.RestoreAccountAndLogin(&request)
|
|
|
|
}
|
|
|
|
|
2023-03-21 17:02:04 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to restore account", zap.Error(err))
|
2023-03-21 17:02:04 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node, and restored account")
|
2023-03-21 17:02:04 +00:00
|
|
|
return nil
|
2023-03-16 14:49:25 +00:00
|
|
|
})
|
2024-06-26 11:14:27 +00:00
|
|
|
|
2023-03-16 14:49:25 +00:00
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2024-03-28 15:01:44 +00:00
|
|
|
// SaveAccountAndLogin saves account in status-go database.
|
|
|
|
// Deprecated: Use CreateAccountAndLogin instead.
|
2019-12-27 09:58:25 +00:00
|
|
|
func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData string) string {
|
2019-08-20 15:38:40 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-03-23 18:47:00 +00:00
|
|
|
var settings settings.Settings
|
2019-12-27 09:58:25 +00:00
|
|
|
err = json.Unmarshal([]byte(settingsJSON), &settings)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2023-10-31 12:42:33 +00:00
|
|
|
|
2023-10-31 12:50:26 +00:00
|
|
|
if *settings.Mnemonic != "" {
|
2023-12-01 11:30:42 +00:00
|
|
|
settings.MnemonicWasNotShown = true
|
2023-10-31 12:42:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
var conf params.NodeConfig
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-05-18 10:42:51 +00:00
|
|
|
var subaccs []*accounts.Account
|
2019-08-20 15:38:40 +00:00
|
|
|
err = json.Unmarshal([]byte(subaccountData), &subaccs)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-04-08 17:54:29 +00:00
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID))
|
2024-06-26 11:14:27 +00:00
|
|
|
err := statusBackend.StartNodeWithAccountAndInitialConfig(account, password, settings, &conf, subaccs, nil)
|
2019-08-20 15:38:40 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", account.KeyUID), zap.Error(err))
|
2019-08-20 15:38:40 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID))
|
2019-08-20 15:38:40 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use DeleteMultiaccountV2 instead
|
2020-07-13 10:45:36 +00:00
|
|
|
func DeleteMultiaccount(keyUID, keyStoreDir string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(deleteMultiaccount, keyUID, keyStoreDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
2020-07-13 10:45:36 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
// deleteMultiaccount
|
|
|
|
func deleteMultiaccount(keyUID, keyStoreDir string) string {
|
|
|
|
err := statusBackend.DeleteMultiaccount(keyUID, keyStoreDir)
|
|
|
|
return makeJSONResponse(err)
|
2020-07-13 10:45:36 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func DeleteMultiaccountV2(requestJSON string) string {
|
|
|
|
return callWithResponse(deleteMultiaccountV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteMultiaccountV2(requestJSON string) string {
|
|
|
|
var request requests.DeleteMultiaccount
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.DeleteMultiaccount(request.KeyUID, request.KeyStoreDir)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:48:51 +00:00
|
|
|
func DeleteImportedKeyV2(requestJSON string) string {
|
|
|
|
return callWithResponse(deleteImportedKeyV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func deleteImportedKeyV2(requestJSON string) string {
|
|
|
|
var request requests.DeleteImportedKey
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.DeleteImportedKey(request.Address, request.Password, request.KeyStoreDir)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use DeleteImportedKeyV2 instead
|
2021-08-13 07:24:33 +00:00
|
|
|
func DeleteImportedKey(address, password, keyStoreDir string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return deleteImportedKey(address, password, keyStoreDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
2021-08-13 07:24:33 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
// deleteImportedKey
|
|
|
|
func deleteImportedKey(address, password, keyStoreDir string) string {
|
|
|
|
err := statusBackend.DeleteImportedKey(address, password, keyStoreDir)
|
|
|
|
return makeJSONResponse(err)
|
2021-08-13 07:24:33 +00:00
|
|
|
}
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
func InitKeystore(keydir string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(initKeystore, keydir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initKeystore initialize keystore before doing any operations with keys.
|
|
|
|
func initKeystore(keydir string) string {
|
2019-08-20 15:38:40 +00:00
|
|
|
err := statusBackend.AccountManager().InitKeystore(keydir)
|
2019-02-01 17:02:52 +00:00
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-06-26 11:14:27 +00:00
|
|
|
// SaveAccountAndLoginWithKeycard saves account in status-go database.
|
|
|
|
// Deprecated: Use CreateAndAccountAndLogin with required keycard properties.
|
2019-12-27 09:58:25 +00:00
|
|
|
func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJSON, subaccountData string, keyHex string) string {
|
2019-09-02 19:03:15 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-03-23 18:47:00 +00:00
|
|
|
var settings settings.Settings
|
2019-12-27 09:58:25 +00:00
|
|
|
err = json.Unmarshal([]byte(settingsJSON), &settings)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2019-09-02 19:03:15 +00:00
|
|
|
var conf params.NodeConfig
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-05-18 10:42:51 +00:00
|
|
|
var subaccs []*accounts.Account
|
2019-12-18 15:09:04 +00:00
|
|
|
err = json.Unmarshal([]byte(subaccountData), &subaccs)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-10-19 15:19:30 +00:00
|
|
|
|
2019-09-02 19:03:15 +00:00
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID))
|
2019-12-27 09:58:25 +00:00
|
|
|
err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, settings, &conf, subaccs, keyHex)
|
2019-09-02 19:03:15 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", account.KeyUID), zap.Error(err))
|
2019-09-02 19:03:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID))
|
2019-09-02 19:03:15 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
2019-02-11 20:20:59 +00:00
|
|
|
// LoginWithKeycard initializes an account with a chat key and encryption key used for PFS.
|
|
|
|
// It purges all the previous identities from Whisper, and injects the key as shh identity.
|
2024-06-26 11:14:27 +00:00
|
|
|
// Deprecated: Use LoginAccount instead.
|
2023-07-20 10:08:57 +00:00
|
|
|
func LoginWithKeycard(accountData, password, keyHex string, configJSON string) string {
|
2019-09-02 19:03:15 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2023-07-20 10:08:57 +00:00
|
|
|
var conf params.NodeConfig
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2019-09-02 19:03:15 +00:00
|
|
|
api.RunAsync(func() error {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID))
|
2023-07-20 10:08:57 +00:00
|
|
|
err := statusBackend.StartNodeWithKey(account, password, keyHex, &conf)
|
2019-09-02 19:03:15 +00:00
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", account.KeyUID), zap.Error(err))
|
2019-09-02 19:03:15 +00:00
|
|
|
return err
|
|
|
|
}
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID))
|
2019-09-02 19:03:15 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return makeJSONResponse(nil)
|
2019-02-11 20:20:59 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 17:02:52 +00:00
|
|
|
func Logout() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(logout)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// logout is equivalent to clearing whisper identities.
|
|
|
|
func logout() string {
|
|
|
|
return makeJSONResponse(statusBackend.Logout())
|
2019-02-01 17:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func SignMessage(rpcParams string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(signMessage, rpcParams)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// signMessage unmarshals rpc params {data, address, password} and
|
|
|
|
// passes them onto backend.SignMessage.
|
|
|
|
func signMessage(rpcParams string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
var params personal.SignParams
|
|
|
|
err := json.Unmarshal([]byte(rpcParams), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
result, err := statusBackend.SignMessage(params)
|
|
|
|
return prepareJSONResponse(result.String(), err)
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:45:27 +00:00
|
|
|
// SignTypedData unmarshall data into TypedData, validate it and signs with selected account,
|
|
|
|
// if password matches selected account.
|
2019-07-26 14:45:10 +00:00
|
|
|
func SignTypedData(data, address, password string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return signTypedData(data, address, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func signTypedData(data, address, password string) string {
|
2019-03-04 13:45:27 +00:00
|
|
|
var typed typeddata.TypedData
|
|
|
|
err := json.Unmarshal([]byte(data), &typed)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
if err := typed.Validate(); err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
2019-07-26 14:45:10 +00:00
|
|
|
result, err := statusBackend.SignTypedData(typed, address, password)
|
2019-03-04 13:45:27 +00:00
|
|
|
return prepareJSONResponse(result.String(), err)
|
|
|
|
}
|
|
|
|
|
2019-03-28 14:56:21 +00:00
|
|
|
// HashTypedData unmarshalls data into TypedData, validates it and hashes it.
|
2022-12-29 06:16:19 +00:00
|
|
|
//
|
2022-03-18 12:20:13 +00:00
|
|
|
//export HashTypedData
|
2019-03-28 14:56:21 +00:00
|
|
|
func HashTypedData(data string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hashTypedData, data)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hashTypedData(data string) string {
|
2019-03-28 14:56:21 +00:00
|
|
|
var typed typeddata.TypedData
|
|
|
|
err := json.Unmarshal([]byte(data), &typed)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
if err := typed.Validate(); err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
result, err := statusBackend.HashTypedData(typed)
|
|
|
|
return prepareJSONResponse(result.String(), err)
|
|
|
|
}
|
|
|
|
|
2020-10-29 07:46:02 +00:00
|
|
|
// SignTypedDataV4 unmarshall data into TypedData, validate it and signs with selected account,
|
|
|
|
// if password matches selected account.
|
2022-12-29 06:16:19 +00:00
|
|
|
//
|
2020-10-29 07:46:02 +00:00
|
|
|
//export SignTypedDataV4
|
|
|
|
func SignTypedDataV4(data, address, password string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return signTypedDataV4(data, address, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func signTypedDataV4(data, address, password string) string {
|
2022-10-25 14:25:08 +00:00
|
|
|
var typed apitypes.TypedData
|
2020-10-29 07:46:02 +00:00
|
|
|
err := json.Unmarshal([]byte(data), &typed)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
result, err := statusBackend.SignTypedDataV4(typed, address, password)
|
|
|
|
return prepareJSONResponse(result.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// HashTypedDataV4 unmarshalls data into TypedData, validates it and hashes it.
|
2022-12-29 06:16:19 +00:00
|
|
|
//
|
2022-03-18 12:20:13 +00:00
|
|
|
//export HashTypedDataV4
|
2020-10-29 07:46:02 +00:00
|
|
|
func HashTypedDataV4(data string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hashTypedDataV4, data)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hashTypedDataV4(data string) string {
|
2022-10-25 14:25:08 +00:00
|
|
|
var typed apitypes.TypedData
|
2020-10-29 07:46:02 +00:00
|
|
|
err := json.Unmarshal([]byte(data), &typed)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
result, err := statusBackend.HashTypedDataV4(typed)
|
|
|
|
return prepareJSONResponse(result.String(), err)
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:02:52 +00:00
|
|
|
func Recover(rpcParams string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(recoverWithRPCParams, rpcParams)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// recoverWithRPCParams unmarshals rpc params {signDataString, signedData} and passes
|
|
|
|
// them onto backend.
|
|
|
|
func recoverWithRPCParams(rpcParams string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
var params personal.RecoverParams
|
|
|
|
err := json.Unmarshal([]byte(rpcParams), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
addr, err := statusBackend.Recover(params)
|
|
|
|
return prepareJSONResponse(addr.String(), err)
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:48:51 +00:00
|
|
|
// SendTransactionWithChainID converts RPC args and calls backend.SendTransactionWithChainID.
|
2022-06-09 13:09:56 +00:00
|
|
|
func SendTransactionWithChainID(chainID int, txArgsJSON, password string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return sendTransactionWithChainID(chainID, txArgsJSON, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sendTransactionWithChainID converts RPC args and calls backend.SendTransactionWithChainID.
|
|
|
|
func sendTransactionWithChainID(chainID int, txArgsJSON, password string) string {
|
2024-11-05 21:28:24 +00:00
|
|
|
var params wallettypes.SendTxArgs
|
2022-06-09 13:09:56 +00:00
|
|
|
err := json.Unmarshal([]byte(txArgsJSON), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
hash, err := statusBackend.SendTransactionWithChainID(uint64(chainID), params, password)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
|
|
|
}
|
|
|
|
return prepareJSONResponseWithCode(hash.String(), err, code)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use SendTransactionV2 instead.
|
2019-02-01 17:02:52 +00:00
|
|
|
func SendTransaction(txArgsJSON, password string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return sendTransaction(txArgsJSON, password)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sendTransaction converts RPC args and calls backend.SendTransaction.
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use sendTransactionV2 instead.
|
2024-09-13 15:08:20 +00:00
|
|
|
func sendTransaction(txArgsJSON, password string) string {
|
2024-11-05 21:28:24 +00:00
|
|
|
var params wallettypes.SendTxArgs
|
2019-02-01 17:02:52 +00:00
|
|
|
err := json.Unmarshal([]byte(txArgsJSON), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
hash, err := statusBackend.SendTransaction(params, password)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
|
|
|
}
|
|
|
|
return prepareJSONResponseWithCode(hash.String(), err, code)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func SendTransactionV2(requestJSON string) string {
|
|
|
|
return callWithResponse(sendTransactionV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func sendTransactionV2(requestJSON string) string {
|
|
|
|
var request requests.SendTransaction
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
hash, err := statusBackend.SendTransaction(request.TxArgs, request.Password)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
|
|
|
}
|
|
|
|
return prepareJSONResponseWithCode(hash.String(), err, code)
|
|
|
|
}
|
|
|
|
|
2019-02-15 11:31:20 +00:00
|
|
|
func SendTransactionWithSignature(txArgsJSON, sigString string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(sendTransactionWithSignature, txArgsJSON, sigString)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sendTransactionWithSignature converts RPC args and calls backend.SendTransactionWithSignature
|
|
|
|
func sendTransactionWithSignature(txArgsJSON, sigString string) string {
|
2024-11-05 21:28:24 +00:00
|
|
|
var params wallettypes.SendTxArgs
|
2019-02-15 11:31:20 +00:00
|
|
|
err := json.Unmarshal([]byte(txArgsJSON), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
sig, err := hex.DecodeString(sigString)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
hash, err := statusBackend.SendTransactionWithSignature(params, sig)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
|
|
|
}
|
|
|
|
return prepareJSONResponseWithCode(hash.String(), err, code)
|
|
|
|
}
|
|
|
|
|
2019-02-21 09:53:39 +00:00
|
|
|
func HashTransaction(txArgsJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hashTransaction, txArgsJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// hashTransaction validate the transaction and returns new txArgs and the transaction hash.
|
|
|
|
func hashTransaction(txArgsJSON string) string {
|
2024-11-05 21:28:24 +00:00
|
|
|
var params wallettypes.SendTxArgs
|
2019-02-21 09:53:39 +00:00
|
|
|
err := json.Unmarshal([]byte(txArgsJSON), ¶ms)
|
|
|
|
if err != nil {
|
|
|
|
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
newTxArgs, hash, err := statusBackend.HashTransaction(params)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
|
|
|
}
|
|
|
|
|
|
|
|
result := struct {
|
2024-11-05 21:28:24 +00:00
|
|
|
Transaction wallettypes.SendTxArgs `json:"transaction"`
|
|
|
|
Hash types.Hash `json:"hash"`
|
2019-02-21 09:53:39 +00:00
|
|
|
}{
|
|
|
|
Transaction: newTxArgs,
|
|
|
|
Hash: hash,
|
|
|
|
}
|
|
|
|
|
|
|
|
return prepareJSONResponseWithCode(result, err, code)
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func HashMessage(message string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hashMessage, message)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// hashMessage calculates the hash of a message to be safely signed by the keycard
|
2019-03-21 10:48:47 +00:00
|
|
|
// The hash is calulcated as
|
2022-12-29 06:16:19 +00:00
|
|
|
//
|
|
|
|
// keccak256("\x19Ethereum Signed Message:\n"${message length}${message}).
|
|
|
|
//
|
2019-03-21 10:48:47 +00:00
|
|
|
// This gives context to the signed message and prevents signing of transactions.
|
2024-09-13 15:08:20 +00:00
|
|
|
func hashMessage(message string) string {
|
2019-04-29 23:26:41 +00:00
|
|
|
hash, err := api.HashMessage(message)
|
|
|
|
code := codeUnknown
|
|
|
|
if c, ok := errToCodeMap[err]; ok {
|
|
|
|
code = c
|
2019-03-21 10:48:47 +00:00
|
|
|
}
|
2019-04-29 23:26:41 +00:00
|
|
|
return prepareJSONResponseWithCode(fmt.Sprintf("0x%x", hash), err, code)
|
2019-03-21 10:48:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 17:02:52 +00:00
|
|
|
func StartCPUProfile(dataDir string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(startCPUProfile, dataDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// startCPUProfile runs pprof for CPU.
|
|
|
|
func startCPUProfile(dataDir string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
err := profiling.StartCPUProfile(dataDir)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func StopCPUProfiling() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(stopCPUProfiling)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stopCPUProfiling stops pprof for cpu.
|
|
|
|
func stopCPUProfiling() string { //nolint: deadcode
|
2019-02-01 17:02:52 +00:00
|
|
|
err := profiling.StopCPUProfile()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func WriteHeapProfile(dataDir string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(writeHeapProfile, dataDir)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// writeHeapProfile starts pprof for heap
|
|
|
|
func writeHeapProfile(dataDir string) string { //nolint: deadcode
|
2019-02-01 17:02:52 +00:00
|
|
|
err := profiling.WriteHeapFile(dataDir)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeJSONResponse(err error) string {
|
|
|
|
errString := ""
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("error in makeJSONResponse", zap.Error(err))
|
2019-02-01 17:02:52 +00:00
|
|
|
errString = err.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
out := APIResponse{
|
|
|
|
Error: errString,
|
|
|
|
}
|
|
|
|
outBytes, _ := json.Marshal(out)
|
|
|
|
|
|
|
|
return string(outBytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AddPeer(enode string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(addPeer, enode)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// addPeer adds an enode as a peer.
|
|
|
|
func addPeer(enode string) string {
|
2019-02-01 17:02:52 +00:00
|
|
|
err := statusBackend.StatusNode().AddPeer(enode)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use ConnectionChangeV2 instead.
|
2019-02-01 17:02:52 +00:00
|
|
|
func ConnectionChange(typ string, expensive int) {
|
2024-09-26 22:37:32 +00:00
|
|
|
call(connectionChange, typ, expensive)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// connectionChange handles network state changes as reported
|
|
|
|
// by ReactNative (see https://facebook.github.io/react-native/docs/netinfo.html)
|
|
|
|
func connectionChange(typ string, expensive int) {
|
2019-02-01 17:02:52 +00:00
|
|
|
statusBackend.ConnectionChange(typ, expensive == 1)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ConnectionChangeV2(requestJSON string) string {
|
|
|
|
return callWithResponse(connectionChangeV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func connectionChangeV2(requestJSON string) string {
|
|
|
|
var request requests.ConnectionChange
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
statusBackend.ConnectionChange(request.Type, request.Expensive)
|
|
|
|
return makeJSONResponse(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use AppStateChangeV2 instead.
|
2019-02-01 17:02:52 +00:00
|
|
|
func AppStateChange(state string) {
|
2024-09-26 22:37:32 +00:00
|
|
|
call(appStateChange, state)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// appStateChange handles app state changes (background/foreground).
|
|
|
|
func appStateChange(state string) {
|
2024-11-19 09:31:29 +00:00
|
|
|
s, err := api.ParseAppState(state)
|
|
|
|
if err != nil {
|
|
|
|
logutils.ZapLogger().Error("parse app state failed, ignoring", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
statusBackend.AppStateChange(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func AppStateChangeV2(requestJSON string) string {
|
|
|
|
return callWithResponse(appStateChangeV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func appStateChangeV2(requestJSON string) string {
|
|
|
|
var request m_requests.AppStateChange
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
statusBackend.AppStateChange(request.State)
|
|
|
|
return makeJSONResponse(nil)
|
2019-02-01 17:02:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 07:56:14 +00:00
|
|
|
func StartLocalNotifications() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(startLocalNotifications)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// startLocalNotifications
|
|
|
|
func startLocalNotifications() string {
|
2020-10-28 07:56:14 +00:00
|
|
|
err := statusBackend.StartLocalNotifications()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func StopLocalNotifications() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(stopLocalNotifications)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// stopLocalNotifications
|
|
|
|
func stopLocalNotifications() string {
|
2020-10-28 07:56:14 +00:00
|
|
|
err := statusBackend.StopLocalNotifications()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2019-02-01 17:02:52 +00:00
|
|
|
func SetMobileSignalHandler(handler SignalHandler) {
|
2024-09-26 22:37:32 +00:00
|
|
|
call(setMobileSignalHandler, handler)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setMobileSignalHandler setup geth callback to notify about new signal
|
|
|
|
// used for gomobile builds
|
|
|
|
func setMobileSignalHandler(handler SignalHandler) {
|
2019-02-01 17:02:52 +00:00
|
|
|
signal.SetMobileSignalHandler(func(data []byte) {
|
|
|
|
if len(data) > 0 {
|
|
|
|
handler.HandleSignal(string(data))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetSignalEventCallback(cb unsafe.Pointer) {
|
2024-09-26 22:37:32 +00:00
|
|
|
call(setSignalEventCallback, cb)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// setSignalEventCallback setup geth callback to notify about new signal
|
|
|
|
func setSignalEventCallback(cb unsafe.Pointer) {
|
2019-02-01 17:02:52 +00:00
|
|
|
signal.SetSignalEventCallback(cb)
|
|
|
|
}
|
2019-02-12 11:07:13 +00:00
|
|
|
|
2019-03-04 14:33:48 +00:00
|
|
|
// ExportNodeLogs reads current node log and returns content to a caller.
|
2022-12-29 06:16:19 +00:00
|
|
|
//
|
2019-03-04 14:33:48 +00:00
|
|
|
//export ExportNodeLogs
|
|
|
|
func ExportNodeLogs() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(exportNodeLogs)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func exportNodeLogs() string {
|
2019-03-04 14:33:48 +00:00
|
|
|
node := statusBackend.StatusNode()
|
|
|
|
if node == nil {
|
|
|
|
return makeJSONResponse(errors.New("node is not running"))
|
|
|
|
}
|
|
|
|
config := node.Config()
|
|
|
|
if config == nil {
|
|
|
|
return makeJSONResponse(errors.New("config and log file are not available"))
|
|
|
|
}
|
|
|
|
data, err := json.Marshal(exportlogs.ExportFromBaseFile(config.LogFile))
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(fmt.Errorf("error marshalling to json: %v", err))
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
2019-03-21 12:02:16 +00:00
|
|
|
|
2019-04-18 13:52:08 +00:00
|
|
|
func SignHash(hexEncodedHash string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(signHash, hexEncodedHash)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// signHash exposes vanilla ECDSA signing required for Swarm messages
|
|
|
|
func signHash(hexEncodedHash string) string {
|
2019-04-18 13:52:08 +00:00
|
|
|
hexEncodedSignature, err := statusBackend.SignHash(hexEncodedHash)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return hexEncodedSignature
|
|
|
|
}
|
2019-09-26 07:01:17 +00:00
|
|
|
|
|
|
|
func GenerateAlias(pk string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(generateAlias, pk)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func generateAlias(pk string) string {
|
2019-09-26 07:01:17 +00:00
|
|
|
// We ignore any error, empty string is considered an error
|
|
|
|
name, _ := protocol.GenerateAlias(pk)
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2022-02-17 15:13:10 +00:00
|
|
|
func IsAlias(value string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(isAlias, value)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func isAlias(value string) string {
|
2022-02-17 15:13:10 +00:00
|
|
|
return prepareJSONResponse(alias.IsAlias(value), nil)
|
|
|
|
}
|
|
|
|
|
2019-09-26 07:01:17 +00:00
|
|
|
func Identicon(pk string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(identicon, pk)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func identicon(pk string) string {
|
2019-09-26 07:01:17 +00:00
|
|
|
// We ignore any error, empty string is considered an error
|
|
|
|
identicon, _ := protocol.Identicon(pk)
|
|
|
|
return identicon
|
|
|
|
}
|
2019-12-16 13:55:02 +00:00
|
|
|
|
2022-03-17 16:58:35 +00:00
|
|
|
func EmojiHash(pk string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(emojiHash, pk)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func emojiHash(pk string) string {
|
2022-03-17 16:58:35 +00:00
|
|
|
return prepareJSONResponse(emojihash.GenerateFor(pk))
|
|
|
|
}
|
|
|
|
|
|
|
|
func ColorHash(pk string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(colorHash, pk)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func colorHash(pk string) string {
|
2022-03-17 16:58:35 +00:00
|
|
|
return prepareJSONResponse(colorhash.GenerateFor(pk))
|
|
|
|
}
|
|
|
|
|
2022-04-08 17:54:29 +00:00
|
|
|
func ColorID(pk string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(colorID, pk)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func colorID(pk string) string {
|
2022-04-08 17:54:29 +00:00
|
|
|
return prepareJSONResponse(identityUtils.ToColorID(pk))
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use ValidateMnemonicV2 instead.
|
2019-12-16 13:55:02 +00:00
|
|
|
func ValidateMnemonic(mnemonic string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return validateMnemonic(mnemonic)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func validateMnemonic(mnemonic string) string {
|
2019-12-16 13:55:02 +00:00
|
|
|
m := extkeys.NewMnemonic()
|
|
|
|
err := m.ValidateMnemonic(mnemonic, extkeys.Language(0))
|
2023-03-28 08:12:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
keyUID, err := statusBackend.GetKeyUIDByMnemonic(mnemonic)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
response := &APIKeyUIDResponse{KeyUID: keyUID}
|
|
|
|
data, err := json.Marshal(response)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
2019-12-16 13:55:02 +00:00
|
|
|
}
|
2020-06-23 10:47:17 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ValidateMnemonicV2(requestJSON string) string {
|
|
|
|
return callWithResponse(validateMnemonicV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateMnemonicV2(requestJSON string) string {
|
|
|
|
var request requests.ValidateMnemonic
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return validateMnemonic(request.Mnemonic)
|
|
|
|
}
|
|
|
|
|
2022-10-25 09:32:26 +00:00
|
|
|
func DecompressPublicKey(key string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(decompressPublicKey, key)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// decompressPublicKey decompresses 33-byte compressed format to uncompressed 65-byte format.
|
|
|
|
func decompressPublicKey(key string) string {
|
2022-10-25 09:32:26 +00:00
|
|
|
decoded, err := types.DecodeHex(key)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
const compressionBytesNumber = 33
|
|
|
|
if len(decoded) != compressionBytesNumber {
|
|
|
|
return makeJSONResponse(errors.New("key is not 33 bytes long"))
|
|
|
|
}
|
|
|
|
pubKey, err := crypto.DecompressPubkey(decoded)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return types.EncodeHex(crypto.FromECDSAPub(pubKey))
|
|
|
|
}
|
|
|
|
|
|
|
|
func CompressPublicKey(key string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(compressPublicKey, key)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// compressPublicKey compresses uncompressed 65-byte format to 33-byte compressed format.
|
|
|
|
func compressPublicKey(key string) string {
|
2022-10-25 09:32:26 +00:00
|
|
|
pubKey, err := common.HexToPubkey(key)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return types.EncodeHex(crypto.CompressPubkey(pubKey))
|
|
|
|
}
|
|
|
|
|
2023-01-20 18:51:36 +00:00
|
|
|
func SerializeLegacyKey(key string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(serializeLegacyKey, key)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// serializeLegacyKey compresses an old format public key (0x04...) to the new one zQ...
|
|
|
|
func serializeLegacyKey(key string) string {
|
2023-01-20 18:51:36 +00:00
|
|
|
cpk, err := multiformat.SerializeLegacyKey(key)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return cpk
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func MultiformatSerializePublicKey(key, outBase string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(multiformatSerializePublicKey, key, outBase)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 10:47:17 +00:00
|
|
|
// SerializePublicKey compresses an uncompressed multibase encoded multicodec identified EC public key
|
2020-06-24 13:39:42 +00:00
|
|
|
// For details on usage see specs https://specs.status.im/spec/2#public-key-serialization
|
2024-09-13 15:08:20 +00:00
|
|
|
func multiformatSerializePublicKey(key, outBase string) string {
|
2020-06-23 10:47:17 +00:00
|
|
|
cpk, err := multiformat.SerializePublicKey(key, outBase)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return cpk
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use MultiformatDeserializePublicKeyV2 instead.
|
2024-09-13 15:08:20 +00:00
|
|
|
func MultiformatDeserializePublicKey(key, outBase string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(multiformatDeserializePublicKey, key, outBase)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 10:47:17 +00:00
|
|
|
// DeserializePublicKey decompresses a compressed multibase encoded multicodec identified EC public key
|
2020-06-24 13:39:42 +00:00
|
|
|
// For details on usage see specs https://specs.status.im/spec/2#public-key-serialization
|
2024-09-13 15:08:20 +00:00
|
|
|
func multiformatDeserializePublicKey(key, outBase string) string {
|
2020-06-23 10:47:17 +00:00
|
|
|
pk, err := multiformat.DeserializePublicKey(key, outBase)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return pk
|
|
|
|
}
|
2021-01-07 11:15:02 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func MultiformatDeserializePublicKeyV2(requestJSON string) string {
|
|
|
|
return callWithResponse(multiformatDeserializePublicKeyV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func multiformatDeserializePublicKeyV2(requestJSON string) string {
|
|
|
|
var request requests.MultiformatDeserializePublicKey
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return multiformatDeserializePublicKey(request.Key, request.OutBase)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use ExportUnencryptedDatabaseV2 instead.
|
2021-01-07 11:15:02 +00:00
|
|
|
func ExportUnencryptedDatabase(accountData, password, databasePath string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return exportUnencryptedDatabase(accountData, password, databasePath)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// exportUnencryptedDatabase exports the database unencrypted to the given path
|
|
|
|
func exportUnencryptedDatabase(accountData, password, databasePath string) string {
|
2021-01-07 11:15:02 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.ExportUnencryptedDatabase(account, password, databasePath)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2021-01-07 11:15:02 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ExportUnencryptedDatabaseV2(requestJSON string) string {
|
|
|
|
return callWithResponse(exportUnencryptedDatabaseV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func exportUnencryptedDatabaseV2(requestJSON string) string {
|
|
|
|
var request requests.ExportUnencryptedDatabase
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.ExportUnencryptedDatabase(request.Account, request.Password, request.DatabasePath)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use ImportUnencryptedDatabaseV2 instead.
|
2021-01-07 11:15:02 +00:00
|
|
|
func ImportUnencryptedDatabase(accountData, password, databasePath string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return importUnencryptedDatabase(accountData, password, databasePath)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// importUnencryptedDatabase imports the database unencrypted to the given directory
|
|
|
|
func importUnencryptedDatabase(accountData, password, databasePath string) string {
|
2021-01-07 11:15:02 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.ImportUnencryptedDatabase(account, password, databasePath)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2021-01-07 11:15:02 +00:00
|
|
|
}
|
2021-06-23 09:21:21 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ImportUnencryptedDatabaseV2(requestJSON string) string {
|
|
|
|
return callWithResponse(importUnencryptedDatabaseV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func importUnencryptedDatabaseV2(requestJSON string) string {
|
|
|
|
var request requests.ImportUnencryptedDatabase
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.ImportUnencryptedDatabase(request.Account, request.Password, request.DatabasePath)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use ChangeDatabasePasswordV2 instead.
|
2024-09-27 10:48:51 +00:00
|
|
|
func ChangeDatabasePassword(keyUID, password, newPassword string) string {
|
|
|
|
return changeDatabasePassword(keyUID, password, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// changeDatabasePassword changes the password of the database
|
2024-09-27 10:48:51 +00:00
|
|
|
func changeDatabasePassword(keyUID, password, newPassword string) string {
|
|
|
|
err := statusBackend.ChangeDatabasePassword(keyUID, password, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2021-06-23 09:21:21 +00:00
|
|
|
}
|
2021-07-20 11:48:10 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ChangeDatabasePasswordV2(requestJSON string) string {
|
|
|
|
return callWithResponse(changeDatabasePasswordV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func changeDatabasePasswordV2(requestJSON string) string {
|
|
|
|
var request requests.ChangeDatabasePassword
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return changeDatabasePassword(request.KeyUID, request.OldPassword, request.NewPassword)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use ConvertToKeycardAccountV2 instead.
|
2023-05-05 07:43:05 +00:00
|
|
|
func ConvertToKeycardAccount(accountData, settingsJSON, keycardUID, password, newPassword string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return convertToKeycardAccount(accountData, settingsJSON, keycardUID, password, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convertToKeycardAccount converts the account to a keycard account
|
|
|
|
func convertToKeycardAccount(accountData, settingsJSON, keycardUID, password, newPassword string) string {
|
2021-07-20 11:48:10 +00:00
|
|
|
var account multiaccounts.Account
|
|
|
|
err := json.Unmarshal([]byte(accountData), &account)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-03-23 18:47:00 +00:00
|
|
|
var settings settings.Settings
|
2021-07-20 11:48:10 +00:00
|
|
|
err = json.Unmarshal([]byte(settingsJSON), &settings)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2023-05-05 07:43:05 +00:00
|
|
|
err = statusBackend.ConvertToKeycardAccount(account, settings, keycardUID, password, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2021-07-20 11:48:10 +00:00
|
|
|
}
|
2022-02-10 17:19:34 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ConvertToKeycardAccountV2(requestJSON string) string {
|
|
|
|
return callWithResponse(convertToKeycardAccountV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertToKeycardAccountV2(requestJSON string) string {
|
|
|
|
var request requests.ConvertToKeycardAccount
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = statusBackend.ConvertToKeycardAccount(request.Account, request.Settings, request.KeycardUID, request.OldPassword, request.NewPassword)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use ConvertToRegularAccountV2 instead.
|
2023-01-25 10:25:07 +00:00
|
|
|
func ConvertToRegularAccount(mnemonic, currPassword, newPassword string) string {
|
2024-09-27 10:48:51 +00:00
|
|
|
return convertToRegularAccount(mnemonic, currPassword, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// convertToRegularAccount converts the account to a regular account
|
|
|
|
func convertToRegularAccount(mnemonic, currPassword, newPassword string) string {
|
2023-01-25 10:25:07 +00:00
|
|
|
err := statusBackend.ConvertToRegularAccount(mnemonic, currPassword, newPassword)
|
2024-09-13 15:08:20 +00:00
|
|
|
return makeJSONResponse(err)
|
2023-01-25 10:25:07 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func ConvertToRegularAccountV2(requestJSON string) string {
|
|
|
|
return callWithResponse(convertToRegularAccountV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func convertToRegularAccountV2(requestJSON string) string {
|
|
|
|
var request requests.ConvertToRegularAccount
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return convertToRegularAccount(request.Mnemonic, request.CurrPassword, request.NewPassword)
|
|
|
|
}
|
|
|
|
|
2022-02-10 17:19:34 +00:00
|
|
|
func ImageServerTLSCert() string {
|
2023-06-02 02:44:24 +00:00
|
|
|
cert, err := server.PublicMediaTLSCert()
|
2022-02-10 17:19:34 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return cert
|
|
|
|
}
|
2022-03-18 12:20:13 +00:00
|
|
|
|
2022-03-23 14:19:19 +00:00
|
|
|
type GetPasswordStrengthRequest struct {
|
|
|
|
Password string `json:"password"`
|
|
|
|
UserInputs []string `json:"userInputs"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PasswordScoreResponse struct {
|
|
|
|
Score int `json:"score"`
|
|
|
|
}
|
|
|
|
|
2022-03-18 12:20:13 +00:00
|
|
|
// GetPasswordStrength uses zxcvbn module and generates a JSON containing information about the quality of the given password
|
|
|
|
// (Entropy, CrackTime, CrackTimeDisplay, Score, MatchSequence and CalcTime).
|
|
|
|
// userInputs argument can be whatever list of strings like user's personal info or site-specific vocabulary that zxcvbn will
|
|
|
|
// make use to determine the result.
|
|
|
|
// For more details on usage see https://github.com/status-im/zxcvbn-go
|
|
|
|
func GetPasswordStrength(paramsJSON string) string {
|
2022-03-23 14:19:19 +00:00
|
|
|
var requestParams GetPasswordStrengthRequest
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(paramsJSON), &requestParams)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
2022-03-18 12:20:13 +00:00
|
|
|
}
|
|
|
|
|
2022-03-23 14:19:19 +00:00
|
|
|
data, err := json.Marshal(zxcvbn.PasswordStrength(requestParams.Password, requestParams.UserInputs))
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(fmt.Errorf("Error marshalling to json: %v", err))
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetPasswordStrengthScore uses zxcvbn module and gets the score information about the given password.
|
|
|
|
// userInputs argument can be whatever list of strings like user's personal info or site-specific vocabulary that zxcvbn will
|
|
|
|
// make use to determine the result.
|
|
|
|
// For more details on usage see https://github.com/status-im/zxcvbn-go
|
|
|
|
func GetPasswordStrengthScore(paramsJSON string) string {
|
|
|
|
var requestParams GetPasswordStrengthRequest
|
|
|
|
var quality scoring.MinEntropyMatch
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(paramsJSON), &requestParams)
|
2022-03-18 12:20:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-03-23 14:19:19 +00:00
|
|
|
quality = zxcvbn.PasswordStrength(requestParams.Password, requestParams.UserInputs)
|
|
|
|
|
|
|
|
data, err := json.Marshal(PasswordScoreResponse{
|
|
|
|
Score: quality.Score,
|
|
|
|
})
|
2022-03-18 12:20:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(fmt.Errorf("Error marshalling to json: %v", err))
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
2022-03-17 18:06:02 +00:00
|
|
|
|
2023-12-07 13:45:53 +00:00
|
|
|
type FleetDescription struct {
|
2024-05-26 23:16:26 +00:00
|
|
|
DefaultFleet string `json:"defaultFleet"`
|
|
|
|
Fleets map[string]map[string][]string `json:"fleets"`
|
2023-12-07 13:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Fleets() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(fleets)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func fleets() string {
|
2023-12-07 13:45:53 +00:00
|
|
|
fleets := FleetDescription{
|
|
|
|
DefaultFleet: api.DefaultFleet,
|
2024-02-22 19:32:24 +00:00
|
|
|
Fleets: params.GetSupportedFleets(),
|
2023-12-07 13:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(fleets)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(fmt.Errorf("Error marshalling to json: %v", err))
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use SwitchFleetV2 instead.
|
2022-03-17 18:06:02 +00:00
|
|
|
func SwitchFleet(fleet string, configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(switchFleet, fleet, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func switchFleet(fleet string, configJSON string) string {
|
2022-03-17 18:06:02 +00:00
|
|
|
var conf params.NodeConfig
|
|
|
|
if configJSON != "" {
|
|
|
|
err := json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-23 12:54:51 +00:00
|
|
|
clusterConfig, err := params.LoadClusterConfigFromFleet(fleet)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-03-17 18:06:02 +00:00
|
|
|
conf.ClusterConfig.Fleet = fleet
|
2023-11-23 12:54:51 +00:00
|
|
|
conf.ClusterConfig.ClusterID = clusterConfig.ClusterID
|
2022-03-17 18:06:02 +00:00
|
|
|
|
2023-11-23 12:54:51 +00:00
|
|
|
err = statusBackend.SwitchFleet(fleet, &conf)
|
2022-03-17 18:06:02 +00:00
|
|
|
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2022-04-06 11:08:52 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func SwitchFleetV2(requestJSON string) string {
|
|
|
|
return callWithResponse(switchFleetV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func switchFleetV2(requestJSON string) string {
|
|
|
|
var request requests.SwitchFleet
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return switchFleet(request.Fleet, request.ConfigJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use GenerateImagesV2 instead.
|
2022-04-06 11:08:52 +00:00
|
|
|
func GenerateImages(filepath string, aX, aY, bX, bY int) string {
|
2024-11-19 09:31:29 +00:00
|
|
|
return generateImages(filepath, aX, aY, bX, bY)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateImagesV2(requestJSON string) string {
|
|
|
|
return callWithResponse(generateImagesV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateImagesV2(requestJSON string) string {
|
|
|
|
var request requests.GenerateImages
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return generateImages(request.Filepath, request.AX, request.AY, request.BX, request.BY)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateImages(filepath string, aX, aY, bX, bY int) string {
|
2022-04-06 11:08:52 +00:00
|
|
|
iis, err := images.GenerateIdentityImages(filepath, aX, aY, bX, bY)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(iis)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(fmt.Errorf("Error marshalling to json: %v", err))
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func LocalPairingPreflightOutboundCheck() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(localPairingPreflightOutboundCheck)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// localPairingPreflightOutboundCheck creates a local tls server accessible via an outbound network address.
|
2023-06-02 03:05:51 +00:00
|
|
|
// The function creates a client and makes an outbound network call to the local server. This function should be
|
|
|
|
// triggered to ensure that the device has permissions to access its LAN or to make outbound network calls.
|
|
|
|
//
|
|
|
|
// In addition, the functionality attempts to address an issue with iOS devices https://stackoverflow.com/a/64242745
|
2024-09-13 15:08:20 +00:00
|
|
|
func localPairingPreflightOutboundCheck() string {
|
2023-06-02 03:05:51 +00:00
|
|
|
err := preflight.CheckOutbound()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func StartSearchForLocalPairingPeers() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(startSearchForLocalPairingPeers)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// startSearchForLocalPairingPeers starts a UDP multicast beacon that both listens for and broadcasts to LAN peers
|
2023-04-12 10:30:12 +00:00
|
|
|
// on discovery the beacon will emit a signal with the details of the discovered peer.
|
|
|
|
//
|
|
|
|
// Currently, beacons are configured to search for 2 minutes pinging the network every 500 ms;
|
|
|
|
// - If no peer discovery is made before this time elapses the operation will terminate.
|
|
|
|
// - If a peer is discovered the pairing.PeerNotifier will terminate operation after 5 seconds, giving the peer
|
|
|
|
// reasonable time to discover this device.
|
|
|
|
//
|
|
|
|
// Peer details are represented by a json.Marshal peers.LocalPairingPeerHello
|
2024-09-13 15:08:20 +00:00
|
|
|
func startSearchForLocalPairingPeers() string {
|
2023-04-12 10:30:12 +00:00
|
|
|
pn := pairing.NewPeerNotifier()
|
|
|
|
err := pn.Search()
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func GetConnectionStringForBeingBootstrapped(configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(getConnectionStringForBeingBootstrapped, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getConnectionStringForBeingBootstrapped starts a pairing.ReceiverServer
|
2023-01-06 12:21:14 +00:00
|
|
|
// then generates a pairing.ConnectionParams. Used when the device is Logged out or has no Account keys
|
2022-08-31 11:44:12 +00:00
|
|
|
// and the device has no camera to read a QR code with
|
|
|
|
//
|
|
|
|
// Example: A desktop device (device without camera) receiving account data from mobile (device with camera)
|
2024-09-13 15:08:20 +00:00
|
|
|
func getConnectionStringForBeingBootstrapped(configJSON string) string {
|
2022-09-21 14:04:14 +00:00
|
|
|
if configJSON == "" {
|
2023-01-06 12:21:14 +00:00
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, PayloadSourceConfig is expected"))
|
2022-08-31 12:47:16 +00:00
|
|
|
}
|
2023-06-01 05:33:57 +00:00
|
|
|
|
2023-07-12 22:29:38 +00:00
|
|
|
statusBackend.LocalPairingStateManager.SetPairing(true)
|
2023-06-01 05:33:57 +00:00
|
|
|
defer func() {
|
2023-07-12 22:29:38 +00:00
|
|
|
statusBackend.LocalPairingStateManager.SetPairing(false)
|
2023-06-01 05:33:57 +00:00
|
|
|
}()
|
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err := pairing.StartUpReceiverServer(statusBackend, configJSON)
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2023-06-01 05:33:57 +00:00
|
|
|
|
|
|
|
err = statusBackend.Logout()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2022-08-31 12:47:16 +00:00
|
|
|
return cs
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func GetConnectionStringForBootstrappingAnotherDevice(configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(getConnectionStringForBootstrappingAnotherDevice, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getConnectionStringForBootstrappingAnotherDevice starts a pairing.SenderServer
|
2023-01-06 12:21:14 +00:00
|
|
|
// then generates a pairing.ConnectionParams. Used when the device is Logged in and therefore has Account keys
|
2022-08-31 11:44:12 +00:00
|
|
|
// and the device might not have a camera
|
|
|
|
//
|
|
|
|
// Example: A mobile or desktop device (devices that MAY have a camera but MUST have a screen)
|
|
|
|
// sending account data to a mobile (device with camera)
|
2024-09-13 15:08:20 +00:00
|
|
|
func getConnectionStringForBootstrappingAnotherDevice(configJSON string) string {
|
2022-09-21 14:04:14 +00:00
|
|
|
if configJSON == "" {
|
2023-03-23 11:44:15 +00:00
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected"))
|
2022-08-31 12:47:16 +00:00
|
|
|
}
|
2023-06-01 05:33:57 +00:00
|
|
|
|
2023-07-12 22:29:38 +00:00
|
|
|
statusBackend.LocalPairingStateManager.SetPairing(true)
|
2023-06-01 05:33:57 +00:00
|
|
|
defer func() {
|
2023-07-12 22:29:38 +00:00
|
|
|
statusBackend.LocalPairingStateManager.SetPairing(false)
|
2023-06-01 05:33:57 +00:00
|
|
|
}()
|
|
|
|
|
2023-03-21 13:08:28 +00:00
|
|
|
cs, err := pairing.StartUpSenderServer(statusBackend, configJSON)
|
2022-08-31 12:47:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return cs
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
|
|
|
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
type inputConnectionStringForBootstrappingResponse struct {
|
|
|
|
InstallationID string `json:"installationId"`
|
|
|
|
KeyUID string `json:"keyUID"`
|
|
|
|
Error error `json:"error"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *inputConnectionStringForBootstrappingResponse) toJSON(err error) string {
|
|
|
|
i.Error = err
|
|
|
|
j, _ := json.Marshal(i)
|
|
|
|
return string(j)
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use InputConnectionStringForBootstrappingV2 instead.
|
2024-09-13 15:08:20 +00:00
|
|
|
func InputConnectionStringForBootstrapping(cs, configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(inputConnectionStringForBootstrapping, cs, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// inputConnectionStringForBootstrapping starts a pairing.ReceiverClient
|
2022-08-31 14:01:45 +00:00
|
|
|
// The given server.ConnectionParams string will determine the server.Mode
|
|
|
|
//
|
|
|
|
// server.Mode = server.Sending
|
2022-08-31 12:47:16 +00:00
|
|
|
// Used when the device is Logged out or has no Account keys and has a camera to read a QR code
|
2022-08-31 11:44:12 +00:00
|
|
|
//
|
|
|
|
// Example: A mobile device (device with a camera) receiving account data from
|
|
|
|
// a device with a screen (mobile or desktop devices)
|
2024-09-13 15:08:20 +00:00
|
|
|
func inputConnectionStringForBootstrapping(cs, configJSON string) string {
|
2023-07-12 22:29:38 +00:00
|
|
|
var err error
|
2022-09-21 14:04:14 +00:00
|
|
|
if configJSON == "" {
|
2023-03-23 11:44:15 +00:00
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected"))
|
|
|
|
}
|
|
|
|
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
params := &pairing.ConnectionParams{}
|
|
|
|
err = params.FromString(cs)
|
|
|
|
if err != nil {
|
|
|
|
response := &inputConnectionStringForBootstrappingResponse{}
|
|
|
|
return response.toJSON(fmt.Errorf("could not parse connection string"))
|
|
|
|
}
|
|
|
|
response := &inputConnectionStringForBootstrappingResponse{
|
|
|
|
InstallationID: params.InstallationID(),
|
|
|
|
KeyUID: params.KeyUID(),
|
|
|
|
}
|
|
|
|
|
2023-07-12 22:29:38 +00:00
|
|
|
err = statusBackend.LocalPairingStateManager.StartPairing(cs)
|
|
|
|
defer func() { statusBackend.LocalPairingStateManager.StopPairing(cs, err) }()
|
|
|
|
if err != nil {
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
return response.toJSON(err)
|
2023-07-12 22:29:38 +00:00
|
|
|
}
|
2023-06-01 05:33:57 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
var conf pairing.ReceiverClientConfig
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return response.toJSON(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = pairing.StartUpReceivingClient(statusBackend, cs, &conf)
|
2023-06-01 05:33:57 +00:00
|
|
|
if err != nil {
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
return response.toJSON(err)
|
2023-06-01 05:33:57 +00:00
|
|
|
}
|
|
|
|
|
feat: fallback pairing seed (#5614)
* feat(pairing)!: Add extra parameters and remove v2 compatibility
This commit includes the following changes:
I have added a flag to maintain 2.29 compatibility.
Breaking change in connection string
The local pairing code that was parsing the connection string had a few non-upgradable features:
It was strictly checking the number of parameters, throwing an error if the number was different. This made it impossible to add parameters to it without breaking.
It was strictly checking the version number. This made increasing the version number impossible as older client would just refuse to connect.
The code has been changed so that:
Two parameters have been added, installation-id and key-uid. Those are needed for the fallback flow.
I have also removed version from the payload, since it wasn't used.
This means that we don't support v1 anymore. V2 parsing is supported . Going forward there's a clear strategy on how to update the protocol (append parameters, don't change existing one).
https://www.youtube.com/watch?v=oyLBGkS5ICk Is a must watch video for understanding the strategy
Changed MessengerResponse to use internally a map of installations rather than an array (minor)
Just moving towards maps as arrays tend to lead to subtle bugs.
Moved pairing methods to messenger_pairing.go
Just moved some methods
Added 2 new methods for the fallback flow
FinishPairingThroughSeedPhraseProcess
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R29
EnableAndSyncInstallation
https://github.com/status-im/status-go/pull/5567/files#diff-1ad620b07fa3bd5fbc96c9f459d88829938a162bf1aaf41c61dea6e38b488d54R18
Flow for clients
Client A1 is logged in
Client A2 is logged out
Client A1 shows a QR code
Client A2 scans a QR code
If connection fails on A2, the user will be prompted to enter a seed phrase.
If the generated account matches the key-uid from the QR code, A2 should call FinishPairingThroughSeedPhraseProcess with the installation id passed in the QR code. This will send installation information over waku. The user should be shown its own installation id and prompted to check the other device.
Client A1 will receive new installation data through waku, if they are still on the qr code page, they should show a popup to the user showing the received installation id, and a way to Enable and Sync, which should call the EnableAndSyncInstallation endpoint. This should finish the fallback syncing flow.
Current issues
Currently I haven't tested that all the data is synced after finishing the flow. I see that the two devices are paired correctly, but for example the DisplayName is not changed on the receiving device. I haven't had time to look into it further.
* test_: add more test for connection string parser
* fix_: fix panic when parse old connection string
* test_: add comments for TestMessengerPairAfterSeedPhrase
* fix_: correct error description
* feat_:rename FinishPairingThroughSeedPhraseProcess to EnableInstallationAndPair
* fix_: delete leftover
* fix_: add UniqueKey method
* fix_: unify the response for InputConnectionStringForBootstrapping
* fix_: remove fields installationID and keyUID in GethStatusBackend
* fix_: rename messenger_pairing to messenger_pairing_and_syncing
---------
Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2024-07-30 09:14:05 +00:00
|
|
|
return response.toJSON(statusBackend.Logout())
|
2023-03-23 11:44:15 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func InputConnectionStringForBootstrappingV2(requestJSON string) string {
|
|
|
|
return callWithResponse(inputConnectionStringForBootstrappingV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func inputConnectionStringForBootstrappingV2(requestJSON string) string {
|
|
|
|
var request m_requests.InputConnectionStringForBootstrapping
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
if err := request.Validate(); err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
params := &pairing.ConnectionParams{}
|
|
|
|
err = params.FromString(request.ConnectionString)
|
|
|
|
if err != nil {
|
|
|
|
response := &inputConnectionStringForBootstrappingResponse{}
|
|
|
|
return response.toJSON(fmt.Errorf("could not parse connection string"))
|
|
|
|
}
|
|
|
|
response := &inputConnectionStringForBootstrappingResponse{
|
|
|
|
InstallationID: params.InstallationID(),
|
|
|
|
KeyUID: params.KeyUID(),
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.LocalPairingStateManager.StartPairing(request.ConnectionString)
|
|
|
|
defer func() { statusBackend.LocalPairingStateManager.StopPairing(request.ConnectionString, err) }()
|
|
|
|
if err != nil {
|
|
|
|
return response.toJSON(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = pairing.StartUpReceivingClient(statusBackend, request.ConnectionString, request.ReceiverClientConfig)
|
|
|
|
if err != nil {
|
|
|
|
return response.toJSON(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.toJSON(statusBackend.Logout())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use InputConnectionStringForBootstrappingAnotherDeviceV2 instead.
|
2024-09-13 15:08:20 +00:00
|
|
|
func InputConnectionStringForBootstrappingAnotherDevice(cs, configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(inputConnectionStringForBootstrappingAnotherDevice, cs, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// inputConnectionStringForBootstrappingAnotherDevice starts a pairing.SendingClient
|
2023-03-23 11:44:15 +00:00
|
|
|
// The given server.ConnectionParams string will determine the server.Mode
|
|
|
|
//
|
|
|
|
// server.Mode = server.Receiving
|
|
|
|
// 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)
|
2024-09-13 15:08:20 +00:00
|
|
|
func inputConnectionStringForBootstrappingAnotherDevice(cs, configJSON string) string {
|
2023-07-12 22:29:38 +00:00
|
|
|
var err error
|
2023-03-23 11:44:15 +00:00
|
|
|
if configJSON == "" {
|
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, SenderClientConfig is expected"))
|
2022-08-31 12:47:16 +00:00
|
|
|
}
|
2022-08-31 11:44:12 +00:00
|
|
|
|
2023-07-12 22:29:38 +00:00
|
|
|
err = statusBackend.LocalPairingStateManager.StartPairing(cs)
|
|
|
|
defer func() { statusBackend.LocalPairingStateManager.StopPairing(cs, err) }()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2024-11-19 09:31:29 +00:00
|
|
|
var conf pairing.SenderClientConfig
|
|
|
|
err = json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = pairing.StartUpSendingClient(statusBackend, cs, &conf)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InputConnectionStringForBootstrappingAnotherDeviceV2(requestJSON string) string {
|
|
|
|
return callWithResponse(inputConnectionStringForBootstrappingAnotherDeviceV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func inputConnectionStringForBootstrappingAnotherDeviceV2(requestJSON string) string {
|
|
|
|
var request m_requests.InputConnectionStringForBootstrappingAnotherDevice
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
if err := request.Validate(); err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.LocalPairingStateManager.StartPairing(request.ConnectionString)
|
|
|
|
defer func() { statusBackend.LocalPairingStateManager.StopPairing(request.ConnectionString, err) }()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2023-06-01 05:33:57 +00:00
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
err = pairing.StartUpSendingClient(statusBackend, request.ConnectionString, request.SenderClientConfig)
|
2022-08-31 14:01:45 +00:00
|
|
|
return makeJSONResponse(err)
|
2022-08-31 11:44:12 +00:00
|
|
|
}
|
2022-08-24 12:42:41 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
func GetConnectionStringForExportingKeypairsKeystores(configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(getConnectionStringForExportingKeypairsKeystores, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getConnectionStringForExportingKeypairsKeystores starts a pairing.SenderServer
|
2023-08-18 08:51:16 +00:00
|
|
|
// then generates a pairing.ConnectionParams. Used when the device is Logged in and therefore has Account keys
|
|
|
|
// and the device might not have a camera, to transfer kestore files of provided key uids.
|
2024-09-13 15:08:20 +00:00
|
|
|
func getConnectionStringForExportingKeypairsKeystores(configJSON string) string {
|
2023-08-18 08:51:16 +00:00
|
|
|
if configJSON == "" {
|
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, SendingServerConfig is expected"))
|
|
|
|
}
|
|
|
|
|
|
|
|
cs, err := pairing.StartUpKeystoreFilesSenderServer(statusBackend, configJSON)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return cs
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use InputConnectionStringForImportingKeypairsKeystoresV2 instead.
|
2024-09-13 15:08:20 +00:00
|
|
|
func InputConnectionStringForImportingKeypairsKeystores(cs, configJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(inputConnectionStringForImportingKeypairsKeystores, cs, configJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// inputConnectionStringForImportingKeypairsKeystores starts a pairing.ReceiverClient
|
2023-08-18 08:51:16 +00:00
|
|
|
// The given server.ConnectionParams string will determine the server.Mode
|
|
|
|
// Used when the device is Logged in and has 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)
|
2024-09-13 15:08:20 +00:00
|
|
|
func inputConnectionStringForImportingKeypairsKeystores(cs, configJSON string) string {
|
2023-08-18 08:51:16 +00:00
|
|
|
if configJSON == "" {
|
|
|
|
return makeJSONResponse(fmt.Errorf("no config given, ReceiverClientConfig is expected"))
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
var conf pairing.KeystoreFilesReceiverClientConfig
|
|
|
|
err := json.Unmarshal([]byte(configJSON), &conf)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = pairing.StartUpKeystoreFilesReceivingClient(statusBackend, cs, &conf)
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func InputConnectionStringForImportingKeypairsKeystoresV2(requestJSON string) string {
|
|
|
|
return callWithResponse(inputConnectionStringForImportingKeypairsKeystoresV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func inputConnectionStringForImportingKeypairsKeystoresV2(requestJSON string) string {
|
|
|
|
var request m_requests.InputConnectionStringForImportingKeypairsKeystores
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
if err := request.Validate(); err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
err = pairing.StartUpKeystoreFilesReceivingClient(statusBackend, request.ConnectionString, request.KeystoreFilesReceiverClientConfig)
|
2023-08-18 08:51:16 +00:00
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:42:12 +00:00
|
|
|
func ValidateConnectionString(cs string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(validateConnectionString, cs)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func validateConnectionString(cs string) string {
|
2023-02-15 14:42:12 +00:00
|
|
|
err := pairing.ValidateConnectionString(cs)
|
|
|
|
if err == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return err.Error()
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
// Deprecated: Use EncodeTransferV2 instead.
|
2022-08-24 12:42:41 +00:00
|
|
|
func EncodeTransfer(to string, value string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(encodeTransfer, to, value)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func encodeTransfer(to string, value string) string {
|
2022-08-24 12:42:41 +00:00
|
|
|
result, err := abi_spec.EncodeTransfer(to, value)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to encode transfer", zap.String("to", to), zap.String("value", value), zap.Error(err))
|
2022-08-24 12:42:41 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func EncodeTransferV2(requestJSON string) string {
|
|
|
|
return callWithResponse(encodeTransferV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func encodeTransferV2(requestJSON string) string {
|
|
|
|
var request requests.EncodeTransfer
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return encodeTransfer(request.To, request.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deprecated: Use EncodeFunctionCallV2 instead.
|
2022-08-24 12:42:41 +00:00
|
|
|
func EncodeFunctionCall(method string, paramsJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(encodeFunctionCall, method, paramsJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func encodeFunctionCall(method string, paramsJSON string) string {
|
2022-08-24 12:42:41 +00:00
|
|
|
result, err := abi_spec.Encode(method, paramsJSON)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to encode function call", zap.String("method", method), zap.String("paramsJSON", paramsJSON), zap.Error(err))
|
2024-09-13 15:08:20 +00:00
|
|
|
return ""
|
2022-08-24 12:42:41 +00:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2024-11-19 09:31:29 +00:00
|
|
|
func EncodeFunctionCallV2(requestJSON string) string {
|
|
|
|
return callWithResponse(encodeFunctionCallV2, requestJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func encodeFunctionCallV2(requestJSON string) string {
|
|
|
|
var request requests.EncodeFunctionCall
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return encodeFunctionCall(request.Method, request.ParamsJSON)
|
|
|
|
}
|
|
|
|
|
2022-08-24 12:42:41 +00:00
|
|
|
func DecodeParameters(decodeParamJSON string) string {
|
2024-09-13 15:08:20 +00:00
|
|
|
return decodeParameters(decodeParamJSON)
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeParameters(decodeParamJSON string) string {
|
2022-08-24 12:42:41 +00:00
|
|
|
decodeParam := struct {
|
|
|
|
BytesString string `json:"bytesString"`
|
|
|
|
Types []string `json:"types"`
|
|
|
|
}{}
|
|
|
|
err := json.Unmarshal([]byte(decodeParamJSON), &decodeParam)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to unmarshal json when decoding parameters", zap.String("decodeParamJSON", decodeParamJSON), zap.Error(err))
|
2022-08-24 12:42:41 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
result, err := abi_spec.Decode(decodeParam.BytesString, decodeParam.Types)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to decode parameters", zap.String("decodeParamJSON", decodeParamJSON), zap.Error(err))
|
2022-08-24 12:42:41 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
bytes, err := json.Marshal(result)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to marshal result", zap.Any("result", result), zap.String("decodeParamJSON", decodeParamJSON), zap.Error(err))
|
2022-08-24 12:42:41 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return string(bytes)
|
|
|
|
}
|
|
|
|
|
|
|
|
func HexToNumber(hex string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hexToNumber, hex)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hexToNumber(hex string) string {
|
2022-08-24 12:42:41 +00:00
|
|
|
return abi_spec.HexToNumber(hex)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NumberToHex(numString string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(numberToHex, numString)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func numberToHex(numString string) string {
|
2022-08-24 12:42:41 +00:00
|
|
|
return abi_spec.NumberToHex(numString)
|
|
|
|
}
|
2022-10-18 13:36:54 +00:00
|
|
|
|
|
|
|
func Sha3(str string) string {
|
|
|
|
return "0x" + abi_spec.Sha3(str)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Utf8ToHex(str string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(utf8ToHex, str)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func utf8ToHex(str string) string {
|
2022-10-18 13:36:54 +00:00
|
|
|
hexString, err := abi_spec.Utf8ToHex(str)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to convert utf8 to hex", zap.String("str", str), zap.Error(err))
|
2022-10-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
return hexString
|
|
|
|
}
|
|
|
|
|
|
|
|
func HexToUtf8(hexString string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(hexToUtf8, hexString)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func hexToUtf8(hexString string) string {
|
2022-10-18 13:36:54 +00:00
|
|
|
str, err := abi_spec.HexToUtf8(hexString)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to convert hex to utf8", zap.String("hexString", hexString), zap.Error(err))
|
2022-10-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
|
|
|
func CheckAddressChecksum(address string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(checkAddressChecksum, address)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkAddressChecksum(address string) string {
|
2022-10-18 13:36:54 +00:00
|
|
|
valid, err := abi_spec.CheckAddressChecksum(address)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to invoke check address checksum", zap.String("address", address), zap.Error(err))
|
2022-10-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
result, _ := json.Marshal(valid)
|
|
|
|
return string(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsAddress(address string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(isAddress, address)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func isAddress(address string) string {
|
2022-10-18 13:36:54 +00:00
|
|
|
valid, err := abi_spec.IsAddress(address)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to invoke IsAddress", zap.String("address", address), zap.Error(err))
|
2022-10-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
result, _ := json.Marshal(valid)
|
|
|
|
return string(result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ToChecksumAddress(address string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(toChecksumAddress, address)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func toChecksumAddress(address string) string {
|
2022-10-18 13:36:54 +00:00
|
|
|
address, err := abi_spec.ToChecksumAddress(address)
|
|
|
|
if err != nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Error("failed to convert to checksum address", zap.String("address", address), zap.Error(err))
|
2022-10-18 13:36:54 +00:00
|
|
|
}
|
|
|
|
return address
|
|
|
|
}
|
2023-01-04 01:55:07 +00:00
|
|
|
|
|
|
|
func DeserializeAndCompressKey(DesktopKey string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(deserializeAndCompressKey, DesktopKey)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func deserializeAndCompressKey(DesktopKey string) string {
|
2023-01-04 01:55:07 +00:00
|
|
|
deserialisedKey := MultiformatDeserializePublicKey(DesktopKey, "f")
|
|
|
|
sanitisedKey := "0x" + deserialisedKey[5:]
|
|
|
|
return CompressPublicKey(sanitisedKey)
|
|
|
|
}
|
2023-06-21 13:04:43 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
type InitLoggingRequest struct {
|
|
|
|
logutils.LogSettings
|
|
|
|
LogRequestGo bool `json:"LogRequestGo"`
|
|
|
|
LogRequestFile string `json:"LogRequestFile"`
|
|
|
|
}
|
|
|
|
|
2024-08-07 11:52:06 +00:00
|
|
|
// InitLogging The InitLogging function should be called when the application starts.
|
|
|
|
// This ensures that we can capture logs before the user login. Subsequent calls will update the logger settings.
|
2023-06-21 13:04:43 +00:00
|
|
|
// Before this, we can only capture logs after user login since we will only configure the logging after the login process.
|
|
|
|
func InitLogging(logSettingsJSON string) string {
|
2024-09-13 15:08:20 +00:00
|
|
|
var logSettings InitLoggingRequest
|
2023-06-21 13:04:43 +00:00
|
|
|
var err error
|
|
|
|
if err = json.Unmarshal([]byte(logSettingsJSON), &logSettings); err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2024-08-07 13:07:26 +00:00
|
|
|
|
2024-11-04 08:09:28 +00:00
|
|
|
if err = logutils.OverrideRootLoggerWithConfig(logSettings.LogSettings); err == nil {
|
2024-10-28 20:54:17 +00:00
|
|
|
logutils.ZapLogger().Info("logging initialised", zap.String("logSettings", logSettingsJSON))
|
2024-08-07 11:52:06 +00:00
|
|
|
}
|
2023-06-21 13:04:43 +00:00
|
|
|
|
2024-09-13 15:08:20 +00:00
|
|
|
if logSettings.LogRequestGo {
|
|
|
|
err = requestlog.ConfigureAndEnableRequestLogging(logSettings.LogRequestFile)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-21 13:04:43 +00:00
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
2024-02-19 12:53:01 +00:00
|
|
|
|
|
|
|
func GetRandomMnemonic() string {
|
|
|
|
mnemonic, err := account.GetRandomMnemonic()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return mnemonic
|
|
|
|
}
|
2024-07-03 11:51:14 +00:00
|
|
|
|
|
|
|
func ToggleCentralizedMetrics(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(toggleCentralizedMetrics, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func toggleCentralizedMetrics(requestJSON string) string {
|
2024-07-03 11:51:14 +00:00
|
|
|
var request requests.ToggleCentralizedMetrics
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = statusBackend.ToggleCentralizedMetrics(request.Enabled)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
2024-07-19 12:22:15 +00:00
|
|
|
return makeJSONResponse(nil)
|
2024-07-03 11:51:14 +00:00
|
|
|
}
|
|
|
|
|
2024-07-11 07:39:19 +00:00
|
|
|
func CentralizedMetricsInfo() string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(centralizedMetricsInfo)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func centralizedMetricsInfo() string {
|
2024-07-11 07:39:19 +00:00
|
|
|
metricsInfo, err := statusBackend.CentralizedMetricsInfo()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
data, err := json.Marshal(metricsInfo)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
return string(data)
|
|
|
|
}
|
|
|
|
|
2024-07-03 11:51:14 +00:00
|
|
|
func AddCentralizedMetric(requestJSON string) string {
|
2024-09-26 22:37:32 +00:00
|
|
|
return callWithResponse(addCentralizedMetric, requestJSON)
|
2024-09-13 15:08:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func addCentralizedMetric(requestJSON string) string {
|
2024-07-03 11:51:14 +00:00
|
|
|
var request requests.AddCentralizedMetric
|
|
|
|
err := json.Unmarshal([]byte(requestJSON), &request)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = request.Validate()
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
metric := request.Metric
|
|
|
|
|
|
|
|
metric.EnsureID()
|
|
|
|
err = statusBackend.AddCentralizedMetric(*metric)
|
|
|
|
if err != nil {
|
|
|
|
return makeJSONResponse(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return metric.ID
|
|
|
|
}
|