Commit Graph

44 Commits

Author SHA1 Message Date
Dave Collins
cebab1ef64
multi: Use secp256k1/v2 module.
This updates the following modules to use the secp256k1/v2 module:

- blockchain
- chaincfg/v2
- dcrutil/v2
- hdkeychain/v2
- mempool/v3
- txscript/v2
- main

The hdkeychain/v3 and txscript/v2 modules both use types from secp256k1
in their public API.

Consequently, in order avoid forcing them to bump their major versions,
secp256k1/v1.0.3 was released with the types redefined in terms of the
secp256k1/v2 module so callers still using v1 of the module that are not
ready to upgrade to the v2 module yet can interoperate by updating to
the latest patch version.
2019-10-08 10:14:13 -05:00
Dave Collins
3e2208f8c1
build: Replace TravisCI with CI via Github actions. 2019-09-20 19:59:04 -05:00
Aaron Campbell
8be96a8729 multi: Correct typos.
Correct typos found by reading code, ispell, and creative grepping.
2019-08-22 10:20:03 -05:00
Dave Collins
8354a310bc
main: Consume latest module minors and patches.
This updates the main module to use the latest available minor and patch
versions of all modules and reverts the recent change that incorrectly
removed all of the blake256 references from the various go.sum files.

The following required direct dependencies are bumped as follows:

- github.com/decred/dcrd/blockchain/stake@v1.2.1
- github.com/decred/dcrd/blockchain/stake/v2@v2.0.1
- github.com/decred/dcrd/certgen@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.5.2
- github.com/decred/dcrd/chaincfg/chainhash@v1.0.2
- github.com/decred/dcrd/chaincfg/v2@v2.2.0
- github.com/decred/dcrd/dcrutil/v2@v2.0.0
- github.com/decred/dcrd/gcs@v1.1.0
- github.com/decred/dcrd/hdkeychain/v2@v2.0.1
- github.com/decred/dcrd/txscript/v2@v2.0.0
- github.com/decred/dcrwallet/rpc/jsonrpc/types@v1.2.0
2019-08-08 10:05:35 -05:00
Nicola Larosa
1149d54cb9 multi: Use crypto/blake256.
This updates the code to make use of the new crypto/blake256 module instead of
github.com/dchest/blake256.

* change the references in the chaincfg/chainhash and gcs modules
* update chaincfg/chainhash to use the new Sum256 API
* remove references to dchest/blake256 from all go.sum files
2019-08-07 18:54:55 -05:00
David Hill
666286f0a7 hdkeychain: Add ChildNum and Depth methods. 2019-07-24 15:15:25 -05:00
Dave Collins
9e63126d48
hdkeychain: Prepare v2.0.1.
This updates the hdkeychain dependencies and serves as a base for
hdkeychain/v2.0.1.

Note that even though some of the updated dependencies consume a new
major version, they are only used internally or in the example code and
therefore a major version bump of the hdkeychain module is not required.

The updated direct dependencies in this commit are as follows:

- github.com/decred/dcrd/chaincfg/v2@v2.0.2
- github.com/decred/dcrd/dcrutil/v2@2.0.0
- github.com/decred/dcrd/dcrec/secp256k1@v1.0.2

The full list of updated direct dependencies since the previous
hdkeychain/v2.0.0 release are as follows:

- github.com/decred/dcrd/chaincfg/v2@v2.0.2
- github.com/decred/dcrd/dcrec@v1.0.0
- github.com/decred/dcrd/dcrutil/v2@2.0.0
- github.com/decred/dcrd/dcrec/secp256k1@v1.0.2
2019-07-22 19:03:51 -05:00
Dave Collins
2fbf64b342
hdkeychain: Correct a few comment typos. 2019-07-22 18:37:26 -05:00
David Hill
893aa30dce multi: Use https links where available. 2019-06-18 14:20:06 -05:00
Dave Collins
c33be8c68c
multi: Update all modules for chaincfg v1.5.1.
This updates all of the modules that still rely on v1 of the chaincfg
module to use v1.5.1 which builds correctly with the major API bump
introduced in the edwards v1.0.0 module.

