-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathstatus.go
2441 lines (2069 loc) · 73.2 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package statusgo
import (
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"os"
"path"
"runtime"
"time"
"unsafe"
"go.uber.org/zap"
"gopkg.in/go-playground/validator.v9"
"github.com/ethereum/go-ethereum/signer/core/apitypes"
"github.com/status-im/zxcvbn-go"
"github.com/status-im/zxcvbn-go/scoring"
"github.com/status-im/extkeys"
abi_spec "github.com/status-im/status-go/abi-spec"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/api"
"github.com/status-im/status-go/api/multiformat"
"github.com/status-im/status-go/centralizedmetrics"
"github.com/status-im/status-go/centralizedmetrics/providers"
gocommon "github.com/status-im/status-go/common"
"github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/exportlogs"
"github.com/status-im/status-go/images"
"github.com/status-im/status-go/logutils"
"github.com/status-im/status-go/logutils/callog"
"github.com/status-im/status-go/logutils/requestlog"
m_requests "github.com/status-im/status-go/mobile/requests"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/accounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/profiling"
"github.com/status-im/status-go/protocol"
"github.com/status-im/status-go/protocol/common"
identityUtils "github.com/status-im/status-go/protocol/identity"
"github.com/status-im/status-go/protocol/identity/alias"
"github.com/status-im/status-go/protocol/identity/colorhash"
"github.com/status-im/status-go/protocol/identity/emojihash"
"github.com/status-im/status-go/protocol/requests"
"github.com/status-im/status-go/server"
"github.com/status-im/status-go/server/pairing"
"github.com/status-im/status-go/server/pairing/preflight"
"github.com/status-im/status-go/services/personal"
"github.com/status-im/status-go/services/typeddata"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/signal"
)
func call(fn any, params ...any) any {
return callog.Call(logutils.ZapLogger(), requestlog.GetRequestLogger(), fn, params...)
}
func callWithResponse(fn any, params ...any) string {
return callog.CallWithResponse(logutils.ZapLogger(), requestlog.GetRequestLogger(), fn, params...)
}
type InitializeApplicationResponse struct {
Accounts []multiaccounts.Account `json:"accounts"`
CentralizedMetricsInfo *centralizedmetrics.MetricsInfo `json:"centralizedMetricsInfo"`
}
func InitializeApplication(requestJSON string) string {
// NOTE: InitializeApplication is logs the call on its own rather than using `callWithResponse`,
// because the API logging is enabled during this exact call.
defer callog.Recover(logutils.ZapLogger())
startTime := time.Now()
response := initializeApplication(requestJSON)
callog.LogCall(
requestlog.GetRequestLogger(),
"InitializeApplication",
requestJSON,
response,
startTime,
)
return response
}
func initializeApplication(requestJSON string) string {
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)
}
err = initializeLogging(&request)
if err != nil {
return makeJSONResponse(err)
}
providers.MixpanelAppID = request.MixpanelAppID
providers.MixpanelToken = request.MixpanelToken
err = os.MkdirAll(request.DataDir, 0700)
if err != nil {
return makeJSONResponse(err)
}
statusBackend.StatusNode().SetMediaServerEnableTLS(request.MediaServerEnableTLS)
statusBackend.UpdateRootDataDir(request.DataDir)
err = statusBackend.OpenAccounts()
if err != nil {
return makeJSONResponse(err)
}
accs, err := statusBackend.GetAccounts()
if err != nil {
return makeJSONResponse(err)
}
metricsInfo, err := statusBackend.CentralizedMetricsInfo()
if err != nil {
return makeJSONResponse(err)
}
statusBackend.SetSentryDSN(request.SentryDSN)
if metricsInfo.Enabled {
err = statusBackend.EnablePanicReporting()
if err != nil {
return makeJSONResponse(err)
}
}
if request.WakuFleetsConfigFilePath != "" {
err = params.LoadFleetsFromFile(request.WakuFleetsConfigFilePath)
if err != nil {
return makeJSONResponse(err)
}
}
response := &InitializeApplicationResponse{
Accounts: accs,
CentralizedMetricsInfo: metricsInfo,
}
data, err := json.Marshal(response)
if err != nil {
return makeJSONResponse(err)
}
return string(data)
}
func initializeLogging(request *requests.InitializeApplication) error {
if request.LogDir == "" {
request.LogDir = request.DataDir
}
preLoginLog := statusBackend.PreLoginLog()
preLoginLog.SetEnabled(request.LogEnabled)
if request.LogLevel != "" {
// ignore the error since it's already validated
_ = preLoginLog.SetLevel(request.LogLevel)
}
err := os.MkdirAll(request.LogDir, 0700)
if err != nil {
return err
}
preLoginLog.SetLogDir(request.LogDir)
logSettings := preLoginLog.ConvertToLogSettings()
err = logutils.OverrideRootLoggerWithConfig(logSettings)
if err != nil {
return err
}
logutils.ZapLogger().Info("logging initialised",
zap.Any("logSettings", logSettings),
zap.Bool("APILoggingEnabled", request.APILoggingEnabled),
)
if request.APILoggingEnabled {
logRequestsFile := path.Join(request.LogDir, api.DefaultAPILogFile)
err = requestlog.ConfigureAndEnableRequestLogging(logRequestsFile)
if err != nil {
return err
}
}
if request.MetricsEnabled {
// Start metrics server
err := statusBackend.StartPrometheusMetricsServer(request.MetricsAddress)
if err != nil {
return err
}
logutils.ZapLogger().Info("metrics prometheus server started", zap.String("address", request.MetricsAddress))
}
return nil
}
// Deprecated: Use InitializeApplication instead.
func OpenAccounts(datadir string) string {
return callWithResponse(openAccounts, datadir)
}
// DEPRECATED: use InitializeApplication
// openAccounts opens database and returns accounts list.
func openAccounts(datadir string) string {
statusBackend.UpdateRootDataDir(datadir)
err := statusBackend.OpenAccounts()
if err != nil {
return makeJSONResponse(err)
}
accs, err := statusBackend.GetAccounts()
if err != nil {
return makeJSONResponse(err)
}
data, err := json.Marshal(accs)
if err != nil {
return makeJSONResponse(err)
}
return string(data)
}
func ExtractGroupMembershipSignatures(signaturePairsStr string) string {
return callWithResponse(extractGroupMembershipSignatures, signaturePairsStr)
}
// ExtractGroupMembershipSignatures extract public keys from tuples of content/signature.
func extractGroupMembershipSignatures(signaturePairsStr string) string {
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 {
return callWithResponse(signGroupMembership, content)
}
// signGroupMembership signs a string containing group membership information.
func signGroupMembership(content string) string {
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)
}
func GetNodeConfig() string {
return callWithResponse(getNodeConfig)
}
// getNodeConfig returns the current config of the Status node
func getNodeConfig() string {
conf, err := statusBackend.GetNodeConfig()
if err != nil {
return makeJSONResponse(err)
}
respJSON, err := json.Marshal(conf)
if err != nil {
return makeJSONResponse(err)
}
return string(respJSON)
}
func ValidateNodeConfig(configJSON string) string {
return callWithResponse(validateNodeConfig, configJSON)
}
// validateNodeConfig validates config for the Status node.
func validateNodeConfig(configJSON string) string {
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 {
return callWithResponse(resetChainData)
}
// resetChainData removes chain data from data directory.
func resetChainData() string {
api.RunAsync(statusBackend.ResetChainData)
return makeJSONResponse(nil)
}
func CallRPC(inputJSON string) string {
return callRPC(inputJSON)
}
// callRPC calls public APIs via RPC.
func callRPC(inputJSON string) string {
resp, err := statusBackend.CallRPC(inputJSON)
if err != nil {
return makeJSONResponse(err)
}
return resp
}
func CallPrivateRPC(inputJSON string) string {
return callPrivateRPC(inputJSON)
}
// callPrivateRPC calls both public and private APIs via RPC.
func callPrivateRPC(inputJSON string) string {
resp, err := statusBackend.CallPrivateRPC(inputJSON)
if err != nil {
return makeJSONResponse(err)
}
return resp
}
// Deprecated: Use VerifyAccountPasswordV2 instead
func VerifyAccountPassword(keyStoreDir, address, password string) string {
return verifyAccountPassword(keyStoreDir, address, password)
}
// verifyAccountPassword verifies account password.
func verifyAccountPassword(keyStoreDir, address, password string) string {
_, err := statusBackend.AccountManager().VerifyAccountPassword(keyStoreDir, address, password)
return makeJSONResponse(err)
}
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)
}
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
func VerifyDatabasePassword(keyUID, password string) string {
return verifyDatabasePassword(keyUID, password)
}
// verifyDatabasePassword verifies database password.
func verifyDatabasePassword(keyUID, password string) string {
err := statusBackend.VerifyDatabasePassword(keyUID, password)
return makeJSONResponse(err)
}
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
func MigrateKeyStoreDir(accountData, password, oldDir, newDir string) string {
return migrateKeyStoreDir(accountData, password, oldDir, newDir)
}
// migrateKeyStoreDir migrates key files to a new directory
func migrateKeyStoreDir(accountData, password, oldDir, newDir string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
err = statusBackend.MigrateKeyStoreDir(account, password, oldDir, newDir)
return makeJSONResponse(err)
}
// login deprecated as Login and LoginWithConfig are deprecated
func login(accountData, password, configJSON string) error {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return err
}
var conf params.NodeConfig
if configJSON != "" {
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
return err
}
}
api.RunAsync(func() error {
logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID))
err := statusBackend.UpdateNodeConfigFleet(account, password, &conf)
if err != nil {
logutils.ZapLogger().Error("failed to update node config fleet", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err))
return statusBackend.LoggedIn(account.KeyUID, err)
}
err = statusBackend.StartNodeWithAccount(account, password, &conf, nil)
if err != nil {
logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err))
return err
}
logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID))
return nil
})
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.
//
// Deprecated: Use LoginAccount instead.
func Login(accountData, password string) string {
err := login(accountData, password, "")
if err != nil {
return makeJSONResponse(err)
}
return makeJSONResponse(nil)
}
// LoginWithConfig 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. It then updates the accounts node db configuration
// mergin the values received in the configJSON parameter
//
// Deprecated: Use LoginAccount instead.
func LoginWithConfig(accountData, password, configJSON string) string {
err := login(accountData, password, configJSON)
if err != nil {
return makeJSONResponse(err)
}
return makeJSONResponse(nil)
}
func CreateAccountAndLogin(requestJSON string) string {
return callWithResponse(createAccountAndLogin, requestJSON)
}
func createAccountAndLogin(requestJSON string) string {
var request requests.CreateAccount
err := json.Unmarshal([]byte(requestJSON), &request)
if err != nil {
return makeJSONResponse(err)
}
err = request.Validate(&requests.CreateAccountValidation{
AllowEmptyDisplayName: true,
})
if err != nil {
return makeJSONResponse(err)
}
api.RunAsync(func() error {
logutils.ZapLogger().Debug("starting a node and creating config")
_, err := statusBackend.CreateAccountAndLogin(&request)
if err != nil {
logutils.ZapLogger().Error("failed to create account", zap.Error(err))
return statusBackend.LoggedIn("", err)
}
logutils.ZapLogger().Debug("started a node, and created account")
return statusBackend.SetupLogSettings()
})
return makeJSONResponse(nil)
}
func AcceptTerms() string {
return callWithResponse(acceptTerms)
}
func acceptTerms() string {
err := statusBackend.AcceptTerms()
return makeJSONResponse(err)
}
func LoginAccount(requestJSON string) string {
return callWithResponse(loginAccount, requestJSON)
}
func loginAccount(requestJSON string) string {
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 {
logutils.ZapLogger().Error("loginAccount failed", zap.Error(err))
return err
}
logutils.ZapLogger().Debug("loginAccount started node")
return statusBackend.SetupLogSettings()
})
return makeJSONResponse(nil)
}
func RestoreAccountAndLogin(requestJSON string) string {
return callWithResponse(restoreAccountAndLogin, requestJSON)
}
func restoreAccountAndLogin(requestJSON string) string {
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 {
logutils.ZapLogger().Debug("starting a node and restoring account")
if request.Keycard != nil {
_, err = statusBackend.RestoreKeycardAccountAndLogin(&request)
} else {
_, err = statusBackend.RestoreAccountAndLogin(&request)
}
if err != nil {
logutils.ZapLogger().Error("failed to restore account", zap.Error(err))
return statusBackend.LoggedIn("", err)
}
logutils.ZapLogger().Debug("started a node, and restored account")
return statusBackend.SetupLogSettings()
})
return makeJSONResponse(nil)
}
// SaveAccountAndLogin saves account in status-go database.
// Deprecated: Use CreateAccountAndLogin instead.
func SaveAccountAndLogin(accountData, password, settingsJSON, configJSON, subaccountData string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var settings settings.Settings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if err != nil {
return makeJSONResponse(err)
}
if *settings.Mnemonic != "" {
settings.MnemonicWasNotShown = true
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
return makeJSONResponse(err)
}
var subaccs []*accounts.Account
err = json.Unmarshal([]byte(subaccountData), &subaccs)
if err != nil {
return makeJSONResponse(err)
}
api.RunAsync(func() error {
logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID))
err := statusBackend.StartNodeWithAccountAndInitialConfig(account, password, settings, &conf, subaccs, nil)
if err != nil {
logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err))
return err
}
logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID))
return statusBackend.SetupLogSettings()
})
return makeJSONResponse(nil)
}
// Deprecated: Use DeleteMultiaccountV2 instead
func DeleteMultiaccount(keyUID, keyStoreDir string) string {
return callWithResponse(deleteMultiaccount, keyUID, keyStoreDir)
}
// deleteMultiaccount
func deleteMultiaccount(keyUID, keyStoreDir string) string {
err := statusBackend.DeleteMultiaccount(keyUID, keyStoreDir)
return makeJSONResponse(err)
}
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)
}
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
func DeleteImportedKey(address, password, keyStoreDir string) string {
return deleteImportedKey(address, password, keyStoreDir)
}
// deleteImportedKey
func deleteImportedKey(address, password, keyStoreDir string) string {
err := statusBackend.DeleteImportedKey(address, password, keyStoreDir)
return makeJSONResponse(err)
}
func InitKeystore(keydir string) string {
return callWithResponse(initKeystore, keydir)
}
// initKeystore initialize keystore before doing any operations with keys.
func initKeystore(keydir string) string {
err := statusBackend.AccountManager().InitKeystore(keydir)
return makeJSONResponse(err)
}
// SaveAccountAndLoginWithKeycard saves account in status-go database.
// Deprecated: Use CreateAndAccountAndLogin with required keycard properties.
func SaveAccountAndLoginWithKeycard(accountData, password, settingsJSON, configJSON, subaccountData string, keyHex string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var settings settings.Settings
err = json.Unmarshal([]byte(settingsJSON), &settings)
if err != nil {
return makeJSONResponse(err)
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
return makeJSONResponse(err)
}
var subaccs []*accounts.Account
err = json.Unmarshal([]byte(subaccountData), &subaccs)
if err != nil {
return makeJSONResponse(err)
}
api.RunAsync(func() error {
logutils.ZapLogger().Debug("starting a node, and saving account with configuration", zap.String("key-uid", account.KeyUID))
err := statusBackend.SaveAccountAndStartNodeWithKey(account, password, settings, &conf, subaccs, keyHex)
if err != nil {
logutils.ZapLogger().Error("failed to start node and save account", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err))
return err
}
logutils.ZapLogger().Debug("started a node, and saved account", zap.String("key-uid", account.KeyUID))
return nil
})
return makeJSONResponse(nil)
}
// 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.
// Deprecated: Use LoginAccount instead.
func LoginWithKeycard(accountData, password, keyHex string, configJSON string) string {
var account multiaccounts.Account
err := json.Unmarshal([]byte(accountData), &account)
if err != nil {
return makeJSONResponse(err)
}
var conf params.NodeConfig
err = json.Unmarshal([]byte(configJSON), &conf)
if err != nil {
return makeJSONResponse(err)
}
api.RunAsync(func() error {
logutils.ZapLogger().Debug("start a node with account", zap.String("key-uid", account.KeyUID))
err := statusBackend.StartNodeWithKey(account, password, keyHex, &conf)
if err != nil {
logutils.ZapLogger().Error("failed to start a node", zap.String("key-uid", gocommon.TruncateWithDot(account.KeyUID)), zap.Error(err))
return err
}
logutils.ZapLogger().Debug("started a node with", zap.String("key-uid", account.KeyUID))
return nil
})
return makeJSONResponse(nil)
}
func Logout() string {
return callWithResponse(logout)
}
// logout is equivalent to clearing whisper identities.
func logout() string {
return makeJSONResponse(statusBackend.Logout())
}
func SignMessage(rpcParams string) string {
return callWithResponse(signMessage, rpcParams)
}
// signMessage unmarshals rpc params {data, address, password} and
// passes them onto backend.SignMessage.
func signMessage(rpcParams string) string {
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)
}
// SignTypedData unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account.
func SignTypedData(data, address, password string) string {
return signTypedData(data, address, password)
}
func signTypedData(data, address, password string) string {
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.SignTypedData(typed, address, password)
return prepareJSONResponse(result.String(), err)
}
// HashTypedData unmarshalls data into TypedData, validates it and hashes it.
//
//export HashTypedData
func HashTypedData(data string) string {
return callWithResponse(hashTypedData, data)
}
func hashTypedData(data string) string {
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)
}
// SignTypedDataV4 unmarshall data into TypedData, validate it and signs with selected account,
// if password matches selected account.
//
//export SignTypedDataV4
func SignTypedDataV4(data, address, password string) string {
return signTypedDataV4(data, address, password)
}
func signTypedDataV4(data, address, password string) string {
var typed apitypes.TypedData
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.
//
//export HashTypedDataV4
func HashTypedDataV4(data string) string {
return callWithResponse(hashTypedDataV4, data)
}
func hashTypedDataV4(data string) string {
var typed apitypes.TypedData
err := json.Unmarshal([]byte(data), &typed)
if err != nil {
return prepareJSONResponseWithCode(nil, err, codeFailedParseParams)
}
result, err := statusBackend.HashTypedDataV4(typed)
return prepareJSONResponse(result.String(), err)
}
func Recover(rpcParams string) string {
return callWithResponse(recoverWithRPCParams, rpcParams)
}
// recoverWithRPCParams unmarshals rpc params {signDataString, signedData} and passes
// them onto backend.
func recoverWithRPCParams(rpcParams string) string {
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)
}
// SendTransactionWithChainID converts RPC args and calls backend.SendTransactionWithChainID.
func SendTransactionWithChainID(chainID int, txArgsJSON, password string) string {
return sendTransactionWithChainID(chainID, txArgsJSON, password)
}
// sendTransactionWithChainID converts RPC args and calls backend.SendTransactionWithChainID.
func sendTransactionWithChainID(chainID int, txArgsJSON, password string) string {
var params wallettypes.SendTxArgs
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)
}
// Deprecated: Use SendTransactionV2 instead.
func SendTransaction(txArgsJSON, password string) string {
return sendTransaction(txArgsJSON, password)
}
// sendTransaction converts RPC args and calls backend.SendTransaction.
// Deprecated: Use sendTransactionV2 instead.
func sendTransaction(txArgsJSON, password string) string {
var params wallettypes.SendTxArgs
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)
}
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)