node-sdk icon indicating copy to clipboard operation
node-sdk copied to clipboard

How to do Payload Encryption with the SDK

Open jerryOkafor opened this issue 6 years ago • 15 comments

I am working on a project that uses the SDK, I have followed the guide on the Readme.md and when I make a call, I get Invalid credentials. I am thinking it is because of the payload encryption as stated here: https://portal.hyperwallet.com/docs/api/v3/overview/payload-encryption. When I informed my boss, he sent this link: https://github.com/hyperwallet/node-sdk/blob/master/test/utils/ApiClient.spec.js#L220. My confusion is this, the entire doc does not show how you can add encryption to the request that you make seamlessly. I don't know if anyone has done that before.

jerryOkafor avatar Mar 08 '19 22:03 jerryOkafor

I see this param in the src: @param {Object} [config.encryptionData] - The JSON object of encryption data What is encrptionData?

jerryOkafor avatar Mar 08 '19 22:03 jerryOkafor

Hi @jerryOkafor

Sorry for the delay. See if this example helps you:

var encryptionData = {
     clientPrivateKeySetPath : EncryptionConfig.CLIENT_PRIVATE_KEYSET_PATH,
     hyperwalletKeySetPath : EncryptionConfig.HYPERWALLET_KEYSET_PATH
};

var client = new Hyperwallet({
    username: username,
    password: password,
    programToken: programToken,
    encryptionData: encryptionData
});

client.getBankAccountStatusTransition(userToken, bankAccountToken, statusTransitionToken, (error, body, res) -> {
   console.log(res);
});

Also before using encrypted calls by sdk, public jwk set of sdk user must be registered on the Hyperwallet side, without this encryption won’t work

wmews-hw avatar Mar 13 '19 00:03 wmews-hw

Btw... thanks for your feedback about our documentation. We are working now finding the gaps and make our integrator's life easier.

wmews-hw avatar Mar 13 '19 00:03 wmews-hw

Thanks for your feedback, I think I am getting close. One more thing, the filed : EncryptionConfig.CLIENT_PRIVATE_KEYSET_PATH is set to https://uat-api.paylution.com/jwkset while CLIENT_PRIVATE_KEYSET_PATH is set to /app/layer7/private-jwkset. I am still confused on how these paths are set. I can not find the specified path /app/layer7/private-jwkset in the example Here.

jerryOkafor avatar Mar 13 '19 13:03 jerryOkafor

CLIENT_PRIVATE_KEYSET_PATH - is the path where your private jwk keys set is located( it can be path to file or URL). The file located on /app/layer7/private-jwkset at github is encrypted because it contains private keys, so you can’t view it. In this example CLIENT_PRIVATE_KEYSET_PATH must be set with user’s own private jwk set, that can be easily generated. And the public part of that generated jwk set must be registered (you may contact our team to do it for you) at Hyperwallet side along with the REST user with which you make REST calls.

HYPERWALLET_KEYSET_PATH - is the location of Hyperwallet public jwk keys set. For example: https://uat-api.paylution.com/jwkset

wmews-hw avatar Mar 13 '19 16:03 wmews-hw

@wmews-hw thanks for your support. I have tried to generate the jwkset using the following command : openssl x509 -in certificate.pem -pubkey -noout and tool : https://russelldavies.github.io/jwk-creator/. I hope I am in the right direction. If not, I would appreciate it if you can give me any definitive guide on how to generate and use this key.

jerryOkafor avatar Mar 14 '19 07:03 jerryOkafor

@wmews-hw after weeks of trial, I have succeeded in doing payload encryption using the jwkset in this repo for testing purposes. Another issue showed up : [ { "message": "Invalid Content-Type specified in Response Header" } ] What could be the reason for such an error?

Thanks in advance.

jerryOkafor avatar Mar 22 '19 15:03 jerryOkafor

@jerryOkafor could you confirm if it is related to this issue: https://github.com/hyperwallet/node-sdk/issues/16 We didn't release it yet, but if so I will prioritize it. Please let me know.

wmews-hw avatar Mar 22 '19 21:03 wmews-hw

@wmews-hw I have confirmed, it does not relate to the above issue. I am still experiencing the issue at the moment.

jerryOkafor avatar Mar 28 '19 13:03 jerryOkafor

@jerryOkafor We will need more information to be able to reproduce this issue. Could you please give us a example how your request looks like?

wmews-hw avatar Mar 28 '19 19:03 wmews-hw

@wmews-hw I will give you access to the local test app so that you can run it and see the response.

jerryOkafor avatar Mar 31 '19 10:03 jerryOkafor

@jerryOkafor A new version of our sdk was released. Could you please confirm whether it fix or not the issue you've reported? https://www.npmjs.com/package/hyperwallet-sdk/v/1.3.1

wmews-hw avatar Apr 09 '19 19:04 wmews-hw

ok, I will do that @wmews-hw. Thanks for your assistance.

jerryOkafor avatar Apr 18 '19 12:04 jerryOkafor

@wmews-hw I have a similar problem with Encryption and there is nothing said in the Hyperwallet documentation. Could you explain how to generate these private and public keys? I reckon it's easy when you know what you do :) Do I need server private key and based on this can I generate keys?

Marcin-TA avatar May 07 '19 15:05 Marcin-TA

@jerryOkafor Could your guide on how to generate and use this key?

Marcin-TA avatar May 09 '19 14:05 Marcin-TA