Commit Graph

114 Commits

Author SHA1 Message Date
Daira Emma Hopwood 6bb8c60f41 Use the new `examine` macro to replace all instances of
`std::visit(match {...}, specimen)`, improving code readability.

For ease of review, this commit includes only obviously correct
transformations that all follow the same pattern.

Signed-off-by: Daira Emma Hopwood <daira@jacaranda.org>
2023-04-04 21:26:39 +01:00
Greg Pfeil 45c4568a7e
Simplify diversifier_index_t handling
- Remove `std::optional` from a number of uses,
- simplify `GetUFVKMetadataForAddress` to `GetUFVKIdForAddress`, and
- add a new `GetUFVKMetadataForAddress` as a wrapper around
  `GetUFVKMetadataForReceiver`.
2023-03-08 18:14:08 -07:00
Kris Nuttycombe 3cec519ce4 scripted-diff: Update Zcash copyrights to 2023
-BEGIN VERIFY SCRIPT-
for party in "The Zcash developers" "The Bitcoin Core developers" "Bitcoin Developers"; do
  sed -i"" -e "s#Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? $party#Copyright (c) \1-2023 $party#" COPYING
  sed -i"" -e "s#\(.*\)\([0-9]\{4\}\)\(-[0-9]\{4\}\)\, $party#\1\2-2023, $party#" contrib/debian/copyright
done

sed -i"" -e "s/define(_COPYRIGHT_YEAR, [0-9]\{4\})/define(_COPYRIGHT_YEAR, 2023)/" configure.ac
sed -i"" -e "s/#define COPYRIGHT_YEAR [0-9]\{4\}/#define COPYRIGHT_YEAR 2023/" src/clientversion.h

git grep "^// Copyright (c) .* The Zcash developers" \
  | awk -F ':' '{print $1}' \
  | xargs -I {} sed -i"" -e "s#// Copyright (c) \([0-9]\{4\}\)\(-[0-9]\{4\}\)\? The Zcash developers#// Copyright (c) \1-2023 The Zcash developers#" {}
-END VERIFY SCRIPT-
2023-01-23 11:31:54 -07:00
Jim Posen 9a7e2c153d scripted-diff: Move util files to separate directory.
-BEGIN VERIFY SCRIPT-
mkdir -p src/util
git mv src/util.h src/util/system.h
git mv src/util.cpp src/util/system.cpp
git mv src/utilmoneystr.h src/util/moneystr.h
git mv src/utilmoneystr.cpp src/util/moneystr.cpp
git mv src/utilstrencodings.h src/util/strencodings.h
git mv src/utilstrencodings.cpp src/util/strencodings.cpp
git mv src/utiltime.h src/util/time.h
git mv src/utiltime.cpp src/util/time.cpp

sed -i -e 's/"util\.h"/"util\/system\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
git checkout HEAD -- src/secp256k1 # exclude secp256k1, which has its own "util.h"
sed -i -e 's/"utilmoneystr\.h"/"util\/moneystr\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/"utilstrencodings\.h"/"util\/strencodings\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp')
sed -i -e 's/"utiltime\.h"/"util\/time\.h"/g' $(git ls-files 'src/*.h' 'src/*.cpp')

sed -i -e 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h
sed -i -e 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h
sed -i -e 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h
sed -i -e 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h

sed -i -e 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am
sed -i -e 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am
sed -i -e 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am
sed -i -e 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am

sed -i -e 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-locale-dependence.sh
sed -i -e 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh
sed -i -e 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh
-END VERIFY SCRIPT-
2022-07-01 17:50:09 -06:00
Kris Nuttycombe 28040f9ce4 scripted-diff: Add 2016-2022 copyright headers for files added/modified in 2016
-BEGIN VERIFY SCRIPT-
grep -l "Copyright" $(grep -L "The Zcash developers" $(git diff --name-only --diff-filter=ACM bitcoin-v0.11.2..94f427a211bb337200c29a1e19be0f5ad2f171b0 -- src/ test/ zcutil/ qa/)) | xargs -I {} sed -i"" -e "s#\(\(.*\)Copyright (c) .* The Bitcoin Core developers\)#\1\n\2Copyright (c) 2016-2022 The Zcash developers#" {}
-END VERIFY SCRIPT-
2022-05-11 17:23:09 -06:00
Kris Nuttycombe 87cc0d22db Add RecipientType to GetPaymentAddressForRecipient result.
This now returns whether or not the address corresponds to an
internal recipient, an external address for the wallet, or a
counterparty's address (an address not derived from any of
the wallet's keys) from GetPaymentAddressForRecipient.

