Message methods should accept more argument types
For example, sign could check if privateKey is a String or Buffer and convert accordingly. I can add these, but I'll wait for #2 to be merged to avoid any conflicts.
+1!
+1
I'm working on this now. Would it be best to call a new constructor and let that handle the conversion? The constructor would also throw a TypeError for bad arguments.
Message.prototype.sign = function sign(privateKey) {
privateKey = new PrivateKey(privateKey);
...
}
I'd use PrivateKey.fromString() and PrivateKey.fromBuffer() and throw an error early. The code path that is taken within type recognition in PrivateKey (and others) can be unpredictable, and lead to some very strange bugs that are not very clear to what went wrong.
Likewise, it may be better to only accept one type of private key, and have less automatic type handling, for similar reasons. Type handling can be done prior to that and will be more visible and flexible to implementation.
There are multiple was that a private key can be represented as a string, and thus could be better handled prior via using:
var privateKey = bitcore.PrivateKey.fromWIF(someWIF); //wif
// or
var privateKey = bitcore.PrivateKey.fromString(someString); //hexa