This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
types.go
65 lines (58 loc) · 2.31 KB
/
types.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
// Copyright (C) 2018 MediBloc
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>
package keystore
import (
"github.com/medibloc/go-medibloc/common"
"github.com/medibloc/go-medibloc/crypto/signature"
"github.com/pborman/uuid"
"github.com/pkg/errors"
)
//
var (
ErrFailedToReadKeystoreFile = errors.New("failed to read keystore file")
ErrInvalidKeystoreVersion = errors.New("cannot parse old version")
ErrFailedToUnmarshalKeystoreJSON = errors.New("failed unmarshal keystore json")
ErrWrongPassphrase = errors.New("wrong passphrase for keystore")
ErrFailedToDecrypt = errors.New("failed to decrypt keystore by passphrase")
)
// CipherJSON json format for crypto field in keystore file
type CipherJSON struct {
Cipher string `json:"cipher"`
CipherText string `json:"ciphertext"`
CipherParams cipherparamsJSON `json:"cipherparams"`
KDF string `json:"kdf"`
KDFParams map[string]interface{} `json:"kdfparams"`
MAC string `json:"mac"`
}
// cipherparamsJSON
type cipherparamsJSON struct {
IV string `json:"iv"`
}
// Key key struct for encryption key argument
type Key struct {
ID uuid.UUID // Version 4 "random" for unique id not derived from key data
// to simplify lookups we also store the address
Address common.Address
// we only store privkey as pubkey/address can be derived from it
// privkey in this struct is always in plaintext
PrivateKey signature.PrivateKey
}
// EncryptedKeyJSONV3 is a struct for encrypted key
type EncryptedKeyJSONV3 struct {
Address string `json:"address"`
Crypto CipherJSON `json:"crypto"`
ID string `json:"id"`
Version int `json:"version"`
}