Skip to content
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

wip: bigint decoding #765

Closed
wants to merge 1 commit into from
Closed

wip: bigint decoding #765

wants to merge 1 commit into from

Conversation

krpeacock
Copy link
Contributor

Description

Currently, attempting to encode a small BigInt value throws errors, and makes serialization difficult.

This approach encodes numbers between positive and negative Number.MAX_SAFE_INTEGER as a Number when serializing to CBOR. However, this strategy doesn't allow them to be deserialized as BigInt. Is this a valid approach?

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

  • My changes follow the guidelines in CONTRIBUTING.md.
  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

@krpeacock krpeacock requested a review from a team as a code owner September 18, 2023 17:47
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@dfinity/agent 87.6 KB (+0.27% 🔺)
@dfinity/candid 13.52 KB (0%)
@dfinity/principal 5.15 KB (0%)
@dfinity/auth-client 92.81 KB (+0.29% 🔺)
@dfinity/assets 90.21 KB (+0.28% 🔺)
@dfinity/identity 90.08 KB (+0.3% 🔺)
@dfinity/identity-secp256k1 232.77 KB (+0.12% 🔺)

// Always use a bigint encoding.
if (v > BigInt(0)) {
// Use a bigint encoding for large values
if (v > BigInt(Number.MAX_SAFE_INTEGER)) {
return cbor.value.tagged(2, cbor.value.bytes(fromHex(v.toString(16))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to fix the padding here to make it even length?

@krpeacock krpeacock closed this Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants