-
Notifications
You must be signed in to change notification settings - Fork 4
/
crypto.go
40 lines (32 loc) · 937 Bytes
/
crypto.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
package crypto
import (
"crypto/ecdsa"
"crypto/elliptic"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
func Keccak256(data []byte) []byte{
return crypto.Keccak256(data)
}
func Sign(digestHash []byte, priv *ecdsa.PrivateKey) ([]byte, error) {
return crypto.Sign(digestHash, priv)
}
func SigToPub(hash []byte, sig []byte)(*ecdsa.PublicKey, error){
return crypto.SigToPub(hash, sig)
}
func PubkeyToAddress(p ecdsa.PublicKey) common.Address{
return crypto.PubkeyToAddress(p)
}
func S256() elliptic.Curve{
return crypto.S256()
}
func EncryptKey(key *Key, auth string, scryptN int, scryptP int) ([]byte, error){
k := key.Key()
return keystore.EncryptKey(&k, auth, scryptN, scryptP)
}
func DecryptKey(keyjson []byte, auth string) (*Key, error){
key, err := keystore.DecryptKey(keyjson, auth)
tkey := ToKey(*key)
return &tkey, err
}