Commit graph

42 commits

Author SHA1 Message Date
Devrandom
dde9e31e50 hdkeychain: correct BIP-32 derivation issue
fixes issue #172
2020-10-21 13:21:55 +02:00
Anirudha Bose
063c4115b3 hdkeychain: add CloneWithVersion to set custom HD version bytes
This adds a new method to the ExtendedKey type that allows cloning the
extended key with custom HD version bytes. It does not mutate the
original extended key on which the method is called.

Added some tests to demonstrate the utility of this method, i.e.,
conversion between standard and SLIP-0132 extended keys.
2020-09-21 09:54:55 -04:00
gipsy
4232759481 Tiny grammar correction
This function should only `by` used by applications that need to create custom ExtendedKeys. => This function should only `be` used by applications that need to create custom ExtendedKeys
2020-08-31 09:38:46 -04:00
Anirudha Bose
f648594deb hdkeychain: Fix small wording issue in ChainCode() tests 2020-07-13 09:53:07 -04:00
Anirudha Bose
6c6f3fd3b7 hdkeychain: Remove duplicate ChildNum() method 2020-07-13 09:53:07 -04:00
Marko Bencun
5fadf96a72 hdkeychain: extend API with ChainCode(), ChildNum()
No way to access them otherwise. Handy for interoperability.
2020-07-13 09:53:07 -04:00
johnta0
35f6653e0a hdkeychain: fix trivial typo 2020-07-06 10:08:01 -04:00
Akio Nakamura
63e5e276cd Fix some typos in docs
This PR fixes 'hardended'/'hardned' to 'hardened' in the godocs.
2020-07-06 10:06:32 -04:00
Wilmer Paulino
d8c8794021
hdkeychain: expose extended key's version and child index 2020-06-17 16:31:20 -07:00
Olaoluwa Osuntokun
5d1446c6ce
hdkeychain: update test case error string due to btcec changes
A bug was recently fixed in btcec wherein we would fail to detect
invalid point decompressions for the curve. This how now been fixed, and
as a result, we'll fail an invalid point earlier in the ParsePubKey
method. We update the error string to reflect this change.
2018-07-06 15:31:18 -07:00
Olaoluwa Osuntokun
06f32abe07
hdkeychain: address go vet warnings 2018-05-14 19:59:48 -07:00
Thomas Kerin
5ffa719c38
Expose hdkeychain.Depth() - returning number of derivations since the root 2017-06-12 02:02:13 +02:00
Chris Pacia
61ec18f9c8 Export NewExtendedKey
Allow users to create custom ExtendedKeys by exporting the newExtendedKey function.
The comment is updated to reflect that this function is only intended to be used
by custom applications.
2017-06-05 14:41:43 -04:00
Dave Collins
fac8a9a582
multi: Update markdown files for GFM changes.
The github markdown interpreter has been changed such that it no longer
allows spaces in between the brackets and parenthesis of links.  This
updates all of the markdown files accordingly.

While here, it also corrects a couple of inconsistencies in regards to
other README.md files in the project.
2017-05-25 13:01:10 -05:00
Dave Collins
66871daeb1 hdkeychain: Add new test vector 3 tests.
This adds the new test vectors added to BIP32 on 2017-02-24 which test
hardened derivation with leading zeros.
2017-05-10 00:19:46 -05:00
Dave Collins
1fb0120cc6
hdkeychain: Consolidate tests into package.
Putting the test code in the same package makes it easier for forks
since they don't have to change the import paths as much.

Also, address a few style and consistent nits while here:
- Prefer t.Fatalf over t.Errorf followed by a return
- Use the consistent style of starting a test function comments with the
  test name
- Prefix test errors by the function being called instead of the one
  doing the calling since the caller itself is already logged by the
  test framework
- Check err in max depth test before checking the returned key is nil
2017-05-09 12:09:02 -05:00
Thomas Kerin
4f8b4dbcb2 hdkeychain: BIP32 maximum depth is 255.
BIP32 keys serialize the depth as a uint8 over the wire. I noticed
uint16 was being used and that the depth was being taken modulo 256
during serialization.

