File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ try {
2+ const mod = require ( 'bigint-buffer' ) ;
3+ const le = typeof mod . toBigIntLE === 'function' ? mod . toBigIntLE : undefined ;
4+ const be = typeof mod . toBigIntBE === 'function' ? mod . toBigIntBE : undefined ;
5+
6+ const isBufferLike = ( b : unknown ) => ( typeof Buffer !== 'undefined' && Buffer . isBuffer ( b ) ) || b instanceof Uint8Array ;
7+
8+ const byteLen = ( b : any ) =>
9+ typeof Buffer !== 'undefined' && Buffer . isBuffer ( b ) ? b . length : ( b as Uint8Array ) . byteLength ;
10+
11+ const assertBuf = ( b : unknown ) => {
12+ if ( ! isBufferLike ( b ) ) throw new TypeError ( 'toBigInt*: input must be Buffer/Uint8Array' ) ;
13+ if ( byteLen ( b as any ) > 1_000_000 ) throw new RangeError ( 'toBigInt*: buffer too large' ) ;
14+ } ;
15+
16+ if ( le )
17+ mod . toBigIntLE = ( buf : Buffer | Uint8Array ) => {
18+ assertBuf ( buf ) ;
19+ return le ( buf ) ;
20+ } ;
21+ if ( be )
22+ mod . toBigIntBE = ( buf : Buffer | Uint8Array ) => {
23+ assertBuf ( buf ) ;
24+ return be ( buf ) ;
25+ } ;
26+ } catch {
27+ /* noop */
28+ }
Original file line number Diff line number Diff line change 1+ import './bigint-buffer-guard' ;
12export * from './lib' ;
23export * from './sol' ;
34export * from './solToken' ;
You can’t perform that action at this time.
0 commit comments