-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethereum.go
54 lines (40 loc) · 1011 Bytes
/
ethereum.go
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
45
46
47
48
49
50
51
52
53
54
/*
*/
package hdwallet
import (
"crypto/elliptic"
"github.com/btcsuite/btcd/btcec"
)
func (w *Wallet) GetETHKeyPair(i uint32) (*btcec.PrivateKey, *btcec.PublicKey, error) {
key, err := w.ethPrivKey(i)
if err != nil {
return nil, nil, err
}
privKey, pubkey := btcec.PrivKeyFromBytes(elliptic.P256(), key.key)
return privKey, pubkey, nil
}
func (w *Wallet) ethPrivKey(i uint32) (*ExtendedKey, error) {
gen := &Secp256K1{}
master := MasterKeyGenerate(w.Seed, Secp256k1CurvePhrase)
purposeKey, err := gen.Child(*master, hardenIndex(purposeBIP44))
if err != nil {
return nil, err
}
btcKey, err := gen.Child(*purposeKey, hardenIndex(coinTypeETH))
if err != nil {
return nil, err
}
accountKey, err := gen.Child(*btcKey, hardenIndex(0))
if err != nil {
return nil, err
}
changeKey, err := gen.Child(*accountKey, uint32(externalChain))
if err != nil {
return nil, err
}
indexKey, err := gen.Child(*changeKey, i)
if err != nil {
return nil, err
}
return indexKey, nil
}