keyring

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const SecretKeySize = 64

Variables

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

SigningContext is the context for signatures used or created with substrate

Functions

This section is empty.

Types

type Category

type Category string
const (
	Ed25519Type Category = "Ed25519"
	Sr25519Type Category = "Sr25519"
)

type Ed25519

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

func NewEd25519

func NewEd25519(seed string) *Ed25519

NewEd25519 create new ed25519 keyring seed: 0x + 64 hex string if seed length not 64, will panic

func (*Ed25519) PublicKey

func (e *Ed25519) PublicKey() string

PublicKey return ED25519 public key

func (*Ed25519) Sign

func (e *Ed25519) Sign(message string) string

Sign message by ed25519 if message has 0x prefix, will decode hex string to bytes else will use string bytes

func (*Ed25519) Type

func (e *Ed25519) Type() Category

Type return keyring type

type IKeyRing

type IKeyRing interface {
	Sign(string) string
	PublicKey() string
	Type() Category
}

func New

func New(category Category, seed string) IKeyRing

type Keypair

type Keypair interface {
	Sign(msg []byte) ([]byte, error)
	Public() PublicKey
	Private() PrivateKey
}

type PrivateKey

type PrivateKey interface {
	Sign(msg []byte) ([]byte, error)
	Public() (PublicKey, error)
	Encode() []byte
	Decode([]byte) error
}

type PublicKey

type PublicKey interface {
	Verify(msg, sig []byte) bool
	Encode() []byte
	Decode([]byte) error
}

type Sr25519

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

func NewSr25519

func NewSr25519(seed string) *Sr25519

NewSr25519 create new sr25519 keyring

func (*Sr25519) PublicKey

func (s *Sr25519) PublicKey() string

PublicKey return sr25519 public key

func (*Sr25519) Sign

func (s *Sr25519) Sign(message string) string

Sign message by sr25519 if message has 0x prefix, will decode hex string to bytes else will use string bytes

func (*Sr25519) Type

func (s *Sr25519) Type() Category

Type return keyring type

type Sr25519Keypair

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

Sr25519Keypair is a sr25519 public-private keypair

func GenerateSr25519Keypair

func GenerateSr25519Keypair() (*Sr25519Keypair, error)

GenerateSr25519Keypair returns a new sr25519 keypair

func NewSr25519FromSeed

func NewSr25519FromSeed(seed []byte) (*Sr25519Keypair, error)

NewSr25519FromSeed from Secret seed to SecretKey

func NewSr25519Keypair

func NewSr25519Keypair(priv *sr25519.SecretKey) (*Sr25519Keypair, error)

NewSr25519Keypair returns a Sr25519Keypair given a schnorrkel secret key

func (*Sr25519Keypair) Private

func (kp *Sr25519Keypair) Private() PrivateKey

Private returns the private key corresponding to this keypair

func (*Sr25519Keypair) Public

func (kp *Sr25519Keypair) Public() PublicKey

Public returns the public key corresponding to this keypair

func (*Sr25519Keypair) Sign

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

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

type Sr25519PrivateKey

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

func (*Sr25519PrivateKey) Decode

func (k *Sr25519PrivateKey) 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 (*Sr25519PrivateKey) Encode

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

Encode returns the 32-byte encoding of the private key

func (*Sr25519PrivateKey) Public

func (k *Sr25519PrivateKey) Public() (PublicKey, error)

Public returns the public key corresponding to this private key

func (*Sr25519PrivateKey) Sign

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

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

type Sr25519PublicKey

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

func (*Sr25519PublicKey) Decode

func (k *Sr25519PublicKey) 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 (*Sr25519PublicKey) Encode

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

Encode returns the 32-byte encoding of the public key

func (*Sr25519PublicKey) Verify

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

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

Jump to

Keyboard shortcuts

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