bnb-chain / javascript-sdk

Javascript SDK to communicate with BNB Beacon Chain.
Apache License 2.0
382 stars 240 forks source link

crypto.generateSignature: error TypeError: Expected Private #85

Closed talbeerysec closed 5 years ago

talbeerysec commented 5 years ago

Tried to follow code from tests (https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/client.test.js) and example from wiki (https://github.com/binance-chain/javascript-sdk/wiki/API-Examples)

in all of them I get "TypeError: Expected Private" when calling to transfer

bnbClient.transfer(addressFrom, addressTo, amount, asset)

error: error TypeError: Expected Private at Object.generateSignature (/Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/crypto/index.js:199:41) at Transaction.sign (/Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/tx/index.js:141:30) at BncClient._callee$ (/Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/client/index.js:54:49) at tryCatch (/Users/talbeery/WebstormProjects/Binance-test/node_modules/regenerator-runtime/runtime.js:65:40) at Generator.invoke [as _invoke] (/Users/talbeery/WebstormProjects/Binance-test/node_modules/regenerator-runtime/runtime.js:303:22) at Generator.prototype.(anonymous function) [as next] (/Users/talbeery/WebstormProjects/Binance-test/node_modules/regenerator-runtime/runtime.js:117:21) at asyncGeneratorStep (/Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/client/index.js:26:103) at _next (/Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/client/index.js:28:194) at /Users/talbeery/WebstormProjects/Binance-test/node_modules/@binance-chain/javascript-sdk/lib/client/index.js:28:364 at new Promise ()

Calling directly to

crypto.generateSignature('aaaaaa', bnbClient.privateKey);

gives the same error

talbeerysec commented 5 years ago

The error was on my side. The key was too short. (maybe consider checking that explicitly and throwing the relevant message)