如何在 react native 钱包中使用 github 的 kadena-io/cardano-crypto.js 助记词

How to use github's kadena-io/cardano-crypto.js mnemonic in react native wallet

提问人:Tiny 提问时间:4/1/2022 最后编辑:herrtimTiny 更新时间:5/26/2022 访问量:362

问:

我想使用 github 的 kadena-io/cardano-crypto.js.This is the cardano-crypto.js 链接: https://github.com/kadena-io/cardano-crypto.js.但是使用时是错误的。我已经尝试了很多方法来修复错误,但它不起作用。要在 cardano-crypto.js 中获取 lib.js 文件,首先我必须安装 npm。我做到了。然后是 lib.js 文件。然后我尝试将 cardano-crypto.js 的 mnemonicToRootKeyPair 函数导入我的 react-native 钱包。但是有一个错误。为了解决错误,首先我尝试使用节点模块导入 cardano-crypto.js。然后我尝试在没有node_module的情况下导入。我以多种方式导入。

从“path”导入 {}

,

_importDefault (require ('path'))

.但不知何故,Cardano-crypto.js的助记词ToRootKeyPair无法运行/导入。错误提示 lib.js:找不到路径。但是 lib.js 文件就在那里。现在我该如何解决这个问题:如何在我们的 react 原生钱包中使用 cardano-crypto.js 的 mnemonicToRootKeyPair

这是我想使用的 cardano-crypto.js 助记符ToRootKeyPair函数代码:

async function mnemonicToRootKeypair(mnemonic, derivationScheme) {
  validateDerivationScheme(derivationScheme)

  if (derivationScheme === 1) {
    return mnemonicToRootKeypairV1(mnemonic)
  } else if (derivationScheme === 2) {
    return mnemonicToRootKeypairV2(mnemonic, '')
  } else {
    throw Error(`Derivation scheme ${derivationScheme} not implemented`)
  }
}

这是我在react原生钱包中使用该函数时的错误: 构建 JavaScript 包失败。 无法从 C:\Users\DCL\Desktop\app\cardanoCrypto\lib.js 解析模块路径:在项目中找不到路径。

JavaScript React-Native 区块链 助记 kadena

评论

3赞 SamsonTheBrave 4/1/2022
请发布错误和您尝试实现的代码
0赞 Tiny 4/1/2022
我在帖子中提到了我想使用什么代码以及存在什么样的错误。请稍微检查一下。这是我的react原生钱包代码,我在其中使用了上述代码:import {mnemonicToRootKeypair} from '../cardanoCrypto' function CreateNewWallet({ navigation }) { const { walletInfo } = useContext(UserContext); const keyPairValue = mnemonicToRootKeypair(walletInfo?.助记词,1);控制台.log(keyPairValue);

答: 暂无答案