{"action":"created","comment":{"url":"https://api.github.com/repos/layr-team/Layr/pulls/comments/180100326","pull_request_review_id":110461605,"id":180100326,"diff_hunk":"@@ -117,36 +128,47 @@ class BatNode {\n \n   sendShardToNode(nodeInfo, shard, shards, shardIdx, storedShardName, distinctIdx, manifestPath) {\n     fs.readFile(`./shards/${storedShardName}`, (err, fileData) => {\n-      let { port, host } = nodeInfo;\n-      let client = this.connect(port, host, () => {\n-        console.log('connected to target batnode')\n-      });\n-  \n-      let message = {\n-        messageType: \"STORE_FILE\",\n-        fileName: shard,\n-        fileContent: fileData\n-      };\n-  \n-      client.on('data', (data) => {\n-        console.log(\"Shard successfully stored on server!\")\n-        if (shardIdx < shards.length - 1){\n-          this.getClosestBatNodeToShard(shards[shardIdx + 1], (batNode, kadNode) => {\n-            this.kadenceNode.getOtherNodeStellarAccount(kadNode, (error, accountId) => {\n-              console.log(\"Sending payment to a peer node's Stellar account...\")\n-              this.sendPaymentFor(accountId, (paymentResult) => {\n-                this.sendShardToNode(batNode, shards[shardIdx + 1], shards, shardIdx + 1, storedShardName, distinctIdx, manifestPath)\n+      crypto.randomBytes(32, (err, randomKey) => {\n+        let nonce = randomKey;\n+        let hashedDataAndNonce = fileUtils.sha1HashData(fileData, nonce);\n+        let shaPreimage = Buffer.from(hashedDataAndNonce, 'hex');\n+        let shaSignerKey = crypto.createHash('sha256').update(shaPreimage).digest('hex');\n+        let stellarPrivateKey = fileUtils.getStellarSecretSeed();\n+        this.createEscrowAccount(stellarPrivateKey, shaSignerKey, (escrowKeypair) => {\n+          let { port, host } = nodeInfo;\n+          let client = this.connect(port, host, () => {\n+            console.log('connected to target batnode')\n+          });\n+      \n+          let message = {\n+            messageType: \"STORE_FILE\",\n+            fileName: shard,\n+            fileContent: fileData,\n+            escrow: escrowKeypair.publicKey(),\n+            nonce\n+          };\n+      \n+          client.on('data', (data) => {\n+            console.log(\"Shard successfully stored on server!\")\n+            if (shardIdx < shards.length - 1){\n+              this.getClosestBatNodeToShard(shards[shardIdx + 1], (batNode, kadNode) => {\n+                this.kadenceNode.getOtherNodeStellarAccount(kadNode, (error, accountId) => {\n+                  console.log(\"Sending payment to a peer node's Stellar account...\")\n+                  this.sendPaymentFor(accountId, (paymentResult) => {","path":"batnode.js","position":81,"original_position":81,"commit_id":"07343bfc8f89692646a84193f19a5016bde18daa","original_commit_id":"07343bfc8f89692646a84193f19a5016bde18daa","user":{"login":"WilfredTA","id":26207779,"avatar_url":"https://avatars3.githubusercontent.com/u/26207779?v=4","gravatar_id":"","url":"https://api.github.com/users/WilfredTA","html_url":"https://github.com/WilfredTA","followers_url":"https://api.github.com/users/WilfredTA/followers","following_url":"https://api.github.com/users/WilfredTA/following{/other_user}","gists_url":"https://api.github.com/users/WilfredTA/gists{/gist_id}","starred_url":"https://api.github.com/users/WilfredTA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WilfredTA/subscriptions","organizations_url":"https://api.github.com/users/WilfredTA/orgs","repos_url":"https://api.github.com/users/WilfredTA/repos","events_url":"https://api.github.com/users/WilfredTA/events{/privacy}","received_events_url":"https://api.github.com/users/WilfredTA/received_events","type":"User","site_admin":false},"body":"Yeah I can actually take `sendPaymentFor` out entirely, as it's not necessary now that we are using escrow smart contracts","created_at":"2018-04-09T13:50:56Z","updated_at":"2018-04-09T13:50:56Z","html_url":"https://github.com/layr-team/Layr/pull/50#discussion_r180100326","pull_request_url":"https://api.github.com/repos/layr-team/Layr/pulls/50","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/comments/180100326"},"html":{"href":"https://github.com/layr-team/Layr/pull/50#discussion_r180100326"},"pull_request":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/50"}},"in_reply_to_id":179972467},"pull_request":{"url":"https://api.github.com/repos/layr-team/Layr/pulls/50","id":180159477,"html_url":"https://github.com/layr-team/Layr/pull/50","diff_url":"https://github.com/layr-team/Layr/pull/50.diff","patch_url":"https://github.com/layr-team/Layr/pull/50.patch","issue_url":"https://api.github.com/repos/layr-team/Layr/issues/50","number":50,"state":"open","locked":false,"title":"Escrow Smart Contracts","user":{"login":"WilfredTA","id":26207779,"avatar_url":"https://avatars3.githubusercontent.com/u/26207779?v=4","gravatar_id":"","url":"https://api.github.com/users/WilfredTA","html_url":"https://github.com/WilfredTA","followers_url":"https://api.github.com/users/WilfredTA/followers","following_url":"https://api.github.com/users/WilfredTA/following{/other_user}","gists_url":"https://api.github.com/users/WilfredTA/gists{/gist_id}","starred_url":"https://api.github.com/users/WilfredTA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WilfredTA/subscriptions","organizations_url":"https://api.github.com/users/WilfredTA/orgs","repos_url":"https://api.github.com/users/WilfredTA/repos","events_url":"https://api.github.com/users/WilfredTA/events{/privacy}","received_events_url":"https://api.github.com/users/WilfredTA/received_events","type":"User","site_admin":false},"body":"Changes introduced by this merge:\r\n\r\n1. Escrow smart contracts are introduced between data host and data owner *per* file stored on data host by data owner.\r\n2. The data host can only access the funds by proving it received the file. This prevents payments from going through in the event that, say, the file doesn't make it to the host. One could argue that we could just send data to a data host, then audit it and pay it if it passes the audit. Problem with this is that it is possible that the payment takes a while to go through, so the data host waits a predetermined amount of time, at which point it deletes the file... But what if the payment was just taking a long time? So after it deletes the file, the payment completes and the data host received money but doesn't have the file. The data owner just lost money... This takes the guesswork out of it: at the time of payment, the data host must have the file.\r\n\r\n3. Future steps using the technology introduced here:\r\n\r\nb. Associate an escrow account with a shard ID (which can be done by setting the escrow account id to the sha256 of the shard id). This allows us to associate each shard with an escrow account id, making audits of each shard pretty straightforward. \r\nb. Set up a time window that, if the data host doesn't withdraw the funds, the funds are merged back to the data owner's account.\r\nc. Set up preAuth transaction signatures (will explain the benefits of using this in our meeting).\r\n\r\n","created_at":"2018-04-08T13:19:03Z","updated_at":"2018-04-09T13:50:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0d794f94126f99aa894830ee6dd1224e8d7717a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/layr-team/Layr/pulls/50/commits","review_comments_url":"https://api.github.com/repos/layr-team/Layr/pulls/50/comments","review_comment_url":"https://api.github.com/repos/layr-team/Layr/pulls/comments{/number}","comments_url":"https://api.github.com/repos/layr-team/Layr/issues/50/comments","statuses_url":"https://api.github.com/repos/layr-team/Layr/statuses/07343bfc8f89692646a84193f19a5016bde18daa","head":{"label":"layr-team:escrow_transactions","ref":"escrow_transactions","sha":"07343bfc8f89692646a84193f19a5016bde18daa","user":{"login":"layr-team","id":37969204,"avatar_url":"https://avatars1.githubusercontent.com/u/37969204?v=4","gravatar_id":"","url":"https://api.github.com/users/layr-team","html_url":"https://github.com/layr-team","followers_url":"https://api.github.com/users/layr-team/followers","following_url":"https://api.github.com/users/layr-team/following{/other_user}","gists_url":"https://api.github.com/users/layr-team/gists{/gist_id}","starred_url":"https://api.github.com/users/layr-team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layr-team/subscriptions","organizations_url":"https://api.github.com/users/layr-team/orgs","repos_url":"https://api.github.com/users/layr-team/repos","events_url":"https://api.github.com/users/layr-team/events{/privacy}","received_events_url":"https://api.github.com/users/layr-team/received_events","type":"Organization","site_admin":false},"repo":{"id":124460487,"name":"Layr","full_name":"layr-team/Layr","owner":{"login":"layr-team","id":37969204,"avatar_url":"https://avatars1.githubusercontent.com/u/37969204?v=4","gravatar_id":"","url":"https://api.github.com/users/layr-team","html_url":"https://github.com/layr-team","followers_url":"https://api.github.com/users/layr-team/followers","following_url":"https://api.github.com/users/layr-team/following{/other_user}","gists_url":"https://api.github.com/users/layr-team/gists{/gist_id}","starred_url":"https://api.github.com/users/layr-team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layr-team/subscriptions","organizations_url":"https://api.github.com/users/layr-team/orgs","repos_url":"https://api.github.com/users/layr-team/repos","events_url":"https://api.github.com/users/layr-team/events{/privacy}","received_events_url":"https://api.github.com/users/layr-team/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/layr-team/Layr","description":"A decentralized (p2p) file storage system built atop Kademlia DHT that enforces data integrity and availability, with cryptocurrency-based incentive scheme","fork":false,"url":"https://api.github.com/repos/layr-team/Layr","forks_url":"https://api.github.com/repos/layr-team/Layr/forks","keys_url":"https://api.github.com/repos/layr-team/Layr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/layr-team/Layr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/layr-team/Layr/teams","hooks_url":"https://api.github.com/repos/layr-team/Layr/hooks","issue_events_url":"https://api.github.com/repos/layr-team/Layr/issues/events{/number}","events_url":"https://api.github.com/repos/layr-team/Layr/events","assignees_url":"https://api.github.com/repos/layr-team/Layr/assignees{/user}","branches_url":"https://api.github.com/repos/layr-team/Layr/branches{/branch}","tags_url":"https://api.github.com/repos/layr-team/Layr/tags","blobs_url":"https://api.github.com/repos/layr-team/Layr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/layr-team/Layr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/layr-team/Layr/git/refs{/sha}","trees_url":"https://api.github.com/repos/layr-team/Layr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/layr-team/Layr/statuses/{sha}","languages_url":"https://api.github.com/repos/layr-team/Layr/languages","stargazers_url":"https://api.github.com/repos/layr-team/Layr/stargazers","contributors_url":"https://api.github.com/repos/layr-team/Layr/contributors","subscribers_url":"https://api.github.com/repos/layr-team/Layr/subscribers","subscription_url":"https://api.github.com/repos/layr-team/Layr/subscription","commits_url":"https://api.github.com/repos/layr-team/Layr/commits{/sha}","git_commits_url":"https://api.github.com/repos/layr-team/Layr/git/commits{/sha}","comments_url":"https://api.github.com/repos/layr-team/Layr/comments{/number}","issue_comment_url":"https://api.github.com/repos/layr-team/Layr/issues/comments{/number}","contents_url":"https://api.github.com/repos/layr-team/Layr/contents/{+path}","compare_url":"https://api.github.com/repos/layr-team/Layr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/layr-team/Layr/merges","archive_url":"https://api.github.com/repos/layr-team/Layr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/layr-team/Layr/downloads","issues_url":"https://api.github.com/repos/layr-team/Layr/issues{/number}","pulls_url":"https://api.github.com/repos/layr-team/Layr/pulls{/number}","milestones_url":"https://api.github.com/repos/layr-team/Layr/milestones{/number}","notifications_url":"https://api.github.com/repos/layr-team/Layr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/layr-team/Layr/labels{/name}","releases_url":"https://api.github.com/repos/layr-team/Layr/releases{/id}","deployments_url":"https://api.github.com/repos/layr-team/Layr/deployments","created_at":"2018-03-08T23:27:45Z","updated_at":"2018-04-08T14:43:09Z","pushed_at":"2018-04-08T13:19:04Z","git_url":"git://github.com/layr-team/Layr.git","ssh_url":"git@github.com:layr-team/Layr.git","clone_url":"https://github.com/layr-team/Layr.git","svn_url":"https://github.com/layr-team/Layr","homepage":"","size":116704,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":16,"license":null,"forks":1,"open_issues":16,"watchers":5,"default_branch":"master"}},"base":{"label":"layr-team:master","ref":"master","sha":"7ebaf3c2bdf2314435fd237d42db6c71396fc5eb","user":{"login":"layr-team","id":37969204,"avatar_url":"https://avatars1.githubusercontent.com/u/37969204?v=4","gravatar_id":"","url":"https://api.github.com/users/layr-team","html_url":"https://github.com/layr-team","followers_url":"https://api.github.com/users/layr-team/followers","following_url":"https://api.github.com/users/layr-team/following{/other_user}","gists_url":"https://api.github.com/users/layr-team/gists{/gist_id}","starred_url":"https://api.github.com/users/layr-team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layr-team/subscriptions","organizations_url":"https://api.github.com/users/layr-team/orgs","repos_url":"https://api.github.com/users/layr-team/repos","events_url":"https://api.github.com/users/layr-team/events{/privacy}","received_events_url":"https://api.github.com/users/layr-team/received_events","type":"Organization","site_admin":false},"repo":{"id":124460487,"name":"Layr","full_name":"layr-team/Layr","owner":{"login":"layr-team","id":37969204,"avatar_url":"https://avatars1.githubusercontent.com/u/37969204?v=4","gravatar_id":"","url":"https://api.github.com/users/layr-team","html_url":"https://github.com/layr-team","followers_url":"https://api.github.com/users/layr-team/followers","following_url":"https://api.github.com/users/layr-team/following{/other_user}","gists_url":"https://api.github.com/users/layr-team/gists{/gist_id}","starred_url":"https://api.github.com/users/layr-team/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/layr-team/subscriptions","organizations_url":"https://api.github.com/users/layr-team/orgs","repos_url":"https://api.github.com/users/layr-team/repos","events_url":"https://api.github.com/users/layr-team/events{/privacy}","received_events_url":"https://api.github.com/users/layr-team/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/layr-team/Layr","description":"A decentralized (p2p) file storage system built atop Kademlia DHT that enforces data integrity and availability, with cryptocurrency-based incentive scheme","fork":false,"url":"https://api.github.com/repos/layr-team/Layr","forks_url":"https://api.github.com/repos/layr-team/Layr/forks","keys_url":"https://api.github.com/repos/layr-team/Layr/keys{/key_id}","collaborators_url":"https://api.github.com/repos/layr-team/Layr/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/layr-team/Layr/teams","hooks_url":"https://api.github.com/repos/layr-team/Layr/hooks","issue_events_url":"https://api.github.com/repos/layr-team/Layr/issues/events{/number}","events_url":"https://api.github.com/repos/layr-team/Layr/events","assignees_url":"https://api.github.com/repos/layr-team/Layr/assignees{/user}","branches_url":"https://api.github.com/repos/layr-team/Layr/branches{/branch}","tags_url":"https://api.github.com/repos/layr-team/Layr/tags","blobs_url":"https://api.github.com/repos/layr-team/Layr/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/layr-team/Layr/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/layr-team/Layr/git/refs{/sha}","trees_url":"https://api.github.com/repos/layr-team/Layr/git/trees{/sha}","statuses_url":"https://api.github.com/repos/layr-team/Layr/statuses/{sha}","languages_url":"https://api.github.com/repos/layr-team/Layr/languages","stargazers_url":"https://api.github.com/repos/layr-team/Layr/stargazers","contributors_url":"https://api.github.com/repos/layr-team/Layr/contributors","subscribers_url":"https://api.github.com/repos/layr-team/Layr/subscribers","subscription_url":"https://api.github.com/repos/layr-team/Layr/subscription","commits_url":"https://api.github.com/repos/layr-team/Layr/commits{/sha}","git_commits_url":"https://api.github.com/repos/layr-team/Layr/git/commits{/sha}","comments_url":"https://api.github.com/repos/layr-team/Layr/comments{/number}","issue_comment_url":"https://api.github.com/repos/layr-team/Layr/issues/comments{/number}","contents_url":"https://api.github.com/repos/layr-team/Layr/contents/{+path}","compare_url":"https://api.github.com/repos/layr-team/Layr/compare/{base}...{head}","merges_url":"https://api.github.com/repos/layr-team/Layr/merges","archive_url":"https://api.github.com/repos/layr-team/Layr/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/layr-team/Layr/downloads","issues_url":"https://api.github.com/repos/layr-team/Layr/issues{/number}","pulls_url":"https://api.github.com/repos/layr-team/Layr/pulls{/number}","milestones_url":"https://api.github.com/repos/layr-team/Layr/milestones{/number}","notifications_url":"https://api.github.com/repos/layr-team/Layr/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/layr-team/Layr/labels{/name}","releases_url":"https://api.github.com/repos/layr-team/Layr/releases{/id}","deployments_url":"https://api.github.com/repos/layr-team/Layr/deployments","created_at":"2018-03-08T23:27:45Z","updated_at":"2018-04-08T14:43:09Z","pushed_at":"2018-04-08T13:19:04Z","git_url":"git://github.com/layr-team/Layr.git","ssh_url":"git@github.com:layr-team/Layr.git","clone_url":"https://github.com/layr-team/Layr.git","svn_url":"https://github.com/layr-team/Layr","homepage":"","size":116704,"stargazers_count":5,"watchers_count":5,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":16,"license":null,"forks":1,"open_issues":16,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/50"},"html":{"href":"https://github.com/layr-team/Layr/pull/50"},"issue":{"href":"https://api.github.com/repos/layr-team/Layr/issues/50"},"comments":{"href":"https://api.github.com/repos/layr-team/Layr/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/layr-team/Layr/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/layr-team/Layr/statuses/07343bfc8f89692646a84193f19a5016bde18daa"}},"author_association":"OWNER"}}
{"actor":{"display_login":"WilfredTA"}}