types

package
v0.0.0-...-6d5dda5 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 28 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// MaxAddrLen is the maximum allowed length (in bytes) for an address.
	MaxAddrLen = 255

	StratosBech32Prefix = "st"
	// PrefixPublic is the prefix for public keys
	PrefixPublic = "pub"
	// PrefixSds is the prefix for sds keys
	PrefixSds = "sds"

	// WalletAddressPrefix defines the Bech32 prefix of an account's address (st)
	WalletAddressPrefix = StratosBech32Prefix
	// WalletPubKeyPrefix defines the Bech32 prefix of an account's public key (stpub)
	WalletPubKeyPrefix = StratosBech32Prefix + PrefixPublic
	// P2PPubkeyPrefix defines the Bech32 prefix of an sds account's public key (stsdspub)
	P2PPubkeyPrefix = StratosBech32Prefix + PrefixSds + PrefixPublic
	// P2PAddressPrefix defines the Bech32 prefix of an sds account's address (stsds)
	P2PAddressPrefix = StratosBech32Prefix + PrefixSds
)

Bech32 conversion constants

View Source
const DATA_MESH_PREFIX = "sdm://"
View Source
const FileHandleLength = 88

FileHandleLength

View Source
const NetworkIDPrefix = "snode:"

Variables

View Source
var (
	ErrEmptyAddress = errors.New("address is empty")
)

Functions

func ChangePassword

func ChangePassword(walletAddress, dir, auth string, key *AccountKey) error

ChangePassword

func CreateP2PKey

func CreateP2PKey(dir, nickname, password, privateKeyHex string) (fwcryptotypes.Address, error)

CreateP2PKey creates a P2P key to be used by one of the SDS nodes, and saves the key data into the dir folder

func CreateP2PKeyFromHdPath

func CreateP2PKeyFromHdPath(dir, nickname, password, mnemonic, bip39Passphrase, hdPath string) (p2pAddress fwcryptotypes.Address, newlyCreated bool, err error)

CreateP2PKeyFromHdPath uses a wallet mnemonic to create a P2P key to be used by one of the SDS nodes, and saves the key data into the dir folder

func CreateWallet

func CreateWallet(dir, nickname, password, mnemonic, bip39Passphrase, hdPath string) (walletAddress fwcryptotypes.Address, newlyCreated bool, err error)

CreateWallet creates a new stratos-chain wallet with the given nickname and password, and saves the key data into the dir folder

func EncryptKey

func EncryptKey(key *AccountKey, auth string) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func GetFromBech32

func GetFromBech32(bech32str, prefix string) ([]byte, error)

GetFromBech32 decodes a bytestring from a Bech32 encoded string.

func KeyExists

func KeyExists(dir, address string) (bool, error)

KeyExists verifies whether the given key (wallet or p2p) exists in the dir folder

func NewMnemonic

func NewMnemonic() (string, error)

func P2PAddressBytesToBech32

func P2PAddressBytesToBech32(addr []byte) string

func P2PPubKeyFromBech32

func P2PPubKeyFromBech32(pubkeyStr string) (fwcryptotypes.PubKey, error)

P2PPubKeyFromBech32 returns an ed25519 SdsPublicKey from a Bech32 string.

func P2PPubKeyToBech32

func P2PPubKeyToBech32(pubkey fwcryptotypes.PubKey) (string, error)

P2PPubKeyToBech32 convert a SdsPublicKey to a Bech32 string.

func ParseFileHandle

func ParseFileHandle(handle string) (protocol, walletAddress, fileHash, fileName string, err error)

ParseFileHandle

func SetupWallet

func SetupWallet(accountDir, defaultHDPath, bip39Passphrase string, updateConfig func(walletKeyAddressString, password string) error) error

func VerifyAddressFormat

func VerifyAddressFormat(bz []byte) error

VerifyAddressFormat verifies that the provided bytes form a valid address according to the default address rules or a custom address verifier set by GetConfig().SetAddressVerifier(). TODO make an issue to get rid of global Config ref: https://github.com/cosmos/cosmos-sdk/issues/9690

func VerifyP2pAddrBytes

func VerifyP2pAddrBytes(p2pPubkey []byte, p2pAddr string) bool

VerifyP2pAddrBytes verify whether P2P address matches public key

func VerifyP2pSignBytes

func VerifyP2pSignBytes(p2pPubkey []byte, signature []byte, message []byte) bool

VerifyP2pSignBytes verify the signature made by P2P key

func VerifyWalletAddr

func VerifyWalletAddr(walletPubkey, walletAddr string) bool

func VerifyWalletAddrBytes

func VerifyWalletAddrBytes(walletPubkey []byte, walletAddr string) bool

func VerifyWalletSign

func VerifyWalletSign(walletPubkey, signature, message string) bool

VerifyWalletSign bech32 format of pubkey, the hex encoded signature, and the sign message

func VerifyWalletSignBytes

func VerifyWalletSignBytes(walletPubkey []byte, signature []byte, message string) bool

VerifyWalletSignBytes []byte version of VerifyWalletKey() for pubkey and signature format

func WalletAddressBytesToBech32

func WalletAddressBytesToBech32(addr []byte) string

func WalletPubKeyFromBech32

func WalletPubKeyFromBech32(pubkeyStr string) (fwcryptotypes.PubKey, error)

WalletPubKeyFromBech32 returns an secp256k1 AccPublicKey from a Bech32 string.

func WalletPubKeyToBech32

func WalletPubKeyToBech32(pubkey fwcryptotypes.PubKey) (string, error)

WalletPubKeyToBech32 convert a AccPublicKey to a Bech32 string.

func WriteKeyFile

