Commit Graph

364 Commits

Author SHA1 Message Date
Ryan X. Charles 266759ff60 Merge remote-tracking branch 'devrandom/bip39'
Conflicts:
	test/index.html
2014-06-20 19:34:21 -07:00
Ryan X. Charles 54c8e04738 remove unbuilding c code, and ...
* Remove c code that didn't compile on my machine
* Replace with sjcl code
* Minor modifications to mnemonic interface more bitcoreish
2014-06-20 19:09:21 -07:00
Ryan X. Charles a7270282d3 Merge pull request #384 from manan19/move-scriptForAddress
Move TransactionBuilder.scriptForAddress to Address.getScriptPubKey. Resolves #373
2014-06-19 20:33:36 -07:00
Manan Patel d83fc6e4b5 Resolves #373
Move TransactionBuilder.scriptForAddress to Address#getScriptPubKey (instance method)
2014-06-19 08:40:30 -07:00
Manan Patel 0d9317e2d4 adding few tests for Peer.js 2014-06-19 01:07:45 -07:00
Ryan X. Charles 83aada8648 Merge pull request #379 from ryanxcharles/feature/address-throw-error
throw error when using invalid length hash in Address constructor
2014-06-13 08:17:18 -07:00
Manuel Araoz 5c11ac3e87 malloc -> calloc, to fix linux version 2014-06-12 13:56:29 -03:00
Manuel Araoz d313ed037e trying to fix 2014-06-12 12:29:51 -03:00
Manuel Araoz a15962da88 fixing 2014-06-12 12:29:51 -03:00
Manuel Araoz d9a91e89c3 attempt to fix in linux 2014-06-12 12:29:51 -03:00
Manuel Araoz 9e46334d27 wierdest way of fixing the problem 2014-06-12 12:29:51 -03:00
Manuel Araoz 5428b1109e add problematic test 2014-06-12 12:29:50 -03:00
Ryan X. Charles c2e5a14eed throw error when using invalid length hash in Address
I have often made the error of using a public key rather than the hash of the
public key when creating an address, leading to invalid addresses. I'm sure I'm
not the only one. This commit follows the principle of "fail early, fail often"
and simply throws an error if you try to insert something other than 20 bytes
long when creating an address, which would be the case when using a public key.
This way that common mistake should be reduced.
2014-06-11 18:13:39 -07:00
Ryan X. Charles 772b12e471 Merge pull request #377 from cmgustavo/feature/fee-constant
Exporting a constant on TransactionBuilder for use on Copay
2014-06-11 15:38:50 -07:00
Gustavo Cortez 1d957b24d9 Exporting a constant on TransactionBuilder for use on Copay (to check available funds to spend). A simple test for this. 2014-06-11 19:00:11 -03:00
Ryan X. Charles 895a512e55 run HierarchicalKey tests in the browser
...not BIP32, which is the old name for HierarchicalKey
2014-06-11 14:28:30 -07:00
Devrandom b523eee812 Switch BIP-0039 to sjcl in browser 2014-06-08 13:30:47 -07:00
Devrandom 79d50e92d4 BIP39 in browser 2014-06-08 12:43:05 -07:00
Devrandom f2472e691b Separate out BIP39 2014-06-08 12:41:37 -07:00
Devrandom 63f7e3d062 BIP39 implementation 2014-06-08 12:40:28 -07:00
Ryan X. Charles 261a94d806 add ECIES example 2014-06-06 14:34:42 -07:00
Ryan X. Charles 80ccaa8396 rename "rand" to more explanatory "getRandomSeed" 2014-06-05 16:41:47 -07:00
Ryan X. Charles 5172b3160b add test to confirm correctness of sha512hmac 2014-06-04 18:57:26 -07:00
Ryan X. Charles af9fdff3a9 use SJCL AES to get ECIES working in the browser 2014-06-03 19:03:50 -07:00
Ryan X. Charles e963ff3c45 add ECIES support in node - not browser 2014-06-02 20:15:58 -07:00
Matias Alejo Garcia c9694c5768 rm console.log 2014-05-26 12:40:07 -03:00
Matias Alejo Garcia e60e389e43 add more strict checking, plus tests 2014-05-25 23:46:20 -03:00
Ryan X. Charles 9fb34f5033 print out string, not buffer 2014-05-23 16:51:32 -07:00
Ryan X. Charles c038abc8e7 rename BIP32 -> HierarchicalKey, deprecate BIP32
Sounds better.
2014-05-11 13:09:57 -04:00
olalonde af942f9b06 Armory: added tests 2014-05-08 07:54:12 +08:00
Ryan X. Charles d3a4cfa333 remove eval
eval is unsafe, and the way it was being used in Script and Script interpreter
was not a good enough reason. This commit removes both uses of eval, then
replaces all uses of OP_XXX with Opcode.map.OP_XXX since there's no reason for
those constants to be global.
2014-05-05 10:43:24 -04:00
Ryan X. Charles 46271de06e add some basic sanity tests for signatures and key generation
Signing a message with ECDSA involves using a random number, and this means
that two signatures should never be the same. This commit adds some basic tests
to Key.signSync and Message.sign to make sure this is the case. Also, a new
bitcore.Key should never have the same private key twice. This commit also adds
a basic test to make sure that is the case.
2014-05-01 12:27:55 -04:00
Ryan X. Charles b1f34d4015 iterate array correctly so that random number is actually used in signing 2014-05-01 10:09:33 -04:00
Ryan X. Charles 405ea0bf6f fix bignum issue
In the browser, sometimes the config for bignum wasn't being set up if (somehow
... still not sure how this is possible) you use bitcore without using
require('bitcore'). This would by pass the code that set the config for bignum.
Solution is to put the config for bignum in bignum itself (in the browser).

This fixes, in particular, an issue with base58 where it was depending on
bignum having the proper config.

Also I add the base58 tests to run in the browser which they weren't
previously.

And finally I add a small test for Bignum in the browser that makes sure the
config is set properly.
2014-04-29 17:59:24 -04:00
Ryan X. Charles c7218ea2fc Merge pull request #305 from maraoz/refactor/improve-BIP32
Refactor/improve bip32 and add test
2014-04-29 15:00:39 -04:00
Manuel Araoz ac719345e8 add tests for BIP32 2014-04-29 14:37:37 -03:00
Manuel Araoz ce00b77de0 name change forKey -> fromKey 2014-04-29 11:49:42 -03:00
Manuel Araoz a1a844c1e6 add Address.forKey convenience method and example vanity address generator 2014-04-29 11:49:42 -03:00
Ryan X. Charles 7f348ca0bd Move BigNumber to internal
...no longer relies on Manuel's repo hostig a version of "bignum" that actually
contained bignumber.js. This moves bignumber.js internally and removes bignum
from the browser build process. Also adds a bitcore.Bignum that links to the
right thing. In node, browser.Bignum is require('bignum'). And in the browser,
bitcore.Bignum is is now Bignumber.js (same as before ... except bignumber.js
is now inside bitcore).
2014-04-28 18:00:59 -04:00
Gordon Hall 602c94265b add test for config extending properly 2014-04-28 12:33:34 -04:00
Ruben de Vries 4860b8f3c7 updated naming for getMultiSigInfo 2014-04-25 15:02:19 +02:00
Ruben de Vries e301a14657 added Script.getMultiSigInfo as easy helper to return information about a multisig script 2014-04-25 14:58:44 +02:00
Ryan X. Charles 9575929162 Merge branch 'feature/secure-random'
Conflicts:
	lib/browser/Key.js
2014-04-24 09:19:58 -03:00
Ryan X. Charles 350f6ae998 Key should make sure new privkey is less than N
...this involves adding a Curve class, and significant refactoring to make this
possible in a clean way.
2014-04-23 21:15:55 -03:00
Manuel Araoz d8827cf9fd skip statistically failing tests 2014-04-23 15:55:35 -03:00
Manuel Araoz 17d0eeeb00 skip pending tests:wq 2014-04-23 15:45:00 -03:00
Manuel Araoz 2a829c4525 reduce number of cases for browser 2014-04-23 15:06:11 -03:00
Manuel Araoz 34ac69616a fix runs test 2014-04-23 15:01:04 -03:00
Manuel Araoz 532564461e testing RNG 2014-04-23 11:32:37 -03:00
Manuel Araoz 0095f5c9d0 rng statistic testswq 2014-04-23 11:32:37 -03:00
Ryan X. Charles 4693d5bc41 remove unnecessary "change" console.log from Electrum test 2014-04-22 22:41:57 -03:00
Ryan X. Charles ba692aaa20 add new SecureRandom class that does the right thing
Generating random numbers properly depends on the platform. The new
getRandomBuffer method does the right thing on the right platform. It will
sometimes fail due to insufficient entropy. The getPseudoRandomBuffer class is
also provided that will never fail, but it is not cryptographically secure and
should not be used for keys.
2014-04-22 22:18:59 -03:00
Matias Alejo Garcia 9951b55a4f signature sorting in .sign and .merge in transaction builder 2014-04-22 21:09:22 -03:00
Matias Alejo Garcia 56d81bc0df remove unused code from Script. Update it to do not use scriptSig placeholders 2014-04-22 21:09:22 -03:00
Matias Alejo Garcia e8ebd2e332 add tx validation to test 2014-04-22 21:09:22 -03:00
Ryan X. Charles a179251152 split Key node tests into separate file 2014-04-22 19:13:35 -03:00
Ryan X. Charles abc799f453 split up Point into separate node and browser versions 2014-04-22 19:13:35 -03:00
Ryan X. Charles e4e45c5245 add Electrum to browser build and tests 2014-04-20 17:49:43 -03:00
olalonde 2644dbb2db Electrum.js: wrote some tests 2014-04-21 04:21:33 +08:00
Ryan X. Charles 55061776ac add Message to browser build and tests 2014-04-19 11:41:00 -03:00
Ryan X. Charles 659dc10f96 add support for signing/verifying messages
This adds a new Message class with static methods for signing and verifying a
message the same way as bitcoind. (In a nutshell, messages a prepended with
"Bitcoin Signed Message:" before being hashed and signed).

There is one important piece missing ... verifying a signature with an address,
and not a public key. I have not yet implemented this because the cryptography
interface of bitcore does not allow me to derive the public key from a
signature. This will need to be added before verifying from an address is
possible.
2014-04-19 11:28:19 -03:00
Matias Alejo Garcia 5a1d572a8d add new constructor to Address (fromScriptPubKey) 2014-04-18 16:51:40 -03:00
Ryan X. Charles a1ef9c5220 make Connection test only run in node
...since it doesn't make sense for the browser
2014-04-17 15:07:19 -03:00
Ryan X. Charles da7fede2c0 Merge remote-tracking branch 'gordonwritescode/feature/tor' 2014-04-17 14:47:58 -03:00
Ryan X. Charles a749dc9d97 fix key tests for browser
Some tests that were intended for node only were running the browser. This
update removes those tests from the browser.
2014-04-16 21:37:46 -03:00
Ryan X. Charles 1a28683e4a Merge pull request #253 from matiu/feature/to-fromObj
add from-to Obj in Transaction Builder
2014-04-14 12:07:52 -03:00
Manuel Araoz bec26d80d6 fix TB test 2014-04-14 11:58:24 -03:00
Matias Alejo Garcia 9a25122b4f add merge options 2014-04-13 09:49:26 -03:00
Matias Alejo Garcia 233438f899 merge working! 2014-04-13 02:21:44 -03:00
Matias Alejo Garcia 52d47bf30e remove txobj from this! #merge WIP 2014-04-12 20:58:22 -03:00
Matias Alejo Garcia 185ebe8ebb add from-to Obj in Transaction Builder 2014-04-12 18:41:34 -03:00
Gordon Hall 3ba4352f7f merged in upstream changes, resolved conflict in package.json, add test for SOCKS5 Connection instantiation 2014-04-11 14:01:55 -04:00
Gordon Hall e53a2341c3 updated connection tests 2014-04-11 13:56:37 -04:00
Ryan X. Charles e61aa8528f add some tests to make sure changes to Key C++ code work as expected 2014-04-11 14:23:19 -03:00
Matias Alejo Garcia d0f2601512 add normalized hash for Txs 2014-04-10 23:30:04 -03:00
Ryan X. Charles 5b0c5fc3b6 Merge pull request #248 from matiu/feature/signatures-add-txbuilder
add signatureAdded counter
2014-04-10 19:56:42 -03:00
Matias Alejo Garcia d507e7f3d5 add signatureAdded counter 2014-04-10 19:43:28 -03:00
Manuel Araoz 3cbcbd54cb fix Buffers.skip in the browser 2014-04-10 18:52:13 -03:00
Manuel Araoz b58d5c5084 fix formatting 2014-04-10 18:24:20 -03:00
Manuel Araoz 6a5aa76b76 Buffers.monkey now at 100% coverage 2014-04-10 18:19:13 -03:00
Manuel Araoz 521a260afc remove deprecated chai uses 2014-04-10 15:39:54 -03:00
Ryan X. Charles c5cd242d15 add test for .isValid() function 2014-04-10 12:30:57 -03:00
Manuel Aráoz a2823a6e08 Merge pull request #237 from ryanxcharles/feature/address-interface
new convenient interface for creating addresses
2014-04-09 15:15:46 -03:00
Ryan X. Charles 3fb80bc76a Merge pull request #238 from matiu/bug/clean-examples
remove unused params in example
2014-04-09 15:15:04 -03:00
Matias Alejo Garcia a8f5f9fcb8 remove unused params in example 2014-04-09 14:13:48 -03:00
Ryan X. Charles a7c8cf49b3 update fromPubKeys to use fromScript
This means fewer code-duplication. Also added another test for fromScript to
make sure it is thoroughly tested. Also pass through opts to createMultisig so
that you can choose to lot let it be sorted if you want.
2014-04-09 14:07:56 -03:00
Ryan X. Charles ae14c4aaa0 new convenient interface for creating addresses
To create an address from a public key or script, you used to have to do the
hashing yourself, and find the version yourself. For example:

var hash = bitcore.util.sha256ripe160(pubkey);
var version = bitcore.networks['livenet'].addressVersion;
var addr = new Address(version, hash);

But with this interface, things are much simpler:

var addr = Address.fromPubKey(pubkey);

The new convenience methods are:

Address.fromPubKey (for regular pubkeyhash addresses)
Address.fromPubKeys (for p2sh multisig addresses)
Address.fromScript (for any p2sh address)
2014-04-09 13:11:24 -03:00
Manuel Araoz 72a44154d4 fix testling config 2014-04-09 12:38:25 -03:00
Ruben de Vries 3118ab1d0c updated the calcDifficulty test to make it clear with what we're testing 2014-04-08 16:08:16 +02:00
Ruben de Vries 9c6c300289 fixed calcDifficulty by making sure the MAX_TARGET is also locally available.
added tests for 2 difficulty calculations.
2014-04-08 10:26:36 +02:00
Manuel Araoz 71353426f6 network refactors 2014-04-07 18:31:17 -03:00
Manuel Araoz 0b2dae43c5 remove console.logs and std::couts 2014-04-04 18:24:34 -03:00
Manuel Araoz 406600720e valid tx tests passing! 2014-04-04 18:06:34 -03:00
Manuel Araoz 34ed503830 fixed 23 Transaction tests!!! :D 2014-04-04 17:33:36 -03:00
Manuel Araoz db38feacce fix old tests for sighash 2014-04-04 14:41:46 -03:00
Manuel Araoz 3886bfe923 some hashForSignature tests passing! :D 2014-04-04 14:39:06 -03:00
Manuel Araoz cc8010f17f adding new data file from bitcoin core 2014-04-04 14:39:06 -03:00
Manuel Araoz 499b171947 tracking Transaction test problems 2014-04-04 14:39:06 -03:00
Matias Alejo Garcia 56bed9b3f2 fix noSorting, add testcase against bitcoind output 2014-04-04 10:37:32 -03:00
Matias Alejo Garcia 8ff1464b2c add test imported from treasure 2014-04-04 09:44:16 -03:00
Matias Alejo Garcia 921bc2ff17 add sorting of pubkeys for multisig addr generation 2014-04-03 22:06:57 -03:00
Ryan X. Charles 710be7b147 add BIP32 example to examples tests 2014-04-02 12:05:11 -04:00
Ryan X. Charles 42522e03b9 Merge branch 'feature/TransactionBuilder-Multisig-support' 2014-04-02 10:40:03 -04:00
Matias Alejo Garcia f6f7a01efc add p2sh support and test 2014-04-02 00:59:26 -03:00
Ryan X. Charles abcaa3d16f Merge pull request #202 from matiu/feature/TransactionBuilder-Multisig-support
Feature/transaction builder multisig support
2014-04-01 12:20:24 -04:00
Matias Alejo Garcia d8f49e87ae different keys p2script example, add new examples in tets 2014-04-01 09:58:17 -03:00
Ryan X. Charles 4f5b41eff0 fix browser tests for Point and Key
The addUncompressed function is for node-only, and is a temporary workaround
until we expose a better crypto interface in both node and the browser. I wrote
tests for this function that were node-only, but were broken in the browser.  I
also wrote tests for the Point class that should have worked in both node and
the browser, and did, but I was using the wrong module such that it worked only
in node.  This update makes the tests work in the browser by using the correct
module.
2014-03-31 16:32:16 -04:00
Matias Alejo Garcia 4fe8dffe4a fix error msgs 2014-03-31 16:25:43 -03:00
Matias Alejo Garcia 8acf093339 multisign test for signing twice with same sig 2014-03-31 15:16:30 -03:00
Matias Alejo Garcia 2af6ab7650 TX_MULTISIG support 2014-03-31 14:41:27 -03:00
Ryan X. Charles 93050e3e92 Merge branch 'feature/TransactionBuilder' 2014-03-30 21:02:22 -04:00
Ryan X. Charles 6a478de259 add transaction builder test to browser 2014-03-30 21:01:40 -04:00
Matias Alejo Garcia 9fc2493a6d remove .init(), move it to constructor 2014-03-29 04:01:32 -03:00
Matias Alejo Garcia cb1a2d9b48 TransactionBuiler working with test 2014-03-28 21:17:34 -03:00
Ryan X. Charles a0daef56d9 Merge pull request #165 from ryanxcharles/feature/bip32
BIP 32 (hierarchical deterministic wallets)
2014-03-28 18:54:58 -04:00
Ryan X. Charles 343a6af7c3 add seed function to generate master privkey
This follows the spec of BIP32. With tests for main test vectors.
2014-03-28 18:46:09 -04:00
Ryan X. Charles f6aa01c445 add basic tests for all functions in Point 2014-03-28 18:07:23 -04:00
Ryan X. Charles 0eedeed449 add remaining public key derivation test vectors
...all pass in node and the browser.
2014-03-28 16:29:12 -04:00
Ryan X. Charles c03d3c5818 get BIP32 working in the browser by exposing more crypto 2014-03-27 23:34:17 -04:00
Ryan X. Charles 63ce079f2b change from under_scores to camelCase
camelCase is the bitcore way
2014-03-27 19:19:29 -04:00
Manuel Araoz 18630bb2b1 fix browser tests 2014-03-26 12:00:03 -03:00
Manuel Araoz b020fe1e80 add sighash tests 2014-03-26 11:51:28 -03:00
Manuel Araoz 72570719d8 random transaction and script generation 2014-03-25 14:37:23 -03:00
Ryan X. Charles 4319a20676 add test of correct parsing of valid script
Even of OP_PUSHDATA1 says to push 117 bytes, if there are only 75 bytes
following, this should still be pushed to the stack.
2014-03-24 20:27:51 -04:00
Ryan X. Charles 7904efe147 remove redundant and slow test 2014-03-23 15:30:31 -07:00
Ryan X. Charles a4393c0657 update BIP32 to be able to derive pubkeys
...using the new addCompressed interface in Key.js
2014-03-23 15:12:52 -07:00
Ryan X. Charles a686e63b0b fix issue by outputing proper pubkey format
The way I was outputting the pubkeys would be incorrect if the first byte of
one of the coordinates was 0, since it would print the first non-zero byte
first. The solution was to use the standard openssl function that outputs a
public key to oct.
2014-03-23 15:11:32 -07:00
Ryan X. Charles d11361be9e expose group operation
BIP32 needs to be able to add two points on the secp256k1 curve. This
functionality was not already being exposed from OpenSSL in bitcore. I have
added an "addUncompressed" function to the Key class which takes in two points
in uncompressed form, adds them, and returns the result. This is necessary for
BIP32.
2014-03-23 10:35:28 -07:00
Ryan X. Charles b7550fc862 add convenience constructor for making new bip32s
Added the ability to create a new master bip32 with new private key and chain code. The way this works is like this:

var bip32 = new BIP32('mainnet');

or:

var bip32 = new BIP32('testnet');
2014-03-22 16:16:58 -07:00
Ryan X. Charles 47fe12ea19 all vector 2 tests work 2014-03-22 16:16:58 -07:00
Ryan X. Charles ba59d97a73 make things work in the browser by fixing sha512
...had to use jsSHA package to do SHA512 in the browser. Unfortunately it is
quite slow compared to node.
2014-03-22 16:16:58 -07:00
Ryan X. Charles 22b57feb7b Get test vector 1 working in node 2014-03-22 16:16:22 -07:00
Ryan X. Charles fa47ee9984 Merge remote-tracking branch 'matiu/feature/Block-test'
Conflicts:
	util/util.js
2014-03-21 14:57:45 -07:00
Matias Alejo Garcia 02296d9517 fix firefox compatibility issue with buffertools#compare 2014-03-21 18:52:49 -03:00
Matias Alejo Garcia 684be77268 small fixes in block, adapt to browser bignum. remove legacy code 2014-03-21 16:39:38 -03:00
Matias Alejo Garcia 5b95b0f0fd Block.js tests WIP 2014-03-21 16:38:01 -03:00
Manuel Araoz 230420fb00 fix test code for Transaction. Test skipped because they still fail 2014-03-21 12:13:23 -07:00
Manuel Araoz ba92a6b1df refactor and fixes for Transaction, ScriptInterpreter, and Key 2014-03-21 12:13:23 -07:00
Manuel Araoz b227341c12 some Transaction tests fixed (canonical signatures) 2014-03-21 12:13:23 -07:00
Manuel Araoz 7869308784 remove console.log 2014-03-21 12:13:23 -07:00
MattFaus 7097ace9dc Remove console.log() statements 2014-03-21 12:13:23 -07:00
MattFaus 5c65149b2e Mark failing tests with skip() 2014-03-21 12:13:23 -07:00
MattFaus 07f49195ea Update invalid transaction test case 2014-03-21 12:13:23 -07:00
MattFaus 8a8ae5b357 Fix merge problem 2014-03-21 12:13:23 -07:00
MattFaus 4ad36b4fb8 Refactor parsing test data into function, add iteration over invalid transaction tests 2014-03-21 12:13:23 -07:00
MattFaus 5af02e937a Work in progress. I have a problem with the verifyInput() callback calling itself whenever the test assertions throw an exception. I looked at the step and async libraries that are already installed via package.json, but I don't think either of these provide the functionality I need. 2014-03-21 12:13:23 -07:00
MattFaus 7257526de3 Reverting modifications of testdata 2014-03-21 12:13:23 -07:00
MattFaus a2a923fa99 Get Transaction test cases running
I removed the skip over the tx_valid.json file and made some tweaks to get most of the test cases passing.  There are still two test cases that fail, as pointed out by the TODO comment I added above them. Oddly, running the test suite reports 3 failing test cases, but if I delete the two marked with the TODO there are 0 reported failures. So, there may be some kind of interaction with these test cases and the others. More investigation is needed.

I updated the two test cases that were testing transaction `23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63` with the input script I found on blockchain.info https://blockchain.info/tx/23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63. A quick search found one other person who was using this same script (23b397edcccc4483eb271ecad09a94dd63.json) and the test passes now, so I'm not sure why the old script was being used.

All of the other changes are simply re-formatting decimal numbers as hex (i.e. `1` => `0x01`).

Furthermore, I added some code in the test fixture itself to verify each of the inputs.

Test Plan:
`mocha -R spec test/test.Transaction.js`
2014-03-21 12:13:23 -07:00
Manuel Araoz 150a943447 fix private key validation and base58 invalid tests 2014-03-19 19:00:45 -03:00
Manuel Araoz 3cd4e31c31 fix Address validation issue 2014-03-19 18:44:24 -03:00