aboutsummaryrefslogtreecommitdiffstats
path: root/ethcrypto/keypair.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-06-30 03:28:04 +0800
committerzelig <viktor.tron@gmail.com>2014-06-30 03:28:04 +0800
commit25314313f8eefd5ae8d13b4c687e4811703eec2a (patch)
tree91c91eafb80f315cc77a689d1b6d4a07aed4735e /ethcrypto/keypair.go
parenta8be0d9f4849d8127d2ba36b90327097f94a91cb (diff)
downloaddexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar.gz
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar.bz2
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar.lz
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar.xz
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.tar.zst
dexon-25314313f8eefd5ae8d13b4c687e4811703eec2a.zip
added Mnemonic() and AsStrings() methods, added memoization for address
Diffstat (limited to 'ethcrypto/keypair.go')
-rw-r--r--ethcrypto/keypair.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/ethcrypto/keypair.go b/ethcrypto/keypair.go
index ae9db3698..18fa5b788 100644
--- a/ethcrypto/keypair.go
+++ b/ethcrypto/keypair.go
@@ -3,12 +3,14 @@ package ethcrypto
import (
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/secp256k1-go"
+ "strings"
)
type KeyPair struct {
PrivateKey []byte
PublicKey []byte
-
+ address []byte
+ mnemonic string
// The associated account
// account *StateObject
}
@@ -29,7 +31,21 @@ func NewKeyPairFromSec(seckey []byte) (*KeyPair, error) {
}
func (k *KeyPair) Address() []byte {
- return Sha3Bin(k.PublicKey[1:])[12:]
+ if k.address == nil {
+ k.address = Sha3Bin(k.PublicKey[1:])[12:]
+ }
+ return k.address
+}
+
+func (k *KeyPair) Mnemonic() string {
+ if k.mnemonic == "" {
+ k.mnemonic = strings.Join(MnemonicEncode(ethutil.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)
}
func (k *KeyPair) RlpEncode() []byte {