func WriteKeyFile(file string, content []byte) error

Types

type AccountKey

type AccountKey struct {
	Id uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	Address fwcryptotypes.Address
	// The HD path to use to derive this key
	HdPath string
	// The mnemonic for the underlying HD wallet
	Mnemonic string
	// a nickname
	Name string
	// The bip39 passphrase for the underlying HD wallet
	Passphrase string
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey fwcryptotypes.PrivKey
}

func DecryptKey

func DecryptKey(keyjson []byte, auth string, isWallet bool) (*AccountKey, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

type Address

type Address interface {
	Equals(Address) bool
	Empty() bool
	Marshal() ([]byte, error)
	MarshalJSON() ([]byte, error)
	Bytes() []byte
	String() string
	Format(s fmt.State, verb rune)
	Hex() string
}

Address is a common interface for different types of addresses used by the SDK

type DataMeshId

type DataMeshId struct {
	Owner string
	Hash  string
}

func DataMeshIdFromString

func DataMeshIdFromString(idString string) (*DataMeshId, error)

func (DataMeshId) String

func (d DataMeshId) String() string

type KeyStorePassphrase

type KeyStorePassphrase struct {
	KeysDirPath string
	ScryptN     int
	ScryptP     int
}

func GetKeyStorePassphrase

func GetKeyStorePassphrase(keysDirPath string) KeyStorePassphrase

func (KeyStorePassphrase) StoreKey

func (ks KeyStorePassphrase) StoreKey(filename string, key *AccountKey, auth string) error

type NetworkID

type NetworkID struct {
	P2pAddress     string
	NetworkAddress string
}

func IDFromString

func IDFromString(idString string) (*NetworkID, error)

func (NetworkID) String

func (n NetworkID) String() string

type P2PAddress

type P2PAddress []byte

func P2PAddressFromBech32

func P2PAddressFromBech32(address string) (addr P2PAddress, err error)

P2PAddressFromBech32 creates an P2PAddress from a Bech32 string.

func P2PAddressFromHex

func P2PAddressFromHex(s string) P2PAddress

func (P2PAddress) Bytes

func (aa P2PAddress) Bytes() []byte

Bytes returns the raw address bytes.

func (P2PAddress) Empty

func (aa P2PAddress) Empty() bool

Empty Returns boolean for whether a P2PAddress is empty

func (P2PAddress) Equals

func (aa P2PAddress) Equals(aa2 Address) bool

Equals Returns boolean for whether two P2PAddress are Equal

func (P2PAddress) Format

func (aa P2PAddress) Format(s fmt.State, verb rune)

Format implements the fmt.Formatter interface.

func (P2PAddress) Hex

func (aa P2PAddress) Hex() string

func (P2PAddress) Marshal

func (aa P2PAddress) Marshal() ([]byte, error)

Marshal returns the raw address bytes. It is needed for protobuf compatibility.

func (P2PAddress) MarshalJSON

func (aa P2PAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON using Bech32.

func (P2PAddress) MarshalYAML

func (aa P2PAddress) MarshalYAML() (interface{}, error)

MarshalYAML marshals to YAML using Bech32.

func (P2PAddress) String

func (aa P2PAddress) String() string

String implements the Stringer interface.

func (*P2PAddress) Unmarshal

func (aa *P2PAddress) Unmarshal(data []byte) error

Unmarshal sets the address to the given data. It is needed for protobuf compatibility.

func (*P2PAddress) UnmarshalJSON

func (aa *P2PAddress) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals from JSON assuming Bech32 encoding.

type WalletAddress

type WalletAddress []byte

WalletAddress a wrapper around bytes meant to represent an account address. When marshaled to a string or JSON, it uses Bech32.

func WalletAddressFromBech32

func WalletAddressFromBech32(address string) (addr WalletAddress, err error)

WalletAddressFromBech32 creates an WalletAddress from a Bech32 string.

func WalletAddressFromHex

func WalletAddressFromHex(s string) WalletAddress

func (WalletAddress) Bytes

func (aa WalletAddress) Bytes() []byte

Bytes returns the raw address bytes.

func (WalletAddress) Empty

func (aa WalletAddress) Empty() bool

Returns boolean for whether an WalletAddress is empty

func (WalletAddress) Equals

func (aa WalletAddress) Equals(aa2 Address) bool

Returns boolean for whether two AccAddresses are Equal

func (WalletAddress) Format

func (aa WalletAddress) Format(s fmt.State, verb rune)

func (WalletAddress) Hex

func (aa WalletAddress) Hex() string

func (WalletAddress) Marshal

func (aa WalletAddress) Marshal() ([]byte, error)

Marshal returns the raw address bytes. It is needed for protobuf compatibility.

func (WalletAddress) MarshalJSON

func (aa WalletAddress) MarshalJSON() ([]byte, error)

MarshalJSON marshals to JSON using Bech32.

func (WalletAddress) MarshalYAML

func (aa WalletAddress) MarshalYAML() (interface{}, error)

MarshalYAML marshals to YAML using Bech32.

func (WalletAddress) String

func (aa WalletAddress) String() string

String implements the Stringer interface.

func (*WalletAddress) Unmarshal

func (aa *WalletAddress) Unmarshal(data []byte) error

Unmarshal sets the address to the given data. It is needed for protobuf compatibility.

func (*WalletAddress) UnmarshalJSON

func (aa *WalletAddress) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals from JSON assuming Bech32 encoding.

func (*WalletAddress) UnmarshalYAML

func (aa *WalletAddress) UnmarshalYAML(data []byte) error

UnmarshalYAML unmarshals from JSON assuming Bech32 encoding.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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