Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: undefined is not a function (evaluating 'entropy.slice(...)') #87

Closed
modenero opened this issue Dec 5, 2017 · 7 comments
Closed
Assignees

Comments

@modenero
Copy link

modenero commented Dec 5, 2017

var checksum = utils.arrayify(utils.sha256(entropy.slice(0, entropyBits / 8)))[0];

Error occurs when attempting to use slice on entropy. This only occurs when entropy is an array-like object and NOT an pure array. Occurs on some (not all) physical devices.
Haven't had any issues on either the Android or iOS emulators.


Dropped in this snippet, which fixes the problem, but then it just keeps popping up in other places where slice is used.

if (!Array.isArray(entropy))
    entropy = Array.prototype.slice.call(entropy, 0)

As a temporary fix, will try creating a slice function and prototype it to all objects.

Working now. Ended up just using the above snippet in the following files (directly before the slice call):

  1. dist/ethers.js
  2. dist/ethers-wallet.js
  3. ethers-wallet/hdnode.js
  4. ethers-utils/pbkdf2.js
@ricmoo ricmoo self-assigned this Dec 8, 2017
@ricmoo ricmoo added the investigate Under investigation and may be a bug. label Dec 8, 2017
@ricmoo
Copy link
Member

ricmoo commented Dec 24, 2017

I wonder if the dist files are missing the call to addSlice which adds slice during arrayify if it is missing. I will look into this. It may be pulling an older version of convert in.

@modenero
Copy link
Author

modenero commented Dec 28, 2017

It seems to only be occurring on "older" (2+ years) mobile devices, still trying to narrow down further. The error occurs in a few more files, than mentioned above, when working with CONTRACTS.

@ricmoo
Copy link
Member

ricmoo commented Dec 28, 2017

Can you confirm you are using a recent version of the dist files?

The line

var entropy = utils.arrayify(new Uint8Array(Math.ceil(11 * words.length / 8)));
should be injecting the slice method when it is not present. If you provide a short example that does not work, I can likely reproduce it in PhantomJS as it is often missing "newer" additions.

@modenero
Copy link
Author

Yes, it is the latest version. This is definitely not affecting all devices, and only the older ones at the moment, so there's probably a common element that we haven't found yet. Hopefully as we continue testing devices, we'll see a pattern. Also, we've seen this on both Android and iOS devices.

@ricmoo
Copy link
Member

ricmoo commented Dec 29, 2017

Can you please provide a very short script that causes this? I need to be able to replicate it before I can add the test cases to protect from it in the future and make sure the fix works.

I have PhantomJS, and without a TypedArray shim, it should fail the same way. I just haven't been able to reproduce it, even on old devices.

@modenero
Copy link
Author

Haven't been able to replicate this reliably and haven't seen this on any newer phones or tablets, but our user base is significantly older devices (especially in intl markets) so it showed up a lot in our bug reports.

Model: Advance 5.0 HD (Android 6.0)

device-2017-12-29-194408

Model: iPhone 4S (iOS 9.3.5 (13G36))

screen shot 2017-12-29 at 7 47 53 pm

@ricmoo
Copy link
Member

ricmoo commented Mar 5, 2018

Is this still an issue with ethers@3.0.1? I believe this should have been fixed a while ago, but the latest version tests using phantomjs against the dist files. The phantomjs environment is a fairly archaic environment itself, so likely if it works in phantomjs, it will work in any older environment.

If this is still an issue though, please feel free to re-open. :)

@ricmoo ricmoo closed this as completed Mar 5, 2018
@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants