Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blockcast

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blockcast - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

src/simple-message.js

2

package.json
{
"name": "blockcast",
"version": "0.0.1",
"version": "0.0.2",
"description": "A decentralized messaging application protocol for publishing to the Bitcoin blockchain.",

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -6,2 +6,82 @@ blockcast

Posting a message
---
First, we'll need a Bitcoin private key and matching public address. Our public address can be thought of as our user ID. In order to post we'll need to make sure that our address has some Bitcoin.
In our examples we're going to use the helloblock test faucet to get our private key, public address and unspent outputs.
```javascript
var helloblock = require("helloblock-js")({
network: 'testnet'
});
helloblock.faucet.get(1, function(err, res, body) {
var privateKeyWIF = body.privateKeyWIF;
var address = body.address;
var unspentOutputs = body.unspents;
// ...
});
```
We'll need to provide a few of your own functions.
Signing a transaction:
```javascript
var signFromPrivateKeyWIF = function(privateKeyWIF) {
return function(tx, callback) {
var key = Bitcoin.ECKey.fromWIF(privateKeyWIF);
tx.sign(0, key);
callback(false, tx);
}
};
var signTransaction = signFromPrivateKeyWIF(privateKeyWIF);
```
Propagating a transaction:
```javascript
var propagateTransaction = function(tx, callback) {
helloblock.transactions.propagate(tx, function(err, res, body) {
callback(err, res);
});
};
```
And finally we're ready to post.
```javascript
blockcast.post({
data: "Hello, world!",
address: address,
unspentOutputs: unspentOutputs,
propagateTransaction: propagateTransaction,
signTransaction: signTransaction
}, function(error, response) {
console.log(response);
});
```
Scanning for messages
---
All we'll need is a list of Bitcoin transactions and we'll get back a list of messages and which public address they're from.
```javascript
helloblock.blocks.getTransactions(307068 , {limit: 100}, function(err, res, transactions) {
blockcast.scan({
transactions: transactions
}, function(err, messages) {
console.log(messages);
});
});
```
How does it work?
---
Messages are compressed using DEFLATE and then embedded across up to 16 Bitcoin transactions in OP_RETURN outputs along with custom headers for a total message size of 607 bytes.
Why build a decentralized messaging application?

@@ -12,3 +92,3 @@ ---

The incentive structures of crypto-currencies allow for users to control their own identities and data. Users must directly pay for the costs of broadcasting information.
The incentive structures of crypto-currencies allow for users to control their own identities and data.

@@ -34,3 +114,3 @@ Why Bitcoin?

Ultimately we feel that Bitcoin with sidechains are a better approach to crypto-currencies than having competing alt-coins.
Ultimately we feel that Bitcoin sidechains are a better approach to crypto-currencies than having competing alt-coins.

@@ -46,2 +126,2 @@ Building any application on top of Bitcoin creates an incentive to own Bitcoin.

We will put resources towards a Bitcoin sidechain specifically designed for decentralized messaging applications as soon as it becomes possible.
We will put resources towards a Bitcoin sidechain specifically designed for decentralized messaging applications as soon as it becomes possible.
var bitcoinTransactionBuilder = require("./bitcoin-transaction-builder");
var simpleMessage = require("./simple-message");
var dataPayload = require("./data-payload");

@@ -101,5 +102,31 @@

var simplePost = function(options, callback) {
var data = new Buffer(options.message);
var privateKeyWIF = options.privateKeyWIF;
var signTransaction = options.signTransaction;
var propagateTransaction = options.propagateTransaction;
var address = options.address;
var unspentOutputs = options.unspentOutputs;
simpleMessage.createSignedTransactionWithData({
data: data,
address: address,
unspentOutputs: unspentOutputs,
privateKeyWIF: privateKeyWIF,
signTransaction: signTransaction
}, function(err, signedTxHash) {
var propagateResponse = function(err, res) {
if (err) {
callback(err, "failure");
return;
}
callback(false, "success");
}
propagateTransaction(signedTxHash, propagateResponse);
});
};
module.exports = {
simplePost: simplePost,
post: post,
scan: scan
};

@@ -97,2 +97,32 @@ jasmine.getEnv().defaultTimeoutInterval = 50000;

it("should create and post a simplePost", function(done) {
var message = randomString(40);
helloblock.faucet.get(1, function(err, res, body) {
if (err) {
return done(err);
}
var privateKeyWIF = body.privateKeyWIF;
var address = body.address;
var unspentOutputs = body.unspents;
var signTransaction = signFromPrivateKeyWIF(privateKeyWIF);
blockcast.simplePost({
message: message,
address: address,
unspentOutputs: unspentOutputs,
propagateTransaction: propagateTransaction,
propagationStatus: propagationStatus,
signTransaction: signTransaction
}, function(error, response) {
expect(response).toBe('success');
done();
});
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc