Documentation ¶
Index ¶
- Constants
- Variables
- func ChangePassword(walletAddress, dir, auth string, key *AccountKey) error
- func CheckIpfsCid(cid string) error
- func CreateP2PKey(dir, nickname, password, privateKeyHex string) (fwcryptotypes.Address, error)
- func CreateP2PKeyFromHdPath(dir, nickname, password, mnemonic, bip39Passphrase, hdPath string) (p2pAddress fwcryptotypes.Address, newlyCreated bool, err error)
- func CreateWallet(dir, nickname, password, mnemonic, bip39Passphrase, hdPath string) (walletAddress fwcryptotypes.Address, newlyCreated bool, err error)
- func EncryptKey(key *AccountKey, auth string) ([]byte, error)
- func GenerateNormalShareLinkV2() string
- func GenerateP2pKeyFromHdPath(mnemonic, bip39Passphrase, hdPath string) (*fwed25519.PrivKey, error)
- func GetFromBech32(bech32str, prefix string) ([]byte, error)
- func KeyExists(dir, address string) (bool, error)
- func NewMnemonic() (string, error)
- func P2PAddressBytesToBech32(addr []byte) string
- func P2PPubKeyFromBech32(pubkeyStr string) (fwcryptotypes.PubKey, error)
- func P2PPubKeyToBech32(pubkey fwcryptotypes.PubKey) (string, error)
- func ParseFileHandle(handle string) (protocol, walletAddress, fileHash, fileName string, err error)
- func SetupWallet(accountDir, defaultHDPath, bip39Passphrase string, ...) error
- func VerifyAddressFormat(bz []byte) error
- func VerifyP2pAddrBytes(p2pPubkey []byte, p2pAddr string) bool
- func VerifyP2pSignBytes(p2pPubkey []byte, signature []byte, message []byte) bool
- func VerifyWalletAddr(walletPubkey, walletAddr string) bool
- func VerifyWalletAddrBytes(walletPubkey []byte, walletAddr string) bool
- func VerifyWalletSign(walletPubkey, signature, message string) bool
- func VerifyWalletSignBytes(walletPubkey []byte, signature []byte, message string) bool
- func WalletAddressBytesToBech32(addr []byte) string
- func WalletPubKeyFromBech32(pubkeyStr string) (fwcryptotypes.PubKey, error)
- func WalletPubKeyToBech32(pubkey fwcryptotypes.PubKey) (string, error)
- func WriteKeyFile(file string, content []byte) error
- type AccountKey
- type Address
- type DataMeshId
- type KeyStorePassphrase
- type NetworkID
- type P2PAddress
- func (aa P2PAddress) Bytes() []byte
- func (aa P2PAddress) Empty() bool
- func (aa P2PAddress) Equals(aa2 Address) bool
- func (aa P2PAddress) Format(s fmt.State, verb rune)
- func (aa P2PAddress) Hex() string
- func (aa P2PAddress) Marshal() ([]byte, error)
- func (aa P2PAddress) MarshalJSON() ([]byte, error)
- func (aa P2PAddress) MarshalYAML() (interface{}, error)
- func (aa P2PAddress) String() string
- func (aa *P2PAddress) Unmarshal(data []byte) error
- func (aa *P2PAddress) UnmarshalJSON(data []byte) error
- type ShareDataMeshId
- type WalletAddress
- func (aa WalletAddress) Bytes() []byte
- func (aa WalletAddress) Empty() bool
- func (aa WalletAddress) Equals(aa2 Address) bool
- func (aa WalletAddress) Format(s fmt.State, verb rune)
- func (aa WalletAddress) Hex() string
- func (aa WalletAddress) Marshal() ([]byte, error)
- func (aa WalletAddress) MarshalJSON() ([]byte, error)
- func (aa WalletAddress) MarshalYAML() (interface{}, error)
- func (aa WalletAddress) String() string
- func (aa *WalletAddress) Unmarshal(data []byte) error
- func (aa *WalletAddress) UnmarshalJSON(data []byte) error
- func (aa *WalletAddress) UnmarshalYAML(data []byte) error
Constants ¶
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
const ( DATA_MESH_PROTOCOL = "sdm://" FileHandleLength = 88 SHARED_DATA_MESH_PROTOCOL = "sds://" NormalShareLinkV2Length = 16 + 1*(1+10) + 1 + 6 NormalShareLinkV1Length = 16 + 0*(1*10) + 1 + 6 )
const NetworkIDPrefix = "snode:"
Variables ¶
var (
ErrEmptyAddress = errors.New("address is empty")
)
Functions ¶
func ChangePassword ¶
func ChangePassword(walletAddress, dir, auth string, key *AccountKey) error
ChangePassword
func CheckIpfsCid ¶
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 GenerateNormalShareLinkV2 ¶
func GenerateNormalShareLinkV2() string
func GenerateP2pKeyFromHdPath ¶
GenerateP2pKeyFromHdPath uses a wallet mnemonic to create a P2P key, but doesn't store it anywhere
func GetFromBech32 ¶
GetFromBech32 decodes a bytestring from a Bech32 encoded string.
func NewMnemonic ¶
func P2PAddressBytesToBech32 ¶
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 ¶
ParseFileHandle
func SetupWallet ¶
func VerifyAddressFormat ¶
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 ¶
VerifyP2pAddrBytes verify whether P2P address matches public key
func VerifyP2pSignBytes ¶
VerifyP2pSignBytes verify the signature made by P2P key
func VerifyWalletAddr ¶
func VerifyWalletAddrBytes ¶
func VerifyWalletSign ¶
VerifyWalletSign bech32 format of pubkey, the hex encoded signature, and the sign message
func VerifyWalletSignBytes ¶
VerifyWalletSignBytes []byte version of VerifyWalletKey() for pubkey and signature format
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 ¶
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 ¶
func DataMeshIdFromString ¶
func DataMeshIdFromString(idString string) (*DataMeshId, error)
func (DataMeshId) String ¶
func (d DataMeshId) String() string
type KeyStorePassphrase ¶
func GetKeyStorePassphrase ¶
func GetKeyStorePassphrase(keysDirPath string) KeyStorePassphrase
func (KeyStorePassphrase) StoreKey ¶
func (ks KeyStorePassphrase) StoreKey(filename string, key *AccountKey, auth string) error
type NetworkID ¶
func IDFromString ¶
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) 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 ShareDataMeshId ¶
type ShareDataMeshId struct {}
func ParseShareLink ¶
func ParseShareLink(getShareString string) (*ShareDataMeshId, error)
func SetShareLink ¶
func SetShareLink(shareId, randCode string) *ShareDataMeshId
func (ShareDataMeshId) Parse ¶
func (s ShareDataMeshId) Parse() (shareId, randCode string)
func (ShareDataMeshId) String ¶
func (s ShareDataMeshId) String() string
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) 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.