-
Notifications
You must be signed in to change notification settings - Fork 241
/
identity.go
62 lines (52 loc) · 1.21 KB
/
identity.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
package images
import (
"encoding/json"
"errors"
"github.com/status-im/status-go/eth-node/crypto"
)
type IdentityImage struct {
KeyUID string
Name string
Payload []byte
Width int
Height int
FileSize int
ResizeTarget int
}
func (i IdentityImage) GetType() (ImageType, error) {
it := GetType(i.Payload)
if it == UNKNOWN {
return it, errors.New("unsupported file type")
}
return it, nil
}
func (i IdentityImage) Hash() []byte {
return crypto.Keccak256(i.Payload)
}
func (i IdentityImage) GetDataURI() (string, error) {
return GetPayloadDataURI(i.Payload)
}
func (i IdentityImage) MarshalJSON() ([]byte, error) {
uri, err := i.GetDataURI()
if err != nil {
return nil, err
}
temp := struct {
KeyUID string `json:"keyUid"`
Name string `json:"type"`
URI string `json:"uri"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"fileSize"`
ResizeTarget int `json:"resizeTarget"`
}{
KeyUID: i.KeyUID,
Name: i.Name,
URI: uri,
Width: i.Width,
Height: i.Height,
FileSize: i.FileSize,
ResizeTarget: i.ResizeTarget,
}
return json.Marshal(temp)
}