Caligatio / jsSHA

A JavaScript/TypeScript implementation of the complete Secure Hash Standard (SHA) family (SHA-1, SHA-224/256/384/512, SHA3-224/256/384/512, SHAKE128/256, cSHAKE128/256, and KMAC128/256) with HMAC.

Home Page:https://caligatio.github.io/jsSHA/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

outputFormat must be HEX, B64, or BYTES

FrancescoMussi opened this issue · comments

Pleaseeeeeeeeeeee
can you be so kind to tell what is wrong in this line:

headerParameters.oauth_signature = encodeURIComponent(oauthSignatureObject.getHMAC(encodeURIComponent(secretKey) + "&" + encodedTokenSecret, ["TEXT", "SHA-1", "B64"]));

My (ionic2) app break exactly there throwing this error:

outputFormat must be HEX, B64, or BYTES

screenshot

I have trying modifying everything but nothing works.

I am following this tutorial for twitter integration with Ionic2:
http://blog.ionic.io/twitter-app-ionic-2/

By the way it seems that we are force to use jssha 1.6 because ngCordovaAuth doesn't support jssha v2.
But now it seems also that DefinitelyTyped doesn't support jssha 1.6.

Shoud I start using drugs or there is actually a solution?

Thanks!

Thanks for replying.
I have tried with 4 values (hope I did it right):

headerParameters.oauth_signature = encodeURIComponent(oauthSignatureObject.getHMAC(encodeURIComponent(secretKey) + "&" + encodedTokenSecret, ["TEXT", "SHA-1", "B64", "HEX"]));

But I was getting the same error.

I have then changed that line keeping the original given by that tutorial:

headerParameters.oauth_signature = encodeURIComponent(oauthSignatureObject.getHMAC(encodeURIComponent(secretKey) + "&" + encodedTokenSecret, "TEXT", "SHA-1", "B64"));

This line was giving the error: Supplied parameters do not match any signature of call target

Most probably because it is jsSHA 1.6 syntax that is not supported anymore by DefinitelyTyped.

The only workaround was to change the index file of jsSHA file for DefinitelyTyped with the 1.6 version - that I was able to find somewhere:

https://github.com/slavomirvojacek/adbrain-typescript-definitions/blob/master/jssha/jssha-1.6.0.d.ts

With that line of code and this file everything works perfectly.
I manage to create a signature and do all the stuff with the Twitter API.

Yesterday I had already opened an issue with DefinitelyTyped and contacted the creator of ngCordovaOauth - that since 2015 doesn't support jsSHA v2 - that's why the tutorial tells to keep jsSHA at 1.6 version:

screenshot

Let's see if we can find a definitive solution.

Thanks for your help!

So I'm going to start this by saying I don't really know anything about DefinitelyTyped however, it appears that you can include the the mapping file (or whatever the proper term is) in the package itself. That being said, I'd be happy to include the mapping file if someone does a PR that includes it, even against the v1 branch.

Closing this due to lack of activity and issue being with DefinitelyTyped.