File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ function mnemonicToEntropy (mnemonic, wordlist) {
4242 return lpad ( index . toString ( 2 ) , '0' , 11 )
4343 } ) . join ( '' )
4444
45+ // max entropy is 1024; (1024×8)+((1024×8)÷32) = 8448
46+ assert ( bits . length <= 8448 , 'Invalid mnemonic' )
47+
4548 // split the binary string into ENT/CS
4649 var dividerIndex = Math . floor ( bits . length / 33 ) * 32
4750 var entropy = bits . slice ( 0 , dividerIndex )
@@ -64,7 +67,7 @@ function entropyToMnemonic (entropy, wordlist) {
6467
6568 var entropyBuffer = new Buffer ( entropy , 'hex' )
6669
67- assert ( entropyBuffer . length && entropyBuffer . length % 4 === 0 , 'Invalid entropy' )
70+ assert ( entropyBuffer . length > 0 && entropyBuffer . length <= 1024 && entropyBuffer . length % 4 === 0 , 'Invalid entropy' )
6871
6972 var entropyBits = bytesToBinary ( [ ] . slice . call ( entropyBuffer ) )
7073 var checksum = checksumBits ( entropyBuffer )
Original file line number Diff line number Diff line change @@ -85,6 +85,15 @@ describe('BIP39', function () {
8585 e = _e ;
8686 }
8787 assert ( e && e . message === 'Invalid entropy' ) ;
88+
89+ var e ;
90+ try {
91+ BIP39 . entropyToMnemonic ( new Buffer ( new Array ( 1028 + 1 ) . join ( '00' ) , 'hex' ) ) ;
92+ e = null ;
93+ } catch ( _e ) {
94+ e = _e ;
95+ }
96+ assert ( e && e . message === 'Invalid entropy' ) ;
8897 } )
8998 } )
9099
You can’t perform that action at this time.
0 commit comments