signing

package
v0.1.1-0...-84673a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package signing is from https://github.com/hyperledger/sawtooth-sdk-go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SHA512

func SHA512(input []byte) string

SHA512 returns a sha512 hex string.

func Verify

func Verify(signature, message, public []byte) bool

Verify returns true if signature is legal, or false.

func VerifyHex

func VerifyHex(signature, message, publicKey string) (bool, error)

VerifyHex verifies signature is legal or not. all inputs must be hex string.

func VerifyMsg

func VerifyMsg(signature, message, publicKey string) (bool, error)

VerifyMsg verifies signature is legal or not. message will be cast to bytes.

Types

type Context

type Context interface {
	// Returns the algorithm name used for this context.
	GetAlgorithmName() string

	// Generates a new random private key.
	NewRandomPrivateKey() PrivateKey

	// Produces a public key for the given private key.
	GetPublicKey(privateKey PrivateKey) PublicKey

	// Sign uses the given private key to calculate a signature for
	// the given data.
	Sign(message []byte, privateKey PrivateKey) []byte

	// Verify uses the given public key to verify that the given
	// signature was created from the given data using the associated
	// private key.
	Verify(signature []byte, message []byte, publicKey PublicKey) bool
}

Context A context for a cryptographic signing algorithm.

func CreateContext

func CreateContext(algorithmName string) Context

CreateContext Returns a Context instance by name.

func NewSecp256k1Context

func NewSecp256k1Context() Context

NewSecp256k1Context returns a new secp256k1 context.

type CryptoFactory

type CryptoFactory struct {
	// contains filtered or unexported fields
}

CryptoFactory A factory for generating Signers.

func NewCryptoFactory

func NewCryptoFactory(context Context) *CryptoFactory

NewCryptoFactory Creates a factory for generating Signers.

func (*CryptoFactory) GetContext

func (factory *CryptoFactory) GetContext() Context

GetContext returns the context that backs this Factory instance.

func (*CryptoFactory) NewSigner

func (factory *CryptoFactory) NewSigner(privateKey PrivateKey) *Signer

NewSigner creates a new Signer for the given private key.

type PrivateKey

type PrivateKey interface {
	// Returns the algorithm name used for this private key.
	GetAlgorithmName() string

	// Returns the private key encoded as a hex string.
	AsHex() string

	// Returns the private key bytes.
	AsBytes() []byte
}

PrivateKey A private key instance. The underlying content is dependent on implementation.

func GeneratePrivKeyFromCode

func GeneratePrivKeyFromCode(code string) PrivateKey

GeneratePrivKeyFromCode returns a private key from some code.

func NewSecp256k1PrivateKey

func NewSecp256k1PrivateKey(privateKey []byte) PrivateKey

NewSecp256k1PrivateKey creates a PrivateKey instance from private key bytes.

func RandomPrivateKey

func RandomPrivateKey() PrivateKey

RandomPrivateKey returns a random private key.

type PublicKey

type PublicKey interface {
	// Returns the algorithm name used for this public key.
	GetAlgorithmName() string

	// Returns the public key encoded as a hex string.
	AsHex() string

	// Returns the public key bytes.
	AsBytes() []byte
}

PublicKey A public key instance. The underlying content is dependent on implementation.

func NewSecp256k1PublicKey

func NewSecp256k1PublicKey(publicKey []byte) PublicKey

NewSecp256k1PublicKey creates a PublicKey instance from public key bytes.

type Secp256k1Context

type Secp256k1Context struct {
	// contains filtered or unexported fields
}

Secp256k1Context implements signing.Context with KoblitzCurve.

func (*Secp256k1Context) GetAlgorithmName

func (ctx *Secp256k1Context) GetAlgorithmName() string

GetAlgorithmName returns the string "secp256k1".

func (*Secp256k1Context) GetPublicKey

func (ctx *Secp256k1Context) GetPublicKey(privateKey PrivateKey) PublicKey

GetPublicKey produces a public key for the given private key.

func (*Secp256k1Context) NewRandomPrivateKey

func (ctx *Secp256k1Context) NewRandomPrivateKey() PrivateKey

NewRandomPrivateKey generates a new random secp256k1 private key.

func (*Secp256k1Context) Sign

func (ctx *Secp256k1Context) Sign(message []byte, privateKey PrivateKey) []byte

Sign uses the given private key to calculate a signature for the given data. A sha256 hash of the data is first calculated and this is what is actually signed. Returns the signature as bytes using the compact serialization (which is just (r, s)).

func (*Secp256k1Context) Verify

func (ctx *Secp256k1Context) Verify(signature []byte, message []byte, publicKey PublicKey) bool

Verify uses the given public key to verify that the given signature was created from the given data using the associated private key. A sha256 hash of the data is calculated first and this is what is actually used to verify the signature.

type Secp256k1PrivateKey

type Secp256k1PrivateKey struct {
	// contains filtered or unexported fields
}

Secp256k1PrivateKey represents a secp256k1 private key.

func (*Secp256k1PrivateKey) AsBytes

func (key *Secp256k1PrivateKey) AsBytes() []byte

AsBytes returns the bytes of the private key.

func (*Secp256k1PrivateKey) AsHex

func (key *Secp256k1PrivateKey) AsHex() string

AsHex returns the private key as a hex-encoded string.

func (*Secp256k1PrivateKey) GetAlgorithmName

func (key *Secp256k1PrivateKey) GetAlgorithmName() string

GetAlgorithmName returns the string "secp256k1".

type Secp256k1PublicKey

type Secp256k1PublicKey struct {
	// contains filtered or unexported fields
}

Secp256k1PublicKey represents secp256k1 public key.

func (*Secp256k1PublicKey) AsBytes

func (key *Secp256k1PublicKey) AsBytes() []byte

AsBytes returns the bytes of the public key.

func (*Secp256k1PublicKey) AsHex

func (key *Secp256k1PublicKey) AsHex() string

AsHex returns the public key as a hex-encoded string.

func (*Secp256k1PublicKey) GetAlgorithmName

func (key *Secp256k1PublicKey) GetAlgorithmName() string

GetAlgorithmName returns the string "secp256k1".

type Signer

type Signer struct {
	// contains filtered or unexported fields
}

Signer A convenient wrapper of Context and PrivateKey.

func GenerateSigner

func GenerateSigner() *Signer

GenerateSigner returns a signer with a random private key.

func GenerateSignerFromCode

func GenerateSignerFromCode(code string) *Signer

GenerateSignerFromCode returns a signer from some code.

func LoadSignerFromBytes

func LoadSignerFromBytes(raw []byte) *Signer

LoadSignerFromBytes returns a signer loading from bytes of private key.

func LoadSignerFromFile

func LoadSignerFromFile(file string) (*Signer, error)

LoadSignerFromFile returns signer from private key file.

func LoadSignerFromHex

func LoadSignerFromHex(hexstr string) (*Signer, error)

LoadSignerFromHex returns a signer from hex string.

func MustSigner

func MustSigner(s *Signer, err error) *Signer

MustSigner ...

func NewSigner

func NewSigner(key PrivateKey) *Signer

NewSigner returns a signer from private key.

func (*Signer) GetPrivateKey

func (s *Signer) GetPrivateKey() PrivateKey

GetPrivateKey ...

func (*Signer) GetPublicKey

func (s *Signer) GetPublicKey() PublicKey

GetPublicKey returns the public key for this Signer instance.

func (*Signer) Sign

func (s *Signer) Sign(message []byte) []byte

Sign Signs the given message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL