Commit Graph

298 Commits

Author SHA1 Message Date
Manuel Araoz
c06c81e27b fixing tests 2014-11-20 18:19:48 -03:00
Manuel Araoz
f0a4aebdfb reorder tests 2014-11-20 18:08:31 -03:00
Manuel Araoz
a9d029341d remove extras 2014-11-20 13:31:51 -03:00
Manuel Araoz
6f2913eed4 fix references 2014-11-20 11:50:23 -03:00
Manuel Araoz
54fa31c85d remove crypto 2014-11-18 18:59:31 -03:00
Eric Martindale
6102374875 Full suite of working tests for Identities. 2014-10-06 18:03:20 -04:00
Eric Martindale
14748ae2b5 Make more tests pass with Identity(). 2014-10-06 17:54:20 -04:00
Eric Martindale
4b6e9aaf03 Improve tests. 2014-10-06 15:40:30 -04:00
Eric Martindale
75cf4c4f9a tidy up identity class, add tests. 2014-10-02 22:27:18 -04:00
Eric Martindale
f01ebd97d2 Buffers, identities, and randomNumbers. 2014-10-01 21:08:06 -04:00
Ryan X. Charles
f54edfb618 Varint(BN()) convenience
...and add some tests for the various constructor conveniences
2014-09-23 22:19:01 -07:00
Ryan X. Charles
8e85eba08b pushin, pushout
Add convenience methods for adding new inputs and outputs.
2014-09-23 22:09:41 -07:00
Ryan X. Charles
c07d509623 initialize transaction
In order to add convenience methods to a transaction, such as pushing new
inputs and outputs, we need to first have the notion of an initialized
transaction, which is actually not blank. An initialized transaction just has
default values for everything, such as no inputs and no outputs, and default
version and nlocktime.
2014-09-23 22:01:30 -07:00
Ryan X. Charles
b37e39abca Script().writeXX convenience methods
Script().writeOp('OP_CHECKMULTISIG'), or...
Script().writeOp(174), or...
Script().writeBuffer([push data buffer]), or...
Script().write([op string, number, or push data buffer])

These convenience methods let you easily write a script.
2014-09-23 21:28:03 -07:00
Ryan X. Charles
d689dbb77e speed up random test slightly
...by caching hexes. Also, correct the "1000" typo - it's actually 100.
2014-09-23 20:28:16 -07:00
Ryan X. Charles
4f71535869 StealthTx
For spotting transactions to which you have the stealth key (or at least the
scan key) and creating transactions to a stealth address. So far it is only
partially working - you can see if a transaction is a stealth transaction (or
at least one of a limited kind of stealth transactions), and you can see that
you do not have the stealth key to spend one of these transactions. However, I
have not yet tested whether you can see a stealth transaction that you actually
have the key to. Also, it is not yet easy to spend to a stealth address.
2014-09-23 16:54:52 -07:00
Ryan X. Charles
4fabad21a1 get rid of obsolete 'bitcore' stealth addr format 2014-09-23 14:27:48 -07:00
Ryan X. Charles
22b87325d7 make Dark Wallet buffer/string formats the default
and rename the old functions to "bitcore buffer" and "bitcore string"
2014-09-23 14:27:48 -07:00
Ryan X. Charles
96df77429f add support for Dark Wallet-style addresses
These functions are prefixed DW which stands for Dark Wallet. The code for the
Dark Wallet address format can be found here:

https://github.com/darkwallet/darkwallet/blob/develop/js/util/stealth.js

