BigNumber encoding hex result doesn't match test cases
See original GitHub issueI haven’t been able to recreate this encoding test case. Is there something I’m doing wrong?
const cbor = require('cbor')
const { BigNumber } = require('bignumber.js')
// This doesn't match the test case here: https://github.com/hildjj/node-cbor/blob/466d01b25959ab1270a409e31453f53b5bba082d/test/cases.js#L695
const num = new BigNumber('9223372036854775807')
console.log(cbor.encode(num).toString('hex')) // c2487fffffffffffffff
// This matches the test case here: https://github.com/hildjj/node-cbor/blob/466d01b25959ab1270a409e31453f53b5bba082d/test/cases.js#L80
const num2 = new BigNumber('18446744073709551616')
console.log(cbor.encode(num2).toString('hex')) // c249010000000000000000
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
BigNumber issue with the AbiCoder. #418 - ethers-io/ethers.js
To solve this, keep in mind to use strings (decimal or 0x prefixed hex) and do all math using big numbers. Here is...
Read more >Convert hex string to int - java - Stack Overflow
The test case I need to satisfy is essentially to Convert "AA0F245C" to int and then back to that string so that I...
Read more >Numerical constants written in hex should allow overflow ...
Let me sum up some observations about this problem and the current state of affairs. 1. The problem with hex int is not...
Read more >Documentation - ethers
The ethers.js library aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem. It was originally...
Read more >math/big - Go Packages
(By always passing in a result value via the receiver, memory use can be much ... that correspond to normal (i.e., not denormal)...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed in version 5.0.2. Use the
collapseBigIntegers
option.generates:
1b7fffffffffffffff
I guess you’re asking for BigNumber integers and ECMAscript bigints to be encoded as normal integers, if they would fit. I’m open to adding an option for that, but since it’s a breaking change as well as breaking round-tripping, I don’t want to make it the default.