{"action":"created","comment":{"url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/comments/34963554","id":34963554,"diff_hunk":"@@ -32,39 +32,37 @@ ECSignature.parseCompact = function (buffer) {\n   }\n }\n \n+// Strict DER - https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki\n+// NOTE: SIGHASH byte ignored\n ECSignature.fromDER = function (buffer) {\n-  assert.equal(buffer.readUInt8(0), 0x30, 'Not a DER sequence')\n-  assert.equal(buffer.readUInt8(1), buffer.length - 2, 'Invalid sequence length')\n-  assert.equal(buffer.readUInt8(2), 0x02, 'Expected a DER integer')\n-\n-  var rLen = buffer.readUInt8(3)\n-  assert(rLen > 0, 'R length is zero')\n-\n-  var offset = 4 + rLen\n-  assert.equal(buffer.readUInt8(offset), 0x02, 'Expected a DER integer (2)')\n-\n-  var sLen = buffer.readUInt8(offset + 1)\n-  assert(sLen > 0, 'S length is zero')\n-\n-  var rB = buffer.slice(4, offset)\n-  var sB = buffer.slice(offset + 2)\n-  offset += 2 + sLen\n-\n-  if (rLen > 1 && rB.readUInt8(0) === 0x00) {\n-    assert(rB.readUInt8(1) & 0x80, 'R value excessively padded')\n-  }\n-\n-  if (sLen > 1 && sB.readUInt8(0) === 0x00) {\n-    assert(sB.readUInt8(1) & 0x80, 'S value excessively padded')\n-  }\n-\n-  assert.equal(offset, buffer.length, 'Invalid DER encoding')\n+  // Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S]\n+  if (buffer.length < 8) throw new Error('DER sequence too short')\n+  if (buffer.length > 72) throw new Error('DER sequence too long')\n+  if (buffer[0] !== 0x30) throw new Error('Not a DER sequence')\n+  if (buffer[1] !== buffer.length - 2) throw new Error('Invalid sequence length')\n+  if (buffer[2] !== 0x02) throw new Error('Expected a DER integer')\n+\n+  var lenR = buffer.readUInt8(3)\n+  if (lenR === 0) throw new Error('R length is zero')\n+  if (5 + lenR >= buffer.length) throw new Error('Invalid DER encoding')\n+  if (buffer[4 + lenR] !== 0x02) throw new Error('Expected a DER integer (2)')\n+\n+  var lenS = buffer[5 + lenR]\n+  if (lenS === 0) throw new Error('S length is zero')\n+  if ((lenR + lenS + 6) !== buffer.length) throw new Error('Invalid DER encoding (2)')\n+\n+  if (buffer[4] & 0x80) throw new Error('R value is negative')\n+  if (lenR > 1 && (buffer[4] === 0x00) && !(buffer[5] & 0x80)) throw new Error('R value excessively padded')\n+\n+  if (buffer[lenR + 6] & 0x80) throw new Error('S value is negative')\n+  if (lenS > 1 && (buffer[lenR + 6] === 0x00) && !(buffer[lenR + 7] & 0x80)) throw new Error('S value excessively padded')","path":"src/ecsignature.js","position":53,"original_position":53,"commit_id":"5021714a85950eb026e53b1da8f59915c56cf55a","original_commit_id":"5021714a85950eb026e53b1da8f59915c56cf55a","user":{"login":"dcousens","id":413395,"avatar_url":"https://avatars.githubusercontent.com/u/413395?v=3","gravatar_id":"","url":"https://api.github.com/users/dcousens","html_url":"https://github.com/dcousens","followers_url":"https://api.github.com/users/dcousens/followers","following_url":"https://api.github.com/users/dcousens/following{/other_user}","gists_url":"https://api.github.com/users/dcousens/gists{/gist_id}","starred_url":"https://api.github.com/users/dcousens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcousens/subscriptions","organizations_url":"https://api.github.com/users/dcousens/orgs","repos_url":"https://api.github.com/users/dcousens/repos","events_url":"https://api.github.com/users/dcousens/events{/privacy}","received_events_url":"https://api.github.com/users/dcousens/received_events","type":"User","site_admin":false},"body":"I will later,  in fact I might even pull this out to a `bip66` module,   that way it could be super clear.","created_at":"2015-07-19T23:18:26Z","updated_at":"2015-07-19T23:18:26Z","html_url":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423#discussion_r34963554","pull_request_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423","_links":{"self":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/comments/34963554"},"html":{"href":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423#discussion_r34963554"},"pull_request":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423"}}},"pull_request":{"url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423","id":39343085,"html_url":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423","diff_url":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423.diff","patch_url":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423.patch","issue_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/423","number":423,"state":"open","locked":false,"title":"adhere more closely to BIP66","user":{"login":"dcousens","id":413395,"avatar_url":"https://avatars.githubusercontent.com/u/413395?v=3","gravatar_id":"","url":"https://api.github.com/users/dcousens","html_url":"https://github.com/dcousens","followers_url":"https://api.github.com/users/dcousens/followers","following_url":"https://api.github.com/users/dcousens/following{/other_user}","gists_url":"https://api.github.com/users/dcousens/gists{/gist_id}","starred_url":"https://api.github.com/users/dcousens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dcousens/subscriptions","organizations_url":"https://api.github.com/users/dcousens/orgs","repos_url":"https://api.github.com/users/dcousens/repos","events_url":"https://api.github.com/users/dcousens/events{/privacy}","received_events_url":"https://api.github.com/users/dcousens/received_events","type":"User","site_admin":false},"body":"See pseudo code for BIP66 [here](https://github.com/bitcoin/bips/blob/master/bip-0066.mediawiki#DER_encoding_reference),  with [ordering amendments](https://github.com/bitcoin/bips/pull/169).\r\n\r\nThe constant amendments are because we ignore the SIGHASH byte in this function, which is why the constants are `8, 72` for the min/max sizes, and `6` instead of `7` for the total length offset.","created_at":"2015-07-07T07:48:03Z","updated_at":"2015-07-19T23:18:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c923d9d5465a429cf0858182687d41184f869505","assignee":{"login":"jprichardson","id":150063,"avatar_url":"https://avatars.githubusercontent.com/u/150063?v=3","gravatar_id":"","url":"https://api.github.com/users/jprichardson","html_url":"https://github.com/jprichardson","followers_url":"https://api.github.com/users/jprichardson/followers","following_url":"https://api.github.com/users/jprichardson/following{/other_user}","gists_url":"https://api.github.com/users/jprichardson/gists{/gist_id}","starred_url":"https://api.github.com/users/jprichardson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jprichardson/subscriptions","organizations_url":"https://api.github.com/users/jprichardson/orgs","repos_url":"https://api.github.com/users/jprichardson/repos","events_url":"https://api.github.com/users/jprichardson/events{/privacy}","received_events_url":"https://api.github.com/users/jprichardson/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423/commits","review_comments_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423/comments","review_comment_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/423/comments","statuses_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/statuses/5021714a85950eb026e53b1da8f59915c56cf55a","head":{"label":"bitcoinjs:bip66adherance","ref":"bip66adherance","sha":"5021714a85950eb026e53b1da8f59915c56cf55a","user":{"login":"bitcoinjs","id":756696,"avatar_url":"https://avatars.githubusercontent.com/u/756696?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinjs","html_url":"https://github.com/bitcoinjs","followers_url":"https://api.github.com/users/bitcoinjs/followers","following_url":"https://api.github.com/users/bitcoinjs/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinjs/subscriptions","organizations_url":"https://api.github.com/users/bitcoinjs/orgs","repos_url":"https://api.github.com/users/bitcoinjs/repos","events_url":"https://api.github.com/users/bitcoinjs/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinjs/received_events","type":"Organization","site_admin":false},"repo":{"id":1701968,"name":"bitcoinjs-lib","full_name":"bitcoinjs/bitcoinjs-lib","owner":{"login":"bitcoinjs","id":756696,"avatar_url":"https://avatars.githubusercontent.com/u/756696?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinjs","html_url":"https://github.com/bitcoinjs","followers_url":"https://api.github.com/users/bitcoinjs/followers","following_url":"https://api.github.com/users/bitcoinjs/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinjs/subscriptions","organizations_url":"https://api.github.com/users/bitcoinjs/orgs","repos_url":"https://api.github.com/users/bitcoinjs/repos","events_url":"https://api.github.com/users/bitcoinjs/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoinjs/bitcoinjs-lib","description":"Bitcoin-related functions implemented in pure JavaScript","fork":false,"url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib","forks_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/forks","keys_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/teams","hooks_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/hooks","issue_events_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/events","assignees_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/tags","blobs_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/languages","stargazers_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/stargazers","contributors_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/contributors","subscribers_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/subscribers","subscription_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/subscription","commits_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/merges","archive_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/downloads","issues_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/labels{/name}","releases_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/releases{/id}","created_at":"2011-05-04T16:03:45Z","updated_at":"2015-07-15T02:57:58Z","pushed_at":"2015-07-08T02:36:51Z","git_url":"git://github.com/bitcoinjs/bitcoinjs-lib.git","ssh_url":"git@github.com:bitcoinjs/bitcoinjs-lib.git","clone_url":"https://github.com/bitcoinjs/bitcoinjs-lib.git","svn_url":"https://github.com/bitcoinjs/bitcoinjs-lib","homepage":"http://bitcoinjs.org","size":5600,"stargazers_count":867,"watchers_count":867,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":268,"mirror_url":null,"open_issues_count":17,"forks":268,"open_issues":17,"watchers":867,"default_branch":"master"}},"base":{"label":"bitcoinjs:master","ref":"master","sha":"db28cf2f0ea255e5449422d8163b56fecc4d8e48","user":{"login":"bitcoinjs","id":756696,"avatar_url":"https://avatars.githubusercontent.com/u/756696?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinjs","html_url":"https://github.com/bitcoinjs","followers_url":"https://api.github.com/users/bitcoinjs/followers","following_url":"https://api.github.com/users/bitcoinjs/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinjs/subscriptions","organizations_url":"https://api.github.com/users/bitcoinjs/orgs","repos_url":"https://api.github.com/users/bitcoinjs/repos","events_url":"https://api.github.com/users/bitcoinjs/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinjs/received_events","type":"Organization","site_admin":false},"repo":{"id":1701968,"name":"bitcoinjs-lib","full_name":"bitcoinjs/bitcoinjs-lib","owner":{"login":"bitcoinjs","id":756696,"avatar_url":"https://avatars.githubusercontent.com/u/756696?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoinjs","html_url":"https://github.com/bitcoinjs","followers_url":"https://api.github.com/users/bitcoinjs/followers","following_url":"https://api.github.com/users/bitcoinjs/following{/other_user}","gists_url":"https://api.github.com/users/bitcoinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoinjs/subscriptions","organizations_url":"https://api.github.com/users/bitcoinjs/orgs","repos_url":"https://api.github.com/users/bitcoinjs/repos","events_url":"https://api.github.com/users/bitcoinjs/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoinjs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoinjs/bitcoinjs-lib","description":"Bitcoin-related functions implemented in pure JavaScript","fork":false,"url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib","forks_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/forks","keys_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/teams","hooks_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/hooks","issue_events_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/events","assignees_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/tags","blobs_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/languages","stargazers_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/stargazers","contributors_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/contributors","subscribers_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/subscribers","subscription_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/subscription","commits_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/merges","archive_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/downloads","issues_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/labels{/name}","releases_url":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/releases{/id}","created_at":"2011-05-04T16:03:45Z","updated_at":"2015-07-15T02:57:58Z","pushed_at":"2015-07-08T02:36:51Z","git_url":"git://github.com/bitcoinjs/bitcoinjs-lib.git","ssh_url":"git@github.com:bitcoinjs/bitcoinjs-lib.git","clone_url":"https://github.com/bitcoinjs/bitcoinjs-lib.git","svn_url":"https://github.com/bitcoinjs/bitcoinjs-lib","homepage":"http://bitcoinjs.org","size":5600,"stargazers_count":867,"watchers_count":867,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":268,"mirror_url":null,"open_issues_count":17,"forks":268,"open_issues":17,"watchers":867,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423"},"html":{"href":"https://github.com/bitcoinjs/bitcoinjs-lib/pull/423"},"issue":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/423"},"comments":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/issues/423/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/pulls/423/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoinjs/bitcoinjs-lib/statuses/5021714a85950eb026e53b1da8f59915c56cf55a"}}}}