sr25519

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Overview

Package sr25519 implements go-perun's wallet interface for the polkadot backend.

Index

Constants

View Source
const AddressLen = 32

AddressLen is the length of an encoded Address in byte.

View Source
const (
	// SignatureLen is the constant length of a signature in byte.
	SignatureLen = 64
)

Variables

View Source
var (
	// ErrWrongAddrType is returned when the type of a Perun Address was not
	// of type Address.
	ErrWrongAddrType = errors.New("got wrong address type")
	// ErrAccountNotPresent is returned when no Account could be found for
	// a specific Address.
	ErrAccountNotPresent = errors.New("account is not present in the wallet")
)

Functions

func IsAcc

func IsAcc(acc pwallet.Account) bool

IsAcc returns whether a Perun Account has the expected Account type.

func IsAddr

func IsAddr(addr pwallet.Address) bool

IsAddr returns whether a Perun Address has the expected Address type.

Types

type Account

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

Account implements the Account interface. Can be used to sign arbitrary data and extrinsics.

func AsAcc

func AsAcc(acc pwallet.Account) *Account

AsAcc returns a Perun Account as Account. Panics if the conversion failed.

func (*Account) Address

func (acc *Account) Address() pwallet.Address

Address returns the Address. Needed by the Account interface.

func (*Account) SignData

func (acc *Account) SignData(data []byte) ([]byte, error)

SignData signs a byte-slice. Needed by the Account interface.

func (*Account) SignExt

func (acc *Account) SignExt(ext *types.Extrinsic, opts types.SignatureOptions, net substrate.NetworkID) error

SignExt signs an extrinsic by modifying it. This behaviour is required by GSRPC.

type Address

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

Address implements the Address interface.

func AsAddr

func AsAddr(addr pwallet.Address) *Address

AsAddr returns a Perun Address as Address. Panics if the conversion failed.

func NewAddressFromPK

func NewAddressFromPK(pk *schnorrkel.PublicKey) *Address

NewAddressFromPK returns a new Address from a public key.

func (*Address) AccountID

func (a *Address) AccountID() types.AccountID

AccountID returns the substrate account id of an address.

func (*Address) Bytes

func (a *Address) Bytes() []byte

Bytes returns the address encoded as byte slice.

func (*Address) Cmp

func (a *Address) Cmp(b pwallet.Address) int

Cmp returns 0 if a == b, -1 if a < b, and +1 if a > b. Where ==, < and > are an arbitrary but fixed total order over Address. Panics if the passed address is not of type Address. Needed by the Perun Address interface.

func (*Address) Equal added in v0.2.0

func (a *Address) Equal(b pwallet.Address) bool

Equal returns whether the passed address is equal to the receiver. Panics if the passed address is not of type Address. Needed by the Perun Address interface.

func (*Address) MarshalBinary added in v0.2.0

func (a *Address) MarshalBinary() (data []byte, err error)

MarshalBinary encodes the receiver into a binary form and returns the result.

func (*Address) String

func (a *Address) String() string

String returns the AccountID as hex string with 0x prefix. Needed by the Perun Address interface.

func (*Address) UnmarshalBinary added in v0.2.0

func (a *Address) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes the form generated by MarshalBinary.

type Backend

type Backend struct{}

Backend implements the Backend interface.

func (*Backend) DecodeSig

func (*Backend) DecodeSig(r io.Reader) (pwallet.Sig, error)

DecodeSig decodes a signature from the reader.

func (*Backend) NewAddress added in v0.2.0

func (*Backend) NewAddress() pwallet.Address

NewAddress returns a variable of type Address, which can be used for unmarshalling an address from its binary representation.

func (*Backend) VerifySignature

func (*Backend) VerifySignature(msg []byte, s pwallet.Sig, a pwallet.Address) (bool, error)

VerifySignature verifies that the signature was created by the address on the passed data. Panics on wrong address type.

type Wallet

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

Wallet implements the Perun Wallet interface. It uses sr25519 cryptography.

func NewWallet

func NewWallet() *Wallet

NewWallet returns a new wallet.

func (*Wallet) DecrementUsage

func (*Wallet) DecrementUsage(pwallet.Address)

DecrementUsage does nothing. Needed by the Perun Wallet interface.

func (*Wallet) ImportSK

func (w *Wallet) ImportSK(sk *schnorrkel.MiniSecretKey) *Account

ImportSK can be used to import a secret key into the wallet.

func (*Wallet) IncrementUsage

func (*Wallet) IncrementUsage(pwallet.Address)

IncrementUsage does nothing. Needed by the Perun Wallet interface.

func (*Wallet) LockAll

func (*Wallet) LockAll()

LockAll does nothing. Needed by the Perun Wallet interface.

func (*Wallet) Unlock

func (w *Wallet) Unlock(pAddr pwallet.Address) (pwallet.Account, error)

Unlock unlocks an Account. Needed by the Perun Wallet interface. Returns ErrWrongAddrType or ErrAccountNotPresent in case of an error.

Directories

Path Synopsis
Package test provides helper and setup functions to test the sr25519 wallet.
Package test provides helper and setup functions to test the sr25519 wallet.

Jump to

Keyboard shortcuts

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