Skip to content

Commit

Permalink
Merge branch 'pnowosie-pnowosie/add-password-to-seed-calculation'
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Nov 30, 2023
2 parents dca85a9 + c79963b commit 75e088b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hdwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newWallet(seed []byte) (*Wallet, error) {
}

// NewFromMnemonic returns a new wallet from a BIP-39 mnemonic.
func NewFromMnemonic(mnemonic string) (*Wallet, error) {
func NewFromMnemonic(mnemonic string, passOpt ...string) (*Wallet, error) {
if mnemonic == "" {
return nil, errors.New("mnemonic is required")
}
Expand All @@ -69,7 +69,7 @@ func NewFromMnemonic(mnemonic string) (*Wallet, error) {
return nil, errors.New("mnemonic is invalid")
}

seed, err := NewSeedFromMnemonic(mnemonic)
seed, err := NewSeedFromMnemonic(mnemonic, passOpt...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (w *Wallet) SignTx(account accounts.Account, tx *types.Transaction, chainID

signer := types.LatestSignerForChainID(chainID)

// Sign the transaction and verify the sender to avoid hardware fault surprises
// Sign the transaction and verify the sender to avoid hardware fault surprises
signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -492,12 +492,17 @@ func NewSeed() ([]byte, error) {
}

// NewSeedFromMnemonic returns a BIP-39 seed based on a BIP-39 mnemonic.
func NewSeedFromMnemonic(mnemonic string) ([]byte, error) {
func NewSeedFromMnemonic(mnemonic string, passOpt ...string) ([]byte, error) {
if mnemonic == "" {
return nil, errors.New("mnemonic is required")
}

return bip39.NewSeedWithErrorChecking(mnemonic, "")
password := ""
if len(passOpt) > 0 {
password = passOpt[0]
}

return bip39.NewSeedWithErrorChecking(mnemonic, password)
}

// DerivePrivateKey derives the private key of the derivation path.
Expand Down

0 comments on commit 75e088b

Please sign in to comment.