harmony-one / sdk

Javascript SDK of Harmony protocol.
MIT License
92 stars 43 forks source link

addByKeyStore requires password of length > 0 #10

Closed mattlockyer closed 4 years ago

mattlockyer commented 4 years ago

using async addByKeyStore(keyStore: string, password: string): Promise<Account>

It's impossible to pass in a password of length == 0, even though this may be a popular option for test accounts or local environments.

Version: "@harmony-js/core": "^0.1.32"

Code to reproduce:

const keystore = '...'
const delegator = await harmony.wallet.addByKeyStore(keystore, '')

Temp fix for line 107 of account.js (dist):

if (!password) {
  throw new Error('you must provide password');
}
// guessing... !password evaluates to false for '' if coming from TypeScript?
// below I want to skip this throw...
if (false && !password) {
   throw new Error('you must provide password');
}
neeboo commented 4 years ago

Maybe I would provide another import method to put the keystore to account Map. Because initially, I only think that if we can not decrypt an keystore , we should not own the privateKey behind.

For your case. I will try fix the length problem. Hang in there

neeboo commented 4 years ago

@mattlockyer would you try this branch to see if the empty string encryption works for you

https://github.com/harmony-one/sdk/tree/neeboo/keystore

neeboo commented 4 years ago

close due to https://github.com/harmony-one/sdk/commit/51d46f22a0394a281890d7710ba7897a4f01b36d