Gordon Hall
11 years ago
34 changed files with 287 additions and 97 deletions
@ -1,11 +1,11 @@ |
|||
var imports = require('soop').imports(); |
|||
var base58 = imports.base58 || require('base58-native').base58; |
|||
var coinUtil = imports.coinUtil || require('./util/util'); |
|||
var coinUtil = imports.coinUtil || require('../util'); |
|||
var Key = imports.Key || require('./Key'); |
|||
var Point = imports.Point || require('./Point'); |
|||
var bignum = imports.bignum || require('bignum'); |
|||
var crypto = require('crypto'); |
|||
var networks = require('./networks'); |
|||
var networks = require('../networks'); |
|||
|
|||
var secp256k1_n = new bignum("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16); |
|||
var secp256k1_Gx = new bignum("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16); |
@ -1,20 +1,20 @@ |
|||
var imports = require('soop').imports(); |
|||
|
|||
var log = imports.log || require('./util/log'); |
|||
var log = imports.log || require('../util/log'); |
|||
|
|||
var MAX_RECEIVE_BUFFER = 10000000; |
|||
var PROTOCOL_VERSION = 70000; |
|||
|
|||
var Put = imports.Put || require('bufferput'); |
|||
var Buffers = imports.Buffers || require('buffers'); |
|||
require('./Buffers.monkey').patch(Buffers); |
|||
require('../patches/Buffers.monkey').patch(Buffers); |
|||
|
|||
var bitcoreDefaults = imports.config || require('./config'); |
|||
var networks = imports.networks || require('./networks'); |
|||
var bitcoreDefaults = imports.config || require('../config'); |
|||
var networks = imports.networks || require('../networks'); |
|||
var Block = imports.Block || require('./Block'); |
|||
var Transaction = imports.Transaction || require('./Transaction'); |
|||
var util = imports.util || require('./util/util'); |
|||
var Parser = imports.Parser || require('./util/BinaryParser'); |
|||
var util = imports.util || require('../util'); |
|||
var Parser = imports.Parser || require('../util/BinaryParser'); |
|||
var buffertools = imports.buffertools || require('buffertools'); |
|||
var doubleSha256 = imports.doubleSha256 || util.twoSha256; |
|||
var nonce = util.generateNonce(); |
@ -0,0 +1,42 @@ |
|||
'use strict'; |
|||
var imports = require('soop').imports(); |
|||
var coinUtil = imports.coinUtil || require('../util'); |
|||
var Key = imports.Key || require('./Key'); |
|||
|
|||
var Message = function() { |
|||
}; |
|||
|
|||
Message.sign = function(str, key) { |
|||
var hash = Message.magicHash(str); |
|||
var sig = key.signSync(hash); |
|||
return sig; |
|||
}; |
|||
|
|||
Message.verifyWithPubKey = function(pubkey, message, sig) { |
|||
var hash = Message.magicHash(message); |
|||
var key = new Key(); |
|||
if (pubkey.length == 65) |
|||
key.compressed = false; |
|||
key.public = pubkey; |
|||
|
|||
return key.verifySignatureSync(hash, sig); |
|||
}; |
|||
|
|||
//TODO: Message.verify ... with address, not pubkey
|
|||
|
|||
Message.magicBytes = new Buffer('Bitcoin Signed Message:\n'); |
|||
|
|||
Message.magicHash = function(str) { |
|||
var magicBytes = Message.magicBytes; |
|||
var prefix1 = coinUtil.varIntBuf(magicBytes.length); |
|||
var message = new Buffer(str); |
|||
var prefix2 = coinUtil.varIntBuf(message.length); |
|||
|
|||
var buf = Buffer.concat([prefix1, magicBytes, prefix2, message]); |
|||
|
|||
var hash = coinUtil.twoSha256(buf); |
|||
|
|||
return hash; |
|||
}; |
|||
|
|||
module.exports = require('soop')(Message); |
@ -1,7 +1,7 @@ |
|||
var imports = require('soop').imports(); |
|||
|
|||
var parent = imports.parent || require('./util/VersionedData'); |
|||
var networks= imports.networks || require('./networks'); |
|||
var parent = imports.parent || require('../util/VersionedData'); |
|||
var networks= imports.networks || require('../networks'); |
|||
|
|||
//compressed is true if public key is compressed; false otherwise
|
|||
function PrivateKey(version, buf, compressed) { |
@ -1,5 +1,5 @@ |
|||
var imports = require('soop').imports(); |
|||
var parent = imports.parent || require('./util/VersionedData'); |
|||
var parent = imports.parent || require('../util/VersionedData'); |
|||
|
|||
function SIN(type, payload) { |
|||
if (typeof type != 'number') { |
@ -1,5 +1,5 @@ |
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var coinUtil = require('../util'); |
|||
var timeUtil = require('../util/time'); |
|||
var Key = require('./Key'); |
|||
var SIN = require('./SIN'); |
|||
|
@ -1,11 +1,11 @@ |
|||
var imports = require('soop').imports(); |
|||
var config = imports.config || require('./config'); |
|||
var log = imports.log || require('./util/log'); |
|||
var util = imports.util || require('./util/util'); |
|||
var config = imports.config || require('../config'); |
|||
var log = imports.log || require('../util/log'); |
|||
var util = imports.util || require('../util'); |
|||
var Opcode = imports.Opcode || require('./Opcode'); |
|||
var buffertools = imports.buffertools || require('buffertools'); |
|||
var bignum = imports.bignum || require('bignum'); |
|||
var Util = imports.Util || require('./util/util'); |
|||
var Util = imports.Util || require('../util'); |
|||
var Script = require('./Script'); |
|||
var Key = require('./Key'); |
|||
|
@ -1,17 +1,17 @@ |
|||
var imports = require('soop').imports(); |
|||
var config = imports.config || require('./config'); |
|||
var log = imports.log || require('./util/log'); |
|||
var config = imports.config || require('../config'); |
|||
var log = imports.log || require('../util/log'); |
|||
var Address = imports.Address || require('./Address'); |
|||
var Script = imports.Script || require('./Script'); |
|||
var ScriptInterpreter = imports.ScriptInterpreter || require('./ScriptInterpreter'); |
|||
var util = imports.util || require('./util/util'); |
|||
var util = imports.util || require('../util'); |
|||
var bignum = imports.bignum || require('bignum'); |
|||
var Put = imports.Put || require('bufferput'); |
|||
var Parser = imports.Parser || require('./util/BinaryParser'); |
|||
var Parser = imports.Parser || require('../util/BinaryParser'); |
|||
var Step = imports.Step || require('step'); |
|||
var buffertools = imports.buffertools || require('buffertools'); |
|||
var error = imports.error || require('./util/error'); |
|||
var networks = imports.networks || require('./networks'); |
|||
var error = imports.error || require('../util/error'); |
|||
var networks = imports.networks || require('../networks'); |
|||
var WalletKey = imports.WalletKey || require('./WalletKey'); |
|||
var PrivateKey = imports.PrivateKey || require('./PrivateKey'); |
|||
|
@ -1,7 +1,7 @@ |
|||
var imports = require('soop').imports(); |
|||
|
|||
var coinUtil = require('./util/util'); |
|||
var timeUtil = require('./util/time'); |
|||
var coinUtil = require('../util'); |
|||
var timeUtil = require('../util/time'); |
|||
var Key = require('./Key'); |
|||
var PrivateKey = require('./PrivateKey'); |
|||
var Address = require('./Address'); |
@ -0,0 +1,57 @@ |
|||
'use strict'; |
|||
|
|||
var chai = chai || require('chai'); |
|||
var should = chai.should(); |
|||
var bitcore = bitcore || require('../bitcore'); |
|||
var Message = bitcore.Message; |
|||
var coinUtil = bitcore.util; |
|||
|
|||
describe('Message', function() { |
|||
describe('sign', function() { |
|||
it('should return a signature', function() { |
|||
var key = bitcore.Key.generateSync(); |
|||
var sig = Message.sign('my message', key); |
|||
sig.length.should.be.greaterThan(0); |
|||
}); |
|||
}); |
|||
|
|||
describe('verifyWithPubKey', function() { |
|||
it('should verify a signed message', function() { |
|||
var message = 'my message'; |
|||
var key = bitcore.Key.generateSync(); |
|||
var sig = Message.sign(message, key); |
|||
Message.verifyWithPubKey(key.public, message, sig).should.equal(true); |
|||
}); |
|||
}); |
|||
|
|||
describe('magicBytes', function() { |
|||
it('should be "Bitcoin Signed Message:\\n"', function() { |
|||
Message.magicBytes.toString().should.equal('Bitcoin Signed Message:\n'); |
|||
}); |
|||
}); |
|||
|
|||
describe('magicHash', function() { |
|||
it('should hash the message with the magic bytes', function() { |
|||
var str = 'my message'; |
|||
var magicBytes = Message.magicBytes; |
|||
var prefix1 = coinUtil.varIntBuf(magicBytes.length); |
|||
var message = new Buffer(str); |
|||
var prefix2 = coinUtil.varIntBuf(message.length); |
|||
|
|||
var buf = Buffer.concat([prefix1, magicBytes, prefix2, message]); |
|||
|
|||
var hash = coinUtil.twoSha256(buf); |
|||
|
|||
var hash2 = Message.magicHash(str); |
|||
|
|||
hash.toString().should.equal(hash2.toString()); |
|||
}); |
|||
|
|||
it('should hash this message the same way as bitcoinjs-lib', function() { |
|||
var hashHex = '74eacdc6c04724869380907bf4aab561a1494a4a800fba266b29b8158c2c4cec'; |
|||
|
|||
var str = 'this is a test message'; |
|||
hashHex.should.equal(Message.magicHash(str).toString('hex')); |
|||
}); |
|||
}); |
|||
}); |
@ -0,0 +1 @@ |
|||
module.exports = require('./util'); |
Loading…
Reference in new issue