This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup_data.go
135 lines (107 loc) · 2.67 KB
/
backup_data.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
/*
Backup Data
*/
package backuplib
import (
"github.com/iden3/go-backup/shamir"
"github.com/iden3/go-iden3-core/db"
"github.com/iden3/go-iden3-crypto/babyjub"
)
type BackupData struct {
kOp []byte // Key. Assumed it is derived from a password
wallet *WalletConfig // Simulated wallet configuration parameters
secretShares *Shares // Shares. Needed in case we want to continue distributing them
secretCfg *shamir.Shamir // Configuration osf secret sharing
secretCustodians *Custodians // Info on custodians so that we can retrieve it later
pK *PrivateKeys // Identity private keys
storage []db.KV // Identity storage
}
var dataBackup BackupData
// Getters/Setters
func GetkOp() []byte {
return dataBackup.kOp
}
func SetkOp(kOp []byte) {
dataBackup.kOp = make([]byte, len(kOp))
copy(dataBackup.kOp, kOp)
}
func GetWallet() *WalletConfig {
return dataBackup.wallet
}
func SetWallet(data *WalletConfig) {
dataBackup.wallet = data
}
func GetShares() *Shares {
return dataBackup.secretShares
}
func SetShares(data *Shares) {
dataBackup.secretShares = data
}
func GetSecretCfg() *Secret {
secretCfg := Secret{
shamir.Shamir{
MaxShares: dataBackup.secretCfg.GetMaxShares(),
MinShares: dataBackup.secretCfg.GetMinShares(),
ElementType: dataBackup.secretCfg.GetElType(),
},
}
return &secretCfg
}
func GetSecretCfgOriginal() *shamir.Shamir {
return dataBackup.secretCfg
}
func SetSecretCfg(data *Secret) {
if data != nil {
secretCfg := shamir.Shamir{
MaxShares: data.GetMaxShares(),
MinShares: data.GetMinShares(),
ElementType: data.GetElType(),
}
dataBackup.secretCfg = &secretCfg
} else {
dataBackup.secretCfg = nil
}
}
func GetCustodians() *Custodians {
return dataBackup.secretCustodians
}
func SetCustodians(data *Custodians) {
dataBackup.secretCustodians = data
}
func GetPrivateKeys() *PrivateKeys {
return dataBackup.pK
}
func SetPrivateKeys(data *PrivateKeys) {
if data == nil {
dataBackup.pK = nil
} else {
PK := make([]babyjub.PrivateKey, len(data.PK))
for idx, pk := range data.PK {
PK[idx] = pk
}
privateKey := PrivateKeys{PK: PK}
dataBackup.pK = &privateKey
}
}
func GetStorage() []db.KV {
return dataBackup.storage
}
func SetStorage(data []db.KV) {
copy(dataBackup.storage, data)
}
func Init(pass []byte, folder string) {
// init aux data in backup structure
SetWallet(initWalletConfig())
// init Secret Sharing
initSecretCfg()
// init Secret Shares
initSecretShares()
// init backup registry
initBackup()
// init Encoding
initEncoding()
// init Custodians
initCustodians()
// init identity
initIdentity(pass, folder)
}