This repository was archived by the owner on Jan 11, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Expand file tree Collapse file tree 3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -206,7 +206,7 @@ function stripHexPrefix(str: string): string {
206206}
207207
208208/** Transform an integer into its hexadecimal value */
209- function intToHex ( integer : number ) : string {
209+ function intToHex ( integer : number | bigint ) : string {
210210 if ( integer < 0 ) {
211211 throw new Error ( 'Invalid integer as argument, must be unsigned!' )
212212 }
@@ -220,7 +220,7 @@ function padToEven(a: string): string {
220220}
221221
222222/** Transform an integer into a Buffer */
223- function intToBuffer ( integer : number ) : Buffer {
223+ function intToBuffer ( integer : number | bigint ) : Buffer {
224224 const hex = intToHex ( integer )
225225 return Buffer . from ( hex , 'hex' )
226226}
@@ -234,7 +234,7 @@ function toBuffer(v: Input): Buffer {
234234 } else {
235235 return Buffer . from ( v )
236236 }
237- } else if ( typeof v === 'number' ) {
237+ } else if ( typeof v === 'number' || typeof v === 'bigint' ) {
238238 if ( ! v ) {
239239 return Buffer . from ( [ ] )
240240 } else {
Original file line number Diff line number Diff line change 11import BN = require( 'bn.js' )
22
3- export type Input = Buffer | string | number | Uint8Array | BN | List | null
3+ export type Input = Buffer | string | number | bigint | Uint8Array | BN | List | null
44
55// Use interface extension instead of type alias to
66// make circular declaration possible.
Original file line number Diff line number Diff line change @@ -61,6 +61,13 @@ describe('RLP encoding (list):', function() {
6161 // })
6262} )
6363
64+ describe ( 'RLP encoding (BigInt):' , function ( ) {
65+ it ( 'should encode a BigInt value' , function ( ) {
66+ const encodedBN = RLP . encode ( BigInt ( 3 ) )
67+ assert . equal ( encodedBN [ 0 ] , 3 )
68+ } )
69+ } )
70+
6471describe ( 'RLP encoding (BN):' , function ( ) {
6572 it ( 'should encode a BN value' , function ( ) {
6673 const encodedBN = RLP . encode ( new BN ( 3 ) )
You can’t perform that action at this time.
0 commit comments