feat(jsonint): add bigint-safe JSON parsing and mint normalization#519
feat(jsonint): add bigint-safe JSON parsing and mint normalization#519robwoodgate wants to merge 10 commits intomainfrom
Conversation
| error?: string; | ||
| code?: number; | ||
| detail?: string; | ||
| detail?: unknown; |
There was a problem hiding this comment.
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":{}}]}
|
@codex review |
There was a problem hiding this comment.
💡 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".
|
@codex review - is this good to go? |
There was a problem hiding this comment.
💡 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".
5c21274 to
c440f89
Compare
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Rebased to main, no longer stacked. |
|
@codex review |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
fix(mint): preserve normalized melt fields
Normalize melt and restore amounts to prevent bigint leaks.
04fb30e to
19b3e78
Compare
There was a problem hiding this comment.
💡 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".
| case 'object': { | ||
| if (val === null) return 'null'; |
There was a problem hiding this comment.
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 👍 / 👎.
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
src/utils/JSONInt.ts(BigInt‑safe JSON parse/stringify, Crockford-style parser with__proto__protection).JSONIntfor request bodies and response parsing (src/transport/request.ts).src/mint/Mint.ts).JSONIntfrom utils (src/utils/index.ts).Notes / v4 direction
Amountdirectly from Mint responses.