{"id":19596393,"url":"https://github.com/henrixapp/proof-of-work-by-stake","last_synced_at":"2025-04-27T15:35:08.238Z","repository":{"id":47959645,"uuid":"495434110","full_name":"henrixapp/proof-of-work-by-stake","owner":"henrixapp","description":"A blockchain approach to time tracking (seminar project)","archived":false,"fork":false,"pushed_at":"2022-08-21T10:46:53.000Z","size":6216,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-02-27T13:32:53.052Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henrixapp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-23T13:58:34.000Z","updated_at":"2022-05-23T23:55:04.000Z","dependencies_parsed_at":"2022-09-22T00:03:28.381Z","dependency_job_id":null,"html_url":"https://github.com/henrixapp/proof-of-work-by-stake","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrixapp%2Fproof-of-work-by-stake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrixapp%2Fproof-of-work-by-stake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrixapp%2Fproof-of-work-by-stake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrixapp%2Fproof-of-work-by-stake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henrixapp","download_url":"https://codeload.github.com/henrixapp/proof-of-work-by-stake/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224076224,"owners_count":17251673,"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":[],"created_at":"2024-11-11T08:53:28.618Z","updated_at":"2024-11-11T08:53:29.979Z","avatar_url":"https://github.com/henrixapp.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# proof-of-work-by-stake\n\n[ReadMe of staking_lib](staking_lib/README.md)\n\n[ReadMe of UI/iOS-App](flutter_app/README.md)\n\n## Tutorial\n\n### Step 0: Get git,flutter and dart\n\nThis heavily depends on your platform, please look at [the official Installation guide for Flutter](https://docs.flutter.dev/get-started/install).\n\nAfterwards running a command like `dart --version` in terminal or cmd should print \nsomething sane like \n\n```bash\n$ dart --version\nDart SDK version: 2.17.1 (stable) (Tue May 17 17:58:21 2022 +0000) on \"macos_x64\"\n```\n\nIn order to download the source code, install git on your platform. (although this is not mandatory)\n\n### Step 1: Get the source code\n\nDownload the source code by either command or the zip option under the green code button.\nIf you download as a zip you have to unpack it somewhere meaningful.\n```bash\n$ cd some/good/place/for/the/project\n$ git clone https://github.com/henrixapp/proof-of-work-by-stake.git\n```\n\n### Step 1: Install dependencies of the project\n\nChange into the directory `staking_lib` of the project:\n```bash\n$ cd proof-of-work-by-stake/staking_lib\n```\n\nNow get the packages that are needed for our project with `dart pub get`:\n\nThe output should look like this:\n```bash\n$ dart pub get\n...\nGot dependencies!\n```\nAfterwards you should be ready to run the programs.\n\n### Step 2: Generate a public/private key pair as Account\n\nOur signing in the blockchain is based on Ed25519 Elliptic Curve.\nIn order to sign transactions later on we need to generate at least two key-pairs.\n\nWhile still being in the `staking_lib` folder execute the first program\n`create_account.dart`. Invoke it with as many usernames as you like. It will \ngenerate for each a valid private/public key pair and store it in the folder as .json.\nFurthermore a png is generated for each public key. For better usage with the app.\n\n**Example:** Lets create an account `henrixapp`and `project-a`\n\n```bash\n$ dart create_account.dart henrixapp project-a\n```\n\nThe files will be automatically generated and look like this:\n```json\n{\"username\":\"henrixapp\",\"pubKeyHEX\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"privateKeyHEX\":\"6a539c310badcfae4e4f5c8d6126a0d2dfc5dcff6b447f963d000cae47492e95\",\"type\":\"user\"}\n```\n\nIn a reallife scenario, you would never share the privateKey(HEX) field.\n\nthis is why we generate a QR-code with the public key to share.\nAnd this `henrixapp-pub.png` looks like this:\n\n![QR-Code](figures/henrixapp-pub.png)\n\nYou can scan it with your phone and it should read `5403...`\n\n**Background** The username is not stored in the chain, but simply for us to \nidentify a key pair.\n\n### Step 3: Generate a chain.\n\nNow it is time to generate our first chain. To initiate a chain call the program\n`client.dart` with a name of a chain, that does not exist (yet).\n\nFor example \n`dart client.dart henrixapp coolchain` generates the chain `coolchain` and stores\nit in `coolchain.json`. As you will see you will automatically get an initial endowment\nof `576000=4 * 5 * 8 * 3600` seconds (or a 40 hour work month).\n\n```bash\n$ dart client.dart henrixapp coolchain \nValidate:\ntrue\nCommand(quit,send,balance):\n```\nNow enter `balance` and afterwards `quit`:\n\n```\nbalance\nYour balance is 576000\nCommand(quit,send,balance):\nquit\n```\n\n**What is happening in the background?** Now a new file called `coolchain.json`\nis generated. It looks like this:\n\n```json\n{\"chain\":[{\"index\":0,\"previousHash\":\"\",\"timestamp\":\"2022-07-28T12:12:11.758438\",\"transactions\":[{\"id\":\"221917031cddbe3425f65017a6e9e2c41f195c343bf22c3a504ac4937f242229\",\"txIns\":[],\"txOuts\":[{\"address\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"amount\":576000}]}],\"announcements\":[],\"difficulty\":10,\"minterAdress\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"minterBalance\":100,\"nonce\":0}]}\n```\n\nIt contains only a socalled *genesis block* with one transaction.\n\nNow is a good time to understand the blockchains approach to transactions.\n\nA normal transaction consists out of two parts `txIns`and `txOuts`. In a normal \ntransaction the input amount must equal the output amount. The `txIns`\nare references to former `txOuts`and  `txOuts`are so to say unspent on the chain until\nthey get referenced in a `txIn`. To get your balance, you just have to sum up all unspent txOuts.\n\nThe *genesis* block of our chain is special because it only contains one `txOut`\nto our previously generated address (`540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b`).\nFurthermore, it does not contain reference to a previous hash as it is the starting block.\n\n\n### Step 4: Send time to a different address\n\nNow we can send some seconds to our second generated address. Simply start the client\nagain and this time send to a different address (in this example `1b661b...`):\n\n```bash\n$ dart client.dart henrixapp coolchain\nValidate:\ntrue\nCommand(quit,send,balance):\nsend\nPlease specify the address:\n1b661b579dfc6a5cd48037099c77eb6bfdf881d3b8572f43b97694fa9d6b2159\nPlease enter the amount:\n1000\nIters: 1\nCommand(quit,send,balance):\nquit\n```\n\nNow have a look at the chain in `coolchain.json`:\n\n```json\n{\"chain\":[{\"index\":0,\"previousHash\":\"\",\"timestamp\":\"2022-07-28T12:12:11.758438\",\"transactions\":[{\"id\":\"221917031cddbe3425f65017a6e9e2c41f195c343bf22c3a504ac4937f242229\",\"txIns\":[],\"txOuts\":[{\"address\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"amount\":576000}]}],\"announcements\":[],\"difficulty\":10,\"minterAdress\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"minterBalance\":100,\"nonce\":0},{\"index\":1,\"previousHash\":\"30b4ac071144305c2f73bc0aeaf1bb36cb39aec0d9509b82f3d1dcb3066cb913\",\"timestamp\":\"2022-07-28T12:26:04.989606\",\"transactions\":[{\"id\":\"35b69a1bdf3a0a35aa90faffe89393a861c4aca77f58da2f3bf783d07ad5047c\",\"txIns\":[{\"txOutId\":\"221917031cddbe3425f65017a6e9e2c41f195c343bf22c3a504ac4937f242229\",\"txOutIndex\":0,\"signature\":\"10aec656a0a31d6c0e722156fa077541d91b6dbae27afd60aa88b456260a5a3d977c1571e5a24a8a3d5d73df52fece901265be0afd8116c3900b503a8fbb9e04\"}],\"txOuts\":[{\"address\":\"1b661b579dfc6a5cd48037099c77eb6bfdf881d3b8572f43b97694fa9d6b2159\",\"amount\":1000},{\"address\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"amount\":575000}]}],\"announcements\":[],\"difficulty\":10000,\"minterAdress\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"minterBalance\":576000,\"nonce\":5593}]}\n```\n\nThere is still the genesis block and now there is a second block. Let's look at it in detail:\n\n```json\n{\"index\":1,\"previousHash\":\"30b4ac071144305c2f73bc0aeaf1bb36cb39aec0d9509b82f3d1dcb3066cb913\",\"timestamp\":\"2022-07-28T12:26:04.989606\",\"transactions\":[{\"id\":\"35b69a1bdf3a0a35aa90faffe89393a861c4aca77f58da2f3bf783d07ad5047c\",\"txIns\":[{\"txOutId\":\"221917031cddbe3425f65017a6e9e2c41f195c343bf22c3a504ac4937f242229\",\"txOutIndex\":0,\"signature\":\"10aec656a0a31d6c0e722156fa077541d91b6dbae27afd60aa88b456260a5a3d977c1571e5a24a8a3d5d73df52fece901265be0afd8116c3900b503a8fbb9e04\"}],\"txOuts\":[{\"address\":\"1b661b579dfc6a5cd48037099c77eb6bfdf881d3b8572f43b97694fa9d6b2159\",\"amount\":1000},{\"address\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"amount\":575000}]}],\"announcements\":[],\"difficulty\":10000,\"minterAdress\":\"540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b\",\"minterBalance\":576000,\"nonce\":5593}]\n```\n\nFirst of all it contains a previous hash and a timestamp. It also contains one transaction.\nIn that the `txIn` is referencing  the previous transaction (starting with `221917`) from the genesis block\nand its 0 (so first) txOut.\nThis `txIn`has to be signed so that we know that the owner of the address is actually fine \nwith spending their `txOut`. the `txOut`consists out of two entries. One for the amount we\nare sending to the address we entered and one containing the rest of the unspent `txOut`\nwe were using.\n\n| Illustration of the txOut/txIn mechanism |\n| ---------------------------------------- |\n| ![](figures/transaction.png) |\n\nFurthermore, it contains information about the minter  and the difficulty we assigned for finding the block and the nonce we used for finding the block more quickly.\n The difficulty is used to satisfy the staking condition:\n\n```\n SHA256 \u003c 2^{256}*(balance/{difficulty)\n```\n\nNow you can check with the second keyfile, whether the amount arrived in their wallet:\n\n```bash\ndart client.dart project-a coolchain\nValidate:\ntrue\nCommand(quit,send,balance):\nbalance\nYour balance is 1000\nCommand(quit,send,balance):\nquit\n```\n\n### Step 5: Get the app working\n\nTo run the app, open a second terminal and change into flutter_app.\nMake sure, that your phone is connected and stays the whole time.\n\n```\n$ flutter run\n```\n\nNow the app should start on your phone. It will ask you for camera permissions,\nas it is easier to scan than to type in long public keys.\nThe app automatically generates a keypair.\nYou can extract it by coping it to the clipboard.\n\nSend this publickey to your pc and try to send some time to it (like in step 4).\n\nIn order to transmit the `coolchain` to your phone, your computer and phone have \nto be on the same network. Now start in the first terminal the `node.dart`script:\n\nIt is important that you give 65000 as second argument to the program.\n`65000`is the  UDP port used to broadcast changes to the network \u0026 phone.\n```bash\n$ dart node.dart henrixapp 65000 coolchain\ntrue\n65000\n65000\nValidate:\n```\n\nAfterwards, you should press the request button in the app and the amount should \nupdate to that what you have transferred first.\nIn the flutter run log should be a message like \n\n```\nUpdated chain. From 540300978d114a3cdffcd1d22ad074cccdf779f5e82807aaedbbc43e6fa1981b.\n```\n\n|  After request update   |\n| ------------------------ |\n| ![Announcement in App](figures/received2600.PNG) |\n\n### Step 6 Using the app\n\nUntil now, we did not use the annoucement feature of our blockchain.\nIf you scan a qr code, like the one earlier, you will automatically announce in the chain,\nthat you are working on the project under that adress and will later transfer time \nto it.\n\n|  Announcement directly   | ... after one minute    |\n| ------------------------ | ----------------------- |\n| ![Announcement in App](figures/qr_scanned.PNG) | ![Announcement in App](figures/qr_1minute.PNG) |\n\nGo ahead and scan the qr code of henrixapp-pub.png for example. Wait for a minute and then \"Checkin time\" to ammend the chain.\n\n\n|  Updated time after transaction to `project-a`   |\n| ------------------------ |\n| ![Updated time after transaction](figures/updated_time_after_transaction.PNG)|\n\nThe node should automatically store these transaction in `coolchain.json`\n\n**Note** you can try to send time to any qr code, but the balance will be lost,\nif the qr code is no valid public key or you do not have the valid private key.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrixapp%2Fproof-of-work-by-stake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrixapp%2Fproof-of-work-by-stake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrixapp%2Fproof-of-work-by-stake/lists"}