简体   繁体   English

编码为十六进制字符串:参数必须是字符串node.js

[英]Encode to hex string: argument must be a string node.js

I am trying to implement a simple transaction flow in hyper ledger sawtooth, for creating transaction it must through some steps 我正在尝试在超级账本锯齿中实现简单的交易流程,因此创建交易必须通过一些步骤

/*
* Create the transactions
*/
const createTransaction = function createTransaction(transactionHeaderBytes, payloadBytes) {

    const signature = signer.sign(transactionHeaderBytes)

    console.log(signature);

    return transaction = protobuf.Transaction.create({
        header: transactionHeaderBytes,
        headerSignature:Buffer.from(signature, "hex"),
        payload: payloadBytes
    });
}

I need to encode headerSignature to a hex string ,but i am getting the following error 我需要将headerSignature编码为十六进制字符串,但出现以下错误

Argument must be a string

But the console.log(signature); 但是console.log(signature); gives the following result a51d254f0c27f15abb016030eeb9e38b5ee06ee13d28d88ac5f5cc13a2520b42088090a1d1d19d321098996dc980b3f94cfc84ba0399a73ba7cd9ddc9b2a453d 提供以下结果a51d254f0c27f15abb016030eeb9e38b5ee06ee13d28d88ac5f5cc13a2520b42088090a1d1d19d321098996dc980b3f94cfc84ba0399a73ba7cd9ddc9b2a453d

UPDATE UPDATE

Error log 错误日志

TypeError: Argument must be a string
    at Op.writeStringBuffer [as fn] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/protobufjs/src/writer_buffer.js:61:13)
    at BufferWriter.finish (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/protobufjs/src/writer.js:449:14)
    at Object.createBatchHeader (/var/accubits-workspace/hypeerledger-sawtooth/tuts/helpers/private-key.js:82:8)
    at app.get (/var/accubits-workspace/hypeerledger-sawtooth/tuts/index.js:24:32)
    at Layer.handle [as handle_request] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/layer.js:95:5)
    at next (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/layer.js:95:5)
    at /var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/var/accubits-workspace/hypeerledger-sawtooth/tuts/node_modules/express/lib/router/index.js:335:12)

The error is not in Buffer.from but in protobuf.Transaction.create 错误不在Buffer.from而是在protobuf.Transaction.create

headerSignature needs to be a string , and you're passing a Buffer headerSignature需要为string ,并且您正在传递Buffer

According to the documentation it should be like this: 根据文档,它应该是这样的:

const signature = signer.sign(transactionHeaderBytes)

const transaction = protobuf.Transaction.create({
    header: transactionHeaderBytes,
    headerSignature: signature,
    payload: payloadBytes
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JsonWebTokenError: jwt 必须是字符串,node.js - JsonWebTokenError: jwt must be a string, node.js 在 node js / javascript 中使用 OR 条件时,传入的参数必须是 Buffer 或 12 个字节的字符串或 24 个十六进制字符的字符串 - Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters while using OR condition in node js / javascript node.js和PostgreSQL查询-抛出新的TypeError('第一个参数必须是字符串或Buffer'); - node.js and PostgreSQL query - throw new TypeError('first argument must be a string or Buffer'); node.js请求POST数组“第一个参数必须是字符串或缓冲区” - node.js request POST array “first argument must be string or buffer” 遇到node.js TypeError:第一个参数必须是字符串或具有尽可能简单脚本的Buffer - running into node.js TypeError: First argument must be a string or Buffer with the simplest possible script “第一个参数必须是字符串或缓冲区” - 遵循 w3schools 的 Node.js 教程时出错 - "First argument must be a string or Buffer"- error when following w3schools' Node.js tutorial TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型 Node.JS - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string Node.JS 使用Windows 1252在node.js中编码字符串 - Encode a string using windows 1252 in node.js 从node.js返回JSON编码字符串 - Returning JSON encode string from node.js 错误:传入的参数必须是12字节的单个字符串或24个十六进制字符的字符串,它在mongodb和节点中 - Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters, its in mongodb and node
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM