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