2015-05-01 19:41:58 +02:00
|
|
|
// Copyright (c) 2014 The btcsuite developers
|
2014-07-19 09:13:00 +02:00
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package hdkeychain_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-10 22:30:39 +02:00
|
|
|
"github.com/lbryio/lbcutil/hdkeychain"
|
2014-07-19 09:13:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// bip0032MasterPriv1 is the master private extended key from the first set of
|
|
|
|
// test vectors in BIP0032.
|
|
|
|
const bip0032MasterPriv1 = "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbP" +
|
|
|
|
"y6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi"
|
|
|
|
|
|
|
|
// BenchmarkDeriveHardened benchmarks how long it takes to derive a hardened
|
|
|
|
// child from a master private extended key.
|
|
|
|
func BenchmarkDeriveHardened(b *testing.B) {
|
|
|
|
b.StopTimer()
|
|
|
|
masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
|
|
|
|
if err != nil {
|
|
|
|
b.Errorf("Failed to decode master seed: %v", err)
|
|
|
|
}
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-09-01 13:15:53 +02:00
|
|
|
masterKey.Derive(hdkeychain.HardenedKeyStart)
|
2014-07-19 09:13:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BenchmarkDeriveNormal benchmarks how long it takes to derive a normal
|
|
|
|
// (non-hardened) child from a master private extended key.
|
|
|
|
func BenchmarkDeriveNormal(b *testing.B) {
|
|
|
|
b.StopTimer()
|
|
|
|
masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
|
|
|
|
if err != nil {
|
|
|
|
b.Errorf("Failed to decode master seed: %v", err)
|
|
|
|
}
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2020-09-01 13:15:53 +02:00
|
|
|
masterKey.Derive(0)
|
2014-07-19 09:13:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BenchmarkPrivToPub benchmarks how long it takes to convert a private extended
|
|
|
|
// key to a public extended key.
|
|
|
|
func BenchmarkPrivToPub(b *testing.B) {
|
|
|
|
b.StopTimer()
|
|
|
|
masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
|
|
|
|
if err != nil {
|
|
|
|
b.Errorf("Failed to decode master seed: %v", err)
|
|
|
|
}
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
masterKey.Neuter()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BenchmarkDeserialize benchmarks how long it takes to deserialize a private
|
|
|
|
// extended key.
|
|
|
|
func BenchmarkDeserialize(b *testing.B) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
hdkeychain.NewKeyFromString(bip0032MasterPriv1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BenchmarkSerialize benchmarks how long it takes to serialize a private
|
|
|
|
// extended key.
|
|
|
|
func BenchmarkSerialize(b *testing.B) {
|
|
|
|
b.StopTimer()
|
|
|
|
masterKey, err := hdkeychain.NewKeyFromString(bip0032MasterPriv1)
|
|
|
|
if err != nil {
|
|
|
|
b.Errorf("Failed to decode master seed: %v", err)
|
|
|
|
}
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
2018-05-15 04:59:48 +02:00
|
|
|
_ = masterKey.String()
|
2014-07-19 09:13:00 +02:00
|
|
|
}
|
|
|
|
}
|