sr25519

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: LGPL-3.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// PublicKeyLength is the expected public key length for sr25519.
	PublicKeyLength = 32
	// SeedLength is the expected seed length for sr25519.
	SeedLength = 32
	// PrivateKeyLength is the expected private key length for sr25519.
	PrivateKeyLength = 32
	// SignatureLength is the expected signature length for sr25519.
	SignatureLength = 64
	// VRFOutputLength is the expected VFR output length for sr25519.
	VRFOutputLength = 32
	// VRFProofLength is the expected VFR proof length for sr25519.
	VRFProofLength = 64
)

Variables

View Source
var SigningContext = []byte("substrate")

SigningContext is the context for signatures used or created with substrate

Functions

func AttachInput added in v0.3.0

func AttachInput(output [VRFOutputLength]byte, pub *PublicKey, t *merlin.Transcript) (
	vrfInOut *sr25519.VrfInOut, err error)

AttachInput wraps schnorrkel *VrfOutput.AttachInput

func VerifySignature added in v0.7.0

func VerifySignature(publicKey, signature, message []byte) error

VerifySignature verifies a signature given a public key and a message

Types

type Keypair

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

Keypair is a sr25519 public-private keypair

func GenerateKeypair

func GenerateKeypair() (*Keypair, error)

GenerateKeypair returns a new sr25519 keypair

func NewKeypair

func NewKeypair(priv *sr25519.SecretKey) (*Keypair, error)

NewKeypair returns a sr25519 Keypair given a schnorrkel secret key

func NewKeypairFromMnenomic added in v0.3.1

func NewKeypairFromMnenomic(mnemonic, password string) (*Keypair, error)

NewKeypairFromMnenomic returns a new Keypair using the given mnemonic and password.

func NewKeypairFromPrivate

func NewKeypairFromPrivate(priv *PrivateKey) (*Keypair, error)

NewKeypairFromPrivate returns a sr25519 Keypair given a *sr25519.PrivateKey

func NewKeypairFromPrivateKeyBytes

func NewKeypairFromPrivateKeyBytes(in []byte) (*Keypair, error)

NewKeypairFromPrivateKeyBytes returns a Keypair given a private key byte slice

func NewKeypairFromPrivateKeyString

func NewKeypairFromPrivateKeyString(in string) (*Keypair, error)

NewKeypairFromPrivateKeyString returns a Keypair given a 0x prefixed private key string

func NewKeypairFromSeed

func NewKeypairFromSeed(keystr []byte) (*Keypair, error)

NewKeypairFromSeed returns a new sr25519 Keypair given a seed

func (*Keypair) Private

func (kp *Keypair) Private() crypto.PrivateKey

Private returns the private key corresponding to this keypair

func (*Keypair) Public

func (kp *Keypair) Public() crypto.PublicKey

Public returns the public key corresponding to this keypair

func (*Keypair) Sign

func (kp *Keypair) Sign(msg []byte) ([]byte, error)

Sign uses the keypair to sign the message using the sr25519 signature algorithm

func (*Keypair) Type added in v0.2.0

func (*Keypair) Type() crypto.KeyType

Type returns Sr25519Type

func (*Keypair) VrfSign

VrfSign creates a VRF output and proof from a message and private key

type PrivateKey

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

PrivateKey holds reference to a sr25519.SecretKey

func NewPrivateKey

func NewPrivateKey(in []byte) (*PrivateKey, error)

NewPrivateKey creates a new private key using the input bytes

func (*PrivateKey) Decode

func (k *PrivateKey) Decode(in []byte) error

Decode decodes the input bytes into a private key and sets the receiver the decoded key Input must be 32 bytes, or else this function will error

func (*PrivateKey) Encode

func (k *PrivateKey) Encode() []byte

Encode returns the 32-byte encoding of the private key

func (*PrivateKey) Hex

func (k *PrivateKey) Hex() string

Hex returns the private key as a '0x' prefixed hex string

func (*PrivateKey) Public

func (k *PrivateKey) Public() (crypto.PublicKey, error)

Public returns the public key corresponding to this private key

func (*PrivateKey) Sign

func (k *PrivateKey) Sign(msg []byte) ([]byte, error)

Sign uses the private key to sign the message using the sr25519 signature algorithm

func (*PrivateKey) VrfSign

VrfSign creates a VRF output and proof from a message and private key

type PublicKey

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

PublicKey holds reference to a sr25519.PublicKey

func NewPublicKey

func NewPublicKey(in []byte) (*PublicKey, error)

NewPublicKey returns a sr25519 public key from 32 byte input

func (*PublicKey) Address

func (k *PublicKey) Address() common.Address

Address returns the ss58 address for this public key

func (*PublicKey) AsBytes added in v0.2.0

func (k *PublicKey) AsBytes() [PublicKeyLength]byte

AsBytes returns the key as a [PublicKeyLength]byte

func (*PublicKey) Decode

func (k *PublicKey) Decode(in []byte) error

Decode decodes the input bytes into a public key and sets the receiver the decoded key Input must be 32 bytes, or else this function will error

func (*PublicKey) Encode

func (k *PublicKey) Encode() []byte

Encode returns the 32-byte encoding of the public key

func (*PublicKey) Hex

func (k *PublicKey) Hex() string

Hex returns the public key as a '0x' prefixed hex string

func (*PublicKey) Verify

func (k *PublicKey) Verify(msg, sig []byte) (bool, error)

Verify uses the sr25519 signature algorithm to verify that the message was signed by this public key; it returns true if this key created the signature for the message, false otherwise

func (*PublicKey) VerifyDeprecated added in v0.3.0

func (k *PublicKey) VerifyDeprecated(msg, sig []byte) (bool, error)

VerifyDeprecated verifies that the public key signed the given message. Deprecated: this is used by ext_crypto_sr25519_verify_version_1 only and should not be used anywhere else. This method does not check that the signature is in fact a schnorrkel signature, and does not distinguish between sr25519 and ed25519 signatures.

func (*PublicKey) VrfVerify

func (k *PublicKey) VrfVerify(t *merlin.Transcript, out [VRFOutputLength]byte,
	proof [VRFProofLength]byte) (bool, error)

VrfVerify confirms that the output and proof are valid given a message and public key

Jump to

Keyboard shortcuts

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