Skip to content

Adds numberFormat to txps#4176

Open
kajoseph wants to merge 11 commits into
bitpay:masterfrom
kajoseph:fixClientServerNumberRounding
Open

Adds numberFormat to txps#4176
kajoseph wants to merge 11 commits into
bitpay:masterfrom
kajoseph:fixClientServerNumberRounding

Conversation

@kajoseph
Copy link
Copy Markdown
Collaborator

@kajoseph kajoseph commented May 24, 2026

Description

There is a lingering bug where signing transaction proposals, particularly EVM, would fail with an error Server response could not be verified. Turns out, this is due to large number rounding slightly differing between the React Native and NodeJS runtimes.

Changelog

  • Adds formatNumbers function to TxProposal model
  • Adds numberFormat options to signing function
  • Adds numberFormat to relevant APIs
  • Sets numberFormat=hex query param to BWC methods
  • Various typing improvements
  • Fixes locked balance calculations
  • Fixes CWC's isHexString method to 0-pad odd-length hex strings

Testing Notes

Create a multi-recipient EVM tx proposal with one recipient receiving 53361793000000000000 (hex: 0x2e48b2c02b6ed0000) and the other 64034152000000010000 (hex: 0x378a701f9fd5ea000). Signing the txp in the app should result in the Server response could not be verified error. ❌

Then, using this branch of the bitpay-app, point the app's bitcore-wallet-client to this branch's BWC and try signing the proposal - it should succeed. ✔️


Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

@kajoseph kajoseph added BWC This pull request modifies the bitcore-wallet-client package BWS This pull request modifies the bitcore-wallet-service package CWC This pull request modifies the crypto-wallet-core package labels May 24, 2026
@kajoseph kajoseph requested review from Copilot and leolambo May 24, 2026 03:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses tx proposal signing/verifying failures caused by large-number precision/rounding differences between React Native and Node.js runtimes by introducing a deterministic number formatting option (notably hex) across BWS/BWC txp APIs and formatting tx-build-relevant fields consistently.

Changes:

  • Added TxProposal.formatNumbers() plus numberFormat plumbing through BWS APIs (create/publish/prepare/getPendingTxs/sign) and updated BWC to request numberFormat=hex.
  • Updated locked-balance calculations for EVM/XRP/SOL to use BigInt when summing pending tx amounts/fees.
  • Fixed CWC isHexString to accept odd-length hex strings by 0-padding, and updated/added related tests and typings.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/crypto-wallet-core/src/utils/index.ts Adjusts isHexString to 0-pad odd-length hex strings before validation.
packages/crypto-wallet-core/test/utils.test.ts Adds coverage for odd-length hex validation behavior.
packages/bitcore-wallet-service/src/lib/model/txproposal.ts Introduces generic numeric typing + formatNumbers() and threads numberFormat into raw-tx creation/signing paths.
packages/bitcore-wallet-service/src/lib/model/txproposal_legacy.ts Renames legacy interface and aligns broadcastedOn typing.
packages/bitcore-wallet-service/src/lib/model/txnote.ts Adds non-persisted editedByName field for fetch-time enrichment.
packages/bitcore-wallet-service/src/lib/server.ts Adds numberFormat support to multiple txp endpoints and adjusts pending-tx retrieval wiring.
packages/bitcore-wallet-service/src/lib/routes/wallets.ts Passes numberFormat from query params into status/build options.
packages/bitcore-wallet-service/src/lib/routes/transactions.ts Adds numberFormat query propagation into txp list/create/sign/prepare/publish routes.
packages/bitcore-wallet-service/src/lib/storage.ts Typing improvements and replaces lodash iteration with for..of loops in completion helpers.
packages/bitcore-wallet-service/src/lib/chain/index.ts Broadens txp typing for getBitcoreTx plumbing.
packages/bitcore-wallet-service/src/lib/chain/eth/index.ts Uses BigInt when summing locked pending amounts/fees.
packages/bitcore-wallet-service/src/lib/chain/sol/index.ts Uses BigInt when summing locked pending amounts/fees.
packages/bitcore-wallet-service/src/lib/chain/xrp/index.ts Uses BigInt when summing locked pending amounts/fees.
packages/bitcore-wallet-service/test/model/txproposal.test.ts Adds tests for formatNumbers and updates fixtures/typing expectations.
packages/bitcore-wallet-service/test/chain/{btc,bch,ltc,doge,xrp}.test.ts Updates fixtures/typing to match updated txp shape and numeric handling.
packages/bitcore-wallet-client/src/lib/api.ts Adds numberFormat=hex to relevant txp API calls (list/publish/sign/prepare/status).
packages/bitcore-wallet-client/src/lib/bulkclient.ts Adds numberFormat=hex to bulk status requests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Comment thread packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 21 out of 21 changed files in this pull request and generated 5 comments.

Comment thread packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Comment thread packages/bitcore-wallet-service/src/lib/model/txproposal.ts
Comment thread packages/bitcore-wallet-service/src/lib/server.ts
Comment thread packages/bitcore-wallet-service/src/lib/routes/transactions.ts
Comment thread packages/bitcore-wallet-service/src/lib/routes/wallets.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BWC This pull request modifies the bitcore-wallet-client package BWS This pull request modifies the bitcore-wallet-service package CWC This pull request modifies the crypto-wallet-core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants