-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcore.js
29 lines (24 loc) · 929 Bytes
/
core.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var bitcore = require('bitcore')
var blockchainjs = require('blockchainjs')
require('bitcore-message')
var Promise = require('bluebird')
var _ = require('lodash')
exports.computeMessageHash = function (message) {
return bitcore.crypto.Hash.sha256(new Buffer(message))
.toString('hex')
}
exports.computeStatement = function (messageHash, verb) {
return "sentiment:" + verb + ":" + messageHash
}
exports.verifySignature = function (address, signature, statement) {
return bitcore.Message(statement).verify(address, signature)
}
var connector = new blockchainjs.connector.Chromanode()
exports.connector = connector
exports.computeAddressBalance = function (address) {
return connector.addressesQuery([address], {status: 'unspent'})
.then(function (data) {
return _.sum(_.filter(data.unspent, 'height'),
function (unspent) { return parseInt(unspent.value) })
})
}