Ejemplo n.º 1
0
// test to help Python team with integration of libsecp256k1
// skip but keep it after they are done
func TestPythonIntegration(t *testing.T) {
	kh := "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032"
	k0, _ := HexToECDSA(kh)
	k1 := FromECDSA(k0)

	msg0 := Keccak256([]byte("foo"))
	sig0, _ := secp256k1.Sign(msg0, k1)

	msg1 := common.FromHex("00000000000000000000000000000000")
	sig1, _ := secp256k1.Sign(msg0, k1)

	fmt.Printf("msg: %x, privkey: %x sig: %x\n", msg0, k1, sig0)
	fmt.Printf("msg: %x, privkey: %x sig: %x\n", msg1, k1, sig1)
}
Ejemplo n.º 2
0
func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
	if len(hash) != 32 {
		return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
	}

	sig, err = secp256k1.Sign(hash, common.LeftPadBytes(prv.D.Bytes(), prv.Params().BitSize/8))
	return
}