Coder Social home page Coder Social logo

Comments (23)

junderw avatar junderw commented on July 23, 2024

Yes you can. Just derive sequential integers for the address index.

from bip39.

junderw avatar junderw commented on July 23, 2024

Please post your JS/TS code if you would like further assistance.

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Here is my code, please show me how to get all wallet addresses like bitcoinj:

const mnemonic = '...';
const seed = bip39.mnemonicToSeedSync(mnemonic);
const node = bip32.fromSeed(seed);
const bitcoinNetwork = bitcoin.networks.testnet
const hdMaster = bitcoin.bip32.fromSeed(seed, bitcoinNetwork)
const address = bitcoin.payments.p2pkh({ pubkey: node.publicKey, bitcoinNetwork }).address;

const keyPair = hdMaster.derivePath('m/0')
const privateKeyBuffer = Buffer.from(keyPair.privateKey);
const privateKey = privateKeyBuffer.toString('hex');

console.log(address + " " + privateKey);

Thanks for the help !!

from bip39.

junderw avatar junderw commented on July 23, 2024

I don't understand.
What is the difference between node and hdMaster...?
Why is privateKey based on m/0 while address is based on m paths?

Can you give me a sample mnemonic and the expected addresses + private keys? (multiple)

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

You can give me your skype or email, I would like to chat with you. Thanks!!

from bip39.

junderw avatar junderw commented on July 23, 2024

My email is on all my commits, and my github profile.

But tbh, it is better to have these discussions out in the open.
Just make a new mnemonic, put it into your bitcoinj app, and post the addresses and keys that pop out.
If it's a brand new random mnemonic there's no reason why you can't share it openly.

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

I am new to bitcoin so do not understand much about it, can you tell me how to get all the wallet address and private key like bitcoinj created?

from bip39.

junderw avatar junderw commented on July 23, 2024

You are saying "like bitcoinj created"

So I am assuming you have an existing app that is using bitcoinj, and you're trying to recreate that in nodejs with bitcoinjs?

In that case, put the following mnemonic into your bitcoinj app and tell me what address(es) it gives you.

pave cook hair interest sad gift mosquito service early volume deal solar

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

This is my mnemonic :

vicious fork like burden broom couch giraffe foil lobster vehicle over park park

In bitcoinj, the test net, my wallet address is::

