crypto

package
v0.1.7-0...-7628261 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BASIC_WALLET uint16 = 0
	TEST_WALLET  uint16 = 1
)

List of wallet types

View Source
const (
	PUBLIC_KEY_SIZE  = ed25519.PublicKeySize
	PRIVATE_KEY_SIZE = ed25519.PrivateKeySize
	SIGNATURE_SIZE   = ed25519.SignatureSize
	HASH_SIZE        = sha256.Size
)

AddressSize represents the new WalletAddress size. PUBLIC_KEY_SIZE is now only used to represent the size of the public key, not the WalletAddress.

View Source
const (
	CREATOR_NAME_SIZE     = 10
	TEST_WALLET_ADDR_SIZE = PUBLIC_KEY_SIZE + CREATOR_NAME_SIZE + 4
)
View Source
const (
	BASIC_WALLET_ADDR_SIZE = PUBLIC_KEY_SIZE + 4
)
View Source
const UINT64_BYTES = 8

Variables

This section is empty.

Functions

func Compare

func Compare(l WalletAddress, r WalletAddress) int

func CompareHashes

func CompareHashes(l [HASH_SIZE]byte, r [HASH_SIZE]byte) int

func CompareWalletAddress

func CompareWalletAddress(l WalletAddress, r WalletAddress) bool

func GenerateKey

func GenerateKey() (ed25519.PublicKey, ed25519.PrivateKey, error)

func HashBytes

func HashBytes(buf []byte) [HASH_SIZE]byte

func IsWalletType

func IsWalletType(WalletType uint16) bool

Checks if it is a wallet type

func LoadKeyFromFile

func LoadKeyFromFile(filename string) ([]byte, error)

func LoadKeyFromHex

func LoadKeyFromHex(key string) ([]byte, error)

func PubKeyToBytes

func PubKeyToBytes(pub crypto.PublicKey) ([]byte, error)

Types

type BasicWallet

type BasicWallet struct {
	Type_     uint16
	Length_   uint16
	Filename_ string
	Public_   ed25519.PublicKey
	Private_  ed25519.PrivateKey
}

func NewSilvermintWallet

func NewSilvermintWallet(addr []byte) BasicWallet

func NewSilvermintWalletFromPrivKey

func NewSilvermintWalletFromPrivKey(privKey []byte) BasicWallet

func (BasicWallet) Filename

func (w BasicWallet) Filename() string

func (BasicWallet) Length

func (w BasicWallet) Length() uint16

func (BasicWallet) MarshalBinary

func (wal BasicWallet) MarshalBinary() ([]byte, error)

func (BasicWallet) Private

func (w BasicWallet) Private() ed25519.PrivateKey

func (BasicWallet) PrivateBytes

func (w BasicWallet) PrivateBytes() [PRIVATE_KEY_SIZE]byte

func (BasicWallet) Public

func (w BasicWallet) Public() ed25519.PublicKey

func (BasicWallet) Save

func (w BasicWallet) Save() error

func (BasicWallet) SaveKeys

func (w BasicWallet) SaveKeys(filename string) error

func (BasicWallet) Sign

func (w BasicWallet) Sign(message []byte) ([]byte, error)

func (BasicWallet) Type

func (w BasicWallet) Type() uint16

func (BasicWallet) Verify

func (w BasicWallet) Verify(message []byte) bool

func (BasicWallet) WalletAddress

func (w BasicWallet) WalletAddress() WalletAddress

WalletAddress returns Address which is the marshal binary of the wallet struct, this is the Public Address that is now used to represent a Wallet, not just the PublicKey

type BasicWalletAddress

type BasicWalletAddress struct {
	Address_ [BASIC_WALLET_ADDR_SIZE]byte
}

func (BasicWalletAddress) Address

func (sa BasicWalletAddress) Address() []byte

func (BasicWalletAddress) Length

func (sa BasicWalletAddress) Length() uint16