Note that I deliberately support only the simplest possible format, which is
where there is only one payload pubkey and the prefix is blank. I should now go
back and replace my old toString, fromString, toBuffer, fromBuffer functions
with these Dark Wallet versions, since they are much more well-thought out than
mine.
2014-09-22 18:23:10 -07:00
Ryan X. Charles
9b8ce05b15 BufferWriter().toBuffer convenience method
It does the same thing as .concat(), but may be easier to remember, since the
rest of the library uses the ".toBuffer()" convention
2014-09-22 17:09:53 -07:00
Ryan X. Charles
792e8080c8 classify pubkeyhash and scripthash scripts
...both the "in" (ScriptSig) and "out" (ScriptPubkey)
2014-09-22 16:04:06 -07:00
Ryan X. Charles
5c7149aeab Stealthkey toJSON/fromJSON 2014-09-22 14:45:41 -07:00
Ryan X. Charles
d6e3266179 toJSON/fromJSON for privkey, pubkey, keypair 2014-09-22 13:55:40 -07:00
Ryan X. Charles
e984736736 allow bufs in constructors
For Transaction, Block and Blockheader. This is a convenience so if you happen
to have the buffer for one of these, you can make a new one like this:

Transaction(txbuf);

Rather than having to do this:

Transaction().fromBuffer(txbuf);
2014-09-22 13:07:39 -07:00
Ryan X. Charles
1516ad3012 remove unused addressString variable 2014-09-22 12:52:09 -07:00
Ryan X. Charles
e6a424303e remove unused base58check dependency 2014-09-22 12:51:18 -07:00
Ryan X. Charles
1bda566679 stealth address to/from JSON 2014-09-22 12:48:13 -07:00
Ryan X. Charles
27fbdb42ad isOpReturn
standard OP_RETURN scripts contain either just an OP_RETURN or an OP_RETURN
followed by a single pushdata OP with not more than 40 bytes.
2014-09-19 21:59:19 -07:00
Ryan X. Charles
ffdfe0ce83 add fromString test for bip32
...since it was lacking any tests
2014-09-19 21:02:57 -07:00
Ryan X. Charles
cc3196085f add .hash() function for a block
This is the plain old hash, which is a double sha256. The id of a block is the
reverse of this.
2014-09-19 17:29:40 -07:00
Ryan X. Charles
aff3992ffb transaction hash and id
...the hash is the usual hash, and the id is the reverse of that, which is what
is usually graphically displayed by bitcoind.
2014-09-19 17:25:35 -07:00
Ryan X. Charles
40d17c5180 block id
The block id is the reverse of the double sha256 hash of the blockheader.
2014-09-19 17:08:44 -07:00
Ryan X. Charles
cfd509f859 make receivePubkey compatible with dark wallet
I had been using this formula for the receiveKeypair:

scanKeypair + payloadKeypair + sharedKeypair

However, Dark Wallet uses this formula:

payloadKeypair + sharedKeypair

