Loopring 3.6 supports support lots of off-chain requests:
orders
order cancellation
swap
join AMM pool
exit AMM pool
transfer
off-chain withdrawals
etc..
Since these off-chain requests will result in modifications to the exchange's state Merkel tree, when you submit these types of requests using Loopring's API, sometimes you must provide EXTRA special signatures required by the Loopring protocol.
Overview of signatures and requests
Below is a signature type table for all those requests, each request asks for different signature methods due to different business models.
Request Type
eddsaSignature
ecdsaSignature
approvedHash
X-API-SIG
eddsaSignature, ecdsaSignature, approvedHash are located in REST request body.
X-API-SIG is located in REST request header.
Y means support.
N means not support.
Disabled means no longer support.
We STRONGLY suggest using Level 2 EdDSA key to sign every request, which saves both time & money for both user and Loopring as no Eth mainnet transaction and the corresponding block confirmation is needed. For more details, please refer to Key Management.
Below we take signing order and signing transfer/withdrawal as examples, as you will see, the first order signing needs merely a Level 2 EdDSA signature, but the latter two needs an extra EIP712 signature in the request header, you can see the difference on the way of submitting the requests.
Signing Orders
You need to serialize specific fields of an order into an integer array, then calculate the Poseidon hash of the array, and then sign the hash with your EdDSA private key.
The rules for serialization of orders, hashing, and signature methods must strictly follow Loopring's Specification.
If you don't use the ethsnarks library to calculate Poseidon hash, please pay attention to the values of the Poseidon parameters to ensure that they are entirely consistent with those used by Loopring. Otherwise, signature verification will fail.
Signing Off-chain Withdrawals
Following structure shows an off-chain withdrawal request:
The code for signing it in Python is as follows. Just like the order, the only difference is the request itself, so we just adjust parameters which calculate the poseidon hash.
You need to serialize specific fields of a transfer into an integer array, then calculate the Poseidon hash of the array, and then sign the hash with your EdDSA private key.
The following is an example of internal transfers: