I want to do some specific task using Javascript Sdk of sawtooth in Node Js but unable to run it successfully. Please find the code below, am getting this error as below.
Can someone help me solve this error?
//Errror
{
"error": {
"code": 30,
"message": "The submitted BatchList was rejected by the validator. It was poorly formed, or has an invalid signature.",
"title": "Submitted Batches Invalid"
}
}
//Code
const {createContext, CryptoFactory} = require('sawtooth-sdk/signing')
const context = createContext('secp256k1')
const privateKey = context.newRandomPrivateKey();
const signer = new CryptoFactory(context).newSigner(privateKey)
const cbor = require('cbor')
const payload = {
Verb: 'set',
Name: 'foo',
Value: 42
}
const payloadBytes = cbor.encode(payload)
const {createHash} = require('crypto')
const {protobuf} = require('sawtooth-sdk')
const transactionHeaderBytes = protobuf.TransactionHeader.encode({
familyName: 'intkey',
familyVersion: '1.0',
inputs: [createHash('sha512').update("intkey").digest('hex')],
outputs: [createHash('sha512').update("intkey").digest('hex')],
signerPublicKey: signer.getPublicKey().asHex(),
// In this example, we're signing the batch with the same private key,
// but the batch can be signed by another party, in which case, the
// public key will need to be associated with that key.
batcherPublicKey: signer.getPublicKey().asHex(),
// In this example, there are no dependencies. This list should include
// an previous transaction header signatures that must be applied for
// this transaction to successfully commit.
// For example,
// dependencies: ['540a6803971d1880ec73a96cb97815a95d374cbad5d865925e5aa0432fcf1931539afe10310c122c5eaae15df61236079abbf4f258889359c4d175516934484a'],
dependencies: [],
payloadSha512: createHash('sha512').update(payloadBytes).digest('hex')
}).finish()
const signature = signer.sign(transactionHeaderBytes);