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"
"github.com/CityOfZion/neo-go/pkg/core/mempool"
"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/smartcontract"
"github.com/CityOfZion/neo-go/pkg/util"
@ -221,16 +220,15 @@ func (s *service) validatePayload(p *Payload) bool {
}
pub := validators[p.validatorIndex]
vs := pub.(*publicKey).GetVerificationScript()
h := hash.Hash160(vs)
h := pub.(*publicKey).GetScriptHash()
return p.Verify(h)
}
func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, crypto.PublicKey) {
for i := range pubs {
script := pubs[i].(*publicKey).GetVerificationScript()
acc := s.wallet.GetAccount(hash.Hash160(script))
sh := pubs[i].(*publicKey).GetScriptHash()
acc := s.wallet.GetAccount(sh)
if acc == nil {
continue
}
@ -446,7 +444,7 @@ func (s *service) getVerifiedTx(count int) []block.Transaction {
sh := s.wallet.GetChangeAddress()
if sh.Equals(util.Uint160{}) {
pk := s.dbft.Pub.(*publicKey)
sh = hash.Hash160(pk.GetVerificationScript())
sh = pk.GetScriptHash()
}
txOuts = []transaction.Output{transaction.Output{
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/state"
"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/smartcontract/trigger"
"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
// key against current list of script hashes for verifying in the interop context.
func (ic *interopContext) checkKeyedWitness(key *keys.PublicKey) (bool, error) {
return ic.checkHashedWitness(hash.Hash160(key.GetVerificationScript()))
return ic.checkHashedWitness(key.GetScriptHash())
}
// runtimeCheckWitness checks witnesses.

View file

@ -10,6 +10,7 @@ import (
"fmt"
"math/big"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/nspcc-dev/rfc6979"
)
@ -98,10 +99,11 @@ func (p *PrivateKey) Address() string {
return pk.Address()
}
// Signature creates the signature using the private key.
func (p *PrivateKey) Signature() []byte {
// GetScriptHash returns verification script hash for public key associated with
// the private key.
func (p *PrivateKey) GetScriptHash() util.Uint160 {
pk := p.PublicKey()
return pk.Signature()
return pk.GetScriptHash()
}
// 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/encoding/address"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/CityOfZion/neo-go/pkg/util"
"github.com/CityOfZion/neo-go/pkg/vm/opcode"
"github.com/pkg/errors"
)
@ -233,18 +234,14 @@ func (p *PublicKey) GetVerificationScript() []byte {
return b
}
// Signature returns a NEO-specific hash of the key.
func (p *PublicKey) Signature() []byte {
sig := hash.Hash160(p.GetVerificationScript())
return sig.BytesBE()
// GetScriptHash returns a Hash160 of verification script for the key.
func (p *PublicKey) GetScriptHash() util.Uint160 {
return hash.Hash160(p.GetVerificationScript())
}
// Address returns a base58-encoded NEO-specific address based on the key hash.
func (p *PublicKey) Address() string {
sig := hash.Hash160(p.GetVerificationScript())
return address.Uint160ToString(sig)
return address.Uint160ToString(p.GetScriptHash())
}
// Verify returns true if the signature is valid and corresponds