类型错误:CryptoJS.SHA256 不是函数
import * as CryptoJS from 'crypto-js';
import * as ecdsa from 'elliptic';
import * as _ from 'lodash'
class Transaction {
id = null;
constructor(id, txIns, txOuts) {
this.id = id;
this.txIns = txIns;
this.txOuts = txOuts;
}
}
function getTransactionId (Transaction)
{
const txInContent = Transaction.txIns.txOutId + Transaction.txIns.txOutIndex;
// const txInContent = Transaction.TxIN.map((TxIN) => TxIN.txOutId + TxIN.txOutIndex).reduce((a, b) => a + b, '');
const txOutContent = Transaction.txOuts.amount + Transaction.txOuts.address;
// const txOutContent = Transaction.TxOut.map((TxOUT) => txOut.amount + txOut.address).reduce((a, b) => a + b, '');
return (txInContent + txOutContent).toString();
}
class TxIN {
txOutId = null;
txOutIndex = null;
signature = null;
constructor(txOutId, txOutIndex, signature) {
this.txOutId = txOutId; // Previous transaction ID
this.txOutIndex = txOutIndex;
this.signature = signature; // Sender's signature
}
}
class TxOUT {
amount = null;
address = null;
constructor(amount, address) {
this.amount = amount; // Amount value of output
this.address = address; // Receiver's address
}
}
let testOut = new TxOUT(10, "tb1****************************ntxt");
let testIn = new TxIN("tb******************************tntxt", 0, "gg")
let testTrans = new Transaction("1329***********************1e99ba8", testIn, testOut);
var test = 'GG';
console.log(test);
var t = CryptoJS.SHA256(test);
我在我的 JavaScript 项目中使用 CryptoJS.SHA256() 。但显示“TypeError:CryptoJS.SHA256 不是函数”。我已经导入了“crypto-js”。当我尝试记录加密货币时。我找到了“SHA256:[函数(匿名)]”。但TypeError无法解决。 我有什么错误吗?
import * as CryptoJS from 'crypto-js';
import * as ecdsa from 'elliptic';
import * as _ from 'lodash'
class Transaction {
id = null;
constructor(id, txIns, txOuts) {
this.id = id;
this.txIns = txIns;
this.txOuts = txOuts;
}
}
function getTransactionId (Transaction)
{
const txInContent = Transaction.txIns.txOutId + Transaction.txIns.txOutIndex;
// const txInContent = Transaction.TxIN.map((TxIN) => TxIN.txOutId + TxIN.txOutIndex).reduce((a, b) => a + b, '');
const txOutContent = Transaction.txOuts.amount + Transaction.txOuts.address;
// const txOutContent = Transaction.TxOut.map((TxOUT) => txOut.amount + txOut.address).reduce((a, b) => a + b, '');
return (txInContent + txOutContent).toString();
}
class TxIN {
txOutId = null;
txOutIndex = null;
signature = null;
constructor(txOutId, txOutIndex, signature) {
this.txOutId = txOutId; // Previous transaction ID
this.txOutIndex = txOutIndex;
this.signature = signature; // Sender's signature
}
}
class TxOUT {
amount = null;
address = null;
constructor(amount, address) {
this.amount = amount; // Amount value of output
this.address = address; // Receiver's address
}
}
let testOut = new TxOUT(10, "tb1****************************ntxt");
let testIn = new TxIN("tb******************************tntxt", 0, "gg")
let testTrans = new Transaction("1329***********************1e99ba8", testIn, testOut);
var test = 'GG';
console.log(test);
var t = CryptoJS.SHA256(test);
I am using the CryptoJS.SHA256() on my JavaScript project. But is shows the "TypeError: CryptoJS.SHA256 is not a function". And I've already import the 'crypto-js'. When I tried to log the crypto. I found the "SHA256: [Function (anonymous)]". But the TypeError cannot be solved.
Is there something I make a mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这些:
npm install @types/node --save-dev
安装 NodeJS 定义
在 tsconfig.ts 文件中添加以下内容:
import 将库导入到要使用的位置
使用 import或
使用特殊的导入语法
try these :
npm install @types/node --save-dev
to install NodeJS definitions
In tsconfig.ts file add the following:
Import the library where you want to use it with import
or
with speical import syntax
尝试像这样得到它:
这里正在运行演示:
https://replit.com/@slash851/crypto-js-test#索引.js
try to get it like this:
here is running demo:
https://replit.com/@slash851/crypto-js-test#index.js