Update to latest go-crypto, adjust code and tests

This commit is contained in:
Ethan Frey 2017-04-10 16:32:30 +02:00
parent 787cf0ebac
commit b6ebf9f8b8
11 changed files with 39 additions and 49 deletions

View File

@ -62,9 +62,9 @@ func (a *Address) UnmarshalJSON(addrHex []byte) error {
}
type Key struct {
Address Address `json:"address"`
PubKey crypto.PubKeyS `json:"pub_key"`
PrivKey crypto.PrivKeyS `json:"priv_key"`
Address Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
PrivKey crypto.PrivKey `json:"priv_key"`
}
// Implements Signer

View File

@ -8,7 +8,6 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/basecoin/types"
crypto "github.com/tendermint/go-crypto"
client "github.com/tendermint/go-rpc/client"
wire "github.com/tendermint/go-wire"
@ -123,7 +122,7 @@ func sendTxCmd(cmd *cobra.Command, args []string) error {
// sign that puppy
signBytes := tx.SignBytes(chainIDFlag)
tx.Inputs[0].Signature = crypto.WrapSignature(privKey.Sign(signBytes))
tx.Inputs[0].Signature = privKey.Sign(signBytes)
fmt.Println("Signed SendTx:")
fmt.Println(string(wire.JSONBytes(tx)))
@ -179,7 +178,7 @@ func AppTx(name string, data []byte) error {
Data: data,
}
tx.Input.Signature = crypto.WrapSignature(privKey.Sign(tx.SignBytes(chainIDFlag)))
tx.Input.Signature = privKey.Sign(tx.SignBytes(chainIDFlag))
fmt.Println("Signed AppTx:")
fmt.Println(string(wire.JSONBytes(tx)))

37
glide.lock generated
View File

@ -1,18 +1,18 @@
hash: c6e5febc35b5fd1003066820defb8a089db048b407239dad9faf44553fdc15e8
updated: 2017-04-21T12:55:42.7004558-04:00
hash: e7876b7cb70f79356bf2809547a78b1074b9f6f032e0ba861a65f8e7a6625832
updated: 2017-04-10T20:27:50.460915186+02:00
imports:
- name: github.com/btcsuite/btcd
version: 4b348c1d33373d672edd83fc576892d0e46686d2
subpackages:
- btcec
- name: github.com/BurntSushi/toml
version: b26d9c308763d68093482582cea63d69be07a0f0
version: 99064174e013895bbd9b025c31100bd1d9b590ca
- name: github.com/ebuchman/fail-test
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
- name: github.com/go-stack/stack
version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82
- name: github.com/golang/protobuf
version: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef
version: 69b215d01a5606c843240eab4937eab3acee6530
subpackages:
- proto
- ptypes/any
@ -25,15 +25,11 @@ imports:
- name: github.com/jmhodges/levigo
version: c42d9e0ca023e2198120196f842701bb4c55d7b9
- name: github.com/mattn/go-colorable
version: ded68f7a9561c023e790de24279db7ebf473ea80
version: acb9493f2794fd0f820de7a27a217dafbb1b65ea
- name: github.com/mattn/go-isatty
version: fc9e8d8ef48496124e79ae0df75490096eccf6fe
version: 9622e0cc9d8f9be434ca605520ff9a16808fee47
- name: github.com/pkg/errors
version: ff09b135c25aae272398c51a07235b90a75aa4f0
- name: github.com/spf13/cobra
version: 10f6b9d7e1631a54ad07c5c0fb71c28a1abfd3c2
- name: github.com/spf13/pflag
version: 2300d0f8576fe575f71aaa5b9bbe4e1b0dc2eb51
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/syndtr/goleveldb
version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4
subpackages:
@ -66,13 +62,13 @@ imports:
- name: github.com/tendermint/go-clist
version: 3baa390bbaf7634251c42ad69a8682e7e3990552
- name: github.com/tendermint/go-common
version: f9e3db037330c8a8d61d3966de8473eaf01154fa
version: 6af2364fa91ef2f3afc8ba0db33b66d9d3ae006c
- name: github.com/tendermint/go-config
version: 620dcbbd7d587cf3599dedbf329b64311b0c307a
- name: github.com/tendermint/go-crypto
version: 3e1dba7ab762bb689123eec30c468967f077a6a4
version: c410fc5e246e9accf95c6e80cb3c6aca2280755c
- name: github.com/tendermint/go-data
version: 9fbf0684fefc4fad580992394a0bcf47c1b3d77e
version: e7fcc6d081ec8518912fcdc103188275f83a3ee5
- name: github.com/tendermint/go-db
version: 9643f60bc2578693844aacf380a7c32e4c029fee
- name: github.com/tendermint/go-events
@ -86,7 +82,7 @@ imports:
- name: github.com/tendermint/go-merkle
version: 714d4d04557fd068a7c2a1748241ce8428015a96
- name: github.com/tendermint/go-p2p
version: a163fddbdd2541793d22402afb113e6ccb391774
version: b5f314ffed65c81bd019ba1dd2bae0e95f3937f3
subpackages:
- upnp
- name: github.com/tendermint/go-rpc
@ -107,7 +103,7 @@ imports:
- app
- client
- name: github.com/tendermint/tendermint
version: 936e66867aecf92595b1f8615361b2867d9a69e6
version: c49b331ba8315725d213712ed0410b5c9eb5ba0f
subpackages:
- blockchain
- cmd/tendermint/commands
@ -126,7 +122,7 @@ imports:
- types
- version
- name: golang.org/x/crypto
version: 96846453c37f0876340a66a47f3f75b1f3a6cd2d
version: 40541ccb1c6e64c947ed6f606b8a6cb4b67d7436
subpackages:
- curve25519
- nacl/box
@ -137,7 +133,7 @@ imports:
- ripemd160
- salsa20/salsa
- name: golang.org/x/net
version: c8c74377599bd978aee1cf3b9b63a8634051cec2
version: d379faa25cbdc04d653984913a2ceb43b0bc46d7
subpackages:
- context
- http2
@ -147,7 +143,7 @@ imports:
- lex/httplex
- trace
- name: golang.org/x/sys
version: ea9bcade75cb975a0b9738936568ab388b845617
version: e48874b42435b4347fc52bdee0424a52abc974d7
subpackages:
- unix
- name: golang.org/x/text
@ -162,13 +158,12 @@ imports:
subpackages:
- googleapis/rpc/status
- name: google.golang.org/grpc
version: 6914ab1e338c92da4218a23d27fcd03d0ad78d46
version: 7b399ed358736bc5522021cdc7d79a8ee9ac6f98
subpackages:
- codes
- credentials
- grpclog
- internal
- keepalive
- metadata
- naming
- peer

View File

@ -17,7 +17,7 @@ import:
- package: github.com/tendermint/merkleeyes
version: develop
- package: github.com/tendermint/tendermint
version: develop
version: unstable
- package: github.com/tendermint/abci
version: develop
- package: github.com/gorilla/websocket

View File

@ -9,7 +9,6 @@ import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/basecoin/app"
"github.com/tendermint/basecoin/types"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
eyescli "github.com/tendermint/merkleeyes/client"
)
@ -52,8 +51,7 @@ func TestCounterPlugin(t *testing.T) {
// Sign request
signBytes := tx.SignBytes(chainID)
// t.Logf("Sign bytes: %X\n", signBytes)
sig := test1PrivAcc.Sign(signBytes)
tx.Input.Signature = crypto.WrapSignature(sig)
tx.Input.Signature = test1PrivAcc.Sign(signBytes)
// t.Logf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx}))
// Write request

View File

@ -270,7 +270,7 @@ func TestIBCPluginBadCommit(t *testing.T) {
// Modify the first byte of the first signature
sig := commit.Precommits[0].Signature.Unwrap().(crypto.SignatureEd25519)
sig[0] += 1
commit.Precommits[0].Signature = crypto.WrapSignature(sig)
commit.Precommits[0].Signature = sig.Wrap()
res = ibcPlugin.RunTx(store, ctx, wire.BinaryBytes(struct{ IBCTx }{IBCUpdateChainTx{
Header: header,
Commit: commit,

View File

@ -7,8 +7,7 @@ import (
"github.com/gorilla/websocket"
"github.com/tendermint/basecoin/types"
cmn "github.com/tendermint/go-common"
crypto "github.com/tendermint/go-crypto"
rpcclient "github.com/tendermint/go-rpc/client"
"github.com/tendermint/go-rpc/client"
"github.com/tendermint/go-rpc/types"
wire "github.com/tendermint/go-wire"
_ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types
@ -67,7 +66,7 @@ func main() {
// Sign request
signBytes := tx.SignBytes(chainID)
sig := root.Sign(signBytes)
tx.Inputs[0].Signature = crypto.WrapSignature(sig)
tx.Inputs[0].Signature = sig
//fmt.Println("tx:", tx)
// Write request
@ -118,7 +117,7 @@ func main() {
// Sign request
signBytes := tx.SignBytes(chainID)
sig := privAccountA.Sign(signBytes)
tx.Inputs[0].Signature = crypto.WrapSignature(sig)
tx.Inputs[0].Signature = sig
//fmt.Println("tx:", tx)
// Write request

View File

@ -9,7 +9,6 @@ import (
"github.com/tendermint/basecoin/app"
"github.com/tendermint/basecoin/types"
cmn "github.com/tendermint/go-common"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
eyescli "github.com/tendermint/merkleeyes/client"
)
@ -50,7 +49,7 @@ func TestSendTx(t *testing.T) {
signBytes := tx.SignBytes(chainID)
// t.Log("Sign bytes: %X\n", signBytes)
sig := test1PrivAcc.Sign(signBytes)
tx.Inputs[0].Signature = crypto.WrapSignature(sig)
tx.Inputs[0].Signature = sig
// t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(types.TxS{tx}))
// Write request
@ -102,7 +101,7 @@ func TestSequence(t *testing.T) {
// Sign request
signBytes := tx.SignBytes(chainID)
sig := test1PrivAcc.Sign(signBytes)
tx.Inputs[0].Signature = crypto.WrapSignature(sig)
tx.Inputs[0].Signature = sig
// t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address)
// Write request
@ -146,7 +145,7 @@ func TestSequence(t *testing.T) {
// Sign request
signBytes := tx.SignBytes(chainID)
sig := privAccountA.Sign(signBytes)
tx.Inputs[0].Signature = crypto.WrapSignature(sig)
tx.Inputs[0].Signature = sig
// t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address)
// Write request

View File

@ -10,8 +10,8 @@ import (
// Creates a PrivAccount from secret.
// The amount is not set.
func PrivAccountFromSecret(secret string) PrivAccount {
privKey := crypto.WrapPrivKey(
crypto.GenPrivKeyEd25519FromSecret([]byte(secret)))
privKey :=
crypto.GenPrivKeyEd25519FromSecret([]byte(secret)).Wrap()
privAccount := PrivAccount{
PrivKey: privKey,
Account: Account{
@ -31,7 +31,7 @@ func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount {
balance += cmn.RandInt64() % (maxAmount - minAmount)
}
privKey := crypto.WrapPrivKey(crypto.GenPrivKeyEd25519())
privKey := crypto.GenPrivKeyEd25519().Wrap()
pubKey := privKey.PubKey()
privAccs[i] = PrivAccount{
PrivKey: privKey,

View File

@ -104,7 +104,7 @@ func NewTxInput(pubKey crypto.PubKey, coins Coins, sequence int) TxInput {
Sequence: sequence,
}
if sequence == 1 {
input.PubKey = crypto.WrapPubKey(pubKey)
input.PubKey = pubKey
}
return input
}
@ -159,7 +159,7 @@ func (tx *SendTx) SignBytes(chainID string) []byte {
func (tx *SendTx) SetSignature(addr []byte, sig crypto.Signature) bool {
for i, input := range tx.Inputs {
if bytes.Equal(input.Address, addr) {
tx.Inputs[i].Signature = crypto.WrapSignature(sig)
tx.Inputs[i].Signature = sig
return true
}
}
@ -183,14 +183,14 @@ type AppTx struct {
func (tx *AppTx) SignBytes(chainID string) []byte {
signBytes := wire.BinaryBytes(chainID)
sig := tx.Input.Signature
tx.Input.Signature = crypto.WrapSignature(nil)
tx.Input.Signature = crypto.Signature{}
signBytes = append(signBytes, wire.BinaryBytes(tx)...)
tx.Input.Signature = sig
return signBytes
}
func (tx *AppTx) SetSignature(sig crypto.Signature) bool {
tx.Input.Signature = crypto.WrapSignature(sig)
tx.Input.Signature = sig
return true
}

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/go-common"
data "github.com/tendermint/go-data"
)
@ -109,7 +109,7 @@ func TestSendTxJSON(t *testing.T) {
sig := test1PrivAcc.Sign(signBytes)
// we handle both raw sig and wrapped sig the same
tx.SetSignature(test1PrivAcc.PubKey.Address(), sig)
tx2.SetSignature(test1PrivAcc.PubKey.Address(), crypto.WrapSignature(sig))
tx2.SetSignature(test1PrivAcc.PubKey.Address(), sig)
assert.Equal(tx, tx2)
// let's marshal / unmarshal this with signature