{"action":"created","comment":{"url":"https://api.github.com/repos/bitcoin-core/website/pulls/comments/50439176","id":50439176,"diff_hunk":"@@ -0,0 +1,124 @@\n+---\n+version: 1\n+title: Segregated Witness Wallet Development Guide\n+name: segwit-wallet-dev\n+type: page\n+permalink: /en/segwit_wallet_dev\n+---\n+\n+### Witness program\n+\n+There are 2 ways to use segregated witness:\n+\n+#### Native witness program\n+\n+Native witness program is defined as a <code>scriptPubKey</code> with a single byte push (<code>OP_0</code>, <code>OP_1</code>, ...,  <code>OP_16</code>) followed by a push of 2 to 32 bytes.\n+\n+#### Witness program nested in P2SH\n+\n+Witness program nested in P2SH is a P2SH output with a <code>redeemScript</code> of a single byte push (<code>OP_0</code>, <code>OP_1</code>, ...,  <code>OP_16</code>) followed by a push of 2 to 32 bytes.\n+\n+### Transaction Serialization\n+\n+If a transaction is transmitted without any witness data, the traditional serialization format MUST be used.\n+\n+If a transaction is transmitted with witness data, a new serialization format MUST be used:\n+\n+<pre><code>[nVersion][marker][flag][txins][txouts][witness][nLockTime]</code></pre>\n+\n+Format of <code>nVersion</code>, <code>txins</code>, <code>txouts</code>, and <code>nLockTime</code> are same as traditional serialization.\n+\n+The <code>marker</code> MUST be <code>0x00</code>.\n+\n+The <code>flag</code> MUST be a 1-byte non-zero value. Currently, <code>0x01</code> MUST be used.\n+\n+The <code>witness</code> is a serialization of all witness data of the transaction. Each txin is associated with a witness field. A witness field starts with a var_int to indicate the number of stack items for the txin. It is followed by stack items, with each item starts with a var_int to indicate the length. Witness data is NOT script and is not restricted by the 520-byte push limit.\n+\n+A non-witness program txin MUST be associated with an empty witness field, represented by a <code>0x00</code>. If all txins are not witness program, a transaction MUST be serialized with the traditional format (exception: coinbase transaction).\n+\n+### Transaction ID\n+\n+Each transaction will have 2 IDs.\n+\n+Definition of <code>txid</code> remains unchanged: the double SHA256 of the traditional serialization.\n+\n+A new <code>wtxid</code> is defined: the double SHA256 of the new serialization with witness data. If a transaction is transmitted without any witness data, its <code>wtxid</code> is same as the <code>txid</code>.\n+\n+The txid remains the primary identifier of a transaction. Particularly, it is used in the txin when referring to a previous output.\n+\n+### Standard script types\n+\n+#### Pay-to-Public-Key-Hash (P2PKH)\n+P2PKH is the most common <code>scriptPubKey</code> template defined by Satoshi Nakamoto, allows simple payment to a single public key. The format is:\n+\n+<pre><code>scriptPubKey (25 bytes): OP_DUP OP_HASH160 < 20-byte-pubkey-hash > OP_EQUALVERIFY OP_CHECKSIG</code></pre>\n+\n+To spend a P2PKH output, the <code>scriptSig</code> is\n+\n+<pre><code>scriptSig: < sig > < pubkey ></code></pre>\n+\n+where the <code>RIPEMD160(SHA256(pubkey))</code> is equal to the <code>20-byte-pubkey-hash</code> in scriptPubKey.\n+\n+#### Pay-to-Script-Hash (P2SH)\n+P2SH is defined in BIP16. It allows payment to arbitrarily complex scripts with a fixed length <code>scriptPubKey</code>. The format is:\n+\n+<pre><code>scriptPubKey (23 bytes): OP_HASH160 <20-byte-script-hash> OP_EQUAL</code></pre>\n+\n+To spend a P2SH output, the <code>scriptSig</code> is\n+\n+<pre><code>scriptSig: <...> <...> <...> < redeemScript ></code></pre>\n+\n+where the <code>RIPEMD160(SHA256(redeemScript))</code> is equal to the <code>20-byte-script-hash</code> in <code>scriptPubKey</code>. The <code>redeemScript</code> is deserialized and evaluated with the remaining data in the <code>scriptSig</code>.\n+\n+#### Pay-to-Witness-Public-Key-Hash (P2WPKH)\n+P2WPKH is a new defined in BIP141. Similar to P2PKH, it allows simple payment to a single public key. The format is:","path":"_posts/en/pages/2016-01-18-segwit-wallet-dev.md","position":74,"original_position":74,"commit_id":"61b4dd6d7324040d8947db0d75c6d08a579bf19b","original_commit_id":"61b4dd6d7324040d8947db0d75c6d08a579bf19b","user":{"login":"kanzure","id":101238,"avatar_url":"https://avatars.githubusercontent.com/u/101238?v=3","gravatar_id":"","url":"https://api.github.com/users/kanzure","html_url":"https://github.com/kanzure","followers_url":"https://api.github.com/users/kanzure/followers","following_url":"https://api.github.com/users/kanzure/following{/other_user}","gists_url":"https://api.github.com/users/kanzure/gists{/gist_id}","starred_url":"https://api.github.com/users/kanzure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kanzure/subscriptions","organizations_url":"https://api.github.com/users/kanzure/orgs","repos_url":"https://api.github.com/users/kanzure/repos","events_url":"https://api.github.com/users/kanzure/events{/privacy}","received_events_url":"https://api.github.com/users/kanzure/received_events","type":"User","site_admin":false},"body":"grammar here: \"is a new defined in BIP141\", needs to be \"P2WPKH is a new script type defined in BIP141\"","created_at":"2016-01-21T18:14:11Z","updated_at":"2016-01-21T18:14:11Z","html_url":"https://github.com/bitcoin-core/website/pull/55#discussion_r50439176","pull_request_url":"https://api.github.com/repos/bitcoin-core/website/pulls/55","_links":{"self":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/comments/50439176"},"html":{"href":"https://github.com/bitcoin-core/website/pull/55#discussion_r50439176"},"pull_request":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/55"}}},"pull_request":{"url":"https://api.github.com/repos/bitcoin-core/website/pulls/55","id":56737599,"html_url":"https://github.com/bitcoin-core/website/pull/55","diff_url":"https://github.com/bitcoin-core/website/pull/55.diff","patch_url":"https://github.com/bitcoin-core/website/pull/55.patch","issue_url":"https://api.github.com/repos/bitcoin-core/website/issues/55","number":55,"state":"open","locked":false,"title":"WIP: Segwit wallet dev guide","user":{"login":"jl2012","id":8403418,"avatar_url":"https://avatars.githubusercontent.com/u/8403418?v=3","gravatar_id":"","url":"https://api.github.com/users/jl2012","html_url":"https://github.com/jl2012","followers_url":"https://api.github.com/users/jl2012/followers","following_url":"https://api.github.com/users/jl2012/following{/other_user}","gists_url":"https://api.github.com/users/jl2012/gists{/gist_id}","starred_url":"https://api.github.com/users/jl2012/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl2012/subscriptions","organizations_url":"https://api.github.com/users/jl2012/orgs","repos_url":"https://api.github.com/users/jl2012/repos","events_url":"https://api.github.com/users/jl2012/events{/privacy}","received_events_url":"https://api.github.com/users/jl2012/received_events","type":"User","site_admin":false},"body":"Required for #56 ","created_at":"2016-01-21T11:38:13Z","updated_at":"2016-01-21T18:14:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f93af4cfa7fd054b1a296cad1ed1a277dd08987b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitcoin-core/website/pulls/55/commits","review_comments_url":"https://api.github.com/repos/bitcoin-core/website/pulls/55/comments","review_comment_url":"https://api.github.com/repos/bitcoin-core/website/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoin-core/website/issues/55/comments","statuses_url":"https://api.github.com/repos/bitcoin-core/website/statuses/61b4dd6d7324040d8947db0d75c6d08a579bf19b","head":{"label":"jl2012:segwit-wallet","ref":"segwit-wallet","sha":"61b4dd6d7324040d8947db0d75c6d08a579bf19b","user":{"login":"jl2012","id":8403418,"avatar_url":"https://avatars.githubusercontent.com/u/8403418?v=3","gravatar_id":"","url":"https://api.github.com/users/jl2012","html_url":"https://github.com/jl2012","followers_url":"https://api.github.com/users/jl2012/followers","following_url":"https://api.github.com/users/jl2012/following{/other_user}","gists_url":"https://api.github.com/users/jl2012/gists{/gist_id}","starred_url":"https://api.github.com/users/jl2012/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl2012/subscriptions","organizations_url":"https://api.github.com/users/jl2012/orgs","repos_url":"https://api.github.com/users/jl2012/repos","events_url":"https://api.github.com/users/jl2012/events{/privacy}","received_events_url":"https://api.github.com/users/jl2012/received_events","type":"User","site_admin":false},"repo":{"id":49876962,"name":"website","full_name":"jl2012/website","owner":{"login":"jl2012","id":8403418,"avatar_url":"https://avatars.githubusercontent.com/u/8403418?v=3","gravatar_id":"","url":"https://api.github.com/users/jl2012","html_url":"https://github.com/jl2012","followers_url":"https://api.github.com/users/jl2012/followers","following_url":"https://api.github.com/users/jl2012/following{/other_user}","gists_url":"https://api.github.com/users/jl2012/gists{/gist_id}","starred_url":"https://api.github.com/users/jl2012/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jl2012/subscriptions","organizations_url":"https://api.github.com/users/jl2012/orgs","repos_url":"https://api.github.com/users/jl2012/repos","events_url":"https://api.github.com/users/jl2012/events{/privacy}","received_events_url":"https://api.github.com/users/jl2012/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jl2012/website","description":"Bitcoin Core main website","fork":true,"url":"https://api.github.com/repos/jl2012/website","forks_url":"https://api.github.com/repos/jl2012/website/forks","keys_url":"https://api.github.com/repos/jl2012/website/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jl2012/website/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jl2012/website/teams","hooks_url":"https://api.github.com/repos/jl2012/website/hooks","issue_events_url":"https://api.github.com/repos/jl2012/website/issues/events{/number}","events_url":"https://api.github.com/repos/jl2012/website/events","assignees_url":"https://api.github.com/repos/jl2012/website/assignees{/user}","branches_url":"https://api.github.com/repos/jl2012/website/branches{/branch}","tags_url":"https://api.github.com/repos/jl2012/website/tags","blobs_url":"https://api.github.com/repos/jl2012/website/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jl2012/website/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jl2012/website/git/refs{/sha}","trees_url":"https://api.github.com/repos/jl2012/website/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jl2012/website/statuses/{sha}","languages_url":"https://api.github.com/repos/jl2012/website/languages","stargazers_url":"https://api.github.com/repos/jl2012/website/stargazers","contributors_url":"https://api.github.com/repos/jl2012/website/contributors","subscribers_url":"https://api.github.com/repos/jl2012/website/subscribers","subscription_url":"https://api.github.com/repos/jl2012/website/subscription","commits_url":"https://api.github.com/repos/jl2012/website/commits{/sha}","git_commits_url":"https://api.github.com/repos/jl2012/website/git/commits{/sha}","comments_url":"https://api.github.com/repos/jl2012/website/comments{/number}","issue_comment_url":"https://api.github.com/repos/jl2012/website/issues/comments{/number}","contents_url":"https://api.github.com/repos/jl2012/website/contents/{+path}","compare_url":"https://api.github.com/repos/jl2012/website/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jl2012/website/merges","archive_url":"https://api.github.com/repos/jl2012/website/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jl2012/website/downloads","issues_url":"https://api.github.com/repos/jl2012/website/issues{/number}","pulls_url":"https://api.github.com/repos/jl2012/website/pulls{/number}","milestones_url":"https://api.github.com/repos/jl2012/website/milestones{/number}","notifications_url":"https://api.github.com/repos/jl2012/website/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jl2012/website/labels{/name}","releases_url":"https://api.github.com/repos/jl2012/website/releases{/id}","created_at":"2016-01-18T12:57:51Z","updated_at":"2016-01-18T12:57:52Z","pushed_at":"2016-01-21T18:06:23Z","git_url":"git://github.com/jl2012/website.git","ssh_url":"git@github.com:jl2012/website.git","clone_url":"https://github.com/jl2012/website.git","svn_url":"https://github.com/jl2012/website","homepage":null,"size":977,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"gh-pages"}},"base":{"label":"bitcoin-core:gh-pages","ref":"gh-pages","sha":"59ce012b9189642cba1a51251e60c948804a96d5","user":{"login":"bitcoin-core","id":13464320,"avatar_url":"https://avatars.githubusercontent.com/u/13464320?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin-core","html_url":"https://github.com/bitcoin-core","followers_url":"https://api.github.com/users/bitcoin-core/followers","following_url":"https://api.github.com/users/bitcoin-core/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin-core/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin-core/subscriptions","organizations_url":"https://api.github.com/users/bitcoin-core/orgs","repos_url":"https://api.github.com/users/bitcoin-core/repos","events_url":"https://api.github.com/users/bitcoin-core/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin-core/received_events","type":"Organization","site_admin":false},"repo":{"id":49334327,"name":"website","full_name":"bitcoin-core/website","owner":{"login":"bitcoin-core","id":13464320,"avatar_url":"https://avatars.githubusercontent.com/u/13464320?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin-core","html_url":"https://github.com/bitcoin-core","followers_url":"https://api.github.com/users/bitcoin-core/followers","following_url":"https://api.github.com/users/bitcoin-core/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin-core/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin-core/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin-core/subscriptions","organizations_url":"https://api.github.com/users/bitcoin-core/orgs","repos_url":"https://api.github.com/users/bitcoin-core/repos","events_url":"https://api.github.com/users/bitcoin-core/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin-core/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoin-core/website","description":"Bitcoin Core main website","fork":false,"url":"https://api.github.com/repos/bitcoin-core/website","forks_url":"https://api.github.com/repos/bitcoin-core/website/forks","keys_url":"https://api.github.com/repos/bitcoin-core/website/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoin-core/website/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoin-core/website/teams","hooks_url":"https://api.github.com/repos/bitcoin-core/website/hooks","issue_events_url":"https://api.github.com/repos/bitcoin-core/website/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoin-core/website/events","assignees_url":"https://api.github.com/repos/bitcoin-core/website/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoin-core/website/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoin-core/website/tags","blobs_url":"https://api.github.com/repos/bitcoin-core/website/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoin-core/website/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoin-core/website/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoin-core/website/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoin-core/website/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoin-core/website/languages","stargazers_url":"https://api.github.com/repos/bitcoin-core/website/stargazers","contributors_url":"https://api.github.com/repos/bitcoin-core/website/contributors","subscribers_url":"https://api.github.com/repos/bitcoin-core/website/subscribers","subscription_url":"https://api.github.com/repos/bitcoin-core/website/subscription","commits_url":"https://api.github.com/repos/bitcoin-core/website/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoin-core/website/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoin-core/website/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoin-core/website/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoin-core/website/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoin-core/website/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoin-core/website/merges","archive_url":"https://api.github.com/repos/bitcoin-core/website/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoin-core/website/downloads","issues_url":"https://api.github.com/repos/bitcoin-core/website/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoin-core/website/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoin-core/website/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoin-core/website/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoin-core/website/labels{/name}","releases_url":"https://api.github.com/repos/bitcoin-core/website/releases{/id}","created_at":"2016-01-09T17:37:52Z","updated_at":"2016-01-18T21:30:01Z","pushed_at":"2016-01-21T18:06:23Z","git_url":"git://github.com/bitcoin-core/website.git","ssh_url":"git@github.com:bitcoin-core/website.git","clone_url":"https://github.com/bitcoin-core/website.git","svn_url":"https://github.com/bitcoin-core/website","homepage":null,"size":1020,"stargazers_count":11,"watchers_count":11,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":15,"forks":11,"open_issues":15,"watchers":11,"default_branch":"gh-pages"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/55"},"html":{"href":"https://github.com/bitcoin-core/website/pull/55"},"issue":{"href":"https://api.github.com/repos/bitcoin-core/website/issues/55"},"comments":{"href":"https://api.github.com/repos/bitcoin-core/website/issues/55/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/55/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoin-core/website/pulls/55/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoin-core/website/statuses/61b4dd6d7324040d8947db0d75c6d08a579bf19b"}}}}