feat: remove Buffer support and bundle polyfill (#2526)

- Removes need for bundlers to polyfill the `Buffer` class. `UInt8Array` are used instead which are native to the browser and node.
- Reduces bundle size 7.1kb gzipped and eliminates 4 runtime dependencies: `base-x`, `base64-js`, `buffer`, and `ieee754`.

BREAKING CHANGE: All methods that previously took a `Buffer` now accept a `UInt8Array`.

---------

Co-authored-by: Jackson Mills <jmills@ripple.com>
This commit is contained in:
Caleb Kniffen
2023-11-30 09:32:28 -06:00
parent eefb52a9cb
commit 38b385969b
77 changed files with 853 additions and 666 deletions

View File

@@ -2,6 +2,12 @@
## Unreleased
### Breaking Changes
* `Buffer` has been replaced with `UInt8Array` for both params and return values. `Buffer` may continue to work with params since they extend `UInt8Arrays`.
### Changes
* Eliminates 4 runtime dependencies: `base-x`, `base64-js`, `buffer`, and `ieee754`.
## 2.0.0 Beta 1 (2023-10-19)
### Breaking Changes

View File

@@ -8,6 +8,7 @@ import {
sign,
verify,
} from '../src'
import { stringToHex } from '@xrplf/isomorphic/utils'
const entropy = new Uint8Array([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -77,7 +78,7 @@ describe('api', () => {
it('sign - secp256k1', () => {
const privateKey = fixtures.secp256k1.keypair.privateKey
const message = fixtures.secp256k1.message
const messageHex = Buffer.from(message, 'utf8').toString('hex')
const messageHex = stringToHex(message)
const signature = sign(messageHex, privateKey)
expect(signature).toEqual(fixtures.secp256k1.signature)
})
@@ -86,14 +87,14 @@ describe('api', () => {
const signature = fixtures.secp256k1.signature
const publicKey = fixtures.secp256k1.keypair.publicKey
const message = fixtures.secp256k1.message
const messageHex = Buffer.from(message, 'utf8').toString('hex')
const messageHex = stringToHex(message)
expect(verify(messageHex, signature, publicKey)).toBeTruthy()
})
it('sign - ed25519', () => {
const privateKey = fixtures.ed25519.keypair.privateKey
const message = fixtures.ed25519.message
const messageHex = Buffer.from(message, 'utf8').toString('hex')
const messageHex = stringToHex(message)
const signature = sign(messageHex, privateKey)
expect(signature).toEqual(fixtures.ed25519.signature)
})
@@ -102,7 +103,7 @@ describe('api', () => {
const signature = fixtures.ed25519.signature
const publicKey = fixtures.ed25519.keypair.publicKey
const message = fixtures.ed25519.message
const messageHex = Buffer.from(message, 'utf8').toString('hex')
const messageHex = stringToHex(message)
expect(verify(messageHex, signature, publicKey)).toBeTruthy()
})