sorare / api

Sorare API documentation
153 stars 47 forks source link

How to Sign limitOrder on Ruby ? #108

Open MichaelBornand opened 2 years ago

MichaelBornand commented 2 years ago

Hello,

I'm trying to sign the limitOrder using a ruby script but can't succeed to do it. After signing and calling AcceptSingleSaleOffer, reasult always is either a 500 error status or an error with "invalid limitOrder signature"

I've seen that the js script is using the sorare/crypto lib, which is not available on ruby, and this script is using a starkware lib to hash and sign the limitOrder, which also is not available on ruby.

RIght now, I have something like that, using the Digest and ECDSA lib on ruby to try to sign, but it is not working

def signLimitOrder(limitOrder, private_key)
    #puts limitOrder.to_json
    digest = Digest::SHA256.digest(limitOrder.to_json)
    #puts digest
    signature = nil
    group = ECDSA::Group::Secp128r2
    while signature.nil?
      temp_key = 1 + SecureRandom.random_number(group.order - 1)
      signature = ECDSA.sign(group, private_key, digest, temp_key)
    end
    signature = EC.sign( digest, private_key )
    #puts signature.to_json
    {r: signature.r.to_s(16),
     s: signature.s.to_s(16)}
  end

is there anyway to achieve that properly with ruby ?

redox commented 2 years ago

Hey @MichaelBornand , we're indeed relying on https://github.com/sorare/crypto#signlimitorder on our end and therefore don't have a ruby implementation. That being said, if you managed to get this work; we would love to hear from it to share it more broadly.

redox commented 2 years ago

It looks like https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/signature.py could be the easiest code to port to Ruby.