2021-12-25 02:16:58 +01:00
|
|
|
package wallet
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
import "orblivion/lbry-id/auth"
|
|
|
|
|
2021-12-25 02:16:58 +01:00
|
|
|
// Currently a small package but given other packages it makes imports easier.
|
|
|
|
// Also this might grow substantially over time
|
|
|
|
|
|
|
|
// For test stubs
|
|
|
|
type WalletUtilInterface interface {
|
2022-06-07 19:25:14 +02:00
|
|
|
ValidateWalletStateMetadata(walletState *WalletStateMetadata) bool
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type WalletUtil struct{}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// This is a subset of the WalletState structure, only the metadata fields. We
|
|
|
|
// don't need access to the encrypted wallet.
|
|
|
|
type WalletStateMetadata struct {
|
|
|
|
DeviceId auth.DeviceId `json:"deviceId"`
|
|
|
|
LastSynced map[auth.DeviceId]int `json:"lastSynced"`
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
type WalletStateHmac string
|
|
|
|
|
2021-12-25 02:16:58 +01:00
|
|
|
// TODO - These "validate" functions could/should be methods. Though I think
|
|
|
|
// we'd lose mockability for testing, since the method isn't the
|
|
|
|
// WalletUtilInterface.
|
|
|
|
// Mainly the job of the clients but we may as well short-circuit problems
|
|
|
|
// here before saving them.
|
2022-06-07 19:25:14 +02:00
|
|
|
func (wu *WalletUtil) ValidateWalletStateMetadata(walletState *WalletStateMetadata) bool {
|
2021-12-25 02:16:58 +01:00
|
|
|
|
|
|
|
// TODO - nonempty fields, up to date, etc
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assumptions: `ws` has been validated
|
|
|
|
// Avoid having to check for error
|
2022-06-07 19:25:14 +02:00
|
|
|
func (ws *WalletStateMetadata) Sequence() int {
|
|
|
|
return ws.LastSynced[ws.DeviceId]
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|