I'm facing a challenge with my BIP39 passphrase which consists of 24 words for recovering my cryptocurrency wallet. Unfortunately, the passphrase does not validate due to a checksum error in the last word. All the words in the passphrase are part of the available BIP39 words list, so my initial assumption is that I may have mistakenly switched the order of two adjacent words in the phrase/array.
My approach involves iterating through each word in an array, swapping it with the neighboring word, running a function check(phrase)
, reverting the swap operation, and moving on to the next word.
Here's an example:
initialPhrase = 'wordOne wordTwo wordThree'
firstAttempt = 'wordTwo wordOne wordThree'
secondAttempt = 'wordOne wordThree wordTwo'
How can I implement this logic using JavaScript assuming all words are stored in an array?