moneybutton / bsv

Bitcoin SV javascript library
Other
204 stars 105 forks source link

BSV Library Version | HD Keys Confussion #253

Open imkrishnaagrawal opened 1 year ago

imkrishnaagrawal commented 1 year ago

Hi Everyone,

I am new to bsv ecosystem and have started a project using typescript/javascript. the obvious choice was bsv npm package as suggested by bsv official website and also followed along some courses however I am facing challenges understanding the versions , maintenance and future of bsv library. most of courses I followed at satolearn and other places are using old version of library which is 1.5.x and also moneybutton documentation is using 0.30.0 (https://about.moneybutton.com/docs/button/mb-crypto-operations). I am facing issue when creating HD Private and Public keys using Mnemonic. while looking at issues I found a solution however it is not working bsv.Mnemonic and bsv.HDPrivKey are undefined. I am using bsv@2.0.10.

const mnemonic = new bsv.Mnemonic()
const hdPrivKey = bsv.HDPrivKey.fromSeed(mnemonic.toSeed())
const someKey = hdPrivKey.deriveChild("m/5/2/8") // Private key
const somePubkey = someKey.publicKey
const address = somePubkey.toAddress()
console.log(address);

Errors:

const mnemonic = new bsv.Mnemonic()
                 ^
TypeError: bsv.Mnemonic is not a constructor
const hdPrivKey = bsv.HDPrivKey.fromSeed(mnemonic.toSeed())
                                ^
TypeError: Cannot read properties of undefined (reading 'fromSeed')

I need suggestion to get some understanding around the issue. Other developers might be facing similar challenges.

mathiasrw commented 1 year ago

I am facing challenges understanding the versions , maintenance and future of bsv library. most of courses I followed at satolearn and other places are using old version of library which is 1.5.x and also moneybutton documentation is using 0.30.0

Im with you on this one

afomi commented 1 year ago

The API has changed substantially between bsv-legacy and the updated bsv@2.0.10

const seed = bsvjs.Bip39.fromRandom().seed
const hdPrivKey = bsvjs.Bip32.fromSeed(seed)
const someKey = hdPrivKey.derive("m/5/2/8")
const somePubkey = someKey.pubKey
const address = bsvjs.Address.fromPubKey(somePubkey).toString()

console.log(address)
Zhell1 commented 1 year ago

using bips as the naming scheme is really confusing to newcomers and fails at the target purpose of It should not be necessary to read the source code of a class or function to know how to use it / so that other developers find the code easy to understand.

developers, especially newcomers, should not have to learn by heart which BIP number corresponds to a well-known feature of any bitcoin library, the feature should be described by its name for clarity and ease of use