Skip to content

feat(jsonint): add bigint-safe JSON parsing and mint normalization#519

Open
robwoodgate wants to merge 10 commits intomainfrom
bigint-json
Open

feat(jsonint): add bigint-safe JSON parsing and mint normalization#519
robwoodgate wants to merge 10 commits intomainfrom
bigint-json

Conversation

@robwoodgate
Copy link
Collaborator

@robwoodgate robwoodgate commented Feb 24, 2026

Description

Introduces a BigInt-safe JSON parser/stringifier and wires it into request/response handling, with Mint response normalization to keep the public v3 API stable while supporting bigint as "numeric digits" in JSON payloads.

Key changes

  • Add src/utils/JSONInt.ts (BigInt‑safe JSON parse/stringify, Crockford-style parser with __proto__ protection).
  • Wire transport to use JSONInt for request bodies and response parsing (src/transport/request.ts).
  • Add/extend Mint response normalization to accept bigint-compatible wire values while keeping v3 numeric output types stable (src/mint/Mint.ts).
  • Export JSONInt from utils (src/utils/index.ts).
  • Add comprehensive JSONInt tests

Notes / v4 direction

  • This keeps v3 public API types as number, but makes bigint safe on the wire and through internal normalization.
  • v4 can remove the tolerant fallbacks and return Amount directly from Mint responses.

error?: string;
code?: number;
detail?: string;
detail?: unknown;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might technically be breaking for someone importing deep (it's not in public API). But it seems mints can return more than strings, eg:

curl -sS -X POST "https://mint.minibits.cash/Bitcoin/v1/mint/quote/bolt11" \
  -H "Content-Type: application/json" \
  -d '{}'
{"detail":[{"type":"missing","loc":["body","unit"],"msg":"Field required","input":{}},{"type":"missing","loc":["body","amount"],"msg":"Field required","input":{}}]}

@robwoodgate
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d22bf9d96

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@robwoodgate
Copy link
Collaborator Author

@codex review - is this good to go?

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c212744ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c440f89fd3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42018ee0ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42018ee0ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Base automatically changed from bigint-amounts to main March 4, 2026 11:06
@robwoodgate
Copy link
Collaborator Author

Rebased to main, no longer stacked.

@robwoodgate robwoodgate added the needs review PR needs reviewers to give it the green light label Mar 6, 2026
@robwoodgate robwoodgate moved this from Backlog to Needs Review in cashu-ts Mar 6, 2026
@robwoodgate
Copy link
Collaborator Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 066e05ecc0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04fb30e3cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (!responseText) {
throw new Error('Empty response body');
}
return JSONInt.parse(responseText);

Choose a reason for hiding this comment

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

P2 Badge Normalize /v1/keysets numeric fields before returning data

Parsing all successful responses via JSONInt.parse now converts oversized integer tokens to bigint, but Mint.getKeySets() returns that payload directly and downstream wallet logic treats input_fee_ppk as a number (getFeesForKeyset multiplies nInputs * feePPK). When a mint sends a /v1/keysets value above Number.MAX_SAFE_INTEGER, this regression causes runtime Cannot mix BigInt and other types errors in fee computation instead of preserving the v3 number contract, so keyset numeric fields should be normalized (or rejected) at the mint boundary.

Useful? React with 👍 / 👎.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19b3e7826a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +413 to +414
case 'object': {
if (val === null) return 'null';

Choose a reason for hiding this comment

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

P2 Badge Unbox boxed primitives before object serialization

JSONInt.stringify treats every non-null object as a plain object, so boxed primitives like new Number(2), new Boolean(false), and new String('x') are serialized as {}, {}, or indexed objects instead of primitive JSON values. Since src/transport/request.ts now uses this serializer for all request bodies, JS callers who pass boxed values can send malformed payloads to mint endpoints (for example an amount becomes {}), which is a regression from the previous JSON.stringify behavior.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review PR needs reviewers to give it the green light

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

1 participant