5 solana使用助记词恢复钱包为何不一致

不知哪里出了问题,感觉是let account = solanaWeb3.Keypair.fromSeed(fromSeedArray.slice(0, 32))使用不当,但fromSeed只接受32位

const solanaWeb3 = require('@solana/web3.js');
const bs58 = require('bs58')
let pharseWord =
'monitor word flag cheap shield split success table course illness company crumble used mail shiver behave drift impact earth settle outer glad ankle only'
let fromSeedArray = new TextEncoder().encode(pharseWord)
let account = solanaWeb3.Keypair.fromSeed(fromSeedArray.slice(0, 32))
let address = account.publicKey.toBase58()
let secretKey = account.secretKey
console.log(address)
// HvvHwAyreoLpZKDi2FGPdhgr9PvpwXSy78BrcHYaoqVx
console.log(secretKey)
// [109, 111, 110, 105, 116, 111, 114, 32, 119, 111, 114, 100, 32, 102, 108, 97, 103, 32, 99, 104, 101, 97, 112, 32, 115, 104, 105, 101, 108, 100, 32, 115, 251, 139, 7, 247, 125, 140, 35, 96, 231, 98, 187, 175, 113, 203, 111, 163, 155, 254, 37, 94, 139, 4, 53, 241, 185, 155, 190, 177, 238, 224, 146, 111]
console.log(bs58.encode(account.secretKey))
// 3BuJbD6ZzgUimq46wsTRQ68EcSBQ69vnBbSSgwB9G7JReTbBpXUMWN8oQXyeGdnxJD1BgBPvUMUVp6xXMCy9H2ei

自己用solana-web3.js得出的结果

address:
HvvHwAyreoLpZKDi2FGPdhgr9PvpwXSy78BrcHYaoqVx
secretKey:
3BuJbD6ZzgUimq46wsTRQ68EcSBQ69vnBbSSgwB9G7JReTbBpXUMWN8oQXyeGdnxJD1BgBPvUMUVp6xXMCy9H2ei

用插件phantom wallet或者TokenPocket得出的结果

address:
J4NQd17FbmgGzPBgBZqjehwkYH1acwV5ZVpXvXe3h11c
secretKey:
5dMuJ41cqommWqEd6dvc1Z74YipSY1hdtntA27MXHQKdFQp5MQB2kBdnaAYQnVF6FUzgAzkwD5EKvbz2AdsRKPa2
请先 登录 后评论

最佳答案 2021-11-01 10:18

不知哪里出了问题,感觉是let account = solanaWeb3.Keypair.fromSeed(fromSeedArray.slice(0, 32))使用不当,但fromSeed只接受32位

这里不能直接转unit8Array,需要通过 bip39 与ed25519 获取到fromSeed

const bip39 = require('bip39')
const ed25519 = require('ed25519-hd-key')
const derivePath = "m/44'/501'/0'/0'"
const seed = await bip39.mnemonicToSeed(mnemonic)
const derivedSeed = ed25519.derivePath(derivePath, seed.toString('hex'))
.key
请先 登录 后评论

其它 3 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
663 - 合约
请先 登录 后评论
khjshi
请先 登录 后评论
  • 4 关注
  • 0 收藏,4820 浏览
  • khjshi 提出于 2021-10-29 08:52