migrate from buffer to Uint8Array#52
Conversation
|
I have kept naming conventions as it is.. LMK if that has to be changed @junderw |
junderw
left a comment
There was a problem hiding this comment.
Thanks for getting started.
Here are a few suggestions to get the ball rolling.
You can also start a pull request to add any other tools you think might be useful (that you see used a lot with Buffers, but can't find an equivalent for Uint8Array) to the uint8array-tools library.
src/test/index.ts
Outdated
| const bytes = Buffer.from(bech32.fromWords(f.words)); | ||
| const bytes2 = Buffer.from(bech32.fromWordsUnsafe(f.words)); | ||
| const words = bech32.toWords(uint8arraytools.fromHex(f.hex)); | ||
| const bytes = new Uint8Array(Buffer.from(bech32.fromWords(f.words))); |
There was a problem hiding this comment.
| const bytes = new Uint8Array(Buffer.from(bech32.fromWords(f.words))); | |
| const bytes = Uint8Array.from(bech32.fromWords(f.words)); |
There was a problem hiding this comment.
the change that u suggested would give a 0 value for any latin character. we will have to initialise a new Uint8Array instance.
or write it like:
const bytes = Uint8Array.from(Buffer.from(bech32.fromWords(f.words)));
If we want to completely eliminate every instance of buffer here, one thing I can do is create a function for the same in uint8array-tools library or keep it the same as i did.
src/test/index.ts
Outdated
| t.same(words, f.words); | ||
| t.same(bytes.toString('hex'), f.hex); | ||
| t.same(bytes2.toString('hex'), f.hex); | ||
| t.same(Buffer.from(bytes).toString('hex'), f.hex); |
There was a problem hiding this comment.
| t.same(Buffer.from(bytes).toString('hex'), f.hex); | |
| t.same(uint8arraytools.toHex(bytes), f.hex); |
|
also in code there are requirements to convert typedArray to string in 'utf8' or 'binary' format. Whereas uint8array-tools library only provides to convert it to 'hex' format. I'll proceed with adding those two feature as well in that library |
|
Hey @junderw all requested changes have been made. |
the following PR fixes #51 .
test script contained some instance of buffer which i shifted to Uint8Array.
uint8array-tools library has also been used to make things easier.