speakeasyjs / speakeasy

**NOT MAINTAINED** Two-factor authentication for Node.js. One-time passcode generator (HOTP/TOTP) with support for Google Authenticator.
MIT License
2.7k stars 228 forks source link

TypeError: item.copy is not a function (browser support) #53

Open tarundhillon opened 8 years ago

tarundhillon commented 8 years ago

I have used browserify to create a standalone js file, I am able to generate a QR code but

  1. When I am trying to totp.verify using base32 encoding I am getting an error "Uncaught TypeError: item.copy is not a function" the exact statement is "item.copy(buf,pos) in the Buffer.concat function. Seems like a dependency is missing ?
  2. There are no errors shown while using hex and ascii encoding but the verify method still doesn't work.

Below are the code snippets

Generate secret, display QR code, also generate a token

requirejs(['speakeasy', 'qrcode'], function(speakeasy, QRCode) {
            _secret = speakeasy.generateSecret({ length: 20 });
            _speakeasy = speakeasy;
            $('#qrcode').qrcode({
                width: 128,
                height: 128,
                text: _secret.otpauth_url
            });

            // printing a generated token to validate the token with Google Authorizer
            var token = speakeasy.totp({
                secret: _secret.ascii,
                //encoding: 'base32'
            });
            $('#qrcode').append(token);
            $('#container').delegate('#loginButton', 'click', handleLoginClick);
        }); 

Verify user token

var userToken = $('#usertoken').val();
        console.log('userToke:',userToken,'secret',_secret.base32);
        var verified = _speakeasy.time.verify({
            secret: _secret.ascii,
            token: userToken,
            window: 2,
            step: 60
        });
        console.log('verified:',verified);

Any suggestions on how to fix this ? Thanks