While here, it also updates all references to the v0 edwards and dcrec
modules to their tagged v1 counterparts, tidies all of the modules via
go mod tidy, and removes all unnecessary indirect entries from the mod
files to keep the modules using the versions the dependencies are tested
with.

The primary motivation for this change is that the chaincfg/v2 module
requires edwards/v1 which is not API compatible with edwards/v0.
Consequently, in order for each module to be incrementally updated to
use chaincfg/v2, all of its dependencies must also be able to build with
edwards/v1 which is the case as of chaincfg v1.5.1.
2019-06-17 15:54:31 -05:00
Dave Collins
1a0b0b662f
release: Introduce hdkeychain v2 module. 2019-03-29 11:40:27 -05:00
Dave Collins
71b02b9d89
hdkeychain: Use mock net params in tests.
This implements a mock network params struct that implements the new
interface and modifies the test code to make use of the mock params
instead of chaincfg.  This completely decouples the tests, with the
exception of the example code, from chaincfg and therefore any updates
to it such as introducing new test networks will not require changes to
the tests.
2019-03-29 11:26:40 -05:00
Dave Collins
a8960587fa
hdkeychain: Introduce NetworkParams interface.
This introduces a new interface named NetworkParams and updates the
functions that currently take a pointer to a chaincfg.Params struct to
accept the interface instead.

This removes the tight coupling between the two packages at the API
boundary and allows callers to easily provide custom values without
having to create and register and entire chaincfg network as previous
required.

Finally, the README.md is updated accordingly.
2019-03-29 11:26:40 -05:00
Dave Collins
4ea06ed7df
hdkeychain: Don't rely on global state.
This refactors the the extended key internals to keep track of the
public and private network ids instead of a version slice in order to
remove the need to rely on global state for looking up the extended
public key ID for the network.

Since the public and private network ids are 8 bytes and the version
slice was 24 bytes, this also has the nice side effect of slightly
optimizing the performance, particularly in the private to public case,
as shown by the following benchmark comparison:

benchmark                 old ns/op   new ns/op   delta
--------------------------------------------------------
BenchmarkDeriveHardened   5795        5600        -3.36%
BenchmarkDeriveNormal     6585        6263        -4.89%
BenchmarkPrivToPub        137         118         -13.87%
BenchmarkDeserialize      17618       17618       +0.00%
BenchmarkSerialize        21672       21061       -2.82%

benchmark                 old bytes   new bytes   delta
--------------------------------------------------------
BenchmarkDeriveHardened   1552        1536        -1.03%
BenchmarkDeriveNormal     1601        1585        -1.00%
BenchmarkPrivToPub        128         112         -12.50%
BenchmarkDeserialize      1640        1624        -0.98%
BenchmarkSerialize        1712        1712        +0.00%
2019-03-29 11:26:39 -05:00
Dave Collins
da25049c71
hdkeychain: Require network on decode extended key.
This modifies NewKeyFromString to accept the required network parameters
for the provided encoded extended key and introduces a new error to
indicate the provide extended key is for the wrong network.

This means that NewKeyFromString will now return ErrWrongNetwork if the
extended key being decoded is not for the provided network.  This
differs from the previous behavior relied on globally-registered
networks in chaincfg to determine which network the encoded key was for
followed by requiring the caller to check upon if the key was for the
specific network it desired upon return.

Finally, it removes the no longer necessary IsForNet method and updates
the documentation accordingly.
2019-03-29 11:26:39 -05:00
Dave Collins
e1125f00fa
hdkeychain: Use locally-scoped netparams in tests.
This modifies the tests to use locals for the network parameter
references to make it easier to mock the parameters in the future.
2019-03-29 11:26:38 -05:00
Dave Collins
6aa6a73591
hdkeychain: Remove SetNet method.
This removes the SetNet method from the ExtendedKey struct since its use
in practice could lead to subtle bugs due to the fact that changing the
network after keys have already been derived and then deriving more keys
will not result in the same derivation as starting with the target
network to begin with.  It is better to simply avoid the possibility of
misuse.

