keys/keybase.go
func (kb dbKeybase) CreateMnemonic(name, passphrase string, algo SignAlgo) (Info, string, error) {
	// NOTE: secret is SHA256 hashed by secp256k1 and ed25519.
	// 16 byte secret corresponds to 12 BIP39 words.
	// XXX: Ledgers use 24 words now - should we ?
	secret := crypto.CRandBytes(16)
	priv, err := generate(algo, secret)
	if err != nil {
		return nil, "", err
	}

	// encrypt and persist the key
	info := kb.writeLocalKey(priv, name, passphrase)

	// we append the type byte to the serialized secret to help with
	// recovery
	// ie [secret] = [type] + [secret]
	typ := cryptoAlgoToByte(algo)
	secret = append([]byte{typ}, secret...)

	// return the mnemonic phrase
	words, err := kb.codec.BytesToWords(secret)
	seed := strings.Join(words, " ")
	return info, seed, err
}
func (kb dbKeybase) CreateMnemonic(name, passphrase string, algo SignAlgo) (Info, string, error) {
	// NOTE: secret is SHA256 hashed by secp256k1 and ed25519.
	// 16 byte secret corresponds to 12 BIP39 words.
	// XXX: Ledgers use 24 words now - should we ?
	secret := crypto.CRandBytes(16)
	priv, err := generate(algo, secret)
	if err != nil {
		return nil, "", err
	}

	// encrypt and persist the key
	info := kb.writeLocalKey(priv, name, passphrase)

	// we append the type byte to the serialized secret to help with
	// recovery
	// ie [secret] = [type] + [secret]
	typ := cryptoAlgoToByte(algo)
	secret = append([]byte{typ}, secret...)

	// return the mnemonic phrase
	words, err := kb.codec.BytesToWords(secret)
	seed := strings.Join(words, " ")
	return info, seed, err
}
func ( kb dbKeybase ) CreateMnemonic ( name , passphrase string , algo SignAlgo ) ( Info , string , error ) { // NOTE: secret is SHA256 hashed by secp256k1 and ed25519. // 16 byte secret corresponds to 12 BIP39 words. // XXX: Ledgers use 24 words now - should we ? secret := crypto . CRandBytes ( 16 ) priv , err := generate ( algo , secret ) if err != nil { return nil , " " , err } // encrypt and persist the key info := kb . writeLocalKey ( priv , name , passphrase ) // we append the type byte to the serialized secret to help with // recovery // ie [secret] = [type] + [secret] typ := cryptoAlgoToByte ( algo ) secret = append ( [ ] byte { typ } , secret ... ) // return the mnemonic phrase words , err := kb . codec . BytesToWords ( secret ) seed := strings . Join ( words , " " ) return info , seed , err }
// CreateMnemonic generates a new key and persists it to storage, encrypted
// using the passphrase.  It returns the generated seedphrase
// (mnemonic) and the key Info.  It returns an error if it fails to
// generate a key for the given algo type, or if another key is
// already stored under the same name.
CreateMnemonic generates a new key and persists it to storage encrypted using the passphrase . It returns the generated seedphrase ( mnemonic ) and the key Info . It returns an error if it fails to generate a key for the given algo type or if another key is already stored under the same name .