09-26-2018 08:11
09-26-2018 08:11
In order to communicate with certain APIs I need the companion to be able to create SHA256 signatures and SHA512 HMACs. Unfortunately, `require('crypto')` as you would in nodeJS does not import the cryptography library.
Is there a way to import the standard node Crypto library or otherwise generate those signatures? I don't feel smart enough to roll my own hashing functions.
Answered! Go to the Best Answer.
Best Answer09-27-2018 01:43
09-27-2018 01:43
Found a way!
If anyone comes looking for a way to create HMAC and SHA512/SHA256 cryptography on the Fitbit companion, this answer will probably help you along. On top of that, you'll have to use Tjeerd's method of including the CryptoJS library.
Best Answer09-26-2018 12:49
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
09-26-2018 12:49
You'll need an ES6 module to import. Just place the js file in your companion folder and import from it.
Best Answer09-26-2018 12:59
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
09-26-2018 12:59
I see you also saw this thread https://community.fitbit.com/t5/SDK-Development/Using-non-ES6-modules/m-p/2972514#M6292
Best Answer09-26-2018 13:16
09-26-2018 13:16
Best Answer09-27-2018 01:43
09-27-2018 01:43
Found a way!
If anyone comes looking for a way to create HMAC and SHA512/SHA256 cryptography on the Fitbit companion, this answer will probably help you along. On top of that, you'll have to use Tjeerd's method of including the CryptoJS library.
Best Answer09-28-2018 14:31
09-28-2018 14:31
Crypto-js also supports ES6 import: https://github.com/brix/crypto-js/blob/develop/README.md
That should make 'my' alternative way of importing non ES6 modules in this case obsolete.
Best Answer09-28-2018 20:10
09-28-2018 20:10
So I'm a little bit new to NodeJS. If I do `npm install crypto-js`, I have to copy over the library from the node_modules to the companion folder? Because if I just leave them in node_modules, the imports fail at runtime.
Best Answer09-29-2018 03:55
09-29-2018 03:55
I tried both: copying it into the companion folder as well as keeping them in the node_modules folder. I then tried importing as per the README, but the build fails:
[18:53:36][error] Error: 'sha256' is not exported by node_modules/crypto-js/sha256.js
respectively:
[18:53:36][error] Error: 'sha256' is not exported by ./crypto-js/sha256.js
Best Answer09-29-2018 07:31
09-29-2018 07:31
Silly me; I was using curly braces to import. But that said, I still cannot get access to the create functions without importing all of cryptoJS.
Also see this SO question
Best Answer06-09-2021 04:14
06-09-2021 04:14
I'm glad you've solved your problem. Things like this happen, and it's good to know that we can find the solution here
Best Answer07-05-2021 10:11
07-05-2021 10:11
When you receive a signed token, the WIF-based web service must trust that instance of the AD FS.
Best Answer09-29-2021 02:37
09-29-2021 02:37
I usually use a crypto mixer
Best Answer