@onekeyfe/kaspa-core-lib 1.0.0-alpha.2 → 1.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/privatekey.js
CHANGED
|
@@ -379,7 +379,7 @@ PrivateKey.prototype.toPublicKey = function () {
|
|
|
379
379
|
if (!this._pubkey) {
|
|
380
380
|
//this._pubkey = PublicKey.fromPrivateKey(this);
|
|
381
381
|
let publicKey = secp256k1.getPublicKey(this.toString(), true);
|
|
382
|
-
console.log("publicKey", Buffer.from(publicKey).toString('hex'));
|
|
382
|
+
// console.log("publicKey", Buffer.from(publicKey).toString('hex'));
|
|
383
383
|
this._pubkey = new PublicKey(Buffer.from(publicKey), {
|
|
384
384
|
network: this.network.name,
|
|
385
385
|
});
|
|
@@ -80,7 +80,7 @@ Output.prototype.invalidSatoshis = function() {
|
|
|
80
80
|
if(!BN.fromString(this._satoshis).eq(this._satoshisBN)) {
|
|
81
81
|
return 'transaction txout satoshis has corrupted value';
|
|
82
82
|
}
|
|
83
|
-
if(BN.fromString(this._satoshis).lt(
|
|
83
|
+
if(BN.fromString(this._satoshis).lt(BN.Zero)) {
|
|
84
84
|
return 'transaction txout negative';
|
|
85
85
|
}
|
|
86
86
|
return false;
|
|
@@ -226,7 +226,7 @@ Transaction.prototype.getSerializationError = function(opts) {
|
|
|
226
226
|
|
|
227
227
|
var unspent = this._getUnspentValue();
|
|
228
228
|
var unspentError;
|
|
229
|
-
if (unspent.lt(
|
|
229
|
+
if (unspent.lt(BN.Zero)) {
|
|
230
230
|
if (!opts.disableMoreOutputThanInput) {
|
|
231
231
|
unspentError = new errors.Transaction.InvalidOutputAmountSum();
|
|
232
232
|
}
|
|
@@ -249,7 +249,7 @@ Transaction.prototype._hasFeeError = function(opts, unspent) {
|
|
|
249
249
|
|
|
250
250
|
if (!opts.disableLargeFees) {
|
|
251
251
|
var maximumFee = Math.floor(Transaction.FEE_SECURITY_MARGIN * this._estimateFee());
|
|
252
|
-
if (unspent
|
|
252
|
+
if (unspent.gt(new BN(maximumFee))) {
|
|
253
253
|
if (this._missingChange()) {
|
|
254
254
|
return new errors.Transaction.ChangeAddressMissing(
|
|
255
255
|
'Fee is too large and no change address was provided'
|
|
@@ -262,7 +262,7 @@ Transaction.prototype._hasFeeError = function(opts, unspent) {
|
|
|
262
262
|
}
|
|
263
263
|
if (!opts.disableSmallFees) {
|
|
264
264
|
var minimumFee = Math.ceil(this._estimateFee() / Transaction.FEE_SECURITY_MARGIN);
|
|
265
|
-
if (unspent
|
|
265
|
+
if (unspent.lt(new BN(minimumFee))) {
|
|
266
266
|
return new errors.Transaction.FeeError.TooSmall(
|
|
267
267
|
'expected more than ' + minimumFee + ' but got ' + unspent
|
|
268
268
|
);
|
|
@@ -970,8 +970,8 @@ Transaction.prototype._updateChangeOutput = function() {
|
|
|
970
970
|
}
|
|
971
971
|
var available = this._getUnspentValue();
|
|
972
972
|
var fee = this.getFee();
|
|
973
|
-
var changeAmount = available.sub(fee);
|
|
974
|
-
if (changeAmount.gt(
|
|
973
|
+
var changeAmount = available.sub(new BN(fee));
|
|
974
|
+
if (changeAmount.gt(BN.Zero)) {
|
|
975
975
|
this._changeIndex = this.outputs.length;
|
|
976
976
|
this._addOutput(new Output({
|
|
977
977
|
script: this._changeScript,
|
|
@@ -1026,7 +1026,7 @@ Transaction.prototype._estimateFee = function() {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
var fee = Math.ceil(getFee(estimatedSize));
|
|
1028
1028
|
var feeWithChange = Math.ceil(getFee(estimatedSize) + getFee(Transaction.CHANGE_OUTPUT_MAX_SIZE));
|
|
1029
|
-
if (!this._changeScript || available.lte(feeWithChange)) {
|
|
1029
|
+
if (!this._changeScript || available.lte(BN.fromNumber(feeWithChange))) {
|
|
1030
1030
|
return fee;
|
|
1031
1031
|
}
|
|
1032
1032
|
return feeWithChange;
|