You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中使用tweetnacl调用box.keyPair()出现no PRNG错误

React Native使用tweetnacl时出现no PRNG错误

在React Native项目中使用tweetnacl库执行以下代码时:

const test = nacl.box.keyPair();

运行时在randombytes环节抛出no PRNG错误。

项目的package.json配置如下:

{
  "dependencies": {
    "@react-navigation/material-bottom-tabs": "^6.2.15",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/native-stack": "^6.9.12",
    "bs58": "^5.0.0",
    "react": "18.2.0",
    "react-native": "0.71.3",
    "react-native-get-random-values": "^1.8.0",
    "react-native-paper": "^5.4.1",
    "react-native-safe-area-context": "^4.5.0",
    "react-native-screens": "^3.20.0",
    "react-native-webview": "^11.26.1",
    "tweetnacl": "^1.0.3"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native-community/eslint-config": "^3.2.0",
    "@tsconfig/react-native": "^2.0.2",
    "@types/jest": "^29.2.1",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "metro-react-native-babel-preset": "0.73.7",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  }
}

错误信息:Error: no PRNG,触发位置为randombytes相关调用。

内容的提问来源于stack exchange,提问作者Jerry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 05:42:54