Documentation ¶
Index ¶
- Constants
- Variables
- func BIP44Account() uint32
- func BIP44HardenedAccountIndex(hai uint32) uint32
- func BIP44HardenedChain() uint32
- func BIP44Purpose() uint32
- func BIP44SpacemeshCoinType() uint32
- func HDPathToString(path HDPath) string
- func IsPathCompletelyHardened(path HDPath) bool
- func PubkeyToAddress(pubkey []byte, hrp string) string
- type EDKeyPair
- type EncryptedWalletFile
- type HDPath
- func (p *HDPath) Account() uint32
- func (p *HDPath) Chain() uint32
- func (p *HDPath) CoinType() uint32
- func (p *HDPath) Extend(idx uint32) HDPath
- func (p *HDPath) Index() uint32
- func (p *HDPath) MarshalJSON() ([]byte, error)
- func (p *HDPath) Purpose() uint32
- func (p *HDPath) String() string
- func (p *HDPath) UnmarshalJSON(data []byte) (err error)
- type PrivateKey
- type PublicKey
- type Wallet
- type WalletKey
- type WalletKeyOpt
Constants ¶
const ( HDPurposeSegment = 0 HDCoinTypeSegment = 1 HDAccountSegment = 2 HDChainSegment = 3 HDIndexSegment = 4 )
const ( Pbkdf2Iterations = 210000 Pbkdf2Dklen = 256 Pbkdf2SaltBytesLen = 16 )
https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
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
const EncKeyLen = 32
Variables ¶
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 ¶
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 ¶
HDPathToString converts a BIP44 HD path to a string of the form "m/44'/540'/account'/chain'/address_index'".
func PubkeyToAddress ¶ added in v1.0.10
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 NewMasterKeyPairFromLedger ¶ added in v1.0.5
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 ¶
StringToHDPath converts a BIP44 HD path string of the form (m/44'/540'/account'/chain'/address_index') to its uint32 slice representation.
func (*HDPath) MarshalJSON ¶
func (*HDPath) UnmarshalJSON ¶
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 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 NewMultiWalletFromMnemonic ¶ added in v1.0.2
func NewMultiWalletRandomMnemonic ¶ added in v1.0.2
type WalletKey ¶
type WalletKey struct {
// contains filtered or unexported fields
}
func NewKey ¶
func NewKey(opts ...WalletKeyOpt) WalletKey
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