Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Patch missing strip() in bn.js@v5 #251

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const stripZeros = function(a: any): Buffer | number[] | string {
export const toBuffer = function(v: any): Buffer {
if (!Buffer.isBuffer(v)) {
if (Array.isArray(v) || v instanceof Uint8Array) {
v = Buffer.from(v)
v = Buffer.from(v as any)
} else if (typeof v === 'string') {
if (ethjsUtil.isHexString(v)) {
v = Buffer.from(ethjsUtil.padToEven(ethjsUtil.stripHexPrefix(v)), 'hex')
Expand Down
11 changes: 10 additions & 1 deletion src/externals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ Object.assign(exports, ethjsUtil)
/**
* [`BN`](https://github.com/indutny/bn.js)
*/
export { BN }
// PatchedBN applies a temporary fix for missing `strip()` when
// a bn.js@v4 instance uses a bn.js@v5 instance:
// https://github.com/indutny/bn.js/issues/239#issuecomment-626237202
class PatchedBN extends BN {
strip() {
// @ts-ignore
return this._strip()
}
}
export { PatchedBN as BN }

/**
* [`rlp`](https://github.com/ethereumjs/rlp)
Expand Down
7 changes: 4 additions & 3 deletions test/externals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import * as secp256k1_export from 'secp256k1'
import * as src from '../src'

describe('External BN export', () => {
it('should export `BN`', () => {
assert.equal(src.BN, BN_export)
})
/* Test temporarily disabled as we are applying a custom patch (see comment in `src/externals.ts`) */
// it('should export `BN`', () => {
// assert.equal(src.BN, BN_export)
// })

it('should use a BN function correctly', () => {
const a = new src.BN('dead', 16)
Expand Down