diff --git a/cmd/commands/tx.go b/cmd/commands/tx.go index 2e12be06ec..0fe0cd731b 100644 --- a/cmd/commands/tx.go +++ b/cmd/commands/tx.go @@ -123,7 +123,7 @@ func sendTxCmd(cmd *cobra.Command, args []string) error { // sign that puppy signBytes := tx.SignBytes(chainIDFlag) - tx.Inputs[0].Signature = crypto.SignatureS{privKey.Sign(signBytes)} + tx.Inputs[0].Signature = crypto.WrapSignature(privKey.Sign(signBytes)) fmt.Println("Signed SendTx:") fmt.Println(string(wire.JSONBytes(tx))) @@ -179,7 +179,7 @@ func AppTx(name string, data []byte) error { Data: data, } - tx.Input.Signature = crypto.SignatureS{privKey.Sign(tx.SignBytes(chainIDFlag))} + tx.Input.Signature = crypto.WrapSignature(privKey.Sign(tx.SignBytes(chainIDFlag))) fmt.Println("Signed AppTx:") fmt.Println(string(wire.JSONBytes(tx))) diff --git a/glide.lock b/glide.lock index 4c67c14d60..6d57797f72 100644 --- a/glide.lock +++ b/glide.lock @@ -70,7 +70,7 @@ imports: - name: github.com/tendermint/go-config version: 620dcbbd7d587cf3599dedbf329b64311b0c307a - name: github.com/tendermint/go-crypto - version: 0ca2c6fdb0706001ca4c4b9b80c9f428e8cf39da + version: 8ff4ce222d32c2328ff0d2bf121fcd34254c03c1 - name: github.com/tendermint/go-data version: e7fcc6d081ec8518912fcdc103188275f83a3ee5 - name: github.com/tendermint/go-db diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index f7c658a9af..6d8168bd7b 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -53,7 +53,7 @@ func TestCounterPlugin(t *testing.T) { signBytes := tx.SignBytes(chainID) // t.Logf("Sign bytes: %X\n", signBytes) sig := test1PrivAcc.Sign(signBytes) - tx.Input.Signature = crypto.SignatureS{sig} + tx.Input.Signature = crypto.WrapSignature(sig) // t.Logf("Signed TX bytes: %X\n", wire.BinaryBytes(struct{ types.Tx }{tx})) // Write request diff --git a/tests/tendermint/main.go b/tests/tendermint/main.go index 73ace4ef88..53416c2357 100644 --- a/tests/tendermint/main.go +++ b/tests/tendermint/main.go @@ -67,7 +67,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := root.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) //fmt.Println("tx:", tx) // Write request @@ -118,7 +118,7 @@ func main() { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) //fmt.Println("tx:", tx) // Write request diff --git a/tests/tmsp/tmsp_test.go b/tests/tmsp/tmsp_test.go index 86b4bfbf24..e78f978b2b 100644 --- a/tests/tmsp/tmsp_test.go +++ b/tests/tmsp/tmsp_test.go @@ -50,7 +50,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.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("Signed TX bytes: %X\n", wire.BinaryBytes(types.TxS{tx})) // Write request @@ -102,7 +102,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := test1PrivAcc.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request @@ -146,7 +146,7 @@ func TestSequence(t *testing.T) { // Sign request signBytes := tx.SignBytes(chainID) sig := privAccountA.Sign(signBytes) - tx.Inputs[0].Signature = crypto.SignatureS{sig} + tx.Inputs[0].Signature = crypto.WrapSignature(sig) // t.Log("ADDR: %X -> %X\n", tx.Inputs[0].Address, tx.Outputs[0].Address) // Write request diff --git a/types/test_helpers.go b/types/test_helpers.go index 81e639ee10..02f96b7814 100644 --- a/types/test_helpers.go +++ b/types/test_helpers.go @@ -12,9 +12,9 @@ import ( func PrivAccountFromSecret(secret string) PrivAccount { privKey := crypto.GenPrivKeyEd25519FromSecret([]byte(secret)) privAccount := PrivAccount{ - PrivKeyS: crypto.PrivKeyS{privKey}, + PrivKeyS: crypto.WrapPrivKey(privKey), Account: Account{ - PubKey: crypto.PubKeyS{privKey.PubKey()}, + PubKey: crypto.WrapPubKey(privKey.PubKey()), }, } return privAccount @@ -31,9 +31,9 @@ func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount { } privKey := crypto.GenPrivKeyEd25519() - pubKey := crypto.PubKeyS{privKey.PubKey()} + pubKey := crypto.WrapPubKey(privKey.PubKey()) privAccs[i] = PrivAccount{ - PrivKeyS: crypto.PrivKeyS{privKey}, + PrivKeyS: crypto.WrapPrivKey(privKey), Account: Account{ PubKey: pubKey, Balance: Coins{Coin{"", balance}}, diff --git a/types/tx.go b/types/tx.go index d4925bbb65..5b0eb84ba5 100644 --- a/types/tx.go +++ b/types/tx.go @@ -104,13 +104,7 @@ func NewTxInput(pubKey crypto.PubKey, coins Coins, sequence int) TxInput { Sequence: sequence, } if sequence == 1 { - // safely wrap if needed - // TODO: extract this as utility function? - ps, ok := pubKey.(crypto.PubKeyS) - if !ok { - ps = crypto.PubKeyS{pubKey} - } - input.PubKey = ps + input.PubKey = crypto.WrapPubKey(pubKey) } return input } @@ -151,25 +145,21 @@ type SendTx struct { func (tx *SendTx) SignBytes(chainID string) []byte { signBytes := wire.BinaryBytes(chainID) sigz := make([]crypto.Signature, len(tx.Inputs)) - for i, input := range tx.Inputs { - sigz[i] = input.Signature.Signature - tx.Inputs[i].Signature.Signature = nil + for i := range tx.Inputs { + sigz[i] = tx.Inputs[i].Signature + tx.Inputs[i].Signature = crypto.Signature{} } signBytes = append(signBytes, wire.BinaryBytes(tx)...) for i := range tx.Inputs { - tx.Inputs[i].Signature.Signature = sigz[i] + tx.Inputs[i].Signature = sigz[i] } return signBytes } func (tx *SendTx) SetSignature(addr []byte, sig crypto.Signature) bool { - sigs, ok := sig.(crypto.SignatureS) - if !ok { - sigs = crypto.SignatureS{sig} - } for i, input := range tx.Inputs { if bytes.Equal(input.Address, addr) { - tx.Inputs[i].Signature = sigs + tx.Inputs[i].Signature = crypto.WrapSignature(sig) return true } } @@ -193,18 +183,14 @@ type AppTx struct { func (tx *AppTx) SignBytes(chainID string) []byte { signBytes := wire.BinaryBytes(chainID) sig := tx.Input.Signature - tx.Input.Signature.Signature = nil + tx.Input.Signature = crypto.WrapSignature(nil) signBytes = append(signBytes, wire.BinaryBytes(tx)...) tx.Input.Signature = sig return signBytes } func (tx *AppTx) SetSignature(sig crypto.Signature) bool { - sigs, ok := sig.(crypto.SignatureS) - if !ok { - sigs = crypto.SignatureS{sig} - } - tx.Input.Signature = sigs + tx.Input.Signature = crypto.WrapSignature(sig) return true } diff --git a/types/tx_test.go b/types/tx_test.go index 71033cc9e7..fb4da2598d 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -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.SignatureS{sig}) + tx2.SetSignature(test1PrivAcc.PubKey.Address(), crypto.WrapSignature(sig)) assert.Equal(tx, tx2) // let's marshal / unmarshal this with signature