class DCP

Public Class Methods

send_banklist_message(key, password) click to toggle source
# File lib/dcp.rb, line 9
def self.send_banklist_message(key, password)
  send_proxy_message(key, password, Time.now.to_i + 60, "")
end
send_oauth_message(key, token) click to toggle source
# File lib/dcp.rb, line 5
def self.send_oauth_message(key, token)
  send_proxy_message(key, token.token, token.expires_at.to_i, "")
end
send_proxy_message(key, password, expiry, scopes) click to toggle source
# File lib/dcp.rb, line 13
def self.send_proxy_message(key, password, expiry, scopes)
   body = {
    oAuthToken: password,
    expiry: expiry,
    endpoint: ENV['PROXY_URL']
  }

  message_string = {
    owner: key.address,
    signature: sign(key, body),
    body: body
  }.to_json

  message = {signedMessage: message_string}

  response = HTTParty.post(ENV['PROXY_URL'], body: message)
  reply_body = response.body
  reply = JSON.parse reply_body

  unless reply['success']
    Rails.logger.error "Proxy service returned error #{reply['error']}"
  end

  return reply
end

Private Class Methods

sign(key, body) click to toggle source
# File lib/dcp.rb, line 41
def self.sign(key, body)
  sig = key.personal_sign body.to_json
  bin_sig = Eth::Utils.hex_to_bin(sig).bytes.rotate(-1).pack('c*')
  {
    r: {
      type: "Buffer",
      data: bin_sig[1..32].bytes
    },
    s: {
      type: "Buffer",
      data: bin_sig[33..65].bytes
    },
    v: bin_sig[0].bytes[0]
  }
end