wallet

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HDPurposeSegment  = 0
	HDCoinTypeSegment = 1
	HDAccountSegment  = 2
	HDChainSegment    = 3
	HDIndexSegment    = 4
)
View Source
const (
	Pbkdf2Iterations   = 210000
	Pbkdf2Dklen        = 256
	Pbkdf2SaltBytesLen = 16
)

https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2

View Source
const BIP32HardenedKeyStart uint32 = 0x80000000

BIP32HardenedKeyStart: keys with index >= this must be hardened as per BIP32. https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#extended-keys

View Source
const EncKeyLen = 32

Variables

View Source
var Pbkdf2HashFunc = sha512.New

Functions

func BIP44Account

func BIP44Account() uint32

After the coin type comes the account (m/44'/540'/account') For now we only support account 0'.

func BIP44HardenedAccountIndex

func BIP44HardenedAccountIndex(hai uint32) uint32

After the Hardened Chain level comes the address indices, as of now, we don't support un-hardened derivation so we'll continue our deviation from the spec here. All addresses will be hardened. (m/44'/540'/account'/chain'/address_index').

func BIP44HardenedChain

func BIP44HardenedChain() uint32

After the account comes the change level, BUT as of now, we don't support un-hardened derivation so we'll be deviating from the spec here. We'll be continuing with hardened derivation. We call it the "hardened chain" level and not the "change" level because these chains don't support "change" functionality in the way that Bitcoin does. Spacemesh isn't a UTXO-based system, so there's no concept of "change". We're keeping the name "chain" because it's a more general term that can be used to describe a sequence of addresses that are related to each other even after the account level. (m/44'/540'/account'/chain') For now we only support "chain" 0. We may want to use a different chain for testnet.

func BIP44Purpose

func BIP44Purpose() uint32

Root of the path is m/purpose' (m/44') https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#purpose We use this to indicate that we're using the BIP44 hierarchy.

func BIP44SpacemeshCoinType

func BIP44SpacemeshCoinType() uint32

After the purpose comes the coin type (m/44'/540') https://github.com/satoshilabs/slips/blob/master/slip-0044.md?plain=1#L571

func HDPathToString

func HDPathToString(path HDPath) string

HDPathToString converts a BIP44 HD path to a string of the form "m/44'/540'/account'/chain'/address_index'".

func IsPathCompletelyHardened

func IsPathCompletelyHardened(path HDPath) bool

func PubkeyToAddress added in v1.0.10

func PubkeyToAddress(pubkey []byte, hrp string) string

Types

type EDKeyPair

type EDKeyPair struct {
	DisplayName string     `json:"displayName"`
	Created     string     `json:"created"`
	Path        HDPath     `json:"path"`
	Public      PublicKey  `json:"publicKey"`
	Private     PrivateKey `json:"secretKey"`
	KeyType     keyType    `json:"keyType"`
}

func NewMasterKeyPair

func NewMasterKeyPair(seed []byte) (*EDKeyPair, error)

func NewMasterKeyPairFromLedger added in v1.0.5

func NewMasterKeyPairFromLedger() (*EDKeyPair, error)

func (*EDKeyPair) NewChildKeyPair added in v1.0.2

func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, error)

type EncryptedWalletFile

type EncryptedWalletFile struct {
	Meta    walletMetadata         `json:"meta"`
	Secrets walletSecretsEncrypted `json:"crypto"`
}

EncryptedWalletFile is the encrypted representation of the wallet on the filesystem.

type HDPath

type HDPath []uint32

func DefaultPath added in v1.0.2

func DefaultPath() HDPath

func StringToHDPath

func StringToHDPath(s string) (HDPath, error)

StringToHDPath converts a BIP44 HD path string of the form (m/44'/540'/account'/chain'/address_index') to its uint32 slice representation.

func (*HDPath) Account

func (p *HDPath) Account() uint32

func (*HDPath) Chain

func (p *HDPath) Chain() uint32

func (*HDPath) CoinType

func (p *HDPath) CoinType() uint32

func (*HDPath) Extend added in v1.0.2

func (p *HDPath) Extend(idx uint32) HDPath

func (*HDPath) Index

func (p *HDPath) Index() uint32

func (*HDPath) MarshalJSON

func (p *HDPath) MarshalJSON() ([]byte, error)

func (*HDPath) Purpose

func (p *HDPath) Purpose() uint32

func (*HDPath) String

func (p *HDPath) String() string

func (*HDPath) UnmarshalJSON

func (p *HDPath) UnmarshalJSON(data []byte) (err error)

type PrivateKey

type PrivateKey ed25519.PrivateKey

func (*PrivateKey) MarshalJSON

func (k *PrivateKey) MarshalJSON() ([]byte, error)

func (*PrivateKey) UnmarshalJSON

func (k *PrivateKey) UnmarshalJSON(data []byte) (err error)

type PublicKey

type PublicKey ed25519.PublicKey

func (*PublicKey) MarshalJSON

func (k *PublicKey) MarshalJSON() ([]byte, error)

func (*PublicKey) UnmarshalJSON

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

type Wallet

type Wallet struct {
	// keystore string
	// password string
	// unlocked bool
	Meta    walletMetadata `json:"meta"`
	Secrets walletSecrets  `json:"crypto"`
}

Wallet is the basic data structure.

func NewMultiWalletFromLedger added in v1.0.5

func NewMultiWalletFromLedger(n int) (*Wallet, error)

func NewMultiWalletFromMnemonic added in v1.0.2

func NewMultiWalletFromMnemonic(m string, n int) (*Wallet, error)

func NewMultiWalletRandomMnemonic added in v1.0.2

func NewMultiWalletRandomMnemonic(n int) (*Wallet, error)

func (*Wallet) Mnemonic added in v1.0.2

func (w *Wallet) Mnemonic() string

type WalletKey

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

func NewKey

func NewKey(opts ...WalletKeyOpt) WalletKey

func (*WalletKey) Export

func (k *WalletKey) Export(file io.Writer, w *Wallet) (err error)

func (*WalletKey) Open

func (k *WalletKey) Open(file io.Reader, debugMode bool) (*Wallet, error)

type WalletKeyOpt

type WalletKeyOpt func(*WalletKey)

func WithIterations

func WithIterations(iterations int) WalletKeyOpt

func WithPasswordOnly

func WithPasswordOnly(password []byte) WalletKeyOpt

WithPasswordOnly is used for reading a stored file. The stored wallet file contains a salt, so it does not need to be set before reading the file.

func WithPbkdf2Password

func WithPbkdf2Password(password []byte) WalletKeyOpt

func WithRandomSalt

func WithRandomSalt() WalletKeyOpt

func WithSalt

func WithSalt(salt [Pbkdf2SaltBytesLen]byte) WalletKeyOpt

Jump to

Keyboard shortcuts

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