account

package
v0.0.0-...-d9e9996 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// 不同语言标准不一样,这里用const直接定义值还是好一些
	// 低
	StrengthEasy = 1
	// 中
	StrengthMiddle = 2
	// 高
	StrengthHard = 3
)

定义助记词的强度类型

View Source
const (
	// 不同语言标准不一样,这里用const直接定义值还是好一些
	// 美国Federal Information Processing Standards的椭圆曲线
	EccFIPS = iota
	// 国密椭圆曲线
	EccGM
)

定义密码算法的类型

Variables

View Source
var (
	// Last4BitsMask 1111 - 11个1,当一个大的bigint和它进行“And”比特运算的时候,就会获得大的bigint最右边4位的比特位
	Last4BitsMask = big.NewInt(15)
	// Shift4BitsFactor 10000 - 乘以这个带有4个0的数等于左移4个比特位,除以这个带有4个0的数等于右移4个比特位,
	Shift4BitsFactor = big.NewInt(16)
)
View Source
var (
	// ErrStrengthNotSupported : 助记词的强度暂未被支持
	// Strength required for generating Mnemonic has not been supported yet.
	ErrStrengthNotSupported = fmt.Errorf("This strength has not been supported yet")

	// ErrCryptographyNotSupported : 密码学算法暂未被支持
	// Cryptography required for generating Mnemonic has not been supported yet.
	ErrCryptographyNotSupported = fmt.Errorf("This cryptography has not been supported yet")

	// ErrReservedTypeNotSupported : 语言暂未被支持
	// ReservedType required for generating Mnemonic has not been supported yet.
	ErrReservedTypeNotSupported = fmt.Errorf("This ReservedType has not been supported yet")
)

Functions

func CheckAddressFormat

func CheckAddressFormat(address string) (bool, uint8)

CheckAddressFormat 验证钱包地址是否是合法的格式 如果成功,返回true和对应的密码学标记位;如果失败,返回false和默认的密码学标记位0

func ExportNewAccount

func ExportNewAccount(path string, privateKey *ecdsa.PrivateKey) error

ExportNewAccount creates new account and export to local file

func ExportNewAccountWithMnemonic

func ExportNewAccountWithMnemonic(path string, language int, strength uint8, cryptography uint8) error

ExportNewAccountWithMnemonic create new account with mnemonic and export to local file

func GetAccInfo

func GetAccInfo() ([]byte, []byte, []byte, error)

GetAccInfo get account info from local data path TODO: 后续要废弃,已过时的方法

func GetAccInfoFromFile

func GetAccInfoFromFile(filename string) ([]byte, []byte, []byte, error)

GetAccInfoFromFile get account info from local file

func GetAddressFromPublicKey

func GetAddressFromPublicKey(pub *ecdsa.PublicKey) (string, error)

GetAddressFromPublicKey 返回33位长度的地址

func GetCryptoByteFromMnemonic

func GetCryptoByteFromMnemonic(mnemonic string, language int) (uint8, error)

GetCryptoByteFromMnemonic get crypto byte from mnemonic

func GetEcdsaPrivateKeyFromFile

func GetEcdsaPrivateKeyFromFile(filename string) (*ecdsa.PrivateKey, error)

GetEcdsaPrivateKeyFromFile get ECDSA private key from local file

func GetEcdsaPrivateKeyFromJSON

func GetEcdsaPrivateKeyFromJSON(jsonContent []byte) (*ecdsa.PrivateKey, error)

GetEcdsaPrivateKeyFromJSON get ECDSA private key from json encoded data

func GetEcdsaPrivateKeyJSONFormat

func GetEcdsaPrivateKeyJSONFormat(k *ecdsa.PrivateKey) (string, error)

GetEcdsaPrivateKeyJSONFormat 获得私钥所对应的的json

func GetEcdsaPublicKeyFromFile

func GetEcdsaPublicKeyFromFile(filename string) (*ecdsa.PublicKey, error)

GetEcdsaPublicKeyFromFile get ECDSA public key from local file

func GetEcdsaPublicKeyFromJSON

func GetEcdsaPublicKeyFromJSON(jsonContent []byte) (*ecdsa.PublicKey, error)

GetEcdsaPublicKeyFromJSON get ECDSA public key from json encoded data

func GetEcdsaPublicKeyJSONFormat

func GetEcdsaPublicKeyJSONFormat(k *ecdsa.PrivateKey) (string, error)

GetEcdsaPublicKeyJSONFormat 获得公钥所对应的的json

func VerifyAddressUsingPublicKey

func VerifyAddressUsingPublicKey(address string, pub *ecdsa.PublicKey) (bool, uint8)

VerifyAddressUsingPublicKey 验证钱包地址是否和指定的公钥match 如果成功,返回true和对应的密码学标记位;如果失败,返回false和默认的密码学标记位0

Types

type ECDSAAccount

type ECDSAAccount struct {
	EntropyByte    []byte
	Mnemonic       string
	JSONPrivateKey string
	JSONPublicKey  string
	Address        string
}

ECDSAAccount 助记词、私钥的json、公钥的json、钱包地址

func CreateNewAccountWithMnemonic

func CreateNewAccountWithMnemonic(language int, strength uint8, cryptography uint8) (*ECDSAAccount, error)

CreateNewAccountWithMnemonic 参数字段:版本号、语言、强度 返回的字段:助记词、私钥的json、公钥的json、钱包地址、错误信息

func GenerateAccountByMnemonic

func GenerateAccountByMnemonic(mnemonic string, language int) (*ECDSAAccount, error)

GenerateAccountByMnemonic 通过助记词来产生/恢复钱包账户 这里不应该再需要知道指定曲线了,也不需要指定地址版本了,这个功能应该由助记词中的标记位来判断

type ECDSAAccountToCloud

type ECDSAAccountToCloud struct {
	Address                 string
	JSONEncryptedPrivateKey string
	EncryptedMnemonic       string
	Password                string
}

ECDSAAccountToCloud 钱包地址、被加密后的私钥、被加密后的助记词、支付密码的明文

type ECDSAInfo

type ECDSAInfo struct {
	EntropyByte []byte
	Mnemonic    string
	Address     string
}

ECDSAInfo 助记词、随机字节数组、钱包地址

type ECDSAPrivateKey

type ECDSAPrivateKey struct {
	Curvname string
	X, Y, D  *big.Int
}

ECDSAPrivateKey 通过这个数据结构来生成私钥的json

type ECDSAPublicKey

type ECDSAPublicKey struct {
	Curvname string
	X, Y     *big.Int
}

ECDSAPublicKey 通过这个数据结构来生成公钥的json

Jump to

Keyboard shortcuts

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