It also removes the related tests.
2019-03-29 11:26:38 -05:00
Dave Collins
a347b76ab3
hdkeychain: Remove Address method.
This removes the Address method from the ExtendedKey struct since
ultimately there will be multiple address types and therefore it no
longer makes sense to return an address which probably isn't the one the
caller actually needs.  Instead, the caller can make use of the ECPubKey
method to obtain the public key and create the desired address from
there.

It also removes the related tests, updates the example to show the
address conversion process for a standard pay-to-pubkey-hash address,
and updates the README.md and doc.go files accordingly.
2019-03-29 11:26:37 -05:00
Dave Collins
3e33f259aa
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 and makes it
more consistent with the rest of the code base.
2019-03-29 11:26:36 -05:00
Dave Collins
3d41c62006
hdkeychain: Correct docs key examples.
This corrects the serialized extended key examples in the package
documentation.  This appears to have been missed when porting the code.
2019-03-29 11:26:36 -05:00
Dave Collins
b05edc64a9
hdkeychain: Correct benchmark extended key.
This corrects the master extended private key used in the benchmarks for
Decred.  This appears to have been missed when porting the code.
2019-03-29 11:26:35 -05:00
Dave Collins
e6c9fddbaf
hdkeychain: Update README.md.
This updates the README.md in hdkeychain to account for changes made in
Decred, correct the NewMaster godoc example link, and format the
examples so the description is on the line after the link for
consistency with other packages in the code base.
2019-03-19 15:08:52 -05:00
Dave Collins
0f50fd5f8c
multi: Add go 1.11 directive to all modules.
This adds the go 1.11 directive to all of the modules in order to
clearly mark they build and work with that version.  Go 1.12 modified
the tools such that tidy will automatically add the new version to
modules that do not already have a directive and that would prevent
builds on Go 1.11 through Go 1.11.3 which is not desirable.
2019-03-18 02:02:35 -05:00
Dave Collins
e052b9cbf2
multi: Remove non-root module replacements.
This modifies all of the modules, with the exception of the root module,
to remove all replacement directives from their go.mod files and update
the requirements and module sums accordingly.

While it is nice to be able to build and test directly from each module
directory and have it pull in the latest untagged changes when
developing, having all of the overrides in each module makes it
infeasible to use the module tools to help maintain the modules and thus
makes it quite difficult to ensure they are all independently accurate
for external consumers.

By maintaining all of the overrides in the root module and invoking all
builds and tests from it, the overrides will apply to ensure the latest
code is being built and tested.

This also modifies the tests script used with in CI to run all of the
tests from the root module accordingly.
2019-02-08 18:01:43 -06:00
Dave Collins
1a370d38d6
release: Tidy module files with published versions. 2018-12-12 12:18:11 -06:00
Dave Collins
220d434b6e
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/dcrec/secp256k1@v1.0.1
- github.com/decred/dcrd/dcrjson@v1.1.0
- github.com/decred/dcrd/database@v1.0.3
- github.com/decred/dcrd/blockchain/stake@v1.1.0
- github.com/decred/dcrd/mining@v1.1.0
- github.com/decred/dcrd/certgen@v1.0.2
- github.com/decred/dcrd/connmgr@v1.0.2
- github.com/decred/dcrd/mempool@v1.1.0

In addition, it serves as a base for tagging releases of the following
module versions that have previous been bumped since the last release,
but not yet tagged:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/txscript@v1.0.2
- github.com/decred/dcrd/blockchain@v1.1.0
- github.com/decred/dcrd/hdkeychain@v1.1.1
- github.com/decred/dcrd/peer@v1.1.0
- github.com/decred/dcrd/rpcclient@v1.1.0

