Commit 92c34714 authored by obscuren's avatar obscuren

secp256k1 method signing

parent 53a30740
...@@ -3,6 +3,7 @@ package main ...@@ -3,6 +3,7 @@ package main
import ( import (
"math/big" "math/big"
"fmt" "fmt"
"github.com/obscuren/secp256k1-go"
_"encoding/hex" _"encoding/hex"
_"crypto/sha256" _"crypto/sha256"
_ "bytes" _ "bytes"
...@@ -73,6 +74,28 @@ func (tx *Transaction) Hash() []byte { ...@@ -73,6 +74,28 @@ func (tx *Transaction) Hash() []byte {
return Sha256Bin(tx.MarshalRlp()) return Sha256Bin(tx.MarshalRlp())
} }
func (tx *Transaction) IsContract() bool {
return tx.recipient == ""
}
func (tx *Transaction) Signature() []byte {
hash := Sha256Bin(tx.MarshalRlp())
sec := Sha256Bin([]byte("myprivkey"))
sig, _ := secp256k1.Sign(hash, sec)
return sig
}
func (tx *Transaction) PublicKey() []byte {
hash := Sha256Bin(tx.MarshalRlp())
sig := tx.Signature()
pubkey, _ := secp256k1.RecoverPubkey(hash, sig)
return pubkey
}
func (tx *Transaction) MarshalRlp() []byte { func (tx *Transaction) MarshalRlp() []byte {
// Prepare the transaction for serialization // Prepare the transaction for serialization
preEnc := []interface{}{ preEnc := []interface{}{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment