- The way we initialise is still the same, the difference is that NOW we give
SEED_PHRASE
asTEST_ACCT_KEY
- Currently we support test phrase only and we sign it using ED25519
- Nothing is changes in sockets except for the url link
-
We do not sign our transaction using ETH library anymore. We now use
nacl
andhashlib
in order to sign the messages. -
For signing orders we sign it using the following scheme
-
Assuming we have the order with values in sui format.
-
We first get the
orderhash
of the order using the following methodflags = hexToByteArray(numberToHex(flags,2)) buffer=bytearray() orderPriceHex=hexToByteArray(numberToHex(int(order["price"]))) orderQuantityHex=hexToByteArray(numberToHex(int(order['quantity']))) orderLeverageHex=hexToByteArray (numberToHex(int(order['leverage']))) orderSalt=hexToByteArray(numberToHex(int(order['salt']))) orderExpiration=hexToByteArray(numberToHex(int(order['expiration']),16)) orderMaker=hexToByteArray(numberToHex(int(order['maker'],16),64)) orderMarket=hexToByteArray(numberToHex(int(order['market'],16),64)) bluefin=bytearray("Bluefin", encoding="utf-8") buffer=orderPriceHex+orderQuantityHex+orderLeverageHex+orderSalt+orderExpiration+orderMaker+orderMarket+flags+bluefin
-
We then get the sha256 of the buffer.hex()
-
We then sign it and append '1' to it, specifying that we signed it using ed25519
-
-
For signing onboarding signer we follow a different approach.
- What is onboarding signer: When we are calling a Bluefin init function we sign a string using our private key and send it to bluefin exchange along with our public key, bluefin exchange verifies it and returns us a token.
- For signing it we first convert our message to bytes and then add [3,0,0, len(message)] to the start of our bytearray and then our message. if our message length is greater than 256 then it wont fit in a byte in this case we follow BCS methodology to send our message.
-
For signing cancel order, there are two ways.
- We first sign the order and send it to bluefin. Now we have the hash of the order. We first change our encode our hash to BCS format.
sigDict={} sigDict['orderHashes']=order_hash encodedMessage=self.encode_message(sigDict)
- Please have a look at signer.py to see the implementation or encode_message.
- Then we sign the encodedMessage and send the signature to bluefin for cancelling order
- We first sign the order and send it to bluefin. Now we have the hash of the order. We first change our encode our hash to BCS format.
-
For signing cancel order second method.
- We sign the order and send it to bluefin, now imagine we do not have the hash of our order.
- We resign our order and get the hash and then we follow the similar approach as above. Please have a look at
7.cancelling_orders.py
in our examples file.
- Basically as explained earlier when sign the onboarding url and send it to bluefin, bluefin returns us the TOKEN.
- The change in this repo is following.
-
# imagine msg="https://testnet.bluefin.io" msgDict={} msgDict['onboardingUrl']=msg msg=json.dumps(msgDict,separators=(',', ':')) # we first create a json something like this '{"onboardingURL":"https://testnet.bluefin.io"} # we then convert this json to a bytearray msg_bytearray=bytearray(msg.encode("utf-8")) intent=bytearray() #we then append [3,0,0,length of our json object] to our intent bytearray intent.extend([3,0,0, len(msg_bytearray)]) intent=intent+msg_bytearray # we then take a blake2b hash of intent bytearray we created hash=hashlib.blake2b(intent,digest_size=32) #then we finally sign the hash