aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-16 18:27:38 +0800
committerobscuren <geffobscura@gmail.com>2015-03-16 18:27:38 +0800
commitb5234413611ce5984292f85a01de1f56c045b490 (patch)
treee6e0c6f7fe8358a2dc63cdea11ac66b4f59397f5 /crypto
parent0b8f66ed9ef177dc72442dd7ba337c6733e30344 (diff)
downloaddexon-b5234413611ce5984292f85a01de1f56c045b490.tar.gz
dexon-b5234413611ce5984292f85a01de1f56c045b490.tar.zst
dexon-b5234413611ce5984292f85a01de1f56c045b490.zip
Moved ethutil => common
Diffstat (limited to 'crypto')
-rw-r--r--crypto/crypto.go10
-rw-r--r--crypto/crypto_test.go4
-rw-r--r--crypto/encrypt_decrypt_test.go8
-rw-r--r--crypto/key_store_test.go10
-rw-r--r--crypto/keypair.go10
5 files changed, 21 insertions, 21 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 90e2c8939..bc72928ac 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -19,7 +19,7 @@ import (
"github.com/ethereum/go-ethereum/crypto/ecies"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/crypto/sha3"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/ripemd160"
)
@@ -39,7 +39,7 @@ func Sha3(data ...[]byte) []byte {
// Creates an ethereum address given the bytes and the nonce
func CreateAddress(b []byte, nonce uint64) []byte {
- return Sha3(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:]
+ return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:]
}
func Sha256(data []byte) []byte {
@@ -74,7 +74,7 @@ func ToECDSA(prv []byte) *ecdsa.PrivateKey {
priv := new(ecdsa.PrivateKey)
priv.PublicKey.Curve = S256()
- priv.D = ethutil.BigD(prv)
+ priv.D = common.BigD(prv)
priv.PublicKey.X, priv.PublicKey.Y = S256().ScalarBaseMult(prv)
return priv
}
@@ -143,7 +143,7 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
}
- sig, err = secp256k1.Sign(hash, ethutil.LeftPadBytes(prv.D.Bytes(), prv.Params().BitSize/8))
+ sig, err = secp256k1.Sign(hash, common.LeftPadBytes(prv.D.Bytes(), prv.Params().BitSize/8))
return
}
@@ -198,7 +198,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
Address: PubkeyToAddress(ecKey.PublicKey),
PrivateKey: ecKey,
}
- derivedAddr := ethutil.Bytes2Hex(key.Address)
+ derivedAddr := common.Bytes2Hex(key.Address)
expectedAddr := preSaleKeyStruct.EthAddr
if derivedAddr != expectedAddr {
err = errors.New("decrypted addr not equal to expected addr")
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go
index c68856622..754287641 100644
--- a/crypto/crypto_test.go
+++ b/crypto/crypto_test.go
@@ -8,7 +8,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
// These tests are sanity checks.
@@ -53,7 +53,7 @@ func BenchmarkSha3(b *testing.B) {
func Test0Key(t *testing.T) {
t.Skip()
- key := ethutil.Hex2Bytes("1111111111111111111111111111111111111111111111111111111111111111")
+ key := common.Hex2Bytes("1111111111111111111111111111111111111111111111111111111111111111")
p, err := secp256k1.GeneratePubKey(key)
addr := Sha3(p[1:])[12:]
diff --git a/crypto/encrypt_decrypt_test.go b/crypto/encrypt_decrypt_test.go
index 85b43c406..6e5b40a37 100644
--- a/crypto/encrypt_decrypt_test.go
+++ b/crypto/encrypt_decrypt_test.go
@@ -5,13 +5,13 @@ import (
"fmt"
"testing"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
func TestBox(t *testing.T) {
- prv1 := ToECDSA(ethutil.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
- prv2 := ToECDSA(ethutil.Hex2Bytes("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"))
- pub2 := ToECDSAPub(ethutil.Hex2Bytes("04bd27a63c91fe3233c5777e6d3d7b39204d398c8f92655947eb5a373d46e1688f022a1632d264725cbc7dc43ee1cfebde42fa0a86d08b55d2acfbb5e9b3b48dc5"))
+ prv1 := ToECDSA(common.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
+ prv2 := ToECDSA(common.Hex2Bytes("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"))
+ pub2 := ToECDSAPub(common.Hex2Bytes("04bd27a63c91fe3233c5777e6d3d7b39204d398c8f92655947eb5a373d46e1688f022a1632d264725cbc7dc43ee1cfebde42fa0a86d08b55d2acfbb5e9b3b48dc5"))
message := []byte("Hello, world.")
ct, err := Encrypt(pub2, message)
diff --git a/crypto/key_store_test.go b/crypto/key_store_test.go
index 11531d460..f0a1e567b 100644
--- a/crypto/key_store_test.go
+++ b/crypto/key_store_test.go
@@ -2,13 +2,13 @@ package crypto
import (
"github.com/ethereum/go-ethereum/crypto/randentropy"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
"reflect"
"testing"
)
func TestKeyStorePlain(t *testing.T) {
- ks := NewKeyStorePlain(ethutil.DefaultDataDir())
+ ks := NewKeyStorePlain(common.DefaultDataDir())
pass := "" // not used but required by API
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
if err != nil {
@@ -36,7 +36,7 @@ func TestKeyStorePlain(t *testing.T) {
}
func TestKeyStorePassphrase(t *testing.T) {
- ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
+ ks := NewKeyStorePassphrase(common.DefaultDataDir())
pass := "foo"
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
if err != nil {
@@ -62,7 +62,7 @@ func TestKeyStorePassphrase(t *testing.T) {
}
func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
- ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
+ ks := NewKeyStorePassphrase(common.DefaultDataDir())
pass := "foo"
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
if err != nil {
@@ -90,7 +90,7 @@ func TestImportPreSaleKey(t *testing.T) {
// python pyethsaletool.py genwallet
// with password "foo"
fileContent := "{\"encseed\": \"26d87f5f2bf9835f9a47eefae571bc09f9107bb13d54ff12a4ec095d01f83897494cf34f7bed2ed34126ecba9db7b62de56c9d7cd136520a0427bfb11b8954ba7ac39b90d4650d3448e31185affcd74226a68f1e94b1108e6e0a4a91cdd83eba\", \"ethaddr\": \"d4584b5f6229b7be90727b0fc8c6b91bb427821f\", \"email\": \"gustav.simonsson@gmail.com\", \"btcaddr\": \"1EVknXyFC68kKNLkh6YnKzW41svSRoaAcx\"}"
- ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
+ ks := NewKeyStorePassphrase(common.DefaultDataDir())
pass := "foo"
_, err := ImportPreSaleKey(ks, []byte(fileContent), pass)
if err != nil {
diff --git a/crypto/keypair.go b/crypto/keypair.go
index da5788437..6702e6595 100644
--- a/crypto/keypair.go
+++ b/crypto/keypair.go
@@ -4,7 +4,7 @@ import (
"strings"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
type KeyPair struct {
@@ -40,19 +40,19 @@ func (k *KeyPair) Address() []byte {
func (k *KeyPair) Mnemonic() string {
if k.mnemonic == "" {
- k.mnemonic = strings.Join(MnemonicEncode(ethutil.Bytes2Hex(k.PrivateKey)), " ")
+ k.mnemonic = strings.Join(MnemonicEncode(common.Bytes2Hex(k.PrivateKey)), " ")
}
return k.mnemonic
}
func (k *KeyPair) AsStrings() (string, string, string, string) {
- return k.Mnemonic(), ethutil.Bytes2Hex(k.Address()), ethutil.Bytes2Hex(k.PrivateKey), ethutil.Bytes2Hex(k.PublicKey)
+ return k.Mnemonic(), common.Bytes2Hex(k.Address()), common.Bytes2Hex(k.PrivateKey), common.Bytes2Hex(k.PublicKey)
}
func (k *KeyPair) RlpEncode() []byte {
return k.RlpValue().Encode()
}
-func (k *KeyPair) RlpValue() *ethutil.Value {
- return ethutil.NewValue(k.PrivateKey)
+func (k *KeyPair) RlpValue() *common.Value {
+ return common.NewValue(k.PrivateKey)
}