{"id":19483439,"url":"https://github.com/librity/nc_nomadcoin","last_synced_at":"2025-08-08T17:44:04.618Z","repository":{"id":57629822,"uuid":"401132563","full_name":"librity/nc_nomadcoin","owner":"librity","description":"Nomad Coders - Nomad Coin - A fully-featured blockchain and cryptocurrency in Golang. ","archived":false,"fork":false,"pushed_at":"2022-08-27T20:32:12.000Z","size":3101,"stargazers_count":11,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T05:23:52.753Z","etag":null,"topics":["blockchain","crypto","cryptocurrency","golang","peer-to-peer","proof-of-work","rest-api","wallet","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/librity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-29T20:08:10.000Z","updated_at":"2023-10-30T09:13:19.000Z","dependencies_parsed_at":"2022-09-26T20:11:15.047Z","dependency_job_id":null,"html_url":"https://github.com/librity/nc_nomadcoin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fnc_nomadcoin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fnc_nomadcoin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fnc_nomadcoin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/librity%2Fnc_nomadcoin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/librity","download_url":"https://codeload.github.com/librity/nc_nomadcoin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224007860,"owners_count":17240294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","crypto","cryptocurrency","golang","peer-to-peer","proof-of-work","rest-api","wallet","websocket"],"created_at":"2024-11-10T20:15:05.534Z","updated_at":"2024-11-10T20:15:06.911Z","avatar_url":"https://github.com/librity.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nomad Coders - Nomad Coin\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/nomadcoin.jpeg\" /\u003e\n\u003c/p\u003e\n\n## Table of Contents\n\n- [About](#about)\n- [Getting Started](#getting_started)\n- [Usage](#usage)\n- [Notes](#notes)\n- [Libs](#libs)\n- [Docs](#docs)\n- [Resources](#resources)\n\n## About \u003ca name = \"about\"\u003e\u003c/a\u003e\n\nA fully-featured blockchain and cryptocurrency using the Go programming language.\n\n- [Take the course too!](https://nomadcoders.co/nomadcoin)\n- [Certificate of Completion](https://nomadcoders.co/certs/36d6a10c-265c-47ef-85c3-93c34bede4dc)\n- [Original code](https://github.com/nomadcoders/nomadcoin)\n\n### Features\n\n- [x] HTML Explorer\n- [x] REST API\n- [x] CLI\n- [x] Database Backend\n- [x] Mining\n- [x] Transactions\n- [x] Wallets\n- [x] P2P (Websockets)\n- [x] Unit Testing\n\n### Future\n\n- [x] Finish README Notes\n- [ ] Verify Transactions\n- [ ] Verify Peer Blocks\n- [ ] Fully Tested\n\n## Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\n\n### Go environment\n\nInstall the latest version of `Go` with the `asdf` version manager:\n\n```bash\n$ cd\n$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf\n$ cd ~/.asdf\n$ git checkout \"$(git describe --abbrev=0 --tags)\"\n\n# For Ubuntu or other linux distros\n$ echo '. $HOME/.asdf/asdf.sh' \u003e\u003e ~/.bashrc\n$ echo '. $HOME/.asdf/completions/asdf.bash' \u003e\u003e ~/.bashrc\n$ source ~/.bashrc\n\n$ asdf plugin-add golang https://github.com/kennyp/asdf-golang.git\n$ asdf install golang latest\n$ asdf list\n$ asdf global golang 1.17.1\n$ asdf current\n$ go help\n```\n\n### Installing\n\n```bash\n$ git clone https://github.com/librity/nc_nomadcoin\n$ cd nc_nomadcoin\n$ go get\n$ asdf reshim golang\n$ go run main.go both\n```\n\n### Analyze race conditions\n\nAutomagically analyze race conditions during execution:\n\n```bash\n$ go run -race main.go rest -port=5001\n$ go run -race main.go rest -port=5002\n# or\n$ go build -race \u0026\u0026 nc_nomadcoin rest -port=5001\n$ go build -race \u0026\u0026 nc_nomadcoin rest -port=5002\n```\n\n### Godocs\n\nYou can browse the documentation of all local packages and projects with the\n[Godocs](https://pkg.go.dev/golang.org/x/tools/godoc#section-readme)\npackage:\n\n```bash\n$ go install golang.org/x/tools/godoc\n$ godoc -http=:6060\n```\n\nThis will install the executable\nand start a server listening on http://localhost:6060\n\n### Testing\n\nRun all tests with coverage report:\n\n```bash\n$ go test -v -coverprofile cover.out ./... \u0026\u0026 go tool cover -html=cover.out\n```\n\n## Usage \u003ca name = \"usage\"\u003e\u003c/a\u003e\n\n### CLI\n\n```bash\n$ go run main.go rest -port=PORT                # Start the REST API (recommended)\n$ go run main.go explorer -port=PORT            # Start the HTML Explorer\n$ go run main.go both -ePort=PORT -rPort=PORT   # Start both REST API and HTML Explorer\n```\n\n### HTML Explorer\n\nA simple webserver that lets you browse all the blocks,\ntransactions and wallets.\n\n- http://localhost:4000\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/explorer_demo.png\" /\u003e\n\u003c/p\u003e\n\n### REST API\n\nIt has the same functionality of the HTML Explorer.\nIt also lets you create transactions, mine blocks, and list connected peers.\n\n- http://localhost:5001\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/rest_demo.png\" /\u003e\n\u003c/p\u003e\n\n## Notes \u003ca name = \"notes\"\u003e\u003c/a\u003e\n\n### Golang is awesome\n\nI really enjoy Go, it's probably my favorite language right now.\nIt blows me away how easy it is to write and refactor code\nusing VSCode's Go extension.\nI'm catching over 95% of bugs and errors before compilation.\nI only ever need to worry about:\n\n- Data races\n- Deadlocks\n- Uninitialized `map`s and `*`pointers\n- Functions that receive `interface{}`s params\n\nEvery other mistake gets highlighted the moment I type it.\nGolang only surprises me when it doesn't work.\n\n### Go Routines and Channels\n\n- Reading from a channel without an active go routines will create a panic.\n- Reading from a closed channel will return `nil`\n  or the type equivalent (`0`, `\"\"`, etc.)\n- Closing a closed channel will create a panic.\n- Sending to a closed channel will create a panic.\n- Channels can be Read-only (`\u003c-chan`) or Send-only (`chan\u003c-`).\n- Both sending and receiving are blocking operations\n  for unbuffered channels.\n- Buffered channels have a non-blocking queue of messages\n  (`make(chan int, BUFFER_SIZE)`).\n  Sending and receiving become blocking operations once the queue is full.\n\n### One-way hash functions\n\nDeterministic, easy to compute, hard to invert:\n\n```go\nhashFunction(\"sexy\") =\u003e \"dsdj21321wq0wjdw0jw9djcosaniqij0\"\nhashFunction(\"sexy\") =\u003e \"dsdj21321wq0wjdw0jw9djcosaniqij0\"\nhashFunction(\"sexyy\") =\u003e \"ri3j9rj2302j0ginvin0n00ivwn0inv0u\"\ninverseHashFunction(\"ri3j9rj2302j0ginvin0n00ivwn0inv0u\") =\u003e UNDEFINED\n```\n\nMany examples exists: MD5, SHA-X, Whirlpool, BLAKEX, etc.\nLike Bitcoin, we use SHA-256.\n\n### Blockchain\n\n```go\nnewBlockHash := hashFunction(NOnce + previousBlockHash + timestamp + ...)\n```\n\n`data` could be anything, usually transactions and smart contracts.\nAny alteration to a previous block's data will\navalanche obvious changes to the next blocks' hashes.\nThis makes it so any node in the network can locally verify the integrity\nof the blockchain.\n\nBitcoin has its own\n[Block hashing algorithm](https://en.bitcoin.it/wiki/Block_hashing_algorithm),\nwhere a header of 80 bytes (containing bitcoin version number,\nthe previous block hash, the hash of the block's transactions, the timestamp,\nthe difficulty, and the NOnce) is hashed.\nIn our implementation we transform the entire block instance\nto Golang's default string representation and hash that.\n\n### Mining (Proof of Work)\n\nThe only thing a miner is allowed to change in a block\n(besides adding transactions) is a special number called _NOnce_.\nThe objective of mining is to change the value of the _NOnce_ so that\nthe block has a hash that start with a determined number of zeros.\n\nThe amount of zeroes required to mine a block determines the difficulty\nof the blockchain, and is adjusted by some mechanism\ndetermined by the developer.\nThis consensus mechanisms is called _Proof of Work_,\nand it's the one used by most cryptocurrencies.\nThe other major one is _Proof of stake_.\nYou can play with this mining simulator to get a better idea:\n\n- https://mining-simulator.netlify.app/\n\n### Accounting model\n\nWe use the UTXO (Unspent Transaction Output) accounting model,\nthe same one used in BitCoin and Cardano.\n\nCoins are created by a special type of transaction: the coinbase transaction.\n\n```go\ntype Transaction struct {\n\tId     string\n\tInput  []string\n\tOutput []string\n}\n\ncoinbaseTx = Transaction{\n\tId:     \"0001\"\n\tInput:  []string{\"$10(blockchain)\"},\n\tOutput: []string{\"$10(miner)\"},\n}\n```\n\nTransactions have multiple inputs and outputs.\nInput is the money you have before the transaction.\nOutput is the money everyone has by the end of the transaction.\n\n```go\ntxs := []Transaction{}\ntxs = append(txs, Transaction{\n\tId:     \"0002\"\n\tInput:  []string{\"$10(lior),txId(0001)\"},\n\tOutput: []string{\"$1(drugDealer)\", \"$2(landLord)\", \"$7(lior)\"},\n})\ntxs = append(txs, Transaction{\n\tId:     \"0003\"\n\tInput:  []string{\"$7(lior),txId(0002)\"},\n\tOutput: []string{\"$7(waiFu)\"},\n})\n```\n\nA transaction Input is a reference to a previous transaction Output.\nWe can only use an Input from a previous Output\nthat's not being used by another transaction in the blockchain or the mempool:\nAn Output becomes \"spent\" once it's referenced by an Input.\n\n### Mempool\n\nUnconfirmed transactions wait on the _Mempool_ until they are added\nto the blockchain by miners, becoming confirmed.\n\n### Digital signing\n\n1. Hash any digital object (string, picture, json, etc.)\n2. Generate a Public-Private key pair\n3. Sign the hash with the private key\n4. Verify signature with the public key\n\n```go\nmessageHash := hashFunction(\"i like turtles\")\npublicKey, privateKey := makeNewKeys()\nsignature := sign(messageHash, privateKey)\nchecksOut := verify(messageHash, signature, publicKey)\n```\n\nAll these functions are cryptographic black boxes made with very cool math.\nThere are\n[many different](https://en.wikipedia.org/wiki/Public-key_cryptography#Examples)\nPublic-key cryptography algorithms with which to sign and verify data.\nWe will use Elliptic-curve cryptography\nwith the [NIST P-256](https://neuromancer.sk/std/nist/P-256) curve,\nwhile Bitcoin uses [Secp256k1](https://en.bitcoin.it/wiki/Secp256k1).\n\n### Elliptic Curve Cryptography\n\nWe start with some Elliptic curve `E`, a set of points defined by an equation:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ecdsa_curve.png\" /\u003e\n\u003c/p\u003e\n\nThe overall shape of the curve is determined by the real numbers `a` and `b`.\nThere's a lot of active research that goes into finding curves\nwithout any backdoors and that are hard to brute force.\n\nBecause Elliptic curves are Algebraic groups,\nwe can add two arbitrary curve points `P` and `Q` and get the curve point `R`:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}P\u0026space;\u0026=\u0026space;(x_{p},\u0026space;y_{p})\\\\Q\u0026space;\u0026=\u0026space;(x_{q},\u0026space;y_{q})\\\\\\lambda\u0026space;\u0026={\\frac{y_{q}-y_{p}}{x_{q}-x_{p}}}\\\\x_{r}\u0026=\\lambda^{2}-x_{p}-x_{q}\\\\y_{r}\u0026=\\lambda(x_{p}-x_{r})-y_{p}\\\\R\u0026space;\u0026=\u0026space;(x_{r},\u0026space;y_{r})\\\\\\end{aligned}}}\u0026space;\u0026space;\" title=\"\\bg_white \\inline {\\displaystyle {\\begin{aligned}P \u0026= (x_{p}, y_{p})\\\\Q \u0026= (x_{q}, y_{q})\\\\\\lambda \u0026={\\frac{y_{q}-y_{p}}{x_{q}-x_{p}}}\\\\x_{r}\u0026=\\lambda^{2}-x_{p}-x_{q}\\\\y_{r}\u0026=\\lambda(x_{p}-x_{r})-y_{p}\\\\R \u0026= (x_{r}, y_{r})\\\\\\end{aligned}}} \" /\u003e\n\u003c/p\u003e\n\nIf we make `P = Q`, `R` will equal the mirror(negative) of the interception\nof the the tangent line at `P` with the curve, or `2P`:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ecdsa_tangent.png\" /\u003e\n\u003c/p\u003e\n\nWe can then add some arbitrary point `G` to itself as many `d` times as we want,\nand we will always end up with another point in the curve `d . G`.\nWe've just invented scalar multiplication of an elliptic curve point:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ecdsa_scalar.png\" /\u003e\n\u003c/p\u003e\n\nThe bigger `d` gets, the more points in the curve we end up hitting\nbefore reaching the point `d . G`.\nThis bouncing around the curve looks very pseudo-random,\nmuch like the modular arithmetic of Diffie–Hellman key exchange algorithm.\n\nThe point of this is that it's computationally impractical\nto calculate the value of `d` from `d . G`, given a large-enough `d`.\nIt's also very easy for a computer to generate `d . G` from `d` and `G`.\nThis is very similar to a hash function,\nin that the output is practically non-invertible:\n\n```go\nellipticCurveScalarMultiplication(G, d) =\u003e x, y\ninversEellipticCurveScalarMultiplication(x, y) =\u003e UNDEFINED\n```\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ecdsa_trapdoor.svg\" /\u003e\n\u003c/p\u003e\n\nThese \"trapdoor function\" are the basis of asymmetric cryptography schemes.\nWhen you generate a Private ECDSA key, you are picking a random number `d`\nbetween zero and a very large prime `n`.\nThe computer then traverses the curve by adding `G` to itself `d` times,\ngenerating the Public Key `K` of coordinates `(x,y)`.\n\nWith these two asymmetric keys we can securely:\n\n- [Exchange secrets over an insecure channel](https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman)\n- [Encrypt and Decrypt arbitrary data](https://en.wikipedia.org/wiki/Integrated_Encryption_Scheme)\n- [Sign and Verify arbitrary data](https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm)\n\nThere's some miscellaneous mathematical trickery to make this\nmore secure and/or efficient, but this is fundamentally how it works.\n\nWe often project the curve over a finite field `n`,\nwhich is a very large prime number.\nThis means that we perform the scalar multiplication of the points,\nthen take the modulus `n` of the result.\nThis turn it into a map of discrete values, or affine points:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}R\u0026space;\u0026=\u0026space;(P\u0026space;\u0026plus;\u0026space;Q){\\bmod\u0026space;{\\,}}n\\\\K\u0026space;\u0026=\u0026space;(d\u0026space;\\cdot\u0026space;G){\\bmod\u0026space;{\\,}}n\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}R \u0026= (P + Q){\\bmod {\\,}}n\\\\K \u0026= (d \\cdot G){\\bmod {\\,}}n\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ecdsa_field.png\" /\u003e\n\u003c/p\u003e\n\n### Elliptic Curve Digital Signature Algorithm (ECDSA)\n\nAlice wants to send a message `M` to Bob.\nThey both agree on an Elliptic curve `E`, a generator point `G` on the curve,\nand a very large prime number `n`.\n\n#### Generate Keys\n\nAlice generates the Private key `a`\nby picking a very large number between 1 and `n-1`.\nShe then generates the Public key `P` and sends it to Bob.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}P\u0026space;\u0026=\u0026space;a\u0026space;\\cdot\u0026space;G\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}P \u0026= a \\cdot G\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\n#### Sign\n\nAlice calculates the message hash `e` and transforms it into a number `z`\nby taking the leftmost bits of `e`.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}e\u0026space;\u0026=\u0026space;{\\textrm\u0026space;{HASH}}(M)\\\\z\u0026space;\u0026=\u0026space;{\\textrm\u0026space;{HASHTOINT}}(e)\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}e \u0026= {\\textrm {HASH}}(M)\\\\z \u0026= {\\textrm {HASHTOINT}}(e)\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\nShe then picks another random number `k` between 1 and `n-1`\n(called the NOnce because it's only used once),\nand multiplies it with `G` modulus `n` to get the coordinate `r`,\nthe first part of the signature.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}(k\u0026space;\\cdot\u0026space;G){\\bmod\u0026space;{\\,}}n\u0026space;\u0026=\u0026space;(r,\u0026space;\\_)\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}(k \\cdot G){\\bmod {\\,}}n \u0026= (r, \\_)\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\nThe second part of the signature `s` is a combination of `k`, `r`, `z` and\nthe private key `a`:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}s\u0026space;\u0026=\u0026space;k^{-1}\u0026space;(z\u0026plus;r*a)\\,{\\bmod\u0026space;{\\,}}n\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}s \u0026= k^{-1} (z+r*a)\\,{\\bmod {\\,}}n\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\nAlice then sends Bob the message `M`, the hash `e` and the signature `(r, s)`.\n\n#### Verify\n\nBob does some basic verifications of the public key `P`,\nlike checking that it's on the curve and it's not the Identity Element `O`.\nHe then checks that `r` and `s` are integers between 1 and `n-1`,\nand that `e` is the hash of `M`.\n\nHe then calculates `z` from `e` the same way Alice did,\nand uses it to calculate `u1` and `u2`:\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}u_{1}\u0026space;\u0026=\u0026space;zs^{-1}\\,{\\bmod\u0026space;{\\,}}n\\\\u_{2}\u0026space;\u0026=\u0026space;rs^{-1}\\,{\\bmod\u0026space;{\\,}}n\\\\\\end{aligned}}}\" title=\"\\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}u_{1} \u0026= zs^{-1}\\,{\\bmod {\\,}}n\\\\u_{2} \u0026= rs^{-1}\\,{\\bmod {\\,}}n\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\nAnd with the public key `P` calculates\nthe coordinate `x1` of the signature point:\nif `x1` is congruent to `r` modulo `n`\n(which means the same as `x1` and `r` differ by a multiple of `n`)\nthen the signature is valid.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/png.image?\\dpi{150}\u0026space;\\bg_white\u0026space;\\bg_white\u0026space;\\inline\u0026space;\\bg_white\u0026space;\\inline\u0026space;{\\displaystyle\u0026space;{\\begin{aligned}(x_{1},y_{1})\u0026space;\u0026=\u0026space;u_{1}\\cdot\u0026space;G\u0026space;\u0026plus;\u0026space;u_{2}\u0026space;\\cdot\u0026space;Q_{A}\\\\x_{1}\u0026space;\u0026\\equiv\u0026space;r\u0026space;{\\pmod\u0026space;{n}}\\\\x_{1}\u0026space;\\,{\\bmod\u0026space;{\\,}}n\u0026space;\u0026=\u0026space;r\u0026space;\\,{\\bmod\u0026space;{\\,}}n\\\\\\end{aligned}}}\" title=\"\\bg_white \\bg_white \\inline \\bg_white \\inline {\\displaystyle {\\begin{aligned}(x_{1},y_{1}) \u0026= u_{1}\\cdot G + u_{2} \\cdot Q_{A}\\\\x_{1} \u0026\\equiv r {\\pmod {n}}\\\\x_{1} \\,{\\bmod {\\,}}n \u0026= r \\,{\\bmod {\\,}}n\\\\\\end{aligned}}}\" /\u003e\n\u003c/p\u003e\n\nIf we didn't project the curve `E` on a field `n`\n(if we didn't modulate the operations),\nthe private key `a` would be recoverable from the signature `(r, s)`,\nthe hash `e` and the value of `k`.\nThis is also why we pick a new random value of `k` for every signature.\n\nHow we securely generate random values of `a` and `k` is an important problem,\nand one that's exploitable by back doors like the one in\n[Dual_EC_DRBG](https://en.wikipedia.org/wiki/Dual_EC_DRBG),\na random number generator the NSA bugged.\n\nMany devices would still be using that garbage if not for\n[Edward Snowden](https://en.wikipedia.org/wiki/Edward_Snowden).\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/ed_snow.webp\" width=\"350\" /\u003e\n\u003c/p\u003e\n\n### Data races\n\nData races can occur when:\n\n- two or more threads (go routines in this case) in a single process\n  access the same memory location concurrently, and\n- at least one of the accesses is for writing, and\n- the threads are not using any exclusive locks\n  to control their accesses to that memory.\n\nWhen these three conditions hold, the order of accesses is non-deterministic,\nand the computation may give different results from run to run\ndepending on that order.\n[Source](https://docs.oracle.com/cd/E19205-01/820-0619/geojs/index.html)\n\nIn Golang we fix data races with blocking `chan`nels,\n`sync.WaitGroup` or `sync.Mutex`.\nThey all do pretty much the same thing:\nlock the variable during read and write\nto guarantee that only one routine access it at a time.\n\n### Peer 2 Peer\n\nThis the most important part of understanding blockchain.\nBitcoin is fundamentally a peer 2 peer protocol that allows\na decentralized network to agree on the data that will be added\nto a write-only database.\n\nWe use [Web Sockets](https://github.com/gorilla/websocket)\nto connect the peers and broadcast new transactions and mined blocks.\n\nWhen node Jr. connects to node Sr., node Jr. send the last block it has.\nNode Sr. then checks whether Jr. is ahead, behind or on the same block as Jr.\nWhichever one's ahead end up sending a copy of their blockchain to the other.\nThen they share a list of the other nodes they're connected to,\nand initiate this handshake again.\n\nWhen someone creates a transaction in a node it broadcasts\nto all the other nodes, creating a \"Global Mempool\".\nEach node then receives the transaction and verifies the transaction's\nsignature: if it's valid the transaction is added to the Mempool\nand relayed to the other nodes.\n\nThe nodes then try to mine the next block, and the one that get's lucky\nbroadcasts the block to all other.\nThe other nodes verify the new block's nonce and transactions:\nif it's valid it is added to the local blockchain\nand relayed to the other nodes.\n\n### Cryptocurrency Investment Advice\n\n```diff\n- THIS IS NOT INVESTMENT ADVICE.\n- I'M NOT RESPONSIBLE FOR YOUR BAD DECISIONS.\n```\n\nThis what I've gathered from all my research, merely my opinion:\n\n- Only bet what you can afford to loose.\n- Don't bet on anything you don't understand.\n- Don't bet on anything you haven't read the code.\n- Don't bet on new currencies if you don't understand\n  the problems they're trying to solve\n  and what they're doing differently.\n- A blockchain is only as good as its dev community.\n- Bet on engineering, not marketability.\n- \"I'm an adult and everything I do is my responsibility.\"\n- Don't be this guy:\n\n[![Watch the video](https://img.youtube.com/vi/61i2iDz7u04/maxresdefault.jpg)](https://youtu.be/61i2iDz7u04)\n\n_To his credit, it's pretty unreasonable to expect someone\nwithout any technical knowledge\nto successfully speculate on shitcoins._\n\n## Libs \u003ca name = \"libs\"\u003e\u003c/a\u003e\n\n- https://github.com/gorilla/mux\n- https://github.com/gorilla/websocket\n- https://github.com/etcd-io/bbolt\n- https://golang.org/x/tools/godoc\n\n## Docs \u003ca name = \"docs\"\u003e\u003c/a\u003e\n\n- https://pkg.go.dev/fmt#Printf\n- https://pkg.go.dev/sync#Once\n- https://pkg.go.dev/net/http#HandleFunc\n- https://pkg.go.dev/log#Fatal\n- https://pkg.go.dev/text/template#hdr-Actions\n- https://pkg.go.dev/html/template#ParseFiles\n- https://pkg.go.dev/path/filepath#Match\n- https://pkg.go.dev/encoding/json#Marshal\n- https://pkg.go.dev/strconv#Atoi\n- https://pkg.go.dev/flag#NewFlagSet\n- https://pkg.go.dev/encoding/gob\n- https://pkg.go.dev/crypto/elliptic#P256\n- https://pkg.go.dev/encoding/hex#DecodeString\n- https://pkg.go.dev/math/big#Int\n- https://pkg.go.dev/crypto/x509#MarshalECPrivateKey\n- https://pkg.go.dev/os#WriteFile\n- https://pkg.go.dev/builtin#close\n- https://pkg.go.dev/testing\n- https://pkg.go.dev/std\n- https://pkg.go.dev/golang.org/x/tools/godoc\n- https://golang.org/doc/\n- https://golang.org/ref/spec#Variables\n- https://golang.org/ref/spec#Pointer_types\n- https://tour.golang.org/methods/17\n- https://go.dev/blog/maps\n\n## Resources \u003ca name = \"resources\"\u003e\u003c/a\u003e\n\n- https://andybrewer.github.io/mvp/?ref=producthunt\n- https://en.wikipedia.org/wiki/Marshalling_(computer_science)\n- https://swagger.io/specification/\n- https://en.wikipedia.org/wiki/Adapter_pattern\n- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status\n- https://marketplace.visualstudio.com/items?itemName=humao.rest-client\n- https://stackoverflow.com/questions/4279611/how-to-embed-a-video-into-github-readme-md\n\n### Key-value DB\n\n- https://en.wikipedia.org/wiki/Key%E2%80%93value_database\n- https://github.com/google/leveldb\n- https://github.com/LMDB/lmdb\n- https://github.com/evnix/boltdbweb\n- https://github.com/br0xen/boltbrowser\n\n### Blockchain\n\n- https://www.youtube.com/playlist?list=PL7jH19IHhOLOJfXeVqjtiawzNQLxOgTdq\n- https://github.com/LarryRuane/minesim\n- https://mining-simulator.netlify.app/\n- https://www.blockchain.com/explorer\n- https://github.com/tensor-programming/golang-blockchain/tree/part_10\n- https://www.youtube.com/playlist?list=PLmL13yqb6OxdEgSoua2WuqHKBuIqvll0x\n\n### Go\n\n- https://www.digitalocean.com/community/tutorials/understanding-data-types-in-go\n- https://stackoverflow.com/questions/25161774/what-are-conventions-for-filenames-in-go\n- https://medium.com/golangspec/labels-in-go-4ffd81932339\n- https://stackoverflow.com/questions/33832762/how-do-i-make-a-go-program-wait-until-there-is-user-input\n- https://stackoverflow.com/questions/37242009/function-returns-lock-by-value\n\n### Go strings\n\n- https://golang.org/src/strconv/atoi.go?h=Atoi\n- https://golangdocs.com/generate-random-string-in-golang\n- https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go\n- https://stackoverflow.com/questions/59402587/how-to-get-enum-variable-name-by-value-in-golang\n- https://embeddedartistry.com/blog/2017/07/05/printf-a-limited-number-of-characters-from-a-string/\n\n### Go gobs\n\n- https://gist.github.com/miguelmota/2a0c0e96c22bccc8740819d5d64ff8d0\n- https://stackoverflow.com/questions/14121422/de-and-encode-interface-with-gob\n- https://go.dev/blog/gob\n- https://gist.github.com/evalphobia/a2ba2636acbc112f68dcd89e8b81d349\n- https://developpaper.com/golang-gob-code-detailed-explanation-of-gob-package/\n\n### Go HTTP\n\n- https://hackthedeveloper.com/golang-server-static-files/\n- https://golangdocs.com/golang-mux-router\n- https://stackoverflow.com/questions/40478027/what-is-an-http-request-multiplexer\n\n### Go maps\n\n- https://golangdocs.com/maps-in-golang\n- https://stackoverflow.com/questions/27267900/runtime-error-assignment-to-entry-in-nil-map\n- https://stackoverflow.com/questions/14928826/passing-pointers-to-maps-in-golang\n- https://stackoverflow.com/questions/2809543/pointer-to-a-map\n\n### Go import cycles\n\n- https://jogendra.dev/import-cycles-in-golang-and-how-to-deal-with-them\n- https://stackoverflow.com/questions/38412950/golang-import-cycle-not-allowed\n\n### Go arrays \u0026 slices\n\n- https://github.com/golang/go/wiki/SliceTricks#reversing\n- https://stackoverflow.com/questions/24757814/golang-convert-byte-array-to-big-int\n- https://stackoverflow.com/questions/37334119/how-to-delete-an-element-from-a-slice-in-golang\n- https://stackoverflow.com/questions/19239449/how-do-i-reverse-an-array-in-go\n- https://stackoverflow.com/questions/54858529/golang-reverse-a-arbitrary-slice\n\n### Go packages\n\n- https://www.gorillatoolkit.org/\n- https://dbdb.io/db/boltdb\n- https://github.com/boltdb/bolt\n- https://cobra.dev/\n- https://gobuffalo.io/en/\n\n### Go templates\n\n- https://gowebexamples.com/templates/\n- https://blog.gopheracademy.com/advent-2017/using-go-templates/\n- https://stackoverflow.com/questions/29762118/range-over-array-index-in-templates\n- https://stackoverflow.com/questions/25689829/arithmetic-in-go-templates\n- https://stackoverflow.com/questions/17843311/template-and-custom-function-panic-function-not-defined\n- https://stackoverflow.com/questions/38686583/golang-parse-all-templates-in-directory-and-subdirectories\n\n### Go data races\n\n- https://docs.oracle.com/cd/E19205-01/820-0619/geojs/index.html\n- https://en.wikipedia.org/wiki/Race_condition\n- https://www.sohamkamani.com/golang/data-races/\n- https://yourbasic.org/golang/data-races-explained/\n- https://programming.guide/go/data-races-explained.html\n- https://programming.guide/go/detect-data-races.html\n\n### Go deadlocks\n\n- https://yourbasic.org/golang/detect-deadlock/\n- https://stackoverflow.com/questions/56051910/using-mutex-lock-still-deadlock\n- https://awesomeopensource.com/project/sasha-s/go-deadlock\n- https://github.com/sasha-s/go-deadlock\n- https://stackoverflow.com/questions/68144512/identifying-golang-deadlock-5-philosophers-problem\n- https://wavded.com/post/golang-deadlockish/\n- https://programming.guide/go/detect-deadlock.html\n\n### Go big.Int\n\n- https://medium.com/orbs-network/big-integers-in-go-14534d0e490d\n- https://blog.devgenius.io/big-int-in-go-handling-large-numbers-is-easy-157cb272dd4f\n- https://stackoverflow.com/questions/44696881/big-int-not-equal-to-one-received-after-big-setbytesbigint-bytes\n\n### Go testing\n\n- https://golangdocs.com/golang-unit-testing\n- https://stackoverflow.com/questions/32425558/how-to-verify-if-a-specific-function-is-called\n- https://www.youtube.com/watch?v=ndmB0bj7eyw\n- https://stackoverflow.com/questions/31595791/how-to-test-panics\n- https://stackoverflow.com/questions/24375966/does-go-test-run-unit-tests-concurrently\n- https://pkg.go.dev/github.com/stretchr/testify/assert?utm_source=godoc\n- https://stackoverflow.com/questions/31201858/how-to-run-golang-tests-sequentially\n- https://github.com/stretchr/testify\n\n### Go crypto\n\n- https://golang.org/src/crypto/\n- https://golangdocs.com/the-crypto-rand-package-in-golang\n- https://www.thepolyglotdeveloper.com/2018/02/encrypt-decrypt-data-golang-application-crypto-packages/\n- https://kashifsoofi.github.io/cryptography/aes-in-go-using-crypto-package/\n- https://golangdocs.com/rsa-encryption-decryption-in-golang\n- https://yourbasic.org/golang/crypto-rand-int/\n- https://golang.hotexamples.com/examples/crypto.ecdsa/-/Verify/golang-verify-function-examples.html\n- https://teemukanstren.com/2018/04/16/trying-to-learn-ecdsa-and-golang/\n- https://golang.hotexamples.com/examples/crypto.ecdsa/-/Sign/golang-sign-function-examples.html\n- https://www.youtube.com/watch?v=jgTqR8PuWuU\n\n### Cryptography\n\n- https://en.wikipedia.org/wiki/Computational_complexity_theory#Intractability\n- https://en.wikipedia.org/wiki/Trapdoor_function\n- https://en.wikipedia.org/wiki/Finite_field\n- https://en.wikipedia.org/wiki/Modular_arithmetic\n- https://en.wikipedia.org/wiki/Integer_factorization\n\n### Hash Functions\n\n- https://en.wikipedia.org/wiki/Hash_function\n- https://en.wikipedia.org/wiki/Cryptographic_hash_function\n- https://en.wikipedia.org/wiki/SHA-2\n- https://en.wikipedia.org/wiki/One-way_function\n\n### Encryption\n\n- https://en.wikipedia.org/wiki/End-to-end_encryption\n- https://en.wikipedia.org/wiki/Encryption\n- https://en.wikipedia.org/wiki/RSA_(cryptosystem)\n- https://en.wikipedia.org/wiki/Advanced_Encryption_Standard\n- https://en.wikipedia.org/wiki/Galois/Counter_Mode\n- https://en.wikipedia.org/wiki/Block_cipher\n- https://www.youtube.com/watch?v=O4xNJsjtN6E\n\n### Public-key cryptography\n\n- https://en.wikipedia.org/wiki/Public-key_cryptography\n- https://www.youngwonks.com/blog/Public-Key-and-Private-Key-Encryption-Explained\n- https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange\n- https://www.youtube.com/watch?v=NmM9HA2MQGI\n- https://www.youtube.com/watch?v=Yjrfm_oRO0w\n\n### Digital signatures\n\n- https://en.wikipedia.org/wiki/Digital_signature\n- https://en.wikipedia.org/wiki/Digital_Signature_Algorithm\n- https://www.tutorialspoint.com/cryptography/cryptography_digital_signatures.htm\n- https://en.wikipedia.org/wiki/Cryptocurrency_wallet\n\n### Elliptic curve cryptography\n\n- https://en.wikipedia.org/wiki/Elliptic-curve_cryptography\n- https://en.wikipedia.org/wiki/Elliptic-curve_Diffie%E2%80%93Hellman\n- https://en.wikipedia.org/wiki/Elliptic_curve\n- https://en.wikipedia.org/wiki/Characteristic_(algebra)\n- https://en.wikipedia.org/wiki/Field_(mathematics)\n- https://en.wikipedia.org/wiki/Discrete_logarithm\n- https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication\n- https://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity\n- https://www.johannes-bauer.com/compsci/ecc\n- https://github.com/Amogh-Bharadwaj/Elliptic-Curve-Cryptography\n\n### Elliptic Curve Digital Signature Algorithm - ECDSA\n\n- https://www.desmos.com/calculator/kkj2efqk5x\n- https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm\n- https://asecuritysite.com/encryption/ecd2\n- https://safecurves.cr.yp.to/\n- https://www.reddit.com/r/crypto/comments/7rithm/what_does_p256_stand_for/\n- https://neuromancer.sk/std/nist/P-256\n- https://askinglot.com/what-is-nist-p256\n- https://askinglot.com/open-detail/108766\n- https://csrc.nist.gov/publications/detail/fips/186/3/archive/2009-06-25\n- https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages\n- https://www.hypr.com/elliptic-curve-digital-signature-algorithm/\n- https://www.maximintegrated.com/en/design/technical-documents/tutorials/5/5767.html\n- https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html\n- https://wizardforcel.gitbooks.io/practical-cryptography-for-developers-book/content/digital-signatures/ecdsa-sign-verify-messages.html\n\n### ECDSA Videos\n\n- https://www.youtube.com/watch?v=NF1pwjL9-DE\n- https://www.youtube.com/watch?v=nybVFJVXbww\n- https://www.youtube.com/watch?v=QzUThXGRFBU\n- https://www.youtube.com/watch?v=dCvB-mhkT0w\n- https://www.youtube.com/watch?v=gAtBM06xwaw\n- https://www.youtube.com/watch?v=-UcCMjQab4w\n- https://www.youtube.com/watch?v=qxmmv2iBRXs\n- https://www.youtube.com/watch?v=muIv8I6v1aE\n\n### Bitcoin\n\n- https://www.coindesk.com/markets/2017/02/19/bitcoin-hash-functions-explained/\n- https://en.bitcoin.it/wiki/Block_hashing_algorithm\n- https://en.bitcoin.it/wiki/Hashcash\n- https://bitcoinmagazine.com/technical/overview-bitcoins-cryptography\n- http://blog.ezyang.com/2011/06/the-cryptography-of-bitcoin/\n- https://en.bitcoin.it/wiki/Secp256k1\n- https://www.youtube.com/channel/UCW7L2NGmFUEsZoPReKW_4iQ/videos\n- https://www.youtube.com/playlist?list=PLR7Zbyu8bxEUDkPc8SG34TiDARfCAohoL\n- https://www.youtube.com/watch?v=duAcEElZpNk\n\n### Accounting models\n\n- https://academy.horizen.io/technology/advanced/the-utxo-model/\n- https://phemex.com/academy/what-are-utxo-unspent-transaction-output\n- https://komodoplatform.com/en/academy/whats-utxo/\n- https://iohk.io/en/blog/posts/2021/03/12/cardanos-extended-utxo-accounting-model-part-2/\n\n### Favicons\n\n- https://favicon.io/emoji-favicons/coin/\n- https://www.freefavicon.com/\n- https://icons8.com/icons/set/coin--animated\n- https://www.ionos.com/tools/favicon-generator\n- https://www.favicon-generator.org/search/---/Coin\n- https://www.favicon.cc/?action=icon\u0026file_id=138923\n- https://www.digitalocean.com/community/tutorials/how-to-add-a-favicon-to-your-website-with-html\n\n### Javascript\n\n- https://www.javatpoint.com/how-to-add-javascript-to-html\n- https://stackoverflow.com/questions/847185/convert-a-unix-timestamp-to-time-in-javascript\n- https://javascript.info/websocket\n- https://developer.mozilla.org/en-US/docs/Web/API/WebSocket\n\n### ASDF version manager\n\n- https://asdf-vm.com/guide/getting-started.html\n- https://awesomeopensource.com/project/asdf-vm/asdf-plugins\n- https://github.com/kennyp/asdf-golang\n- https://gist.github.com/rubencaro/5ce32fb30bbfa70e7db6be14cf42a35c\n\n### Design patterns\n\n- http://blog.ralch.com/articles/design-patterns/golang-composite/\n- https://dev.to/stevensunflash/using-domain-driven-design-ddd-in-golang-3ee5\n- https://www.geeksforgeeks.org/composite-design-pattern/\n- https://www.oreilly.com/library/view/software-architecture-patterns/9781491971437/ch01.html\n- https://www.codeproject.com/articles/654670/layered-application-design-pattern\n\n### Golang's `http.server` architecture\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\".github/golang_multiplexer.png\" /\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fnc_nomadcoin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibrity%2Fnc_nomadcoin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibrity%2Fnc_nomadcoin/lists"}