Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement BIP 39 and HD wallet features #1705

Merged
merged 47 commits into from
May 19, 2021
Merged

Implement BIP 39 and HD wallet features #1705

merged 47 commits into from
May 19, 2021

Conversation

someone235
Copy link
Collaborator

@someone235 someone235 commented May 11, 2021

Closes #1644

@codecov
Copy link

codecov bot commented May 11, 2021

Codecov Report

Merging #1705 (3bc52f0) into v0.11.0-dev (010df3b) will decrease coverage by 0.69%.
The diff coverage is 18.39%.

Impacted file tree graph

@@               Coverage Diff               @@
##           v0.11.0-dev    #1705      +/-   ##
===============================================
- Coverage        59.48%   58.78%   -0.70%     
===============================================
  Files              565      577      +12     
  Lines            22445    22774     +329     
===============================================
+ Hits             13351    13388      +37     
- Misses            6974     7257     +283     
- Partials          2120     2129       +9     
Impacted Files Coverage Δ
cmd/kaspawallet/balance.go 0.00% <0.00%> (ø)
cmd/kaspawallet/broadcast.go 0.00% <0.00%> (ø)
cmd/kaspawallet/common.go 0.00% <ø> (ø)
cmd/kaspawallet/config.go 0.00% <0.00%> (ø)
cmd/kaspawallet/create.go 0.00% <0.00%> (ø)
cmd/kaspawallet/create_unsigned_tx.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/client/client.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/server/address.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/server/balance.go 0.00% <0.00%> (ø)
cmd/kaspawallet/daemon/server/broadcast.go 0.00% <0.00%> (ø)
... and 38 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 010df3b...3bc52f0. Read the comment docs.

@@ -62,13 +66,20 @@ type signConfig struct {
}

type broadcastConfig struct {
RPCServer string `long:"rpcserver" short:"s" description:"RPC server to connect to"`
Transaction string `long:"transaction" short:"t" description:"The signed transaction to broadcast (encoded in hex)" required:"true"`
ServerAddress string `long:"walletserver" short:"s" description:"Wallet server to connect to"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact that it's usually called daemon, but here it's called "Server".
Please pick one and use everywhere.

Also, I'd add (default: localhost) in the description. (It is the default, right?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed this part:
Also, I'd add (default: localhost) in the description. (It is the default, right?)

cmd/kaspawallet/create.go Outdated Show resolved Hide resolved
cmd/kaspawallet/create.go Outdated Show resolved Hide resolved
cmd/kaspawallet/create.go Show resolved Hide resolved
"os"

"github.com/kaspanet/kaspad/cmd/kaspawallet/keys"
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet"
"github.com/pkg/errors"
)

func create(conf *createConfig) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather if all the logic in this function (and similar functions as well) will be in libkaspawallet.
(Just extract the needed info out of config first, so that the lib doesn't rely on config, and maybe also the creation of the keys file)

We want a re-usable library that can be used for multiple wallets, even ones that don't want to use the daemon.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the way it worked before and not related to this PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, Created issue, feel free to add info to the issue / fight me if you think this is not what we want.
#1724

cmd/kaspawallet/libkaspawallet/bip39.go Outdated Show resolved Hide resolved
return bip32.KaspaSimnetPrivate, nil
}

return [4]byte{}, errors.Errorf("unknown network %s", params.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very critical, but I'd put this inside default:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you missed this comment (if you purposefully ignored because you disagree - that's fine, just LMK)

cmd/kaspawallet/send.go Outdated Show resolved Hide resolved
cmd/kaspawallet/sign.go Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
}

// collectUTXOsFromFarAddresses collects UTXOs
// from s.nextSyncStartIndex to s.nextSyncStartIndex+numIndexesToQuery
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather if these comments were more accessible (a.k.a. didn't assume person knows the meaning of variables such as s.nextSyncStartIndex.

In other words, explain the difference between Close and Far addresses in laymen terms.

}

err = keys.WriteKeysFile(
conf.NetParams(), conf.KeysFile, encryptedPrivateKeys, publicKeys, conf.MinimumSignatures, conf.ECDSA)
cosignerIndex, err := libkaspawallet.MinimumCosignerIndex(signerExtendedPublicKeys, extendedPublicKeys)
Copy link
Collaborator

@svarogg svarogg May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sort is an implementation detail, why should the user be aware of it?

The sort is not an implementation detail, it is defined in the BIP.

The assumption is that keys are always ordered except in exported functions
Couldn't it be nice if the assumption had some (even if weak) guarantee using the type-system.

Correct me if I'm wrong, but it seems like addressesToQuery assumes s.keysFile.ExtendedPublicKeys is sorted, while in reality it isn't so.
(also dumpUnencrypted Data, where it's not as critical, but still could be nice)

Even if it is, I'd really love it if you had to call sortPublicKeys only once, not every time you need this assumption - this is very error prone, and someone will forget.

cmd/kaspawallet/daemon/server/address.go Outdated Show resolved Hide resolved
@@ -239,19 +241,24 @@ func getAEAD(password, salt []byte) (cipher.AEAD, error) {
return chacha20poly1305.NewX(key)
}

func decryptPrivateKey(encryptedPrivateKey *EncryptedPrivateKey, password []byte) ([]byte, error) {
func decryptMnemonic(encryptedPrivateKey *EncryptedMnemonic, password []byte) (string, error) {
aead, err := getAEAD(password, encryptedPrivateKey.salt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And... are everyone supposed to know that?

return bip32.KaspaSimnetPrivate, nil
}

return [4]byte{}, errors.Errorf("unknown network %s", params.Name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you missed this comment (if you purposefully ignored because you disagree - that's fine, just LMK)

return nil, err
}

psTx, err := libkaspawallet.CreateUnsignedTransaction(s.keysFile.ExtendedPublicKeys,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please search all over the code for "psTx" and rename to something that everyone understand.

svarogg
svarogg previously approved these changes May 18, 2021
privateKey, publicKey, err := keyPairFunction(i)
encryptedPrivateKeys = make([]*EncryptedMnemonic, 0, len(mnemonics))
for _, mnemonic := range mnemonics {
extendedPublicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(params, mnemonic, isMultisig)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now we save the mnemonics in the DB?
Is there any reason why it is necessary?
why not internally only use extended keys and only in backup/recover use mnemonics?
This will drastically decrease the attack vector that bip39 imposes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

@svarogg svarogg merged commit 4658f9d into v0.11.0-dev May 19, 2021
@svarogg svarogg deleted the bip39 branch May 19, 2021 07:03
@dravenk dravenk mentioned this pull request May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants