Skip to content

Commit

Permalink
chore: release version 1.0.0-alpha.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 committed Aug 20, 2024
1 parent c020c4e commit d53f721
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ declare module '@onekeyfe/kaspacore-lib' {
export namespace Transaction {

static class sighash {
static sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod);
// static sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod);
static sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, flags): Buffer;
}
class UnspentOutput {
Expand Down Expand Up @@ -155,7 +155,7 @@ declare module '@onekeyfe/kaspacore-lib' {
fee(amount: number): this;
setVersion(version: number): this;
feePerKb(amount: number): this;
sign(privateKey: PrivateKey|PrivateKey[] | string|string[], sigtype:number, signingMethod:string|undefined): this;
// sign(privateKey: PrivateKey|PrivateKey[] | string|string[], sigtype:number, signingMethod:string|undefined): this;
applySignature(sig: crypto.Signature): this;
addInput(input: Transaction.Input): this;
addOutput(output: Transaction.Output): this;
Expand Down
1 change: 0 additions & 1 deletion lib/crypto/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ BN.One = new BN(1);
BN.Minus1 = new BN(-1);

BN.fromNumber = function(n) {
$.checkArgument(_.isNumber(n));
if (_.isNumber(n)) {
if (n <= 0x1fffffffffffff) {
return new BN(n);
Expand Down
2 changes: 1 addition & 1 deletion lib/transaction/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Output.prototype.inspect = function() {

Output.fromBufferReader = function(br) {
var obj = {};
obj.satoshis = BN.fromNumber(br.readUInt64LEBN()).toString();
obj.satoshis = br.readUInt64LEBN().toString();
var version = br.readUInt16LE();
var size = br.readUInt64LEBN().toNumber();
if (size !== 0) {
Expand Down
13 changes: 11 additions & 2 deletions lib/transaction/unspentoutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var JSUtil = require('../util/js');
var Script = require('../script');
var Address = require('../address');
var Unit = require('../unit');
var BN = require('../crypto/bn');

/**
* Represents an unspent output information: its script, associated amount and address,
Expand Down Expand Up @@ -46,8 +47,16 @@ function UnspentOutput(data) {
var script = new Script(data.scriptPubKey || data.script);
$.checkArgument(!_.isUndefined(data.amount) || !_.isUndefined(data.satoshis),
'Must provide an amount for the output');
var amount = !_.isUndefined(data.amount) ? new Unit.fromBTC(data.amount).toSatoshis() : data.satoshis;
$.checkArgument(_.isNumber(amount), 'Amount must be a number');

var amount;
if (!_.isUndefined(data.amount)) {
amount = BN.fromNumber(data.amount);
amount = amount.mul(new BN(1e8)).toString();
} else {
amount = BN.fromNumber(data.satoshis).toString();
}
$.checkArgument(!amount.includes('.'), 'Amount must be a number');

JSUtil.defineImmutable(this, {
address: address,
txId: txId,
Expand Down
23 changes: 19 additions & 4 deletions lib/util/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

var _ = require('lodash');
var logLevels = require('./log').logLevels;
var BN = require('../crypto/bn');

const UINT64_MAX = new BN('18446744073709551615');

/**
* Determines whether a string contains only hexadecimal values
Expand Down Expand Up @@ -85,10 +88,22 @@ const JSUtil = {
* @return {Boolean}
*/
isNaturalNumber: function isNaturalNumber(value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value &&
value >= 0;
if (typeof value === 'string') {
if (!/^\d*$/.test(value)) {
return false;
}
}

if(typeof value === 'number' || typeof value === 'string'){
try {
var bnValue = BN.fromNumber(value);
return bnValue.lte(UINT64_MAX);
} catch (e) {
return false;
}
}

return false;
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/kaspacore-lib",
"version": "1.0.0-alpha.1",
"version": "1.0.0-alpha.5",
"main": "index.js",
"authors": [
{
Expand Down

0 comments on commit d53f721

Please sign in to comment.