helium / helium-js

Official TypeScript packages for interacting with the Helium blockchain
Apache License 2.0
110 stars 35 forks source link

Can not find a way to restore a keypair created from Keypair.makeRandom() #244

Open idoor88 opened 3 years ago

idoor88 commented 3 years ago

Hi, I created a KeyPair from: let keypair = await Keypair.makeRandom(); then I have the pubilcKey, privateKey and address saved, later on I need to restore the keypair object so I can use it when sign: const signedPaymentTxn = await paymentTxn.sign({ payer: keypair });

it seems I can not find a way to restore the keypair from the pubilcKey, privateKey and address I saved.

Any clues? Thanks in advance

sawyerru commented 3 years ago

Hello,

I am facing a similar issue and raised the following issue. I was told to basically store the entropy that is used to generate the keypair initially. Like so:

import { Keypair, utils } from '@helium/crypto'

const keypairEntropy = await utils.randomBytes(32)
const keypair = await Keypair.fromEntropy(keypairEntropy)

I would prefer to have some ability to regenerate the keypair from the privateKey hex string, so I'll keep you updated if theres a separate method in the underlying libsodium-wrapper method that can be used.

idoor88 commented 3 years ago

Yes, I ended up doing the same thing. Thanks

ygcool commented 3 years ago

Is there a solution? Are there any examples? Thanks