forked from somatic-labs/meteorite
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprivkey.go
More file actions
44 lines (32 loc) · 1.06 KB
/
privkey.go
File metadata and controls
44 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"fmt"
"github.com/cosmos/cosmos-sdk/crypto/hd"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
func getPrivKey(config Config, mnemonic []byte) (cryptotypes.PrivKey, cryptotypes.PubKey, string) {
// Generate a Bip32 HD wallet for the mnemonic and a user supplied password
// create master key and derive first key for keyring
stringmem := string(mnemonic)
algo := hd.Secp256k1
derivedPriv, err := algo.Derive()(stringmem, "", "m/44'/330'/0'/0/0")
if err != nil {
panic(err)
}
privKey := algo.Generate()(derivedPriv)
// Create master private key from
pubKey := privKey.PubKey()
// Convert the public key to Bech32 with custom HRP
// bech32PubKey, err := bech32ifyPubKeyWithCustomHRP("celestia", pubKey)
// if err != nil {
// panic(err)
// }
addressbytes := sdk.AccAddress(pubKey.Address().Bytes())
address, err := sdk.Bech32ifyAddressBytes(config.Prefix, addressbytes)
if err != nil {
panic(err)
}
fmt.Println("Address Ought to be", address)
return privKey, pubKey, address
}