Fixes #5708
2022-03-20 16:36:38 -06:00
Kris Nuttycombe 4df6c028f4 Correctly report change outputs in z_viewtransaction.
One of the invariants that we want to hold for unified addresses
is that we never want change addresses to be visible to users.
This updates address metadata retrieval to also indicate whether
or not an address is associated with a UFVK's internal key,
and omits and flags change addresses in z_viewtransaction output.
2022-03-18 11:09:35 -06:00
Kris Nuttycombe 9582a2c1f1 Eliminate redundancy between the wallet and the keystore.
The methods `FindUnifiedFullViewingKey` and `FindUFVKByReceiver`
are implementable with only the information that'a available from
the keystore, so it's better to use the methods that are defined
there in the previous commit.
2022-03-17 11:38:44 -06:00
Kris Nuttycombe 9d8c20ed78 Add UnifiedAddress variant to ZTXOSelector
When a user supplies a unified address as the source of funds
for z_sendmany, the previous behavior could have risked user
privacy by spending transparent UTXOs belonging to different
diversified addresses in the same transaction, thereby linking
those addresses, and consequently any diversified shielded
receivers of unified addresses containing those transparent
receivers.

This change limits selection of transparent UTXOs to only those
explicitly associated with the unified receivers of the provided
source UA. Also, if a UA is provided as the source, the behavior
is maintained that only shielded notes in pools corresponding to
the receivers of that UA will be selected.
2022-03-17 11:38:44 -06:00
Jack Grigg 3179e45467 Trial-decrypt candidate Sapling receivers with all wallet UFVKs
This ensures we have the same semantics for detecting Orchard and
Sapling receivers in UAs, even if the UA they are part of was derived
outside of the zcashd wallet.
2022-02-23 02:23:45 +00:00
Kris Nuttycombe 258f0fc72f Add Orchard components to unified full viewing keys
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-22 21:08:10 +00:00
Kris Nuttycombe 1a1522a4f1 Add Orchard components to unified address
Co-authored-by: Jack Grigg <jack@z.cash>
2022-02-21 17:04:27 +00:00
Kris Nuttycombe 3e3ee1bf3b Add various bits of documentation 2022-02-19 15:29:19 +00:00
Kris Nuttycombe bf79be2b57 Replace z_getbalanceforaddress with z_getbalanceforviewingkey 2022-02-09 16:58:55 -07:00
Kris Nuttycombe a46720aab1 Add accessor method for Sapling IVKs to SaplingDiversifiableFullViewingKey 2022-02-01 08:24:31 -07:00
Kris Nuttycombe 90e59c3be0 Do not add Sapling addresses to the wallet by default when adding extfvks.
Adding the default address to the wallet automatically made sense
prior to support of diversified addresses, but this is no longer
desirable behavior as we have separated key generation from address
derivation.
2022-01-31 11:31:16 -07:00
Kris Nuttycombe 66530d97e1 Rename AddSaplingIncomingViewingKey -> AddSaplingPaymentAddress
This operation was poorly named; the wallet already contained
the IVK, and this operation was simply adding the ability to
look up the IVK by a specific diversified address derived
from that IVK.
2022-01-30 17:24:52 -07:00
Kris Nuttycombe ae2213dcdc Fix variable shadowing in change address derivation & add change IVK to the keystore. 2022-01-30 11:15:50 -07:00
Kris Nuttycombe cc392c70a6 Merge branch 'master' into feature/wallet_unified_addresses 2022-01-12 16:54:12 -07:00
Kris Nuttycombe c35e2b4438 Remove spurious uses of HaveSpendingKeyForPaymentAddress
There's no need to dispatch through this visitor in cases where
the payment address type is already statically known.
2022-01-06 13:44:45 -07:00
Kris Nuttycombe eb53abbbaf Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>
2022-01-04 16:29:53 -07:00
Kris Nuttycombe 5d07a8ae79 Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>
2021-12-30 10:53:51 -07:00
Kris Nuttycombe 74e4bef6f2 Ensure that unified address metadata is always correctly populated.
This reworks the way that address metadata is added to the wallet
to make adding address metadata to the wallet's in-memory cache
the responsibility of a single method rather than distributed
across multiple places in the code.
2021-12-23 09:33:17 -07:00
Kris Nuttycombe 24e46a16f1 Only derive ZcashdUnifiedFullViewingKey from UnifiedFullViewingKey
This changes ZcashdUnifiedSpendingKey::ToUnifiedFullViewingKey
to return a `UnifiedFullViewingKey` object. This makes the
derivation of ZcashdUnifiedFullViewingKey values more regular,
removing the need to be able to construct these values directly
from the spending key.

This change also modifies ZcashdUnifiedSpendingKey to remove
the `std::optional` wrapper from its member keys. This
optionality is spurious, because it is always possible to
derive a "complete" spending key, and we do not support
import of unified spending keys.
2021-12-22 16:09:17 -07:00
Kris Nuttycombe 700b98f0b0 Add tests for keystore storage and retrieval of UFVKs. 2021-12-22 15:57:47 -07:00
Kris Nuttycombe 0dcdc28a38 Add CWallet::GetUnifiedForReceiver 2021-12-22 15:57:47 -07:00
Kris Nuttycombe b29ca10b8d Add unified address generation.
Generate unified addresses from UFVKs, and add the associated
metadata to the wallet database.
2021-12-22 15:57:47 -07:00
Kris Nuttycombe e56f252a86 Add unified address tracking to KeyStore 2021-12-22 15:55:36 -07:00
Kris Nuttycombe ef068c51a9 Store ufvks to the wallet database. 2021-12-22 15:55:36 -07:00
Kris Nuttycombe b67e62d977 Address comments from code review. 2021-10-29 13:38:36 -06:00
Kris Nuttycombe 8883ae8b9e Add support for externally searching for valid Sapling diversifiers.
In order to support generation of unified addresses, it needs
to be possible for the code generating a unified address to search
the space of Sapling diversifiers to obtain a valid diversifier.