func (BasicWalletAddress) Uint64

func (sa BasicWalletAddress) Uint64() uint64

type Signature

type Signature [SIGNATURE_SIZE]byte

type TestWallet

type TestWallet struct {
	Type_        uint16
	Length_      uint16
	Filename_    string
	CreatorName_ string
	Public_      ed25519.PublicKey
	Private_     ed25519.PrivateKey
}

func NewTestWallet

func NewTestWallet(addr []byte) TestWallet

func (TestWallet) CreatorName

func (w TestWallet) CreatorName() string

func (TestWallet) Filename

func (w TestWallet) Filename() string

func (TestWallet) Length

func (w TestWallet) Length() uint16

func (TestWallet) MarshalBinary

func (w TestWallet) MarshalBinary() ([]byte, error)

func (TestWallet) Private

func (w TestWallet) Private() ed25519.PrivateKey

func (TestWallet) PrivateBytes

func (w TestWallet) PrivateBytes() [PRIVATE_KEY_SIZE]byte

func (TestWallet) Public

func (w TestWallet) Public() ed25519.PublicKey

func (TestWallet) Save

func (w TestWallet) Save() error

func (TestWallet) SaveKeys

func (w TestWallet) SaveKeys(filename string) error

func (TestWallet) Sign

func (w TestWallet) Sign(message []byte) ([]byte, error)

func (TestWallet) Type

func (w TestWallet) Type() uint16

func (TestWallet) Verify

func (w TestWallet) Verify(message []byte) bool

func (TestWallet) WalletAddress

func (w TestWallet) WalletAddress() WalletAddress

WalletAddress returns Address which is the marshal binary of the wallet struct, this is the Public Address that is now used to represent a Wallet, not just the PublicKey

type TestWalletAddress

type TestWalletAddress struct {
	Address_ [TEST_WALLET_ADDR_SIZE]byte
}

func (TestWalletAddress) Address

func (a TestWalletAddress) Address() []byte

func (TestWalletAddress) Length

func (a TestWalletAddress) Length() uint16

func (TestWalletAddress) Uint64

func (a TestWalletAddress) Uint64() uint64

type Wallet

type Wallet interface {
	Type() uint16
	Length() uint16
	Filename() string
	Public() ed25519.PublicKey
	Private() ed25519.PrivateKey

	WalletAddress() WalletAddress
	PrivateBytes() [PRIVATE_KEY_SIZE]byte
	Save() error
	SaveKeys(filename string) error
	Sign(message []byte) ([]byte, error)
	Verify(message []byte) bool

	MarshalBinary() ([]byte, error)
}

func LoadWalletFromFile

func LoadWalletFromFile(filename string) (Wallet, error)

func NewWallet

func NewWallet(filename string, walletType uint16) (Wallet, error)

func UnmarshalBinary

func UnmarshalBinary(keybytes []byte) (Wallet, error)

NB(chuck): Kinda dumb, but we can't have an UnmarshalBinary([]byte) error interface function for a Wallet. That would require changing the Wallet interface from being an interface to {BasicWallet, TestWallet} to being an interface to {*BasicWallet, *TestWallet} (since UnmarshalBinary must have a pointer receiver). This changes all the Ledger stuff because we could no longer readily store/lookup wallets in maps or check them for equality, due to the fact that we'd be comparing pointers instead of structs.

func UnmarshalPublicKeyFromHex

func UnmarshalPublicKeyFromHex(hex string) (Wallet, error)

type WalletAddress

type WalletAddress interface {
	Address() []byte
	Length() uint16
	Uint64() uint64
}

func NewWalletAddress

func NewWalletAddress(address []byte) WalletAddress

type WalletKey

type WalletKey [PRIVATE_KEY_SIZE]byte

WalletAddress is now a marshal binary containing: Type, Length, and PublicKey.

Jump to

Keyboard shortcuts

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