类型的参数'缓冲区的参数不能分配给类型的参数' String |数字| bn'
我有一个打字稿项目。该项目中的功能是以下函数:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论