@@ -16,8 +16,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1616
1717var WeakMap = require ( 'weak-map' ) ;
1818
19- var csprngBytes = require ( 'lib/csprng-bytes' ) ;
20- var prngBytes = require ( 'lib/prng-bytes' ) ;
19+ var _require = require ( './lib/csprng-bytes' ) ,
20+ csprngBytes = _require . csprngBytes ;
21+
22+ var _require2 = require ( './lib/prng-bytes' ) ,
23+ prngBytes = _require2 . prngBytes ;
2124
2225var BITS_PER_BYTE = 8 ;
2326var abs = Math . abs ,
@@ -92,7 +95,9 @@ var CharSet = function () {
9295 if ( ! [ 2 , 4 , 8 , 16 , 32 , 64 ] . includes ( length ) ) {
9396 throw new Error ( 'Invalid char count: must be one of 2,4,8,16,32,64' ) ;
9497 }
95- var bitsPerChar = floor ( log2 ( length ) ) ;
98+
99+ this . bitsPerChar = floor ( log2 ( length ) ) ;
100+
96101 // Ensure no repeated characters
97102 for ( var i = 0 ; i < length ; i += 1 ) {
98103 var c = chars . charAt ( i ) ;
@@ -104,10 +109,9 @@ var CharSet = function () {
104109 }
105110 var privProps = {
106111 chars : chars ,
107- bitsPerChar : bitsPerChar ,
108112 length : length ,
109- ndxFn : genNdxFn ( bitsPerChar ) ,
110- charsPerChunk : lcm ( bitsPerChar , BITS_PER_BYTE ) / bitsPerChar
113+ ndxFn : genNdxFn ( this . bitsPerChar ) ,
114+ charsPerChunk : lcm ( this . bitsPerChar , BITS_PER_BYTE ) / this . bitsPerChar
111115 } ;
112116 charsetProps . set ( this , privProps ) ;
113117 }
@@ -120,7 +124,7 @@ var CharSet = function () {
120124 } , {
121125 key : 'getBitsPerChar' ,
122126 value : function getBitsPerChar ( ) {
123- return charsetProps . get ( this ) . bitsPerChar ;
127+ return this . bitsPerChar ;
124128 }
125129 } , {
126130 key : 'getNdxFn' ,
@@ -140,8 +144,8 @@ var CharSet = function () {
140144 } , {
141145 key : 'bytesNeeded' ,
142146 value : function bytesNeeded ( bitLen ) {
143- var count = ceil ( bitLen / this . bitsPerChar ( ) ) ;
144- return ceil ( count * this . bitsPerChar ( ) / BITS_PER_BYTE ) ;
147+ var count = ceil ( bitLen / this . bitsPerChar ) ;
148+ return ceil ( count * this . bitsPerChar / BITS_PER_BYTE ) ;
145149 }
146150
147151 // Aliases
@@ -156,11 +160,8 @@ var CharSet = function () {
156160 value : function ndxFn ( ) {
157161 return this . getNdxFn ( ) ;
158162 }
159- } , {
160- key : 'bitsPerChar' ,
161- value : function bitsPerChar ( ) {
162- return this . getBitsPerChar ( ) ;
163- }
163+ // bitsPerChar() { return this.getBitsPerChar() }
164+
164165 } ] ) ;
165166 return CharSet ;
166167} ( ) ;
@@ -177,7 +178,7 @@ var _stringWithBytes = function _stringWithBytes(bytes, bitLen, charset) {
177178 return '' ;
178179 }
179180
180- var bitsPerChar = charset . getBitsPerChar ( ) ;
181+ var bitsPerChar = charset . bitsPerChar ;
181182 var count = ceil ( bitLen / bitsPerChar ) ;
182183 if ( count <= 0 ) {
183184 return '' ;
@@ -209,28 +210,6 @@ var _stringWithBytes = function _stringWithBytes(bytes, bitLen, charset) {
209210 return string ;
210211} ;
211212
212- // const csprngBytes = count => Buffer.from(Crypto.randomBytes(count))
213-
214- // const prngBytes = (count) => {
215- // console.log('CxDebug prng: true')
216- // const BYTES_USED_PER_RANDOM_CALL = 6
217- // const randCount = ceil(count / BYTES_USED_PER_RANDOM_CALL)
218-
219- // const buffer = new ArrayBuffer(count)
220- // const dataView = new DataView(new ArrayBuffer(BITS_PER_BYTE))
221- // for (let rNum = 0; rNum < randCount; rNum += 1) {
222- // dataView.setFloat64(0, random())
223- // for (let n = 0; n < BYTES_USED_PER_RANDOM_CALL; n += 1) {
224- // const fByteNum = endianByteNum[n]
225- // const bByteNum = (rNum * BYTES_USED_PER_RANDOM_CALL) + n
226- // if (bByteNum < count) {
227- // buffer[bByteNum] = dataView.getUint8(fByteNum)
228- // }
229- // }
230- // }
231- // return buffer
232- // }
233-
234213var entropyBits = function entropyBits ( total , risk ) {
235214 if ( total === 0 ) {
236215 return 0 ;
0 commit comments