Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7afc9ae

Browse files
committed
Refactor
entropy -> entropyBits
1 parent e310537 commit 7afc9ae

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/entropy.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,21 @@ const bitsWithPowers = (tPower, rPower) => {
5353
return N
5454
}
5555

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))
5858
}
5959

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))
6262
}
6363

64-
const stringWithBytes = (entropy, charSet, bytes) => {
64+
const stringWithBytes = (entropyBits, charSet, bytes) => {
6565
if (!CharSet.isValid(charSet)) {
6666
throw new Error('Invalid CharSet')
6767
}
68-
if (entropy <= 0) { return '' }
68+
if (entropyBits <= 0) { return '' }
6969

70-
const count = Math.ceil(entropy / charSet.bitsPerChar)
70+
const count = Math.ceil(entropyBits / charSet.bitsPerChar)
7171
if (count <= 0) { return '' }
7272

7373
const needed = Math.ceil(count * (charSet.bitsPerChar / _bitsPerByte))
@@ -92,22 +92,22 @@ const stringWithBytes = (entropy, charSet, bytes) => {
9292
return string
9393
}
9494

95-
const bytesNeeded = (entropy, charSet) => {
95+
const bytesNeeded = (entropyBits, charSet) => {
9696
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)
9898
if (count <= 0) { return 0 }
9999

100100
const bytesPerSlice = charSet.bitsPerChar / _bitsPerByte
101101
return Math.ceil(count * bytesPerSlice)
102102
}
103103

104-
const _cryptoBytes = (entropy, charSet) => {
104+
const _cryptoBytes = (entropyBits, charSet) => {
105105
const crypto = require('crypto')
106-
return Buffer.from(crypto.randomBytes(bytesNeeded(entropy, charSet)))
106+
return Buffer.from(crypto.randomBytes(bytesNeeded(entropyBits, charSet)))
107107
}
108108

109-
const _randomBytes = (entropy, charSet) => {
110-
const byteCount = bytesNeeded(entropy, charSet)
109+
const _randomBytes = (entropyBits, charSet) => {
110+
const byteCount = bytesNeeded(entropyBits, charSet)
111111
const randCount = Math.ceil(byteCount / 6)
112112

113113
const buffer = new Buffer(byteCount)

0 commit comments

Comments
 (0)