Browse Source

Revert "Merge pull request #160 from matiu/cash"

This reverts commit b5c4f76799, reversing
changes made to 5feb9e547c.
master
Emilio Almansi 7 years ago
parent
commit
97cd3913e0
  1. 2
      index.js
  2. 2
      lib/encoding/base58.js
  3. 6
      lib/encoding/bufferreader.js
  4. 8
      lib/hdprivatekey.js
  5. 4
      lib/hdpublickey.js
  6. 17
      lib/networks.js
  7. 6
      lib/transaction/transaction.js
  8. 2
      package.json
  9. 80
      test/address.js
  10. 8
      test/data/bitcoind/base58_keys_invalid.json
  11. 28
      test/data/bitcoind/base58_keys_valid.json
  12. 14
      test/data/tx_creation.json
  13. 4
      test/privatekey.js
  14. 10
      test/publickey.js
  15. 26
      test/script/script.js
  16. 6
      test/transaction/input/multisig.js
  17. 8
      test/transaction/input/multisigscripthash.js
  18. 2
      test/transaction/input/publickeyhash.js
  19. 1
      test/transaction/transaction.js
  20. 68
      test/uri.js

2
index.js

@ -6,7 +6,7 @@ var bitcore = module.exports;
bitcore.version = 'v' + require('./package.json').version;
bitcore.versionGuard = function(version) {
if (version !== undefined) {
var message = 'More than one instance of bitcore-lib-cash found. ' +
var message = 'More than one instance of bitcore-lib found. ' +
'Please make sure to require bitcore-lib and check that submodules do' +
' not also include their own bitcore-lib dependency.';
throw new Error(message);

2
lib/encoding/base58.js

@ -26,7 +26,7 @@ Base58.validCharacters = function validCharacters(chars) {
if (buffer.Buffer.isBuffer(chars)) {
chars = chars.toString();
}
return _.every(_.map(chars, function(char) { return _.includes(ALPHABET, char); }));
return _.all(_.map(chars, function(char) { return _.contains(ALPHABET, char); }));
};
Base58.prototype.set = function(obj) {

6
lib/encoding/bufferreader.js

@ -17,12 +17,8 @@ var BufferReader = function BufferReader(buf) {
buf: buf
});
} else if (_.isString(buf)) {
var b = new Buffer(buf, 'hex');
if (b.length * 2 != buf.length)
throw new TypeError('Invalid hex string');
this.set({
buf: b,
buf: new Buffer(buf, 'hex'),
});
} else if (_.isObject(buf)) {
var obj = buf;

8
lib/hdprivatekey.js

@ -74,7 +74,7 @@ function HDPrivateKey(arg) {
HDPrivateKey.isValidPath = function(arg, hardened) {
if (_.isString(arg)) {
var indexes = HDPrivateKey._getDerivationIndexes(arg);
return indexes !== null && _.every(indexes, HDPrivateKey.isValidPath);
return indexes !== null && _.all(indexes, HDPrivateKey.isValidPath);
}
if (_.isNumber(arg)) {
@ -99,11 +99,11 @@ HDPrivateKey._getDerivationIndexes = function(path) {
var steps = path.split('/');
// Special cases:
if (_.includes(HDPrivateKey.RootElementAlias, path)) {
if (_.contains(HDPrivateKey.RootElementAlias, path)) {
return [];
}
if (!_.includes(HDPrivateKey.RootElementAlias, steps[0])) {
if (!_.contains(HDPrivateKey.RootElementAlias, steps[0])) {
return null;
}
@ -123,7 +123,7 @@ HDPrivateKey._getDerivationIndexes = function(path) {
return index;
});
return _.some(indexes, isNaN) ? null : indexes;
return _.any(indexes, isNaN) ? null : indexes;
};
/**

4
lib/hdpublickey.js

@ -75,7 +75,7 @@ function HDPublicKey(arg) {
HDPublicKey.isValidPath = function(arg) {
if (_.isString(arg)) {
var indexes = HDPrivateKey._getDerivationIndexes(arg);
return indexes !== null && _.every(indexes, HDPublicKey.isValidPath);
return indexes !== null && _.all(indexes, HDPublicKey.isValidPath);
}
if (_.isNumber(arg)) {
@ -184,7 +184,7 @@ HDPublicKey.prototype._deriveWithNumber = function(index, hardened) {
HDPublicKey.prototype._deriveFromString = function(path) {
/* jshint maxcomplexity: 8 */
if (_.includes(path, "'")) {
if (_.contains(path, "'")) {
throw new hdErrors.InvalidIndexCantDeriveHardened();
} else if (!HDPublicKey.isValidPath(path)) {
throw new hdErrors.InvalidPath(path);

17
lib/networks.js

@ -38,7 +38,7 @@ function get(arg, keys) {
return networks[index][key] === arg;
};
for (var index in networks) {
if (_.some(keys, containsArg)) {
if (_.any(keys, containsArg)) {
return networks[index];
}
}
@ -129,19 +129,20 @@ function removeNetwork(network) {
addNetwork({
name: 'livenet',
alias: 'mainnet',
pubkeyhash: 28,
pubkeyhash: 0x00,
privatekey: 0x80,
scripthash: 40,
scripthash: 0x05,
xpubkey: 0x0488b21e,
xprivkey: 0x0488ade4,
networkMagic: 0xf9beb4d9,
port: 8333,
dnsSeeds: [
'seed.bitcoinabc.org',
'seed-abc.bitcoinforks.org',
'seed.bitcoinunlimited.info',
'seed.bitprim.org ',
'seed.deadalnix.me'
'seed.bitcoin.sipa.be',
'dnsseed.bluematt.me',
'dnsseed.bitcoin.dashjr.org',
'seed.bitcoinstats.com',
'seed.bitnodes.io',
'bitseed.xf2.org'
]
});

6
lib/transaction/transaction.js

@ -541,7 +541,7 @@ Transaction.prototype.from = function(utxo, pubkeys, threshold) {
});
return this;
}
var exists = _.some(this.inputs, function(input) {
var exists = _.any(this.inputs, function(input) {
// TODO: Maybe prevTxId should be a string? Or defined as read only property?
return input.prevTxId.toString('hex') === utxo.txId && input.outputIndex === utxo.outputIndex;
});
@ -647,7 +647,7 @@ Transaction.prototype.uncheckedAddInput = function(input) {
* @return {boolean}
*/
Transaction.prototype.hasAllUtxoInfo = function() {
return _.every(this.inputs.map(function(input) {
return _.all(this.inputs.map(function(input) {
return !!input.output;
}));
};
@ -1103,7 +1103,7 @@ Transaction.prototype.isFullySigned = function() {
);
}
});
return _.every(_.map(this.inputs, function(input) {
return _.all(_.map(this.inputs, function(input) {
return input.isFullySigned();
}));
};

2
package.json

@ -85,7 +85,7 @@
"buffer-compare": "=1.0.0",
"elliptic": "=3.0.3",
"inherits": "=2.0.1",
"lodash": "^4.17.4"
"lodash": "=3.10.1"
},
"devDependencies": {
"bitcore-build": "bitpay/bitcore-build",

80
test/address.js

@ -18,8 +18,8 @@ var invalidbase58 = require('./data/bitcoind/base58_keys_invalid.json');
describe('Address', function() {
var pubkeyhash = new Buffer('3c3fa3d4adcaf8f52d5b1843975e122548269937', 'hex');
var buf = Buffer.concat([new Buffer([28]), pubkeyhash]);
var str = 'CMxTMLHVazpmroYhw2bfXNJFyxLuX4srpv';
var buf = Buffer.concat([new Buffer([0]), pubkeyhash]);
var str = '16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r';
it('can\'t build without data', function() {
(function() {
@ -68,20 +68,20 @@ describe('Address', function() {
// livenet valid
var PKHLivenet = [
'CMPeBN1BZDzaqU5DF66X5QykLcS1voucT9',
'CRZoT4EafXoYLNJm3bPpTjK3h4q1FSxet4',
'CTHVPhghRAmiLHajoKYTGRyiU8RomQmAfZ',
'CaSvYEmgxVRYiAauWzW1XP4SHkyTiS78yy',
' CaSvYEmgxVRYiAauWzW1XP4SHkyTiS78yy \t\n'
'15vkcKf7gB23wLAnZLmbVuMiiVDc1Nm4a2',
'1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT',
'1BpbpfLdY7oBS9gK7aDXgvMgr1DPvNhEB2',
'1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7',
' 1Jz2yCRd5ST1p2gUqFB5wsSQfdm3jaFfg7 \t\n'
];
// livenet p2sh
var P2SHLivenet = [
'H8rnMErHmZWKpp8H3beDwL8BsSEwzDFSjJ',
'H8kzbJ9Mw46WdAxC8SAFadHn1oNqp6jEsu',
'HCGvZEM8pNyAFBfRrz9Eo4N4eGJPuFahd9',
'HVZezVtqnDwoTZTZ997fZUUGZMetDFUDLf',
'\tHVZezVtqnDwoTZTZ997fZUUGZMetDFUDLf \n \r'
'342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey',
'33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk',
'37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3',
'3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy',
'\t \n3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy \r'
];
// testnet p2sh
@ -94,18 +94,18 @@ describe('Address', function() {
//livenet bad checksums
var badChecksums = [
'C5vkcKf7gB23wLAnZLmbVuMiiVDc3nq4a2',
'CA6ut1tWnUq1SEQLMr4ttDh24wcbj4w2TT',
'CBpbpfLdY7oBS9gK7aDXgvMgr1DpvNH3B2',
'CJz2yCRd5ST1p2gUqFB5wsSQfdmEJaffg7'
'15vkcKf7gB23wLAnZLmbVuMiiVDc3nq4a2',
'1A6ut1tWnUq1SEQLMr4ttDh24wcbj4w2TT',
'1BpbpfLdY7oBS9gK7aDXgvMgr1DpvNH3B2',
'1Jz2yCRd5ST1p2gUqFB5wsSQfdmEJaffg7'
];
//livenet non-base58
var nonBase58 = [
'C5vkcKf7g#23wLAnZLmb$uMiiVDc3nq4a2',
'CA601ttWnUq1SEQLMr4ttDh24wcbj4w2TT',
'CBpbpfLdY7oBS9gK7aIXgvMgr1DpvNH3B2',
'CJz2yCRdOST1p2gUqFB5wsSQfdmEJaffg7'
'15vkcKf7g#23wLAnZLmb$uMiiVDc3nq4a2',
'1A601ttWnUq1SEQLMr4ttDh24wcbj4w2TT',
'1BpbpfLdY7oBS9gK7aIXgvMgr1DpvNH3B2',
'1Jz2yCRdOST1p2gUqFB5wsSQfdmEJaffg7'
];
//testnet valid
@ -119,17 +119,17 @@ describe('Address', function() {
describe('validation', function() {
it('getValidationError detects network mismatchs', function() {
var error = Address.getValidationError('HC1hAdrx7APHg1DkE4bVLsZhY1SE5Dik1r', 'testnet');
var error = Address.getValidationError('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'testnet');
should.exist(error);
});
it('isValid returns true on a valid address', function() {
var valid = Address.isValid('HC1hAdrx7APHg1DkE4bVLsZhY1SE5Dik1r', 'livenet');
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'livenet');
valid.should.equal(true);
});
it('isValid returns false on network mismatch', function() {
var valid = Address.isValid('HC1hAdrx7APHg1DkE4bVLsZhY1SE5Dik1r', 'testnet');
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'testnet');
valid.should.equal(false);
});
@ -214,10 +214,10 @@ describe('Address', function() {
});
it('addresses with whitespace are validated correctly', function() {
var ws = ' \r \t \n CRZoT4EafXoYLNJm3bPpTjK3h4q1FSxet4 \t \n \r';
var ws = ' \r \t \n 1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT \t \n \r';
var error = Address.getValidationError(ws);
should.not.exist(error);
Address.fromString(ws).toString().should.equal('CRZoT4EafXoYLNJm3bPpTjK3h4q1FSxet4');
Address.fromString(ws).toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
});
});
@ -332,7 +332,7 @@ describe('Address', function() {
it('should make this address from a compressed pubkey', function() {
var pubkey = new PublicKey('0285e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b004');
var address = Address.fromPublicKey(pubkey, 'livenet');
address.toString().should.equal('CR9Aex3uR9Brm2etmqio8u6bG7g2uF5ewo');
address.toString().should.equal('19gH5uhqY6DKrtkU66PsZPUZdzTd11Y7ke');
});
it('should use the default network for pubkey', function() {
@ -345,24 +345,24 @@ describe('Address', function() {
var pubkey = new PublicKey('0485e9737a74c30a873f74df05124f2aa6f53042c2fc0a130d6cbd7d16b944b00' +
'4833fef26c8be4c4823754869ff4e46755b85d851077771c220e2610496a29d98');
var a = Address.fromPublicKey(pubkey, 'livenet');
a.toString().should.equal('CMmRMkJoBXgVa7rVeqbzSmEzUp6YgVBuaV');
a.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
var b = new Address(pubkey, 'livenet', 'pubkeyhash');
b.toString().should.equal('CMmRMkJoBXgVa7rVeqbzSmEzUp6YgVBuaV');
b.toString().should.equal('16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX');
});
it('should classify from a custom network', function() {
var custom = {
name: 'customnetwork',
pubkeyhash: 10,
pubkeyhash: 0x1c,
privatekey: 0x1e,
scripthash: 15,
scripthash: 0x28,
xpubkey: 0x02e8de8f,
xprivkey: 0x02e8da54,
networkMagic: 0x0c110907,
port: 7333
};
var addressString = 'CX4WePxBwq1Y6u7VyMJfmmitE7GiTgC9aE';
Networks.add(custom);
var addressString = '57gZdnwcQHLirKLwDHcFiWLq9jTZwRaxaE';
var network = Networks.get('customnetwork');
var address = Address.fromString(addressString);
address.type.should.equal(Address.PayToPublicKeyHash);
@ -382,26 +382,26 @@ describe('Address', function() {
'0xc8e11b0eb0d2ad5362d894f048908341fa61b6e1 OP_EQUALVERIFY OP_CHECKSIG');
var buf = s.toBuffer();
var a = Address.fromScript(s, 'livenet');
a.toString().should.equal('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
a.toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
var b = new Address(s, 'livenet');
b.toString().should.equal('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
b.toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
});
it('should make this address from a p2sh input script', function() {
var s = Script.fromString('OP_HASH160 20 0xa6ed4af315271e657ee307828f54a4365fa5d20f OP_EQUAL');
var a = Address.fromScript(s, 'livenet');
a.toString().should.equal('HMjkpaXwkpiL2dF6NzqRCyj8HzxSEGPGr3');
a.toString().should.equal('3GueMn6ruWVfQTN4XKBGEbCbGLwRSUhfnS');
var b = new Address(s, 'livenet');
b.toString().should.equal('HMjkpaXwkpiL2dF6NzqRCyj8HzxSEGPGr3');
b.toString().should.equal('3GueMn6ruWVfQTN4XKBGEbCbGLwRSUhfnS');
});
it('returns the same address if the script is a pay to public key hash out', function() {
var address = 'CMmRMkJoBXgVa7rVeqbzSmEzUp6YgVBuaV';
var address = '16JXnhxjJUhxfyx4y6H4sFcxrgt8kQ8ewX';
var script = Script.buildPublicKeyHashOut(new Address(address));
Address(script, Networks.livenet).toString().should.equal(address);
});
it('returns the same address if the script is a pay to script hash out', function() {
var address = 'HGNshk7ZtEP3UwYTqTWAjeJpZLMk3BWkJt';
var address = '3BYmEwgV2vANrmfRymr1mFnHXgLjD6gAWm';
var script = Script.buildScriptHashOut(new Address(address));
Address(script, Networks.livenet).toString().should.equal(address);
});
@ -487,7 +487,7 @@ describe('Address', function() {
describe('#inspect', function() {
it('should output formatted output correctly', function() {
var address = new Address(str);
var output = '<Address: CMxTMLHVazpmroYhw2bfXNJFyxLuX4srpv, type: pubkeyhash, network: livenet>';
var output = '<Address: 16VZnHwRhwrExfeHFHGjwrgEMq8VcYPs9r, type: pubkeyhash, network: livenet>';
address.inspect().should.equal(output);
});
});
@ -535,9 +535,9 @@ describe('Address', function() {
it('can create an address from a set of public keys', function() {
var address = Address.createMultisig(publics, 2, Networks.livenet);
address.toString().should.equal('HLiwrE9wYi9XHHeXL8R8fN5cWZpBUN8Kme');
address.toString().should.equal('3FtqPRirhPvrf7mVUSkygyZ5UuoAYrTW3y');
address = new Address(publics, 2, Networks.livenet);
address.toString().should.equal('HLiwrE9wYi9XHHeXL8R8fN5cWZpBUN8Kme');
address.toString().should.equal('3FtqPRirhPvrf7mVUSkygyZ5UuoAYrTW3y');
});
it('works on testnet also', function() {

8
test/data/bitcoind/base58_keys_invalid.json

@ -5,12 +5,6 @@
[
"x"
],
[
"19dcawoKcZdQz365WpXWMhX6QCUpR9SY4r"
],
[
"37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3"
],
[
"37qgekLpCCHrQuSjvX3fs496FWTGsHFHizjJAs6NPcR47aefnnCWECAhHV6E3g4YN7u7Yuwod5Y"
],
@ -108,7 +102,7 @@
"dB7cwYdcPSgiyAwKWL3JwCVwSk6epU2txw"
],
[
"1PhFUhUAh8ZQQisH8QQWafAxtQYju3SFTX"
"HPhFUhUAh8ZQQisH8QQWafAxtQYju3SFTX"
],
[
"4ctAH6AkHzq5ioiM1m9T3E2hiYEev5mTsB"

28
test/data/bitcoind/base58_keys_valid.json

@ -1,6 +1,6 @@
[
[
"CRjG93RdHa96NpA9X3Mdh4eF1bEhzApax4",
"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i",
"65a16059864a2fdbc7c99a4723a8395bc6f188eb",
{
"addrType": "pubkey",
@ -9,7 +9,7 @@
}
],
[
"HHBUiko6ebQGgatGgHTKJUWXJvhF19L2GP",
"3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou",
"74f209f6ea907e2ea48f74fae05782ae8a665257",
{
"addrType": "script",
@ -72,7 +72,7 @@
}
],
[
"CSQxFcEezj9FnAN9cgyf8oAuzVYrv6bJ9P",
"1Ax4gZtb7gAit2TivwejZHYtNNLT18PUXJ",
"6d23156cbbdcc82a5a47eee4c2c7c583c18b6bf4",
{
"addrType": "pubkey",
@ -81,7 +81,7 @@
}
],
[
"HVZezVtqnDwoTZTZ997fZUUGZMetDFUDLf",
"3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy",
"fcc5460dd6e2487c7d75b1963625da0e8f4c5975",
{
"addrType": "script",
@ -144,7 +144,7 @@
}
],
[
"CTYV1mMn7KTDLbWRQj6BgiQ2kMaptRX8TP",
"1C5bSj1iEGUgSTbziymG7Cn18ENQuT36vv",
"7987ccaa53d02c8873487ef919677cd3db7a6912",
{
"addrType": "pubkey",
@ -153,7 +153,7 @@
}
],
[
"HFcVRP2d87gdAtLGRcuPm3P1qJGYEYwN5r",
"3AnNxabYGoTxYiTEZwFEnerUoeFXK2Zoks",
"63bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb",
{
"addrType": "script",
@ -216,7 +216,7 @@
}
],
[
"CYJddWGB2S7Y6jus9ADPdNdXi9KXHavv7U",
"1Gqk4Tv79P91Cc1STQtU3s1W6277M2CVWu",
"adc1cc2081a27206fae25792f28bbc55b831549d",
{
"addrType": "pubkey",
@ -225,7 +225,7 @@
}
],
[
"H8kzbJ9Mw46WdAxC8SAFadHn1oNqp6jEsu",
"33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk",
"188f91a931947eddd7432d6e614387e32b244709",
{
"addrType": "script",
@ -288,7 +288,7 @@
}
],
[
"CaQF5DqQmmpRmkW172udeLTKRsufArS4wS",
"1JwMWBVLtiqtscbaRHai4pqHokhFCbtoB4",
"c4c1b72491ede1eedaca00618407ee0b772cad0d",
{
"addrType": "pubkey",
@ -297,7 +297,7 @@
}
],
[
"HV37PTm9Qk9RvRbYMsA6w4A7PqU98b2bxJ",
"3QCzvfL4ZRvmJFiWWBVwxfdaNBT8EtxB5y",
"f6fe69bcb548a829cce4c57bf6fff8af3a5981f9",
{
"addrType": "script",
@ -360,7 +360,7 @@
}
],
[
"CR6W9z9PVcbwtAzWCZrRwD982KhEEGCjcq",
"19dcawoKcZdQz365WpXWMhX6QCUpR9SY4r",
"5eadaf9bb7121f0f192561a5a62f5e5f54210292",
{
"addrType": "pubkey",
@ -369,7 +369,7 @@
}
],
[
"HCGvZEM8pNyAFBfRrz9Eo4N4eGJPuFahd9",
"37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3",
"3f210e7277c899c3a155cc1c90f4106cbddeec6e",
{
"addrType": "script",
@ -432,7 +432,7 @@
}
],
[
"CKGuHmh1kqq9p7k39fdTLLeC4kkFb672zQ",
"13p1ijLwsnrcuyqcTvJXkq2ASdXqcnEBLE",
"1ed467017f043e91ed4c44b4e8dd674db211c4e6",
{
"addrType": "pubkey",
@ -441,7 +441,7 @@
}
],
[
"HFAQjwyDvKhrtnNbPrHy8Rr9jTQAFnYkeY",
"3ALJH9Y951VCGcVZYAdpA3KchoP9McEj1G",
"5ece0cadddc415b1980f001785947120acdb36fc",
{
"addrType": "script",

14
test/data/tx_creation.json

@ -64,20 +64,20 @@
],
[
"from", [{
"address":"HDd3XftwtyQwdibDbEJZ8uYRBJXNsRq1gS","txid":"073281b2cc94e879aaf30ea2e92947d9827b270015849d3a5b96a89ee15bfa66","vout":0,"ts":1418877950,"scriptPubKey":"a9144de752833233fe69a20064f29b2ca0f6399c8af387","amount":0.00318512,"confirmationsFromCache":false
"address":"38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z","txid":"073281b2cc94e879aaf30ea2e92947d9827b270015849d3a5b96a89ee15bfa66","vout":0,"ts":1418877950,"scriptPubKey":"a9144de752833233fe69a20064f29b2ca0f6399c8af387","amount":0.00318512,"confirmationsFromCache":false
}, ["03411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba", "03bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab", "03c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea7330"], 2],
"to", ["HGR6veMqmYQH8uzKvZFqQBV1xkskQxZEYu", 300299],
"to", ["3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9", 300299],
"sign", [["L3y1PAXfjayeB3w6NP7qfNxPbuPpQFA6hd6gj4BUKa2xSdLwoVSZ", "L3a57fiNjqfbXBdYvvGYPQ1HiDX463mwA2xFGTYVkXYdooaz9Z2u"], 1],
"serialize", "010000000166fa5be19ea8965b3a9d841500277b82d94729e9a20ef3aa79e894ccb281320700000000fc0047304402202f66fcfc0d5bff109ec12327ca37e0bc7722d08da9538f12468994799534bed602203a0b374f3a6810b0ee26028c390e14f5b6bada8fa390f4364d70d04aee240d350147304402206757f710f25937cd846fd8c56687c463a4561e9e0421fc173c78eaf2de9b9a7d02204995db6b81513b67a42b09dabab6ed4cb90901c52f6f945b768827a9390bda60014c69522103411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba2103bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab2103c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea733053aeffffffff010b9504000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
],
[
"from", [{"address":"HGR6veMqmYQH8uzKvZFqQBV1xkskQxZEYu","txid":"afbf98ca4a43db8915d75184b5204fbe71d916482adfe85cb0ed3635764fc220","vout":0,"ts":1418878108,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00318512,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2
"from", [{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"afbf98ca4a43db8915d75184b5204fbe71d916482adfe85cb0ed3635764fc220","vout":0,"ts":1418878108,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00318512,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2
],
"from", [
{"address":"HGR6veMqmYQH8uzKvZFqQBV1xkskQxZEYu","txid":"dc2e197ab72f71912c39bc23a42d823a3aa8d469fe65eb591c086e60d14c64a0","vout":0,"ts":1418878014,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00300299,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2],
"to", ["HDd3XftwtyQwdibDbEJZ8uYRBJXNsRq1gS", 150000],
"to", ["HDd3XftwtyQwdibDbEJZ8uYRBJXNsRq1gS", 160000],
"change", ["HGR6veMqmYQH8uzKvZFqQBV1xkskQxZEYu"],
{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"dc2e197ab72f71912c39bc23a42d823a3aa8d469fe65eb591c086e60d14c64a0","vout":0,"ts":1418878014,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00300299,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2],
"to", ["38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z", 150000],
"to", ["38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z", 160000],
"change", ["3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9"],
"sign", ["L2U9m5My3cdyN5qX1PH4B7XstGDZFWwyukdX8gj8vsJ3fkrqArQo", 1],
"sign", ["L4jFVcDaqZCkknP5KQWjCBgiLFxKxRxywNGTucm3jC3ozByZcbZv", 1],
"serialize", "010000000220c24f763536edb05ce8df2a4816d971be4f20b58451d71589db434aca98bfaf00000000fdfd0000473044022024b955f8bf6aaf0741da011e3214eaec7040cd12694303471cefc6ba0cc4ec290220124738015033a465636dec1524a6f956a229e69d31aef6c7a98b2a291f3cfc6701483045022100e6ae6c43240e8a11a6de2d034501c2a366c0ccdf069c7828de0791f05e68e787022028b80bd36c2b2ae63fe7afb491da6c0ce23fbbb982450962c817b20f0bb24075014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffffa0644cd1606e081c59eb65fe69d4a83a3a822da423bc392c91712fb77a192edc00000000fc00483045022100ae7f136cf906dc37d34d5035b8d2001c6a783773b74507ba83080e73e903623f0220023baf7738395268f7097e5586130f682b911fd49b83b265f8fa481f2a6b1ee90146304302201d60f512a8b37663d85c123933053e0354f13d89daf699ca600defa03d4a1dab021f41042b6e4ba30311fc3a68c228c3725f3b0f05a4453ef19408e6a4ae30a2b0014c695221020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2210271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b2103a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd853aeffffffff03f04902000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387007102000000000017a9144de752833233fe69a20064f29b2ca0f6399c8af387ab2f03000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"

4
test/privatekey.js

@ -256,7 +256,7 @@ describe('PrivateKey', function() {
it('should output this known livenet address correctly', function() {
var privkey = PrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
var address = privkey.toAddress();
address.toString().should.equal('CRZoT4EafXoYLNJm3bPpTjK3h4q1FSxet4');
address.toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
});
it('should output this known testnet address correctly', function() {
@ -446,7 +446,7 @@ describe('PrivateKey', function() {
it('creates an address as expected from WIF, livenet', function() {
var privkey = new PrivateKey('5J2NYGstJg7aJQEqNwYp4enG5BSfFdKXVTtBLvHicnRGD5kjxi6');
privkey.publicKey.toAddress().toString().should.equal('CJYVWx2K5pgJGbwsKxCEDyTxRCi8qfAXxE');
privkey.publicKey.toAddress().toString().should.equal('135bwugFCmhmNU3SeCsJeTqvo5ViymgwZ9');
});
it('creates an address as expected from WIF, testnet', function() {

10
test/publickey.js

@ -337,7 +337,7 @@ describe('PublicKey', function() {
it('should output this known mainnet address correctly', function() {
var pk = new PublicKey('03c87bd0e162f26969da8509cafcb7b8c8d202af30b928c582e263dd13ee9a9781');
var address = pk.toAddress('livenet');
address.toString().should.equal('CRZoT4EafXoYLNJm3bPpTjK3h4q1FSxet4');
address.toString().should.equal('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT');
});
it('should output this known testnet address correctly', function() {
@ -353,10 +353,10 @@ describe('PublicKey', function() {
// wif private key, address
// see: https://github.com/bitcoin/bitcoin/blob/master/src/test/key_tests.cpp#L20
var data = [
['5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj', 'CfijQPpGx8Y1wXCezKDVtiVSPrYs1TqKcS'],
['5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3', 'CWYreGRKEf45tmDJru2G9zG5fPSN7JN6T1'],
['Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw', 'CeGCRrDwqS9rZLCKzGmys6FLUede24ZV4o'],
['L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g', 'CTtcbLKQtFW3tR4x2ADdqrbiJVfZQD9cFm']
['5HxWvvfubhXpYYpS3tJkw6fq9jE9j18THftkZjHHfmFiWtmAbrj', '1QFqqMUD55ZV3PJEJZtaKCsQmjLT6JkjvJ'],
['5KC4ejrDjv152FGwP386VD1i2NYc5KkfSMyv1nGy1VGDxGHqVY3', '1F5y5E5FMc5YzdJtB9hLaUe43GDxEKXENJ'],
['Kwr371tjA9u2rFSMZjTNun2PXXP3WPZu2afRHTcta6KxEUdm1vEw', '1NoJrossxPBKfCHuJXT4HadJrXRE9Fxiqs'],
['L3Hq7a8FEQwJkW1M2GNKDW28546Vp5miewcCzSqUD9kCAXrJdS3g', '1CRj2HyM1CXWzHAXLQtiGLyggNT9WQqsDs']
];
data.forEach(function(d){

26
test/script/script.js

@ -659,12 +659,12 @@ describe('Script', function() {
});
describe('#buildPublicKeyHashOut', function() {
it('should create script from livenet address', function() {
var address = Address.fromString('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var s = Script.buildPublicKeyHashOut(address);
should.exist(s);
s.toString().should.equal('OP_DUP OP_HASH160 20 0xecae7d092947b7ee4998e254aa48900d26d2ce1d OP_EQUALVERIFY OP_CHECKSIG');
s.isPublicKeyHashOut().should.equal(true);
s.toAddress().toString().should.equal('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
s.toAddress().toString().should.equal('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
});
it('should create script from testnet address', function() {
var address = Address.fromString('mxRN6AQJaDi5R6KmvMaEmZGe3n5ScV9u33');
@ -739,14 +739,14 @@ describe('Script', function() {
});
it('inherits network property from other script', function() {
var s1 = new Script.fromAddress(new Address('CWuF5o5ZGDwXNWe2eCPxPZPWwKMWuiixY2'));
var s1 = new Script.fromAddress(new Address('1FSMWkjVPAxzUNjbxT52p3mVKC971rfW3S'));
var s2 = Script.buildScriptHashOut(s1);
should.exist(s1._network);
s1._network.should.equal(s2._network);
});
it('inherits network property form an address', function() {
var address = new Address('H9Ctbp1Y7th1TgkbabT19mpXGqEsTXggJE');
var address = new Address('34Nn91aTGaULqWsZiunrBPHzFBDrZ3B8XS');
var script = Script.buildScriptHashOut(address);
should.exist(script._network);
script._network.should.equal(address.network);
@ -821,12 +821,12 @@ describe('Script', function() {
data.should.deep.equal(new Buffer(0));
});
it('for a P2PKH address', function() {
var address = Address.fromString('Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU');
var address = Address.fromString('1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14');
var script = Script.buildPublicKeyHashOut(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
});
it('for a P2SH address', function() {
var address = Address.fromString('HMXzpZbgNAhKii1x5eSJCqhY657VyZgNb5');
var address = Address.fromString('3GhtMmAbWrUf6Y8vDxn9ETB14R6V7Br3mt');
var script = new Script(address);
expect(BufferUtil.equal(script.getData(), address.hashBuffer)).to.be.true();
});
@ -862,13 +862,13 @@ describe('Script', function() {
script.toAddress().network.should.equal(Networks.defaultNetwork);
});
it('for a P2PKH address', function() {
var stringAddress = 'Ce3M4ysH6XH7RMK1RYu4wLujcC7sv4EhNU';
var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
});
it('for a P2SH address', function() {
var stringAddress = 'HMXzpZbgNAhKii1x5eSJCqhY657VyZgNb5';
var stringAddress = '3GhtMmAbWrUf6Y8vDxn9ETB14R6V7Br3mt';
var address = new Address(stringAddress);
var script = new Script(address);
script.toAddress().toString().should.equal(stringAddress);
@ -881,26 +881,26 @@ describe('Script', function() {
// taken from tx 7e519caca256423320b92e3e17be5701f87afecbdb3f53af598032bfd8d164f5
var script = new Script('OP_DUP OP_HASH160 20 ' +
'0xc8e11b0eb0d2ad5362d894f048908341fa61b6e1 OP_EQUALVERIFY OP_CHECKSIG');
script.toAddress().toString().should.equal('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
script.toAddress().toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
});
it('works for p2pkh input', function() {
// taken from tx 7e519caca256423320b92e3e17be5701f87afecbdb3f53af598032bfd8d164f5
var script = new Script('72 0x3045022100eff96230ca0f55b1e8c7a63e014f48611ff1af40875ecd33dee9062d7a6f5e2002206320405b5f6992c756e03e66b21a05a812b60996464ac6af815c2638b930dd7a01 65 0x04150defa035a2c7d826d7d5fc8ab2154bd1bb832f1a5c8ecb338f436362ad232e428b57db44677c5a8bd42c5ed9e2d7e04e742c59bee1b40080cfd57dec64b23a');
script.toAddress().toString().should.equal('Can3P2Qf8L78v1zmTU1cs6RTrQATGLYZY4');
script.toAddress().toString().should.equal('1KK9oz4bFH8c1t6LmighHaoSEGx3P3FEmc');
// taken from tx 7f8f95752a59d715dae9e0008a42e7968d2736741591bbfc6685f6e1649c21ed
var s2 = new Script('71 0x3044022017053dad84aa06213749df50a03330cfd24d6b8e7ddbb6de66c03697b78a752a022053bc0faca8b4049fb3944a05fcf7c93b2861734d39a89b73108f605f70f5ed3401 33 0x0225386e988b84248dc9c30f784b06e02fdec57bbdbd443768eb5744a75ce44a4c');
s2.toAddress().toString().should.equal('CNx4RZSLJH5EzVQJHvoVP3ZjiVvCC6Eog1');
s2.toAddress().toString().should.equal('17VArX6GRE6i6MVscBUZoXwi6NhnHa68B7');
});
it('works for p2sh output', function() {
// taken from tx fe1f764299dc7f3b5a8fae912050df2b633bf99554c68bf1c456edb9c2b63585
var script = new Script('OP_HASH160 20 0x99d29051af0c29adcb9040034752bba7dde33e35 OP_EQUAL');
script.toAddress().toString().should.equal('HLYU1vJySyVh8RxLFnrstPNnpmDFe7fiir');
script.toAddress().toString().should.equal('3FiMZ7stbfH2WG5JQ7CiuzrFo7CEnGUcAP');
});
it('works for p2sh input', function() {
// taken from tx fe1f764299dc7f3b5a8fae912050df2b633bf99554c68bf1c456edb9c2b63585
var script = new Script('OP_FALSE 72 0x3045022100e824fbe979fac5834d0062dd5a4e82a898e00ac454bd254cd708ad28530816f202206251ff0fa4dd70c0524c690d4e4deb2bd167297e7bbdf6743b4a8050d681555001 37 0x512102ff3ae0aaa4679ea156d5581dbe6695cc0c311df0aa42af76670d0debbd8f672951ae');
script.toAddress().toString().should.equal('HMNq5CPHnBYbDUebDrqoV8iadzvHBw7bJP');
script.toAddress().toString().should.equal('3GYicPxCvsKvbJmZNBBeWkC3cLuGFhtrQi');
});
// no address scripts

6
test/transaction/input/multisig.js

@ -21,7 +21,7 @@ describe('MultiSigInput', function() {
var public1 = privateKey1.publicKey;
var public2 = privateKey2.publicKey;
var public3 = privateKey3.publicKey;
var address = new Address('H8piCq1XQrr3DbkPF5YFi5VdMV2mCQEnKW');
var address = new Address('33zbk2aSZYdNbRsMPPt6jgy6Kq1kQreqeb');
var output = {
txId: '66e64ef8a3b384164b78453fa8c8194de9a473ba14f89485a0e433699daec140',
@ -71,14 +71,14 @@ describe('MultiSigInput', function() {
.to(address, 1000000);
var input = transaction.inputs[0];
_.every(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
_.all(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
var serialized = publicKeyMissing.toString();
return serialized === public1.toString() ||
serialized === public2.toString() ||
serialized === public3.toString();
}).should.equal(true);
transaction.sign(privateKey1);
_.every(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
_.all(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
var serialized = publicKeyMissing.toString();
return serialized === public2.toString() ||
serialized === public3.toString();

8
test/transaction/input/multisigscripthash.js

@ -21,10 +21,10 @@ describe('MultiSigScriptHashInput', function() {
var public1 = privateKey1.publicKey;
var public2 = privateKey2.publicKey;
var public3 = privateKey3.publicKey;
var address = new Address('H8piCq1XQrr3DbkPF5YFi5VdMV2mCQEnKW');
var address = new Address('33zbk2aSZYdNbRsMPPt6jgy6Kq1kQreqeb');
var output = {
address: 'H8piCq1XQrr3DbkPF5YFi5VdMV2mCQEnKW',
address: '33zbk2aSZYdNbRsMPPt6jgy6Kq1kQreqeb',
txId: '66e64ef8a3b384164b78453fa8c8194de9a473ba14f89485a0e433699daec140',
outputIndex: 0,
script: new Script(address),
@ -54,14 +54,14 @@ describe('MultiSigScriptHashInput', function() {
.to(address, 1000000);
var input = transaction.inputs[0];
_.every(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
_.all(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
var serialized = publicKeyMissing.toString();
return serialized === public1.toString() ||
serialized === public2.toString() ||
serialized === public3.toString();
}).should.equal(true);
transaction.sign(privateKey1);
_.every(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
_.all(input.publicKeysWithoutSignature(), function(publicKeyMissing) {
var serialized = publicKeyMissing.toString();
return serialized === public2.toString() ||
serialized === public3.toString();

2
test/transaction/input/publickeyhash.js

@ -20,7 +20,7 @@ describe('PublicKeyHashInput', function() {
var address = new Address(publicKey, Networks.livenet);
var output = {
address: 'H8piCq1XQrr3DbkPF5YFi5VdMV2mCQEnKW',
address: '33zbk2aSZYdNbRsMPPt6jgy6Kq1kQreqeb',
txId: '66e64ef8a3b384164b78453fa8c8194de9a473ba14f89485a0e433699daec140',
outputIndex: 0,
script: new Script(address),

1
test/transaction/transaction.js

@ -114,6 +114,7 @@ describe('Transaction', function() {
.sign(p2shPrivateKey1)
.sign(p2shPrivateKey2);
console.log('[transaction.js.116]'); //TODO
var txData = JSON.stringify(tx);
var tx2 = new Transaction(JSON.parse(txData));
var tx2Data = JSON.stringify(tx2);

68
test/uri.js

@ -21,19 +21,19 @@ describe('URI', function() {
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
expect(uri.amount).to.be.undefined();
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.amount.should.equal('123.22');
expect(uri.otherParam).to.be.undefined();
uri = URI.parse('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22' +
uri = URI.parse('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22' +
'&other-param=something&req-extra=param');
uri.address.should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.amount.should.equal('123.22');
uri['other-param'].should.equal('something');
uri['req-extra'].should.equal('param');
@ -41,14 +41,14 @@ describe('URI', function() {
// TODO: Split this and explain tests
it('URIs can be validated statically (test vector)', function() {
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk').should.equal(true);
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj').should.equal(true);
URI.isValid('bitcoin:mkYY5NRvikVBY1EPtaq9fAFgquesdjqECw').should.equal(true);
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2')
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2')
.should.equal(true);
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param')
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param')
.should.equal(true);
URI.isValid('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&req-other=param',
URI.isValid('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&req-other=param',
['req-other']).should.equal(true);
URI.isValid('bitcoin:mmrqEBJxUCf42vdb3oozZtyz5mKr3Vb2Em?amount=0.1&' +
'r=https%3A%2F%2Ftest.bitpay.com%2Fi%2F6DKgf8cnJC388irbXk5hHu').should.equal(true);
@ -69,7 +69,7 @@ describe('URI', function() {
});
it('do not need new keyword', function() {
var uri = URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
var uri = URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.should.be.instanceof(URI);
});
@ -78,14 +78,14 @@ describe('URI', function() {
var uri;
it('parses address', function() {
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.should.be.instanceof(bitcore.Address);
uri.network.should.equal(Networks.livenet);
});
it('parses amount', function() {
uri = URI.fromString('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=123.22');
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri = URI.fromString('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=123.22');
uri.address.toString().should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.amount.should.equal(12322000000);
expect(uri.otherParam).to.be.undefined();
});
@ -97,7 +97,7 @@ describe('URI', function() {
});
it('stores unknown parameters as "extras"', function() {
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param');
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param');
uri.address.should.be.instanceof(bitcore.Address);
expect(uri.other).to.be.undefined();
uri.extras.other.should.equal('param');
@ -105,12 +105,12 @@ describe('URI', function() {
it('throws error when a required feature is not supported', function() {
(function() {
return new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&req-required=param');
return new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param&req-required=param');
}).should.throw(Error);
});
it('has no false negative when checking supported features', function() {
uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.2&other=param&' +
uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.2&other=param&' +
'req-required=param', ['req-required']);
uri.address.should.be.instanceof(bitcore.Address);
uri.amount.should.equal(120000000);
@ -125,7 +125,7 @@ describe('URI', function() {
var uri;
uri = new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj'
});
uri.address.should.be.instanceof(bitcore.Address);
uri.network.should.equal(Networks.livenet);
@ -137,7 +137,7 @@ describe('URI', function() {
uri.network.should.equal(Networks.testnet);
uri = new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
amount: 120000000,
other: 'param'
});
@ -148,13 +148,13 @@ describe('URI', function() {
(function() {
return new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
'req-required': 'param'
});
}).should.throw(Error);
uri = new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
amount: 120000000,
other: 'param',
'req-required': 'param'
@ -166,19 +166,19 @@ describe('URI', function() {
});
it('should support double slash scheme', function() {
var uri = new URI('bitcoin://CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
uri.address.toString().should.equal('CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
var uri = new URI('bitcoin://1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri.address.toString().should.equal('1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
});
it('should input/output String', function() {
var str = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' +
var str = 'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?' +
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD';
URI.fromString(str).toString().should.equal(str);
});
it('should input/output JSON', function() {
var json = JSON.stringify({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
message: 'Donation for project xyz',
label: 'myLabel',
other: 'xD'
@ -187,12 +187,12 @@ describe('URI', function() {
});
it('should support numeric amounts', function() {
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=12.10001');
var uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=12.10001');
expect(uri.amount).to.be.equal(1210001000);
});
it('should support extra arguments', function() {
var uri = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?' +
var uri = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?' +
'message=Donation%20for%20project%20xyz&label=myLabel&other=xD');
should.exist(uri.message);
@ -207,25 +207,25 @@ describe('URI', function() {
it('should generate a valid URI', function() {
new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
}).toString().should.equal(
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk'
'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj'
);
new URI({
address: 'CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk',
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
amount: 110001000,
message: 'Hello World',
something: 'else'
}).toString().should.equal(
'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk?amount=1.10001&message=Hello%20World&something=else'
'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj?amount=1.10001&message=Hello%20World&something=else'
);
});
it('should be case insensitive to protocol', function() {
var uri1 = new URI('bItcOin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
var uri2 = new URI('bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk');
var uri1 = new URI('bItcOin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
var uri2 = new URI('bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj');
uri1.address.toString().should.equal(uri2.address.toString());
});
@ -238,7 +238,7 @@ describe('URI', function() {
});
it('displays nicely on the console (#inspect)', function() {
var uri = 'bitcoin:CUqyiihRoVt5bjhPZTP9sjswHbP16vKQWk';
var uri = 'bitcoin:1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj';
var instance = new URI(uri);
instance.inspect().should.equal('<URI: ' + uri + '>');
});

Loading…
Cancel
Save