/
crypto.go
46 lines (37 loc) · 1.14 KB
/
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
41
42
43
44
45
46
package mockhookcrypto
import (
"fmt"
"crypto/sha256"
"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/sha3"
)
// KryptoHookMock is a krypto hook implementation that we use for VM tests
type KryptoHookMock int
// KryptoHookMockInstance is a krypto hook mock singleton
const KryptoHookMockInstance KryptoHookMock = 0
// Sha256 cryptographic function
func (KryptoHookMock) Sha256(data []byte) ([]byte, error) {
hash := sha256.New()
hash.Write(data)
result := hash.Sum(nil)
return result, nil
}
// Keccak256 cryptographic function
func (KryptoHookMock) Keccak256(data []byte) ([]byte, error) {
hash := sha3.NewLegacyKeccak256()
hash.Write(data)
result := hash.Sum(nil)
return result, nil
}
// Ripemd160 cryptographic function
func (KryptoHookMock) Ripemd160(data []byte) ([]byte, error) {
hash := ripemd160.New()
hash.Write(data)
result := hash.Sum(nil)
return result, nil
}
// Ecrecover calculates the corresponding Ethereum address for the public key which created the given signature
func (KryptoHookMock) Ecrecover(hash []byte, recoveryID []byte, r []byte, s []byte) ([]byte, error) {
fmt.Println(">>>>> Ecrecover")
return []byte{}, nil
}