@@ -16,8 +16,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
16
17
17
var WeakMap = require ( 'weak-map' ) ;
18
18
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 ;
21
24
22
25
var BITS_PER_BYTE = 8 ;
23
26
var abs = Math . abs ,
@@ -92,7 +95,9 @@ var CharSet = function () {
92
95
if ( ! [ 2 , 4 , 8 , 16 , 32 , 64 ] . includes ( length ) ) {
93
96
throw new Error ( 'Invalid char count: must be one of 2,4,8,16,32,64' ) ;
94
97
}
95
- var bitsPerChar = floor ( log2 ( length ) ) ;
98
+
99
+ this . bitsPerChar = floor ( log2 ( length ) ) ;
100
+
96
101
// Ensure no repeated characters
97
102
for ( var i = 0 ; i < length ; i += 1 ) {
98
103
var c = chars . charAt ( i ) ;
@@ -104,10 +109,9 @@ var CharSet = function () {
104
109
}
105
110
var privProps = {
106
111
chars : chars ,
107
- bitsPerChar : bitsPerChar ,
108
112
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
111
115
} ;
112
116
charsetProps . set ( this , privProps ) ;
113
117
}
@@ -120,7 +124,7 @@ var CharSet = function () {
120
124
} , {
121
125
key : 'getBitsPerChar' ,
122
126
value : function getBitsPerChar ( ) {
123
- return charsetProps . get ( this ) . bitsPerChar ;
127
+ return this . bitsPerChar ;
124
128
}
125
129
} , {
126
130
key : 'getNdxFn' ,
@@ -140,8 +144,8 @@ var CharSet = function () {
140
144
} , {
141
145
key : 'bytesNeeded' ,
142
146
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 ) ;
145
149
}
146
150
147
151
// Aliases
@@ -156,11 +160,8 @@ var CharSet = function () {
156
160
value : function ndxFn ( ) {
157
161
return this . getNdxFn ( ) ;
158
162
}
159
- } , {
160
- key : 'bitsPerChar' ,
161
- value : function bitsPerChar ( ) {
162
- return this . getBitsPerChar ( ) ;
163
- }
163
+ // bitsPerChar() { return this.getBitsPerChar() }
164
+
164
165
} ] ) ;
165
166
return CharSet ;
166
167
} ( ) ;
@@ -177,7 +178,7 @@ var _stringWithBytes = function _stringWithBytes(bytes, bitLen, charset) {
177
178
return '' ;
178
179
}
179
180
180
- var bitsPerChar = charset . getBitsPerChar ( ) ;
181
+ var bitsPerChar = charset . bitsPerChar ;
181
182
var count = ceil ( bitLen / bitsPerChar ) ;
182
183
if ( count <= 0 ) {
183
184
return '' ;
@@ -209,28 +210,6 @@ var _stringWithBytes = function _stringWithBytes(bytes, bitLen, charset) {
209
210
return string ;
210
211
} ;
211
212
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
-
234
213
var entropyBits = function entropyBits ( total , risk ) {
235
214
if ( total === 0 ) {
236
215
return 0 ;
0 commit comments