aion-web3-avm-abi
Advanced tools
Comparing version 1.2.6-beta.4 to 1.2.6-beta.5
{ | ||
"name": "aion-web3-avm-abi", | ||
"namespace": "aion", | ||
"version": "1.2.6-beta.4", | ||
"version": "1.2.6-beta.5", | ||
"description": "Web3 module encode and decode AVM in/output.", | ||
@@ -12,2 +12,3 @@ "repository": "https://github.com/aionnetwork/aion_web3/tree/avm-support-update/packages/web3-avm-abi", | ||
"aion-web3-utils": "1.1.4", | ||
"bignumber.js": "9.0.0", | ||
"bn.js": "^4.11.8", | ||
@@ -17,3 +18,3 @@ "safe-buffer": "^5.1.2", | ||
}, | ||
"gitHead": "4b48e2dd4a8acc1ef30c0b2fd2f1a08fea0f9c6b" | ||
"gitHead": "7e4ea8091598b8ba2b4d8d46d418276f36fbdc20" | ||
} |
@@ -5,2 +5,4 @@ /** | ||
var BN = require('bn.js'); | ||
//var BigNumber = require('big-number'); | ||
var BigNumber = require('bignumber.js'); | ||
var aionLib = require('aion-lib'); | ||
@@ -139,2 +141,107 @@ var HexCharacters = '0123456789abcdef'; | ||
/*function bigNumber(val) { | ||
//console.log('####start#####'); | ||
//console.log(bigNumberify(val)); | ||
//console.log(BigNumber(val).toString(256)); | ||
//console.log('####end#####'); | ||
//return '0x'+BigNumber(val).toString(16); | ||
//return bigNumberify(val); | ||
var bigint64 = new BigInt64Array(); | ||
return bigint64.of(val); | ||
}*/ | ||
function hexToBn(hex) { | ||
hex = hex.substring(2,hex.length);//remove 0x | ||
if (hex.length % 2) { | ||
hex = '0' + hex; | ||
} | ||
var highbyte = parseInt(hex.slice(0, 2), 16) | ||
var bn = BigInt('0x'+hex); | ||
if (0x80 & highbyte) { | ||
// bn = ~bn; WRONG in JS (would work in other languages) | ||
// manually perform two's compliment (flip bits, add one) | ||
// (because JS binary operators are incorrect for negatives) | ||
bn = BigInt('0b' + bn.toString(2).split('').map(function (i) { | ||
return '0' === i ? 1 : 0 | ||
}).join('')) + BigInt(1); | ||
// add the sign character to output string (bytes are unaffected) | ||
bn = -bn; | ||
} | ||
return bn; | ||
} | ||
function bnToHex(bn) { | ||
var pos = true; | ||
bn = BigInt(bn); | ||
// I've noticed that for some operations BigInts can | ||
// only be compared to other BigInts (even small ones). | ||
// However, <, >, and == allow mix and match | ||
if (bn < 0) { | ||
pos = false; | ||
bn = bitnot(bn); | ||
} | ||
var base = 16; | ||
var hex = bn.toString(base); | ||
if (hex.length % 2) { | ||
hex = '0' + hex; | ||
} | ||
// Check the high byte _after_ proper hex padding | ||
var highbyte = parseInt(hex.slice(0, 2), 16); | ||
var highbit = (0x80 & highbyte); | ||
if (pos && highbit) { | ||
// A 32-byte positive integer _may_ be | ||
// represented in memory as 33 bytes if needed | ||
hex = '00' + hex; | ||
} | ||
return hex; | ||
} | ||
function bitnot(bn) { | ||
// JavaScript's bitwise not doesn't work on negative BigInts (bn = ~bn; // WRONG!) | ||
// so we manually implement our own two's compliment (flip bits, add one) | ||
bn = -bn; | ||
var bin = (bn).toString(2) | ||
var prefix = ''; | ||
while (bin.length % 8) { | ||
bin = '0' + bin; | ||
} | ||
if ('1' === bin[0] && -1 !== bin.slice(1).indexOf('1')) { | ||
prefix = '11111111'; | ||
} | ||
bin = bin.split('').map(function (i) { | ||
return '0' === i ? '1' : '0'; | ||
}).join(''); | ||
return BigInt('0b' + prefix + bin) + BigInt(1); | ||
} | ||
function bigNumber(bn,direction=null) { | ||
if(direction !== null){ | ||
return hexToBn(bn); | ||
}else{ | ||
return "0x"+bnToHex(bn); | ||
} | ||
} | ||
function bufToBn(buf) { | ||
var hex = []; | ||
u8 = Int8Array.from(buf); | ||
u8.forEach(function (i) { | ||
var h = i.toString(16); | ||
if (h.length % 2) { h = '0' + h; } | ||
hex.push(h); | ||
}); | ||
return BigInt('0x' + hex.join('')).toString(10); | ||
} | ||
function bigNumberifyhex(val) { | ||
@@ -338,2 +445,3 @@ return new BN(val,16); | ||
bigNumberify: bigNumberify, | ||
bigNumber: bigNumber, | ||
bigNumberifyhex: bigNumberifyhex, | ||
@@ -346,3 +454,4 @@ getAddress: getAddress, | ||
endianEncoding: endianEncoding, | ||
bufToBn: bufToBn, | ||
defineReadOnly: defineReadOnly | ||
} |
@@ -533,8 +533,5 @@ /* | ||
let length = reader.readByte(); | ||
//let length = reader.readLength(); | ||
/*if (tag !== this.tag) { | ||
this._throwError("invalid tag"); | ||
}*/ | ||
let value = utils.bigNumberify(reader.readBytes(length)); | ||
return value; | ||
let value = utils.bigNumber(utils.hexlify(reader.readBytes(length)),1); | ||
return value;//.toString(16); | ||
} | ||
@@ -547,3 +544,4 @@ | ||
let bytes = utils.arrayify(utils.bigNumberify(value)); | ||
let bytes = utils.arrayify(utils.bigNumber(value)); | ||
if(array){ | ||
@@ -550,0 +548,0 @@ writer.writeByte(0x23); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91018
1621
6
+ Addedbignumber.js@9.0.0
+ Addedbignumber.js@9.0.0(transitive)