mafintosh / simple-hypercore-protocol

Hypercore protocol state machine
MIT License
26 stars 13 forks source link

Replace Buffer.concat with Buffer.from to make the library work in browser #7

Closed dmaretskyi closed 3 years ago

dmaretskyi commented 3 years ago

When bundling for the browser it looks like the underlying crypto library (sodium-javascript) works on Uint8Array objects and not Buffers. This causes an error when they get to those Buffer.concat calls:

Error [TypeError]: "list" argument must be an Array of Buffers

I've replaced them with Buffer.from which should convert the Uint8Array values to instances of Buffer. This should should allow the library to be used in a browsers environment with more configurations and resolve some of the problems mentioned in #5.

PS: We've created a testing framework to easily run mocha unit-tests in different browsers using playwright. Let me know if you are interested, I can submit a PR.

mafintosh commented 3 years ago

2.1.2