-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Max encodable BigInt is smaller than max encodable Number? #109
Comments
Not quite, there is a space within which Line 164 in 7f423b3
Interesting theme though! Let me prattle on a bit about this, I hope it's informative: In CBOR we use the unsigned integer major ( So we end up with two problems for JavaScript:
So cborg will do the following iirc:
On the topic of bigger integers, it is theoretically possible to encode big ints with CBOR, there's a standard for it and a registered tag, which we could have (and still could, maybe) opted to use for DAG-CBOR. Then we'd get all the To date, the answer has always been - use bytes to represent these and have a standard for it (essentially an ADL). And this has grown up in Filecoin and it's the one that's generally recommended for use. Unfortunately it's been standardised around Go's comfort zone, but fortunately it's not too non-standard since it's really just: the byte representation of the integer in big endian, with some special case handling for negatives. Go has a Thankfully for Rust, it also has easy handling of big endian representations to and from bytes to big ints so it can deal with the same thing: https://github.com/filecoin-project/ref-fvm/blob/fce783ab982e914abdecc82a4b9ea07fff98d7d5/shared/src/bigint/bigint_ser.rs#L24-L70 In JS, I never had reason to write one of these but Glif has to deal with them, here's the encoder: https://github.com/glifio/modules/blob/1a1ba285434fd3d37592f1955a9225a53287ecc7/packages/filecoin-number/src/FilecoinNumber.ts#L183-L188, but I can't find a decoder, which is a bit surprising, maybe it's elsewhere. They also use bignumber.js and it would be nice to just be able to use |
I just came across this weird edge case:
The error is thrown during encoding (not decoding as the message suggests), and it seems encodable
Number
ranges are bigger thanBigInt
ranges?The text was updated successfully, but these errors were encountered: