3

I am trying to use blockapps-js to invoke functions on my smart contract deployed in blockapps. Since I need the private key for it, I am looking at the app/users/admin/.json file. Problem is I cannot figure out which of these fields to use. Is it encPrivKeys.key? My code is not working yet, and am trying to figure out whether that is the cause.

{
  "encSeed": {
    "encStr": "...",
    "iv": "...",
    "salt": "..."
  },
  "encHdRootPriv": {
    "encStr": "...",
    "iv": "",
    "salt": ""
  },
  "hdIndex": 1,
  "encPrivKeys": {
    "": {
    "key": "...",
    "iv": "",
    "salt": ""
  }
},
  "addresses": ["..."],
  "keyHash": "...",
  "salt": {
    "words": [, -,,],
    "sigBytes": 16
  }
} 
4

I'm not familiar with blockapps, but encprivkey is going to be your encrypted private key. The key is encrypted by the iv (hash) field and then salted with the salt field.

You will need to decrypt the private key before you can use it. ;)

4

OK, not sure if it's the best way of doing it, but I finally made it happen.

Here is how:

npm install eth-lightwallet
node
>var lightwallet = require("eth-lightwallet")
>var upgrade = require("eth-lightwallet/lib/upgrade")
>var jsonStr='contents of ./app/users/admin/*.json file'
>var newJSON
>upgrade.upgradeOldSerialized(jsonStr, , function(err, tmpJSON) {newJSON=tmpJSON;console.log(newJSON);});
>keystore = lightwallet.keystore.deserialize(newJSON);
>var derivedKey;
>lightwallet.keystore.deriveKeyFromPassword('', function (err, pwDerivedKey) {derivedKey = pwDerivedKey;});
>var addresses = keystore.getAddresses();
>keystore.exportPrivateKey(addresses[0], derivedKey);

I used advice from this post, however, sdk-s have changed since.

  • If this is the correct answer, then feel free to mark it as correct. – tayvano Apr 18 '16 at 21:08
  • In the version I installed today the deriveKeyFromPassword function doesn't exist, and there is deriveKeyFromPasswordAndSalt. However the salt argument is optional. – paulmorriss Nov 20 '17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.