Define canonical JSON encoding for unsigned 64-bit integers#343
Define canonical JSON encoding for unsigned 64-bit integers#343robwoodgate wants to merge 1 commit intocashubtc:mainfrom
Conversation
|
When exactly are the amounts bigger than |
Just look at Minibits key amounts: https://mint.minibits.cash/Bitcoin/v1/keys Keys Amounts in millisats (eg melt quotes, amounts in unit Even if not used 99.99% of the time, the wire support must be solid. |
Yeah, I agree that if amounts are listed in msats, then we need this. |
|
|
||
| `UInt64Json` **MAY** be represented as a JSON integer number or a base-10 decimal string. | ||
|
|
||
| Implementations **MUST** accept both forms. |
There was a problem hiding this comment.
If we want to encourage a single standard (decimal string) over time, we could tweak:
| Implementations **MUST** accept both forms. | |
| Implementations **MUST** accept both forms, and **SHOULD** encode values as decimal strings. |
We already consistently use string amounts in the /v1/keys api, so this would be a continuation of that precedent.
|
I think this is too excessive. NUT-00 could state that all amounts are uint64 and we could leave the rest as is. |
When you say 'uint64', do you mean non-quoted integers? As mentioned by others, key amounts are quoted currently , but fees are non-quoted. Both of those, I think, make sense as fees can't realistically get very big |
Key amounts ARE all strings, and that is perfect. Not suggesting a change there at all. In a perfect world, ALL u64 amounts would be represented as strings in JSON. The issue is "amounts" (sums of key amounts), which currently transport as numeric digits, and which CAN be > 2^53-1 because a) some keys are already larger than that, and b) combinations of proofs could go over the limit in total. Especially with millisat (or in future, nanosat) amounts. Fee amounts can stay as numeric digits, as it would be crazy if fees went over the limit. |


The NUTs define amounts as unsigned 64-bit integers, but the JSON wire encoding is ambiguous.
JSON has no integer type, and many clients parse JSON numbers via float-like defaults. This can cause cross-language divergence and precision loss for large values (e.g, in environments where JSON numbers use IEEE-754).
This PR defines a canonical
UInt64Jsonformat, which is backwards compatible and precision safe across runtimes.Simply:
This applies to
int/u64fields across the protocol, including amounts in Proofs, Blinded Messages, and request/response payloads.Fee fields are unchanged to keep the change minimal, but we could include all int/u64 JSON fields for consistency.