mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-24 06:25:55 +00:00
Adding passPhrase to function's signature
This commit is contained in:
parent
5388c974b5
commit
e251311fa4
@ -32,11 +32,12 @@ func dumpUnencryptedData(conf *dumpUnencryptedDataConfig) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
passPhrase = []byte(GetPassword("Enter passphrase (press 'ENTER' to skip):"))
|
||||
mnemonicPublicKeys := make(map[string]struct{})
|
||||
for i, mnemonic := range mnemonics {
|
||||
fmt.Printf("Mnemonic #%d:\n%s\n\n", i+1, mnemonic)
|
||||
publicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(conf.NetParams(), mnemonic, len(keysFile.ExtendedPublicKeys) > 1)
|
||||
publicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(conf.NetParams(), mnemonic, passPhrase, len(keysFile.ExtendedPublicKeys) > 1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -59,13 +59,22 @@ func encryptedMnemonicExtendedPublicKeyPairs(params *dagconfig.Params, mnemonics
|
||||
if subtle.ConstantTimeCompare(password, confirmPassword) != 1 {
|
||||
return nil, nil, errors.New("Passwords are not identical")
|
||||
}
|
||||
|
||||
passPhrase = []byte(GetPassword("Enter passphrase (press 'ENTER' to skip):"))
|
||||
if len(passPhrase) == 0 {
|
||||
confirmPassPhrase := []byte(GetPassword("Confirm passphrase:"))
|
||||
|
||||
if subtle.ConstantTimeCompare(passPhrase, confirmPassPhrase) != 1 {
|
||||
return nil, nil, errors.New("PassPhrase are not identical")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
encryptedPrivateKeys = make([]*EncryptedMnemonic, 0, len(mnemonics))
|
||||
extendedPublicKeys = make([]string, 0, len(mnemonics))
|
||||
|
||||
for _, mnemonic := range mnemonics {
|
||||
extendedPublicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(params, mnemonic, isMultisig)
|
||||
extendedPublicKey, err := libkaspawallet.MasterPublicKeyFromMnemonic(params, mnemonic, passPhrase, isMultisig)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func defaultPath(isMultisig bool) string {
|
||||
// MasterPublicKeyFromMnemonic returns the master public key with the correct derivation for the given mnemonic.
|
||||
func MasterPublicKeyFromMnemonic(params *dagconfig.Params, mnemonic string, passPhrase string, isMultisig bool) (string, error) {
|
||||
path := defaultPath(isMultisig)
|
||||
extendedKey, err := extendedKeyFromMnemonicAndPath(mnemonic, path, params)
|
||||
extendedKey, err := extendedKeyFromMnemonicAndPath(mnemonic, path, passPhrase, params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -52,7 +52,7 @@ func MasterPublicKeyFromMnemonic(params *dagconfig.Params, mnemonic string, pass
|
||||
}
|
||||
|
||||
func extendedKeyFromMnemonicAndPath(mnemonic string, path string, passPhrase string, params *dagconfig.Params) (*bip32.ExtendedKey, error) {
|
||||
seed := bip39.NewSeed(mnemonic, "")
|
||||
seed := bip39.NewSeed(mnemonic, passPhrase)
|
||||
version, err := versionFromParams(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -59,12 +59,13 @@ func sign(params *dagconfig.Params, mnemonic string, partiallySignedTransaction
|
||||
)
|
||||
partiallySignedTransaction.Tx.Inputs[i].SigOpCount = byte(len(partiallySignedInput.PubKeySignaturePairs))
|
||||
}
|
||||
|
||||
|
||||
passPhrase = []byte(GetPassword("Enter passphrase (press 'ENTER' to skip):"))
|
||||
signed := false
|
||||
for i, partiallySignedInput := range partiallySignedTransaction.PartiallySignedInputs {
|
||||
isMultisig := len(partiallySignedInput.PubKeySignaturePairs) > 1
|
||||
path := defaultPath(isMultisig)
|
||||
extendedKey, err := extendedKeyFromMnemonicAndPath(mnemonic, path, params)
|
||||
extendedKey, err := extendedKeyFromMnemonicAndPath(mnemonic, path, passPhrase, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user