@@ -53,21 +53,21 @@ const bitsWithPowers = (tPower, rPower) => {
53
53
return N
54
54
}
55
55
56
- const string = ( entropy , charSet ) => {
57
- return stringWithBytes ( entropy , charSet , _cryptoBytes ( entropy , charSet ) )
56
+ const string = ( entropyBits , charSet ) => {
57
+ return stringWithBytes ( entropyBits , charSet , _cryptoBytes ( entropyBits , charSet ) )
58
58
}
59
59
60
- const stringRandom = ( entropy , charSet ) => {
61
- return stringWithBytes ( entropy , charSet , _randomBytes ( entropy , charSet ) )
60
+ const stringRandom = ( entropyBits , charSet ) => {
61
+ return stringWithBytes ( entropyBits , charSet , _randomBytes ( entropyBits , charSet ) )
62
62
}
63
63
64
- const stringWithBytes = ( entropy , charSet , bytes ) => {
64
+ const stringWithBytes = ( entropyBits , charSet , bytes ) => {
65
65
if ( ! CharSet . isValid ( charSet ) ) {
66
66
throw new Error ( 'Invalid CharSet' )
67
67
}
68
- if ( entropy <= 0 ) { return '' }
68
+ if ( entropyBits <= 0 ) { return '' }
69
69
70
- const count = Math . ceil ( entropy / charSet . bitsPerChar )
70
+ const count = Math . ceil ( entropyBits / charSet . bitsPerChar )
71
71
if ( count <= 0 ) { return '' }
72
72
73
73
const needed = Math . ceil ( count * ( charSet . bitsPerChar / _bitsPerByte ) )
@@ -92,22 +92,22 @@ const stringWithBytes = (entropy, charSet, bytes) => {
92
92
return string
93
93
}
94
94
95
- const bytesNeeded = ( entropy , charSet ) => {
95
+ const bytesNeeded = ( entropyBits , charSet ) => {
96
96
if ( ! CharSet . isValid ( charSet ) ) { throw new Error ( 'Invalid CharSet' ) }
97
- const count = Math . ceil ( entropy / charSet . bitsPerChar )
97
+ const count = Math . ceil ( entropyBits / charSet . bitsPerChar )
98
98
if ( count <= 0 ) { return 0 }
99
99
100
100
const bytesPerSlice = charSet . bitsPerChar / _bitsPerByte
101
101
return Math . ceil ( count * bytesPerSlice )
102
102
}
103
103
104
- const _cryptoBytes = ( entropy , charSet ) => {
104
+ const _cryptoBytes = ( entropyBits , charSet ) => {
105
105
const crypto = require ( 'crypto' )
106
- return Buffer . from ( crypto . randomBytes ( bytesNeeded ( entropy , charSet ) ) )
106
+ return Buffer . from ( crypto . randomBytes ( bytesNeeded ( entropyBits , charSet ) ) )
107
107
}
108
108
109
- const _randomBytes = ( entropy , charSet ) => {
110
- const byteCount = bytesNeeded ( entropy , charSet )
109
+ const _randomBytes = ( entropyBits , charSet ) => {
110
+ const byteCount = bytesNeeded ( entropyBits , charSet )
111
111
const randCount = Math . ceil ( byteCount / 6 )
112
112
113
113
const buffer = new Buffer ( byteCount )
0 commit comments