Finally, it updates all of the dependencies for every module accordingly,
adds a few missing overrides for transitive dependencies, and tidies up
some of the go module sum files.
2018-12-10 11:18:00 -06:00
David Hill
5f8081761d multi: Remove unused code. 2018-10-31 21:50:09 -04:00
Dave Collins
47ade78c1a
multi: Resurrect regression network.
This resurrects the regression test network that was removed before
initial launch although it really should not have been.  The simulation
test network and the regression test network do not serve the same
purpose.  Specifically, the regression test network is intended for unit
tests, RPC server tests, and consensus tests.  On the other hand, the
simulation test network is intended for private use within a group of
individuals doing simulation testing and full integration tests between
different applications such as wallets, voting service providers, mining
pools, block explorers, and other services that build on Decred.

Keeping the concerns separate will allow the simulation test network to
be modified in ways such as activating consensus changes that have been
successfully voted into mainnet without also needing to vote them in on
the simulation test network while still preserving the ability for the
unit tests to properly test the voting semantics and handling to help
prevent regressions.

In addition to resurrecting the regression test network, this also fully
fleshes out new values for the various addresses prefixes (Rk, Rs, Re,
etc), HD key prefixes (rprv, rpub), and treasury multisig details.

As a part of resurrecting the network, a new CLI flag `--regnet` is
added to allow the RPC test harness connect to a running instance, the
areas of the code which involve votes have been modified to allow the
votes to apply to the new network, and tests have been added to the
relevant modules.

This bumps the affected module versions as follows:

- github.com/decred/dcrd/wire@v1.2.0
- github.com/decred/dcrd/chaincfg@v1.2.0
- github.com/decred/dcrd/dcrutil@v1.2.0
- github.com/decred/dcrd/hdkeychain@v1.1.1

The blockchain module is also affected, but since its version has
already been bumped since the last release tag, it is not bumped again.

Finally, this does not include switching unit tests or the RPC test
harness over the new network since that will be done in a separate
commit.
2018-10-09 18:52:13 -05:00
Dave Collins
36f61d8ebd build: Tidy module sums (go mod tidy). 2018-08-16 20:03:27 -05:00
Dave Collins
9536f0c88f
release: Bump module versions and deps.
This bumps the various module versions as follows:

- github.com/decred/dcrd/addrmgr@v1.0.2
- github.com/decred/dcrd/wire@v1.1.0
- github.com/decred/dcrd/chaincfg@v1.1.1
- github.com/decred/dcrd/connmgr@v1.0.1
- github.com/decred/dcrd/dcrutil@v1.1.1
- github.com/decred/dcrd/database@v1.0.1
- github.com/decred/dcrd/hdkeychain@v1.1.0
- github.com/decred/dcrd/txscript@v1.0.1
- github.com/decred/dcrd/blockchain/stake@v1.0.1
- github.com/decred/dcrd/gcs@v1.0.1
- github.com/decred/dcrd/blockchain@v1.0.1
- github.com/decred/dcrd/mining@v1.0.1
- github.com/decred/dcrd/mempool@v1.0.1
- github.com/decred/dcrd/peer@v1.0.1
- github.com/decred/dcrd/rpcclient@v1.0.1

It also updates all of the dependencies for every module accordingly and
adds a few missing overrides for transitive dependencies.
2018-08-09 14:30:22 -05:00
Dave Collins
9e1579771b
multi: Reset testnet and bump to version 3.
This adds a new testnet3 network with new genesis block, block one
ledger, treasury address, and network magic.

All consensus rules that were voted in by testnet2 are automatically
active on the new testnet3 without having to vote them in again.
Consequently, there are no consensus vote agendas defined for it.
2018-08-08 08:09:32 -05:00
Dave Collins
96a1a8546d
multi: Reduce testnet2 refs in unit tests.
This modifies the test code for several unit tests to prefer using
another network, such as mainnet or simnet, when not specifically
testing something that requires testnet.

In the cases where where testnet is required, it also now prefers a
local reference over directly accessing the testnet parameters directly
from the chaincfg package.

This is being done because the test network undergoes periodic resets
and by reducing the number of direct references, it simplifies the
process of resetting it.
2018-08-08 06:41:50 -05:00
Dave Collins
295179fc0d
build: Refine build module support.
This further refines the modules to add the following new modules
instead of depending on the entire dcrd module:

- github.com/decred/dcrd/dcrjson@v1.0.0
- github.com/decred/dcrd/blockchain@v1.0.0
- github.com/decred/dcrd/blockchain/stake@v1.0.0
- github.com/decred/dcrd/gcs@v1.0.0
- github.com/decred/dcrd/mining@v1.0.0
- github.com/decred/dcrd/mempool@v1.0.0
- github.com/decred/dcrd/peer@v1.0.0
- github.com/decred/dcrd/rpcclient@v1.0.0

Also, it ensures modules that rely on other modules within the repo are
provided replacements to the latest repo code to ensure builds against
master and continuous integration use the latest code.

- github.com/decred/dcrd/addrmgr
- github.com/decred/dcrd/blockchain
- github.com/decred/dcrd/blockchain/stake
- github.com/decred/dcrd/chaincfg
- github.com/decred/dcrd/connmgr
- github.com/decred/dcrd/database
- github.com/decred/dcrd/dcrec/secp256k1
- github.com/decred/dcrd/dcrjson
- github.com/decred/dcrd/dcrutil
- github.com/decred/dcrd/gcs
- github.com/decred/dcrd/hdkeychain
- github.com/decred/dcrd/mempool
- github.com/decred/dcrd/mining
- github.com/decred/dcrd/peer
- github.com/decred/dcrd/rpcclient
- github.com/decred/dcrd/txscript
- github.com/decred/dcrd/wire
2018-08-05 20:45:45 -05:00
Dave Collins
04be5e5efe
hdkeychain: Refine go build module support.
Now that the base58, chaincfg, chainhash, dcrec, secp256k1, and dcrutil
modules have been defined, update the hdkeychain module to only depend
on them instead of the entire dcrd module.
2018-07-21 14:07:38 -05:00
David Hill
01316e20f3 multi: Continue conversion from chainec to dcrec. 2018-07-04 11:21:43 -04:00
Dave Collins
45e313e6d2
multi: Define vgo modules.
This adds module support for the versioned go toolchain.  In particular,
the following packages are defined as modules:

* addrmgr
* blockchain
* certgen
* chaincfg
* connmgr
* database
* dcrjson
* dcrutil
* gcs
* hdkeychain
* mempool
* mining
* peer
* rpcclient
* txscript
* wire

It does not update the travis build environment or README since it is
experimental at this point.
2018-05-25 15:38:16 -05:00
Donald Adu-Poku
2e293f28bf multi: use secp256k1 types and fields directly.
The chainec package is scheduled to be removed. This PR replaces
chainec function calls within the hdkeychain package with the
underlining secp256k1 types and fields which breaks its dependence
on a package soon to be removed. memwallet, a member of rpctest which
calls hdkeychain functions is also updated.
2018-05-17 00:46:57 +00:00
Dave Collins
7ba7cd62a3
hdkeychain: Satisfy fmt.Stringer interface.
This reverts changes to the String function on ExtendedKey to match the
upstream code so that it satisfies the fmt.Stringer interface as
intended.
2018-04-30 10:33:33 -05:00
Josh Rickmar
3149946b23 hdkeychain: Correct hash algorithm in comment 2018-04-25 17:34:47 -05:00
Markus Richter
1e42b8524d multi: Properly capitalize Decred.
Decred is inconsistencly capitalized in the code base,
change all occurences of decred to Decred.
2018-03-01 17:41:35 -06:00
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
David Hill
393a95c079 multi: fix some maligned linter warnings 2018-02-13 14:50:33 -06:00
David Hill
20686cd775 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
Josh Rickmar
65001cd49e hdkeychain: Move to github.com/decred/dcrd/hdkeychain
This change moves the hdkeychain package outside of the dcrutil
directory into its own top-level package.  This change is being made
since hdkeychain only depends on dcrutil's address code, and if the
rpctest integration tests are ever moved outside of the dcrd repo,
hdkeychain will no longer be required to remain in dcrd to avoid a
cyclic dependency.
2017-10-12 08:31:54 -05:00