Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: encode principal to Eth address as hex #524

Merged
merged 6 commits into from
Jan 18, 2024

Conversation

peterpeterparker
Copy link
Member

@peterpeterparker peterpeterparker commented Jan 17, 2024

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

  • new utils encodePrincipalToEthAddress
  • add function to documentation

Copy link
Contributor

github-actions bot commented Jan 17, 2024

size-limit report 📦

Path Size
@dfinity/ckbtc 7.12 KB (0%)
@dfinity/cketh 1.9 KB (+8.44% 🔺)
@dfinity/cmc 1.26 KB (0%)
@dfinity/ledger-icrc 2.93 KB (0%)
@dfinity/ledger-icp 15.95 KB (0%)
@dfinity/nns 35.62 KB (0%)
@dfinity/nns-proto 76.44 KB (0%)
@dfinity/sns 15.15 KB (0%)
@dfinity/utils 4.4 KB (0%)
@dfinity/ic-management 2.2 KB (0%)

@peterpeterparker peterpeterparker marked this pull request as ready for review January 17, 2024 11:46
Copy link
Contributor

@mstrasinskis mstrasinskis left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM.

@peterpeterparker peterpeterparker merged commit 642a522 into main Jan 18, 2024
11 checks passed
@peterpeterparker peterpeterparker deleted the feat/encode-principal-for-eth branch January 18, 2024 13:54
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.

None yet

2 participants