keys: rename Signature to GetScriptHash, make it return Uint160

Signature itself wasn't used at all and its name is very misleading, Uint160
script hash is way more useful.
This commit is contained in:
Roman Khimov 2020-02-19 12:10:36 +03:00
parent 4299d1cf1b
commit a903147b60
4 changed files with 15 additions and 19 deletions

View file

@ -11,7 +11,6 @@ import (
coreb "github.com/CityOfZion/neo-go/pkg/core/block" coreb "github.com/CityOfZion/neo-go/pkg/core/block"
"github.com/CityOfZion/neo-go/pkg/core/mempool" "github.com/CityOfZion/neo-go/pkg/core/mempool"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/smartcontract" "github.com/CityOfZion/neo-go/pkg/smartcontract"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
@ -221,16 +220,15 @@ func (s *service) validatePayload(p *Payload) bool {
} }
pub := validators[p.validatorIndex] pub := validators[p.validatorIndex]
vs := pub.(*publicKey).GetVerificationScript() h := pub.(*publicKey).GetScriptHash()
h := hash.Hash160(vs)
return p.Verify(h) return p.Verify(h)
} }
func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, crypto.PublicKey) { func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, crypto.PublicKey) {
for i := range pubs { for i := range pubs {
script := pubs[i].(*publicKey).GetVerificationScript() sh := pubs[i].(*publicKey).GetScriptHash()
acc := s.wallet.GetAccount(hash.Hash160(script)) acc := s.wallet.GetAccount(sh)
if acc == nil { if acc == nil {
continue continue
} }
@ -446,7 +444,7 @@ func (s *service) getVerifiedTx(count int) []block.Transaction {
sh := s.wallet.GetChangeAddress() sh := s.wallet.GetChangeAddress()
if sh.Equals(util.Uint160{}) { if sh.Equals(util.Uint160{}) {
pk := s.dbft.Pub.(*publicKey) pk := s.dbft.Pub.(*publicKey)
sh = hash.Hash160(pk.GetVerificationScript()) sh = pk.GetScriptHash()
} }
txOuts = []transaction.Output{transaction.Output{ txOuts = []transaction.Output{transaction.Output{
AssetID: core.UtilityTokenID(), AssetID: core.UtilityTokenID(),

View file

@ -8,7 +8,6 @@ import (
"github.com/CityOfZion/neo-go/pkg/core/block" "github.com/CityOfZion/neo-go/pkg/core/block"
"github.com/CityOfZion/neo-go/pkg/core/state" "github.com/CityOfZion/neo-go/pkg/core/state"
"github.com/CityOfZion/neo-go/pkg/core/transaction" "github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/crypto/keys"
"github.com/CityOfZion/neo-go/pkg/smartcontract/trigger" "github.com/CityOfZion/neo-go/pkg/smartcontract/trigger"
"github.com/CityOfZion/neo-go/pkg/util" "github.com/CityOfZion/neo-go/pkg/util"
@ -311,7 +310,7 @@ func (ic *interopContext) checkHashedWitness(hash util.Uint160) (bool, error) {
// checkKeyedWitness checks hash of signature check contract with a given public // checkKeyedWitness checks hash of signature check contract with a given public
// key against current list of script hashes for verifying in the interop context. // key against current list of script hashes for verifying in the interop context.
func (ic *interopContext) checkKeyedWitness(key *keys.PublicKey) (bool, error) { func (ic *interopContext) checkKeyedWitness(key *keys.PublicKey) (bool, error) {
return ic.checkHashedWitness(hash.Hash160(key.GetVerificationScript())) return ic.checkHashedWitness(key.GetScriptHash())
} }
// runtimeCheckWitness checks witnesses. // runtimeCheckWitness checks witnesses.

View file

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/nspcc-dev/rfc6979" "github.com/nspcc-dev/rfc6979"
) )
@ -98,10 +99,11 @@ func (p *PrivateKey) Address() string {
return pk.Address() return pk.Address()
} }
// Signature creates the signature using the private key. // GetScriptHash returns verification script hash for public key associated with
func (p *PrivateKey) Signature() []byte { // the private key.
func (p *PrivateKey) GetScriptHash() util.Uint160 {
pk := p.PublicKey() pk := p.PublicKey()
return pk.Signature() return pk.GetScriptHash()
} }
// Sign signs arbitrary length data using the private key. // Sign signs arbitrary length data using the private key.

View file

@ -12,6 +12,7 @@ import (
"github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
"github.com/CityOfZion/neo-go/pkg/encoding/address" "github.com/CityOfZion/neo-go/pkg/encoding/address"
"github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/CityOfZion/neo-go/pkg/vm/opcode" "github.com/CityOfZion/neo-go/pkg/vm/opcode"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -233,18 +234,14 @@ func (p *PublicKey) GetVerificationScript() []byte {
return b return b
} }
// Signature returns a NEO-specific hash of the key. // GetScriptHash returns a Hash160 of verification script for the key.
func (p *PublicKey) Signature() []byte { func (p *PublicKey) GetScriptHash() util.Uint160 {
sig := hash.Hash160(p.GetVerificationScript()) return hash.Hash160(p.GetVerificationScript())
return sig.BytesBE()
} }
// Address returns a base58-encoded NEO-specific address based on the key hash. // Address returns a base58-encoded NEO-specific address based on the key hash.
func (p *PublicKey) Address() string { func (p *PublicKey) Address() string {
sig := hash.Hash160(p.GetVerificationScript()) return address.Uint160ToString(p.GetScriptHash())
return address.Uint160ToString(sig)
} }
// Verify returns true if the signature is valid and corresponds // Verify returns true if the signature is valid and corresponds