crypto: updates from reviews (#535)

This commit is contained in:
Federico Kunze Küllmer
2021-09-07 17:29:24 +00:00
committed by GitHub
parent c3f70aeaf7
commit 2e45a0665e
12 changed files with 71 additions and 70 deletions
+9 -1
View File
@@ -67,6 +67,7 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
return nil, err
}
// create a BTC-utils hd-derivation key chain
masterKey, err := hdkeychain.NewMaster(seed, &chaincfg.MainNetParams)
if err != nil {
return nil, err
@@ -80,11 +81,15 @@ func (s ethSecp256k1Algo) Derive() hd.DeriveFn {
}
}
// btc-utils representation of a secp256k1 private key
privateKey, err := key.ECPrivKey()
if err != nil {
return nil, err
}
// cast private key to a convertible form (single scalar field element of secp256k1)
// and then load into ethcrypto private key format.
// TODO: add links to godocs of the two methods or implementations of them, to compare equivalency
privateKeyECDSA := privateKey.ToECDSA()
derivedKey := crypto.FromECDSA(privateKeyECDSA)
@@ -98,6 +103,9 @@ func (s ethSecp256k1Algo) Generate() hd.GenerateFn {
bzArr := make([]byte, ethsecp256k1.PrivKeySize)
copy(bzArr, bz)
return &ethsecp256k1.PrivKey{Key: bzArr}
// TODO: modulo P
return &ethsecp256k1.PrivKey{
Key: bzArr,
}
}
}