This seems like a bug, as the behaviour is not described in the BIP,
and also introduces incompatibilities which can be hard to make sense
of. For example, the parent fingerprint should be 0x00000000 for a key
of depth zero, whereas with the existing code if depth=256, then the
serialization will set 0 but still set a parent fingerprint.
2017-05-09 11:40:57 -05:00
David Hill
86346b5a95 build: Add gosimple linter to goclean.sh 2017-01-11 15:38:44 -05:00
Dave Collins
22c91fa80a Update for recent chainhash-related API changes. (#78)
This updates all code in the main package and subpackages to make use of
the new chainhash package since the old wire.ShaHash type and functions
have been removed in favor of the abstracted package.

Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.

The following is an overview of the changes:

- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
  - Block.Sha -> Hash
  - Block.TxSha -> TxHash
  - Tx.Sha -> Hash
  - bloom.Filter.AddShaHash -> AddHash
- Rename all variables that included sha in their name to include hash
  instead
- Add license headers to coinset package files
2016-08-08 12:38:16 -05:00
Dave Collins
2d190f72ff hdkeychain: Correct extended privkey serialization.
This corrects an issue with the serialization of extended private keys
where certain underlying derivations could cause lead to printing
extended privkeys that did not have the expected xprv prefix.

In addition, tests for private key derivation have been added as well as
a specific test which triggers the previously failing case.
2016-02-09 17:34:25 -06:00
Dave Collins
ff82dacded hdkeychain: Update NewMaster to accept network.
This changes the NewMaster function to accept the network the generated
extended master key is associated with.  This could previously be done
by calling SetNet on the returned extended key, but that approach is
more error prone since it is easy for a caller to forget to do it or
never know they should to begin with.
2015-11-10 11:31:41 -06:00
Dave Collins
e8bab6bc19 docs: Make various README.md files consistent.
First, it removes the documentation section from all the README.md files
and instead puts a web-based godoc badge and link at the top with the
other badges. This is being done since the local godoc tool no longer
ships with Go by default, so the instructions no longer work without
first installing godoc. Due to this, pretty much everyone uses the
web-based godoc these days anyways. Anyone who has manually installed
godoc won't need instructions.

Second, it makes sure the ISC license badge is at the top with the other
badges and removes the textual reference in the overview section.

Third, it's modifies the Installation section to Installation and
Updating and adds a -u to the go get command since it works for both and
thus is simpler.

Finally, it replaces the badges with SVG versions from shields.io so
they are consistent.
2015-10-23 17:17:38 -05:00
Mawuli Adzoe
deba3d6436 Fix tiny typo in docs. 2015-07-24 06:59:43 +00:00
Josh Rickmar
53b0b8cd09 Fix typo in test. 2015-06-11 16:39:44 -04:00
Dave Collins
1b73e9828d Relicense to the btcsuite developers. 2015-05-01 12:41:58 -05:00
Dave Collins
499e9e0daa Update btcec path import paths to new location. 2015-02-06 10:35:18 -06:00
Dave Collins
1324fa1fad Update btcnet path import paths to new location. 2015-02-05 23:30:03 -06:00
Dave Collins
80b97479bd Update btcwire path import paths to new location. 2015-02-05 14:48:38 -06:00
Dave Collins
9e2037d6db Update btcec import paths to new location. 2015-01-16 18:04:23 -06:00
Dave Collins
7ac9b42a52 Update btcnet import paths to new location. 2015-01-16 17:36:18 -06:00
Dave Collins
fdc00f8eff Update btcwire import paths to new location. 2015-01-16 15:26:50 -06:00
Dave Collins
f80c4d718d Update btcutil import paths in README.md files. 2015-01-15 21:35:29 -06:00
Dave Collins
506d333934 Update btcutil import paths to new location. 2015-01-15 15:13:38 -06:00
benma
07db1b5a70 Integrate the new base58 package. 2014-12-22 12:01:50 +01:00
Dave Collins
ea27722dac Export the hdkeychain min and max seed byte lens. 2014-09-25 22:13:42 -05:00
Dave Collins
2539ca9860 Fix hdkeychain to avoid zeroing net version bytes.
This commit corrects the Zero function in hdkeychain to nil the version
instead of zeroing the bytes.  This is necessary because the keys are
holding onto a reference into the specific version bytes for the network
as provided by the btcnet package.  Zeroing them causes the bytes in the
btcnet package to be zeroed which then leads to issues later when trying
to use them.

Also, to prevent regressions, new tests have been added to exercise this
scenario.

Pointed out by @jimmysong.
2014-09-08 14:30:56 -05:00
Dave Collins
f6d6cd5d27 Update hdkeychain test coverage report. 2014-08-18 18:18:16 -05:00
Dave Collins
7bd19adb47 Test variable declaration consistency. 2014-08-18 18:17:58 -05:00
Dave Collins
f8ad0939a2 Add new function on extended keys to zero them.
This commit adds a new function named Zero on the hdkeychain.ExtendedKey
which can be used to manually clear the memory used for an extended key.
This is useful for enhanced security by allowing the caller to explicitly
clear the memory when they're done with a key.  Otherwise it might hang
around in memory for a while.

Once a key has been zeroed it is no longer usable.

This commit also contains tests to ensure everything works as expected
after a key has been zeroed.
2014-08-18 17:54:20 -05:00
Dave Collins
a36fbe9ade Correct DefaultWalletLayout example link. 2014-07-22 17:18:15 -05:00
Dave Collins
8f049a120c Correct example links in hdkeychain READEME.md. 2014-07-22 17:17:14 -05:00
Dave Collins
e6c5ca2a6a Implement hdkeychain BIP0032 API.
This commit adds a new sub-package named hdkeychain which can be used to
derive hierarchical deterministic key chains which form the foundation of
hd wallets.

- Support for private and public extended keys
- Convenient cryptographically secure seed generation
- Simple creation of master nodes
- Support for multi-layer derivation
- Easy serialization and deserialization for both private and public
  extended keys
- Support for custom networks by registering them with btcnet
- Obtaining the underlying EC pubkeys, EC privkeys, and associated bitcoin addresses
  ties in seamlessly with existing btcec and btcutil types which provide
  powerful tools for working with them to do things like sign transactions
  and generate payment scripts
- Makes use of the btcec package which is highly optimized for secp256k1
- Code examples including:
  - Generating a cryptographically secure random seed and deriving a
    master node from it
  - Default HD wallet layout as described by BIP0032
  - Audits use case as described by BIP0032
- Comprehensive test coverage including the BIP0032 test vectors
- Benchmarks
2014-07-22 17:11:46 -05:00