Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
add review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
krlosMata committed Sep 24, 2021
1 parent 2dbceb2 commit 7c154b4
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions docs/developers/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In this tutorial we will walk through the process of using the SDK to:
- [Configure Hermez Environment](#configure-hermez-environment)
- [Check token exists in Hermez Network](#check-token-exists-in-hermez-network)
- [Create a Wallet](#create-a-wallet)
- [Derive private babyjubjub from ethereum account](#derive-private-babyjubjub-from-ethereum-account)
- [Derive private Babyjubjub from Ethereum account](#derive-private-babyjubjub-from-ethereum-account)
- [Deposit Tokens from Ethereum into Hermez Network](#deposit-tokens-from-ethereum-into-hermez-network)
- [Verify Balance](#verify-balance)
- [Withdrawing](#withdrawing)
Expand Down Expand Up @@ -147,16 +147,26 @@ We can create a new Hermez wallet by providing the Ethereum private key of an Et
const hermezEthereumAddress2 = wallet2.hermezEthereumAddress

```
### Derive private babyjubjub from ethereum account
The specification to derive private babyjubjub from ethereum account is the following:
### Derive private Babyjubjub from Ethereum account
The specification to derive private Babyjubjub from Ethereum account is the following:
- Message to be signed: `Hermez Network account access.\n\nSign this message if you are in a trusted application only.`
- Sign message with your ethereum private key: `signature = eth_sign(MESSAGE)`
- Sign message with your Ethereum private key: `signature = eth_sign(MESSAGE)`
- message string is parsed to bytes using utf8 conversion. Further details can be found [here](http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array) and [here](https://github.com/ethers-io/ethers.js/blob/ce8f1e4015c0f27bf178238770b1325136e3351a/packages/strings/src.ts/utf8.ts#L202)
- please note that the json RPC method used is `eth_sign`. Further details can be found [here](`https://eth.wiki/json-rpc/API#eth_sign`)
- The computed `signature` is then hashed using keccak256 hash to finally derive the babyjubjub private key: `privateKeyBabyjubjub = keccak256(signature)`
- The computed `signature` is then hashed using keccak256 hash to finally derive the Babyjubjub private key: `privateKeyBabyjubjub = keccak256(signature)`

> notes:
> - if ecdsa standard libraries are used instead of Ethereum specific ones, remember to add 27 to `v` signature value
> - The public Babyjubjub key is derived from the private Babyjubjub key. Hermez Network uses the public Babyjubjub key compressed form (uint256)
> - There are two representations of public Babyjubjub key: hexadecimal and base64
> - Hexadecimal is done by converting the public Babyjubjub key compressed form (uint256) into big-endian hexadecimal string
> - Base64 is done by converting the public Babyjubjub key compressed form (uint256) into its little-endian base64 string
> - it also adds an additional checksum byte computed as the sum of all its bytes (mod $2^{8}$) which is concatenated at the end of the public Babyjubjub key compressed form

> implementations examples can be found [here](https://github.com/hermeznetwork/hermezjs/blob/main/src/hermez-wallet.js#L33), [here](https://github.com/hermeznetwork/hermezjs/blob/main/src/addresses.js#L109) and [here](https://github.com/hermeznetwork/hermez-go-sdk/blob/main/account/creation.go#L115)

## Deposit Tokens from Ethereum into Hermez Network
Creating a Hermez account and depositing tokens is done simultaneously as an L1 transaction. In this example we are going to deposit 1 `ETH` tokens into the newly created Hermez accounts.
Creating a Hermez account and depositing tokens is done simultaneously as an L1 transaction. In this example, we are going to deposit 1 `ETH` token into the newly created Hermez accounts.

```js
// set amount to deposit
Expand Down

0 comments on commit 7c154b4

Please sign in to comment.