Improve naming of ECKey/ECPubKey formatters. close vbuterin/bitcoinjs-lib#13
This commit is contained in:
parent
e08533ff7a
commit
56bb0a0c6d
1 changed files with 43 additions and 19 deletions
62
src/eckey.js
62
src/eckey.js
|
@ -52,22 +52,36 @@ ECKey.prototype.getPub = function() {
|
||||||
return ECPubKey(ecparams.getG().multiply(this.priv),this.compressed)
|
return ECPubKey(ecparams.getG().multiply(this.priv),this.compressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
ECKey.prototype.export = function (format) {
|
/**
|
||||||
var bytes = this.priv.toByteArrayUnsigned();
|
* @deprecated Reserved keyword, factory pattern. Use toHex, toBytes, etc.
|
||||||
if (this.compressed)
|
*/
|
||||||
bytes.push(1)
|
ECKey.prototype['export'] = function(format) {
|
||||||
return format === "base58" ? base58.checkEncode(bytes,128)
|
format || (format = 'hex')
|
||||||
: format === "wif" ? base58.checkEncode(bytes,128)
|
return this['to' + format.substr(0, 1).toUpperCase() + format.substr(1)]()
|
||||||
: format === "bin" ? conv.bytesToString(bytes)
|
|
||||||
: format === "bytes" ? bytes
|
|
||||||
: format === "hex" ? conv.bytesToHex(bytes)
|
|
||||||
: bytes
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ECKey.prototype.toString = function (format) {
|
ECKey.prototype.toBin = function() {
|
||||||
return ''+this.export(format)
|
return conv.bytesToString(this.toBytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.toBase58 = function() {
|
||||||
|
return base58.checkEncode(this.toBytes(), 128)
|
||||||
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.toWif = ECKey.prototype.toBase58
|
||||||
|
|
||||||
|
ECKey.prototype.toHex = function() {
|
||||||
|
return conv.bytesToHex(this.toBytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.toBytes = function() {
|
||||||
|
var bytes = this.priv.toByteArrayUnsigned();
|
||||||
|
if (this.compressed) bytes.push(1)
|
||||||
|
return bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
ECKey.prototype.toString = ECKey.prototype.toBase58
|
||||||
|
|
||||||
ECKey.prototype.getBitcoinAddress = function(v) {
|
ECKey.prototype.getBitcoinAddress = function(v) {
|
||||||
return this.getPub().getBitcoinAddress(v)
|
return this.getPub().getBitcoinAddress(v)
|
||||||
}
|
}
|
||||||
|
@ -116,15 +130,25 @@ ECPubKey.prototype.multiply = function(key) {
|
||||||
return ECPubKey(this.pub.multiply(ECKey(key).priv),this.compressed)
|
return ECPubKey(this.pub.multiply(ECKey(key).priv),this.compressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPubKey.prototype.export = function(formt) {
|
ECPubKey.prototype['export'] = function(format) {
|
||||||
var o = this.pub.getEncoded(this.compressed)
|
format || (format = 'hex')
|
||||||
return formt == 'hex' ? conv.bytesToHex(o)
|
return this['to' + format.substr(0, 1).toUpperCase() + format.substr(1)]()
|
||||||
: formt == 'bin' ? conv.bytesToString(o)
|
|
||||||
: o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPubKey.prototype.toString = function (format) {
|
ECPubKey.prototype.toBytes = function() {
|
||||||
return ''+this.export(format)
|
return this.pub.getEncoded(this.compressed)
|
||||||
|
}
|
||||||
|
|
||||||
|
ECPubKey.prototype.toHex = function() {
|
||||||
|
return conv.bytesToHex(this.toBytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
ECPubKey.prototype.toBin = function() {
|
||||||
|
return conv.bytesToString(this.toBytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
ECPubKey.prototype.toString = function() {
|
||||||
|
return this.getBitcoinAddress().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
ECPubKey.prototype.getBitcoinAddress = function(v) {
|
ECPubKey.prototype.getBitcoinAddress = function(v) {
|
||||||
|
|
Loading…
Reference in a new issue