addr:mkZmHTqtAfqrhrL1kNHPHN7KtyXpLk2AwD hash160:3760af9bb1a306d8b0d29111a71e1714e848cdf7 (M, root)
addr:mzfoeKrivn9qwEYY3mXLYeC5t3XMv57e6M hash160:d216e998c60687222c08a793f838988836a52d8c (M/0H, account)
addr:moSQVNyX8axM174vmmUVwsTY8nosUH5eAY hash160:56e4cb0d4a82541d83b954d68a1bdfb935f9f7d8 (M/0H/0, external)
addr:mrz6cADNkQKTVR6RednxzXjixpQGtZMDox hash160:7dcb8da0eeaba02d796a686383c57e1ade6ea617 (M/0H/1, internal)
addr:mpC8aH8pcrNzy5hzBhTgdgZv12jbs6FBVa hash160:5f29cf5403cc642728a0c85594aaaeed0323bb5e (M/0H/0/0)
addr:mkycrQEFcVKPENg4TPCVyy5aYpYfAyacz6 hash160:3be3a15a2f47daab4b2c450149db30fbe13b89f2 (M/0H/0/1)
addr:muRTbfmUMt7XSZR143hTWZk6rC7SkvPKwY hash160:9887ba0980b4a55245f063ac85130122cf882718 (M/0H/0/2)
addr:mns93KwuVnrnLUrcdeC7o353dQ18hWSXF9 hash160:509a2b8c5277ba49768978a1527aa6954a8cc135 (M/0H/0/3)
addr:mtoZZtFHEJXVGwwKpm3uCuapaVPioDVrzB hash160:91bdbc2536395a220a2afa8035fc1a80bc0b801a (M/0H/0/4)
addr:muVAUZ1thodKehuFUk9gL1fn6x7QAetihc hash160:993b18e53391a8b2b803716aaa3028ddef530c71 (M/0H/0/5)
addr:n364APV7cd7789tuYgXk99d78ZcdGdVuBr hash160:ec9d443427fc9753b985fd4b3598f2adf690510a (M/0H/0/6)
addr:mjHQaE5migddtoynPB5aFhBELWNBWDJDjX hash160:29509dbb1166c8a5dc80c954c4dc0a6080d40384 (M/0H/0/7)
addr:mn92ykB6woJsxzXJdRMmrksmaJsZdUk9Ns hash160:48a3a3bd70e7b5f9774f80624a085179f34f5d02 (M/0H/0/8)
addr:mwAWVSLMm5gNB8uFwcJMBP99UrZ4FV8pgc hash160:aba427477bdcfc17cb8f7a8d52aa74aadeadd6cd (M/0H/0/9)
addr:mtneUknMcRUjJpZ9UiFMqNs4adM3P7aQ42 hash160:91916b40bf90152aa2b515ffe640c9abcd1412ac (M/0H/0/10)
addr:mv6fUfdis6d3BsMvqVBSfALFH4wSBLH8RC hash160:9ff1dd93926232f3d7141b67a5047afc30496eb6 (M/0H/0/11)
addr:n3NjerqHtdfJL4Y2x2vb51EwkkGkMS1M1D hash160:efc4e31bca8baf1032cdcbf30c333e4ccbe28930 (M/0H/0/12)
addr:mqCjhBLrmrhtSWRz6r7Dpr44q7ehgE2cVP hash160:6a3f406222e54a43043810cfc9e0e679e4a28acb (M/0H/0/13)
addr:mp7zYwwVYZyYZ6JQy2L75e5SzHbxx7Te9h hash160:5e6172e52a120deca537289323efce05c19f3b5e (M/0H/0/14)
addr:mnBfPASXzgV7nFe3FLfGU5op2D276SSEiV hash160:4922dc202a32037aa3f1722789c9317c66654213 (M/0H/0/15)
addr:mipfqGKCW3QbYxeFxPAPFVhc4Aip6hTBUr hash160:24421f7b5e81b9b07289d6c6e2dc2a85c69ab15e (M/0H/0/16)
addr:mv4XYD3dCtRe16qzbsYhiUDqGn9Ddmtrk7 hash160:9f8a681189ee7a7e0ba0ea0e82c43c27d064b718 (M/0H/0/17)
addr:n36hKeLTUAW31mKXSYUM67LatYXXXRkPj8 hash160:ecbc4922740590bb121a4d718d0399831a21aef6 (M/0H/0/18)
addr:n2ruHmRgd9Tp7FTKCehjtwtAJ9S91uZTd5 hash160:ea2073c915eb88edc96e5bd5c5e44defc9c34487 (M/0H/0/19)
addr:mzSKqsQNAdGm8TLUMq6uridkzLSFnquTcy hash160:cf8a4c4384249305afaafd69a83d5c206d63bb47 (M/0H/0/20)
addr:mik2LFXfKscBy4WrmrZcBZYUCDBJo67MBE hash160:236127cf8bf28fda358f665073918774ff606648 (M/0H/0/21)
addr:miwAvQDTxuyx4eHTsSVteQ3ZQDrPuebRs4 hash160:257ce69105b1ba6a0411ab9bbf9957b426167bc5 (M/0H/0/22)
addr:mydpXc5xqUUhCxBHKEj2TW9aS4wczWDvX7 hash160:c6beb15c8a458da7c703a33d047a92681082a82d (M/0H/0/23)
addr:mnQt7mkg8bMzJxufXQEMJ1RsgxYHcLnced hash160:4ba2e5d0231625db532685de1a4

Thanks for support !!

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Currently I have the private key of one wallet, hopefully from it we will get a way to get the private key of other wallets:

address : mpC8aH8pcrNzy5hzBhTgdgZv12jbs6FBVa
private key : 3d6982c7687c3892ebf32bd092cb2be47d115a39453c218a8e01fd882ec82549

