Documentation ¶
Index ¶
- Constants
- Variables
- func CheckAddressFormat(address string) (bool, uint8)
- func ExportNewAccount(path string, privateKey *ecdsa.PrivateKey) error
- func ExportNewAccountWithMnemonic(path string, language int, strength uint8, cryptography uint8) error
- func GetAccInfo() ([]byte, []byte, []byte, error)
- func GetAccInfoFromFile(filename string) ([]byte, []byte, []byte, error)
- func GetAddressFromPublicKey(pub *ecdsa.PublicKey) (string, error)
- func GetCryptoByteFromMnemonic(mnemonic string, language int) (uint8, error)
- func GetEcdsaPrivateKeyFromFile(filename string) (*ecdsa.PrivateKey, error)
- func GetEcdsaPrivateKeyFromJSON(jsonContent []byte) (*ecdsa.PrivateKey, error)
- func GetEcdsaPrivateKeyJSONFormat(k *ecdsa.PrivateKey) (string, error)
- func GetEcdsaPublicKeyFromFile(filename string) (*ecdsa.PublicKey, error)
- func GetEcdsaPublicKeyFromJSON(jsonContent []byte) (*ecdsa.PublicKey, error)
- func GetEcdsaPublicKeyJSONFormat(k *ecdsa.PrivateKey) (string, error)
- func VerifyAddressUsingPublicKey(address string, pub *ecdsa.PublicKey) (bool, uint8)
- type ECDSAAccount
- type ECDSAAccountToCloud
- type ECDSAInfo
- type ECDSAPrivateKey
- type ECDSAPublicKey
Constants ¶
const ( // 不同语言标准不一样,这里用const直接定义值还是好一些 // 低 StrengthEasy = 1 // 中 StrengthMiddle = 2 // 高 StrengthHard = 3 )
定义助记词的强度类型
const ( // 不同语言标准不一样,这里用const直接定义值还是好一些 // 美国Federal Information Processing Standards的椭圆曲线 EccFIPS = iota // 国密椭圆曲线 EccGM )
定义密码算法的类型
Variables ¶
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) )
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 ¶
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 ¶
GetAccInfo get account info from local data path TODO: 后续要废弃,已过时的方法
func GetAccInfoFromFile ¶
GetAccInfoFromFile get account info from local file
func GetAddressFromPublicKey ¶
GetAddressFromPublicKey 返回33位长度的地址
func GetCryptoByteFromMnemonic ¶
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 ¶
GetEcdsaPublicKeyFromFile get ECDSA public key from local file
func GetEcdsaPublicKeyFromJSON ¶
GetEcdsaPublicKeyFromJSON get ECDSA public key from json encoded data
func GetEcdsaPublicKeyJSONFormat ¶
func GetEcdsaPublicKeyJSONFormat(k *ecdsa.PrivateKey) (string, error)
GetEcdsaPublicKeyJSONFormat 获得公钥所对应的的json
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 ECDSAPrivateKey ¶
ECDSAPrivateKey 通过这个数据结构来生成私钥的json
type ECDSAPublicKey ¶
ECDSAPublicKey 通过这个数据结构来生成公钥的json