1 | # Open Publish
|
2 |
|
3 | [![Build Status](http://drone.d.blockai.com/api/badge/github.com/blockai/openpublish/status.svg?branch=master)](http://drone.d.blockai.com/github.com/blockai/openpublish)
|
4 |
|
5 | A publishing protocol for registering media as a digital asset on the Bitcoin blockchain.
|
6 |
|
7 | Open Publish aims to give ownership of digital media back to the individual and allow individuals to create contracts for licensing and micropayment channels using Bitcoin. Think combining BlockSign, OpenAssets and a royalty payment mechanism.
|
8 |
|
9 | Like BlockSign, digital media is represented as a cryptographic digest but in a content-addressable format that works seamlessly with IPFS, BitTorrent and WebTorrent. This content-addressable representation is provably signed, timestamped, and recorded in perpetuity by the Bitcoin blockchain in a format compatible with the BitTorrent Magnet URI scheme and IPFS address scheme.
|
10 |
|
11 | The Open Publish protocol allows claiming ownership over a digital asset that can be used by other products to represent a limited and non-exclusive copyright of this document.
|
12 |
|
13 | The Open Publish protocol allows for transfering partial ownership of these digital assets.
|
14 |
|
15 | Any honest third-party software can read the state of ownership from the Bitcoin blockchain and create software that directs payments to the legitimate owners of the content in the form of direct tips, monthly subscriptions or various synchronization licenses modeled on existing intellectual property systems.
|
16 |
|
17 | For example, someone could write software that displays media with a consumer Bitcoin wallet allowing for people to easily and directly tip the rights-holders.
|
18 |
|
19 | It assumes that the wallet address that posted the Open Publish registration transaction to the Bitcoin blockchain is controlled by the owner of the registered media.
|
20 |
|
21 | Blockai cannot control what assets are registered on the Bitcoin blockchain so it is up to individual developers or development teams to make sure they honor their local rules and regulations pertaining to copyright. For example, Blockai will not display content that is deemed to not be owned by the claimant Bitcoin address, fully adhering to any DMCA notices.
|
22 |
|
23 | # Install
|
24 |
|
25 | `npm install openpublish`
|
26 |
|
27 | # Browser Usage
|
28 |
|
29 | In our examples we're going to use ```test-common-wallet``` to create our wallet.
|
30 |
|
31 | This simple wallet and the Open Publish API adhere to the [Common Wallet](https://github.com/blockai/abstract-common-wallet) standard.
|
32 |
|
33 | ## Bitcoin Wallet
|
34 |
|
35 | We will assume that this wallet is owned and operated by Alice.
|
36 |
|
37 | ```js
|
38 | var aliceWallet = testCommonWallet({
|
39 | seed: "some-random-very-long-and-super-safe-passphrase",
|
40 | network: "testnet",
|
41 | commonBlockchain: commonBlockchain
|
42 | });
|
43 | ```
|
44 |
|
45 | We'll need to provide an instance of a commonBlockchain which will provide functions for signing a transaction, propagating a trasnaction, and looking up a transaction by ```txid```.
|
46 |
|
47 | In this example we're using the in memory version that is provided by ```mem-common-blockchain```.
|
48 |
|
49 |
|
50 | ```javascript
|
51 | var commonBlockchain = require("mem-common-blockchain")({
|
52 | type: "local"
|
53 | });
|
54 |
|
55 | // or we could connect to testnet
|
56 |
|
57 | // commonBlockchain = require('blockcypher-unofficial')({
|
58 | // network: "testnet"
|
59 | // });
|
60 | ```
|
61 |
|
62 | ## Register Media with an Open Publish transaction posted to the Bitcoin network
|
63 |
|
64 | Hosting and distribution of content is not the goal of Open Publish although an optional link to the content can be part of the metadata.
|
65 |
|
66 | Files can be hosted on any existing web servers at the expense of the owner. A private service by Blockai called [Bitstore](https://github.com/blockai/bitstore-client) is a content-addressable file hosting and distribution service that uses Bitcoin public key infrastructure for authentication and payment. All files hosted on Bitstore are seeded on both BitTorrent and WebTorrent. As it uses Bitcoin wallets for authentication no account creation is necessary which makes it very convenient for application developers.
|
67 |
|
68 | In this example, Alice is using her wallet along with a file that she draged and dropped on to a web page.
|
69 |
|
70 | ```javascript
|
71 | var openpublish = require('openpublish');
|
72 |
|
73 | var file; // a browser File object returned from drop or file select form
|
74 | var fileUri; // a permalink to the above file
|
75 |
|
76 | openpublish.register({
|
77 | file: file,
|
78 | uri: fileUri,
|
79 | commonWallet: aliceWallet,
|
80 | commonBlockchain: commonBlockchain
|
81 | }, function(err, receipt) {
|
82 | var registerData = receipt.data;
|
83 | var sha1 = registerData.sha1; // the SHA-1 that represents your media file
|
84 | var blockcastTx = receipt.blockcastTx;
|
85 | var txid = blockcastTx.txid; // the Bitcoin transaction where the first payload of the the data is embedded
|
86 | var transactionTotal = blockcastTx.transactionTotal; // the number of Bitcoin transactions in the data payload
|
87 | });
|
88 | ```
|
89 |
|
90 | ## Transfering ownership of digital assets
|
91 |
|
92 | Open Publish allows for rights-holders to transfer partial ownership of the digital assets that represent their registered works, in a manner similar to how rights are transfered in music and book publishing.
|
93 |
|
94 | In this example, Alice's is transfering part ownership of her digital asset to her friend Bob.
|
95 |
|
96 | Alice started with 100,000,000 of total value in her asset when she first registered her media file.
|
97 |
|
98 | After this transaction has been signed by both wallets and cleared by the Bitcoin network, Alice will have 70,000,000 and Bob will have 30,000,000.
|
99 |
|
100 | Transfers are only valid for a set number of days before full ownership reverts back to Alice.
|
101 |
|
102 | ```js
|
103 | var bobWallet = testCommonWallet({
|
104 | seed: "another-random-very-long-and-super-safe-passphrase",
|
105 | network: "testnet",
|
106 | commonBlockchain: commonBlockchain
|
107 | });
|
108 |
|
109 | openpublish.transfer({
|
110 | assetValue: 30000000, // the number of assets that Alice is transfering
|
111 | bitcoinValue: 5000000, // the number of bitcoin that Bob is transfering
|
112 | ttl: 365, // the number of days that the transfer is valid for before reverting back to Alice
|
113 | sha1: registerData.sha1,
|
114 | assetWallet: aliceWallet,
|
115 | bitcoinWallet: bobWallet,
|
116 | commonBlockchain: commonBlockchain
|
117 | }, function(err, receipt) {
|
118 | var blockcastTx = receipt.blockcastTx;
|
119 | var txid = blockcastTx.txid; // the Bitcoin transaction where the first payload of the the data is embedded
|
120 | var transactionTotal = blockcastTx.transactionTotal; // the number of Bitcoin transactions in the data payload
|
121 | });
|
122 | });
|
123 | ```
|
124 |
|
125 | ## Public stream
|
126 |
|
127 | Open Publish transactions are native Bitcoin transactions. This means they are broadcast and stored on all nodes in the Bitcoin network. Anyone can freely stream, read, and write their own Open Publish transactions in same equal-access manner as native Bitcoin transactions. Open Publish takes advantage of the unique distributed yet single-source-of-truth nature of the Bitcoin blockchain.
|
128 |
|
129 | What this means is that neither Blockai nor any other private entity is required to register with Open Publish.
|
130 |
|
131 | ### Open Publish State
|
132 |
|
133 | Blockai runs and maintains it's own Open Publish state machine which can be query about the state of ownership for individual assets, to get a list of assets owned by a particular Bitcoin address, to see the tips associated with a particular asset or owner, and more.
|
134 |
|
135 | Check out the [```openpublish-state```](https://github.com/blockai/openpublish-state) for more info.
|
136 |
|
137 | ### Scanning without using Blockai's Open Publish State
|
138 |
|
139 | Here we're scanning for a list of Open Published documents for our wallet. During these early development stages Open Publish uses the [Blockcast](https://github.com/blockai/blockcast) protocol to embed data in the blockchain. As the protocol matures it will support additional small footprint formats.
|
140 |
|
141 | In this example we're querying the bitcoin blockchain for all of Alice's transactions and then scanning them one by one to look for all of her Open Publish registrations.
|
142 |
|
143 | ```javascript
|
144 | commonBlockchain.Addresses.Transactions([aliceWallet.address], function(err, addresses_transactions) {
|
145 | var transactions = addresses_transactions[0];
|
146 | var openPublishDocuments = [];
|
147 | transactions.forEach(function(tx) {
|
148 | blockcast.scanSingle({
|
149 | txid: tx.txid,
|
150 | commonBlockchain: commonBlockchain
|
151 | }, function(err, body) {
|
152 | if (!message) {
|
153 | return;
|
154 | }
|
155 | var data = JSON.parse(body);
|
156 | if (!data) {
|
157 | return;
|
158 | }
|
159 | if (data.op == "r") {
|
160 | openPublishDocuments.push(data);
|
161 | }
|
162 | });
|
163 | });
|
164 | });
|
165 | ```
|
166 |
|
167 | ## Tipping and Micropayments
|
168 |
|
169 | Open Publish comes with some very basic tipping functionalities. The tip will only be valid if the destination address matches the owner of the asset as registered on the blockchain.
|
170 |
|
171 | In this example, Alice found a really great photograph that is represented by the SHA-1 ```d1aef793e057364f8bd7a0344b4aa77be4aa7561```. She used ```openpublish-state``` to find out the wallet address of the rights-holder and then sent them a tip in bitcoin.
|
172 |
|
173 | ```js
|
174 | var sha1 = "d1aef793e057364f8bd7a0344b4aa77be4aa7561";
|
175 |
|
176 | openpublishState.findDoc({
|
177 | sha1: sha1
|
178 | }, function(err, openpublishDoc) {
|
179 | var tipDestinationAddress = openpublishDoc.sourceAddresses[0];
|
180 | openpublish.tip({
|
181 | destination: tipDestinationAddress,
|
182 | sha1: sha1,
|
183 | amount: 10000, // in satoshi
|
184 | commonWallet: aliceWallet,
|
185 | commonBlockchain: commonBlockchain
|
186 | }, function(error, tipTx) {
|
187 | var propagateResponse = tipTx.propagateResponse;
|
188 | var txid = tipTx.txid;
|
189 | });
|
190 | });
|
191 | ```
|