Git Product home page Git Product logo

bcoin-guide's People

Contributors

impranshu avatar pinheadmz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bcoin-guide's Issues

[JOURNAL] Week 02 (Pradyuman)

Name: Pradyuman Verma
Topic: Week 2 Journal

What I learned:

  • This week, I learned about double-spent attack and chain reorg; we also demonstrated this attack in local regtest mode. You can check out my blog.
  • Checked the bcoin configuration file and, successfully ran multiple nodes on a different port and connecting them.
  • Used different commands with their parameters, e.g. bcoin --network=regtest has many helpful parameters --log-level=info, --max-inbound, --max-outbound, --selfish.

Questions:
Q1. What is api-key, and why it is used?
-> It is a secret key used by RPC. It is required to access all endpoints. Otherwise, you will get a 401 unauthorised error is returned. The API key is set either in wallet.conf or the --api-key argument at launch. It is a general configuration not mandatory to use.
Q2. What is a Wallet token?
-> Every individual wallet has its security token, a 32-byte hash calculated from the wallet master key. A wallet is always created with a corresponding token. The token is returned when a wallet is created or from the bwallet-cli info API endpoint. When wallet-auth is set to true, the token must be sent in the query string or JSON body for any requests regarding that wallet. Requests with incorrect tokens are rejected with a 403 Forbidden error.
Q3. What is wallet-auth?
-> Without wallet-auth: true, other applications on your system could theoretically access your wallet through the HTTP server without any authentication barriers. wallet-auth: true requires a wallet's token to be submitted with every request, which add extra security.

[JOURNAL] Week 01 (Pradyuman)


Name: Pradyuman Verma

Questions :
Q1: What are tests?
-> test are used for various things like to prevent regression and also for documentation.
Q2: Difference between network=regtest and network=testnet?
-> testnet is out on the internet, but regtest is on local. regtest do not connects to any external nodes. It is all in your local computer only while testnet is more like mainet. You are synced to a blockchain and can transfer coins to any other node.
Q3: Bwallet-cli vs bcoin-cli?
-> bcoin run two servers, one for wallet and the other for full node. Each server has two API commands to fetch JSON data.

We also discussed some questions from the week1 guide;
Q1: When you requested an address, you got a JSON blob with data like account, branch and index. Do you know what these mean?
-> the JSON response is like this-

{
  "name": "default",
  "account": 0,
  "branch": 0,
  "index": 3,
  "witness": false,
  "nested": false,
  "publicKey": "03af169e5a186bbd7b380cb4553c72af243e18f243785b1597f192bbedd4a94fc3",
  "script": null,
  "program": null,
  "type": "pubkeyhash",
  "address": "n2eoT9D8txT5ZymDvCFPA8PHs2CmTV6oJT"
}

where,
account = This splits the keyspace into independent user identities, so the wallet never mixes the coins across different accounts. Users can use these accounts to organize the funds in the same fashion as bank accounts; for donation purposes (where all addresses are considered public), for saving purposes, for common expenses etc. Accounts are numbered from index 0 in a sequentially increasing manner. This number is used as a child index in BIP32 derivation.
branch = According to BIP44, an account has two children (known as branches): the first for receiving addresses and the second for change addresses. Here in bcoin, there is also a third branch for nested segwit addresses. (bcoin does not implement BIPS 49 and 84 yet.) These three branches can, in turn, have as many children as needed.
index = index of address in the branch.

Q2. What did you notice was different about the first wallet address vs the SegWit address?
-> In the first wallet, the wallet address starts with m..., which is a bech32 address, while the second wallet has a segwit address that starts with bc... which is a base58check.

Q3. When you sent the transaction, you got a big JSON blob back with data like fee, rate, and path. What do these mean?
-> rate is the transaction fees in sat/byte, fee is the total transaction fee (rate * size), and a path is an object which contains information on a particular path to a key in the tree hierarchy of the wallet.

