|
| 1 | +const {ethers} = require("hardhat"); |
| 2 | +const bip39 = require('bip39'); |
| 3 | + |
| 4 | +// 通过助记词创建钱包 |
| 5 | +//squirrel refuse ozone miracle hollow renew sail clever fruit chaos merit brown |
| 6 | +function* permutations(arr, n = arr.length) { |
| 7 | + if (n <= 1) yield arr.slice(); |
| 8 | + else for (let i = 0; i < n; i++) { |
| 9 | + yield* permutations(arr, n - 1); |
| 10 | + const j = n % 2 ? 0 : i; |
| 11 | + [arr[n - 1], arr[j]] = [arr[j], arr[n - 1]]; |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +const words = mnemonic.split(' '); |
| 16 | + |
| 17 | +for (const perm of permutations(words)) { |
| 18 | + const testMnemonic = perm.join(' '); |
| 19 | + console.log(testMnemonic); |
| 20 | + if (bip39.validateMnemonic(testMnemonic)) { |
| 21 | + |
| 22 | + |
| 23 | + for (let i = 0; i <= 10; i++) { |
| 24 | + let path = `m/44'/60'/1'/0/${i}`; |
| 25 | + let secondMnemonicWallet = ethers.Wallet.fromMnemonic(testMnemonic, path); |
| 26 | + if (secondMnemonicWallet.address.toLowerCase() === "0x55A68930b14f8166AD0c432C01d68739B94d3cf3".toLowerCase()) { |
| 27 | + console.log(`Valid mnemonic: ${testMnemonic} with path: ${path}`); |
| 28 | + break; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + } |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +// if (validMnemonics.length > 0) { |
| 37 | +// console.log("Valid mnemonic orders found:"); |
| 38 | +// validMnemonics.forEach(mnemonic => console.log(mnemonic)); |
| 39 | +// } else { |
| 40 | +// console.error("No valid mnemonic order found."); |
| 41 | +// } |
| 42 | + |
| 43 | +// const wallet2 = ethers.Wallet.fromMnemonic(validMnemonics[0] ? validMnemonics[0] : mnemonic); |
| 44 | +// console.log("Address: " + wallet2.address); |
| 45 | + |
| 46 | +// // Load the second account from a mnemonic |
| 47 | +// let path = "m/44'/60'/1'/0/0"; |
| 48 | +// let secondMnemonicWallet = ethers.Wallet.fromMnemonic(validMnemonics[0] ? validMnemonics[0] : mnemonic, path); |
| 49 | +// // Load using a non-english locale wordlist (the path "null" will use the default) |
| 50 | +// // let secondMnemonicWallet = ethers.Wallet.fromMnemonic(mnemonic, null, ethers.wordlists.ko); |
0 commit comments