hedera-sdk-js icon indicating copy to clipboard operation
hedera-sdk-js copied to clipboard

Make `words` in `Mnemonic` a publicly visible field

Open jackthta opened this issue 3 years ago • 0 comments

Description

I used to be able to Mnemonic.generate() and access the mnemonic words directly like so ...

Mnemonic.generate().then((mnemonic) => {
  const mnemonicPhrase = mnemonic.words; // 👈
  // do stuff with `mnemonicPhrase`
})

... but it seems that the words property is now wrapped inside a _mnemonic property, so to have the above example work, I would have to do this:

Mnemonic.generate().then((mnemonic) => {
  const mnemonicPhrase = mnemonic._mnemonic.words; // 👈
  // do stuff with `mnemonicPhrase`
})

I don't think it's in best practice to access _-prefixed properties like that, so my temporary workaround has been to do ...

Mnemonic.generate().then((mnemonic) => {
  const mnemonicPhrase = mnemonic.toString().split(' '); // 👈
  // do stuff with `mnemonicPhrase`
})

... but that's pretty verbose and I think it would be very helpful and convenient to just be able to access the words property like in the first example.

Steps to reproduce

Mnemonic.generate().then((mnemonic) => {
  // follow steps #2 and #3 in here
})
  1. Trying to access mnemonic.words shouldn't work.
  2. Trying to see what's inside mnemonic via console.log(mnemonic) and there should be a _mnemonic property that contains the desired words property.

Additional context

No response

Hedera network

mainnet

Version

2.18.0

Operating system

No response

jackthta avatar Oct 11 '22 21:10 jackthta