rust 如何在dApp NEAR中存储API密钥

4nkexdtk  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(77)

例如,我的应用程序使用IPFS,我通过www.example.com访问它web3.storage。但是为了让web3.storage工作,你需要一个API令牌,我为此支付了费用。
如果一切都是开源的,在哪里存储这个令牌?在前端,任何人都可以看到我的令牌并开始使用它。在智能合约中,不可能处理大数据
该文档如下所述:

function getAccessToken () {
  // If you're just testing, you can paste in a token
  // and uncomment the following line:
  // return 'paste-your-token-here'

  // In a real app, it's better to read an access token from an
  // environement variable or other configuration that's kept outside of
  // your code base. For this to work, you need to set the
  // WEB3STORAGE_TOKEN environment variable before you run your code.
  return process.env.WEB3STORAGE_TOKEN
}

但是任何人都可以很容易地调试代码并找到这个令牌。

csbfibhn

csbfibhn1#

如果一切都是开源的,在哪里存储这个令牌?在前端,任何人都可以看到我的令牌并开始使用它。在智能合约中,不可能处理大数据
这个问题没有解决的办法。所有面向前端的API令牌都是可窃取的。你只需要监视你的API密钥,并在发生这种情况时轮换它们。
在理想的世界中,用户自己会为他们的钱包付费,然后提供API访问支付,但这不会很快发生。

相关问题