Skip to content

fix(num): keep 4 bytes in stringToSha256ToArrayBuff4 when the top byte is zero - #1770

Open
takinanton wants to merge 1 commit into
starknet-io:developfrom
takinanton:fix/ledger-path-app-hash-padding
Open

takinanton wants to merge 1 commit into
starknet-io:developfrom
takinanton:fix/ledger-path-app-hash-padding

Conversation

@takinanton

Copy link
Copy Markdown

Motivation and Resolution

num.stringToSha256ToArrayBuff4 is documented to return 4 bytes but it goes through toHex which drops leading zeroes. When the top byte of the masked hash is zero it returns 3 bytes. That happens for about 1 application name in 128, for example App135 gives [40, 206, 181]. getLedgerPathBuffer111 and getLedgerPathBuffer221 concatenate that value so the derivation path comes out 23 bytes long with every later field shifted by one byte.

The result is now padded to 8 hex digits before the conversion, the same way the account id is padded in the path builders. App135 gives [0, 40, 206, 181]. Names that already produced 4 bytes are unchanged, LedgerW included.

RPC version (if applicable)

Not applicable.

Usage related changes

  • A custom Ledger application name whose hash starts with a zero byte now gets a 24 byte path. Before it got 23 bytes.

Development related changes

  • Two unit tests added, one for the helper and one for getLedgerPathBuffer111 with such a name. Both fail on develop.

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

I ran npm run test:unit (98 suites pass), ts:check, eslint and prettier on the touched files. I did not run the devnet suites. I found no issue to link. Not tried on a physical Ledger.

🤖 Generated with Claude Code

…e is zero

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant