Browse Source

backwards compatible addresses

pull/113/head
Ethan Buchman 9 years ago
parent
commit
7865cd3533
2 changed files with 22 additions and 7 deletions
  1. +17
    -2
      account/pub_key.go
  2. +5
    -5
      config/tendermint_test/config.go

+ 17
- 2
account/pub_key.go View File

@ -5,6 +5,7 @@ import (
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519"
"github.com/tendermint/tendermint/Godeps/_workspace/src/github.com/tendermint/ed25519/extra25519"
"github.com/tendermint/tendermint/Godeps/_workspace/src/golang.org/x/crypto/ripemd160"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
)
@ -31,8 +32,22 @@ var _ = binary.RegisterInterface(
// Implements PubKey
type PubKeyEd25519 [32]byte
// TODO: Or should this just be BinaryRipemd160(key)? (The difference is the TypeByte.)
func (pubKey PubKeyEd25519) Address() []byte { return binary.BinaryRipemd160(pubKey[:]) }
// TODO: Slicing the array gives us length prefixing but loses the type byte.
// Revisit if we add more pubkey types.
// For now, we artificially append the type byte in front to give us backwards
// compatibility for when the pubkey wasn't fixed length array
func (pubKey PubKeyEd25519) Address() []byte {
w, n, err := new(bytes.Buffer), new(int64), new(error)
binary.WriteBinary(pubKey[:], w, n, err)
if *err != nil {
panic(*err)
}
// append type byte
encodedPubkey := append([]byte{1}, w.Bytes()...)
hasher := ripemd160.New()
hasher.Write(encodedPubkey) // does not error
return hasher.Sum(nil)
}
// TODO: Consider returning a reason for failure, or logging a runtime type mismatch.
func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool {


+ 5
- 5
config/tendermint_test/config.go View File

@ -110,23 +110,23 @@ var defaultGenesis = `{
"chain_id" : "tendermint_test",
"accounts": [
{
"address": "C3C1AF26C0CB2C1DB233D8936AD2C6335AAB6844",
"address": "E9B5D87313356465FAE33C406CE2C2979DE60BCB",
"amount": 200000000
},
{
"address": "C76F0E490A003FDB4A94B310C354F1650A6F97B7",
"address": "DFE4AFFA4CEE17CD01CB9E061D77C3ECED29BD88",
"amount": 200000000
},
{
"address": "576C84059355CD3B8CBDD81C3FCBC5CE5B6632E0",
"address": "F60D30722E7B497FA532FB3207C3FB29C31B1992",
"amount": 200000000
},
{
"address": "CD9AB051EDEA88E61ABDF2A1ACF10C3803F0972F",
"address": "336CB40A5EB92E496E19B74FDFF2BA017C877FD6",
"amount": 200000000
},
{
"address": "4EE2D93B0A1FBA4E9EBE20E088AA122002A2EB0C",
"address": "D218F0F439BF0384F6F5EF8D0F8B398D941BD1DC",
"amount": 200000000
}
],


Loading…
Cancel
Save