TypeError: Class constructor CryptoFactory cannot be invoked without 'new'

TypeError: Class constructor CryptoFactory cannot be invoked without 'new'

我想用sawtooth-sdk,引导代码(https://sawtooth.hyperledger.org/docs/core/releases/latest/_autogen/sdk_submit_tutorial_js.html):

const {createContext, CryptoFactory} = require('sawtooth-sdk/signing')

const context = createContext('secp256k1')
const privateKey = context.newRandomPrivateKey()
const signer = CryptoFactory(context).newSigner(privateKey)

但是错误:

TypeError: Class constructor CryptoFactory cannot be invoked without 'new'

如错误所述,您应该更改:

const signer = CryptoFactory(context).newSigner(privateKey)

至:

const signer = (new CryptoFactory(context)).newSigner(privateKey)