This repository has been archived by the owner. It is now read-only.

Not able to login the user due to sjcl error #39

jeetendra-choudhary opened this Issue May 20, 2016 · 10 comments


None yet
6 participants

jeetendra-choudhary commented May 20, 2016

Hi ,

I am trying to login the user after successful sign up. However I am getting below error -

TypeError: undefined is not an object (evaluating 'sjcl.codec.bytes.toBits')

var signin = {}; 

signin.login = function(){

signin.userName                 =       $("#loginUserName").val();
signin.userPassword             =       $("#loginPassword").val();

AWSCognito.config.region = 'us-east-1';
AWSCognito.config.credentials = new AWS.CognitoIdentityCredentials({
    IdentityPoolId: '...' // your identity pool id here

// Need to provide placeholder keys unless unauthorised user access is enabled for user pool
AWSCognito.config.update({accessKeyId: 'anything', secretAccessKey: 'anything'})

var authenticationData = { 
    Username : signin.userName,
    Password : signin.userPassword,
var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
var poolData = { 
var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
var userData = { 
    Username : signin.userName,
    Pool : userPool
var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
    onSuccess: function (result) {
        console.log('access token + ' + result.getAccessToken().getJwtToken());

    onFailure: function(err) {



Here is my repository for the code, Really appreciate any help in this regard.

Thanks & Regards


This comment has been minimized.


itrestian commented May 20, 2016

Hi Jeetendra,

This happens because the Stanford JavaScript Crypto Library doesn't include the bytes codec that the SDK uses so it must be included with the --with-codecBytes option when configuring the Stanford JavaScript Crypto Library (see sjlc README/INSTALL). It is known to build on Linux and requires a Java runtime.



This comment has been minimized.

samuelsensei commented May 20, 2016

This might help you out.

One of the comments has a zip file with the bytes codec included in the sjcl. It should do the trick.


This comment has been minimized.

jeetendra-choudhary commented May 21, 2016

Hi @itrestian ,

Thanks for the information and reference, however I am not very sure how to proceed with this issue. I am using local machine to test this and have the java runtime available, but I am not able to configure and use SJCL due to lack of proper documentation regarding this. Is there any more specific documentation on how to utilise it with plain javascript.

@samuelsensei the provided link doesn't work and gives a page not found error.

I have created a question on Stack Overflow for same.

Thanks & Regards


This comment has been minimized.

appeality commented May 22, 2016

The link provided by samuelsensei is broken, this should link directly to the zip of the library with the codec included:



This comment has been minimized.

jeetendra-choudhary commented May 22, 2016

Hi @appeality,

Thanks a lot you made my day. Now it works perfectly. Thank you very very much.

Best Regards


This comment has been minimized.

amank12 commented Dec 11, 2016

I am getting following error using similar code for authenticating user ;

"amazon-cognito-identity.min.js:19Uncaught TypeError: Cannot read property 'hex' of undefined(…)"

I tried with sjcl.js attached in this thread.


This comment has been minimized.

appeality commented Dec 11, 2016

@amank12 Are you using Angular 2 cli?


This comment has been minimized.

amank12 commented Dec 12, 2016

I am using JavaScript in HTML.

This problem got resolved after I changed order of js files included at top of file.


This comment has been minimized.

owlstack commented Feb 16, 2017

@appeality Where should I include that file?


This comment has been minimized.

jeetendra-choudhary commented Feb 18, 2017


You should include below mentioned scripts in your index.html file or which ever file you are loading first.

<!-- Javascript -->
    <script src="assets/js/jquery-1.11.1.min.js"></script>
     <script src=""></script>
    <script src="assets/js/jsbn.js"></script>
    <script src="assets/js/jsbn2.js"></script>
    <script src="assets/js/sjcl.js"></script>
    <script src="assets/js/moment.js"></script>
    <script src="assets/js/aws-cognito-sdk.min.js"></script>
    <script src="assets/js/amazon-cognito-identity.min.js"></script>
    <script src="assets/js/aws-sdk.min.js"></script>
    <script src=""></script>
	<script src=""></script>
  			defaultJSExtensions: true
    <script src="assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/js/jquery.backstretch.min.js"></script>
    <script src="assets/js/scripts.js"></script>
    <script src="assets/js/signup.js"></script>
    <script src="assets/js/signin.js"></script>
    <script src="assets/js/APP_CONSTANT.js"></script>

    <!--[if lt IE 10]>
        <script src="assets/js/placeholder.js"></script>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.