Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get an error signature. #10

Open
JacksonRGB opened this issue Oct 27, 2020 · 0 comments
Open

Get an error signature. #10

JacksonRGB opened this issue Oct 27, 2020 · 0 comments

Comments

@JacksonRGB
Copy link

My signature from zecutil and zcash-cli signature results are different.

./zcash-cli -conf=/blockchain/pkg/zcash/zcash.conf  createrawtransaction '[{"txid": "643020d7a70b7660b3b77550be9a4a8a54f8d088b5e3d5a887ade41848117829", "vout": 1}]' '{"tmF3uG6NKJXTvLFkXETx7NVxKwKWSBvPf21": "0.095"}'
0400008085202f89012978114818e4ad87a8d5e3b588d0f8548a4a9abe5075b7b360760ba7d72030640100000000ffffffff0160f59000000000001976a9143a8b2f8d711643f5bff63945ef44c2973bab10ce88ac000000002c6811000000000000000000000000

 ./zcash-cli -conf=/blockchain/pkg/zcash/zcash.conf signrawtransaction 0400008085202f89012978114818e4ad87a8d5e3b588d0f8548a4a9abe5075b7b360760ba7d72030640100000000ffffffff0160f59000000000001976a9143a8b2f8d711643f5bff63945ef44c2973bab10ce88ac000000002c6811000000000000000000000000
{
  "hex": "0400008085202f89012978114818e4ad87a8d5e3b588d0f8548a4a9abe5075b7b360760ba7d7203064010000006b483045022100f6b037872ad833c951869e63291364d2fed4e1de8dcc8157cfefebc86bfa34c202207a7fd5c72243eff854538f9aea3ed063f78ce3876048330a9f68353a3272cb07012102d46a5c8b2aa894c9efc9f7eb92efd1c150ecad55f892d5de61675d44968dcc8cffffffff0160f59000000000001976a9143a8b2f8d711643f5bff63945ef44c2973bab10ce88ac000000002c6811000000000000000000000000",
  "complete": true
}

./zcash-cli -conf=/blockchain/pkg/zcash/zcash.conf  dumpprivkey tmCaNubpa6dFm5TJraf5u8dTbG6C4HpZp9R
cRy5WaeUyHx81JHpgJY7UdWaih43Demn9P2RGEoBNF8wfKvwuUgM
package main

import (
	"bytes"
	"encoding/hex"
	"fmt"

	"github.com/btcsuite/btcd/btcec"
	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcd/chaincfg/chainhash"
	"github.com/btcsuite/btcd/txscript"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
	"github.com/btcsuite/btcutil/base58"
	"github.com/iqoption/zecutil"
)

func main() {
	TestSign()
}

var netParams = &chaincfg.Params{
	Name: "test",
}

func TestSign() {

	var (
		wif *btcutil.WIF
		err error
	)

	if wif, err = btcutil.DecodeWIF("cRy5WaeUyHx81JHpgJY7UdWaih43Demn9P2RGEoBNF8wfKvwuUgM"); err != nil {
		fmt.Println("can't parse wif")
		return
	}

	var ph *chainhash.Hash
	if ph, err = chainhash.NewHashFromStr(
		"643020d7a70b7660b3b77550be9a4a8a54f8d088b5e3d5a887ade41848117829",
	); err != nil {
		fmt.Println(err)
		return
	}

	newTx := wire.NewMsgTx(4)
	txIn := wire.NewTxIn(wire.NewOutPoint(ph, 1), nil, nil)
	newTx.AddTxIn(txIn)

	type receiver struct {
		addr   string
		amount int64
	}

	receivers := []receiver{
		// {"tmF834qorixnCV18bVrkM8WN1Xasy5eXcZV", 20000},
		{"tmF3uG6NKJXTvLFkXETx7NVxKwKWSBvPf21", 9500000},
	}

	for _, receiver := range receivers {
		decoded := base58.Decode(receiver.addr)
		var addr *btcutil.AddressPubKeyHash
		if addr, err = btcutil.NewAddressPubKeyHash(decoded[2:len(decoded)-4], netParams); err != nil {
			fmt.Println(err)
			return
		}

		receiverPkScript, err := txscript.PayToAddrScript(addr)
		if err != nil {
			fmt.Println(err)
			return
		}

		txOut := wire.NewTxOut(receiver.amount, receiverPkScript)
		newTx.AddTxOut(txOut)
	}

	zecTx := &zecutil.MsgTx{
		MsgTx:        newTx,
		ExpiryHeight: 1140780,
	}

	var prevTxScript []byte
	if prevTxScript, err = hex.DecodeString("76a9141f665d94693ea7712530ee8460116cbf879858f488ac"); err != nil {
		fmt.Println(err)
		return
	}

	sigScript, err := zecutil.SignTxOutput(netParams, zecTx, 0, prevTxScript, txscript.SigHashAll,
		txscript.KeyClosure(func(a btcutil.Address) (*btcec.PrivateKey, bool, error) {
			return wif.PrivKey, wif.CompressPubKey, nil
		}),
		nil,
		nil,
		0)

	if err != nil {
		fmt.Println(err)
		return
	}
	txIn.SignatureScript = sigScript

	var buf bytes.Buffer
	if err = zecTx.ZecEncode(&buf, 0, wire.BaseEncoding); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(hex.EncodeToString(buf.Bytes()))

	// wrong 0400008085202f89012978114818e4ad87a8d5e3b588d0f8548a4a9abe5075b7b360760ba7d7203064010000006b483045022100c235988b0d7910a23bf179ea197a3a20d14c5f711eef07f0ea4284a21304391d02204b196d4d5b1ce2f174f49d1ae532e98335ecfce618ce92e4c88c2fde20c27069012102d46a5c8b2aa894c9efc9f7eb92efd1c150ecad55f892d5de61675d44968dcc8cffffffff0160f59000000000001976a9143a8b2f8d711643f5bff63945ef44c2973bab10ce88ac000000002c6811000000000000000000000000

	// right 0400008085202f89012978114818e4ad87a8d5e3b588d0f8548a4a9abe5075b7b360760ba7d7203064010000006b483045022100f6b037872ad833c951869e63291364d2fed4e1de8dcc8157cfefebc86bfa34c202207a7fd5c72243eff854538f9aea3ed063f78ce3876048330a9f68353a3272cb07012102d46a5c8b2aa894c9efc9f7eb92efd1c150ecad55f892d5de61675d44968dcc8cffffffff0160f59000000000001976a9143a8b2f8d711643f5bff63945ef44c2973bab10ce88ac000000002c6811000000000000000000000000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant