├── .gitignore ├── README.md ├── config.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | test.js 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bitproof for Node.js 2 | 3 | 4 | ### Installation 5 | 6 | You can install Bitproof with npm: 7 | 8 | ```sh 9 | $ npm install bitproof 10 | ``` 11 | 12 | ### Certify 13 | ```javascript 14 | // dependencies 15 | var Bitproof = require('bitproof'); 16 | 17 | // Find your API credentials in your Bitproof Dashboard 18 | var notary = new Bitproof(YOUR_API_KEY, YOUR_SECRET_KEY); 19 | 20 | // push some hex in the blockchain 21 | notary.push(HEX_UP_TO_40_BYTES, function(result) { 22 | console.log(result); 23 | }, function(err) { 24 | console.log(err); 25 | }); 26 | ``` 27 | 28 | ### Read a proof 29 | ```javascript 30 | // dependencies 31 | var Bitproof = require('bitproof'); 32 | 33 | // no API keys are needed for read only 34 | var notary = new Bitproof(); 35 | 36 | // read some hex in the blockchain 37 | var transactionId = 'e65a501b8caab14cea934e5aff06a82110ed152cc6c6d62a5b5146dc9dc21dae'; 38 | notary.read(transactionId, function(result) { 39 | console.log(result); 40 | }, function(err) { 41 | console.log(err); 42 | }); 43 | ``` 44 | 45 | **Applications using Bitproof for Node.js** 46 | 47 | - [Bitproof](https://bitproof.io/) 48 | - Contact us to be here 49 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | var base = 'https://api.bitproof.io/v1'; 2 | 3 | module.exports = { 4 | urls: { 5 | 'push': base + '/blockchain/push', 6 | 'read': base + '/blockchain/read' 7 | } 8 | }; -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * dependencies 3 | */ 4 | 5 | var request = require('request'), 6 | config = require('./config'); 7 | 8 | /*! 9 | * init 10 | */ 11 | 12 | function Bitproof(key, secret) { 13 | 14 | // Auth 15 | this.key = key; 16 | this.secret = secret; 17 | 18 | // we should test auth right now 19 | } 20 | 21 | /*! 22 | * get auth headers 23 | */ 24 | 25 | Bitproof.prototype.getAuthHeaders = function() { 26 | return { 27 | 'API_KEY': this.key, 28 | 'API_SECRET': this.secret 29 | }; 30 | } 31 | 32 | /*! 33 | * send hex to Bitproof 34 | */ 35 | 36 | Bitproof.prototype.push = function(hex, success, err) { 37 | // check routine could be done locally 38 | 39 | var options = { 40 | uri: config.urls.push, 41 | headers: this.getAuthHeaders(), 42 | method: 'POST', 43 | json: { 44 | "data": hex 45 | } 46 | }; 47 | request(options, function (error, response, body) { 48 | if (!error && response.statusCode == 200) { 49 | success(body); 50 | } else { 51 | err(error); 52 | } 53 | }); 54 | }; 55 | 56 | /*! 57 | * get hex from Bitproof 58 | */ 59 | 60 | Bitproof.prototype.read = function(txid, success, err) { 61 | // we could add options, such as output limits / include metadata 62 | 63 | var options = { 64 | uri: config.urls.read, 65 | method: 'GET', 66 | qs: { 67 | txid: txid 68 | } 69 | }; 70 | request(options, function (error, response, body) { 71 | if (!error && response.statusCode == 200) { 72 | success(body); 73 | } else { 74 | err(error); 75 | } 76 | }); 77 | }; 78 | 79 | module.exports = Bitproof; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitproof", 3 | "version": "1.0.0", 4 | "description": "Bitproof for Node.js", 5 | "main": "index.js", 6 | "dependencies": { 7 | "request": "^2.60.0" 8 | }, 9 | "devDependencies": {}, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/Bitproof-Inc/bitproof-node.git" 16 | }, 17 | "keywords": [ 18 | "Bitproof", 19 | "Blockchain", 20 | "Timestamping", 21 | "Bitcoin" 22 | ], 23 | "author": "Bitproof, Inc.", 24 | "license": "ISC", 25 | "bugs": { 26 | "url": "https://github.com/Bitproof-Inc/bitproof-node/issues" 27 | }, 28 | "homepage": "https://github.com/Bitproof-Inc/bitproof-node#readme" 29 | } 30 | --------------------------------------------------------------------------------