OSDN Git Service

Merge pull request #935 from Bytom/dev
[bytom/bytom.git] / crypto / crypto.go
index 8c328d9..cd33037 100644 (file)
 package crypto
 
 import (
-       "fmt"
-       //"io"
-       //"io/ioutil"
-       //"math/big"
-       //"os"
-
-       //"encoding/hex"
-       //"errors"
-
-       "bytom/common"
-       "golang.org/x/crypto/sha3"
+       "github.com/bytom/common"
        "golang.org/x/crypto/ripemd160"
+       "golang.org/x/crypto/sha3"
 )
 
-
 func Sha256(data ...[]byte) []byte {
        d := sha3.New256()
        for _, b := range data {
@@ -52,43 +42,9 @@ func Sha256Hash(data ...[]byte) (h common.Hash) {
 func Sha3(data ...[]byte) []byte          { return Sha256(data...) }
 func Sha3Hash(data ...[]byte) common.Hash { return Sha256Hash(data...) }
 
-
 func Ripemd160(data []byte) []byte {
        ripemd := ripemd160.New()
        ripemd.Write(data)
 
        return ripemd.Sum(nil)
 }
-
-func PubkeyToAddress(pubBytes []byte) common.Address{
-       address, _ := common.AddressEncode("bm", 1, toInt(Ripemd160(Sha3(pubBytes))))
-       fmt.Printf(address)
-       return common.StringToAddress(address)
-}
-
-func AddressToPubkey(addr common.Address) (int, []byte, error) {
-       ver, data, err := common.AddressDecode("bm", addr.Str())
-       return ver, toBytes(data), err
-}
-
-func zeroBytes(bytes []byte) {
-       for i := range bytes {
-               bytes[i] = 0
-       }
-}
-
-func toInt(bytes []byte) []int{
-       ints := make([]int, len(bytes))
-       for i := range bytes {
-               ints[i] = int(bytes[i])
-       }
-       return ints
-}
-
-func toBytes(ints []int) []byte{
-       bytes := make([]byte, len(ints))
-       for i := range ints {
-               bytes[i] = byte(ints[i])
-       }
-       return bytes
-}