Open banteg opened 2 months ago
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.
json-stable-stringify
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",}'
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: