类型的参数'缓冲区的参数不能分配给类型的参数' String |数字| bn'

发布于 2025-02-09 21:10:07 字数 851 浏览 1 评论 0原文

我有一个打字稿项目。该项目中的功能是以下函数:

import { hexToBytes, toHex } from 'web3-utils'

const signMessage = (msg: Hash) => {
    //  msg is a keccak-256 hash
    //
    const hashed = Buffer.from(hexToBytes(msg))
    const prvKey = Buffer.from(process.env.PRIVATE_KEY, "hex")
    const { signature, recid } = ecdsaSign(hashed, prvKey)
    // add key recovery parameter
    const ethSignature = new Uint8Array(65)
    ethSignature.set(signature)
    ethSignature[64] = recid
    return toHex(Buffer.from(ethSignature))
  }

这是从

const ethSignature: Uint8Array
Argument of type 'Buffer' is not assignable to parameter of type 'string | number | BN'.
  Type 'Buffer' is missing the following properties from type 'BN': clone, toNumber, toArray, toArrayLike, and 81 more.ts(2345) 

这里发生了什么,我该如何解决此问题?

I have a Typescript project. Within that project is the following function:

import { hexToBytes, toHex } from 'web3-utils'

const signMessage = (msg: Hash) => {
    //  msg is a keccak-256 hash
    //
    const hashed = Buffer.from(hexToBytes(msg))
    const prvKey = Buffer.from(process.env.PRIVATE_KEY, "hex")
    const { signature, recid } = ecdsaSign(hashed, prvKey)
    // add key recovery parameter
    const ethSignature = new Uint8Array(65)
    ethSignature.set(signature)
    ethSignature[64] = recid
    return toHex(Buffer.from(ethSignature))
  }

This is taken from here. In that context, the function works fine. However, VSCode semantic highlighting marks the final line of the function as an error and provides the following:

const ethSignature: Uint8Array
Argument of type 'Buffer' is not assignable to parameter of type 'string | number | BN'.
  Type 'Buffer' is missing the following properties from type 'BN': clone, toNumber, toArray, toArrayLike, and 81 more.ts(2345) 

What is going on here, and how do I resolve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文