Documentation ¶
Index ¶
- Constants
- Variables
- func EncryptKey(hdkey *HDKey, auth string, scryptN, scryptP int) ([]byte, error)
- func GenerateSeed(length uint8) ([]byte, error)
- func GetExtendSeed(seed []byte, masterKey string) ([]byte, error)
- func KeyFileName(alias, rootId string) string
- type HDKey
- func DecryptHDKey(keyjson []byte, auth string) (*HDKey, error)
- func NewHDKey(seed []byte, alias, rootPath string) (*HDKey, error)
- func StoreHDKey(dir, alias, auth string, scryptN, scryptP int) (*HDKey, string, error)
- func StoreHDKeyWithSeed(dir, alias, auth string, seed []byte, scryptN, scryptP int) (*HDKey, string, error)
- type HDKeystore
Constants ¶
const ( // MinSeedBytes is the minimum number of bytes allowed for a seed to // a master node. MinSeedBytes = 16 // 128 bits // MaxSeedBytes is the maximum number of bytes allowed for a seed to // a master node. MaxSeedBytes = 64 // 512 bits // The hierarchy described by BIP0043 is: // m/<purpose>'/* // This is further extended by BIP0044 to: // m/44'/<coin type>'/<account>' // BIP0044,m/44'/ //openwallet coin type is 88': m/44'/88' OpenwCoinTypePath = "m/44'/88'" )
const ( // StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptN = 1 << 18 // StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB // memory and taking approximately 1s CPU time on a modern processor. StandardScryptP = 1 // LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptN = 1 << 12 // LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB // memory and taking approximately 100ms CPU time on a modern processor. LightScryptP = 6 //种子长度 SeedLen = 32 )
Variables ¶
var ( //KeyID首字节的标识 KeyIDVer = []byte{0x48} //Derived路径错误 ErrInvalidDerivedPath = errors.New("Invalid DerivedPath") //错误的HDPath ErrInvalidHDPath = errors.New("Invalid HDPath") // ErrInvalidSeedLen describes an error in which the provided seed or // seed length is not in the allowed range. ErrInvalidSeedLen = fmt.Errorf("seed length must be between %d and %d "+ "bits", MinSeedBytes*8, MaxSeedBytes*8) )
var ( //ErrLocked = accounts.NewAuthNeededError("password or unlock") ErrNoMatch = errors.New("no key for given address or file") //ErrDecrypt 机密出错 ErrDecrypt = errors.New("could not decrypt key with given passphrase") )
Functions ¶
func EncryptKey ¶
EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.
func GenerateSeed ¶
GenerateSeed returns a cryptographically secure random seed that can be used as the input for the NewMaster function to generate a new master node.
The length is in bytes and it must be between 16 and 64 (128 to 512 bits). The recommended length is 32 (256 bits) as defined by the RecommendedSeedLen constant.
func GetExtendSeed ¶
GetExtendSeed 获得某个币种的扩展种子
func KeyFileName ¶
keyFileName implements the naming convention for keyfiles: wallet--<alias>-<rootId>
Types ¶
type HDKey ¶
type HDKey struct { //私钥别名 Alias string //账户路径 RootPath string // 账户的扩展ID KeyID string // contains filtered or unexported fields }
HDKey 分层确定性密钥,基于BIP32模型创建的账户模型
func DecryptHDKey ¶
DecryptKey decrypts a key from a json blob, returning the private key itself.
func StoreHDKey ¶
StoreHDKey 创建HDKey
func StoreHDKeyWithSeed ¶
func StoreHDKeyWithSeed(dir, alias, auth string, seed []byte, scryptN, scryptP int) (*HDKey, string, error)
StoreHDKey 创建HDKey
func (*HDKey) DerivedKeyWithPath ¶
func (k *HDKey) DerivedKeyWithPath(path string, curveType uint32) (*owkeychain.ExtendedKey, error)
DerivedKeyWithPath 根据BIP32的规则获取子密钥,例如:m/<purpose>'/* @param path string "" (root key) "m" (root key) "/" (root key) "m/0'" (hardened child #0 of the root key) "/0'" (hardened child #0 of the root key) "0'" (hardened child #0 of the root key) "m/44'/1'/2'" (BIP44 testnet account #2) "/44'/1'/2'" (BIP44 testnet account #2) "44'/1'/2'" (BIP44 testnet account #2)
The following paths are invalid:
"m / 0 / 1" (contains spaces) "m/b/c" (alphabetical characters instead of numerical indexes) "m/1.2^3" (contains illegal characters) @param curveType string ECC_CURVE_SECP256K1 ECC_CURVE_SECP256R1 ECC_CURVE_ED25519
type HDKeystore ¶
type HDKeystore struct {
// contains filtered or unexported fields
}
HDKeystore HDKey的存粗工具类
func NewHDKeystore ¶
func NewHDKeystore(keydir string, scryptN, scryptP int) *HDKeystore
NewHDKeystore 实例化HDKeystore
func (HDKeystore) GetKey ¶
func (ks HDKeystore) GetKey(rootId, filename, auth string) (*HDKey, error)
GetKey 通过accountId读取钥匙
func (*HDKeystore) JoinPath ¶
func (ks *HDKeystore) JoinPath(filename string) string
JoinPath 文件路径组合