-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrate from buffer to Uint8Array #52
base: master
Are you sure you want to change the base?
Conversation
I have kept naming conventions as it is.. LMK if that has to be changed @junderw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.