renproject / send-crypto

A minimal JavaScript library / wallet for sending crypto assets
MIT License
53 stars 14 forks source link

BTC account using bip84 private key #32

Open rkyshz opened 3 years ago

rkyshz commented 3 years ago

How do I use a bip84 private key generated from a seed phrase generated here. I get invalid private key buffer error.

iamnotstatic commented 2 years ago

First of all this library operates on BIP 44 so while interacting with it you might not get accurate results.. So i will advise you to use BIP44 if you want to use this library..

About the invalid private key buffer i believe you're pasting a WIF or hex key and it's expecting a Buffer one way to solve this is to use ECPair to convert the key to Keypar then pass the private key here a sample

// If private key is a WIF
const keyPair = ECPair.fromWIF('L1jbWJZUKyuVDyjqYiU4e4BxWj5mxrzXkYC4pyvX2MVAAaTu88Sx');
const account = new CryptoAccount(keyPair.privateKey);
// If private key is hex 
// Remove the first 0x on the hex 
const keyPair = ECPair.fromPrivateKey(
    Buffer.from(
      '394cf5961b2a0136d7b69b676c45bcc9dcc929b66f8380b7253ef60284cde13cf',
      'hex'
    )
  );

const account = new CryptoAccount(keyPair.privateKey);