Documentation ¶
Overview ¶
@Title @Description @Author Niels 2020/9/10
@Title @Description @Author Niels 2020/9/10
- MIT License
- Copyright (c) 2019-2020 niels.wang
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in all
- copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- SOFTWARE.
Index ¶
- Constants
- Variables
- type Account
- type AccountSDK
- type KeyStore
- type NerveAccount
- func (a *NerveAccount) GetAddr() string
- func (a *NerveAccount) GetAddrBytes() []byte
- func (a *NerveAccount) GetChainId() uint16
- func (a *NerveAccount) GetPrefix() string
- func (a *NerveAccount) GetPriKey() []byte
- func (a *NerveAccount) GetPriKeyHex() string
- func (a *NerveAccount) GetPubKey() []byte
- func (a *NerveAccount) GetPubKeyHex() string
- func (a *NerveAccount) GetType() uint8
- type NerveAccountSDK
- func (sdk *NerveAccountSDK) CreateAccount() (Account, error)
- func (sdk *NerveAccountSDK) CreateKeyStore(account Account, password string) (*KeyStore, error)
- func (sdk *NerveAccountSDK) CreateKeyStoreByPrikey(prikey []byte, password string) (*KeyStore, error)
- func (sdk *NerveAccountSDK) GetAccountByEckey(ec *eckey.EcKey) (Account, error)
- func (sdk *NerveAccountSDK) GetAddressByPubBytes(bytes []byte, accountType uint8) []byte
- func (sdk *NerveAccountSDK) GetBytesAddress(address string) ([]byte, error)
- func (sdk *NerveAccountSDK) GetStringAddress(bytes []byte) string
- func (sdk *NerveAccountSDK) ImportAccount(prikey []byte) (Account, error)
- func (sdk *NerveAccountSDK) ImportFromKeyStore(keyStoreJson string, password string) (account Account, err error)
- func (sdk *NerveAccountSDK) PasswordCheck(password string) bool
- func (sdk *NerveAccountSDK) Sign(account Account, data []byte) ([]byte, error)
- func (sdk *NerveAccountSDK) ValidAddress(address string) error
- func (sdk *NerveAccountSDK) Verify(pubkey []byte, data []byte, signResult []byte) bool
Examples ¶
Constants ¶
View Source
const ( //默认的地址字节长度 AddressBytesLength = 23 //默认账户类型 NormalAccountType = uint8(1) //合约账户类型 ContractAccountType = uint8(2) //多签账户类型 P2SHAccountType = uint8(3) )
Variables ¶
View Source
var PrefixTable = [...]string{"", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
用于前缀和实际地址的分隔符
Functions ¶
This section is empty.
Types ¶
type AccountSDK ¶
type AccountSDK interface { CreateAccount() (Account, error) ImportAccount(prikey []byte) (Account, error) ValidAddress(address string) error ImportFromKeyStore(keyStoreJson string, password string) (Account, error) CreateKeyStoreByPrikey(prikey []byte, password string) (*KeyStore, error) CreateKeyStore(account Account, password string) (*KeyStore, error) GetAddressByPubBytes(bytes []byte, accountType uint8) []byte GetAccountByEckey(ec *eckey.EcKey) (Account, error) GetStringAddress(bytes []byte) string GetBytesAddress(address string) ([]byte, error) Sign(account Account, data []byte) ([]byte, error) Verify(pubkey []byte, data []byte, signResult []byte) bool }
func GetAccountSDK ¶
func GetAccountSDK(chainId uint16, prefix string) AccountSDK
type KeyStore ¶
type KeyStore struct { //地址 Address string `json:"address"` //使用密码对私钥进行加密后,得到的密文 EncryptedPrivateKey string `json:"encryptedPrivateKey"` //公钥Hex Pubkey string `json:"pubkey"` // contains filtered or unexported fields }
keystore 结构,所有NULS体系的keystore都遵循该基本协议 todo 下一个版本增加加密算法的说明和算法参数
type NerveAccount ¶
type NerveAccount struct {
// contains filtered or unexported fields
}
func (*NerveAccount) GetAddr ¶
func (a *NerveAccount) GetAddr() string
func (*NerveAccount) GetAddrBytes ¶
func (a *NerveAccount) GetAddrBytes() []byte
func (*NerveAccount) GetChainId ¶
func (a *NerveAccount) GetChainId() uint16
func (*NerveAccount) GetPrefix ¶
func (a *NerveAccount) GetPrefix() string
func (*NerveAccount) GetPriKey ¶
func (a *NerveAccount) GetPriKey() []byte
func (*NerveAccount) GetPriKeyHex ¶
func (a *NerveAccount) GetPriKeyHex() string
func (*NerveAccount) GetPubKey ¶
func (a *NerveAccount) GetPubKey() []byte
func (*NerveAccount) GetPubKeyHex ¶
func (a *NerveAccount) GetPubKeyHex() string
func (*NerveAccount) GetType ¶
func (a *NerveAccount) GetType() uint8
type NerveAccountSDK ¶
type NerveAccountSDK struct {
// contains filtered or unexported fields
}
func (*NerveAccountSDK) CreateAccount ¶
func (sdk *NerveAccountSDK) CreateAccount() (Account, error)
Example ¶
创建账户,支持NULS生态内任意区块链的账户创建
chainId := uint16(9) //Nerve主网为:9,测试网为:5,NULS主网为:1,NULS测试网为:2 prefix := "NERVE" //Nerve主网为:NERVE,测试网为:TNVT,NULS主网为:NULS,NULS测试网为:tNULS sdk := GetAccountSDK(chainId, prefix) //创建账户 account, err := sdk.CreateAccount() if nil != err { fmt.Println(err.Error()) return } fmt.Println("Address:", account.GetAddr()) fmt.Println("Private Key:", account.GetPriKeyHex()) fmt.Println("Public Key:", account.GetPubKeyHex()) fmt.Println("Chain ID:", account.GetChainId())
Output:
func (*NerveAccountSDK) CreateKeyStore ¶
func (sdk *NerveAccountSDK) CreateKeyStore(account Account, password string) (*KeyStore, error)
func (*NerveAccountSDK) CreateKeyStoreByPrikey ¶
func (sdk *NerveAccountSDK) CreateKeyStoreByPrikey(prikey []byte, password string) (*KeyStore, error)
func (*NerveAccountSDK) GetAccountByEckey ¶
func (sdk *NerveAccountSDK) GetAccountByEckey(ec *eckey.EcKey) (Account, error)
根据EcKey生成账户
func (*NerveAccountSDK) GetAddressByPubBytes ¶
func (sdk *NerveAccountSDK) GetAddressByPubBytes(bytes []byte, accountType uint8) []byte
根据公钥,生成账户地址
func (*NerveAccountSDK) GetBytesAddress ¶
func (sdk *NerveAccountSDK) GetBytesAddress(address string) ([]byte, error)
func (*NerveAccountSDK) GetStringAddress ¶
func (sdk *NerveAccountSDK) GetStringAddress(bytes []byte) string
根据地址字节数组,生成可以阅读的字符串地址
func (*NerveAccountSDK) ImportAccount ¶
func (sdk *NerveAccountSDK) ImportAccount(prikey []byte) (Account, error)
Example ¶
使用私钥导入账户,支持NULS生态内任意区块链的账户创建
chainId := uint16(9) //Nerve主网为:9,测试网为:5,NULS主网为:1,NULS测试网为:2 prefix := "NERVE" //Nerve主网为:NERVE,测试网为:TNVT,NULS主网为:NULS,NULS测试网为:tNULS sdk := GetAccountSDK(chainId, prefix) //创建账户 prikey, _ := hex.DecodeString("602bec1904be78c646fe4f5c00f04cab6164be5ff80a48846b4afa0c96a76c25") account, err := sdk.ImportAccount(prikey) if nil != err { fmt.Println(err.Error()) return } fmt.Println("Address:", account.GetAddr()) fmt.Println("Private Key:", account.GetPriKeyHex()) fmt.Println("Public Key:", account.GetPubKeyHex()) fmt.Println("Chain ID:", account.GetChainId())
Output:
func (*NerveAccountSDK) ImportFromKeyStore ¶
func (sdk *NerveAccountSDK) ImportFromKeyStore(keyStoreJson string, password string) (account Account, err error)
func (*NerveAccountSDK) PasswordCheck ¶
func (sdk *NerveAccountSDK) PasswordCheck(password string) bool
校验密码是否满足格式要求,如果不满足则返回false。 密码至少8位,必须包含字母和数字
func (*NerveAccountSDK) Sign ¶
func (sdk *NerveAccountSDK) Sign(account Account, data []byte) ([]byte, error)
func (*NerveAccountSDK) ValidAddress ¶
func (sdk *NerveAccountSDK) ValidAddress(address string) error
Click to show internal directories.
Click to hide internal directories.