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.
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.
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.
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)
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.