Browse Source

fix in android not support spread

use `Array.from` instead of `...`
master
Mr.jiangzhiguo 5 years ago
committed by junderw
parent
commit
d42e6af7af
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 4
      src/index.js
  2. 4
      ts_src/index.ts

4
src/index.js

@ -27,7 +27,7 @@ function deriveChecksumBits(entropyBuffer) {
const hash = createHash('sha256')
.update(entropyBuffer)
.digest();
return bytesToBinary([...hash]).slice(0, CS);
return bytesToBinary(Array.from(hash)).slice(0, CS);
}
function salt(password) {
return 'mnemonic' + (password || '');
@ -106,7 +106,7 @@ function entropyToMnemonic(entropy, wordlist) {
throw new TypeError(INVALID_ENTROPY);
if (entropy.length % 4 !== 0)
throw new TypeError(INVALID_ENTROPY);
const entropyBits = bytesToBinary([...entropy]);
const entropyBits = bytesToBinary(Array.from(entropy));
const checksumBits = deriveChecksumBits(entropy);
const bits = entropyBits + checksumBits;
const chunks = bits.match(/(.{1,11})/g);

4
ts_src/index.ts

@ -32,7 +32,7 @@ function deriveChecksumBits(entropyBuffer: Buffer): string {
.update(entropyBuffer)
.digest();
return bytesToBinary([...hash]).slice(0, CS);
return bytesToBinary(Array.from(hash)).slice(0, CS);
}
function salt(password?: string): string {
@ -136,7 +136,7 @@ export function entropyToMnemonic(
if (entropy.length > 32) throw new TypeError(INVALID_ENTROPY);
if (entropy.length % 4 !== 0) throw new TypeError(INVALID_ENTROPY);
const entropyBits = bytesToBinary([...entropy]);
const entropyBits = bytesToBinary(Array.from(entropy));
const checksumBits = deriveChecksumBits(entropy);
const bits = entropyBits + checksumBits;

Loading…
Cancel
Save