Wallet

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const ADDRESS_PREFIX = "xrb"

Variables

View Source
var ALLOWED_PREFIX = [...]string{"xrb"}
View Source
var ErrImpossibleDecode = errors.New("impossible to decode the seed")
View Source
var SupportedVersions = [...]uint8{0}

Functions

func CreateKeyPair

func CreateKeyPair(b []byte) (PublicKey, SecretKey, error)

CreateKeyPair creates the Ed25519 key-pair from an given input and returns the public/private key, and error not nil if something go wrong.

func GenerateRandomKeyPair

func GenerateRandomKeyPair() (PublicKey, SecretKey, error)

GenerateRandomKeyPair creates the Ed25519, using an random input, we use the crypto/rand.

func RecoverKeyPairFromClassicalSeed

func RecoverKeyPairFromClassicalSeed(seed string, i uint32) (PublicKey, SecretKey, error)

RecoverKeyPairFromClassicalSeed will return the Ed25519 key-pair based on the hex-encoded HEX and one INDEX it uses the same process used in official wallet of Nano. In case of failure the error will be non-nil. The Nano Wallet Seed uses BLAKE2b(size = 32, key = nil, message = SEED+INDEX) to construct the key.

func RecoverKeyPairFromCoinSeed

func RecoverKeyPairFromCoinSeed(seed CoinSeed, i uint32) (PublicKey, SecretKey, error)

RecoverKeyPairFromSeed will return the Ed25519 key-pair based on given COINSEED and INDEX, it also returns non-nil error in case of failure. It uses the Blake2X instead of Blake2b and can support up to 256 keys. The Nanollet Seed uses BLAKE2bXOF(size = COINSIZE, key = COINSEED, message = INDEX)

Types

type Address

type Address string

func (Address) GetChecksum

func (addr Address) GetChecksum() ([]byte, error)

GetChecksum extract the existing checksum of the address, returns the checksum as byte-array.

func (Address) GetPrefix

func (addr Address) GetPrefix() string

GetPrefix extract the existing prefix of the address, everything before the first underscore.

func (Address) GetPublicKey

func (addr Address) GetPublicKey() (PublicKey, error)

PublicKeyFromFromAddress gets the Ed25519 public-key from the encoded address, returning the public-key. It's return an non-nil error if something bad happens.

func (Address) IsCorrectlyFormatted

func (addr Address) IsCorrectlyFormatted() bool

IsCorrectlyFormatted returns true if the given encoded address have an correct format. It return true if had an valid prefix and length, but checksum doesn't matter.

func (Address) IsValid

func (addr Address) IsValid() bool

IsValid returns true if the given encoded address have an correct formatting and also the checksum is correct.

func (*Address) MarshalJSON

func (d *Address) MarshalJSON() ([]byte, error)

func (Address) RemovePrefix

func (addr Address) RemovePrefix() Address

RemovePrefix remove the prefix of the address, returns an address without the prefix.

func (*Address) UnmarshalJSON

func (d *Address) UnmarshalJSON(data []byte) (err error)

func (Address) UpdatePrefix

func (addr Address) UpdatePrefix() Address

UpdateAddress modify the prefix of the address returning the address with new prefix identifier. (Can be used if "xrb_" be replaced by "nano_" in future)

type CoinSeed

type CoinSeed []byte

func RecoverCoinSeed

func RecoverCoinSeed(seed Seed, coin Currency) CoinSeed

RecoverKeyPairFromSeed will return an seed for given currency.

type Currency

type Currency uint32
const (
	Base Currency = iota
	Nano
)

@TODO Support Banano

type PublicKey

type PublicKey []byte

func (PublicKey) CompareChecksum

func (pk PublicKey) CompareChecksum(checksum []byte) bool

CompareChecksum check the publick-key with arbitrary given checksum, it will return true if the checksum matches and false otherwise.

func (PublicKey) CompareSignature

func (pk PublicKey) CompareSignature(message, sig []byte) bool

CompareSignature checks the autencity of the signature based on public-key, it returns false if is wrong.

func (*PublicKey) CreateAddress

func (pk *PublicKey) CreateAddress() Address

CreateAddress creates the encoded address using the public-key. It returns the address (with identifier, public-key and checksum) as string, encoded with base32.

func (PublicKey) CreateChecksum

func (pk PublicKey) CreateChecksum() []byte

Checksum creates the checksum for given public-key, it returns the checksum in byte format.

func (PublicKey) MarshalJSON

func (d PublicKey) MarshalJSON() ([]byte, error)

func (*PublicKey) UnmarshalJSON

func (d *PublicKey) UnmarshalJSON(data []byte) (err error)

type SecretKey

type SecretKey []byte

func (SecretKey) CreateSignature

func (sk SecretKey) CreateSignature(message []byte) ([]byte, error)

CreateSignature signs the message with the private-key. It return the signature.

func (SecretKey) PublicKey

func (sk SecretKey) PublicKey() (PublicKey, error)

PublicKeyFromSecretKey extract the Ed25519 public-key from the secret key and return the public-key.

type Seed

type Seed []byte

func (*Seed) CreateKeyPair

func (s *Seed) CreateKeyPair(coin Currency, index uint32) (PublicKey, SecretKey, error)

CreateKeyPair creates the public-key and secret-key using the given currency and index.

type SeedFY

type SeedFY struct {
	Version uint8
	Type    uint8
	Time    uint8
	Memory  uint8
	Thread  uint8
	Salt    []byte
}

func NewSeedFY

func NewSeedFY() (sf SeedFY, err error)

NewSeedFY generate the SeedFY, which is the random salt and the default computational cost parameters used in the Argon2id derivation in combination with the password.

func ReadSeedFY

func ReadSeedFY(s string) (sf SeedFY, err error)

ReadSeedFY act like to NewSeedFY, however it creates the struct based on the given hex-encoded SeedFY.

func (*SeedFY) Encode

func (sf *SeedFY) Encode() (string, error)

Encode will return the hexadecimal representation of the given SeedFY.

func (*SeedFY) IsValid

func (sf *SeedFY) IsValid() (r bool)

IsValid will return false if the SeedFY is not supported or don't have enough seed-length

func (*SeedFY) RecoverSeed

func (sf *SeedFY) RecoverSeed(password string, additionaldata []byte) Seed

RecoverSeedFromSeedFY returns the Seed based on given password and hex-encoded SeedFY. SEEDFY: [version][type]time[memory][thread][salt]

Jump to

Keyboard shortcuts

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