simplify tx builder checksum calculation

Open
#807 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
web-dev

Research direction

Start at apps/tx-builder/src/lib/checksum.ts around line 8 and inspect how serializeJSONObject produces the checksum input. Compare the proposed stable-stringify approach with the example tx builder JSON output. Done means the custom encoding is simplified while checksum calculation remains deterministic for tx builder files.

Written by the indexing model from the issue text.

Description

im working on adding the tx builder json format support to ape-safe and the way checksum is calculated sticks out to me.

currently it uses some unhinged weird custom encoding, which looks very brittle when you consider porting into other languages.

consider using something like json-stable-stringify instead.

https://github.com/safe-global/safe-react-apps/blob/8952156607a0f432555e5d699ec21eaea4f25f67/apps/tx-builder/src/lib/checksum.ts#L8

example of output:

>>> serializeJSONObject(batchFileObject)
'{["chainId","createdAt","meta","transactions","version"]"4",1646321521061,{["checksum","createdFromOwnerAddress","createdFromSafeAddress","name","txBuilderVersion"]"","0x49d4450977E2c95362C13D3a31a09311E0Ea26A6","0xDF8a1Ce35c9a6ACE153B4e0767942f1E2291a1Aa","test batch file","1.4.0",},[{["contractInputsValues","contractMethod","to","value"]{["paramAddress"]"0x49d4450977E2c95362C13D3a31a09311E0Ea26A6",},{["inputs","name","payable"][{["internalType","name","type"]"address","paramAddress","address",}],"testAddress",false,},"0x49d4450977E2c95362C13D3a31a09311E0Ea26A6","0",},{["contractInputsValues","contractMethod","to","value"]{["paramAddress","paramBool"]"","false",},{["inputs","name","payable"][{["internalType","name","type"]"bool","paramBool","bool",}],"testBool",false,},"0x49d4450977E2c95362C13D3a31a09311E0Ea26A6","0",},{["data","to","value"]"0x42f4579000000000000000000000000049d4450977e2c95362c13d3a31a09311e0ea26a6","0x49d4450977E2c95362C13D3a31a09311E0Ea26A6","2000000000000000000",}],"1.0",}'
Dominant language
TypeScript
Stars
116
Forks
84
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from safe-global/safe-react-apps

All issues in safe-global/safe-react-apps

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.