【问题标题】:Failing in convert a mnemonic to a seed for a solana wallet未能将助记词转换为 solana 钱包的种子
【发布时间】:2021-09-09 13:47:09
【问题描述】:

我正在尝试在后端使用钱包种子,使用nodejs,来连接区块链。来自"@solana/web3.js" 库的Keypair 模块有一个fromSeed 方法,我将它与来自bip39 库的另一种方法的输入一起使用,它将我的助记符转换为种子。这是我的代码

const mnemonic = <My-mnemonic>
console.log(bip39.validateMnemonic(mnemonic)) // true
bip39.mnemonicToSeed(mnemonic).then(buffer => Keypair.fromSeed(buffer)).catch(err => console.log(err))

这是我的错误

Error: bad seed size
    at Function.nacl.sign.keyPair.fromSeed (/home/diazrock/Carrera/Elasbit/NFT's/mint-nft-solana/node_modules/tweetnacl/nacl-fast.js:2329:11)
    at Function.fromSeed (/home/diazrock/Carrera/Elasbit/NFT's/mint-nft-solana/node_modules/@solana/web3.js/lib/index.cjs.js:5625:53)
    at bip39.mnemonicToSeed.then.buffer (repl:1:55)

【问题讨论】:

    标签: node.js blockchain wallet solana


    【解决方案1】:

    Keypair.fromSeed() 采用 Unit8Array check

    buffer.toJSON().data 这会返回一个 64 长度的数组,因此它分别包含公钥和私钥。检查this

    let a = new Uint8Array(buffer.toJSON().data.slice(0,32))
    const key = Keypair.fromSeed(a);
    

    我尝试了上述方法,并且有效。 key 有一个公钥和私钥组件。

    【讨论】:

      猜你喜欢
      • 2022-06-17
      • 1970-01-01
      • 2022-10-15
      • 2022-12-17
      • 2022-06-20
      • 1970-01-01
      • 2021-11-13
      • 2022-06-17
      • 2022-06-14
      相关资源
      最近更新 更多