-
Notifications
You must be signed in to change notification settings - Fork 5
/
address.go
76 lines (60 loc) · 1.29 KB
/
address.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
package ozcoin
import (
"encoding/json"
"math/big"
)
type WalletPublicKey struct {
TPK ECCPoint `json:"pk_track"`
PPK ECCPoint `json:"pk_priv"`
}
type WalletTrackingKey struct {
WalletPublicKey
TSK *big.Int `json:"sk_track"`
}
type WalletPrivateKey struct {
WalletTrackingKey
PSK *big.Int `json:"sk_priv"`
}
func (track WalletTrackingKey) PublicKey() WalletPublicKey {
return track.WalletPublicKey
}
func (priv WalletPrivateKey) PublicKey() WalletPublicKey {
return priv.WalletPublicKey
}
func (priv WalletPrivateKey) TrackingKey() WalletTrackingKey {
return priv.WalletTrackingKey
}
func NewPrivateKey() *WalletPrivateKey {
tsk := RandomInt()
psk := RandomInt()
tskx, tsky := CURVE.Params().ScalarBaseMult(tsk.Bytes())
pskx, psky := CURVE.Params().ScalarBaseMult(psk.Bytes())
w := &WalletPrivateKey{
WalletTrackingKey: WalletTrackingKey{
WalletPublicKey: WalletPublicKey{
TPK: ECCPoint{tskx, tsky},
PPK: ECCPoint{pskx, psky},
},
TSK: tsk,
},
PSK: psk,
}
return w
}
func (w *WalletPublicKey) Json() []byte {
b, err := json.Marshal(w)
if err != nil {
panic(err)
}
return b
}
func (w *WalletPrivateKey) Json() []byte {
b, err := json.Marshal(w)
if err != nil {
panic(err)
}
return b
}
func (w *WalletPublicKey) Hash() SHA256Sum {
return Hash(w.Json())
}