aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-05 08:55:03 +0800
committerobscuren <obscuren@obscura.com>2014-01-05 08:55:03 +0800
commit92c3471445d9a46389ddab893a159ce273707a95 (patch)
treeb05efb759f8e0db212c8e56e84cdc403492c4535
parent53a30740eea7d3b3010337166e53a62ebff508f3 (diff)
downloaddexon-92c3471445d9a46389ddab893a159ce273707a95.tar.gz
dexon-92c3471445d9a46389ddab893a159ce273707a95.tar.zst
dexon-92c3471445d9a46389ddab893a159ce273707a95.zip
secp256k1 method signing
-rw-r--r--transaction.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/transaction.go b/transaction.go
index f5c848a31..f38f0fed3 100644
--- a/transaction.go
+++ b/transaction.go
@@ -3,6 +3,7 @@ package main
import (
"math/big"
"fmt"
+ "github.com/obscuren/secp256k1-go"
_"encoding/hex"
_"crypto/sha256"
_ "bytes"
@@ -73,6 +74,28 @@ func (tx *Transaction) Hash() []byte {
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 {
// Prepare the transaction for serialization
preEnc := []interface{}{