Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: replace node buffers with uint8arrays #180

Merged
merged 2 commits into from
Aug 7, 2020

Conversation

achingbrain
Copy link
Member

All usage of node buffers have been replaced with uint8arrays.

BREAKING CHANGES:

  • Where node Buffers were returned, now Uint8Arrays are

All usage of node buffers have been replaced with uint8arrays.

BREAKING CHANGES:

- Where node Buffers were returned, now Uint8Arrays are
@achingbrain
Copy link
Member Author

Tagging @Gozala too as he's not in the eligible reviewers list.

@jacobheun
Copy link
Contributor

Tagging @Gozala too as he's not in the eligible reviewers list.

@Gozala sent you invite to the libp2p org and added you to the js repos team.

@@ -16,7 +16,7 @@ exports.generateKeyFromSeed = async function (seed) { // eslint-disable-line req

exports.hashAndSign = async function (key, msg) { // eslint-disable-line require-await
return forge.pki.ed25519.sign({ message: msg, privateKey: key })
// return Buffer.from(nacl.sign.detached(msg, key))
// return Uint8Array.from(nacl.sign.detached(msg, key))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forge is going to create an api inconsistency whenever it's returned. Forge isn't very consistent so some of the returned types may be Buffer in node.js. This is the case for ed25519. We likely need to add more checks in the tests for api types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to return Buffers as they are still Uint8Arrays. I think it's only a problem if it returns the weird ascii-byte-array-string it seems to use internally.

Copy link
Member Author

@achingbrain achingbrain Aug 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though we could just pass the output to new Uint8Array for safety. As long as it's not a that string type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be ok. I believe the API does convert from the forge buffer when returning.

@jacobheun jacobheun merged commit a0f387a into master Aug 7, 2020
@jacobheun jacobheun deleted the fix/replace-node-buffers-with-uint8arrays branch August 7, 2020 14:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants