Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51c53b16ce | ||
|
|
29b11b1896 | ||
|
|
e20df21449 | ||
|
|
dc3f653fe2 | ||
|
|
a868ec0ef4 | ||
|
|
e2952b6e3a | ||
|
|
0d238f1165 | ||
|
|
28bb0f4cfc | ||
|
|
684c306833 | ||
|
|
722e2efeae | ||
|
|
100de8a9ba | ||
|
|
5d2d5ef024 | ||
|
|
0d58557cac | ||
|
|
26fb622cbe | ||
|
|
2ff90b7ab9 | ||
|
|
b1a7a9907c | ||
|
|
38b69f4bfc | ||
|
|
cd69983c31 | ||
|
|
bac81ce88e | ||
|
|
fe4bbf3d72 | ||
|
|
3e43d79b6e | ||
|
|
4984d81284 | ||
|
|
8c423d5cf1 | ||
|
|
9640cba354 | ||
|
|
ebbf6b4ef7 | ||
|
|
8b451f2bb5 | ||
|
|
b18ee9a49d | ||
|
|
f76b184e48 | ||
|
|
5986e9b887 | ||
|
|
9096fc4928 | ||
|
|
f21cb1d8b0 | ||
|
|
bf54f79856 | ||
|
|
21c5cff10d | ||
|
|
c996f08040 | ||
|
|
b5219c7805 | ||
|
|
c9c49da658 | ||
|
|
e154c205b3 | ||
|
|
c380e4698a | ||
|
|
50d36d5b30 | ||
|
|
66b11a565f | ||
|
|
acd86fdc43 | ||
|
|
586c8c0e20 | ||
|
|
f28d500b76 | ||
|
|
2fe70f9f52 | ||
|
|
c730eb5b3f | ||
|
|
df8e219a89 | ||
|
|
b0d1121165 | ||
|
|
fdea02e9a6 | ||
|
|
212fa1498e | ||
|
|
7f03d154dd | ||
|
|
98056209a9 | ||
|
|
693f2aac7b | ||
|
|
ba9ff424c2 | ||
|
|
29dcf56262 | ||
|
|
36c164cb30 |
@ -1 +1 @@
|
|||||||
repo_token: lBB0wwrjIH3RkwvTjkv8g5r4aUjcIUreC
|
repo_token: 92KyB69bPowWlcfgXqc24kE5Qt60cCPba
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,3 +11,4 @@ coverage
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
docs
|
docs
|
||||||
browser/bitcore-dev.js
|
browser/bitcore-dev.js
|
||||||
|
browser/testdata.js
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '0.10'
|
- '0.10.35'
|
||||||
notifications:
|
notifications:
|
||||||
hipchat:
|
hipchat:
|
||||||
rooms:
|
rooms:
|
||||||
|
|||||||
@ -104,7 +104,7 @@ node browser/build.js -a
|
|||||||
To generate a customized bitcore bundle, you can specify which submodules you want to include in it with the -s option:
|
To generate a customized bitcore bundle, you can specify which submodules you want to include in it with the -s option:
|
||||||
|
|
||||||
```
|
```
|
||||||
node browser/build.js -s Transaction,Address
|
node browser/build.js -s lib/Transaction,lib/Address
|
||||||
```
|
```
|
||||||
|
|
||||||
This will generate a `browser/bundle.js` containing only the Transaction and Address class, with all their dependencies. Use this option if you are not using the whole bitcore library, to optimize the bundle size, script loading time, and general resource usage.
|
This will generate a `browser/bundle.js` containing only the Transaction and Address class, with all their dependencies. Use this option if you are not using the whole bitcore library, to optimize the bundle size, script loading time, and general resource usage.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
5960
browser/testdata.js
5960
browser/testdata.js
File diff suppressed because one or more lines are too long
553
examples.md
553
examples.md
@ -1,8 +1,11 @@
|
|||||||
#Address.js
|
#Address.js
|
||||||
'use strict';
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
@ -21,87 +24,95 @@
|
|||||||
console.log(addr.data + ' is ' + (valid ? '' : 'not ') + 'valid');
|
console.log(addr.data + ' is ' + (valid ? '' : 'not ') + 'valid');
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#Armory.js
|
#Armory.js
|
||||||
var Armory = require('../lib/Armory');
|
|
||||||
var Address = require('../lib/Address');
|
|
||||||
|
|
||||||
// Initial public key can be retrieved from paper backup
|
```js
|
||||||
|
|
||||||
var PublicX = '9df5 23e7 18b9 1f59 a790 2d46 999f 9357 ccf8 7208 24d4 3076 4516 b809 f7ab ce4e';
|
var Armory = require('../lib/Armory');
|
||||||
var PublicY = '66ba 5d21 4682 0dae 401d 9506 8437 2516 79f9 0c56 4186 cc50 07df c6d0 6989 1ff4';
|
var Address = require('../lib/Address');
|
||||||
var pubkey = '04' + PublicX.split(' ').join('') + PublicY.split(' ').join('');
|
|
||||||
|
|
||||||
// Chain code can be generated by entering paper backup
|
// Initial public key can be retrieved from paper backup
|
||||||
// on brainwallet.org/#chains or by using Armory.fromSeed() below
|
|
||||||
|
|
||||||
var chaincode = '84ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
|
var PublicX = '9df5 23e7 18b9 1f59 a790 2d46 999f 9357 ccf8 7208 24d4 3076 4516 b809 f7ab ce4e';
|
||||||
|
var PublicY = '66ba 5d21 4682 0dae 401d 9506 8437 2516 79f9 0c56 4186 cc50 07df c6d0 6989 1ff4';
|
||||||
|
var pubkey = '04' + PublicX.split(' ').join('') + PublicY.split(' ').join('');
|
||||||
|
|
||||||
var armory = new Armory(chaincode, pubkey);
|
// Chain code can be generated by entering paper backup
|
||||||
|
// on brainwallet.org/#chains or by using Armory.fromSeed() below
|
||||||
|
|
||||||
console.log('Deriving public keys for');
|
var chaincode = '84ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
|
||||||
console.log('------------------------');
|
|
||||||
console.log('Chain code: %s', chaincode);
|
|
||||||
console.log('Public key: %s', pubkey);
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
var armory = new Armory(chaincode, pubkey);
|
||||||
|
|
||||||
|
console.log('Deriving public keys for');
|
||||||
|
console.log('------------------------');
|
||||||
|
console.log('Chain code: %s', chaincode);
|
||||||
|
console.log('Public key: %s', pubkey);
|
||||||
|
console.log('');
|
||||||
|
|
||||||
|
for (var i = 0; i < 5; i++) {
|
||||||
console.log(Address.fromPubKey(armory.pubkey).as('base58'));
|
console.log(Address.fromPubKey(armory.pubkey).as('base58'));
|
||||||
armory = armory.next();
|
armory = armory.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive first public key and chain code from seed
|
// Derive first public key and chain code from seed
|
||||||
var seed = [
|
var seed = [
|
||||||
'aagh hjfj sihk ietj giik wwai awtd uodh hnji',
|
'aagh hjfj sihk ietj giik wwai awtd uodh hnji',
|
||||||
'soss uaku egod utai itos fijj ihgi jhau jtoo'
|
'soss uaku egod utai itos fijj ihgi jhau jtoo'
|
||||||
];
|
];
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Deriving public keys for');
|
console.log('Deriving public keys for');
|
||||||
console.log('------------------------');
|
console.log('------------------------');
|
||||||
console.log('Seed: %s', seed.join(' '));
|
console.log('Seed: %s', seed.join(' '));
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
// skip first public key
|
// skip first public key
|
||||||
var a = Armory.fromSeed(seed.join('\n')).next();
|
var a = Armory.fromSeed(seed.join('\n')).next();
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
console.log(Address.fromPubKey(a.pubkey).as('base58'));
|
console.log(Address.fromPubKey(a.pubkey).as('base58'));
|
||||||
a = a.next();
|
a = a.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var mpk = '045a09a3286873a72f164476bde9d1d8e5c2bc044e35aa47eb6e798e325a86417f7c35b61d9905053533e0b4f2a26eca0330aadf21c638969e45aaace50e4c0c8784ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
|
var mpk = '045a09a3286873a72f164476bde9d1d8e5c2bc044e35aa47eb6e798e325a86417f7c35b61d9905053533e0b4f2a26eca0330aadf21c638969e45aaace50e4c0c8784ac14bc4b388b33da099a0b4ee3b507284d99e1476639e36e5ca5e6af86481e';
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Deriving public keys for');
|
console.log('Deriving public keys for');
|
||||||
console.log('------------------------');
|
console.log('------------------------');
|
||||||
console.log('Master Public Key: %s', mpk);
|
console.log('Master Public Key: %s', mpk);
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|
||||||
// skip first public key
|
// skip first public key
|
||||||
var b = Armory.fromMasterPublicKey(mpk).next();
|
var b = Armory.fromMasterPublicKey(mpk).next();
|
||||||
|
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
||||||
b = b.next();
|
b = b.next();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#ConnectionTor.js
|
#ConnectionTor.js
|
||||||
var Peer = require('../lib/Peer');
|
|
||||||
var Connection = require('../lib/Connection');
|
|
||||||
var dns = require('dns');
|
|
||||||
|
|
||||||
// get a peer from dns seed
|
```js
|
||||||
dns.resolve('dnsseed.bluematt.me', function(err, seeds) {
|
|
||||||
|
var Peer = require('../lib/Peer');
|
||||||
|
var Connection = require('../lib/Connection');
|
||||||
|
var dns = require('dns');
|
||||||
|
|
||||||
|
// get a peer from dns seed
|
||||||
|
dns.resolve('dnsseed.bluematt.me', function(err, seeds) {
|
||||||
// use the first peer
|
// use the first peer
|
||||||
var peer = new Peer(seeds[0], 8333);
|
var peer = new Peer(seeds[0], 8333);
|
||||||
|
|
||||||
@ -132,10 +143,14 @@
|
|||||||
//console.log(err);
|
//console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-Multisig.js
|
#CreateAndSignTx-Multisig.js
|
||||||
var run = function() {
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
@ -155,6 +170,7 @@
|
|||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1396288753,
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.4296,
|
amount: 0.4296,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
@ -204,6 +220,7 @@
|
|||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
ts: 1396288753,
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
@ -228,22 +245,26 @@
|
|||||||
|
|
||||||
console.log('[this example originally generated TXID: 1eb388977b2de99562eb0fbcc661a100eaffed99c53bfcfebe5a087002039b83 on testnet]\n\n\thttp://test.bitcore.io/tx/1eb388977b2de99562eb0fbcc661a100eaffed99c53bfcfebe5a087002039b83');
|
console.log('[this example originally generated TXID: 1eb388977b2de99562eb0fbcc661a100eaffed99c53bfcfebe5a087002039b83 on testnet]\n\n\thttp://test.bitcore.io/tx/1eb388977b2de99562eb0fbcc661a100eaffed99c53bfcfebe5a087002039b83');
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is just for browser & mocha compatibility
|
// This is just for browser & mocha compatibility
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-PayToPubkeyHash.js
|
#CreateAndSignTx-PayToPubkeyHash.js
|
||||||
var run = function() {
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
|
|
||||||
var priv = 'cTgGUrcro89yUtKeG6gHBAS14r3qp25KwTTxG9d4kEzcFxecuZDm';
|
var priv = 'cTgGUrcro89yUtKeG6gHBAS14r3qp25KwTTxG9d4kEzcFxecuZDm';
|
||||||
@ -255,6 +276,7 @@
|
|||||||
address: "mqSjTad2TKbPcKQ3Jq4kgCkKatyN44UMgZ",
|
address: "mqSjTad2TKbPcKQ3Jq4kgCkKatyN44UMgZ",
|
||||||
txid: "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
txid: "2ac165fa7a3a2b535d106a0041c7568d03b531e58aeccdd3199d7289ab12cfc1",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1394719301,
|
||||||
scriptPubKey: "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ac",
|
scriptPubKey: "76a9146ce4e1163eb18939b1440c42844d5f0261c0338288ac",
|
||||||
amount: 0.01,
|
amount: 0.01,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
@ -302,22 +324,26 @@
|
|||||||
|
|
||||||
var txHex = tx.serialize().toString('hex');
|
var txHex = tx.serialize().toString('hex');
|
||||||
console.log('TX HEX IS: ', txHex);
|
console.log('TX HEX IS: ', txHex);
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is just for browser & mocha compatibility
|
// This is just for browser & mocha compatibility
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
```
|
||||||
|
|
||||||
#CreateAndSignTx-PayToScriptHash.js
|
#CreateAndSignTx-PayToScriptHash.js
|
||||||
var run = function() {
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
@ -338,6 +364,7 @@
|
|||||||
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
ts: 1396290442,
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.3795,
|
amount: 0.3795,
|
||||||
confirmations: 7
|
confirmations: 7
|
||||||
@ -402,6 +429,7 @@
|
|||||||
address: p2shAddress,
|
address: p2shAddress,
|
||||||
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
ts: 1396375187,
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 1
|
confirmations: 1
|
||||||
@ -451,28 +479,32 @@
|
|||||||
console.log('ret', ret); //TODO
|
console.log('ret', ret); //TODO
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// This is just for browser & mocha compatibility
|
// This is just for browser & mocha compatibility
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#CreateKey.js
|
#CreateKey.js
|
||||||
'use strict';
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
@ -510,17 +542,21 @@
|
|||||||
print(wk2);
|
print(wk2);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#CreateScript.js
|
#CreateScript.js
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var run = function() {
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
@ -588,15 +624,19 @@
|
|||||||
var a = new Address(networks.livenet.P2SHVersion, hash);
|
var a = new Address(networks.livenet.P2SHVersion, hash);
|
||||||
p('\tp2sh Addr: ' + a.toString());
|
p('\tp2sh Addr: ' + a.toString());
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#ECIES.js
|
#ECIES.js
|
||||||
var run = function() {
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
|
|
||||||
console.log('ECIES: Elliptic Curve Integrated Encryption Scheme');
|
console.log('ECIES: Elliptic Curve Integrated Encryption Scheme');
|
||||||
@ -614,34 +654,42 @@
|
|||||||
|
|
||||||
var decrypted = bitcore.ECIES.decrypt(key.private, encrypted);
|
var decrypted = bitcore.ECIES.decrypt(key.private, encrypted);
|
||||||
console.log('Decrypted (with private key): "' + decrypted.toString() + '"');
|
console.log('Decrypted (with private key): "' + decrypted.toString() + '"');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// This is just for browser & mocha compatibility
|
// This is just for browser & mocha compatibility
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#ElectrumMPK.js
|
#ElectrumMPK.js
|
||||||
var Electrum = require('../lib/Electrum');
|
|
||||||
var Address = require('../lib/Address');
|
|
||||||
|
|
||||||
var mpk = '92eea4d2f5263651db9e3222caded1fd4c89772f79a7c03fb6afc00e9d2c9d2ed9b86c2c95fc1171e49163079dacb7f048b3c509a27a490e1df9e7128362d468';
|
```js
|
||||||
|
|
||||||
mpk = new Electrum(mpk);
|
var Electrum = require('../lib/Electrum');
|
||||||
|
var Address = require('../lib/Address');
|
||||||
|
|
||||||
var key0 = mpk.generatePubKey(0);
|
var mpk = '92eea4d2f5263651db9e3222caded1fd4c89772f79a7c03fb6afc00e9d2c9d2ed9b86c2c95fc1171e49163079dacb7f048b3c509a27a490e1df9e7128362d468';
|
||||||
var addr0 = Address.fromPubKey(key0);
|
|
||||||
|
|
||||||
console.log(addr0.as('base58'));
|
mpk = new Electrum(mpk);
|
||||||
|
|
||||||
|
var key0 = mpk.generatePubKey(0);
|
||||||
|
var addr0 = Address.fromPubKey(key0);
|
||||||
|
|
||||||
|
console.log(addr0.as('base58'));
|
||||||
|
```
|
||||||
|
|
||||||
#HierarchicalKey.js
|
#HierarchicalKey.js
|
||||||
var run = function() {
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
var HierarchicalKey = bitcore.HierarchicalKey;
|
var HierarchicalKey = bitcore.HierarchicalKey;
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
@ -712,50 +760,123 @@
|
|||||||
console.log('m/100 address: ' + Address.fromPubKey(hkey.derive('m/100').eckey.public).toString());
|
console.log('m/100 address: ' + Address.fromPubKey(hkey.derive('m/100').eckey.public).toString());
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// This is just for browser & mocha compatibility
|
// This is just for browser & mocha compatibility
|
||||||
if (typeof module !== 'undefined') {
|
if (typeof module !== 'undefined') {
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#PayToScriptHashAddress.js
|
#NetworkMonitor.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var NetworkMonitor = bitcore.NetworkMonitor;
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
networkName: 'testnet',
|
||||||
|
host: 'localhost',
|
||||||
|
port: 18333
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var nm = new NetworkMonitor.create(config);
|
||||||
|
// monitor incoming transactions to http://tpfaucet.appspot.com/ donation address
|
||||||
|
nm.incoming('msj42CCGruhRsFrGATiUuh25dtxYtnpbTx', function(tx) {
|
||||||
|
console.log('Donation to tpfaucet! '+JSON.stringify(tx.getStandardizedObject()));
|
||||||
|
});
|
||||||
|
|
||||||
|
// connect to bitcoin network and start listening
|
||||||
|
nm.start();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#Opreturn.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
var bitcoreUtil = bitcore.util;
|
var coinUtil = bitcore.util;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
var network = bitcore.networks.livenet;
|
var network = bitcore.networks.testnet;
|
||||||
|
|
||||||
|
var script = 'OP_RETURN 58434c524e4748530000000000000000000000010000000005f5e100';
|
||||||
var script = ''; // write down your script here
|
|
||||||
var s = Script.fromHumanReadable(script);
|
var s = Script.fromHumanReadable(script);
|
||||||
var hash = bitcoreUtil.sha256ripe160(s.getBuffer());
|
var result = (s.classify() == Script.TX_RETURN)
|
||||||
var version = network.addressScript;
|
console.log("Is op_return:", result);
|
||||||
|
};
|
||||||
|
|
||||||
var addr = new Address(version, hash);
|
module.exports.run = run;
|
||||||
var addrStr = addr.as('base58');
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
// This outputs the "address" of thescript
|
#PayToScriptHashAddress.js
|
||||||
console.log(addrStr);
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var bitcoreUtil = bitcore.util;
|
||||||
|
var Script = bitcore.Script;
|
||||||
|
var network = bitcore.networks.livenet;
|
||||||
|
|
||||||
|
|
||||||
|
var script = ''; // write down your script here
|
||||||
|
var s = Script.fromHumanReadable(script);
|
||||||
|
var hash = bitcoreUtil.sha256ripe160(s.getBuffer());
|
||||||
|
var version = network.addressScript;
|
||||||
|
|
||||||
|
var addr = new Address(version, hash);
|
||||||
|
var addrStr = addr.as('base58');
|
||||||
|
|
||||||
|
// This outputs the "address" of thescript
|
||||||
|
console.log(addrStr);
|
||||||
|
```
|
||||||
|
|
||||||
#PeerDiscovery.js
|
#PeerDiscovery.js
|
||||||
var PeerManager = require('../lib/PeerManager');
|
|
||||||
var peerman = new PeerManager();
|
|
||||||
|
|
||||||
peerman.discover({
|
```js
|
||||||
|
|
||||||
|
var PeerManager = require('../lib/PeerManager');
|
||||||
|
var peerman = new PeerManager();
|
||||||
|
|
||||||
|
peerman.discover({
|
||||||
limit: 12
|
limit: 12
|
||||||
}).start();
|
}).start();
|
||||||
|
```
|
||||||
|
|
||||||
#PeerManager.js
|
#PeerManager.js
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var run = function() {
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Peer = bitcore.Peer;
|
var Peer = bitcore.Peer;
|
||||||
@ -794,17 +915,21 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
peerman.start();
|
peerman.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#Rpc.js
|
#Rpc.js
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var run = function() {
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var RpcClient = bitcore.RpcClient;
|
var RpcClient = bitcore.RpcClient;
|
||||||
@ -828,17 +953,21 @@
|
|||||||
}
|
}
|
||||||
console.log(ret);
|
console.log(ret);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#Script.js
|
#Script.js
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var run = function() {
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
@ -882,17 +1011,69 @@
|
|||||||
var script = 'DUP HASH160 0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUALVERIFY CHECKSIG';
|
var script = 'DUP HASH160 0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUALVERIFY CHECKSIG';
|
||||||
var s = Script.fromHumanReadable(script);
|
var s = Script.fromHumanReadable(script);
|
||||||
console.log(getAddrStr(s)[0]); // mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT
|
console.log(getAddrStr(s)[0]); // mkZBYBiq6DNoQEKakpMJegyDbw2YiNQnHT
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#ScriptInterpreter.js
|
||||||
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
|
var bitcore = require('../bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var coinUtil = bitcore.util;
|
||||||
|
var Script = bitcore.Script;
|
||||||
|
var ScriptInterpreter = bitcore.ScriptInterpreter;
|
||||||
|
var network = bitcore.networks.testnet;
|
||||||
|
|
||||||
|
|
||||||
|
// using "static" method
|
||||||
|
var scriptPubKeyHR = '0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71 EQUAL';
|
||||||
|
var scriptPubKey = Script.fromHumanReadable(scriptPubKeyHR);
|
||||||
|
|
||||||
|
var scriptSigHR = '0x14 0x3744841e13b90b4aca16fe793a7f88da3a23cc71';
|
||||||
|
var scriptSig = Script.fromHumanReadable(scriptSigHR);
|
||||||
|
|
||||||
|
ScriptInterpreter.verifyFull(scriptSig, scriptPubKey, undefined, undefined,
|
||||||
|
undefined, undefined, function(err, result) {
|
||||||
|
console.log('script verified successfully? ', result)
|
||||||
|
});
|
||||||
|
|
||||||
|
// using an instance
|
||||||
|
scriptPubKeyHR = '0x26 0x554e5a49500370e53982a1d5201829562c5d9eebf256eb755b92c9b1449afd99f9f8c3265631 DROP HASH256 0x20 0x34b4f6042e1bcfc6182ee2727a3d0069a9071385bc07b318f57e77a28ffa13ac EQUAL';
|
||||||
|
scriptPubKey = Script.fromHumanReadable(scriptPubKeyHR);
|
||||||
|
|
||||||
|
scriptSigHR = '0x41 0x0470e53982a1d5201829562c5d9eebf256eb755b92c9b1449afd99f9f8c3265631142f3bf6954e3bec4bdad1a1a197bf90904a1e6f06c209eb477e2fde00d26691';
|
||||||
|
scriptSig = Script.fromHumanReadable(scriptSigHR);
|
||||||
|
|
||||||
|
var si = new ScriptInterpreter();
|
||||||
|
si.verifyFull(scriptSig, scriptPubKey, undefined, undefined,
|
||||||
|
undefined, function(err, result) {
|
||||||
|
console.log('script verified successfully? ', result)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.run = run;
|
||||||
|
if (require.main === module) {
|
||||||
|
run();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#SendTx.js
|
#SendTx.js
|
||||||
'use strict';
|
|
||||||
|
|
||||||
var run = function() {
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Peer = bitcore.Peer;
|
var Peer = bitcore.Peer;
|
||||||
@ -991,54 +1172,58 @@
|
|||||||
|
|
||||||
peerman.start();
|
peerman.start();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
#SimpleP2Pmonitor.js
|
#SimpleP2Pmonitor.js
|
||||||
/**
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
/**
|
||||||
* This is a simple script that will display network messages.
|
* This is a simple script that will display network messages.
|
||||||
* It users the Peer / Connection classes directly instead of
|
* It users the Peer / Connection classes directly instead of
|
||||||
* relying on PeerManager.
|
* relying on PeerManager.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// replace by require('bitcore') if you use somewhere else
|
// replace by require('bitcore') if you use somewhere else
|
||||||
var bitcore = require('../');
|
var bitcore = require('../');
|
||||||
|
|
||||||
//bitcore.config.logger = 'debug';
|
//bitcore.config.logger = 'debug';
|
||||||
|
|
||||||
var Peer = bitcore.Peer,
|
var Peer = bitcore.Peer,
|
||||||
Connection = bitcore.Connection;
|
Connection = bitcore.Connection;
|
||||||
|
|
||||||
var peer = new Peer('127.0.0.1', 8333);
|
var peer = new Peer('127.0.0.1', 8333);
|
||||||
|
|
||||||
var socket = peer.createConnection();
|
var socket = peer.createConnection();
|
||||||
|
|
||||||
var con = new Connection(socket, peer);
|
var con = new Connection(socket, peer);
|
||||||
|
|
||||||
con.on('error', function(msg) {
|
con.on('error', function(msg) {
|
||||||
var peer = msg.peer,
|
var peer = msg.peer,
|
||||||
err = msg.err;
|
err = msg.err;
|
||||||
console.error('Error connecting to peer', peer.host + ':' + peer.port, '(' + err.message + ')');
|
console.error('Error connecting to peer', peer.host + ':' + peer.port, '(' + err.message + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
con.on('disconnect', function(msg) {
|
con.on('disconnect', function(msg) {
|
||||||
console.log('disconnect: ', msg);
|
console.log('disconnect: ', msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
con.on('connect', function(msg) {
|
con.on('connect', function(msg) {
|
||||||
console.log('Connected to %s', msg.peer.host + ':' + msg.peer.port);
|
console.log('Connected to %s', msg.peer.host + ':' + msg.peer.port);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Listen P2P messages */
|
/* Listen P2P messages */
|
||||||
|
|
||||||
// Make a log function available to all listeners
|
// Make a log function available to all listeners
|
||||||
// The log function is just like console.log except it prefixes
|
// The log function is just like console.log except it prefixes
|
||||||
// messages with [host:port]
|
// messages with [host:port]
|
||||||
function listen(event_name, fn) {
|
function listen(event_name, fn) {
|
||||||
con.on(event_name, function(event) {
|
con.on(event_name, function(event) {
|
||||||
fn(event, function() {
|
fn(event, function() {
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
@ -1048,35 +1233,39 @@
|
|||||||
console.log.apply(console, args);
|
console.log.apply(console, args);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
listen('getaddr', function(event, log) {
|
listen('getaddr', function(event, log) {
|
||||||
log('Received message getaddr');
|
log('Received message getaddr');
|
||||||
log(event);
|
log(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
listen('verack', function(event, log) {
|
listen('verack', function(event, log) {
|
||||||
log('Received message verack');
|
log('Received message verack');
|
||||||
});
|
});
|
||||||
|
|
||||||
listen('version', function(event, log) {
|
listen('version', function(event, log) {
|
||||||
log('Received message version (%s)', event.message.version);
|
log('Received message version (%s)', event.message.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
listen('addr', function(event, log) {
|
listen('addr', function(event, log) {
|
||||||
log('Received message addr (%s addresses)', event.message.addrs.length);
|
log('Received message addr (%s addresses)', event.message.addrs.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
listen('inv', function(event, log) {
|
listen('inv', function(event, log) {
|
||||||
log('Received message inv (%s invs)', event.message.count);
|
log('Received message inv (%s invs)', event.message.count);
|
||||||
console.log(event.message.invs);
|
console.log(event.message.invs);
|
||||||
});
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#VanityAddress.js
|
#VanityAddress.js
|
||||||
'use strict';
|
|
||||||
|
```js
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
// Replace '../bitcore' with 'bitcore' if you use this code elsewhere.
|
||||||
var bitcore = require('../bitcore');
|
var bitcore = require('../bitcore');
|
||||||
var Key = bitcore.Key;
|
var Key = bitcore.Key;
|
||||||
@ -1095,10 +1284,10 @@
|
|||||||
console.log('Address: ' + a.toString());
|
console.log('Address: ' + a.toString());
|
||||||
console.log('Private Key: ' + k.private.toString('hex'));
|
console.log('Private Key: ' + k.private.toString('hex'));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.run = run;
|
module.exports.run = run;
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|||||||
22
examples/browser/ECIES.html
Normal file
22
examples/browser/ECIES.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<script src="../../browser/bundle.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
var Buffer = bitcore.Buffer;
|
||||||
|
console.log('ECIES: Elliptic Curve Integrated Encryption Scheme');
|
||||||
|
console.log('A way of encrypting with a public key and decrypting with a private key.');
|
||||||
|
var key = bitcore.Key.generateSync();
|
||||||
|
console.log('Private key: ' + key.private.toString('hex'));
|
||||||
|
console.log('Public key: ' + key.public.toString('hex'));
|
||||||
|
var message = new Buffer('This is a message to be encrypt');
|
||||||
|
console.log('Message: "' + message.toString() + '"');
|
||||||
|
var encrypted = bitcore.ECIES.encrypt(key.public, message);
|
||||||
|
console.log('Encrypted (with public key): ' + encrypted.toString('hex'));
|
||||||
|
var decrypted = bitcore.ECIES.decrypt(key.private, encrypted);
|
||||||
|
console.log('Decrypted (with private key): "' + decrypted.toString() + '"');
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
</html>
|
||||||
@ -9,7 +9,7 @@ var format = es.through(
|
|||||||
if (file.isStream()) return this.emit('error', new Error('Streaming not supported'));
|
if (file.isStream()) return this.emit('error', new Error('Streaming not supported'));
|
||||||
|
|
||||||
//add indentation
|
//add indentation
|
||||||
var contents = "\t" + file.contents.toString("utf8").split("\n").join("\n\t");
|
var contents = "\n```js\n\n" + file.contents.toString("utf8").split("\n").join("\n") + "```\n";
|
||||||
//add header
|
//add header
|
||||||
contents = ["#", path.basename(file.path), "\n", contents].join("");
|
contents = ["#", path.basename(file.path), "\n", contents].join("");
|
||||||
file.contents = new Buffer(contents, "utf8");
|
file.contents = new Buffer(contents, "utf8");
|
||||||
|
|||||||
@ -189,7 +189,13 @@ Address.fromPubkeyHashScriptSig = function(scriptSig, network) {
|
|||||||
//extract an address from scriptSig
|
//extract an address from scriptSig
|
||||||
Address.fromScriptSig = function(scriptSig, network) {
|
Address.fromScriptSig = function(scriptSig, network) {
|
||||||
if (typeof scriptSig === 'string') {
|
if (typeof scriptSig === 'string') {
|
||||||
scriptSig = new Script(new Buffer(scriptSig, 'hex'));
|
try {
|
||||||
|
var scriptSigBuf = new Buffer(scriptSig, 'hex')
|
||||||
|
} catch(err) {
|
||||||
|
// Error: Invalid public key
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
scriptSig = new Script(scriptSigBuf);
|
||||||
}
|
}
|
||||||
if (!network)
|
if (!network)
|
||||||
network = 'livenet';
|
network = 'livenet';
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
var util = require('../util');
|
var util = require('../util');
|
||||||
var Script = require('./Script');
|
var Script = require('./Script');
|
||||||
var Bignum = require('bignum');
|
var Bignum = require('bignum');
|
||||||
var Binary = require('binary');
|
|
||||||
var Step = require('step');
|
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
var Transaction = require('./Transaction');
|
var Transaction = require('./Transaction');
|
||||||
var TransactionIn = Transaction.In;
|
var TransactionIn = Transaction.In;
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var Net = require('net');
|
var Net = require('net');
|
||||||
var Binary = require('binary');
|
var Put = require('bufferput');
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
|
|
||||||
function Peer(host, port, services) {
|
function Peer(host, port, services) {
|
||||||
@ -45,7 +45,7 @@ Peer.prototype.toString = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Peer.prototype.toBuffer = function() {
|
Peer.prototype.toBuffer = function() {
|
||||||
var put = Binary.put();
|
var put = new Put();
|
||||||
put.word32le(this.lastSeen);
|
put.word32le(this.lastSeen);
|
||||||
put.word64le(this.services);
|
put.word64le(this.services);
|
||||||
put.put(this.getHostAsBuffer());
|
put.put(this.getHostAsBuffer());
|
||||||
|
|||||||
@ -15,6 +15,7 @@ function RpcClient(opts) {
|
|||||||
this.protocol = (opts.protocol == 'http') ? http : https;
|
this.protocol = (opts.protocol == 'http') ? http : https;
|
||||||
this.batchedCalls = null;
|
this.batchedCalls = null;
|
||||||
this.disableAgent = opts.disableAgent || false;
|
this.disableAgent = opts.disableAgent || false;
|
||||||
|
this.rejectUnauthorized = opts.rejectUnauthorized || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcClient.prototype.batch = function(batchCallback, resultCallback) {
|
RpcClient.prototype.batch = function(batchCallback, resultCallback) {
|
||||||
@ -33,6 +34,7 @@ var callspec = {
|
|||||||
decodeRawTransaction: '',
|
decodeRawTransaction: '',
|
||||||
dumpPrivKey: '',
|
dumpPrivKey: '',
|
||||||
encryptWallet: '',
|
encryptWallet: '',
|
||||||
|
estimateFee: 'int',
|
||||||
getAccount: '',
|
getAccount: '',
|
||||||
getAccountAddress: 'str',
|
getAccountAddress: 'str',
|
||||||
getAddedNodeInfo: '',
|
getAddedNodeInfo: '',
|
||||||
@ -163,6 +165,7 @@ function rpc(request, callback) {
|
|||||||
path: '/',
|
path: '/',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
port: self.port,
|
port: self.port,
|
||||||
|
rejectUnauthorized: self.rejectUnauthorized,
|
||||||
agent: self.disableAgent ? false : undefined,
|
agent: self.disableAgent ? false : undefined,
|
||||||
};
|
};
|
||||||
if (self.httpOptions) {
|
if (self.httpOptions) {
|
||||||
@ -204,7 +207,7 @@ function rpc(request, callback) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
req.on('error', function(e) {
|
req.on('error', function(e) {
|
||||||
var err = new Error('Could not connect to bitcoin via RPC: ' + e.message);
|
var err = new Error('Could not connect to bitcoin via RPC at host: ' + self.host + ' port: ' + self.port + ' Error: ' + e.message);
|
||||||
log.err(err);
|
log.err(err);
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,7 +7,6 @@ var util = require('../util');
|
|||||||
var bignum = require('bignum');
|
var bignum = require('bignum');
|
||||||
var Put = require('bufferput');
|
var Put = require('bufferput');
|
||||||
var Parser = require('../util/BinaryParser');
|
var Parser = require('../util/BinaryParser');
|
||||||
var Step = require('step');
|
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
var error = require('../util/error');
|
var error = require('../util/error');
|
||||||
var WalletKey = require('./WalletKey');
|
var WalletKey = require('./WalletKey');
|
||||||
@ -633,14 +632,19 @@ Transaction.prototype.getReceivingAddresses = function(networkName) {
|
|||||||
ret = [];
|
ret = [];
|
||||||
for (var i = 0; i<this.outs.length; i++) {
|
for (var i = 0; i<this.outs.length; i++) {
|
||||||
var o = this.outs[i];
|
var o = this.outs[i];
|
||||||
var addr = Address.fromScriptPubKey(o.getScript(), networkName)[0].toString();
|
var addrs = Address.fromScriptPubKey(o.getScript(), networkName);
|
||||||
ret.push(addr);
|
if (typeof addrs[0] !== 'undefined') {
|
||||||
|
ret.push(addrs[0].toString());
|
||||||
|
} else {
|
||||||
|
ret.push(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
Transaction.prototype.getSendingAddresses = function(networkName) {
|
Transaction.prototype.getSendingAddresses = function(networkName) {
|
||||||
var ret = [];
|
|
||||||
if (!networkName) networkName = 'livenet';
|
if (!networkName) networkName = 'livenet';
|
||||||
|
var ret = [];
|
||||||
for (var i = 0; i<this.ins.length; i++) {
|
for (var i = 0; i<this.ins.length; i++) {
|
||||||
var input = this.ins[i];
|
var input = this.ins[i];
|
||||||
var scriptSig = input.getScript();
|
var scriptSig = input.getScript();
|
||||||
|
|||||||
@ -744,8 +744,9 @@ fnToSign[Script.TX_SCRIPTHASH] = TransactionBuilder.prototype._signScriptHash;
|
|||||||
// sign
|
// sign
|
||||||
// ----
|
// ----
|
||||||
// Signs a transaction.
|
// Signs a transaction.
|
||||||
// `keys`: an array of strings representing private keys to sign the
|
// `keys`: an array of strings representing private keys to sign the transaction in WIF private key format
|
||||||
// transaction in WIF private key format OR bitcore's `WalletKey` objects
|
// OR bitcore's `WalletKey` objects
|
||||||
|
// OR string representing private keys to sign the transaction in WIF private key format separated by commas
|
||||||
//
|
//
|
||||||
// If multiple keys are given, each will be tested against the transaction's
|
// If multiple keys are given, each will be tested against the transaction's
|
||||||
// scriptPubKeys. Only the valid private keys will be used to sign.
|
// scriptPubKeys. Only the valid private keys will be used to sign.
|
||||||
@ -756,6 +757,7 @@ fnToSign[Script.TX_SCRIPTHASH] = TransactionBuilder.prototype._signScriptHash;
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
TransactionBuilder.prototype.sign = function(keys) {
|
TransactionBuilder.prototype.sign = function(keys) {
|
||||||
|
if (typeof keys === "string") keys = keys.split(',');
|
||||||
if (!(keys instanceof Array))
|
if (!(keys instanceof Array))
|
||||||
throw new Error('parameter should be an array');
|
throw new Error('parameter should be an array');
|
||||||
|
|
||||||
@ -819,10 +821,12 @@ TransactionBuilder.prototype.build = function() {
|
|||||||
//
|
//
|
||||||
TransactionBuilder.prototype.toObj = function() {
|
TransactionBuilder.prototype.toObj = function() {
|
||||||
|
|
||||||
|
var utxos = this.selectedUtxos && this.selectedUtxos[0] ? this.selectedUtxos : JSON.parse(this.vanilla.utxos);
|
||||||
|
|
||||||
var ret = {
|
var ret = {
|
||||||
version: TOOBJ_VERSION,
|
version: TOOBJ_VERSION,
|
||||||
outs: JSON.parse(this.vanilla.outs),
|
outs: JSON.parse(this.vanilla.outs),
|
||||||
utxos: JSON.parse(this.vanilla.utxos),
|
utxos: utxos,
|
||||||
opts: JSON.parse(this.vanilla.opts),
|
opts: JSON.parse(this.vanilla.opts),
|
||||||
scriptSig: this.vanilla.scriptSig,
|
scriptSig: this.vanilla.scriptSig,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -23,8 +23,6 @@ bnjs.fromBuffer = function(buf, opts) {
|
|||||||
buf = nbuf;
|
buf = nbuf;
|
||||||
}
|
}
|
||||||
var hex = buf.toString('hex');
|
var hex = buf.toString('hex');
|
||||||
if (hex.length % 2)
|
|
||||||
hex = "0" + hex;
|
|
||||||
var bn = new bnjs(hex, 16);
|
var bn = new bnjs(hex, 16);
|
||||||
return bn;
|
return bn;
|
||||||
};
|
};
|
||||||
@ -32,9 +30,7 @@ bnjs.fromBuffer = function(buf, opts) {
|
|||||||
bnjs.prototype.toBuffer = function(opts) {
|
bnjs.prototype.toBuffer = function(opts) {
|
||||||
var buf;
|
var buf;
|
||||||
if (opts && opts.size) {
|
if (opts && opts.size) {
|
||||||
var hex = this.toString(16);
|
var hex = this.toString(16, 2);
|
||||||
if (hex.length % 2)
|
|
||||||
hex = "0" + hex;
|
|
||||||
var natlen = hex.length/2;
|
var natlen = hex.length/2;
|
||||||
buf = new Buffer(hex, 'hex');
|
buf = new Buffer(hex, 'hex');
|
||||||
|
|
||||||
@ -56,9 +52,7 @@ bnjs.prototype.toBuffer = function(opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var hex = this.toString(16);
|
var hex = this.toString(16, 2);
|
||||||
if (hex.length % 2)
|
|
||||||
hex = "0" + hex;
|
|
||||||
buf = new Buffer(hex, 'hex');
|
buf = new Buffer(hex, 'hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -160,6 +160,12 @@ Key.sign = function(hash, priv, k) {
|
|||||||
var Q = Point.multiply(G, k);
|
var Q = Point.multiply(G, k);
|
||||||
var r = Q.x.mod(n);
|
var r = Q.x.mod(n);
|
||||||
var s = k.invm(n).mul(e.add(d.mul(r))).mod(n);
|
var s = k.invm(n).mul(e.add(d.mul(r))).mod(n);
|
||||||
|
//enforce low s
|
||||||
|
//see BIP 62, "low S values in signatures"
|
||||||
|
var n_half = bignum.fromBuffer(new Buffer("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0", 'hex'), {size: 32});
|
||||||
|
if (s.cmp(n_half) > 0) {
|
||||||
|
s = new bignum(n).sub(s);
|
||||||
|
}
|
||||||
} while (r.cmp(new bignum(0)) <= 0 || s.cmp(new bignum(0)) <= 0);
|
} while (r.cmp(new bignum(0)) <= 0 || s.cmp(new bignum(0)) <= 0);
|
||||||
|
|
||||||
return {r: r, s: s};
|
return {r: r, s: s};
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
var bignum = require('bignum');
|
|
||||||
var Point = require('../Point');
|
var Point = require('../Point');
|
||||||
var SecureRandom = require('../SecureRandom');
|
var SecureRandom = require('../SecureRandom');
|
||||||
var bignum = require('bignum');
|
var bignum = require('bignum');
|
||||||
|
|||||||
73
package.json
73
package.json
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "bitcore",
|
"name": "bitcore",
|
||||||
"description": "Bitcoin Library",
|
"description": "Bitcoin Library",
|
||||||
"version": "0.1.36",
|
"version": "0.1.41",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Stephen Pair",
|
"name": "Stephen Pair",
|
||||||
"email": "stephen@bitpay.com"
|
"email": "stephen@bitpay.com"
|
||||||
@ -30,6 +30,10 @@
|
|||||||
{
|
{
|
||||||
"name": "Gordon Hall",
|
"name": "Gordon Hall",
|
||||||
"email": "gordon@bitpay.com"
|
"email": "gordon@bitpay.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Esteban Ordano",
|
||||||
|
"email": "eordano@gmail.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -49,44 +53,27 @@
|
|||||||
"install": "node-gyp rebuild",
|
"install": "node-gyp rebuild",
|
||||||
"test": "node browser/build.js -a && node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
"test": "node browser/build.js -a && node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
||||||
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
|
"coverage": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --reporter spec test",
|
||||||
"prepublish": "node browser/build.js -m"
|
"prepublish": "node browser/build.js -a"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"grunt-browserify": "~2.0.0",
|
"asn1.js": "0.4.1",
|
||||||
"grunt-contrib-watch": "~0.5.3",
|
"async": "~0.2.10",
|
||||||
"grunt-markdown": "~0.5.0",
|
"bignum": "^0.9.0",
|
||||||
"grunt-mocha-test": "~0.8.2",
|
"binary": "^0.3.0",
|
||||||
"grunt-shell": "~0.6.4",
|
|
||||||
"protobufjs": "=3.0.0",
|
|
||||||
"coveralls": "^2.10.0",
|
|
||||||
"istanbul": "~0.2.6",
|
|
||||||
"commander": "~2.2.0",
|
|
||||||
"mocha": ">=1.15.1",
|
|
||||||
"sjcl": "=1.0.1",
|
|
||||||
"hash.js": "=0.3.1",
|
|
||||||
"bn.js": "=0.13.3",
|
|
||||||
"jsrsasign": "=0.0.3",
|
|
||||||
"elliptic": "=0.15.7",
|
|
||||||
"bindings": "=1.1.1",
|
"bindings": "=1.1.1",
|
||||||
|
"bn.js": "=1.0.0",
|
||||||
|
"brfs": "=1.0.0",
|
||||||
|
"browserify-buffertools": "git://github.com/maraoz/browserify-buffertools.git",
|
||||||
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
"bufferput": "git://github.com/bitpay/node-bufferput.git",
|
||||||
"bignum": "=0.6.2",
|
|
||||||
"binary": "=0.3.0",
|
|
||||||
"step": "=0.0.4",
|
|
||||||
"buffers": "=0.1.1",
|
"buffers": "=0.1.1",
|
||||||
"buffertools": "=2.1.2",
|
"buffertools": "=2.1.2",
|
||||||
"browserify": "=3.40.0",
|
"elliptic": "=1.0.0",
|
||||||
"browser-pack": "=2.0.1",
|
"hash.js": "=0.3.2",
|
||||||
"browserify-buffertools": "git://github.com/maraoz/browserify-buffertools.git",
|
"jsrsasign": "=0.0.3",
|
||||||
"socks5-client": "~0.3.6",
|
|
||||||
"brfs": "=1.0.0",
|
|
||||||
"chai": "=1.9.1",
|
|
||||||
"uglifyify": "=1.2.3",
|
|
||||||
"async": "~0.2.10",
|
|
||||||
"event-stream": "~3.1.5",
|
|
||||||
"gulp-concat": "~2.2.0",
|
|
||||||
"gulp": "~3.8.2",
|
|
||||||
"preconditions": "^1.0.7",
|
"preconditions": "^1.0.7",
|
||||||
"asn1.js": "0.4.1"
|
"protobufjs": "=3.0.0",
|
||||||
|
"sjcl": "=1.0.1",
|
||||||
|
"socks5-client": "~0.3.6"
|
||||||
},
|
},
|
||||||
"testling": {
|
"testling": {
|
||||||
"harness": "mocha-bdd",
|
"harness": "mocha-bdd",
|
||||||
@ -104,6 +91,7 @@
|
|||||||
},
|
},
|
||||||
"browser": {
|
"browser": {
|
||||||
"bignum": "./lib/browser/Bignum.js",
|
"bignum": "./lib/browser/Bignum.js",
|
||||||
|
"buffertools": "browserify-buffertools",
|
||||||
"./lib/Key.js": "./lib/browser/Key.js",
|
"./lib/Key.js": "./lib/browser/Key.js",
|
||||||
"./lib/Point.js": "./lib/browser/Point.js",
|
"./lib/Point.js": "./lib/browser/Point.js",
|
||||||
"./lib/ECIES.js": "./lib/browser/ECIES.js",
|
"./lib/ECIES.js": "./lib/browser/ECIES.js",
|
||||||
@ -112,12 +100,27 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.10"
|
"node": ">=0.10 <0.10.36"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"sinon": "^1.10.3",
|
"browserify": "=3.40.0",
|
||||||
|
"chai": "=1.9.1",
|
||||||
|
"commander": "~2.2.0",
|
||||||
|
"coveralls": "^2.10.0",
|
||||||
|
"event-stream": "~3.1.5",
|
||||||
"express": "4.6.1",
|
"express": "4.6.1",
|
||||||
|
"grunt-browserify": "~2.0.0",
|
||||||
|
"grunt-contrib-watch": "~0.5.3",
|
||||||
|
"grunt-markdown": "~0.5.0",
|
||||||
|
"grunt-mocha-test": "~0.8.2",
|
||||||
|
"grunt-shell": "~0.6.4",
|
||||||
|
"gulp": "~3.8.2",
|
||||||
|
"gulp-concat": "~2.2.0",
|
||||||
|
"istanbul": "~0.2.6",
|
||||||
|
"mocha": ">=1.15.1",
|
||||||
|
"optimist": "0.6.1",
|
||||||
"request": "2.39.0",
|
"request": "2.39.0",
|
||||||
"optimist": "0.6.1"
|
"sinon": "^1.10.3",
|
||||||
|
"uglifyify": "=1.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -934,8 +934,8 @@ describe('TransactionBuilder', function() {
|
|||||||
it('should check sign parameters', function() {
|
it('should check sign parameters', function() {
|
||||||
var b = getP2shBuilder(1);
|
var b = getP2shBuilder(1);
|
||||||
(function() {
|
(function() {
|
||||||
b.sign(testdata.dataUnspentSign.keyStringsP2sh[0])
|
b.sign(testdata.dataUnspentSign.keyStringsP2sh[0]);
|
||||||
}).should.throw('array');
|
}).should.not.throw('array');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user