forked from TrueCloudLab/neoneo-go
testchain: implement Sign function
Sign any data by all consensus nodes.
This commit is contained in:
parent
76a6937f32
commit
0f17402599
2 changed files with 18 additions and 19 deletions
|
@ -71,17 +71,7 @@ func newBlock(cfg config.ProtocolConfiguration, index uint32, prev util.Uint256,
|
||||||
}
|
}
|
||||||
_ = b.RebuildMerkleRoot()
|
_ = b.RebuildMerkleRoot()
|
||||||
|
|
||||||
buf := io.NewBufBinWriter()
|
b.Script.InvocationScript = testchain.Sign(b.GetSignedPart())
|
||||||
for i := 0; i < testchain.Size(); i++ {
|
|
||||||
pKey := testchain.PrivateKey(i)
|
|
||||||
b := b.GetSignedPart()
|
|
||||||
sig := pKey.Sign(b)
|
|
||||||
if len(sig) != 64 {
|
|
||||||
panic("wrong signature length")
|
|
||||||
}
|
|
||||||
emit.Bytes(buf.BinWriter, sig)
|
|
||||||
}
|
|
||||||
b.Script.InvocationScript = buf.Bytes()
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,15 +498,8 @@ func signTx(bc *Blockchain, txs ...*transaction.Transaction) error {
|
||||||
}
|
}
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
data := tx.GetSignedPart()
|
data := tx.GetSignedPart()
|
||||||
|
|
||||||
var invoc []byte
|
|
||||||
for i := 0; i < testchain.Size(); i++ {
|
|
||||||
priv := testchain.PrivateKey(i)
|
|
||||||
invoc = append(invoc, getInvocationScript(data, priv)...)
|
|
||||||
}
|
|
||||||
|
|
||||||
tx.Scripts = []transaction.Witness{{
|
tx.Scripts = []transaction.Witness{{
|
||||||
InvocationScript: invoc,
|
InvocationScript: testchain.Sign(data),
|
||||||
VerificationScript: rawScript,
|
VerificationScript: rawScript,
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,10 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// privNetKeys is a list of unencrypted WIFs sorted by public key.
|
// privNetKeys is a list of unencrypted WIFs sorted by public key.
|
||||||
|
@ -78,3 +80,17 @@ func MultisigScriptHash() util.Uint160 {
|
||||||
func MultisigAddress() string {
|
func MultisigAddress() string {
|
||||||
return address.Uint160ToString(MultisigScriptHash())
|
return address.Uint160ToString(MultisigScriptHash())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sign signs data by all consensus nodes and returns invocation script.
|
||||||
|
func Sign(data []byte) []byte {
|
||||||
|
buf := io.NewBufBinWriter()
|
||||||
|
for i := 0; i < Size(); i++ {
|
||||||
|
pKey := PrivateKey(i)
|
||||||
|
sig := pKey.Sign(data)
|
||||||
|
if len(sig) != 64 {
|
||||||
|
panic("wrong signature length")
|
||||||
|
}
|
||||||
|
emit.Bytes(buf.BinWriter, sig)
|
||||||
|
}
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue