-
Notifications
You must be signed in to change notification settings - Fork 232
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
Conversation
…he relevant endpoints
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
cmd/kaspawallet/config.go
Outdated
@@ -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"` |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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?)
"os" | ||
|
||
"github.com/kaspanet/kaspad/cmd/kaspawallet/keys" | ||
"github.com/kaspanet/kaspad/cmd/kaspawallet/libkaspawallet" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func create(conf *createConfig) error { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
return bip32.KaspaSimnetPrivate, nil | ||
} | ||
|
||
return [4]byte{}, errors.Errorf("unknown network %s", params.Name) |
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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)
} | ||
|
||
// collectUTXOsFromFarAddresses collects UTXOs | ||
// from s.nextSyncStartIndex to s.nextSyncStartIndex+numIndexesToQuery |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
@@ -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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
privateKey, publicKey, err := keyPairFunction(i) | ||
encryptedPrivateKeys = make([]*EncryptedMnemonic, 0, len(mnemonics)) | ||
for _, mnemonic := range mnemonics { | ||
extendedPublicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(params, mnemonic, isMultisig) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
Closes #1644