Getting a matching public key

I’m experiencing a problem with the js-sdk. when I try to call a contract method I get the “Invalid Key Pair” error. I just switched to using the production environment, and substituted my test priv/pub key pair with the live one I exported via waellet.
It seems like the public key is for some reason the problem, it doesn’t match what is expected, even though everything is valid (used and tested in the waellet and superhero), I deployed a contract with it using AE studio …

maybe this will help you https://github.com/aeternity/tutorials/blob/master/making-aeternity-wallet-transactions-with-aepp-sdk-js.md#keypair-creation-with-an-existing-private-key

Unfortunately it doesn’t :frowning:
I got the public key but I still get the same “Invalid Key Pair” error when trying to use it to call a contract.

const {Crypto} = require('@aeternity/aepp-sdk');

function generateKeyPairWithExistingPrivateKey(secretKey){
  const hexBuffer = Crypto.hexStringToByte(secretKey);
  const keyPair = Crypto.generateKeyPairFromSecret(hexBuffer)
  const publicKey = Crypto.aeEncodeKey(keyPair.publicKey);
  return {publicKey: publicKey, secretKey: secretKey};
}

const keyPair = Crypto.generateKeyPair();
console.log(keyPair.publicKey === generateKeyPairWithExistingPrivateKey(keyPair.secretKey).publicKey)

this generates the same publickey for me.

Probably the issue is then in how you try to call the contract.

Not the issue with contract cal. What fails is the method in es/utils/crypto.js which is called isValidKeypair.
So again to mention, this happens when I export the keys from Waellet extension. If I generate the account via aecli those keys work fine.

how do you do that?

Go into settings and export the private key

I see, the waellet uses HD keys internally, the exported key is not managed within the HD tree, just the plain keypair of the corresponding seed, the exported key is not compatible to be used with the sdk currently.

When wanting to use waellet with an aepp, consider to use the AEX-2 interface for wallet connections.

also maybe @milenradkov.chain has something to add

Ok, is there a way that I get to the keys which are compatible with the sdk?

From the keys I exported from our Waellet/Superhero account. It’s important because we have live contracts published with those keys, and I do need them because we use the aestudio to interract with the contract.

Does AE studio use the HDwallet or a single key-pair?

Both waellet and superhero do use HDwallets and allows export/import of such.

AE studio uses superhero wallet, you don’t use your keys there directly (https://studio.aepps.com/)

So just to get back to the problem. Can I get to the key format I can use with the js-sdk?

Just export your seed and import it in the sdk?

Is there any documentation or examples on how to do this?

4 Likes

Yup, did the trick, thanks Milen :slight_smile:

2 Likes