feat: encode principal to Eth address as hex #524
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
To deposit ETH to the ckETH helper contract, starting point to convert ETH into ckETH, one have to call ths contract on the Ethereum network using the targeted principal (no subaccount) encoded as byte array similar to an Ethereum data hex.
This PR provide a utils that does such encoding and expose it ot the ckETH-js.
Notes
Except reusing the utils-js function
decodeBase32
this PR basically copies the JS code that has been impemented for the ckETH minter dashboard.Minter dashboard: https://sv3dd-oaaaa-aaaar-qacoa-cai.raw.icp0.io/dashboard
JS function: https://github.com/dfinity/ic/blob/master/rs/ethereum/cketh/minter/templates/principal_to_bytes.js
It is worth to note that the original code checks the length of the bytes (see code here) but given that this function accepts a principal as parameter, and not a text, we can assume the principal is valid (creating a principal object with agent-js which is invalid throw an error).
Changes
encodePrincipalToEthAddress