Historically, invalid diviersifiers were simply skipped, so we retain
this behavior when obtaining a Sapling address from the legacy HD seed.
2021-10-19 11:48:02 -06:00
Kris Nuttycombe 5677649af1 Derive random HD seeds from ZIP-339 seed phrases.
Add support for dump of legacy HD seeds & persistence of mnemonic-based seeds.
2021-10-19 11:48:02 -06:00
Yuri Zhykin e715e1393b Fix for incorrect locking in GetPubKey() (keystore.cpp)
zcash: cherry picked from commit 220f950ab1302f8f8c0bb5b9c818f3d6569796bd
zcash: https://github.com/bitcoin/bitcoin/pull/7913
2021-02-19 15:11:22 -07:00
Jorge Timón c3983ccb1c scripted-diff: Remove #include <boost/foreach.hpp>
-BEGIN VERIFY SCRIPT-
sed -i ':a;N;$!ba;s/#include <boost\/foreach.hpp>\n//' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp
-END VERIFY SCRIPT-
2020-11-23 23:07:15 +00:00
Jack Grigg a62405f44f Store imported Sapling ExtFVKs in wallet database 2020-02-21 01:32:15 +00:00
Jack Grigg b62bb98087 Remove default address parameter from Sapling keystore methods
Now that we store SaplingExtendedFullViewingKey internally, we have
access to the default address everywhere we require it.
2020-02-20 13:01:49 +00:00
Jack Grigg d74fdd76eb SaplingFullViewingKey -> SaplingExtendedFullViewingKey in keystore maps
All of these maps are created from scratch on wallet load, so we can
alter their contents without compatibility concerns. With this change,
we can use the existing maps to implement viewing key support. The
downside is that the wallet will take more space in memory, but that can
easily be improved in future by storing ExtFVK fingerprints in some of
the maps (which would improve memory usage even compared to the original
layout).
2020-02-20 13:01:49 +00:00
Matt Corallo e61f62923b
Add logic to track pubkeys as watch-only, not just scripts 2019-11-14 15:46:06 +00:00
Larry Ruane 5a5094bbb5 simplify locking, merge cs_SpendingKeyStore into cs_KeyStore 2019-11-03 19:53:28 -07:00
Daira Hopwood bc909a7a7f Replace http with https: in links to the MIT license.
Also change MIT/X11 to just MIT, since no distinction was intended.

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
2019-07-18 15:26:01 +01:00
Simon cb9cff5fdc Fix deadlock from calling CWallet::AddSaplingIncomingViewingKey instead of CBasicKeyStore::AddSaplingIncomingViewingKey 2018-10-05 21:15:08 -07:00
Homu 325ba00336 Auto merge of #3542 - Eirik0:3511-update-address-mapping, r=bitcartel
Add newly discovered sapling addresses to the wallet when decrypting

Closes #3511
2018-10-03 21:49:32 -07:00
Eirik Ogilvie-Wigley a4ecd0fa72 Add newly discovered sapling addresses to the wallet 2018-10-01 09:34:25 -06:00
Eirik Ogilvie-Wigley 83c4e360da Address need not be optional when adding sapling keys 2018-09-27 15:44:04 -06:00
Eirik Ogilvie-Wigley 5e360fb29f Add sapling spending keys to z_exportwallet 2018-09-14 15:07:15 -06:00
Jack Grigg b33a7ec46e
wallet: Don't allow an HDSeed to be overwritten
We can maybe relax this restriction later once we have worked out the UX
implications.
2018-09-03 10:45:37 +01:00
Jack Grigg 70b4ad2dcd
wallet: Switch from SaplingSpendingKey to SaplingExtendedSpendingKey
The wallet now only stores Sapling extended spending keys, and thus can
only be used with keys generated from an HDSeed via ZIP 32.

Note that not all Sapling keys in the wallet will correspond to the
wallet's HDSeed, as a standalone Sapling xsk can be imported via
z_importkey. However, it must have been generated from a seed itself,
and thus is more likely to be backed up elsewhere.
2018-09-03 10:45:37 +01:00
Jack Grigg 70c8c25e4b
Store HDSeed in CBasicKeyStore 2018-09-03 10:27:52 +01:00
Jack Grigg 25d5e80cbe
Rename *SpendingKey -> *SproutSpendingKey
Also GetPaymentAddresses -> GetSproutPaymentAddresses
2018-08-03 10:10:26 +01:00
Jack Grigg 4c77517772
Rename *ViewingKey* -> *SproutViewingKey* 2018-08-03 02:23:38 +01:00