|
@@ -78,27 +78,27 @@ export const useWalletStore = defineStore("useWalletStore", {
|
|
|
if (!web3) throw new Error("区块链连接失败");
|
|
|
|
|
|
// 助记词路径
|
|
|
- if (isMnemonic) {
|
|
|
- let wordArray;
|
|
|
- if (Array.isArray(this.words)) {
|
|
|
- if (this.words.length === 1 && typeof this.words[0] === "string") {
|
|
|
- wordArray = this.words[0].trim().split(/[\s,]+/).filter(Boolean);
|
|
|
- } else {
|
|
|
- wordArray = this.words.flat().map(w => String(w).trim()).filter(Boolean);
|
|
|
- }
|
|
|
- } else {
|
|
|
- wordArray = String(this.words)
|
|
|
- .trim()
|
|
|
- .split(/[\s,]+/)
|
|
|
- .filter(Boolean);
|
|
|
- }
|
|
|
- if (![12, 24].includes(wordArray.length)) {
|
|
|
- throw new Error("助记词应为12或24个单词");
|
|
|
- }
|
|
|
- const mnemonic = wordArray.join(" ");
|
|
|
- const hdwallet = web3.eth.accounts.wallet.create(1, mnemonic);
|
|
|
- this.privateKey = hdwallet[0].privateKey;
|
|
|
- }
|
|
|
+ // if (isMnemonic) {
|
|
|
+ // let wordArray;
|
|
|
+ // if (Array.isArray(this.words)) {
|
|
|
+ // if (this.words.length === 1 && typeof this.words[0] === "string") {
|
|
|
+ // wordArray = this.words[0].trim().split(/[\s,]+/).filter(Boolean);
|
|
|
+ // } else {
|
|
|
+ // wordArray = this.words.flat().map(w => String(w).trim()).filter(Boolean);
|
|
|
+ // }
|
|
|
+ // } else {
|
|
|
+ // wordArray = String(this.words)
|
|
|
+ // .trim()
|
|
|
+ // .split(/[\s,]+/)
|
|
|
+ // .filter(Boolean);
|
|
|
+ // }
|
|
|
+ // if (![12, 24].includes(wordArray.length)) {
|
|
|
+ // throw new Error("助记词应为12或24个单词");
|
|
|
+ // }
|
|
|
+ // const mnemonic = wordArray.join(" ");
|
|
|
+ // const hdwallet = web3.eth.accounts.wallet.create(1, mnemonic);
|
|
|
+ // this.privateKey = hdwallet[0].privateKey;
|
|
|
+ // }
|
|
|
if (!/^0x[0-9a-fA-F]{64}$/.test(this.privateKey)) {
|
|
|
throw new Error("私钥格式不正确");
|
|
|
}
|