Q4. When you checked your wallet balance, there is confirmed and unconfirmed. What's the difference? (bonus: how does bcoin use the terms differently than Bitcoin Core?)
-> In bcoin, confirmed refers to the total balance of coins confirmed in the blockchain, unconfirmed refers to the total confirmed plus unconfirmed transaction in the mempool, or we can say that `unconfirmed is the total future balance.

What I learned

  • many bcoin commands, and their implementation in javascript, and using curl.
  • about BIP 44, BIP 39, BIP 43 for hierarchical deterministic wallets.
  • BIP 141, 144, 143 for segwit.

I wrote a blog on this you can also check it out.

[JOURNAL] Week 2

I Learned about:

  1. Security --
    wallet-token: for each individual wallet
    api-key: for protecting access to server

  2. What is nodegyp?
    It is used to compile code in C for being used in JS

  3. Raspberry pie --
    small single board 35$ computer which can be used to run bitcoin-core

  4. What is jq?
    command-line JSON processor

  5. how does bwallet-cli work with bcoin full node?
    We add bcoin-wallet server as a plugin to the bcoin full node. Bcoin-wallet and bcoin-node are wrappers around http requests.

  6. what does onetry do?
    Add → adds to host list,
    remove → removes from host lis
    onetry → tries to connect to given node

  7. Double spending
    Interesting how we can invalidate blocks and perform reorgs.

  8. Why did we use 150BTC to test double spending?
    TBD

  9. How did we broadcast a tx hash without the actual transaction?
    TBD

[JOURNAL] Week 1

  1. Why npm rebuild and not npm install?

Node modules are stored on github, not relying on npm

gpk, nodegyp - language bindings between C++ and Javascript

  1. I learned:
  • bcoin has no signet like bitcoin-core
  • regtest - no peers, only me in network, for learning and testing
  • json RPC is similar to rest api
  • Confirmed is a subset of unconfirmed and not mutually exclusive like bitcoincore
  1. Still need to explore:
  • Taproot
  • apidocs
  1. What I can do:
  • use bcoin to develop some project
  • improve bcoin by writing tests
  • bring it to pace with bitcoin core by writing features that dont exist

Bitcoin wallet practice

  1. bwallet-cli master
{
  "encrypted": false,
  "key": {
    "xprivkey": "tprv8ZgxMBicQKsPfC8gLWcHksF3v5vHJ6YYxE7VWcUoRYTH1RnyjkFhD674Kw8ZySYr6ja4DZoCTbaicvByUPhhmWcYM4ykN8HhnYSdGVXeSUu"
  },
  "mnemonic": {
    "bits": 128,
    "language": "english",
    "entropy": "d4da09aa0fd0f033682fcc685578bb14",
    "phrase": "state space hedgehog cabbage audit boost pass wet hair profit conduct cinnamon"
  }
}
  1. bwallet-cli account=default address (to Recieve)
{
  "name": "default",
  "account": 0,
  "branch": 0,
  "index": 4,
  "witness": false,
  "nested": false,
  "publicKey": "0234822ad169884d87e2e2b207b8fd4626505a21c021bc08bea93b92eb11c4d366",
  "script": null,
  "program": null,
  "type": "pubkeyhash",
  "address": "mjW2JPbEyhitki4ktBH9WdWHAuaGth1qDZ"
}
  1. bcoin-cli rpc generatetoaddress 300 mjW2JPbEyhitki4ktBH9WdWHAuaGth1qDZ

  2. bwallet-cli balance

    {
      "account": -1,
      "tx": 300,
      "coin": 300,
      "unconfirmed": 1121250000000,
      "confirmed": 1121250000000
    }
  3. bwallet-cli mkwallet --id=Raj --witness=true

{
  "network": "regtest",
  "wid": 2,
  "id": "Raj",
  "watchOnly": false,
  "accountDepth": 1,
  "token": "3e839d6b1f5cc744a9ffd9b49f2f419d390acd104817be1fb81c562ae17bac63",
  "tokenDepth": 0,
  "master": {
    "encrypted": false
  },
  "balance": {
    "tx": 0,
    "coin": 0,
    "unconfirmed": 0,
    "confirmed": 0
  }
}
  1. bwallet-cli --id=Raj --account=default address
{
  "name": "default",
  "account": 0,
  "branch": 0,
  "index": 1,
  "witness": true,
  "nested": false,
  "publicKey": "03bee7e3c9a839349a7552714e6b053ebdb08b7c325b5a9fc7741d3d76bc295c61",
  "script": null,
  "program": "0014fb21fcc014942c98b5e371635aca16eadad9e549",
  "type": "witness",
  "address": "bcrt1qlvslesq5jskf3d0rw9344jskatddne2fwh2vg8"
}
  1. bwallet-cli send bcrt1qlvslesq5jskf3d0rw9344jskatddne2fwh2vg8 30.55
    (coins from Default to Raj Wallet)
{
  "hash": "80ee633d7f54d543f4bc1e3775421afdb1c5740710f2437dbec0e91f30e31442",
  "height": -1,
  "block": null,
  "time": 0,
  "mtime": 1627191686,
  "date": "1970-01-01T00:00:00Z",
  "mdate": "2021-07-25T05:41:26Z",
  "size": 222,
  "virtualSize": 222,
  "fee": 4480,
  "rate": 20180,
  "confirmations": 0,
  "inputs": [
    {
      "value": 5000000000,
      "address": "mv9a92YbQjkSzx3Rk685Qmnu4wrMbseEn5",
      "path": {
        "name": "default",
        "account": 0,
        "change": false,
        "derivation": "m/0'/0/2"
      }
    }
  ],
  "outputs": [
    {
      "value": 1944995520,
      "address": "morANU98jkQRCgfMPyobXpmHztEEGgBuFY",
      "path": {
        "name": "default",
        "account": 0,
        "change": true,
        "derivation": "m/0'/1/0"
      }
    },
    {
      "value": 3055000000,
      "address": "bcrt1qlvslesq5jskf3d0rw9344jskatddne2fwh2vg8",
      "path": null
    }
  ],
  "tx": "01000000017fa12af76eead4a79a9f9ffbd7b3c5f035fb1ef99ef7a7696ee51b45178b0f04000000006a4730440220068be3abf29d201f401e34a36f7e4fe4a8305ed0d28ee9460bcb37a2bdbc155e0220274aef79895c705571215de5871b5e41fa12ab5b9c9e665c1ab8cd508796978b0121025f94b8d11679f227729684fb367538e900fed753a1c4b6e3a98567d391d6570dffffffff02c046ee73000000001976a9145b62fd7c521fc217302ec2e3e08452a60f21b4bd88acc09917b600000000160014fb21fcc014942c98b5e371635aca16eadad9e54900000000"
}
  1. bwallet-cli --id=Raj balance
{
  "account": -1,
  "tx": 1,
  "coin": 1,
  "unconfirmed": 3055000000,
  "confirmed": 0
}

[JOURNAL] Week 03 (pradyuman)

What I learned :

  • This week, we hopped into the code base, and went through some files containing code about JSON-rpc API and rest API.
  • I looked at test files of this code implementation, and tried breaking the code and curing it afterwords.
  • Also made some changes in the test files to increase code coverage and raised a PR (check it here)
  • And I resolved this issue by making changes to blockchain directory files. (here is the PR that resolves the issue).
  • Last but not least, I did set up my bcoin node in spv mode, and checked commands that do work in this mode.

Questions :
1. What are different types of logger levels available on bcoin ?
-> So, bcoin support six types (technically five). These are - none, error, info, warning, debug, spam.
You can check those here.
Logger.levels = { NONE: 0, ERROR: 1, WARNING: 2, INFO: 3, DEBUG: 4, SPAM: 5 };
To set the logger level manually, you can use --log-level=info while starting your bcoin node.

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.