It is not actually necessary to add the scanKeypair in order to have all the
features of stealth addresses, at least as far as I can tell. So in order to
bring my implementation closer to Dark Wallet's, I have removed the scanKeypair
from this calculation.
2014-09-19 14:32:32 -07:00
Ryan X. Charles
e11019a083 toJSON, fromJSON
Every object should have toJSON and fromJSON methods so you can have a reliable
way to store and retrieve objects.
2014-09-18 17:52:02 -07:00
Ryan X. Charles
f17d604e44 Address().fromHashbuf() convenience method
...useful for when you have the pubkeyhash, but not the version byte.
2014-09-18 15:18:53 -07:00
Ryan X. Charles
d2bc960744 fix capitalization error on case-sensitive filesystems 2014-09-17 17:02:40 -07:00
Ryan X. Charles
6fe5d416a0 fix capitalization error on case-sensitive filesystems 2014-09-17 17:00:32 -07:00
Ryan X. Charles
cf5b2f1250 varint -> vi canonical spelling 2014-09-17 16:48:23 -07:00
Ryan X. Charles
4a21a9551c fromX is actually static
...should add an instance method in the future
2014-09-17 16:32:38 -07:00
Ryan X. Charles
f727c5ad25 fix varint test broken in browser 2014-09-17 16:03:57 -07:00
Ryan X. Charles
0212e4bd4c replace .buffer with .read 2014-09-17 15:49:45 -07:00
Ryan X. Charles
6e1dfd3003 allow bufferreader.read to specify length
...to be more symmetric with the write function of bufferwriter
2014-09-17 15:41:30 -07:00
Ryan X. Charles
aee8547093 add fromString method for library consistency 2014-09-17 15:32:14 -07:00
Ryan X. Charles
6494ca5076 convenience: varint -> vi 2014-09-17 15:27:12 -07:00
Ryan X. Charles
5f21059bf8 more convenient names 2014-09-17 15:20:01 -07:00
Ryan X. Charles
9473bdf9b0 more convenient name 2014-09-17 15:15:56 -07:00
Ryan X. Charles
7390b15f89 add set function to bip32 2014-09-17 15:11:16 -07:00
Ryan X. Charles
0641184e84 support string input in constructor 2014-09-17 15:02:11 -07:00
Ryan X. Charles
c41419b6ef use buffer functions
...instead of adhoc uint functions
2014-09-17 14:49:17 -07:00
Ryan X. Charles
78ef76eb2f more convenient constructor
...allow inputing strings or buffers in the constructor.
2014-09-17 14:29:53 -07:00
Ryan X. Charles
40ea68a3ff more convenient Base58 constructor 2014-09-17 14:26:19 -07:00
Ryan X. Charles
ac85264a28 Address().fromBuffer(buf); 2014-09-17 14:22:18 -07:00
Ryan X. Charles
8a52e6c316 Block 2014-09-16 18:42:11 -07:00
Ryan X. Charles
0d180810de Blockheader 2014-09-16 17:28:00 -07:00
Ryan X. Charles
7ea66e032f add real-world tx to transaction test 2014-09-16 14:39:51 -07:00
Ryan X. Charles
5b25679e15 Transaction 2014-09-16 14:35:26 -07:00
Ryan X. Charles
6c42969d01 improve error message 2014-09-16 11:44:51 -07:00
Ryan X. Charles
6e9755b009 sign, verify convenience functions 2014-09-16 11:34:28 -07:00
Ryan X. Charles
ed335f35f7 throw error if hashbuf is not 32 bytes 2014-09-16 11:33:49 -07:00
Ryan X. Charles
ced35a07eb Txout 2014-09-15 18:38:21 -07:00
Ryan X. Charles
42130c78a0 Txin 2014-09-15 17:08:09 -07:00
Ryan X. Charles
4594cbb9e7 add bn support to varint class 2014-09-15 15:29:39 -07:00
Ryan X. Charles
3fa651e553 disable examples in browser 2014-09-15 15:09:50 -07:00
Ryan X. Charles
f6a8878aa2 Varint class
...will be useful in transactions. Note that we already have a primitive
understanding of Varints in the BufferReader and BufferWriter classes. However,
the new Varint class is a varint object which actually depends on BufferReader
and BufferWriter for reading and writing varints. This class is for keeping
track of the raw buffer that is read in from a buffer.
2014-09-15 15:05:54 -07:00
Ryan X. Charles
4bb9105b2d varInt -> varint
I don't like having to capitalize things unnecessarily
2014-09-15 14:41:46 -07:00
Ryan X. Charles
30c96721a0 varIntNum 2014-09-15 14:36:31 -07:00
Ryan X. Charles
d363956ba1 add readVarIntBuf function
...will be useful for new Varint class
2014-09-15 14:27:42 -07:00
Ryan X. Charles
3c668c9cf0 readVarInt -> readVarIntNum
"varInt" refers to the varInt object, which is not actually implemented yet.
This function should therefore really be called readVarIntNum.
2014-09-15 14:19:08 -07:00
Ryan X. Charles
8e959426e2 support reading varInt nums up to js precision
Javascript only supports 64 bit floating points, which have uint precision up
to Math.pow(2, 53). We now support reading variable sized numbers up to that
size. If the number is bigger than that, then we need to use BN.
2014-09-15 13:58:24 -07:00
Ryan X. Charles
543762bc67 fromBuffer convenience function for pubkey 2014-09-15 11:32:39 -07:00
Ryan X. Charles
385edbcc92 simplify ECIES interface
the toKeypair doesn't really need to be a keypair. upon encrypting, it merely
needs to be a pubkey. and upon decrypting, it needs to be a privkey.
2014-09-15 11:19:18 -07:00
Ryan X. Charles
8dc6a5023a test the case when no fromkeypair is used
...during encryption, and make sure you can still decrypt the message.
2014-09-15 10:52:32 -07:00
Ryan X. Charles
fbfa64582c autogenerated fromkeypair if not present 2014-09-15 10:43:14 -07:00
Ryan X. Charles
4a027e260a Address().fromScript(script)
It is convenient to be able to derive an address directly from a script for
p2sh transactions.
2014-09-12 17:49:01 -07:00
Ryan X. Charles
79d79012d4 fix bug where you can't use isForMe without payloadKeypair
It should be possible to check to see if a message isForMe with only the
scanKeypair, and not the payloadKeypair. There was a bug where only the
scanKeypair was being used to produce the receiveKeypair, but this was a
mistake. Both the scanPubkey and payloadPubkey should be necessary to produce
the receivePubkey, and both the scanPrivkey and payloadPrivkey should be
necessary to produce the receivePrivkey. If an online computer has only the
public keys of both (and the scanPrivkey), then that is good enough to check
for isForMe.
2014-09-12 17:24:00 -07:00
Ryan X. Charles
88f3690ef6 StealthMessage example 2014-09-12 12:55:11 -07:00
Ryan X. Charles
5a86a1a5c6 StealthMessage
This code should be regarded as being a proof-of-concept, and needs more review
before being used in production code. At least one thing is guaranteed to
change, and that is the format of a stealth address.
2014-09-10 14:00:53 -07:00
Ryan X. Charles
74549a53ec key -> keypair
Since the class has been renamed Key -> Keypair, instances should be renamed
key -> keypair.
2014-09-02 16:36:21 -07:00
Ryan X. Charles
219aa528c8 AsReceiver implied 2014-09-02 15:54:24 -07:00
Ryan X. Charles
558a7672ef Stealthkey AsSender functions obsolete
use StealthAddress instead
2014-09-02 15:28:32 -07:00
Ryan X. Charles
d1a570135d getSharedKeypair & getReceivePubkey 2014-09-02 15:25:16 -07:00
Ryan X. Charles
48ae69cab0 convenience: StealthAddress(str) or StealthAddress(buf) 2014-09-02 14:23:11 -07:00
Ryan X. Charles
36fd6b2d9c take address stuff out of stealthkey
...that is what StealthAddress is now for
2014-09-02 12:53:41 -07:00
Ryan X. Charles
139fe02355 StealthAddress 2014-09-02 12:48:36 -07:00
Ryan X. Charles
258dab9d6d convenience: Stealth(payloadKeypair, scanKeypair) 2014-09-02 12:08:33 -07:00
Ryan X. Charles
a768755764 convenience: new Pubkey(point) 2014-09-01 21:16:10 -07:00
Ryan X. Charles
6f56c8d1fc convenience: new Privkey(bn) 2014-09-01 21:13:44 -07:00
Ryan X. Charles
ef3a89f254 add Signature(r, s) convenience 2014-09-01 21:08:16 -07:00
Ryan X. Charles
3b2b725070 Script().fromString(str)
...the format of fromString and toString are deliberately not compatible with
bitcoind. The format here is supposed to be both human-readable, and
byte-for-byte isomorphic to the binary representation. In the future we will
need to add support for bitcoind-like strings, both for the test data (e.g.,
script_invalid.json) or for the bitcoind console style.
2014-09-01 19:42:20 -07:00
Ryan X. Charles
6375941ef8 script.toString() 2014-09-01 18:31:02 -07:00
Ryan X. Charles
e6af57f4fa script.toBuffer(); 2014-09-01 18:01:17 -07:00
Ryan X. Charles
378dc923ef preserve claimed length and op code
When parsing OP_PUSHDATAX commands, the the length of data might not require
the size integer of OP_PUSHDATAX. For instance, you might write 1 byte, and yet
use OP_PUSHDATA4. We need to record which OP_PUSHDATAX was used so that when we
write the buffer back out, we can write the same one. Also, the claimed length
may be different. For instance, we may OP_PUSHDATA of length 100 to the stack,
but there may only be 50 bytes left in the script. In that case, buf.length and
chunk.len will be different. I'm not sure if that would be considered a valid
script, but in any case, for script analysis, we need both values.
2014-09-01 17:27:39 -07:00
Ryan X. Charles
e3aa93614e one more test to make sure things are working 2014-09-01 16:44:27 -07:00
Ryan X. Charles
697b3e5009 Script().fromBuffer(buf)
...code heavily inspired/copied from bitcore
2014-09-01 16:41:07 -07:00
Ryan X. Charles
8b3ad7ac85 read a buffer, like slicing while iterating pos 2014-09-01 16:40:31 -07:00
Ryan X. Charles
572582938f more convenient bufferreader 2014-09-01 15:53:26 -07:00
Ryan X. Charles
15801773e3 the beginnings of script 2014-09-01 15:45:03 -07:00
Ryan X. Charles
6a26813955 p2sh -> scripthash
more appealing and memorable name
2014-09-01 12:06:18 -07:00
Ryan X. Charles
a0150f82ef fromNumber, toNumber, fromString, toString
...like the rest of the library.
2014-08-31 20:38:39 -07:00
Ryan X. Charles
03578e2ba5 Opcode
...code from bitcore
2014-08-29 19:24:51 -07:00
Ryan X. Charles
c59013eb46 remove useless Address dependency from Keypair
to get an address from a key, just do Address().fromPubkey(key.pubkey)
2014-08-29 15:42:30 -07:00
Ryan X. Charles
f028b6b913 Stealth -> Stealthkey
More explanatory. Will break up into separate Stealthkey, StealthAddress, and
StealthMessage classes.
2014-08-29 14:34:01 -07:00
Ryan X. Charles
32fabd0c0f Key -> Keypair
"Keypair" is a more explanatory name, and also should be less confused with
other kinds of keys (particularly "cipher keys", which are the keys used in
symmetric block ciphers, especially AES).
2014-08-29 14:18:56 -07:00
Ryan X. Charles
40a2007e18 confusingly named SymEnc -> accurately named AESCBC
This will also further discourage use amongst anyone who doesn't understand
what this is.
2014-08-29 13:07:49 -07:00
Ryan X. Charles
bdb8daaf07 remove redundant "test." from test names 2014-08-29 13:01:05 -07:00
Ryan X. Charles
faa7a81cac Key().fromPrivkey() 2014-08-29 12:43:55 -07:00
Ryan X. Charles
40e8dfec06 compressed by default with fromRandom 2014-08-29 12:38:43 -07:00
Ryan X. Charles
5313085773 Pubkey().fromPrivkey() 2014-08-28 20:19:30 -07:00
Ryan X. Charles
c39acbcca3 Privkey().fromRandom() 2014-08-28 19:27:22 -07:00
Ryan X. Charles
280578d641 network -> networkstr
...for compatibility with address, and to make the types obvious
2014-08-28 17:53:11 -07:00
Ryan X. Charles
e2824035bb Pubkey.prototype.set 2014-08-28 17:41:38 -07:00
Ryan X. Charles
356ddcfa4e test invalid address 2014-08-28 17:32:08 -07:00
Ryan X. Charles
ac47796acd .isValid() is more convenient than .validate() 2014-08-28 17:30:32 -07:00
Ryan X. Charles
109f31cfdb Privkey.prototype.set 2014-08-28 17:26:56 -07:00
Ryan X. Charles
6b4bc4c49c Stealth.prototype.set 2014-08-28 17:00:34 -07:00
Ryan X. Charles
0ca390d45b Message.prototype.set 2014-08-28 16:42:47 -07:00
Ryan X. Charles
a5f79c7651 Signature.prototype.set 2014-08-28 16:38:21 -07:00
Ryan X. Charles
28d3a40704 Key.prototype.set 2014-08-28 16:18:36 -07:00
Ryan X. Charles
75c1503a92 ECDSA.prototype.set 2014-08-28 16:07:28 -07:00
Ryan X. Charles
0d9b54711e BufferWriter.prototype.set 2014-08-28 16:02:24 -07:00
Ryan X. Charles
3475ee973c BufferReader.prototype.set 2014-08-28 15:52:32 -07:00
Ryan X. Charles
3919b24685 make bip32 mostly compatible with the rest of the lib
the constructor shouldn't do much. just set some varibles. in this case, i have
yet to write the code that sets the varibles. but better this than
autogenerating a new random BIP32. for that, call fromRandom()
2014-08-28 15:38:29 -07:00
Ryan X. Charles
d50d766352 Base58Check.prototype.set 2014-08-28 15:31:06 -07:00
Ryan X. Charles
da8989b649 add set function to Base58 2014-08-28 15:27:58 -07:00
Ryan X. Charles
6b7592d67b add address validation convenience function 2014-08-28 15:22:03 -07:00
Ryan X. Charles
f52e679f93 refactor address - use "set" function
...intend for this to become standard throughout the lib
2014-08-28 15:18:48 -07:00
Ryan X. Charles
cc316e9455 ECIES 2014-08-28 14:43:21 -07:00
Ryan X. Charles
6f54d4cde6 Encryption -> SymEnc
This is more explanatory ("symmetric encryption") and also does not encourage
its use for people who don't know what they're doing. (It should only be used
in combination with some type of message authentication.)
2014-08-28 11:10:40 -07:00
Ryan X. Charles
1cb2f900af symmetric encryption convenience class 2014-08-27 17:15:10 -07:00
Ryan X. Charles
ae02a878dd woops ... actually check that output is correct 2014-08-27 15:57:46 -07:00
Ryan X. Charles
ed826bf95c add test to make sure AES works with CBC 2014-08-27 15:37:54 -07:00
Ryan X. Charles
a8e3e0b993 static methods start with @ in tests 2014-08-27 14:37:28 -07:00
Ryan X. Charles
ce98b87d90 add it description 2014-08-27 14:37:01 -07:00
Ryan X. Charles
429a2d099f test decrypt 2014-08-27 14:36:23 -07:00
Ryan X. Charles
73b904ce21 CBC decrypt 2014-08-25 21:16:33 -07:00
Ryan X. Charles
dfa190b5a5 blockbufs2buf 2014-08-25 21:02:00 -07:00
Ryan X. Charles
ae319ffcbc unpad 2014-08-25 20:53:29 -07:00
Ryan X. Charles
a6e74666c8 decrypt blocks 2014-08-25 20:38:39 -07:00
Ryan X. Charles
eddeb60d7d decrypt block 2014-08-25 20:25:18 -07:00
Ryan X. Charles
97e40f9ac6 rename keybuf -> cipherkeybuf
...since this use of "key" is very different than the public/private key pair
that is key.js
2014-08-25 16:38:53 -07:00
Ryan X. Charles
a09cac4ba6 block cipher should support "encrypt" and "decrypt" 2014-08-25 16:30:04 -07:00
Ryan X. Charles
12f29a9b52 CBC encryption 2014-08-25 16:25:01 -07:00
Ryan X. Charles
38d9ab65af xor buffers ... will be useful for CBC 2014-08-24 20:51:56 -07:00
Ryan X. Charles
db7ae4c6d1 static tests start with @ 2014-08-24 20:37:16 -07:00
Ryan X. Charles
1b1ecd989a pkcs7
This is a standard algorithm for the purposes of padding a block for a block
cipher. It will be used in CBC, which in turned will be used with AES for
ECIES.
2014-08-24 19:38:20 -07:00
Ryan X. Charles
1dead4cbc4 AES 2014-08-24 17:33:09 -07:00
Ryan X. Charles
a0ad59fbac static tests start with @ 2014-08-24 14:51:55 -07:00
Ryan X. Charles
76e8136b45 prefix static methods with @ in tests
...instance methods prefixed with #
2014-08-24 14:29:35 -07:00
Ryan X. Charles
b81e4c75fb put static methods at the top 2014-08-24 14:27:47 -07:00
Ryan X. Charles
bc94a5cb59 sign/verify with uncompressed pubkeys 2014-08-22 19:43:32 -07:00