from bip39.

junderw avatar junderw commented on July 23, 2024

getKeysFromMnemonic('vicious fork like burden broom couch giraffe foil lobster vehicle over park park')

const bip39 = require('bip39')
const bitcoinjs = require('bitcoinjs-lib')

const DEFAULT_OPTS = {
  keyCount: 25,
  startingKey: 0,
  isChange: false,
  network: bitcoinjs.networks.testnet,
}

function getKeysFromMnemonic(mnemonic, opts) {
  const {
    keyCount,
    startingKey,
    isChange,
    network,
  } = Object.assign({}, DEFAULT_OPTS, opts)

  const seed = bip39.mnemonicToSeedSync(mnemonic)
  const root = bitcoinjs.bip32.fromSeed(seed, network)
  const account = root.deriveHardened(0)
  // can also be derived with root.derivePath(`m/0'/0`)
  const external = account.derive(0)
  // can also be derived with root.derivePath(`m/0'/1`)
  const internal = account.derive(1)

  const keys = []
  function pushKey (key, path) {
    const payment = bitcoinjs.payments.p2pkh({
      pubkey: key.publicKey,
      network
    })
    keys.push({
      path,
      address: payment.address,
      hash160: payment.hash.toString('hex'),
      privateKey: key.toWIF(),
    })
  }

  pushKey(root, 'M, root')
  pushKey(account, 'M/0H, account')
  pushKey(external, 'M/0H/0, external')
  pushKey(internal, 'M/0H/1, internal')

  const inExIndex = isChange ? 1 : 0
  const internalOrExternal = isChange ? internal : external
  for (let i = startingKey; i < startingKey + keyCount; i++) {
    const key = internalOrExternal.derive(i)
    pushKey(key, `M/0H/${inExIndex}/${i}`)
  }

  return keys
}

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Wow !!! Thanks you very much !!!

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

How to convert private key : "cPe5XTzR26eJehgRZj42Bfooa2yoLtHUMYbD17C8eJNoRe3y5HXy" -> to private as hex :
"3d6982c7687c3892ebf32bd092cb2be47d115a39453c218a8e01fd882ec82549" ?

Thanks you !!

from bip39.

junderw avatar junderw commented on July 23, 2024

key.toWIF() -> key.privateKey.toString('hex')

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Is the number of wallet addresses created limited?
Thanks !!

from bip39.

junderw avatar junderw commented on July 23, 2024

minimum index is 0
maximum index is 2147483647

So you could do
(I updated the function to use an option object instead of a bunch of parameters)
getKeysFromMnemonic(mnemonic, { startingKey: 2147483647, keyCount: 1 })
or
getKeysFromMnemonic(mnemonic, { startingKey: 2147483600, keyCount: 48 })
if you wanted.

getKeysFromMnemonic(mnemonic, { keyCount: 2147483647 })
will take forever.

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Thanks for your answers !!!

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Hello, Is this library for long term use in the future?

from bip39.

junderw avatar junderw commented on July 23, 2024

I don't understand your question.

It is released under the ISC license, so that means:

  1. We have no obligation to you. No warranty etc.
  2. You have no obligation to us. You can use this forever if you want.

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Thanks you !!!

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Hello bro, I have questions please help me

  1. How to get balance BTC wallet
  2. How to send a transaction to an address
  3. Show me how to get the transaction history of the wallet

Thank you for your help !!

from bip39.

junderw avatar junderw commented on July 23, 2024

2 is in the integration tests.

1 and 3 are varied and there are many ways to do it. In general you should run your own Bitcoin node and figure out a way to get utxo info from it. (RPC is one way, or some app that sits on top of bitcoin like NBXplorer is another way)

from bip39.

suusofttruongnv avatar suusofttruongnv commented on July 23, 2024

Hi bro,
I want to use Bitcoinjs-lib to do the above 3 things, is it possible? if so please let me know the code!
I just want to use Bitcoinjs-lib without a third party!

Thanks !!!

from bip39.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.