UNPKG

5.21 kBMarkdownView Raw
1# Open Publish
2
3A publishing protocol for registering media as a digital asset on the Bitcoin blockchain.
4
5Open 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.
6
7Like BlockSign, digital media is represented as a cryptographic digest but in a content-addressable format that works seamlessly with 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.
8
9The 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.
10
11Any 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.
12
13For example, someone could write software that displays media with a consumer Bitcoin wallet allowing for people to easily and directly tip the rights-holders.
14
15It 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.
16
17# Install
18
19`npm install openpublish`
20
21# Browser Usage
22
23In our examples we're going to use ```bitcoinjs-lib``` to create our wallet.
24
25## Bitcoin Wallet
26
27```javascript
28var bitcoin = require("bitcoinjs-lib");
29
30var seed = bitcoin.crypto.sha256("test");
31var wallet = new bitcoin.Wallet(seed, bitcoin.networks.testnet);
32var address = wallet.generateAddress();
33
34var signRawTransaction = function(txHex, cb) {
35 var tx = bitcoin.Transaction.fromHex(txHex);
36 var signedTx = wallet.signWith(tx, [address]);
37 var txid = signedTx.getId();
38 var signedTxHex = signedTx.toHex();
39 cb(false, signedTxHex, txid);
40};
41
42var commonWallet = {
43 signRawTransaction: signRawTransaction,
44 address: address
45}
46```
47
48We'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```.
49
50In this example we're using the in memory version that is provided by ```mem-common-blockchain```.
51
52
53```javascript
54var commonBlockchain = require("mem-common-blockchain")({
55 type: "local"
56});
57
58// or we could connect to testnet
59
60// commonBlockchain = require('blockcypher-unofficial')({
61// network: "testnet"
62// });
63```
64
65## Register Media with an Open Publish transaction posted to the Bitcoin network
66
67Hosting and distribution of content is not the goal of Open Publish although an optional link to the content can be part of the metadata.
68
69Files 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.
70
71```javascript
72var openpublish = require('openpublish');
73
74var file; // a browser File object returned from drop or file select form
75var fileUri; // a permalink to the above file
76
77openpublish.register({
78 file: file,
79 uri: fileUri,
80 commonWallet: commonWallet,
81 commonBlockchain: commonBlockchain
82}, function(err, receipt) {
83 var blockcastTx = receipt.blockcastTx;
84 var txid = blockcastTx.txid; // the Bitcoin transaction where the first payload of the the data is embedded
85});
86```
87
88## Public stream
89
90Open 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.
91
92What this means is that neither Blockai nor any other private entity is required to register with Open Publish.
93
94Here we're scanning for a list of Open Published documents for our wallet. Open Publish uses the Blockcast protocol to embed data in the blockchain.
95
96```javascript
97commonBlockchain.Addresses.Transactions([commonWallet.address], function(err, addresses_transactions) {
98 var transactions = addresses_transactions[0];
99 var openPublishDocuments = [];
100 transactions.forEach(function(tx) {
101 blockcast.scanSingle({
102 txid: tx.txid,
103 commonBlockchain: commonBlockchain
104 }, function(err, message) {
105 if (!message) {
106 return;
107 }
108 var data = JSON.parse(message);
109 if (!data) {
110 return;
111 }
112 if (data.op == "r") {
113 openPublishDocuments.push(data);
114 }
115 });
116 });
117});
118```