Using CryptoJS
See original GitHub issueI’m trying to test this library to see how I could use it with CryptoJS alongside other stuff and it seems to not like it even when I convert the hashes into buffers
test('Simple', () => {
const data = ['Lorem', 'Ipsum', 'Dolore', 'Sit', 'Amet'];
const leaves = data.map(d => Buffer.from(SHA256(d).toString(), 'hex'));
console.log(leaves);
let tree = new MerkelTree(leaves, SHA256);
}
I get this error:
TypeError [ERR_INVALID_ARG_TYPE]: The "list[0]" argument must be one of type Array, Buffer, or Uint8Array. Received type object
at Function.concat (buffer.js:479:13)
at MerkleTree.createHashes (/home/maxie/Dropbox/Projects/SaCoin/node_modules/merkletreejs/index.js:57:23)
at MerkleTree.createHashes (/home/maxie/Dropbox/Projects/SaCoin/node_modules/merkletreejs/index.js:86:10)
at new MerkleTree (/home/maxie/Dropbox/Projects/SaCoin/node_modules/merkletreejs/index.js:37:10)
at Object.<anonymous>.test (/home/maxie/Dropbox/Projects/SaCoin/tests/MerkelTree.test.js:9:14)
at Object.asyncFn (/home/maxie/Dropbox/Projects/SaCoin/node_modules/jest-jasmine2/build/jasmine_async.js:108:37)
at resolve (/home/maxie/Dropbox/Projects/SaCoin/node_modules/jest-jasmine2/build/queue_runner.js:56:12)
at new Promise (<anonymous>)
at mapper (/home/maxie/Dropbox/Projects/SaCoin/node_modules/jest-jasmine2/build/queue_runner.js:43:19)
at promise.then (/home/maxie/Dropbox/Projects/SaCoin/node_modules/jest-jasmine2/build/queue_runner.js:87:41)
This error says that the leave inputs aren’t buffers but they are (confirmed by expect(leaves[0] instanceof Buffer).toBeTruthy();
passing) so I’m perplexed as to why that is happening?
I don’t want to use crypto because all the crypto functions in my project are based on CryptoJS and work perfectly well.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
how to use CryptoJS in javascript - node.js - Stack Overflow
Here's a sample on how to use CryptoJs in webclient: // INIT var myString = "blablabla Card game bla"; var myPassword = "myPassword"; ......
Read more >CryptoJS - CryptoJS
CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns.
Read more >CryptoJS Tutorial For Dummies | Davide Barranca
CryptoJS makes large use of Word Array - that is, arrays of 32-bits words (instances of the CryptoJS.lib.WordArray ); few useful functions:.
Read more >brix/crypto-js: JavaScript library of crypto standards. - GitHub
JavaScript library of crypto standards. Contribute to brix/crypto-js development by creating an account on GitHub.
Read more >crypto-js - npm
JavaScript library of crypto standards.. Latest version: 4.1.1, last published: a year ago. Start using crypto-js in your project by running ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Although the CryptoJS constructor type is called Buffer, CryptoJS buffers are not actually native Node.js buffers which is what’s causing the error.
To get around this you can wrap the hashing function in order to return a
Buffer
.We should however support CryptoJS in a future release
@Berkmann18 @DonleeIO
Latest release supports CryptoJS algos