Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

547
Vistas
TypeError: CryptoJS.SHA256 is not a function

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?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

try these :

npm install @types/node --save-dev to install NodeJS definitions

npm install --save @types/crypto-js

In tsconfig.ts file add the following:

"files": [
"./node_modules/@types/node/index.d.ts"
]

Import the library where you want to use it with import

import * as sha256 from 'crypto-js/sha256';

or with speical import syntax

import sha256 = require("crypto-js/sha256");
about 4 years ago · Juan Pablo Isaza Denunciar

0

try to get it like this:

var SHA256 = require("crypto-js/sha256");
console.log(SHA256('my message'));

here is running demo: https://replit.com/@slash851/crypto-js-test#index.js

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda